1 /* ______ ___ ___ 2 * /\ _ \ /\_ \ /\_ \ 3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ 4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ 5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ 6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ 7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ 8 * /\____/ 9 * \_/__/ 10 * 11 * Haptic (that is, force feedback) routines for Allegro. 12 * 13 * By Beoran. 14 * 15 * See LICENSE.txt for copyright information. 16 */ 17 18 #ifndef __al_included_allegro5_haptic_h 19 #define __al_included_allegro5_haptic_h 20 21 #include "allegro5/base.h" 22 #include "allegro5/display.h" 23 #include "allegro5/events.h" 24 #include "allegro5/joystick.h" 25 #include "allegro5/keyboard.h" 26 #include "allegro5/mouse.h" 27 #include "allegro5/touch_input.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #if defined(ALLEGRO_UNSTABLE) || defined(ALLEGRO_INTERNAL_UNSTABLE) || defined(ALLEGRO_SRC) 34 35 /* Enum: ALLEGRO_HAPTIC_CONSTANTS 36 */ 37 enum ALLEGRO_HAPTIC_CONSTANTS 38 { 39 ALLEGRO_HAPTIC_RUMBLE = 1 << 0, 40 ALLEGRO_HAPTIC_PERIODIC = 1 << 1, 41 ALLEGRO_HAPTIC_CONSTANT = 1 << 2, 42 ALLEGRO_HAPTIC_SPRING = 1 << 3, 43 ALLEGRO_HAPTIC_FRICTION = 1 << 4, 44 ALLEGRO_HAPTIC_DAMPER = 1 << 5, 45 ALLEGRO_HAPTIC_INERTIA = 1 << 6, 46 ALLEGRO_HAPTIC_RAMP = 1 << 7, 47 ALLEGRO_HAPTIC_SQUARE = 1 << 8, 48 ALLEGRO_HAPTIC_TRIANGLE = 1 << 9, 49 ALLEGRO_HAPTIC_SINE = 1 << 10, 50 ALLEGRO_HAPTIC_SAW_UP = 1 << 11, 51 ALLEGRO_HAPTIC_SAW_DOWN = 1 << 12, 52 ALLEGRO_HAPTIC_CUSTOM = 1 << 13, 53 ALLEGRO_HAPTIC_GAIN = 1 << 14, 54 ALLEGRO_HAPTIC_ANGLE = 1 << 15, 55 ALLEGRO_HAPTIC_RADIUS = 1 << 16, 56 ALLEGRO_HAPTIC_AZIMUTH = 1 << 17, 57 ALLEGRO_HAPTIC_AUTOCENTER= 1 << 18, 58 }; 59 60 61 62 /* Type: ALLEGRO_HAPTIC 63 */ 64 typedef struct ALLEGRO_HAPTIC ALLEGRO_HAPTIC; 65 66 /* Direction of a haptic effect. Angle is a value between 0 and 2*M_PI. 67 * An angle 0 means oriented towards the user, M_PI is away from the user 68 * (towards the screen). Angle is only supported if the device capabilities 69 * include ALLEGRO_HAPTIC_ANGLE. 70 * 71 * Radius (if supported) is the distance of the effect from the user as a 72 * value between 0 and 1. Normally it is zero. Radius is only supported if the 73 * device capabilities include ALLEGRO_HAPTIC_RADIUS. 74 * 75 * Azimuth is the angle of elevation, between -M_PI/2 and M_PI/2. 76 * Zero points to the horizontal plane, -M_PI/2 points down, and M_PI/2 points 77 * up. Azimuth is only supported if the device capabilities include 78 * ALLEGRO_HAPTIC_AZIMUTH. 79 */ 80 struct ALLEGRO_HAPTIC_DIRECTION 81 { 82 double angle; 83 double radius; 84 double azimuth; 85 }; 86 87 /* In all of the following structs, the doubles that express duration 88 * represent time in seconds. The double that represent levels of intensity 89 * are between 0.0 and 1.0. 90 */ 91 92 /* Delay to start the replay and duration of the replay, expressed in seconds. */ 93 struct ALLEGRO_HAPTIC_REPLAY 94 { 95 double length; 96 double delay; 97 }; 98 99 /* Envelope of the effect. */ 100 struct ALLEGRO_HAPTIC_ENVELOPE 101 { 102 double attack_length; 103 double attack_level; 104 double fade_length; 105 double fade_level; 106 }; 107 108 /* Constant effect. Level is between 0.0 and 1.0. */ 109 struct ALLEGRO_HAPTIC_CONSTANT_EFFECT 110 { 111 double level; 112 struct ALLEGRO_HAPTIC_ENVELOPE envelope; 113 }; 114 115 /* Ramp effect. Both start_level and end level are between 0.0 and 1.0. */ 116 struct ALLEGRO_HAPTIC_RAMP_EFFECT 117 { 118 double start_level; 119 double end_level; 120 struct ALLEGRO_HAPTIC_ENVELOPE envelope; 121 }; 122 123 /* Condition effect. */ 124 struct ALLEGRO_HAPTIC_CONDITION_EFFECT 125 { 126 double right_saturation; 127 double left_saturation; 128 double right_coeff; 129 double left_coeff; 130 double deadband; 131 double center; 132 }; 133 134 /* Periodic (wave) effect. */ 135 struct ALLEGRO_HAPTIC_PERIODIC_EFFECT 136 { 137 int waveform; 138 double period; 139 double magnitude; 140 double offset; 141 double phase; 142 143 struct ALLEGRO_HAPTIC_ENVELOPE envelope; 144 int custom_len; 145 double *custom_data; 146 }; 147 148 /* Simple rumble effect with a magnitude between 0.0 and 1.0 for both 149 * the strong and the weak rumble motors in the haptic device. 150 */ 151 struct ALLEGRO_HAPTIC_RUMBLE_EFFECT 152 { 153 double strong_magnitude; 154 double weak_magnitude; 155 }; 156 157 union ALLEGRO_HAPTIC_EFFECT_UNION 158 { 159 struct ALLEGRO_HAPTIC_CONSTANT_EFFECT constant; 160 struct ALLEGRO_HAPTIC_RAMP_EFFECT ramp; 161 struct ALLEGRO_HAPTIC_PERIODIC_EFFECT periodic; 162 struct ALLEGRO_HAPTIC_CONDITION_EFFECT condition; 163 struct ALLEGRO_HAPTIC_RUMBLE_EFFECT rumble; 164 }; 165 166 167 /* Type: ALLEGRO_HAPTIC_EFFECT 168 */ 169 struct ALLEGRO_HAPTIC_EFFECT 170 { 171 172 int type; 173 struct ALLEGRO_HAPTIC_DIRECTION direction; 174 struct ALLEGRO_HAPTIC_REPLAY replay; 175 union ALLEGRO_HAPTIC_EFFECT_UNION data; 176 }; 177 178 typedef struct ALLEGRO_HAPTIC_EFFECT ALLEGRO_HAPTIC_EFFECT; 179 180 181 /* Type: ALLEGRO_HAPTIC_EFFECT_ID 182 */ 183 typedef struct ALLEGRO_HAPTIC_EFFECT_ID ALLEGRO_HAPTIC_EFFECT_ID; 184 185 struct ALLEGRO_HAPTIC_EFFECT_ID 186 { 187 ALLEGRO_HAPTIC *_haptic; 188 int _id; 189 int _handle; 190 void * _pointer; 191 double _effect_duration; 192 bool _playing; 193 double _start_time; 194 double _end_time; 195 void * driver; 196 }; 197 198 199 AL_FUNC(bool, al_install_haptic, (void)); 200 AL_FUNC(void, al_uninstall_haptic, (void)); 201 AL_FUNC(bool, al_is_haptic_installed, (void)); 202 203 AL_FUNC(bool, al_is_mouse_haptic, (ALLEGRO_MOUSE *)); 204 AL_FUNC(bool, al_is_joystick_haptic, (ALLEGRO_JOYSTICK *)); 205 AL_FUNC(bool, al_is_keyboard_haptic, (ALLEGRO_KEYBOARD *)); 206 AL_FUNC(bool, al_is_display_haptic, (ALLEGRO_DISPLAY *)); 207 AL_FUNC(bool, al_is_touch_input_haptic, (ALLEGRO_TOUCH_INPUT *)); 208 209 AL_FUNC(ALLEGRO_HAPTIC *, al_get_haptic_from_mouse, (ALLEGRO_MOUSE *)); 210 AL_FUNC(ALLEGRO_HAPTIC *, al_get_haptic_from_joystick, (ALLEGRO_JOYSTICK *)); 211 AL_FUNC(ALLEGRO_HAPTIC *, al_get_haptic_from_keyboard, (ALLEGRO_KEYBOARD *)); 212 AL_FUNC(ALLEGRO_HAPTIC *, al_get_haptic_from_display, (ALLEGRO_DISPLAY *)); 213 AL_FUNC(ALLEGRO_HAPTIC *, al_get_haptic_from_touch_input, (ALLEGRO_TOUCH_INPUT *)); 214 215 AL_FUNC(bool, al_release_haptic, (ALLEGRO_HAPTIC *)); 216 217 AL_FUNC(bool, al_is_haptic_active, (ALLEGRO_HAPTIC *)); 218 AL_FUNC(int, al_get_haptic_capabilities, (ALLEGRO_HAPTIC *)); 219 AL_FUNC(bool, al_is_haptic_capable, (ALLEGRO_HAPTIC *, int)); 220 221 AL_FUNC(bool, al_set_haptic_gain, (ALLEGRO_HAPTIC *, double)); 222 AL_FUNC(double, al_get_haptic_gain, (ALLEGRO_HAPTIC *)); 223 224 AL_FUNC(bool, al_set_haptic_autocenter, (ALLEGRO_HAPTIC *, double)); 225 AL_FUNC(double, al_get_haptic_autocenter, (ALLEGRO_HAPTIC *)); 226 227 228 AL_FUNC(int, al_get_max_haptic_effects, (ALLEGRO_HAPTIC *)); 229 AL_FUNC(bool, al_is_haptic_effect_ok, (ALLEGRO_HAPTIC *, ALLEGRO_HAPTIC_EFFECT *)); 230 AL_FUNC(bool, al_upload_haptic_effect, (ALLEGRO_HAPTIC *, ALLEGRO_HAPTIC_EFFECT *, ALLEGRO_HAPTIC_EFFECT_ID *)); 231 AL_FUNC(bool, al_play_haptic_effect, (ALLEGRO_HAPTIC_EFFECT_ID *, int)); 232 AL_FUNC(bool, al_upload_and_play_haptic_effect, (ALLEGRO_HAPTIC *, ALLEGRO_HAPTIC_EFFECT *, ALLEGRO_HAPTIC_EFFECT_ID *, int)); 233 AL_FUNC(bool, al_stop_haptic_effect, (ALLEGRO_HAPTIC_EFFECT_ID *)); 234 AL_FUNC(bool, al_is_haptic_effect_playing, (ALLEGRO_HAPTIC_EFFECT_ID *)); 235 AL_FUNC(bool, al_release_haptic_effect, (ALLEGRO_HAPTIC_EFFECT_ID *)); 236 AL_FUNC(double, al_get_haptic_effect_duration, (ALLEGRO_HAPTIC_EFFECT *)); 237 AL_FUNC(bool, al_rumble_haptic, (ALLEGRO_HAPTIC *, double, double, ALLEGRO_HAPTIC_EFFECT_ID *)); 238 239 #endif 240 241 #ifdef __cplusplus 242 } 243 #endif 244 245 #endif 246 247 /* vim: set sts=3 sw=3 et: */ 248