TexturModel.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // t: Die Textur
  41. void TexturModel::setTextur( Textur *t )
  42. {
  43. if( !t )
  44. return;
  45. this->textur->setPolygonTextur( 0, t );
  46. rend = 1;
  47. }
  48. // Setzt die Größe, in der Die Textur angezeigt wird
  49. // gr: Ein Vektor, der für x und y die breite und höhe beinhaltet
  50. void TexturModel::setSize( Vec2< float > gr )
  51. {
  52. gr /= 2;
  53. Vertex3D *vertecies = new Vertex3D[ 4 ];
  54. for( int i = 0; i < 4; i++ )
  55. vertecies[ i ].knochenId = 0;
  56. vertecies[ 0 ].pos = Vec3<float >( -gr.x, gr.y, 0.f );
  57. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  58. vertecies[ 1 ].pos = Vec3<float >( gr.x, gr.y, 0.f );
  59. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  60. vertecies[ 2 ].pos = Vec3<float >( -gr.x, -gr.y, 0.f );
  61. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  62. vertecies[ 3 ].pos = Vec3<float >( gr.x, -gr.y, 0.f );
  63. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  64. model->setVertecies( vertecies, 4 );
  65. }
  66. // Setzt die Größe, in der die Textur angezeigt wird
  67. // b: Die Breite, in der die Textur angezeigt wird
  68. // h: Die Höhe, in der die Textur angezeigt wird
  69. void TexturModel::setSize( float b, float h )
  70. {
  71. b /= 2;
  72. h /= 2;
  73. Vertex3D *vertecies = new Vertex3D[ 4 ];
  74. for( int i = 0; i < 4; i++ )
  75. vertecies[ i ].knochenId = 0;
  76. vertecies[ 0 ].pos = Vec3<float >( -b, h, 0.f );
  77. vertecies[ 0 ].tPos = Vec2< float >( 0.f, 0.f );
  78. vertecies[ 1 ].pos = Vec3<float >( b, h, 0.f );
  79. vertecies[ 1 ].tPos = Vec2< float >( 1.f, 0.f );
  80. vertecies[ 2 ].pos = Vec3<float >( -b, -h, 0.f );
  81. vertecies[ 2 ].tPos = Vec2< float >( 0.f, 1.f );
  82. vertecies[ 3 ].pos = Vec3<float >( b, -h, 0.f );
  83. vertecies[ 3 ].tPos = Vec2< float >( 1.f, 1.f );
  84. model->setVertecies( vertecies, 4 );
  85. }