CameraDialog.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 <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         // Add the rounded corners
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         // Set the new viewport
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         // Draw the stuff we want to see
00132         //GLCameraFrustum::instance()->backupFrustum();
00133         drawLandscape();
00134         //GLCameraFrustum::instance()->restoreFrustum();
00135         
00136         // Return the viewport to the original
00137         Main2DCamera::instance()->draw(0);
00138 
00139         // Draw the camera name
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         // Simulate this viewport
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 

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