Docsity

Camera Control - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Camera Control - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics 3D Viewing and Camera Control

3D Viewing

n Similar to taking a photograph

n Control the “lens” of the camera

n Project the object from 3D world to 2D screen

Viewing Transformation

n OpenGL Code:

void display()

glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(0,0,1,0,0,0,0,1,0);

display_all(); // your display routine

Viewing Transformation

n Control the “lens” of the camera

n Important camera parameters to specify

n Camera (eye) position (Ex,Ey,Ez) in world coordinate system

n lookAt point (cx, cy, cz)

n Orientation (which way is up?): Up vector (Up_x, Up_y, Up_z)

world (cx, cy, cz)

(ex, ey, ez) view up vector (Up_x, Up_y, Up_z)

Viewing Transformation

n gluLookAt call transforms the object from world to eye

space by:

n Constructing eye coordinate frame (u, v, n) n Composes matrix to perform coordinate transformation n Loads this matrix into the V part of modelview matrix n Allows flexible Camera Control

Eye Coordinate Frame

n Constructing u,v,n?

n Known: eye position, LookAt Point, up vector

n To find out: new origin and three basis vectors

eye

Lookat Point

Assumption: direction of view is

orthogonal to view plane (plane that objects will be projected onto)

90

o

Eye Coordinate Frame

n How about u and v?

eye

Lookat n

u

v

V_up •We can get^ u^ first^ -

•u is a vector that is perp

to the plane spanned by

N and view up vector (V_up)

U = V_up x n

u = U / | U |

Eye Coordinate Frame

n How about v?

eye

Lookat n

u

v

V_up Knowing n and u, getting v

is easy

v = n x u

v is already normalized

World to Eye Transformation

n Next, use u, v, n to compose V part of modelview

n Transformation matrix (Mw2e)?

P’ = Mw2e x P

v u

n

world x

y

z

P

  1. Come up with the transformation sequence to move eye coordinate frame to the world
  2. And then apply this sequence to the point P in a reverse order

World to Eye Transformation

n Rotate the eye frame to “align” it with the world frame

n Translate (-ex, -ey, -ez)

v u

n

world x

y

z

(ex,ey,ez)

Rotation: ux uy uz 0 vx vy vz 0 nx ny nz 0 0 0 0 1

Translation: 1 0 0 -ex 0 1 0 -ey 0 0 1 -ez 0 0 0 1

Flexible Camera Control

n Sometimes, we want camera to move

n Just like controlling a airplane’s orientation

n Use aviation terms for this: pitch, yaw, roll

n Pitch: nose up-down n Roll: roll body of plane n Yaw: move nose side to side

pitch

x

y

yaw

y

x

roll

Flexible Camera Control

n May create a camera class

class Camera

private:

Point3 eye;

Vector3 u, v, n;…. etc

n Let user specify pitch, roll, yaw to change camera

n Example:

cam.slide(-1, 0, -2); // slide camera forward and left

cam.roll(30); // roll camera through 30 degrees

cam.yaw(40); // yaw it through 40 degrees

cam.pitch(20); // pitch it through 20 degrees

Loading Modelview Matrix directly

void Camera::setModelViewMatrix(void)

{ // load modelview matrix with existing camera values

float m[16]; Vector3 eVec(eye.x, eye.y, eye.z);// eye as vector m[0] = u.x; m[4] = u.y; m[8] = u.z; m[12] = -eVec.dot(u); m[1] = v.x; m[5] = v.y; m[9] = v.z; m[13] = -eVec.dot(v); m[2] = n.x; m[6] = n.y; m[10] = n.z; m[14] = -eVec.dot(n); m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1.0; glMatrixMode(GL_MODELVIEW); glLoadMatrixf(m); // load OpenGL’s modelview matrix

}

Above setModelViewMatrix acts like gluLookAt

Slide changes eVec, roll, pitch, yaw, change u, v, n

Camera Slide

n User changes eye by delU, delV or delN

n eye = eye + changes

n Note: function below combines all slides into one

void camera::slide(float delU, float delV, float delN)

eye.x += delUu.x + delVv.x + delN*n.x;

eye.y += delUu.y + delVv.y + delN*n.y;

eye.z += delUu.z + delVv.z + delN*n.z;

setModelViewMatrix( );