1 | Default bounds
|
---|
2 |
|
---|
3 | 1 -1
|
---|
4 | | /
|
---|
5 | | /
|
---|
6 | | /
|
---|
7 | |/
|
---|
8 | -1 --------------- 1
|
---|
9 | /|
|
---|
10 | / |
|
---|
11 | / |
|
---|
12 | / |
|
---|
13 | 1 -1
|
---|
14 |
|
---|
15 | Matrices
|
---|
16 |
|
---|
17 | model: transforms each object separately
|
---|
18 | view: transforms the whole world
|
---|
19 |
|
---|
20 | for instance, a positive x translation moves either one object or all objects on the screen to the right a certain distance.
|
---|
21 |
|
---|
22 | If you want to transform the camera position or rotation, it should be the inverse of the transformations the view matrix is applying.
|
---|
23 |
|
---|
24 | projection: Here's where the fun stuff begins
|
---|
25 | Viewing Frustum diagram is on page 99
|
---|
26 |
|
---|
27 | I need to first implement the click detection function without applying the projection matrix
|
---|
28 |
|
---|
29 | The click detection function uses ray tracing to figure out which object we hit
|
---|
30 |
|
---|
31 | First, we need to generate the equation for the ray that starts at the camera position and through the point the user clicked. To do that, we need to turn the 2d point of the click into a 3d point on the near clipping plane.
|
---|
32 |
|
---|
33 | Ray Equation:
|
---|
34 | R(t) = O+Dt
|
---|
35 |
|
---|
36 | where R(t) defines all the points on the ray, O is the camera origin,
|
---|
37 | and D is the direction of the ray.
|
---|
38 |
|
---|
39 | In this case, D = P-O, where P is the point the user clicked on in 3D space
|
---|
40 |
|
---|
41 | Camera position = (0, 0, 0)
|
---|
42 |
|
---|
43 |
|
---|
44 | BUFFER FUNCTIONS
|
---|
45 | -----------------
|
---|
46 |
|
---|
47 | glGenBuffers creates a buffer
|
---|
48 | glBindBuffer sets the currently active buffer
|
---|
49 | glBufferData populates the buffer with data
|
---|
50 |
|
---|
51 | glGenVertexArrays creates a vao
|
---|
52 | glBindVertexArray sets the currently active vao
|
---|
53 | glEnableVertexAttribArray sets the active index in the vao
|
---|
54 | glVertexAttribPointer determines the layout of a buffer in a VAO
|
---|
55 | -The last params (often NULL), specifies the offset in the buffer
|
---|