Vertices For TriangleList and X,Y,Z Explanation Needed

Started by
4 comments, last by gp343 20 years, 4 months ago
Hi there i''m experiencing Problems with how vertices are render in Managed DirectX. I''m trying to create a box 6 sided. I have seen how tom miller did his in his book, however I cannot understand how he did the left side, right side, back,top, and bottom side. Ideally my overall plan is to create a plane or base for a house i want to model. I really don''t know how to visualize these vertices. Especially the X,Y,Z coordinate systems. Please Help. James
Advertisement
Think about it plane at a time. Write it down too, that always helps. I''m going to describe a cube that is centered in the middle of the monitor. The front wall of the cube is out in front of the monitor, the back wall is back inside the monitor, the left and right walls are the left and right walls of the monitor, and the bottom and top are the bottom and top of the monitor.

Front and back walls use: XY Plane (no change in Z)
Left and right walls use: YZ Plane (no change in X)
Top and bottom walls use: XZ Plane (no change in Y)

First, let''s do the XY plane. So imagine a normal graph (like ones you''ve seen in school) with just x and y, flat. The one thing common to all vertices lying on that graph is that z never changes. In the case of a sheet of paper, z=0. In the case for the front wall of our cube, z = -1. So for your vertices (points) on the graph,

Pt1: x = -1, y = -1, z = -1
Pt2: x = -1, y = 1, z = -1
Pt3: x = 1, y = 1, z = -1
Pt4: x = 1, y = -1, z = -1

These are the four points needed for a square in the XY plane. Now, you''ll have to order them appropriately when creating the vertex buffer to get what you want, but it''s going to be at least 3 out of these 4 that you use (you use 3 in a triangle list).

Now, think about the z axis, where it is and what it is. Imagining that your monitor is the flat XY plane, Z is defined (in directX) as positive into the monitor. So if you go 1 unit into the monitor, that''s Z = 1. We''ll call that the back wall of the cube. It uses the same points above, except Z = 1.

Now, we want a left and right wall. The commonality of the left wall and the front wall is the vertices along which axis? The Y Axis. Which axis does not change? The X Axis. So all x axis values are -1 this time. But now the Z values are going to range from 0 to 1 for each point.

Pt1: x = -1, y = -1, z = -1
Pt2: x = -1, y = -1, z = 1
Pt3: x = -1, y = 1, z = 1
Pt4: x = -1, y = 1, z = -1

For the right wall, x is simply now equal to 1. You might have noticed above that it looks very similar to the first set of points (for the front and back wall). All I did was rotate the actual values to the right. For instance, in the first set of points, Pt2 got rotated from (-1, 1, -1) to (-1, -1, 1).

As you can probably guess, if you rotate them again, you''ll have your bottom wall. Pt2 went from (-1, -1, 1) to (1, -1, -1).

Pt1: x = -1, y = -1, z = -1
Pt2: x = 1, y = -1, z = -1
Pt3: x = 1, y = -1, z = 1
Pt4: x = -1, y = -1, z = 1

Of course to create your top wall, all you need to do is substitute y = 1 instead of -1.

Now on to trianglelists. A triangle list is simply defined by a series of vertices. The first 3 vertices in the vertex buffer determine the starting triangle. Then you add one more vertice and the hardware takes that one plue the previous two vertices to create the next triangle. Draw it out to fully understand it. That''s all there is to triangle lists. One thing to keep in mind, you will want to turn culling off while learning all of this. Then learn what culling is.

Good luck,
Chris
Chris ByersMicrosoft DirectX MVP - 2005
Hey Chris, Man Millions of Thanks, i have finally gotten to grisp with it, thanks to your tips.

All the best

James
quote:Original post by Supernat02


Now on to trianglelists. A triangle list is simply defined by a series of vertices. The first 3 vertices in the vertex buffer determine the starting triangle. Then you add one more vertice and the hardware takes that one plue the previous two vertices to create the next triangle. Draw it out to fully understand it. That's all there is to triangle lists. One thing to keep in mind, you will want to turn culling off while learning all of this. Then learn what culling is.


I would like to correct you on this. From the DirectX SDK:

D3DPT_TRIANGLELISTRenders the specified vertices as a sequence of isolated triangles. Each group of three vertices defines a separate triangle.        


I think you meant a triangle strip, or an indexed triangle list.

[edited by - foofightr on November 30, 2003 7:05:26 PM]
Perhaps he was referring to a triangle fan?

D3DPT_TRIANGLEFAN
Renders the vertices as a triangle fan
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
Sorry about that, I was referring to a triangle strip! Thanks for pointing out the error.

Chris
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement