Skip to content

Commit d317c02

Browse files
author
GamerMan7799
committed
Update to v1.4.0-beta.5
### Updated * Finished Drag tool * Various code improvements
1 parent 8559df6 commit d317c02

File tree

10 files changed

+215
-121
lines changed

10 files changed

+215
-121
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ FolderName\SDL2.dll
3838
FolderName\SDL2_image.dll
3939
```
4040

41-
If you are using the verision I complie, which can be found in the [release tab](https://github.com/Dragon-Wonder/Physics-Collision-Simulator/releases)
41+
If you are using the verision I compile, which can be found in the [release tab](https://github.com/Dragon-Wonder/Physics-Collision-Simulator/releases)
4242
you will also need the following binaries.
4343

4444
```
@@ -143,6 +143,6 @@ Clicking on a ball will delete it.
143143

144144
Clicking and dragging on a ball will allow you to move a ball where the mouse is. When released the ball will still have its inital velocity.
145145

146-
### Info Tool - WIP
146+
### Info Tool
147147

148148
Clicking on a ball will write infomation about it to the console

docs/ChangesLog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
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.4] - WIP
6+
## [1.4.0-beta.5] - WIP
77
### Added
88
* Toolbar with different tools including: drag, fire, drop, rope, delete, and info. Not all are fully working at the moment.
9-
* Currently finished tools: fire, drop, delete, info
9+
* Currently finished tools: fire, drag, drop, delete, and info.
1010
* SDL Licenses.
1111
* Credits to Docs.
1212
* More Doxygen stuff.
13-
* Debug message that prints ball mass.
13+
* Debug message that prints ball mass when created.
1414
* Ability to pause the simulation.
1515

1616
### Changed

project/Physics-Simulator.cbp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Build>
1010
<Target title="Debug-Windows">
1111
<Option platforms="Windows;" />
12-
<Option output="../Physics-Simulator-PRIVATE" prefix_auto="1" extension_auto="1" />
12+
<Option output="../Physics-Simulator-DEBUG" prefix_auto="1" extension_auto="1" />
1313
<Option working_dir="../" />
1414
<Option object_output="obj/Debug/" />
1515
<Option type="1" />
@@ -65,7 +65,7 @@
6565
</Target>
6666
<Target title="Debug-Linux">
6767
<Option platforms="Unix;" />
68-
<Option output="../Physics-Simulator-PRIVATE" prefix_auto="1" extension_auto="1" />
68+
<Option output="../Physics-Simulator-DEBUG" prefix_auto="1" extension_auto="1" />
6969
<Option working_dir="../" />
7070
<Option object_output="obj/Debug/" />
7171
<Option type="1" />

res/boilerplate.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
id ICON "Icon_App.ico"
33
/**********************************************************************************************************************************************/
44
#include <windows.h>
5-
//#include <string>
65
#include "../src/version.h"
76
/**********************************************************************************************************************************************/
87
//General stuff that should need to be changed
98
#define VER_COMPANYNAME_STR "Public Domain"
109
#define VER_FILEDESCRIPTION_STR "A simple program that stimulates collisions between different objects"
1110
#define VER_FILENAME_STR "SDL Physics Simulation"
12-
#define VER_ORIGINALFILENAME_STR "Physics-Simulation.exe"
1311
#define VER_LEGALCOPYRIGHT_STR "http://unlicense.org"
1412
#define VER_COMMENTS_STR "Source Code found at: https://github.com/Dragon-Wonder/Physics-Collision-Simulator"
1513
/**********************************************************************************************************************************************/
1614
//If Private is define above, indicting that it was a build not meant to be released define these variables
1715
#ifndef DEFINED_BUILD_MODE_PRIVATE
16+
#define VER_ORIGINALFILENAME_STR "Physics-Simulation.exe"
1817
#define VER_DEBUG 0
1918
#define VER_PRIVATEBUILD 0
2019
#define VER_PRERELEASE 0
2120
#else
21+
#define VER_ORIGINALFILENAME_STR "Physics-Simulation-DEBUG.exe"
2222
#define VER_DEBUG VS_FF_DEBUG
2323
#define VER_PRIVATEBUILD VS_FF_PRIVATEBUILD
2424
#define VER_PRERELEASE VS_FF_PRERELEASE

src/cannonball.cpp

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -151,61 +151,63 @@ void clsCannonball::update(double newdeltat) {
151151
///
152152
/////////////////////////////////////////////////
153153

154+
blncheckphysics_ = true; // enable on update
154155
if (!paused_) {
155-
blncheckphysics_ = true; // enable on update
156+
156157
deltat_ = newdeltat;
157158

158159
// reset the forces so strange things don't happen
159160
forces_ = {0.0, props_.mass * global::physics::kGravity};
160161

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-
173162
// get new velocities if collision with edges
174163
double coefres = (global::config.values.uchrCollisionMethod == CollideInelastic) ?
175164
global::physics::kCoefficientRestitution : 1.0;
176165

177166
if (collisionbox_.left < screen_place_.w / 2) {
178167
vel_.x *= -1 * coefres;
179168
vel_.y *= coefres;
169+
forces_.x -= props_.mass * global::physics::kGravity;
180170
dblLOC_.x = screen_place_.w;
181171
}
182172

183173
if (collisionbox_.right > (screen::screenatt.width)) {
184174
vel_.x *= -1 * coefres;
185175
vel_.y *= coefres;
176+
forces_.x += props_.mass * global::physics::kGravity;
186177
dblLOC_.x = screen::screenatt.width - screen_place_.w / 2;
187178
}
188179

189180
if (collisionbox_.bottom > (screen::screenatt.height)) {
190181
vel_.x *= coefres;
191182
vel_.y *= -1 * coefres;
183+
forces_.y -= props_.mass * global::physics::kGravity;
192184
dblLOC_.y = screen_place_.h / 2;
193185
}
194186

195187
if (collisionbox_.top < 0 ) {
196188
vel_.x *= coefres;
197189
vel_.y *= -1 * coefres;
190+
forces_.y += props_.mass * global::physics::kGravity;
198191
dblLOC_.y = (screen::screenatt.height) - screen_place_.h / 2;
199192
}
200193

194+
if (blndragenabled_) {
195+
doMagnusEffect();
196+
dragUpdateAcc();
197+
}
198+
doFriction();
199+
200+
acc_.x = forces_.x / props_.mass;
201+
acc_.y = forces_.y / props_.mass;
202+
203+
vel_.x = (vel_.x + acc_.x * deltat_);
204+
vel_.y = (vel_.y + acc_.y * deltat_);
205+
206+
207+
201208
dblLOC_.x = dblLOC_.x + vel_.x * deltat_ /*+ 0.5 * acc_.x * pow(deltat_,2)*/;
202209
dblLOC_.y = dblLOC_.y + vel_.y * deltat_ /*+ 0.5 * acc_.y * pow(deltat_,2)*/;
203210

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-
209211
if (global::config.values.blnLogging) {
210212
FILE* logfile = fopen("logfile.log","a");
211213
fprintf(logfile,"Ball %3u \t (%.3f, %.3f)\n",ballID_, dblLOC_.x,dblLOC_.y);
@@ -222,6 +224,7 @@ void clsCannonball::update(double newdeltat) {
222224
} //end if debug mode
223225
} //end if should kill
224226
} // end if not paused
227+
updateCollisionBox();
225228
show(); //show the ball on the screen
226229
}
227230
/*****************************************************************************/
@@ -299,6 +302,7 @@ void clsCannonball::setValues(double r, LOC init_place,
299302
blnstarted_ = true;
300303

301304
dragCalcValues();
305+
updateCollisionBox();
302306

303307

304308
forces_ = {0.00, global::physics::kGravity * props_.mass};
@@ -394,6 +398,10 @@ void clsCannonball::updateCollisionBox() {
394398
/// @brief Updates the collision box
395399
/////////////////////////////////////////////////
396400

401+
// update place and collision box again in case something changed
402+
place_.x = round(dblLOC_.x);
403+
place_.y = round(dblLOC_.y);
404+
397405
//Update the collision box for the new location
398406
collisionbox_.left = place_.x - floor(screen_place_.w / 2);
399407
collisionbox_.top = screen::screenatt.height - (place_.y + floor(screen_place_.h / 2));
@@ -417,24 +425,10 @@ void clsCannonball::doFriction() {
417425
normal_force;
418426
updateCollisionBox();
419427
//Update acc for Friction values
420-
if ( collisionbox_.bottom <= screen_place_.h ||
421-
collisionbox_.top >= screen::screenatt.height ) {
422-
//Ball is in contact with floor or ceiling update x acc
428+
if ( collisionbox_.bottom <= screen_place_.h ) {
429+
//Ball is in contact with floor
423430
forces_.x += friction * (vel_.x < 0.0 ? -1.0 : 1.0);
424-
} // end if touching top/bottom
425-
426-
427-
// Since there really isn't a normal force when the ball contacts
428-
// the edges, this section is commented out.
429-
/*
430-
if ( collisionbox_.left < (screen_place_.w /2 ) ||
431-
collisionbox_.right > screen::screenatt.width ) {
432-
// Ball is in contact with the wall update y acc.
433-
forces_.y += friction * (vel_.y < 0.0 ? -1.0 : 1.0);
434-
// add normal force
435-
forces_.x += normal_force * (collisionbox_.right > screen::screenatt.width) ?
436-
1.0 : -1.0;
437-
} // end if touching side edges */
431+
}
438432
}
439433
/*****************************************************************************/
440434
void clsCannonball::doMagnusEffect() {
@@ -493,3 +487,11 @@ void clsCannonball::togglePause() {
493487
paused_ = !(paused_);
494488
}
495489
/*****************************************************************************/
490+
bool clsCannonball::isPaused() {
491+
/////////////////////////////////////////////////
492+
/// @brief Returns if paused or not
493+
/////////////////////////////////////////////////
494+
495+
return paused_;
496+
}
497+
/*****************************************************************************/

src/cannonball.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class clsCannonball {
8484
double getSpin(void);
8585
void writeInfo(void);
8686
void togglePause(void);
87+
bool isPaused(void);
8788
bool blnstarted_; /**< Whether or not the ball is "started" if it is, the program will update
8889
it and won't let a new ball replace it in its array spot. */
8990

0 commit comments

Comments
 (0)