Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_primitives.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_ttf.h>
- #include <cstdio>
- #include <string>
- #include "deg_trig.h"
- using namespace std;
- const int SCREEN_X = 800;
- const int SCREEN_Y = 600;
- const float fps = 60.0f;
- struct posits
- {
- float x_pos;
- float y_pos;
- };
- bool allegro5_setup( ALLEGRO_DISPLAY **disp,
- ALLEGRO_EVENT_QUEUE **event_q,
- ALLEGRO_TIMER **f_timer,
- ALLEGRO_FONT **fnt_1,
- ALLEGRO_FONT **fnt_2)
- {
- if(al_init() == false)
- {
- printf("Allegro did not initialize.\n");
- return false;
- }
- if(al_install_mouse() == false)
- {
- printf("Mouse did not install.\n");
- return false;
- }
- al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
- *disp = al_create_display(SCREEN_X, SCREEN_Y);
- if(*disp == NULL)
- {
- printf("Display not created.\n");
- return false;
- }
- *event_q = al_create_event_queue();
- if(*event_q == NULL)
- {
- printf("Event Queue not created.\n");
- al_destroy_display(*disp);
- return false;
- }
- *f_timer = al_create_timer(1.0f / fps);
- if(*f_timer == NULL)
- {
- printf("Timer not created.\n");
- al_destroy_display(*disp);
- al_destroy_event_queue(*event_q);
- return false;
- }
- al_init_font_addon();
- if(al_init_ttf_addon() == false)
- {
- printf("TTF addon not initialized.\n");
- al_destroy_display(*disp);
- al_destroy_event_queue(*event_q);
- al_destroy_timer(*f_timer);
- return false;
- }
- *fnt_1 = al_load_ttf_font("./fonts/Verdana.ttf", -11, NULL);
- *fnt_2 = al_load_ttf_font("./fonts/Verdana.ttf", -19, NULL);
- if((*fnt_1 == NULL || *fnt_2 == NULL) || (*fnt_1 == NULL && *fnt_2 == NULL))
- {
- printf("TTF Font did not load. Check that it exists in /font.\n");
- al_destroy_display(*disp);
- al_destroy_event_queue(*event_q);
- al_destroy_timer(*f_timer);
- return false;
- }
- if(al_init_primitives_addon() == false)
- {
- printf("Primitives did not initialize.\n");
- al_destroy_display(*disp);
- al_destroy_event_queue(*event_q);
- al_destroy_timer(*f_timer);
- return false;
- }
- al_register_event_source(*event_q, al_get_display_event_source(*disp));
- al_register_event_source(*event_q, al_get_mouse_event_source());
- al_register_event_source(*event_q, al_get_timer_event_source(*f_timer));
- return true;
- }
- //---------------------------------------------------------------
- void allegro5_terminate( ALLEGRO_DISPLAY **disp,
- ALLEGRO_EVENT_QUEUE **event_q,
- ALLEGRO_TIMER **f_timer)
- {
- al_destroy_display(*disp);
- al_destroy_event_queue(*event_q);
- al_destroy_timer(*f_timer);
- }
- //---------------------------------------------------------------
- //---------------------------------------------------------------
- int main(int argc, char *argv[])
- {
- ALLEGRO_DISPLAY *display = NULL;
- ALLEGRO_EVENT_QUEUE *event_queue = NULL;
- ALLEGRO_TIMER *timer = NULL;
- ALLEGRO_FONT *font_1 = NULL;
- ALLEGRO_FONT *font_2 = NULL;
- bool draw = false;
- bool loop = true;
- bool mouseb = false;
- char buffer[100];
- //int mx = 0;
- //int my = 0;
- float x_dist = 0.0f;
- float y_dist = 0.0f;
- float r_bearing = 0.0f;
- float full_r_bearing = 0.0f;
- float d_bearing = 0.0f;
- float deg_cos = 0.0f;
- float deg_sin = 0.0f;
- float rad_cos = 0.0f;
- float rad_sin = 0.0f;
- float deg_tan = 0.0f;
- float rad_tan = 0.0f;
- float nod_d_bearing = 0.0f;
- float nod_deg_cos = 0.0f;
- float nod_deg_sin = 0.0f;
- posits act_ac_pos;
- posits dest_ac_pos;
- act_ac_pos.x_pos = 400.0f;
- act_ac_pos.y_pos = 300.0f;
- dest_ac_pos.x_pos = 0.0f;
- dest_ac_pos.y_pos = 0.0f;
- if(allegro5_setup(&display, &event_queue, &timer, &font_1, &font_2) == false)
- return -1;
- al_start_timer(timer);
- while(loop == true)
- {
- ALLEGRO_EVENT event;
- al_wait_for_event(event_queue, &event);
- switch(event.type)
- {
- case ALLEGRO_EVENT_DISPLAY_CLOSE:
- loop = false;
- break;
- case ALLEGRO_EVENT_TIMER:
- draw = true;
- break;
- case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
- mouseb = true;
- dest_ac_pos.x_pos = (float)event.mouse.x;
- dest_ac_pos.y_pos = (float)event.mouse.y;
- break;
- case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
- mouseb = false;
- break;
- case ALLEGRO_EVENT_MOUSE_AXES:
- if(mouseb == true)
- /*{
- dest_ac_pos.x_pos = event.mouse.x;
- dest_ac_pos.y_pos = event.mouse.y;
- }*/
- break;
- default:
- break;
- }
- if(al_event_queue_is_empty(event_queue) && draw == true)
- {
- if(mouseb == true)
- {
- x_dist = dest_ac_pos.x_pos - act_ac_pos.x_pos;
- y_dist = dest_ac_pos.y_pos - act_ac_pos.y_pos;
- r_bearing = atan2f(y_dist, x_dist);
- full_r_bearing = my_atan2f_PIx2_rads(y_dist, x_dist);
- d_bearing = my_atan2f_deg(y_dist, x_dist);
- deg_cos = my_cosf_deg(d_bearing);
- deg_sin = my_sinf_deg(d_bearing);
- rad_cos = cosf(r_bearing);
- rad_sin = sinf(r_bearing);
- deg_tan = my_tanf_deg(d_bearing);
- rad_tan = tanf(r_bearing);
- nod_d_bearing = my_nod_atan2f_deg(y_dist, x_dist);
- nod_deg_cos = my_nod_cosf_deg(nod_d_bearing);
- nod_deg_sin = my_nod_sinf_deg(nod_d_bearing);
- }
- al_clear_to_color(al_map_rgb(0,0,30));
- al_draw_circle(act_ac_pos.x_pos, act_ac_pos.y_pos, 3.0f, al_map_rgb(200,200,200), 0);
- sprintf(buffer, "Bearing radians %.4f", r_bearing);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 10.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Bearing full radians %.4f", full_r_bearing);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 20.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Bearing degrees %.2f", d_bearing);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 30.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Cosine Value from degrees %.4f", deg_cos);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 45.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Sine Value from degrees %.4f", deg_sin);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 55.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Cosine Value from radians %.4f", rad_cos);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 70.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Sine Value from radians %.4f", rad_sin);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 80.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Tangent Value from radians %.4f", rad_tan);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 95.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "Tangent Value from degrees %.4f", deg_tan);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 105.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "North Orientated Atan Degrees %.2f", nod_d_bearing);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 120.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "North Orientated Cosine form Degrees %.4f", nod_deg_cos);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 130.0f, ALLEGRO_ALIGN_LEFT, buffer);
- sprintf(buffer, "North Orientated Cosine form Degrees %.4f", nod_deg_sin);
- al_draw_text(font_1, al_map_rgb(200,200,200), 10.0f, 140.0f, ALLEGRO_ALIGN_LEFT, buffer);
- al_flip_display();
- draw = false;
- }
- }
- al_stop_timer(timer);
- allegro5_terminate(&display, &event_queue, &timer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement