View Poll Results: Which Graphics Library do you use primarily?
- Voters
- 23. You may not vote on this poll
-
Mar 4th, 2002, 09:51 AM
#11
Its pretty simple, once you get going. You start at the origin, 0.0f, 0.0f, 0.0f (just about everything uses floats =). Once you know where you start, you can define vertices. The simplest visible vertes is defined as:
Code:
struct VERTEX {
float x; float y; float z;
unsigned long color;
};
Very simply, x, y, z coordinates, with a color. I usually use Y for up, but you can set this to anything you want. Then, to actually define your vertices, you need a buffer of some sort (D3D8 uses vertex buffers for speed, while OGL can use simple pointers). For simplicity, I will just use a pointer...
Code:
VERTEX* verts = new VERTEX[3];
verts[0].x = 0.0f; verts[0].y = 1.0f; verts[0].z = 0.0f; verts[0].color = 0x00ff0000;
verts[0].x = 0.5f; verts[0].y = 0.0f; verts[0].z = 0.0f; verts[0].color = 0x0000ff00;
verts[0].x = 0.0f; verts[0].y = 0.0f; verts[0].z = 0.5f; verts[0].color = 0x000000ff;
Now we have a triangle, sitting on the origin, with three different colored vertices.
At this point, you could send your triangle to whatever API you are using, be it D3D, OGL, or whatever. The API will then use matrices to transform your 3d triangle into 2d space. There are usually 3 matices used. The Projection matrix does that actual transformation. The View matrix defines your camera. The world matrix defines transformations that you can do on each triangle drawn. For instance, we could create a rotation matrix around the y axis, and apply it to the triangle, to make it spin. This rotation matrix is multiplied by the view matrix, which defines the camera (and the UP vector, as well), and finally by the projection matrix to create a final transformation matrix. This matrix is multiplied by the vertices to get the final screen coordinates. These are then passed to the rasterizer, which does that drawing. The D3DX library included with DX8 has a ton of matrix functions that you can use, for all three types.
That should be a fairly good base, though quick =). If you need anything, just ask =).
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|