add more bubbles

This commit is contained in:
Thyme1 2022-01-08 19:49:33 +01:00
parent 84074a4263
commit 8b3aa7a4ee

View File

@ -19,14 +19,11 @@ GLuint cubeProgram, cubeBuffer;
GLuint programColor;
GLuint programTexture;
GLuint textureSubmarine;
<<<<<<< HEAD
GLuint textureBubble;
=======
>>>>>>> fog
GLuint textureFish;
unsigned int cubemapTexture, skyboxVAO;
unsigned int cubeVAO, cubeVBO;
std::vector<glm::vec3> array[100];
float old_x, old_y = -1;
glm::vec3 cursorDiff;
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -10.f, -1.0f));
@ -44,10 +41,7 @@ glm::mat4 cameraMatrix, perspectiveMatrix;
Core::Shader_Loader shaderLoader;
Core::RenderContext submarineContext;
Core::RenderContext fishContext;
<<<<<<< HEAD
Core::RenderContext bubbleContext;
=======
>>>>>>> fog
std::vector<glm::vec3> fishKeyPoints({
glm::vec3(-18.0f, -10.0f, -10.0f),
@ -67,11 +61,31 @@ glm::vec3(-15.0f, -8.0f, -6.0f),
glm::vec3(-18.0f, -10.0f, -10.0f),
});
std::vector<glm::vec3> bubbleKeyPoints({
glm::vec3(-0, -20.0f, 0),
glm::vec3(-0, 20.0f, 0),
});
std::random_device rd; // obtain a random number from hardware
std::mt19937 gen(rd()); // seed the generator
std::uniform_int_distribution<> distr(-50, 50); // define the range
std::vector<glm::vec3> genBubbleKeyPoints(){
float random1 = distr(gen);
float random2 = distr(gen);
std::vector<glm::vec3> bubbleKeyPoints({
glm::vec3(random1 , -50.0f, random2),
glm::vec3(random1 , 50.0f, random2)
}
);
return bubbleKeyPoints;
};
void generateArray() {
for (int i = 0; i < 100; i++) {
array[i] = genBubbleKeyPoints();
}
}
@ -319,30 +333,11 @@ glm::mat4 animationMatrix(float time, glm::vec3 change, std::vector<glm::vec3> k
auto animationRotation = glm::squad(keyRotation[index % rotationSize], keyRotation[(index + 1) % rotationSize], a1, a2, t);
<<<<<<< HEAD
glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(scaleValue)) * glm::mat4_cast(animationRotation);
=======
glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(0.5f)) * glm::mat4_cast(animationRotation);
>>>>>>> fog
return result;
}
void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
{
GLuint program = programColor;
glUseProgram(program);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "modelViewProjectionMatrix"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::DrawContext(context);
glUseProgram(0);
}
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId, GLuint program)
{
@ -362,6 +357,7 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
}
void renderScene()
{
cameraMatrix = createCameraMatrix();
@ -381,63 +377,43 @@ void renderScene()
glDrawArrays(GL_TRIANGLES, 0, 36);
//glUseProgram(cubeProgram);
//glBindVertexArray(0);
//glBindVertexArray(cubeVAO);
//glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
//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 bubbleInitialTransformation = 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.5f));
//drawObjectTexture(bubbleContext, bubbleInitialTransformation, cubemapTexture, cubeProgram);
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);
<<<<<<< HEAD
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);
glm::vec3 change0 = glm::vec3(0, 0, 0);
for (int j = 0; j < 50; j++) {
drawObjectTexture(bubbleContext, animationMatrix(time + j, change0, array[j], glm::vec3(0.1f), 0.99f), cubemapTexture, cubeProgram);
}
for (int i = 0; i < 5; i++) {
if (time > -10) {
drawObjectTexture(fishContext, animationMatrix(time + 15, change1, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture);
drawObjectTexture(fishContext, animationMatrix(time + 15, change2, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture);
drawObjectTexture(fishContext, animationMatrix(time + 15, change3, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture);
drawObjectTexture(fishContext, animationMatrix(time + 15, change4, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture);
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change5, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), cubemapTexture, cubeProgram);
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change6, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), cubemapTexture, cubeProgram);
drawObjectTexture(bubbleContext, animationMatrix(time + 15, change7, bubbleKeyPoints, glm::vec3(0.01f), 0.2f), cubemapTexture, cubeProgram);
time -= 6;
}
}
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine, programTexture);
=======
for (int i = 0; i < 4; 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 -= 8;
}
}
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
>>>>>>> fog
glutSwapBuffers();
}
@ -544,11 +520,7 @@ void init()
skyboxProgram = shaderLoader.CreateProgram((char*)"shaders/skybox.vert", (char*)"shaders/skybox.frag");
cubeProgram = shaderLoader.CreateProgram((char*)"shaders/bubble.vert", (char*)"shaders/bubble.frag");
cubemapTexture = loadCubemap();
<<<<<<< HEAD
=======
>>>>>>> fog
loadModelToContext("models/submarine.obj", submarineContext);
textureSubmarine = Core::LoadTexture("textures/submarine.png");
@ -556,14 +528,12 @@ void init()
textureFish = Core::LoadTexture("textures/fish.png");
initKeyRotation();
<<<<<<< HEAD
loadModelToContext("models/submarine.obj", submarineContext);
textureSubmarine = Core::LoadTexture("textures/submarine.png");
loadModelToContext("models/sphere.obj", bubbleContext);
textureBubble = Core::LoadTexture("textures/bubble.png");
generateArray();
initCube();
=======
>>>>>>> fog
initSkybox();
}