commit 6c9c546748327135ba61ea3d649e53f248fabdb7 Author: Laureηt Date: Wed Jun 21 20:37:15 2023 +0200 init$ diff --git a/TP1/.vscode/settings.json b/TP1/.vscode/settings.json new file mode 100644 index 0000000..1060b04 --- /dev/null +++ b/TP1/.vscode/settings.json @@ -0,0 +1,56 @@ +{ + "files.exclude": + { + "**/.DS_Store":true, + "**/.git":true, + "**/.gitignore":true, + "**/.gitmodules":true, + "**/*.booproj":true, + "**/*.pidb":true, + "**/*.suo":true, + "**/*.user":true, + "**/*.userprefs":true, + "**/*.unityproj":true, + "**/*.dll":true, + "**/*.exe":true, + "**/*.pdf":true, + "**/*.mid":true, + "**/*.midi":true, + "**/*.wav":true, + "**/*.gif":true, + "**/*.ico":true, + "**/*.jpg":true, + "**/*.jpeg":true, + "**/*.png":true, + "**/*.psd":true, + "**/*.tga":true, + "**/*.tif":true, + "**/*.tiff":true, + "**/*.3ds":true, + "**/*.3DS":true, + "**/*.fbx":true, + "**/*.FBX":true, + "**/*.lxo":true, + "**/*.LXO":true, + "**/*.ma":true, + "**/*.MA":true, + "**/*.obj":true, + "**/*.OBJ":true, + "**/*.asset":true, + "**/*.cubemap":true, + "**/*.flare":true, + "**/*.mat":true, + "**/*.meta":true, + "**/*.prefab":true, + "**/*.unity":true, + "build/":true, + "Build/":true, + "Library/":true, + "library/":true, + "obj/":true, + "Obj/":true, + "ProjectSettings/":true, + "temp/":true, + "Temp/":true + } +} \ No newline at end of file diff --git a/TP1/Assets/Scripts/Utils/Interpolateur.cs b/TP1/Assets/Scripts/Utils/Interpolateur.cs new file mode 100644 index 0000000..9db4c87 --- /dev/null +++ b/TP1/Assets/Scripts/Utils/Interpolateur.cs @@ -0,0 +1,375 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System; +using UnityEngine.UI; + + +public class Interpolateur : MonoBehaviour +{ + // Pas d'échantillonnage + public float pas = 1 / 100; + // Conteneur des points cliqués + public GameObject Donnees; + // Les points (X,Y) cliqués + private List X = new List(); + private List Y = new List(); + public enum EInterpolationType { Lagrange, Neville }; + public EInterpolationType InterpolationType = EInterpolationType.Lagrange; + public enum EParametrisationType { Reguliere, Distance, RacineDistance, Tchebytcheff, None } + public EParametrisationType ParametrisationType = EParametrisationType.Reguliere; + + // Pour le dessin des courbes + private List P2DRAW = new List(); + // UI + public Text text; + + ////////////////////////////////////////////////////////////////////////// + // fonction : buildParametrisationReguliere // + // semantique : construit la parametrisation reguliere et les // + // échantillons de temps selon cette parametrisation // + // params : // + // - int nbElem : nombre d'elements de la parametrisation // + // - float pas : pas d'échantillonage // + // sortie : // + // - List T : parametrisation reguliere // + // - List tToEval : echantillon sur la parametrisation // + ////////////////////////////////////////////////////////////////////////// + (List, List) buildParametrisationReguliere(int nbElem, float pas) + { + // Vecteur des pas temporels + List T = new List(); + + // Echantillonage des pas temporels + List tToEval = new List(); + + // Construction des pas temporels + for (int i = 0; i < nbElem; i++) + { + T.Add(i); + } + + // Construction des échantillons + for (float i = T.First(); i <= T.Last(); i += pas) + { + tToEval.Add(i); + } + + return (T, tToEval); + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : buildParametrisationDistance // + // semantique : construit la parametrisation sur les distances et les // + // échantillons de temps selon cette parametrisation // + // params : // + // - int nbElem : nombre d'elements de la parametrisation // + // - float pas : pas d'échantillonage // + // sortie : // + // - List T : parametrisation distances // + // - List tToEval : echantillon sur la parametrisation // + ////////////////////////////////////////////////////////////////////////// + (List, List) buildParametrisationDistance(int nbElem, float pas) + { + // Vecteur des pas temporels + List T = new List(); + // Echantillonage des pas temporels + List tToEval = new List(); + + // Construction des pas temporels + T.Add(0); + for (int i = 0; i < X.Count - 1; i++) + { + float distance = (float)Math.Sqrt((Math.Pow(X[i + 1] - X[i], 2) + Math.Pow(Y[i + 1] - Y[i], 2))); + T.Add(T.Last() + distance); + } + + // Construction des échantillons + for (float i = T.First(); i < T.Last(); i += pas) + { + tToEval.Add(i); + } + + return (T, tToEval); + } + + //////////////////////////////////////////////////////////////////////////// + // fonction : buildParametrisationRacineDistance // + // semantique : construit la parametrisation sur les racines des distances// + // et les échantillons de temps selon cette parametrisation // + // params : // + // - int nbElem : nombre d'elements de la parametrisation // + // - float pas : pas d'échantillonage // + // sortie : // + // - List T : parametrisation racines distances // + // - List tToEval : echantillon sur la parametrisation // + //////////////////////////////////////////////////////////////////////////// + (List, List) buildParametrisationRacineDistance(int nbElem, float pas) + { + // Vecteur des pas temporels + List T = new List(); + // Echantillonage des pas temporels + List tToEval = new List(); + + // Construction des pas temporels + T.Add(0); + for (int i = 0; i < X.Count - 1; i++) + { + float distance = (float)Math.Sqrt(Math.Sqrt((Math.Pow(X[i + 1] - X[i], 2) + Math.Pow(Y[i + 1] - Y[i], 2)))); + T.Add(T.Last() + distance); + } + + // Construction des échantillons + for (float i = T.First(); i < T.Last(); i += pas) + { + tToEval.Add(i); + } + + return (T, tToEval); + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : buildParametrisationTchebycheff // + // semantique : construit la parametrisation basée sur Tchebycheff // + // et les échantillons de temps selon cette parametrisation// + // params : // + // - int nbElem : nombre d'elements de la parametrisation // + // - float pas : pas d'échantillonage // + // sortie : // + // - List T : parametrisation Tchebycheff // + // - List tToEval : echantillon sur la parametrisation // + ////////////////////////////////////////////////////////////////////////// + (List, List) buildParametrisationTchebycheff(int nbElem, float pas) + { + // Vecteur des pas temporels + List T = new List(); + // Echantillonage des pas temporels + List tToEval = new List(); + + // Construction des pas temporels + for (int i = 0; i < X.Count; i++) + { + float value = (float)Math.Cos((2 * i + 1) * Math.PI / (2 * (X.Count - 1) + 2)); + T.Add(value); + } + + // Construction des échantillons + for (float i = T.First(); i > T.Last(); i -= pas) + { + tToEval.Add(i); + } + + return (T, tToEval); + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : applyLagrangeParametrisation // + // semantique : applique la subdivion de Lagrange aux points (x,y) // + // placés en paramètres en suivant les temps indiqués // + // params : // + // - List X : liste des abscisses des points // + // - List Y : liste des ordonnées des points // + // - List T : temps de la parametrisation // + // - List tToEval : échantillon des temps sur T // + // sortie : rien // + ////////////////////////////////////////////////////////////////////////// + void applyLagrangeParametrisation(List X, List Y, List T, List tToEval) + { + for (int i = 0; i < tToEval.Count; ++i) + { + // Calcul de xpoint et ypoint + float t = tToEval[i]; + float xpoint = lagrange(t, T, X); + float ypoint = lagrange(t, T, Y); + Vector3 pos = new Vector3(xpoint, 0.0f, ypoint); + P2DRAW.Add(pos); + } + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : applyNevilleParametrisation // + // semantique : applique la subdivion de Neville aux points (x,y) // + // placés en paramètres en suivant les temps indiqués // + // params : // + // - List X : liste des abscisses des points // + // - List Y : liste des ordonnées des points // + // - List T : temps de la parametrisation // + // - List tToEval : échantillon des temps sur T // + // sortie : rien // + ////////////////////////////////////////////////////////////////////////// + void applyNevilleParametrisation(List X, List Y, List T, List tToEval) + { + for (int i = 0; i < tToEval.Count; ++i) + { + // Appliquer neville a l'echantillon i + float t = tToEval[i]; + Vector2 v = neville(X, Y, T, t); + Vector3 pos = new Vector3(v[0], 0.0f, v[1]); + P2DRAW.Add(pos); + } + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : lagrange // + // semantique : calcule la valeur en x du polynome de Lagrange passant // + // par les points de coordonnées (X,Y) // + // params : // + // - float x : point dont on cherche l'ordonnée // + // - List X : liste des abscisses des points // + // - List Y : liste des ordonnées des points // + // sortie : valeur en x du polynome de Lagrange passant // + // par les points de coordonnées (X,Y) // + ////////////////////////////////////////////////////////////////////////// + private float lagrange(float x, List X, List Y) + { + float sum = 0.0f; + int n = X.Count; + + for (int j = 0; j < n; j++) + { + float prod = 1.0f; + for (int i = 0; i < n; i++) + { + if (i != j) + { + prod *= (x - X[i]) / (X[j] - X[i]); + } + } + sum += Y[j] * prod; + } + + return sum; + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : neville // + // semantique : calcule le point atteint par la courbe en t sachant // + // qu'elle passe par les (X,Y) en T // + // params : // + // - List X : liste des abscisses des points // + // - List Y : liste des ordonnées des points // + // - List T : liste des temps de la parametrisation // + // - t : temps ou on cherche le point de la courbe // + // sortie : point atteint en t de la courbe // + ////////////////////////////////////////////////////////////////////////// + private Vector2 neville(List X, List Y, List T, float t) + { + int n = X.Count; + List nevX = new List(X); + List nevY = new List(Y); + + for (int i = n - 1; i > 0; i--) + { + for (int j = 0; j < i; j++) + { + nevX[j] = (T[j + n - i] - t) / (T[j + n - i] - T[j]) * nevX[j] + (t - T[j]) / (T[j + n - i] - T[j]) * nevX[j + 1]; + nevY[j] = (T[j + n - i] - t) / (T[j + n - i] - T[j]) * nevY[j] + (t - T[j]) / (T[j + n - i] - T[j]) * nevY[j + 1]; + } + } + + return new Vector2(nevX.First(), nevY.First()); + } + + ////////////////////////////////////////////////////////////////////////// + //////////////////////// NE PAS TOUCHER !!! ////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + void Update() + { + if (Input.GetKeyDown(KeyCode.Return)) + { + var ListePointsCliques = GameObject.Find("Donnees").GetComponent(); + List T = new List(); + List tToEval = new List(); + + if (ListePointsCliques.X.Count > 0) + { + X = ListePointsCliques.X; + Y = ListePointsCliques.Y; + + if (InterpolationType == EInterpolationType.Lagrange) + { + switch (ParametrisationType) + { + case EParametrisationType.None: + List x = new List(); + List y = new List(); + var xmax = 10.0f; + var xcur = -10.0f; + while (xcur < xmax) + { + xcur += pas; + x.Add(xcur); + } + for (int i = 0; i < x.Count; i++) + { + y.Add(lagrange(x[i], X, Y)); + } + + for (int i = 0; i < x.Count; ++i) + { + Vector3 pos = new Vector3(x[i], 0.0f, y[i]); + P2DRAW.Add(pos); + } + break; + case EParametrisationType.Reguliere: + (T, tToEval) = buildParametrisationReguliere(X.Count, pas); + applyLagrangeParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.Distance: + (T, tToEval) = buildParametrisationDistance(X.Count, pas); + applyLagrangeParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.RacineDistance: + (T, tToEval) = buildParametrisationRacineDistance(X.Count, pas); + applyLagrangeParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.Tchebytcheff: + (T, tToEval) = buildParametrisationTchebycheff(X.Count, pas); + applyLagrangeParametrisation(X, Y, T, tToEval); + break; + } + + } + else if (InterpolationType == EInterpolationType.Neville) + { + + switch (ParametrisationType) + { + case EParametrisationType.Reguliere: + (T, tToEval) = buildParametrisationReguliere(X.Count, pas); + applyNevilleParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.Distance: + (T, tToEval) = buildParametrisationDistance(X.Count, pas); + applyNevilleParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.RacineDistance: + (T, tToEval) = buildParametrisationRacineDistance(X.Count, pas); + applyNevilleParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.Tchebytcheff: + (T, tToEval) = buildParametrisationTchebycheff(X.Count, pas); + applyNevilleParametrisation(X, Y, T, tToEval); + break; + case EParametrisationType.None: + text.text = "Vous devez choisir un type de parametrisation pour utiliser Neville"; + break; + } + } + } + } + } + + ////////////////////////////////////////////////////////////////////////// + //////////////////////// NE PAS TOUCHER !!! ////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + void OnDrawGizmosSelected() + { + Gizmos.color = Color.blue; + for (int i = 0; i < P2DRAW.Count - 1; ++i) + { + Gizmos.DrawLine(P2DRAW[i], P2DRAW[i + 1]); + } + } +} diff --git a/TP1/Assets/Scripts/Utils/InterpolateurDeSurface.cs b/TP1/Assets/Scripts/Utils/InterpolateurDeSurface.cs new file mode 100644 index 0000000..b592cda --- /dev/null +++ b/TP1/Assets/Scripts/Utils/InterpolateurDeSurface.cs @@ -0,0 +1,199 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System; +using UnityEngine.UI; + +public class InterpolateurDeSurface : MonoBehaviour +{ + public GameObject particle; + public float[] X; + public float[,] Y; + public float[] Z; + public bool autoGenerateGrid; + public float pas; + private List> ListePoints = new List>(); + + void Start() + { + if (true) + { + int n = 5; + + X = new float[n]; + Y = new float[n, n]; + Z = new float[n]; + + for (int i = 0; i < n; i++) + { + X[i] = (float)i / (float)(n - 1); + Z[i] = (float)i / (float)(n - 1); + } + + for (int i = 0; i < n; i++) + { + float XC2 = (X[i] - (1.0f / 2.0f)) * (X[i] - (1.0f / 2.0f)); + + for (int j = 0; j < n; j++) + { + float ZC2 = (Z[j] - (1.0f / 2.0f)) * (Z[j] - (1.0f / 2.0f)); + + Y[i, j] = (float)Math.Exp(-(XC2 + ZC2)); + Instantiate(particle, new Vector3(X[i], Y[i, j], Z[j]), Quaternion.identity); + } + } + } + else + { + + } + } + + void Update() + { + if (Input.GetKeyDown(KeyCode.Return)) + { + List T = new List(); + List tToEval = new List(); + + (T, tToEval) = buildParametrisationReguliere(X.Count(), pas); + applyLagrangeParametrisation(X, Y, Z, T, tToEval); + } + } + + (List, List) buildParametrisationReguliere(int nbElem, float pas) + { + // Vecteur des pas temporels + List T = new List(); + // Echantillonage des pas temporels + List tToEval = new List(); + + // Construction des pas temporels + for (int i = 0; i < nbElem; i++) + { + T.Add(i); + } + + // Construction des échantillons + for (float t = 0; t < T.Last(); t += pas) + { + tToEval.Add(t); + } + + return (T, tToEval); + } + + void applyLagrangeParametrisation(float[] X, float[,] Y, float[] Z, List T, List tToEval) + { + ListePoints.Clear(); + + float[] newX = new float[tToEval.Count()]; + float[,] newY_interm = new float[tToEval.Count(), Z.Count()]; + float[,] newY = new float[tToEval.Count(), tToEval.Count()]; + float[] newZ = new float[tToEval.Count()]; + + for (int i = 0; i < tToEval.Count(); i++) + { + float t = tToEval[i]; + + newX[i] = lagrange(t, T, X); + newZ[i] = lagrange(t, T, Z); + } + + + + for (int k = 0; k < Z.Count(); k++) + { + float[] Yk = GetColumn(Y, k); + + for (int i = 0; i < tToEval.Count(); i++) + { + float t = tToEval[i]; + + float val = lagrange(t, T, Yk); + newY[i, k * (int)(1 / pas)] = val; + newY_interm[i, k] = val; + } + } + + // for (int k = 0; k < tToEval.Count(); k++) + // { + // float[] Yk = GetRow(newY_interm, k); + + // for (int i = 0; i < tToEval.Count(); i++) + // { + // float t = tToEval[i]; + + // newY[k, i] = lagrange(t, T, Yk); + // } + // } + + for (int i = 0; i < tToEval.Count(); i++) + { + List ListePoints_i = new List(); + + for (int j = 0; j < tToEval.Count(); j++) + { + ListePoints_i.Add(new Vector3(newX[i], newY[i, j], newZ[j])); + } + + ListePoints.Add(ListePoints_i); + } + + } + + private float lagrange(float x, List X, float[] Y) + { + float sum = 0; + for (int i = 0; i < X.Count; i++) + { + float xi = X[i]; + + float prod = 1; + for (int j = 0; j < X.Count; j++) + { + float xj = X[j]; + + if (xi != xj) + { + prod *= (x - xj) / (xi - xj); + } + } + + sum += prod * Y[i]; + } + return sum; + } + + void OnDrawGizmosSelected() + { + Gizmos.color = Color.blue; + if (autoGenerateGrid) + { + + for (int j = 0; j < ListePoints.Count; ++j) + { + for (int i = 0; i < ListePoints[j].Count - 1; ++i) + { + Gizmos.DrawLine(ListePoints[j][i], ListePoints[j][i + 1]); + } + } + } + } + + + public float[] GetColumn(float[,] matrix, int columnNumber) + { + return Enumerable.Range(0, matrix.GetLength(0)) + .Select(x => matrix[x, columnNumber]) + .ToArray(); + } + + public float[] GetRow(float[,] matrix, int rowNumber) + { + return Enumerable.Range(0, matrix.GetLength(1)) + .Select(x => matrix[rowNumber, x]) + .ToArray(); + } +} \ No newline at end of file diff --git a/TP1/Assets/Scripts/Utils/Points.cs b/TP1/Assets/Scripts/Utils/Points.cs new file mode 100644 index 0000000..32591ad --- /dev/null +++ b/TP1/Assets/Scripts/Utils/Points.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Permet de stocker les coordonnees des points selectionnes a l'écran en vue d'un traitement +public class Points : MonoBehaviour +{ + // Objet qui sera instancie sur un clic + public GameObject particle; + // Listes memoires des coordonnees + public List X = new List(); + public List Y = new List(); + + // Methode appellee a chaque pas de simulation + void Update() + { + // Position de la souris + Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f); + + // Si on clique + if (Input.GetButtonDown("Fire1")) + { + Vector3 wordPos; + Ray ray = Camera.main.ScreenPointToRay(mousePos); + RaycastHit hit; + if (Physics.Raycast(ray, out hit, 1000f)) + { + wordPos = hit.point; + } + else + { + wordPos = Camera.main.ScreenToWorldPoint(mousePos); + } + // On instancie un point sur le plan + Instantiate(particle, wordPos, Quaternion.identity); + X.Add(wordPos.x); + Y.Add(wordPos.z); + } + } +} diff --git a/TP1/Assets/Scripts/Utils/Zoom.cs b/TP1/Assets/Scripts/Utils/Zoom.cs new file mode 100644 index 0000000..3ddc16f --- /dev/null +++ b/TP1/Assets/Scripts/Utils/Zoom.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Script qui permet de zoomer avec la molette de la souris +public class Zoom : MonoBehaviour +{ + + private float scrollSpeed = 4.0f; + private float cameraDistance = 0f; + + void Update() + { + cameraDistance = Input.GetAxis("Mouse ScrollWheel") * scrollSpeed; + transform.Translate(new Vector3(0,0, cameraDistance)); + } +} diff --git a/TP2/.vscode/settings.json b/TP2/.vscode/settings.json new file mode 100644 index 0000000..4edd970 --- /dev/null +++ b/TP2/.vscode/settings.json @@ -0,0 +1,56 @@ +{ + "files.exclude": + { + "**/.DS_Store":true, + "**/.git":true, + "**/.gitignore":true, + "**/.gitmodules":true, + "**/*.booproj":true, + "**/*.pidb":true, + "**/*.suo":true, + "**/*.user":true, + "**/*.userprefs":true, + "**/*.unityproj":true, + "**/*.dll":true, + "**/*.exe":true, + "**/*.pdf":true, + "**/*.mid":true, + "**/*.midi":true, + "**/*.wav":true, + "**/*.gif":true, + "**/*.ico":true, + "**/*.jpg":true, + "**/*.jpeg":true, + "**/*.png":true, + "**/*.psd":true, + "**/*.tga":true, + "**/*.tif":true, + "**/*.tiff":true, + "**/*.3ds":true, + "**/*.3DS":true, + "**/*.fbx":true, + "**/*.FBX":true, + "**/*.lxo":true, + "**/*.LXO":true, + "**/*.ma":true, + "**/*.MA":true, + "**/*.obj":true, + "**/*.OBJ":true, + "**/*.asset":true, + "**/*.cubemap":true, + "**/*.flare":true, + "**/*.mat":true, + "**/*.meta":true, + "**/*.prefab":true, + "**/*.unity":true, + "build/":true, + "Build/":true, + "Library/":true, + "library/":true, + "obj/":true, + "Obj/":true, + "ProjectSettings/":true, + "temp/":true, + "Temp/":true + } +} \ No newline at end of file diff --git a/TP2/Assets/Scripts/Bernstein.cs b/TP2/Assets/Scripts/Bernstein.cs new file mode 100644 index 0000000..c4187a5 --- /dev/null +++ b/TP2/Assets/Scripts/Bernstein.cs @@ -0,0 +1,108 @@ +using System.Collections; +using System.Collections.Generic; +using System; +using UnityEngine; +using UnityEngine.UI; + +////////////////////////////////////////////////////////////////////////// +///////////////// Classe qui gère les polys de Bernstein ///////////////// +////////////////////////////////////////////////////////////////////////// +public class Bernstein : MonoBehaviour +{ + + // Nombre de polynmes de Bernstein a dessiner + public int nombrePolynomesBernstein = 1; + // Slider : permet de choisir le nombre de poly depuis la simulation + public Slider slider; + // pas d'échantillonage pour affichage + private float pas = 0.01f; + // Liste des couleurs pour affichage + private Color[] listeCouleurs = new Color[] { Color.blue, Color.cyan, Color.green, Color.magenta, Color.red, Color.yellow }; + // Listes des différents points composants les polynomes de Bernstein + // ListePoints[0] : liste des points composant le poly de Bernstein 0 sur n-1 + private List> ListePoints = new List>(); + + float BernsteinValue(int i, int m, float u) + { + long iParmisM = KparmiN(i, m); + double value = iParmisM * Math.Pow(u, i) * Math.Pow(1 - u, m - i); + return (float)value; + } + + /////////////////////////////////////////////////////////////////////////// + // fonction : buildPolysBernstein // + // semantique : remplit le vecteur ListePoints avec les listes des points// + // composant les polys de Bernstein // + // params : aucun // + // sortie : aucune // + /////////////////////////////////////////////////////////////////////////// + void buildPolysBernstein() + { + for (int i = 0; i <= nombrePolynomesBernstein; i++) + { + List courbe = new List(); + for (float x = 0; x < 1; x += pas) + { + Vector2 vector = new Vector2(x, BernsteinValue(i, nombrePolynomesBernstein, x)); + courbe.Add(vector); + } + ListePoints.Add(courbe); + } + } + + //////////////////////////////////////////////////////////////////////////// + // Fonction KparmiN // + // Semantique : etant donnés k et n, calcule k parmi n // + // Entrees : - int k // + // - int n // + // Sortie : k parmi n // + //////////////////////////////////////////////////////////////////////////// + + long KparmiN(int k, int n) + { + decimal result = 1; + for (int i = 1; i <= k; i++) + { + result *= n - (k - i); + result /= i; + } + return (long)result; + } + + //////////////////////////////////////////////////////////////////////////// + ////////////////////////// NE PAS TOUCHER ////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + void Start() + { + buildPolysBernstein(); + } + + void Update() + { + if (slider.value != nombrePolynomesBernstein) + { + nombrePolynomesBernstein = (int)slider.value; + ListePoints.Clear(); + buildPolysBernstein(); + } + } + + void OnDrawGizmosSelected() + { + float profondeur = -2.0f; + for (int i = 0; i < ListePoints.Count; ++i) + { + Gizmos.color = listeCouleurs[i % listeCouleurs.Length]; + List listePointsPolynome = ListePoints[i]; + for (int j = 0; j < listePointsPolynome.Count - 1; ++j) + { + Vector3 p1 = new Vector3(listePointsPolynome[j].x, profondeur, listePointsPolynome[j].y); + Vector3 p2 = new Vector3(listePointsPolynome[j + 1].x, profondeur, listePointsPolynome[j + 1].y); + Gizmos.DrawLine(p1, p2); + } + } + Gizmos.color = Color.black; + Gizmos.DrawLine(new Vector3(1.0f, profondeur, 0.0f), new Vector3(0.0f, profondeur, 0.0f)); + Gizmos.DrawLine(new Vector3(0.0f, profondeur, 0.0f), new Vector3(0.0f, profondeur, 1.0f)); + } +} diff --git a/TP2/Assets/Scripts/CalculHodographe.cs b/TP2/Assets/Scripts/CalculHodographe.cs new file mode 100755 index 0000000..b9b9358 --- /dev/null +++ b/TP2/Assets/Scripts/CalculHodographe.cs @@ -0,0 +1,159 @@ +using System; +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CalculHodographe : MonoBehaviour +{ + // Nombre de subdivision dans l'algo de DCJ + public int NombreDeSubdivision = 3; + // Liste des points composant la courbe de l'hodographe + private List ListePoints = new List(); + // Donnees i.e. points cliqués + + public GameObject Donnees; + public GameObject particle; + + ////////////////////////////////////////////////////////////////////////// + // fonction : DeCasteljauSub // + // semantique : renvoie la liste des points composant la courbe // + // approximante selon un nombre de subdivision données // + // params : - List X : abscisses des point de controle // + // - List Y : odronnees des point de controle // + // - int nombreDeSubdivision : nombre de subdivision // + // sortie : // + // - (List, List) : liste des abscisses et liste // + // des ordonnées des points composant la courbe // + ////////////////////////////////////////////////////////////////////////// + (List, List) DeCasteljauSub(List X, List Y, int nombreDeSubdivision) + { + if (nombreDeSubdivision == 0) + { // condition de terminaison + return (X, Y); + } + else + { // récurrence + List x_gauche = new List(); + List y_gauche = new List(); + + List x_droite = new List(); + List y_droite = new List(); + + // copie de X et Y pour la subdivision + int n = X.Count; + List nevX = new List(X); + List nevY = new List(Y); + + // ajout des premiers points + x_gauche.Add(X[0]); + y_gauche.Add(Y[0]); + + for (int i = n - 1; i > 0; i--) + { + for (int j = 0; j < i; j++) + { + nevX[j] = 0.5f * nevX[j] + 0.5f * nevX[j + 1]; + nevY[j] = 0.5f * nevY[j] + 0.5f * nevY[j + 1]; + } + // ajouts de la subdiv de gauche + x_gauche.Add(nevX[0]); + y_gauche.Add(nevY[0]); + } + + // ajout de la subdiv de droite + for (int i = 0; i < n; i++) + { + x_droite.Add(nevX[i]); + y_droite.Add(nevY[i]); + } + + // déclaration des nouvelles listes de points + List x_new_gauche = new List(); + List y_new_gauche = new List(); + List x_new_droite = new List(); + List y_new_droite = new List(); + + // appels récurrents + (x_new_gauche, y_new_gauche) = DeCasteljauSub(x_gauche, y_gauche, nombreDeSubdivision - 1); + (x_new_droite, y_new_droite) = DeCasteljauSub(x_droite, y_droite, nombreDeSubdivision - 1); + + // on enlève le point en commun dans une des deux listes + x_new_droite.RemoveAt(0); + y_new_droite.RemoveAt(0); + + return (x_new_gauche.Concat(x_new_droite).ToList(), y_new_gauche.Concat(y_new_droite).ToList()); + } + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : Hodographe // + // semantique : renvoie la liste des vecteurs vitesses entre les paires // + // consécutives de points de controle // + // approximante selon un nombre de subdivision données // + // params : - List X : abscisses des point de controle // + // - List Y : odronnees des point de controle // + // - float Cx : offset d'affichage en x // + // - float Cy : offset d'affichage en y // + // sortie : // + // - (List, List) : listes composantes des // + // vecteurs vitesses sous la forme (Xs,Ys) // + ////////////////////////////////////////////////////////////////////////// + (List, List) Hodographe(List X, List Y, float Cx = 1.5f, float Cy = 0.0f) + { + List XHodo = new List(); + List YHodo = new List(); + + for (int i = 0; i < X.Count - 1; i++) + { + XHodo.Add(X[i + 1] - X[i] + Cx); + YHodo.Add(Y[i + 1] - Y[i] + Cy); + } + + return DeCasteljauSub(XHodo, YHodo, 3); + } + + ////////////////////////////////////////////////////////////////////////// + //////////////////////////// NE PAS TOUCHER ////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + void Start() + { + Instantiate(particle, new Vector3(1.5f, -4.0f, 0.0f), Quaternion.identity); + } + + void Update() + { + // if (Input.GetKeyDown(KeyCode.Return)) + // { + + ListePoints.Clear(); + + var ListePointsCliques = GameObject.Find("Donnees").GetComponent(); + if (ListePointsCliques.X.Count > 1) + { + List XSubdivision = new List(); + List YSubdivision = new List(); + List dX = new List(); + List dY = new List(); + + (dX, dY) = Hodographe(ListePointsCliques.X, ListePointsCliques.Y); + + (XSubdivision, YSubdivision) = DeCasteljauSub(dX, dY, NombreDeSubdivision); + for (int i = 0; i < XSubdivision.Count; ++i) + { + ListePoints.Add(new Vector3(XSubdivision[i], -4.0f, YSubdivision[i])); + } + } + + // } + } + + void OnDrawGizmosSelected() + { + Gizmos.color = Color.blue; + for (int i = 0; i < ListePoints.Count - 1; ++i) + { + Gizmos.DrawLine(ListePoints[i], ListePoints[i + 1]); + } + } +} diff --git a/TP2/Assets/Scripts/DeCasteljauEvaluation.cs b/TP2/Assets/Scripts/DeCasteljauEvaluation.cs new file mode 100644 index 0000000..6840e11 --- /dev/null +++ b/TP2/Assets/Scripts/DeCasteljauEvaluation.cs @@ -0,0 +1,119 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +////////////////////////////////////////////////////////////////////////// +///////////////// Classe qui gère l'évaluation via DCJ /////////////////// +////////////////////////////////////////////////////////////////////////// +public class DeCasteljauEvaluation : MonoBehaviour +{ + // Pas d'échantillonage construire la parametrisation + public float pas = 1 / 100; + // Liste des points composant la courbe + private List ListePoints = new List(); + // Donnees i.e. points cliqués + public GameObject Donnees; + // Coordonnees des points composant le polygone de controle + private List PolygoneControleX = new List(); + private List PolygoneControleY = new List(); + + ////////////////////////////////////////////////////////////////////////// + // fonction : buildEchantillonnage // + // semantique : construit un échantillonnage regulier // + // params : aucun // + // sortie : // + // - List tToEval : échantillonnage regulier // + ////////////////////////////////////////////////////////////////////////// + List buildEchantillonnage() + { + List tToEval = new List(); + + for (float t = 0; t < 1; t += pas) + { + tToEval.Add(t); + } + + return tToEval; + } + + ////////////////////////////////////////////////////////////////////////// + // fonction : DeCasteljau // + // semantique : renvoie le point approxime via l'aglgorithme de DCJ // + // pour une courbe définie par les points de controle // + // (X,Y) à l'instant t // + // params : - List X : abscisses des point de controle // + // - List Y : odronnees des point de controle // + // - float t : temps d'approximation // + // sortie : // + // - Vector2 : point atteint au temps t // + ////////////////////////////////////////////////////////////////////////// + Vector2 DeCasteljau(List X, List Y, float t) + { + int n = X.Count; + List nevX = new List(X); + List nevY = new List(Y); + + for (int i = n - 1; i > 0; i--) + { + for (int j = 0; j < i; j++) + { + nevX[j] = (1 - t) * nevX[j] + t * nevX[j + 1]; + nevY[j] = (1 - t) * nevY[j] + t * nevY[j + 1]; + } + } + + return new Vector2(nevX[0], nevY[0]); + } + + ////////////////////////////////////////////////////////////////////////// + //////////////////////////// NE PAS TOUCHER ////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + + void Start() + { + + } + + void Update() + { + // if (Input.GetKeyDown(KeyCode.Return)) + // { + PolygoneControleX.Clear(); + PolygoneControleY.Clear(); + ListePoints.Clear(); + + var ListePointsCliques = GameObject.Find("Donnees").GetComponent(); + if (ListePointsCliques.X.Count > 0) + { + for (int i = 0; i < ListePointsCliques.X.Count; ++i) + { + PolygoneControleX.Add(ListePointsCliques.X[i]); + PolygoneControleY.Add(ListePointsCliques.Y[i]); + } + + List T = buildEchantillonnage(); + Vector2 point = new Vector2(); + foreach (float t in T) + { + point = DeCasteljau(ListePointsCliques.X, ListePointsCliques.Y, t); + ListePoints.Add(new Vector3(point.x, -4.0f, point.y)); + } + } + // } + } + + void OnDrawGizmosSelected() + { + Gizmos.color = Color.red; + for (int i = 0; i < PolygoneControleX.Count - 1; ++i) + { + Gizmos.DrawLine(new Vector3(PolygoneControleX[i], -4.0f, PolygoneControleY[i]), new Vector3(PolygoneControleX[i + 1], -4.0f, PolygoneControleY[i + 1])); + } + + Gizmos.color = Color.blue; + for (int i = 0; i < ListePoints.Count - 1; ++i) + { + Gizmos.DrawLine(ListePoints[i], ListePoints[i + 1]); + } + } +} diff --git a/TP2/Assets/Scripts/DeCasteljauSubdivision.cs b/TP2/Assets/Scripts/DeCasteljauSubdivision.cs new file mode 100755 index 0000000..ecf0f37 --- /dev/null +++ b/TP2/Assets/Scripts/DeCasteljauSubdivision.cs @@ -0,0 +1,146 @@ +using System; +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +////////////////////////////////////////////////////////////////////////// +///////////////// Classe qui gère la subdivision via DCJ ///////////////// +////////////////////////////////////////////////////////////////////////// +public class DeCasteljauSubdivision : MonoBehaviour +{ + // Pas d'échantillonage pour affichage + public float pas = 1 / 100; + // Nombre de subdivision dans l'algo de DCJ + public int NombreDeSubdivision = 10; + // Liste des points composant la courbe + private List ListePoints = new List(); + // Donnees i.e. points cliqués + public GameObject Donnees; + // Coordonnees des points composant le polygone de controle + private List PolygoneControleX = new List(); + private List PolygoneControleY = new List(); + + ////////////////////////////////////////////////////////////////////////// + // fonction : DeCasteljauSub // + // semantique : renvoie la liste des points composant la courbe // + // approximante selon un nombre de subdivision données // + // params : - List X : abscisses des point de controle // + // - List Y : odronnees des point de controle // + // - int nombreDeSubdivision : nombre de subdivision // + // sortie : // + // - (List, List) : liste des abscisses et liste // + // des ordonnées des points composant la courbe // + ////////////////////////////////////////////////////////////////////////// + (List, List) DeCasteljauSub(List X, List Y, int nombreDeSubdivision) + { + if (nombreDeSubdivision == 0) + { // condition de terminaison + return (X, Y); + } + else + { // récurrence + List x_gauche = new List(); + List y_gauche = new List(); + + List x_droite = new List(); + List y_droite = new List(); + + // copie de X et Y pour la subdivision + int n = X.Count; + List nevX = new List(X); + List nevY = new List(Y); + + // ajout des premiers points + x_gauche.Add(X[0]); + y_gauche.Add(Y[0]); + + for (int i = n - 1; i > 0; i--) + { + for (int j = 0; j < i; j++) + { + nevX[j] = 0.5f * nevX[j] + 0.5f * nevX[j + 1]; + nevY[j] = 0.5f * nevY[j] + 0.5f * nevY[j + 1]; + } + // ajouts de la subdiv de gauche + x_gauche.Add(nevX[0]); + y_gauche.Add(nevY[0]); + } + + // ajout de la subdiv de droite + for (int i = 0; i < n; i++) + { + x_droite.Add(nevX[i]); + y_droite.Add(nevY[i]); + } + + // déclaration des nouvelles listes de points + List x_new_gauche = new List(); + List y_new_gauche = new List(); + List x_new_droite = new List(); + List y_new_droite = new List(); + + // appels récurrents + (x_new_gauche, y_new_gauche) = DeCasteljauSub(x_gauche, y_gauche, nombreDeSubdivision - 1); + (x_new_droite, y_new_droite) = DeCasteljauSub(x_droite, y_droite, nombreDeSubdivision - 1); + + // on enlève le point en commun dans une des deux listes + x_new_droite.RemoveAt(0); + y_new_droite.RemoveAt(0); + + return (x_new_gauche.Concat(x_new_droite).ToList(), y_new_gauche.Concat(y_new_droite).ToList()); + } + } + + ////////////////////////////////////////////////////////////////////////// + //////////////////////////// NE PAS TOUCHER ////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + void Start() + { + + } + + void Update() + { + // if (Input.GetKeyDown(KeyCode.Return)) + // { + + PolygoneControleX.Clear(); + PolygoneControleY.Clear(); + ListePoints.Clear(); + + var ListePointsCliques = GameObject.Find("Donnees").GetComponent(); + if (ListePointsCliques.X.Count > 0) + { + for (int i = 0; i < ListePointsCliques.X.Count; ++i) + { + PolygoneControleX.Add(ListePointsCliques.X[i]); + PolygoneControleY.Add(ListePointsCliques.Y[i]); + } + List XSubdivision = new List(); + List YSubdivision = new List(); + + (XSubdivision, YSubdivision) = DeCasteljauSub(ListePointsCliques.X, ListePointsCliques.Y, NombreDeSubdivision); + for (int i = 0; i < XSubdivision.Count; ++i) + { + ListePoints.Add(new Vector3(XSubdivision[i], -4.0f, YSubdivision[i])); + } + } + // } + } + + void OnDrawGizmosSelected() + { + Gizmos.color = Color.red; + for (int i = 0; i < PolygoneControleX.Count - 1; ++i) + { + Gizmos.DrawLine(new Vector3(PolygoneControleX[i], -4.0f, PolygoneControleY[i]), new Vector3(PolygoneControleX[i + 1], -4.0f, PolygoneControleY[i + 1])); + } + + Gizmos.color = Color.blue; + for (int i = 0; i < ListePoints.Count - 1; ++i) + { + Gizmos.DrawLine(ListePoints[i], ListePoints[i + 1]); + } + } +} diff --git a/TP2/Assets/Scripts/Points.cs b/TP2/Assets/Scripts/Points.cs new file mode 100755 index 0000000..96eebe1 --- /dev/null +++ b/TP2/Assets/Scripts/Points.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Permet de stocker les coordonnees des points selectionnes a l'écran en vue d'un traitement +public class Points : MonoBehaviour +{ + // Objet qui sera instancie sur un clic + public GameObject particle; + // Listes memoires des coordonnees + public List X = new List(); + public List Y = new List(); + + // Methode appellee au debut du programme + void Start() + { + + } + + // Methode appellee a chaque pas de simulation + void Update() + { + Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f); + + if (Input.GetButtonDown("Fire1")) + { + Vector3 wordPos; + Ray ray = Camera.main.ScreenPointToRay(mousePos); + RaycastHit hit; + if (Physics.Raycast(ray, out hit, 1000f)) + { + wordPos = hit.point; + } + else + { + wordPos = Camera.main.ScreenToWorldPoint(mousePos); + } + Instantiate(particle, wordPos, Quaternion.identity); + X.Add(wordPos.x); + Y.Add(wordPos.z); + } + } +} diff --git a/TP2/Assets/Scripts/SurfaceBezierTriangulaire.cs b/TP2/Assets/Scripts/SurfaceBezierTriangulaire.cs new file mode 100644 index 0000000..a8e20eb --- /dev/null +++ b/TP2/Assets/Scripts/SurfaceBezierTriangulaire.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; + +public class SurfaceBezierTriangulaire : MonoBehaviour +{ + + void Start() + { + + } + + void Update() + { + + } + + void OnDrawGizmosSelected() + { + Gizmos.color = Color.blue; + } +} diff --git a/TP2/Assets/Scripts/Zoom.cs b/TP2/Assets/Scripts/Zoom.cs new file mode 100644 index 0000000..3ddc16f --- /dev/null +++ b/TP2/Assets/Scripts/Zoom.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Script qui permet de zoomer avec la molette de la souris +public class Zoom : MonoBehaviour +{ + + private float scrollSpeed = 4.0f; + private float cameraDistance = 0f; + + void Update() + { + cameraDistance = Input.GetAxis("Mouse ScrollWheel") * scrollSpeed; + transform.Translate(new Vector3(0,0, cameraDistance)); + } +} diff --git a/TP3/.vscode/settings.json b/TP3/.vscode/settings.json new file mode 100644 index 0000000..4edd970 --- /dev/null +++ b/TP3/.vscode/settings.json @@ -0,0 +1,56 @@ +{ + "files.exclude": + { + "**/.DS_Store":true, + "**/.git":true, + "**/.gitignore":true, + "**/.gitmodules":true, + "**/*.booproj":true, + "**/*.pidb":true, + "**/*.suo":true, + "**/*.user":true, + "**/*.userprefs":true, + "**/*.unityproj":true, + "**/*.dll":true, + "**/*.exe":true, + "**/*.pdf":true, + "**/*.mid":true, + "**/*.midi":true, + "**/*.wav":true, + "**/*.gif":true, + "**/*.ico":true, + "**/*.jpg":true, + "**/*.jpeg":true, + "**/*.png":true, + "**/*.psd":true, + "**/*.tga":true, + "**/*.tif":true, + "**/*.tiff":true, + "**/*.3ds":true, + "**/*.3DS":true, + "**/*.fbx":true, + "**/*.FBX":true, + "**/*.lxo":true, + "**/*.LXO":true, + "**/*.ma":true, + "**/*.MA":true, + "**/*.obj":true, + "**/*.OBJ":true, + "**/*.asset":true, + "**/*.cubemap":true, + "**/*.flare":true, + "**/*.mat":true, + "**/*.meta":true, + "**/*.prefab":true, + "**/*.unity":true, + "build/":true, + "Build/":true, + "Library/":true, + "library/":true, + "obj/":true, + "Obj/":true, + "ProjectSettings/":true, + "temp/":true, + "Temp/":true + } +} \ No newline at end of file diff --git a/TP3/Assets/Scripts/CourbesFermees.cs b/TP3/Assets/Scripts/CourbesFermees.cs new file mode 100644 index 0000000..be5e04c --- /dev/null +++ b/TP3/Assets/Scripts/CourbesFermees.cs @@ -0,0 +1,112 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CourbesFermees : MonoBehaviour +{ + // Liste des points composant la courbe + private List ListePoints = new List(); + // Donnees i.e. points cliqués + public GameObject Donnees; + // Coordonnees des points composant le polygone de controle + private List PolygoneControleX = new List(); + private List PolygoneControleY = new List(); + + // degres des polynomes par morceaux + public int degres = 5; + // nombre d'itération de subdivision + public int nombreIteration = 5; + + ////////////////////////////////////////////////////////////////////////// + // fonction : subdivise // + // semantique : réalise nombreIteration subdivision pour des polys de // + // degres degres // + // params : - List X : abscisses des point de controle // + // - List Y : odronnees des point de controle // + // sortie : // + // - (List, List) : points de la courbe // + ////////////////////////////////////////////////////////////////////////// + (List, List) subdivise(List X, List Y) + { + List Xold = new List(X); + List Yold = new List(Y); + + List XResult = new List(); + List YResult = new List(); + + for (int d = 1; d <= degres; d++) + { + XResult = new List(); + YResult = new List(); + + for (int i = 0; i < Xold.Count; i++) + { + if (d != degres) + { + XResult.Add(Xold[i]); + YResult.Add(Yold[i]); + } + + XResult.Add((Xold[(i + 1) % Xold.Count] + Xold[i]) / 2); + YResult.Add((Yold[(i + 1) % Yold.Count] + Yold[i]) / 2); + } + + Xold = new List(XResult); + Yold = new List(YResult); + } + + return (Xold, Yold); + } + + ////////////////////////////////////////////////////////////////////////// + //////////////////////////// NE PAS TOUCHER ////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + + void Update() + { + if (Input.GetKeyDown(KeyCode.Return)) + { + var ListePointsCliques = GameObject.Find("Donnees").GetComponent(); + if (ListePointsCliques.X.Count > 0) + { + for (int i = 0; i < ListePointsCliques.X.Count; ++i) + { + PolygoneControleX.Add(ListePointsCliques.X[i]); + PolygoneControleY.Add(ListePointsCliques.Y[i]); + } + + List Xres = new List(); + List Yres = new List(); + + (Xres, Yres) = subdivise(ListePointsCliques.X, ListePointsCliques.Y); + for (int i = 0; i < Xres.Count; ++i) + { + ListePoints.Add(new Vector3(Xres[i], -4.0f, Yres[i])); + } + } + } + } + + void OnDrawGizmosSelected() + { + Gizmos.color = Color.red; + for (int i = 0; i < PolygoneControleX.Count - 1; ++i) + { + Gizmos.DrawLine(new Vector3(PolygoneControleX[i], -4.0f, PolygoneControleY[i]), new Vector3(PolygoneControleX[i + 1], -4.0f, PolygoneControleY[i + 1])); + } + if (PolygoneControleX.Count > 0) + { + Gizmos.DrawLine(new Vector3(PolygoneControleX[PolygoneControleX.Count - 1], -4.0f, PolygoneControleY[PolygoneControleY.Count - 1]), new Vector3(PolygoneControleX[0], -4.0f, PolygoneControleY[0])); + } + + Gizmos.color = Color.blue; + for (int i = 0; i < ListePoints.Count - 1; ++i) + { + Gizmos.DrawLine(ListePoints[i], ListePoints[i + 1]); + } + if (ListePoints.Count > 0) + { + Gizmos.DrawLine(ListePoints[ListePoints.Count - 1], ListePoints[0]); + } + } +} diff --git a/TP3/Assets/Scripts/Points.cs b/TP3/Assets/Scripts/Points.cs new file mode 100755 index 0000000..96eebe1 --- /dev/null +++ b/TP3/Assets/Scripts/Points.cs @@ -0,0 +1,43 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Permet de stocker les coordonnees des points selectionnes a l'écran en vue d'un traitement +public class Points : MonoBehaviour +{ + // Objet qui sera instancie sur un clic + public GameObject particle; + // Listes memoires des coordonnees + public List X = new List(); + public List Y = new List(); + + // Methode appellee au debut du programme + void Start() + { + + } + + // Methode appellee a chaque pas de simulation + void Update() + { + Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f); + + if (Input.GetButtonDown("Fire1")) + { + Vector3 wordPos; + Ray ray = Camera.main.ScreenPointToRay(mousePos); + RaycastHit hit; + if (Physics.Raycast(ray, out hit, 1000f)) + { + wordPos = hit.point; + } + else + { + wordPos = Camera.main.ScreenToWorldPoint(mousePos); + } + Instantiate(particle, wordPos, Quaternion.identity); + X.Add(wordPos.x); + Y.Add(wordPos.z); + } + } +} diff --git a/TP3/Assets/Scripts/Zoom.cs b/TP3/Assets/Scripts/Zoom.cs new file mode 100644 index 0000000..3ddc16f --- /dev/null +++ b/TP3/Assets/Scripts/Zoom.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Script qui permet de zoomer avec la molette de la souris +public class Zoom : MonoBehaviour +{ + + private float scrollSpeed = 4.0f; + private float cameraDistance = 0f; + + void Update() + { + cameraDistance = Input.GetAxis("Mouse ScrollWheel") * scrollSpeed; + transform.Translate(new Vector3(0,0, cameraDistance)); + } +}