1 /* 2 * ball.h 3 * ball in Mondrian 4 * DIN Is Noise is released under GNU Public License 2.0 5 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath 6 * For more information, please visit https://dinisnoise.org/ 7 */ 8 9 #ifndef __ball__ 10 #define __ball__ 11 12 #include "trail.h" 13 #include "ball_ops.h" 14 15 struct rect; 16 17 struct ball { // a ball 18 19 enum {NOTE = 0, NOISE}; 20 int trig_what; // trigger note or noise? 21 22 float x, y; // position 23 24 // velocity - speed, vector, slope, slope inverse, is slope infinite? 25 float V, vx, vy, vm, vm_1; 26 int vm_inf; 27 28 int auto_rotate; // velocity vector auto rotating? 0 - no, 1 - anti-clockwise, -1 - clockwise 29 float dtheta; // angle to rotate ball direction 30 31 rect* R; // box in which it is bouncing 32 int select; // selected? 33 int frozen; // frozen? 34 35 float pitch_mult; // to modulate pitch 36 int mod; // 0 = no modulation, < 0 = modulate down, > 0 modulate up // for visual 37 38 float vol_mult; // to scale triggered sound volume 39 float attack_time; // time for note to rise to full volume 40 float decay_time; // time for note to fall silent 41 enum {SET_DECAY_TIME=1, SET_ATTACK_TIME, SET_VOL_MULT}; 42 43 // bouncer = bounces, wrecker = makes slits, healer = closes slits 44 int type; 45 static const char* types_str [4]; 46 enum {BOUNCER=0, WRECKER, HEALER, INVALID}; // ball types 47 48 // to initialise new ball 49 static float recent_attack_time; 50 static float recent_decay_time; 51 static float recent_pitch_mult; 52 53 int num_notes; // number of active notes triggered by this ball 54 int del; // delete ball? when triggered sounds have decayed 55 56 // operations 57 turn op_turn; 58 speed op_speed; 59 teleport op_teleport; 60 Clone op_clone; 61 Transform op_transform; 62 63 void eval_ops (); 64 65 // visual 66 trail_t trail; // trail 67 float r, g, b; // color 68 69 // log 70 static int ref; // to log if we deleted all balls on exit 71 72 ball (int _type = BOUNCER); ~ballball73 ~ball () { --ref; } 74 75 void init (int _type = BOUNCER); 76 void set_velocity (float _x, float _y); 77 void rotate_velocity (int dir); 78 void calc_velocity_slope (); 79 void update (); 80 void set_type (int _type); 81 void color_using_modulation (); 82 void on_edge_hit (int e1, int e2, int cl, float& v, float xry, float yrx, float elb, float ewh, std::pair<float, float>& invl, int& eh); 83 void print (); 84 void clone_this (ball* C); 85 86 }; 87 #endif 88