dummy.cpp
Go to the documentation of this file.
1 
32 #define GLM_MESSAGES
33 #include "../glm.hpp"
34 #include <limits>
35 
36 struct material
37 {
42  float shininess; // Srm
43 };
44 
45 struct light
46 {
47  glm::vec4 ambient; // Acli
48  glm::vec4 diffuse; // Dcli
51  glm::vec4 halfVector; // Derived: Hi
53  float spotExponent; // Srli
54  float spotCutoff; // Crli
55  // (range: [0.0,90.0], 180.0)
56  float spotCosCutoff; // Derived: cos(Crli)
57  // (range: [1.0,0.0],-1.0)
58  float constantAttenuation; // K0
59  float linearAttenuation; // K1
61 };
62 
63 
64 // Sample 1
65 #include <glm/vec3.hpp>// glm::vec3
66 #include <glm/geometric.hpp>// glm::cross, glm::normalize
67 
69 (
70  glm::vec3 const & a,
71  glm::vec3 const & b,
72  glm::vec3 const & c
73 )
74 {
75  return glm::normalize(glm::cross(c - a, b - a));
76 }
77 
78 typedef unsigned int GLuint;
79 #define GL_FALSE 0
80 void glUniformMatrix4fv(GLuint, int, int, float*){}
81 
82 // Sample 2
83 #include <glm/vec3.hpp> // glm::vec3
84 #include <glm/vec4.hpp> // glm::vec4, glm::ivec4
85 #include <glm/mat4x4.hpp> // glm::mat4
86 #include <glm/gtc/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale, glm::perspective
87 #include <glm/gtc/type_ptr.hpp> // glm::value_ptr
88 void func(GLuint LocationMVP, float Translate, glm::vec2 const & Rotate)
89 {
90  glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
91  glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
92  glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
93  glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
94  glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
95  glm::mat4 MVP = Projection * View * Model;
96  glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP));
97 }
98 
99 // Sample 3
100 #include <glm/vec2.hpp>// glm::vec2
101 #include <glm/packing.hpp>// glm::packUnorm2x16
102 #include <glm/integer.hpp>// glm::uint
103 #include <glm/gtc/type_precision.hpp>// glm::i8vec2, glm::i32vec2
104 std::size_t const VertexCount = 4;
105 // Float quad geometry
106 std::size_t const PositionSizeF32 = VertexCount * sizeof(glm::vec2);
108 {
109  glm::vec2(-1.0f,-1.0f),
110  glm::vec2( 1.0f,-1.0f),
111  glm::vec2( 1.0f, 1.0f),
112  glm::vec2(-1.0f, 1.0f)
113  };
114 // Half-float quad geometry
115 std::size_t const PositionSizeF16 = VertexCount * sizeof(glm::uint);
117 {
122 };
123 // 8 bits signed integer quad geometry
124 std::size_t const PositionSizeI8 = VertexCount * sizeof(glm::i8vec2);
126 {
127  glm::i8vec2(-1,-1),
128  glm::i8vec2( 1,-1),
129  glm::i8vec2( 1, 1),
130  glm::i8vec2(-1, 1)
131 };
132 // 32 bits signed integer quad geometry
133 std::size_t const PositionSizeI32 = VertexCount * sizeof(glm::i32vec2);
135 {
136  glm::i32vec2 (-1,-1),
137  glm::i32vec2 ( 1,-1),
138  glm::i32vec2 ( 1, 1),
139  glm::i32vec2 (-1, 1)
140 };
141 
143 {
146 };
147 
148 /*
149 // Sample 4
150 #include <glm/vec3.hpp>// glm::vec3
151 #include <glm/geometric.hpp>// glm::normalize, glm::dot, glm::reflect
152 #include <glm/exponential.hpp>// glm::pow
153 #include <glm/gtc/random.hpp>// glm::vecRand3
154 glm::vec3 lighting
155 (
156  intersection const & Intersection,
157  material const & Material,
158  light const & Light,
159  glm::vec3 const & View
160 )
161 {
162  glm::vec3 Color(0.0f);
163  glm::vec3 LightVertor(glm::normalize(
164  Light.position - Intersection.position +
165  glm::vecRand3(0.0f, Light.inaccuracy));
166 
167  if(!shadow(Intersection.position, Light.position, LightVertor))
168  {
169  float Diffuse = glm::dot(Intersection.normal, LightVector);
170  if(Diffuse <= 0.0f)
171  return Color;
172  if(Material.isDiffuse())
173  Color += Light.color() * Material.diffuse * Diffuse;
174  if(Material.isSpecular())
175  {
176  glm::vec3 Reflect(glm::reflect(
177  glm::normalize(-LightVector),
178  glm::normalize(Intersection.normal)));
179  float Dot = glm::dot(Reflect, View);
180  float Base = Dot > 0.0f ? Dot : 0.0f;
181  float Specular = glm::pow(Base, Material.exponent);
182  Color += Material.specular * Specular;
183  }
184  }
185  return Color;
186 }
187 */
188 int main()
189 {
190  return 0;
191 }
std::size_t const PositionSizeF16
Definition: dummy.cpp:115
f
highp_i32vec2 i32vec2
Definition: fwd.hpp:558
int main()
Definition: dummy.cpp:188
glm::vec4 halfVector
Definition: dummy.cpp:51
glm::vec4 specular
Definition: dummy.cpp:41
unsigned int uint
Definition: type_int.hpp:170
glm::vec4 position
Definition: dummy.cpp:144
std::size_t const PositionSizeF32
Definition: dummy.cpp:106
void func(GLuint LocationMVP, float Translate, glm::vec2 const &Rotate)
Definition: dummy.cpp:88
glm::vec4 specular
Definition: dummy.cpp:49
float quadraticAttenuation
Definition: dummy.cpp:60
GLM_FUNC_DECL detail::tmat4x4< T, P > scale(detail::tmat4x4< T, P > const &m, detail::tvec3< T, P > const &v)
GLM_FUNC_DECL detail::tmat4x4< T, defaultp > perspective(T const &fovy, T const &aspect, T const &near, T const &far)
glm::vec4 position
Definition: dummy.cpp:50
glm::vec4 emission
Definition: dummy.cpp:38
float linearAttenuation
Definition: dummy.cpp:59
glm::vec4 ambient
Definition: dummy.cpp:47
unsigned int GLuint
Definition: dummy.cpp:78
GLM_FUNC_DECL genType::value_type const * value_ptr(genType const &vec)
glm::uint const PositionDataF16[VertexCount]
Definition: dummy.cpp:116
GLM_FUNC_DECL genType normalize(genType const &x)
GLM_FUNC_DECL detail::tvec3< T, P > cross(detail::tvec3< T, P > const &x, detail::tvec3< T, P > const &y)
#define GL_FALSE
Definition: dummy.cpp:79
glm::vec4 ambient
Definition: dummy.cpp:39
glm::i32vec2 const PositionDataI32[VertexCount]
Definition: dummy.cpp:134
glm::vec3 computeNormal(glm::vec3 const &a, glm::vec3 const &b, glm::vec3 const &c)
Definition: dummy.cpp:69
highp_vec2 vec2
Definition: type_vec.hpp:387
glm::vec4 diffuse
Definition: dummy.cpp:48
glm::vec3 spotDirection
Definition: dummy.cpp:52
Definition: dummy.cpp:45
highp_i8vec2 i8vec2
Definition: fwd.hpp:399
glm::vec3 normal
Definition: dummy.cpp:145
std::size_t const PositionSizeI8
Definition: dummy.cpp:124
void glUniformMatrix4fv(GLuint, int, int, float *)
Definition: dummy.cpp:80
float spotExponent
Definition: dummy.cpp:53
std::size_t const PositionSizeI32
Definition: dummy.cpp:133
glm::i8vec2 const PositionDataI8[VertexCount]
Definition: dummy.cpp:125
std::size_t const VertexCount
Definition: dummy.cpp:104
float constantAttenuation
Definition: dummy.cpp:58
float spotCosCutoff
Definition: dummy.cpp:56
glm::vec2 const PositionDataF32[VertexCount]
Definition: dummy.cpp:107
GLM_FUNC_DECL detail::tmat4x4< T, P > translate(detail::tmat4x4< T, P > const &m, detail::tvec3< T, P > const &v)
glm::vec4 diffuse
Definition: dummy.cpp:40
GLM_FUNC_DECL detail::tmat4x4< T, P > rotate(detail::tmat4x4< T, P > const &m, T const &angle, detail::tvec3< T, P > const &axis)
float shininess
Definition: dummy.cpp:42
float spotCutoff
Definition: dummy.cpp:54
GLM_FUNC_DECL uint packUnorm2x16(vec2 const &v)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31