示例#1
0
        private xna.Vector3 SingleRaycast(xna.Vector3 from, xna.Vector3 to)
        {
            var rayResult = PhysicsEngine.Raycast2D(
                RaycastProperties.FromSingleRay(
                    TypeConversion.FromXNA(from),
                    TypeConversion.FromXNA(to)
                    )
                );

            RaycastResult result = null;

            //
            // !Warning! this code is relying on the Raycast operation being
            // fundementally synchronous, wrapped in an async API.
            //

            if (rayResult.Test(out result))
            {
                if (result.ImpactPoints.Count == 1)
                {
                    var impact = result.ImpactPoints[0].Position;
                    return(new xna.Vector3(
                               impact.X,
                               impact.Y,
                               impact.Z
                               ));
                }
            }

            return(to);
        }
        void InsertEntityNotificationHandler(InsertSimulationEntity ins)
        {
            _entity = (SonarEntity)ins.Body;
            _entity.ServiceContract = Contract.Identifier;

            // CreateDefaultState();

            RaycastProperties raycastProperties = new RaycastProperties();

            raycastProperties.StartAngle     = (float)-_state.AngularRange / 2.0f;
            raycastProperties.EndAngle       = (float)_state.AngularRange / 2.0f;
            raycastProperties.AngleIncrement = (float)_state.AngularResolution;
            // raycastProperties.Range = LASER_RANGE;
            raycastProperties.Range = SONAR_RANGE;
            // Raul - This should be the pose of the sonar transducer.
            // Raul - I consider 8 Sonar transducers rays in the P3DX frontal ring
            // Raul - coming from a common central point.
            raycastProperties.OriginPose = new Pose();

            _entity.RaycastProperties = raycastProperties;
            _entity.Register(_raycastResults);

            // attach handler to raycast results port
            Activate(Arbiter.Receive(true, _raycastResults, RaycastResultsHandler));
        }
示例#3
0
        private void SingleRaycastAsync(xna.Vector3 from, xna.Vector3 to, int index, Port <OcclusionRay> resultPort)
        {
            var rayResult = PhysicsEngine.Raycast2D(
                RaycastProperties.FromSingleRay(
                    TypeConversion.FromXNA(from),
                    TypeConversion.FromXNA(to)
                    )
                );

            Activate(
                Arbiter.Receive(false, rayResult,
                                delegate(RaycastResult result)
            {
                xna.Vector3 hitPoint;

                if (result.ImpactPoints.Count == 1)
                {
                    var impact = result.ImpactPoints[0].Position;
                    hitPoint   = new xna.Vector3(
                        impact.X,
                        impact.Y,
                        impact.Z
                        );
                }
                else
                {
                    hitPoint = to;
                }

                float distance = (hitPoint - to).Length();

                resultPort.Post(
                    new OcclusionRay
                {
                    Index    = index,
                    Point    = from,
                    Impact   = hitPoint,
                    Distance = distance,
                    Occluded = distance > OcclusionThreshold,
                    Run      = 0
                }
                    );
            }
                                )
                );
        }
        void InsertEntityNotificationHandler(InsertSimulationEntity ins)
        {
            _entity = (SonarEntity)ins.Body;
            _entity.ServiceContract = Contract.Identifier;

            // CreateDefaultState();

            RaycastProperties raycastProperties = new RaycastProperties();            
            raycastProperties.StartAngle = (float) -_state.AngularRange / 2.0f;
            raycastProperties.EndAngle = (float) _state.AngularRange / 2.0f;
            raycastProperties.AngleIncrement = (float)_state.AngularResolution;
            // raycastProperties.Range = LASER_RANGE;
            raycastProperties.Range = SONAR_RANGE;
            // Raul - This should be the pose of the sonar transducer.
            // Raul - I consider 8 Sonar transducers rays in the P3DX frontal ring
            // Raul - coming from a common central point.
            raycastProperties.OriginPose = new Pose();

            _entity.RaycastProperties = raycastProperties;
            _entity.Register(_raycastResults);

            // attach handler to raycast results port
            Activate(Arbiter.Receive(true, _raycastResults, RaycastResultsHandler));
        }