Camera Control Homework

In this assignment, you will implement a camera control AI that attempts to keep a number of non-player characters in view at all times. This assignment uses the Unity3D game engine, a freely available 3D game engine that uses the C# programming language.

We have set up a 3D environment with a number of small dinosaurs running around randomly. You must implement a camera control AI that keeps the dinosaurs in view at all times, no matter where they go.

You should base your camera control AI on the ConstraintCam technique described in the paper, Intelligent Multi-shot Visualization Interfaces for Dynamic 3D Worlds.

Your camera control AI should prefer to view the dinosaurs from the front (between 45 degrees and -45 degrees from the front of the dinosaurs) and to get in as close to the dinosaurs as it can without losing sight of the other dinosaurs.

If it is impossible to keep all dinosaurs in view, it should keep as many in view as possible. The camera AI should relax the preference for viewing the dinosaurs from the front before dropping a dinosaur completely from view. You do not need to implement split-screen viewing.


ConstraintCam in a Nutshell

Please consult Intelligent Multi-shot Visualization Interfaces for Dynamic 3D Worlds for a complete discription of the ConstraintCam algorithm. The following is a concise overview.

ConstraintCam attempts to find a position and orientation for a virtual camera in 3D space that keeps multiple target NPCs visible at all times AND views the NPCs from a preferred angle.

Consider the image below, which shows a top-down view of an NPC. The desire is to view the NPC from 90 degrees (from the front), but any angle between 45 and 180 degrees would be acceptable. The green box is a wall that would occlude the camera if it were between the NPC and the camera. We can see that the camera's should be placed just to the right of the wall, somewhere between 45 and 90 degrees.

To automatically compute the camera position for the case of one NPC, it is advantageous to work in polar coordinates, where any position in 3D space relative to the NPC can be defined as an angle on imaginary circle around the NPC, the angle above the ground, and the distance from the NPC. In the above, we are just considering the angle around the imaginary circle.

To find an area in the 3D world that is consistent with the viewing preference and guaranteed not to occlude the view of the NPC, the figure below shows what the vantage-consistent region would look like in polar coordinate space (ignoring distance) and what the obstacle looks like in polar coordinate space (ignoring distance). View cones look like squares (cubes when distance is added in), which are easy to work with.

Doing a simple intersection of squares (or cubes) yields a space where the camera can be placed. Pick any point in this space as an angle around circle, angle above ground (and distance) for the placement of the virtual camera. Ideally, this point will be the one closest to the optimal viewpoint (e.g., 90 degrees in this example to see the NPC from directly in front). Then translate the polar coordinates back into Cartesian coordinates.

Distance is not shown in the above example, but there will also be a preferred viewing distance, a minimum acceptable distance, and a maximum acceptable distance.

It is left as an exercise how to extend the technique to 2+ NPCs and to incorporate distance constraints.

If the constraint consistent region is empty, then there is no point at which the camera can be placed that meets all viewpoint constraints. When this happens, one or more constraints must be relaxed. First try removing the distance constraint and recomputing the view area. If that also fails, remove the prefered minimum and maximum view angle from one or more NPCs until the view area has a solution.

The virtual camera must also have an orientation. The camera should be oriented toward the mean position between all NPCs. This may require the camera to move farther back from the NPCs to keep all NPCs in view.

Since the NPCs will move unpredictably around the environment, the camera will have to move as well. Good cinematographic practice suggests that if the camera needs to move a small distance, it should interpolate smoothly between its current point and the desired point. If the camera must move a large distance, it is often preferable to "cut", meaning it jumps instantaneously to the desired point (creating the appearance that one camera is turned off and another is turned on, although in fact there is just one camera that can move instantaneously between points in virtual space).


What you need to know

MyCamera

This is the class you will be altering for this assignment.

Member variables:

The other class variables are used to handle methods, as a caveat of Unity C# is that static function variables do not exist. Class variables are used in replacement of that.

Member functions:


Instructions

To accomplish this, you will write whatever functions you need in the “My Camera” class to provide target positions and rotations to the camera.

You are NOT allowed to modify the CompyScript class.


Grading

Grading will be performed via in-class demonstration. The quality of your solution, in terms of keeping the dinosaur NPCs in view and at the preferred view angle and view distance will be compared to solutions from other students in the class.


Submission

To submit your solution, create a copy of your Unity folder somewhere to prepare for zipping. Then delete the “Library” folder of your project. The Library folder contains the stream compiled data that unity uses to quickly run editor instances of the game, and is specific to an individual computer. The TAs computer will generate their own Library folder upon opening your project, and this will greatly reduce your project size for submitting on T-Square.

Then zip your project, calling it LastFirst_CameraAI.zip, and submit it to T-square.