feat(1): Task 1

This commit is contained in:
Tibo De Peuter 2024-12-05 22:00:22 +01:00
parent 42a3ed61e9
commit bc480fdcaa
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
7 changed files with 55 additions and 14 deletions

View file

@ -10,6 +10,10 @@ void main()
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code:
color = vec3(1,1,1);
if (is_moon) {
color = vec3(0.5,0.45,0.5);
} else {
color = vec3(0.2,0.3,0.8);
}
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -5,12 +5,8 @@ mat4 identity()
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code
return mat4(
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0);
// Based on:
// https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Matrix_constructors
return mat4(1.0);
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -19,6 +19,25 @@ mat4 model(bool is_moon, float time)
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code
return identity();
if (!is_moon) {
return identity();
}
// Based on:
// https://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#cumulating-transformations
mat4 scale_matrix = uniform_scale(0.30);
float r = 2.0;
mat4 translation_matrix = translate(vec3(r, 0, 0));
// TODO Why is PI not defined?
float full_rotation = 2 * 3.14159;
float theta = full_rotation * time / 4.0;
mat4 rotation_matrix = rotate_about_y(theta);
// Small hack to make the moon rotate around the origin
// Usually you would rotate first, then translate
return rotation_matrix * translation_matrix * scale_matrix;
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -17,6 +17,10 @@ void main()
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code
pos_cs_in = vec4(pos_vs_in,1.0);
// Object in world
vec4 pos_vs = model(is_moon, animation_seconds) * vec4(pos_vs_in, 1.0);
// world -> eye -> screen
pos_cs_in = proj * view * pos_vs;
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -6,7 +6,14 @@ mat4 rotate_about_y(float theta)
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code
return identity();
// Based on:
// https://en.wikipedia.org/wiki/Rotation_matrix#Basic_3D_rotations
return mat4(
cos(theta), 0, sin(theta), 0,
0, 1, 0, 0,
-sin(theta), 0, cos(theta), 0,
0, 0, 0, 1
);
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -5,7 +5,15 @@ mat4 translate(vec3 t)
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code
return identity();
// Based on:
// https://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#translation-matrices
// and README
return mat4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
t.x, t.y, t.z, 1
);
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -6,7 +6,10 @@ mat4 uniform_scale(float s)
{
/////////////////////////////////////////////////////////////////////////////
// Replace with your code
return identity();
// Based on:
// https://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#scaling-matrices
// and
// https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Matrix_constructors
return mat4(mat3(s));
/////////////////////////////////////////////////////////////////////////////
}