@@ -151,78 +151,77 @@ void clsCannonball::update(double newdeltat) {
151
151
// /
152
152
// ///////////////////////////////////////////////
153
153
154
- blncheckphysics_ = true ; // enable on update
155
- deltat_ = newdeltat;
156
-
157
- // reset the forces so strange things don't happen
158
- forces_ = {0.0 , props_.mass * global::physics::kGravity };
159
-
160
- if (blndragenabled_) {
161
- doMagnusEffect ();
162
- dragUpdateAcc ();
163
- }
164
- doFriction ();
165
-
166
- acc_.x = forces_.x / props_.mass ;
167
- acc_.y = forces_.y / props_.mass ;
168
-
169
- vel_.x = (vel_.x + acc_.x * deltat_);
170
- vel_.y = (vel_.y + acc_.y * deltat_);
171
-
172
- // get new velocities if collision with edges
173
-
174
- double coefres = (global::config.values .uchrCollisionMethod == CollideInelastic) ?
175
- global::physics::kCoefficientRestitution : 1.0 ;
176
-
177
-
178
- /* TODO (GamerMan7799#2#): Make this stuff simpler */
179
- if (collisionbox_.left < screen_place_.w / 2 ) {
180
- vel_.x *= -1 * coefres;
181
- vel_.y *= coefres;
182
- dblLOC_.x = screen_place_.w ;
183
- }
184
-
185
- if (collisionbox_.right > (screen::screenatt.width )) {
186
- vel_.x *= -1 * coefres;
187
- vel_.y *= coefres;
188
- dblLOC_.x = screen::screenatt.width - screen_place_.w / 2 ;
189
- }
190
-
191
- if (collisionbox_.bottom > (screen::screenatt.height )) {
192
- vel_.x *= coefres;
193
- vel_.y *= -1 * coefres;
194
- dblLOC_.y = screen_place_.h / 2 ;
195
- }
196
-
197
- if (collisionbox_.top < 0 ) {
198
- vel_.x *= coefres;
199
- vel_.y *= -1 * coefres;
200
- dblLOC_.y = (screen::screenatt.height ) - screen_place_.h / 2 ;
201
- }
202
-
203
- dblLOC_.x = dblLOC_.x + vel_.x * deltat_ /* + 0.5 * acc_.x * pow(deltat_,2)*/ ;
204
- dblLOC_.y = dblLOC_.y + vel_.y * deltat_ /* + 0.5 * acc_.y * pow(deltat_,2)*/ ;
205
-
206
- // update place and collision box again in case something changed
207
- place_.x = round (dblLOC_.x );
208
- place_.y = round (dblLOC_.y );
209
- updateCollisionBox ();
210
-
211
- if (global::config.values .blnLogging ) {
212
- FILE* logfile = fopen (" logfile.log" ," a" );
213
- fprintf (logfile," Ball %3u \t (%.3f, %.3f)\n " ,ballID_, dblLOC_.x ,dblLOC_.y );
214
- fclose (logfile);
215
- }
216
-
217
- double total_v;
218
- total_v = sqrt ( pow (vel_.x ,2 ) + pow (vel_.y ,2 ) );
219
- if (total_v < global::physics::kMinVelocity || isnan (total_v) ) {
220
- blnstarted_ = false ;
221
- if (global::blnDebugMode) {
222
- if ( isnan (total_v) ) { printf (" Ball velocity is NaN; killing it.\n " ); }
223
- else { printf (" Ball moving too slow; killing it.\n " ); }
224
- } // end if debug mode
225
- } // end if should kill
154
+ if (!paused_) {
155
+ blncheckphysics_ = true ; // enable on update
156
+ deltat_ = newdeltat;
157
+
158
+ // reset the forces so strange things don't happen
159
+ forces_ = {0.0 , props_.mass * global::physics::kGravity };
160
+
161
+ if (blndragenabled_) {
162
+ doMagnusEffect ();
163
+ dragUpdateAcc ();
164
+ }
165
+ doFriction ();
166
+
167
+ acc_.x = forces_.x / props_.mass ;
168
+ acc_.y = forces_.y / props_.mass ;
169
+
170
+ vel_.x = (vel_.x + acc_.x * deltat_);
171
+ vel_.y = (vel_.y + acc_.y * deltat_);
172
+
173
+ // get new velocities if collision with edges
174
+ double coefres = (global::config.values .uchrCollisionMethod == CollideInelastic) ?
175
+ global::physics::kCoefficientRestitution : 1.0 ;
176
+
177
+ if (collisionbox_.left < screen_place_.w / 2 ) {
178
+ vel_.x *= -1 * coefres;
179
+ vel_.y *= coefres;
180
+ dblLOC_.x = screen_place_.w ;
181
+ }
182
+
183
+ if (collisionbox_.right > (screen::screenatt.width )) {
184
+ vel_.x *= -1 * coefres;
185
+ vel_.y *= coefres;
186
+ dblLOC_.x = screen::screenatt.width - screen_place_.w / 2 ;
187
+ }
188
+
189
+ if (collisionbox_.bottom > (screen::screenatt.height )) {
190
+ vel_.x *= coefres;
191
+ vel_.y *= -1 * coefres;
192
+ dblLOC_.y = screen_place_.h / 2 ;
193
+ }
194
+
195
+ if (collisionbox_.top < 0 ) {
196
+ vel_.x *= coefres;
197
+ vel_.y *= -1 * coefres;
198
+ dblLOC_.y = (screen::screenatt.height ) - screen_place_.h / 2 ;
199
+ }
200
+
201
+ dblLOC_.x = dblLOC_.x + vel_.x * deltat_ /* + 0.5 * acc_.x * pow(deltat_,2)*/ ;
202
+ dblLOC_.y = dblLOC_.y + vel_.y * deltat_ /* + 0.5 * acc_.y * pow(deltat_,2)*/ ;
203
+
204
+ // update place and collision box again in case something changed
205
+ place_.x = round (dblLOC_.x );
206
+ place_.y = round (dblLOC_.y );
207
+ updateCollisionBox ();
208
+
209
+ if (global::config.values .blnLogging ) {
210
+ FILE* logfile = fopen (" logfile.log" ," a" );
211
+ fprintf (logfile," Ball %3u \t (%.3f, %.3f)\n " ,ballID_, dblLOC_.x ,dblLOC_.y );
212
+ fclose (logfile);
213
+ }
214
+
215
+ double total_v;
216
+ total_v = sqrt ( pow (vel_.x ,2 ) + pow (vel_.y ,2 ) );
217
+ if (total_v < global::physics::kMinVelocity || isnan (total_v) ) {
218
+ blnstarted_ = false ;
219
+ if (global::blnDebugMode) {
220
+ if ( isnan (total_v) ) { printf (" Ball velocity is NaN; killing it.\n " ); }
221
+ else { printf (" Ball moving too slow; killing it.\n " ); }
222
+ } // end if debug mode
223
+ } // end if should kill
224
+ } // end if not paused
226
225
show (); // show the ball on the screen
227
226
}
228
227
/* ****************************************************************************/
@@ -278,6 +277,7 @@ void clsCannonball::setValues(double r, LOC init_place,
278
277
// ///////////////////////////////////////////////
279
278
280
279
ballID_ = newID;
280
+ paused_ = false ;
281
281
282
282
props_.radius = r; // in meters
283
283
@@ -417,8 +417,8 @@ void clsCannonball::doFriction() {
417
417
normal_force;
418
418
updateCollisionBox ();
419
419
// Update acc for Friction values
420
- if ( collisionbox_.bottom < screen_place_.h ||
421
- collisionbox_.top > screen::screenatt.height ) {
420
+ if ( collisionbox_.bottom <= screen_place_.h ||
421
+ collisionbox_.top >= screen::screenatt.height ) {
422
422
// Ball is in contact with floor or ceiling update x acc
423
423
forces_.x += friction * (vel_.x < 0.0 ? -1.0 : 1.0 );
424
424
} // end if touching top/bottom
@@ -469,3 +469,27 @@ void clsCannonball::setSpin(double newspin) {
469
469
spin_ = newspin;
470
470
}
471
471
/* ****************************************************************************/
472
+ void clsCannonball::writeInfo () {
473
+ // ///////////////////////////////////////////////
474
+ // / @brief Writes information bout the ball to the console
475
+ // ///////////////////////////////////////////////
476
+
477
+ printf (" \n\n " );
478
+ printf (" Information about Ball: %i\n " ,ballID_);
479
+ printf (" Color: \t \t \t (%i, %i, %i)\n " ,color_.Red , color_.Green , color_.Blue );
480
+ printf (" Location: \t \t (%5.5f, %5.5f)\n " ,dblLOC_.x ,dblLOC_.y );
481
+ printf (" Velocity: \t \t (%5.5f, %5.5f)\n " ,vel_.x ,vel_.y );
482
+ printf (" Acceleration: \t \t (%5.5f, %5.5f)\n " ,acc_.x ,acc_.y );
483
+ printf (" Forces: \t \t (%5.5f, %5.5f)\n " , forces_.x , forces_.y );
484
+ printf (" Spin: \t \t \t (%5.5f)\n\n\n " , spin_);
485
+
486
+ }
487
+ /* ****************************************************************************/
488
+ void clsCannonball::togglePause () {
489
+ // ///////////////////////////////////////////////
490
+ // / @brief Enable/disable pause
491
+ // ///////////////////////////////////////////////
492
+
493
+ paused_ = !(paused_);
494
+ }
495
+ /* ****************************************************************************/
0 commit comments