add plants

This commit is contained in:
Łukasz Śliwiński 2022-02-10 00:47:19 +01:00
parent 3d27017c07
commit 5720fc00d5
22 changed files with 55 additions and 6 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\Tomek\Source\Repos\Grafika\GrafikaProjekt\Debug\grk-cw6.exe</FullPath>
<FullPath>C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

View File

@ -1,2 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.30.30705:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\Tomek\Source\Repos\Grafika\GrafikaProjekt\|
Debug|Win32|C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\|

Binary file not shown.

View File

@ -1 +1,4 @@
 projekt.vcxproj -> C:\Users\Tomek\Source\Repos\Grafika\GrafikaProjekt\Debug\grk-cw6.exe
 main.cpp
C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\pliki\src\main.cpp(289,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”
projekt.vcxproj -> C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,7 @@
#include <iostream>
#include <cmath>
#include <vector>
#include <fstream>
#include "stb_image.h"
#include "Shader_Loader.h"
@ -16,6 +17,8 @@ GLuint programCubemap;
GLuint programTexture;
Core::Shader_Loader shaderLoader;
int random[320];
int random2[320];
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
@ -79,6 +82,7 @@ glm::vec3 cameraUp;
float cameraAngle = 0;
int lastMouseX, lastMouseY, mouseX, mouseY;
int rypa = 0;
unsigned int cubemapTexture;
glm::mat4 cameraMatrix, perspectiveMatrix;
@ -205,6 +209,26 @@ void drawObjectCubemap(glm::mat4 modelMatrix, unsigned int textureId)
glUseProgram(0);
}
size_t split(const std::string& txt, std::vector<std::string>& strs, char ch)
{
size_t pos = txt.find(ch);
size_t initialPos = 0;
strs.clear();
// Decompose statement
while (pos != std::string::npos) {
strs.push_back(txt.substr(initialPos, pos - initialPos));
initialPos = pos + 1;
pos = txt.find(ch, initialPos);
}
// Add the last one
strs.push_back(txt.substr(initialPos, std::min(pos, txt.size()) - initialPos + 1));
return strs.size();
}
void renderScene()
{
// Aktualizacja macierzy widoku i rzutowania
@ -223,9 +247,26 @@ void renderScene()
drawObjectTexture(shipContext, shipModelMatrix, textureSubmarine);
drawObjectTexture(sphereContext, glm::translate(glm::vec3(0, -1.2, 0)), textureAsteroid);
drawObjectTexture(fish1Context, glm::translate(glm::vec3(0, 0, 0)), textureFish1);
drawObjectTexture(fish2Context, glm::translate(glm::vec3(0.25f, 0, 0)), textureFish2);
drawObjectTexture(plant1, glm::translate(glm::vec3(0.25f, -0.4f, 0)), texturePlant1);
drawObjectTexture(plant3, glm::translate(glm::vec3(0.25f, 0, 0)), texturePlant3);
rypa = (rypa + 1) % 360;
drawObjectTexture(fish2Context, glm::translate(glm::vec3(0.25f, 0, (float)rypa/(float)360)) * glm::rotate(glm::degrees((float)rypa / (float)360), glm::vec3(0, 1, 0)), textureFish2);
std::ifstream MyReadFile("models/teren1.obj");
std::string myText;
std::vector<std::string> v;
for (int i = 1; i < 320; i++)
{
for (int j = 0; j < random[i]; j++)
{
std::getline(MyReadFile, myText);
if (j == 25)
{
split(myText, v, ' ');
drawObjectTexture(plant1, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 1.25, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i]), glm::vec3(0, 1, 0)), texturePlant1);
}
}
split(myText, v, ' ');
drawObjectTexture(plant3, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 0.9, std::stof(v[3]))), texturePlant3);
}
glutSwapBuffers();
}
@ -246,6 +287,11 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
void init()
{
srand(time(0));
for (int i = 0; i < 320; i++)
{
random[i] = rand() % 50 + 25;
random2[i] = rand() % 361 + 1;
}
glEnable(GL_DEPTH_TEST);
programCubemap = shaderLoader.CreateProgram("shaders/shader_cubemap.vert", "shaders/shader_cubemap.frag");
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");