Skip to main content
gamedev.net
🔒 Locked

Multiple Objects

Started by ribbonfish Jul 2, 2004 at 1:49 AM 2 replies 750+ views
Original Post
ribbonfish
ribbonfish
I am just wondering if this is the right way to do it. I have a sphere in the middle of the screen. A cube is set on top of it. Right now how I do it is I render a sphere in the middle at the origin. Then I have to set the world matrix multiplying it with a transformation. And render the cube. The problem is all objects after the transformation are rendered at the transformed position, meaning the next time(next frame) the sphere is rendered, it'll be centered at the transformed position instead of the origin. OK, i can put a transformation call before rendering the sphere. But is this the right way to do it, since there will be some sort of matrix multiplication happening every frame, where there are a lot of objects in difference positions, it can get very flicky. Please let me know how to do it better, thanks.
SoulSpectre
SoulSpectre
You will need to either reset the matrix, set a new one, or pop off the additional mtrices.
Lokken
Lokken
I remember for OpenGL that there was a push and pop matrix ability. Is this mirrored in D3D?
________what we do in life, echoes in eternity
neneboricua19
neneboricua19
Quote:
Original post by Lokken
I remember for OpenGL that there was a push and pop matrix ability. Is this mirrored in D3D?

Yes. D3D has the ID3DXMatrixStack interface. You could just as easily use the stl::stack in C++ but either will accomplish the task.

In general, when you render each object, you have to set that object's world transform. Pseudocode for a render loop would look like this:
for(DWORD i = 0; i < dwNumMeshes; i++){  pMeshes.SetWorldMatrix();  pMeshes.Render();}

In the original poster's case of a sphere, the transform for the sphere would just be an identity matrix.

neneboricua

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.