static void EERIE_CreateMatriceProj(float width, float height, EERIE_CAMERA * cam) { float fov = focalToFov(cam->focal); const float nearDist = 1.f; const float farDist = cam->cdepth; const float frustumDepth = farDist - nearDist; float aspect = height / width; float w = aspect * (glm::cos(fov / 2) / glm::sin(fov / 2)); float h = 1.0f * (glm::cos(fov / 2) / glm::sin(fov / 2)); float Q = farDist / frustumDepth; cam->ProjectionMatrix = glm::mat4x4(); cam->ProjectionMatrix[0][0] = w; cam->ProjectionMatrix[1][1] = h; cam->ProjectionMatrix[2][2] = Q; cam->ProjectionMatrix[3][2] = (-Q * nearDist); cam->ProjectionMatrix[2][3] = 1.f; cam->ProjectionMatrix[3][3] = 0.f; GRenderer->SetProjectionMatrix(cam->ProjectionMatrix); glm::mat4 tempViewMatrix = Util_SetViewMatrix(cam->orgTrans); GRenderer->SetViewMatrix(tempViewMatrix); cam->ProjectionMatrix[0][0] *= width * .5f; cam->ProjectionMatrix[1][1] *= height * .5f; cam->ProjectionMatrix[2][2] = -(farDist * nearDist) / frustumDepth; //HYPERBOLIC cam->ProjectionMatrix[3][2] = Q; GRenderer->SetViewport(Rect(static_cast<s32>(width), static_cast<s32>(height))); }
static glm::mat4x4 createProjectionMatrix(const Vec2f & size, const Vec2f & center, Camera * cam) { float fov = focalToFov(cam->focal); const float nearDist = 1.f; const float farDist = cam->cdepth; const float frustumDepth = farDist - nearDist; float aspectw = (size.y < size.x) ? size.y / size.x : 1.f; float aspecth = (size.y < size.x) ? 1.f : size.x / size.y; float w = aspectw * (glm::cos(fov / 2) / glm::sin(fov / 2)); float h = aspecth * (glm::cos(fov / 2) / glm::sin(fov / 2)); float Q = farDist / frustumDepth; glm::mat4x4 projectionMatrix; projectionMatrix[0][0] = w; projectionMatrix[1][1] = -h; projectionMatrix[2][2] = Q; projectionMatrix[3][2] = -Q * nearDist; projectionMatrix[2][3] = 1.f; projectionMatrix[3][3] = 0.f; glm::mat4x4 centerShift(1); centerShift = glm::translate(centerShift, Vec3f(2.f * center.x / size.x - 1.f, 1.f - 2.f * center.y / size.y, 0.f)); return centerShift * projectionMatrix; }