public static bool DefaultGizmoCloseEnough(ref MatrixD invGridWorldMatrix, BoundingBoxD gizmoBox, float gridSize, float intersectionDistance)
        {
            //MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 0.0f), "Intersection distance = " + intersectionDistance, Color.Red, 1.0f);

            var m = invGridWorldMatrix;

            MyCharacter character = MySession.LocalCharacter;
            if (character == null)
                return false;

            // Character head for measuring distance to intesection.
            Vector3D originHead = character.GetHeadMatrix(true).Translation;
            // Camera position adn direction. Used for ray cast to cube block box.
            Vector3D originCamera = MySector.MainCamera.Position;
            Vector3 direction = MySector.MainCamera.ForwardVector;

            Vector3 localHead = Vector3D.Transform(originHead, m);
            Vector3 localStart = Vector3D.Transform(originCamera, m);
            Vector3 localEnd = Vector3D.Transform(originCamera + direction * intersectionDistance, m);
            LineD line = new LineD(localStart, localEnd);

            // AABB of added block
            float inflate = 0.025f * gridSize;
            gizmoBox.Inflate(inflate);

            /*{
                Vector4 blue = Color.Blue.ToVector4();
                Matrix mtx = Matrix.Invert(invGridWorldMatrix);
                MySimpleObjectDraw.DrawTransparentBox(ref mtx, ref gizmoBox, ref blue, MySimpleObjectRasterizer.Wireframe, 1, 0.04f);
            }*/

            double distance = double.MaxValue;
            if (gizmoBox.Intersects(line, out distance))
            {
                // Distance from the player's head to the gizmo box.
                double distanceToPlayer = gizmoBox.Distance(localHead);
                return distanceToPlayer <= 5.0;
            }
            return false;
        }
 internal float CalculateCameraDistance()
 {
     return((float)Aabb.Distance(MyRender11.Environment.Matrices.CameraPosition));
 }
Exemple #3
0
 internal float CalculateCameraDistance()
 {
     return((float)Aabb.Distance(MyEnvironment.CameraPosition));
 }
        public static bool DefaultGizmoCloseEnough(ref MatrixD invGridWorldMatrix, BoundingBoxD gizmoBox, float gridSize, float intersectionDistance)
        {
            //MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 0.0f), "Intersection distance = " + intersectionDistance, Color.Red, 1.0f);

            var m = invGridWorldMatrix;

            MyCharacter character = MySession.Static.LocalCharacter;
            if (character == null)
                return false;

            // Character head for measuring distance to intesection.
            Vector3D originHead = character.GetHeadMatrix(true).Translation;
            // Camera position adn direction. Used for ray cast to cube block box.
            Vector3D originCamera = MySector.MainCamera.Position;
            Vector3 direction = MySector.MainCamera.ForwardVector;

            double cameraHeadDist = (originHead - MySector.MainCamera.Position).Length();

            Vector3 localHead = Vector3D.Transform(originHead, m);
            Vector3 localStart = Vector3D.Transform(originCamera, m);
            Vector3 localEnd = Vector3D.Transform(originCamera + direction * (intersectionDistance + (float)cameraHeadDist), m);
            LineD line = new LineD(localStart, localEnd);

            // AABB of added block
            float inflate = 0.025f * gridSize;
            gizmoBox.Inflate(inflate);

            //{
            //    Color blue = Color.Blue;
            //    MatrixD mtx = MatrixD.Invert(invGridWorldMatrix);
            //    MySimpleObjectDraw.DrawTransparentBox(ref mtx, ref gizmoBox, ref blue, MySimpleObjectRasterizer.Wireframe, 1, 0.04f);



            //    MyRenderProxy.DebugDrawLine3D(originCamera, originCamera + direction * (intersectionDistance + (float)cameraHeadDist), Color.Red, Color.Red, false);
            //}

            double distance = double.MaxValue;
            if (gizmoBox.Intersects(ref line, out distance))
            {
                // Distance from the player's head to the gizmo box.
                double distanceToPlayer = gizmoBox.Distance(localHead);
                if (MySession.Static.ControlledEntity is MyShipController)
                {
                    if (MyCubeBuilder.Static.CubeBuilderState.CurrentBlockDefinition.CubeSize == MyCubeSize.Large)
                        return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistLargeSurvivalShip;
                    else
                        return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistSmallSurvivalShip;
                }
                else
                {
                    if (MyCubeBuilder.Static.CubeBuilderState.CurrentBlockDefinition.CubeSize == MyCubeSize.Large)
                        return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistLargeSurvivalCharacter;
                    else
                        return distanceToPlayer <= MyCubeBuilder.CubeBuilderDefinition.BuildingDistSmallSurvivalCharacter;
                }
            }
            return false;
        }