private void RemoveSelected() { this.continousPressed = false; this.distance = float.MaxValue; if (this.selectedEntity != null) { this.selectedEntity.RemoveComponent <MotorizedGrabSpring3D>(); this.selectedEntity = null; } this.mouseJoint = null; }
private void RemoveSelected() { this.continousPressed = false; this.distance = float.MaxValue; if (this.selectedEntity != null) { var jointMap = this.selectedEntity.FindComponent <JointMap3D>(); if (jointMap != null) { jointMap.RemoveJoint("mouseJoint"); } this.selectedEntity = null; } this.mouseJoint = null; }
protected override void Update(TimeSpan gameTime) { this.input = WaveServices.Input; if (this.input.MouseState.IsConnected) { this.mouseState = this.input.MouseState; // Update Mouse Position this.mousePosition.X = this.mouseState.X; this.mousePosition.Y = this.mouseState.Y; // Left Button Presseded (just one time while pressed) if (this.mouseState.LeftButton == ButtonState.Pressed && !continousPressed) { this.continousPressed = true; this.SelectPickedEntity(); if (this.selectedEntity != null) { this.distance = MathHelper.Max(this.distance, MINDISTANCE); // Mouse point at entity collide point distance this.pickingPosition.X = this.mousePosition.X; this.pickingPosition.Y = this.mousePosition.Y; this.pickingPosition.Z = this.distance; this.pickingPosition = this.camera.Unproject(ref this.pickingPosition); // obtains CameraPosition-PickingPosition vector this.pickingPosition = this.camera.Position - this.pickingPosition; this.pickingPosition.Normalize(); // Calculate this.pickingPosition = this.camera.Position + this.pickingPosition * this.distance; var jointMap = this.selectedEntity.FindComponent<JointMap3D>(); if (jointMap != null) { this.mouseJoint = new MotorizedGrabSpring3D(this.pickingPosition); jointMap.AddJoint("joint", this.mouseJoint); } } } // Left Button Released if (this.mouseState.LeftButton == ButtonState.Release && continousPressed) { this.RemoveSelected(); } if (this.selectedEntity != null && this.distance < float.MaxValue && this.mouseJoint != null) { // Mouse point at entity collide point distance this.pickingPosition.X = this.mousePosition.X; this.pickingPosition.Y = this.mousePosition.Y; this.pickingPosition.Z = this.distance; this.pickingPosition = this.camera.Unproject(ref this.pickingPosition); // obtains CameraPosition-PickingPosition vector this.pickingPosition = this.camera.Position - this.pickingPosition; this.pickingPosition.Normalize(); // Calculate this.pickingPosition = this.camera.Position + this.pickingPosition * this.distance; this.mouseJoint.WorldAnchor = this.pickingPosition; } } // Keyboard Controls if (this.input.KeyboardState.IsConnected) { this.keyboardState = this.input.KeyboardState; // (Up) adds distance if (this.keyboardState.Up == ButtonState.Pressed) { if (this.selectedEntity != null & this.distance < float.MaxValue) { this.distance += 0.3f; } } // (Down) Substracts distance else if (this.keyboardState.Down == ButtonState.Pressed) { if (this.selectedEntity != null && this.distance > MINDISTANCE) { this.distance -= 0.3f; } } } }
private void RemoveSelected() { this.continousPressed = false; this.distance = float.MaxValue; if (this.selectedEntity != null) { var jointMap = this.selectedEntity.FindComponent<JointMap3D>(); if (jointMap != null) { jointMap.RemoveJoint("joint"); } this.selectedEntity = null; } this.mouseJoint = null; }
private void RemoveSelected() { this.continousPressed = false; this.distance = float.MaxValue; if (this.selectedEntity != null) { this.selectedEntity.RemoveComponent<MotorizedGrabSpring3D>(); this.selectedEntity = null; } this.mouseJoint = null; }
protected override void Update(TimeSpan gameTime) { this.input = WaveServices.Input; if (this.input.MouseState.IsConnected) { this.mouseState = this.input.MouseState; // Update Mouse Position this.mousePosition.X = this.mouseState.X; this.mousePosition.Y = this.mouseState.Y; // Left Button Presseded (just one time while pressed) if (this.mouseState.LeftButton == ButtonState.Pressed && !continousPressed) { this.continousPressed = true; this.SelectPickedEntity(); if (this.selectedEntity != null) { this.distance = MathHelper.Max(this.distance, MINDISTANCE); // Mouse point at entity collide point distance this.pickingPosition.X = this.mousePosition.X; this.pickingPosition.Y = this.mousePosition.Y; this.pickingPosition.Z = this.distance; this.pickingPosition = this.camera.Unproject(ref this.pickingPosition, ref camera.View, ref this.camera.Projection, ref this.identity); // obtains CameraPosition-PickingPosition vector this.pickingPosition = this.camera.Position - this.pickingPosition; this.pickingPosition.Normalize(); // Calculate this.pickingPosition = this.camera.Position + this.pickingPosition * this.distance; this.mouseJoint = new MotorizedGrabSpring3D(this.pickingPosition); this.selectedEntity.AddComponent(mouseJoint); } } // Left Button Released if (this.mouseState.LeftButton == ButtonState.Release && continousPressed) { this.RemoveSelected(); } if (this.selectedEntity != null && this.distance < float.MaxValue && this.mouseJoint != null) { // Mouse point at entity collide point distance this.pickingPosition.X = this.mousePosition.X; this.pickingPosition.Y = this.mousePosition.Y; this.pickingPosition.Z = this.distance; this.pickingPosition = this.camera.Unproject(ref this.pickingPosition, ref camera.View, ref this.camera.Projection, ref this.identity); // obtains CameraPosition-PickingPosition vector this.pickingPosition = this.camera.Position - this.pickingPosition; this.pickingPosition.Normalize(); // Calculate this.pickingPosition = this.camera.Position + this.pickingPosition * this.distance; this.mouseJoint.WorldAnchor = this.pickingPosition; } } // Keyboard Controls if (this.input.KeyboardState.IsConnected) { this.keyboardState = this.input.KeyboardState; // (Up) adds distance if (this.keyboardState.Up == ButtonState.Pressed) { if (this.selectedEntity != null & this.distance < float.MaxValue) { this.distance += 0.3f; } } // (Down) Substracts distance else if (this.keyboardState.Down == ButtonState.Pressed) { if (this.selectedEntity != null && this.distance > MINDISTANCE) { this.distance -= 0.3f; } } } }