Apply a translation

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Apply a translation

Post by goutbouyo »

Hi,

For my shooting function, I'd like that the bullet start at the right hand of my enemy.
But I don't know how to do that, how can I make a translation ???

Can you help me please, it's only maths...
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Hi,

I do it that way:

First you need the target vector:

Code: Select all

// Set target vector for the weapon
core::matrix4 rotMatrix;
rotMatrix.setRotationDegrees( player->getRotation() );
core::vector3df targetVec = core::vector3df( 0.0f, 0.0f, 1.0f );
rotMatrix.transformVect( targetVec );
Second: You update your bullet's position with this vector (which you have to store once in your bullet class):

Code: Select all

position += targetVec * static_cast< float >( velocity * timeDiff ) / 1000.0f;
node->setPosition( position );
Regards - Xaron
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

Thanks but I'm not sure you understood my problem.
Instead of starting at the ennemy->getPosition(), I want the bullet to start at the right hand of the ennemy.

So how can I do that pease ???
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

The same way. Just get the absolute rotation of the weapon to compute the target vector. Then you start the bullet from the absolute position of the weapon and add this target vector (multiplied with its velocity) every frame to the current bullet position.

Regards - Xaron
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

But the problem is that I don't have the position of the enemy's weapon.
And I use an animator for my bullets.

The thing I search is how to find the position of the right hand of the enemy ...
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

goutbouyo wrote:But the problem is that I don't have the position of the enemy's weapon.
:shock: How come? If you display the enemy including the weapon you have the enemy's scene node. If the weapon is a child of the enemy (this makes things much easier), you can simply get the weapon's position, too. Or is the enemy including the weapon one mesh/model? If yes you still have the relative position of the weapon, haven't you?

Regards - Xaron
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

The weapon is integrated in the enemy model(a MD2).
So, how can I have it position ???
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

No idea on this problem ???
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

Post by IPv6 »

Vfy be you should use joints? it is possible to put joints in model editor that will be moved with the animation. and it is possible to get posishion of specific joint in the animated mesh. just add joints to weapons and get thier positions at runtime
funcdoobiest
Posts: 48
Joined: Thu Jun 15, 2006 6:35 pm

Post by funcdoobiest »

Goutbouyo, you could always just use some trial and error, if you are using the MD2 models I assume you will have some sort of 'firing' animation, so the weapon will always be in the same position relative to the model's position in the world (like Xaron said), so you could just make a reasonable guess and then keep adjusting it until it is right.

I know this isn't a very pleasing solution (the offset could be different for each model) but as far as I know there are no bones you can use in an MD2 model (they use vertex animation, not skeletal) to find the gun position.
goutbouyo
Posts: 47
Joined: Thu Mar 24, 2005 6:55 pm

Post by goutbouyo »

I found a solution :
I create an invisible child node of my enemy's node on his left hand.
Then, I use the absolute position of this node to place my bullet start position.

Thanks all for your help !!!
Post Reply