예제 #1
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setAutoFreeze(bool _bFreeze)
{
    NewtonBodySetAutoFreeze(m_pActor, _bFreeze ? 1 : 0);
    setActivationState(true);
    m_activationState = 1;
}
예제 #2
0
void btCollisionObject::activate(bool forceActivation)
{
	if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT)))
	{
		setActivationState(ACTIVE_TAG);
		m_deactivationTime = btScalar(0.);
	}
}
예제 #3
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setAngularVelocity(const Math::Vector3& _omega)
{
    setActivationState(true);
    m_activationState = 1;

    NewtonBodySetOmega(m_pActor, _omega.m_array);
}
예제 #4
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setLinearVelocity(const Math::Vector3& _velocity)
{
    setActivationState(true);
    m_activationState = 1;

    NewtonBodySetVelocity(m_pActor, _velocity.m_array);
}
예제 #5
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setPosition(const Math::Point3& _pos)
{
    Zen::Math::Matrix4 mat;
    //mat.identity();
    getOrientation(mat);
    mat.setPosition(_pos);
    setActivationState(true);
    m_activationState = 1;

    NewtonBodySetMatrix(m_pActor, mat.m_array);
}
예제 #6
0
void World::
reset()
{
	btCollisionObjectArray a = dynamicsWorld->getCollisionObjectArray();
	for (int i = 0; i < a.size(); i++) {
		auto o = a[i];
		if (!o->isStaticOrKinematicObject()) {
			std::cout << "Object: " << o->getUserPointer() << std::endl;

			btTransform t = o->getWorldTransform();
			btVector3 v = t.getOrigin();

			if (v.getY() < -10) {

				std::shared_ptr<app::gl::AppObject> new_object;

				dynamicsWorld->removeCollisionObject(o);
				for (auto i = objects.begin(); i != objects.end(); ++i) {
					if (i->get() == o->getUserPointer()) {
						new_object = std::make_shared<app::gl::AppObject>(*(i->get()));
						v.setX(disx(gen));
						v.setY(disy(gen));
						v.setZ(disz(gen));
						t.setOrigin(v);
						new_object->setWorldTransform(t);
						objects.erase(i);
						break;
					}
				}
				addToWorld(new_object,
						btRigidBody::btRigidBodyConstructionInfo(new_object->getMass(),
								nullptr, nullptr, new_object->getInitialInertia()));
			} else {

				v.setX(disx(gen));
				v.setY(disy(gen));
				v.setZ(disz(gen));
				t.setOrigin(v);
				o->setWorldTransform(t);
				o->setInterpolationLinearVelocity(btVector3(0,0,0));
				o->setInterpolationAngularVelocity(btVector3(0,0,0));
				o->setActivationState(1);
				o->activate(true);
			}

		}
	}
}
예제 #7
0
void RigidBody::init( const Format &format )
{
	mType = getPhyObjType( format.mCollShape->getName() );
	
	mCollGroup = format.mCollisionGroup;
	mCollMask = format.mCollisionMask;
	
	mCollisionShape = format.mCollShape;
	mCollisionShape->setLocalScaling( toBullet(format.mInitialScale) );

	recalculateBoundingSphere();
	
	btVector3 localInertia(0,0,0);
	
	if( format.mMass != 0.0f && ! format.mSetKinematic ) {
		mCollisionShape->calculateLocalInertia( format.mMass, localInertia );
	}
	
	mMotionState = format.mMotionState;
	
	btRigidBody::btRigidBodyConstructionInfo cInfo( format.mMass, mMotionState.get(), mCollisionShape.get(), localInertia );
	
	cInfo.m_friction = format.mFriction;
	cInfo.m_restitution = format.mRestitution;
	
	mRigidBody.reset( new btRigidBody(cInfo) );
	
	if( format.mSetKinematic ) {
		mRigidBody->setCollisionFlags( mRigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
		setActivationState( DISABLE_DEACTIVATION );
	}
	
	if( format.mAddToWorld ) {
		Context()->addRigidBody( mRigidBody.get(), mCollGroup, mCollMask );
		mAddedToWorld = true;
	}
	
	if( ! mMotionState ) {
		btTransform trans;
		trans.setOrigin( toBullet( format.mInitialPosition ) );
		trans.setRotation( toBullet( format.mInitialRotation ) );
		mRigidBody->setWorldTransform( trans );
	}
	
	mRigidBody->setUserPointer( format.mRigidBodyUserPtr ? format.mRigidBodyUserPtr : this );
}
예제 #8
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
void
PhysicsActor::setOrientation(const Math::Matrix4& _orient)
{
    // transfer values from input matrix to temporary matrix:
    Math::Matrix4 matrix;
    for (int i = 0; i < 16; i++)
    {
        matrix.m_array[i] = _orient.m_array[i];
    }

    // add offset to orientation matrix before setting body:
    Math::Point3 pos;
    pos = getPosition();
    matrix.setPosition(pos);

    setActivationState(true);
    m_activationState = 1;

    NewtonBodySetMatrix(m_pActor, matrix.m_array);
}