D3DXMatrixLookAtLH Questions

This is a discussion on D3DXMatrixLookAtLH Questions within the Game Programming forums, part of the General Programming Boards category; Im trying to create a plane on the X/Y Plane, im setting up my Camera on the Z axis as ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    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:

    Code:
    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:

    Code:
    D3DXMatrixIdentity(&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.

    PaYnE
    Attached Images Attached Images  

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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.

    Code:
    D3DXVECTOR3 position(0.0f,0.0f,-50.0f);
    D3DXVECTOR3 target(0.0f,0.0f,0.0f);
    D3DXVECTOR3 up(0.0f,1.0f,0.0f);
    
    D3DXMATRIX V;
    D3DXMatrixLookAtLH(&V,&position,&target,&up);

    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.

    Code:
    D3DXMATRIX proj;
    D3DXMatrixPerspectiveFovLH(&proj,PI*.5f,(float)screenwidth/(float)screenheight,1.0f,500.0f);
    Device->SetTransform(D3DTS_PROJECTION,&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. questions....so 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 Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21