943,753 Members | Top Members by Rank

Ad:
Feb 24th, 2009
0

Directx Input / Movement Q

Expand Post »
Ok so this is probably a stupid quesiton with an easy answer. Im learning directx and trying to create a simple 3d game. I need to move my character in the direction its facing rather than just using by the world axis.
I think its some easy maths i feel asleep during at school a quick hint would be appriecated.
Last edited by Richy321; Feb 24th, 2009 at 12:49 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Richy321 is offline Offline
31 posts
since Sep 2008
Feb 24th, 2009
1

Re: Directx Input / Movement Q

Are your transforms 'full 3d' or 'half 3d'? That is, when your character rotates, can they rotate over all axes, or just around an 'up' vector? Are you using matrices as the authoritative representation of the character's transform, or some scalars ( typically x, y,z and rotation ).

MATRICES

If you're using transform matrices, the vector that points 'forward' in the character's space is one of the vectors in the upper 3x3 submatrix, the actual vector depends on the way you define 'up' and 'forward', and whether the vector is a row or column of the matrix depends on whether you treat vectors as rows or columns.. but for e.g., in OpenGL, it would usually be:
m00 m01 m02 m03
m10 m11 m12 m13
m20 m21 m22 m23
m30 m31 m32 m33
the usual 'forward' vector (z) is emboldened. If you extract 'forward' from the character's matrix, and add if to the character's position, it will move the character in their own 'forward'.

I know for a fact that this is different in most DX setups, but it will be quite similar, most likely the row m20->m22, assuming that z is forward, which it isn't always.

SCALARS

If you're just using x, y, z and rotation scalars.... then assuming that positive z is 'up' and positive x is 'forward'... the forward direction vector is:
x = cos ( r )
y = sin ( r )
so,
player.x += cos ( r ) * speed;
player.y += sin ( r ) * speed;
should work. if it comes out sideways ( i.e moving to the left/right rather than back/forward, then change to cos ( r + ( pi / 2 ) ) and sin ( r + ( pi / 2 ) ), or minus, perhaps multiply all by -1: it all depends on how you interpret components in your code.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Feb 25th, 2009
0

Re: Directx Input / Movement Q

Thank you for your detailed responce, i will try this when i get home from work and get back to you.

nb. i am using half 3d but wil probably implement full 3d for code reusability as im attempting to create a framework for multiple game demos.

For anyone else reading directx matrix is:

http://msdn.microsoft.com/en-us/libr...69(VS.85).aspx
Attached Thumbnails
Click image for larger version

Name:	Bb206269.matmult(en-us,VS.85).gif
Views:	169
Size:	2.2 KB
ID:	9341  
Last edited by Richy321; Feb 25th, 2009 at 7:56 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
Richy321 is offline Offline
31 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: OpenGL problem
Next Thread in Game Development Forum Timeline: Opengl problem transformation/rotating.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC