/// <summary>
        /// Attempts to activate the entity.
        /// </summary>
        public void Activate()
        {
            //If we're trying to activate, always set the deactivation candidacy to false.  This resets the timer if necessary.
            IsDeactivationCandidate = false;
            var currentSimulationIsland = SimulationIsland;

            if (currentSimulationIsland != null)
            {
                //We can force-activate an island.
                //Note that this does nothing for objects not in a space
                //or kinematic objects that don't have an island.
                //"Activating" a kinematic object is meaningless- their activity state
                //is entirely defined by their velocity.
                currentSimulationIsland.IsActive = true;
            }
            else
            {
                //"Wake up" the kinematic entity.
                //The time is used as a flag.  If time <= 0, that means the object will be considered active until the subsequent update.
                velocityTimeBelowLimit = -1;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Scales all components of the matrix.
        /// </summary>
        /// <param name="matrix">Matrix to scale.</param>
        /// <param name="scale">Amount to scale.</param>
        /// <param name="result">Scaled matrix.</param>
        public static void Multiply(ref Matrix matrix, Fix64 scale, out Matrix result)
        {
            result.M11 = matrix.M11 * scale;
            result.M12 = matrix.M12 * scale;
            result.M13 = matrix.M13 * scale;
            result.M14 = matrix.M14 * scale;

            result.M21 = matrix.M21 * scale;
            result.M22 = matrix.M22 * scale;
            result.M23 = matrix.M23 * scale;
            result.M24 = matrix.M24 * scale;

            result.M31 = matrix.M31 * scale;
            result.M32 = matrix.M32 * scale;
            result.M33 = matrix.M33 * scale;
            result.M34 = matrix.M34 * scale;

            result.M41 = matrix.M41 * scale;
            result.M42 = matrix.M42 * scale;
            result.M43 = matrix.M43 * scale;
            result.M44 = matrix.M44 * scale;
        }
Ejemplo n.º 3
0
        public override Fix64 GetFloatValue(BitArray bitArray)
        {
            int result = 0;

            for (int i = 0; i < _size; i++)
            {
                int  index = _bitOffset + i;
                bool bit   = bitArray[index];
                if (bit)
                {
                    result |= 1 << i;
                }
            }

            //min = -1.0
            //max = 1.0
            //precision = 0.5
            //default = 0.0

            //-1.0, -0.5, 0, 0.5, 1.0
            // 0,  1, 2, 3, 4
            //if result is greater than the max value
            //the actual value = (result - number of values) * precision
            //for example, for result 3, actual value = (3 - 5) * 0.5 = -2 * 0.5 = -1.0
            Fix64 floatResult = (Fix64)result * _precision;

            //is result valid?
            if (result > _nvalues)
            {
                SWConsole.Error($"invalid result({result}): result={result} min={_min} max={_max} default={_defaultValue}");
                floatResult = _defaultValue;
            }
            else if (floatResult > _max)
            {
                floatResult = (Fix64)(result - _nvalues) * _precision;
            }

            return(floatResult);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Computes the volume distribution of the triangle.
        /// The volume distribution can be used to compute inertia tensors when
        /// paired with mass and other tuning factors.
        /// </summary>
        ///<param name="vA">First vertex in the triangle.</param>
        ///<param name="vB">Second vertex in the triangle.</param>
        ///<param name="vC">Third vertex in the triangle.</param>
        /// <returns>Volume distribution of the shape.</returns>
        public static Matrix3x3 ComputeVolumeDistribution(Vector3 vA, Vector3 vB, Vector3 vC)
        {
            Vector3 center = (vA + vB + vC) * F64.OneThird;

            //Calculate distribution of mass.

            Fix64 massPerPoint = F64.OneThird;

            //Subtract the position from the distribution, moving into a 'body space' relative to itself.
            //        [ (j * j + z * z)  (-j * j)  (-j * z) ]
            //I = I + [ (-j * j)  (j * j + z * z)  (-j * z) ]
            //	      [ (-j * z)  (-j * z)  (j * j + j * j) ]

            Fix64 i = vA.X - center.X;
            Fix64 j = vA.Y - center.Y;
            Fix64 k = vA.Z - center.Z;
            //localInertiaTensor += new Matrix(j * j + k * k, -j * j, -j * k, 0, -j * j, j * j + k * k, -j * k, 0, -j * k, -j * k, j * j + j * j, 0, 0, 0, 0, 0); //No mass per point.
            var volumeDistribution = new Matrix3x3(massPerPoint * (j * j + k * k), massPerPoint * (-i * j), massPerPoint * (-i * k),
                                                   massPerPoint * (-i * j), massPerPoint * (i * i + k * k), massPerPoint * (-j * k),
                                                   massPerPoint * (-i * k), massPerPoint * (-j * k), massPerPoint * (i * i + j * j));

            i = vB.X - center.X;
            j = vB.Y - center.Y;
            k = vB.Z - center.Z;
            var pointContribution = new Matrix3x3(massPerPoint * (j * j + k * k), massPerPoint * (-i * j), massPerPoint * (-i * k),
                                                  massPerPoint * (-i * j), massPerPoint * (i * i + k * k), massPerPoint * (-j * k),
                                                  massPerPoint * (-i * k), massPerPoint * (-j * k), massPerPoint * (i * i + j * j));

            Matrix3x3.Add(ref volumeDistribution, ref pointContribution, out volumeDistribution);

            i = vC.X - center.X;
            j = vC.Y - center.Y;
            k = vC.Z - center.Z;
            pointContribution = new Matrix3x3(massPerPoint * (j * j + k * k), massPerPoint * (-i * j), massPerPoint * (-i * k),
                                              massPerPoint * (-i * j), massPerPoint * (i * i + k * k), massPerPoint * (-j * k),
                                              massPerPoint * (-i * k), massPerPoint * (-j * k), massPerPoint * (i * i + j * j));
            Matrix3x3.Add(ref volumeDistribution, ref pointContribution, out volumeDistribution);
            return(volumeDistribution);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Multiply two matrices. Notice: matrix multiplication is not commutative.
        /// </summary>
        /// <param name="matrix1">The first matrix.</param>
        /// <param name="matrix2">The second matrix.</param>
        /// <param name="result">The product of both matrices.</param>
        public static void Multiply(ref JMatrix matrix1, ref JMatrix matrix2, out JMatrix result)
        {
            Fix64 num0 = ((matrix1.M11 * matrix2.M11) + (matrix1.M12 * matrix2.M21)) + (matrix1.M13 * matrix2.M31);
            Fix64 num1 = ((matrix1.M11 * matrix2.M12) + (matrix1.M12 * matrix2.M22)) + (matrix1.M13 * matrix2.M32);
            Fix64 num2 = ((matrix1.M11 * matrix2.M13) + (matrix1.M12 * matrix2.M23)) + (matrix1.M13 * matrix2.M33);
            Fix64 num3 = ((matrix1.M21 * matrix2.M11) + (matrix1.M22 * matrix2.M21)) + (matrix1.M23 * matrix2.M31);
            Fix64 num4 = ((matrix1.M21 * matrix2.M12) + (matrix1.M22 * matrix2.M22)) + (matrix1.M23 * matrix2.M32);
            Fix64 num5 = ((matrix1.M21 * matrix2.M13) + (matrix1.M22 * matrix2.M23)) + (matrix1.M23 * matrix2.M33);
            Fix64 num6 = ((matrix1.M31 * matrix2.M11) + (matrix1.M32 * matrix2.M21)) + (matrix1.M33 * matrix2.M31);
            Fix64 num7 = ((matrix1.M31 * matrix2.M12) + (matrix1.M32 * matrix2.M22)) + (matrix1.M33 * matrix2.M32);
            Fix64 num8 = ((matrix1.M31 * matrix2.M13) + (matrix1.M32 * matrix2.M23)) + (matrix1.M33 * matrix2.M33);

            result.M11 = num0;
            result.M12 = num1;
            result.M13 = num2;
            result.M21 = num3;
            result.M22 = num4;
            result.M23 = num5;
            result.M31 = num6;
            result.M32 = num7;
            result.M33 = num8;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a JMatrix representing an orientation from a quaternion.
        /// </summary>
        /// <param name="quaternion">The quaternion the matrix should be created from.</param>
        /// <param name="result">JMatrix representing an orientation.</param>
        public static void CreateFromQuaternion(ref JQuaternion quaternion, out JMatrix result)
        {
            Fix64 num9 = quaternion.X * quaternion.X;
            Fix64 num8 = quaternion.Y * quaternion.Y;
            Fix64 num7 = quaternion.Z * quaternion.Z;
            Fix64 num6 = quaternion.X * quaternion.Y;
            Fix64 num5 = quaternion.Z * quaternion.W;
            Fix64 num4 = quaternion.Z * quaternion.X;
            Fix64 num3 = quaternion.Y * quaternion.W;
            Fix64 num2 = quaternion.Y * quaternion.Z;
            Fix64 num  = quaternion.X * quaternion.W;

            result.M11 = 1f - (2f * (num8 + num7));
            result.M12 = 2f * (num6 + num5);
            result.M13 = 2f * (num4 - num3);
            result.M21 = 2f * (num6 - num5);
            result.M22 = 1f - (2f * (num7 + num9));
            result.M23 = 2f * (num2 + num);
            result.M31 = 2f * (num4 + num3);
            result.M32 = 2f * (num2 - num);
            result.M33 = 1f - (2f * (num8 + num9));
        }
Ejemplo n.º 7
0
    private void Fall(Fix64 decel)
    {
        // get the velocity after deceleration
        if (velocity.Y - (decel * time_delta) > -jumpSpeed)
        {
            velocity.Y -= decel * time_delta;
        }
        else
        {
            velocity.Y = -jumpSpeed;
        }

        float y_distance = Mathf.Clamp((float)(velocity.Y * time_delta), (float)(border_b - pos.Y), (float)(border_t - pos.Y));
        float x_distance = Mathf.Clamp((float)(velocity.X * time_delta), (float)(border_l - pos.X), (float)(border_r - pos.X));

        if ((Fix64)y_distance == border_b - pos.Y)
        {
            state.airborne = false;
        }

        transform.position += (Vector3.right * x_distance) + (Vector3.up * y_distance);
    }
Ejemplo n.º 8
0
        ///<summary>
        /// Constructs a new convex hull shape.
        /// The point set will be recentered on the local origin.
        /// If that offset is needed, use the other constructor which outputs the computed center.
        ///</summary>
        ///<param name="vertices">Point set to use to construct the convex hull.</param>
        ///<exception cref="ArgumentException">Thrown when the point set is empty.</exception>
        public ConvexHullShape(IList <Vector3> vertices)
        {
            if (vertices.Count == 0)
            {
                throw new ArgumentException("Vertices list used to create a ConvexHullShape cannot be empty.");
            }

            var surfaceVertices     = CommonResources.GetVectorList();
            var hullTriangleIndices = CommonResources.GetIntList();

            Vector3 center;

            UpdateConvexShapeInfo(ComputeDescription(vertices, collisionMargin, out center, hullTriangleIndices, surfaceVertices));
            this.vertices = surfaceVertices.ToArray();


            CommonResources.GiveBack(hullTriangleIndices);
            CommonResources.GiveBack(surfaceVertices);

            unexpandedMaximumRadius = MaximumRadius - collisionMargin;
            unexpandedMinimumRadius = MinimumRadius - collisionMargin;
        }
Ejemplo n.º 9
0
        void _Catching(FBActor actor, Fix64 deltaTime)
        {
            actor.m_timer -= deltaTime;

            if (actor.m_timer <= Fix64.Zero)
            {
                //Debuger.Log("_Catching end frameNumber:" + actor.world.world.frameCount);
                actor.particle.velocity = FixVector2.kZero;
                actor.m_stateSubState   = (int)SubState.kAfterCatching;
                actor.m_timer           = actor.m_configuration.dkcb_afterCathingWaitingTime[actor.m_stateDataIndex];

                //能拿到球的情况下在球的运动差值完成后冻结球
                actor.world.ball.willBeFreezed();
                actor.world.ball.transferTarget = actor;

                //播放球员起身动画
                actor.world.onDoorKeeperBeginToGetup(actor);
                return;
            }

            actor.particle.velocity = actor.m_cathingBallStateMovingVelocity;
        }
Ejemplo n.º 10
0
        public void Transpose()
        {
            Fix64 m00 = this.x.x;
            Fix64 m01 = this.y.x;
            Fix64 m02 = this.z.x;
            Fix64 m10 = this.x.y;
            Fix64 m11 = this.y.y;
            Fix64 m12 = this.z.y;
            Fix64 m20 = this.x.z;
            Fix64 m21 = this.y.z;
            Fix64 m22 = this.z.z;

            this.x.x = m00;
            this.x.y = m01;
            this.x.z = m02;
            this.y.x = m10;
            this.y.y = m11;
            this.y.z = m12;
            this.z.x = m20;
            this.z.y = m21;
            this.z.z = m22;
        }
Ejemplo n.º 11
0
    FixVector2 getClampedDirection(FixVector2 direction, FixVector2 expectDirection, Fix64 clampAngle)
    {
        FixVector2 destDirection = expectDirection;
        Fix64      dif           = FixVector2.dot(expectDirection, direction);

        //角度过大
        if (dif < Fix64.Cos(clampAngle))
        {
            //旋转angleClamp
            Fix64 c = FixVector2.cross(expectDirection, direction);
            if (c < Fix64.Zero)//逆时针旋转为正
            {
                destDirection = FixVector2.rotate(expectDirection, -clampAngle);
            }
            else
            {
                destDirection = FixVector2.rotate(expectDirection, clampAngle);
            }
        }

        return(destDirection);
    }
Ejemplo n.º 12
0
        public Fix64Vec2 FindNearestPointOnEdge(Fix64Vec2 testPosition, Fix64Vec2 pa, Fix64Vec2 pb, Fix64 width)
        {
            Fix64Vec2 pointOnEdge = Fix64Math.FindNearestPointOnLine(testPosition, pa, pb);
            Fix64     distanceToA = Fix64Vec2.Distance(pointOnEdge, pa);
            Fix64     edgeWidth   = Fix64Vec2.Distance(pa, pb);
            Fix64     distanceToB = edgeWidth - distanceToA;
            Fix64Vec2 ba          = pb - pa;

            ba = ba.normalized;
            Fix64 halfWidth = width / Fix64.two;

            if (distanceToA < halfWidth)
            {
                pointOnEdge = pa + ba * halfWidth;
            }
            else if (distanceToB < halfWidth)
            {
                pointOnEdge = pb - ba * halfWidth;
            }

            return(pointOnEdge);
        }
Ejemplo n.º 13
0
    public void Play(LegacyAnimationData animData, Fix64 blendingTime, Fix64 normalizedTime) {
        if (animData == null) return;

        if (currentAnimationData != null) {
            currentAnimationData.speed = currentAnimationData.originalSpeed;
            currentAnimationData.normalizedSpeed = 1;
        }

        currentAnimationData = animData;

        if (blendingTime == 0 || 
            ((UFE.isConnected || UFE.config.debugOptions.emulateNetwork) && UFE.config.networkOptions.disableBlending)) {
            animator.Play(currentAnimationData.clipName);
        } else {
            animator.CrossFade(currentAnimationData.clipName, (float)blendingTime);
        }
        
        SetSpeed(currentAnimationData.speed);
        deltaDisplacement = new Vector3();

        SetCurrentClipPosition(normalizedTime);
    }
Ejemplo n.º 14
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public BoxBoxTestDemo(DemosGame game)
            : base(game)
        {
            //Fix64 blockWidth = 2;
            //Fix64 blockHeight = 2;
            //Fix64 blockLength = 6f;
            //Entity toAdd;


            //toAdd = new Box(new Vector3(0, 2,0), blockWidth, blockHeight, blockLength, 20);
            //toAdd.ActivityInformation.IsAlwaysActive = true;
            //toAdd.AllowStabilization = false;
            //Space.Add(toAdd);

            int   numColumns = 3;
            int   numRows    = 3;
            int   numHigh    = 30;
            Fix64 xSpacing   = 1.01m;
            Fix64 ySpacing   = 1.01m;
            Fix64 zSpacing   = 1.01m;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    for (int k = 0; k < numHigh; k++)
                    {
                        Space.Add(new Box(new Vector3(
                                              xSpacing * i - (numRows - 1) * xSpacing / 2,
                                              1 + k * (ySpacing),
                                              zSpacing * j - (numColumns - 1) * zSpacing / 2),
                                          .5m, .5m, .5m, 5));
                    }
                }
            }

            Space.Add(new Box(new Vector3(0, 0, 0), 20, 1, 20));
            game.Camera.Position = new Vector3(0, 3, 10);
        }
Ejemplo n.º 15
0
    /// <summary>
    /// AI在知道目标点的时候传球
    /// </summary>
    /// <param name="actor"></param>
    /// <param name="passBallDirection"></param>
    /// <param name="index"></param>
    public bool passBallToTarget(FBActor target, int index)
    {
        if (target == null)
        {
            Debuger.LogError(" target is null");
            return(false);
        }
        if (index < 0)
        {
            Debuger.LogError(" index < 0" + index);
            return(false);
        }
        var owner = m_ball.owner;

        if (owner == null)
        {
            Debuger.LogError(" owner is null");
            return(false);
        }

        Fix64 maxR  = owner.configuration.passBallMaxR[index];
        Fix64 minR  = owner.configuration.passBallMinR[index];
        Fix64 angle = owner.configuration.passBallFov[index];

        var passBallDirection = (target.getPosition() - owner.getPosition()).normalized;

        FixVector2 actorFaceDirection = getAjustedDirection(owner.direction, passBallDirection, owner.configuration.passBallAngleTorelance[index]);

        if (owner.doPassBall(index, actorFaceDirection))
        {
            //保存传球对象
            passBallType   = index;
            passBallTarget = target;
            passBallDir    = passBallDirection;
            return(true);
        }
        return(false);
    }
Ejemplo n.º 16
0
        /// <summary>
        /// Computes the quaternion rotation between two normalized vectors.
        /// </summary>
        /// <param name="v1">First unit-length vector.</param>
        /// <param name="v2">Second unit-length vector.</param>
        /// <param name="q">Quaternion representing the rotation from v1 to v2.</param>
        public static void GetQuaternionBetweenNormalizedVectors(ref Vector3 v1, ref Vector3 v2, out Quaternion q)
        {
            Fix64 dot;

            Vector3.Dot(ref v1, ref v2, out dot);
            //For non-normal vectors, the multiplying the axes length squared would be necessary:
            //Fix64 w = dot + (Fix64)Math.Sqrt(v1.LengthSquared() * v2.LengthSquared());
            if (dot < F64.Cm0p9999) //parallel, opposing direction
            {
                //If this occurs, the rotation required is ~180 degrees.
                //The problem is that we could choose any perpendicular axis for the rotation. It's not uniquely defined.
                //The solution is to pick an arbitrary perpendicular axis.
                //Project onto the plane which has the lowest component magnitude.
                //On that 2d plane, perform a 90 degree rotation.
                Fix64 absX = Fix64.Abs(v1.X);
                Fix64 absY = Fix64.Abs(v1.Y);
                Fix64 absZ = Fix64.Abs(v1.Z);
                if (absX < absY && absX < absZ)
                {
                    q = new Quaternion(F64.C0, -v1.Z, v1.Y, F64.C0);
                }
                else if (absY < absZ)
                {
                    q = new Quaternion(-v1.Z, F64.C0, v1.X, F64.C0);
                }
                else
                {
                    q = new Quaternion(-v1.Y, v1.X, F64.C0, F64.C0);
                }
            }
            else
            {
                Vector3 axis;
                Vector3.Cross(ref v1, ref v2, out axis);
                q = new Quaternion(axis.X, axis.Y, axis.Z, dot + F64.C1);
            }
            q.Normalize();
        }
Ejemplo n.º 17
0
        ///<summary>
        /// Updates the pair handler.
        ///</summary>
        ///<param name="dt">Timestep duration.</param>
        public override void UpdateCollision(Fix64 dt)
        {
            if (!suppressEvents)
            {
                CollidableA.EventTriggerer.OnPairUpdated(CollidableB, this);
                CollidableB.EventTriggerer.OnPairUpdated(CollidableA, this);
            }

            UpdateContacts(dt);


            if (contactCount > 0)
            {
                if (!suppressEvents)
                {
                    CollidableA.EventTriggerer.OnPairTouching(CollidableB, this);
                    CollidableB.EventTriggerer.OnPairTouching(CollidableA, this);
                }

                if (previousContactCount == 0)
                {
                    //collision started!
                    CollidableA.EventTriggerer.OnInitialCollisionDetected(CollidableB, this);
                    CollidableB.EventTriggerer.OnInitialCollisionDetected(CollidableA, this);

                    //No solver updateable addition in this method since it's handled by the "AddSolverUpdateable" method.
                }
            }
            else if (previousContactCount > 0 && !suppressEvents)
            {
                //collision ended!
                CollidableA.EventTriggerer.OnCollisionEnded(CollidableB, this);
                CollidableB.EventTriggerer.OnCollisionEnded(CollidableA, this);

                //No solver updateable removal in this method since it's handled by the "RemoveSolverUpdateable" method.
            }
            previousContactCount = contactCount;
        }
Ejemplo n.º 18
0
        public static Fix64 Max(params Fix64[] values)
        {
            int   num = values.Length;
            Fix64 result;

            if (num == 0)
            {
                result = Zero;
            }
            else
            {
                Fix64 num2 = values[0];
                for (int i = 1; i < num; i++)
                {
                    if (values[i] > num2)
                    {
                        num2 = values[i];
                    }
                }
                result = num2;
            }
            return(result);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Transforms a vector using a quaternion. Specialized for x,0,0 vectors.
        /// </summary>
        /// <param name="x">X component of the vector to transform.</param>
        /// <param name="rotation">Rotation to apply to the vector.</param>
        /// <param name="result">Transformed vector.</param>
        public static void TransformX(Fix64 x, ref Quaternion rotation, out Vector3 result)
        {
            //This operation is an optimized-down version of v' = q * v * q^-1.
            //The expanded form would be to treat v as an 'axis only' quaternion
            //and perform standard quaternion multiplication.  Assuming q is normalized,
            //q^-1 can be replaced by a conjugation.
            Fix64 y2  = rotation.Y + rotation.Y;
            Fix64 z2  = rotation.Z + rotation.Z;
            Fix64 xy2 = rotation.X * y2;
            Fix64 xz2 = rotation.X * z2;
            Fix64 yy2 = rotation.Y * y2;
            Fix64 zz2 = rotation.Z * z2;
            Fix64 wy2 = rotation.W * y2;
            Fix64 wz2 = rotation.W * z2;
            //Defer the component setting since they're used in computation.
            Fix64 transformedX = x * (F64.C1 - yy2 - zz2);
            Fix64 transformedY = x * (xy2 + wz2);
            Fix64 transformedZ = x * (xz2 - wy2);

            result.X = transformedX;
            result.Y = transformedY;
            result.Z = transformedZ;
        }
Ejemplo n.º 20
0
        // 返回值表示是否发生了状态迁移
        public virtual bool Run(Fix64 te)
        {
            if (!running)
            {
                return(false);
            }

            if (curState == null)
            {
                curState = StartState;
                CurSt.RunIn.SC(null);
            }

            // 刚刚变换到当前状态,则等待下一帧经过迁移条件检查后在执行,因为有可能立刻被迁移到别的状态去了
            var stateTransformed = CheckTransition(te);

            if (running && !stateTransformed)
            {
                CurSt.DoRun.SC(CurSt, te);
            }

            return(stateTransformed);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Computes a convex shape description for a ConeShape.
        /// </summary>
        ///<param name="height">Height of the cone.</param>
        ///<param name="radius">Radius of the cone base.</param>
        ///<param name="collisionMargin">Collision margin of the shape.</param>
        /// <returns>Description required to define a convex shape.</returns>
        public static ConvexShapeDescription ComputeDescription(Fix64 height, Fix64 radius, Fix64 collisionMargin)
        {
            ConvexShapeDescription description;

            description.EntityShapeVolume.Volume = F64.OneThird * MathHelper.Pi * radius * radius * height;

            description.EntityShapeVolume.VolumeDistribution = new Matrix3x3();
            Fix64 diagValue = (F64.C0p1 * height * height + F64.C0p15 * radius * radius);

            description.EntityShapeVolume.VolumeDistribution.M11 = diagValue;
            description.EntityShapeVolume.VolumeDistribution.M22 = F64.C0p3 * radius * radius;
            description.EntityShapeVolume.VolumeDistribution.M33 = diagValue;

            description.MaximumRadius = collisionMargin + MathHelper.Max(F64.C0p75 * height, Fix64.Sqrt(F64.C0p0625 * height * height + radius * radius));

            Fix64 denominator = radius / height;

            denominator = denominator / Fix64.Sqrt(denominator * denominator + F64.C1);
            description.MinimumRadius = collisionMargin + MathHelper.Min(F64.C0p25 * height, denominator * F64.C0p75 * height);

            description.CollisionMargin = collisionMargin;
            return(description);
        }
    public static int ComputeHealFinalValue_s(IntPtr l)
    {
        int result;

        try
        {
            Fix64 baseHeal;
            LuaObject.checkValueType <Fix64>(l, 1, out baseHeal);
            int attackerBuff_HealMul;
            LuaObject.checkType(l, 2, out attackerBuff_HealMul);
            int targetBuff_HealReceiveMul;
            LuaObject.checkType(l, 3, out targetBuff_HealReceiveMul);
            Fix64 fix = BattleFormula.ComputeHealFinalValue(baseHeal, attackerBuff_HealMul, targetBuff_HealReceiveMul);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, fix);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 23
0
        private FixVector2 getMoveTargetOffset(FBActor actor, out Fix64 heightOffset)
        {
            FixVector2 moveTaregetOffset = FixVector2.kZero;
            Fix64      moveHeight        = Fix64.Zero;
            FixVector2 offset            = actor.configuration.dkcb_cathingOffset[actor.m_stateDataIndex];

            FixVector2 targetDirection = actor.m_stateVector - actor.getPosition();
            Fix64      length          = targetDirection.length;

            targetDirection   = targetDirection / length;
            moveTaregetOffset = targetDirection * (length - offset.x);
            //Debuger.Log("getMoveTargetOffset configOffset:" + (UnityEngine.Vector2)offset
            //    + " targetPosition:" + (UnityEngine.Vector2)actor.m_stateVector
            //    + " actorPosition:" + (UnityEngine.Vector2)actor.getPosition());

            heightOffset = actor.m_stateValue2 - offset.y;
            if (heightOffset <= Fix64.Zero)
            {
                heightOffset = Fix64.Zero;
            }

            return(moveTaregetOffset);
        }
Ejemplo n.º 24
0
    private void AccelerateLeft(Fix64 fvelocity, Fix64 accel)
    {
        // get the new velocity
        Fix64 new_velocity = velocity.X - (accel * time_delta);

        // get the velocity after acceleration (cannot exceed -fvelocity)
        if (new_velocity > Fix64.Zero)
        {
            velocity.X = Fix64.Zero;
        }
        else if (new_velocity <= -fvelocity)
        {
            velocity.X = -fvelocity;
        }
        else
        {
            velocity.X = new_velocity;
        }

        float distance = Mathf.Clamp((float)(velocity.X * time_delta), (float)(border_l - pos.X), (float)(border_r - pos.X));

        transform.position += Vector3.right * distance;
    }
Ejemplo n.º 25
0
        public bool IsValidEdgePoint(Fix64Vec2 p, Fix64Vec2 pClose, Fix64Vec2 pFar, Fix64 width)
        {
            Fix64Vec2 vCloseP = pClose - p;
            Fix64Vec2 vFarP   = pFar - p;
            Fix64     angle   = Fix64Vec2.Angle(vCloseP, vFarP);

            //hypotenuse
            Fix64 h = Fix64Vec2.Distance(pClose, p);
            //adjacent
            Fix64 halfWidth = width / Fix64.two;
            Fix64 a         = halfWidth;

            Fix64 minAngle = Fix64.two * Fix64.Asin(a / h) * Fix64.RadToDegree;

            if (minAngle > angle)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 26
0
    //- 处于该状态时每帧调用的函数
    //
    // @return none
    public override void updateLogic()
    {
        //UnityTools.Log("towerstand");
        for (int i = 0; i < GameData.g_listSoldier.Count; i++)
        {
            var soldier = GameData.g_listSoldier[i];

            Fix64 distance = FixVector3.Distance(m_unit.m_fixv3LogicPosition, soldier.m_fixv3LogicPosition);
            s_scTestContent += distance.ToString() + ",";

            //如果进入攻击范围并且大于禁止攻击的范围
            if (distance <= (Fix64)m_unit.attackRange)
            {
                s_fixTestCount         += distance;
                m_unit.lockedAttackUnit = soldier;

                m_unit.addAttackingObj(soldier);
                soldier.addAttackMeObj(m_unit);

                m_unit.changeState("towerattack");
            }
        }
    }
Ejemplo n.º 27
0
    public void Skill()
    {
        //photonView.RPC("RealSkill", PhotonTargets.All);
        //gameObject.GetComponent<MoveScript>().stopwalking();
        //gameObject.GetComponent<StealthScript>().StealthEnd();
        currentcooldown = 0;
        skillavaliable  = false;
        float        radius      = 2;
        Vector2      actionplace = transform.position;
        Fix64        rfix        = (Fix64)4;
        Fix64Vector2 apf         = new Fix64Vector2(actionplace);

        Collider2D[] colliders = Physics2D.OverlapCircleAll(actionplace, radius);
        foreach (Collider2D hit in colliders)
        {
            HPScript hp = hit.GetComponent <HPScript>();
            if (hp != null)
            {
                if (hit == gameObject.GetComponent <Collider2D>())
                {
                    hp.GetHurt(Mathf.Min(10, hp.currentHP - 1));
                }
                else
                {
                    Rigidbody2D  rb        = hit.GetComponent <Rigidbody2D>();
                    Fix64Vector2 rbpf      = new Fix64Vector2(rb.position);
                    Fix64Vector2 explforce = rbpf - apf;
                    if (explforce.LengthSquare() > rfix)
                    {
                        continue;
                    }
                    hp.GetHurt(10);
                    hit.GetComponent <RBScript>().GetPushed(explforce.normalized() * (Fix64)9, 1f);
                }
            }
        }
    }
Ejemplo n.º 28
0
        void _beforeCatching(FBActor actor, Fix64 deltaTime)
        {
            if (actor.world.ball.owner != null || !actor.world.ball.willBeCatched)
            {
                actor.setToMovementState();
                //actor.m_nextState = Movement.instance;
                return;
            }

            actor.m_timer -= deltaTime;

            if (actor.m_timer <= actor.configuration.scb_catchingAniTime[actor.m_stateDataIndex] && !actor.m_stateBool)
            {
                actor.m_stateBool = true;
                actor.world.onActorAirCatchingBall(actor, actor.m_stateDataIndex);
            }

            if (actor.m_timer <= Fix64.Zero)
            {
                actor.m_direction = actor.m_stateVector;
                actor.world.ball.transferTarget = actor;

                actor.m_stateSubState = (int)SubState.kAfterCatching;
                actor.m_timer         = actor.m_configuration.scb_lockTimeAfterCatching[actor.m_stateDataIndex];

                return;
            }

            var cos   = FixVector2.dot(actor.m_stateVector, actor.m_direction);
            var sin   = FixVector2.cross(actor.m_stateVector, actor.m_direction);
            var angle = Fix64.Atan2(sin, cos) * actor.m_timer / actor.m_stateValue;

            cos = Fix64.Cos(angle);
            sin = Fix64.Sin(angle);
            actor.m_direction.x = FixVector2.dot(actor.m_stateVector, new FixVector2(cos, -sin));
            actor.m_direction.y = FixVector2.dot(actor.m_stateVector, new FixVector2(sin, cos));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public RagdollDemo(DemosGame game)
            : base(game)
        {
            int   numRows    = 8;
            int   numColumns = 3;
            Fix64 xSpacing   = 5;
            Fix64 zSpacing   = 5;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    Ragdoll ragdoll = new Ragdoll();
                    //Transform and add every bone.
                    foreach (var bone in ragdoll.Bones)
                    {
                        bone.WorldTransform *= Matrix.CreateTranslation(new Vector3(
                                                                            i * xSpacing - (numRows - 1) * xSpacing / 2,
                                                                            i - 1.5m,
                                                                            j * zSpacing - (numColumns - 1) * zSpacing / 2));
                        Space.Add(bone);
                    }

                    //Add every constraint.
                    foreach (var joint in ragdoll.Joints)
                    {
                        Space.Add(joint);
                    }
                }
            }

            //Add some ground.
            Space.Add(new Box(new Vector3(0, -3.5m, 0), 50, 1, 50));

            game.Camera.Position      = new Vector3(0, 5, -35);
            game.Camera.ViewDirection = new Vector3(0, 0, 1);
        }
Ejemplo n.º 30
0
    bool InitData()
    {
        bool res = true;

        switch (level)
        {
        case 1:
            expend   = (Fix64)75;
            treatHP  = (Fix64)100;
            attackHP = (Fix64)100;
            break;

        case 2:
            expend   = (Fix64)100;
            treatHP  = (Fix64)150;
            attackHP = (Fix64)150;
            break;

        case 3:
            expend   = (Fix64)125;
            treatHP  = (Fix64)200;
            attackHP = (Fix64)200;
            break;

        case 4:
            expend   = (Fix64)150;
            treatHP  = (Fix64)250;
            attackHP = (Fix64)250;
            break;

        default:
            UnityTools.Log("技能等级异常 " + name + " level=" + level);
            res = false;
            break;
        }
        return(res);
    }