Add shoal
This commit is contained in:
parent
8821c01e2f
commit
3ee0d0d64e
@ -6,6 +6,7 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
@ -58,7 +59,7 @@ std::string skyboxTextures[6] = {
|
||||
};
|
||||
|
||||
float skyboxVerticeParameter = 20.0f;
|
||||
float skyboxBoundary = 19.5f;
|
||||
float skyboxBoundary = 18.5f;
|
||||
|
||||
float skyboxVertices[] = {
|
||||
-skyboxVerticeParameter, skyboxVerticeParameter, -skyboxVerticeParameter,
|
||||
@ -114,7 +115,7 @@ bool isInBoundaries(glm::vec3 nextPosition) {
|
||||
void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
float angleSpeed = 10.f;
|
||||
float moveSpeed = 0.1f;
|
||||
float moveSpeed = 1.0f;
|
||||
glm::vec3 nextPosition;
|
||||
switch (key)
|
||||
{
|
||||
@ -175,10 +176,27 @@ glm::mat4 createCameraMatrix()
|
||||
return Core::createViewMatrixQuat(cameraPos, rotation);
|
||||
}
|
||||
|
||||
glm::mat4 animationMatrix(float time) {
|
||||
std::vector<glm::vec3> changeKeyPoints(std::vector<glm::vec3> keyPoints, glm::vec3 toChange) {
|
||||
//void test(){
|
||||
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.;
|
||||
time = time * speed;
|
||||
std::vector<float> distances;
|
||||
std::vector<glm::vec3> newKeyPoints = changeKeyPoints(keyPoints, change);
|
||||
float timeStep = 0;
|
||||
for (int i = 0; i < keyPoints.size() - 1; i++) {
|
||||
timeStep += (keyPoints[i] - keyPoints[i + 1]).length();
|
||||
@ -199,9 +217,7 @@ glm::mat4 animationMatrix(float time) {
|
||||
int size = keyPoints.size();
|
||||
int rotationSize = keyRotation.size();
|
||||
|
||||
std::cout << (index - 1) % size << " " << index % size << " " << (index+1)%size << " " << (index+2)%size << std::endl;
|
||||
|
||||
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::vec3 pos = glm::catmullRom(newKeyPoints[std::max(0, (index-1)%size)], newKeyPoints[(index) % size], newKeyPoints[(index + 1) % size], newKeyPoints[(index + 2) % size], t);
|
||||
|
||||
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);
|
||||
@ -272,9 +288,16 @@ void renderScene()
|
||||
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::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), textureFish);
|
||||
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 -= 3;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user