Setting mass to nonsense value 100000000.0f made it a bit harder, but still its very easy to pass through (mostly when i rotate moveable object and pass at certain angle). Setting setCcdMotionThreshold() and setCcdSweptSphereRadius() without any effect. Also when I set groundMass 0.0 to be static, I can pass trought it like it was not an obstacle. I must be doing something really wrong.
Could anyone suggest me, what I am doing wrong and how to make 2D collision properly work without being able to pass through object? Using Bullet 2.85 compiled from git.
Thanks, any help is appreciated.
*edit* in another standalone application test gravity works fine, so it seems I am setting something incorrectly here, however under high gravity object seems to be rotated over Z axis sooner or later, so going from 2D to 3D and thus behaving incorrectly (same i have noticed in the other application, the object transforms to 3D and this body->setLinearFactor(btVector3(1,1,0)); body->setAngularFactor(btVector3(0,0,1)); doesnt seem to prevent it. Could anyone try to set high gravity e.g. m_dynamicsWorld->setGravity(btVector3(0, 1000, 0)); and lock object to 2D and test behavriour? Thanks
Screenshots
http://i.imgur.com/j7Rmvv8.png
http://i.imgur.com/knmtewN.png
physics init
Code: Select all
btBroadphaseInterface* m_broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* m_collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
/*
btVoronoiSimplexSolver* m_simplex = new btVoronoiSimplexSolver();
btMinkowskiPenetrationDepthSolver* m_pdSolver = new btMinkowskiPenetrationDepthSolver();
btConvex2dConvex2dAlgorithm::CreateFunc* m_convexAlgo2d = new btConvex2dConvex2dAlgorithm::CreateFunc(m_simplex, m_pdSolver);
m_dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE, m_convexAlgo2d);
m_dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE, m_convexAlgo2d);
m_dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE, m_convexAlgo2d);
m_dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE, new btBox2dBox2dCollisionAlgorithm::CreateFunc());
*/
btConstraintSolver* m_solver = new btSequentialImpulseConstraintSolver;
//m_solver = m_sol; //btSequentialImpulseConstraintSolver* m_sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0, 0, 0));
GLDebugDrawer* m_debugDraw = new GLDebugDrawer(this->getWindowSize().x, this->getWindowSize().y);
m_debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
m_dynamicsWorld->setDebugDrawer(m_debugDraw);
//static object
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(5000), btScalar(200), btScalar(150)));
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(200, 400, 0));
btScalar massGround(1.0f);
bool isDynamicGround = (massGround != 0.f);
btVector3 localInertiaGround(0, 0, 0);
if (isDynamicGround)
groundShape->calculateLocalInertia(massGround, localInertiaGround);
btDefaultMotionState* myMotionStateGround = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfoGround(massGround, myMotionStateGround, groundShape, localInertiaGround);
btRigidBody* m_groundBody = new btRigidBody(rbInfoGround);
//m_groundBody->setCcdMotionThreshold(10);
//m_groundBody->setCcdSweptSphereRadius(10);
m_dynamicsWorld->addRigidBody(m_groundBody);
//m_groundBody->setActivationState(DISABLE_DEACTIVATION);
m_groundBody->setLinearFactor(btVector3(1, 1, 0));
m_groundBody->setAngularFactor(btVector3(0, 0, 1));
//moveable object
btConvexShape* shipShape = new btBoxShape(btVector3(btScalar(276/2), btScalar(276/2), btScalar(150)));
shipShape->setMargin(btScalar(0.04));
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(100000000.0f); //this makes it harder to pass through objects
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0, 0, 0);
if (isDynamic)
shipShape->calculateLocalInertia(mass, localInertia);
startTransform.setOrigin(btVector3(0, 0, 0));
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(0, 0, 0);
rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass, myMotionState, shipShape, localInertia);
btRigidBody* m_shipBody2 = new btRigidBody(rbInfo);
m_shipBody2->setCcdMotionThreshold(10);
m_shipBody2->setCcdSweptSphereRadius(10);
m_dynamicsWorld->addRigidBody(m_shipBody2);
m_shipBody2->setActivationState(DISABLE_DEACTIVATION);
m_shipBody2->setLinearFactor(btVector3(1, 1, 0));
m_shipBody2->setAngularFactor(btVector3(0, 0, 1));
Code: Select all
ship.Process();
m_dynamicsWorld->stepSimulation(GameState::deltaTime);
btTransform trans = m_shipBody2->getWorldTransform();
trans.setOrigin(btVector3(ship.GetPosition().x, ship.GetPosition().y, 0));
trans.setRotation(btQuaternion(btVector3(0.0, 0.0, 1.0), btRadians(ship.GetRotation())));
m_shipBody2->setWorldTransform(trans);
m_dynamicsWorld->debugDrawWorld();
m_debugDraw->Render(GameState::asset.GetShader("shader1.vs").id, GameState::camera.GetViewMatrix(), GameState::camera.GetProjection());
Code: Select all
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionShapes/btBox2dShape.h>
#include <BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h>
#include <BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h>
#include <BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h>
#include <BulletCollision/CollisionShapes/btConvex2dShape.h>
#include <BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h>
#include "GLDebugDrawer.hpp"