mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
optimized directx perspective calculation and fixed orthographic projection
This commit is contained in:
parent
c5a0b25bc8
commit
1b5e1c6ecf
@ -802,6 +802,7 @@ prepare_lens() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lets get the lens perspective matrix
|
||||||
const LMatrix4f &projection_mat = _current_lens->get_projection_mat();
|
const LMatrix4f &projection_mat = _current_lens->get_projection_mat();
|
||||||
|
|
||||||
// The projection matrix must always be left-handed Y-up internally,
|
// The projection matrix must always be left-handed Y-up internally,
|
||||||
@ -810,9 +811,31 @@ prepare_lens() {
|
|||||||
LMatrix4f::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()) *
|
LMatrix4f::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()) *
|
||||||
projection_mat;
|
projection_mat;
|
||||||
|
|
||||||
|
float vfov = _current_lens->get_vfov();
|
||||||
|
float nearf = _current_lens->get_near();
|
||||||
|
float farf = _current_lens->get_far();
|
||||||
|
|
||||||
|
//dxgsg7_cat.debug() << new_projection_mat << endl;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = _pScrn->pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION,
|
if (_current_lens->get_type().get_name() == "PerspectiveLens") {
|
||||||
(LPD3DMATRIX)new_projection_mat.get_data());
|
((LPD3DMATRIX)new_projection_mat.get_data())->_33 = farf / (farf-nearf);
|
||||||
|
((LPD3DMATRIX)new_projection_mat.get_data())->_43 = -nearf * farf / (farf - nearf);
|
||||||
|
|
||||||
|
hr = _pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION,
|
||||||
|
(D3DMATRIX*)new_projection_mat.get_data());
|
||||||
|
//dxgsg7_cat.debug() << new_projection_mat << endl;
|
||||||
|
//dxgsg7_cat.debug() << "using perspective projection" << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
((LPD3DMATRIX)new_projection_mat.get_data())->_33 = 1/(farf-nearf);
|
||||||
|
((LPD3DMATRIX)new_projection_mat.get_data())->_43 = -nearf/(farf-nearf);
|
||||||
|
|
||||||
|
hr = _pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION,
|
||||||
|
(LPD3DMATRIX)new_projection_mat.get_data());
|
||||||
|
//dxgsg7_cat.debug() << new_projection_mat << endl;
|
||||||
|
//dxgsg7_cat.debug() << "using ortho projection" << endl;
|
||||||
|
}
|
||||||
return SUCCEEDED(hr);
|
return SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1030,40 +1030,56 @@ prepare_lens() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hr;
|
// lets get the lens perspective matrix
|
||||||
|
const LMatrix4f &projection_mat = _current_lens->get_projection_mat();
|
||||||
|
|
||||||
|
// The projection matrix must always be left-handed Y-up internally,
|
||||||
|
// even if our coordinate system of choice is otherwise.
|
||||||
|
LMatrix4f new_projection_mat =
|
||||||
|
LMatrix4f::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()) *
|
||||||
|
projection_mat;
|
||||||
|
|
||||||
|
float vfov = _current_lens->get_vfov();
|
||||||
|
float nearf = _current_lens->get_near();
|
||||||
|
float farf = _current_lens->get_far();
|
||||||
|
|
||||||
|
//dxgsg8_cat.debug() << new_projection_mat << endl;
|
||||||
|
|
||||||
|
HRESULT hr;
|
||||||
if (_current_lens->get_type().get_name() == "PerspectiveLens") {
|
if (_current_lens->get_type().get_name() == "PerspectiveLens") {
|
||||||
// new method, still in test
|
#if 0
|
||||||
const LMatrix4f mat_temp;
|
const LMatrix4f mat_temp;
|
||||||
|
|
||||||
float hfov = _current_lens->get_hfov();
|
float hfov = _current_lens->get_hfov();
|
||||||
float vfov = _current_lens->get_vfov();
|
|
||||||
float ar = _current_lens->get_aspect_ratio();
|
float ar = _current_lens->get_aspect_ratio();
|
||||||
float nearf = _current_lens->get_near();
|
float nearf = _current_lens->get_near();
|
||||||
float farf = _current_lens->get_far();
|
float farf = _current_lens->get_far();
|
||||||
//dxgsg8_cat.debug() << "hfov " << hfov << " vfov " << vfov << " ar " << ar << " near " << nearf << " far " << farf << endl;
|
|
||||||
|
|
||||||
double vfov_radian = vfov * 0.0174532925;
|
double vfov_radian = vfov * 0.0174532925;
|
||||||
|
|
||||||
|
dxgsg8_cat.debug() << "hfov " << hfov << " vfov " << vfov << " ar " << ar << " near " << nearf << " far " << farf << endl;
|
||||||
D3DXMatrixPerspectiveFovLH( (D3DXMATRIX*)mat_temp.get_data(), vfov_radian, ar, nearf, farf );
|
D3DXMatrixPerspectiveFovLH( (D3DXMATRIX*)mat_temp.get_data(), vfov_radian, ar, nearf, farf );
|
||||||
|
|
||||||
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
|
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
|
||||||
(D3DMATRIX*)mat_temp.get_data());
|
(D3DMATRIX*)mat_temp.get_data());
|
||||||
//dxgsg8_cat.debug() << mat_temp << endl;
|
dxgsg8_cat.debug() << mat_temp << endl;
|
||||||
//dxgsg8_cat.debug() << "using perspective projection" << endl;
|
#endif
|
||||||
}
|
|
||||||
else {
|
|
||||||
const LMatrix4f &projection_mat = _current_lens->get_projection_mat();
|
|
||||||
|
|
||||||
// The projection matrix must always be left-handed Y-up internally,
|
((D3DXMATRIX*)new_projection_mat.get_data())->_33 = farf / (farf-nearf);
|
||||||
// even if our coordinate system of choice is otherwise.
|
((D3DXMATRIX*)new_projection_mat.get_data())->_43 = -nearf * farf / (farf - nearf);
|
||||||
LMatrix4f new_projection_mat =
|
|
||||||
LMatrix4f::convert_mat(CS_yup_left, _current_lens->get_coordinate_system()) *
|
|
||||||
projection_mat;
|
|
||||||
|
|
||||||
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
|
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
|
||||||
(D3DMATRIX*)new_projection_mat.get_data());
|
(D3DMATRIX*)new_projection_mat.get_data());
|
||||||
//dxgsg8_cat.debug() << new_projection_mat << endl;
|
//dxgsg8_cat.debug() << new_projection_mat << endl;
|
||||||
//dxgsg8_cat.debug() << "using other projection" << endl;
|
//dxgsg8_cat.debug() << "using perspective projection" << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
((D3DXMATRIX*)new_projection_mat.get_data())->_33 = 1/(farf-nearf);
|
||||||
|
((D3DXMATRIX*)new_projection_mat.get_data())->_43 = -nearf/(farf-nearf);
|
||||||
|
|
||||||
|
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
|
||||||
|
(D3DMATRIX*)new_projection_mat.get_data());
|
||||||
|
//dxgsg8_cat.debug() << new_projection_mat << endl;
|
||||||
|
//dxgsg8_cat.debug() << "using ortho projection" << endl;
|
||||||
}
|
}
|
||||||
return SUCCEEDED(hr);
|
return SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user