#include "ptvecteur4fc.h" ///fonction qui initialise un vecteur4f /** @param vect4fOut : vecteur4f à initialiser * @param x : composante du vecteur4f en x * @param y : composante du vecteur4f en y * @param z : composante du vecteur4f en z @param t : composante du vecteur en t (quatrième composante) */ void setPtVect4f(PtVect4fc vect4fOut, float x, float y, float z, float t){ vect4fOut[0] = x; vect4fOut[1] = y; vect4fOut[2] = z; vect4fOut[3] = t; } ///fonction qui initialise la composante x du vect4f passé en paramètre /** @param vect4fOut : vecteur4f à initialiser * @param x : composante du vecteur4f en x */ void setXPtVect4f(PtVect4fc vect4fOut, float x){ vect4fOut[0] = x; } ///fonction qui initialise la composante y du vect4f passé en paramètre /** @param vect4fOut : vecteur4f à initialiser * @param y : composante du vecteur4f en y */ void setYPtVect4f(PtVect4fc vect4fOut, float y){ vect4fOut[1] = y; } ///fonction qui initialise la composante z du vect4f passé en paramètre /** @param vect4fOut : vecteur4f à initialiser * @param z : composante du vecteur4f en z */ void setZPtVect4f(PtVect4fc vect4fOut, float z){ vect4fOut[2] = z; } ///fonction qui initialise la composante t du vect4f passé en paramètre /** @param vect4fOut : vecteur4f à initialiser * @param t : composante du vecteur4f en t */ void setTPtVect4f(PtVect4fc vect4fOut, float t){ vect4fOut[3] = t; } ///fonction qui initialise la n-ième composante du vect4f /** @param vect4fOut : vecteur4f à initialiser * @param n : numèro de la composante (0 -> x, 1 -> y, 2 -> z, 3 -> t) * @param value : valeur de la composante */ void setValueNPtVect4f(PtVect4fc vect4fOut, unsigned int n, float value){ vect4fOut[n] = value; } ///fonction qui initialise la n-ième composante du vect4f si n peut être une composante du vecteur (0 <= n < 4) /** @param vect4fOut : vecteur3f à initialiser * @param n : numèro de la composante (0 -> x, 1 -> y, 2 -> z, 3 -> t) * @param value : valeur de la composante */ void setValueNTestPtVect4f(PtVect4fc vect4fOut, unsigned int n, float value){ if(n < 3) vect4fOut[n] = value; } ///fonction qui calcule vect4fOut = vect4fIn1 - vect4fIn2 /** @param vect4fOut : résultat de l'addition vect4fIn1 + vect4fIn2 (ce vecteur doit dèjà être alloué) * @param vect4fIn1 : vecteur4f * @param vect4fIn2 : vecteur4f */ void addPtVect4f(PtVect4fc vect4fOut, const PtVect4fc vect4fIn1, const PtVect4fc vect4fIn2){ vect4fOut[0] = vect4fIn1[0] + vect4fIn2[0]; vect4fOut[1] = vect4fIn1[1] + vect4fIn2[1]; vect4fOut[2] = vect4fIn1[2] + vect4fIn2[2]; vect4fOut[3] = vect4fIn1[3] + vect4fIn2[3]; } ///fonction qui calcule vect4fOut = vect4fIn1 - vect4fIn2 /** @param vect4fOut : résultat de la soustraction vect4fIn1 - vect4fIn2 (ce vecteur doit dèjà être alloué) * @param vect4fIn1 : vecteur4f * @param vect4fIn2 : vecteur4f */ void subPtVect4f(PtVect4fc vect4fOut, const PtVect4fc vect4fIn1, const PtVect4fc vect4fIn2){ vect4fOut[0] = vect4fIn1[0] - vect4fIn2[0]; vect4fOut[1] = vect4fIn1[1] - vect4fIn2[1]; vect4fOut[2] = vect4fIn1[2] - vect4fIn2[2]; vect4fOut[3] = vect4fIn1[3] - vect4fIn2[3]; } ///fonction qui crée l'opposé de vect4fIn /** @param vect4fOut : devient l'opposé de vect4fIn (ce vecteur doit dèjà être alloué) * @param vect4fIn : vecteur dont on veut l'opposé */ void oppPtVect4f(PtVect4fc vect4fOut, const PtVect4fc vect4fIn){ vect4fOut[0] = -vect4fIn[0]; vect4fOut[1] = -vect4fIn[1]; vect4fOut[2] = -vect4fIn[2]; vect4fOut[3] = -vect4fIn[3]; } ///fonction qui calcul l'opposer de vect4fInOut qui devient son opposer /** @param vect4fInOut : vecteur4f dont on veut caluler l'opposer, sera l'opposer à la fin de la fonction */ void oppSelfPtVect4f(PtVect4fc vect4fInOut){ vect4fInOut[0] = -vect4fInOut[0]; vect4fInOut[1] = -vect4fInOut[1]; vect4fInOut[2] = -vect4fInOut[2]; vect4fInOut[3] = -vect4fInOut[3]; } ///fonction qui multiplie vect4fIn par un scalaire scal /** @param vect4fOut : résultat de la multipication (ce vecteur doit dèjà être alloué) * @param vect4fIn : vecteur4f que l'on veut multiplier * @param scal : scalaire de la multiplication */ void multPtVect4f(PtVect4fc vect4fOut, PtVect4fc vect4fIn, float scal){ vect4fOut[0] = vect4fIn[0]*scal; vect4fOut[1] = vect4fIn[1]*scal; vect4fOut[2] = vect4fIn[2]*scal; vect4fOut[3] = vect4fIn[3]*scal; } ///fonction qui multiplie vect4fInOut par scal et renvoie le résultat dans vect4fInOut /** @param vect4fInOut : vecteur4f qui va être multiplier par scal * @param scal : scalaire de multiplication */ void multSelfPtVect4f(PtVect4fc vect4fInOut, float scal){ vect4fInOut[0] *= scal; vect4fInOut[1] *= scal; vect4fInOut[2] *= scal; } ///fonction qui divise le vecteur4f vect4fIn par un scalaire /** @param vect4fOut : résultat de la division de vect4fIn par scal (ce vecteur doit dèjà être alloué) * @param vect4fIn : vecteur4f que l'on veut diviser * @param scal : scalaire de la division (ne doit pas être 0) * @return vect4fIn/scal */ void divPtVect4f(PtVect4fc vect4fOut, const PtVect4fc vect4fIn, float scal){ vect4fOut[0] = vect4fIn[0]/scal; vect4fOut[1] = vect4fIn[1]/scal; vect4fOut[2] = vect4fIn[2]/scal; vect4fOut[3] = vect4fIn[3]/scal; } ///fonction qui divise vect4fInOut par scal et renvoie le résultat dans vect4fInOut /** @param vect4fInOut : vecteur4f qui va être diviser par scal * @param scal : scalaire de division */ void divSelfPtVect4f(PtVect4fc vect4fInOut, float scal){ vect4fInOut[0] /= scal; vect4fInOut[1] /= scal; vect4fInOut[2] /= scal; vect4fInOut[3] /= scal; } ///fonction qui renvoie le produit scalaire entre vect4fIn1 et vect4fIn2 /** @param vect4fIn1 : vecteur4f * @param vect4fIn2 : vecteur4f * @return produit scalaire vect3fIn1*vect3fIn2 */ float dotProductPtVect4f(const PtVect4fc vect4fIn1, const PtVect4fc vect4fIn2){ return vect4fIn1[0]*vect4fIn2[0] + vect4fIn1[1]*vect4fIn2[1] + vect4fIn1[2]*vect4fIn2[2] + vect4fIn1[3]*vect4fIn2[3]; } ///fonction qui renvoie la norme du vecteur4f /** @param vect4fIn : vecteur dont on veut sa norme * @return norme du vecteur4f */ float normePtVect4f(const PtVect4fc vect4fIn){ return sqrt(vect4fIn[0]*vect4fIn[0] + vect4fIn[1]*vect4fIn[1] + vect4fIn[2]*vect4fIn[2] + vect4fIn[3]*vect4fIn[3]); } ///fonction qui renvoie la norme du vecteur4f au carré /** @param vect4fIn : vecteur dont on veut le carré de sa norme * @return carré de la norme du vecteur4f */ float normeSQRPtVect4f(const PtVect4fc vect4fIn){ return vect4fIn[0]*vect4fIn[0] + vect4fIn[1]*vect4fIn[1] + vect4fIn[2]*vect4fIn[2] + vect4fIn[3]*vect4fIn[3]; } ///fonction qui normalise le vecteur4f vect4fIn /** @param vect4fInOut : vecteur4f qui sera normaliser */ void normaliseSelfPtVect4f(PtVect4fc vect4fInOut){ float norme = normePtVect4f(vect4fInOut); divSelfPtVect4f(vect4fInOut, norme); } ///fonction qui normalise vect4fIn et affecte vect4fOut /** @param vect4fOut : vecteur normal de vect4fIn * @param vect4fIn : vecteur à normaliser */ void normalisePtVect4f(PtVect4fc vect4fOut, const PtVect4fc vect4fIn){ float norme = normePtVect4f(vect4fIn); divPtVect4f(vect4fOut, vect4fIn, norme); } ///fonction qui normalise vect4fIn et affecte vect4fOut si sa norme est non nulle /** @param vect4fOut : vecteur normal de vect4fIn (doit déjà avoir été aloué) * @param vect4fIn : vecteur à normaliser */ void normaliseVect4f0(PtVect4fc vect4fOut, const PtVect4fc vect4fIn){ float norme = normePtVect4f(vect4fIn); if(norme != 0.0) divPtVect4f(vect4fOut, vect4fIn, norme); } ///fonction qui affiche un vecteur4f /** @param vect4f : vecteur4f à afficher */ void printPtVect4f(const PtVect4fc vect4f){ printf("(%f, %f, %f, %f)\n", vect4f[0], vect4f[1], vect4f[2], vect4f[3]); }