81 lines
3.1 KiB
C++
81 lines
3.1 KiB
C++
#ifndef Pudding_h_
|
|
#define Pudding_h_
|
|
|
|
#include <stdlib.h>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include <type_traits>
|
|
#include <filesystem>
|
|
#include <curl/curl.h>
|
|
#include "SDL.h"
|
|
#include "json/json.hpp"
|
|
#include "glm/vec2.hpp"
|
|
#include "opencv2/core.hpp"
|
|
#include "opencv2/videoio.hpp"
|
|
#include "opencv2/highgui.hpp"
|
|
#include "opencv2/imgproc.hpp"
|
|
#include "zbar.h"
|
|
#include "Game.hpp"
|
|
#include "Color.hpp"
|
|
#include "extension.hpp"
|
|
#include "Item.hpp"
|
|
|
|
class Pudding : public Game
|
|
{
|
|
|
|
private:
|
|
|
|
typedef Game super;
|
|
const std::string OPEN_FOOD_API_URL = "https://world.openfoodfacts.org/api/v0/product/";
|
|
const std::string NUTRONIX_API_URL = "https://trackapi.nutritionix.com/v2/search/item?upc=";
|
|
const std::string BARCODE_MONSTER_API_URL = "https://barcode.monster/api/";
|
|
const std::string BEST_BUY_API_URL_1 = "https://api.bestbuy.com/v1/products(upc=";
|
|
const std::string BEST_BUY_API_URL_2 = ")?format=json&apiKey=";
|
|
const std::string NUTRONIX_NOT_FOUND = "resource not found";
|
|
const std::string GIANTBOMB_API_URL = "https://www.giantbomb.com/api/release/?api_key=";
|
|
const glm::vec3 ZERO_VECTOR_3D = glm::vec3(0, 0, 0);
|
|
const glm::vec3 Y_UNIT_NORMAL_3D = glm::vec3(0, 1, 0);
|
|
const glm::mat4 VIEW_MATRIX = glm::lookAt(glm::vec3(4, 3, 3), ZERO_VECTOR_3D, Y_UNIT_NORMAL_3D);
|
|
const glm::vec3 PUDDING_BROWN = glm::vec3(0.713f, 0.359f, 0.224f);
|
|
const glm::vec3 PUDDING_YELLOW = glm::vec3(0.878f, 0.859f, 0.122f);
|
|
std::string current_barcode, previous_barcode, current_config_barcode, current_camera_barcode;
|
|
std::vector<Item> items;
|
|
int current_item_index = 0;
|
|
cv::VideoCapture capture;
|
|
cv::Mat capture_frame;
|
|
zbar::ImageScanner image_scanner;
|
|
GLuint vbo, flat_program, mvp_program, video_capture_texture_id, mvp_id;
|
|
glm::mat4 projection, model = glm::mat4(1.0f), mvp;
|
|
std::vector<glm::vec3> wireframe_pudding_vertices, pudding_vertices, pudding_colors;
|
|
|
|
void set_pudding_model(const std::vector<glm::vec2>&, const std::vector<glm::vec2>&, float y);
|
|
void set_wireframe_pudding_vertices(const std::vector<glm::vec2>&, const std::vector<glm::vec2>&, float y);
|
|
void load_gl_context();
|
|
void initialize_camera();
|
|
void incorporate_open_food_api(Item&);
|
|
void incorporate_nutronix_api(Item&);
|
|
void incorporate_edamam_api(Item&);
|
|
void incorporate_best_buy_api(Item&);
|
|
void save_item_json(const nlohmann::json&, const Item&, const std::string&) const;
|
|
nlohmann::json json_from_url(const std::string&, const std::vector<std::string>& = {});
|
|
void curl_get_bytes(const std::string& url, std::vector<std::uint8_t>&, const std::vector<std::string>& = {});
|
|
static size_t curl_write_response(std::uint8_t*, size_t, size_t, std::vector<std::uint8_t>*);
|
|
std::shared_ptr<GLuint> texture_from_image_url(const std::string&);
|
|
static void destroy_texture(GLuint*);
|
|
|
|
public:
|
|
|
|
Pudding();
|
|
void respond(SDL_Event&);
|
|
void add_item(const std::string&);
|
|
void increment_item_index(int = 1);
|
|
Item& get_current_item();
|
|
void update();
|
|
virtual std::string get_class_name() const { return "Pudding"; }
|
|
|
|
};
|
|
|
|
#endif
|