new ship, added fish and bubble movement

This commit is contained in:
koziej97 2022-02-09 21:22:33 +01:00
parent ad9083330b
commit 7d852ae1fb
10 changed files with 137 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(513,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw6.vcxproj). Może to spowodować niepoprawne zachowanie podczas oczyszczania i ponownej kompilacji.
main.cpp
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(120,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(121,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(260,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(134,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(135,23): warning C4244: "=": konwersja z "int" do "float", możliwa utrata danych
C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\cw 6\src\main.cpp(382,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych
Camera.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
grk-cw6.vcxproj -> C:\Users\lukas\Desktop\Projekt - Grafika komputerowa\Projekt\Debug\Projekt.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -16,6 +16,8 @@
float width = 600;
float height = 600;
float moveTime = glutGet(GLUT_ELAPSED_TIME) / 100000000000.f;
GLuint programColor;
GLuint programTexture;
GLuint programSkybox;
@ -25,6 +27,7 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext fishContext;
Core::RenderContext skyboxContext;
Core::RenderContext bubbleContext;
glm::vec3 cameraPos = glm::vec3(0, 0, 5);
glm::vec3 cameraDir; // Wektor "do przodu" kamery
@ -33,13 +36,24 @@ float cameraAngle = 0;
glm::mat4 cameraMatrix, perspectiveMatrix;
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, 1.0f));
glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f));
glm::quat rotation = glm::quat(1, 0, 0, 0);
GLuint textureFish;
GLuint textureBubble;
GLuint textureShip;
glm::vec3 fishLocation[20];
bool fishChangeDirection[20];
float fishRadianDirection[20];
glm::mat4 fishTransformation[20];
int fishDirection[20];
// 0 - prosto, 1 - prawo, 2 - do ty³u, 3 - lewo
glm::vec3 bubbleLocation[30];
glm::vec3 fishLocation[10];
float mouseXPosition;
float mouseYPosition;
@ -183,6 +197,81 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
glUseProgram(0);
}
glm::vec3 moveBubble(glm::vec3 location, int index)
{
location.y = location.y + moveTime * 4;
if (location.y >= 10)
{
location = glm::ballRand(15.0);
location.y = -10;
}
bubbleLocation[index] = location;
return bubbleLocation[index];
}
glm::mat4 moveFish(glm::vec3 location, int index)
{
// zmiana kierunku
if (fishChangeDirection[index] == true)
{
fishDirection[index] = (fishDirection[index] + 1) % 4;
fishChangeDirection[index] = false;
}
// ruch
if (fishDirection[index] == 0)
{
if (location.z < -20)
{
fishChangeDirection[index] = true;
}
else {
location.z = location.z - moveTime * 5;
fishRadianDirection[index] = 0.0f;
}
}
else if (fishDirection[index] == 1)
{
if (location.x > 20)
{
fishChangeDirection[index] = true;
}
else {
location.x = location.x + moveTime * 10;
fishRadianDirection[index] = 90.0f;
}
}
else if (fishDirection[index] == 2)
{
if (location.z < -20)
{
fishChangeDirection[index] = true;
}
else {
location.z = location.z - moveTime * 10;
fishRadianDirection[index] = 180.0f;
}
}
else
{
if (location.x < -20)
{
fishChangeDirection[index] = true;
}
else {
location.x = location.x - moveTime * 10;
fishRadianDirection[index] = 270.0f;
}
}
fishLocation[index] = location;
fishTransformation[index] = glm::translate(fishLocation[index]) * glm::rotate(glm::radians(fishRadianDirection[index]), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.002f));
return fishTransformation[index];
}
void drawObjectSkybox(Core::RenderContext context)
{
glUseProgram(programSkybox);
@ -221,16 +310,26 @@ void renderScene()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.1f, 0.3f, 1.0f);
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.5f));
// rysowanie statku
glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)) * glm::rotate(glm::radians(270.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.001f));
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir) * glm::rotate(-cameraAngle, glm::vec3(0, 1, 0)) * shipInitialTransformation;
drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f));
drawObjectTexture(shipContext, shipModelMatrix, textureShip);
for (int i = 0; i < 10; i++)
// rysowanie ryb
for (int i = 0; i < 20; i++)
{
glm::mat4 fishInitialTransformation = glm::translate(fishLocation[i]) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.005f));
drawObjectTexture(fishContext, fishInitialTransformation, textureFish);
//glm::mat4 fishInitialTransformation = glm::translate(fishLocation[i]) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.005f));
//drawObjectTexture(fishContext, fishInitialTransformation, textureFish);
drawObjectTexture(fishContext, moveFish(fishLocation[i], i), textureFish);
}
// rysowanie b¹belków powietrza
for (int i = 0; i < 30; i++)
{
drawObjectTexture(bubbleContext, glm::translate(moveBubble(bubbleLocation[i], i)) * glm::rotate(glm::radians(0.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.1f)), textureBubble);
}
// rysowanie skyboxa
drawObjectSkybox(skyboxContext);
glutSwapBuffers();
@ -252,9 +351,32 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
void init()
{
for (int i = 0; i < 10; i++)
for (int i = 0; i < 20; i++)
{
fishLocation[i] = glm::ballRand(20.0);
fishDirection[i] = rand() % 4 + 0;
if (fishDirection[i] == 0)
{
fishRadianDirection[i] = 0.0f;
}
else if (fishDirection[i] == 1)
{
fishRadianDirection[i] = 90.0f;
}
else if (fishDirection[i] == 3)
{
fishRadianDirection[i] = 180.0f;
}
else
{
fishRadianDirection[i] = 270.0f;
}
fishChangeDirection[i] = false;
}
for (int i = 0; i < 30; i++)
{
bubbleLocation[i] = glm::ballRand(15.0);
}
srand(time(0));
@ -262,9 +384,12 @@ void init()
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
programSkybox = shaderLoader.CreateProgram("shaders/skybox.vert", "shaders/skybox.frag");
loadModelToContext("models/spaceship.obj", shipContext);
loadModelToContext("models/submarine.obj", shipContext);
loadModelToContext("models/TropicalFish01.obj", fishContext);
loadModelToContext("models/sphere.obj", bubbleContext);
textureFish = Core::LoadTexture("textures/TropicalFish01.jpg");
textureBubble = Core::LoadTexture("textures/bubble.png");
textureShip = Core::LoadTexture("textures/txt-subm-1.jpg");
// SKYBOX
// Create VAO, VBO, and EBO for the skybox