Sign in to follow this  
repka3

Equipping armor/weapon

Recommended Posts

Hi all, first let me explain the nature of question: I'm working in a little (little, little) 3d engine based on directx 9 for learning something about 3d programming. I'm a total noob and for now i've implemented this few things: 1)terrain from heightmap, 3 blended texture (grass, dirt,mountains) using shader. 2)skinned mesh loading (i made my own model using 3ds max and bone system) with animations jump,attack,running and idle. (vertex blending, lighting,texturing done in vertex/pixel shader) 3)load some static mesh for environment purpose (a little cartoonish house and some tree) Now the question is, suppose you have modelled a weapon like sword and you want "equip" that and following the animation of attack. How to ? :) I need just some advice in logical workflow.. Thx who will answer. bye.

Share this post


Link to post
Share on other sites
I think this is one of the things scene graphs are good for.
It's the concept of different coordinate systems, you have world space, model space, etc. So if you want to have the sword follow the hand then you have to define the sword's position and rotation defined in terms of a coordinate space whose origin is a point on the hand.

My linear algebra is really rusty since I haven't touched any graphics code for a while, but I think the transforms from the hand space to world space would look something like this:

SwordVertexInHandSpace * HandToModelSpace * ModelToWorldSpace

Like I said before, you could look at scene graphs to do this kind of thing.

I hope this was a least a little helpful lol,
mikfig

Share this post


Link to post
Share on other sites
The trick is to attach an equiped model to a bone. Well, when you do bone animation, you will determine your animation frame, put all bones in position and apply a skin_to_bone transformation.
Each bone is represented by an transformation, so we could just take a final bone transformation WITHOUT the skin_to_bone transformation.
Let's say the right hand bone, then we could use this transformation as an offset to your character model to determine the position of your equiped sword:


character_transformation = ...

// setup skeleton
for each bone_i
bone_i_transformation = ... interpolate animated bones ...

// apply final transformation for skinning
for each bone_i
skinned_bone_id = bone_to_skin_i_transformation * bone_i_transformation

// use skinned bones for shader and render character
setup_shader( skinned_bone_X )
render_character( character_transformation)

// determine transformation for sword in right hand
sword_transform = bone_RIGHTHAND_transformation * character_transformation

// render sword
render_sword( sword_transformation)



If this works, you should add an offset to your bones and add extra bones like "right_item" which will not deform your mesh but are just attachment points for your items.

Share this post


Link to post
Share on other sites
really thx :) I will try to attach to a right hand bone today, i will let you know somethings :))

thx again.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ashaman73
...apply a skin_to_bone transformation.
I'm not sure what you mean by this. Perhaps you could explain further. I'm assuming the mesh is already textured so I'm confused.

I have a real simple approach to this problem. Since you know where this weapon will appear, add a joint to that spot just for this purpose, you simply apply the joint's translation matrix to the object. The center point on the object needs to be where it will be held. I'm assuming your model is being animated in model space.

Add a function that can retrieve the the joint offset and matrix from that joint. Apply this to the object and then do your other translations to take it to camera view. I'm sure there's more to this and will require some experimentation. You may also want to research the concept of weapon slots.

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