MCPcopy Create free account
hub / github.com/carbonengine/trinity / AddSphere

Method AddSphere

trinity/TriLineSet.cpp:77–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77void TriLineSet::AddSphere( const Vector3& center, float radius, int segments, uint32_t color )
78{
79 if( segments < 4 )
80 {
81 segments = 4;
82 }
83
84 if( segments % 2 == 1 )
85 {
86 ++segments;
87 }
88
89 float step = ( XM_PI * 2.0f ) / (float)segments;
90 float halfStep = step * 0.5f;
91
92 float curRadius = 0.0f;
93 float curY = 0.0f;
94 for( int i = 0; i < segments; ++i )
95 {
96 float fi = (float)i;
97
98 float nextRadius = sin( fi * halfStep ) * radius;
99 float nextY = cos( fi * halfStep ) * radius;
100
101 for( int j = 0; j < segments; ++j )
102 {
103 float t0 = (float)j * step;
104 float x0 = sin( t0 ) * curRadius;
105 float z0 = cos( t0 ) * curRadius;
106
107 float t1 = t0 + step;
108 float x1 = sin( t1 ) * curRadius;
109 float z1 = cos( t1 ) * curRadius;
110
111 Vector3 from;
112 from.x = x0 + center.x;
113 from.y = center.y - curY;
114 from.z = z0 + center.z;
115
116 Vector3 to;
117 to.x = x1 + center.x;
118 to.y = from.y;
119 to.z = z1 + center.z;
120
121 Add( from, color, to, color );
122
123 Vector3 nextTo;
124 nextTo.x = center.x + sin( t0 ) * nextRadius;
125 nextTo.y = center.y - nextY;
126 nextTo.z = center.z + cos( t0 ) * nextRadius;
127
128 Add( from, color, nextTo, color );
129
130 from.y = center.y + curY;
131 to.y = from.y;
132
133 Add( from, color, to, color );
134

Callers 3

DrawSphereMethod · 0.80
DrawSphereMethod · 0.80
DrawCapsuleMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected