protected override void Reset() { if (!IsRegistered) { return; } if (vertexes.Count < 3) { return; } if (B2Body != null) { World.B2World.DestroyBody(B2Body); } b2BodyDef = new BodyDef(); b2BodyDef.Angle = Angle / 180.0f * 3.14f; b2BodyDef.Position = Position.ToB2Vector(); b2PolygonDefs = DivideToTriangles(vertexes.Select(v => v - CenterPosition).ToList()); B2Body = World.B2World.CreateBody(b2BodyDef); foreach (var item in b2PolygonDefs) { B2Body.CreateFixture(item); } B2Body.SetMassFromShapes(); }
/// <summary> /// 初期化 /// </summary> /// <param name="world">登録するワールド</param> public PhysicsPolygonColliderNode(World world) : base(world) { b2PolygonDefs = new List <PolygonDef>(); vertexes = new List <Vector2F>(); B2Body = World.B2World.CreateBody(b2BodyDef); foreach (var item in b2PolygonDefs) { B2Body.CreateFixture(item); } }
/// <summary> /// 初期化 /// </summary> /// <param name="shapeType">物理形状タイプ</param> /// <param name="world">登録するワールド</param> public PhysicsTriangleColliderNode(World world) : base(world) { b2PolygonDef = new PolygonDef(); vertexes = new List <Vector2F>(); vertexes.Add(new Vector2F(0, -1)); vertexes.Add(new Vector2F(1, 0)); vertexes.Add(new Vector2F(0, 1)); b2PolygonDef.Vertices = vertexes.Select(v => v.ToB2Vector()).ToArray(); b2PolygonDef.VertexCount = 3; B2Body = World.B2World.CreateBody(b2BodyDef); B2Body.CreateFixture(b2PolygonDef); }