Draw sleep velocity (#49)
- draw sleep velocity for debugging - added back shape names with B3_SHAPE_NAME_LENGTH - zup command line option
This commit is contained in:
parent
0f6fdad541
commit
540ea387b0
28 changed files with 554 additions and 132 deletions
|
|
@ -219,6 +219,7 @@ void ApplyGuiFlags( b3DebugDraw* out )
|
|||
out->drawJointExtras = s_adapter.guiDraw.drawJointExtras;
|
||||
out->drawBounds = s_adapter.guiDraw.drawBounds;
|
||||
out->drawMass = s_adapter.guiDraw.drawMass;
|
||||
out->drawSleep = s_adapter.guiDraw.drawSleep;
|
||||
out->drawBodyNames = s_adapter.guiDraw.drawBodyNames;
|
||||
out->drawContacts = s_adapter.guiDraw.drawContacts;
|
||||
out->drawAnchorA = s_adapter.guiDraw.drawAnchorA;
|
||||
|
|
|
|||
|
|
@ -493,6 +493,10 @@ sapp_desc sokol_main( int argc, char** argv )
|
|||
s_sampleOverride = g_replayIndex;
|
||||
}
|
||||
}
|
||||
else if ( strcmp( argv[i], "--zup" ) == 0 )
|
||||
{
|
||||
s_context.viewZUp = true;
|
||||
}
|
||||
}
|
||||
|
||||
sapp_desc desc{};
|
||||
|
|
|
|||
|
|
@ -1633,6 +1633,7 @@ static void DrawMenuBar( SampleContext* context )
|
|||
ImGui::MenuItem( "Joint Extras", nullptr, &gd->drawJointExtras );
|
||||
ImGui::MenuItem( "Bounds", nullptr, &gd->drawBounds );
|
||||
ImGui::MenuItem( "Mass", nullptr, &gd->drawMass );
|
||||
ImGui::MenuItem( "Sleep", nullptr, &gd->drawSleep );
|
||||
ImGui::MenuItem( "Body Names", nullptr, &gd->drawBodyNames );
|
||||
ImGui::MenuItem( "Graph Colors", nullptr, &gd->drawGraphColors );
|
||||
ImGui::MenuItem( "Islands", nullptr, &gd->drawIslands );
|
||||
|
|
|
|||
|
|
@ -369,6 +369,76 @@ public:
|
|||
|
||||
static int sampleGyroscopicTorque = RegisterSample( "Bodies", "Gyroscopic Torque", GyroscopicTorque::Create );
|
||||
|
||||
// todo this doesn't behave correctly because the friction center is influenced by speculative points
|
||||
#if 0
|
||||
// Spinning tops.
|
||||
// Ported from PEEL (GyroscopicPrecession).
|
||||
class GyroscopicPrecession : public Sample
|
||||
{
|
||||
public:
|
||||
explicit GyroscopicPrecession( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 25.0f, 55.0f, { 0.0f, 2.0f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 30.0f );
|
||||
|
||||
// Top shape: a wide n-gon rim up top and a point at the origin, so it balances on its tip.
|
||||
constexpr int numSegs = 7;
|
||||
constexpr float r = 2.0f;
|
||||
constexpr float h = 2.0f;
|
||||
b3Vec3 hullPoints[numSegs + 1];
|
||||
const float dphi = 2.0f * B3_PI / numSegs;
|
||||
for ( int i = 0; i < numSegs; ++i )
|
||||
{
|
||||
hullPoints[i] = { r * cosf( i * dphi ), h, r * sinf( i * dphi ) };
|
||||
}
|
||||
hullPoints[numSegs] = b3Vec3_zero;
|
||||
b3HullData* hull = b3CreateHull( hullPoints, numSegs + 1, numSegs + 1 );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
||||
// Tilt the symmetry axis, then spin about that tilted axis so gravity induces precession.
|
||||
b3Quat rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 15.0f * B3_PI / 180.0f );
|
||||
b3Vec3 angularVelocity = b3RotateVector( rotation, { 0.0f, 75.0f, 0.0f } );
|
||||
|
||||
constexpr int count = 1;
|
||||
constexpr float separation = 6.0f;
|
||||
for ( int x = 0; x < count; ++x )
|
||||
{
|
||||
for ( int z = 0; z < count; ++z )
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = { ( x - count / 2 ) * separation, h, ( z - count / 2 ) * separation };
|
||||
bodyDef.rotation = rotation;
|
||||
bodyDef.gravityScale = 0.0f;
|
||||
|
||||
// The spin rate exceeds the default cap, so bypass it as the test intends.
|
||||
bodyDef.allowFastRotation = true;
|
||||
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
|
||||
b3Body_SetAngularVelocity( bodyId, angularVelocity );
|
||||
}
|
||||
}
|
||||
|
||||
b3DestroyHull( hull );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new GyroscopicPrecession( context );
|
||||
}
|
||||
};
|
||||
|
||||
static int sampleGyroscopicPrecession = RegisterSample( "Bodies", "Gyroscopic Precession", GyroscopicPrecession::Create );
|
||||
#endif
|
||||
|
||||
class Weeble : public Sample
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -778,9 +778,9 @@ public:
|
|||
ImGui::TextColored( PanelColor( b3_colorRed ), "****DIVERGED****" );
|
||||
}
|
||||
|
||||
const char* phaseTag = b3RecPlayer_IsAtEnd( m_player ) ? " (end)"
|
||||
const char* phaseTag = b3RecPlayer_IsAtEnd( m_player ) ? " (end)"
|
||||
: b3RecPlayer_IsAtPreStep( m_player ) ? " (pre-step)"
|
||||
: "";
|
||||
: "";
|
||||
ImGui::TextDisabled( "Frame %d / %d%s", b3RecPlayer_GetFrame( m_player ), m_info.frameCount, phaseTag );
|
||||
|
||||
// Selection detail lives here in the info panel, not the Outline window, so the scene tree gets
|
||||
|
|
@ -1197,8 +1197,8 @@ public:
|
|||
int count = b3RecPlayer_GetBodyCount( m_player );
|
||||
for ( int ord = 0; ord < count; ++ord )
|
||||
{
|
||||
b3BodyId body = b3RecPlayer_GetBodyId( m_player, ord );
|
||||
if ( B3_IS_NULL( body ) || b3Body_IsValid( body ) == false )
|
||||
b3BodyId bodyId = b3RecPlayer_GetBodyId( m_player, ord );
|
||||
if ( B3_IS_NULL( bodyId ) || b3Body_IsValid( bodyId ) == false )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1206,10 +1206,15 @@ public:
|
|||
bool ownsSelection =
|
||||
m_selBodyOrdinal == ord && ( m_selKind == SelBody || m_selKind == SelShape || m_selKind == SelJoint );
|
||||
|
||||
const char* name = b3Body_GetName( body );
|
||||
const char* bodyName = b3Body_GetName( bodyId );
|
||||
if ( bodyName == nullptr || bodyName[0] == 0 )
|
||||
{
|
||||
b3BodyType bodyType = b3Body_GetType( bodyId );
|
||||
bodyName = ReplayBodyTypeName( bodyType );
|
||||
}
|
||||
|
||||
char label[64];
|
||||
snprintf( label, sizeof( label ), "Body %d %s###b%d", ord,
|
||||
( name != nullptr && name[0] != '\0' ) ? name : ReplayBodyTypeName( b3Body_GetType( body ) ), ord );
|
||||
snprintf( label, sizeof( label ), "Body %d %s###b%d", ord, bodyName, ord );
|
||||
|
||||
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth;
|
||||
if ( m_selKind == SelBody && m_selBodyOrdinal == ord )
|
||||
|
|
@ -1237,12 +1242,17 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
BodyShapes( m_shapeBuffer, body );
|
||||
BodyShapes( m_shapeBuffer, bodyId );
|
||||
for ( int s = 0; s < (int)m_shapeBuffer.size(); ++s )
|
||||
{
|
||||
b3ShapeType shapeType = b3Shape_GetType( m_shapeBuffer[s] );
|
||||
const char* shapeName = b3Shape_GetName( m_shapeBuffer[s] );
|
||||
if ( shapeName == nullptr || shapeName[0] == 0 )
|
||||
{
|
||||
b3ShapeType shapeType = b3Shape_GetType( m_shapeBuffer[s] );
|
||||
shapeName = ReplayShapeTypeName( shapeType );
|
||||
}
|
||||
char sl[64];
|
||||
snprintf( sl, sizeof( sl ), "Shape %d %s###b%ds%d", s, ReplayShapeTypeName( shapeType ), ord, s );
|
||||
snprintf( sl, sizeof( sl ), "Shape %d %s###b%ds%d", s, shapeName, ord, s );
|
||||
ImGuiTreeNodeFlags lf =
|
||||
ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_NoTreePushOnOpen;
|
||||
if ( m_selKind == SelShape && m_selBodyOrdinal == ord && m_selSlot == s )
|
||||
|
|
@ -1263,7 +1273,7 @@ public:
|
|||
}
|
||||
|
||||
b3JointId joints[16];
|
||||
int jn = b3Body_GetJoints( body, joints, 16 );
|
||||
int jn = b3Body_GetJoints( bodyId, joints, 16 );
|
||||
for ( int j = 0; j < jn; ++j )
|
||||
{
|
||||
char jl[64];
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "gfx/debug_adapter.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "gfx/keycodes.h"
|
||||
#include "imgui.h"
|
||||
#include "mesh_loader.h"
|
||||
#include "sample.h"
|
||||
#include "gfx/draw.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
|
|
@ -452,6 +452,12 @@ public:
|
|||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = 0.1f;
|
||||
|
||||
#if B3_SHAPE_NAME_LENGTH > 0
|
||||
char buffer[B3_SHAPE_NAME_LENGTH + 1];
|
||||
snprintf( buffer, sizeof( buffer ), "box_%d", i );
|
||||
shapeDef.name = buffer;
|
||||
#endif
|
||||
|
||||
b3CreateHullShape( bodyId, &shapeDef, &cube.base );
|
||||
}
|
||||
|
||||
|
|
@ -573,7 +579,7 @@ public:
|
|||
{
|
||||
if ( m_context->restart == false )
|
||||
{
|
||||
if (m_isDebug)
|
||||
if ( m_isDebug )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 15.0f, 25.0f, b3Pos_zero );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue