Difference between revisions of "3D Fundamentals Tutorial 2"

From Chilipedia
Jump to: navigation, search
(Video)
 
(10 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
The tutorial video is on YouTube [https://youtu.be/HV1ZGyiY5C8 here].
 
The tutorial video is on YouTube [https://youtu.be/HV1ZGyiY5C8 here].
 +
 +
<div class="mw-collapsible mw-collapsed"><br />
 +
* Fix an error in <code>Mat2.h</code> (multiplication of vectors with matrices) [https://youtu.be/HV1ZGyiY5C8?t=0m16s 0:16]
 +
* Introducing 3D space [https://youtu.be/HV1ZGyiY5C8?t=1m57s 1:57]
 +
* Implementing the <code>Vec3</code> class [https://youtu.be/HV1ZGyiY5C8?t=3m19s 3:19]
 +
<div class="mw-collapsible-content">
 +
:* Inherits from <code>Vec2</code> (z-component added)
 +
:* Overload all operators for 3D
 +
:* Advantage of inheritence here: enables passing <code>Vec3</code>s into functions that accept <code>Vecc2&</code> references
 +
</div>
 +
* Calculating the length of a 3D vector (i.e., in R3) [https://youtu.be/HV1ZGyiY5C8?t=4m57s 4:57]
 +
* The <code>Mat3</code> 3D Matrix class [https://youtu.be/HV1ZGyiY5C8?t=5m57s 5:57]
 +
* Choosing a coordinate system [https://youtu.be/HV1ZGyiY5C8?t=7m37s 7:37]
 +
<div class="mw-collapsible-content">
 +
:* We choose a Left Handed coordinate system
 +
:* And start with defining World Space (=object space for now) and Screen Space
 +
</div>
 +
* Setting up a World Space (Chili likes to call it Pube Space) [https://youtu.be/HV1ZGyiY5C8?t=10m08s 10:08]
 +
<div class="mw-collapsible-content">
 +
:* We set the Origin (0,0,0) of world space in the middle of the screen
 +
::- This makes for better (easier) scaling
 +
:* We will use NDC (Normalized Device Coordinates)
 +
::- Meaning: we don't use pixel values, but normalized values relative to screen size
 +
::- (e.g. x=1.0 means far right end of screen, x=-1.0 for far left end of screen
 +
::- Main advantage: become independent from screen size
 +
::- Note: Direct 3D and OpenGL use NDC
 +
:* We will use the Pre-Clip 3D space definition: z=1.0 indicates half cube depth
 +
</div>
 +
* Transforming vertices from Pube Space to Screen Space [https://youtu.be/HV1ZGyiY5C8?t=14m01s 14:01]
 +
<div class="mw-collapsible-content">
 +
:* Introducing the <code>PubeScreenTransformer</code> class
 +
</div>
 +
* Testing: drawing a cube [https://youtu.be/HV1ZGyiY5C8?t=17m07s 17:07]
 +
<div class="mw-collapsible-content">
 +
:* <code>Cube</code> class created as a data structure to hold the vertices
 +
</div>
 +
* Representing lines: vertex container + vector of indices [https://youtu.be/HV1ZGyiY5C8?t=18m34s 18:34]
 +
<div class="mw-collapsible-content">
 +
:* This strategy avoids having to transform vertices multiple times
 +
:* Same concept as IndexBuffer used in Direct3D to draw primitives [https://youtu.be/HV1ZGyiY5C8?t=20m40s 20:40]
 +
:* Make the <code>Cube</code> class return a <code>IndexedLineList</code> struct
 +
</div>
 +
* Code for drawing: transform the vertices and iterate through the index buffer [https://youtu.be/HV1ZGyiY5C8?t=21m50s 21:50]
 +
* Limitations observed: not square and not 3D. Why? [https://youtu.be/HV1ZGyiY5C8?t=23m22s 23:22]
 +
<div class="mw-collapsible-content">
 +
:* Screen size is not square, we'll use a quick fix for now
 +
:* We still lack 3D visual cues because we don't account for the z-component yet (we're still in Orthographic Projection)
 +
</div>
 +
</div>
  
 
== Downloads ==
 
== Downloads ==
Line 13: Line 62:
 
* [https://www.patreon.com/planetchili Planet Chili Patreon]
 
* [https://www.patreon.com/planetchili Planet Chili Patreon]
 
* [[3D Fundamentals Tutorial 3|Next in series (Tutorial 3)]]
 
* [[3D Fundamentals Tutorial 3|Next in series (Tutorial 3)]]
* [[Beginner C++ Game Programming Series]]
+
* [[3D Fundamentals Series]]

Latest revision as of 06:12, 24 April 2020

In this video we lay the groundwork needed to represent and transform positions and 3D space, we define the relationship between our 3D space and the screen coordinates, and we setup a data structure to hold our test cube geometry.

Video

The tutorial video is on YouTube here.


  • Fix an error in Mat2.h (multiplication of vectors with matrices) 0:16
  • Introducing 3D space 1:57
  • Implementing the Vec3 class 3:19
  • Inherits from Vec2 (z-component added)
  • Overload all operators for 3D
  • Advantage of inheritence here: enables passing Vec3s into functions that accept Vecc2& references
  • Calculating the length of a 3D vector (i.e., in R3) 4:57
  • The Mat3 3D Matrix class 5:57
  • Choosing a coordinate system 7:37
  • We choose a Left Handed coordinate system
  • And start with defining World Space (=object space for now) and Screen Space
  • Setting up a World Space (Chili likes to call it Pube Space) 10:08
  • We set the Origin (0,0,0) of world space in the middle of the screen
- This makes for better (easier) scaling
  • We will use NDC (Normalized Device Coordinates)
- Meaning: we don't use pixel values, but normalized values relative to screen size
- (e.g. x=1.0 means far right end of screen, x=-1.0 for far left end of screen
- Main advantage: become independent from screen size
- Note: Direct 3D and OpenGL use NDC
  • We will use the Pre-Clip 3D space definition: z=1.0 indicates half cube depth
  • Transforming vertices from Pube Space to Screen Space 14:01
  • Introducing the PubeScreenTransformer class
  • Testing: drawing a cube 17:07
  • Cube class created as a data structure to hold the vertices
  • Representing lines: vertex container + vector of indices 18:34
  • This strategy avoids having to transform vertices multiple times
  • Same concept as IndexBuffer used in Direct3D to draw primitives 20:40
  • Make the Cube class return a IndexedLineList struct
  • Code for drawing: transform the vertices and iterate through the index buffer 21:50
  • Limitations observed: not square and not 3D. Why? 23:22
  • Screen size is not square, we'll use a quick fix for now
  • We still lack 3D visual cues because we don't account for the z-component yet (we're still in Orthographic Projection)

Downloads

The GitHub repository for the tutorial code is here.


See also