Interact with smooth curves in OpenGL.
For each Task below show the control points and the curve
(sequence of line segments).
The points \(P_i\) are the same for all Tasks.
Connect all the control points with white lines
Vertex
array of size ncpoints + 1
. Copy the coordinate from
cpoints
, set the color to white and make sure the curve is closed.
glDrawArrays
with
GL_LINE_STRIP
to draw the polygon.
From the polygon in Task 1, generate a smoother curve by subdivision.
Initialize \(P_i^0 = P_i\) (green).
Double the number of control points by setting
where \(k\) is the level of subdivison and
\(i\) is the index of points is in range \(0 \dots (N\times 2^k-1)\) .
Cycle through a maximal level of subdivisions: when \(k=0\) show the original control polygon. When key 1 is pressed and \(k=m\) then compute and draw the control polygon at level \(k=m+1\). However, when \(m=5\), \(m\) is set to 0 and the original control polygon is drawn.
Another way to generate a curve is to construct several smoothly connected Bezier pieces.
We are going to construct 8 pieces of degree 4. The \(i\)th piece has control points \(\mathbf{c}_i=\{c_{i,0},c_{i,1},c_{i,2},c_{i,3},c_{i,4}\}\). One of the 5 control points is given as: \[c_{i,2} = \frac{4P_{i-1}+16P_i+4P_{i+1}}{24}\] and the points \(c_{i,1}\) and \(c_{i_3}\) have the following form: \[c_{i,1} = a P_{i-1} + b P_i + c P_{i+1}\] \[c_{i,3} = c P_{i-1} + b P_i + a P_{i+1}\] for constants \(a,b,c\).
For each Bezier curve piece:
Draw the 5 BB-coefficients in red
Choose \(n\) the number of pieces to discretize each Bezier piece into (tessellation number) sufficiently high so the discretized curve looks smooth.
Implement Task 4 using the OpenGL 4.x tessellation engine.
Make sure picking still works on the original \(N\) vertices, and your curves adapt to their movement.