$search
00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 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 //camera_->lookAt( point ); 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 } // namespace ogre_tools