Horizon level computation final
This commit is contained in:
parent
6e7b980096
commit
bdf6228679
@ -58,7 +58,7 @@ Graphic3DRenderer::~Graphic3DRenderer() {}
|
|||||||
|
|
||||||
void Graphic3DRenderer::SetRTSize(unsigned int w, unsigned int h) {
|
void Graphic3DRenderer::SetRTSize(unsigned int w, unsigned int h) {
|
||||||
mRTSize.x = w; mRTSize.y = h;
|
mRTSize.x = w; mRTSize.y = h;
|
||||||
mMainCamera->SetFrustrum(75.0f, mRTSize.x/mRTSize.y, 1.0f, 100.f);
|
mMainCamera->SetFrustrum(90.0f, mRTSize.x/mRTSize.y, 1.0f, 100.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphic3DRenderer::UpdateCamera(CAMERA_MOVE type, const float value) {
|
void Graphic3DRenderer::UpdateCamera(CAMERA_MOVE type, const float value) {
|
||||||
@ -231,29 +231,23 @@ void Graphic3DRenderer::UpdateInternalTestObjects() {
|
|||||||
mRenderList[2]->SetRotation(thetaAngle3, 0.f, thetaAngle3 * 0.5f);
|
mRenderList[2]->SetRotation(thetaAngle3, 0.f, thetaAngle3 * 0.5f);
|
||||||
mRenderList[3]->SetRotation(0.f, thetaAngle, 0.f);
|
mRenderList[3]->SetRotation(0.f, thetaAngle, 0.f);
|
||||||
}
|
}
|
||||||
#include <iostream>
|
|
||||||
// Compute the screen ratio between the ground and the sky (aka. Line of Horizon)
|
// Compute the screen ratio between the ground and the sky (aka. Line of Horizon)
|
||||||
inline float Graphic3DRenderer::ComputeSGRatio() {
|
inline float Graphic3DRenderer::ComputeSGRatio() {
|
||||||
// FoV angle for Y axis is recovered using frustrum FoV and apply RT screen ratio to it
|
// FoV angle for Y axis is recovered using frustrum FoV and apply RT screen ratio to it
|
||||||
//const double fovYAngleDiv2 = M3D_Deg2Rad(mMainCamera->GetFoV() * mRTSize.y / mRTSize.x) * 0.5f;
|
const float fovYAngleDiv2 = M3D_Deg2Rad(mMainCamera->GetFoV()) * 0.5f;
|
||||||
const double fovYAngle = M3D_Deg2Rad(mMainCamera->GetFoV()) * mRTSize.y / mRTSize.x;
|
|
||||||
// Get the camera pitch angle over camera FoV ratio
|
// Get the camera pitch angle over camera FoV ratio
|
||||||
//const float theta = M3D_ScalarASin(-mMainCamera->GetLook3f().y) * (fovYAngleDiv2 + 0.2047198f) / M3D_PIDIV2;
|
const float theta = M3D_ScalarASinEst(-mMainCamera->GetLook3f().y);
|
||||||
const float theta = M3D_ScalarASin(-mMainCamera->GetLook3f().y);
|
// Get the camera altitude from the ground
|
||||||
|
const float altitude = mMainCamera->GetPos3f().y;
|
||||||
|
|
||||||
// Simple approach, real (infinite) horizon (w/o camera height and far screen calculation)
|
// Ground/Sky screen ratio calculation using "simple" trigonometric properties of the
|
||||||
double sgRatio = 0.5f + std::tan(((theta / M3D_PI) / fovYAngle) * M3D_PIDIV4);
|
// pinhole (frustrum) camera model.
|
||||||
std::cout << (theta / M3D_PI) << ' ' << fovYAngle << ' ' << sgRatio << std::endl;
|
// The triangle made by the ground plane intersection with the frustum. This intersection
|
||||||
// Finite ground (to far plan), camera height impact the ground "level" -- KEEP FOR FURTHER USE
|
// cross the far plane at some point. Instead of computing the coordinate of the point, we
|
||||||
/*double sgRatio = -(mMainCamera->GetPos3f().y * 0.1f * M3D_ScalarCos(fovYAngleDiv2) - 101.f * M3D_ScalarSin(fovYAngleDiv2 + theta))
|
// directly use the far plane length to get the corresponding ratio for the screen.
|
||||||
/ (2.f * 101.f * M3D_ScalarSin(fovYAngleDiv2) * M3D_ScalarCos(theta));
|
double sgRatio = -(altitude * M3D_ScalarCosEst(fovYAngleDiv2) - mMainCamera->GetFarZ() * M3D_ScalarSinEst(fovYAngleDiv2 + theta))
|
||||||
std::cout << fovYAngleDiv2 << ' ' << theta << ' ' << sgRatio << std::endl;*/
|
/ (2.f * mMainCamera->GetFarZ() * M3D_ScalarSinEst(fovYAngleDiv2) * M3D_ScalarCosEst(theta));
|
||||||
/*double p0 = 101.f / M3D_ScalarCos(fovYAngleDiv2);
|
|
||||||
double pf = mMainCamera->GetPos3f().y * 0.1f / M3D_ScalarSin(theta+fovYAngleDiv2);
|
|
||||||
double gh = (std::abs(p0 - pf) * M3D_ScalarSin(theta+fovYAngleDiv2)) / M3D_ScalarCos(theta);
|
|
||||||
double sh = 2.f * 101.f * std::tan(fovYAngleDiv2);
|
|
||||||
double sgRatio = gh / sh;
|
|
||||||
std::cout << fovYAngleDiv2 << ' ' << theta << " p0:" << p0 << " pf:" << pf << " gh:" << gh << " sh:" << sh << ' ' << sgRatio << std::endl;*/
|
|
||||||
|
|
||||||
// Clamp
|
// Clamp
|
||||||
if (sgRatio > 1.f)
|
if (sgRatio > 1.f)
|
||||||
|
@ -8,6 +8,7 @@ Camera::Camera() {
|
|||||||
void Camera::SetFrustrum(float fov, float r, float zn, float zf) {
|
void Camera::SetFrustrum(float fov, float r, float zn, float zf) {
|
||||||
//if (!frameDirty)
|
//if (!frameDirty)
|
||||||
this->fov = fov;
|
this->fov = fov;
|
||||||
|
this->zf = zf;
|
||||||
M3D_MATRIX pMat = M3D_TransformMatrixFrustrumFovLH(M3D_Deg2Rad(fov), r, zn, zf);
|
M3D_MATRIX pMat = M3D_TransformMatrixFrustrumFovLH(M3D_Deg2Rad(fov), r, zn, zf);
|
||||||
M3D_V4StoreF4x4(&mProjMat, pMat);
|
M3D_V4StoreF4x4(&mProjMat, pMat);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public:
|
|||||||
Camera& operator= (Camera const&) = delete;
|
Camera& operator= (Camera const&) = delete;
|
||||||
|
|
||||||
float GetFoV() const { return fov; }
|
float GetFoV() const { return fov; }
|
||||||
|
float GetFarZ() const { return zf; }
|
||||||
M3D_VECTOR GetPos() const { return M3D_V4LoadF3(&mPos); }
|
M3D_VECTOR GetPos() const { return M3D_V4LoadF3(&mPos); }
|
||||||
M3D_F3 GetPos3f() const { return mPos; }
|
M3D_F3 GetPos3f() const { return mPos; }
|
||||||
M3D_VECTOR GetLook() const { return M3D_V4LoadF3(&mLook); }
|
M3D_VECTOR GetLook() const { return M3D_V4LoadF3(&mLook); }
|
||||||
@ -39,7 +40,8 @@ public:
|
|||||||
void Yaw(float angle);
|
void Yaw(float angle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float fov;
|
float fov; // It's the Y-FoV!
|
||||||
|
float zf;
|
||||||
|
|
||||||
M3D_F4X4 mProjMat = M3D_MIdentity4x4();
|
M3D_F4X4 mProjMat = M3D_MIdentity4x4();
|
||||||
M3D_F4X4 mViewMat = M3D_MIdentity4x4();
|
M3D_F4X4 mViewMat = M3D_MIdentity4x4();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user