Exemple #1
0
 void RenderSystem::RenderPoint3DSet(std::string psName, std::string psMaterialName, const MagicDGP::Point3DSet* pPS)
 {
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(psName))
     {
         pMObj = mpSceneMgr->getManualObject(psName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(psName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     if (pPS->HasNormal())
     {
         int pointNum = pPS->GetPointNumber();
         pMObj->begin(psMaterialName, Ogre::RenderOperation::OT_POINT_LIST);
         for (int i = 0; i < pointNum; i++)
         {
             const MagicDGP::Point3D* pPoint = pPS->GetPoint(i);
             if (pPoint->IsValid() == false)
             {
                 continue;
             }
             MagicMath::Vector3 pos = pPoint->GetPosition();
             MagicMath::Vector3 nor = pPoint->GetNormal();
             MagicMath::Vector3 color = pPoint->GetColor();
             pMObj->position(pos[0], pos[1], pos[2]);
             pMObj->normal(nor[0], nor[1], nor[2]);
             pMObj->colour(color[0], color[1], color[2]);
         }
         pMObj->end();
     }
     else
     {
         int pointNum = pPS->GetPointNumber();
         pMObj->begin(psMaterialName, Ogre::RenderOperation::OT_POINT_LIST);
         for (int i = 0; i < pointNum; i++)
         {
             const MagicDGP::Point3D* pPoint = pPS->GetPoint(i);
             if (pPoint->IsValid() == false)
             {
                 continue;
             }
             MagicMath::Vector3 pos = pPoint->GetPosition();
             MagicMath::Vector3 color = pPoint->GetColor();
             pMObj->position(pos[0], pos[1], pos[2]);
             pMObj->colour(color[0], color[1], color[2]);
         }
         pMObj->end();
     }
     
 }
Ogre::MeshPtr STLLoader::toMesh(const std::string& name)
{
  Ogre::ManualObject* object = new Ogre::ManualObject( "the one and only" );
  object->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST );

  unsigned int vertexCount = 0;
  V_Triangle::const_iterator it = triangles_.begin();
  V_Triangle::const_iterator end = triangles_.end();
  for (; it != end; ++it )
  {
    if( vertexCount >= 2004 )
    {
      // Subdivide large meshes into submeshes with at most 2004
      // vertices to prevent problems on some graphics cards.
      object->end();
      object->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST );
      vertexCount = 0;
    }

    const STLLoader::Triangle& tri = *it;

    float u, v;
    u = v = 0.0f;
    object->position( tri.vertices_[0] );
    object->normal( tri.normal_);
    calculateUV( tri.vertices_[0], u, v );
    object->textureCoord( u, v );

    object->position( tri.vertices_[1] );
    object->normal( tri.normal_);
    calculateUV( tri.vertices_[1], u, v );
    object->textureCoord( u, v );

    object->position( tri.vertices_[2] );
    object->normal( tri.normal_);
    calculateUV( tri.vertices_[2], u, v );
    object->textureCoord( u, v );

    object->triangle( vertexCount + 0, vertexCount + 1, vertexCount + 2 );

    vertexCount += 3;
  }

  object->end();

  Ogre::MeshPtr mesh = object->convertToMesh( name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
  mesh->buildEdgeList();

  delete object;

  return mesh;
}
void NavigationCell::debugDrawCellAndNeigbours()
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* debugNode;

    if( mgr->hasSceneNode( "debugDrawNode" ) )
    {
        debugNode = mgr->getSceneNode( "debugDrawNode" );
    }
    else
    {
        debugNode = mgr->getRootSceneNode()->createChildSceneNode( "debugDrawNode" );
        debugNode->translate( 0, 1, 0 );    // Move up slightly to see lines better.
    }

    if( mgr->hasManualObject( "debugDraw" ) )
        debug = mgr->getManualObject( "debugDraw" );
    else
    {
        debug = mgr->createManualObject( "debugDraw" );
        debugNode->attachObject( debug );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    for( int i = 0; i < 3; i++ )
    {
        if( mLinks[i] )
        {
            debug->begin( "debug/blue", Ogre::RenderOperation::OT_LINE_STRIP );
            debug->position( mLinks[i]->mVertices[0] );
            debug->position( mLinks[i]->mVertices[1] );
            debug->position( mLinks[i]->mVertices[2] );
            debug->position( mLinks[i]->mVertices[0] );
            debug->end();
        }
    }

    debug->begin( "debug/yellow", Ogre::RenderOperation::OT_LINE_STRIP );
    debug->position( mVertices[0].x, mVertices[0].y+1, mVertices[0].z );
    debug->position( mVertices[1].x, mVertices[1].y+1, mVertices[1].z );
    debug->position( mVertices[2].x, mVertices[2].y+1, mVertices[2].z );
    debug->position( mVertices[0].x, mVertices[0].y+1, mVertices[0].z );
    debug->end();

}
Exemple #4
0
	void _drawGridPlane(void)
	{
		Ogre::ManualObject* gridPlane = mSceneMgr->createManualObject("GridPlane");
		Ogre::SceneNode* gridPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("GridPlaneNode");

		Ogre::MaterialPtr gridPlaneMaterial = Ogre::MaterialManager::getSingleton().create("GridPlanMaterial", "General");
		gridPlaneMaterial->setReceiveShadows(false);
		gridPlaneMaterial->getTechnique(0)->setLightingEnabled(true);
		gridPlaneMaterial->getTechnique(0)->getPass(0)->setDiffuse(1, 1, 1, 0);
		gridPlaneMaterial->getTechnique(0)->getPass(0)->setAmbient(1, 1, 1);
		gridPlaneMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1, 1, 1);

		gridPlane->begin("GridPlaneMaterial", Ogre::RenderOperation::OT_LINE_LIST);
		for (int i = 0; i < 21; i++)
		{
			gridPlane->position(-500.0f, 0.0f, 500.0f - i * 50);
			gridPlane->position(500.0f, 0.0f, 500.0f - i * 50);

			gridPlane->position(-500.f + i * 50, 0.f, 500.0f);
			gridPlane->position(-500.f + i * 50, 0.f, -500.f);
		}

		gridPlane->end();

		gridPlaneNode->attachObject(gridPlane);
	}
Exemple #5
0
void CubeWorld::createWorldChunks (void)
{
	//std::vector<int> VertexArray;
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0.5, 0));

	Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshMatChunk");
	MeshChunk->begin("TerrainImage");

	for (int z = 0; z < WORLD_SIZE; z += CHUNK_SIZE)
	{
		for (int y = 0; y < WORLD_SIZE; y += CHUNK_SIZE)
		{
			for (int x = 0; x < WORLD_SIZE; x += CHUNK_SIZE)
			{
				createChunk(MeshChunk, x,y,z); /* WFaces or not */
				//createChunkWater(x, y, z);
			}
		}
	}

}
void NavigationCell::debugDrawClassification( Ogre::Vector3 start, Ogre::Vector3 end )
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* node;

    if( mgr->hasManualObject( "debugDrawClassification" ) )
        debug = mgr->getManualObject( "debugDrawClassification" );
    else
    {
        debug = mgr->createManualObject( "debugDrawClassification" );
        node = mgr->getRootSceneNode()->createChildSceneNode();
        node->attachObject( debug );
        node->translate( 0, 1, 0 );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    debug->begin( "debug/blue", Ogre::RenderOperation::OT_LINE_LIST );
    debug->position( start );
    debug->position( end );
    debug->end();

//    debugDrawCell( debug, "debug/yellow", "debug/blue" );
}
Exemple #7
0
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);
}
Exemple #8
0
	// Dibujado de raycast para depurar
	void CShootRaycast::drawRaycast(const Ray& raycast) {
		Graphics::CScene *scene = Graphics::CServer::getSingletonPtr()->getActiveScene();
		Ogre::SceneManager *mSceneMgr = scene->getSceneMgr();

		std::stringstream aux;
		aux << "laser" << _nameWeapon << _temporal;
		++_temporal;
		std::string laser = aux.str();

		Ogre::ManualObject* myManualObject =  mSceneMgr->createManualObject(laser); 
		Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(laser+"_node"); 
 
		myManualObject->begin("laser", Ogre::RenderOperation::OT_LINE_STRIP);
		Vector3 v = raycast.getOrigin();
		myManualObject->position(v.x,v.y,v.z);

		for(int i=0; i < _distance;++i){
			Vector3 v = raycast.getPoint(i);
			myManualObject->position(v.x,v.y,v.z);
			// etc 
		}

		myManualObject->end(); 
		myManualObjectNode->attachObject(myManualObject);
	}// drawRaycast
Exemple #9
0
 void RenderSystem::RenderLineSegments(std::string lsName, std::string materialName, const std::vector<MagicMath::Vector3>& startPos, const std::vector<MagicMath::Vector3>& endPos)
 {
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(lsName))
     {
         pMObj = mpSceneMgr->getManualObject(lsName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(lsName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     pMObj->begin(materialName, Ogre::RenderOperation::OT_LINE_LIST);
     int lineNum = startPos.size();
     for (int i = 0; i < lineNum; i++)
     {
         MagicMath::Vector3 start = startPos.at(i);
         MagicMath::Vector3 end = endPos.at(i);
         pMObj->position(start[0], start[1], start[2]);
         pMObj->position(end[0], end[1], end[2]);
     }
     pMObj->end();
 }
void addQuad(
	const std::vector<Ogre::Vector3>& i_clockwiseQuad,
	const Ogre::Vector3& i_normal,
	size_t i_nRows,
	size_t i_nCols,
	const Ogre::String& i_material,
	Ogre::ManualObject& io_object)
{
	assert(i_clockwiseQuad.size() == 4);
	assert(i_nRows != 0 && i_nCols != 0);

	const std::vector<Ogre::Vector3>& box = i_clockwiseQuad;
	const Ogre::Vector3& n = i_normal;
	float ratioCol = 1.f / (float)(i_nCols);
	float ratioRow = 1.f / (float)(i_nRows);
	Ogre::Vector3 stepCol = (box[1] - box[0]) * ratioCol;
	Ogre::Vector3 stepRow = (box[3] - box[0]) * ratioRow;

	std::vector<Ogre::Vector3> cur(4);

	for (size_t r = 0; r < i_nRows; ++r)
	{
		io_object.begin(i_material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
		for (size_t c = 0; c < i_nCols; ++c)
		{
			cur[0] = box[0] + stepRow * (float)r + stepCol * (float)c;
			cur[1] = box[0] + stepRow * (float)r + stepCol * (float)(c+1);
			cur[2] = box[0] + stepRow * (float)(r+1) + stepCol * (float)(c+1);
			cur[3] = box[0] + stepRow * (float)(r+1) + stepCol * (float)(c);

			io_object.position(cur[0].x, cur[0].y, cur[0].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)r, ratioCol*(float)c);

			io_object.position(cur[3].x, cur[3].y, cur[3].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)(r+1), ratioCol*(float)c);

			io_object.position(cur[1].x, cur[1].y, cur[1].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)r, ratioCol*(float)(c+1));

			io_object.position(cur[1].x, cur[1].y, cur[1].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)r, ratioCol*(float)(c + 1));

			io_object.position(cur[3].x, cur[3].y, cur[3].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)(r + 1), ratioCol*(float)c);

			io_object.position(cur[2].x, cur[2].y, cur[2].z);
			io_object.normal(n.x, n.y, n.z);
			io_object.textureCoord(ratioRow*(float)(r+1), ratioCol*(float)(c + 1));

		}
		io_object.end();
	}
}
Exemple #11
0
//-------------------------------------------------------
Ogre::MeshPtr Ground::CreateRegion(size_t id, const std::string & material, const Ogre::Box & roi, const Ogre::Vector3 & offset, const Ogre::Vector3 & steps, const Ogre::Vector2 & texOffset)
{
    assert(mSceneManager != nullptr);

    Ogre::ManualObject* object = mSceneManager->createManualObject();
    object->begin(material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
    {
        size_t lastIdx = 0;
        for (size_t y = 0; y < REGION_SIZE; ++y)
        {
            size_t texY = static_cast<size_t>(static_cast<float>(y) / REGION_SIZE * (roi.getHeight() - 1));
            size_t texYn = static_cast<size_t>(static_cast<float>(y + 1) / REGION_SIZE * (roi.getHeight() - 1));

            //Flip texture vertically
            texY  = roi.getHeight() - 1 - texY;
            texYn = roi.getHeight() - 1 - texYn;

            float texCrdT = texOffset[1] + static_cast<float>(texY) / (mImage->getHeight() - 1);
            float texCrdTn = texOffset[1] + static_cast<float>(texYn) / (mImage->getHeight() - 1);

            for (size_t x = 0; x < REGION_SIZE; ++x)
            {
                size_t texX = static_cast<size_t>(static_cast<float>(x) / REGION_SIZE * (roi.getWidth() - 1));
                size_t texXn = static_cast<size_t>(static_cast<float>(x + 1) / REGION_SIZE * (roi.getWidth() - 1));

                float texCrdS = texOffset[0] + static_cast<float>(texX) / (mImage->getWidth() - 1);
                float texCrdSn = texOffset[0] + static_cast<float>(texXn) / (mImage->getWidth() - 1);

                float h00 = mImage->getColourAt(roi.left + texX,  roi.top + texY, 0)[0];
                float h10 = mImage->getColourAt(roi.left + texXn, roi.top + texY, 0)[0];
                float h01 = mImage->getColourAt(roi.left + texX,  roi.top + texYn, 0)[0];
                float h11 = mImage->getColourAt(roi.left + texXn, roi.top + texYn, 0)[0];

                object->position(x * steps[0] + offset[0], y * steps[1] + offset[1], h00 * steps[2]);
                object->textureCoord(texCrdS, texCrdT);
                object->colour(h00, h00, h00);
                
                object->position((x + 1) * steps[0] + offset[0], y * steps[1] + offset[1], h10 * steps[2]);
                object->textureCoord(texCrdSn, texCrdT);
                object->colour(h10, h10, h10);

                object->position(x * steps[0] + offset[0], (y + 1) * steps[1] + offset[1], h01 * steps[2]);
                object->textureCoord(texCrdS, texCrdTn);
                object->colour(h01, h01, h01);

                object->position((x + 1) * steps[0] + offset[0], (y + 1) * steps[1] + offset[1], h11 * steps[2]);
                object->textureCoord(texCrdSn, texCrdTn);
                object->colour(h11, h11, h11);

                object->triangle(lastIdx + 1, lastIdx + 2, lastIdx);
                object->triangle(lastIdx + 3, lastIdx + 2, lastIdx + 1);
                lastIdx += 4;
            }
        }
    }
    object->end();
    return object->convertToMesh("Mesh/" + CLASS_NAME  + "/" + mName + "/" + std::to_string(id));
}
void addLine(
	Ogre::Vector3 i_start,
	Ogre::Vector3 i_end,
	const Ogre::String& i_material,
	Ogre::ManualObject& io_object)
{
	io_object.begin(i_material, Ogre::RenderOperation::OT_LINE_LIST);
	io_object.position(i_start.x, i_start.y, i_start.z);
	io_object.position(i_end.x, i_end.y, i_end.z);
	io_object.end();
}
void ParticleFactory::CreateExplosionParticleGeometry(Ogre::String object_name, int num_particles){

		/* Retrieve scene manager and root scene node */
        //Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);

        /* Create point list for the object */
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);

		/* Initialize random numbers */
		std::srand(std::time(0));

		/* Create a set of points which will be the particles */
		/* This is similar to drawing a sphere: we will sample points on a sphere, but will allow them to also
		   deviate a bit from the sphere along the normal (change of radius) */
		float trad = 0.04; // Defines the starting point of the particles
        float maxspray = 0.01; // This is how much we allow the points to deviate from the sphere
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Randomly select three numbers to define a point in spherical coordinates
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            w = ((double) rand() / (RAND_MAX));

			// Use u to define the angle theta along one direction of a sphere
            theta = u * 2.0 * 3.1416;
			// Use v to define the angle phi along the other direction of the sphere
			phi = acos(2.0*v - 1.0);
			// Use we to define how much we can deviate from the surface of the sphere (change of radius)
            spray = maxspray*pow((float) w, (float) (1.0/3.0)); // Cubic root of w

			// Define the normal and point based on theta, phi and the spray
            Ogre::Vector3 normal = Ogre::Vector3(spray*cos(theta)*sin(phi), spray*sin(theta)*sin(phi), spray*cos(phi));
			object->position(normal.x*trad, normal.y*trad, normal.z*trad);
			object->normal(normal);
			object->colour(Ogre::ColourValue(i/(float) num_particles, 0.0, 1.0 - (i/(float) num_particles))); // We can use the color for debug, if needed
		}
		
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);

}
Ogre::MeshPtr MultiShape::realizeMesh(const std::string& name)
	{
		Ogre::ManualObject * manual = Root::getInstance()->sceneManager->createManualObject(name);
				
		for (std::vector<Shape>::iterator it = shapes.begin(); it!=shapes.end(); it++)
		{
			manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
			it->_appendToManualObject(manual);
			manual->end();
		}		
		
		Ogre::MeshPtr mesh = manual->convertToMesh(name);
		return mesh;
	}
Entity* EntityFactory::createBeamGun(const BeamGunConfig& config)
{
	EntityManager* entityMgr = engine_->entityMgr_;
	Entity* entity = entityMgr->create();

	float y = 0.1f;

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(config.posX_, config.posY_);
	b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);

	b2PolygonShape shape;
	b2Vec2 vertices[4];
	vertices[0].Set(0, y);
	vertices[1].Set(0, -y);
	vertices[2].Set(config.beamRange_, -y);
	vertices[3].Set(config.beamRange_, y);
	shape.Set(vertices, 4);

	b2FixtureDef sd;
	sd.shape = &shape;
	sd.density = 0;
	sd.filter.categoryBits = ComPhysics::CATEG_PlayerBeam;
	sd.filter.maskBits = ComPhysics::MASK_PlayerBeam;

	body->CreateFixture(&sd);

	ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
	comPhysics->setMainBody(body, entity);


	Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
	Ogre::ManualObject* manual = sceneMgr->createManualObject();
	manual->begin("beam", Ogre::RenderOperation::OT_LINE_STRIP);
	manual->position(0, y, 0);
	manual->position(0, -y, 0);
	manual->position(config.beamRange_, -y, 0);
	manual->position(config.beamRange_, y, 0);
	manual->position(0, y, 0);
	manual->end();
	Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
		Ogre::Vector3(config.posX_, config.posY_, 0));
	node->attachObject(manual);

	ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
	comGraphics->sceneNode_ = node;

	return entity;
}
Exemple #16
0
Mesh* MultiShape::GenerateMesh(const String& Name, const String& Group)
{
    Ogre::ManualObject* TempMan = new Ogre::ManualObject("TempMan");

    for( ShapeIterator It = this->Shapes.begin() ; It != this->Shapes.end() ; ++It )
    {
        TempMan->begin("BaseWhiteNoLighting",Ogre::RenderOperation::OT_LINE_STRIP);
        (*It)._AppendToManualObject(TempMan);
        TempMan->end();
    }

    Mesh* NewMesh = MeshManager::GetSingletonPtr()->_WrapInternalMesh( TempMan->convertToMesh(Name,Group) );
    delete TempMan;
    return NewMesh;
}
Exemple #17
0
Ogre::ManualObject* OBJImp::loadObject(std::string fileName){
	Ogre::ManualObject* mObj = video.ogreSceneMgr->createManualObject(fileName);
	mObj->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
	std::cout << "Opening .obj file: " << fileName.c_str() << std::endl;
	std::ifstream file(fileName);
	if(!file){
		std::cout << "Opening file failed!\n";
		return NULL;
	} else {
		std::cout << "OBJ File loaded successfully!\n";
	}
	std::string line;
	int totalLines = 0;
	int currentLine = 0;
	//obj content storage
	std::string type;
	std::string tmp;
	double v1, v2, v3;
	Ogre::Vector3 tmpVec3;

	while(std::getline(file,line)){
		std::stringstream iss(line);
		std::getline(iss, type, ' ');
		std::getline(iss, tmp, ' ');
		if(tmp.find("#") != std::string::npos){
			break;
		}
		v1 = std::stod(tmp.c_str());
		std::getline(iss, tmp, ' ');
		if(tmp.find("#") != std::string::npos){
			break;
		}
		v2 = std::stod(tmp.c_str());
		std::getline(iss, tmp, ' ');
		if(tmp.find("#") != std::string::npos){
			break;
		}
		v3 = std::stod(tmp.c_str());
		tmpVec3.x = v1;
		tmpVec3.y = v2;
		tmpVec3.z = v3;

		tmpVerts.push_back(tmpVec3);
		mObj->position(tmpVec3);
	}
	mObj->end();
	return mObj;
}
void Chart::indicator(const Ogre::Real chartX, const Ogre::Real chartY)
{
	const std::string chartXString = Ogre::StringConverter::toString(chartX).substr(0, std::min(Ogre::StringConverter::toString(chartX).size(), (std::string::size_type)4));
	const std::string chartYString = Ogre::StringConverter::toString(chartY).substr(0, std::min(Ogre::StringConverter::toString(chartY).size(), (std::string::size_type)3));
	const Ogre::Vector3 x = chartToScreen( Ogre::Vector2(chartX, mMin.y) );
	const Ogre::Vector3 y = chartToScreen( Ogre::Vector2(mMin.x, chartY) );
	const Ogre::ColourValue magenta(1,0,1);

	// indicator
    Ogre::ManualObject *chartIndicator = mSceneMgr->createManualObject();
    chartIndicator->setUseIdentityProjection(true);
    chartIndicator->setUseIdentityView(true);
    chartIndicator->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    chartIndicator->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    chartIndicator->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
    chartIndicator->position( x );
	chartIndicator->colour( magenta );
    chartIndicator->position( chartToScreen( Ogre::Vector2(chartX, chartY) ) );
	chartIndicator->colour( magenta );
    chartIndicator->position( y );
	chartIndicator->colour( magenta );
    chartIndicator->end();

	// text of values on the sides of the axes
	if(first)
	{
		TextRenderer::getSingleton().addTextBox("txt6" + rndIDString, chartXString, x.x - 0.01 * chartXString.size(), x.y - 0.035, 20, 20, magenta);
		TextRenderer::getSingleton().addTextBox("txt7" + rndIDString, chartYString, y.x - 0.035 - 0.01 * chartYString.size(), y.y - 0.0025, 20, 20, magenta);
		first = false;
	} 
	else
	{
		TextRenderer::getSingleton().removeTextBox("txt6" + rndIDString);
		TextRenderer::getSingleton().removeTextBox("txt7" + rndIDString);
		TextRenderer::getSingleton().addTextBox("txt6" + rndIDString, chartXString, x.x - 0.01 * chartXString.size(), x.y - 0.035, 20, 20, magenta);
		TextRenderer::getSingleton().addTextBox("txt7" + rndIDString, chartYString, y.x - 0.035 - 0.01 * chartYString.size(), y.y - 0.0025, 20, 20, magenta);
	}

    if (mChartIndicator)
    {
        mChartSceneNode->detachObject(mChartIndicator);
        mSceneMgr->destroyManualObject(mChartIndicator);
    }
    mChartIndicator = chartIndicator;
    mChartSceneNode->attachObject(mChartIndicator);

    mChartSceneNode->needUpdate();
}
Exemple #19
0
void LevelManager::drawTriangle(const Triangle *t)
{
    Ogre::ManualObject* manual = GLOBAL_SCN_MNGR->createManualObject();
    manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);

    Ogre::Real height = 5.0f;
    manual->position(t->v1->x, height, t->v1->y);  // start position
    manual->position(t->v2->x, height, t->v2->y);  // start position
    manual->position(t->v3->x, height, t->v3->y);  // start position
    manual->position(t->v1->x, height, t->v1->y);  // start position

    manual->end();
    Ogre::SceneNode *node = GLOBAL_SCN_MNGR->getRootSceneNode()->createChildSceneNode();
    node->attachObject(manual);

}
Exemple #20
0
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;
}
Ogre::ManualObject* RecastInterface::_exportPolygonMeshToEntity(unsigned short* vertices,
														  int numVertices,
														  unsigned short* polygons,
														  int numPolys,
														  int maxPolys,
														  int numVertsPerPoly,
														  const Ogre::Vector3& origin)
{
	if(_polyMesh == nullptr || _detailMesh == nullptr)
	{
		return NULL;
	}

	int nIndex = 0;
	Ogre::ManualObject* manObj = _scene->createManualObject("recastTempMO");
	manObj->begin("arena_locker/blue",Ogre::RenderOperation::OT_TRIANGLE_LIST);
	for( int i = 0; i < numPolys; ++i)
	{
		const unsigned short* p = &polygons[i * numVertsPerPoly * 2];

		unsigned short vi[3];
		for(int j = 2; j < numVertsPerPoly; ++j)
		{
			if(p[j] == RC_MESH_NULL_IDX) break;
			vi[0] = p[0];
			vi[1] = p[j-1];
			vi[2] = p[j];
			for(int k = 0; k < 3; ++k)
			{
				const unsigned short* v = &vertices[vi[k]*3];
				const float x = origin[0] + v[0] * _recastParams.getCellSize();
				const float y = origin[1] + v[1] * _recastParams.getCellHeight();
				const float z = origin[2] + v[2] * _recastParams.getCellSize();

				manObj->position(x,y,z);
			}
			manObj->triangle(nIndex,nIndex+1,nIndex+2);
			nIndex += 3;
		}
	}

	manObj->end();

	return manObj;
}
Exemple #22
0
Ogre::SceneNode* SideVerifier::createSceneNode(Ogre::SceneNode* parent, std::string name,
                                               Ogre::Vector3 defaultTranslate)
{
    Ogre::SceneNode* node = parent->createChildSceneNode(name);
    node->translate(defaultTranslate);

    Ogre::ManualObject* myManualObject = new Ogre::ManualObject("manual1" + name);

    myManualObject->begin("manual1Material", Ogre::RenderOperation::OT_LINE_LIST);
    myManualObject->position(0, 0, 0);
    myManualObject->position(0, 0, -1);
    myManualObject->end();

    //DEBUG
//    node->attachObject(myManualObject);

    return node;
}
Exemple #23
0
 void RenderSystem::RenderMesh3D(std::string meshName, std::string materialName, const MagicDGP::Mesh3D* pMesh)
 {
     InfoLog << "RenderSystem::RenderMesh3D" << std::endl;
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(meshName))
     {
         pMObj = mpSceneMgr->getManualObject(meshName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(meshName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     pMObj->begin(materialName, Ogre::RenderOperation::OT_TRIANGLE_LIST);
     int vertNum = pMesh->GetVertexNumber();
     for (int i = 0; i < vertNum; i++)
     {
         const MagicDGP::Vertex3D* pVert = pMesh->GetVertex(i);
         MagicMath::Vector3 pos = pVert->GetPosition();
         MagicMath::Vector3 nor = pVert->GetNormal();
         MagicMath::Vector3 color = pVert->GetColor();
         pMObj->position(pos[0], pos[1], pos[2]);
         pMObj->normal(nor[0], nor[1], nor[2]);
         pMObj->colour(color[0], color[1], color[2]);
     }
     int faceNum = pMesh->GetFaceNumber();
     for (int i = 0; i < faceNum; i++)
     {
         if (pMesh->GetFace(i)->IsValid())
         {
             const MagicDGP::Edge3D* pEdge = pMesh->GetFace(i)->GetEdge();
             pMObj->triangle(pEdge->GetVertex()->GetId(), pEdge->GetNext()->GetVertex()->GetId(), pEdge->GetPre()->GetVertex()->GetId());
         }
     }
     pMObj->end();
 }
Ogre::MeshPtr Path::realizeMesh(const std::string& name)
{
    Ogre::SceneManager *smgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second;
    Ogre::ManualObject * manual = smgr->createManualObject();
    manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);

    for (std::vector<Ogre::Vector3>::iterator itPos = mPoints.begin(); itPos != mPoints.end(); itPos++)
        manual->position(*itPos);
    if (mClosed)
        manual->position(*(mPoints.begin()));
    manual->end();

    Ogre::MeshPtr mesh;
    if (name=="")
        mesh = manual->convertToMesh(Utils::getName());
    else
        mesh = manual->convertToMesh(name);

    return mesh;
}
Exemple #25
0
 void RenderSystem::RenderLightMesh3DWithTexture(std::string meshName, std::string materialName, const MagicDGP::LightMesh3D* pMesh)
 {
     InfoLog << "RenderSystem::RenderMesh3D" << std::endl;
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(meshName))
     {
         pMObj = mpSceneMgr->getManualObject(meshName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(meshName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     pMObj->begin(materialName, Ogre::RenderOperation::OT_TRIANGLE_LIST);
     int vertNum = pMesh->GetVertexNumber();
     for (int i = 0; i < vertNum; i++)
     {
         const MagicDGP::Vertex3D* pVert = pMesh->GetVertex(i);
         MagicMath::Vector3 pos = pVert->GetPosition();
         MagicMath::Vector3 nor = pVert->GetNormal();
         MagicMath::Vector3 texCord = pVert->GetTexCord();
         pMObj->position(pos[0], pos[1], pos[2]);
         pMObj->normal(nor[0], nor[1], nor[2]);
         pMObj->textureCoord(texCord[0], texCord[1]);
     }
     int faceNum = pMesh->GetFaceNumber();
     for (int i = 0; i < faceNum; i++)
     {
         MagicDGP::FaceIndex faceIdx = pMesh->GetFace(i);
         pMObj->triangle(faceIdx.mIndex[0], faceIdx.mIndex[1], faceIdx.mIndex[2]);
     }
     pMObj->end();
 }
Exemple #26
0
void
	Player::drawLine(std::string bone, int joint1, int joint2)
{
	if (!initSkel)
		createLine(bone, joint1, joint2);
	else if (initSkel)
	{
		vector<Ogre::Vector3> skeletonNodes = mKinect->getSkeletonNodes();
		Ogre::ManualObject* myManualObject = mSceneManager->getManualObject(bone);

		myManualObject->clear();

		Ogre::Vector3 bone1 = 20 * skeletonNodes[joint1] + Ogre::Vector3(-50, 30, 20);
		Ogre::Vector3 bone2 = 20 * skeletonNodes[joint2] + Ogre::Vector3(-50, 30, 20);

		myManualObject->begin(bone + "Material", Ogre::RenderOperation::OT_LINE_LIST);
		myManualObject->position(bone1.x, bone1.y, bone1.z); 
		myManualObject->position(bone2.x, bone2.y, bone2.z); 
		myManualObject->end();
	}
}
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);
}
Exemple #28
0
void OgreExporter_c::ExportWallMesh(Ogre::ManualObject &manualMesh, int floorHeight, int ceilingHeight, Name_u textureName, int offsetX, int offsetY, const Vertex_s *vertices, const LineDef_s &lineDef, const WadFile_c &wad)
{
	std::stringstream stream;
	stream << textureName.ToString();
	manualMesh.begin(stream.str(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

	const Texture_s &tex = wad.GetTextureInfo(textureName);

	const Vertex_s &startVertex = vertices[lineDef.iStartVertex];
	const Vertex_s &endVertex = vertices[lineDef.iEndVertex];

	int height = ceilingHeight - floorHeight;	
	int width = Ogre::Vector2(startVertex.iX, startVertex.iY).distance(Ogre::Vector2(endVertex.iX, endVertex.iY));
	
	float offsetU = offsetX / (float) tex.uWidth;
	float offsetV = offsetY / (float) tex.uHeight;	

	float endV = (height / (float)tex.uHeight) + offsetV;
	float endU = (width / (float) tex.uWidth) + offsetU;

	manualMesh.position(-startVertex.iX, floorHeight, startVertex.iY);
	manualMesh.textureCoord(offsetU, endV);

	manualMesh.position(-startVertex.iX, ceilingHeight, startVertex.iY);
	manualMesh.textureCoord(offsetU, offsetV);
	
	manualMesh.position(-endVertex.iX, ceilingHeight, endVertex.iY);
	manualMesh.textureCoord(endU, offsetV);		

	manualMesh.position(-endVertex.iX, floorHeight, endVertex.iY);
	manualMesh.textureCoord(endU, endV);	

	manualMesh.triangle(2, 1, 0);
	manualMesh.triangle(0, 3, 2);

	manualMesh.end();
}
Exemple #29
0
    /**
     * This is the most basic "triangle" example, done as a Scene in Ogre.
     */
    Ogre::SceneManager* createTriangleScene() {
        Ogre::SceneManager* scene = mRoot->createSceneManager(Ogre::ST_GENERIC);

        // Configure camera (~ view & projection transforms, i.e. gluLookAt + glOrtho)
        Ogre::Camera* camera = scene->createCamera("MainCamera"); // We can use an arbitrary name here
        camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
        camera->setOrthoWindow(2, 2);              // ~ glOrtho(-1, 1, -1, 1)
        camera->setAspectRatio((float) mWindow->getWidth() / mWindow->getHeight());
        camera->setNearClipDistance(0.5);
        camera->setPosition(Ogre::Vector3(0,0,1)); // Move camera away from (0, 0, 0), otherwise the triangle at z=0 will be clipped

        // Now add some geometry to the scene
        Ogre::ManualObject* triangle = scene->createManualObject("Triangle");

        // ~ glBegin, glVertex, glEnd
        // "BaseWhiteNoLighting" is a built-in name for a basic non-lit material
        triangle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
        triangle->position(0, 0.5, 0);            // ~ glVertex.
                                                  // Contrary to OpenGL we *first* must create the vertex
        triangle->colour(Ogre::ColourValue::Red); // .. and then provide its attributes such as color (~ glColor)
        triangle->position(-0.5, -0.5, 0);
        triangle->colour(Ogre::ColourValue::Green);
        triangle->position(0.5, -0.5, 0);
        triangle->colour(Ogre::ColourValue::Blue);
        triangle->end();

        // Add the created triangle object to the scene graph
        // For this we create a SceneNode object, which will combine information about
        // the object's geometry with its modeling transform
        // (see frameRenderingQueued to understand how to rotate the triangle by changing this transform)
        scene->getRootSceneNode()->createChildSceneNode("Triangle")->attachObject(triangle);

        // Exercise 1: Create new object, add vertices, attach the object to a new SceneNode
        // ...

        return scene;
    }
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);
}