Perspective View

advertisement
Graphics
Viewing
고려대학교 컴퓨터 그래픽스 연구실
kucg.korea.ac.kr
Graphics Lab @ Korea University
Fundamental Types of
Viewing

Perspective views


KUCG
finite COP (center of projection)
Parallel views


COP at infinity
DOP (direction of projection)
perspective view
kucg.korea.ac.kr
parallel view
Graphics Lab @ Korea University
Parallel View
kucg.korea.ac.kr
KUCG
Graphics Lab @ Korea University
Perspective View
kucg.korea.ac.kr
KUCG
Graphics Lab @ Korea University
Classical Viewing

KUCG
Specific relationship between the objects and
the viewers
kucg.korea.ac.kr
Graphics Lab @ Korea University
Orthographic Projections

KUCG
Projectors are perpendicular to the projection
plane

preserve both distances and angles
orthographic projections
kucg.korea.ac.kr
temple and three multiview
orthographic projections
Graphics Lab @ Korea University
Axonometric Projections (1/2)

KUCG
Projection plane can have any orientation with
respect to the object

projectors are still orthogonal to the projection planes
construction
kucg.korea.ac.kr
top view
side view
Graphics Lab @ Korea University
Axonometric Projections (2/2)

KUCG
Preserve parallel lines but not angles



isometric – projection plane is placed symmetrically
with respect to the three principal faces
dimetric – two of principal faces
trimetric – general case
kucg.korea.ac.kr
Graphics Lab @ Korea University
Axonometric Projections (2/2)

KUCG
Preserve parallel lines but not angles



isometric – projection plane is placed symmetrically
with respect to the three principal faces
dimetric – two of principal faces
trimetric – general case
kucg.korea.ac.kr
Graphics Lab @ Korea University
Oblique Projections

KUCG
Projectors can make an arbitrary angle with the
projection plane

preserve angels in planes parallel to the projection
plane
construction
kucg.korea.ac.kr
top view
side view
Graphics Lab @ Korea University
Perspective Projections (1/2)

KUCG
Diminution of size

when objects are moved father from the viewer, their
images become smaller
kucg.korea.ac.kr
Graphics Lab @ Korea University
Perspective Projections (2/2)

KUCG
One-, two-, and three-point perspectives


how many of the three principal directions in the
object are parallel to the projection plane
vanishing points
three-point
perspective
kucg.korea.ac.kr
two-point
perspective
one-point
perspective
Graphics Lab @ Korea University
Perspective Projections (2/2)

KUCG
One-, two-, and three-point perspectives


how many of the three principal directions in the
object are parallel to the projection plane
vanishing points
three-point
perspective
kucg.korea.ac.kr
two-point
perspective
one-point
perspective
Graphics Lab @ Korea University
Perspective Projections (2/2)

KUCG
One-, two-, and three-point perspectives


how many of the three principal directions in the
object are parallel to the projection plane
vanishing points
three-point
perspective
kucg.korea.ac.kr
two-point
perspective
one-point
perspective
Graphics Lab @ Korea University
Perspective Projections (2/2)

KUCG
One-, two-, and three-point perspectives


how many of the three principal directions in the
object are parallel to the projection plane
vanishing points
three-point
perspective
kucg.korea.ac.kr
two-point
perspective
one-point
perspective
Graphics Lab @ Korea University
Positioning of the Camera (1/3)

KUCG
OpenGL places a camera at the origin of the
world frame pointing in the negative z direction

move the camera away from the objects
glTranslatef(0.0, 0.0, -d);
initial configuration
kucg.korea.ac.kr
after change in the model-view matrix
Graphics Lab @ Korea University
Positioning of the Camera (2/3)

KUCG
Look at the same object from the positive x axis

translation after rotation by 90 degrees about the y
axis
glMatrixMode(GL_MODELVIEW);
glLoadIdentity( );
glTranslatef(0.0, 0.0, -d);
glRotatef(-90.0, 0.0, 1.0, 0.0);
kucg.korea.ac.kr
Graphics Lab @ Korea University
Positioning of the Camera (3/3)

KUCG
Create an isometric view of the cube
1
0
M  TR x R y  
0

0
y
(1, 1, 1)
0  1
1 0 0  0
0 1  d  0

0 0 1  0
0 0
(0, 1,
0 

6 / 3  3 / 3 0 
3 /3
6 / 3 0  

0
0
1 
0
0
y
(0, 1,
2)
2 /2
0
0
1
2 /2 0
0
0
y
2 / 2 0

0
0
2 / 2 0

0
1
2)
z
x
view from
positive z axis
kucg.korea.ac.kr
x
view from
positive z axis
view from
positive x axis
Graphics Lab @ Korea University
Positioning of the Camera (3/3)

KUCG
Create an isometric view of the cube
glMatrixMode(GL_MODELVIEW);
glLoadIdentity( );
glTranslatef(0.0, 0.0, -d);
glRotatef(35.26, 1.0, 0.0, 0.0);
glRotatef(45.0, 0.0, 1.0, 0.0);
y
(1, 1, 1)
y
(0, 1,
y
2)
(0, 0,
x
view from
positive z axis
kucg.korea.ac.kr
x
3)
x
view from
positive z axis
Graphics Lab @ Korea University
U-V-N System (1/2)

KUCG
VRP (view-reference point), VPN (view-plane
normal), and VUP (view-up vector)

u, v (up-direction vector), n (normal vector)
 x, y, z axes respectively
camera frame
kucg.korea.ac.kr
determination of the view-up vector
Graphics Lab @ Korea University
U-V-N System (2/2)

KUCG
Translation after rotation



VRP – (x, y, z)  T(-x, -y, -z)
VNP – (nx, ny, nz)  n
VUP – vup  v = vup – (vup• n) n
u=vn
(※ our assumption – all vectors must be normalized )
1
0
M  TR  
0

0
kucg.korea.ac.kr
0 0  x  u x
1 0  y   v x
0 1  z  n x

0 0 1  0
uy
uz
vy
ny
vz
nz
0
0
0
0
0

1
Graphics Lab @ Korea University
Look-At Function

KUCG
OpenGL utility function
gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz);

VRP: eyePoint

VPN: – ( atPoint – eyePoint )

VUP: upPoint – eyePoint
look-at positioning
kucg.korea.ac.kr
Graphics Lab @ Korea University
Others

Roll, pitch, and yaw


KUCG
ex. flight simulation
Elevation and azimuth

ex. star in the sky
kucg.korea.ac.kr
Graphics Lab @ Korea University
Simple Perspective
Projections (1/2)

KUCG
Simple camera


projection plane is orthogonal to z axis
projection plane in front of COP
zp  d,
x
xp 
,
z/d
three-dimensional view
kucg.korea.ac.kr
x xp

z d
y
yp 
z/d
top view
side view
Graphics Lab @ Korea University
Simple Perspective
Projections (2/2)

Homogeneous coordinates
 x   wx 
 y   wy 
p  
 z   wz 
   
1   w 

KUCG
 x   x 
z/d   x 
xp  

 y   z /yd   y   y 

 
p




p

 z/d  
zp   z / d 
 z 
z
 
   d  



1
z
/
d
  


z/d

1



  1 
Perspective projection matrix
1
0
M
0

0
0
0
1
0
0
1
0 1/ d
kucg.korea.ac.kr
0
0
0

0
Model-view
Projection
Perspective
division
projection pipeline
Graphics Lab @ Korea University
Simple Orthogonal Projections

KUCG
Projectors are perpendicular to the view plane
xp  x
yp  y
zp  0

Orthographic projection matrix
 x p  1
 y  0
 p  
 z p  0
  
 1  0
kucg.korea.ac.kr
0 0 0  x 
1 0 0  y 
0 0 0  z 
 
0 0 1  1 
Graphics Lab @ Korea University
Projections in OpenGL

Angle of view


KUCG
only objects that fit within the
angle of view of the camera
appear in the image
View volume

be clipped out of scene
 frustum – truncated pyramid
kucg.korea.ac.kr
Graphics Lab @ Korea University
Perspective in OpenGL (1/2)

KUCG
Specification of a frustum
glMatrixMode(GL_PROJECTION);
glLoadIdentity( );
glFrustum(xmin, xmax, ymin, ymax, near, far);

near, far: positive number !!
 zmax = – far
 zmin = – near
kucg.korea.ac.kr
Graphics Lab @ Korea University
Perspective in OpenGL (2/2)

KUCG
Specification using the field of view
glMatrixMode(GL_PROJECTION);
glLoadIdentity( );
gluPerspective(fovy, aspect, near, far);

fov: angle between top and
bottom planes
 fovy: the angle of view in the
up (y) direction
 aspect ratio: width divided
by height
kucg.korea.ac.kr
Graphics Lab @ Korea University
Parallel in OpenGL

KUCG
Orthographic viewing function
glMatrixMode(GL_PROJECTION);
glLoadIdentity( );
glOrtho(xmin, xmax, ymin, ymax, near, far);


OpenGL provides only this parallel-viewing function
near < far !!
 no restriction on the sign
 zmax = – far
 zmin = – near
kucg.korea.ac.kr
Graphics Lab @ Korea University
Walking Though a Scene (1/2)
void keys(unsigned
{
if(key == ‘x’)
if(key == ‘X’)
if(key == ‘y’)
if(key == ‘Y’)
if(key == ‘z’)
if(key == ‘Z’)
}
KUCG
char key, int x, int y)
viewer[0]
viewer[0]
viewer[1]
viewer[1]
viewer[2]
viewer[2]
-=
+=
-=
+=
-=
+=
1.0;
1.0;
1.0;
1.0;
1.0;
1.0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(viewer[0], viewer[1], viewer[2], 0,0,0, 0,1,0);
glRotatef(theta[0], 1.0, 0.0, 0.0);
glRotatef(theta[1], 0.0, 1.0, 0.0);
glRotatef(theta[2], 0.0, 0.0, 1.0);
colorcube( );
}
glFlush( );
glutSwapBuffers( );
kucg.korea.ac.kr
Graphics Lab @ Korea University
Walking Though a Scene (2/2)
KUCG
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity( );
if( w <= h )
glFrustum(-2.0, 2.0, -2.0*(GLfloat)h/(GLfloat)w,
2.0*(GLfloat)h/(GLfloat)w, 2.0, 20.0);
else
glFrustum(-2.0 *(GLfloat)w/(GLfloat)h,
2.0 *(GLfloat)w/(GLfloat)h, -2.0, 2.0, 2.0, 20.0);
glMatrixMode(GL_MODELVIEW);
}
kucg.korea.ac.kr
Graphics Lab @ Korea University
Projections & Shadows (1/2)
KUCG

Shadow polygon
 Steps




light source at (xl, yl, zl)
translation (-xl, -yl, -zl)
perspective projection
through the origin
translation (xl, yl, zl)
1
0
M  T 1 PT  
0

0
kucg.korea.ac.kr
0
1
0
0
0
0
1
0
0
xl  1

1
yl  0
0
z l  0

1  0 1 / y l
0
0
1
0
0 1
0 0
0  0

0  0
0
1
0
0
0  xl 
0  yl 
1  zl 

0 1 
Graphics Lab @ Korea University
Projections & Shadows (2/2)
KUCG
GLfloat m[16];
/* shadow projection matrix */
for(i=0; i<16; i++) m[i] = 0.0;
m[0] = m[5] = m[10] = 1.0;
m[7] = -1.0/yl;
glColor3fv(polygon_color);
glBegin(GL_POLYGON);
.
.
.
glEnd( );
glMatrixMode(GL_MODELVIEW);
glPushMatrix( );
glTranslatef(xl, yl, zl);
glMultMatrixf(m);
glTranslatef(-xl, -yl, -zl);
glColorfv(shadow_color);
glBegin(GL_POLYGON);
.
.
.
glEnd( );
glPopMatrix( );
kucg.korea.ac.kr
/* draw the polygon normally */
/*
/*
/*
/*
save state */
translate back */
project */
move light to origin */
/* draw the polygon again */
/* restore state */
Graphics Lab @ Korea University
Shadows from a Cube onto
Ground
kucg.korea.ac.kr
KUCG
Graphics Lab @ Korea University
Download