bool FrustumPhysicsObject::frustumInit(unsigned int attributeIndex,short collisionFilterGroup)
{
	if(attributeIndex < 0)
	{
		return false;
	}
	attributeIndex_ = attributeIndex;
	collisionFilterGroup_ = collisionFilterGroup;
	AttributePtr<Attribute_Camera> ptr_camera = itrCamera_3.at(attributeIndex);
	btVector3 localInertia;
	localInertia.setZero();
	btCollisionShape* collisionShape = CollisionShapes::Instance()->getFrustumShape(attributeIndex_);
	btScalar mass = static_cast<btScalar>(1);
	setMassProps(mass, localInertia);
	setCollisionShape(collisionShape);
	btTransform world;
	
	AttributePtr<Attribute_Spatial> ptr_spatial = itrCamera_3.at(attributeIndex_)->ptr_spatial;
 	AttributePtr<Attribute_Position> ptr_position = ptr_spatial->ptr_position;
 	world.setOrigin(convert(ptr_position->position));
	world.setRotation(convert(ptr_spatial->rotation));
	setWorldTransform(world);
	setCollisionFlags(getCollisionFlags() | CF_NO_CONTACT_RESPONSE); 
	forceActivationState(DISABLE_DEACTIVATION);
	return true;
}
Example #2
0
void PhysicsObject::writeNonSynchronizedPhysicsObjectDataToPhysicsAttribute()
{
	AttributePtr<Attribute_Physics> ptr_physics = itrPhysics_.at(attributeIndex_);

	ptr_physics->angularVelocity = convert(&getAngularVelocity());
	ptr_physics->collisionFilterGroup = getCollisionFilterGroup();
	ptr_physics->collisionResponse = (getCollisionFlags() & btCollisionObject::CF_NO_CONTACT_RESPONSE) == 0;
	ptr_physics->gravity = convert(&getGravity());
	ptr_physics->linearVelocity = convert(&getLinearVelocity());
	//ptr_physics->collisionFilterMask = 
	//ptr_physics->mass = physicsObject->getInvMass(); //only mass inverse is stored in physics object
	//ptr_physics->meshID = //not stored in physics object
}
Example #3
0
    //-----------------------------------------------------------------------
    //                        T P h y s i c s O b j e c t
    //-----------------------------------------------------------------------
    TPhysicsObject::TPhysicsObject (const TString& name, ISceneNode *sceneNode, 
        TCollisionShape* bodyShape, float mass, 
        bool isSensor, bool isGhost, short groupMask, short collisionMask,
        TVector3 colliderOffset) : btDefaultMotionState(),
        m_name(name),
        m_sceneNode(sceneNode),
        m_shape(bodyShape),
        m_mass(mass),
        m_sensor(isSensor),
        m_ghost(isGhost),
        m_groupMask(groupMask),
        m_collisionMask(collisionMask),
        m_offset(colliderOffset)
    {
        m_sceneNode->OnRegisterSceneNode();
        m_sceneNode->updateAbsolutePosition();

        m_shape->setScale(m_sceneNode->getScale());

        // calculate local intertia for dynamic objects
        btVector3 localInertia(0,0,0);
        if (mass != 0.f)
            m_shape->calculateLocalInertia(mass,localInertia);

        m_rigidBody = new btRigidBody(m_mass,this,m_shape->getShape(),localInertia);
        m_rigidBody->setUserPointer(this);

        if(m_sensor | m_ghost)
            setCollisionFlags(getCollisionFlags() | btRigidBody::CF_NO_CONTACT_RESPONSE);

        
        if(m_rigidBody->isStaticOrKinematicObject())
        {
            m_groupMask = short(btBroadphaseProxy::StaticFilter);
            m_collisionMask = short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
        }
        else
        {
            m_groupMask = short(btBroadphaseProxy::DefaultFilter);
            m_collisionMask = short(btBroadphaseProxy::AllFilter);
        }
        

        getApplication()->getPhysicsManager()->addPhysicsObject(this);
    }
Example #4
0
bool PhysicsObject::init(unsigned int attributeIndex, short collisionFilterGroup)
{
	if(attributeIndex < 0)
	{
		return false;
	}
	attributeIndex_ = attributeIndex;
	collisionFilterGroup_ = collisionFilterGroup;

	//Get the init data from a physics attribute
	AttributePtr<Attribute_Physics> ptr_physics = itrPhysics_.at(attributeIndex);
	btScalar mass = static_cast<btScalar>(ptr_physics->mass);

	//Resolve mass, local inertia of the collision shape, and also the collision shape itself.
	btCollisionShape* collisionShape = subClassSpecificCollisionShape();
	if(collisionShape != nullptr)
	{
		setCollisionShape(collisionShape);
	}
	else
	{
		ERROR_MESSAGEBOX("Error in PhysicsObject::init. Expected collision shape pointer unexpectedly set to nullptr. Using default shape instead.");
		setCollisionShape(CollisionShapes::Instance()->getDefaultShape());
	}
	
	btVector3 localInertia = subClassCalculateLocalInertiaHook(mass);
	setMassProps(mass, localInertia); //Set inverse mass and inverse local inertia
	updateInertiaTensor();
	if((getCollisionFlags() & btCollisionObject::CF_STATIC_OBJECT))
	{
		btTransform world;

		AttributePtr<Attribute_Spatial> ptr_spatial = itrPhysics_.at(attributeIndex_)->ptr_spatial;
		AttributePtr<Attribute_Position> ptr_position = ptr_spatial->ptr_position;
 		world.setOrigin(convert(ptr_position->position));
		world.setRotation(convert(ptr_spatial->rotation));
		setWorldTransform(world);  //Static physics objects: transform once
	}
	else
	{
		//Non-static physics objects: let a derived btMotionState handle transforms.
		MotionState* customMotionState = new MotionState(attributeIndex);
		setMotionState(customMotionState);

		setAngularVelocity(btVector3(ptr_physics->angularVelocity.x,
										ptr_physics->angularVelocity.y,
										ptr_physics->angularVelocity.z));
		setLinearVelocity(btVector3(ptr_physics->linearVelocity.x,
										ptr_physics->linearVelocity.y,
										ptr_physics->linearVelocity.z));
		//Gravity is set after "addRigidBody" for non-static physics objects
	}

	if(ptr_physics->collisionResponse)
	{
		setCollisionFlags(getCollisionFlags() & ~CF_NO_CONTACT_RESPONSE); //Activate collision response
	}
	else
	{
		setCollisionFlags(getCollisionFlags() | CF_NO_CONTACT_RESPONSE); //Deactivate collision response
	}
	
	return subClassSpecificInitHook();
}