{"id":22042962,"url":"https://github.com/spear97/3d-world","last_synced_at":"2026-04-28T18:02:32.887Z","repository":{"id":222698574,"uuid":"758137023","full_name":"spear97/3D-World","owner":"spear97","description":"An Interactive 3D Environment project that was created during my Spring 2022 Semester at Texas Wesleyan University. A custom graphics Engine Made from Scratch Utilizing OpenGL and C++ to render different environment and spawn 3d object into the Environment. ","archived":false,"fork":false,"pushed_at":"2024-02-24T01:41:08.000Z","size":247017,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T19:48:45.974Z","etag":null,"topics":["3d-computer-graphics","3d-engine","computer-graphics","computer-graphics-opengl","cpp","object-oriented-programming","opengl","rendering-pipeline","software-development","visual-studio"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spear97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-15T17:37:45.000Z","updated_at":"2024-02-17T03:47:36.000Z","dependencies_parsed_at":"2025-01-28T19:56:37.999Z","dependency_job_id":null,"html_url":"https://github.com/spear97/3D-World","commit_stats":null,"previous_names":["spear97/3d-world"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spear97%2F3D-World","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spear97%2F3D-World/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spear97%2F3D-World/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spear97%2F3D-World/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spear97","download_url":"https://codeload.github.com/spear97/3D-World/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245111927,"owners_count":20562511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-computer-graphics","3d-engine","computer-graphics","computer-graphics-opengl","cpp","object-oriented-programming","opengl","rendering-pipeline","software-development","visual-studio"],"created_at":"2024-11-30T12:13:52.501Z","updated_at":"2026-04-28T18:02:27.828Z","avatar_url":"https://github.com/spear97.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 3D World\n\n## Description\n\nAn Interactive 3D Environment project that was created during my Spring 2022 Semester at Texas Wesleyan University. A custom graphics Engine Made from Scratch Utilizing OpenGL and C++ to render different environment and spawn 3d object into the Environment. \n\n## Table of Contents\n- Screenshots\n  - [UI](#UI)\n  - [Forest Environment](#Forest)\n  - [Muddy Environment](#Muddy)\n  - [Desert Environment](#Desert)\n- Classes\n  - [Vector3d](#Vector3d)\n  - [ObjLoader](#ObjLoader)\n  - [Polyhedron](#Polyhedron)\n- Technology\n  - [Cpp](#Cpp)\n  - [OpenGL](#OpenGL)\n\n## Screenshots\n\n### UI\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/UI_A.png)  ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/UI_B.png) \n\n### Default\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/Default.png)  \nHow the application will load initially\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/Default_Grass.png) \n\n3D Grass Object that was rendered from Grass.obj\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/Default_Wukong.png) \n\n3D Wukong Object that was rendered from Wukong.obj\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/Default-Military-Vehicle.png) \n\n3D MIlitary Vehicle Object that was rendered from MilitaryVehicle.obj\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/Default-Patrick.png) \n\n3D Patrick Object that was rendered from patrick.obj\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/Default-Sonic.png) \n\n3D Sonic Object that was rendered from Sonic.obj\n\n### Forest \n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/ForestA.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/ForestB.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/ForestC.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/ForestD.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/ForestE.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/ForestF.png)    \n\n### Muddy \n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DirtA.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DirtB.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DirtC.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DirtD.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DirtE.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DirtF.png) \n\n### Desert Environment\n\n![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DesertA.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DesertB.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DesertC.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DesertD.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DesertE.png) ![Custom Screenshot](https://github.com/spear97/3D-World/blob/main/ScreenShots/DesertF.png)\n\n## Classes\n\n### Vector3d\n\nThe `Vector3d` class represents a 3D vector with x, y, and z components. It includes various constructors, operator overloads, and functions for vector manipulation such as addition, subtraction, scalar multiplication, normalization, and rotation.\n\n#### Usage\n\nTo use the `Vector3d` class in your project, include the `Vector3d.h` header file and make sure to link it properly.\n\n```cpp\n#include \"Vector3d.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    // Create vectors\n    mathtool::Vector3d v1(1.0, 2.0, 3.0);\n    mathtool::Vector3d v2(4.0, 5.0, 6.0);\n\n    // Perform operations\n    mathtool::Vector3d sum = v1 + v2;\n    mathtool::Vector3d difference = v1 - v2;\n    \n    // Output results\n    std::cout \u003c\u003c \"Sum: \" \u003c\u003c sum \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"Difference: \" \u003c\u003c difference \u003c\u003c std::endl;\n\n    return 0;\n}\n```\n\n#### Operators\n\nThe Vector3d class overloads the following operators:\n- `+=`, `-=`: Addition and subtraction with another vector.\n- `*=`: Scalar multiplication with a double.\n- `/=`: Scalar division with a double.\n- `==`, `!=`: Equality and inequality comparisons.\n- `+`, `-`: Addition and subtraction of vectors.\n- `*`: Dot product with another vector or scalar multiplication with a double.\n- `/`: Scalar division with a double.\n- `^`: Power with another vector.\n- `%`: Cross product with another vector.\n- `\u003c\u003c`: Output stream for vector.\n- `\u003e\u003e`: Input stream for vector.\n\n### Functions\n\nThe Vector3d class provides the following member functions:\n\n- `norm()`: Get the norm (magnitude) of the vector.\n- `normsqr()`: Get the squared norm of the vector.\n- `selfNormalize()`: Normalize the vector in place.\n- `normalize()`: Return a normalized copy of the vector.\n- `comp()`: Find the component of this vector along another vector's direction.\n- `selfScale()`: Scale the vector to a certain size in place.\n- `scale()`: Return a scaled copy of the vector.\n- `rotateX()`, `rotateY()`, `rotateZ()`: Rotate the vector about the X, Y, or Z axis by a given angle.\n- `rotateXd()`, `rotateYd()`, `rotateZd()`: Rotate the vector about the X, Y, or Z axis by a given angle in degrees.\n- `reset()`: Set all components of the vector to zero.\n- `GetX()`, `GetY()`, `GetZ()`: Get individual components of the vector.\n- `SetX()`, `SetY()`, `SetZ()`: Set individual components of the vector.\n\n#### Examples\n\nHere are some examples demonstrating the usage of the Vector3d class:\n\n```cpp\n#include \"Vector3d.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    mathtool::Vector3d v1(1.0, 2.0, 3.0);\n    mathtool::Vector3d v2(4.0, 5.0, 6.0);\n\n    // Addition\n    mathtool::Vector3d sum = v1 + v2;\n    std::cout \u003c\u003c \"Sum: \" \u003c\u003c sum \u003c\u003c std::endl;\n\n    // Scalar multiplication\n    mathtool::Vector3d scaled = v1 * 2.0;\n    std::cout \u003c\u003c \"Scaled: \" \u003c\u003c scaled \u003c\u003c std::endl;\n\n    // Dot product\n    double dot = v1 * v2;\n    std::cout \u003c\u003c \"Dot product: \" \u003c\u003c dot \u003c\u003c std::endl;\n\n    // Normalization\n    mathtool::Vector3d normalized = v1.normalize();\n    std::cout \u003c\u003c \"Normalized: \" \u003c\u003c normalized \u003c\u003c std::endl;\n\n    return 0;\n}\n```\n### ObjLoader\n\nThe `ObjLoader` class provides functionality for loading Wavefront OBJ files, extracting vertex positions, texture coordinates, normals, and faces. It can be used to load 3D models from OBJ files for rendering or other purposes.\n\n### Usage \n\nTo use the `ObjLoader` class, include the `ObjLoader.h` header file in your C++ project.\n\n### Functions\n\n- `ObjLoader()`: Default constructor.\n- `ObjLoader(string _fname)`: Constructor that sets the filename to load.\n- `void Load()`: Loads the OBJ file specified by the filename.\n- `void Print()`: Prints information about the loaded OBJ file.\n- `vector\u003cVector3d\u003e GetVertices()`: Returns the vector of vertex positions.\n- `vector\u003cpair\u003cdouble, double\u003e\u003e GetTextureCoordinates()`: Returns the vector of texture coordinates.\n- `vector\u003cVector3d\u003e GetNormals()`: Returns the vector of normals.\n- `vector\u003cFace\u003e GetFaces()`: Returns the vector of faces.\n\n### Structs\n\n#### Face\n\n- `void Print()`: Prints the IDs of vertices in the face.\n- `vector\u003cint\u003e ids`: Vector of vertex IDs for the face.\n- `vector\u003cint\u003e texIds`: Vector of texture coordinate IDs for the face.\n- `vector\u003cint\u003e normalIds`: Vector of normal IDs for the face.\n\n### Examples\n\nHere is an example of how to use the ObjLoader class:\n\n```cpp\n#include \"ObjLoader.h\"\n\nint main() {\n    ObjLoader obj(\"model.obj\");\n    obj.Load();\n\n    obj.Print(); // Print information about the loaded model\n\n    // Get the loaded data\n    vector\u003cVector3d\u003e vertices = obj.GetVertices();\n    vector\u003cpair\u003cdouble, double\u003e\u003e texCoords = obj.GetTextureCoordinates();\n    vector\u003cVector3d\u003e normals = obj.GetNormals();\n    vector\u003cFace\u003e faces = obj.GetFaces();\n\n    // Use the data...\n}\n```\n\n### ObjLoader\n\nThe `Polyhedron` class extends the functionality of `ObjLoader` to represent a 3D polyhedron. It includes methods for drawing the polyhedron, recentring its position, and adjusting its orientation. This class is useful for rendering and manipulating 3D models loaded from Wavefront OBJ files.\n\n### Usage \nTo use the `Polyhedron` class, include the `Polyhedron.h` header file in your C++ project.\n\n```cpp\n#include \"Polyhedron.h\"\n```\n\n### Creating a Polyhedron\n\nYou can create a Polyhedron instance by providing the filename of the OBJ file, center position, rotation angle around Y-axis, and color:\n\n```cpp\nVector3d centerPosition(0.0, 0.0, 0.0);\ndouble rotationY = 0.0; // in radians\nVector3d color(1.0, 0.0, 0.0); // Red color\nPolyhedron poly(\"path/to/file.obj\", centerPosition, rotationY, color);\n```\n\n### Drawing the Polyhedron\n\nYou can draw the polyhedron using the Draw() function:\n\n```cpp\npoly.Draw();\n```\n\n### Recentering\n\nYou can recentre the polyhedron's position using Recenter() or only on the XZ-plane using RecenterXZ():\n\n```cpp\npoly.Recenter();   // Recenters the polyhedron\npoly.RecenterXZ(); // Recenters the polyhedron on the XZ-plane\n```\n\n### Constructors\n\n- `Polyhedron(string _fname, Vector3d _c, double _rotY, Vector3d _clr)`: Constructor that takes the filename of the OBJ file, center position _c, rotation angle around Y-axis _rotY, and color _clr.\n- `Polyhedron(const Polyhedron\u0026 other)`: Copy constructor.\n\n### Functions\n\n- `void Draw()`: Draws the polyhedron.\n- `void Recenter()`: Recenters the polyhedron's position.\nvoid RecenterXZ(): Recenters the polyhedron's position on the XZ-plane.\n\n### Members\n\nVector3d center: Center position of the polyhedron.\ndouble rotY: Rotation angle around the Y-axis.\nVector3d color: Color of the polyhedron.\n\n### Examples\n\nHere is an example of how to use the Polyhedron class:\n\n```cpp\n#include \"Polyhedron.h\"\n\nint main() {\n    Vector3d centerPosition(0.0, 0.0, 0.0);\n    double rotationY = 0.0; // in radians\n    Vector3d color(1.0, 0.0, 0.0); // Red color\n\n    Polyhedron poly(\"model.obj\", centerPosition, rotationY, color);\n    poly.Load(); // Load the OBJ file\n    poly.Recenter(); // Recenter the polyhedron\n    poly.Draw(); // Draw the polyhedron\n\n    return 0;\n}\n```\n\n## Technology\n\n### Cpp\n\n#### What is C++?\nC++ is a high-level programming language that was developed as an extension of the C programming language. It was created by Bjarne Stroustrup at Bell Labs in the early 1980s, and it has become one of the most widely used languages, particularly for systems programming, game development, and other performance-intensive applications.\n\n#### Features of C++\n- `Object-Oriented`: C++ supports the principles of object-oriented programming (OOP) such as classes, inheritance, polymorphism, encapsulation, and abstraction.\n\n- `Efficient`: It allows low-level manipulation of data, making it suitable for system programming, embedded programming, and other performance-critical applications.\n\n- `Standard Library`: C++ comes with a rich standard library that provides a set of functions manipulating various data structures, algorithms, and more.\n- `Platform Independence`: C++ programs can run on different operating systems with minimal changes, thanks to its compilers available for various platforms.\n- `Compatibility with C`: C++ is largely compatible with C code. It is possible to include C code in C++ programs, and many C programs can be compiled with a C++ compiler.\n\n#### Use Cases\n\n- `System Software`: Operating systems, device drivers, firmware, and other system-level software are often written in C++ due to its low-level capabilities.\n- `Game Development`: Many game engines and game development frameworks (like Unreal Engine, Unity) use C++ as a primary language for game development due to its performance.\n- `Application Software`: C++ is used for creating various types of applications, including desktop applications, web browsers (like Mozilla Firefox), productivity software, etc.\n- `Embedded Systems`: C++ is used in embedded systems programming where resources are limited, but performance is crucial.\n  \n#### Example\n\nHere's a simple \"Hello, World!\" program in C++:\n\n```cpp\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c \"Hello, World!\" \u003c\u003c std::endl;\n    return 0;\n}\n```\n\nThis program uses the iostream library to print \"Hello, World!\" to the console. The `main()` function is the entry point of the program, and `std::cout` is used for output. `\u003c\u003c` is the stream insertion operator used to output data to the console, and `std::endl` is used to end the line.\n\nC++ has a rich syntax and many features beyond this simple example, making it a powerful and flexible language for a wide range of programming tasks.\n\n### OpenGL\n\n`OpenGL (Open Graphics Library)` is an open-source, cross-platform graphics `API (Application Programming Interface)` for rendering 2D and 3D vector graphics. It provides a set of functions for rendering complex 2D and 3D graphics, enabling developers to create interactive applications such as video games, simulations, visualizations, and more. `OpenGL` is widely used in the computer graphics industry and is supported on various platforms, including Windows, macOS, Linux, and mobile operating systems.\n\n##### Features of OpenGL\n\n- `Cross-Platform`: `OpenGL` is designed to be platform-independent, allowing developers to write code once and have it run on different operating systems without significant modifications.\n- `Hardware Acceleration`: It takes advantage of the GPU (Graphics Processing Unit) in modern graphics cards, allowing for fast and efficient rendering of complex graphics.\n- `Rendering Pipeline`: OpenGL follows a rendering pipeline model, where objects and scenes are transformed and rendered in stages, providing flexibility and control over the rendering process.\n- `Shader Support`: OpenGL supports programmable shaders written in languages like `GLSL` (OpenGL Shading Language), allowing developers to create custom effects and manipulate graphics at a more granular level.\n- `Community and Libraries`: There is a large community of developers using OpenGL, as well as various libraries and frameworks built on top of OpenGL (such as GLFW, GLM, and GLEW) that simplify common tasks and provide additional functionality.\n\n#### Use Cases\n\n- `Game Development`: OpenGL is widely used in the gaming industry for creating graphics-intensive games. Game engines like Unity and Unreal Engine use OpenGL (or its modern variant, Vulkan) as their rendering backend.\n- `Scientific Visualization`: It is used in applications that require visualizing complex data, such as simulations, medical imaging, and CAD (Computer-Aided Design) software.\n- `Virtual Reality (VR) and Augmented Reality (AR)`: OpenGL has been used in creating VR and AR applications, providing the necessary rendering capabilities for immersive experiences.\n- `Computer-Aided Design (CAD)`: Many CAD applications rely on OpenGL for rendering 3D models and scenes.\n- `Visual Effects (VFX) in Films`: OpenGL is also used in the film industry for creating visual effects and rendering scenes.\n\n#### Example\n\nHere's a simple example of an OpenGL program in C++ that creates a basic window and renders a colored triangle:\n\n```cpp\n#include \u003cGL/glew.h\u003e\n#include \u003cGLFW/glfw3.h\u003e\n#include \u003ciostream\u003e\n\nint main() {\n    // Initialize GLFW\n    if (!glfwInit()) {\n        std::cerr \u003c\u003c \"Failed to initialize GLFW\" \u003c\u003c std::endl;\n        return -1;\n    }\n\n    // Create a windowed mode window and its OpenGL context\n    GLFWwindow* window = glfwCreateWindow(640, 480, \"OpenGL Window\", NULL, NULL);\n    if (!window) {\n        std::cerr \u003c\u003c \"Failed to create GLFW window\" \u003c\u003c std::endl;\n        glfwTerminate();\n        return -1;\n    }\n\n    // Make the window's context current\n    glfwMakeContextCurrent(window);\n\n    // Initialize GLEW\n    if (glewInit() != GLEW_OK) {\n        std::cerr \u003c\u003c \"Failed to initialize GLEW\" \u003c\u003c std::endl;\n        glfwTerminate();\n        return -1;\n    }\n\n    // Define the vertices of a triangle\n    GLfloat vertices[] = {\n        -0.5f, -0.5f, 0.0f,\n         0.5f, -0.5f, 0.0f,\n         0.0f,  0.5f, 0.0f\n    };\n\n    // Create and bind a Vertex Array Object (VAO)\n    GLuint vao;\n    glGenVertexArrays(1, \u0026vao);\n    glBindVertexArray(vao);\n\n    // Create a Vertex Buffer Object (VBO) and copy the vertex data to it\n    GLuint vbo;\n    glGenBuffers(1, \u0026vbo);\n    glBindBuffer(GL_ARRAY_BUFFER, vbo);\n    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);\n\n    // Specify the layout of the vertex data\n    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);\n    glEnableVertexAttribArray(0);\n\n    // Main rendering loop\n    while (!glfwWindowShouldClose(window)) {\n        // Clear the color buffer\n        glClear(GL_COLOR_BUFFER_BIT);\n\n        // Draw the triangle\n        glDrawArrays(GL_TRIANGLES, 0, 3);\n\n        // Swap buffers and poll for events\n        glfwSwapBuffers(window);\n        glfwPollEvents();\n    }\n\n    // Clean up\n    glDeleteVertexArrays(1, \u0026vao);\n    glDeleteBuffers(1, \u0026vbo);\n    glfwTerminate();\n    return 0;\n}\n```\n\nThis program creates a simple OpenGL window using GLFW, initializes GLEW for OpenGL extensions, and renders a colored triangle using vertex buffer objects (VBOs) and vertex array objects (VAOs). This example demonstrates the basic setup and rendering process in OpenGL.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspear97%2F3d-world","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspear97%2F3d-world","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspear97%2F3d-world/lists"}