Moving in D3D

Started by
7 comments, last by deathtrap 20 years, 5 months ago
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?
Advertisement
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.

Alrighty then. Thanks alot
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...
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com
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.
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.
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?
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.
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.

This topic is closed to new replies.

Advertisement