All posts by mrmoss

MSL Input and Drawing Programming Interface

Input: 
//True when key/button is down, false when up. 
bool input_check(const int key); 
 
//True when key/button is pressed once, after being pressed, the key must be released and then pressed down again. 
bool input_check_pressed(const int key); 
 
//True when the key/button is released. 
bool input_check_released(const int key); 
 
//Regular Keyboard Bindings 
kb_bang                 '!' 
kb_quote                '\"' 
kb_she                  '#' 
kb_dollar               '$' 
kb_percent              '%' 
kb_ampersand            '&' 
kb_apostrophe           '\'' 
kb_open_parentheses     '(' 
kb_close_parentheses    ')' 
kb_asterisk             '*' 
kb_plus                 '+' 
kb_comma                ',' 
kb_minus                '-' 
kb_period               '.' 
kb_forward_slash        '/' 
kb_0                    '0' 
kb_1                    '1' 
kb_2                    '2' 
kb_3                    '3' 
kb_4                    '4' 
kb_5                    '5' 
kb_6                    '6' 
kb_7                    '7' 
kb_8                    '8' 
kb_9                    '9' 
kb_colon                ':' 
kb_semi_colon           ';' 
kb_less_than            '<' 
kb_equal                '=' 
kb_greater_than         '>' 
kb_question             '?' 
kb_at                   '@' 
kb_A                    'A' 
kb_B                    'B' 
kb_C                    'C' 
kb_D                    'D' 
kb_E                    'E' 
kb_F                    'F' 
kb_G                    'G' 
kb_H                    'H' 
kb_I                    'I' 
kb_J                    'J' 
kb_K                    'K' 
kb_L                    'L' 
kb_M                    'M' 
kb_N                    'N' 
kb_O                    'O' 
kb_P                    'P' 
kb_Q                    'Q' 
kb_R                    'R' 
kb_S                    'S' 
kb_T                    'T' 
kb_U                    'U' 
kb_V                    'V' 
kb_W                    'W' 
kb_X                    'X' 
kb_Y                    'Y' 
kb_Z                    'Z' 
kb_open_square          '[' 
kb_back_slash           '\\' 
kb_close_square         ']' 
kb_carrot               '^' 
kb_under_score          '_' 
kb_accent               '`' 
kb_a                    'a' 
kb_b                    'b' 
kb_c                    'c' 
kb_d                    'd' 
kb_e                    'e' 
kb_f                    'f' 
kb_g                    'g' 
kb_h                    'h' 
kb_i                    'i' 
kb_j                    'j' 
kb_k                    'k' 
kb_l                    'l' 
kb_m                    'm' 
kb_n                    'n' 
kb_o                    'o' 
kb_p                    'p' 
kb_q                    'q' 
kb_r                    'r' 
kb_s                    's' 
kb_t                    't' 
kb_u                    'u' 
kb_v                    'v' 
kb_w                    'w' 
kb_x                    'x' 
kb_y                    'y' 
kb_z                    'z' 
kb_open_bracket         '{' 
kb_pipe                 '|' 
kb_close_bracket        '}' 
kb_tilde                '~' 
 
//Advanced Keyboard Bindings 
kb_backspace 
kb_tab 
kb_enter 
kb_escape 
kb_space 
kb_insert 
kb_numlock 
kb_delete 
 
//Special Keyboard Bindings 
kb_BASE 
kb_f1 
kb_f2 
kb_f3 
kb_f4 
kb_f5 
kb_f6 
kb_f7 
kb_f8 
kb_f9 
kb_f10 
kb_f11 
kb_f12 
kb_left 
kb_up 
kb_right 
kb_down 
kb_page_up 
kb_page_down 
kb_home 
kb_end 
 
//Mouse Bindings 
mb_BASE 
mb_left 
mb_middle 
mb_right 
mb_scroll_up 
mb_scroll_down
 
Drawing: 
//Color Class Declaration 
class color 
{ 
    public: 
        //Friend Classes 
        friend class sprite; 
 
        //Constructor (Default) 
        color(const float red=1,const float green=1,const float blue=1,const float alpha=1); 
 
        //Member Variables 
        float r; 
        float g; 
        float b; 
        float a; 
}; 
 
//Point Direction Function (Returns direction between two points in degrees) 
double point_direction(const double x1,const double y1,const double x2,const double y2); 
 
//Point Distance Function (Returns distance between two points) 
double point_distance(const double x1,const double y1,const double x2,const double y2); 
 
//Basic Shape Drawing Functions 
void draw_point(const double x,const double y,const msl::color& color=msl::color(1,1,1,1)); 
 
void draw_line(const double x1,const double y1,const double x2,const double y2,const msl::color& color=msl::color(1,1,1,1)); 
 
void draw_triangle(const double x1,const double y1,const double x2,const double y2,const double x3,const double y3, 
    const bool fill,const msl::color& color=msl::color(1,1,1,1)); 
 
void draw_rectangle(const double x,const double y,const double width,const double height,const bool fill,const msl::color& color=msl::color(1,1,1,1)); 
 
void draw_rectangle_center(const double x,const double y,const double width,const double height,const bool fill,const msl::color& color=msl::color(1,1,1,1)); 
 
void draw_rectangle_gradient(const double x,const double y,const double width,const double height,const bool fill, 
    const msl::color& color_top_left=msl::color(1,1,1,1), 
    const msl::color& color_top_right=msl::color(1,1,1,1), 
    const msl::color& color_bottom_right=msl::color(1,1,1,1), 
    const msl::color& color_bottom_left=msl::color(1,1,1,1)); 
 
void draw_rectangle_center_gradient(const double x,const double y,const double width,const double height,const bool fill, 
    const msl::color& color_top_left=msl::color(1,1,1,1), 
    const msl::color& color_top_right=msl::color(1,1,1,1), 
    const msl::color& color_bottom_right=msl::color(1,1,1,1), 
    const msl::color& color_bottom_left=msl::color(1,1,1,1)); 
 
void draw_circle(const double x,const double y,const double radius,const msl::color& color=msl::color(1,1,1,1));

OrionDev-GK12 Edition

Here’s a small zip file that contains everything you need to create 2d graphics in c++.  This comes pre-packed with OpenGL, GLU, GLUT, GLEW, GLUI, and SOIL.  Included are several examples.

LINK

Instructions for installation:

  1. Download zip.
  2. Unzip zip.
  3. Open the oriondev-gk12 folder and run editor.bat.
  4. Open an example file to get started!

This zip is for Windows, but if anyone wants to use this on a Unix system feel free to use our libraries:  msl (Mike’s Standard Library) and osl (Orion’s Standard Library).  The libraries are located in:  oriondev-gk12/compiler/include

RobotC Gamepad Library

Controlling an NXT with a gamepad in RobotC isn’t too difficult, but it does require some more advanced programming techniques.  Most programmers end up creating some helper functions and variables that they copy and paste throughout their projects, and here is my “library”.

LINK

Gamepad Layout

Example:

//RobotC Joystick Helper Example Source
//    Created By:        Mike Moss
//    Modified On:       01/09/2013

//Joystick Helper Code
#include "joystick_helper.c"

//Our Program
task main()
{
    //Do Forever
    while(true)
    {
        //Get Gamepad States
        js_update();

        //Move motor A with the X button on joystick 1
        if(js_button(1,js_x)==true)
        {
            motor[motorA]=100;
        }

        //Move motor C with the up arrow on the dpad (0 is up, 2 is right, 4 is down, etc...)
        if(js_dpad(0))
        {
            motor[motorC]=100;
        }

        //Move motor B based on the Y axis on the left thumb stick
        //    of joystick 2 with a deadzone of 15
        motor[motorB]=js_lthumb_y(2,15);
    }
}

Meet the Team: Mike

I’m Mike, and I too have a soft spot for robots!  I’m a student seeking a degree in Computer Science at the University of Alaska Fairbanks.

Background

  • Born and raised in Fairbanks, AK.
  • Got my first computer when I was 4.
  • Took my first computer apart when I was 5.
  • Started programming when I was 8.
  • Starting building robots when I was 15.

Looking forward to building some new hardware and software!