/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Engine/Components/Colliders/BodyShape.cs
143 строки
5 KB
EugenyCh7
- Puppet2D.Engine.Collision
24 авг 2025, 18:34
24 авг 2025, 18:34
d1742be
Код
Авторство
О чём код?
using Puppet2D.Engine.Common; using System; namespace Puppet2D.Engine.Components.Colliders { /// <summary> /// Used to create a body shape. /// </summary> public class BodyShape : ICloneable<BodyShape> { private int internalValue; /// <summary> /// The density, usually in kg/m^2. /// This is not part of the surface material because this is for the interior, /// which may have other considerations, such as being hollow. /// For example a wood barrel may be hollow or full of water. /// </summary> public float Density { get; set; } /// <summary> /// Collision filtering data. /// </summary> public Filter Filter { get; set; } /// <summary> /// A sensor shape generates overlap events but never generates a collision response. /// Sensors do not have continuous collision. /// Instead, use a ray or shape cast for those scenarios. /// Sensors still contribute to the body mass if they have non-zero density. /// Note: /// Sensor events are disabled by default. /// </summary> public bool IsSensor { get; set; } /// <summary> /// Enable sensor events for this shape. /// This applies to sensors and non-sensors. /// False by default, even for sensors. /// </summary> public bool EnableSensorEvents { get; set; } /// <summary> /// Enable contact events for this shape. /// Only applies to kinematic and dynamic bodies. /// Ignored for sensors. False by default. /// </summary> public bool EnableContactEvents { get; set; } /// <summary> /// Enable pre-solve contact events for this shape. /// Only applies to dynamic bodies. /// These are expensive and must be carefully handled due to threading. /// Ignored for sensors. /// </summary> public bool EnablePreSolveEvents { get; set; } /// <summary> /// Enable hit events for this shape. /// Only applies to kinematic and dynamic bodies. /// Ignored for sensors. False by default. /// </summary> public bool EnableHitEvents { get; set; } /// <summary> /// When shapes are created they will scan the environment for collision the next time step. /// This can significantly slow down static body creation when there are many static shapes. /// This is flag is ignored for dynamic and kinematic shapes which always invoke contact creation. /// </summary> public bool InvokeContactCreation { get; set; } /// <summary> /// The surface material for this shape. /// </summary> public SurfaceMaterial Material { get; set; } /// <summary> /// Should the body update the mass properties when this shape is created. Default is true. /// </summary> public bool UpdateBodyMass { get; set; } public BodyShape() : this(B2.DefaultShapeDef()) { } internal BodyShape(B2.ShapeDef shapeDef) { Density = shapeDef.density; Filter = new Filter(shapeDef.filter); IsSensor = shapeDef.isSensor; EnableSensorEvents = shapeDef.enableSensorEvents; EnableContactEvents = shapeDef.enableContactEvents; EnablePreSolveEvents = shapeDef.enablePreSolveEvents; EnableHitEvents = shapeDef.enableHitEvents; InvokeContactCreation = shapeDef.invokeContactCreation; Material = new SurfaceMaterial(shapeDef.material); UpdateBodyMass = shapeDef.updateBodyMass; internalValue = shapeDef.internalValue; } internal B2.ShapeDef Cast() { return new B2.ShapeDef { density = Density, enableContactEvents = EnableContactEvents, enablePreSolveEvents = EnablePreSolveEvents, enableSensorEvents = EnableSensorEvents, enableHitEvents = EnableHitEvents, filter = Filter.Cast(), isSensor = IsSensor, invokeContactCreation = InvokeContactCreation, material = Material.Cast(), updateBodyMass = UpdateBodyMass, internalValue = internalValue }; } public BodyShape Clone() { return new BodyShape { Density = Density, Filter = Filter, IsSensor = IsSensor, EnableSensorEvents = EnableSensorEvents, EnableContactEvents = EnableContactEvents, EnablePreSolveEvents = EnablePreSolveEvents, EnableHitEvents = EnableHitEvents, InvokeContactCreation = InvokeContactCreation, Material = Material.Clone(), UpdateBodyMass = UpdateBodyMass, internalValue = internalValue }; } object ICloneable.Clone() { return Clone(); } } }