~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to COLLADASaxFrameworkLoader/src/COLLADASaxFWLLibraryCamerasLoader.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of COLLADASaxFrameworkLoader.
 
5
 
 
6
    Licensed under the MIT Open Source License, 
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#include "COLLADASaxFWLStableHeaders.h"
 
12
#include "COLLADASaxFWLLibraryCamerasLoader.h"
 
13
#include "COLLADASaxFWLLoader.h"
 
14
#include "COLLADASaxFWLFileLoader.h"
 
15
 
 
16
#include "COLLADAFWIWriter.h"
 
17
#include "COLLADAFWCamera.h"
 
18
 
 
19
 
 
20
namespace COLLADASaxFWL
 
21
{
 
22
 
 
23
    //------------------------------
 
24
        LibraryCamerasLoader::LibraryCamerasLoader( IFilePartLoader* callingFilePartLoader )
 
25
                : FilePartLoader(callingFilePartLoader)
 
26
                , mCurrentCamera(0)
 
27
                , mCurrentCameraHasX(false)
 
28
                , mCurrentCameraHasY(false)
 
29
                , mCurrentCameraHasAspectRatio(false)
 
30
                , mInOptics(false)
 
31
        {
 
32
        }
 
33
 
 
34
    //------------------------------
 
35
        LibraryCamerasLoader::~LibraryCamerasLoader()
 
36
        {
 
37
        }
 
38
 
 
39
        //------------------------------
 
40
        void LibraryCamerasLoader::resetCurrentValues()
 
41
        {
 
42
                mCurrentCamera = 0;
 
43
                mCurrentCameraHasX = false;
 
44
                mCurrentCameraHasY = false;
 
45
                mCurrentCameraHasAspectRatio = false;
 
46
        }
 
47
 
 
48
    //------------------------------
 
49
    const COLLADAFW::UniqueId& LibraryCamerasLoader::getUniqueId ()
 
50
    {
 
51
        if ( mCurrentCamera )
 
52
            return mCurrentCamera->getUniqueId ();
 
53
        return COLLADAFW::UniqueId::INVALID;
 
54
    }
 
55
 
 
56
        //------------------------------
 
57
        bool LibraryCamerasLoader::end__library_cameras()
 
58
        {
 
59
                getFileLoader()->moveUpInSidTree();
 
60
                finish();
 
61
                return true;
 
62
        }
 
63
 
 
64
        //------------------------------
 
65
        bool LibraryCamerasLoader::begin__camera( const camera__AttributeData& attributeData )
 
66
        {
 
67
                mCurrentCamera = FW_NEW COLLADAFW::Camera( createUniqueIdFromId( attributeData.id, COLLADAFW::Camera::ID()) );
 
68
 
 
69
                if ( attributeData.name )
 
70
                        mCurrentCamera->setName( (const char*) attributeData.name );
 
71
                else if ( attributeData.id )
 
72
                        mCurrentCamera->setName( (const char*) attributeData.id );
 
73
 
 
74
        if ( attributeData.id )
 
75
            mCurrentCamera->setOriginalId ( (const char*)attributeData.id );
 
76
 
 
77
                getFileLoader()->addToSidTree( attributeData.id, 0);
 
78
                return true;
 
79
        }
 
80
 
 
81
        //------------------------------
 
82
        bool LibraryCamerasLoader::end__camera()
 
83
        {
 
84
                // we need to determine the description type
 
85
                // X = 1, Y = 2, aspect ratio = 4
 
86
                int descriptionType = (mCurrentCameraHasX ? 1 : 0) +
 
87
                                                          (mCurrentCameraHasY ? 2 : 0) +
 
88
                                                          (mCurrentCameraHasAspectRatio ? 4 : 0);
 
89
                switch ( descriptionType )
 
90
                {
 
91
                case 1:
 
92
                        mCurrentCamera->setDescriptionType(COLLADAFW::Camera::SINGLE_X);
 
93
                        break;
 
94
                case 2:
 
95
                        mCurrentCamera->setDescriptionType(COLLADAFW::Camera::SINGLE_Y);
 
96
                        break;
 
97
                case 3:
 
98
                        mCurrentCamera->setDescriptionType(COLLADAFW::Camera::X_AND_Y);
 
99
                        break;
 
100
                case 5:
 
101
                        mCurrentCamera->setDescriptionType(COLLADAFW::Camera::ASPECTRATIO_AND_X);
 
102
                        break;
 
103
                case 6:
 
104
                        mCurrentCamera->setDescriptionType(COLLADAFW::Camera::ASPECTRATIO_AND_Y);
 
105
                        break;
 
106
                default:
 
107
                        mCurrentCamera->setDescriptionType(COLLADAFW::Camera::UNDEFINED);
 
108
                }
 
109
 
 
110
                bool success = true;
 
111
                if ( (getObjectFlags() & Loader::CAMERA_FLAG) != 0 )
 
112
                {
 
113
                        getFileLoader()->addCamera( mCurrentCamera );
 
114
                }
 
115
                resetCurrentValues();
 
116
                getFileLoader()->moveUpInSidTree();
 
117
                return success;
 
118
        }
 
119
 
 
120
        //------------------------------
 
121
        bool LibraryCamerasLoader::begin__perspective()
 
122
        {
 
123
                mCurrentCamera->setCameraType(COLLADAFW::Camera::PERSPECTIVE);
 
124
                return true;
 
125
        }
 
126
 
 
127
        //------------------------------
 
128
        bool LibraryCamerasLoader::begin__orthographic()
 
129
        {
 
130
                mCurrentCamera->setCameraType(COLLADAFW::Camera::ORTHOGRAPHIC);
 
131
                return true;
 
132
        }
 
133
 
 
134
        //------------------------------
 
135
        bool LibraryCamerasLoader::begin__xfov( const xfov__AttributeData& attributeData )
 
136
        {
 
137
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getXFov());
 
138
                return true;
 
139
        }
 
140
 
 
141
        //------------------------------
 
142
        bool LibraryCamerasLoader::data__xfov( float value )
 
143
        {
 
144
                mCurrentCamera->setXFov( value );
 
145
                mCurrentCameraHasX = true;
 
146
                return true;
 
147
        }
 
148
 
 
149
        //------------------------------
 
150
        bool LibraryCamerasLoader::end__xfov()
 
151
        {
 
152
                moveUpInSidTree();
 
153
                return true;
 
154
        }
 
155
 
 
156
        //------------------------------
 
157
        bool LibraryCamerasLoader::begin__yfov( const yfov__AttributeData& attributeData )
 
158
        {
 
159
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getYFov());
 
160
                return true;
 
161
        }
 
162
 
 
163
        //------------------------------
 
164
        bool LibraryCamerasLoader::data__yfov( float value )
 
165
        {
 
166
                mCurrentCamera->setYFov( value );
 
167
                mCurrentCameraHasY = true;
 
168
                return true;
 
169
        }
 
170
 
 
171
        //------------------------------
 
172
        bool LibraryCamerasLoader::end__yfov()
 
173
        {
 
174
                moveUpInSidTree();
 
175
                return true;
 
176
        }
 
177
 
 
178
        //------------------------------
 
179
        bool LibraryCamerasLoader::begin__xmag( const xmag__AttributeData& attributeData )
 
180
        {
 
181
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getXMag());
 
182
                return true;
 
183
        }
 
184
 
 
185
        //------------------------------
 
186
        bool LibraryCamerasLoader::data__xmag( float value )
 
187
        {
 
188
                mCurrentCamera->setXMag( value );
 
189
                mCurrentCameraHasX = true;
 
190
                return true;
 
191
        }
 
192
 
 
193
        //------------------------------
 
194
        bool LibraryCamerasLoader::end__xmag()
 
195
        {
 
196
                moveUpInSidTree();
 
197
                return true;
 
198
        }
 
199
 
 
200
        //------------------------------
 
201
        bool LibraryCamerasLoader::begin__ymag( const ymag__AttributeData& attributeData )
 
202
        {
 
203
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getYMag());
 
204
                return true;
 
205
        }
 
206
 
 
207
        //------------------------------
 
208
        bool LibraryCamerasLoader::data__ymag( float value )
 
209
        {
 
210
                mCurrentCamera->setYMag( value );
 
211
                mCurrentCameraHasY = true;
 
212
                return true;
 
213
        }
 
214
 
 
215
        //------------------------------
 
216
        bool LibraryCamerasLoader::end__ymag()
 
217
        {
 
218
                moveUpInSidTree();
 
219
                return true;
 
220
        }
 
221
 
 
222
        //------------------------------
 
223
        bool LibraryCamerasLoader::begin__aspect_ratio( const aspect_ratio__AttributeData& attributeData )
 
224
        {
 
225
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getAspectRatio());
 
226
                return true;
 
227
        }
 
228
 
 
229
        //------------------------------
 
230
        bool LibraryCamerasLoader::data__aspect_ratio( float value )
 
231
        {
 
232
                mCurrentCamera->setAspectRatio(value);
 
233
                mCurrentCameraHasAspectRatio = true;
 
234
                return true;
 
235
        }
 
236
 
 
237
        //------------------------------
 
238
        bool LibraryCamerasLoader::end__aspect_ratio()
 
239
        {
 
240
                moveUpInSidTree();
 
241
                return true;
 
242
        }
 
243
 
 
244
        //------------------------------
 
245
        bool LibraryCamerasLoader::begin__znear( const znear__AttributeData& attributeData )
 
246
        {
 
247
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getNearClippingPlane());
 
248
                return true;
 
249
        }
 
250
 
 
251
        //------------------------------
 
252
        bool LibraryCamerasLoader::data__znear( float value )
 
253
        {
 
254
                mCurrentCamera->setNearClippingPlane(value);
 
255
                return true;
 
256
        }
 
257
 
 
258
        //------------------------------
 
259
        bool LibraryCamerasLoader::end__znear()
 
260
        {
 
261
                moveUpInSidTree();
 
262
                return true;
 
263
        }
 
264
 
 
265
        //------------------------------
 
266
        bool LibraryCamerasLoader::begin__zfar( const zfar__AttributeData& attributeData )
 
267
        {
 
268
                addToSidTree( 0, attributeData.sid, &mCurrentCamera->getFarClippingPlane());
 
269
                return true;
 
270
        }
 
271
 
 
272
        //------------------------------
 
273
        bool LibraryCamerasLoader::data__zfar( float value )
 
274
        {
 
275
                mCurrentCamera->setFarClippingPlane(value);
 
276
                return true;
 
277
        }
 
278
 
 
279
        //------------------------------
 
280
        bool LibraryCamerasLoader::end__zfar()
 
281
        {
 
282
                moveUpInSidTree();
 
283
                return true;
 
284
        }
 
285
 
 
286
} // namespace COLLADASaxFWL