Sign in to follow this  
BrightSoul

Translating a rectangle

Recommended Posts

BrightSoul    122
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.

Share this post


Link to post
Share on other sites
z80    134
You can change the world or the view matrix and modify a bunch of geometry at once in hardware.

Share this post


Link to post
Share on other sites
_goat    804
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. :)

Share this post


Link to post
Share on other sites
BrightSoul    122
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

Share this post


Link to post
Share on other sites
_goat    804
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).

Share this post


Link to post
Share on other sites
BrightSoul    122
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^^

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