Sign in to follow this  
prux

Direct3D, D3DFVF_XYZ ignores my Z value

Recommended Posts

Im using this article: http://www.two-kings.de/tutorials/dxgraphics/dxgraphics03.html this is how I built my program. But whatever Z value I set, the triangle remains perpendicularly to me. It ignores my Z value - what should I do? I dont touch any camera settings. And in addition, my values are bigger, about 200. Thx in advance.

Share this post


Link to post
Share on other sites

Hi,

While looking at the link you provided, I couldn't see any mentions of setting the projection matrix.

I guess that you are using an orthographic projection which could explain the results you are having (ie. z value not having an effect).

http://msdn.microsoft.com/en-us/library/ee422164(VS.85).aspx

Cheers!

Share this post


Link to post
Share on other sites
How are you changing the Z value? Do you still keep all the Z values of the vertices of a particular object (triangle/ quad) the same of did you try to make them different? Your remark about the triangle remaining perpendicular to the camera suggests the second case, imho. If this is true then I don't think it has anything to do with the orthographic projection matrix.

I would help us if you showed us the X, Y, Z values you are using and some screenshots of the result.

Share this post


Link to post
Share on other sites
here is the image: http://img230.imageshack.us/img230/8610/triangler.jpg

coordinates (x,y,z and diffuse)

100,100,50, [255,0,0,255]
200,200,100, [0,255,0,255]
100,200,-100, [0,0,255,255]

I set it once

Share this post


Link to post
Share on other sites
I didn't see your example, but it's probably the projection matrix. Try using a perspective matrix:

D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.5f, 1.0f, 100.0f);
pDevice->SetTransform(D3DTS_PROJECTION, &matProj);


According to what you described, the example might be using an orthogonal matrix.

EDIT: Anyway, if you a trying a perspective projection, a "single triangle" is not enough to notice the perspective effect. So, maybe it is working but you just couldn't notice.

Share this post


Link to post
Share on other sites
Quote:
Original post by prux
here is the image: http://img230.imageshack.us/img230/8610/triangler.jpg

coordinates (x,y,z and diffuse)

100,100,50, [255,0,0,255]
200,200,100, [0,255,0,255]
100,200,-100, [0,0,255,255]

I set it once


That can perfectly correspond to that image, there doesn't have to be any problem at all.
If you're looking in the direction of the Z axis, you won't be able to see whether the vertex is at Z = 50 or Z = -100.
Even perspective projection won't help you much if there's only one triangle on the screen.

If changing X and Y works, I bet also the Z changes are effective, it's just not easy to actually see it. You say it remains perpendicular to you, I say you cannot be sure about this ;)

Share this post


Link to post
Share on other sites
Quote:

Even perspective projection won't help you much if there's only one triangle on the screen.


Actually it does help. With perspective projection the triangle will get smaller/bigger as the Z value is changed

Quote:

when I set this matrix then only a black screen I can see.


You are probably looking into wrong direction or the triangle is clipped by z-buffer.

see this link
for information about direct3d matrices which is must-to-know information.

Cheers!

Share this post


Link to post
Share on other sites
Quote:

Actually it does help. With perspective projection the triangle will get smaller/bigger as the Z value is changed


If he's translating the whole triangle on the Z axis.
But if you hard-code the coordinates (one vertex Z100, other Z-100) and then run the application, it won't be very evident which triangle VERTEX is "smaller" and which "bigger" ;)

Share this post


Link to post
Share on other sites
Quote:

If he's translating the whole triangle on the Z axis.
But if you hard-code the coordinates (one vertex Z100, other Z-100) and then run the application, it won't be very evident which triangle VERTEX is "smaller" and which "bigger" ;)


Well, prove it :) I guess it depends greatly on the units he is using. 100 meters vs 100 cms vs 100 mm. Anyhow, the triangle shape would change.

Cheers!

Share this post


Link to post
Share on other sites
The triangle shape would change (a bit), yes. My point is that if you set some coordinates, start the application, check the triangle, stop the application, change the Z coordinates, start and check again, you can easily fail to notice the difference, becase the Z coord won't have such a great effect if you're looking down the Z axis.
Btw, I don't know what you meant by the units (m, cm, mm), D3D doesn't use physical units. A box 1.0 x 1.0 x 1.0 with the same camera settings will look the same whether it represents a 1 mm large dust seed or a 1 m crate.

Anyway, back to the topic - prux, have you advanced anyhow? Have you confirmed that the Z coordinate REALLY doesn't have any effect, regardless how it seems to be? ;)

Share this post


Link to post
Share on other sites
Set this matrix before your draw calls.

D3DXMATRIX mat(
1.0, 0.0, 0.1, 0.0,
0.0, 1.0, 0.1, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
);
pDevice->SetTransform(D3DTS_D3DTS_VIEW, &mat);

If the triangles change it means that andrew1b is right an you should check your transformations again.

Share this post


Link to post
Share on other sites
Quote:

The triangle shape would change (a bit), yes. My point is that if you set some coordinates, start the application, check the triangle, stop the application, change the Z coordinates, start and check again, you can easily fail to notice the difference, becase the Z coord won't have such a great effect if you're looking down the Z axis.


Possibly, but in this case I trust in Prux's observations and by looking the code links he provided I am strongly on the opinion that basically this thread is all about projection and camera matrices and between perspective/orthogonal projection.

Quote:

Btw, I don't know what you meant by the units (m, cm, mm), D3D doesn't use physical units. A box 1.0 x 1.0 x 1.0 with the same camera settings will look the same whether it represents a 1 mm large dust seed or a 1 m crate.


Units are something that the developer decide. It is true that Direct3D isn't based on any particular unit system. However, in order to make any sense in a 3d world, one must decide what 1 (D3D) unit represents.
For example, in one of my projects I used 1 (d3d)unit = 1 meter. So, moving 200 units in that scale system makes a huge difference compared to another project where I used 1 unit = 1 cm. Practically, this is all about the proportions and the distance of the camera to the object, but still it makes a difference.

Quote:

Anyway, back to the topic - prux, have you advanced anyhow? Have you confirmed that the Z coordinate REALLY doesn't have any effect, regardless how it seems to be? ;)


Anyway, back to the topic ... any success with your triangle? It may help to draw several triangles at different locations in 3d space when beginning to work with the view/projection/world matrices, since black screen is always confusing. Also, consider implementing some camera functionality to rotate the view in case the initial camera direction is looking into empty space.

Good luck!

Share this post


Link to post
Share on other sites
Quote:
Original post by prux
trying that matrix, I get this: http://img163.imageshack.us/img163/3939/image1ypb.jpg

even I set all the Z to 0, its the same.

I see. That is exactly how it should be. Now try a little bit different matrix and set your viewport rectangle to the output window dimensions (Please make sure that the width and height correspond to the real values.).

D3DVIEWPORT9 vp;
vp.X = 0;
vp.Y = 0;
vp.Width = // ouput window width
vp.Height = // output window height
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;

// The matrix is now transposed
D3DXMATRIX mat(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.1, 0.1, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
);

pDevice->SetTransform(D3DTS_D3DTS_VIEW, &mat);
pDevice->SetViewport(&vp);

Share this post


Link to post
Share on other sites
hmm the error must be somewhere elsewhere... if I change the fov, etc (D3DTS_PROJECTION) it doesnt have any effect. I will have to check my vertexes

Share this post


Link to post
Share on other sites
one more thing, if I turn the stencilbuffer on (AutoDepthStencilFormat:= D3DFMT_D16; EnableAutoDepthStencil:= TRUE;) it shows nothing. When I turn it off, everything works good, now with my camera system I can move in my 3D world greatly. Any idea with the stencilbuffer maybe?

Share this post


Link to post
Share on other sites
Quote:
Original post by prux
one more thing, if I turn the stencilbuffer on (AutoDepthStencilFormat:= D3DFMT_D16; EnableAutoDepthStencil:= TRUE;) it shows nothing. When I turn it off, everything works good, now with my camera system I can move in my 3D world greatly. Any idea with the stencilbuffer maybe?


Quote from msdn

Quote:

If EnableAutoDepthStencil is true, AutoDepthStencilFormat must be a valid depth stencil format.


It seems that AutoDepthStencilFormat:= D3DFMT_D16 isn't valid depth stencil format, which is logical since D3DFMT_D16 is a depth only format.

Cheers!

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