test update

Test cloth mass type switching feature which allows the user to set some particles as static, kinematic, or dynamic.

Renamed SpringClothCollision to SpringClothContact for consistency.

Removed ShiftCenter test for visualizing the effects of external center of mass shifting. This probably must be moved into another folder since might scare the user.

Ordered some test entries such that experiments are the last defined. Those are not actually features of the library and probably must be removed from the testbed into a different project containing experiments.
This commit is contained in:
Irlan 2018-05-18 19:35:16 -03:00
parent 66228785fc
commit 2f383fb958
4 changed files with 212 additions and 108 deletions

View File

@ -58,16 +58,16 @@
#include <testbed/tests/varying_friction.h>
#include <testbed/tests/varying_restitution.h>
#include <testbed/tests/tumbler.h>
#include <testbed/tests/single_pendulum.h>
#include <testbed/tests/multiple_pendulum.h>
#include <testbed/tests/cloth_test.h>
#include <testbed/tests/spring_cloth_test.h>
#include <testbed/tests/spring_cloth.h>
#include <testbed/tests/spring_cloth_collision_test.h>
#include <testbed/tests/spring_cloth_contact.h>
#include <testbed/tests/mass_types.h>
#include <testbed/tests/tension_mapping.h>
#include <testbed/tests/single_pendulum.h>
#include <testbed/tests/rope_test.h>
#include <testbed/tests/mass_spring.h>
#include <testbed/tests/shift_center.h>
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 }
};

View File

@ -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

View File

@ -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

View File

@ -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;