11#include <QScopedPointer>
15#include "BulletClosestRayCallback.h"
16#include "BulletTargetShape.h"
18#include "IException.h"
19#include "IsisBullet.h"
20#include "SurfacePoint.h"
22#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
32 btCollisionWorld::ClosestRayResultCallback(btVector3(0,0,0), btVector3(0,0,0)),
33 m_point(0.0, 0.0, 0.0), m_normal(0.0, 0.0, 0.0),
34 m_triangleIndex(-1), m_partId(-1) {
51 const btVector3 &point,
52 const btVector3 &normal) :
53 btCollisionWorld::ClosestRayResultCallback(result.observer(), result.lookdir()) {
68 const btVector3 &lookdir) :
69 btCollisionWorld::ClosestRayResultCallback(observer, lookdir),
70 m_point(0.0, 0.0, 0.0), m_normal(0.0, 0.0, 0.0),
71 m_triangleIndex(-1), m_partId(-1) {
95 const btVector3 &lookdir,
96 const btCollisionWorld::RayResultCallback &source,
97 btCollisionWorld::LocalRayResult &rayResult,
98 bool normalInWorldSpace) :
99 btCollisionWorld::ClosestRayResultCallback(observer, lookdir),
100 m_point(0.0, 0.0, 0.0), m_normal(0.0, 0.0, 0.0),
101 m_triangleIndex(-1), m_partId(-1) {
131 return ( ClosestRayResultCallback::m_rayFromWorld );
141 return ( ClosestRayResultCallback::m_rayToWorld );
158 return ( RayResultCallback::m_closestHitFraction );
172 "No hits in ray trace so no surface point!",
174 return ( btVector3(0.0, 0.0, 0.0) );
189 "No hits in ray trace so no normal!",
191 return btVector3(0.0, 0.0, 0.0);
222 if ( !
isValid() )
return (DBL_MAX);
239 if ( !(
isValid() && other.isValid()) )
return (DBL_MAX);
253 if ( !
isValid() )
return (DBL_MAX);
267 if ( !(
isValid() && other.isValid()) )
return (
false);
268 if (
triangleIndex() != other.triangleIndex() )
return (
false);
269 if (
partId() != other.partId() )
return (
false);
292 const btScalar tolerance)
const {
293 if ( !(
isValid() && other.isValid()) )
return (
false);
294 if (
triangleIndex() != other.triangleIndex() )
return (
false);
295 if (
partId() != other.partId() )
return (
false);
298 if (
distance( other ) > tolerance )
return (
false );
315 return (
static_cast<const BulletTargetShape *
> (m_collisionObject->getUserPointer()) );
334 bool normalInWorldSpace) {
335 btScalar hitFraction = ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
337 m_point = m_hitPointWorld;
342 m_partId = rayResult.m_localShapeInfo->m_shapePart;
343 return (hitFraction);
354 return ( (btTriangleRaycastCallback::kF_FilterBackfaces |
355 btTriangleRaycastCallback::kF_KeepUnflippedNormal |
356 btTriangleRaycastCallback::kF_UseGjkConvexCastRaytest) );
366 const btCollisionWorld::RayResultCallback &source) {
Bullet ray tracing callback for closest hit on target surface.
void copyRayResult(btCollisionWorld::RayResultCallback &dest, const btCollisionWorld::RayResultCallback &source)
Easy way to copy one callback into another.
btScalar fraction() const
Return the intersection hit fraction or fractional distance along the ray of the intersection.
btScalar distance() const
Returns the distance from the intersection point to the beginning of the ray.
btVector3 m_normal
! The intersection point in body fixed (x, y, z) kilometers.
btVector3 lookdir() const
Return the end of the ray.
int m_partId
! The 0-based index of the intersected triangle.
bool isValid() const
Checks if the callback is valid/has a valid intersection.
virtual ~BulletClosestRayCallback()
Destory a callback.
int triangleIndex() const
Return the 0-based index of the intersected triangle.
btVector3 point() const
Return the intersection point, if one exists.
bool operator==(const BulletClosestRayCallback &other) const
Equality operator to check if this callback is equivalent to another callback.
unsigned int defaultFlags() const
Return the default ray cast flags.
bool isVisible(const BulletClosestRayCallback &other, const btScalar tolerance=DBL_MAX) const
Check if the intersection in this is visible based on another callback.
btVector3 normal() const
Return the local surface normal at the intersection, if an intersection exists.
int partId() const
Return the Bullet ID of the intersected collision object.
BulletClosestRayCallback()
Default constructor.
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace)
! The Bullet ID of the intersected collision object.
const BulletTargetShape * body() const
@breif Return pointer to target shape
int m_triangleIndex
! The local surface normal at the intersection point in body fixed (x, y, z).
btVector3 observer() const
Return the beginning of the ray.
Bullet Target Shape for planetary bodies.
@ Programmer
This error is for when a programmer made an API call that was illegal.
This is free and unencumbered software released into the public domain.