Hello XTUIO people, and thanks so much for UniTUIO!
I've had some troubles with a custom touchscreen sensor and finally found this, which will keep me from doing dirty tricks with mouse emulation to get things working. At least I hope so.
I'm more of a designer than a coder though, and have some problems modifying the BBBasicTouchManipulation.cs script. My setup is like this:
I have a CameraParent-object that has a camera as a child. Touching anywhere on the screen I want to be able to move this CameraParent around, rotate it, and with pinch-zoom change the distance from camera to cameraparent. This will be used to move a camera around above a city area.
In the attached script I have changed some things so that I can do this (except pinch-zoom). However, when I rotate and then try to move forward, the forward direction is not updated. I'm missing something here.
| Code: |
using UnityEngine;
using System.Collections;
// MANIPULATED BBBasicTouchManipulation.cs
// GOAL: single touch -> drag move along X- and Z-axis.
// GOAL: double touch pinch: Zoom (Move Camera closer to CameraParent)
// GOAL: double touch rotate: Rotate CameraParent around Y-axis
// GOAL: double touch move up/down: Tilt CameraParent along X-axis ()
// SUB-GOAL: If more than two points are detected it will still rotate, zoom and so on. Its easy to accidentally touch the screen with other parts of your hand, especially if you use one hand with double touch gestures.
// rotate is in the plane of the camera
public class TUIOCameraController : BBSimpleTouchableObject {
public bool allowDrag = true;
public bool allowScale = true;
public bool allowRotate = true;
public float minimumScale = 1.0f;
public float maximumScale = 3.0f;
public GameObject CameraParent;
private Transform saveParent;
private Vector3 movement;
protected GameObject pivot;
public override void handleSingleTouch(iPhoneTouch touch)
{
movement = touchMovementVector(touch);
movement.y = 0.0F; //LOCK MOVEMENT ALONG THE Y-AXIS
//if (movement.sqrMagnitude > 0.01) { // USE THIS IF MOVEMENT IS JERKY. IT WILL FILTER OUT SMALL MOVEMENTS I GUESS.
//this.startPivot(gameObject.transform.position); // MODIFY AND USE THIS IF PIVOT POINT NEED TO BE PLACED IN DIFFERENT PLACES DEPENDING ON TOUCH
CameraParent.transform.Translate(-movement,Space.World); // MAKE movement NEGATIVE TO REVERSE DIRECTION
//this.endPivot();
//}
}
//CODE CUT HERE --------------------------------------
// NEXT CHANGED PART IS THIS:
if (allowRotate) CameraParent.transform.RotateAround(CameraParent.transform.position,Vector3.up,angleDelta); //JUST ROTATE AROUND CameraParent CENTER
//CODE CUT HERE --------------------------------------------
|
So my questions:
1: How do I update the forwards direction? Or should I do this in another way?
2: This is attached to a invisible collider in front of the camera, but that will hijack all interactions with other objects right? How can I solve this?
3: Any advice on how to do the pinch-zoom to change distance between camera and cameraparent would be nice too.
4: Another problem: When using the unity editor everything works fine. When using TUIO SIMULATOR (by Martin Kaltenbrunner), motion will not stop until I stop holding mouse down. Is this normal?
Thanks in advance for any kind of help or advice on this!
/Gus