Perspective Projection - Part 1 // OpenGL Tutorial #11

Поділитися
Вставка
  • Опубліковано 15 чер 2024
  • In this video I'm going to explain and implement perspective projection in OpenGL. This transformation is core in making your 3D game actually look like it has a third dimension. It makes objects that are further away from the camera appear smaller while closer objects appear larger. This video is part one and deals mainly with the projection of the XY coordinates. In the next video we will handle the Z component and the aspect ratio.
    Back face culling is explained in • From Dot To Triangle ...
    Make sure to watch all the previous tutorials in the "OpenGL For Beginners" playlist at • OpenGL for Beginners
    Please visit ogldev.org to see more of my tutorials on modern OpenGL.
    ** Link to source: github.com/emeiri/ogldev/blob...
    If you want to get the same version that was used in the video checkout the tag TUT_11_PERS_PROJ_1.
    ** OpenGL 4.6 specification: www.khronos.org/registry/Open...
    Timecodes:
    0:00 Intro
    2:14 The View Frustum
    5:47 View onto the YZ plane
    6:14 Projecting on the near clip plane
    6:42 The field of view
    8:27 Calculating the projected point (Y component)
    10:37 Calculating the projected point (X component)
    11:33 How to implement?
    12:07 The projection Matrix
    13:09 Perspective Division
    14:43 Copying the Z into W
    15:38 Start of code review
    15:55 How I got the cube mesh
    17:10 Handling face culling
    18:32 Transformation matrices
    20:02 Run without projection
    20:20 Implement the perspective projection matrix
    21:45 Run with projection
    23:40 Conclusion
    Feel free to comment below.
    Email: ogldev1@gmail.com
    Facebook: / ogldev-188319114585587
    GIthub: github.com/emeiri/ogldev.git
    Twitter: @ogldev
    One time donations (Paypal): ogldev.org/donate.html
    Patreon: / ogldev
    My gear (Amazon affiliate links):
    Camera - Canon EOS M50: amzn.to/3duVIOh
    Camera mic - Rode Videomic: amzn.to/3dsGVDs
    Desktop mic - Rode NT-USB-Mini: amzn.to/3giMoif
    Credits:
    Music: "Cute" from bensound.com
    View Frustum image: upload.wikimedia.org/wikipedi... (MithrandirMage, CC BY-SA 3.0 creativecommons.org/licenses/..., via Wikimedia Commons)
    Enjoy,
    Etay Meiri
    #opengl #ogldev #opengtutorials

КОМЕНТАРІ • 107

  • @Robinho659
    @Robinho659 2 роки тому +13

    as a maths teacher from germany i have to admit i wish i could explain like u do. i dont remember understanding a new topic that quick. thank you, great work! :)

    • @OGLDEV
      @OGLDEV  2 роки тому

      Thanks a lot!

  • @kerbalcadet2783
    @kerbalcadet2783 2 роки тому +10

    Amazing that this has so few views - I couldn't find a good explanation of projection matrices until I stumbled on this. Great work!

    • @OGLDEV
      @OGLDEV  2 роки тому

      Thanks a lot for your feedback!

  • @Bunny99s
    @Bunny99s 3 місяці тому +2

    I know you want to keep it simple and on point. Though the "perspective divide" is generally called the homogeneous divide. We use homogeneous coordinates because "normal" cartesian coordinates and matrix multiplication can't represent translation or projection. The idea of homogeneous coordinates is that we simply go one dimension higher and offset our desired coordinate system by one unit in that new dimension. That's why points in space have "w" set to 1. So the whole 3d coordinate space simply lives at a 3d "sliver" of 4d space, at a distance of 1 from the origin. Matrix multiplications still can't do translations, however we can do a shear operation in 4d space. Since our 3d space that we are interested in is at distance 1, when applying a shear, our "flat" 3d space within the 4d space would appear to have shifted. So we actually want to keep our coordinate space at a "w" distance of 1 at all times. So if w contains a value different from 1, we "normalize" our coordinates by dividing the whole vector by w. Yes, this division is hardcoded into the rendering pipeline. This simple convention allows us all sorts of things to represent with just matrices and since you can combine matrices this is super efficient for more complex setups.
    If you have trouble understanding 4d coordinates, homogeneous coordinates also work for 2d coordinates in the same way. When you have 2d coordinates in a 2d plane, we simply offset them by 1 in the z direction. By applying a shear, we can move the 2d coordinate system around. This concept also applies to higher dimensions. So when you want to represent actual 4d space, we can use 5x5 matrices to do the translation and projection down into 3d space.

    • @OGLDEV
      @OGLDEV  3 місяці тому

      Thanks for the comment. I actually think that 'perspective division' is a bit more common and this is how it's called in the OpneGL spec, but both terms are fine.

  • @sripradpotukuchi9415
    @sripradpotukuchi9415 2 роки тому +3

    My mind is _blown!_ Your way of explanation is truly amazing. It was very intuitive and everything just clicked into place for me.
    Thank you so much for putting out this content. Instantly subscribed!

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      Glad it was helpful!

  • @weifang2218
    @weifang2218 2 роки тому +1

    Best OpenGl tutorials that I have seen. Thanks !!!

    • @OGLDEV
      @OGLDEV  2 роки тому

      Thank you!

  • @ReversedFootage
    @ReversedFootage Рік тому

    Wow this is the most thorough video about the subject I've seen so far, it's really good, you explain things very well. Thank you

    • @OGLDEV
      @OGLDEV  Рік тому

      You're very welcome!

  • @thormind7338
    @thormind7338 2 роки тому +1

    Wow, thank you for this video. Everything is explained so clearly!

    • @OGLDEV
      @OGLDEV  2 роки тому

      Your'e welcome :-)

  • @coltsmith6467
    @coltsmith6467 2 місяці тому

    I'm a bit late to the party, but this video finally made this stuff click for me - thank you! I've been reading textbooks and trying to understand for a couple weeks now, and your explanation made it finally made sense.
    Thank you for making these learning resources :)

    • @OGLDEV
      @OGLDEV  2 місяці тому

      Glad it was helpful!

  • @user-lt8iq9yj3s
    @user-lt8iq9yj3s 2 роки тому +1

    Best opengl tutorial I've ever seen!

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      Thank you!

  • @Forka137
    @Forka137 Рік тому +1

    I'm learning OpenGL using Joey de Vries book and this video was a great complement for me to really understand what was going on. I will probably watch the whole series, thank you!

    • @OGLDEV
      @OGLDEV  Рік тому

      Thanks and good luck!

  • @Glyn-Leine
    @Glyn-Leine 3 роки тому +1

    actually really interesting and helpful! am looking forward to the next video!

    • @OGLDEV
      @OGLDEV  3 роки тому +1

      Thank you! It will be ready in a few days.

  • @ryarsh1
    @ryarsh1 2 роки тому +1

    You are a _fantastic_ teacher, thank you so much for sharing your knowledge!
    all the best,

    • @OGLDEV
      @OGLDEV  2 роки тому

      Thank you Jack!

  • @jamesbeilby
    @jamesbeilby 2 роки тому +1

    Thanks! Great explanation from first principles

    • @OGLDEV
      @OGLDEV  2 роки тому

      You're welcome :-)

  • @alexmassy
    @alexmassy 9 місяців тому

    So cool. Love the breakdown. It clarify a lot for me. Thank you !

    • @OGLDEV
      @OGLDEV  9 місяців тому

      Glad it was helpful!

  • @Mochu_s_Junkyard
    @Mochu_s_Junkyard 7 місяців тому

    My man thank you very for the tutorial you are the real MVP and not those matrices
    I'm learning opengl on my own with no computer science background and this small series in cameras has been the real deal for me, keep it up, try to be a little more dynamic and I am sure that the channel will go very far :)

    • @OGLDEV
      @OGLDEV  7 місяців тому +1

      Thanks! I wish I was able to publish more frequently but it's very difficult with a full time job and a few kids. Maybe in the future I'll be able to work on this full time and publish every week. Kind of a chicken and an egg problem...

  • @BackUp-cz6zn
    @BackUp-cz6zn 2 роки тому +2

    great video saved me from depression i was llooking like every where for two days and a 20 minute video made it look easy
    it would be great if you did a video about the whole row-major vs column-major difference and how do i know what matrix to multiply first.
    like i have no idea what happens when i multiply the translation first but it just doesnt work unless i re order the projection matrix to look like a column-major one

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      Thanks! I'll add the row/column major topic to the TODO list. Regarding matrix multiplication order - please check out my video ua-cam.com/video/gdlu6EEWm2I/v-deo.html. I think it should address your question.

  • @antoinefortin1386
    @antoinefortin1386 2 роки тому +1

    Awesome series!

    • @OGLDEV
      @OGLDEV  2 роки тому

      Thanks Antoine!

  • @EgorChebotarev
    @EgorChebotarev 11 місяців тому

    good explanation with 2d and 3d definition

    • @OGLDEV
      @OGLDEV  11 місяців тому

      Thanks :-)

  • @foebelboo
    @foebelboo 7 місяців тому

    thanx ogldev!!

    • @OGLDEV
      @OGLDEV  7 місяців тому

      You're welcome!

  • @scriptercoding
    @scriptercoding Рік тому

    This tutorial is lovely amazing :D

  • @kratostheinevitable3932
    @kratostheinevitable3932 Рік тому +1

    amazing, explanation.

  • @user-ts4gw3yr5u
    @user-ts4gw3yr5u 9 місяців тому

    Very easy to understand ^o^

    • @OGLDEV
      @OGLDEV  9 місяців тому

      Glad it helped!

  • @Sgoose105
    @Sgoose105 Рік тому

    very very good lecture
    better than my prof

    • @OGLDEV
      @OGLDEV  Рік тому

      lol! Thanks :-)

  • @laurentbedief2199
    @laurentbedief2199 3 роки тому +1

    Super tuto !!!!!! j'ai hâte de voir le prochain . Merci à toi !!! J'oubliais , tu parles bien le français ?

    • @OGLDEV
      @OGLDEV  3 роки тому

      Merci! Je parle français uniquement avec google translate ;-)

    • @laurentbedief2199
      @laurentbedief2199 3 роки тому

      @@OGLDEV ok ;-) thanks

    • @laurentbedief2199
      @laurentbedief2199 3 роки тому

      @MO 9845 don't worry, i can speak to @oglDev in english, i really thought @oglDev speaks french ;-)

  • @Sneha_Negi
    @Sneha_Negi 2 роки тому +4

    your videos are a great help..
    just one query... i have applied your same code your code works fine...
    but then i applied your code for a mesh data given. without projection matrix it works fine like it should work..but then i apply the projection matrix the screen goes black..i applied different angles wide and small..for angle 180 i can see something appearing in my screen...but seems like instead of getting a solid mesh i see lines coming out towards screens..seems like from a far depth for all other angles i barely see something on screen..i also tried changing the depth using the translation matrix nothing worked...
    any suggestion would be great help...

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      What is the range of the vertices of the problematic range on all the axis? I don't think you should work with an angle of 180 because it seems the frustum will be weird in this case (not a pyramid). Stay with 45 degrees and check the z range of the vertices. Perhaps they are being clipped on the near and far z.

    • @Sneha_Negi
      @Sneha_Negi 2 роки тому

      @@OGLDEV thank you very much for the reply..
      my range of the given mesh data for x(-18,20) for y(-20,25) for z(-32,32) these are approximations.. what i did is i scaled my points to 0.01 so that they become inside -1,1 and then tried applying your projection matrix...
      also i watched many lecture they say camera is at origin then how are we able to see positive z values since camera facing towards neg z axis... so much confusion
      can you provide the links from where i can have better understanding of how to modify the protection matrix according to ones need...

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      You are not supposed to scale the positions by 0.01 and then apply projection because you may end up with degenerate triangles. Perspective projection should bring the visible vertices into the [-1,1] range. I take a somewhat different path from other sources and I teach perspective projection before the camera transform so when you are on tutorial 11/12 you need to ignore the camera which is explained in tutorials 13-15. The camera must indeed be at the origin when you apply pers proj but since we have no notion of a camera at this point you can assume that it is there by default. The other lecture probably assume that you are using a right handed coordinate system with the camera looking down along the -z. This is indeed confusing. I'm using a left handed coordinate system. From the top of my head I think you just need to replace 1 in location [4,3] with -1 to switch from left hand to right hand. A couple of resources that may help you here are www.songho.ca/opengl/gl_projectionmatrix.html and www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix

    • @Sneha_Negi
      @Sneha_Negi 2 роки тому

      @@OGLDEV ohh thank you very much sir... that clears my doubt...because the libraries that already are there like glm library i think they use right hand rule... and reading from different different resources had confused my understanding..thank you that cleared...my doubt

    • @OGLDEV
      @OGLDEV  2 роки тому

      You can choose the type of the coordinate system in glm using glm::frustumLH and glm::frustumRH

  • @user-or7uo5hh9j
    @user-or7uo5hh9j 3 місяці тому

    Hello Etay, thanks for the series.
    Could you please explain, why in projected point we set z_p to be equal to 1 instead of d?
    At time 9:52 you pointed out that z_p = d, but then from the final matrix 12:35 it is easy to see that z_p will be equal to 1 after division by z.

    • @OGLDEV
      @OGLDEV  3 місяці тому

      The projection matrix is composed of two completely independent transformations - projection of X&Y for the illusion of 3D and mapping of Z to -1 to 1 between the near and far Z. In this video we handle the first one and in the next one we handle the second. So right now the final matrix looks like that because we are still not mapping the Z properly.

  • @Sneha_Negi
    @Sneha_Negi 2 роки тому

    just one more question that is eating up my head..
    the near and far plane are always on negative z axis according to right hand convention...and so my screen will clip only what's inside the frustum..my question is ...that what happens to positive z coordinates... as they are not inside our frustum they will not be displayed right?
    so for taking care of that do we have to translate all our object coordinates in negative z direction so that now our object is in the near and far plane range.

    • @OGLDEV
      @OGLDEV  2 роки тому

      The camera is at the origin and it can only point at either the positive or negative half of the coordinate system. So in the right handed the negative Z is in front of you and the negative Z is behind you and must be clipped.

  • @saranh1687
    @saranh1687 2 роки тому +1

    this is very nice explanation. you describe everything in detail.is that possible that you go further, and provide tutorials also in gaming, like realtime graphics, game development? or maybe like what thinmatrix did, but he did it in java, not c++.

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      Thanks! The plan for the next few months is to focus on various 3D techniques. From there branching to game development is definitely something that I'm considering.

    • @saranh1687
      @saranh1687 2 роки тому

      @@OGLDEV thank you very much,.that would be amazing.cause any game development tutorial i found was with java and opengl.no one was with c++ and opengl.

    • @OGLDEV
      @OGLDEV  2 роки тому

      The Cherno has a good series on game engine development in C++ - ua-cam.com/play/PLlrATfBNZ98dC-V-N3m0Go4deliWHPFwT.html

    • @saranh1687
      @saranh1687 2 роки тому

      @@OGLDEV thank you very much for the adivce,i will follow it later,but i could not see any visual results in his tutorials,thats not im not following it yet.like in thimatrix,there will be a game,an environment,something visual,for him it was some cubes...but i will go for it.thanx

    • @OGLDEV
      @OGLDEV  2 роки тому

      @Sara nh I watched the first few episodes of his game engine series and they are mostly about setting up all the infra structure of the engine. I think that is expected because there is a lot of infra structure in such sw. I haven't followed the entire series but I noticed lately that he started doing effects like bloom, lighting, etc so I guess there is something to see. I hope I'll be able to find time to watch it...

  • @chad4094
    @chad4094 7 місяців тому

    I wasn't able to get it to work until I used the glm library and used glm::perspective. The matrix glm::perspective creates is very different from your Projection matrix. How did you get yours to work without specifying a far or near clip plane? Why is the Z value on the 4th row 1 instead of -1? Thanks again for your videos, despite my shortcuts I still wouldn't have been able to get as far as I have without them.

    • @OGLDEV
      @OGLDEV  7 місяців тому

      The near/far clip planes are handled in the second part of this video. Once completed, you should find my matrix and the one by GLM almost the same (at least that's what I remember from the last time I checked...). The difference in the sign of Z is due to the right handedness of GLM vs my left handedness.

  • @kryptoid2568
    @kryptoid2568 2 роки тому +4

    You look like Electroboom if he was more interested in 3D graphics
    GPUboom lol
    Other than that, I find this video very helpful, as perspective projection is the hardest thing for me to setup.

    • @OGLDEV
      @OGLDEV  2 роки тому +2

      And we have almost the same number of subscribers ;-)

  • @Anthrax02w
    @Anthrax02w Рік тому

    07:22 Then why it does need to set the angle when prospective if can be set auto depending on near plane value?

    • @OGLDEV
      @OGLDEV  Рік тому

      Please see my response below to @smashmyheadagainst from about 3 months ago. I'll be back from vacation in a few days and will be able to share more details then.

  • @anthonynolanjannotta4688
    @anthonynolanjannotta4688 2 роки тому

    @6:00 What if the camera is located at the same y value as the objects that are being projected? the lines from the top of each object would just be parallel and they wouldn't be scaled down in the perspective view, right? Or am I more confused than I thought lol.
    Thanks!

    • @OGLDEV
      @OGLDEV  2 роки тому

      The fact that the camera and the objects have the same Y value just means they are at the same "height". Whether or not the objects are visible depends on their relation to the frustum and for that we need to know the target vector.

    • @anthonynolanjannotta4688
      @anthonynolanjannotta4688 2 роки тому

      @@OGLDEV gotcha,
      So In my example let’s say the objects are people who are the same size, if I wanted a 3rd person view from the perspective of one of the people, I’d have to set the viewing plane to be above and behind the head of the person, right? If I wanted a 1st person perspective, the viewing plane would be in front of the person, and at the same height(y value) right? So in that case, the farther objects wouldn’t appear smaller, is that right?
      Thanks!! 🙏

    • @OGLDEV
      @OGLDEV  2 роки тому

      With perspective projection the further the object the smaller it looks, same as with regular human vision. Whether this is 1st person or 3rd person view is just a matter of whether the camera is "inside" the character or hovering a bit above.

  • @aleksandrstukalov
    @aleksandrstukalov Рік тому

    Hey, how exactly you've exported vertex coordinates and indices from blender?

  • @smashmyheadagainst
    @smashmyheadagainst Рік тому

    Hi Etay! Something is bugging me! You explained changing the field of view angle moves the near plane where the vertices are projected to. But in a typical function generating a projection matrix, one typically specify the field of view, the aspect ratio and the distance to the near and far planes. But if given the field of view angle, the near plane distance is also known, why do we have a different parameter to set the near plane distance, which could be different from the value derived from the distance d (f in the code) you showed ? My understanding was the image is not projected to the near plane but instead to a plane between the near and far plane which distance varies according to the field of view. Surely I missed something here. Thanks

    • @OGLDEV
      @OGLDEV  Рік тому +1

      Changing the view angle changes the projection plane and not the near plane. The projection plane must be located so that only the range [-1,1] on both X and Y are inside the frustum. When the field of view is 90 degrees the projection plane is at a distance of 1. Increasing the FOV pulls it backward and decreasing it pushes it further away. We want to keep the FOV and near/far planes independent from one another. The FOV affects only the X and Y. The near/far affects the projected Z that goes into the depth buffer. The projection of the X and Y doesn't care where the near Z is located. You can have a very narrow FOV with the projection plane at z=5 while the near Z is 1. All the points along the ray from the object to the camera are projected on the same location on the projection plane. So points before and after the projection plane go to the same location. The near/far planes are simply there to determine what is too close or too far and must be dropped.

    • @smashmyheadagainst
      @smashmyheadagainst Рік тому

      @@OGLDEV Thanks for taking the time for such a detailed answer, I appreciate. At 5:36 you say: "Basically, we are mapping or projecting the point onto the near clip plane". That's where I was confused. If I understand correctly, the near clip plane can be the projection plane in a very particular case (a 90 degres fov) but generally, it's not ? Well, that's what I understand from your answer. Also, I didn't know floating point numbers had a precision issue outside the [0, 1] range ! I though the issue occurred when mixing small and big number in computations hence why one should keep them in the smallest possible range, being small or big. Anyway, I'm learning a lot ! Keep up the good work, thanks!

    • @OGLDEV
      @OGLDEV  Рік тому

      Yeah I guess my sentence there was not so accurate. Floating points have all kinds of precision issue in every range. This is why we get Z-fighting.

  • @Sneha_Negi
    @Sneha_Negi 2 роки тому

    or can you just tell me...what should we take care of while changing the angle and the depth in translation matrix

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      Changing the angle causes a zoom in/out effect, so you may want to compensate that in the Z of the translation matrix so that the object will not be too close or too far away. I have a feeling the problem is with the Z. Since you can see the mesh without projection the X and Y are probably already in the -1 to 1 range.

    • @Sneha_Negi
      @Sneha_Negi 2 роки тому

      also one more qsn you haven't use depth buffer...and enable depth tests..
      when i tried doing it..your code showed black screen what could be the reason for that?

    • @OGLDEV
      @OGLDEV  2 роки тому +1

      I recently realized that I may have delayed the depth test too long so I've added it to the next tutorial which will be out in a few days. It shouldn't be a problem as long as you use simple models like the cube because back face culling will take care of the depth test. Which tutorial showed a black screen with the depth test?

    • @Sneha_Negi
      @Sneha_Negi 2 роки тому

      @@OGLDEV your code for this tutorial which i found on github..

    • @OGLDEV
      @OGLDEV  2 роки тому

      OK, so it probably has something to do with the fact that tutorial 11 is missing the Z transformation which is explained in tutorial 12. I guess when the depth test is enabled most of the vertices end up being clipped. Try to enable the depth test in tutorial 12.

  • @ChoudharyRamesh
    @ChoudharyRamesh 2 роки тому

    21:42 , when z will be divided by w it willl became 1 , so how this depth imformation is preserved ?

    • @OGLDEV
      @OGLDEV  2 роки тому

      This is explained in part 2 of the perspective projection tutorial (next one on the playlist). In this video I only talk about making X and Y dependent on the distance from the object and the aspect ratio and the normalization of the Z is handled in the next one.

    • @ChoudharyRamesh
      @ChoudharyRamesh 2 роки тому

      @@OGLDEVThanks for rply. I am doing same but my output is black screen only even after model translated to 3 ,as you did. What I am doing wrong ?

    • @OGLDEV
      @OGLDEV  2 роки тому

      Difficult to say, what do you have as the original Z value in the vertex? Does it work without the perspective matrix? Please try to compare your code to my code from the repo. If you can't find the problem you can send it to me and I'll try to find some time to take a look.

  • @omlachake2551
    @omlachake2551 7 місяців тому

    Hello Etay, I have been following the series sequentially and you have been clearing the whole concepts for me, Thanks!
    Until this video, I faced no issues at all, however, I can now see nothing on my screen, complete Black window, no errors, no issues at all. I changed many things in the Transformation matrices, but still got no results. I am using Visual Studio 2022 on Windows 10. Please would you help me out? I am crying my brains out why this doesn't work.
    Here is a more detailed Problem :
    When all three matrices are just identity matrices, I can see the the square / cube.
    I add Rotation, along the z axis, it starts rotating, but looks weird.
    I add Translation to Z, it starts moving left and right.
    I change Projection[0][0] and Projection[1][0] to 'f', it still acts like the identity Projection Matrix.
    But, when I set the Projection[3][3] to zero. It all goes blank.

    • @OGLDEV
      @OGLDEV  7 місяців тому

      Are rotation and translation working as expected without projection? Note that the order of transformations matters. I have a video about that. Regarding projection - try to compare your matrix to mine. What is the FOV that you are using? Note that Projection[1][0] should be zero while [1][1] should be f.

    • @omlachake2551
      @omlachake2551 7 місяців тому

      ​@@OGLDEV Rotation Works, the Translation, instead of moving the camera far away, the complete Cube moves sideways. But atleast I can see something on the screen. With Projection, its black. The order is also correct. Referred to your previous videos.
      I have now copied the exact code you have, except, I am using glm and not your library. All the matrices are exact as same as you.
      The FOV is 90 degrees, before converting it to radians. I do use glm::radians to convert.

    • @OGLDEV
      @OGLDEV  7 місяців тому

      I think it's critical to get the translation along Z working correctly because the projection works by dividing X and Y by Z. If the object moves sideways when Z is changed then it may break everything. Start with a basic sample that renders a single triangle (bottom left corner of the screen, top center and bottom right). The camera should be at the origin and facing the Z axis. Apply the projection and start moving the triangle along Z. The simple projection matrix in this video should make it smaller as it moves away. There is no near/far Z at this point which is explained in the next video. Note that without near/far Z mapping the valid range for Z is -1.0 to 1.0 so make sure not to go outside of this range. You can see that in my sample the Z is +0.5 or -0.5 for the vertices of the cube. If you change this to +1.5 and -1.5 you will also get a blank screen every now and then.

  • @thelifelearner5618
    @thelifelearner5618 Місяць тому

    can i get this code completely in pdf form

    • @OGLDEV
      @OGLDEV  Місяць тому

      Have you tried using one of the online tools to convert code to pdf?

  • @matthewmorrison2071
    @matthewmorrison2071 2 роки тому

    could you get away with just dividing by Z

    • @OGLDEV
      @OGLDEV  2 роки тому

      Division by Z is indeed the core of projection. The other parts of the matrix are for field of view, aspect ratio and Z transformation.

  • @NewThingsAk
    @NewThingsAk Рік тому

    how to install ogldev_math_3d.h

    • @OGLDEV
      @OGLDEV  Рік тому

      It's in the git repo github.com/emeiri/ogldev
      In the Include directory.