CXXFLAGS += -I /usr/local/include
LDFLAGS += -L /usr/local/lib
+# For ImGui
+CXXFLAGS += -I imgui
+LDFLAGS += imgui/*.o imgui/backends/*.o
+
all: ${OBJS}
${CXX} ${OBJS} ${LDFLAGS} -o game
double cctime = 0;
double movement_time = 0;
double gmtime = 0;
+ bool show_hud = 0;
+ bool show_menu = 0;
};
vec3 get_lookat_point(int direction = 0, float r = 0.0);
globals g;
vector<GameObject*> game_objects;
vector<SolidObject*> solid_objects;
-vector<Overlay*> overlays;
map<string, unsigned int> gl_resources;
Hud *main_hud;
+Aimpoint *aimpoint;
#else
extern globals g;
extern vector<GameObject*> game_objects;
extern vector<SolidObject*> solid_objects;
-extern vector<Overlay*> overlays;
extern map<string, unsigned int> gl_resources;
extern Hud *main_hud;
+extern Aimpoint *aimpoint;
#endif
struct vertex {
#include "game.h"
-void load_level(){
+void empty_level(){
+ g.player_position = vec3(0, 1, 0);
+
+ FloorPanel *floor = (FloorPanel*)add_object(new FloorPanel, "The Floor", true);
+ floor->texture_file = "textures/stones.png";
+ floor->add_location_size(vec3(0, 0, 0), vec3(20, 1, 20));
+ floor->add_location_size(vec3(12, 0, 0), vec3(4, 1, 4));
+}
+
+void demo_level(){
/* Level Loading Area */
g.player_position = vec3(0, 1, 10);
mouse->texture_file = "textures/mouse.jpg";
}
+void load_level(){
+ /* Choose Here. We could make a UI for this... */
+ demo_level();
+}
+
GameObject* add_object(GameObject *new_object, string name, bool solid){
game_objects.push_back(new_object);
if(solid)
#define MAIN
-#include "game.h"
+//#define IMGUI
+#include "game.h"
+#ifdef IMGUI
+#include "imgui/imgui.h"
+#include "imgui/backends/imgui_impl_glfw.h"
+#include "imgui/backends/imgui_impl_opengl3.h"
+#endif
int movement_count = 0;
void fire();
}
/* For each object:
+ for(auto o : overlays)
+ o->draw();
* if object->moving:
* for each instance of that object:
* for each solid object:
g.on_count++;
}
+ main_hud->lprintf(1, "Location: %.2f %.2f %.2f", g.player_position.x, g.player_position.y, g.player_position.z);
double end_time = glfwGetTime();
double sleep_seconds = 0.01 - (end_time - start_time);
unsigned long sleep_microseconds = sleep_seconds * 1000000.0;
framecount = 0;
g.movement_time = 1.0 / (double)movement_count;
movement_count = 0;
- printf("FPS: %u cctime = %lf movement_time = %lf gmtime = %lf\n", g.last_fps, g.cctime, g.movement_time, g.gmtime);
+ main_hud->lprintf(2, "FPS: %u cctime = %0.5lf movement_time = %0.5lf gmtime = %0.5lf\n", g.last_fps, g.cctime, g.movement_time, g.gmtime);
/*
for(auto proj : game_objects) {
if(proj->name == "Projectiles") {
if(key == GLFW_KEY_SPACE)
if(!clear_check(g.player_position - vec3(0, g.player_height, 0), g.move_margin))
g.vertical_speed = g.jump_speed;
- if(key == GLFW_KEY_ESCAPE)
- g.release_cursor = true;
+ if(key == GLFW_KEY_ESCAPE) {
+ if(g.release_cursor){
+ g.release_cursor = false;
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
+ } else {
+ g.release_cursor = true;
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ }
+ g.show_menu = !g.show_menu;
+ }
+ if(key == GLFW_KEY_F3)
+ g.show_hud = !g.show_hud;
}
if(action == GLFW_RELEASE) { // UP
if(key == GLFW_KEY_W)
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {
if(g.release_cursor)
- g.release_cursor = false;
- else if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
+ return;
+ if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
fire();
} else if(button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
vec3 B;
glfwSetFramebufferSizeCallback(window, window_size_callback);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
+ // Set up imgui (if we want to use it)
+#ifdef IMGUI
+ IMGUI_CHECKVERSION();
+ using namespace ImGui;
+ CreateContext();
+ ImGuiIO& io = GetIO();// (void)io; // Why?
+ StyleColorsDark();
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
+ ImGui_ImplOpenGL3_Init("#version 450");
+#endif
+
// Set up hud and aimpoint
- Overlay *aimpoint = new Aimpoint("Aimpoint");
+ Aimpoint *aimpoint = new Aimpoint("Aimpoint");
aimpoint->init();
- overlays.push_back(aimpoint);
main_hud = new Hud("Main Hud");
main_hud->init();
- overlays.push_back(main_hud);
- main_hud->lprintf(1, "Hello World!");
+ main_hud->lprintf(0, "Hello World!");
load_level();
for(auto o : game_objects)
for(auto o : game_objects)
o->draw(vp);
- for(auto o : overlays)
- o->draw();
+ if(g.show_hud)
+ main_hud->draw();
+ aimpoint->draw();
+
+#ifdef IMGUI
+ if(g.show_menu){
+ StyleColorsDark();
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplGlfw_NewFrame();
+ NewFrame();
+ Begin("OurWindow");
+ Text("FPS: %.1f FPS", GetIO().Framerate);
+ Text("X = %f, Y = %f, Z = %f", g.player_position.x, g.player_position.y, g.player_position.z);
+ Projectile* p = (Projectile*)find_object("Projectiles");
+ SliderFloat("Speed", &(p->speed), 0.0, 1.0);
+ RadioButton("Projectiles Bounce", &(p->bounce), 1);
+ RadioButton("Projectiles Stop", &(p->bounce), 0);
+
+ // Add some option to try it out
+ End();
+ Render();
+ ImGui_ImplOpenGL3_RenderDrawData(GetDrawData());
+ }
+#endif
/* Not for a particular object */
glfwSwapBuffers(window);
constexpr static float proj_size = .3;
vector<vec3> velocities;
vector<float> times_to_live;
+ float speed = 0.1f;
+ int bounce = 1;
Projectile() {
moving = true;
};
void add_location_size(vec3 start, vec3 vel){
- velocities.push_back(vel * 0.1f);
+ velocities.push_back(vel * speed);
times_to_live.push_back(2000);
specials.push_back(0);
models.push_back(translate(mat4(1.0), start));
void report_collision(GameObject *other, size_t other_instance, size_t our_instance) {
if(our_instance >= models.size())
throw runtime_error("Attempt to report collision with nonexistent instance");
- vec3 our_center = get_center(our_instance);
- vec3 other_cp = other->closest_point(our_center, other_instance);
- /* Now figure out what shape the other object is! */
- /* If we could get a normal vector for the surface we hit... */
- bool rx = true, ry = true, rz = true;
- if(fabs(other_cp.x - our_center.x) < 0.01)
- rx = false;
- if(fabs(other_cp.y - our_center.y) < 0.01)
- ry = false;
- if(fabs(other_cp.z - our_center.z) < 0.01)
- rz = false;
-
- if(rx)
- velocities[our_instance] *= vec3(-1, 1, 1);
- if(ry)
- velocities[our_instance] *= vec3(1, -1, 1);
- if(rz)
- velocities[our_instance] *= vec3(1, 1, -1);
-
- /* Might not need this - applies one timestep of movement to make sure this projectile
- * isn't in contact with the wall anymore so it won't bounce right back */
- models[our_instance] = translate(models[our_instance], velocities[our_instance]);
+ if(bounce){
+ vec3 our_center = get_center(our_instance);
+ vec3 other_cp = other->closest_point(our_center, other_instance);
+ /* Now figure out what shape the other object is! */
+ /* If we could get a normal vector for the surface we hit... */
+ bool rx = true, ry = true, rz = true;
+ if(fabs(other_cp.x - our_center.x) < 0.01)
+ rx = false;
+ if(fabs(other_cp.y - our_center.y) < 0.01)
+ ry = false;
+ if(fabs(other_cp.z - our_center.z) < 0.01)
+ rz = false;
+
+ if(rx)
+ velocities[our_instance] *= vec3(-1, 1, 1);
+ if(ry)
+ velocities[our_instance] *= vec3(1, -1, 1);
+ if(rz)
+ velocities[our_instance] *= vec3(1, 1, -1);
+
+ /* Might not need this - applies one timestep of movement to make sure this projectile
+ * isn't in contact with the wall anymore so it won't bounce right back */
+ models[our_instance] = translate(models[our_instance], velocities[our_instance]);
+ } else {
+ /* TODO: To properly stick, we should make sure we're not kinda partly inside */
+ velocities[our_instance] = vec3(0, 0, 0);
+ }
};
};
void main(void) {
outcolor = texture(tex, vec2(frag_texcoord.x, -frag_texcoord.y));
+ outcolor.g = 0;
+ outcolor.b = 0;
if(outcolor.r < 0.1)
- discard;
+ outcolor = vec4(1.0, 1.0, 1.0, 1.0);
+// discard;
}
void main(void) {
gl_Position = vp * models[gl_InstanceID] * vec4(in_vertex, 1.0);
- out_texcoord = in_texcoord;
+ out_texcoord = in_texcoord;
+// We'll come back and solve this with normal vectors
+// out_texcoord = in_texcoord * vec2(models[gl_InstanceID][0][0], models[gl_InstanceID][2][2]);
special = instance_special[gl_InstanceID];
}