Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

3dsmodel.cpp

Go to the documentation of this file.
00001 // 3dsmodel.cpp
00002 // 
00003 // Copyright (C) 2000, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #include "3dsmodel.h"
00011 
00012 using namespace std;
00013 
00014 
00015 M3DColor::M3DColor() :
00016     red(0), green(0), blue(0)
00017 {
00018 }
00019 
00020 M3DColor::M3DColor(float _red, float _green, float _blue) :
00021     red(_red), green(_green), blue(_blue)
00022 {
00023 }
00024 
00025 
00026 M3DMaterial::M3DMaterial() :
00027     ambient(0, 0, 0),
00028     diffuse(0, 0, 0),
00029     specular(0, 0, 0),
00030     shininess(1.0f)
00031 {
00032 }
00033 
00034 string M3DMaterial::getName() const
00035 {
00036     return name;
00037 }
00038 
00039 void M3DMaterial::setName(string _name)
00040 {
00041     name = _name;
00042 }
00043 
00044 M3DColor M3DMaterial::getDiffuseColor() const
00045 {
00046     return diffuse;
00047 }
00048 
00049 void M3DMaterial::setDiffuseColor(M3DColor color)
00050 {
00051     diffuse = color;
00052 }
00053 
00054 M3DColor M3DMaterial::getAmbientColor() const
00055 {
00056     return ambient;
00057 }
00058 
00059 void M3DMaterial::setAmbientColor(M3DColor color)
00060 {
00061     ambient = color;
00062 }
00063 
00064 M3DColor M3DMaterial::getSpecularColor() const
00065 {
00066     return specular;
00067 }
00068 
00069 void M3DMaterial::setSpecularColor(M3DColor color)
00070 {
00071     specular = color;
00072 }
00073 
00074 float M3DMaterial::getShininess() const
00075 {
00076     return shininess;
00077 }
00078 
00079 void M3DMaterial::setShininess(float _shininess)
00080 {
00081     shininess = _shininess;
00082 }
00083 
00084 float M3DMaterial::getOpacity() const
00085 {
00086     return opacity;
00087 }
00088 
00089 void M3DMaterial::setOpacity(float _opacity)
00090 {
00091     opacity = _opacity;
00092 }
00093 
00094 string M3DMaterial::getTextureMap() const
00095 {
00096     return texmap;
00097 }
00098 
00099 void M3DMaterial::setTextureMap(const string& _texmap)
00100 {
00101     texmap = _texmap;
00102 }
00103 
00104 
00105 M3DTriangleMesh::M3DTriangleMesh()
00106 {
00107     matrix = Mat4f::identity();
00108 }
00109 
00110 M3DTriangleMesh::~M3DTriangleMesh()
00111 {
00112 }
00113 
00114 Mat4f M3DTriangleMesh::getMatrix() const
00115 {
00116     return matrix;
00117 }
00118 
00119 void M3DTriangleMesh::setMatrix(const Mat4f& m)
00120 {
00121     matrix = m;
00122 }
00123 
00124 Point3f M3DTriangleMesh::getVertex(uint16 n) const
00125 {
00126     return points[n];
00127 }
00128 
00129 uint16 M3DTriangleMesh::getVertexCount() const
00130 {
00131     return (uint16) (points.size());
00132 }
00133 
00134 void M3DTriangleMesh::addVertex(Point3f p)
00135 {
00136     points.insert(points.end(), p);
00137 }
00138 
00139 Point2f M3DTriangleMesh::getTexCoord(uint16 n) const
00140 {
00141     return texCoords[n];
00142 }
00143 
00144 uint16 M3DTriangleMesh::getTexCoordCount() const
00145 {
00146     return (uint16) (texCoords.size());
00147 }
00148 
00149 void M3DTriangleMesh::addTexCoord(Point2f p)
00150 {
00151     texCoords.insert(texCoords.end(), p);
00152 }
00153 
00154 void M3DTriangleMesh::getFace(uint16 n, uint16& v0, uint16& v1, uint16& v2) const
00155 {
00156     int m = (int) n * 3;
00157     v0 = faces[m];
00158     v1 = faces[m + 1];
00159     v2 = faces[m + 2];
00160 }
00161 
00162 uint16 M3DTriangleMesh::getFaceCount() const
00163 {
00164     return (uint16) (faces.size() / 3);
00165 }
00166 
00167 void M3DTriangleMesh::addFace(uint16 v0, uint16 v1, uint16 v2)
00168 {
00169     faces.insert(faces.end(), v0);
00170     faces.insert(faces.end(), v1);
00171     faces.insert(faces.end(), v2);
00172 }
00173 
00174 uint32 M3DTriangleMesh::getSmoothingGroups(uint16 face) const
00175 {
00176     if (face < smoothingGroups.size())
00177         return smoothingGroups[face];
00178     else
00179         return 0;
00180 }
00181 
00182 void M3DTriangleMesh::addSmoothingGroups(uint32 smGroups)
00183 {
00184     smoothingGroups.insert(smoothingGroups.end(), smGroups);
00185 }
00186 
00187 uint16 M3DTriangleMesh::getSmoothingGroupCount() const
00188 {
00189     return (uint16) (smoothingGroups.size());
00190 }
00191 
00192 string M3DTriangleMesh::getMaterialName() const
00193 {
00194     return materialName;
00195 }
00196 
00197 void M3DTriangleMesh::setMaterialName(string _materialName)
00198 {
00199     materialName = _materialName;
00200 }
00201 
00202 
00203 
00204 M3DModel::M3DModel()
00205 {
00206 }
00207 
00208 M3DModel::~M3DModel()
00209 {
00210     for (unsigned int i = 0; i < triMeshes.size(); i++)
00211         if (triMeshes[i] != NULL)
00212             delete triMeshes[i];
00213 }
00214 
00215 M3DTriangleMesh* M3DModel::getTriMesh(uint32 n)
00216 {
00217     if (n < triMeshes.size())
00218         return triMeshes[n];
00219     else
00220         return NULL;
00221 }
00222 
00223 uint32 M3DModel::getTriMeshCount()
00224 {
00225     return triMeshes.size();
00226 }
00227 
00228 void M3DModel::addTriMesh(M3DTriangleMesh* triMesh)
00229 {
00230     triMeshes.insert(triMeshes.end(), triMesh);
00231 }
00232 
00233 void M3DModel::setName(const string _name)
00234 {
00235     name = _name;
00236 }
00237 
00238 const string M3DModel::getName() const
00239 {
00240     return name;
00241 }
00242 
00243 
00244 M3DScene::M3DScene()
00245 {
00246 }
00247 
00248 M3DScene::~M3DScene()
00249 {
00250     unsigned int i;
00251     for (i = 0; i < models.size(); i++)
00252         if (models[i] != NULL)
00253             delete models[i];
00254     for (i = 0; i < materials.size(); i++)
00255         if (materials[i] != NULL)
00256             delete materials[i];
00257 }
00258 
00259 M3DModel* M3DScene::getModel(uint32 n) const
00260 {
00261     if (n < models.size())
00262         return models[n];
00263     else
00264         return NULL;
00265 }
00266 
00267 uint32 M3DScene::getModelCount() const
00268 {
00269     return models.size();
00270 }
00271 
00272 void M3DScene::addModel(M3DModel* model)
00273 {
00274     models.insert(models.end(), model);
00275 }
00276 
00277 M3DMaterial* M3DScene::getMaterial(uint32 n) const
00278 {
00279     if (n < materials.size())
00280         return materials[n];
00281     else
00282         return NULL;
00283 }
00284 
00285 uint32 M3DScene::getMaterialCount() const
00286 {
00287     return materials.size();
00288 }
00289 
00290 void M3DScene::addMaterial(M3DMaterial* material)
00291 {
00292     materials.insert(materials.end(), material);
00293 }
00294 
00295 M3DColor M3DScene::getBackgroundColor() const
00296 {
00297     return backgroundColor;
00298 }
00299 
00300 void M3DScene::setBackgroundColor(M3DColor color)
00301 {
00302     backgroundColor = color;
00303 }

Generated on Sat Jan 14 22:30:26 2006 for Celestia by  doxygen 1.4.1