void PlayState::addSceneAtaque() { //Cogemos el tablero y le damos la vuelta SceneNode *nodeTableroCol = _sceneMgr->getSceneNode("tableroCol"); nodeTableroCol->roll(Ogre::Degree(180)); //Casillas normales y casillas invisibles para hacer las consultas por RayQuery stringstream sauxnode; string s = "CasColATAQ_"; string x = "CasATAQ_"; Ogre::Real offsetX = 0.0; Ogre::Real offsetY = 0.0; Ogre::Real origen = 7.2; for (int i = 0; i < 10; i++) { offsetY = i * 0.6; for (int j = 0; j < 10; j++) { offsetX = j * 0.6; sauxnode << s << j << "_" << i; SceneNode *nodeCasillaCol = _sceneMgr->createSceneNode (sauxnode.str ()); Entity *entCasillaCol = _sceneMgr->createEntity (sauxnode.str (), "CasillaCol.mesh"); entCasillaCol->setQueryFlags(STAGE); nodeCasillaCol->attachObject(entCasillaCol); nodeCasillaCol->setVisible(false); nodeTableroCol->addChild (nodeCasillaCol); cout << "nodo " << sauxnode.str() << " creado. \n"; sauxnode.str(""); sauxnode << x << j << "_" << i; SceneNode *nodeCasilla = _sceneMgr->createSceneNode(sauxnode.str()); Entity *entCasilla = _sceneMgr->createEntity(sauxnode.str(), "Casilla.mesh"); entCasilla->setQueryFlags(CASILLA); nodeCasilla->attachObject(entCasilla); nodeTableroCol->addChild (nodeCasilla); cout << "nodo " << sauxnode.str() << " creado. \n"; nodeCasilla->setPosition(origen - j - offsetX , nodeCasilla->getPosition().y-1, (origen - i - offsetY) * -1); nodeCasillaCol->setPosition(origen - j - offsetX, nodeCasillaCol->getPosition().y-1, (origen - i - offsetY) * -1); sauxnode.str(""); } } }
SceneNode* SceneGraphFactory::transform(scenario::SCNXArchive &scnxArchive, const bool &showLaneConnectors) { SceneNode *sn = new SceneNode(); if (scnxArchive.getAerialImage() != NULL) { clog << "SceneGraphFactory: Found AerialImage but currently no transformation available." << endl; } ScenarioTransformation scenarioTransformer(showLaneConnectors); Scenario &scenario = scnxArchive.getScenario(); scenario.accept(scenarioTransformer); sn->addChild(scenarioTransformer.getRoot()); return sn; }
int gr_node_add_child_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* selfData = (gr_node_ud*)luaL_checkudata(L, 1, "gr.node"); luaL_argcheck(L, selfData != 0, 1, "Node expected"); SceneNode *self = dynamic_cast<SceneNode*>(selfData->node); ASSERT(self); gr_node_ud* childdata = (gr_node_ud*)luaL_checkudata(L, 2, "gr.node"); luaL_argcheck(L, childdata != 0, 2, "Node expected"); SceneNode* child = childdata->node; self->addChild(child); return 0; }
void StandLatas::paintBallsHud(){ _numBolas = NUM_BOLAS; SceneNode *ballsHud = _sceneMgr->createSceneNode("ballsHud"); for(int i=0; i< _numBolas;i++){ stringstream str; str << "BallHud" << i; string name = str.str(); SceneNode *ballNode = _sceneMgr->createSceneNode(name); Entity *ballEnt = _sceneMgr->createEntity("ball.mesh"); ballNode->attachObject(ballEnt); ballNode->scale(Vector3(0.3,0.3,0.3)); ballNode->translate(Vector3(((float)i/(float)10)-0.4,-0.35,0)); std::cout << str.str() << " - " << ballNode->getPosition() << std::endl; ballsHud->addChild(ballNode); } _sceneMgr->getRootSceneNode()->addChild(ballsHud); ballsHud->setPosition(_cameraNode->getPosition() + Vector3(0,0,-1)); }
// Just override the mandatory create scene method void createScene(void) { RenderSystem *rs = Root::getSingleton().getRenderSystem(); const RenderSystemCapabilities* caps = rs->getCapabilities(); if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM))) { OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support vertex and fragment programs, so cannot " "run this demo. Sorry!", "DeferredShading::createScene"); } if (caps->getNumMultiRenderTargets()<2) { OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support at least two simultaneous render targets, so cannot " "run this demo. Sorry!", "DeferredShading::createScene"); } // Prepare athene mesh for normalmapping MeshPtr pAthene = MeshManager::getSingleton().load("athene.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); unsigned short src, dest; if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) pAthene->buildTangentVectors(VES_TANGENT, src, dest); // Prepare knot mesh for normal mapping pAthene = MeshManager::getSingleton().load("knot.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) pAthene->buildTangentVectors(VES_TANGENT, src, dest); // Set ambient light mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.15)); // Skybox mSceneMgr->setSkyBox(true, "DeferredDemo/SkyBox"); // Create "root" node SceneNode* rootNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Entity* athena = mSceneMgr->createEntity("Athena", "athene.mesh"); athena->setMaterialName("DeferredDemo/DeferredAthena"); SceneNode *aNode = rootNode->createChildSceneNode(); aNode->attachObject( athena ); aNode->setPosition(-100, 40, 100); // Create a prefab plane mPlane = new MovablePlane("ReflectPlane"); mPlane->d = 0; mPlane->normal = Vector3::UNIT_Y; MeshManager::getSingleton().createCurvedPlane("ReflectionPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *mPlane, 2000, 2000, -1000, 20, 20, true, 1, 10, 10, Vector3::UNIT_Z); mPlaneEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" ); mPlaneNode = rootNode->createChildSceneNode(); mPlaneNode->attachObject(mPlaneEnt); mPlaneNode->translate(-5, -30, 0); //mPlaneNode->roll(Degree(5)); mPlaneEnt->setMaterialName("DeferredDemo/Ground"); // Create an entity from a model (will be loaded automatically) Entity* knotEnt = mSceneMgr->createEntity("Knot", "knot.mesh"); knotEnt->setMaterialName("DeferredDemo/RockWall"); knotEnt->setMeshLodBias(0.25f); // Create an entity from a model (will be loaded automatically) Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); ogreHead->getSubEntity(0)->setMaterialName("DeferredDemo/Ogre/Eyes");// eyes ogreHead->getSubEntity(1)->setMaterialName("DeferredDemo/Ogre/Skin"); ogreHead->getSubEntity(2)->setMaterialName("DeferredDemo/Ogre/EarRing"); // earrings ogreHead->getSubEntity(3)->setMaterialName("DeferredDemo/Ogre/Tusks"); // tusks rootNode->createChildSceneNode( "Head" )->attachObject( ogreHead ); // Add a whole bunch of extra entities to fill the scene a bit Entity *cloneEnt; int N=4; for (int n = 0; n < N; ++n) { float theta = 2.0f*Math::PI*(float)n/(float)N; // Create a new node under the root SceneNode* node = mSceneMgr->createSceneNode(); // Random translate Vector3 nodePos; nodePos.x = Math::SymmetricRandom() * 40.0 + Math::Sin(theta) * 500.0; nodePos.y = Math::SymmetricRandom() * 20.0 - 40.0; nodePos.z = Math::SymmetricRandom() * 40.0 + Math::Cos(theta) * 500.0; node->setPosition(nodePos); Quaternion orientation(Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom()); orientation.normalise(); node->setOrientation(orientation); rootNode->addChild(node); // Clone knot char cloneName[12]; sprintf(cloneName, "Knot%d", n); cloneEnt = knotEnt->clone(cloneName); // Attach to new node node->attachObject(cloneEnt); } mCamera->setPosition(-50, 100, 500); mCamera->lookAt(0,0,0); // show overlay Overlay* overlay = OverlayManager::getSingleton().getByName("Example/ShadowsOverlay"); overlay->show(); mSystem = new DeferredShadingSystem(mWindow->getViewport(0), mSceneMgr, mCamera); // Create main, moving light MLight* l1 = mSystem->createMLight();//"MainLight"); l1->setDiffuseColour(0.75f, 0.7f, 0.8f); l1->setSpecularColour(0.85f, 0.9f, 1.0f); SceneNode *lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); lightNode->attachObject(l1); // Create a track for the light Animation* anim = mSceneMgr->createAnimation("LightTrack", 16); // Spline it for nice curves anim->setInterpolationMode(Animation::IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack* track = anim->createNodeTrack(0, lightNode); // Setup keyframes TransformKeyFrame* key = track->createNodeKeyFrame(0); // A start position key->setTranslate(Vector3(300,300,-300)); key = track->createNodeKeyFrame(4);//B key->setTranslate(Vector3(300,300,300)); key = track->createNodeKeyFrame(8);//C key->setTranslate(Vector3(-300,300,300)); key = track->createNodeKeyFrame(12);//D key->setTranslate(Vector3(-300,300,-300)); key = track->createNodeKeyFrame(16);//D key->setTranslate(Vector3(300,300,-300)); // Create a new animation state to track this SharedData::getSingleton().mAnimState = mSceneMgr->createAnimationState("LightTrack"); SharedData::getSingleton().mAnimState->setEnabled(true); // Create some happy little lights createSampleLights(); // safely setup application's (not postfilter!) shared data SharedData::getSingleton().iCamera = mCamera; SharedData::getSingleton().iRoot = mRoot; SharedData::getSingleton().iWindow = mWindow; SharedData::getSingleton().iActivate = true; SharedData::getSingleton().iGlobalActivate = true; SharedData::getSingleton().iSystem = mSystem; SharedData::getSingleton().iMainLight = l1; }
bool Scene::addSceneFile(const char* Scenefile, const char* modellePfad) { SceneNode* root; this->m_Root = root; char in_room_name[200]; Vector in_room_size; char in_room_wallpaper_texture[200]; //float in_room_wallpaper_tiling[2]; Vector in_room_wallpaper_tiling; char in_room_model[200]; char in_object_name[200]; Vector in_object_translation; Vector in_object_rotation; float in_rotationAngle; Vector in_object_scaling; char in_object_model[200]; char in_object_parent[200]; std::vector<std::string*> coord; std::ifstream in(Scenefile); if(!in.is_open()) { std::cout << "datei nicht geoeffnet" << std::endl; return -1; } char buf[256]; while(!in.eof()) { in.getline(buf,256); coord.push_back(new std::string(buf)); } for(int i=0;i<coord.size();i++) { if((*coord[i])[0]=='r' && (*coord[i])[1]=='o' && (*coord[i])[2]=='o' && (*coord[i])[3]=='m') { sscanf(coord[i]->c_str(),"roomname %s { size %f %f %f wallpaper { texture %s tiling %f %f } model %s }", in_room_name, &in_room_size.X, &in_room_size.Y, &in_room_size.Z, in_room_wallpaper_texture, &in_room_wallpaper_tiling.X, &in_room_wallpaper_tiling.Y, in_room_model); SceneNode* rootNode = new SceneNode(); rootNode->m_isActive =false; this->m_Root = rootNode; std::string s_in_room_name(in_room_name); Model* model = new Model(); char fullPath[200] = {0}; strcat(fullPath,modellePfad); strcat(fullPath,in_room_model); model->load(fullPath, true, modellePfad); this->m_Models.insert(std::pair<std::string, Model*>(in_room_name, model)); this->m_Root->setScaling(in_room_size); this->m_Root->setModel(model); this->m_Root->setName(s_in_room_name); this->m_SceneNodesSet.insert(this->m_Root); } else { sscanf(coord[i]->c_str(),"object %s { translation %f %f %f rotation %f %f %f %f scaling %f %f %f model %s parent %s }", in_object_name, &in_object_translation.X, &in_object_translation.Y, &in_object_translation.Z, &in_object_rotation.X, &in_object_rotation.Y, &in_object_rotation.Z, &in_rotationAngle, &in_object_scaling.X, &in_object_scaling.Y, &in_object_scaling.Z, &in_object_model, &in_object_parent); SceneNode* newNode = new SceneNode(); newNode->m_isActive = false; Model* model = new Model(); char fullPath[200] = {0}; strcat(fullPath,modellePfad); strcat(fullPath,in_object_model); model->load(fullPath, true, modellePfad); this->m_Models.insert(std::pair<std::string, Model*>(in_object_name, model)); std::string s_in_object_name(in_object_name); newNode->setName(s_in_object_name); std::string s_in_object_parent(in_object_parent); if(s_in_object_parent == "NULL") { newNode->setParent(this->m_Root); this->m_Root->addChild(newNode); } else { SceneNode* parent = findSceneNode(s_in_object_parent); if(parent == NULL) { parent = m_Root; } newNode->setParent(parent); parent->addChild(newNode); } std::string s_in_model_ID(in_object_name); newNode->setModel(m_Models.at(s_in_model_ID)); //newNode->setLocalTransform(in_object_translation, in_object_rotation, in_rotationAngle); newNode->m_lastRotation = in_rotationAngle; newNode->m_lastScale = in_object_scaling.X; newNode->setLocalTransform(in_object_translation); newNode->setRotation(in_object_rotation, in_rotationAngle); newNode->setScaling(in_object_scaling); this->m_SceneNodesSet.insert(newNode); } } return false; }
void PlayState::createScene () { //Objeto movable "suelo" para consultar al sceneManager SceneNode *nodeTableroCol = _sceneMgr->createSceneNode("tableroCol"); Entity *entTableroCol = _sceneMgr->createEntity("entTableroCol", "tableroCol.mesh"); entTableroCol->setQueryFlags(STAGE); nodeTableroCol->attachObject(entTableroCol); nodeTableroCol->setVisible(true); _sceneMgr->getRootSceneNode()->addChild(nodeTableroCol); //Casillas normales y casillas invisibles para hacer las consultas por RayQuery stringstream sauxnode; string s = "CasillaCol_"; string x = "Casilla_"; Ogre::Real offsetX = 0.0; Ogre::Real offsetY = 0.0; Ogre::Real origen = -7.2; for (int i = 0; i < 10; i++) { offsetY = i * 0.6; for (int j = 0; j < 10; j++) { offsetX = j * 0.6; sauxnode << s << j << "_" << i; SceneNode *nodeCasillaCol = _sceneMgr->createSceneNode (sauxnode.str ()); Entity *entCasillaCol = _sceneMgr->createEntity (sauxnode.str (), "CasillaCol.mesh"); entCasillaCol->setQueryFlags(STAGE); nodeCasillaCol->attachObject(entCasillaCol); nodeCasillaCol->setVisible(false); nodeTableroCol->addChild (nodeCasillaCol); //cout << "nodo " << sauxnode.str() << " creado. \n"; sauxnode.str(""); sauxnode << x << j << "_" << i; SceneNode *nodeCasilla = _sceneMgr->createSceneNode(sauxnode.str()); Entity *entCasilla = _sceneMgr->createEntity(sauxnode.str(), "Casilla.mesh"); entCasilla->setQueryFlags(CASILLA); nodeCasilla->attachObject(entCasilla); nodeTableroCol->addChild (nodeCasilla); //cout << "nodo " << sauxnode.str() << " creado. \n"; nodeCasilla->setPosition(origen + j + offsetX , nodeCasilla->getPosition().y+1, origen + i + offsetY); nodeCasillaCol->setPosition(origen + j + offsetX, nodeCasillaCol->getPosition().y+1, origen + i + offsetY); sauxnode.str(""); } } SceneNode *nodoLuz = _sceneMgr->createSceneNode ("Luces"); _sceneMgr->setShadowTechnique (SHADOWTYPE_STENCIL_ADDITIVE); Light *luz = _sceneMgr->createLight ("Luz1"); luz->setType (Light::LT_SPOTLIGHT); luz->setPosition (9, 2, 5); luz->setDirection (Vector3 (3, -2, 0)); luz->setSpotlightInnerAngle (Degree (5.0f)); luz->setSpotlightOuterAngle (Degree (55.0f)); luz->setSpotlightFalloff (0.0f); nodoLuz->attachObject (luz); _sceneMgr->getRootSceneNode ()->addChild (nodoLuz); }