Torque3D Documentation / _generateds / afxCurveEval.cpp

afxCurveEval.cpp

Engine/source/afx/util/afxCurveEval.cpp

More...

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include "afx/arcaneFX.h"
 28#include "afx/util/afxCurveEval.h"
 29
 30Point2F afxHermiteEval::evaluateCurve( Point2F &v0, Point2F &v1,
 31                                         Point2F &t0, Point2F &t1, F32 t )
 32{
 33  F32 t_3 = t*t*t;
 34  F32 t_2 = t*t;
 35  F32 h1 = ( 2.0f * t_3 ) - ( 3.0f * t_2 ) + 1;
 36  F32 h2 = (-2.0f * t_3 ) + ( 3.0f * t_2 );
 37  F32 h3 = t_3 - ( 2.0f * t_2 ) + t;
 38  F32 h4 = t_3 - t_2;
 39
 40  Point2F v( 
 41    (h1*v0.x)+(h2*v1.x)+(h3*t0.x)+(h4*t1.x),
 42    (h1*v0.y)+(h2*v1.y)+(h3*t0.y)+(h4*t1.y) );
 43
 44  return v;
 45}
 46
 47Point2F afxHermiteEval::evaluateCurve( Point2F &v0, Point2F &v1, F32 t )
 48{
 49  Point2F tangent( 1, 0 );
 50  return( evaluateCurve( v0, v1, tangent, tangent, t ) );
 51}
 52
 53Point2F afxHermiteEval::evaluateCurveTangent( Point2F &v0, Point2F &v1,
 54                                                Point2F &t0, Point2F &t1, F32 t )
 55{
 56  F32 t_2 = t*t;
 57  F32 h1_der = ( 6.0f * t_2 ) - ( 6.0f * t );
 58  F32 h2_der = (-6.0f * t_2 ) + ( 6.0f * t );
 59  F32 h3_der = ( 3.0f * t_2 ) - ( 4.0f * t ) + 1;
 60  F32 h4_der = ( 3.0f * t_2 ) - ( 2.0f * t );
 61
 62  Point2F tangent( 
 63    (h1_der*v0.x)+(h2_der*v1.x)+(h3_der*t0.x)+(h4_der*t1.x),
 64    (h1_der*v0.y)+(h2_der*v1.y)+(h3_der*t0.y)+(h4_der*t1.y) );
 65
 66  return tangent;
 67}
 68
 69Point2F afxHermiteEval::evaluateCurveTangent( Point2F &v0, Point2F &v1, F32 t )
 70{
 71  Point2F tangent( 1, 0 );
 72  return( evaluateCurveTangent( v0, v1, tangent, tangent, t ) );
 73}
 74
 75Point3F afxHermiteEval::evaluateCurve( Point3F &v0, Point3F &v1,
 76                                         Point3F &t0, Point3F &t1, F32 t )
 77{
 78  F32 t_3 = t*t*t;
 79  F32 t_2 = t*t;
 80  F32 h1 = ( 2.0f * t_3 ) - ( 3.0f * t_2 ) + 1;
 81  F32 h2 = (-2.0f * t_3 ) + ( 3.0f * t_2 );
 82  F32 h3 = t_3 - ( 2.0f * t_2 ) + t;
 83  F32 h4 = t_3 - t_2;
 84
 85  Point3F v( 
 86    (h1*v0.x)+(h2*v1.x)+(h3*t0.x)+(h4*t1.x),
 87    (h1*v0.y)+(h2*v1.y)+(h3*t0.y)+(h4*t1.y),
 88    (h1*v0.z)+(h2*v1.z)+(h3*t0.z)+(h4*t1.z) );
 89
 90  return v;
 91}
 92
 93Point3F afxHermiteEval::evaluateCurve( Point3F &v0, Point3F &v1, F32 t )
 94{
 95  Point3F tangent( 1, 0, 0 );
 96  return( evaluateCurve( v0, v1, tangent, tangent, t ) );
 97}
 98
 99Point3F afxHermiteEval::evaluateCurveTangent( Point3F &v0, Point3F &v1,
100                                                Point3F &t0, Point3F &t1, F32 t )
101{
102  F32 t_2 = t*t;
103  F32 h1_der = ( 6.0f * t_2 ) - ( 6.0f * t );
104  F32 h2_der = (-6.0f * t_2 ) + ( 6.0f * t );
105  F32 h3_der = ( 3.0f * t_2 ) - ( 4.0f * t ) + 1;
106  F32 h4_der = ( 3.0f * t_2 ) - ( 2.0f * t );
107
108  Point3F tangent( 
109    (h1_der*v0.x)+(h2_der*v1.x)+(h3_der*t0.x)+(h4_der*t1.x),
110    (h1_der*v0.y)+(h2_der*v1.y)+(h3_der*t0.y)+(h4_der*t1.y),
111    (h1_der*v0.z)+(h2_der*v1.z)+(h3_der*t0.z)+(h4_der*t1.z) );
112
113  return tangent;
114}
115
116Point3F afxHermiteEval::evaluateCurveTangent( Point3F &v0, Point3F &v1, F32 t )
117{
118  Point3F tangent( 1, 0, 0 );
119  return( evaluateCurveTangent( v0, v1, tangent, tangent, t ) );
120}
121
122//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
123
124