ViewPoints.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <engine/ViewPoints.h>
00022 #include <engine/ScorchedContext.h>
00023 #include <common/Defines.h>
00024 #include <common/OptionsScorched.h>
00025 #include <tank/TankContainer.h>
00026 
00027 ViewPoints::ViewPoints() : context_(0), totalTime_(0), finished_(false)
00028 {
00029 }
00030 
00031 ViewPoints::~ViewPoints()
00032 {
00033 }
00034 
00035 void ViewPoints::getValues(FixedVector &lookAt, 
00036                                                    FixedVector &lookFrom)
00037 {
00038         lookAt = lookAt_;
00039         lookFrom = lookFrom_;
00040 }
00041 
00042 void ViewPoints::setValues(FixedVector &lookAt, 
00043                                                    FixedVector &lookFrom)
00044 {
00045         lookAt_ = lookAt;
00046         lookFrom_ = lookFrom;
00047 }
00048 
00049 void ViewPoints::simulate(fixed frameTime)
00050 {
00051         if (getLookAtCount() == 0) return;
00052 
00053         FixedVector max, min;
00054         bool firstItor = true;
00055         fixed count = 0;
00056 
00057         static FixedVector lookAt;
00058         static FixedVector lookFrom;
00059         lookAt.zero();
00060         lookFrom.zero();
00061 
00062         std::list<ViewPoint *>::iterator itor =
00063                 points_.begin();
00064         std::list<ViewPoint *>::iterator enditor =
00065                 points_.end();
00066         for (; itor != enditor; itor++)
00067         {
00068                 FixedVector &itorPosition = (*itor)->getPosition();
00069                 FixedVector &itorLookAt = (*itor)->getLookFrom();
00070                 fixed itorRadius = (*itor)->getRadius();
00071 
00072                 if (firstItor)
00073                 {
00074                         firstItor = false;
00075                         min = itorPosition;
00076                         max = itorPosition;
00077                 }
00078 
00079                 min[0] = MIN(min[0], itorPosition[0] - itorRadius);
00080                 min[1] = MIN(min[1], itorPosition[1] - itorRadius);
00081                 min[2] = MIN(min[2], itorPosition[2] - itorRadius);
00082                 max[0] = MAX(max[0], itorPosition[0] + itorRadius);
00083                 max[1] = MAX(max[1], itorPosition[1] + itorRadius);
00084                 max[2] = MAX(max[2], itorPosition[2] + itorRadius);             
00085 
00086                 lookAt += itorPosition;
00087                 lookFrom += itorLookAt;
00088                 count += 1;
00089         }
00090 
00091         fixed dist = 25;
00092         fixed maxMin = (max - min).Magnitude();
00093         if (maxMin > 0)
00094         {
00095                 dist = maxMin + 25;
00096         }
00097         lookFrom.StoreNormalize();
00098 
00099         lookAt /= count;
00100         lookFrom *= dist;
00101 
00102         lookAt_ = lookAt;
00103         lookFrom_ = lookFrom;
00104 }
00105 
00106 int ViewPoints::getLookAtCount()
00107 {
00108         if (finished_) return 0;
00109         return (int) points_.size();
00110 }
00111 
00112 ViewPoints::ViewPoint *ViewPoints::getNewViewPoint(unsigned int playerId)
00113 {
00114         if (context_->getServerMode()) return 0;
00115         if (playerId == 0) return 0;
00116 
00117         if (context_->getTankContainer().getCurrentPlayerId() != playerId &&
00118                 context_->getOptionsGame().getTurnType() == OptionsGame::TurnSimultaneous)
00119         {
00120                 return 0;
00121         }
00122 
00123         ViewPoint *viewpoint = new ViewPoint();
00124         points_.push_back(viewpoint);
00125         return viewpoint;
00126 }
00127 
00128 void ViewPoints::explosion(unsigned int playerId)
00129 {
00130         if (context_->getServerMode()) return;
00131 
00132         if (context_->getTankContainer().getCurrentPlayerId() != playerId &&
00133                 context_->getOptionsGame().getTurnType() == OptionsGame::TurnSimultaneous)
00134         {
00135                 return;
00136         }
00137 
00138         finished_ = true;
00139 }
00140 
00141 void ViewPoints::releaseViewPoint(ViewPoint *point)
00142 {
00143         points_.remove(point);
00144 }

Generated on Mon Feb 16 15:14:50 2009 for Scorched3D by  doxygen 1.5.3