| 163 | } |
| 164 | |
| 165 | static int unProject(float winx, float winy, float winz, const Matrix& invTransform, const float viewport[4], Vec3& objectCoordinate) { |
| 166 | Vec4 in, out; |
| 167 | // Transformation of normalized coordinates between -1 and 1 |
| 168 | in.x = (winx - viewport[0]) / viewport[2] * 2.0f - 1.0f; |
| 169 | in.y = (winy - viewport[1]) / viewport[3] * 2.0f - 1.0f; |
| 170 | in.z = 2.0f * winz - 1.0f; |
| 171 | in.w = 1.0f; |
| 172 | // Objects coordinates |
| 173 | Matrix::mulVec4(out, invTransform, in); |
| 174 | if (out.w == 0.0f) { |
| 175 | return 0; |
| 176 | } |
| 177 | out.w = 1.0f / out.w; |
| 178 | objectCoordinate.x = out.x * out.w; |
| 179 | objectCoordinate.y = out.y * out.w; |
| 180 | objectCoordinate.z = out.z * out.w; |
| 181 | return 1; |
| 182 | } |
| 183 | |
| 184 | Vec2 NodeTouchHandler::getPos(const Vec3& winPos) { |
| 185 | Vec3 pos = winPos; |