mSplinePatch.cpp
Engine/source/math/mSplinePatch.cpp
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/mSplinePatch.h" 25 26 27//****************************************************************************** 28// Spline control points 29//****************************************************************************** 30SplCtrlPts::SplCtrlPts() 31{ 32} 33 34//------------------------------------------------------------------------------ 35// Destructor 36//------------------------------------------------------------------------------ 37SplCtrlPts::~SplCtrlPts() 38{ 39} 40 41//------------------------------------------------------------------------------ 42// Get point 43//------------------------------------------------------------------------------ 44const Point3F * SplCtrlPts::getPoint( U32 pointNum ) 45{ 46 return &mPoints[pointNum]; 47} 48 49//------------------------------------------------------------------------------ 50// Set point 51//------------------------------------------------------------------------------ 52void SplCtrlPts::setPoint( Point3F &point, U32 pointNum ) 53{ 54 mPoints[pointNum] = point; 55} 56 57//------------------------------------------------------------------------------ 58// Add point 59//------------------------------------------------------------------------------ 60void SplCtrlPts::addPoint( Point3F &point ) 61{ 62 mPoints.push_back( point ); 63} 64 65//------------------------------------------------------------------------------ 66// Submit control points 67//------------------------------------------------------------------------------ 68void SplCtrlPts::submitPoints( Point3F *pts, U32 num ) 69{ 70 mPoints.clear(); 71 72 for( S32 i=0; i<num; i++ ) 73 { 74 mPoints.push_back( pts[i] ); 75 } 76} 77 78 79//****************************************************************************** 80// Spline patch - base class 81//****************************************************************************** 82SplinePatch::SplinePatch() 83{ 84 mNumReqControlPoints = 0; 85} 86 87//------------------------------------------------------------------------------ 88// This method is the only way to modify control points once they have been 89// submitted to the patch. This was done to make sure the patch has a chance 90// to re-calc any pre-calculated data it may be using from the submitted control 91// points. 92//------------------------------------------------------------------------------ 93void SplinePatch::setControlPoint( Point3F &point, S32 index ) 94{ 95 mControlPoints.setPoint( point, index ); 96} 97 98//------------------------------------------------------------------------------ 99// Calc point on spline using already submitted points 100//------------------------------------------------------------------------------ 101void SplinePatch::calc( F32 /*t*/, Point3F &result ) 102{ 103 result.x = result.y = result.z = 0.0f; 104} 105 106//------------------------------------------------------------------------------ 107// Calc point on spline using passed-in points 108//------------------------------------------------------------------------------ 109void SplinePatch::calc( Point3F * /*points*/, F32 /*t*/, Point3F &result ) 110{ 111 result.x = result.y = result.z = 0.0f; 112} 113