Sign in to follow this  
fathom88

Moving D3DXMesh ??

Recommended Posts

fathom88    180
I'm trying to represent data points in a 3D plane. However, I find using DrawPrimitives and simply drawing points does not convey well in 3D. Instead, I want to draw tiny spheres instead of dots. I use the DirectX create sphere. It's fine. However, it does not give me a way to place the sphere in a specific location (x,y,z). It seems to just create it at the center. I could just make my own vertex buffer with the triangle list needed to create my own sphere and then move the spheres by doing matrix translations. There should be an easier way. Isn't a 3D mesh just a list of vertices? I don't see why I can't do matrix translation on the underlying vertices to place the sphere created by DirectX 9 at a specific location (and then move them; which I'll want to eventually want to do). I have found some examples of moving meshes. However, they all involve moving the view (or the world) and not the actual mesh object (sphere, teapot, box). Thanks for any help.

Share this post


Link to post
Share on other sites
Illco    928
I think you are stumbling upon the various spaces used in 3D viewing. First of all, there is object space. Naturally, this is where objects are defined in terms of their vertices. Usually, this is around the (local) origin. The vertices in the vertex buffer are thus all relative to the point (0,0,0). Second, there is world space -- this is where objects as a whole reside at certain locations. Instead of accessing the vertex buffers and transforming the vertices, the usual process is different. For each object, a transform is calculated that transforms it from object space to world space. This is usually referred to as the world transform and specified in the world matrix.

Now this is exactly why the sphere class does not and should not offer a position: its position is natively the origin and if you want it elsewhere you should provide a transform from object space to world space. If this transform is the identity matrix, the object will remain at the origin. If this transform specifies a translation to (0,0,5) the object will move that way. The same way rotations can be implemented.

So, solving your problem would look something like this:

// Create the sphere in object space
sphere = createsphere()

// Compute a world transform
world = translation( 0, 0, 5 );

// Render the sphere using the world transform
device->settransform( world )
sphere->render()


I hope this is all clear. If not, feel free to ask. Greetz,


Illco

Share this post


Link to post
Share on other sites
fathom88    180
I think I see what you're doing. Please excuse my ignorance, it seems that doing a set transform on the world moves the 0,0,0 center to a new loction (depending on the translation). From the point of create sphere, you're still creating the sphere at the center location. It looks to like it's in a new location in the application window; but in reality it's the world that's moved and not the sphere. Please correct me if I'm wrong. (Side note: It reminds me of an episode of Futurama where Fry has a super fast ship which does not move; but, instead, the ship moves the universe). I created a wire frame box using object space coordinates. To move the sphere, I did a translation matrix and then I did a set world transform. Finally, I drew the sphere. However, I had to undo my world transform with an idenitiy matrix before I drew my box. Without it, my box moved with the sphere. I would prefer to move the sphere in object space. Is this bad form to do these constant world transforms?

Share this post


Link to post
Share on other sites
turnpast    1011
You might be better off thinking of transformations as positioning information applied at different stages in the rendering process. When you specify the world transformation you are not 'moving the world', but specifing how the the following objects 'will be moved' into world space at that transformation stage.

The target space is eventually 'screen space' and in direct x there are typically three transformation steps to get from object space to screen space: the world transformation, view transformation and projection transformation. This process it generally aplied by the hardware at render time, but you could easily apply it yourself and say move a mesh from object space to world space by multiplying every position in the mesh by the world transformation. This would be in effect moving the object in object space. There may be reasons to do this, but the hardware is very fast at doing it as part of its vertex pipeline and the manual process is very slow -- so don't do it unless you have a very good reason.

In other words, the origin (0,0,0) is never moved, rather the vertices themselves are positioned and repositioned through a series of matrix multiplications.

hope this helps.

Share this post


Link to post
Share on other sites
Illco    928
Quote:

It seems that doing a set transform on the world moves the 0,0,0 center to a new loction (depending on the translation).

It translates the object such that its (object space) origin is at the specified location, yes.

Quote:

It looks to like it's in a new location in the application window; but in reality it's the world that's moved and not the sphere.

You could see it like that, but it is probably easier to see it as translating the objects and not the world, like turnpast said.

Quote:

However, I had to undo my world transform with an idenitiy matrix before I drew my box.

Rather than seeing this as 'unoding' the transformation you could think of it as specifying the transformation for the box (which accidently happens to be the identity matrix but could have been some other, different, translation).

After digesting all this, the ordinary way of rendering a scene with multiple objects is done like this:

// Set view and projection transforms; usually fixed per frame
device->settransform( view )
device->settransform( projection )

// Render all objects with individual transforms
for all objects o
device->settransform( o->gettransform() )
o->render()


Greetz,

Illco

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