BasicBlocks.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "BasicBlocks.h"
  2. #include <Model3D.h>
  3. #include <Globals.h>
  4. #include <GraphicsApi.h>
  5. #include <Bild.h>
  6. #include <Model3DList.h>
  7. #include "Globals.h"
  8. BasicBlock::BasicBlock( ItemType *zTool, Framework::Vec3<int> pos, Framework::Textur *t )
  9. : Block( zTool, pos )
  10. {
  11. Model3DData *data = 0;
  12. if( Framework::zM3DRegister()->hatModel( "cube" ) )
  13. data = Framework::zM3DRegister()->getModel( "cube" );
  14. else
  15. {
  16. data = new Model3DData();
  17. Framework::zM3DRegister()->addModel( dynamic_cast<Model3DData *>( data->getThis() ), "cube" );
  18. float size = 1;
  19. float left, right, top, bottom;
  20. // Calculate the screen coordinates of the left side of the bitmap.
  21. left = (float)( ( size / 2.0 ) * -1 );
  22. // Calculate the screen coordinates of the right side of the bitmap.
  23. right = left + (float)size;
  24. // Calculate the screen coordinates of the top of the bitmap.
  25. top = (float)( size / 2.0 );
  26. // Calculate the screen coordinates of the bottom of the bitmap.
  27. bottom = top - (float)size;
  28. float front = -size / 2;
  29. float back = front + size;
  30. Vertex3D *vertecies = new Vertex3D[ 24 ];
  31. for( int i = 0; i < 24; i++ )
  32. vertecies[ i ].knochenId = 0;
  33. vertecies[ 0 ].pos = Vec3<float >( left, top, front );
  34. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  35. vertecies[ 1 ].pos = Vec3<float >( right, top, front );
  36. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  37. vertecies[ 2 ].pos = Vec3<float >( left, bottom, front );
  38. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  39. vertecies[ 3 ].pos = Vec3<float >( right, bottom, front );
  40. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  41. vertecies[ 4 ].pos = Vec3<float >( left, top, back );
  42. vertecies[ 4 ].tPos = Vec2< float >( 0.0f, 0.0f );
  43. vertecies[ 5 ].pos = Vec3<float >( right, top, back );
  44. vertecies[ 5 ].tPos = Vec2< float >( 1.0f, 0.0f );
  45. vertecies[ 6 ].pos = Vec3<float >( left, bottom, back );
  46. vertecies[ 6 ].tPos = Vec2< float >( 0.0f, 1.0f );
  47. vertecies[ 7 ].pos = Vec3<float >( right, bottom, back );
  48. vertecies[ 7 ].tPos = Vec2< float >( 1.0f, 1.0f );
  49. vertecies[ 8 ].pos = Vec3<float >( left, top, front );
  50. vertecies[ 8 ].tPos = Vec2< float >( 1.f, 0.f );
  51. vertecies[ 9 ].pos = Vec3<float >( right, top, front );
  52. vertecies[ 9 ].tPos = Vec2< float >( 0.f, 0.f );
  53. vertecies[ 10 ].pos = Vec3<float >( left, bottom, front );
  54. vertecies[ 10 ].tPos = Vec2< float >( 1.f, 1.f );
  55. vertecies[ 11 ].pos = Vec3<float >( right, bottom, front );
  56. vertecies[ 11 ].tPos = Vec2< float >( 0.f, 1.f );
  57. vertecies[ 12 ].pos = Vec3<float >( left, top, back );
  58. vertecies[ 12 ].tPos = Vec2< float >( 0.0f, 0.0f );
  59. vertecies[ 13 ].pos = Vec3<float >( right, top, back );
  60. vertecies[ 13 ].tPos = Vec2< float >( 1.0f, 0.0f );
  61. vertecies[ 14 ].pos = Vec3<float >( left, bottom, back );
  62. vertecies[ 14 ].tPos = Vec2< float >( 0.0f, 1.0f );
  63. vertecies[ 15 ].pos = Vec3<float >( right, bottom, back );
  64. vertecies[ 15 ].tPos = Vec2< float >( 1.0f, 1.0f );
  65. vertecies[ 16 ].pos = Vec3<float >( left, top, front );
  66. vertecies[ 16 ].tPos = Vec2< float >( 0.f, 1.f );
  67. vertecies[ 17 ].pos = Vec3<float >( right, top, front );
  68. vertecies[ 17 ].tPos = Vec2< float >( 1.f, 1.f );
  69. vertecies[ 18 ].pos = Vec3<float >( left, bottom, front );
  70. vertecies[ 18 ].tPos = Vec2< float >( 0.f, 0.f );
  71. vertecies[ 19 ].pos = Vec3<float >( right, bottom, front );
  72. vertecies[ 19 ].tPos = Vec2< float >( 1.f, 0.f );
  73. vertecies[ 20 ].pos = Vec3<float >( left, top, back );
  74. vertecies[ 20 ].tPos = Vec2< float >( 0.0f, 0.0f );
  75. vertecies[ 21 ].pos = Vec3<float >( right, top, back );
  76. vertecies[ 21 ].tPos = Vec2< float >( 1.0f, 0.0f );
  77. vertecies[ 22 ].pos = Vec3<float >( left, bottom, back );
  78. vertecies[ 22 ].tPos = Vec2< float >( 0.0f, 1.0f );
  79. vertecies[ 23 ].pos = Vec3<float >( right, bottom, back );
  80. vertecies[ 23 ].tPos = Vec2< float >( 1.0f, 1.0f );
  81. model->setVertecies( vertecies, 24 );
  82. // front side
  83. Polygon3D *p = new Polygon3D();
  84. p->indexAnz = 6;
  85. p->indexList = new int[ p->indexAnz ];
  86. p->indexList[ 0 ] = 0;
  87. p->indexList[ 1 ] = 3;
  88. p->indexList[ 2 ] = 2;
  89. p->indexList[ 3 ] = 0;
  90. p->indexList[ 4 ] = 1;
  91. p->indexList[ 5 ] = 3;
  92. model->addPolygon( p );
  93. // back side
  94. p = new Polygon3D();
  95. p->indexAnz = 6;
  96. p->indexList = new int[ p->indexAnz ];
  97. p->indexList[ 0 ] = 4;
  98. p->indexList[ 1 ] = 6;
  99. p->indexList[ 2 ] = 7;
  100. p->indexList[ 3 ] = 4;
  101. p->indexList[ 4 ] = 7;
  102. p->indexList[ 5 ] = 5;
  103. model->addPolygon( p );
  104. // right side
  105. p = new Polygon3D();
  106. p->indexAnz = 6;
  107. p->indexList = new int[ p->indexAnz ];
  108. p->indexList[ 0 ] = 1 + 8;
  109. p->indexList[ 1 ] = 7 + 8;
  110. p->indexList[ 2 ] = 3 + 8;
  111. p->indexList[ 3 ] = 1 + 8;
  112. p->indexList[ 4 ] = 5 + 8;
  113. p->indexList[ 5 ] = 7 + 8;
  114. model->addPolygon( p );
  115. // left side
  116. p = new Polygon3D();
  117. p->indexAnz = 6;
  118. p->indexList = new int[ p->indexAnz ];
  119. p->indexList[ 0 ] = 0 + 8;
  120. p->indexList[ 1 ] = 2 + 8;
  121. p->indexList[ 2 ] = 6 + 8;
  122. p->indexList[ 3 ] = 0 + 8;
  123. p->indexList[ 4 ] = 6 + 8;
  124. p->indexList[ 5 ] = 4 + 8;
  125. model->addPolygon( p );
  126. // top side
  127. p = new Polygon3D();
  128. p->indexAnz = 6;
  129. p->indexList = new int[ p->indexAnz ];
  130. p->indexList[ 0 ] = 4 + 16;
  131. p->indexList[ 1 ] = 1 + 16;
  132. p->indexList[ 2 ] = 0 + 16;
  133. p->indexList[ 3 ] = 4 + 16;
  134. p->indexList[ 4 ] = 5 + 16;
  135. p->indexList[ 5 ] = 1 + 16;
  136. model->addPolygon( p );
  137. // down side
  138. p = new Polygon3D();
  139. p->indexAnz = 6;
  140. p->indexList = new int[ p->indexAnz ];
  141. p->indexList[ 0 ] = 6 + 16;
  142. p->indexList[ 1 ] = 2 + 16;
  143. p->indexList[ 2 ] = 3 + 16;
  144. p->indexList[ 3 ] = 6 + 16;
  145. p->indexList[ 4 ] = 3 + 16;
  146. p->indexList[ 5 ] = 7 + 16;
  147. model->addPolygon( p );
  148. }
  149. setModelDaten( data );
  150. Bild *b = new Bild();
  151. b->neuBild( 10, 10, 0xFF2B240B );
  152. Textur *tex = currentGame->zScreen()->zGraphicsApi()->createOrGetTextur( "dirt", b );
  153. Model3DTextur *textur = new Model3DTextur();
  154. textur->setPolygonTextur( 0, dynamic_cast<Textur *>( tex->getThis() ) );
  155. textur->setPolygonTextur( 1, dynamic_cast<Textur *>( tex->getThis() ) );
  156. textur->setPolygonTextur( 2, dynamic_cast<Textur *>( tex->getThis() ) );
  157. textur->setPolygonTextur( 3, dynamic_cast<Textur *>( tex->getThis() ) );
  158. textur->setPolygonTextur( 4, dynamic_cast<Textur *>( tex->getThis() ) );
  159. textur->setPolygonTextur( 5, tex );
  160. setModelTextur( textur );
  161. }
  162. DirtBlockType::DirtBlockType()
  163. : BlockType( ID )
  164. {}
  165. void DirtBlockType::loadSuperBlock( Block *zBlock, Framework::StreamReader *zReader )
  166. {
  167. BlockType::loadSuperBlock( zBlock, zReader );
  168. }
  169. Block *DirtBlockType::createBlock( Framework::Vec3<int> position )
  170. {
  171. // TODO: load texture
  172. return new BasicBlock( 0, position, 0 ); // TODO: add efective tool
  173. }
  174. DirtBlockItemType::DirtBlockItemType()
  175. : BasicBlockItemType( ID )
  176. {}
  177. Item *DirtBlockItemType::createItem() const
  178. {
  179. BasicBlockItem *item = new BasicBlockItem( (ItemType *)this, "Dirt" );
  180. return item;
  181. }