当前位置: 首页>>代码示例>>C#>>正文


C# BoundingBoxD.Distance方法代码示例

本文整理汇总了C#中BoundingBoxD.Distance方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBoxD.Distance方法的具体用法?C# BoundingBoxD.Distance怎么用?C# BoundingBoxD.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingBoxD的用法示例。


在下文中一共展示了BoundingBoxD.Distance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DefaultGizmoCloseEnough

        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;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:40,代码来源:MyCubeBuilderGizmo.cs

示例2: DefaultGizmoCloseEnough

        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;
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:59,代码来源:MyCubeBuilderGizmo.cs


注:本文中的BoundingBoxD.Distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。