This commit is contained in:
andreistr21 2022-02-10 18:12:30 +01:00
commit eb94a7ddd0

View File

@ -24,7 +24,7 @@ enum {
PASS_NORMAL, PASS_CAUSTIC
};
void bubbleManager();
static GLboolean HaveTexObj = GL_FALSE;
static int reportSpeed = 0;
@ -40,6 +40,7 @@ static int showCaustics = 1, causticMotion = 1;
static int useMipmaps = 1;
static int currentCaustic = 0;
static int causticIncrement = 1;
static int NUMBER_OF_BUBBLES = 500;
static float lightAngle = 0.0, lightHeight = 20;
static GLfloat angle = -150; /* in degrees */
@ -98,8 +99,12 @@ int WIN_HEIGHT = 720;
float sea_bottom_y_pos = -3.f;
const int amount_of_marine_plants = 150;
glm::vec3 planetLocation[10];
glm::vec3 marinePlantsLocation[amount_of_marine_plants];
glm::vec3 planetLocation[100];
glm::vec3 bubbleLocation[500];
glm::vec3 bubbleOriginalLocation[500];
bool bubbleZdir[500] ;
bool bubbleXdir[500] ;
float mouseXPosition;
float mouseYPosition;
@ -198,9 +203,9 @@ void changeVehicleSpeed() {
vehicleAngle += vehicleAngleSpeed;
printf("vehicleSpeed: %.4f\n", vehicleSpeed);
printf("vehicleAngleSpeed: %.4f\n", vehicleAngleSpeed);
printf("vehicleVerticalSpeed: %.4f\n", vehicleVerticalSpeed);
//printf("vehicleSpeed: %.4f\n", vehicleSpeed);
//printf("vehicleAngleSpeed: %.4f\n", vehicleAngleSpeed);
//printf("vehicleVerticalSpeed: %.4f\n", vehicleVerticalSpeed);
}
@ -459,6 +464,8 @@ void drawScene()
drawObjectTexture(fishContext, modelMatrix, textureFish01);
bubbleManager();
for (int i = 0; i < 10; i++)
{
@ -554,6 +561,74 @@ void drawScene()
}
void bubbleMovement(int i) {
float bubbleWobblingDivider = 100;
int x = floor(bubbleLocation[i].x);
int y = floor(bubbleLocation[i].y);
int z = floor(bubbleLocation[i].z);
float bubbleWobbling = 0.0005;
float bubbleUp = 0.01;
//printf(xDir ? "true\n" : "false\n");
//printf(zDir ? "true\n" : "false\n");
if (bubbleLocation[i].x > bubbleOriginalLocation[i].x + bubbleWobbling * bubbleWobblingDivider ) {
bubbleXdir[i] = false;
//printf("herex1\n");
}
if (bubbleLocation[i].x < bubbleOriginalLocation[i].x - bubbleWobbling * bubbleWobblingDivider){
bubbleXdir[i] = true;
//printf("herex2\n");
}
if (bubbleLocation[i].z > bubbleOriginalLocation[i].z + bubbleWobbling * bubbleWobblingDivider) {
bubbleZdir[i] = false;
}
if (bubbleLocation[i].z < bubbleOriginalLocation[i].z - bubbleWobbling * bubbleWobblingDivider) {
bubbleZdir[i] = true;
}
if (bubbleXdir[i]) {
bubbleLocation[i].x += bubbleWobbling;
} else {
bubbleLocation[i].x -= bubbleWobbling;
}
if (bubbleZdir[i] ) {
bubbleLocation[i].z += bubbleWobbling;
}
else {
bubbleLocation[i].z -= bubbleWobbling;
}
if (y >= 10.0) {
bubbleLocation[i].y = -10.0;
}
bubbleLocation[i].y += bubbleUp;
}
void bubbleManager() {
for (int i = 0; i < NUMBER_OF_BUBBLES; i++)
{
bubbleMovement(i);
glm::mat4 modelMatrix = glm::translate(bubbleLocation[i]);
// Scaling models
glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001);
modelMatrix = glm::scale(modelMatrix, scale);
drawObjectTexture(fishContext, modelMatrix, textureFish01);
}
}
void drawSceneLight(int pass)
{
@ -733,9 +808,12 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
context.initFromAssimpMesh(scene->mMeshes[0]);
}
void init()
{
for (int i = 0; i < 10; i++)
srand(time(NULL));
for (int i = 0; i < 100; i++)
{
planetLocation[i] = glm::ballRand(20.0);
}
@ -745,6 +823,21 @@ void init()
marinePlantsLocation[i] = glm::ballRand(35.0);
}
for (int i = 0; i < NUMBER_OF_BUBBLES; i++)
{
// srand(time(NULL));
float MAX_NUM = 100.0;
bubbleLocation[i].x = (((float)rand() / (float)(RAND_MAX)) * MAX_NUM) - MAX_NUM / 2;
bubbleLocation[i].y = (((float)rand() / (float)(RAND_MAX)) * 10) - 5;
bubbleLocation[i].z = (((float)rand() / (float)(RAND_MAX)) * MAX_NUM) - MAX_NUM / 2;
bubbleOriginalLocation[i] = bubbleLocation[i];
bubbleZdir[i] = true;
bubbleXdir[i] = false;
}
srand(time(0));
glEnable(GL_DEPTH_TEST);
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");