Ejemplo n.º 1
0
        void GrabLeft()
        {
            leftGrabbing       = true;
            world_GrabLoc_left = controller_left.transform.position;

            if (rightGrabbing)
            {
                controller.Set((world_GrabLoc_left + world_GrabLoc_right) * 0.5f, Quaternion.identity, Vector3.one);
                world_grab_vec = world_GrabLoc_left - world_GrabLoc_right;
                if (dolly_mode)
                {
                    world_grab_vec.y = 0f;
                }
                world_grab_vec_len = world_grab_vec.magnitude;
            }
            else
            {
                controller.Set(world_GrabLoc_left, controller_left.transform.rotation, Vector3.one);
                if (dolly_mode)
                {
                    controller.localRotation = Quaternion.FromToRotation(controller.localRotation * Vector3.up, Vector3.up) * controller.localRotation;
                }
            }
            // Set world origin as child of controller
            child.Clear();
            TransformXtra.SiblingToChild(child, controller);
        }
Ejemplo n.º 2
0
 public void Regrab(Selector selector)
 {
     SetCursor(selector);
     // Lossy scale is correct if object is not skewed by a rotation up the tree.
     obj_world.Set(transform.position, transform.rotation, transform.lossyScale);
     obj_child.Set(obj_world);
     obj_child.TransformUp(cursor);
 }
Ejemplo n.º 3
0
        // Set cursorSrt to the cursor model in camaraRig space.
        private void SetLocalCursor()
        {
            if (leftGrabbing && rightGrabbing)
            {
                Vector3 tempVec2 = (selectorLeft.transform.localPosition + selectorRight.transform.localPosition) * 0.5f;

                cursorSrt.localPosition = tempVec2;

                Vector3 tempVec = selectorLeft.transform.localPosition - selectorRight.transform.localPosition;
                cursorSrt.localRotation = Quaternion.LookRotation(tempVec, Vector3.up);

                if (scaleLock == false)
                {
                    float currentDistance = Vector3.Distance(selectorLeft.transform.localPosition, selectorRight.transform.localPosition);

                    float scaletemp = currentDistance / initialDistance;
                    // Vector3 tempVec3 = new Vector3(scaletemp, scaletemp, scaletemp);
                    cursorSrt.localScale = Vector3.one * scaletemp;
                }
                else
                {
                    cursorSrt.localScale = Vector3.one;
                }
            }
            else if (leftGrabbing)
            {
                cursorSrt.Set(selectorLeft.transform.GetLocalSrt());
            }
            else if (rightGrabbing)
            {
                cursorSrt.Set(selectorRight.transform.GetLocalSrt());
            }

            if (dollyMode == true)
            {
                Vector3    wonkylocal = cursorSrt.localRotation * Vector3.up;
                Quaternion DQ         = Quaternion.FromToRotation(wonkylocal, Vector3.up);
                // Vector3 fixedVec = DQ * wonkylocal;
                cursorSrt.localRotation = Quaternion.FromToRotation(wonkylocal, Vector3.up) * cursorSrt.localRotation;
            }
        }
Ejemplo n.º 4
0
    private void SetControllerSrt()
    {
        if (isLeftGripped && !isRightGripped)
        {
            controllerSrt.Set(leftController.transform.localPosition, leftController.transform.localRotation, leftController.transform.localScale);
        }
        else if (isRightGripped && !isLeftGripped)
        {
            controllerSrt.Set(rightController.transform.localPosition, rightController.transform.localRotation, rightController.transform.localScale);
        }
        // two controller
        else
        {
            // position
            Vector3 leftControllerPos  = leftController.transform.localPosition;
            Vector3 rightControllerPos = rightController.transform.localPosition;
            Vector3 averagePos         = (leftControllerPos + rightControllerPos) / 2;


            //rotation
            Quaternion currentRotation = Quaternion.FromToRotation(InitialVector, leftControllerPos - rightControllerPos);


            // scale
            Vector3 currentScaleVec = Vector3.one;
            if (AllowScale)
            {
                if (initialScalelength > 0.00001f)
                {
                    float currentScaleLength = (rightControllerPos - leftControllerPos).magnitude;
                    scaleNum        = currentScaleLength / initialScalelength;
                    currentScaleVec = new Vector3(scaleNum, scaleNum, scaleNum);
                }
            }

            controllerSrt.Set(averagePos, currentRotation, currentScaleVec);
        }
    }
Ejemplo n.º 5
0
 void SetCursor(Selector selector)
 {
     cursor.Set(selector.Cursor);
     if (dolly_mode)
     {
         if (yaw_mode)
         {
             cursor.localRotation = Quaternion.identity;
         }
         else
         {
             cursor.localRotation = Quaternion.FromToRotation(cursor.localRotation * Vector3.up, Vector3.up) * cursor.localRotation;
         }
     }
 }
Ejemplo n.º 6
0
 private void SetWorldOffsetSrt()
 {
     cameraRigSrt.Set(transform.position, transform.rotation, transform.localScale);
     worldOffsetSrt = controllerSrt.Inverse() * cameraRigSrt.Inverse();
 }
Ejemplo n.º 7
0
        public override void DoGrab(Selector selector, bool state)
        {
            base.DoGrab(selector, state);

            if (state)
            {
                if (grabbing_selector == null)
                {
                    Rigidbody body = GetComponent <Rigidbody>();
                    if (body != null)
                    {
//#if USE_VELOCITY
                        save_useGravity = body.useGravity;
                        body.useGravity = false;
//#else
//                        save_drag = body.drag;
//                        save_angdrag = body.angularDrag;

//                        save_useGravity = body.useGravity;
//                        body.useGravity = true;
//#endif
                        save_isKinematic = body.isKinematic;
                        body.isKinematic = false;
                    }

                    //#if USE_VELOCITY
                    RotationMover mover = gameObject.GetComponent <RotationMover>();
                    if (mover)
                    {
                        Destroy(mover);
                    }
                    //#endif

                    Regrab(selector);

                    grab_loc.Set(cursor);
                    grab_loc.TransformUp(obj_world);

                    grabbing_selector = selector;

                    //grab_evt.Invoke();
                }
            }
            else
            {
                if (grabbing_selector == selector)
                {
                    Rigidbody body = GetComponent <Rigidbody>();
                    if (body != null)
                    {
                        body.useGravity = save_useGravity;

                        body.velocity        = (save_isKinematic) ? Vector3.zero : selector.GetVelocity();
                        body.angularVelocity = (save_isKinematic || dolly_mode) ? Vector3.zero : selector.GetAngularVelocity();
                        //body.angularVelocity = Vector3.zero;

//#if USE_VELOCITY
                        if (dolly_mode && gameObject.GetComponent <RotationMover>() == null)
                        {
                            RotationMover mover = gameObject.AddComponent <RotationMover>();
                            mover.Set(yaw_mode, save_isKinematic);
                        }
                        else
                        {
                            body.isKinematic = save_isKinematic;
                        }
//#else
//                        body.isKinematic = save_isKinematic;
//                        body.drag = save_drag;
//                        body.angularDrag = save_angdrag;
//#endif
                    }

                    grabbing_selector = null;
                    //release_evt.Invoke();
                }
            }
        }