Main MRPT website > C++ reference for MRPT 1.5.7
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 
51 
53 {
54  const uint8_t version = 0;
55  out << version;
56 
57  out << light_ID
61  << position[0] << position[1] << position[2] << position[3]
62  << direction[0] << direction[1] << direction[2]
64 }
65 
67 {
69  in >> version;
70 
71  switch(version)
72  {
73  case 0:
74  in >> light_ID
78  >> position[0] >> position[1] >> position[2] >> position[3]
79  >> direction[0] >> direction[1] >> direction[2]
81  break;
82  default:
84  };
85 }
86 
88 {
89 #if MRPT_HAS_OPENGL_GLUT
90  const GLenum id = (GLenum)((int)GL_LIGHT0 + light_ID);
91 
92  glEnable( id );
93 
104 #endif
105 }
106 
107 void CLight::setPosition(float x,float y,float z,float w)
108 {
109  position[0] = x;
110  position[1] = y;
111  position[2] = z;
112  position[3] = w;
113 }
114 void CLight::setDirection(float dx,float dy,float dz)
115 {
116  direction[0] = dx;
117  direction[1] = dy;
118  direction[2] = dz;
119 }
120 
121 
122 
123 namespace mrpt
124 {
125  namespace opengl
126  {
128  {
129  o.readFromStream(in);
130  return in;
131  }
133  {
134  o.writeToStream(out);
135  return out;
136  }
137  }
138 }
139 
#define GL_SPECULAR
Definition: glew.h:576
float direction[3]
[x,y,z]
Definition: CLight.h:42
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
GLdouble GLdouble z
Definition: glext.h:3734
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:132
#define GL_SPOT_EXPONENT
Definition: glew.h:579
float constant_attenuation
Definition: CLight.h:43
GLAPI void GLAPIENTRY glEnable(GLenum cap)
#define GL_LINEAR_ATTENUATION
Definition: glew.h:582
::mrpt::utils::CStream & operator>>(mrpt::utils::CStream &in, CAngularObservationMeshPtr &pObj)
CLight()
Default constructor, sets default values.
Definition: CLight.cpp:24
void writeToStream(mrpt::utils::CStream &out) const
Definition: CLight.cpp:52
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:87
#define GL_POSITION
Definition: glew.h:577
#define GL_LIGHT0
Definition: glew.h:566
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
Each of the possible lights of a 3D scene.
Definition: CLight.h:28
unsigned char uint8_t
Definition: rptypes.h:43
float color_specular[4]
Definition: CLight.h:39
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define GL_DIFFUSE
Definition: glew.h:575
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLAPI void GLAPIENTRY glLightf(GLenum light, GLenum pname, GLfloat param)
int version
Definition: mrpt_jpeglib.h:898
unsigned int GLenum
Definition: glew.h:202
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define GL_SPOT_CUTOFF
Definition: glew.h:580
float spot_exponent
Definition: CLight.h:46
GLAPI void GLAPIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params)
float linear_attenuation
Definition: CLight.h:44
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
uint8_t light_ID
OpenGL ID (typical range: 0-7)
Definition: CLight.h:35
void readFromStream(mrpt::utils::CStream &in)
Definition: CLight.cpp:66
GLenum GLint GLint y
Definition: glext.h:3516
float color_ambient[4]
Definition: CLight.h:37
#define GL_CONSTANT_ATTENUATION
Definition: glew.h:581
float color_diffuse[4]
Definition: CLight.h:38
GLenum GLint x
Definition: glext.h:3516
float quadratic_attenuation
Definition: CLight.h:45
void setPosition(float x, float y, float z, float w)
Definition: CLight.cpp:107
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:41
#define GL_AMBIENT
Definition: glew.h:574
void setDirection(float dx, float dy, float dz)
Definition: CLight.cpp:114
#define GL_SPOT_DIRECTION
Definition: glew.h:578
#define GL_QUADRATIC_ATTENUATION
Definition: glew.h:583



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019