Back to index

extremetuxracer  0.5beta
model_ac.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  */
00018 
00019 #ifndef _PP_MODEL_AC_H
00020 #define _PP_MODEL_AC_H
00021 
00022 
00023 #include "alg/poly.h"
00024 #include "alg/color.h"
00025 
00026 #include <string>
00027 #include <stdio.h>
00028 
00029 namespace pp{
00030        
00031 class Vertex 
00032 {
00033 public:
00034     pp::Vec3d vec;
00035     pp::Vec3d normal;
00036 };
00037 
00038 class UV
00039 {
00040 public:
00041        double u,v;   
00042 };
00043        
00044 class Surface : public pp::Polygon
00045 {
00046 public:
00047        Surface();
00048        ~Surface();
00049 
00050        pp::UV *uvs;
00051     pp::Vec3d normal;
00052     int flags;
00053     int mat;
00054 };
00055 
00056 class Material
00057 {
00058  public:
00059        pp::Color diffuse; 
00060     pp::Color ambient;
00061     pp::Color specular;
00062     pp::Color emissive;
00063     double shininess;
00064     double transparency;
00065     std::string name;
00066 };
00067 
00068 
00069 
00070 class ModelObject
00071 {
00072 public:
00073        ModelObject();
00074        ~ModelObject();
00075        
00076        pp::Vec3d loc;
00077     std::string name;
00078     std::string data;
00079     std::string url;
00080     pp::Vertex *vertices;
00081     int num_vert;
00082 
00083     pp::Surface *surfaces;
00084     int num_surf;
00085     double texture_repeat_x, texture_repeat_y;
00086     double texture_offset_x, texture_offset_y;
00087 
00088     int num_kids;
00089     pp::ModelObject **kids;
00090     double matrix[9];
00091     int type;
00092     int texture;
00093 };
00094 
00095 class ModelAC
00096 {
00097        pp::ModelObject* mp_model;
00098 
00099        int m_tokc;
00100        char* ma_tokv[30];
00101        
00102        int m_line;
00103        char ma_buff[255];
00104 
00105        pp::Material ma_palette[255];
00106        int m_numPalette;
00107        int m_startMatIndex;
00108               
00109        int loadTexture(const char *fileName);
00110        void prepareRender();       
00111        void render(ModelObject *ob);
00112        void setColor(long matno);
00113        void setSimpleColor(long matno);
00114        int stringToObjectType(std::string& string);
00115        ModelObject* loadObject(FILE *f, ModelObject *parent);
00116        void objectCalculateVertexNormals(ModelObject *ob);
00117        void calculateVertexNormals(ModelObject *ob);
00118        int getTokens(char *s, int *argc, char *argv[]);
00119        pp::Material* getMaterialFromPalette(int id);
00120        bool readLine(FILE *f);
00121        Surface* readSurface(FILE *f, Surface *s, ModelObject *ob);    
00122        void CalculateTriNormal(pp::Vec3d *v1, pp::Vec3d *v2, pp::Vec3d *v3, pp::Vec3d *n);
00123               
00124 public:
00125        ModelAC(const char *fileName);
00126 
00127        pp::ModelObject* getModel(){return mp_model;}
00128        int getDisplayList();
00129 
00130 };
00131 //pp::ModelObject *ac_load_ac3d(const char *filename);
00132 //int ac_display_list_render_object(pp::ModelObject *ob);
00133 
00134 } //namepsace pp
00135 
00136 #endif // _PP_MODEL_AC_H