[SOLVED] An additional method for btRigidBody

User avatar
BrightBit
Posts: 6
Joined: Fri Dec 31, 2010 8:51 pm

[SOLVED] An additional method for btRigidBody

Post by BrightBit »

Hello Bullet community,

the btRigidBody class provides only one method to change the position of the body:

Code: Select all

void btRigidBody::translate(const btVector3& v)
{
    m_worldTransform.getOrigin() += v; 
}
However, I need a btRigidBody::setPosition that would basically do:

Code: Select all

void btRigidBody::setPosition(const btVector3& v)
{
    m_worldTransform.setOrigin(v);
}
"Why?" you may ask. Well, I programmed a terrain that consists of smaller pieces, so called chunks, each of them uses a btRigidBody. Within each frame all those chunks will be repositioned in relation to the camera position to keep them near the origin. Chunks out of a certain range will be unloaded and new chunks will be loaded. This way I am able to have infinite terrain. If you know Minecraft you might know what I mean. The point is that the repositioning of the chunks' btRigidBodies via translate could cause some floating point inaccuraccies over time. Whereas with a call for btRigidBody::setPosition I would be able to avoid those problems.

Is there a chance that the devs add such a method to bullet?


Greetings
BrightBit
Last edited by BrightBit on Thu May 12, 2011 11:37 pm, edited 1 time in total.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: An additional method for btRigidBody

Post by dphil »

What if you try:

Code: Select all

void btRigidBody::setCenterOfMassTransform(const btTransform &xform);
passing in a transform that has the position ("origin") you want and no rotation. I'm not entirely sure what this function does, but at a quick glance it looks like it might be what you want.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: An additional method for btRigidBody

Post by Mako_energy02 »

dphil is correct, the Transform on the class is what stores the location and rotation information for the body. In addition to the function he provided, the base class for the rigid body btCollisionObject, has get and set functions for the objects world transform, "getWorldTransform()" and "setWorldTransform(const btTransform& worldTrans)". You can make a transform ahead of time and pass it in, or you can get the existing transform and call "setOrigin(const btVector3& origin)" on it.

This is easy enough I don't think it merrits adding a convenience function to the class.
Last edited by Mako_energy02 on Sat May 14, 2011 9:59 pm, edited 1 time in total.
User avatar
BrightBit
Posts: 6
Joined: Fri Dec 31, 2010 8:51 pm

Didn't look for the base class

Post by BrightBit »

I feel like an idiot, now. :oops: I don't know why I didn't check btRigidBody's base class.

Thank you guys, your answers helped.