| 300 | } |
| 301 | |
| 302 | Vec2 Camera::projectGL(const Vec3& src) const |
| 303 | { |
| 304 | Vec2 screenPos; |
| 305 | |
| 306 | auto viewport = _director->getWinSize(); |
| 307 | Vec4 clipPos; |
| 308 | getViewProjectionMatrix().transformVector(Vec4(src.x, src.y, src.z, 1.0f), &clipPos); |
| 309 | |
| 310 | if (clipPos.w == 0.0f) |
| 311 | AXLOGW("WARNING: Camera's clip position w is 0.0! a black screen should be expected."); |
| 312 | |
| 313 | float ndcX = clipPos.x / clipPos.w; |
| 314 | float ndcY = clipPos.y / clipPos.w; |
| 315 | |
| 316 | screenPos.x = (ndcX + 1.0f) * 0.5f * viewport.width; |
| 317 | screenPos.y = (ndcY + 1.0f) * 0.5f * viewport.height; |
| 318 | return screenPos; |
| 319 | } |
| 320 | |
| 321 | Vec3 Camera::unproject(const Vec3& src) const |
| 322 | { |
no test coverage detected