Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please write it with C++ Using a 3D graphics package, such as OpenGL, draw a blue uniform cubic B-spline using the following control points (also

please write it with C++

Using a 3D graphics package, such as OpenGL, draw a blue uniform cubic B-spline using the following control points (also draw the control points in black):

( 0.0, 0.0, 0.0),

( 1.0, 3.5, 0.0),

( 4.8, 1.8, 0.0),

( 6.5, 7.0, 0.0),

( 9.0, 3.5, 0.0),

(32.5, 4.8, 0.0),

(33.2, 2.6, 0.0),

(36.8, 7.0, 0.0),

(37.8, 5.0, 0.0),

(41.2, 20.5, 0.0),

(41.5, 21.5, 0.0),

Hint to get started: Start with code for drawing the control points in black. Then draw a straight blue line made up of many dots from the first point to the last point. Position the camera on the positive Z axis. Then replace the code for drawing a straight line with code for drawing a curve. An algorithm for drawing a curve is given in the online notes at the end of Uniform B-Spline Derivation section of the Interpolation notes.

Hint for OpenGL: The DrawPoint(Qx, Qy, Qz) function in the notes corresponds to the following OpenGL commands:

glBegin(GL_POINTS);

glVertex3d(Qx, Qy, Qz);

glEnd();

(b) Motion Control

Using a 3D graphics package, such as OpenGL, animate a yellow ball moving along the blue curved path defined in part (a) above. The ball should take 5 seconds to traverse the whole path and then begin again. Motion control should be used to ensure that the ball goes at a constant rate along the curve.

Hint for drawing the sphere in the right place: Leave your code for part (a) unchanged because we still want to be able to see the curved path. You can add a DrawSphere function that is similar to the DrawCurve function, but it will need to depend on the time or the fraction of the arc length. To determine where to translate the sphere for drawing, calculate Qx, Qy, and Qz in the same manner as for part(a).

Hint: for implementing motion control: Construct a table similar to that shown in class. Call the function for constructing the table once from the init function. In your table, add an extra column for the segment number (which was variable i in the Uniform B-Spline notes). When drawing in segment 0, use points 0, 1, 2, and 3; when drawing in segment 1, use points 1, 2, 3, and 4; etc. To initialize the table, fill in say 20 evenly spaced u values between 0 and 1 for segment 0, then repeat for each of the other segments. A GetParameters function for the table can be provided that, given an arc length, returns the estimated values for the segment number i and the fraction u.

Alternate hint: instead of having a separate integer segment number i and floating point u value, combine them into a single floating point number. Put this number in the table instead of a u value. For example, let a value of 3.72 represent segment 3 and u = 0.72. Using this idea, no extra column is needed in the table, interpolation code is simplified, and the GetParameters function only needs to return a single value. However, you will need to break the value back into i and u components.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

Describe the team dynamics at Facebook.

Answered: 1 week ago