Camera/View Space // OpenGL Beginners Series

  Рет қаралды 18,220

OGLDEV

OGLDEV

Күн бұрын

In this video I describe the Camera/View space and provide a full overview of all the coordinate system transitions that are involved in 3D rendering. For the camera I use a well known model called the UVN camera and I describe the steps for creating the camera/view transformation matrix based on that model.
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_13_CAMERA_SPACE.
OpenGL 4.6 specification: www.khronos.org/registry/Open...
Timecodes
0:00 Intro
0:30 Background
1:18 Local Coordinate System
1:42 World Coordinate System
3:15 Camera / View Coordinate System
4:43 Camera / View Transformation
5:40 Coordinate Systems Summary
6:48 The WVP matrix
7:38 Building the view transformation
8:45 The UVN camera model
11:45 Coordinate system change of basis
15:02 Chage of basis in matrix form
17:03 Code review
20:42 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 - "Summer" 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

Пікірлер: 57
@OGLDEV
@OGLDEV 2 жыл бұрын
While working on tutorial 15 (camera rotations using Quaternions) I found out I have a serious bug in that last slide where I show the final view transformation matrix. I tried to use a shortcut by combining the translation and rotation matrices together but it cannot be done like that. You have to multiply them. I have just pushed a fix for that (ogldev/Common/math_3d.cpp) and I will address it again when the next video is out. Sorry.
@OGLDEV
@OGLDEV 2 жыл бұрын
@MO 9845 :-)
@SourceCodeAR
@SourceCodeAR 2 жыл бұрын
I have never seen a teacher who teaches Graphics with such an ease. You really have a great sense of explaining. Your strong focus on explaining the concepts is really the best part of you and it makes you unique, a great and valuable teacher.
@OGLDEV
@OGLDEV 2 жыл бұрын
Wow! Thank you!!!
@taca3692
@taca3692 2 жыл бұрын
I truly believe that one day your series will become the go-to lectures on graphics programming.
@OGLDEV
@OGLDEV 2 жыл бұрын
Thank you! I hope you are correct ;-)
@user-bd7tc5kd9h
@user-bd7tc5kd9h 5 ай бұрын
Your video has had a positive impact on my learning, and I wanted to express my gratitude
@OGLDEV
@OGLDEV 5 ай бұрын
You're welcome :-)
@devinleamy3950
@devinleamy3950 2 жыл бұрын
Preaching to the choir here but your content is really fantastic. Thanks for the awesome series! Finding your channel made my day.
@OGLDEV
@OGLDEV 2 жыл бұрын
Glad you enjoy it!
@capsbr2100
@capsbr2100 Жыл бұрын
Hello, big fan of your teaching since years ago, as I have mentioned before, thanks to you I have managed to learn OpenGL by learning things from detail by looking at your theory and code. Perhaps just a simple linear algebra that might help explain why the position of the camera is set to its negative and the camera rotation is its transpose: The camera transform matrix in world coordinate system, would be the matrix T*R*S, where T is the actual position of the camera R orientation and S scale. that is, considering only rotation and position for now M = (T*R). In order to transform world to camera coordinate system, one simply negates the matrix M, such that M^-1. That means (T*R)^-1, which is equal to (R^-1 * T^-1) which is equal to (R.transpose * T^-1), where T will have its non-diagonal values negative such that M = (R.transpose* -T). I wish to start someday with Vulkan... Maybe after you have a complete course on it :))
@OGLDEV
@OGLDEV Жыл бұрын
Hi, I'm on vacation. Will get back to you next week.
@OGLDEV
@OGLDEV Жыл бұрын
Not sure I fully understood the question so I'll try this - the reason why the position of the camera is in the negative for the camera translation is that in order for the projection to work we need the camera to be in the origin and looking along the Z axis. So if the camera is at (1,0,0) we need to move it one unit left on the X axis which means the camera translation will be (-1,0,0). So everything moves left one unit and in reference to the camera their orientation is the same but the camera is now at the origin. You don't need to negate the matrices. The camera translation is according to the above and for the rotation you set the matrix using the UVN camera vectors. I just published a (hopefully entertaining) video exactly on this topic from my vacation in Rome. You are welcome to check it out :-). Regarding Vulkan - it is on my wish list just haven't found the time for it yet...
@capsbr2100
@capsbr2100 Жыл бұрын
@OGLDEV Makes sense as well, in fact I still have your explanation in my head since I read this tutorial in... 2019 or something. Really, thanks for taking the time to answer, to explain again, and even make a video about it, I will definitely look into it. :))
@chopchop708
@chopchop708 2 жыл бұрын
I've been struggling to figure out how view matrices work, but this video helped me understand it wonderfully, thank you for this amazing resource!
@OGLDEV
@OGLDEV 2 жыл бұрын
Glad to hear that :-)
@abdulrahmanalsarori5722
@abdulrahmanalsarori5722 2 жыл бұрын
I love how you visualize things. Makes it easier to understand what is going on with the camera behind the scenes.
@OGLDEV
@OGLDEV 2 жыл бұрын
Thank you!
@brianrosenlof388
@brianrosenlof388 2 жыл бұрын
This is an excellent description, thank you!!
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks :-)
@erin34uio5y32
@erin34uio5y32 Жыл бұрын
thank you so much for making this series, you are so great at explaining and for someone who is learning about 3d rendering at the same time as building a renderer your explanations help so much, and you are the only person i have found who has helped me understand it so well :D
@OGLDEV
@OGLDEV Жыл бұрын
Thank you :-)
@marlinjai
@marlinjai Жыл бұрын
Thank you so much for sharring all this knowledge and providing those resources. This helps so much with the learning process. Its super well explained as well.
@OGLDEV
@OGLDEV Жыл бұрын
Glad it was helpful!
@laurentbedief2199
@laurentbedief2199 2 жыл бұрын
thank you very much and long live your KZbin channel !!
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks!
@Sneha_Negi
@Sneha_Negi 2 жыл бұрын
this videoo...was great..cleared all my doubts....thank you so much for your efforts 😊
@OGLDEV
@OGLDEV 2 жыл бұрын
Most welcome 😊
@alangutierrez9558
@alangutierrez9558 8 ай бұрын
great explanation!
@OGLDEV
@OGLDEV 8 ай бұрын
Thanks!
@taherlogbi6285
@taherlogbi6285 2 жыл бұрын
Perfect explanation, Thank you so much.
@OGLDEV
@OGLDEV 2 жыл бұрын
Glad you enjoyed it!
@yuhaohan1451
@yuhaohan1451 Жыл бұрын
very helpful, thank you!
@OGLDEV
@OGLDEV Жыл бұрын
You're welcome :-)
@paulaenchina
@paulaenchina 2 жыл бұрын
Super helpfull! Having a hard time with Computer Graphics but your channel is helping me so much :)
@OGLDEV
@OGLDEV 2 жыл бұрын
Great to hear :-)
@krzysztof588
@krzysztof588 2 жыл бұрын
you are an absolute unit
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks!
@question_mark
@question_mark Жыл бұрын
thank you soooooooo much =)
@OGLDEV
@OGLDEV Жыл бұрын
You're welcome :-)
@nourrahim8516
@nourrahim8516 2 жыл бұрын
you are awsome
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks!
@suhailmohamed3013
@suhailmohamed3013 Жыл бұрын
@16:11 in the video you say that the matrix inverse is equal to its transpose because the vectors are linearly independent, I think you mean't to say orthogonal. Good video though
@OGLDEV
@OGLDEV Жыл бұрын
Good catch. The inverse of a matrix is equal to its transpose if the vectors are linearly independent and their length is 1. In other words, they are orthonormal. In other words, the matrix that they construct is orthogonal.
@coderedart
@coderedart 2 жыл бұрын
some of the math was hard to understand, but i think if i watch it again, i will eventually get it. it feels like i'm looking at what happens when i use a glm::lookAt() behind the scenes.
@OGLDEV
@OGLDEV 2 жыл бұрын
Thanks for the feedback. If you have specific areas that are difficult or not clear I may do a follow-up session about them. In general, my niche was always to go over all the math step by step. I think that even if you decide to use glm in your real application it still benefits you in the long run if you make sure you understand everything that happens.
@solomonchild5
@solomonchild5 2 жыл бұрын
kzbin.info/www/bejne/p2bNgH-wqcipqa8 I'm not sure the jump from how the axis were defined to the fact that they should be normalized is really intuitive. Is it because of the fact that rotation matrix should be orthononormal?
@OGLDEV
@OGLDEV 2 жыл бұрын
We want to generate a transformation matrix from world to camera. The other way around is very simple based on the UVN vectors. So we want to invert that matrix. In general matrix inversion is done using the determinant so a bit more complex, but if you know that the vectors are orthonormal you can simply transpose and you are done. I guess that for 3D it would be best practice to always make sure that your axis system is always orthonormal. The default system is orthonormal: (1,0,0), (0,1,0) and (0,0,1).
@sherminatorex
@sherminatorex 2 жыл бұрын
i don’t understand, some people say the camera has no coordinates in the world space, some say that they its coordinate is at the origin and now from what i understand you say that the camera isn’t always at the origin. i am lost
@OGLDEV
@OGLDEV 2 жыл бұрын
Sorry for the confusion. The camera most definitely has a position in the world. Same as any other object the camera can be translated and rotated. The only difference is that you don't render the camera itself. You want to render all the other objects from the position of the camera. This means that you need to project these objects on a "virtual" window in front of the camera. This projection can be quite complex if you use the position of the camera in world space as-is. It will be much simpler to do that when the camera is at the origin and looking down the Z axis (positive or negative - your choice). This means that we need to transfer the position of all objects from one frame of reference - the world - to another frame of reference - the camera. So the objects don't move, you just need to recalculate their position based on another frame of reference. For example, an object can be located in world space at 4,5,6 and at 7,8,9 in the camera frame of reference (view/camera space). The basic idea is that you can define one frame of reference based on its orientation in another frame of reference and vice versa. Therefore, the coordinates of the camera in world space can be anywhere the viewer can go but in view space the camera will always be at 0,0,0. These are simply two frames of reference that you can switch between. Hope this helps. Let me know if something is missing. I may do a video about it.
@sherminatorex
@sherminatorex 2 жыл бұрын
@@OGLDEV okay, thank you very much for this complete answer. but how do you place the camera in the world space ? is it just the same way as for any vertex ? because when we switch from world space to camera space, how do we determine where will be the new coordinates of the surrounding objects ? For instance, if the camera in the world space is placed at (30, 5, 70) and there is an object at (40, 5, 75). How do we determine the fact that in camera space we will be at the exact same location as in the world space ? We compute a substration ? Because as you said, camera in camera space is at origin so how do we do to be anywhere else at the same time. Sorry ahah i know it is badly formulated. Also how do you determine which sense of the z axis is the camera looking ?
@sherminatorex
@sherminatorex 2 жыл бұрын
@@OGLDEV yeah a video would be definitely great
@OGLDEV
@OGLDEV 2 жыл бұрын
Placing the camera in world space is represented in the 3D pipeline as a matrix that transforms from world space to view space. Think about it this way - the vertices of the objects begin their life in local space where the origin is in the center of the object (not a strict requirement but this is very natural in the modeller). To place them in the world you need to apply a local-to-world transformation. So you create a local-to-world matrix and you multiply each vertex in the vertex shader by it (later to be combined with all the other matrices). But the camera begins its life in the world space from the start. The camera is just a point that you need to place somewhere. You don't need to transform it from local to world. It has no meaning in the context of a camera. Simply decide where you want your camera to be and what is its target vector. But our goal, eventually, is to project the vertices on a virtual window in front of a camera (a window which goes from -1,-1 to 1,1) and then transform this normalized window into the actual window (e.g. 1920x1080). As I said in the previous comment, creating this projection for an arbitrary location of a camera is a bit complex. This is where camera space comes in. Based on the camera location and target vector you create a camera transformation matrix that will transfer the vertices from world space to camera space. This is simply telling the vertex - ok dude, in reference to the world you are at X1Y1Z1, but in reference to the camera (which is in the same world) you are at X2Y2Z2. The camera matrix does this transformation so after we multiply the local position by the world matrix we multiply it by the camera matrix. The next step of course is to multiply by the projection matrix and all three matrices are combined into one. So the world matrix will place the vertices in the world and the camera matrix will fix their position so that it will be as if the camera is now the origin. The subtraction that you mentioned is simply part of the camera space matrix. The translation part of this matrix will be (-30, -5, -70) in order to "move" the camera to the origin. Apply this on every vertex to get its position in reference to the camera (now that it is in the origin). Regarding the sign of Z - this is determined by either the 1 or -1 which is placed on the [4,3] location in the projection matrix. The depth buffer goes from 0 to 1. If you have 1 in the projection matrix you are in a left handed coordinate system so objects with positive Z values will get a Z between 0 to 1 and the camera will be able to see them (negative Z values will stay negative and behind the camera). If you have -1 in the projection matrix you are in a right handed coordinate system so object with negative Z values will be flipped to 0 to 1 (because you multiply the Z by the -1) and the camera will be able to see them (and positive Z values will flip to the negative and be outside the range of the depth buffer).
@OGLDEV
@OGLDEV 2 жыл бұрын
Sure, I'll complete the next tutorial and make a video dedicated to these questions.
Moving The Camera // OpenGL Beginners Series
22:40
OGLDEV
Рет қаралды 11 М.
The Camera Transform
47:18
UC Davis Academics
Рет қаралды 127 М.
Зу-зу Күлпәш. Стоп. (1-бөлім)
52:33
ASTANATV Movie
Рет қаралды 866 М.
КИРПИЧ ОБ ГОЛОВУ #shorts
00:24
Паша Осадчий
Рет қаралды 6 МЛН
Uma Ki Super Power To Dekho 😂
00:15
Uma Bai
Рет қаралды 41 МЛН
All OpenGL Effects!
30:21
Low Level Game Dev
Рет қаралды 53 М.
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 888 М.
Math for Game Developers - The Camera View Transform Matrix
12:20
Jorge Rodriguez
Рет қаралды 44 М.
How Shaders Work (in OpenGL) | How to Code Minecraft Ep. 3
30:48
GamesWithGabe
Рет қаралды 106 М.
LookAt - Interactive 3D Graphics
2:46
Udacity
Рет қаралды 24 М.
Textures in OpenGL | How to Code Minecraft Ep. 4
25:38
GamesWithGabe
Рет қаралды 94 М.
The Key to Realistic Environments in Blender
10:41
Kaizen
Рет қаралды 249 М.
Зу-зу Күлпәш. Стоп. (1-бөлім)
52:33
ASTANATV Movie
Рет қаралды 866 М.