remove transition at the end, show frustum from the start
This commit is contained in:
parent
31e9a41970
commit
f90461b587
53
src/main.c
53
src/main.c
|
@ -35,7 +35,7 @@ GLuint initialWindowHeight = 600;
|
||||||
GLfloat aspect;
|
GLfloat aspect;
|
||||||
mat4 realProjectionMatrix;
|
mat4 realProjectionMatrix;
|
||||||
|
|
||||||
GLfloat currentHue = 0.0f;
|
GLfloat currentTime = 0.0f;
|
||||||
|
|
||||||
int frameCount = 0;
|
int frameCount = 0;
|
||||||
struct timespec last_time, current_time;
|
struct timespec last_time, current_time;
|
||||||
|
@ -87,7 +87,7 @@ void updateStatusDisplay() {
|
||||||
double fps = frameCount / elapsed;
|
double fps = frameCount / elapsed;
|
||||||
frameCount = 0;
|
frameCount = 0;
|
||||||
last_time = current_time;
|
last_time = current_time;
|
||||||
printf("\rFPS: %5.2f - currentValue: %5.2f", fps, currentHue);
|
printf("\rFPS: %5.2f - currentTime: %5.2f", fps, currentTime);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,6 +347,7 @@ void draw(void) {
|
||||||
// 0.35 done
|
// 0.35 done
|
||||||
// 0.4 start projection
|
// 0.4 start projection
|
||||||
// 0.45 done
|
// 0.45 done
|
||||||
|
// 0.55 - repeat
|
||||||
updateStatusDisplay();
|
updateStatusDisplay();
|
||||||
|
|
||||||
mat4 identity;
|
mat4 identity;
|
||||||
|
@ -356,13 +357,13 @@ void draw(void) {
|
||||||
// mat4Interpolate(projectionMatrix, identity, projectionMatrix, mapTo01(currentHue, 0.0f, 0.1f));
|
// mat4Interpolate(projectionMatrix, identity, projectionMatrix, mapTo01(currentHue, 0.0f, 0.1f));
|
||||||
|
|
||||||
// counter for animation
|
// counter for animation
|
||||||
currentHue += 0.0001f;
|
currentTime += 0.0001f;
|
||||||
int state = glfwGetKey(window, GLFW_KEY_SPACE);
|
int state = glfwGetKey(window, GLFW_KEY_SPACE);
|
||||||
if (state == GLFW_PRESS)
|
if (state == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
currentHue += 0.001f;
|
currentTime += 0.001f;
|
||||||
}
|
}
|
||||||
if (currentHue > 1.0) currentHue = 0.0f;
|
if (currentTime > 0.55f) currentTime = 0.0f;
|
||||||
|
|
||||||
// clear colour and depth buffer
|
// clear colour and depth buffer
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
@ -372,7 +373,7 @@ void draw(void) {
|
||||||
mat4 viewMatrix;
|
mat4 viewMatrix;
|
||||||
|
|
||||||
// mat4Identity(viewMatrix);
|
// mat4Identity(viewMatrix);
|
||||||
vec3 cameraPos = {cos(currentHue * 6 * M_PI) * 3.0f, 3.0f + sin(currentHue * 12 * M_PI) * 0.5, sin(currentHue * 6 * M_PI) * 3.0f};
|
vec3 cameraPos = {cos(currentTime * 6 * M_PI) * 3.0f, 3.0f + sin(currentTime * 12 * M_PI) * 0.5, sin(currentTime * 6 * M_PI) * 3.0f};
|
||||||
vec3 cameraLookAt = {0.0f, 0.0f, 0.0f};
|
vec3 cameraLookAt = {0.0f, 0.0f, 0.0f};
|
||||||
vec3 cameraUp = {0.0f, 1.0f, 0.0f};
|
vec3 cameraUp = {0.0f, 1.0f, 0.0f};
|
||||||
mat4BuildLookAt(viewMatrix, cameraPos, cameraLookAt, cameraUp);
|
mat4BuildLookAt(viewMatrix, cameraPos, cameraLookAt, cameraUp);
|
||||||
|
@ -382,32 +383,32 @@ void draw(void) {
|
||||||
vec3 virtualCameraLookAt = {0.0f, 0.0f, -1.0f};
|
vec3 virtualCameraLookAt = {0.0f, 0.0f, -1.0f};
|
||||||
|
|
||||||
// calculate virtual lookAt and projection
|
// calculate virtual lookAt and projection
|
||||||
mat4 virtualCameraMatrix;
|
mat4 virtualViewMatrix;
|
||||||
mat4 virtualProjectionMatrix;
|
mat4 virtualProjectionMatrix;
|
||||||
mat4BuildLookAt(virtualCameraMatrix, virtualCameraPosition, virtualCameraLookAt, cameraUp);
|
mat4BuildLookAt(virtualViewMatrix, virtualCameraPosition, virtualCameraLookAt, cameraUp);
|
||||||
mat4BuildPerspective(virtualProjectionMatrix, 60 * M_PI / 180, aspect, 1, 4);
|
mat4BuildPerspective(virtualProjectionMatrix, 60 * M_PI / 180, aspect, 1, 4);
|
||||||
|
|
||||||
|
mat4 inverseVirtualView;
|
||||||
|
mat4Inverse(inverseVirtualView, virtualViewMatrix);
|
||||||
|
mat4Interpolate(inverseVirtualView, inverseVirtualView, identity, mapTo01(currentTime, 0.3f, 0.35f));
|
||||||
|
|
||||||
|
mat4 inverseVirtualProjection;
|
||||||
|
mat4Inverse(inverseVirtualProjection, virtualProjectionMatrix);
|
||||||
|
|
||||||
mat4 viewFrustumModelView;
|
mat4 viewFrustumModelView;
|
||||||
mat4Inverse(viewFrustumModelView, virtualProjectionMatrix);
|
mat4Multiply(viewFrustumModelView, inverseVirtualView, inverseVirtualProjection);
|
||||||
|
|
||||||
mat3 mat3CameraRotationMatrix;
|
mat3 mat3CameraRotationMatrix;
|
||||||
mat3From4(mat3CameraRotationMatrix, virtualCameraMatrix);
|
mat3From4(mat3CameraRotationMatrix, virtualViewMatrix);
|
||||||
mat3Inverse(mat3CameraRotationMatrix, mat3CameraRotationMatrix);
|
mat3Inverse(mat3CameraRotationMatrix, mat3CameraRotationMatrix);
|
||||||
mat4 cameraRotationMatrix;
|
mat4 cameraRotationMatrix;
|
||||||
mat4From3(cameraRotationMatrix, mat3CameraRotationMatrix);
|
mat4From3(cameraRotationMatrix, mat3CameraRotationMatrix);
|
||||||
|
|
||||||
mat4Interpolate(projectionMatrix, virtualProjectionMatrix, realProjectionMatrix, mapTo01(currentHue, 0.1f, 0.15f));
|
mat4Interpolate(projectionMatrix, virtualProjectionMatrix, realProjectionMatrix, mapTo01(currentTime, 0.1f, 0.15f));
|
||||||
mat4Interpolate(viewMatrix, virtualCameraMatrix, viewMatrix, mapTo01(currentHue, 0.1f, 0.15f));
|
mat4Interpolate(viewMatrix, virtualViewMatrix, viewMatrix, mapTo01(currentTime, 0.1f, 0.15f));
|
||||||
|
|
||||||
mat4Interpolate(projectionMatrix, projectionMatrix, virtualProjectionMatrix, mapTo01(currentHue, 0.7f, 0.75f));
|
|
||||||
mat4Interpolate(viewMatrix, viewMatrix, virtualCameraMatrix, mapTo01(currentHue, 0.7f, 0.75f));
|
|
||||||
|
|
||||||
mat4Interpolate(virtualCameraMatrix, identity, virtualCameraMatrix, mapTo01(currentHue, 0.3f, 0.35f));
|
|
||||||
mat4Interpolate(virtualProjectionMatrix, identity, virtualProjectionMatrix, mapTo01(currentHue, 0.4f, 0.45f) * mapTo01(currentHue, 0.4f, 0.45f));
|
|
||||||
|
|
||||||
mat4Interpolate(virtualCameraMatrix, virtualCameraMatrix, identity, mapTo01(currentHue, 0.7f, 0.75f));
|
|
||||||
mat4Interpolate(virtualProjectionMatrix, virtualProjectionMatrix, identity, mapTo01(currentHue, 0.7f, 0.75f));
|
|
||||||
|
|
||||||
|
mat4Interpolate(virtualViewMatrix, identity, virtualViewMatrix, mapTo01(currentTime, 0.3f, 0.35f));
|
||||||
|
mat4Interpolate(virtualProjectionMatrix, identity, virtualProjectionMatrix, mapTo01(currentTime, 0.4f, 0.45f) * mapTo01(currentTime, 0.4f, 0.45f));
|
||||||
|
|
||||||
|
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
@ -433,7 +434,7 @@ void draw(void) {
|
||||||
vec3Set(position, -0.3f, 0.5f, -0.4f);
|
vec3Set(position, -0.3f, 0.5f, -0.4f);
|
||||||
mat4Translate(modelMatrix, modelMatrix, position);
|
mat4Translate(modelMatrix, modelMatrix, position);
|
||||||
|
|
||||||
mat4Multiply(modelMatrix, virtualCameraMatrix, modelMatrix);
|
mat4Multiply(modelMatrix, virtualViewMatrix, modelMatrix);
|
||||||
mat4Multiply(modelMatrix, virtualProjectionMatrix, modelMatrix);
|
mat4Multiply(modelMatrix, virtualProjectionMatrix, modelMatrix);
|
||||||
|
|
||||||
glUniform1f(brightnessLocation, 1.0f);
|
glUniform1f(brightnessLocation, 1.0f);
|
||||||
|
@ -450,7 +451,7 @@ void draw(void) {
|
||||||
vec3Set(position, -0.9f, 0.3f, -3.8f);
|
vec3Set(position, -0.9f, 0.3f, -3.8f);
|
||||||
mat4Translate(modelMatrix, modelMatrix, position);
|
mat4Translate(modelMatrix, modelMatrix, position);
|
||||||
|
|
||||||
mat4Multiply(modelMatrix, virtualCameraMatrix, modelMatrix);
|
mat4Multiply(modelMatrix, virtualViewMatrix, modelMatrix);
|
||||||
mat4Multiply(modelMatrix, virtualProjectionMatrix, modelMatrix);
|
mat4Multiply(modelMatrix, virtualProjectionMatrix, modelMatrix);
|
||||||
|
|
||||||
glUniform1f(brightnessLocation, 1.0f);
|
glUniform1f(brightnessLocation, 1.0f);
|
||||||
|
@ -468,11 +469,11 @@ void draw(void) {
|
||||||
mat4Multiply(modelMatrix, cameraRotationMatrix, modelMatrix);
|
mat4Multiply(modelMatrix, cameraRotationMatrix, modelMatrix);
|
||||||
|
|
||||||
mat4Translate(modelMatrix, modelMatrix, virtualCameraPosition);
|
mat4Translate(modelMatrix, modelMatrix, virtualCameraPosition);
|
||||||
mat4Multiply(modelMatrix, virtualCameraMatrix, modelMatrix);
|
mat4Multiply(modelMatrix, virtualViewMatrix, modelMatrix);
|
||||||
|
|
||||||
glUniform1f(brightnessLocation, 0.0f);
|
glUniform1f(brightnessLocation, 0.0f);
|
||||||
|
|
||||||
if (currentHue < 0.37f) {
|
if (currentTime < 0.37f) {
|
||||||
drawCube(modelMatrix, viewMatrix);
|
drawCube(modelMatrix, viewMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,7 +491,7 @@ void draw(void) {
|
||||||
glLineWidth(5.0f);
|
glLineWidth(5.0f);
|
||||||
glDrawArrays(GL_LINES, 0, 6);
|
glDrawArrays(GL_LINES, 0, 6);
|
||||||
|
|
||||||
if (currentHue > 0.35f && currentHue < 0.65) {
|
if (currentTime < 0.65) {
|
||||||
mat4Multiply(viewFrustumModelView, virtualProjectionMatrix, viewFrustumModelView);
|
mat4Multiply(viewFrustumModelView, virtualProjectionMatrix, viewFrustumModelView);
|
||||||
mat4Multiply(viewFrustumModelView, viewMatrix, viewFrustumModelView);
|
mat4Multiply(viewFrustumModelView, viewMatrix, viewFrustumModelView);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue