Sign in to follow this  

Rotate a D3DXVECTOR3

This topic is 4594 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, I was just wondering if d3dx9math.h Provides functionality to rotate a point around another anchor point on an arbitrary plane. Like it provides many of transformations, matrices etc. Any input in this would really be appreciated. Fahad Ashfaque [Edited by - fahadash on May 14, 2005 4:03:19 PM]

Share this post


Link to post
Share on other sites
D3DXMatrixRotationAxis enables you rotate around an arbitrary axis (which could be the plane's normal vector).
This is the one I know by heart, but maybe searching the DirectX documentation can result in a better one for this specific situation.

Share this post


Link to post
Share on other sites
Quote:
Original post by WanMaster
D3DXMatrixRotationAxis enables you rotate around an arbitrary axis (which could be the plane's normal vector).
This is the one I know by heart, but maybe searching the DirectX documentation can result in a better one for this specific situation.




I am confused, The function you told is to deal with matrices not D3DXVECTOR3.

Do you know if I can multiply a Vector with Rotation matrix and get vector in return ?


Thanks


Fahad Ashfaque

Share this post


Link to post
Share on other sites
If you're using D3DXMATRIX, I think you can just multiply the vector by the matrix like so:

D3DXMATRIX mat;
D3DXVECTOR3 v;
D3DXVECTOR3 vTransformed = v*mat;


I think D3DX lets you do that anyway...

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
If you're using D3DXMATRIX, I think you can just multiply the vector by the matrix like so:
*** Source Snippet Removed ***
I think D3DX lets you do that anyway...


I cannot see any over load like D3DXVECTOR3& operator *= (CONST D3DXVECTOR3&);

When I see the code for D3DXMATRIX at page 45 of the Title: "Introduction to 3D Game Programming with DirectX 9.0 by Frank D. Luna"


Thanks for your reply anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Specchum
Well there is the D3DXVec3TransformCoord function, which transforms a vector by a given matrix. More details in the sdk. HTH.


Well, I just read your reply. Let me tell you why I need to do this.

I am moving the VIEW by using the Arrow keys.

What I need to do is, to rotate a vLookAt around a vEyePos, I've the normal
vector to that plane that is vUp.

Thanks for your reply, I am going to see the sdk for that.


Fahad Ashfaque

Share this post


Link to post
Share on other sites
Using spherical coordinates, you can easily rotate the camera around a point (the center of the sphere) by just adding/subtracting the theta value. I just did a quick search on the internet for the equations and found this site to help you out.

http://www.math.montana.edu/frankw/ccp/multiworld/multipleIVP/spherical/body.htm

Just make the center of your sphere the LookAt point, and make the point at (rho, theta, phi) the camera.

Share this post


Link to post
Share on other sites
Quote:
I am confused, The function you told is to deal with matrices not D3DXVECTOR3.

Do you know if I can multiply a Vector with Rotation matrix and get vector in return ?

Yes, a vector can be tranformed by a matrix. You need to create a function to provide this operation. If you are using D3DX structures, you can use the D3DXVec3TransformCoord function (as Specchum said) for that.

Mathematically, a rotation is described around an axis (a vector), not around a point.

OK, let's show an example:

1) Defining the rotation axis and the rotation matrix:

D3DXVECTOR3 axis (...,...,...); // this axis could be your vUp if you want to rotate around it
D3DXMATRIX mat;
D3DXMatrixRotationAxis( &mat, &axis, angle );

Note:
- The angle value must be increased/decreased when the arrow keys are pressed.
- D3DXMatrixRotationAxis function provides a matrix that describes a rotation around an arbitrary axis. If you just want to rotate around x, y or z axes from the world coordinate system, you can use D3DXMatrixRotationX/Y/Z functions (you don't need to define a rotation axis).


2) Defining the camera's eye and camera's target:

D3DXVECTOR3 vEyePos (...,...,...); // camera's eye
D3DXVECTOR3 vLookAt (...,...,...); // camera's target


3) Defining a vector from vLookAt to vEyePos and transforming it by mat:

D3DXVECTOR3 vLookAtEye = vEyePos - vLookAt;
D3DXVec3TransformCoord( &vLookAtEye, &vLookAtEye, &mat );


4) Now update the vEyePos:

vEyePos = vLookAt + vLookAtEye;

Share this post


Link to post
Share on other sites

This topic is 4594 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this