add bubbles
This commit is contained in:
parent
8470efa3b8
commit
992877b644
@ -19,7 +19,7 @@ enum {
|
|||||||
PASS_NORMAL, PASS_CAUSTIC
|
PASS_NORMAL, PASS_CAUSTIC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void bubbleManager();
|
||||||
|
|
||||||
static GLboolean HaveTexObj = GL_FALSE;
|
static GLboolean HaveTexObj = GL_FALSE;
|
||||||
static int reportSpeed = 0;
|
static int reportSpeed = 0;
|
||||||
@ -35,6 +35,7 @@ static int showCaustics = 1, causticMotion = 1;
|
|||||||
static int useMipmaps = 1;
|
static int useMipmaps = 1;
|
||||||
static int currentCaustic = 0;
|
static int currentCaustic = 0;
|
||||||
static int causticIncrement = 1;
|
static int causticIncrement = 1;
|
||||||
|
static int NUMBER_OF_BUBBLES = 500;
|
||||||
|
|
||||||
static float lightAngle = 0.0, lightHeight = 20;
|
static float lightAngle = 0.0, lightHeight = 20;
|
||||||
static GLfloat angle = -150; /* in degrees */
|
static GLfloat angle = -150; /* in degrees */
|
||||||
@ -82,7 +83,11 @@ obj::Model planeModel;
|
|||||||
int WIN_WIDTH = 1280;
|
int WIN_WIDTH = 1280;
|
||||||
int WIN_HEIGHT = 720;
|
int WIN_HEIGHT = 720;
|
||||||
|
|
||||||
glm::vec3 planetLocation[10];
|
glm::vec3 planetLocation[100];
|
||||||
|
glm::vec3 bubbleLocation[500];
|
||||||
|
glm::vec3 bubbleOriginalLocation[500];
|
||||||
|
bool bubbleZdir[500] ;
|
||||||
|
bool bubbleXdir[500] ;
|
||||||
|
|
||||||
float mouseXPosition;
|
float mouseXPosition;
|
||||||
float mouseYPosition;
|
float mouseYPosition;
|
||||||
@ -181,9 +186,9 @@ void changeVehicleSpeed() {
|
|||||||
|
|
||||||
vehicleAngle += vehicleAngleSpeed;
|
vehicleAngle += vehicleAngleSpeed;
|
||||||
|
|
||||||
printf("vehicleSpeed: %.4f\n", vehicleSpeed);
|
//printf("vehicleSpeed: %.4f\n", vehicleSpeed);
|
||||||
printf("vehicleAngleSpeed: %.4f\n", vehicleAngleSpeed);
|
//printf("vehicleAngleSpeed: %.4f\n", vehicleAngleSpeed);
|
||||||
printf("vehicleVerticalSpeed: %.4f\n", vehicleVerticalSpeed);
|
//printf("vehicleVerticalSpeed: %.4f\n", vehicleVerticalSpeed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,6 +447,8 @@ void drawScene()
|
|||||||
|
|
||||||
drawObjectTexture(fishContext, modelMatrix, textureFish01);
|
drawObjectTexture(fishContext, modelMatrix, textureFish01);
|
||||||
|
|
||||||
|
bubbleManager();
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -486,6 +493,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)
|
void drawSceneLight(int pass)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -665,13 +740,32 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
|||||||
context.initFromAssimpMesh(scene->mMeshes[0]);
|
context.initFromAssimpMesh(scene->mMeshes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void init()
|
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);
|
planetLocation[i] = glm::ballRand(20.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));
|
srand(time(0));
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
||||||
|
Loading…
Reference in New Issue
Block a user