fshake3d
0.0.1
FreeformDensity3DSurfaceEditor
|
00001 #include "ui_SceneViewPerspective.hpp" 00002 00003 // --- Perspective Scene View ------------------------------------------------ 00004 00005 SceneViewPerspective::SceneViewPerspective() 00006 : SceneView(ProjectionType_PERSPECTIVE) 00007 , mSphereCoords(90,90) 00008 , mFOVY(45.0) 00009 { 00010 } 00011 00012 void SceneViewPerspective::setAspect(double aspect) 00013 { 00014 mProjection.setAspect(aspect); 00015 } 00016 00017 void SceneViewPerspective::dragBegin() 00018 { 00019 if (mDragButton == GLUT_RIGHT_BUTTON) 00020 { 00021 mBaseSphereCoords = mSphereCoords; 00022 } 00023 else if (mDragButton == GLUT_MIDDLE_BUTTON) 00024 { 00025 mBaseFOVY = mProjection.getFOVY(); 00026 } 00027 } 00028 void SceneViewPerspective::dragUpdate(const Vec2i& d) 00029 { 00030 if (mDragButton == GLUT_RIGHT_BUTTON) 00031 { 00032 mSphereCoords = mBaseSphereCoords - Vec2d(d[0],d[1]); 00033 mSphereCoords[1] = clamp(mSphereCoords[1], 0.1, 179.9 ); 00034 00035 // update direction 00036 00037 setDirection( spherical_coordinate_to_Vec3d( mSphereCoords[0], mSphereCoords[1] ) ); 00038 00039 // update up 00040 00041 double a = Math::deg2Rad(mSphereCoords[0]); 00042 double b = Math::deg2Rad(mSphereCoords[1]); 00043 AxisAngled zrot(a,0,0,1); 00044 AxisAngled yrot(b,0,1,0); 00045 00046 Matrix44d tm1 = make<Matrix44d>( zrot ); 00047 Matrix44d tm2 = make<Matrix44d>( yrot ); 00048 Vec3d up(-1,0,0); 00049 00050 Matrix44d tm3 = tm1 * tm2; 00051 00052 Vec3d upt = tm3 * up; 00053 setUp( upt ); 00054 } 00055 else if (mDragButton == GLUT_MIDDLE_BUTTON) 00056 { 00057 mFOVY = clamp( mBaseFOVY + d[1]*0.1, 0.01, 179.99 ); 00058 } 00059 } 00060 void SceneViewPerspective::display() 00061 { 00062 mProjection.setFOVY( clamp( mFOVY, 0.01, 179.99 ) ); 00063 00064 setDirection( spherical_coordinate_to_Vec3d( mSphereCoords[0], mSphereCoords[1] ) ); 00065 SceneView::display(); 00066 } 00067 00068 void SceneViewPerspective::setProjectionViewSize(const Vec2d& size) 00069 { 00070 SceneView::setProjectionViewSize(size); 00071 }