Sign in to follow this  
Schmacker

Some basic q's about Transformations

Recommended Posts

I'm just starting to play around with Direct3D, got me my obligatory rotating cube (though its doing some strange things, but thats not important right now), and am wondering about transforms, and a few other things. Say I have a system whereby each model is loaded into a Mesh object, and every GameObject points to it's particular Mesh. First thing is, I want to draw all of the objects that use the same mesh one after another, right? Say that I have 10 GameObjects that use the 1 mesh. I set up the transform for the first, draw it, then set up the transform for the second, draw it, so on and so forth. That how I should do it right? World Transform moves the object from (0,0,0) to it's position in the world, is how I understand that they work. Is that a correct assumption, or does it work otherwise? I'm pretty sure that I wanted to ask more things, but a lot of what I'm thinking about worries about speed which, right now in my state of learning, are the wrong questions to be asking, but I will come back to ask more, I'm sure of it. Also, I do hope the questions make sense, I've tried to be as clear as I can, but I'm in a bit of a tangle with this stuff. Thanks Dyl [Edit - fixed stupid spelling error]

Share this post


Link to post
Share on other sites
I find your post fairly vague, but I see a few things in it:

1) You're worrying about state-changes that slow down your performance and so you try to change as less as possible.
- It is true, that too much state changes will slow down performance. Often people will sort on textures/shaders/vertexbuffers. This is less important as the following.
2) You're wondering how/when/if to rendering everything.
- One thing is for sure, you don't want to render everything. You'll have to think of a way to cull away objects that aren't in your cameras sight. The most popular way these days is using an octree and frustum culling.

Share this post


Link to post
Share on other sites
Cheers for the quick reply... it seems that I wasn't as clear as I had hoped... me and my not know what Im asking sometimes :)

Yes to the worrying about state changes, I've heard that thats bad, and that I want to do it as little as possible. However, I was already well aware not to draw everything. Early out is good.

I am still not up to understanding trans forms. I know sketchily how to use them, something that I'm working on, but I'm wondering, mostly, if the way the world transform works is quite right... ie the moving from (0,0,0) to (x,y,z)

Still, any help is appricated here, I know I've got a lot to learn :)

Thanks
Dyl

Share this post


Link to post
Share on other sites
You're right. If the mesh is exactly the same, you want multiple world matrix's and 1 mesh.

Then render as you said. Set the world, render mesh.

When I started, I was confused about 1 thing. I thought the world matrix handled where the object was in the world. But its the reverse. You are moving the world, NOT THE OBJECT... The object is always at 0,0,0. But you can move the world when rendering to give the object a location in the world.

For example. If you have a mesh you want (0,0,10) (10 z into the world)... You want to set the rest of the world 10 back on the z axis, so the world matrix transform would be (0,0,-10). The object's position remains at 0,0,0...

To make a long story short, just reverse the transformations in your brain when thinking about it. If you want an object X,Y,Z into the world, just set the world matrix (-X,-Y,-Z) and it will work fine.

Share this post


Link to post
Share on other sites
Just some basic pointers:

It's good to make static things static. So, when you load a mesh that's supposed to go to (10,0,2) and stay there, it's optimal to lock the vertex buffer, take each vertex and multiply it by the (10,0,2) transformation, then unlock the buffer. Do that once and leave it. Then, you can call SetTransform(WORLD, Identity) and draw all of your static meshes (that are within your view anyway). Think about how the pipeline in the graphics card works. It takes the three matrices you feed it and just multiplies them all together, then multiplies the final one by the vertex point to move it. It's that simple (in simple terms anyway). You can do the same thing to move vertices around.

Try not to get too bogged down with what the transformation is really doing. Just know that if you use D3DX extended functions, such as D3DXMatrixTranslation(...), you plug in the values that you want the object to appear at (i.e. 10,0,2). It handles the rest. You will need to know about inverses and transforms later when making billboards and stuff like that, but I wouldn't worry about it right now.

SetTransform for the WORLD is optimally used for a moving object (whether it be moving across the terrain or moving in place as an animation). Other things to be aware of: Don't call SetTexture very often. Try to use textures that have everything included on them. If you have a tiled terrain, don't make a separate texture for each tile. Make a big one and use texture coordinates to separate them.

Good luck,
Chris

Share this post


Link to post
Share on other sites
Cheers for the replys guys, its always helpful to know that Im thinking along the right tracks... now its off to work so unfortunately I can't play around with this, but when I get home I definately will be :)

Thanks
Dyl

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