00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/CameraDialog.h>
00022 #include <GLW/GLWFont.h>
00023 #include <GLEXT/GLCameraFrustum.h>
00024 #include <common/DefinesString.h>
00025 #include <graph/Main2DCamera.h>
00026 #include <client/ScorchedClient.h>
00027 #include <client/ClientState.h>
00028 #include <landscape/Landscape.h>
00029 #include <tankgraph/RenderTargets.h>
00030 #include <engine/ActionController.h>
00031 #include <lang/LangResource.h>
00032
00033 CameraDialog *CameraDialog::instance_ = 0;
00034
00035 CameraDialog *CameraDialog::instance()
00036 {
00037 if (!instance_)
00038 {
00039 instance_ = new CameraDialog;
00040 }
00041
00042 return instance_;
00043 }
00044
00045 CameraDialog::CameraDialog() :
00046 GLWWindow("Camera", 100, 15, 200, 200, eTransparent |
00047 eResizeable | eSmallTitle | eSavePosition,
00048 "Shows a view from behind the current tank\n"
00049 "or its shots in a different window")
00050 {
00051 targetCam_.setCameraType(TargetCamera::CamGun);
00052 }
00053
00054 CameraDialog::~CameraDialog()
00055 {
00056 }
00057
00058 void CameraDialog::savePosition(XMLNode *node)
00059 {
00060 GLWWindow::savePosition(node);
00061
00062 node->addChild(new XMLNode("w", int(getW())));
00063 node->addChild(new XMLNode("h", int(getH())));
00064 node->addChild(new XMLNode("type", int(targetCam_.getCameraType())));
00065
00066 }
00067
00068 void CameraDialog::loadPosition(XMLNode *node)
00069 {
00070 GLWWindow::loadPosition(node);
00071
00072 int w, h, type;
00073 if (!node->getNamedChild("w", w)) return;
00074 if (!node->getNamedChild("h", h)) return;
00075 if (!node->getNamedChild("type", type)) return;
00076
00077 setW(float(w));
00078 setH(float(h));
00079 targetCam_.setCameraType((TargetCamera::CamType) type);
00080 }
00081
00082 void CameraDialog::draw()
00083 {
00084 const float inset = 5.0f;
00085 const float corner = 20.0f;
00086
00087 GLWWindow::draw();
00088
00089
00090 {
00091 GLState newState(GLState::DEPTH_ON | GLState::TEXTURE_OFF | GLState::BLEND_ON);
00092
00093 glPushMatrix();
00094 glTranslatef(0.0f, 0.0f, 4000.0f);
00095 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
00096 glBegin(GL_TRIANGLE_FAN);
00097 glVertex2f(x_ + inset - 2.0f, y_ + inset - 2.0f);
00098 drawCircle(7, 13, x_ + inset + corner,
00099 y_ + inset + corner, corner);
00100 glEnd();
00101
00102 glBegin(GL_TRIANGLE_FAN);
00103 glVertex2f(x_ + w_ - inset + 2.0f, y_ + inset - 2.0f);
00104 drawCircle(3, 9, x_ + w_ - inset - corner,
00105 y_ + inset + corner, corner);
00106 glEnd();
00107
00108 glBegin(GL_TRIANGLE_FAN);
00109 glVertex2f(x_ + w_ - inset + 2.0f, y_ + h_ - inset + 2.0f);
00110 drawCircle(-1, 5, x_ + w_ - inset - corner,
00111 y_ + h_ - inset - corner, corner);
00112 glEnd();
00113
00114 glBegin(GL_TRIANGLE_FAN);
00115 glVertex2f(x_ + inset - 2.0f, y_ + h_ - inset + 2.0f);
00116 drawCircle(11, 17, x_ + inset + corner,
00117 y_ + h_ - inset - corner, corner);
00118 glEnd();
00119 glPopMatrix();
00120 }
00121
00122
00123 targetCam_.getCamera().setWindowSize(
00124 int(float(w_ - inset - inset) / GLViewPort::getWidthMult()),
00125 int(float(h_ - inset - inset) / GLViewPort::getHeightMult()));
00126 targetCam_.getCamera().setWindowOffset(
00127 int(float(x_ + inset) / GLViewPort::getWidthMult()),
00128 int(float(y_ + inset) / GLViewPort::getHeightMult()));
00129 targetCam_.draw();
00130
00131
00132
00133 drawLandscape();
00134
00135
00136
00137 Main2DCamera::instance()->draw(0);
00138
00139
00140 GLState newState(GLState::TEXTURE_OFF);
00141 Vector col(0.7f, 0.7f, 0.7f);
00142
00143 LANG_RESOURCE_VAR_1(CAMERA, "CAMERA_CHOICE", "{0} Camera",
00144 targetCam_.getCameraNames()[targetCam_.getCameraType()]);
00145 GLWFont::instance()->getGameFont()->
00146 draw(col, 10.0f, x_ + 15.0f, y_ + 15.0f, 0.0f,
00147 CAMERA);
00148 }
00149
00150 void CameraDialog::simulate(float frameTime)
00151 {
00152 bool playing = (ScorchedClient::instance()->getGameState().getState() ==
00153 ClientState::StatePlaying);
00154
00155
00156 targetCam_.simulate(frameTime, playing);
00157 }
00158
00159 void CameraDialog::drawLandscape()
00160 {
00161 GLCameraFrustum::instance()->draw(0);
00162 Landscape::instance()->drawLand();
00163 RenderTargets::instance()->render3D.draw(0);
00164 Landscape::instance()->drawWater();
00165 Landscape::instance()->drawObjects();
00166 ScorchedClient::instance()->getActionController().draw(0);
00167 ScorchedClient::instance()->getParticleEngine().draw(0);
00168 targetCam_.drawPrecipitation();
00169 }
00170
00171 void CameraDialog::mouseDown(int button, float x, float y, bool &skipRest)
00172 {
00173 GLWWindow::mouseDown(button, x, y, skipRest);
00174 if (x > x_ && x < x_ + 120 && y > y_ && y < y_ + 40)
00175 {
00176 int type = (int) targetCam_.getCameraType(); type++;
00177 if (type >= (int) TargetCamera::CamFree) type = (int) TargetCamera::CamTop;
00178 targetCam_.setCameraType((TargetCamera::CamType) type);
00179 }
00180 }
00181