MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / mapMouseCoordinatesToSphere

Method mapMouseCoordinatesToSphere

testbed/src/Scene.cpp:76–95  ·  view source on GitHub ↗

Map the mouse x,y coordinates to a point on a sphere

Source from the content-addressed store, hash-verified

74
75// Map the mouse x,y coordinates to a point on a sphere
76bool Scene::mapMouseCoordinatesToSphere(double xMouse, double yMouse,
77 Vector3& spherePoint) const {
78
79 if ((xMouse >= 0) && (xMouse <= mWindowWidth) && (yMouse >= 0) && (yMouse <= mWindowHeight)) {
80 float x = float(xMouse - 0.5f * mWindowWidth) / float(mWindowWidth);
81 float y = float(0.5f * mWindowHeight - yMouse) / float(mWindowHeight);
82 float sinx = std::sin(PI * x * 0.5f);
83 float siny = std::sin(PI * y * 0.5f);
84 float sinx2siny2 = sinx * sinx + siny * siny;
85
86 // Compute the point on the sphere
87 spherePoint.x = sinx;
88 spherePoint.y = siny;
89 spherePoint.z = (sinx2siny2 < 1.0f) ? std::sqrt(1.0f - sinx2siny2) : 0.0f;
90
91 return true;
92 }
93
94 return false;
95}
96
97// Called when a mouse button event occurs
98bool Scene::mouseButtonEvent(int /*button*/, bool down, int /*mods*/, double mousePosX, double mousePosY) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected