Code-It-Yourself! 3D Graphics Engine Part #3 - Cameras & Clipping

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ค. 2024
  • Phew, it's a long one but I feel necessary to get this series moving. This video describes how to implement cameras and clipping planes in a 3D engine. In addition, I derive the look at and point at matrices, typically used in cameras, and talk about how to clip triangles against planes in world space, views space and screen space
    Source: github.com/OneLoneCoder/Javid...
    / discord
    Blog: www.onelonecoder.com
    Twitter: @javidx9
    Twitch: javidx9
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 402

  • @javidx9
    @javidx9  5 ปีที่แล้ว +195

    Hey, its long I know, but its difficult to demonstrate cameras without clipping, and its not very interesting to demonstrate clipping without cameras :D Anyway, as with all my videos - best enjoyed in your own time, and at your own pace.

    • @Jacbo1
      @Jacbo1 5 ปีที่แล้ว +1

      My camera keeps rotating up and down when I'm not touching anything and it changes when I go above or below the object. Any help? It's been doing it since I implemented moving and turning the camera (I only have yaw turning though)

    • @compositeembryo7186
      @compositeembryo7186 4 ปีที่แล้ว

      just wondering about olcConsoleGameEngine... is it available to the general public to look at or do we write our own?

    •  4 ปีที่แล้ว +2

      @@compositeembryo7186 it is on github and is open sourced. (oneLoneCoder).

    • @U20E0
      @U20E0 3 ปีที่แล้ว +1

      I found this channel after I decided to make a 3d software renderer, and got stuck at some weird skewing when rotating the camera. by coincidence I was using olcPGE.
      and my 'camera problems' were caused by incorrectly scaling the coordinates before drawing (rendering some offscreen stuff) :/ .

    • @javidx9extra
      @javidx9extra 3 ปีที่แล้ว +1

      Sounds like your matrix calculations are not quite right.

  • @smellthel
    @smellthel 3 ปีที่แล้ว +202

    “If your goal is to learn about wheels, then there’s nothing wrong with reinventing the wheel”
    I think Jack’s a genius

  • @jimjohn2652
    @jimjohn2652 5 ปีที่แล้ว +517

    That awkward feeling that a random youtuber can explain Analitical Geometry much more intuitively than your average college professors.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +111

      Thanks Jim, but to be fair there is a lot of stuff that I don't cover too - but I'll take it! :D

    • @hamyncheese
      @hamyncheese 5 ปีที่แล้ว +89

      also, he is not a "random" youtuber. He is a well educated, highly experienced, articulate professional in the related field. Your average college professor prefers velcro over shoelaces and can't cook a pancake.

    • @o0julek0o
      @o0julek0o 5 ปีที่แล้ว +12

      Quite frankly, most university lectures (UK here) are garbage who are winging it just like most of us. Pointless.

    • @jsonkody
      @jsonkody 4 ปีที่แล้ว +10

      Cause this 'random guy' has provably better idea what he is talking about than just some average professor simce hes spend last 30 years by programmimg this stuff? Maybe because that ....

    • @jsonkody
      @jsonkody 4 ปีที่แล้ว +1

      ... sry. I am writing on mobile 🤔🤨😶

  • @D0UGlE
    @D0UGlE 4 ปีที่แล้ว +93

    This is exactly the level of complexity and abstraction I have been looking for in beginning computer graphics, but I could never find in the places I've looked. This series has given me a lot more confidence in approaching the maths and API's of lower level graphics programming. Thanks javidx9!

  • @3echo0
    @3echo0 3 ปีที่แล้ว +49

    For those who enjoy following along with the video instead of loading up the final source code, and things display back to front when you first load up "axis.obj", there was a bit of code skipped at the end of the first section where x/y of triProjected are inverted ( *= -1.0f) before offsetting by {1, 1, 0}.

    • @miloz1950
      @miloz1950 3 ปีที่แล้ว +5

      Note: line 607 in file

    • @_Vesper
      @_Vesper 3 ปีที่แล้ว +9

      Thanks a bunch, that had me stumped for a little while so I decided to check the comments

    • @RaffaelloBertini
      @RaffaelloBertini 2 ปีที่แล้ว +2

      it is caused by an error in the projection matrix (the projection matrix is not quite right for the final reprensentaton). There is no need to "hack" with a *=-1.0f if the projection matrix is correct.

    • @nates9778
      @nates9778 2 ปีที่แล้ว +1

      I had this problem while making my own axis.obj in Blender. While testing the projection matrix with a bunch of debug meshes I created in the code, everything seemed to work fine, but when exporting from Blender the Z-Axis was flipped. It seems to be the case that in our 3d-application, we are using a left-handed coordinate system meaning if we use our left hand and we curl our fingers from the X-Axis to the Y-Axis, our thumb (Z-Axis) is facing away from us (the camera). And in Blender it's reversed, if we curl our right hand from X to Y, Z is facing towards us. And on top of that there's the whole thing were blender switches Y and Z and you have to export as "Y-Up" and that makes things even more confusing.

    • @wheany
      @wheany ปีที่แล้ว +8

      @@RaffaelloBertini And the error in the projection matrix is that the element on row 2, column 3 (0-based index, as in the code) should be a -1 instead of 1.
      After that you also need to fix the depth sorting function to return the triangles in the opposite order.

  • @outsider1st
    @outsider1st 5 ปีที่แล้ว +134

    Wow, wish I had them math skills..
    This is honestly the best TH-cam channel when it comes to designing games / engines from scratch.
    I like that you're not trying to overcomplicate things by adding complex language's features, I think that's good approach of teaching.
    Well done!

    • @javidx9
      @javidx9  5 ปีที่แล้ว +46

      Thanks Niko, I get a mixed response because my videos do not demonstrate "best practice" whatever that is, but I try to make the videos about the ideas rather than the language

    • @MatheusSilva-bi2yc
      @MatheusSilva-bi2yc 4 ปีที่แล้ว +3

      @@javidx9 I'm followng along but in linux and rust and I usually don't like videos and gamedev in general because they don't explain the ideas but you do, I'm an experienced backend programmer and the field of graphics is fascinating to me thanks. And so I believe that best practices are to be used by oneself when they get to do this "for real"

    • @CottidaeSEA
      @CottidaeSEA 4 ปีที่แล้ว +2

      @@MatheusSilva-bi2yc Best practice to me seems more like "whatever makes most sense to use" because in every scenario I've encountered, performance is second. You don't rewrite code that works unless you need to improve performance. Functionality always comes first.

    • @MatheusSilva-bi2yc
      @MatheusSilva-bi2yc 4 ปีที่แล้ว +1

      @@CottidaeSEA and readability it's very rare to see a moment where perf is more important than readability.

    • @CottidaeSEA
      @CottidaeSEA 4 ปีที่แล้ว +2

      @@MatheusSilva-bi2yc Yeah, naming in particular is something I get annoyed by. Some dude arbitrarily having single letter variables in the code, good shit. Especially fun when working with JavaScript or some other non-strict language, but even in a language like Rust it's just awful.
      Also, documenting absolutely everything isn't necessary, and sometimes a method/function name does enough to tell the reader what it does. However, sometimes you have situations where there's absolutely no documentation. That's not a fun time.

  • @dailyshadow
    @dailyshadow 4 ปีที่แล้ว +28

    I’m going to have to watch this one a few times to understand. I never got into vectors or matrices so this is all new to me.

    • @dailyshadow
      @dailyshadow 4 ปีที่แล้ว +10

      Also, it’s hard to wrap your head around how many calculations computers are doing at a time when playing a game.

    • @nixcc1628
      @nixcc1628 3 ปีที่แล้ว +6

      @@dailyshadow I know this is kinda late but I recommend 3blue1brown's series on linear-algebra he explains intuitively how matrices and vectors work

    • @jaimefranco3875
      @jaimefranco3875 2 ปีที่แล้ว +1

      @@nixcc1628 thx I nees to study my mathematics

    • @haikamu7178
      @haikamu7178 ปีที่แล้ว

      You can checkout khan academy for intuitive explanation of those math

  • @mogusugom
    @mogusugom 20 วันที่ผ่านมา

    i have stayed up at night just to watch this video since it gives so much juicy information that I haven’t heard from anywhere else and explained well too.

  • @atarixle
    @atarixle 3 ปีที่แล้ว +1

    Big thumb up, the result of this step-by-step-explained knowledge is jaw-dropping!

  • @arseniimasiuk7705
    @arseniimasiuk7705 4 ปีที่แล้ว +2

    this is the best explaining of 3d graphics what i ever seen. Thank you!

  • @jamesking2439
    @jamesking2439 ปีที่แล้ว +1

    It's pretty cool getting to see everything that the hardware and graphics api normally does for you.

  • @nailbomb420
    @nailbomb420 4 ปีที่แล้ว +10

    That intro giving me the frontier elite 2 vibes 😍

  • @thefrenchdev965
    @thefrenchdev965 2 ปีที่แล้ว +4

    Looking at this 3 years later and this is so instructive! I never had any class on the subject and I think the explanations are so clear. I won't make my own engine but I find it so interesting to see how it works.

  • @Qwantopides
    @Qwantopides 2 หลายเดือนก่อน +1

    You sir have made an outstanding job making these videos!

  • @mdimransarkar1103
    @mdimransarkar1103 2 ปีที่แล้ว

    This is absolutely stunning.....you can make everything with triangles!

  • @khrissxander
    @khrissxander 5 ปีที่แล้ว +2

    I'm just incredibly in awe of both your progression and work.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Hi Khriss, to avoid replying to all your posts - its great seeing you watching through the back catalogue! So Thank you very much for all your kind words!

  • @NeilRoy
    @NeilRoy 5 ปีที่แล้ว +5

    Very impressive! I done a sort of a hacked frustum culling on a project of my own. Not nearly as good of a job as you did. But once I culled out the objects that were not in view, the speed increase was tremendous, and I haven't even implemented backface culling which is really simple as you already showed. I figured if I could get some sort of occlusion culling the speed will ramp up quite a bit more.
    Like you, I am fascinated at just how much of this sort of stuff modern games do in order to make a scene look extremely complex, yet they are cutting out SO MUCH you cannot see, it's amazing. The faster you make it, the more detail you can add in for what you do see.
    In my own test code, I didn't do it as well as you, I have what is a cube world (I started this long before minecraft, so no influence there, though now I see I could have made a million on this, LOL) and I basically just check along a grid, discarding grid locations that are not in view. I actually use a 2D level editor to plop down buildings which are various height cubes in a city setting, or a road which is a flat section on the grid.
    I also found some really nice code I used in a lunar landscape 3D program I made which checks your location within a polygon you are directly over top of and then sets your height based on that for some terrain following. It was fairly simple math to determine the position within the polygon then check the height at that location using the normal of the plane etc. Kewl stuff anyhow.

  • @blahbeastie
    @blahbeastie 5 ปีที่แล้ว +15

    I really appreciate that you took the time at the top of this video to walk through the decision making process behind your refactor. I think people at every level of software development get frozen up and often completely shut down by these kinds of design dilemmas; I feel that you taking the time to talk about your own choices is a nice way to let people know that they are not alone in their indecision.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +4

      Hi Tyler, thanks for your support. It's easy for people to become overwhelmed by code, but they must never forget that its completely ok, and with time they will come to understand it.

  • @davidpike766
    @davidpike766 5 ปีที่แล้ว +10

    every time you say "intuitively", I add two weeks. love the videos, though- thanks Javid

  • @lonkwuzhere4433
    @lonkwuzhere4433 2 ปีที่แล้ว +13

    Thank you so much for this video series. a lot of the math that goes into 3d projection is really intimidating and hard to understand but your method of introducing a method as a black box then elaborating on that method further down the line really helps me understand the information being presented. Considering that I'm a high school student with below-average math grades and even I can understand and comprehend what's going on in these videos is just incredible. One other thing, I'm not just stealing the code you've graciously put up on Github, I'm writing it from scratch in python 3.7 with the PyGame library for plotting and some Vector3 calculations as well.
    The fact my code works at all is just a testament to how well-structured your videos are. Keep doing what you do man you're the best!

    • @javidx9
      @javidx9  2 ปีที่แล้ว +3

      Hey I appreciate the kind words Lonk! Keep practicing and it all clicks soon enough!

  • @3DSage
    @3DSage 5 ปีที่แล้ว +4

    Great video as always, and I like the intro with the music! Perfect. I can't wait to see what you do next.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Thanks 3D Sage - based off the old elite intros :D

  • @robertboran6234
    @robertboran6234 5 ปีที่แล้ว +4

    A lot of great Math. The beauty is when you mix it with code. Very nice as usual.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +2

      Thanks Robert - a bit of a maths overload this series - normal service to be resumed shortly :D

  • @unhandledexception.
    @unhandledexception. 5 ปีที่แล้ว +1

    Amazing work !
    Thank you for all the effort you put into those videos!

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Thanks Martin, my pleasure!

  • @ppotter10
    @ppotter10 4 ปีที่แล้ว +1

    Truly love the more in-depth explanation of your videos! Can understand that it might be a little hard to understand if you don't have a math/engineer background, but there are other videos for that :)

  • @celestialamber174
    @celestialamber174 5 ปีที่แล้ว +3

    Thanks for making this tutorial series! Following along using Unity is really helping me understand the underlying aspects of 3d rendering.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +2

      Hi CelestialAmber, saw you on the discord, good stuff!

  • @gregattraf
    @gregattraf ปีที่แล้ว +1

    Wow! Thank you for doing this. You have really helped me. I have been trying to implement this using javascript. So cool!

  • @art_out_of_despair
    @art_out_of_despair 2 หลายเดือนก่อน +1

    I have NO WORDS. This is some sort of Art. For my humanitarian mind - almost a Drama.
    I'd wish you were my Math teacher at school years-years ago, I would understand what a greatest goal I have to suffer for!
    Thank you for the pleasure of learning from you!

    • @javidx9
      @javidx9  หลายเดือนก่อน +1

      That's very kind of you, thanks!

  • @GodofWar1515
    @GodofWar1515 5 ปีที่แล้ว +3

    Wow this is really great!! I really learned a lot from this. I now understand how 3d cameras work. The math is also really great. Great job.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Cheers Lucas, its only a primer really, there are lots of additional techniques I've not covered, but I'm pleased you got something from it.

  • @whoshotdk
    @whoshotdk 4 ปีที่แล้ว +9

    To those following along;
    In the Triangle_ClipAgainstPlane->dist method, there's an unused normalized vec3d n. Don't attempt to fix the line below with that variable; else you'll be normalizing the value twice :P
    Excellent tutorial Javid. I heard a rumour there's more 3D to come; I'd love to see a Javidsplanation of parent-child transformations for an object/scene graph!

  • @htweiss256
    @htweiss256 2 ปีที่แล้ว +7

    This is a great little project!
    I got a great deal of enjoyment out of implementing your 3D Graphics Engine in/for a SFML Render Window.
    I slowly work my way through the videos and watched a few others.
    It allowed me learn a great amount and revisit mathematics I haven't used in years.
    My real surprise and delight was when I realized/understood your window or frame was the actual
    Window's "console window" and the implications.
    Dude, That's Novel! Good Show!

    • @javidx9
      @javidx9  2 ปีที่แล้ว

      Thank you! 😊

  • @tezza48
    @tezza48 5 ปีที่แล้ว +3

    You got me hooked on the elite intro! I'll be watching from the start :D

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Ahh a fellow elite fan, excellent! Hello Commander Will!

    • @tezza48
      @tezza48 5 ปีที่แล้ว

      o7 CMDR. I first saw it in 1st year on my degree in what's basically an "ancient games" module that ended up on early videogames, from then i was amazed and had to play it. OOlite confuse the hell out of me so i settled for ED, which is hardly a downgrade it seems!

  • @LuigiTrabacchin
    @LuigiTrabacchin 4 ปีที่แล้ว +3

    I had to work with a lot of 3D software and i certainly treated lot of those matrix transformations as black boxes too, i'm finally getting used to them and understand em!
    i'm looking forward in doing my own 3D engine (in another language i like more xD) so i can finally totally grasp it. Just to trash it and get back to open GL, maybe i'll keep it to brag with friends!
    BTW Thanks! amazing series !

  • @i_do_stuff
    @i_do_stuff 9 หลายเดือนก่อน

    Thanks for the tutorial! I finally got it running

  • @DavidBauer38
    @DavidBauer38 2 ปีที่แล้ว

    Best... Intro... Ever.... Hope you and the family are doing well, sir!

  • @pedrobaltazar2725
    @pedrobaltazar2725 5 ปีที่แล้ว +1

    Man, your video tutorials are awesome!!!

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Hey thanks Pedro!

  • @bscubed
    @bscubed 5 ปีที่แล้ว +2

    Nice 2001 reference, and an amazingly insightful video. Loving this series so far!

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      lol, thanks Brendan! Its interesting seeing generational differences interpreting the intro. Some say 2001, others say Elite :D

    • @billowen3285
      @billowen3285 3 ปีที่แล้ว

      @@javidx9 whoops I thought it was star wars haha

  • @dehrk9024
    @dehrk9024 3 ปีที่แล้ว +1

    The space odyssey intro was awesome! xD

  • @minecraftermad
    @minecraftermad 4 ปีที่แล้ว +2

    it was fun when i figured all this out by my self when making my first opengl game and didn't know of any of the libraries etc so i just made my own vector lib (i did end up using the projection matrices etc)

  • @illiasolohub3225
    @illiasolohub3225 2 ปีที่แล้ว +1

    the enetrance is just a masterpiece

  • @mangai3599
    @mangai3599 3 ปีที่แล้ว +5

    I am a math lover and finally, by God's grace, I discovered your channel. I am quite happy to see lots of math in your videos. Please make more and more videos math is required in programming. I started only to get into programming beacuse of Math and especially beacuse CS is the field in which we see really power and beauti of Pure Mathematics! Great Work. Thanks a lot sir, keep going!

  • @hippzhipos2385
    @hippzhipos2385 3 ปีที่แล้ว +3

    Really learnt a lot of awesome information from this. Thank you very much. Can you maybe do some videos on hardware rendering next ? GPUs maybe ?

  • @toose8388
    @toose8388 5 ปีที่แล้ว +3

    Woah this series keeps getting more and more impressive! The rotating cube was working fine for me but I can't get any display on my console when I load in vertices from an object file. I've even tried downloading your github repository directly and running it, and get the same issue (so it doesn't seem to be a typo on my end). I will look into my VS and console settings now

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Im answering these a bit late and out of order, is it possible this was resolved on the discord server?

  • @lucs0091
    @lucs0091 5 ปีที่แล้ว +104

    This is still the console application right?

    • @javidx9
      @javidx9  5 ปีที่แล้ว +43

      lol yes :D

    • @doom694
      @doom694 5 ปีที่แล้ว

      javidx9 Very nice

    • @joedempseysr.3376
      @joedempseysr.3376 5 ปีที่แล้ว +14

      Even when you know exactly how it works, it still looks like magic! 🤓

    • @CMYTUB
      @CMYTUB 4 ปีที่แล้ว

      @@joedempseysr.3376 TRUE!!!! And very fun!!!!

  • @chessprogramming591
    @chessprogramming591 ปีที่แล้ว +2

    If anyone was wondering why cube mesh no longer works with these new Part3 vs Part2 updates - make sure to initialise 'w' in the cube mesh definition. It took me a few hours to realize like why cube wasn't appearing on screen. But I'm following this tutorial in JavaScript, not sure how likely it would behave in C++, IMO it should either not compile or result in undefined behavior.
    P.S. Javid, thank you for amazing tutorial, I'm close to making my own mine craft like program to build binary logic circuits in 3D, thank you so much for your time and effort,
    code is very didactic so even a noob like me can understand it)

  • @owa_creator
    @owa_creator 4 หลายเดือนก่อน +1

    Dude, you're the best!!!!!

  • @TheBypasser
    @TheBypasser 5 ปีที่แล้ว +3

    Lovely but slow :P You could collapse your whole stack of transforms into a single model-to-projection matrix before rendering the frame (so that a vertex would immediately become transformed into the view frustum, by the way the off-center offsets, the output resolution and such can already be included into that matrix as well so you are only left to divide the vector components by the last one in order to get the 2D frame you need) which will save you the need to multiply every vertex later on with every transform matrix one by one. Also a good step is to add a vertex buffer which you can simply process before working on the triangles themselves, so that every vertex coordinate set would be multiplied just once no matter how many triangles reuse it. As this ends up in clipping, it is even more fun as all the extra vertices you get from clipping do require no matrix operations at all as they are already in the view frustum space. The normals would require a separate path in this however, as they don't like to be screen-space ;)

  • @kamran_aghlami
    @kamran_aghlami 5 ปีที่แล้ว +3

    55:20, thanks to this now I can't play games without hitting 100% brain usage trying to visualize every thing thats happening under the hood, I'm almost 2 months into learning computer graphics and I am just enforcing my belief in "making games is way more fun than actually playing them.", every day.
    You've done a great job of explaining every bits of math that's going on. As a 'NOT a math genius' I really appreciate your efforts trying to visualize concepts for us visual learners.
    I don't have much to say as I am still recovering from joy of watching this, please never stop making these videos.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +2

      Hi Kamran, Working out how games get made can take the shine off a game itself, but I agree with you its quite addictive! I try to present concepts and ideas to programmers, who may not be specialised in certain fields, hopefully to demonstrate that this stuff is not too hard once you know the basics :D

  • @brutalmustache9533
    @brutalmustache9533 5 ปีที่แล้ว +1

    Really cool. Thanks a lot man.

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Hey cheers buddy!

  • @3DSage
    @3DSage 5 ปีที่แล้ว +4

    A black and white checkerboard texture would be fun to see next!

    • @javidx9
      @javidx9  5 ปีที่แล้ว +4

      Oh I see, that nice easy one that will look really great, with no requirements for complex spatial filtering algorithms? I see what you are up to :D

  • @GeekTeach
    @GeekTeach ปีที่แล้ว

    Great tutorial! I have been working with my students on a software engineering project and I being the silly teacher I am chose to take control of the Graphics component of our little game. I know much of this in theory, but I was obstinate against moving into triangles. Rectangles should be fine - I've used rectangles with 3d graphics for years. Congrats, you taught an old dog a new trick! Triangles are your friends!
    Anyway, I did run into a bit of an issue - I don't know if it was converting your code from C++ into C#, but it didn't seem that the clipped triangles correctly maintained their order. I ended up throwing a simple if statement into the code that if you had one internal point and it was the second point of the triangle, reverse the orientation; and if you had two internal points and it was the second point that was trimmed off, reverse the orientation of those two triangles as well.
    Anyway, thanks for the tutorial, I'm vastly smarter than I was two days ago! 😁

  • @axitc
    @axitc ปีที่แล้ว

    You are such a genius !

  • @FFA704
    @FFA704 5 ปีที่แล้ว +1

    I'm surprised at how fast and potentially actually useful this is

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Hi Alex, yeah the performance may drop significantly if I get around to texturing though, we'll start to hit the limitations of the windows subsystem which renders the console I think.

  • @Rraccd
    @Rraccd 5 ปีที่แล้ว +1

    Hey, it wasn’t too long. Perfect, as I was traveling from Cincinnati to Dayton.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Hello! Hopefully you were not driving and watching :S

    • @Rraccd
      @Rraccd 5 ปีที่แล้ว

      javidx9 passenger;)

  • @---rp3kg
    @---rp3kg 4 ปีที่แล้ว +3

    Just like that, you created a 3D game engine... what the hell man O.O

  • @AinurEru
    @AinurEru 4 ปีที่แล้ว

    javidx9 correct me if I'm erong, but regarding computation of the "new up" vector (around 24:13 ) there's aactually a way to defive it without any computation at all - just by coordinate-substitution and negating some of them: Say we got the forwards vector, and normalized it, as you've described (call it "F"), then "assuming" a "described" up vector of the positive Y-axis, and a lef-handed coordinate system, the "new up vector" ( call it "U") would simlply have the coordinates:
    Uy = Fz
    Ux = -Fx
    Uz = -Fy
    You can see it if you initially draw a unit circly in 2D, with Z-axis pointing right, and Y-axis pointing up, then draw some unit-length F vector from the origin, then a perpendiculat to it at the other side of the Z-axis. You'll see that Fy maps to -Uz and Fz just maps to Uy. Then, imagin rotating that entire 2D plane around the Y axis towards you (outside the paper, clockwise if looking at this from Y downward), then assuming a left-hand coordinate system (X-axis pointint out of the papaer), you'll see that any such rotation taking F some amount outside the paper, takes U exacly that amount inside the paper, so Fx maps to -Ux.
    I thow that the's an assumption there about which direction is up, and what handendness is, but: Regarding handedness, you're entire codebase has to assume one way or the other anyways (as this here does for the cross product when computing the "right" vector), and regarding the "Y up" assumption, you could just have your function "switch" on which coordinate of the provided up-vector is set to 1, and just do a different substitutions accordingly (flipping signs in other directions, etc.).
    Am I making sense or am I missing seomthing?

  • @MaikKellerhals
    @MaikKellerhals 3 ปีที่แล้ว +2

    i tried several tutorials on 3d engines, this is the only one i really understand and can follow easily step by step. Thank you very much!
    I'm implementing it on a Teensy 3.6 controller board (ARM Cortex-M4) with a 64x64 LED matrix using the SmartMatrix library for drawing.
    It works perfectly and doesn't use too many resources (yet). Only ram is a problem (256KB). Ship loads fine from SD card, teapot ist far too big, ram overflows, but other simple meshes (up to about 300 tris) work absolutely fine! Might need to upgrade to a Teensy 4.1 ;)
    edited the import code to use sdFat library and handle quads (if 4 values, make another triangle with values 1, 3, 4).

    • @javidx9
      @javidx9  3 ปีที่แล้ว +1

      Hey thats awesome Maik, is 64x64 high enough definition to sensibly make out what the objects look like?

    • @MaikKellerhals
      @MaikKellerhals 3 ปีที่แล้ว +1

      @@javidx9 It's just enough, especially in wireframe with antialiased line drawing. The low resolution models help too ;) See Video here:
      th-cam.com/video/xEykhFppZlo/w-d-xo.html
      I've also implemented XBox controller support over Bluetooth to control rotation and move around in the scene.
      Thanks to you I'm now starting to implement my own 3d engine for Browsers in JavaScript/WebGL

  • @victorhugo-wo2ci
    @victorhugo-wo2ci 2 ปีที่แล้ว

    Intro is akin to frontiers elite II how much i love that game lol

  • @smellthel
    @smellthel 3 ปีที่แล้ว +1

    epic intro

  • @FrostGamingHype
    @FrostGamingHype 2 ปีที่แล้ว +2

    ever since i watched part 1 and made an 2D Console Graphics Engine I really really want to create something like this like whole genshin impact in the console and its pretty good since triangles are the most common 2D Shapes now if we are using lines insted of triangles the system load will be more high than the triangles because Every Shape will consist of 3 Lines therefore if there is an mountain with 3200 triangles so it would be 3200x3 = no.of lines insted of rendering lines you should render triangles or if you want something more like genshin impact or even gta 5 in the console you can make Anti Aliasing to make the things look more smoother by giving the end parts of the char lighter shade frist draw extra pixels like 2 more char pixels then give the 1 the acctul shade and the 2 the lighter shade of that color

  • @shoaibzafar5663
    @shoaibzafar5663 ปีที่แล้ว +1

    Hey man you rae genious 🙂

  • @ilikeplanes4616
    @ilikeplanes4616 2 ปีที่แล้ว

    Okay that intro HAD to be a reference to 2001 a Space Odysssey

  • @mistervoldemort7540
    @mistervoldemort7540 5 ปีที่แล้ว +3

    I've been waiting for this video, thank you, another great video! Just a queery: shouldn't the Z axis be poiting in the other sens, in order to follow the right hand rule?

    • @javidx9
      @javidx9  5 ปีที่แล้ว +4

      Hi Voldemort, no love for left hand rule then? bah, all these righties out there...

    • @mistervoldemort7540
      @mistervoldemort7540 5 ปีที่แล้ว +1

      I didn't know the left hand rule existed lol sorry... haha

  • @MrGmuss
    @MrGmuss ปีที่แล้ว

    thanks you sir!

  • @KoeWaffle
    @KoeWaffle 5 ปีที่แล้ว +1

    Nice 2001: A Space Odyssey reference there ;)

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Hi KeoWaffle, I tried to get the Strauss piece, but it was not royalty free :( Instead I went with Blue Danube, mostly because of the original Elite games.

  • @ishdx9374
    @ishdx9374 3 ปีที่แล้ว

    aaa ELITE!!! NICE

  • @knssoftware6018
    @knssoftware6018 5 ปีที่แล้ว +3

    Why did I not heed your intro warning... my brain has a memory leak! Thanks though; it was an amazing way to kill off my last grey matter!

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      lol, I agree this video was a bit more intense than all my others, hopefully a one off though.

  • @christianarroyo3265
    @christianarroyo3265 5 ปีที่แล้ว +10

    I like watching your videos (even though half the time I don't know what you're talking about lol) but I have a few questions.
    1. How did you get into coding? Was it always a passion you had? Did you go to college for it? And if so, what majors/minors did you take up to help with your journey to programming? Do you only program in C++? And what have you programmed? (I guess a basic synopsis of your programming career journey)
    2. What actions would you recommend new/aspiring coders who want to program (whether its C++ or Java or whatever) to take?
    I myself was exposed to coding in my second year of college in my fourth semester (currently about to head into my third year of college/fifth semester) when I had to take a required course on C++. Even though I enjoyed the class, I felt it was too easy not necessarily because I was good at it (that can be debatable) but because my professor only taught the most basic things in C++. This left me wanting more, as I want to learn more C++ and any other programming/coding including Java, JavaScript, Python, PhP, etc. So recently I found a website that was devoted to teaching C++ and it's lessons were opened to everyone. I want to argue that I learned more from the website from my actual class (but I digress). Even though I have learned a considerable amount of C++ from this website (and will learn more) do you have any tips for learning programming easier? Any other websites for any other programming/scripting languages? Is there some topics in mathematics I should always know in case I decide to program (since I see that a lot of the more advanced mathematics are essential to a lot of your coding)? Also, as a beginner, what should I aspire to program (I only know that I want to program, but I don't know what to program)?
    3. Even though you make videos on how you code using more advanced techniques in C++, have you ever thought on making videos teaching the different aspects of C++ from the most basic stuff to the more advance stuff for new/aspiring programmers?
    Either way, I still watching your videos. Even if I'm not sure of all the stuff you do, watching your videos aspires me to learn more and more C++ so that one day I might be able to understand all aspects of your videos and, hopefully, be as skillful as you. Keep up the great work! :)

    • @javidx9
      @javidx9  5 ปีที่แล้ว +16

      Hi Christian,
      1) I started coding when I was 9 on a BBC Micro Model B+, I seemed to have natural understanding of it so I chose not to study it formally, but took qualifications in my early teens for Pascal and C++. In college I studied maths and physics, and at uni I studied Systems Engineering (electronics and embedded computing). After uni, I switched to neuroscience for a PhD. I program in C/C++, Pascal, Basics, x86, Thumb2, Java, VHDL/Verilog and Lua. I have dabbled and done things in numerous other languages too. I don't think the language itself actually matters, its more the awareness of how you are harnessing the computer to solve a problem - this takes time and practice to learn, whereas the specific syntax of a language can be picked up in days.
      2) Please see this video th-cam.com/video/vVRCJ52g5m4/w-d-xo.html which I feel answers most of your question. Also, getting quick sensible answers to questions when you have them is important, so (shameless plug alert) join our discord server! I think people assume maths is a requirement for programming, but it isnt. 90% of the time you need simple arithmetic. Applications such as 3D engines do require that you have an awareness of basic vector geometry, but rarely do you need advanced mathmatics, unless of course that is the focus of what you are trying to achieve. For games in particular, a basic grasp of kinematics and laws of motion is very useful too. You should aim to program things you enjoy, but are mostly within your ability. I feel learning programming doesnt come from taking on ambitious projects, but from debugging normal projects - you'll learn far more from making mistakes than drowning in complexity.
      3) I have. I don't consider any video on this channel to be advanced C++, and in most cases I actively simplify the code to make it accessible and educational for people like yourself, lol, this angers the people who do like advanced C++ code :D I can't win... anyway, I am considering doing some "Back To Basics" videos in the future.
      Thanks, I will!

    • @christianarroyo3265
      @christianarroyo3265 5 ปีที่แล้ว +1

      Thank you so much for your response, it really means a lot to me. I will definitely be sure to take your advice and watch the video you provided for me! :)

    • @joedempseysr.3376
      @joedempseysr.3376 5 ปีที่แล้ว +1

      @@javidx9 In my Comp. Sci. classes I got 3 kinds of students: 1) The "slow", who will never understand the material, so I can't teach them. 2) The very bright who probably understand the material better than I do so I don't have to teach them. And 3) Everyone else who lie within the first standard deviation, IQ wise,. Now my challenge is to try to reach as many of them as I can. My point is that if you teach to the middle most of the time you can't go too far wrong. I think you strike just the right balance.

  • @Summersault666
    @Summersault666 4 ปีที่แล้ว +13

    2001 space oddissey in the begining?

  • @gbrls_yt
    @gbrls_yt 5 ปีที่แล้ว +1

    Amazing

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Thanks Gabriel!

  • @hideozeki1791
    @hideozeki1791 5 ปีที่แล้ว +1

    Good job

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Thanks Hide!

  • @MrKriegus
    @MrKriegus 4 ปีที่แล้ว +2

    6:04 I don`t think we need to create that Identity matrix, since we completly change the matWorld matrix on the next line, therefore we don`t need to make the MakeIdentity function at all unless for the purpose of the next video and I have not watched that one yet
    34:25 Isn`t the xNX + xNy also a dot product between the function and the normal making the equation from 45:10 just simply:
    Vector_DotProduct(plane_n, p) - Vector_DotProduct(plane_n, plane_p)?

  • @jsflood
    @jsflood 5 ปีที่แล้ว +1

    Great video! :-)

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Thanks John, a bit too long I think.

    • @jsflood
      @jsflood 5 ปีที่แล้ว

      Not at all. Just perfect! :-D

  • @ILGiullareDiCorte
    @ILGiullareDiCorte 5 ปีที่แล้ว +1

    Yeahhhh thanks! I couldn't wait more :D how many parts will you still do?

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Hello! I'm unsure yet, I might experiment with texturing and depth buffers, but I may take a little break and work on something else - undecided at this point in time :D

  • @hatacoyama1246
    @hatacoyama1246 4 ปีที่แล้ว +1

    very high iq needed to understand this. i dont understand this
    especially the original rotation matrices and what the heck happened with the point at stuff in this video, help appreciated

  • @lucs0091
    @lucs0091 5 ปีที่แล้ว +1

    AWESOME INTRO. Does this video cover everything on algebra? Please don´t stop.

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      lol, not quite everything...

  • @PCarew
    @PCarew 5 ปีที่แล้ว +1

    I've gone in a slightly different direction and have added two cameras/ eye positions and am exploring stereoscopic view with red/cyan anaglyphs.

  • @AmazingAmbro1
    @AmazingAmbro1 2 ปีที่แล้ว

    i'm a beginner programmer and i'm not that good at advanced math skills, but hey this really helped me

  • @kallebanan1924
    @kallebanan1924 5 ปีที่แล้ว +3

    Amazing video! One question, how do you run your programs with that fps counter and everything? When I do i get nothing like that, im using the default console.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Hi Kalle, I use a utility I created and use for most of my videos called olcConsoleGameEngine, which sets the title bar of the command prompt window amongst other things.

  • @FFA704
    @FFA704 5 ปีที่แล้ว +1

    Will you do texture mapping ?

  • @abx4t
    @abx4t 2 ปีที่แล้ว

    Javid, were the normals under the edge ring of the lid of the teapot all reversed for you? It looks black but I can't quite tell, and it is for me. Trying to figure out of that was to be expected.

  • @CedLePingouin
    @CedLePingouin 5 ปีที่แล้ว +2

    Hi,
    I really like your videos. Especially those on 3D programming. I've always wanted to better understand the rendering pipeline, but I did not learn the math that goes with it. Your videos make these topics a bit more accessible.
    I have a question : at 6:09, isn't line 337 made useless by the following line ? I mean, as an identity matrix, the variable "matWorld" is never used, is it ? It gets immediately replaced by matRotZ * matRotX.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +2

      Hi Cedric and thanks! It is useless functionally, but visually it reassures me that the matrix is an identity matrix, which if i change the code later i can see the flow of calculation.

  • @pyyros122
    @pyyros122 2 ปีที่แล้ว +1

    Loved your video. Could you give some tips on your line drawing function? When I try my machine gets extremely slow (about 10 fps), and In my model I’m drawing far fewer triangles than you are.

    • @javidx9
      @javidx9  2 ปีที่แล้ว

      Thanks, two things I guess. Firstly make sure you are running a release mode build. Secondly, the lines are not clipped, so if you are drawing a line millions of pixels in length (it could be really close to camera for example) then it will draw it all even though you cant see it.

  • @NightingBlade342
    @NightingBlade342 2 ปีที่แล้ว

    Great video, can u tell how to do rotation in x and z dimension?

  • @JohnDoe-vg8px
    @JohnDoe-vg8px 5 ปีที่แล้ว +1

    damn that's cool

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      lol d3vvil, I agree! :D

  • @user-oc9ss7ty7i
    @user-oc9ss7ty7i 5 ปีที่แล้ว +5

    Camera Controls 2.0 with "Sprinting"
    if (GetKey(VK_UP).bHeld) {
    vCamera.y += (GetKey(VK_SHIFT).bHeld)? 16.0f*fElapsedTime:8.0f*fElapsedTime;
    }
    //Similarly for down, left and right
    if (GetKey(L'W').bHeld) {
    vec3d _2F = Vector_Mul(vForward, 2.0f);
    vCamera = (GetKey(VK_SHIFT).bHeld) ? Vector_Add(vCamera, _2F) : Vector_Add(vCamera, vForward);
    }
    //Similar for S
    if (GetKey(L'A').bHeld) {
    fYaw -= (GetKey(VK_SHIFT).bHeld) ? 4.0f *fElapsedTime : 2.0f * fElapsedTime;
    }
    //Similar for D (Or "acceleration" for turning can be left out entirely)

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Hey thanks! That's a great contribution, hopefully it should float somewhere near the top so others can see it.

  • @francescopiazza4882
    @francescopiazza4882 4 ปีที่แล้ว

    A lot of things, but good things!

  • @willsimpson3370
    @willsimpson3370 5 ปีที่แล้ว +5

    question about your "auto dist = [&](vec3d &p)" function: i don't actively develop with c++ so not familiar with its lambda expressions, so what purpose does the proceeding line "vec3d n = Vector_Normalise(p);" serve? visual studio seemingly doesn't give feedback to lines of code that are unused since you don't use n.
    i'm creating a version of this engine in java and i don't have any issues when i didn't include the line of code.

    • @javidx9
      @javidx9  5 ปีที่แล้ว +1

      Hi Will, yeah you found an unused line there - I dont like to change the source once the video is made, you get what I make, bugs and all :D. You are correct, VS doesnt care less about lines of code that are unused, and I like that. In this situation if I recall correctly, I was experimenting with different ways of interpreting the distance. It just got left in. Sometimes though, I'll leave bits of code there that I think I'll come back to later on, perhaps this was one of those cases. Lambdas in C++ are not really anything special. For all intents and purposes you can just treat it like a function. The only advantages they offer are to do with scoping.

  • @MistralKriss
    @MistralKriss 4 ปีที่แล้ว +1

    Sir, I could not describe how usefull this serie is, and how gratefull I am, for your work.
    Still I think there is a mistake (when I saw it, I thought "What ? Is that true ? is this allowed ?" and first I trusted it was ok. But there was a part of my instinct that said, nope something sounds wrong..
    So I began to think a bit more deeply and : there's a mathematical mistake, a small one... at 32:20 you state Y = dy/dx*X + C, then you write Ydx = dyX + c, which is wrong.
    If you multiply the both sides of the initial equation by dx, you get : dxY = dx * (dy/dx X + c) which is (dx/dx)*dyX + Cdx (distributivity) , not (dyX + C) (You forgot to mutiply C by dx)

  • @Allan_
    @Allan_ ปีที่แล้ว

    These videos are really nice and I understand the concepts for the most part, but I don't quite understand why they are used and how. Whenever you explain something it takes me at least 3 rewatches to understand the math. But even then, I still don't understand the purpose nor what it does. Is there any article, video or anything that goes in to the depth of all of these equations and matrix calculations so I can get a better understanding of 3D graphics. I've been able to follow along with your videos in Lua and it works for the most part. I can't get the clipping to work, whenever an object goes to the left, right or bottom of the screen then the triangles don't clip correctly and starting getting huge. If I understood clipping 100% then I could make my own system and wouldn't need to worry about major clipping bugs.

  • @thefoolishgmodcube2644
    @thefoolishgmodcube2644 5 ปีที่แล้ว +2

    0:00 Star Fox HD looks neat

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      lol XD

  • @teddycooper190
    @teddycooper190 3 ปีที่แล้ว

    What do you think would be the best way to add collision detection (if there is anyway to).

  • @shadyalnajjar1082
    @shadyalnajjar1082 4 ปีที่แล้ว +4

    Your great
    But for more helpful
    Tell us about the math(subjects names )is used and resources(book name) for this

  • @MacShrike
    @MacShrike 5 ปีที่แล้ว +1

    Phew.. I'm still with you but I need a drink.. no wait; I drank to much… holidays and all. Ill continue tomorrow.
    Thank you again..againagain

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Hi Machiel, I'm just responding to this one of the trail of comments you left. Thanks buddy! (and its ok to drink during the holidays XD)

  • @luizaugusto9421
    @luizaugusto9421 ปีที่แล้ว +1

    22:25 47:00 Thanks, man! Very nice you chanel! U got a new inscriton

  • @neuemage
    @neuemage 5 ปีที่แล้ว +1

    Intro reminds me of space homer xD

  • @maksymvarivodin5985
    @maksymvarivodin5985 4 หลายเดือนก่อน

    I don't know what is the problem, but it seems to me, that u have ur x-axis(in console engine) inverted, because when created exact same principle code, everything worked the same, BUT horizontally mirrored. I'm currently using quite nice, well-documented 2D graphics library - SFML.

  • @saltyyolk9934
    @saltyyolk9934 5 ปีที่แล้ว +1

    Impressive flat shading.

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      Yeah it looks ok given the limited palette dunnit?

  • @arnaudgranier3045
    @arnaudgranier3045 4 ปีที่แล้ว

    Is that me or is your axis.obj model left handed ?
    Really cool series by the way !!!

    • @TheQuiQuestion
      @TheQuiQuestion 3 ปีที่แล้ว

      It's definitely left handed.

  • @theluca907
    @theluca907 3 ปีที่แล้ว +1

    Hey, it's been more than two years that this video is out but i have a question, at 47:13, what's inside the two outside_points array (the value, e.g. outisde_point[0])? Because i'm struggling to find it. And i wanted to thank you for your all your videos !! I'm trying to replicate this using lua and the framework Love2D, and your videos are so clear that i can ! Sorry for my english and keep going !

    • @javidx9
      @javidx9  3 ปีที่แล้ว

      This array gets populated with points that lie "outside" the clipping plane. Knowing how many lie outside as opposed to inside informs you whether you need to construct 1 or 2 additional triangles.

  • @Chruschtschowka
    @Chruschtschowka 5 ปีที่แล้ว +4

    "I just use planes because I did the math so" I sense frustum culling

    • @javidx9
      @javidx9  5 ปีที่แล้ว

      lol, have to wait and see :D