public TargetCamera(Vector3 position, Vector3 target, float fov, float aspectRatio, float zNear, float zFar, CameraControlType type = CameraControlType.ArcBall) : base(fov, aspectRatio, zNear, zFar) { this.Position = position; this.Target = target; this.ViewMatrix = Matrix4.LookAt(position, target, Vector3.UnitY); this.ControlScheme = new CameraControl(type); }
public CameraControl(CameraControlType type = CameraControlType.ArcBall) { oldMouseState = Mouse.GetState(); oldKeyboardState = Keyboard.GetState(); switch (type) { case CameraControlType.ArcBall: UpdateFunc = (camera, mouse, keyboard) => { ArcBall(camera); }; break; case CameraControlType.FPS: UpdateFunc = (camera, mouse, keyboard) => { FPS(camera); }; break; } }
public void SetData(Hashtable ht) { if(ht.ContainsKey("type")) { this.type = (CameraControlType)System.Enum.Parse( typeof(CameraControlType), (string)ht["type"]); if(this.IsFollowControl()) { this.distance = float.Parse((string)ht["distance"]); this.height = float.Parse((string)ht["height"]); this.heightDamping = float.Parse((string)ht["heightdamping"]); this.rotationDamping = float.Parse((string)ht["rotationdamping"]); } else if(this.IsLookControl()) { this.damping = float.Parse((string)ht["damping"]); this.smooth = bool.Parse((string)ht["smooth"]); } else if(this.IsMobileControl()) { this.distance = float.Parse((string)ht["distance"]); this.height = float.Parse((string)ht["height"]); this.minHeight = float.Parse((string)ht["minheight"]); this.maxHeight = float.Parse((string)ht["maxheight"]); this.heightDamping = float.Parse((string)ht["heightdamping"]); this.allowRotation = bool.Parse((string)ht["allowrotation"]); this.allowZoom = bool.Parse((string)ht["allowzoom"]); this.rotation = float.Parse((string)ht["rotation"]); this.mouseTouch.SetData(ht); if(ht.ContainsKey("rotationdamping")) { this.rotationDamping = float.Parse((string)ht["rotationdamping"]); } if(ht.ContainsKey("rotationfactor")) { this.rotationFactor = float.Parse((string)ht["rotationfactor"]); } if(ht.ContainsKey("zoomfactor")) { this.zoomFactor = float.Parse((string)ht["zoomfactor"]); } if(ht.ContainsKey("touchfingers")) { this.mouseTouch.useTouch = true; this.mouseTouch.touchCount = int.Parse((string)ht["touchfingers"]); } if(ht.ContainsKey("zoomkeychange")) { this.zoomKeyChange = float.Parse((string)ht["zoomkeychange"]); } if(ht.ContainsKey(XMLHandler.NODES)) { ArrayList s = ht[XMLHandler.NODES] as ArrayList; foreach(Hashtable ht2 in s) { if(ht2[XMLHandler.NODE_NAME] as string == CameraControlSettings.ZOOMPLUSKEY) { this.zoomPlusKey = ht2[XMLHandler.CONTENT] as string; } else if(ht2[XMLHandler.NODE_NAME] as string == CameraControlSettings.ZOOMMINUSKEY) { this.zoomMinusKey = ht2[XMLHandler.CONTENT] as string; } } } } else if(this.IsFirstPersonControl()) { this.offset = VectorHelper.FromHashtable(ht, "ox", "oy", "oz"); this.sensitivity = VectorHelper.FromHashtable(ht, "sx", "sy"); if(ht.ContainsKey("lockcursor")) this.lockCursor = true; if(ht.ContainsKey(XMLHandler.NODES)) { ArrayList s = ht[XMLHandler.NODES] as ArrayList; foreach(Hashtable ht2 in s) { if(ht2[XMLHandler.NODE_NAME] as string == CameraControlSettings.ONCHILD) { this.onChild = ht2[XMLHandler.CONTENT] as string; } else if(ht2[XMLHandler.NODE_NAME] as string == CameraControlSettings.HORIZONTALAXIS) { this.horizontalAxis = ht2[XMLHandler.CONTENT] as string; } else if(ht2[XMLHandler.NODE_NAME] as string == CameraControlSettings.VERTICALAXIS) { this.verticalAxis = ht2[XMLHandler.CONTENT] as string; } } } } } }
public void OnViewPointPanelDrag(BaseEventData baseData) { PointerEventData data = (PointerEventData)baseData; if (this._cameraControlPointers.ContainsKey(data.pointerId)) { CameraControllPointer pointer = this._cameraControlPointers[data.pointerId]; pointer.offsetPoint = data.delta; CameraControllPointer pointer2 = pointer; CameraControlType currentTouchType = this.GetCurrentTouchType(); if (currentTouchType == CameraControlType.TwoPoint) { foreach (KeyValuePair <int, CameraControllPointer> pair in this._cameraControlPointers) { if (pair.Key != data.pointerId) { pointer2 = pair.Value; } } float num = Vector2.Distance(pointer.enterPoint, pointer2.enterPoint); float num2 = Vector2.Distance(pointer.offsetPoint + pointer.enterPoint, pointer2.offsetPoint + pointer2.enterPoint); float f = num - num2; float zoomDelta = (f * Time.deltaTime) * 4f; if (!pointer.isDrag && (Mathf.Abs(f) > 20f)) { pointer.isDrag = true; Singleton <CameraManager> .Instance.GetMainCamera().FollowControlledRotateStart(); } if (pointer.isDrag) { this._dragOffset = data.delta; Singleton <CameraManager> .Instance.GetMainCamera().SetFollowControledZoomingData(zoomDelta); } } else if ((currentTouchType == CameraControlType.OnePoint) && (this._preControlType == CameraControlType.None)) { if (!pointer.isDrag) { float num5 = ((data.position.x - pointer.enterPoint.x) / ((float)Screen.width)) * this._screenWidthInInch; float num6 = ((data.position.y - pointer.enterPoint.y) / ((float)Screen.height)) * this._screenHeightInInch; float num7 = (num5 * num5) + (num6 * num6); if (num7 > 0.0036f) { pointer.isDrag = true; Singleton <CameraManager> .Instance.GetMainCamera().FollowControlledRotateStart(); } } if (pointer.isDrag) { Vector2 delta = data.delta; delta.x = (delta.x / ((float)Screen.width)) * this._screenWidthInInch; delta.y = (delta.y / ((float)Screen.height)) * this._screenHeightInInch; Singleton <CameraManager> .Instance.GetMainCamera().SetFollowControledRotationData(delta); } } else if ((currentTouchType == CameraControlType.OnePoint) && (this._preControlType == CameraControlType.TwoPoint)) { Singleton <CameraManager> .Instance.GetMainCamera().SetFollowControledRotationData(data.delta - this._dragOffset); } } }
private void RefreshControlType() { this._preControlType = this._currentControlType; this._currentControlType = this.GetCurrentTouchType(); }
public void SetCameraControlType(CameraControlType type) { controlType = type; }