Camera Extensions
Extension methods for CameraComponent. They fall into two halves: converting between screen and world space, which needs no physics engine, and raycasting into the scene, which does - so those live in the Bepu and Bullet packages.
Screen and world space
In the Stride.CommunityToolkit.Engine namespace. Screen positions here are normalized: (0,0) is the bottom-left of the viewport and (1,1) the top-right.
GetPickRay()- ARayfrom the camera through a screen point. The usual starting point for object picking.CalculateRayFromScreenPosition()- The same ray as a(nearPoint, farPoint)pair of world positions, when you want the endpoints rather than aRay.CalculateRayPlaneIntersectionPoint()- Where that ray crosses theZ=0plane, as aVector2. This is how you turn a mouse position into a 2D world position without any physics at all.ScreenPointToRay()- The near and far vectors of the ray, unprojected but not yet divided through byw.ScreenToWorldRaySegment()- The ray as aRaySegmentfrom the near plane to the far plane, which is the form the Bepu and BulletSimulationraycast helpers take.ScreenToWorldPoint()- Converts a screen position with a depth to a world position.WorldToScreenPoint()- The inverse: where a world position lands on screen. Use this to hang a label on an object.WorldToClip()- Converts a world position to clip space, one step earlier thanWorldToScreenPoint().LogicDirectionToWorldDirection()- Turns a 2D input direction into a world direction relative to where the camera is facing, so "forward" on a gamepad stick means forward on screen. An overload takes an explicit up vector.
Note
Most of these have in/out overloads that avoid copying vectors, and WorldToScreenPoint() has one
taking a GraphicsDevice when you want pixels rather than normalized coordinates. See the
API reference for the full set.
Raycasting - Bepu
In the Stride.CommunityToolkit.Bepu namespace.
Raycast()- Casts from the camera through a screen position and reports the first hit as aHitInfo.RaycastMouse()- The same, reading the mouse position for you.
Raycasting - Bullet
In the Stride.CommunityToolkit.Bullet namespace. Both take either a ScriptComponent or a Simulation and return a HitResult.
Raycast()- Casts from the camera through a screen position, filtered by collision group.RaycastMouse()- The same, reading the mouse position for you.