-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geometry.hpp
116 lines (99 loc) · 3.55 KB
/
Geometry.hpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/******************************************************************************
* @file Geometry.hpp
* @author Andrés Gavín Murillo, 716358
* @author Abel Naya Forcano, 544125
* @date Enero 2020
* @coms Informática Gráfica - Trabajo 4: Path tracer
******************************************************************************/
#ifndef TRABAJO1_GEOMETRIC_HPP
#define TRABAJO1_GEOMETRIC_HPP
#include <array>
#include "HCoord.hpp"
#include "Material.hpp"
// Geometries
enum GEOMETRY_TYPE {
SPHERE,
PLANE,
TRIANGLE,
CIRCLE,
CUADRIC
};
typedef struct {
const HCoord center; // center of sphere (UCS)
const float radius; // radius of sphere (>=0)
} GEOMETRY_SPHERE;
typedef struct {
const HCoord normal; // normal direction of plane (UCS, normalized)
const float dist; // distance to origin
} GEOMETRY_PLANE;
typedef struct {
const GEOMETRY_PLANE plane; // plane this triangle is on. The normal is cross(dirX,dirY)
const HCoord point; // first point
const HCoord dirX; // second point
const HCoord dirY; // third point
} GEOMETRY_TRIANGLE;
typedef struct {
const GEOMETRY_PLANE plane; // plane this circle is on. THe normal is cross(axisX,axisY)
const HCoord center; // center of circle
const HCoord axisX; // X axis, defines the max value
const HCoord axisY; // Y axis, defines the max value
} GEOMETRY_CIRCLE;
typedef struct {
const float A, B, C, D, E, F, G, H, I, J; // cuadric values
} GEOMETRY_CUADRIC;
typedef struct {
const GEOMETRY_TYPE type;
const union {
const GEOMETRY_SPHERE sphere;
const GEOMETRY_PLANE plane;
const GEOMETRY_TRIANGLE triangle;
const GEOMETRY_CIRCLE circle;
const GEOMETRY_CUADRIC cuadric;
} data;
} Geometry;
/**
* Creates a sphere
* @param center center of sphere (UCS)
* @param radius radious of sphere (UCS)
* @return the sphere as geometry
*/
Geometry Sphere(const HCoord ¢er, float radius);
/**
* Creates a plane
* @param normal normal vector of plane
* @param dist distance to origin (in normal direction: if normal is (0,0,1) and dist=1 the plane is on (0,0,-1) visible from origin)
* @return the plane as geometry
*/
Geometry Plane(const HCoord &normal, float dist);
/**
* Creates a triangle from 3 points. The normal of the triangle is cross(point2-point1,point3-point1)
* @param point1 a point, like the 'center' of the triangle
* @param point2 like the end of the axisX of the triangle
* @param point3 like the end of the axisY of the triangle
* @return the triangle as geometry
*/
Geometry Triangle(const HCoord &point1, const HCoord &point2, const HCoord &point3);
/**
* Creates a circle (Oval) from a center and two axis
* @param center center of the circle
* @param axisX direction of the x axis, its length marks the end of the circle
* @param axisY direction of the y axis, its length marks the end of the circle
* @return the circle as geometry
*/
Geometry Circle(const HCoord ¢er, const HCoord &axisX, const HCoord &axisY);
/**
* Creates a circle (Oval) from a center and two axis
* @param center center of the circle
* @param axisX direction of the x axis, its length marks the end of the circle
* @param axisY direction of the y axis, its length marks the end of the circle
* @return the circle as geometry
*/
Geometry Cuadric(float A, float B, float C, float D, float E, float F, float G, float H, float I, float J);
/**
*
* @param geometry
* @param position
* @return the normal vector
*/
HCoord normal(const Geometry &geometry, const HCoord &position);
#endif //TRABAJO1_GEOMETRIC_HPP