| 263 | //----------------------------------------------------------------------------// |
| 264 | |
| 265 | void Picking::project(const physx::PxVec3& v, int& xi, int& yi, float& depth) const |
| 266 | { |
| 267 | SampleRenderer::Renderer* renderer = mFrame.getRenderer(); |
| 268 | SampleRenderer::RendererProjection projection = mFrame.getCamera().getProjMatrix(); |
| 269 | const PxTransform view = mFrame.getCamera().getViewMatrix().getInverse(); |
| 270 | |
| 271 | PxVec3 pos = SampleRenderer::project(projection, view, v); |
| 272 | ///* Map x, y and z to range 0-1 */ |
| 273 | pos.x = (pos.x + 1 ) * 0.5f; |
| 274 | pos.y = (pos.y + 1 ) * 0.5f; |
| 275 | pos.z = (pos.z + 1 ) * 0.5f; |
| 276 | |
| 277 | PxU32 windowWidth = 0; |
| 278 | PxU32 windowHeight = 0; |
| 279 | renderer->getWindowSize(windowWidth, windowHeight); |
| 280 | |
| 281 | /* Map x,y to viewport */ |
| 282 | pos.x *= windowWidth; |
| 283 | pos.y *= windowHeight; |
| 284 | |
| 285 | depth = (float)pos.z; |
| 286 | |
| 287 | xi = (int)(pos.x + 0.5); |
| 288 | yi = (int)(pos.y + 0.5); |
| 289 | } |
no test coverage detected