generate contact when body type changes at runtime, decoupling, add first ray cast hit query to world query (more to add later such as sphere/box/convex casts), hotfix
This commit is contained in:
@ -61,9 +61,9 @@ public:
|
||||
|
||||
void RayHit()
|
||||
{
|
||||
if (m_rayHit.m_shape)
|
||||
if (m_rayHit.shape)
|
||||
{
|
||||
if (m_rayHit.m_shape->GetBody() != m_character)
|
||||
if (m_rayHit.shape->GetBody() != m_character)
|
||||
{
|
||||
Test::RayHit();
|
||||
}
|
||||
@ -72,12 +72,12 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
if (m_rayHit.m_shape)
|
||||
if (m_rayHit.shape)
|
||||
{
|
||||
if (m_rayHit.m_shape->GetBody() != m_character)
|
||||
if (m_rayHit.shape->GetBody() != m_character)
|
||||
{
|
||||
b3Vec3 point = m_rayHit.m_point;
|
||||
b3Vec3 normal = m_rayHit.m_normal;
|
||||
b3Vec3 point = m_rayHit.point;
|
||||
b3Vec3 normal = m_rayHit.normal;
|
||||
|
||||
const b3Transform& xf = m_character->GetTransform();
|
||||
b3Vec3 n = point - xf.position;
|
||||
|
@ -206,16 +206,16 @@ public:
|
||||
{
|
||||
// Perform the ray cast
|
||||
RayCastListener listener;
|
||||
m_world.RayCast(&listener, p1, p2);
|
||||
listener.hit.shape = NULL;
|
||||
m_world.RayCastFirst(&listener, p1, p2);
|
||||
|
||||
i32 hitId = listener.FindClosestHit();
|
||||
if (hitId >= 0)
|
||||
RayCastHit hit = listener.hit;
|
||||
if (hit.shape)
|
||||
{
|
||||
// Replace current hit
|
||||
RayCastHit hit = listener.m_hits[hitId];
|
||||
g_debugDraw->DrawSegment(p1, hit.m_point, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(hit.m_point, b3Color(1.0f, 0.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(hit.m_point, hit.m_point + hit.m_normal, b3Color(1.0f, 1.0f, 1.0f));
|
||||
g_debugDraw->DrawSegment(p1, hit.point, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(hit.point, b3Color(1.0f, 0.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(hit.point, hit.point + hit.normal, b3Color(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -19,10 +19,11 @@
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
||||
#include <bounce/bounce.h>
|
||||
|
||||
#include <glfw/glfw3.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include "../framework/debug_draw.h"
|
||||
#include <bounce/bounce.h>
|
||||
|
||||
struct Settings
|
||||
{
|
||||
@ -83,53 +84,14 @@ struct TestEntry
|
||||
TestCreate create;
|
||||
};
|
||||
|
||||
enum TestType
|
||||
{
|
||||
// Collision
|
||||
e_QHull,
|
||||
e_Cluster,
|
||||
e_Distance,
|
||||
e_CapsuleDistance,
|
||||
e_CapsuleAndCapsule,
|
||||
e_CapsuleAndHull,
|
||||
e_HullAndHull,
|
||||
// Dynamics
|
||||
// Joints
|
||||
e_NewtonCradle,
|
||||
e_Vehicle,
|
||||
e_Door,
|
||||
e_HingeChain,
|
||||
e_Ragdoll,
|
||||
// Contacts
|
||||
e_Quadric,
|
||||
e_MeshContact,
|
||||
// World
|
||||
e_SphereStack,
|
||||
e_CapsuleStack,
|
||||
e_BoxStack,
|
||||
e_ShapeStack,
|
||||
e_Jenga,
|
||||
e_Thin,
|
||||
e_Pyramid,
|
||||
e_Pyramids,
|
||||
// World Queries
|
||||
e_RayCast,
|
||||
e_SensorTest,
|
||||
e_Character,
|
||||
e_BodyTypes,
|
||||
e_VaryingFriction,
|
||||
e_VaryingRestitution,
|
||||
e_testCount
|
||||
};
|
||||
|
||||
extern TestEntry g_tests[e_testCount];
|
||||
extern TestEntry g_tests[];
|
||||
|
||||
struct RayCastHit
|
||||
{
|
||||
b3Shape* m_shape;
|
||||
b3Vec3 m_point;
|
||||
b3Vec3 m_normal;
|
||||
float32 m_fraction;
|
||||
b3Shape* shape;
|
||||
b3Vec3 point;
|
||||
b3Vec3 normal;
|
||||
float32 fraction;
|
||||
};
|
||||
|
||||
class RayCastListener : public b3RayCastListener
|
||||
@ -137,35 +99,14 @@ class RayCastListener : public b3RayCastListener
|
||||
public:
|
||||
float32 ReportShape(b3Shape* shape, const b3Vec3& point, const b3Vec3& normal, float32 fraction)
|
||||
{
|
||||
RayCastHit hit;
|
||||
hit.m_shape = shape;
|
||||
hit.m_point = point;
|
||||
hit.m_normal = normal;
|
||||
hit.m_fraction = fraction;
|
||||
|
||||
m_hits.PushBack(hit);
|
||||
|
||||
// Continue.
|
||||
hit.shape = shape;
|
||||
hit.point = point;
|
||||
hit.normal = normal;
|
||||
hit.fraction = fraction;
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
int FindClosestHit() const
|
||||
{
|
||||
float32 minFraction = FLT_MAX;
|
||||
int minIndex = -1;
|
||||
for (u32 i = 0; i < m_hits.Count(); ++i)
|
||||
{
|
||||
const RayCastHit* hit = m_hits.Get(i);
|
||||
if (hit->m_fraction < minFraction)
|
||||
{
|
||||
minFraction = hit->m_fraction;
|
||||
minIndex = i;
|
||||
}
|
||||
}
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
b3StackArray<RayCastHit, 256> m_hits;
|
||||
RayCastHit hit;
|
||||
};
|
||||
|
||||
class Test : public b3ContactListener
|
||||
|
Reference in New Issue
Block a user