8.7 - Bezier Path Orientation

Consider a race car speeding around a race track. Not only is the car changing location, it is also changing orientation as it follows the race track. The speed of an object along a Bezier defined curve is a vector which has a magnitude and a direction. We can use the direction of the speed vector to control the orientation of an object as it follows the path.

Every object has a local coordinate system that is defined by three orthogonal axes. The speed vector of a Bezier parametric equation can be used to set one of the axes of a local coordinate system. To solve for the other two axes we need one more vector, which must be arbitrarily specified by an animator. Please note that this was also true of a virtual camera. To calculate a local coordinate system for a camera we made the animator specify which direction was “up”.

With reference to lesson 7.6, if we know the desired orientation and location of an object, the transformation matrix needed to place the object in the scene is straightforward: the local coordinate system axes become the first three columns, while the location fills in the fourth column like this:

ux
uy
uz
0
vx
vy
vz
0
nx
ny
nz
0
tx
ty
tz
1
Eq1

where the vector, <ux,uy,uz> is “to the right” of the object, the vector, <vx,vy,vz>, is pointing “up”, and the vector, <nx,ny,nz> is pointing away from the “front” of the object.

The following WebGL program modifies the orientation of a model based on the direction of the path’s speed vector. We arbitrarily align the speed vector with the n axis of the local coordinate system and specify that the “up direction” is in the y-axis direction. The local coordinate system is calculated by taking cross-products of these vectors to create three orthogonal axes. The location is calculated from the Bezier equation. Please experiment with the following WebGL program and study the code.

Show: Code   Canvas   Run Info
 
1
/**
2
 * bezier_path.js, By Wayne Brown, Fall 2017
3
 */
4
5
/**
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2015 C. Wayne Brown
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 */
28
29
"use strict";
30
31
/**------------------------------------------------------------------------
32
* Store and manipulate a path defined by 4 control points.
33
* @param control_points {Array} of GlPoint4 locations
34
* @param start_frame {number} the frame that starts the path animation
35
* @param end_frame {number} the frame that ends the path animation
36
* @constructor
37
*/
38
window.BezierOrientationPath = function (control_points, start_frame, end_frame) {
39
40
  // Constructor
41
  let self = this;
42
43
  // Objects needed for internal elements and calculations
44
  let P = new GlPoint4();
45
  let V = new GlVector3();
46
47
  // The points that define the path
48
  let p0 = control_points[0];
49
  let p1 = control_points[1];
234
 
1
/**
2
 * bezier_scene.js, By Wayne Brown, Fall 2017
3
 */
4
5
/**
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2015 C. Wayne Brown
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 */
28
29
"use strict";
30
31
/** -----------------------------------------------------------------------
32
 * Create a WebGL 3D scene, store its state, and render its models.
33
 *
34
 * @param id {string} The id of the webglinteractive directive
35
 * @param download {SceneDownload} An instance of the SceneDownload class
36
 * @param vshaders_dictionary {object} A dictionary of vertex shaders.
37
 * @param fshaders_dictionary {object} A dictionary of fragment shaders.
38
 * @param models {object} A dictionary of models.
39
 * @constructor
40
 */
41
window.BezierOrientationScene = function (id, download, vshaders_dictionary,
42
                                fshaders_dictionary, models) {
43
44
  // Private variables
45
  let self = this;
46
  let my_canvas = null;
47
48
  let gl = null;
49
  let program = null;
../_static/08_bezier_orientation/bezier_orientation.html

Use a parametric equation to calculate points along a path.
Intermediate points influence acceleration and deceleration.

Calculated Animation Properties:
speed : ---
acceleration : ---
frames per second : ---
Please use a browser that supports "canvas"

Timing:
current frame 0 : 0 120
animation: start frame: end frame:
Control Points:
Show path
Scale <p1-p0> 1.0 : 0.0 3.0
---

Open this webgl program in a new tab or window

Summary

The first derivative of the Bezier equation produces a speed vector. This vector can be used to define a local coordinate system that aligns the animated model with the path of motion.

Glossary

Bezier parametric equation
A function of one variable, t, that calculates changes along a “path”.
Speed vector
The first derivative of an equation of motion. Speed always has a direction and a magnitude.

Self Assessment

Q-193: The names u, v and n are used to define a local coordinate system for an object (either a model or a camera.) In reference to the object, which direction does the u vector point.




Q-194: If u and n are known, how can v be calculated.





Q-195: How can you make an object move more slowly along a path – without changing the path’s location?





Next Section - 8.8 - Chained Bezier Paths