RavEngine
Loading...
Searching...
No Matches
PxVehicleMaths.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#pragma once
34#include "foundation/PxSimpleTypes.h"
35#include "foundation/PxMemory.h"
36
37#include "PxVehicleLimits.h"
38
39#if !PX_DOXYGEN
40namespace physx
41{
42namespace vehicle2
43{
44#endif
45
47{
48public:
49 enum
50 {
51 eMAX_SIZE = PxVehicleLimits::eMAX_NB_WHEELS + 3
52 };
53
54 PxVehicleVectorN(const PxU32 size)
55 : mSize(size)
56 {
57 PX_ASSERT(mSize <= PxVehicleVectorN::eMAX_SIZE);
58 PxMemZero(mValues, sizeof(PxReal)*PxVehicleVectorN::eMAX_SIZE);
59 }
60
62 {
63 }
64
66 {
67 for (PxU32 i = 0; i < src.mSize; i++)
68 {
69 mValues[i] = src.mValues[i];
70 }
71 mSize = src.mSize;
72 }
73
75 {
76 for (PxU32 i = 0; i < src.mSize; i++)
77 {
78 mValues[i] = src.mValues[i];
79 }
80 mSize = src.mSize;
81 return *this;
82 }
83
84 PX_FORCE_INLINE PxReal& operator[] (const PxU32 i)
85 {
86 PX_ASSERT(i < mSize);
87 return (mValues[i]);
88 }
89
90 PX_FORCE_INLINE const PxReal& operator[] (const PxU32 i) const
91 {
92 //PX_ASSERT(i < mSize);
93 return (mValues[i]);
94 }
95
96 PX_FORCE_INLINE PxU32 getSize() const { return mSize; }
97
98private:
99
100 PxReal mValues[PxVehicleVectorN::eMAX_SIZE];
101 PxU32 mSize;
102};
103
105{
106public:
107
109 : mSize(0)
110 {
111 }
112
113 PxVehicleMatrixNN(const PxU32 size)
114 : mSize(size)
115 {
116 PX_ASSERT(mSize <= PxVehicleVectorN::eMAX_SIZE);
117 PxMemZero(mValues, sizeof(PxReal)*PxVehicleVectorN::eMAX_SIZE*PxVehicleVectorN::eMAX_SIZE);
118 }
119
121 {
122 for (PxU32 i = 0; i < src.mSize; i++)
123 {
124 for (PxU32 j = 0; j < src.mSize; j++)
125 {
126 mValues[i][j] = src.mValues[i][j];
127 }
128 }
129 mSize = src.mSize;
130 }
131
133 {
134 }
135
137 {
138 for (PxU32 i = 0; i < src.mSize; i++)
139 {
140 for (PxU32 j = 0; j < src.mSize; j++)
141 {
142 mValues[i][j] = src.mValues[i][j];
143 }
144 }
145 mSize = src.mSize;
146 return *this;
147 }
148
149 PX_FORCE_INLINE PxReal get(const PxU32 i, const PxU32 j) const
150 {
151 PX_ASSERT(i < mSize);
152 PX_ASSERT(j < mSize);
153 return mValues[i][j];
154 }
155
156 PX_FORCE_INLINE void set(const PxU32 i, const PxU32 j, const PxReal val)
157 {
158 PX_ASSERT(i < mSize);
159 PX_ASSERT(j < mSize);
160 mValues[i][j] = val;
161 }
162
163 PX_FORCE_INLINE PxU32 getSize() const { return mSize; }
164
165 PX_FORCE_INLINE void setSize(const PxU32 size)
166 {
167 PX_ASSERT(size <= PxVehicleVectorN::eMAX_SIZE);
168 mSize = size;
169 }
170
171public:
172
173 PxReal mValues[PxVehicleVectorN::eMAX_SIZE][PxVehicleVectorN::eMAX_SIZE];
174 PxU32 mSize;
175};
176
177
178/*
179 LUPQ decomposition
180
181 Based upon "Outer Product LU with Complete Pivoting," from Matrix Computations (4th Edition), Golub and Van Loan
182
183 Solve A*x = b using:
184
185 MatrixNNLUSolver solver;
186 solver.decomposeLU(A);
187 solver.solve(b, x);
188*/
190{
191private:
192
194 PxU32 mP[PxVehicleVectorN::eMAX_SIZE - 1]; // Row permutation
195 PxU32 mQ[PxVehicleVectorN::eMAX_SIZE - 1]; // Column permutation
196 PxReal mDetM;
197
198public:
199
202
203 PxReal getDet() const { return mDetM; }
204
205 void decomposeLU(const PxVehicleMatrixNN& A);
206
207 //Given a matrix A and a vector b find x that satisfies Ax = b, where the matrix A is the matrix that was passed to #decomposeLU.
208 //Returns true if the lu decomposition indicates that the matrix has an inverse and x was successfully computed.
209 //Returns false if the lu decomposition resulted in zero determinant ie the matrix has no inverse and no solution exists for x.
210 //Returns false if the size of either b or x doesn't match the size of the matrix passed to #decomposeLU.
211 //If false is returned then each relevant element of x is set to zero.
212 bool solve(const PxVehicleVectorN& b, PxVehicleVectorN& x) const;
213};
214
215
217{
218public:
219
220 void solve(const PxU32 maxIterations, const PxReal tolerance, const PxVehicleMatrixNN& A, const PxVehicleVectorN& b, PxVehicleVectorN& result) const;
221};
222
224{
225public:
226
227 bool solve(const PxVehicleMatrixNN& A_, const PxVehicleVectorN& b_, PxVehicleVectorN& result) const;
228};
229
230#if !PX_DOXYGEN
231} //namespace vehicle2
232} //namespace physx
233#endif
234
Definition PxVehicleMaths.h:224
Definition PxVehicleMaths.h:190
Definition PxVehicleMaths.h:105
Definition PxVehicleMaths.h:47
#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
PX_FORCE_INLINE void * PxMemZero(void *dest, PxU32 count)
Sets the bytes of the provided buffer to zero.
Definition PxMemory.h:53