|
|
@ -767,6 +767,64 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h |
|
|
|
rlPopMatrix(); |
|
|
|
} |
|
|
|
|
|
|
|
// Draw a cylinder with base at startPos and top at endPos |
|
|
|
// NOTE: It could be also used for pyramid and cone |
|
|
|
void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color) |
|
|
|
{ |
|
|
|
if (sides < 3) sides = 3; |
|
|
|
|
|
|
|
int numVertex = sides*6; |
|
|
|
rlCheckRenderBatchLimit(numVertex); |
|
|
|
if(sides < 3) sides = 3; |
|
|
|
|
|
|
|
Vector3 difference = Vector3Subtract(endPos, startPos); |
|
|
|
// Construct a basis of the base and the top face: |
|
|
|
Vector3 b1 = Vector3Normalize(Vector3Perpendicular(difference)); |
|
|
|
Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, difference)); |
|
|
|
|
|
|
|
float base_angle = (2.0 * PI) / sides; |
|
|
|
|
|
|
|
rlBegin(RL_TRIANGLES); |
|
|
|
rlColor4ub(color.r, color.g, color.b, color.a); |
|
|
|
|
|
|
|
for (int i = 0; i < sides; i++) { |
|
|
|
// compute the four vertices |
|
|
|
float s1 = sinf(base_angle * (i+0)) * startRadius; |
|
|
|
float c1 = cosf(base_angle * (i+0)) * startRadius; |
|
|
|
Vector3 w1 = Vector3Add(startPos, Vector3Add(Vector3Scale(b1, s1), Vector3Scale(b2, c1))); |
|
|
|
float s2 = sinf(base_angle * (i+1)) * startRadius; |
|
|
|
float c2 = cosf(base_angle * (i+1)) * startRadius; |
|
|
|
Vector3 w2 = Vector3Add(startPos, Vector3Add(Vector3Scale(b1, s2), Vector3Scale(b2, c2))); |
|
|
|
float s3 = sinf(base_angle * (i+0)) * endRadius; |
|
|
|
float c3 = cosf(base_angle * (i+0)) * endRadius; |
|
|
|
Vector3 w3 = Vector3Add(endPos, Vector3Add(Vector3Scale(b1, s3), Vector3Scale(b2, c3))); |
|
|
|
float s4 = sinf(base_angle * (i+1)) * endRadius; |
|
|
|
float c4 = cosf(base_angle * (i+1)) * endRadius; |
|
|
|
Vector3 w4 = Vector3Add(endPos, Vector3Add(Vector3Scale(b1, s4), Vector3Scale(b2, c4))); |
|
|
|
|
|
|
|
if (startRadius > 0) { // |
|
|
|
rlVertex3f(startPos.x, startPos.y, startPos.z); // | |
|
|
|
rlVertex3f(w2.x, w2.y, w2.z); // T0 |
|
|
|
rlVertex3f(w1.x, w1.y, w1.z); // | |
|
|
|
} // |
|
|
|
// w2 x.-----------x startPos |
|
|
|
rlVertex3f(w1.x, w1.y, w1.z); // | |\'. T0 / |
|
|
|
rlVertex3f(w2.x, w2.y, w2.z); // T1 | \ '. / |
|
|
|
rlVertex3f(w3.x, w3.y, w3.z); // | |T \ '. / |
|
|
|
// | 2 \ T 'x w1 |
|
|
|
rlVertex3f(w2.x, w2.y, w2.z); // | w4 x.---\-1-|---x endPos |
|
|
|
rlVertex3f(w4.x, w4.y, w4.z); // T2 '. \ |T3/ |
|
|
|
rlVertex3f(w3.x, w3.y, w3.z); // | '. \ | / |
|
|
|
// '.\|/ |
|
|
|
if (endRadius > 0) { // 'x w3 |
|
|
|
rlVertex3f(endPos.x, endPos.y, endPos.z); // | |
|
|
|
rlVertex3f(w3.x, w3.y, w3.z); // T3 |
|
|
|
rlVertex3f(w4.x, w4.y, w4.z); // | |
|
|
|
} // |
|
|
|
} |
|
|
|
rlEnd(); |
|
|
|
} |
|
|
|
|
|
|
|
// Draw a wired cylinder |
|
|
|
// NOTE: It could be also used for pyramid and cone |
|
|
|
void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color) |
|
|
@ -800,6 +858,54 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl |
|
|
|
rlPopMatrix(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Draw a wired cylinder with base at startPos and top at endPos |
|
|
|
// NOTE: It could be also used for pyramid and cone |
|
|
|
void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color) |
|
|
|
{ |
|
|
|
if (sides < 3) sides = 3; |
|
|
|
|
|
|
|
int numVertex = sides*6; |
|
|
|
rlCheckRenderBatchLimit(numVertex); |
|
|
|
|
|
|
|
Vector3 difference = Vector3Subtract(endPos, startPos); |
|
|
|
// Construct a basis of the base and the top face: |
|
|
|
Vector3 b1 = Vector3Normalize(Vector3Perpendicular(difference)); |
|
|
|
Vector3 b2 = Vector3Normalize(Vector3CrossProduct(b1, difference)); |
|
|
|
|
|
|
|
float base_angle = (2.0 * PI) / sides; |
|
|
|
|
|
|
|
rlBegin(RL_LINES); |
|
|
|
rlColor4ub(color.r, color.g, color.b, color.a); |
|
|
|
|
|
|
|
for (int i = 0; i < sides; i++) { |
|
|
|
// compute the four vertices |
|
|
|
float s1 = sinf(base_angle * (i+0)) * startRadius; |
|
|
|
float c1 = cosf(base_angle * (i+0)) * startRadius; |
|
|
|
Vector3 w1 = Vector3Add(startPos, Vector3Add(Vector3Scale(b1, s1), Vector3Scale(b2, c1))); |
|
|
|
float s2 = sinf(base_angle * (i+1)) * startRadius; |
|
|
|
float c2 = cosf(base_angle * (i+1)) * startRadius; |
|
|
|
Vector3 w2 = Vector3Add(startPos, Vector3Add(Vector3Scale(b1, s2), Vector3Scale(b2, c2))); |
|
|
|
float s3 = sinf(base_angle * (i+0)) * endRadius; |
|
|
|
float c3 = cosf(base_angle * (i+0)) * endRadius; |
|
|
|
Vector3 w3 = Vector3Add(endPos, Vector3Add(Vector3Scale(b1, s3), Vector3Scale(b2, c3))); |
|
|
|
float s4 = sinf(base_angle * (i+1)) * endRadius; |
|
|
|
float c4 = cosf(base_angle * (i+1)) * endRadius; |
|
|
|
Vector3 w4 = Vector3Add(endPos, Vector3Add(Vector3Scale(b1, s4), Vector3Scale(b2, c4))); |
|
|
|
|
|
|
|
rlVertex3f(w1.x, w1.y, w1.z); |
|
|
|
rlVertex3f(w2.x, w2.y, w2.z); |
|
|
|
|
|
|
|
rlVertex3f(w1.x, w1.y, w1.z); |
|
|
|
rlVertex3f(w3.x, w3.y, w3.z); |
|
|
|
|
|
|
|
rlVertex3f(w3.x, w3.y, w3.z); |
|
|
|
rlVertex3f(w4.x, w4.y, w4.z); |
|
|
|
} |
|
|
|
rlEnd(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Draw a plane |
|
|
|
void DrawPlane(Vector3 centerPos, Vector2 size, Color color) |
|
|
|
{ |
|
|
|