more tests

This commit is contained in:
Irlan 2018-04-29 23:33:43 -03:00
parent f3c263111b
commit dc12bd5c8e
7 changed files with 275 additions and 14 deletions

View File

@ -22,10 +22,11 @@
#include <testbed/tests/distance_test.h>
#include <testbed/tests/collide_test.h>
#include <testbed/tests/capsule_collision.h>
#include <testbed/tests/hull_collision.h>
#include <testbed/tests/deep_capsule.h>
#include <testbed/tests/degenerate_capsule.h>
#include <testbed/tests/hull_face_contact.h>
#include <testbed/tests/hull_edge_contact.h>
#include <testbed/tests/box_face_contact.h>
#include <testbed/tests/box_edge_contact.h>
#include <testbed/tests/linear_motion.h>
#include <testbed/tests/angular_motion.h>
#include <testbed/tests/gyro_motion.h>
@ -41,6 +42,7 @@
#include <testbed/tests/newton_cradle.h>
#include <testbed/tests/ragdoll.h>
#include <testbed/tests/mesh_contact_test.h>
#include <testbed/tests/hull_contact_test.h>
#include <testbed/tests/sphere_stack.h>
#include <testbed/tests/capsule_stack.h>
#include <testbed/tests/box_stack.h>
@ -73,11 +75,13 @@ TestEntry g_tests[] =
{ "Cluster", &Cluster::Create },
{ "Distance", &Distance::Create },
{ "Capsule Collision", &CapsuleCollision::Create },
{ "Hull Collision", &HullCollision::Create },
{ "Deep Capsule", &DeepCapsule::Create },
{ "Degenerate Capsule", &DegenerateCapsule::Create },
{ "Hull Face Contact", &HullFaceContact::Create },
{ "Hull Edge Contact", &HullEdgeContact::Create },
{ "Box Face Contact", &BoxFaceContact::Create },
{ "Box Edge Contact", &BoxEdgeContact::Create },
{ "Capsule Spin", &CapsuleSpin::Create },
{ "Hull Contact Test", &HullContactTest::Create },
{ "Mesh Contact Test", &MeshContactTest::Create },
{ "Linear Motion", &LinearMotion::Create },
{ "Angular Motion", &AngularMotion::Create },

View File

@ -16,13 +16,13 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef HULL_EDGE_CONTACT_H
#define HULL_EDGE_CONTACT_H
#ifndef BOX_EDGE_CONTACT_H
#define BOX_EDGE_CONTACT_H
class HullEdgeContact : public Collide
class BoxEdgeContact : public Collide
{
public:
HullEdgeContact()
BoxEdgeContact()
{
b3Transform xf;
xf.position.SetZero();
@ -49,7 +49,7 @@ public:
static Test* Create()
{
return new HullEdgeContact();
return new BoxEdgeContact();
}
b3BoxHull m_box;

View File

@ -16,13 +16,13 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef HULL_FACE_CONTACT_H
#define HULL_FACE_CONTACT_H
#ifndef BOX_FACE_CONTACT_H
#define BOX_FACE_CONTACT_H
class HullFaceContact : public Collide
class BoxFaceContact : public Collide
{
public:
HullFaceContact()
BoxFaceContact()
{
b3Transform m;
m.rotation = b3Diagonal(1.0f, 2.0f, 1.0f);
@ -50,7 +50,7 @@ public:
static Test* Create()
{
return new HullFaceContact();
return new BoxFaceContact();
}
b3BoxHull m_box1;

View File

@ -55,6 +55,9 @@ public:
m_world.DrawShape(m_xfA, m_shapeA);
m_world.DrawShape(m_xfB, m_shapeB);
g_draw->DrawString(b3Color_white, "Left/Right/Up/Down Arrow - Translate shape");
g_draw->DrawString(b3Color_white, "X/Y/Z - Rotate shape");
}
virtual void KeyDown(int key)
@ -94,6 +97,14 @@ public:
m_xfB.rotation = m_xfB.rotation * xfy;
}
if (key == GLFW_KEY_Z)
{
b3Quat qy(b3Vec3(0.0f, 0.0f, 1.0f), 0.05f * B3_PI);
b3Mat33 xfz = b3QuatMat33(qy);
m_xfB.rotation = m_xfB.rotation * xfz;
}
}
b3Shape* m_shapeA;

View File

@ -70,6 +70,9 @@ public:
m_world.DrawShape(m_xfA, &m_shapeA);
m_world.DrawShape(m_xfB, &m_shapeB);
g_draw->DrawString(b3Color_white, "Left/Right/Up/Down Arrow - Translate shape");
g_draw->DrawString(b3Color_white, "X/Y/Z - Rotate shape");
}
void KeyDown(int key)
@ -109,6 +112,14 @@ public:
m_xfB.rotation = m_xfB.rotation * xfy;
}
if (key == GLFW_KEY_Z)
{
b3Quat qy(b3Vec3(0.0f, 0.0f, 1.0f), 0.05f * B3_PI);
b3Mat33 xfz = b3QuatMat33(qy);
m_xfB.rotation = m_xfB.rotation * xfz;
}
}
static Test* Create()

View File

@ -0,0 +1,120 @@
/*
* 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.
*/
#ifndef HULL_COLLISION_H
#define HULL_COLLISION_H
class HullCollision : public Collide
{
public:
enum
{
// Half to avoid generation failure due to many vertices
e_count = B3_MAX_HULL_VERTICES / 2
};
HullCollision()
{
m_xfA.position.Set(0.0f, 1.5f, 0.0f);
m_xfA.rotation.SetIdentity();
m_xfB.SetIdentity();
m_cache.count = 0;
Generate();
}
void KeyDown(int button)
{
if (button == GLFW_KEY_G)
{
Generate();
}
Collide::KeyDown(button);
}
void Generate()
{
for (u32 i = 0; i < e_count; ++i)
{
float32 x = RandomFloat(-1.0f, 1.0f);
float32 y = RandomFloat(-1.0f, 1.0f);
float32 z = RandomFloat(-1.0f, 1.0f);
// Clamp to force coplanarities.
// This will stress the convex hull creation code.
x = b3Clamp(x, -0.9f, 0.9f);
y = b3Clamp(y, -0.9f, 0.9f);
z = b3Clamp(z, -0.9f, 0.9f);
b3Vec3 p(x, y, z);
m_points1[i] = p;
}
for (u32 i = 0; i < e_count; ++i)
{
float32 x = RandomFloat(-1.0f, 1.0f);
float32 y = RandomFloat(-1.0f, 1.0f);
float32 z = RandomFloat(-1.0f, 1.0f);
// Clamp to force coplanarities.
// This will stress the convex hull creation code.
x = b3Clamp(x, -0.9f, 0.9f);
y = b3Clamp(y, -0.9f, 0.9f);
z = b3Clamp(z, -0.9f, 0.9f);
b3Vec3 p(x, y, z);
m_points2[i] = p;
}
}
void Step()
{
b3QHull hull1;
hull1.Set(m_points1, e_count);
b3HullShape sA;
sA.m_hull = &hull1;
m_shapeA = &sA;
b3QHull hull2;
hull2.Set(m_points2, e_count);
b3HullShape sB;
sB.m_hull = &hull2;
m_shapeB = &sB;
g_draw->DrawString(b3Color_white, "G - Generate a random convex hull pair");
Collide::Step();
}
static Test* Create()
{
return new HullCollision();
}
b3Vec3 m_points1[e_count];
b3Vec3 m_points2[e_count];
};
#endif

View File

@ -0,0 +1,115 @@
/*
* 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.
*/
#ifndef HULL_CONTACT_TEST_H
#define HULL_CONTACT_TEST_H
class HullContactTest : public Test
{
public:
HullContactTest()
{
{
b3BodyDef bdef;
bdef.type = b3BodyType::e_staticBody;
b3Body* body = m_world.CreateBody(bdef);
b3HullShape hs;
hs.m_hull = &m_groundHull;
b3ShapeDef sdef;
sdef.shape = &hs;
sdef.friction = 1.0f;
body->CreateShape(sdef);
}
static b3QHull hulls[2];
for (u32 i = 0; i < 2; ++i)
{
b3QHull* hull = hulls + i;
const u32 count = B3_MAX_HULL_VERTICES / 4;
b3Vec3 points[count];
for (u32 j = 0; j < count; ++j)
{
// Clamp to force coplanarities.
// This will stress the generation code.
float32 x = 3.0f * RandomFloat(-1.0f, 1.0f);
float32 y = 3.0f * RandomFloat(-1.0f, 1.0f);
float32 z = 3.0f * RandomFloat(-1.0f, 1.0f);
x = b3Clamp(x, -1.5f, 1.5f);
y = b3Clamp(y, -1.5f, 1.5f);
z = b3Clamp(z, -1.5f, 1.5f);
b3Vec3 p(x, y, z);
points[j] = p;
}
hull->Set(points, count);
}
{
b3BodyDef bdef;
bdef.type = b3BodyType::e_dynamicBody;
bdef.position.Set(0.0f, 5.0f, 0.0f);
b3Body* body = m_world.CreateBody(bdef);
b3HullShape hs;
hs.m_hull = hulls + 0;
b3ShapeDef sdef;
sdef.density = 0.1f;
sdef.friction = 0.1f;
sdef.shape = &hs;
body->CreateShape(sdef);
}
{
b3BodyDef bdef;
bdef.type = b3BodyType::e_dynamicBody;
bdef.position.Set(0.0f, 10.0f, 0.0f);
b3Body* body = m_world.CreateBody(bdef);
b3HullShape hs;
hs.m_hull = hulls + 1;
b3ShapeDef sdef;
sdef.density = 0.1f;
sdef.friction = 0.1f;
sdef.shape = &hs;
body->CreateShape(sdef);
}
}
static Test* Create()
{
return new HullContactTest();
}
};
#endif