Jump to content

[SOLVED] Finding the HAT


photo

Recommended Posts

Posted

Hi there

 

For the Unigine v1, we used the following code to get the height above terrain (HAT) and pack it into the CigiHatHotExtResponse packet.

int ret[0];
dvec3 p0 = position + vec3(0.0f,0.0f,1000.0f);
dvec3 p1 = position - vec3(0.0f,0.0f,1000.0f);
Object object = engine.world.getIntersection(p0,p1,~0,ret);
			
CigiHatHotExtResponse response = new CigiHatHotExtResponse(hathot_id);

if(object != NULL) {
	dvec3 point = ret[0];
	vec3 normal = ret[1];
				
	response.setResponseValid(1);
				
	response.setHeightAbove(position.z - point.z);
	response.setHeightOf(point.z);
				
	response.setAzimuth(atan2(normal.x,normal.y) * RAD2DEG);
	response.setElevation(acos(clamp(-normal.z,-1.0f,1.0f)) * RAD2DEG - 90.0f);
}
			

engine.cigi.addIGPacket(response);

In Unigine V2 there are some changes in the getIntersection* commands.

 

We tried it as followed:

int ret[0];
dvec3 p0 = position + vec3(0.0f, 0.0f, -200.0f);
dvec3 p1 = position - vec3(0.0f, 0.0f, 1000.0f);
int intersected = engine.world.getIntersectionObjects(p0, p1, ret);

But as it seems, the returned 'ret' value doesn't contains any more the point and its normal of the ground model. As described in the documentation, the ret array contains the result.

 

Is my approach correct? I should get the point on the ground vertically below the spectator.

 

Thanks a lot,

Renato

Posted

Hi Renato,
 
According to the migration guide you should use this function instead: getIntersection(p0, p1, int mask, variable v). Variable v will define the results that function returns. For example:
 

WorldIntersectionNormal intersection = new WorldIntersectionNormal();
dvec3 p0 = position + vec3(0.0f,0.0f,1000.0f);
dvec3 p1 = position - vec3(0.0f,0.0f,1000.0f);

Object object = engine.world.getIntersection(p0,p1,~0,ret);

if(object != NULL) {
  log.message("point: %s index: %i surface: %i normal: %s \n", typeinfo(intersection.getPoint()), intersection.getIndex(), intersection.getSurface(), typeinfo(intersection.getNormal()));
}

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Hi Andrey

 

Sorry, I couldn't have thought of the migration guide!

 

Thanks a lot.

Posted

Hi Andrey

 

I came across the following situation while using the getIntersection function with a WorldIntersectionNormal object.

 

The z-value of the intersection point increase or decrease to the same amount as the change of the object in the middle of the reference line. Does the WorldIntersectionNormal object doesn't contain the intersection point coordinates relative to the world pivot point?

 

Hope, you understand what I mean,

Renato

Posted

What I mean is, that I want to find out the HOT (height-of-terrain) of the terrain below a specific point...

Posted

Hi Andrey,

 

I've found the problem. If I had to change the definition of p0 to remain the Aircraft's position and not 1000m above, as shown below.

dvec3 p0 = position;

The WorldIntersectionNormal object returns the HOT correctly.

 

This is the code I'm using right now:

WorldIntersectionNormal intersection = new WorldIntersectionNormal();
dvec3 p0 = position;
dvec3 p1 = position - vec3(0.0f, 0.0f, 2000.0f);
Object object = engine.world.getIntersection(p0, p1, ~0, intersection);

dvec3 point = intersection.getPoint();
vec3 normal = intersection.getNormal();
response.setResponseValid(1);
response.setHeightAbove(position.z - point.z);
response.setHeightOf(point.z);
...

engine.cigi.addIGPacket(response);

Kind regards,

Renato

Posted

Yes, solved for now. Thanks a lot!

×
×
  • Create New...