Assignment 2 – Tessellation and Interpolation

EDA221 – Introduction to Computer Graphics, 2016
Assignment 2 – Tessellation and Interpolation
In this assignment you will tessellate your own model from a parametric
equation. This task involves setting up appropriate data structures, and
then generating surface points and surface derivatives from the parametric
equations – an exercise in programming as well as vector calculus.
You will also implement two different interpolation schemes: linear interpolation, and cubic interpolation using Catmull-Rom splines.
Getting Started
Look in the CG Labs/src/EDA221 folder for the parametric shapes.cpp file. It
contains a scene set up with a parametrically tessellated circle ring which
will serve as a starting point for this and the next assignment.
Tessellation
Implement the function bodies of createQuad() and createSphere() found in
parametric shapes.cpp. Use the existing implementation of the circle ring as
guidance. Test both shapes in the scene and validate that they are tessellated
correctly. Allow for variable resolution rates of the parametric variables. Include at least spatial coordinates (x, y, z) and normals (nx , ny , nz ) in the
vertex-definition (in assignment 3 you will be asked to include texture coordinates, tangents and binormals as well).
Sphere


 r sin(θ) sin(ϕ) 
−r cos(ϕ)
p(θ, ϕ) =
, 0 ≤ θ ≤ 2π, 0 ≤ ϕ ≤ π


r cos(θ) sin(ϕ)
Sphere tangent and binormal




r cos(θ) sin(ϕ) 
r sin(θ) cos(ϕ) 


∂p
∂p
0
r sin(ϕ)
=
,
=

 ∂ϕ 

∂θ
−r sin(θ) sin(ϕ)
r cos(θ) cos(ϕ)
1
Torus (Optional)


(ra + rb cos(θ)) cos(ϕ)
p(θ, ϕ) = (ra + rb cos(θ)) sin(ϕ) , 0 ≤ θ, ϕ ≤ 2π


−rb sin(θ)
Torus tangent and binormal




−rb sin(θ) cos(ϕ) 
−(ra + rb cos(θ)) sin(ϕ)


∂p
∂p
(ra + rb cos(θ)) cos(ϕ)
= −rb sin(θ)) sin(ϕ) ,
=

 ∂ϕ 

∂θ
−rb cos(θ)
0
Discussion Topics
• Switch between back- and front-face culling. Look for the line in the
code that switches the culling. Which triangles are culled and which
are rendered?
• Examine the “Normals”-shader (press ’3’) and apply it to your model.
What does it do? Are the normals of your model correct?
Interpolation
Implement the function bodies for linear and cubic Catmull-Rom interpolation in the file Interpolation.cpp. Then set up a cyclic path of at least 10
points and interpolate some object along this path.
Linear interpolation:
1 0
pi
p(x) = 1 x
, x ∈ [0, 1]
−1 1 pi+1
Catmull-Rom spline:

q(x) = 1 x x2


0
1
0
0
pi−1


−τ
0
τ
0 
  pi 
x3 
 2τ τ − 3 3 − 2τ −τ  pi+1  , x ∈ [0, 1]
−τ 2 − τ τ − 2 τ
pi+2
The tension factor can be set to τ = 0.5 initially.
2
Discussion Topics
• How does the distribution of the control points affect the velocity of
the animated object? Why? How can this be addressed?
• Animate two objects along the same path using different tension τ ; how
do the trajectories differ?
• How can an animated object be made to keep ”facing forward” as it
travels along its path?
Hint: Use the derivative of the spline (analytical or numerical) to obtain a tangent vector.
Requirements for approval
You will be asked to demonstrate your tessellated, correctly lit model, and to
discuss the roles of the parametric variables (θ and ϕ, for instance). You will
also be asked to demonstrate and discuss the concepts of linear and cubic
Catmull-Rom interpolation.
Useful C++ Framework commands
Change polymode (Filled/Line/Point) Z
White shader
1
Diffuse shader
2
Normal shader
3
Texture coordinate shader
4
3
Useful Visual Studio 2015 commands
Execution & debugging
Build
Build+Run (using current configuration)
Stop
Toggle breakpoint at current line
Step Into (while in break mode)
Text editing
Comment selection
Uncomment selection
Delete entire row
4
Ctrl+Shift+B
F5
Shift+F5
F9
F11
Ctrl+K, Ctrl+C
Ctrl+K, Ctrl+U
Ctrl+X