Thread: direction in directx

  1. #1
    Unregistered
    Guest

    direction in directx

    i'm writing a first person perspective demo in directx 8, and i was wondering if anyone could give me any ideas on how they go about finding out which direction the user is facing...right now, if the user presses the up key, i increment both Z axis coordinates, etc, so the user "walks" forward. but if they turn and press up, there is an obvious problem...can anyone tell me the best way to know which way they are facing and also which axis' to increment/decrement based on this direction? thanks!

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can set up a translation matrix for the amount of z-axis units moved. Set up a rotation matrix for the amount of y-axis rotation. Multiply these two together and translate your View Translation matrix by the result. This code updates the view matrix by the change in x-axis,z-axis and y rotation (strafing,walking backwards/forwards and turning) -

    D3DXMATRIX rot_view;
    D3DXMATRIX tran_matrix;
    z-=z1;
    x-=x1;
    r-=r1;

    D3DXMatrixTranslation(&tran_matrix,-x,0.0f,-z);
    D3DXMatrixRotationY(&rot_view,r);
    D3DXMatrixMultiply(&tran_matrix,&rot_view,&tran_ma trix);
    D3DXMatrixMultiply(&view_matrix,&view_matrix,&tran _matrix);

    x1 = x;
    z1= z;
    r1=r;

    This assumes you already have your View Translation matrix set up in the D3DXMATRIX view_matrix and that x,z and r are the total amounts to translate/rotate and x1,z1 and r1 are static variables.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mouse Maze Problem
    By Furbiesandbeans in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2008, 04:20 PM
  2. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 12:16 PM
  3. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  4. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM
  5. Classic problem doesn't accept direction
    By cheesehead in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2001, 06:32 PM