Code-It-Yourself! 3D Graphics Engine Part #1 - Triangles & Projection
Why Stack Overflow recommends it
Stack Overflow users link it as the tutorial they followed when asking why their own port of the 3D engine (to SDL2, C, C# or Java) draws a broken or incomplete cube.
Recommended by 0 people across 0 different months, 2019 to 2023.
What it is
javidx9 starts a series on building a 3D graphics engine from scratch in C++. This first part covers setting up the project, vertices and triangles, and how a projection matrix turns 3D coordinates into 2D screen coordinates, ending with a rotating, translated cube.
What people said
Cites Ascor · 2019-03 · Stack Overflow · on “Rendering a cube made of triangles gives weird angles on rotation”
@meowgoesthedog I've noted your comment for further tinkering (thanks!), however, this gentleman [this video] uses the exact same function and his seems to work just fine.
Cites brobot · 2020-10 · Stack Overflow · on “"Invalid Initializer Member Declarator"”
I found a video [this video] about making a simple 3D graphics engine (in c++) and I have been trying to port it to c# (I'm not very experienced in either language). I have been running into an issue while defining the triangles of a cube. Here is the troublesome code: private mesh meshCube = new mesh(); meshCube.tris = new List<triangle>{ new triangle {p = new vec3d[] { new vec3d { x = 0.0f, y = 0.0f, z = 0.0f }, new vec3d { x = 0.0f, y = 1.0f, z = 0.0f }, new vec3d { x = 1.0f, y = 1.0f, z = 0.0f }, }, //From this point onward the error message "Invalid initializer member declarator" is displayed. new triangle {p = new vec3d[] { new vec3d { x = 0.0f, y = 0.0f, z = 0.0f }, new vec3d { x = 1.0f, y
Cites YellowAfterlife · 2021-02 · Stack Overflow · on “I can't translate points in my 3D graphics engine (java)”
I highly suspect your issue to be that in C++, doing ( timestamp [this video] ) triTranslated = tri; will in fact make a copy of the triangle, whereas your code merely gets a reference, therefore your triangles drift away at pace of 3 units per render, likely vanishing out of view before you could see anything.
Cites Enos Soares · 2022-03 · Stack Overflow · on “SDL window updates slowly if I don't move my mouse”
I recently tried to implement OneLoneCoder's simple 3d Graphics Engine [this video] , from his Code-It-Yourself series, on SDL2. So I made some triangles that move on the window, but these triangles would appear to move at a slower framerate when I left my mouse completely still, and then move at their normal framerate if I started to move my mouse. You see, to animate these triangles I used some while loops, something like this: while (true) { // Black Background SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_RenderClear(renderer); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // Custom function that draws a triangle using SDL_RenderDrawLine() drawTriangle(renderer, triangle); SDL_R
Cites Slykapar · 2023-06 · Stack Overflow · on “How can I implement 3d graphics rendering in C with the SDL2?”
I tried implementing a C program which draws a 3d cube using SDL2. Im sorry if it is just a stupid small mistake I'm very new to C/C++. I followed this tutorial: [this video] . The guy from the tutorial coded everything in C++ but I tried coding it in C. But there's a problem with my code. Only parts of the Cube are drawn and it looks really weird. Here is all my code: main.c: #include "window.h" int main() { window_init(); window_startloop(); return 0; } window.c: #include "window.h" #define false 0 #define true 1 void MultMatrixVec(vec3 *i, vec3 *o, mat4x4 *m) { o->x = i->x * m->m[0][0] + i->y * m->m[1][0] + i->z * m->m[2][0] + m->m[3][0]; o->y = i->x * m->m[0][1] + i->y * m->m[1][1] + i->z * m
Cites user21956960 · 2023-06 · Stack Overflow · on “When trying to render a cube, all the triangles get rendered into a line”
I have been doing javidx9's 3D Graphics series [this video] except with SDL2 instead of the olcConsleGameEngine and I have gotten to the part before rotation. and all the triangles when rendered just turn into a line in the middle-ish of the screen Code 3D.h: #pragma once #include <vector> #include <cmath> #include "stdio.h" #include "SDL.h" struct Vector3 { float x, y, z; }; struct Triangle { Vector3 points[3]; }; struct Mesh { std::vector<Triangle> Triangles; }; struct Matrix4x4 { float m[4][4] = {0}; }; class Camera { public: Mesh cube; Matrix4x4 projectionMatrix; void init(int width, int height, float FOV, float nearPlane, float farPlane) { cube.Triangles = { { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0