00001 /* 00002 Copyright (c) 2011, The Cinder Project: http://libcinder.org All rights reserved. 00003 This code is intended for use with the Cinder C++ library: http://libcinder.org 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 00024 #pragma once 00025 00026 #include "cinder/Cinder.h" 00027 #include "cinder/CinderMath.h" 00028 #include "cinder/Matrix22.h" 00029 #include "cinder/Matrix33.h" 00030 #include "cinder/Matrix44.h" 00031 #include "cinder/MatrixAlgo.h" 00032 00033 namespace cinder { 00034 00036 // Parallel Transport Frames 00037 // 00038 // These methods compute a set of reference frames, defined by their 00039 // transformation matrix, along a curve. It is designed so that the 00040 // array of points and the array of matrices used to fetch these routines 00041 // don't need to be ordered as the curve. 00042 // 00043 // A typical usage would be : 00044 // 00045 // m[0] = Imath::firstFrame( p[0], p[1], p[2] ); 00046 // for( int i = 1; i < n - 1; i++ ) 00047 // { 00048 // m[i] = Imath::nextFrame( m[i-1], p[i-1], p[i], t[i-1], t[i] ); 00049 // } 00050 // m[n-1] = Imath::lastFrame( m[n-2], p[n-2], p[n-1] ); 00051 // 00052 // See Graphics Gems I for the underlying algorithm. 00053 // These are also called Parallel Transport Frames 00054 // see Game Programming Gems 2, Section 2.5 00055 00056 // Vec3 00057 template< typename T > 00058 Matrix44<T> firstFrame( 00059 const Vec3<T> &firstPoint, 00060 const Vec3<T> &secondPoint, 00061 const Vec3<T> &thirdPoint 00062 ); 00063 00064 template< typename T > 00065 Matrix44<T> nextFrame( 00066 const Matrix44<T> &prevMatrix, 00067 const Vec3<T> &prevPoint, 00068 const Vec3<T> &curPoint, 00069 Vec3<T> &prevTangent, 00070 Vec3<T> &curTangent 00071 ); 00072 00073 template< typename T > 00074 Matrix44<T> lastFrame( 00075 const Matrix44<T> &prevMatrix, 00076 const Vec3<T> &prevPoint, 00077 const Vec3<T> &lastPoint 00078 ); 00079 00080 // Vec4 00081 template< typename T > 00082 Matrix44<T> firstFrame( 00083 const Vec4<T> &firstPoint, 00084 const Vec4<T> &secondPoint, 00085 const Vec4<T> &thirdPoint 00086 ) 00087 { 00088 return firstFrame( firstPoint.xyz(), secondPoint.xyz(), thirdPoint.xyz() ); 00089 } 00090 00091 template< typename T > 00092 Matrix44<T> nextFrame( 00093 const Matrix44<T> &prevMatrix, 00094 const Vec4<T> &prevPoint, 00095 const Vec4<T> &curPoint, 00096 Vec4<T> &prevTangent, 00097 Vec4<T> &curTangent 00098 ) 00099 { 00100 Vec3<T> aPrevTangent = prevTangent.xyz(); 00101 Vec3<T> aCurTangent = curTangent.xyz(); 00102 return nextFrame( prevMatrix, prevPoint.xyz(), curPoint.xyz(), aPrevTangent, aCurTangent ); 00103 } 00104 00105 template< typename T > 00106 Matrix44<T> lastFrame( 00107 const Matrix44<T> &prevMatrix, 00108 const Vec4<T> &prevPoint, 00109 const Vec4<T> &lastPoint 00110 ) 00111 { 00112 return lastFrame( prevMatrix, prevPoint.xyz(), lastPoint.xyz() ); 00113 } 00114 00115 } // namespace cinder