1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
18 #include "backend/video.h"
19 #include "backend/input.h"
20 #include "backend/texture.h"
21 #include "backend/shapes.h"
23 #include "phys/camera.h"
24 #include "phys/world.h"
25 #include "phys/generic_objects.h"
26 #include "phys/player.h"
27 #include "phys/conversion.h"
31 #include "base/time.h"
39 using namespace SandBox
;
41 int sandbox_run(void *);
43 /* see mods/list.h for what this is for... */
44 struct mod sandbox_mod
= {
47 "A demo for testing features"
52 int sandbox_run(void *)
56 //int width = v_info()->width;
57 //int height = v_info()->height;
64 World
*w
= World::Instance();
66 std::vector
<Object
*> objects
;
68 Texture
home_tex("data/material/moon.jpg");
70 Planet
home(&home_tex
, 128, 0.02);
74 //Sphere player(5, 1);
75 float player_speed
= 500;
76 player
.setPosition(0.0, 128.0 + 8, 0.0);
77 objects
.push_back(&player
);
79 //cam.follow(&player);
80 cam
.setOffset(Vec3f(0.0, 10.0, 10.0));
83 cam
.setPosition(Vec3f(100.0, 0.0, 400.0));
84 //cam.setPosition(Vec3f(0.0, 128.0, 100.0));
85 //cam.lookAt(player.getPositionV());
87 Time::Stamp delta
= 0;
88 Time::Stamp frame_time
= Time::Now();
93 frame_time
= Time::Now();
95 glClearColor(0,0,0,0);
96 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
98 glMatrixMode(GL_MODELVIEW
);
104 Vec3f pos
= player
.getPositionV();
105 glColor3f(1.0, 0.0, 0.0);
106 player
.getUp().draw(pos
, 10);
107 player
.getForward().draw(pos
, 10);
108 glColor3f(0.0, 1.0, 0.0);
112 for (size_t i
=0; i
<objects
.size(); i
++) {
113 objects
[i
]->clearGravity();
114 home
.applyGravity(objects
[i
]);
115 objects
[i
]->update();
122 keysym_t
*key
= i_keystate();
130 //player.getBody()->addRelForce(player_speed, 0.0, 0.0);
131 player
.getBody()->addTorque(0.0, player_speed
* 0.1, 0.0);
134 //player.getBody()->addRelForce(-player_speed, 0.0, 0.0);
135 player
.getBody()->addTorque(0.0, -player_speed
* 0.1, 0.0);
138 player
.getBody()->addRelForce(0.0, 0.0, player_speed
);
141 player
.getBody()->addRelForce(0.0, 0.0, -player_speed
);
146 screen_pos
= i_mpos();
147 gl_pos
= v_unproject(screen_pos
[0],screen_pos
[1],1);
149 glEnable(GL_LIGHTING
);
153 glDisable(GL_LIGHTING
);
155 glDisable(GL_TEXTURE_2D
);
156 glDisable(GL_DEPTH_TEST
);
159 glTranslatef(gl_pos
[0],gl_pos
[1],0);
169 glEnable(GL_DEPTH_TEST
);
171 glEnable(GL_TEXTURE_2D
);
172 glColor3f(1.0, 1.0, 1.0);
175 glEnable(GL_LIGHTING
);
176 glDisable(GL_TEXTURE_2D
);
177 glColor3f(1.0, 0.0, 0.0);
179 static float rot
= 0;
184 delta
= Time::Now() - frame_time
;
186 Time::Sleep(20 - delta
);
195 //glClearColor(0,0,0,0);
197 glMatrixMode(GL_PROJECTION
);
200 double w
= v_info()->width
, h
= v_info()->height
;
203 gluPerspective(45,aspect
,1,3000);
205 glEnable(GL_DEPTH_TEST
);
208 glEnable(GL_CULL_FACE
);
211 glShadeModel(GL_SMOOTH
);
213 //glEnable(GL_TEXTURE_2D);
215 glBlendFunc(GL_SRC_ALPHA
,GL_ONE_MINUS_SRC_ALPHA
);