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


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

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


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

示例1: 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

示例2: addstrip

	void addstrip(const HeightMap &hm, colour_func cf, u16 y0, u16 y1, u32 bufNum)
	{
		SMeshBuffer *buf = 0;
		if (bufNum<Mesh->getMeshBufferCount())
		{
			buf = (SMeshBuffer*)Mesh->getMeshBuffer(bufNum);
		}
		else
		{
			// create new buffer
			buf = new SMeshBuffer();
			Mesh->addMeshBuffer(buf);
			// to simplify things we drop here but continue using buf
			buf->drop();
		}
		buf->Vertices.set_used((1 + y1 - y0) * Width);

		u32 i=0;
		for (u16 y = y0; y <= y1; ++y)
		{
			for (u16 x = 0; x < Width; ++x)
			{
				const f32 z = hm.get(x, y);
				const f32 xx = (f32)x/(f32)Width;
				const f32 yy = (f32)y/(f32)Height;

				S3DVertex& v = buf->Vertices[i++];
				v.Pos.set(x, Scale * z, y);
				v.Normal.set(hm.getnormal(x, y, Scale));
				v.Color=cf(xx, yy, z);
				v.TCoords.set(xx, yy);
			}
		}

		buf->Indices.set_used(6 * (Width - 1) * (y1 - y0));
		i=0;
		for(u16 y = y0; y < y1; ++y)
		{
			for(u16 x = 0; x < Width - 1; ++x)
			{
				const u16 n = (y-y0) * Width + x;
				buf->Indices[i]=n;
				buf->Indices[++i]=n + Width;
				buf->Indices[++i]=n + Width + 1;
				buf->Indices[++i]=n + Width + 1;
				buf->Indices[++i]=n + 1;
				buf->Indices[++i]=n;
				++i;
			}
		}

		buf->recalculateBoundingBox();
	}
开发者ID:bacsmar,项目名称:irrlicht,代码行数:53,代码来源:main.cpp

示例3: 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

示例4: 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

示例5: 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

示例6: createRainbowMeshBuffer

SMeshBuffer* createRainbowMeshBuffer( // XY-plane, normale is -Z
		f32 outerRadius,
		f32 innerRadius,
		f32 zAngleStart,
		f32 zAngleEnd,
		u32 segments,
		const core::vector3df& pos)
{
	SMeshBuffer* buffer = new SMeshBuffer();
	if (!buffer)
		return 0;

	//! outer-cylinder material
	buffer->Material.Lighting = false;
	buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
	buffer->Material.Wireframe = false;
	buffer->Material.FogEnable = false;
	buffer->Material.BackfaceCulling = true;
	buffer->Vertices.clear();
	buffer->Indices.clear();
//	buffer->Vertices.reallocate();
//	buffer->Vertices.set_used(0);
//	buffer->Indices.reallocate();
//	buffer->Indices.set_used(0);

	//! Constants
	const f32 phi = 2.0f*core::PI * (zAngleEnd-zAngleStart) / (360.0f * (f32)segments);
	const f32 phiStart = 2.0f*core::PI * (zAngleStart-90.0f) / 360.0f;
	const f32 z = pos.Z;

	//! Locals
	f32 x0,y0,x1,y1,x2,y2,x3,y3,sinPhi,cosPhi;

	//! Tables
	f32* sinTable = new f32[segments+1];
	f32* cosTable = new f32[segments+1];

	for (u32 i=0; i<segments+1; ++i)
	{
		const f32 angle = (f32)i*phi + phiStart;
		sinTable[i] = sinf(angle);
		cosTable[i] = cosf(angle);
	}

	//! build MeshBuffer (each segment consists of 2 triangles, important for texturing, each segment contains one complete texture)
	for (u32 i=0; i<segments; ++i)
	{
		x0 = pos.X - innerRadius * sinTable[i+1];
		y0 = pos.Y + innerRadius * cosTable[i+1];
		x1 = pos.X - outerRadius * sinTable[i+1];
		y1 = pos.Y + outerRadius * cosTable[i+1];
		x2 = pos.X - outerRadius * sinTable[i];
		y2 = pos.Y + outerRadius * cosTable[i];
		x3 = pos.X - innerRadius * sinTable[i];
		y3 = pos.Y + innerRadius * cosTable[i];

		buffer->Vertices.push_back(video::S3DVertex(x0,y0,z,0,0,-1,0xFFFFFFFF,0,1)); // A
		buffer->Vertices.push_back(video::S3DVertex(x1,y1,z,0,0,-1,0xFFFFFFFF,0,0)); // B
		buffer->Vertices.push_back(video::S3DVertex(x2,y2,z,0,0,-1,0xFFFFFFFF,1,0)); // C
		buffer->Vertices.push_back(video::S3DVertex(x3,y3,z,0,0,-1,0xFFFFFFFF,1,1)); // D
		buffer->Indices.push_back(4*i+0); // A
		buffer->Indices.push_back(4*i+1); // B
		buffer->Indices.push_back(4*i+2); // C
		buffer->Indices.push_back(4*i+0); // A
		buffer->Indices.push_back(4*i+2); // C
		buffer->Indices.push_back(4*i+3); // D
	}

	delete [] sinTable;
	delete [] cosTable;

	//! BBox
	buffer->recalculateBoundingBox();
	return buffer;

} // END FUNCTION
开发者ID:benjaminhampe,项目名称:libHampe,代码行数:76,代码来源:createRainbow.cpp

示例7: CreateCylinderSceneNode

IMeshSceneNode* CustomSceneNodeManager::CreateCylinderSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height)
{
	/*if (!cylinderMesh)
	{*/
		if (resolution >= 4)
		{
			SMesh* newCylinderMesh = new SMesh();

			SMeshBuffer* buf = new SMeshBuffer();
		
			newCylinderMesh->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;

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

				buf->Vertices.push_back(temp1);
				buf->Vertices.push_back(temp2);

				currentTheta += skipAmount;
			}

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

			//Get indices
			for(int i = 0; i < noWarningSignedResolution - 1; i++)
			{
				buf->Indices.push_back(i*2);
				buf->Indices.push_back(i*2+2);
				buf->Indices.push_back(i*2+1);

				buf->Indices.push_back(i*2+1);
				buf->Indices.push_back(i*2+2);
				buf->Indices.push_back(i*2+3);

				buf->Indices.push_back(i*2);
				buf->Indices.push_back(buf->Vertices.size()-2);
				buf->Indices.push_back(i*2+2);

				buf->Indices.push_back(i*2+1);
				buf->Indices.push_back(i*2+3);
				buf->Indices.push_back(buf->Vertices.size()-1);
			}

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

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

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

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

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

			buf->recalculateBoundingBox();
			newCylinderMesh->recalculateBoundingBox();

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

			newCylinderMesh->drop();

			return node;
		}

	/*	return NULL;
//.........这里部分代码省略.........
开发者ID:niraj-rayalla,项目名称:PhysicsHelper,代码行数:101,代码来源:CustomSceneNodeManager.cpp

示例8: 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

示例9: 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

示例10: 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

示例11: 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


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