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/MatrixAffine2.h" 00030 #include "cinder/Matrix33.h" 00031 #include "cinder/Matrix44.h" 00032 #include "cinder/MatrixAlgo.h" 00033 00034 namespace cinder { 00035 00037 // Parallel Transport Frames 00038 // 00039 // These methods compute a set of reference frames, defined by their 00040 // transformation matrix, along a curve. It is designed so that the 00041 // array of points and the array of matrices used to fetch these routines 00042 // don't need to be ordered as the curve. 00043 // 00044 // A typical usage would be : 00045 // 00046 // m[0] = Imath::firstFrame( p[0], p[1], p[2] ); 00047 // for( int i = 1; i < n - 1; i++ ) 00048 // { 00049 // m[i] = Imath::nextFrame( m[i-1], p[i-1], p[i], t[i-1], t[i] ); 00050 // } 00051 // m[n-1] = Imath::lastFrame( m[n-2], p[n-2], p[n-1] ); 00052 // 00053 // See Graphics Gems I for the underlying algorithm. 00054 // These are also called Parallel Transport Frames 00055 // see Game Programming Gems 2, Section 2.5 00056 00057 // Vec3 00058 template< typename T > 00059 Matrix44<T> firstFrame( 00060 const Vec3<T> &firstPoint, 00061 const Vec3<T> &secondPoint, 00062 const Vec3<T> &thirdPoint 00063 ); 00064 00065 template< typename T > 00066 Matrix44<T> nextFrame( 00067 const Matrix44<T> &prevMatrix, 00068 const Vec3<T> &prevPoint, 00069 const Vec3<T> &curPoint, 00070 Vec3<T> &prevTangent, 00071 Vec3<T> &curTangent 00072 ); 00073 00074 template< typename T > 00075 Matrix44<T> lastFrame( 00076 const Matrix44<T> &prevMatrix, 00077 const Vec3<T> &prevPoint, 00078 const Vec3<T> &lastPoint 00079 ); 00080 00081 // Vec4 00082 template< typename T > 00083 Matrix44<T> firstFrame( 00084 const Vec4<T> &firstPoint, 00085 const Vec4<T> &secondPoint, 00086 const Vec4<T> &thirdPoint 00087 ) 00088 { 00089 return firstFrame( firstPoint.xyz(), secondPoint.xyz(), thirdPoint.xyz() ); 00090 } 00091 00092 template< typename T > 00093 Matrix44<T> nextFrame( 00094 const Matrix44<T> &prevMatrix, 00095 const Vec4<T> &prevPoint, 00096 const Vec4<T> &curPoint, 00097 Vec4<T> &prevTangent, 00098 Vec4<T> &curTangent 00099 ) 00100 { 00101 Vec3<T> aPrevTangent = prevTangent.xyz(); 00102 Vec3<T> aCurTangent = curTangent.xyz(); 00103 return nextFrame( prevMatrix, prevPoint.xyz(), curPoint.xyz(), aPrevTangent, aCurTangent ); 00104 } 00105 00106 template< typename T > 00107 Matrix44<T> lastFrame( 00108 const Matrix44<T> &prevMatrix, 00109 const Vec4<T> &prevPoint, 00110 const Vec4<T> &lastPoint 00111 ) 00112 { 00113 return lastFrame( prevMatrix, prevPoint.xyz(), lastPoint.xyz() ); 00114 } 00115 00116 } // namespace cinder