/* ----------------------------------------------------------------------------- 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 .\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; }