--- /dev/null
+#pragma once
+
+
+class Cat : public FloorPanel {
+public:
+ bool direction = true;
+ float switchtime;
+ Cat() {
+ switchtime = 1000;
+ };
+ void add_location(vec3 loc){
+ models.push_back(translate(mat4(1.0), loc));
+ }
+ void movement(float time) {
+ for(size_t i = 0; i < models.size(); i++) {
+ vec3 mov = vec3(0, 0, -.01);
+ if(!direction)
+ mov = vec3(0, 0, .01);
+ if(switchtime < 0) {
+ direction = !direction;
+ switchtime = 1000;
+ }
+ switchtime -= time;
+ models[i] = translate(models[i], mov);
+ vec3 our_center = get_center(i);
+ for(auto &mouse : game_objects){
+ if(mouse->name == "Mouse"){
+ for(size_t mouse_inst = 0; mouse_inst < mouse->models.size(); mouse_inst++){
+ vec3 mcp = mouse->closest_point(our_center, mouse_inst);
+ vec3 ocp = closest_point(mcp, i);
+ if(can_see(mcp, ocp)){
+ printf("We can see a mouse!\n");
+ } else {
+ if(switchtime > 900){
+ cout << "Can't see mouse, our_center = " << our_center << " mcp = " << mcp << endl;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+};
FloorPanel *floor = (FloorPanel*)add_object(new FloorPanel, "The Floor", true);
floor->texture_file = "textures/stones.png";
- for(float i = -90; i < 90; i+= 5)
- for(float j = -90; j < 90; j+= 5)
- for(float k = -10; k <= -2; k += 1)
+ for(float i = -45; i < 45; i+= 5)
+ for(float j = -45; j < 45; j+= 5)
+ for(float k = -2; k <= -2; k += 1)
floor->add_location_size(vec3(i, k, j), vec3(5, 1, 5));
/* New Way */
ExplodingTarget *targ = (ExplodingTarget*)add_object(new ExplodingTarget, "Target", true);
targ->texture_file = "textures/chalet.jpg";
- targ->add_location_size(vec3(20, 4, 40), vec3(6, 6, 6));
+ targ->add_location_size(vec3(20, 20, 40), vec3(6, 6, 6));
targ->add_location_size(vec3(20, 40, 40), vec3(6, 6, 6));
+
+ Cat *cat = (Cat*)add_object(new Cat, "Cat", true);
+ cat->add_location(vec3(5, 2, 40));
+ cat->texture_file = "textures/cat.jpg";
+
+ FloorPanel *mouse = (FloorPanel*)add_object(new FloorPanel, "Mouse", true);
+ mouse->add_location(vec3(-5, 0, 40));
+ mouse->texture_file = "textures/mouse.jpg";
}
GameObject* add_object(GameObject *new_object, string name, bool solid){
vec3 moinst_center = mo->get_center(mo_inst);
vec3 soinst_center = so->get_center(so_inst);
if(mo->fast_check_distance(mo_inst) + so->fast_check_distance(so_inst)
- < distance(moinst_center, soinst_center))
+ < distance(moinst_center, soinst_center))
continue;
vec3 mo_cp = mo->closest_point(soinst_center, mo_inst);
vec3 so_cp = so->closest_point(moinst_center, so_inst);
if(mo->inside_instance(so_cp, mo_inst) || so->inside_instance(mo_cp, so_inst)){
// We have a collison!
-// printf("Collision Found: (%f %f %f), (%f %f %f)\n", moinst_center.x, moinst_center.y, moinst_center.z, soinst_center.x, soinst_center.y, soinst_center.z);
+ // printf("Collision Found: (%f %f %f), (%f %f %f)\n", moinst_center.x, moinst_center.y, moinst_center.z, soinst_center.x, soinst_center.y, soinst_center.z);
mo->report_collision(so, so_inst, mo_inst);
so->report_collision(mo, mo_inst, so_inst);
}
}
}
+float closest_check(vec3 pointcheck){
+ float min_distance = 1000.0;
+ for(auto so : solid_objects){
+ for(size_t so_inst = 0; so_inst < so->models.size(); so_inst++){
+ vec3 soinst_center = so->get_center(so_inst);
+ float fcd = distance(pointcheck, soinst_center);
+ if(so->fast_check_distance(so_inst) < fcd) {
+ if(fcd < min_distance)
+ min_distance = fcd;
+ continue;
+ }
+ if(so->inside_instance(pointcheck, so_inst)){
+ // There is something in the way!
+ return 0.0f;
+ }
+ vec3 so_cp = so->closest_point(pointcheck, so_inst);
+ float compare_dist = distance(so_cp, pointcheck);
+ if(compare_dist < min_distance)
+ min_distance = compare_dist;
+ }
+ }
+ return min_distance;
+}
+
+bool can_see(vec3 A, vec3 B){
+ vec3 D = normalize(B - A);
+ while(true){
+ float move_distance = closest_check(A);
+ /* Should the 0.01 be a parameter like "Open space width"? */
+ if(move_distance < 0.01)
+ return false;
+ float remaining_distance = distance(A, B);
+ if(remaining_distance <= (move_distance + 0.5))
+ return true;
+ A = A + (D * move_distance);
+ }
+}
+
void collision_check_thread_function(){
for(;;){
double startime = glfwGetTime();
collision_check();
double endtime = glfwGetTime();
-
+
g.cctime = endtime - startime;
}
}
for(auto o : game_objects)
o->movement(1000 * (start_time - last_start));
last_start = start_time;
-
+
double end_time = glfwGetTime();
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);
/*
- for(auto proj : game_objects) {
+ for(auto proj : game_objects) {
if(proj->name == "Projectiles") {
- printf("Projectile count: %lu\n", ((Projectile*)proj)->models.size());
- break;
+ printf("Projectile count: %lu\n", ((Projectile*)proj)->models.size());
+ break;
}
- }
- */
-
+ }
+ */
+
this_thread::sleep_for(chrono::milliseconds(1000));
}
}
g.release_cursor = false;
else if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
fire();
+ } else if(button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
+ vec3 B;
+ B.x = g.player_position.x + cos(g.heading) * 10;
+ B.y = g.player_position.y;
+ B.z = g.player_position.z + sin(g.heading) * 10;
+ bool is_clear = can_see(g.player_position, B);
+ cout << "is_clear: " << is_clear << endl;
}
}