bubbles #10

Merged
s452667 merged 20 commits from bubbles into master 2022-01-08 19:56:25 +01:00
Showing only changes of commit bde06c173d - Show all commits

View File

@ -27,7 +27,9 @@ unsigned int cubeVAO, cubeVBO;
float old_x, old_y = -1;
glm::vec3 cursorDiff;
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -10.f, -1.0f));
glm::vec3 cameraPos = glm::vec3(0, 0, 5);
glm::vec3 cameraPos = glm::vec3(0, 0, 0);
glm::vec3 oldCameraPos = glm::vec3(0, 0, 5);
glm::vec3 cameraDir; // Wektor "do przodu" kamery
glm::vec3 cameraSide; // Wektor "w bok" kamery
float cameraAngle = 0;
@ -41,7 +43,7 @@ Core::RenderContext submarineContext;
Core::RenderContext fishContext;
Core::RenderContext bubbleContext;
std::vector<glm::vec3> keyPoints({
std::vector<glm::vec3> fishKeyPoints({
glm::vec3(-18.0f, -10.0f, -10.0f),
glm::vec3(-10.0f, -5.0f, -12.0f),
glm::vec3(8.0f, -3.0f, -3.0f),
@ -56,10 +58,22 @@ 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::vec3> bubbleKeyPoints({
glm::vec3(-0, -17.0f, 0),
glm::vec3(-0, 17.0f, 0),
});
std::vector<glm::quat> keyRotation;
std::vector<Core::Node> fish;
@ -208,6 +222,9 @@ void keyboard(unsigned char key, int x, int y)
}
}
void mouse(int x, int y)
{
if (old_x >= 0) {
@ -251,8 +268,8 @@ std::vector<glm::vec3> changeKeyPoints(std::vector<glm::vec3> keyPoints, glm::ve
return result;
}
glm::mat4 animationMatrix(float time, glm::vec3 change) {
float speed = 1.;
glm::mat4 animationMatrix(float time, glm::vec3 change, std::vector<glm::vec3> keyPoints, glm::vec3 scaleValue, float speed) {
time = time * speed;
std::vector<float> distances;
std::vector<glm::vec3> newKeyPoints = changeKeyPoints(keyPoints, change);
@ -285,7 +302,7 @@ glm::mat4 animationMatrix(float time, glm::vec3 change) {
auto animationRotation = glm::squad(keyRotation[index % rotationSize], keyRotation[(index + 1) % rotationSize], a1, a2, t);
glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(0.25f)) * glm::mat4_cast(animationRotation);
glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(scaleValue)) * glm::mat4_cast(animationRotation);
return result;
}
@ -326,6 +343,7 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
glUseProgram(0);
}
void renderScene()
{
cameraMatrix = createCameraMatrix();
@ -349,27 +367,36 @@ void renderScene()
//glDrawArrays(GL_TRIANGLES, 0, 36);
//glBindVertexArray(0);
glm::mat4 submarineInitialTransformation = glm::translate(glm::vec3(0, -0.5, -0.4)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
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 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);
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);
glm::vec3 change5 = glm::vec3(0, 1, 0);
glm::vec3 change6 = glm::vec3(0, 0, 0);
glm::vec3 change7 = glm::vec3(1, 0, 0);
glm::vec3 change8 = glm::vec3(0, 1, 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);
drawObjectTexture(fishContext, animationMatrix(time + 15, change1, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
drawObjectTexture(fishContext, animationMatrix(time + 15, change2, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
drawObjectTexture(fishContext, animationMatrix(time + 15, change3, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
drawObjectTexture(fishContext, animationMatrix(time + 15, change4, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish);
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change5, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), textureBubble);
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change6, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), textureBubble);
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change7, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), textureBubble);
time -= 6;
}
}
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
glutSwapBuffers();
}
@ -442,9 +469,9 @@ void initKeyRotation() {
glm::quat oldRotationCamera = glm::quat(1, 0, 0, 0);
glm::vec3 direction;
glm::quat rotation;
for (int i = 0; i < keyPoints.size() - 1; i++) {
for (int i = 0; i < fishKeyPoints.size() - 1; i++) {
//3.1
direction = glm::normalize(keyPoints[i + 1] - keyPoints[i]);
direction = glm::normalize(fishKeyPoints[i + 1] - fishKeyPoints[i]);
//3.2
rotation = glm::normalize(glm::rotationCamera(oldDirection, direction) * oldRotationCamera);
//3.3