clipping.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * 3D Engine
  3. * clipping.c:
  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 11/03/2021.
  8. */
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <clipping.h>
  13. static plane_t frustum[TOTAL_PLANES];
  14. void initFrustumPlanes(double fov, double aspectRation, double zNear, double zFar)
  15. {
  16. frustum[LEFT_PLANE].point = vec3(0, 0, 0);
  17. frustum[LEFT_PLANE].normal = vec3( cos(fov) / 2, 0, sin(fov) / 2);
  18. frustum[RIGHT_PLANE].point = vec3(0, 0, 0);
  19. frustum[RIGHT_PLANE].normal = vec3( -cos(fov) / 2, 0, sin(fov) / 2);
  20. frustum[TOP_PLANE].point = vec3(0, 0, 0);
  21. frustum[TOP_PLANE].normal = vec3(0, -cos(fov) / 2, sin(fov) / 2);
  22. frustum[BOTTOM_PLANE].point = vec3(0, 0, 0);
  23. frustum[BOTTOM_PLANE].normal = vec3(0, cos(fov) / 2, sin(fov) / 2);
  24. frustum[NEAR_PLANE].point = vec3(0, 0, zNear);
  25. frustum[NEAR_PLANE].normal = vec3(0, 0, 1);
  26. frustum[FAR_PLANE].point = vec3(0, 0, zFar);
  27. frustum[FAR_PLANE].normal = vec3(0, 0, -1);
  28. }