Camera Class Reference

#include <camera.h>

Inheritance diagram for Camera:

Inheritance graph
[legend]
Collaboration diagram for Camera:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Camera ()
void SetXY (Point2i pos)
void SetXYabs (int x, int y)
void SetXYabs (const Point2i &pos)
void FollowObject (PhysicalObj *obj, bool follow, bool center_on, bool force_center_on_object=false)
void StopFollowingObj (PhysicalObj *obj)
bool IsVisible (const PhysicalObj &obj)
void Refresh ()
bool HasFixedX () const
bool HasFixedY () const
Point2i FreeDegrees () const
Point2i NonFreeDegrees () const
void CenterOn (const PhysicalObj &obj)
void CenterOnFollowedObject ()
void AutoCrop ()
void SetAutoCrop (bool crop)
bool IsAutoCrop () const
void SetCloseFollowing (bool close)

Public Attributes

bool auto_crop

Private Attributes

PhysicalObjfollowed_object
bool throw_camera
bool follow_closely

Detailed Description

Definition at line 30 of file camera.h.


Constructor & Destructor Documentation

Camera::Camera (  ) 

Definition at line 38 of file camera.cpp.

00038               {
00039   throw_camera = false;
00040   auto_crop = true;
00041   followed_object = NULL;
00042 }


Member Function Documentation

void Camera::AutoCrop (  ) 

Definition at line 108 of file camera.cpp.

00108                      {
00109   if( !followed_object || followed_object->IsGhost() )
00110     return;
00111 
00112   if( !IsVisible(*followed_object) )
00113   {
00114     MSG_DEBUG("camera.scroll", "The object is not visible.");
00115     CenterOnFollowedObject();
00116     return;
00117   }
00118 
00119   if(follow_closely)
00120   {
00121     CenterOn(*followed_object);
00122     return;
00123   }
00124   Point2i pos = followed_object->GetPosition();
00125   Point2i size = followed_object->GetSize();
00126 
00127   if( pos.y < 0 )
00128     pos.y = 0;
00129 
00130   Point2i dstMax = GetSize()/2 - CAMERA_MARGIN;
00131   Point2i cameraBR = GetSize() + position;
00132   Point2i objectBRmargin = pos + size + CAMERA_MARGIN;
00133   Point2i dst(0, 0);
00134 
00135   dst += cameraBR.inf(objectBRmargin) * (objectBRmargin - cameraBR);
00136   dst += (pos - CAMERA_MARGIN).inf(position) * (pos - CAMERA_MARGIN - position);
00137 
00138   SetXY( dst * CAMERA_SPEED / dstMax );
00139 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::CenterOn ( const PhysicalObj obj  ) 

Definition at line 94 of file camera.cpp.

00094                                            {
00095   if (obj.IsGhost())
00096     return;
00097 
00098   MSG_DEBUG( "camera.scroll", "centering on %s", obj.GetName().c_str() );
00099 
00100   Point2i pos(0, 0);
00101 
00102   pos += FreeDegrees() * obj.GetPosition() - ( GetSize() - obj.GetSize() )/2;
00103   pos += NonFreeDegrees() * ( world.GetSize() - GetSize() )/2;
00104 
00105   SetXYabs( pos );
00106 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::CenterOnFollowedObject (  ) 

Definition at line 89 of file camera.cpp.

00089                                    {
00090   CenterOn(*followed_object);
00091 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::FollowObject ( PhysicalObj obj,
bool  follow,
bool  center_on,
bool  force_center_on_object = false 
)

Definition at line 174 of file camera.cpp.

00174                                                                                                    {
00175   MSG_DEBUG( "camera.tracking", "Following object %s, center_on=%d, follow=%d", obj->GetName().c_str(), center_on, follow);
00176   if ((center_on) && ((followed_object != obj) || !IsVisible(*obj) || force_center_on_object))
00177   {
00178     bool visible = IsVisible(*obj);
00179     CenterOn(*obj);
00180     auto_crop = follow;
00181     if(!visible)
00182       wind.RandomizeParticlesPos();
00183   }
00184   followed_object = obj;
00185 }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2i Camera::FreeDegrees (  )  const

Definition at line 52 of file camera.cpp.

00052                                  {
00053   return Point2i(HasFixedX()? 0 : 1,
00054                  HasFixedY()? 0 : 1);
00055 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Camera::HasFixedX (  )  const

Definition at line 44 of file camera.cpp.

00044                             {
00045   return (int)world.GetWidth() <= GetSizeX();
00046 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Camera::HasFixedY (  )  const

Definition at line 48 of file camera.cpp.

00048                             {
00049   return (int)world.GetHeight() <= GetSizeY();
00050 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Camera::IsAutoCrop (  )  const

Definition at line 146 of file camera.cpp.

00147 {
00148   return auto_crop;
00149 }

bool Camera::IsVisible ( const PhysicalObj obj  ) 

Definition at line 192 of file camera.cpp.

00192                                             {
00193    return Intersect( obj.GetRect() );
00194 }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2i Camera::NonFreeDegrees (  )  const

Definition at line 57 of file camera.cpp.

00057                                     {
00058   return Point2i(1, 1) - FreeDegrees();
00059 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::Refresh (  ) 

Definition at line 156 of file camera.cpp.

00156                     {
00157   throw_camera = false;
00158 
00159   // mouse mouvement
00160   Mouse::GetInstance()->TestCamera();
00161   if (throw_camera) return;
00162 
00163 #ifdef TODO_KEYBOARD // ???
00164   // keyboard movement
00165   clavier.TestCamera();
00166   if (throw_camera)
00167     return;
00168 #endif
00169 
00170   if (auto_crop)
00171     AutoCrop();
00172 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::SetAutoCrop ( bool  crop  ) 

Definition at line 141 of file camera.cpp.

00142 {
00143   auto_crop = crop;
00144 }

Here is the caller graph for this function:

void Camera::SetCloseFollowing ( bool  close  ) 

Definition at line 151 of file camera.cpp.

00152 {
00153   follow_closely = close;
00154 }

Here is the caller graph for this function:

void Camera::SetXY ( Point2i  pos  ) 

Definition at line 81 of file camera.cpp.

00081                              {
00082   pos = pos * FreeDegrees();
00083   if( pos.IsNull() )
00084     return;
00085 
00086   SetXYabs(position + pos);
00087 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::SetXYabs ( const Point2i pos  ) 

Definition at line 77 of file camera.cpp.

00077                                        {
00078   SetXYabs(pos.x, pos.y);
00079 }

Here is the call graph for this function:

void Camera::SetXYabs ( int  x,
int  y 
)

Definition at line 61 of file camera.cpp.

00061                                  {
00062   AppWormux * app = AppWormux::GetInstance();
00063 
00064   if( !HasFixedX() )
00065     position.x = BorneLong(x, 0, world.GetWidth() - GetSizeX());
00066   else
00067     position.x = - (app->video.window.GetWidth() - world.GetWidth())/2;
00068 
00069   if( !HasFixedY() )
00070     position.y = BorneLong(y, 0, world.GetHeight()-GetSizeY());
00071   else
00072     position.y = - (app->video.window.GetHeight() - world.GetHeight())/2;
00073 
00074   throw_camera = true;
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Camera::StopFollowingObj ( PhysicalObj obj  ) 

Definition at line 187 of file camera.cpp.

00187                                              {
00188   if(followed_object == obj)
00189     FollowObject((PhysicalObj*)&ActiveCharacter(), true, true, true);
00190 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool Camera::auto_crop

Definition at line 32 of file camera.h.

bool Camera::follow_closely [private]

Definition at line 37 of file camera.h.

PhysicalObj* Camera::followed_object [private]

Definition at line 35 of file camera.h.

bool Camera::throw_camera [private]

Definition at line 36 of file camera.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:38:40 2007 for Wormux by  doxygen 1.4.7