Skip to content

Commit d5c1bac

Browse files
author
Patrick Rye
committed
Update to v1.1.9-Beta
16 September 2015 Released version 1.1.9-Beta Change log: -Added: Cannonballs now keep track of ID for logging purposes -Fixed: Log file is now cleared at start -Added: Clearer Debug Message if a ball was killed because of speed or NaN -Added: Unrealistic method where velocity is modified with the inverse root of the distance between the points (this was an attempt to prevent the balls from sticking together as they have been)
1 parent 82dbea2 commit d5c1bac

File tree

5 files changed

+70
-22
lines changed

5 files changed

+70
-22
lines changed

ChangesLog.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
16 September 2015
2+
Released version 1.1.9-Beta
3+
4+
Change log:
5+
-Added: Cannonballs now keep track of ID for logging purposes
6+
-Fixed: Log file is now cleared at start
7+
-Added: Clearer Debug Message if a ball was killed because of speed or NaN
8+
-Added: Unrealistic method where velocity is modified with the inverse root of the distance between the points
9+
(this was an attempt to prevent the balls from sticking together as they have been)
10+
11+
112
16 September 2015
213
Released version 1.1.8-Beta
314

415
Change log:
5-
-Added: More collision methods (Inelastic, Elastic, Perfect Inelastic, and No Collisons)
16+
-Added: More collision methods (Inelastic, Elastic, Perfect Inelastic, and No Collisions)
617
-Improved: Collision equations
718
-Fixed: You can now properly fire a cannonball in all directions
819
-Fixed: Balls that have velocity as NaN will be removed
@@ -12,7 +23,7 @@
1223
Released version 1.1.7-Beta
1324

1425
Change log:
15-
-Added: Collisons
26+
-Added: Collisions
1627
-Fixed: Bug with mouse keeping old coordinates
1728
-Fixed: X Fire velocity not being right
1829

@@ -25,7 +36,7 @@
2536
-Note: Currently the array holding multiple cannonball is NOT dynamic I still have to figure that out.
2637
-Removed: Ball position updating on debug mode (too many balls)
2738
-Fixed: Bug with balls not correctly bouncing at certain velocities
28-
-Updated: Ball will now be removed if thier velocity drops below a certain value.
39+
-Updated: Ball will now be removed if their velocity drops below a certain value.
2940

3041
15 September 2015
3142
Released version 1.1.5-Beta
@@ -99,7 +110,7 @@
99110

100111
Change log:
101112
-Added: Config file
102-
-Applied: Software state being added to boilerplater
113+
-Applied: Software state being added to boilerplate
103114
-Added: Logging of ball location to a file
104115
-Applied: Easier way to change images path (config file)
105116

src/cannonball.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ void clsCannonball::update(double newdeltat) {
6161
dblLOC.x = dblLOC.x + vel.x * deltat + 0.5 * acc.x * pow(deltat,2);
6262
vel.x = (vel.x + acc.x * deltat);
6363
if (dblLOC.x <= 0.0 || dblLOC.x >= window.width - dst.w) {
64-
vel.x *= Global::Physics::fRecoil;
65-
if (dblLOC.x <= 0.0) {dblLOC.x++;}
66-
else {dblLOC.x--;}
64+
vel.x *= Global::Physics::fRecoil;
65+
if (dblLOC.x <= 0.0) {dblLOC.x++;}
66+
else {dblLOC.x--;}
6767
} //end if hitting x edges
6868
dblLOC.y = dblLOC.y + vel.y * deltat + 0.5 * acc.y * pow(deltat,2);
6969
vel.y = (vel.y + acc.y * deltat);
7070
if (dblLOC.y <= dst.h || dblLOC.y >= window.height) {
71-
vel.y *= Global::Physics::fRecoil;
72-
if (dblLOC.y <= dst.h) {dblLOC.y++;}
73-
else {dblLOC.y--;}
71+
vel.y *= Global::Physics::fRecoil;
72+
if (dblLOC.y <= dst.h) {dblLOC.y++;}
73+
else {dblLOC.y--;}
7474
}//end if hitting y edges
7575

7676
if (dblLOC.x < 0.0) {place.x = 0;}
@@ -82,16 +82,19 @@ void clsCannonball::update(double newdeltat) {
8282
//if (Global::blnDebugMode) {printf("Ball updated, new position (%f, %f)\n",dblLOC.x,dblLOC.y);}
8383
if (Global::Config.values.blnLogging) {
8484
FILE* logfile = fopen("logfile.log","a");
85-
fprintf(logfile,"(%.5f, %.5f)\n",dblLOC.x,dblLOC.y);
85+
fprintf(logfile,"Ball %3u \t (%.3f, %.3f)\n",ballID, dblLOC.x,dblLOC.y);
8686
fclose(logfile);
8787
}
8888

8989
double total_v;
9090
total_v = sqrt( pow(vel.x,2) + pow(vel.y,2) );
9191
if (total_v < Global::Physics::fMinVelocity || isnan(total_v) ) {
92-
blnstarted = false;
93-
if (Global::blnDebugMode) {printf("Ball moving too slow; killing it\n");}
94-
}
92+
blnstarted = false;
93+
if (Global::blnDebugMode) {
94+
if ( isnan(total_v) ) {printf("Ball vel is Nan; killing it\n");}
95+
else {printf("Ball moving too slow; killing it\n");}
96+
} //end if debug mode
97+
} //end if should kill
9598
show();
9699
}
97100
/**********************************************************************************************************************************************/
@@ -109,7 +112,7 @@ void clsCannonball::show() {
109112
SDL_RenderCopy(window.ren,ball,NULL,&dst);
110113
}
111114
/**********************************************************************************************************************************************/
112-
void clsCannonball::setValues(double r, LOC init_place, double init_vel, double init_angle) {
115+
void clsCannonball::setValues(double r, LOC init_place, double init_vel, double init_angle, uint ID) {
113116
props.radius = r; //in meters
114117
props.density = Global::Physics::uBallDensity; //density of steel in kg/m^3
115118

@@ -119,8 +122,11 @@ void clsCannonball::setValues(double r, LOC init_place, double init_vel, double
119122

120123
vel.x = (double)(init_vel) * (cos(init_angle * Rad_Convert));
121124
vel.y = (double)(init_vel) * (sin(init_angle * Rad_Convert));
125+
126+
ballID = ID;
122127
blnstarted = true;
123128

129+
124130
if (Global::Config.values.blnDragMode) { enableDrag(); }
125131
}
126132
/**********************************************************************************************************************************************/

src/cannonball.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class clsCannonball {
3030
public:
3131
/** Default constructor */
3232
clsCannonball();
33-
void setValues(double, LOC, double, double);
33+
void setValues(double, LOC, double, double, uint);
3434
LOC getplace(void);
3535
void setplace(LOC);
3636

@@ -43,6 +43,7 @@ class clsCannonball {
4343

4444
bool blnstarted;
4545
private:
46+
uint ballID;
4647
bool blnDragEnabled;
4748

4849
SDL_Texture* ball;

src/main.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ SDL_Texture* tempball;
6060
/**********************************************************************************************************************************************************************/
6161
int main(int argc, char *argv[]) {
6262
Global::Config.Check(); //Load Config file and all its values.
63+
if (Global::Config.values.blnLogging) { //Open log file to clear it, if it exists
64+
FILE* logfile = fopen("logfile.log","w");
65+
fclose(logfile);
66+
}
6367

6468
if (Global::blnDebugMode) {printf("OS: %s\n",Global::Config.values.OperatingSystem);}
6569
clsTick Tick; //create tick object
@@ -139,7 +143,7 @@ void addNewCannonball(LOC mouseC, LOC mouseO ) {
139143
//loop through array to find next available cannonball slot
140144
for (uint i = 0; i < DEFINED_CANNONBALL_LIMIT; i++) {
141145
if (!Cannonballs[i].blnstarted) {
142-
Cannonballs[i].setValues(2.0, mouseO, fire_v, angle);
146+
Cannonballs[i].setValues(2.0, mouseO, fire_v, angle, i);
143147
Cannonballs[i].setSDLScreen(tempball, tempwin);
144148
return;
145149
} //end if not started
@@ -179,6 +183,32 @@ void doCollision(uint numA, uint numB) {
179183
Aprops = Cannonballs[numA].getPhysicalProps();
180184
Bprops = Cannonballs[numB].getPhysicalProps();
181185

186+
//This part here has no actual basis on real life,
187+
//it is just my attempt at preventing the cannonballs from sticking together
188+
LOC CenterA, CenterB, DeltaCenters;
189+
double VelModder;
190+
CenterA = Cannonballs[numA].getplace();
191+
CenterB = Cannonballs[numB].getplace();
192+
193+
CenterA.x += 5;
194+
CenterA.y += 5;
195+
CenterB.x += 5;
196+
CenterB.y += 5;
197+
198+
DeltaCenters.x = abs(CenterA.x - CenterB.x);
199+
DeltaCenters.y = abs(CenterA.y - CenterB.y);
200+
//Since it is r^2 and the sqrt of this give us r, we just drop the sqrt part to save time
201+
VelModder = pow((double)DeltaCenters.x,2) + pow((double)DeltaCenters.y,2);
202+
VelModder = 200.0 / VelModder; //200 is the highest value possible
203+
if (VelModder < 1.0) {VelModder = 1.0;}
204+
//else if (VelModder > 0.05) {VelModder = 0.05;}
205+
206+
Avel.x *= (double) VelModder;
207+
Avel.y *= (double) VelModder;
208+
Bvel.x *= (double) VelModder;
209+
Bvel.y *= (double) VelModder;
210+
//End of non real stuff
211+
182212
double Aangle, Bangle, ContactAngle;
183213
double Atotal_v, Btotal_v;
184214

src/version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
//Standard Version Type
1515
#define DEFINED_VER_MAJOR 1
1616
#define DEFINED_VER_MINOR 1
17-
#define DEFINED_VER_BUILD 8
17+
#define DEFINED_VER_BUILD 9
1818
#define DEFINED_VER_REVISION 1
1919

2020
//Miscellaneous Version Types
21-
#define DEFINED_VER_BUILDS_COUNT 0
22-
#define DEFINED_VER_RC_FILEVERSION 1,1,8,1
23-
#define DEFINED_VER_RC_FILEVERSION_STRING "1, 1, 8, 1\0"
24-
#define DEFINED_VER_FULLVERSION_STRING "1.1.8.1"
21+
#define DEFINED_VER_BUILDS_COUNT 22
22+
#define DEFINED_VER_RC_FILEVERSION 1,1,9,1
23+
#define DEFINED_VER_RC_FILEVERSION_STRING "1, 1, 9, 1\0"
24+
#define DEFINED_VER_FULLVERSION_STRING "1.1.9.1"
2525

2626
//These values are to keep track of your versioning state, don't modify them.
2727
#define DEFINED_VER_BUILD_HISTORY 1

0 commit comments

Comments
 (0)