| 3238 | } |
| 3239 | |
| 3240 | btVector3 PhysicsServerExample::getRayTo(int x, int y) |
| 3241 | { |
| 3242 | CommonRenderInterface* renderer = m_guiHelper->getRenderInterface(); |
| 3243 | |
| 3244 | if (!renderer) |
| 3245 | { |
| 3246 | btAssert(0); |
| 3247 | return btVector3(0, 0, 0); |
| 3248 | } |
| 3249 | |
| 3250 | float top = 1.f; |
| 3251 | float bottom = -1.f; |
| 3252 | float nearPlane = 1.f; |
| 3253 | float tanFov = (top - bottom) * 0.5f / nearPlane; |
| 3254 | float fov = btScalar(2.0) * btAtan(tanFov); |
| 3255 | |
| 3256 | btVector3 camPos, camTarget; |
| 3257 | renderer->getActiveCamera()->getCameraPosition(camPos); |
| 3258 | renderer->getActiveCamera()->getCameraTargetPosition(camTarget); |
| 3259 | |
| 3260 | btVector3 rayFrom = camPos; |
| 3261 | btVector3 rayForward = (camTarget - camPos); |
| 3262 | rayForward.normalize(); |
| 3263 | float farPlane = 10000.f; |
| 3264 | rayForward *= farPlane; |
| 3265 | |
| 3266 | btVector3 rightOffset; |
| 3267 | btVector3 cameraUp = btVector3(0, 0, 0); |
| 3268 | cameraUp[m_guiHelper->getAppInterface()->getUpAxis()] = 1; |
| 3269 | |
| 3270 | btVector3 vertical = cameraUp; |
| 3271 | |
| 3272 | btVector3 hor; |
| 3273 | hor = rayForward.cross(vertical); |
| 3274 | hor.safeNormalize(); |
| 3275 | vertical = hor.cross(rayForward); |
| 3276 | vertical.safeNormalize(); |
| 3277 | |
| 3278 | float tanfov = tanf(0.5f * fov); |
| 3279 | |
| 3280 | hor *= 2.f * farPlane * tanfov; |
| 3281 | vertical *= 2.f * farPlane * tanfov; |
| 3282 | |
| 3283 | btScalar aspect; |
| 3284 | float width = float(renderer->getScreenWidth()); |
| 3285 | float height = float(renderer->getScreenHeight()); |
| 3286 | |
| 3287 | aspect = width / height; |
| 3288 | |
| 3289 | hor *= aspect; |
| 3290 | |
| 3291 | btVector3 rayToCenter = rayFrom + rayForward; |
| 3292 | btVector3 dHor = hor * 1.f / width; |
| 3293 | btVector3 dVert = vertical * 1.f / height; |
| 3294 | |
| 3295 | btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical; |
| 3296 | rayTo += btScalar(x) * dHor; |
| 3297 | rayTo -= btScalar(y) * dVert; |
no test coverage detected