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


C# Camera.GetCameraToViewportRay方法代码示例

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


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

示例1: RenderEntityOverCursor

        void RenderEntityOverCursor(Camera camera)
        {
            Vec2 mouse = renderTarget.GetFloatMousePosition();
            _mouseOver = null;

            if (mouse.X < 0 || mouse.X > 1 || mouse.Y < 0 || mouse.Y > 1)
                _worldViewModel.ClearMouseOverEntity();
            else
            {
                // Find entity under cursor of mouse
                Ray ray = camera.GetCameraToViewportRay(mouse);
                Map.Instance.GetObjects(ray, delegate(MapObject obj, float scale)
                {
                    if (!(obj.UserData is int))
                        return true;
                    _mouseOver = obj;
                    return false;
                });

                if (_mouseOver != null)
                {
                    // Put a yellow box around it and a tooltip
                    camera.DebugGeometry.Color = new ColorValue(1, 1, 0);
                    camera.DebugGeometry.AddBounds(_mouseOver.MapBounds);
                    _worldViewModel.WorldNavigation.MouseOverEntity = (int)_mouseOver.UserData;
                }
                else
                    _worldViewModel.ClearMouseOverEntity();

                // TODO: after removing the physical bodies, this ray-cast never hits anything of course...
                RayCastResult result = PhysicsWorld.Instance.RayCast(ray, (int)ContactGroup.CastOnlyCollision);
                _mouseIntersection = result.Position;
                if (result.Shape != null)
                {
                    camera.DebugGeometry.Color = new ColorValue(1, 0, 0);
                    camera.DebugGeometry.AddSphere(new Sphere(result.Position, 0.2f));
                }
            }
            SetToolTipString();

            // Show all selected entities with a blue box around them
            // except MouseOver as it will be yellow
            camera.DebugGeometry.Color = new ColorValue(0.5f, 0.5f, 1);
            foreach (MapObject mo in _worldViewModel.WorldNavigation.SelectedEntities
                .Select(x => Entities.Instance.GetByName(x.ToString()))
                .OfType<MapObject>()
                .Where(mo => mo != _mouseOver))
                camera.DebugGeometry.AddBounds(mo.MapBounds);
        }
开发者ID:timothypratley,项目名称:Strive.NET,代码行数:49,代码来源:PerspectiveView.xaml.cs

示例2: Pick

        // intersects objects in scene with ray from screen coords: x, y
        public static RaySceneQueryResult Pick(SceneManager mgr, int x, int y, Viewport vp, Camera cam)
        {
            //normalise mouse coordinates to [0,1]
            //we could have used the panel's width/height in pixels instead of viewport's width/height
            float scrx = (float)x / vp.ActualWidth;
            float scry = (float)y / vp.ActualHeight;

            Ray ray = cam.GetCameraToViewportRay(scrx, scry);
            RaySceneQuery query = mgr.CreateRayQuery(ray);
            RaySceneQueryResult results = query.Execute();
            return results;
        }
开发者ID:RainsSoft,项目名称:ogreflow,代码行数:13,代码来源:Utils.cs

示例3: RaycastFromCamera

        public RaycastResult RaycastFromCamera(RenderWindow window, Camera camera, Vector2 point, uint queryMask)
        {
            // Create the ray to test
                float tx = point.x / window.Width;
                float ty = point.y / window.Height;
                Ray ray = camera.GetCameraToViewportRay(tx, ty);

                return this.Raycast(ray, queryMask);
        }
开发者ID:aRkker,项目名称:Survival,代码行数:9,代码来源:CollisionTools.cs


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