linux fixes, bugfixes, comments

This commit is contained in:
Irlan Robson
2016-12-21 19:15:43 -02:00
parent 1672673839
commit 81f744b805
149 changed files with 2371 additions and 3413 deletions

View File

@ -16,18 +16,18 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\broad_phase.h>
#include <bounce/collision/broad_phase.h>
b3BroadPhase::b3BroadPhase()
{
m_moveBufferCapacity = 16;
m_moveBuffer = (i32*)b3Alloc(m_moveBufferCapacity * sizeof(i32));
memset(m_moveBuffer, NULL, m_moveBufferCapacity * sizeof(i32));
memset(m_moveBuffer, 0, m_moveBufferCapacity * sizeof(i32));
m_moveBufferCount = 0;
m_pairBufferCapacity = 16;
m_pairBuffer = (b3Pair*)b3Alloc(m_pairBufferCapacity * sizeof(b3Pair));
memset(m_pairBuffer, NULL, m_pairBufferCapacity * sizeof(b3Pair));
memset(m_pairBuffer, 0, m_pairBufferCapacity * sizeof(b3Pair));
m_pairBufferCount = 0;
}

View File

@ -16,10 +16,10 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\distance.h>
#include <bounce\common\math\vec2.h>
#include <bounce\common\math\vec3.h>
#include <bounce\common\math\mat22.h>
#include <bounce/collision/distance.h>
#include <bounce/common/math/vec2.h>
#include <bounce/common/math/vec3.h>
#include <bounce/common/math/mat22.h>
b3Vec3 b3ClosestPointOnPlane(const b3Vec3& P, const b3Plane& plane)
{

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\gjk\gjk.h>
#include <bounce\collision\gjk\gjk_proxy.h>
#include <bounce/collision/gjk/gjk.h>
#include <bounce/collision/gjk/gjk_proxy.h>
// Implementation of the GJK (Gilbert-Johnson-Keerthi) algorithm
// using Voronoi regions and Barycentric coordinates.

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\gjk\gjk_cache.h>
#include <bounce\collision\gjk\gjk_proxy.h>
#include <bounce/collision/gjk/gjk_cache.h>
#include <bounce/collision/gjk/gjk_proxy.h>
extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters;
u32 b3_gjkCacheHits;

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\gjk\gjk_cache.h>
#include <bounce/collision/gjk/gjk_cache.h>
b3GJKFeaturePair b3GetFeaturePair(const b3SimplexCache& cache)
{

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\sat\sat.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/collision/sat/sat.h>
#include <bounce/collision/shapes/hull.h>
// Implementation of the SAT (Separating Axis Test) for
// convex hulls. Thanks to Dirk Gregorius for his presentation

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\sat\sat_edge_and_hull.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/collision/sat/sat_edge_and_hull.h>
#include <bounce/collision/shapes/capsule.h>
#include <bounce/collision/shapes/hull.h>
float32 b3ProjectEdge(const b3Capsule* hull, const b3Plane& plane)
{

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\sat\sat_vertex_and_hull.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/collision/sat/sat_vertex_and_hull.h>
#include <bounce/collision/shapes/sphere.h>
#include <bounce/collision/shapes/hull.h>
float32 b3ProjectVertex(const b3Sphere* hull, const b3Plane& plane)
{

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\shapes\hull.h>
#include <bounce/collision/shapes/hull.h>
void b3Hull::Validate() const
{
@ -28,22 +28,36 @@ void b3Hull::Validate() const
void b3Hull::Validate(const b3Face* face) const
{
bool ok = false;
const b3HalfEdge* begin = GetEdge(face->edge);
const b3HalfEdge* edge = begin;
do
{
if (GetFace(edge->face) == face)
{
ok = true;
break;
}
edge = edges + edge->next;
} while (edge != begin);
B3_ASSERT(ok);
Validate(edges + face->edge);
}
void b3Hull::Validate(const b3HalfEdge* e) const
{
u32 edgeIndex = (u32)(e - edges);
u8 edgeIndex = (u8)(e - edges);
const b3HalfEdge* twin = edges + e->twin;
B3_ASSERT(twin->twin == edgeIndex);
// Each edge must be followed by its twin.
B3_ASSERT(b3Abs(twin - e) == 1);
//B3_ASSERT(edges[e->prev].next == edgeIndex);
B3_ASSERT(e->origin != twin->origin);
B3_ASSERT(twin->twin == edgeIndex);
u32 count = 0;
const b3HalfEdge* start = e;
const b3HalfEdge* begin = e;
do
{
const b3HalfEdge* next = edges + e->next;
@ -51,5 +65,5 @@ void b3Hull::Validate(const b3HalfEdge* e) const
e = twin;
B3_ASSERT(count < edgeCount);
++count;
} while (e != start);
}
} while (e != begin);
}

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\trees\dynamic_tree.h>
#include <bounce/collision/trees/dynamic_tree.h>
b3DynamicTree::b3DynamicTree()
{
@ -25,7 +25,7 @@ b3DynamicTree::b3DynamicTree()
// Preallocate 32 nodes.
m_nodeCapacity = 32;
m_nodes = (b3Node*) b3Alloc(m_nodeCapacity * sizeof(b3Node));
memset(m_nodes, NULL, m_nodeCapacity * sizeof(b3Node));
memset(m_nodes, 0, m_nodeCapacity * sizeof(b3Node));
m_nodeCount = 0;
// Link the allocated nodes and make the first node
@ -67,7 +67,7 @@ i32 b3DynamicTree::AllocateNode()
m_nodes[node].child1 = NULL_NODE;
m_nodes[node].child2 = NULL_NODE;
m_nodes[node].height = 0;
m_nodes[node].userData = nullptr;
m_nodes[node].userData = NULL;
++m_nodeCount;
@ -133,7 +133,7 @@ void b3DynamicTree::UpdateNode(i32 proxyId, const b3AABB3& aabb)
InsertLeaf(proxyId);
}
i32 b3DynamicTree::HeuristicSearch(const b3AABB3& leafAABB) const
i32 b3DynamicTree::FindBest(const b3AABB3& leafAABB) const
{
// To find a good branch node, the manhattan distance could be used as heuristic.
// However, the current propagated node and the leaf node volume are incompletely considerable.
@ -215,7 +215,7 @@ void b3DynamicTree::InsertLeaf(i32 leaf)
b3AABB3 leafAabb = m_nodes[leaf].aabb;
// Search for the best branch node of this tree starting from the tree root node.
i32 sibling = HeuristicSearch(leafAabb);
i32 sibling = FindBest(leafAabb);
i32 oldParent = m_nodes[sibling].parent;
@ -226,7 +226,7 @@ void b3DynamicTree::InsertLeaf(i32 leaf)
m_nodes[sibling].parent = newParent;
m_nodes[newParent].child2 = leaf;
m_nodes[leaf].parent = newParent;
m_nodes[newParent].userData = nullptr;
m_nodes[newParent].userData = NULL;
m_nodes[newParent].aabb = b3Combine(leafAabb, m_nodes[sibling].aabb);
m_nodes[newParent].height = m_nodes[sibling].height + 1;
@ -362,7 +362,7 @@ void b3DynamicTree::Validate(i32 nodeID) const
}
}
void b3DynamicTree::Draw(b3Draw* b3Draw) const
void b3DynamicTree::Draw(b3Draw* draw) const
{
b3Color red = b3Color(1.0f, 0.0f, 0.0f);
b3Color green = b3Color(0.0f, 1.0f, 0.0f);
@ -390,11 +390,11 @@ void b3DynamicTree::Draw(b3Draw* b3Draw) const
const b3Node* node = m_nodes + nodeIndex;
if (node->IsLeaf())
{
b3Draw->DrawAABB(node->aabb, purple);
draw->DrawAABB(node->aabb, purple);
}
else
{
b3Draw->DrawAABB(node->aabb, red);
draw->DrawAABB(node->aabb, red);
stack.Push(node->child1);
stack.Push(node->child2);

View File

@ -16,13 +16,13 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\collision\trees\static_tree.h>
#include <bounce\common\template\stack.h>
#include <bounce/collision/trees/static_tree.h>
#include <bounce/common/template/stack.h>
#include <algorithm>
b3StaticTree::b3StaticTree()
{
m_nodes = nullptr;
m_nodes = NULL;
m_nodeCount = 0;
}
@ -31,17 +31,46 @@ b3StaticTree::~b3StaticTree()
b3Free(m_nodes);
}
void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 N)
struct b3Params
{
B3_ASSERT(N > 0);
u32 node;
u32* indices;
u32 numObjects;
};
// Leafs = N, Internals = N - 1, Total = 2N - 1, if we assume
struct b3SortPredicate
{
const b3AABB3* bs;
u32 axis;
bool operator()(const u32& i, const u32& j) const
{
const b3AABB3* b1 = bs + i;
const b3AABB3* b2 = bs + j;
b3Vec3 c1 = b1->Centroid();
b3Vec3 c2 = b2->Centroid();
if (c1[axis] < c2[axis])
{
return true;
}
return false;
}
};
void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 n)
{
B3_ASSERT(n > 0);
// Leafs = n, Internals = n - 1, Total = 2n - 1, if we assume
// each leaf node contains exactly 1 object.
const u32 kMinObjectsPerLeaf = 1;
u32 internalCapacity = N - 1;
u32 leafCapacity = N;
u32 nodeCapacity = 2 * N - 1;
u32 internalCapacity = n - 1;
u32 leafCapacity = n;
u32 nodeCapacity = 2 * n - 1;
u32 internalCount = 0;
u32 leafCount = 0;
@ -49,42 +78,13 @@ void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 N)
m_nodes = (b3Node*)b3Alloc(nodeCapacity * sizeof(b3Node));
m_nodeCount = 1;
struct b3Params
{
u32 node;
u32* indices;
u32 numObjects;
};
struct b3SortPredicate
{
const b3AABB3* bs;
u32 axis;
bool operator()(const u32& i, const u32& j) const
{
const b3AABB3* b1 = bs + i;
const b3AABB3* b2 = bs + j;
b3Vec3 c1 = b1->Centroid();
b3Vec3 c2 = b2->Centroid();
if (c1[axis] < c2[axis])
{
return true;
}
return false;
}
};
b3Stack<b3Params, 256> stack;
{
b3Params params;
params.node = 0;
params.indices = ids;
params.numObjects = N;
params.numObjects = n;
stack.Push(params);
}
@ -189,7 +189,7 @@ void b3StaticTree::Build(u32* ids, const b3AABB3* set, u32 N)
B3_ASSERT(m_nodeCount == nodeCapacity);
}
void b3StaticTree::Draw(b3Draw* b3Draw) const
void b3StaticTree::Draw(b3Draw* draw) const
{
b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f);
b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f);
@ -215,11 +215,11 @@ void b3StaticTree::Draw(b3Draw* b3Draw) const
const b3Node* node = m_nodes + nodeIndex;
if (node->IsLeaf())
{
b3Draw->DrawAABB(node->aabb, purple);
draw->DrawAABB(node->aabb, purple);
}
else
{
b3Draw->DrawAABB(node->aabb, red);
draw->DrawAABB(node->aabb, red);
stack.Push(node->child1);
stack.Push(node->child2);

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\common\math\mat22.h>
#include <bounce\common\math\mat33.h>
#include <bounce/common/math/mat22.h>
#include <bounce/common/math/mat33.h>
b3Vec2 b3Mat22::Solve(const b3Vec2& b) const
{

View File

@ -16,14 +16,14 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\common\memory\block_pool.h>
#include <bounce/common/memory/block_pool.h>
b3BlockPool::b3BlockPool(u32 blockSize)
{
m_blockSize = blockSize;
m_chunkSize = b3_blockCount * m_blockSize;
m_chunks = nullptr;
m_chunks = NULL;
m_chunkCount = 0;
// Pre-allocate some chunks
@ -42,7 +42,7 @@ b3BlockPool::b3BlockPool(u32 blockSize)
current->next = (b3Block*)((u8*)chunk->freeBlocks + (i + 1) * blockSize);
}
b3Block* last = (b3Block*)((u8*)chunk->freeBlocks + (b3_blockCount - 1) * blockSize);
last->next = nullptr;
last->next = NULL;
// Push back the new chunk of the singly-linked list of chunks.
chunk->next = m_chunks;
@ -90,7 +90,7 @@ void* b3BlockPool::Allocate()
current->next = (b3Block*)((u8*)chunk->freeBlocks + (i + 1) * m_blockSize);
}
b3Block* last = (b3Block*)((u8*)chunk->freeBlocks + (b3_blockCount - 1) * m_blockSize);
last->next = nullptr;
last->next = NULL;
// Push back the new chunk of the singly-linked list of chunks.
chunk->next = m_chunks;

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\common\memory\stack_allocator.h>
#include <bounce/common/memory/stack_allocator.h>
b3StackAllocator::b3StackAllocator()
{

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\common\settings.h>
#include <bounce\common\math\math.h>
#include <bounce/common/settings.h>
#include <bounce/common/math/math.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2016-2016 Irlan Robson http://www.irlan.net
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\common\time.h>
// This file contains platform dependent code
// and may not compile depending of the OS.
#if (_WIN32 == 1)
#include <Windows.h>
float64 GetCyclesPerSecond()
{
LARGE_INTEGER integer;
QueryPerformanceFrequency(&integer);
return float64(integer.QuadPart);
}
u64 GetCycleCount()
{
LARGE_INTEGER integer;
QueryPerformanceCounter(&integer);
return integer.QuadPart;
}
#endif
float64 b3Time::m_invFrequency = 0.0;
b3Time::b3Time()
{
m_lastTime = 0;
m_curTime = 0;
if (m_invFrequency == 0.0)
{
float64 cyclesPerSec = GetCyclesPerSecond();
float64 secPerCycles = 1.0 / cyclesPerSec;
float64 milisecPerCycles = 1000.0 * secPerCycles;
m_invFrequency = milisecPerCycles;
}
m_lastRealTime = GetCycleCount();
}
void b3Time::Update()
{
// Retrieve the current time in units of cycles.
u64 curTime = GetCycleCount();
u64 dt = curTime - m_lastRealTime;
m_lastRealTime = curTime;
float64 dtMs = m_invFrequency * float64(dt);
UpdateBy(dtMs);
}
void b3Time::UpdateBy(float64 delta)
{
m_lastTime = m_curTime;
m_curTime += delta;
}

View File

@ -16,11 +16,11 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\world.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\joints\joint.h>
#include <bounce\dynamics\contacts\contact.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/world.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/joints/joint.h>
#include <bounce/dynamics/contacts/contact.h>
b3Body::b3Body(const b3BodyDef& def, b3World* world)
{
@ -107,7 +107,7 @@ b3Shape* b3Body::CreateShape(const b3ShapeDef& def)
}
// Compute the world AABB of the new shape and assign a broad-phase proxy to it.
b3Transform xf = shape->GetTransform();
b3Transform xf = m_xf;
b3AABB3 aabb;
shape->ComputeAABB(&aabb, xf);

View File

@ -16,19 +16,19 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contact_manager.h>
#include <bounce\dynamics\contacts\convex_contact.h>
#include <bounce\dynamics\contacts\mesh_contact.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\world_listeners.h>
#include <bounce/dynamics/contact_manager.h>
#include <bounce/dynamics/contacts/convex_contact.h>
#include <bounce/dynamics/contacts/mesh_contact.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/world_listeners.h>
b3ContactManager::b3ContactManager() :
m_convexBlocks(sizeof(b3ConvexContact)),
m_meshBlocks(sizeof(b3MeshContact))
{
m_contactListener = nullptr;
m_contactFilter = nullptr;
m_contactListener = NULL;
m_contactFilter = NULL;
}
void b3ContactManager::AddPair(void* dataA, void* dataB)
@ -123,7 +123,7 @@ void b3ContactManager::AddPair(void* dataA, void* dataB)
// Add the contact to the world contact list.
m_contactList.PushFront(c);
if (c->m_type == b3ContactType::e_meshContact)
if (c->m_type == e_meshContact)
{
// Add the contact to the world mesh contact list.
b3MeshContact* mc = (b3MeshContact*)c;
@ -237,7 +237,7 @@ b3Contact* b3ContactManager::Create(b3Shape* shapeA, b3Shape* shapeB)
B3_ASSERT(typeA <= typeB);
b3Contact* c = nullptr;
b3Contact* c = NULL;
if (typeA != e_meshShape && typeB != e_meshShape)
{
void* block = m_convexBlocks.Allocate();
@ -267,7 +267,7 @@ b3Contact* b3ContactManager::Create(b3Shape* shapeA, b3Shape* shapeB)
void b3ContactManager::Destroy(b3Contact* c)
{
// Report to the contact listener that the contact will be destroyed.
// Report to the contact listener the contact will be destroyed.
if (m_contactListener)
{
if (c->IsOverlapping())
@ -297,7 +297,7 @@ void b3ContactManager::Destroy(b3Contact* c)
{
b3MeshContact* mc = (b3MeshContact*)c;
// Remove the contact from the world mesh contact list.
// Remove the mesh contact from the world mesh contact list.
m_meshContactList.Remove(&mc->m_link);
mc->~b3MeshContact();

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\clip.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/dynamics/contacts/collide/clip.h>
#include <bounce/collision/shapes/capsule.h>
#include <bounce/collision/shapes/hull.h>
void b3BuildEdge(b3ClipVertex vOut[2],
const b3Capsule* hull)

View File

@ -16,16 +16,16 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\dynamics\shapes\mesh_shape.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce\collision\shapes\mesh.h>
#include <bounce\collision\distance.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/dynamics/shapes/mesh_shape.h>
#include <bounce/collision/shapes/sphere.h>
#include <bounce/collision/shapes/capsule.h>
#include <bounce/collision/shapes/hull.h>
#include <bounce/collision/shapes/mesh.h>
#include <bounce/collision/distance.h>
void b3ShapeGJKProxy::Set(const b3Shape* shape, u32 index)
{
@ -171,8 +171,8 @@ void b3CollideShapeAndShape(b3Manifold& manifold,
static const b3CollideFunction s_CollideMatrix[e_maxShapes][e_maxShapes] =
{
{ &b3CollideSphereAndSphereShapes, &b3CollideSphereAndCapsuleShapes, &b3CollideSphereAndHullShapes },
{ nullptr, &b3CollideCapsuleAndCapsuleShapes, &b3CollideCapsuleAndHullShapes },
{ nullptr, nullptr, &b3CollideHullAndHullShapes },
{ NULL, &b3CollideCapsuleAndCapsuleShapes, &b3CollideCapsuleAndHullShapes },
{ NULL, NULL, &b3CollideHullAndHullShapes },
};
b3ShapeType typeA = shapeA->GetType();

View File

@ -16,13 +16,13 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\collide\clip.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/collide/clip.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/collision/shapes/capsule.h>
#include <bounce/collision/shapes/hull.h>
void b3BuildEdgeContact(b3Manifold& manifold,
const b3Transform& xf1, const b3Capsule* hull1,

View File

@ -16,11 +16,11 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\collide\clip.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/collide/clip.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
#include <bounce/collision/shapes/capsule.h>
bool b3AreParalell(const b3Capsule& hullA, const b3Capsule& hullB)
{

View File

@ -16,12 +16,12 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\collide\clip.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\contacts\contact_cluster.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/collide/clip.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/contacts/contact_cluster.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/collision/shapes/hull.h>
void b3BuildEdgeContact(b3Manifold& manifold,
const b3Transform& xfA, const b3Hull* hullA,

View File

@ -16,11 +16,11 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\collide\clip.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/collide/clip.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/collision/shapes/hull.h>
extern u32 b3_convexCacheHits;

View File

@ -16,12 +16,12 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
#include <bounce/collision/shapes/sphere.h>
#include <bounce/collision/shapes/capsule.h>
void b3CollideSphereAndCapsule(b3Manifold& manifold,
const b3Transform& xfA, const b3SphereShape* sA,

View File

@ -16,12 +16,12 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/collision/shapes/sphere.h>
#include <bounce/collision/shapes/hull.h>
void b3CollideSphereAndHull(b3Manifold& manifold,
const b3Transform& xf1, const b3SphereShape* s1,

View File

@ -16,10 +16,10 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\collide\collide.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce/dynamics/contacts/collide/collide.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
#include <bounce/collision/shapes/sphere.h>
void b3CollideSphereAndSphere(b3Manifold& manifold,
const b3Transform& xf1, const b3SphereShape* s1,

View File

@ -16,12 +16,12 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\contact.h>
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\world.h>
#include <bounce\dynamics\world_listeners.h>
#include <bounce/dynamics/contacts/contact.h>
#include <bounce/dynamics/contacts/manifold.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/world.h>
#include <bounce/dynamics/world_listeners.h>
const b3Manifold* b3Contact::GetManifold(u32 index) const
{
@ -41,10 +41,10 @@ void b3Contact::GetWorldManifold(b3WorldManifold* out, u32 index) const
b3Manifold* m = m_manifolds + index;
const b3Shape* shapeA = GetShapeA();
b3Transform xfA = shapeA->GetTransform();
b3Transform xfA = shapeA->GetBody()->GetTransform();
const b3Shape* shapeB = GetShapeB();
b3Transform xfB = shapeB->GetTransform();
b3Transform xfB = shapeB->GetBody()->GetTransform();
out->Initialize(m, xfA, shapeA->m_radius, xfB, shapeB->m_radius);
}
@ -54,12 +54,12 @@ void b3Contact::Update(b3ContactListener* listener)
b3Shape* shapeA = GetShapeA();
b3Body* bodyA = shapeA->GetBody();
i32 proxyA = shapeA->m_broadPhaseID;
b3Transform xfA = shapeA->GetTransform();
b3Transform xfA = bodyA->GetTransform();
b3Shape* shapeB = GetShapeB();
b3Body* bodyB = shapeB->GetBody();
i32 proxyB = shapeB->m_broadPhaseID;
b3Transform xfB = shapeB->GetTransform();
b3Transform xfB = bodyB->GetTransform();
b3World* world = bodyA->GetWorld();
@ -134,7 +134,7 @@ void b3Contact::Update(b3ContactListener* listener)
}
// Notify the contact listener the new contact state.
if (listener != nullptr)
if (listener != NULL)
{
if (wasOverlapping == false && isOverlapping == true)
{

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\contact_cluster.h>
#include <bounce\collision\distance.h>
#include <bounce/dynamics/contacts/contact_cluster.h>
#include <bounce/collision/distance.h>
inline void AddCluster(b3Array<b3Cluster>& clusters, const b3Vec3& centroid)
{

View File

@ -16,11 +16,11 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\contact_solver.h>
#include <bounce\dynamics\contacts\contact.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\body.h>
#include <bounce\common\memory\stack_allocator.h>
#include <bounce/dynamics/contacts/contact_solver.h>
#include <bounce/dynamics/contacts/contact.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/body.h>
#include <bounce/common/memory/stack_allocator.h>
// This solver implements PGS for solving velocity constraints and
// NGS for solving position constraints.

View File

@ -16,9 +16,10 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\convex_contact.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\world.h>
#include <bounce/dynamics/contacts/convex_contact.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/world.h>
b3ConvexContact::b3ConvexContact(b3Shape* shapeA, b3Shape* shapeB)
{
@ -35,10 +36,10 @@ b3ConvexContact::b3ConvexContact(b3Shape* shapeA, b3Shape* shapeB)
bool b3ConvexContact::TestOverlap()
{
b3Shape* shapeA = GetShapeA();
b3Transform xfA = shapeA->GetTransform();
b3Transform xfA = shapeA->GetBody()->GetTransform();
b3Shape* shapeB = GetShapeB();
b3Transform xfB = shapeB->GetTransform();
b3Transform xfB = shapeB->GetBody()->GetTransform();
return b3TestOverlap(xfA, 0, shapeA, xfB, 0, shapeB, &m_cache);
}
@ -46,16 +47,14 @@ bool b3ConvexContact::TestOverlap()
void b3ConvexContact::Collide()
{
b3Shape* shapeA = GetShapeA();
b3Transform xfA = shapeA->GetTransform();
b3Body* bodyA = shapeA->GetBody();
b3Transform xfA = bodyA->GetTransform();
b3Shape* shapeB = GetShapeB();
b3Transform xfB = shapeB->GetTransform();
b3Body* bodyB = shapeB->GetBody();
b3Transform xfB = bodyB->GetTransform();
B3_ASSERT(m_manifoldCount == 0);
b3CollideShapeAndShape(m_stackManifold, xfA, shapeA, xfB, shapeB, &m_cache);
m_manifoldCount = 1;
}
void b3ConvexContact::SynchronizeShapes()
{
}

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\manifold.h>
#include <bounce/dynamics/contacts/manifold.h>
void b3Manifold::GuessImpulses()
{

View File

@ -16,16 +16,16 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\contacts\mesh_contact.h>
#include <bounce\dynamics\contacts\contact_cluster.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\shapes\mesh_shape.h>
#include <bounce\dynamics\world.h>
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\collision\shapes\mesh.h>
#include <bounce\collision\shapes\triangle_hull.h>
#include <bounce\common\memory\stack_allocator.h>
#include <bounce/dynamics/contacts/mesh_contact.h>
#include <bounce/dynamics/contacts/contact_cluster.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/shapes/mesh_shape.h>
#include <bounce/dynamics/world.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/collision/shapes/mesh.h>
#include <bounce/collision/shapes/triangle_hull.h>
#include <bounce/common/memory/stack_allocator.h>
b3MeshContact::b3MeshContact(b3Shape* shapeA, b3Shape* shapeB)
{
@ -35,11 +35,12 @@ b3MeshContact::b3MeshContact(b3Shape* shapeA, b3Shape* shapeB)
m_manifolds = m_stackManifolds;
m_manifoldCount = 0;
b3Transform xfA = shapeA->GetTransform();
b3Transform xfB = shapeB->GetTransform();
b3Transform xfA = shapeA->GetBody()->GetTransform();
b3Transform xfB = shapeB->GetBody()->GetTransform();
b3Transform xf = b3MulT(xfB, xfA);
// The fat aabb relative to shape B's frame.
b3AABB3 fatAABB;
shapeA->ComputeAABB(&fatAABB, xf);
fatAABB.Extend(B3_AABB_EXTENSION);
@ -65,16 +66,16 @@ void b3MeshContact::SynchronizeShapes()
b3Transform xfA = bodyA->m_xf;
b3Shape* shapeB = GetShapeB();
b3Transform xfB = shapeB->GetTransform();
b3Body* bodyB = shapeB->GetBody();
b3Transform xfB = bodyB->GetTransform();
b3Sweep* sweepA = &bodyA->m_sweep;
b3Transform xfA0;
xfA0.position = sweepA->worldCenter0;
xfA0.rotation = b3ConvertQuatToRot(sweepA->orientation0);
// Calculate the displacement of the body A.
// using its position at the last time step and the current position.
// Could use displacement = velocity * dt.
// Calculate the displacement of body A using its position at the last
// time step and the current position.
b3Vec3 displacement = xfA.position - xfA0.position;
// Compute the AABB in the reference frame of shape B.
@ -83,8 +84,7 @@ void b3MeshContact::SynchronizeShapes()
b3AABB3 aabb;
shapeA->ComputeAABB(&aabb, xf);
// Update the AABB with the new (transformed) AABB and
// buffer move.
// Update the AABB with the new (transformed) AABB and buffer move.
m_aabbMoved = MoveAABB(aabb, displacement);
}
@ -191,11 +191,13 @@ bool b3MeshContact::Report(u32 proxyId)
bool b3MeshContact::TestOverlap()
{
b3Shape* shapeA = GetShapeA();
b3Transform xfA = shapeA->GetTransform();
b3Body* bodyA = shapeA->GetBody();
b3Transform xfA = bodyA->GetTransform();
u32 indexA = 0;
b3Shape* shapeB = GetShapeB();
b3Transform xfB = shapeB->GetTransform();
b3Body* bodyB = shapeB->GetBody();
b3Transform xfB = bodyB->GetTransform();
b3MeshShape* meshShapeB = (b3MeshShape*)shapeB;
const b3Mesh* meshB = meshShapeB->m_mesh;
@ -222,15 +224,17 @@ void b3MeshContact::Collide()
b3Shape* shapeA = GetShapeA();
b3Body* bodyA = shapeA->GetBody();
b3Transform xfA = shapeA->GetTransform();
b3Transform xfA = bodyA->GetTransform();
b3Shape* shapeB = GetShapeB();
b3Body* bodyB = shapeB->GetBody();
b3MeshShape* meshShapeB = (b3MeshShape*)shapeB;
b3Transform xfB = shapeB->GetTransform();
b3Transform xfB = bodyB->GetTransform();
b3World* world = bodyA->GetWorld();
b3StackAllocator* allocator = &world->m_stackAllocator;
// Create one manifold per triangle.
b3Manifold* tempManifolds = (b3Manifold*)allocator->Allocate(m_triangleCount * sizeof(b3Manifold));
u32 tempCount = 0;
@ -263,7 +267,8 @@ void b3MeshContact::Collide()
++tempCount;
}
// Send contact manifolds for clustering. This is an important optimization.
B3_ASSERT(m_manifoldCount == 0);
m_manifoldCount = b3Clusterize(m_stackManifolds, tempManifolds, tempCount, xfA, shapeA->m_radius, xfB, B3_HULL_RADIUS);
allocator->Free(tempManifolds);
}
}

View File

@ -16,29 +16,29 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\common\draw.h>
#include <bounce\dynamics\world.h>
#include <bounce\dynamics\body.h>
#include <bounce/common/draw.h>
#include <bounce/dynamics/world.h>
#include <bounce/dynamics/body.h>
#include <bounce\dynamics\contacts\convex_contact.h>
#include <bounce\dynamics\contacts\mesh_contact.h>
#include <bounce/dynamics/contacts/convex_contact.h>
#include <bounce/dynamics/contacts/mesh_contact.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\dynamics\shapes\mesh_shape.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/dynamics/shapes/mesh_shape.h>
#include <bounce\dynamics\joints\mouse_joint.h>
#include <bounce\dynamics\joints\spring_joint.h>
#include <bounce\dynamics\joints\revolute_joint.h>
#include <bounce\dynamics\joints\sphere_joint.h>
#include <bounce\dynamics\joints\cone_joint.h>
#include <bounce/dynamics/joints/mouse_joint.h>
#include <bounce/dynamics/joints/spring_joint.h>
#include <bounce/dynamics/joints/revolute_joint.h>
#include <bounce/dynamics/joints/sphere_joint.h>
#include <bounce/dynamics/joints/cone_joint.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce\collision\shapes\mesh.h>
#include <bounce/collision/shapes/sphere.h>
#include <bounce/collision/shapes/capsule.h>
#include <bounce/collision/shapes/hull.h>
#include <bounce/collision/shapes/mesh.h>
void b3World::DebugDraw() const
{
@ -108,7 +108,7 @@ void b3World::DebugDraw() const
const b3Manifold* m = manifolds + i;
b3WorldManifold wm;
wm.Initialize(m, shapeA->GetTransform(), shapeA->m_radius, shapeB->GetTransform(), shapeB->m_radius);
wm.Initialize(m, shapeA->GetBody()->GetTransform(), shapeA->m_radius, shapeB->GetBody()->GetTransform(), shapeB->m_radius);
if (wm.pointCount > 0)
{

View File

@ -16,15 +16,15 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\island.h>
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\time_step.h>
#include <bounce\dynamics\joints\joint.h>
#include <bounce\dynamics\joints\joint_solver.h>
#include <bounce\dynamics\contacts\contact.h>
#include <bounce\dynamics\contacts\contact_solver.h>
#include <bounce\common\memory\stack_allocator.h>
#include <bounce\common\time.h>
#include <bounce/dynamics/island.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/time_step.h>
#include <bounce/dynamics/joints/joint.h>
#include <bounce/dynamics/joints/joint_solver.h>
#include <bounce/dynamics/contacts/contact.h>
#include <bounce/dynamics/contacts/contact_solver.h>
#include <bounce/common/memory/stack_allocator.h>
#include <bounce/common/time.h>
b3Island::b3Island(b3StackAllocator* allocator, u32 bodyCapacity, u32 contactCapacity, u32 jointCapacity)
{

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joint_manager.h>
#include <bounce\dynamics\joints\joint.h>
#include <bounce\dynamics\body.h>
#include <bounce/dynamics/joint_manager.h>
#include <bounce/dynamics/joints/joint.h>
#include <bounce/dynamics/body.h>
b3JointManager::b3JointManager()
{
@ -33,7 +33,7 @@ b3Joint* b3JointManager::Create(const b3JointDef* def)
B3_ASSERT(bodyA != bodyB);
if (bodyA == bodyB)
{
return nullptr;
return NULL;
}
// Allocate the new joint.

View File

@ -16,11 +16,11 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\cone_joint.h>
#include <bounce\dynamics\body.h>
#include <bounce\common\draw.h>
#include <bounce/dynamics/joints/cone_joint.h>
#include <bounce/dynamics/body.h>
#include <bounce/common/draw.h>
// C = dot(u2, u1) - cos(0.5 * angle) > 0
// C = dot(u2, u1) - cos(angle / 2) > 0
// Cdot = dot(u2, omega1 x u1) + dot(u1, omega2 x u2)
// Cycle:
// dot(u1 x u2, omega1) + dot(u2 x u1, omega2) =
@ -28,6 +28,9 @@
// n = u2 x u1
// J = [0 -n 0 n]
// Stable C:
// C = angle / 2 - atan2( norm(u2 x u1), dot(u2, u1) ) > 0
void b3ConeJointDef::Initialize(b3Body* bA, b3Body* bB,
const b3Vec3& axis, const b3Vec3& anchor, float32 angle)
{
@ -109,7 +112,7 @@ void b3ConeJoint::InitializeConstraints(const b3SolverData* data)
float32 mass = b3Dot((m_iA + m_iB) * m_limitAxis, m_limitAxis);
m_limitMass = mass > 0.0f ? 1.0f / mass : 0.0f;
// C = cone - angle >= 0
// C = cone / 2 - angle >= 0
float32 cosine = b3Dot(u2, u1);
float32 sine = b3Length(m_limitAxis);
float32 angle = atan2(sine, cosine);
@ -185,23 +188,12 @@ void b3ConeJoint::SolveVelocityConstraints(const b3SolverData* data)
// Solve limit constraint.
if (m_enableLimit && m_limitState != e_inactiveLimit)
{
float32 impulse = 0.0f;
float32 Cdot = b3Dot(m_limitAxis, wB - wA);
float32 impulse = -m_limitMass * Cdot;
float32 oldImpulse = m_limitImpulse;
m_limitImpulse = b3Max(m_limitImpulse + impulse, 0.0f);
impulse = m_limitImpulse - oldImpulse;
if (m_limitState == e_equalLimits)
{
float32 Cdot = b3Dot(m_limitAxis, wB - wA);
impulse = -m_limitMass * Cdot;
m_limitImpulse += impulse;
}
else if (m_limitState == e_atLowerLimit)
{
float32 Cdot = b3Dot(m_limitAxis, wB - wA);
impulse = -m_limitMass * Cdot;
float32 oldImpulse = m_limitImpulse;
m_limitImpulse = b3Max(m_limitImpulse + impulse, 0.0f);
impulse = m_limitImpulse - oldImpulse;
}
b3Vec3 P = impulse * m_limitAxis;
wA -= m_iA * P;
@ -258,12 +250,12 @@ bool b3ConeJoint::SolvePositionConstraints(const b3SolverData* data)
float32 limitError = 0.0f;
if (m_enableLimit)
{
// Compute Jacobian
// Compute fresh Jacobian
b3Vec3 u1 = b3Mul(qA, m_localFrameA.rotation.y);
b3Vec3 u2 = b3Mul(qB, m_localFrameB.rotation.y);
b3Vec3 limitAxis = b3Cross(u2, u1);
// Compute effective mass.
// Compute fresh effective mass.
float32 mass = b3Dot((iA + iB) * limitAxis, limitAxis);
float32 limitMass = mass > 0.0f ? 1.0f / mass : 0.0f;
@ -301,26 +293,26 @@ bool b3ConeJoint::SolvePositionConstraints(const b3SolverData* data)
return linearError <= B3_LINEAR_SLOP && limitError <= B3_ANGULAR_SLOP;
}
const b3Transform& b3ConeJoint::GetFrameA() const
b3Transform b3ConeJoint::GetFrameA() const
{
return GetBodyA()->GetWorldFrame(m_localFrameA);
}
b3Transform b3ConeJoint::GetFrameB() const
{
return GetBodyB()->GetWorldFrame(m_localFrameB);
}
const b3Transform& b3ConeJoint::GetLocalFrameA() const
{
return m_localFrameA;
}
void b3ConeJoint::SetFrameA(const b3Transform& frame)
{
m_localFrameA = frame;
}
const b3Transform& b3ConeJoint::GetFrameB() const
const b3Transform& b3ConeJoint::GetLocalFrameB() const
{
return m_localFrameB;
}
void b3ConeJoint::SetFrameB(const b3Transform& frame)
{
m_localFrameB = frame;
}
bool b3ConeJoint::IsLimitEnabled() const
{
return m_enableLimit;
@ -338,14 +330,14 @@ void b3ConeJoint::SetEnableLimit(bool bit)
}
}
float32 b3ConeJoint::GetLowerLimit() const
float32 b3ConeJoint::GetConeAngle() const
{
return m_coneAngle;
}
void b3ConeJoint::SetLimit(float32 angle)
void b3ConeJoint::SetConeAngle(float32 angle)
{
if (angle != m_coneAngle || angle != m_coneAngle)
if (angle != m_coneAngle)
{
GetBodyA()->SetAwake(true);
GetBodyB()->SetAwake(true);
@ -354,10 +346,10 @@ void b3ConeJoint::SetLimit(float32 angle)
}
}
void b3ConeJoint::Draw(b3Draw* b3Draw) const
void b3ConeJoint::Draw(b3Draw* draw) const
{
b3Transform xfA = GetBodyA()->GetWorldFrame(m_localFrameA);
b3Draw->DrawTransform(xfA);
b3Transform xfB = GetBodyB()->GetWorldFrame(m_localFrameB);
b3Draw->DrawTransform(xfB);
}
b3Transform xfA = GetFrameA();
draw->DrawTransform(xfA);
b3Transform xfB = GetFrameB();
draw->DrawTransform(xfB);
}

View File

@ -16,16 +16,16 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\joint.h>
#include <bounce\dynamics\joints\mouse_joint.h>
#include <bounce\dynamics\joints\spring_joint.h>
#include <bounce\dynamics\joints\revolute_joint.h>
#include <bounce\dynamics\joints\sphere_joint.h>
#include <bounce\dynamics\joints\cone_joint.h>
#include <bounce/dynamics/joints/joint.h>
#include <bounce/dynamics/joints/mouse_joint.h>
#include <bounce/dynamics/joints/spring_joint.h>
#include <bounce/dynamics/joints/revolute_joint.h>
#include <bounce/dynamics/joints/sphere_joint.h>
#include <bounce/dynamics/joints/cone_joint.h>
b3Joint* b3Joint::Create(const b3JointDef* def)
{
b3Joint* joint = nullptr;
b3Joint* joint = NULL;
switch (def->type)
{
case e_mouseJoint:

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\joint_solver.h>
#include <bounce\dynamics\joints\joint.h>
#include <bounce/dynamics/joints/joint_solver.h>
#include <bounce/dynamics/joints/joint.h>
b3JointSolver::b3JointSolver(const b3JointSolverDef* def)
{

View File

@ -16,15 +16,15 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\mouse_joint.h>
#include <bounce\dynamics\body.h>
#include <bounce\common\draw.h>
#include <bounce/dynamics/joints/mouse_joint.h>
#include <bounce/dynamics/body.h>
#include <bounce/common/draw.h>
b3MouseJoint::b3MouseJoint(const b3MouseJointDef* def)
{
m_type = e_mouseJoint;
m_worldAnchorA = def->worldAnchorA;
m_localAnchorB = def->localAnchorB;
m_worldTargetA = def->target;
m_localAnchorB = def->bodyB->GetLocalPoint(def->target);
m_maxForce = def->maxForce;
m_impulse.SetZero();
}
@ -42,7 +42,7 @@ void b3MouseJoint::InitializeConstraints(const b3SolverData* data)
b3Vec3 worldAnchorB = b3Mul(qB, m_localAnchorB) + xB;
m_C = worldAnchorB - m_worldAnchorA;
m_C = worldAnchorB - m_worldTargetA;
m_rB = worldAnchorB - xB;
b3Mat33 M = b3Diagonal(m_mB);
@ -54,7 +54,7 @@ void b3MouseJoint::InitializeConstraints(const b3SolverData* data)
void b3MouseJoint::WarmStart(const b3SolverData* data)
{
data->velocities[m_indexB].v += m_mB * m_impulse;
data->velocities[m_indexB].w += b3Mul(m_iB, b3Cross(m_rB, m_impulse));
data->velocities[m_indexB].w += m_iB * b3Cross(m_rB, m_impulse);
}
void b3MouseJoint::SolveVelocityConstraints(const b3SolverData* data)
@ -80,7 +80,7 @@ void b3MouseJoint::SolveVelocityConstraints(const b3SolverData* data)
impulse = m_impulse - oldImpulse;
vB += m_mB * impulse;
wB += b3Mul(m_iB, b3Cross(m_rB, impulse));
wB += m_iB * b3Cross(m_rB, impulse);
data->velocities[m_indexB].v = vB;
data->velocities[m_indexB].w = wB;
@ -88,27 +88,41 @@ void b3MouseJoint::SolveVelocityConstraints(const b3SolverData* data)
bool b3MouseJoint::SolvePositionConstraints(const b3SolverData* data)
{
// There is no position correction for spring joints.
// There is no position correction for this constraint.
// todo Implement Buda spring?
return true;
}
// Get the world space anchor point on the first body (usually the mouse world space position).
b3Vec3 b3MouseJoint::GetWorldAnchorB() const
b3Vec3 b3MouseJoint::GetAnchorA() const
{
return b3Mul(GetBodyB()->GetTransform(), m_localAnchorB);
return m_worldTargetA;
}
void b3MouseJoint::Draw(b3Draw* b3Draw) const
b3Vec3 b3MouseJoint::GetAnchorB() const
{
b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f);
b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f);
b3Color yellow = b3Color(1.0f, 1.0f, 0.0f, 1.0f);
return GetBodyB()->GetWorldPoint(m_localAnchorB);
}
const b3Vec3& b3MouseJoint::GetTarget() const
{
return m_worldTargetA;
}
void b3MouseJoint::SetTarget(const b3Vec3& target)
{
m_worldTargetA = target;
}
void b3MouseJoint::Draw(b3Draw* draw) const
{
b3Color red(1.0f, 0.0f, 0.0f);
b3Color green(0.0f, 1.0f, 0.0f);
b3Color yellow(1.0f, 1.0f, 0.0f);
b3Transform xfB = GetBodyB()->m_xf;
b3Vec3 worldAnchorA = m_worldAnchorA;
b3Vec3 worldAnchorB = b3Mul(xfB, m_localAnchorB);
b3Vec3 a = GetAnchorA();
b3Vec3 b = GetAnchorB();
b3Draw->DrawPoint(worldAnchorA, green);
b3Draw->DrawPoint(worldAnchorB, red);
b3Draw->DrawSegment(worldAnchorA, worldAnchorB, yellow);
}
draw->DrawPoint(a, green);
draw->DrawPoint(b, red);
draw->DrawSegment(a, b, yellow);
}

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\revolute_joint.h>
#include <bounce\dynamics\body.h>
#include <bounce\common\draw.h>
#include <bounce/dynamics/joints/revolute_joint.h>
#include <bounce/dynamics/body.h>
#include <bounce/common/draw.h>
// C1 = p2 - p1
// C2 = dot(u2, w1)
@ -35,7 +35,7 @@
// [0 -n1 0 n1]
// [0 -n2 0 n2]
// W = [i1 0 0]
// W = [i1 0 0 0]
// [0 m1 0 0]
// [0 0 i2 0]
// [0 0 0 m2]
@ -359,8 +359,7 @@ void b3RevoluteJoint::SolveVelocityConstraints(const b3SolverData* data)
Cdot[3] = Cdot2;
Cdot[4] = Cdot3;
// Copy the effective mass so it can be destroyed in the
// linear solver.
// Copy the matrix so it can be destroyed in the linear solver.
b3Mat<5, 5> mass = m_mass;
b3Vec<5> impulse = -Cdot;
if (b3Solve(impulse.e, mass.e, 5))
@ -566,26 +565,26 @@ bool b3RevoluteJoint::SolvePositionConstraints(const b3SolverData* data)
limitError <= B3_ANGULAR_SLOP;
}
const b3Transform& b3RevoluteJoint::GetFrameA() const
b3Transform b3RevoluteJoint::GetFrameA() const
{
return GetBodyA()->GetWorldFrame(m_localFrameA);
}
b3Transform b3RevoluteJoint::GetFrameB() const
{
return GetBodyB()->GetWorldFrame(m_localFrameB);
}
const b3Transform& b3RevoluteJoint::GetLocalFrameA() const
{
return m_localFrameA;
}
void b3RevoluteJoint::SetFrameA(const b3Transform& frame)
{
m_localFrameA = frame;
}
const b3Transform& b3RevoluteJoint::GetFrameB() const
const b3Transform& b3RevoluteJoint::GetLocalFrameB() const
{
return m_localFrameB;
}
void b3RevoluteJoint::SetFrameB(const b3Transform& frame)
{
m_localFrameB = frame;
}
bool b3RevoluteJoint::IsLimitEnabled() const
{
return m_enableLimit;
@ -666,10 +665,10 @@ void b3RevoluteJoint::SetMaxMotorTorque(float32 torque)
m_maxMotorTorque = torque;
}
void b3RevoluteJoint::Draw(b3Draw* b3Draw) const
void b3RevoluteJoint::Draw(b3Draw* draw) const
{
b3Transform xfA = GetBodyA()->GetWorldFrame(m_localFrameA);
b3Draw->DrawTransform(xfA);
b3Transform xfB = GetBodyB()->GetWorldFrame(m_localFrameB);
b3Draw->DrawTransform(xfB);
}
b3Transform xfA = GetFrameA();
b3Transform xfB = GetFrameB();
draw->DrawTransform(xfA);
draw->DrawTransform(xfB);
}

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\sphere_joint.h>
#include <bounce\dynamics\body.h>
#include <bounce\common\draw.h>
#include <bounce/dynamics/joints/sphere_joint.h>
#include <bounce/dynamics/body.h>
#include <bounce/common/draw.h>
void b3SphereJointDef::Initialize(b3Body* bA, b3Body* bB, const b3Vec3& anchor)
{
@ -147,12 +147,22 @@ bool b3SphereJoint::SolvePositionConstraints(const b3SolverData* data)
return b3Length(C) <= B3_LINEAR_SLOP;
}
void b3SphereJoint::Draw(b3Draw* b3Draw) const
b3Vec3 b3SphereJoint::GetAnchorA() const
{
b3Vec3 pA = GetBodyA()->GetWorldPoint(m_localAnchorA);
b3Draw->DrawPoint(pA, b3Color(1.0f, 0.0f, 0.0f, 1.0f));
b3Vec3 pB = GetBodyB()->GetWorldPoint(m_localAnchorB);
b3Draw->DrawPoint(pB, b3Color(0.0f, 1.0f, 0.0f, 1.0f));
b3Draw->DrawSegment(pA, pB, b3Color(1.0f, 1.0f, 0.0f, 1.0f));
return GetBodyA()->GetWorldPoint(m_localAnchorA);
}
b3Vec3 b3SphereJoint::GetAnchorB() const
{
return GetBodyB()->GetWorldPoint(m_localAnchorB);
}
void b3SphereJoint::Draw(b3Draw* draw) const
{
b3Vec3 a = GetAnchorA();
b3Vec3 b = GetAnchorB();
draw->DrawPoint(a, b3Color(1.0f, 0.0f, 0.0f));
draw->DrawPoint(b, b3Color(0.0f, 1.0f, 0.0f));
draw->DrawSegment(a, b, b3Color(1.0f, 1.0f, 0.0f));
}

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\joints\spring_joint.h>
#include <bounce\dynamics\body.h>
#include <bounce\common\draw.h>
#include <bounce/dynamics/joints/spring_joint.h>
#include <bounce/dynamics/body.h>
#include <bounce/common/draw.h>
// C = ||x2 + r2 - x1 - r1|| - length
// Cdot = dot(n, v2 + w2 x r2 - v1 - w1 x r1)
@ -44,6 +44,56 @@ b3SpringJoint::b3SpringJoint(const b3SpringJointDef* def)
m_impulse = 0.0f;
}
b3Vec3 b3SpringJoint::GetAnchorA() const
{
return GetBodyA()->GetWorldPoint(m_localAnchorA);
}
b3Vec3 b3SpringJoint::GetAnchorB() const
{
return GetBodyB()->GetWorldPoint(m_localAnchorB);
}
const b3Vec3& b3SpringJoint::GetLocalAnchorA() const
{
return m_localAnchorA;
}
const b3Vec3& b3SpringJoint::GetLocalAnchorB() const
{
return m_localAnchorB;
}
float32 b3SpringJoint::GetLength() const
{
return m_length;
}
void b3SpringJoint::SetLength(float32 length)
{
m_length = length;
}
float32 b3SpringJoint::GetFrequency() const
{
return m_frequencyHz;
}
void b3SpringJoint::SetFrequency(float32 frequency)
{
m_frequencyHz = frequency;
}
float32 b3SpringJoint::GetDampingRatio() const
{
return m_dampingRatio;
}
void b3SpringJoint::SetDampingRatio(float32 ratio)
{
m_dampingRatio = ratio;
}
void b3SpringJoint::InitializeConstraints(const b3SolverData* data)
{
b3Body* m_bodyA = GetBodyA();
@ -66,7 +116,7 @@ void b3SpringJoint::InitializeConstraints(const b3SolverData* data)
b3Vec3 xB = data->positions[m_indexB].x;
b3Quat qB = data->positions[m_indexB].q;
// Handle singularity
// Singularity check.
m_n = xB + m_rB - xA - m_rA;
float32 length = b3Length(m_n);
if (length > B3_LINEAR_SLOP)
@ -199,16 +249,16 @@ bool b3SpringJoint::SolvePositionConstraints(const b3SolverData* data)
return b3Abs(C) < B3_LINEAR_SLOP;
}
void b3SpringJoint::Draw(b3Draw* b3Draw) const
void b3SpringJoint::Draw(b3Draw* draw) const
{
b3Color red = b3Color(1.0f, 0.0f, 0.0f, 1.0f);
b3Color green = b3Color(0.0f, 1.0f, 0.0f, 1.0f);
b3Color blue = b3Color(0.0f, 0.0f, 1.0f, 1.0f);
b3Vec3 pA = GetBodyA()->GetWorldPoint(m_localAnchorA);
b3Vec3 pB = GetBodyB()->GetWorldPoint(m_localAnchorB);
b3Vec3 a = GetBodyA()->GetWorldPoint(m_localAnchorA);
b3Vec3 b = GetBodyB()->GetWorldPoint(m_localAnchorB);
b3Draw->DrawPoint(pA, green);
b3Draw->DrawPoint(pB, green);
b3Draw->DrawSegment(pA, pB, blue);
draw->DrawPoint(a, green);
draw->DrawPoint(b, green);
draw->DrawSegment(a, b, blue);
}

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
b3CapsuleShape::b3CapsuleShape()
{

View File

@ -16,15 +16,15 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce\common\template\array.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/collision/shapes/hull.h>
#include <bounce/common/template/array.h>
b3HullShape::b3HullShape()
{
m_type = e_hullShape;
m_radius = B3_HULL_RADIUS;
m_hull = nullptr;
m_hull = NULL;
}
b3HullShape::~b3HullShape()

View File

@ -16,14 +16,14 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\shapes\mesh_shape.h>
#include <bounce\collision\shapes\mesh.h>
#include <bounce/dynamics/shapes/mesh_shape.h>
#include <bounce/collision/shapes/mesh.h>
b3MeshShape::b3MeshShape()
{
m_type = e_meshShape;
m_radius = B3_HULL_RADIUS;
m_mesh = nullptr;
m_mesh = NULL;
}
b3MeshShape::~b3MeshShape()
@ -161,7 +161,7 @@ bool b3MeshShape::RayCast(b3RayCastOutput* output, const b3RayCastInput& input,
callback.hit = false;
callback.output.fraction = B3_MAX_FLOAT;
m_mesh->tree.QueryRay(&callback, subInput);
m_mesh->tree.RayCast(&callback, subInput);
output->fraction = callback.output.fraction;
output->normal = b3Mul(xf.rotation, callback.output.normal);

View File

@ -16,18 +16,18 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce\dynamics\shapes\capsule_shape.h>
#include <bounce\dynamics\shapes\hull_shape.h>
#include <bounce\dynamics\shapes\mesh_shape.h>
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\world.h>
#include <bounce\dynamics\contacts\contact.h>
#include <bounce\collision\shapes\sphere.h>
#include <bounce\collision\shapes\capsule.h>
#include <bounce\collision\shapes\hull.h>
#include <bounce\collision\shapes\mesh.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
#include <bounce/dynamics/shapes/capsule_shape.h>
#include <bounce/dynamics/shapes/hull_shape.h>
#include <bounce/dynamics/shapes/mesh_shape.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/world.h>
#include <bounce/dynamics/contacts/contact.h>
#include <bounce/collision/shapes/sphere.h>
#include <bounce/collision/shapes/capsule.h>
#include <bounce/collision/shapes/hull.h>
#include <bounce/collision/shapes/mesh.h>
void b3Shape::SetSensor(bool flag)
{
@ -41,11 +41,6 @@ void b3Shape::SetSensor(bool flag)
}
}
b3Transform b3Shape::GetTransform() const
{
return m_body->GetTransform();
}
void b3Shape::DestroyContacts()
{
b3World* world = m_body->GetWorld();
@ -195,7 +190,7 @@ void b3Shape::Dump(i32 bodyIndex) const
b3Shape* b3Shape::Create(const b3ShapeDef& def)
{
b3Shape* shape = nullptr;
b3Shape* shape = NULL;
switch (def.shape->GetType())
{
case e_sphereShape:

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\shapes\sphere_shape.h>
#include <bounce/dynamics/shapes/sphere_shape.h>
b3SphereShape::b3SphereShape()
{

View File

@ -16,15 +16,15 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\dynamics\world.h>
#include <bounce\dynamics\body.h>
#include <bounce\dynamics\island.h>
#include <bounce\dynamics\world_listeners.h>
#include <bounce\dynamics\shapes\shape.h>
#include <bounce\dynamics\contacts\contact.h>
#include <bounce\dynamics\joints\joint.h>
#include <bounce\dynamics\time_step.h>
#include <bounce\common\time.h>
#include <bounce/dynamics/world.h>
#include <bounce/dynamics/body.h>
#include <bounce/dynamics/island.h>
#include <bounce/dynamics/world_listeners.h>
#include <bounce/dynamics/shapes/shape.h>
#include <bounce/dynamics/contacts/contact.h>
#include <bounce/dynamics/joints/joint.h>
#include <bounce/dynamics/time_step.h>
#include <bounce/common/time.h>
extern u32 b3_allocCalls;
extern u32 b3_maxAllocCalls;
@ -33,7 +33,7 @@ b3World::b3World() : m_bodyBlocks(sizeof(b3Body))
{
b3_allocCalls = 0;
b3_maxAllocCalls = 0;
m_debugDraw = nullptr;
m_debugDraw = NULL;
memset(&m_profile, 0, sizeof(b3Profile));
m_flags = e_clearForcesFlag;
@ -329,7 +329,7 @@ void b3World::Solve(float32 dt, u32 velocityIterations, u32 positionIterations)
}
}
struct b3CastRayCallback
struct b3RayCastCallback
{
float32 Report(const b3RayCastInput& input, i32 proxyId)
{
@ -338,7 +338,7 @@ struct b3CastRayCallback
b3Shape* shape = (b3Shape*)userData;
// Calculate transformation from shape local space to world space.
b3Transform xf = shape->GetTransform();
b3Transform xf = shape->GetBody()->GetTransform();
b3RayCastOutput output;
bool hit = shape->RayCast(&output, input, xf);
@ -364,20 +364,20 @@ struct b3CastRayCallback
const b3BroadPhase* broadPhase;
};
void b3World::CastRay(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const
void b3World::RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const
{
b3RayCastInput input;
input.p1 = p1;
input.p2 = p2;
input.maxFraction = 1.0f;
b3CastRayCallback callback;
b3RayCastCallback callback;
callback.listener = listener;
callback.broadPhase = &m_contactMan.m_broadPhase;
m_contactMan.m_broadPhase.QueryRay(&callback, input);
m_contactMan.m_broadPhase.RayCast(&callback, input);
}
struct b3CastAABBCallback
struct b3QueryAABBCallback
{
bool Report(i32 proxyID)
{
@ -389,9 +389,9 @@ struct b3CastAABBCallback
const b3BroadPhase* broadPhase;
};
void b3World::CastAABB(b3QueryListener* listener, const b3AABB3& aabb) const
void b3World::QueryAABB(b3QueryListener* listener, const b3AABB3& aabb) const
{
b3CastAABBCallback callback;
b3QueryAABBCallback callback;
callback.listener = listener;
callback.broadPhase = &m_contactMan.m_broadPhase;
m_contactMan.m_broadPhase.QueryAABB(&callback, aabb);

View File

@ -16,9 +16,9 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <bounce\quickhull\qh_hull.h>
#include <bounce\common\template\stack.h>
#include <bounce\common\draw.h>
#include <bounce/quickhull/qh_hull.h>
#include <bounce/common/template/stack.h>
#include <bounce/common/draw.h>
float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Array<b3Vec3>& vertices)
{
@ -76,31 +76,31 @@ void qhHull::Construct(void* memory, const b3Array<b3Vec3>& vs)
// Euler's formula
// V - E + F = 2
m_freeVertices = nullptr;
m_freeVertices = NULL;
qhVertex* vertices = (qhVertex*)memory;
for (u32 i = 0; i < V; ++i)
{
FreeVertex(vertices + i);
}
m_freeEdges = nullptr;
m_freeEdges = NULL;
qhHalfEdge* edges = (qhHalfEdge*)((u8*)vertices + V * sizeof(qhVertex));
for (u32 i = 0; i < HE; ++i)
{
FreeEdge(edges + i);
}
m_freeFaces = nullptr;
m_freeFaces = NULL;
qhFace* faces = (qhFace*)((u8*)edges + HE * sizeof(qhHalfEdge));
for (u32 i = 0; i < F; ++i)
{
qhFace* f = faces + i;
f->conflictList.head = nullptr;
f->conflictList.head = NULL;
f->conflictList.count = 0;
FreeFace(f);
}
m_faceList.head = nullptr;
m_faceList.head = NULL;
m_faceList.count = 0;
m_iteration = 0;
@ -295,7 +295,7 @@ bool qhHull::BuildInitialHull(const b3Array<b3Vec3>& vertices)
// Discard internal points since they can't be in the hull.
float32 d0 = m_tolerance;
qhFace* f0 = nullptr;
qhFace* f0 = NULL;
for (u32 j = 0; j < 4; ++j)
{
@ -324,7 +324,7 @@ qhVertex* qhHull::NextVertex()
{
// Find the point furthest from the current hull.
float32 d0 = m_tolerance;
qhVertex* v0 = nullptr;
qhVertex* v0 = NULL;
qhFace* f = m_faceList.head;
while (f)
@ -479,7 +479,7 @@ qhHalfEdge* qhHull::AddAdjoiningTriangle(qhVertex* eye, qhHalfEdge* horizonEdge)
e1->tail = v1;
e1->prev = e3;
e1->next = e2;
e1->twin = nullptr;
e1->twin = NULL;
e1->face = face;
e2->tail = v2;
@ -492,10 +492,10 @@ qhHalfEdge* qhHull::AddAdjoiningTriangle(qhVertex* eye, qhHalfEdge* horizonEdge)
e3->tail = v3;
e3->prev = e2;
e3->next = e1;
e3->twin = nullptr;
e3->twin = NULL;
e3->face = face;
horizonEdge->twin = nullptr;
horizonEdge->twin = NULL;
face->edge = e1;
face->center = (v1->position + v2->position + v3->position) / 3.0f;
@ -511,8 +511,8 @@ void qhHull::AddNewFaces(b3Array<qhFace*>& newFaces, qhVertex* eye, const b3Arra
{
newFaces.Reserve(horizon.Count());
qhHalfEdge* beginEdge = nullptr;
qhHalfEdge* prevEdge = nullptr;
qhHalfEdge* beginEdge = NULL;
qhHalfEdge* prevEdge = NULL;
{
qhHalfEdge* edge = horizon[0];
@ -571,7 +571,7 @@ void qhHull::AddNewFaces(b3Array<qhFace*>& newFaces, qhVertex* eye, const b3Arra
// Use tolerance and discard internal points.
float32 max = m_tolerance;
qhFace* iMax = nullptr;
qhFace* iMax = NULL;
for (u32 i = 0; i < newFaces.Count(); ++i)
{
@ -587,7 +587,7 @@ void qhHull::AddNewFaces(b3Array<qhFace*>& newFaces, qhVertex* eye, const b3Arra
if (iMax)
{
qhVertex* v0 = v;
v->conflictFace = nullptr;
v->conflictFace = NULL;
v = f->conflictList.Remove(v);
iMax->conflictList.PushFront(v0);
v0->conflictFace = iMax;
@ -595,7 +595,7 @@ void qhHull::AddNewFaces(b3Array<qhFace*>& newFaces, qhVertex* eye, const b3Arra
else
{
qhVertex* v0 = v;
v->conflictFace = nullptr;
v->conflictFace = NULL;
v = f->conflictList.Remove(v);
FreeVertex(v0);
}
@ -739,7 +739,7 @@ bool qhHull::IsConsistent() const
return true;
}
void qhHull::Draw(b3Draw* b3Draw) const
void qhHull::Draw(b3Draw* draw) const
{
qhFace* face = m_faceList.head;
while (face)
@ -750,12 +750,12 @@ void qhHull::Draw(b3Draw* b3Draw) const
qhVertex* v = face->conflictList.head;
while (v)
{
b3Draw->DrawPoint(v->position, b3Color(1.0f, 1.0f, 0.0f));
b3Draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f));
draw->DrawPoint(v->position, b3Color(1.0f, 1.0f, 0.0f));
draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f));
v = v->next;
}
b3Draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f));
draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f));
b3StackArray<b3Vec3, 32> polygon;
qhHalfEdge* edge = face->edge;
@ -765,7 +765,7 @@ void qhHull::Draw(b3Draw* b3Draw) const
edge = edge->next;
} while (edge != face->edge);
b3Draw->DrawSolidPolygon(polygon.Elements(), polygon.Count(), b3Color(0.0f, 0.0f, 1.0f, 1.0f));
draw->DrawSolidPolygon(polygon.Elements(), polygon.Count(), b3Color(0.0f, 0.0f, 1.0f, 1.0f));
face = face->next;
}

View File

@ -16,10 +16,14 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <glad\glad.h>
#include <gl\GLU.h>
#include <imgui\imgui.h>
#include <testbed\framework\debug_draw.h>
#include <testbed/framework/debug_draw.h>
#include <glad/glad.h>
#include <GL/glu.h>
#include <stdio.h>
#include <stdarg.h>
#include <imgui/imgui.h>
extern Camera g_camera;
@ -594,7 +598,7 @@ struct DrawShapes
while (s)
{
DrawShape(s, xf);
s = s->m_next;
s = s->GetNext();
}
glDisable(GL_COLOR_MATERIAL);
@ -798,4 +802,4 @@ void DebugDraw::Submit()
m_triangles->Submit();
m_lines->Submit();
m_points->Submit();
}
}

View File

@ -16,11 +16,11 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <glad\glad.h>
#include <glfw\glfw3.h>
#include <imgui\imgui.h>
#include <imgui\imgui_impl_glfw_gl3.h>
#include <testbed\tests\test.h>
#include <glad/glad.h>
#include <glfw/glfw3.h>
#include <imgui/imgui.h>
#include <imgui/imgui_impl_glfw_gl3.h>
#include <testbed/tests/test.h>
GLFWwindow* g_window;
Settings g_settings;
@ -29,7 +29,7 @@ Camera g_camera;
DebugDraw* g_debugDraw;
bool g_leftDown;
bool g_rightDown;
bool g_altDown;
bool g_shiftDown;
b3Vec2 g_ps0;
void WindowSize(int w, int h)
@ -51,7 +51,7 @@ void MouseMove(GLFWwindow* w, double x, double y)
float32 nx = b3Clamp(dp.x, -1.0f, 1.0f);
float32 ny = b3Clamp(dp.y, -1.0f, 1.0f);
if (g_altDown)
if (g_shiftDown)
{
if (g_leftDown)
{
@ -83,7 +83,7 @@ void MouseMove(GLFWwindow* w, double x, double y)
void MouseWheel(GLFWwindow* w, double dx, double dy)
{
float32 n = b3Clamp(float32(dy), -1.0f, 1.0f);
if (g_altDown)
if (g_shiftDown)
{
g_camera.m_zoom += 0.5f * -n;
}
@ -106,7 +106,7 @@ void MouseButton(GLFWwindow* w, int button, int action, int mods)
{
g_leftDown = true;
if (g_altDown == false)
if (g_shiftDown == false)
{
g_test->MouseLeftDown(pw);
}
@ -125,7 +125,7 @@ void MouseButton(GLFWwindow* w, int button, int action, int mods)
{
g_leftDown = false;
if (g_altDown == false)
if (g_shiftDown == false)
{
g_test->MouseLeftUp(pw);
}
@ -150,13 +150,13 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
{
case GLFW_PRESS:
{
if (button == GLFW_KEY_LEFT_ALT)
if (button == GLFW_KEY_LEFT_SHIFT)
{
g_altDown = true;
g_shiftDown = true;
g_test->KeyDown(button);
}
if (g_altDown)
if (g_shiftDown)
{
if (button == GLFW_KEY_DOWN)
{
@ -167,11 +167,6 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
{
g_camera.m_zoom -= 0.05f;
}
if (button == GLFW_KEY_R)
{
g_settings.lastTestID = -1;
}
}
else
{
@ -182,12 +177,12 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
}
case GLFW_RELEASE:
{
if (button == GLFW_KEY_LEFT_ALT)
if (button == GLFW_KEY_LEFT_SHIFT)
{
g_altDown = false;
g_shiftDown = false;
}
if (g_altDown == false)
if (g_shiftDown == false)
{
g_test->KeyUp(button);
}
@ -247,7 +242,7 @@ void Interface()
}
ImVec2 buttonSize = ImVec2(-1, 0);
if (ImGui::Button("Restart (R)", buttonSize))
if (ImGui::Button("Restart", buttonSize))
{
g_settings.lastTestID = -1;
}
@ -345,13 +340,6 @@ void Run()
ImGui_ImplGlfwGL3_NewFrame();
Step();
if (g_settings.drawShapes)
{
g_debugDraw->Submit(g_test->m_world);
}
if (g_settings.drawGrid)
{
u32 n = 20;
@ -397,9 +385,16 @@ void Run()
g_debugDraw->DrawSegment(p1, p2, color2);
}
}
Step();
g_debugDraw->Submit();
if (g_settings.drawShapes)
{
g_debugDraw->Submit(g_test->m_world);
}
Interface();
ImGui::Render();
@ -411,53 +406,65 @@ void Run()
}
int main(int argc, char** args)
{
// Create g_window
{
if (glfwInit() == 0)
{
fprintf(stderr, "Failed to initialize GLFW\n");
return -1;
}
// Create g_window
extern b3Version b3_version;
char title[256];
sprintf_s(title, "Bounce Testbed Version %d.%d.%d", b3_version.major, b3_version.minor, b3_version.revision);
sprintf(title, "Bounce Testbed Version %d.%d.%d", b3_version.major, b3_version.minor, b3_version.revision);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
g_window = glfwCreateWindow(1024, 768, title, NULL, NULL);
g_leftDown = false;
g_rightDown = false;
g_altDown = false;
g_ps0.SetZero();
glfwMakeContextCurrent(g_window);
glfwSwapInterval(1);
if (g_window == NULL)
{
fprintf(stderr, "Failed to opengl GLFW window\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(g_window);
glfwSetCursorPosCallback(g_window, MouseMove);
glfwSetScrollCallback(g_window, MouseWheel);
glfwSetMouseButtonCallback(g_window, MouseButton);
glfwSetKeyCallback(g_window, KeyButton);
glfwSetCharCallback(g_window, Char);
glfwSwapInterval(1);
if (gladLoadGL() == 0)
{
fprintf(stderr, "Error: %d\n", glad_glGetError());
glfwTerminate();
exit(EXIT_FAILURE);
}
printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
g_leftDown = false;
g_rightDown = false;
g_shiftDown = false;
g_ps0.SetZero();
// Create UI
CreateInterface();
// Create renderer
g_debugDraw = new DebugDraw();
// Run the g_tests
g_test = nullptr;
// Run the testbed
g_test = NULL;
Run();
// Destroy the last test
if (g_test)
{
delete g_test;
g_test = nullptr;
g_test = NULL;
}
// Destroy renderer

View File

@ -16,7 +16,7 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <testbed\tests\test.h>
#include <testbed/tests/test.h>
extern u32 b3_allocCalls, b3_maxAllocCalls;
extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters;
@ -49,9 +49,8 @@ Test::Test()
g_camera.m_center.SetZero();
g_settings.drawGrid = false;
m_rayHit.m_shape = nullptr;
m_mouseJoint = nullptr;
m_groundBody = nullptr;
m_rayHit.m_shape = NULL;
m_mouseJoint = NULL;
{
b3Transform xf;
@ -363,20 +362,23 @@ void Test::MouseMove(const Ray3& pw)
float32 w1 = 1.0f - hitFraction;
float32 w2 = hitFraction;
b3Vec3 worldPointA = w1 * pw.Start() + w2 * pw.End();
m_mouseJoint->SetWorldAnchorA(worldPointA);
b3Vec3 target = w1 * pw.Start() + w2 * pw.End();
m_mouseJoint->SetTarget(target);
}
}
void Test::MouseLeftDown(const Ray3& pw)
{
// Clear the current hit
m_rayHit.m_shape = nullptr;
m_rayHit.m_shape = NULL;
if (m_mouseJoint)
{
b3Body* groundBody = m_mouseJoint->GetBodyA();
m_world.DestroyJoint(m_mouseJoint);
m_mouseJoint = nullptr;
m_world.DestroyBody(m_groundBody);
m_mouseJoint = NULL;
m_world.DestroyBody(groundBody);
}
b3Vec3 p1 = pw.Start();
@ -384,7 +386,7 @@ void Test::MouseLeftDown(const Ray3& pw)
// Perform the ray cast
RayCastListener listener;
m_world.CastRay(&listener, p1, p2);
m_world.RayCast(&listener, p1, p2);
int hitId = listener.FindClosestHit();
@ -400,40 +402,28 @@ void Test::MouseLeftDown(const Ray3& pw)
void Test::MouseLeftUp(const Ray3& pw)
{
m_rayHit.m_shape = nullptr;
m_rayHit.m_shape = NULL;
if (m_mouseJoint)
{
b3Body* groundBody = m_mouseJoint->GetBodyA();
m_world.DestroyJoint(m_mouseJoint);
m_mouseJoint = nullptr;
m_world.DestroyBody(m_groundBody);
m_mouseJoint = NULL;
m_world.DestroyBody(groundBody);
}
}
void Test::RayHit()
{
b3BodyDef bdef;
m_groundBody = m_world.CreateBody(bdef);
b3Shape* shape = m_rayHit.m_shape;
b3Body* bodyA = m_groundBody;
b3Body* bodyB = shape->GetBody();
// Ray hit point in world space
b3Vec3 worldPointA = m_rayHit.m_point;
// xf from world space to the local space of the shape
b3Transform xf = shape->GetTransform();
// Ray hit point in world space
// lp = xf^-1 * wp
b3Vec3 localPointA = b3MulT(xf, worldPointA);
b3Body* bodyA = m_world.CreateBody(bdef);
b3Body* bodyB = m_rayHit.m_shape->GetBody();
b3MouseJointDef def;
def.bodyA = bodyA;
def.bodyB = bodyB;
def.worldAnchorA = worldPointA;
def.localAnchorB = localPointA;
def.target = m_rayHit.m_point;
def.maxForce = 2000.0f * bodyB->GetMass();
m_mouseJoint = (b3MouseJoint*)m_world.CreateJoint(def);

View File

@ -16,36 +16,36 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <testbed\tests\test.h>
#include <testbed\tests\quickhull_test.h>
#include <testbed\tests\cluster_test.h>
#include <testbed\tests\distance_test.h>
#include <testbed\tests\capsule_distance.h>
#include <testbed\tests\collide_test.h>
#include <testbed\tests\capsule_collision.h>
#include <testbed\tests\capsule_and_hull_collision.h>
#include <testbed\tests\hull_collision.h>
#include <testbed\tests\spring.h>
#include <testbed\tests\newton_cradle.h>
#include <testbed\tests\hinge_motor.h>
#include <testbed\tests\hinge_chain.h>
#include <testbed\tests\ragdoll.h>
#include <testbed\tests\quadrics.h>
#include <testbed\tests\mesh_contact_test.h>
#include <testbed\tests\sphere_stack.h>
#include <testbed\tests\capsule_stack.h>
#include <testbed\tests\box_stack.h>
#include <testbed\tests\shape_stack.h>
#include <testbed\tests\jenga.h>
#include <testbed\tests\thin.h>
#include <testbed\tests\pyramid.h>
#include <testbed\tests\pyramids.h>
#include <testbed\tests\ray_cast.h>
#include <testbed\tests\sensor_test.h>
#include <testbed\tests\character_test.h>
#include <testbed\tests\body_types.h>
#include <testbed\tests\varying_friction.h>
#include <testbed\tests\varying_restitution.h>
#include <testbed/tests/test.h>
#include <testbed/tests/quickhull_test.h>
#include <testbed/tests/cluster_test.h>
#include <testbed/tests/distance_test.h>
#include <testbed/tests/capsule_distance.h>
#include <testbed/tests/collide_test.h>
#include <testbed/tests/capsule_collision.h>
#include <testbed/tests/capsule_and_hull_collision.h>
#include <testbed/tests/hull_collision.h>
#include <testbed/tests/spring.h>
#include <testbed/tests/newton_cradle.h>
#include <testbed/tests/hinge_motor.h>
#include <testbed/tests/hinge_chain.h>
#include <testbed/tests/ragdoll.h>
#include <testbed/tests/quadrics.h>
#include <testbed/tests/mesh_contact_test.h>
#include <testbed/tests/sphere_stack.h>
#include <testbed/tests/capsule_stack.h>
#include <testbed/tests/box_stack.h>
#include <testbed/tests/shape_stack.h>
#include <testbed/tests/jenga.h>
#include <testbed/tests/thin.h>
#include <testbed/tests/pyramid.h>
#include <testbed/tests/pyramids.h>
#include <testbed/tests/ray_cast.h>
#include <testbed/tests/sensor_test.h>
#include <testbed/tests/character_test.h>
#include <testbed/tests/body_types.h>
#include <testbed/tests/varying_friction.h>
#include <testbed/tests/varying_restitution.h>
TestEntry g_tests[e_testCount] =
{