position vector z confusion

Started by
6 comments, last by jagguy 17 years, 8 months ago
Using D3DXVECTOR3 I find that the z component doesn't work well. In a 2d tiled map if I display things at position z > 1.0 at it doesn't display at all. So what is the point of the z and how does it work ?
Advertisement
The Z should be for 3D applications, its the 3rd dimension, it indicates depth, and when you push it past 1, it seems to be outside of the cameras valid viewing area. There are two clipping planes which determine where the cameras viewing starts and stops, so the renderer can determine if an object is visible or not. Keep it at 0 if you're working in 2D. What kind of view are you using? Ortho?

View Frustum

[Edited by - ScottC on August 13, 2006 3:12:04 AM]
I know the z is for 3d. I wanted to do a 2d game where you go into the screen and having a z component solves this.

Is the clipping plane automatically set for the use of sprite or can you set it so you can use z .
You might want to check your nearplane setting, this is where objects start to get clipped.

Also, you probably want to use a orthological matrix for 2d stuff.
Quote:Original post by jagguy
I know the z is for 3d. I wanted to do a 2d game where you go into the screen and having a z component solves this.

Is the clipping plane automatically set for the use of sprite or can you set it so you can use z .


You'll want to be using an orthographic view, i'm not familiar with Direct3D though, only OpenGL. You would be best off posting in these forums asking how to set up an orthographic viewport in Direct3D.
Are you using pretransformed vertices (ie. D3DFVF_XYZRHV)? In that case z needs to be in the range [0..1] and directly maps to the z buffer.

Be careful, i found that using exactly 1.0f will be clipped on some cards (rounding error?) so for the maximum use something like 0.9999f.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I am using sprites not vertices/textures.
Where do you set the plane clipping settings with the sprite anyway as the regular projrct view has no effect.

q)ID3DXSprite::SetWorldViewLH I thought you could set things up with this so you can put a sprite along a z axis. This didn't seem to do that, if anything at all.
This does allow you to have a z value for a sprite but reduces the actual screen in doing so. If you place a tile at (x,y,5) all the tiles are small and in left hand corner.

D3DXVECTOR3 vEyePt( 0.0f, 0.0f, -5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_Sprite->SetWorldViewLH (NULL,&matView);
// g_Sprite->SetTransform( D3DTS_VIEW, &matView );


D3DXMATRIX matProj;

D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
640.0f / 480.0f, 1.0f, 1000.0f );

// g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
g_Sprite->SetTransform(&matProj );

This topic is closed to new replies.

Advertisement