rotate a D3DXVECTOR3 about another .?

Started by
4 comments, last by MTclip 18 years, 6 months ago
just wondering how one would go about rotating 1 D3DXVECTOR3 about another.. here is what i have tried and it has given me not what i expected.. D3DXMatrixRotationYawPitchRoll(&m_tempMatrix, xrot, yrot, zrot); D3DXVec3TransformCoord(&m_tempVector3, &m_position, &m_tempMatrix); m_target += m_tempVector3; .... basically i expected it to rotate the m_target about the m_position... im obviously wrong
Advertisement
Do you mean rotating the target vector around another vector ?
If so use your another vector as the rotation axis and call the D3DXMatrixRotationAxis() method to create a rotation matrix wich rotates your target vector around that another vector.
The function is simple to use, you provide it with the following parameters :
D3DXMatrix* pOut - The resulting rotation matrix
D3DXVECTOR3* pVec - Rotation axis (the axis vector which is the vector you want to rotate your target vector around)
FLOAT angle - Rotation angle

Now you can use the D3DXVec3TransformCoord() method as you did before to rotate your target vector as needed providing the method with the rotation matrix created before.
There is nothing that can't be solved. Just people that can't solve it. :)
hmmm well thanks for that but it is still not working...

D3DXMatrixRotationAxis(&m_tempMatrix,&m_position ,x);
D3DXVec3TransformCoord(&m_target, &m_position, &m_tempMatrix);

thats what i have changed it to(amungst others)...

.. i am trying to rotate the target around the position...

i must still be doing something wrong..


should the x be the change in angle...
if x = 0, will it not rotate at all or will it rotate it to angle 0..
The rotation is defined around an axis (not around a point). So, for rotating m_target around m_position, I understand that you desire to rotate m_target around an axis that passes by the origin and by m_position. Is it really it what you want? Perhaps you would like to rotate m_target around a vertical axis that passes by m_position.

In the first case, you could do:

D3DXMatrixRotationAxis(&m_tempMatrix,&m_position ,theta); // Transform m_target by m_tempMatrixD3DXVec3TransformCoord(&m_target, &m_target, &m_tempMatrix);



In the second case, you could do:

// I suppose the y-axis is your vertical axisD3DXMatrixRotationY(&m_tempMatrix,theta); // Transform m_target by m_tempMatrixD3DXVec3TransformCoord(&m_target, &m_target, &m_tempMatrix);
If x = 0 then no rotation will take place.
The angle provided is the angle of rotation of the current object / vertex
which means if x = 90 the object / vertex will be rotated 90 degrees from its current rotation state.

Also note that the angle your provide needs to be in radians.
If you want to rotate in x degrees use the macro D3DXToRadian(x) to get the rotation angle in radians.


There is nothing that can't be solved. Just people that can't solve it. :)
well thanks for the replies .. but i finally got my original idea to work

HRESULT Camera::rotateAboutSelf(float x, float y, float z){	if(x == 0 && y == 0 && z == 0)		return S_OK;		m_xMoveDelta += x * m_xSens;	m_yMoveDelta += y * m_ySens;	m_zMoveDelta += z * m_zSens;		D3DXMatrixRotationYawPitchRoll(&m_tempMatrix, m_xMove, m_yMove, m_zMove);	D3DXVec3TransformCoord(&m_target, &m_position, &m_tempMatrix);	return S_OK;}


i also have another function called rotateAboutTarget() its all the same except
D3DXVec3TransformCoord(&m_target, &m_position, &m_tempMatrix);
becomes
D3DXVec3TransformCoord(&m_position, &m_target, &m_tempMatrix);

then of course you will have to update the view matrix...

This topic is closed to new replies.

Advertisement