LCOV - code coverage report
Current view: top level - src - Frustum.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 55 55
Test Date: 2026-04-03 02:26:39 Functions: 100.0 % 8 8

            Line data    Source code
       1              : #include "Frustum.h"
       2              : 
       3              : //------------------------------------------------------------------------------
       4          210 : Frustum::Frustum() {}
       5              : 
       6              : //------------------------------------------------------------------------------
       7           60 : Frustum::~Frustum() {}
       8              : 
       9              : //------------------------------------------------------------------------------
      10            9 : void Frustum::extractFromProjectionMatrix(const Matrix &m) {
      11              :   // left clipping plane
      12           18 :   planes[0].setPlane(
      13            9 :     (m.data[3] + m.data[0]),
      14            9 :     (m.data[7] + m.data[4]),
      15            9 :     (m.data[11] + m.data[8]),
      16            9 :     (m.data[15] + m.data[12])
      17              :   );
      18              : 
      19              :   // right clipping plane
      20           18 :   planes[1].setPlane(
      21            9 :     (m.data[3] - m.data[0]),
      22            9 :     (m.data[7] - m.data[4]),
      23            9 :     (m.data[11] - m.data[8]),
      24            9 :     (m.data[15] - m.data[12])
      25              :   );
      26              : 
      27              :   // bottom clipping plane
      28           18 :   planes[2].setPlane(
      29            9 :     (m.data[3] + m.data[1]),
      30            9 :     (m.data[7] + m.data[5]),
      31            9 :     (m.data[11] + m.data[9]),
      32            9 :     (m.data[15] + m.data[13])
      33              :   );
      34              : 
      35              :   // top clipping plane
      36           18 :   planes[3].setPlane(
      37            9 :     (m.data[3] - m.data[1]),
      38            9 :     (m.data[7] - m.data[5]),
      39            9 :     (m.data[11] - m.data[9]),
      40            9 :     (m.data[15] - m.data[13])
      41              :   );
      42              : 
      43              :   // far clipping plane
      44           18 :   planes[4].setPlane(
      45            9 :     (m.data[3] - m.data[2]),
      46            9 :     (m.data[7] - m.data[6]),
      47            9 :     (m.data[11] - m.data[10]),
      48            9 :     (m.data[15] - m.data[14])
      49              :   );
      50              : 
      51              :   // near clipping plane
      52           18 :   planes[5].setPlane(
      53            9 :     (m.data[3] + m.data[2]),
      54            9 :     (m.data[7] + m.data[6]),
      55            9 :     (m.data[11] + m.data[10]),
      56            9 :     (m.data[15] + m.data[14])
      57              :   );
      58              : 
      59           63 :   for (int i = 0; i < NUM_PLANES; i++) {
      60           54 :     planes[i].normalize();
      61           54 :   }
      62            9 : }
      63              : 
      64              : //------------------------------------------------------------------------------
      65           14 : int Frustum::testSphere(const Sphere &sphere) {
      66              :   float distance;
      67           14 :   Vector origin;
      68              : 
      69              :   // calculate distance between sphere and each plane //
      70           29 :   for (int i = 0; i < NUM_PLANES; i++) {
      71           27 :     sphere.getOriginVector(origin);
      72              : 
      73           27 :     distance = planes[i].distanceToPoint(origin.x, origin.y, origin.z);
      74              : 
      75              :     // if this distance is < -sphere.radius, we are outside
      76           27 :     if (distance < -sphere.getRadius())
      77            2 :       return(-1);
      78              : 
      79              :     // else if the distance is between +- radius, then we intersect
      80           25 :     if ((float)fabs(distance) < sphere.getRadius())
      81           10 :       return(0);
      82           15 :   }
      83              : 
      84              :   // otherwise we are fully in view
      85            2 :   return(1);
      86           14 : }
      87              : 
      88              : //------------------------------------------------------------------------------
      89            1 : int Frustum::testBoundingBox() { return 0; }
      90              : 
      91              : //------------------------------------------------------------------------------
      92            8 : void Frustum::getPlaneDefinition(const int &num, float &a, float &b, float &c, float &d) {
      93            8 :   if (num >= 0 && num < NUM_PLANES) {
      94            6 :     planes[num].getDefinition(a, b, c, d);
      95            6 :   }
      96            8 : }
        

Generated by: LCOV version 2.4-0