MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / getCameraInfo

Method getCameraInfo

examples/ExampleBrowser/OpenGLGuiHelper.cpp:1191–1245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1189}
1190
1191bool OpenGLGuiHelper::getCameraInfo(int* width, int* height, float viewMatrix[16], float projectionMatrix[16], float camUp[3], float camForward[3], float hor[3], float vert[3], float* yaw, float* pitch, float* camDist, float cameraTarget[3]) const
1192{
1193 if (getRenderInterface() && getRenderInterface()->getActiveCamera())
1194 {
1195 *width = m_data->m_glApp->m_window->getWidth();
1196 *height = m_data->m_glApp->m_window->getHeight();
1197 getRenderInterface()->getActiveCamera()->getCameraViewMatrix(viewMatrix);
1198 getRenderInterface()->getActiveCamera()->getCameraProjectionMatrix(projectionMatrix);
1199 getRenderInterface()->getActiveCamera()->getCameraUpVector(camUp);
1200 getRenderInterface()->getActiveCamera()->getCameraForwardVector(camForward);
1201
1202 float top = 1.f;
1203 float bottom = -1.f;
1204 float tanFov = (top - bottom) * 0.5f / 1;
1205 float fov = btScalar(2.0) * btAtan(tanFov);
1206 btVector3 camPos, camTarget;
1207 getRenderInterface()->getActiveCamera()->getCameraPosition(camPos);
1208 getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget);
1209 btVector3 rayFrom = camPos;
1210 btVector3 rayForward = (camTarget - camPos);
1211 rayForward.normalize();
1212 float farPlane = 10000.f;
1213 rayForward *= farPlane;
1214
1215 btVector3 rightOffset;
1216 btVector3 cameraUp = btVector3(camUp[0], camUp[1], camUp[2]);
1217 btVector3 vertical = cameraUp;
1218 btVector3 hori;
1219 hori = rayForward.cross(vertical);
1220 hori.normalize();
1221 vertical = hori.cross(rayForward);
1222 vertical.normalize();
1223 float tanfov = tanf(0.5f * fov);
1224 hori *= 2.f * farPlane * tanfov;
1225 vertical *= 2.f * farPlane * tanfov;
1226 btScalar aspect = float(*width) / float(*height);
1227 hori *= aspect;
1228 //compute 'hor' and 'vert' vectors, useful to generate raytracer rays
1229 hor[0] = hori[0];
1230 hor[1] = hori[1];
1231 hor[2] = hori[2];
1232 vert[0] = vertical[0];
1233 vert[1] = vertical[1];
1234 vert[2] = vertical[2];
1235
1236 *yaw = getRenderInterface()->getActiveCamera()->getCameraYaw();
1237 *pitch = getRenderInterface()->getActiveCamera()->getCameraPitch();
1238 *camDist = getRenderInterface()->getActiveCamera()->getCameraDistance();
1239 cameraTarget[0] = camTarget[0];
1240 cameraTarget[1] = camTarget[1];
1241 cameraTarget[2] = camTarget[2];
1242 return true;
1243 }
1244 return false;
1245}
1246
1247void OpenGLGuiHelper::setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16])
1248{

Callers

nothing calls this directly

Calls 15

btAtanFunction · 0.85
getCameraUpVectorMethod · 0.80
getCameraPositionMethod · 0.80
getCameraYawMethod · 0.80
getCameraPitchMethod · 0.80
getCameraDistanceMethod · 0.80
btVector3Class · 0.50
getActiveCameraMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected