|
|
@@ -35,15 +35,15 @@ namespace crown
|
|
|
{
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
-Raycast::Raycast(PxScene* scene, EventStream& events, const char* callback, CollisionMode::Enum mode, CollisionType::Enum filter)
|
|
|
+Raycast::Raycast(PxScene* scene, EventStream& events, const char* callback, CollisionMode::Enum mode, CollisionType::Enum type)
|
|
|
: m_scene(scene)
|
|
|
, m_buffer(m_hits, CE_MAX_RAY_INTERSECTIONS)
|
|
|
, m_events(events)
|
|
|
, m_callback(callback)
|
|
|
, m_mode(mode)
|
|
|
- , m_filter(filter)
|
|
|
+ , m_type(type)
|
|
|
{
|
|
|
- switch (m_filter)
|
|
|
+ switch (m_type)
|
|
|
{
|
|
|
case CollisionType::BOTH: break;
|
|
|
case CollisionType::STATIC: m_fd.flags = PxQueryFlag::eSTATIC; break;
|
|
|
@@ -59,57 +59,39 @@ Raycast::Raycast(PxScene* scene, EventStream& events, const char* callback, Coll
|
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
-void Raycast::cast(const Vector3& from, const Vector3& dir, const float length)
|
|
|
+void Raycast::cast(const Vector3& from, const Vector3& dir, const float length, List<RaycastHit>& hits)
|
|
|
{
|
|
|
- bool hit = m_scene->raycast(PxVec3(from.x, from.y, from.z), PxVec3(dir.x, dir.y, dir.z), length,
|
|
|
- m_buffer, PxHitFlags(PxHitFlag::eDEFAULT), m_fd);
|
|
|
+ m_scene->raycast(PxVec3(from.x, from.y, from.z), PxVec3(dir.x, dir.y, dir.z), length, m_buffer, PxHitFlags(PxHitFlag::eDEFAULT), m_fd);
|
|
|
|
|
|
for (uint32_t i = 0; i < m_buffer.getNbAnyHits(); i++)
|
|
|
{
|
|
|
PxRaycastHit rh = m_buffer.getAnyHit(i);
|
|
|
|
|
|
- physics_world::SceneQueryEvent ev;
|
|
|
-
|
|
|
- ev.type = SceneQueryType::RAYCAST;
|
|
|
- ev.mode = m_mode;
|
|
|
- ev.hit = hit;
|
|
|
- ev.callback = m_callback;
|
|
|
- ev.position.x = rh.position.x;
|
|
|
- ev.position.y = rh.position.y;
|
|
|
- ev.position.z = rh.position.z;
|
|
|
- ev.distance = rh.distance;
|
|
|
- ev.normal.x = rh.normal.x;
|
|
|
- ev.normal.y = rh.normal.y;
|
|
|
- ev.normal.z = rh.normal.z;
|
|
|
- ev.actor = (Actor*)(rh.actor->userData);
|
|
|
-
|
|
|
- event_stream::write(m_events, physics_world::EventType::SCENE_QUERY, ev);
|
|
|
-
|
|
|
- Log::i("callback: %s", ev.callback);
|
|
|
- Log::i("position: (%f, %f, %f)", ev.position.x, ev.position.y, ev.position.z);
|
|
|
- Log::i("normal: (%f, %f, %f)", ev.normal.x, ev.normal.y, ev.normal.z);
|
|
|
- Log::i("distance: %f", ev.distance);
|
|
|
+ RaycastHit hit;
|
|
|
+
|
|
|
+ hit.position.x = rh.position.x;
|
|
|
+ hit.position.y = rh.position.y;
|
|
|
+ hit.position.z = rh.position.z;
|
|
|
+ hit.distance = rh.distance;
|
|
|
+ hit.normal.x = rh.normal.x;
|
|
|
+ hit.normal.y = rh.normal.y;
|
|
|
+ hit.normal.z = rh.normal.z;
|
|
|
+ hit.actor = (Actor*)(rh.actor->userData);
|
|
|
+
|
|
|
+ hits.push_back(hit);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
-Actor* Raycast::sync_cast(const Vector3& from, const Vector3& dir, const float length)
|
|
|
+CollisionMode::Enum Raycast::mode() const
|
|
|
{
|
|
|
- bool hit = m_scene->raycast(PxVec3(from.x, from.y, from.z), PxVec3(dir.x, dir.y, dir.z), length,
|
|
|
- m_buffer, PxHitFlags(PxHitFlag::eDEFAULT), m_fd);
|
|
|
-
|
|
|
- if (hit)
|
|
|
- {
|
|
|
- PxRaycastHit rh = m_buffer.getAnyHit(0);
|
|
|
-
|
|
|
- Log::i("callback: %s", m_callback);
|
|
|
- Log::i("position: (%f, %f, %f)", rh.position.x, rh.position.y, rh.position.z);
|
|
|
- Log::i("distance: %f", rh.distance);
|
|
|
-
|
|
|
- return (Actor*)(rh.actor->userData);
|
|
|
- }
|
|
|
- else return NULL;
|
|
|
+ return m_mode;
|
|
|
}
|
|
|
|
|
|
+//-------------------------------------------------------------------------
|
|
|
+CollisionType::Enum Raycast::type() const
|
|
|
+{
|
|
|
+ return m_type;
|
|
|
+}
|
|
|
|
|
|
} // namespace crown
|