1 ///////////////////////////////////////////////////////////////////////////////////
2 /// OpenGL Mathematics (glm.g-truc.net)
3 ///
4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
5 /// Permission is hereby granted, free of charge, to any person obtaining a copy
6 /// of this software and associated documentation files (the "Software"), to deal
7 /// in the Software without restriction, including without limitation the rights
8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 /// copies of the Software, and to permit persons to whom the Software is
10 /// furnished to do so, subject to the following conditions:
11 ///
12 /// The above copyright notice and this permission notice shall be included in
13 /// all copies or substantial portions of the Software.
14 ///
15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 /// THE SOFTWARE.
22 ///
23 /// @ref core
24 /// @file glm/core/dummy.cpp
25 /// @date 2011-01-19 / 2011-06-15
26 /// @author Christophe Riccio
27 ///
28 /// GLM is a header only library. There is nothing to compile.
29 /// dummy.cpp exist only a wordaround for CMake file.
30 ///////////////////////////////////////////////////////////////////////////////////
31
32 #define GLM_FORCE_RADIANS
33 #define GLM_MESSAGES
34 #include "../glm.hpp"
35 #include <limits>
36
37 struct material
38 {
39 glm::vec4 emission; // Ecm
40 glm::vec4 ambient; // Acm
41 glm::vec4 diffuse; // Dcm
42 glm::vec4 specular; // Scm
43 float shininess; // Srm
44 };
45
46 struct light
47 {
48 glm::vec4 ambient; // Acli
49 glm::vec4 diffuse; // Dcli
50 glm::vec4 specular; // Scli
51 glm::vec4 position; // Ppli
52 glm::vec4 halfVector; // Derived: Hi
53 glm::vec3 spotDirection; // Sdli
54 float spotExponent; // Srli
55 float spotCutoff; // Crli
56 // (range: [0.0,90.0], 180.0)
57 float spotCosCutoff; // Derived: cos(Crli)
58 // (range: [1.0,0.0],-1.0)
59 float constantAttenuation; // K0
60 float linearAttenuation; // K1
61 float quadraticAttenuation;// K2
62 };
63
64
65 // Sample 1
66 #include <glm/vec3.hpp>// glm::vec3
computeNormal(glm::vec3 const & a,glm::vec3 const & b,glm::vec3 const & c)67 #include <glm/geometric.hpp>// glm::cross, glm::normalize
68
69 glm::vec3 computeNormal
70 (
71 glm::vec3 const & a,
72 glm::vec3 const & b,
73 glm::vec3 const & c
74 )
75 {
76 return glm::normalize(glm::cross(c - a, b - a));
77 }
78
glUniformMatrix4fv(GLuint,int,int,float *)79 typedef unsigned int GLuint;
80 #define GL_FALSE 0
81 void glUniformMatrix4fv(GLuint, int, int, float*){}
82
83 // Sample 2
84 #include <glm/vec3.hpp> // glm::vec3
85 #include <glm/vec4.hpp> // glm::vec4, glm::ivec4
86 #include <glm/mat4x4.hpp> // glm::mat4
func(GLuint LocationMVP,float Translate,glm::vec2 const & Rotate)87 #include <glm/gtc/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale, glm::perspective
88 #include <glm/gtc/type_ptr.hpp> // glm::value_ptr
89 void func(GLuint LocationMVP, float Translate, glm::vec2 const & Rotate)
90 {
91 glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
92 glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
93 glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
94 glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
95 glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
96 glm::mat4 MVP = Projection * View * Model;
97 glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP));
98 }
99
100 // Sample 3
101 #include <glm/vec2.hpp>// glm::vec2
102 #include <glm/packing.hpp>// glm::packUnorm2x16
103 #include <glm/integer.hpp>// glm::uint
104 #include <glm/gtc/type_precision.hpp>// glm::i8vec2, glm::i32vec2
105 std::size_t const VertexCount = 4;
106 // Float quad geometry
107 std::size_t const PositionSizeF32 = VertexCount * sizeof(glm::vec2);
108 glm::vec2 const PositionDataF32[VertexCount] =
109 {
110 glm::vec2(-1.0f,-1.0f),
111 glm::vec2( 1.0f,-1.0f),
112 glm::vec2( 1.0f, 1.0f),
113 glm::vec2(-1.0f, 1.0f)
114 };
115 // Half-float quad geometry
116 std::size_t const PositionSizeF16 = VertexCount * sizeof(glm::uint);
117 glm::uint const PositionDataF16[VertexCount] =
118 {
119 glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, -1.0f))),
120 glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, -1.0f))),
121 glm::uint(glm::packUnorm2x16(glm::vec2( 1.0f, 1.0f))),
122 glm::uint(glm::packUnorm2x16(glm::vec2(-1.0f, 1.0f)))
123 };
124 // 8 bits signed integer quad geometry
125 std::size_t const PositionSizeI8 = VertexCount * sizeof(glm::i8vec2);
126 glm::i8vec2 const PositionDataI8[VertexCount] =
127 {
128 glm::i8vec2(-1,-1),
129 glm::i8vec2( 1,-1),
130 glm::i8vec2( 1, 1),
131 glm::i8vec2(-1, 1)
132 };
133 // 32 bits signed integer quad geometry
134 std::size_t const PositionSizeI32 = VertexCount * sizeof(glm::i32vec2);
135 glm::i32vec2 const PositionDataI32[VertexCount] =
136 {
137 glm::i32vec2 (-1,-1),
138 glm::i32vec2 ( 1,-1),
139 glm::i32vec2 ( 1, 1),
140 glm::i32vec2 (-1, 1)
141 };
142
143 struct intersection
144 {
145 glm::vec4 position;
146 glm::vec3 normal;
147 };
148
149 /*
150 // Sample 4
151 #include <glm/vec3.hpp>// glm::vec3
152 #include <glm/geometric.hpp>// glm::normalize, glm::dot, glm::reflect
153 #include <glm/exponential.hpp>// glm::pow
154 #include <glm/gtc/random.hpp>// glm::vecRand3
155 glm::vec3 lighting
156 (
157 intersection const & Intersection,
158 material const & Material,
159 light const & Light,
160 glm::vec3 const & View
161 )
162 {
163 glm::vec3 Color(0.0f);
164 glm::vec3 LightVertor(glm::normalize(
165 Light.position - Intersection.position +
166 glm::vecRand3(0.0f, Light.inaccuracy));
167
168 if(!shadow(Intersection.position, Light.position, LightVertor))
169 {
170 float Diffuse = glm::dot(Intersection.normal, LightVector);
171 if(Diffuse <= 0.0f)
172 return Color;
173 if(Material.isDiffuse())
174 Color += Light.color() * Material.diffuse * Diffuse;
175 if(Material.isSpecular())
176 {
177 glm::vec3 Reflect(glm::reflect(
178 glm::normalize(-LightVector),
179 glm::normalize(Intersection.normal)));
180 float Dot = glm::dot(Reflect, View);
181 float Base = Dot > 0.0f ? Dot : 0.0f;
182 float Specular = glm::pow(Base, Material.exponent);
183 Color += Material.specular * Specular;
184 }
185 }
186 return Color;
main()187 }
188 */
189 int main()
190 {
191 return 0;
192 }
193