MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / ScreenRay

Method ScreenRay

utilities/olcUTIL_Hardware3D.h:1212–1228  ·  view source on GitHub ↗

Converts a mouse coordinate into a ray cast from screen location into distance along a line that is obscured by mouse pointer

Source from the content-addressed store, hash-verified

1210 // Converts a mouse coordinate into a ray cast from screen location into
1211 // distance along a line that is obscured by mouse pointer
1212 olc::vf3d ScreenRay(const olc::vf2d& vScreenPos) const
1213 {
1214 // Create parallel ray from screen along projected depth
1215 olc::vf3d ray_parallel = {
1216 (2.0f * vScreenPos.x) / vScreenSize.x - 1.0f,
1217 1.0f - (2.0f * vScreenPos.y) / vScreenSize.y,
1218 1.0f, 1.0f
1219 };
1220 // Invert that screen point into view space
1221 olc::vf3d ray_projected = matProjectionInv * ray_parallel;
1222 ray_projected.w = 0.0f;
1223 // Invert into world space (relative to 0,0,0)
1224 olc::vf3d ray_world = matViewInv * ray_projected;
1225 ray_world.w = 0.0f;
1226 // Return normalised ray to be tidy
1227 return ray_world.norm();
1228 }
1229
1230 protected:
1231

Callers

nothing calls this directly

Calls 1

normMethod · 0.45

Tested by

no test coverage detected