Jump to content
  • Advertisement


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


Rotation from one vector to another -- repost

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

I lost my original post but no one replied to it anyway. Anyway, I have an effect that gets created along the z axis and I want to find the rotation to the camera's direction. Here's what I have right now. m_vDir is the camera's direction.
// Rotate the cylinder off the z axis to face the direction of the ray

	// Find the rotation from vCurrDir to m_vDir and store it for render time

	D3DXVECTOR3 vCurrDir = D3DXVECTOR3(0.0f, 0.0f, 1.0f);	// Current direction

	D3DXVECTOR3 vRotAxis;
	D3DXVec3Cross( &vRotAxis, &vCurrDir, &m_vDir );			// Find the rotation axis

	float fAngle = D3DXVec3Dot( &vCurrDir, &m_vDir );		// Angle of rotation

	D3DXQUATERNION quat = D3DXQUATERNION( vRotAxis.x, vRotAxis.y, vRotAxis.z, fAngle );	// Rotation quaternion

	D3DXMatrixRotationQuaternion( &m_rotMat, &quat );		// Rotation matrix

I use the resulting m_rotMat in my render function to rotate the effect. My code seems correct but my effect is positioned all messed up. Any ideas? I have been trying to fix this for a few weeks now and still no luck! grrr [edited by - beoch on September 30, 2002 6:35:09 PM]

Share this post

Link to post
Share on other sites
Maybe it''s your solution: this is a function to find angle between 2 vector...
float GetVectorAngle(D3DVECTOR Vec1,D3DVECTOR Vec2)
return (float) acos(DotProduct(Vec1,Vec2)/(Magnitude(Vec1)*(Magnitude(Vec2))));

If vec1 and vec2 are normalized, you can omit the "/(Magnitude(Vec1)*(Magnitude(Vec2)"


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!