mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-04 00:26:45 +00:00 
			
		
		
		
	Starting to implement new PhysicActor
This commit is contained in:
		
							parent
							
								
									2efceba1fc
								
							
						
					
					
						commit
						23777033fd
					
				
					 8 changed files with 49 additions and 37 deletions
				
			
		| 
						 | 
				
			
			@ -89,7 +89,7 @@ namespace MWClass
 | 
			
		|||
    {
 | 
			
		||||
        const std::string model = getModel(ptr);
 | 
			
		||||
        if(!model.empty()){
 | 
			
		||||
            physics.insertObjectPhysics(ptr, model);
 | 
			
		||||
            physics.insertActorPhysics(ptr, model);
 | 
			
		||||
        }
 | 
			
		||||
        MWBase::Environment::get().getMechanicsManager()->addActor (ptr);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,7 +125,7 @@ namespace MWClass
 | 
			
		|||
 | 
			
		||||
    void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
 | 
			
		||||
    {
 | 
			
		||||
        physics.insertObjectPhysics(ptr, getModel(ptr));
 | 
			
		||||
        physics.insertActorPhysics(ptr, getModel(ptr));
 | 
			
		||||
        MWBase::Environment::get().getMechanicsManager()->addActor(ptr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -294,7 +294,7 @@ namespace MWClass
 | 
			
		|||
    {
 | 
			
		||||
        Ogre::Vector3 vector (0, 0, 0);
 | 
			
		||||
 | 
			
		||||
        vector.x = - getMovementSettings (ptr).mLeftRight * 127;
 | 
			
		||||
        vector.x = getMovementSettings (ptr).mLeftRight * 127;
 | 
			
		||||
        vector.y = getMovementSettings (ptr).mForwardBackward * 127;
 | 
			
		||||
		vector.z = getMovementSettings(ptr).mUpDown * 127;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -266,6 +266,7 @@ RenderingManager::rotateObject(
 | 
			
		|||
        float *f = ptr.getRefData().getPosition().rot;
 | 
			
		||||
        rot.x += f[0], rot.y += f[1], rot.z += f[2];
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if (!isPlayer && isActive) {
 | 
			
		||||
        Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X);
 | 
			
		||||
        Ogre::Quaternion yr(Ogre::Radian(rot.y), Ogre::Vector3::UNIT_Y);
 | 
			
		||||
| 
						 | 
				
			
			@ -273,6 +274,7 @@ RenderingManager::rotateObject(
 | 
			
		|||
        
 | 
			
		||||
        ptr.getRefData().getBaseNode()->setOrientation(xr * yr * zr);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return force;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -201,8 +201,7 @@ namespace MWWorld
 | 
			
		|||
                playerphysics->ps.viewangles.y =
 | 
			
		||||
                    Ogre::Radian(mPlayerData.yaw).valueDegrees() + 90;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                pm_ref.rightmove = -iter->second.x;
 | 
			
		||||
                pm_ref.rightmove = iter->second.x;
 | 
			
		||||
                pm_ref.forwardmove = -iter->second.y;
 | 
			
		||||
                pm_ref.upmove = iter->second.z;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -215,6 +214,7 @@ namespace MWWorld
 | 
			
		|||
    {
 | 
			
		||||
        Pmove(playerphysics);
 | 
			
		||||
       
 | 
			
		||||
 | 
			
		||||
        std::vector< std::pair<std::string, Ogre::Vector3> > response;
 | 
			
		||||
        for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -224,6 +224,7 @@ namespace MWWorld
 | 
			
		|||
            if(it->first == "player"){
 | 
			
		||||
 | 
			
		||||
                coord = playerphysics->ps.origin ;
 | 
			
		||||
                 
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -257,8 +258,9 @@ namespace MWWorld
 | 
			
		|||
        const Ogre::Vector3& position, float scale, const Ogre::Quaternion& rotation)
 | 
			
		||||
    {
 | 
			
		||||
        //TODO:optimize this. Searching the std::map isn't very efficient i think.
 | 
			
		||||
        std::cout << "NPC position" << position << "\n";
 | 
			
		||||
        mEngine->addCharacter(handle, mesh, position, scale, rotation);
 | 
			
		||||
        OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle);
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -189,7 +189,9 @@ namespace MWWorld
 | 
			
		|||
        mPlayer = new MWWorld::Player (mStore.npcs.find ("player"), *this);
 | 
			
		||||
        mRendering->attachCameraTo(mPlayer->getPlayer());
 | 
			
		||||
 | 
			
		||||
        mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), "", Ogre::Vector3 (0, 0, 0), 0, Ogre::Quaternion::ZERO);
 | 
			
		||||
        std::string playerCollisionFile = "meshes\\base_anim.nif";    //This is used to make a collision shape for our player
 | 
			
		||||
                                                                      //We will need to support the 1st person file too in the future
 | 
			
		||||
        mPhysics->addActor (mPlayer->getPlayer().getRefData().getHandle(), playerCollisionFile, Ogre::Vector3 (0, 0, 0), 1, Ogre::Quaternion::ZERO);
 | 
			
		||||
 | 
			
		||||
        // global variables
 | 
			
		||||
        mGlobalVariables = new Globals (mStore);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,12 +27,12 @@ namespace Physic
 | 
			
		|||
    };
 | 
			
		||||
 | 
			
		||||
    PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale): 
 | 
			
		||||
        mName(name), mEngine(engine), mMesh(mesh), mBoxTranslation(Ogre::Vector3::ZERO), mBoxRotation(Ogre::Quaternion::ZERO), mBody(0)
 | 
			
		||||
        mName(name), mEngine(engine), mMesh(mesh), mBoxTranslation(Ogre::Vector3::ZERO), mBoxRotation(Ogre::Quaternion::ZERO), mBody(0), collisionMode(false)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        // The capsule is at the origin
 | 
			
		||||
        btTransform transform;
 | 
			
		||||
        transform.setIdentity();
 | 
			
		||||
        Ogre::Vector3 test;
 | 
			
		||||
        mBody = mEngine->createAndAdjustRigidBody(mesh, mName, scale, position, rotation, &test);
 | 
			
		||||
        std::cout << "Test" << test << "\n";
 | 
			
		||||
        mEngine->addRigidBody(mBody, false);  //Add rigid body to dynamics world, but do not add to object map
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +51,7 @@ namespace Physic
 | 
			
		|||
 | 
			
		||||
    void PhysicActor::enableCollisions(bool collision)
 | 
			
		||||
    {
 | 
			
		||||
       
 | 
			
		||||
        collisionMode = collision;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void PhysicActor::setVerticalVelocity(float z)
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +61,7 @@ namespace Physic
 | 
			
		|||
 | 
			
		||||
    bool PhysicActor::getCollisionMode()
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
        return collisionMode;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void PhysicActor::setWalkDirection(const btVector3& mvt)
 | 
			
		||||
| 
						 | 
				
			
			@ -79,12 +79,12 @@ namespace Physic
 | 
			
		|||
 | 
			
		||||
    btVector3 PhysicActor::getPosition(void)
 | 
			
		||||
    {
 | 
			
		||||
        return btVector3(0,0,0);//return internalGhostObject->getWorldTransform().getOrigin() -mTranslation;
 | 
			
		||||
        return mBody->getWorldTransform().getOrigin();//return internalGhostObject->getWorldTransform().getOrigin() -mTranslation;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    btQuaternion PhysicActor::getRotation(void)
 | 
			
		||||
    {
 | 
			
		||||
        return btQuaternion(0,0,0);//return btQuaternion::internalGhostObject->getWorldTransform().getRotation();
 | 
			
		||||
        return mBody->getWorldTransform().getRotation();//return btQuaternion::internalGhostObject->getWorldTransform().getRotation();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void PhysicActor::setPosition(const btVector3& pos)
 | 
			
		||||
| 
						 | 
				
			
			@ -290,7 +290,8 @@ namespace Physic
 | 
			
		|||
        mHeightFieldMap.erase(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void PhysicEngine::adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation){
 | 
			
		||||
    void PhysicEngine::adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, 
 | 
			
		||||
        Ogre::Vector3 scaledBoxPosition, Ogre::Quaternion boxRotation){
 | 
			
		||||
        btTransform tr;
 | 
			
		||||
        btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
 | 
			
		||||
        if(box != NULL){
 | 
			
		||||
| 
						 | 
				
			
			@ -317,8 +318,11 @@ namespace Physic
 | 
			
		|||
        adjustRigidBody(shape, body, scale, position, rotation);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation)
 | 
			
		||||
    RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
 | 
			
		||||
        Ogre::Vector3* scaledBoxPosition, Ogre::Quaternion* boxRotation)
 | 
			
		||||
    {
 | 
			
		||||
        if(scaledBoxPosition != 0)
 | 
			
		||||
            *scaledBoxPosition = Ogre::Vector3(0, 5, 0);
 | 
			
		||||
        std::string sid = (boost::format("%07.3f") % scale).str();
 | 
			
		||||
        std::string outputstring = mesh + sid;
 | 
			
		||||
        //std::cout << "The string" << outputstring << "\n";
 | 
			
		||||
| 
						 | 
				
			
			@ -348,7 +352,7 @@ namespace Physic
 | 
			
		|||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void PhysicEngine::addRigidBody(RigidBody* body)
 | 
			
		||||
    void PhysicEngine::addRigidBody(RigidBody* body, bool addToMap)
 | 
			
		||||
    {
 | 
			
		||||
        if(body)
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			@ -361,14 +365,16 @@ namespace Physic
 | 
			
		|||
                dynamicsWorld->addRigidBody(body,COL_RAYCASTING,COL_RAYCASTING|COL_WORLD);
 | 
			
		||||
            }
 | 
			
		||||
            body->setActivationState(DISABLE_DEACTIVATION);
 | 
			
		||||
            RigidBody* oldBody = RigidBodyMap[body->mName];
 | 
			
		||||
            if (oldBody != NULL)
 | 
			
		||||
            {
 | 
			
		||||
                dynamicsWorld->removeRigidBody(oldBody);
 | 
			
		||||
                delete oldBody;
 | 
			
		||||
            }
 | 
			
		||||
            if(addToMap){
 | 
			
		||||
                RigidBody* oldBody = RigidBodyMap[body->mName];
 | 
			
		||||
                if (oldBody != NULL)
 | 
			
		||||
                {
 | 
			
		||||
                    dynamicsWorld->removeRigidBody(oldBody);
 | 
			
		||||
                    delete oldBody;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            RigidBodyMap[body->mName] = body;
 | 
			
		||||
                RigidBodyMap[body->mName] = body;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -92,6 +92,7 @@ namespace Physic
 | 
			
		|||
        OEngine::Physic::RigidBody* mBody;
 | 
			
		||||
        Ogre::Vector3 mBoxTranslation;
 | 
			
		||||
        Ogre::Quaternion mBoxRotation;
 | 
			
		||||
        bool collisionMode;
 | 
			
		||||
        std::string mMesh;
 | 
			
		||||
        PhysicEngine* mEngine;
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			@ -138,18 +139,18 @@ namespace Physic
 | 
			
		|||
        ~PhysicEngine();
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Create a RigidBody.It does not add it to the simulation, but it does add it to the rigidBody Map,
 | 
			
		||||
         * so you can get it with the getRigidBody function.
 | 
			
		||||
 | 
			
		||||
           After created, the body is set to the correct rotation, position, and scale
 | 
			
		||||
         * Creates a RigidBody.  It does not add it to the simulation.
 | 
			
		||||
         * After created, the body is set to the correct rotation, position, and scale
 | 
			
		||||
         */
 | 
			
		||||
        RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation);
 | 
			
		||||
        RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, 
 | 
			
		||||
            Ogre::Vector3* scaledBoxPosition = 0, Ogre::Quaternion* boxRotation = 0);
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Adjusts a rigid body to the right position and rotation
 | 
			
		||||
         */
 | 
			
		||||
 | 
			
		||||
        void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation);
 | 
			
		||||
        void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, 
 | 
			
		||||
            Ogre::Vector3 scaledBoxPosition = Ogre::Vector3::ZERO, Ogre::Quaternion boxRotation = Ogre::Quaternion::ZERO);
 | 
			
		||||
        /**
 | 
			
		||||
         Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation.
 | 
			
		||||
         */
 | 
			
		||||
| 
						 | 
				
			
			@ -169,7 +170,7 @@ namespace Physic
 | 
			
		|||
        /**
 | 
			
		||||
         * Add a RigidBody to the simulation
 | 
			
		||||
         */
 | 
			
		||||
        void addRigidBody(RigidBody* body);
 | 
			
		||||
        void addRigidBody(RigidBody* body, bool addToMap = true);
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Remove a RigidBody from the simulation. It does not delete it, and does not remove it from the RigidBodyMap.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,8 +36,7 @@ void newtrace(traceResults* const results, const Ogre::Vector3& start, const Ogr
 | 
			
		|||
	//Ogre::Vector3 endReplace = startReplace;
 | 
			
		||||
	//endReplace.z -= .25;
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f,0.0f), isInterior, enginePass);
 | 
			
		||||
	const bool hasHit = NewPhysicsTrace<collisionWorldTrace>(&out, start, end, BBHalfExtents, Ogre::Vector3(0.0f, 0.0f, 0.0f), isInterior, enginePass);
 | 
			
		||||
	
 | 
			
		||||
	if (out.fraction < 0.001f)
 | 
			
		||||
		results->startsolid = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue