protected override bool defineCmd() { JSIApp app = (JSIApp)this.mApp; JSIPerspCameraPerson cp = app.getPerspCameraPerson(); // create a plane on the pivot, directly facing the camera. Plane pivotPlane = new Plane(-cp.getView(), cp.getPivot()); // project the previous screen point to the plane. Ray prevPtRay = cp.getCamera().ScreenPointToRay(this.mPrevPt); float prevPtDist = float.NaN; pivotPlane.Raycast(prevPtRay, out prevPtDist); Vector3 prevPtOnPlane = prevPtRay.GetPoint(prevPtDist); // project the current screen point to the plane. Ray curPtRay = cp.getCamera().ScreenPointToRay(this.mCurPt); float curPtDist = float.NaN; pivotPlane.Raycast(curPtRay, out curPtDist); Vector3 curPtOnPlane = curPtRay.GetPoint(curPtDist); // calculate the position difference between the two points. Vector3 offset = curPtOnPlane - prevPtOnPlane; // update the postion of the camera. cp.setEye(cp.getEye() - offset); return(true); }
protected override bool defineCmd() { JSIApp app = (JSIApp)this.mApp; JSIPerspCameraPerson cp = app.getPerspCameraPerson(); float dx = this.mCurPt.x - this.mPrevPt.x; float dy = this.mCurPt.y - this.mPrevPt.y; float dAzimuth = 180.0f * dx / Screen.width; float dZenith = -180.0f * dy / Screen.height; // Quaternion qa = Quaternion.AngleAxis(dAzimuth, Vector3.up); Quaternion qa = Quaternion.AngleAxis(dAzimuth, cp.getUp()); Quaternion qz = Quaternion.AngleAxis(dZenith, cp.getRight()); Vector3 pivotToEye = cp.getEye() - cp.getPivot(); Vector3 nextEye = cp.getPivot() + qa * qz * pivotToEye; Vector3 nextView = qa * qz * cp.getView(); cp.setEye(nextEye); cp.setView(nextView); return(true); }