Setting Position of Bullet Affected Nodes

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Dark Dragon DX
Posts: 24
Joined: Fri Nov 05, 2010 11:46 pm

Setting Position of Bullet Affected Nodes

Post by Dark Dragon DX »

Not sure if anyone else has something like this, but I figured it can help. (Probably very inefficient, but its the only way I know.)

Code: Select all

World->removeCollisionObject(Body, false);
Node->setPosition(position);
IRigidBox *Body = World->addRigidBody(Shape);
IRigidBox can be changed to any other body type.
Body is the body affecting Node.
Node is the pointer to an ISceneNode.
World is obviously a pointer to IrrBulletWorld.

Yea, I know this is an incredibally simple snippet, but this caused me quite a few problems not knowing about the removeCollisionObject command. :oops: So I figured this could be useful to other people that didn't know it was there either. It also works with setRotation and setScale.
hayate
Posts: 43
Joined: Mon Feb 16, 2009 9:38 pm
Location: Brescia, Italy

Re: Setting Position of Bullet Affected Nodes

Post by hayate »

Dark Dragon DX wrote:

Code: Select all

World->removeCollisionObject(Body, false);
Node->setPosition(position);
IRigidBox *Body = World->addRigidBody(Shape);
IRigidBox can be changed to any other body type.
Body is the body affecting Node.
Node is the pointer to an ISceneNode.
World is obviously a pointer to IrrBulletWorld.
Hi, what is "Shape" in "World->addRigidBody(Shape);" Is it the mesh of Node?
Sorry for my awful english ^_^'
Image
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Setting Position of Bullet Affected Nodes

Post by shadowslair »

hayate wrote:Hi, what is "Shape" in "World->addRigidBody(Shape);" Is it the mesh of Node?
The shape is the collision representation of the body. For example you wanna create a football ball- the shape is a sphere with some radius and the body holds the transformation, mass etc. physics` properties. Sth like that. You can have a shape that uses the node mesh to be build. Depends on what library you use and the thing you need to use it for.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

Dark Dragon DX:

If you're doing this when you "spawn" a new object, that's fine, and the correct way to do it, because the IRigidBody constructor automatically sets its transformation to the scene node's transformation.

However, because you first remove the object and then create a new one at the new position, it seems like you're simply trying to re-position the object.

To do this, use ICollisionObject::setWorldTransform() and give it a matrix4 that describes the new transformation.

- Josiah
Josiah Hartzell
Image
Dark Dragon DX
Posts: 24
Joined: Fri Nov 05, 2010 11:46 pm

Post by Dark Dragon DX »

cobra wrote:Dark Dragon DX:

If you're doing this when you "spawn" a new object, that's fine, and the correct way to do it, because the IRigidBody constructor automatically sets its transformation to the scene node's transformation.

However, because you first remove the object and then create a new one at the new position, it seems like you're simply trying to re-position the object.

To do this, use ICollisionObject::setWorldTransform() and give it a matrix4 that describes the new transformation.

- Josiah
Oh, thanks. I'm relatively new to the engine so I'll have to learn how to use matrix4. (Sorry for epic long post delay, I'm never on the forums)
Post Reply