Changeset 3657 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Mar 27, 2005, 12:22:09 AM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 9 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/Makefile.am
r3655 r3657 59 59 lib/graphics/importer/array.cc \ 60 60 lib/graphics/importer/objModel.cc \ 61 lib/graphics/importer/primitive_model.cc \ 61 62 lib/graphics/importer/model.cc \ 62 63 lib/graphics/importer/material.cc \ -
orxonox/trunk/src/Makefile.in
r3655 r3657 65 65 data_tank.$(OBJEXT) graphics_engine.$(OBJEXT) light.$(OBJEXT) \ 66 66 fontset.$(OBJEXT) array.$(OBJEXT) objModel.$(OBJEXT) \ 67 model.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \68 base_entity.$(OBJEXT) base_object.$(OBJEXT) \67 primitive_model.$(OBJEXT) model.$(OBJEXT) material.$(OBJEXT) \ 68 texture.$(OBJEXT) base_entity.$(OBJEXT) base_object.$(OBJEXT) \ 69 69 ini_parser.$(OBJEXT) list.$(OBJEXT) resource_manager.$(OBJEXT) \ 70 70 vector.$(OBJEXT) curve.$(OBJEXT) glmenu_imagescreen.$(OBJEXT) … … 93 93 @AMDEP_TRUE@ ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/p_node.Po \ 94 94 @AMDEP_TRUE@ ./$(DEPDIR)/player.Po ./$(DEPDIR)/primitive.Po \ 95 @AMDEP_TRUE@ ./$(DEPDIR)/primitive_model.Po \ 95 96 @AMDEP_TRUE@ ./$(DEPDIR)/projectile.Po \ 96 97 @AMDEP_TRUE@ ./$(DEPDIR)/resource_manager.Po \ … … 264 265 lib/graphics/importer/array.cc \ 265 266 lib/graphics/importer/objModel.cc \ 267 lib/graphics/importer/primitive_model.cc \ 266 268 lib/graphics/importer/model.cc \ 267 269 lib/graphics/importer/material.cc \ … … 434 436 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@ 435 437 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive.Po@am__quote@ 438 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive_model.Po@am__quote@ 436 439 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/projectile.Po@am__quote@ 437 440 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_manager.Po@am__quote@ … … 832 835 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 833 836 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o objModel.obj `if test -f 'lib/graphics/importer/objModel.cc'; then $(CYGPATH_W) 'lib/graphics/importer/objModel.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/importer/objModel.cc'; fi` 837 838 primitive_model.o: lib/graphics/importer/primitive_model.cc 839 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT primitive_model.o -MD -MP -MF "$(DEPDIR)/primitive_model.Tpo" -c -o primitive_model.o `test -f 'lib/graphics/importer/primitive_model.cc' || echo '$(srcdir)/'`lib/graphics/importer/primitive_model.cc; \ 840 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/primitive_model.Tpo" "$(DEPDIR)/primitive_model.Po"; else rm -f "$(DEPDIR)/primitive_model.Tpo"; exit 1; fi 841 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='lib/graphics/importer/primitive_model.cc' object='primitive_model.o' libtool=no @AMDEPBACKSLASH@ 842 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/primitive_model.Po' tmpdepfile='$(DEPDIR)/primitive_model.TPo' @AMDEPBACKSLASH@ 843 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 844 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o primitive_model.o `test -f 'lib/graphics/importer/primitive_model.cc' || echo '$(srcdir)/'`lib/graphics/importer/primitive_model.cc 845 846 primitive_model.obj: lib/graphics/importer/primitive_model.cc 847 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT primitive_model.obj -MD -MP -MF "$(DEPDIR)/primitive_model.Tpo" -c -o primitive_model.obj `if test -f 'lib/graphics/importer/primitive_model.cc'; then $(CYGPATH_W) 'lib/graphics/importer/primitive_model.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/importer/primitive_model.cc'; fi`; \ 848 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/primitive_model.Tpo" "$(DEPDIR)/primitive_model.Po"; else rm -f "$(DEPDIR)/primitive_model.Tpo"; exit 1; fi 849 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='lib/graphics/importer/primitive_model.cc' object='primitive_model.obj' libtool=no @AMDEPBACKSLASH@ 850 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/primitive_model.Po' tmpdepfile='$(DEPDIR)/primitive_model.TPo' @AMDEPBACKSLASH@ 851 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 852 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o primitive_model.obj `if test -f 'lib/graphics/importer/primitive_model.cc'; then $(CYGPATH_W) 'lib/graphics/importer/primitive_model.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/importer/primitive_model.cc'; fi` 834 853 835 854 model.o: lib/graphics/importer/model.cc -
orxonox/trunk/src/lib/graphics/importer/Makefile.am
r3656 r3657 27 27 model.cc \ 28 28 objModel.cc \ 29 primitive_model.cc \ 29 30 array.cc \ 30 31 material.cc \ … … 38 39 model.h \ 39 40 objModel.h \ 41 primitive_model.h \ 40 42 array.h \ 41 43 material.h \ -
orxonox/trunk/src/lib/graphics/importer/Makefile.in
r3656 r3657 54 54 PROGRAMS = $(bin_PROGRAMS) 55 55 am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \ 56 model.$(OBJEXT) objModel.$(OBJEXT) array.$(OBJEXT) \ 57 material.$(OBJEXT) texture.$(OBJEXT) graphics_engine.$(OBJEXT) \ 58 base_object.$(OBJEXT) vector.$(OBJEXT) 56 model.$(OBJEXT) objModel.$(OBJEXT) primitive_model.$(OBJEXT) \ 57 array.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \ 58 graphics_engine.$(OBJEXT) base_object.$(OBJEXT) \ 59 vector.$(OBJEXT) 59 60 importer_OBJECTS = $(am_importer_OBJECTS) 60 61 importer_LDADD = $(LDADD) … … 67 68 @AMDEP_TRUE@ ./$(DEPDIR)/graphics_engine.Po \ 68 69 @AMDEP_TRUE@ ./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \ 69 @AMDEP_TRUE@ ./$(DEPDIR)/objModel.Po ./$(DEPDIR)/texture.Po \ 70 @AMDEP_TRUE@ ./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po 70 @AMDEP_TRUE@ ./$(DEPDIR)/objModel.Po \ 71 @AMDEP_TRUE@ ./$(DEPDIR)/primitive_model.Po \ 72 @AMDEP_TRUE@ ./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \ 73 @AMDEP_TRUE@ ./$(DEPDIR)/windowHandler.Po 71 74 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 72 75 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 195 198 model.cc \ 196 199 objModel.cc \ 200 primitive_model.cc \ 197 201 array.cc \ 198 202 material.cc \ … … 206 210 model.h \ 207 211 objModel.h \ 212 primitive_model.h \ 208 213 array.h \ 209 214 material.h \ … … 283 288 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@ 284 289 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@ 290 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive_model.Po@am__quote@ 285 291 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@ 286 292 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@ -
orxonox/trunk/src/lib/graphics/importer/framework.cc
r3656 r3657 17 17 18 18 #include "vector.h" 19 20 #include "primitive_model.h" 21 19 22 20 23 int verbose; … … 76 79 obj = new OBJModel(argv[1]); 77 80 else 78 obj = (OBJModel*) newModel(SPHERE);81 obj = new PrimitiveModel(SPHERE); 79 82 80 83 M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0); -
orxonox/trunk/src/lib/graphics/importer/framework.h
r3656 r3657 35 35 36 36 WindowHandler wHandler; // Create an instance of the whandler basecode class 37 OBJModel* obj;37 Model* obj; 38 38 39 39 -
orxonox/trunk/src/lib/graphics/importer/model.cc
r3656 r3657 34 34 { 35 35 this->initialize(); 36 }37 38 /**39 \brief Creates a 3D-Model of Primitive-Type type40 41 if you want to just display a Cube/Sphere/Cylinder/... without any material.42 43 \todo implement Cube/Sphere/Cylinder/...44 */45 Model::Model(PRIMITIVE type)46 {47 this->initialize();48 49 switch (type)50 {51 default:52 case CUBE:53 this->cubeModel();54 break;55 case SPHERE:56 this->sphereModel();57 break;58 case CYLINDER:59 this->cylinderModel();60 break;61 62 }63 this->importToGL ();64 65 this->cleanup();66 36 } 67 37 … … 492 462 493 463 tmpElem->vertexNumber = va_arg (itemlist, int) -1; 494 if (type >= 2)464 if (type & TEXCOORD) 495 465 tmpElem->texCoordNumber = va_arg (itemlist, int) -1; 496 if (type == 1 || type ==3)466 if (type & NORMAL) 497 467 tmpElem->normalNumber = va_arg(itemlist, int) -1; 498 468 this->currentGroup->currentFace->vertexCount++; … … 863 833 864 834 } 865 866 /**867 \brief Builds a Sphere into the Model.868 \param size The radius of the Sphere.869 \param detail The detail of the Sphere.870 */871 void Model::sphereModel(float size, unsigned int detail)872 {873 int vertexCount = 0;874 if (detail <= 0)875 detail = 1;876 // detail = 2; // make it even877 float df = (float)detail;878 879 // defining the Vertices880 for (float i = 0; i < df *2.0; i+=1.0)881 {882 float vi = i/df *PI;883 for (float j = -df / 2.0 +1.0; j < df / 2.0; j+=1.0 *df/(df+1.0))884 {885 float vj = j/df *PI;886 this->addVertex(size * cos(vi) * cos(vj),887 size * sin(vj),888 size * sin(vi) * cos(vj));889 this->addVertexTexture(i / (df *2.0), (j-1.0)/(df)+.5);890 vertexCount++;891 }892 }893 this->addVertex(0, -size, 0);894 this->addVertex(0, size, 0);895 896 // defining the binding Faces.897 unsigned int v1, v2, v3, v4;898 for (int i = 0; i <= detail * 2 -1; i++)899 {900 for (int j = 0; j <= detail; j++)901 {902 903 v1 = i*detail + j;904 v4 = i*detail + (j+1);905 906 if (i == detail*2 -1)907 {908 v2 = j;909 v3 = j+1;910 }911 else912 {913 v2 = (i+1)*detail + j;914 v3 = (i+1)*detail + (j+1);915 }916 917 if (j == 0)918 {919 v1 = vertexCount+1;920 this->addFace(3, 2, v1, v1, v3, v3, v4, v4);921 }922 else if (j == detail)923 {924 v3 = vertexCount+2;925 this->addFace(3, 2, v1, v1, v2, v2, v3, v3);926 }927 else928 this->addFace(4, 2, v1, v1, v2, v2, v3, v3, v4, v4);929 }930 }931 }932 /**933 \brief Creates a Cylinder.934 */935 void Model::cylinderModel(void)936 {937 unsigned int detail = 20;938 float size = 1.0;939 940 // check if devision by zero941 if (detail <= 3)942 detail = 3;943 int count = 0;944 // defining Points of the Cylinder.945 for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail)946 {947 this->addVertex(size*cos(phi), size*sin(phi), -size);948 this->addVertex(size*cos(phi), size*sin(phi), size);949 count ++;950 }951 this->addVertex(0, 0, -size);952 this->addVertex(0, 0, size);953 954 955 if (count != detail)956 PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);957 vertices->debug();958 959 // adding Faces960 for (int i = 0; i < detail-1; i++)961 {962 int p1, p2, p3, p4;963 p1 = 2*i+1;964 p2 = 2*i+2;965 if (i <= detail);966 p3 = 2*i+4;967 p4 = 2*i+3;968 // something is wrong here969 this->addFace(4, 0, p1, p2, p3, p4);970 this->addFace(3, 0, p4, p1, 2*detail+1);971 this->addFace(3, 0, p2, p3, 2*detail+2);972 }973 addFace(4,0, 2*detail-1, 2*detail, 2, 1);974 this->addFace(3, 0, 1, 2*detail-1, 2*detail+1);975 this->addFace(3, 0, 2*detail, 2, 2*detail+2);976 977 }978 979 980 void Model::coneModel(float size, unsigned int detail)981 {982 983 984 } -
orxonox/trunk/src/lib/graphics/importer/model.h
r3656 r3657 15 15 using namespace std; 16 16 17 //! Specification of different primitives the Model knows 18 enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER}; 17 // definition of different modes for setting up Faces 18 #define VERTEX 0 //!< If Faces are created WITH Vertex-Coordinate 19 #define NORMAL 1 //!< If Faces are created WITH Normals (otherwise autocalculate) 20 #define TEXCOORD 2 //!< If Faces are created WITH TextureCoordinate 19 21 20 22 //! Class that handles 3D-Models. it can also read them in and display them. … … 23 25 public: 24 26 Model(void); 25 Model(PRIMITIVE type);26 27 Model(char* modelName); 27 28 virtual ~Model(void); … … 114 115 115 116 void cubeModel(void); 116 void sphereModel(float size = 1.0, unsigned int detail = 10);117 void cylinderModel(void);118 void coneModel(float size = 1.0, unsigned int detail = 10);119 117 }; 120 118 -
orxonox/trunk/src/lib/graphics/importer/primitive_model.cc
r3655 r3657 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 12 10 13 11 ### File Specific: 14 main-programmer: ...12 main-programmer: Benjamin Grauer 15 13 co-programmer: ... 16 14 */ 17 15 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 19 20 #include "proto_class.h" 21 22 #include "stdincl.h" // maybe 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_MODEL 17 18 #include "primitive_model.h" 19 20 #include <math.h> 21 #include "vector.h" 22 #include "debug.h" 23 23 24 24 using namespace std; … … 29 29 \todo this constructor is not jet implemented - do it 30 30 */ 31 ProtoClass::ProtoClass () 32 { 33 this->setClassName ("ProtoClass"); 31 PrimitiveModel::PrimitiveModel () 32 { 33 this->initialize(); 34 35 this->cubeModel(); 36 37 this->importToGL (); 38 39 this->cleanup(); 40 } 41 42 /** 43 \brief Creates a 3D-Model of Primitive-Type type 44 45 if you want to just display a Cube/Sphere/Cylinder/... without any material. 46 47 \todo implement Cube/Sphere/Cylinder/... 48 */ 49 PrimitiveModel::PrimitiveModel(PRIMITIVE type, float size, unsigned int detail) 50 { 51 this->initialize(); 52 53 switch (type) 54 { 55 default: 56 case CUBE: 57 this->cubeModel(); 58 break; 59 case SPHERE: 60 this->sphereModel(size, detail); 61 break; 62 case CYLINDER: 63 this->cylinderModel(); 64 break; 65 case CONE: 66 this->coneModel(size, detail); 67 break; 68 case PLANE: 69 this->planeModel(size, detail); 70 break; 71 } 72 this->importToGL (); 73 74 this->cleanup(); 34 75 } 35 76 … … 39 80 40 81 */ 41 Pr otoClass::~ProtoClass()82 PrimitiveModel::~PrimitiveModel () 42 83 { 43 84 // delete what has to be deleted here 44 85 } 45 86 46 /** 47 \brief nonsense - delete this method 48 \param realy nothing to give 49 \returns true or false - probably nothing? 50 51 this is just to show the doxygen abilities (this for example is an extension for a long comment) 52 */ 53 bool ProtoClass::doNonSense (int nothing) {} 87 88 89 90 /** 91 \brief Includes a default model 92 93 This will inject a Cube, because this is the most basic model. 94 */ 95 void PrimitiveModel::cubeModel(void) 96 { 97 this->addVertex (-0.5, -0.5, 0.5); 98 this->addVertex (0.5, -0.5, 0.5); 99 this->addVertex (-0.5, 0.5, 0.5); 100 this->addVertex (0.5, 0.5, 0.5); 101 this->addVertex (-0.5, 0.5, -0.5); 102 this->addVertex (0.5, 0.5, -0.5); 103 this->addVertex (-0.5, -0.5, -0.5); 104 this->addVertex (0.5, -0.5, -0.5); 105 106 this->addVertexTexture (0.0, 0.0); 107 this->addVertexTexture (1.0, 0.0); 108 this->addVertexTexture (0.0, 1.0); 109 this->addVertexTexture (1.0, 1.0); 110 this->addVertexTexture (0.0, 2.0); 111 this->addVertexTexture (1.0, 2.0); 112 this->addVertexTexture (0.0, 3.0); 113 this->addVertexTexture (1.0, 3.0); 114 this->addVertexTexture (0.0, 4.0); 115 this->addVertexTexture (1.0, 4.0); 116 this->addVertexTexture (2.0, 0.0); 117 this->addVertexTexture (2.0, 1.0); 118 this->addVertexTexture (-1.0, 0.0); 119 this->addVertexTexture (-1.0, 1.0); 120 121 this->addVertexNormal (0.0, 0.0, 1.0); 122 this->addVertexNormal (0.0, 0.0, 1.0); 123 this->addVertexNormal (0.0, 0.0, 1.0); 124 this->addVertexNormal (0.0, 0.0, 1.0); 125 this->addVertexNormal (0.0, 1.0, 0.0); 126 this->addVertexNormal (0.0, 1.0, 0.0); 127 this->addVertexNormal (0.0, 1.0, 0.0); 128 this->addVertexNormal (0.0, 1.0, 0.0); 129 this->addVertexNormal (0.0, 0.0, -1.0); 130 this->addVertexNormal (0.0, 0.0, -1.0); 131 this->addVertexNormal (0.0, 0.0, -1.0); 132 this->addVertexNormal (0.0, 0.0, -1.0); 133 this->addVertexNormal (0.0, -1.0, 0.0); 134 this->addVertexNormal (0.0, -1.0, 0.0); 135 this->addVertexNormal (0.0, -1.0, 0.0); 136 this->addVertexNormal (0.0, -1.0, 0.0); 137 this->addVertexNormal (1.0, 0.0, 0.0); 138 this->addVertexNormal (1.0, 0.0, 0.0); 139 this->addVertexNormal (1.0, 0.0, 0.0); 140 this->addVertexNormal (1.0, 0.0, 0.0); 141 this->addVertexNormal (-1.0, 0.0, 0.0); 142 this->addVertexNormal (-1.0, 0.0, 0.0); 143 this->addVertexNormal (-1.0, 0.0, 0.0); 144 this->addVertexNormal (-1.0, 0.0, 0.0); 145 146 /* normaleLess-testingMode 147 this->addFace ("1 2 4 3"); 148 this->addFace ("3 4 6 5"); 149 this->addFace ("5 6 8 7"); 150 this->addFace ("7 8 2 1"); 151 this->addFace ("2 8 6 4"); 152 this->addFace ("7 1 3 5"); 153 */ 154 155 this->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4); 156 this->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8); 157 this->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12); 158 this->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16); 159 this->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20); 160 this->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24); 161 162 } 163 164 /** 165 \brief Builds a Sphere into the Model. 166 \param size The radius of the Sphere. 167 \param detail The detail of the Sphere. 168 */ 169 void PrimitiveModel::sphereModel(float size, unsigned int detail) 170 { 171 int vertexCount = 0; 172 if (detail <= 0) 173 detail = 1; 174 // detail = 2; // make it even 175 float df = (float)detail; 176 177 // defining the Vertices 178 for (float i = 0; i < df *2.0; i+=1.0) 179 { 180 float vi = i/df *PI; 181 for (float j = -df / 2.0 +1.0; j < df / 2.0; j+=1.0 *df/(df+1.0)) 182 { 183 float vj = j/df *PI; 184 this->addVertex(size * cos(vi) * cos(vj), 185 size * sin(vj), 186 size * sin(vi) * cos(vj)); 187 this->addVertexTexture(i / (df *2.0), (j-1.0)/(df)+.5); 188 vertexCount++; 189 } 190 } 191 this->addVertex(0, -size, 0); 192 this->addVertex(0, size, 0); 193 194 // defining the binding Faces. 195 unsigned int v1, v2, v3, v4; 196 for (int i = 0; i <= detail * 2 -1; i++) 197 { 198 for (int j = 0; j <= detail; j++) 199 { 200 201 v1 = i*detail + j; 202 v4 = i*detail + (j+1); 203 204 if (i == detail*2 -1) 205 { 206 v2 = j; 207 v3 = j+1; 208 } 209 else 210 { 211 v2 = (i+1)*detail + j; 212 v3 = (i+1)*detail + (j+1); 213 } 214 215 if (j == 0) 216 { 217 v1 = vertexCount+1; 218 this->addFace(3, TEXCOORD, v1, v1, v3, v3, v4, v4); 219 } 220 else if (j == detail) 221 { 222 v3 = vertexCount+2; 223 this->addFace(3, TEXCOORD, v1, v1, v2, v2, v3, v3); 224 } 225 else 226 this->addFace(4, TEXCOORD, v1, v1, v2, v2, v3, v3, v4, v4); 227 } 228 } 229 } 230 /** 231 \brief Creates a Cylinder. 232 */ 233 void PrimitiveModel::cylinderModel(float size, unsigned int detail) 234 { 235 // check if devision by zero 236 if (detail <= 3) 237 detail = 3; 238 int count = 0; 239 // defining Points of the Cylinder. 240 for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail) 241 { 242 this->addVertex(size*cos(phi), size*sin(phi), -size); 243 this->addVertex(size*cos(phi), size*sin(phi), size); 244 count ++; 245 } 246 this->addVertex(0, 0, -size); 247 this->addVertex(0, 0, size); 248 249 250 if (count != detail) 251 PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count); 252 253 // adding Faces 254 for (int i = 0; i < detail-1; i++) 255 { 256 int p1, p2, p3, p4; 257 p1 = 2*i+1; 258 p2 = 2*i+2; 259 if (i <= detail); 260 p3 = 2*i+4; 261 p4 = 2*i+3; 262 // something is wrong here 263 this->addFace(4, 0, p1, p2, p3, p4); 264 this->addFace(3, 0, p4, p1, 2*detail+1); 265 this->addFace(3, 0, p2, p3, 2*detail+2); 266 } 267 addFace(4,0, 2*detail-1, 2*detail, 2, 1); 268 this->addFace(3, VERTEX, 1, 2*detail-1, 2*detail+1); 269 this->addFace(3, VERTEX, 2*detail, 2, 2*detail+2); 270 } 271 272 /** 273 \brief creates a cone inside of this Model 274 \param size The size of the cone 275 \param detail the Detail-level of this cone 276 */ 277 void PrimitiveModel::coneModel(float size, unsigned int detail) 278 { 279 this->addVertex(0,-size,0); 280 this->addVertex(0,size,0); 281 if (detail <= 0) 282 detail = 1; 283 float df = (float)detail; 284 285 // defining the Vertices 286 for (float i = 0; i < df; i+=1.0) 287 { 288 float vi = i/df *2.0*PI; 289 this->addVertex(size* sin(vi), 290 -size, 291 size* cos(vi)); 292 } 293 294 //defining Faces 295 for (int i = 0; i < detail; i++) 296 { 297 unsigned int v1, v2; 298 v1 = i+3; 299 if (i == detail -1) 300 v2 = 3; 301 else 302 v2 = i+4; 303 this->addFace(3, VERTEX, 1, v1, v2); 304 this->addFace(3, VERTEX, 2, v1, v2); 305 } 306 } 307 308 /** 309 \brief creates a Plane inside of this Model 310 \param size The size of this plane 311 \param detail the Detail-level of this plane. 312 */ 313 void PrimitiveModel::planeModel(float size, unsigned int detail) 314 { 315 //defining vertices 316 for (int i = 0; i < detail; i++) 317 for (int j = 0; j < detail; j++) 318 { 319 this->addVertex(((float)i/(float)(detail-1) -.5)*size, 320 0, 321 ((float)j/(float)(detail-1) -.5)*size); 322 this->addVertexTexture((float)i/(float)(detail-1), 323 (float)j/(float)(detail-1)); 324 } 325 //defining Faces 326 unsigned int v1, v2, v3, v4; 327 for (int i = 0; i < detail-1; i++) 328 for (int j = 1; j < detail; j++) 329 { 330 v1 = i*detail + j; 331 v2 = (i+1)*detail + j; 332 v3 = (i+1)*detail + (j+1); 333 v4 = i*detail + (j+1); 334 this->addFace(4, TEXCOORD, v1, v1, v2, v2, v3, v3, v4, v4); 335 } 336 } -
orxonox/trunk/src/lib/graphics/importer/primitive_model.h
r3655 r3657 1 1 /*! 2 \file proto_class.h 3 \brief Definition of the proto class template, used quickly start work 4 \todo Example: this shows how to use simply add a Marker that here has to be done something. 2 \file primitive_model.h 5 3 6 The Protoclass exists, to help you quikly getting the run for how to develop in orxonox.7 It is an example for the CODING-CONVENTION, and a starting-point for every class.8 4 */ 9 5 10 #ifndef _PR OTO_CLASS_H11 #define _PR OTO_CLASS_H6 #ifndef _PRIMITIVE_MODEL_H 7 #define _PRIMITIVE_MODEL_H 12 8 13 #include "what realy has to be included" 14 #include "base_object.h" 9 #include "model.h" 10 11 //! Specification of different primitives the Model knows 12 enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER, CONE}; 15 13 16 14 // FORWARD DEFINITION \\ 17 class someClassWeNeed;18 15 19 20 /*class Test;*/ /* forward definition of class Test (without including it here!)*/ 21 22 //! A default class that aids you to start creating a new class 23 /** 24 here can be some longer description of this class 25 */ 26 class ProtoClass : public BaseObject { 16 //! A Class to create some default Models 17 class PrimitiveModel : public Model { 27 18 28 19 public: 29 Pr otoClass();30 virtual ~ProtoClass();20 PrimitiveModel(); 21 PrimitiveModel(PRIMITIVE type, float size = 1.0, unsigned int detail = 10); 31 22 32 bool doNonSense (int nothing);23 virtual ~PrimitiveModel(); 33 24 34 private: 35 int nonSense; //!< doxygen tag here like this for all the variables - delete this variable if you use this 36 25 protected: 26 void cubeModel(void); 27 void sphereModel(float size = 1.0, unsigned int detail = 10); 28 void cylinderModel(float size = 1.0, unsigned int detail = 10); 29 void coneModel(float size = 1.0, unsigned int detail = 10); 30 void planeModel(float size = 1.0, unsigned int detail = 1); 37 31 }; 38 32 39 #endif /* _PR OTO_CLASS_H */33 #endif /* _PRIMITIVE_MODEL_H */ -
orxonox/trunk/src/lib/util/resource_manager.cc
r3655 r3657 20 20 // different resource Types 21 21 #include "objModel.h" 22 #include "primitive_model.h" 22 23 #include "texture.h" 23 24 … … 110 111 { 111 112 PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", tmpName); 112 tmpResource = new Model(CUBE);113 tmpResource = new PrimitiveModel(CUBE); 113 114 } 114 115 break;
Note: See TracChangeset
for help on using the changeset viewer.