00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <GLW/GLWWeaponModel.h>
00022 #include <client/ScorchedClient.h>
00023 #include <client/ClientState.h>
00024 #include <tankgraph/TargetRendererImplTank.h>
00025 #include <tankgraph/MissileMesh.h>
00026 #include <tank/TankContainer.h>
00027 #include <tank/TankAccessories.h>
00028 #include <tank/TankState.h>
00029 #include <GLW/GLWTranslate.h>
00030 #include <weapons/AccessoryStore.h>
00031 #include <weapons/Accessory.h>
00032 #include <landscape/Landscape.h>
00033 #include <sky/Sky.h>
00034 #include <common/Vector4.h>
00035 #include <common/Defines.h>
00036
00037 REGISTER_CLASS_SOURCE(GLWWeaponModel);
00038
00039 GLWWeaponModel::GLWWeaponModel(float x, float y, float w, float h) :
00040 GLWidget(x, y, w, h),
00041 totalTime_(0.0f)
00042 {
00043 }
00044
00045 GLWWeaponModel::~GLWWeaponModel()
00046 {
00047 }
00048
00049 void GLWWeaponModel::simulate(float frameTime)
00050 {
00051 GLWidget::simulate(frameTime);
00052 totalTime_+=frameTime;
00053 }
00054
00055 void GLWWeaponModel::draw()
00056 {
00057 GLWidget::draw();
00058
00059 Tank *current =
00060 ScorchedClient::instance()->getTankContainer().getCurrentTank();
00061 if (!current ||
00062 current->getState().getState() != TankState::sNormal)
00063 {
00064 return;
00065 }
00066
00067 TargetRendererImplTank *renderer = (TargetRendererImplTank *)
00068 current->getRenderer();
00069 if (!renderer) return;
00070
00071 GLWTankTips *tankTips = renderer->getTips();
00072 Accessory *weapon = current->getAccessories().getWeapons().getCurrent();
00073 if (!weapon) return;
00074
00075 Vector4 sunPosition(-100.0f, 100.0f, 400.0f, 1.0f);
00076 Vector4 sunDiffuse(0.9f, 0.9f, 0.9f, 1.0f);
00077 Vector4 sunAmbient(0.4f, 0.4f, 0.4f, 1.0f);
00078 glLightfv(GL_LIGHT1, GL_AMBIENT, sunAmbient);
00079 glLightfv(GL_LIGHT1, GL_DIFFUSE, sunDiffuse);
00080
00081
00082
00083 static Accessory *storedWeapon = 0;
00084 static Tank *storedTank = 0;
00085 static MissileMesh *storedMesh = 0;
00086 if (weapon != storedWeapon || current != storedTank)
00087 {
00088 storedWeapon = weapon;
00089 storedTank = current;
00090 storedMesh = Accessory::getWeaponMesh(storedWeapon->getModel(), current);
00091 }
00092
00093 GLState tankState(GLState::TEXTURE_ON | GLState::DEPTH_ON);
00094 setToolTip(&weapon->getToolTip());
00095
00096
00097 glPushMatrix();
00098 glTranslatef(x_ + w_ / 2.0f, y_ + w_ / 2.0f, 0.0f);
00099
00100 glLightfv(GL_LIGHT1, GL_POSITION, sunPosition);
00101
00102 glRotatef(totalTime_ * 45.0f, 0.0f, 0.0f, 1.0f);
00103 Vector position;
00104 Vector direction(0.3f, 1.0f, 1.0f);
00105 float scale = MIN(storedWeapon->getModelScale().asFloat(), 1.0f);
00106 storedMesh->setScale(w_ / 3.0f * scale);
00107 storedMesh->draw(position, direction, 0, totalTime_ * 45.0f, totalTime_ * 20.0f);
00108 glPopMatrix();
00109
00110 Landscape::instance()->getSky().getSun().setLightPosition();
00111 }
00112
00113 void GLWWeaponModel::mouseDown(int button, float x, float y, bool &skipRest)
00114 {
00115 Tank *current =
00116 ScorchedClient::instance()->getTankContainer().getCurrentTank();
00117 if (!current ||
00118 current->getState().getState() != TankState::sNormal)
00119 {
00120 return;
00121 }
00122 TargetRendererImplTank *renderer = (TargetRendererImplTank *)
00123 current->getRenderer();
00124 if (!renderer) return;
00125 GLWTankTips *tankTips = renderer->getTips();
00126
00127 if (inBox(x, y, x_, y_, w_, h_))
00128 {
00129 skipRest = true;
00130
00131 tankTips->weaponTip.showItems(GLWTranslate::getPosX() + x,
00132 GLWTranslate::getPosY() + y);
00133 }
00134 }