25 switch (camera_rotation) {
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] ) );
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;
172 for (
i = 0;
i < 4;
i++) {
180 LOGI(
"[ %f, %f, %f ]", vector[0], vector[1], vector[2]);
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));