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

Method AddCylinder

trinity/TriLineSet.cpp:145–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145void TriLineSet::AddCylinder( const Vector3& start, const Vector3& end, float radius, int segments, uint32_t color )
146{
147 Vector3 z = start - end;
148 float length = Length( z );
149 z /= length;
150
151 Vector3 up( 0.0f, 1.0f, 0.0f );
152 if( fabs( z.y ) > 0.99f )
153 {
154 up = Vector3( 1.0f, 0.0f, 0.0f );
155 }
156
157 Vector3 x = Normalize( Cross( up, z ) );
158
159 Vector3 y = Cross( z, x );
160
161 Matrix m;
162 m._11 = x.x;
163 m._12 = x.y;
164 m._13 = x.z;
165 m._14 = 0.0f;
166
167 m._21 = y.x;
168 m._22 = y.y;
169 m._23 = y.z;
170 m._24 = 0.0f;
171
172 m._31 = z.x;
173 m._32 = z.y;
174 m._33 = z.z;
175 m._34 = 0.0f;
176
177 m._41 = end.x;
178 m._42 = end.y;
179 m._43 = end.z;
180 m._44 = 1.0f;
181
182 Matrix scale = ScalingMatrix( radius, radius, length );
183 m = scale * m;
184
185 if( segments < 4 )
186 {
187 segments = 4;
188 }
189
190 if( segments % 2 == 1 )
191 {
192 ++segments;
193 }
194
195 float step = ( XM_PI * 2.0f ) / (float)segments;
196 for( int i = 0; i < segments; ++i )
197 {
198 float x = cosf( i * step );
199 float y = sinf( i * step );
200
201 Vector3 from( x, y, 0.0f );
202 Vector3 to( x, y, 1.0f );

Callers 2

DrawCapsuleMethod · 0.80
DrawCylinderMethod · 0.80

Calls 3

LengthFunction · 0.85
CrossFunction · 0.85
Vector3Class · 0.70

Tested by

no test coverage detected