void TorusGenerator::AddToTriangleBuffer(TriangleBuffer& Buffer) const { Buffer.RebaseOffset(); Buffer.EstimateVertexCount( ( this->NumPoloidalSeg + 1 ) * ( this->NumToroidalSeg + 1 ) ); Buffer.EstimateIndexCount( ( this->NumPoloidalSeg ) * ( this->NumToroidalSeg + 1 ) * 6 ); Real deltaSection = ( MathTools::GetTwoPi() / this->NumToroidalSeg ); Real deltaCircle = ( MathTools::GetTwoPi() / this->NumPoloidalSeg ); Integer Offset = 0; for( Whole i = 0 ; i <= this->NumPoloidalSeg ; i++ ) { for( Whole j = 0 ; j<= this->NumToroidalSeg ; j++ ) { Vector3 c0( this->TorusPoloidalRadius, 0.0, 0.0 ); Vector3 v0( this->TorusPoloidalRadius + this->TorusToroidalRadius * cosf( j * deltaSection ), this->TorusToroidalRadius * sinf( j * deltaSection ), 0.0 ); Quaternion q( i * deltaCircle, Vector3::Unit_Y() ); Vector3 v = q * v0; Vector3 c = q * c0; this->AddPoint( Buffer, v, ( v - c ).GetNormal(), Vector2( i / (Real)this->NumPoloidalSeg, j / (Real)this->NumToroidalSeg ) ); if( i != this->NumPoloidalSeg ) { Buffer.AddIndex( Offset + this->NumToroidalSeg + 1 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + this->NumToroidalSeg ); Buffer.AddIndex( Offset + this->NumToroidalSeg + 1 ); Buffer.AddIndex( Offset + 1 ); Buffer.AddIndex( Offset ); } Offset++; } } }
void TubeGenerator::AddToTriangleBuffer(TriangleBuffer& Buffer) const { Buffer.RebaseOffset(); Buffer.EstimateVertexCount( ( this->NumSegHeight + 1 ) * ( this->NumSegCircle + 1 ) * 2 + ( this->NumSegCircle + 1 ) * 4 ); Buffer.EstimateIndexCount( 6 * ( this->NumSegCircle + 1 ) * this->NumSegHeight * 2 + 6 * this->NumSegCircle * 2 ); Real deltaAngle = ( MathTools::GetTwoPi() / this->NumSegCircle ); Real deltaHeight = this->TubeHeight / (Real)this->NumSegHeight; int Offset = 0; for( Whole i = 0 ; i <= this->NumSegHeight ; ++i ) { for( Whole j = 0 ; j <= this->NumSegCircle ; ++j ) { Real x0 = this->TubeOuterRadius * cosf( j * deltaAngle ); Real z0 = this->TubeOuterRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3( x0, i * deltaHeight, z0 ), Vector3( x0, 0, z0 ).GetNormal(), Vector2( j / (Real)this->NumSegCircle, i / (Real)this->NumSegHeight ) ); if( i != this->NumSegHeight ) { Buffer.AddIndex( Offset + this->NumSegCircle + 1 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + this->NumSegCircle ); Buffer.AddIndex( Offset + this->NumSegCircle + 1 ); Buffer.AddIndex( Offset + 1 ); Buffer.AddIndex( Offset ); } Offset++; } } for( Whole i = 0 ; i <= this->NumSegHeight ; ++i ) { for( Whole j = 0 ; j<= this->NumSegCircle ; ++j ) { Real x0 = this->TubeInnerRadius * cosf( j * deltaAngle ); Real z0 = this->TubeInnerRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3( x0, i * deltaHeight, z0 ), -Vector3( x0, 0, z0 ).GetNormal(), Vector2( j / (Real)this->NumSegCircle, i / (Real)this->NumSegHeight ) ); if( i != this->NumSegHeight ) { Buffer.AddIndex( Offset + this->NumSegCircle + 1 ); Buffer.AddIndex( Offset + this->NumSegCircle ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + this->NumSegCircle + 1 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + 1); } Offset++; } } //low cap for( Whole j = 0 ; j <= this->NumSegCircle ; ++j ) { Real x0 = this->TubeInnerRadius * cosf( j * deltaAngle ); Real z0 = this->TubeInnerRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3( x0, 0.0f, z0 ), Vector3::Neg_Unit_Y(), Vector2( j / (Real)this->NumSegCircle, 1. ) ); x0 = this->TubeOuterRadius * cosf( j * deltaAngle ); z0 = this->TubeOuterRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3( x0, 0.0f, z0 ), Vector3::Neg_Unit_Y(), Vector2( j / (Real)this->NumSegCircle, 0. ) ); if( j != this->NumSegCircle ) { Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + 1 ); Buffer.AddIndex( Offset + 3 ); Buffer.AddIndex( Offset + 2 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + 3 ); } Offset += 2; } //high cap for( Whole j = 0 ; j <= this->NumSegCircle ; ++j ) { Real x0 = this->TubeInnerRadius * cosf( j * deltaAngle ); Real z0 = this->TubeInnerRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3( x0, this->TubeHeight, z0 ), Vector3::Unit_Y(), Vector2( j / (Real)this->NumSegCircle, 0. ) ); x0 = this->TubeOuterRadius * cosf( j * deltaAngle ); z0 = this->TubeOuterRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3( x0, this->TubeHeight, z0 ), Vector3::Unit_Y(), Vector2( j / (Real)this->NumSegCircle, 1. ) ); if( j != this->NumSegCircle ) { Buffer.AddIndex( Offset + 1 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + 3 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + 2 ); Buffer.AddIndex( Offset + 3 ); } Offset += 2; } }
void ConeGenerator::AddToTriangleBuffer(TriangleBuffer& Buffer) const { Buffer.RebaseOffset(); Buffer.EstimateVertexCount( ( this->NumSegHeight + 1 ) * ( this->NumSegCircle + 1 ) + this->NumSegCircle + 2 ); Buffer.EstimateIndexCount( this->NumSegHeight * this->NumSegCircle * 6 + 3 * this->NumSegCircle ); Real deltaAngle = ( MathTools::GetTwoPi() / this->NumSegCircle ); Real deltaHeight = this->ConeHeight / (Real)this->NumSegHeight; Integer Offset = 0; Vector3 refNormal = Vector3( this->ConeRadius, this->ConeHeight, 0.f ).GetNormal(); Quaternion q; for( Whole i = 0 ; i <= this->NumSegHeight ; i++ ) { Real r0 = this->ConeRadius * ( 1 - i / (Real)this->NumSegHeight ); for( Whole j = 0; j <= this->NumSegCircle ; j++ ) { Real x0 = r0 * cosf( j * deltaAngle ); Real z0 = r0 * sinf( j * deltaAngle ); q.SetFromAxisAngle( -deltaAngle * j, Vector3::Unit_Y() ); this->AddPoint(Buffer, Vector3( x0, i * deltaHeight, z0 ), q * refNormal, Vector2( j / (Real)this->NumSegCircle, i / (Real)this->NumSegHeight ) ); if( i != this->NumSegHeight && j != this->NumSegCircle ) { Buffer.AddIndex( Offset + this->NumSegCircle + 2 ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + this->NumSegCircle + 1 ); Buffer.AddIndex( Offset + this->NumSegCircle + 2 ); Buffer.AddIndex( Offset + 1 ); Buffer.AddIndex( Offset ); } Offset++; } } //low cap Integer CenterIndex = Offset; this->AddPoint(Buffer, Vector3(0.0,0.0,0.0), Vector3::Neg_Unit_Y(), Vector2(0.0,1.0) ); Offset++; for( Whole j = 0 ; j <= this->NumSegCircle ; j++ ) { Real x0 = this->ConeRadius * cosf( j * deltaAngle ); Real z0 = this->ConeRadius * sinf( j * deltaAngle ); this->AddPoint(Buffer, Vector3(x0, 0.0f, z0), Vector3::Neg_Unit_Y(), Vector2( j / (Real)this->NumSegCircle, 0.0 ) ); if( j != this->NumSegCircle ) { Buffer.AddIndex( CenterIndex ); Buffer.AddIndex( Offset ); Buffer.AddIndex( Offset + 1 ); } Offset++; } }