MCPcopy Create free account
hub / github.com/defold/defold / PickNode

Function PickNode

engine/gui/src/gui.cpp:4311–4339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4309 }
4310
4311 bool PickNode(HScene scene, HNode node, float x, float y)
4312 {
4313 Vector4 scale((float) scene->m_Context->m_PhysicalWidth / (float) scene->m_Context->m_DefaultProjectWidth,
4314 (float) scene->m_Context->m_PhysicalHeight / (float) scene->m_Context->m_DefaultProjectHeight, 1, 1);
4315 Matrix4 transform;
4316 InternalNode* n = GetNode(scene, node);
4317 CalculateNodeTransform(scene, n, CalculateNodeTransformFlags(CALCULATE_NODE_BOUNDARY | CALCULATE_NODE_INCLUDE_SIZE | CALCULATE_NODE_RESET_PIVOT), transform);
4318 // DEF-3066 set Z scale to 1.0 to get a sound inverse node transform for picking
4319 transform.setElem(2, 2, 1.0f);
4320 transform = inverse(transform);
4321 Vector4 screen_pos(x * scale.getX(), y * scale.getY(), 0.0f, 1.0f);
4322 Vector4 node_pos = transform * screen_pos;
4323 const float EPSILON = 0.0001f;
4324 // check if we need to project the local position to the node plane
4325 if (dmMath::Abs(node_pos.getZ()) > EPSILON)
4326 {
4327 Vector4 ray_dir = transform.getCol2();
4328 // falsify if node is almost orthogonal to the screen plane, impossible to pick
4329 if (dmMath::Abs(ray_dir.getZ()) < 0.0001f)
4330 {
4331 return false;
4332 }
4333 node_pos -= ray_dir * (node_pos.getZ() / ray_dir.getZ());
4334 }
4335 return node_pos.getX() >= 0.0f
4336 && node_pos.getX() <= 1.0f
4337 && node_pos.getY() >= 0.0f
4338 && node_pos.getY() <= 1.0f;
4339 }
4340
4341 bool IsNodeEnabled(HScene scene, HNode node, bool recursive)
4342 {

Callers 1

LuaPickNodeFunction · 0.70

Calls 9

AbsFunction · 0.85
GetNodeFunction · 0.70
CalculateNodeTransformFunction · 0.70
inverseFunction · 0.50
getXMethod · 0.45
getYMethod · 0.45
getZMethod · 0.45
getCol2Method · 0.45

Tested by

no test coverage detected