RavEngine
Loading...
Searching...
No Matches
VoxelMap.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 VOXEL_MAP_H
30#define VOXEL_MAP_H
31
32#include "PxPhysicsAPI.h"
33
34/*
35VoxelMap inherits physx::PxCustomGeometry::Callbacks interface and provides
36implementations for 5 callback functions:
37
38- getLocalBounds
39- generateContacts
40- raycast
41- overlap
42- sweep
43
44It should be passed to PxCustomGeometry constructor.
45
46*/
48{
49 void setDimensions(int x, int y, int z);
50 int dimX() const;
51 int dimY() const;
52 int dimZ() const;
53
54 void setVoxelSize(float x, float y, float z);
55 const physx::PxVec3& voxelSize() const;
56 float voxelSizeX() const;
57 float voxelSizeY() const;
58 float voxelSizeZ() const;
59
60 physx::PxVec3 extents() const;
61
62 void setVoxel(int x, int y, int z, bool yes = true);
63
64 bool voxel(int x, int y, int z) const;
65
66 void clearVoxels();
67
68 void setFloorVoxels(int layers);
69
70 void setWaveVoxels();
71
72 void voxelize(const physx::PxGeometry& geom, const physx::PxTransform& pose, bool add = true);
73
74 physx::PxVec3 voxelPos(int x, int y, int z) const;
75
76 void pointCoords(const physx::PxVec3& p, int& x, int& y, int& z) const;
77
78 void getVoxelRegion(const physx::PxBounds3& b, int& sx, int& sy, int& sz, int& ex, int& ey, int& ez) const;
79
80 // physx::PxCustomGeometry::Callbacks overrides
81
84 virtual bool generateContacts(const physx::PxGeometry& geom0, const physx::PxGeometry& geom1, const physx::PxTransform& pose0, const physx::PxTransform& pose1,
85 const physx::PxReal contactDistance, const physx::PxReal meshContactMargin, const physx::PxReal toleranceLength,
86 physx::PxContactBuffer& contactBuffer) const;
87 virtual physx::PxU32 raycast(const physx::PxVec3& origin, const physx::PxVec3& unitDir, const physx::PxGeometry& geom, const physx::PxTransform& pose,
88 physx::PxReal maxDist, physx::PxHitFlags hitFlags, physx::PxU32 maxHits, physx::PxGeomRaycastHit* rayHits, physx::PxU32 stride, physx::PxRaycastThreadContext*) const;
89 virtual bool overlap(const physx::PxGeometry& geom0, const physx::PxTransform& pose0, const physx::PxGeometry& geom1, const physx::PxTransform& pose1, physx::PxOverlapThreadContext*) const;
90 virtual bool sweep(const physx::PxVec3& unitDir, const physx::PxReal maxDist,
91 const physx::PxGeometry& geom0, const physx::PxTransform& pose0, const physx::PxGeometry& geom1, const physx::PxTransform& pose1,
92 physx::PxGeomSweepHit& sweepHit, physx::PxHitFlags hitFlags, const physx::PxReal inflation, physx::PxSweepThreadContext*) const;
93 virtual void visualize(const physx::PxGeometry&, physx::PxRenderOutput&, const physx::PxTransform&, const physx::PxBounds3&) const;
95 virtual bool usePersistentContactManifold(const physx::PxGeometry&, physx::PxReal&) const { return true; }
96
97private:
98
99 int pacsX() const;
100 int pacsY() const;
101 int pacsZ() const;
102
103 int m_dimensions[3];
104 physx::PxVec3 m_voxelSize;
106};
107
108#endif
Definition PxArray.h:53
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Definition PxContactBuffer.h:42
A geometry object.
Definition PxGeometry.h:79
Utility class to compute and manipulate mass and inertia tensor properties.
Definition PxMassProperties.h:65
Definition PxRenderOutput.h:50
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define DECLARE_CUSTOM_GEOMETRY_TYPE
Used in pair with IMPLEMENT_CUSTOM_GEOMETRY_TYPE to overwrite Callbacks::getCustomType() callback.
Definition PxCustomGeometry.h:291
Definition VoxelMap.h:48
virtual void computeMassProperties(const physx::PxGeometry &, physx::PxMassProperties &) const
Compute custom geometry mass properties. For geometries usable with dynamic rigidbodies.
Definition VoxelMap.h:94
virtual DECLARE_CUSTOM_GEOMETRY_TYPE physx::PxBounds3 getLocalBounds(const physx::PxGeometry &) const
Return local bounds.
Definition VoxelMap.cpp:197
virtual void visualize(const physx::PxGeometry &, physx::PxRenderOutput &, const physx::PxTransform &, const physx::PxBounds3 &) const
Visualize custom geometry for debugging. Optional.
Definition VoxelMap.cpp:419
virtual bool usePersistentContactManifold(const physx::PxGeometry &, physx::PxReal &) const
Compatible with PhysX's PCM feature. Allows to optimize contact generation.
Definition VoxelMap.h:95
virtual bool generateContacts(const physx::PxGeometry &geom0, const physx::PxGeometry &geom1, const physx::PxTransform &pose0, const physx::PxTransform &pose1, const physx::PxReal contactDistance, const physx::PxReal meshContactMargin, const physx::PxReal toleranceLength, physx::PxContactBuffer &contactBuffer) const
Contacts generation. Generate collision contacts between two geometries in given poses.
Definition VoxelMap.cpp:202
virtual bool overlap(const physx::PxGeometry &geom0, const physx::PxTransform &pose0, const physx::PxGeometry &geom1, const physx::PxTransform &pose1, physx::PxOverlapThreadContext *) const
Overlap. Test if geometries overlap.
Definition VoxelMap.cpp:320
Custom geometry callbacks structure. User should inherit this and implement all pure virtual function...
Definition PxCustomGeometry.h:102
Stores results of raycast queries.
Definition PxGeometryHit.h:151
Stores results of sweep queries.
Definition PxGeometryHit.h:175
A per-thread context passed to low-level query functions.
Definition PxGeometryQueryContext.h:52