/// <summary>
        /// Queues a raycast
        /// </summary>
        /// <param name="position">Origin of Ray</param>
        /// <param name="direction">Ray normal</param>
        /// <param name="length">Ray length</param>
        /// <param name="retMethod">Return method to send the results</param>
        public void QueueRequest(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
        {
            lock (m_PendingRequests)
            {
                ODERayCastRequest req = new ODERayCastRequest();
                req.callbackMethod = retMethod;
                req.length = length;
                req.Normal = direction;
                req.Origin = position;

                m_PendingRequests.Add(req);
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new instance of the Wheel class.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="car">The RigidBody on which to apply the wheel forces.</param>
        /// <param name="position">The position of the wheel on the body (in body space).</param>
        /// <param name="radius">The wheel radius.</param>
        public Wheel(World world,RigidBody car,JVector position,float radius)
        {
            this.world = world;
            this.car = car;
            this.Position = position;

            raycast = new RaycastCallback(RaycastCallback);

            // set some default values.
            this.SideFriction = 1.5f;
            this.ForwardFriction = 1f;
            this.Radius = radius;
            this.Inertia = 1.0f;
            this.WheelTravel = 0.2f;
            this.MaximumAngularVelocity = 200;
            this.NumberOfRays = 5;
        }
示例#3
0
        /// <summary>
        /// Creates a new instance of the Wheel class.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="car">The RigidBody on which to apply the wheel forces.</param>
        /// <param name="position">The position of the wheel on the body (in body space).</param>
        /// <param name="radius">The wheel radius.</param>
        public Wheel(World world, RigidBody car, JVector position, float radius)
        {
            this.world = world;
            this.car   = car;
            Position   = position;

            raycast = new RaycastCallback(RaycastCallback);

            // set some default values.
            SideFriction           = 1.5f;
            ForwardFriction        = 1f;
            Radius                 = radius;
            Inertia                = 1.0f;
            WheelTravel            = 0.2f;
            MaximumAngularVelocity = 200;
            NumberOfRays           = 5;
        }
示例#4
0
        /// <summary>
        /// Sends a ray (definied by start and direction) through the scene (all bodies added).
        /// NOTE: For performance reasons terrain and trianglemeshshape aren't checked
        /// against rays (rays are of infinite length). They are checked against segments
        /// which start at rayOrigin and end in rayOrigin + rayDirection.
        /// </summary>
        #region public override bool Raycast(JVector rayOrigin, JVector rayDirection, out JVector normal,out FP fraction)
        public override bool Raycast(TSVector rayOrigin, TSVector rayDirection, RaycastCallback raycast, out RigidBody body, out TSVector normal, out FP fraction)
        {
            body = null; normal = TSVector.zero; fraction = FP.MaxValue;

            TSVector tempNormal; FP tempFraction;
            bool     result = false;

            // TODO: This can be done better in CollisionSystemPersistenSAP
            foreach (IBroadphaseEntity e in bodyList)
            {
                if (e is SoftBody)
                {
                    SoftBody softBody = e as SoftBody;
                    foreach (RigidBody b in softBody.VertexBodies)
                    {
                        if (this.Raycast(b, rayOrigin, rayDirection, out tempNormal, out tempFraction))
                        {
                            if (tempFraction < fraction && (raycast == null || raycast(b, tempNormal, tempFraction)))
                            {
                                body     = b;
                                normal   = tempNormal;
                                fraction = tempFraction;
                                result   = true;
                            }
                        }
                    }
                }
                else
                {
                    RigidBody b = e as RigidBody;

                    if (this.Raycast(b, rayOrigin, rayDirection, out tempNormal, out tempFraction))
                    {
                        if (tempFraction < fraction && (raycast == null || raycast(b, tempNormal, tempFraction)))
                        {
                            body     = b;
                            normal   = tempNormal;
                            fraction = tempFraction;
                            result   = true;
                        }
                    }
                }
            }

            return(result);
        }
        public override bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal, out float fraction)
        {
            body     = null;
            normal   = JVector.Zero;
            fraction = float.MaxValue;

            JVector tempNormal;
            float   tempFraction;
            bool    result = false;

            foreach (var e in bodyList)
            {
                if (e is SoftBody softBody)
                {
                    foreach (RigidBody rigidBody in softBody.VertexBodies)
                    {
                        if (Raycast(rigidBody, rayOrigin, rayDirection, out tempNormal, out tempFraction) &&
                            tempFraction < fraction &&
                            (raycast == null || raycast(rigidBody, tempNormal, tempFraction)))
                        {
                            body     = rigidBody;
                            normal   = tempNormal;
                            fraction = tempFraction;
                            result   = true;
                        }
                    }
                }
                else
                {
                    var rigidBody = e as RigidBody;

                    if (Raycast(rigidBody, rayOrigin, rayDirection, out tempNormal, out tempFraction) &&
                        tempFraction < fraction &&
                        (raycast == null || raycast(rigidBody, tempNormal, tempFraction)))
                    {
                        body     = rigidBody;
                        normal   = tempNormal;
                        fraction = tempFraction;
                        result   = true;
                    }
                }
            }

            return(result);
        }
示例#6
0
        public void RemoveListener(int layer, RaycastCallback callback)
        {
            if (!_callbacksDict.ContainsKey(layer))
            {
                return;
            }
            var cbs = _callbacksDict[layer];

            if (!cbs.Contains(callback))
            {
                return;
            }
            cbs.Remove(callback);
            if (cbs.Count == 0)
            {
                _callbacksDict.Remove(layer);
            }
        }
示例#7
0
            private void PropagateRaycast <TState>(Ray ray, RaycastCallback <TState> objectCallback, ref TState stateData)
            {
                if (!this.isSubdivided || !ReferenceEquals(this.indices, null))
                {
                    objectCallback(ref stateData, ref this.container);
                    return;
                }

                // Propagate
                Vector3[] min    = this.childrenBounds.min;
                Vector3[] max    = this.childrenBounds.max;
                Vector3[] center = this.childrenBounds.center;
                for (int i = 0; i < ChildBucketCount; i++)
                {
                    if (BoundingBox.RayIntersection(ref min[i], ref max[i], ref center[i], ref ray))
                    {
                        this.children[i].PropagateRaycast <TState>(ray, objectCallback, ref stateData);
                    }
                }
            }
        public TSRaycastHit Raycast(TSRay ray, FP maxDistance, int layerMask, RaycastCallback callback = null)
        {
            IBody    hitBody;
            TSVector hitNormal;
            FP       hitFraction;

            TSVector origin    = ray.origin;
            TSVector direction = ray.direction;

            direction *= maxDistance;
            if (Raycast(origin, direction, callback, layerMask, out hitBody, out hitNormal, out hitFraction))
            {
                GameObject  other              = PhysicsManager.instance.GetGameObject(hitBody);
                TSRigidBody bodyComponent      = other.GetComponent <TSRigidBody>();
                TSCollider  colliderComponent  = other.GetComponent <TSCollider>();
                TSTransform transformComponent = other.GetComponent <TSTransform>();
                return(new TSRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, direction, hitFraction));
            }

            return(null);
        }
示例#9
0
        //Vector3 rawRotation;//, rotation;

        public Tool(Player parent, GameInput gameInput)
        {
            Parent = parent;

            this.gameInput = gameInput;

            raycastCallback = new RaycastCallback(mRaycastCallback);

            slot = getSlot();

            icon = new GuiElement(this.parent.hud);
            icon.setSizeRel(new Vector2(256, 128));

            iconPos       = new Vector2(-0.8f, 0.8f - slot * iconDist);
            smoothIconPos = iconPos;
            icon.Position = smoothIconPos;

            icon.setMaterial("hud\\blank_icon.xmf");

            createWeaponModel();
        }
示例#10
0
        //Vector3 rawRotation;//, rotation;
        public Tool(Player parent, GameInput gameInput)
        {
            Parent = parent;

            this.gameInput = gameInput;

            raycastCallback = new RaycastCallback(mRaycastCallback);

            slot = getSlot();

            icon = new GuiElement(this.parent.hud);
            icon.setSizeRel(new Vector2(256, 128));

            iconPos = new Vector2(-0.8f, 0.8f - slot * iconDist);
            smoothIconPos = iconPos;
            icon.Position = smoothIconPos;

            icon.setMaterial("hud\\blank_icon.xmf");

            createWeaponModel();
        }
示例#11
0
        /// <summary>
        /// Creates a new instance of the Wheel class.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="car">The RigidBody on which to apply the wheel forces.</param>
        /// <param name="position">The position of the wheel on the body (in body space).</param>
        /// <param name="radius">The wheel radius.</param>
        public Wheel(RigidBody car, JVector position, float radius)
        {
            this.car      = car;
            this.Position = position;

            raycast = new RaycastCallback(RaycastCallback);

            // set some default values.
            //this.SideFriction = 455f;
            // this.ForwardFriction = 451f;

            this.SideFriction    = 1.5f;
            this.ForwardFriction = 1f;

            this.Radius      = radius;
            this.Inertia     = 1.0f;
            this.WheelTravel = 0.2f;
            //MAX SPEED
            this.MaximumAngularVelocity = 200f;
            this.NumberOfRays           = 10;
        }
示例#12
0
        public TSRaycastHit Raycast(TSRay ray, FP maxDistance, RaycastCallback callback = null)
        {
            IBody    hitBody;
            TSVector hitNormal;
            FP       hitFraction;

            TSVector origin    = ray.origin;
            TSVector direction = ray.direction;

            if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
            {
                if (hitFraction <= maxDistance)
                {
                    GameObject  other = PhysicsManager.instance.GetGameObject(hitBody);
                    TSTransform transformComponent = transformMap[hitBody];
                    TSRigidBody bodyComponent      = transformComponent.rb;
                    TSCollider  colliderComponent  = transformComponent.tsCollider;
                    hit.Init(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction);
                    return(hit);
                }
            }
            else
            {
                direction *= maxDistance;
                if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
                {
                    GameObject  other = PhysicsManager.instance.GetGameObject(hitBody);
                    TSTransform transformComponent = transformMap[hitBody];
                    TSRigidBody bodyComponent      = transformComponent.rb;
                    TSCollider  colliderComponent  = transformComponent.tsCollider;
                    hit.Init(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction);
                    return(hit);
                }
            }
            return(null);
        }
示例#13
0
 public abstract bool Raycast(TSVector rayOrigin, TSVector rayDirection, RaycastCallback raycast, int layerMask, out RigidBody body, out TSVector normal, out FP fraction);
 public override bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal, out float fraction)
 {
     throw new NotImplementedException();
 }
示例#15
0
 public override void RaycastActor(PhysicsActor actor, Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
 {
     if (retMethod != null && actor !=null)
     {
         IntPtr geom;
         if (actor is OdePrim)
             geom = ((OdePrim)actor).prim_geom;
         else if (actor is OdeCharacter)
             geom = ((OdePrim)actor).prim_geom;
         else
             return;
         if (geom == IntPtr.Zero)
             return;
         m_rayCastManager.QueueRequest(geom, position, direction, length, retMethod);
     }
 }
        public void QueueRequest(IntPtr geom, Vector3 position, Vector3 direction, float length, int count, RaycastCallback retMethod)
        {
            ODERayRequest req = new ODERayRequest();
            req.geom = geom;
            req.callbackMethod = retMethod;
            req.length = length;
            req.Normal = direction;
            req.Origin = position;
            req.Count = count;

            m_PendingRequests.Enqueue(req);
        }
 public override bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal, out float fraction)
 {
     throw new NotImplementedException();
 }
示例#18
0
文件: World.cs 项目: johang88/triton
        public bool Raycast(Vector3 origin, Vector3 direction, RaycastCallback callback, out Body body, out Vector3 normal, out float fraction)
        {
            RigidBody rigidBody;
            JVector jitterNormal;

            Jitter.Collision.RaycastCallback jitterCallback = (RigidBody body1, JVector normal1, float fraction1) =>
            {
                return callback((Body)body1.Tag, Conversion.ToTritonVector(ref normal1), fraction1);
            };

            var res = PhysicsWorld.CollisionSystem.Raycast(Conversion.ToJitterVector(ref origin), Conversion.ToJitterVector(ref direction), jitterCallback, out rigidBody, out jitterNormal, out fraction);

            normal = Conversion.ToTritonVector(ref jitterNormal);
            if (rigidBody != null)
            {
                body = (Body)rigidBody.Tag;
            }
            else
            {
                body = null;
            }

            return res;
        }
示例#19
0
 public float getFocus()
 {
     RaycastCallback raycast = new RaycastCallback(RaycastCallback); RigidBody body; JVector normal; float frac;
     bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection),
         raycast, out body, out normal, out frac);
     if (result)
     {
         return frac;
     }
     else
     {
         return zFar;
     }
 }
        public override bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal, out float fraction)
        {
            throw new NotImplementedException();
            //body = null; normal = JVector.Zero; fraction = float.MaxValue;

            //JVector tempNormal; float tempFraction;
            //bool result = false;

            //// TODO: This can be done better in CollisionSystemPersistenSAP
            //foreach (IBroadphaseEntity e in bodyList)
            //{
            //    if (e is SoftBody)
            //    {
            //        SoftBody softBody = e as SoftBody;
            //        foreach (RigidBody b in softBody.VertexBodies)
            //        {
            //            if (this.Raycast(b, rayOrigin, rayDirection, out tempNormal, out tempFraction))
            //            {
            //                if (tempFraction < fraction && (raycast == null || raycast(b, tempNormal, tempFraction)))
            //                {
            //                    body = b;
            //                    normal = tempNormal;
            //                    fraction = tempFraction;
            //                    result = true;
            //                }
            //            }
            //        }
            //    }
            //    else
            //    {
            //        RigidBody b = e as RigidBody;

            //        if (this.Raycast(b, rayOrigin, rayDirection, out tempNormal, out tempFraction))
            //        {
            //            if (tempFraction < fraction && (raycast == null || raycast(b, tempNormal, tempFraction)))
            //            {
            //                body = b;
            //                normal = tempNormal;
            //                fraction = tempFraction;
            //                result = true;
            //            }
            //        }
            //    }
            //}

            //return result;
        }
示例#21
0
 /// <summary>
 /// Queue a raycast against the physics scene.
 /// The provided callback method will be called when the raycast is complete
 ///
 /// Many physics engines don't support collision testing at the same time as
 /// manipulating the physics scene, so we queue the request up and callback
 /// a custom method when the raycast is complete.
 /// This allows physics engines that give an immediate result to callback immediately
 /// and ones that don't, to callback when it gets a result back.
 ///
 /// ODE for example will not allow you to change the scene while collision testing or
 /// it asserts, 'opteration not valid for locked space'.  This includes adding a ray to the scene.
 ///
 /// This is named RayCastWorld to not conflict with modrex's Raycast method.
 /// </summary>
 /// <param name="position">Origin of the ray</param>
 /// <param name="direction">Direction of the ray</param>
 /// <param name="length">Length of ray in meters</param>
 /// <param name="retMethod">Method to call when the raycast is complete</param>
 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
 {
     if (retMethod != null)
     {
         retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
     }
 }
示例#22
0
 public void Raycast <TState>(Ray ray, RaycastCallback <TState> objectCallback, ref TState stateData)
 {
     PropagateRaycast <TState>(ray, objectCallback, ref stateData);
 }
示例#23
0
 public void Raycast <TState>(Ray ray, RaycastCallback <TState> objectCallback, ref TState data)
 {
     root.Raycast(ray, objectCallback, ref data);
 }
示例#24
0
        public void UpdateFrame(IGameInputDriver input, double time)
        {
            this.camera.Pan  -= 0.5f * input.MouseMovement.X;
            this.camera.Tilt -= 0.5f * input.MouseMovement.Y;

            this.camera.Pan %= 360.0f;
            this.camera.Tilt = MathHelper.Clamp(this.camera.Tilt, -80, 80);

            Vector3 forward = Vector3.Zero;

            forward.X = 1.0f * (float)(Math.Sin(MathHelper.DegreesToRadians(this.camera.Pan)));
            forward.Y = 0.0f;
            forward.Z = 1.0f * (float)(Math.Cos(MathHelper.DegreesToRadians(this.camera.Pan)));

            Vector3 right = Vector3.Cross(forward, Vector3.UnitY);

            Vector3 move = Vector3.Zero;

            if (input.GetButton(Key.W))
            {
                move += forward;
            }
            if (input.GetButton(Key.S))
            {
                move -= forward;
            }
            if (input.GetButton(Key.D))
            {
                move += right;
            }
            if (input.GetButton(Key.A))
            {
                move -= right;
            }

            this.WalkSpeed = 10.0f * move.Jitter();

            if (input.GetButtonDown(Key.Space))
            {
                RaycastCallback callback = (b, n, f) =>
                {
                    return(b.IsStatic);
                };
                RigidBody body;
                JVector   normal;
                float     friction;

                if (this.world.CollisionSystem.Raycast(
                        this.Position,
                        new JVector(0, -1, 0),
                        callback,
                        out body,
                        out normal,
                        out friction))
                {
                    if (friction < 0.9f)
                    {
                        this.AddForce(new JVector(0, 200, 0));
                        Console.WriteLine("{0} {1} {2}", body, normal, friction);
                    }
                }
            }

            var origin    = this.camera.GetEye();
            var direction = this.camera.GetForward();

            if (input.GetMouseDown(MouseButton.Left))
            {
                this.Tool?.PrimaryUse(origin, direction);
            }

            if (input.GetMouseDown(MouseButton.Right))
            {
                this.Tool?.SecondaryUse(origin, direction);
            }
        }
        public override bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal, out double fraction)
        {
            body = null; normal = JVector.Zero; fraction = double.MaxValue;

            JVector tempNormal; double tempFraction;
            bool result = false;

            // TODO: This can be done better in CollisionSystemPersistenSAP
            foreach (IBroadphaseEntity e in bodyList)
            {
                if (e is SoftBody)
                {
                    SoftBody softBody = e as SoftBody;
                    foreach (RigidBody b in softBody.VertexBodies)
                    {
                        if (this.Raycast(b, rayOrigin, rayDirection, out tempNormal, out tempFraction))
                        {
                            if (tempFraction < fraction && (raycast == null || raycast(b, tempNormal, tempFraction)))
                            {
                                body = b;
                                normal = tempNormal;
                                fraction = tempFraction;
                                result = true;
                            }
                        }
                    }
                }
                else
                {
                    RigidBody b = e as RigidBody;

                    if (this.Raycast(b, rayOrigin, rayDirection, out tempNormal, out tempFraction))
                    {
                        if (tempFraction < fraction && (raycast == null || raycast(b, tempNormal, tempFraction)))
                        {
                            body = b;
                            normal = tempNormal;
                            fraction = tempFraction;
                            result = true;
                        }
                    }
                }
            }

            return result;
        }
示例#26
0
        public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
        {
            if (retMethod != null)
            {
                ODERayRequest req = new ODERayRequest();
                req.actor = null;
                req.callbackMethod = retMethod;
                req.length = length;
                req.Normal = direction;
                req.Origin = position;
                req.Count = 0;
                req.filter = RayFilterFlags.AllPrims;

                m_rayCastManager.QueueRequest(req);
            }
        }
示例#27
0
 /// <summary>
 /// Sends a ray (definied by start and direction) through the scene (all bodies added).
 /// NOTE: For performance reasons terrain and trianglemeshshape aren't checked
 /// against rays (rays are of infinite length). They are checked against segments
 /// which start at rayOrigin and end in rayOrigin + rayDirection.
 /// </summary>
 public abstract bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal, out float fraction);
示例#28
0
 /// <summary>
 /// Sends a ray (definied by start and direction) through the scene (all bodies added).
 /// NOTE: For performance reasons terrain and trianglemeshshape aren't checked
 /// against rays (rays are of infinite length). They are checked against segments
 /// which start at rayOrigin and end in rayOrigin + rayDirection.
 /// </summary>
 public abstract bool Raycast(FPVector rayOrigin, FPVector rayDirection, RaycastCallback raycast, out RigidBody body, out FPVector normal, out FP fraction);
 /// <summary>
 /// Sends a ray (definied by start and direction) through the scene (all bodies added).
 /// NOTE: For performance reasons terrain and trianglemeshshape aren't checked
 /// against rays (rays are of infinite length). They are checked against segments
 /// which start at rayOrigin and end in rayOrigin + rayDirection.
 /// </summary>
 public abstract bool Raycast(JVector rayOrigin, JVector rayDirection, RaycastCallback raycast, out RigidBody body, out JVector normal,out float fraction);
示例#30
0
 public bool Raycast(TSVector rayOrigin, TSVector rayDirection, RaycastCallback raycast, out IBody body, out TSVector normal, out FP fraction)
 {
     throw new NotImplementedException();
 }
 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
 {
     if (retMethod != null)
     {
         m_rayCastManager.QueueRequest(position, direction, length, retMethod);
     }
 }
示例#32
0
 public TSRaycastHit Raycast(TSRay ray, FP maxDistance, RaycastCallback callback = null)
 {
     throw new NotImplementedException();
 }
示例#33
0
 /// <summary>
 /// Queue a raycast against the physics scene.
 /// The provided callback method will be called when the raycast is complete
 /// 
 /// Many physics engines don't support collision testing at the same time as 
 /// manipulating the physics scene, so we queue the request up and callback 
 /// a custom method when the raycast is complete.
 /// This allows physics engines that give an immediate result to callback immediately
 /// and ones that don't, to callback when it gets a result back.
 /// 
 /// ODE for example will not allow you to change the scene while collision testing or
 /// it asserts, 'opteration not valid for locked space'.  This includes adding a ray to the scene.
 /// 
 /// This is named RayCastWorld to not conflict with modrex's Raycast method.
 /// </summary>
 /// <param name="position">Origin of the ray</param>
 /// <param name="direction">Direction of the ray</param>
 /// <param name="length">Length of ray in meters</param>
 /// <param name="retMethod">Method to call when the raycast is complete</param>
 public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, RaycastCallback retMethod)
 {
     if (retMethod != null)
         retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
 }
示例#34
0
 public virtual void RaycastAll(TSVector rayOrigin, TSVector rayDirection, RaycastCallback raycast, int layerMask)
 {
     throw new NotImplementedException();
 }