INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Sphere.h
Go to the documentation of this file.
1/**
2@file Sphere.h
3@author JOL
4*/
5#pragma once
6#ifndef _SPHERE_H_
7#define _SPHERE_H_
8
9// In order to call opengl commands in all graphical objects
10#include "GraphicalObject.h"
11
12/// Namespace RayTracer
13namespace rt {
14 /// A sphere is a concrete GraphicalObject that represents a sphere in 3D space.
15 struct Sphere : public GraphicalObject {
16
17 static const int NLAT = 16; ///< number of different latitudes for display
18 static const int NLON = 24; ///< number of different longitudes for display
19
20 /// Virtual destructor since object contains virtual methods.
21 virtual ~Sphere() {}
22
23 /// Creates a sphere of center \a xc and radius \a r.
24 Sphere( Point3 xc, Real r, const Material& m )
25 : GraphicalObject(), center( xc ), radius( r ), material( m )
26 {}
27
28 /// Given latitude and longitude in degrees, returns the point on
29 /// the sphere at these coordinates.
30 Point3 localize( Real latitude, Real longitude ) const;
31
32 // ---------------- GraphicalObject services ----------------------------
33 public:
34
35 /// This method is called by Scene::init() at the beginning of the
36 /// display in the OpenGL window. May be useful for some
37 /// precomputations.
38 void init( Viewer& /* viewer */ ) {}
39
40 /// This method is called by Scene::draw() at each frame to
41 /// redisplay objects in the OpenGL window.
42 void draw( Viewer& viewer );
43
44
45 /// @return the normal vector at point \a p on the sphere (\a p
46 /// should be on or close to the sphere).
48
49 /// @return the material associated to this part of the object
51
52 /// @param[in] ray the incoming ray
53 /// @param[out] returns the point of intersection with the object
54 /// (if any), or the closest point to it.
55 ///
56 /// @return either a real < 0.0 if there is an intersection, or a
57 /// kind of distance to the closest point of intersection.
58 Real rayIntersection( const Ray& ray, Point3& p );
59
60 public:
61 /// The center of the sphere
63 /// The radius of the sphere
65 /// The material (global to the sphere).
67 };
68
69} // namespace rt
70
71#endif // #define _SPHERE_H_
Namespace RayTracer.
Definition Color.h:11
float Real
the type for representing a real number.
Definition Ray.h:18
A sphere is a concrete GraphicalObject that represents a sphere in 3D space.
Definition Sphere.h:15
static const int NLAT
number of different latitudes for display
Definition Sphere.h:17
void init(Viewer &)
Definition Sphere.h:38
Point3 center
The center of the sphere.
Definition Sphere.h:62
Vector3 getNormal(Point3 p)
Definition Sphere.cpp:77
void draw(Viewer &viewer)
Definition Sphere.cpp:8
Point3 localize(Real latitude, Real longitude) const
Definition Sphere.cpp:65
Real rayIntersection(const Ray &ray, Point3 &p)
Definition Sphere.cpp:92
Real radius
The radius of the sphere.
Definition Sphere.h:64
Sphere(Point3 xc, Real r, const Material &m)
Creates a sphere of center xc and radius r.
Definition Sphere.h:24
virtual ~Sphere()
Virtual destructor since object contains virtual methods.
Definition Sphere.h:21
Material material
The material (global to the sphere).
Definition Sphere.h:66
Material getMaterial(Point3 p)
Definition Sphere.cpp:86
static const int NLON
number of different longitudes for display
Definition Sphere.h:18