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 //------------------------------ LibraryCamerasLoader(IFilePartLoader * callingFilePartLoader)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 //------------------------------ ~LibraryCamerasLoader()35 LibraryCamerasLoader::~LibraryCamerasLoader() 36 { 37 } 38 39 //------------------------------ resetCurrentValues()40 void LibraryCamerasLoader::resetCurrentValues() 41 { 42 mCurrentCamera = 0; 43 mCurrentCameraHasX = false; 44 mCurrentCameraHasY = false; 45 mCurrentCameraHasAspectRatio = false; 46 } 47 48 //------------------------------ getUniqueId()49 const COLLADAFW::UniqueId& LibraryCamerasLoader::getUniqueId () 50 { 51 if ( mCurrentCamera ) 52 return mCurrentCamera->getUniqueId (); 53 return COLLADAFW::UniqueId::INVALID; 54 } 55 56 //------------------------------ end__library_cameras()57 bool LibraryCamerasLoader::end__library_cameras() 58 { 59 getFileLoader()->moveUpInSidTree(); 60 finish(); 61 return true; 62 } 63 64 //------------------------------ begin__camera(const camera__AttributeData & attributeData)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 //------------------------------ end__camera()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 //------------------------------ begin__perspective()121 bool LibraryCamerasLoader::begin__perspective() 122 { 123 mCurrentCamera->setCameraType(COLLADAFW::Camera::PERSPECTIVE); 124 return true; 125 } 126 127 //------------------------------ begin__orthographic()128 bool LibraryCamerasLoader::begin__orthographic() 129 { 130 mCurrentCamera->setCameraType(COLLADAFW::Camera::ORTHOGRAPHIC); 131 return true; 132 } 133 134 //------------------------------ begin__xfov(const xfov__AttributeData & attributeData)135 bool LibraryCamerasLoader::begin__xfov( const xfov__AttributeData& attributeData ) 136 { 137 addToSidTree( 0, attributeData.sid, &mCurrentCamera->getXFov()); 138 return true; 139 } 140 141 //------------------------------ data__xfov(float value)142 bool LibraryCamerasLoader::data__xfov( float value ) 143 { 144 mCurrentCamera->setXFov( value ); 145 mCurrentCameraHasX = true; 146 return true; 147 } 148 149 //------------------------------ end__xfov()150 bool LibraryCamerasLoader::end__xfov() 151 { 152 moveUpInSidTree(); 153 return true; 154 } 155 156 //------------------------------ begin__yfov(const yfov__AttributeData & attributeData)157 bool LibraryCamerasLoader::begin__yfov( const yfov__AttributeData& attributeData ) 158 { 159 addToSidTree( 0, attributeData.sid, &mCurrentCamera->getYFov()); 160 return true; 161 } 162 163 //------------------------------ data__yfov(float value)164 bool LibraryCamerasLoader::data__yfov( float value ) 165 { 166 mCurrentCamera->setYFov( value ); 167 mCurrentCameraHasY = true; 168 return true; 169 } 170 171 //------------------------------ end__yfov()172 bool LibraryCamerasLoader::end__yfov() 173 { 174 moveUpInSidTree(); 175 return true; 176 } 177 178 //------------------------------ begin__xmag(const xmag__AttributeData & attributeData)179 bool LibraryCamerasLoader::begin__xmag( const xmag__AttributeData& attributeData ) 180 { 181 addToSidTree( 0, attributeData.sid, &mCurrentCamera->getXMag()); 182 return true; 183 } 184 185 //------------------------------ data__xmag(float value)186 bool LibraryCamerasLoader::data__xmag( float value ) 187 { 188 mCurrentCamera->setXMag( value ); 189 mCurrentCameraHasX = true; 190 return true; 191 } 192 193 //------------------------------ end__xmag()194 bool LibraryCamerasLoader::end__xmag() 195 { 196 moveUpInSidTree(); 197 return true; 198 } 199 200 //------------------------------ begin__ymag(const ymag__AttributeData & attributeData)201 bool LibraryCamerasLoader::begin__ymag( const ymag__AttributeData& attributeData ) 202 { 203 addToSidTree( 0, attributeData.sid, &mCurrentCamera->getYMag()); 204 return true; 205 } 206 207 //------------------------------ data__ymag(float value)208 bool LibraryCamerasLoader::data__ymag( float value ) 209 { 210 mCurrentCamera->setYMag( value ); 211 mCurrentCameraHasY = true; 212 return true; 213 } 214 215 //------------------------------ end__ymag()216 bool LibraryCamerasLoader::end__ymag() 217 { 218 moveUpInSidTree(); 219 return true; 220 } 221 222 //------------------------------ begin__aspect_ratio(const aspect_ratio__AttributeData & attributeData)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 //------------------------------ data__aspect_ratio(float value)230 bool LibraryCamerasLoader::data__aspect_ratio( float value ) 231 { 232 mCurrentCamera->setAspectRatio(value); 233 mCurrentCameraHasAspectRatio = true; 234 return true; 235 } 236 237 //------------------------------ end__aspect_ratio()238 bool LibraryCamerasLoader::end__aspect_ratio() 239 { 240 moveUpInSidTree(); 241 return true; 242 } 243 244 //------------------------------ begin__znear(const znear__AttributeData & attributeData)245 bool LibraryCamerasLoader::begin__znear( const znear__AttributeData& attributeData ) 246 { 247 addToSidTree( 0, attributeData.sid, &mCurrentCamera->getNearClippingPlane()); 248 return true; 249 } 250 251 //------------------------------ data__znear(float value)252 bool LibraryCamerasLoader::data__znear( float value ) 253 { 254 mCurrentCamera->setNearClippingPlane(value); 255 return true; 256 } 257 258 //------------------------------ end__znear()259 bool LibraryCamerasLoader::end__znear() 260 { 261 moveUpInSidTree(); 262 return true; 263 } 264 265 //------------------------------ begin__zfar(const zfar__AttributeData & attributeData)266 bool LibraryCamerasLoader::begin__zfar( const zfar__AttributeData& attributeData ) 267 { 268 addToSidTree( 0, attributeData.sid, &mCurrentCamera->getFarClippingPlane()); 269 return true; 270 } 271 272 //------------------------------ data__zfar(float value)273 bool LibraryCamerasLoader::data__zfar( float value ) 274 { 275 mCurrentCamera->setFarClippingPlane(value); 276 return true; 277 } 278 279 //------------------------------ end__zfar()280 bool LibraryCamerasLoader::end__zfar() 281 { 282 moveUpInSidTree(); 283 return true; 284 } 285 286 } // namespace COLLADASaxFWL 287