lecture 13 robb t. koether - hampden-sydney...

24
Moving the Camera Lecture 13 Robb T. Koether Hampden-Sydney College Mon, Sep 18, 2017 Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 1 / 17

Upload: others

Post on 09-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Moving the CameraLecture 13

Robb T. Koether

Hampden-Sydney College

Mon, Sep 18, 2017

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 1 / 17

Page 2: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Outline

1 The Viewing Transformation

2 Calculating the Eye Coordinates

3 Moving the Camera

4 Assignment

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 2 / 17

Page 3: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Outline

1 The Viewing Transformation

2 Calculating the Eye Coordinates

3 Moving the Camera

4 Assignment

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 3 / 17

Page 4: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Viewing Transformation

The Viewing Transformation

camerax

y

z

The default camera

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 4 / 17

Page 5: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Viewing Transformation

The Viewing Transformation

camera

look

d

x

y

z

Translate the camera

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 4 / 17

Page 6: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Viewing Transformation

The Viewing Transformation

camera

look x

y

z

Rotate the camera vertically (pitch)

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 4 / 17

Page 7: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Viewing Transformation

The Viewing Transformation

cameralook x

y

z

Rotate the camera horizontally (yaw)

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 4 / 17

Page 8: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Camera’s Position

The camera’s position may be determined by three quantities.Pitch – angle tilting forward (up or down).Yaw – angle left or right.Distance – distance from the look point.

Given pitch, yaw , and dist , how do we compute the x-, y -, andz-coordinates of the camera?

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 5 / 17

Page 9: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Camera’s Position

The Camera’s Position

eye

uplook

The eye (or camera) position, the look point, and up

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 6 / 17

Page 10: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Camera’s Position

The Camera’s Position

eye

look

yawpitch

dist

The pitch, yaw , and dist

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 6 / 17

Page 11: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Camera’s Position

The Camera’s Position

eye

look

pitch

θϕ

The pitch, yaw , and dist

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 6 / 17

Page 12: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Outline

1 The Viewing Transformation

2 Calculating the Eye Coordinates

3 Moving the Camera

4 Assignment

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 7 / 17

Page 13: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Calculating the Camera’s Coordinates

The vertical distance (elevation, or y ) to eye is

dist · sinϕ.

The horizontal distance from look to directly under eye is

dist · cosϕ.

Thus, the x coordinate is

(dist · cosϕ) sin θ

and the z-coordinate is

(dist · cosϕ) cos θ.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 8 / 17

Page 14: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Calculating the Camera’s Coordinates

The vertical distance (elevation, or y ) to eye is

dist · sinϕ.

The horizontal distance from look to directly under eye is

dist · cosϕ.

Thus, the x coordinate is

(dist · cosϕ) sin θ

and the z-coordinate is

(dist · cosϕ) cos θ.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 8 / 17

Page 15: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Calculating the Camera’s Coordinates

The vertical distance (elevation, or y ) to eye is

dist · sinϕ.

The horizontal distance from look to directly under eye is

dist · cosϕ.

Thus, the x coordinate is

(dist · cosϕ) sin θ

and the z-coordinate is

(dist · cosϕ) cos θ.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 8 / 17

Page 16: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Calculating the Camera’s Coordinates

Calculating the Camera’s Coordinateseye = dist*vec3(cos(pitch)*sin(yaw), sin(pitch),

cos(pitch)*cos(yaw));

x = dist · cosϕ sin θ,y = dist · sinϕ,z = dist · cosϕ cos θ.

This calculation of eye should be placed in the setView()function.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 9 / 17

Page 17: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Outline

1 The Viewing Transformation

2 Calculating the Eye Coordinates

3 Moving the Camera

4 Assignment

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 10 / 17

Page 18: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Moving the Camera

To move the camera, we will modify yaw , pitch, and dist .We want the user interface to be simple and intuitive.

Drag the mouse left or right to change yaw .Drag the mouse up or down to change pitch.Roll the mouse wheel to change dist .

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 11 / 17

Page 19: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Yaw Angle

For the yaw angle, let the width of the window represent 180◦.Let old_x and old_y be where the mouse was last clicked, asreported by the mousebutton callback function (and later updatedin the cursor position callback function).In the cursor position callback function, xpos and ypos will be thecurrent coordinates.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 12 / 17

Page 20: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Yaw Angle

The Yaw Anglefloat d_yaw = (float)(xpos - old_x)/fb_width*180.0f;yaw += d_yaw;old_x = xpos;

Write similar code for pitch.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 13 / 17

Page 21: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Distance

For the distance to the look point, let each click of the wheelrepresent a 5% change.The change should be small enough that zooming appears to besmooth.A forward rotation will replace dist with dist/1.05f.A backward rotation will replace dist with 1.05f*dist.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 14 / 17

Page 22: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

The Distance

The Distanceif (yoffset > 0)

dist /= 1.05f;else

dist *= 1.05f;

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 15 / 17

Page 23: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Outline

1 The Viewing Transformation

2 Calculating the Eye Coordinates

3 Moving the Camera

4 Assignment

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 16 / 17

Page 24: Lecture 13 Robb T. Koether - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms331/Lectures... · To move the camera, we will modify yaw, pitch, and dist. We want the user

Assignment

AssignmentAssignment 12.

Robb T. Koether (Hampden-Sydney College) Moving the Camera Mon, Sep 18, 2017 17 / 17