1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of the OGRE Reference Application, a layer built
|
---|
4 | on top of OGRE(Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __REFAPP_JOINT_H__
|
---|
26 | #define __REFAPP_JOINT_H__
|
---|
27 |
|
---|
28 | #include "OgreRefAppPrerequisites.h"
|
---|
29 |
|
---|
30 | namespace OgreRefApp {
|
---|
31 |
|
---|
32 | /** Represents a linkage between application objects or between them and the world, enforcing
|
---|
33 | certain constraints.
|
---|
34 | @remarks
|
---|
35 | Joints can be used to link application objects together, or to link them to a static point
|
---|
36 | in the world according to certain constraints. You should create joints using
|
---|
37 | World::createJoint. You should then set certain global options, like it's world
|
---|
38 | anchor position, before attaching it to application objects. You application objects
|
---|
39 | should already be positioned how you would like relative to the joint anchor, since once
|
---|
40 | they are attached, they will be constrained by it.
|
---|
41 | */
|
---|
42 | class _OgreRefAppExport Joint
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | /// The type of joint
|
---|
46 | enum JointType {
|
---|
47 | /// Ball & socket joint, has 3 degrees of freedom
|
---|
48 | JT_BALL,
|
---|
49 | /// Sliding joint, 1 degree of freedom (in-out)
|
---|
50 | JT_SLIDER,
|
---|
51 | /// Hinge joint, 1 degree of freedom
|
---|
52 | JT_HINGE,
|
---|
53 | /// Universal joint, like a double-hinge, 2 degrees of freedom
|
---|
54 | JT_UNIVERSAL,
|
---|
55 | /// 2 hinges in series, like the axel of a car
|
---|
56 | JT_HINGE2
|
---|
57 | };
|
---|
58 | /** Constructor, however you should use World::createJoint(type, obj1, obj2). */
|
---|
59 | Joint(JointType jtype);
|
---|
60 | virtual ~Joint() { if (mOdeJoint) delete mOdeJoint; }
|
---|
61 |
|
---|
62 |
|
---|
63 | /** Returns the type of this joint. */
|
---|
64 | JointType getType(void);
|
---|
65 | /** Set the anchor point of this joint.
|
---|
66 | @remarks
|
---|
67 | Sets the location, in world space, of the anchor point of this joint, which is usually
|
---|
68 | the hinge point or just the origin of joint. It has no meaning for JT_SLIDER and thus
|
---|
69 | you don't need to call it for that.
|
---|
70 | */
|
---|
71 | virtual void setAnchorPosition(const Vector3& point) = 0;
|
---|
72 |
|
---|
73 | /** Gets the anchor position of this joint. */
|
---|
74 | virtual const Vector3& getAnchorPosition(void);
|
---|
75 |
|
---|
76 |
|
---|
77 | /** Gets the attached objects, a NULL means no object ie a static attachment. */
|
---|
78 | virtual const std::pair<ApplicationObject*, ApplicationObject*>& getAttachments(void);
|
---|
79 |
|
---|
80 | /** Sets the axes for this joint.
|
---|
81 | @remarks
|
---|
82 | The meaning of axes for a joint depends on it's type:
|
---|
83 | <ul>
|
---|
84 | <li>For JT_BALL, it has no meaning and you don't need to call it.</li>
|
---|
85 | <li>For JT_SLIDER, only one is applicable and it's the axis along which the slide occurs. </li>
|
---|
86 | <li>For JT_HINGE, only one is applicable and it's the hinge axis. </li>
|
---|
87 | <li>For JT_UNIVERSAL, and JT_HINGE2 it's the 2 hinge axes.</li>
|
---|
88 | </ul>
|
---|
89 | */
|
---|
90 | virtual void setAxes(const Vector3& primaryAxis, const Vector3& secondaryAxis = Vector3::ZERO) = 0;
|
---|
91 |
|
---|
92 | /** Gets the axes of this joint. */
|
---|
93 | virtual const std::pair<Vector3, Vector3>& getAxes(void);
|
---|
94 |
|
---|
95 | protected:
|
---|
96 |
|
---|
97 | /** Sets the objects attached to this joint.
|
---|
98 | @remarks
|
---|
99 | It appears that this has to be set before other joint params like
|
---|
100 | anchor etc, otherwise the joint does not behave. Therefore it is internal
|
---|
101 | and is called during construction.
|
---|
102 | */
|
---|
103 | void setAttachments(ApplicationObject* obj1, ApplicationObject* obj2);
|
---|
104 |
|
---|
105 | JointType mType;
|
---|
106 | Vector3 mAnchor;
|
---|
107 | std::pair<ApplicationObject*, ApplicationObject*> mAttachedObjects;
|
---|
108 | std::pair<Vector3, Vector3> mAxes;
|
---|
109 |
|
---|
110 | // ODE object
|
---|
111 | dJoint* mOdeJoint;
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 | };
|
---|
122 | }
|
---|
123 |
|
---|
124 | #endif
|
---|