Borland inclined plane simulation problem..

Hey there!

I'm struggling with my fresh app, that have to simulate how would ball move on 2 inclined planes (Going down from first, then up on the second, then back on second etc.)

Dunno why but my ball starts to... fly! My IT teacher told me I've broken all physics laws possible...

It's messy, I know and apologize, but I would be glad if someone could check this...

More than 50% declarations are unessesary but I have no time atm :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
//---------------------------------------------------------------------------

#include <vcl.h>
#include <math.h>
#include <time.h>
#include <dos.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define PI 3.14159265
#define g 10



TForm1 *Form1;
int blad;
int suma;
int kat;
float b;
float kat2;
float b2;
int r;
float c;
float c2;
float a;
float a2;
float x1;
float y1;
float p;
int o;
int przes;
double t;
float sx;
float sy;
float t2;
float t3;
char zmiana='0';
float vx;
float vy;
float ax2;
float ay2;
float ax;
float ay;
float ax3;
float ay3;
int licznik=0;
float sx2;
float sy2;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
kat=StrToInt(Edit1->Text);
b=200;
kat2=StrToInt(Edit3->Text);
b2=200;
if((kat>90)||(kat2>90))
        {
        MessageBox(NULL, "Kąt nie może byc większy niż 90!", "UWAGA!", MB_ICONSTOP|MB_SETFOREGROUND);
        blad=1;
        }
else
{
blad=0;
}

c= b/cos (kat*PI/180);
c2=b2/cos (kat2*PI/180);
a=sqrt(c*c-b*b);
a2= sqrt(c2*c2-b2*b2);

x1=16;
y1=392;
p=0;
o=0;
suma=0;
przes = 0;
ax=g*sin(kat*PI/180)*cos(kat*PI/180)*0.02;
ay=g*sin(kat*PI/180)*sin(kat*PI/180)*0.02;
ax3=g*sin(kat2*PI/180)*cos(kat2*PI/180);
ay3=g*sin(kat2*PI/180)*sin(kat2*PI/180);
r=Shape1->Width;

if (blad==0)
{
Shape1->Visible=true;
Timer1->Enabled=true;
Canvas->MoveTo(x1, y1);
	Canvas->LineTo(x1, y1+a);
        Canvas->LineTo(x1+b, y1+a);
        Canvas->LineTo(x1, y1);
        Canvas->MoveTo(x1+b, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a-a2);
        Canvas->LineTo(x1+b, y1+a);
        Shape1->Top=x1;
        Shape1->Left=y1;
        t=0;
        zmiana='0';
}
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
switch(zmiana)
{

case '0':
t=t+0.02;
t2=t2+0.02;
Label9->Caption=int (sx/6);
Label10->Caption=int (sy/6);
Label11->Caption=int (t);
sx=(0.5)*(t2*t2)*ax;
sy=(0.5)*(t2*t2)*ay;
// LICZENIE BOKÓW

        //Wzor na przyspieszenie BEZ masy ->> p=p+(g*sin(kat*PI/180));
        //Przesuniecie o x-a, y+a, milisekundy - x-a/1000, y+a/1000
        //Funkcja sleep(), delay() do rysowania kulki
        //p=p+(g*sin(kat*PI/180));
        Canvas->MoveTo(x1, y1);
	Canvas->LineTo(x1, y1+a);
        Canvas->LineTo(x1+b, y1+a);
        Canvas->LineTo(x1, y1);
        Canvas->MoveTo(x1+b, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a-a2);
        Canvas->LineTo(x1+b, y1+a);
        Shape1->Left=x1+sx-0.5*r;
        Shape1->Top=y1+sy-r;
        vx=ax*t2;
        vy=ay*t2;
        if(int (y1+a)==int (y1+sy))
        {
        Timer1->Enabled=false;
        Timer2->Enabled=true;
        zmiana='1';
        Label12->Caption=vx;
        Label13->Caption=vy;
        }
        //if((x1+(0.5)*(t*t)*g*sin(kat*PI/180)*cos(kat*PI/180))<
        //Canvas->Ellipse(x1+(1.5*r)+przes,y1+(1.5*r)+przes,x1-(0.5*r)+przes,y1-(0.5*r)+przes);
        break;
case '2':
t3=0;
t=t+0.02;
t2=t2+0.02;
licznik=licznik+1;
vx=vx-ax*t2*0.02;
vy=vy-ay*t2*0.02;
Label14->Caption=vx;
Label15->Caption=vy;

Label9->Caption=int (ay/1.2);
Label10->Caption=int (ax/1.2);
Label11->Caption=int (t);
ax2=vx*t2;
ay2=vy*t2;
Label12->Caption=ax;
Label13->Caption=ay;
// LICZENIE BOKÓW

        //Wzor na przyspieszenie BEZ masy ->> p=p+();
        //Przesuniecie o x-a, y+a, milisekundy - x-a/1000, y+a/1000
        //Funkcja sleep(), delay() do rysowania kulki
        //p=p+(g*sin(kat*PI/180));
        Canvas->MoveTo(x1, y1);
	Canvas->LineTo(x1, y1+a);
        Canvas->LineTo(x1+b, y1+a);
        Canvas->LineTo(x1, y1);
        Canvas->MoveTo(x1+b, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a-a2);
        Canvas->LineTo(x1+b, y1+a);
        Shape1->Left=x1+b-ax2-0.5*r;
        Shape1->Top=y1+a+ay2-r;
        vx=ax*t2;
        vy=ay*t2;
        if((licznik>20)&&(y1+a>int (y1+a+ay2)))
        {
        Timer2->Enabled=false;
        }
        break;

        }

}
//---------------------------------------------------------------------------





void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button4Click(TObject *Sender)
{
Form1->Refresh();
Shape1->Visible=false;
Timer1->Enabled=false;
Label9->Caption=0;
Label10->Caption=0;
Label11->Caption=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)
{
t=0;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer2Timer(TObject *Sender)
{

switch(zmiana)
{

case '1':
licznik=licznik+1;
vx=vx-ax*0.02;
vy=vy-ay*0.02;
Label14->Caption=vx;
Label15->Caption=vy;
t=t+0.02;
t3=t3+0.02;
Label9->Caption=int (ay/1.2);
Label10->Caption=int (ax/1.2);
Label11->Caption=int (t);
sx2=vx*t3;
sy2=vy*t3;
Label12->Caption=ax2;
Label13->Caption=ay2;
// LICZENIE BOKÓW

        //Wzor na przyspieszenie BEZ masy ->> p=p+();
        //Przesuniecie o x-a, y+a, milisekundy - x-a/1000, y+a/1000
        //Funkcja sleep(), delay() do rysowania kulki
        //p=p+(g*sin(kat*PI/180));
        Canvas->MoveTo(x1, y1);
	Canvas->LineTo(x1, y1+a);
        Canvas->LineTo(x1+b, y1+a);
        Canvas->LineTo(x1, y1);
        Canvas->MoveTo(x1+b, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a);
        Canvas->LineTo(x1+b+b2, y1+a-a2);
        Canvas->LineTo(x1+b, y1+a);
        Shape1->Left=x1+b+sx2-0.5*r;
        Shape1->Top=y1+a-sy2-r;

        if((licznik>20)&&(y1+a>int (y1+a+sy2)))
        {
        vx=ax*t3;
        vy=ay*t3;
        Timer2->Enabled=false;
        Timer1->Enabled=true;
        zmiana='2';
        licznik=0;

        }
        break;

        }
}
//-------------------------------------------------------------------------- 


http://www.speedyshare.com/files/26389854/projet.rar -> whole thing

Cheers!
Topic archived. No new replies allowed.