create blue bubbles from floor to ceiling
This commit is contained in:
parent
537681ccaa
commit
bde06c173d
@ -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;
|
||||
@ -167,8 +181,8 @@ float skyboxVertices[] = {
|
||||
|
||||
|
||||
bool isInBoundaries(glm::vec3 nextPosition) {
|
||||
return nextPosition.z > -skyboxBoundary && nextPosition.z < skyboxBoundary && nextPosition.y > -skyboxBoundary &&
|
||||
nextPosition.y < skyboxBoundary && nextPosition.x < skyboxBoundary && nextPosition.x > -skyboxBoundary;
|
||||
return nextPosition.z > -skyboxBoundary && nextPosition.z < skyboxBoundary&& nextPosition.y > -skyboxBoundary &&
|
||||
nextPosition.y < skyboxBoundary&& nextPosition.x < skyboxBoundary&& nextPosition.x > -skyboxBoundary;
|
||||
}
|
||||
|
||||
|
||||
@ -181,25 +195,25 @@ void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
case 'z': cursorDiff.z -= angleSpeed; break;
|
||||
case 'x': cursorDiff.z += angleSpeed; break;
|
||||
case 'w':
|
||||
case 'w':
|
||||
nextPosition = cameraPos + (cameraDir * moveSpeed);
|
||||
if (isInBoundaries(nextPosition)) {
|
||||
cameraPos = nextPosition;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
case 's':
|
||||
nextPosition = cameraPos - (cameraDir * moveSpeed);
|
||||
if (isInBoundaries(nextPosition)) {
|
||||
cameraPos = nextPosition;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
case 'd':
|
||||
nextPosition = cameraPos + (cameraSide * moveSpeed);
|
||||
if (isInBoundaries(nextPosition)) {
|
||||
cameraPos = nextPosition;
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
case 'a':
|
||||
nextPosition = cameraPos - (cameraSide * moveSpeed);
|
||||
if (isInBoundaries(nextPosition)) {
|
||||
cameraPos = nextPosition;
|
||||
@ -208,6 +222,9 @@ void keyboard(unsigned char key, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void mouse(int x, int y)
|
||||
{
|
||||
if (old_x >= 0) {
|
||||
@ -247,12 +264,12 @@ std::vector<glm::vec3> changeKeyPoints(std::vector<glm::vec3> keyPoints, glm::ve
|
||||
change.z = keyPoints[i].z + toChange.z;
|
||||
result.push_back(change);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -276,16 +293,16 @@ glm::mat4 animationMatrix(float time, glm::vec3 change) {
|
||||
int size = keyPoints.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(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);
|
||||
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 a2 = keyRotation[(index + 1) % rotationSize] * glm::exp(-(glm::log(glm::inverse(keyRotation[(index + 1) % rotationSize]) * keyRotation[index % rotationSize]) + glm::log(glm::inverse(keyRotation[(index + 1) % rotationSize]) * keyRotation[(index + 2) % rotationSize])) * divideByFour);
|
||||
|
||||
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
|
||||
@ -472,12 +499,12 @@ void initCube()
|
||||
void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
programColor = shaderLoader.CreateProgram((char*) "shaders/shader_color.vert", (char*) "shaders/shader_color.frag");
|
||||
programTexture = shaderLoader.CreateProgram((char*) "shaders/shader_tex.vert", (char*) "shaders/shader_tex.frag");
|
||||
skyboxProgram = shaderLoader.CreateProgram((char *) "shaders/skybox.vert", (char *) "shaders/skybox.frag");
|
||||
programColor = shaderLoader.CreateProgram((char*)"shaders/shader_color.vert", (char*)"shaders/shader_color.frag");
|
||||
programTexture = shaderLoader.CreateProgram((char*)"shaders/shader_tex.vert", (char*)"shaders/shader_tex.frag");
|
||||
skyboxProgram = shaderLoader.CreateProgram((char*)"shaders/skybox.vert", (char*)"shaders/skybox.frag");
|
||||
cubeProgram = shaderLoader.CreateProgram((char*)"shaders/bubble.vert", (char*)"shaders/bubble.frag");
|
||||
cubemapTexture = loadCubemap();
|
||||
|
||||
|
||||
loadModelToContext("models/submarine.obj", submarineContext);
|
||||
textureSubmarine = Core::LoadTexture("textures/submarine.png");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user