commit x64 compilation from lulu cause the other branch dont seems to compile properly at home
This commit is contained in:
73
include/engine/physic/physic_constraint_desc.cpp
Normal file
73
include/engine/physic/physic_constraint_desc.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "physic/physic_constraint_desc.h"
|
||||
#include "metafile/nml.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using GS::NML::Tag;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool PhysicConstraintDesc::FromMetaTag(Tag &tag)
|
||||
{
|
||||
if (tag.name != "Constraint")
|
||||
__ERR__(__LOG_E__ << "Could not parse physic constraint, incorrect root tag (" << tag.name << ").\n", false)
|
||||
|
||||
type = TypeNone;
|
||||
item_a = item_b = NULL;
|
||||
pivot_a = pivot_b = Matrix4::IdentityMatrix();
|
||||
|
||||
NMLTagForeach(pt, tag)
|
||||
{
|
||||
if (pt->name == "Type")
|
||||
{
|
||||
String _type(pt->GetString());
|
||||
|
||||
if (_type == "Point")
|
||||
type = TypePoint;
|
||||
else if (_type == "Hinge")
|
||||
type = TypeHinge;
|
||||
}
|
||||
|
||||
else if (pt->name == "PivotA")
|
||||
pivot_a.FromMetaTag(*pt);
|
||||
else if (pt->name == "PivotB")
|
||||
pivot_b.FromMetaTag(*pt);
|
||||
|
||||
else __LOG_W__ << "Unknown tag '" << pt->name << "' in <PhysicConstraint>.\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Tag *PhysicConstraintDesc::AsMetaTag() const
|
||||
{
|
||||
Tag *root = new Tag("Constraint");
|
||||
if (!root)
|
||||
__ERR__(__LOG_E__ << "Could not create physic constraint root tag to serialize.\n", NULL)
|
||||
|
||||
if (type != TypeNone)
|
||||
{
|
||||
String _type = "None";
|
||||
switch (type)
|
||||
{
|
||||
case TypePoint: _type = "Point"; break;
|
||||
case TypeHinge: _type = "Hinge"; break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
root->AddChild("Type", _type.c_str());
|
||||
}
|
||||
|
||||
// Save pivot informations.
|
||||
root->AddChild(pivot_a.AsMetaTag("PivotA"));
|
||||
root->AddChild(pivot_b.AsMetaTag("PivotB"));
|
||||
return root;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
143
include/engine/physic/physic_item_desc.cpp
Normal file
143
include/engine/physic/physic_item_desc.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "physic/physic_item_desc.h"
|
||||
#include "metafile/nml.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using namespace GS::NML;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
float PhysicItemDesc::GetMass() const
|
||||
{
|
||||
float mass = 0;
|
||||
ListForeachPtr(PhysicShape *, shape, shape_list)
|
||||
mass += shape->mass;
|
||||
return mass;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool PhysicItemDesc::FromMetaTag(Tag &tag)
|
||||
{
|
||||
if ((tag.name != "TauItem") && (tag.name != "GColItem") && (tag.name != "PhysicItem"))
|
||||
__ERR__(__LOG_E__ << "Could not parse physic item, incorrect root tag (" << tag.name << ").\n", false)
|
||||
|
||||
shape_list.Clear();
|
||||
vehicle.wheel_list.Clear();
|
||||
physic_flags.Set(PhysicFlag_None);
|
||||
|
||||
self_mask = 1;
|
||||
collision_mask = 1;
|
||||
|
||||
// Parse root tags.
|
||||
NMLTagForeach(pt, tag)
|
||||
{
|
||||
if (pt->name == "SelfMask")
|
||||
self_mask = pt->GetInteger();
|
||||
else if (pt->name == "Mask")
|
||||
collision_mask = pt->GetInteger();
|
||||
|
||||
else if (pt->name == "Mode")
|
||||
{
|
||||
String mode(pt->GetString());
|
||||
|
||||
if (mode == "None") physic_mode = Mode_None;
|
||||
else if (mode == "Static") physic_mode = Mode_Static;
|
||||
else if (mode == "Dynamic") physic_mode = Mode_Dynamic;
|
||||
else if (mode == "Kinematic") physic_mode = Mode_Kinematic;
|
||||
else if (mode == "Character") physic_mode = Mode_Character;
|
||||
else if (mode == "Vehicle") physic_mode = Mode_Vehicle;
|
||||
}
|
||||
else if (pt->name == "Shapes")
|
||||
{
|
||||
NMLTagForeach(st, *pt)
|
||||
if (PhysicShape *shape = new PhysicShape)
|
||||
{
|
||||
shape->FromMetaTag(*st);
|
||||
shape_list.Add(shape);
|
||||
}
|
||||
}
|
||||
else if (pt->name == "Wheels")
|
||||
{
|
||||
NMLTagForeach(wt, *pt)
|
||||
if (PhysicWheel *wheel = new PhysicWheel)
|
||||
{
|
||||
wheel->FromMetaTag(*wt);
|
||||
vehicle.wheel_list.Add(wheel);
|
||||
}
|
||||
}
|
||||
else if (pt->name == "Flag")
|
||||
{}
|
||||
|
||||
else if (pt->name == "CharacterRadius")
|
||||
character.radius = pt->GetReal();
|
||||
else if (pt->name == "CharacterHeight")
|
||||
character.height = pt->GetReal();
|
||||
else if (pt->name == "CharacterMaxStep")
|
||||
character.max_step = pt->GetReal();
|
||||
|
||||
else if (pt->name == "LinearDamping_v2")
|
||||
linear_damping = pt->GetReal();
|
||||
else if (pt->name == "AngularDamping_v2")
|
||||
angular_damping = pt->GetReal();
|
||||
#if 1
|
||||
else if (pt->name == "LinearDamping")
|
||||
linear_damping = pt->GetReal();
|
||||
else if (pt->name == "AngularDamping")
|
||||
angular_damping = pt->GetReal();
|
||||
else if (pt->name == "Active")
|
||||
;
|
||||
#endif
|
||||
|
||||
else __LOG_W__ << "Unknown tag '" << pt->name << "' in <PhysicItem>.\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Tag *PhysicItemDesc::AsMetaTag() const
|
||||
{
|
||||
Tag *root = new Tag("PhysicItem");
|
||||
if (!root)
|
||||
__ERR__(__LOG_E__ << "Could not create collision item root tag to serialize.\n", NULL)
|
||||
|
||||
root->AddChild("SelfMask", (int)self_mask);
|
||||
root->AddChild("Mask", (int)collision_mask);
|
||||
root->AddChild("LinearDamping_v2", linear_damping);
|
||||
root->AddChild("AngularDamping_v2", angular_damping);
|
||||
root->AddChild("CharacterRadius", character.radius);
|
||||
root->AddChild("CharacterHeight", character.height);
|
||||
root->AddChild("CharacterMaxStep", character.max_step);
|
||||
|
||||
switch (physic_mode)
|
||||
{
|
||||
default:
|
||||
case Mode_None: root->AddChild("Mode", "None"); break;
|
||||
|
||||
case Mode_Static: root->AddChild("Mode", "Static"); break;
|
||||
case Mode_Dynamic: root->AddChild("Mode", "Dynamic"); break;
|
||||
case Mode_Kinematic: root->AddChild("Mode", "Kinematic"); break;
|
||||
|
||||
case Mode_Character: root->AddChild("Mode", "Character"); break;
|
||||
case Mode_Vehicle: root->AddChild("Mode", "Vehicle"); break;
|
||||
}
|
||||
|
||||
// Dump shapes.
|
||||
if (shape_list.GetCount())
|
||||
if (Tag *st = root->AddChild("Shapes"))
|
||||
ListForeachPtr(PhysicShape *, shape, shape_list)
|
||||
st->AddChild(shape->AsMetaTag());
|
||||
|
||||
// Dump wheels.
|
||||
if (vehicle.wheel_list.GetCount())
|
||||
if (Tag *wt = root->AddChild("Wheels"))
|
||||
ListForeachPtr(PhysicWheel *, wheel, vehicle.wheel_list)
|
||||
wt->AddChild(wheel->AsMetaTag());
|
||||
|
||||
return root;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
100
include/engine/physic/physic_shape.cpp
Normal file
100
include/engine/physic/physic_shape.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "physic/physic_shape.h"
|
||||
#include "math/matrix4.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
GS::Matrix4 PhysicShape::GetMatrix()
|
||||
{ return Matrix4::TransformationMatrix(position, rotation, dimensions); }
|
||||
void PhysicShape::SetMatrix(const GS::Matrix4 &m)
|
||||
{ m.Decompose(&position, &dimensions, &rotation); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool PhysicShape::Set(Type t, const char *p)
|
||||
{
|
||||
Free();
|
||||
|
||||
type = t;
|
||||
path = p;
|
||||
return true;
|
||||
}
|
||||
bool PhysicShape::Set(Type t, const GS::Vector4 &d)
|
||||
{
|
||||
Free();
|
||||
|
||||
type = t;
|
||||
dimensions = d;
|
||||
return true;
|
||||
}
|
||||
bool PhysicShape::Set(float *ph, int w, int h, float r)
|
||||
{
|
||||
Free();
|
||||
|
||||
type = TypeHeightmap;
|
||||
|
||||
// Resample the terrain heightfield to a meter resolution.
|
||||
width = (int)((float)w * r);
|
||||
height = (int)((float)h * r);
|
||||
|
||||
//
|
||||
float i = (float)w / (float)width, j = (float)h / (float)height;
|
||||
|
||||
heightmap.Allocate(width * height);
|
||||
|
||||
if (float *po = heightmap)
|
||||
{
|
||||
float y = 0;
|
||||
for (int v = 0; v < height; ++v)
|
||||
{
|
||||
float x = 0;
|
||||
for (int u = 0; u < width; ++u)
|
||||
{
|
||||
// *po++ = ph[int(h - y - 1) * w + int(x)];
|
||||
*po++ = ph[int(y) * w + int(x)];
|
||||
x += i;
|
||||
}
|
||||
y += j;
|
||||
}
|
||||
}
|
||||
|
||||
resolution = 1.f; // Resampled
|
||||
return true;
|
||||
}
|
||||
void PhysicShape::Free()
|
||||
{
|
||||
type = TypeNone;
|
||||
heightmap.Free();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
PhysicShape::PhysicShape()
|
||||
{
|
||||
type = TypeNone;
|
||||
mass = 0; // Static.
|
||||
|
||||
position.Set();
|
||||
rotation.Set();
|
||||
dimensions.Set(1, 1, 1);
|
||||
scale.Set(1, 1, 1);
|
||||
|
||||
restitution = 0.5;
|
||||
static_friction = 0.5;
|
||||
dynamic_friction = 0.5;
|
||||
|
||||
width = height = 0;
|
||||
resolution = 1;
|
||||
}
|
||||
PhysicShape::~PhysicShape()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
157
include/engine/physic/physic_shape_nml.cpp
Normal file
157
include/engine/physic/physic_shape_nml.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "physic/physic_shape.h"
|
||||
#include "math/matrix3.h"
|
||||
#include "metafile/nml.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::NML;
|
||||
using namespace GS::S3D;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool PhysicShape::FromMetaTag(Tag &tag)
|
||||
{
|
||||
if ((tag.name != "GColShape") && (tag.name != "PhysicShape"))
|
||||
__ERR__(__LOG_E__ << "Could not parse physic shape, incorrect root tag (" << tag.name << ").\n", false)
|
||||
|
||||
type = TypeNone;
|
||||
mass = Units::Kg(1.f);
|
||||
|
||||
// Parse root tags.
|
||||
String _mss("Mass"), _damp("Damping"), _sfr("StaticFriction"), _dfr("DynamicFriction"), _res("Restitution"),
|
||||
_plm("Polymesh"), _msh("Mesh"), _dms("Dimensions"), _rds("Radius"), _pos("Position"), _ori("Orientation"), _rot("Rotation"),
|
||||
_act("Active"), _type("Type"), _aso("AnisotropicFriction"), _vsf("VStaticFriction"), _vdf("VDynamicFriction"),
|
||||
_scl("Scale");
|
||||
|
||||
NMLTagForeach(pt, tag)
|
||||
{
|
||||
if (pt->name == _type)
|
||||
{
|
||||
String _type(pt->GetString());
|
||||
|
||||
if (_type == "Box")
|
||||
type = TypeBox;
|
||||
else if (_type == "Sphere")
|
||||
type = TypeSphere;
|
||||
else if (_type == "Convex")
|
||||
type = TypeConvex;
|
||||
else if (_type == "Cylinder")
|
||||
type = TypeCylinder;
|
||||
else if (_type == "Cone")
|
||||
type = TypeCone;
|
||||
else if (_type == "Capsule")
|
||||
type = TypeCapsule;
|
||||
else if (_type == "Mesh")
|
||||
type = TypeMesh;
|
||||
else if (_type == "Heightmap")
|
||||
type = TypeHeightmap;
|
||||
|
||||
// GCol shapes.
|
||||
else if (_type == "Cuboid")
|
||||
type = TypeBox;
|
||||
else if (_type == "PolyMesh")
|
||||
type = TypeMesh;
|
||||
|
||||
else type = TypeNone;
|
||||
}
|
||||
|
||||
else if (pt->name == _pos)
|
||||
position.FromMetaTag(*pt);
|
||||
else if (pt->name == _rot)
|
||||
rotation.FromMetaTag(*pt);
|
||||
else if (pt->name == _ori)
|
||||
{
|
||||
Matrix3 orientation_matrix;
|
||||
orientation_matrix.FromMetaTag(*pt);
|
||||
rotation = orientation_matrix.AsEuler();
|
||||
}
|
||||
else if (pt->name == _scl)
|
||||
scale.FromMetaTag(*pt);
|
||||
else if (pt->name == _dms)
|
||||
dimensions.FromMetaTag(*pt);
|
||||
else if (pt->name == _rds)
|
||||
dimensions.x = pt->GetReal();
|
||||
|
||||
else if ((pt->name == _plm) || (pt->name == _msh))
|
||||
path = pt->GetString();
|
||||
|
||||
else if (pt->name == _mss)
|
||||
mass = pt->GetReal();
|
||||
|
||||
else if (pt->name == _sfr)
|
||||
static_friction = pt->GetReal();
|
||||
else if (pt->name == _dfr)
|
||||
dynamic_friction = pt->GetReal();
|
||||
else if (pt->name == _res)
|
||||
restitution = pt->GetReal();
|
||||
|
||||
#if 1
|
||||
else if (pt->name == "Active")
|
||||
;
|
||||
#endif
|
||||
|
||||
else __LOG_W__ << "Unknown tag '" << pt->name << "' in <PhysicShape>.\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Tag *PhysicShape::AsMetaTag() const
|
||||
{
|
||||
Tag *root = new Tag("PhysicShape");
|
||||
if (!root)
|
||||
__ERR__(__LOG_E__ << "Could not create collision shape root tag to serialize.\n", NULL)
|
||||
|
||||
if (type != TypeNone)
|
||||
{
|
||||
String _type;
|
||||
switch (type)
|
||||
{
|
||||
case TypeBox: _type = "Box"; break;
|
||||
case TypeSphere: _type = "Sphere"; break;
|
||||
case TypeConvex: _type = "Convex"; break;
|
||||
case TypeCylinder: _type = "Cylinder"; break;
|
||||
case TypeCone: _type = "Cone"; break;
|
||||
case TypeCapsule: _type = "Capsule"; break;
|
||||
case TypeMesh: _type = "Mesh"; break;
|
||||
case TypeHeightmap: _type = "Heightmap"; break;
|
||||
|
||||
default:
|
||||
_type = "None";
|
||||
break;
|
||||
}
|
||||
root->AddChild("Type", _type.c_str());
|
||||
}
|
||||
|
||||
root->AddChild(position.AsMetaTag("Position"));
|
||||
root->AddChild(rotation.AsMetaTag("Rotation"));
|
||||
root->AddChild(scale.AsMetaTag("Scale"));
|
||||
root->AddChild(dimensions.AsMetaTag("Dimensions"));
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case TypeMesh:
|
||||
case TypeConvex:
|
||||
if (!path.IsEmpty())
|
||||
root->AddChild("Mesh", path.c_str());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (mass != Units::Kg(1))
|
||||
root->AddChild("Mass", mass);
|
||||
|
||||
root->AddChild("StaticFriction", static_friction);
|
||||
root->AddChild("DynamicFriction", dynamic_friction);
|
||||
root->AddChild("Restitution", restitution);
|
||||
return root;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
69
include/engine/physic/physic_wheel.cpp
Normal file
69
include/engine/physic/physic_wheel.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "physic/physic_wheel.h"
|
||||
#include "math/matrix4.h"
|
||||
#include "metafile/nml.h"
|
||||
#include "log/log.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
using GS::NML::Tag;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool PhysicWheel::FromMetaTag(Tag &tag)
|
||||
{
|
||||
if (tag.name != "PhysicWheel")
|
||||
__ERR__(__LOG_E__ << "Could not parse physic wheel, incorrect root tag (" << tag.name << ").\n", false)
|
||||
|
||||
// Parse root tags.
|
||||
NMLTagForeach(pt, tag)
|
||||
{
|
||||
if (pt->name == "Friction") friction = pt->GetReal();
|
||||
else if (pt->name == "Radius") radius = pt->GetReal();
|
||||
|
||||
else if (pt->name == "RefMatrix") ref_matrix.FromMetaTag(*pt);
|
||||
|
||||
else if (pt->name == "RestLength") rest_length = pt->GetReal();
|
||||
else if (pt->name == "MaxCompression") max_compression = pt->GetReal();
|
||||
else if (pt->name == "Stiffness") stiffness = pt->GetReal();
|
||||
else if (pt->name == "Damping") damping = pt->GetReal();
|
||||
|
||||
else __LOG_W__ << "Unknown tag '" << pt->name << "' in <PhysicWheel>.\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Tag *PhysicWheel::AsMetaTag() const
|
||||
{
|
||||
Tag *root = new Tag("PhysicWheel");
|
||||
if (!root)
|
||||
__ERR__(__LOG_E__ << "Could not create physic wheel root tag to serialize.\n", NULL)
|
||||
|
||||
root->AddChild("Friction", friction);
|
||||
root->AddChild("Radius", radius);
|
||||
|
||||
root->AddChild(ref_matrix.AsMetaTag("RefMatrix"));
|
||||
|
||||
root->AddChild("RestLength", rest_length);
|
||||
root->AddChild("MaxCompression", max_compression);
|
||||
root->AddChild("Stiffness", stiffness);
|
||||
root->AddChild("Damping", damping);
|
||||
return root;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
PhysicWheel::PhysicWheel()
|
||||
{
|
||||
ref_matrix = Matrix4::IdentityMatrix();
|
||||
|
||||
friction = 50.f;
|
||||
radius = 0.3f;
|
||||
|
||||
rest_length = 1.0f;
|
||||
max_compression = 2.0f;
|
||||
stiffness = 30.f;
|
||||
damping = 0.25f;
|
||||
}
|
||||
19
include/engine/physic/physic_world.cpp
Normal file
19
include/engine/physic/physic_world.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#include "physic/physic_world.h"
|
||||
|
||||
using namespace GS::S3D;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
PhysicWorld::PhysicWorld()
|
||||
{
|
||||
timestep = 1.f / 60.f;
|
||||
gravity.Set(0, -9.8f, 0); // m.s2
|
||||
world_interface = NULL;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user