-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsphere.cpp
More file actions
45 lines (39 loc) · 1.3 KB
/
Copy pathsphere.cpp
File metadata and controls
45 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <ostream>
#include <cmath>
#include "scene.hpp"
#include "rayon.hpp"
#include "sphere.hpp"
Sphere::Sphere(const float r, const Point c, const Couleur coul, const float reflex)
{
rayon = r;
centre = c;
couleur = coul;
reflexivite = reflex;
}
Sphere::Sphere(const float centerX, const float centerY,const float centerZ,const float r,const int colorR,const int colorG,const int colorB,const float reflx)
{
rayon = r;
centre.setX(centerX);
centre.setY(centerY);
centre.setZ(centerZ);
couleur.setR(colorR);
couleur.setG(colorG);
couleur.setB(colorB);
reflexivite = reflx;
}
void Sphere::afficher(std::ostream &flux) const
{
flux << "SPHERE ::\tposition:" << centre << " rayon:" << rayon << " couleur:" << couleur << " reflexivite" << reflexivite << std::endl;
}
Point Sphere::normale(const Point intersection)
{
Point vNormale = intersection - centre;
vNormale = vNormale/vNormale.norme(); //normalisation du vecteur
return vNormale;
}
bool Sphere::contient(const Point p) const
{
float dist = abs(pow(p.getX() - centre.getX(), 2) + pow(p.getY() - centre.getY(), 2) + pow(p.getZ() - centre.getZ(), 2) - pow(rayon, 2)); //on injecte les coordonnees du point dans l'equation de la sphere
return (dist < 0.005f); //2 floats ne peuvent pas etre egaux donc on teste s'ils sont tres proches
}