コード例 #1
0
        private ProjectionRaycastData FindProjectedBlock()
        {
            if (Owner != null)
            {
                Vector3D startPosition = Sensor.Center;
                Vector3D forward       = Sensor.FrontPoint - Sensor.Center;
                forward.Normalize();

                //Increased welder distance when projecting because it was hard to build on large grids
                float      welderDistance = m_toolActionDistance * m_toolActionDistance * 2.0f;
                Vector3D   endPosition    = startPosition + forward * welderDistance;
                LineD      line           = new LineD(startPosition, endPosition);
                MyCubeGrid projectionGrid;
                Vector3I   blockPosition;
                double     distanceSquared;
                if (MyCubeGrid.GetLineIntersection(ref line, out projectionGrid, out blockPosition, out distanceSquared))
                {
                    if (projectionGrid.Projector != null)
                    {
                        var projector = projectionGrid.Projector;

                        var blocks = projectionGrid.RayCastBlocksAllOrdered(startPosition, endPosition);

                        ProjectionRaycastData?farthestVisibleBlock = null;

                        for (int i = blocks.Count - 1; i >= 0; i--)
                        {
                            var projectionBlock = blocks[i];
                            var canBuild        = projector.CanBuild(projectionBlock.CubeBlock, true);
                            if (canBuild == MyProjector.BuildCheckResult.OK)
                            {
                                farthestVisibleBlock = new ProjectionRaycastData
                                {
                                    raycastResult = canBuild,
                                    hitCube       = projectionBlock.CubeBlock,
                                    cubeProjector = projector,
                                };
                            }
                            else if (canBuild == MyProjector.BuildCheckResult.AlreadyBuilt)
                            {
                                farthestVisibleBlock = null;
                            }
                        }

                        if (farthestVisibleBlock.HasValue)
                        {
                            return(farthestVisibleBlock.Value);
                        }
                    }
                }
            }
            return(new ProjectionRaycastData
            {
                raycastResult = MyProjector.BuildCheckResult.NotFound,
            });
        }
コード例 #2
0
        private ProjectionRaycastData FindProjectedBlock()
        {
            if (Owner != null)
            {
                Vector3D startPosition = m_raycastComponent.Caster.Center;
                Vector3D forward       = m_raycastComponent.Caster.FrontPoint - m_raycastComponent.Caster.Center;
                forward.Normalize();

                // Welder distance is now in caster.
                float      welderDistance = DEFAULT_REACH_DISTANCE * m_distanceMultiplier;
                Vector3D   endPosition    = startPosition + forward * welderDistance;
                LineD      line           = new LineD(startPosition, endPosition);
                MyCubeGrid projectionGrid;
                Vector3I   blockPosition;
                double     distanceSquared;
                if (MyCubeGrid.GetLineIntersection(ref line, out projectionGrid, out blockPosition, out distanceSquared))
                {
                    if (projectionGrid.Projector != null)
                    {
                        var projector = projectionGrid.Projector;

                        var blocks = projectionGrid.RayCastBlocksAllOrdered(startPosition, endPosition);

                        ProjectionRaycastData?farthestVisibleBlock = null;

                        for (int i = blocks.Count - 1; i >= 0; i--)
                        {
                            var projectionBlock = blocks[i];
                            var canBuild        = projector.CanBuild(projectionBlock.CubeBlock, true);
                            if (canBuild == MyProjectorBase.BuildCheckResult.OK)
                            {
                                farthestVisibleBlock = new ProjectionRaycastData
                                {
                                    raycastResult = canBuild,
                                    hitCube       = projectionBlock.CubeBlock,
                                    cubeProjector = projector,
                                };
                            }
                            else if (canBuild == MyProjectorBase.BuildCheckResult.AlreadyBuilt)
                            {
                                farthestVisibleBlock = null;
                            }
                        }

                        if (farthestVisibleBlock.HasValue)
                        {
                            return(farthestVisibleBlock.Value);
                        }
                    }
                }
            }
            return(new ProjectionRaycastData
            {
                raycastResult = MyProjectorBase.BuildCheckResult.NotFound,
            });
        }
コード例 #3
0
ファイル: MyWelder.cs プロジェクト: Chrus/SpaceEngineers
        private ProjectionRaycastData FindProjectedBlock()
        {
            if (Owner != null)
            {
                Vector3D startPosition = m_raycastComponent.Caster.Center;
                Vector3D forward = m_raycastComponent.Caster.FrontPoint - m_raycastComponent.Caster.Center;
                forward.Normalize();

                // Welder distance is now in caster.
                float welderDistance = DEFAULT_REACH_DISTANCE * m_distanceMultiplier;
                Vector3D endPosition = startPosition + forward * welderDistance;
                LineD line = new LineD(startPosition, endPosition);
                MyCubeGrid projectionGrid;
                Vector3I blockPosition;
                double distanceSquared;
                if (MyCubeGrid.GetLineIntersection(ref line, out projectionGrid, out blockPosition, out distanceSquared))
                {
                    if (projectionGrid.Projector != null)
                    {
                        var projector = projectionGrid.Projector;

                        var blocks = projectionGrid.RayCastBlocksAllOrdered(startPosition, endPosition);

                        ProjectionRaycastData? farthestVisibleBlock = null;

                        for (int i = blocks.Count - 1; i >= 0; i--)
                        {
                            var projectionBlock = blocks[i];
                            var canBuild = projector.CanBuild(projectionBlock.CubeBlock, true);
                            if (canBuild == BuildCheckResult.OK)
                            {
                                farthestVisibleBlock = new ProjectionRaycastData
                                {
                                    raycastResult = canBuild,
                                    hitCube = projectionBlock.CubeBlock,
                                    cubeProjector = projector,
                                };
                            }
                            else if (canBuild == BuildCheckResult.AlreadyBuilt)
                            {
                                farthestVisibleBlock = null;
                            }
                        }

                        if (farthestVisibleBlock.HasValue)
                        {
                            return farthestVisibleBlock.Value;
                        }
                    }
                }
            }
            return new ProjectionRaycastData
            {
                raycastResult = BuildCheckResult.NotFound,
            };
        }
コード例 #4
0
ファイル: MyWelder.cs プロジェクト: martejj/SpaceEngineers
        private ProjectionRaycastData FindProjectedBlock()
        {
            if (Owner != null)
            {
                Vector3D startPosition = Sensor.Center;
                Vector3D forward = Sensor.FrontPoint - Sensor.Center;
                forward.Normalize();

                //Increased welder distance when projecting because it was hard to build on large grids
                float welderDistance = m_toolActionDistance * m_toolActionDistance * 2.0f;
                Vector3D endPosition = startPosition + forward * welderDistance;
                LineD line = new LineD(startPosition, endPosition);
                MyCubeGrid projectionGrid;
                Vector3I blockPosition;
                double distanceSquared;
                if (MyCubeGrid.GetLineIntersection(ref line, out projectionGrid, out blockPosition, out distanceSquared))
                {
                    if (projectionGrid.Projector != null)
                    {
                        var projector = projectionGrid.Projector;

                        var blocks = projectionGrid.RayCastBlocksAllOrdered(startPosition, endPosition);

                        ProjectionRaycastData? farthestVisibleBlock = null;

                        for (int i = blocks.Count - 1; i >= 0; i--)
                        {
                            var projectionBlock = blocks[i];
                            var canBuild = projector.CanBuild(projectionBlock.CubeBlock, true);
                            if (canBuild == MyProjector.BuildCheckResult.OK)
                            {
                                farthestVisibleBlock = new ProjectionRaycastData
                                {
                                    raycastResult = canBuild,
                                    hitCube = projectionBlock.CubeBlock,
                                    cubeProjector = projector,
                                };
                            }
                            else if (canBuild == MyProjector.BuildCheckResult.AlreadyBuilt)
                            {
                                farthestVisibleBlock = null;
                            }
                        }

                        if (farthestVisibleBlock.HasValue)
                        {
                            return farthestVisibleBlock.Value;
                        }
                    }
                }
            }
            return new ProjectionRaycastData
            {
                raycastResult = MyProjector.BuildCheckResult.NotFound,
            };
        }