OpenMW
components/nif/controller.hpp
Go to the documentation of this file.
00001 /*
00002   OpenMW - The completely unofficial reimplementation of Morrowind
00003   Copyright (C) 2008-2010  Nicolay Korslund
00004   Email: < korslund@gmail.com >
00005   WWW: http://openmw.sourceforge.net/
00006 
00007   This file (controller.h) is part of the OpenMW package.
00008 
00009   OpenMW is distributed as free software: you can redistribute it
00010   and/or modify it under the terms of the GNU General Public License
00011   version 3, as published by the Free Software Foundation.
00012 
00013   This program is distributed in the hope that it will be useful, but
00014   WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   version 3 along with this program. If not, see
00020   http://www.gnu.org/licenses/ .
00021 
00022  */
00023 
00024 #ifndef OPENMW_COMPONENTS_NIF_CONTROLLER_HPP
00025 #define OPENMW_COMPONENTS_NIF_CONTROLLER_HPP
00026 
00027 #include "record.hpp"
00028 #include "niffile.hpp"
00029 #include "recordptr.hpp"
00030 
00031 namespace Nif
00032 {
00033 
00034 class Controller : public Record
00035 {
00036 public:
00037     ControllerPtr next;
00038     int flags;
00039     float frequency, phase;
00040     float timeStart, timeStop;
00041     ControlledPtr target;
00042 
00043     void read(NIFStream *nif)
00044     {
00045         next.read(nif);
00046 
00047         flags = nif->getUShort();
00048 
00049         frequency = nif->getFloat();
00050         phase = nif->getFloat();
00051         timeStart = nif->getFloat();
00052         timeStop = nif->getFloat();
00053 
00054         target.read(nif);
00055     }
00056 
00057     void post(NIFFile *nif)
00058     {
00059         Record::post(nif);
00060         next.post(nif);
00061         target.post(nif);
00062     }
00063 };
00064 
00065 class NiParticleSystemController : public Controller
00066 {
00067 public:
00068     struct Particle {
00069         Ogre::Vector3 velocity;
00070         float lifetime;
00071         float lifespan;
00072         float timestamp;
00073         int vertex;
00074     };
00075 
00076     float velocity;
00077     float velocityRandom;
00078 
00079     float verticalDir; // 0=up, pi/2=horizontal, pi=down
00080     float verticalAngle;
00081     float horizontalDir;
00082     float horizontalAngle;
00083 
00084     float size;
00085     float startTime;
00086     float stopTime;
00087 
00088     float emitRate;
00089     float lifetime;
00090     float lifetimeRandom;
00091 
00092     int emitFlags; // Bit 0: Emit Rate toggle bit (0 = auto adjust, 1 = use Emit Rate value)
00093     Ogre::Vector3 offsetRandom;
00094 
00095     NodePtr emitter;
00096 
00097     int numParticles;
00098     int activeCount;
00099     std::vector<Particle> particles;
00100 
00101     ExtraPtr extra;
00102 
00103     void read(NIFStream *nif)
00104     {
00105         Controller::read(nif);
00106 
00107         velocity = nif->getFloat();
00108         velocityRandom = nif->getFloat();
00109         verticalDir = nif->getFloat();
00110         verticalAngle = nif->getFloat();
00111         horizontalDir = nif->getFloat();
00112         horizontalAngle = nif->getFloat();
00113         /*normal?*/ nif->getVector3();
00114         /*color?*/ nif->getVector4();
00115         size = nif->getFloat();
00116         startTime = nif->getFloat();
00117         stopTime = nif->getFloat();
00118         nif->getChar();
00119         emitRate = nif->getFloat();
00120         lifetime = nif->getFloat();
00121         lifetimeRandom = nif->getFloat();
00122 
00123         emitFlags = nif->getUShort();
00124         offsetRandom = nif->getVector3();
00125 
00126         emitter.read(nif);
00127 
00128         /* Unknown Short, 0?
00129          * Unknown Float, 1.0?
00130          * Unknown Int, 1?
00131          * Unknown Int, 0?
00132          * Unknown Short, 0?
00133          */
00134         nif->skip(16);
00135 
00136         numParticles = nif->getUShort();
00137         activeCount = nif->getUShort();
00138 
00139         particles.resize(numParticles);
00140         for(size_t i = 0;i < particles.size();i++)
00141         {
00142             particles[i].velocity = nif->getVector3();
00143             nif->getVector3(); /* unknown */
00144             particles[i].lifetime = nif->getFloat();
00145             particles[i].lifespan = nif->getFloat();
00146             particles[i].timestamp = nif->getFloat();
00147             nif->getUShort(); /* unknown */
00148             particles[i].vertex = nif->getUShort();
00149         }
00150 
00151         nif->getUInt(); /* -1? */
00152         extra.read(nif);
00153         nif->getUInt(); /* -1? */
00154         nif->getChar();
00155     }
00156 
00157     void post(NIFFile *nif)
00158     {
00159         Controller::post(nif);
00160         emitter.post(nif);
00161         extra.post(nif);
00162     }
00163 };
00164 typedef NiParticleSystemController NiBSPArrayController;
00165 
00166 class NiMaterialColorController : public Controller
00167 {
00168 public:
00169     NiPosDataPtr data;
00170 
00171     void read(NIFStream *nif)
00172     {
00173         Controller::read(nif);
00174         data.read(nif);
00175     }
00176 
00177     void post(NIFFile *nif)
00178     {
00179         Controller::post(nif);
00180         data.post(nif);
00181     }
00182 };
00183 
00184 class NiPathController : public Controller
00185 {
00186 public:
00187     NiPosDataPtr posData;
00188     NiFloatDataPtr floatData;
00189 
00190     void read(NIFStream *nif)
00191     {
00192         Controller::read(nif);
00193 
00194         /*
00195            int = 1
00196            2xfloat
00197            short = 0 or 1
00198         */
00199         nif->skip(14);
00200         posData.read(nif);
00201         floatData.read(nif);
00202     }
00203 
00204     void post(NIFFile *nif)
00205     {
00206         Controller::post(nif);
00207 
00208         posData.post(nif);
00209         floatData.post(nif);
00210     }
00211 };
00212 
00213 class NiUVController : public Controller
00214 {
00215 public:
00216     NiUVDataPtr data;
00217 
00218     void read(NIFStream *nif)
00219     {
00220         Controller::read(nif);
00221 
00222         nif->getUShort(); // always 0
00223         data.read(nif);
00224     }
00225 
00226     void post(NIFFile *nif)
00227     {
00228         Controller::post(nif);
00229         data.post(nif);
00230     }
00231 };
00232 
00233 class NiKeyframeController : public Controller
00234 {
00235 public:
00236     NiKeyframeDataPtr data;
00237 
00238     void read(NIFStream *nif)
00239     {
00240         Controller::read(nif);
00241         data.read(nif);
00242     }
00243 
00244     void post(NIFFile *nif)
00245     {
00246         Controller::post(nif);
00247         data.post(nif);
00248     }
00249 };
00250 
00251 class NiAlphaController : public Controller
00252 {
00253 public:
00254     NiFloatDataPtr data;
00255 
00256     void read(NIFStream *nif)
00257     {
00258         Controller::read(nif);
00259         data.read(nif);
00260     }
00261 
00262     void post(NIFFile *nif)
00263     {
00264         Controller::post(nif);
00265         data.post(nif);
00266     }
00267 };
00268 
00269 class NiGeomMorpherController : public Controller
00270 {
00271 public:
00272     NiMorphDataPtr data;
00273 
00274     void read(NIFStream *nif)
00275     {
00276         Controller::read(nif);
00277         data.read(nif);
00278         nif->getChar(); // always 0
00279     }
00280 
00281     void post(NIFFile *nif)
00282     {
00283         Controller::post(nif);
00284         data.post(nif);
00285     }
00286 };
00287 
00288 class NiVisController : public Controller
00289 {
00290 public:
00291     NiVisDataPtr data;
00292 
00293     void read(NIFStream *nif)
00294     {
00295         Controller::read(nif);
00296         data.read(nif);
00297     }
00298 
00299     void post(NIFFile *nif)
00300     {
00301         Controller::post(nif);
00302         data.post(nif);
00303     }
00304 };
00305 
00306 class NiFlipController : public Controller
00307 {
00308 public:
00309     int mTexSlot; // NiTexturingProperty::TextureType
00310     float mDelta; // Time between two flips. delta = (start_time - stop_time) / num_sources
00311     NiSourceTextureList mSources;
00312 
00313     void read(NIFStream *nif)
00314     {
00315         Controller::read(nif);
00316         mTexSlot = nif->getUInt();
00317         /*unknown=*/nif->getUInt();/*0?*/
00318         mDelta = nif->getFloat();
00319         mSources.read(nif);
00320     }
00321 
00322     void post(NIFFile *nif)
00323     {
00324         Controller::post(nif);
00325         mSources.post(nif);
00326     }
00327 };
00328 
00329 } // Namespace
00330 #endif