Ejemplo n.º 1
0
        public void TestTransformRotateAroundAxis(float angle, float x, float y, float z)
        {
            _Transform _t = _Transform.RotateAroundAxis(angle, new _float4(x, y, z, 0.0f));
            Transform  t  = Transform.Rotate(angle, new float4(x, y, z));

            Assert.AreEqual(_t[0][0], t[0][0]);
            Assert.AreEqual(_t[1][0], t[1][0]);
            Assert.AreEqual(_t[2][0], t[2][0]);
            Assert.AreEqual(_t[3][0], t[3][0]);

            Assert.AreEqual(_t[0][1], t[0][1]);
            Assert.AreEqual(_t[1][1], t[1][1]);
            Assert.AreEqual(_t[2][1], t[2][1]);
            Assert.AreEqual(_t[3][1], t[3][1]);

            Assert.AreEqual(_t[0][2], t[0][2]);
            Assert.AreEqual(_t[1][2], t[1][2]);
            Assert.AreEqual(_t[2][2], t[2][2]);
            Assert.AreEqual(_t[3][2], t[3][2]);

            Assert.AreEqual(_t[0][3], t[0][3]);
            Assert.AreEqual(_t[1][3], t[1][3]);
            Assert.AreEqual(_t[2][3], t[2][3]);
            Assert.AreEqual(_t[3][3], t[3][3]);

            PrintTransform(_t);
            Console.WriteLine("---");
            PrintTransform((_Transform)t);
        }
Ejemplo n.º 2
0
        unsafe public void TestTransformInverse(float a, float b, float c, float d)
        {
            _Transform _f4 = new _Transform(a, b, c, d, a, b, c, d, a, b, c, d, a, b, c, d);

            byte *addr = (byte *)&_f4;

            Console.WriteLine("Size:      {0}", sizeof(_Transform));
            Console.WriteLine("x Offset: {0}", (byte *)&_f4.x.x - addr);
            Console.WriteLine("y Offset: {0}", (byte *)&_f4.y.x - addr);
            Console.WriteLine("z Offset: {0}", (byte *)&_f4.z.x - addr);
            Console.WriteLine("w Offset: {0}", (byte *)&_f4.w.x - addr);

            Console.WriteLine("x.x:      {0}", _f4.x.x);
            Console.WriteLine("x.y:      {0}", _f4.x.y);
            Console.WriteLine("x.z:      {0}", _f4.x.z);
            Console.WriteLine("x.w:      {0}", _f4.x.w);


            _Transform _f4inv = _Transform.Inverse(_f4);

            Console.WriteLine("x.x:      {0}", _f4inv.x.x);
            Console.WriteLine("x.y:      {0}", _f4inv.x.y);
            Console.WriteLine("x.z:      {0}", _f4inv.x.z);
            Console.WriteLine("x.w:      {0}", _f4inv.x.w);
        }
Ejemplo n.º 3
0
 private void PrintTransform(_Transform xfm)
 {
     Console.WriteLine(" {0} {1} {2} {3}", xfm[0][0], xfm[0][1], xfm[0][2], xfm[0][3]);
     Console.WriteLine(" {0} {1} {2} {3}", xfm[1][0], xfm[1][1], xfm[1][2], xfm[1][3]);
     Console.WriteLine(" {0} {1} {2} {3}", xfm[2][0], xfm[2][1], xfm[2][2], xfm[2][3]);
     Console.WriteLine(" {0} {1} {2} {3}", xfm[3][0], xfm[3][1], xfm[3][2], xfm[3][3]);
 }
Ejemplo n.º 4
0
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* ----------------------------- SPECIAL RABBIT ACTION FUNCTIONS ------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    protected IEnumerator JumpTo(Cell c, _Transform from, Quaternion look, Vector3 up, float omega)
    {
        // declaration
        Vector3 to;
        float   step, height;

        // initialization
        to   = c.position;
        step = 0f;

        // reserve new cell
        this.entity.cellable.ReserveNextCell(c);

        // move to new cell
        while (step < 1f)
        {
            step  += this.rabbit.rabbitData.speed * Time.deltaTime;
            height = Mathf.PingPong(Mathf.Min(step * this.jumpHeight * 2f, this.jumpHeight * 2f), this.jumpHeight);

            // movement
            this.entity.myTransform.rotation = Quaternion.Slerp(from.rotation, look, step * omega);
            this.entity.myTransform.position = Vector3.Lerp(from.position, to, step) + up * height;

            yield return(null);
        }

        // reach new cell
        this.entity.myTransform.SetPositionAndRotation(to, look);
        this.entity.cellable.UpdateCurrentCell();
    }
Ejemplo n.º 5
0
    private void Start()
    {
        this.myRigidbody.rotation = this.transform.AbsoluteRotation();
        this.targetPosition       = this.cellable.currentCell.position + (this.cellable.currentCell.normal * 0.5f);

        this.heart = HeartManager.instance.heart;
        // this.heart.rotation = Quaternion.LookRotation(this.myRigidbody.rotation * Vector3.up);

        this.StartSnakeMovement();
    }
Ejemplo n.º 6
0
        private IEnumerator SmoothRotationCoroutine(_Transform previous, _Transform current, Quaternion targetRotation, bool locked)
        {
            Vector3    lookUp, targetRight;
            Vector3    tgtp;
            Quaternion tgtr;
            int        rightDot, forwardDot;
            float      previousAngle, angle;


            targetRight = this.target.rotation * Vector3.right;
            rightDot    = Mathf.RoundToInt(Vector3.Dot(targetRight, current.right));
            forwardDot  = Mathf.RoundToInt(Vector3.Dot(previous.up, -rightDot * current.forward));
            lookUp      = current.forward + rightDot * forwardDot * current.up;

            // Camera smoothly reaches 'lookat' rotation
            do
            {
                tgtp = this.GetTargetLockAxis(previous, rightDot, locked);
                tgtr = Quaternion.LookRotation(tgtp - this.myTransform.position, lookUp);
                this.myTransform.rotation = Quaternion.Slerp(this.myTransform.rotation, tgtr, SMOOTH_TRANSITION * Time.deltaTime);
                angle = Quaternion.Angle(this.myTransform.rotation, tgtr);

                yield return(null);
            }while(angle > 1f);

            // Camera looks at target until nearly reaches target rotation
            do
            {
                tgtp = this.GetTargetLockAxis(previous, rightDot, locked);
                this.myTransform.LookAt(tgtp, lookUp);
                angle = Quaternion.Angle(this.myTransform.rotation, targetRotation);

                yield return(null);
            }while(angle > 10f);

            // Camera continues to look at target until it reaches best angle possible
            do
            {
                tgtp = this.GetTargetLockAxis(previous, rightDot, locked);
                this.myTransform.LookAt(tgtp, lookUp);
                previousAngle = angle;
                angle         = Quaternion.Angle(this.myTransform.rotation, targetRotation);

                yield return(null);
            }while(previousAngle > angle);

            // Camera finishes its rotation to match heart rotation
            while (Quaternion.Angle(this.myTransform.rotation, targetRotation) > 0.1f)
            {
                this.myTransform.rotation = Quaternion.Slerp(this.myTransform.rotation, targetRotation, SMOOTH_OMEGA * Time.deltaTime);
                yield return(null);
            }

            this.myTransform.rotation = targetRotation;
        }
Ejemplo n.º 7
0
        /* -------------------------------------------------------------------------------------------*/
        /* -------------------------------------------------------------------------------------------*/
        /* -------------------------------------------------------------------------------------------*/
        /* ----------------------------------- ROTATION FUNCTIONS ------------------------------------*/
        /* -------------------------------------------------------------------------------------------*/
        /* -------------------------------------------------------------------------------------------*/
        /* -------------------------------------------------------------------------------------------*/
        private void OnHeartRotate(_Transform previous, _Transform current)
        {
            Quaternion targetRotation;
            float      angle;
            bool       locked;

            this.TryStopCoroutine(ref this.smoothRotationCoroutine);

            angle               = Quaternion.Angle(this.myTransform.rotation, this.previousTarget);
            locked              = (angle < SMOOTH_LOCK_THRESHOLD);
            targetRotation      = current.rotation * Quaternion.Euler(90, 0, 0);
            this.previousTarget = targetRotation;
            this.StartAndStopCoroutine(ref this.smoothRotationCoroutine, this.SmoothRotationCoroutine(previous, current, targetRotation, locked));
        }
Ejemplo n.º 8
0
        public void TestTransformLookAt(float px, float py, float pz, float lx, float ly, float lz, float ux, float uy, float uz)
        {
            _float4 pos = new _float4 {
                x = px, y = py, z = pz, w = 0.0f
            };
            _float4 look = new _float4 {
                x = lx, y = ly, z = lz, w = 0.0f
            };
            _float4 up = new _float4 {
                x = ux, y = uy, z = uz, w = 0.0f
            };

            _Transform laxfm = _Transform.LookAt(pos, look, up);

            PrintTransform(laxfm);
        }
Ejemplo n.º 9
0
        private Vector3 GetTargetLockAxis(_Transform previous, int dot, bool locked)
        {
            if (!locked)
            {
                return(this.target.position);
            }

            Vector3 tgtp = this.target.position;

            // dot == 0 -> heart rotate around its z axis
            // dot != 0 -> heart rotate around its x axis

            // We use old heart rotation for calculs as nex heart rotation miss some informations

            if (dot == 0)
            {
                if (Mathf.RoundToInt(Vector3.Dot(previous.forward, Vector3.right)) != 0)
                {
                    tgtp.Set(this.myTransform.position.x, tgtp.y, tgtp.z);
                }
                else if (Mathf.RoundToInt(Vector3.Dot(previous.forward, Vector3.up)) != 0)
                {
                    tgtp.Set(tgtp.x, this.myTransform.position.y, tgtp.z);
                }
                else
                {
                    tgtp.Set(tgtp.x, tgtp.y, this.myTransform.position.z);
                }
            }
            else
            {
                if (Mathf.RoundToInt(Vector3.Dot(previous.right, Vector3.right)) != 0)
                {
                    tgtp.Set(this.myTransform.position.x, tgtp.y, tgtp.z);
                }
                else if (Mathf.RoundToInt(Vector3.Dot(previous.right, Vector3.up)) != 0)
                {
                    tgtp.Set(tgtp.x, this.myTransform.position.y, tgtp.z);
                }
                else
                {
                    tgtp.Set(tgtp.x, tgtp.y, this.myTransform.position.z);
                }
            }

            return(tgtp);
        }
Ejemplo n.º 10
0
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* -------------------------- BASIC MOVEMENT CONTROLLER OVERRIDINGS ---------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    /* --------------------------------------------------------------------------------------------*/
    protected virtual IEnumerator StepOverFace(StepOver stepover)
    {
        // declaration
        _Transform from;

        // check
        if (this.entity.cellable.currentCell.isInner)
        {
            yield break;
        }

        // initialization
        from = new _Transform(this.entity.myTransform);

        // jump
        yield return(this.JumpTo(stepover.cell, from, stepover.rotation, stepover.up, ROTATION_OVER_FACE_SPEED));
    }
Ejemplo n.º 11
0
    protected virtual IEnumerator StepTowards(Cell c)
    {
        // declaration
        _Transform from;
        Quaternion look;

        // check
        if (this.TargetIsTooFarAway(c, this.rabbit.rabbitData.maxStepDistance))
        {
            yield break;
        }

        // initialization
        from = new _Transform(this.entity.myTransform);
        look = Quaternion.LookRotation(c.position - this.entity.cellable.currentCell.position, entity.myTransform.up).SetAbsoluteRotation();

        // jump
        yield return(this.JumpTo(c, from, look, this.entity.myTransform.up, ROTATION_SPEED));
    }
Ejemplo n.º 12
0
 public void Invoke(_Transform value)
 {
     this.Invoke();
     this._transformEvent?.Invoke(value);
 }