TexturModel.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "TexturModel.h"
  2. #include "DXBuffer.h"
  3. #include "Textur.h"
  4. #include "Globals.h"
  5. #include "TexturList.h"
  6. using namespace Framework;
  7. // Inhalt der TexturModel Klasse
  8. // Konstruktor
  9. TexturModel::TexturModel()
  10. : Model3D()
  11. {
  12. Vertex3D *vertecies = new Vertex3D[ 4 ];
  13. for( int i = 0; i < 4; i++ )
  14. vertecies[ i ].knochenId = 0;
  15. vertecies[ 0 ].pos = Vec3<float >( -50, 50, 0.f );
  16. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  17. vertecies[ 1 ].pos = Vec3<float >( 50, 50, 0.f );
  18. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  19. vertecies[ 2 ].pos = Vec3<float >( -50, -50, 0.f );
  20. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  21. vertecies[ 3 ].pos = Vec3<float >( 50, -50, 0.f );
  22. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  23. model = new Model3DData();
  24. model->setVertecies( vertecies, 4 );
  25. Polygon3D *p = new Polygon3D();
  26. p->indexAnz = 6;
  27. p->indexList = new int[ p->indexAnz ];
  28. p->indexBuffer->setLength( p->indexAnz * 4 );
  29. p->indexBuffer->setData( p->indexList );
  30. p->indexList[ 0 ] = 0;
  31. p->indexList[ 1 ] = 3;
  32. p->indexList[ 2 ] = 2;
  33. p->indexList[ 3 ] = 0;
  34. p->indexList[ 4 ] = 1;
  35. p->indexList[ 5 ] = 3;
  36. model->addPolygon( p );
  37. textur = new Model3DTextur();
  38. }
  39. // Setzt die Textur die angezeigt werden soll
  40. // textur: Die Textur als Bild
  41. void TexturModel::setTextur( Bild *textur )
  42. {
  43. Textur *t = new Textur();
  44. t->setBildZ( textur );
  45. this->textur->setPolygonTextur( 0, t );
  46. rend = 1;
  47. }
  48. // Setzt die Textur die angezeigt werden soll
  49. // id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
  50. void TexturModel::setTextur( int id )
  51. {
  52. Textur *t = texturRegister->getTextur( id );
  53. if( !t )
  54. return;
  55. this->textur->setPolygonTextur( 0, t );
  56. rend = 1;
  57. }
  58. // Setzt die Größe, in der Die Textur angezeigt wird
  59. // gr: Ein Vektor, der für x und y die breite und höhe beinhaltet
  60. void TexturModel::setSize( Vec2< float > gr )
  61. {
  62. gr /= 2;
  63. Vertex3D *vertecies = new Vertex3D[ 4 ];
  64. for( int i = 0; i < 4; i++ )
  65. vertecies[ i ].knochenId = 0;
  66. vertecies[ 0 ].pos = Vec3<float >( -gr.x, gr.y, 0.f );
  67. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  68. vertecies[ 1 ].pos = Vec3<float >( gr.x, gr.y, 0.f );
  69. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  70. vertecies[ 2 ].pos = Vec3<float >( -gr.x, -gr.y, 0.f );
  71. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  72. vertecies[ 3 ].pos = Vec3<float >( gr.x, -gr.y, 0.f );
  73. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  74. model->setVertecies( vertecies, 4 );
  75. }
  76. // Setzt die Größe, in der die Textur angezeigt wird
  77. // b: Die Breite, in der die Textur angezeigt wird
  78. // h: Die Höhe, in der die Textur angezeigt wird
  79. void TexturModel::setSize( float b, float h )
  80. {
  81. b /= 2;
  82. h /= 2;
  83. Vertex3D *vertecies = new Vertex3D[ 4 ];
  84. for( int i = 0; i < 4; i++ )
  85. vertecies[ i ].knochenId = 0;
  86. vertecies[ 0 ].pos = Vec3<float >( -b, h, 0.f );
  87. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  88. vertecies[ 1 ].pos = Vec3<float >( b, h, 0.f );
  89. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  90. vertecies[ 2 ].pos = Vec3<float >( -b, -h, 0.f );
  91. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  92. vertecies[ 3 ].pos = Vec3<float >( b, -h, 0.f );
  93. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  94. model->setVertecies( vertecies, 4 );
  95. }
  96. // Verringert den Reference Counting Zähler. Wenn der Zähler 0 erreicht, wird das Zeichnung automatisch gelöscht.
  97. // return: 0.
  98. Model3D *TexturModel::release()
  99. {
  100. ref--;
  101. if( !ref )
  102. delete this;
  103. return 0;
  104. }