Exemplo n.º 1
0
void PlayerVehicle::update(const float currentTime, const float elapsedTime)
{
	PhysicalThing* pt = mActor->getPhysicalThing();
	OgreNewt::Body* body = NULL;
	if(pt) pt->_getBody();
	if(body)
	{
		Vector3 position;
		Quaternion orientation;
		body->getPositionOrientation(position, orientation);
		setPosition(Vec3(position.x, position.y, position.z));

	//  Get the velocity vector
		mCurrentVelocity = body->getVelocity();
	//  enforce speed limit
	//  newVelocity = newVelocity.truncateLength (maxSpeed ());
	//  update speed
		setSpeed(mCurrentVelocity.length());
		Vec3 newVelocity(mCurrentVelocity.x, mCurrentVelocity.y, mCurrentVelocity.z);

	//  regenerate local space (by default: align vehicle's forward axis with
	//  new velocity, but this behavior may be overridden by derived classes.)
		if (speed() > 0) regenerateOrthonormalBasisUF (newVelocity / speed());

	//  prevent adding a counter force against gravity
		if (mCurrentVelocity.y < 0.0f) mCurrentVelocity.y = 0.0f;
	}
	mCurrentForce = Ogre::Vector3::ZERO;
}
void PhysicsRagDoll::setPositionOrientation(const Ogre::Vector3& pos, const Ogre::Quaternion &orient)
{
    Ogre::Vector3 oldPos = mNode->_getDerivedPosition();
    Ogre::Quaternion oldOri = mNode->_getDerivedOrientation();
    Ogre::Quaternion oldOriInv = oldOri.Inverse();

    for (RagBoneMapIterator it = mRagBonesMap.begin(); it != mRagBonesMap.end(); it++)
    {
        OgreNewt::Body* body = it->second->getBody();
        if (body)
        {
            Ogre::Vector3 boneOldPos;
            Ogre::Quaternion boneOldOri;
            body->getPositionOrientation(boneOldPos, boneOldOri);
            
            // get old position and orientation in local space
            Ogre::Vector3 boneOldLocalPos = oldOriInv*(boneOldPos - oldPos);
            Ogre::Quaternion boneOldLocalOri = oldOriInv*boneOldOri;

            // calculate and set new position in orientation
            body->setPositionOrientation(pos + orient*boneOldLocalPos, orient*boneOldLocalOri);
            body->unFreeze();
        }
    }
    mNode->setPosition(pos);
    mNode->setOrientation(orient);
}
    void PhysicalObstacle::_update()
    {
    	OgreNewt::Body *body = mPhysicalThing->_getBody();
    	RlAssert(body, "PhysicalThing has no body yet!");
        Vector3 position;
        Quaternion orientation;
        body->getPositionOrientation(position, orientation);

    	const OgreNewt::Collision* collision = body->getCollision();
    	RlAssert(collision, "Body has no collision!");
    	AxisAlignedBox box = collision->getAABB();
    	Ogre::Vector3 dims = box.getMaximum() - box.getMinimum();
    	OpenSteer::BoxObstacle *obstacle = new OpenSteer::BoxObstacle(dims[0], dims[1], dims[2]);
    	obstacle->setForward(0,0,-1);
    	obstacle->setPosition(position[0], position[1], position[2]);
    	//obstacle->setOrientation(orient[0], orient[1], orient[2]);
    	setObstacle(obstacle);
    }