Assignment 116: Animated real-time camera

The task is to design and implement an animated camera "fly-through" in a real-time 3D renderer. Your camera will be used in a 3D scene viewer 086shader as an alternative to the interactive "Trackball" used by default. You will only need to modify the "Model-View" and "Projection" matrices used for rendering the scene, but you will not need to modify the scene rendering code itself.

Camera flythrough

Basics

The basis is the project 086shaders from the grcis repository. The application can read a 3D scene from a file (Wavefront OBJ) or generate it procedurally (you may use your solution of the assignment 057 or the implicit SFC curve implemented in the previous year by the student Matúš Goliaš). The scene is then rendered using the GPU renderer (be sure to check out the code, so you know how things work). You may enable smooth shading, for which your geometry must contain per-vertex normal vectors.
After checking the Animation check-box, the code in the AnimatedCamera class will be used (see the source file Camera.cs). The animation curve can define the camera trajectory, orientation, or both. The user can also load the camera script from an external file using the button Load cam (implementing this functionality is optional). The Start/Stop button resumes/stops the animation, Reset cam sets the camera to its initial state.
Whenever the Animation check-box is off, the interactive Trackball is (re-)enabled.

Theory

All the necessary details are available in the lecture Mathematics for 3D graphics, in the part concerned with matrix transformation, quaternions, and animation curves.
You will define the "Model-View" matrix, which places and orients the camera in the world-space (this can also be regarded as transforming the entire world so that the viewer, i.e. the camera position, is at the origin looking down the negative z-axis). Furthermore, you can also set the "Projection" matrix, which defines the parameters of the perspective projection. (A side note: The former matrix describes what is in computer vision called the "Extrinsic camera parameters" while the latter defines the "Intrinsic parameters", i.e. the parameters of the optical system proper).
You may set reasonable projection parameters and never change them during the animation. A reasonable maximum camera angle is 80° or less. Of course, your may implement zooming in and out as a part of the fly-through, for which you would need to modify the projection matrix as function of time.
Camera movement: it is necessary to move the camera along a smooth animation curve (defined either using goniometry or - even better - though a general interpolation curve, such as Catmull-Rom or Bezier).
Camera orientation: the camera orientation should have the maximum possible degree of continuity, for example using the quaternion interpolation or using a smoothly moving target object (cf Matrix4.LookAt()).

Technical details

The IDynamicCamera interface defines the dynamic camera API. You can derive your camera from the class DefaultDynamicCamera, in which most of the interface methods are already reasonably implemented, and you will only have to worry about the calculation of the time-varying transformation matrices.
Implementation of your camera is in the source file Camera.cs, the class is called AnimatedCamera. Its default behavior is to fly around the origin on a circle-like trajectory with the view fixed at the origin (i.e. the scene center). The following section describes the most important properties and functions of the API, which you will need to implement or at least understand. Functions used only for the interactive camera (Trackball) are intentionally skipped as they are not needed for the animated camera.

Extract from IDynamicCamera API

  • Update() - called when the animation mode is enabled. You may read animation parameters from the text field Param: or from the external text file (the format of which is entirely under your control).
  • double Time - current time in seconds.
  • double MinTime - start of the animation interval.
  • double MaxTime - end of the animation interval (after reaching this time, the program will jump back to the start - the animation is automatically made periodic).
  • Reset() - [re-]initialization of the animation to the initial state.
  • GLsetupViewport() - called upon every change of the window geometry (the "Resize" event). The minimum you should do here is to update the projection matrix so that it respects the window's aspect ratio.
  • Matrix4 ModelView - returns the current Model-View transform matrix. This is the central point of your implementation of the animated camera, as this matrix defines the camera position and orientation.
  • Matrix4 ModelViewInv - you may implement a faster way of calculating the inverse of the Model-View matrix (so it does not have to be inverted numerically - which is what the default implementation does).
  • Matrix4 Projection - returns the current projection matrix.
  • Vector3 Eye - returns the current camera (eye) position in world coordinates.

You may read up on the IDynamicCamera API in the file Trackball.cs.

Example of an external script

One line of a text file = one key-frame. The line can be read e.g. by the function TextReader.ReadLine(). Parameters are in the format Util.ParseKeyValueList(), and the only mandatory item on each line is the time. Parameters:

  • t = <double> - time of the key-frame in seconds
  • pos = [<double>;<double>;<double>] - camera position [x;y;z]
  • lookat = [<double>;<double>;<double>] - position of the point being tracked [x;y;z]
  • up = [<double>;<double>;<double>] - "up" vector [x;y;z]

Items that are not set are copied from the previous line. So when you only set the time, it means a constant segment from the previous key frame.

Deadline

The due date is: 28. 2. 2023

Points

7 pts: smooth camera movement defined procedurally in the program or a smooth interpolation of a trajectory defined by key-frames
up to 4 pts: smooth interpolation of camera orientation (quaternions or a non-trivial moving tracking target)
up to 5 pts: scripted animation (externally defined animation script using your own format)
up to 5 pts: bonus for an interesting/nice-looking script

Project

Visual Studio project: 086shader

Source file

Modify and hand-in the file: Camera.cs.
Remember to set your name in the InitParams() function!


Copyright (C) 2018-2020 J.Pelikán and J.Krivánek, last change: 2022-12-08 12:17:14 +0100 (Thu, 08 Dec 2022)