SIMD hull collision (#93)
SIMD based hull collision inspired by example code from @cairnc in #54 <img width="1676" height="1332" alt="image" src="https://github.com/user-attachments/assets/58b137bd-bf7b-4c99-863c-64341b973a3d" /> - Fixed #78 - Fixed #85 and fixed CI to error on UB. - Updated benchmarks - Added AMD scalar benchmarks - Added Neon benchmarks - More determinism unit tests - Sample leak detection - Added b3Body_AllowFastRotation - Added b3Body_IsFastRotationAllowed - Bumped b3HullData version - Bumped b3CompoundData version
This commit is contained in:
parent
d421e45c82
commit
c37cfe4cd7
84 changed files with 3898 additions and 1151 deletions
|
|
@ -44,6 +44,12 @@ set(GFX_FILES
|
|||
|
||||
add_library(gfx STATIC ${GFX_FILES})
|
||||
|
||||
set_target_properties(gfx PROPERTIES
|
||||
C_STANDARD 17
|
||||
C_STANDARD_REQUIRED YES
|
||||
C_EXTENSIONS YES
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
set_source_files_properties(
|
||||
sokol_impl.c
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@
|
|||
// `sokol` INTERFACE target. On Apple this file is compiled as Objective-C
|
||||
// with ARC (see src/app/CMakeLists.txt) so sokol_app's Cocoa backend builds.
|
||||
//
|
||||
// SOKOL_WIN32_FORCE_MAIN: sokol_app defaults to WinMain (subsystem:windows)
|
||||
// on Windows. Our binaries are console-subsystem so the smoke test can
|
||||
// surface stderr to ctest, so force the int main variant.
|
||||
// SOKOL_NO_ENTRY: samples/main.cpp supplies its own main() so it can install
|
||||
// MSVC CRT leak reporting and dump after sapp_run returns, past sokol's own
|
||||
// teardown. Our main is console-subsystem, which also keeps stderr flowing to
|
||||
// ctest for the smoke test.
|
||||
//
|
||||
// _POSIX_C_SOURCE: glibc gates clock_gettime / CLOCK_MONOTONIC behind a
|
||||
// POSIX feature-test macro under -std=c17. Define before any system headers.
|
||||
|
|
@ -21,7 +22,7 @@
|
|||
#define SOKOL_APP_IMPL
|
||||
#define SOKOL_GLUE_IMPL
|
||||
#define SOKOL_LOG_IMPL
|
||||
#define SOKOL_WIN32_FORCE_MAIN
|
||||
#define SOKOL_NO_ENTRY
|
||||
|
||||
#include "sokol_gfx.h"
|
||||
#include "sokol_app.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
// SPDX-FileCopyrightText: 2025 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
// stdlib before crtdbg so the malloc->_malloc_dbg remap lands after the real prototype
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#include "gfx/debug_adapter.h"
|
||||
#include "gfx/keycodes.h"
|
||||
#include "gfx/renderer.h"
|
||||
|
|
@ -18,6 +28,12 @@
|
|||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
#include <tracy/Tracy.hpp>
|
||||
#else
|
||||
#define FrameMark
|
||||
#endif
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
|
|
@ -32,6 +48,7 @@ static SampleContext s_context;
|
|||
static int s_frame = 0;
|
||||
static int s_frameLimit = -1;
|
||||
static int s_sampleOverride = -1;
|
||||
static int s_exitCode = 0;
|
||||
|
||||
static int CompareSamples( const void* a, const void* b )
|
||||
{
|
||||
|
|
@ -75,6 +92,10 @@ static void OnDrawUI( void )
|
|||
|
||||
static void OnInit( void )
|
||||
{
|
||||
#ifdef TRACY_ENABLE
|
||||
tracy::StartupProfiler();
|
||||
#endif
|
||||
|
||||
#if defined( _WIN32 )
|
||||
timeBeginPeriod( 1 );
|
||||
#endif
|
||||
|
|
@ -307,12 +328,17 @@ static void OnEvent( const sapp_event* e )
|
|||
}
|
||||
}
|
||||
|
||||
// Pace the loop to 60 Hz so the fixed 1/60 physics step plays at real time on any
|
||||
// display. Sleep the bulk of the idle time, then spin the last bit since sleep wakes
|
||||
// are only accurate to about a millisecond.
|
||||
// This limits the render rate to the simulation rate. Physics debugging
|
||||
// ergonomics require render frames and simulation frames to be one to one.
|
||||
// I don't recommend this setup for games, where a decoupled render
|
||||
// and simulation rate is desirable.
|
||||
static void LimitFrameRate( uint64_t frameStart )
|
||||
{
|
||||
const float targetMs = 1000.0f / 60.0f;
|
||||
// By limiting to the simulation hertz, this allows me to run the simulation
|
||||
// at 240Hz and render at that rate when using a 240Hz monitor. It also allows
|
||||
// me to run a 10Hz simulation in at the wall clock rate.
|
||||
float hertz = b3ClampFloat(s_context.hertz, 5.0f, 1000.0f);
|
||||
const float targetMs = 1000.0f / hertz;
|
||||
const float spinMs = 2.0f;
|
||||
|
||||
int sleepMs = (int)( targetMs - spinMs - b3GetMilliseconds( frameStart ) );
|
||||
|
|
@ -424,6 +450,9 @@ static void OnFrame( void )
|
|||
sg_commit();
|
||||
++s_frame;
|
||||
|
||||
// For the Tracy profiler
|
||||
FrameMark;
|
||||
|
||||
if ( s_frameLimit < 0 )
|
||||
{
|
||||
LimitFrameRate( frameStart );
|
||||
|
|
@ -447,7 +476,13 @@ static void OnCleanup( void )
|
|||
timeEndPeriod( 1 );
|
||||
#endif
|
||||
|
||||
exit( errors == 0 ? 0 : 1 );
|
||||
#ifdef TRACY_ENABLE
|
||||
tracy::ShutdownProfiler();
|
||||
#endif
|
||||
|
||||
// Return instead of exit so sokol frees its own window and context. main
|
||||
// dumps CRT leaks once sapp_run returns, past that teardown.
|
||||
s_exitCode = errors == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
static void OnAppLog( const char* tag, uint32_t logLevel, uint32_t logItemId, const char* message, uint32_t lineNumber,
|
||||
|
|
@ -469,7 +504,7 @@ static void OnAppLog( const char* tag, uint32_t logLevel, uint32_t logItemId, co
|
|||
}
|
||||
}
|
||||
|
||||
sapp_desc sokol_main( int argc, char** argv )
|
||||
static sapp_desc BuildAppDesc( int argc, char** argv )
|
||||
{
|
||||
for ( int i = 1; i < argc; ++i )
|
||||
{
|
||||
|
|
@ -528,3 +563,23 @@ sapp_desc sokol_main( int argc, char** argv )
|
|||
|
||||
return desc;
|
||||
}
|
||||
|
||||
// We own main (SOKOL_NO_ENTRY) so the leak dump can run after sapp_run returns,
|
||||
// once sokol has torn down its window and context. On Windows sapp_run returns
|
||||
// after that teardown; on macOS it may not return, so the dump is Windows only.
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
#if defined( _MSC_VER )
|
||||
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
|
||||
#endif
|
||||
|
||||
sapp_desc desc = BuildAppDesc( argc, argv );
|
||||
sapp_run( &desc );
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
_CrtDumpMemoryLeaks();
|
||||
#endif
|
||||
|
||||
return s_exitCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1427,6 +1427,10 @@ public:
|
|||
GetGuiDraw()->drawJoints = false;
|
||||
}
|
||||
|
||||
b3Capacity capacity = {};
|
||||
GetJunkyardCapacity( &capacity );
|
||||
CreateWorld( &capacity );
|
||||
|
||||
CreateJunkyard( m_worldId );
|
||||
|
||||
SetGroundShape( GetGroundShapeId() );
|
||||
|
|
@ -1461,6 +1465,10 @@ public:
|
|||
m_camera->SetView( 45.0f, 20.0f, 150.0f, { 0.0f, 15.0f, 0.0f } );
|
||||
}
|
||||
|
||||
b3Capacity capacity = {};
|
||||
GetConvexPileCapacity( &capacity );
|
||||
CreateWorld( &capacity );
|
||||
|
||||
CreateConvexPile( m_worldId );
|
||||
|
||||
SetGroundShape( GetGroundShapeId() );
|
||||
|
|
|
|||
|
|
@ -370,8 +370,9 @@ public:
|
|||
static int sampleGyroscopicTorque = RegisterSample( "Bodies", "Gyroscopic Torque", GyroscopicTorque::Create );
|
||||
|
||||
// Spinning tops. Ported from PEEL.
|
||||
// Each top is tilted and spun about the world up axis. Offsetting the spin axis from the
|
||||
// symmetry axis is what makes them precess under gravity instead of spinning true.
|
||||
// Each top is tilted and spun about its symmetry axis. Gravity torque about the tip is what makes
|
||||
// them precess instead of toppling. The first top carries a diagnostic that compares the measured
|
||||
// precession rate against the classical heavy top solution.
|
||||
class GyroscopicPrecession : public Sample
|
||||
{
|
||||
public:
|
||||
|
|
@ -400,7 +401,7 @@ public:
|
|||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
||||
// Tilt the symmetry axis, then spin about the world up axis so the offset drives precession.
|
||||
// Tilt the top, then spin it about its own symmetry axis. Gravity does the rest.
|
||||
b3Quat rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 15.0f * B3_PI / 180.0f );
|
||||
b3Vec3 angularVelocity = b3RotateVector( rotation, { 0.0f, 75.0f, 0.0f } );
|
||||
|
||||
|
|
@ -422,16 +423,156 @@ public:
|
|||
b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
|
||||
b3Body_SetAngularVelocity( bodyId, angularVelocity );
|
||||
|
||||
if ( x == 0 && z == 0 )
|
||||
{
|
||||
m_topId = bodyId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b3DestroyHull( hull );
|
||||
|
||||
// Mass properties of the measured top. The tip sits at the body origin, so the pivot distance is
|
||||
// just the height of the center of mass, and the symmetry axis is the local up axis.
|
||||
b3MassData massData = b3Body_GetMassData( m_topId );
|
||||
m_mass = massData.mass;
|
||||
m_pivotDistance = massData.center.y;
|
||||
m_spinInertia = massData.inertia.cy.y;
|
||||
|
||||
// Transverse inertia belongs about the pivot, not the center of mass
|
||||
float transverse = 0.5f * ( massData.inertia.cx.x + massData.inertia.cz.z );
|
||||
m_transverseInertia = transverse + m_mass * m_pivotDistance * m_pivotDistance;
|
||||
|
||||
m_gravity = b3Length( b3World_GetGravity( m_worldId ) );
|
||||
|
||||
m_azimuth = 0.0f;
|
||||
m_actualAngle = 0.0f;
|
||||
m_expectedAngle = 0.0f;
|
||||
m_elapsed = 0.0f;
|
||||
m_groundTime = 0.0f;
|
||||
m_rate = 0.0f;
|
||||
m_measuring = false;
|
||||
}
|
||||
|
||||
// Steady precession rate of a heavy symmetric top about the vertical. The slow root of
|
||||
// I1 * W^2 * cos(tilt) - I3 * spin * W + M * g * d = 0. Goldstein 5.7.
|
||||
// Collapses to torque over spin momentum for a fast top.
|
||||
float ExpectedRate( float spin, float cosTilt ) const
|
||||
{
|
||||
float momentum = m_spinInertia * spin;
|
||||
float torque = m_mass * m_gravity * m_pivotDistance;
|
||||
if ( momentum <= FLT_EPSILON )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float a = m_transverseInertia * cosTilt;
|
||||
float discriminant = momentum * momentum - 4.0f * a * torque;
|
||||
if ( a <= FLT_EPSILON || discriminant < 0.0f )
|
||||
{
|
||||
// Axis at or past horizontal, or spinning too slowly to precess steadily
|
||||
return torque / momentum;
|
||||
}
|
||||
|
||||
return ( momentum - sqrtf( discriminant ) ) / ( 2.0f * a );
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
bool isAwake = b3Body_IsAwake( m_topId );
|
||||
if ( isAwake == false )
|
||||
{
|
||||
DrawTextLine( "top is sleeping" );
|
||||
return;
|
||||
}
|
||||
|
||||
b3Pos tip = b3Body_GetPosition( m_topId );
|
||||
b3Quat quat = b3Body_GetRotation( m_topId );
|
||||
b3Vec3 axis = b3RotateVector( quat, b3Vec3_axisY );
|
||||
b3Vec3 omega = b3Body_GetAngularVelocity( m_topId );
|
||||
float spin = b3Dot( omega , axis );
|
||||
float cosTilt = b3ClampFloat( axis.y, -1.0f, 1.0f );
|
||||
float expected = ExpectedRate( spin, cosTilt );
|
||||
|
||||
if ( m_didStep )
|
||||
{
|
||||
float timeStep = 1.0f / m_context->hertz;
|
||||
|
||||
// Gravity exerts no torque about the center of mass while the top is airborne, so the pivot
|
||||
// solution only applies once the tip lands. Give the landing impulse time to wash out too,
|
||||
// otherwise it biases the average for the rest of the run.
|
||||
if ( tip.y < 0.05f )
|
||||
{
|
||||
m_groundTime += timeStep;
|
||||
}
|
||||
|
||||
if ( m_measuring == false )
|
||||
{
|
||||
if ( m_groundTime > 0.5f )
|
||||
{
|
||||
m_measuring = true;
|
||||
m_azimuth = b3Atan2( -axis.z, axis.x );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Right handed angle of the symmetry axis about the world up axis
|
||||
float azimuth = b3Atan2( -axis.z, axis.x );
|
||||
float delta = b3UnwindAngle( azimuth - m_azimuth );
|
||||
m_azimuth = azimuth;
|
||||
|
||||
m_actualAngle += delta;
|
||||
m_expectedAngle += expected * timeStep;
|
||||
m_elapsed += timeStep;
|
||||
|
||||
// Nutation swings the instantaneous rate between zero and twice the mean, so filter it
|
||||
// with a one second time constant.
|
||||
float alpha = timeStep / ( timeStep + 1.0f );
|
||||
m_rate += alpha * ( delta / timeStep - m_rate );
|
||||
}
|
||||
}
|
||||
|
||||
DrawLine( tip, b3OffsetPos( tip, 5.0f * axis ), MakeColor( b3_colorYellow ) );
|
||||
|
||||
DrawTextLine( "spin %.1f rad/s, tilt %.1f deg", spin, ( 180.0f / B3_PI ) * acosf( cosTilt ) );
|
||||
DrawTextLine( "precession: expected %.4f rad/s, actual %.4f rad/s", expected, m_rate );
|
||||
|
||||
if ( m_elapsed > 0.0f )
|
||||
{
|
||||
// Average both sides over the same window. The spin decays, so the expected rate drifts with it.
|
||||
float expectedAverage = m_expectedAngle / m_elapsed;
|
||||
float actualAverage = m_actualAngle / m_elapsed;
|
||||
float error = expectedAverage != 0.0f ? 100.0f * ( actualAverage - expectedAverage ) / expectedAverage : 0.0f;
|
||||
DrawTextLine( "%.1f s average: expected %.4f, actual %.4f, error %+.1f%%", m_elapsed, expectedAverage, actualAverage,
|
||||
error );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextLine( "waiting for the tip to land" );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new GyroscopicPrecession( context );
|
||||
}
|
||||
|
||||
b3BodyId m_topId;
|
||||
float m_mass;
|
||||
float m_gravity;
|
||||
float m_pivotDistance;
|
||||
float m_spinInertia;
|
||||
float m_transverseInertia;
|
||||
float m_azimuth;
|
||||
float m_actualAngle;
|
||||
float m_expectedAngle;
|
||||
float m_elapsed;
|
||||
float m_groundTime;
|
||||
float m_rate;
|
||||
bool m_measuring;
|
||||
};
|
||||
|
||||
static int sampleGyroscopicPrecession = RegisterSample( "Bodies", "Gyroscopic Precession", GyroscopicPrecession::Create );
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "imgui.h"
|
||||
#include "sample.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "stability.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "gfx/debug_adapter.h"
|
||||
|
|
@ -741,60 +740,6 @@ public:
|
|||
|
||||
static int sampleMeshDrop = RegisterSample( "Continuous", "Mesh Drop", MeshDrop::Create );
|
||||
|
||||
class MeshDropUnitTest : public Sample
|
||||
{
|
||||
public:
|
||||
explicit MeshDropUnitTest( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Pos_zero );
|
||||
GetGuiDraw()->forceScale = 0.1f;
|
||||
}
|
||||
|
||||
m_data = CreateMeshDrop( m_worldId, b3Pos_zero );
|
||||
m_failed = false;
|
||||
}
|
||||
|
||||
~MeshDropUnitTest() override
|
||||
{
|
||||
DestroyMeshDrop( &m_data );
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
if ( m_failed == false )
|
||||
{
|
||||
if ( m_stepCount >= 300 )
|
||||
{
|
||||
b3BodyEvents bodyEvents = b3World_GetBodyEvents( m_worldId );
|
||||
if ( bodyEvents.moveCount > 0 )
|
||||
{
|
||||
m_failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_failed == true )
|
||||
{
|
||||
DrawTextLine( "failed!" );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new MeshDropUnitTest( context );
|
||||
}
|
||||
|
||||
MeshDropData m_data;
|
||||
bool m_failed;
|
||||
};
|
||||
|
||||
static int sampleMeshDropUnitTest = RegisterSample( "Continuous", "Mesh Drop Unit Test", MeshDropUnitTest::Create );
|
||||
|
||||
// This sample shows that clustering based on the manifold normal can lead to clipping and/or tunneling.
|
||||
class HumpMesh : public Sample
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "determinism.h"
|
||||
#include "gfx/debug_adapter.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "sample.h"
|
||||
#include "stability.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
|
|
@ -57,3 +60,207 @@ public:
|
|||
};
|
||||
|
||||
static int sampleFallingRagdolls = RegisterSample( "Determinism", "Falling Ragdolls", FallingRagdolls::Create );
|
||||
|
||||
class WavePile : public Sample
|
||||
{
|
||||
public:
|
||||
explicit WavePile( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 45.0f, 25.0f, 25.0f, b3Pos_zero );
|
||||
}
|
||||
|
||||
m_data = CreateWavePile( m_worldId );
|
||||
m_done = false;
|
||||
}
|
||||
|
||||
~WavePile() override
|
||||
{
|
||||
DestroyWavePile( &m_data );
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
if ( m_done == false )
|
||||
{
|
||||
// Only advance the scenario on real steps, else pausing would skew the step count
|
||||
if ( m_didStep )
|
||||
{
|
||||
m_done = UpdateWavePile( m_worldId, &m_data );
|
||||
if ( m_done )
|
||||
{
|
||||
printf( "sleep step = %d, hash = 0x%08X\n", m_data.sleepStep, m_data.hash );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextLine( "sleep step = %d, hash = 0x%08X", m_data.sleepStep, m_data.hash );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new WavePile( context );
|
||||
}
|
||||
|
||||
WavePileData m_data;
|
||||
bool m_done;
|
||||
};
|
||||
|
||||
static int sampleWavePile = RegisterSample( "Determinism", "Wave Pile", WavePile::Create );
|
||||
|
||||
class QuerySpawn : public Sample
|
||||
{
|
||||
public:
|
||||
explicit QuerySpawn( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 45.0f, 25.0f, 30.0f, b3Pos_zero );
|
||||
}
|
||||
|
||||
m_data = CreateQuerySpawn( m_worldId );
|
||||
m_frameCount = 0;
|
||||
m_done = false;
|
||||
}
|
||||
|
||||
~QuerySpawn() override
|
||||
{
|
||||
DestroyQuerySpawn( &m_data );
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
if ( m_done == false )
|
||||
{
|
||||
// Advance every 10th step so each query lingers on screen. This diverges from
|
||||
// the unit test cadence, so the hashes differ from the pinned constants.
|
||||
if ( m_didStep )
|
||||
{
|
||||
m_frameCount += 1;
|
||||
if ( m_frameCount % 10 == 1 )
|
||||
{
|
||||
m_done = UpdateQuerySpawn( m_worldId, &m_data );
|
||||
if ( m_done )
|
||||
{
|
||||
printf( "sleep step = %d, hash = 0x%08X, hits = %d, query hash = 0x%08X\n", m_data.sleepStep,
|
||||
m_data.hash, m_data.queryHitCount, m_data.queryHash );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DrawTextLine( "spawned = %d of %d, query hits = %d", m_data.spawnCount, QUERY_SPAWN_COUNT, m_data.queryHitCount );
|
||||
DrawTextLine( "ray = yellow, overlap box = magenta, sphere cast = cyan, spawn = white" );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextLine( "sleep step = %d, hash = 0x%08X", m_data.sleepStep, m_data.hash );
|
||||
DrawTextLine( "query hits = %d, query hash = 0x%08X", m_data.queryHitCount, m_data.queryHash );
|
||||
}
|
||||
}
|
||||
|
||||
void Render() override
|
||||
{
|
||||
Sample::Render();
|
||||
|
||||
if ( m_data.spawnCount == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ray with hit point and normal, red end point on a miss
|
||||
DrawLine( m_data.rayOrigin, m_data.rayPoint, MakeColor( b3_colorYellow ) );
|
||||
DrawPoint( m_data.rayOrigin, 5.0f, MakeColor( b3_colorYellow ) );
|
||||
if ( m_data.rayDidHit )
|
||||
{
|
||||
DrawPoint( m_data.rayPoint, 8.0f, MakeColor( b3_colorGreen ) );
|
||||
DrawLine( m_data.rayPoint, b3OffsetPos( m_data.rayPoint, m_data.rayNormal ), MakeColor( b3_colorGreen ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPoint( m_data.rayPoint, 5.0f, MakeColor( b3_colorRed ) );
|
||||
}
|
||||
|
||||
DrawBounds( m_data.overlapBounds, 0.0f, MakeColor( b3_colorMagenta ) );
|
||||
|
||||
// Swept sphere stopped at its cast fraction, gray when it reached full length
|
||||
b3Pos castCenter = b3OffsetPos( m_data.rayOrigin, b3MulSV( m_data.castFraction, m_data.rayTranslation ) );
|
||||
b3Sphere castSphere = { b3Vec3_zero, QUERY_SPAWN_CAST_RADIUS };
|
||||
Vec4 castColor = m_data.castFraction < 1.0f ? MakeColor( b3_colorCyan ) : MakeColor( b3_colorGray );
|
||||
DrawWireSphere( { castCenter, b3Quat_identity }, &castSphere, 24, castColor );
|
||||
|
||||
DrawCross( m_data.lastSpawnPosition, 0.5f, MakeColor( b3_colorWhite ) );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new QuerySpawn( context );
|
||||
}
|
||||
|
||||
QuerySpawnData m_data;
|
||||
int m_frameCount;
|
||||
bool m_done;
|
||||
};
|
||||
|
||||
static int sampleQuerySpawn = RegisterSample( "Determinism", "Query Spawn", QuerySpawn::Create );
|
||||
|
||||
class MeshDropDeterminism : public Sample
|
||||
{
|
||||
public:
|
||||
explicit MeshDropDeterminism( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Pos_zero );
|
||||
GetGuiDraw()->forceScale = 0.1f;
|
||||
}
|
||||
|
||||
m_data = CreateMeshDrop( m_worldId, b3Pos_zero );
|
||||
m_done = false;
|
||||
}
|
||||
|
||||
~MeshDropDeterminism() override
|
||||
{
|
||||
DestroyMeshDrop( &m_data );
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
if ( m_done == false )
|
||||
{
|
||||
if ( m_didStep )
|
||||
{
|
||||
m_done = UpdateMeshDrop( m_worldId, &m_data );
|
||||
if ( m_done )
|
||||
{
|
||||
printf( "sleep step = %d, hash = 0x%08X\n", m_data.sleepStep, m_data.hash );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextLine( "sleep step = %d, hash = 0x%08X", m_data.sleepStep, m_data.hash );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new MeshDropDeterminism( context );
|
||||
}
|
||||
|
||||
MeshDropData m_data;
|
||||
bool m_done;
|
||||
};
|
||||
|
||||
static int sampleMeshDropDeterminism = RegisterSample( "Determinism", "Mesh Drop", MeshDropDeterminism::Create );
|
||||
|
|
|
|||
|
|
@ -10,45 +10,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
class DumpLoader : public Sample
|
||||
{
|
||||
public:
|
||||
explicit DumpLoader( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } );
|
||||
// m_camera->SetView( 45.0f, 30.0f, 300.0f, { 3910.62109f, 9862.50293f, 875.395081f } );
|
||||
}
|
||||
|
||||
b3SetLengthUnitsPerMeter( 1.0f );
|
||||
|
||||
const char* dumpPrefix = "data/dumps/single_box/";
|
||||
|
||||
#include "dumps/single_box/box3d_dump.inl"
|
||||
}
|
||||
|
||||
~DumpLoader() override
|
||||
{
|
||||
for ( b3MeshData* md : m_meshes )
|
||||
{
|
||||
b3DestroyMesh( md );
|
||||
}
|
||||
|
||||
b3SetLengthUnitsPerMeter( 1.0f );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new DumpLoader( context );
|
||||
}
|
||||
|
||||
std::vector<b3MeshData*> m_meshes;
|
||||
};
|
||||
|
||||
static int sampleDumpLoader = RegisterSample( "Issues", "Dump Loader", DumpLoader::Create );
|
||||
|
||||
class Crash : public Sample
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public:
|
|||
bodyDef.type = b3_dynamicBody;
|
||||
for ( int index = 0; index < m_boxCount; ++index )
|
||||
{
|
||||
bodyDef.position = { -10.0f + 5.0f * index, 15.75f, -10.6f };
|
||||
bodyDef.position = { -10.0f + 5.0f * index, 14.25f, -10.6f };
|
||||
b3BodyId boxBody = b3CreateBody( m_worldId, &bodyDef );
|
||||
shapeDef.baseMaterial.friction = ( index + 1 ) * ( index + 1 ) * 0.04f;
|
||||
b3CreateHullShape( boxBody, &shapeDef, &box.base );
|
||||
|
|
|
|||
|
|
@ -11,84 +11,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
class CardHouseThick : public Sample
|
||||
{
|
||||
public:
|
||||
explicit CardHouseThick( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 25.0f, 10.0f, { 0.0f, 2.0f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 10.0f );
|
||||
|
||||
const float alpha = 25.0f * B3_DEG_TO_RAD;
|
||||
const float width = 0.38f;
|
||||
const float height = 0.98f;
|
||||
const float depth = 0.08f;
|
||||
|
||||
float offsetX = 0.5f * height * b3Sin( alpha ) + 0.045f;
|
||||
float offsetY = 0.5f * height * b3Cos( alpha ) + 0.035f;
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( 0.5f * depth, 0.5f * height, 0.5f * width );
|
||||
AddVerticalRow( 4, -6.0f * offsetX, offsetX, offsetY, alpha, box );
|
||||
AddHorizontalRow( 3, -4.0f * offsetX, 4.0f * offsetX, 2.0f * offsetY + 0.04f, box );
|
||||
AddVerticalRow( 3, -4.0f * offsetX, offsetX, 3.0f * offsetY + 0.08f, alpha, box );
|
||||
AddHorizontalRow( 2, -2.0f * offsetX, 4.0f * offsetX, 4.0f * offsetY + 0.12f, box );
|
||||
AddVerticalRow( 2, -2.0f * offsetX, offsetX, 5.0f * offsetY + 0.16f, alpha, box );
|
||||
AddHorizontalRow( 1, -0.0f * offsetX, 4.0f * offsetX, 6.0f * offsetY + 0.20f, box );
|
||||
AddVerticalRow( 1, -0.0f * offsetX, offsetX, 7.0f * offsetY + 0.24f, alpha, box );
|
||||
}
|
||||
|
||||
void AddVerticalRow( int n, float startX, float offsetX, float startY, float alpha, const b3BoxHull& box )
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.friction = 0.8f;
|
||||
|
||||
for ( int index = 0; index < n; ++index )
|
||||
{
|
||||
bodyDef.position = { startX - offsetX, startY, 0.0f };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, -alpha );
|
||||
b3BodyId body1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( body1, &shapeDef, &box.base );
|
||||
|
||||
bodyDef.position = { startX + offsetX, startY, 0.0f };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, alpha );
|
||||
b3BodyId body2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( body2, &shapeDef, &box.base );
|
||||
|
||||
startX += 4.0f * offsetX;
|
||||
}
|
||||
}
|
||||
|
||||
void AddHorizontalRow( int n, float startX, float offsetX, float startY, const b3BoxHull& box )
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.friction = 0.8f;
|
||||
|
||||
for ( int index = 0; index < n; ++index )
|
||||
{
|
||||
bodyDef.position = { startX + index * offsetX, startY, 0.0f };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI );
|
||||
b3BodyId body = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( body, &shapeDef, &box.base );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new CardHouseThick( context );
|
||||
}
|
||||
};
|
||||
|
||||
static int sampleCardHouseThick = RegisterSample( "Stacking", "Card House Thick", CardHouseThick::Create );
|
||||
|
||||
// From PEEL
|
||||
class CardHouse : public Sample
|
||||
{
|
||||
|
|
@ -104,6 +26,7 @@ public:
|
|||
AddGroundBox( 10.0f );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = 0.05f;
|
||||
shapeDef.baseMaterial.friction = 0.7f;
|
||||
|
||||
float cardHeight = 0.2f;
|
||||
|
|
@ -287,7 +210,7 @@ public:
|
|||
bodyDef.name = "cube";
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = { 0.0f, 0.5f, 0.0f };
|
||||
bodyDef.angularVelocity = { 0.0f, 10.0f, 0.0f };
|
||||
//bodyDef.angularVelocity = { 0.0f, 10.0f, 0.0f };
|
||||
m_bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
|
@ -430,7 +353,7 @@ public:
|
|||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 20.0f, 0.0f } );
|
||||
m_camera->SetView( 40.0f, 15.0f, 50.0f, { 0.0f, 20.0f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 40.0f );
|
||||
|
|
@ -441,7 +364,6 @@ public:
|
|||
bodyDef.type = b3_dynamicBody;
|
||||
|
||||
b3BoxHull cube = b3MakeBoxHull( a, a, a );
|
||||
// b3Quat q = b3MakeQuatFromAxisAngle( { 1.0f, 0.0f, 0.0f }, 0.5f * B3_PI );
|
||||
|
||||
for ( int i = 0; i < 40; ++i )
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue