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 TestGame::DrawNewCore(Logic::CoreBuiltEvnt *evnt){ Ogre::Entity* drop= mSceneMgr->createEntity("Mesh"+evnt->building->mSysName, "BaseDropNew.mesh"); drop->setCastShadows(true); const Ogre::AxisAlignedBox test =drop->getBoundingBox(); Control::ClickHelper* helpr = new Control::ClickHelper(Logic::CHT_BUILDING); helpr->target = evnt->building; drop->setUserAny(Ogre::Any(helpr)); Ogre::SceneNode *coreNode = evnt->country->mNode->createChildSceneNode(); Ogre::Vector3 tempvect = calculateActualPointFromCenter(evnt->country->mCapital.mPosition,evnt->tile->mPosition); tempvect= tempvect*TILESIZE; coreNode->attachObject(drop); coreNode->translate(tempvect); coreNode->pitch(Ogre::Degree(90)); coreNode->scale(0.5,0.5,0.5); Ogre::AnimationState* temp= drop->getAnimationState("drop"); temp->setLoop(false); temp->setEnabled(true); mAllAnimation .insert(temp); Ogre::Entity* basePlane= mSceneMgr->createEntity("MeshBaseFloor"+evnt->building->mSysName, "BaseCloseLook.mesh"); basePlane->setMaterialName("BaseCloseLook/Rockwall"); Ogre::SceneNode *BaseDraw = evnt->country->mNode->createChildSceneNode(),*camspot; BaseDraw->attachObject(basePlane); BaseDraw->translate(2000*evnt->building->mSlot,0,0); camspot = BaseDraw->createChildSceneNode("CamPoint_"+evnt->building->mSysName); camspot->setPosition(0,45,45); camspot->lookAt(Ogre::Vector3(0,0,0), Ogre::Node::TS_PARENT); helpr = new Control::ClickHelper(Logic::CHT_EMPTYSPACE); helpr->target = evnt->building; basePlane->setUserAny(Ogre::Any(helpr)); }
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 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 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 CharacterPreview::setup () { mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC); // This is a dummy light to turn off shadows without having to use a separate set of shaders Ogre::Light* l = mSceneMgr->createLight(); l->setType (Ogre::Light::LT_DIRECTIONAL); l->setDiffuseColour (Ogre::ColourValue(0,0,0)); /// \todo Read the fallback values from INIImporter (Inventory:Directional*) l = mSceneMgr->createLight(); l->setType (Ogre::Light::LT_DIRECTIONAL); l->setDirection (Ogre::Vector3(0.3, -0.7, 0.3)); l->setDiffuseColour (Ogre::ColourValue(1,1,1)); mSceneMgr->setAmbientLight (Ogre::ColourValue(0.5, 0.5, 0.5)); mCamera = mSceneMgr->createCamera (mName); mCamera->setAspectRatio (float(mSizeX) / float(mSizeY)); Ogre::SceneNode* renderRoot = mSceneMgr->getRootSceneNode()->createChildSceneNode("renderRoot"); //we do this with mwRoot in renderingManager, do it here too. renderRoot->pitch(Ogre::Degree(-90)); mNode = renderRoot->createChildSceneNode(); mAnimation = new NpcAnimation(mCharacter, mNode, 0, true, (renderHeadOnly() ? NpcAnimation::VM_HeadOnly : NpcAnimation::VM_Normal)); Ogre::Vector3 scale = mNode->getScale(); mCamera->setPosition(mPosition * scale); mCamera->lookAt(mLookAt * scale); mCamera->setNearClipDistance (0.01); mCamera->setFarClipDistance (1000); mTexture = Ogre::TextureManager::getSingleton().getByName (mName); if (mTexture.isNull ()) mTexture = Ogre::TextureManager::getSingleton().createManual(mName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET); mRenderTarget = mTexture->getBuffer()->getRenderTarget(); mRenderTarget->removeAllViewports (); mViewport = mRenderTarget->addViewport(mCamera); mViewport->setOverlaysEnabled(false); mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0)); mViewport->setShadowsEnabled(false); mRenderTarget->setActive(true); mRenderTarget->setAutoUpdated (false); onSetup (); }
void // Load other propers or objects (e.g. furniture) GameApplication::loadObjects() { using namespace Ogre; Ogre::Entity *ent; Ogre::SceneNode *node; ///////////////////////////////////////////////////////////////////////////////////////////////////// // Lecture 7 ent = mSceneMgr->createEntity("Gun", "38pistol.mesh"); node = mSceneMgr->getRootSceneNode()->createChildSceneNode("GunNode", Ogre::Vector3(5.0f, 1.4f, 5.0f)); node->attachObject(ent); node->pitch(Degree(90)); node->setScale(0.1f, 0.1f, 0.1); ent = mSceneMgr->createEntity("Gun2", "9mm.mesh"); node = mSceneMgr->getRootSceneNode()->createChildSceneNode("GunNode2", Ogre::Vector3(5.0f, 1.4f, 5.0f)); node->attachObject(ent); node->pitch(Degree(90)); node->setScale(0.1f, 0.1f, 0.1); /////////////////////////////////////////////////////////////////////////////////////////////////// }
void PhysicEngine::createDebugRendering() { if(!isDebugCreated) { Ogre::SceneManagerEnumerator::SceneManagerIterator iter = Ogre::Root::getSingleton().getSceneManagerIterator(); iter.begin(); Ogre::SceneManager* scn = iter.getNext(); Ogre::SceneNode* node = scn->getRootSceneNode()->createChildSceneNode(); node->pitch(Ogre::Degree(-90)); mDebugDrawer = new BtOgre::DebugDrawer(node, dynamicsWorld); dynamicsWorld->setDebugDrawer(mDebugDrawer); isDebugCreated = true; dynamicsWorld->debugDrawWorld(); } }
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; }
void Laser::Initialize(Ogre::SceneManager *sceneManager, Ogre::SceneNode* parentNode, PhysicsEngine &physicsEngine, unsigned int parentID) { PhysicsEntity::Initialize(sceneManager, parentNode, physicsEngine, parentID); //setting our mass to 0 bodyType = ENTITY_BODY_METAPHYSICAL; dynamic = false; mass = 0.0f; Ogre::Entity *laserEntity = sceneManager->createEntity("Cylinder"); laserEntity->setMaterialName("LaserMaterial"); Ogre::SceneNode *laserSceneNode = sceneNode->createChildSceneNode("Laser" + Ogre::StringConverter::toString(entityCount)); laserSceneNode->attachObject(laserEntity); laserSceneNode->scale(0.3f, 1000.0f, 0.3f); laserSceneNode->pitch(Ogre::Radian(-Ogre::Math::HALF_PI)); laserSceneNode->translate(0,0,-500.0f); sceneNode->setVisible(false); }
void CharacterPreview::setup () { mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC); mCamera = mSceneMgr->createCamera (mName); mCamera->setAspectRatio (float(mSizeX) / float(mSizeY)); Ogre::SceneNode* renderRoot = mSceneMgr->getRootSceneNode()->createChildSceneNode("renderRoot"); //we do this with mwRoot in renderingManager, do it here too. renderRoot->pitch(Ogre::Degree(-90)); mNode = renderRoot->createChildSceneNode(); mAnimation = new NpcAnimation(mCharacter, mNode, MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview); mNode->setVisible (false); Ogre::Vector3 scale = mNode->getScale(); mCamera->setPosition(mPosition * scale); mCamera->lookAt(mLookAt * scale); mCamera->setNearClipDistance (0.01); mCamera->setFarClipDistance (1000); mTexture = Ogre::TextureManager::getSingleton().getByName (mName); if (mTexture.isNull ()) mTexture = Ogre::TextureManager::getSingleton().createManual(mName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET); mRenderTarget = mTexture->getBuffer()->getRenderTarget(); mRenderTarget->removeAllViewports (); mViewport = mRenderTarget->addViewport(mCamera); mViewport->setOverlaysEnabled(false); mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0)); mViewport->setShadowsEnabled(false); mViewport->setMaterialScheme("local_map"); mViewport->setVisibilityMask (RV_PlayerPreview); mRenderTarget->setActive(true); mRenderTarget->setAutoUpdated (false); onSetup (); }
void createScene() { // Create the Entity Ogre::Entity* robot = mSceneMgr->createEntity("Robot", "robot.mesh"); // Attach robot to scene graph Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Robot"); //RobotNode->setPosition((Ogre::Real)-0.3, (Ogre::Real)0.2, (Ogre::Real)0); RobotNode->attachObject(robot); RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001); RobotNode->pitch(Ogre::Degree(180)); RobotNode->yaw(Ogre::Degree(-90)); // The animation // Set the good animation mAnimationState = robot->getAnimationState( "Idle" ); // Start over when finished mAnimationState->setLoop( true ); // Animation enabled mAnimationState->setEnabled( true ); }
RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine, MWWorld::Environment& environment) :mRendering(_rend), mObjects(mRendering), mActors(mRendering, environment), mAmbientMode(0), mDebugging(engine) { mRendering.createScene("PlayerCam", 55, 5); // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); // Load resources ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Turn the entire scene (represented by the 'root' node) -90 // degrees around the x axis. This makes Z go upwards, and Y go into // the screen (when x is to the right.) This is the orientation that // Morrowind uses, and it automagically makes everything work as it // should. SceneNode *rt = mRendering.getScene()->getRootSceneNode(); mMwRoot = rt->createChildSceneNode(); mMwRoot->pitch(Degree(-90)); mObjects.setMwRoot(mMwRoot); mActors.setMwRoot(mMwRoot); //used to obtain ingame information of ogre objects (which are faced or selected) mRaySceneQuery = mRendering.getScene()->createRayQuery(Ray()); Ogre::SceneNode *playerNode = mMwRoot->createChildSceneNode ("player"); playerNode->pitch(Degree(90)); Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode(); Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode(); cameraPitchNode->attachObject(mRendering.getCamera()); //mSkyManager = 0; mSkyManager = new SkyManager(mMwRoot, mRendering.getCamera()); mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode); mSun = 0; }
//------------------------------------------------------------------------------------- void Cenario::iniciarCenario(){ // Crio um nó filho do nó raiz na hierarquia de cena Cenario::cenarioNode = Bomberman::getInstance()->mSceneMgr->getRootSceneNode()->createChildSceneNode("cenarioNode"); //Posiciona o Nó Cenario::cenarioNode->setPosition( Ogre::Vector3(0,0,0) ); Ogre::Entity* campoEntity = Bomberman::getInstance()->mSceneMgr->createEntity("cenario", "scenario_green.mesh"); Ogre::SceneNode * campo = Bomberman::getInstance()->mSceneMgr->getRootSceneNode()->createChildSceneNode( "campo" ); campo->attachObject(campoEntity); campo->setPosition(6,-0.5f,-7); campo->setScale( 10.0f, 10.0f, 10.0f ); campo->pitch( Ogre::Degree( -90 ) ); Ogre::SceneNode* elementoNode; Ogre::Entity* elementoEntidade; for( int i = 0; i < LINHAS; i++ ){ for( int j = 0; j < COLUNAS; j++){ Ogre::String nomeEntidade, nomeCenarioNode; Square square = Cenario::criarSquare( i, j, &nomeCenarioNode, &nomeEntidade ); switch( Cenario::cenario[i][j] ){ case 'X': elementoNode = Cenario::cenarioNode->createChildSceneNode( nomeCenarioNode ); elementoEntidade = Bomberman::getInstance()->mSceneMgr->createEntity( nomeEntidade, "block_hard.mesh" ); elementoEntidade->setCastShadows(true); elementoNode->setPosition( Ogre::Vector3( i, 0, j * - 1 ) ); elementoNode->attachObject( elementoEntidade ); elementoNode->setScale( 0.5f, 0.5f, 0.5f ); break; case 'B': elementoNode = Cenario::cenarioNode->createChildSceneNode( nomeCenarioNode ); elementoEntidade = Bomberman::getInstance()->mSceneMgr->createEntity( nomeEntidade, "block_normal.mesh" ); elementoEntidade->setCastShadows(true); elementoNode->setPosition( Ogre::Vector3( i, 0, j * - 1 ) ); elementoNode->attachObject( elementoEntidade ); elementoNode->setScale( 0.5f, 0.5f, 0.5f ); break; case 'H': elementoNode = Cenario::cenarioNode->createChildSceneNode( "bomberman_node" ); elementoEntidade = Bomberman::getInstance()->mSceneMgr->createEntity( "bomberman", "bomberman.mesh" ); elementoEntidade->setCastShadows(true); elementoNode->setPosition( Ogre::Vector3( i, 0.5f, j * - 1 ) ); elementoNode->attachObject( elementoEntidade ); elementoNode->setScale( 0.3f, 0.3f, 0.3f ); elementoNode->yaw( Ogre::Degree( 180 ) ); break; } Cenario::cenarioSquare[i][j] = square; } } }
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 CsCameraManager::Update() { static clock_t prevTime = clock(); static Ogre::Vector3 lerpPos; static Ogre::Quaternion slerpRot; static float linLerpStep; static float angLerpStep; clock_t curTime = clock(); float timeStep = (curTime - prevTime) / (float) CLOCKS_PER_SEC; Ogre::SceneNode* camNode = mCameraList[mCurrentCamera].second; // the interpolation ---------------------------------------- // the current camera is not actually used, the default camera is used to approximate // the current camera posA = mDefaultCamNode->_getDerivedPosition(); rotA = mDefaultCamNode->_getDerivedOrientation(); posB = camNode->_getDerivedPosition(); rotB = camNode->_getDerivedOrientation(); linLerpStep = 0.5 * timeStep / 0.12; // reaches half i 0.3 seconds angLerpStep = 0.5 * timeStep / 0.12; // for fast moving targets if (mTargetObject) { float linear = mTargetObject->GetLinearVelocity().length(); float angular = mTargetObject->GetAngularVelocity().length(); if (linear > 200.0f) { linLerpStep += (linear - 150) / 300.0f; angLerpStep += (linear - 150) / 300.0f; } if (angular > 3.0f) { linLerpStep += (angular - 2.0f) / 8.0f; angLerpStep += (angular - 2.0f) / 8.0f; } } if (linLerpStep > 1.0f) linLerpStep = 0.90f; if (angLerpStep > 1.0f) angLerpStep = 0.90f; if (linLerpStep < 0.0f) linLerpStep = 0.1f; if (angLerpStep < 0.0f) angLerpStep = 0.1f; lerpPos = (posB - posA) * linLerpStep + posA; slerpRot = Ogre::Quaternion::Slerp(angLerpStep, rotA, rotB, true); mDefaultCamNode->setPosition(lerpPos); mDefaultCamNode->setOrientation(slerpRot); // ---------------------------------------------------------- if (mCameraType[mCurrentCamera] == Chaos::ORBIT_CAMERA) { Orbit(timeStep); } else if (mCameraType[mCurrentCamera] == Chaos::FREE_CAMERA) { if ( mButtonState[Chaos::ARROW_UP]) camNode->translate(0,0,-timeStep * MOVE_SPEED, Ogre::Node::TS_LOCAL); if ( mButtonState[Chaos::ARROW_DOWN]) camNode->translate(0,0,timeStep * MOVE_SPEED, Ogre::Node::TS_LOCAL); if ( mButtonState[Chaos::ARROW_LEFT]) camNode->translate(-timeStep * MOVE_SPEED,0,0, Ogre::Node::TS_LOCAL); if ( mButtonState[Chaos::ARROW_RIGHT]) camNode->translate(timeStep * MOVE_SPEED,0,0, Ogre::Node::TS_LOCAL); if (xrel) camNode->yaw(Ogre::Radian(Ogre::Degree(-LOOK_SPEED * xrel * timeStep)), Ogre::Node::TS_WORLD); if (yrel) camNode->pitch(Ogre::Radian(Ogre::Degree(-LOOK_SPEED * yrel * timeStep)), Ogre::Node::TS_LOCAL); } xrel = yrel = zrel = 0; prevTime = curTime; }
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; }
//--------------------------------------------------------------------------------------- bool DigitalForensicsVisualisation::visualise(const CEGUI::EventArgs &e) { try { mSceneMgr->getRootSceneNode()->removeAndDestroyChild("FilesNode"); mSceneMgr->destroyAllMovableObjects(); //does not destroy movable texts, they are needed to be destroyed manually mSceneMgr->destroyAllManualObjects(); cubeCount = pyramidCount = cylinderCount = 0; for (unsigned long int i = 0; i < textArrIndex; ++i) { textArr[textArrIndex]->~MovableText(); textArr[textArrIndex] = NULL; } textArrIndex = 0; } catch(std::exception& e) { //do nothing OutputDebugString("DID NOTHING\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nnREALLYDIDNOTHING\nn"); } beginProgress(); const float radius = 1000; const float thickness = radius - 45; try { MYSQL_RES *res_set; /* Create a pointer to recieve the return value.*/ MYSQL_ROW row; /* Assign variable for rows. */ OutputDebugString(buildQuery().c_str()); res_set = mysqlExecute(buildQuery().c_str()); unsigned long long int numrows = mysql_num_rows(res_set); /* Create the count to print all rows */ float distFromCentre = radius - thickness; unsigned long long int itemIndex = 0; char containerName[50]; //for container char fileName[50]; //for fileName char fontName[50]; //for fontName filesNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("FilesNode"); filesNode->setPosition (0, -300, -500); srand(time(NULL)); for (float y = radius - thickness; y <= radius; y += Ogre::Math::PI * 6) { //progress_bar->setProgress(progress_bar->getProgress() + ( 1/ (Ogre::Math::PI / (thickness * thickness)))); for (float theta = 0; theta <= Ogre::Math::PI * 1.8; theta += Ogre::Math::PI / (distFromCentre / 6)) { if ((row = mysql_fetch_row(res_set)) == NULL) goto exit; try { app.e.name = row[0]; app.e.directory = row[1]; app.e.size = std::stoull(row[2]); //for unsigned long long app.e.setExtension(); std::string ext = app.e.extension; for (unsigned int i = 0; i < ext.length(); ++i) { ext[i] = std::toupper(ext[i]); } app.e.extension = ext; app.e.write_permission = std::stoi(row[4]); app.e.access_permission = std::stoi(row[5]); app.e.creation_time = row[6]; app.e.access_time = row[7]; app.e.modification_time = row[8]; app.e.c = std::stoi(row[9]); app.e.a = std::stoi(row[10]); app.e.m = std::stoi(row[11]); } catch(std::exception& e) { OutputDebugString(e.what()); OutputDebugString("SIZEEXCEPTIONNN\nn\n\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\n\nn\nn\nn\nn\nnn\nn\nSIZEEXCEPTIONNN\nn\n"); app.e.creation_time = app.e.modification_time = app.e.access_time = app.e.name = "exception occured"; } sprintf(containerName,"container_%d",itemIndex); sprintf(fontName,"font_%d", itemIndex); sprintf(fileName, "file_%d", itemIndex++); Ogre::SceneNode* container = filesNode->createChildSceneNode(containerName); Ogre::SceneNode* fsn = container->createChildSceneNode(fileName); Ogre::SceneNode* fontNode = container->createChildSceneNode(fontName); Ogre::SceneNode* textureNode; bool isTexture = app.e.isTextureFile(); if (isTexture) { try { char textureName[50]; sprintf(textureName,"texture_%d",itemIndex-1); std::stringstream ss; ss << app.e.directory << "/" << app.e.name; //loads and adds the image to the resources///// Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("MyMaterial2"); Ogre::MaterialPtr matClone = material->clone(textureName); loadImageFile(textureName,ss.str()); matClone->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(textureName); textureNode = container->createChildSceneNode(textureName); textureNode->attachObject(rectangle(textureName)); textureNode->setPosition(y * cos(theta), 0, y * sin(theta)); textureNode->scale(.09,((float) app.e.size / 20000000 + 0.1),.09); } catch(std::exception e) { OutputDebugStringA("\nm\nm\nm\nm\nm\nm\nm\nm"); OutputDebugStringA(e.what()); }; } ColorMap cm(app.e.extension); if (colorTree.search(cm) == NULL) colorTree.insert(cm); else cm = colorTree.search(cm)->data; if ((app.e.write_permission == 1) && (app.e.access_permission == 1)) fsn ->attachObject(cube(true, cm)); else if ((app.e.write_permission == 1) && (app.e.access_permission == 0)) fsn->attachObject(cube(false, cm)); else if ((app.e.write_permission == 0) && (app.e.access_permission == 1)) { fsn -> attachObject(pyramid(cm)); fsn -> scale (1.3, 1.3, 1.3); } else { fsn->attachObject(cylinder(cm)); fsn->pitch((Ogre::Radian) Ogre::Math::PI); if (isTexture) textureNode->scale(.8,1,.8); } std::stringstream ss; ss << "file name: " << app.e.name << "\n\nlast access time: " << app.e.access_time << "\nmodification time: " << app.e.modification_time << "\ncreation time: " << app.e.creation_time; std::string s = ss.str(); textArr[textArrIndex] = new Ogre::MovableText("tayyar", (s)); textArr[textArrIndex] ->setTextAlignment(Ogre::MovableText::H_CENTER, Ogre::MovableText::V_CENTER); // Center horizontally and display above the node textArr[textArrIndex] ->setColor(Ogre::ColourValue(1,1,1,.65)); fontNode->attachObject(textArr[textArrIndex++]); fsn->setPosition(y * cos(theta), 0, y * sin(theta)); fontNode->setPosition(fsn->getPosition().x + 6, fsn->getPosition().y, fsn->getPosition().z + 3.75); fsn->scale(.09,((float) app.e.size / 20000000 + 0.1),.09); OutputDebugString(fileName); OutputDebugString("\n"); } distFromCentre += Ogre::Math::PI * 6; } } catch(std::exception& e) { OutputDebugString(e.what()); OutputDebugString("EXCEPTIONNN\nn\n\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\nn\n\nn\nn\nn\nn\nnn\nn\nEXCEPTIONNN\nn\n"); } exit: endProgress(); return true; }
//----------------------------------------------------------------------------- void SSAOApp::_loadSponzaMesh(const std::string&_meshName) { Ogre::SceneNode *node = _loadMesh(_meshName, Ogre::Vector3::ZERO); node->scale(50, 50, 50); node->pitch(Ogre::Radian(Ogre::Math::PI / 2)); }
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)); }
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; }
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");*/ }