00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }