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

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