2
\$\begingroup\$

So I have a model of a spear and when it gets thrown I want to set the orientation of the spear to its direction. ( I also want to use this for other things like bullets pointing in the direction they are moving in)

my Models local forward Vector is +Z and I have the direction that it is moving in (in world space) from the velocity but I can't work out how to rotate it locally so that it is always pointing the right direction.

I tried to work out the difference in the angles and then create a Rotation matrix to apply to its rotation, but that didn't give me the desired results.

I am working in DirectX. Any help would be appreciated

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You could rebuild the spears orientation matrix from a direction vector.

Good example with dx code is here..

https://stackoverflow.com/questions/4237873/rotate-a-sphere-so-that-its-pole-heads-towards-the-camera/4237921#4237921

\$\endgroup\$
8
  • \$\begingroup\$ Hmm, I understand the maths, but maybe a silly question but what would you then do with the orientation matrix? \$\endgroup\$
    – unknownSPY
    Commented Apr 6, 2016 at 15:18
  • \$\begingroup\$ I tried applying the orientation matrix as a rotation matrix on the current rotation of the object using D3DXVec3TransformCoord but that had very odd affects on the rotation \$\endgroup\$
    – unknownSPY
    Commented Apr 6, 2016 at 15:43
  • \$\begingroup\$ You dont apply it, you need to set it. The matrix you create is a replacement for the spear matrix. \$\endgroup\$
    – RobM
    Commented Apr 7, 2016 at 9:23
  • \$\begingroup\$ Sorry I don't understand, Where would I set this? \$\endgroup\$
    – unknownSPY
    Commented Apr 7, 2016 at 9:35
  • \$\begingroup\$ Please could you clarify how I would reset/ rebuild a models orientation matrix (at runtime)? \$\endgroup\$
    – unknownSPY
    Commented Apr 11, 2016 at 7:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .