bugfix(heightmap): Reduce ray cast lengths and fix ray casting in BaseHeightMapRenderObjClass::Cast_Ray#2836
bugfix(heightmap): Reduce ray cast lengths and fix ray casting in BaseHeightMapRenderObjClass::Cast_Ray#2836xezon wants to merge 2 commits into
Conversation
…eHeightMapRenderObjClass::Cast_Ray
| *rayEnd -= *rayStart; //vector camera to world space point | ||
| rayEnd->Normalize(); //make unit vector | ||
| *rayEnd *= sqr(m_3DCamera->Get_Depth()); //adjust length to reach far clip plane and beyond | ||
| *rayEnd *= m_3DCamera->Get_Depth() * 2; //adjust length to reach far clip plane and beyond |
There was a problem hiding this comment.
I cannot recall why I picked sqr(farZ) before. farZ*2 appears to also be sufficient.
| result.ComputeContactPoint=true; | ||
|
|
||
| Int p; | ||
| for (p=0; p<3; p++) { |
There was a problem hiding this comment.
I have no clue why there was this loop here. It does not do anything. I removed it and it works.
There was a problem hiding this comment.
I now see why this loop is there and I put it back and fixed the looping logic as far as I could tell.
| result.StartBad=false; | ||
| lineseg2.Set(lineseg.Get_P1(),lineseg.Get_P0()); //reverse line segment | ||
| if (CollisionMath::Collide(lineseg2,hbox,&result)) | ||
| { if (!result.StartBad) //check if end point inside terrain |
There was a problem hiding this comment.
When the ray length was very large, then this collision here failed. I am not sure why but I suspect because of floating point precision loss at very large numbers.
When it failed, then P1 was a very large number, and the cells loop further below would then iterate over very large integer numbers which practically meant the application hung up.
With this change the ray cast now aborts early if this collision test failed, which avoids all this trouble.
This change reduces the ray cast lengths from
sqr(farZ)tofarZ*2and fixes ray casting inBaseHeightMapRenderObjClass::Cast_Ray.The
sqr(farZ)produced too large ray casts which somehow brokeBaseHeightMapRenderObjClass::Cast_Rayand caused infinite loops.