void btRigidBody::debugLocalProperties(btIDebugDraw* glDebugDrawer){
    btTransform chassisTrans = getCenterOfMassTransform();

    btVector3 sideVector (
          chassisTrans.getBasis()[0][0],
          chassisTrans.getBasis()[1][0],
          chassisTrans.getBasis()[2][0]);

    btVector3 fwdVector (
          chassisTrans.getBasis()[0][2],
          chassisTrans.getBasis()[1][2],
          chassisTrans.getBasis()[2][2]);

    if(idDebug == 1){
        for(int i = 0; i < 4;i++){
            btVector3 angLinearVelocity = debugAngularVelocity[i].cross(debugRelVector[i]);
            btVector3 relativePosition = debugRelVector[i] + getCenterOfMassPosition();
            btVector3 toRelativePosition = relativePosition+angLinearVelocity*2;
            //glDebugDrawer->drawLine(relativePosition,toRelativePosition,btVector3(0.2,0.7,0.5));

            //angLinearVelocity = debugAngularVelocity.cross(4.9*-sideVector);
            relativePosition = getCenterOfMassPosition()-sideVector*6;
            toRelativePosition = relativePosition+angLinearVelocity*1000;
            //glDebugDrawer->drawLine(relativePosition,toRelativePosition,btVector3(0.2,0.7,0.5));

            relativePosition = getCenterOfMassPosition()+fwdVector*4+btVector3(0,3,0);
            toRelativePosition = relativePosition+debugLinearVelocity*1000;
            //glDebugDrawer->drawLine(relativePosition,toRelativePosition,btVector3(0.2,0.7,0.5));
        }
    }
}
Ejemplo n.º 2
0
glm::vec3 ObjectAction::getPosition() {
    auto rigidBody = getRigidBody();
    if (!rigidBody) {
        return glm::vec3(0.0f);
    }
    return bulletToGLM(rigidBody->getCenterOfMassPosition());
}
Ejemplo n.º 3
0
btRigidBody* FractureBody::breakConnection(int con_id)
{
	btAssert(con_id >= 0 && con_id < m_connections.size());
	int shape_id = m_connections[con_id].m_shapeId;
	btCompoundShape* compound = static_cast<btCompoundShape*>(m_collisionShape);

	// Init child body.
	btRigidBody* child = m_connections[con_id].m_body;
	btTransform trans = getWorldTransform() * compound->getChildTransform(shape_id);
	child->setWorldTransform(trans);
	child->setLinearVelocity(getVelocityInLocalPoint(trans.getOrigin()-getCenterOfMassPosition()));
	child->setAngularVelocity(btVector3(0, 0, 0));
	setConId(*child->getCollisionShape(), -1);

	// Remove child shape.
	btAssert(child->getCollisionShape() == compound->getChildShape(shape_id));
	compound->removeChildShapeByIndex(shape_id);

	// Execute fracture callback.
	if (m_connections[con_id].m_fracture)
	{
		(*m_connections[con_id].m_fracture)(m_connections[con_id]);
	}

	// Invalidate connection.
	m_connections[con_id].m_shapeId = -1;

	// Update shape id due to shape swapping.
	if (shape_id < compound->getNumChildShapes())
	{
		btCollisionShape* child_shape = compound->getChildShape(shape_id);
		con_id = getConId(*child_shape);
		if (con_id >= 0 && con_id < m_connections.size())
		{
			m_connections[con_id].m_shapeId = shape_id;
		}
	}

	return child;
}