Jump to content
  • Advertisement
Sign in to follow this  
jagguy

position vector z confusion

This topic is 4455 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 .

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!