-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sphere.h
71 lines (55 loc) · 2.18 KB
/
Sphere.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
@file Sphere.h
@author JOL
*/
#pragma once
#ifndef _SPHERE_H_
#define _SPHERE_H_
// In order to call opengl commands in all graphical objects
#include "GraphicalObject.h"
/// Namespace RayTracer
namespace rt {
/// A sphere is a concrete GraphicalObject that represents a sphere in 3D space.
struct Sphere : public GraphicalObject {
static const int NLAT = 16; ///< number of different latitudes for display
static const int NLON = 24; ///< number of different longitudes for display
/// Virtual destructor since object contains virtual methods.
virtual ~Sphere() {}
/// Creates a sphere of center \a xc and radius \a r.
Sphere( Point3 xc, Real r, const Material& m )
: GraphicalObject(), center( xc ), radius( r ), material( m )
{}
/// Given latitude and longitude in degrees, returns the point on
/// the sphere at these coordinates.
Point3 localize( Real latitude, Real longitude ) const;
// ---------------- GraphicalObject services ----------------------------
public:
/// This method is called by Scene::init() at the beginning of the
/// display in the OpenGL window. May be useful for some
/// precomputations.
void init( Viewer& /* viewer */ ) {}
/// This method is called by Scene::draw() at each frame to
/// redisplay objects in the OpenGL window.
void draw( Viewer& viewer );
/// @return the normal vector at point \a p on the sphere (\a p
/// should be on or close to the sphere).
Vector3 getNormal( Point3 p );
/// @return the material associated to this part of the object
Material getMaterial( Point3 p );
/// @param[in] ray the incoming ray
/// @param[out] returns the point of intersection with the object
/// (if any), or the closest point to it.
///
/// @return either a real < 0.0 if there is an intersection, or a
/// kind of distance to the closest point of intersection.
Real rayIntersection( const Ray& ray, Point3& p );
public:
/// The center of the sphere
Point3 center;
/// The radius of the sphere
Real radius;
/// The material (global to the sphere).
Material material;
};
} // namespace rt
#endif // #define _SPHERE_H_