RavEngine
Loading...
Searching...
No Matches
DySpatial.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef DY_SPATIAL_H
30#define DY_SPATIAL_H
31
32#include "foundation/PxVec3.h"
33#include "foundation/PxTransform.h"
34#include "CmSpatialVector.h"
35
36namespace physx
37{
38namespace Dy
39{
40// translate a motion resolved at position p to the origin
41
42
43// should have a 'from' frame and a 'to' frame
45{
46public:
47 SpInertia() {}
48
49 SpInertia(const PxMat33& ll, const PxMat33& la, const PxMat33& aa): mLL(ll), mLA(la), mAA(aa)
50 {
51 }
52
53 static SpInertia getZero()
54 {
55 return SpInertia(PxMat33(PxZero), PxMat33(PxZero),
56 PxMat33(PxZero));
57 }
58
59 static SpInertia dyad(const Cm::SpatialVector& column, const Cm::SpatialVector& row)
60 {
61 return SpInertia(dyad(column.linear, row.linear),
62 dyad(column.linear, row.angular),
63 dyad(column.angular, row.angular));
64 }
65
66
67 static SpInertia inertia(PxReal mass, const PxVec3& inertia)
68 {
69 return SpInertia(PxMat33::createDiagonal(PxVec3(mass,mass,mass)), PxMat33(PxZero),
71 }
72
73
74 SpInertia operator+(const SpInertia& m) const
75 {
76 return SpInertia(mLL+m.mLL, mLA+m.mLA, mAA+m.mAA);
77 }
78
79 SpInertia operator-(const SpInertia& m) const
80 {
81 return SpInertia(mLL-m.mLL, mLA-m.mLA, mAA-m.mAA);
82 }
83
84 SpInertia operator*(PxReal r) const
85 {
86 return SpInertia(mLL*r, mLA*r, mAA*r);
87 }
88
89 void operator+=(const SpInertia& m)
90 {
91 mLL+=m.mLL;
92 mLA+=m.mLA;
93 mAA+=m.mAA;
94 }
95
96 void operator-=(const SpInertia& m)
97 {
98 mLL-=m.mLL;
99 mLA-=m.mLA;
100 mAA-=m.mAA;
101 }
102
103
104 PX_FORCE_INLINE Cm::SpatialVector operator *(const Cm::SpatialVector& v) const
105 {
106 return Cm::SpatialVector(mLL*v.linear +mLA*v.angular,
107 mLA.transformTranspose(v.linear)+mAA*v.angular);
108 }
109
110 SpInertia operator *(const SpInertia& v) const
111 {
112 return SpInertia(mLL*v.mLL + mLA * v.mLA.getTranspose(),
113 mLL*v.mLA + mLA * v.mAA,
114 mLA.getTranspose()*v.mLA + mAA * v.mAA);
115 }
116
117
118 bool isFinite() const
119 {
120 return true;
121// return mLL.isFinite() && mLA.isFinite() && mAA.isFinite();
122 }
123
124 PxMat33 mLL, mLA; // linear force from angular motion, linear force from linear motion
125 PxMat33 mAA; // angular force from angular motion, mAL = mLA.transpose()
126
127private:
128 static PxMat33 dyad(PxVec3 col, PxVec3 row)
129 {
130 return PxMat33(col*row.x, col*row.y, col*row.z);
131 }
132
133
134};
135
136}
137}
138
139#endif
Definition CmSpatialVector.h:46
Definition DySpatial.h:45
PX_CUDA_CALLABLE static PX_INLINE const PxMat33T createDiagonal(const PxVec3T< float > &d)
Construct from diagonal, off-diagonals are zero.
Definition PxMat33.h:186
3x3 matrix class
Definition PxMat33.h:91
PX_CUDA_CALLABLE PX_INLINE const PxVec3 transformTranspose(const PxVec3 &other) const
Transform vector by matrix transpose, v' = M^t*v.
Definition PxMat33.h:332
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat33 getTranspose() const
Get transposed matrix.
Definition PxMat33.h:190
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39