| | |
Directx Input / Movement Q
Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 30
Reputation:
Solved Threads: 0
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.
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.
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:
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:
so,
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.
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
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 )
player.x += cos ( r ) * speed; player.y += sin ( r ) * speed;
Plato forgot the nullahedron..
•
•
Join Date: Sep 2008
Posts: 30
Reputation:
Solved Threads: 0
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
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
Last edited by Richy321; Feb 25th, 2009 at 7:56 am.
![]() |
Similar Threads
- Mouse Lag in Games (Windows NT / 2000 / XP)
- Issue with DirectX (Game Development)
- special keys as inputs (Game Development)
Other Threads in the Game Development Forum
- Previous Thread: OpenGL problem
- Next Thread: Making Text Based Game
| Thread Tools | Search this Thread |
Tag cloud for Game Development
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamedevelopment gameprogramming gamer games gaming gauntanamo government graphics idaho in-gameadvertisement intel intellectualproperty l-systems laracroft larrabee lindenmayer live manhunt math mathematics matrix mercenaries microsoft mmorpg modded msn multicore naked news nintendo obama opengl palin physics pirate playstation politics processor projection ps3 rpg search selection software sony stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360






