State::State(double mass, const Vector2D& gravMod, const Vector2D& position, const Vector2D& velocity, double restitution, double static_friction, double kinetic_friction) : _mass(mass), _gravMod(gravMod), _position(position), _velocity(velocity), _acceleration(0.0, 0.0), _forces(), _impulses(), _active(true), _mat(restitution, static_friction, kinetic_friction), _bounding_rectangle(nullptr), _collision_shape(nullptr), _density(), _damper(DEFAULT_DAMPER_VALUE) { SetBoundingRectangle(_bounding_rectangle); SetCollisionShape(_collision_shape); _density = CalculateDensity(); }
State::State(const State& other) : _mass(other._mass), _gravMod(other._gravMod), _position(other._position), _velocity(other._velocity), _acceleration(other._acceleration), _forces(other._forces), _impulses(other._impulses), _active(other._active), _mat(other._mat), _bounding_rectangle(nullptr), _collision_shape(nullptr), _density(), _damper(DEFAULT_DAMPER_VALUE) { SetBoundingRectangle(other._bounding_rectangle); SetCollisionShape(other._collision_shape); _density = CalculateDensity(); }
/* ************************* Parses and XML collision file Uses Tinyxml ************************* */ bool CollisionParser::ParseCollision (list <BOUNDING_COLLISION*> *pBList, const char *pFile) { std::string f0=pFile; std::string f=stx_convertpath(f0).c_str(); TiXmlDocument *mXmlDoc = new TiXmlDocument(f.c_str()); // Fatal error, cannot load if (!mXmlDoc->LoadFile()) return 0; // Document root TiXmlElement *mXBoundingAreas = 0; mXBoundingAreas = mXmlDoc->FirstChildElement("bounding_areas"); if (!mXBoundingAreas) { Debug->Header ("Invalid name for document root, should be <bounding_areas>", 2); mXmlDoc->Clear(); delete mXmlDoc; return 0; } // ----- Triangle ----- TiXmlElement *mXTriangle = 0; mXTriangle = mXBoundingAreas->FirstChildElement("triangle"); while (mXTriangle) { if (mXTriangle->Attribute("id") && mXTriangle->Attribute("ax") && mXTriangle->Attribute("ay") && mXTriangle->Attribute("bx") && mXTriangle->Attribute("by") && mXTriangle->Attribute("cx") && mXTriangle->Attribute("cy")) { std::string mId(mXTriangle->Attribute("id")); //LOG_PRINT("SetBoundingTriangle mId.c_str()=%s\n",mId.c_str()) SetBoundingTriangle (pBList, (char*)mId.c_str(), atoi (mXTriangle->Attribute("ax")), atoi (mXTriangle->Attribute("ay")), atoi (mXTriangle->Attribute("bx")), atoi (mXTriangle->Attribute("by")), atoi (mXTriangle->Attribute("cx")), atoi (mXTriangle->Attribute("cy"))); } else { Debug->Header ("The triangle doesn't have all the attributes", 2); mXmlDoc->Clear(); delete mXmlDoc; return 0; } // Move to the next element mXTriangle = mXTriangle->NextSiblingElement("triangle"); } // ----- Circle ----- TiXmlElement *mXCircle = 0; mXCircle = mXBoundingAreas->FirstChildElement("circle"); while (mXCircle) { if (mXCircle->Attribute("id") && mXCircle->Attribute("x") && mXCircle->Attribute("y") && mXCircle->Attribute("radius")) { std::string mId(mXCircle->Attribute("id")); //LOG_PRINT("SetBoundingCircle mId.c_str()=%s\n",mId.c_str()) SetBoundingCircle (pBList, (char*)mId.c_str(), atoi (mXCircle->Attribute("x")), atoi (mXCircle->Attribute("y")), atoi (mXCircle->Attribute("radius"))); } else { Debug->Header ("The circle doesn't have all the attributes", 2); mXmlDoc->Clear(); delete mXmlDoc; return 0; } // Move to the next element mXCircle = mXCircle->NextSiblingElement("circle"); } // ----- Rectangle ----- TiXmlElement *mXRectangle= 0; mXRectangle = mXBoundingAreas->FirstChildElement("rectangle"); //LOG_FNLN while (mXRectangle) { if (mXRectangle->Attribute("id") && mXRectangle->Attribute("x") && mXRectangle->Attribute("y") && mXRectangle->Attribute("width") && mXRectangle->Attribute("height")) { std::string mId(mXRectangle->Attribute("id")); //LOG_PRINT("SetBoundingRectangle mId.c_str()=%s\n",mId.c_str()) SetBoundingRectangle (pBList, (char*)mId.c_str(), atoi (mXRectangle->Attribute("x")), atoi (mXRectangle->Attribute("y")), atoi (mXRectangle->Attribute("width")), atoi (mXRectangle->Attribute("height"))); } else { Debug->Header ("The rectangle doesn't have all the attributes", 2); mXmlDoc->Clear(); delete mXmlDoc; return 0; } // Move to the next element mXRectangle = mXRectangle->NextSiblingElement("rectangle"); } // Delete our allocated document and return success ) mXmlDoc->Clear(); delete mXmlDoc; return 1; }