Sign in to follow this  
sambsp

[question:]transform problem

Recommended Posts

I'm considering such a case if I want to develop a snooker game by using Direct3D,each time I need to render all the balls, the step to render a ball will look like, 1. Compute the rotation matrix and translation matrix of this ball 2. Combine those 2 matrixes 3. Use SetTransform() to apply the matrix from combination 4. Use DrawPrimitive() to draw this ball Then, we render next ball with different rotation matrix and translation matrix; And next ball ... Now my question coming, how about the z-order? Such a rendering method will cause the problem, am I right? Then, how ... I'm the newbie of Direct3D, as I have learned till now, I feel that the transform will apply to all the vertices valid in function DrawPrimitive(), so I cannot just throw all balls' vertices into the drawing function and let the Direct3D test the z-order, since different ball maybe has different rotation angle, and different translation step. Am I right?

Share this post


Link to post
Share on other sites
You can just throw all balls' vertices into the drawing function and let the Direct3D test the z-order. It is called z-buffering and it will make sure that objects in your scene overlap and intersect as they should. It is explained fairly well in the docs (do a search for 'z-buffer'). You may still have to order your objects for the sake of culling and performance, but z-buffering will work with your transforms and is easy to setup.

Share this post


Link to post
Share on other sites
To turnpast:
I know I can throw all the vertices into drawing function and let Direct3D test the z-order for me. But as I have represented,
the different ball need different transformation matrix, not the same, so, how about this?

Share this post


Link to post
Share on other sites
Quote:
1. Compute the rotation matrix and translation matrix of this ball
2. Combine those 2 matrixes
3. Use SetTransform() to apply the matrix from combination
4. Use DrawPrimitive() to draw this ball


this looks fine to me, dont worry about setting your world transforms several times a frame, all games do it. What you might want to consider for performance is batching so that two objects with the same transform render together (so u dont have redundant transforms). But even this isnt a major issue, as I see it, a pool game cant have all that many meshes to give you trouble with setting transforms multiple times.
Another good performance optimization is concatenating the view and world matrices, and setting only the world transform (even when you move the camera). The sdk docs are pretty good on this subject too..

Share this post


Link to post
Share on other sites
Ok, let me try to explain how the z-buffer works (as I understand it) and why it does not matter what transforms you use. I hope that this is addressing your question.

The z buffer (or depth buffer) should match the size of the render target and at render time it gets drawn on just like the screen (or whatever your target is). The big difference between the depth buffer and the selected target is that the depth value of every point is drawn on it rather than the color. Now whenever you draw something the depth buffer is used as a sort of mask to determine what points can and cannot be seen. All of this happens after your transformations have been applied. Your World and View matricies really have nothing to do with the depth buffering.

I am not sure that everyting I said is right, there is a fairly good explination of this in the docs if you want more information.

Hope this is some help.

Share this post


Link to post
Share on other sites
Quote:
I am not sure that everyting I said is right, there is a fairly good explination of this in the docs if you want more information.


You're exactly right. Though the Z-Buffer is not a mask in the conventional sense, as the stencil buffer is. The Z-buffer distributes depth values exponentially over distance 0 to infinity. So objects closer to you have much better depth information than those farther away. The W-buffer on the other hand stores them linearly (as I recall) so the depth values are more evenly distrubuted.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi, all:
As I know, the z-buffer can be disabled/enabled by user, if I don't use it, will the Direct3D draw my all balls correctly regardless the order I draw them?

Share this post


Link to post
Share on other sites
Quote:
As I know, the z-buffer can be disabled/enabled by user, if I don't use it, will the Direct3D draw my all balls correctly regardless the order I draw them?


no it is the opposite of what you say. If you enable the Zbuffer and create the device with EnableAutoDepthStencil set to TRUE, then d3d will draw your meshes correctly regardless of what order you draw them. If you disable Zbuffering then you MUST draw the scene back-to-front to get the overlaps correct.

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