diff --git a/examples/testbed/framework/test_entries.cpp b/examples/testbed/framework/test_entries.cpp index 70d3ec3..99d7d9a 100644 --- a/examples/testbed/framework/test_entries.cpp +++ b/examples/testbed/framework/test_entries.cpp @@ -58,16 +58,16 @@ #include #include #include -#include #include #include #include #include -#include +#include +#include #include +#include #include #include -#include TestEntry g_tests[] = { @@ -111,15 +111,15 @@ TestEntry g_tests[] = { "Varying Restitution", &VaryingRestitution::Create }, { "Tumbler", &Tumbler::Create }, { "Initial Overlap", &InitialOverlap::Create }, - { "Single Pendulum", &SinglePendulum::Create }, { "Multiple Pendulum", &MultiplePendulum::Create }, { "Cloth", &Cloth::Create }, - { "Spring Cloth", &SpringCloth::Create }, - { "Spring Cloth Collision", &SpringClothCollision::Create }, - { "Tension Mapping", &TensionMapping::Create }, - { "Rope", &Rope::Create }, { "Mass-Spring System", &MassSpring::Create }, - { "Shift Center", &ShiftCenter::Create }, + { "Spring Cloth", &SpringCloth::Create }, + { "Spring Cloth Contact", &SpringClothContact::Create }, + { "Mass Types", &MassTypes::Create }, + { "Tension Mapping", &TensionMapping::Create }, + { "Single Pendulum", &SinglePendulum::Create }, + { "Rope", &Rope::Create }, { NULL, NULL } }; diff --git a/examples/testbed/tests/mass_types.h b/examples/testbed/tests/mass_types.h new file mode 100644 index 0000000..21080a2 --- /dev/null +++ b/examples/testbed/tests/mass_types.h @@ -0,0 +1,198 @@ +/* +* 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 MASS_TYPES_H +#define MASS_TYPES_H + +class MassTypes : public SpringClothTest +{ +public: + MassTypes() + { + b3SpringClothDef def; + def.allocator = &m_clothAllocator; + def.mesh = &m_clothMesh; + def.density = 0.2f; + def.ks = 100000.0f; + def.gravity.Set(0.0f, -10.0f, 0.0f); + + m_cloth.Initialize(def); + + b3AABB3 aabb; + aabb.m_lower.Set(-5.0f, -1.0f, -6.0f); + aabb.m_upper.Set(5.0f, 1.0f, -4.0f); + + for (u32 i = 0; i < def.mesh->vertexCount; ++i) + { + if (aabb.Contains(def.mesh->vertices[i])) + { + m_cloth.SetType(i, b3MassType::e_staticMass); + } + } + } + + void Step() + { + SpringClothTest::Step(); + + g_draw->DrawString(b3Color_white, "S - Static"); + g_draw->DrawString(b3Color_white, "D - Dynamic"); + g_draw->DrawString(b3Color_white, "K - Kinematic"); + g_draw->DrawString(b3Color_white, "Arrows - Apply Force/Velocity/Position"); + } + + void KeyDown(int button) + { + if (button == GLFW_KEY_S) + { + for (u32 i = 0; i < m_cloth.GetMassCount(); ++i) + { + m_cloth.SetType(i, b3MassType::e_staticMass); + } + } + + if (button == GLFW_KEY_K) + { + for (u32 i = 0; i < m_cloth.GetMassCount(); ++i) + { + m_cloth.SetType(i, b3MassType::e_kinematicMass); + } + } + + if (button == GLFW_KEY_D) + { + for (u32 i = 0; i < m_cloth.GetMassCount(); ++i) + { + m_cloth.SetType(i, b3MassType::e_dynamicMass); + } + } + + for (u32 i = 0; i < m_cloth.GetMassCount(); ++i) + { + if (m_cloth.GetType(i) == b3MassType::e_staticMass) + { + if (button == GLFW_KEY_LEFT) + { + b3Vec3 p = m_cloth.GetPosition(i); + + p.x -= 1.0f; + + m_cloth.SetPosition(i, p); + } + + if (button == GLFW_KEY_RIGHT) + { + b3Vec3 p = m_cloth.GetPosition(i); + + p.x += 1.0f; + + m_cloth.SetPosition(i, p); + } + + if (button == GLFW_KEY_UP) + { + b3Vec3 p = m_cloth.GetPosition(i); + + p.z += 1.0f; + + m_cloth.SetPosition(i, p); + } + + if (button == GLFW_KEY_DOWN) + { + b3Vec3 p = m_cloth.GetPosition(i); + + p.z -= 1.0f; + + m_cloth.SetPosition(i, p); + } + } + + if (m_cloth.GetType(i) == b3MassType::e_kinematicMass) + { + if (button == GLFW_KEY_LEFT) + { + b3Vec3 v = m_cloth.GetVelocity(i); + + v.x -= 5.0f; + + m_cloth.SetVelocity(i, v); + } + + if (button == GLFW_KEY_RIGHT) + { + b3Vec3 v = m_cloth.GetVelocity(i); + + v.x += 5.0f; + + m_cloth.SetVelocity(i, v); + } + + if (button == GLFW_KEY_UP) + { + b3Vec3 v = m_cloth.GetVelocity(i); + + v.z -= 5.0f; + + m_cloth.SetVelocity(i, v); + } + + if (button == GLFW_KEY_DOWN) + { + b3Vec3 v = m_cloth.GetVelocity(i); + + v.z += 5.0f; + + m_cloth.SetVelocity(i, v); + } + } + + if (m_cloth.GetType(i) == b3MassType::e_dynamicMass) + { + if (button == GLFW_KEY_LEFT) + { + m_cloth.ApplyForce(i, b3Vec3(-100.0f, 0.0f, 0.0f)); + } + + if (button == GLFW_KEY_RIGHT) + { + m_cloth.ApplyForce(i, b3Vec3(100.0f, 0.0f, 0.0f)); + } + + if (button == GLFW_KEY_UP) + { + m_cloth.ApplyForce(i, b3Vec3(0.0f, 0.0f, -100.0f)); + } + + if (button == GLFW_KEY_DOWN) + { + m_cloth.ApplyForce(i, b3Vec3(0.0f, 0.0f, 100.0f)); + } + } + } + } + + static Test* Create() + { + return new MassTypes(); + } + + b3GridMesh<10, 10> m_clothMesh; +}; + +#endif \ No newline at end of file diff --git a/examples/testbed/tests/shift_center.h b/examples/testbed/tests/shift_center.h deleted file mode 100644 index 0f479d7..0000000 --- a/examples/testbed/tests/shift_center.h +++ /dev/null @@ -1,94 +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. -*/ - -#ifndef SHIFT_CENTER_H -#define SHIFT_CENTER_H - -class ShiftCenter : public Test -{ -public: - ShiftCenter() - { - { - b3BodyDef bd; - b3Body* ground = m_world.CreateBody(bd); - - b3HullShape hs; - hs.m_hull = &m_groundHull; - - b3ShapeDef sd; - sd.shape = &hs; - - ground->CreateShape(sd); - } - - { - b3BodyDef bd; - bd.type = e_dynamicBody; - bd.position.Set(0.0f, 5.0f, 0.0f); - - b3Body* body = m_world.CreateBody(bd); - - b3SphereShape sphere; - sphere.m_center.SetZero(); - sphere.m_radius = 1.0f; - - b3ShapeDef sd; - sd.density = 0.1f; - sd.friction = 0.3f; - sd.shape = &sphere; - - body->CreateShape(sd); - - // Retrieve the local center of mass and inertia about the - // local center of mass - b3MassData massData; - body->GetMassData(&massData); - - // Shift the inertia to the local origin - massData.I += massData.mass * b3Steiner(massData.center); - - // Make a copy of the old local center of mass - b3Vec3 oldCenter = massData.center; - - // Pick a center of mass of choice - massData.center.z += 10.0f; - - // Measure the displacement from the old local center of mass - // to the new local center of mass. - b3Vec3 d = massData.center - oldCenter; - - // Move the inertia at the local origin to the new local origin - massData.I += massData.mass * b3Steiner(d); - - // Update local center of mass and inertia - body->SetMassData(&massData); - } - } - - ~ShiftCenter() - { - } - - static Test* Create() - { - return new ShiftCenter(); - } -}; - -#endif \ No newline at end of file diff --git a/examples/testbed/tests/spring_cloth_collision_test.h b/examples/testbed/tests/spring_cloth_contact.h similarity index 88% rename from examples/testbed/tests/spring_cloth_collision_test.h rename to examples/testbed/tests/spring_cloth_contact.h index 35c4bbf..db446ee 100644 --- a/examples/testbed/tests/spring_cloth_collision_test.h +++ b/examples/testbed/tests/spring_cloth_contact.h @@ -16,13 +16,13 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SPRING_CLOTH_COLLISION_H -#define SPRING_CLOTH_COLLISION_H +#ifndef SPRING_CLOTH_CONTACT_H +#define SPRING_CLOTH_CONTACT_H -class SpringClothCollision : public SpringClothTest +class SpringClothContact : public SpringClothTest { public: - SpringClothCollision() + SpringClothContact() { b3SpringClothDef def; def.allocator = &m_clothAllocator; @@ -46,7 +46,7 @@ public: static Test* Create() { - return new SpringClothCollision(); + return new SpringClothContact(); } b3GridMesh<10, 10> m_clothMesh;