Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:41:01+00:00 2026-05-26T19:41:01+00:00

im creating a 3d room which you can walk around with a first person

  • 0

im creating a 3d room which you can walk around with a first person camera
i have defined the position of the eyeX eyeY and eyeZ as shown below:

float eyeX = 0; 
float eyeY = 100;
float eyeZ = 75;

here is my lookat code:

D3DXMatrixLookAtLH( &g_matView, &D3DXVECTOR3( eyeX, eyeY,eyeZ ),
                        &D3DXVECTOR3( LookatX, LookatY, LookatZ ),
                        &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &g_matView );

my code allows me to move the camera around but not like a first person camera and i am struggling to achieve this.

    //   forwards = UP ARROW 
    //   Backwards = DOWN ARROW  
    //   rotate left = LEFT ARROW     
    //   rotate right = RIGHT ARROW    



    case WM_KEYDOWN:
    {
        // Handle any non-accelerated key commands
        switch (wparam)
        {

    case VK_RIGHT:
    if(eyeX >=-50)
        {
            --eyeX;
        }

    return (0);


    case VK_LEFT:
    if(eyeX <=50)
        {
            ++eyeX;
        }
    return (0);


    case VK_DOWN:
    if(eyeZ >=-50)
        {
            --eyeZ;
        }

    return (0);


    case VK_UP:
    if(eyeZ <=50)
        {
            ++eyeZ;
        }
    return (0);


    case VK_SPACE:
    if(eyeY >=-50)
        {
            --eyeY;
        }

    return (0);


    case VK_SHIFT:
    if(eyeY <=50)
        {
            ++eyeY;
        }
    return (0);

        }
        break;
    }



    LookatX = eyeX + 5.0f;
    LookatY = eyeY;
    LookatZ = eyeZ;

    case WM_DESTROY: 
    {
        // kill the application         
        PostQuitMessage(0);

        return(0);
    }

    default:
        break;

} // end switch

could anyone suggest some changes which would allow me to move around my room like a first person camera?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:41:01+00:00Added an answer on May 26, 2026 at 7:41 pm

    Instead of using D3DXMatrixLookAtLH, you could keep a view matrix.

    Set up

    (Note that I am making up names of functions, you might have to create these yourself)

    Start with something like

    Matrix view = Matrices.createIdentity();
    

    Then every frame, you set the view matrix(just like you are doing with the matrix you are getting from MatrixLookAtLH)

    Moving around

    Normally modifing a model matrix is like this.

    model = Matrix.multiply(model,transformation).
    

    However, you manipulate the camera backwards

    view = Matrix.multiply(transformation, view)
    

    Simply run your switch statement, generate a transformation and update the view matrix.

    e.g:

    if (key == 'w')
      view = Matrix.multiply(Matrices.createTranslate(0,0,-5), view);
    
    if (key = 'j') // Key to turn
      view = Matrix.multiply(Matrices.createRotateY(.1), view);
    

    Formulas for genereating these matrices can be found on wikipedia(or DirectX might give them on its own).

    (This is all based off of a simple software renderer I made a while ago, but it should apply the same to DirectX)

    EDIT:
    Oh, it looks like DirectX has all of these functions for you already in http://msdn.microsoft.com/en-us/library/windows/desktop/bb281696(v=vs.85).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a bouncing object that can bounce around a 2D rectangular room.
I am creating a class where I defined a Struct called Room which I
Scenario : Creating a server which has Room objects which contain User objects. I
I was wondering if anyone can help me get started with creating a room
I have this function of mine which selects all room types from the database,
I have dynamic form about posting room ad and first option is: Room in:
I'm creating an initialising function for the class 'Room', and found that the program
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character
Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext.xml]: Invocation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.