当前位置: 首页>>代码示例>>C++>>正文


C++ ManualObject::normal方法代码示例

本文整理汇总了C++中ogre::ManualObject::normal方法的典型用法代码示例。如果您正苦于以下问题:C++ ManualObject::normal方法的具体用法?C++ ManualObject::normal怎么用?C++ ManualObject::normal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ogre::ManualObject的用法示例。


在下文中一共展示了ManualObject::normal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toMesh

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;
}
开发者ID:carnoot,项目名称:gazebo_pcl_project,代码行数:52,代码来源:stl_loader.cpp

示例2:

 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();
     }
     
 }
开发者ID:jinghuaguo,项目名称:magic3d,代码行数:60,代码来源:RenderSystem.cpp

示例3: CreateExplosionParticleGeometry

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);

}
开发者ID:WilliamCreber,项目名称:COMP3501_EOY_Project,代码行数:51,代码来源:ParticleFactory.cpp

示例4: addQuad

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();
	}
}
开发者ID:BeanOfLight,项目名称:BeanOfLight,代码行数:58,代码来源:ProceduralShape.cpp

示例5: malloc

//-------------------------------------------------------------------------------------
Ogre::ManualObject* const DigitalForensicsVisualisation::rectangle(std::string matName)
{

	char* name = (char*) malloc (32);
	sprintf(name, "rect%d", app.rectCount++);

	Ogre::ManualObject* rect = mSceneMgr->createManualObject(name);
	rect->begin(matName, Ogre::RenderOperation::OT_TRIANGLE_LIST);

	rect->position(100,100.1,0);
	rect->textureCoord(1,0);
	rect->normal(50,500,50);

	rect->position(0,100.1,100);
	rect->textureCoord(0,1);
	rect->normal(50,500,50);

	rect->position(0,100.1,0);
	rect->textureCoord(0,0);
	rect->normal(50,500,50);

	rect->position(100,100.1,100);
	rect->textureCoord(1,1);
	rect->normal(50,500,50);

	rect->triangle(2,1,0);
	rect->triangle(1,3,0);
	
	rect->end();
	free(name);


	return rect;


}
开发者ID:ljmu-cms,项目名称:digital-forensics-visualisation,代码行数:37,代码来源:DigitalForensicsVisualisation.cpp

示例6: createCubeMesh

//Copied from BetaCairo demo : http://www.ogre3d.org/forums/viewtopic.php?t=26987 (created by betajaen)
Ogre::ManualObject* OgreAppLogic::createCubeMesh(const std::string& name, const std::string& matName)
{
	Ogre::ManualObject* cube = new Ogre::ManualObject(name);
	cube->begin(matName);

	cube->position(0.500000,-0.500000,1.000000);
	cube->normal(0.408248f,-0.816497f,0.408248f);
	cube->textureCoord(1,0);


	cube->position(-0.500000,-0.500000,0.000000);
	cube->normal(-0.408248f,-0.816497f,-0.408248f);
	cube->textureCoord(0,1);

	cube->position(0.500000,-0.500000,0.000000);
	cube->normal(0.666667f,-0.333333f,-0.666667f);
	cube->textureCoord(1,1);

	cube->position(-0.500000,-0.500000,1.000000);
	cube->normal(-0.666667f,-0.333333f,0.666667f);
	cube->textureCoord(0,0);

	cube->position(0.500000,0.500000,1.000000);
	cube->normal(0.666667f,0.333333f,0.666667f);
	cube->textureCoord(1,0);

	cube->position(-0.500000,-0.500000,1.000000);
	cube->normal(-0.666667f,-0.333333f,0.666667f);
	cube->textureCoord(0,1);

	cube->position(0.500000,-0.500000,1.000000);
	cube->normal(0.408248f,-0.816497f,0.408248f);
	cube->textureCoord(1,1);

	cube->position(-0.500000,0.500000,1.000000);
	cube->normal(-0.408248f,0.816497f,0.408248f);
	cube->textureCoord(0,0);

	cube->position(-0.500000,0.500000,0.000000);
	cube->normal(-0.666667f,0.333333f,-0.666667f);
	cube->textureCoord(0,1);

	cube->position(-0.500000,-0.500000,0.000000);
	cube->normal(-0.408248f,-0.816497f,-0.408248f);
	cube->textureCoord(1,1);

	cube->position(-0.500000,-0.500000,1.000000);
	cube->normal(-0.666667f,-0.333333f,0.666667f);
	cube->textureCoord(1,0);

	cube->position(0.500000,-0.500000,0.000000);
	cube->normal(0.666667f,-0.333333f,-0.666667f);
	cube->textureCoord(0,1);

	cube->position(0.500000,0.500000,0.000000);
	cube->normal(0.408248f,0.816497f,-0.408248f);
	cube->textureCoord(1,1);

	cube->position(0.500000,-0.500000,1.000000);
	cube->normal(0.408248f,-0.816497f,0.408248f);
	cube->textureCoord(0,0);

	cube->position(0.500000,-0.500000,0.000000);
	cube->normal(0.666667f,-0.333333f,-0.666667f);
	cube->textureCoord(1,0);

	cube->position(-0.500000,-0.500000,0.000000);
	cube->normal(-0.408248f,-0.816497f,-0.408248f);
	cube->textureCoord(0,0);

	cube->position(-0.500000,0.500000,1.000000);
	cube->normal(-0.408248f,0.816497f,0.408248f);
	cube->textureCoord(1,0);

	cube->position(0.500000,0.500000,0.000000);
	cube->normal(0.408248f,0.816497f,-0.408248f);
	cube->textureCoord(0,1);

	cube->position(-0.500000,0.500000,0.000000);
	cube->normal(-0.666667f,0.333333f,-0.666667f);
	cube->textureCoord(1,1);

	cube->position(0.500000,0.500000,1.000000);
	cube->normal(0.666667f,0.333333f,0.666667f);
	cube->textureCoord(0,0);

	cube->triangle(0,1,2);
	cube->triangle(3,1,0);
	cube->triangle(4,5,6);
	cube->triangle(4,7,5);
	cube->triangle(8,9,10);
	cube->triangle(10,7,8);
	cube->triangle(4,11,12);
	cube->triangle(4,13,11);
	cube->triangle(14,8,12);
	cube->triangle(14,15,8);
	cube->triangle(16,17,18);
	cube->triangle(16,19,17);
	cube->end(); 
//.........这里部分代码省略.........
开发者ID:aufheben1,项目名称:visual-experiments,代码行数:101,代码来源:OgreAppLogic.cpp

示例7: addTerrainDecal

int DecalManager::addTerrainDecal(Ogre::Vector3 position, Ogre::Vector2 size, Ogre::Vector2 numSeg, Ogre::Real rotation, Ogre::String materialname, Ogre::String normalname)
{
#if 0
	Ogre::ManualObject *mo = gEnv->ogreSceneManager->createManualObject();
	String oname = mo->getName();
	SceneNode *mo_node = terrain_decals_snode->createChildSceneNode();

	mo->begin(materialname, Ogre::RenderOperation::OT_TRIANGLE_LIST);
	AxisAlignedBox *aab=new AxisAlignedBox();
	float uTile = 1, vTile = 1;

	Vector3 normal = Vector3(0,1,0); // UP
	
	int offset = 0;
	float ground_dist = 0.001f;

	Ogre::Vector3 vX = normal.perpendicular();
	Ogre::Vector3 vY = normal.crossProduct(vX);
	Ogre::Vector3 delta1 = size.x / numSeg.x * vX;
	Ogre::Vector3 delta2 = size.y / numSeg.y * vY;
	// build one corner of the square
	Ogre::Vector3 orig = -0.5*size.x*vX - 0.5*size.y*vY;

	for (int i1 = 0; i1<=numSeg.x; i1++)
		for (int i2 = 0; i2<=numSeg.y; i2++)
		{
			Vector3 pos = orig+i1*delta1+i2*delta2 + position;
			pos.y = hfinder->getHeightAt(pos.x, pos.z) + ground_dist;
			mo->position(pos);
			aab->merge(pos);
			mo->textureCoord(i1/(Ogre::Real)numSeg.x*uTile, i2/(Ogre::Real)numSeg.y*vTile);
			mo->normal(normal);
		}

	bool reverse = false;
	if (delta1.crossProduct(delta2).dotProduct(normal)>0)
		reverse= true;
	for (int n1 = 0; n1<numSeg.x; n1++)
	{
		for (int n2 = 0; n2<numSeg.y; n2++)
		{
			if (reverse)
			{
				mo->index(offset+0);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+1);
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+(numSeg.y+1)+1);
			}
			else
			{
				mo->index(offset+0);
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1));
				mo->index(offset+1);
				mo->index(offset+(numSeg.y+1)+1);
				mo->index(offset+(numSeg.y+1));
			}
			offset++;
		}
		offset++;
	}
	offset+=numSeg.y+1;

	mo->end();
	mo->setBoundingBox(*aab);
	// some optimizations
	mo->setCastShadows(false);
	mo->setDynamic(false);
	delete(aab);

	MeshPtr mesh = mo->convertToMesh(oname+"_mesh");

	// build edgelist
	mesh->buildEdgeList();

	// remove the manualobject again, since we dont need it anymore
	gEnv->ogreSceneManager->destroyManualObject(mo);

	unsigned short src, dest;
	if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
	{
		mesh->buildTangentVectors(VES_TANGENT, src, dest);
	}
	
	Entity *ent = gEnv->ogreSceneManager->createEntity(oname+"_ent", oname+"_mesh");
	mo_node->attachObject(ent);

	mo_node->setVisible(true);
	//mo_node->showBoundingBox(true);
	mo_node->setPosition(Vector3::ZERO); //(position.x, 0, position.z));


	// RTSS
	//Ogre::RTShader::ShaderGenerator::getSingleton().createShaderBasedTechnique(materialname, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
	//Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, materialname);
	RTSSgenerateShadersForMaterial(materialname, normalname);

#endif
//.........这里部分代码省略.........
开发者ID:Aperion,项目名称:rigsofrods-next-stable,代码行数:101,代码来源:DecalManager.cpp

示例8: UpdateTerrain

// Given a scene node for a terrain, find the manual object on that scene node and
// update the manual object with the heightmap passed. If  there is no manual object on
// the scene node, remove all it's attachments and add the manual object.
// The heightmap is passed in a 1D array ordered by width rows (for(width) {for(length) {hm[w,l]}})
// This must be called between frames since it touches the scene graph
// BETWEEN FRAME OPERATION
void Region::UpdateTerrain(const int hmWidth, const int hmLength, const float* hm) {
	Ogre::SceneNode* node = this->TerrainSceneNode;
	LG::Log("Region::UpdateTerrain: updating terrain for region %s", this->Name.c_str());

	if (node == NULL) {
		LG::Log("Region::UpdateTerrain: terrain scene node doesn't exist. Not updating terrain.");
		return;
	}

	// Find the movable object attached to the scene node. If not found remove all.
	if (node->numAttachedObjects() > 0) {
		Ogre::MovableObject* attached = node->getAttachedObject(0);
		if (attached->getMovableType() != "ManualObject") {
            // don't know why this would ever happen but clean out the odd stuff
            LG::Log("Found extra stuff on terrain scene node");
			node->detachAllObjects();
		}
	}
	// if there is not a manual object on the node, create a new one
	if (node->numAttachedObjects() == 0) {
		LG::Log("Region::UpdateTerrain: creating terrain ManualObject for region %s", this->Name.c_str());
        // if no attached objects, we add our dynamic ManualObject
		Ogre::ManualObject* mob = LG::RendererOgre::Instance()->m_sceneMgr->createManualObject("ManualObject/" + node->getName());
		mob->addQueryFlags(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
		mob->setDynamic(true);
		mob->setCastShadows(true);
		mob->setVisible(true);
		node->attachObject(mob);
		// m_visCalc->RecalculateVisibility();
	}

	Ogre::ManualObject* mo = (Ogre::ManualObject*)node->getAttachedObject(0);

	// stuff our heightmap information into the dynamic manual object
	mo->estimateVertexCount(hmWidth * hmLength);
	mo->estimateIndexCount(hmWidth * hmLength * 6);

	if (mo->getNumSections() == 0) {
		// if first time
		mo->begin(LG::GetParameter("Renderer.Ogre.DefaultTerrainMaterial"));
	}
	else {
		mo->beginUpdate(0);					// we've been here before
	}

	int loc = 0;
	for (int xx = 0; xx < hmWidth; xx++) {
		for (int yy = 0; yy < hmLength; yy++) {
			mo->position((Ogre::Real)xx, (Ogre::Real)yy, hm[loc++]);
			mo->textureCoord((float)xx / (float)hmWidth, (float)yy / (float)hmLength);
			mo->normal(0.0, 1.0, 0.0);	// always up (for the moment)
		}
	}

	for (int px = 0; px < hmLength-1; px++) {
		for (int py = 0; py < hmWidth-1; py++) {
			mo->quad(px      + py       * hmWidth,
					 px      + (py + 1) * hmWidth,
					(px + 1) + (py + 1) * hmWidth,
					(px + 1) + py       * hmWidth
					 );
		}
	}

	mo->end();

	return;
}
开发者ID:Misterblue,项目名称:LookingGlass-Viewer,代码行数:74,代码来源:Region.cpp

示例9: CreateThrusterParticleGeometry

void ParticleFactory::CreateThrusterParticleGeometry(Ogre::String object_name, int num_particles, float loop_radius, float circle_radius){

	//try {
		/* 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 torus: we will sample points on the surface of the torus */

		
		float maxspray = 1.5; // This is how much we allow the points to wander around
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Randomly select two numbers to define a point on the torus
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            
			// Use u and v to define the point on the torus
            theta = u * Ogre::Math::TWO_PI;
			phi = v * Ogre::Math::TWO_PI;
			Ogre::Vector3 center = Ogre::Vector3(loop_radius*cos(theta), loop_radius*sin(theta), 0.0);
            Ogre::Vector3 normal = Ogre::Vector3(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));
			object->position(center + normal*circle_radius); // Position of the point
			object->colour(Ogre::ColourValue(((float) i)/((float) num_particles), 0.0, 1.0 - (((float) i)/((float) num_particles))));
			object->textureCoord(Ogre::Vector2(0.0, 0.0));

			// Now sample a point on a sphere to define a direction for points to wander around
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
			w = ((double) rand() / (RAND_MAX));
			
			theta = u * Ogre::Math::TWO_PI;
			phi = acos(2.0*v * -1.0);
			spray = maxspray*pow((float) w, (float) (1.0/4.0)); // Cubic root
			Ogre::Vector3 wander = Ogre::Vector3(spray*cos(theta)*cos(phi), spray*cos(theta)*sin(phi), sin(phi)*-2);

			object->normal(wander);
		}

		object->position(Ogre::Vector3(0.0f, 0.0f, -30.0f));
		object->colour(Ogre::ColourValue(0.0f, 0.0f, 0.0f));
		object->textureCoord(Ogre::Vector2(0.0f, 0.0f));
		object->normal(Ogre::Vector3(0.0f, 0.0f, -30.0f));

        object->end();
		
		
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);
  /*  }
    catch (Ogre::Exception &e){
        throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what())));
    }
    catch(std::exception &e){
        throw(OgreAppException(std::string("std::Exception: ") + std::string(e.what())));
    }*/
}
开发者ID:WilliamCreber,项目名称:COMP3501_EOY_Project,代码行数:71,代码来源:ParticleFactory.cpp

示例10: CreateWall

void OgreApplication::CreateWall(Ogre::String material_name){
	    
	try {

		/* Create two rectangles */

        /* 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;
        Ogre::String object_name = "Wall";
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);

        /* Create triangle list for the object */
        object->begin(material_name, Ogre::RenderOperation::OT_TRIANGLE_LIST);

		/* Add vertices */
		/* One side of the "wall" */
		object->position(-1.0,-1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(1.0, 0.0);

        object->position(-1.0,1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(1.0, 1.0);

        object->position(1.0,1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(0.0, 1.0);

        object->position(1.0,-1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(0.0, 0.0);

		/* The other side of the "wall" */
        object->position(-1.0,-1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(0.0, 0.0);

        object->position(-1.0,1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(0.0, 1.0);

        object->position(1.0,1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(1.0, 1.0);

        object->position(1.0,-1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(1.0, 0.0);
        
		/* Add triangles */
		/* One side */
		object->triangle(0, 1, 2);
        object->triangle(0, 2, 3);
		/* The other side */
        object->triangle(4, 7, 6);
        object->triangle(4, 6, 5);
        
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        Ogre::String mesh_name = "Wall";
        object->convertToMesh(mesh_name);

        /* Create one instance of the sphere (one entity) */
		/* The same object can have multiple instances or entities */
        Ogre::Entity* entity = scene_manager->createEntity(mesh_name);

		/* Apply a material to the entity to give it color */
		/* We already did that above, so we comment it out here */
		/* entity->setMaterialName(material_name); */
		/* But, this call is useful if we have multiple entities with different materials */

		/* Create a scene node for the entity */
		/* The scene node keeps track of the entity's position */
        Ogre::SceneNode* scene_node = root_scene_node->createChildSceneNode(mesh_name);
        scene_node->attachObject(entity);

        /* Position and rotate the entity with the scene node */
		//scene_node->rotate(Ogre::Vector3(0, 1, 0), Ogre::Degree(60));
		//scene_node->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(30));
		//scene_node->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(-90));
        //scene_node->translate(0.0, 0.0, 0.0);
		scene_node->scale(0.5, 0.5, 0.5);
    }
    catch (Ogre::Exception &e){
        throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what())));
//.........这里部分代码省略.........
开发者ID:FanZhang10,项目名称:NormalMap,代码行数:101,代码来源:ogre_application.cpp

示例11:

Ogre::ManualObject* BasicTutorial2::createCubeMesh (Ogre::String name, Ogre::String matName) 
{
   Ogre::ManualObject* cube = new Ogre::ManualObject(name);
   cube->begin(matName);
 
   cube->position(0.5f,-0.5f,1.0f);cube->normal(0.408248f,-0.816497f,0.408248f);cube->textureCoord(1,0);
   cube->position(-0.5f,-0.5f,0.0f);cube->normal(-0.408248f,-0.816497f,-0.408248f);cube->textureCoord(0,1);
   cube->position(0.5f,-0.5f,0.0f);cube->normal(0.666667f,-0.333333f,-0.666667f);cube->textureCoord(1,1);
   cube->position(-0.5f,-0.5f,1.0f);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,0);
   cube->position(0.5f,0.5f,1.0f);cube->normal(0.666667f,0.333333f,0.666667f);cube->textureCoord(1,0);
   cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,1);
   cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248f);cube->textureCoord(1,1);
   cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(0,0);
   cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(0,1);
   cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(1,1);
   cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667,-0.333333,0.666667);cube->textureCoord(1,0);
   cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(0,1);
   cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(1,1);
   cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248);cube->textureCoord(0,0);
   cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(1,0);
   cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(0,0);
   cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(1,0);
   cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(0,1);
   cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(1,1);
   cube->position(0.5,0.5,1.0);cube->normal(0.666667,0.333333,0.666667);cube->textureCoord(0,0);
 
   cube->triangle(0,1,2);      cube->triangle(3,1,0);
   cube->triangle(4,5,6);      cube->triangle(4,7,5);
   cube->triangle(8,9,10);      cube->triangle(10,7,8);
   cube->triangle(4,11,12);   cube->triangle(4,13,11);
   cube->triangle(14,8,12);   cube->triangle(14,15,8);
   cube->triangle(16,17,18);   cube->triangle(16,19,17);
   cube->end();
 
   return cube;
}
开发者ID:asvsfs,项目名称:TheJourney,代码行数:36,代码来源:BasicTutorial2.cpp

示例12: generateMeshObstacles

void Map::generateMeshObstacles(std::string materialName)
{
    Ogre::ManualObject* obstacles = new Ogre::ManualObject("obstacles");
    obstacles->estimateIndexCount(m_length * m_width * 8);
    obstacles->estimateVertexCount(m_length * m_width * 8);
    obstacles->clear();
    obstacles->begin(materialName);

    Ogre::Vector3 pos = Ogre::Vector3(0, 0, 0);
    Ogre::Quaternion quat;
    Ogre::Quaternion quatNext;
    unsigned long planeNum = 0;

    m_obstaclePositions.clear();

    for (unsigned int i = 0; i < m_length; i++) {
        quat = m_rotationalSpline.getPoint(i);
        quatNext = m_rotationalSpline.getPoint(i + 1);

        for (int x = -100 * (m_width / (double) 2), j = 0; (unsigned) j < m_width; j++, x += 100) {
            int back = -100;
            int left = x;
            int right = x + 100;
            int up = 100;

            Ogre::Vector3 nextPos =             pos + quat * Ogre::Vector3(0, 0, back);
            Ogre::Vector3 posMinus50 =          pos + quat * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 posPlus50 =           pos + quat * Ogre::Vector3(right, 0, 0);
            Ogre::Vector3 nextPosMinus50 =      nextPos + quatNext * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 nextPosPlus50 =       nextPos + quatNext * Ogre::Vector3(right, 0, 0);

            //TODO: fix normals
            obstacles->position(posMinus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(1, 1);
            obstacles->position(nextPosMinus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(1, 0);
            obstacles->position(posPlus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(0, 1);
            obstacles->position(nextPosPlus50);
            obstacles->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            obstacles->textureCoord(0, 0);

            Ogre::Vector3 nextPosUp =           nextPos + quat * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 posMinus50Up =        posMinus50 + quat * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 posPlus50Up =         posPlus50 + quat * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 nextPosMinus50Up =    nextPosMinus50 + quatNext * Ogre::Vector3(0, up, 0);
            Ogre::Vector3 nextPosPlus50Up =     nextPosPlus50 + quatNext * Ogre::Vector3(0, up, 0);

            //TODO: fix normals
            obstacles->position(posMinus50Up);
            obstacles->normal((quat * Vector3(-1, 1, 1)).normalisedCopy());
            obstacles->textureCoord(0, 0);
            obstacles->position(nextPosMinus50Up);
            obstacles->normal((quat * Vector3(-1, 1, -1)).normalisedCopy());
            obstacles->textureCoord(0, 1);
            obstacles->position(posPlus50Up);
            obstacles->normal((quat * Vector3(1, 1, 1)).normalisedCopy());
            obstacles->textureCoord(1, 0);
            obstacles->position(nextPosPlus50Up);
            obstacles->normal((quat * Vector3(1, 1, -1)).normalisedCopy());
            obstacles->textureCoord(1, 1);

            if (m_cubes[planeNum / (double) m_width][planeNum % m_width] == OBSTACLE) {

                //TODO: check if this hack works..
                m_obstaclePositions.push_back(posMinus50);

                //top
                obstacles->triangle(4 + planeNum * 8, 5 + planeNum * 8, 6 + planeNum * 8);
                obstacles->triangle(6 + planeNum * 8, 5 + planeNum * 8, 4 + planeNum * 8);
                obstacles->triangle(5 + planeNum * 8, 7 + planeNum * 8, 6 + planeNum * 8);
                obstacles->triangle(6 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);

                if (planeNum % m_width == 0 || m_cubes[planeNum / (double) m_width][(planeNum - 1) % m_width] != OBSTACLE) {
                    //left
                    obstacles->triangle(0 + planeNum * 8, 4 + planeNum * 8, 5 + planeNum * 8);
                    obstacles->triangle(5 + planeNum * 8, 4 + planeNum * 8, 0 + planeNum * 8);
                    obstacles->triangle(0 + planeNum * 8, 1 + planeNum * 8, 5 + planeNum * 8);
                    obstacles->triangle(5 + planeNum * 8, 1 + planeNum * 8, 0 + planeNum * 8);
                }

                if (planeNum % m_width == m_width - 1 || m_cubes[planeNum / (double) m_width][(planeNum + 1) % m_width] != OBSTACLE) {
                    //right
                    obstacles->triangle(2 + planeNum * 8, 6 + planeNum * 8, 7 + planeNum * 8);
                    obstacles->triangle(7 + planeNum * 8, 6 + planeNum * 8, 2 + planeNum * 8);
                    obstacles->triangle(2 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    obstacles->triangle(7 + planeNum * 8, 3 + planeNum * 8, 2 + planeNum * 8);
                }

                if (planeNum / (double) m_width >= m_length - 1 || m_cubes[(planeNum + m_width) / (double) m_width][planeNum % m_width] != OBSTACLE) {
                    //back
                    obstacles->triangle(5 + planeNum * 8, 7 + planeNum * 8, 1 + planeNum * 8);
                    obstacles->triangle(1 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);
                    obstacles->triangle(1 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    obstacles->triangle(7 + planeNum * 8, 3 + planeNum * 8, 1 + planeNum * 8);
                }

//.........这里部分代码省略.........
开发者ID:prettyv,项目名称:rauschabstand,代码行数:101,代码来源:Map.cpp

示例13: generateMesh

void Map::generateMesh(std::string materialName)
{
    Ogre::ManualObject* plane = new Ogre::ManualObject("plane");
    plane->estimateIndexCount(m_length * m_width * 8);
    plane->estimateVertexCount(m_length * m_width * 8);
    plane->clear();
    plane->begin(materialName);

    Ogre::Vector3 pos = Ogre::Vector3(0, 0, 0);
    Ogre::Quaternion quat;
    Ogre::Quaternion quatNext;
    unsigned long planeNum = 0;

    for (unsigned int i = 0; i < m_length; i++) {
        quat = m_rotationalSpline.getPoint(i);
        quatNext = m_rotationalSpline.getPoint(i + 1);

        for (int x = -100 * (m_width / (double) 2), j = 0; (unsigned) j < m_width; j++, x += 100) {
            int back = -100;
            int left = x;
            int right = x + 100;
            int down = -20 ;

            Ogre::Vector3 nextPos =             pos + quat * Ogre::Vector3(0, 0, back);
            Ogre::Vector3 posMinus50 =          pos + quat * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 posPlus50 =           pos + quat * Ogre::Vector3(right, 0, 0);
            Ogre::Vector3 nextPosMinus50 =      nextPos + quatNext * Ogre::Vector3(left, 0, 0);
            Ogre::Vector3 nextPosPlus50 =       nextPos + quatNext * Ogre::Vector3(right, 0, 0);

            //TODO: fix normals?
            plane->position(posMinus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(1, 1);
            plane->position(nextPosMinus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(1, 0);
            plane->position(posPlus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(0, 1);
            plane->position(nextPosPlus50);
            plane->normal((quat * Vector3(0, 1, 0)).normalisedCopy());
            plane->textureCoord(0, 0);

            Ogre::Vector3 nextPosDown =         nextPos + quat * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 posMinus50Down =      posMinus50 + quat * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 posPlus50Down =       posPlus50 + quat * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 nextPosMinus50Down =  nextPosMinus50 + quatNext * Ogre::Vector3(0, down, 0);
            Ogre::Vector3 nextPosPlus50Down =   nextPosPlus50 + quatNext * Ogre::Vector3(0, down, 0);

            //TODO: fix normals?
            plane->position(posMinus50Down);
            plane->normal((quat * Vector3(-1, -1, 1)).normalisedCopy());
            plane->textureCoord(0, 0);
            plane->position(nextPosMinus50Down);
            plane->normal((quat * Vector3(-1, -1, -1)).normalisedCopy());
            plane->textureCoord(0, 1);
            plane->position(posPlus50Down);
            plane->normal((quat * Vector3(1, -1, 1)).normalisedCopy());
            plane->textureCoord(1, 0);
            plane->position(nextPosPlus50Down);
            plane->normal((quat * Vector3(1, -1, -1)).normalisedCopy());
            plane->textureCoord(1, 1);

            if (m_cubes[planeNum / (double) m_width][planeNum % m_width] != HOLE) {
                //if (m_cubes[planeNum / (double) m_width][planeNum % m_width] == NORMAL)
                //{
                //top
                plane->triangle(0 + planeNum * 8, 1 + planeNum * 8, 2 + planeNum * 8);
                plane->triangle(2 + planeNum * 8, 1 + planeNum * 8, 0 + planeNum * 8);
                plane->triangle(1 + planeNum * 8, 3 + planeNum * 8, 2 + planeNum * 8);
                plane->triangle(2 + planeNum * 8, 3 + planeNum * 8, 1 + planeNum * 8);
                //}

                //bottom
                plane->triangle(4 + planeNum * 8, 5 + planeNum * 8, 6 + planeNum * 8);
                plane->triangle(6 + planeNum * 8, 5 + planeNum * 8, 4 + planeNum * 8);
                plane->triangle(5 + planeNum * 8, 7 + planeNum * 8, 6 + planeNum * 8);
                plane->triangle(6 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);

                if (planeNum % m_width == 0 || m_cubes[planeNum / (double) m_width][(planeNum - 1) % m_width] == HOLE) {
                    //left
                    plane->triangle(0 + planeNum * 8, 4 + planeNum * 8, 5 + planeNum * 8);
                    plane->triangle(5 + planeNum * 8, 4 + planeNum * 8, 0 + planeNum * 8);
                    plane->triangle(0 + planeNum * 8, 1 + planeNum * 8, 5 + planeNum * 8);
                    plane->triangle(5 + planeNum * 8, 1 + planeNum * 8, 0 + planeNum * 8);
                }

                if (planeNum % m_width == m_width - 1 || m_cubes[planeNum / (double) m_width][(planeNum + 1) % m_width] == HOLE) {
                    //right
                    plane->triangle(2 + planeNum * 8, 6 + planeNum * 8, 7 + planeNum * 8);
                    plane->triangle(7 + planeNum * 8, 6 + planeNum * 8, 2 + planeNum * 8);
                    plane->triangle(2 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
                    plane->triangle(7 + planeNum * 8, 3 + planeNum * 8, 2 + planeNum * 8);
                }

                if (planeNum / (double) m_width >= m_length - 1 || m_cubes[(planeNum + m_width) / (double) m_width][planeNum % m_width] == HOLE) {
                    //back
                    plane->triangle(5 + planeNum * 8, 7 + planeNum * 8, 1 + planeNum * 8);
                    plane->triangle(1 + planeNum * 8, 7 + planeNum * 8, 5 + planeNum * 8);
                    plane->triangle(1 + planeNum * 8, 3 + planeNum * 8, 7 + planeNum * 8);
//.........这里部分代码省略.........
开发者ID:prettyv,项目名称:rauschabstand,代码行数:101,代码来源:Map.cpp

示例14: readModel

void AssetLoader::readModel(Ogre::SceneManager* sceneMgr, Ogre::SceneNode* scnNode, const aiScene* scene, aiNode* nd)
{
	for (size_t n = 0; n < nd->mNumChildren; n++) 
	{	
		aiNode* cnd = nd->mChildren[n];
		Ogre::SceneNode* cnode = createChildSceneNodeWithTransform(scnNode, cnd);

		for (size_t i = 0; i < cnd->mNumMeshes; i++) {
			aiMesh* m = scene->mMeshes[cnd->mMeshes[i]];	
			aiMaterial* mat = scene->mMaterials[m->mMaterialIndex];

			std::string nodeName = getFullPathName(cnd);
			Ogre::MaterialPtr omat = createMaterial(Ogre::String(nodeName), m->mMaterialIndex, mat);

			aiVector3D* vec  = m->mVertices;
			aiVector3D* norm = m->mNormals;
			aiVector3D* uv   = m->mTextureCoords[0];
			aiColor4D*  vcol = NULL;	
			if (m->HasVertexColors(0)) vcol = m->mColors[0];

			// 頂点情報の読み込み
			Ogre::AxisAlignedBox aab;
			Ogre::ManualObject* mobj = new Ogre::ManualObject(nodeName+"_MObj");
			mobj->begin(omat->getName());
			//mobj->begin("Ogre/Skin");
			for (size_t n = 0; n < m->mNumVertices; n ++) {
				Ogre::Vector3 position(vec->x, vec->y, vec->z);
				aab.merge(position);

				mobj->position(vec->x, vec->y, vec->z); 
				vec++;  

				mobj->normal(norm->x, norm->y, norm->z);
				norm++; 

				if (uv)   { 
					mobj->textureCoord(uv->x, uv->y);        
					uv++;   
				}
				if (vcol) { 
					mobj->colour(vcol->r, vcol->g, vcol->b, vcol->a); 
					vcol++;
				}
			}

			// ポリゴンの構築
			for (size_t n = 0; n < m->mNumFaces; n++) {
				aiFace* face = &m->mFaces[n];
				for (size_t k = 0; k < face->mNumIndices; k++) {
					mobj->index(face->mIndices[k]);
				}
			}
			mobj->end();
			mobj->setBoundingBox(aab);

			Ogre::String meshName(nodeName+"_Mesh");
			mobj->convertToMesh(meshName);
			delete mobj;

			Ogre::String entityName(nodeName+"_Entity");
			std::cout << "entity: " << entityName << std::endl;
			Ogre::Entity* ent = sceneMgr->createEntity(entityName, meshName);
			cnode->attachObject(ent);
		}

		readModel(sceneMgr, cnode, scene, cnd);
	}
}
开发者ID:toshinoritakata,项目名称:OgreKinect,代码行数:68,代码来源:AssetLoader.cpp

示例15: CreateSplineParticleGeometry

void  ParticleFactory::CreateSplineParticleGeometry(Ogre::String object_name, int num_particles, float loop_radius, float circle_radius){

		/* Retrieve scene manager and root scene node */
        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 torus: we will sample points on a torus, but will allow the points to also
		   deviate a bit from the torus along the direction of a random vector */
        float maxspray = 0.5; // This is how much we allow the points to deviate along a normalized vector
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Get two random numbers
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            
			// Use u and v to define a point on the torus with angles theta and phi
            theta = u * Ogre::Math::TWO_PI;
			phi = v * Ogre::Math::TWO_PI;

			// Get center of loop and point's normal on the torus
			Ogre::Vector3 center = Ogre::Vector3(loop_radius*cos(theta), loop_radius*sin(theta), 0.0);
            Ogre::Vector3 normal = Ogre::Vector3(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));

			// Next, we want to let the points deviate along the direction of a random vector
			// To obtain a random vector, we sample a point on the sphere
			// The point on the sphere minus the origin (0, 0) is the random vector

			// Randomly select two numbers to define a point in spherical coordinates
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
			
			// Use u to define the angle theta along one direction of a sphere
			theta = u * Ogre::Math::TWO_PI;
			// Use v to define the angle phi along the other direction of the sphere
			phi = acos(2.0*v - 1.0);
			// Get the point on the sphere (equivalent to a normalized direction vector since the origin is zero)
			Ogre::Vector3 direct = Ogre::Vector3(cos(theta)*sin(phi), sin(theta)*sin(phi), -cos(phi));
			// We need z = -cos(phi) to make sure that the z coordinate runs from -1 to 1 as phi runs from 0 to pi

			// Now, multiply a random amount of deviation by this vector, which is the deviation we will add to the point on the torus
			w = ((double) rand() / (RAND_MAX));
			spray = maxspray*pow((float) w, (float) (1.0/3.0)); // cbrt(w);
			Ogre::Vector3 wander = Ogre::Vector3(spray*direct.x, spray*direct.y, direct.z);
				
			// Add computed quantities to the object
			object->position(center + normal*circle_radius);
			object->normal(wander);
			object->colour(Ogre::ColourValue(((float) i)/((float) num_particles), 0.0, 0.0)); // Store particle id in the red channel as a float
			object->textureCoord(Ogre::Vector2(0.0, 0.0));
		}
		
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);
   
}
开发者ID:WilliamCreber,项目名称:COMP3501_EOY_Project,代码行数:70,代码来源:ParticleFactory.cpp


注:本文中的ogre::ManualObject::normal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。