示例#1
0
        public void Update()
        {
            if (collisionDomain.HasContact(CollisionObject))
            {
                if (triggeredRigidbodies.Count != 0)
                {
                    triggeredRigidbodies.RemoveAll(rigidBody1 => !collisionDomain.HaveContact(CollisionObject, rigidBody1.CollisionObject));
                }

                var characters = collisionDomain.GetContactObjects(CollisionObject)
                                 .Select(collisionObject => collisionObject.GeometricObject)
                                 .OfType <RigidBody>()
                                 .Where(rigidBody1 => rigidBody1.Name == nameOfTarget)
                                 .Except(triggeredRigidbodies);
                foreach (var character in characters)
                {
                    triggeredRigidbodies.Add(character);
                    OnTriggerEnter(character.UserData);
                }
            }
            else
            {
                if (triggeredRigidbodies.Count != 0)
                {
                    triggeredRigidbodies.Clear();
                }
            }
        }
示例#2
0
        protected override void OnUpdate(TimeSpan deltaTime)
        {
            // Update direction of picking object.
            // TODO(matt) Clean this bs up!
            var services        = (ServiceContainer)ServiceLocator.Current;
            var inputService    = services.GetInstance <IInputService>();
            var graphicsService = services.GetInstance <IGraphicsService>();
            var mousePos        = inputService.MousePosition;

            var originalCameraMat = _cameraObject.CameraNode.PoseWorld.Inverse.ToMatrix44F();
            var originalCameraPos = _cameraObject.CameraNode.PoseWorld.Position;
            var mouseWorldPosOld  = GraphicsHelper.Unproject(graphicsService.GraphicsDevice.Viewport, new Vector3F(mousePos.X, mousePos.Y, 0),
                                                             _cameraObject.CameraNode.Camera.Projection.ToMatrix44F(), originalCameraMat);

            ((GeometricObject)_pickingObject.GeometricObject).Pose = new Pose(new Vector3F(mouseWorldPosOld.X, mouseWorldPosOld.Y, ((GeometricObject)_pickingObject.GeometricObject).Pose.Position.Z));


            // TODO: If figureNodes can move or scale, we have to copy the new Pose
            // and Scale from the FigureNodes to their CollisionObjects.

            _collisionDomain.Update(deltaTime);

            // Reset colors of figure nodes that where "picked" in the last frame.
            // TODO: To make this faster, loop over the contact objects of the last
            // frame and not over all nodes in the scene.
            foreach (var figureNode in _scene.GetDescendants().OfType <FigureNode>())
            {
                // Figure nodes which were picked, have the color info in the UserData.
                if (figureNode.UserData != null)
                {
                    figureNode.StrokeColor = ((Pair <Vector3F>)figureNode.UserData).First;
                    figureNode.FillColor   = ((Pair <Vector3F>)figureNode.UserData).Second;
                    figureNode.UserData    = null;
                }
            }

            // Change the color of all figure nodes which touch the picking object.
            foreach (var pickedObject in _collisionDomain.GetContactObjects(_pickingObject))
            {
                var myGeometricObject = pickedObject.GeometricObject as FigureGeometricObject;
                if (myGeometricObject != null)
                {
                    var figureNode = myGeometricObject.FigureNode;
                    _debugRenderer.DrawText("Picked node: " + figureNode.Name);

                    // Store original color in UserData.
                    figureNode.UserData = new Pair <Vector3F>(figureNode.StrokeColor, figureNode.FillColor);
                    // Change color.
                    figureNode.StrokeColor = new Vector3F(0.8f, 0.6f, 0.08f);
                    figureNode.FillColor   = new Vector3F(1, 0.7f, 0.1f);
                }
            }

            // Draw the picking object (for debugging).
            _debugRenderer.DrawObject(_pickingObject.GeometricObject, Color.Red, true, false);
        }
        protected override void OnUpdate(TimeSpan deltaTime)
        {
            // Update direction of picking object.
            ((GeometricObject)_pickingObject.GeometricObject).Pose = _cameraObject.CameraNode.PoseWorld;

            // TODO: If figureNodes can move or scale, we have to copy the new Pose
            // and Scale from the FigureNodes to their CollisionObjects.

            _collisionDomain.Update(deltaTime);

            // Reset colors of figure nodes that where "picked" in the last frame.
            // TODO: To make this faster, loop over the contact objects of the last
            // frame and not over all nodes in the scene.
            foreach (var figureNode in _scene.GetDescendants().OfType <FigureNode>())
            {
                // Figure nodes which were picked, have the color info in the UserData.
                if (figureNode.UserData != null)
                {
                    figureNode.StrokeColor = ((Pair <Vector3F>)figureNode.UserData).First;
                    figureNode.FillColor   = ((Pair <Vector3F>)figureNode.UserData).Second;
                    figureNode.UserData    = null;
                }
            }

            // Change the color of all figure nodes which touch the picking object.
            foreach (var pickedObject in _collisionDomain.GetContactObjects(_pickingObject))
            {
                var myGeometricObject = pickedObject.GeometricObject as FigureGeometricObject;
                if (myGeometricObject != null)
                {
                    var figureNode = myGeometricObject.FigureNode;
                    _debugRenderer.DrawText("Picked node: " + figureNode.Name);

                    // Store original color in UserData.
                    figureNode.UserData = new Pair <Vector3F>(figureNode.StrokeColor, figureNode.FillColor);
                    // Change color.
                    figureNode.StrokeColor = new Vector3F(0.8f, 0.6f, 0.08f);
                    figureNode.FillColor   = new Vector3F(1, 0.7f, 0.1f);
                }
            }

            // Draw the picking object (for debugging).
            _debugRenderer.DrawObject(_pickingObject.GeometricObject, Color.Red, true, false);
        }