Sign in to follow this  
Freaky

SetTransform no effect

Recommended Posts

It seems as if SetTransform has no effect what so ever. I can see the following triangle: Vertex 1: (150.0f, 50.0f, -5.0f) Vertex 2: (250.0f, 250.0f, -5.0f) Vertex 3: (50.0f, 250.0f, -5.0f) But I can't see the following triangle: Vertex 1: (-1.0f, 1.0f, -5.0f) Vertex 2: (0.0f, -1.0f, -5.0f) Vertex 3: (1.0f, 1.0f, -5.0f) Is this known behavior? Someone please explain cause I'm new to DirectX and have been coding with OGL all the time. This problem doesn't make me like D3D more :) Here is the code I have been using to setup my view & projection matrix. (Don't notice the hardcoded 640 & 480, during development I grew tired of it not working :)
	// Set a appropriate view matrix
	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH (&matProj, D3DX_PI / 4, (float) 640 / (float) 480, 1.0f, 7500.0f);
	pDev->SetTransform (D3DTS_PROJECTION, &matProj);

	D3DMATRIX trans, rots, cameraMatrix;
	D3DXMatrixTranslation((D3DXMATRIX*)&trans,0.0f,0.0f,10.5f);
	D3DXMatrixRotationX((D3DXMATRIX*)&rots, 0.0f);
	D3DXMatrixMultiply((D3DXMATRIX*)&cameraMatrix,(D3DXMATRIX*)&rots,(D3DXMATRIX*)&trans);
	
	D3DXMatrixRotationY((D3DXMATRIX*)&rots, 0.0f);
	D3DXMatrixMultiply((D3DXMATRIX*)&cameraMatrix,(D3DXMATRIX*)&rots,(D3DXMATRIX*)&cameraMatrix);
    
	//Set the camera matrix
	pDev->SetTransform(D3DTS_VIEW,&cameraMatrix);

	D3DMATRIX worldMatrix;
	D3DXMatrixIdentity((D3DXMATRIX*)&worldMatrix);
	pDev->SetTransform(D3DTS_WORLD,&worldMatrix);

Thx in advance everybody, Freaky Edited by Coder: Some lines are too wide for code tags. Used source tags. [Edited by - Coder on August 18, 2004 10:13:20 AM]

Share this post


Link to post
Share on other sites
Are you using the RHW component in your vertices? It instructs D3D not to perform any transformations against the vertex data, because it assumes that you have transformed the vertices in your program already as needed.

As a sidenote, depth near/far ratio of 1/7500 in your projection is not good in most situations - if you use a 16-bit depth stencil, the z precision is terrible (and this is somewhat true with 24- or 32-bit depth formats as well).

Kind regards,
-Nik

Share this post


Link to post
Share on other sites
Just a thought, what is your flexible vertex format set as ?

Also, I usually set my world transform before my view.

Sure the translation matrix is putting the triangle into view ?


Share this post


Link to post
Share on other sites
My current FVF:


#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
struct VERTEXDATA
{
FLOAT x, y, z;
DWORD color;
};

I used the RHW component at first. This doesn't solve the problem however.

Anybody care to supply transformation matrices (view, projection & world) which are sure to display the following triangle:

Vertex 1: (-1.0f, 1.0f, -5.0f)
Vertex 2: (0.0f, -1.0f, -5.0f)
Vertex 3: (1.0f, 1.0f, -5.0f)

Thx in advance,

- Freaky

Share this post


Link to post
Share on other sites
Maybe it's because i'm still drunk :D but shouldn't the matrices I combined above show the triangle?

If not, i'd like to find out which matrices DO actually show the triangle :D Gives me something to work with ;)

Again thx,

- Freaky

Share this post


Link to post
Share on other sites
I recommend using D3DXMatrixLookAtLH for view matrix generation, at least when you're learning D3D. That way, you have well-defined vectors (eyepoint, target, up direction) as parameters, instead of separate translation and rotation steps, and the "camera" position is easier to understand.
Of course, in the last steps of optimizing the code, you may want to construct your own view matrix from the beginning anyway.

-Nik

PS. A common (but often overlooked) reason for this behavior is that the geometry is simply too small. Do test this by moving the eyepoint closer to the triangle.

Share this post


Link to post
Share on other sites
I agree on several notes. Reduce your 7500 far clipping plane to something smaller. Try 1000, though I wouldn't think that affects this problem. Secondly, if you can see a triangle at x and y equal to 250 units, and it's not taking up the full screen, you won't be able to see one that's 2 units across, like your smaller (tiny tiny rather) triangle. Try increasing the size of the triangle.

If that doesn't do it, there's something you're not showing up, code-wise, that's doing it. If so, show us the code that you use to draw the triangles. And explain or show the way you initialize them, i.e. both initialized with the same color and normals.

Chris

Share this post


Link to post
Share on other sites
damn freaky I had a program yesterday that displayed a triangle of exactly that size in wold space. I dont have my source on this computer but my view matrix was at 0,0, -15. and was pointing at 0,0,0. The triangle was at 0 on the Z axis. Hopefully that I'll try to paste my code for you later if I remember.

Share this post


Link to post
Share on other sites
xegoth, I would really appreciate it if you would try to remember your code :)

So far for my first contact with DX :P. Maybe it's a hint I should stick to OpenGL :P

I'll keep on trying and waiting for xegoth.

Thx again,

- Freaky

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this