source: trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp @ 510

Revision 510, 1.8 KB checked in by mattausch, 19 years ago (diff)
  • Property svn:executable set to *
Line 
1#include "Beam.h"
2#include "VssRay.h"
3
4
5
6
7void
8Beam::Construct(const  AxisAlignedBox3 &box,
9                                const  AxisAlignedBox3 &dBox)
10{
11  // the frustum is defined by set of negative halfspace described by mPlanes
12 
13  // construct
14  Vector3 center = box.Center();
15  Vector3 dCenter = dBox.Center();
16
17  // "back plane"
18  mPlanes.push_back(Plane3(-VssRay::GetDirection(dCenter.x, dCenter.y), center));
19
20  Vector3 directions[4];
21  directions[0] = VssRay::GetDirection(dBox.Min().x, dBox.Min().y);
22  directions[1] = VssRay::GetDirection(dBox.Max().x, dBox.Min().y);
23  directions[2] = VssRay::GetDirection(dBox.Max().x, dBox.Max().y);
24  directions[3] = VssRay::GetDirection(dBox.Min().x, dBox.Max().y);
25 
26  // side planes
27  mPlanes.push_back(Plane3(CrossProd(directions[0], directions[1]), center));
28  mPlanes.push_back(Plane3(CrossProd(directions[1], directions[2]), center));
29  mPlanes.push_back(Plane3(CrossProd(directions[2], directions[3]), center));
30  mPlanes.push_back(Plane3(CrossProd(directions[3], directions[0]), center));
31
32
33  // now make sure all planes contain the spatial box
34  int i, j;
35  for (i=0; i < mPlanes.size(); i++) {
36        for (j=0; j < 8; j++) {
37          float dist = mPlanes[i].Distance(box.GetVertex(j));
38          if (dist > 0)
39                mPlanes[i].mD -= dist;
40        }
41  }
42
43  mBox = box;
44  mDirBox = dBox;
45 
46  SetValid();
47}
48
49// conservative frustum box intersection
50// returns
51// 0 - box intersects the frustum
52// -1 - box intersects the frustum and is fully inside
53// 1 - box does not intersect the frustum
54
55int
56Beam::ComputeIntersection(const  AxisAlignedBox3 &box)
57{
58  int i;
59  int result = -1;
60  for (i=0; i < mPlanes.size(); i++) {
61        int side = box.Side(mPlanes[i]);
62        if (side == 1)
63          return 1;
64        if (side > result)
65          result = side;
66  }
67  return result;
68}
Note: See TracBrowser for help on using the repository browser.