AaronCameron.net
Not Left, nor right. Just correct.
Not a Member? - Login or Create an Account
Sunday the 20th of May 2012 @ 02:58pm
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cColourMod.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2002  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "materials/cColourMod.h"
00026 
00027 #include "n2l/dynVars.h"
00028 #include "n2l/vfs.h"
00029 
00030 namespace n2l
00031 {
00032     /**************************************************************************/
00033     cColourMod::cColourMod()
00034     {
00035         init();
00036     }
00037 
00038     /**************************************************************************/
00039     cColourMod::cColourMod( const cVfsNodeInterface &iNode )
00040     {
00041         init();
00042         load( iNode );
00043     }
00044 
00045     /**************************************************************************/
00046     cColourMod::cColourMod( const cDynVar &iDef )
00047     {
00048         init();
00049         load( iDef );
00050     }
00051 
00052     /**************************************************************************/
00053     cColourMod::~cColourMod()
00054     {
00055     }
00056 
00057     /**************************************************************************/
00058     void cColourMod::load( const cVfsNodeInterface &iNode )
00059     {
00060         const tUint DataOffset =
00061         vfsNodeFileWithHeader( iNode, "n2l::cColourMod");
00062 
00063         cDynVar def;
00064         def.unserialize( iNode.buffer().c_str()+DataOffset );
00065         load( def );
00066     }
00067     
00068     /**************************************************************************/
00069     void cColourMod::load( const cDynVar &iDef )
00070     {
00071         modType( tModType(tSint(iDef.keyValueOr(
00072             "modType",tSint(ModType_None) ))) );
00073         mCol1 = iDef["col1"];
00074         mCol2 = iDef["col2"];
00075     }
00076 
00077     /**************************************************************************/
00078     void cColourMod::apply( cColour &oC, const cColour &iC ) const
00079     {
00080         switch (mModType) {
00081             case ModType_None:
00082                 oC = iC;
00083                 break;
00084 
00085             case ModType_Add:
00086                 oC = iC;
00087                 oC += mCol1;
00088                 break;
00089 
00090             case ModType_Mul:
00091                 oC = iC;
00092                 oC *= mCol1;
00093                 break;
00094 
00095             case ModType_AddMul:
00096                 oC = iC;
00097                 oC += mCol1;
00098                 oC *= mCol2;
00099                 break;
00100 
00101             case ModType_MulAdd:
00102                 oC = iC;
00103                 oC *= mCol1;
00104                 oC += mCol2;
00105                 break;
00106 
00107             case ModType_Replace:
00108                 oC = mCol1;
00109                 break;
00110 
00111             default:
00112                 throw cOutOfBoundsException( "cColourMod::apply",
00113                     "Requested mod type is unknown." );
00114         }
00115     }
00116 
00117     /**************************************************************************/
00118     void cColourMod::apply( cColour &ioC ) const
00119     {
00120         switch (mModType) {
00121             case ModType_None:
00122                 break;
00123 
00124             case ModType_Add:
00125                 ioC += mCol1;
00126                 return;
00127 
00128             case ModType_Mul:
00129                 ioC *= mCol1;
00130                 break;
00131 
00132             case ModType_AddMul:
00133                 ioC += mCol1;
00134                 ioC *= mCol2;
00135                 break;
00136 
00137             case ModType_MulAdd:
00138                 ioC *= mCol1;
00139                 ioC += mCol2;
00140                 break;
00141 
00142             case ModType_Replace:
00143                 ioC = mCol1;
00144                 break;
00145 
00146             default:
00147                 throw cOutOfBoundsException( "cColourMod::apply",
00148                     "Requested mod type is unknown." );
00149         }
00150     }
00151 
00152     /**************************************************************************/
00153     const cColour cColourMod::apply( const cColour &iC ) const
00154     {
00155         cColour tmp;
00156         apply( tmp, iC );
00157         return tmp;
00158     }
00159 
00160     /**************************************************************************/
00161     void cColourMod::modType( const tModType &iModType )
00162     {
00163         if (iModType<ModType_None || iModType>=ModType_NumModTypes)
00164             throw cOutOfBoundsException( "cColourMod::apply",
00165                 "Requested mod type is unknown.", asString(tSint(iModType)) );
00166         mModType = iModType;
00167     }
00168 
00169     /**************************************************************************/
00170     void cColourMod::init()
00171     {
00172         mModType = ModType_None;
00173     }
00174 
00175 } // namespace n2l
©2012 Aaron Cameron