void controlLight() { // //The first // if(screenTouches.Count==2&&lastScreenTouches.Count!=0) // {} if (screenTouches.Count == 2 && lastScreenTouches.Count == 2) { ScreenTouch lastTouch1 = lastScreenTouches [0]; ScreenTouch lastTouch2 = lastScreenTouches [1]; ScreenTouch touch1 = screenTouches [0]; ScreenTouch touch2 = screenTouches [1]; if (lastTouch1.getId() == screenTouches [1].getId()) { touch1 = screenTouches [1]; touch2 = screenTouches [0]; } float dis1 = Vector2.Distance(lastTouch1.getTouchPosition(), touch1.getTouchPosition()); float dis2 = Vector2.Distance(lastTouch2.getTouchPosition(), touch2.getTouchPosition()); float lastDis = Vector2.Distance(lastTouch1.getTouchPosition(), lastTouch2.getTouchPosition()); float dis = Vector2.Distance(touch1.getTouchPosition(), touch2.getTouchPosition()); float disVariance = dis - lastDis; lightTheta += disVariance / 2; Vector2 lastVec = new Vector2(); Vector2 vec = new Vector2(); if (dis1 > dis2) { lastVec = lastTouch1.getTouchPosition() - lastTouch2.getTouchPosition(); vec = touch1.getTouchPosition() - touch2.getTouchPosition(); } if (dis1 < dis2) { lastVec = lastTouch2.getTouchPosition() - lastTouch1.getTouchPosition(); vec = touch2.getTouchPosition() - touch1.getTouchPosition(); } lastVec.Normalize(); vec.Normalize(); float cross = lastVec.x * vec.y - lastVec.y * vec.x; float alphaVariance = Mathf.Acos(Vector2.Dot(lastVec, vec)); if (cross > 0) { lightAlpha += alphaVariance; } if (cross < 0) { lightAlpha -= alphaVariance; } } }
float CheckRotateAngle(ref bool rotate) { float rotateAngle = 0; if (screenTouches.Count == 1 && lastScreenTouches.Count == 1) { ScreenTouch touch = (ScreenTouch)screenTouches [0]; ScreenTouch lastTouch = (ScreenTouch)lastScreenTouches [0]; if (touch.getId() == lastFingerId) { rotateAngle = touch.getTouchPosition().y - lastTouch.getTouchPosition().y; rotate = true; } lastFingerId = touch.getId(); } return(rotateAngle / 50); }