本文整理汇总了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);
}
示例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;
}
示例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);
}