fix: Camera.viewToRay end position calculation#483
fix: Camera.viewToRay end position calculation#483kubax2000 wants to merge 1 commit intoSceneView:mainfrom kubax2000:bugfix/collision-system
Conversation
|
Hi! |
|
You're right @grassydragon. |
Yes, I'll take a look today in the evening. |
|
In Sceneform there is a return then when |
|
That's also what I had in mind but do you think the NAN could come from there? |
|
Hi! To be sure, replace the line with and get the correct answer I hope this helps in finding the right solution |
@ThomasGorisse, to be honest, I don't understand the formula in the |
|
Thanks a lot @den59k . That was very very tricky to find. Good job!!! |
I'll try soon and tell the results. I checked yesterday that other libraries, for example, GLM, had the same formula for unprojecting a point so the problem isn't in the formula. |
|
Yeah, it doesn't seem to be the formula, sorry. I found out after I started testing further. But my click started working correctly after I replaced @ThomasGorisse I will describe the problem of why NaN occurs: When we project a point onto projectionTransform, the w component is zero (the point goes to infinity). Then there is a condition that replaces xy by 0 in this case (I don't know why this is here, it looks like a dirty hack). And at the end the result is multiplied by 1/w, and in the Kotlin |
@ThomasGorisse, no, I've checked and this isn't the case here.
Yes, @den59k is absolutely right. We can't use the I think the final code of the method should be as follows: fun Camera.viewToWorld(viewPosition: Float2, z: Float = 1.0f): Position {
// Normalize between -1 and 1.
val clipSpacePosition = Float4(
x = viewPosition.x * 2.0f - 1.0f,
y = viewPosition.y * 2.0f - 1.0f,
z = 2.0f * z - 1.0f,
w = 1.0f
)
val result = inverse(cullingProjectionTransform * viewTransform) * clipSpacePosition
if (MathHelper.almostEqualRelativeAndAbs(result.w, 0.0f)) {
return Position()
}
return result.xyz / result.w
} |
|
Great work here! |
|
Fixed in 2.2.0 from 5cc1fb0 |
#400 fix
If z equals 1.0f viewToWorld returns [NaN, NaN, -Infinity].