Banderin::Banderin( Ogre::String nombre , Ogre::SceneManager* sm , float _x , float _y , float _z){ x = _x; y = _y; z = _z; _sceneManager = sm; nodoBanderin = _sceneManager->createSceneNode("Banderin"+nombre); Ogre::SceneNode* nodoSuperiorIzq = _sceneManager->createSceneNode(nombre+"superiorIzq"); Ogre::SceneNode* nodoBandera = _sceneManager->createSceneNode(nombre+"bandera"); Ogre::SceneNode* nodoSuperiorDer = _sceneManager->createSceneNode(nombre+"superiorDer"); Ogre::SceneNode* nodoBaseDer = _sceneManager->createSceneNode(nombre+"baseDer"); Ogre::Entity* entBanderin = _sceneManager->createEntity("usb_cilindro.mesh"); Ogre::Entity* entSuperiorIzq = _sceneManager->createEntity("poly10.mesh"); Ogre::Entity* entBandera = _sceneManager->createEntity("usb_planocurvo.mesh"); Ogre::Entity* entSuperiorDer = _sceneManager->createEntity("poly10.mesh"); Ogre::Entity* entBaseDer = _sceneManager->createEntity("usb_cilindro.mesh"); entBanderin->setMaterialName("banderin"); entSuperiorIzq->setMaterialName("superior"); entBandera->setMaterialName("bandera"); entSuperiorDer->setMaterialName("superior"); entBaseDer->setMaterialName("banderin"); nodoSuperiorIzq->attachObject(entSuperiorIzq); nodoSuperiorIzq->setScale(0.03,0.008,0.06); nodoSuperiorIzq->translate(2.2,7.2,0.0); nodoSuperiorIzq->rotate(Ogre::Vector3(0.0,0.0,1.0),Ogre::Radian(Ogre::Degree(180.0))); nodoBandera->attachObject(entBandera); nodoBandera->setScale(1.2,3.85,1.0); nodoBandera->translate(-2.2,7.2,0.0); nodoBandera->rotate(Ogre::Vector3(0.0,0.0,1.0),Ogre::Radian(Ogre::Degree(90.0))); nodoSuperiorDer->attachObject(entSuperiorDer); nodoSuperiorDer->setScale(0.03,0.008,0.06); nodoSuperiorDer->translate(-152.2,7.2,0.0); nodoBaseDer->attachObject(entBaseDer); nodoBaseDer->translate(-150.0,0.0,0.0); nodoBanderin->attachObject(entBanderin); nodoBanderin->addChild(nodoSuperiorIzq); nodoBanderin->addChild(nodoBandera); nodoBanderin->addChild(nodoSuperiorDer); nodoBanderin->addChild(nodoBaseDer); nodoBanderin->setPosition(x,y,z); nodoBanderin->setScale(60.0,600.0,60.0); }
void VLogicModel::_updateLocatorPos() { for (VLocatorMap::iterator itr = mLocators.begin(); itr != mLocators.end(); ++itr) { VLocatorValue &tempValue = itr->second; // 只更新创建出来的(已经使用的)locator node if (tempValue.mLocatorNode != VNULL) { if (!tempValue.mBoneName.empty()) { Ogre::Bone *bone = VNULL; try { bone = mSkeleton->getBone(tempValue.mBoneName); } catch (const Ogre::Exception &e) { Ogre::LogManager::getSingleton().logMessage("LogicModel::_updateLocatorPos " + mName + e.getDescription()); continue; } assert(bone != VNULL); Ogre::SceneNode *locatorNode = tempValue.mLocatorNode; assert(locatorNode != VNULL); locatorNode->setPosition(bone->_getDerivedPosition()); locatorNode->setOrientation(bone->_getDerivedOrientation()); if (tempValue.mTranslateFirst) { // 先平移,再旋转 locatorNode->translate(tempValue.mPosition, Ogre::Node::TS_LOCAL); locatorNode->rotate(tempValue.mOrientation, Ogre::Node::TS_LOCAL); } else { // 先旋转,再平移 locatorNode->rotate(tempValue.mOrientation, Ogre::Node::TS_LOCAL); locatorNode->translate(tempValue.mPosition, Ogre::Node::TS_LOCAL); } } } } if (mLocators.size() != 0) { mModelMainNode->_update(true, false); } }
void AWGraphics::SceneDirector::createPlayer() { // Add player entity to the scene Ogre::Entity* ogreEntity = mSceneMgr->createEntity("ogrehead.mesh"); Ogre::SceneNode* parentNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Ogre::SceneNode* ogreNode = parentNode->createChildSceneNode(); ogreNode->attachObject(ogreEntity); ogreNode->rotate(Ogre::Vector3(0.0, 1.0, 0.0), Ogre::Radian(Ogre::Degree(180))); ogreNode->setPosition(0, 80, 0); mPlayerNode = parentNode; // Initialize and add a light mSceneMgr->setAmbientLight(Ogre::ColourValue(.5, .5, .5)); Ogre::Light* light = mSceneMgr->createLight("MainLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(Ogre::Vector3(0, -1, 1)); /*// Directional light Ogre::Light* directionalLight = mSceneMgr->createLight("DirectionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(.8, .6, .2)); directionalLight->setSpecularColour(Ogre::ColourValue(.8, .6, .2)); */ // Add skydome mSceneMgr->setSkyDome(true, "CloudySky", 5, 8); // cannot find... :( }
bool TutorialApplication::mouseMoved(const OIS::MouseEvent& me) { // Move the camera around an origin point if the user is holding the right mouse button if(me.state.buttonDown(OIS::MB_Right)) { int relativeX = me.state.X.rel; int relativeY = me.state.Y.rel; int relativeZ = me.state.Z.rel; Ogre::SceneNode* positionNode = mSceneMgr->getSceneNode("CAMERA_POSITION"); Ogre::Vector3 pos = positionNode->getPosition(); Ogre::Vector3 origin = Ogre::Vector3(0,0,0); Ogre::Vector3 scale = origin - pos; scale.normalise(); //if(pos.z > 50.0f) //{ positionNode->setPosition(pos+(scale*relativeZ)); //} //currentDegree += ; if(currentDegree > maxDegree){ currentDegree = maxDegree; } if(currentDegree < minDegree){ currentDegree = minDegree; } Ogre::SceneNode* rotationNode = mSceneMgr->getSceneNode("CAMERA_ROTATION"); rotationNode->rotate(Ogre::Quaternion(Ogre::Degree(relativeX*0.1f), Ogre::Vector3(0,1,0)) , Ogre::Node::TransformSpace::TS_WORLD); rotationNode->rotate(Ogre::Quaternion(Ogre::Degree(relativeY*0.1f), Ogre::Vector3(1,0,0)) , Ogre::Node::TransformSpace::TS_LOCAL); } return true; }
int main(int argc, char* argv[]){ cout << "Test Ogre Program blaha" << endl; //Relative to where its executed from, not binary location Ogre::Root *mRoot = new Ogre::Root("configs/plugins.cfg","configs/config.cfg","logs/main.log"); if(!(mRoot->restoreConfig() || mRoot->showConfigDialog())){ delete mRoot; return -1; } // setup resources // Only add the minimally required resource locations to load up the Ogre head mesh Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/programs", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/programs/GLSL", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/scripts", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/textures", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/models", "FileSystem", "General"); //Create the window Ogre::RenderWindow *mWindow = mRoot->initialise(true, "initial Render Window"); Ogre::SceneManager *sceneManager = mRoot->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera *camera = sceneManager->createCamera("PlayerCam"); camera->setPosition(Ogre::Vector3(0,0,80)); camera->lookAt(Ogre::Vector3(0,0,-300)); camera->setNearClipDistance(5); Ogre::Viewport* vp = mWindow->addViewport(camera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); Ogre::Entity* ogreHead = sceneManager->createEntity("Head","ogreHead.mesh"); Ogre::SceneNode* headNode = sceneManager->getRootSceneNode()->createChildSceneNode(); headNode->attachObject(ogreHead); sceneManager->setAmbientLight(Ogre::ColourValue(0.5,0.5,0.5)); //Run the system bool continueRunning = true; while(continueRunning){ mRoot->renderOneFrame(); headNode->rotate(Ogre::Vector3(0,1,0),Ogre::Radian(0.005)); if(mWindow->isClosed()){ continueRunning = false; } } delete mRoot; }
//--------------------------------------------------------------------------------------------- void TShowTankWoT_test::AddEntity(Ogre::Entity* pEnt, TOrient& orient, Ogre::SceneManager* pSM) { pEnt->setCastShadows(false); Ogre::SceneNode* pNode = pSM->getRootSceneNode()->createChildSceneNode(); pNode->attachObject(pEnt); pNode->setScale(orient.scale); pNode->rotate(orient.axisRotate, orient.angleRotate); pNode->setPosition(orient.pos); }
void ExteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) { assert(mInsert); Ogre::SceneNode *parent = mInsert; //std::cout << "ELEMENTS:" << elements; for (int i = 0; i < elements; i++){ if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i])) parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneNodeName[i])); } parent->rotate(axis, angle); }
// FrameListener callback (~ idleFunc). Perform animation here bool frameRenderingQueued(const Ogre::FrameEvent& evt) { float t = mTimer.getMilliseconds()*0.001; // Do some simple animations by changing scene node transform parameters Ogre::SceneNode* triangle = mScene->getSceneNode("Triangle"); triangle->resetToInitialState(); triangle->rotate(Ogre::Vector3(0, 0, 1), Ogre::Radian(t)); // Exercise 1: Use SceneNode to manipulate the object and create animation // ... return true; // Return false to quit }
void HelloOgre::update(float){ static int move_dir = -1; static float move_step = 2.0f; static int move_count = 0; static float move_offset = 0.0f; if( move_count % 150 == 0 ){ move_dir *= -1; } move_offset = move_step * move_dir; move_count++; if( ogre_head_node ){ ogre_head_node->translate( Ogre::Vector3(move_offset, 0.0f, 0.0f)); ogre_head_node->rotate( Ogre::Vector3( 0.0f, 1.0f, 0.0f ), Ogre::Radian(0.1f) ); } if( ogre_head_node2 ){ ogre_head_node2->translate( Ogre::Vector3(-move_offset, 0.0f, 0.0f)); ogre_head_node2->rotate( Ogre::Vector3( 0.0f, 1.0f, 0.0f ), Ogre::Radian(0.1f) ); } size_t nsize = vec_ogre_head_node.size(); Ogre::SceneNode* pnode = NULL; size_t half_size = nsize >> 1; for( size_t i=0; i<half_size; ++i ){ pnode = vec_ogre_head_node[i]; pnode->translate( Ogre::Vector3((move_offset*i*0.1f), 0.0f, 0.0f)); pnode->rotate( Ogre::Vector3( 0.0f, 1.0f, 0.0f ), Ogre::Radian(0.1f) ); } for( size_t i=0; i<half_size; ++i ){ pnode = vec_ogre_head_node[half_size+i]; pnode->translate( Ogre::Vector3(-(move_offset*i*0.1f), 0.0f, 0.0f)); pnode->rotate( Ogre::Vector3( 0.0f, 1.0f, 0.0f ), Ogre::Radian(0.1f) ); } }
void ModelRenderer::repositionSceneNode() { if (mModel) { Ogre::SceneNode* node = mTexture->getRenderContext()->getSceneNode(); if (node) { node->setOrientation(mDefaultRotation); node->rotate(mModel->getDefinition()->getRotation()); //translate the scale node according to the translate defined in the model node->setPosition(mDefaultTranslation); node->translate(mModel->getDefinition()->getTranslate()); } } }
void TutorialApplication::createCamera(void) { // Create the camera ExampleApplication::createCamera(); SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("CameraNode"); camNode->attachObject(mCamera); // Create headlight Light* light = mSceneMgr->createLight("headlight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDiffuseColour(1,1,1); Ogre::SceneNode* lightNode = camNode->createChildSceneNode("HeadlightNode"); lightNode->rotate( Ogre::Vector3::UNIT_Y, Ogre::Degree(180), Ogre::Node::TS_LOCAL ); lightNode->attachObject(light); }
//------------------------------------------------------------------------------------- bool PlayersManager::moving(zappy::Player *p, int i) { OPlayer *OPlayer = this->mOPlayers.at(i); this->speed = Constants::SquareSize / ((Constants::timeUnit / static_cast<Ogre::Real>(time))); Ogre::SceneNode *node = OPlayer->getSceneNode(); Ogre::Vector3 &direction = OPlayer->getDirection(); Ogre::Real &distance = OPlayer->getDistance(); Ogre::Real move = this->speed * this->tslf; Ogre::Vector3 destination(p->getX() * Constants::SquareSize, 0, p->getY() * Constants::SquareSize); Ogre::AnimationState *anim = OPlayer->getEntity()-> getAnimationState(distance <= 0.0f ? "Idle" : "Walk"); anim->setLoop(true); anim->setEnabled(true); if (direction == Ogre::Vector3::ZERO) { Ogre::Vector3 src = node->getOrientation() * Ogre::Vector3::UNIT_X; direction = destination - node->getPosition(); distance = direction.normalise(); if ((1.0f + src.dotProduct(direction)) < 0.0001f) node->yaw(Ogre::Degree(180)); else node->rotate(src.getRotationTo(direction)); if (distance > Constants::SquareSize) distance = 0.0f; } else { distance -= move; if (distance <= 0.0f) { node->setPosition(destination); direction = Ogre::Vector3::ZERO; } else node->translate(direction * move); } if (OPlayer->stateHasChanged()) OPlayer->detachAnim(); anim->addTime(this->tslf); return true; }
void createPalms(Ogre::SceneManager *mSceneMgr) { const int NumberOfPalms = 12; Ogre::SceneNode* mPalmsSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); for (int k = 0; k < NumberOfPalms; k++) { Ogre::Vector3 RandomPos = Ogre::Vector3(rnd_(500,2500), 0, rnd_(500,2500)); Ogre::RaySceneQuery * raySceneQuery = mSceneMgr-> createRayQuery(Ogre::Ray(RandomPos + Ogre::Vector3(0,1000000,0), Ogre::Vector3::NEGATIVE_UNIT_Y)); Ogre::RaySceneQueryResult& qryResult = raySceneQuery->execute(); Ogre::RaySceneQueryResult::iterator i = qryResult.begin(); if (i != qryResult.end() && i->worldFragment) { if (i->worldFragment->singleIntersection.y>105 || i->worldFragment->singleIntersection.y<20) { k--; continue; } RandomPos.y = i->worldFragment->singleIntersection.y; } else { k--; continue; } Ogre::Entity *mPalmEnt = mSceneMgr->createEntity("Palm"+Ogre::StringConverter::toString(k), "Palm.mesh"); Ogre::SceneNode *mPalmSN = mPalmsSceneNode->createChildSceneNode(); mPalmSN->rotate(Ogre::Vector3(-1,0,rnd_(-0.3,0.3)), Ogre::Degree(90)); mPalmSN->attachObject(mPalmEnt); Ogre::Real Scale = rnd_(50,75); mPalmSN->scale(Scale,Scale,Scale); mPalmSN->setPosition(RandomPos); } }
void ModelRenderer::repositionSceneNode() { if (mModel) { Ogre::SceneNode* node = mTexture->getRenderContext()->getSceneNode(); if (node) { node->setOrientation(Ogre::Quaternion::IDENTITY); //rotate node to fit with WF space //perhaps this is something to put in the model spec instead? // node->rotate(Ogre::Vector3::UNIT_Y,(Ogre::Degree)90); node->rotate(mModel->getRotation()); //translate the scale node according to the translate defined in the model node->setPosition(Ogre::Vector3::ZERO); node->translate(mModel->getDefinition()->getTranslate()); } } }
// ------------------------- Scene description ------------------------- // SceneManager* createOgreScene() { SceneManager* scene = mRoot->createSceneManager(ST_GENERIC); // Initialize camera Camera* camera = scene->createCamera("MainCamera"); camera->setPosition(Vector3(0, 10, 30)); camera->lookAt(Vector3(0, 0, 0)); camera->setNearClipDistance(0.5); camera->setFOVy(Ogre::Degree(60.0)); camera->setAspectRatio((float) mWindow->getWidth() / mWindow->getHeight()); // Set up lighting (~ glEnable(GL_LIGHTING), glEnable(GL_LIGHT0), glLightfv(...)): scene->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f)); Light* light = scene->createLight("MainLight"); light->setType(Light::LT_POINT); light->setDiffuseColour(1, 1, 1); light->setSpecularColour(1, 1, 1); light->setPosition(20.0f, 80.0f, 50.0f); // Enable shadow computations scene->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); // Scenery Ogre::Entity* plane = scene->createEntity("Plane", Ogre::SceneManager::PT_PLANE); Ogre::SceneNode* planeNode = scene->getRootSceneNode()->createChildSceneNode("PlaneNode"); planeNode->attachObject(plane); planeNode->rotate(Ogre::Vector3(-1, 0, 0), Ogre::Degree(90)); plane->setCastShadows(false); plane->setMaterialName("Floor/Marble"); // Load character mesh mBodyNode = scene->getRootSceneNode()->createChildSceneNode(Vector3::UNIT_Y * 5); mBodyEnt = scene->createEntity("SinbadBody", "Sinbad.mesh"); mBodyNode->attachObject(mBodyEnt); // Load animations // Exercise 5: Get pointer to animation state // ... return scene; }
void World::LoadSceneFile(string sceneFile) { Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_LOW); Ogre::SceneNode* worldNode = m_sceneMgr->getRootSceneNode()->createChildSceneNode(); worldNode->rotate(Ogre::Vector3::UNIT_X, Ogre::Degree(-90.0f)); string meshName; float fDrawDistance; bool bIsLod; Ogre::Vector3 position; Ogre::Quaternion rotation; ifstream sceneStream(sceneFile); // skip the title and the table title of the file string strline; int i = 0; while (!sceneStream.eof()) { getline(sceneStream, strline); if (strline.length() == 0) continue; std::istringstream ss(strline); std::string token; getline(ss, token, ','); boost::trim(token); meshName = token; getline(ss, token, ','); boost::trim(token); fDrawDistance = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); bIsLod = lexical_cast<bool>(token); getline(ss, token, ','); boost::trim(token); position.x = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); position.y = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); position.z = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); rotation.w = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); rotation.x = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); rotation.y = lexical_cast<float>(token); getline(ss, token, ','); boost::trim(token); rotation.z = lexical_cast<float>(token); Ogre::MeshPtr mesh; Ogre::Entity* entity; Ogre::Entity* realEntity = m_sceneMgr->createEntity(meshName); if (fDrawDistance > 300.0f && !bIsLod) continue; if (bIsLod) { mesh = Ogre::MeshManager::getSingleton().createManual(meshName + "lod" + std::to_string(i), "General"); // empty mesh mesh->createManualLodLevel(0, "NULL"); mesh->createManualLodLevel(700, meshName); mesh->_setBounds( realEntity->getMesh()->getBounds()); mesh->_setBoundingSphereRadius(realEntity->getMesh()->getBoundingSphereRadius()); mesh->load(); entity->setRenderingDistance(fDrawDistance); entity = m_sceneMgr->createEntity(mesh->getName()); } else { mesh = Ogre::MeshManager::getSingleton().getByName(meshName); entity = m_sceneMgr->createEntity(meshName); entity->setRenderingDistance(fDrawDistance); } m_sceneMgr->destroyEntity(realEntity); Ogre::SceneNode* sceneNode = worldNode->createChildSceneNode(); sceneNode->attachObject(entity); fix_gta_coord(rotation); sceneNode->rotate(rotation); sceneNode->setPosition(position); i++; } worldNode->setScale(5.0f, 5.0f, 5.0f); sceneStream.close(); Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_NORMAL); }
Ogre::SceneNode* GameObjectFactory::create_SAF() { Ogre::String _objectName = "SAF_" + Ogre::StringConverter::toString(SAF_id); SAF_id++; Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode(); Ogre::Entity* entity = scene_manager->createEntity(_objectName, "Base_Ship.mesh"); Ogre::SceneNode* node = root_scene_node->createChildSceneNode(_objectName); entity->setMaterialName("ShinyMaterial"); node->attachObject(entity); //node->setPosition(0.0,0.0,0.0); node->setScale(1.0,1.0,1.0); node->showBoundingBox(true); //cockpit entity = scene_manager->createEntity(_objectName + "_Cockpit", "Cockpit.mesh"); Ogre::SceneNode* child = node->createChildSceneNode(_objectName + "_Cockpit"); entity->setMaterialName("BlueMaterial"); child->attachObject(entity); child->rotate(Ogre::Quaternion(Ogre::Radian(1.570797f), Ogre::Vector3(0.0,0.0,-1.0))); child->translate(-1.22, -0.17430, 0.0f); // /* Ogre::SceneNode* camera = scene_manager->getSceneNode("MyCameraNode"); Ogre::Camera* mCam = (Ogre::Camera*)camera->detachObject("MyCamera"); scene_manager->destroySceneNode("MyCameraNode"); mCam->setPosition(child->_getDerivedPosition()); mCam->setOrientation(child->_getDerivedOrientation()); mCam->move(Ogre::Vector3(0.0, 0.5, 0.0)); cout << mCam->getPosition() << endl; child->attachObject(mCam); child = child->createChildSceneNode("MyCameraNode"); child->attachObject(mCam); child->rotate(Ogre::Quaternion(Ogre::Radian(3.14159f), Ogre::Vector3(-1.0, 0.0, 1.0))); child->pitch(Ogre::Degree(95)); child->translate(0.0, -1.6, 0.0); */ //generators entity = scene_manager->createEntity(_objectName + "_Generator", "Generator.mesh"); child = node->createChildSceneNode(_objectName + "_Generator"); entity->setMaterialName("ObjectMaterial"); child->attachObject(entity); child->translate(0.5f, 0.0f, 0.0f); //engines entity = scene_manager->createEntity(_objectName + "_Engines", "Engines.mesh"); child = node->createChildSceneNode(_objectName + "_Engines"); entity->setMaterialName("ShinyBlueMaterial"); child->attachObject(entity); child->rotate(Ogre::Quaternion(Ogre::Radian(3.01f), Ogre::Vector3(-1.0,0.0,0.0))); child->translate(-0.02796f, -0.92620f, -0.87242f); // entity = scene_manager->createEntity(_objectName + "_Impulse", "Impule_Engine.mesh"); child = node->createChildSceneNode(_objectName + "_Impulse"); entity->setMaterialName("ObjectMaterial"); child->attachObject(entity); child->translate(1.69124f, 0.31351f, 0.005f); //launchers entity = scene_manager->createEntity(_objectName + "_Launcher", "Launcher_Weapon.mesh"); child = node->createChildSceneNode(_objectName + "_Launcher"); entity->setMaterialName("ShinyBlueMaterial"); child->attachObject(entity); child->translate(1.64124f, 0.2, 0.005); //laser entity = scene_manager->createEntity(_objectName + "_Laser", "Laser_Weapon.mesh"); child = node->createChildSceneNode(_objectName + "_Laser"); entity->setMaterialName("ShinyBlueMaterial"); child->attachObject(entity); child->translate(1.66224f, 0.21, 0.005); // return node; }
int initOgreAR(aruco::CameraParameters camParams, unsigned char* buffer, std::string resourcePath) { /// INIT OGRE FUNCTIONS #ifdef _WIN32 root = new Ogre::Root(resourcePath + "plugins_win.cfg", resourcePath + "ogre_win.cfg"); #elif __x86_64__ || __ppc64__ root = new Ogre::Root(resourcePath + "plugins_x64.cfg", resourcePath + "ogre.cfg"); #else root = new Ogre::Root(resourcePath + "plugins.cfg", resourcePath + "ogre.cfg"); #endif if (!root->showConfigDialog()) return -1; Ogre::SceneManager* smgr = root->createSceneManager(Ogre::ST_GENERIC); /// CREATE WINDOW, CAMERA AND VIEWPORT Ogre::RenderWindow* window = root->initialise(true); Ogre::Camera *camera; Ogre::SceneNode* cameraNode; camera = smgr->createCamera("camera"); camera->setNearClipDistance(0.01f); camera->setFarClipDistance(10.0f); camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC); camera->setPosition(0, 0, 0); camera->lookAt(0, 0, 1); double pMatrix[16]; camParams.OgreGetProjectionMatrix(camParams.CamSize,camParams.CamSize, pMatrix, 0.05,10, false); Ogre::Matrix4 PM(pMatrix[0], pMatrix[1], pMatrix[2] , pMatrix[3], pMatrix[4], pMatrix[5], pMatrix[6] , pMatrix[7], pMatrix[8], pMatrix[9], pMatrix[10], pMatrix[11], pMatrix[12], pMatrix[13], pMatrix[14], pMatrix[15]); camera->setCustomProjectionMatrix(true, PM); camera->setCustomViewMatrix(true, Ogre::Matrix4::IDENTITY); window->addViewport(camera); cameraNode = smgr->getRootSceneNode()->createChildSceneNode("cameraNode"); cameraNode->attachObject(camera); /// CREATE BACKGROUND FROM CAMERA IMAGE int width = camParams.CamSize.width; int height = camParams.CamSize.height; // create background camera image mPixelBox = Ogre::PixelBox(width, height, 1, Ogre::PF_R8G8B8, buffer); // Create Texture mTexture = Ogre::TextureManager::getSingleton().createManual("CameraTexture",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,width,height,0,Ogre::PF_R8G8B8,Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); //Create Camera Material Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("CameraMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Technique *technique = material->createTechnique(); technique->createPass(); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->createTextureUnitState("CameraTexture"); Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("CameraMaterial"); // Render the background before everything else rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); // Hacky, but we need to set the bounding box to something big, use infinite AAB to always stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Attach background to the scene Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode("Background"); node->attachObject(rect); /// CREATE SIMPLE OGRE SCENE // add sinbad.mesh Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourcePath + "Sinbad.zip", "Zip", "Popular"); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); for(int i=0; i<MAX_MARKERS; i++) { Ogre::String entityName = "Marker_" + Ogre::StringConverter::toString(i); Ogre::Entity* ogreEntity = smgr->createEntity(entityName, "Sinbad.mesh"); Ogre::Real offset = ogreEntity->getBoundingBox().getHalfSize().y; ogreNode[i] = smgr->getRootSceneNode()->createChildSceneNode(); // add entity to a child node to correct position (this way, entity axis is on feet of sinbad) Ogre::SceneNode *ogreNodeChild = ogreNode[i]->createChildSceneNode(); ogreNodeChild->attachObject(ogreEntity); // Sinbad is placed along Y axis, we need to rotate to put it along Z axis so it stands up over the marker // first rotate along X axis, then add offset in Z dir so it is over the marker and not in the middle of it ogreNodeChild->rotate(Ogre::Vector3(1,0,0), Ogre::Radian(Ogre::Degree(90))); ogreNodeChild->translate(0,0,offset,Ogre::Node::TS_PARENT); // mesh is too big, rescale! const float scale = 0.006675f; ogreNode[i]->setScale(scale, scale, scale); // Init animation ogreEntity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE); if(i==0) { baseAnim[i] = ogreEntity->getAnimationState("HandsClosed"); topAnim[i] = ogreEntity->getAnimationState("HandsRelaxed"); } else if(i==1) { baseAnim[i] = ogreEntity->getAnimationState("Dance"); topAnim[i] = ogreEntity->getAnimationState("Dance"); } else if(i==2) { baseAnim[i] = ogreEntity->getAnimationState("RunBase"); topAnim[i] = ogreEntity->getAnimationState("RunTop"); } else { baseAnim[i] = ogreEntity->getAnimationState("IdleBase"); topAnim[i] = ogreEntity->getAnimationState("IdleTop"); } baseAnim[i]->setLoop(true); topAnim[i]->setLoop(true); baseAnim[i]->setEnabled(true); topAnim[i]->setEnabled(true); } /// KEYBOARD INPUT READING size_t windowHnd = 0; window->getCustomAttribute("WINDOW", &windowHnd); im = OIS::InputManager::createInputSystem(windowHnd); keyboard = static_cast<OIS::Keyboard*>(im->createInputObject(OIS::OISKeyboard, true)); return 1; }
void DemoKeeper::FrictionDemo( void ) { mWorld->markForWrite(); // In this demo we have one fixed object and 10 dynamic objects, all of which are hkBoxShapes. But before we create // them we will outline the parameters used in this demo: // // Illustrative parameters for the demo // const int numObjects = 10; // the number of moving boxes const hkReal objectStep = 1.2f; // a notional 'width' of a moving box pair const hkReal initialFriction = 0.0f; const hkReal frictionRange = 1.0f; // friction ranges from initialFriction to frictionRange const hkVector4 axis(0.0f,0.0f,1.0f); const hkReal angle = -HK_REAL_PI / 10.0f; const hkQuaternion boxOrientation(axis, angle); // Orientation const hkReal fixedBoxHalfHeight = 1.0f; const hkReal movingBoxHalfHeight = 0.3f; const hkReal movingBoxInitialVerticalDisplacement = 0.25f; // // Derived parameters for the demo // const hkReal frictionStep = frictionRange / numObjects; // friction ranges in steps of frictionStep const hkReal positionAlongZ = - (objectStep * numObjects) / 2.0f; const hkVector4 fixedBoxSize((objectStep * numObjects) / 2.0f + 2.0f, fixedBoxHalfHeight, (objectStep * numObjects) / 2.0f + 2.0f); const hkVector4 boxSize(0.5f, movingBoxHalfHeight, 0.5f); // Since we've rotated everything, the height above the fixed box is proportional to the 1/cosine of the angle we rotated by. const hkReal movingBoxCentreHeight = (fixedBoxHalfHeight + movingBoxHalfHeight + movingBoxInitialVerticalDisplacement) / hkMath::cos(angle); // As you can see these parameters are used to calculate the position, orientation and frictional values // that are assigned to each of the boxes. By scaling the frictional values between 0.0 and 0.9 you // can see a range of responses from the different boxes as they drop on the surface of the large sloped box. // The creation of the various rigid bodies in the demo is fairly straight forward and follows the usual scheme // of filling out the various members of the hkpRigidBodyCinfo structure, asking Havok to compute // the 'mass properties' for the body and finally adding it to the world. The only slight difference this time // is that each of the dynamic boxes receives a different value for 'm_friction': // // Box shapes // hkpBoxShape* fixedBoxShape = new hkpBoxShape( fixedBoxSize , 0 ); hkpBoxShape* boxShape = new hkpBoxShape( boxSize , 0 ); // // Physical parameters for the demo // hkReal fixedBoxFriction = 0.25f; hkReal boxMass = 1.0f; // // Create the fixed box // { // Position of the box hkVector4 boxPosition(0.0f, 5.0f, 0.0f); hkpRigidBodyCinfo info; { info.m_motionType = hkpMotion::MOTION_FIXED; info.m_friction = fixedBoxFriction; info.m_shape = fixedBoxShape; info.m_position = boxPosition; info.m_rotation = boxOrientation; } hkpRigidBody* box = new hkpRigidBody(info); mWorld->addEntity(box); box->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale and rotate boxNode->scale(((objectStep * numObjects) / 2.0f + 2.0f)*2, fixedBoxHalfHeight*2,((objectStep * numObjects) / 2.0f + 2.0f)*2); Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(boxOrientation); boxNode->rotate(q); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, box,mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, box); } // // Create the moving boxes // for(int i = 0; i < numObjects; i++) { // Compute the box inertia tensor hkMassProperties massProperties; hkpInertiaTensorComputer::computeBoxVolumeMassProperties(boxSize, boxMass, massProperties); // Set up the construction info parameters for the box hkpRigidBodyCinfo info; // Each box has a different friction ranging from 0.0 to 0.9 info.m_friction = initialFriction + frictionStep * i; info.m_shape = boxShape; info.m_mass = boxMass; info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; // Position of the box hkReal zpos = positionAlongZ + objectStep * i; info.m_position = hkVector4(0.0f, movingBoxCentreHeight+6.5, zpos); info.m_rotation = boxOrientation; // Create a box hkpRigidBody* box = new hkpRigidBody(info); mWorld->addEntity(box); box->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale boxNode->scale(0.5f*2, movingBoxHalfHeight*2, 0.5f*2); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.1356,0.3242,0.5403)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, box,mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, box); } // // Remove references from shapes // fixedBoxShape->removeReference(); boxShape->removeReference(); mWorld->unmarkForWrite(); }
void DemoKeeper::createGround( void ) { const hkVector4 halfExtents(12.0f, 1.0f, 12.0f); hkpShape* groundShape = new hkpBoxShape(halfExtents, 0 ); hkpRigidBodyCinfo bodyInfo; bodyInfo.m_mass = 0.0f; bodyInfo.m_shape = groundShape; bodyInfo.m_motionType = hkpMotion::MOTION_FIXED; bodyInfo.m_position.set(0.0f, 10.0f, 0.0f); hkVector4 axis(1.0f, 0.0f, 0.0f); { axis.set(1,0,1); axis.normalize3(); bodyInfo.m_rotation = hkQuaternion(axis, 0.5f); bodyInfo.m_position.set(10.0f, 10.0f, -10.0f); hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo); mWorld->addEntity(groundBody); groundBody->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale and rotate boxNode->scale(24, 2, 24); Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation); boxNode->rotate(q); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, groundBody); } { axis.set(-1,0,1); axis.normalize3(); bodyInfo.m_rotation = hkQuaternion(axis, 0.5f); bodyInfo.m_position.set(10.0f, 10.0f, 10.0f); hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo); mWorld->addEntity(groundBody); groundBody->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale and rotate boxNode->scale(24, 2, 24); Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation); boxNode->rotate(q); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, groundBody); } { axis.set(1,0,-1); axis.normalize3(); bodyInfo.m_rotation = hkQuaternion(axis, 0.5f); bodyInfo.m_position.set(-10.0f, 10.0f, -10.0f); hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo); mWorld->addEntity(groundBody); groundBody->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale and rotate boxNode->scale(24, 2, 24); Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation); boxNode->rotate(q); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, groundBody); } { axis.set(-1,0,-1); axis.normalize3(); bodyInfo.m_rotation = hkQuaternion(axis, 0.5f); bodyInfo.m_position.set(-10.0f, 10.0f, 10.0f); hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo); mWorld->addEntity(groundBody); groundBody->removeReference(); //render it with Ogre Ogre::SceneNode* boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //scale and rotate boxNode->scale(24, 2, 24); Ogre::Quaternion q = HkOgre::Convert::hkQuatToOgre(bodyInfo.m_rotation); boxNode->rotate(q); //display and sync Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::StringConverter::toString(mLabMgr->getEntityCount()),"defCube.mesh"); mLabMgr->setColor(ent, Ogre::Vector3(0.3047,0.3047,0.3047)); HkOgre::Renderable* rend = new HkOgre::Renderable(boxNode, groundBody, mWorld); boxNode->attachObject(ent); //register to lab manager mLabMgr->registerEnity( boxNode, groundBody); } groundShape->removeReference(); }
void BellDisplay::initialise_render_window() { Gtk::Allocation allocation = get_allocation(); set_app_paintable(true); set_child_visible(true); Ogre::NameValuePairList params; #ifdef WIN32 params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)GDK_WINDOW_HWND(mRefGdkWindow->gobj())); #else // GdkWindow* parent = mRefGdkWindow->gobj(); GdkWindow* parent = get_window()->gobj(); GdkDisplay* display = gdk_window_get_display(parent); GdkScreen* screen = gdk_window_get_screen(parent); Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); Screen* xscreen = GDK_SCREEN_XSCREEN(screen); int screen_number = XScreenNumberOfScreen(xscreen); XID xid_parent = GDK_WINDOW_XID(parent); params["parentWindowHandle"] = Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(xdisplay)) + ":" + Ogre::StringConverter::toString(static_cast<unsigned int>(screen_number)) + ":" + Ogre::StringConverter::toString(static_cast<unsigned long>(xid_parent)); #endif mRenderWindow = Ogre::Root::getSingleton().createRenderWindow("Gtk+Ogre Widget", allocation.get_width(), allocation.get_height(), false, ¶ms); mRenderWindow->setAutoUpdated(false); mRenderWindow->setVisible(true); set_has_window(true); set_double_buffered(true); mRenderWindow->setActive(true); mRenderWindow->setVisible(true); // Set default mipmap level & texture filtering Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_TRILINEAR); // Create scene manager mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "SceneManager"); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.7, 0.7, 0.7, 0.7)); Ogre::Light* light = mSceneMgr->createLight("MainLight"); light->setPosition(10, 40, 50); // Create the camera mCamera = mSceneMgr->createCamera("Camera"); mCamera->setPosition(0, 0, 50); mCamera->lookAt(0, 0, 0); mCamera->setNearClipDistance(5); // Create one viewport, entire window mViewport = mRenderWindow->addViewport(mCamera); // Alter the camera aspect ratio to match the viewport mCamera->setFOVy(Ogre::Degree(15)); mCamera->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight())); mSceneMgr->getRootSceneNode()->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(90)); mSceneMgr->getRootSceneNode()->rotate(Ogre::Vector3(0, 0, 1), Ogre::Degree(90)); double offset = -10.0 * (m_BellCount - 1) / 2.0; for(int i = 0; i < m_BellCount; i++) { Ogre::SceneNode* parent = mSceneMgr->getRootSceneNode()->createChildSceneNode(); m_Bells.push_back(BellEntity(mSceneMgr, parent)); parent->rotate(Ogre::Quaternion(Ogre::Radian(-atan2(offset, 50)), Ogre::Vector3::UNIT_Z)); m_Bells[i].Position(offset); offset += 10; } }