Added getPerspective() method to Matrix* and SceneView
This commit is contained in:
@@ -10,19 +10,15 @@ void testFrustum(double left,double right,double bottom,double top,double zNear,
|
||||
osg::Matrix f;
|
||||
f.makeFrustum(left,right,bottom,top,zNear,zFar);
|
||||
|
||||
double c_left=0;
|
||||
double c_right=0;
|
||||
double c_top=0;
|
||||
double c_bottom=0;
|
||||
double c_zNear=0;
|
||||
double c_zFar=0;
|
||||
|
||||
double c_zNear = f(3,2) / (f(2,2)-1.0f);
|
||||
double c_zFar = f(3,2) / (1.0f+f(2,2));
|
||||
|
||||
double c_left = c_zNear * (f(2,0)-1.0f) / f(0,0);
|
||||
double c_right = c_zNear * (1.0f+f(2,0)) / f(0,0);
|
||||
|
||||
double c_top = c_zNear * (1+f(2,1)) / f(1,1);
|
||||
double c_bottom = c_zNear * (f(2,1)-1.0f) / f(1,1);
|
||||
|
||||
f.getFrustum(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar);
|
||||
|
||||
std::cout << "testFrustum"<<std::endl;
|
||||
std::cout << "testFrustum"<<f.getFrustum(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar)<<std::endl;
|
||||
std::cout << " left = "<<left<<" compute "<<c_left<<std::endl;
|
||||
std::cout << " right = "<<right<<" compute "<<c_right<<std::endl;
|
||||
|
||||
@@ -40,19 +36,14 @@ void testOrtho(double left,double right,double bottom,double top,double zNear,do
|
||||
osg::Matrix f;
|
||||
f.makeOrtho(left,right,bottom,top,zNear,zFar);
|
||||
|
||||
double c_zNear = (f(3,2)+1.0f) / f(2,2);
|
||||
double c_zFar = (f(3,2)-1.0f) / f(2,2);
|
||||
|
||||
double c_left = -(1.0f+f(3,0)) / f(0,0);
|
||||
double c_right = (1.0f-f(3,0)) / f(0,0);
|
||||
double c_left=0;
|
||||
double c_right=0;
|
||||
double c_top=0;
|
||||
double c_bottom=0;
|
||||
double c_zNear=0;
|
||||
double c_zFar=0;
|
||||
|
||||
double c_bottom = -(1.0f+f(3,1)) / f(1,1);
|
||||
double c_top = (1.0f-f(3,1)) / f(1,1);
|
||||
|
||||
f.getOrtho(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar);
|
||||
|
||||
|
||||
std::cout << "testOrtho"<<std::endl;
|
||||
std::cout << "testOrtho "<< f.getOrtho(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar) << std::endl;
|
||||
std::cout << " left = "<<left<<" compute "<<c_left<<std::endl;
|
||||
std::cout << " right = "<<right<<" compute "<<c_right<<std::endl;
|
||||
|
||||
@@ -65,6 +56,26 @@ void testOrtho(double left,double right,double bottom,double top,double zNear,do
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void testPerspective(double fovy,double aspect,double zNear,double zFar)
|
||||
{
|
||||
osg::Matrix f;
|
||||
f.makePerspective(fovy,aspect,zNear,zFar);
|
||||
|
||||
double c_fovy=0;
|
||||
double c_aspect=0;
|
||||
double c_zNear=0;
|
||||
double c_zFar=0;
|
||||
|
||||
std::cout << "testPerspective "<< f.getPerspective(c_fovy,c_aspect,c_zNear,c_zFar) << std::endl;
|
||||
std::cout << " fovy = "<<fovy<<" compute "<<c_fovy<<std::endl;
|
||||
std::cout << " aspect = "<<aspect<<" compute "<<c_aspect<<std::endl;
|
||||
|
||||
std::cout << " zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
|
||||
std::cout << " zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void testLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
|
||||
{
|
||||
osg::Matrix mv;
|
||||
@@ -158,6 +169,9 @@ int main( int argc, char** argv )
|
||||
testOrtho(0,1,1,2,2.1,1000);
|
||||
testOrtho(-1,10,1,20,2.5,100000);
|
||||
|
||||
testPerspective(20,1,1,1000);
|
||||
testPerspective(90,2,1,1000);
|
||||
|
||||
testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
|
||||
testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(1.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user