Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Christian Schlager

My angle computation code doesnt work...What does -1.#J mean?

This topic is 5287 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, my tank is driving across a terrain and this code computes the angles to align it with the polygon beneath:
// tank normal
D3DXVECTOR3 tank_normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
// Polygon normal
D3DXVECTOR3 poly_normal = D3DXVECTOR3( 
// temp vector for first angle
D3DXVECTOR3 vectorX = D3DXVECTOR3(tank_normal.x, poly_normal.y, poly_normal.z);
// angle between tank normal and temp vector
float scalarproductX = scalar(tank_normal, vectorX);
float lengthX = (float)sqrt(sq(tank_normal.x) + sq(tank_normal.y) + sq(tank_normal.z)) * (float)sqrt(sq(vectorX.x) + sq(vectorX.y) + sq(vectorX.z));
	tank[j].mesh.angle.x = (float)(acos(scalarproductX / lengthX) * 180.0f / D3DX_PI);
// now second angle from temp vector to Polygon normal
float scalarproductZ = scalar(vectorX, poly_normal);
float lengthZ = (float)sqrt(sq(vectorX.x) + sq(vectorX.y) + sq(vectorX.z)) * (float)sqrt(sq(poly_normal.x) + sq(poly_normal.y) + sq(poly_normal.z));
tank[j].mesh.angle.z = (float)(acos(scalarproductZ / lengthZ) * 180.0f / D3DX_PI);
unfortunately it doesnt work... Sometimes i get this value: -1.#J for tank[j].mesh.angle.z. What's that? Is it like -infinite or sth.? Something wrong with the code? thanks for help. Christian [edited by - Christian Schlager on April 4, 2004 1:00:29 PM] [edited by - Christian Schlager on April 4, 2004 1:02:06 PM]

Share this post

Link to post
Share on other sites
if you do acos(x), x has to be in range [-1, 1]. If not, then you get a math exception, and the result is garbage.

not sure what you try to do with LengthX and LengthZ, if it''s for the length of a vector, and you are using directX, you might as well use

D3DXVec3Dot() for a dot product (scalar product)
D3DXVec3Cross() for cross product
D3DXVec3Length() for length of vectors

Share this post

Link to post
Share on other sites

  • 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!