E:/Eigene Dateien/Eigene Projekte/c0re/DAEffect.cpp

Go to the documentation of this file.
00001 /*
00002         This file is part of c0re.
00003 
00004         c0re is a multiplayer RTS on a hexagonal map with an evolving unit concept.
00005     Copyright (C) 2007 Stephan Hofmann
00006 
00007     c0re is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "DAEffect.h"
00022 
00023 #include "system.h"
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 #include <math.h>
00027 
00028 #include "Level.h"
00029 
00030 DAEffect::DAEffect(Vector3i p_origin, Vector3i p_destination, int p_valOrig, int p_valDest, Level* p_level)
00031 {
00032         origin = p_origin;
00033         destination = p_destination;
00034         valOrig = p_valOrig;
00035         valDest = p_valDest;
00036         level = p_level;
00037 }
00038 
00039 DAEffect::~DAEffect()
00040 {
00041 }
00042 
00043 int DAEffect::render()
00044 {
00045         int ret = 0;
00046         ratio = 2.0;
00047         Vector3d ori, dest;
00048         //get the global coordinates from the origin
00049         ori.x = origin.x * 0.75;
00050         ori.y = origin.y * 0.87;
00051         if (origin.x % 2 == 1)
00052         {
00053                 ori.y += 0.44;
00054         }
00055         //get the global coordinates from the destination
00056         dest.x = destination.x * 0.75;
00057         dest.y = destination.y * 0.87;
00058         if (destination.x % 2 == 1)
00059         {
00060                 dest.y += 0.44;
00061         }
00062         //now compute the angle
00063         Vector3d delta = dest - ori;
00064         double size = delta.length();
00065         ratio *= size;
00066         double angle = 0.0;
00067         if (origin.x == destination.x)
00068         {
00069                 if (origin.y > destination.y)
00070                         angle = 270.0;
00071                 else
00072                         angle = 90.0;
00073         }
00074         else
00075         {
00076                 angle = (atan(delta.y / delta.x)* 57.3);
00077                 if (ori.x < dest.x)
00078                 {
00079                         angle = 360 + angle;
00080                 }
00081                 else
00082                 {
00083                         angle = 180 + angle;
00084                 }
00085         }
00086         
00087         glPushMatrix();
00088         //this is needed as the tile is only using 0.87 of the y-size of the square
00089         glTranslated(0.0, 0.065, 0.0);
00090         delta /= 2.0;
00091         delta += ori;
00092         glTranslated(delta.x, delta.y, delta.z);
00093         glRotated(angle, 0.0, 0.0, 1.0);
00094         glScaled(size, size, size);
00095         Texture::render();
00096         glPopMatrix();
00097 
00098         //now the combat values:
00099         Vector3d origColor, destColor;
00100         if ((valOrig < valDest) && (valDest != 99))
00101         {
00102                 origColor.x = 1.0;
00103                 destColor.y = 1.0;
00104         }
00105         else
00106         {
00107                 destColor.x = 1.0;              
00108                 origColor.y = 1.0;
00109         }
00110         glPushMatrix();
00111         //this is needed as the tile is only using 0.87 of the y-size of the square
00112         glTranslated(0.0, 0.065, 0.0);
00113         glColor4d(origColor.x, origColor.y, origColor.z, 1.0);
00114         level->glPrint2d(ori.x, ori.y, "%i", valOrig);
00115         glColor4d(destColor.x, destColor.y, destColor.z, 1.0);
00116         if (valDest != 99)
00117                 level->glPrint2d(dest.x, dest.y, "%i", valDest);
00118         else
00119                 level->glPrint2d(dest.x, dest.y, "E");
00120         glPopMatrix();
00121         return ret;
00122 }

Generated on Tue Jul 17 22:02:22 2007 for C0re by  doxygen 1.5.2