| 225 | } |
| 226 | |
| 227 | void SceneParser::parse_camera(const aiScene* scene, Scene& parsed_scene, float frame_aspect_override) |
| 228 | { |
| 229 | // Taking the first camera as the camera of the scene |
| 230 | if (scene->mNumCameras > 0) |
| 231 | { |
| 232 | aiCamera* camera = scene->mCameras[0]; |
| 233 | |
| 234 | glm::vec3 camera_position = *reinterpret_cast<glm::vec3*>(&camera->mPosition); |
| 235 | glm::vec3 camera_lookat = *reinterpret_cast<glm::vec3*>(&camera->mLookAt); |
| 236 | glm::vec3 camera_up = *reinterpret_cast<glm::vec3*>(&camera->mUp); |
| 237 | |
| 238 | // Inversing the lookat because glm::lookat creates a world->view matrix which means |
| 239 | // that the position of the camera in world->view matrix is going to be '-true_position' |
| 240 | // |
| 241 | // Same for the other properties of the matrix |
| 242 | glm::mat4x4 lookat = glm::inverse(glm::lookAt(camera_position, camera_lookat, camera_up)); |
| 243 | |
| 244 | glm::vec3 scale, skew, translation; |
| 245 | glm::vec4 perspective; |
| 246 | glm::quat orientation; |
| 247 | glm::decompose(lookat, scale, orientation, translation, skew, perspective); |
| 248 | |
| 249 | parsed_scene.camera.m_translation = translation; |
| 250 | parsed_scene.camera.m_rotation = orientation; |
| 251 | |
| 252 | float aspect_ratio = frame_aspect_override == -1 ? camera->mAspect : frame_aspect_override; |
| 253 | float vertical_fov = 2.0f * std::atan(std::tan(camera->mHorizontalFOV * 0.5f) * aspect_ratio) + 0.425f; |
| 254 | parsed_scene.camera.projection_matrix = glm::perspective(vertical_fov, aspect_ratio, camera->mClipPlaneNear, camera->mClipPlaneFar); |
| 255 | parsed_scene.camera.vertical_fov = vertical_fov; |
| 256 | |
| 257 | // Custom clip planes distances are not supported by the renderer so hardcoding to 0.1f and 100.0f |
| 258 | // instead of reading from the camera properties |
| 259 | parsed_scene.camera.near_plane = 0.1f;// camera->mClipPlaneNear; |
| 260 | parsed_scene.camera.far_plane = 100.0f;// camera->mClipPlaneFar; |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | // Creating a default camera because the scene doesn't have one |
| 265 | |
| 266 | glm::mat4x4 lookat = glm::inverse(glm::lookAt(glm::vec3(0, 0, 0), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0))); |
| 267 | |
| 268 | glm::vec3 scale, skew, translation; |
| 269 | glm::vec4 perspective; |
| 270 | glm::quat orientation; |
| 271 | glm::decompose(lookat, scale, orientation, translation, skew, perspective); |
| 272 | |
| 273 | parsed_scene.camera.m_translation = translation; |
| 274 | parsed_scene.camera.m_rotation = orientation; |
| 275 | |
| 276 | float aspect_ratio = 1280.0f / 720.0f; |
| 277 | float horizontal_fov = 40.0f / 180 * M_PI; |
| 278 | float vertical_fov = 2.0f * std::atan(std::tan(horizontal_fov * 0.5f) * aspect_ratio) + 0.425f; |
| 279 | parsed_scene.camera.projection_matrix = glm::perspective(vertical_fov, aspect_ratio, 0.1f, 100.0f); |
| 280 | parsed_scene.camera.vertical_fov = vertical_fov; |
| 281 | parsed_scene.camera.near_plane = 0.1f; |
| 282 | parsed_scene.camera.far_plane = 100.0f; |
| 283 | } |
| 284 | } |
nothing calls this directly
no outgoing calls
no test coverage detected