Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Matrix.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, The Cinder Project: http://libcinder.org All rights reserved.
3  This code is intended for use with the Cinder C++ library: http://libcinder.org
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 
24 #pragma once
25 
26 #include "cinder/Cinder.h"
27 #include "cinder/CinderMath.h"
28 #include "cinder/Matrix22.h"
29 #include "cinder/MatrixAffine2.h"
30 #include "cinder/Matrix33.h"
31 #include "cinder/Matrix44.h"
32 #include "cinder/MatrixAlgo.h"
33 
34 namespace cinder {
35 
37 // Parallel Transport Frames
38 //
39 // These methods compute a set of reference frames, defined by their
40 // transformation matrix, along a curve. It is designed so that the
41 // array of points and the array of matrices used to fetch these routines
42 // don't need to be ordered as the curve.
43 //
44 // A typical usage would be :
45 //
46 // m[0] = Imath::firstFrame( p[0], p[1], p[2] );
47 // for( int i = 1; i < n - 1; i++ )
48 // {
49 // m[i] = Imath::nextFrame( m[i-1], p[i-1], p[i], t[i-1], t[i] );
50 // }
51 // m[n-1] = Imath::lastFrame( m[n-2], p[n-2], p[n-1] );
52 //
53 // See Graphics Gems I for the underlying algorithm.
54 // These are also called Parallel Transport Frames
55 // see Game Programming Gems 2, Section 2.5
56 
57 // Vec3
58 template< typename T >
59 Matrix44<T> firstFrame(
60  const Vec3<T> &firstPoint,
61  const Vec3<T> &secondPoint,
62  const Vec3<T> &thirdPoint
63 );
64 
65 template< typename T >
66 Matrix44<T> nextFrame(
67  const Matrix44<T> &prevMatrix,
68  const Vec3<T> &prevPoint,
69  const Vec3<T> &curPoint,
70  Vec3<T> &prevTangent,
71  Vec3<T> &curTangent
72 );
73 
74 template< typename T >
75 Matrix44<T> lastFrame(
76  const Matrix44<T> &prevMatrix,
77  const Vec3<T> &prevPoint,
78  const Vec3<T> &lastPoint
79 );
80 
81 // Vec4
82 template< typename T >
84  const Vec4<T> &firstPoint,
85  const Vec4<T> &secondPoint,
86  const Vec4<T> &thirdPoint
87 )
88 {
89  return firstFrame( firstPoint.xyz(), secondPoint.xyz(), thirdPoint.xyz() );
90 }
91 
92 template< typename T >
94  const Matrix44<T> &prevMatrix,
95  const Vec4<T> &prevPoint,
96  const Vec4<T> &curPoint,
97  Vec4<T> &prevTangent,
98  Vec4<T> &curTangent
99 )
100 {
101  Vec3<T> aPrevTangent = prevTangent.xyz();
102  Vec3<T> aCurTangent = curTangent.xyz();
103  return nextFrame( prevMatrix, prevPoint.xyz(), curPoint.xyz(), aPrevTangent, aCurTangent );
104 }
105 
106 template< typename T >
108  const Matrix44<T> &prevMatrix,
109  const Vec4<T> &prevPoint,
110  const Vec4<T> &lastPoint
111 )
112 {
113  return lastFrame( prevMatrix, prevPoint.xyz(), lastPoint.xyz() );
114 }
115 
116 } // namespace cinder
Matrix44< T > nextFrame(const Matrix44< T > &prevMatrix, const Vec3< T > &prevPoint, const Vec3< T > &curPoint, Vec3< T > &prevTangent, Vec3< T > &curTangent)
Definition: Matrix.cpp:77
Matrix44< T > lastFrame(const Matrix44< T > &prevMatrix, const Vec3< T > &prevPoint, const Vec3< T > &lastPoint)
Definition: Matrix.cpp:127
Definition: Vector.h:691
Definition: Vector.h:65
Vec3< T > xyz() const
Definition: Vector.h:973
Definition: Matrix44.h:41
Matrix44< T > firstFrame(const Vec3< T > &firstPoint, const Vec3< T > &secondPoint, const Vec3< T > &thirdPoint)
Definition: Matrix.cpp:37