Ejemplo n.º 1
0
    void Update()
    {
        bool didTouch = false;
        // get all the touches, see if one hits me
        int i;

        for (i = 0; i < iPhoneInput.touchCount; i++)
        {
            iPhoneTouch touch = iPhoneInput.GetTouch(i);
            Vector3     pos   = new Vector3(touch.position.x, touch.position.y, 0.0f);
            if (GetComponent <GUIText>() != null)
            {
                if (GetComponent <GUIText>().HitTest(pos))
                {
                    didTouch = true;
                    this.doTouchDown();
                }
            }
            else
            {
                if (GetComponent <GUITexture>().HitTest(pos))
                {
                    didTouch = true;
                    this.doTouchDown();
                }
            }
        }
        if (!didTouch && touchDown)
        {
            doTouchUp();
        }
    }
Ejemplo n.º 2
0
    // we go through each touch input and place a crosshair at it's position.
    // we save a list of crosshairs and deactivate them when they are not
    // being used.
    void Update()
    {
        int crosshairIndex = 0;
        int i;

        for (i = 0; i < iPhoneInput.touchCount; i++)
        {
            if (crosshairs.Count <= crosshairIndex)
            {
                // make a new crosshair and cache it
                GameObject newCrosshair = (GameObject)Instantiate(crosshairPrefab, Vector3.zero, Quaternion.identity);
                crosshairs.Add(newCrosshair);
            }
            iPhoneTouch touch          = iPhoneInput.GetTouch(i);
            Vector3     screenPosition = new Vector3(touch.position.x, touch.position.y, 0.0f);
            GameObject  thisCrosshair  = (GameObject)crosshairs[crosshairIndex];
            thisCrosshair.SetActiveRecursively(true);
            thisCrosshair.transform.position = renderingCamera.ScreenToViewportPoint(screenPosition);
            crosshairIndex++;
        }

        // if there are any extra ones, then shut them off
        for (i = crosshairIndex; i < crosshairs.Count; i++)
        {
            GameObject thisCrosshair = (GameObject)crosshairs[i];
            thisCrosshair.SetActiveRecursively(false);
        }
    }
Ejemplo n.º 3
0
    public iPhoneTouch touchWithEvent(BBTouchEvent anEvent)
    {
        iPhoneTouch newTouch = new iPhoneTouch();

        newTouch.fingerId        = (int)anEvent.eventID;
        newTouch.position.x      = anEvent.screenPosition.x;
        newTouch.position.y      = anEvent.screenPosition.y;
        newTouch.deltaPosition.x = anEvent.screenPosition.x - anEvent.lastScreenPosition.x;
        newTouch.deltaPosition.y = anEvent.screenPosition.y - anEvent.lastScreenPosition.y;
        newTouch.deltaTime       = anEvent.touchTime - anEvent.lastTouchTime;
        newTouch.tapCount        = 1;  // no tap recog yet
        if (anEvent.eventState == BBTouchEventState.Began)
        {
            newTouch.phase = iPhoneTouchPhase.Began;
        }
        if (anEvent.eventState == BBTouchEventState.Moved)
        {
            newTouch.phase = iPhoneTouchPhase.Moved;
        }
        if (anEvent.eventState == BBTouchEventState.Stationary)
        {
            newTouch.phase = iPhoneTouchPhase.Stationary;
        }
        if (anEvent.eventState == BBTouchEventState.Ended)
        {
            newTouch.phase = iPhoneTouchPhase.Ended;
        }
        return(newTouch);
    }
Ejemplo n.º 4
0
    public void Update(iPhoneTouch touch)
    {
        this.touch = touch;
        isDirty = true;

        // do something with the game object
        // go.charmander()
    }
Ejemplo n.º 5
0
    public TouchTracker BeginTracking(iPhoneTouch touch)
    {
        TouchTracker tracker = new TouchTracker(touch);
        trackers.Add(tracker);
        trackerLookup[touch.fingerId] = tracker;

        return tracker;
    }
Ejemplo n.º 6
0
    public TouchTracker(iPhoneTouch touch)
    {
        fingerId = touch.fingerId;
        firstTouch = touch;

        Begin ();
        Update (firstTouch);
    }
Ejemplo n.º 7
0
 public override void handleSingleTouch(iPhoneTouch aTouch)
 {
     if (touchDown)
     {
         return;
     }
     notificationObject.SendMessage(touchDownMessage, SendMessageOptions.DontRequireReceiver);
     touchDown = true;
 }
    public Vector3 touchMovementVector(iPhoneTouch touch)
    {
        float zDistanceFromCamera = Vector3.Distance(renderingCamera.transform.position, gameObject.transform.position);

        Vector3 screenPosition     = new Vector3(touch.position.x, touch.position.y, zDistanceFromCamera);
        Vector3 lastScreenPosition = new Vector3(touch.position.x - touch.deltaPosition.x, touch.position.y - touch.deltaPosition.y, zDistanceFromCamera);

        Vector3 cameraWorldPosition     = this.renderingCamera.ScreenToWorldPoint(screenPosition);
        Vector3 lastCameraWorldPosition = this.renderingCamera.ScreenToWorldPoint(lastScreenPosition);

        return(cameraWorldPosition - lastCameraWorldPosition);
    }
Ejemplo n.º 9
0
 public override void handleSingleTouch(iPhoneTouch touch)
 {
     //Rotate
     if (!allowRotate)
     {
         return;
     }
     //Set startPivot on object (with current transform position), and start rotating around according to x and y axis.
     this.startPivot(gameObject.transform.position);
     pivot.transform.RotateAround(gameObject.transform.position, new Vector3(0, 1, 0), -touch.deltaPosition.x * speed);
     pivot.transform.RotateAround(gameObject.transform.position, new Vector3(1, 0, 0), touch.deltaPosition.y * speed);
     this.endPivot();
 }
Ejemplo n.º 10
0
    void Update()
    {
        // Make sure the user touched the screen
        if (iPhoneInput.touchCount==0){
            return;
        }

        Camera mainCamera = FindCamera();

        // We need to actually hit an object
        RaycastHit hit = new RaycastHit();

        touch = iPhoneInput.GetTouch(0);

        if(touch.phase == iPhoneTouchPhase.Began){

            if (!Physics.Raycast(mainCamera.ScreenPointToRay(touch.position),  out hit, 10000))
                    return;

            // We need to hit a rigidbody that is not kinematic
            if (!hit.rigidbody || hit.rigidbody.isKinematic)
                return;

            if (!springJoint){
                GameObject go = new GameObject("Rigidbody dragger");

                //Rigidbody is automatically added by SpringJoint

                springJoint = (SpringJoint)go.AddComponent ("SpringJoint");
                go.rigidbody.isKinematic = true;
            }

            springJoint.transform.position = hit.point;

            if (attachToCenterOfMass){
                Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
                anchor = springJoint.transform.InverseTransformPoint(anchor);
                springJoint.anchor = anchor;
            }else{
                springJoint.anchor = Vector3.zero;
            }

            springJoint.spring = spring;
            springJoint.damper = damper;
            springJoint.maxDistance = distance;
            springJoint.connectedBody = hit.rigidbody;

            StartCoroutine("DragObject", hit.distance);
        }
    }
    public override void handleSingleTouch(iPhoneTouch touch)
    {
        if (!allowDrag)
        {
            return;
        }
        // // we want to drag our object

        movement = touchMovementVector(touch);
//		if (movement.sqrMagnitude > 0.01) {
        this.startPivot(gameObject.transform.position);
        pivot.transform.Translate(movement, Space.World);
        this.endPivot();
//		}
    }
Ejemplo n.º 12
0
 public iPhoneTouch touchWithEvent(BBTouchEvent anEvent)
 {
     iPhoneTouch newTouch = new iPhoneTouch();
     newTouch.fingerId = (int)anEvent.eventID;
     newTouch.position.x = anEvent.screenPosition.x;
     newTouch.position.y = anEvent.screenPosition.y;
     newTouch.deltaPosition.x = anEvent.screenPosition.x - anEvent.lastScreenPosition.x;
     newTouch.deltaPosition.y = anEvent.screenPosition.y - anEvent.lastScreenPosition.y;
     newTouch.deltaTime = anEvent.touchTime - anEvent.lastTouchTime;
     newTouch.tapCount = 1; // no tap recog yet
     if (anEvent.eventState == BBTouchEventState.Began) newTouch.phase = iPhoneTouchPhase.Began;
     if (anEvent.eventState == BBTouchEventState.Moved) newTouch.phase = iPhoneTouchPhase.Moved;
     if (anEvent.eventState == BBTouchEventState.Stationary) newTouch.phase = iPhoneTouchPhase.Stationary;
     if (anEvent.eventState == BBTouchEventState.Ended) newTouch.phase = iPhoneTouchPhase.Ended;
     return newTouch;
 }
Ejemplo n.º 13
0
    public override void handleManyTouches(ArrayList events)
    {
        Vector3 movement = new Vector3(0, 0, 0);
        int     count    = 0;

        if (!allowDrag)
        {
            return;
        }
        for (int i = 0; i < iPhoneInput.touchCount; i++)
        {
            if (iPhoneInput.touchCount > i && iPhoneInput.touchCount < 20 && iPhoneInput.GetTouch(i) != null)
            {
                iPhoneTouch touch = iPhoneInput.GetTouch(i);
                movement += touchMovementVector(touch);
                count++;
            }
        }
        //GameObject outofbounds;
        //iPhoneTouch touch1 = (iPhoneTouch)events[1];

        /*if (touch0.fingerId > touch1.fingerId) {
         *      // flip them, 0 should be the earlier index
         *      touch0 = (iPhoneTouch)events[1];
         *      touch1 = (iPhoneTouch)events[0];
         * }*/
        //Vector3 test = collider.bounds.max;
        //if (movement.sqrMagnitude > 0.01){
        //	&& collider.bounds.center.x/collider.bounds.size.x<0.4 && collider.bounds.center.x/collider.bounds.size.x>0.1)

        this.startPivot(gameObject.transform.position);

        //Camera.main.transform.Translate(movement,Space.World);
        //Vector3 angle = renderingCamera.WorldToScreenPoint(pivot.transform.position);

//			print(Vector3.Angle((outofbounds.position-renderingCamera.transform.position),renderingCamera.transform.forward));

        pivot.transform.Translate(movement / count, Space.World);
        if (Vector3.Angle((pivot.transform.position - renderingCamera.transform.position), renderingCamera.transform.forward) > 20)
        {
            pivot.transform.Translate(-movement / count, Space.World);
        }

        this.endPivot();
        //}
//		print("new: "+ collider.bounds.max+ " asfd" +(test+movement)+" old: "+test);
    }
Ejemplo n.º 14
0
    // we go through each touch input and place a crosshair at it's position.
    // we save a list of crosshairs and deactivate them when they are not
    // being used.
    void FixedUpdate()
    {
        int crosshairIndex = 0;
        int i;

//		print ("nr touch events: " + iPhoneInput.touchCount);
        for (i = 0; i < iPhoneInput.touchCount; i++)
        {
            if (crosshairs.Count <= crosshairIndex)
            {
                // make a new crosshair and cache it
                GameObject newCrosshair = (GameObject)Instantiate(crosshairPrefab, Vector3.zero, Quaternion.identity);
                newCrosshair.name = crosshairPrefab.name;
                crosshairs.Add(newCrosshair);
//				print ("instanciando manito");
            }
            iPhoneTouch touch          = iPhoneInput.GetTouch(i);
            Vector3     screenPosition = new Vector3(touch.position.x, touch.position.y, 0.0f);
            GameObject  thisCrosshair  = (GameObject)crosshairs[crosshairIndex];
            //thisCrosshair.SetActiveRecursively(true);
            thisCrosshair.GetComponent <CircleCollider2D>().enabled = true;
            thisCrosshair.SetActive(true);
            //thisCrosshair.transform.position = renderingCamera.ScreenToViewportPoint(screenPosition * 4f);
            Vector2 newPosition = Camera.main.ScreenToWorldPoint(new Vector3(screenPosition.x, screenPosition.y, 10f));
//			thisCrosshair.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(screenPosition.x, screenPosition.y, 10f));
//			thisCrosshair.transform.position = new Vector3(thisCrosshair.transform.position .x, thisCrosshair.transform.position .y, -1f);
//			thisCrosshair.GetComponent<Rigidbody2D>().position = Camera.main.ScreenToWorldPoint(new Vector3(screenPosition.x, screenPosition.y, 10f));
            thisCrosshair.GetComponent <Rigidbody2D>().MovePosition(newPosition);
            crosshairIndex++;
        }

        // if there are any extra ones, then shut them off
        for (i = crosshairIndex; i < crosshairs.Count; i++)
        {
            GameObject thisCrosshair = (GameObject)crosshairs[i];
            //thisCrosshair.SetActiveRecursively(false);
            thisCrosshair.GetComponent <CircleCollider2D>().enabled = false;
            thisCrosshair.SetActive(false);
        }
    }
Ejemplo n.º 15
0
    public void checkForTouches()
    {
        // some defensive programming
        // check to make sure that we have a collider and that we found a camera
        if (gameObject.GetComponent <Collider>() == null)
        {
            Debug.Log("Object: " + gameObject.name + " is trying to collect touches but has no collider");
            return;
        }
        if (renderingCamera == null)
        {
            Debug.Log("Object: " + gameObject.name + " cannot find a camera.");
            return;
        }

        // clear out our frame event buffer
        thisFrameEvents.Clear();
        RaycastHit hit = new RaycastHit();         // need one of these to check for hits

        // step through each touch and see if any are hitting me
        int i;

        for (i = 0; i < iPhoneInput.touchCount; i++)
        {
            iPhoneTouch touch          = iPhoneInput.GetTouch(i);
            Vector3     screenPosition = new Vector3(touch.position.x, touch.position.y, 0.0f);

            if (Physics.Raycast(Camera.main.ScreenPointToRay(screenPosition), out hit, Mathf.Infinity))
            {
                // do we have a hit?
                if (hit.transform.gameObject == gameObject)
                {
                    thisFrameEvents.Add(touch);
                }
            }
        }
    }
Ejemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        //Screen touch positions from TUIO
        for (int i = 0; i < iPhoneInput.touchCount; ++i)
        {
            iPhoneTouch touch          = iPhoneInput.GetTouch(i);
            Vector3     screenPosition = new Vector3(touch.position.x, touch.position.y, 0.0f);
            //Debug.Log("Screen position: " + screenPosition);

            //Do Screen to Ray to find where the screen point lies on the frustum window/Touch Surface
            Ray ray = Camera.main.ScreenPointToRay(new Vector3(screenPosition.x, screenPosition.y, 0.0f));
            //Debug.Log(screenPosition.x + ", " +  screenPosition.y);
            Debug.DrawRay(ray.origin, ray.direction * 10, Color.green);

            //Detect if this ray is hitting the HittableObject and send messages with position of the object
            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(ray, out hit, 20))
            {
                if (hit.collider.tag == "Hittable")
                {
                    if (cubeRef != null)
                    {
                        cubeRef.renderer.material.color = Color.red;
                        cubeRef = null;
                    }

                    cubeRef = hit.collider.gameObject;
                    cubeRef.renderer.material.color = Color.green;
                    //Vector3 normalPoint = hit.normal;
                    //Debug.DrawRay(hit.point, hit.normal * 10, Color.yellow);
                    lastHitPoint = hit.point;
                    //Debug.Log(lastHitPoint);

                    if (isHittingObject)
                    {
                        testObject.transform.position = hit.point;
                        //Fire the event and send the hit position
                        if (OnObjectTouched != null)
                        {
                            OnObjectTouched(lastHitPoint);
                        }
                        //Debug.Log("hit world position: " + lastHitPoint);
                    }
                    else
                    {
                        if (OnObjectTouchStart != null)
                        {
                            OnObjectTouchStart(lastHitPoint);
                        }
                        isHittingObject = true;
                        //Debug.Log("Start");
                    }
                }
            }
            else
            {
                if (isHittingObject)
                {
                    raiseObjectTouchStopEvent();
                }
            }
        }

        if (iPhoneInput.touchCount == 0 && isHittingObject)
        {
            raiseObjectTouchStopEvent();
        }
    }
Ejemplo n.º 17
0
    }                                                               // two touches

    virtual public void handleSingleTouch(iPhoneTouch aTouch)
    {
    }                                                                // just one touch
Ejemplo n.º 18
0
    void OnGUI()
    {
        GUI.skin = customskin2;
        Rect windowRect0 = new Rect(0, 0, Screen.width, Screen.height);

        for (int xi = 0; xi < iPhoneInput.touchCount; xi++)
        {
            if (iPhoneInput.touchCount > xi && iPhoneInput.touchCount < 20 && iPhoneInput.GetTouch(xi) != null)
            {
                //When touching set starttime to current time
                //touchTime=Time.time;

                //Get all touches
                iPhoneTouch touch = iPhoneInput.GetTouch(xi);

                Vector3 screenPosition = new Vector3(touch.position.x, touch.position.y, 0.0f);
                // = new RaycastHit(); // need one of these to check for hits
                RaycastHit[] hits;

                if (Physics.Raycast(Camera.main.ScreenPointToRay(screenPosition), Mathf.Infinity))
                {
                    //print("hit");

                    hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(screenPosition), Mathf.Infinity);
                    for (int ii = 0; ii < hits.Length; ii++)
                    {
                        if (hits[0].transform.gameObject.name == "hole")
                        {
                            hits[0].transform.gameObject.renderer.enabled = true;
                            pressTime = Time.time;
                        }
                    }
                    //	print(hits[ii].transform.gameObject.name);
                    //if (hit.transform.gameObject == gameObject)
                }
            }
        }
        //Set GUI style
        //if (Application.isEditor) {
        if (Time.time - pressTime < 2 && Time.time > 5)
        {
            GUI.Box(windowRect0, "En skada i skelettet");
        }
        else if (GameObject.Find("hole") != null)
        {
            GameObject.Find("hole").renderer.enabled = false;
        }

        if (GUI.Button(new Rect(Screen.width / 5 * 2f, Screen.height / 12 * 0.50f, Screen.width / 5 * 1f, Screen.height / 12 * 1.2f), "Utgångsläge"))
        {
        }
        ;
        GUI.Label(new Rect(Screen.width / 5 * 2f, Screen.height / 12 * 0.75f, Screen.width / 5 * 1f, Screen.height / 12 * 1.0f), "Tryck här för startvy!");
        if (GUI.Button(new Rect(Screen.width / 5 * 3.8f, Screen.height / 12 * 0.50f, Screen.width / 5 * 1f, Screen.height / 12 * 1.2f), "Fler modeller"))
        {
        }
        ;
        GUI.Label(new Rect(Screen.width / 5 * 3.8f, Screen.height / 12 * 0.75f, Screen.width / 5 * 1f, Screen.height / 12 * 1.0f), "Välj en annan rekonstruktion!");
        //}
        GUI.skin = customskin;

        //Initialization text
        string startText2 = startText;

        if (Time.time < 3)
        {
            for (int i = 0; i < Time.time; i++)
            {
                startText2 = startText2 + ".";
            }
            GUI.Label(new Rect(0, 0, Screen.width, Screen.height), startText2);
        }

        //Display the universeum and biomnia logo
        GUI.Button(new Rect(Screen.width / 30, Screen.height / 30, Screen.width * 1.2f * 0.1432f, Screen.height * 1.2f * 0.0838f), universeumLogo);
        GUI.Button(new Rect((Screen.width / 30) * 23, Screen.height / 12 * 10.5f, Screen.width * 1.3f * 0.1666f, Screen.height * 1.3f * 0.0837f), biomniaLogo);

        //Display the layer buttons
        GUI.Button(new Rect(Screen.width / 5, Screen.height / 12 * 9.5f, Screen.width / 6, Screen.height / 5), btnTextureskin);
        GUI.Button(new Rect((Screen.width / 5) * 2, Screen.height / 12 * 9.5f, Screen.width / 6, Screen.height / 5), btnTexturelungs);
        GUI.Button(new Rect((Screen.width / 5) * 3, Screen.height / 12 * 9.5f, Screen.width / 6, Screen.height / 5), btnTextureskeleton);

        if (Application.isEditor)
        {
            if (Time.time > 1 + nextPrint)
            {
                nextPrint = Time.time; m_fps = Mathf.RoundToInt(1 / Time.smoothDeltaTime);
            }
            GUI.Label(new Rect(0, 0, 100, 100), "FPS: " + m_fps);
        }
    }
Ejemplo n.º 19
0
 public override void handleSingleTouch(iPhoneTouch touch)
 {
     //Rotate
     if(!allowRotate) return;
     //Set startPivot on object (with current transform position), and start rotating around according to x and y axis.
     this.startPivot(gameObject.transform.position);
         pivot.transform.RotateAround(gameObject.transform.position, new Vector3(0, 1, 0),-touch.deltaPosition.x*speed);
         pivot.transform.RotateAround(gameObject.transform.position, new Vector3(1, 0, 0), touch.deltaPosition.y*speed);
     this.endPivot();
 }
 public virtual void handleSingleTouch(iPhoneTouch aTouch)
 {
 }
Ejemplo n.º 21
0
    public override void handleSingleTouch(iPhoneTouch touch)
    {
        if (!allowDrag) return;
        // // we want to drag our object

        movement = touchMovementVector(touch);

        if (movement.sqrMagnitude > 0.01) {
          this.startPivot(gameObject.transform.position);
            pivot.transform.Translate(movement,Space.World);
            this.endPivot();
        }
    }
 void onGUIDown(iPhoneTouch pTouch)
 {
     Debug.Log(gameObject.name + " Down");
 }
Ejemplo n.º 23
0
    public Vector3 touchMovementVector(iPhoneTouch touch)
    {
        float zDistanceFromCamera = Vector3.Distance(renderingCamera.transform.position,gameObject.transform.position);

        Vector3 screenPosition = new Vector3(touch.position.x,touch.position.y,zDistanceFromCamera);
        Vector3 lastScreenPosition = new Vector3(touch.position.x - touch.deltaPosition.x,touch.position.y - touch.deltaPosition.y,zDistanceFromCamera);

        Vector3 cameraWorldPosition = this.renderingCamera.ScreenToWorldPoint(screenPosition);
        Vector3 lastCameraWorldPosition = this.renderingCamera.ScreenToWorldPoint(lastScreenPosition);

        return cameraWorldPosition - lastCameraWorldPosition;
    }
Ejemplo n.º 24
0
    public override void handleDoubleTouch(ArrayList events)
    {
        //Scale
        if (!allowScale)
        {
            return;
        }
        //Collect the two thisFrameEvents as iPhoneTouches
        iPhoneTouch touch0 = (iPhoneTouch)events[0];
        iPhoneTouch touch1 = (iPhoneTouch)events[1];

        if (touch0.fingerId > touch1.fingerId)
        {
            // flip them, 0 should be the earlier index
            touch0 = (iPhoneTouch)events[1];
            touch1 = (iPhoneTouch)events[0];
        }

        //create a temporary pivot, to perform the scaling on
        this.startPivot(gameObject.transform.position);

        //Grab the object distance from camera, and current and last screen positions of the touches.
        float   zDistanceFromCamera = Vector3.Distance(renderingCamera.transform.position, gameObject.transform.position);
        Vector3 screenPosition0     = new Vector3(touch0.position.x, touch0.position.y, zDistanceFromCamera);
        Vector3 lastScreenPosition0 = new Vector3(touch0.position.x - touch0.deltaPosition.x, touch0.position.y - touch0.deltaPosition.y, zDistanceFromCamera);
        Vector3 screenPosition1     = new Vector3(touch1.position.x, touch1.position.y, zDistanceFromCamera);
        Vector3 lastScreenPosition1 = new Vector3(touch1.position.x - touch1.deltaPosition.x, touch1.position.y - touch1.deltaPosition.y, zDistanceFromCamera);

        //Calculate last and current distance between the touches
        float distNow    = (screenPosition0 - screenPosition1).magnitude;
        float distThen   = (lastScreenPosition0 - lastScreenPosition1).magnitude;
        float angleNow   = Mathf.Atan2((screenPosition0.x - screenPosition1.x) / 2, (screenPosition0.y - screenPosition1.y) / 2) * Mathf.Rad2Deg;
        float angleThen  = Mathf.Atan2((lastScreenPosition0.x - lastScreenPosition1.x) / 2, (lastScreenPosition0.y - lastScreenPosition1.y) / 2) * Mathf.Rad2Deg;
        float angleDelta = (angleNow - angleThen);

        if (allowScale)
        {
            //Calculate the quotient from the touches of the last frame from the current; if distQuote>1 zooming
            //float distMove = (distNow/distThen-1)*Mathf.Sqrt(zDistanceFromCamera);
            float distMove = (distNow / distThen - 1) / (-pivot.transform.position.z * 2) / speed * 6;
            print(distMove);
            pivot.transform.Translate(-Vector3.forward * distMove, Space.World);

            if (pivot.transform.position.z > maxDist || pivot.transform.position.z < minDist)
            {
                pivot.transform.Translate(Vector3.forward * distMove, Space.World);
            }
        }

        if (allowTwoFingerRotate)
        {
            transform.Rotate(-pivot.transform.forward, angleDelta, Space.World);
        }

        if (allowTwoFingerMove)
        {
            if (Mathf.Abs(distNow - distThen) < 0.5f && Mathf.Abs(angleDelta) < 0.5f)
            {
                //Grab movementvector
                movement = touchMovementVector(touch0);

                //Perform move
                pivot.transform.Translate(movement, Space.World);

                //If faulty move, outside of bounds, undo
                if (Vector3.Angle((pivot.transform.position - renderingCamera.transform.position), renderingCamera.transform.forward) > 20)
                {
                    pivot.transform.Translate(-movement, Space.World);
                }
            }
        }


        //Put the temporary pivotchange on the object
        this.endPivot();

        /*if (allowSingleAxisRotate){
         *
         * }*/
    }
Ejemplo n.º 25
0
    // Update is called once per frame
    void Update()
    {
        if (Camera.main.transform.position == endPos && !mouseDown)
        {
            for (int xi = 0; xi < iPhoneInput.touchCount; xi++)
            {
                if (iPhoneInput.touchCount > xi && iPhoneInput.touchCount < 20 && iPhoneInput.GetTouch(xi) != null)
                {
                    //When touching set starttime to current time
                    //float touchTime=Time.time;

                    //Get all touches
                    iPhoneTouch touch = iPhoneInput.GetTouch(xi);
                    //Where to touch hits the screen, raycast straight forward to check for hit on object.
                    Vector3 screenPosition = new Vector3(touch.position.x, touch.position.y, 0.0f);
                    //RaycastHit hit = new RaycastHit(); // need one of these to check for hits
                    RaycastHit[] hits;

                    if (Physics.Raycast(Camera.main.ScreenPointToRay(screenPosition), Mathf.Infinity) && animateState == false)
                    {
                        //print("hit");
                        hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(screenPosition), Mathf.Infinity);
                        //RaycastHit hit = hits[0];
                        //print(hits[0].transform.gameObject.name);*/

                        for (int i = 0; i < 4; i++)
                        {
                            if (hits[0].transform.gameObject.name == models[i])
                            {
                                beginPos = hits[0].transform.position + new Vector3(0, 0, -4.5f);
                                hitModel = i;
                            }
                        }
                        //if (hit.transform.gameObject == gameObject)

                        StartCoroutine(AnimateCamera(endPos, beginPos, hitModel));

                        /*foreach(GameObject c in GameObject.FindGameObjectsWithTag("Models_2"))
                         * {
                         *      objArray.Push(c);
                         *      c.active = false;
                         * }*/

                        //Camera.main.transform.Translate(5,5,10);
                    }
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.Y) && animateState == false)
        {
            if (Camera.main.transform.position == beginPos)
            {
                StartCoroutine(AnimateCamera(beginPos, endPos, hitModel));

                /*while(objArray.length>0){
                 * GameObject  go = objArray.Pop();
                 * go.active = true;
                 * }*/
            }



            //if (!Input.GetMouseButton (0))
            //	return;

            // Only if we hit something, do we continue
            //RaycastHit hit;
            //if (!Physics.Raycast (camera.ScreenPointToRay(Input.mousePosition), hit))
            //	return;

            //Vector3 ray = camera.ScreenPointToRay (Input.mousePosition);
        }
        if (iPhoneInput.touchCount > 0)
        {
            mouseDown = true;
        }
        else
        {
            mouseDown = false;
        }
        //print(hitModel);
    }
Ejemplo n.º 26
0
 void onGUIUp(iPhoneTouch pTouch)
 {
     Debug.Log(gameObject.name + " Up");
 }
    public override void handleDoubleTouch(ArrayList events)
    {
        if (!allowRotate && !allowScale)
        {
            return;
        }
        // double touch can be a scale or a rotate, or both
        //
        // let's do the rotate first
        // since this is a 2 touch gesture, we can only rotate in 2d, which in this case is in the camera plane
        // pivot on the lower touch index

        iPhoneTouch touch0 = (iPhoneTouch)events[0];
        iPhoneTouch touch1 = (iPhoneTouch)events[1];

        if (touch0.fingerId > touch1.fingerId)
        {
            // flip them, 0 should be the earlier index
            touch0 = (iPhoneTouch)events[1];
            touch1 = (iPhoneTouch)events[0];
        }

        this.startPivot(gameObject.transform.position);

        //
        //  //////////////////////////////// ROTATE
        //

        float zDistanceFromCamera = Vector3.Distance(renderingCamera.transform.position, gameObject.transform.position);

        Vector3 screenPosition0     = new Vector3(touch0.position.x, touch0.position.y, zDistanceFromCamera);
        Vector3 lastScreenPosition0 = new Vector3(touch0.position.x - touch0.deltaPosition.x, touch0.position.y - touch0.deltaPosition.y, zDistanceFromCamera);

        Vector3 screenPosition1     = new Vector3(touch1.position.x, touch1.position.y, zDistanceFromCamera);
        Vector3 lastScreenPosition1 = new Vector3(touch1.position.x - touch1.deltaPosition.x, touch1.position.y - touch1.deltaPosition.y, zDistanceFromCamera);


        float angleNow  = Mathf.Atan2(screenPosition0.x - screenPosition1.x, screenPosition0.y - screenPosition1.y) * Mathf.Rad2Deg;
        float angleThen = Mathf.Atan2(lastScreenPosition0.x - lastScreenPosition1.x, lastScreenPosition0.y - lastScreenPosition1.y) * Mathf.Rad2Deg;

        float angleDelta = angleNow - angleThen;

        if (allowRotate)
        {
            pivot.transform.RotateAround(gameObject.transform.position, renderingCamera.transform.position - gameObject.transform.position, angleDelta);
        }

        //
        //  ///////////////////////////  SCALE
        //
        if (allowScale)
        {
            float distNow  = (screenPosition0 - screenPosition1).magnitude;
            float distThen = (lastScreenPosition0 - lastScreenPosition1).magnitude;

            float scale = distNow / distThen;

            // presume for the time being that our scales are uniform
            if (transform.localScale.x * scale < minimumScale)
            {
                scale = minimumScale / transform.localScale.x;
            }
            if (transform.localScale.x * scale > maximumScale)
            {
                scale = maximumScale / transform.localScale.x;
            }

            Vector3 local = pivot.transform.localScale;

            local.x *= scale;
            local.y *= scale;
            local.z *= scale;
            pivot.transform.localScale = local;
        }

        this.endPivot();
    }