CS
486/686 Game Engineering
Practice Problems #3
- You want to point your camera at an object. You want the
camera be as close as possible to "right side up", given that it is
pointed at the object. That is, you want the camera's up vector
to be as close as possible to the world up vector, given that the
camera is pointed directly at the object. If the object has the
position po = [pox, poy, poz], and the camera has the position pc = [pcx, pcy, pcz], give the rotational matrix for the camera.
- You want to aim a turret. The turret consists of two
objects: The "base", which can rotate around the y axis, and the
barrel, which can be raised or lowered:

The barrel is attached to the turret (so that it moves when the turret
moves). The barrel is attached at an offset of [0,0,0] in turret
space (so the origin of the barrel is the same as the origin of the
turret). Assume that if the rotational matrix of the barrel (in
turret space) is the identity matrix I, the barrel points straight down the z-axis of the turret.
You wish to rotate the turret and raise the barrel so that it points at an object at position p = [px, py, px].
Show how to create the rotational matrix for both the turret (in
world space) and the barrel (in turret space). Feel free to
define "local variables" in your answer (such as, let x = || p1 × p2||)
- Recall the solar system definition from the second midterm. We are going to extend it a little bit. We have:
- Position of Sun 1 (vector): ps1
- Scalar Distance dp1 and orientaion qp1 of Planet 1 from sun 1
(where the orientation qp1 is a quaternion that describes how much we
need to rotate the vector [0,0,dp1] to point from sun1 to planet 1 in
world space)
- Scalar distance dm1 and orentation qm1 of Moon 1 from Planet
1 (where the orientation qm1 is a quaternion that describes how much we
need to rotate the vector [0,0,dm1] to point from planet 1 to moon 1,
in world space)
- Position of Sun 2 (vector): ps2
- Scalar Distance dp2 and
orientaion qp2 of Planet 2 from sun 2 (where the orientation qp2 is a
quaternion that describes how much we need to rotate the vector
[0,0,dp2] to point from sun20 to planet 2 in world space)
- Scalar
distance dm2 and orentation qm2 of Moon 2 from Planet 2 (where the
orientation qm2 is a quaternion that describes how much we
need to rotate the vector [0,0,dm1] to point from planet 2 to moon 2,
in world space)
Give an equation that describes the scalar distance between moon 1 and moon 2.
- What is the output of the following fragment of C++ code:
int &wierd(int &x)
{
return ++x;
}
int main()
{
int x = 1;
int &y = wierd(x);
printf("x = %d, y = &d \n", x, y);
y++;
printf("x = %d\n", x);
}
Bonus question: If we change the ++x to a x++, then the code will no longer compile. Why not?