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; }
const ActorVector& RaySceneQuery::execute() { // Clear last results mResult.clear(); // Setup and execute raycast. Set result to be ordered by distance OgreNewt::BasicRaycast raycast = OgreNewt::BasicRaycast( PhysicsManager::getSingleton()._getNewtonWorld(), mRayStart, mRayEnd, true); const OgreNewt::MaterialID* levelId = PhysicsManager::getSingleton().getMaterialID("level"); // Collect results for (int i = 0, num = raycast.getHitCount(); i < num; ++i) { OgreNewt::BasicRaycast::BasicRaycastInfo info = raycast.getInfoAt(i); OgreNewt::Body* body = info.mBody; if (body != NULL) { // Are we done? if (mLevelOcclusion && (body->getMaterialGroupID() == levelId)) break; // Add actor to this body to the result Actor* actor = NULL; if( body->getUserData().getType() == typeid(Actor*) ) { actor = Ogre::any_cast<Actor*>(body->getUserData()); } if (actor != NULL) mResult.push_back(actor); } } return mResult; }
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 PhysicsManager::addLevelGeometry( Ogre::Entity* levelEntity, const std::vector<OgreNewt::CollisionPtr> &collisions) { RlAssert1(levelEntity); RlAssert1(levelEntity->getParentSceneNode()); SceneNode* node = levelEntity->getParentSceneNode(); //Level entity has to be attached to a scene node. // try one compound collision for the entity if there are several collisions OgreNewt::CollisionPtr collision; switch( collisions.size() ) { case 0: break; case 1: collision = collisions[0]; break; default: collision = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::CompoundCollision(mWorld, collisions, 0)); break; } if( collision ) { OgreNewt::Body* body = new OgreNewt::Body(mWorld, collision ); body->attachNode(node); body->setPositionOrientation(node->_getDerivedPosition(), node->_getDerivedOrientation()); body->setMaterialGroupID(getMaterialID("level")); mLevelBodiesQuadTree.add(body); //mLevelBodies.push_back(body); } // adjust worldAABB Vector3 minV(mWorldAABB.getMinimum()); Vector3 maxV(mWorldAABB.getMaximum()); AxisAlignedBox entityAABB = levelEntity->getWorldBoundingBox(true); minV.makeFloor(entityAABB.getMinimum()); maxV.makeCeil(entityAABB.getMaximum()); mWorldAABB.setMinimum(minV - Vector3(50, 50, 50)); mWorldAABB.setMaximum(maxV + Vector3(50, 50, 50)); mWorld->setWorldSize(mWorldAABB); }
void OgreNewtonApplication::createScene() { // sky box. mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); // shadows on! mSceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE ); // floor object! Entity* floor; SceneNode* floornode; floor = mSceneMgr->createEntity("Floor", "simple_terrain.mesh" ); floornode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "FloorNode" ); floornode->attachObject( floor ); floor->setMaterialName( "Simple/BeachStones" ); floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; #endif //floornode->setScale( siz ); bod->attachNode( floornode ); bod->setPositionOrientation( Ogre::Vector3(0.0,-4.0,0.0), Ogre::Quaternion::IDENTITY ); // position camera mCamera->setPosition(0.0, -2.0, 10.0); mCamera->setNearClipDistance( 0.01f ); //make a light Ogre::Light* light; light = mSceneMgr->createLight( "Light1" ); light->setType( Ogre::Light::LT_POINT ); light->setPosition( Ogre::Vector3(0.0, 100.0, 100.0) ); }
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); }
void StepRecognitionMovement::calculateForceAndTorque(Vector3 &force, Vector3 &torque, Real timestep) { // move to nextTarget if( mMoveToNextTarget ) { Real mass; Vector3 inertia; OgreNewt::Body *body = mMovingCreature->getCreature()->getActor()->getPhysicalThing()->_getBody(); body->getMassMatrix(mass, inertia); Vector3 pos = mMovingCreature->getCreature()->getPosition(); Vector3 diff = mNextTarget - pos; Vector3 vel = body->getVelocity(); force.y = mass*( mLinearSpringK*diff.y - mLinearDampingK*vel.y ); std::ostringstream oss; oss << "Step-Recognition: diff: " << diff.y << " vel: " << vel.y << " Step force: " << force.y; oss << " DiffToTarget: " << mMovingCreature->getCreature()->getOrientation().Inverse() * (mNextTarget - mMovingCreature->getCreature()->getPosition()); LOG_MESSAGE(Logger::RULES, oss.str()); } }
OgreNewt::Body* OgreNewtonApplication::makeSimpleBox( Ogre::Vector3& size, Ogre::Vector3& pos, Ogre::Quaternion& orient ) { Entity* box1; SceneNode* box1node; box1 = mSceneMgr->createEntity( "Entity"+Ogre::StringConverter::toString(mEntityCount++), "box.mesh" ); box1node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); box1node->attachObject( box1 ); box1node->setScale( size ); OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( m_World, size, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); // base mass on the size of the object. Ogre::Real mass = size.x * size.y * size.z * 2.5; // calculate the inertia based on box formula and mass Ogre::Vector3 inertia, offset; col->calculateInertialMatrix(inertia, offset); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; #endif bod->attachNode( box1node ); bod->setMassMatrix( mass, mass*inertia ); bod->setCenterOfMass(offset); bod->setStandardForceCallback(); box1->setMaterialName( "Simple/BumpyMetal" ); bod->setPositionOrientation( pos, orient ); return bod; }
void PhysicsManager::run(Real elapsedTime) { // do nothing, if not enabled if (!mEnabled) return; // does not need to be executed each frame! // this is only here for testing //NewtonSetMinimumFrameRate(mWorld->getNewtonWorld(), 1./mMaxTimestep); if( mDebugMode == 4 ) { mWorld->getDebugger().clearRaycastsRecorded(); } // Newton kann timesteps zwischen 1/20 und 1/600! mElapsed += elapsedTime * mTimeFactor; while( mElapsed >= mMaxTimestep) { // perhaps we should add a newtonupdate listener, but i don't // know if it's really neccessary GameEventManager::getSingleton().notifyNewtonWorldUpdate(); mWorld->update(mMaxTimestep); mElapsed-=mMaxTimestep; #ifdef _DEBUG if( mDebugMode ) { LOG_DEBUG(Logger::CORE, "\tNewtonBodyLog: &Body Position Orientation Velocity "\ "Omega Force Torque NewtonBodyGetContinuousCollisionMode mass inertia"); if( Logger::getSingleton().getLogDetail() <= Logger::LL_DEBUG ) for( OgreNewt::Body* body = mWorld->getFirstBody(); body != NULL; body = body->getNext() ) logBodyProperties(body); } #endif } if( mElapsed > mMinTimestep) { // perhaps we should add a newtonupdate listener, but i don't // know if it's really neccessary GameEventManager::getSingleton().notifyNewtonWorldUpdate(); mWorld->update(mElapsed); mElapsed = 0; #ifdef _DEBUG if( mDebugMode ) { LOG_DEBUG(Logger::CORE, "\tNewtonBodyLog: &Body Position Orientation Velocity "\ "Omega Force Torque NewtonBodyGetContinuousCollisionMode mass inertia"); for( OgreNewt::Body* body = mWorld->getFirstBody(); body != NULL; body = body->getNext() ) logBodyProperties(body); } #endif } if( mDebugMode == 2 ) { mWorld->getDebugger().showDebugInformation(); } else if( mDebugMode == 3 ) { mWorld->getDebugger().stopRaycastRecording(); } }
void OgreNewtonApplication::createScene() { // setup CEGUI mGUIRenderer = new CEGUI::OgreCEGUIRenderer( mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr ); new CEGUI::System( mGUIRenderer ); // load up CEGUI stuff... try { using namespace CEGUI; CEGUI::Logger::getSingleton().setLoggingLevel( CEGUI::Informative ); CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLookSkin.scheme"); CEGUI::System::getSingleton().setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow"); CEGUI::System::getSingleton().setDefaultFont((CEGUI::utf8*)"BlueHighway-10"); CEGUI::Window* sheet = CEGUI::WindowManager::getSingleton().createWindow( (CEGUI::utf8*)"DefaultWindow", (CEGUI::utf8*)"root_wnd" ); CEGUI::System::getSingleton().setGUISheet( sheet ); //makeGUI(); //setupGUI(); } catch (CEGUI::Exception) {} // sky box. mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); // shadows on! mSceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE ); // floor object! Entity* floor; SceneNode* floornode; floor = mSceneMgr->createEntity("Floor", "simple_terrain.mesh" ); floornode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "FloorNode" ); floornode->attachObject( floor ); floor->setMaterialName( "Simple/BeachStones" ); floor->setCastShadows( false ); //Ogre::Vector3 siz(100.0, 10.0, 100.0); OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( m_World, floor, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( m_World, col ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete col; #endif //floornode->setScale( siz ); bod->attachNode( floornode ); bod->setPositionOrientation( Ogre::Vector3(0.0,-10.0,0.0), Ogre::Quaternion::IDENTITY ); // make a simple rope. Ogre::Vector3 size(3,1.0,1.0); Ogre::Vector3 pos(0,1,0); Ogre::Quaternion orient = Ogre::Quaternion::IDENTITY; // loop through, making bodies and connecting them. OgreNewt::Body* parent = NULL; OgreNewt::Body* child = NULL; for (int x=0;x<8;x++) { // make the next box. child = makeSimpleBox(size, pos, orient); // now make a new joint connecting this to the last box. OgreNewt::Joint* joint; // make the joint right between the bodies... if (parent) { joint = new OgreNewt::BasicJoints::BallAndSocket( m_World, child, parent, pos-Ogre::Vector3(size.x/2,0,0) ); } else { // no parent, this is the first joint, so just pass NULL as the parent, to stick it to the "world" joint = new OgreNewt::BasicJoints::BallAndSocket( m_World, child, NULL, pos-Ogre::Vector3(size.x/2,0,0) ); } // offset pos a little more. pos += Ogre::Vector3(size.x,0,0); // save the last body for the next loop! parent = child; } for (int i=0; i<15;i++) { pos = Ogre::Vector3( 10-rand()%20, 4+rand()%2, 10-rand()%20 ); size = Ogre::Vector3( 1+rand()%3, 1+rand()%3, 1+rand()%3 ); OgreNewt::Body* bod = makeSimpleBox( size, pos, orient ); } // position camera mCamera->setPosition(0.0, -3.0, 23.0); //make a light Ogre::Light* light; light = mSceneMgr->createLight( "Light1" ); light->setType( Ogre::Light::LT_POINT ); light->setPosition( Ogre::Vector3(0.0, 100.0, 100.0) ); }
void OgreNewtonApplication::createScene() { // sky box. mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); // shadows on! mSceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE ); // floor object! Entity* floor; SceneNode* floornode; floor = mSceneMgr->createEntity("Floor", "simple_terrain.mesh" ); floornode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "FloorNode" ); floornode->attachObject( floor ); floor->setMaterialName( "Simple/BeachStones" ); floor->setCastShadows( false ); //------------------------------------------------------------- // add some other objects. Entity* floor2; SceneNode* floornode2; floor2 = mSceneMgr->createEntity("Floor2", "simple_terrain.mesh" ); floornode2 = floornode->createChildSceneNode( "FloorNode2" ); floornode2->attachObject( floor2 ); floor2->setMaterialName( "Simple/BeachStones" ); floor2->setCastShadows( false ); floornode2->setPosition( Ogre::Vector3(80.0f, 0.0f, 0.0f) ); Entity* floor3; SceneNode* floornode3; floor3 = mSceneMgr->createEntity("Floor3", "simple_terrain.mesh" ); floornode3 = floornode->createChildSceneNode( "FloorNode3" ); floornode3->attachObject( floor3 ); floor3->setMaterialName( "Simple/BeachStones" ); floor3->setCastShadows( false ); floornode3->setPosition( Ogre::Vector3(-80.0f, -5.0f, 0.0f) ); floornode3->setOrientation( Ogre::Quaternion( Ogre::Degree(15.0f), Ogre::Vector3::UNIT_Z ) ); //------------------------------------------------------------- // using the new "SceneParser" TreeCollision primitive. this will automatically parse an entire tree of // SceneNodes (parsing all children), and add collision for all meshes in the tree. OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* stat_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( m_World ); stat_col->parseScene( floornode, true, 0 ); OgreNewt::Body* bod = new OgreNewt::Body( m_World, OgreNewt::CollisionPtr(stat_col) ); #ifdef OGRENEWT_NO_COLLISION_SHAREDPTR delete stat_col; #endif bod->attachNode( floornode ); bod->setPositionOrientation( Ogre::Vector3(0.0,-20.0,0.0), Ogre::Quaternion::IDENTITY ); // make a simple rope. Ogre::Vector3 size(3,1.5,1.5); Ogre::Vector3 pos(0,3,0); Ogre::Quaternion orient = Ogre::Quaternion::IDENTITY; // loop through, making bodies and connecting them. OgreNewt::Body* parent = NULL; OgreNewt::Body* child = NULL; for (int x=0;x<5;x++) { // make the next box. child = makeSimpleBox(size, pos, orient); // now make a new joint connecting this to the last box. OgreNewt::Joint* joint; // make the joint right between the bodies... if (parent) { joint = new MyCustomBallSocket(child, parent, pos-Ogre::Vector3(size.x/2,0,0), Ogre::Vector3(Ogre::Vector3::UNIT_X) ); } else { // no parent, this is the first joint, so just pass NULL as the parent, to stick it to the "world" joint = new MyCustomBallSocket(child, NULL, pos-Ogre::Vector3(size.x/2,0,0), Ogre::Vector3(Ogre::Vector3::UNIT_X) ); } // offset pos a little more. pos += Ogre::Vector3(size.x,0,0); // save the last body for the next loop! parent = child; } // position camera mCamera->setPosition(0.0, -3.0, 20.0); //make a light Ogre::Light* light; light = mSceneMgr->createLight( "Light1" ); light->setType( Ogre::Light::LT_POINT ); light->setPosition( Ogre::Vector3(0.0, 100.0, 100.0) ); }
void EngineMap::create() { //carrega atributos do xml String fileName = "media/maps/"; fileName += _name.c_str(); fileName += ".xml"; TiXmlDocument doc(fileName.c_str()); if (!doc.LoadFile()) return; TiXmlHandle handleDoc(&doc); //obtém elemento com as configurações do mapa TiXmlElement* elMap = handleDoc.FirstChild("map").Element(); if (!elMap) return; String stPlayerStart = elMap->Attribute("player_start"); String stPlayerStartOrientation = elMap->Attribute("player_start_orientation"); String stSkyBox = elMap->Attribute("skybox"); String stMinWorldSize = elMap->Attribute("min_world_size"); String stMaxWorldSize = elMap->Attribute("max_world_size"); String stAmbientLight = elMap->Attribute("ambient_light"); if (stPlayerStart != "") { _playerStart = StringConverter::parseVector3(stPlayerStart); } else { _playerStart = Vector3::ZERO; } if (stPlayerStartOrientation != "") { _playerStartOrientation = StringConverter::parseQuaternion(stPlayerStartOrientation); } else { _playerStartOrientation = Quaternion(1,0,0,0); } _skybox = stSkyBox; _minWorldSize = StringConverter::parseVector3(stMinWorldSize); _maxWorldSize = StringConverter::parseVector3(stMaxWorldSize); //cria a iluminação geral do mapa Vector3 ambientLight = StringConverter::parseVector3(stAmbientLight); EngineGlobalObjects::getInstance().getSceneManager()->setAmbientLight(ColourValue(ambientLight.x, ambientLight.y, ambientLight.z)); //obtém elementos e cria TiXmlElement* elObject = elMap->FirstChildElement("object"); while(elObject) { //obtém o tipo do objeto String stType = elObject->Attribute("type"); //verifica o tipo if (stType == "static_mesh") { String stMass = elObject->Attribute("mass"); String stInertia = elObject->Attribute("inertia"); String stCollision = elObject->Attribute("collision"); String stCastShadows = elObject->Attribute("castshadows"); String stMeshFile = elObject->Attribute("meshfile"); String stMaterial = elObject->Attribute("material"); String stName = elObject->Attribute("name"); String stPosition = elObject->Attribute("position"); String stOrientation = elObject->Attribute("orientation"); String stScale = elObject->Attribute("scale"); String stCenterOfMass = elObject->Attribute("center_of_mass"); //prepara os atributos bool castShadow = StringConverter::parseBool(stCastShadows); String nodeName = "map_object_" + stName; String entityName = "map_object_entity_" + stName; Real mass = StringConverter::parseReal(stMass); Vector3 inertia = StringConverter::parseVector3(stInertia); Vector3 position = StringConverter::parseVector3(stPosition); Quaternion orientation = StringConverter::parseQuaternion(stOrientation); Vector3 scale = StringConverter::parseVector3(stScale); Vector3 centerOfMass = StringConverter::parseVector3(stCenterOfMass); //cria o node e entity Entity *entity; entity = EngineGlobalObjects::getInstance().getSceneManager()->createEntity(entityName, stMeshFile); if (stMaterial != "") { entity->setMaterialName(stMaterial); } entity->setCastShadows(castShadow); SceneNode *node = EngineGlobalObjects::getInstance().getSceneManager()->getRootSceneNode()->createChildSceneNode(nodeName); node->attachObject(entity); //define tamanho node->setScale(scale); //cria colisão if (stCollision == "fixed") { OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( EngineGlobalObjects::getInstance().getWorld(), entity, true, 0 )); OgreNewt::Body* bod = new OgreNewt::Body( EngineGlobalObjects::getInstance().getWorld(), col ); bod->attachNode( node ); bod->setPositionOrientation( position, orientation ); //define callback customizado bod->setCustomForceAndTorqueCallback<EngineMap>(&EngineMap::forceCallback, this); } else if (stCollision == "normal") { OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull(EngineGlobalObjects::getInstance().getWorld(), entity, 0)); OgreNewt::Body* bod = new OgreNewt::Body( EngineGlobalObjects::getInstance().getWorld(), col ); bod->attachNode( node ); bod->setMassMatrix( mass, inertia ); bod->setCenterOfMass(centerOfMass); bod->setStandardForceCallback(); bod->setPositionOrientation( position, orientation ); //define callback customizado bod->setCustomForceAndTorqueCallback<EngineMap>(&EngineMap::forceCallback, this); } } else if (stType == "light") { String stName = elObject->Attribute("name"); String stPosition = elObject->Attribute("position"); String stDirection = elObject->Attribute("direction"); String stAttenuation = elObject->Attribute("attenuation"); String stCastShadows = elObject->Attribute("castshadows"); String stDiffuse = elObject->Attribute("diffuse"); String stLightrange = elObject->Attribute("lightrange"); String stLighttype = elObject->Attribute("lighttype"); String stPower = elObject->Attribute("power"); String stSpecular = elObject->Attribute("specular"); Light *light; light = EngineGlobalObjects::getInstance().getSceneManager()->createLight(stName); if(stLighttype=="LT_POINT") light->setType(Light::LT_POINT); if(stLighttype=="LT_SPOTLIGHT") light->setType(Light::LT_SPOTLIGHT); if(stLighttype=="LT_DIRECTIONAL") light->setType(Light::LT_DIRECTIONAL); light->setPosition(StringConverter::parseVector3(stPosition)); light->setDiffuseColour(StringConverter::parseColourValue(stDiffuse)); light->setSpecularColour(StringConverter::parseColourValue(stSpecular)); Vector4 att = StringConverter::parseVector4(stAttenuation); light->setAttenuation(att.x, att.y, att.z, att.w); light->setDirection(StringConverter::parseVector3(stDirection)); light->setPowerScale(StringConverter::parseReal(stPower)); light->setSpotlightFalloff(1); light->setCastShadows(StringConverter::parseBool(stCastShadows)); } elObject = elObject->NextSiblingElement("object"); } //obtém elementos da fog e cria TiXmlElement* elFog = elMap->FirstChildElement("fog"); while(elFog) { String stFogMode = elFog->Attribute("mode"); String stFogColour = elFog->Attribute("colour"); String stFogStart = elFog->Attribute("start"); String stFogEnd = elFog->Attribute("end"); String stFogDensity = elFog->Attribute("density"); _fogMode = stFogMode; _fogColour = StringConverter::parseColourValue(stFogColour); _fogStart = StringConverter::parseReal(stFogStart); _fogEnd = StringConverter::parseReal(stFogEnd); _fogDensity = StringConverter::parseReal(stFogDensity); //configura a fog no cenário se o modo da fog foi informado if (stFogMode != "") { FogMode fogMode; if (_fogMode == "none") fogMode = FogMode::FOG_NONE; if (_fogMode == "exp") fogMode = FogMode::FOG_EXP; if (_fogMode == "exp2") fogMode = FogMode::FOG_EXP2; if (_fogMode == "linear") fogMode = FogMode::FOG_LINEAR; EngineGlobalObjects::getInstance().getSceneManager()->setFog(fogMode, _fogColour, _fogDensity, _fogStart, _fogEnd); } elFog = elFog->NextSiblingElement("fog"); } //cria o céu createSkyBox(); doc.Clear(); }
void SteeringVehicle::update(const float currentTime, const float elapsedTime) { SimpleVehicle::update(currentTime, elapsedTime); Vector3 pos = mCreature->getPosition(); setPosition(pos); OgreNewt::Body* body = mCreature->getActor()->getPhysicalThing()->_getBody(); // Get the velocity vector mCurrentVelocity = body->getVelocity(); // enforce speed limit // newVelocity = newVelocity.truncateLength(maxSpeed()); // update speed setSpeed(mCurrentVelocity.length()); Vector3 newVelocity(mCurrentVelocity); // regenerate local space(by default: align vehicle's forward axis with // new velocity, but this behavior may be overridden by derived classes.) // use future orientation or not?? Quaternion orientation(mController->getYaw(), Ogre::Vector3::UNIT_Y); Vector3 newUnitForward = orientation*Vector3::NEGATIVE_UNIT_Z; regenerateOrthonormalBasisUF(newUnitForward); // only process if mMovingCreature not NULL if (mController == NULL || mCreature->getQueryFlags() & QUERYFLAG_PLAYER) { mCurrentForce = Vector3::ZERO; return; } // calculate the result of the force Vector3 result = mCurrentForce;// + mCurrentVelocity; mDebugSteer = mCurrentForce; // @todo remove this if (mCreature->getAu() <= 6) mCreature->modifyAu(20,true); AbstractMovement* mov_drehen = mController->getMovementFromId(CreatureController::MT_DREHEN); Real vel_drehen(0); Radian max_drehen = Degree(0); if (mov_drehen->calculateBaseVelocity(vel_drehen)) { max_drehen = Degree(vel_drehen * 360 * elapsedTime); } Ogre::Quaternion future_orientation(mController->getYaw(), Ogre::Vector3::UNIT_Y); Ogre::Vector3 creatureDirection = future_orientation * Ogre::Vector3::NEGATIVE_UNIT_Z; Radian yaw(0); creatureDirection.y = result.y = 0; yaw = creatureDirection.getRotationTo(result, Ogre::Vector3::UNIT_Y).getYaw(); if (yaw > Radian(0) && yaw > max_drehen) yaw = max_drehen; if (yaw < Radian(0) && yaw < -max_drehen) yaw = -max_drehen; Ogre::Vector3 direction(Ogre::Vector3::ZERO); Ogre::Vector3 rotation(0,yaw.valueRadians(),0); CreatureController::MovementType movement = CreatureController::MT_STEHEN; if (result != Ogre::Vector3::ZERO) { direction.z = -1; movement = CreatureController::MT_GEHEN; } mController->setMovement(movement, direction, rotation); LOG_DEBUG(Logger::AI, "SteeringVehicle: mController->setMovement " + Ogre::StringConverter::toString(movement) + ", " + Ogre::StringConverter::toString(direction) + ", " + Ogre::StringConverter::toString(rotation)); mCurrentForce = Ogre::Vector3::ZERO; }