Jump to content
  • Advertisement
Sign in to follow this  

Terrain to Vehicle normal

This topic is 3800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have a terrain and lets say a box. User controls box with arrow keys. I want box height and orientation follows terrain heights. I implemented and I succeded. But I have a small problem. I am using following code to make orientation
	Quaternion q;
	Vector3 nodeNormal, rotVector;
	FLOAT rotAngle;

	nodeNormal = node.GetWorldOrientation().GetYAxis();
	rotVector = nodeNormal.Cross( normal );

	rotAngle = Math_ACos( nodeNormal.Dot( normal ) );
	q.RotateAroundAxis( rotVector, rotAngle );

	node.SetRotate( q );
It does orientation correctly. But the problem is when it rotates object, it changes z axis of the object. Assume that box is facing (z axis) to (0.0f, 0.0f, 1.0f) when terrain height changes above code is applied and resulting Z axis becomes (0.3f, -0.1, 0.99f). Box should not rotate around Y axis. Is there any suggestion?

Share this post

Link to post
Share on other sites
normal is the normal vector of the triangle which box on it. it is calculated like this. let be p1, p2 and p3 the points of the triangle.
pa = p2-p1
pb = p3-p1
pa = pa.Cross( pb )
normal = pa

nodeNormal is the normal (Y Axis) of the box.

Share this post

Link to post
Share on other sites
another way to do this is through re-normalising the orientation matrix.

Vector right, up, forward; // the three orientation vectors of your vehicle, aka [x, y, z].
Vector normal; // the terrain normal.

up = normal;
forward = right.cross(up);
right = up.cross(forward);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!