Thread: D3DXMatrixLookAtLH Questions

  1. #1
    Registered User
    Join Date
    Aug 2003

    D3DXMatrixLookAtLH Questions

    Im trying to create a plane on the X/Y Plane, im setting up my Camera on the Z axis as shown in the image attached

    When using the D3DXMatrixLookAtLH function i set these parameters:

    D3DXVECTOR3 vLookatPt(0, 0, 0);
    D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);
    D3DXVECTOR3 vEyePt(0, 0, -25);
    D3DXMatrixLookAtLH(&Matrix, &vEyePt, &vLookatPt, &vUpVec);
    My first question is: Why is it that when i change the vUpVec to (0.0f, 0.0f, 1.0f), i dont get anything on my screen when i render, but it should be right, im using the Z axis for up.

    Second question: The plane i drew is a perfect square, 5x5, but when it renders, i get a rectangle, why is that?

    Heres the code for the Projection and World matrix:

    g_Device->SetTransform(D3DTS_WORLD, &Matrix);
    D3DXMatrixPerspectiveFovLH(&Matrix, D3DXToRadian(45), 1.0f, 1.0f, 50.0f);
    g_Device->SetTransform(D3DTS_PROJECTION, &Matrix);
    Any help would be appreciated, thanks.


  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    The problem is that Direct3D is clipping your geometry on the z axis. You must translate away from the plane in question and then render it. Basically you are inside of your geometry - all D3D planes range from 1 to somevalue with 1 being the smallest. It can't be zero because that would cause a divide by zero error.

    So translate the object in question 50 to 100 units on z and then render it. You will see it then. And your up vector shows that your Z is not up and down, your Y is. I would not change the default behavior of your 3D system until you get the full gist of what is taking place - it will only serve to confuse you. Always have x be left/right, y up/down, and z in/out on screen.

    D3DXVECTOR3 position(0.0f,0.0f,-50.0f);
    D3DXVECTOR3 target(0.0f,0.0f,0.0f);
    D3DXVECTOR3 up(0.0f,1.0f,0.0f);

    A perfect square in memory is not always a perfect square on the screen. Most popular screen ratios have more horizontal pixels than vertical. This will cause the top and bottom of your square to look smaller than the left and right sides. You should account for this ratio in your perspective transformation.

    D3DXMATRIX proj;
    You are doing a 1.0 to 1.0 projection and you need a screenwidth to screenheight projection.

    float aspectratio=(float)screenwidth/(float)screenheight;

    So on a 640x480 screen your aspect ratio is 1.333f, that is there are 1.333 horiztontal pixels for every 1 vertical.
    Last edited by VirtualAce; 04-06-2004 at 08:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM