コード例 #1
0
        private static bool IsTargetVisible(MySmallShip smallShip, MyEntity otherEntity)
        {
            MyLine line = new MyLine(smallShip.WorldVolume.Center, otherEntity.GetPosition(), true);
            MyIntersectionResultLineTriangleEx?result = MyEntities.GetIntersectionWithLine(ref line, smallShip, null, ignoreChilds: true);

            return(result != null && result.Value.Entity.GetBaseEntity() == otherEntity);
        }
コード例 #2
0
        //  Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned.
        internal override bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx?t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
        {
            t = null;
            return(false);

            //Matrix invWorld = Matrix.Invert(WorldMatrix);
            //Vector3 from = Vector3.Transform(line.From, invWorld);
            //Vector3 to = Vector3.Transform(line.To, invWorld);

            //Line lineLocal = new Line(from, to);

            //bool res = base.GetIntersectionWithLine(ref line, out t, flags);

            //if (res)
            //{
            //    var definition = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(MyObjectBuilderTypeEnum.Ladder));
            //    if (definition.ExcludedAreaForCamera != null)
            //    {
            //        foreach (var b in definition.ExcludedAreaForCamera)
            //        {
            //            if (b.Contains(t.Value.IntersectionPointInObjectSpace) == ContainmentType.Contains)
            //            {
            //                t = null;
            //                return false;
            //            }
            //        }
            //    }
            //}

            //return res;
        }
コード例 #3
0
        private static bool Intersects(MyEntity entity, ref LineD localLine, out MyIntersectionResultLineTriangleEx?result, IntersectionFlags flags = DefaultFlags)
        {
            Logger.TraceLog("Checking entity: " + entity.getBestName() + ", line from: " + localLine.From + ", to: " + localLine.To);

            Logger.DebugLog("entity is a MyCubeGrid, please call the appropriate method", Logger.severity.FATAL, condition: entity is MyCubeGrid);

            Matrix  localMatrix = entity.PositionComp.LocalMatrix;
            Matrix  invLocal; Matrix.Invert(ref localMatrix, out invLocal);
            MatrixD invLocalD = invLocal;

            result = entity.ModelCollision.GetTrianglePruningStructure().GetIntersectionWithLine(entity, ref localLine, ref invLocalD, flags);
            if (result.HasValue)
            {
                return(true);
            }

            if (entity.Subparts != null)
            {
                foreach (MyEntitySubpart part in entity.Subparts.Values)
                {
                    if (Intersects(part, ref localLine, out result, flags))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #4
0
        public bool GetIntersectionWithLine_FullyBuiltProgressModels(ref LineD line, out MyIntersectionResultLineTriangleEx?t, out ushort blockId, IntersectionFlags flags = 3, bool checkZFight = false, bool ignoreGenerated = false)
        {
            t       = 0;
            blockId = 0;
            double maxValue = double.MaxValue;
            bool   flag     = false;

            foreach (KeyValuePair <ushort, MySlimBlock> pair in this.m_mapIdToBlock)
            {
                MySlimBlock block = pair.Value;
                if (!ignoreGenerated || !block.BlockDefinition.IsGeneratedBlock)
                {
                    MyModel modelOnlyData = MyModels.GetModelOnlyData(block.BlockDefinition.Model);
                    if (modelOnlyData != null)
                    {
                        MyIntersectionResultLineTriangleEx?nullable = modelOnlyData.GetTrianglePruningStructure().GetIntersectionWithLine(block.FatBlock, ref line, flags);
                        if (nullable != null)
                        {
                            double num2 = (nullable.Value.IntersectionPointInWorldSpace - line.From).LengthSquared();
                            if ((num2 < maxValue) && (!checkZFight || (maxValue >= (num2 + 0.0010000000474974513))))
                            {
                                maxValue = num2;
                                t        = nullable;
                                blockId  = pair.Key;
                                flag     = true;
                            }
                        }
                    }
                }
            }
            return(flag);
        }
コード例 #5
0
        //  Calculates intersection of line with object.
        public virtual bool GetIntersectionWithLine(ref LineD line, out Vector3D?v, bool useCollisionModel = true, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
        {
            v = null;
            MyModel collisionModel = Model;

            if (useCollisionModel)
            {
                collisionModel = ModelCollision;
            }

            if (collisionModel != null)
            {
                MyIntersectionResultLineTriangleEx?result = collisionModel.GetTrianglePruningStructure().GetIntersectionWithLine(this, ref line, flags);
                if (result != null)
                {
                    v = result.Value.IntersectionPointInWorldSpace;
                    return(true);
                }
            }
            else
            {
                Debug.Assert(false);//this should be overriden by child class if object has no model by default
            }
            return(false);
        }
コード例 #6
0
        public bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx?t, out ushort blockId, IntersectionFlags flags = 3, bool checkZFight = false, bool ignoreGenerated = false)
        {
            t       = 0;
            blockId = 0;
            double maxValue = double.MaxValue;
            bool   flag     = false;

            foreach (KeyValuePair <ushort, MySlimBlock> pair in this.m_mapIdToBlock)
            {
                MyIntersectionResultLineTriangleEx?nullable;
                MySlimBlock block = pair.Value;
                if ((!ignoreGenerated || !block.BlockDefinition.IsGeneratedBlock) && (block.FatBlock.GetIntersectionWithLine(ref line, out nullable, IntersectionFlags.ALL_TRIANGLES) && (nullable != null)))
                {
                    double num2 = (nullable.Value.IntersectionPointInWorldSpace - line.From).LengthSquared();
                    if ((num2 < maxValue) && (!checkZFight || (maxValue >= (num2 + 0.0010000000474974513))))
                    {
                        maxValue = num2;
                        t        = nullable;
                        blockId  = pair.Key;
                        flag     = true;
                    }
                }
            }
            return(flag);
        }
コード例 #7
0
 private void GetHitEntityAndPosition(LineD line, out IMyEntity entity, out Vector3D hitPosition, out Vector3 hitNormal)
 {
     entity      = null;
     hitPosition = hitNormal = Vector3.Zero;
     VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyEntities.GetIntersectionWithLine()");
     m_intersection = MyEntities.GetIntersectionWithLine(ref line, m_ignoreEntity, m_weapon, false, false, true, IntersectionFlags.ALL_TRIANGLES, MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * CHECK_INTERSECTION_INTERVAL);
     VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
     if (m_intersection != null)
     {
         entity      = m_intersection.Value.Entity;
         hitPosition = m_intersection.Value.IntersectionPointInWorldSpace;
         hitNormal   = m_intersection.Value.NormalInWorldSpace;
     }
     if (entity == null)
     {
         var hitRigidBody = MyPhysics.CastRay(line.From, line.To, out hitPosition, out hitNormal);
         entity = hitRigidBody.GetEntity() as MyEntity;
     }
     if (entity == null)
     {
         return;
     }
     if (!(entity is MyCharacter))
     {
         entity = entity.GetTopMostParent();
     }
 }
コード例 #8
0
        public MyIntersectionResultLineTriangleEx?GetIntersectionWithLine(MyEntity physObject, ref MyLine line, ref Matrix customInvMatrix, IntersectionFlags flags)
        {
            MyLine lineInModelSpace = new MyLine(MyUtils.GetTransform(line.From, ref customInvMatrix), MyUtils.GetTransform(line.To, ref customInvMatrix), true);

            MyIntersectionResultLineTriangleEx?ret = m_rootNode.GetIntersectionWithLine(physObject, m_model, ref lineInModelSpace, null, flags);

            return(ret);
        }
コード例 #9
0
        public Sandbox.Common.MyIntersectionResultLineTriangleEx?GetIntersectionWithLine(IMyEntity physObject, ref LineD line, ref MatrixD customInvMatrix, IntersectionFlags flags)
        {
            LineD lineInModelSpace = new LineD(Vector3D.Transform(line.From, ref customInvMatrix), Vector3D.Transform(line.To, ref customInvMatrix));

            MyIntersectionResultLineTriangleEx?ret = m_rootNode.GetIntersectionWithLine(physObject, m_model, ref lineInModelSpace, null, flags);

            return(ret);
        }
コード例 #10
0
        private static bool IsLookAtTarget(MySmallShip smallShip, MyEntity otherEntity)
        {
            if (!MUST_LOOK_AT_TARGET || MySession.Is25DSector)
            {
                return(true);
            }
            float  length = Vector3.Distance(smallShip.WorldVolume.Center, otherEntity.WorldVolume.Center);
            MyLine line   = new MyLine(smallShip.WorldVolume.Center, smallShip.WorldVolume.Center + smallShip.WorldMatrix.Forward * length * 1.5f, true);
            MyIntersectionResultLineTriangleEx?result = MyEntities.GetIntersectionWithLine(ref line, smallShip, null, ignoreChilds: true);

            return(result != null && result.Value.Entity.GetBaseEntity() == otherEntity);
        }
コード例 #11
0
        public override bool GetIntersectionWithLine(ref MyLine line, out MyIntersectionResultLineTriangleEx?t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
        {
            t = null;
            foreach (MyPrefabBase prefab in m_prefabs)
            {
                MyEntity entity = prefab as MyEntity;
                MyIntersectionResultLineTriangleEx?prefabIntersectionResult;
                entity.GetIntersectionWithLine(ref line, out prefabIntersectionResult);
                t = MyIntersectionResultLineTriangleEx.GetCloserIntersection(ref t, ref prefabIntersectionResult);
            }

            return(t != null);
        }
コード例 #12
0
ファイル: MySunWind.cs プロジェクト: whztt07/Miner-Wars-2081
        private static void ComputeMaxDistance(MySunWindBillboardSmall billboard)
        {
            Vector3 sunWindVector = m_directionFromSunNormalized * MySunWindConstants.SUN_WIND_LENGTH_HALF;
            var     offset        = (-m_directionFromSunNormalized * MySunWindConstants.RAY_CAST_DISTANCE);
            //  This line start where billboard starts and end at place that is farest possible place billboard can reach
            //  If intersection found, we will mark that place as small billboard's destination. It can't go further.
            MyLine line = new MyLine((sunWindVector + billboard.InitialAbsolutePosition) + offset, billboard.InitialAbsolutePosition + m_directionFromSunNormalized * MySunWindConstants.SUN_WIND_LENGTH_TOTAL, true);
            MyIntersectionResultLineTriangleEx?intersection = MyEntities.GetIntersectionWithLine_IgnoreOtherThanSpecifiedClass(ref line, DoNotIgnoreTheseTypes);

            billboard.MaxDistance = (intersection != null) ?
                                    (intersection.Value.Triangle.Distance - billboard.Radius) :
                                    MySunWindConstants.SUN_WIND_LENGTH_TOTAL;
        }
コード例 #13
0
        public MyIntersectionResultLineTriangleEx?GetIntersectionWithLine(ref MyLine line)
        {
            MyIntersectionResultLineTriangleEx?result = null;

            //  Test against childs of this phys object (in this case guns)
            foreach (MyGunBase gun in m_guns)
            {
                MyIntersectionResultLineTriangleEx?intersectionGun = gun.GetIntersectionWithLine(ref line);

                result = MyIntersectionResultLineTriangleEx.GetCloserIntersection(ref result, ref intersectionGun);
            }

            return(result);
        }
コード例 #14
0
 //  Find if distance between two intersections is less than "tolerance distance".
 public static bool IsDistanceLessThanTolerance(ref MyIntersectionResultLineTriangleEx?a, ref MyIntersectionResultLineTriangleEx?b,
                                                float distanceTolerance)
 {
     if (((a == null) && (b != null)) ||
         ((a != null) && (b != null) && (Math.Abs(b.Value.Triangle.Distance - a.Value.Triangle.Distance) <= distanceTolerance)))
     {
         return(true);
     }
     else
     {
         //  This will be returned also when ((a == null) && (b == null))
         return(false);
     }
 }
コード例 #15
0
        /// <summary>
        /// Returns interstection with line
        /// </summary>
        /// <param name="line">Line</param>
        /// <returns></returns>
        public MyIntersectionResultLineTriangleEx?GetIntersectionWithLine(ref MyLine line)
        {
            MyIntersectionResultLineTriangleEx?result = null;

            //  Test against childs of this phys object (in this case guns)
            foreach (MyGunBase gun in GetMountedWeaponsWithHarvesterAndDrill())
            {
                MyIntersectionResultLineTriangleEx?intersectionGun;
                gun.GetIntersectionWithLine(ref line, out intersectionGun);
                result = MyIntersectionResultLineTriangleEx.GetCloserIntersection(ref result, ref intersectionGun);
            }

            return(result);
        }
コード例 #16
0
 //  Find and return closer intersection of these two. If intersection is null then it's not really an intersection.
 public static MyIntersectionResultLineTriangleEx?GetCloserIntersection(ref MyIntersectionResultLineTriangleEx?a, ref MyIntersectionResultLineTriangleEx?b)
 {
     if (((a == null) && (b != null)) ||
         ((a != null) && (b != null) && (b.Value.Triangle.Distance < a.Value.Triangle.Distance)))
     {
         //  If only "b" contains valid intersection, or when it's closer than "a"
         return(b);
     }
     else
     {
         //  This will be returned also when ((a == null) && (b == null))
         return(a);
     }
 }
コード例 #17
0
        private static void ComputeMaxDistance(MySunWindBillboardSmall billboard)
        {
            Vector3D vectord = -m_directionFromSunNormalized * 30000.0;
            LineD    line    = new LineD(((m_directionFromSunNormalized * 30000.0) + billboard.InitialAbsolutePosition) + vectord, billboard.InitialAbsolutePosition + (m_directionFromSunNormalized * 60000.0));
            MyIntersectionResultLineTriangleEx?nullable = MyEntities.GetIntersectionWithLine(ref line, null, null, false, true, true, IntersectionFlags.ALL_TRIANGLES, 0f, true);

            if (nullable != null)
            {
                billboard.MaxDistance = nullable.Value.Triangle.Distance - billboard.Radius;
            }
            else
            {
                billboard.MaxDistance = 60000f;
            }
        }
コード例 #18
0
        public static MyIntersectionResultLineTriangleEx?GetIntersectionWithLine(ref MyLine line)
        {
            MyIntersectionResultLineTriangleEx?result = null;

            //  Check all voxel maps
            for (int value = 0; value < m_voxelMaps.Count; value++)
            {
                MyIntersectionResultLineTriangleEx?testResultEx;
                m_voxelMaps[value].GetIntersectionWithLine(ref line, out testResultEx);

                //  If intersection occured and distance to intersection is closer to origin than any previous intersection)
                result = MyIntersectionResultLineTriangleEx.GetCloserIntersection(ref result, ref testResultEx);
            }

            return(result);
        }
コード例 #19
0
        public MyIntersectionResultLineTriangleEx?GetIntersectionInNearSpace(MyEntity entity, ref MyLine worldLine, bool convertLine)
        {
            if (!entity.IsVisible())
            {
                return(null);
            }

            MyLine line = worldLine;

            if (convertLine)
            {
                ConvertLineToNearWorldCoordinates(ref line);
            }

            Matrix drawMatrix = entity.GetWorldMatrixForDraw();

            drawMatrix.Translation += MyCamera.Position;
            Matrix worldInv = Matrix.Invert(drawMatrix);

            MyIntersectionResultLineTriangleEx?ret = entity.ModelLod0.GetTrianglePruningStructure().GetIntersectionWithLine(entity, ref line, ref worldInv, IntersectionFlags.ALL_TRIANGLES);

            if (ret == null)
            {
                foreach (MyEntity child in entity.Children)
                {
                    if (!child.IsVisible())
                    {
                        continue;
                    }

                    drawMatrix              = child.GetWorldMatrixForDraw();
                    drawMatrix.Translation += MyCamera.Position;
                    worldInv = Matrix.Invert(drawMatrix);

                    System.Diagnostics.Debug.Assert(!float.IsNaN(worldInv.M11));

                    ret = child.ModelLod0.GetTrianglePruningStructure().GetIntersectionWithLine(child, ref line, ref worldInv, IntersectionFlags.ALL_TRIANGLES);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }

            return(ret);
        }
コード例 #20
0
        /// <summary>
        /// Chceck if ship can see target
        /// </summary>
        /// <param name="position">Target position</param>
        /// <param name="target">Target entity.</param>
        /// <returns>True, if bot can see position.</returns>
        public static MyEntity CanSee(MyEntity source, Vector3 position, MyEntity ignoreEntity)
        {
            MyIntersectionResultLineTriangleEx?result = null;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MySmallShip CanSee");
            //There is 100 multiplier because Epsilon can get lost during transformation inside GetAllIntersectionWithLine
            //and normalization assert then appears
            if ((source.GetPosition() - position).Length() > MyMwcMathConstants.EPSILON * 100.0f)
            {
                var line = new MyLine(source.GetPosition(), position, true);
                result = MyEntities.GetIntersectionWithLine(ref line, source, ignoreEntity, ignoreChilds: true);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            return(result.HasValue ? result.Value.Entity : null);
        }
コード例 #21
0
        //  If explosion was with voxels, crease dirt decals in player's cockpit glass
        //  We don't throw random number of debris lines from explosion (because it will be waste). Instead we get intersection line from explosion center to player head,
        //  which should intersect the cockpit glass. Plus we move player head by random vector.
        void CreateDirtDecalOnCockpitGlass(ref BoundingSphere explosionSphere)
        {
            MySmallShip player      = MySession.PlayerShip;
            float       maxDistance = m_explosionSphere.Radius * MyExplosionsConstants.EXPLOSION_RADIUS_MULTPLIER_FOR_DIRT_GLASS_DECALS;
            float       distance    = Vector3.Distance(player.GetPosition(), explosionSphere.Center) - player.ModelLod0.BoundingSphere.Radius;

            //  Decal interpolator - based on distance to explosion, range <0..1>
            //  But then increased because we aren't able to reach max distance so we need to help it little bit
            float interpolator = 1 - MathHelper.Clamp(distance / maxDistance, 0, 1);

            interpolator = (float)Math.Pow(interpolator, 3f);

            //  Don't create dirt decal if we are too far
            if (interpolator <= 0.0f)
            {
                return;
            }

            //  Chech intersection between explosion and player's head. BUT move the line in player's head direction, because we don't want to make intersection with object which caused the explosion
            //MyLine line = new MyLine(intersection.IntersectionPointInWorldSpace, player.GetPosition(), true);
            //MyLine line = new MyLine(intersection.IntersectionPointInWorldSpace, MyCamera.m_initialSunWindPosition, true);
            //Vector3 playerHeadPositionWorld = MyUtils.GetTransform(MyFakes.PLAYER_HEAD_FOR_COCKPIT_INTERIOR_FAKE_TRANSLATION * -1, ref player.WorldMatrix);
            Vector3 playerHeadPositionWorld = player.GetPlayerHeadForCockpitInterior();
            MyLine  line = new MyLine(explosionSphere.Center, playerHeadPositionWorld, true);

            line.From += line.Direction * MyExplosionsConstants.OFFSET_LINE_FOR_DIRT_DECAL;

            MyIntersectionResultLineTriangleEx?glassIntersection = MyEntities.GetIntersectionWithLine_IgnoreOtherThanSpecifiedClass(ref line, new Type[] { typeof(MySmallShip) });

            if ((glassIntersection != null) && (glassIntersection.Value.Entity is MyCockpitGlassEntity))
            {
                //  Decal alpha (never is 1.0f, because we want to see through the dirt)
                float alpha = MathHelper.Clamp(MathHelper.Lerp(0.2f, 1.0f, interpolator) - 0.1f, 0, 1);
                //const float ALPHA_INCREASE = 0.4f;
                //float alpha = 1 - (float)Math.Pow(MathHelper.Clamp(distance / maxDistance, 0, 1), 5);
                //float alpha = (float)MathHelper.SmoothStep(0, 1, 1 - MathHelper.Clamp(distance / maxDistance, 0, 1));
                //float alpha = MathHelper.Clamp(1 - MathHelper.Clamp(distance / maxDistance, 0, 1) + ALPHA_INCREASE, ALPHA_INCREASE, 1);

                //  Decal size
                float size = MathHelper.Lerp(2.5f, 4f, interpolator);

                MyIntersectionResultLineTriangleEx glassIntersection2 = glassIntersection.Value;

                MyCockpitGlassDecals.Add(MyCockpitGlassDecalTexturesEnum.DirtOnGlass, size, MyMwcUtils.GetRandomRadian(), alpha, ref glassIntersection2, true);
            }
        }
コード例 #22
0
ファイル: MySunWind.cs プロジェクト: warex0/SpaceEngineers
        private static void ComputeMaxDistance(MySunWindBillboardSmall billboard)
        {
            Vector3 sunWindVector = m_directionFromSunNormalized * MySunWindConstants.SUN_WIND_LENGTH_HALF;
            var     offset        = (-m_directionFromSunNormalized * MySunWindConstants.RAY_CAST_DISTANCE);
            //  This line start where billboard starts and end at place that is farest possible place billboard can reach
            //  If intersection found, we will mark that place as small billboard's destination. It can't go further.
            LineD line = new LineD((sunWindVector + billboard.InitialAbsolutePosition) + offset, billboard.InitialAbsolutePosition + m_directionFromSunNormalized * MySunWindConstants.SUN_WIND_LENGTH_TOTAL);
            MyIntersectionResultLineTriangleEx?intersection = MyEntities.GetIntersectionWithLine(ref line, null, null);

            if (intersection != null)
            {
                billboard.MaxDistance = (float)(intersection.Value.Triangle.Distance - billboard.Radius);
            }
            else
            {
                billboard.MaxDistance = MySunWindConstants.SUN_WIND_LENGTH_TOTAL;
            }
        }
コード例 #23
0
 private bool IsVisibleFromSun(MyIntersectionResultLineTriangleEx?result)
 {
     if (!MyRender.EnableAsteroidShadows)
     {
         if (result.HasValue && (result.Value.Entity is MyStaticAsteroid) && (result.Value.Entity as MyStaticAsteroid).IsGenerated)
         {
             return(true);
         }
         else
         {
             return(!result.HasValue);
         }
     }
     else
     {
         return(!result.HasValue);
     }
 }
コード例 #24
0
        private void GetHitEntityAndPosition(LineD line, out IMyEntity entity, out Vector3D hitPosition, out Vector3 hitNormal, out bool hitHead)
        {
            entity      = null;
            hitPosition = hitNormal = Vector3.Zero;
            hitHead     = false;

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyEntities.GetIntersectionWithLine()");
            m_intersection = MyEntities.GetIntersectionWithLine(ref line, m_ignoreEntity, m_weapon, false, false, true, IntersectionFlags.ALL_TRIANGLES, MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * CHECK_INTERSECTION_INTERVAL);
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            if (m_intersection != null)
            {
                entity      = m_intersection.Value.Entity;
                hitPosition = m_intersection.Value.IntersectionPointInWorldSpace;
                hitNormal   = m_intersection.Value.NormalInWorldSpace;
            }
            if (entity == null)
            {
                var hitInfo = MyPhysics.CastRay(line.From, line.To);
                if (hitInfo.HasValue)
                {
                    entity      = hitInfo.Value.HkHitInfo.GetHitEntity() as MyEntity;
                    hitPosition = hitInfo.Value.Position;
                    hitNormal   = hitInfo.Value.HkHitInfo.Normal;
                }
            }
            if (entity == null)
            {
                return;
            }

            if (m_projectileAmmoDefinition.HeadShot && entity is MyCharacter)
            {
                MyCharacter hitCharacter = entity as MyCharacter;
                MyIntersectionResultLineTriangleEx?t;
                hitCharacter.GetIntersectionWithLine(ref line, out t, out hitHead);
            }

            if (!(entity is MyCharacter))
            {
                entity = entity.GetTopMostParent();
            }
        }
コード例 #25
0
        private void DebugDrawGeneratingBlock()
        {
            LineD line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * 200);
            MyIntersectionResultLineTriangleEx?intersection = MyEntities.GetIntersectionWithLine(ref line, MySession.LocalCharacter, null);

            if (intersection.HasValue && intersection.Value.Entity is MyCubeGrid)
            {
                MyCubeGrid grid = intersection.Value.Entity as MyCubeGrid;
                MyIntersectionResultLineTriangleEx?t = null;
                MySlimBlock block = null;
                if (grid.GetIntersectionWithLine(ref line, out t, out block) && t.HasValue && block != null)
                {
                    if (block.BlockDefinition.IsGeneratedBlock)
                    {
                        DebugDrawGeneratingBlock(block);
                    }
                }
            }
        }
コード例 #26
0
        private static bool IsCustomLookAtTarget(MySmallShip smallShip, MyEntity otherEntity, float radius)
        {
            if (!MUST_LOOK_AT_TARGET)
            {
                return(true);
            }

            BoundingSphere sphere          = new BoundingSphere(otherEntity.WorldVolume.Center, radius);
            Ray            ray             = new Ray(smallShip.GetPosition(), smallShip.WorldMatrix.Forward);
            float?         rayIntersection = ray.Intersects(sphere);

            if (rayIntersection.HasValue)
            {
                MyLine line = new MyLine(smallShip.WorldVolume.Center, otherEntity.WorldVolume.Center, true);
                MyIntersectionResultLineTriangleEx?result = MyEntities.GetIntersectionWithLine(ref line, smallShip, null, ignoreChilds: true);
                return(!result.HasValue || !result.HasValue || result.Value.Entity == otherEntity);
            }
            return(false);
        }
コード例 #27
0
        /// <summary>
        /// Tests a line for intersection with models of blocks on the grid.
        /// </summary>
        public static bool Intersects(this MySlimBlock slim, ref LineD localLine, out MyIntersectionResultLineTriangleEx?result, IntersectionFlags flags = DefaultFlags)
        {
            Logger.TraceLog("Checking slim block: " + slim.getBestName() + ", line from: " + localLine.From + ", to: " + localLine.To);

            if (slim.FatBlock != null)
            {
                return(Intersects(slim.FatBlock, ref localLine, out result));
            }

            MyCube cube;

            if (!slim.CubeGrid.TryGetCube(slim.Position, out cube))
            {
                throw new Exception("Failed to get MyCube for " + slim.nameWithId());
            }

            foreach (MyCubePart part in cube.Parts)
            {
                Matrix  localMatrix = part.InstanceData.LocalMatrix;
                Matrix  invLocal; Matrix.Invert(ref localMatrix, out invLocal);
                MatrixD invLocalD = invLocal;

                Logger.TraceLog("Checking part: " + part.Model.AssetName + ", line from " + localLine.From + " to " + localLine.To + " becomes " +
                                Vector3D.Transform(localLine.From, ref invLocalD) + " to " + Vector3D.Transform(localLine.To, ref invLocalD));

                result = part.Model.GetTrianglePruningStructure().GetIntersectionWithLine(slim.CubeGrid, ref localLine, ref invLocalD, flags);
                if (result.HasValue)
                {
                    MyIntersectionResultLineTriangleEx value = result.Value;
                    Vector3.Transform(ref value.IntersectionPointInObjectSpace, ref localMatrix, out value.IntersectionPointInObjectSpace);
                    Matrix orientation = localMatrix.GetOrientation();
                    Vector3.Transform(ref value.NormalInObjectSpace, ref orientation, out value.NormalInObjectSpace);

                    result = value;
                    return(true);
                }
            }

            result = null;
            return(false);
        }
コード例 #28
0
        /// <summary>
        /// Tests a line for intersection with models of blocks on the grid.
        /// </summary>
        public static bool Intersects(this MyCubeBlock block, ref LineD localLine, out MyIntersectionResultLineTriangleEx?result, IntersectionFlags flags = DefaultFlags)
        {
            Logger.TraceLog("Checking cube block: " + block.getBestName() + ", line from: " + localLine.From + ", to: " + localLine.To);

            MyCompoundCubeBlock compound = block as MyCompoundCubeBlock;

            if (compound != null)
            {
                foreach (MySlimBlock subBlock in compound.GetBlocks())
                {
                    if (Intersects(subBlock, ref localLine, out result))
                    {
                        return(true);
                    }
                }
                result = null;
                return(false);
            }

            return(Intersects((MyEntity)block, ref localLine, out result, flags));
        }
コード例 #29
0
        //  Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned.
        internal virtual bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx?t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
        {
            bool ret = false;

            t = null;
            MyModel collisionModel = Model;

            if (collisionModel != null)
            {
                VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyEntity.GetIntersectionWithLine on model");
                MyIntersectionResultLineTriangleEx?result = collisionModel.GetTrianglePruningStructure().GetIntersectionWithLine(this, ref line, flags);
                VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
                if (result != null)
                {
                    t   = result.Value;
                    ret = true;
                }
            }

            return(ret);
        }
コード例 #30
0
        private void DebugDrawModelTextures()
        {
            LineD line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * 200);
            MyIntersectionResultLineTriangleEx?intersection = MyEntities.GetIntersectionWithLine(ref line, MySession.LocalCharacter, null);

            if (intersection.HasValue)
            {
                int row = 0;

                if (intersection.Value.Entity is MyCubeGrid)
                {
                    MyCubeGrid grid = intersection.Value.Entity as MyCubeGrid;
                    MyIntersectionResultLineTriangleEx?t = null;
                    MySlimBlock block = null;
                    if (grid.GetIntersectionWithLine(ref line, out t, out block) && t.HasValue && block != null)
                    {
                        DebugDrawModelTextures(block.FatBlock, ref row);
                    }
                }
            }
        }
コード例 #31
0
 private void GetHitEntityAndPosition(LineD line, out IMyEntity entity, out Vector3D hitPosition, out Vector3 hitNormal)
 {
     entity = null;
     hitPosition = hitNormal = Vector3.Zero;
     VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyEntities.GetIntersectionWithLine()");
     m_intersection = MyEntities.GetIntersectionWithLine(ref line, m_ignoreEntity, m_weapon, false, false, true, IntersectionFlags.ALL_TRIANGLES, MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * CHECK_INTERSECTION_INTERVAL);
     VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
     if(m_intersection != null)
     { 
         entity = m_intersection.Value.Entity;
         hitPosition = m_intersection.Value.IntersectionPointInWorldSpace;
         hitNormal = m_intersection.Value.NormalInWorldSpace;
     }
     if (entity == null)
     {
         var hitRigidBody = MyPhysics.CastRay(line.From, line.To, out hitPosition, out hitNormal);
         entity = hitRigidBody.GetEntity() as MyEntity;
     }
     if (entity == null)
         return;
     if (!(entity is MyCharacter))
         entity = entity.GetTopMostParent();
 }
コード例 #32
0
ファイル: MyProjectile.cs プロジェクト: fluxit/SpaceEngineers
        private void GetHitEntityAndPosition(LineD line, out IMyEntity entity, out Vector3D hitPosition, out Vector3 hitNormal, out bool hitHead)
        {
            entity = null;
            hitPosition = hitNormal = Vector3.Zero;
            hitHead = false;

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyEntities.GetIntersectionWithLine()");
            m_intersection = MyEntities.GetIntersectionWithLine(ref line, m_ignoreEntity, m_weapon, false, false, true, IntersectionFlags.ALL_TRIANGLES, MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * CHECK_INTERSECTION_INTERVAL);
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            if(m_intersection != null)
            { 
                entity = m_intersection.Value.Entity;
                hitPosition = m_intersection.Value.IntersectionPointInWorldSpace;
                hitNormal = m_intersection.Value.NormalInWorldSpace;
            }
            if (entity == null)
            {
                var hitInfo = MyPhysics.CastRay(line.From, line.To);
                if (hitInfo.HasValue)
                {
                    entity = hitInfo.Value.HkHitInfo.GetHitEntity() as MyEntity;
                    hitPosition = hitInfo.Value.Position;
                    hitNormal = hitInfo.Value.HkHitInfo.Normal;
                }
            }
            if (entity == null)
                return;

            if (m_projectileAmmoDefinition.HeadShot && entity is MyCharacter)
            {
                MyCharacter hitCharacter = entity as MyCharacter;
                MyIntersectionResultLineTriangleEx? t;
                hitCharacter.GetIntersectionWithLine(ref line, out t, out hitHead);
            }

            if (!(entity is MyCharacter))
                entity = entity.GetTopMostParent();
        }