示例#1
0
        public bool isValid2(int i0, int i1, int i2, VInt3[] aBuf, VInt3[] bBuf, VFixedPoint lower, VFixedPoint upper)
        {
            VInt3 pa0 = aBuf[i0];
            VInt3 pa1 = aBuf[i1];
            VInt3 pa2 = aBuf[i2];

            VInt3 pb0 = bBuf[i0];
            VInt3 pb1 = bBuf[i1];
            VInt3 pb2 = bBuf[i2];

            VInt3 p0 = pa0 - pb0;
            VInt3 p1 = pa1 - pb1;
            VInt3 p2 = pa2 - pb2;

            VInt3 v1 = p1 - p0;
            VInt3 v2 = p2 - p0;

            VInt3 denormalizedNormal = VInt3.Cross(v1, v2);

            VInt3       planeNormal = denormalizedNormal.Normalize();
            VFixedPoint planeDist   = VInt3.Dot(planeNormal, p0);

            m_planeNormal = planeNormal;
            m_planeDist   = planeDist;

            return(planeDist >= lower && upper >= planeDist);
        }
示例#2
0
        public static void calculateVelocity(VIntTransform transform0, VIntTransform transform1, VFixedPoint timeStep, ref VInt3 linVel, ref VInt3 angVel)
        {
            linVel = (transform1.position - transform0.position) / timeStep;
            VIntQuaternion rotation = VIntQuaternion.FromToRotation(transform0.forward, transform1.forward);

            angVel.x = rotation.x;
            angVel.y = rotation.y;
            angVel.z = rotation.z;
            angVel   = angVel.Normalize() * rotation.w / timeStep;
        }
示例#3
0
        protected void stepForwardAndStrafe(CollisionWorld collisionWorld, VInt3 walkMove)
        {
            VIntTransform start = VIntTransform.Identity, end = VIntTransform.Identity;

            targetPosition = currentPosition + walkMove;
            VFixedPoint fraction = VFixedPoint.One;
            int         maxIter  = 10;

            while (fraction > VFixedPoint.Create(0.01f) && maxIter-- > 0)
            {
                start.position = currentPosition;
                end.position   = targetPosition;

                List <CastResult> results = new List <CastResult>();
                me.setWorldTransform(start);
                collisionWorld.SweepTest(me, end.position, results);

                if (results.Count > 0)
                {
                    VFixedPoint closestHitFraction = results[0].fraction;
                    VInt3       hitNormalWorld     = results[0].normal;
                    for (int i = 1; i < results.Count; i++)
                    {
                        VFixedPoint afraction = results[i].fraction;
                        if (afraction <= closestHitFraction)
                        {
                            closestHitFraction = afraction;
                            hitNormalWorld     = results[i].normal;
                        }
                    }

                    fraction -= closestHitFraction;
                    updateTargetPositionBasedOnCollision(hitNormalWorld);
                    VInt3       currentDir = targetPosition - currentPosition;
                    VFixedPoint distance2  = currentDir.sqrMagnitude;
                    if (distance2 > Globals.EPS2)
                    {
                        currentDir = currentDir.Normalize();
                        if (VInt3.Dot(currentDir, normalizedDirection) <= VFixedPoint.Zero)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    currentPosition = targetPosition;
                }
            }
        }
示例#4
0
        public static void rayTestSingle(VInt3 fromPos, VInt3 toPos, CollisionObject collisionObject, RayResultCallback resultCallback)
        {
            SphereShape sphereShape    = (SphereShape)collisionObject.getCollisionShape();
            VInt3       objectPosition = collisionObject.getWorldTransform().position;
            VInt3       hitNormal      = VInt3.zero;
            VFixedPoint t0             = VFixedPoint.Zero;

            if (rayTestSphere(fromPos, toPos, objectPosition, sphereShape.getRadius(), ref hitNormal, ref t0))
            {
                resultCallback.addSingleResult(collisionObject, hitNormal.Normalize(), t0);
            }
        }
示例#5
0
        protected void updateTargetPositionBasedOnCollision(VInt3 hitNormal)
        {
            VInt3       movementDirection = targetPosition - currentPosition;
            VFixedPoint movementLength    = movementDirection.magnitude;

            if (movementLength > Globals.EPS)
            {
                movementDirection = movementDirection.Normalize();

                VInt3 reflectionDir = computeReflectionDirection(movementDirection, hitNormal);
                reflectionDir = reflectionDir.Normalize();

                VInt3 perpendicularDir = perpendicularComponent(reflectionDir, hitNormal);
                targetPosition = currentPosition + perpendicularDir * movementLength;
            }
        }
示例#6
0
        //sphere move to collide capsule
        static bool sweepSphereCapsule(SphereShape sphere, VIntTransform sphereTransform, VInt3 end,
                                       CapsuleShape capsule, VIntTransform capsuleTransform, ref VInt3 normal, ref VFixedPoint t)
        {
            VInt3       move           = end - sphereTransform.position;
            VFixedPoint radiusSum      = sphere.getRadius() + capsule.getRadius();
            VInt3       capsuleP0      = capsuleTransform.TransformPoint(capsule.getUpAxis() * capsule.getHalfHeight());
            VInt3       capsuleP1      = capsuleTransform.TransformPoint(capsule.getUpAxis() * -capsule.getHalfHeight());
            VInt3       spherePosition = sphereTransform.position;
            VFixedPoint tmp            = VFixedPoint.Zero;

            if (Distance.distancePointSegmentSquared(capsuleP0, capsuleP1, spherePosition, ref tmp) < radiusSum * radiusSum)
            {
                t      = VFixedPoint.Zero;
                normal = -move.Normalize();
                return(true);
            }

            VFixedPoint u0        = VFixedPoint.Zero;
            VInt3       tmpNormal = VInt3.zero;

            if (capsuleP0 == capsuleP1)
            {
                VInt3 ToPos = spherePosition + move;
                if (SphereSphereSweepAlgorithm.sphereSphereSweep(sphere.getRadius(), spherePosition, ToPos, capsule.getRadius(), capsuleTransform.position, ref u0, ref tmp, ref tmpNormal))
                {
                    t      = u0;
                    normal = tmpNormal;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (CapsuleRaytestAlgorithm.raycastCapsule(spherePosition, end, capsuleP0, capsuleP1, radiusSum, ref normal, ref u0))
            {
                t = u0;
                VFixedPoint param             = VFixedPoint.Zero;
                VInt3       movedSphereCenter = spherePosition + (end - spherePosition) * u0;
                Distance.distancePointSegmentSquared(capsuleP0, capsuleP1, movedSphereCenter, ref param);
                normal = movedSphereCenter - (capsuleP0 * (VFixedPoint.One - param) + capsuleP1 * param);
                normal = normal.Normalize();
                return(true);
            }

            return(false);
        }
示例#7
0
        public static bool sweepCapsuleCapsule(CapsuleShape lss0, VIntTransform transform0, VInt3 toPos, CapsuleShape lss1, VIntTransform transform1, ref VFixedPoint dist, ref VInt3 hitNormal)
        {
            VInt3       FromPos   = transform0.position;
            VFixedPoint radiusSun = lss0.getRadius() + lss1.getRadius();
            VFixedPoint length    = (toPos - FromPos).magnitude;
            VInt3       dir       = (toPos - FromPos) / length;

            VInt3 lss0p0 = transform0.TransformPoint(lss0.getUpAxis() * lss0.getHalfHeight()), lss0p1 = transform0.TransformPoint(lss0.getUpAxis() * -lss0.getHalfHeight());
            VInt3 lss1p0 = transform1.TransformPoint(lss1.getUpAxis() * lss1.getHalfHeight()), lss1p1 = transform1.TransformPoint(lss1.getUpAxis() * -lss1.getHalfHeight());

            bool        initialOverlapStatus = false;
            VFixedPoint tmp = VFixedPoint.Zero;

            if (lss0.getHalfHeight() < Globals.EPS)
            {
                initialOverlapStatus = Distance.distancePointSegmentSquared(lss1p0, lss1p1, lss0p0, ref tmp) < radiusSun * radiusSun;
            }
            else if (lss1.getHalfHeight() < Globals.EPS)
            {
                initialOverlapStatus = Distance.distancePointSegmentSquared(lss0p0, lss0p1, lss1p0, ref tmp) < radiusSun * radiusSun;
            }
            else
            {
                VInt3 x, y;
                initialOverlapStatus = Distance.SegmentSegmentDist2(lss0p0, lss0p1 - lss0p0, lss1p0, lss1p1 - lss1p0, out x, out y) < radiusSun * radiusSun;
            }

            if (initialOverlapStatus)
            {
                dist      = VFixedPoint.Zero;
                hitNormal = (FromPos - toPos).Normalize();
                return(true);
            }

            // 1. Extrude lss0 by lss1's length
            // 2. Inflate extruded shape by lss1's radius
            // 3. Raycast against resulting quad
            VInt3 D = (lss0p1 - lss0p0) * VFixedPoint.Half;
            VInt3 p0 = lss1p0 - D, p1 = lss1p1 - D, p0b = lss1p0 + D, p1b = lss1p1 + D;
            VInt3 normal = VInt3.Cross(p1b - p0b, p1 - p0b); normal = normal.Normalize();

            dist = VFixedPoint.One; bool status = false;

            VInt3 pa, pb, pc;

            if (VInt3.Dot(normal, dir) >= VFixedPoint.Zero)
            {
                pc = p0 - normal * radiusSun;
                pa = p1 - normal * radiusSun;
                pb = p1b - normal * radiusSun;
            }
            else
            {
                pc = p0 + normal * radiusSun;
                pa = p1 + normal * radiusSun;
                pb = p1b + normal * radiusSun;
            }
            VFixedPoint t = VFixedPoint.Zero, u = VFixedPoint.Zero, v = VFixedPoint.Zero;

            if (rayQuad(transform1.position, dir, pa, pb, pc, ref t, ref u, ref v, true) && t >= VFixedPoint.Zero && t < length)
            {
                dist   = t / length;
                status = true;
            }

            if (!status)
            {
                VInt3[] caps = new VInt3[]
                {
                    p0, p1, p1, p1b, p1b, p0b, p0b, p0
                };
                VInt3 tmpNormal = VInt3.zero;
                for (int i = 0; i < 4; i++)
                {
                    VFixedPoint s = VFixedPoint.Zero;
                    if (CapsuleRaytestAlgorithm.raycastCapsule(FromPos, toPos, caps[i * 2], caps[i * 2 + 1], radiusSun, ref tmpNormal, ref s))
                    {
                        if (s > VFixedPoint.Zero && s < dist)
                        {
                            dist   = s;
                            status = true;
                        }
                    }
                }
            }

            if (status)
            {
                VInt3 x, y;
                Distance.SegmentSegmentDist2(lss0p0 + dir * length * dist, lss0p1 - lss0p0, lss1p0, lss1p1 - lss1p0, out x, out y);
                hitNormal = (x - y).Normalize();
            }
            return(status);
        }
示例#8
0
 public void setVelocityForTimeInterval(VInt3 velocity)
 {
     walkDirection       = velocity;
     normalizedDirection = walkDirection.Normalize();
 }
示例#9
0
        private bool UseImpl(PoolObjHandle <ActorRoot> user)
        {
            bool  flag  = false;
            bool  flag2 = false;
            bool  flag3 = false;
            VInt3 value = VInt3.forward;

            switch (this.skillContext.AppointType)
            {
            case SkillRangeAppointType.Auto:
            case SkillRangeAppointType.Target:
                flag = true;
                break;

            case SkillRangeAppointType.Pos:
                flag2 = true;
                break;

            case SkillRangeAppointType.Directional:
                flag3 = true;
                value = this.skillContext.UseVector;
                if (this.skillContext.TargetID != 0u)
                {
                    PoolObjHandle <ActorRoot> actor = Singleton <GameObjMgr> .GetInstance().GetActor(this.skillContext.TargetID);

                    if (actor)
                    {
                        VInt3 vInt = actor.handle.location - user.handle.location;
                        vInt.y = 0;
                        vInt.Normalize();
                        value = vInt;
                    }
                }
                break;

            case SkillRangeAppointType.Track:
                flag2 = true;
                flag3 = true;
                value = this.skillContext.EndVector - this.skillContext.UseVector;
                if (value.sqrMagnitudeLong < 1L)
                {
                    value = VInt3.forward;
                }
                break;
            }
            if (flag && !this.skillContext.TargetActor)
            {
                return(false);
            }
            if (flag)
            {
                this.curAction = new PoolObjHandle <Action>(ActionManager.Instance.PlayAction(this.ActionName, true, false, new GameObject[]
                {
                    user.handle.gameObject,
                    this.skillContext.TargetActor.handle.gameObject
                }));
            }
            else
            {
                this.curAction = new PoolObjHandle <Action>(ActionManager.Instance.PlayAction(this.ActionName, true, false, new GameObject[]
                {
                    user.handle.gameObject
                }));
            }
            if (!this.curAction)
            {
                return(false);
            }
            this.curAction.handle.onActionStop += this.OnActionStopDelegate;
            this.curAction.handle.refParams.AddRefParam("SkillObj", this);
            this.curAction.handle.refParams.AddRefParam("SkillContext", this.skillContext);
            if (flag)
            {
                this.curAction.handle.refParams.AddRefParam("TargetActor", this.skillContext.TargetActor);
            }
            if (flag2)
            {
                this.curAction.handle.refParams.SetRefParam("_TargetPos", this.skillContext.UseVector);
            }
            if (flag3)
            {
                this.curAction.handle.refParams.SetRefParam("_TargetDir", value);
            }
            this.curAction.handle.refParams.SetRefParam("_BulletPos", this.skillContext.BulletPos);
            this.curAction.handle.refParams.SetRefParam("_BulletUseDir", user.handle.forward);
            if (this.bAgeImmeExcute)
            {
                this.curAction.handle.UpdateLogic((int)Singleton <FrameSynchr> .GetInstance().FrameDelta);
            }
            return(true);
        }
示例#10
0
 public static VFixedPoint SinAngle(VInt3 from, VInt3 to)
 {
     return(Cross(from.Normalize(), to.Normalize()).magnitude);
 }
示例#11
0
 public static VFixedPoint Angle(VInt3 a, VInt3 b)
 {
     return(FMath.Trig.acos(Dot(a.Normalize(), b.Normalize())));
 }
示例#12
0
 public static VIntQuaternion AngleAxis(VFixedPoint angle, VInt3 axis)
 {
     axis = axis.Normalize();
     return(new VIntQuaternion(FMath.Trig.Sin(angle / 2) * axis.x, FMath.Trig.Sin(angle / 2) * axis.y, FMath.Trig.Sin(angle / 2) * axis.z, FMath.Trig.Cos(angle / 2)));
 }
示例#13
0
        //Good Game
        //public override bool GetPortal (GraphNode other, List<Vector3> left, List<Vector3> right, bool backwards) {
        public override bool GetPortal(GraphNode other, List <VInt3> left, List <VInt3> right, bool backwards)
        {
            if (backwards)
            {
                return(true);
            }

            GridGraph gg = GetGridGraph(GraphIndex);

            int[]      neighbourOffsets = gg.neighbourOffsets;
            GridNode[] nodes            = gg.nodes;

            for (int i = 0; i < 4; i++)
            {
                if (HasConnectionInDirection(i) && other == nodes[NodeInGridIndex + neighbourOffsets[i]])
                {
                    //Good Game

                    /*Vector3 middle = ((Vector3)(position + other.position))*0.5f;
                     *                  Vector3 cross = Vector3.Cross(gg.collision.up, (Vector3)(other.position-position));*/
                    VInt3 middle = ((position + other.position)) / 2;
                    VInt3 cross  = VInt3.Cross((VInt3)gg.collision.up, (other.position - position));
                    cross.Normalize();
                    cross *= gg.nodeSize * 0.5f;
                    left.Add(middle - cross);
                    right.Add(middle + cross);
                    return(true);
                }
            }

            for (int i = 4; i < 8; i++)
            {
                if (HasConnectionInDirection(i) && other == nodes[NodeInGridIndex + neighbourOffsets[i]])
                {
                    bool rClear = false;
                    bool lClear = false;
                    if (HasConnectionInDirection(i - 4))
                    {
                        GridNode n2 = nodes[NodeInGridIndex + neighbourOffsets[i - 4]];
                        if (n2.Walkable && n2.HasConnectionInDirection((i - 4 + 1) % 4))
                        {
                            rClear = true;
                        }
                    }

                    if (HasConnectionInDirection((i - 4 + 1) % 4))
                    {
                        GridNode n2 = nodes[NodeInGridIndex + neighbourOffsets[(i - 4 + 1) % 4]];
                        if (n2.Walkable && n2.HasConnectionInDirection(i - 4))
                        {
                            lClear = true;
                        }
                    }

                    //Good Game

                    /*Vector3 middle = ((Vector3)(position + other.position))*0.5f;
                     *                  Vector3 cross = Vector3.Cross(gg.collision.up, (Vector3)(other.position-position));*/
                    VInt3 middle = ((position + other.position)) / 2;
                    VInt3 cross  = VInt3.Cross((VInt3)gg.collision.up, (other.position - position));
                    cross.Normalize();
                    cross *= gg.nodeSize * 1.4142f;

                    /*left.Add(middle - (lClear ? cross : Vector3.zero));
                     *                  right.Add(middle + (rClear ? cross : Vector3.zero));*/
                    left.Add(middle - (lClear ? cross : VInt3.zero));
                    right.Add(middle + (rClear ? cross : VInt3.zero));
                    return(true);
                }
            }

            return(false);
        }
        private bool UseImpl(PoolObjHandle <ActorRoot> user)
        {
            if (this.skillContext == null || !this.skillContext.TargetActor || this.cfgData == null)
            {
                return(false);
            }
            BuffHolderComponent buffHolderComp = this.skillContext.TargetActor.handle.BuffHolderComp;

            if (buffHolderComp == null)
            {
                return(false);
            }
            if (!this.CheckUseRule(this.skillContext))
            {
                return(false);
            }
            if (!buffHolderComp.overlayRule.CheckOverlay(this))
            {
                return(false);
            }
            bool  flag  = false;
            bool  flag2 = false;
            VInt3 value = VInt3.forward;

            switch (this.skillContext.AppointType)
            {
            case SkillRangeAppointType.Pos:
                flag = true;
                break;

            case SkillRangeAppointType.Directional:
                flag2 = true;
                value = this.skillContext.UseVector;
                if (this.skillContext.TargetID != 0u)
                {
                    PoolObjHandle <ActorRoot> actor = Singleton <GameObjMgr> .GetInstance().GetActor(this.skillContext.TargetID);

                    if (actor)
                    {
                        VInt3 vInt = actor.handle.location - user.handle.location;
                        vInt.y = 0;
                        vInt.Normalize();
                        value = vInt;
                    }
                }
                break;

            case SkillRangeAppointType.Track:
                flag  = true;
                flag2 = true;
                value = this.skillContext.EndVector - this.skillContext.UseVector;
                if (value.sqrMagnitudeLong < 1L)
                {
                    value = VInt3.forward;
                }
                break;
            }
            GameObject gameObject  = this.skillContext.Originator ? this.skillContext.Originator.handle.gameObject : null;
            GameObject gameObject2 = this.skillContext.TargetActor ? this.skillContext.TargetActor.handle.gameObject : null;

            this.curAction = new PoolObjHandle <Action>(ActionManager.Instance.PlayAction(this.ActionName, true, false, new GameObject[]
            {
                gameObject,
                gameObject2
            }));
            if (!this.curAction)
            {
                return(false);
            }
            this.curAction.handle.onActionStop += new ActionStopDelegate(this.OnActionStoped);
            this.curAction.handle.refParams.AddRefParam("SkillObj", this);
            this.curAction.handle.refParams.AddRefParam("SkillContext", this.skillContext);
            this.curAction.handle.refParams.AddRefParam("TargetActor", this.skillContext.TargetActor);
            this.curAction.handle.refParams.SetRefParam("_BulletPos", this.skillContext.EffectPos);
            this.curAction.handle.refParams.SetRefParam("_BulletDir", this.skillContext.EffectDir);
            if (flag)
            {
                this.curAction.handle.refParams.SetRefParam("_TargetPos", this.skillContext.UseVector);
            }
            if (flag2)
            {
                this.curAction.handle.refParams.SetRefParam("_TargetDir", value);
            }
            if (this.cfgData != null)
            {
                int num = this.cfgData.iDuration;
                if (this.cfgData.iDurationGrow > 0)
                {
                    SkillSlotType skillSlotType = this.skillContext.SlotType;
                    int           num2          = (int)(this.cfgData.bGrowthType % 10);
                    int           num3          = (int)(this.cfgData.bGrowthType / 10);
                    if ((skillSlotType >= SkillSlotType.SLOT_SKILL_1 && skillSlotType <= SkillSlotType.SLOT_SKILL_3) || (skillSlotType == SkillSlotType.SLOT_SKILL_0 && num2 > 0))
                    {
                        int num4 = 1;
                        if (this.skillContext.Originator && this.skillContext.Originator.handle.SkillControl != null && this.skillContext.Originator.handle.ValueComponent != null)
                        {
                            SkillSlot skillSlot = null;
                            if (num2 == 1)
                            {
                                num4 = this.skillContext.Originator.handle.ValueComponent.actorSoulLevel;
                            }
                            else
                            {
                                if (num2 - 1 >= 1 && num2 - 1 <= 3)
                                {
                                    skillSlotType = (SkillSlotType)(num2 - 1);
                                }
                                this.skillContext.Originator.handle.SkillControl.TryGetSkillSlot(skillSlotType, out skillSlot);
                                if (skillSlot != null)
                                {
                                    num4 = skillSlot.GetSkillLevel();
                                }
                            }
                        }
                        num4 = ((num4 < 1) ? 1 : num4);
                        num3 = ((num3 < 1) ? 1 : num3);
                        num += (num4 - 1) / num3 * this.cfgData.iDurationGrow;
                    }
                }
                if (this.skillContext.Originator && this.skillContext.Originator.handle != null && this.skillContext.Originator.handle.TheActorMeta.ActorType == ActorTypeDef.Actor_Type_Hero && this.skillContext.Originator.handle.TheStaticData.TheHeroOnlyInfo.AttackDistanceType == 2 && this.cfgData.iLongRangeReduction > 0)
                {
                    num = num * this.cfgData.iLongRangeReduction / 10000;
                }
                this.curAction.handle.ResetLength(num, false);
                if (this.cfgData.bEffectType == 2)
                {
                    this.DealTenacity(this.skillContext.TargetActor);
                }
            }
            bool flag3 = true;

            if (this.cfgData.bShowType != 0 || this.cfgData.bFloatTextID > 0)
            {
                if (!this.skillContext.TargetActor || this.skillContext.TargetActor.handle == null || this.skillContext.TargetActor.handle.BuffHolderComp == null || this.skillContext.TargetActor.handle.BuffHolderComp.SpawnedBuffList == null)
                {
                    return(false);
                }
                for (int i = 0; i < this.skillContext.TargetActor.handle.BuffHolderComp.SpawnedBuffList.get_Count(); i++)
                {
                    BuffSkill buffSkill = this.skillContext.TargetActor.handle.BuffHolderComp.SpawnedBuffList.get_Item(i);
                    if (buffSkill != null && buffSkill.cfgData != null && buffSkill.cfgData.iCfgID == this.cfgData.iCfgID)
                    {
                        flag3 = false;
                        break;
                    }
                }
                if (flag3)
                {
                    SpawnBuffEventParam spawnBuffEventParam = new SpawnBuffEventParam((uint)this.cfgData.bShowType, (uint)this.cfgData.bFloatTextID, this.skillContext.TargetActor);
                    Singleton <GameSkillEventSys> .GetInstance().SendEvent <SpawnBuffEventParam>(GameSkillEventDef.Event_SpawnBuff, this.skillContext.TargetActor, ref spawnBuffEventParam, GameSkillEventChannel.Channel_HostCtrlActor);
                }
            }
            this.skillContext.TargetActor.handle.BuffHolderComp.AddBuff(this);
            if (this.cfgData.bEffectType == 2 && this.cfgData.bShowType != 2)
            {
                LimitMoveEventParam limitMoveEventParam = new LimitMoveEventParam(base.CurAction.handle.length, this.SkillID, this.skillContext.TargetActor);
                Singleton <GameSkillEventSys> .GetInstance().SendEvent <LimitMoveEventParam>(GameSkillEventDef.AllEvent_LimitMove, this.skillContext.TargetActor, ref limitMoveEventParam, GameSkillEventChannel.Channel_AllActor);
            }
            if (this.bAgeImmeExcute)
            {
                this.curAction.handle.UpdateLogic((int)Singleton <FrameSynchr> .GetInstance().FrameDelta);
            }
            return(true);
        }