AaronCameron.net
I care not for your petty politics.
Not a Member? - Login or Create an Account
Tuesday the 22nd of May 2012 @ 02:29am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cRMd2.h

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2003  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 #ifndef _n2l4_cRMd2_H
00026 #define _n2l4_cRMd2_H
00027 
00028 #include "n2l/n2l.h"
00029 #include "renderTools/cRModelInterface.h"
00030 
00031 namespace n2l
00032 {
00033 
00034     class cVfsNodeInterface;
00035     class cGLTexture;
00036 
00045     class cRMd2 : public cRModelInterface
00046     {
00047     public:
00048         cRMd2( const cVfsNodeInterface & iFile );
00049         virtual ~cRMd2();
00050 
00051         virtual void load( const cVfsNodeInterface & iFile );
00052 
00053         virtual void selectFrame( const tUint iFrameNum );
00054         const tUint currentFrame() const { return mCurrentFrame; }
00055         const tUint numFrames() const { return mHeader.mNumFrames; }
00056 
00057         void defaultTexture( const cAutoPtr<const cGLTexture> & iTexture );
00058 
00059 
00060         virtual void render(    const cAutoPtr<const cGLTexture> & i_iTexture,
00061                                 const tRenderOptions iOptions = R_Normal ) const;
00062         
00063 
00069         virtual void renderInter(   const tUint iFrameNum,
00070                                     const tFloat iFraction,
00071                                     const cAutoPtr<const cGLTexture> & i_iTexture,
00072                                     const tRenderOptions iOptions = R_Normal ) const;
00073 
00074 
00075         virtual void centerAroundOrigin();
00076 
00077 
00082         virtual const tString dump() const;
00083 
00088         virtual const tString dumpFrames() const;
00089 
00090 
00091         virtual const tString & vfsType() const;
00092 
00093     private:
00102         typedef struct
00103         {
00109             tSint32 mMagic;
00111             tSint32 mVersion;
00113             tSint32 mSkinWidth;
00115             tSint32 mSkinHeight;
00117             tSint32 mFrameSize;
00119             tSint32 mNumSkins;
00121             tSint32 mNumVertices;
00124             tSint32 mNumTexCoords;
00126             tSint32 mNumTriangles;
00128             tSint32 mNumGlCommands;
00130             tSint32 mNumFrames;
00133             tSint32 mOffsetSkins;
00136             tSint32 mOffsetTexCoords;
00139             tSint32 mOffsetTriangles;
00142             tSint32 mOffsetFrames;
00145             tSint32 mOffsetGlCommands;
00148             tSint32 mOffsetEnd;
00149         } tHeader;
00150 
00151         typedef struct
00152         {
00163             tUint8  mVertex[3];
00173             tSint8  mLightNormalIndex;  
00174         } tRawTriangleVertex;
00175 
00176         typedef struct
00177         {
00178             tFloat  mVertex[3];
00179             tSint8  mLightNormalIndex;
00180         } tTriangleVertex;
00181 
00182 
00186         class cFrame
00187         {
00188         public:
00189             cFrame( const tSint iNumVert ) : mVertices(0) {}
00190             ~cFrame() { free(); }
00191             void readFrom(  const tUint8 * iBuffer,
00192                             const tUint iNumVert );
00193 
00196             tFloat              mScale[3];
00199             tFloat              mTranslate[3];
00201             char                mName[16];
00203             tTriangleVertex *   mVertices;
00204 
00205         private:
00206             void free();
00207         };
00208 
00212         typedef struct
00213         {
00221             tSint16 mVertexIndices[3];
00225             tSint16 mTextureIndices[3];
00226         } tTriangle;
00227 
00233         typedef struct
00234         {
00244             tSint16 mS, mT;
00245         } tRawTextureCoordinate;
00246 
00247         typedef struct
00248         {
00249             tFloat mS, mT;
00250         } tTextureCoordinate;
00251 
00262         typedef struct
00263         {
00271             tFloat  mS, mT;
00273             tSint32 mVertexIndex;
00274         } tGLCommandVertex;
00275 
00276 
00277         typedef char tSkin[64];
00278 
00279         static const tSint32    Md2MagicNumber;
00280         static const tSint32    Md2VersionNumber;
00281 
00282         cRMd2();
00283 
00284         tHeader                 mHeader;
00285         std::vector<cFrame*>    mFrames;
00286         tSkin *                 mSkins;
00287         tTriangle *             mTriangles;
00288         tTextureCoordinate *    mTextureCoords;
00289 
00290         // Some state so we can keep track of which frame we're showing
00291         tUint   mCurrentFrame;
00292         cAutoPtr<cGLTexture>    mTexture;
00293 
00294     }; // class
00295 
00296 } // namespace n2l
00297 
00298 #endif
©2012 Aaron Cameron