Example #1
0
    // Update is called once per frame
    void Update()
    {
        Quaternion R = Quaternion.Euler(angle);

        transform.rotation = R;
        GetComponent <myTransformation>().Rotation = new MyVector3(angle);
        Quaternion t = new Quaternion(q.x, q.y, q.z, q.w);

        UnityRotation          = transform.rotation;
        UnityTargetOrientation = t * UnityRotation;
        UnityEulerAngle        = UnityTargetOrientation.eulerAngles;
        transform.rotation     = UnityTargetOrientation;
        UnityNewRotation       = transform.rotation;
        UnityNewEulerAngle     = UnityNewRotation.eulerAngles;
        transform.rotation     = UnityRotation;



        Rotation          = GetComponent <myTransformation>().GetRotation();
        TargetOrientation = q * Rotation;
        myTransformation Temp = GetComponent <myTransformation>();

        EulerAngle = Quat.QuatToEuler(TargetOrientation);
        Temp.SetRotation(TargetOrientation);

        NewRotation   = Temp.GetRotation();
        NewEulerAngle = Quat.QuatToEuler(NewRotation);
        GetComponent <myTransformation>().Rotation = new MyVector3(angle);
    }
    // Update is called once per frame
    void Update()
    {
        Angle += Time.deltaTime * 2;
        q      = new Quat(Angle, Axis);
        myTransformation Transformation = GetComponent <myTransformation>();

        Transformation.SetRotation(q);
    }
Example #3
0
    void FixedUpdate()
    {
        Collided       = false;                             //Set collided to false
        Transformation = GetComponent <myTransformation>(); //Get transformation component of object
        if (Transformation.Translation.y < -50)
        {
            Transformation.Translation.y = 50; //If object has fallen through level reset that object
        }
        if (PhysicObjectHandler != null)
        {
            Gravity = PhysicObjectHandler.Gravity; //Set gravity to be handler gravity (Singleton)
        }
        if (Dynamic == true || Bouncy == true)
        {
            WeightForce  = Force + (Gravity * Mass); //set weight force to be force + gravtiy * mass
            Force       += Gravity * Mass;           //Increase force by gravity * mass
            Acceleration = Force / Mass;             //Set Acceleration to be force / mass


            Velocity           += Acceleration * Time.fixedDeltaTime;        //Increase velocity by acceleration * fixed delta time
            Force               = new MyVector3(0, 0, 0);                    //sets force to 0 otherwise a force will constantly be applied ot the object
            AngularAcceleration = torque / Inertia;                          //set rotational acceleration to be torque / intertia
            AngularVelocity    += AngularAcceleration * Time.fixedDeltaTime; //Increase angular velocity by angular acceleration * fixed delta time
            torque              = new MyVector3(0, 0, 0);                    //Set torque to 0 otherwise object will always rotate
        }

        if (PhysicObjectHandler != null)
        {
            for (int i = 0; i < PhysicObjectHandler.PhysicHandle.Count; i++)
            {
                if (ObjectId != PhysicObjectHandler.PhysicHandle[i].ObjectId)
                {
                    if (Transformation.BoundObject.Intersects(PhysicObjectHandler.PhysicHandle[i].Transformation.BoundObject))
                    {
                        Collided = true;                                                                                                                      //Set collided to true
                        Transformation.BoundObject.CollisionResolution(PhysicObjectHandler.PhysicHandle[i].Transformation.BoundObject, out Normal, out Push); //Get collision resoloutiuon data from the collision
                        if (Bouncy == true)
                        {
                            Transformation.Translation += Normal * (Push + 0.0000001639f);          //Push the object by normal * (Push + 0.0000001639f) this stops to object getting stuck on terrain

                            Velocity = new MyVector3(-Velocity.x, -Velocity.y, -Velocity.z) * 0.9f; //Inverse velocity and times it by 0.9
                        }
                        if (Dynamic == true)
                        {
                            Transformation.Translation += Normal * (Push + 0.0000001639f); //Push the object by normal * (Push + 0.0000001639f) this stops to object getting stuck on terrain
                            Velocity = new MyVector3(0, 0, 0);                             //Set velocity to be 0
                        }
                    }
                }
            }
        }
        Transformation.Translation += Velocity * Time.deltaTime; //Increase translation by velocity * delta time



        if (player == false)
        {
            Quat  q     = new Quat();                                                       //Create Q
            float avMag = (AngularVelocity * Time.fixedDeltaTime).Length();                 //set av mg to be the length of  angular velocity * fixed time
            q.w = Mathf.Cos(avMag / 2);                                                     //set w to be Cos of av mag /2
            q.x = Mathf.Sin(avMag / 2) * (AngularVelocity * Time.fixedDeltaTime).x / avMag; //set x to be sin of av mag / 2  * angular velocity x * fixed time / avg mag
            q.y = Mathf.Sin(avMag / 2) * (AngularVelocity * Time.fixedDeltaTime).y / avMag; //set y to be sin of av mag / 2  * angular velocity y * fixed time / avg mag
            q.z = Mathf.Sin(avMag / 2) * (AngularVelocity * Time.fixedDeltaTime).z / avMag; //set z to be sin of av mag / 2  * angular velocity z * fixed time / avg mag
            Quat TargetOrienation = q * Transformation.GetRotation();                       //Multiply new rotation by current rotation of object

            Transformation.SetRotation(TargetOrienation);                                   //Set rotation of object to new rotation
            AngularVelocity *= (Time.deltaTime * 2);                                        //Multiply Angular Velocity by Delta time * 2
        }
    }