Euclid
Geometry Processing and Shape Analysis in C++
RenderCore.h
1 
6 #pragma once
7 
8 #include <Eigen/Dense>
9 
10 namespace Euclid
11 {
17 class Camera
18 {
19 public:
20  using Vec3 = Eigen::Vector3f;
21 
22 public:
26  Camera() = default;
27 
38  Camera(const Vec3& position,
39  const Vec3& focus,
40  const Vec3& up,
41  float tnear,
42  float tfar)
43  {
44  pos = position;
45  dir = (position - focus).normalized();
46  u = up.cross(dir).normalized();
47  v = dir.cross(u);
48  this->tnear = tnear;
49  this->tfar = tfar;
50  }
51 
52  virtual ~Camera();
53 
57  void lookat(const Vec3& position, const Vec3& focus, const Vec3& up)
58  {
59  pos = position;
60  dir = (position - focus).normalized();
61  u = up.cross(dir).normalized();
62  v = dir.cross(u);
63  }
64 
70  void set_range(float tnear, float tfar)
71  {
72  this->tnear = tnear;
73  this->tfar = tfar;
74  }
75 
76 public:
80  Eigen::Vector3f pos{ 0.0f, 0.0f, 0.0f };
81 
85  Eigen::Vector3f u{ 1.0f, 0.0f, 0.0f };
86 
90  Eigen::Vector3f v{ 0.0f, 1.0f, 0.0f };
91 
95  Eigen::Vector3f dir{ 0.0f, 0.0f, 1.0f };
96 
100  float tnear = 0.0f;
101 
105  float tfar = std::numeric_limits<float>::max();
106 };
107 
108 inline Camera::~Camera() {}
109 
110 struct Transform
111 {
115  alignas(32) Eigen::Matrix4f model_matrix;
116 
120  alignas(32) Eigen::Matrix4f mvp;
121 
126  alignas(32) Eigen::Matrix4f normal_matrix;
127 
132  {
133  model_matrix.setIdentity();
134  mvp.setIdentity();
135  normal_matrix.setIdentity();
136  }
137 
141  Transform(const Eigen::Matrix4f& model,
142  const Eigen::Matrix4f& view,
143  const Eigen::Matrix4f& projection)
144  {
145  model_matrix = model;
146  mvp = projection * view * model;
147  normal_matrix = model.inverse().transpose();
148  }
149 };
150 
154 struct Material
155 {
159  alignas(16) Eigen::Array3f ambient;
160 
164  alignas(16) Eigen::Array3f diffuse;
165 };
166 
170 struct Light
171 {
175  alignas(16) Eigen::Array3f position;
176 
180  alignas(16) Eigen::Array3f color;
181 
185  alignas(4) float intensity;
186 };
187 
189 } // namespace Euclid
Transform()
Initialize to identity matrices.
Definition: RenderCore.h:131
Eigen::Vector3f u
Right vector.
Definition: RenderCore.h:85
float tnear
The near plane.
Definition: RenderCore.h:100
void lookat(const Vec3 &position, const Vec3 &focus, const Vec3 &up)
Pose the camera according to the parameteres.
Definition: RenderCore.h:57
Eigen::Vector3f pos
Position.
Definition: RenderCore.h:80
Definition: RenderCore.h:110
void set_range(float tnear, float tfar)
Set the range of the ray.
Definition: RenderCore.h:70
Eigen::Vector3f dir
Negative view vector.
Definition: RenderCore.h:95
float tfar
The far plane.
Definition: RenderCore.h:105
Camera()=default
Create a Camera with default paramters.
Definition: AABB.h:6
A simple Lambertian material model.
Definition: RenderCore.h:154
A basic positionable camera model.
Definition: RenderCore.h:17
Transform(const Eigen::Matrix4f &model, const Eigen::Matrix4f &view, const Eigen::Matrix4f &projection)
Initialize from the mvp matrices.
Definition: RenderCore.h:141
Camera(const Vec3 &position, const Vec3 &focus, const Vec3 &up, float tnear, float tfar)
Create a Camera.
Definition: RenderCore.h:38
CGAL::Vector_3< Kernel > normalized(const CGAL::Vector_3< Kernel > &vec)
Return a normalized version of the input vector.
Definition: Vector.cpp:32
A simple point light model.
Definition: RenderCore.h:170
Eigen::Vector3f v
Up vector.
Definition: RenderCore.h:90