1
Answers to Quiz 2
Qn 1
a)
1
2
(1 − cos𝛼) 0 ≤ 𝛼 ≤ 𝜋
b)
Paper 1
void animate ( void )
{
double t;
t = glutGet (GLUT_ELAPSED_TIME);
alpha = 20.0 + 50.0 * (1 – cos ( PI * t/(3000.0);
glutPostRedisplay ( );
}
Paper 2
void animate ( void )
{
double t;
t = glutGet (GLUT_ELAPSED_TIME);
alpha = 40.0 + 60.0 * (1 – cos ( PI * t/(3000.0);
glutPostRedisplay ( );
}
Qn 2
a)
Paper 1
void ground_plane (void)
{
2
glColor3f (0, 1, 0);
glVertex3f (-100, -100, 2);
glVertex3f ( 100, -100, 2);
glVertex3f ( 100, 100, 2);
glVertex3f (-100, 100, 2);
}
Paper 2
void ground_plane (void)
{
glColor3f (0, 1, 0);
glVertex3f (-150, -150, 2);
glVertex3f ( 150, -150, 2);
glVertex3f ( 150, 150, 2);
glVertex3f (-150, 150, 2);
}
b)
void cube (void)
{
glPushMatrix ( );
glColor3f (0, 0, 1);
glTranslate (0, 0, 7);
glutSolidCube (10);
glPopMatrix ( );
}
c)
After changing to the light coordinate system, a perspective projection on the plane 𝑍 = −28 is
performed. The matrix is
(
1 0 0 0
0 1 0 0
0 0 1 0
0 0 1.0/−28.0 0
)
GLfloat Xs = 10;
GLfloat Ys = 20;
GLfloat Zs = 30;
3
GLfloat light1PosType [ ] = {Xs, Ys, Zs, 1.0};
:
GLfloat M[16];
for (i=0; i<16; i++) M[i]=0; M[0]=M[5]=M[10]=1; M[11]=-1.0/28.0; ground_plane ( ); cube ( ); glPushMatrix ( ); glTranslatef (Xs, Yz, Zs); glMultMatrixf (M); glTranslatef (-Xs, -Ys, -Zs); glColor3fv (shadowcolour); cube ( ); glPopMatrix ( ); Qn 3 a) 𝑀 = ( 1 0 − 𝑉𝑝𝑥 𝑉𝑝𝑧 𝑧𝑣𝑝 𝑉𝑝𝑥 𝑉𝑝𝑧 0 1 − 𝑉𝑝𝑦 𝑉𝑝𝑧 𝑧𝑣𝑝 𝑉𝑝𝑦 𝑉𝑝𝑧 0 0 0 𝑧𝑣𝑝 0 0 0 1 ) (𝑉𝑝𝑥, 𝑉𝑝𝑦. 𝑉𝑝𝑧) = (−1, 1, 2√2) 𝑧𝑣𝑝 = 2 𝑀 = ( 1 0 1 2√2 − 1 √2 0 1 − 1 2√2 1 √2 0 0 0 2 0 0 0 1 ) b) 𝑡𝑎𝑛−1 𝑉𝑝𝑧 √𝑉𝑝𝑥 2 + 𝑉𝑝𝑦 2 = 2 𝐶𝑎𝑏𝑖𝑛𝑒𝑡 𝑝𝑟𝑜𝑗𝑒𝑐𝑡𝑖𝑜𝑛 4 c) 1. the shadow has sharp boundaries 2. the shadow has a constant colour. There is no difference in shading when shadows overlap 3. the shading of the shadow is not varying (there is no soft shadow) 4. it can only generate shadow correctly if the shape the shadow casts is planar or any other reasonable answers Qn 4 a) The camera is pointing at (0, 0, 0) 𝑁 = (0, 0, 1) 𝑉 = |(100, 100, 100)| = ( 1 √3 , 1 √3 , 1 √3 ) 𝑁 ∙ 𝑉 = 1 √3 b) 𝐼 = 𝑘𝑎𝐼𝑎 + 𝑘𝑑(𝑁 ∙ 𝐿)𝐼𝑙 + 𝑘𝑠(𝑉 ∙ 𝑅) 𝑛𝑠𝐼𝑙 = (0.1)(0.2) + (0.8)(𝑁 ∙ 𝐿)(0.8) + (0.1)(𝑉 ∙ 𝑅)2(0.8) 𝐿 = (0, − 1 √2 , 1 √2 ) 𝑅 = 2(𝑁 ∙ 𝐿)𝑁 − 𝐿 = (0,0, √2) − (0,− 1 √2 , 1 √2 ) = (0, 1 √2 , 1 √2 ) 𝐼 = (0.1)(0.2) + (0.8) ( 1 √2 ) (0.8) + (0.1) ( 2 √6 ) 2 (0.8) = 0.525881673