Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Sphere.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #ifndef SPHERE_H
17 #define SPHERE_H
18 
19 #include "Shape.h"
20 
24 class Sphere : public Shape
25 {
26 
27 public:
29  Sphere() : Shape()
30  {
31  position = vec3(0.0, 0.0, 0.0);
32  radius = 0.;
33  }
35  Sphere(vec3 pos, decimal r) : Shape()
36  {
37  position = vec3(pos);
38  radius = r;
39 
40  setBBox();
41  }
43  Sphere(Sphere* other) : Shape(other)
44  {
45  position = vec3(other->position);
46  radius = other->radius;
47  box = other->box;
48  }
50  virtual Shape* Clone()
51  {
52  Sphere* newShape = new Sphere(this);
53  return newShape;
54  }
56  Sphere(const Sphere& other) : Shape(other)
57  {
58  position = vec3(other.position);
59  radius = other.radius;
60  box = other.box;
61  }
68  virtual bool getIntersection(Ray& ray, Intersection& inter);
70  void setRadius(decimal _radius)
71  {
72  radius = _radius;
73  setBBox();
74  }
77  {
78  return radius;
79  }
81  void setPosition(const vec3& _position)
82  {
83  position = _position;
84  setBBox();
85  }
88  {
89  return position;
90  }
91  virtual int form()
92  {
93  return SPHERE;
94  }
95 
96 protected:
99 
100  void setBBox()
101  {
104  }
105 };
106 
107 #endif
@ SPHERE
Definition: Shape.h:38
Definition of a bounding box which is aligned along the axis (BBox AABB).
Definition: BBox.h:32
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Definition: Ray.h:38
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
Definition: Shape.h:57
BBox box
Bounding box of the shape.
Definition: Shape.h:210
Sphere Shape.
Definition: Sphere.h:25
vec3 getPosition()
Get the position (center) of the sphere.
Definition: Sphere.h:87
Sphere(const Sphere &other)
Copy constructor.
Definition: Sphere.h:56
Sphere(vec3 pos, decimal r)
Constructor with the position pos and the radius r of the sphere.
Definition: Sphere.h:35
virtual int form()
Return type of the shape.
Definition: Sphere.h:91
virtual Shape * Clone()
Return a pointer to this sphere.
Definition: Sphere.h:50
virtual bool getIntersection(Ray &ray, Intersection &inter)
Check if a ray intersect this sphere.
Definition: Sphere.cpp:18
decimal getRadius()
Get the radius of the sphere.
Definition: Sphere.h:76
Sphere()
Constructor, the Sphere is located at (0,0,0) with a radius 0.
Definition: Sphere.h:29
decimal radius
Radius of the sphere.
Definition: Sphere.h:98
void setBBox()
Definition: Sphere.h:100
void setRadius(decimal _radius)
Set the radius of the sphere.
Definition: Sphere.h:70
vec3 position
Center of the sphere.
Definition: Sphere.h:97
Sphere(Sphere *other)
Copy constructor from a pointed sphere.
Definition: Sphere.h:43
void setPosition(const vec3 &_position)
Set the center of the sphere.
Definition: Sphere.h:81
float decimal
Definition: mathlib.h:45
base_vec3< decimal > vec3
Definition: mathlib.h:381
Intersection struct.
Definition: Shape.h:46