Exemple #1
0
        protected override void CreateSummons(int triggerIndex)
        {
            BuffData.Summon[][] summonss = this._buff.trigger.summons;

            int index = summonss.Length - 1;

            index = triggerIndex <= index ? triggerIndex : index;

            BuffData.Summon[] summons = summonss[index];

            Battle battle = this._buff.battle;
            int    count  = summons.Length;

            for (int i = 0; i < count; i++)
            {
                BuffData.Summon summon = summons[i];

                Vec3 buffPos = this._buff.property.position;

                float distance = battle.random.NextFloat(this._buff.radius - 0.5f, this._buff.radius + 0.5f);
                Quat  q        = Quat.Euler(0f, battle.random.NextFloat(0f, 360f), 0f);
                Vec3  offset   = q * Vec3.right * distance;
                offset.y = this._buff.caster.size.y * 0.5f;
                FoxFire foxFire = battle.CreateBio <FoxFire>(summon.id, buffPos + offset, this._buff.property.direction, this._buff.caster.property.team);
                foxFire.Setup(this._buff.property.lvl, this._buff.caster, distance);
            }
        }
Exemple #2
0
        public float angleWithDirection(Vector3 direction)
        {
            Vector3 myForward    = Quat.Euler(rotation) * new Vector3(0, 0, 1);
            Vector3 otherForward = direction;
            var     crossLen     = myForward.Cross(otherForward).Length;
            var     dotVal       = myForward.Dot(otherForward);

            return(Mathf.Atan2(crossLen, dotVal));
        }
Exemple #3
0
        public float angleBetweenForwards(NebulaTransform other)
        {
            Vector3 myForward    = Quat.Euler(rotation) * new Vector3(0, 0, 1);
            Vector3 otherForward = Quat.Euler(other.rotation) * new Vector3(0, 0, 1);
            var     crossLen     = myForward.Cross(otherForward).Length;
            var     dotVal       = myForward.Dot(otherForward);

            return(Mathf.Atan2(crossLen, dotVal));
        }
Exemple #4
0
        public void Matrix3()
        {
            FMat3 fm  = FMat3.FromQuaternion(FQuat.Euler(( Fix64 )30, ( Fix64 )(-20), ( Fix64 )49.342f));
            Mat3  m   = Mat3.FromQuaternion(Quat.Euler(30, -20, 49.342f));
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(4, 6, 9);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(4, 6, 9);

            fv  = fm.TransformPoint(fv);
            fv2 = fm.TransformVector(fv2);
            v   = m.TransformPoint(v);
            v2  = m.TransformVector(v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(fv2.ToString());
            this._output.WriteLine(v.ToString());
            this._output.WriteLine(v2.ToString());
            fm = FMat3.LookAt(fv, fv2);
            m  = Mat3.LookAt(v, v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fv = fm.Euler();
            v  = m.Euler();
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fm = FMat3.FromEuler(fv);
            m  = Mat3.FromEuler(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromScale(fv);
            m  = Mat3.FromScale(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromCross(fv);
            m  = Mat3.FromCross(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromOuterProduct(fv, fv2);
            m  = Mat3.FromOuterProduct(v, v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromRotationAxis(( Fix64 )35, fv);
            m  = Mat3.FromRotationAxis(35, v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.NonhomogeneousInverse(fm);
            m  = Mat3.NonhomogeneousInvert(m);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
        }
Exemple #5
0
        internal void Setup(int lvl, Bio caster, float distance)
        {
            this.skills[0].ApplyLevel(lvl);

            LFoxFireIdle idleAction = this.fsm[FSMStateType.Idle].GetAction <LFoxFireIdle>();

            idleAction.caster     = caster;
            idleAction.distance   = distance;
            idleAction.angleSpeed = Quat.Euler(0f, this.battle.random.NextFloat(this.angleSpeed, this.angleSpeed2), 0f);

            this._caster = caster;
            this._caster.AddRef();
        }
Exemple #6
0
        public void Matrix4()
        {
            FMat4 fm  = FMat4.FromQuaternion(FQuat.Euler(( Fix64 )30, ( Fix64 )(-20), ( Fix64 )49.342f));
            Mat4  m   = Mat4.FromQuaternion(Quat.Euler(30, -20, 49.342f));
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(4, 6, 9);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(4, 6, 9);

            fv  = fm.TransformPoint(fv);
            fv2 = fm.TransformVector(fv2);
            v   = m.TransformPoint(v);
            v2  = m.TransformVector(v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(fv2.ToString());
            this._output.WriteLine(v.ToString());
            this._output.WriteLine(v2.ToString());
            fm = FMat4.FromEuler(fv);
            m  = Mat4.FromEuler(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat4.FromScale(fv);
            m  = Mat4.FromScale(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat4.FromRotationAxis(( Fix64 )35, fv);
            m  = Mat4.FromRotationAxis(35, v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat4.NonhomogeneousInverse(fm);
            m  = Mat4.NonhomogeneousInvert(m);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat4.FromTRS(new FVec3(4, 5, 6), FQuat.identity, FVec3.one);
            m  = Mat4.FromTRS(new Vec3(4, 5, 6), Quat.identity, Vec3.one);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat4.NonhomogeneousInverse(fm);
            m  = Mat4.NonhomogeneousInvert(m);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fv = fm.TransformPoint(fv);
            v  = m.TransformPoint(v);
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
        }
Exemple #7
0
        public void MTest()
        {
            var m = Mat4.FromTRS(new Vec3(1, -2, 3), Quat.Euler(new Vec3(90, 0, 0)), new Vec3(2, 3, 4));

            this.Log(m.ToString());
            m.Invert();
            this.Log(m);
            this.Log(m.TransformPoint(new Vec3(1, 0, -1)));

            var m2 = Mat4.FromRotationAxis(-43, Vec3.Normalize(new Vec3(3, 2, 4)));

            this.Log(m2);
            var m3 = m2 * m;

            this.Log(m3);


            //var m4 = Mat3.FromOuterProduct( new Vec3( 1, -2, 3 ), new Vec3( 93, 44, 32 ) );
            //var m5 = Mat3.FromCross( new Vec3( 2.5f, 3, 4 ) );
            //var m6 = m4 * m5;
            //m6 = m6.RotateAround( 33, new Vec3( 2, 3, 4 ) );
            //this.Log( m6 );
        }
Exemple #8
0
 public void RotateTowards(Vector3 direction, float rotationValue)
 {
     rotation = Quat.Slerp(Quat.Euler(rotation), Quat.LookRotation(direction), rotationValue).eulerAngles;
 }
Exemple #9
0
        public void Quat4()
        {
            FQuat fq  = FQuat.Euler(( Fix64 )45, ( Fix64 )(-23), ( Fix64 )(-48.88));
            FQuat fq2 = FQuat.Euler(( Fix64 )23, ( Fix64 )(-78), ( Fix64 )(-132.43f));
            Quat  q   = Quat.Euler(45, -23, -48.88f);
            Quat  q2  = Quat.Euler(23, -78, -132.43f);
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(1, 0, 0);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(1, 0, 0);

            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            this._output.WriteLine(fq2.ToString());
            this._output.WriteLine(q2.ToString());
            Fix64 fa = FQuat.Angle(fq, fq2);
            float a  = Quat.Angle(q, q2);

            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.AngleAxis(( Fix64 )(-123.324), fv);
            q  = Quat.AngleAxis(-123.324f, v);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fa = FQuat.Dot(fq, fq2);
            a  = Quat.Dot(q, q2);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.FromToRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.FromToRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Lerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Lerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Normalize(fq);
            q.Normalize();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.Inverse();
            q = Quat.Inverse(q);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fv = FQuat.Orthogonal(fv);
            v  = Quat.Orthogonal(v);
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = FQuat.Slerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Slerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.LookRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.LookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.ToAngleAxis(out fa, out fv);
            q.ToAngleAxis(out a, out v);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = fq.Conjugate();
            q  = q.Conjugate();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.SetLookRotation(FVec3.Normalize(fv), fv2);
            q.SetLookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
        }
Exemple #10
0
        public Quat ComputeRotation(Vector3 direction, float rotationSpeed, float deltaTime)
        {
            var newRot = Quat.Slerp(Quat.Euler(transform.rotation), Quat.LookRotation(direction), Mathf.Clamp(rotationSpeed * deltaTime, 0, 1.3f));

            return(newRot);
        }
Exemple #11
0
        protected Quat ComputeRotation(Vector3 direction, float rotationSpeed, float deltaTime)
        {
            var newRot = (mAlignWithForwardDirection) ? Quat.Slerp(Quat.Euler(transform.rotation), Quat.LookRotation(direction), rotationSpeed * deltaTime) : Quat.Euler(transform.rotation);

            return(newRot);
        }
Exemple #12
0
    // ApplyBoneOrientationConstraints and constrain rotations.
    public void Constrain(ref Matrix4x4[] jointOrientations, ref bool[] jointTracked)
    {
        // Constraints are defined as a vector with respect to the parent bone vector, and a constraint angle,
        // which is the maximum angle with respect to the constraint axis that the bone can move through.

        // Calculate constraint values. 0.0-1.0 means the bone is within the constraint cone. Greater than 1.0 means
        // it lies outside the constraint cone.
        for (int i = 0; i < this.jointConstraints.Count; i++)
        {
            BoneOrientationConstraint jc = this.jointConstraints[i];

            if (!jointTracked[i] || jc.joint == (int)NuiSkeletonPositionIndex.HipCenter)
            {
                // End joint is not tracked or Hip Center has no parent to perform this calculation with.
                continue;
            }

            // If the joint has a parent, constrain the bone direction to be within the constraint cone
            int parentIdx = GetSkeletonJointParent(jc.joint);

            // Local bone orientation relative to parent
            Matrix4x4 localOrientationMatrix = Invert(jointOrientations[parentIdx]) * jointOrientations[jc.joint];

            Vector3 localOrientationZ = (Vector3)localOrientationMatrix.GetColumn(2);
            Vector3 localOrientationY = (Vector3)localOrientationMatrix.GetColumn(1);
            if (localOrientationZ == Vector3.zero || localOrientationY == Vector3.zero)
            {
                continue;
            }

            Quat    localRotation = Quat.LookRotation(localOrientationZ, localOrientationY);
            Vector3 eulerAngles   = localRotation.eulerAngles;
            bool    isConstrained = false;

            //Matrix4x4 globalOrientationMatrix = jointOrientations[jc.joint];
            //Quaternion globalRotation = Quaternion.LookRotation(globalOrientationMatrix.GetColumn(2), globalOrientationMatrix.GetColumn(1));

            for (int a = 0; a < jc.axisConstrainrs.Count; a++)
            {
                AxisOrientationConstraint ac = jc.axisConstrainrs[a];

                Quat axisRotation = Quat.AngleAxis(localRotation.eulerAngles[ac.axis], ac.rotateAround);
                //Quaternion axisRotation = Quaternion.AngleAxis(globalRotation.eulerAngles[ac.axis], ac.rotateAround);
                float angleFromMin = Quat.Angle(axisRotation, quatToQuat2(ac.minQuaternion));
                float angleFromMax = Quat.Angle(axisRotation, quatToQuat2(ac.maxQuaternion));

                if (!(angleFromMin <= ac.angleRange && angleFromMax <= ac.angleRange))
                {
                    // Keep the current rotations around other axes and only
                    // correct the axis that has fallen out of range.
                    //Vector3 euler = globalRotation.eulerAngles;

                    if (angleFromMin > angleFromMax)
                    {
                        eulerAngles[ac.axis] = ac.angleMax;
                    }
                    else
                    {
                        eulerAngles[ac.axis] = ac.angleMin;
                    }

                    isConstrained = true;
                }
            }

            if (isConstrained)
            {
                Quat constrainedRotation = Quat.Euler(eulerAngles);

                // Put it back into the bone orientations
                localOrientationMatrix      = Transform(localOrientationMatrix, quatToQuat(constrainedRotation));
                jointOrientations[jc.joint] = jointOrientations[parentIdx] * localOrientationMatrix;
                //globalOrientationMatrix.SetTRS(Vector3.zero, constrainedRotation, Vector3.one);
                //jointOrientations[jc.joint] = globalOrientationMatrix;

                switch (jc.joint)
                {
                case (int)NuiSkeletonPositionIndex.ShoulderCenter:
                    jointOrientations[(int)NuiSkeletonPositionIndex.Head] = jointOrientations[jc.joint];
                    break;

                case (int)NuiSkeletonPositionIndex.WristLeft:
                    jointOrientations[(int)NuiSkeletonPositionIndex.HandLeft] = jointOrientations[jc.joint];
                    break;

                case (int)NuiSkeletonPositionIndex.WristRight:
                    jointOrientations[(int)NuiSkeletonPositionIndex.HandRight] = jointOrientations[jc.joint];
                    break;

                case (int)NuiSkeletonPositionIndex.AnkleLeft:
                    jointOrientations[(int)NuiSkeletonPositionIndex.FootLeft] = jointOrientations[jc.joint];
                    break;

                case (int)NuiSkeletonPositionIndex.AnkleRight:
                    jointOrientations[(int)NuiSkeletonPositionIndex.FootRight] = jointOrientations[jc.joint];
                    break;
                }
            }

//			globalRotation = Quaternion.LookRotation(globalOrientationMatrix.GetColumn(2), globalOrientationMatrix.GetColumn(1));
//			string stringToDebug = string.Format("{0}, {2}", (KinectWrapper.NuiSkeletonPositionIndex)jc.joint,
//				globalRotation.eulerAngles, localRotation.eulerAngles);
//			Debug.Log(stringToDebug);
//
//			if(debugText != null)
//				debugText.guiText.text = stringToDebug;
        }
    }