25 switch (camera_rotation) {
44 for (GLint error = glGetError(); error; error = glGetError()) {
45 LOGE(
"after %s() glError (0x%x)\n", operation, error);
51 GLuint shader = glCreateShader(shader_type);
53 glShaderSource(shader, 1, &shader_source,
NULL);
54 glCompileShader(shader);
56 glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
59 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len);
61 char* buf = (
char*) malloc(info_len);
63 glGetShaderInfoLog(shader, info_len,
NULL, buf);
64 LOGE(
"Could not compile shader %d:\n%s\n", shader_type, buf);
67 glDeleteShader(shader);
76 const char* fragment_source) {
83 if (!fragment_shader) {
87 GLuint program = glCreateProgram();
89 glAttachShader(program, vertexShader);
91 glAttachShader(program, fragment_shader);
93 glLinkProgram(program);
95 glGetProgramiv(program, GL_LINK_STATUS, &link_status);
96 if (link_status != GL_TRUE) {
98 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &buf_length);
100 char* buf = (
char*) malloc(buf_length);
102 glGetProgramInfoLog(program, buf_length,
NULL, buf);
103 LOGE(
"Could not link program:\n%s\n", buf);
107 glDeleteProgram(program);
119 float scale_x =
glm::length(
glm::vec3( transform_mat[0][0], transform_mat[1][0], transform_mat[2][0] ) );
120 float scale_y =
glm::length(
glm::vec3( transform_mat[0][1], transform_mat[1][1], transform_mat[2][1] ) );
121 float scale_z =
glm::length(
glm::vec3( transform_mat[0][2], transform_mat[1][2], transform_mat[2][2] ) );
125 if( determinant < 0.0 )
128 translation.
x = transform_mat[3][0];
129 translation.
y = transform_mat[3][1];
130 translation.
z = transform_mat[3][2];
132 float inverse_scale_x = 1.0 / scale_x;
133 float inverse_scale_y = 1.0 / scale_y;
134 float inverse_scale_z = 1.0 / scale_z;
136 glm::mat4 transform_unscaled = transform_mat;
138 transform_unscaled[0][0] *= inverse_scale_x;
139 transform_unscaled[1][0] *= inverse_scale_x;
140 transform_unscaled[2][0] *= inverse_scale_x;
142 transform_unscaled[0][1] *= inverse_scale_y;
143 transform_unscaled[1][1] *= inverse_scale_y;
144 transform_unscaled[2][1] *= inverse_scale_y;
146 transform_unscaled[0][2] *= inverse_scale_z;
147 transform_unscaled[1][2] *= inverse_scale_z;
148 transform_unscaled[2][2] *= inverse_scale_z;
158 return glm::vec3(mat[col][0], mat[col][1], mat[col][2]);
162 return glm::vec3(mat[3][0], mat[3][1], mat[3][2]);
166 return value < min ? min : (value > max ? max : value);
172 for (i = 0; i < 4; i++) {
173 LOGI(
"[ %f, %f, %f, %f ]", matrix[0][i], matrix[1][i], matrix[2][i],
180 LOGI(
"[ %f, %f, %f ]", vector[0], vector[1], vector[2]);
185 LOGI(
"[ %f, %f, %f, %f ]", quat[0], quat[1], quat[2], quat[3]);
190 return x * (1.0f - a) + y * a;
202 float tmin, tmax, tymin, tymax, tzmin, tzmax;
204 if (direction.
x >= 0) {
205 tmin = (aabb_min.
x - start.x) / direction.
x;
206 tmax = (aabb_max.
x - start.x) / direction.
x;
208 tmin = (aabb_max.
x - start.x) / direction.
x;
209 tmax = (aabb_min.
x - start.x) / direction.
x;
211 if (direction.
y >= 0) {
212 tymin = (aabb_min.
y - start.y) / direction.
y;
213 tymax = (aabb_max.
y - start.y) / direction.
y;
215 tymin = (aabb_max.
y - start.y) / direction.
y;
216 tymax = (aabb_min.
y - start.y) / direction.
y;
218 if ((tmin > tymax) || (tymin > tmax))
return false;
220 if (tymin > tmin) tmin = tymin;
221 if (tymax < tmax) tmax = tymax;
222 if (direction.
z >= 0) {
223 tzmin = (aabb_min.
z - start.z) / direction.
z;
224 tzmax = (aabb_max.
z - start.z) / direction.
z;
226 tzmin = (aabb_max.
z - start.z) / direction.
z;
227 tzmax = (aabb_min.
z - start.z) / direction.
z;
229 if ((tmin > tzmax) || (tzmin > tmax))
return false;
231 if (tzmin > tmin) tmin = tzmin;
232 if (tzmax < tmax) tmax = tzmax;
234 return ((tmin < 1.0
f) && (tmax > 0));
static GLuint LoadShader(GLenum shader_type, const char *shader_source)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
glm::vec3 GetTranslationFromMatrix(const glm::mat4 &mat)
void PrintQuaternion(const glm::quat &quat)
highp_quat quat
Quaternion of default single-precision floating-point numbers.
int NormalizedColorCameraRotation(int camera_rotation)
GLM_FUNC_DECL T determinant(matType< T, P > const &m)
GLuint CreateProgram(const char *vertex_source, const char *fragment_source)
float DistanceSquared(const glm::vec3 &v1, const glm::vec3 &v2)
void PrintMatrix(const glm::mat4 &matrix)
glm::vec3 ApplyTransform(const glm::mat4 &mat, const glm::vec3 &vec)
float Clamp(float value, float min, float max)
glm::vec3 LerpVector(const glm::vec3 &x, const glm::vec3 &y, float a)
GLM_FUNC_DECL detail::tquat< T, P > quat_cast(detail::tmat3x3< T, P > const &x)
GLM_FUNC_DECL detail::tquat< T, P > rotation(detail::tvec3< T, P > const &orig, detail::tvec3< T, P > const &dest)
void PrintVector(const glm::vec3 &vector)
void CheckGlError(const char *operation)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
glm::vec3 GetColumnFromMatrix(const glm::mat4 &mat, const int col)
GLM_FUNC_DECL T dot(vecType< T, P > const &x, vecType< T, P > const &y)
bool SegmentAABBIntersect(const glm::vec3 &aabb_min, const glm::vec3 &aabb_max, const glm::vec3 &start, const glm::vec3 &end)
ULogger class and convenient macros.
GLM_FUNC_DECL genType::value_type length(genType const &x)
void DecomposeMatrix(const glm::mat4 &transform_mat, glm::vec3 &translation, glm::quat &rotation, glm::vec3 &scale)