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-2018, 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>
14 
15 #include "opengl_internals.h"
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace std;
20 
21 // Ctor:
23  : light_ID(0),
24  constant_attenuation(1.f),
25  linear_attenuation(0.f),
26  quadratic_attenuation(0.f),
27  spot_exponent(0.f),
28  spot_cutoff(180.f)
29 {
30  color_ambient[0] = 0.05f;
31  color_ambient[1] = 0.05f;
32  color_ambient[2] = 0.05f;
33  color_ambient[3] = 1.f;
34 
35  color_diffuse[0] = 0.7f;
36  color_diffuse[1] = 0.7f;
37  color_diffuse[2] = 0.7f;
38  color_diffuse[3] = 1.f;
39 
40  color_specular[0] = 0.05f;
41  color_specular[1] = 0.05f;
42  color_specular[2] = 0.05f;
43  color_specular[3] = 1.f;
44 
45  setPosition(0, 0, 1, 0);
46  setDirection(0, 0, -1);
47 }
48 
50 {
51  const uint8_t version = 0;
52  out << version;
53 
54  out << light_ID << color_ambient[0] << color_ambient[1] << color_ambient[2]
55  << color_ambient[3] << color_diffuse[0] << color_diffuse[1]
58  << position[0] << position[1] << position[2] << position[3]
61  << spot_cutoff;
62 }
63 
65 {
66  uint8_t version;
67  in >> version;
68 
69  switch (version)
70  {
71  case 0:
72  in >> light_ID >> color_ambient[0] >> color_ambient[1] >>
73  color_ambient[2] >> color_ambient[3] >> color_diffuse[0] >>
74  color_diffuse[1] >> color_diffuse[2] >> color_diffuse[3] >>
76  color_specular[3] >> position[0] >> position[1] >>
77  position[2] >> position[3] >> direction[0] >> direction[1] >>
80  break;
81  default:
83  };
84 }
85 
87 {
88 #if MRPT_HAS_OPENGL_GLUT
89  const GLenum id = (GLenum)((int)GL_LIGHT0 + light_ID);
90 
91  glEnable(id);
92 
103 #endif
104 }
105 
106 void CLight::setPosition(float x, float y, float z, float w)
107 {
108  position[0] = x;
109  position[1] = y;
110  position[2] = z;
111  position[3] = w;
112 }
113 void CLight::setDirection(float dx, float dy, float dz)
114 {
115  direction[0] = dx;
116  direction[1] = dy;
117  direction[2] = dz;
118 }
119 
120 namespace mrpt::opengl
121 {
124 {
125  o.readFromStream(in);
126  return in;
127 }
130 {
131  o.writeToStream(out);
132  return out;
133 }
134 } // namespace mrpt
135 
136 
#define GL_SPECULAR
Definition: glew.h:580
float direction[3]
[x,y,z]
Definition: CLight.h:41
GLdouble GLdouble z
Definition: glext.h:3872
#define GL_SPOT_EXPONENT
Definition: glew.h:583
float constant_attenuation
Definition: CLight.h:42
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define GL_LINEAR_ATTENUATION
Definition: glew.h:586
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:128
CLight()
Default constructor, sets default values.
Definition: CLight.cpp:22
STL namespace.
void readFromStream(mrpt::serialization::CArchive &in)
Definition: CLight.cpp:64
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:86
#define GL_POSITION
Definition: glew.h:581
void writeToStream(mrpt::serialization::CArchive &out) const
Definition: CLight.cpp:49
#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:22
unsigned char uint8_t
Definition: rptypes.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
float color_specular[4]
Definition: CLight.h:35
#define GL_DIFFUSE
Definition: glew.h:579
GLAPI void GLAPIENTRY glLightf(GLenum light, GLenum pname, GLfloat param)
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:45
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
GLAPI void GLAPIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params)
float linear_attenuation
Definition: CLight.h:43
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:31
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, mrpt::opengl::CLight &o)
Definition: CLight.cpp:122
GLenum GLint GLint y
Definition: glext.h:3538
float color_ambient[4]
Definition: CLight.h:33
#define GL_CONSTANT_ATTENUATION
Definition: glew.h:585
float color_diffuse[4]
Definition: CLight.h:34
GLenum GLint x
Definition: glext.h:3538
float quadratic_attenuation
Definition: CLight.h:44
void setPosition(float x, float y, float z, float w)
Definition: CLight.cpp:106
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:39
#define GL_AMBIENT
Definition: glew.h:578
void setDirection(float dx, float dy, float dz)
Definition: CLight.cpp:113
#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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020