Skip to content

Commit af759ba

Browse files
author
GamerMan7799
committed
Update to v1.4.0-RC.1
## [1.4.0-RC.1] ### Added * Toolbar with different tools including: drag, fire, drop, rope, delete, and info. (Issue #5) * Changable Ratio of meters to Pixels (default is 10 pixels/meter) ### Changed * Disabled rope tool, still need to work on some of the equations. (Issue #4) * Reduced kVelocityScalar from 1 -> 0.1 * Floors to casts (due to large number of calls of the floor functions). ### Removed * Interia/engergy from spins, because it did nothing. ### Fixed * Bug of balls getting stuck in walls. * Bug of balls velocity becoming NaN. (Issue #3)
1 parent f372e22 commit af759ba

File tree

13 files changed

+202
-190
lines changed

13 files changed

+202
-190
lines changed

LICENSE.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/ChangesLog.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,33 @@
33
All notable changes to this project will be documented here.
44
This project adheres to [Semantic Versioning](http://semver.org/)
55

6-
## [1.4.0-beta.6] - WIP
6+
## [1.4.0-RC.1] - WIP
77
### Added
8-
* Toolbar with different tools including: drag, fire, drop, rope, delete, and info. Not all are fully working at the moment.
8+
* Toolbar with different tools including: drag, fire, drop, rope, delete, and info. (Issue #5)
99
* Currently finished tools: fire, drag, drop, delete, and info.
10-
* Rope tool now creates rope between two balls or ball and wall. (Does nothing else at the moment)
1110
* SDL Licenses.
1211
* Credits to Docs.
1312
* More Doxygen stuff.
1413
* Debug message that prints ball mass when created.
1514
* Ability to pause the simulation.
15+
* Changable Ratio of meters to Pixels (default is 10 pixels/meter)
1616

1717
### Changed
1818
* Moved Docs to Doc folder.
1919
* Moved various items out of main.cpp into core.cpp to avoid main becoming too large.
2020
* How balls are updated (order and a few equations) to make it hopefully more realistic.
21+
* Increased ball size from 10x10 pixels to 25x25 pixels.
22+
* Various code improvements.
23+
* Disabled rope tool, still need to work on some of the equations. (Issue #4)
24+
* Reduced kVelocityScalar from 1 -> 0.1
25+
* Floors to casts (due to large number of calls of the floor functions).
2126

27+
### Removed
28+
* Interia/engergy from spins, because it did nothing.
2229

23-
### Updated
24-
* Various code improvements.
25-
* Increased ball size from 10x10 pixels to 25x25 pixels.
30+
### Fixed
31+
* Bug of balls getting stuck in walls.
32+
* Bug of balls velocity becoming NaN. (Issue #3)
2633

2734
## [1.3.1-R] - 2018-03-16
2835
### Added

project/Physics-Simulator.cbp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
<lib_finder disable_auto="1" />
169169
<DoxyBlocks>
170170
<comment_style block="5" line="0" />
171-
<doxyfile_project project_number="v1.4.0-beta.2" output_directory="gh-pages" />
171+
<doxyfile_project project_number="v1.4.0-R" output_directory="gh-pages" />
172172
<doxyfile_build extract_all="1" />
173173
<doxyfile_warnings />
174174
<doxyfile_output />

src/cannonball.cpp

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ clsCannonball::clsCannonball() {
2828
deltat_ = (1.00 / 60.00);
2929
forces_ = {0,0};
3030
acc_ = {0.00, global::physics::kGravity};
31-
spin_ = 1.0;
3231

3332
props_.radius = 5.0; //in meters
3433
props_.density = global::physics::kBallDensity; //density of steel in kg/m^3
@@ -156,13 +155,6 @@ void clsCannonball::update(double newdeltat) {
156155

157156
deltat_ = newdeltat;
158157

159-
if (blndragenabled_) {
160-
doMagnusEffect();
161-
dragUpdateAcc();
162-
}
163-
doFriction();
164-
checkEdges();
165-
166158
acc_.x = forces_.x / props_.mass;
167159
acc_.y = forces_.y / props_.mass;
168160

@@ -172,6 +164,8 @@ void clsCannonball::update(double newdeltat) {
172164
dblLOC_.x += vel_.x * deltat_ /*+ 0.5 * acc_.x * pow(deltat_,2)*/;
173165
dblLOC_.y += vel_.y * deltat_ /*+ 0.5 * acc_.y * pow(deltat_,2)*/;
174166

167+
setEdgePosition();
168+
175169
if (global::config.values.blnLogging) {
176170
FILE* logfile = fopen("logfile.log","a");
177171
fprintf(logfile,"Ball %3u \t (%.3f, %.3f)\n",ballID_, dblLOC_.x,dblLOC_.y);
@@ -191,7 +185,6 @@ void clsCannonball::update(double newdeltat) {
191185
updateCollisionBox();
192186
show(); //show the ball on the screen
193187
// reset the forces so strange things don't happen
194-
forces_ = {0.0, props_.mass * global::physics::kGravity};
195188
}
196189
/*****************************************************************************/
197190
void clsCannonball::show() {
@@ -256,12 +249,9 @@ void clsCannonball::setValues(double r, LOC init_place,
256249

257250
acc_ = {0.00, global::physics::kGravity};
258251

259-
spin_ = (rand() % 1000 - 500) / 500;
260-
261-
262252
place_ = init_place;
263-
dblLOC_ = { (double) place_.x,
264-
(double) place_.y };
253+
dblLOC_ = { (double) place_.x / global::physics::kMeterPixelRatio,
254+
(double) place_.y / global::physics::kMeterPixelRatio};
265255

266256
vel_ = { (double)(init_vel) * (cos(init_angle)),
267257
(double)(init_vel) * (sin(init_angle)) };
@@ -307,8 +297,8 @@ void clsCannonball::setplace(LOC newplace) {
307297
/////////////////////////////////////////////////
308298
/// @brief Set the ball's place
309299
/////////////////////////////////////////////////
310-
dblLOC_.x = (double)newplace.x;
311-
dblLOC_.y = (double)newplace.y;
300+
dblLOC_.x = (double)newplace.x / global::physics::kMeterPixelRatio;
301+
dblLOC_.y = (double)newplace.y / global::physics::kMeterPixelRatio;
312302
}
313303
/*****************************************************************************/
314304
void clsCannonball::setPhysicalProps(PP newprops) {
@@ -365,12 +355,12 @@ void clsCannonball::updateCollisionBox() {
365355
/////////////////////////////////////////////////
366356

367357
// update place and collision box again in case something changed
368-
place_.x = round(dblLOC_.x);
369-
place_.y = round(dblLOC_.y);
358+
place_.x = round(dblLOC_.x * global::physics::kMeterPixelRatio);
359+
place_.y = round(dblLOC_.y * global::physics::kMeterPixelRatio);
370360

371361
//Update the collision box for the new location
372-
collisionbox_.left = place_.x - floor(screen_place_.w / 2);
373-
collisionbox_.top = screen::screenatt.height - (place_.y + floor(screen_place_.h / 2));
362+
collisionbox_.left = place_.x - (int)(screen_place_.w / 2);
363+
collisionbox_.top = screen::screenatt.height - (place_.y + (int)(screen_place_.h / 2));
374364
collisionbox_.bottom = collisionbox_.top + screen_place_.h;
375365
collisionbox_.right = collisionbox_.left + screen_place_.w;
376366
}
@@ -392,38 +382,12 @@ void clsCannonball::doFriction() {
392382
}
393383
}
394384
/*****************************************************************************/
395-
void clsCannonball::doMagnusEffect() {
396-
/////////////////////////////////////////////////
397-
/// @brief Calculates the Magnus Effect caused by the ball's spin
398-
/////////////////////////////////////////////////
399-
400-
double magnus_force = pow(M_PI,2) * pow(props_.radius,3) *
401-
global::physics::kDensityAir;
402-
403-
forces_.x -= magnus_force * vel_.y * spin_;
404-
forces_.y += magnus_force * vel_.x * spin_;
405-
}
406-
/*****************************************************************************/
407385
void clsCannonball::addForce(dblXY newforces) {
408386

409387
forces_.x += newforces.x;
410388
forces_.y += newforces.y;
411389
}
412390
/*****************************************************************************/
413-
double clsCannonball::getSpin() {
414-
/////////////////////////////////////////////////
415-
/// @brief Returns the ball's spin
416-
/////////////////////////////////////////////////
417-
return spin_;
418-
}
419-
/*****************************************************************************/
420-
void clsCannonball::setSpin(double newspin) {
421-
/////////////////////////////////////////////////
422-
/// @brief Sets the ball's spin
423-
/////////////////////////////////////////////////
424-
spin_ = newspin;
425-
}
426-
/*****************************************************************************/
427391
void clsCannonball::writeInfo() {
428392
/////////////////////////////////////////////////
429393
/// @brief Writes information bout the ball to the console
@@ -436,7 +400,6 @@ void clsCannonball::writeInfo() {
436400
printf("Velocity: \t \t (%5.5f, %5.5f)\n",vel_.x,vel_.y);
437401
printf("Acceleration: \t \t (%5.5f, %5.5f)\n",acc_.x,acc_.y);
438402
printf("Forces: \t \t (%5.5f, %5.5f)\n", forces_.x, forces_.y);
439-
printf("Spin: \t \t \t (%5.5f)\n\n\n", spin_);
440403

441404
}
442405
/*****************************************************************************/
@@ -462,20 +425,16 @@ LOC clsCannonball::getScreenPlace() {
462425
/////////////////////////////////////////////////
463426
LOC temp;
464427
temp.x = screen_place_.x;
465-
temp.x += floor (screen_place_.w/2);
428+
temp.x += (int)(screen_place_.w/2);
466429
temp.y = screen_place_.y;
467-
temp.y += floor(screen_place_.h/2);
430+
temp.y += (int)(screen_place_.h/2);
468431
return temp;
469432
}
470433
/*****************************************************************************/
471434
void clsCannonball::checkEdges() {
472435
/////////////////////////////////////////////////
473436
/// @brief Checks and does stuff if ball is colliding with edges.
474437
/////////////////////////////////////////////////
475-
476-
/** @bug (GamerMan7799#1#): Balls appear to bounce forever because position is updated again after
477-
running this function. */
478-
479438
// get new velocities if collision with edges
480439
double coefres = (global::config.values.uchrCollisionMethod == CollideInelastic) ?
481440
global::physics::kCoefficientRestitution : 1.0;
@@ -484,28 +443,71 @@ void clsCannonball::checkEdges() {
484443
vel_.x *= -1 * coefres;
485444
vel_.y *= coefres;
486445
forces_.x = 0;
487-
dblLOC_.x = screen_place_.w + 1;
488446
}
489447

490448
if (collisionbox_.right > (screen::screenatt.width)) {
491449
vel_.x *= -1 * coefres;
492450
vel_.y *= coefres;
493451
forces_.x = 0;
494-
dblLOC_.x = screen::screenatt.width - screen_place_.w / 2 - 1;
495452
}
496453

497454
if (collisionbox_.bottom > (screen::screenatt.height)) {
498455
vel_.x *= coefres;
499456
vel_.y *= -1 * coefres;
500457
forces_.y = 0;
501-
dblLOC_.y = screen_place_.h / 2 + 1;
502458
}
503459

504460
if (collisionbox_.top < 0 ) {
505461
vel_.x *= coefres;
506462
vel_.y *= -1 * coefres;
507463
forces_.y = 2 * props_.mass * global::physics::kGravity;
508-
dblLOC_.y = (screen::screenatt.height) - screen_place_.h / 2 - 1;
509464
}
510465
}
511466
/*****************************************************************************/
467+
void clsCannonball::setEdgePosition() {
468+
/////////////////////////////////////////////////
469+
/// @brief Set position if colliding with edges
470+
/////////////////////////////////////////////////
471+
472+
if (collisionbox_.left < screen_place_.w / 2) {
473+
dblLOC_.x = (screen_place_.w + 1);
474+
dblLOC_.x /= global::physics::kMeterPixelRatio;
475+
}
476+
477+
if (collisionbox_.right > (screen::screenatt.width)) {
478+
dblLOC_.x = (screen::screenatt.width - screen_place_.w / 2 - 1);
479+
dblLOC_.x /= global::physics::kMeterPixelRatio;
480+
}
481+
482+
if (collisionbox_.bottom > (screen::screenatt.height)) {
483+
dblLOC_.y = (screen_place_.h / 2 + 1 );
484+
dblLOC_.y /= global::physics::kMeterPixelRatio;
485+
}
486+
487+
if (collisionbox_.top < 0 ) {
488+
dblLOC_.y = ((screen::screenatt.height) - screen_place_.h / 2 - 1);
489+
dblLOC_.y /= global::physics::kMeterPixelRatio;
490+
}
491+
}
492+
/*****************************************************************************/
493+
dblXY clsCannonball::getForces() {
494+
/////////////////////////////////////////////////
495+
/// @brief Returns forces on ball.
496+
/////////////////////////////////////////////////
497+
498+
return forces_;
499+
}
500+
/*****************************************************************************/
501+
void clsCannonball::updateForces() {
502+
/////////////////////////////////////////////////
503+
/// @brief Updates all the forces on the ball.
504+
/////////////////////////////////////////////////
505+
506+
forces_ = {0,props_.mass * global::physics::kGravity};
507+
508+
if (blndragenabled_) { dragUpdateAcc(); }
509+
doFriction();
510+
checkEdges();
511+
512+
}
513+
/*****************************************************************************/

src/cannonball.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,19 @@ class clsCannonball {
7575
LOC getplace(void);
7676
LOC getScreenPlace(void);
7777
void setplace(LOC);
78-
void setSpin(double);
7978
void update(double);
79+
void updateForces(void);
8080
dblXY getVelocity(void);
81+
dblXY getForces(void);
8182
void setVelocity(dblXY);
8283
PP getPhysicalProps(void);
8384
void setPhysicalProps(PP);
8485
BOX getBOX(void);
85-
double getSpin(void);
8686
void writeInfo(void);
8787
void togglePause(void);
8888
bool isPaused(void);
8989
void checkEdges(void);
90+
void setEdgePosition(void);
9091
bool blnstarted_; /**< Whether or not the ball is "started" if it is, the program will update
9192
it and won't let a new ball replace it in its array spot. */
9293

@@ -114,7 +115,6 @@ class clsCannonball {
114115
the movements looking realistic. See clsTick::getTimeDifference */
115116

116117
dblXY forces_; /**< Forces on the ball in x and y */
117-
double spin_; /**< The angular velocity of the ball (in rad/s) for the Magnus Effect */
118118
bool paused_; /**< If the simulation is paused or not. */
119119

120120
void show(void);
@@ -123,7 +123,6 @@ class clsCannonball {
123123
void dragUpdateAcc(void);
124124
void doFriction(void);
125125
void updateCollisionBox(void);
126-
void doMagnusEffect(void);
127126
};
128127
/*****************************************************************************/
129128
#endif // __CANNONBALL_HEADER__

0 commit comments

Comments
 (0)