Changeset 540 for trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
- Timestamp:
- 01/15/06 04:23:51 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
r535 r540 1 1 #include "VssRay.h" 2 2 #include "Beam.h" 3 3 #include "Mesh.h" 4 #include "Polygon3.h" 4 5 5 6 6 7 void 7 Beam::Construct(const AxisAlignedBox3 &box, constAxisAlignedBox3 &dBox)8 Beam::Construct(const AxisAlignedBox3 &box, const AxisAlignedBox3 &dBox) 8 9 { 9 10 // the frustum is defined by set of negative halfspace described by mPlanes … … 73 74 74 75 75 void Beam::Compute Frustum(float &left, float &right,76 77 78 76 void Beam::ComputePerspectiveFrustum(float &left, float &right, 77 float &bottom, float &top, 78 float &near, float &far, 79 const AxisAlignedBox3 &sceneBBox) const 79 80 { 80 81 const float xDirRange = mDirBox.Max().x - mDirBox.Min().x; 81 82 const float yDirRange = mDirBox.Max().y - mDirBox.Min().y; 83 //Debug << "xdir range: " << xDirRange << endl; 84 //Debug << "ydir range: " << yDirRange << endl; 82 85 83 86 near = 0.1f; // NOTE: what is the best value for near and far plane? 84 87 far = 2.0f * Magnitude(sceneBBox.Diagonal()); 85 86 left = near / tan(xDirRange * 0.5f); 87 right = near / tan(xDirRange * 0.5f); 88 89 bottom = near / tan(yDirRange * 0.5f); 90 top = near / tan(yDirRange * 0.5f); 88 89 right = fabs(near * tan(xDirRange * 0.5f)); 90 left = -right; 91 92 top = fabs(near * tan(yDirRange * 0.5f)); 93 bottom = -top; 94 } 95 96 97 void Beam::ComputeOrthoFrustum(float &left, float &right, 98 float &bottom, float &top, 99 float &near, float &far, 100 const AxisAlignedBox3 &sceneBBox) const 101 { 102 const int vAxis = GetMainDirection().DrivingAxis(); 103 const int axis2 = (vAxis + 1) % 3; 104 const int axis3 = (vAxis + 2) % 3; 105 106 const float xDirRange = mBox.Max()[axis2] - mDirBox.Min()[axis2]; 107 const float yDirRange = mDirBox.Max()[axis3] - mDirBox.Min()[axis3]; 108 109 near = 0.1f; // NOTE: what is the best value for near and far plane? 110 far = 2.0f * Magnitude(sceneBBox.Diagonal()); 111 112 right = xDirRange * 0.5f; 113 left = -right; 114 115 top = yDirRange * 0.5; 116 bottom = -top; 91 117 } 92 118 … … 94 120 Vector3 Beam::GetMainDirection() const 95 121 { 96 const Vector3 dCenter = mDirBox.Center(); 97 return VssRay::GetDirection(dCenter.x, dCenter.y); 122 return - mPlanes[0].mNormal; 98 123 } 99 124 … … 123 148 } 124 149 150 151 void Beam::CreateMesh(const float zfar) 152 { 153 if (mMesh) 154 return; 155 156 mMesh = new Mesh(); 157 158 // -- compute far plane 159 160 // box should not never remove part of beam polygons 161 Vector3 bmin = mBox.Min() - Vector3(zfar * 2.0); 162 Vector3 bmax = mBox.Max() + Vector3(zfar * 2.0); 163 164 AxisAlignedBox3 bbox(bmin, bmax); 165 Plane3 fplane; 166 fplane.mNormal = -mPlanes[0].mNormal; 167 168 // NOTE: beam far plane must not not be culled by gl far plane 169 fplane.mD = mPlanes[0].mD - zfar - 1.0f; 170 mPlanes.push_back(fplane); 171 172 for (int i = 0; i < mPlanes.size(); ++ i) 173 { 174 Polygon3 *poly = bbox.CrossSection(mPlanes[i]); 175 176 if (!poly->Valid(Limits::Small)) 177 DEL_PTR(poly); 178 179 for (int j = 0; (j < mPlanes.size()) && poly; ++ j) 180 { 181 if (j != i) 182 { 183 Polygon3 *front = new Polygon3(); 184 Polygon3 *back = new Polygon3(); 185 186 poly->Split(mPlanes[j], *front, *back, Limits::Small); 187 DEL_PTR(poly); 188 DEL_PTR(front); 189 190 if (!back->Valid(Limits::Small)) 191 DEL_PTR(back); 192 poly = back; 193 } 194 } 195 196 if (poly) 197 { 198 poly->AddToMesh(*mMesh); 199 } 200 } 201 202 // remove far plane 203 mPlanes.pop_back(); 204 }
Note: See TracChangeset
for help on using the changeset viewer.