Skip to content

Commit 105c6b9

Browse files
author
Patrick Rye
committed
Update to v1.2.3-beta
21 September 2015 Released version 1.2.3-Beta Change log: -Removed: Sky image (replaced with SDL_SetRenderDrawColor) -Added: Cannonballs are now more transparent the less mass they have -Removed: My attempt at making parts of the ball image transparent (it wasn't working) -Changed: Reduced fTimetoSizeRatio from 1.2458 to 0.0124 -Added: Namespace Equations to hold equation values -Changed: Screen background color from White to Black -Changed: Ball color from Black to White -Changed: Pixel color from Black to White -Added: Ball Path is now drawn on screen (holds so many past points, can be enabled in config file)
1 parent c833113 commit 105c6b9

File tree

14 files changed

+141
-147
lines changed

14 files changed

+141
-147
lines changed

ChangesLog.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
21 September 2015
2+
Released version 1.2.3-Beta
3+
4+
Change log:
5+
-Removed: Sky image (replaced with SDL_SetRenderDrawColor)
6+
-Added: Cannonballs are now more transparent the less mass they have
7+
-Removed: My attempt at making parts of the ball image transparent (it wasn't working)
8+
-Changed: Reduced fTimetoSizeRatio from 1.2458 to 0.0124
9+
-Added: Namespace Equations to hold equation values
10+
-Changed: Screen background color from White to Black
11+
-Changed: Ball color from Black to White
12+
-Changed: Pixel color from Black to White
13+
-Added: Ball Path is now drawn on screen (holds so many past points, can be enabled in config file)
14+
115
18 September 2015
216
Released version 1.2.2-Beta
317

project/SDL-Cannon-Simulation.cbp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
<Unit filename="../src/global.h" />
136136
<Unit filename="../src/image_ball.xpm" />
137137
<Unit filename="../src/image_pixel.xpm" />
138-
<Unit filename="../src/image_sky.xpm" />
139138
<Unit filename="../src/main.cpp" />
140139
<Unit filename="../src/screen.cpp" />
141140
<Unit filename="../src/screen.h" />

src/cannonball.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,36 @@ void clsCannonball::update(double newdeltat) {
104104
if (total_v < Global::Physics::fMinVelocity || isnan(total_v) ) {
105105
blnstarted = false;
106106
if (Global::blnDebugMode) {
107-
if ( isnan(total_v) ) {printf("Ball vel is NaN; killing it\n");}
107+
if ( isnan(total_v) ) {printf("Ball velocity is NaN; killing it\n");}
108108
else {printf("Ball moving too slow; killing it\n");}
109109
} //end if debug mode
110110
} //end if should kill
111111
show();
112112
}
113113
/**********************************************************************************************************************************************/
114-
void clsCannonball::setSDLScreen(SDL_Texture* SDLball, WINATT SDLwindow) {
114+
void clsCannonball::setSDLScreen(SDL_Texture* SDLball, SDL_Texture* SDLpxel, WINATT SDLwindow) {
115115
ball = SDLball;
116+
pixel = SDLpxel;
116117
SDL_QueryTexture(ball,NULL,NULL, &Screen_place.w, &Screen_place.h);
117118
window = SDLwindow;
118119
}
119120
/**********************************************************************************************************************************************/
120121
void clsCannonball::show() {
121122
Screen_place.x = place.x;
122123
Screen_place.y = window.height - place.y;
124+
125+
if (Global::Config.values.blnDrawPathOnScreen) { drawPath(place); }
126+
127+
Uint8 alpha = 0xFF;
128+
double dblAlpha;
129+
130+
dblAlpha = (double) Global::Equations::fMassAlphaRatio * log(props.mass) + Global::Equations::fMassAlphaOffset;
131+
alpha = dblAlpha < (double) Global::Equations::uAlphaMinimum ? (Uint8) Global::Equations::uAlphaMinimum : (Uint8) dblAlpha;
132+
alpha = dblAlpha > 255.0 ? 255 : (Uint8) dblAlpha;
133+
134+
//set the ball alpha
135+
SDL_SetTextureAlphaMod(ball, alpha);
136+
123137
//Place the ball
124138
SDL_RenderCopy(window.ren,ball,NULL,&Screen_place);
125139
}
@@ -174,3 +188,25 @@ BOX clsCannonball::getBOX() {
174188
return CollisionBox;
175189
}
176190
/**********************************************************************************************************************************************/
191+
void clsCannonball::drawPath(LOC newplace) {
192+
static uint UpdatesSinceLast;
193+
194+
//If there have been enough updates since the last time the path was updated,
195+
//then update the path array otherwise inc updates
196+
if ( UpdatesSinceLast >= 25 ) {
197+
UpdatesSinceLast = 0;
198+
//First move all the old locations down one spot in the array
199+
for (uint i = 1; i < DEFINED_MAXNUMPASTPOINTS; i++) { path[i] = path[i-1]; }
200+
//Now put the new location into the latest spot
201+
path[0] = newplace;
202+
} else { UpdatesSinceLast++; } //end if update points
203+
//Now draw the path
204+
SDL_Rect dst;
205+
dst.w = dst.h = 1;
206+
for (uint i = 0; i < DEFINED_MAXNUMPASTPOINTS; i++) {
207+
dst.y = window.height - (uint)(path[i].y - Screen_place.h / 2);
208+
dst.x = (uint)(path[i].x + Screen_place.w / 2);
209+
SDL_RenderCopy(window.ren, pixel, NULL, &dst);
210+
} //end for
211+
}
212+
/**********************************************************************************************************************************************/

src/cannonball.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "screen.h"
1111
/**********************************************************************************************************************************************/
1212
#define PI 3.1415926535897
13+
#define DEFINED_MAXNUMPASTPOINTS 5
1314
/**********************************************************************************************************************************************/
1415
struct stcDoubleValues {
1516
double x;
@@ -44,7 +45,7 @@ class clsCannonball {
4445
void setplace(LOC);
4546

4647
void update(double);
47-
void setSDLScreen(SDL_Texture*, WINATT);
48+
void setSDLScreen(SDL_Texture*, SDL_Texture*, WINATT);
4849
dblXY getVelocity(void);
4950
void setVelocity(dblXY);
5051
PP getPhysicalProps(void);
@@ -57,6 +58,7 @@ class clsCannonball {
5758
bool blnDragEnabled;
5859

5960
SDL_Texture* ball;
61+
SDL_Texture* pixel;
6062
WINATT window;
6163

6264
BOX CollisionBox;
@@ -68,9 +70,12 @@ class clsCannonball {
6870
dblXY acc;
6971
PP props;
7072

73+
LOC path[DEFINED_MAXNUMPASTPOINTS];
74+
7175
void enableDrag(void);
7276
double deltat;
7377
void show(void);
78+
void drawPath(LOC);
7479
void Drag_calcvalues(void);
7580
void Drag_updateacc(void);
7681
};

src/config.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ clsConfig::clsConfig() {
1010
//Set default values
1111
values.blnLogging = false;
1212
values.blnDragMode = false;
13+
values.blnDrawPathOnScreen = false;
1314
values.uintScreenWidth = 640;
1415
values.uintScreenHeight = 480;
1516
#if defined(_AIX)
@@ -56,6 +57,7 @@ void clsConfig::make(void) {
5657
fprintf(configFile,"Screen Height: %u\n",values.uintScreenHeight);
5758
fprintf(configFile,"Log Ball's path: %u\n", (values.blnLogging ? 1 : 0) ) ;
5859
fprintf(configFile,"Enable Drag Mode (experimental): %u\n", (values.blnDragMode ? 1 : 0) );
60+
fprintf(configFile,"Draw Ball path on screen: %u\n", (values.blnDrawPathOnScreen ? 1 : 0) );
5961
fclose(configFile);
6062
}
6163
/**********************************************************************************************************************************************/
@@ -89,6 +91,12 @@ void clsConfig::load(void) {
8991
if(Global::blnDebugMode) {printf("Enable Drag \t %d\n",intTempBool);}
9092
values.blnDragMode = (intTempBool == 1);
9193

94+
fgets(chrTempString,50,configFile);
95+
intValuesScanned = sscanf(chrTempString, "%*s %*s %*s %*s %*s %d",&intTempBool);
96+
if (intValuesScanned < 1) {printf("ERROR!"); intTempBool = 0;}
97+
if(Global::blnDebugMode) {printf("Enable Screen Path \t %d\n",intTempBool);}
98+
values.blnDrawPathOnScreen = (intTempBool == 1);
99+
92100
fclose(configFile);
93101
printf("\n\n");
94102
}
@@ -127,7 +135,7 @@ void clsConfig::Check(void) {
127135
printf("Current config file out of date. Making new one.\n");
128136
fclose(configFile);
129137
make();
130-
} else { load();}
138+
} else { load(); }
131139
} //end if exists
132140
}
133141
/**********************************************************************************************************************************************/

src/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct ConfigValues {
1414
uint uintScreenHeight;
1515
bool blnLogging;
1616
bool blnDragMode;
17+
bool blnDrawPathOnScreen;
1718
char* OperatingSystem;
1819
};
1920

src/global.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ namespace Global {
1919
extern const float fKineticFriction;
2020
extern const float fDensityAir;
2121
extern const float fRecoil;
22-
extern const float fVelocityScalar;
2322
extern const float fMinVelocity;
2423
extern const float fCoefficientRestitution;
25-
extern const float fTimetoSizeRatio;
2624
extern const uchar CollisionMethod;
2725
}
26+
27+
namespace Equations {
28+
extern const float fVelocityScalar;
29+
extern const float fTimetoSizeRatio;
30+
extern const float fMassAlphaRatio;
31+
extern const float fMassAlphaOffset;
32+
extern const uchar uAlphaMinimum;
33+
}
2834
}
2935
/**********************************************************************************************************************************************/
3036
#endif // __GLOBAL_H_INCLUDED__

src/image_ball.xpm

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
/* XPM */
22
static char * image_ball_xpm[] = {
3-
"10 10 8 1",
4-
" c #FFFFFF",
5-
". c #828282",
6-
"+ c #454545",
7-
"@ c #A8A8A8",
8-
"# c #2C2C2C",
9-
"$ c #070707",
10-
"% c #060606",
11-
"& c #050505",
12-
" .++. ",
13-
" @#$%%$#@ ",
14-
" #%&&&&%# ",
15-
".$&&&&&&$.",
16-
"+%&&&&&&%+",
17-
"+%&&&&&&%+",
18-
".$&&&&&&$.",
19-
" #%&&&&%# ",
20-
" @#$%%$#@ ",
21-
" .++. "};
3+
"10 10 16 1",
4+
" g #000000",
5+
". g #CACACA",
6+
"+ g #F9F9F9",
7+
"@ g #D5D5D5",
8+
"# g #888888",
9+
"$ g #FDFDFD",
10+
"% g #FFFFFF",
11+
"& g #FEFEFE",
12+
"* g #969696",
13+
"= g #FCFCFC",
14+
"- g #EEEEEE",
15+
"; g #F5F5F5",
16+
"> g #BBBBBB",
17+
", g #C6C6C6",
18+
"' g #EFEFEF",
19+
") g #F6F6F6",
20+
" .++@ ",
21+
" #$%%%%&* ",
22+
" $%%%%%%& ",
23+
".%%%%%%%%@",
24+
"=%%%%%%%%&",
25+
"=%%%%%%%%&",
26+
"-%%%%%%%%;",
27+
" &%%%%%%% ",
28+
" >%%%%%%, ",
29+
" '&&) "};

src/image_pixel.xpm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* XPM */
22
static char * image_pixel_xpm[] = {
33
"1 1 1 1",
4-
" c #000000",
4+
" c #FFFFFF",
55
" "};

src/image_sky.xpm

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

0 commit comments

Comments
 (0)