本文整理汇总了C#中Engine.Camera.GetCameraToViewportRay方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.GetCameraToViewportRay方法的具体用法?C# Camera.GetCameraToViewportRay怎么用?C# Camera.GetCameraToViewportRay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine.Camera
的用法示例。
在下文中一共展示了Camera.GetCameraToViewportRay方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderEntityOverCursor
void RenderEntityOverCursor( Camera camera )
{
Vec2 mouse = renderTargetUserControl1.GetFloatMousePosition();
Ray ray = camera.GetCameraToViewportRay( mouse );
MapObject mapObject = null;
Map.Instance.GetObjects( ray, delegate( MapObject obj, float scale )
{
if( obj is StaticMesh )
return true;
mapObject = obj;
return false;
} );
if( mapObject != null )
{
camera.DebugGeometry.Color = new ColorValue( 1, 1, 0 );
camera.DebugGeometry.AddBounds( mapObject.MapBounds );
}
}
示例2: 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 == null || !(obj.UserData is EntityModel))
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.SetMouseOverEntity(((EntityModel)_mouseOver.UserData).Id);
}
else
_worldViewModel.ClearMouseOverEntity();
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.SelectedEntities
.Select(evm => Entities.Instance.GetByName(evm.Entity.Id.ToString()))
.OfType<MapObject>()
.Where(mo => mo != _mouseOver))
camera.DebugGeometry.AddBounds(mo.MapBounds);
}