add more plants

This commit is contained in:
Łukasz Śliwiński 2022-02-10 17:32:07 +01:00
parent 73db74da7a
commit d8c487d3dd
22 changed files with 60 additions and 29 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project> <Project>
<ProjectOutputs> <ProjectOutputs>
<ProjectOutput> <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> </ProjectOutput>
</ProjectOutputs> </ProjectOutputs>
<ContentFiles /> <ContentFiles />

View File

@ -1,2 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.30.30705:TargetPlatformVersion=10.0.19041.0: 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,4 +1,4 @@
 main.cpp  main.cpp
C:\Users\Tomek\source\repos\Grafika\GrafikaProjekt\pliki\src\main.cpp(302,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\pliki\src\main.cpp(329,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” Camera.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
projekt.vcxproj -> C:\Users\Tomek\source\repos\Grafika\GrafikaProjekt\Debug\grk-cw6.exe projekt.vcxproj -> C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe

Binary file not shown.

Binary file not shown.

View File

@ -19,6 +19,7 @@ GLuint programTexture;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
int random[320]; int random[320];
int random2[320]; int random2[320];
int randomRock[65];
Core::RenderContext shipContext; Core::RenderContext shipContext;
Core::RenderContext sphereContext; Core::RenderContext sphereContext;
@ -113,7 +114,7 @@ void keyboard(unsigned char key, int x, int y)
{ {
float angleSpeed = 0.1f; float angleSpeed = 0.1f;
float moveSpeed = 0.1f; float moveSpeed = 0.4f;
switch(key) switch(key)
{ {
case 'z': cameraAngle -= angleSpeed; break; case 'z': cameraAngle -= angleSpeed; break;
@ -135,7 +136,7 @@ void mouse(int x, int y)
glm::mat4 createCameraMatrix() glm::mat4 createCameraMatrix()
{ {
rotation = glm::normalize(rotation * glm::angleAxis((float)(mouseX * 0.01), cameraUp) * glm::angleAxis((float)(mouseY * 0.01), cameraSide)); rotation = glm::normalize(rotation * glm::angleAxis((float)(mouseX * 0.05), cameraUp) * glm::angleAxis((float)(mouseY * 0.05), cameraSide));
mouseX = mouseY = 0; mouseX = mouseY = 0;
cameraDir = glm::inverse(rotation) * glm::vec3(0, 0, -1); cameraDir = glm::inverse(rotation) * glm::vec3(0, 0, -1);
cameraSide = glm::inverse(rotation) * glm::vec3(-1, 0, 0); cameraSide = glm::inverse(rotation) * glm::vec3(-1, 0, 0);
@ -237,6 +238,50 @@ size_t split(const std::string& txt, std::vector<std::string>& strs, char ch)
return strs.size(); return strs.size();
} }
void createFlora()
{
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, ' ');
if (random[i] > 50)
drawObjectTexture(plant1, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 1.2, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i]), glm::vec3(0, 1, 0)), texturePlant1);
else
drawObjectTexture(grass, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 1.15, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i]), glm::vec3(0, 1, 0)), texturePlant3);
}
}
split(myText, v, ' ');
if (random[i] > 50)
drawObjectTexture(plant3, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 0.9, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i]), glm::vec3(0, 1, 0)), texturePlant3);
else
drawObjectTexture(plant4, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 1.2, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i]), glm::vec3(0, 1, 0)), texturePlant4);
}
}
void createRockFlora()
{
std::ifstream MyReadFile("models/cave.obj");
std::string myText;
std::vector<std::string> v;
for (int i = 0; i < 65; i++)
{
for (int i = 0; i < randomRock[i]; i++)
std::getline(MyReadFile, myText);
split(myText, v, ' ');
if (randomRock[i] > 34)
drawObjectTexture(plant5, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 0.6, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i * 3]), glm::vec3(0, 1, 0)), texturePlant5);
else
drawObjectTexture(plant4, glm::translate(glm::vec3(std::stof(v[1]), std::stof(v[2]) - 0.6, std::stof(v[3]))) * glm::rotate(glm::degrees((float)random2[i*3]), glm::vec3(0, 1, 0)), texturePlant4);
}
}
void renderScene() void renderScene()
{ {
// Aktualizacja macierzy widoku i rzutowania // Aktualizacja macierzy widoku i rzutowania
@ -256,30 +301,12 @@ void renderScene()
drawObjectTexture(sphereContext, glm::translate(glm::vec3(0, -1.2, 0)), textureAsteroid); drawObjectTexture(sphereContext, glm::translate(glm::vec3(0, -1.2, 0)), textureAsteroid);
drawObjectTexture(fish1Context, glm::translate(glm::vec3(0, 0, 0)), textureFish1); drawObjectTexture(fish1Context, glm::translate(glm::vec3(0, 0, 0)), textureFish1);
rypa = (rypa + 1) % 360; 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); drawObjectTexture(fish2Context, glm::rotate(glm::degrees((float)rypa / (float)360), glm::vec3(0, -1, 0)) * glm::translate(glm::vec3(0.5, 0, (float)rypa/(float)360)), textureFish2);
drawObjectTexture(smiglo, shipModelMatrix * glm::translate(glm::vec3(0, -0.3, -1)) * glm::rotate(glm::degrees((float)rypa), glm::vec3(0, 0, 1)), textureSmiglo); drawObjectTexture(smiglo, shipModelMatrix * glm::translate(glm::vec3(0, -0.3, -1)) * glm::rotate(glm::degrees((float)rypa), glm::vec3(0, 0, 1)), textureSmiglo);
drawObjectTexture(grass, glm::translate(glm::vec3(0, 1, 0)), texturePlant3); drawObjectTexture(cave, glm::translate(glm::vec3(0, -0.6, 0)), textureAsteroid);
drawObjectTexture(plant4, glm::translate(glm::vec3(0, 1, 0)), texturePlant4);
drawObjectTexture(plant5, glm::translate(glm::vec3(0, 1, 0)), texturePlant5);
drawObjectTexture(cave, glm::translate(glm::vec3(0, -0.4, 0)), textureAsteroid);
std::ifstream MyReadFile("models/teren1.obj"); createFlora();
std::string myText; createRockFlora();
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(); glutSwapBuffers();
} }
@ -305,6 +332,10 @@ void init()
random[i] = rand() % 50 + 25; random[i] = rand() % 50 + 25;
random2[i] = rand() % 361 + 1; random2[i] = rand() % 361 + 1;
} }
for (int i = 0; i < 65; i++)
{
randomRock[i] = rand() % 20 + 30;
}
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
programCubemap = shaderLoader.CreateProgram("shaders/shader_cubemap.vert", "shaders/shader_cubemap.frag"); programCubemap = shaderLoader.CreateProgram("shaders/shader_cubemap.vert", "shaders/shader_cubemap.frag");
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag"); programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
@ -355,7 +386,7 @@ int main(int argc, char ** argv)
{ {
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 200); glutInitWindowPosition(200, 0);
glutInitWindowSize(600, 600); glutInitWindowSize(600, 600);
glutCreateWindow("OpenGL Pierwszy Program"); glutCreateWindow("OpenGL Pierwszy Program");
glewInit(); glewInit();