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:
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.
/**
* bezier_path.js, By Wayne Brown, Fall 2017
*/
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 C. Wayne Brown
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
"use strict";
/**------------------------------------------------------------------------
* Store and manipulate a path defined by 4 control points.
* @param control_points {Array} of GlPoint4 locations
* @param start_frame {number} the frame that starts the path animation
* @param end_frame {number} the frame that ends the path animation
* @constructor
*/
window.BezierOrientationPath = function (control_points, start_frame, end_frame) {
// Constructor
let self = this;
// Objects needed for internal elements and calculations
let P = new GlPoint4();
let V = new GlVector3();
// The points that define the path
let p0 = control_points[0];
let p1 = control_points[1];
/**
* bezier_scene.js, By Wayne Brown, Fall 2017
*/
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 C. Wayne Brown
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
"use strict";
/** -----------------------------------------------------------------------
* Create a WebGL 3D scene, store its state, and render its models.
*
* @param id {string} The id of the webglinteractive directive
* @param download {SceneDownload} An instance of the SceneDownload class
* @param vshaders_dictionary {object} A dictionary of vertex shaders.
* @param fshaders_dictionary {object} A dictionary of fragment shaders.
* @param models {object} A dictionary of models.
* @constructor
*/
window.BezierOrientationScene = function (id, download, vshaders_dictionary,
fshaders_dictionary, models) {
// Private variables
let self = this;
let my_canvas = null;
let gl = null;
let program = null;
Use a parametric equation to calculate points along a path.
Intermediate points influence acceleration and deceleration.
speed : ---
acceleration : ---
frames per second : ---
current frame 0 : 0 120
animation: start frame: end frame:
Show path
Scale <p1-p0> 1.0 : 0.0 3.0
---
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¶
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.
u
and n
are known, how can v
be calculated.