MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / OnMouseClick

Method OnMouseClick

GTE/Samples/SceneGraphs/Castle/CastleWindow3.cpp:142–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142bool CastleWindow3::OnMouseClick(MouseButton button, MouseState state, int32_t x, int32_t y, uint32_t)
143{
144 if (button == MOUSE_LEFT && state == MOUSE_DOWN)
145 {
146 // Do a picking operation. Reflect y to obtain right-handed window
147 // coordinates.
148 y = mYSize - 1 - y;
149 int32_t viewX, viewY, viewW, viewH;
150 mEngine->GetViewport(viewX, viewY, viewW, viewH);
151 Vector4<float> origin, direction;
152 if (mCamera->GetPickLine(viewX, viewY, viewW, viewH, x, y, origin, direction))
153 {
154 // Use a ray for picking.
155 float tmin = 0.0f;
156 float constexpr tmax = std::numeric_limits<float>::max();
157
158 // We care only about intersecting a mesh, so request model-space
159 // coordinates to avoid computing world-space information.
160 mPicker(mScene, origin, direction, tmin, tmax);
161 if (mPicker.records.size() > 0)
162 {
163 // Display the selected object's name.
164 PickRecord const& record = mPicker.GetClosestNonnegative();
165 mPickMessage = record.visual->name;
166 }
167 else
168 {
169 mPickMessage = "";
170 }
171 }
172 return true;
173 }
174
175 return false;
176}
177
178bool CastleWindow3::SetEnvironment()
179{

Callers

nothing calls this directly

Calls 2

GetPickLineMethod · 0.80
GetViewportMethod · 0.45

Tested by

no test coverage detected