void Draw(float x, float y, float z, LPDIRECT3D9TEXTURE Texture, RECT Rec)
{
D3DXMatrixLookAtLH(&Mat, //Matrix Stored in
&D3DXVECTOR3(0.0f, 3.0f, -5.0f), //Position of the Camera
&D3DXVECTOR3(0.0f, 0.0f, 0.0f), //Where Camera is looking to
&D3DXVECTOR3(0.0f, 1.0f, 0.0f)); //Points Straight up (for rotation or something?)
ID3DXSprite->SetWorldViewLH(NULL, //World Transformation
&Mat);
D3DXMatrixTransformation(&vMat, NULL, NULL, NULL, NULL, NULL, &D3DXVECTOR3(x, y, z);
ID3DXSprite->Begin(D3DXSPRITE_SORT_DEPTH_BACKTOFRONT);
ID3DXSprite->SetTransform(&vMat);
ID3DXSprite->Draw(Texture, &Rec, NULL, NULL, 0xFFFFFFFF);
ID3DXSprite->End();
}
Camera Positioning
My whole goal here is trying to sort my sprites by the Z-Order, which is not working out to well, I think it's because of how i'm trying to place my camera..
What i'm doing is something like this
(a little drawing function similar to how mine is)
So I have a couple questions I guess..I supposedly set my camera (0, 3, -5) and looking at the orgin, but yet, for my view Transformation I can only set my z coordnate between 0.0, and 1.0?
And secondly, (main question) no matter what z value I pass in there, it always paints the textures in the order I paint them..as if i didn't even put a z value in there..
I'm not an expert on ID3DXSprite, so I'm not 100% sure...
Now, I believe the reason your sprites aren't being sorted correctly is that Begin/End is called for every sprite. If you call Begin/End once for all your sprites, they will be sorted (plus rendering will probably be a lot faster). Also, you don't need to set the view matrix for every sprite. Try changing your code to work like this:
Quote:Original post by kag1
... I supposedly set my camera (0, 3, -5) and looking at the orgin, but yet, for my view Transformation I can only set my z coordnate between 0.0, and 1.0? ...
D3DXMatrixLookAtLH(&Mat, ... ); ID3DXSprite->SetWorldViewLH(NULL, &Mat);
This creates and sets the view matrix, not the world matrix.Now, I believe the reason your sprites aren't being sorted correctly is that Begin/End is called for every sprite. If you call Begin/End once for all your sprites, they will be sorted (plus rendering will probably be a lot faster). Also, you don't need to set the view matrix for every sprite. Try changing your code to work like this:
D3DXMatrixLookAtLH( &Mat, ... ); ID3DXSprite->SetWorldViewLH( NULL, &Mat ); ID3DXSprite->Begin( D3DXSPRITE_SORT_DEPTH_BACKTOFRONT ); for ( ... ) { Draw( x, y, z, texture, rec ); } ID3DXSprite->End();void Draw( float x, float y, float z, LPDIRECT3D9TEXTURE Texture, RECT Rec ){ D3DXMatrixTransformation( &vMat, NULL, NULL, NULL, NULL, NULL, &D3DXVECTOR3(x, y, z ); ID3DXSprite->SetTransform( &vMat ); ID3DXSprite->Draw( Texture, &Rec, NULL, NULL, 0xFFFFFFFF );}
Wow Great, it works now (kinda) the reason was as you said because they were all in their own Begin and End Sections...
but now..i'm kind of upset I can't turn AlphaBlending on half way through the Begin() - End()..and if I do, it doesn't work..
I have to put them in 2 different Begin() -- End() groups..and then because of that, the Z Orders won't matter between the transparent and non transparent Textures..
not that it matters a whole lot..but...Is there anyway around this one?
Thanks again JohnBolton
but now..i'm kind of upset I can't turn AlphaBlending on half way through the Begin() - End()..and if I do, it doesn't work..
I have to put them in 2 different Begin() -- End() groups..and then because of that, the Z Orders won't matter between the transparent and non transparent Textures..
not that it matters a whole lot..but...Is there anyway around this one?
Thanks again JohnBolton
JohnBolton.Rating++;
Draw the opaque sprites front-to-back (front-to-back is generally faster than back-to-front, but unsorted may be faster than either). Then draw the alpha-blended sprites back-to-front (back-to-front is required so the alpha-blending looks right).
As long as you're not clearing your depth buffer, it shouldn't matter if you have multiple Begin/End calls because all the pixels in the depth buffer are unaffected unless you Clear() them.
are you sure ZTest is enabled? (its a SetRenderState value). and unless you're using pre-transformed and lit vertices (XYZRHW), you can set the maximum/minimum zvalues by changing your perspective transformation matrix (D3DXMatrixPerspectiveFovLH, for example).
while sorting back to front is necessary with alpha blending (unless you get into 'depth slicing' which is a technique to avoid sorting, but its a bit complex), sorting front to back for all your other polys doesn't really provide that much of a speed boost as cards nowadays are very efficient at testing/rendering very quickly, as opposed to using CPU time to sort through all your polygons before sending them off to the graphics card.
are you sure ZTest is enabled? (its a SetRenderState value). and unless you're using pre-transformed and lit vertices (XYZRHW), you can set the maximum/minimum zvalues by changing your perspective transformation matrix (D3DXMatrixPerspectiveFovLH, for example).
while sorting back to front is necessary with alpha blending (unless you get into 'depth slicing' which is a technique to avoid sorting, but its a bit complex), sorting front to back for all your other polys doesn't really provide that much of a speed boost as cards nowadays are very efficient at testing/rendering very quickly, as opposed to using CPU time to sort through all your polygons before sending them off to the graphics card.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement