Ignore:
Timestamp:
01/15/06 04:23:51 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp

    r535 r540  
    11#include "VssRay.h" 
    22#include "Beam.h" 
    3  
     3#include "Mesh.h" 
     4#include "Polygon3.h" 
    45 
    56 
    67void 
    7 Beam::Construct(const  AxisAlignedBox3 &box, const AxisAlignedBox3 &dBox) 
     8Beam::Construct(const AxisAlignedBox3 &box, const AxisAlignedBox3 &dBox) 
    89{ 
    910  // the frustum is defined by set of negative halfspace described by mPlanes 
     
    7374 
    7475 
    75 void Beam::ComputeFrustum(float &left, float &right, 
    76                                                   float &bottom, float &top, 
    77                                                   float &near, float &far, 
    78                                                   const AxisAlignedBox3 &sceneBBox) const 
     76void Beam::ComputePerspectiveFrustum(float &left, float &right, 
     77                                                                        float &bottom, float &top, 
     78                                                                        float &near, float &far, 
     79                                                                        const AxisAlignedBox3 &sceneBBox) const 
    7980{ 
    8081        const float xDirRange = mDirBox.Max().x - mDirBox.Min().x; 
    8182        const float yDirRange = mDirBox.Max().y - mDirBox.Min().y; 
     83        //Debug << "xdir range: " << xDirRange << endl; 
     84        //Debug << "ydir range: " << yDirRange << endl; 
    8285 
    8386        near = 0.1f; // NOTE: what is the best value for near and far plane? 
    8487        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 
     97void 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; 
    91117} 
    92118 
     
    94120Vector3 Beam::GetMainDirection() const 
    95121{ 
    96         const Vector3 dCenter = mDirBox.Center(); 
    97         return VssRay::GetDirection(dCenter.x, dCenter.y); 
     122        return - mPlanes[0].mNormal; 
    98123} 
    99124 
     
    123148} 
    124149 
     150 
     151void 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.