TexturModel.cpp 2.9 KB

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