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

« back to all changes in this revision

Viewing changes to src/components/ogre/carpenter/BluePrint.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: BluePrint
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
 
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 CARPENTERBLUEPRINT_H
 
24
#define CARPENTERBLUEPRINT_H
 
25
// ------------------------------
 
26
// Include WFmath header files
 
27
// ------------------------------
 
28
#include <wfmath/point.h>
 
29
#include <wfmath/vector.h>
 
30
#include <wfmath/axisbox.h>
 
31
#include <wfmath/quaternion.h>
 
32
 
 
33
#include "Carpenter.h"
 
34
 
 
35
namespace Carpenter {
 
36
 
 
37
class AttachPair;
 
38
class AttachPoint;
 
39
class BlockSpec;
 
40
class BuildingBlock;
 
41
class BuildingBlockSpec;
 
42
class BuildingBlockSpecDefinition;
 
43
class BuildingBlockBinding;
 
44
class BuildingBlockBindingDefinition;
 
45
class BuildingBlockDefinition;
 
46
class BluePrint;
 
47
class Carpenter;
 
48
 
 
49
/**
 
50
@author Erik Hjortsberg
 
51
*/
 
52
 
 
53
 
 
54
 
 
55
class BuildingBlockBindingDefinition
 
56
{
 
57
public:
 
58
        BuildingBlockBindingDefinition() {}
 
59
         std::string mBlock1Name;
 
60
         std::string mBlock2Name;
 
61
         std::string mPair1Name;
 
62
         std::string mPair2Name;
 
63
         std::string mPoint1Name;
 
64
         std::string mPoint2Name;
 
65
};
 
66
 
 
67
class BuildingBlockBinding
 
68
{
 
69
friend class BluePrint;
 
70
public:
 
71
        BuildingBlockBinding(const BuildingBlock* block1, const AttachPoint* point1, const BuildingBlock* block2,       const AttachPoint* point2);
 
72
        const std::string& getType() const;
 
73
        const BuildingBlock* getBlock1() const { return mBlock1; }
 
74
        const BuildingBlock* getBlock2() const { return mBlock2; }
 
75
        const AttachPoint* getAttachPoint1() const { return mPoint1; }
 
76
        const AttachPoint* getAttachPoint2() const { return mPoint2; }
 
77
 
 
78
 
 
79
protected:
 
80
        const BuildingBlock* mBlock1;
 
81
        const AttachPoint* mPoint1;
 
82
        const BuildingBlock* mBlock2;
 
83
        const AttachPoint* mPoint2;
 
84
};
 
85
 
 
86
 
 
87
 
 
88
 
 
89
 
 
90
 
 
91
 
 
92
 
 
93
 
 
94
class BuildingBlockDefinition
 
95
{
 
96
public:
 
97
        BuildingBlockDefinition() {}
 
98
         std::string mName;
 
99
         std::string mBuildingBlockSpec;
 
100
};
 
101
 
 
102
class BuildingBlock
 
103
{
 
104
friend class BluePrint;
 
105
public:
 
106
        BuildingBlock();
 
107
        const std::vector<BuildingBlockBinding*> getBindingsForBlock() const;
 
108
        const AttachPair* getAttachPair(const std::string& name);
 
109
        const std::string& getName() const { return mBlockDefinition.mName; }
 
110
        
 
111
        
 
112
        WFMath::Point<3> getWorldPositionForPoint(const AttachPoint* point);
 
113
        bool isAttached() const;
 
114
        
 
115
        
 
116
 
 
117
        void setPosition(WFMath::Point<3> position);
 
118
        void setOrientation(WFMath::Quaternion orientation);
 
119
        const WFMath::Point<3>& getPosition() const;
 
120
        const WFMath::Quaternion& getOrientation() const;
 
121
        
 
122
        const BuildingBlockSpec* getBuildingBlockSpec() const;
 
123
        
 
124
        const BlockSpec* getBlockSpec() const;
 
125
        
 
126
        const std::vector<const AttachPoint*> getAllPoints() const;
 
127
        
 
128
        /**
 
129
         *    the number of bindings that are dependant on this block
 
130
                        as long as it's more than zero, the block cannot be deleted
 
131
         * @return 
 
132
         */
 
133
        int getNumberOfChildBindings() const;
 
134
        
 
135
protected:      
 
136
        //ModelBlock mModelBlock;
 
137
        BuildingBlockSpec* mBuildingBlockSpec;
 
138
        BuildingBlockDefinition mBlockDefinition;
 
139
        WFMath::Point<3> mPosition;
 
140
        WFMath::Quaternion mOrientation;
 
141
        bool mAttached;
 
142
        /**
 
143
                A vector of all points that are already bound
 
144
        */
 
145
        std::vector<const AttachPoint*> mBoundPoints;
 
146
        
 
147
        /**
 
148
         *    removes a point from the list of bound points
 
149
         * @param point 
 
150
         */
 
151
        void removeBoundPoint(const AttachPoint* point);
 
152
        
 
153
        /**
 
154
        the number of bindings that are dependant on this block
 
155
        as long as it's more than zero, the block cannot be deleted
 
156
        */
 
157
        int mChildBindings;
 
158
 
 
159
};
 
160
 
 
161
 
 
162
inline bool BuildingBlock::isAttached() const { return mAttached; }
 
163
inline void BuildingBlock::setPosition(WFMath::Point<3> position) { mPosition = position;}
 
164
inline void BuildingBlock::setOrientation(WFMath::Quaternion orientation) { mOrientation = orientation;}
 
165
inline const WFMath::Point<3>& BuildingBlock::getPosition() const { return mPosition;}
 
166
inline const WFMath::Quaternion& BuildingBlock::getOrientation() const { return mOrientation;}
 
167
inline const BuildingBlockSpec* BuildingBlock::getBuildingBlockSpec() const { return mBuildingBlockSpec; }
 
168
inline const BlockSpec* BuildingBlock::getBlockSpec() const { return mBuildingBlockSpec->getBlockSpec(); }
 
169
inline int BuildingBlock::getNumberOfChildBindings() const { return mChildBindings; }
 
170
 
 
171
 
 
172
 
 
173
 
 
174
 
 
175
class BluePrint
 
176
{
 
177
public:
 
178
        BluePrint(const std::string & name, Carpenter* carpenter);
 
179
        
 
180
        const std::string& getName() const;
 
181
        
 
182
        /**
 
183
         *    compiles the blueprint into a structure
 
184
         */
 
185
        void compile();
 
186
        
 
187
        BuildingBlock* createBuildingBlock(BuildingBlockDefinition);
 
188
        
 
189
        /**
 
190
         *    deletes a building block from the blueprint
 
191
         * @param name 
 
192
         */
 
193
//      void deleteBuildingBlock(const std::string & name);
 
194
 
 
195
        BuildingBlockBinding* addBinding(BuildingBlockBindingDefinition definition);
 
196
        BuildingBlockBinding* addBinding(const BuildingBlock* block1, const AttachPoint* point1, const BuildingBlock* block2,   const AttachPoint* point2);
 
197
        const std::vector< BuildingBlock*> getAttachedBlocks() const;
 
198
        const std::list< BuildingBlockBinding>* getBindings() const;
 
199
 
 
200
        /**
 
201
         *    accessor for the name of the starting block
 
202
         * @param name 
 
203
         */
 
204
        void setStartingBlock(const std::string& name);
 
205
        const BuildingBlock* getStartingBlock() const;
 
206
        
 
207
        /**
 
208
         *    Places the unbound block in the supplied bindings correctly
 
209
         * @param binding 
 
210
         */
 
211
        void placeBindings(BuildingBlock* unboundBlock, std::vector<BuildingBlockBinding*> bindings);
 
212
        
 
213
        Carpenter* const getCarpenter();
 
214
        
 
215
        
 
216
        /**
 
217
         *    true if the building block can be removed from the blueprint
 
218
         * @param  
 
219
         * @return 
 
220
         */
 
221
        bool isRemovable(const BuildingBlock* bblock) const;
 
222
        
 
223
        /**
 
224
         *    removes the building block from the blueprint, if it can be removed
 
225
         * @param bblock 
 
226
         * @return 
 
227
         */
 
228
        bool remove(const BuildingBlock* bblock);
 
229
 
 
230
        typedef std::map<const std::string,  BuildingBlock> BuildingBlockStore;
 
231
protected:
 
232
        BuildingBlockStore mBuildingBlocks;
 
233
        std::list< BuildingBlockBinding> mBindings;
 
234
        
 
235
        std::vector< BuildingBlock*> mAttachedBlocks;
 
236
        BuildingBlock* mStartingBlock;
 
237
        std::string mName;
 
238
        
 
239
        Carpenter* mCarpenter;
 
240
        
 
241
        
 
242
        void doBindingsForBlock(BuildingBlock *block);
 
243
 
 
244
};
 
245
 
 
246
inline Carpenter* const BluePrint::getCarpenter() { return mCarpenter;}
 
247
inline const std::string& BluePrint::getName() const {return mName;}
 
248
inline const BuildingBlock* BluePrint::getStartingBlock() const {return mStartingBlock;}
 
249
 
 
250
};
 
251
 
 
252
#endif