Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreRefAppCollideCamera.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of the OGRE Reference Application, a layer built
00004 on top of OGRE(Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2003 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #include "OgreRefAppCollideCamera.h"
00026 #include "OgreRefAppWorld.h"
00027 #include "OgreLogManager.h"
00028 
00029 
00030 namespace OgreRefApp {
00031 
00032     //-----------------------------------------------------------------------
00033     CollideCamera::CollideCamera(const String& name): ApplicationObject(name) 
00034     {
00035         setUp(name);
00036         
00037     }
00038     //-----------------------------------------------------------------------
00039     void CollideCamera::setUp(const String& name)
00040     {
00041         // Create visual presence
00042         SceneManager* sm = World::getSingleton().getSceneManager();
00043         mSceneNode = sm->getRootSceneNode()->createChildSceneNode(name);
00044 
00045         mCamera = sm->createCamera(name);
00046 
00047         mSceneNode->attachObject(mCamera);
00048         // Add reverse reference (to self!)
00049         mCamera->setUserObject(this);
00050 
00051         // No mass body (considered static)
00052 
00053         // Create collision proxy, at near dist
00054         // SpaceID is irrelevant, we're doing our own spacial partitioning
00055         dSphere* odeSphere = new dSphere(0, mCamera->getNearClipDistance());
00056         mCollisionProxies.push_back(odeSphere);
00057         updateCollisionProxies();
00058 
00059 
00060     }
00061     //-----------------------------------------------------------------------
00062     void CollideCamera::_notifyCollided(SceneQuery::WorldFragment* wf, const CollisionInfo& info) 
00063     {
00064         this->translateWorldSpace(info.normal * info.penetrationDepth);
00065 
00066     }
00067     //-----------------------------------------------------------------------
00068     void CollideCamera::setOrientation(const Quaternion& orientation)
00069     {
00070         // Set on camera
00071         mCamera->setOrientation(orientation);
00072     }
00073     //-----------------------------------------------------------------------
00074     const Quaternion& CollideCamera::getOrientation(void)
00075     {
00076         return mCamera->getOrientation();
00077     }
00078     //-----------------------------------------------------------------------
00079     void CollideCamera::roll(Real angleunits) 
00080     {
00081         mCamera->roll(angleunits);
00082     }
00083     //-----------------------------------------------------------------------
00084     void CollideCamera::pitch(Real angleunits) 
00085     {
00086         mCamera->pitch(angleunits);
00087     }
00088     //-----------------------------------------------------------------------
00089     void CollideCamera::yaw(Real angleunits) 
00090     {
00091         mCamera->yaw(angleunits);
00092     }
00093     //-----------------------------------------------------------------------
00094     void CollideCamera::rotate(const Vector3& axis, Real angleunits) 
00095     {
00096         mCamera->rotate(axis, angleunits);
00097     }
00098     //-----------------------------------------------------------------------
00099     void CollideCamera::rotate(const Quaternion& q)
00100     {
00101         mCamera->rotate(q);
00102     }
00103     //-----------------------------------------------------------------------
00104     void CollideCamera::translate(const Vector3& d)
00105     {
00106         // Adjust position by rotation
00107         Vector3 newTrans = mCamera->getOrientation() * d;
00108         translateWorldSpace(newTrans);
00109 
00110     }
00111     //-----------------------------------------------------------------------
00112     void CollideCamera::setProjectionType(ProjectionType pt) 
00113     {
00114         mCamera->setProjectionType(pt);
00115     }
00116     //-----------------------------------------------------------------------
00117     ProjectionType CollideCamera::getProjectionType(void) const 
00118     {
00119         return mCamera->getProjectionType();
00120     }
00121     //-----------------------------------------------------------------------
00122     void CollideCamera::setDetailLevel(SceneDetailLevel sd) 
00123     {
00124         mCamera->setDetailLevel(sd);
00125     }
00126     //-----------------------------------------------------------------------
00127     SceneDetailLevel CollideCamera::getDetailLevel(void) const 
00128     {
00129         return mCamera->getDetailLevel();
00130     }
00131     //-----------------------------------------------------------------------
00132     void CollideCamera::setDirection(Real x, Real y, Real z) 
00133     {
00134         mCamera->setDirection(x, y, z);
00135 
00136     }
00137     //-----------------------------------------------------------------------
00138     void CollideCamera::setDirection(const Vector3& vec) 
00139     {
00140         mCamera->setDirection(vec);
00141     }
00142     //-----------------------------------------------------------------------
00143     Vector3 CollideCamera::getDirection(void) const 
00144     {
00145         return mCamera->getDirection();
00146     }
00147     //-----------------------------------------------------------------------
00148     void CollideCamera::lookAt( const Vector3& targetPoint ) 
00149     {
00150         mCamera->lookAt(targetPoint);
00151     }
00152     //-----------------------------------------------------------------------
00153     void CollideCamera::lookAt(Real x, Real y, Real z) 
00154     {
00155         mCamera->lookAt(x, y, z);
00156     }
00157     //-----------------------------------------------------------------------
00158     void CollideCamera::setFixedYawAxis( bool useFixed, const Vector3& fixedAxis) 
00159     {
00160         mCamera->setFixedYawAxis(useFixed, fixedAxis);
00161     }
00162     //-----------------------------------------------------------------------
00163     void CollideCamera::setFOVy(Real fovy) 
00164     {
00165         mCamera->setFOVy(fovy);
00166         nearDistChanged();
00167     }
00168     //-----------------------------------------------------------------------
00169     Real CollideCamera::getFOVy(void) const 
00170     {
00171         return mCamera->getFOVy();
00172     }
00173     //-----------------------------------------------------------------------
00174     void CollideCamera::setNearClipDistance(Real nearDist) 
00175     {
00176         mCamera->setNearClipDistance(nearDist);
00177         nearDistChanged();
00178     }
00179     //-----------------------------------------------------------------------
00180     Real CollideCamera::getNearClipDistance(void) const 
00181     {
00182         return mCamera->getNearClipDistance();
00183     }
00184     //-----------------------------------------------------------------------
00185     void CollideCamera::setFarClipDistance(Real farDist) 
00186     {
00187         mCamera->setFarClipDistance(farDist);
00188     }
00189     //-----------------------------------------------------------------------
00190     Real CollideCamera::getFarClipDistance(void) const 
00191     {
00192         return mCamera->getFarClipDistance();
00193     }
00194     //-----------------------------------------------------------------------
00195     void CollideCamera::setAspectRatio(Real ratio) 
00196     {
00197         mCamera->setAspectRatio(ratio);
00198     }
00199     //-----------------------------------------------------------------------
00200     Real CollideCamera::getAspectRatio(void) const 
00201     {
00202         return mCamera->getAspectRatio();
00203     }
00204     //-----------------------------------------------------------------------
00205     const Plane& CollideCamera::getFrustumPlane( FrustumPlane plane ) 
00206     {
00207         return mCamera->getFrustumPlane(plane);
00208     }
00209     //-----------------------------------------------------------------------
00210     bool CollideCamera::isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy) 
00211     {
00212         return mCamera->isVisible(bound, culledBy);
00213     }
00214     //-----------------------------------------------------------------------
00215     bool CollideCamera::isVisible(const Sphere& bound, FrustumPlane* culledBy) 
00216     {
00217         return mCamera->isVisible(bound, culledBy);
00218     }
00219     //-----------------------------------------------------------------------
00220     bool CollideCamera::isVisible(const Vector3& vert, FrustumPlane* culledBy) 
00221     {
00222         return mCamera->isVisible(vert, culledBy);
00223     }
00224     //-----------------------------------------------------------------------
00225     void CollideCamera::nearDistChanged(void)
00226     {
00227         // Alter the size of the collision proxy to compensate
00228         CollisionProxyList::iterator i = mCollisionProxies.begin();
00229         dSphere* sph = static_cast<dSphere*>(*i);
00230         sph->setRadius(getNearClipDistance());
00231     }
00232 
00233 }
00234 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:24 2004