source: OGRE/trunk/ogrenew/ReferenceApplication/ReferenceAppLayer/src/OgreRefAppCollideCamera.cpp @ 692

Revision 692, 8.9 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#include "OgreRefAppCollideCamera.h"
26#include "OgreRefAppWorld.h"
27#include "OgreLogManager.h"
28
29
30namespace OgreRefApp {
31
32    //-----------------------------------------------------------------------
33    CollideCamera::CollideCamera(const String& name): ApplicationObject(name)
34    {
35        setUp(name);
36       
37    }
38    //-----------------------------------------------------------------------
39    void CollideCamera::setUp(const String& name)
40    {
41        // Create visual presence
42        SceneManager* sm = World::getSingleton().getSceneManager();
43        mSceneNode = sm->getRootSceneNode()->createChildSceneNode(name);
44
45        mCamera = sm->createCamera(name);
46
47        mSceneNode->attachObject(mCamera);
48        // Add reverse reference (to self!)
49        mCamera->setUserObject(this);
50
51        // No mass body (considered static)
52
53        // Create collision proxy, at near dist
54        // SpaceID is irrelevant, we're doing our own spacial partitioning
55        dSphere* odeSphere = new dSphere(0, mCamera->getNearClipDistance());
56        mCollisionProxies.push_back(odeSphere);
57        updateCollisionProxies();
58
59
60    }
61    //-----------------------------------------------------------------------
62    void CollideCamera::_notifyCollided(SceneQuery::WorldFragment* wf, const CollisionInfo& info)
63    {
64        this->translateWorldSpace(info.normal * info.penetrationDepth);
65
66    }
67    //-----------------------------------------------------------------------
68    void CollideCamera::setOrientation(const Quaternion& orientation)
69    {
70        // Set on camera
71        mCamera->setOrientation(orientation);
72    }
73    //-----------------------------------------------------------------------
74    const Quaternion& CollideCamera::getOrientation(void)
75    {
76        return mCamera->getOrientation();
77    }
78    //-----------------------------------------------------------------------
79    void CollideCamera::roll(const Radian& angle)
80    {
81        mCamera->roll(angle);
82    }
83    //-----------------------------------------------------------------------
84    void CollideCamera::pitch(const Radian& angle)
85    {
86        mCamera->pitch(angle);
87    }
88    //-----------------------------------------------------------------------
89    void CollideCamera::yaw(const Radian& angle)
90    {
91        mCamera->yaw(angle);
92    }
93    //-----------------------------------------------------------------------
94    void CollideCamera::rotate(const Vector3& axis, const Radian& angle)
95    {
96        mCamera->rotate(axis, angle);
97    }
98    //-----------------------------------------------------------------------
99    void CollideCamera::rotate(const Quaternion& q)
100    {
101        mCamera->rotate(q);
102    }
103    //-----------------------------------------------------------------------
104    void CollideCamera::translate(const Vector3& d)
105    {
106        // Adjust position by rotation
107        Vector3 newTrans = mCamera->getOrientation() * d;
108        translateWorldSpace(newTrans);
109
110    }
111    //-----------------------------------------------------------------------
112    void CollideCamera::setProjectionType(ProjectionType pt)
113    {
114        mCamera->setProjectionType(pt);
115    }
116    //-----------------------------------------------------------------------
117    ProjectionType CollideCamera::getProjectionType(void) const
118    {
119        return mCamera->getProjectionType();
120    }
121    //-----------------------------------------------------------------------
122    void CollideCamera::setPolygonMode(PolygonMode sd)
123    {
124        mCamera->setPolygonMode(sd);
125    }
126    //-----------------------------------------------------------------------
127    PolygonMode CollideCamera::getPolygonMode(void) const
128    {
129        return mCamera->getPolygonMode();
130    }
131    //-----------------------------------------------------------------------
132    void CollideCamera::setDirection(Real x, Real y, Real z)
133    {
134        mCamera->setDirection(x, y, z);
135
136    }
137    //-----------------------------------------------------------------------
138    void CollideCamera::setDirection(const Vector3& vec)
139    {
140        mCamera->setDirection(vec);
141    }
142    //-----------------------------------------------------------------------
143    Vector3 CollideCamera::getDirection(void) const
144    {
145        return mCamera->getDirection();
146    }
147    //-----------------------------------------------------------------------
148    void CollideCamera::lookAt( const Vector3& targetPoint )
149    {
150        mCamera->lookAt(targetPoint);
151    }
152    //-----------------------------------------------------------------------
153    void CollideCamera::lookAt(Real x, Real y, Real z)
154    {
155        mCamera->lookAt(x, y, z);
156    }
157    //-----------------------------------------------------------------------
158    void CollideCamera::setFixedYawAxis( bool useFixed, const Vector3& fixedAxis)
159    {
160        mCamera->setFixedYawAxis(useFixed, fixedAxis);
161    }
162    //-----------------------------------------------------------------------
163    void CollideCamera::setFOVy(const Radian& fovy)
164    {
165        mCamera->setFOVy(fovy);
166        nearDistChanged();
167    }
168    //-----------------------------------------------------------------------
169    const Radian& CollideCamera::getFOVy(void) const
170    {
171        return mCamera->getFOVy();
172    }
173    //-----------------------------------------------------------------------
174    void CollideCamera::setNearClipDistance(Real nearDist)
175    {
176        mCamera->setNearClipDistance(nearDist);
177        nearDistChanged();
178    }
179    //-----------------------------------------------------------------------
180    Real CollideCamera::getNearClipDistance(void) const
181    {
182        return mCamera->getNearClipDistance();
183    }
184    //-----------------------------------------------------------------------
185    void CollideCamera::setFarClipDistance(Real farDist)
186    {
187        mCamera->setFarClipDistance(farDist);
188    }
189    //-----------------------------------------------------------------------
190    Real CollideCamera::getFarClipDistance(void) const
191    {
192        return mCamera->getFarClipDistance();
193    }
194    //-----------------------------------------------------------------------
195    void CollideCamera::setAspectRatio(Real ratio)
196    {
197        mCamera->setAspectRatio(ratio);
198    }
199    //-----------------------------------------------------------------------
200    Real CollideCamera::getAspectRatio(void) const
201    {
202        return mCamera->getAspectRatio();
203    }
204    //-----------------------------------------------------------------------
205    const Plane& CollideCamera::getFrustumPlane( FrustumPlane plane )
206    {
207        return mCamera->getFrustumPlane(plane);
208    }
209    //-----------------------------------------------------------------------
210    bool CollideCamera::isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy)
211    {
212        return mCamera->isVisible(bound, culledBy);
213    }
214    //-----------------------------------------------------------------------
215    bool CollideCamera::isVisible(const Sphere& bound, FrustumPlane* culledBy)
216    {
217        return mCamera->isVisible(bound, culledBy);
218    }
219    //-----------------------------------------------------------------------
220    bool CollideCamera::isVisible(const Vector3& vert, FrustumPlane* culledBy)
221    {
222        return mCamera->isVisible(vert, culledBy);
223    }
224    //-----------------------------------------------------------------------
225    void CollideCamera::nearDistChanged(void)
226    {
227        // Alter the size of the collision proxy to compensate
228        CollisionProxyList::iterator i = mCollisionProxies.begin();
229        dSphere* sph = static_cast<dSphere*>(*i);
230        sph->setRadius(getNearClipDistance());
231    }
232
233}
234
Note: See TracBrowser for help on using the repository browser.