Torque3D Documentation / _generateds / mPlaneTransformer.cpp

mPlaneTransformer.cpp

Engine/source/math/mPlaneTransformer.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/mPlaneTransformer.h"
25#include "math/mMathFn.h"
26
27void PlaneTransformer::set(const MatrixF& xform, const Point3F& scale)
28{
29   mTransform = xform;
30   mScale     = scale;
31
32   MatrixF scaleMat(true);
33   F32* m = scaleMat;
34   m[MatrixF::idx(0, 0)] = scale.x;
35   m[MatrixF::idx(1, 1)] = scale.y;
36   m[MatrixF::idx(2, 2)] = scale.z;
37
38   mTransposeInverse = xform;
39   mTransposeInverse.mul(scaleMat);
40   mTransposeInverse.transpose();
41   mTransposeInverse.inverse();
42}
43
44void PlaneTransformer::transform(const PlaneF& plane, PlaneF& result)
45{
46   Point3F point = plane;
47   point *= -plane.d;
48   point.convolve(mScale);
49   mTransform.mulP(point);
50
51   Point3F normal = plane;
52   mTransposeInverse.mulV(normal);
53
54   result.set(point, normal);
55//   mTransformPlane(mTransform, mScale, plane, &result);
56}
57
58void PlaneTransformer::setIdentity()
59{
60   static struct MakeIdentity
61   {
62      PlaneTransformer  transformer;
63      MakeIdentity()
64      {
65         MatrixF  defMat(true);
66         Point3F  defScale(1.0f, 1.0f, 1.0f);
67         transformer.set(defMat, defScale);
68      }
69   } sMakeIdentity;
70
71   *this = sMakeIdentity.transformer;
72}
73