00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <math.h>
00022 #include <tankgraph/MissileMesh.h>
00023 #include <graph/ModelRenderer.h>
00024 #include <graph/ModelRendererStore.h>
00025 #include <3dsparse/Model.h>
00026 #include <GLEXT/GLLenseFlare.h>
00027 #include <landscape/Landscape.h>
00028 #include <landscapemap/LandscapeMaps.h>
00029 #include <client/ScorchedClient.h>
00030 #include <common/Defines.h>
00031
00032 MissileMesh::MissileMesh(ModelID &missile) :
00033 innerScale_(1.0f),
00034 scale_(1.0f)
00035 {
00036 model_ = ModelRendererStore::instance()->loadModel(missile);
00037
00038
00039 const float maxSize = 2.0f;
00040 Vector min = model_->getModel()->getMin();
00041 Vector max = model_->getModel()->getMax();
00042 float size = (max - min).Magnitude();
00043 if (size > maxSize) innerScale_ = 2.2f / size;
00044
00045
00046 std::vector<Mesh *>::iterator itor;
00047 for (itor = model_->getModel()->getMeshes().begin();
00048 itor != model_->getModel()->getMeshes().end();
00049 itor++)
00050 {
00051 Mesh *mesh = (*itor);
00052 const char *name = mesh->getName();
00053 if (strstr(name, "\"Flare") == name ||
00054 strstr(name, "\"flare") == name)
00055 {
00056 FlareInfo info;
00057
00058
00059 info.position = (mesh->getMax() + mesh->getMin()) / 2.0f;
00060 info.size = MAX(1.0f, (mesh->getMax() - mesh->getMin()).Magnitude());
00061
00062 flares_.push_back(info);
00063 }
00064 }
00065 }
00066
00067 MissileMesh::~MissileMesh()
00068 {
00069 }
00070
00071 void MissileMesh::draw(Vector &position, Vector &direction, int flareType, float rotation, float frame)
00072 {
00073
00074
00075 Vector dir = direction.Normalize();
00076 const float radToDeg = 180.0f / 3.14f;
00077 float angXYRad = 3.14f - atan2f(dir[0], dir[1]);
00078 float angYZRad = acosf(dir[2]);
00079 float angXYDeg = angXYRad * radToDeg;
00080 float angYZDeg = angYZRad * radToDeg;
00081
00082
00083 float scale = innerScale_ * scale_;
00084 glPushMatrix();
00085 glTranslatef(position[0], position[1], position[2]);
00086
00087 glRotatef(angXYDeg, 0.0f, 0.0f, 1.0f);
00088 glRotatef(angYZDeg, 1.0f, 0.0f, 0.0f);
00089
00090 glRotatef(rotation, 0.0f, 0.0f, 1.0f);
00091 glScalef(scale, scale, scale);
00092 model_->draw(frame, 0.0f, 1.0f, true);
00093 glPopMatrix();
00094
00095
00096 std::list<FlareInfo>::iterator flareItor;
00097 for (flareItor = flares_.begin();
00098 flareItor != flares_.end();
00099 flareItor++)
00100 {
00101 FlareInfo info = (*flareItor);
00102
00103 float newX = info.position[0];
00104 float newY = info.position[1];
00105 float newZ = info.position[2];
00106
00107 float newX2 =
00108 (newX * getFastCos(rotation)) -
00109 (newY * getFastSin(rotation));
00110 float newY2 =
00111 (newX * getFastSin(rotation)) +
00112 (newY * getFastCos(rotation));
00113 float newZ2 =
00114 newZ;
00115
00116 float newX3 =
00117 newX2;
00118 float newY3 =
00119 (newY2 * getFastCos(angYZRad)) -
00120 (newZ2 * getFastSin(angYZRad));
00121 float newZ3 =
00122 (newY2 * getFastSin(angYZRad)) +
00123 (newZ2 * getFastCos(angYZRad));
00124
00125 float newX4 =
00126 (newX3 * getFastCos(angXYRad)) -
00127 (newY3 * getFastSin(angXYRad));
00128 float newY4 =
00129 (newX3 * getFastSin(angXYRad)) +
00130 (newY3 * getFastCos(angXYRad));
00131 float newZ4 =
00132 newZ3;
00133
00134 Vector newPos;
00135 newPos[0] = position[0] + newX4 * scale;
00136 newPos[1] = position[1] + newY4 * scale;
00137 newPos[2] = position[2] + newZ4 * scale;
00138
00139 GLLenseFlare::instance()->draw(newPos, false, flareType, info.size);
00140 }
00141 }
00142
00143 void MissileMesh::setScale(float scale)
00144 {
00145 scale_=scale;
00146 }