# D3DXMatrixLookAtLH Questions

• 04-06-2004
X PaYnE X
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
• 04-06-2004
VirtualAce
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.