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


C++ SMesh::recalculateBoundingBox方法代码示例

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


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

示例1: init

	void init(const HeightMap &hm, f32 scale, colour_func cf, IVideoDriver *driver)
	{
		Scale = scale;

		const u32 mp = driver -> getMaximalPrimitiveCount();
		Width = hm.width();
		Height = hm.height();

		const u32 sw = mp / (6 * Height); // the width of each piece

		u32 i=0;
		for(u32 y0 = 0; y0 < Height; y0 += sw)
		{
			u16 y1 = y0 + sw;
			if (y1 >= Height)
				y1 = Height - 1; // the last one might be narrower
			addstrip(hm, cf, y0, y1, i);
			++i;
		}
		if (i<Mesh->getMeshBufferCount())
		{
			// clear the rest
			for (u32 j=i; j<Mesh->getMeshBufferCount(); ++j)
			{
				Mesh->getMeshBuffer(j)->drop();
			}
			Mesh->MeshBuffers.erase(i,Mesh->getMeshBufferCount()-i);
		}
		// set dirty flag to make sure that hardware copies of this
		// buffer are also updated, see IMesh::setHardwareMappingHint
		Mesh->setDirty();
		Mesh->recalculateBoundingBox();
	}
开发者ID:bacsmar,项目名称:irrlicht,代码行数:33,代码来源:main.cpp

示例2: init

	void init(const HeightMap &hm, f32 scale, colour_func cf, IVideoDriver *driver)
	{
		Scale = scale;

		const u32 mp = driver -> getMaximalPrimitiveCount();
		Width = hm.width();
		Height = hm.height();
		
		const u32 sw = mp / (6 * Height); // the width of each piece

		u32 i=0;
		for(u32 y0 = 0; y0 < Height; y0 += sw)
		{
			u16 y1 = y0 + sw;
			if (y1 >= Height)
				y1 = Height - 1; // the last one might be narrower
			addstrip(hm, cf, y0, y1, i);
			++i;
		}
		if (i<Mesh->getMeshBufferCount())
		{
			// clear the rest
			for (u32 j=i; j<Mesh->getMeshBufferCount(); ++j)
			{
				Mesh->getMeshBuffer(j)->drop();
			}
			Mesh->MeshBuffers.erase(i,Mesh->getMeshBufferCount()-i);
		}

		Mesh->recalculateBoundingBox();
	}
开发者ID:PavelPol,项目名称:worldforever,代码行数:31,代码来源:main.cpp

示例3: createMesh

//! Creates/loads an animated mesh from the file.
IAnimatedMesh* CSMFMeshFileLoader::createMesh(io::IReadFile* file)
{
     // create empty mesh
     SMesh *mesh = new SMesh();

     // load file
     u16 version;
     u8  flags;
     s32 limbCount;
     s32 i;

     io::BinaryFile::read(file, version);
     io::BinaryFile::read(file, flags);
     io::BinaryFile::read(file, limbCount);

     // load mesh data
     core::matrix4 identity;
     for (i=0; i < limbCount; ++i)
          loadLimb(file, mesh, identity);

     // recalculate buffer bounding boxes
     for (i=0; i < (s32)mesh->getMeshBufferCount(); ++i)
          mesh->getMeshBuffer(i)->recalculateBoundingBox();

     mesh->recalculateBoundingBox();
     SAnimatedMesh *am = new SAnimatedMesh();
     am->addMesh(mesh);
     mesh->drop();
     am->recalculateBoundingBox();

     return am;
}
开发者ID:merydwin,项目名称:IrrlichtV2,代码行数:33,代码来源:CSMFMeshFileLoader.cpp

示例4: createMeshFromSoftBody

IMesh* MeshTools::createMeshFromSoftBody(btSoftBody* softBody)
{
	SMeshBuffer* buffer = new SMeshBuffer();
	video::S3DVertex vtx;
	vtx.Color.set(255,255,255,255);

    /* Each soft body contain an array of vertices (nodes/particles_mass)   */
    btSoftBody::tNodeArray&   nodes(softBody->m_nodes);

    // Convert bullet nodes to vertices
    for(int i=0;i<nodes.size();++i)
    {
        const btSoftBody::Node&	n=nodes[i];
        const btVector3 normal=n.m_n;
        const btVector3 pos=n.m_x;

        vtx.Pos.set(pos.getX(), pos.getY(), pos.getZ());
		vtx.Normal.set(normal.getX(), normal.getY(), normal.getZ());

        // TODO: calculate texture coords
        //vtx.TCoords.set(tsx, tsy);

        buffer->Vertices.push_back(vtx);
    }

    // Convert triangles of the softbody to an index list
    for(int i=0;i<softBody->m_faces.size();++i)
    {
        auto	faces = softBody->m_faces;

        btSoftBody::Node*   node_0=faces[i].m_n[0];
        btSoftBody::Node*   node_1=faces[i].m_n[1];
        btSoftBody::Node*   node_2=faces[i].m_n[2];

        const int indices[] =
        {
            int(node_0-&nodes[0]),
            int(node_1-&nodes[0]),
            int(node_2-&nodes[0])
        };

        for(int j=0;j<3;++j)
            buffer->Indices.push_back(indices[j]);
    }

	buffer->recalculateBoundingBox();

	// Default the mesh to stream because most likely we will be updating
	// the vertex positions every frame to deal with softbody movement.
	buffer->setHardwareMappingHint(EHM_STREAM);

	SMesh* mesh = new SMesh();
	mesh->addMeshBuffer(buffer);
	mesh->recalculateBoundingBox();
	buffer->drop();
	return mesh;
}
开发者ID:Habaut,项目名称:GameBindings,代码行数:57,代码来源:MeshTools.cpp

示例5: readMesh

//! reads a mesh sections and creates a mesh from it
IAnimatedMesh* CIrrMeshFileLoader::readMesh(io::IXMLReader* reader)
{
	SAnimatedMesh* animatedmesh = new SAnimatedMesh();
	SMesh* mesh = new SMesh();

	animatedmesh->addMesh(mesh);
	mesh->drop();

	core::stringc bbSectionName = "boundingBox";
	core::stringc bufferSectionName = "buffer";
	core::stringc meshSectionName = "mesh";

	if (!reader->isEmptyElement())
	while(reader->read())
	{
		if (reader->getNodeType() == io::EXN_ELEMENT)
		{
			const wchar_t* nodeName = reader->getNodeName();
			if (bbSectionName == nodeName)
			{
				// inside a bounding box, ignore it for now because
				// we are calculating this anyway ourselves later.
			}
			else
			if (bufferSectionName == nodeName)
			{
				// we've got a mesh buffer

				IMeshBuffer* buffer = readMeshBuffer(reader);
				if (buffer)
				{
					mesh->addMeshBuffer(buffer);
					buffer->drop();
				}
			}
			else
				skipSection(reader, true); // unknown section

		} // end if node type is element
		else
		if (reader->getNodeType() == io::EXN_ELEMENT_END)
		{
			if (meshSectionName == reader->getNodeName())
			{
				// end of mesh section reached, cancel out
				break;
			}
		}
	} // end while reader->read();

	mesh->recalculateBoundingBox();
	animatedmesh->recalculateBoundingBox();

	return animatedmesh;
}
开发者ID:codetiger,项目名称:IrrNacl,代码行数:56,代码来源:CIrrMeshFileLoader.cpp

示例6: SMesh

irr::scene::IMesh* CGWIC_Cell::TerrainToMesh(int LOD)
{
	SMesh* out = new SMesh();
	CDynamicMeshBuffer* buff = new CDynamicMeshBuffer(EVT_2TCOORDS,EIT_16BIT);
	terrain->getMeshBufferForLOD(*buff,LOD);
	const u32 vertCnt = buff->getVertexCount();
	S3DVertex2TCoords* mbv = reinterpret_cast<S3DVertex2TCoords*> (buff->getVertexBuffer().getData());
	vector3df scale = terrain->getScale();
	for (u32 i=0; i<vertCnt; i++) mbv[i].Pos *= scale;
	out->addMeshBuffer(buff);
	out->recalculateBoundingBox();
	buff->drop();
	terrain->setPosition(terrain->getPosition());
	return out;
}
开发者ID:matrixsmaster,项目名称:GWIC,代码行数:15,代码来源:CGWIC_Cell.cpp

示例7: createHillPlaneMesh

// creates a hill plane
IAnimatedMesh* CGeometryCreator::createHillPlaneMesh(const core::dimension2d<f32>& tileSize, const core::dimension2d<s32>& tc,
        video::SMaterial* material,     f32 hillHeight, const core::dimension2d<f32>& ch,
        const core::dimension2d<f32>& textureRepeatCount)
{
    core::dimension2d<s32> tileCount = tc;
    tileCount.Height += 1;
    tileCount.Width += 1;

    core::dimension2d<f32> countHills = ch;

    SMeshBuffer* buffer = new SMeshBuffer();
    SMesh* mesh = new SMesh();
    video::S3DVertex vtx;
    vtx.Color.set(255,255,255,255);
    vtx.Normal.set(0,0,0);

    if (countHills.Width < 0.01f) countHills.Width = 1;
    if (countHills.Height < 0.01f) countHills.Height = 1;

    f32 halfX = (tileSize.Width * tileCount.Width) / 2;
    f32 halfY = (tileSize.Height * tileCount.Height) / 2;

    // create vertices

    s32 x = 0;
    s32 y = 0;

    core::dimension2d<f32> tx;
    tx.Width = 1.0f / (tileCount.Width / textureRepeatCount.Width);
    tx.Height = 1.0f / (tileCount.Height / textureRepeatCount.Height);


    for (x=0; x<tileCount.Width; ++x)
        for (y=0; y<tileCount.Height; ++y)
        {
            vtx.Pos.set(tileSize.Width * x - halfX, 0, tileSize.Height * y - halfY);
            vtx.TCoords.set(-(f32)x * tx.Width, (f32)y * tx.Height);

            if (hillHeight)
                vtx.Pos.Y = (f32)(sin(vtx.Pos.X * countHills.Width * engine::core::PI / halfX) *
                                  cos(vtx.Pos.Z * countHills.Height * engine::core::PI / halfY))
                            *hillHeight;

            buffer->Vertices.push_back(vtx);
        }

    // create indices

    for (x=0; x<tileCount.Width-1; ++x)
        for (y=0; y<tileCount.Height-1; ++y)
        {
            s32 current = y*tileCount.Width + x;

            buffer->Indices.push_back(current);
            buffer->Indices.push_back(current + 1);
            buffer->Indices.push_back(current + tileCount.Width);

            buffer->Indices.push_back(current + 1);
            buffer->Indices.push_back(current + 1 + tileCount.Width);
            buffer->Indices.push_back(current + tileCount.Width);
        }

    // recalculate normals
    for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
    {
        core::plane3d<f32> p(
            buffer->Vertices[buffer->Indices[i+0]].Pos,
            buffer->Vertices[buffer->Indices[i+1]].Pos,
            buffer->Vertices[buffer->Indices[i+2]].Pos);

        p.Normal.normalize();

        buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
        buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
        buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
    }

    if (material)
        buffer->Material = *material;

    buffer->recalculateBoundingBox();

    SAnimatedMesh* animatedMesh = new SAnimatedMesh();
    mesh->addMeshBuffer(buffer);
    mesh->recalculateBoundingBox();
    animatedMesh->addMesh(mesh);
    animatedMesh->recalculateBoundingBox();

    mesh->drop();
    buffer->drop();

    return animatedMesh;
}
开发者ID:jduranmaster,项目名称:ltegameengine,代码行数:94,代码来源:CGeometryCreator.cpp

示例8: crosses


//.........这里部分代码省略.........
        }
    };

    Visitor visitor;
    tree.triangulate(triangles, section, min_height, max_height, &visitor);
    //tree.sweep(triangles, section, &visitor);

   //cout << "num triangle points: " << triangles.size() << endl;

    vector<QuadTreePtr> leaves;
    tree.dumpLeaves(leaves);

    //cout << "num leaves: " << leaves.size() << endl;

/*
    for (QuadTreePtr p1 : leaves)
        for (QuadTreePtr p2 : leaves)
            if (p1 != p2)
                if (p1->isAdjacent(p2))
                    if (!visitor.has(p1, p2))
                    {
                        auto sz1 = p1->region.getSize();
                        auto sz2 = p2->region.getSize();
                        auto c1 = p1->region.getCenter();
                        auto c2 = p2->region.getCenter();
                        char const* path1 = p1->getPath().c_str();
                        char const* path2 = p2->getPath().c_str();
                        cout << path1 << endl;
                        cout << path2 << endl;
                        cout << "Missing pair of adjacent vertices." << endl;
                    }

    float x1 = section.UpperLeftCorner.X;
    float x2 = section.LowerRightCorner.X;
    float y1 = section.UpperLeftCorner.Y;
    float y2 = section.LowerRightCorner.Y;
*/
    /*
        d---c
        | / |
        a---b
    */

    /*
    S3DVertex sa;
    sa.Pos = vector3df(x1, y1, 0);
    PsblVertPtr a = new PossibleVertex(sa);

    S3DVertex sb;
    sb.Pos = vector3df(x2, y1, 0);
    PsblVertPtr b = new PossibleVertex(sb);

    S3DVertex sc;
    sc.Pos = vector3df(x2, y2, 0);
    PsblVertPtr c = new PossibleVertex(sc);

    S3DVertex sd;
    sd.Pos = vector3df(x1, y2, 0);
    PsblVertPtr d = new PossibleVertex(sd);

    // a-b-c
    // a-c-d
    triangles.push_back(a);
    triangles.push_back(b);
    triangles.push_back(c);

    triangles.push_back(a);
    triangles.push_back(c);
    triangles.push_back(d);

    triangles.push_back(c);
    triangles.push_back(b);
    triangles.push_back(a);

    triangles.push_back(d);
    triangles.push_back(c);
    triangles.push_back(a);
    */

	SMeshBuffer* buffer = new SMeshBuffer();

    for (auto pv : triangles)
        pv->addToMeshBuf(buffer, vector3df());

    if (buffer->getIndexCount() % 3 > 0)
        throw std::logic_error("SurfaceQuadTree triangulation added a 'triangle' with less than 3 vertices in it.");

    //cout << "num vertices " << buffer->getVertexCount() << endl;
    //cout << "num indices " << buffer->getIndexCount() << endl;

	buffer->recalculateBoundingBox();
	buffer->setHardwareMappingHint(EHM_STATIC);

	SMesh* mesh = new SMesh();
	mesh->addMeshBuffer(buffer);
	mesh->recalculateBoundingBox();
	buffer->drop();

	return mesh;
}
开发者ID:Habaut,项目名称:GameBindings,代码行数:101,代码来源:HillMesh.cpp

示例9: createMesh


//.........这里部分代码省略.........

	u16 attrib=0;
	core::stringc token;
	token.reserve(32);

	while (file->getPos() < filesize)
	{
		if (!binary)
		{
			if (getNextToken(file, token) != "facet")
			{
				if (token=="endsolid")
					break;
				mesh->drop();
				return 0;
			}
			if (getNextToken(file, token) != "normal")
			{
				mesh->drop();
				return 0;
			}
		}
		getNextVector(file, normal, binary);
		if (!binary)
		{
			if (getNextToken(file, token) != "outer")
			{
				mesh->drop();
				return 0;
			}
			if (getNextToken(file, token) != "loop")
			{
				mesh->drop();
				return 0;
			}
		}
		for (u32 i=0; i<3; ++i)
		{
			if (!binary)
			{
				if (getNextToken(file, token) != "vertex")
				{
					mesh->drop();
					return 0;
				}
			}
			getNextVector(file, vertex[i], binary);
		}
		if (!binary)
		{
			if (getNextToken(file, token) != "endloop")
			{
				mesh->drop();
				return 0;
			}
			if (getNextToken(file, token) != "endfacet")
			{
				mesh->drop();
				return 0;
			}
		}
		else
		{
			file->read(&attrib, 2);
#ifdef __BIG_ENDIAN__
			attrib = os::Byteswap::byteswap(attrib);
#endif
		}

		SMeshBuffer* mb = reinterpret_cast<SMeshBuffer*>(mesh->getMeshBuffer(mesh->getMeshBufferCount()-1));
		u32 vCount = mb->getVertexCount();
		video::SColor color(0xffffffff);
		if (attrib & 0x8000)
			color = video::A1R5G5B5toA8R8G8B8(attrib);
		if (normal==core::vector3df())
			normal=core::plane3df(vertex[2],vertex[1],vertex[0]).Normal;
		mb->Vertices.push_back(video::S3DVertex(vertex[2],normal,color, core::vector2df()));
		mb->Vertices.push_back(video::S3DVertex(vertex[1],normal,color, core::vector2df()));
		mb->Vertices.push_back(video::S3DVertex(vertex[0],normal,color, core::vector2df()));
		mb->Indices.push_back(vCount);
		mb->Indices.push_back(vCount+1);
		mb->Indices.push_back(vCount+2);
	}	// end while (file->getPos() < filesize)
	mesh->getMeshBuffer(0)->recalculateBoundingBox();

	// Create the Animated mesh if there's anything in the mesh
	SAnimatedMesh* pAM = 0;
	if ( 0 != mesh->getMeshBufferCount() )
	{
		mesh->recalculateBoundingBox();
		pAM = new SAnimatedMesh();
		pAM->Type = EAMT_OBJ;
		pAM->addMesh(mesh);
		pAM->recalculateBoundingBox();
	}

	mesh->drop();

	return pAM;
}
开发者ID:NotKyon,项目名称:DarkIrrlicht,代码行数:101,代码来源:CSTLMeshFileLoader.cpp

示例10: CreateConeSceneNode

IMeshSceneNode* CustomSceneNodeManager::CreateConeSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height)
{
	if (resolution >= 4)
	{
		/*IMesh* newConeMesh = sceneManager->getGeometryCreator()->createConeMesh(radius, height, resolution, color, color);

		IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh);

		sceneManager->getMeshCache()->addMesh(irr::io::path("ConeMesh"), (irr::scene::IAnimatedMesh*)newConeMesh);
		newConeMesh->drop();*/

		SMesh* newConeMesh = new SMesh();

		SMeshBuffer* buf = new SMeshBuffer();
	
		newConeMesh->addMeshBuffer(buf);
		buf->MappingHint_Vertex = EHM_STATIC;
		buf->MappingHint_Index = EHM_STATIC;
		buf->drop();

		int noWarningSignedResolution = resolution;

		float currentTheta = 0.0f;
		float skipAmount = 2.0f*PI / (float)resolution;
		float halfHeight = height / 2.0f;

		S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f));
		S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f));
		for(int i = 0; i < noWarningSignedResolution; i++)
		{
			float x = cosf(currentTheta) * radius;
			float z = sinf(currentTheta) * radius;

			temp2.Pos.X = x;
			temp2.Pos.Z = z;
			temp2.TCoords.X = currentTheta / 2.0f*PI;

			buf->Vertices.push_back(temp2);

			currentTheta += skipAmount;
		}
		
		buf->Vertices.push_back(temp1);

		//Get side indices
		for(int i = 0; i < noWarningSignedResolution - 1; i++)
		{
			buf->Indices.push_back(i);
			buf->Indices.push_back(buf->Vertices.size()-1);
			buf->Indices.push_back(i+1);
		}

		buf->Indices.push_back(buf->Vertices.size()-2);
		buf->Indices.push_back(buf->Vertices.size()-1);
		buf->Indices.push_back(0);

		temp2.Pos.X = 0.0f;
		temp2.Pos.Z = 0.0f;
		buf->Vertices.push_back(temp2);

		//Get bottom indices
		for(int i = 0; i < noWarningSignedResolution - 1; i++)
		{
			buf->Indices.push_back(i);
			buf->Indices.push_back(i+1);
			buf->Indices.push_back(buf->Vertices.size()-1);
		}

		buf->Indices.push_back(buf->Vertices.size()-1);
		buf->Indices.push_back(buf->Vertices.size()-3);
		buf->Indices.push_back(0);

		//Calculate normals
		CalculateNormals(buf->Vertices, buf->Indices);

		buf->recalculateBoundingBox();
		newConeMesh->recalculateBoundingBox();

		IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh);

		newConeMesh->drop();

		return node;
	}

	return NULL;
}
开发者ID:niraj-rayalla,项目名称:PhysicsHelper,代码行数:87,代码来源:CustomSceneNodeManager.cpp

示例11: CreateCapsuleSceneNode


//.........这里部分代码省略.........
				temp1.TCoords.Y = currentPhi / PI;

				buf->Vertices.push_back(temp1);

				currentTheta += thetaSkipAmount;
			}

			currentTheta = 0.0f;
			currentPhi += phiSkipAmount;
		}
		temp1.Pos.X = 0.0f;
		temp1.Pos.Y = -(halfHeight + radius);
		temp1.Pos.Z = 0.0f;
		buf->Vertices.push_back(temp1);

		//Top vertex indices
		for(unsigned int i = 1; i <= resolution; i++)
		{
			if (i == resolution)
			{
				buf->Indices.push_back(i);
				buf->Indices.push_back(0);
				buf->Indices.push_back(1);
			}
			else
			{
				buf->Indices.push_back(i);
				buf->Indices.push_back(0);
				buf->Indices.push_back(i + 1);
			}
		}

		//Get indices
		int i  = 1 + resolution;

		while(i < buf->Vertices.size() - 1)
		{
			for(unsigned int j = 1; j < resolution; j++)
			{
				buf->Indices.push_back(i);
				buf->Indices.push_back(i - noWarningSignedResolution);
				buf->Indices.push_back(i - noWarningSignedResolution + 1);

				buf->Indices.push_back(i);
				buf->Indices.push_back(i - noWarningSignedResolution + 1);
				buf->Indices.push_back(i + 1);

				i++;
			}

			buf->Indices.push_back(i);
			buf->Indices.push_back(i - noWarningSignedResolution);
			buf->Indices.push_back(i - noWarningSignedResolution + 1 - resolution);

			buf->Indices.push_back(i);
			buf->Indices.push_back(i - noWarningSignedResolution + 1 - resolution);
			buf->Indices.push_back(i + 1 - resolution);

			i++;
		}

		//Bottom vertex indices
		for(int i = resolution; i >= 1 ; i--)
		{
			if (i == 1)
			{
				/*buf->Indices.push_back(i);
				buf->Indices.push_back(0);
				buf->Indices.push_back(1);*/

				buf->Indices.push_back(buf->Vertices.size() -1);
				buf->Indices.push_back(buf->Vertices.size() -1 - i);
				buf->Indices.push_back(buf->Vertices.size() - 1 - resolution);
			}
			else
			{
				buf->Indices.push_back(buf->Vertices.size() -1);
				buf->Indices.push_back(buf->Vertices.size() -1 - i);
				buf->Indices.push_back(buf->Vertices.size() - i);
			}
		}




		//Calculate normals
		CalculateNormals(buf->Vertices, buf->Indices);

		buf->recalculateBoundingBox();
		newCapsuleMesh->recalculateBoundingBox();

		IMeshSceneNode* node = sceneManager->addMeshSceneNode(newCapsuleMesh);

		newCapsuleMesh->drop();

		return node;
	}

	return NULL;
}
开发者ID:niraj-rayalla,项目名称:PhysicsHelper,代码行数:101,代码来源:CustomSceneNodeManager.cpp

示例12: createMeshFromHeightmap


//.........这里部分代码省略.........

            vert.Pos.set(x, y, thisHeight);

            // I'm only averaging normals along the 4 compass directions.  It's
            // arguable whether diagonals should count; I chose to ignore diagonals.
            // Ignoring diagonals allows me to assume the "run" in rise/run is always
            // just one unit; if you add diagonals here you'll also need to change
            // the slope calculation to use the actual distance instead of assuming 1.
            vector2di offsetsArray[] = {
                vector2di( 1, 0),  //  3 o'clock
                vector2di( 0, 1),  // 12 o'clock
                vector2di(-1, 0),  //  9 o'clock
                vector2di( 0,-1)   //  6 o'clock
            };

            // Calculate the normals of the surrounding slopes.
            // Uses the image, not just the tile patch size, so it will
            // calculate correct normals for vertices on tile edges.
            for (size_t i=-0; i < 4; ++i)
            {
                vector2di offset = vector2di(x,y) + offsetsArray[i];

                // Skip this offset if it's outside the image
                if (offset.X < 0 || offset.Y < 0 || offset.X >= (s32)imageDimension.Width || offset.Y >= (s32)imageDimension.Height)
                    continue;

                vector2di otherPixelPos(
                    startAtPixel.X+x+offset.X,
                    startAtPixel.Y-y-offset.Y
                );
                float otherHeight = 255 - image->getPixel((u32)otherPixelPos.X, (u32)otherPixelPos.Y).getAverage();

                // The code Irrlicht's in terrain scene node does all kinds of complicated
                // business with cross products and such - waaay over complicated.  You don't need
                // all that stuff.  Dude it' s a heightmap: all you need to worray about is
                // rise over run on unit intervals!  Algebra 1 type stuff, y = mx + c

                // Calculate the rise of the line over the run, taking into account the fact
                // that the offset could be in either direction.
                float rise = (offset.X < 0 || offset.Y < 0)? thisHeight - otherHeight : otherHeight - thisHeight;

                // Assuming that run = 1, m = rise / run is just m = rise.
                float m = rise;

                // The the slope of the normal is just the negative of the reciprocal of the line slope.
                float n = -1.0f / rise;

                // The X,Y of the normal vector is just going to be the X and Y of the offset
                // (think about it - obviously the normal of the slope must tilt in the direction of the run)
                // and the Z of the normal vector is just the slope of the normal over that run.
                vector3df normVect(offset.X, offset.Y, n);

                //vert.Normal += normVect;
            }

            //vert.Normal.normalize();
            vert.Normal.set(0,0,-1.0f);
        }
    }

    // Pre-allocate index data to 2*3*Width*Height for triangles.
    // There is actually 1 less square per count of vertices though,
    // for instance if you had 2x2 vertices, you only have 1 square.
    buffer->Indices.set_used(2*3*(useTileSize.Width-1)*(useTileSize.Height-1));

    // Start with 1 and generate all the triangles from their top right corners.
    // Like this (A is top right corner at x,y):
    //
    //              y=1  B---A
    //                   | / |
    //              y=0  C---D
    //                  x=0 x=1
    for (u32 dst=0, x=1; x < useTileSize.Width; ++x)
    {
        for (u32 y=1; y < useTileSize.Height; ++y)
        {
            u32 A = getIndex(useTileSize, x,   y   );
            u32 B = getIndex(useTileSize, x-1, y   );
            u32 C = getIndex(useTileSize, x-1, y-1 );
            u32 D = getIndex(useTileSize, x,   y-1 );

            buffer->Indices[dst++] = C;
            buffer->Indices[dst++] = B;
            buffer->Indices[dst++] = A;

            buffer->Indices[dst++] = D;
            buffer->Indices[dst++] = C;
            buffer->Indices[dst++] = A;
        }
    }

	buffer->recalculateBoundingBox();
	buffer->setHardwareMappingHint(EHM_STATIC);

	SMesh* mesh = new SMesh();
	mesh->addMeshBuffer(buffer);
	mesh->recalculateBoundingBox();
	buffer->drop();
	return mesh;
}
开发者ID:Habaut,项目名称:GameBindings,代码行数:101,代码来源:MeshTools.cpp

示例13: axis


//.........这里部分代码省略.........
                        normal.X =  normals[p];
                        normal.Y = -normals[p+1]; //left-handed->right-handed
                        normal.Z =  normals[p+2];
                    } else {
                        normal.X = 0;
                        normal.Y = 0;
                        normal.Z = 1;
                    }
                }
                for(int k=0; k < 3; ++k) {
                    long orgVertexIndex = si.triangles[j * 3 + k];
                    if (ai.normalPerVertex) {
                        int p;
                        if (normalIndices.length()) {
                            p = normalIndices[j*3+k]*3;
                        } else {
                            p = orgVertexIndex*3;
                        }
                        normal.X =  normals[p];
                        normal.Y = -normals[p+1]; //left-handed -> right-handed
                        normal.Z =  normals[p+2];
                    }
                    int p = orgVertexIndex * 3;
                    vertex.X =  scale.X*vertices[p];
                    vertex.Y = -scale.Y*vertices[p+1]; // left-handed -> right-handed
                    vertex.Z =  scale.Z*vertices[p+2];
                    //std::cout << vertices[p] <<"," << vertices[p+1] << "," << vertices[p+2] << std::endl;
                    vector2df texc;
                    if (textureCoordinate) {

                        texc.X = textureCoordinate[ai.textureCoordIndices[j*3+k]*2];
                        texc.Y = textureCoordinate[ai.textureCoordIndices[j*3+k]*2+1];
                    }
                    // redundant vertices
                    mb->Vertices.push_back(video::S3DVertex(vertex,normal,color, texc));
                }
                mb->Indices.push_back(vCount);
                mb->Indices.push_back(vCount+2);
                mb->Indices.push_back(vCount+1);
                vCount += 3;
            }
            mesh->getMeshBuffer(0)->recalculateBoundingBox();

            // Create the Animated mesh if there's anything in the mesh
            SAnimatedMesh* pAM = 0;
            if ( 0 != mesh->getMeshBufferCount() )
            {
                mesh->recalculateBoundingBox();
                pAM = new SAnimatedMesh();
                pAM->Type = EAMT_OBJ;
                pAM->addMesh(mesh);
                pAM->recalculateBoundingBox();
            }

            mesh->drop();

            vector3df noscale(1,1,1);

            IMeshSceneNode *node
                = i_mgr->addMeshSceneNode(mesh, this, -1,
                                          pos,
                                          rpy,
                                          noscale);

            if (ai.textureIndex >= 0) {
                const TextureInfo& ti = txs[ai.textureIndex];
                //std::cout << "url:" << ti.url << std::endl;
                video::IVideoDriver* driver = i_mgr->getVideoDriver();
                const char *path = ti.url;
                SMaterial& mat = node->getMaterial(0);
                ITexture *texture = driver->getTexture(path);
                mat.setTexture( 0, texture);
            }

        }

        const SensorInfoSequence& sensors = i_li.sensors;
        for (unsigned int i=0; i<sensors.length(); i++) {
            const SensorInfo& si = sensors[i];
            std::string type(si.type);
            if (type == "Vision") {
                //std::cout << si.name << std::endl;
                ISceneNode *camera = i_mgr->addEmptySceneNode(this);
                camera->setName(si.name);
                camera->setPosition(vector3df( si.translation[0],
                                               -si.translation[1],
                                               si.translation[2]));
                Vector3 axis(si.rotation[0],
                             si.rotation[1],
                             si.rotation[2]);
                Matrix33 R;
                hrp::calcRodrigues(R, axis, si.rotation[3]);
                Vector3 rpy(rpyFromRot(R));
                camera->setRotation(vector3df(-180/M_PI*rpy[0],
                                              180/M_PI*rpy[1],
                                              -180/M_PI*rpy[2]));
                m_cameraInfos.push_back(new GLcamera(si, camera));
            }
        }
    }
开发者ID:hattorishizuko,项目名称:hrpsys-base,代码行数:101,代码来源:IrrModel.cpp

示例14: splitMeshZ


//.........这里部分代码省略.........
            //  1 cont.     AB' AB'     AB' replaces B in P
            //  2           -   B       B proper is in Q and not in P
            //  2 cont.     -   -       Link B-C is not split
            //  3           -   C       C proper is in Q and not in P
            //  3 cont.     CA' CA'     CA' replaces C in P
            //
            // Now, read the columns P and Q vertically top to bottom to see the resultant vertex order.
            // The triangle P is trivially still the correct winding order; it is just a smaller triangle now.
            // The new quad Q retains the old triangle's winding order property for the following reason:
            //  As you wrapped around a full circle in old triangle A-B-C you would have traversed C-A then A-B.
            //      The link C-A has been cut and vertex CA' inserted.
            //      The link A-B has been cut and vertex AB' inserted.
            //  If you traverse the new shape starting from the _middle_ you follow the following path:
            //      B-C     C-CA'   CA'-AB'    AB'-B    B-C (again)
            //  Compare to old triangle:
            //      B-C          C-A        A-B         B-C (again)
            //  Even though vertex A has been cut off and replaced with two vertices, the two
            //  new vertices lie along the path that the old links took and are in the new shape in the right order.

            mid1 = linkSplitter.processLink(leftShape, rightShape, a, b);
            mid2 = linkSplitter.processLink(leftShape, rightShape, b, c);
            mid3 = linkSplitter.processLink(leftShape, rightShape, c, a);
        }

        // If a triangle was split then two of those three midpoints are inhabited by a vertex.
        // We want to get them both in mid1 and mid2 AND we need them in correct order.
        PsblVertPtr cut1 = (mid1 && mid2)? mid1 : mid2;
        PsblVertPtr cut2 = (mid2 && mid3)? mid3 : mid2;

        if (cut1 && cut2)
        {
            vector<PsblVertPtr> chain = linkSplitter.chopLink(cut1, cut2, 1);
            linkSplitter.insertPoints(leftShape, cut1, cut2, chain);
            linkSplitter.insertPoints(rightShape, cut1, cut2, chain);
        }

        linkSplitter.addConvexShape(leftShape, leftMeshBuf,   -offset/2);
        linkSplitter.addConvexShape(rightShape, rightMeshBuf,  offset/2);

        // Add any edges of the left shape that lie along the border.
        linkSplitter.addEdgeLinks(leftShape, leftEdgeLinks);

        // Right side polys that share a border with left side ones will have
        // opposite winding order.  In order for set_intersection to consider them
        // as matches, we'll store the right side links in reversed order.
        std::reverse(rightShape.begin(), rightShape.end());
        linkSplitter.addEdgeLinks(rightShape, rightEdgeLinks);
    }

	SMesh* leftMesh = new SMesh();
	leftMeshBuf->recalculateBoundingBox();
	leftMeshBuf->setHardwareMappingHint(EHM_STATIC);
    leftMesh->addMeshBuffer(leftMeshBuf);
	leftMesh->recalculateBoundingBox();
	leftMeshBuf->drop();  // we drop the buf, mesh obj has it now

	SMesh* rightMesh = new SMesh();
	rightMeshBuf->recalculateBoundingBox();
	rightMeshBuf->setHardwareMappingHint(EHM_STATIC);
    rightMesh->addMeshBuffer(rightMeshBuf);
	rightMesh->recalculateBoundingBox();
	rightMeshBuf->drop();  // we drop the buf, mesh obj has it now

    SMesh* middleMesh = NULL;
    if (zInsert > 0)
    {
        set<pair<PsblVertPtr,PsblVertPtr>> result;
        std::set_intersection(
            leftEdgeLinks.begin(), leftEdgeLinks.end(),
            rightEdgeLinks.begin(), rightEdgeLinks.end(),
            std::inserter(result, result.begin())
        );

        size_t debugsize = result.size();

        if (result.size() > 0)
        {
            SMeshBuffer* middleMeshBuf = new SMeshBuffer();

            vector<PsblVertPtr> shape(4);
            for (auto it=result.begin(); it!=result.end(); ++it)
            {
                shape[0] = it->second;
                shape[1] = it->first;
                shape[2] = it->first->duplicate(offset);
                shape[3] = it->second->duplicate(offset);
                linkSplitter.addConvexShape(shape, middleMeshBuf, -offset/2);
            }

            middleMesh = new SMesh();
            middleMeshBuf->recalculateBoundingBox();
            middleMeshBuf->setHardwareMappingHint(EHM_STATIC);
            middleMesh->addMeshBuffer(middleMeshBuf);
            middleMesh->recalculateBoundingBox();
            middleMeshBuf->drop();  // we drop the buf, mesh obj has it now
        }
    }

	return SplitMeshResult {leftMesh, middleMesh, rightMesh};
}
开发者ID:Habaut,项目名称:GameBindings,代码行数:101,代码来源:MeshTools.cpp

示例15: createTerrainMesh


//.........这里部分代码省略.........
                blockSize.Width = hMapSize.Width - processed.X;
            if (processed.Y + blockSize.Height > hMapSize.Height)
                blockSize.Height = hMapSize.Height - processed.Y;

            SMeshBuffer* buffer = new SMeshBuffer();
            s32 x,y;

            // add vertices of vertex block
            for (y=0; y<blockSize.Height; ++y)
                for (x=0; x<blockSize.Width; ++x)
                {
                    video::SColor clr = heightmap->getPixel(x+processed.X, y+processed.Y);
                    f32 height = ((clr.getRed() + clr.getGreen() + clr.getBlue()) / 3.0f)/255.0f * maxHeight;

                    vtx.Pos.set((f32)(x+processed.X) * stretchSize.Width,
                                height, (f32)(y+processed.Y) * stretchSize.Height);

                    vtx.TCoords.set((f32)(x+0.5f) / ((f32)blockSize.Width),
                                    (f32)(y+0.5f) / ((f32)blockSize.Height));

                    buffer->Vertices.push_back(vtx);
                }

            // add indices of vertex block
            for (y=0; y<blockSize.Height-1; ++y)
                for (x=0; x<blockSize.Width-1; ++x)
                {
                    s32 c = (y*blockSize.Width) + x;

                    buffer->Indices.push_back(c);
                    buffer->Indices.push_back(c + blockSize.Width);
                    buffer->Indices.push_back(c + 1);

                    buffer->Indices.push_back(c + 1);
                    buffer->Indices.push_back(c + blockSize.Width);
                    buffer->Indices.push_back(c + 1 + blockSize.Width);
                }

            // recalculate normals
            for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
            {
                core::plane3d<f32> p(
                    buffer->Vertices[buffer->Indices[i+0]].Pos,
                    buffer->Vertices[buffer->Indices[i+1]].Pos,
                    buffer->Vertices[buffer->Indices[i+2]].Pos);
                p.Normal.normalize();

                buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
                buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
                buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
            }

            if (buffer->Vertices.size())
            {
                // create texture for this block
                video::IImage* img = new video::CImage(texture,
                                                       core::position2d<s32>((s32)(processed.X*thRel.X), (s32)(processed.Y*thRel.Y)),
                                                       core::dimension2d<s32>((s32)(blockSize.Width*thRel.X), (s32)(blockSize.Height*thRel.Y)));

                sprintf(textureName, "terrain%d_%d", tm, mesh->getMeshBufferCount());

                material.Texture1 = driver->addTexture(textureName, img);

                if (material.Texture1)
                {
                    sprintf(tmp, "Generated terrain texture (%dx%d): %s",
                            material.Texture1->getSize().Width,
                            material.Texture1->getSize().Height,
                            textureName);
                    os::Printer::log(tmp);
                }
                else
                    os::Printer::log("Could not create terrain texture.", textureName, ELL_ERROR);

                buffer->Material = material;
                img->drop();
            }

            buffer->recalculateBoundingBox();
            mesh->addMeshBuffer(buffer);
            buffer->drop();

            // keep on processing
            processed.X += maxVtxBlockSize.Width - borderSkip;
        }

        // keep on processing
        processed.X = 0;
        processed.Y += maxVtxBlockSize.Height - borderSkip;
    }

    SAnimatedMesh* animatedMesh = new SAnimatedMesh();
    mesh->recalculateBoundingBox();
    animatedMesh->addMesh(mesh);
    animatedMesh->recalculateBoundingBox();

    mesh->drop();

    return animatedMesh;
}
开发者ID:jduranmaster,项目名称:ltegameengine,代码行数:101,代码来源:CGeometryCreator.cpp


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