fog
@ -1,8 +1 @@
|
|||||||
main_2_1a.cpp
|
grk-cw2.vcxproj -> C:\Users\pyron\Documents\grafika\submarine\Debug\grk-cw2.exe
|
||||||
C:\Users\pyron\Documents\grafika\submarine\cw 2\src\main_2_1a.cpp(335,69): warning C4305: 'argument': truncation from 'double' to 'float'
|
|
||||||
C:\Users\pyron\Documents\grafika\submarine\cw 2\src\main_2_1a.cpp(384,15): warning C4244: 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data
|
|
||||||
Camera.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
|
|
||||||
PhysXExtensions_static_32.lib(ExtCpuWorkerThread.obj) : warning LNK4099: PDB 'PhysXExtensions_static_32.pdb' was not found with 'PhysXExtensions_static_32.lib(ExtCpuWorkerThread.obj)' or at 'C:\Users\pyron\Documents\grafika\submarine\Debug\PhysXExtensions_static_32.pdb'; linking object as if no debug info
|
|
||||||
PhysXExtensions_static_32.lib(ExtDefaultCpuDispatcher.obj) : warning LNK4099: PDB 'PhysXExtensions_static_32.pdb' was not found with 'PhysXExtensions_static_32.lib(ExtDefaultCpuDispatcher.obj)' or at 'C:\Users\pyron\Documents\grafika\submarine\Debug\PhysXExtensions_static_32.pdb'; linking object as if no debug info
|
|
||||||
PhysXExtensions_static_32.lib(ExtDefaultErrorCallback.obj) : warning LNK4099: PDB 'PhysXExtensions_static_32.pdb' was not found with 'PhysXExtensions_static_32.lib(ExtDefaultErrorCallback.obj)' or at 'C:\Users\pyron\Documents\grafika\submarine\Debug\PhysXExtensions_static_32.pdb'; linking object as if no debug info
|
|
||||||
grk-cw2.vcxproj -> C:\Users\pyron\Documents\grafika\submarine\Debug\grk-cw2.exe
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
<None Include="shaders\shader_box.vert" />
|
<None Include="shaders\shader_box.vert" />
|
||||||
<None Include="shaders\shader_color.frag" />
|
<None Include="shaders\shader_color.frag" />
|
||||||
<None Include="shaders\shader_color.vert" />
|
<None Include="shaders\shader_color.vert" />
|
||||||
|
<None Include="shaders\shader_particle.frag" />
|
||||||
|
<None Include="shaders\shader_particle.vert" />
|
||||||
<None Include="shaders\shader_tex.frag" />
|
<None Include="shaders\shader_tex.frag" />
|
||||||
<None Include="shaders\shader_tex.vert" />
|
<None Include="shaders\shader_tex.vert" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
<None Include="shaders\shader_box.vert">
|
<None Include="shaders\shader_box.vert">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="shaders\shader_particle.frag">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="shaders\shader_particle.vert">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\Shader_Loader.cpp">
|
<ClCompile Include="src\Shader_Loader.cpp">
|
||||||
|
85579
cw 2/models/geyser.obj
Normal file
39134
cw 2/models/submarine.obj
Normal file
@ -6,9 +6,11 @@ out vec3 TexCoords;
|
|||||||
uniform mat4 perspective;
|
uniform mat4 perspective;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
TexCoords = aPos;
|
TexCoords = aPos;
|
||||||
vec4 pos = perspective * view * vec4(aPos, 1.0);
|
vec4 pos = perspective * view * vec4(aPos, 1.0);
|
||||||
gl_Position = pos.xyww;
|
gl_Position = pos.xyww;
|
||||||
|
|
||||||
}
|
}
|
@ -3,12 +3,19 @@
|
|||||||
uniform vec3 objectColor;
|
uniform vec3 objectColor;
|
||||||
uniform vec3 lightDir;
|
uniform vec3 lightDir;
|
||||||
|
|
||||||
|
//vec4(0.0175,0.4716,0.5109,1.0)
|
||||||
|
|
||||||
in vec3 interpNormal;
|
in vec3 interpNormal;
|
||||||
|
in float visibility;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(interpNormal);
|
vec3 normal = normalize(interpNormal);
|
||||||
float ambient = 0.2;
|
float ambient = 0.2;
|
||||||
float diffuse = max(dot(normal, -lightDir), 0.0);
|
float diffuse = max(dot(normal, -lightDir), 0.0);
|
||||||
|
|
||||||
gl_FragColor = vec4(objectColor * (ambient + (1-ambient) * diffuse), 1.0);
|
gl_FragColor = vec4(objectColor * (ambient + (1-ambient) * diffuse), 1.0);
|
||||||
|
|
||||||
|
|
||||||
|
gl_FragColor = mix(vec4(0.0175,0.4716,0.5109,0.5), gl_FragColor, visibility);
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,22 @@ layout(location = 2) in vec3 vertexNormal;
|
|||||||
uniform mat4 modelViewProjectionMatrix;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
|
|
||||||
out vec3 interpNormal;
|
out vec3 interpNormal;
|
||||||
|
|
||||||
|
out float visibility;
|
||||||
|
const float density = 0.0035;
|
||||||
|
const float gradient = 5.0;
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||||
|
|
||||||
|
float distance = length(gl_Position.xyz);
|
||||||
|
visibility = exp(-pow((distance*density),gradient));
|
||||||
|
visibility = clamp(visibility,0.0,1.0);
|
||||||
}
|
}
|
||||||
|
11
cw 2/shaders/shader_particle.frag
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
in vec2 TexCoords;
|
||||||
|
in vec4 ParticleColor;
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
uniform sampler2D sprite;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
color = (texture(sprite, TexCoords) * ParticleColor);
|
||||||
|
}
|
17
cw 2/shaders/shader_particle.vert
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>
|
||||||
|
|
||||||
|
out vec2 TexCoords;
|
||||||
|
out vec4 ParticleColor;
|
||||||
|
|
||||||
|
uniform mat4 projection;
|
||||||
|
uniform vec2 offset;
|
||||||
|
uniform vec4 color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
float scale = 10.0f;
|
||||||
|
TexCoords = vertex.zw;
|
||||||
|
ParticleColor = color;
|
||||||
|
gl_Position = projection * vec4((vertex.xy * scale) + offset, 0.0, 1.0);
|
||||||
|
}
|
@ -6,12 +6,17 @@ uniform vec3 lightDir;
|
|||||||
in vec3 interpNormal;
|
in vec3 interpNormal;
|
||||||
in vec2 interpTexCoord;
|
in vec2 interpTexCoord;
|
||||||
|
|
||||||
|
in float visibility;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
|
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y);
|
||||||
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
||||||
vec3 normal = normalize(interpNormal);
|
vec3 normal = normalize(interpNormal);
|
||||||
float ambient = 0.2;
|
float ambient = 0.2;
|
||||||
float diffuse = max(dot(normal, -lightDir), 0.0);
|
float diffuse = max(dot(normal, -lightDir), 0.0);
|
||||||
gl_FragColor = vec4(color * (ambient + (1-ambient) * diffuse), 1.0);
|
gl_FragColor = vec4(color * (ambient + (1-ambient) * diffuse), 1.0);
|
||||||
|
|
||||||
|
gl_FragColor = mix(vec4(0.0175,0.4716,0.5109,1.0), gl_FragColor, visibility);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,23 @@ layout(location = 2) in vec3 vertexNormal;
|
|||||||
uniform mat4 modelViewProjectionMatrix;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
out vec3 interpNormal;
|
out vec3 interpNormal;
|
||||||
out vec2 interpTexCoord;
|
out vec2 interpTexCoord;
|
||||||
|
|
||||||
|
out float visibility;
|
||||||
|
const float density = 0.006;
|
||||||
|
const float gradient = 2.0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||||
interpTexCoord = vertexTexCoord;
|
interpTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
float distance = length(gl_Position);
|
||||||
|
visibility = exp(-pow((distance*density),gradient));
|
||||||
|
visibility = clamp(visibility,0.0,1.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
#define SIZE 1.0f
|
#define SIZE 1.0f
|
||||||
#define SCREEN_X 1920
|
#define SCREEN_X 1920
|
||||||
#define SCREEN_Y 1080
|
#define SCREEN_Y 1080
|
||||||
#define SEAWEED_NUM 20
|
#define SEAWEED_NUM 100
|
||||||
#define FISH_NUM 20
|
#define FISH_NUM 100
|
||||||
|
#define PARTICLE_NUM 300
|
||||||
|
#define GROUND_XY 400
|
||||||
|
#define GEYSER_NUM 3
|
||||||
|
|
||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
GLuint programColor;
|
GLuint programColor;
|
||||||
@ -26,9 +28,24 @@ GLuint programSkyBox;
|
|||||||
|
|
||||||
auto radians = 0.01f;
|
auto radians = 0.01f;
|
||||||
|
|
||||||
|
struct fish
|
||||||
|
{
|
||||||
|
glm::vec3 position;
|
||||||
|
int counter = 0;
|
||||||
|
int rotation = 0;
|
||||||
|
glm::vec3 color = glm::vec3(0.9f, 0.1f, 0.3f);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct particle
|
||||||
|
{
|
||||||
|
glm::vec3 position;
|
||||||
|
glm::vec3 color = glm::vec3(0.55f, 0.65f, 0.94f);
|
||||||
|
float velocity = 0;
|
||||||
|
float size;
|
||||||
|
};
|
||||||
|
|
||||||
// Skybox
|
// Skybox
|
||||||
GLuint SkyboxVertexBuffer, SkyboxVertexAttributes;
|
GLuint SkyboxVertexBuffer, SkyboxVertexAttributes;
|
||||||
|
|
||||||
float cubeMapVertices[] = {
|
float cubeMapVertices[] = {
|
||||||
-SIZE, SIZE, -SIZE,
|
-SIZE, SIZE, -SIZE,
|
||||||
-SIZE, -SIZE, -SIZE,
|
-SIZE, -SIZE, -SIZE,
|
||||||
@ -73,65 +90,58 @@ float cubeMapVertices[] = {
|
|||||||
SIZE, -SIZE, SIZE
|
SIZE, -SIZE, SIZE
|
||||||
};
|
};
|
||||||
// Modele
|
// Modele
|
||||||
obj::Model groundModel, boxModel, sphereModel, seaweedModel, fishModel;
|
obj::Model groundModel, boxModel, sphereModel, seaweedModel, fishModel, submarineModel, particleModel, geyserModel;
|
||||||
|
|
||||||
// Contexty
|
// Contexty
|
||||||
Core::RenderContext groundContext, boxContext, sphereContext, seaweedContext, fishContext;
|
Core::RenderContext groundContext, boxContext, sphereContext, seaweedContext, fishContext, submarineContext, particleContext, geyserContext;
|
||||||
|
|
||||||
// Tekstury
|
// Tekstury
|
||||||
GLuint boxTexture, groundTexture, seaweedTexture, cubeMapTexture;
|
GLuint boxTexture, groundTexture, seaweedTexture, cubeMapTexture, submarineTexture, particleTexture, geyserTexture;
|
||||||
// Kamera
|
// Kamera
|
||||||
float cameraAngle = 0;
|
float cameraAngle = 0;
|
||||||
glm::vec3 cameraPos = glm::vec3(0, 10, 0);
|
|
||||||
glm::vec3 cameraSide;
|
|
||||||
glm::vec3 cameraDir;
|
|
||||||
bool firstMouse = true;
|
|
||||||
|
|
||||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
|
||||||
|
|
||||||
int xDiff, yDiff = 0;
|
|
||||||
int xPos, yPos = 0;
|
|
||||||
glm::quat rotation = glm::quat(1, 0, 0, 0);
|
|
||||||
|
|
||||||
float y_rotation_angle;
|
float y_rotation_angle;
|
||||||
float around_rotation_angle;
|
float around_rotation_angle;
|
||||||
|
|
||||||
float moving_angle = 360.0;
|
float moving_angle = 360.0;
|
||||||
|
int xDiff, yDiff = 0;
|
||||||
|
int xPos, yPos = 0;
|
||||||
glm::vec3 lightDir = glm::normalize(glm::vec3(-1, 0, -1));
|
bool firstMouse = true;
|
||||||
|
glm::vec3 cameraPos = glm::vec3(0, 35, 10);
|
||||||
|
glm::vec3 cameraSide;
|
||||||
|
glm::vec3 cameraDir;
|
||||||
|
glm::vec3 lightDir = glm::normalize(glm::vec3(-0.5, -1, -0.5));
|
||||||
|
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||||
|
glm::quat rotation = glm::quat(1, 0, 0, 0);
|
||||||
|
|
||||||
std::vector<glm::vec3> seaweedPosition;
|
std::vector<glm::vec3> seaweedPosition;
|
||||||
std::vector<glm::vec3> fishPosition;
|
std::vector<glm::vec3> fishPosition;
|
||||||
|
|
||||||
struct fish
|
|
||||||
{
|
|
||||||
glm::vec3 position;
|
|
||||||
int counter = 0;
|
|
||||||
int rotation = 0;
|
|
||||||
glm::vec3 color = glm::vec3(0.9f, 0.1f, 0.3f);
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<fish> fishList;
|
std::vector<fish> fishList;
|
||||||
|
std::vector<std::vector<particle>> particleList;
|
||||||
|
std::vector<glm::vec3> geyserList;
|
||||||
|
|
||||||
void keyboard(unsigned char key, int x, int y)
|
void keyboard(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
float angleSpeed = 0.1f;
|
float angleSpeed = 0.05f;
|
||||||
float moveSpeed = 0.5f;
|
float moveSpeed = 0.5f;
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case 'z': rotation = glm::angleAxis(angleSpeed, glm::vec3(0, 0, 1)) * rotation; break;
|
case 'z': rotation = glm::angleAxis(angleSpeed, glm::vec3(0, 0, 1)) * rotation; break;
|
||||||
case 'x': rotation = glm::angleAxis(angleSpeed, glm::vec3(0, 0, -1)) * rotation; break;
|
case 'x': rotation = glm::angleAxis(angleSpeed, glm::vec3(0, 0, -1)) * rotation; break;
|
||||||
|
|
||||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
||||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||||
case 'd': cameraPos += cameraSide * moveSpeed; moving_angle > 340.0 ? moving_angle -= 1.0 : moving_angle += 0; break;
|
|
||||||
case 'a': cameraPos -= cameraSide * moveSpeed; moving_angle < 380.0 ? moving_angle += 1.0 : moving_angle += 0; break;
|
case 'r': cameraPos += glm::vec3(0,1,0) * moveSpeed; break;
|
||||||
|
case 't': cameraPos += glm::vec3(0, -1, 0) * moveSpeed; break;
|
||||||
|
|
||||||
|
case 'a': rotation = glm::angleAxis(angleSpeed, glm::vec3(0, -1, 0)) * rotation; break;
|
||||||
|
case 'd': rotation = glm::angleAxis(angleSpeed, glm::vec3(0, 1, 0)) * rotation; break;
|
||||||
|
|
||||||
|
case 'q': cameraPos -= cameraSide * moveSpeed; break;
|
||||||
|
case 'e': cameraPos += cameraSide * moveSpeed; break;
|
||||||
|
|
||||||
|
|
||||||
case 'p': glutLeaveMainLoop();
|
case 'p': glutLeaveMainLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mouse(int x, int y)
|
void mouse(int x, int y)
|
||||||
{
|
{
|
||||||
if (firstMouse) {
|
if (firstMouse) {
|
||||||
@ -195,7 +205,7 @@ void drawObjectTexture(Core::RenderContext* context, glm::mat4 modelMatrix, GLui
|
|||||||
|
|
||||||
glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
|
glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
|
||||||
Core::SetActiveTexture(textureId, "textureSampler", program, 0);
|
Core::SetActiveTexture(textureId, "textureSampler", program, 0);
|
||||||
|
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelViewProjectionMatrix"), 1, GL_FALSE, (float*)&transformation);
|
glUniformMatrix4fv(glGetUniformLocation(program, "modelViewProjectionMatrix"), 1, GL_FALSE, (float*)&transformation);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
@ -204,30 +214,33 @@ void drawObjectTexture(Core::RenderContext* context, glm::mat4 modelMatrix, GLui
|
|||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
void initGeyser() {
|
||||||
|
|
||||||
void renderSkybox()
|
geyserList.push_back(glm::vec3(180, 0.1f, 210));
|
||||||
{
|
geyserList.push_back(glm::vec3(-130, 0.1f, 50));
|
||||||
glDepthFunc(GL_LEQUAL);
|
geyserList.push_back(glm::vec3(30, 0.1f, -80));
|
||||||
glUseProgram(programSkyBox);
|
|
||||||
glm::mat4 view = glm::mat4(glm::mat3(cameraMatrix));
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "view"), 1, GL_FALSE, (float*)&view);
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "perspective"), 1, GL_FALSE, (float*)&perspectiveMatrix);
|
|
||||||
|
|
||||||
glBindVertexArray(SkyboxVertexAttributes);
|
}
|
||||||
glActiveTexture(GL_TEXTURE0);
|
void initBubbles() {
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapTexture);
|
for (int j = 0; j < GEYSER_NUM; j++)
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
std::vector<particle> particleGroup;
|
||||||
glBindVertexArray(0);
|
for (int i = 0; i < PARTICLE_NUM; i++) {
|
||||||
glDepthFunc(GL_LESS);
|
particle new_particle;
|
||||||
//glDepthMask(GL_TRUE);
|
new_particle.position = glm::vec3(geyserList[j].x + static_cast<float>(rand() % 4000 - 2000) / 1000.0f, static_cast<float>(rand() % 60 + 5), geyserList[j].z + static_cast<float>(rand() % 4000 - 2000) / 1000.0f);
|
||||||
|
new_particle.velocity = static_cast<float>(rand() % 50 + 300) / 1000.0f;
|
||||||
glUseProgram(0);
|
new_particle.size = static_cast<float>(rand() % 150 + 150) / 1000.0f;
|
||||||
|
|
||||||
|
particleGroup.push_back(new_particle);
|
||||||
|
}
|
||||||
|
particleList.push_back(particleGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void initSeaweed() {
|
void initSeaweed() {
|
||||||
for (int i = 0; i < SEAWEED_NUM; i++) {
|
for (int i = 0; i < SEAWEED_NUM; i++) {
|
||||||
seaweedPosition.push_back(glm::vec3(static_cast<float>(rand() % 200 - 100), 0.1f, static_cast<float>(rand() % 200 - 100)));
|
auto x = static_cast<float>(rand() % GROUND_XY - (GROUND_XY / 2));
|
||||||
|
auto z = static_cast<float>(rand() % GROUND_XY - (GROUND_XY / 2));
|
||||||
|
seaweedPosition.push_back(glm::vec3(x,0.1f,z));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -235,7 +248,9 @@ void initFish() {
|
|||||||
|
|
||||||
for (int i = 0; i < FISH_NUM; i++) {
|
for (int i = 0; i < FISH_NUM; i++) {
|
||||||
fish new_fish;
|
fish new_fish;
|
||||||
new_fish.position = glm::vec3(static_cast<float>(rand() % 200 - 100), static_cast<float>(rand() % 20 + 10), static_cast<float>(rand() % 200 - 100));
|
auto x = static_cast<float>(rand() % GROUND_XY - (GROUND_XY / 2));
|
||||||
|
auto z = static_cast<float>(rand() % GROUND_XY - (GROUND_XY / 2));
|
||||||
|
new_fish.position = glm::vec3(x, static_cast<float>(rand() % 40 + 10), z);
|
||||||
new_fish.rotation = rand() % 4;
|
new_fish.rotation = rand() % 4;
|
||||||
|
|
||||||
new_fish.color.x = static_cast<float>(rand() % 10) / 10;
|
new_fish.color.x = static_cast<float>(rand() % 10) / 10;
|
||||||
@ -244,8 +259,6 @@ void initFish() {
|
|||||||
fishList.push_back(new_fish);
|
fishList.push_back(new_fish);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initSkybox()
|
void initSkybox()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -271,27 +284,51 @@ void initSkybox()
|
|||||||
|
|
||||||
cubeMapTexture = Core::LoadCubemap(faces);
|
cubeMapTexture = Core::LoadCubemap(faces);
|
||||||
}
|
}
|
||||||
|
void renderSkybox()
|
||||||
|
{
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glUseProgram(programSkyBox);
|
||||||
|
glm::mat4 view = glm::mat4(glm::mat3(cameraMatrix));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "view"), 1, GL_FALSE, (float*)&view);
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "perspective"), 1, GL_FALSE, (float*)&perspectiveMatrix);
|
||||||
|
|
||||||
|
glBindVertexArray(SkyboxVertexAttributes);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapTexture);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
//glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
void renderSubmarine()
|
||||||
|
{
|
||||||
|
glm::mat4 submarineInitialMatrix = glm::translate(glm::vec3(0, -20, -30)) * glm::rotate(glm::radians(180.0f),glm::vec3(0,1,0)) * glm::scale(glm::vec3(2.0f));
|
||||||
|
glm::mat4 submarineMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialMatrix;
|
||||||
|
drawObjectTexture(&submarineContext, submarineMatrix, submarineTexture);
|
||||||
|
}
|
||||||
void renderGround()
|
void renderGround()
|
||||||
{
|
{
|
||||||
glm::mat4 groundMatrix = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(90.0f), glm::vec3(0, 0, -1));// *glm::scale(glm::vec3(30));;
|
float scale = static_cast<float>(GROUND_XY) / 100.0f;
|
||||||
|
glm::mat4 groundMatrix = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(90.0f), glm::vec3(0, 0, -1)) * glm::scale(glm::vec3(scale));
|
||||||
drawObjectTexture(&groundContext, groundMatrix, groundTexture);
|
drawObjectTexture(&groundContext, groundMatrix, groundTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderSeaweed()
|
void renderSeaweed()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SEAWEED_NUM; i++) {
|
for (int i = 0; i < SEAWEED_NUM; i++) {
|
||||||
glm::mat4 seaweedMatrix = glm::translate(seaweedPosition[i]);// * glm::scale(glm::vec3(0.01f));
|
glm::mat4 seaweedMatrix = glm::translate(seaweedPosition[i]);
|
||||||
drawObjectColor(&seaweedContext, seaweedMatrix, glm::vec3(0.1f, 0.6f, 0.1f));
|
drawObjectColor(&seaweedContext, seaweedMatrix, glm::vec3(0.1f, 0.6f, 0.1f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderFish()
|
void renderFish()
|
||||||
{
|
{
|
||||||
|
|
||||||
glm::mat4 fishMatrix;
|
glm::mat4 fishMatrix;
|
||||||
for (int i = 0; i < FISH_NUM; i++) {
|
for (int i = 0; i < FISH_NUM; i++) {
|
||||||
int result = rand() % (10000 - fishList[i].counter);
|
int result = rand() % (20000 - fishList[i].counter);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
fishList[i].rotation = rand() % 4;
|
fishList[i].rotation = rand() % 4;
|
||||||
@ -305,32 +342,59 @@ void renderFish()
|
|||||||
switch (fishList[i].rotation)
|
switch (fishList[i].rotation)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
fishList[i].position.z -= 0.001f;
|
fishList[i].position.z -= 0.008f;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
fishList[i].position.x -= 0.001f;
|
fishList[i].position.x -= 0.008f;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
fishList[i].position.z += 0.001f;
|
fishList[i].position.z += 0.008f;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
fishList[i].position.x += 0.001f;
|
fishList[i].position.x += 0.008f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fishMatrix = glm::translate(fishList[i].position) * glm::rotate(glm::radians(fishList[i].rotation * 90.0f), glm::vec3(0, 1, 0));
|
fishMatrix = glm::translate(fishList[i].position) * glm::rotate(glm::radians(fishList[i].rotation * 90.0f), glm::vec3(0, 1, 0));
|
||||||
drawObjectColor(&fishContext, fishMatrix, fishList[i].color);
|
drawObjectColor(&fishContext, fishMatrix, fishList[i].color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void renderBubbles()
|
||||||
|
{
|
||||||
|
for (int j = 0; j < GEYSER_NUM; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < PARTICLE_NUM; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//glm::mat4 particleTrans = glm::translate(glm::vec3(0 + -0.1 * i / 45, -2.5f, -4 * sin(time * i))) * glm::rotate(glm::radians(270.0f), glm::vec3(0, -2, 0)) * glm::rotate(glm::radians(0.0f), glm::vec3(1, 0, 0)) * glm::scale(glm::vec3(0.02f));
|
||||||
|
//glm::mat4 particleModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::mat4_cast(glm::inverse(rotation)) * particleTrans;
|
||||||
|
|
||||||
|
glm::mat4 particleModelMatrix = glm::translate(particleList[j][i].position) * glm::scale(glm::vec3(particleList[j][i].size));
|
||||||
|
|
||||||
|
|
||||||
|
if (particleList[j][i].position.y > 90) {
|
||||||
|
particleList[j][i].position.y = 5;
|
||||||
|
particleList[j][i].velocity = static_cast<float>(rand() % 90 + 10) / 1000.0f;
|
||||||
|
}
|
||||||
|
particleList[j][i].position.y += particleList[j][i].velocity;//particleList[i].color
|
||||||
|
drawObjectTexture(&particleContext, particleModelMatrix, particleTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void renderGeyser()
|
||||||
|
{
|
||||||
|
for (int j = 0; j < GEYSER_NUM; j++)
|
||||||
|
{
|
||||||
|
glm::mat4 gayserModelMatrix = glm::translate(geyserList[j]) * scale(glm::vec3(0.006f)) * scale(glm::vec3(1.0f, 3.0f, 1.0f));
|
||||||
|
drawObjectTexture(&geyserContext, gayserModelMatrix, geyserTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
void renderScene()
|
void renderScene()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
|
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
|
||||||
|
|
||||||
cameraMatrix = createCameraMatrix();
|
cameraMatrix = createCameraMatrix();
|
||||||
perspectiveMatrix = Core::createPerspectiveMatrix(0.1, 400, 1.1f);
|
perspectiveMatrix = Core::createPerspectiveMatrix(0.1, 500, 1.1f);
|
||||||
|
|
||||||
|
|
||||||
renderSkybox();
|
renderSkybox();
|
||||||
@ -338,6 +402,9 @@ void renderScene()
|
|||||||
renderGround();
|
renderGround();
|
||||||
renderSeaweed();
|
renderSeaweed();
|
||||||
renderFish();
|
renderFish();
|
||||||
|
renderSubmarine();
|
||||||
|
renderBubbles();
|
||||||
|
renderGeyser();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|
||||||
@ -352,17 +419,28 @@ void init()
|
|||||||
groundModel = obj::loadModelFromFile("models/plane.obj");
|
groundModel = obj::loadModelFromFile("models/plane.obj");
|
||||||
seaweedModel = obj::loadModelFromFile("models/seaweed.obj");
|
seaweedModel = obj::loadModelFromFile("models/seaweed.obj");
|
||||||
fishModel = obj::loadModelFromFile("models/fish.obj");
|
fishModel = obj::loadModelFromFile("models/fish.obj");
|
||||||
|
submarineModel = obj::loadModelFromFile("models/submarine.obj");
|
||||||
|
particleModel = obj::loadModelFromFile("models/sphere.obj");
|
||||||
|
geyserModel = obj::loadModelFromFile("models/geyser.obj");
|
||||||
|
|
||||||
groundTexture = Core::LoadTexture("textures/sand.jpg");
|
groundTexture = Core::LoadTexture("textures/sand.jpg");
|
||||||
seaweedTexture = Core::LoadTexture("textures/sea.jpg");
|
seaweedTexture = Core::LoadTexture("textures/sea.jpg");
|
||||||
|
submarineTexture = Core::LoadTexture("textures/Base_color.png");
|
||||||
|
particleTexture = Core::LoadTexture("textures/bubble.jpg");
|
||||||
|
geyserTexture = Core::LoadTexture("textures/geyser.jpg");
|
||||||
|
|
||||||
groundContext.initFromOBJ(groundModel);
|
groundContext.initFromOBJ(groundModel);
|
||||||
seaweedContext.initFromOBJ(seaweedModel);
|
seaweedContext.initFromOBJ(seaweedModel);
|
||||||
fishContext.initFromOBJ(fishModel);
|
fishContext.initFromOBJ(fishModel);
|
||||||
|
submarineContext.initFromOBJ(submarineModel);
|
||||||
|
particleContext.initFromOBJ(particleModel);
|
||||||
|
geyserContext.initFromOBJ(geyserModel);
|
||||||
|
|
||||||
initFish();
|
initFish();
|
||||||
initSeaweed();
|
initSeaweed();
|
||||||
initSkybox();
|
initSkybox();
|
||||||
|
initGeyser();
|
||||||
|
initBubbles();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
cw 2/textures/Base_Color.png
Normal file
After Width: | Height: | Size: 12 MiB |
BIN
cw 2/textures/bubble.jpg
Normal file
After Width: | Height: | Size: 210 KiB |
BIN
cw 2/textures/bubble.png
Normal file
After Width: | Height: | Size: 338 KiB |
BIN
cw 2/textures/geyser.jpg
Normal file
After Width: | Height: | Size: 151 KiB |
BIN
cw 2/textures/particle.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 723 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 274 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 462 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 525 KiB After Width: | Height: | Size: 65 KiB |
BIN
cw 2/textures/skybox/old/back.jpg
Normal file
After Width: | Height: | Size: 723 KiB |
BIN
cw 2/textures/skybox/old/bottom.jpg
Normal file
After Width: | Height: | Size: 274 KiB |
BIN
cw 2/textures/skybox/old/front.jpg
Normal file
After Width: | Height: | Size: 462 KiB |
BIN
cw 2/textures/skybox/old/left.jpg
Normal file
After Width: | Height: | Size: 525 KiB |
BIN
cw 2/textures/skybox/old/right.jpg
Normal file
After Width: | Height: | Size: 588 KiB |
Before Width: | Height: | Size: 588 KiB After Width: | Height: | Size: 65 KiB |