mQuadPatch.cpp

Engine/source/math/mQuadPatch.cpp

More...

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#include "math/mQuadPatch.h"
25
26
27//******************************************************************************
28// Quadratic spline patch
29//******************************************************************************
30QuadPatch::QuadPatch()
31{
32   setNumReqControlPoints(3);
33}
34
35//------------------------------------------------------------------------------
36//------------------------------------------------------------------------------
37void QuadPatch::calcABC( const Point3F *points )
38{
39   a = points[2] - points[1];
40   b = points[1] - points[0];
41   c = points[0];
42}
43
44
45//------------------------------------------------------------------------------
46//------------------------------------------------------------------------------
47void QuadPatch::submitControlPoints( SplCtrlPts &points )
48{
49   Parent::submitControlPoints( points );
50   calcABC( points.getPoint(0) );
51};
52
53
54//------------------------------------------------------------------------------
55//------------------------------------------------------------------------------
56void QuadPatch::setControlPoint( Point3F &point, S32 index )
57{
58   ( (SplCtrlPts*) getControlPoints() )->setPoint( point, index );
59   calcABC( getControlPoint(0) );
60}
61
62//------------------------------------------------------------------------------
63//------------------------------------------------------------------------------
64void QuadPatch::calc( F32 t, Point3F &result )
65{
66   F32 t2 = t*t;
67   result = a*t2 + b*t + c;
68}
69
70
71//------------------------------------------------------------------------------
72//------------------------------------------------------------------------------
73void QuadPatch::calc( Point3F *points, F32 t, Point3F &result )
74{
75   calcABC( points );
76   calc( t, result );
77}
78