1 /***************************************************************************
2 * Copyright (C) 2004 by Murray Evans *
3 * m.evans@rdg.ac.uk *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include "Galaxy.h"
21 #include "GalaxyLoader.h"
22
CGalaxy(void)23 CGalaxy::CGalaxy(void)
24 {
25 }
26
~CGalaxy(void)27 CGalaxy::~CGalaxy(void)
28 {
29 }
30
AddBase(CBase * in_Base)31 int CGalaxy::AddBase(CBase *in_Base)
32 {
33 int index_i;
34 index_i = AddMent((CEntity*) in_Base);
35 bases.AddToEnd(index_i);
36 return bases.Size() -1;
37 }
38
AddShip(CShip * in_Ship)39 int CGalaxy::AddShip(CShip *in_Ship)
40 {
41 int index_i;
42 index_i = AddMent((CEntity*) in_Ship);
43 ships.AddToEnd(index_i);
44 return ships.Size() -1;
45 }
46
AddInert(CInert * in_Inert)47 int CGalaxy::AddInert(CInert *in_Inert)
48 {
49 int index_i;
50 index_i = AddMent((CEntity*) in_Inert);
51 inerts.AddToEnd(index_i);
52 return inerts.Size() -1;
53 }
54
LoadFromFile(string in_Filename_s)55 int CGalaxy::LoadFromFile(string in_Filename_s)
56 {
57 CGalaxyLoader gl;
58 return gl.Load(in_Filename_s, this);
59 }
60
Render()61 int CGalaxy::Render()
62 {
63 glColor4f(1.0,1.0,1.0,1.0);
64 glClearColor(0,0,0,0);
65 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
66 // do thi better some day...
67 // set up drawing and render each entity
68 glMatrixMode(GL_MODELVIEW);
69 glLoadIdentity();
70 glMatrixMode(GL_PROJECTION);
71 glLoadIdentity();
72 // gluPerspective(45, 640/480, 1, 100);
73 glFrustum(-1, 1, -0.75, 0.75, 1, 1000);
74 glMatrixMode(GL_MODELVIEW);
75
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
77 // enable depth testing if it's not already enabled.
78 glEnable(GL_DEPTH_TEST);
79 // set up camera
80 CVec4f u, f, p;
81 u = camera.GetUp();
82
83 f = camera.GetFace();
84 p = camera.GetPos();
85 gluLookAt(p.X(),p.Y(),p.Z(),
86 p.X() + f.X(), p.Y() + f.Y(),p.Z()+f.Z(),
87 u.X(),u.Y(),u.Z());
88
89 // draw an outline of the arena
90 glLineWidth(2);
91 glDisable(GL_LIGHTING);
92 glDisable(GL_BLEND);
93 glBegin(GL_LINE_LOOP);
94 glColor4f(1.0,0.0,0.0,1.0);
95 glVertex3f(0,0,0);
96 glVertex3f(width_f, 0, 0);
97 glVertex3f(width_f, height_f, 0);
98 glVertex3f(0, height_f, 0);
99 glEnd();
100
101 // draw the background
102 extern CTextureManager texMan;
103
104 glEnable(GL_TEXTURE_2D);
105 glDepthMask(GL_FALSE);
106 glColor4f(1.0,1.0,1.0,1.0);
107 glBindTexture(GL_TEXTURE_2D, texMan.textures[this->backTex_i].id_ui);
108 CVec4f campos = camera.GetPos();
109 glBegin(GL_QUADS);
110 glTexCoord2f(1, 1); glVertex3f(-600,-600, campos.Z()-500);
111 glTexCoord2f(0, 1); glVertex3f(width_f+600,-600, campos.Z()-500);
112 glTexCoord2f(0, 0); glVertex3f(width_f+600,height_f+600, campos.Z()-500);
113 glTexCoord2f(1, 0); glVertex3f(-600,height_f+600, campos.Z()-500);
114 glEnd();
115 glFlush();
116 glEnable(GL_BLEND);
117 glBlendFunc(GL_ONE, GL_ONE);
118 glColor4f(1.0,1.0,1.0,0.5);
119 glBindTexture(GL_TEXTURE_2D, texMan.textures[this->starsTex_i].id_ui);
120 glBegin(GL_QUADS);
121 glTexCoord2f(1, 1); glVertex3f(campos.X()-75,campos.Y()-75, campos.Z()-100);
122 glTexCoord2f(0, 1); glVertex3f(campos.X()+75,campos.Y()-75, campos.Z()-100);
123 glTexCoord2f(0, 0); glVertex3f(campos.X()+75,campos.Y()+75, campos.Z()-100);
124 glTexCoord2f(1, 0); glVertex3f(campos.X()-75,campos.Y()+75, campos.Z()-100);
125 glEnd();
126 glFlush();
127 glDisable(GL_BLEND);
128 glDepthMask(GL_TRUE);
129 glDisable(GL_TEXTURE_2D);
130
131
132 glColor4f(1.0, 1.0, 1.0, 1.0);
133 glEnable(GL_LIGHTING);
134
135 CScene::Render();
136
137
138 galPartGen.Render();
139 glFinish();
140 // draw a map of the arena?
141 // or maybe something more like a radar??
142 return 0;
143 }
144
Update()145 void CGalaxy::Update()
146 {
147 galPartGen.Update();
148 }
149
FreeAll()150 void CGalaxy::FreeAll()
151 {
152 ents.Clear();
153 ships.Clear();
154 shipsAvailToPlayer.Clear();
155 ments.Clear();
156 lights.Clear();
157 bases.Clear();
158 inerts.Clear();
159 shipTypes.Clear();
160 gunTypes.Clear();
161 cargoTypes.Clear();
162 factions.Clear();
163 }
164