Skip to content

Commit

Permalink
Refactor: Cleanup TD1
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpellegrini committed Jan 21, 2023
1 parent 9e6fdea commit f9f747b
Show file tree
Hide file tree
Showing 6 changed files with 494 additions and 770 deletions.
11 changes: 7 additions & 4 deletions Raylib_BaseProject/examples/core/Coordinates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
28 changes: 13 additions & 15 deletions Raylib_BaseProject/examples/core/CoreBasicWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*
********************************************************************************************/
#include "raylib.h"
#include <raymath.h>
#include "rlgl.h"
#include <raymath.h>
#include <math.h>
#include <float.h>
#include <vector>
Expand Down Expand Up @@ -55,33 +55,30 @@ 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
prevMousePos = mousePos; // mise à jour de la position précédente de la souris

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);
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -211,8 +208,9 @@ int main(int argc, char* argv[])
DrawSphere({ 0,0,15 }, .2f, BLUE);
}
EndMode3D();

DrawFPS(1800 * screenSizeCoef, 20 * screenSizeCoef);
EndDrawing();

//----------------------------------------------------------------------------------
}

Expand Down
Loading

0 comments on commit f9f747b

Please sign in to comment.