This commit is contained in:
Irlan
2017-05-28 21:05:32 -03:00
parent e0d2580fa1
commit c411bf341a
34 changed files with 1693 additions and 181 deletions

View File

@ -64,7 +64,7 @@ b3Mat44 Camera::BuildProjectionMatrix() const
b3Transform Camera::BuildWorldTransform() const
{
b3Transform xf;
xf.rotation = b3ConvertQuatToMat(m_q);
xf.rotation = b3QuatMat33(m_q);
xf.position = (m_zoom * xf.rotation.z) - m_center;
return xf;
}
@ -78,7 +78,7 @@ b3Mat44 Camera::BuildWorldMatrix() const
b3Transform Camera::BuildViewTransform() const
{
b3Transform xf;
xf.rotation = b3ConvertQuatToMat(m_q);
xf.rotation = b3QuatMat33(m_q);
xf.position = (m_zoom * xf.rotation.z) - m_center;
return b3Inverse(xf);
}
@ -1281,6 +1281,65 @@ void DebugDraw::DrawSolidSphere(const b3Vec3& center, float32 radius, const b3Co
m_solid->DrawSphere(radius, color, xf);
}
void DebugDraw::DrawCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius, const b3Color& color)
{
float32 height = b3Length(c1 - c2);
{
b3Transform xfc;
xfc.rotation.SetIdentity();
xfc.position = c1;
m_wire->DrawSphere(radius, color, xfc);
}
if (height > 0.0f)
{
DrawSegment(c1, c2, color);
{
b3Transform xfc;
xfc.rotation.SetIdentity();
xfc.position = c2;
m_wire->DrawSphere(radius, color, xfc);
}
}
}
void DebugDraw::DrawSolidCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius, const b3Color& c)
{
float32 height = b3Length(c1 - c2);
{
b3Transform xfc;
xfc.rotation.SetIdentity();
xfc.position = c1;
m_solid->DrawSphere(radius, c, xfc);
}
if (height > 0.0f)
{
{
b3Mat33 R;
R.y = (1.0f / height) * (c1 - c2);
R.z = b3Perp(R.y);
R.x = b3Cross(R.y, R.z);
b3Transform xfc;
xfc.position = 0.5f * (c1 + c2);
xfc.rotation = R;
m_solid->DrawCylinder(radius, height, c, xfc);
}
{
b3Transform xfc;
xfc.rotation.SetIdentity();
xfc.position = c2;
m_solid->DrawSphere(radius, c, xfc);
}
}
}
void DebugDraw::DrawTransform(const b3Transform& xf)
{
float32 lenght = 1.0f;

View File

@ -103,6 +103,10 @@ public:
void DrawSolidSphere(const b3Vec3& center, float32 radius, const b3Color& color);
void DrawCapsule(const b3Vec3& p1, const b3Vec3& p2, float32 radius, const b3Color& color);
void DrawSolidCapsule(const b3Vec3& p1, const b3Vec3& p2, float32 radius, const b3Color& color);
void DrawAABB(const b3AABB3& aabb, const b3Color& color);
void DrawTransform(const b3Transform& xf);

View File

@ -64,14 +64,14 @@ static void MouseMove(GLFWwindow* w, double x, double y)
if (g_leftDown)
{
// Negate angles to do positive rotations (CCW) of the world.
float32 angleX = 0.005f * B3_PI * -nx;
float32 angleY = 0.005f * B3_PI * -ny;
float32 angleX = 0.005f * B3_PI * -nx;
b3Quat qx = b3QuatRotationX(angleY);
b3Quat qy = b3QuatRotationY(angleX);
b3Quat qx(b3Vec3(1.0f, 0.0f, 0.0f), angleY);
b3Quat qy(b3Vec3(0.0f, 1.0f, 0.0f), angleX);
g_camera.m_q = qy * g_camera.m_q;
g_camera.m_q = g_camera.m_q * qx;
g_camera.m_q = qy * g_camera.m_q;
g_camera.m_q.Normalize();
}

View File

@ -55,9 +55,12 @@
#include <testbed/tests/body_types.h>
#include <testbed/tests/varying_friction.h>
#include <testbed/tests/varying_restitution.h>
#include <testbed/tests/cloth_test.h>
#include <testbed/tests/tumbler.h>
#include <testbed/tests/pendulum.h>
#include <testbed/tests/single_pendulum.h>
#include <testbed/tests/multiple_pendulum.h>
#include <testbed/tests/cloth_test.h>
#include <testbed/tests/rope_test.h>
//#include <testbed/tests/tree_test.h>
TestEntry g_tests[] =
{
@ -97,9 +100,12 @@ TestEntry g_tests[] =
{ "Body Types", &BodyTypes::Create },
{ "Varying Friction", &VaryingFriction::Create },
{ "Varying Restitution", &VaryingRestitution::Create },
{ "Cloth", &Cloth::Create },
{ "Tumbler", &Tumbler::Create },
{ "Initial Overlap", &InitialOverlap::Create },
{ "Pendulum", &Pendulum::Create },
{ "Single Pendulum", &SinglePendulum::Create },
{ "Multiple Pendulum", &MultiplePendulum::Create },
{ "Cloth", &Cloth::Create },
{ "Rope", &Rope::Create },
//{ "Tree", &Tree::Create },
{ NULL, NULL }
};

View File

@ -33,11 +33,11 @@ public:
{
g_camera.m_center.Set(2.5f, -2.0f, 5.5f);
g_camera.m_zoom = 40.0f;
{
b3BodyDef bdef;
bdef.type = b3BodyType::e_staticBody;
b3Body* body = m_world.CreateBody(bdef);
b3HullShape hs;
@ -48,12 +48,12 @@ public:
sdef.friction = 1.0f;
body->CreateShape(sdef);
}
}
b3Vec3 boxScale(1.0f, 1.0f, 1.0f);
static b3BoxHull boxHull;
b3Transform m;
m.rotation = b3Diagonal(boxScale.x, boxScale.y, boxScale.z);
m.position.SetZero();
@ -75,7 +75,7 @@ public:
bdef.position.x = float32(i) * boxScale.x;
bdef.position.y = 2.5f * float32(j) * boxScale.y;
bdef.position.z = float32(k) * boxScale.z;
bdef.position += stackOrigin;
b3Body* body = m_world.CreateBody(bdef);

View File

@ -25,14 +25,14 @@ public:
CapsuleAndHullCollision1()
{
m_xfA.position.Set(0.0f, 0.0f, 0.0f);
m_xfA.rotation = b3ConvertQuatToMat(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.55f * B3_PI));
m_xfA.rotation = b3QuatMat33(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.55f * B3_PI));
m_sA.m_centers[0].Set(1.0f, -1.0f, 0.0f);
m_sA.m_centers[1].Set(0.0f, 1.0f, 0.0f);
m_sA.m_radius = 2.0f;
m_xfB.position.Set(0.f, 0.0f, 0.0f);
m_xfB.rotation = b3ConvertQuatToMat(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.0f * B3_PI));
m_xfB.rotation = b3QuatMat33(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.0f * B3_PI));
b3Transform xf;
xf.SetIdentity();

View File

@ -25,14 +25,14 @@ public:
CapsuleAndHullCollision2()
{
m_xfA.position.Set(0.0f, 0.0f, 0.0f);
m_xfA.rotation = b3ConvertQuatToMat(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.55f * B3_PI));
m_xfA.rotation = b3QuatMat33(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.55f * B3_PI));
m_sA.m_centers[0].Set(0.0f, 0.0f, 0.0f);
m_sA.m_centers[1].Set(0.0f, 0.0f, 0.0f);
m_sA.m_radius = 0.05f;
m_xfB.position.Set(0.f, 0.0f, 0.0f);
m_xfB.rotation = b3ConvertQuatToMat(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.0f * B3_PI));
m_xfB.rotation = b3QuatMat33(b3Quat(b3Vec3(0.0f, 0.0f, 1.0f), 0.0f * B3_PI));
b3Transform xf;
xf.SetIdentity();

View File

@ -92,7 +92,7 @@ public:
if (key == GLFW_KEY_X)
{
b3Quat qx(b3Vec3(1.0f, 0.0f, 0.0f), 0.05f * B3_PI);
b3Mat33 xfx = b3ConvertQuatToMat(qx);
b3Mat33 xfx = b3QuatMat33(qx);
m_xfB.rotation = m_xfB.rotation * xfx;
}
@ -100,7 +100,7 @@ public:
if (key == GLFW_KEY_Y)
{
b3Quat qy(b3Vec3(0.0f, 1.0f, 0.0f), 0.05f * B3_PI);
b3Mat33 xfy = b3ConvertQuatToMat(qy);
b3Mat33 xfy = b3QuatMat33(qy);
m_xfB.rotation = m_xfB.rotation * xfy;
}

View File

@ -103,7 +103,7 @@ public:
if (key == GLFW_KEY_X)
{
b3Quat qx(b3Vec3(1.0f, 0.0f, 0.0f), 0.05f * B3_PI);
b3Mat33 xfx = b3ConvertQuatToMat(qx);
b3Mat33 xfx = b3QuatMat33(qx);
m_xfB.rotation = m_xfB.rotation * xfx;
}
@ -111,7 +111,7 @@ public:
if (key == GLFW_KEY_Y)
{
b3Quat qy(b3Vec3(0.0f, 1.0f, 0.0f), 0.05f * B3_PI);
b3Mat33 xfy = b3ConvertQuatToMat(qy);
b3Mat33 xfy = b3QuatMat33(qy);
m_xfB.rotation = m_xfB.rotation * xfy;
}

View File

@ -0,0 +1,149 @@
/*
* 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 MULTIPLE_PENDULUM
#define MULTIPLE_PENDULUM
class MultiplePendulum : public Test
{
public:
MultiplePendulum()
{
g_camera.m_zoom = 10.0f;
b3Vec3 axis(0.0f, 0.0f, 1.0f);
b3Body* bs[6];
{
b3BodyDef bd;
bd.type = e_staticBody;
bs[0] = m_world.CreateBody(bd);
}
{
b3BodyDef bd;
bd.type = e_dynamicBody;
bd.position.Set(-0.5f, 0.0f, 0.0f);
bs[1] = m_world.CreateBody(bd);
b3CapsuleShape s;
s.m_centers[0].Set(0.5f, 0.0f, 0.0f);
s.m_centers[1].Set(-0.5f, 0.0f, 0.0f);
s.m_radius = 0.05f;
b3ShapeDef sd;
sd.shape = &s;
sd.density = 10.0f;
bs[1]->CreateShape(sd);
b3RevoluteJointDef jd;
jd.Initialize(bs[0], bs[1], axis, b3Vec3(0.0f, 0.0f, 0.0f), 0.0f, 1.0f);
m_world.CreateJoint(jd);
}
{
b3BodyDef bd;
bd.type = e_dynamicBody;
bd.position.Set(-1.5f, 0.0f, 0.0f);
bs[2] = m_world.CreateBody(bd);
b3CapsuleShape s;
s.m_centers[0].Set(0.5f, 0.0f, 0.0f);
s.m_centers[1].Set(-0.5f, 0.0f, 0.0f);
s.m_radius = 0.05f;
b3ShapeDef sd;
sd.shape = &s;
sd.density = 10.0f;
bs[2]->CreateShape(sd);
b3RevoluteJointDef jd;
jd.Initialize(bs[1], bs[2], axis, b3Vec3(-1.0f, 0.0f, 0.0f), 0.0f, 1.0f);
m_world.CreateJoint(jd);
}
{
b3BodyDef bd;
bd.type = e_dynamicBody;
bd.position.Set(-2.5f, 0.0f, 0.0f);
bs[3] = m_world.CreateBody(bd);
b3CapsuleShape s;
s.m_centers[0].Set(0.5f, 0.0f, 0.0f);
s.m_centers[1].Set(-0.5f, 0.0f, 0.0f);
s.m_radius = 0.05f;
b3ShapeDef sd;
sd.shape = &s;
sd.density = 100.0f;
bs[3]->CreateShape(sd);
b3RevoluteJointDef jd;
jd.Initialize(bs[2], bs[3], axis, b3Vec3(-2.0f, 0.0f, 0.0f), 0.0f, 1.0f);
m_world.CreateJoint(jd);
}
{
b3BodyDef bd;
bd.type = e_dynamicBody;
bd.position.Set(-3.5f, 0.0f, 0.0f);
bs[4] = m_world.CreateBody(bd);
b3CapsuleShape s;
s.m_centers[0].Set(0.5f, 0.0f, 0.0f);
s.m_centers[1].Set(-0.5f, 0.0f, 0.0f);
s.m_radius = 0.05f;
b3ShapeDef sd;
sd.shape = &s;
sd.density = 1000.0f;
bs[4]->CreateShape(sd);
b3RevoluteJointDef jd;
jd.Initialize(bs[3], bs[4], axis, b3Vec3(-3.0f, 0.0f, 0.0f), 0.0f, 1.0f);
m_world.CreateJoint(jd);
}
{
b3BodyDef bd;
bd.type = e_dynamicBody;
bd.position.Set(-4.5f, 0.0f, 0.0f);
bs[5] = m_world.CreateBody(bd);
b3CapsuleShape s;
s.m_centers[0].Set(0.5f, 0.0f, 0.0f);
s.m_centers[1].Set(-0.5f, 0.0f, 0.0f);
s.m_radius = 0.05f;
b3ShapeDef sd;
sd.shape = &s;
sd.density = 50.0f;
bs[5]->CreateShape(sd);
b3RevoluteJointDef jd;
jd.Initialize(bs[4], bs[5], axis, b3Vec3(-4.0f, 0.0f, 0.0f), 0.0f, 1.0f);
m_world.CreateJoint(jd);
}
}
static Test* Create()
{
return new MultiplePendulum();
}
};
#endif

View File

@ -0,0 +1,118 @@
/*
* 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 hebd 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 woubd 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 ROPE_TEST_H
#define ROPE_TEST_H
extern Settings g_settings;
class Rope : public Test
{
public:
enum
{
e_count = 10
};
Rope()
{
g_camera.m_zoom = 30.0f;
b3Vec3 vs[e_count];
float32 ms[e_count];
vs[0].Set(0.0f, 0.0f, 0.0f);
ms[0] = 0.0f;
for (u32 i = 1; i < e_count; ++i)
{
ms[i] = 1.0f;
vs[i].Set(float32(i), 0.0f, 0.0f);
}
b3RopeDef rd;
rd.gravity.Set(0.0f, -10.0f, 0.0f);
rd.masses = ms;
rd.vertices = vs;
rd.count = e_count;
m_rope.Initialize(rd);
}
void KeyDown(int button)
{
if (button == GLFW_KEY_A)
{
m_rope.SetGravity(b3Vec3(-10.0f, 0.0f, 0.0f));
}
if (button == GLFW_KEY_D)
{
m_rope.SetGravity(b3Vec3(10.0f, 0.0f, 0.0f));
}
if (button == GLFW_KEY_S)
{
m_rope.SetGravity(b3Vec3(0.0f, 0.0f, 10.0f));
}
if (button == GLFW_KEY_W)
{
m_rope.SetGravity(b3Vec3(0.0f, 0.0f, -10.0f));
}
if (button == GLFW_KEY_Q)
{
m_rope.SetGravity(b3Vec3(0.0f, 10.0f, 0.0f));
}
if (button == GLFW_KEY_E)
{
m_rope.SetGravity(b3Vec3(0.0f, -10.0f, 0.0f));
}
}
void Step()
{
float32 dt = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
if (g_settings.pause)
{
if (g_settings.singleStep)
{
g_settings.singleStep = false;
}
else
{
dt = 0.0f;
}
}
m_rope.Step(dt);
m_rope.Draw(g_debugDraw);
}
static Test* Create()
{
return new Rope();
}
b3Rope m_rope;
};
#endif

View File

@ -22,10 +22,10 @@
extern Settings g_settings;
extern DebugDraw* g_debugDraw;
class Pendulum : public Test
class SinglePendulum : public Test
{
public:
Pendulum()
SinglePendulum()
{
m_g = -10.0f;
@ -34,7 +34,7 @@ public:
m_I = m_m * m_r * m_r;
// Initial state
m_theta = 0.5f * B3_PI;
m_theta = -0.5f * B3_PI;
m_omega = 0.0f;
}
@ -90,7 +90,7 @@ public:
static Test* Create()
{
return new Pendulum();
return new SinglePendulum();
}
// Gravity