Public Member Functions | |
eCameraSensor (eGameObject *o, eCoord &camera, const eCoord &target) | |
constructor | |
void | LookAround (eWall const *w, int direction, Correction &correction, REAL heightLimit, int recursion, int hardRecursion) |
virtual void | PassEdge (const eWall *w, REAL time, REAL alpha, int) |
eCameraSensor & | SetZLimit (REAL const &zLimit) |
Sets height limit of walls to consider blockers. | |
REAL const & | GetZLimit (void) const |
Gets height limit of walls to consider blockers. | |
eCameraSensor const & | GetZLimit (REAL &zLimit) const |
Gets height limit of walls to consider blockers. | |
eCameraSensor & | SetRatio (REAL const &ratio) |
Sets mixing ratio of clipped position and old position. | |
REAL const & | GetRatio (void) const |
Gets mixing ratio of clipped position and old position. | |
eCameraSensor const & | GetRatio (REAL &ratio) const |
Gets mixing ratio of clipped position and old position. | |
eCameraSensor & | SetCamera (eCamera *camera) |
Sets the camera. | |
eCamera * | GetCamera (void) const |
Gets the camera. | |
eCameraSensor const & | GetCamera (eCamera *&camera) const |
Gets the camera. | |
eCameraSensor & | SetLowerWall (bool const &lowerWall) |
Sets flag to lower blocking walls instead of moving the camera. | |
bool const & | GetLowerWall (void) const |
Gets flag to lower blocking walls instead of moving the camera. | |
eCameraSensor const & | GetLowerWall (bool &lowerWall) const |
Gets flag to lower blocking walls instead of moving the camera. | |
Public Attributes | |
bool | moved_ |
flag indicating that the camera position was moved | |
Private Attributes | |
eCoord & | camPos_ |
the position of the camera | |
eCoord | target_ |
the position of the target | |
REAL | zLimit_ |
height limit of walls to consider blockers | |
REAL | ratio_ |
mixing ratio of clipped position and old position (0: perfect clipping, ->1: smooth clipping) | |
eCamera * | camera_ |
the camera | |
bool | lowerWall_ |
flag to lower blocking walls instead of moving the camera | |
Classes | |
struct | Correction |
helper struct to get the best (smallest) position correction More... |
Definition at line 707 of file eCamera.cpp.
eCameraSensor::eCameraSensor | ( | eGameObject * | o, | |
eCoord & | camera, | |||
const eCoord & | target | |||
) | [inline] |
constructor
Definition at line 711 of file eCamera.cpp.
References eDebugLine::Draw(), eDebugLine::SetColor(), and eDebugLine::SetTimeout().
00712 :eSensor(o,o->Position(),camera-target), moved_(false), 00713 camPos_(camera), target_(target), zLimit_(2), ratio_(0), camera_(0), lowerWall_( true ) 00714 { 00715 #ifdef DEBUG_VISIBILITY_TARGETS 00716 eDebugLine::SetColor( 1,1,1 ); 00717 eDebugLine::SetTimeout(.005); 00718 eDebugLine::Draw( target, 0, target, 2 ); 00719 #endif 00720 Move( target,0,0 ); 00721 //clip_ = true; 00722 }
void eCameraSensor::LookAround | ( | eWall const * | w, | |
int | direction, | |||
Correction & | correction, | |||
REAL | heightLimit, | |||
int | recursion, | |||
int | hardRecursion | |||
) | [inline] |
looks around the given wall (push the camera so that the ray from the camera to the object passes beside the wall )
w | the wall | |
direction | whether to look "left" or "right" around the wall (relative to wall) | |
correction | the correction suggestion to store the result in | |
heightLimit | maximal height a wall may have before it counts as an obstacle | |
recursion | maximum number of corners to follow the wall around | |
hardRecursion | maximum number of walls to follow |
Definition at line 749 of file eCamera.cpp.
References eWall::BlocksCamera(), eCoord, eWall::Edge(), EPS, eWallHolder::GetWall(), eCameraSensor::Correction::Improve(), eHalfEdge::Next(), eHalfEdge::Other(), eHalfEdge::Point(), REAL, sqrt(), and st_Breakpoint().
00750 { 00751 // abort if recursion is too deep aleready 00752 if ( recursion < 0 || hardRecursion < 0 ) 00753 return; 00754 00755 static int count = 0; 00756 count ++; 00757 if ( count == 35390 ) 00758 st_Breakpoint(); 00759 00760 // tell the wall that it is blocking the sight (if requested) 00761 if ( lowerWall_ ) 00762 { 00763 w->BlocksCamera( camera_, heightLimit ); 00764 } 00765 00766 // NULL pointer checks 00767 if ( !w || !w->Edge() || !w->Edge()->Other() ) 00768 return; 00769 00770 // project camera position a bit to the other side of the wall: 00771 // get the two endpoints 00772 eHalfEdge const * edge = (direction == 0 ? w->Edge() : w->Edge()->Other()); 00773 eCoord const & p1 = *edge->Point(); 00774 eCoord const & p2 = *edge->Other()->Point(); 00775 00776 // it is ony valid if the order of points on an imaginary line is 00777 // camPos_ -> p1 -> targtet_ 00778 // (otherwise, te wall is not blocking sight at all) 00779 if ( !lowerWall_ && eCoord::F( camPos_ - p1, target_ - p1 ) > 0 ) 00780 return; 00781 00782 // determine normal of target - p1 line 00783 eCoord diff = target_ - p1; 00784 diff.Normalize(); 00785 eCoord normal = diff.Turn(0,-1); 00786 00787 // determine which side the other endpoint of the line lies on 00788 REAL sideOther=eCoord::F(normal,p2-p1); 00789 00790 // find other walls that end in p1 00791 { 00792 bool wallContinues = false; 00793 eHalfEdge const * run = edge; 00794 do 00795 { 00796 run = run->Other(); 00797 if (run) 00798 run = run->Next(); 00799 00800 if (!run || !run->Other() || run == edge) 00801 break; 00802 00803 if ( run->GetWall() || run->Other()->GetWall() ) 00804 { 00805 // got one! determine its other entpoint 00806 eCoord const & p3 = *run->Other()->Point(); 00807 00808 // determine which side of the ray the other endpoint of the wall lies on 00809 REAL side3=eCoord::F(normal,p3-p1); 00810 00811 // if it lies on the same side as p1, the edgepoint is an outline point 00812 // and needs to be projected. If not, we need to recurse. 00813 if ( side3 * sideOther < 0 ) 00814 { 00815 wallContinues = true; 00816 00817 // only on corners the recursion level should be decreased 00818 int recursion2 = recursion; 00819 if ( fabs( (p2 - p1)*(p1 - p3) ) >= 10 * EPS * sqrt( (p1-p2).NormSquared() * (p1-p3).NormSquared() ) ) 00820 recursion2--; 00821 00822 // recurse 00823 if ( run->GetWall() ) 00824 LookAround( run->GetWall(), 1, correction, heightLimit, recursion2, hardRecursion-1 ); 00825 else if ( run->Other()->GetWall() ) 00826 LookAround( run->Other()->GetWall(), 0, correction, heightLimit, recursion2, hardRecursion-1 ); 00827 } 00828 } 00829 } 00830 while ( true ); 00831 00832 // if recursion took place, don't project on this wall. 00833 if ( wallContinues ) 00834 return; 00835 } 00836 00837 // No other wall found: project camera around this wall. 00838 REAL side=eCoord::F(normal,camPos_-p1) * (1-ratio_); 00839 correction.Improve( camPos_ - normal * side, fabs( side ) ); 00840 }
virtual void eCameraSensor::PassEdge | ( | const eWall * | w, | |
REAL | time, | |||
REAL | alpha, | |||
int | ||||
) | [inline, virtual] |
called when the sensor passes another wall
w | the wall that is passed | |
time | usually the game time of the event, here time simply is the fraction of the distance from the object to the camera covered so far | |
alpha | relative coordinate of the collision point on the wall |
Reimplemented from eSensor.
Definition at line 847 of file eCamera.cpp.
References eCameraSensor::Correction::correctTo, eCameraSensor::Correction::distance, eCoord, eWall::EndPoint(), eWall::Height(), eWall::Len(), and REAL.
00848 { 00849 // determine the height limit (max. height at which walls will not be considered blockers) 00850 REAL objectZ = 1.5; 00851 if ( camera_ ) 00852 objectZ = camera_->CenterCamZ() * 2; 00853 REAL heightLimit = ( .5 * zLimit_ * time + objectZ * ( 1 - time ) ); 00854 00855 // exit early if the wall does not obstruct view 00856 if ( moved_ || !w || !owned->EdgeIsDangerous(w, time, alpha) || w->Height() <= heightLimit ) 00857 return; 00858 00859 heightLimit *= .5f; 00860 00861 // project camera position a bit to the other side of the wall: 00862 // get the two endpoints 00863 eCoord const & p1 = w->EndPoint(0); 00864 eCoord const & p2 = w->EndPoint(1); 00865 00866 // calculate wall normal 00867 eCoord diff=p2-p1; 00868 diff=diff*(1/w->Len()); 00869 eCoord normal=diff.Turn(0,-1); 00870 00871 // project 00872 REAL side=eCoord::F(normal,camPos_-p1); 00873 00874 // initialize correction suggestion; be very reluctant to project (it's confusing) 00875 Correction correction; 00876 correction.distance = fabs( side ) * 10; 00877 correction.correctTo = camPos_ - normal*(side); 00878 00879 // try to look around the edge to the right and left instead 00880 int recursion = lowerWall_? 0 : 2; 00881 LookAround( w, 0, correction, heightLimit, recursion, 1000 ); 00882 LookAround( w, 1, correction, heightLimit, recursion, 1000 ); 00883 00884 // execute the correction 00885 if ( !lowerWall_ ) 00886 { 00887 moved_ = correction.distance > .001f; 00888 camPos_ = correction.correctTo; 00889 } 00890 }
eCameraSensor & eCameraSensor::SetZLimit | ( | REAL const & | zLimit | ) | [inline] |
Sets height limit of walls to consider blockers.
zLimit | height limit of walls to consider blockers to set |
Definition at line 957 of file eCamera.cpp.
References zLimit_.
Referenced by eCamera::Bound().
00958 { 00959 this->zLimit_ = zLimit; 00960 return *this; 00961 }
REAL const & eCameraSensor::GetZLimit | ( | void | ) | const [inline] |
Gets height limit of walls to consider blockers.
Definition at line 924 of file eCamera.cpp.
References zLimit_.
00925 { 00926 return this->zLimit_; 00927 }
eCameraSensor const & eCameraSensor::GetZLimit | ( | REAL & | zLimit | ) | const [inline] |
Gets height limit of walls to consider blockers.
zLimit | height limit of walls to consider blockers to fill |
Definition at line 940 of file eCamera.cpp.
References zLimit_.
00941 { 00942 zLimit = this->zLimit_; 00943 return *this; 00944 }
eCameraSensor & eCameraSensor::SetRatio | ( | REAL const & | ratio | ) | [inline] |
Sets mixing ratio of clipped position and old position.
ratio | mixing ratio of clipped position and old position to set |
Definition at line 1006 of file eCamera.cpp.
References ratio_.
Referenced by eCamera::Bound().
01007 { 01008 this->ratio_ = ratio; 01009 return *this; 01010 }
REAL const & eCameraSensor::GetRatio | ( | void | ) | const [inline] |
Gets mixing ratio of clipped position and old position.
Definition at line 973 of file eCamera.cpp.
References ratio_.
00974 { 00975 return this->ratio_; 00976 }
eCameraSensor const & eCameraSensor::GetRatio | ( | REAL & | ratio | ) | const [inline] |
Gets mixing ratio of clipped position and old position.
ratio | mixing ratio of clipped position and old position to fill |
Definition at line 989 of file eCamera.cpp.
References ratio_.
00990 { 00991 ratio = this->ratio_; 00992 return *this; 00993 }
eCameraSensor & eCameraSensor::SetCamera | ( | eCamera * | camera | ) | [inline] |
Sets the camera.
camera | the camera to set |
Definition at line 1055 of file eCamera.cpp.
References camera_.
Referenced by eCamera::Bound().
01056 { 01057 this->camera_ = camera; 01058 return *this; 01059 }
eCamera * eCameraSensor::GetCamera | ( | void | ) | const [inline] |
Gets the camera.
Definition at line 1022 of file eCamera.cpp.
References camera_.
01023 { 01024 return this->camera_; 01025 }
eCameraSensor const & eCameraSensor::GetCamera | ( | eCamera *& | camera | ) | const [inline] |
Gets the camera.
camera | the camera to fill |
Definition at line 1038 of file eCamera.cpp.
References camera_.
01039 { 01040 camera = this->camera_; 01041 return *this; 01042 }
eCameraSensor & eCameraSensor::SetLowerWall | ( | bool const & | lowerWall | ) | [inline] |
Sets flag to lower blocking walls instead of moving the camera.
lowerWall | flag to lower blocking walls instead of moving the camera to set |
Definition at line 1104 of file eCamera.cpp.
References lowerWall_.
Referenced by eCamera::Bound().
01105 { 01106 this->lowerWall_ = lowerWall; 01107 return *this; 01108 }
bool const & eCameraSensor::GetLowerWall | ( | void | ) | const [inline] |
Gets flag to lower blocking walls instead of moving the camera.
Definition at line 1071 of file eCamera.cpp.
References lowerWall_.
Referenced by eCamera::Bound().
01072 { 01073 return this->lowerWall_; 01074 }
eCameraSensor const & eCameraSensor::GetLowerWall | ( | bool & | lowerWall | ) | const [inline] |
Gets flag to lower blocking walls instead of moving the camera.
lowerWall | flag to lower blocking walls instead of moving the camera to fill |
Definition at line 1087 of file eCamera.cpp.
References lowerWall_.
01088 { 01089 lowerWall = this->lowerWall_; 01090 return *this; 01091 }
flag indicating that the camera position was moved
Definition at line 891 of file eCamera.cpp.
Referenced by eCamera::Bound().
eCoord& eCameraSensor::camPos_ [private] |
eCoord eCameraSensor::target_ [private] |
REAL eCameraSensor::zLimit_ [private] |
height limit of walls to consider blockers
Definition at line 908 of file eCamera.cpp.
Referenced by GetZLimit(), and SetZLimit().
REAL eCameraSensor::ratio_ [private] |
mixing ratio of clipped position and old position (0: perfect clipping, ->1: smooth clipping)
Definition at line 909 of file eCamera.cpp.
Referenced by GetRatio(), and SetRatio().
eCamera* eCameraSensor::camera_ [private] |
bool eCameraSensor::lowerWall_ [private] |
flag to lower blocking walls instead of moving the camera
Definition at line 911 of file eCamera.cpp.
Referenced by GetLowerWall(), and SetLowerWall().