Jump to content

[SOLVED] Terrain Intersection Issue


photo

Recommended Posts

Hello ,

 

We are trying calculate the intersection point of mouse with Terrain.

We are using the api ObjectTerrain::getIntersection()  from unigine script.

 

And I observed issue that for the same set of input I was getting no intersection at first few clicks

But after few mouse clicks at the same point i got the intersection.

 

Code we are using :

 

vec3 startPos,endPos;
Unigine::getPlayerMouseDirection(startPos,endPos)
ObjectIntersection intersection = new ObjectIntersection();
vec3 p0 = terrainObject.getIWorldTransform() * startPos;
vec3 p1 = terrainObject.getIWorldTransform() * endPos;
if( terrainObject.getIntersection(p0,p1, intersection, 0 ) == 1 )
{
     // we have intersectionPoint //
}
I debugged the code and found that 
 
int TerrainSurface::getIntersection(const vec3 &point_0,const vec3 &point_1,vec3 *ret_point,vec3 *ret_normal,vec4 *ret_texcoord,int holes) 
 
Calls createPatches()
and then uses the patches for calculating intersection points.
if the patches were created during the call  createPatches() if they were not present
 
TerrainSurface state is set to dirty (As patches are still not valid , no valid bounding boxes i think )
I hope it is not right to do intersection with newly created patches.
 
So i have modified the code as below which fixed the issue
 
int TerrainSurface::getIntersection(const vec3 &point_0,const vec3 &point_1,vec3 *ret_point,vec3 *ret_normal,vec4 *ret_texcoord,int holes) {
 
loadHeights(1);
    if (patch_root == NULL)
    {
        createPatches();
        update();
    }

 

 

Can you please confirm that the problem we are facing is a bug in TerrainSurface::getIntersection ?
is the fix right ? Optimised ?
  or
Do we need to change our application  code ?
 
 
 
Link to comment
  • 2 weeks later...
×
×
  • Create New...