Strange Rotational and Translational behaivour using VTK

Post Reply
cevez
Posts: 2
Joined: Mon Oct 20, 2014 1:43 pm

Strange Rotational and Translational behaivour using VTK

Post by cevez »

Hello everyone,
i have very strange behaivour when simulating spheres and other objects.
gravity works fine, but as soon as one object hits a plane or another object it starts going all over the world.
because im using VTK i cannot pass the openGL matrix to reallocate position and rotation, so here's how i tried to do it:
void Visualizer::renderSphere(scenarioobject* sceneobj){

btRigidBody* body = sceneobj->body;
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
qDebug()<<trans.getOrigin().getX()<<trans.getOrigin().getY()<<trans.getOrigin().getZ();
qDebug()<<trans.getRotation().x()<<trans.getRotation().y()<<trans.getRotation().z();
body->getMotionState()->getWorldTransform(trans);
btQuaternion quat;
quat =trans.getRotation();
double w = quat.getW();
double x = quat.getX();
double y = quat.getY();
double z = quat.getZ();
double x1,x2,x3;
double sqw = w*w; double sqx = x*x; double sqy = y*y; double sqz = z*z;
x3=((atan2(2.0 * (x*y + z*w),(sqx - sqy - sqz + sqw))));
x1=((atan2(2.0 * (y*z + x*w),(-sqx - sqy + sqz + sqw))));
x2=((asin(-2.0 * (x*z - y*w))));
sphereActor=sceneobj->actor;
sphereActor->setPosition(trans.getOrigin().getX(),trans.getOrigin().getY(),trans.getOrigin().getZ());

// sphereActor->RotateWXYZ(quat.getW(),quat.getX(),quat.getY(),quat.getZ());
sphereActor->RotateX(x1);
sphereActor->RotateY(x2);
sphereActor->RotateZ(x3);
}
the returned values i got whens tarting the simulation with no force given except gravity are
renderSphere
-1.06848e-11 -0.995 -0.0580943
0.289493 1.625e-08 6.09593e-09

renderSphere
8.78684e-10 -0.995008 0.00265067
0.0104895 -1.58752e-07 -8.75783e-08

renderSphere
-1.06838e-11 -0.995 -0.058098
0.289141 1.62459e-08 6.09181e-09

renderSphere
8.78743e-10 -0.995008 0.00265067
0.0104898 -1.58763e-07 -8.75841e-08


with the first line values beeing x,y,z and the second line value rotation for one object
two colors are two objects
i declare the sphere as following:
void Visualizer::addSphere(float x, float y, float z, float rad, float mass){
scenarioobject* sceneobject=new scenarioobject();
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(x,y,z));
btSphereShape* sphere = new btSphereShape(rad);
btMotionState* mot = new btDefaultMotionState(t);
btVector3 inertia(x-rad,y-rad,z-rad);
mot->setWorldTransform(t);
sphere->calculateLocalInertia(mass,inertia);
btRigidBody::btRigidBodyConstructionInfo info(mass,mot,sphere,inertia);
info.m_friction =0.5f;
info.m_restitution=0.1f;
info.m_angularDamping=0.1f;
info.m_linearDamping=0.2f;
btRigidBody* body = new btRigidBody(info);
world->addRigidBody(body);
sceneobject->addBody(body);
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(x,y,z);
sphereSource->SetRadius(rad);
sceneobject->addPointer(sphereSource);
sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
sceneobject->addMapper(sphereMapper);
sphereActor = vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
sceneobject->addActor(sphereActor);
mp_ren->AddActor(sphereActor);
scenario.push_back(sceneobject);
}
have i forgotten anything? or does bullet just dont like VTK? ;)

sincerly CeVeZ
cevez
Posts: 2
Joined: Mon Oct 20, 2014 1:43 pm

Re: Strange Rotational and Translational behaivour using VTK

Post by cevez »

alright, the translational misbehave was fixed, i forgot to add friction to the plane.
but rotational behaivour is still wrong. any idea for that without using the OpenGL matrix?
Post Reply