void BasicTutorial3::createCursor( float radius ) { radius *= VOXEL_SCALE; // Assuming scene_mgr is your SceneManager. Ogre::ManualObject * circle = mSceneMgr->createManualObject("debugCursor"); // accuracy is the count of points (and lines). // Higher values make the circle smoother, but may slowdown the performance. // The performance also is related to the count of circles. float const accuracy = 35; circle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP); unsigned point_index = 0; for(float theta = 0; theta <= 2 * M_PI; theta += M_PI / accuracy) { circle->position(radius * cos(theta), 0, radius * sin(theta)); circle->index(point_index++); } for(float theta = 0; theta <= 2 * M_PI; theta += M_PI / accuracy) { circle->position(radius * cos(theta), radius * sin(theta), 0); circle->index(point_index++); } circle->index(0); // Rejoins the last point to the first. circle->end(); mCursor = mSceneMgr->getRootSceneNode()->createChildSceneNode("debugCursor"); mCursor->attachObject(circle); }
void Pencil::createIndicator() { Ogre::ManualObject * circle = sceneMgr->createManualObject(name + "::indicator"); float const radius = 2.0; float const accuracy = 35; circle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP); unsigned point_index = 0; for (float theta = 0; theta <= 2 * Ogre::Math::PI; theta += Ogre::Math::PI / accuracy) { circle->position(radius * cos(theta), 0, radius * sin(theta)); circle->index(point_index++); } circle->index(0); // Rejoins the last point to the first. circle->end(); indicatorNode = surfPlaneNode->createChildSceneNode(); indicatorNode->attachObject(circle); indicatorVisible = true; }
static void BuildCellTriangles( Ogre::ManualObject& manualObject, const float cellWidth, const float cellHeight, const Ogre::Vector3& minBoundary, const Ogre::ColourValue& color, const size_t xOffset, const size_t yOffset, const size_t zOffset) { const unsigned int vertexCount = static_cast<unsigned int>(manualObject.getCurrentVertexCount()); const Ogre::Vector3 offset = minBoundary + Ogre::Vector3( xOffset * cellWidth, yOffset * cellHeight, zOffset * cellWidth); manualObject.position(offset); manualObject.colour(color); manualObject.position(offset + Ogre::Vector3(cellWidth, 0, 0)); manualObject.colour(color); manualObject.position(offset + Ogre::Vector3(0, 0, cellWidth)); manualObject.colour(color); manualObject.position(offset + Ogre::Vector3(cellWidth, 0, cellWidth)); manualObject.colour(color); manualObject.index(vertexCount); manualObject.index(vertexCount + 2); manualObject.index(vertexCount + 1); manualObject.index(vertexCount + 1); manualObject.index(vertexCount + 2); manualObject.index(vertexCount + 3); }
void BasicWindow::addAxesLines(float length) { Ogre::ManualObject* mo = mSceneMgr->createManualObject("axesLines"); mo->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); mo->position(-length,0,0); //<- 0 mo->colour(Ogre::ColourValue::Red); mo->position(length,0,0); //<- 1 mo->colour(Ogre::ColourValue::Red); mo->position(0,-length,0); //<- 2 mo->colour(Ogre::ColourValue::Green); mo->position(0,length,0); //<- 3 mo->colour(Ogre::ColourValue::Green); mo->position(0,0,-length); //<- 4 mo->colour(Ogre::ColourValue::Blue); mo->position(0,0,length); //<- 5 mo->colour(Ogre::ColourValue::Blue); mo->index(0); mo->index(1); mo->index(2); mo->index(3); mo->index(4); mo->index(5); mo->end(); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mo); }
Ogre::ManualObject * CCone::CreateCone(Ogre::Real Intensity) { Ogre::ManualObject *Cone = NULL; Ogre::SceneManager *SceneManager = Ogre::Root::getSingleton().getSceneManager("DynamicEffects"); Cone = SceneManager->createManualObject("Cone"); Cone->setDynamic(false); Cone->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST); Ogre::Real deltaAngle = (Ogre::Math::TWO_PI / m_BaseSegments); Ogre::Real deltaHeight = m_Height/(Ogre::Real)m_HeightSegments; Ogre::Vector3 Normal = Ogre::Vector3(m_Radius, m_Height, 0.f).normalisedCopy(); Ogre::Quaternion Quaternion; int Offset = 0; for (int HeightSegmentIndex = 0; HeightSegmentIndex <= m_HeightSegments; HeightSegmentIndex++) { Ogre::Real Radius = m_Radius * (1 - HeightSegmentIndex / (Ogre::Real)m_HeightSegments); for (int BaseSegmentIndex = 0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++) { Ogre::Real x = Radius* cosf(BaseSegmentIndex * deltaAngle); Ogre::Real z = Radius * sinf(BaseSegmentIndex * deltaAngle); Cone->position(x, HeightSegmentIndex * deltaHeight, z); Cone->colour(Intensity, Intensity, 0.0, 1.0); Quaternion.FromAngleAxis(Ogre::Radian(-BaseSegmentIndex*deltaAngle), Ogre::Vector3::NEGATIVE_UNIT_Y); Cone->normal(Quaternion * Normal); Cone->textureCoord(BaseSegmentIndex / (Ogre::Real)m_BaseSegments, HeightSegmentIndex / (Ogre::Real)m_HeightSegments); if (HeightSegmentIndex != m_HeightSegments && BaseSegmentIndex != m_BaseSegments) { Cone->index(Offset + m_BaseSegments + 2); Cone->index(Offset); Cone->index(Offset + m_BaseSegments + 1); Cone->index(Offset + m_BaseSegments + 2); Cone->index(Offset + 1); Cone->index(Offset); } Offset++; } } int centerIndex = Offset; Cone->position(0,0,0); Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y); Cone->textureCoord(0.0,1); Offset++; for (int BaseSegmentIndex=0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++) { Ogre::Real x = m_Radius * cosf(BaseSegmentIndex*deltaAngle); Ogre::Real z = m_Radius * sinf(BaseSegmentIndex*deltaAngle); Cone->position(x, 0.0f, z); Cone->colour(Intensity, Intensity, 0.0, 0.0); Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y); Cone->textureCoord(BaseSegmentIndex/(Ogre::Real)m_BaseSegments,0.0); if (BaseSegmentIndex != m_BaseSegments) { Cone->index(centerIndex); Cone->index(Offset); Cone->index(Offset+1); } Offset++; } Cone->end(); return Cone; }
void Oculus::setupOgreOculus( Ogre::SceneManager *sm, Ogre::RenderWindow* win, Ogre::Root* root ) { mSceneMgr = root->createSceneManager(Ogre::ST_GENERIC); mSceneMgr->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) ); mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED); Ogre::SceneNode* meshNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); // Configure Render Textures: Sizei recommendedTex0Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Left, mHMD->DefaultEyeFov[0], 1.0f ); Sizei recommendedTex1Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Right, mHMD->DefaultEyeFov[1], 1.0f ); // Generate a texture for each eye, as a rendertarget: mLeftEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual( "RiftRenderTextureLeft", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, recommendedTex0Size.w, recommendedTex0Size.h, 0, Ogre::PF_X8B8G8R8, Ogre::TU_RENDERTARGET ); mRightEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual( "RiftRenderTextureRight", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, recommendedTex1Size.w, recommendedTex1Size.h, 0, Ogre::PF_X8B8G8R8, Ogre::TU_RENDERTARGET ); // Assign the textures to the eyes used later: mMatLeft = Ogre::MaterialManager::getSingleton().getByName( "Oculus/LeftEye" ); mMatLeft->getTechnique(0)->getPass(0)->getTextureUnitState(0)-> setTexture( mLeftEyeRenderTexture ); mMatRight = Ogre::MaterialManager::getSingleton().getByName( "Oculus/RightEye" ); mMatRight->getTechnique(0)->getPass(0)->getTextureUnitState(0)-> setTexture( mRightEyeRenderTexture ); ovrEyeRenderDesc eyeRenderDesc[2]; eyeRenderDesc[0] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Left, mHMD->DefaultEyeFov[0] ); eyeRenderDesc[1] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Right, mHMD->DefaultEyeFov[1] ); ovrVector2f UVScaleOffset[2]; ovrRecti viewports[2]; viewports[0].Pos.x = 0; viewports[0].Pos.y = 0; viewports[0].Size.w = recommendedTex0Size.w; viewports[0].Size.h = recommendedTex0Size.h; viewports[1].Pos.x = recommendedTex0Size.w; viewports[1].Pos.y = 0; viewports[1].Size.w = recommendedTex1Size.w; viewports[1].Size.h = recommendedTex1Size.h; Ogre::ManualObject* manual; // Create the Distortion Meshes: for ( int eyeNum = 0; eyeNum < 2; eyeNum ++ ) { ovrDistortionMesh meshData; ovrHmd_CreateDistortionMesh( mHMD, eyeRenderDesc[eyeNum].Eye, eyeRenderDesc[eyeNum].Fov, 0, &meshData ); Ogre::GpuProgramParametersSharedPtr params; if( eyeNum == 0 ) { ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov, recommendedTex0Size, viewports[eyeNum], UVScaleOffset); params = mMatLeft->getTechnique(0)->getPass(0)->getVertexProgramParameters(); } else { ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov, recommendedTex1Size, viewports[eyeNum], UVScaleOffset); params = mMatRight->getTechnique(0)->getPass(0)->getVertexProgramParameters(); } params->setNamedConstant( "eyeToSourceUVScale", Ogre::Vector4( UVScaleOffset[0].x, UVScaleOffset[0].y,0,0 ) ); params->setNamedConstant( "eyeToSourceUVOffset", Ogre::Vector4( UVScaleOffset[1].x, UVScaleOffset[1].y,0,0 ) ); std::cout << "UVScaleOffset[0]: " << UVScaleOffset[0].x << ", " << UVScaleOffset[0].y << std::endl; std::cout << "UVScaleOffset[1]: " << UVScaleOffset[1].x << ", " << UVScaleOffset[1].y << std::endl; // create ManualObject // TODO: Destroy the manual objects!! if( eyeNum == 0 ) { manual = mSceneMgr->createManualObject("RiftRenderObjectLeft"); manual->begin("Oculus/LeftEye", Ogre::RenderOperation::OT_TRIANGLE_LIST); //manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST); } else { manual = mSceneMgr->createManualObject("RiftRenderObjectRight"); manual->begin("Oculus/RightEye", Ogre::RenderOperation::OT_TRIANGLE_LIST); //manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST); } for( unsigned int i = 0; i < meshData.VertexCount; i++ ) { ovrDistortionVertex v = meshData.pVertexData[i]; manual->position( v.ScreenPosNDC.x, v.ScreenPosNDC.y, 0 ); manual->textureCoord( v.TanEyeAnglesR.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x, v.TanEyeAnglesR.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y); manual->textureCoord( v.TanEyeAnglesG.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x, v.TanEyeAnglesG.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y); manual->textureCoord( v.TanEyeAnglesB.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x, v.TanEyeAnglesB.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y); //float vig = std::max( v.VignetteFactor, (float)0.0 ); //manual->colour( vig, vig, vig, vig ); manual->colour( 1, 1, 1, 1 ); } for( unsigned int i = 0; i < meshData.IndexCount; i++ ) { manual->index( meshData.pIndexData[i] ); } // tell Ogre, your definition has finished manual->end(); ovrHmd_DestroyDistortionMesh( &meshData ); meshNode->attachObject( manual ); } // Set up IPD in meters: mIPD = ovrHmd_GetFloat(mHMD, OVR_KEY_IPD, 0.064f); // Set a default value for interpupillary distance: mIPD = 0.064f; // Create a camera in the (new, external) scene so the mesh can be rendered onto it: mCamera = mSceneMgr->createCamera("OculusRiftExternalCamera"); mCamera->setFarClipDistance(1000000.0f); mCamera->setNearClipDistance( 0.1f ); mCamera->setProjectionType( Ogre::PT_ORTHOGRAPHIC ); mCamera->setOrthoWindow(2 , 2); mCamera->lookAt( 0, 0, -1 ); mSceneMgr->getRootSceneNode()->attachObject( mCamera ); meshNode->setPosition( 0, 0, -1 ); meshNode->setScale( 1, 1, -0.1f ); mViewport = m_window->addViewport( mCamera); mViewport->setBackgroundColour(Ogre::ColourValue::Black); mViewport->setOverlaysEnabled(true); }
int DecalManager::addTerrainDecal(Ogre::Vector3 position, Ogre::Vector2 size, Ogre::Vector2 numSeg, Ogre::Real rotation, Ogre::String materialname, Ogre::String normalname) { #if 0 Ogre::ManualObject *mo = gEnv->ogreSceneManager->createManualObject(); String oname = mo->getName(); SceneNode *mo_node = terrain_decals_snode->createChildSceneNode(); mo->begin(materialname, Ogre::RenderOperation::OT_TRIANGLE_LIST); AxisAlignedBox *aab=new AxisAlignedBox(); float uTile = 1, vTile = 1; Vector3 normal = Vector3(0,1,0); // UP int offset = 0; float ground_dist = 0.001f; Ogre::Vector3 vX = normal.perpendicular(); Ogre::Vector3 vY = normal.crossProduct(vX); Ogre::Vector3 delta1 = size.x / numSeg.x * vX; Ogre::Vector3 delta2 = size.y / numSeg.y * vY; // build one corner of the square Ogre::Vector3 orig = -0.5*size.x*vX - 0.5*size.y*vY; for (int i1 = 0; i1<=numSeg.x; i1++) for (int i2 = 0; i2<=numSeg.y; i2++) { Vector3 pos = orig+i1*delta1+i2*delta2 + position; pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_dist; mo->position(pos); aab->merge(pos); mo->textureCoord(i1/(Ogre::Real)numSeg.x*uTile, i2/(Ogre::Real)numSeg.y*vTile); mo->normal(normal); } bool reverse = false; if (delta1.crossProduct(delta2).dotProduct(normal)>0) reverse= true; for (int n1 = 0; n1<numSeg.x; n1++) { for (int n2 = 0; n2<numSeg.y; n2++) { if (reverse) { mo->index(offset+0); mo->index(offset+(numSeg.y+1)); mo->index(offset+1); mo->index(offset+1); mo->index(offset+(numSeg.y+1)); mo->index(offset+(numSeg.y+1)+1); } else { mo->index(offset+0); mo->index(offset+1); mo->index(offset+(numSeg.y+1)); mo->index(offset+1); mo->index(offset+(numSeg.y+1)+1); mo->index(offset+(numSeg.y+1)); } offset++; } offset++; } offset+=numSeg.y+1; mo->end(); mo->setBoundingBox(*aab); // some optimizations mo->setCastShadows(false); mo->setDynamic(false); delete(aab); MeshPtr mesh = mo->convertToMesh(oname+"_mesh"); // build edgelist mesh->buildEdgeList(); // remove the manualobject again, since we dont need it anymore gEnv->ogreSceneManager->destroyManualObject(mo); unsigned short src, dest; if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) { mesh->buildTangentVectors(VES_TANGENT, src, dest); } Entity *ent = gEnv->ogreSceneManager->createEntity(oname+"_ent", oname+"_mesh"); mo_node->attachObject(ent); mo_node->setVisible(true); //mo_node->showBoundingBox(true); mo_node->setPosition(Vector3::ZERO); //(position.x, 0, position.z)); // RTSS //Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(materialname, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME); //Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, materialname); RTSSgenerateShadersForMaterial(materialname, normalname); #endif return 0; }
int DecalManager::addTerrainSplineDecal(Ogre::SimpleSpline *spline, float width, Ogre::Vector2 numSeg, Ogre::Vector2 uvSeg, Ogre::String materialname, float ground_offset, Ogre::String export_fn, bool debug) { #if 0 Ogre::ManualObject *mo = gEnv->ogreSceneManager->createManualObject(); String oname = mo->getName(); SceneNode *mo_node = terrain_decals_snode->createChildSceneNode(); mo->begin(materialname, Ogre::RenderOperation::OT_TRIANGLE_LIST); AxisAlignedBox *aab=new AxisAlignedBox(); int offset = 0; // how width is the road? float delta_width = width / numSeg.x; float steps_len = 1.0f / numSeg.x; for (int l = 0; l<=numSeg.x; l++) { // get current position on that spline Vector3 pos_cur = spline->interpolate(steps_len * (float)l); Vector3 pos_next = spline->interpolate(steps_len * (float)(l + 1)); Ogre::Vector3 direction = (pos_next - pos_cur); if (l == numSeg.x) { // last segment uses previous position pos_next = spline->interpolate(steps_len * (float)(l - 1)); direction = (pos_cur - pos_next); } for (int w = 0; w<=numSeg.y; w++) { // build vector for the width Vector3 wn = direction.normalisedCopy().crossProduct(Vector3::UNIT_Y); // calculate the offset, spline in the middle Vector3 offset = (-0.5 * wn * width) + (w/numSeg.y) * wn * width; // push everything together Ogre::Vector3 pos = pos_cur + offset; // get ground height there pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_offset; // add the position to the mesh mo->position(pos); aab->merge(pos); mo->textureCoord(l/(Ogre::Real)numSeg.x*uvSeg.x, w/(Ogre::Real)numSeg.y*uvSeg.y); mo->normal(Vector3::UNIT_Y); } } bool reverse = false; for (int n1 = 0; n1<numSeg.x; n1++) { for (int n2 = 0; n2<numSeg.y; n2++) { if (reverse) { mo->index(offset+0); mo->index(offset+(numSeg.y+1)); mo->index(offset+1); mo->index(offset+1); mo->index(offset+(numSeg.y+1)); mo->index(offset+(numSeg.y+1)+1); } else { mo->index(offset+0); mo->index(offset+1); mo->index(offset+(numSeg.y+1)); mo->index(offset+1); mo->index(offset+(numSeg.y+1)+1); mo->index(offset+(numSeg.y+1)); } offset++; } offset++; } offset+=numSeg.y+1; mo->end(); mo->setBoundingBox(*aab); // some optimizations mo->setCastShadows(false); mo->setDynamic(false); delete(aab); MeshPtr mesh = mo->convertToMesh(oname+"_mesh"); // build edgelist mesh->buildEdgeList(); // remove the manualobject again, since we dont need it anymore gEnv->ogreSceneManager->destroyManualObject(mo); unsigned short src, dest; if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) { mesh->buildTangentVectors(VES_TANGENT, src, dest); } Entity *ent = gEnv->ogreSceneManager->createEntity(oname+"_ent", oname+"_mesh"); mo_node->attachObject(ent); mo_node->setVisible(true); //mo_node->showBoundingBox(true); mo_node->setPosition(Vector3::ZERO); //(position.x, 0, position.z)); if (!export_fn.empty()) { MeshSerializer *ms = new MeshSerializer(); ms->exportMesh(mesh.get(), export_fn); LOG("spline mesh exported as " + export_fn); delete(ms); } // TBD: RTSS //Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(materialname, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME); //Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, materialname); RTSSgenerateShadersForMaterial(materialname, ""); #endif return 0; }
//------------------------------------------------------------------------------------- void TutorialApplication::createScene(void) { // Set the scene's ambient light mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f)); // Create an Entity Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "templeTest111.mesh"); b= ogreHead->getBoundingBox(); Ogre::Vector3 t= b.getCenter(); Ogre::Vector3 dim = b.getSize(); // Create a SceneNode and attach the Entity to it Ogre::SceneNode* headNode1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode1"); Ogre::SceneNode* headNode2 = headNode1->createChildSceneNode("HeadNode2",Ogre::Vector3(-1*t.x,-1*t.y,-1*t.z)); headNode2->attachObject(ogreHead); //headNode1->scale(0.15,0.15,0.15); //Create a Light and set its position Ogre::Light* light = mSceneMgr->createLight("MainLight"); light->setPosition(0.0f, 10000.0f, 0.0f); //create skybox. mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); //create arrow /* Ogre::Entity* arrow = mSceneMgr->createEntity("arrow", "arrow.mesh"); Ogre::SceneNode* arrowNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("arrowNode"); arrowNode->attachObject(arrow); arrowNode->translate(4000,4000,0); arrowNode->scale(50,1,100); */ // Assuming scene_mgr is your SceneManager. Ogre::ManualObject * circle = mSceneMgr->createManualObject("circle"); float const radius = 7; float const accuracy = 35; circle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP); unsigned point_index = 0; for(float theta = 0; theta <= 2 * Ogre::Math::PI; theta += Ogre::Math::PI / accuracy) { circle->position(radius * cos(theta), 0, radius * sin(theta)); circle->index(point_index++); } circle->index(0);// Rejoins the last point to the first. circle->end(); circleNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("circleNode"); circleNode->attachObject(circle); circleNode->scale(100,1,100); //circleNode->translate(4000,-4000,0); mCamera->setOrthoWindow(dim.x,dim.z); mWindow->resize(500+700,500*dim.z/dim.x); winsize.x = 500; winsize.y = mWindow->getHeight(); mCamera->setAspectRatio(dim.x/dim.z); mCamera2->setAspectRatio(700.0/mWindow->getHeight()); mCamera2->setPosition(4000,(-dim.y/2)+1000,0); mCamera2->lookAt(4000,(-dim.y/2)+1000,-1); }
// funcion donde se coloca lo que se desea desplegar. void createScene(){ _sceneManager->setAmbientLight(Ogre::ColourValue(0.2,0.2,0.2)); _sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); // LUZ Ogre::Light* LuzPuntual01 = _sceneManager->createLight("Luz01"); LuzPuntual01->setType(Ogre::Light::LT_DIRECTIONAL); LuzPuntual01->setDiffuseColour(1.0,1.0,1.0); LuzPuntual01->setDirection(Ogre::Vector3( 1, -1, -1 )); Ogre::Light* LuzPuntual02 = _sceneManager->createLight("Luz02"); LuzPuntual02->setType(Ogre::Light::LT_DIRECTIONAL); LuzPuntual02->setDiffuseColour(1.0,1.0,1.0); LuzPuntual02->setDirection(Ogre::Vector3( -1, -1, -1 )); //Chasis Carro _nodeChasisCarro = _sceneManager->createSceneNode("ChasisCarro"); _sceneManager->getRootSceneNode()->addChild(_nodeChasisCarro); Ogre::Entity* _entChasisCarro = _sceneManager->createEntity("ChasisCarro", "chasisCarro.mesh"); _nodeChasisCarro->attachObject(_entChasisCarro); /* Ruedas Izquierdas */ _nodeRuedaSimple0 = _sceneManager->createSceneNode("RuedaSimple0"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple0); // _nodeRuedaSimple00 = _nodeRuedaSimple0->createChildSceneNode("RuedaSimple00"); // _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple00); Ogre::Entity* _entRuedaSimple0 = _sceneManager->createEntity("RuedaSimple0", "RuedaDetallada.mesh"); _nodeRuedaSimple0->attachObject(_entRuedaSimple0); // _nodeRuedaSimple00->attachObject(_entRuedaSimple0); _nodeRuedaSimple0->translate(9,3,5); _nodeRuedaSimple2 = _sceneManager->createSceneNode("RuedaSimple2"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple2); // _nodeRuedaSimple22 = _nodeRuedaSimple2->createChildSceneNode("RuedaSimple22"); // _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple22); Ogre::Entity* _entRuedaSimple2 = _sceneManager->createEntity("RuedaSimple2", "RuedaDetallada.mesh"); _nodeRuedaSimple2->attachObject(_entRuedaSimple2); // _nodeRuedaSimple22->attachObject(_entRuedaSimple2); _nodeRuedaSimple2->translate(9,3,-5); /* Ruedas Derechas */ _nodeRuedaSimple1 = _sceneManager->createSceneNode("RuedaSimple1"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple1); // _nodeRuedaSimple11 = _nodeRuedaSimple1->createChildSceneNode("RuedaSimple11"); // _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple11); Ogre::Entity* _entRuedaSimple1 = _sceneManager->createEntity("RuedaSimple1", "RuedaDetallada.mesh"); _nodeRuedaSimple1->attachObject(_entRuedaSimple1); // _nodeRuedaSimple11->attachObject(_entRuedaSimple1); _nodeRuedaSimple1->translate(-7,3,5); _nodeRuedaSimple3 = _sceneManager->createSceneNode("RuedaSimple3"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple3); // _nodeRuedaSimple33 = _nodeRuedaSimple3->createChildSceneNode("RuedaSimple33"); //_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple33); Ogre::Entity* _entRuedaSimple3 = _sceneManager->createEntity("RuedaSimple3", "RuedaDetallada.mesh"); _nodeRuedaSimple3->attachObject(_entRuedaSimple3); //_nodeRuedaSimple33->attachObject(_entRuedaSimple3); _nodeRuedaSimple3->translate(-7,3,-5); /* ALA DERECHA INFERIOR Se crea el nodo padre de la nave llamado eje */ eje = _sceneManager->getRootSceneNode()->createChildSceneNode("eje"); padreDI = eje->createChildSceneNode("padreDI"); Ogre::ManualObject* alad = _sceneManager->createManualObject("alad"); alad->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); alad->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); alad->position(4.0, -0.5, 0.0); alad->position(15.0, -0.5, 0.0); alad->position(15.0, 0.0, 0.0); alad->position(5.0, 0.0, 0.0); alad->index(0); alad->index(1); alad->index(2); alad->index(3); alad->index(0); alad->end(); padreDI->attachObject(alad); Ogre::ManualObject* alad2 = _sceneManager->createManualObject("alad2"); alad2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); alad2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); alad2->position(5.0, 0.0, 0.0); alad2->position(15.0, 0.0, 0.0); alad2->position(14.0, 0.0, -3.0); alad2->position(5.0, 0.0, -4.0); alad2->index(0); alad2->index(1); alad2->index(2); alad2->index(3); alad2->index(0); alad2->end(); padreDI->attachObject(alad2); /* ALA DERECHA SUPERIOR */ padreDS = eje->createChildSceneNode("padreDS"); Ogre::ManualObject* aladS = _sceneManager->createManualObject("aladS"); aladS->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladS->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); aladS->position(4.0, 0.0, 0.0); aladS->position(15.0, 0.0, 0.0); aladS->position(15.0, 0.5, 0.0); aladS->position(5.0, 0.5, 0.0); aladS->index(0); aladS->index(1); aladS->index(2); aladS->index(3); aladS->index(0); aladS->end(); padreDS->attachObject(aladS); Ogre::ManualObject* aladS2 = _sceneManager->createManualObject("aladS2"); aladS2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladS2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); aladS2->position(5.0, 0.5, 0.0); aladS2->position(15.0, 0.5, 0.0); aladS2->position(14.0, 0.5, -3.0); aladS2->position(5.0, 0.5, -3.0); aladS2->index(0); aladS2->index(1); aladS2->index(2); aladS2->index(3); aladS2->index(0); aladS2->end(); padreDS->attachObject(aladS2); /* ALA IZQUIERDA INFERIOR */ padreII = eje->createChildSceneNode("padreII"); Ogre::ManualObject* aladI = _sceneManager->createManualObject("aladI"); aladI->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladI->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); aladI->position(-15.0, -0.5, 0.0); aladI->position(5.0, -0.5, 0.0); aladI->position(-5.0, 0.0, 0.0); aladI->position(-15.0, 0.0, 0.0); aladI->index(0); aladI->index(1); aladI->index(2); aladI->index(3); aladI->index(0); aladI->end(); padreII->attachObject(aladI); Ogre::ManualObject* aladI2 = _sceneManager->createManualObject("aladI2"); aladI2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladI2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); aladI2->position(-15.0, 0.0, 0.0); aladI2->position(-5.0, 0.0, 0.0); aladI2->position(-5.0, 0.0, -4.0); aladI2->position(-14.0, 0.0, -3.0); aladI2->index(0); aladI2->index(1); aladI2->index(2); aladI2->index(3); aladI2->index(0); aladI2->end(); padreII->attachObject(aladI2); /* ALA IZQUIERDA SUPERIOR */ padreIS = eje->createChildSceneNode("padreIS"); Ogre::ManualObject* aladIS = _sceneManager->createManualObject("aladIS"); aladIS->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladIS->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); aladIS->position(-15.0, 0.0, 0.0); aladIS->position(5.0, 0.0, 0.0); aladIS->position(-5.0, 0.5, 0.0); aladIS->position(-15.0, 0.5, 0.0); aladIS->index(0); aladIS->index(1); aladIS->index(2); aladIS->index(3); aladIS->index(0); aladIS->end(); padreIS->attachObject(aladIS); Ogre::ManualObject* aladIS2 = _sceneManager->createManualObject("aladIS2"); aladIS2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladIS2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); aladIS2->position(-15.0, 0.5, 0.0); aladIS2->position(-5.0, 0.5, 0.0); aladIS2->position(-5.0, 0.5, -3.0); aladIS2->position(-14.0, 0.5, -2.0); aladIS2->index(0); aladIS2->index(1); aladIS2->index(2); aladIS2->index(3); aladIS2->index(0); aladIS2->end(); padreIS->attachObject(aladIS2); /* Rotaciones de las alas */ eje->scale(2.5,2.5,2.5); eje->translate(0,5,0); eje->yaw(Ogre::Degree(180)); /* Trasladar las alas */ padreIS->translate(4,0,0); padreDS->translate(-4,0,0); padreDI->translate(-4,0,0); padreII->translate(4,0,0); eje->scale(0.1,0.1,0.1); //BordePista Ogre::SceneNode* _nodeBPista = _sceneManager->createSceneNode("BordePista"); _sceneManager->getRootSceneNode()->addChild(_nodeBPista); Ogre::Entity* _entBPista = _sceneManager->createEntity("BordePista", "bordePista02.mesh"); _nodeBPista->attachObject(_entBPista); _entBPista->setMaterialName("Examples/pared"); //PisoObstaculo Ogre::SceneNode* _nodePObstaculo = _sceneManager->createSceneNode("PistaObstaculo"); _sceneManager->getRootSceneNode()->addChild(_nodePObstaculo); Ogre::Entity* _entPObstaculo = _sceneManager->createEntity("PistaObstaculo", "pisoObstaculo02.mesh"); _nodePObstaculo->attachObject(_entPObstaculo); //PisoNOObstaculo Ogre::SceneNode* _nodePNObstaculo = _sceneManager->createSceneNode("PistaNoObstaculo"); _sceneManager->getRootSceneNode()->addChild(_nodePNObstaculo); Ogre::Entity* _entPNOObstaculo = _sceneManager->createEntity("PistaNoObstaculo", "pisoNoObstaculo02.mesh"); _nodePNObstaculo->attachObject(_entPNOObstaculo); _entPNOObstaculo->setMaterialName("Examples/piso"); //PosterInicioFinal Ogre::SceneNode* _nodePoster = _sceneManager->createSceneNode("PosterInicioFinal"); _sceneManager->getRootSceneNode()->addChild(_nodePoster); Ogre::Entity* _entPoster = _sceneManager->createEntity("PosterInicioFinal", "posterInicioFinal02.mesh"); _nodePoster->attachObject(_entPoster); //BanderaInicial Ogre::SceneNode* _nodeBInicial = _sceneManager->createSceneNode("BanderaInicial"); _sceneManager->getRootSceneNode()->addChild(_nodeBInicial); Ogre::Entity* _entBanderaI = _sceneManager->createEntity("BanderaInicial", "banderaInicial02.mesh"); _nodeBInicial->attachObject(_entBanderaI); //BanderaFinal Ogre::SceneNode* _nodeBFinal = _sceneManager->createSceneNode("BanderaFinal"); _sceneManager->getRootSceneNode()->addChild(_nodeBFinal); Ogre::Entity* _entBanderaF = _sceneManager->createEntity("BanderaFinal", "banderaFinal.mesh"); _nodeBFinal->attachObject(_entBanderaF); _sceneManager->setSkyDome(true,"Examples/cielo",5,8); }
void AssetLoader::readModel(Ogre::SceneManager* sceneMgr, Ogre::SceneNode* scnNode, const aiScene* scene, aiNode* nd) { for (size_t n = 0; n < nd->mNumChildren; n++) { aiNode* cnd = nd->mChildren[n]; Ogre::SceneNode* cnode = createChildSceneNodeWithTransform(scnNode, cnd); for (size_t i = 0; i < cnd->mNumMeshes; i++) { aiMesh* m = scene->mMeshes[cnd->mMeshes[i]]; aiMaterial* mat = scene->mMaterials[m->mMaterialIndex]; std::string nodeName = getFullPathName(cnd); Ogre::MaterialPtr omat = createMaterial(Ogre::String(nodeName), m->mMaterialIndex, mat); aiVector3D* vec = m->mVertices; aiVector3D* norm = m->mNormals; aiVector3D* uv = m->mTextureCoords[0]; aiColor4D* vcol = NULL; if (m->HasVertexColors(0)) vcol = m->mColors[0]; // 頂点情報の読み込み Ogre::AxisAlignedBox aab; Ogre::ManualObject* mobj = new Ogre::ManualObject(nodeName+"_MObj"); mobj->begin(omat->getName()); //mobj->begin("Ogre/Skin"); for (size_t n = 0; n < m->mNumVertices; n ++) { Ogre::Vector3 position(vec->x, vec->y, vec->z); aab.merge(position); mobj->position(vec->x, vec->y, vec->z); vec++; mobj->normal(norm->x, norm->y, norm->z); norm++; if (uv) { mobj->textureCoord(uv->x, uv->y); uv++; } if (vcol) { mobj->colour(vcol->r, vcol->g, vcol->b, vcol->a); vcol++; } } // ポリゴンの構築 for (size_t n = 0; n < m->mNumFaces; n++) { aiFace* face = &m->mFaces[n]; for (size_t k = 0; k < face->mNumIndices; k++) { mobj->index(face->mIndices[k]); } } mobj->end(); mobj->setBoundingBox(aab); Ogre::String meshName(nodeName+"_Mesh"); mobj->convertToMesh(meshName); delete mobj; Ogre::String entityName(nodeName+"_Entity"); std::cout << "entity: " << entityName << std::endl; Ogre::Entity* ent = sceneMgr->createEntity(entityName, meshName); cnode->attachObject(ent); } readModel(sceneMgr, cnode, scene, cnd); } }
Ogre::MeshPtr Loader::getMeshFromMdl(unsigned int id){ if(!models[id].isNull()){ return models[id]; } std::string name = "mesh"+Utils::toStr(id); std::ifstream stream; stream.open(("Models/"+name+".mdl").c_str(),std::ios::in|std::ios::binary); Ogre::ManualObject* obj = OgreFramework::getSingletonPtr()->m_pSceneMgr->createManualObject(); unsigned int texture, normalmap, vertices, indices; short endian; stream.read((char*)&endian,sizeof(short)); stream.read((char*)&texture,sizeof(unsigned int)); stream.read((char*)&normalmap,sizeof(unsigned int)); stream.read((char*)&vertices,sizeof(unsigned int)); stream.read((char*)&indices,sizeof(unsigned int)); float bounds[6];//{minX,minY,minZ,maxX,maxY,maxZ} stream.read((char*)bounds,sizeof(float)*6); std::string textureFName,normalMapFName; for(int i=0;i<texture;i++){ char c; stream.read((char*)&c,sizeof(char)); textureFName+=c; } if(normalmap>0){ for(int i=0;i<texture;i++){ char c; stream.read((char*)&c,sizeof(char)); normalMapFName+=c; } } if(normalmap>0) obj->begin("NormalMapTexture"); else obj->begin("PlainTexture"); float * arrayV = new float[vertices*(3+3+2)]; stream.read((char*)arrayV,sizeof(float)*(3+3+2)*vertices);//should also work - automatically grab ALL vertex data to array in one operation :) C++ is great for(int i=0;i<vertices;i++){ int ptr = i*(3+3+2); obj->position(arrayV[ptr],arrayV[ptr+1],arrayV[ptr+2]); obj->normal(arrayV[ptr+3],arrayV[ptr+4],arrayV[ptr+5]); obj->textureCoord(arrayV[ptr+6],arrayV[ptr+7]); } delete [] arrayV; unsigned int * arrayI = new unsigned int[indices]; stream.read((char*)arrayI,sizeof(unsigned int)*indices); for(int i=0;i<indices;i++){ obj->index(arrayI[i]); } delete [] arrayI; obj->end(); /*if(normalmap>0){ obj->setMaterialName("NormalMapTexture"); obj->addTextureAlias("normalmap",normalMapFName); } else{ obj->setMaterialName("OneTexture"); } obj->addTextureAlias("textura",textureFName);*/ OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(obj); Ogre::MeshPtr mesh = obj->convertToMesh(name); mesh->getSubMesh(0)->addTextureAlias("textura",textureFName);//TODO normalmap return mesh; /*Ogre::MeshPtr meshM = Ogre::MeshManager::getSingletonPtr()->createManual(name,"General"); unsigned int texture, normalmap, vertices, indices; short endian; stream.read((char*)&endian,sizeof(short)); stream.read((char*)&texture,sizeof(unsigned int)); stream.read((char*)&normalmap,sizeof(unsigned int)); stream.read((char*)&vertices,sizeof(unsigned int)); stream.read((char*)&indices,sizeof(unsigned int)); float bounds[6];//{minX,minY,minZ,maxX,maxY,maxZ} stream.read((char*)bounds,sizeof(float)*6); std::string textureFName,normalMapFName; for(int i=0;i<texture;i++){ char c; stream.read((char*)&c,sizeof(char)); textureFName+=c; } if(normalmap>0){ for(int i=0;i<texture;i++){ char c; stream.read((char*)&c,sizeof(char)); normalMapFName+=c; } } Ogre::SubMesh* mesh = meshM->createSubMesh(); // We first create a VertexData Ogre::VertexData* data = new Ogre::VertexData(); // Then, we link it to our Mesh/SubMesh : #ifdef SHARED_GEOMETRY meshM->sharedVertexData = data; #else mesh->useSharedVertices = false; // This value is 'true' by default mesh->vertexData = data; #endif // We have to provide the number of verteices we'll put into this Mesh/SubMesh data->vertexCount = vertices; // Then we can create our VertexDeclaration Ogre::VertexDeclaration* decl = data->vertexDeclaration; size_t offset = 0; decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION); offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3); decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL); offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3); decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES); offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);//you can't animate because one buffer Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(0), // This value is the size of a vertex in memory vertices, // The number of vertices you'll put into this buffer Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY // Properties ); float * arrayV = new float[vertices*(3+3+2)]; stream.read((char*)arrayV,sizeof(float)*(3+3+2)*vertices);//should also work - automatically grab ALL vertex data to array in one operation :) C++ is great vbuf->writeData(0, vbuf->getSizeInBytes(), arrayV, true); delete [] arrayV; // "data" is the Ogre::VertexData* we created before Ogre::VertexBufferBinding* bind = data->vertexBufferBinding; bind->setBinding(0, vbuf); Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer( Ogre::HardwareIndexBuffer::IT_16BIT, // You can use several different value types here indices, // The number of indices you'll put in that buffer Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY // Properties ); mesh->indexData->indexBuffer = ibuf; // The pointer to the index buffer mesh->indexData->indexCount = indices; // The number of indices we'll use mesh->indexData->indexStart = 0; unsigned int * arrayI = new unsigned int[indices]; stream.read((char*)arrayI,sizeof(unsigned int)*indices); ibuf->writeData(0, ibuf->getSizeInBytes(), arrayI, true); delete [] arrayI; if(normalmap>0){ mesh->setMaterialName("NormalMapTexture"); mesh->addTextureAlias("normalmap",normalMapFName); } else{ //mesh->setMaterialName("OneTexture"); } mesh->addTextureAlias("textura",textureFName); meshM->_setBounds(Ogre::AxisAlignedBox(bounds[0],bounds[1],bounds[2],bounds[3],bounds[4],bounds[5])); meshM->_setBoundingSphereRadius(std::max(bounds[3]-bounds[0], std::max(bounds[4]-bounds[1], bounds[5]-bounds[2]))/2.0f); meshM->load();//TODO need? return meshM;*/ }