Example #1
0
        /// <summary>
        /// Cast a ray through the physics scene until it hits something. It can only hit
        /// something that its CollisionSkinPredicate allows it to hit.
        /// </summary>
        /// <param name="distance">The distance at which the impact occurred from the starting point</param>
        /// <param name="skin">The CollisionSkin that was collided with</param>
        /// <param name="pos">The position of collision</param>
        /// <param name="normal">The normal of the surface at which the collision occurred</param>
        /// <param name="seg">The segment to use for the collision query</param>
        /// <param name="pred">The CollisionSkinPredicate acts like a collision filter, allowing
        /// collisions with only certain other bodies.</param>
        public SegmentIntersectInfo PerformSegmentIntersectQuery(Vector3 rayOrigin, Vector3 direction)
        {
            SegmentIntersectInfo info = new SegmentIntersectInfo();

            RayCastResult result;

            this.physicsSpace.RayCast(new Ray(rayOrigin, direction), out result);

            info.position = result.HitData.Location;
            info.normal   = result.HitData.Normal;
            info.distance = result.HitData.T;

            var tag = result.HitObject.Tag as IEntityTag;

            if (null == tag)
            {
                throw new Exception("All physics objects should have the QS Engine's custom tag data.");
            }

            info.entityID = tag.EntityID;

            return(info);
        }
Example #2
0
        public void RayCastForEntityReport()
        {
            // First we determine the line segment between the camera's position and the cursor
            // as if it were at the far plane.
            var msgGetSegment = ObjectPool.Aquire <MsgGetLineSegmentToCursor>();

            this.game.SendInterfaceMessage(msgGetSegment, InterfaceType.Camera);

            // Now we use that line segment to check for physics collisions
            PhysicsInterface physics = this.game.SceneManager.GetInterface(InterfaceType.Physics) as PhysicsInterface;

            if (null == physics)
            {
                throw new Exception("Cannot perform a physics ray cast without a registered PhysicsInterface");
            }

            SegmentIntersectInfo info = physics.PerformSegmentIntersectQuery(msgGetSegment.lineSegment);

            // Check if the ray hit anything
            if (QSGame.UniqueIDEmpty == info.entityID)
            {
                return;
            }

            List <TypeReflectionInfo> entityInfo;

            this.game.SceneManager.GetEntityReflectionInfo(info.entityID, out entityInfo);

            if (null == this.infoWindows)
            {
                this.infoWindows = new Dictionary <Int64, EntityInfoWindow>();
            }

            EntityInfoWindow window;

            if (!this.infoWindows.TryGetValue(info.entityID, out window))
            {
                // If a window doesn't yet exist for this entity, then we create one
                window = new EntityInfoWindow(100, 100, info.entityID, this.game);

                this.infoWindows.Add(info.entityID, window);

                this.game.Gui.Screen.Desktop.Children.Add(window);
            }
            else
            {
                if (!window.IsOpen)
                {
                    this.game.Gui.Screen.Desktop.Children.Add(window);
                }

                window.Label.Items.Clear();
            }

            for (int i = 0; i < entityInfo.Count; ++i)
            {
                TypeReflectionInfo rInfo = entityInfo[i];

                window.Label.Items.Add(rInfo.typeName);

                List <string> details = QSUtils.ConvertTypeReflectionInfoToString(rInfo.properties);

                for (int j = 0; j < details.Count; ++j)
                {
                    window.Label.Items.Add(details[j]);
                }
            }
        }