Cube.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "Cube.h"
  2. #include "Textur.h"
  3. #include "Globals.h"
  4. #include "Model3DList.h"
  5. #include "TexturList.h"
  6. #include "DXBuffer.h"
  7. using namespace Framework;
  8. // Inhalt der Cube Klasse
  9. // Konstruktor
  10. // size: Die Größe des Würfels
  11. Cube::Cube( float size )
  12. : Model3D()
  13. {
  14. if( m3dRegister->hatModel( Standart3DTypes::cube ) )
  15. model = m3dRegister->getModel( Standart3DTypes::cube );
  16. else
  17. {
  18. model = new Model3DData();
  19. m3dRegister->addModel( (Model3DData *)model->getThis(), Standart3DTypes::cube );
  20. float stdSize = 100;
  21. float left, right, top, bottom;
  22. // Calculate the screen coordinates of the left side of the bitmap.
  23. left = (float)( ( stdSize / 2.0 ) * -1 );
  24. // Calculate the screen coordinates of the right side of the bitmap.
  25. right = left + (float)stdSize;
  26. // Calculate the screen coordinates of the top of the bitmap.
  27. top = (float)( stdSize / 2.0 );
  28. // Calculate the screen coordinates of the bottom of the bitmap.
  29. bottom = top - (float)stdSize;
  30. float front = -stdSize / 2;
  31. float back = front + stdSize;
  32. Vertex3D *vertecies = new Vertex3D[ 24 ];
  33. for( int i = 0; i < 24; i++ )
  34. vertecies[ i ].knochenId = 0;
  35. vertecies[ 0 ].pos = Vec3<float >( left, top, front );
  36. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  37. vertecies[ 1 ].pos = Vec3<float >( right, top, front );
  38. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  39. vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
  40. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  41. vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
  42. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  43. vertecies[ 4 ].pos = Vec3<float >( left, top, back );
  44. vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  45. vertecies[ 5 ].pos = Vec3<float >( right, top, back );
  46. vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  47. vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
  48. vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  49. vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
  50. vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  51. vertecies[ 8 ].pos = Vec3<float >( left, top, front );
  52. vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
  53. vertecies[ 9 ].pos = Vec3<float >( right, top, front );
  54. vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
  55. vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
  56. vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
  57. vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
  58. vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
  59. vertecies[ 12 ].pos = Vec3<float >( left, top, back );
  60. vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  61. vertecies[ 13 ].pos = Vec3<float >( right, top, back );
  62. vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  63. vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
  64. vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  65. vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
  66. vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  67. vertecies[ 16 ].pos = Vec3<float >( left, top, front );
  68. vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
  69. vertecies[ 17 ].pos = Vec3<float >( right, top, front );
  70. vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
  71. vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
  72. vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
  73. vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
  74. vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
  75. vertecies[ 20 ].pos = Vec3<float >( left, top, back );
  76. vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  77. vertecies[ 21 ].pos = Vec3<float >( right, top, back );
  78. vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  79. vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
  80. vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  81. vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
  82. vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  83. model->setVertecies( vertecies, 24 );
  84. // front side
  85. Polygon3D *p = new Polygon3D();
  86. p->indexAnz = 6;
  87. p->indexList = new int[ p->indexAnz ];
  88. p->indexList[ 0 ] = 0;
  89. p->indexList[ 1 ] = 3;
  90. p->indexList[ 2 ] = 2;
  91. p->indexList[ 3 ] = 0;
  92. p->indexList[ 4 ] = 1;
  93. p->indexList[ 5 ] = 3;
  94. model->addPolygon( p );
  95. // back side
  96. p = new Polygon3D();
  97. p->indexAnz = 6;
  98. p->indexList = new int[ p->indexAnz ];
  99. p->indexList[ 0 ] = 4;
  100. p->indexList[ 1 ] = 6;
  101. p->indexList[ 2 ] = 7;
  102. p->indexList[ 3 ] = 4;
  103. p->indexList[ 4 ] = 7;
  104. p->indexList[ 5 ] = 5;
  105. model->addPolygon( p );
  106. // right side
  107. p = new Polygon3D();
  108. p->indexAnz = 6;
  109. p->indexList = new int[ p->indexAnz ];
  110. p->indexList[ 0 ] = 1 + 8;
  111. p->indexList[ 1 ] = 7 + 8;
  112. p->indexList[ 2 ] = 3 + 8;
  113. p->indexList[ 3 ] = 1 + 8;
  114. p->indexList[ 4 ] = 5 + 8;
  115. p->indexList[ 5 ] = 7 + 8;
  116. model->addPolygon( p );
  117. // left side
  118. p = new Polygon3D();
  119. p->indexAnz = 6;
  120. p->indexList = new int[ p->indexAnz ];
  121. p->indexList[ 0 ] = 0 + 8;
  122. p->indexList[ 1 ] = 2 + 8;
  123. p->indexList[ 2 ] = 6 + 8;
  124. p->indexList[ 3 ] = 0 + 8;
  125. p->indexList[ 4 ] = 6 + 8;
  126. p->indexList[ 5 ] = 4 + 8;
  127. model->addPolygon( p );
  128. // top side
  129. p = new Polygon3D();
  130. p->indexAnz = 6;
  131. p->indexList = new int[ p->indexAnz ];
  132. p->indexList[ 0 ] = 4 + 16;
  133. p->indexList[ 1 ] = 1 + 16;
  134. p->indexList[ 2 ] = 0 + 16;
  135. p->indexList[ 3 ] = 4 + 16;
  136. p->indexList[ 4 ] = 5 + 16;
  137. p->indexList[ 5 ] = 1 + 16;
  138. model->addPolygon( p );
  139. // down side
  140. p = new Polygon3D();
  141. p->indexAnz = 6;
  142. p->indexList = new int[ p->indexAnz ];
  143. p->indexList[ 0 ] = 6 + 16;
  144. p->indexList[ 1 ] = 2 + 16;
  145. p->indexList[ 2 ] = 3 + 16;
  146. p->indexList[ 3 ] = 6 + 16;
  147. p->indexList[ 4 ] = 3 + 16;
  148. p->indexList[ 5 ] = 7 + 16;
  149. model->addPolygon( p );
  150. }
  151. textur = new Model3DTextur();
  152. }
  153. // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
  154. // textur: Die Textur
  155. void Cube::setTextur( Textur *textur )
  156. {
  157. this->textur->setPolygonTextur( LINKS, (Textur *)textur->getThis() );
  158. this->textur->setPolygonTextur( OBEN, (Textur *)textur->getThis() );
  159. this->textur->setPolygonTextur( RECHTS, (Textur *)textur->getThis() );
  160. this->textur->setPolygonTextur( UNTEN, (Textur *)textur->getThis() );
  161. this->textur->setPolygonTextur( VORNE, (Textur *)textur->getThis() );
  162. this->textur->setPolygonTextur( HINTEN, textur );
  163. rend = 1;
  164. }
  165. // Setzt die Textur von einer bestimmten Seite des Würfels
  166. // textur: Die Textur
  167. // s: Die Seite, die gesetzt werden soll
  168. void Cube::setTextur( Textur *textur, CubeSeite s )
  169. {
  170. this->textur->setPolygonTextur( s, textur );
  171. rend = 1;
  172. }