You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ugeentitycube.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "ugeentitycube.h"
  2. UGEEntityCube::UGEEntityCube(QObject *parent)
  3. : UGEEntity(parent)
  4. , _size(1.0)
  5. {
  6. }
  7. float UGEEntityCube::getSize() const
  8. {
  9. return _size;
  10. }
  11. void UGEEntityCube::draw(AbstractRenderDevice *device)
  12. {
  13. float r = _size / 2;
  14. if (_textureId.isNull()) {
  15. QColor color = Qt::red;
  16. QList<ColorVector3D> points;
  17. points << ColorVector3D(color, -r, -r, r) << ColorVector3D(color, -r, r, r)
  18. << ColorVector3D(color, r, r, r) << ColorVector3D(color, r, -r, r)
  19. << ColorVector3D(color, -r, -r, -r) << ColorVector3D(color, -r, r, -r)
  20. << ColorVector3D(color, r, r, -r) << ColorVector3D(color, r, -r, -r);
  21. drawPolygon(device, QList<ColorVector3D>() << points[3] << points[2] << points[1] << points[0]);
  22. drawPolygon(device, QList<ColorVector3D>() << points[2] << points[3] << points[7] << points[6]);
  23. drawPolygon(device, QList<ColorVector3D>() << points[6] << points[7] << points[4] << points[5]);
  24. drawPolygon(device, QList<ColorVector3D>() << points[5] << points[4] << points[0] << points[1]);
  25. drawPolygon(device, QList<ColorVector3D>() << points[1] << points[2] << points[6] << points[5]);
  26. drawPolygon(device, QList<ColorVector3D>() << points[4] << points[7] << points[3] << points[0]);
  27. }
  28. else {
  29. QColor color = Qt::white;
  30. drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), color, r, -r, r)
  31. << TextureVector3D(Vector2D(0.25, 0.25), color, r, r, r)
  32. << TextureVector3D(Vector2D(0.00, 0.25), color, -r, r, r)
  33. << TextureVector3D(Vector2D(0.00, 0.50), color, -r, -r, r), _textureId);
  34. drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), color, r, r, r)
  35. << TextureVector3D(Vector2D(0.25, 0.25), color, r, -r, r)
  36. << TextureVector3D(Vector2D(0.50, 0.25), color, r, -r, -r)
  37. << TextureVector3D(Vector2D(0.50, 0.50), color, r, r, -r), _textureId);
  38. drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.25), color, r, r, -r)
  39. << TextureVector3D(Vector2D(0.50, 0.50), color, r, -r, -r)
  40. << TextureVector3D(Vector2D(0.75, 0.50), color, -r, -r, -r)
  41. << TextureVector3D(Vector2D(0.75, 0.25), color, -r, r, -r), _textureId);
  42. drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.75, 0.25), color, -r, r, -r)
  43. << TextureVector3D(Vector2D(0.75, 0.50), color, -r, -r, -r)
  44. << TextureVector3D(Vector2D(1.00, 0.50), color, -r, -r, r)
  45. << TextureVector3D(Vector2D(1.00, 0.25), color, -r, r, r), _textureId);
  46. drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.00), color, -r, r, r)
  47. << TextureVector3D(Vector2D(0.25, 0.25), color, r, r, r)
  48. << TextureVector3D(Vector2D(0.50, 0.25), color, r, r, -r)
  49. << TextureVector3D(Vector2D(0.50, 0.00), color, -r, r, -r), _textureId);
  50. drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.75), color, -r, -r, -r)
  51. << TextureVector3D(Vector2D(0.50, 0.50), color, r, -r, -r)
  52. << TextureVector3D(Vector2D(0.25, 0.5), color, r, -r, r)
  53. << TextureVector3D(Vector2D(0.25, 0.75), color, -r, -r, r), _textureId);
  54. }
  55. }
  56. QVariant UGEEntityCube::getTextureId() const
  57. {
  58. return _textureId;
  59. }
  60. void UGEEntityCube::setSize(float size)
  61. {
  62. _size = size;
  63. }
  64. void UGEEntityCube::setTextureId(const QVariant &textureId)
  65. {
  66. _textureId = textureId;
  67. }