Archived

This topic is now archived and is closed to further replies.

skillfreak

Translating Vertices

Recommended Posts

skillfreak    160
When you first setup vertices for a texture, you lock, copy them in, and unlock. I have heard that this is very expensive in terms of speed. I have also found little bits of info about setting up a matrix and multipling your orignal stream out or something to that effect, to ''trick'' the d3d in moving your coords. ? If anyone would elaborate on that, I''d appreciate it.

Share this post


Link to post
Share on other sites
Tom    352
I haven''t actually used vertex buffers in a practical situation, but I do understand how they work, and by the looks of it they can be incredibly useful for performing transforming many vertices in one easy step.

I''ll assume you know how to create a vertex buffer from an array of vertices. To transform them, you must call SetTransform for you D3D device and set the transformation matrix to whatever transformations you want to perform. If you can set up a D3D device, then you can do this. You can also provide clipping planes if you want the vertices in your buffer to be clipped.

Anyway, after you set up your transformation matrix, just call the ProcessVertices method with the appropriate parameters, and Direct3D will do the rest for you. In Visual Basic, my code would look something like this:

Call d3ddev.SetTransform(D3DTRANSFORMSTATE_WORLD, matXForm)
Call vtxBuffer.ProcessVertices(D3DVOP_TRANSFORM, vtxBuffer, 0, numVerts, vtxBuffer, 0, d3ddev, D3DPV_DEFAULT)

This churns ever vertex in vtxBuffer through matXForm and dumps them back into vtxBuffer. You need to keep track of numVerts yourself so you don''t overflow the buffer. The SDK can tell you a lot more about this method than I can.

Share this post


Link to post
Share on other sites
CrazedGenius    156
Actually, the above method usually isn''t necessary. Do this:

1. Create vertex buffer with mesh info
2. Create matrix
3. SetTransform with new matrix
4. DrawPrimitive

ProcessVertices gives you the data back, which is not usually necessary. This method applies the transforms and draws to the screen. Read the SDK docs / samples.

Share this post


Link to post
Share on other sites
skillfreak    160
How would I translate these vertices? Say I have an x and y and z that I collect from my mouse. How would I translate those.(z at 1)
Right now, I'm trying mix between both of your posts, and its not working. It just chills up in the top left portion of my screen. =) Thanks thus far!

Edited by - skillfreak on November 5, 2001 4:57:26 PM

Share this post


Link to post
Share on other sites