NDEVR
API Documentation
GravityIntersection

Computes gravity-based intersection transforms by casting rays along a gravity vector and finding where they intersect scene geometry. More...

Collaboration diagram for GravityIntersection:
[legend]

Public Member Functions

Matrix< fltp08calculateIntersection () const
 Calculates an intersection transform by projecting query points along the gravity vector and fitting a rotation and translation from original positions to intersection positions.
void setup (DesignObjectLookup *lookup, const Matrix< fltp08 > &mat, const Buffer< Vertex< 3, fltp08 > > &points)
 Initializes the gravity intersection with the required scene context, transform, and query points.

Static Public Member Functions

static Buffer< Vertex< 3, fltp08 > > FilterSamples (fltp08 cluster_distance, Buffer< Vertex< 3, fltp08 > > clustered_points, Vertex< 3, fltp08 > center)
 Filters a set of points by iteratively extracting the lowest-Z point and removing nearby neighbors within a clustering distance.
static Buffer< Vertex< 3, fltp08 > > FindGravityPoints (const Model &model, fltp08 delta, fltp08 max)
 Generates a set of gravity sample points by casting vertical rays through a model's bounding area.
static Vertex< 3, fltp08LowestPoint (const Buffer< Vertex< 3, fltp08 > > &clustered_points)
 Finds the vertex with the lowest Z coordinate from a set of points.

Protected Attributes

Matrix< fltp08m_current_transform
 The transformation matrix applied to query points before performing intersection queries.
Vector< 3, fltp08m_gravity_vector = Vector<3, fltp08>(0, 0, -1)
 The direction of gravity used for raycasting. Defaults to downward along the Z axis.
DesignObjectLookupm_lookup = nullptr
 Pointer to the scene lookup used for selection/intersection queries. Not owned by this class.
fltp08 m_max_fall_height = 100.0
 The maximum distance to cast rays along the gravity vector in each direction from a query point.
Buffer< Vertex< 3, fltp08 > > m_query_points
 The set of local-space query points to project along the gravity vector.

Detailed Description

Computes gravity-based intersection transforms by casting rays along a gravity vector and finding where they intersect scene geometry.

GravityIntersection projects a set of query points along a gravity direction, finds the nearest surface intersections in the scene, and computes a best-fit rotation and translation matrix that aligns the original point plane to the intersection point plane. This is useful for settling or dropping objects onto terrain or other surfaces.

Definition at line 16 of file GravityIntersection.h.

Member Function Documentation

◆ calculateIntersection()

Matrix< fltp08 > GravityIntersection::calculateIntersection ( ) const
inline

Calculates an intersection transform by projecting query points along the gravity vector and fitting a rotation and translation from original positions to intersection positions.

The method casts line segments along the gravity vector from each query point, performs selection queries against the scene to find nearest surface hits, then computes a best-fit plane for both the original and intersection point sets. A rotation matrix is derived using Rodrigues' rotation formula to align the two planes, combined with an average translation offset.

Returns
A transformation matrix combining rotation and translation to move objects from their current positions to the gravity-intersected surface. Returns identity if fewer than 3 query points are provided or fewer than 3 valid intersections are found.
Note
The rotation is computed via Rodrigues' formula using the cross product and dot product of the two plane normals. The translation is the average displacement from original to intersection points. It is unclear why the min-heap is initialized with capacity 4 but the size check requires 3 – the commented-out heap pruning logic suggests this may have been intended to keep only the best 3 intersections.

Definition at line 38 of file GravityIntersection.h.

References Buffer< t_type, t_memory_manager >::add(), allow_interactions, cast(), SelectionInfo::clearLastSelection(), cross(), SelectionInfo::current_selection, dot(), SelectionInfo::is_exact, IsInvalid(), IsValid(), LineSegment< t_dims, t_type, t_vertex >::lengthSquared(), m_current_transform, m_gravity_vector, m_lookup, m_max_fall_height, m_query_points, SelectionInfo::min_screen_cutoff_distance, ModelIterator::model_filter, SelectionInfo::nearest_line, SelectionInfo::nearest_point, SelectionInfo::nearest_solid, SelectionInfo::nearestScreenLocation(), Vector< t_dims, t_type >::normalized(), SelectionInfo::ClosestModelInfo::screen_distance, skew(), and spacial_visible.

◆ FilterSamples()

Buffer< Vertex< 3, fltp08 > > GravityIntersection::FilterSamples ( fltp08 cluster_distance,
Buffer< Vertex< 3, fltp08 > > clustered_points,
Vertex< 3, fltp08 > center )
inlinestatic

Filters a set of points by iteratively extracting the lowest-Z point and removing nearby neighbors within a clustering distance.

For each iteration, the point with the lowest Z value is found. All points within the specified cluster distance are removed from the input set. Among tied Z values, the point closest to the provided center is preferred. This produces a reduced set of representative low points spread across the spatial domain.

Parameters
[in]cluster_distanceThe squared distance threshold for clustering nearby points.
[in]clustered_pointsThe input buffer of points to filter (consumed during processing).
[in]centerA reference center point used to break ties among equal-Z candidates.
Returns
A buffer of filtered representative points, one per cluster.
Note
The cluster_distance parameter is compared against squared distances (via distanceSquared), so callers should pass a non-squared distance value only if distanceSquared internally returns non-squared results. This naming may be misleading.

Definition at line 243 of file GravityIntersection.h.

References Buffer< t_type, t_memory_manager >::add(), IsValid(), and LowestPoint().

Referenced by FindGravityPoints().

◆ FindGravityPoints()

Buffer< Vertex< 3, fltp08 > > GravityIntersection::FindGravityPoints ( const Model & model,
fltp08 delta,
fltp08 max )
inlinestatic

Generates a set of gravity sample points by casting vertical rays through a model's bounding area.

Iterates over a 2D grid within the model's XY bounding box, casting vertical line segments upward from the minimum Z. For each grid cell, the nearest surface intersection is recorded. The resulting points are then filtered by clustering to remove duplicates, and transformed back into the model's local coordinate space.

Parameters
[in]modelThe model whose geometry is sampled for gravity intersection points.
[in]deltaA fraction of the model's largest bounding dimension used as the grid step size.
[in]maxThe maximum ray length (height) for vertical intersection queries.
Returns
A buffer of gravity sample points in the model's local coordinate space.

Definition at line 171 of file GravityIntersection.h.

References Set< t_value >::add(), Bounds< t_dims, t_type, t_vertex >::center(), SelectionInfo::clearLastSelection(), SelectionInfo::current_selection, FilterSamples(), Model::getBoundsOfVisible(), Model::getCompleteTransform(), SelectionInfo::is_exact, IsValid(), SelectionInfo::min_screen_cutoff_distance, SelectionInfo::nearest_line, SelectionInfo::nearest_point, SelectionInfo::nearest_solid, SelectionInfo::nearestScreenLocation(), ModelIterator::parseAll(), SelectionInfo::ClosestModelInfo::screen_distance, Bounds< t_dims, t_type, t_vertex >::span(), SelectionInfo::use_interaction_flag, and Set< t_value >::values().

◆ LowestPoint()

Vertex< 3, fltp08 > GravityIntersection::LowestPoint ( const Buffer< Vertex< 3, fltp08 > > & clustered_points)
inlinestatic

Finds the vertex with the lowest Z coordinate from a set of points.

Parameters
[in]clustered_pointsThe buffer of 3D points to search through.
Returns
The vertex with the minimum Z value. Returns a vertex initialized to the maximum representable value if the buffer is empty.

Definition at line 211 of file GravityIntersection.h.

Referenced by FilterSamples().

◆ setup()

void GravityIntersection::setup ( DesignObjectLookup * lookup,
const Matrix< fltp08 > & mat,
const Buffer< Vertex< 3, fltp08 > > & points )
inline

Initializes the gravity intersection with the required scene context, transform, and query points.

Parameters
[in]lookupThe design object lookup used for performing selection queries against scene geometry.
[in]matThe current transformation matrix applied to the query points before raycasting.
[in]pointsThe set of query points (in local space) to project along the gravity vector.

Definition at line 150 of file GravityIntersection.h.

References m_current_transform, m_lookup, and m_query_points.


The documentation for this class was generated from the following file: