# Object Attachment

## Recommended Posts

For instance, when a player picks up a weapon, how do you attach the two objects (man and gun, or grouping in other sense) and move them together as one. (Using DX9c) Thanks Jack

##### Share on other sites
One idea is to use a Scene Graph. The general idea is that you have a tree structure. Underneath a node are all of the items that that node is holding/containing/supporting/attached to, etc... The root node represents a general point in the world, that any unattached objects would come off of.

In your example, you would start off with two children coming off of the root node, a man, and a gun. If either moves, rotates, or changes in other ways, it only affects itself. To attach the gun to the man, you would move the gun node underneath the man node. From now on, whenever the man moves or rotates, it tells all of it's children (in this case the gun), that it needs to move or rotate also, based off of where the man is. There are a complete different ways to actually implement this or use this, but I believe that that is the general principle.

I don't think there are any native structures or anything in DX9x that implement this, I'm pretty sure it's something the programmer implements themselves. I'm not an expert on Scene Graphs, so hopefully somebody else will come along and provide a more detailed description if you want it.

You may also found this topic more fitting under graphics programming, since I'm not sure if there are any DirectX specific issues with how you would handle this.

##### Share on other sites
You could also have every person have a list of objects.

struct Object{    int type;};struct Gun : public object{    int ammo;    //etc};class Being{private:    List<object> objects;};

I dont really know too much about inheritance, but I think that will work.

##### Share on other sites
Quote:
 Original post by TibreI don't think there are any native structures or anything in DX9x that implement this, I'm pretty sure it's something the programmer implements themselves. I'm not an expert on Scene Graphs, so hopefully somebody else will come along and provide a more detailed description if you want it.

Implementing scene graphs is just as easy as multiplying two matrices.
Since matrices are used to transform one coordinate system to another (e.g. local to world), they can be concatenated by multiplication to go through different coordinate systems (e.g. hand to man, then man to world).

##### Share on other sites
just combine the weapon's matrix with the chrachter's hand martix together...

##### Share on other sites
Some source code?
Thanks
Jack

##### Share on other sites
How about alignment? How do you specify the gun is on top of the palm or being gripped by the palm? Any clue?
Thanks
Jack

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628389
• Total Posts
2982410

• 10
• 9
• 19
• 24
• 11