Mesh.cpp 654 B

1234567891011121314151617181920212223242526
  1. #include "client/rendering/Mesh.h"
  2. #include "rendering/Attributes.h"
  3. Mesh::Triangle::Triangle(const Vertex& a, const Vertex& b, const Vertex& c)
  4. : a(a), b(b), c(c) {
  5. normalA = (b.position - a.position).cross(c.position - a.position);
  6. normalB = normalA;
  7. normalC = normalA;
  8. }
  9. Mesh::Mesh() : vertices(0) {
  10. }
  11. bool Mesh::init() {
  12. vertexBuffer.init(Attributes().addFloat(3).addFloat(2).addFloat(3));
  13. return false;
  14. }
  15. void Mesh::build(const TypedBuffer<Triangle>& buffer) {
  16. vertices = buffer.getLength() * 3;
  17. vertexBuffer.setStaticData(buffer.getByteLength(), buffer);
  18. }
  19. void Mesh::draw() {
  20. vertexBuffer.draw(vertices);
  21. }