{"id":16557148,"url":"https://github.com/madeyoga/computer-graphics","last_synced_at":"2025-06-10T09:04:33.149Z","repository":{"id":103152895,"uuid":"147620626","full_name":"madeyoga/Computer-Graphics","owner":"madeyoga","description":"OpenGL (GLUT), Computer Graphics Algorithms","archived":false,"fork":false,"pushed_at":"2019-02-23T06:02:18.000Z","size":115150,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T23:12:30.599Z","etag":null,"topics":["glut","opengl"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madeyoga.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2018-09-06T05:07:26.000Z","updated_at":"2024-11-06T18:41:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"10a3a2f7-8c3d-4738-8a30-40b359b8a43d","html_url":"https://github.com/madeyoga/Computer-Graphics","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madeyoga%2FComputer-Graphics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madeyoga%2FComputer-Graphics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madeyoga%2FComputer-Graphics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madeyoga%2FComputer-Graphics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madeyoga","download_url":"https://codeload.github.com/madeyoga/Computer-Graphics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madeyoga%2FComputer-Graphics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259043760,"owners_count":22797159,"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":["glut","opengl"],"created_at":"2024-10-11T20:06:38.970Z","updated_at":"2025-06-10T09:04:33.134Z","avatar_url":"https://github.com/madeyoga.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Computer-Graphics\n![Build Status](http://img.shields.io/travis/badges/badgerbadgerbadger.svg?style=flat-square)\n\n26416083, Computer Graphics, Using OpenGL (GLUT)\n\n![itr](https://i.imgur.com/c2atLio.png)\n![avt](https://i.imgur.com/D3HNnhn.png)\n![ivy](https://i.imgur.com/aKuzEVH.png)\n![c_h](https://i.imgur.com/lCXzK2L.png)\n\n### Requirements\n- Visual Studio 2015 (v140 platform toolset)\n- Target Platform Version 8.1\n- #define _CRT_SECURE_NO_WARNINGS\n\n## Available Classes\n- **Vector**\n- **Matrix** deprecated\n- **Matrix2** (07 Oct, 2018)\n- **Transformation**\n- **Quadric**\n- **Hierarchy**\n- **RGBColor**\n- **Face**\n- **Mesh**\n- **Light**\n- **Material**\n- **Camera**\n\n## Getting Started\n- Download projects `.zip` file or by using git \u003cbr\u003e\n```\ngit clone https://github.com/MadeYoga/Computer-Graphics.git\n```\n\n- Copy all files inside `Classes` folder and paste it to your project folder\n\n- include these lines of code into your main.cpp file project\u003cbr\u003e\n  \n```cpp\n#include \u003cfstream\u003e\n#include \u003ciostream\u003e\nusing namespace std;\n\n// you should declare `glut.h` or glut header before including `Header.h`\n// it doesn't always looks like this to declare `glut.h`,\n// it depends on how you install `glut.h`.\n#include \"GL Libraries\\GL\\glut.h\"\n\n#include \"Header.h\"\n```\n\n### Example (Load Model)\n```cpp\n#include \u003cfstream\u003e\n\n#include \u003ciostream\u003e\nusing namespace std;\n\n#include \"GL Libraries\\GL\\glut.h\"\n#include \"Header.h\"\n\n#define WINDOW_SIZE 600\n\n// Define World and Camera(Eye)\nWorld world;\nCamera cam;\n\nvoid idle() {\n\tglutPostRedisplay();\n}\n\nvoid initWorld() {\n\tglOrtho(-WINDOW_SIZE, WINDOW_SIZE, -WINDOW_SIZE, WINDOW_SIZE, -WINDOW_SIZE, WINDOW_SIZE);\n\tglClearColor(0, 0, 0, 0);\n\n\t// Define Objects\n\tMesh teapot_mesh, cube_mesh;\n\t// load .obj file\n\tteapot_mesh.loadObject_poly(\"teko.txt\");\n\tcube_mesh.loadObject_square(\"kubus.txt\");\n\t// add Objects to world\n\tworld.add_mesh(teapot_mesh);\n\tworld.add_mesh(cube_mesh)\n}\n\nvoid test() {\n\tglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\n\tglRotatef(1, 1, 1, 1);\n\tglPointSize(2);\n  \n  \t/*~magics happens here~*/\n\tworld.draw(cam);\n  \t\n\tglDisable(GL_TEXTURE_2D);\n\tglutSwapBuffers();\n}\n\nvoid main(int argc, char **argv) {\n\n\t// INIT\n\tglutInit(\u0026argc, argv);\n\tglutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);\n\tglutInitWindowSize(WINDOW_SIZE, WINDOW_SIZE);\n\tglutCreateWindow(\"test 2!\");\n\n\tglutIdleFunc(idle);\n\tglutDisplayFunc(test);\n\tinitWorld();\n\n\tglutMainLoop();\n\n}\n```\n\n### Example Camera Movement\n```cpp\nCamera cam;\n\nvoid keyPressed(unsigned char key, int x, int y) {\n\tif (key == 'p') {\n\t\tcam.change_view_y(-20);\n\t}\n\telse if (key == 'a') {\n\t\tcam.change_view_x(20);\n\t}\n\telse if (key == 'l') {\n\t\tcam.change_view_y(20);\n\t}\n\telse if (key == 'd') {\n\t\tcam.change_view_x(-20);\n\t}\n\telse if (key == 'w') {\n\t\tcam.change_view_z(-20);\n\t}\n\telse if (key == 's') {\n\t\tcam.change_view_z(20);\n\t}\n\telse if (key == 'h') {\n\t\tcam.rotate(Vector(1, 0, 0, 1), 10);\n\t}\n\telse if (key == 'j') {\n\t\tcam.rotate(Vector(-1, 0, 0, 1), 10);\n\t}\n\telse if (key == 'q') {\n\t\tcam.rotate(Vector(0, 1, 0, 1), 10);\n\t}\n\telse if (key == 'e') {\n\t\tcam.rotate(Vector(0, -1, 0, 1), 10);\n\t}\n\telse if (key == 'k') {\n\t\tcam.rotate(Vector(0, 0, 1, 1), 10);\n\t}\n\telse if (key == 'i') {\n\t\tcam.rotate(Vector(0, 0, -1, 1), 10);\n\t}\n}\n\nvoid test() {\n\t// Display something.\n}\n\nvoid main(int argc, char **argv) {\n\t// INIT\n\tglutInit(\u0026argc, argv);\n\tglutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);\n\tglutInitWindowSize(WINDOW_SIZE, WINDOW_SIZE);\n\tglutCreateWindow(\"GRAFKOM GG!\");\n\tglutIdleFunc(idle);\n\tglutDisplayFunc(test);\n\tinitWorld();\n\tglutKeyboardFunc(keyPressed); // \n\tglutMainLoop();\n}\n```\n\n### Example Transformation on obj\n```cpp\n// Load obj file\nbed_mesh.loadObject_square(\"bed.obj\");\n// scale\nbed_mesh.matrix_transform = Transformation().scale(Vector(2, 2, 2, 1));\n// translate, this will force .matrix_transform value to change.\nbed_mesh.matrix_transform.translate(Vector(400, 137, -400, 1));\n// rotate x\nbed_mesh.matrix_transform = bed_mesh.matrix_transform.multiplies(Transformation().rotate_x(-1.575));\n// set color to white. default: green\nbed_mesh.set_color(RGBColor(1, 1, 1));\n```\n\n### More Examples \ni, provide a small set of Examples in the [Other Directory](https://github.com/MadeYoga/Grafika-Komputer)`. its messy, gonna clean it later`.\n## Docs\nThe basics of computer graphics is **MATH**, so, i'm not going to explain every single detail about these `math` thing\u003cbr\u003e\ni'm only going to explain how these classes works.\n### **Vector.h**\n```cpp\n// Declare Vector object named `v`\nVector v(x, y, z, 1);\nv.showVectorOnConsole();\n// to change the declared Vector object value, use `set_value` method\nv.set_value(new_x, new_y, new_z); // doesn't include `w`, w value is constant (integer 1).\n```\n### **Matrix2.h**\n\nmake sure you had `identity.txt`(with matrix identity value in it) inside your project directory\n```cpp\n// Declare Matrix2 object. by default, it will declare an identity matrix.\nMatrix2 matrix;\nmatrix.showMatrixOnConsole();\n// Other method to declare Matrix2 object. this will declare a 4x4 matrix with value 0 on each indexes.\n// theres a bug on it, can declare only with 4 max row and 4 max cols. gonna fix it later.\nMatrix2 matrix0(4, 4);\n```\n\nMatrix2 values is using a 2 dimensional array and its public, so, to get `Matrix2` values, use `Matrix2._matrix`\n```cpp \n// DECLARE matrix identity 4x4\nMatrix2 dummy_matrix;\n// get matrix's value at row 0 and col 0\ndummy_matrix._matrix[0][0];\ndummy_matrix._matrix[1][0];\n.\n.\ndummy_matrix._matrix[3][3];\n// returns a 2d array with 4x4 row and col\ndummy_matrix._matrix;\n```\n\nMatrix can be multiplied by/with a matrix. In order to multiply two matrices, A and B, the number of columns in A must equal the number of rows in B. Thus, if A is an m x n matrix and B is an r x s matrix, n = r.\n```cpp\n// this is how you multiplies a matrix.\nmatrix.multiplies(matrix0);\n// `multiplies` method returns a `multiplies result value` instead of changin the original `matrix` values\n// so, do it like this.\nmatrix = matrix.multiplies(matrix0);\n\n// Matrix can also multiplied by a `Vector` and the result would be a Vector, so, `multiplies` method gonna returns a Vector object instead of Matrix2\n// still, `multiplies` method doesn't change their matrix original value, it would only returns a multiplies result.\nVector v = matrix.multiplies(Vector(x, y, z, w));\n```\n\n### Transformation.h\n`Transformation` class provides you to get a transformation matrix value from a given `Vector`. Matrix Such as Translation, Scaling, Rotation. this class will return matrix as shown below.\n![matrix_transformation](http://opensource.petra.ac.id/~m26415172/matrix.jpg)\n### Example Transformation.h\n```cpp \nTransformation transformation();\n\nVector vector(50, 50, 50, 1);\ntransformation.scale(vector);\ntransformation.translate(vector);\nfloat theta = 60;\n// returns X-ROTATION 3D matrix\ntransformation.rotate_x(theta);\n// returns Y-ROTATION 3D matrix\ntransformation.rotate_y(theta);\n// returns Z-ROTATION 3D matrix\ntransformation.rotate_z(theta);\n```\n### Example transforming a Matrix\n```cpp\nVector vector(50, 50, 50, 1);\nTransformation transformation();\nMatrix2 matrix(); // Matrix that we want to transform\n\nMatrix2 transformation_matrix = transformation.translate(vector);\n\n// to transform a Matrix, we need to multiplies it with th transformation matrix\nmatrix = matrix.multiplies( transformation_matrix );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadeyoga%2Fcomputer-graphics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadeyoga%2Fcomputer-graphics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadeyoga%2Fcomputer-graphics/lists"}