00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "ortho_camera.h"
00032 #include "wx_ogre_render_window.h"
00033
00034 #include "ros/assert.h"
00035
00036 #include <OGRE/OgreCamera.h>
00037 #include <OGRE/OgreSceneManager.h>
00038 #include <OGRE/OgreSceneNode.h>
00039 #include <OGRE/OgreVector3.h>
00040 #include <OGRE/OgreQuaternion.h>
00041
00042 namespace ogre_tools
00043 {
00044
00045 OrthoCamera::OrthoCamera( wxOgreRenderWindow* render_window, Ogre::SceneManager* scene_manager )
00046 : CameraBase( scene_manager )
00047 , scale_( 10.0f )
00048 , render_window_( render_window )
00049 {
00050 camera_->setProjectionType( Ogre::PT_ORTHOGRAPHIC );
00051 camera_->setNearClipDistance(0.001f);
00052 camera_->setFarClipDistance(50.0f);
00053 camera_->setFixedYawAxis(false);
00054
00055 update();
00056 }
00057
00058 OrthoCamera::~OrthoCamera()
00059 {
00060 }
00061
00062 void OrthoCamera::update()
00063 {
00064 render_window_->setOrthoScale( scale_ );
00065 }
00066
00067 void OrthoCamera::yaw( float angle )
00068 {
00069 camera_->yaw( Ogre::Radian( angle ) );
00070 }
00071
00072 void OrthoCamera::pitch( float angle )
00073 {
00074 camera_->pitch( Ogre::Radian( angle ) );
00075 }
00076
00077 void OrthoCamera::roll( float angle )
00078 {
00079 camera_->roll( Ogre::Radian( angle ) );
00080 }
00081
00082 Ogre::Vector3 OrthoCamera::getPosition()
00083 {
00084 return camera_->getPosition();
00085 }
00086
00087 Ogre::Quaternion OrthoCamera::getOrientation()
00088 {
00089 return camera_->getOrientation();
00090 }
00091
00092 void OrthoCamera::setFrom( CameraBase* camera )
00093 {
00094 ROS_BREAK();
00095 }
00096
00097 void OrthoCamera::setOrientation( float x, float y, float z, float w )
00098 {
00099 camera_->setOrientation(Ogre::Quaternion(w, x, y, z));
00100 }
00101
00102 void OrthoCamera::move( float x, float y, float z )
00103 {
00104 camera_->moveRelative( Ogre::Vector3( x, y, z ) );
00105 }
00106
00107 void OrthoCamera::setPosition( float x, float y, float z )
00108 {
00109 camera_->setPosition( x, y, z );
00110 }
00111
00112 void OrthoCamera::lookAt( const Ogre::Vector3& point )
00113 {
00114
00115 Ogre::Vector3 current_pos = camera_->getPosition();
00116 current_pos.x = point.x;
00117 current_pos.z = point.z;
00118 camera_->setPosition(current_pos);
00119 }
00120
00121 void OrthoCamera::mouseLeftDrag( int diff_x, int diff_y, bool ctrl, bool alt, bool shift )
00122 {
00123 roll( -diff_x * 0.005 );
00124 }
00125
00126 void OrthoCamera::mouseMiddleDrag( int diff_x, int diff_y, bool ctrl, bool alt, bool shift )
00127 {
00128 move( -diff_x / scale_, diff_y / scale_, 0.0f );
00129 }
00130
00131 void OrthoCamera::mouseRightDrag( int diff_x, int diff_y, bool ctrl, bool alt, bool shift )
00132 {
00133 scale_ *= 1.0 - diff_y * 0.01;
00134
00135 update();
00136 }
00137
00138 void OrthoCamera::scrollWheel( int diff, bool ctrl, bool alt, bool shift )
00139 {
00140 scale_ *= 1.0 - (-diff) * 0.001;
00141
00142 update();
00143 }
00144
00145 void OrthoCamera::fromString(const std::string& str)
00146 {
00147 std::istringstream iss(str);
00148
00149 iss >> scale_;
00150 iss.ignore();
00151
00152 Ogre::Vector3 vec;
00153 iss >> vec.x;
00154 iss.ignore();
00155 iss >> vec.y;
00156 iss.ignore();
00157 iss >> vec.z;
00158 iss.ignore();
00159 camera_->setPosition(vec);
00160
00161 Ogre::Quaternion quat;
00162 iss >> quat.x;
00163 iss.ignore();
00164 iss >> quat.y;
00165 iss.ignore();
00166 iss >> quat.z;
00167 iss.ignore();
00168 iss >> quat.w;
00169 iss.ignore();
00170 camera_->setOrientation(quat);
00171
00172 update();
00173 }
00174
00175 std::string OrthoCamera::toString()
00176 {
00177 std::ostringstream oss;
00178 oss << scale_ << " " << camera_->getPosition().x << " " << camera_->getPosition().y << " " << camera_->getPosition().z
00179 << " " << camera_->getOrientation().x << " " << camera_->getOrientation().y << " " << camera_->getOrientation().z << " " << camera_->getOrientation().w;
00180
00181 return oss.str();
00182 }
00183
00184 }