Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ReferenceApplication/ReferenceAppLayer/src/OgreRefAppCollideCamera.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 9.1 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of the OGRE Reference Application, a layer built
4on top of OGRE(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreRefAppCollideCamera.h"
30#include "OgreRefAppWorld.h"
31#include "OgreLogManager.h"
32
33
34namespace OgreRefApp {
35
36    //-----------------------------------------------------------------------
37    CollideCamera::CollideCamera(const String& name): ApplicationObject(name) 
38    {
39        setUp(name);
40       
41    }
42    //-----------------------------------------------------------------------
43    void CollideCamera::setUp(const String& name)
44    {
45        // Create visual presence
46        SceneManager* sm = World::getSingleton().getSceneManager();
47        mSceneNode = sm->getRootSceneNode()->createChildSceneNode(name);
48
49        mCamera = sm->createCamera(name);
50
51        mSceneNode->attachObject(mCamera);
52        // Add reverse reference (to self!)
53        mCamera->setUserObject(this);
54
55        // No mass body (considered static)
56
57        // Create collision proxy, at near dist
58        // SpaceID is irrelevant, we're doing our own spacial partitioning
59        dSphere* odeSphere = new dSphere(0, mCamera->getNearClipDistance());
60        mCollisionProxies.push_back(odeSphere);
61        updateCollisionProxies();
62
63
64    }
65    //-----------------------------------------------------------------------
66    void CollideCamera::_notifyCollided(SceneQuery::WorldFragment* wf, const CollisionInfo& info) 
67    {
68        this->translateWorldSpace(info.normal * info.penetrationDepth);
69
70    }
71    //-----------------------------------------------------------------------
72    void CollideCamera::setOrientation(const Quaternion& orientation)
73    {
74        // Set on camera
75        mCamera->setOrientation(orientation);
76    }
77    //-----------------------------------------------------------------------
78    const Quaternion& CollideCamera::getOrientation(void)
79    {
80        return mCamera->getOrientation();
81    }
82    //-----------------------------------------------------------------------
83    void CollideCamera::roll(const Radian& angle) 
84    {
85        mCamera->roll(angle);
86    }
87    //-----------------------------------------------------------------------
88    void CollideCamera::pitch(const Radian& angle) 
89    {
90        mCamera->pitch(angle);
91    }
92    //-----------------------------------------------------------------------
93    void CollideCamera::yaw(const Radian& angle) 
94    {
95        mCamera->yaw(angle);
96    }
97    //-----------------------------------------------------------------------
98    void CollideCamera::rotate(const Vector3& axis, const Radian& angle) 
99    {
100        mCamera->rotate(axis, angle);
101    }
102    //-----------------------------------------------------------------------
103    void CollideCamera::rotate(const Quaternion& q)
104    {
105        mCamera->rotate(q);
106    }
107    //-----------------------------------------------------------------------
108    void CollideCamera::translate(const Vector3& d)
109    {
110        // Adjust position by rotation
111        Vector3 newTrans = mCamera->getOrientation() * d;
112        translateWorldSpace(newTrans);
113
114    }
115    //-----------------------------------------------------------------------
116    void CollideCamera::setProjectionType(ProjectionType pt) 
117    {
118        mCamera->setProjectionType(pt);
119    }
120    //-----------------------------------------------------------------------
121    ProjectionType CollideCamera::getProjectionType(void) const 
122    {
123        return mCamera->getProjectionType();
124    }
125    //-----------------------------------------------------------------------
126    void CollideCamera::setPolygonMode(PolygonMode sd) 
127    {
128        mCamera->setPolygonMode(sd);
129    }
130    //-----------------------------------------------------------------------
131    PolygonMode CollideCamera::getPolygonMode(void) const 
132    {
133        return mCamera->getPolygonMode();
134    }
135    //-----------------------------------------------------------------------
136    void CollideCamera::setDirection(Real x, Real y, Real z) 
137    {
138        mCamera->setDirection(x, y, z);
139
140    }
141    //-----------------------------------------------------------------------
142    void CollideCamera::setDirection(const Vector3& vec) 
143    {
144        mCamera->setDirection(vec);
145    }
146    //-----------------------------------------------------------------------
147    Vector3 CollideCamera::getDirection(void) const 
148    {
149        return mCamera->getDirection();
150    }
151    //-----------------------------------------------------------------------
152    void CollideCamera::lookAt( const Vector3& targetPoint ) 
153    {
154        mCamera->lookAt(targetPoint);
155    }
156    //-----------------------------------------------------------------------
157    void CollideCamera::lookAt(Real x, Real y, Real z) 
158    {
159        mCamera->lookAt(x, y, z);
160    }
161    //-----------------------------------------------------------------------
162    void CollideCamera::setFixedYawAxis( bool useFixed, const Vector3& fixedAxis) 
163    {
164        mCamera->setFixedYawAxis(useFixed, fixedAxis);
165    }
166    //-----------------------------------------------------------------------
167    void CollideCamera::setFOVy(const Radian& fovy)
168    {
169        mCamera->setFOVy(fovy);
170        nearDistChanged();
171    }
172    //-----------------------------------------------------------------------
173    const Radian& CollideCamera::getFOVy(void) const
174    {
175        return mCamera->getFOVy();
176    }
177    //-----------------------------------------------------------------------
178    void CollideCamera::setNearClipDistance(Real nearDist) 
179    {
180        mCamera->setNearClipDistance(nearDist);
181        nearDistChanged();
182    }
183    //-----------------------------------------------------------------------
184    Real CollideCamera::getNearClipDistance(void) const 
185    {
186        return mCamera->getNearClipDistance();
187    }
188    //-----------------------------------------------------------------------
189    void CollideCamera::setFarClipDistance(Real farDist) 
190    {
191        mCamera->setFarClipDistance(farDist);
192    }
193    //-----------------------------------------------------------------------
194    Real CollideCamera::getFarClipDistance(void) const 
195    {
196        return mCamera->getFarClipDistance();
197    }
198    //-----------------------------------------------------------------------
199    void CollideCamera::setAspectRatio(Real ratio) 
200    {
201        mCamera->setAspectRatio(ratio);
202    }
203    //-----------------------------------------------------------------------
204    Real CollideCamera::getAspectRatio(void) const 
205    {
206        return mCamera->getAspectRatio();
207    }
208    //-----------------------------------------------------------------------
209    const Plane& CollideCamera::getFrustumPlane( FrustumPlane plane ) 
210    {
211        return mCamera->getFrustumPlane(plane);
212    }
213    //-----------------------------------------------------------------------
214    bool CollideCamera::isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy) 
215    {
216        return mCamera->isVisible(bound, culledBy);
217    }
218    //-----------------------------------------------------------------------
219    bool CollideCamera::isVisible(const Sphere& bound, FrustumPlane* culledBy) 
220    {
221        return mCamera->isVisible(bound, culledBy);
222    }
223    //-----------------------------------------------------------------------
224    bool CollideCamera::isVisible(const Vector3& vert, FrustumPlane* culledBy) 
225    {
226        return mCamera->isVisible(vert, culledBy);
227    }
228    //-----------------------------------------------------------------------
229    void CollideCamera::nearDistChanged(void)
230    {
231        // Alter the size of the collision proxy to compensate
232        CollisionProxyList::iterator i = mCollisionProxies.begin();
233        dSphere* sph = static_cast<dSphere*>(*i);
234        sph->setRadius(getNearClipDistance());
235    }
236
237}
238
Note: See TracBrowser for help on using the repository browser.