Fixes 07 (#97)
#84 #82 Added B3_RESTITUTION_ITERATIONS to override restitution iterations. Fix regression in hull stacking stability.
This commit is contained in:
parent
dfa5e6add0
commit
23861418d8
27 changed files with 877 additions and 448 deletions
|
|
@ -98,8 +98,8 @@ void CharacterMover::SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3
|
|||
float drop = control * m_friction * timeStep;
|
||||
float newSpeed = b3MaxFloat( 0.0f, speed - drop );
|
||||
float ratio = newSpeed / speed;
|
||||
m_velocity.x *= newSpeed / speed;
|
||||
m_velocity.z *= newSpeed / speed;
|
||||
m_velocity.x *= ratio;
|
||||
m_velocity.z *= ratio;
|
||||
}
|
||||
|
||||
float maxSpeed = m_sprint ? 1.5f * m_maxSpeed : m_maxSpeed;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
// SPDX-FileCopyrightText: 2025 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "gfx/debug_adapter.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "imgui.h"
|
||||
#include "sample.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "gfx/debug_adapter.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -442,7 +441,7 @@ public:
|
|||
m_runCount = 0;
|
||||
m_failure = false;
|
||||
m_autoGenerate = false;
|
||||
|
||||
m_collide = true;
|
||||
m_stepWhilePaused = true;
|
||||
|
||||
Generate();
|
||||
|
|
@ -549,13 +548,16 @@ public:
|
|||
|
||||
// Don't allow shapes to collide with each other. This
|
||||
// makes isolating failures easier.
|
||||
shapeDef.filter.categoryBits = 2;
|
||||
shapeDef.filter.maskBits = 1;
|
||||
if ( m_collide == false )
|
||||
{
|
||||
shapeDef.filter.categoryBits = 2;
|
||||
shapeDef.filter.maskBits = 1;
|
||||
}
|
||||
|
||||
g_randomSeed = (uint32_t)b3GetTicks();
|
||||
|
||||
bool simulateAll = true;
|
||||
//g_randomSeed = 1910133196;
|
||||
// g_randomSeed = 1910133196;
|
||||
|
||||
m_runCount += 1;
|
||||
m_stepCount = 0;
|
||||
|
|
@ -624,6 +626,11 @@ public:
|
|||
Generate();
|
||||
}
|
||||
|
||||
if ( ImGui::Checkbox( "Collide", &m_collide ) )
|
||||
{
|
||||
Generate();
|
||||
}
|
||||
|
||||
if ( ImGui::Button( "Generate" ) )
|
||||
{
|
||||
Generate();
|
||||
|
|
@ -645,8 +652,7 @@ public:
|
|||
{
|
||||
PickRay pickRay = m_camera->BuildPickRay( m_context->mouseX, m_context->mouseY );
|
||||
|
||||
b3RayResult result =
|
||||
b3World_CastRayClosest( m_worldId, pickRay.origin, pickRay.translation, b3DefaultQueryFilter() );
|
||||
b3RayResult result = b3World_CastRayClosest( m_worldId, pickRay.origin, pickRay.translation, b3DefaultQueryFilter() );
|
||||
|
||||
if ( result.hit )
|
||||
{
|
||||
|
|
@ -736,6 +742,7 @@ public:
|
|||
int m_runCount;
|
||||
bool m_failure;
|
||||
bool m_autoGenerate;
|
||||
bool m_collide;
|
||||
};
|
||||
|
||||
static int sampleMeshDrop = RegisterSample( "Continuous", "Mesh Drop", MeshDrop::Create );
|
||||
|
|
@ -862,13 +869,12 @@ public:
|
|||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 15.0f, 0.0f } );
|
||||
|
||||
}
|
||||
|
||||
AddGroundBox( 40.0f );
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( 0.5f, 10.0f, 0.5f );
|
||||
b3Capsule capsule = {{0.0f, -9.5f, 0.0f}, {0.0f, 9.5f, 0.0f}, 0.5f};
|
||||
b3Capsule capsule = { { 0.0f, -9.5f, 0.0f }, { 0.0f, 9.5f, 0.0f }, 0.5f };
|
||||
|
||||
bool useCapsule = false;
|
||||
|
||||
|
|
@ -881,7 +887,7 @@ public:
|
|||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
if (useCapsule)
|
||||
if ( useCapsule )
|
||||
{
|
||||
b3CreateCapsuleShape( bodyId, &shapeDef, &capsule );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public:
|
|||
{
|
||||
Sample::Step( );
|
||||
|
||||
if ( m_done == false )
|
||||
if ( m_done == false && (m_context->pause == false || m_context->singleStep > 0) )
|
||||
{
|
||||
m_done = UpdateFallingRagdolls( m_worldId, &m_data );
|
||||
if (m_done)
|
||||
|
|
|
|||
|
|
@ -1146,3 +1146,160 @@ public:
|
|||
};
|
||||
|
||||
static int sampleWheelStack = RegisterSample( "Issues", "GMod Wheel Stack", WheelStack::Create );
|
||||
|
||||
class RestitutionOvershoot : public Sample
|
||||
{
|
||||
public:
|
||||
static constexpr float m_boxHalf = 0.5f;
|
||||
static constexpr float m_floorHalfXZ = 0.375f;
|
||||
static constexpr float m_floorHalfY = 0.25f;
|
||||
static constexpr float m_dropHeight = 10.0f;
|
||||
static constexpr float m_tolerance = 0.05f;
|
||||
|
||||
explicit RestitutionOvershoot( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 20.0f, 0.0f, 28.0f, { 0.0f, m_dropHeight + m_boxHalf, 0.0f } );
|
||||
}
|
||||
|
||||
b3BoxHull floor = b3MakeBoxHull( m_floorHalfXZ, m_floorHalfY, m_floorHalfXZ );
|
||||
b3BodyDef floorDef = b3DefaultBodyDef();
|
||||
floorDef.type = b3_staticBody;
|
||||
floorDef.position = { 0.0f, -m_floorHalfY, 0.0f };
|
||||
b3BodyId floorBody = b3CreateBody( m_worldId, &floorDef );
|
||||
|
||||
b3ShapeDef floorShape = b3DefaultShapeDef();
|
||||
b3CreateHullShape( floorBody, &floorShape, &floor.base );
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( m_boxHalf, m_boxHalf, m_boxHalf );
|
||||
b3BodyDef boxDef = b3DefaultBodyDef();
|
||||
boxDef.type = b3_dynamicBody;
|
||||
boxDef.position = { 0.0f, m_dropHeight, 0.0f };
|
||||
m_boxBody = b3CreateBody( m_worldId, &boxDef );
|
||||
|
||||
b3ShapeDef boxShape = b3DefaultShapeDef();
|
||||
boxShape.baseMaterial.restitution = 1.0f;
|
||||
b3CreateHullShape( m_boxBody, &boxShape, &box.base );
|
||||
|
||||
m_currentY = m_dropHeight;
|
||||
m_maxBounceY = 0.0f;
|
||||
m_bounced = false;
|
||||
m_failed = false;
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
if ( B3_IS_NON_NULL( m_boxBody ) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3Pos position = b3Body_GetPosition( m_boxBody );
|
||||
m_currentY = position.y;
|
||||
|
||||
b3Vec3 velocity = b3Body_GetLinearVelocity( m_boxBody );
|
||||
if ( m_bounced == false && velocity.y > 0.0f )
|
||||
{
|
||||
m_bounced = true;
|
||||
}
|
||||
|
||||
if ( m_bounced )
|
||||
{
|
||||
if ( position.y > m_maxBounceY )
|
||||
{
|
||||
m_maxBounceY = position.y;
|
||||
}
|
||||
if ( position.y > m_dropHeight + m_tolerance )
|
||||
{
|
||||
m_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
b3Pos markerPoint = { 0.0f, m_dropHeight + m_boxHalf, 0.0f };
|
||||
DrawPlane( b3Vec3_axisY, markerPoint, MakeColor( b3_colorYellow ) );
|
||||
|
||||
DrawTextLine( "drop height = %.2f m", m_dropHeight );
|
||||
DrawTextLine( "current y = %.2f m", m_currentY );
|
||||
DrawTextLine( "max bounce = %.2f m", m_maxBounceY );
|
||||
|
||||
if ( m_bounced == false )
|
||||
{
|
||||
DrawTextLine( "waiting for first bounce..." );
|
||||
}
|
||||
else if ( m_failed )
|
||||
{
|
||||
DrawTextLine( "FAIL: box exceeded drop height" );
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextLine( "PASS: bounce stays at or below drop height" );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new RestitutionOvershoot( context );
|
||||
}
|
||||
|
||||
b3BodyId m_boxBody = {};
|
||||
float m_currentY = 0.0f;
|
||||
float m_maxBounceY = 0.0f;
|
||||
bool m_bounced = false;
|
||||
bool m_failed = false;
|
||||
};
|
||||
|
||||
static int sampleRestitutionOvershoot = RegisterSample( "Issues", "Restitution Overshoot", RestitutionOvershoot::Create );
|
||||
|
||||
class SlideTwistOffCenterShape : public Sample
|
||||
{
|
||||
public:
|
||||
explicit SlideTwistOffCenterShape( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( -30.0f, 17.0f, 30.0f, { 0.0f, 5.0f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 50.0f );
|
||||
|
||||
b3Quat orientation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 20.0f * B3_DEG_TO_RAD );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
||||
bodyDef.position = { 0.0f, 4.0f, 0.0f };
|
||||
bodyDef.rotation = orientation;
|
||||
b3BodyId planeBody = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3BoxHull plane = b3MakeBoxHull( 10.0f, 0.5f, 10.0f );
|
||||
shapeDef.baseMaterial.friction = 0.6f;
|
||||
b3CreateHullShape( planeBody, &shapeDef, &plane.base );
|
||||
|
||||
b3Vec3 boxLocalCenter = { 1.0f, 0.5f, 1.0f };
|
||||
b3Vec3 boxOffset = b3RotateVector( orientation, boxLocalCenter );
|
||||
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = { -boxOffset.x, 5.0f - boxOffset.y, -boxOffset.z };
|
||||
bodyDef.rotation = orientation;
|
||||
//bodyDef.angularVelocity = 25.0f * b3RotateVector( orientation, b3Vec3_axisY );
|
||||
b3BodyId boxBody = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3BoxHull mBox = b3MakeOffsetBoxHull( 1.0f, 0.5f, 1.0f, boxLocalCenter );
|
||||
shapeDef.baseMaterial.friction = 0.3f;
|
||||
b3CreateHullShape( boxBody, &shapeDef, &mBox.base );
|
||||
|
||||
b3Body_SetAngularVelocity( boxBody, 25.0f * b3RotateVector( orientation, b3Vec3_axisY ) );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new SlideTwistOffCenterShape( context );
|
||||
}
|
||||
};
|
||||
|
||||
static int sampleSlideTwistOffCenterShape =
|
||||
RegisterSample( "Issues", "Slide Twist Off Center Shape", SlideTwistOffCenterShape::Create );
|
||||
|
|
|
|||
|
|
@ -517,7 +517,7 @@ public:
|
|||
b3TransformPoint( xf, m_triangle[2] ),
|
||||
};
|
||||
|
||||
b3CollideSphereAndTriangle( &m_manifold, m_pointCapacity, &m_sphere, localTriangle );
|
||||
b3CollideTriangleAndSphere( &m_manifold, m_pointCapacity, localTriangle, &m_sphere );
|
||||
}
|
||||
|
||||
b3Sphere m_sphere;
|
||||
|
|
@ -668,7 +668,7 @@ public:
|
|||
b3TransformPoint( xf, m_triangle[2] ),
|
||||
};
|
||||
|
||||
b3CollideCapsuleAndTriangle( &m_manifold, m_pointCapacity, &m_capsule, localTriangle, &m_simplexCache );
|
||||
b3CollideTriangleAndCapsule( &m_manifold, m_pointCapacity, localTriangle, &m_capsule, &m_simplexCache );
|
||||
}
|
||||
|
||||
b3Capsule m_capsule;
|
||||
|
|
@ -913,8 +913,8 @@ public:
|
|||
b3TransformPoint( xf, m_triangle[2] ),
|
||||
};
|
||||
|
||||
b3CollideHullAndTriangle( &m_manifold, m_pointCapacity, m_hull, localTriangle[0], localTriangle[1], localTriangle[2],
|
||||
m_flags, &m_satCache, true );
|
||||
b3CollideTriangleAndHull( &m_manifold, m_pointCapacity, localTriangle[0], localTriangle[1], localTriangle[2],
|
||||
m_flags, m_hull, &m_satCache, true );
|
||||
}
|
||||
|
||||
int m_flags;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// SPDX-FileCopyrightText: 2025 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "gfx/draw.h"
|
||||
#include "human.h"
|
||||
#include "imgui.h"
|
||||
#include "sample.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
|
|
@ -232,9 +233,14 @@ public:
|
|||
m_groundMesh = b3CreateGridMesh( 20, 20, 1.0f, 1, true );
|
||||
b3CreateMeshShape( groundId, &shapeDef, m_groundMesh, b3Vec3_one );
|
||||
|
||||
g_randomSeed = 42;
|
||||
float a = 0.1f * e_count;
|
||||
b3Vec3 lower = { -a, -a, -a };
|
||||
b3Vec3 upper = { a, a, a };
|
||||
for ( int i = 0; i < e_count; ++i )
|
||||
{
|
||||
b3Pos position = { 0.1f * i, 2.0f + 0.5f * i, -0.1f * i };
|
||||
b3Vec3 offset = RandomVec3( lower, upper );
|
||||
b3Pos position = { offset.x, 2.0f, offset.z };
|
||||
float torque = 10.0f;
|
||||
float hertz = 0.5f;
|
||||
float damping = 0.7f;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public:
|
|||
m_camera->SetView( -140.0f, 17.0f, 60.0f, { 0.0f, 7.5f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 50.0f );
|
||||
AddGroundBox( 80.0f );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
|
|
|||
|
|
@ -210,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();
|
||||
|
|
@ -409,7 +409,7 @@ public:
|
|||
{
|
||||
if ( m_context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 35.0f, 15.0f, 30.0f, { 0.0f, 10.0f, 0.0f } );
|
||||
m_camera->SetView( 35.0f, 15.0f, 12.0f, { 0.0f, 2.0f, 0.0f } );
|
||||
}
|
||||
|
||||
m_shapeType = b3_hullShape;
|
||||
|
|
@ -418,42 +418,43 @@ public:
|
|||
|
||||
void CreateStack()
|
||||
{
|
||||
AddGroundBox( 60.0f );
|
||||
AddGroundBox( 20.0f );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = m_shapeType == b3_capsuleShape ? 0.1f : 0.05f;
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
|
||||
float h = 1.0f;
|
||||
float r = 0.1f;
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( h, r, r );
|
||||
b3Capsule capsule = { { -h, 0.0f, 0.0f }, { h, 0.0f, 0.0f }, r };
|
||||
int count = 30;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = m_shapeType == b3_capsuleShape ? 0.1f : 0.01f;
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
float alpha = ( i & 1 ) == 1 ? 0.0f : 0.5f * B3_PI;
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( 2.5f, 0.25f, 0.25f );
|
||||
b3Capsule capsule = { { -2.5f, 0.0f, 0.0f }, { 2.5f, 0.0f, 0.0f }, 0.25f };
|
||||
float x = ( i & 1 ) == 0 ? h - 2.0f * r : 0.0f;
|
||||
float z = ( i & 1 ) == 0 ? 0.0f : h - 2.0f * r;
|
||||
|
||||
for ( int i = 0; i < m_size; ++i )
|
||||
bodyDef.position = { x, ( 2.1f * i + 0.5f ) * r, z };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha );
|
||||
b3BodyId boxBody1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
bodyDef.position = { -x, ( 2.1f * i + 0.5f ) * r, -z };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha );
|
||||
b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
if ( m_shapeType == b3_capsuleShape )
|
||||
{
|
||||
float alpha = ( i & 1 ) == 1 ? 0.0f : 0.5f * B3_PI;
|
||||
|
||||
float x = ( i & 1 ) == 0 ? 1.75f : 0.0f;
|
||||
float z = ( i & 1 ) == 0 ? 0.0f : 1.75f;
|
||||
|
||||
bodyDef.position = { x, 0.5f * i + 0.25f, z };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha );
|
||||
b3BodyId boxBody1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
bodyDef.position = { -x, 0.5f * i + 0.25f, -z };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha );
|
||||
b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
if ( m_shapeType == b3_capsuleShape )
|
||||
{
|
||||
b3CreateCapsuleShape( boxBody1, &shapeDef, &capsule );
|
||||
b3CreateCapsuleShape( boxBody2, &shapeDef, &capsule );
|
||||
}
|
||||
else
|
||||
{
|
||||
b3CreateHullShape( boxBody1, &shapeDef, &box.base );
|
||||
b3CreateHullShape( boxBody2, &shapeDef, &box.base );
|
||||
}
|
||||
b3CreateCapsuleShape( boxBody1, &shapeDef, &capsule );
|
||||
b3CreateCapsuleShape( boxBody2, &shapeDef, &capsule );
|
||||
}
|
||||
else
|
||||
{
|
||||
b3CreateHullShape( boxBody1, &shapeDef, &box.base );
|
||||
b3CreateHullShape( boxBody2, &shapeDef, &box.base );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -484,7 +485,6 @@ public:
|
|||
return new JengaStack( context );
|
||||
}
|
||||
|
||||
static constexpr int m_size = 40;
|
||||
b3ShapeType m_shapeType;
|
||||
};
|
||||
|
||||
|
|
@ -811,7 +811,7 @@ public:
|
|||
{
|
||||
if ( m_context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 30.0f, 50.0f, { 0.0f, 5.0f, 0.0f } );
|
||||
m_camera->SetView( 40.0f, 15.0f, 50.0f, { 0.0f, 12.0f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 40.0f );
|
||||
|
|
@ -847,3 +847,93 @@ public:
|
|||
};
|
||||
|
||||
static int samplePyramid2D = RegisterSample( "Stacking", "Pyramid2D", Pyramid2D::Create );
|
||||
|
||||
// This stresses the edge-edge handling.
|
||||
class EdgeCrossing : public Sample
|
||||
{
|
||||
public:
|
||||
explicit EdgeCrossing( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 25.0f, 10.0f, b3Pos_zero );
|
||||
}
|
||||
|
||||
AddGroundBox( 40.0f );
|
||||
|
||||
b3Vec3 h = { 0.2f, 0.02f, 0.04f };
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
||||
bodyDef.position.x = -10.0f;
|
||||
bodyDef.position.z = -2.0f;
|
||||
|
||||
b3BoxHull box1 = b3MakeBoxHull( h.x, h.y, h.z );
|
||||
b3BoxHull box2 = b3MakeBoxHull( h.x, h.z, h.y );
|
||||
|
||||
b3Vec3 axis = b3Normalize( { 0.1f, 0.9f, 0.0f } );
|
||||
for ( float angle = -B3_PI; angle < B3_PI + 0.001f; angle += 0.1f * B3_PI )
|
||||
{
|
||||
bodyDef.position.y = h.y;
|
||||
bodyDef.rotation = b3Quat_identity;
|
||||
b3BodyId bodyId1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( bodyId1, &shapeDef, &box1.base );
|
||||
|
||||
bodyDef.position.y = 20.0f * h.y;
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( axis, angle );
|
||||
b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3CreateHullShape( boxBody2, &shapeDef, &box1.base );
|
||||
|
||||
bodyDef.position.x += 1.0f;
|
||||
}
|
||||
|
||||
bodyDef.position.x = -10.0f;
|
||||
bodyDef.position.z = 0.0f;
|
||||
|
||||
for ( float angle = -B3_PI; angle < B3_PI + 0.001f; angle += 0.1f * B3_PI )
|
||||
{
|
||||
bodyDef.position.y = h.z;
|
||||
bodyDef.rotation = b3Quat_identity;
|
||||
b3BodyId bodyId1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( bodyId1, &shapeDef, &box2.base );
|
||||
|
||||
bodyDef.position.y = 20.0f * h.z;
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( axis, angle );
|
||||
b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3CreateHullShape( boxBody2, &shapeDef, &box2.base );
|
||||
|
||||
bodyDef.position.x += 1.0f;
|
||||
}
|
||||
|
||||
bodyDef.position.x = -10.0f;
|
||||
bodyDef.position.z = 2.0f;
|
||||
|
||||
for ( float angle = -B3_PI; angle < B3_PI + 0.001f; angle += 0.1f * B3_PI )
|
||||
{
|
||||
bodyDef.position.y = h.y;
|
||||
bodyDef.rotation = b3Quat_identity;
|
||||
b3BodyId bodyId1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( bodyId1, &shapeDef, &box1.base );
|
||||
|
||||
bodyDef.position.y = 20.0f * h.y;
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( axis, angle );
|
||||
b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3CreateHullShape( boxBody2, &shapeDef, &box2.base );
|
||||
|
||||
bodyDef.position.x += 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new EdgeCrossing( context );
|
||||
}
|
||||
};
|
||||
|
||||
static int sampleEdgeCrossing = RegisterSample( "Stacking", "Edge Crossing", EdgeCrossing::Create );
|
||||
|
|
|
|||
Loading…
Reference in a new issue