public override void DoWork()
        {
            MyBoxSensorElement seBoxElement = (MyBoxSensorElement)m_SensorElement;

            Matrix seBoxMatrix = seBoxElement.GetGlobalTransformation();

            BoundingBox oeAABB = m_RBElement.GetWorldSpaceAABB();
            BoundingBox seBB   = new BoundingBox(-seBoxElement.Extent, seBoxElement.Extent);

            MyOrientedBoundingBox seBoxOriented = MyOrientedBoundingBox.CreateFromBoundingBox(seBB).Transform(seBoxMatrix);

            m_IsInside = seBoxOriented.Intersects(ref oeAABB);
        }
Esempio n. 2
0
        public override void DoWork()
        {
            MyRBBoxElement     rbBoxElement = (MyRBBoxElement)m_RBElement;
            MyBoxSensorElement seBoxElement = (MyBoxSensorElement)m_SensorElement;

            Matrix rbBoxMatrix = rbBoxElement.GetGlobalTransformation();
            Matrix seBoxMatrix = seBoxElement.GetGlobalTransformation();

            BoundingBox rbBB = new BoundingBox(-rbBoxElement.Size / 2f, rbBoxElement.Size / 2f);
            BoundingBox seBB = new BoundingBox(-seBoxElement.Extent, seBoxElement.Extent);

            MyOrientedBoundingBox rbBoxOriented = MyOrientedBoundingBox.CreateFromBoundingBox(rbBB).Transform(rbBoxMatrix);
            MyOrientedBoundingBox seBoxOriented = MyOrientedBoundingBox.CreateFromBoundingBox(seBB).Transform(seBoxMatrix);

            m_IsInside = rbBoxOriented.Intersects(ref seBoxOriented);
        }
Esempio n. 3
0
        public override void DoWork()
        {
            MyRBSphereElement  sphere = (MyRBSphereElement)m_RBElement;
            MyBoxSensorElement box    = (MyBoxSensorElement)m_SensorElement;

            Matrix  boxMatrix    = box.GetGlobalTransformation();
            Vector3 sphereCenter = sphere.GetGlobalTransformation().Translation;

            Matrix invBoxMatrix = Matrix.Invert(boxMatrix);

            Vector3 boxLocalsphereCenter = Vector3.Transform(sphereCenter, invBoxMatrix);

            bool    penetration = false;
            Vector3 normal      = new Vector3();
            Vector3 closestPos  = new Vector3();
            uint    customData  = 0;

            MyElementHelper.GetClosestPointForBox(box.Extent, boxLocalsphereCenter, ref closestPos, ref normal, ref penetration, ref customData);

            if (penetration)
            {
                m_IsInside = true;
                return;
            }

            closestPos = Vector3.Transform(closestPos, boxMatrix);

            float vLength = (sphereCenter - closestPos).LengthSquared();

            if (vLength <= sphere.Radius * sphere.Radius)
            {
                m_IsInside = true;
            }
            else
            {
                m_IsInside = false;
            }
        }
Esempio n. 4
0
        private void InitSensor(MyMwcObjectBuilder_EntityDetector_TypesEnum type, Vector3 size)
        {
            MySensorElement sensorElement;

            if (type == MyMwcObjectBuilder_EntityDetector_TypesEnum.Sphere)
            {
                MySphereSensorElement sphereSensorElement = new MySphereSensorElement();
                sphereSensorElement.Radius = size.Length() / 2f;
                sensorElement = sphereSensorElement;
                EntityDetectorType = MyEntityDetectorType.Sphere;
                m_radius = sphereSensorElement.Radius;
            }
            else if (type == MyMwcObjectBuilder_EntityDetector_TypesEnum.Box)
            {
                MyBoxSensorElement boxSensorElement = new MyBoxSensorElement();
                boxSensorElement.Size = size;
                sensorElement = boxSensorElement;
                EntityDetectorType = MyEntityDetectorType.Box;
                m_extent = size / 2f;
            }
            else
            {
                throw new MyMwcExceptionApplicationShouldNotGetHere();
            }

            sensorElement.LocalPosition = Vector3.Zero;
            MySensorDesc senDesc = new MySensorDesc();
            senDesc.m_Element = sensorElement;
            senDesc.m_Matrix = Matrix.Identity;
            senDesc.m_SensorEventHandler = this;
            m_sensor.Inserted = false;
            m_sensor.LoadFromDesc(senDesc);
            m_sensor.Active = true;
            m_size = size;           
        }