add more fish

This commit is contained in:
Matraf 2022-01-17 16:20:48 +01:00
parent 44164da244
commit 1611666e96
8 changed files with 60485 additions and 42 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,8 @@ void main()
vec3 R = reflect(-normalize(lightDir),normal); vec3 R = reflect(-normalize(lightDir),normal);
float ambient = 0.2; float ambient = 0.2;
float specular = pow(max(0,dot(R,V)),1000); float specular = pow(max(0,dot(R,V)),1000);
gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0) * (1.0f - depth) + vec4(depth * vec3(0.0f, 0.109f, 0.447f), 1.0f); //gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0) * (1.0f - depth) + vec4(depth * vec3(0.0f, 0.109f, 0.447f), 1.0f);
//gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0);
//Odkomentowac jak sie nie chce mgly i zakomentowac wyzej (patrz skybox.frag tez)
gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0);
} }

View File

@ -22,6 +22,8 @@ float logisticDepth(float depth, float steepness, float offset)
void main() void main()
{ {
float depth = logisticDepth(gl_FragCoord.z, 0.1f, 3.0f); float depth = logisticDepth(gl_FragCoord.z, 0.1f, 3.0f);
FragColor = texture(skybox, TexCoords)* (1.0f - depth) + vec4(depth * vec3(0.0f, 0.109f, 0.447f), 1.0f); //FragColor = texture(skybox, TexCoords)* (1.0f - depth) + vec4(depth * vec3(0.0f, 0.109f, 0.447f), 1.0f);
//FragColor = texture(skybox, TexCoords);
//Odkomentowac jak sie nie chce mgly i zakomentowac wyzej (patrz shader_tex.frag tez)
FragColor = texture(skybox, TexCoords);
} }

View File

@ -22,11 +22,14 @@ GLuint textureSubmarine;
GLuint textureBubble; GLuint textureBubble;
GLuint textureFloor; GLuint textureFloor;
GLuint textureFish; GLuint textureFish;
GLuint textureShark;
GLuint textureFangtooth;
unsigned int cubemapTexture, skyboxVAO; unsigned int cubemapTexture, skyboxVAO;
unsigned int cubeVAO, cubeVBO; unsigned int cubeVAO, cubeVBO;
std::vector<glm::vec3> bubbleArray[300]; std::vector<glm::vec3> bubbleArray[300];
float old_x, old_y = -1; float old_x, old_y = -1;
glm::vec3 cursorDiff; glm::vec3 cursorDiff;
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -10.f, -1.0f)); glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -10.f, -1.0f));
@ -45,27 +48,71 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext submarineContext; Core::RenderContext submarineContext;
Core::RenderContext floorContext; Core::RenderContext floorContext;
Core::RenderContext fishContext; Core::RenderContext fishContext;
Core::RenderContext fangtoothContext;
Core::RenderContext sharkContext;
Core::RenderContext bubbleContext; Core::RenderContext bubbleContext;
std::vector<glm::vec3> fishKeyPoints({ std::vector<glm::vec3> fishKeyPointsFirst({
glm::vec3(-18.0f, -10.0f, -10.0f), glm::vec3(0.0f, -130.0f, 0.0f),
glm::vec3(-10.0f, -5.0f, -12.0f), glm::vec3(50.0f, -130.0f, 25.0f),
glm::vec3(8.0f, -3.0f, -3.0f), glm::vec3(75.0f, -130.0f, 75.0f),
glm::vec3(5.0f, 0.0f, 3.0f), glm::vec3(40.0f, -130.0f, 100.0f),
glm::vec3(3.0f, 2.0f, 4.0f), glm::vec3(-25.0f, -130.0f, 85.0f),
glm::vec3(8.0f, 5.0f, 9.0f), glm::vec3(-60.0f, -130.0f, 75.0f),
glm::vec3(14.0f, 6.0f, 15.0f), glm::vec3(-75.0f, -130.0f, 70.0f),
glm::vec3(15.0f, 12.0f, 12.0f), glm::vec3(-100.0f, -130.0f, 35.0f),
glm::vec3(10.0f, 17.0f, 15.0f), glm::vec3(-90.0f, -130.0f, 0.0f),
glm::vec3(5.0f, 10.0f, 7.0f), glm::vec3(-105.0f, -130.0f, -50.0f),
glm::vec3(-1.0f, 4.0f, 8.0f), glm::vec3(-95.0f, -130.0f, -75.0f),
glm::vec3(-8.0f, 0.0f, 3.0f), glm::vec3(-115.0f, -130.0f, -100.0f),
glm::vec3(-12.0f, -6.0f, -3.0f), glm::vec3(-75.0f, -130.0f, -120.0f),
glm::vec3(-15.0f, -8.0f, -6.0f), glm::vec3(-70.0f, -130.0f, -135.0f),
glm::vec3(-18.0f, -10.0f, -10.0f), glm::vec3(-35.0f, -130.0f, -120.0f),
glm::vec3(10.0f, -130.0f, -150.0f),
glm::vec3(25.0f, -130.0f, -135.0f),
glm::vec3(50.0f, -130.0f, -140.0f),
glm::vec3(60.0f, -130.0f, -110.0f),
glm::vec3(50.0f, -130.0f, -75.0f),
glm::vec3(30.0f, -130.0f, -85.0f),
glm::vec3(10.0f, -130.0f, -50.0f),
glm::vec3(-40.0f, -130.0f, -65.0f),
glm::vec3(-25.0f, -130.0f, -25.0f),
glm::vec3(-15.0f, -130.0f, -10.0f),
glm::vec3(0.0f, -130.0f, 0.0f),
}); });
std::vector<glm::quat> fishKeyRotationFirst;
std::vector<glm::vec3> fishKeyPointsSecond({
glm::vec3(0.0f, 0.0f, 15.0f),
glm::vec3(-20.0f, 10.0f, 10.0f),
glm::vec3(-35.0f, 15.0f, 5.0f),
glm::vec3(-55.0f, 0.0f, 5.0f),
glm::vec3(-70.0f, 0.0f, 0.0f),
glm::vec3(-70.0f, 0.0f, -10.0f),
glm::vec3(-70.0f, 0.0f, -25.0f),
glm::vec3(-85.0f, 0.0f, -35.0f),
glm::vec3(-115.0f, 0.0f, -45.0f),
glm::vec3(-135.0f, 0.0f, -25.0f),
glm::vec3(-155.0f, 0.0f, -5.0f),
glm::vec3(-175.0f, 0.0f, 0.0f)
});
std::vector<glm::quat> fishKeyRotationSecond;
std::vector<glm::vec3> sharkKeyPoints({
glm::vec3(-300.0f, 100.0f, -300.0f),
glm::vec3(-200.0f, 100.0f, -200.0f),
glm::vec3(-100.0f, 100.0f, -100.0f),
glm::vec3(0.0f, 100.0f, 0.0f),
glm::vec3(100.0f, 100.0f, 100.0f),
glm::vec3(200.0f, 100.0f, 200.0f),
glm::vec3(300.0f, 100.0f, 300.0f),
});
std::vector<glm::quat> sharkKeyRotation;
std::vector<glm::vec3> generatedFishKeyPoints[30];
std::vector<glm::quat> generatedFishKeyRotation;
std::vector<glm::quat> keyRotation;
std::vector<Core::Node> fish; std::vector<Core::Node> fish;
@ -176,12 +223,16 @@ bool isInBoundaries(glm::vec3 nextPosition) {
nextPosition.y < skyboxBoundary&& nextPosition.x < skyboxBoundary&& nextPosition.x > -skyboxBoundary; nextPosition.y < skyboxBoundary&& nextPosition.x < skyboxBoundary&& nextPosition.x > -skyboxBoundary;
} }
//First gen
std::random_device rd; // obtain a random number from hardware std::random_device rd; // obtain a random number from hardware
std::mt19937 gen(rd()); // seed the generator std::mt19937 gen(rd()); // seed the generator
std::uniform_int_distribution<> distr(-skyboxVerticeParameter, skyboxVerticeParameter); // define the range std::uniform_int_distribution<> distr(-skyboxVerticeParameter, skyboxVerticeParameter); // define the range
//Second gen
std::uniform_int_distribution<> distribution(10, 10); // define the range
std::vector<glm::vec3> genBubbleKeyPoints() { std::vector<glm::vec3> genBubbleKeyPoints() {
float random1 = distr(gen); float random1 = distr(gen);
float random2 = distr(gen); float random2 = distr(gen);
std::vector<glm::vec3> bubbleKeyPoints({ std::vector<glm::vec3> bubbleKeyPoints({
@ -199,10 +250,34 @@ void generateBubbleArray() {
} }
} }
std::vector<glm::vec3> genFishKeyPoints() {
std::vector<glm::vec3> fishKeyPoints2;
for (int i = 0; i < fishKeyPointsFirst.size(); i++) {
float random1 = distribution(gen);
float random2 = distribution(gen);
glm::vec3 oldKeyPoint = fishKeyPointsFirst[i];
fishKeyPoints2.push_back(glm::vec3(oldKeyPoint.x + random1, -100.f, oldKeyPoint.z + random2));
}
//while (fishKeyPoints2.size() <= 30) {
// float random1 = distribution(gen);
// float random2 = distribution(gen);
// fishKeyPoints2.push_back(glm::vec3(random1, -100.0f, random2));
// }
return fishKeyPoints2;
};
void generateFishArray() {
for (int i = 0; i < 30; i++) {
generatedFishKeyPoints[i] = genFishKeyPoints();
}
}
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 = 1.0f; float moveSpeed = 10.0f;
glm::vec3 nextPosition; glm::vec3 nextPosition;
switch (key) switch (key)
{ {
@ -289,7 +364,7 @@ std::vector<glm::vec3> changeKeyPoints(std::vector<glm::vec3> keyPoints, glm::ve
return result; return result;
} }
glm::mat4 animationMatrix(float time, glm::vec3 change, std::vector<glm::vec3> keyPoints, glm::vec3 scaleValue, float speed) { glm::mat4 animationMatrix(float time, glm::vec3 change, std::vector<glm::vec3> keyPoints, std::vector<glm::quat> keyRotation, glm::vec3 scaleValue, float speed) {
time = time * speed; time = time * speed;
std::vector<float> distances; std::vector<float> distances;
@ -372,28 +447,42 @@ 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::vec3 change1 = glm::vec3(0, 3, 0); glm::vec3 change1 = glm::vec3(0, 4, 0);
glm::vec3 change2 = glm::vec3(0, 0, 0); glm::vec3 change2 = glm::vec3(-3, 0, 4);
glm::vec3 change3 = glm::vec3(3, 0, 0); glm::vec3 change3 = glm::vec3(6, 0, 3);
glm::vec3 change4 = glm::vec3(0, 2, 1); glm::vec3 change4 = glm::vec3(0, 2, -5);
glm::vec3 change0 = glm::vec3(0, 0, 0); glm::vec3 change0 = glm::vec3(0, 0, 0);
for (int j = 0; j < 100; j++) { //for (int j = 0; j < 100; j++) {
drawObjectTexture(bubbleContext, animationMatrix(time + j, change0, bubbleArray[j], glm::vec3(0.04f), 0.1f), cubemapTexture, bubbleProgram); // drawObjectTexture(bubbleContext, animationMatrix(time + j, change0, bubbleArray[j], glm::vec3(0.04f), 0.1f), cubemapTexture, bubbleProgram);
} //}
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if (time > -10) { if (time > -10) {
drawObjectTexture(fishContext, animationMatrix(time + 15, change1, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); drawObjectTexture(fishContext, animationMatrix(time + 15, change1, fishKeyPointsFirst, fishKeyRotationFirst, glm::vec3(0.8f), 1.f), textureFish, programTexture);
drawObjectTexture(fishContext, animationMatrix(time + 15, change2, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); drawObjectTexture(fishContext, animationMatrix(time + 15, change2, fishKeyPointsFirst, fishKeyRotationFirst, glm::vec3(0.8f), 1.f), textureFish, programTexture);
drawObjectTexture(fishContext, animationMatrix(time + 15, change3, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); drawObjectTexture(fishContext, animationMatrix(time + 15, change3, fishKeyPointsFirst, fishKeyRotationFirst, glm::vec3(0.8f), 1.f), textureFish, programTexture);
drawObjectTexture(fishContext, animationMatrix(time + 15, change4, fishKeyPoints, glm::vec3(0.25f), 1.f), textureFish, programTexture); drawObjectTexture(fishContext, animationMatrix(time + 15, change4, fishKeyPointsFirst, fishKeyRotationFirst, glm::vec3(0.8f), 1.f), textureFish, programTexture);
drawObjectTexture(fangtoothContext, animationMatrix(time + 15, change1, fishKeyPointsSecond, fishKeyRotationSecond, glm::vec3(0.25f), 1.f), textureFangtooth, programTexture);
time -= 6; drawObjectTexture(sharkContext, animationMatrix(time + 15, change1, sharkKeyPoints, sharkKeyRotation, glm::vec3(10.8f), 1.f), textureShark, programTexture);
time -= 5;
} }
} }
//drawObjectTexture(bubbleContext, submarineInitialTransformation, cubemapTexture, bubbleProgram);
//for (int i = 0; i < 3; i++) {
// if (time > -10) {
//
// time -= 9;
// }
//}
if (time > -10) {
time -= 5;
}
//drawObjectTexture(bubbleContext, submarineInitialTransformation, textureBubble, bubbleProgram);
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine, programTexture); drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine, programTexture);
drawObjectTexture(floorContext, floorTransformation, textureFloor, programTexture); drawObjectTexture(floorContext, floorTransformation, textureFloor, programTexture);
glutSwapBuffers(); glutSwapBuffers();
@ -462,14 +551,14 @@ void initSkybox()
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
} }
void initKeyRotation() { void initKeyRotation(std::vector<glm::vec3>& keyPoints, std::vector<glm::quat>& keyRotation) {
glm::vec3 oldDirection = glm::vec3(0, 0, 1); glm::vec3 oldDirection = glm::vec3(0, 0, 1);
glm::quat oldRotationCamera = glm::quat(1, 0, 0, 0); glm::quat oldRotationCamera = glm::quat(1, 0, 0, 0);
glm::vec3 direction; glm::vec3 direction;
glm::quat rotation; glm::quat rotation;
for (int i = 0; i < fishKeyPoints.size() - 1; i++) { for (int i = 0; i < keyPoints.size() - 1; i++) {
//3.1 //3.1
direction = glm::normalize(fishKeyPoints[i + 1] - fishKeyPoints[i]); direction = glm::normalize(keyPoints[i + 1] - keyPoints[i]);
//3.2 //3.2
rotation = glm::normalize(glm::rotationCamera(oldDirection, direction) * oldRotationCamera); rotation = glm::normalize(glm::rotationCamera(oldDirection, direction) * oldRotationCamera);
//3.3 //3.3
@ -509,16 +598,29 @@ void init()
loadModelToContext("models/fish.obj", fishContext); loadModelToContext("models/fish.obj", fishContext);
textureFish = Core::LoadTexture("textures/fish.png"); textureFish = Core::LoadTexture("textures/fish.png");
initKeyRotation(); loadModelToContext("models/fangtooth.obj", fangtoothContext);
textureFangtooth = Core::LoadTexture("textures/fangtooth.png");
loadModelToContext("models/shark.obj", sharkContext);
textureShark = Core::LoadTexture("textures/shark.png");
loadModelToContext("models/submarine.obj", submarineContext); loadModelToContext("models/submarine.obj", submarineContext);
textureSubmarine = Core::LoadTexture("textures/submarine.png"); textureSubmarine = Core::LoadTexture("textures/submarine.png");
loadModelToContext("models/sphere.obj", bubbleContext); loadModelToContext("models/sphere.obj", bubbleContext);
textureBubble = Core::LoadTexture("textures/bubble.png"); textureBubble = Core::LoadTexture("textures/bubble.png");
loadModelToContext("models/terrain.obj", floorContext); loadModelToContext("models/terrain.obj", floorContext);
textureFloor = Core::LoadTexture("textures/sand.png"); textureFloor = Core::LoadTexture("textures/sand.png");
generateFishArray();
generateBubbleArray(); generateBubbleArray();
initKeyRotation(fishKeyPointsFirst, fishKeyRotationFirst);
initKeyRotation(fishKeyPointsSecond, fishKeyRotationSecond);
initKeyRotation(sharkKeyPoints, sharkKeyRotation);
initCube(); initCube();
initSkybox(); initSkybox();

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 KiB