• Advertisement


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

Can anyone see anything wrong with this?

This topic is 5405 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

And more importantly, are there any boundary conditions I should know about? It''s probably something really obvious, but under certain conditions using this code it can do really weird things.
// Create 2D versions of the vectors to work with

		XYDir = D3DXVECTOR2(vDir.x, vDir.y);
		XZDir = D3DXVECTOR2(vDir.x, vDir.z);
		XYVel = D3DXVECTOR2(vVelocity.x, vVelocity.y);
		XZVel = D3DXVECTOR2(vVelocity.x, vVelocity.z);

		// Normalize the velocity vectors

		D3DXVec2Normalize(&NXYVel, &XYVel);
		D3DXVec2Normalize(&NXZVel, &XZVel);
		D3DXVec2Normalize(&NXYDir, &XYDir);
		D3DXVec2Normalize(&NXZDir, &XZDir);
		// Calculate the dot products

		float XYDot, XZDot;
		XYDot = (float)acos((double)D3DXVec2Dot(&NXYVel, &NXYDir));
		XZDot = (float)acos((double)D3DXVec2Dot(&NXZVel, &NXZDir));
		// Calculate the Forward and Up Values using the XY plane

		float Forward, Up;
		Forward = (float)cos((double)XYDot) * D3DXVec2Length(&XYVel);
		Up = (float)sin((double)XYDot) * D3DXVec2Length(&XYVel);
		// Calculate the Right value using the XZ plane

		float Right;
		Right = (float)sin((double)XYDot) * D3DXVec2Length(&XZVel);

		// Fill out the vModelV values

		vModelV = D3DXVECTOR3(Right, Up, Forward);
Essentially its purpose is to take the orientation vectors and the vVelocity world-space vector and work out what the multiplier is for each of the orientation vectors to re-create the world space vector. The thing is, I''m not sure its entirely right but I''m also unsure where I''m going wrong - can anyone help me clean it up? ##UnknownPlayer##

Share this post

Link to post
Share on other sites

  • Advertisement