MRPT  1.9.9
CLight.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CLight.h>
14 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace std;
20 
21 // Ctor:
23 {
24  color_ambient[0] = 0.05f;
25  color_ambient[1] = 0.05f;
26  color_ambient[2] = 0.05f;
27  color_ambient[3] = 1.f;
28 
29  color_diffuse[0] = 0.7f;
30  color_diffuse[1] = 0.7f;
31  color_diffuse[2] = 0.7f;
32  color_diffuse[3] = 1.f;
33 
34  color_specular[0] = 0.05f;
35  color_specular[1] = 0.05f;
36  color_specular[2] = 0.05f;
37  color_specular[3] = 1.f;
38 
39  setPosition(0, 0, 1, 0);
40  setDirection(0, 0, -1);
41 }
42 
44 {
45  const uint8_t version = 0;
46  out << version;
47 
48  out << light_ID << color_ambient[0] << color_ambient[1] << color_ambient[2]
49  << color_ambient[3] << color_diffuse[0] << color_diffuse[1]
50  << color_diffuse[2] << color_diffuse[3] << color_specular[0]
51  << color_specular[1] << color_specular[2] << color_specular[3]
52  << position[0] << position[1] << position[2] << position[3]
53  << direction[0] << direction[1] << direction[2] << constant_attenuation
54  << linear_attenuation << quadratic_attenuation << spot_exponent
55  << spot_cutoff;
56 }
57 
59 {
60  uint8_t version;
61  in >> version;
62 
63  switch (version)
64  {
65  case 0:
66  in >> light_ID >> color_ambient[0] >> color_ambient[1] >>
67  color_ambient[2] >> color_ambient[3] >> color_diffuse[0] >>
68  color_diffuse[1] >> color_diffuse[2] >> color_diffuse[3] >>
69  color_specular[0] >> color_specular[1] >> color_specular[2] >>
70  color_specular[3] >> position[0] >> position[1] >>
71  position[2] >> position[3] >> direction[0] >> direction[1] >>
72  direction[2] >> constant_attenuation >> linear_attenuation >>
73  quadratic_attenuation >> spot_exponent >> spot_cutoff;
74  break;
75  default:
77  };
78 }
79 
81 {
82 #if MRPT_HAS_OPENGL_GLUT
83  const auto id = (GLenum)((int)GL_LIGHT0 + light_ID);
84 
85  glEnable(id);
86 
87  glLightfv(id, GL_AMBIENT, color_ambient);
88  glLightfv(id, GL_DIFFUSE, color_diffuse);
89  glLightfv(id, GL_SPECULAR, color_specular);
90  glLightfv(id, GL_POSITION, position);
91  glLightfv(id, GL_SPOT_DIRECTION, direction);
92  glLightf(id, GL_SPOT_EXPONENT, spot_exponent);
93  glLightf(id, GL_SPOT_CUTOFF, spot_cutoff);
94  glLightf(id, GL_CONSTANT_ATTENUATION, constant_attenuation);
95  glLightf(id, GL_LINEAR_ATTENUATION, linear_attenuation);
96  glLightf(id, GL_QUADRATIC_ATTENUATION, quadratic_attenuation);
97 #endif
98 }
99 
100 void CLight::setPosition(float x, float y, float z, float w)
101 {
102  position[0] = x;
103  position[1] = y;
104  position[2] = z;
105  position[3] = w;
106 }
107 void CLight::setDirection(float dx, float dy, float dz)
108 {
109  direction[0] = dx;
110  direction[1] = dy;
111  direction[2] = dz;
112 }
113 
114 namespace mrpt::opengl
115 {
118 {
119  o.readFromStream(in);
120  return in;
121 }
124 {
125  o.writeToStream(out);
126  return out;
127 }
128 } // namespace mrpt::opengl
#define GL_SPECULAR
Definition: glew.h:581
GLdouble GLdouble z
Definition: glext.h:3879
#define GL_SPOT_EXPONENT
Definition: glew.h:584
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define GL_LINEAR_ATTENUATION
Definition: glew.h:587
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:122
CLight()
Default constructor, sets default values.
Definition: CLight.cpp:22
STL namespace.
void readFromStream(mrpt::serialization::CArchive &in)
Definition: CLight.cpp:58
void sendToOpenGL() const
Define the light in the current OpenGL rendering context (users normally don&#39;t need to call this expl...
Definition: CLight.cpp:80
#define GL_POSITION
Definition: glew.h:582
void writeToStream(mrpt::serialization::CArchive &out) const
Definition: CLight.cpp:43
#define GL_LIGHT0
Definition: glew.h:571
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
Each of the possible lights of a 3D scene.
Definition: CLight.h:22
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
#define GL_DIFFUSE
Definition: glew.h:580
GLAPI void GLAPIENTRY glLightf(GLenum light, GLenum pname, GLfloat param)
unsigned int GLenum
Definition: glew.h:207
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define GL_SPOT_CUTOFF
Definition: glew.h:585
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
GLAPI void GLAPIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params)
mrpt::vision::TStereoCalibResults out
GLuint in
Definition: glext.h:7391
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, mrpt::opengl::CLight &o)
Definition: CLight.cpp:116
GLenum GLint GLint y
Definition: glext.h:3542
#define GL_CONSTANT_ATTENUATION
Definition: glew.h:586
GLenum GLint x
Definition: glext.h:3542
void setPosition(float x, float y, float z, float w)
Definition: CLight.cpp:100
#define GL_AMBIENT
Definition: glew.h:579
void setDirection(float dx, float dy, float dz)
Definition: CLight.cpp:107
#define GL_SPOT_DIRECTION
Definition: glew.h:583
#define GL_QUADRATIC_ATTENUATION
Definition: glew.h:588



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 479715d5b Tue Nov 12 07:26:21 2019 +0100 at mar nov 12 07:30:12 CET 2019