triangle.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * 3D Engine
  3. * triangle.h:
  4. * Based on pikuma.com 3D software renderer in C
  5. * Copyright (c) 2021 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 04/03/2021.
  8. */
  9. #ifndef THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H
  10. #define THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H
  11. #include <stdint.h>
  12. #include <display.h>
  13. #include <vector.h>
  14. #include <texture.h>
  15. /***********************************************************************************************************************
  16. * Data types
  17. **********************************************************************************************************************/
  18. typedef struct face_t
  19. {
  20. int a, b, c;
  21. int at, bt, ct;
  22. tex2_t a_uv, b_uv, c_uv;
  23. colour_t colour;
  24. } face_t;
  25. typedef struct triangle_t
  26. {
  27. vec4_t points[3];
  28. tex2_t textureCoordinates[3];
  29. colour_t colour;
  30. double averageDepth;
  31. texture_t *texture;
  32. } triangle_t;
  33. /***********************************************************************************************************************
  34. * Prototypes
  35. **********************************************************************************************************************/
  36. void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour);
  37. void drawFilledTriangle(struct triangle_t *t);
  38. void drawTextureTriangle(struct triangle_t *t);
  39. vec3_t getTriangleNormal(vec4_t vertices[3]);
  40. int compareTrianglesZOrder(const void *p1, const void *p2);
  41. #endif /* THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H */