void DrawLight(void)
{
M_Translation.Translate(light_pos_model.x, light_pos_model.y, light_pos_model.z); // Position of the point sprite object
// M_Rotation.Rotate(rotation, 0.0f, 1.0f, 0.0f); // Orbit the point object around Y axis
// M_Rotation_Light.Rotate(-rotation, 0.0f, 1.0f, 0.0f); // WORKS BUT ONLY IF THE VIEW DOESN'T CHANGE
Lighting(); // Perform the matrix operations
// Load the vertex data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, triangle);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, triangle_colour);
// glDisable(GL_CULL_FACE);
// Render the object
glDrawArrays(GL_POINTS, 0, 1);
// glDrawArrays(GL_TRIANGLES, 0, 3);
// glEnable(GL_CULL_FACE);
}
void DrawBox(void)
{
M_Modelview.LoadIdentity(); // Reset the ModelView matrix
M_ModelviewProj.LoadIdentity(); // Reset the ModelViewProjecion matrix
M_Translation.Translate(-5.0f, 0.0f, -15.0f); // Translate 15 units into the screen and 5 units to the left
M_Rotation.BuildMatrixFromQuaternion(quat); // Build the rotation matrix
M_Rotation.LoadIdentity(); // TEMP
Transform(); // Perform the matrix transformations
box_test.DrawLWO(); // Draw the box object
}
void DrawCar(void)
{
M_Modelview.LoadIdentity(); // Reset the ModelView matrix
M_ModelviewProj.LoadIdentity(); // Reset the ModelViewProjecion matrix
M_Translation.Translate(6.0f, 0.0f, -15.0f); // Translate 15 units into the screen and 6 units to the right
M_Rotation.BuildMatrixFromQuaternion(quat); // Build our rotation matrix from the quaternion 'quat'
M_Rotation.LoadIdentity(); // TEMP
Transform(); // Perform the matrix transformations
car_test.DrawLWO(); // Draw the car object
}
void Draw3D(void)
{
DrawLight();
DrawBox();
DrawCar();
}
void Transform(void)
{
M_Modeling = M_Translation * M_Rotation; // OPPOSITE ORDER IS COMPUTED: ROTATION -> TRANSLATION
M_Modelview = M_Viewing * M_Modeling; // Combine the Modeling Matrix and the Viewing Matrix (Model -> View)
M_Modelview.GetMatrix(mv_Matrix); // Save the Modelview matrix in mv_Matrix
M_ModelviewProj = M_Projection * M_Modelview; // MODELVIEW MUST BE COMPUTED FIRST! MODELVIEW -> PROJECTION
M_ModelviewProj.GetMatrix(mvp_Matrix); // Save the final Modelview Projection matrix in mvp_Matrix
glUseProgram(lightProgram); // START THE SHADER HERE!
glUniformMatrix4fv(mv_Location, 1, GL_FALSE, mv_Matrix); // Must be called AFTER glUseProgram (For conversion to eye-space)
glUniformMatrix4fv(mvp_Location, 1, GL_FALSE, mvp_Matrix); // Must be called AFTER glUseProgram (For conveersion to clip-space)
// glUniformMatrix4fv(inv_Location, 1, GL_FALSE, inv_Matrix); // Must be called AFTER glUseProgram (For conveersion to clip-space)
glUniform3f(light_Location, light_pos[0], light_pos[1], light_pos[2]); // TEST!!
}
void Lighting(void)
{
M_LightMatrix = M_Rotation * M_Translation; // Calculate the light matrix for model-space transformation
M_Modelview = M_Viewing * M_LightMatrix; // This calculation transforms the point sprite object into eye-space
M_ModelviewProj = M_Projection * M_Modelview; // MODELVIEW MUST BE COMPUTED FIRST! MODELVIEW -> PROJECTION
M_ModelviewProj.GetMatrix(mvp_Matrix); // Save the final Modelview Projection matrix in mvp_Matrix
/********* T E S T I N G ********/
M_LightMatrix = M_Rotation_Light * M_Translation;
/********************************/
light_pos_world = M_LightMatrix * light_pos_model; // Convert the light position from object-space to world-space
light_pos_eye = M_Viewing * light_pos_world; // Convert the light position from world-space to eye-space
// light_pos[0] = light_pos_world.x;
// light_pos[1] = light_pos_world.y;
// light_pos[2] = light_pos_world.z;
light_pos[0] = light_pos_eye.x;
light_pos[1] = light_pos_eye.y;
light_pos[2] = light_pos_eye.z;
glEnableVertexAttribArray(0); // Enable the vertex position attribute array
glEnableVertexAttribArray(1); // Enable the vertex colour attribute array
glUseProgram(basicProgram); // START THE SHADER HERE!
glUniformMatrix4fv(basic_mvp_Handle, 1, GL_FALSE, mvp_Matrix); // Must be called AFTER glUseProgram
glUniform3f(light_Location, light_pos[0], light_pos[1], light_pos[2]); // TEST!!
}