public override void EndAction() { base.EndAction(); List<Vector2> vertices = this.GetVertices(this.actionShape).ToList(); vertices.RemoveAt(this.currentVertex); if (vertices.Count < 3 || this.currentVertex < 2) { this.Environment.SelectShapes(null); this.Environment.ActiveBody.RemoveShape(this.actionShape); } else { this.SetVertices(this.actionShape, vertices.ToArray()); // Remove the shape and re-add it properly using an UndoRedoAction. // Now that we're sure the shape is valid, we want its creation to // show up in the UndoRedo stack. this.Environment.ActiveBody.RemoveShape(this.actionShape); UndoRedoManager.Do(new CreateRigidBodyShapeAction(this.Environment.ActiveBody, this.actionShape)); } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.Environment.ActiveBody), ReflectionInfo.Property_RigidBody_Shapes); this.actionShape = null; }
public RayCastData(ShapeInfo shape, Vector2 pos, Vector2 normal, float fraction) { this.shape = shape; this.pos = pos; this.normal = normal; this.fraction = fraction; }
protected override void OnCopyTo(ShapeInfo target) { base.OnCopyTo(target); CircleShapeInfo c = target as CircleShapeInfo; c.radius = this.radius; c.position = this.position; }
public CollisionFilterData(GameObject myObj, GameObject otherObj, ShapeInfo myShape, ShapeInfo otherShape) { this.myObject = myObj; this.otherObject = otherObj; this.myShape = myShape; this.otherShape = otherShape; }
protected override void OnCopyTo(ShapeInfo target) { base.OnCopyTo(target); CircleShapeInfo c = target as CircleShapeInfo; c.radius = this.radius; c.position = this.position; }
/// <summary> /// Copies this ShapeInfos data to another one. It is assumed that both are of the same type. /// </summary> /// <param name="target"></param> protected virtual void OnCopyTo(ShapeInfo target) { // Don't copy the parent! target.density = this.density; target.sensor = this.sensor; target.friction = this.friction; target.restitution = this.restitution; }
public static RigidBodyEditorSelShape Create(ShapeInfo shape) { if (shape is CircleShapeInfo) return new RigidBodyEditorSelCircleShape(shape as CircleShapeInfo); else if (shape is PolyShapeInfo ) return new RigidBodyEditorSelPolyShape (shape as PolyShapeInfo ); else if (shape is ChainShapeInfo ) return new RigidBodyEditorSelChainShape (shape as ChainShapeInfo ); else if (shape is LoopShapeInfo ) return new RigidBodyEditorSelLoopShape (shape as LoopShapeInfo ); else return null; }
public override void BeginAction() { base.BeginAction(); Vector2[] initialVertices = this.GetInitialVertices(this.Environment.ActiveBodyPos); this.currentVertex = 1; this.actionShape = this.CreateShapeInfo(initialVertices); this.initialVertexCount = initialVertices.Length; // Add the shape to the body. We're not doing an actual UndoRedoAction // just yet, because we don't want a potentially invalid under-construction // polygon to show up in the UndoRedo stack. We'll do a proper UndoRedoAction // when finishing up the shape. this.Environment.ActiveBody.AddShape(this.actionShape); DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.Environment.ActiveBody), ReflectionInfo.Property_RigidBody_Shapes); this.Environment.SelectShapes(new ShapeInfo[] { this.actionShape }); }
public void OnInit(Component.InitContext context) { if(context == InitContext.Activate) { float bottom = 0; RigidBody body = (RigidBody)GameObj.GetComponent(typeof(RigidBody)); if(body.Shapes != null) { foreach (ShapeInfo bodyShape in body.Shapes) { if (bodyShape.AABB.BottomY > bottom) { bottom = bodyShape.AABB.BottomY; } } } groundDetecion = new CircleShapeInfo(1, new Vector2(0, bottom + 1.5f), 0); groundDetecion.IsSensor = true; groundDetecion.Friction = 0f; groundDetecion.Restitution = 0f; body.AddShape(groundDetecion); } }
/// <summary> /// Performs a global physical AABB query and returns the <see cref="RigidBody">bodies</see> that /// might be roughly contained or intersected by the specified region. /// </summary> /// <param name="worldCoord"></param> /// <param name="size"></param> /// <param name="queriedBodies"> /// A list that will be filled with all bodies that were found. /// The list will not be cleared before adding items. /// </param> /// <returns>Returns whether any new body was found.</returns> public bool QueryRect(Vector2 worldCoord, Vector2 size, List <RigidBody> queriedBodies) { Vector2 fsWorldCoord = PhysicsUnit.LengthToPhysical * worldCoord; FarseerPhysics.Collision.AABB fsWorldAABB = new FarseerPhysics.Collision.AABB(fsWorldCoord, PhysicsUnit.LengthToPhysical * (worldCoord + size)); int oldResultCount = queriedBodies.Count; this.native.QueryAABB(fixture => { ShapeInfo shape = fixture.UserData as ShapeInfo; if (shape != null && shape.Parent != null && shape.Parent.Active) { if (!queriedBodies.Contains(shape.Parent)) { queriedBodies.Add(shape.Parent); } } return(true); }, ref fsWorldAABB); return(queriedBodies.Count > oldResultCount); }
public void CopyTo(ShapeInfo other) { Cloning.CloneProvider.DeepCopyTo(this, other); }
private int GetSpikeIndex(ShapeInfo spikeShape) { RigidBody body = this.GameObj.GetComponent<RigidBody>(); if (body == null) return -1; int i = 0; foreach (ShapeInfo shape in body.Shapes.Skip(1)) { if (spikeShape == shape) return i; i++; } return -1; }
void Cloning.ICloneable.CopyDataTo(object targetObj, Cloning.CloneProvider provider) { ShapeInfo targetShape = targetObj as ShapeInfo; this.OnCopyTo(targetShape); }
protected abstract void SetVertices(ShapeInfo shape, Vector2[] vertices);
protected abstract Vector2[] GetVertices(ShapeInfo shape);
protected override Vector2[] GetVertices(ShapeInfo shape) { return (shape as ChainShapeInfo).Vertices; }
public RigidBodyCollisionEventArgs(GameObject obj, CollisionData data, ShapeInfo shapeA, ShapeInfo shapeB) : base(obj, data) { this.colShapeA = shapeA; this.colShapeB = shapeB; }
protected SelShape(ShapeInfo shape) { this.shape = shape; }
/// <summary> /// Removes an existing shape from the body. /// </summary> /// <param name="shape"></param> public void RemoveShape(ShapeInfo shape) { if (shape == null) throw new ArgumentNullException("shape"); if (shape.Parent != this) return; if (this.shapes == null || !this.shapes.Contains(shape)) return; this.shapes.Remove(shape); shape.Parent = null; if (this.body != null) shape.DestroyFixture(this.body, false); }
protected RigidBodyEditorSelShape(ShapeInfo shape) { this.shape = shape; }
public RigidBodyCollisionEventArgs(GameObject obj, CollisionData data, ShapeInfo shapeA, ShapeInfo shapeB) : base(obj, data) { this.colShapeA = shapeA; this.colShapeB = shapeB; }
private void DrawShapeArea(Canvas canvas, Transform transform, ShapeInfo shape) { canvas.PushState(); if (shape is CircleShapeInfo) this.DrawShapeArea(canvas, transform, shape as CircleShapeInfo); else if (shape is PolyShapeInfo) this.DrawShapeArea(canvas, transform, (shape as PolyShapeInfo).Vertices); else if (shape is LoopShapeInfo && this.fillHollowShapes) this.DrawShapeArea(canvas, transform, (shape as LoopShapeInfo).Vertices); else if (shape is ChainShapeInfo && this.fillHollowShapes) this.DrawShapeArea(canvas, transform, (shape as ChainShapeInfo).Vertices); canvas.PopState(); }
protected override void SetVertices(ShapeInfo shape, Vector2[] vertices) { (shape as ChainShapeInfo).Vertices = vertices; }
protected override void OnCopyTo(ShapeInfo target) { base.OnCopyTo(target); PolyShapeInfo c = target as PolyShapeInfo; c.vertices = this.vertices != null ? (Vector2[])this.vertices.Clone() : null; }
void ICloneExplicit.CopyDataTo(object targetObj, CloneProvider provider) { ShapeInfo targetShape = targetObj as ShapeInfo; this.OnCopyTo(targetShape); }
/// <summary> /// Copies this ShapeInfos data to another one. It is assumed that both are of the same type. /// </summary> /// <param name="target"></param> protected virtual void OnCopyTo(ShapeInfo target) { // Don't copy the parent! target.density = this.density; target.sensor = this.sensor; target.friction = this.friction; target.restitution = this.restitution; }
/// <summary> /// Adds a new shape to the body. /// </summary> /// <param name="shape"></param> public void AddShape(ShapeInfo shape) { if (shape == null) throw new ArgumentNullException("shape"); if (this.shapes != null && this.shapes.Contains(shape)) return; if (shape.Parent != null && shape.Parent != this) shape.Parent.RemoveShape(shape); if (this.shapes == null) this.shapes = new List<ShapeInfo>(); this.shapes.Add(shape); shape.Parent = this; this.FlagBodyShape(); }
public void CopyTo(ShapeInfo other) { Cloning.CloneProvider.DeepCopyTo(this, other); }
public RigidBodyEditorSelPolyLikeShape(ShapeInfo shape) : base(shape) { this.UpdateShapeStats(); }
public CollisionFilterData(GameObject myObj, GameObject otherObj, ShapeInfo myShape, ShapeInfo otherShape) { this.myObject = myObj; this.otherObject = otherObj; this.myShape = myShape; this.otherShape = otherShape; }
public static SelShape Create(ShapeInfo shape) { if (shape is CircleShapeInfo) return new SelCircleShape(shape as CircleShapeInfo); else if (shape is PolyShapeInfo) return new SelPolyShape(shape as PolyShapeInfo); // else if (shape is EdgeShapeInfo) return new SelEdgeShape(shape as EdgeShapeInfo); else if (shape is LoopShapeInfo) return new SelLoopShape(shape as LoopShapeInfo); else return null; }
private void DrawShapeOutline(Canvas canvas, Transform transform, ShapeInfo shape) { canvas.PushState(); if (shape is CircleShapeInfo) this.DrawShapeOutline(canvas, transform, shape as CircleShapeInfo); else if (shape is PolyShapeInfo) this.DrawShapeOutline(canvas, transform, shape as PolyShapeInfo); else if (shape is LoopShapeInfo) this.DrawShapeOutline(canvas, transform, shape as LoopShapeInfo); canvas.PopState(); }