| 182 | } |
| 183 | |
| 184 | Vec2 NodeTouchHandler::getPos(const Vec3& winPos) { |
| 185 | Vec3 pos = winPos; |
| 186 | Size viewSize = SharedView.getSize(); |
| 187 | |
| 188 | Matrix invMVP; |
| 189 | { |
| 190 | Matrix MVP; |
| 191 | Matrix::mulMtx(MVP, SharedDirector.getViewProjection(), _target->getWorld()); |
| 192 | bx::mtxInverse(invMVP.m, MVP.m); |
| 193 | } |
| 194 | bx::Plane plane(bx::InitNone); |
| 195 | bx::calcPlane(plane, bx::Vec3{0, 0, 0}, bx::Vec3{1, 0, 0}, bx::Vec3{0, 1, 0}); |
| 196 | |
| 197 | Vec3 posTarget{pos.x, pos.y, 1.0f}; |
| 198 | float viewPort[4]{0, 0, viewSize.width, viewSize.height}; |
| 199 | |
| 200 | Vec3 origin, target; |
| 201 | unProject(pos.x, pos.y, pos.z, invMVP, viewPort, origin); |
| 202 | unProject(posTarget.x, posTarget.y, posTarget.z, invMVP, viewPort, target); |
| 203 | |
| 204 | bx::Vec3 dir = bx::sub(target, origin); |
| 205 | bx::Vec3 dirNorm = bx::normalize(dir); |
| 206 | float denom = bx::dot(dirNorm, plane.normal); |
| 207 | if (std::abs(denom) >= FLT_EPSILON) { |
| 208 | float nom = bx::dot(origin, plane.normal) + plane.dist; |
| 209 | float t = -(nom / denom); |
| 210 | if (t >= 0) { |
| 211 | bx::Vec3 offset = bx::mul(dirNorm, t); |
| 212 | bx::Vec3 result = bx::add(origin, offset); |
| 213 | return Vec2{result.x, result.y}; |
| 214 | } |
| 215 | } |
| 216 | return Vec2{-1.0f, -1.0f}; |
| 217 | } |
| 218 | |
| 219 | Vec2 NodeTouchHandler::getPos(const SDL_Event& event) { |
| 220 | Vec3 pos{-1.0f, -1.0f, 0.0f}; |
nothing calls this directly
no test coverage detected