bubbles #10
@ -6,6 +6,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include "Shader_Loader.h"
|
#include "Shader_Loader.h"
|
||||||
#include "Render_Utils.h"
|
#include "Render_Utils.h"
|
||||||
@ -41,11 +42,22 @@ Core::RenderContext fishContext;
|
|||||||
Core::RenderContext bubbleContext;
|
Core::RenderContext bubbleContext;
|
||||||
|
|
||||||
std::vector<glm::vec3> keyPoints({
|
std::vector<glm::vec3> keyPoints({
|
||||||
glm::vec3(15.0f, 5.0f, 15.0f),
|
glm::vec3(-18.0f, -10.0f, -10.0f),
|
||||||
glm::vec3(15.0f, 5.0f, -15.0f),
|
glm::vec3(-10.0f, -5.0f, -12.0f),
|
||||||
glm::vec3(-15.0f, 5.0f, -15.0f),
|
glm::vec3(8.0f, -3.0f, -3.0f),
|
||||||
glm::vec3(-15.0f, 5.0f, 15.0f),
|
glm::vec3(5.0f, 0.0f, 3.0f),
|
||||||
glm::vec3(15.0f, 5.0f, 15.0f),
|
glm::vec3(3.0f, 2.0f, 4.0f),
|
||||||
|
glm::vec3(8.0f, 5.0f, 9.0f),
|
||||||
|
glm::vec3(14.0f, 6.0f, 15.0f),
|
||||||
|
glm::vec3(15.0f, 12.0f, 12.0f),
|
||||||
|
glm::vec3(10.0f, 17.0f, 15.0f),
|
||||||
|
glm::vec3(5.0f, 10.0f, 7.0f),
|
||||||
|
glm::vec3(-1.0f, 4.0f, 8.0f),
|
||||||
|
glm::vec3(-8.0f, 0.0f, 3.0f),
|
||||||
|
glm::vec3(-12.0f, -6.0f, -3.0f),
|
||||||
|
glm::vec3(-15.0f, -8.0f, -6.0f),
|
||||||
|
|
||||||
|
glm::vec3(-18.0f, -10.0f, -10.0f),
|
||||||
});
|
});
|
||||||
|
|
||||||
std::vector<glm::quat> keyRotation;
|
std::vector<glm::quat> keyRotation;
|
||||||
@ -62,7 +74,7 @@ std::string skyboxTextures[6] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
float skyboxVerticeParameter = 20.0f;
|
float skyboxVerticeParameter = 20.0f;
|
||||||
float skyboxBoundary = 19.5f;
|
float skyboxBoundary = 18.5f;
|
||||||
|
|
||||||
float cubeVertices[] = {
|
float cubeVertices[] = {
|
||||||
// positions // normals
|
// positions // normals
|
||||||
@ -163,7 +175,7 @@ bool isInBoundaries(glm::vec3 nextPosition) {
|
|||||||
void keyboard(unsigned char key, int x, int y)
|
void keyboard(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
float angleSpeed = 10.f;
|
float angleSpeed = 10.f;
|
||||||
float moveSpeed = 0.1f;
|
float moveSpeed = 1.0f;
|
||||||
glm::vec3 nextPosition;
|
glm::vec3 nextPosition;
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
@ -224,10 +236,26 @@ glm::mat4 createCameraMatrix()
|
|||||||
return Core::createViewMatrixQuat(cameraPos, rotation);
|
return Core::createViewMatrixQuat(cameraPos, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 animationMatrix(float time) {
|
std::vector<glm::vec3> changeKeyPoints(std::vector<glm::vec3> keyPoints, glm::vec3 toChange) {
|
||||||
|
std::vector<glm::vec3> result;
|
||||||
|
int size = keyPoints.size();
|
||||||
|
glm::vec3 change;
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
change.x = keyPoints[i].x + toChange.x;
|
||||||
|
change.y = keyPoints[i].y + toChange.y;
|
||||||
|
change.z = keyPoints[i].z + toChange.z;
|
||||||
|
result.push_back(change);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 animationMatrix(float time, glm::vec3 change) {
|
||||||
float speed = 1.;
|
float speed = 1.;
|
||||||
time = time * speed;
|
time = time * speed;
|
||||||
std::vector<float> distances;
|
std::vector<float> distances;
|
||||||
|
std::vector<glm::vec3> newKeyPoints = changeKeyPoints(keyPoints, change);
|
||||||
float timeStep = 0;
|
float timeStep = 0;
|
||||||
for (int i = 0; i < keyPoints.size() - 1; i++) {
|
for (int i = 0; i < keyPoints.size() - 1; i++) {
|
||||||
timeStep += (keyPoints[i] - keyPoints[i + 1]).length();
|
timeStep += (keyPoints[i] - keyPoints[i + 1]).length();
|
||||||
@ -248,8 +276,7 @@ glm::mat4 animationMatrix(float time) {
|
|||||||
int size = keyPoints.size();
|
int size = keyPoints.size();
|
||||||
int rotationSize = keyRotation.size();
|
int rotationSize = keyRotation.size();
|
||||||
|
|
||||||
|
glm::vec3 pos = glm::catmullRom(newKeyPoints[std::max(0, (index-1)%size)], newKeyPoints[(index) % size], newKeyPoints[(index + 1) % size], newKeyPoints[(index + 2) % size], t);
|
||||||
glm::vec3 pos = glm::catmullRom(keyPoints[std::max(0, (index-1)%size)], keyPoints[(index) % size], keyPoints[(index + 1) % size], keyPoints[(index + 2) % size], t);
|
|
||||||
|
|
||||||
glm::quat divideByFour = glm::quat(0.25f, 0.25f, 0.25f, 0.25f);
|
glm::quat divideByFour = glm::quat(0.25f, 0.25f, 0.25f, 0.25f);
|
||||||
auto a1 = keyRotation[index % rotationSize] * glm::exp(-(glm::log(glm::inverse(keyRotation[index % rotationSize]) * keyRotation[std::max(0, (index - 1)%rotationSize)]) + glm::log(glm::inverse(keyRotation[index % rotationSize]) * keyRotation[(index + 1) % rotationSize])) * divideByFour);
|
auto a1 = keyRotation[index % rotationSize] * glm::exp(-(glm::log(glm::inverse(keyRotation[index % rotationSize]) * keyRotation[std::max(0, (index - 1)%rotationSize)]) + glm::log(glm::inverse(keyRotation[index % rotationSize]) * keyRotation[(index + 1) % rotationSize])) * divideByFour);
|
||||||
@ -258,7 +285,7 @@ glm::mat4 animationMatrix(float time) {
|
|||||||
|
|
||||||
auto animationRotation = glm::squad(keyRotation[index % rotationSize], keyRotation[(index + 1) % rotationSize], a1, a2, t);
|
auto animationRotation = glm::squad(keyRotation[index % rotationSize], keyRotation[(index + 1) % rotationSize], a1, a2, t);
|
||||||
|
|
||||||
glm::mat4 result = glm::translate(pos) * glm::mat4_cast(animationRotation);
|
glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(0.25f)) * glm::mat4_cast(animationRotation);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -326,11 +353,23 @@ void renderScene()
|
|||||||
glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation;
|
glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation;
|
||||||
|
|
||||||
glm::mat4 fishInitialTransformation = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
|
glm::mat4 fishInitialTransformation = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
|
||||||
glm::mat4 bubbleModelMatrix = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.05f));
|
glm::mat4 bubbleModelMatrix = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.005f));
|
||||||
|
|
||||||
drawObjectTexture(bubbleContext, bubbleModelMatrix, textureBubble);
|
drawObjectTexture(bubbleContext, bubbleModelMatrix, textureBubble);
|
||||||
|
|
||||||
drawObjectTexture(fishContext, animationMatrix(time + 15), textureFish);
|
glm::vec3 change1 = glm::vec3(0, 3, 0);
|
||||||
|
glm::vec3 change2 = glm::vec3(0, 0, 0);
|
||||||
|
glm::vec3 change3 = glm::vec3(3, 0, 0);
|
||||||
|
glm::vec3 change4 = glm::vec3(0, 2, 1);
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
if (time > -10) {
|
||||||
|
drawObjectTexture(fishContext, animationMatrix(time + 15, change1), textureFish);
|
||||||
|
drawObjectTexture(fishContext, animationMatrix(time + 15, change2), textureFish);
|
||||||
|
drawObjectTexture(fishContext, animationMatrix(time + 15, change3), textureFish);
|
||||||
|
drawObjectTexture(fishContext, animationMatrix(time + 15, change4), textureFish);
|
||||||
|
time -= 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
|
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
@ -415,7 +454,6 @@ void initKeyRotation() {
|
|||||||
oldRotationCamera = rotation;
|
oldRotationCamera = rotation;
|
||||||
}
|
}
|
||||||
keyRotation.push_back(glm::quat(1, 0, 0, 0));
|
keyRotation.push_back(glm::quat(1, 0, 0, 0));
|
||||||
keyRotation.push_back(glm::quat(1, -1, 1, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCube()
|
void initCube()
|
||||||
|
Loading…
Reference in New Issue
Block a user