# Rotate a D3DXVECTOR3

This topic is 4907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
Quote:
 Original post by WanMasterD3DXMatrixRotationAxis 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

##### Share on other sites
Well there is the D3DXVec3TransformCoord function, which transforms a vector by a given matrix. More details in the sdk. HTH.

##### 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 on other sites
Quote:
 Original post by Evil SteveIf 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"

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

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.

##### 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 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 itD3DXMATRIX  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 eyeD3DXVECTOR3 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 on other sites
Thanks guys, specially Specchum, supernat2, adriano_usp

These combinatinos really did help and I've made it correctly.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632993
• Total Posts
3009761
• ### Who's Online (See full list)

There are no registered users currently online

×