Пример #1
0
        public void adjust_offset(AFrame offset, double quantum)
        {
            if (PhysicsObj == null || TargetID == 0 || !Initialized)
            {
                return;
            }

            var target         = PhysicsObj.GetObjectA(TargetID);
            var targetPosition = target == null ? TargetPosition : target.Position;

            offset.Origin   = PhysicsObj.Position.GetOffset(targetPosition);
            offset.Origin   = PhysicsObj.Position.GlobalToLocalVec(offset.Origin);
            offset.Origin.Z = 0.0f;

            var radius = PhysicsObj.GetRadius();
            var dist   = Position.CylinderDistanceNoZ(radius, PhysicsObj.Position, TargetRadius, targetPosition) - StickyRadius;

            if (Vec.NormalizeCheckSmall(ref offset.Origin))
            {
                offset.Origin = Vector3.Zero;
            }

            var speed   = 0.0f;
            var minterp = PhysicsObj.get_minterp();

            if (minterp != null)
            {
                speed = minterp.get_max_speed() * 5.0f;
            }

            if (speed < PhysicsGlobals.EPSILON)
            {
                speed = 15.0f;
            }

            var delta = speed * (float)quantum;

            if (delta >= Math.Abs(dist))
            {
                delta = dist;
            }

            offset.Origin *= delta;

            var curHeading    = PhysicsObj.Position.Frame.get_heading();
            var targetHeading = PhysicsObj.Position.heading(targetPosition);
            var heading       = targetHeading - curHeading;

            if (Math.Abs(heading) < PhysicsGlobals.EPSILON)
            {
                heading = 0.0f;
            }
            if (heading < -PhysicsGlobals.EPSILON)
            {
                heading += 360.0f;
            }

            //Console.WriteLine($"StickyManager.AdjustOffset(targetHeading={targetHeading}, curHeading={curHeading}, setHeading={heading})");
            offset.set_heading(heading);
        }
Пример #2
0
        public void adjust_offset(AFrame offset, double quantum)
        {
            if (TargetID == 0 || !Initialized)
            {
                return;
            }

            var target         = PhysicsObj.GetObjectA(TargetID);
            var targetPosition = target == null ? TargetPosition : target.Position;

            offset.Origin   = PhysicsObj.Position.GetOffset(targetPosition);
            offset.Origin   = PhysicsObj.Position.GlobalToLocalVec(offset.Origin);
            offset.Origin.Z = 0.0f;

            var radius = PhysicsObj.GetRadius();
            var dist   = Position.CylinderDistanceNoZ(radius, PhysicsObj.Position, TargetRadius, targetPosition) - StickyRadius;

            CollisionInfo.NormalizeCheckSmall(ref offset.Origin);

            var speed   = 0.0f;
            var minterp = PhysicsObj.get_minterp();

            if (minterp != null)
            {
                speed = minterp.get_max_speed() * 5.0f;
            }

            var delta = speed * (float)quantum;

            if (delta >= Math.Abs(dist))
            {
                delta = dist;
            }

            offset.Origin *= delta;

            var heading = PhysicsObj.Position.heading(targetPosition) - PhysicsObj.Position.Frame.get_heading();

            if (Math.Abs(heading) < PhysicsGlobals.EPSILON)
            {
                heading = 0.0f;
            }
            if (heading < -PhysicsGlobals.EPSILON)
            {
                heading += 360.0f;
            }

            offset.set_heading(heading);
        }
Пример #3
0
        public bool FindPlacementPos()
        {
            // refactor me
            SpherePath.SetCheckPos(SpherePath.CurPos, SpherePath.CurCell);

            CollisionInfo.SlidingNormalValid  = false;
            CollisionInfo.ContactPlaneValid   = false;
            CollisionInfo.ContactPlaneIsWater = false;

            var transitionState = TransitionalInsert(3);

            var redo = 0;

            transitionState = ValidatePlacementTransition(transitionState, ref redo);

            if (transitionState == TransitionState.OK)
            {
                return(true);
            }

            if (!SpherePath.PlacementAllowsSliding)
            {
                return(false);
            }

            var adjustDist = 4.0f;
            var adjustRad  = adjustDist;
            var sphereRad  = SpherePath.LocalSphere[0].Radius;

            var fakeSphere = false;

            if (sphereRad < 0.125f)
            {
                fakeSphere = true;
                adjustRad  = 2.0f;
            }
            else if (sphereRad < 0.48f)
            {
                sphereRad = 0.48f;
            }

            var movementDelta = sphereRad;

            var fNumSteps = 4.0f / movementDelta;

            if (fakeSphere)
            {
                fNumSteps *= 0.5f;
            }

            if (fNumSteps <= 1.0f)
            {
                return(false);
            }

            var numSteps       = (int)Math.Ceiling(fNumSteps);
            var distPerStep    = adjustRad / numSteps;
            var radiansPerStep = (float)(Math.PI * distPerStep / sphereRad);

            var totalDist = 0.0f;
            var totalRad  = 0.0f;

            for (var i = 0; i < numSteps; i++)
            {
                totalDist += distPerStep;
                totalRad  += radiansPerStep;

                var rad = (int)Math.Ceiling(totalRad);
                rad *= 2;
                var angle = 360.0f / rad;

                var frame = new AFrame();

                for (var j = 0; j < rad; j++)
                {
                    SpherePath.SetCheckPos(SpherePath.CurPos, SpherePath.CurCell);
                    frame.set_heading(angle * j);
                    var offset = frame.get_vector_heading() * totalDist;
                    SpherePath.GlobalOffset = AdjustOffset(offset);
                    if (SpherePath.GlobalOffset.Length() >= PhysicsGlobals.EPSILON)
                    {
                        SpherePath.AddOffsetToCheckPos(SpherePath.GlobalOffset);

                        // possibly reset by AdjustOffset
                        CollisionInfo.SlidingNormalValid  = false;
                        CollisionInfo.ContactPlaneValid   = false;
                        CollisionInfo.ContactPlaneIsWater = false;

                        transitionState = TransitionalInsert(3);
                        transitionState = ValidatePlacementTransition(transitionState, ref redo);

                        if (transitionState == TransitionState.OK)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }