/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Engine/Components/Colliders/Collider.cs
169 строк
5 KB
EugenyCh7
++ IsValid
26 авг 2025, 22:46
26 авг 2025, 22:46
73c1630
Код
Авторство
О чём код?
using Puppet2D.Engine.Common; using Puppet2D.Engine.Components.RigidBodies; using Puppet2D.Graphics; using Puppet2D.System; using System; namespace Puppet2D.Engine.Components.Colliders { public abstract class Collider : Component { protected const float degreesInRadians = 180f / MathF.PI; internal B2.ShapeId? ShapeId; public BodyShape BodyShape { get; set; } public float Angle { get; set; } public abstract Shape GetShape(); public abstract RectangleShape GetBox(); public abstract MassData ComputeMassData(float density); internal override void Create() { base.Create(); RigidBody?.AddCollider(this); } internal override void Destroy() { base.Destroy(); RigidBody?.RemoveCollider(this); } /// <summary> /// Are contact events enabled. /// </summary> public bool AreContactEventsEnabled { get => B2.ShapeAreContactEventsEnabled(ShapeId.Value); set => B2.ShapeEnableContactEvents(ShapeId.Value, value); } /// <summary> /// Are hit events enabled. /// </summary> public bool AreHitEventsEnabled { get => B2.ShapeAreHitEventsEnabled(ShapeId.Value); set => B2.ShapeEnableHitEvents(ShapeId.Value, value); } /// <summary> /// Are pre-solve events enabled. /// </summary> public bool ArePreSolveEventsEnabled { get => B2.ShapeArePreSolveEventsEnabled(ShapeId.Value); set => B2.ShapeEnablePreSolveEvents(ShapeId.Value, value); } /// <summary> /// Are sensor events enabled. /// </summary> public bool AreSensorEventsEnabled { get => B2.ShapeAreSensorEventsEnabled(ShapeId.Value); set => B2.ShapeEnableSensorEvents(ShapeId.Value, value); } /// <summary> /// The density of a shape, typically in kg/m^2. /// </summary> public float Density { get => B2.ShapeGetDensity(ShapeId.Value); set => B2.ShapeSetDensity(ShapeId.Value, value, BodyShape.UpdateBodyMass); } /// <summary> /// The shape filter. /// </summary> public Filter Filter { get => new Filter(B2.ShapeGetFilter(ShapeId.Value)); set => B2.ShapeSetFilter(ShapeId.Value, value.Cast()); } /// <summary> /// The friction of a shape. /// </summary> public float Friction { get => B2.ShapeGetFriction(ShapeId.Value); set => B2.ShapeSetFriction(ShapeId.Value, value); } /// <summary> /// The shape restitution. /// </summary> public float Restitution { get => B2.ShapeGetRestitution(ShapeId.Value); set => B2.ShapeSetRestitution(ShapeId.Value, value); } /// <summary> /// Returns true If the shape is a sensor. /// </summary> public bool IsSensor { get => B2.ShapeIsSensor(ShapeId.Value); } /// <summary> /// The current world AABB. /// </summary> public AABB AABB { get => B2.ShapeGetAABB(ShapeId.Value); } /// <summary> /// The current rigid body associated with the collider. /// </summary> public RigidBody Body { get => World.GetRigidBody(ShapeId.Value); } /// <summary> /// Get the closest point on a shape to a target point. /// Target and result are in world space. /// </summary> public Vector2 GetClosestPoint(Vector2 target) { return B2.ShapeGetClosestPoint(ShapeId.Value, target); } /// <summary> /// The mass data for a shape. /// </summary> public MassData MassData { get => new MassData(B2.ShapeGetMassData(ShapeId.Value)); } /// <summary> /// Shape identifier validation. Provides validation for up to 64K allocations. /// </summary> public bool IsValid { get => B2.ShapeIsValid(ShapeId.Value); } /// <summary> /// Ray cast a shape directly. /// </summary> public CastOutput RayCast(RayCastInput rayCastInput) { unsafe { B2.RayCastInput input = rayCastInput.Cast(); return new CastOutput(B2.ShapeRayCast(ShapeId.Value, &input)); } } } }