Table of Contents

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() - A Ray from 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 a Ray.
  • CalculateRayPlaneIntersectionPoint() - Where that ray crosses the Z=0 plane, as a Vector2. 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 by w.
  • ScreenToWorldRaySegment() - The ray as a RaySegment from the near plane to the far plane, which is the form the Bepu and Bullet Simulation raycast 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 than WorldToScreenPoint().
  • 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 a HitInfo.
  • 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.