Archived

This topic is now archived and is closed to further replies.

Moving in D3D

This topic is 5143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I want to move an object(cube) independantly from another object(ball), would I have to lock the cubes vertex buffer each frame and update each vertex? , or do I just use a translation matrix?

Share this post


Link to post
Share on other sites
Use a matrix, and pDev->SetTransform(D3DTS_WORLD, &mat).

All objects should be moved, scaled, translated, and/or sheared using this method, until you get to more advanced techniques.

Some examples of more advanced techniques are:

Pre-transforming static geometry so it can be rendered in less calls, at the expense of video memory.

Batching small objects, such as particles, or tiles, by transforming them in software. The overhead of transforming in software is MUCH less than the overhead of calling DrawPrimitive() for very small object.

Share this post


Link to post
Share on other sites
quote:

If I want to move an object(cube) independantly from another object(ball), would I have to lock the cubes vertex buffer each frame and update each vertex? , or do I just use a translation matrix?



If you are considering moving the object by locking the vertex buffer; I have to assume that you are using a Flexible Vertex Format of D3DFVF_XYZRHW? If you are using this Flexible Vertex Format; please keep in mind that your object will be in screen space, not world space.

_______________________________________
Understanding is a three edged sword...

Share this post


Link to post
Share on other sites
Keep in mind using a matrix for movement only applies when your objects are at 0,0 in their own model space. You would have a good reason to lock your vb and change each vertex if you wanted to modify the object within it''s model space. Otherwise, if you''re messing with the object in some world space (which it appears you are), then using matrices is fine and dandy.

Share this post


Link to post
Share on other sites
actually i''m using managed DX , and the vertex format is PositionColored . and I don''t think that is in screen coordinates as it doesn''t have an RHW field, whereas the Transformed[Colored] has the RHW field.

Share this post


Link to post
Share on other sites
quote:
Original post by nerdboy80
Keep in mind using a matrix for movement only applies when your objects are at 0,0 in their own model space. You would have a good reason to lock your vb and change each vertex if you wanted to modify the object within it''s model space. Otherwise, if you''re messing with the object in some world space (which it appears you are), then using matrices is fine and dandy.


Just a small question. What would be a reason where I''d want to modify the object in its model space rather than world space?

Share this post


Link to post
Share on other sites
You can rotate, scale, shear an object in model space using matrices. There''s nothing stopping you from doing model space transforms with the world transform...

Examples of modifying a model that would require a lock are things like morphing, terrain deformation, etc. Things that modify a subset of vertices in a manner that cannot be expressed as a tranform of the whole object.

Share this post


Link to post
Share on other sites
Really you only want to modify an object in model space to do things like changing it''s shape, not really moving it around, *unless* you want to cache the geometry, like Namethatnobodyelsetook said.

Warning: I don''t explain things well and googling for "scene graphs", or other such things will probably make more sense...

I however am designing an app with arbitrary levels of hierarchy. Each model space contains objects, some of them (like simple cubes, cylinders, ect...) simply exist in that model space, and are transformed in that model space, per vertex. Others, are actually references to other model spaces, which use matrix transforms to draw themselves into their parent model space. So, a car model made up of say 30 cubes would have each of those cubes in it''s model space, but the car, when put in a parent model space would use matrix transforms to quickly transform all of it''s cubes to the appropriate place. It doesn''t need to worry about transforming one of the cubes it has while in it''s parent model space, because the user only interacts with things at that level, and each cube is one level below, in the car model space.

Share this post


Link to post
Share on other sites