/*! Create a normalized direction vector for an arbitraty set of rotation angles. \param[in,out] dst The resulting direction vector will be stored in this variable. \param[in] up_axis The up axis. \param[in] rotx The X angle in degree. \param[in] roty The Y angle in degree. \param[in] rotz The Z angle in degree. */ void create_direction_vector( vec3 *dst, vec3 *up_axis, float rotx, float roty, float rotz ) { vec4 rotation; mat4 m; mat4_identity( &m ); rotation.z = 1.0f; rotation.x = rotation.y = 0.0f; rotation.w = rotz; mat4_rotate( &m, &m, &rotation ); rotation.y = 1.0f; rotation.x = rotation.z = 0.0f; rotation.w = roty; mat4_rotate( &m, &m, &rotation ); rotation.x = 1.0f; rotation.y = rotation.z = 0.0f; rotation.w = rotx; mat4_rotate( &m, &m, &rotation ); vec3_invert( up_axis, up_axis ); vec3_multiply_mat4( dst, up_axis, &m ); }
void material_draw_callback(void *ptr) { OBJMATERIAL *objmaterial = (OBJMATERIAL *) ptr; PROGRAM *program = objmaterial->program; unsigned int i = 0; while (i != program->uniform_count) { if (!strcmp(program->uniform_array[i].name, "DIFFUSE")) { glUniform1i(program->uniform_array[i].location, 1); } else if (!strcmp(program->uniform_array[i].name, "MODELVIEWPROJECTIONMATRIX")) { glUniformMatrix4fv(program->uniform_array[i].location, 1, GL_FALSE, (float *)GFX_get_modelview_projection_matrix()); } else if (!strcmp(program->uniform_array[i].name, "DISSOLVE")) { glUniform1f(program->uniform_array[i].location, objmaterial->dissolve); } else if (!strcmp(program->uniform_array[i].name, "AMBIENT_COLOR")) { glUniform3fv(program->uniform_array[i].location, 1, (float *)&objmaterial->ambient); } else if (!strcmp(program->uniform_array[i].name, "DIFFUSE_COLOR")) { glUniform3fv(program->uniform_array[i].location, 1, (float *)&objmaterial->diffuse); } else if (!strcmp(program->uniform_array[i].name, "SPECULAR_COLOR")) { glUniform3fv(program->uniform_array[i].location, 1, (float *)&objmaterial->specular); } else if (!strcmp(program->uniform_array[i].name, "SHININESS")) { glUniform1f(program->uniform_array[i].location, objmaterial->specular_exponent * 0.128f); } else if (!strcmp(program->uniform_array[i].name, "MODELVIEWMATRIX")) { glUniformMatrix4fv(program->uniform_array[i].location, 1, GL_FALSE, (float *)GFX_get_modelview_matrix()); } else if (!strcmp(program->uniform_array[i].name, "PROJECTIONMATRIX")) { glUniformMatrix4fv(program->uniform_array[i].location, 1, GL_FALSE, (float *)GFX_get_projection_matrix()); } else if (!strcmp(program->uniform_array[i].name, "NORMALMATRIX")) { glUniformMatrix3fv(program->uniform_array[i].location, 1, GL_FALSE, (float *)GFX_get_normal_matrix()); } else if (!strcmp(program->uniform_array[i].name, "LIGHTPOSITION")) { vec3 position = { 0.0f, -3.0f, 10.0f }; vec3 eyeposition = { 0.0f, 0.0f, 0.0f }; vec3_multiply_mat4(&eyeposition, &position, &gfx.modelview_matrix[gfx.modelview_matrix_index - 1]); glUniform3fv(program->uniform_array[i].location, 1, (float *)&eyeposition); } ++i; } }
void LAMP_get_direction_in_eye_space( LAMP *lamp, mat4 *m, vec3 *direction ) { vec3_multiply_mat4( direction, &lamp->direction, m ); vec3_invert( direction, direction ); }