diff --git a/cw 6/Debug/Camera.obj b/cw 6/Debug/Camera.obj index c7e206c..31edc7e 100644 Binary files a/cw 6/Debug/Camera.obj and b/cw 6/Debug/Camera.obj differ diff --git a/cw 6/Debug/Render_Utils.obj b/cw 6/Debug/Render_Utils.obj index 014d1d4..9217aa2 100644 Binary files a/cw 6/Debug/Render_Utils.obj and b/cw 6/Debug/Render_Utils.obj differ diff --git a/cw 6/Debug/SOIL.obj b/cw 6/Debug/SOIL.obj index 0c4ff44..50b050c 100644 Binary files a/cw 6/Debug/SOIL.obj and b/cw 6/Debug/SOIL.obj differ diff --git a/cw 6/Debug/Shader_Loader.obj b/cw 6/Debug/Shader_Loader.obj index fb47552..6ad2b44 100644 Binary files a/cw 6/Debug/Shader_Loader.obj and b/cw 6/Debug/Shader_Loader.obj differ diff --git a/cw 6/Debug/Texture.obj b/cw 6/Debug/Texture.obj index 5dbfecd..c71cba6 100644 Binary files a/cw 6/Debug/Texture.obj and b/cw 6/Debug/Texture.obj differ diff --git a/cw 6/Debug/grk-cw6.log b/cw 6/Debug/grk-cw6.log index 282f82b..1dc8f63 100644 --- a/cw 6/Debug/grk-cw6.log +++ b/cw 6/Debug/grk-cw6.log @@ -1,4 +1,6 @@  main_6_1.cpp -C:\Users\User\Desktop\grk-cw\cw 6\src\main_6_1.cpp(144,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\User\Desktop\grk-cw\Debug\grk-cw6.exe +E:\Projects\Visual Studio 2019\GRK\cw 6\src\main_6_1.cpp(93,23): warning C4244: '=': conversion from 'int' to 'float', possible loss of data +E:\Projects\Visual Studio 2019\GRK\cw 6\src\main_6_1.cpp(94,23): warning C4244: '=': conversion from 'int' to 'float', possible loss of data +E:\Projects\Visual Studio 2019\GRK\cw 6\src\main_6_1.cpp(228,12): 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 + grk-cw6.vcxproj -> E:\Projects\Visual Studio 2019\GRK\Debug\grk-cw6.exe diff --git a/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog b/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog index 25f7435..4914cf3 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog and b/cw 6/Debug/grk-cw6.tlog/CL.command.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog b/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog index 0b6b529..813db0a 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog and b/cw 6/Debug/grk-cw6.tlog/CL.read.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog b/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog index 685f27b..3d034d3 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog and b/cw 6/Debug/grk-cw6.tlog/CL.write.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/grk-cw6.lastbuildstate b/cw 6/Debug/grk-cw6.tlog/grk-cw6.lastbuildstate index 57fc1c9..7c4552e 100644 --- a/cw 6/Debug/grk-cw6.tlog/grk-cw6.lastbuildstate +++ b/cw 6/Debug/grk-cw6.tlog/grk-cw6.lastbuildstate @@ -1,2 +1,2 @@ -PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30037:VCServicingVersionATL=14.29.30038:VCServicingVersionCrtHeaders=14.29.30040:VCServicingVersionCompilers=14.29.30040:TargetPlatformVersion=10.0.19041.0: -Debug|Win32|C:\Users\User\Desktop\grk-cw\| +#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 +Debug|Win32|E:\Projects\Visual Studio 2019\GRK\| diff --git a/cw 6/Debug/grk-cw6.tlog/grk-cw6.write.1u.tlog b/cw 6/Debug/grk-cw6.tlog/grk-cw6.write.1u.tlog index 1244dd6..46b134b 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/grk-cw6.write.1u.tlog and b/cw 6/Debug/grk-cw6.tlog/grk-cw6.write.1u.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/link.command.1.tlog b/cw 6/Debug/grk-cw6.tlog/link.command.1.tlog index a836614..8671f01 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/link.command.1.tlog and b/cw 6/Debug/grk-cw6.tlog/link.command.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/link.delete.1.tlog b/cw 6/Debug/grk-cw6.tlog/link.delete.1.tlog new file mode 100644 index 0000000..7b5ea82 Binary files /dev/null and b/cw 6/Debug/grk-cw6.tlog/link.delete.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/link.read.1.tlog b/cw 6/Debug/grk-cw6.tlog/link.read.1.tlog index 11c49ca..cacf604 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/link.read.1.tlog and b/cw 6/Debug/grk-cw6.tlog/link.read.1.tlog differ diff --git a/cw 6/Debug/grk-cw6.tlog/link.write.1.tlog b/cw 6/Debug/grk-cw6.tlog/link.write.1.tlog index d26b19e..1c40e6c 100644 Binary files a/cw 6/Debug/grk-cw6.tlog/link.write.1.tlog and b/cw 6/Debug/grk-cw6.tlog/link.write.1.tlog differ diff --git a/cw 6/Debug/image_DXT.obj b/cw 6/Debug/image_DXT.obj index 8f9064f..4b15262 100644 Binary files a/cw 6/Debug/image_DXT.obj and b/cw 6/Debug/image_DXT.obj differ diff --git a/cw 6/Debug/image_helper.obj b/cw 6/Debug/image_helper.obj index 5c48eff..f2bf4cc 100644 Binary files a/cw 6/Debug/image_helper.obj and b/cw 6/Debug/image_helper.obj differ diff --git a/cw 6/Debug/main_6_1.obj b/cw 6/Debug/main_6_1.obj index a741646..6c9ba03 100644 Binary files a/cw 6/Debug/main_6_1.obj and b/cw 6/Debug/main_6_1.obj differ diff --git a/cw 6/Debug/stb_image_aug.obj b/cw 6/Debug/stb_image_aug.obj index 241d24c..4e49e78 100644 Binary files a/cw 6/Debug/stb_image_aug.obj and b/cw 6/Debug/stb_image_aug.obj differ diff --git a/cw 6/Debug/vc142.idb b/cw 6/Debug/vc142.idb index e433d13..2435141 100644 Binary files a/cw 6/Debug/vc142.idb and b/cw 6/Debug/vc142.idb differ diff --git a/cw 6/Debug/vc142.pdb b/cw 6/Debug/vc142.pdb index 825f66e..4280644 100644 Binary files a/cw 6/Debug/vc142.pdb and b/cw 6/Debug/vc142.pdb differ diff --git a/cw 6/models/Submarine.3DS b/cw 6/models/Submarine.3DS new file mode 100644 index 0000000..8d1b1b1 Binary files /dev/null and b/cw 6/models/Submarine.3DS differ diff --git a/cw 6/models/TropicalFish01.3ds b/cw 6/models/TropicalFish01.3ds new file mode 100644 index 0000000..a49a3fd Binary files /dev/null and b/cw 6/models/TropicalFish01.3ds differ diff --git a/cw 6/src/main_6_1.cpp b/cw 6/src/main_6_1.cpp index 31ac7c1..b07e9b7 100644 --- a/cw 6/src/main_6_1.cpp +++ b/cw 6/src/main_6_1.cpp @@ -17,19 +17,19 @@ GLuint programTexture; Core::Shader_Loader shaderLoader; Core::RenderContext shipContext; -Core::RenderContext sphereContext; +Core::RenderContext fishContext; -glm::vec3 cameraPos = glm::vec3(0, 0, 5); +glm::vec3 cameraPos = glm::vec3(0, 0, 0); glm::vec3 cameraDir; // Wektor "do przodu" kamery glm::vec3 cameraSide; // Wektor "w bok" kamery + +glm::vec3 vehiclePos = glm::vec3(0, 0, 0); +glm::vec3 vehicleDir; // Wektor "do przodu" kamery +glm::vec3 vehicleSide; // Wektor "w bok" kamery +float vehicleAngle = 0; + float cameraAngle = 0; -int ARRAY_LENGTH = 10; - -int arr_x[10] = {0}; -int arr_y[10] = {0}; -int arr_z[10] = {0}; - glm::mat4 cameraMatrix, perspectiveMatrix; glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f)); @@ -37,34 +37,95 @@ glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f)); glm::quat rotation = glm::quat(1, 0, 0, 0); GLuint textureAsteroid; +GLuint textureFish01; + + +int WIN_WIDTH = 1280; +int WIN_HEIGHT = 720; + +glm::vec3 planetLocation[10]; + +float mouseXPosition; +float mouseYPosition; +float mouseXPositionLast; +float mouseYPositionLast; +float delta_x = 0; +float delta_y = 0; +glm::quat rotationCamera; +glm::quat rotation_y; +glm::quat rotation_x; +float dy = 0; +float dx = 0; + + void keyboard(unsigned char key, int x, int y) { - + float angleSpeed = 0.1f; float moveSpeed = 0.1f; - switch(key) + switch (key) { - case 'z': cameraAngle -= angleSpeed; break; - case 'x': cameraAngle += angleSpeed; break; - case 'w': cameraPos += cameraDir * moveSpeed; break; - case 's': cameraPos -= cameraDir * moveSpeed; break; - case 'd': cameraPos += cameraSide * moveSpeed; break; - case 'a': cameraPos -= cameraSide * moveSpeed; break; + case 'z': vehicleAngle -= angleSpeed; delta_x = vehicleAngle; break; + case 'x': vehicleAngle += angleSpeed; cameraAngle = vehicleAngle; break; + case 'w': vehiclePos += vehicleDir * moveSpeed; break; + case 's': vehiclePos -= vehicleDir * moveSpeed; break; + case 'd': vehiclePos += vehicleSide * moveSpeed; break; + case 'a': vehiclePos -= vehicleSide * moveSpeed; break; + //case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break; + //case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break; + + case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(vehicleAngle, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break; + + //delta_x = 0; delta_y = 0; cameraPos = glm::vec3(0, 0, 5); rotation = glm::quat(1, 0, 0, 0); dy = 0; dx = 0; mouseXPositionLast = mouseXPosition; mouseYPositionLast = mouseYPosition; + //glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT/ 2); } + + //rot_y = glm::angleAxis(vehicleAngle * 0.01f, glm::vec3(0, 1, 0)); } void mouse(int x, int y) { + if (mouseXPositionLast >= 0) { + delta_x = x - mouseXPositionLast; + delta_y = y - mouseYPositionLast; + } + mouseXPositionLast = x; + mouseYPositionLast = y; } glm::mat4 createCameraMatrix() { - cameraDir = glm::vec3(cosf(cameraAngle - glm::radians(90.0f)), 0.0f, sinf(cameraAngle - glm::radians(90.0f))); - glm::vec3 up = glm::vec3(0, 1, 0); - cameraSide = glm::cross(cameraDir, up); + //delta_x = delta_x + vehicleAngle; + glm::quat rot_x = glm::angleAxis(delta_y * 0.01f, glm::vec3(1, 0, 0)); + glm::quat rot_y = glm::angleAxis(delta_x * 0.01f, glm::vec3(0, 1, 0)); + + + + dy += delta_y; + dx += delta_x; + delta_x = 0; + delta_y = 0; + + + vehicleDir = glm::vec3(cosf(vehicleAngle - glm::radians(90.0f)), 0.0f, sinf(vehicleAngle - glm::radians(90.0f))); + + vehicleSide = glm::cross(vehicleDir, glm::vec3(0, 1, 0)); + + rotation_x = glm::normalize(rot_x * rotation_x); + rotation_y = glm::normalize(rot_y * rotation_y); + + rotationCamera = glm::normalize(rotation_y * rotation_x); + + glm::quat inverse_rot = glm::inverse(rotationCamera); + + cameraDir = inverse_rot * glm::vec3(0, 0, -1); + glm::vec3 up = glm::vec3(0, 1, 0); + cameraSide = inverse_rot * glm::vec3(1, 0, 0); + + + return Core::createViewMatrixQuat(vehiclePos + glm::vec3(0, 2, 2), rotationCamera); - return Core::createViewMatrix(cameraPos, cameraDir, up); } void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color) @@ -111,16 +172,35 @@ 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.25f,0)) * glm::rotate(glm::radians(180.0f), glm::vec3(0,1,0)) * glm::scale(glm::vec3(0.25f)); - glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::rotate(-cameraAngle, glm::vec3(0,1,0)) * shipInitialTransformation; - drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f)); - + glm::mat4 shipInitialTransformation = glm::translate(glm::vec3(0, 0, 0)); + // Scaling models + glm::vec3 shipScale = glm::vec3(0.01, 0.01, 0.01); + shipInitialTransformation = glm::scale(shipInitialTransformation, shipScale); - for (int i = 0; i < ARRAY_LENGTH; i++) { - drawObjectTexture(sphereContext, glm::translate(glm::vec3(arr_x[i], arr_y[i], arr_z[i])), textureAsteroid); + shipInitialTransformation = 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)); + glm::mat4 shipModelMatrix = glm::translate(vehiclePos + vehicleDir) * glm::rotate(-vehicleAngle, glm::vec3(0, 1, 0)) * shipInitialTransformation; + drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f)); + + + glm::mat4 modelMatrix = glm::translate(glm::vec3(0, 0, 0)); + // Scaling models + glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001); + modelMatrix = glm::scale(modelMatrix, scale); + + drawObjectTexture(fishContext, modelMatrix, textureFish01); + + for (int i = 0; i < 10; i++) + { + + glm::mat4 modelMatrix = glm::translate(planetLocation[i]); + // Scaling models + glm::vec3 scale = glm::vec3(0.001, 0.001, 0.001); + modelMatrix = glm::scale(modelMatrix, scale); + + drawObjectTexture(fishContext, modelMatrix, textureFish01); } - drawObjectTexture(sphereContext, glm::translate(glm::vec3(0,0,0)), textureAsteroid); + glutSwapBuffers(); } @@ -139,21 +219,20 @@ void loadModelToContext(std::string path, Core::RenderContext& context) } void init() -{ +{ + for (int i = 0; i < 10; i++) + { + planetLocation[i] = glm::ballRand(20.0); + } srand(time(0)); glEnable(GL_DEPTH_TEST); programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag"); programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag"); - loadModelToContext("models/spaceship.obj", shipContext); - loadModelToContext("models/sphere.obj", sphereContext); - - for (int i = 0; i < ARRAY_LENGTH; i++) { - arr_x[i] = rand() % 11 - 10; - arr_y[i] = rand() % 11 - 10; - arr_z[i] = rand() % 11 - 10; - } + loadModelToContext("models/Submarine.3DS", shipContext); + loadModelToContext("models/TropicalFish01.3ds", fishContext); textureAsteroid = Core::LoadTexture("textures/asteroid.png"); + textureFish01 = Core::LoadTexture("textures/TropicalFish01.jpg"); } void shutdown() @@ -167,16 +246,18 @@ void idle() glutPostRedisplay(); } -int main(int argc, char ** argv) +int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(200, 200); - glutInitWindowSize(600, 600); + glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT); + glutCreateWindow("OpenGL Pierwszy Program"); glewInit(); init(); + glutWarpPointer(WIN_WIDTH / 2, WIN_HEIGHT / 2); glutKeyboardFunc(keyboard); glutPassiveMotionFunc(mouse); glutDisplayFunc(renderScene); @@ -187,4 +268,4 @@ int main(int argc, char ** argv) shutdown(); return 0; -} +} \ No newline at end of file diff --git a/cw 6/textures/TropicalFish01.jpg b/cw 6/textures/TropicalFish01.jpg new file mode 100644 index 0000000..4461275 Binary files /dev/null and b/cw 6/textures/TropicalFish01.jpg differ