public void Init(ColliderInfo info, ColliderType colliderType) { if (info.Entity == Entity.Null) { throw new InvalidOperationException("Entity of " + info.ItemType + " " + colliderType + " not set!"); } Type = colliderType; ItemType = info.ItemType; Id = info.Id; Entity = info.Entity; Material = info.Material; Threshold = info.HitThreshold; FireEvents = info.FireEvents; IsEnabled = info.IsEnabled; }
public Line3DCollider(float3 v1, float3 v2, ColliderInfo info) : this() { _header.Init(info, ColliderType.Line3D); var vLine = math.normalize(v2 - v1); // Axis of rotation to make 3D cylinder a cylinder along the z-axis var transAxis = new float3(vLine.y, -vLine.x, 0.0f); var l = math.lengthsq(transAxis); // line already points in z axis? if (l <= 1e-6f) { // choose arbitrary rotation vector transAxis.Set(1, 0f, 0f); } else { transAxis /= math.sqrt(l); } // Angle to rotate the line into the z-axis var dot = vLine.z; _matrix = new float3x3(); _matrix.RotationAroundAxis(transAxis, -math.sqrt(1 - dot * dot), dot); var trans1 = math.mul(_matrix, v1); var trans2Z = math.mul(_matrix, v2).z; // set up HitLineZ parameters _xy.x = trans1.x; _xy.y = trans1.y; _zLow = math.min(trans1.z, trans2Z); _zHigh = math.max(trans1.z, trans2Z); Bounds = new ColliderBounds(_header.Entity, _header.Id, new Aabb( math.min(v1.x, v2.x), math.max(v1.x, v2.x), math.min(v1.y, v2.y), math.max(v1.y, v2.y), math.min(v1.z, v2.z), math.max(v1.z, v2.z) )); }
internal (PlaneCollider, PlaneCollider) CreateColliders() { var info = new ColliderInfo { ItemType = ItemType.Table, Entity = Player.PlayfieldEntity, FireEvents = false, IsEnabled = true, Material = new PhysicsMaterialData { Elasticity = ColliderComponent.Elasticity, ElasticityFalloff = ColliderComponent.ElasticityFalloff, Friction = ColliderComponent.Friction, ScatterAngleRad = ColliderComponent.Scatter }, HitThreshold = 0 }; return( new PlaneCollider(new float3(0, 0, 1), MainComponent.TableHeight, info), new PlaneCollider(new float3(0, 0, -1), MainComponent.GlassHeight, info) ); }
public SpinnerCollider(SpinnerComponent component, float height, ColliderInfo info) : this() { _header.Init(info, ColliderType.Spinner); var halfLength = component.Length * 0.5f; var radAngle = math.radians(component.Rotation); var sn = math.sin(radAngle); var cs = math.cos(radAngle); var v1 = new float2( component.Position.x - cs * (halfLength + PhysicsConstants.PhysSkin), // through the edge of the component.Position.y - sn * (halfLength + PhysicsConstants.PhysSkin) // spinner ); var v2 = new float2( component.Position.x + cs * (halfLength + PhysicsConstants.PhysSkin), // oversize by the ball radius component.Position.y + sn * (halfLength + PhysicsConstants.PhysSkin) // this will prevent clipping ); LineSeg0 = new LineCollider(v1, v2, height, height + 2.0f * PhysicsConstants.PhysSkin, info); LineSeg1 = new LineCollider(v2, v1, height, height + 2.0f * PhysicsConstants.PhysSkin, info); Bounds = LineSeg0.Bounds; }
public PlungerCollider(PlungerComponent comp, PlungerColliderComponent collComp, ColliderInfo info) : this() { _header.Init(info, ColliderType.Plunger); var zHeight = comp.PositionZ; var x = comp.Position.x - comp.Width; var y = comp.Position.y + comp.Height; var x2 = comp.Position.x + comp.Width; // static LineSegBase = new LineCollider(new float2(x, y), new float2(x2, y), zHeight, zHeight + Plunger.PlungerHeight, info); JointBase0 = new LineZCollider(new float2(x, y), zHeight, zHeight + Plunger.PlungerHeight, info); JointBase1 = new LineZCollider(new float2(x2, y), zHeight, zHeight + Plunger.PlungerHeight, info); var frameEnd = comp.Position.y - collComp.Stroke; Bounds = new ColliderBounds(_header.Entity, _header.Id, new Aabb( x - 0.1f, x2 + 0.1f, frameEnd - 0.1f, y + 0.1f, zHeight, zHeight + Plunger.PlungerHeight )); }
public PointCollider(float3 p, ColliderInfo info) : this() { _header.Init(info, ColliderType.Point); P = p; }
public LineSlingshotCollider(float force, float2 v1, float2 v2, float zLow, float zHigh, ColliderInfo info) : this() { _header.Init(info, ColliderType.LineSlingShot); _force = force; V1 = v1; V2 = v2; ZLow = zLow; ZHigh = zHigh; CalcNormal(); }
public FlipperCollider(CircleCollider hitCircleBase, float flipperRadius, float startRadius, float endRadius, float startAngle, float endAngle, ColliderInfo info) : this() { var bounds = hitCircleBase.Bounds; _header.Init(info, ColliderType.Flipper); _hitCircleBase = hitCircleBase; _zLow = bounds.Aabb.ZLow; _zHigh = bounds.Aabb.ZHigh; // compute bounds. we look at the flipper angles to compute the smallest possible bounds. var c = _hitCircleBase.Center; var r2 = endRadius + 0.1f; var r3 = startRadius + 0.1f; var a0 = ClampDegrees(startAngle); var a1 = ClampDegrees(endAngle); // start with no bounds var aabb = new Aabb(c.x, c.x, c.y, c.y, _zLow, _zHigh); // extend with start and end position aabb = ExtendBoundsAtPosition(aabb, c, flipperRadius, r2, a0); aabb = ExtendBoundsAtPosition(aabb, c, flipperRadius, r2, a1); // extend with extremes (-90°, 0°, 90° and 180°) aabb = ExtendBoundsAtExtreme(aabb, c, flipperRadius, r2, r3, a0, a1, -90f); aabb = ExtendBoundsAtExtreme(aabb, c, flipperRadius, r2, r3, a0, a1, 0f); aabb = ExtendBoundsAtExtreme(aabb, c, flipperRadius, r2, r3, a0, a1, 90f); aabb = ExtendBoundsAtExtreme(aabb, c, flipperRadius, r2, r3, a0, a1, 180f); Bounds = new ColliderBounds(_header.Entity, _header.Id, aabb); }