本文整理汇总了C++中TriangleBuffer::index方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleBuffer::index方法的具体用法?C++ TriangleBuffer::index怎么用?C++ TriangleBuffer::index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriangleBuffer
的用法示例。
在下文中一共展示了TriangleBuffer::index方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addToTriangleBuffer
void PlaneGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(numSegX>0 && numSegY>0 && "Num seg must be positive");
assert(!normal.isZeroLength() && "Normal must not be null");
assert(sizeX>0. && sizeY>0. && "Size must be positive");
buffer.rebaseOffset();
buffer.estimateVertexCount((numSegX+1)*(numSegY+1));
buffer.estimateIndexCount(numSegX*numSegY*6);
int offset = 0;
Ogre::Vector3 vX = normal.perpendicular();
Ogre::Vector3 vY = normal.crossProduct(vX);
Ogre::Vector3 delta1 = sizeX / numSegX * vX;
Ogre::Vector3 delta2 = sizeY / numSegY * vY;
// build one corner of the square
Ogre::Vector3 orig = -0.5*sizeX*vX - 0.5*sizeY*vY;
for (int i1 = 0; i1<=numSegX; i1++)
for (int i2 = 0; i2<=numSegY; i2++)
{
buffer.position(orig+i1*delta1+i2*delta2+position);
buffer.textureCoord(i1/(Ogre::Real)numSegX*uTile, i2/(Ogre::Real)numSegY*vTile);
buffer.normal(normal);
}
bool reverse = false;
if (delta1.crossProduct(delta2).dotProduct(normal)>0)
reverse= true;
for (int n1 = 0; n1<numSegX; n1++)
{
for (int n2 = 0; n2<numSegY; n2++)
{
if (reverse)
{
buffer.index(offset+0);
buffer.index(offset+(numSegY+1));
buffer.index(offset+1);
buffer.index(offset+1);
buffer.index(offset+(numSegY+1));
buffer.index(offset+(numSegY+1)+1);
}
else
{
buffer.index(offset+0);
buffer.index(offset+1);
buffer.index(offset+(numSegY+1));
buffer.index(offset+1);
buffer.index(offset+(numSegY+1)+1);
buffer.index(offset+(numSegY+1));
}
offset++;
}
offset++;
}
}
示例2: addToTriangleBuffer
void PlaneGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(mNumSegX>0 && mNumSegY>0 && "Num seg must be positive");
assert(!mNormal.isZeroLength() && "Normal must not be null");
assert(mSizeX>0. && mSizeY>0. && "Size must be positive");
buffer.rebaseOffset();
buffer.estimateVertexCount((mNumSegX+1)*(mNumSegY+1));
buffer.estimateIndexCount(mNumSegX*mNumSegY*6);
int offset = 0;
Vector3 vX = mNormal.perpendicular();
Vector3 vY = mNormal.crossProduct(vX);
Vector3 delta1 = mSizeX / (Real)mNumSegX * vX;
Vector3 delta2 = mSizeY / (Real)mNumSegY * vY;
// build one corner of the square
Vector3 orig = -0.5f*mSizeX*vX - 0.5f*mSizeY*vY;
for (unsigned short i1 = 0; i1<=mNumSegX; i1++)
for (unsigned short i2 = 0; i2<=mNumSegY; i2++)
{
addPoint(buffer, orig+i1*delta1+i2*delta2,
mNormal,
Vector2(i1/(Real)mNumSegX, i2/(Real)mNumSegY));
}
bool reverse = false;
if (delta1.crossProduct(delta2).dotProduct(mNormal)>0)
reverse= true;
for (unsigned short n1 = 0; n1<mNumSegX; n1++)
{
for (unsigned short n2 = 0; n2<mNumSegY; n2++)
{
if (reverse)
{
buffer.index(offset+0);
buffer.index(offset+(mNumSegY+1));
buffer.index(offset+1);
buffer.index(offset+1);
buffer.index(offset+(mNumSegY+1));
buffer.index(offset+(mNumSegY+1)+1);
}
else
{
buffer.index(offset+0);
buffer.index(offset+1);
buffer.index(offset+(mNumSegY+1));
buffer.index(offset+1);
buffer.index(offset+(mNumSegY+1)+1);
buffer.index(offset+(mNumSegY+1));
}
offset++;
}
offset++;
}
}
示例3: addToTriangleBuffer
void Lathe::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert( mShapeToExtrude && "Shape must not be null!");
int numSegShape = mShapeToExtrude->getSegCount();
assert(numSegShape>1 && "Shape must contain at least two points");
int offset =0;
buffer.rebaseOffset();
buffer.estimateIndexCount(mNumSeg*numSegShape*6);
buffer.estimateVertexCount((numSegShape+1)*(mNumSeg+1));
for (int i=0;i<=mNumSeg;i++)
{
Real angle = i/(Real)mNumSeg*Math::TWO_PI;
Quaternion q;
q.FromAngleAxis((Radian)angle,Vector3::UNIT_Y);
for (int j=0;j<=numSegShape;j++)
{
Vector2 v0 = mShapeToExtrude->getPoint(j);
Vector3 vp(v0.x,v0.y,0);
Vector2 vp2direction = mShapeToExtrude->getAvgDirection(j);
Vector2 vp2normal = vp2direction.perpendicular();
Vector3 normal(vp2normal.x, vp2normal.y, 0);
normal.normalise();
if (mShapeToExtrude->getOutSide() == SIDE_LEFT)
{
normal = -normal;
}
addPoint(buffer, q*vp,
q*normal,
Vector2(i/(Real)mNumSeg, j/(Real)numSegShape));
if (j <numSegShape && i <mNumSeg)
{
buffer.index(offset + numSegShape + 2);
buffer.index(offset);
buffer.index(offset + numSegShape + 1);
buffer.index(offset + numSegShape + 2);
buffer.index(offset + 1);
buffer.index(offset);
}
offset ++;
}
}
}
示例4: addToTriangleBuffer
void TorusKnotGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(mNumSegSection>0 && mNumSegCircle>0 && "Num seg and circle must be positive");
assert(mRadius>0. && mSectionRadius>0. && "Radius and section radius must be positive");
assert(mP>0 && mQ>0 && "p and q must be positive");
buffer.rebaseOffset();
buffer.estimateVertexCount((mNumSegCircle*mP+1)*(mNumSegSection+1));
buffer.estimateIndexCount((mNumSegCircle*mP)*(mNumSegSection+1)*6);
int offset = 0;
for (int i = 0; i <= mNumSegCircle * mP;i++)
{
Real phi = Math::TWO_PI * i/(Real)mNumSegCircle;
Real x0 = mRadius*(2 + cos(mQ*phi/(Real)mP)) * cos(phi) / 3.f;
Real y0 = mRadius*sin(mQ*phi/(Real)mP) / 3.f;
Real z0 = mRadius*(2 + cos(mQ*phi/(Real)mP)) * sin(phi) / 3.f;
Real phi1 = Math::TWO_PI * (i+1)/(Real)mNumSegCircle;
Real x1 = mRadius*(2 + cos(mQ*phi1/(Real)mP)) * cos(phi1) / 3.f;
Real y1 = mRadius*sin(mQ*phi1/mP) / 3.f;
Real z1 = mRadius*(2 + cos(mQ*phi1/(Real)mP)) * sin(phi1) / 3.f;
Vector3 v0(x0,y0,z0);
Vector3 v1(x1,y1,z1);
Vector3 direction((v1-v0).normalisedCopy());
Quaternion q = Utils::_computeQuaternion(direction);
for (int j =0;j<=mNumSegSection;j++)
{
Real alpha = Math::TWO_PI *j/mNumSegSection;
Vector3 vp = mSectionRadius*(q * Vector3(cos(alpha), sin(alpha),0));
addPoint(buffer, v0+vp,
vp.normalisedCopy(),
Vector2(i/(Real)mNumSegCircle, j/(Real)mNumSegSection));
if (i != mNumSegCircle * mP)
{
buffer.index(offset + mNumSegSection + 1);
buffer.index(offset + mNumSegSection);
buffer.index(offset);
buffer.index(offset + mNumSegSection + 1);
buffer.index(offset);
buffer.index(offset + 1);
}
offset ++;
}
}
}
示例5: addToTriangleBuffer
void SphereGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(mNumRings>0 && mNumSegments>0 && "Num seg must be positive");
assert(mRadius>0 && "Radius must be positive");
buffer.rebaseOffset();
buffer.estimateVertexCount((mNumRings+1)*(mNumSegments+1));
buffer.estimateIndexCount(mNumRings*(mNumSegments+1)*6);
Real fDeltaRingAngle = (Math::PI / mNumRings);
Real fDeltaSegAngle = (Math::TWO_PI / mNumSegments);
int offset = 0;
// Generate the group of rings for the sphere
for(unsigned int ring = 0; ring <= mNumRings; ring++ ) {
Real r0 = mRadius * sinf (ring * fDeltaRingAngle);
Real y0 = mRadius * cosf (ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for(unsigned int seg = 0; seg <= mNumSegments; seg++) {
Real x0 = r0 * sinf(seg * fDeltaSegAngle);
Real z0 = r0 * cosf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
addPoint(buffer, Vector3(x0, y0, z0),
Vector3(x0, y0, z0).normalisedCopy(),
Vector2((Real) seg / (Real) mNumSegments, (Real) ring / (Real) mNumRings));
if (ring != mNumRings) {
// each vertex (except the last) has six indices pointing to it
buffer.index(offset + mNumSegments + 1);
buffer.index(offset);
buffer.index(offset + mNumSegments);
buffer.index(offset + mNumSegments + 1);
buffer.index(offset + 1);
buffer.index(offset);
offset ++;
}
}; // end for seg
} // end for ring
}
示例6: addToTriangleBuffer
void CylinderGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(mHeight>0. && mRadius>0. && "height and radius must be positive");
assert(mNumSegBase>0 && mNumSegHeight>0 && "Num seg must be positive integers");
buffer.rebaseOffset();
if (mCapped)
{
buffer.estimateVertexCount((mNumSegHeight+1)*(mNumSegBase+1)+2*(mNumSegBase+1)+2);
buffer.estimateIndexCount(mNumSegHeight*(mNumSegBase+1)*6+6*mNumSegBase);
} else {
buffer.estimateVertexCount((mNumSegHeight+1)*(mNumSegBase+1));
buffer.estimateIndexCount(mNumSegHeight*(mNumSegBase+1)*6);
}
Real deltaAngle = (Math::TWO_PI / mNumSegBase);
Real deltaHeight = mHeight/(Real)mNumSegHeight;
int offset = 0;
for (int i = 0; i <=mNumSegHeight; i++)
for (int j = 0; j<=mNumSegBase; j++)
{
Real x0 = mRadius * cosf(j*deltaAngle);
Real z0 = mRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, i*deltaHeight, z0),
Vector3(x0,0,z0).normalisedCopy(),
Vector2(j/(Real)mNumSegBase, i/(Real)mNumSegHeight));
if (i != mNumSegHeight)
{
buffer.index(offset + mNumSegBase + 1);
buffer.index(offset);
buffer.index(offset + mNumSegBase);
buffer.index(offset + mNumSegBase + 1);
buffer.index(offset + 1);
buffer.index(offset);
}
offset ++;
}
if (mCapped)
{
//low cap
int centerIndex = offset;
addPoint(buffer, Vector3::ZERO,
Vector3::NEGATIVE_UNIT_Y,
Vector2::UNIT_Y);
offset++;
for (int j=0;j<=mNumSegBase;j++)
{
Real x0 = mRadius * cosf(j*deltaAngle);
Real z0 = mRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, 0.0f, z0),
Vector3::NEGATIVE_UNIT_Y,
Vector2(j/(Real)mNumSegBase,0.0));
if (j!=mNumSegBase)
{
buffer.index(centerIndex);
buffer.index(offset);
buffer.index(offset+1);
}
offset++;
}
// high cap
centerIndex = offset;
addPoint(buffer, Vector3(0,mHeight,0),
Vector3::UNIT_Y,
Vector2::ZERO);
offset++;
for (int j=0;j<=mNumSegBase;j++)
{
Real x0 = mRadius * cosf(j*deltaAngle);
Real z0 = mRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, mHeight, z0),
Vector3::UNIT_Y,
Vector2(j/(Real)mNumSegBase,1.));
if (j!=mNumSegBase)
{
buffer.index(centerIndex);
buffer.index(offset+1);
buffer.index(offset);
}
offset++;
}
}
}
示例7: addToTriangleBuffer
void CapsuleGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(mNumRings>0 && mNumSegments>0 && mNumSegHeight>0 && "Num seg must be positive integers");
assert(mHeight>0. && mRadius>0. && "mHeight and radius must be positive");
buffer.rebaseOffset();
buffer.estimateVertexCount((2*mNumRings+2)*(mNumSegments+1) + (mNumSegHeight-1)*(mNumSegments+1));
buffer.estimateIndexCount((2*mNumRings+1)*(mNumSegments+1)*6 + (mNumSegHeight-1)*(mNumSegments+1)*6);
Real fDeltaRingAngle = (Math::HALF_PI / mNumRings);
Real fDeltaSegAngle = (Math::TWO_PI / mNumSegments);
Real sphereRatio = mRadius / (2 * mRadius + mHeight);
Real cylinderRatio = mHeight / (2 * mRadius + mHeight);
int offset = 0;
// Top half sphere
// Generate the group of rings for the sphere
for(unsigned int ring = 0; ring <= mNumRings; ring++ )
{
Real r0 = mRadius * sinf ( ring * fDeltaRingAngle);
Real y0 = mRadius * cosf (ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for(unsigned int seg = 0; seg <= mNumSegments; seg++)
{
Real x0 = r0 * cosf(seg * fDeltaSegAngle);
Real z0 = r0 * sinf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
addPoint(buffer, Vector3(x0, 0.5f*mHeight + y0, z0),
Vector3(x0, y0, z0).normalisedCopy(),
Vector2((Real) seg / (Real) mNumSegments, (Real) ring / (Real) mNumRings * sphereRatio));
// each vertex (except the last) has six indices pointing to it
buffer.index(offset + mNumSegments + 1);
buffer.index(offset + mNumSegments);
buffer.index(offset);
buffer.index(offset + mNumSegments + 1);
buffer.index(offset);
buffer.index(offset + 1);
offset ++;
} // end for seg
} // end for ring
// Cylinder part
Real deltaAngle = (Math::TWO_PI / mNumSegments);
Real deltamHeight = mHeight/(Real)mNumSegHeight;
for (unsigned short i = 1; i < mNumSegHeight; i++)
for (unsigned short j = 0; j<=mNumSegments; j++)
{
Real x0 = mRadius * cosf(j*deltaAngle);
Real z0 = mRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, 0.5f*mHeight-i*deltamHeight, z0),
Vector3(x0,0,z0).normalisedCopy(),
Vector2(j/(Real)mNumSegments, i/(Real)mNumSegHeight * cylinderRatio + sphereRatio));
buffer.index(offset + mNumSegments + 1);
buffer.index(offset + mNumSegments);
buffer.index(offset);
buffer.index(offset + mNumSegments + 1);
buffer.index(offset);
buffer.index(offset + 1);
offset ++;
}
// Bottom half sphere
// Generate the group of rings for the sphere
for(unsigned int ring = 0; ring <= mNumRings; ring++)
{
Real r0 = mRadius * sinf (Math::HALF_PI + ring * fDeltaRingAngle);
Real y0 = mRadius * cosf (Math::HALF_PI + ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for(unsigned int seg = 0; seg <= mNumSegments; seg++)
{
Real x0 = r0 * cosf(seg * fDeltaSegAngle);
Real z0 = r0 * sinf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
addPoint(buffer, Vector3(x0, -0.5f*mHeight + y0, z0),
Vector3(x0, y0, z0).normalisedCopy(),
Vector2((Real) seg / (Real) mNumSegments, (Real) ring / (Real) mNumRings*sphereRatio + cylinderRatio + sphereRatio));
if (ring != mNumRings)
{
// each vertex (except the last) has six indices pointing to it
buffer.index(offset + mNumSegments + 1);
buffer.index(offset + mNumSegments);
buffer.index(offset);
buffer.index(offset + mNumSegments + 1);
buffer.index(offset);
buffer.index(offset + 1);
}
offset ++;
//.........这里部分代码省略.........
示例8: addToTriangleBuffer
void TubeGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
buffer.rebaseOffset();
buffer.estimateVertexCount((mNumSegHeight+1)*(mNumSegBase+1)*2+(mNumSegBase+1)*4);
buffer.estimateIndexCount(6*(mNumSegBase+1)*mNumSegHeight*2+6*mNumSegBase*2);
Real deltaAngle = (Math::TWO_PI / mNumSegBase);
Real deltaHeight = mHeight/(Real)mNumSegHeight;
int offset = 0;
for (unsigned int i = 0; i <=mNumSegHeight; i++)
for (unsigned int j = 0; j<=mNumSegBase; j++)
{
Real x0 = mOuterRadius * cosf(j*deltaAngle);
Real z0 = mOuterRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, i*deltaHeight, z0),
Vector3(x0,0,z0).normalisedCopy(),
Vector2(j/(Real)mNumSegBase, i/(Real)mNumSegHeight));
if (i != mNumSegHeight)
{
buffer.index(offset + mNumSegBase + 1);
buffer.index(offset);
buffer.index(offset + mNumSegBase);
buffer.index(offset + mNumSegBase + 1);
buffer.index(offset + 1);
buffer.index(offset);
}
offset ++;
}
for (unsigned int i = 0; i <=mNumSegHeight; i++)
for (unsigned int j = 0; j<=mNumSegBase; j++)
{
Real x0 = mInnerRadius * cosf(j*deltaAngle);
Real z0 = mInnerRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, i*deltaHeight, z0),
-Vector3(x0,0,z0).normalisedCopy(),
Vector2(j/(Real)mNumSegBase, i/(Real)mNumSegHeight));
if (i != mNumSegHeight)
{
buffer.index(offset + mNumSegBase + 1);
buffer.index(offset + mNumSegBase);
buffer.index(offset);
buffer.index(offset + mNumSegBase + 1);
buffer.index(offset);
buffer.index(offset + 1);
}
offset ++;
}
//low cap
for (unsigned int j=0; j<=mNumSegBase; j++)
{
Real x0 = mInnerRadius * cosf(j*deltaAngle);
Real z0 = mInnerRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, 0.0f, z0),
Vector3::NEGATIVE_UNIT_Y,
Vector2(j/(Real)mNumSegBase,1.));
x0 = mOuterRadius * cosf(j*deltaAngle);
z0 = mOuterRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, 0.0f, z0),
Vector3::NEGATIVE_UNIT_Y,
Vector2(j/(Real)mNumSegBase,0.));
if (j!=mNumSegBase)
{
buffer.index(offset);
buffer.index(offset+1);
buffer.index(offset+3);
buffer.index(offset+2);
buffer.index(offset);
buffer.index(offset+3);
}
offset+=2;
}
//high cap
for (unsigned int j=0; j<=mNumSegBase; j++)
{
Real x0 = mInnerRadius * cosf(j*deltaAngle);
Real z0 = mInnerRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, mHeight, z0),
Vector3::UNIT_Y,
Vector2(j/(Real)mNumSegBase,0.));
x0 = mOuterRadius * cosf(j*deltaAngle);
z0 = mOuterRadius * sinf(j*deltaAngle);
addPoint(buffer, Vector3(x0, mHeight, z0),
Vector3::UNIT_Y,
Vector2(j/(Real)mNumSegBase,1.));
//.........这里部分代码省略.........
示例9: _extrudeCapImpl
//-----------------------------------------------------------------------
void Extruder::_extrudeCapImpl(TriangleBuffer& buffer) const
{
std::vector<int> indexBuffer;
PointList pointList;
buffer.rebaseOffset();
Triangulator t;
if (mShapeToExtrude)
t.setShapeToTriangulate(mShapeToExtrude);
else
t.setMultiShapeToTriangulate(mMultiShapeToExtrude);
t.triangulate(indexBuffer, pointList);
buffer.estimateIndexCount(2*indexBuffer.size());
buffer.estimateVertexCount(2*pointList.size());
//begin cap
buffer.rebaseOffset();
Quaternion qBegin = Utils::_computeQuaternion(mExtrusionPath->getDirectionAfter(0));
if (mRotationTrack)
{
Real angle = mRotationTrack->getFirstValue();
qBegin = qBegin*Quaternion((Radian)angle, Vector3::UNIT_Z);
}
Real scaleBegin=1.;
if (mScaleTrack)
scaleBegin = mScaleTrack->getFirstValue();
for (size_t j =0;j<pointList.size();j++)
{
Vector2 vp2 = pointList[j];
Vector3 vp(vp2.x, vp2.y, 0);
Vector3 normal = -Vector3::UNIT_Z;
Vector3 newPoint = mExtrusionPath->getPoint(0)+qBegin*(scaleBegin*vp);
addPoint(buffer, newPoint,
qBegin*normal,
vp2);
}
for (size_t i=0;i<indexBuffer.size()/3;i++)
{
buffer.index(indexBuffer[i*3]);
buffer.index(indexBuffer[i*3+2]);
buffer.index(indexBuffer[i*3+1]);
}
// end cap
buffer.rebaseOffset();
Quaternion qEnd = Utils::_computeQuaternion(mExtrusionPath->getDirectionBefore(mExtrusionPath->getSegCount()));
if (mRotationTrack)
{
Real angle = mRotationTrack->getLastValue();
qEnd = qEnd*Quaternion((Radian)angle, Vector3::UNIT_Z);
}
Real scaleEnd=1.;
if (mScaleTrack)
scaleEnd = mScaleTrack->getLastValue();
for (size_t j =0;j<pointList.size();j++)
{
Vector2 vp2 = pointList[j];
Vector3 vp(vp2.x, vp2.y, 0);
Vector3 normal = Vector3::UNIT_Z;
Vector3 newPoint = mExtrusionPath->getPoint(mExtrusionPath->getSegCount())+qEnd*(scaleEnd*vp);
addPoint(buffer, newPoint,
qEnd*normal,
vp2);
}
for (size_t i=0;i<indexBuffer.size()/3;i++)
{
buffer.index(indexBuffer[i*3]);
buffer.index(indexBuffer[i*3+1]);
buffer.index(indexBuffer[i*3+2]);
}
}
示例10: addToTriangleBuffer
//.........这里部分代码省略.........
//now recreate indices
newFaces.push_back(i1);
newFaces.push_back(i12);
newFaces.push_back(i13);
newFaces.push_back(i2);
newFaces.push_back(i23);
newFaces.push_back(i12);
newFaces.push_back(i3);
newFaces.push_back(i13);
newFaces.push_back(i23);
newFaces.push_back(i12);
newFaces.push_back(i23);
newFaces.push_back(i13);
}
faces.swap(newFaces);
}
/// Step 3 : generate texcoords
std::vector<Vector2> texCoords;
for (unsigned short i=0;i<vertices.size();i++)
{
const Vector3& vec = vertices[i];
Real u, v;
Real r0 = sqrtf(vec.x*vec.x+vec.z*vec.z);
Real alpha;
alpha = atan2f(vec.z,vec.x);
u = alpha/Math::TWO_PI+.5f;
v = atan2f(vec.y, r0)/Math::PI + .5f;
texCoords.push_back(Vector2(u,v));
}
/// Step 4 : fix texcoords
// find vertices to split
std::vector<int> indexToSplit;
for (unsigned int i=0;i<faces.size()/3;i++)
{
Vector2& t0 = texCoords[faces[i*3+0]];
Vector2& t1 = texCoords[faces[i*3+1]];
Vector2& t2 = texCoords[faces[i*3+2]];
if (Math::Abs(t2.x-t0.x)>0.5)
{
if (t0.x<0.5)
indexToSplit.push_back(faces[i*3]);
else
indexToSplit.push_back(faces[i*3+2]);
}
if (Math::Abs(t1.x-t0.x)>0.5)
{
if (t0.x<0.5)
indexToSplit.push_back(faces[i*3]);
else
indexToSplit.push_back(faces[i*3+1]);
}
if (Math::Abs(t2.x-t1.x)>0.5)
{
if (t1.x<0.5)
indexToSplit.push_back(faces[i*3+1]);
else
indexToSplit.push_back(faces[i*3+2]);
}
}
//split vertices
for (unsigned short i=0;i<indexToSplit.size();i++)
{
示例11: addToTriangleBuffer
void CapsuleGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(numRings>0 && numSegments>0 && numSegHeight>0 && "Num seg must be positive integers");
assert(height>0. && radius>0. && "Height and radius must be positive");
buffer.rebaseOffset();
buffer.estimateVertexCount((2*numRings+2)*(numSegments+1) + (numSegHeight-1)*(numSegments+1));
buffer.estimateIndexCount((2*numRings+1)*(numSegments+1)*6 + (numSegHeight-1)*(numSegments+1)*6);
Ogre::Real fDeltaRingAngle = (Ogre::Math::HALF_PI / numRings);
Ogre::Real fDeltaSegAngle = (Ogre::Math::TWO_PI / numSegments);
Ogre::Real sphereRatio = radius / (2 * radius + height);
Ogre::Real cylinderRatio = height / (2 * radius + height);
int offset = 0;
// Top half sphere
// Generate the group of rings for the sphere
for(unsigned int ring = 0; ring <= numRings; ring++ )
{
Ogre::Real r0 = radius * sinf ( ring * fDeltaRingAngle);
Ogre::Real y0 = radius * cosf (ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for(unsigned int seg = 0; seg <= numSegments; seg++)
{
Ogre::Real x0 = r0 * cosf(seg * fDeltaSegAngle);
Ogre::Real z0 = r0 * sinf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
buffer.position( x0, 0.5*height + y0, z0);
if (enableNormals)
buffer.normal(Ogre::Vector3(x0, y0, z0).normalisedCopy());
for (unsigned int tc=0;tc<numTexCoordSet;tc++)
buffer.textureCoord((Ogre::Real) seg / (Ogre::Real) numSegments * uTile, (Ogre::Real) ring / (Ogre::Real) numRings * vTile * sphereRatio);
// each vertex (except the last) has six indices pointing to it
buffer.index(offset + numSegments + 1);
buffer.index(offset + numSegments);
buffer.index(offset);
buffer.index(offset + numSegments + 1);
buffer.index(offset);
buffer.index(offset + 1);
offset ++;
} // end for seg
} // end for ring
// Cylinder part
Ogre::Real deltaAngle = (Ogre::Math::TWO_PI / numSegments);
Ogre::Real deltaHeight = height/(Ogre::Real)numSegHeight;
for (int i = 1; i < numSegHeight; i++)
for (int j = 0; j<=numSegments; j++)
{
Ogre::Real x0 = radius * cosf(j*deltaAngle);
Ogre::Real z0 = radius * sinf(j*deltaAngle);
buffer.position(x0, 0.5*height-i*deltaHeight, z0);
buffer.normal(Ogre::Vector3(x0,0,z0).normalisedCopy());
buffer.textureCoord(j/(Ogre::Real)numSegments*uTile, i/(Ogre::Real)numSegHeight*vTile * cylinderRatio + sphereRatio);
buffer.index(offset + numSegments + 1);
buffer.index(offset + numSegments);
buffer.index(offset);
buffer.index(offset + numSegments + 1);
buffer.index(offset);
buffer.index(offset + 1);
offset ++;
}
// Bottom half sphere
// Generate the group of rings for the sphere
for(unsigned int ring = 0; ring <= numRings; ring++)
{
Ogre::Real r0 = radius * sinf (Ogre::Math::HALF_PI + ring * fDeltaRingAngle);
Ogre::Real y0 = radius * cosf (Ogre::Math::HALF_PI + ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for(unsigned int seg = 0; seg <= numSegments; seg++)
{
Ogre::Real x0 = r0 * cosf(seg * fDeltaSegAngle);
Ogre::Real z0 = r0 * sinf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
buffer.position( x0, -0.5*height + y0, z0);
if (enableNormals)
buffer.normal(Ogre::Vector3(x0, y0, z0).normalisedCopy());
for (unsigned int tc=0;tc<numTexCoordSet;tc++)
buffer.textureCoord((Ogre::Real) seg / (Ogre::Real) numSegments * uTile, (Ogre::Real) ring / (Ogre::Real) numRings * vTile*sphereRatio + cylinderRatio + sphereRatio);
if (ring != numRings)
{
// each vertex (except the last) has six indices pointing to it
buffer.index(offset + numSegments + 1);
buffer.index(offset + numSegments);
buffer.index(offset);
buffer.index(offset + numSegments + 1);
buffer.index(offset);
//.........这里部分代码省略.........
示例12: addToTriangleBuffer
void TubeGenerator::addToTriangleBuffer(TriangleBuffer& buffer) const
{
assert(height>0. && outerRadius>0. && innerRadius>0. && "Height and radius must be positive");
assert(innerRadius<outerRadius && "Outer radius must be bigger than inner radius");
assert(numSegBase>0 && numSegHeight>0 && "Num seg must be positive integers");
buffer.rebaseOffset();
buffer.estimateVertexCount((numSegHeight+1)*(numSegBase+1)*2+(numSegBase+1)*4);
buffer.estimateIndexCount(6*(numSegBase+1)*numSegHeight*2+6*numSegBase*2);
Ogre::Real deltaAngle = (Ogre::Math::TWO_PI / numSegBase);
Ogre::Real deltaHeight = height/(Ogre::Real)numSegHeight;
int offset = 0;
for (int i = 0; i <=numSegHeight; i++)
for (int j = 0; j<=numSegBase; j++)
{
Ogre::Real x0 = outerRadius * cosf(j*deltaAngle);
Ogre::Real z0 = outerRadius * sinf(j*deltaAngle);
buffer.position(x0, i*deltaHeight, z0);
buffer.normal(Ogre::Vector3(x0,0,z0).normalisedCopy());
buffer.textureCoord(j/(Ogre::Real)numSegBase*uTile, i/(Ogre::Real)numSegHeight*vTile);
if (i != numSegHeight)
{
buffer.index(offset + numSegBase + 1);
buffer.index(offset);
buffer.index(offset + numSegBase);
buffer.index(offset + numSegBase + 1);
buffer.index(offset + 1);
buffer.index(offset);
}
offset ++;
}
for (int i = 0; i <=numSegHeight; i++)
for (int j = 0; j<=numSegBase; j++)
{
Ogre::Real x0 = innerRadius * cosf(j*deltaAngle);
Ogre::Real z0 = innerRadius * sinf(j*deltaAngle);
buffer.position(x0, i*deltaHeight, z0);
buffer.normal(-Ogre::Vector3(x0,0,z0).normalisedCopy());
buffer.textureCoord(j/(Ogre::Real)numSegBase*uTile, i/(Ogre::Real)numSegHeight*vTile);
if (i != numSegHeight)
{
buffer.index(offset + numSegBase + 1);
buffer.index(offset + numSegBase);
buffer.index(offset);
buffer.index(offset + numSegBase + 1);
buffer.index(offset);
buffer.index(offset + 1);
}
offset ++;
}
//low cap
for (int j=0;j<=numSegBase;j++)
{
Ogre::Real x0 = innerRadius * cosf(j*deltaAngle);
Ogre::Real z0 = innerRadius * sinf(j*deltaAngle);
buffer.position(x0, 0.0f, z0);
buffer.normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
buffer.textureCoord(j/(Ogre::Real)numSegBase*uTile,vTile);
x0 = outerRadius * cosf(j*deltaAngle);
z0 = outerRadius * sinf(j*deltaAngle);
buffer.position(x0, 0.0f, z0);
buffer.normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
buffer.textureCoord(j/(Ogre::Real)numSegBase*uTile,0.0);
if (j!=numSegBase)
{
buffer.index(offset);
buffer.index(offset+1);
buffer.index(offset+3);
buffer.index(offset+2);
buffer.index(offset);
buffer.index(offset+3);
}
offset+=2;
}
//high cap
for (int j=0;j<=numSegBase;j++)
{
Ogre::Real x0 = innerRadius * cosf(j*deltaAngle);
Ogre::Real z0 = innerRadius * sinf(j*deltaAngle);
buffer.position(x0, height, z0);
buffer.normal(Ogre::Vector3::UNIT_Y);
buffer.textureCoord(j/(Ogre::Real)numSegBase*uTile,0.0);
x0 = outerRadius * cosf(j*deltaAngle);
z0 = outerRadius * sinf(j*deltaAngle);
//.........这里部分代码省略.........
示例13: _latheCapImpl
//-----------------------------------------------------------------------
void Lathe::_latheCapImpl(TriangleBuffer& buffer) const
{
std::vector<int> indexBuffer;
PointList pointList;
buffer.rebaseOffset();
Triangulator t;
Shape shapeCopy;
MultiShape multishapeCopy;
if (mShapeToExtrude)
{
shapeCopy = *mShapeToExtrude;
shapeCopy.close();
t.setShapeToTriangulate(&shapeCopy);
}
else
{
multishapeCopy = *mMultiShapeToExtrude;
multishapeCopy.close();
t.setMultiShapeToTriangulate(mMultiShapeToExtrude);
}
t.triangulate(indexBuffer, pointList);
buffer.estimateIndexCount(2*indexBuffer.size());
buffer.estimateVertexCount(2*pointList.size());
//begin cap
buffer.rebaseOffset();
Quaternion q;
q.FromAngleAxis(mAngleBegin, Vector3::UNIT_Y);
for (size_t j =0;j<pointList.size();j++)
{
Vector2 vp2 = pointList[j];
Vector3 vp(vp2.x, vp2.y, 0);
Vector3 normal = Vector3::UNIT_Z;
addPoint(buffer, q*vp,
q*normal,
vp2);
}
for (size_t i=0;i<indexBuffer.size()/3;i++)
{
buffer.index(indexBuffer[i*3]);
buffer.index(indexBuffer[i*3+1]);
buffer.index(indexBuffer[i*3+2]);
}
//end cap
buffer.rebaseOffset();
q.FromAngleAxis(mAngleEnd, Vector3::UNIT_Y);
for (size_t j =0;j<pointList.size();j++)
{
Vector2 vp2 = pointList[j];
Vector3 vp(vp2.x, vp2.y, 0);
Vector3 normal = -Vector3::UNIT_Z;
addPoint(buffer, q*vp,
q*normal,
vp2);
}
for (size_t i=0;i<indexBuffer.size()/3;i++)
{
buffer.index(indexBuffer[i*3]);
buffer.index(indexBuffer[i*3+2]);
buffer.index(indexBuffer[i*3+1]);
}
}