public static bool CheckIntersection(Ray ray, PointCollider sphere, Translation sphereCenter)
    {
        float3 center = sphereCenter.Value + sphere.centerOffset;
        float3 dir    = center - (float3)ray.origin;

        float dirSqLen   = dir.x * dir.x + dir.y * dir.y + dir.z * dir.z;
        float pointSqRad = sphere.radius * sphere.radius;

        float distanceAlongRay;

        if (dirSqLen < pointSqRad)
        {
            //point radius overlap with ray origin
            return(true);
        }

        distanceAlongRay = math.dot(ray.direction, dir);

        if (distanceAlongRay < 0)
        {
            return(false);
        }

        float dist = pointSqRad + distanceAlongRay * distanceAlongRay - dirSqLen;

        return(!(dist < 0));
    }
Ejemplo n.º 2
0
 public static bool BoxWithPoint(BoxCollider collider, PointCollider other)
 {
     return(!(
                (collider.Right <= other.Left) ||
                (collider.Bottom <= other.Top) ||
                (collider.Left >= other.Right) ||
                (collider.Top >= other.Bottom)
                ));
 }
Ejemplo n.º 3
0
 public Crosshair()
 {
     pointCollider = new PointCollider(0, 0, ColliderTags.Crosshair);
     AddCollider(pointCollider);
     image.Scale = 0.1f;
     image.CenterOrigin();
     Layer = -1000;
     AddGraphic(image);
     MainScene.Instance.Add(this);
 }
Ejemplo n.º 4
0
        public static BlobAssetReference <QuadTree> CreateBlobAssetReference()
        {
            using (var builder = new BlobBuilder(Allocator.Temp)) {
                ref var rootQuadTree = ref builder.ConstructRoot <QuadTree>();

                var colliders = builder.Allocate(ref rootQuadTree.Colliders, 2);
                LineCollider.Create(builder, ref colliders[0], new float2(1f, 20f), new float2(3f, 4f), 5f, 6f);
                PointCollider.Create(builder, ref colliders[1], new float3(7f, 8f, 9f));

                return(builder.CreateBlobAssetReference <QuadTree>(Allocator.Persistent));
            }
Ejemplo n.º 5
0
        public Shuriken() : base()
        {
            m_attack          = new AttackComponent(1.0f, 0.1f);
            m_sprite          = new Sprite(Globals.TheGame, TextureLibrary.GetSpriteSheet("atk_shuriken", 1, 5), m_transform);
            m_sprite.Origin   = new Vector2(0.5f, 0.0f);
            m_transform.Scale = new Vector2(3.0f, 3.0f);
            m_animation       = new SpriteSheetAnimation(m_sprite, 0, 4, 0.1f, 1);
            m_pointCollider   = new PointCollider(m_attack, Transform);

            World.UL_Global.Add(this, 0);
            World.DL_Foreground.Add(this, 0);
        }
Ejemplo n.º 6
0
 public override bool VSPoint(PointCollider col) => CollisionSystem.BoxVSPoint(Min, Max, col.Center);
Ejemplo n.º 7
0
 public static bool PointWithPoint(PointCollider collider, PointCollider other)
 {
     return(Math.Abs(collider.Left - other.Left) < 1f ||
            Math.Abs(collider.Top - other.Top) < 1f);
 }
Ejemplo n.º 8
0
 public static bool CircleWithPoint(CircleCollider collider, PointCollider other)
 {
     return(FeMath.Distance(collider.Position, other.Position) <= collider.Radius);
 }
Ejemplo n.º 9
0
 internal abstract bool CollidesWith(PointCollider other);
 public override bool VSPoint(PointCollider col) => CollisionSystem.PointVSCircle(Center, col.Center, RadiusSqrd);
Ejemplo n.º 11
0
 public override bool VSPoint(PointCollider col)
 {
     return(col.Center == Center);
 }
Ejemplo n.º 12
0
 public abstract bool VSPoint(PointCollider col);