//------------------------------------------------------------------------------------- void HelloOGRE::createScene(void) { using namespace Ogre; Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "7.mesh"); //Ogre::Entity* cube = mSceneMgr->createEntity("cube","abc.mesh"); Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Head"); headNode->attachObject(ogreHead); ManualObject * axis = mSceneMgr->createManualObject("Axis"); axis->begin("line",Ogre::RenderOperation::OperationType::OT_LINE_LIST); axis->position(0.0f,0.0f,0.0f); axis->position(20.0f,0.0f,0.0f); axis->end(); headNode->attachObject(axis); // Set ambient light mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0,0.5, 0.0)); mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); mSceneMgr->setSkyDome(true,"Examples/Rockwall"); //mSceneMgr->setSkyPlane(true,"Example/" // Create a light Ogre::Light* l = mSceneMgr->createLight("MainLight"); l->setDiffuseColour(0.0f,1.0f,0.0f); l->setPosition(20,80,50); l->setDirection(0.0,0.0,0.0); }
MeshPtr ShowNormalsGenerator::buildMesh(const std::string& name, const String& group) const { SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second; ManualObject* mo = buildManualObject(); Ogre::MeshPtr mesh = mo->convertToMesh(name, group); sceneMgr->destroyManualObject(mo); return mesh; }
void DebugDisplay::drawPoint( Vector3 p ) { oht_assert_threadmodel(ThrMdl_Main); ManualObject * pManObj = _pSceneManager->createManualObject(); rollbackTransforms(p); pManObj->begin(getCurrentMaterial(), RenderOperation::OT_POINT_LIST); pManObj->position(p); pManObj->end(); _pScNode->attachObject(pManObj); }
void OgreAppLogic::createScene(void) { // setup some basic lighting for our scene mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); // make a cube to bounce around Entity *ent1; SceneNode *boxNode; ManualObject *cmo = createCubeMesh("manual", ""); cmo->convertToMesh("cube"); ent1 = mSceneMgr->createEntity("Cube", "cube.mesh"); ent1->setCastShadows(true); boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); boxNode->attachObject(ent1); boxNode->setScale(Vector3(0.1,0.1,0.1)); // for some reason converttomesh multiplied dimensions by 10 mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); mSceneMgr->createLight()->setPosition(20, 80, 50); // create a floor mesh resource MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Plane(Vector3::UNIT_Y, -30), 1000, 1000, 10, 10, true, 1, 8, 8, Vector3::UNIT_Z); // create a floor entity, give it a material, and place it at the origin Entity* floor = mSceneMgr->createEntity("Floor", "floor"); floor->setMaterialName("Examples/BumpyMetal"); mSceneMgr->getRootSceneNode()->attachObject(floor); mSceneMgr->getRootSceneNode()->attachObject(mSceneMgr->createEntity("Head", "ogrehead.mesh")); mSceneMgr->setSkyBox(true, "Examples/GridSkyBox"); Ogre::Entity* ent = mSceneMgr->createEntity("Sinbad.mesh"); //1x1_cube.mesh //Sinbad.mesh //axes.mesh mObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("cube"); mObjectNode->setOrientation(Quaternion(Degree(90.f), Vector3::UNIT_X)); Ogre::Real scale = 22; mObjectNode->setPosition(10, 10, 10*scale); mObjectNode->setScale(Ogre::Vector3::UNIT_SCALE*scale); mObjectNode->attachObject(ent); mObjectNode->setVisible(true); // create swords and attach them to sinbad Ogre::Entity* sword1 = mSceneMgr->createEntity("SinbadSword1", "Sword.mesh"); Ogre::Entity* sword2 = mSceneMgr->createEntity("SinbadSword2", "Sword.mesh"); ent->attachObjectToBone("Sheath.L", sword1); ent->attachObjectToBone("Sheath.R", sword2); mAnimState = ent->getAnimationState("Dance"); mAnimState->setLoop(true); mAnimState->setEnabled(true); }
void setupScene() { mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); Camera *cam = mSceneMgr->createCamera("Camera"); Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); Entity *ent; mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25)); mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE ); // EN:: make a cube to bounce around // BR:: cria um cubo pra quicar ManualObject *cmo = createCubeMesh("manual", ""); cmo->convertToMesh("cube"); ent = mSceneMgr->createEntity("Cube", "cube.mesh"); ent->setCastShadows(true); boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); boxNode->attachObject(ent); boxNode->setScale(Vector3(0.1,0.1,0.1)); // EN:: make a rock wall on the floor // BR:: adiciona piso de pedra no chão Plane plane(Vector3::UNIT_Y, 0); MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z); ent = mSceneMgr->createEntity("GroundEntity", "ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); ent->setMaterialName("Examples/Rockwall"); ent->setCastShadows(false); // EN:: make a light to see stuff with // BR:: adiciona uma iluminação Light *light = mSceneMgr->createLight("Light1"); light->setType(Light::LT_POINT); light->setPosition(Vector3(250, 150, 250)); light->setDiffuseColour(ColourValue::White); light->setSpecularColour(ColourValue::White); // EN:: Create the scene node // BR:: cria o SceneNode (nó da cena) SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Vector3(-200, 100, 200)); node->yaw(Degree(-45)); node->attachObject(cam); }
void Application::createScene() { //mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); In create cameras and viewports //Camera *cam = mSceneMgr->createCamera("Camera"); //Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); // Entity *ent; mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25)); mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE ); // make a cube to bounce around ManualObject *cmo = createCubeMesh("manual", ""); cmo->convertToMesh("cube"); ent = mSceneMgr->createEntity("Cube", "cube.mesh"); ent->setCastShadows(true); boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); boxNode->attachObject(ent); boxNode->setScale(Vector3(0.1,0.1,0.1)); // for some reason converttomesh multiplied dimensions by 10 // // // make a rock wall on the floor Plane plane(Vector3::UNIT_Y, 0); MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z); ent = mSceneMgr->createEntity("GroundEntity", "ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); ent->setMaterialName("Examples/Rockwall"); ent->setCastShadows(false); // // // make a light to see stuff with Light *light = mSceneMgr->createLight("Light1"); light->setType(Light::LT_POINT); light->setPosition(Vector3(250, 150, 250)); light->setDiffuseColour(ColourValue::White); light->setSpecularColour(ColourValue::White); // // // Create the scene node SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Vector3(-200, 100, 200)); node->yaw(Degree(-45)); //node->attachObject(cam); //node->attachObject(mCamera); }
void DebugDisplay::drawTriangle( Vector3 t0, Vector3 t1, Vector3 t2 ) { oht_assert_threadmodel(ThrMdl_Main); ManualObject * pManObj = _pSceneManager->createManualObject(); rollbackTransforms(t0); rollbackTransforms(t1); rollbackTransforms(t2); pManObj->begin(getCurrentMaterial(), RenderOperation::OT_TRIANGLE_LIST); pManObj->position(t0); pManObj->position(t1); pManObj->position(t2); pManObj->end(); _pScNode->attachObject(pManObj); }
Entity* OctreeNode::getOctreeGrid(SceneManager *sceneManager) { if (!mOctreeGrid) { mGridPositionCount = 0; mNodeI++; ManualObject* manual = sceneManager->createManualObject(); manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); manual->colour((Real)1.0, (Real)0.0, (Real)0.0); buildOctreeGridLines(manual); manual->end(); StringUtil::StrStreamType meshName; meshName << "VolumeOctreeGridMesh" << mNodeI; manual->convertToMesh(meshName.str()); StringUtil::StrStreamType entityName; entityName << "VolumeOctreeGrid" << mNodeI; mOctreeGrid = sceneManager->createEntity(entityName.str(), meshName.str()); } return mOctreeGrid; }
void App::CreateRacingLine() { //void ROADPATCH::AddRacinglineScenenode(SCENENODE * node, ROADPATCH * nextpatch, ManualObject* m = mSceneMgr->createManualObject(); m->begin("track/Racingline", RenderOperation::OT_TRIANGLE_LIST); int ii = 0; const std::list <ROADSTRIP>& roads = pGame->track.GetRoadList(); for (std::list <ROADSTRIP>::const_iterator it = roads.begin(); it != roads.end(); ++it) { const std::list <ROADPATCH>& pats = (*it).GetPatchList(); for (std::list <ROADPATCH>::const_iterator i = pats.begin(); i != pats.end(); ++i) { const VERTEXARRAY* a = &((*i).racingline_vertexarray); if (!a) continue; int verts = a->vertices.size(); if (verts == 0) continue; int faces = a->faces.size(); for (int v = 0; v < verts; v += 3) m->position(a->vertices[v+0], a->vertices[v+2], -a->vertices[v+1]); for (int f = 0; f < faces; ++f) m->index(ii + a->faces[f]); ii += verts/3; } } m->setCastShadows(false); m->end(); hud->ndLine = mSceneMgr->getRootSceneNode()->createChildSceneNode(); hud->ndLine->attachObject(m); //ndLine->setVisible(pSet->racingline); }
void MeshWithoutIndexDataTests::testCreateLineList() { ManualObject* lineList = OGRE_NEW ManualObject("line"); lineList->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); lineList->position(0, 50, 0); lineList->position(50, 100, 0); lineList->position(50, 50, 0); lineList->position(100, 100, 0); lineList->position(0, 50, 0); lineList->position(50, 50, 0); lineList->end(); String fileName = "lineList.mesh"; MeshPtr lineListMesh = lineList->convertToMesh(fileName); OGRE_DELETE lineList; CPPUNIT_ASSERT(lineListMesh->getNumSubMeshes() == 1); CPPUNIT_ASSERT(lineListMesh->getSubMesh(0)->indexData->indexCount == 0); RenderOperation rop; lineListMesh->getSubMesh(0)->_getRenderOperation(rop); CPPUNIT_ASSERT(rop.useIndexes == false); CPPUNIT_ASSERT(lineListMesh->getSubMesh(0)->vertexData->vertexCount == 6); MeshSerializer meshWriter; meshWriter.exportMesh(lineListMesh.get(), fileName); mMeshMgr->remove( fileName ); ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem"); MeshPtr loadedLineList = mMeshMgr->load(fileName, "General"); remove(fileName.c_str()); CPPUNIT_ASSERT(loadedLineList->getNumSubMeshes() == 1); CPPUNIT_ASSERT(loadedLineList->getSubMesh(0)->indexData->indexCount == 0); loadedLineList->getSubMesh(0)->_getRenderOperation(rop); CPPUNIT_ASSERT(rop.useIndexes == false); CPPUNIT_ASSERT(loadedLineList->getSubMesh(0)->vertexData->vertexCount == 6); mMeshMgr->remove( fileName ); }
// CreatePart mesh //--------------------------------------------------- void CarModel::CreatePart(SceneNode* ndCar, Vector3 vPofs, String sCar2, String sCarI, String sMesh, String sEnt, bool ghost, uint32 visFlags, AxisAlignedBox* bbox, String stMtr, VERTEXARRAY* var, bool bLogInfo) { if (FileExists(sCar2 + sMesh)) { Entity* ent = mSceneMgr->createEntity(sCarI + sEnt, sDirname + sMesh, sCarI); if (bbox) *bbox = ent->getBoundingBox(); if (ghost) { ent->setRenderQueueGroup(RQG_CarGhost); ent->setCastShadows(false); } else if (visFlags == RV_CarGlass) ent->setRenderQueueGroup(RQG_CarGlass); ndCar->attachObject(ent); ent->setVisibilityFlags(visFlags); if (bLogInfo) LogMeshInfo(ent, sDirname + sMesh); } else { ManualObject* mo = pApp->CreateModel(mSceneMgr, stMtr, var, vPofs, false, false, sCarI+sEnt); if (!mo) return; if (bbox) *bbox = mo->getBoundingBox(); if (ghost) { mo->setRenderQueueGroup(RQG_CarGhost); mo->setCastShadows(false); } else if (visFlags == RV_CarGlass) mo->setRenderQueueGroup(RQG_CarGlass); ndCar->attachObject(mo); mo->setVisibilityFlags(visFlags); /** /// save .mesh MeshPtr mpCar = mInter->convertToMesh("Mesh" + sEnt); MeshSerializer* msr = new MeshSerializer(); msr->exportMesh(mpCar.getPointer(), sDirname + sMesh);/**/ } }
ManualObject *Debugging::createPathgridLines(const ESM::Pathgrid *pathgrid) { ManualObject *result = mSceneMgr->createManualObject(); result->begin(PATHGRID_LINE_MATERIAL, RenderOperation::OT_LINE_LIST); for(ESM::Pathgrid::EdgeList::const_iterator it = pathgrid->mEdges.begin(); it != pathgrid->mEdges.end(); ++it) { const ESM::Pathgrid::Edge &edge = *it; const ESM::Pathgrid::Point &p1 = pathgrid->mPoints[edge.mV0], &p2 = pathgrid->mPoints[edge.mV1]; Vector3 direction = (Vector3(p2.mX, p2.mY, p2.mZ) - Vector3(p1.mX, p1.mY, p1.mZ)); Vector3 lineDisplacement = direction.crossProduct(Vector3::UNIT_Z).normalisedCopy(); lineDisplacement = lineDisplacement * POINT_MESH_BASE + Vector3(0, 0, 10); // move lines up a little, so they will be less covered by meshes/landscape result->position(Vector3(p1.mX, p1.mY, p1.mZ) + lineDisplacement); result->position(Vector3(p2.mX, p2.mY, p2.mZ) + lineDisplacement); } result->end(); result->setVisibilityFlags (RV_Debug); return result; }
//--------------------------------------------------------------------- void PFile::addGroup( const Group &group, ManualObject &mo ,const String &sub_name, const String &material_base_name ,const Ogre::Bone *bone ) const { size_t material_index( 0 ); if( group.has_texture ) { material_index = group.texture_index + 1; } String material_name( material_base_name + "/" + Ogre::StringConverter::toString( material_index ) ); const uint16 bone_handle( bone->getHandle() ); const Ogre::Vector3 bone_position( getPosition( bone ) ); size_t index( 0 ); size_t vertex_count( group.num_polygons * 3 ); size_t index_count( vertex_count ); size_t polygon_end_index( group.polygon_start_index + group.num_polygons ); mo.begin( sub_name, material_name, vertex_count, index_count ); for( size_t p( group.polygon_start_index ); p < polygon_end_index; ++p ) { const PolygonDefinition& polygon( m_polygon_definitions[p] ); for( int i(3); i--; ) { uint32 v( group.vertex_start_index +polygon.vertex[i] ) ,n( 0 + polygon.normal[i] ) ,t( group.texture_coordinate_start_index +polygon.vertex[i] ); Ogre::Vector3 pos( m_vertices[ v ] ); mo.position((STATIC_ROTATION * (pos / HRCFile::kDownScaler)) + bone_position); mo.colour( m_vertex_colors[ v ] ); mo.normal( STATIC_ROTATION * m_normals[ n ] ); if( group.has_texture ) { mo.textureCoord(m_texture_coordinates[t]); } mo.bone( index, bone_handle ); mo.index( index++ ); } } mo.end(); }
ManualObject* SnowTerrain::createDebugNormals(Ogre::SceneManager* mSceneMgr) { ManualObject* manual = mSceneMgr->createManualObject("NormalsDebug"); float *heights = getTerrainHeightData(); Vector4 *normals = getTerrainNormalData(); manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); int terrainSize = getTerrain()->getSize(); int terrainWorldSize = getTerrain()->getWorldSize(); for(int z = 0; z < terrainSize; ++z) { for(int x = 0; x < terrainSize; ++x) { int i = ((terrainSize)*(terrainSize) ) - (z+1)*terrainSize + (x+1); Vector3 n = Vector3(normals[i].x, normals[i].y, normals[i].z); float h = heights[i]; Real factor = (Real)terrainSize - 1.0f; Real invFactor = 1.0f / factor; float mScale = terrainWorldSize / (Real)(terrainSize); Real mBase = -terrainWorldSize * 0.5; Vector3 mPos = Ogre::Vector3(terrainWorldSize * 0.5, 0, terrainWorldSize * 0.5); Vector3 worldPos; worldPos.x = x * mScale + mBase + mPos.x; worldPos.y = h + mPos.y; worldPos.z = z * mScale + mBase + mPos.z; // convert back to "normal map" colors (0/1 float instead of -1/1 float, also rgb=>xzy) manual->colour((n.x + 1)*0.5, (n.z + 1)*0.5, (n.y + 1)*0.5); // draw line manual->position(worldPos); manual->position(worldPos + 3*n); //manual->index(i); //manual->index(1); } } manual->end(); //OGRE_FREE(normals); return manual; }
ProceduralManualObject* createProceduralParticleSystem() { particleSystem = static_cast<ProceduralManualObject*> (mSceneMgr->createMovableObject("ParticleGSEntity", ProceduralManualObjectFactory::FACTORY_TYPE_NAME)); particleSystem->setMaterial("Ogre/ParticleGS/Display"); //Generate the geometry that will seed the particle system ManualObject* particleSystemSeed = mSceneMgr->createManualObject("ParticleSeed"); //This needs to be the initial launcher particle particleSystemSeed->begin("Ogre/ParticleGS/Display", RenderOperation::OT_POINT_LIST); particleSystemSeed->position(0,0,0); //Position particleSystemSeed->textureCoord(1); //Timer particleSystemSeed->textureCoord(0); //Type particleSystemSeed->textureCoord(0,0,0); //Velocity particleSystemSeed->end(); //Generate the RenderToBufferObject RenderToVertexBufferSharedPtr r2vbObject = HardwareBufferManager::getSingleton().createRenderToVertexBuffer(); r2vbObject->setRenderToBufferMaterialName("Ogre/ParticleGS/Generate"); //Apply the random texture TexturePtr randomTexture = RandomTools::generateRandomVelocityTexture(); r2vbObject->getRenderToBufferMaterial()->getTechnique(0)->getPass(0)-> getTextureUnitState("RandomTexture")->setTextureName( randomTexture->getName(), randomTexture->getTextureType()); r2vbObject->setOperationType(RenderOperation::OT_POINT_LIST); r2vbObject->setMaxVertexCount(16000); r2vbObject->setResetsEveryUpdate(false); VertexDeclaration* vertexDecl = r2vbObject->getVertexDeclaration(); size_t offset = 0; offset += vertexDecl->addElement(0, offset, VET_FLOAT3, VES_POSITION).getSize(); //Position offset += vertexDecl->addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 0).getSize(); //Timer offset += vertexDecl->addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 1).getSize(); //Type offset += vertexDecl->addElement(0, offset, VET_FLOAT3, VES_TEXTURE_COORDINATES, 2).getSize(); //Velocity //Bind the two together particleSystem->setRenderToVertexBuffer(r2vbObject); particleSystem->setManualObject(particleSystemSeed); //Set bounds AxisAlignedBox aabb; aabb.setMinimum(-100,-100,-100); aabb.setMaximum(100,100,100); particleSystem->setBoundingBox(aabb); return particleSystem; }
void pathDrawerState::dibujaLinea(size_t idFrom, size_t idTo) { ManualObject* manual = _sceneMgr->createManualObject("line_" + to_string(idFrom)); manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); Vector3 aux(vMarcas[idFrom]._nodoMarca->getPosition()); aux.y = _planeRoadNode->getPosition().y + 1; manual->position(aux); //start aux = vMarcas[idTo]._nodoMarca->getPosition(); aux.y = _planeRoadNode->getPosition().y + 1; manual->position(aux); //end manual->end(); _sceneMgr->getRootSceneNode()->attachObject(manual); cout << "nombre entity linea: " << manual->getName() << endl; }
void MeshWithoutIndexDataTests::testCreateLineWithMaterial() { String matName = "lineMat"; MaterialPtr matPtr = MaterialManager::getSingleton().create(matName, "General"); Pass* pass = matPtr->getTechnique(0)->getPass(0); pass->setDiffuse(1.0, 0.1, 0.1, 0); ManualObject* line = OGRE_NEW ManualObject("line"); line->begin(matName, RenderOperation::OT_LINE_LIST); line->position(0, 50, 0); line->position(50, 100, 0); line->end(); String fileName = "lineWithMat.mesh"; MeshPtr lineMesh = line->convertToMesh(fileName); OGRE_DELETE line; CPPUNIT_ASSERT(lineMesh->getNumSubMeshes() == 1); CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->indexData->indexCount == 0); RenderOperation rop; lineMesh->getSubMesh(0)->_getRenderOperation(rop); CPPUNIT_ASSERT(rop.useIndexes == false); CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->vertexData->vertexCount == 2); MeshSerializer meshWriter; meshWriter.exportMesh(lineMesh.get(), fileName); MaterialSerializer matWriter; matWriter.exportMaterial( MaterialManager::getSingleton().getByName(matName), matName + ".material" ); mMeshMgr->remove( fileName ); ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem"); MeshPtr loadedLine = mMeshMgr->load(fileName, "General"); remove(fileName.c_str()); remove((matName + ".material").c_str()); CPPUNIT_ASSERT(loadedLine->getNumSubMeshes() == 1); CPPUNIT_ASSERT(loadedLine->getSubMesh(0)->indexData->indexCount == 0); loadedLine->getSubMesh(0)->_getRenderOperation(rop); CPPUNIT_ASSERT(rop.useIndexes == false); CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->vertexData->vertexCount == 2); mMeshMgr->remove( fileName ); }
Entity* MeshBuilder::generateWithManualObject(SceneManager *sceneManager, const String &name, const String &material) { ManualObject* manual = sceneManager->createManualObject(); manual->begin(material, RenderOperation::OT_TRIANGLE_LIST); for (VecVertex::const_iterator iter = mVertices.begin(); iter != mVertices.end(); ++iter) { manual->position(Vector3(iter->x, iter->y, iter->z)); manual->normal(Vector3(iter->nX, iter->nY, iter->nZ)); } for (VecIndices::const_iterator iter = mIndices.begin(); iter != mIndices.end(); ++iter) { manual->index(*iter); } manual->end(); StringUtil::StrStreamType meshName; meshName << name << "ManualObject"; MeshManager::getSingleton().remove(meshName.str()); manual->convertToMesh(meshName.str()); return sceneManager->createEntity(name, meshName.str()); }
Entity* DualGridGenerator::getDualGrid(SceneManager *sceneManager) { if (!mDualGrid && mDualCells.size() > 0) { ManualObject* manual = sceneManager->createManualObject(); manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); manual->colour((Real)0.0, (Real)1.0, (Real)0.0); manual->estimateVertexCount(mDualCells.size() * 8); manual->estimateIndexCount(mDualCells.size() * 24); uint32 baseIndex = 0; for (VecDualCell::iterator it = mDualCells.begin(); it != mDualCells.end(); ++it) { MeshBuilder::addCubeToManualObject( manual, it->mC0, it->mC1, it->mC2, it->mC3, it->mC4, it->mC5, it->mC6, it->mC7, baseIndex); } manual->end(); mDualGridI++; StringUtil::StrStreamType meshName; meshName << "VolumeDualGridGridMesh" << mDualGridI; manual->convertToMesh(meshName.str()); StringUtil::StrStreamType entityName; entityName << "VolumeDualGrid" << mDualGridI; mDualGrid = sceneManager->createEntity(entityName.str(), meshName.str()); } return mDualGrid; }
void TutorialApplication::createScene(void) { m_SceneMgr->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f)); // Render the bottom grid using lines Ogre::ManualObject *man = m_SceneMgr->createManualObject("grid"); man->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); for (Real i = -GRID_SIZE + GRID_SPACING; i < GRID_SIZE; i += GRID_SPACING) { man->position(i, 0, -GRID_SIZE); man->position(i, 0, GRID_SIZE); man->position(-GRID_SIZE, 0, i); man->position(GRID_SIZE, 0, i); } man->end(); m_SceneMgr->getRootSceneNode()->attachObject(man); // Create the cursor plane ManualObject *plane = m_SceneMgr->createManualObject("basePlane"); plane->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_STRIP); plane->position(0, 0, 0); plane->position(0, 0, CURSOR_SIZE); plane->position(CURSOR_SIZE, 0, 0); plane->position(CURSOR_SIZE, 0, CURSOR_SIZE); plane->end(); m_cursorNode = m_SceneMgr->getRootSceneNode()->createChildSceneNode("cursorNode"); m_cursorNode->attachObject(plane); // Create all possible cones, so they can be shown later m_pointNode = m_SceneMgr->getRootSceneNode()->createChildSceneNode("coneBase"); for (Vector3 coneDir : CONE_CASES) { std::vector<Vector3> seenList; SceneNode *childNode = m_pointNode->createChildSceneNode(); m_coneNodes.push_back(childNode); createCones(nullptr, seenList, childNode, m_pointNode->getPosition(), coneDir); } assert (m_coneNodes.size() == CONE_CASES.size()); m_pointNode->setVisible(false, true); }
void MeshWithoutIndexDataTests::testEdgeList() { String fileName = "testEdgeList.mesh"; ManualObject* line = OGRE_NEW ManualObject("line"); line->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); line->position(0, 50, 0); line->position(50, 100, 0); line->end(); MeshPtr mesh = line->convertToMesh(fileName); OGRE_DELETE line; // whole mesh must not contain index data, for this test CPPUNIT_ASSERT(mesh->getNumSubMeshes() == 1); CPPUNIT_ASSERT(mesh->getSubMesh(0)->indexData->indexCount == 0); mesh->buildEdgeList(); MeshSerializer meshWriter; // if it does not crash here, test is passed meshWriter.exportMesh(mesh.get(), fileName); remove(fileName.c_str()); mMeshMgr->remove( fileName ); }
ManualObject* ShowNormalsGenerator::buildManualObject() const { if (mTriangleBuffer == NULL) OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE, "The input triangle buffer must not be null", "Procedural::ShowNormalsGenerator::buildManualObject()"); SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second; if (sceneMgr == NULL) OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE, "Scene Manager must be set in Root", "Procedural::ShowNormalsGenerator::buildManualObject()"); ManualObject* manual = sceneMgr->createManualObject(); manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST); const std::vector<TriangleBuffer::Vertex>& vertices = mTriangleBuffer->getVertices(); for (std::vector<TriangleBuffer::Vertex>::const_iterator it = vertices.begin(); it!= vertices.end(); ++it) { manual->position(it->mPosition); manual->position(it->mPosition + it->mNormal * mSize); if (mVisualStyle == VS_ARROW) { Vector3 axis2 = it->mNormal.perpendicular(); Vector3 axis3 = it->mNormal.crossProduct(axis2); manual->position(it->mPosition + it->mNormal * mSize); manual->position(it->mPosition + (.8f * it->mNormal + .1f * axis2) * mSize); manual->position(it->mPosition + it->mNormal * mSize); manual->position(it->mPosition + .8f * (it->mNormal - .1f * axis2) * mSize); manual->position(it->mPosition + it->mNormal * mSize); manual->position(it->mPosition + .8f * ( it->mNormal + .1f * axis3)* mSize); manual->position(it->mPosition + it->mNormal * mSize); manual->position(it->mPosition + .8f * (it->mNormal - .1f * axis3)* mSize); } } manual->end(); return manual; }
///--------------------------------------------------------------------------------------------------------------- // Update HUD ///--------------------------------------------------------------------------------------------------------------- void CHud::Update(int carId, float time) { PROFILER.beginBlock("g.hud"); // update HUD elements for all cars that have a viewport (local or replay) //----------------------------------------------------------------------------------- int cnt = std::min(6/**/, (int)app->carModels.size()); // all cars int cntC = std::min(4/**/, cnt - (app->isGhost2nd && !app->bRplPlay ? 1 : 0)); // all vis plr int c; // gui viewport - done once for all if (carId == -1) for (c = 0; c < cntC; ++c) if (app->carModels[c]->eType == CarModel::CT_LOCAL) { // hud rpm,vel float vel=0.f, rpm=0.f, clutch=1.f; int gear=1; GetVals(c,&vel,&rpm,&clutch,&gear); // update all mini pos tri for (int i=0; i < cnt; ++i) UpdRot(c, i, vel, rpm); } /// all minimap car pos-es rot const static Real tc[4][2] = {{0,1}, {1,1}, {0,0}, {1,0}}; const float z = pSet->size_minipos; // tri size if (carId == -1 && moPos) { moPos->beginUpdate(0); const int plr = app->mSplitMgr->mNumViewports; for (int v = 0; v < plr; ++v) // all viewports { const Hud& h = hud[v]; const float sc = pSet->size_minimap * app->mSplitMgr->mDims[v].avgsize; const Vector3& pos = h.ndMap->getPosition(); for (c = 0; c < cntC; ++c) // all mini pos for one car { const SMiniPos& sp = h.vMiniPos[c]; const ColourValue& clr = app->carModels[c]->color; for (int p=0; p < 4; ++p) // all 4 points { float x = pos.x + (sp.x + sp.px[p]*z)*sc; float y = pos.y + (sp.y + sp.py[p]*z)*sc*asp; moPos->position(x, y, 0); moPos->textureCoord(tc[p][0], tc[p][1]); moPos->colour(clr); } } } int ii = plr * cntC; for (int i=0; i < ii; ++i) { int n = i*4; moPos->quad(n,n+1,n+3,n+2); } moPos->end(); } // track% local, updated always for (c = 0; c < cntC; ++c) { CarModel* cm = app->carModels[c]; if (cm->eType == CarModel::CT_LOCAL || cm->eType == CarModel::CT_REPLAY) cm->UpdTrackPercent(); } if (carId == -1 || app->carModels.empty()) { PROFILER.endBlock("g.hud"); return; } #ifdef DEBUG assert(carId >= 0); assert(carId < app->carModels.size()); #endif CarModel* pCarM = app->carModels[carId]; CAR* pCar = pCarM ? pCarM->pCar : 0; float vel=0.f, rpm=0.f, clutch=1.f; int gear=1; GetVals(carId,&vel,&rpm,&clutch,&gear); Hud& h = hud[carId]; /// multiplayer // ----------------------------------------------------------------------------------- static float tm = 0.f; tm += time; if (tm > 0.2f /**/&& app->mClient/**/) // not every frame, each 0.2s // if (pSet->game.isNetw) .. { // sort winners std::list<CarModel*> cms; for (c=0; c < cnt; ++c) cms.push_back(app->carModels[c]); cms.sort(SortWin); //stable_sort(cms.begin(), cms.end(), SortWin); String msg = ""; int place = 1; // assing places for (std::list<CarModel*>::iterator it = cms.begin(); it != cms.end(); ++it) { CarModel* cm = *it; bool end = app->pGame->timer.GetCurrentLap(cm->iIndex) >= pSet->game.num_laps; cm->iWonPlace = end ? place++ : 0; // when ended race // detect change (won), can happen more than once, if time diff < ping delay if (cm->iWonPlace != cm->iWonPlaceOld) { cm->iWonPlaceOld = cm->iWonPlace; cm->iWonMsgTime = gPar.timeWonMsg; if (cm->iIndex == 0) // for local player, show end wnd app->mWndNetEnd->setVisible(true); } if (cm->iWonMsgTime > 0.f) { cm->iWonMsgTime -= tm; if (cm->iWonPlace != 0) msg += cm->sDispName + " " + TR("#{FinishedCommaPlace}") + ": " + toStr(cm->iWonPlace) + "\n"; } } if (app->mClient && /*ap->pGame->timer.pretime <= 0.f &&*/ app->pGame->timer.waiting) msg += TR("#{NetWaitingForOthers}")+"...\n"; // chat 2 last lines if (gui->sChatLast1 != "") msg += gui->sChatLast1 + "\n"; if (gui->sChatLast2 != "") msg += gui->sChatLast2; ++gui->iChatMove; if (gui->iChatMove >= 10) //par 2sec { gui->iChatMove = 0; gui->sChatLast1 = gui->sChatLast2; gui->sChatLast2 = ""; } // upd hud msgs if (txMsg) { txMsg->setCaption(msg); bckMsg->setVisible(!msg.empty()); } // upd end list if (app->mWndNetEnd->getVisible()) { MyGUI::MultiList2* li = gui->liNetEnd; li->removeAllItems(); for (std::list<CarModel*>::iterator it = cms.begin(); it != cms.end(); ++it) { CarModel* cm = *it; String clr = StrClr(cm->color); li->addItem(""/*clr+ toStr(c+1)*/, 0); int l = li->getItemCount()-1; li->setSubItemNameAt(1,l, clr+ (cm->iWonPlace == 0 ? "--" : toStr(cm->iWonPlace))); li->setSubItemNameAt(2,l, clr+ cm->sDispName); li->setSubItemNameAt(3,l, clr+ StrTime( cm->iWonPlace == 0 ? 0.f : app->pGame->timer.GetPlayerTimeTot(cm->iIndex) )); //li->setSubItemNameAt(4,l, clr+ fToStr(cm->iWonMsgTime,1,3)); li->setSubItemNameAt(4,l, clr+ StrTime( app->pGame->timer.GetBestLapRace(cm->iIndex) )); li->setSubItemNameAt(5,l, clr+ toStr( app->pGame->timer.GetCurrentLap(cm->iIndex) )); } } tm = 0.f; } /// opponents list // ----------------------------------------------------------------------------------- bool visOpp = h.txOpp[0] && pSet->show_opponents; if (visOpp && pCarM && pCarM->pMainNode) { std::list<CarModel*> cms; // sorted list for (c=0; c < cnt; ++c) { // cars only CarModel* cm = app->carModels[c]; if (!cm->isGhost()) { if (app->bRplPlay) cm->trackPercent = app->carPoses[app->iCurPoses[c]][c].percent; cms.push_back(cm); } } if (pSet->opplist_sort) cms.sort(SortPerc); for (c=0; c < cnt; ++c) { // add last, if visible, ghost1 (dont add 2nd) and track's ghost CarModel* cm = app->carModels[c]; if (cm->eType == (app->isGhost2nd ? CarModel::CT_GHOST2 : CarModel::CT_GHOST) && pSet->rpl_ghost || cm->isGhostTrk() && pSet->rpl_trackghost) { cm->trackPercent = app->carPoses[app->iCurPoses[c]][c].percent; // ghost,rpl cms.push_back(cm); } } bool bGhostEnd = app->pGame->timer.GetPlayerTime(0) > app->ghplay.GetTimeLength(); String s0,s1,s2; // Track% Dist Nick ColourValue clr; c = 0; for (std::list<CarModel*>::iterator it = cms.begin(); it != cms.end(); ++it) { CarModel* cm = *it; if (cm->pMainNode) { bool bGhost = cm->isGhost() && !cm->isGhostTrk(); bool bGhostVis = (app->ghplay.GetNumFrames() > 0) && pSet->rpl_ghost; bool bGhEmpty = bGhost && !bGhostVis; // dist ----------- if (cm == pCarM || bGhEmpty) // no dist to self or to empty ghost s1 += "\n"; else { Vector3 v = cm->pMainNode->getPosition() - pCarM->pMainNode->getPosition(); float dist = v.length(); // meters Real h = std::min(60.f, dist) / 60.f; clr.setHSB(0.5f - h * 0.4f, 1, 1); s1 += StrClr(clr)+ fToStr(dist,0,3)+"m\n"; } // percent % ----------- if (bGhEmpty || cm->isGhostTrk()) s0 += "\n"; else { float perc = bGhost && bGhostEnd ? 100.f : cm->trackPercent; clr.setHSB(perc*0.01f * 0.4f, 0.7f, 1); s0 += StrClr(clr)+ fToStr(perc,0,3)+"%\n"; } // nick name ----------- if (cm->eType != CarModel::CT_REPLAY) { s2 += StrClr(cm->color)+ cm->sDispName; bool end = app->pGame->timer.GetCurrentLap(cm->iIndex) >= pSet->game.num_laps && (app->mClient || pSet->game.local_players > 1); // multiplay or split if (end) // place (1) s2 += " (" + toStr(cm->iWonPlace) + ")"; } s2 += "\n"; ++c; } } // upd pos, size if (h.lastOppH != c) { h.lastOppH = c; int y = c*25 +4, yo = h.yOpp - y-4; for (int n=0; n < 3; ++n) { h.txOpp[n]->setPosition(h.xOpp + n*65+5, yo + 3); h.txOpp[n]->setSize(90,y); } h.bckOpp->setPosition(h.xOpp, yo); h.bckOpp->setSize(230,y); } h.txOpp[0]->setCaption(s0); h.txOpp[1]->setCaption(s1); h.txOpp[2]->setCaption(s2); } // Set motion blur intensity for this viewport, depending on car's linear velocity //----------------------------------------------------------------------------------- if (pSet->blur) { // use velocity squared to achieve an exponential motion blur float speed = pCar->GetVelocity().MagnitudeSquared(); // peak at 250 kmh (=69 m/s), 69² = 4761 // motion blur slider: 1.0 = peak at 100 km/h 0.0 = peak at 400 km/h -> 0.5 = peak at 250 km/h // lerp(100, 400, 1-motionBlurIntensity) float peakSpeed = 100 + (1-pSet->blur_int) * (400-100); float intens = fabs(speed) / pow((peakSpeed/3.6f), 2); // higher fps = less perceived motion blur time a frame will be still visible on screen: // each frame, 1-intens of the original image is lost // example (intens = 0.7): // frame 1: full img frame 2: 0.7 * image // frame 3: 0.7² * image frame 4: 0.7³ * image // portion of image visible after 'n' frames: pow(intens, n); // example 1: 60 fps 0.7³ image after 4 frames: 0.066 sec // example 2: 120 fps 0.7³ image after 4 frames: 0.033 sec // now: need to achieve *same* time for both fps values // to do this, adjust intens // (1.0/fps) * pow(intens, n) == (1.0/fps2) * pow(intens2, n) // set n=4 intens_new = sqrt(sqrt((intens^4 * fpsReal/desiredFps)) intens = sqrt(sqrt( pow(intens, 4) * ((1.0f/time) / 120.0f) )); intens = std::min(intens, 0.9f); // clamp to 0.9f app->motionBlurIntensity = intens; } /// gear, vel texts ----------------------------- if (h.txVel && h.txGear && pCar) { float cl = clutch*0.8f + 0.2f; if (gear == -1) { h.txGear->setCaption("R"); h.txGear->setTextColour(Colour(0.3,1,1,cl)); } else if (gear == 0) { h.txGear->setCaption("N"); h.txGear->setTextColour(Colour(0.3,1,0.3,cl)); } else if (gear > 0 && gear < 8) { h.txGear->setCaption(toStr(gear)); h.txGear->setTextColour(Colour(1,1-gear*0.1,0.2,cl)); } h.txVel->setCaption(fToStr(fabs(vel),0,3)); float k = pCar->GetSpeedometer() * 3.6f * 0.0025f; // vel clr #define m01(x) std::min(1.0f, std::max(0.0f, (float) (x) )) h.txVel->setTextColour(Colour(m01(k*2), m01(0.5+k*1.5-k*k*2.5), m01(1+k*0.8-k*k*3.5))); } // boost fuel (time) ------ if (h.txBFuel && pCar && h.txBFuel->getVisible()) { h.txBFuel->setCaption(fToStr(pCar->dynamics.boostFuel,1,3)); } // damage % ------ if (h.txDamage && pCar && h.txDamage->getVisible()) { float d = std::min(100.f, pCar->dynamics.fDamage); //h.txDamage->setCaption(TR("#{Damage}\n ")+fToStr(d,0,3)+" %"); d*=0.01f; h.txDamage->setCaption(fToStr(d,0,3)+" %"); d*=0.01f; float e = std::min(1.f, 0.8f + d*2.f); h.txDamage->setTextColour(Colour(e-d*d*0.4f, std::max(0.f, e-d), std::max(0.f, e-d*2.f) )); } // abs, tcs on ------ if (h.txAbs && h.txTcs && pCar) { bool vis = pCar->GetABSEnabled(); h.txAbs->setVisible(vis); if (vis) h.txAbs->setAlpha(pCar->GetABSActive() ? 1.f : 0.6f); vis = pCar->GetTCSEnabled(); h.txTcs->setVisible(vis); if (vis) h.txTcs->setAlpha(pCar->GetTCSActive() ? 1.f : 0.6f); } /// times, race pos ----------------------------- if (pSet->show_times && pCar) { TIMER& tim = app->pGame->timer; bool hasLaps = pSet->game.local_players > 1 || pSet->game.champ_num >= 0 || pSet->game.chall_num >= 0 || app->mClient; if (hasLaps) { // place if (pCarM->iWonPlace > 0 && h.txPlace) { String s = TR("--- "+toStr(pCarM->iWonPlace)+" #{TBPlace} ---"); h.txPlace->setCaption(s); const static Colour clrPlace[4] = { Colour(0.4,1,0.2), Colour(1,1,0.3), Colour(1,0.7,0.2), Colour(1,0.5,0.2) }; h.txPlace->setTextColour(clrPlace[pCarM->iWonPlace-1]); h.bckPlace->setVisible(true); } } // times ------------------------------ bool cur = pCarM->iCurChk >= 0 && !app->vTimeAtChks.empty(); float ghTimeES = cur ? app->vTimeAtChks[pCarM->iCurChk] : 0.f; float part = ghTimeES / app->fLastTime; // fraction which track ghost has driven bool coldStart = tim.GetCurrentLap(carId) == 1; // was 0 float carMul = app->GetCarTimeMul(pSet->game.car[carId], pSet->game.sim_mode); //| cur float ghTimeC = ghTimeES + (coldStart ? 0 : 1); float ghTime = ghTimeC * carMul; // scaled float diffT = pCarM->timeAtCurChk - ghTime; // cur car diff at chk float diff = 0.f; // on hud //!- if (pCarM->updTimes || pCarM->updLap) { pCarM->updTimes = false; // track time, points float last = tim.GetLastLap(carId), best = tim.GetBestLap(carId, pSet->game.trackreverse); float timeCur = last < 0.1f ? best : last; float timeTrk = app->data->tracks->times[pSet->game.track]; bool b = timeTrk > 0.f && timeCur > 0.f; //bool coldStart = tim.GetCurrentLap(carId) == 1; // was 0 float time = (/*place*/1 * app->data->cars->magic * timeTrk + timeTrk) / carMul; // trk time (for 1st place) //float t1pl = data->carsXml.magic * timeTrk; float points = 0.f, curPoints = 0.f; int place = app->GetRacePos(timeCur, timeTrk, carMul, coldStart, &points); //| cur float timCC = timeTrk + (coldStart ? 0 : 1); float timCu = timCC * carMul; diff = pCarM->timeAtCurChk + /*(coldStart ? 1:0)*carMul*/ - time * part; ///new float chkPoints = 0.f; // cur, at chk, assume diff time later than track ghost int chkPlace = app->GetRacePos(timCu + diffT, timeTrk, carMul, coldStart, &chkPoints); bool any = cur || b; h.sTimes = "\n#80E080" + StrTime(time)+ "\n#D0D040" + (cur ? toStr( chkPlace ) : "--")+ "\n#F0A040" + (cur ? fToStr(chkPoints,1,3) : "--"); float dlap = last - time; h.sLap = "#D0E8FF"+TR("#{TBLapResults}") + "\n#80C8FF" + StrTime(last)+ (last > 0.f ? String(" ") + (dlap > 0.f ? "#80E0FF+" : "#60FF60-") + fToStr(fabs(dlap), 1,3) : "")+ "\n#80E0E0" + StrTime(best)+ "\n#80E080" + StrTime(time)+ "\n#D0D040" + (b ? toStr(place) : "--")+ "\n#F0A040" + (b ? fToStr(points,1,3) : "--"); if (h.txLap) h.txLap->setCaption(h.sLap); } if (h.txTimes) h.txTimes->setCaption( (hasLaps ? "#A0E0D0"+toStr(tim.GetCurrentLap(carId)+1)+" / "+toStr(pSet->game.num_laps) : "") + "\n#A0E0E0" + StrTime(tim.GetPlayerTime(carId))+ (cur ? String(" ") + (diff > 0.f ? "#80E0FF+" : "#60FF60-")+ fToStr(fabs(diff), 1,3) : "")+ h.sTimes+ "\n#E0B090" + fToStr(pCarM->trackPercent,0,1)+"%" ); if (h.txLap) { //if (pCarM->updLap) //{ pCarM->updLap = false; //h.txLap->setCaption(h.sLap); //} float a = std::min(1.f, pCarM->fLapAlpha * 2.f); bool hasRoad = app->scn->road && app->scn->road->getNumPoints() > 2; bool vis = pSet->show_times && hasRoad && a > 0.f; if (vis) { if (app->iLoad1stFrames == -2) //bLoading) // fade out { pCarM->fLapAlpha -= !hasRoad ? 1.f : time * gPar.fadeLapResults; if (pCarM->fLapAlpha < 0.f) pCarM->fLapAlpha = 0.f; } h.bckLap->setAlpha(a); h.txLapTxt->setAlpha(a); h.txLap->setAlpha(a); } h.bckLap->setVisible(vis); h.txLapTxt->setVisible(vis); h.txLap->setVisible(vis); } } // checkpoint warning -------- if (app->scn->road && h.bckWarn && pCarM) { /* checks debug * if (ov[0].oU) { //"ghost: " + GetTimeString(ghost.GetTimeLength()) + " " + toStr(ghost.GetNumFrames()) + "\n" + //"ghplay: " + GetTimeString(ghplay.GetTimeLength()) + " " + toStr(ghplay.GetNumFrames()) + "\n" + ov[0].oU->setCaption(String("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") + " st " + toStr(pCarM->bInSt ? 1:0) + " in" + toStr(pCarM->iInChk) + " | cur" + toStr(pCarM->iCurChk) + " > next " + toStr(pCarM->iNextChk) + " | Num " + toStr(pCarM->iNumChks) + " / All " + toStr(road->mChks.size())); } /**/ if (pCarM->bWrongChk) pCarM->fChkTime = gPar.timeShowChkWarn; bool show = pCarM->fChkTime > 0.f; if (show) pCarM->fChkTime -= time; h.bckWarn->setVisible(show && pSet->show_times); } // race countdown ------ if (h.txCountdown) { bool vis = app->pGame->timer.pretime > 0.f && !app->pGame->timer.waiting; if (vis) h.txCountdown->setCaption(fToStr(app->pGame->timer.pretime,1,3)); h.txCountdown->setVisible(vis); } // camera cur ------ if (h.txCam) { FollowCamera* cam = pCarM->fCam; if (cam && cam->updName) { cam->updName = false; h.txCam->setCaption(cam->sName); } } //------------------------------------------------------------------------------------------------------------------- /// debug infos //------------------------------------------------------------------------------------------------------------------- static int oldTxtClr = -2; // clr upd if (oldTxtClr != pSet->car_dbgtxtclr) { oldTxtClr = pSet->car_dbgtxtclr; UpdDbgTxtClr(); } // car debug text -------- static bool oldCarTxt = false; if (pCar && ov[0].oU) { if (pSet->car_dbgtxt) { std::stringstream s1,s2,s3,s4; pCar->DebugPrint(s1, true, false, false, false); ov[0].oU->setCaption(s1.str()); pCar->DebugPrint(s2, false, true, false, false); ov[1].oU->setCaption(s2.str()); pCar->DebugPrint(s3, false, false, true, false); ov[2].oU->setCaption(s3.str()); pCar->DebugPrint(s4, false, false, false, true); ov[3].oU->setCaption(s4.str()); }else if (pSet->car_dbgtxt != oldCarTxt) { ov[0].oU->setCaption(""); /*ovU[1]->setCaption(""); ovU[2]->setCaption(""); ovU[3]->setCaption("");*/ } } oldCarTxt = pSet->car_dbgtxt; // profiling times -------- if (pSet->profilerTxt && ov[1].oU) { PROFILER.endCycle(); static int frame=0; ++frame; if (frame > 10) //par { frame = 0; std::string sProf = PROFILER.getAvgSummary(quickprof::MILLISECONDS); //sProf = "PROF "+fToStr(1000.f/PROFILER.getAvgDuration(" frameSt",quickprof::MILLISECONDS), 2,4); ov[1].oU->setCaption(sProf); } //if (newPosInfos.size() > 0) //ov[3].oU->setCaption("carm: " + toStr(ap->carModels.size()) + " newp: " + toStr((*newPosInfos.begin()).pos)); } // bullet profiling text -------- static bool oldBltTxt = false; if (ov[1].oU) { if (pSet->bltProfilerTxt) { static int cc = 0; ++cc; if (cc > 40) { cc = 0; std::stringstream os; bltDumpAll(os); ov[1].oU->setCaption(os.str()); } } else if (pSet->bltProfilerTxt != oldBltTxt) ov[1].oU->setCaption(""); } oldBltTxt = pSet->bltProfilerTxt; // wheels slide, susp bars -------- if (pSet->car_dbgbars && pCar) { const Real xp = 80, yp = -530, ln = 20, y4 = 104; //const static char swh[4][6] = {"F^L<","F^R>","RvL<","RvR>"}; for (int w=0; w < 4; ++w) if (ov[3-w].oL && ov[3-w].oR && ov[3-w].oS) { float slide = /*-1.f*/0.f, sLong = 0.f, sLat = 0.f; float squeal = pCar->GetTireSquealAmount((WHEEL_POSITION)w, &slide, &sLong, &sLat); //MATHVECTOR<float,3> vwhVel = pCar->dynamics.GetWheelVelocity((WHEEL_POSITION)w); //float whVel = vwhVel.Magnitude() * 3.6f; /** // info static char ss[256]; sprintf(ss, "%s %6.3f %6.3f %6.3f %6.3f\n", swh[w], sLong/4.f, sLat/3.f, slide, squeal); ColourValue clr; clr.setHSB( slide/20.f, 0.8f, 1.f ); //clr.a = min(0.f, slide/2.f); ovL[3-w]->setCaption(String(ss)); ovL[3-w]->setColour(clr); //ovL[3-w]->setPosition(0.f, 230 + w*22); /**/ // bar meters | float susp = pCar->dynamics.GetSuspension(WHEEL_POSITION(w)).GetDisplacementPercent(); sLong = fabs(sLong); float slng = sLong / sLong * powf(sLong, 0.3f); // slide*20.f ov[3-w].oR->setPosition(slng * 14.f +xp, yp + w*ln); ov[3-w].oL->setPosition(sLat * 14.f +xp, yp + w*ln +y4); ov[3-w].oS->setPosition(susp * 70.f +xp, yp + w*ln -y4); } if (ov[4].oL) ov[4].oL->setPosition(xp, yp + -20 +y4+3); if (ov[4].oS) ov[4].oS->setPosition(xp + 70, yp + -20 -104-3); //ov[3-w].oR->setCaption("|"); ov[3-w].oR->setColour(ColourValue(0.6,1.0,0.7)); } // input values /*if (pCar && ap->pGame && ap->pGame->profilingmode) { const std::vector<float>& inp = pCar->dynamics.inputsCopy; if (ov[2].oU && inp.size() == CARINPUT::ALL) { sprintf(s, " Throttle %5.2f\n Brake %5.2f\n Steer %5.2f\n" " Handbrake %5.2f\n Boost %5.2f\n Flip %5.2f\n" ,inp[CARINPUT::THROTTLE], inp[CARINPUT::BRAKE], -inp[CARINPUT::STEER_LEFT]+inp[CARINPUT::STEER_RIGHT] ,inp[CARINPUT::HANDBRAKE],inp[CARINPUT::BOOST], inp[CARINPUT::FLIP] ); ov[2].oU->setCaption(String(s)); } }/**/ // wheels ter mtr, surface info --------- if (pSet->car_dbgsurf && pCar) { String ss = ""; ss = pCarM->txtDbgSurf; // surfaces info /*ss += "\n"; for (int i=0; i < ap->pGame->track.tracksurfaces.size(); ++i) ss += String(ap->pGame->track.tracksurfaces[i].name.c_str()) + "\n";/**/ //ovCarDbg->show(); if (ov[4].oX) { //ov[4].oL->setTop(400); ov[4].oX->setCaption(ss); } } /// tire vis circles + + + + if (pCar && moTireVis[0] && pSet->car_tirevis) { const Real z = 6000.f / pSet->tc_r, zy = pSet->tc_xr, m_z = 2.f * z; // scale, max factor const int na = 32; // circle quality const Real ad = 2.f*PI_d/na, u = 0.02f; // u line thickness const ColourValue cb(0.8,0.8,0.8),cl(0.2,1,0.2),cr(0.9,0.4,0),cc(1,1,0); for (int i=0; i < 4; ++i) { const CARDYNAMICS& cd = pCar->dynamics; const CARWHEEL::SlideSlip& t = cd.wheel[i].slips; float d = cd.wheel_contact[i].GetDepth() - 2*cd.wheel[i].GetRadius(); bool off = !(d > -0.1f && d <= -0.01f); // not in air //bool on = cd.wheel_contact[i].GetColObj(); ManualObject* m = moTireVis[i]; m->beginUpdate(0); // back + m->position(-1,0,0); m->colour(cb); m->position( 1,0,0); m->colour(cb); m->position(0,-1,0); m->colour(cb); m->position(0, 1,0); m->colour(cb); // tire, before combine Real lx = off ? 0.f : t.preFy/z*zy, ly = off ? 0.f : t.preFx/z; for (int y=-1; y<=1; ++y) for (int x=-1; x<=1; ++x) { m->position(0 +x*u, 0 +y*u, 0); m->colour(cr); m->position(lx +x*u, ly +y*u, 0); m->colour(cr); } // tire line / lx = off ? 0.f : t.Fy/z*zy; ly = off ? 0.f : t.Fx/z; for (int y=-2; y<=2; ++y) for (int x=-2; x<=2; ++x) { m->position(0 +x*u, 0 +y*u, 0); m->colour(cl); m->position(lx +x*u, ly +y*u, 0); m->colour(cl); } // max circle o Real rx = off || t.Fym > m_z ? 0.f : t.Fym/z, ry = off || t.Fxm > m_z ? 0.f : t.Fxm/z, a = 0.f; Vector3 p(0,0,0),po(0,0,0); for (int n=0; n <= na; ++n) { p.x = rx*cosf(a)*zy; p.y =-ry*sinf(a); if (n > 0) { m->position(po); m->colour(cc); m->position(p); m->colour(cc); } a += ad; po = p; } m->end(); } } PROFILER.endBlock("g.hud"); }
//--------------------------------------------------------------------- void Grid3DPageStrategy::updateDebugDisplay(Page* p, SceneNode* sn) { uint8 dbglvl = mManager->getDebugDisplayLevel(); if (dbglvl) { // we could try to avoid updating the geometry every time here, but this // wouldn't easily deal with paging parameter changes. There shouldn't // be that many pages anyway, and this is debug after all, so update every time int32 x, y, z; Grid3DPageStrategyData* stratData = static_cast<Grid3DPageStrategyData*>( p->getParentSection()->getStrategyData()); stratData->calculateCell(p->getID(), &x, &y, &z); Grid3DPageStrategyData* data = static_cast<Grid3DPageStrategyData*>(p->getParentSection()->getStrategyData()); // Determine our centre point, we'll anchor here Vector3 midPoint; data->getMidPointGridSpace(x, y, z, midPoint); sn->setPosition(midPoint); //--- Get coordinates, relative to midPoint : Vector3 corners[8]; Vector3 hSize = 0.500f * stratData->getCellSize(); for (int i = 0; i < 8; ++i) { corners[i].x = i&1 ? hSize.x : -hSize.x; corners[i].z = i&2 ? hSize.y : -hSize.y; corners[i].y = i&4 ? hSize.z : -hSize.z; } //--- Get a material String matName = "Ogre/G3D/Debug"; MaterialPtr mat = MaterialManager::getSingleton().getByName(matName); if (mat.isNull()) { mat = MaterialManager::getSingleton().create(matName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Pass* pass = mat->getTechnique(0)->getPass(0); pass->setLightingEnabled(false); pass->setVertexColourTracking(TVC_AMBIENT); pass->setDepthWriteEnabled(false); mat->load(); } ManualObject* mo = 0; bool update = sn->numAttachedObjects() > 0; if( update ) { mo = static_cast<ManualObject*>(sn->getAttachedObject(0)); mo->beginUpdate(0); } else { mo = p->getParentSection()->getSceneManager()->createManualObject(); mo->begin(matName, RenderOperation::OT_LINE_STRIP); } ColourValue vcol = ColourValue::Green; mo->position(corners[0]); mo->colour(vcol); // First Square... mo->position(corners[1]); mo->colour(vcol); mo->position(corners[3]); mo->colour(vcol); mo->position(corners[2]); mo->colour(vcol); mo->position(corners[0]); mo->colour(vcol); mo->position(corners[4]); mo->colour(vcol); // 0-4 link + second square and mo->position(corners[5]); mo->colour(vcol); mo->position(corners[7]); mo->colour(vcol); mo->position(corners[6]); mo->colour(vcol); mo->position(corners[4]); mo->colour(vcol); mo->position(corners[5]); mo->colour(vcol); // 5-1 link mo->position(corners[1]); mo->colour(vcol); mo->position(corners[3]); mo->colour(vcol); // 3-7 link mo->position(corners[7]); mo->colour(vcol); mo->position(corners[6]); mo->colour(vcol); // 6-2 link mo->position(corners[2]); mo->colour(vcol); mo->end(); if(!update) sn->attachObject(mo); } }
void GridBuilder::buildInScene(Ogre::SceneManager *_scene, int _units) { using namespace Ogre; SceneNode *gridNode = _scene->getRootSceneNode()->createChildSceneNode("WorldGrid Node"); ManualObject *axes = _scene->createManualObject("AXES"); axes->begin("WorldGrid/Axes", RenderOperation::OT_LINE_LIST); // X axis axes->position(-_units, 0.0, 0.0); axes->colour(0.1, 0.0, 0.0); axes->position( _units, 0.0, 0.0); axes->colour(1.0, 0.0, 0.0); // Y Axis axes->position(0.0, -_units, 0.0); axes->colour(0.0, 0.1, 0.0); axes->position(0.0, _units, 0.0); axes->colour(0.0, 1.0, 0.0); // Z axis axes->position( 0.0, 0.0, -_units); axes->colour(0.0, 0.0, 0.1); axes->position( 0.0, 0.0, _units); axes->colour(0.0, 0.0, 1.0); axes->end(); gridNode->attachObject(axes); axes->setQueryFlags(0x00); ManualObject *grid = _scene->createManualObject("Grid Lines"); grid->begin("WorldGrid/Lines", RenderOperation::OT_LINE_LIST); float c; for (int i = 10; i<=_units ; i+=10) { c = (i%100) ? 0.6 : 0.7; grid->position(-_units, 0, i); grid->colour(c, c, c); grid->position( _units, 0, i); grid->colour(c, c, c); grid->position(-_units, 0, -i); grid->colour(c, c, c); grid->position( _units, 0, -i); grid->colour(c, c, c); grid->position(i, 0, -_units); grid->colour(c, c, c); grid->position(i, 0, _units); grid->colour(c, c, c); grid->position(-i, 0, -_units); grid->colour(c, c, c); grid->position(-i, 0, _units); grid->colour(c, c, c); } grid->end(); grid->setQueryFlags(0x00); gridNode->attachObject(grid); }
// util //--------------------------------------------------------------------------------------------------------------- ManualObject* App::Create2D(const String& mat, Real s, bool dyn) { ManualObject* m = mSceneMgr->createManualObject(); m->setDynamic(dyn); m->setUseIdentityProjection(true); m->setUseIdentityView(true); m->setCastShadows(false); m->estimateVertexCount(4); m->begin(mat, RenderOperation::OT_TRIANGLE_STRIP); m->position(-s,-s*asp, 0); m->textureCoord(0, 1); m->position( s,-s*asp, 0); m->textureCoord(1, 1); m->position(-s, s*asp, 0); m->textureCoord(0, 0); m->position( s, s*asp, 0); m->textureCoord(1, 0); m->end(); //TODO:replace OT_TRIANGLE_FAN with a more friendly version for D3D11 as it is not supported /* m->estimateVertexCount(6); m->begin(mat, RenderOperation::OT_TRIANGLE_LIST); m->position(-s,-s*asp, 0); m->textureCoord(0, 1); m->position( s,-s*asp, 0); m->textureCoord(1, 1); m->position( s, s*asp, 0); m->textureCoord(1, 0); m->position(-s, s*asp, 0); m->textureCoord(0, 0); m->position(-s,-s*asp, 0); m->textureCoord(0, 1); m->position( s, s*asp, 0); m->textureCoord(1, 0); m->end(); */ AxisAlignedBox aabInf; aabInf.setInfinite(); m->setBoundingBox(aabInf); // always visible m->setRenderQueueGroup(RQG_Hud2); return m; }
void PlayPen_testProjectSphere::setupContent() { mSceneMgr->setAmbientLight(ColourValue::White); Plane plane; plane.normal = Vector3::UNIT_Y; plane.d = 0; MeshManager::getSingleton().createPlane("Myplane", TRANSIENT_RESOURCE_GROUP, plane, 4500,4500,10,10,true,1,5,5,Vector3::UNIT_Z); Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); pPlaneEnt->setMaterialName("Examples/GrassFloor"); pPlaneEnt->setCastShadows(false); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); mProjectionSphere = new Sphere(Vector3(0, 2000, 0), 1500.0); ManualObject* debugSphere = mSceneMgr->createManualObject("debugSphere"); debugSphere->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP); for (int i = 0; i <= 20; ++i) { Vector3 basePos(mProjectionSphere->getRadius(), 0, 0); Quaternion quat; quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Y); basePos = quat * basePos; debugSphere->position(basePos); } for (int i = 0; i <= 20; ++i) { Vector3 basePos(mProjectionSphere->getRadius(), 0, 0); Quaternion quat; quat.FromAngleAxis(Radian(((float)i/(float)20)*Math::TWO_PI), Vector3::UNIT_Z); basePos = quat * basePos; debugSphere->position(basePos); } debugSphere->end(); mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,2000,0))->attachObject(debugSphere); MaterialPtr mat = MaterialManager::getSingleton().create("scissormat", TRANSIENT_RESOURCE_GROUP); Pass* p = mat->getTechnique(0)->getPass(0); p->setDepthWriteEnabled(false); p->setSceneBlending(SBT_TRANSPARENT_ALPHA); TextureUnitState* t = p->createTextureUnitState(); t->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue::Red); t->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 0.5f); mScissorRect = mSceneMgr->createManualObject("mScissorRect"); mScissorRect->setUseIdentityProjection(true); mScissorRect->setUseIdentityView(true); AxisAlignedBox aabb; aabb.setInfinite(); mScissorRect->setBoundingBox(aabb); mScissorRect->begin(mat->getName()); mScissorRect->position(Vector3::ZERO); mScissorRect->position(Vector3::ZERO); mScissorRect->position(Vector3::ZERO); mScissorRect->quad(0, 1, 2, 3); mScissorRect->end(); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mScissorRect); mCamera->setPosition(0,3000,5000); mCamera->lookAt(mProjectionSphere->getCenter()); }
void DebugDisplay::drawCube( AxisAlignedBox bbox ) { oht_assert_threadmodel(ThrMdl_Main); ManualObject * pManObj = _pSceneManager->createManualObject(); rollbackTransforms(bbox); pManObj->begin(getCurrentMaterial(), RenderOperation::OT_LINE_LIST); const Vector3 m0 = bbox.getMinimum(), mN = bbox.getMaximum(); pManObj->position(m0.x, m0.y, m0.z); pManObj->position(mN.x, m0.y, m0.z); pManObj->position(m0.x, m0.y, m0.z); pManObj->position(m0.x, mN.y, m0.z); pManObj->position(m0.x, m0.y, m0.z); pManObj->position(m0.x, m0.y, mN.z); pManObj->position(mN.x, mN.y, m0.z); pManObj->position(mN.x, m0.y, m0.z); pManObj->position(mN.x, mN.y, m0.z); pManObj->position(m0.x, mN.y, m0.z); pManObj->position(mN.x, mN.y, m0.z); pManObj->position(mN.x, mN.y, mN.z); pManObj->position(m0.x, mN.y, mN.z); pManObj->position(m0.x, mN.y, m0.z); pManObj->position(m0.x, mN.y, mN.z); pManObj->position(m0.x, m0.y, mN.z); pManObj->position(m0.x, mN.y, mN.z); pManObj->position(mN.x, mN.y, mN.z); pManObj->position(mN.x, m0.y, mN.z); pManObj->position(m0.x, m0.y, mN.z); pManObj->position(mN.x, m0.y, mN.z); pManObj->position(mN.x, m0.y, m0.z); pManObj->position(mN.x, m0.y, mN.z); pManObj->position(mN.x, mN.y, mN.z); pManObj->end(); _pScNode->attachObject(pManObj); }
Ogre::SceneNode* Terminal::createTexturedRect(std::string object_name, std::string texture_name, float left, float top, float right, float bottom) { MaterialPtr material = MaterialManager::getSingleton().create(object_name,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->getTechnique(0)->getPass(0)->createTextureUnitState(texture_name); material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); // Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true); ManualObject* manual = Entropy::getSingletonPtr()->mSceneMgr->createManualObject(object_name); manual->setUseIdentityProjection(true); manual->setUseIdentityView(true); manual->begin(object_name, RenderOperation::OT_TRIANGLE_STRIP); manual->position(left, bottom, 0.0); manual->position(left, top, 0.0); manual->position(right, bottom, 0.0); manual->position(right, top, 0.0); manual->index(0); manual->index(1); manual->index(2); manual->index(3); manual->end(); // rect->setCorners(left,top,right,bottom); // rect->setMaterial(object_name); manual->setRenderQueueGroup(RENDER_QUEUE_OVERLAY); Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); manual->setBoundingBox(aabInf); Ogre::SceneNode* rect_node = Entropy::getSingletonPtr()->mSceneMgr->getRootSceneNode()->createChildSceneNode(object_name); rect_node->attachObject(manual); // rect->setVisible(false); // rect_node->setPosition(0,0,0); return rect_node; }
ManualObject *Debugging::createPathgridPoints(const ESM::Pathgrid *pathgrid) { ManualObject *result = mSceneMgr->createManualObject(); const float height = POINT_MESH_BASE * sqrtf(2); result->begin(PATHGRID_POINT_MATERIAL, RenderOperation::OT_TRIANGLE_STRIP); bool first = true; uint32 startIndex = 0; for(ESM::Pathgrid::PointList::const_iterator it = pathgrid->mPoints.begin(); it != pathgrid->mPoints.end(); it++, startIndex += 6) { Vector3 pointPos(it->mX, it->mY, it->mZ); if (!first) { // degenerate triangle from previous octahedron result->index(startIndex - 4); // 2nd point of previous octahedron result->index(startIndex); // start point of current octahedron } result->position(pointPos + Vector3(0, 0, height)); // 0 result->position(pointPos + Vector3(-POINT_MESH_BASE, -POINT_MESH_BASE, 0)); // 1 result->position(pointPos + Vector3(POINT_MESH_BASE, -POINT_MESH_BASE, 0)); // 2 result->position(pointPos + Vector3(POINT_MESH_BASE, POINT_MESH_BASE, 0)); // 3 result->position(pointPos + Vector3(-POINT_MESH_BASE, POINT_MESH_BASE, 0)); // 4 result->position(pointPos + Vector3(0, 0, -height)); // 5 result->index(startIndex + 0); result->index(startIndex + 1); result->index(startIndex + 2); result->index(startIndex + 5); result->index(startIndex + 3); result->index(startIndex + 4); // degenerates result->index(startIndex + 4); result->index(startIndex + 5); result->index(startIndex + 5); // end degenerates result->index(startIndex + 1); result->index(startIndex + 4); result->index(startIndex + 0); result->index(startIndex + 3); result->index(startIndex + 2); first = false; } result->end(); result->setVisibilityFlags (RV_Debug); return result; }