00001
00007 #include "dynamics2d_cylinder_model.h"
00008 #include "dynamics2d_gripping.h"
00009 #include "dynamics2d_engine.h"
00010
00011 namespace argos {
00012
00013
00014
00015
00016 CDynamics2DCylinderModel::CDynamics2DCylinderModel(CDynamics2DEngine& c_engine,
00017 CCylinderEntity& c_entity) :
00018 CDynamics2DStretchableObjectModel(c_engine, c_entity) {
00019
00020 Real fRadius = c_entity.GetRadius();
00021
00022 const CVector3& cPosition = GetEmbodiedEntity().GetOriginAnchor().Position;
00023 CRadians cXAngle, cYAngle, cZAngle;
00024 GetEmbodiedEntity().GetOriginAnchor().Orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
00025
00026
00027
00028 cpBody* ptBody;
00029 if(GetEmbodiedEntity().IsMovable()) {
00030
00031 SetMass(c_entity.GetMass());
00032
00033 ptBody = cpSpaceAddBody(GetDynamics2DEngine().GetPhysicsSpace(),
00034 cpBodyNew(GetMass(),
00035 cpMomentForCircle(GetMass(),
00036 0,
00037 fRadius + fRadius,
00038 cpvzero)));
00039 ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
00040 cpBodySetAngle(ptBody, cZAngle.GetValue());
00041
00042 cpShape* ptShape = cpSpaceAddShape(GetDynamics2DEngine().GetPhysicsSpace(),
00043 cpCircleShapeNew(ptBody, fRadius, cpvzero));
00044 ptShape->e = 0.0;
00045 ptShape->u = 0.7;
00046
00047 SetGrippable(new CDynamics2DGrippable(GetEmbodiedEntity(),
00048 ptShape));
00049
00050 SetBody(ptBody, c_entity.GetHeight());
00051
00052 SetLinearFriction(0.0f, 1.49f);
00053 SetAngularFriction(0.0f, 1.49f);
00054 }
00055 else {
00056
00057
00058 ptBody = cpBodyNewStatic();
00059 ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
00060 cpBodySetAngle(ptBody, cZAngle.GetValue());
00061
00062 cpShape* ptShape = cpSpaceAddShape(
00063 GetDynamics2DEngine().GetPhysicsSpace(),
00064 cpCircleShapeNew(ptBody,
00065 fRadius,
00066 cpvzero));
00067 ptShape->e = 0.0;
00068 ptShape->u = 0.1;
00069
00070 ptShape->collision_type = CDynamics2DEngine::SHAPE_NORMAL;
00071
00072 SetBody(ptBody, c_entity.GetHeight());
00073 }
00074 }
00075
00076
00077
00078
00079 REGISTER_STANDARD_DYNAMICS2D_OPERATIONS_ON_ENTITY(CCylinderEntity, CDynamics2DCylinderModel);
00080
00081
00082
00083
00084 }