optimized directx perspective calculation and fixed orthographic projection

This commit is contained in:
Asad M. Zaman 2004-01-03 01:44:20 +00:00
parent c5a0b25bc8
commit 1b5e1c6ecf
2 changed files with 60 additions and 21 deletions

View File

@ -802,6 +802,7 @@ prepare_lens() {
return false;
}
// 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,
@ -810,9 +811,31 @@ prepare_lens() {
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();
//dxgsg7_cat.debug() << new_projection_mat << endl;
HRESULT hr;
hr = _pScrn->pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION,
if (_current_lens->get_type().get_name() == "PerspectiveLens") {
((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);
}

View File

@ -1030,28 +1030,7 @@ prepare_lens() {
return false;
}
HRESULT hr;
if (_current_lens->get_type().get_name() == "PerspectiveLens") {
// new method, still in test
const LMatrix4f mat_temp;
float hfov = _current_lens->get_hfov();
float vfov = _current_lens->get_vfov();
float ar = _current_lens->get_aspect_ratio();
float nearf = _current_lens->get_near();
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;
D3DXMatrixPerspectiveFovLH( (D3DXMATRIX*)mat_temp.get_data(), vfov_radian, ar, nearf, farf );
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
(D3DMATRIX*)mat_temp.get_data());
//dxgsg8_cat.debug() << mat_temp << endl;
//dxgsg8_cat.debug() << "using perspective projection" << endl;
}
else {
// 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,
@ -1060,10 +1039,47 @@ prepare_lens() {
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 0
const LMatrix4f mat_temp;
float hfov = _current_lens->get_hfov();
float ar = _current_lens->get_aspect_ratio();
float nearf = _current_lens->get_near();
float farf = _current_lens->get_far();
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 );
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
(D3DMATRIX*)mat_temp.get_data());
dxgsg8_cat.debug() << mat_temp << endl;
#endif
((D3DXMATRIX*)new_projection_mat.get_data())->_33 = farf / (farf-nearf);
((D3DXMATRIX*)new_projection_mat.get_data())->_43 = -nearf * farf / (farf - nearf);
hr = _pD3DDevice->SetTransform(D3DTS_PROJECTION,
(D3DMATRIX*)new_projection_mat.get_data());
//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);
}