View matrix Problem

Started by
7 comments, last by Kalthorn 17 years, 10 months ago
What would cause a quad to completely disappear when only a slight location change is made to the location of the View matrix? Specifically: device.Transform.View = Matrix.LookAtLH (new Vector3(0, 10, -25), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); Changing the z value of the location vector to anything less than -25 (-26, etc) or going above 12y or positive X will make it just up and disappear. I'm sure many other random values will or won't work but I'm looking for a general reasons this might happen. Backface culling is off. I've heard that making a look at vector parallel to the world up vector makes things go screwy but that should not be the case here. My quad upper left is at the origin while the bottom right is at (10,0,-10). Anything to point me in the right direction is appreciated.
Advertisement
this is java right? cause if its C++ those new statements are memory leaks.. neway, my guess would be your projection matrix is set to clip at past those values. this code is in C++ but it shouldnt be hard to convert:

    D3DXMATRIX matProj;    FLOAT fAspect = ((FLOAT)pBackBufferSurfaceDesc->Width) / pBackBufferSurfaceDesc->Height;    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 1000.0f );    V(pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ));


you can look up the function but the 1.0 and the 1000.0 are the minimum and maximum z values. The D3DX_PI/4 is the number of radians you can see (the higher it is the wider your view).
my guess would be its something like this:
float aspect = device.BackBufferSurfaceDesc.Width/device.BackBufferSurfaceDesc.Height;device.Transform.Projection = Matrix.MatrixPerspectiveFovLH(3.141592/4,aspect,1,1000);
The code is C#. My projection matrix is exactly as both of yours with a depth range of 1 to 100.
well where is the quad then? is the z value of the quad 75?
The quad is on the X/Z plane. The upper left point on the quad is at the origin (0,0,0) the the bottom right is at (10,0,-10). The other points are (10,0,0) and (0,0,-10).

So I'm just looking forward and down on the a square from the view matrix.
the call:

Matrix.LookAtLH
(new Vector3(0, 10, -25), new Vector3(0, 0, 0), new Vector3(0,1,0))

returns this matrix:

viewMatrix
{Determinant: 0.9999998
M11: 1
M12: 0
M13: 0
M14: 0
M21: 0
M22: 0.9284766
M23: -0.3713906
M24: 0
M31: 0
M32: 0.3713906
M33: 0.9284766
M34: 0
M41: 0
M42: 0
M43: 26.92582
M44: 1
}

My position values are completely wrong. Using the same vec3 later with matrix.Translate gets the location values correct.
whats wrong with that matrix? It has to both rotate and translate so I dont see anything noticeably wrong.
Yeah I just realized that. I guess I have lost my matrix math skills. Thanks for the help though!

This topic is closed to new replies.

Advertisement