~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/ModelMount.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Interface: ModelMount
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2008
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifndef EMBEROGREMODELMOUNT_H
 
24
#define EMBEROGREMODELMOUNT_H
 
25
 
 
26
#include <wfmath/axisbox.h>
 
27
 
 
28
namespace Ogre {
 
29
        class SceneNode;
 
30
        class Node;
 
31
}
 
32
 
 
33
namespace EmberOgre {
 
34
 
 
35
namespace Model {
 
36
        class Model;
 
37
}
 
38
 
 
39
/**
 
40
        @brief Acts as a mount for a model, connecting it to two scene nodes.
 
41
        A model can contain internal orientation and offset data. This requires us to use two different scene nodes for each model instance. The inner most scene node, called the "scale node", is the one which the Model is attached to. This is then offset and oriented in relation to the outer scene node. Whenever we move the Model, we move only the outer scene node, leaving the inner scene node completely in the hands of the Model.
 
42
        The scale node will be owned by this class.
 
43
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
44
*/
 
45
class ModelMount{
 
46
public:
 
47
 
 
48
        /**
 
49
        * @brief Ctor.
 
50
        * @param model The model which we need a mount for.
 
51
        * @param mainNode The main node. A scale node will be created as a child, to which the model then will be attached. Ownership of the main node isn't transferred to this class, but the scale node that's created will be owned, and destroyed, by this class.
 
52
        */
 
53
        ModelMount(::EmberOgre::Model::Model& model, Ogre::SceneNode* mainNode);
 
54
 
 
55
        /**
 
56
         * @brief Dtor.
 
57
         * The scale node will be destroyed here.
 
58
         */
 
59
        virtual ~ModelMount();
 
60
        
 
61
        /**
 
62
         * @brief Gets the main node. This is the node to use when positioning or rotating the Model.
 
63
         * @return The main node.
 
64
         */
 
65
        Ogre::SceneNode* getMainNode() const;
 
66
 
 
67
        /**
 
68
         * @brief Gets the scale node. This is the node to which the Model is directly attached to. It should normally never be altered outside of this class.
 
69
         * Under normal circumstances the scale node is handed solely by this class and should never be modified from outside functionality. Accessing through this method is mainly for lookup purposes, when you need to read the orientation or scale of the bounding box.
 
70
         * @return The scale node, to which the Model is attached.
 
71
         */
 
72
        Ogre::SceneNode* getScaleNode() const;
 
73
        
 
74
        /**
 
75
         * @brief Gets the Model instance to which this mount is attached.
 
76
         * @return The model instance.
 
77
         */
 
78
        ::EmberOgre::Model::Model& getModel() const;
 
79
        
 
80
        /**
 
81
         * @brief Rescales the model according to the bounding box.
 
82
         * @param wfBbox The bounding box to the model should be scaled. If you don't have an axis box available, just send null.
 
83
         */
 
84
        void rescale(const WFMath::AxisBox<3>* wfBbox);
 
85
        
 
86
//      const Ogre::Vector3 calculateScaling(::EmberOgre::Model::Model& model, const WFMath::AxisBox<3>* wfBbox);
 
87
        
 
88
        
 
89
protected:
 
90
        /**
 
91
         *@brief The Model which this mount is attached to.
 
92
         */
 
93
        ::EmberOgre::Model::Model& mModel;
 
94
        
 
95
        /**
 
96
         * @brief The inner scale node, to which the model is attached to.
 
97
         * It's this node that we'll change the orientation and position of. This node should never be touched by outside functionality.
 
98
         */
 
99
        Ogre::SceneNode* mScaleNode;
 
100
        
 
101
        /**
 
102
         * @brief The main node, to which the scale node is attached.
 
103
         * This node is the external node, used for positioning the Model.
 
104
         */
 
105
        Ogre::SceneNode* mMainNode;
 
106
        
 
107
        
 
108
        /**
 
109
         * @brief Resets all scaling and rotation
 
110
         */
 
111
        void reset();
 
112
 
 
113
        /**
 
114
         * @brief Scales the scale node accoring to the submitted bounding box.
 
115
         * @note You should in almost all cases call reset() before calling this method.
 
116
         * @param wfBbox The bounding box, in WF space, for which we should scale the node, or null if there's no bbox available.
 
117
         */
 
118
        void scaleNode(const WFMath::AxisBox<3>* wfBbox);
 
119
        
 
120
        /**
 
121
         * @brief Gets the active scaling node. If the model is attached to a node already, this will be used, else the mScaleNode will be used.
 
122
         * @return The active scaling node.
 
123
         */
 
124
        Ogre::Node* getActiveScaleNode() const; 
 
125
 
 
126
};
 
127
 
 
128
inline Ogre::SceneNode* ModelMount::getMainNode() const
 
129
{
 
130
        return mMainNode;
 
131
}
 
132
 
 
133
 
 
134
inline ::EmberOgre::Model::Model& ModelMount::getModel() const
 
135
{
 
136
        return mModel;
 
137
}
 
138
 
 
139
 
 
140
}
 
141
 
 
142
#endif