RavEngine
Loading...
Searching...
No Matches
ExtQuadric.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
27#ifndef EXT_QUADRIC_H
28#define EXT_QUADRIC_H
29
30#include "foundation/PxVec3.h"
31
32// MM: used in ExtMeshSimplificator
33// see paper Garland and Heckbert: "Surface Simplification Using Quadric Error Metrics"
34
35namespace physx
36{
37 namespace Ext
38 {
39 class Quadric {
40 public:
41 PX_FORCE_INLINE void zero()
42 {
43 a00 = 0.0f; a01 = 0.0f; a02 = 0.0f; a03 = 0.0f;
44 a11 = 0.0f; a12 = 0.0f; a13 = 0.0f;
45 a22 = 0.0f; a23 = 0.0f;
46 a33 = 0.0f;
47 }
48
49 PX_FORCE_INLINE void setFromPlane(const PxVec3& v0, const PxVec3& v1, const PxVec3& v2)
50 {
51 PxVec3 n = (v1 - v0).cross(v2 - v0); n.normalize();
52 float d = -n.dot(v0);
53 a00 = n.x * n.x; a01 = n.x * n.y; a02 = n.x * n.z; a03 = n.x * d;
54 a11 = n.y * n.y; a12 = n.y * n.z; a13 = n.y * d;
55 a22 = n.z * n.z; a23 = n.z * d;
56 a33 = d * d;
57 }
58
59 PX_FORCE_INLINE Quadric operator +(const Quadric& q) const
60 {
61 Quadric sum;
62 sum.a00 = a00 + q.a00; sum.a01 = a01 + q.a01; sum.a02 = a02 + q.a02; sum.a03 = a03 + q.a03;
63 sum.a11 = a11 + q.a11; sum.a12 = a12 + q.a12; sum.a13 = a13 + q.a13;
64 sum.a22 = a22 + q.a22; sum.a23 = a23 + q.a23;
65 sum.a33 = a33 + q.a33;
66 return sum;
67 }
68
69 void operator +=(const Quadric& q)
70 {
71 a00 += q.a00; a01 += q.a01; a02 += q.a02; a03 += q.a03;
72 a11 += q.a11; a12 += q.a12; a13 += q.a13;
73 a22 += q.a22; a23 += q.a23;
74 a33 += q.a33;
75 }
76
77 PxF32 outerProduct(const PxVec3& v)
78 {
79 return a00 * v.x * v.x + 2.0f * a01 * v.x * v.y + 2.0f * a02 * v.x * v.z + 2.0f * a03 * v.x +
80 a11 * v.y * v.y + 2.0f * a12 * v.y * v.z + 2.0f * a13 * v.y +
81 a22 * v.z * v.z + 2.0f * a23 * v.z + a33;
82 }
83 private:
84 PxF32 a00, a01, a02, a03;
85 PxF32 a11, a12, a13;
86 PxF32 a22, a23;
87 PxF32 a33;
88
89 };
90 }
91}
92
93#endif
Definition ExtQuadric.h:39
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