#### Archived

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

# How to make a Local Axis for object?

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

## Recommended Posts

hi all i can move the object on the world axis only. I loaded a Fighter.x when i rotate it then move it should move toward where its facing(Front)but it only moves on the z axis. i think im supposed to add a Look,up,Right and pos vectors in the objects Struct. But dont know how i should implement the code in the struct and the frame move function. I tyred using Quaternions but it either Rotates or Translates not both at the same time. i would apreciate any help thxs

##### Share on other sites
Hello, I''m still a beginner myself but I have run into that problem. I''ll try to help. I know this is not the best way but it''s the only way it''s worked for me.

I use the D3D matrix to implement this. I have a member D3DXMATRIX to hold the rotation from frame to frame.
I create a translation matrix prior to drawing the model and call a translate matrix function to increment the Z-Axis Then I build the rotation matrix. Then I multiply the rotation by the translation. after you can then go ahead and call the set transform for the world using the m_matRotate.
[ source ]
//in the app.h
D3DXMATRIX m_matRotate; // member variable matrix to hold the rotation.
float m_fZTranslation; // translation of the z-axis
float m_fRotation;

// in the app.cpp
// constructor or a one-time intit function
D3DXMatrixIdentity(&m_matRotate);

// key handler code
if(VK_UP) // example of incrementing the z-axis
m_fZTranslation+= 1.0f;
if(VK_RIGHT)// rotate
m_fRotation += .03f;

// move character done prior to rendering
D3DXMATRIX matTrans; // temp matrix to hold the tanslation
D3DXMatrixIdentity(&matTrans);

//Transform charactrer in the scene
D3DXMatrixTranslation(&matTrans,0,0,m_fZTranslation);
D3DXMatrixRotationY(&m_matRotate,m_fRotation ); D3DXMatrixMultiply(&m_matRotate,&m_matTrans,&m_matRotate);

[ /source ]

The reason this works is because the m_matRotate matrix holds the rotaion orientation and the translation position. If you notice the Translate Matrix function only increments the Z-Axis, when this is multiplied to the m_matRotate matrix that already holds the rotation orientation it will move the model where it''s facing.
I hope this could help you. I hope someone else posts with another way cause even though this way works it just doesn''t seem to be the best way.
-w

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011722
• ### Who's Online (See full list)

There are no registered users currently online

×