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 Animation class will be used (see the source file Animation.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 formatUtil.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.

Optional fly-through modelled and rendered in 3ds Max

As an optional part of this assignment, you can set up an interesting fly-through of at least 12 second in 3ds Max and deliver the rendered result. Selection of the geometry for your rendered animation is completely up to you but should be more than just a predefined object from 3ds Max. The camera animation should feature at least 5 key points and should modify camera position and orientation, and also show modification of perspective projection (for example zooming in and out).

Deadline

The due date is: 13. 1. 2019

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 scrip
up to 5 pts: for an interesting fly-through modelled and rendered in 3ds Max

Project

Visual Studio project: 086shader
Make sure to always SVN update just before you start working on a new project.

Source file

Modify and hand-in the file: Camera.cs. Should your camera animation be somehow tied to your procedural geometry from the assignment 057, include also your file Construction.cs.
Remember to set your name in the InitParams() function!
Should you decide to hand in your 3ds Max fly-through, please send in the following:

  • a link to a pre-rendered video (of at least 12 seconds) stored on a video/file sharing service such as YouTube, Vimeo, Dropbox, Google drive etc.
  • a link to your 3d Max scene
  • Power Point (or similar) presentation with a few slides showing and describing your 3d Max setup, including a screen-shot from the animation curve editor.
  • Note that all of the above items should be easily associated with your name (your name and the assignment ID should ideally be a part of the file name).


    Copyright (C) 2018 J.Pelikán and J.Krivánek, last change: 2019-05-09 17:52:59 +0200 (Thu, 09 May 2019)