Showing the changes to interface/src/SecondaryCamera.cpp (1 of 1 file). Show all
Unified · Split
| @@ -54,42 +54,41 @@ public: · 53 unmodified lines | ||
| 54 | 54 | |
| 55 | 55 | void setMirrorProjection(ViewFrustum& srcViewFrustum) { |
| 56 | 56 | if (_attachedEntityId.isNull()) { |
| 57 | − qDebug() << "ERROR: Cannot set mirror projection for SecondaryCamera without an attachedEntityId set."; | |
| 57 | + qWarning() << "ERROR: Cannot set mirror projection for SecondaryCamera without an attachedEntityId set."; | |
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | − EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(_attachedEntityId, _attachedEntityPropertyFlags); | |
| 62 | − glm::vec3 mirrorPropsPos = entityProperties.getPosition(); | |
| 63 | − glm::quat mirrorPropsRot = entityProperties.getRotation(); | |
| 64 | − glm::vec3 mirrorPropsDim = entityProperties.getDimensions(); | |
| 61 | + EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(_attachedEntityId, | |
| 62 | + _attachedEntityPropertyFlags); | |
| 63 | + glm::vec3 mirrorPropertiesPosition = entityProperties.getPosition(); | |
| 64 | + glm::quat mirrorPropertiesRotation = entityProperties.getRotation(); | |
| 65 | + glm::vec3 mirrorPropertiesDimensions = entityProperties.getDimensions(); | |
| 66 | + glm::vec3 halfMirrorPropertiesDimensions = 0.5f * mirrorPropertiesDimensions; | |
| 65 | 67 | |
| 66 | 68 | // setup mirror from world as inverse of world from mirror transformation using inverted x and z for mirrored image |
| 67 | − glm::mat4 worldFromMirrorRot = glm::mat4_cast(mirrorPropsRot) * glm::scale(vec3(-1.f, 1.f, -1.f)); | |
| 68 | − glm::mat4 worldFromMirrorTrans = glm::translate(mirrorPropsPos); | |
| 69 | − glm::mat4 worldFromMirror = worldFromMirrorTrans * worldFromMirrorRot; | |
| 69 | + glm::mat4 worldFromMirrorRotation = glm::mat4_cast(mirrorPropertiesRotation) * glm::scale(vec3(-1.0f, 1.0f, -1.0f)); | |
| 70 | + glm::mat4 worldFromMirrorTranslation = glm::translate(mirrorPropertiesPosition); | |
| 71 | + glm::mat4 worldFromMirror = worldFromMirrorTranslation * worldFromMirrorRotation; | |
| 70 | 72 | glm::mat4 mirrorFromWorld = glm::inverse(worldFromMirror); |
| 71 | 73 | |
| 72 | 74 | // get mirror camera position by reflecting main camera position's z coordinate in mirror space |
| 73 | − glm::vec3 mainCamPosWorld = qApp->getCamera().getPosition(); | |
| 74 | − glm::vec3 mainCamPosMirror = vec3(mirrorFromWorld * vec4(mainCamPosWorld, 1.f)); | |
| 75 | − glm::vec3 mirrorCamPosMirror = vec3(mainCamPosMirror.x, mainCamPosMirror.y, -mainCamPosMirror.z); | |
| 76 | − glm::vec3 mirrorCamPosWorld = vec3(worldFromMirror * vec4(mirrorCamPosMirror, 1.f)); | |
| 75 | + glm::vec3 mainCameraPositionWorld = qApp->getCamera().getPosition(); | |
| 76 | + glm::vec3 mainCameraPositionMirror = vec3(mirrorFromWorld * vec4(mainCameraPositionWorld, 1.0f)); | |
| 77 | + glm::vec3 mirrorCameraPositionMirror = vec3(mainCameraPositionMirror.x, mainCameraPositionMirror.y, | |
| 78 | + -mainCameraPositionMirror.z); | |
| 79 | + glm::vec3 mirrorCameraPositionWorld = vec3(worldFromMirror * vec4(mirrorCameraPositionMirror, 1.0f)); | |
| 77 | 80 | |
| 78 | 81 | // set frustum position to be mirrored camera and set orientation to mirror's adjusted rotation |
| 79 | − glm::vec3 eyePos = mirrorCamPosWorld; | |
| 80 | − glm::quat eyeOri = glm::quat_cast(worldFromMirrorRot); | |
| 81 | − srcViewFrustum.setPosition(eyePos); | |
| 82 | − srcViewFrustum.setOrientation(eyeOri); | |
| 82 | + glm::quat mirrorCamOrientation = glm::quat_cast(worldFromMirrorRotation); | |
| 83 | + srcViewFrustum.setPosition(mirrorCameraPositionWorld); | |
| 84 | + srcViewFrustum.setOrientation(mirrorCamOrientation); | |
| 83 | 85 | |
| 84 | 86 | // build frustum using mirror space translation of mirrored camera |
| 85 | − float n = mirrorCamPosMirror.z + mirrorPropsDim.z * 2.f; | |
| 86 | − float f = _farClipPlaneDistance; | |
| 87 | − float r = -mirrorCamPosMirror.x + mirrorPropsDim.x / 2.f; | |
| 88 | − float l = -mirrorCamPosMirror.x - mirrorPropsDim.x / 2.f; | |
| 89 | − float t = -mirrorCamPosMirror.y + mirrorPropsDim.y / 2.f; | |
| 90 | − float b = -mirrorCamPosMirror.y - mirrorPropsDim.y / 2.f; | |
| 91 | − | |
| 92 | − glm::mat4 frustum = glm::frustum(l, r, b, t, n, f); | |
| 87 | + float nearClip = mirrorCameraPositionMirror.z + mirrorPropertiesDimensions.z * 2.0f; | |
| 88 | + glm::vec3 upperRight = halfMirrorPropertiesDimensions - mirrorCameraPositionMirror; | |
| 89 | + glm::vec3 bottomLeft = -halfMirrorPropertiesDimensions - mirrorCameraPositionMirror; | |
| 90 | + glm::mat4 frustum = glm::frustum(bottomLeft.x, upperRight.x, bottomLeft.y, upperRight.y, nearClip, _farClipPlaneDistance); | |
| 91 | + | |
| 93 | 92 | srcViewFrustum.setProjection(frustum); |
| 94 | 93 | } |
| 95 | 94 | |
| @@ -118,15 +117,17 @@ public: · 22 unmodified lines | ||
| 118 | 117 | setMirrorProjection(srcViewFrustum); |
| 119 | 118 | } else { |
| 120 | 119 | if (!_attachedEntityId.isNull()) { |
| 121 | − EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(_attachedEntityId, _attachedEntityPropertyFlags); | |
| 120 | + EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(_attachedEntityId, | |
| 121 | + _attachedEntityPropertyFlags); | |
| 122 | 122 | srcViewFrustum.setPosition(entityProperties.getPosition()); |
| 123 | 123 | srcViewFrustum.setOrientation(entityProperties.getRotation()); |
| 124 | − } | |
| 125 | − else { | |
| 124 | + } else { | |
| 126 | 125 | srcViewFrustum.setPosition(_position); |
| 127 | 126 | srcViewFrustum.setOrientation(_orientation); |
| 128 | 127 | } |
| 129 | − srcViewFrustum.setProjection(glm::perspective(glm::radians(_vFoV), ((float)args->_viewport.z / (float)args->_viewport.w), _nearClipPlaneDistance, _farClipPlaneDistance)); | |
| 128 | + srcViewFrustum.setProjection(glm::perspective(glm::radians(_vFoV), | |
| 129 | + ((float)args->_viewport.z / (float)args->_viewport.w), | |
| 130 | + _nearClipPlaneDistance, _farClipPlaneDistance)); | |
| 130 | 131 | } |
| 131 | 132 | // Without calculating the bound planes, the secondary camera will use the same culling frustum as the main camera, |
| 132 | 133 | // which is not what we want here. |