From f9f747b79b15323e2bc4117c9b3a7b20bba0f969 Mon Sep 17 00:00:00 2001 From: Arthur Pellegrini Date: Sat, 21 Jan 2023 02:43:28 +0100 Subject: [PATCH] Refactor: Cleanup TD1 --- .../examples/core/Coordinates.hpp | 11 +- .../examples/core/CoreBasicWindow.cpp | 28 +- .../examples/core/My3DPrimitives.cpp | 998 +++++++----------- .../examples/core/My3DPrimitives.hpp | 152 ++- .../examples/core/coordinates.cpp | 29 +- .../examples/core/reference_frame.h | 46 - 6 files changed, 494 insertions(+), 770 deletions(-) delete mode 100644 Raylib_BaseProject/examples/core/reference_frame.h diff --git a/Raylib_BaseProject/examples/core/Coordinates.hpp b/Raylib_BaseProject/examples/core/Coordinates.hpp index d31e010..a787a7d 100644 --- a/Raylib_BaseProject/examples/core/Coordinates.hpp +++ b/Raylib_BaseProject/examples/core/Coordinates.hpp @@ -11,6 +11,7 @@ #ifndef COORDINATES_STRUCTS #define COORDINATES_STRUCTS +// Stocke les informations relatives à un référentiel dans l'espace 3D struct ReferenceFrame { Vector3 origin; Vector3 i, j, k; @@ -44,34 +45,36 @@ struct ReferenceFrame { } }; +// Représente un point dans un système de coordonnées polaires(2D) struct Polar { float rho; float theta; }; +// Représente un point dans un système de coordonnées cylindriques(3D) struct Cylindrical { float rho; float theta; float y; }; +// Représente un point dans un système de coordonnées sphériques(3D) struct Spherical { float rho; float theta; - float phi; }; #endif -// Fonction de conversion de coordonnées cartésiennes en coordonnées polaires (et inversement) +// Fonctions de conversion de coordonnées cartésiennes en coordonnées polaires (et inversement) Polar CartesianToPolar(Vector2 cart, bool keepThetaPositive); Vector2 PolarToCartesian(Polar polar); -// Fonction de conversion de coordonnées cartésiennes en coordonnées cylindriques (et inversement) +// Fonctions de conversion de coordonnées cartésiennes en coordonnées cylindriques (et inversement) Cylindrical CartesianToCylindrical(Vector3 cart); Vector3 CylindricalToCartesien(Cylindrical cyl); -// Fonction de conversion de coordonnées cartésiennes en coordonnées sphériques (et inversement) +// Fonctions de conversion de coordonnées cartésiennes en coordonnées sphériques (et inversement) Spherical CartesianToSpherical(Vector3 cart); Vector3 SphericalToCartesian(Spherical sph); diff --git a/Raylib_BaseProject/examples/core/CoreBasicWindow.cpp b/Raylib_BaseProject/examples/core/CoreBasicWindow.cpp index 69fc96d..4ee55e0 100644 --- a/Raylib_BaseProject/examples/core/CoreBasicWindow.cpp +++ b/Raylib_BaseProject/examples/core/CoreBasicWindow.cpp @@ -19,8 +19,8 @@ * ********************************************************************************************/ #include "raylib.h" -#include #include "rlgl.h" +#include #include #include #include @@ -55,7 +55,7 @@ void MyUpdateOrbitalCamera(Camera* camera, float deltaTime) Vector2 mousePos; static Vector2 prevMousePos = { 0, 0 }; Vector2 mouseVect; - //Spherical sphDelta; + Spherical sphDelta; mousePos = GetMousePosition(); // on récupère la position de la souris mouseVect = Vector2Subtract(mousePos, prevMousePos); // on récupère le vecteur de déplacement de la souris @@ -63,25 +63,22 @@ void MyUpdateOrbitalCamera(Camera* camera, float deltaTime) float mouseWheelRotation = -GetMouseWheelMove(); // le mouvement de la molette de la souris - sphPos.rho += mouseWheelRotation * sphSpeed.rho; - if (sphPos.rho < rhoMin) sphPos.rho = rhoMin; - if (sphPos.rho > rhoMax) sphPos.rho = rhoMax; - + sphDelta.rho = mouseWheelRotation * sphSpeed.rho; + sphDelta.theta = mouseVect.x * DEG2RAD * sphSpeed.theta; + sphDelta.phi = Clamp(mouseVect.y, -179.0f, 179.0f) * DEG2RAD * sphSpeed.phi; + if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) { - sphPos.theta += mouseVect.x * DEG2RAD * sphSpeed.theta; - sphPos.phi += Clamp(mouseVect.y, -179.0f, 179.0f) * DEG2RAD * sphSpeed.phi; + sphPos.theta += sphDelta.theta; + sphPos.phi += sphDelta.phi; if (sphPos.phi < phiMin) sphPos.phi = phiMin; if (sphPos.phi > phiMax) sphPos.phi = phiMax; } + sphPos.rho = Clamp(sphPos.rho + sphDelta.rho, rhoMin, rhoMax); + // Mise à jour de la caméra camera->position = SphericalToCartesian(sphPos); - - // Monitoring - //printf("Position de la souris -> x:%f & y:%f \n", mousePos.x, mousePos.y); - //printf("Delta déplacement souris -> x:%f & y:%f \n", mouseVect.x, mouseVect.y); - //printf("rho -> %f;theta -> %f; phi -> %f \n", sphPos.rho, sphPos.theta, sphPos.phi); } @@ -176,7 +173,7 @@ int main(int argc, char* argv[]) // SPHERE ReferenceFrame ref_sphere = ReferenceFrame({ -7,5,0 }, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), -time)); Sphere sphere = { ref_sphere, 3.0f }; - MyDrawSphere(sphere, 20, 20, true, true, RED); + MyDrawSphere(sphere, 90, 90, true, true, RED); // FIN SPHERE // CYLINDER @@ -211,8 +208,9 @@ int main(int argc, char* argv[]) DrawSphere({ 0,0,15 }, .2f, BLUE); } EndMode3D(); - + DrawFPS(1800 * screenSizeCoef, 20 * screenSizeCoef); EndDrawing(); + //---------------------------------------------------------------------------------- } diff --git a/Raylib_BaseProject/examples/core/My3DPrimitives.cpp b/Raylib_BaseProject/examples/core/My3DPrimitives.cpp index 577dc44..75048e6 100644 --- a/Raylib_BaseProject/examples/core/My3DPrimitives.cpp +++ b/Raylib_BaseProject/examples/core/My3DPrimitives.cpp @@ -2,51 +2,33 @@ #include #include "My3DPrimitives.hpp" -/****************************************************************** -* LINE * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner un segment à partir des coordonnées définnisant son point de départ et sa direction -/// -/// Contient les deux vecteurs permettant de positionner le point de la ligne et son vecteur de direction -/// Contient la couleur de la ligne +/************************************************ +* Line * +*************************************************/ void MyDrawLine(Line line, Color color) { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex3f(line.pt.x, line.pt.y, line.pt.z); - rlVertex3f(line.pt.x + line.dir.x, line.pt.y + line.dir.y, line.pt.z + line.dir.z); + rlVertex3f(line.pt.x, line.pt.y, line.pt.z); // Position du premier point de la ligne + rlVertex3f(line.pt.x + line.dir.x, line.pt.y + line.dir.y, line.pt.z + line.dir.z); // Position du second point de la ligne (calculé en partant du premier point et en ajoutant la direction de la ligne) rlEnd(); } -/****************************************************************** -* SEGMENT * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner un segment à partir de deux points donnés en paramètre -/// -/// Contient les deux vecteurs permettant de positionner les points du segment -/// Contient la couleur du segment +/************************************************ +* Segment * +*************************************************/ void MyDrawSegment(Segment segment, Color color) { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex3f(segment.pt1.x, segment.pt1.y, segment.pt1.z); - rlVertex3f(segment.pt2.x, segment.pt2.y, segment.pt2.z); + rlVertex3f(segment.pt1.x, segment.pt1.y, segment.pt1.z); // Position du premier point du segment + rlVertex3f(segment.pt2.x, segment.pt2.y, segment.pt2.z); // Position du second point du segment rlEnd(); } -/****************************************************************** -* TRIANGLE * -*******************************************************************/ - -// -/// Méthode permettant de dessiner un triangle d'une certaine couleur à partir de trois points donnés en paramètre -/// -/// Contient les trois vecteurs permettant de positionner les points du triangle -/// Contient la couleur du triangle +/************************************************ +* Triangle * +*************************************************/ void MyDrawPolygonTriangle(Triangle triangle, Color color) { int numVertex = 3; @@ -54,17 +36,12 @@ void MyDrawPolygonTriangle(Triangle triangle, Color color) rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex3f(triangle.pt1.x, triangle.pt1.y, triangle.pt1.z); - rlVertex3f(triangle.pt2.x, triangle.pt2.y, triangle.pt2.z); - rlVertex3f(triangle.pt3.x, triangle.pt3.y, triangle.pt3.z); + rlVertex3f(triangle.pt1.x, triangle.pt1.y, triangle.pt1.z); // Position du premier point du triangle + rlVertex3f(triangle.pt2.x, triangle.pt2.y, triangle.pt2.z); // Position du deuxième point du triangle + rlVertex3f(triangle.pt3.x, triangle.pt3.y, triangle.pt3.z); // Position du troisième point du triangle rlEnd(); } -// -/// Méthode permettant de dessiner un triangle en mode fil de fer à partir de trois points donnés en paramètre -/// -/// Contient les trois vecteurs permettant de positionner les points du triangle -/// Contient la couleur du maillage void MyDrawWireframeTriangle(Triangle triangle, Color color) { int numVertex = 3; @@ -72,36 +49,21 @@ void MyDrawWireframeTriangle(Triangle triangle, Color color) rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex3f(triangle.pt1.x, triangle.pt1.y, triangle.pt1.z); - rlVertex3f(triangle.pt2.x, triangle.pt2.y, triangle.pt2.z); - rlVertex3f(triangle.pt3.x, triangle.pt3.y, triangle.pt3.z); + rlVertex3f(triangle.pt1.x, triangle.pt1.y, triangle.pt1.z); // Position du premier point du triangle + rlVertex3f(triangle.pt2.x, triangle.pt2.y, triangle.pt2.z); // Position du deuxième point du triangle + rlVertex3f(triangle.pt3.x, triangle.pt3.y, triangle.pt3.z); // Position du troisième point du triangle rlEnd(); } -/// -/// Méthode permettant de dessiner un triangle en mode polygone et/ou fil de fer -/// -/// Contient les trois vecteurs permettant de positionner les points du triangle -/// Indique si le triangle doit être dessiné en mode polygone -/// Indique si le triangle doit être dessiné en mode fil de fer -/// Contient la couleur à utiliser pour dessiner le triangle en mode polygone -/// Contient la couleur à utiliser pour dessiner le triangle en mode fil de fer void MyDrawTriangle(Triangle triangle, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonTriangle(triangle, polygonColor); if (drawWireframe) MyDrawWireframeTriangle(triangle, wireframeColor); } - -/****************************************************************** -* QUAD * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner un quad en mode polygone à partir de quatre points donnés en paramètre -/// -/// Contient les informations pour positionner et orienter le quad -/// Contient la couleur de la surface +/************************************************ +* Quad * +*************************************************/ void MyDrawPolygonQuad(Quad quad, Color color) { int numVertex = 6; @@ -125,11 +87,6 @@ void MyDrawPolygonQuad(Quad quad, Color color) rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un quad en mode fil de fer à partir de quatre points donnés en paramètre -/// -/// Contient les informations pour positionner et orienter le quad -/// Contient la couleur du fil de fer void MyDrawWireframeQuad(Quad quad, Color color) { int numVertex = 10; @@ -157,33 +114,15 @@ void MyDrawWireframeQuad(Quad quad, Color color) rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un quad en mode polygone et/ou fil de fer -/// -/// Contient les informations pour positionner et orienter le quad -/// Indique si le quad doit être dessiné en mode polygone -/// Indique si le quad doit être dessiné en mode fil de fer -/// Contient la couleur à utiliser pour dessiner le quad en mode polygone -/// Contient la couleur à utiliser pour dessiner le quad en mode fil de fer void MyDrawQuad(Quad quad, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonQuad(quad, polygonColor); if (drawWireframe) MyDrawWireframeQuad(quad, wireframeColor); } - -/****************************************************************** -* PLANE * -*******************************************************************/ - -// -/// Méthode permettant de dessiner un plane en mode polygone et/ou fil de fer (imagination requise pour étendre à l'infini) -/// -/// Contient les informations pour positionner et orienter le plane -/// Indique si le plane doit être dessiné en mode polygone -/// Indique si le plane doit être dessiné en mode fil de fer -/// Contient la couleur à utiliser pour dessiner le plane en mode polygone -/// Contient la couleur à utiliser pour dessiner le plane en mode fil de fer +/************************************************ +* Plane * +*************************************************/ void MyDrawPlane(Plane plane, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { ReferenceFrame ref; @@ -198,127 +137,16 @@ void MyDrawPlane(Plane plane, bool drawPolygon, bool drawWireframe, Color polygo rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(1, 0, 1); - Quad quad = { ref, { 40,0,40 } }; + Quad quad = { ref, { 40,0,40 } }; //Impression d'infini avec des extensions de 40m if (drawPolygon) MyDrawPolygonQuad(quad, polygonColor); if (drawWireframe) MyDrawWireframeQuad(quad, wireframeColor); rlPopMatrix(); } - -/****************************************************************** -* BOX * -*******************************************************************/ - -// -/// Méthode permettant de dessiner une box en mode polygone -/// -/// Contient les informations pour positionner et orienter la box -/// Contient la couleur à utiliser pour dessiner la box -void MyDrawPolygonBox(Box box, Color color) -{ - int numVertex = 36; - if (rlCheckBufferLimit(numVertex)) rlglDraw(); - rlPushMatrix(); - rlTranslatef(box.ref.origin.x, box.ref.origin.y, box.ref.origin.z); - Vector3 vect; - float angle; - QuaternionToAxisAngle(box.ref.q, &vect, &angle); - rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); - rlScalef(box.extents.x, box.extents.y, box.extents.z); - - Quaternion q = QuaternionIdentity(); - Quad top = { ReferenceFrame({ 0,1,0 }, q), {1,0,1} }; - q = QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI); - Quad bottom = { ReferenceFrame({ 0,-1,0 }, q), {1,0,1} }; - - q = QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), -PI / 2); - Quad front = { ReferenceFrame({ 1,0,0 }, q), {1,0,1} }; - q = QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2); - Quad back = { ReferenceFrame({ -1,0,0 }, q), {1,0,1} }; - - q = QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2); - Quad left = { ReferenceFrame({ 0,0,1 }, q), {1,0,1} }; - q = QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), -PI / 2); - Quad right = { ReferenceFrame({ 0,0,-1 }, q), {1,0,1} }; - - MyDrawPolygonQuad(top, color); - MyDrawPolygonQuad(bottom, color); - MyDrawPolygonQuad(front, color); - MyDrawPolygonQuad(back, color); - MyDrawPolygonQuad(left, color); - MyDrawPolygonQuad(right, color); - - rlPopMatrix(); -} - -// -/// Méthode permettant de dessiner une box en mode fil de fer -/// -/// Contient les informations pour positionner et orienter la box -/// Contient la couleur à utiliser pour dessiner le fil de fer -void MyDrawWireframeBox(Box box, Color color) -{ - int numVertex = 60; - if (rlCheckBufferLimit(numVertex)) rlglDraw(); - rlPushMatrix(); - rlTranslatef(box.ref.origin.x, box.ref.origin.y, box.ref.origin.z); - Vector3 vect; - float angle; - QuaternionToAxisAngle(box.ref.q, &vect, &angle); - rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); - rlScalef(box.extents.x, box.extents.y, box.extents.z); - - Quaternion q = QuaternionIdentity(); - Quad top = { ReferenceFrame({ 0,1,0 }, q), {1,0,1} }; - q = QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI); - Quad bottom = { ReferenceFrame({ 0,-1,0 }, q), {1,0,1} }; - - q = QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), -PI / 2); - Quad front = { ReferenceFrame({ 1,0,0 }, q), {1,0,1} }; - q = QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2); - Quad back = { ReferenceFrame({ -1,0,0 }, q), {1,0,1} }; - - q = QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2); - Quad left = { ReferenceFrame({ 0,0,1 }, q), {1,0,1} }; - q = QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), -PI / 2); - Quad right = { ReferenceFrame({ 0,0,-1 }, q), {1,0,1} }; - - MyDrawWireframeQuad(top, color); - MyDrawWireframeQuad(bottom, color); - MyDrawWireframeQuad(front, color); - MyDrawWireframeQuad(back, color); - MyDrawWireframeQuad(left, color); - MyDrawWireframeQuad(right, color); - - rlPopMatrix(); -} - -/// -/// Méthode permettant de dessiner une box en mode polygone et/ou fil de fer -/// -/// Contient les informations pour positionner et orienter la box -/// Indique si la box doit être dessinée en mode polygone -/// Indique si la box doit être dessinée en mode fil de fer -/// Contient la couleur à utiliser pour dessiner la box en mode polygone -/// Contient la couleur à utiliser pour dessiner la box en mode fil de fer -void MyDrawBox(Box box, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) -{ - if (drawPolygon) MyDrawPolygonBox(box, polygonColor); - if (drawWireframe) MyDrawWireframeBox(box, wireframeColor); -} - - -/****************************************************************** -* DISK * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner un disk d'une certaine couleur en utilisant des triangles -/// -/// Contient les informations sur le disk (position, rayon, orientation) -/// Nombre de secteurs utilisés pour dessiner le disk -/// Contient la couleur du disk +/************************************************ +* Disk * +*************************************************/ void MyDrawPolygonDisk(Disk disk, int nSectors, Color color) { int numVertex = nSectors * 3; @@ -328,28 +156,27 @@ void MyDrawPolygonDisk(Disk disk, int nSectors, Color color) float angle; QuaternionToAxisAngle(disk.ref.q, &vect, &angle); rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); - rlScalef(disk.radius, 1, disk.radius); + rlScalef(disk.radius, 0, disk.radius); - Cylindrical v1, v2; + Cylindrical c1, c2; + Vector3 v1, v2; + // On parcourt le nombre de secteurs du disque for (int i = 0; i < nSectors; i++) { - // On calcule les coordonnées cylindriques des sommets du triangle - v1 = { 1, 2 * PI / nSectors * i, 0 }; - v2 = { 1, 2 * PI / nSectors * (i + 1), 0 }; + // On calcule les coordonnées cylindriques des points des segments + c1 = { 1, 2 * PI / nSectors * i, 0 }; + c2 = { 1, 2 * PI / nSectors * (i + 1), 0 }; + + v1 = CylindricalToCartesien(c1); + v2 = CylindricalToCartesien(c2); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawTriangle3D(CylindricalToCartesien(v2), { 0 }, CylindricalToCartesien(v1), color); + DrawTriangle3D(v2, { 0 }, v1, color); } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un disk en mode fil de fer -/// -/// Contient les informations sur le disk (position, rayon, orientation) -/// Nombre de secteurs utilisés pour dessiner le disk -/// Contient la couleur du fil de fer void MyDrawWireframeDisk(Disk disk, int nSectors, Color color) { int numVertex = nSectors * 3; @@ -359,50 +186,152 @@ void MyDrawWireframeDisk(Disk disk, int nSectors, Color color) float angle; QuaternionToAxisAngle(disk.ref.q, &vect, &angle); rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); - rlScalef(disk.radius, 1, disk.radius); + rlScalef(disk.radius, 0, disk.radius); - Cylindrical v1, v2; + Cylindrical c1, c2; + Vector3 v1, v2; + // On parcourt le nombre de secteurs du disque for (int i = 0; i < nSectors; i++) { // On calcule les coordonnées cylindriques des points des segments - v1 = { 1, 2 * PI / nSectors * i, 0 }; - v2 = { 1, 2 * PI / nSectors * (i + 1), 0 }; + c1 = { 1, 2 * PI / nSectors * i, 0 }; + c2 = { 1, 2 * PI / nSectors * (i + 1), 0 }; + + v1 = CylindricalToCartesien(c1); + v2 = CylindricalToCartesien(c2); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v2), color); - DrawLine3D({ 0 }, CylindricalToCartesien(v2), color); + DrawLine3D(v1, v2, color); + DrawLine3D({ 0 }, v2, color); } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un disk en mode polygone et/ou fil de fer -/// -/// Contient les informations relatives au disk (origine, rayon, orientation) -/// Nombre de secteurs utilisés pour dessiner le disk -/// Définit si on dessine le disk en mode polygone -/// Définit si on dessine le disk en mode fil de fer -/// Couleur utilisée pour dessiner le disk en mode polygone -/// Couleur utilisée pour dessiner le disk en mode fil de fer void MyDrawDisk(Disk disk, int nSectors, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonDisk(disk, nSectors, polygonColor); if (drawWireframe) MyDrawWireframeDisk(disk, nSectors, wireframeColor); } +/************************************************ +* Box * +*************************************************/ +//{ X -> far; Y -> vertical; Z -> horizontal } +void MyDrawPolygonBox(Box box, Color color) +{ + int numVertex = 36; + if (rlCheckBufferLimit(numVertex)) rlglDraw(); + rlPushMatrix(); + rlTranslatef(box.ref.origin.x, box.ref.origin.y, box.ref.origin.z); + Vector3 vect; + float angle; + QuaternionToAxisAngle(box.ref.q, &vect, &angle); + rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); + rlScalef(box.extents.x, box.extents.y, box.extents.z); + + // On détermine l'emplacement des points de la Box + Vector3 front_top_left = { -1, 1, 1 }; + Vector3 front_top_right = { 1, 1, 1 }; + Vector3 front_bottom_left = { -1, -1, 1 }; + Vector3 front_bottom_right = { 1, -1, 1 }; + Vector3 back_top_left = { -1, 1, -1 }; + Vector3 back_top_right = { 1, 1, -1 }; + Vector3 back_bottom_left = { -1, -1, -1 }; + Vector3 back_bottom_right = { 1, -1, -1 }; + + // On dessine la face de devant + DrawTriangle3D(front_bottom_right, front_top_left, front_bottom_left, color); + DrawTriangle3D(front_bottom_right, front_top_right, front_top_left, color); + // On dessine la face de derrière + DrawTriangle3D(back_bottom_left, back_top_left, back_top_right, color); + DrawTriangle3D(back_top_right, back_bottom_right, back_bottom_left, color); + // On dessine la face supérieure + DrawTriangle3D(back_top_left, front_top_left, front_top_right, color); + DrawTriangle3D(front_top_right, back_top_right, back_top_left, color); + // On dessine la face inférieure + DrawTriangle3D(back_bottom_right, front_bottom_left, back_bottom_left, color); + DrawTriangle3D(back_bottom_right, front_bottom_right, front_bottom_left, color); + // On dessine la face gauche + DrawTriangle3D(front_bottom_left, back_top_left, back_bottom_left, color); + DrawTriangle3D(front_bottom_left, front_top_left, back_top_left, color); + // On dessine la face droite + DrawTriangle3D(front_top_right, front_bottom_right, back_bottom_right, color); + DrawTriangle3D(front_top_right, back_bottom_right, back_top_right, color); + rlPopMatrix(); +} + +void MyDrawWireframeBox(Box box, Color color) +{ + int numVertex = 36; + if (rlCheckBufferLimit(numVertex)) rlglDraw(); + rlPushMatrix(); + rlTranslatef(box.ref.origin.x, box.ref.origin.y, box.ref.origin.z); + Vector3 vect; + float angle; + QuaternionToAxisAngle(box.ref.q, &vect, &angle); + rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); + rlScalef(box.extents.x, box.extents.y, box.extents.z); -/****************************************************************** -* SPHERE * -*******************************************************************/ + // On détermine l'emplacement des points de la Box + Vector3 front_top_left = { -1, 1, 1 }; + Vector3 front_top_right = { 1, 1, 1 }; + Vector3 front_bottom_left = { -1, -1, 1 }; + Vector3 front_bottom_right = { 1, -1, 1 }; + Vector3 back_top_left = { -1, 1, -1 }; + Vector3 back_top_right = { 1, 1, -1 }; + Vector3 back_bottom_left = { -1, -1, -1 }; + Vector3 back_bottom_right = { 1, -1, -1 }; + + // On dessine la face de devant + DrawLine3D(front_top_left, front_top_right, color); + DrawLine3D(front_bottom_left, front_bottom_right, color); + DrawLine3D(front_top_left, front_bottom_left, color); + DrawLine3D(front_top_right, front_bottom_right, color); + DrawLine3D(front_bottom_right, front_top_left, color); + // On dessine la face de derrière + DrawLine3D(back_top_left, back_top_right, color); + DrawLine3D(back_bottom_left, back_bottom_right, color); + DrawLine3D(back_top_left, back_bottom_left, color); + DrawLine3D(back_top_right, back_bottom_right, color); + DrawLine3D(back_bottom_left, back_top_right, color); + // On dessine la face supérieure + DrawLine3D(front_top_left, back_top_left, color); + DrawLine3D(front_top_right, back_top_right, color); + DrawLine3D(front_top_right, back_top_left, color); + // On dessine la face inférieure + DrawLine3D(front_bottom_left, back_bottom_left, color); + DrawLine3D(front_bottom_right, back_bottom_right, color); + DrawLine3D(front_bottom_left, back_bottom_right, color); + // On dessine la face gauche + DrawLine3D(front_bottom_left, back_top_left, color); + // On dessine la face droite + DrawLine3D(back_bottom_right, front_top_right, color); + rlPopMatrix(); +} + +void MyDrawBox(Box box, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) +{ + if (drawPolygon) MyDrawPolygonBox(box, polygonColor); + if (drawWireframe) MyDrawWireframeBox(box, wireframeColor); +} -/// -/// Méthode permettant de dessiner une sphère à partir des paramètres donnés -/// -/// Contient les informations sur la sphère (position, rotation, rayon) -/// Nombre de méridiens utilisés pour dessiner la sphère -/// Nombre de parallèles utilisés pour dessiner la sphère -/// Couleur de la sphère +/************************************************ +* Sphere * +*************************************************/ +// Positions des points à chaque itération +// 1-----2 +// | \ | +// | \ | +// | \ | +// 3-----4 +// +// MERIDIAN -> phi € [0°, 180°] +// | +// | +// -----|----- PARALLEL -> theta € [0°, 360°] +// | +// | void MyDrawPolygonSphere(Sphere sphere, int nMeridians, int nParallels, Color color) { int numVertex = nMeridians * nParallels * 4; @@ -414,45 +343,32 @@ void MyDrawPolygonSphere(Sphere sphere, int nMeridians, int nParallels, Color co rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(sphere.radius, sphere.radius, sphere.radius); - // Points position for one quad in the sphere - // 1-----2 - // | \ | - // | \ | - // | \ | - // 3-----4 - Spherical pt1, pt2, pt3, pt4; // = {rho, theta, phi} - - // MERIDIAN -> phi € [0°, 180°] - // | - // | - // -----|----- PARALLEL -> theta € [0°, 360°] - // | - // | + Spherical s1, s2, s3, s4; + Vector3 v1, v2, v3, v4; for (int m = 0; m < nMeridians; m++) { for (int p = 0; p < nParallels; p++) { - pt1 = { 1, 2 * PI / nMeridians * m, PI / nParallels * p}; - pt2 = { 1, 2 * PI / nMeridians * (m+1), PI / nParallels * p }; - pt3 = { 1, 2 * PI / nMeridians * m, PI / nParallels * (p+1) }; - pt4 = { 1, 2 * PI / nMeridians * (m+1), PI / nParallels * (p+1) }; + // On calcule les coordonnées sphériques des points de la face + s1 = { 1, 2 * PI / nMeridians * m, PI / nParallels * p }; + s2 = { 1, 2 * PI / nMeridians * (m + 1), PI / nParallels * p }; + s3 = { 1, 2 * PI / nMeridians * m, PI / nParallels * (p + 1) }; + s4 = { 1, 2 * PI / nMeridians * (m + 1), PI / nParallels * (p + 1) }; + + v1 = SphericalToCartesian(s1); + v2 = SphericalToCartesian(s2); + v3 = SphericalToCartesian(s3); + v4 = SphericalToCartesian(s4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawTriangle3D(SphericalToCartesian(pt1), SphericalToCartesian(pt4), SphericalToCartesian(pt2), color); - DrawTriangle3D(SphericalToCartesian(pt1), SphericalToCartesian(pt3), SphericalToCartesian(pt4), color); + DrawTriangle3D(v1, v4, v2, color); + DrawTriangle3D(v1, v3, v4, color); } } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner une sphère en fil de fer à partir des paramètres donnés -/// -/// Contient les informations sur la sphère (position, rotation, rayon) -/// Nombre de méridiens utilisés pour dessiner la sphère -/// Nombre de parallèles utilisés pour dessiner la sphère -/// Couleur du fil de fer void MyDrawWireframeSphere(Sphere sphere, int nMeridians, int nParallels, Color color) { int numVertex = nMeridians * nParallels * 4; @@ -464,72 +380,41 @@ void MyDrawWireframeSphere(Sphere sphere, int nMeridians, int nParallels, Color rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(sphere.radius, sphere.radius, sphere.radius); - // Points position for one quad in the sphere - // 1-----2 - // | \ | - // | \ | - // | \ | - // 3-----4 - Spherical pt1, pt2, pt3, pt4; // = {rho, theta, phi} - - // MERIDIAN -> phi € [0°, 180°] - // | - // | - // -----|----- PARALLEL -> theta € [0°, 360°] - // | - // | + Spherical s1, s2, s3, s4; + Vector3 v1, v2, v3, v4; for (int m = 0; m < nMeridians; m++) { for (int p = 0; p < nParallels; p++) { - pt1 = { 1, 2 * PI / nMeridians * m, PI / nParallels * p }; - pt2 = { 1, 2 * PI / nMeridians * (m + 1), PI / nParallels * p }; - pt3 = { 1, 2 * PI / nMeridians * m, PI / nParallels * (p + 1) }; - pt4 = { 1, 2 * PI / nMeridians * (m + 1), PI / nParallels * (p + 1) }; + // On calcule les coordonnées sphériques des points de la face + s1 = { 1, 2 * PI / nMeridians * m, PI / nParallels * p }; + s2 = { 1, 2 * PI / nMeridians * (m + 1), PI / nParallels * p }; + s3 = { 1, 2 * PI / nMeridians * m, PI / nParallels * (p + 1) }; + s4 = { 1, 2 * PI / nMeridians * (m + 1), PI / nParallels * (p + 1) }; + + v1 = SphericalToCartesian(s1); + v2 = SphericalToCartesian(s2); + v3 = SphericalToCartesian(s3); + v4 = SphericalToCartesian(s4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawLine3D(SphericalToCartesian(pt1), SphericalToCartesian(pt4), color); - DrawLine3D(SphericalToCartesian(pt1), SphericalToCartesian(pt2), color); - DrawLine3D(SphericalToCartesian(pt1), SphericalToCartesian(pt3), color); + DrawLine3D(v1, v4, color); + DrawLine3D(v1, v2, color); + DrawLine3D(v1, v3, color); + // Inutile de dessiner [V3,V4] et [V2,V4] car ils correspondront respectivement lors du prochain tour de boucle à [V1,V2] et [V1,V3] } } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner une sphère en mode polygone et/ou fil de fer -/// -/// Contient les informations sur la sphère tels que sa référence => orientation et position et son rayon -/// Le nombre de méridiens de la sphère -/// Le nombre de parallèles de la sphère -/// Indique si on dessine la sphère en mode polygones -/// Indique si on dessine la sphère en mode fil de fer -/// La couleur des polygones -/// La couleur du fil de fer void MyDrawSphere(Sphere sphere, int nMeridians, int nParallels, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonSphere(sphere, nMeridians, nParallels, polygonColor); if (drawWireframe) MyDrawWireframeSphere(sphere, nMeridians, nParallels, wireframeColor); } - -/****************************************************************** -* Sphere Optimization Methods * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner la portion de sphère à partir d'un certain nombre de méridiens et de parallèles, -/// ainsi que de la plage de début et de fin pour theta et phi -/// -/// Contient les informations de la sphère (centre, rayon, orientation) -/// Nombre de meridiens utilisés pour dessiner la portion de sphère -/// Nombre de parallèles utilisés pour dessiner la portion de sphère -/// Angle de départ (en radians) pour le dessin des parallèles -/// Angle final (en radians) pour le dessin des parallèles -/// Angle de départ (en radians) pour le dessin des meridiens -/// Angle final (en radians) pour le dessin des meridiens -/// Couleur de la portion de sphère +// Fonctions Potion Sphère void MyDrawPolygonSpherePortion(Sphere sphere, int nMeridians, int nParallels, float startTheta, float endTheta, float startPhi, float endPhi, Color color) { int numVertex = nMeridians * nParallels * 4; @@ -541,50 +426,32 @@ void MyDrawPolygonSpherePortion(Sphere sphere, int nMeridians, int nParallels, f rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(sphere.radius, sphere.radius, sphere.radius); - // Points position for one quad in the sphere - // 1-----2 - // | \ | - // | \ | - // | \ | - // 3-----4 - Spherical pt1, pt2, pt3, pt4; // = {rho, theta, phi} - - // MERIDIAN -> phi € [0°, 180°] - // | - // | - // -----|----- PARALLEL -> theta € [0°, 360°] - // | - // | + Spherical s1, s2, s3, s4; + Vector3 v1, v2, v3, v4; for (int m = 0; m < nMeridians; m++) { for (int p = 0; p < nParallels; p++) { - pt1 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * m }; - pt2 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; - pt3 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * m }; - pt4 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; + // On calcule les coordonnées sphériques des points de la face + s1 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * m }; + s2 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; + s3 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * m }; + s4 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; + + v1 = SphericalToCartesian(s1); + v2 = SphericalToCartesian(s2); + v3 = SphericalToCartesian(s3); + v4 = SphericalToCartesian(s4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawTriangle3D(SphericalToCartesian(pt1), SphericalToCartesian(pt2), SphericalToCartesian(pt4), color); - DrawTriangle3D(SphericalToCartesian(pt1), SphericalToCartesian(pt4), SphericalToCartesian(pt3), color); + DrawTriangle3D(v1, v2, v4, color); + DrawTriangle3D(v1, v4, v3, color); } } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner la portion de sphère en fil de fer à partir d'un certain nombre de méridiens et de parallèles, -/// ainsi que de la plage de début et de fin pour theta et phi -/// -/// Contient les informations de la sphère (centre, rayon, orientation) -/// Nombre de meridiens utilisés pour dessiner la portion de sphère -/// Nombre de parallèles utilisés pour dessiner la portion de sphère -/// Angle de départ (en radians) pour le dessin des parallèles -/// Angle final (en radians) pour le dessin des parallèles -/// Angle de départ (en radians) pour le dessin des meridiens -/// Angle final (en radians) pour le dessin des meridiens -/// Couleur de la ligne void MyDrawWireframeSpherePortion(Sphere sphere, int nMeridians, int nParallels, float startTheta, float endTheta, float startPhi, float endPhi, Color color) { int numVertex = nMeridians * nParallels * 4; @@ -596,74 +463,44 @@ void MyDrawWireframeSpherePortion(Sphere sphere, int nMeridians, int nParallels, rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(sphere.radius, sphere.radius, sphere.radius); - // Points position for one quad in the sphere - // 1-----2 - // | \ | - // | \ | - // | \ | - // 3-----4 - Spherical pt1, pt2, pt3, pt4; // = {rho, theta, phi} - - // MERIDIAN -> phi € [0°, 180°] - // | - // | - // -----|----- PARALLEL -> theta € [0°, 360°] - // | - // | + Spherical s1, s2, s3, s4; + Vector3 v1, v2, v3, v4; for (int m = 0; m < nMeridians; m++) { for (int p = 0; p < nParallels; p++) { - pt1 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * m }; - pt2 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; - pt3 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * m }; - pt4 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; + // On calcule les coordonnées sphériques des points de la face + s1 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * m }; + s2 = { 1, startTheta + (endTheta - startTheta) / nParallels * p, startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; + s3 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * m }; + s4 = { 1, startTheta + (endTheta - startTheta) / nParallels * (p + 1), startPhi + (endPhi - startPhi) / nMeridians * (m + 1) }; + + v1 = SphericalToCartesian(s1); + v2 = SphericalToCartesian(s2); + v3 = SphericalToCartesian(s3); + v4 = SphericalToCartesian(s4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawLine3D(SphericalToCartesian(pt1), SphericalToCartesian(pt4), color); - DrawLine3D(SphericalToCartesian(pt1), SphericalToCartesian(pt2), color); - DrawLine3D(SphericalToCartesian(pt1), SphericalToCartesian(pt3), color); - DrawLine3D(SphericalToCartesian(pt2), SphericalToCartesian(pt4), color); - DrawLine3D(SphericalToCartesian(pt3), SphericalToCartesian(pt4), color); + DrawLine3D(v1, v4, color); + DrawLine3D(v1, v2, color); + DrawLine3D(v1, v3, color); + DrawLine3D(v2, v4, color); + DrawLine3D(v3, v4, color); } } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner la portion de sphère en mode polygone et/ou fil de fer -/// -/// Contient les informations de la sphère à dessiner, tels que sa position, sa rotation et son rayon -/// Nombre de méridiens à utiliser pour dessiner la sphère -/// Nombre de parallèles à utiliser pour dessiner la sphère -/// Limite de début pour theta -/// Limite de fin pour theta -/// Limite de début pour phi -/// Limite de fin pour phi -/// Indicateur pour dessiner ou non la portion sphérique en mode polygone -/// Indicateur pour dessiner ou non la portion sphérique en mode fil de fer -/// Couleur à utiliser pour dessiner la portion sphérique en mode polygone -/// Couleur à utiliser pour dessiner la portion sphérique en mode fil de fer void MyDrawSpherePortion(Sphere sphere, int nMeridians, int nParallels, float startTheta, float endTheta, float startPhi, float endPhi, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonSpherePortion(sphere, nMeridians, nParallels, startTheta, endTheta, startPhi, endPhi, polygonColor); if (drawWireframe) MyDrawWireframeSpherePortion(sphere, nMeridians, nParallels, startTheta, endTheta, startPhi, endPhi, wireframeColor); } - -/****************************************************************** -* CYLINDER * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner un cylindre en mode polygone d'une certaine couleur -/// et de spécifier s'il faut dessiner les disques supérieur et inférieur à partir de paramètres donnés -/// -/// Contient les informations sur la position, la taille et l'orientation du cylindre -/// Nombre de secteurs utilisés pour dessiner le cylindre -/// Indique s'il faut dessiner les disques supérieur et inférieur -/// Contient la couleur du cylindre +/************************************************ +* Cylinder * +*************************************************/ void MyDrawPolygonCylinder(Cylinder cylinder, int nSectors, bool drawCaps, Color color) { int numVertex = nSectors * 3; @@ -676,35 +513,35 @@ void MyDrawPolygonCylinder(Cylinder cylinder, int nSectors, bool drawCaps, Color rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(cylinder.radius, cylinder.halfHeight, cylinder.radius); - Cylindrical v1, v2, v3, v4; + Cylindrical c1, c2, c3, c4; + Vector3 v1, v2, v3, v4; for (int i = 0; i < nSectors; i++) { - v1 = { 1, 2 * PI / nSectors * i, 1 }; - v2 = { 1, 2 * PI / nSectors * (i + 1), 1 }; - v3 = { 1, 2 * PI / nSectors * i, -1 }; - v4 = { 1, 2 * PI / nSectors * (i + 1), -1 }; + // On calcule les coordonnées cylindriques des points de la face + c1 = { 1, 2 * PI / nSectors * i, 1 }; + c2 = { 1, 2 * PI / nSectors * (i + 1), 1 }; + c3 = { 1, 2 * PI / nSectors * i, -1 }; + c4 = { 1, 2 * PI / nSectors * (i + 1), -1 }; + + v1 = CylindricalToCartesien(c1); + v2 = CylindricalToCartesien(c2); + v3 = CylindricalToCartesien(c3); + v4 = CylindricalToCartesien(c4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - if (drawCaps) { // alors dessin des disques supérieurs et inférieurs (formes discoïdales) - DrawTriangle3D(CylindricalToCartesien(v2), { 0, 1, 0 }, CylindricalToCartesien(v1), color); - DrawTriangle3D({ 0, -1, 0 }, CylindricalToCartesien(v4), CylindricalToCartesien(v3), color); + if (drawCaps) { // alors dessin des disques supérieurs et inférieurs + DrawTriangle3D(v2, { 0, 1, 0 }, v1, color); + DrawTriangle3D({ 0, -1, 0 }, v4, v3, color); } - DrawTriangle3D(CylindricalToCartesien(v1), CylindricalToCartesien(v4), CylindricalToCartesien(v2), color); - DrawTriangle3D(CylindricalToCartesien(v1), CylindricalToCartesien(v3), CylindricalToCartesien(v4), color); + DrawTriangle3D(v1, v4, v2, color); + DrawTriangle3D(v1, v3, v4, color); } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un cylindre en mode fil de fer d'une certaine couleur -/// et de spécifier s'il faut dessiner les disques supérieur et inférieur à partir de paramètres donnés -/// -/// Contient les informations sur la position, la taille et l'orientation du cylindre -/// Nombre de secteurs utilisés pour dessiner le cylindre -/// Indique s'il faut dessiner les disques supérieur et inférieur -/// Contient la couleur de la ligne + void MyDrawWireframeCylinder(Cylinder cylinder, int nSectors, bool drawCaps, Color color) { int numVertex = nSectors * 4; @@ -717,54 +554,43 @@ void MyDrawWireframeCylinder(Cylinder cylinder, int nSectors, bool drawCaps, Col rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(cylinder.radius, cylinder.halfHeight, cylinder.radius); - Cylindrical v1, v2, v3, v4; + Cylindrical c1, c2, c3, c4; + Vector3 v1, v2, v3, v4; for (int i = 0; i < nSectors; i++) { - v1 = { 1, 2 * PI / nSectors * i, 1 }; - v2 = { 1, 2 * PI / nSectors * (i + 1), 1 }; - v3 = { 1, 2 * PI / nSectors * i, -1 }; - v4 = { 1, 2 * PI / nSectors * (i + 1), -1 }; + // On calcule les coordonnées cylindriques des points de la face + c1 = { 1, 2 * PI / nSectors * i, 1 }; + c2 = { 1, 2 * PI / nSectors * (i + 1), 1 }; + c3 = { 1, 2 * PI / nSectors * i, -1 }; + c4 = { 1, 2 * PI / nSectors * (i + 1), -1 }; + + v1 = CylindricalToCartesien(c1); + v2 = CylindricalToCartesien(c2); + v3 = CylindricalToCartesien(c3); + v4 = CylindricalToCartesien(c4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - if (drawCaps) { // alors dessin des disques supérieurs et inférieurs (formes discoïdales) - DrawLine3D(CylindricalToCartesien(v1), { 0, 1, 0 }, color); - DrawLine3D(CylindricalToCartesien(v3), { 0, -1, 0 }, color); + if (drawCaps) { // alors dessin des disques supérieurs et inférieurs + DrawLine3D(v1, { 0, 1, 0 }, color); + DrawLine3D(v3, { 0, -1, 0 }, color); } - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v2), color); - DrawLine3D(CylindricalToCartesien(v3), CylindricalToCartesien(v4), color); - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v3), color); - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v4), color); + DrawLine3D(v1, v2, color); + DrawLine3D(v3, v4, color); + DrawLine3D(v1, v3, color); + DrawLine3D(v1, v4, color); + // Inutile de dessiner [V2,V4] car il correspondra lors du prochain tour de boucle à [V1,V3] } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un cylindre en mode polygone et/ou fil de fer -/// -/// Contient les informations relatives à la forme du cylindre (rayon, hauteur ...) -/// Nombre de secteurs utilisés pour dessiner le cylindre -/// Indique si les disques supérieur et inférieur du cylindre doivent être dessinés -/// Indique si le cylindre doit être dessiné en mode polygones -/// Indique si le cylindre doit être dessiné en mode fil de fer -/// Couleur utilisée pour dessiner le cylindre en mode polygones -/// Couleur utilisée pour dessiner le cylindre en mode fil de fer void MyDrawCylinder(Cylinder cylinder, int nSectors, bool drawCaps, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonCylinder(cylinder, nSectors, drawCaps, polygonColor); if (drawWireframe) MyDrawWireframeCylinder(cylinder, nSectors, drawCaps, wireframeColor); } -/// -/// Méthode permettant de dessiner un cylindre infini avec une certaine couleur -/// -/// Contient les informations nécessaires pour positionner le cylindre -/// Nombre de secteurs utilisés pour dessiner le cylindre -/// Indique si le cylindre doit être dessiné en mode polygones -/// Indique si le cylindre doit être dessiné en mode fil de fer -/// Couleur utilisée pour dessiner le cylindre en mode polygones -/// Couleur utilisée pour dessiner le cylindre en mode fil de fer void MyDrawInfiniteCylinder(InfiniteCylinder infiniteCylinder, int nSectors, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { Cylinder inf_cylinder = Cylinder{ infiniteCylinder.ref, 40.0f, infiniteCylinder.radius }; @@ -772,19 +598,7 @@ void MyDrawInfiniteCylinder(InfiniteCylinder infiniteCylinder, int nSectors, boo if (drawWireframe) MyDrawWireframeCylinder(inf_cylinder, nSectors, false, wireframeColor); } - -/****************************************************************** -* Cylinder Optimization Methods * -*******************************************************************/ - -/// -/// Cette méthode permet de dessiner une portion de cylindre en utilisant un certain nombre de secteurs et une intervalle de début et de fin pour l'angle theta -/// -/// Contient les informations nécessaires pour dessiner le cylindre, telles que la position, le rayon et la hauteur -/// Le nombre de secteurs à utiliser pour dessiner la portion de cylindre -/// L'angle de départ (en degrés) à utiliser pour dessiner la portion de cylindre -/// L'angle de fin (en degrés) à utiliser pour dessiner la portion de cylindre -/// La couleur à utiliser pour dessiner le cylindre +// Fonctions Potion Cylindre void MyDrawPolygonCylinderPortion(Cylinder cylinder, int nSectors, float startTheta, float endTheta, Color color) { int numVertex = nSectors * 4; @@ -796,30 +610,29 @@ void MyDrawPolygonCylinderPortion(Cylinder cylinder, int nSectors, float startTh rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(cylinder.radius, cylinder.halfHeight, cylinder.radius); - Cylindrical v1, v2, v3, v4; + Cylindrical c1, c2, c3, c4; + Vector3 v1, v2, v3, v4; for (int i = 0; i < nSectors; i++) { - v1 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, 1 }; - v2 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), 1 }; - v3 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, -1 }; - v4 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), -1 }; + // On calcule les coordonnées cylindriques des points de la face + c1 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, 1 }; + c2 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), 1 }; + c3 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, -1 }; + c4 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), -1 }; + + v1 = CylindricalToCartesien(c1); + v2 = CylindricalToCartesien(c2); + v3 = CylindricalToCartesien(c3); + v4 = CylindricalToCartesien(c4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawTriangle3D(CylindricalToCartesien(v1), CylindricalToCartesien(v4), CylindricalToCartesien(v2), color); - DrawTriangle3D(CylindricalToCartesien(v1), CylindricalToCartesien(v3), CylindricalToCartesien(v4), color); + DrawTriangle3D(v1, v4, v2, color); + DrawTriangle3D(v1, v3, v4, color); } rlPopMatrix(); } -/// -/// Cette méthode permet de dessiner une portion de cylindre en mode fil de fer en utilisant un certain nombre de secteurs et une intervalle de début et de fin pour l'angle theta -/// -/// Contient les informations nécessaires pour dessiner le cylindre, telles que la position, le rayon et la hauteur -/// Le nombre de secteurs à utiliser pour dessiner la portion de cylindre -/// L'angle de départ (en degrés) à utiliser pour dessiner la portion de cylindre -/// L'angle de fin (en degrés) à utiliser pour dessiner la portion de cylindre -/// La couleur à utiliser pour dessiner les lignes void MyDrawWireframeCylinderPortion(Cylinder cylinder, int nSectors, float startTheta, float endTheta, Color color) { int numVertex = nSectors * 4; @@ -831,54 +644,42 @@ void MyDrawWireframeCylinderPortion(Cylinder cylinder, int nSectors, float start rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); rlScalef(cylinder.radius, cylinder.halfHeight, cylinder.radius); - Cylindrical v1, v2, v3, v4; + Cylindrical c1, c2, c3, c4; + Vector3 v1, v2, v3, v4; for (int i = 0; i < nSectors; i++) { - v1 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, 1 }; - v2 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), 1 }; - v3 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, -1 }; - v4 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), -1 }; + // On calcule les coordonnées cylindriques des points de la face + c1 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, 1 }; + c2 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), 1 }; + c3 = { 1, startTheta + (endTheta - startTheta) / nSectors * i, -1 }; + c4 = { 1, startTheta + (endTheta - startTheta) / nSectors * (i + 1), -1 }; + + v1 = CylindricalToCartesien(c1); + v2 = CylindricalToCartesien(c2); + v3 = CylindricalToCartesien(c3); + v4 = CylindricalToCartesien(c4); if (rlCheckBufferLimit(numVertex)) rlglDraw(); - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v2), color); - DrawLine3D(CylindricalToCartesien(v3), CylindricalToCartesien(v4), color); - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v3), color); - DrawLine3D(CylindricalToCartesien(v1), CylindricalToCartesien(v4), color); - DrawLine3D(CylindricalToCartesien(v2), CylindricalToCartesien(v4), color); + DrawLine3D(v1, v2, color); + DrawLine3D(v3, v4, color); + DrawLine3D(v1, v3, color); + DrawLine3D(v1, v4, color); + DrawLine3D(v2, v4, color); } rlPopMatrix(); } -/// -/// Méthode permettant de dessiner une portion de cylindre en mode polygone et/ou de fil de fer -/// -/// Contient les informations de base sur le cylindre (position, taille ...) -/// Nombre de secteurs utilisés pour dessiner la portion de cylindre -/// Angle de départ pour dessiner la portion de cylindre -/// Angle final pour dessiner la portion de cylindre -/// Détermine si la portion de cylindre doit être dessinée en utilisant des polygones -/// Détermine si la portion de cylindre doit être dessinée en utilisant un fil de fer -/// Couleur à utiliser pour dessiner les polygones -/// Couleur à utiliser pour dessiner le fil de fer void MyDrawCylinderPortion(Cylinder cylinder, int nSectors, float startTheta, float endTheta, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonCylinderPortion(cylinder, nSectors, startTheta, endTheta, polygonColor); if (drawWireframe) MyDrawWireframeCylinderPortion(cylinder, nSectors, startTheta, endTheta, wireframeColor); } - -/****************************************************************** -* CAPSULE * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner une capsule en mode polygones -/// -/// Contient les informations de la capsule (référence => l'orientation et la position, hauteur, rayon) -/// Nombre de secteurs utilisés pour dessiner les sphères -/// Nombre de parallèles utilisés pour dessiner les sphères et le cylindre -/// Contient la couleur des polygones +/************************************************ +* Capsule * +*************************************************/ +// Pour dessiner la Capsule nous utilisons les Primitives 3D "PortionSphere" et "PortionCylinder". void MyDrawPolygonCapsule(Capsule capsule, int nSectors, int nParallels, Color color) { rlPushMatrix(); @@ -888,9 +689,10 @@ void MyDrawPolygonCapsule(Capsule capsule, int nSectors, int nParallels, Color c QuaternionToAxisAngle(capsule.ref.q, &vect, &angle); rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); - Cylinder capsule_cylinder = { ReferenceFrame({0, 0, 0}, QuaternionIdentity()), capsule.halfHeight, capsule.radius }; - Sphere capsule_sphere_top = { ReferenceFrame({0, capsule.halfHeight, 0}, QuaternionIdentity()), capsule.radius }; - Sphere capsule_sphere_bottom = { ReferenceFrame({0, -capsule.halfHeight, 0}, QuaternionIdentity()), capsule.radius }; + Quaternion q = QuaternionIdentity(); + Sphere capsule_sphere_top = { ReferenceFrame({0, capsule.halfHeight, 0}, q), capsule.radius }; + Cylinder capsule_cylinder = { ReferenceFrame({0, 0, 0}, q), capsule.halfHeight, capsule.radius }; + Sphere capsule_sphere_bottom = { ReferenceFrame({0, -capsule.halfHeight, 0}, q), capsule.radius }; MyDrawPolygonSpherePortion(capsule_sphere_top, nSectors, nParallels, 0.0f * DEG2RAD, 360.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); MyDrawPolygonCylinder(capsule_cylinder, nParallels, false, color); @@ -898,13 +700,6 @@ void MyDrawPolygonCapsule(Capsule capsule, int nSectors, int nParallels, Color c rlPopMatrix(); } -/// -/// Méthode permettant de dessiner une capsule en mode fil de fer -/// -/// Contient les informations de la capsule (référence => l'orientation et la position, hauteur, rayon) -/// Nombre de secteurs utilisés pour dessiner les sphères -/// Nombre de parallèles utilisés pour dessiner les sphères et le cylindre -/// Contient la couleur des lignes void MyDrawWireframeCapsule(Capsule capsule, int nSectors, int nParallels, Color color) { rlPushMatrix(); @@ -914,9 +709,10 @@ void MyDrawWireframeCapsule(Capsule capsule, int nSectors, int nParallels, Color QuaternionToAxisAngle(capsule.ref.q, &vect, &angle); rlRotatef(angle * RAD2DEG, vect.x, vect.y, vect.z); - Cylinder capsule_cylinder = { ReferenceFrame({0, 0, 0}, QuaternionIdentity()), capsule.halfHeight, capsule.radius }; - Sphere capsule_sphere_top = { ReferenceFrame({0, capsule.halfHeight, 0}, QuaternionIdentity()), capsule.radius}; - Sphere capsule_sphere_bottom = { ReferenceFrame({0, -capsule.halfHeight, 0}, QuaternionIdentity()), capsule.radius }; + Quaternion q = QuaternionIdentity(); + Sphere capsule_sphere_top = { ReferenceFrame({0, capsule.halfHeight, 0}, q), capsule.radius }; + Cylinder capsule_cylinder = { ReferenceFrame({0, 0, 0}, q), capsule.halfHeight, capsule.radius }; + Sphere capsule_sphere_bottom = { ReferenceFrame({0, -capsule.halfHeight, 0}, q), capsule.radius }; MyDrawWireframeSpherePortion(capsule_sphere_top, nSectors, nParallels, 0.0f * DEG2RAD, 360.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); MyDrawWireframeCylinder(capsule_cylinder, nParallels, false, color); @@ -925,33 +721,16 @@ void MyDrawWireframeCapsule(Capsule capsule, int nSectors, int nParallels, Color rlPopMatrix(); } -/// -/// Méthode permettant de dessiner une capsule en mode polygone et/ou fil de fer -/// -/// Contient les informations de la capsule (référence => l'orientation et la position, hauteur, rayon) -/// Nombre de secteurs utilisés pour dessiner les sphères -/// Nombre de parallèles utilisés pour dessiner les sphères et le cylindre -/// Détermine si la capsule doit être dessinée en mode polygone -/// Détermine si la capsule doit être dessinée en mode fil de fer -/// Contient la couleur des polygones -/// Contient la couleur des lignes en mode fil de fer void MyDrawCapsule(Capsule capsule, int nSectors, int nParallels, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonCapsule(capsule, nSectors, nParallels, polygonColor); if (drawWireframe) MyDrawWireframeCapsule(capsule, nSectors, nParallels, wireframeColor); } - -/****************************************************************** -* ROUNDED BOX * -*******************************************************************/ - -/// -/// Méthode permettant de dessiner un boîte arrondie en mode polygones -/// -/// Contient les informations de la boîte arrondie (référence => l'orientation et la position, dimensions, rayon des Sphères) -/// Nombre de secteurs utilisés -/// Contient la couleur des polygones +/************************************************ +* RoundedBox * +*************************************************/ +// Pour dessiner la RoundedBox nous utilisons les Primitives 3D "PortionSphere", "PortionCylinder" et "Quad". void MyDrawPolygonRoundedBox(RoundedBox roundedBox, int nSectors, Color color) { rlPushMatrix(); @@ -963,7 +742,7 @@ void MyDrawPolygonRoundedBox(RoundedBox roundedBox, int nSectors, Color color) Quaternion q = QuaternionIdentity(); - //SPHERES PART + // Initialisation des parties sphériques de la RoundedBox (8) Sphere sph_top_front_left = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,roundedBox.extents.z }, q), roundedBox.radius }; Sphere sph_top_front_right = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,-roundedBox.extents.z }, q), roundedBox.radius }; Sphere sph_top_back_right = { ReferenceFrame({ -roundedBox.extents.x,roundedBox.extents.y,-roundedBox.extents.z }, q), roundedBox.radius }; @@ -973,16 +752,21 @@ void MyDrawPolygonRoundedBox(RoundedBox roundedBox, int nSectors, Color color) Sphere sph_bottom_back_right = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,-roundedBox.extents.z }, q), roundedBox.radius }; Sphere sph_bottom_back_left = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,roundedBox.extents.z }, q), roundedBox.radius }; - MyDrawPolygonSpherePortion(sph_top_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_top_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_top_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_top_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_bottom_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_bottom_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_bottom_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - MyDrawPolygonSpherePortion(sph_bottom_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + // Initialisation des parties cylindriques de la RoundedBox (12) + Cylinder cyl_top_front = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; + Cylinder cyl_top_back = { ReferenceFrame({ -roundedBox.extents.x,roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; + Cylinder cyl_bottom_back = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; + Cylinder cyl_bottom_front = { ReferenceFrame({ roundedBox.extents.x,-roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; + Cylinder cyl_front_right = { ReferenceFrame({ roundedBox.extents.x,0,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; + Cylinder cyl_back_right = { ReferenceFrame({ -roundedBox.extents.x,0,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; + Cylinder cyl_back_left = { ReferenceFrame({ -roundedBox.extents.x,0,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; + Cylinder cyl_front_left = { ReferenceFrame({ roundedBox.extents.x,0,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; + Cylinder cyl_top_left = { ReferenceFrame({ 0,roundedBox.extents.y,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; + Cylinder cyl_top_right = { ReferenceFrame({ 0,roundedBox.extents.y,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; + Cylinder cyl_bottom_right = { ReferenceFrame({ 0,-roundedBox.extents.y,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; + Cylinder cyl_bottom_left = { ReferenceFrame({ 0,-roundedBox.extents.y,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; - //QUADS PART + // Initialisation des Quads de la RoundedBox (6) Quad quad_top = { ReferenceFrame({ 0,roundedBox.extents.y + roundedBox.radius,0 }, q), { roundedBox.extents.x, 0, roundedBox.extents.z } }; Quaternion quad_q = QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI)); Quad quad_bottom = { ReferenceFrame({ 0,-(roundedBox.extents.y + roundedBox.radius),0 }, quad_q), { roundedBox.extents.x, 0, roundedBox.extents.z } }; @@ -995,28 +779,15 @@ void MyDrawPolygonRoundedBox(RoundedBox roundedBox, int nSectors, Color color) quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI)); Quad quad_left = { ReferenceFrame({ 0,0,roundedBox.extents.z + roundedBox.radius }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.x} }; - MyDrawPolygonQuad(quad_top, color); - MyDrawPolygonQuad(quad_bottom, color); - MyDrawPolygonQuad(quad_front, color); - MyDrawPolygonQuad(quad_back, color); - MyDrawPolygonQuad(quad_right, color); - MyDrawPolygonQuad(quad_left, color); - - //CYLINDICALS PART - Cylinder cyl_top_front = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; - Cylinder cyl_top_back = { ReferenceFrame({ -roundedBox.extents.x,roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; - Cylinder cyl_bottom_back = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; - Cylinder cyl_bottom_front = { ReferenceFrame({ roundedBox.extents.x,-roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; - - Cylinder cyl_front_right = { ReferenceFrame({ roundedBox.extents.x,0,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; - Cylinder cyl_back_right = { ReferenceFrame({ -roundedBox.extents.x,0,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; - Cylinder cyl_back_left = { ReferenceFrame({ -roundedBox.extents.x,0,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; - Cylinder cyl_front_left = { ReferenceFrame({ roundedBox.extents.x,0,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,1,0 }), PI / 2))), roundedBox.extents.y, roundedBox.radius }; - - Cylinder cyl_top_left = { ReferenceFrame({ 0,roundedBox.extents.y,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; - Cylinder cyl_top_right = { ReferenceFrame({ 0,roundedBox.extents.y,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; - Cylinder cyl_bottom_right = { ReferenceFrame({ 0,-roundedBox.extents.y,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; - Cylinder cyl_bottom_left = { ReferenceFrame({ 0,-roundedBox.extents.y,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; + // Affichage des différentes parties de la RoundedBox en Polygon + MyDrawPolygonSpherePortion(sph_top_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_top_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_top_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_top_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_bottom_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_bottom_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_bottom_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawPolygonSpherePortion(sph_bottom_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); MyDrawPolygonCylinderPortion(cyl_bottom_front, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); MyDrawPolygonCylinderPortion(cyl_top_front, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); @@ -1031,15 +802,16 @@ void MyDrawPolygonRoundedBox(RoundedBox roundedBox, int nSectors, Color color) MyDrawPolygonCylinderPortion(cyl_bottom_right, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, color); MyDrawPolygonCylinderPortion(cyl_bottom_left, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, color); + MyDrawPolygonQuad(quad_top, color); + MyDrawPolygonQuad(quad_bottom, color); + MyDrawPolygonQuad(quad_front, color); + MyDrawPolygonQuad(quad_back, color); + MyDrawPolygonQuad(quad_right, color); + MyDrawPolygonQuad(quad_left, color); + rlPopMatrix(); } -/// -/// Méthode permettant de dessiner un boîte arrondie en mode fil de fer -/// -/// Contient les informations de la boîte arrondie (référence => l'orientation et la position, dimensions, rayon des Sphères) -/// Nombre de secteurs utilisés -/// Contient la couleur des lignes void MyDrawWireframeRoundedBox(RoundedBox roundedBox, int nSectors, Color color) { rlPushMatrix(); @@ -1051,7 +823,7 @@ void MyDrawWireframeRoundedBox(RoundedBox roundedBox, int nSectors, Color color) Quaternion q = QuaternionIdentity(); - //SPHERES PART + // Initialisation des parties sphériques de la RoundedBox (8) Sphere sph_top_front_left = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,roundedBox.extents.z }, q), roundedBox.radius }; Sphere sph_top_front_right = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,-roundedBox.extents.z }, q), roundedBox.radius }; Sphere sph_top_back_right = { ReferenceFrame({ -roundedBox.extents.x,roundedBox.extents.y,-roundedBox.extents.z }, q), roundedBox.radius }; @@ -1061,36 +833,7 @@ void MyDrawWireframeRoundedBox(RoundedBox roundedBox, int nSectors, Color color) Sphere sph_bottom_back_right = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,-roundedBox.extents.z }, q), roundedBox.radius }; Sphere sph_bottom_back_left = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,roundedBox.extents.z }, q), roundedBox.radius }; - MyDrawWireframeSpherePortion(sph_top_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_top_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_top_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_top_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_bottom_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_bottom_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_bottom_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - MyDrawWireframeSpherePortion(sph_bottom_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); - - //QUADS PART - Quad quad_top = { ReferenceFrame({ 0,roundedBox.extents.y + roundedBox.radius,0 }, q), { roundedBox.extents.x, 0, roundedBox.extents.z } }; - Quaternion quad_q = QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI)); - Quad quad_bottom = { ReferenceFrame({ 0,-(roundedBox.extents.y + roundedBox.radius),0 }, quad_q), { roundedBox.extents.x, 0, roundedBox.extents.z } }; - quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2)); - Quad quad_front = { ReferenceFrame({ roundedBox.extents.x + roundedBox.radius,0,0 }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.z } }; - quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI)); - Quad quad_back = { ReferenceFrame({ -(roundedBox.extents.x + roundedBox.radius),0,0 }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.z } }; - quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2)); - Quad quad_right = { ReferenceFrame({ 0,0,-(roundedBox.extents.z + roundedBox.radius) }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.x} }; - quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI)); - Quad quad_left = { ReferenceFrame({ 0,0,roundedBox.extents.z + roundedBox.radius }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.x} }; - - MyDrawWireframeQuad(quad_top, color); - MyDrawWireframeQuad(quad_bottom, color); - MyDrawWireframeQuad(quad_front, color); - MyDrawWireframeQuad(quad_back, color); - MyDrawWireframeQuad(quad_left, color); - MyDrawWireframeQuad(quad_right, color); - - //CYLINDICALS PART + // Initialisation des parties cylindriques de la RoundedBox (12) Cylinder cyl_top_front = { ReferenceFrame({ roundedBox.extents.x,roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; Cylinder cyl_top_back = { ReferenceFrame({ -roundedBox.extents.x,roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; Cylinder cyl_bottom_back = { ReferenceFrame({ -roundedBox.extents.x,-roundedBox.extents.y,0 }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2))), roundedBox.extents.z, roundedBox.radius }; @@ -1104,6 +847,29 @@ void MyDrawWireframeRoundedBox(RoundedBox roundedBox, int nSectors, Color color) Cylinder cyl_bottom_right = { ReferenceFrame({ 0,-roundedBox.extents.y,-roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; Cylinder cyl_bottom_left = { ReferenceFrame({ 0,-roundedBox.extents.y,roundedBox.extents.z }, QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2))), roundedBox.extents.x, roundedBox.radius }; + // Initialisation des Quads de la RoundedBox (6) + Quad quad_top = { ReferenceFrame({ 0,roundedBox.extents.y + roundedBox.radius,0 }, q), { roundedBox.extents.x, 0, roundedBox.extents.z } }; + Quaternion quad_q = QuaternionMultiply(q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI)); + Quad quad_bottom = { ReferenceFrame({ 0,-(roundedBox.extents.y + roundedBox.radius),0 }, quad_q), { roundedBox.extents.x, 0, roundedBox.extents.z } }; + quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 0,0,1 }), PI / 2)); + Quad quad_front = { ReferenceFrame({ roundedBox.extents.x + roundedBox.radius,0,0 }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.z } }; + quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI)); + Quad quad_back = { ReferenceFrame({ -(roundedBox.extents.x + roundedBox.radius),0,0 }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.z } }; + quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI / 2)); + Quad quad_right = { ReferenceFrame({ 0,0,-(roundedBox.extents.z + roundedBox.radius) }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.x} }; + quad_q = QuaternionMultiply(quad_q, QuaternionFromAxisAngle(Vector3Normalize({ 1,0,0 }), PI)); + Quad quad_left = { ReferenceFrame({ 0,0,roundedBox.extents.z + roundedBox.radius }, quad_q), { roundedBox.extents.y, 0, roundedBox.extents.x} }; + + // Affichage des différentes parties de la RoundedBox en Wireframe + MyDrawWireframeSpherePortion(sph_top_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_top_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_top_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_top_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_bottom_front_left, nSectors, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_bottom_front_right, nSectors, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_bottom_back_right, nSectors, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawWireframeSpherePortion(sph_bottom_back_left, nSectors, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); + MyDrawWireframeCylinderPortion(cyl_bottom_front, nSectors, 0.0f * DEG2RAD, 90.0f * DEG2RAD, color); MyDrawWireframeCylinderPortion(cyl_top_front, nSectors, 90.0f * DEG2RAD, 180.0f * DEG2RAD, color); MyDrawWireframeCylinderPortion(cyl_top_back, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, color); @@ -1117,18 +883,16 @@ void MyDrawWireframeRoundedBox(RoundedBox roundedBox, int nSectors, Color color) MyDrawWireframeCylinderPortion(cyl_bottom_right, nSectors, 180.0f * DEG2RAD, 270.0f * DEG2RAD, color); MyDrawWireframeCylinderPortion(cyl_bottom_left, nSectors, 270.0f * DEG2RAD, 360.0f * DEG2RAD, color); + MyDrawWireframeQuad(quad_top, color); + MyDrawWireframeQuad(quad_bottom, color); + MyDrawWireframeQuad(quad_front, color); + MyDrawWireframeQuad(quad_back, color); + MyDrawWireframeQuad(quad_left, color); + MyDrawWireframeQuad(quad_right, color); + rlPopMatrix(); } -/// -/// Méthode permettant de dessiner une boîte arrondie en mode polygones et/ou fil de fer -/// -/// Contient les informations de la boîte arrondie (référence => l'orientation et la position, dimensions, rayon des Sphères) -/// Nombre de secteurs utilisés -/// Indique s'il faut dessiner les polygones -/// Indique s'il faut dessiner le fil de fer -/// Contient la couleur des polygones -/// Contient la couleur du fil de fer void MyDrawRoundedBox(RoundedBox roundedBox, int nSectors, bool drawPolygon, bool drawWireframe, Color polygonColor, Color wireframeColor) { if (drawPolygon) MyDrawPolygonRoundedBox(roundedBox, nSectors, polygonColor); diff --git a/Raylib_BaseProject/examples/core/My3DPrimitives.hpp b/Raylib_BaseProject/examples/core/My3DPrimitives.hpp index baf088e..ae1c34a 100644 --- a/Raylib_BaseProject/examples/core/My3DPrimitives.hpp +++ b/Raylib_BaseProject/examples/core/My3DPrimitives.hpp @@ -9,43 +9,52 @@ struct Line { Vector3 pt; - Vector3 dir; + Vector3 dir; // dir != { 0, 0, 0 } }; -struct Segment { +struct Segment { // pt1 != pt2 Vector3 pt1; - Vector3 pt2; + Vector3 pt2; }; -struct Triangle { +struct Triangle { // pt1 != pt2 && pt1 != pt3 && pt2 != pt3 Vector3 pt1; Vector3 pt2; - Vector3 pt3; + Vector3 pt3; }; struct Quad { ReferenceFrame ref; - Vector3 extents; + Vector3 extents; // Demi-Longueurs depuis le centre du Quad (ici seuls X et Z sont utilisés) }; -struct Plane { - Vector3 n; - float d; - Plane(Vector3 n, float d) { - this->n = n; // avec n unitaire +struct Plane { // Plan "Infini" (effort d’imagination) + Vector3 n; // Vecteur normal + float d; // Distance à l’origine signée + + Plane(Vector3 n, float d) + { + this->n = n; // n unitaire this->d = d; } - Plane(Vector3 n, Vector3 pt) { - this->n = n; // avec n unitaire + + Plane(Vector3 n, Vector3 pt) + { + this->n = n; // n unitaire this->d = Vector3DotProduct(n, pt); } - Plane(Vector3 pt1, Vector3 pt2, Vector3 pt3) { + + Plane(Vector3 pt1, Vector3 pt2, Vector3 pt3) + { this->n = Vector3CrossProduct(Vector3Subtract(pt2, pt1), Vector3Subtract(pt3, pt2)); - if (Vector3Length(n) < EPSILON) { + + if (Vector3Length(n) < EPSILON) + { this->n = { 0, 0, 0 }; this->d = 0; } - else { + else + { this->n = Vector3Normalize(this->n); this->d = Vector3DotProduct(this->n, pt1); } @@ -54,134 +63,123 @@ struct Plane { struct Disk { ReferenceFrame ref; - float radius; + float radius; // Rayon }; struct Box { ReferenceFrame ref; - Vector3 extents; + Vector3 extents; // Demi-Longueurs depuis le centre de la Box }; struct Sphere { ReferenceFrame ref; - float radius; + float radius; // Rayon }; -struct Cylinder { +struct InfiniteCylinder { // Demi-Hauteur "Infinie" (effort d’imagination) ReferenceFrame ref; - float halfHeight; - float radius; + float radius; // Rayon }; -struct InfiniteCylinder { +struct Cylinder { ReferenceFrame ref; - float radius; + float halfHeight; // Demi-Hauteur depuis le centre + float radius; // Rayon }; struct Capsule { ReferenceFrame ref; - float halfHeight; - float radius; + float halfHeight; // Demi-Hauteur depuis le centre + float radius; // Rayon du Cylindre et des Demi-Sphères }; struct RoundedBox { ReferenceFrame ref; - Vector3 extents; - float radius; + Vector3 extents; // Demi-Longueurs depuis le centre de la RoundedBox + float radius; // Rayon du Cylindre et des Demi-Sphères }; #endif -/****************************************************************** -* Line * -*******************************************************************/ +/************************************************ +* Line * +*************************************************/ void MyDrawLine(Line line, Color color = DARKGRAY); - -/****************************************************************** -* Segment * -*******************************************************************/ +/************************************************ +* Segment * +*************************************************/ void MyDrawSegment(Segment segment, Color color = DARKGRAY); - -/****************************************************************** -* Triangle * -*******************************************************************/ +/************************************************ +* Triangle * +*************************************************/ void MyDrawPolygonTriangle(Triangle triangle, Color color = LIGHTGRAY); void MyDrawWireframeTriangle(Triangle triangle, Color color = DARKGRAY); void MyDrawTriangle(Triangle triangle, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* Quad * -*******************************************************************/ +/************************************************ +* Quad * +*************************************************/ void MyDrawPolygonQuad(Quad quad, Color color = LIGHTGRAY); void MyDrawWireframeQuad(Quad quad, Color color = DARKGRAY); void MyDrawQuad(Quad quad, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* Plane * -*******************************************************************/ +/************************************************ +* Plane * +*************************************************/ void MyDrawPlane(Plane plane, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* Disk * -*******************************************************************/ +/************************************************ +* Disk * +*************************************************/ void MyDrawPolygonDisk(Disk disk, int nSectors, Color color = LIGHTGRAY); void MyDrawWireframeDisk(Disk disk, int nSectors, Color color = DARKGRAY); void MyDrawDisk(Disk disk, int nSectors, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* Box * -*******************************************************************/ +/************************************************ +* Box * +*************************************************/ void MyDrawPolygonBox(Box box, Color color = LIGHTGRAY); void MyDrawWireframeBox(Box box, Color color = DARKGRAY); void MyDrawBox(Box box, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* Sphere * -*******************************************************************/ +/************************************************ +* Sphere * +*************************************************/ void MyDrawPolygonSphere(Sphere sphere, int nMeridians, int nParallels, Color color = LIGHTGRAY); void MyDrawWireframeSphere(Sphere sphere, int nMeridians, int nParallels, Color color = DARKGRAY); void MyDrawSphere(Sphere sphere, int nMeridians, int nParallels, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); -/****************************************************************** -* Sphere Optimization Methods * -*******************************************************************/ + +// Fonctions Potion Sphère void MyDrawPolygonSpherePortion(Sphere sphere, int nMeridians, int nParallels, float startTheta, float endTheta, float startPhi, float endPhi, Color color = LIGHTGRAY); void MyDrawWireframeSpherePortion(Sphere sphere, int nMeridians, int nParallels, float startTheta, float endTheta, float startPhi, float endPhi, Color color = LIGHTGRAY); void MyDrawSpherePortion(Sphere sphere, int nMeridians, int nParallels, float startTheta, float endTheta, float startPhi, float endPhi, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); +/************************************************ +* Cylinder * +*************************************************/ +void MyDrawInfiniteCylinder(InfiniteCylinder infiniteCylinder, int nSectors, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); -/****************************************************************** -* Cylinder * -*******************************************************************/ void MyDrawPolygonCylinder(Cylinder cylinder, int nSectors, bool drawCaps = false, Color color = LIGHTGRAY); void MyDrawWireframeCylinder(Cylinder cylinder, int nSectors, bool drawCaps = false, Color color = LIGHTGRAY); void MyDrawCylinder(Cylinder cylinder, int nSectors, bool drawCaps = false, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); -void MyDrawInfiniteCylinder(InfiniteCylinder infiniteCylinder, int nSectors, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); -/****************************************************************** -* Cylinder Optimization Methods * -*******************************************************************/ + +// Fonctions Potion Cylindre void MyDrawPolygonCylinderPortion(Cylinder cylinder, int nSectors, float startTheta, float endTheta, Color color = LIGHTGRAY); void MyDrawWireframeCylinderPortion(Cylinder cylinder, int nSectors, float startTheta, float endTheta, Color color = LIGHTGRAY); void MyDrawCylinderPortion(Cylinder cylinder, int nSectors, float startTheta, float endTheta, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* Capsule * -*******************************************************************/ +/************************************************ +* Capsule * +*************************************************/ void MyDrawPolygonCapsule(Capsule capsule, int nSectors, int nParallels, Color color = LIGHTGRAY); void MyDrawWireframeCapsule(Capsule capsule, int nSectors, int nParallels, Color color = LIGHTGRAY); void MyDrawCapsule(Capsule capsule, int nSectors, int nParallels, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); - -/****************************************************************** -* RoundedBox * -*******************************************************************/ +/************************************************ +* RoundedBox * +*************************************************/ void MyDrawPolygonRoundedBox(RoundedBox roundedBox, int nSectors, Color color = LIGHTGRAY); void MyDrawWireframeRoundedBox(RoundedBox roundedBox, int nSectors, Color color = LIGHTGRAY); void MyDrawRoundedBox(RoundedBox roundedBox, int nSectors, bool drawPolygon = true, bool drawWireframe = true, Color polygonColor = LIGHTGRAY, Color wireframeColor = DARKGRAY); diff --git a/Raylib_BaseProject/examples/core/coordinates.cpp b/Raylib_BaseProject/examples/core/coordinates.cpp index e7152d5..140b9ee 100644 --- a/Raylib_BaseProject/examples/core/coordinates.cpp +++ b/Raylib_BaseProject/examples/core/coordinates.cpp @@ -1,8 +1,8 @@ #include "Coordinates.hpp" -/******************************************************************************************* -* Fonctions de conversion des différents types de coordonn�es -* ******************************************************************************************/ +/************************************************************************************************************************************* +* Fonctions de conversion de coordonnées cartésiennes en coordonnées polaires (et inversement) * +**************************************************************************************************************************************/ Polar CartesianToPolar(Vector2 cart, bool keepThetaPositive = true) { Polar polar = { Vector2Length(cart), atan2f(cart.y, cart.x) }; @@ -16,11 +16,14 @@ Vector2 PolarToCartesian(Polar polar) return Vector2Scale({ cosf(polar.theta),sinf(polar.theta) }, polar.rho); } +/************************************************************************************************************************************* +* Fonctions de conversion de coordonnées cartésiennes en coordonnées cylindriques (et inversement) * +**************************************************************************************************************************************/ Cylindrical CartesianToCylindrical(Vector3 cart) { Cylindrical cyl; cyl.y = cart.y; - cyl.rho = sqrtf(powf(cart.x, 2) + powf(cart.z, 2)); + cyl.rho = sqrtf(powf(cart.x, 2) + powf(cart.z, 2)); // RHO² = X² + Z² if (cyl.rho < EPSILON) cyl.theta = 0; @@ -36,29 +39,33 @@ Vector3 CylindricalToCartesien(Cylindrical cyl) return { cyl.rho * sinf(cyl.theta), cyl.y, cyl.rho * cosf(cyl.theta) }; } -// Fonction de conversion de coordonnées cartésiennes en coordonnées sphériques +/************************************************************************************************************************************* +* Fonctions de conversion de coordonnées cartésiennes en coordonnées sphériques (et inversement) * +**************************************************************************************************************************************/ Spherical CartesianToSpherical(Vector3 cart) { Spherical sph; - sph.rho = sqrtf(powf(cart.x, 2) + powf(cart.y, 2) + powf(cart.z, 2)); + sph.rho = sqrtf(powf(cart.x, 2) + powf(cart.y, 2) + powf(cart.z, 2)); // RHO² = X² + Y² + Z² - if (sph.rho < EPSILON) { + if (sph.rho < EPSILON) // Si la distance RHO est trop petite, les points se confondent peu importe la valeur des angles THETA ou PHI + { sph.theta = 0.0f; sph.phi = 0.0f; } - else { + else + { sph.phi = acosf(cart.y / sph.rho); + if ((sph.phi < EPSILON) || (sph.phi > PI - EPSILON)) sph.theta = 0.0f; - else { + else + { sph.theta = asinf(cart.x / (sph.rho * sinf(sph.phi))); - if (cart.z < 0.0f) sph.theta = PI - sph.theta; } } return sph; } -// Fonction de conversion de coordonnées sphériques en coordonnées cartésiennes Vector3 SphericalToCartesian(Spherical sph) { return { sph.rho * sinf(sph.phi) * sinf(sph.theta), sph.rho * cosf(sph.phi), sph.rho * sinf(sph.phi) * cosf(sph.theta) }; diff --git a/Raylib_BaseProject/examples/core/reference_frame.h b/Raylib_BaseProject/examples/core/reference_frame.h deleted file mode 100644 index c99881f..0000000 --- a/Raylib_BaseProject/examples/core/reference_frame.h +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************************* -* ReferenceFrame -* ******************************************************************************************/ - -#include -#include -#include -#include - -#ifndef REF_FRAME_STRUCT -#define REF_FRAME_STRUCT - -struct ReferenceFrame { - Vector3 origin; - Vector3 i, j, k; - Quaternion q; - ReferenceFrame() - { - origin = { 0,0,0 }; - i = { 1,0,0 }; - j = { 0,1,0 }; - k = { 0,0,1 }; - q = QuaternionIdentity(); - } - ReferenceFrame(Vector3 origin, Quaternion q) - { - this->q = q; - this->origin = origin; - i = Vector3RotateByQuaternion({ 1,0,0 }, q); - j = Vector3RotateByQuaternion({ 0,1,0 }, q); - k = Vector3RotateByQuaternion({ 0,0,1 }, q); - } - void Translate(Vector3 vect) - { - this->origin = Vector3Add(this->origin, vect); - } - void RotateByQuaternion(Quaternion qRot) - { - q = QuaternionMultiply(qRot, q); - i = Vector3RotateByQuaternion({ 1,0,0 }, q); - j = Vector3RotateByQuaternion({ 0,1,0 }, q); - k = Vector3RotateByQuaternion({ 0,0,1 }, q); - } -}; - -#endif