Translating a rectangle

Started by
4 comments, last by BrightSoul 18 years, 1 month ago
Hello, I'm moving my very first steps into Direct3D. Using C#, I'm developing a small sample application in order to get acquainted with the 3D evinronment. I was able to initialize a 3d space and put a textured rectangle into it. Then I made it translate on the X axis by manually incrementing on a per-frame basis the X coordinate of each vertex in the VertexBuffer. CustomVertex.TransformedTextured[] v = (CustomVertex.TransformedTextured[]) myRectangle.Lock(0,0); v[0].X += 1; v[1].X += 1; v[2].X += 1; v[3].X += 1; myRectangle.Unlock(); This is working indeed, but I'm not sure if I am doing it right. I mean, this way, it is the CPU that has to calculate the new coordinates for each vertex. Shouldn't be the GPU (ie. Direct3D) to recalculate the new position for each vertex given the translation vector (ie. 1 pixel on X axis)? How do I tell the myRectangle VertexBuffer to translate all its vertex automatically? I'm sorry, I'm not even sure my question makes sense.
Advertisement
You can change the world or the view matrix and modify a bunch of geometry at once in hardware.
To expand: You will need to read up on matrices. Both OpenGL and Direct3D use matrices to transform geometry. In Direct3D, there is the Projection Matrix, the World Matrix and the View Matrix. OpenGL has the Projection Matrix and the Model-View Matrix (sometimes known as the World-View matrix) - which is the concatenation of the World and View matrices. You standard solution (assuming Direct3D), would be to define the correct translation matrix, and apply it to the world matrix. In OpenGL, you will need to deal with the matrix stack (the Model-View Matrix Stack). It's not overly complicated - just different.

Anyway, click the link in my sig for help on the terms presented. :)
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]
ok thanks. I *think* I understand the "world matrix", but doesn't that affect all the triangles I have on the 3D world?

I just want to translate a rectangle (=2 triangles) while other triangles on the world remain still. I thought I had to apply the transformation only to 1 specific vertex buffer and that is why I wrote that code on my previous post.
What should I do?

Edit: I'm using Direct3D
Yes, the world matrix will transform all geometry rendered. Which is why you can set it back to the Identity matrix after you've finished rendering your rectangle. It's standard practice to associate a matrix with each vertex buffer/mesh, and set it as the world matrix, even if most of them are the Identity matrix (and most of them won't be).
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]
Quote:Original post by _goat
Yes, the world matrix will transform all geometry rendered. Which is why you can set it back to the Identity matrix after you've finished rendering your rectangle.


Thank you I made it work with world transformations.
I shall mess with meshes next^^

This topic is closed to new replies.

Advertisement