Main MRPT website > C++ reference for MRPT 1.9.9
CLight.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CLight.h>
13 #include <mrpt/utils/CStream.h>
14 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::utils;
20 using namespace mrpt::math;
21 using namespace std;
22 
23 // Ctor:
25  : light_ID(0),
26  constant_attenuation(1.f),
27  linear_attenuation(0.f),
28  quadratic_attenuation(0.f),
29  spot_exponent(0.f),
30  spot_cutoff(180.f)
31 {
32  color_ambient[0] = 0.05f;
33  color_ambient[1] = 0.05f;
34  color_ambient[2] = 0.05f;
35  color_ambient[3] = 1.f;
36 
37  color_diffuse[0] = 0.7f;
38  color_diffuse[1] = 0.7f;
39  color_diffuse[2] = 0.7f;
40  color_diffuse[3] = 1.f;
41 
42  color_specular[0] = 0.05f;
43  color_specular[1] = 0.05f;
44  color_specular[2] = 0.05f;
45  color_specular[3] = 1.f;
46 
47  setPosition(0, 0, 1, 0);
48  setDirection(0, 0, -1);
49 }
50 
52 {
53  const uint8_t version = 0;
54  out << version;
55 
56  out << light_ID << color_ambient[0] << color_ambient[1] << color_ambient[2]
57  << color_ambient[3] << color_diffuse[0] << color_diffuse[1]
60  << position[0] << position[1] << position[2] << position[3]
63  << spot_cutoff;
64 }
65 
67 {
68  uint8_t version;
69  in >> version;
70 
71  switch (version)
72  {
73  case 0:
74  in >> light_ID >> color_ambient[0] >> color_ambient[1] >>
75  color_ambient[2] >> color_ambient[3] >> color_diffuse[0] >>
76  color_diffuse[1] >> color_diffuse[2] >> color_diffuse[3] >>
78  color_specular[3] >> position[0] >> position[1] >>
79  position[2] >> position[3] >> direction[0] >> direction[1] >>
82  break;
83  default:
85  };
86 }
87 
89 {
90 #if MRPT_HAS_OPENGL_GLUT
91  const GLenum id = (GLenum)((int)GL_LIGHT0 + light_ID);
92 
93  glEnable(id);
94 
105 #endif
106 }
107 
108 void CLight::setPosition(float x, float y, float z, float w)
109 {
110  position[0] = x;
111  position[1] = y;
112  position[2] = z;
113  position[3] = w;
114 }
115 void CLight::setDirection(float dx, float dy, float dz)
116 {
117  direction[0] = dx;
118  direction[1] = dy;
119  direction[2] = dz;
120 }
121 
122 namespace mrpt
123 {
124 namespace opengl
125 {
128 {
129  o.readFromStream(in);
130  return in;
131 }
134 {
135  o.writeToStream(out);
136  return out;
137 }
138 }
139 }
#define GL_SPECULAR
Definition: glew.h:580
float direction[3]
[x,y,z]
Definition: CLight.h:51
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble z
Definition: glext.h:3872
mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:132
#define GL_SPOT_EXPONENT
Definition: glew.h:583
float constant_attenuation
Definition: CLight.h:52
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define GL_LINEAR_ATTENUATION
Definition: glew.h:586
CLight()
Default constructor, sets default values.
Definition: CLight.cpp:24
void writeToStream(mrpt::utils::CStream &out) const
Definition: CLight.cpp:51
STL namespace.
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:88
#define GL_POSITION
Definition: glew.h:581
#define GL_LIGHT0
Definition: glew.h:570
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
Each of the possible lights of a 3D scene.
Definition: CLight.h:32
unsigned char uint8_t
Definition: rptypes.h:41
float color_specular[4]
Definition: CLight.h:45
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define GL_DIFFUSE
Definition: glew.h:579
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLAPI void GLAPIENTRY glLightf(GLenum light, GLenum pname, GLfloat param)
mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, mrpt::opengl::CLight &o)
Definition: CLight.cpp:126
unsigned int GLenum
Definition: glew.h:206
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define GL_SPOT_CUTOFF
Definition: glew.h:584
float spot_exponent
Definition: CLight.h:55
GLAPI void GLAPIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params)
float linear_attenuation
Definition: CLight.h:53
GLuint in
Definition: glext.h:7274
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
uint8_t light_ID
OpenGL ID (typical range: 0-7)
Definition: CLight.h:41
void readFromStream(mrpt::utils::CStream &in)
Definition: CLight.cpp:66
GLenum GLint GLint y
Definition: glext.h:3538
float color_ambient[4]
Definition: CLight.h:43
#define GL_CONSTANT_ATTENUATION
Definition: glew.h:585
float color_diffuse[4]
Definition: CLight.h:44
GLenum GLint x
Definition: glext.h:3538
float quadratic_attenuation
Definition: CLight.h:54
void setPosition(float x, float y, float z, float w)
Definition: CLight.cpp:108
float position[4]
[x,y,z,w]: w=0 means directional light, w=1 means a light at a real 3D position.
Definition: CLight.h:49
#define GL_AMBIENT
Definition: glew.h:578
void setDirection(float dx, float dy, float dz)
Definition: CLight.cpp:115
#define GL_SPOT_DIRECTION
Definition: glew.h:582
#define GL_QUADRATIC_ATTENUATION
Definition: glew.h:587



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019