//----------------------------------------------------------------------------- void SSAOApp::_buildRoom() { Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0.0f); Ogre::MeshPtr planeMesh = Ogre::MeshManager::getSingleton().createPlane("Plane.mesh" ,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ,plane , 1000, 1000 , 1, 1, true , 1, 5, 5 , Ogre::Vector3::UNIT_Z ); Ogre::SceneNode *wallNode; wallNode = _makeWall("Plane.mesh", "ground"); wallNode = _makeWall("Plane.mesh", "left wall"); wallNode->translate(-500, 500, 0); wallNode->roll(Ogre::Radian(-Ogre::Math::PI / 2)); wallNode = _makeWall("Plane.mesh", "back wall"); wallNode->translate(0, 500, -500); wallNode->pitch(Ogre::Radian(Ogre::Math::PI / 2)); wallNode = _makeWall("Plane.mesh", "right wall"); wallNode->translate(500, 500, 0); wallNode->roll(Ogre::Radian(Ogre::Math::PI / 2)); }
void Room::initOgreEntity(Ogre::SceneManager* mSceneMgr){ Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane( "wall", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, WALL_SIZE, WALL_SIZE, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* walls[NUM_WALLS]; for(int i = 0; i < NUM_WALLS; i++){ walls[i] = mSceneMgr->createEntity("wall"); walls[i]->setMaterialName("Examples/Rockwall"); walls[i]->setCastShadows(true); } //FLOOR mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(walls[0]); //CEILING Ogre::SceneNode* sceneForManip = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, WALL_SIZE, 0)); sceneForManip->attachObject(walls[1]); sceneForManip->roll(Ogre::Degree(180)); //LEFT WALL sceneForManip = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-WALL_SIZE/2, WALL_SIZE/2, 0)); sceneForManip->attachObject(walls[2]); sceneForManip->roll(Ogre::Degree(-90)); //RIGHT WALL sceneForManip = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(WALL_SIZE/2, WALL_SIZE/2, 0)); sceneForManip->attachObject(walls[3]); sceneForManip->roll(Ogre::Degree(90)); //BACK WALL sceneForManip = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, WALL_SIZE/2, -WALL_SIZE/2)); sceneForManip->attachObject(walls[4]); sceneForManip->pitch(Ogre::Degree(90)); //FRONT WALL sceneForManip = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, WALL_SIZE/2, WALL_SIZE/2)); sceneForManip->attachObject(walls[5]); sceneForManip->pitch(Ogre::Degree(-90)); targetWall = sceneForManip; }
void ModelMountTestCase::testModelMountScaling() { Ogre::Root root; Ogre::SceneManager* sceneManager = root.createSceneManager(Ogre::ST_GENERIC); TestModel model(*sceneManager); //First test with a straight forward case. Ogre::SceneNode* node = sceneManager->getRootSceneNode()->createChildSceneNode(); //We get an error when it's destroyed. So we don't destroy it. SceneNodeProvider* nodeProvider = new SceneNodeProvider(node, nullptr); Model::ModelMount mount(model, nodeProvider); scaleAndTestMount(model, mount, nodeProvider->getNode()); //Test with the parent node being scaled node->setScale(Ogre::Vector3(3.0f, 0.2f, 200.0f)); Ogre::SceneNode* subNode = node->createChildSceneNode(); nodeProvider = new SceneNodeProvider(subNode, nullptr); Model::ModelMount mount2(model, nodeProvider); scaleAndTestMount(model, mount2, nodeProvider->getNode()); //Test with the parent node being scaled and rotated node->setScale(Ogre::Vector3(3.0f, 0.2f, 200.0f)); node->yaw(Ogre::Degree(42)); node->pitch(Ogre::Degree(76)); node->roll(Ogre::Degree(98)); subNode = node->createChildSceneNode(); nodeProvider = new SceneNodeProvider(subNode, nullptr); Model::ModelMount mount3(model, nodeProvider); scaleAndTestMount(model, mount3, nodeProvider->getNode()); }
void Hundir::createScene() { Ogre::Entity* inicio = _sceneManager->createEntity("Inicio.mesh"); Ogre::SceneNode* ninicio = _sceneManager->createSceneNode("ninicio"); _sceneManager->getRootSceneNode()->addChild(ninicio); ninicio->attachObject(inicio); ninicio->yaw(Ogre::Degree(-15)); ninicio->pitch(Ogre::Degree(50)); ninicio->roll(Ogre::Degree(90)); ninicio->setScale(1,1.5,1.2); ninicio->setPosition(0,0,-2); /* Sombras */ _sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE); _sceneManager->setShadowColour(Ogre::ColourValue(0.5, 0.5, 0.5) ); _sceneManager->setAmbientLight(Ogre::ColourValue(0.9, 0.9, 0.9)); _sceneManager->setShadowTextureCount(2); _sceneManager->setShadowTextureSize(512); /* Iluminacion */ Ogre::Light *light = _sceneManager->createLight("Light"); light->setType(Ogre::Light::LT_SPOTLIGHT); light->setDirection(Ogre::Vector3(0,-1,0)); light->setSpotlightInnerAngle(Ogre::Degree(25.0f)); light->setSpotlightOuterAngle(Ogre::Degree(200.0f)); light->setPosition(0, 150, 0); light->setSpecularColour(1, 1, 1); light->setDiffuseColour(1, 1, 1); light->setSpotlightFalloff(5.0f); light->setCastShadows(true); }
void ProjectileManager::createProjectile(const Ogre::Vector3& tankPosition, const Ogre::Quaternion& turretOrientation, const Ogre::Degree& angle, const float& velocity, const float& dmg){ std::ostringstream oss; oss << "Projectile" << time(0) << projectiles.size() << counter++; Ogre::ParticleSystem* particleSystem = mSceneMgr->createParticleSystem(oss.str(), "Examples/PurpleFountain"); scaleBy(1.f, particleSystem); Ogre::SceneNode* parentParticleSn = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Ogre::SceneNode* particleSn = parentParticleSn->createChildSceneNode(); Ogre::Vector3 start(-115.f, 10.f, 0.f); parentParticleSn->setPosition(tankPosition); particleSn->setPosition(start); parentParticleSn->yaw(turretOrientation.getYaw()); particleSn->attachObject(particleSystem); particleSn->roll(Ogre::Degree(-90.f)); particleSn->scale(Ogre::Vector3(0.1f)); projectiles.insert(new Projectile(start, particleSn, angle, velocity, dmg)); }
// Fix for Simon in regards to animation mesh's orientation void Player::setAnimation(DynamicObject *p) { // makes a child node of parent node Ogre::SceneNode *childNode = mPlayerObject->mSceneNode->createChildSceneNode("child"); childNode->flipVisibility(true); // makes this entire thing visible since parent node is invisible for (Ogre::String name : p->meshNames) { Ogre::Entity *newEnt = mSceneManager->createEntity(name); //mEntity->setCastShadows(true); childNode->attachObject(newEnt); childNode->setPosition(0, -125, 0); childNode->setOrientation(Ogre::Quaternion(0, 0, 1, -1)); // does the rotation childNode->roll(Ogre::Radian(Ogre::Math::PI)); // fixes it so player's back faces us } }
Wall* Application::createWall(Ogre::String nme, GameObject::objectType tp, Ogre::String meshName, int x, int y, int z, Ogre::Vector3 scale, Ogre::Degree pitch, Ogre::Degree yaw, Ogre::Degree roll, Ogre::SceneManager* scnMgr, GameManager* ssm, Ogre::Real mss, Ogre::Real rest, Ogre::Real frict, bool kinematic, Simulator* mySim) { createRootEntity(nme, meshName, x, y, z); Ogre::SceneNode* sn = mSceneManager->getSceneNode(nme); Ogre::Entity* ent = SceneHelper::getEntity(mSceneManager, nme, 0); const btTransform pos; OgreMotionState* ms = new OgreMotionState(pos, sn); sn->setScale(scale.x, scale.y, scale.z); sn->pitch(pitch); sn->yaw(yaw); sn->roll(roll); Wall* obj = new Wall(nme, tp, mSceneManager, ssm, sn, ent, ms, mySim, mss, rest, frict, scale, kinematic); obj->addToSimulator(); return obj; }
Agent::Agent(Ogre::SceneManager* SceneManager, std::string name, std::string filename, float height, float scale) { using namespace Ogre; mSceneMgr = SceneManager; // keep a pointer to where this agent will be if (mSceneMgr == NULL) { std::cout << "ERROR: No valid scene manager in Agent constructor" << std::endl; return; } this->height = height; this->scale = scale; mBodyNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); // create a new scene node mBodyEntity = mSceneMgr->createEntity(name, filename); // load the model mBodyNode->attachObject(mBodyEntity); // attach the model to the scene node mBodyNode->translate(0,height,0); // make the Ogre stand on the plane (almost) mBodyNode->scale(scale,scale,scale); // Scale the figure // Lecture 16: Movable text //Ogre::MovableText* msg = new Ogre::MovableText("TXT_001", "this is the caption"); //msg->setTextAlignment(Ogre::MovableText::H_CENTER, Ogre::MovableText::V_ABOVE); // Center horizontally and display above the node //mBodyNode->attachObject(msg); projectile = false; // lecture 12 mass = 1.0; ParticleSystem::setDefaultNonVisibleUpdateTimeout(5); // set nonvisible timeout ps = mSceneMgr->createParticleSystem("Fountain1", "Examples/PurpleFountain"); Ogre::SceneNode* mnode = mBodyNode->createChildSceneNode(); mnode->roll(Degree(180)); mnode->attachObject(ps); ps->setVisible(false); //initPos = Ogre::Vector3::ZERO; //default position if none given initPos = this->mBodyNode->getPosition(); //save starting position vel = Ogre::Vector3::ZERO; }
ObjectEditHandler::ObjectEditHandler(SceneDoc *Owner) { mOwner = Owner; mMode = OEM_NONE; mAxisMode = AM_NONE; mTarget = NULL; mObjectEditNode = mOwner->getSceneManager()->getRootSceneNode()->createChildSceneNode(); mRayQuery = mOwner->getSceneManager()->createRayQuery(Ogre::Ray()); mMaterials[0] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/RedMat"); mMaterials[1] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/GreenMat"); mMaterials[2] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/BlueMat"); mMaterials[3] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/ObjectIndicatorWhiteMat"); mMaterials[4] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/ObjectIndicatorYellowMat"); ////////////////////////////////////////////////// // 碰撞检测 ////////////////////////////////////////////////// mCollisionManager = new OgreOpcode::CollisionManager(Owner->getSceneManager()); mCollisionManager->addCollClass("Object"); mCollisionManager->addCollType("Object", "Object", OgreOpcode::COLLTYPE_IGNORE); mCollisionContext = mCollisionManager->createContext("SceneObject"); Ogre::MovableObjectFactory* Factory = Ogre::Root::getSingleton().getMovableObjectFactory(Ogre::EntityFactory::FACTORY_TYPE_NAME); Ogre::NameValuePairList Params; ////////////////////////////////////////////////// // 平移放缩指示器 ////////////////////////////////////////////////// mIndicatorContext = mCollisionManager->createContext("TransScale"); mTransScaleNode = mObjectEditNode->createChildSceneNode("TransScaleIndicator"); mTransScaleNode->setScale(200.0f, 200.0f, 200.0f); // x Ogre::SceneNode *SubNode = mTransScaleNode->createChildSceneNode(); SubNode->roll(Ogre::Degree(-90.0f)); Ogre::Entity *Entity = Owner->getSceneManager()->createEntity("TransScaleXLine", "MoveArrowLineVisible.mesh"); //Entity->setQueryFlags(0); // 参与查询 Entity->setCastShadows(false); Entity->setMaterial(mMaterials[0]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_TRANS_SCALE_X] = Entity; Entity = Owner->getSceneManager()->createEntity("TransScaleXCone", "MoveArrowConeVisible.mesh"); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[0]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); Params["mesh"] = "MoveArrowCollision.mesh"; Entity = (Ogre::Entity*)Factory->createInstance("TransScaleXCol", Owner->getSceneManager(), &Params); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setVisible(false); SubNode->attachObject(Entity); OgreOpcode::CollisionObject *CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_X; // y SubNode = mTransScaleNode; Entity = Owner->getSceneManager()->createEntity("TransScaleYLine", "MoveArrowLineVisible.mesh"); //Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[1]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_TRANS_SCALE_Y] = Entity; Entity = Owner->getSceneManager()->createEntity("TransScaleYCone", "MoveArrowConeVisible.mesh"); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[1]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); Params["mesh"] = "MoveArrowCollision.mesh"; Entity = (Ogre::Entity*)Factory->createInstance("TransScaleYCol", Owner->getSceneManager(), &Params); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setVisible(false); SubNode->attachObject(Entity); CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_Y; // z SubNode = mTransScaleNode->createChildSceneNode(); SubNode->pitch(Ogre::Degree(90)); Entity = Owner->getSceneManager()->createEntity("TransScaleZLine", "MoveArrowLineVisible.mesh"); //Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[2]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_TRANS_SCALE_Z] = Entity; Entity = Owner->getSceneManager()->createEntity("TransScaleZCone", "MoveArrowConeVisible.mesh"); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[2]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); Params["mesh"] = "MoveArrowCollision.mesh"; Entity = (Ogre::Entity*)Factory->createInstance("TransScaleZCol", Owner->getSceneManager(), &Params); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setVisible(false); SubNode->attachObject(Entity); CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_Z; // box SubNode = mTransScaleNode; Params["mesh"] = "Box1m.mesh"; Entity =(Ogre::Entity*)Factory->createInstance("TransScaleAll", Owner->getSceneManager(), &Params); //Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[3]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_TRANS_SCALE_ALL] = Entity; CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_ALL; mIndicatorContext->reset(); mObjectEditNode->removeChild(mTransScaleNode); ////////////////////////////////////////////////// // 旋转指示器 ////////////////////////////////////////////////// mIndicatorContext = mCollisionManager->createContext("Rotate"); mRotateNode = mObjectEditNode->createChildSceneNode("RotateIndicator"); mRotateNode->setScale(200.0f, 200.0f, 200.0f); // x SubNode = mRotateNode->createChildSceneNode(); SubNode->roll(Ogre::Degree(90)); Entity = Owner->getSceneManager()->createEntity("RotateX", "RotationRingVisible.mesh"); //Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[0]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_ROTATE_X] = Entity; Params["mesh"] = "RotationRingCollision.mesh"; Entity =(Ogre::Entity*)Factory->createInstance("RotateXCol", Owner->getSceneManager(), &Params); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setVisible(false); SubNode->attachObject(Entity); CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_X; // y SubNode = mRotateNode; Entity = Owner->getSceneManager()->createEntity("RotateY", "RotationRingVisible.mesh"); //Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[1]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_ROTATE_Y] = Entity; Params["mesh"] = "RotationRingCollision.mesh"; Entity =(Ogre::Entity*)Factory->createInstance("RotateYCol", Owner->getSceneManager(), &Params); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setVisible(false); SubNode->attachObject(Entity); CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_Y; // z SubNode = mRotateNode->createChildSceneNode(); SubNode->pitch(Ogre::Degree(90.0f)); Entity = Owner->getSceneManager()->createEntity("RotateZ", "RotationRingVisible.mesh"); //Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setMaterial(mMaterials[2]); Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); SubNode->attachObject(Entity); mTransformEntities[AM_ROTATE_Z] = Entity; Params["mesh"] = "RotationRingCollision.mesh"; Entity =(Ogre::Entity*)Factory->createInstance("RotateZCol", Owner->getSceneManager(), &Params); Entity->setQueryFlags(0); Entity->setCastShadows(false); Entity->setVisible(false); SubNode->attachObject(Entity); CollisionObject = AddCollisionEntity(mIndicatorContext, Entity); mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_Z; mIndicatorContext->reset(); mObjectEditNode->removeChild(mRotateNode); }
Ogre::Entity* ModelFile::GetModel( const ModelInfo& info ) { VectorTexForGen textures; Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create( info.data.name + "export", "General" ); Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create( info.data.name + "export", "General" ); int number_of_bones = GetU8( 0x02 ); int number_of_parts = GetU8( 0x03 ); int offset_to_bones = GetU32LE( 0x0c ); int offset_to_parts = GetU32LE( 0x10 ); Ogre::Bone* root1 = skeleton->createBone( "0", 0 ); Ogre::Bone* root2 = skeleton->createBone( "1", 1 ); root1->addChild( root2 ); for( int i = 0; i < number_of_bones; ++i ) { Bone bone; bone.parent_id = ( i != 0 ) ? ( s8 )GetU8( offset_to_bones + i * 0x04 + 0x03 ) : -1; bone.length = ( s16 )GetU16LE( offset_to_bones + i * 0x04 + 0x00 ); m_Skeleton.push_back(bone); Ogre::Bone* bone1 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 2 ), i * 2 + 2 ); Ogre::Bone* bone2 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 3 ), i * 2 + 3 ); LOGGER->Log( "Add skeleton bone: bone_id = " + Ogre::StringConverter::toString( i ) + ", length = " + Ogre::StringConverter::toString( bone.length ) + ", parent = " + Ogre::StringConverter::toString( bone.parent_id ) + ".\n" ); if( bone.parent_id == -1 ) { skeleton->getBone( 1 )->addChild( bone1 ); } else { skeleton->getBone( bone.parent_id * 2 + 3 )->addChild( bone1 ); } bone1->addChild( bone2 ); } AnimationExtractor( skeleton, info, m_Skeleton ); // draw skeleton { //DrawSkeleton( m_Skeleton, mesh ); } for( int i = 0; i < number_of_parts; ++i ) { MeshExtractor( info.data, "ffix/field_model/" + info.data.name, this, offset_to_parts + i * 0x28, textures, mesh ); } // <OGRE> /////////////////////////////// skeleton->optimiseAllAnimations(); Ogre::SkeletonSerializer skeleton_serializer; skeleton_serializer.exportSkeleton( skeleton.getPointer(), "exported/models/field/units/" + info.data.name + ".skeleton" ); // Update bounds Ogre::AxisAlignedBox aabb( -999, -999, -999, 999, 999, 999 ); mesh->_setBounds( aabb, false ); mesh->_setBoundingSphereRadius( 999 ); mesh->setSkeletonName( "models/field/units/" + info.data.name + ".skeleton" ); Ogre::MeshSerializer ser; ser.exportMesh( mesh.getPointer(), "exported/models/field/units/" + info.data.name + ".mesh" ); // create and export textures for model //if (textures.size() > 0) { Vram* vram = new Vram(); File* tex = new File( "./data/field/5/1b/2/4/1.tim" ); LoadTimFileToVram( tex, 0, vram ); delete tex; tex = new File( "./data/field/5/1b/2/4/2.tim" ); LoadTimFileToVram( tex, 0, vram ); delete tex; vram->Save( "1.jpg" ); CreateTexture( vram, info.data, "exported/models/field/units/" + info.data.name + ".png", textures ); delete vram; } CreateMaterial( "ffix/field_model/" + info.data.name, "exported/models/field/units/" + info.data.name + ".material", ( textures.size() > 0 ) ? "models/field/units/" + info.data.name + ".png" : "", "", "" ); Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" ); Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/field/units/" + info.data.name + ".mesh" ); //thisEntity->setDisplaySkeleton(true); //thisEntity->setDebugDisplayEnabled(true); thisEntity->setVisible( false ); thisEntity->getAnimationState( info.animations_name[ 0 ] )->setEnabled(true); thisEntity->getAnimationState( info.animations_name[ 0 ] )->setLoop(true); Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode(); thisSceneNode->setPosition( 0, 0, 0 ); thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) ); thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) ); thisSceneNode->pitch( Ogre::Radian( Ogre::Degree(90.0f ) ) ); thisSceneNode->attachObject( thisEntity ); return thisEntity; }
//------------------------------------------------------------------------------------- void TutorialApplication::createScene(void) { // Set the scene's ambient light mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f)); // Create an Entity Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); // Create a SceneNode and attach the Entity to it Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode"); headNode->attachObject(ogreHead); headNode->setPosition(0, 25, 0); headNode->roll(Ogre::Radian(0.5)); Ogre::ManualObject* myManualObject = mSceneMgr->createManualObject("manual1"); Ogre::ManualObject* myManualObject2 = mSceneMgr->createManualObject("manual2"); Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual1_node"); Ogre::SceneNode* myManualObjectNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual2_node"); // NOTE: The second parameter to the create method is the resource group the material will be added to. // If the group you name does not exist (in your resources.cfg file) the library will assert() and your program will crash Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("blueMaterial","General"); myManualObjectMaterial->setReceiveShadows(false); myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0); myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1); myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("greenMaterial","General"); myManualObjectMaterial->setReceiveShadows(false); myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,1,0,0); myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,1,0); myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,1,0); myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("redMaterial","General"); myManualObjectMaterial->setReceiveShadows(false); myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(1,0,0,0); myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(1,0,0); myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0); myManualObject->begin("blueMaterial", Ogre::RenderOperation::OT_LINE_LIST); myManualObject->position(0, 0, 0); myManualObject->position(50, 0, 0); myManualObject->end(); myManualObject->begin("greenMaterial", Ogre::RenderOperation::OT_LINE_LIST); myManualObject->position(0, 0, 0); myManualObject->position(0, 70, 0); myManualObject->end(); myManualObject->begin("redMaterial", Ogre::RenderOperation::OT_LINE_LIST); myManualObject->position(0, 0, 0); myManualObject->position(0, 0, 50); myManualObject->end(); myManualObjectNode->attachObject(myManualObject); myManualObject2->begin("blueMaterial", Ogre::RenderOperation::OT_LINE_LIST); myManualObject2->position(0, 0, 0); myManualObject2->position(50, 0, 0); myManualObject2->end(); myManualObject2->begin("greenMaterial", Ogre::RenderOperation::OT_LINE_LIST); myManualObject2->position(0, 0, 0); myManualObject2->position(0, 70, 0); myManualObject2->end(); myManualObject2->begin("redMaterial", Ogre::RenderOperation::OT_LINE_LIST); myManualObject2->position(0, 0, 0); myManualObject2->position(0, 0, 50); myManualObject2->end(); myManualObjectNode2->attachObject(myManualObject2); myManualObjectNode2->roll(Ogre::Radian(0.5)); // Create a Light and set its position Ogre::Light* light = mSceneMgr->createLight("MainLight"); light->setPosition(20.0f, 80.0f, 50.0f); }
void CViewManagerView::On3dViews() { int ViewIndex = CMFCRibbonGallery::GetLastSelectedItem(ID_3DVIEWS); CEngine *Engine = ((CViewManagerApp*)AfxGetApp())->m_Engine; Ogre::Root *Root = Engine->GetRoot(); m_SceneManager->_updateSceneGraph(m_Camera); Ogre::SceneNode *CubeNode = m_SceneManager->getSceneNode("Cube"); Ogre::AxisAlignedBox Box = m_SceneManager->getRootSceneNode()->_getWorldAABB(); Ogre::Vector3 Center = Box.getCenter(); Ogre::Vector3 Position; Ogre::Vector3 Destination; switch (ViewIndex) { case 0: //top Position = Center; Position.y += 4.0 * Box.getSize().y; Destination = Center; break; case 1://bottom Position = Center; Position.y -= 4.0 * Box.getSize().y; Destination = Center; break; case 2: Position = Center; Position.x += 4.0 * Box.getSize().x; Destination = Center; break; case 3: Position = Center; Position.x -= 4.0 * Box.getSize().x; Destination = Center; break; case 4: Position = Center; Position.z -= 4.0 * Box.getSize().z; Destination = Center; break; case 5: Position = Center; Position.z += 4.0 * Box.getSize().z; Destination = Center; break; case 9: CubeNode->roll(Ogre::Radian(-atan(sin(Ogre::Math::PI/4.0)))); CubeNode->yaw(Ogre::Radian(Ogre::Math::PI/4.0)); Destination = Center; Position = m_Camera->getPosition(); break; } m_Camera->setPosition(Position); m_Camera->lookAt(Destination); Root->renderOneFrame(); }
void CameraApp::createScene() { /***************************************************************************/ /* This create a scene with a textured plane and a penguin. The camera */ /* is placed directly behind the penguin. Both the camera and the penguin */ /* are attached to the same scene node. As a result, when the node is */ /* moved or rotated, the camera and the penguin move or rotate exactly the */ /* same. This gives you a first person camera that is always looking over */ /* the shoulder of your character. */ /***************************************************************************/ sceneMgr->setAmbientLight( Ogre::ColourValue( 1, 1, 1 ) ); Ogre::Light *l = sceneMgr->createLight("MainLight"); Ogre::Camera *camera = sceneMgr->createCamera("MainCam"); camNode = sceneMgr->getRootSceneNode()->createChildSceneNode( "CameraNode" ); camNode->attachObject(camera); camera->setPosition(0.0, 0.0, 0.0); int originX = -15; int distancebetween = 10; for (int i = 0; i < 4; i++) { Ogre::Entity *sinbadEntity = sceneMgr->createEntity("Sinbad" + i, "Sinbad.mesh"); Ogre::SceneNode *sinbadNode = sceneMgr->getRootSceneNode()->createChildSceneNode("SinbadNode" + i); sinbadNode->attachObject(sinbadEntity); sinbadNode->setScale(1,1,1); sinbadNode->translate(originX + (distancebetween * i), 0, -40); switch (i) { case 1: sinbadNode->yaw(Ogre::Degree(90.0f)); break; case 2: sinbadNode->pitch(Ogre::Degree(90.0f)); break; case 3: sinbadNode->roll(Ogre::Degree(90.0f)); break; } } Ogre::Entity *sinbadEntity = sceneMgr->createEntity("SinbadScaled", "Sinbad.mesh"); Ogre::SceneNode *sinbadNode = sceneMgr->getRootSceneNode()->createChildSceneNode("SinbadScaledNode"); sinbadNode->attachObject(sinbadEntity); sinbadNode->setScale(5,5,5); //sinbadNode->rotate(Ogre::Vector3(1,0,0), Ogre::Degree(90)); //sinbadNode->rotate(Ogre::Vector3(0,0,1), Ogre::Degree(-90)); sinbadNode->translate(0, 0, -60); Ogre::Viewport *vp = window->addViewport(camera); vp->setDimensions(0.0f, 0.0f, 1.0f, 1.0f); camera->setAspectRatio((float)vp->getActualWidth() / (float) vp->getActualHeight()); camera->setFarClipDistance(1000.0f); camera->setNearClipDistance(5.0f); camera->lookAt(0,0,-10); setActiveCamera(camera); /*Ogre::Plane plane(Ogre::Vector3::UNIT_Y, -10); Ogre::MeshManager::getSingleton().createPlane("plane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity *planeEntity = sceneMgr->createEntity("PlaneEntity", "plane"); sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEntity); planeEntity->setMaterialName("Examples/BeachStones");*/ }
void createScene() { Ogre::SceneNode* nroca = mSceneMgr->createSceneNode("nroca"); Ogre::Entity *roca = mSceneMgr->createEntity("roca", "cube.mesh"); nroca->attachObject(roca); mSceneMgr->getRootSceneNode()->addChild(nroca); Ogre::SceneNode* ntronco = mSceneMgr->createSceneNode("ntronco"); Ogre::Entity *tronco = mSceneMgr->createEntity("tronco", "cube.mesh"); ntronco->attachObject(tronco); mSceneMgr->getRootSceneNode()->addChild(ntronco); Ogre::SceneNode* ncabeza = mSceneMgr->createSceneNode("ncabeza"); Ogre::Entity *cabeza = mSceneMgr->createEntity("cabeza", "cube.mesh"); ncabeza->attachObject(cabeza); ntronco->addChild(ncabeza); Ogre::SceneNode* nbase = mSceneMgr->createSceneNode("nbase"); Ogre::Entity *base = mSceneMgr->createEntity("base", "cube.mesh"); nbase->attachObject(base); ncabeza->addChild(nbase); Ogre::SceneNode* nsombrero = mSceneMgr->createSceneNode("nsombrero"); Ogre::Entity *sombrero = mSceneMgr->createEntity("sombrero", "cube.mesh"); nsombrero->attachObject(sombrero); nbase->addChild(nsombrero); Ogre::SceneNode* nbrazoizq = mSceneMgr->createSceneNode("nbrazoizq"); Ogre::Entity *brazoizq = mSceneMgr->createEntity("brazoizq", "cube.mesh"); nbrazoizq->attachObject(brazoizq); ntronco->addChild(nbrazoizq); Ogre::SceneNode* nbrazoder = mSceneMgr->createSceneNode("nbrazoder"); Ogre::Entity *brazoder = mSceneMgr->createEntity("brazoder", "cube.mesh"); nbrazoder->attachObject(brazoder); ntronco->addChild(nbrazoder); Ogre::SceneNode* npiernaizq = mSceneMgr->createSceneNode("npiernaizq"); Ogre::Entity *piernaizq = mSceneMgr->createEntity("piernaizq", "cube.mesh"); npiernaizq->attachObject(piernaizq); ntronco->addChild(npiernaizq); Ogre::SceneNode* npiernader = mSceneMgr->createSceneNode("npiernader"); Ogre::Entity *piernader = mSceneMgr->createEntity("piernader", "cube.mesh"); npiernader->attachObject(piernader); ntronco->addChild(npiernader); Ogre::SceneNode* npieder = mSceneMgr->createSceneNode("npieder"); Ogre::Entity *pieder = mSceneMgr->createEntity("pieder", "cube.mesh"); npieder->attachObject(pieder); npiernader->addChild(npieder); nroca->setPosition(0,7,0); nroca->setScale(7,7,7); nroca->pitch(Degree(30)); nroca->roll(Degree(-45)); ntronco->setPosition(-20,4,0); ntronco->setScale(1,3,1); ntronco->roll(Degree(17)); ncabeza->setPosition(0.25,1.35,0); ncabeza->setScale(1,0.33,1); ncabeza->roll(Degree(-10)); nbase->setPosition(0.25,2,0); nbase->setScale(1,0.15,1); nbase->roll(Degree(-30)); nsombrero->setPosition(0,2.5,0); nsombrero->setScale(0.5,3.5,0.5); nbrazoder->setScale(0.5,1,0.5); nbrazoder->setPosition(-2,0.65,-2.25); nbrazoder->roll(Degree(90)); nbrazoder->pitch(Degree(-30)); nbrazoizq->setScale(0.5,1,0.5); nbrazoizq->setPosition(-2,0.65,2.25); nbrazoizq->roll(Degree(100)); nbrazoizq->pitch(Degree(30)); npiernaizq->setPosition(-1.75,-1.75,-0.25); npiernaizq->setScale(0.5,1,0.5); npiernaizq->roll(Degree(-45)); npiernader->setPosition(1,-1.35,0.5); npiernader->setScale(0.5,0.5,0.5); npiernader->roll(Degree(35)); npieder->setPosition(2.25,-1.25,1.75); npieder->roll(Degree(90)); Ogre::Plane pl1(Ogre::Vector3::UNIT_Y, -5); Ogre::MeshManager::getSingleton().createPlane("pl1",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,pl1,200,200,1,1,true,1,20,20,Ogre::Vector3::UNIT_Z); Ogre::SceneNode* nground = mSceneMgr->createSceneNode("ground"); Ogre::Entity *ground = mSceneMgr->createEntity("pEnt","pl1"); ground->setMaterialName("Ground"); nground->attachObject(ground); mSceneMgr->getRootSceneNode()->addChild(nground); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); }
int OgreOculus::go(void) { // Create Root object root = new Ogre::Root("plugin.cfg", "ogre.cfg"); // OpenGL root->loadPlugin("RenderSystem_GL_d"); root->setRenderSystem(root->getRenderSystemByName("OpenGL Rendering Subsystem")); // Initialize Root root->initialise(false); // Initialize Oculus ovrHmd hmd; ovrHmdDesc hmdDesc; ovrGraphicsLuid luid; ovr_Initialize(nullptr); if(ovr_Create(&hmd, &luid) != ovrSuccess) exit(-1); hmdDesc = ovr_GetHmdDesc(hmd); if(ovr_ConfigureTracking(hmd, ovrTrackingCap_Orientation |ovrTrackingCap_MagYawCorrection |ovrTrackingCap_Position, 0) != ovrSuccess) exit(-2); // Turn off HUD ovr_SetInt(hmd, "PerfHudMode", ovrPerfHud_Off); // Create a window window = root->createRenderWindow("Ogre + Oculus = <3", hmdDesc.Resolution.w/2, hmdDesc.Resolution.h/2, false); // Create scene manager and cameras smgr = root->createSceneManager(Ogre::ST_GENERIC); // Load Ogre resource paths from config file Ogre::ConfigFile cf; cf.load("resources_d.cfg"); // Go through all sections & settings in the file and add resources Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } // Set resources Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Create the model itself via OgreModel.cpp createOgreModel(smgr); // Create camera createCamera(); // Set viewport and background color Ogre::Viewport* vp = window->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(34, 89, 0)); // Yellow // Set aspect ratio mCamera->setAspectRatio( Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); // Initialize glew if(glewInit() != GLEW_OK) exit(-3); // Get texture sizes ovrSizei texSizeL, texSizeR; texSizeL = ovr_GetFovTextureSize(hmd, ovrEye_Left, hmdDesc.DefaultEyeFov[left], 1); texSizeR = ovr_GetFovTextureSize(hmd, ovrEye_Right, hmdDesc.DefaultEyeFov[right], 1); // Calculate render buffer size ovrSizei bufferSize; bufferSize.w = texSizeL.w + texSizeR.w; bufferSize.h = max(texSizeL.h, texSizeR.h); // Create render texture set ovrSwapTextureSet* textureSet; if(ovr_CreateSwapTextureSetGL(hmd, GL_RGB, bufferSize.w, bufferSize.h, &textureSet) != ovrSuccess) exit(-4); // Create Ogre render texture Ogre::GLTextureManager* textureManager = static_cast<Ogre::GLTextureManager*>(Ogre::GLTextureManager::getSingletonPtr()); Ogre::TexturePtr rtt_texture(textureManager->createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, bufferSize.w, bufferSize.h, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET)); Ogre::RenderTexture* rttEyes = rtt_texture->getBuffer(0, 0)->getRenderTarget(); Ogre::GLTexture* gltex = static_cast<Ogre::GLTexture*>(Ogre::GLTextureManager::getSingleton().getByName("RttTex").getPointer()); GLuint renderTextureID = gltex->getGLID(); // Put camera viewport on the ogre render texture Ogre::Viewport* vpts[nbEyes]; vpts[left]=rttEyes->addViewport(cams[left], 0, 0, 0, 0.5f); vpts[right]=rttEyes->addViewport(cams[right], 1, 0.5f, 0, 0.5f); vpts[left]->setBackgroundColour(Ogre::ColourValue(34, 89, 0)); // Black background vpts[right]->setBackgroundColour(Ogre::ColourValue(34, 89, 0)); ovrTexture* mirrorTexture; if(ovr_CreateMirrorTextureGL(hmd, GL_RGB, hmdDesc.Resolution.w, hmdDesc.Resolution.h, &mirrorTexture) != ovrSuccess) exit(-5); Ogre::TexturePtr mirror_texture(textureManager->createManual("MirrorTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, hmdDesc.Resolution.w, hmdDesc.Resolution.h, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET)); // Get GLIDs GLuint ogreMirrorTextureID = static_cast<Ogre::GLTexture*>(Ogre::GLTextureManager::getSingleton().getByName("MirrorTex").getPointer())->getGLID(); GLuint oculusMirrorTextureID = ((ovrGLTexture*)mirrorTexture)->OGL.TexId; // Create EyeRenderDesc ovrEyeRenderDesc EyeRenderDesc[nbEyes]; EyeRenderDesc[left] = ovr_GetRenderDesc(hmd, ovrEye_Left, hmdDesc.DefaultEyeFov[left]); EyeRenderDesc[right] = ovr_GetRenderDesc(hmd, ovrEye_Right, hmdDesc.DefaultEyeFov[right]); // Get offsets ovrVector3f offset[nbEyes]; offset[left]=EyeRenderDesc[left].HmdToEyeViewOffset; offset[right]=EyeRenderDesc[right].HmdToEyeViewOffset; // Compositor layer ovrLayerEyeFov layer; layer.Header.Type = ovrLayerType_EyeFov; layer.Header.Flags = 0; layer.ColorTexture[left] = textureSet; layer.ColorTexture[right] = textureSet; layer.Fov[left] = EyeRenderDesc[left].Fov; layer.Fov[right] = EyeRenderDesc[right].Fov; layer.Viewport[left] = OVR::Recti(0, 0, bufferSize.w/2, bufferSize.h); layer.Viewport[right] = OVR::Recti(bufferSize.w/2, 0, bufferSize.w/2, bufferSize.h); // Get projection matrices for(size_t eyeIndex(0); eyeIndex < ovrEye_Count; eyeIndex++) { // Get the projection matrix OVR::Matrix4f proj = ovrMatrix4f_Projection(EyeRenderDesc[eyeIndex].Fov, static_cast<float>(0.01f), 4000, true); // Convert it to Ogre matrix Ogre::Matrix4 OgreProj; for(size_t x(0); x < 4; x++) for(size_t y(0); y < 4; y++) OgreProj[x][y] = proj.M[x][y]; // Set the matrix cams[eyeIndex]->setCustomProjectionMatrix(true, OgreProj); } // Variables for render loop bool render(true); ovrFrameTiming hmdFrameTiming; ovrTrackingState ts; OVR::Posef pose; ovrLayerHeader* layers; // Create event listener for handling user input createEventListener(); //Run physics loop in a new thread std::map<Ogre::Entity*, Ogre::Vector3> positionRequests; std::map<Ogre::Entity*, std::string> animationRequests; std::map<Ogre::Entity*, std::vector<int>> rotationRequests; std::map<std::string, std::string> message; std::thread physicsThread(physicsLoop, smgr, &message, &positionRequests, &animationRequests, &rotationRequests); // Render loop while(render) { // Suspend physics loop and perform requested movement/rotations/animations if(positionRequests.size() > 0 || animationRequests.size() > 0 || rotationRequests.size() > 0){ message.insert(std::pair<std::string, std::string>("", "")); for(auto const &request : positionRequests) { Ogre::Vector3 pos = request.second; Ogre::SceneNode* sceneNode = request.first->getParentSceneNode(); sceneNode->setPosition(pos); } for(auto const &request : animationRequests) { request.first->getAnimationState(request.second)->addTime(0.1); } for(auto const &request : rotationRequests) { Ogre::SceneNode* sceneNode = request.first->getParentSceneNode(); sceneNode->roll(Ogre::Degree(request.second[0])); sceneNode->pitch(Ogre::Degree(request.second[1])); sceneNode->yaw(Ogre::Degree(request.second[2])); } positionRequests.clear(); animationRequests.clear(); rotationRequests.clear(); // Resume physics loop message.clear(); } // Update Ogre window Ogre::WindowEventUtilities::messagePump(); // Advance textureset index textureSet->CurrentIndex = (textureSet->CurrentIndex + 1) % textureSet->TextureCount; // Capture user input mKeyboard->capture(); mMouse->capture(); // Movement calculations mPlayerNode->translate(mDirection, Ogre::Node::TS_LOCAL); hmdFrameTiming = ovr_GetFrameTiming(hmd, 0); ts = ovr_GetTrackingState(hmd, hmdFrameTiming.DisplayMidpointSeconds); pose = ts.HeadPose.ThePose; ovr_CalcEyePoses(pose, offset, layer.RenderPose); oculusOrient = pose.Rotation; oculusPos = pose.Translation; mHeadNode->setOrientation(Ogre::Quaternion(oculusOrient.w, oculusOrient.x, oculusOrient.y, oculusOrient.z) * initialOculusOrientation.Inverse()); // Apply head tracking mHeadNode->setPosition(headPositionTrackingSensitivity * Ogre::Vector3(oculusPos.x, oculusPos.y,oculusPos.z)); // Update Ogre viewports root->_fireFrameRenderingQueued(); vpts[left]->update(); vpts[right]->update(); // Copy the rendered image to the Oculus Swap Texture glCopyImageSubData(renderTextureID, GL_TEXTURE_2D, 0, 0, 0, 0, ((ovrGLTexture*)(&textureSet->Textures[textureSet->CurrentIndex]))->OGL.TexId, GL_TEXTURE_2D, 0, 0, 0, 0, bufferSize.w,bufferSize.h, 1); layers = &layer.Header; // Submit new frame to the Oculus and update window ovr_SubmitFrame(hmd, 0, nullptr, &layers, 1); window->update(); // Exit loop when window is closed if(window->isClosed()) render = false; } // Shud down Oculus ovr_Destroy(hmd); ovr_Shutdown(); // Delete Ogre root and return delete root; return EXIT_SUCCESS; }
Ogre::Entity* StageFile::GetModel( const StageInfo& info ) { //DumpSettings("exported/" + info.data.name + ".lua"); VectorTexForGen textures; Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create(info.data.name + "export", "General"); Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create(info.data.name + "export", "General"); u32 number_of_files = GetU32LE(0); LOGGER->Log("Number of file " + IntToString(number_of_files) + "\n"); Ogre::Bone* root1 = skeleton->createBone( "0", 0 ); Ogre::Bone* root2 = skeleton->createBone( "1", 1 ); root1->addChild( root2 ); Ogre::Animation* anim = skeleton->createAnimation( "Idle", 1 ); Ogre::NodeAnimationTrack* track1 = anim->createNodeTrack( 0, root1 ); track1->removeAllKeyFrames(); Ogre::TransformKeyFrame* frame1 = track1->createNodeKeyFrame( 0 ); Ogre::Matrix3 matrix; matrix.FromEulerAnglesYXZ( Ogre::Radian( Ogre::Degree( 0 ) ), Ogre::Radian( Ogre::Degree( -90 ) ), Ogre::Radian( Ogre::Degree( 0 ) ) ); Ogre::Quaternion rot; rot.FromRotationMatrix( matrix ); frame1->setRotation( rot ); for (u32 i = 1; i < number_of_files - 1; ++i) { int offset_to_vertex = GetU32LE(0x04 + i * 0x04); MeshExtractor(info.data, "ffvii/battle_stage/" + info.data.name, this, offset_to_vertex, textures, mesh, Ogre::StringConverter::toString(i), 1); } // <OGRE> /////////////////////////////// skeleton->optimiseAllAnimations(); Ogre::SkeletonSerializer skeleton_serializer; skeleton_serializer.exportSkeleton(skeleton.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".skeleton"); // Update bounds Ogre::AxisAlignedBox aabb(-999, -999, -999, 999, 999, 999); mesh->_setBounds(aabb, false); mesh->_setBoundingSphereRadius(999); mesh->setSkeletonName( "models/ffvii/battle/stages/" + info.data.name + ".skeleton" ); Ogre::MeshSerializer ser; ser.exportMesh(mesh.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".mesh"); // create and export textures for model if( textures.size() > 0 ) { int number_of_files = GetU32LE( 0x00 ); int offset_to_texture = GetU32LE( number_of_files * 0x04 ); Vram* vram = Vram::MakeInstance().release(); LoadTimFileToVram( this, offset_to_texture, vram ); //vram->Save( "qqq" ); CreateTexture( vram, info.data, "exported/models/ffvii/battle/stages/" + info.data.name + ".png", textures ); delete vram; } CreateMaterial("ffvii/battle_stage/" + info.data.name, "exported/models/ffvii/battle/stages/" + info.data.name + ".material", "models/ffvii/battle/stages/" + info.data.name + ".png", "", ""); Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" ); Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/ffvii/battle/stages/" + info.data.name + ".mesh" ); //thisEntity->setDisplaySkeleton(true); //thisEntity->setDebugDisplayEnabled(true); thisEntity->setVisible(false); thisEntity->getAnimationState( "Idle" )->setEnabled( true ); thisEntity->getAnimationState( "Idle" )->setLoop( true ); Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode(); thisSceneNode->setPosition( 0, 0, 0 ); thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) ); thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) ); thisSceneNode->pitch( Ogre::Radian( Ogre::Degree( 90.0f ) ) ); thisSceneNode->attachObject( thisEntity ); return thisEntity; }