672 lines
54 KiB
HTML
672 lines
54 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
<title>Geometry Queries — NVIDIA PhysX SDK 4.1 Documentation</title>
|
|
|
|
|
|
|
|
<link rel="shortcut icon" href="_static/images/favicon.ico"/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/breathe.css" type="text/css" />
|
|
<link rel="next" title="Scene Queries" href="SceneQueries.html" />
|
|
<link rel="prev" title="GPU Rigid Bodies" href="GPURigidBodies.html" />
|
|
<link href="../_static/css/nvidia_theme.css" rel="stylesheet" type="text/css">
|
|
|
|
|
|
<style>
|
|
.wy-nav-content::before {
|
|
content: "PhysX 4.1 SDK Guide";
|
|
}
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script src="../_static/js/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav">
|
|
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search">
|
|
|
|
|
|
|
|
<a href="../Index.html" class="icon icon-home"> Python
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="reference internal" href="Index.html">User's Guide</a><ul class="current">
|
|
<li class="toctree-l2"><a class="reference internal" href="License.html">PhysX License</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Introduction.html">Welcome to PhysX</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="HelloWorld.html">Snippets</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="BuildingWithPhysX.html">Building with PhysX</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="API.html">The PhysX API</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Startup.html">Startup and Shutdown</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Threading.html">Threading</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Geometry.html">Geometry</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="RigidBodyOverview.html">Rigid Body Overview</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="RigidBodyCollision.html">Rigid Body Collision</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="RigidBodyDynamics.html">Rigid Body Dynamics</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Simulation.html">Simulation</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="AdvancedCollisionDetection.html">Advanced Collision Detection</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Joints.html">Joints</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Articulations.html">Articulations</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Articulations.html#maximal-coordinate-and-reduced-articulations">Maximal Coordinate and Reduced Articulations</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Articulations.html#maximal-coordinate-articulations">Maximal Coordinate Articulations</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Articulations.html#reduced-coordinate-articulations">Reduced Coordinate Articulations</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="OriginShift.html">Scene Origin</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="GPURigidBodies.html">GPU Rigid Bodies</a></li>
|
|
<li class="toctree-l2 current"><a class="current reference internal" href="">Geometry Queries</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#introduction">Introduction</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#raycasts">Raycasts</a><ul>
|
|
<li class="toctree-l4"><a class="reference internal" href="#raycasts-against-spheres-capsules-boxes-and-convex-meshes">Raycasts against Spheres, Capsules, Boxes and Convex Meshes</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#raycasts-against-planes">Raycasts against Planes</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#raycasts-against-triangle-meshes">Raycasts against Triangle Meshes</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#raycasts-against-heightfields">Raycasts against Heightfields</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#overlaps">Overlaps</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#penetration-depth">Penetration Depth</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#sweeps">Sweeps</a><ul>
|
|
<li class="toctree-l4"><a class="reference internal" href="#initial-overlaps">Initial Overlaps</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#precise-sweeps">Precise Sweeps</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#sweeps-against-height-fields">Sweeps against Height Fields</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#pitfalls">Pitfalls</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#additional-pxgeometryquery-functions">Additional PxGeometryQuery functions</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#pxmeshquery">PxMeshQuery</a><ul>
|
|
<li class="toctree-l4"><a class="reference internal" href="#mesh-overlaps">Mesh Overlaps</a></li>
|
|
<li class="toctree-l4"><a class="reference internal" href="#sweeps-against-triangles">Sweeps against Triangles</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l2"><a class="reference internal" href="SceneQueries.html">Scene Queries</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Vehicles.html">Vehicles</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="CharacterControllers.html">Character Controllers</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="DebugVisualization.html">Debug Visualization</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="VisualDebugger.html">PhysX Visual Debugger (PVD)</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Statistics.html">Simulation Statistics</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="Serialization.html">Serialization</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="ExtendingSerialization.html">Extending Serialization</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="BestPractices.html">Best Practices Guide</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="MigrationFrom28.html">Migrating From PhysX SDK 2.x to 3.x</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="MigrationTo33.html">Migrating From PhysX SDK 3.2 to 3.3</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="MigrationTo34.html">Migrating From PhysX SDK 3.3 to 3.4</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="MigrationTo40.html">Migrating From PhysX SDK 3.4 to 4.0</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" aria-label="top navigation">
|
|
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="../Index.html">Python</a>
|
|
|
|
</nav>
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
|
|
<div class="rst-content">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
|
|
<ul class="wy-breadcrumbs">
|
|
|
|
<li><a href="../Index.html">Docs</a> »</li>
|
|
|
|
<li><a href="Index.html">User's Guide</a> »</li>
|
|
|
|
<li>Geometry Queries</li>
|
|
|
|
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<div class="section" id="geometry-queries">
|
|
<span id="geometryqueries"></span><h1>Geometry Queries<a class="headerlink" href="#geometry-queries" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="introduction">
|
|
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
|
|
<p>This chapter describes how to use PhysX' collision functionality with individual geometry objects. There are four main kinds of geometry queries:</p>
|
|
<ul class="simple">
|
|
<li>raycasts ("raycast queries") test a ray against a geometry object.</li>
|
|
<li>sweeps ("sweep queries") move one geometry object along a line to find the first point of intersection with another geometry object.</li>
|
|
<li>overlaps ("overlap queries") determine whether two geometry objects intersect.</li>
|
|
<li>penetration depth computations ("minimal translational distance queries", abbreviated here to "MTD") test two overlapping geometry objects to find the direction along which they can be separated by the minimum distance.</li>
|
|
</ul>
|
|
<p>In addition, PhysX provides helpers to compute the AABB of a geometry object, and to compute the distance between a point and a geometry object.</p>
|
|
<p>In all of the following functions, a geometry object is defined by its shape (a <em>PxGeometry</em> structure) and its pose (a <em>PxTransform</em> structure). All transforms and vectors are interpreted as being in the same space, and the results are also returned in that space.</p>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="raycasts">
|
|
<h2>Raycasts<a class="headerlink" href="#raycasts" title="Permalink to this headline">¶</a></h2>
|
|
<img alt="../_images/GeomQueryRaycast.png" src="../_images/GeomQueryRaycast.png" />
|
|
<p>A raycast query traces a point along a line segment until it hits a geometry object. PhysX supports raycasts for all geometry types.</p>
|
|
<p>The following code illustrates how to use a raycast query:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxRaycastHit</span> <span class="n">hitInfo</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">maxHits</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
|
|
<span class="n">PxHitFlags</span> <span class="n">hitFlags</span> <span class="o">=</span> <span class="n">PxHitFlag</span><span class="o">::</span><span class="n">ePOSITION</span><span class="o">|</span><span class="n">PxHitFlag</span><span class="o">::</span><span class="n">eNORMAL</span><span class="o">|</span><span class="n">PxHitFlag</span><span class="o">::</span><span class="n">eUV</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">hitCount</span> <span class="o">=</span> <span class="n">PxGeometryQuery</span><span class="o">::</span><span class="n">raycast</span><span class="p">(</span><span class="n">origin</span><span class="p">,</span> <span class="n">unitDir</span><span class="p">,</span>
|
|
<span class="n">geom</span><span class="p">,</span> <span class="n">pose</span><span class="p">,</span>
|
|
<span class="n">maxDist</span><span class="p">,</span>
|
|
<span class="n">hitFlags</span><span class="p">,</span>
|
|
<span class="n">maxHits</span><span class="p">,</span> <span class="o">&</span><span class="n">hitInfo</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The arguments are interpreted as follows:</p>
|
|
<ul class="simple">
|
|
<li><em>origin</em> is the start point of the ray.</li>
|
|
<li><em>unitDir</em> is a unit vector defining the direction of the ray.</li>
|
|
<li><em>maxDist</em> is the maximum distance to search along the ray. It must be in the [0, inf) range. If the maximum distance is 0, a hit will only be returned if the ray starts inside a shape, as detailed below for each geometry.</li>
|
|
<li><em>geom</em> is the geometry to test against.</li>
|
|
<li><em>pose</em> is the pose of the geometry.</li>
|
|
<li><em>hitFlags</em> specifies the values that should be returned by the query, and options for processing the query.</li>
|
|
<li><em>maxHits</em> is the maximum number of hits to return.</li>
|
|
<li><em>hitInfo</em> specifies the <em>PxRaycastHit</em> structure(s) into which the raycast results will be stored.</li>
|
|
</ul>
|
|
<p>The returned result is the number of intersections found. For each intersection, a <em>PxRaycastHit</em> is populated. The fields of this structure are as follows:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxRigidActor</span><span class="o">*</span> <span class="n">actor</span><span class="p">;</span>
|
|
<span class="n">PxShape</span><span class="o">*</span> <span class="n">shape</span><span class="p">;</span>
|
|
<span class="n">PxVec3</span> <span class="n">position</span><span class="p">;</span>
|
|
<span class="n">PxVec3</span> <span class="n">normal</span><span class="p">;</span>
|
|
<span class="n">PxF32</span> <span class="n">distance</span><span class="p">;</span>
|
|
<span class="n">PxHitFlags</span> <span class="n">flags</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">faceIndex</span><span class="p">;</span>
|
|
<span class="n">PxF32</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">;</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Some fields are optional, and the flags field indicates which members have been filled with result values. The query will fill fields in the output structure if the corresponding flags were set in the input - for example, if the <em>PxHitFlag::ePOSITION</em> is set in the input hitFlags, the query will fill in the <em>PxRaycastHit::position</em> field, and set the <em>PxHitFlag::ePOSITION</em> flag in <em>PxRaycastHit::flags</em>. If the input flag is not set for a specific member, the result structure may or may not contain valid data for that member. Omitting the <em>eNORMAL</em> and <em>ePOSITION</em> flags in the input can sometimes result in faster queries.</p>
|
|
<p>For a raycast which is not initially intersecting the geometry object, the fields are populated as follows (optional fields are listed together with the flag that controls them):</p>
|
|
<ul class="simple">
|
|
<li><em>actor</em> and <em>shape</em> are not filled (these fields are used only in scene-level raycasts, see <a class="reference internal" href="SceneQueries.html#scenequeries"><em>Scene Queries</em></a>).</li>
|
|
<li><em>position</em> (<em>PxHitFlag::ePOSITION</em>) is the position of the intersection.</li>
|
|
<li><em>normal</em> (<em>PxHitFlag::eNORMAL</em>) is the surface normal at the point of intersection.</li>
|
|
<li><em>distance</em> is the distance along the ray at which the intersection was found.</li>
|
|
<li><em>flags</em> specifies which fields of the structure are valid.</li>
|
|
<li><em>faceIndex</em> is the index of the face which the ray hit. For triangle mesh and height field intersections, it is a triangle index. For convex mesh intersections it is a polygon index. For other shapes it is always set to 0xffffffff.</li>
|
|
<li><em>u</em> and <em>v</em> (<em>PxHitFlag::eUV</em>) are the barycentric coordinates of the intersection. These fields (and the flag) are supported only for meshes and heightfields.</li>
|
|
</ul>
|
|
<p>The position field is related to the barycentric coordinates via the following formula, where v0, v1 and v2 are the vertices from the hit triangle:</p>
|
|
<blockquote>
|
|
<div>position = (1 - u - v)*v0 + u*v1 + v*v2;</div></blockquote>
|
|
<p>This mapping is implemented in <em>PxTriangle::pointFromUV()</em>.</p>
|
|
<p>See <a class="reference internal" href="Geometry.html#geometry"><em>Geometry</em></a> for details of how to retrieve face and vertex data from triangle meshes, convex meshes and height fields using face and vertex indices.</p>
|
|
<p>Exceptions to the above behavior may apply if a ray starts inside an object, in which case PhysX may not be able to compute meaningful output values for some fields. In these cases the field will remain unmodified and the corresponding flag will not be set. Specific details vary by geometry type, and are described below.</p>
|
|
<p>The exact conditions for raycast intersections are as follows:</p>
|
|
<div class="section" id="raycasts-against-spheres-capsules-boxes-and-convex-meshes">
|
|
<h3>Raycasts against Spheres, Capsules, Boxes and Convex Meshes<a class="headerlink" href="#raycasts-against-spheres-capsules-boxes-and-convex-meshes" title="Permalink to this headline">¶</a></h3>
|
|
<p>For solid objects (sphere, capsule, box, convex) at most 1 result is returned. If the ray origin is inside a solid object:</p>
|
|
<ul class="simple">
|
|
<li>the reported hit distance is set to zero.</li>
|
|
<li>the hit normal is set to be the opposite of the ray's direction, and the <em>PxHitFlag::eNORMAL</em> flag is set in the output.</li>
|
|
<li>the hit impact position is set to the ray's origin and the <em>PxHitFlag::ePOSITION</em> flag is set in the output.</li>
|
|
</ul>
|
|
<p>If the start or end point of a ray is very close to the surface of the object, it may be treated as being on either side of the surface.</p>
|
|
</div>
|
|
<div class="section" id="raycasts-against-planes">
|
|
<h3>Raycasts against Planes<a class="headerlink" href="#raycasts-against-planes" title="Permalink to this headline">¶</a></h3>
|
|
<p>For raycasts, a plane is treated as an infinite single-sided quad that includes its boundary (note that this is not the same as for overlaps). At most one result is returned, and if the ray origin is behind the plane's surface, no hit will be reported even in case the ray intersects the plane.</p>
|
|
<p>If the start or end point of a ray is very close to the plane, it may be treated as being on either side of the plane.</p>
|
|
</div>
|
|
<div class="section" id="raycasts-against-triangle-meshes">
|
|
<span id="raycasts-vs-meshes"></span><h3>Raycasts against Triangle Meshes<a class="headerlink" href="#raycasts-against-triangle-meshes" title="Permalink to this headline">¶</a></h3>
|
|
<p>Triangle meshes are treated as thin triangle surfaces rather than solid objects. They may be configured to return either an arbitrary hit, the closest hit, or multiple hits.</p>
|
|
<ul class="simple">
|
|
<li>if maxHits is 1 and <em>PxHitFlag::eMESH_ANY</em> is not set, the query will return the closest intersection.</li>
|
|
<li>if maxHits is 1 and <em>PxHitFlag::eMESH_ANY</em> is set, the query will return an arbitrary intersection. Use this when it is sufficient to know whether or not the ray hit the mesh, e.g. for line-of-sight queries or shadow rays.</li>
|
|
<li>if maxHits is greater than 1, the query will return multiple intersections, up to maxHits. If more than maxHits intersection points exist, there is no guarantee that the results will include the closest. Use this for e.g. wall-piercing bullets that hit multiple triangles, or where special filtering is required. Note that <em>PxHitFlag::eMESH_MULTIPLE</em> must be used in this case.</li>
|
|
</ul>
|
|
<p>In general "any hit" queries are faster than "closest hit" queries, and "closest hit" queries are faster than "multiple hits" queries.</p>
|
|
<p>By default, back face hits (where the triangle's outward-facing normal has a positive dot product with the ray direction) are culled, and so for any triangle hit the reported normal will have a negative dot product with the ray direction. This behavior may be modified by the mesh instance's <em>PxMeshGeometryFlag::eDOUBLE_SIDED</em> flag and the query's <em>PxHitFlag::eMESH_BOTH_SIDES</em> flag:</p>
|
|
<ul class="simple">
|
|
<li>if either <em>PxMeshGeometryFlag::eDOUBLE_SIDED</em> or <em>PxHitFlag::eMESH_BOTH_SIDES</em> is set, culling is disabled.</li>
|
|
<li>if <em>PxMeshGeometryFlag::eDOUBLE_SIDED</em> is set, the reported normal is reversed for a back face hit.</li>
|
|
</ul>
|
|
<p>For example a transparent glass window could be modeled as a double-sided mesh, so that a ray would hit either side with the reported normal facing opposite to the ray direction. A raycast tracing the path of a bullet that may penetrate the front side of a mesh and emerge from the back could use <em>eMESH_BOTH_SIDES</em> to find both front and back facing triangles even when the mesh is single-sided.</p>
|
|
<p>The following diagram shows what happens with different flags, for a single raycast intersecting a mesh in several places.</p>
|
|
<a class="reference internal image-reference" href="../_images/RayMeshDS_Permutations.png"><img alt="../_images/RayMeshDS_Permutations.png" src="../_images/RayMeshDS_Permutations.png" /></a>
|
|
<p>To use <em>PxHitFlag::eMESH_BOTH_SIDES</em> for selected meshes rather than all, set the flag inside the <em>PxQueryFilterCallback</em>.</p>
|
|
<p>If the start or end point of a ray is very close to the surface of a triangle, it may be treated as being on either side of the triangle.</p>
|
|
<p>If the start or end point of a ray is very close to the surface of a triangle, it may be treated as being on the either side of the triangle.</p>
|
|
</div>
|
|
<div class="section" id="raycasts-against-heightfields">
|
|
<h3>Raycasts against Heightfields<a class="headerlink" href="#raycasts-against-heightfields" title="Permalink to this headline">¶</a></h3>
|
|
<ul class="simple">
|
|
<li>Heightfields are treated the same way as triangle meshes with normals oriented (in shape space) in +y direction.</li>
|
|
<li>Double-sided heightfields are treated the same way as double sided triangle meshes.</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="overlaps">
|
|
<h2>Overlaps<a class="headerlink" href="#overlaps" title="Permalink to this headline">¶</a></h2>
|
|
<img alt="../_images/GeomQueryOverlap.png" src="../_images/GeomQueryOverlap.png" />
|
|
<p>Overlap queries simply check whether two geometry objects overlap. One of the geometries must be a box, sphere, capsule or convex, and the other may be of any type.</p>
|
|
<p>The following code illustrates how to use an overlap query:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="n">isOverlapping</span> <span class="o">=</span> <span class="n">overlap</span><span class="p">(</span><span class="n">geom0</span><span class="p">,</span> <span class="n">pose0</span><span class="p">,</span> <span class="n">geom1</span><span class="p">,</span> <span class="n">pose1</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Overlaps do not support hit flags and return only a boolean result.</p>
|
|
<ul class="simple">
|
|
<li>A plane is treated as a solid half-space: that is, everything behind the plane is considered part of the volume.</li>
|
|
<li>Triangle meshes are treated as thin triangle surfaces rather than solid objects.</li>
|
|
<li>Heightfields are treated as triangle surface. Overlap geometries that do not intersect with the heightfield surface will not report a hit.</li>
|
|
</ul>
|
|
<p>If more than a boolean result is needed for meshes and heightfields, use the <em>PxMeshQuery</em> API instead (see <a class="reference internal" href="#meshquery"><em>PxMeshQuery</em></a>).</p>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="penetration-depth">
|
|
<h2>Penetration Depth<a class="headerlink" href="#penetration-depth" title="Permalink to this headline">¶</a></h2>
|
|
<img alt="../_images/GeomQueryPenetration.png" src="../_images/GeomQueryPenetration.png" />
|
|
<p>When two objects are intersecting, PhysX can compute the minimal distance and direction by which the objects must be translated to separate them (this quantity is sometimes referred to as MTD, for <em>minimum translational distance</em>, as it is the vector of minimal length by which translation will separate the shapes). One geometry object must be a box, sphere, capsule or convex mesh, and the other may be of any type.</p>
|
|
<p>The following code illustrates how to use a penetration depth query:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="n">isPenetrating</span> <span class="o">=</span> <span class="n">PxGeometryQuery</span><span class="o">::</span><span class="n">computePenetration</span><span class="p">(</span><span class="n">direction</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span>
|
|
<span class="n">geom0</span><span class="p">,</span> <span class="n">pose0</span><span class="p">,</span>
|
|
<span class="n">geom1</span><span class="p">,</span> <span class="n">pose1</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The arguments are interpreted as follows:</p>
|
|
<ul class="simple">
|
|
<li><em>direction</em> is set to the direction in which the first object should be translated in order to depenetrate from the second.</li>
|
|
<li><em>distance</em> is set to the distance by which the first object should be translated in order to depenetrate from the second.</li>
|
|
<li><em>geom0</em> is the first geometry.</li>
|
|
<li><em>pose0</em> is the transform of the first geometry.</li>
|
|
<li><em>geom1</em> is the second geometry.</li>
|
|
<li><em>pose2</em> is the transform of the second geometry.</li>
|
|
</ul>
|
|
<p>The function returns true if the objects are penetrating, in which case it sets the direction and depth fields. Translating the first object by the depenetration vector D = direction * depth will separate the two objects. If the function returns true, the returned depth will always be positive or zero. If objects do not overlap, the function returns false, and the values of the direction and distance fields are undefined.</p>
|
|
<p>For simple (convex) shapes, returned results are accurate.</p>
|
|
<p>For meshes and heightfields, an iterative algorithm is used and dedicated functions are exposed in <em>PxExtensions</em>:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxU32</span> <span class="n">nb</span><span class="p">;</span>
|
|
<span class="kt">bool</span> <span class="n">status</span> <span class="o">=</span> <span class="n">PxComputeTriangleMeshPenetration</span><span class="p">(</span><span class="n">direction</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span>
|
|
<span class="n">geom</span><span class="p">,</span> <span class="n">geomPose</span><span class="p">,</span>
|
|
<span class="n">meshGeom</span><span class="p">,</span> <span class="n">meshPose</span><span class="p">,</span>
|
|
<span class="n">maxIter</span><span class="p">,</span> <span class="o">&</span><span class="n">nb</span><span class="p">);</span>
|
|
|
|
<span class="n">PxU32</span> <span class="n">nb</span><span class="p">;</span>
|
|
<span class="kt">bool</span> <span class="n">status</span> <span class="o">=</span> <span class="n">PxComputeHeightFieldPenetration</span><span class="p">(</span><span class="n">direction</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span>
|
|
<span class="n">geom</span><span class="p">,</span> <span class="n">geomPose</span><span class="p">,</span>
|
|
<span class="n">heightFieldGeom</span><span class="p">,</span> <span class="n">heightFieldPose</span><span class="p">,</span>
|
|
<span class="n">maxIter</span><span class="p">,</span> <span class="o">&</span><span class="n">nb</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Here, <em>maxIter</em> is the maximum number of iterations for the algorithm, and <em>nb</em> is an optional output argument which will be set to the number of iterations performed. If no overlap is detected, the function returns false. The code will attempt at most maxIter iterations but may exit earlier if a depenetration vector is found. Usually maxIter = 4 gives good results.</p>
|
|
<p>These functions only compute an approximate depenetration vector, and work best when the amount of overlap between the geometry object and the mesh/heightfield is small. In particular, an intersection with a triangle will be ignored when the object's center is behind the triangle, and if this holds for all intersecting triangles then no overlap is detected, and the functions do not compute an MTD vector.</p>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="sweeps">
|
|
<h2>Sweeps<a class="headerlink" href="#sweeps" title="Permalink to this headline">¶</a></h2>
|
|
<img alt="../_images/GeomQuerySweep.png" src="../_images/GeomQuerySweep.png" />
|
|
<p>A sweep query traces one geometry object through space to find the impact point on a second geometry object, and reports information concerning the impact point if one is found. PhysX only supports sweep queries where the first geometry object (the one that is traced through space) is a sphere, box, capsule or convex geometry. The second geometry object may be of any type.</p>
|
|
<p>The following code illustrates how to use a sweep query:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxSweepHit</span> <span class="n">hitInfo</span><span class="p">;</span>
|
|
<span class="n">PxHitFlags</span> <span class="n">hitFlags</span> <span class="o">=</span> <span class="n">PxHitFlag</span><span class="o">::</span><span class="n">ePOSITION</span><span class="o">|</span><span class="n">PxHitFlag</span><span class="o">::</span><span class="n">eNORMAL</span><span class="p">;</span>
|
|
<span class="n">PxReal</span> <span class="n">inflation</span> <span class="o">=</span> <span class="mf">0.0f</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">hitCount</span> <span class="o">=</span> <span class="n">PxGeometryQuery</span><span class="o">::</span><span class="n">sweep</span><span class="p">(</span><span class="n">unitDir</span><span class="p">,</span> <span class="n">maxDist</span><span class="p">,</span>
|
|
<span class="n">geomToSweep</span><span class="p">,</span> <span class="n">poseToSweep</span><span class="p">,</span>
|
|
<span class="n">geomSweptAgainst</span><span class="p">,</span> <span class="n">poseSweptAgainst</span><span class="p">,</span>
|
|
<span class="n">hitInfo</span><span class="p">,</span>
|
|
<span class="n">hitFlags</span><span class="p">,</span>
|
|
<span class="n">inflation</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The arguments are interpreted as follows:</p>
|
|
<ul class="simple">
|
|
<li><em>unitDir</em> is a unit vector defining the direction of the sweep.</li>
|
|
<li><em>maxDist</em> is the maximum distance to search along the sweep. It must be in the [0, inf) range, and is clamped by SDK code to at most <em>PX_MAX_SWEEP_DISTANCE</em>. A sweep of length 0 is equivalent to an overlap check.</li>
|
|
<li><em>geomToSweep</em> is the geometry to sweep. Supported geometries are: box, sphere, capsule or convex mesh.</li>
|
|
<li><em>poseToSweep</em> is the initial pose of the geometry to sweep.</li>
|
|
<li><em>geomSweptAgainst</em> is the geometry to sweep against (any geometry type can be used here).</li>
|
|
<li><em>poseSweptAgainst</em> is the pose of the geometry to sweep against.</li>
|
|
<li><em>hitInfo</em> is the returned result. A sweep will return at most one hit.</li>
|
|
<li><em>hitFlags</em> determines how the sweep is processed, and which data is returned if an impact is found.</li>
|
|
<li><em>inflation</em> inflates the first geometry with a shell extending outward from the object surface, making any corners rounded. It can be used to ensure a minimum margin of space is kept around the geometry when using sweeps to test whether movement is possible.</li>
|
|
</ul>
|
|
<p>As with raycasts, fields will be filled in the output structure if the corresponding flags were set in the input hitFlags. The fields of PxSweepHit are as follows:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxRigidActor</span><span class="o">*</span> <span class="n">actor</span><span class="p">;</span>
|
|
<span class="n">PxShape</span><span class="o">*</span> <span class="n">shape</span><span class="p">;</span>
|
|
<span class="n">PxVec3</span> <span class="n">position</span><span class="p">;</span>
|
|
<span class="n">PxVec3</span> <span class="n">normal</span><span class="p">;</span>
|
|
<span class="n">PxF32</span> <span class="n">distance</span><span class="p">;</span>
|
|
<span class="n">PxHitFlags</span> <span class="n">flags</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">faceIndex</span><span class="p">;</span>
|
|
</pre></div>
|
|
</div>
|
|
<ul class="simple">
|
|
<li><em>actor</em> and <em>shape</em> are not filled (these fields are used only in scene-level sweeps, see <a class="reference internal" href="SceneQueries.html#scenequeries"><em>Scene Queries</em></a>).</li>
|
|
<li><em>position</em> (<em>PxHitFlag::ePOSITION</em>) is the position of the intersection. When there are multiple impact points, such as two boxes meeting face-to-face, PhysX will select one point arbitrarily. More detailed information for meshes or height fields may be obtained using the functions in <a class="reference internal" href="#meshquery"><em>PxMeshQuery</em></a>.</li>
|
|
<li><em>normal</em> (<em>PxHitFlag::eNORMAL</em>) is the surface normal at the point of impact. It is a unit vector, pointing outwards from the hit object and backwards along the sweep direction (in the sense that the dot product between the sweep direction and the impact normal is negative).</li>
|
|
<li><em>distance</em> is the distance along the ray at which the intersection was found.</li>
|
|
<li><em>flags</em> specifies which fields of the structure are valid.</li>
|
|
<li><em>faceIndex</em> is the index of the face hit by the sweep. This is a face from the hit object, not from the swept object. For triangle mesh and height field intersections, it is a triangle index. For convex mesh intersections it is a polygon index. For other shapes it is always set to 0xffffffff. For convex meshes the face index computation is rather expensive. The face index computation can be disabled by not providing the scene query hit flag <em>PxHitFlag::eFACE_INDEX</em>. If needed the face index can also be computed externally using the function <em>PxFindFaceIndex</em> which is part of the PhysX extensions library.</li>
|
|
</ul>
|
|
<p>Unlike raycasts, u,v coordinates are not supported for sweeps.</p>
|
|
<p>For the geometry object swept against:</p>
|
|
<ul class="simple">
|
|
<li>A plane is treated as a solid half-space: that is, everything behind the plane is considered part of the volume to sweep against.</li>
|
|
<li>The same backface-culling rules as for raycasts apply for sweeps, with the notable difference that <em>eMESH_MULTIPLE</em> is not supported.</li>
|
|
</ul>
|
|
<div class="section" id="initial-overlaps">
|
|
<h3>Initial Overlaps<a class="headerlink" href="#initial-overlaps" title="Permalink to this headline">¶</a></h3>
|
|
<p>Similarly to a raycast starting inside an object, a sweep may start with the two geometries initially intersecting. By default PhysX will detect and report the overlap. Use <em>PxSweepHit::hadInitialOverlap()</em> to see if the hit was generated by an initial overlap.</p>
|
|
<p>For triangle meshes and height fields, backface culling is performed before overlap checks, and thus no initial overlap is reported if a triangle is culled.</p>
|
|
<p>Depending on the value of <em>PxHitFlag::eMTD</em>, PhysX may also calculate the MTD. If <em>PxHitFlag::eMTD</em> is not set:</p>
|
|
<ul class="simple">
|
|
<li>the distance is set to zero.</li>
|
|
<li>the normal is set to be the opposite of the sweep direction, and the <em>PxHitFlag::eNORMAL</em> flag is set in the <em>PxSweepHit</em> result structure.</li>
|
|
<li>the position is undefined, and the <em>PxHitFlag::ePOSITION</em> flag is <em>not</em> set in the <em>PxSweepHit</em> result structure.</li>
|
|
<li>the faceIndex is a face from the second geometry object. For a heightfield or triangle mesh, it is the index of the first overlapping triangle found. For other geometry types, the index is set to 0xffffffff.</li>
|
|
</ul>
|
|
<p>If <em>PxHitFlag::eMTD</em> is set, the hit results are defined as follows:</p>
|
|
<ul class="simple">
|
|
<li>the distance is set to the penetration depth.</li>
|
|
<li>the normal is set to the depenetration direction, and the <em>PxHitFlag::eNORMAL</em> flag is set in the <em>PxSweepHit</em> result structure.</li>
|
|
<li>the position is a point on the sweep geometry object (i.e. the first geometry argument) and the <em>PxHitFlag::ePOSITION</em> flag is set in the <em>PxSweepHit</em> result structure.</li>
|
|
<li>the faceIndex is a face from the second geometry object:</li>
|
|
</ul>
|
|
<blockquote>
|
|
<div><ul class="simple">
|
|
<li>For triangle meshes and heightfields it is the last penetrated triangle found during the last iteration of the depenetration algorithm.</li>
|
|
<li>For other geometry types, the index is set to 0xffffffff.</li>
|
|
</ul>
|
|
</div></blockquote>
|
|
<p>This flag will incur additional processing overhead in the case of an initial overlap. In addition, the following restrictions apply:</p>
|
|
<ul class="simple">
|
|
<li><em>PxHitFlag::eMTD</em> is incompatible with <em>PxHitFlag::ePRECISE_SWEEP</em> and <em>PxHitFlag::eASSUME_NO_INITIAL_OVERLAP</em> (see below). Using <em>PxHitFlag::eMTD</em> in conjunction with either of these flags will result in a warning being issued and the flag(s) that are incompatible with <em>PxHitFlag::eMTD</em> being ignored.</li>
|
|
</ul>
|
|
<p>Testing for initial overlaps sometimes uses a specialized code path and incurs a performance penalty. If is it possible to guarantee that geometry objects are not initially overlapping, the check for overlaps can be suppressed with <em>PxHitFlag::eASSUME_NO_INITIAL_OVERLAP</em>. There are some restrictions on the use of this flag (also, see <a class="reference internal" href="#sweep-pitfalls"><em>Pitfalls</em></a>)</p>
|
|
<ul class="simple">
|
|
<li>Using <em>PxHitFlag::eASSUME_NO_INITIAL_OVERLAP</em> flag when the geometries initially overlap produces undefined behavior.</li>
|
|
<li><em>PxHitFlag::eASSUME_NO_INITIAL_OVERLAP</em> in combination with zero sweep distance produces a warning and undefined behavior.</li>
|
|
</ul>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">sweeps with <em>PxHitFlag::eMTD</em> use two kinds of backface culling for triangles. First, the triangles are culled based on sweep direction to determine whether there is an overlap. If an overlap is detected, they are further culled by whether the centroid is behind the triangle, and if no triangles are found, the direction will be set opposite to the sweep direction and the distance to 0.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">in most cases, translating the first geometry object by -normal*distance will separate the objects. However, an iterative depenetration algorithm is used to find the MTD for triangle meshes and height fields, and the MTD result may not provide complete depenetration from the mesh in extreme cases. In this case the query should be called a second time after the translation has been applied.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">a known issue in PhysX 3.3 is that the face index for a sweep against a convex mesh is undefined when the eMTD flag is not set.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="precise-sweeps">
|
|
<h3>Precise Sweeps<a class="headerlink" href="#precise-sweeps" title="Permalink to this headline">¶</a></h3>
|
|
<p><em>PxHitFlag::ePRECISE_SWEEP</em> enables more accurate sweep code (by default a potentially faster but less accurate solution is used). The <em>ePRECISE_SWEEP</em> flag is not compatible with the inflation parameter, or with the flag <em>PxHitFlag::eMTD</em>.</p>
|
|
</div>
|
|
<div class="section" id="sweeps-against-height-fields">
|
|
<h3>Sweeps against Height Fields<a class="headerlink" href="#sweeps-against-height-fields" title="Permalink to this headline">¶</a></h3>
|
|
<ul>
|
|
<li><p class="first">Height fields are treated as thin triangle surfaces rather than solid objects.</p>
|
|
</li>
|
|
<li><p class="first">For single-sided height fields the normal of the hit will face in +y local space direction.</p>
|
|
</li>
|
|
<li><p class="first">Height fields are treated as double sided if either one of eDOUBLE_SIDED or eMESH_BOTH_SIDES flags are used.</p>
|
|
<blockquote>
|
|
<div><ul class="simple">
|
|
<li>The returned hit normal will always face the sweep direction.</li>
|
|
</ul>
|
|
</div></blockquote>
|
|
</li>
|
|
<li><p class="first">eMESH_ANY flag has no effect.</p>
|
|
</li>
|
|
<li><p class="first">ePRECISE_SWEEP flag has no effect.</p>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="pitfalls">
|
|
<span id="sweep-pitfalls"></span><h3>Pitfalls<a class="headerlink" href="#pitfalls" title="Permalink to this headline">¶</a></h3>
|
|
<p>There are some pitfalls to be aware of when using sweeps:</p>
|
|
<ul class="simple">
|
|
<li>Due to numerical precision issues, incorrect results may be returned when the objects have very large size disparities.</li>
|
|
<li>Due to algorithmic differences, a sweep query may detect a different set of initially overlapping shapes than an overlap query. In particular, it is not sufficient to perform an overlap check in order to determine the safety of the <em>PxHitFlag::eIGNORE_INITIAL_OVERLAP</em> flag. Applications that need consistent overlap/sweep/penetration depth information should use sweep checks with initial overlap testing and the <em>PxHitFlag::eMTD</em> flag.</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<div class="section" id="additional-pxgeometryquery-functions">
|
|
<h2>Additional PxGeometryQuery functions<a class="headerlink" href="#additional-pxgeometryquery-functions" title="Permalink to this headline">¶</a></h2>
|
|
<img alt="../_images/GeomQueryPointDistance.png" src="../_images/GeomQueryPointDistance.png" />
|
|
<p>The following function computes the distance between a point and a geometry object. Only solid objects (box, sphere, capsule, convex) are supported:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxReal</span> <span class="n">dist</span> <span class="o">=</span> <span class="n">PxGeometryQuery</span><span class="o">::</span><span class="n">pointDistance</span><span class="p">(</span><span class="n">point</span><span class="p">,</span> <span class="n">geom</span><span class="p">,</span> <span class="n">pose</span><span class="p">,</span> <span class="n">closestPoint</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p><em>closestPoint</em> is an optional output argument which returns the closest point.</p>
|
|
<img alt="../_images/GeomQueryWorldBounds.png" src="../_images/GeomQueryWorldBounds.png" />
|
|
<p>The following function computes the axis-aligned bounding box (AABB) enclosing a geometry object, given its pose:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxBounds3</span> <span class="n">bounds</span> <span class="o">=</span> <span class="n">PxGeometryQuery</span><span class="o">::</span><span class="n">getWorldBounds</span><span class="p">(</span><span class="n">geom</span><span class="p">,</span> <span class="n">pose</span><span class="p">,</span> <span class="n">inflation</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The bounding box is scaled by the <em>inflation</em> value, which defaults to 1.01f if not explicitly specified.</p>
|
|
<hr class="docutils" />
|
|
</div>
|
|
<div class="section" id="pxmeshquery">
|
|
<span id="meshquery"></span><h2>PxMeshQuery<a class="headerlink" href="#pxmeshquery" title="Permalink to this headline">¶</a></h2>
|
|
<p>PhysX provides additional functionality for obtaining multiple results for triangle mesh and height field overlaps, and for sweeping against arrays of triangles. Only boxes, spheres and capsules may be tested against meshes or heightfields using these functions.</p>
|
|
<div class="section" id="mesh-overlaps">
|
|
<h3>Mesh Overlaps<a class="headerlink" href="#mesh-overlaps" title="Permalink to this headline">¶</a></h3>
|
|
<p>The following code illustrates how to process the mesh triangles touching a given spherical volume:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="n">PxU32</span> <span class="n">triangleIndexBuffer</span><span class="p">[</span><span class="n">bufferSize</span><span class="p">];</span>
|
|
<span class="n">PxU32</span> <span class="n">startIndex</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
|
<span class="kt">bool</span> <span class="n">bufferOverflowOccured</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">nbTriangles</span> <span class="o">=</span> <span class="n">PxMeshQuery</span><span class="o">::</span><span class="n">findOverlapTriangleMesh</span><span class="p">(</span><span class="n">sphereGeom</span><span class="p">,</span> <span class="n">spherePose</span><span class="p">,</span>
|
|
<span class="n">meshGeom</span><span class="p">,</span> <span class="n">meshPose</span><span class="p">,</span>
|
|
<span class="n">triangleIndexBuffer</span><span class="p">,</span> <span class="n">bufferSize</span><span class="p">,</span>
|
|
<span class="n">startIndex</span><span class="p">,</span> <span class="n">bufferOverflowOccured</span><span class="p">);</span>
|
|
|
|
<span class="k">for</span><span class="p">(</span><span class="n">PxU32</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">nbTriangles</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
|
|
<span class="p">{</span>
|
|
<span class="n">PxTriangle</span> <span class="n">tri</span><span class="p">;</span>
|
|
<span class="n">PxU32</span> <span class="n">vertexIndices</span><span class="p">[</span><span class="mi">3</span><span class="p">];</span>
|
|
<span class="n">PxMeshQuery</span><span class="o">::</span><span class="n">getTriangle</span><span class="p">(</span><span class="n">meshGeom</span><span class="p">,</span> <span class="n">meshPose</span><span class="p">,</span> <span class="n">triangleIndexBuffer</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">tri</span><span class="p">,</span> <span class="n">vertexIndices</span><span class="p">);</span>
|
|
|
|
<span class="p">...</span> <span class="c1">// process triangle info</span>
|
|
<span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The <em>findOverlapTriangleMesh</em> method is used to extract the indices of the triangles:</p>
|
|
<ul class="simple">
|
|
<li><em>sphereGeom</em> and <em>spherePose</em> specify the region to test for overlap.</li>
|
|
<li><em>meshGeom</em> and <em>meshPose</em> specify the mesh and its pose.</li>
|
|
<li><em>triangleIndexBuffer</em> and <em>triangleSize</em> specify the output buffer and its size.</li>
|
|
<li><em>startIndex</em> is used to restart the query if the buffer size is exceeded. In this case, to query for more triangles set this parameter to the number retrieved so far.</li>
|
|
<li><em>bufferOverflowOccured</em> is set if more triangles would be returned from the query than would fit in the buffer.</li>
|
|
</ul>
|
|
<p>Similar query functionality exists for height fields.</p>
|
|
</div>
|
|
<div class="section" id="sweeps-against-triangles">
|
|
<h3>Sweeps against Triangles<a class="headerlink" href="#sweeps-against-triangles" title="Permalink to this headline">¶</a></h3>
|
|
<p>Sometimes, for example, when using the mesh overlap API, it is convenient to be able to sweep against groups of triangles. PhysX provides a function specifically for this purpose, with the following signature:</p>
|
|
<div class="highlight-c++"><div class="highlight"><pre><span class="kt">bool</span> <span class="nf">sweep</span><span class="p">(</span><span class="k">const</span> <span class="n">PxVec3</span><span class="o">&</span> <span class="n">unitDir</span><span class="p">,</span>
|
|
<span class="k">const</span> <span class="n">PxReal</span> <span class="n">distance</span><span class="p">,</span>
|
|
<span class="k">const</span> <span class="n">PxGeometry</span><span class="o">&</span> <span class="n">geom</span><span class="p">,</span>
|
|
<span class="k">const</span> <span class="n">PxTransform</span><span class="o">&</span> <span class="n">pose</span><span class="p">,</span>
|
|
<span class="n">PxU32</span> <span class="n">triangleCount</span><span class="p">,</span>
|
|
<span class="k">const</span> <span class="n">PxTriangle</span><span class="o">*</span> <span class="n">triangles</span><span class="p">,</span>
|
|
<span class="n">PxSweepHit</span><span class="o">&</span> <span class="n">sweepHit</span><span class="p">,</span>
|
|
<span class="n">PxHitFlags</span> <span class="n">hitFlags</span> <span class="o">=</span> <span class="n">PxHitFlag</span><span class="o">::</span><span class="n">eDEFAULT</span><span class="p">,</span>
|
|
<span class="k">const</span> <span class="n">PxU32</span><span class="o">*</span> <span class="n">cachedIndex</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">,</span>
|
|
<span class="k">const</span> <span class="n">PxReal</span> <span class="n">inflation</span> <span class="o">=</span> <span class="mf">0.0f</span><span class="p">,</span>
|
|
<span class="kt">bool</span> <span class="n">doubleSided</span> <span class="o">=</span> <span class="nb">false</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>The arguments are interpreted as follows:</p>
|
|
<ul class="simple">
|
|
<li><em>unitDir</em>, <em>distance</em>, <em>geom</em> and <em>pose</em> function identically to the first four parameters of PxGeometryQuery::sweep(). <em>distance</em> is clamped to PX_MAX_SWEEP_DISTANCE.</li>
|
|
<li><em>triangleCount</em> is the number of triangles contained in the buffer against which to sweep.</li>
|
|
<li><em>triangles</em> is the buffer of triangles.</li>
|
|
<li><em>hitFlags</em> specifies the required information in the output.</li>
|
|
<li><em>cachedIndex</em>, if set, specifies the index of a triangle to test first. This can be a useful optimization when repeatedly sweeping against the same set of triangles.</li>
|
|
<li><em>inflation</em> functions identically to the inflation parameter of PxGeometryQuery::sweep().</li>
|
|
<li><em>doubleSided</em> indicates whether the input triangles are double-sided or not. This is equivalent to the <em>PxMeshGeometryFlag::eDOUBLE_SIDED</em> flag - that is, it suppresses backface culling, and for any hit the returned normal faces opposite to the sweep direction (see <a class="reference internal" href="#raycasts-vs-meshes"><em>Raycasts against Triangle Meshes</em></a>).</li>
|
|
</ul>
|
|
<p>This function has extra limitations compared to the other sweep queries:</p>
|
|
<ul class="simple">
|
|
<li>the geometry type must be either a sphere, a capsule or a box. Convex geometry is not supported.</li>
|
|
<li>the function returns a single hit. Multiple hits (and in particular PxHitFlag::eMESH_MULTIPLE) are not supported.</li>
|
|
<li>The function always returns the closest hit.</li>
|
|
<li>The only supported flags are PxHitFlag::eDEFAULT, PxHitFlag::eASSUME_NO_INITIAL_OVERLAP, PxHitFlag::ePRECISE_SWEEP, PxHitFlag::eMESH_BOTH_SIDES and PxHitFlag::eMESH_ANY.</li>
|
|
</ul>
|
|
<p>The function tests each input triangle in the order they are given. By default, the function will test all triangles and return the closest sweep hit (if a hit has been found). If PxHitFlag::eMESH_ANY is used, the function will return as soon as a hit is found (skipping the remaining untested triangles). This flag can also be used to emulate PxHitFlag::eMESH_MULTIPLE, by calling the function repeatedly with PxHitFlag::eMESH_ANY, using as a starting point the previously returned hit triangle (whose index, between 0 and 'triangleCount', is available in sweepHit.faceIndex).</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
<a href="SceneQueries.html" class="btn btn-neutral float-right" title="Scene Queries" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
|
|
|
|
|
|
<a href="GPURigidBodies.html" class="btn btn-neutral" title="GPU Rigid Bodies" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2008-2021 NVIDIA Corporation, 2788 San Tomas Expressway, Santa Clara, CA 95051 U.S.A. All rights reserved
|
|
|
|
</p>
|
|
</div>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'../',
|
|
VERSION:'4.1',
|
|
LANGUAGE:'',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true,
|
|
SOURCELINK_SUFFIX: ''
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="../_static/js/theme.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.Navigation.enable(false);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |