void _draw() { int state = statestack_top(); io::clear_screen(); view_t view; if (state == STATE_EXAMINE) { view = compute_view(target_cursor_position(), VIEW_WIDTH, VIEW_HEIGHT, current_dungeon->width, current_dungeon->height); } else { view = compute_view(player.pos, VIEW_WIDTH, VIEW_HEIGHT, current_dungeon->width, current_dungeon->height); } compute_fov(current_dungeon, player.pos.x, player.pos.y); draw_dungeon(current_dungeon, view); if (inside_view(view, player.pos)) { if (player.flag & CF_INVISIBLE) draw_symbol_hilite(player.symbol, player.pos.x - view.x, player.pos.y - view.y); else draw_symbol(player.symbol, player.pos.x - view.x, player.pos.y - view.y); } if (state == STATE_EXAMINE || state == STATE_CAST_SPELL || state == STATE_ZAP_WAND) { draw_target_cursor(view); } draw_stats(); erase_msg_buffer(); flush_turn_log(false); io::flush(); }
camera_callable::camera_callable() : fov_(45.0f), horizontal_angle_(float(M_PI)), vertical_angle_(0.0f), speed_(0.1f), mouse_speed_(0.005f), near_clip_(0.1f), far_clip_(300.0f), mode_(MODE_AUTO), type_(PERSPECTIVE_CAMERA), ortho_left_(0), ortho_bottom_(0), ortho_top_(preferences::actual_screen_height()), ortho_right_(preferences::actual_screen_width()) { up_ = glm::vec3(0.0f, 1.0f, 0.0f); position_ = glm::vec3(0.0f, 0.0f, 10.0f); aspect_ = float(preferences::actual_screen_width())/float(preferences::actual_screen_height()); compute_view(); compute_projection(); }
camera_callable::camera_callable(const variant& node) : fov_(45.0f), horizontal_angle_(float(M_PI)), vertical_angle_(0.0f), speed_(0.1f), mouse_speed_(0.005f), near_clip_(0.1f), far_clip_(300.0f), mode_(MODE_AUTO), type_(PERSPECTIVE_CAMERA), ortho_left_(0), ortho_bottom_(0), ortho_top_(preferences::actual_screen_height()), ortho_right_(preferences::actual_screen_width()) { position_ = glm::vec3(0.0f, 0.0f, 10.0f); if(node.has_key("fov")) { fov_ = std::min(90.0f, std::max(15.0f, float(node["fov"].as_decimal().as_float()))); } if(node.has_key("horizontal_angle")) { horizontal_angle_ = float(node["horizontal_angle"].as_decimal().as_float()); } if(node.has_key("vertical_angle")) { vertical_angle_ = float(node["vertical_angle"].as_decimal().as_float()); } if(node.has_key("speed")) { speed_ = float(node["speed"].as_decimal().as_float()); } if(node.has_key("mouse_speed")) { mouse_speed_ = float(node["mouse_speed"].as_decimal().as_float()); } if(node.has_key("aspect")) { aspect_ = float(node["aspect"].as_decimal().as_float()); } else { aspect_ = float(preferences::actual_screen_width())/float(preferences::actual_screen_height()); } if(node.has_key("position")) { ASSERT_LOG(node["position"].is_list() && node["position"].num_elements() == 3, "position must be a list of 3 decimals."); position_ = glm::vec3(float(node["position"][0].as_decimal().as_float()), float(node["position"][1].as_decimal().as_float()), float(node["position"][2].as_decimal().as_float())); } if(node.has_key("type")) { if(node["type"].as_string() == "orthogonal") { type_ = ORTHOGONAL_CAMERA; } } if(node.has_key("ortho_window")) { ASSERT_LOG(node["ortho_window"].is_list() && node["ortho_window"].num_elements() == 4, "Attribute 'ortho_window' must be a 4 element list. left,right,top,bottom"); ortho_left_ = node["ortho_window"][0].as_int(); ortho_right_ = node["ortho_window"][1].as_int(); ortho_top_ = node["ortho_window"][2].as_int(); ortho_bottom_ = node["ortho_window"][3].as_int(); } // If lookat key is specified it overrides the normal compute. if(node.has_key("lookat")) { const variant& la = node["lookat"]; ASSERT_LOG(la.has_key("position") && la.has_key("target") && la.has_key("up"), "lookat must be a map having 'position', 'target' and 'up' as tuples"); glm::vec3 position(la["position"][0].as_decimal().as_float(), la["position"][1].as_decimal().as_float(), la["position"][2].as_decimal().as_float()); glm::vec3 target(la["target"][0].as_decimal().as_float(), la["target"][1].as_decimal().as_float(), la["target"][2].as_decimal().as_float()); glm::vec3 up(la["up"][0].as_decimal().as_float(), la["up"][1].as_decimal().as_float(), la["up"][2].as_decimal().as_float()); look_at(position, target, up); mode_ = MODE_MANUAL; } else { compute_view(); } compute_projection(); }