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


C# Bounds.RayIntersection方法代码示例

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


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

示例1: DrawObjectSelectionBorder

        private void DrawObjectSelectionBorder(Bounds bounds)
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;
            GuiRenderer renderer = EngineApp.Instance.ScreenGuiRenderer;

            Texture texture = TextureManager.Instance.Load("Gui\\Textures\\ObjectSelectionBorder.png");
            Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

            float sizeY = .08f;
            Vec2 size = SnapToPixel(new Vec2(sizeY / camera.AspectRatio, sizeY), viewportSize);
            float alpha = MathFunctions.Sin(Time * MathFunctions.PI) * .5f + .5f;

            Rect screenRectangle = Rect.Cleared;
            {
                Vec3[] points = null;
                bounds.ToPoints(ref points);
                foreach (Vec3 point in points)
                {
                    Vec2 screenPoint;
                    if (camera.ProjectToScreenCoordinates(point, out screenPoint))
                    {
                        screenPoint.Clamp(new Vec2(0, 0), new Vec2(1, 1));
                        screenRectangle.Add(screenPoint);
                    }
                }

                Vec2[] screenPositions = new Vec2[] {
					new Vec2( 0, 0 ),
					new Vec2( 1, 0 ),
					new Vec2( 0, 1 ),
					new Vec2( 1, 1 ) };
                foreach (Vec2 screenPosition in screenPositions)
                {
                    Ray ray = camera.GetCameraToViewportRay(screenPosition);
                    if (bounds.RayIntersection(ray))
                        screenRectangle.Add(screenPosition);
                }

                if (screenRectangle.GetSize().X < size.X * 2)
                {
                    screenRectangle = new Rect(
                        screenRectangle.GetCenter().X - size.X, screenRectangle.Top,
                        screenRectangle.GetCenter().X + size.X, screenRectangle.Bottom);
                }
                if (screenRectangle.GetSize().Y < size.Y * 2)
                {
                    screenRectangle = new Rect(
                        screenRectangle.Left, screenRectangle.GetCenter().Y - size.Y,
                        screenRectangle.Right, screenRectangle.GetCenter().Y + size.Y);
                }
            }

            {
                Vec2 point = screenRectangle.LeftTop;
                point = SnapToPixel(point, viewportSize) + new Vec2(.25f, .25f) / viewportSize;
                Rect rectangle = new Rect(point, point + size);
                Rect texCoord = new Rect(0, 0, .5f, .5f);
                renderer.AddQuad(rectangle, texCoord, texture, new ColorValue(1, 1, 1, alpha), true);
            }

            {
                Vec2 point = screenRectangle.RightTop;
                point = SnapToPixel(point, viewportSize) + new Vec2(.25f, .25f) / viewportSize;
                Rect rectangle = new Rect(point - new Vec2(size.X, 0), point + new Vec2(0, size.Y));
                Rect texCoord = new Rect(.5f, 0, 1, .5f);
                renderer.AddQuad(rectangle, texCoord, texture, new ColorValue(1, 1, 1, alpha), true);
            }

            {
                Vec2 point = screenRectangle.LeftBottom;
                point = SnapToPixel(point, viewportSize) + new Vec2(.25f, .25f) / viewportSize;
                Rect rectangle = new Rect(point - new Vec2(0, size.Y), point + new Vec2(size.X, 0));
                Rect texCoord = new Rect(0, .5f, .5f, 1);
                renderer.AddQuad(rectangle, texCoord, texture, new ColorValue(1, 1, 1, alpha), true);
            }

            {
                Vec2 point = screenRectangle.RightBottom;
                point = SnapToPixel(point, viewportSize) + new Vec2(.25f, .25f) / viewportSize;
                Rect rectangle = new Rect(point - size, point);
                Rect texCoord = new Rect(.5f, .5f, 1, 1);
                renderer.AddQuad(rectangle, texCoord, texture, new ColorValue(1, 1, 1, alpha), true);
            }
        }
开发者ID:AKNightHawk,项目名称:AssaultKnights2,代码行数:84,代码来源:ActionGameWindow.cs


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