
how are you all? 
William Labbett
Member #4,486
March 2004

Just in case anyone was missing me , I wanted to say hi again Allegro! My absence hasn't meant I've not been programming. In fact I've been working really hard on my game and it's going very well indeed. Here's an example of some code I wrote recently : 1/* circle_and_rotating_line_collision() : checks if a circle moving in a straight line, collides with a
2straight line which is rotating around a fixed point
3
4arguments:
5
6pai : polygon angle increment : angle in radians for how much the polygon rotated per update
7
8*/
9int circle_and_rotating_line_collision(Circle *c, const double cr_x, const double cr_y, const double pai, Point v1, Point v2, PotentialMove& move)
10{
11
12 Point v1_s, v2_s; // v1 shifted and v2 shifted by radius of circle in direction perpendicular to side of polygon away from centre of rotation
13
14
15
16 double psa2 = atan2( (v2.y  v1.y) , (v2.x  v1.x) );
17 if( psa2 < 0.0 )
18 {
19 psa2 += TWO_PI;
20 }
21
22 psa2 = ALLEGRO_PI / 2.0f;
23
24 principal_value( &psa2 );
25
26 v1_s.x = v1.x + c>radius * cos(psa2);
27 v1_s.y = v1.y + c>radius * sin(psa2);
28 v2_s.x = v2.x + c>radius * cos(psa2);
29 v2_s.y = v2.y + c>radius * sin(psa2);
30
31 const double k = c>remaining_distance / pai; // for storing the constant value : (distance circle travels) / (polygon increment angle)
32 const double xL = v1_s.x < v2_s.x ? v1_s.x  cr_x : v2_s.x  cr_x;
33 const double yL = v1_s.x < v2_s.x ? v1_s.y  cr_y : v2_s.y  cr_y;
34 const double xR = v1_s.x < v2_s.x ? v2_s.x  cr_x : v1_s.x  cr_x;
35 const double yR = v1_s.x < v2_s.x ? v2_s.y  cr_y : v1_s.y  cr_y;
36 const double sL = sqrt( (xR  xL) * (xR  xL) + (yR  yL) * (yR  yL) ); // length of polygon side
37 const double xt = ((xL * (xR  xL)) + (yL * (yR  yL))) / sL; // xt : x translation for the spiral
38 const double yt = (yL * xR  xL * yR) / sL; // yt : y translation for the spiral
39 const double cos_psa = (xR  xL) / sL; // cosine of the angle side of polygon makes
40 const double sin_psa = (yR  yL) / sL; // sine of the angle side of polygon makes
41 double pc[7]; // polynomial coeffecients
42 double z[ 12 ]; // array for real and imaginary parts of solutions to polynomial
43 int i;
44 gsl_poly_complex_workspace *w = gsl_poly_complex_workspace_alloc (7);
45
46 double r, pA;
47
48 double a = c>cc_x  cr_x;
49 double b = c>cc_y  cr_y;
50
51 //cout << "a" << a << "b" << b << "\n";
52 double psa = atan2( yR  yL, xR  xL );
53
54 if( psa < 0.0f )
55 {
56 psa += TWO_PI;
57 }
58
59
60 //cout << "psa = " << psa << "\n";
61
62 pc[0] = b * cos_psa  a * sin_psa  yt;
63 pc[1] = k * sin(c>circle_angle) * cos_psa  a * cos_psa  k * cos(c>circle_angle) * sin_psa  b * sin_psa;
64 pc[2] =  b * cos_psa / 2.0f + a * sin_psa / 2.0f  k * sin(c>circle_angle) * sin_psa  k * cos(c>circle_angle) * cos_psa;
65 pc[3] = k * sin(c>circle_angle) * cos_psa / 2.0f + a * cos_psa / 6.0 + b * sin_psa / 6.0f + k * cos(c>circle_angle) * sin_psa / 2.0f;
66 pc[4] = b * cos_psa / 24.0f  a * sin_psa / 24.0f + k * cos(c>circle_angle) * cos_psa / 6.0f + k * sin(c>circle_angle) * sin_psa / 6.0f;
67 pc[5] = k * sin(c>circle_angle) * cos_psa / 24.0f  k * cos(c>circle_angle) * sin_psa / 24.0f  a * cos_psa / 120.0f  b * sin_psa / 120.0f;
68 pc[6] =  k * cos(c>circle_angle) * cos_psa / 120.0f  k * sin(c>circle_angle) * sin_psa / 120.0f;
69
70 gsl_poly_complex_solve(pc, 7, w, z);
71
72 for(i = 0; i < 6; ++i)
73 {
74 if( z[ 2 * i + 1] == 0.0)
75 {
76 r = sqrt( pow( b + k * z[2*i] * sin( c>circle_angle ), 2) + pow( a + k * z[2*i] * cos( c>circle_angle ), 2) );
77
78 pA = atan2( b + k * z[2*i] * sin( c>circle_angle ), a + k * z[2*i] * cos( c>circle_angle ));
79
80 if( z[2*i] >= 0.0 && z[2*i] <= pai && r * cos( pA  z[2*i]  psa)  xt >= 0 && r * cos( pA  z[2*i]  psa )  xt <= sL )
81 {
82
83 double hit_x, hit_xr;
84 double hit_y, hit_yr;
85
86 //cout << "degrees required to hit " << (z[2*i] * 180.0f / ALLEGRO_PI) << "\n";
87
88 rotate_point( psa, r * cos( pA  z[2*i]  psa), r * sin( pA  z[2*i]  psa), &hit_x, &hit_y);
89 rotate_point( z[2*i], hit_x, hit_y, &hit_xr, &hit_yr);
90
91 move.x = hit_xr + cr_x;
92 move.y = hit_yr + cr_y;
93
94 double xLr, yLr, xRr, yRr; // for storing where the coordinates of the ends of the line where it
95 // it is when the circle hits it
96
97 // rotate points (xL, yL) and (xR, yR) to where they are when circle hits it so the angle of it
98 // can be worked out. This is needed to determine the angle the circle bounces off at
99
100 rotate_point(z[2*i], xL, yL, &xLr, &yLr);
101 rotate_point(z[2*i], xR, yR, &xRr, &yRr);
102
103 double side_angle = atan2( yRr  yLr, xRr  xLr );
104
105 double new_angle = 2.0f * side_angle  c>circle_angle;
106
107 principal_value(&new_angle);
108
109 move.angle = new_angle;
110
111 //cout << "returning 1 from rotating line function.\n";
112 //eek();
113
114 return 1;
115 }
116 }
117
118 }
119
120 //cout << "rotating line function : returning 0.\n";
121
122 return 0;
123}
It took me weeks to work it out but it works good. Very proud to have worked it out. So here I am, finally getting somewhere with my game and they want to rope me in for a medical assessment to see if I'm fit for work. Also, I'm now doing a maths degree and playing ping ping once a week. Anyway, hope everyone's getting on alright, Will

Dario ff
Member #10,065
August 2008

Hello Will! Nice to see you're still making progress with that project. Is it for that isometric project you posted some screens some time ago? As for me, I'm on my 2nd year of Electronics Engineering and currently working on a large reverseengineering/modding project. Ironically it has taught me a lot more and been a great motivation to learn how more modern 3D graphics engines work, and I'll surely try out all this stuff for probably building my dream engine once more. Not using Allegro much lately, but I'll surely try to jump back in if Speedhack happens this year again. TranslatorHack 2010, a human translation chain in a.cc. 
William Labbett
Member #4,486
March 2004

hi dario, thanks for saying hi. Dario ff said: Is it for that isometric project you posted some screens some time ago? It's for a pong variation I'm working on : {"name":"606007","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/6\/563db1236d17c276cfd44d6964358f8a.png","w":1070,"h":816,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/6\/563db1236d17c276cfd44d6964358f8a"}

Edgar Reynaldo
Member #8,592
May 2007

On to my second year of four for a CompSci degree, have 10 days til classes start again for the summer term... Glad you're making progress Will. My Website!  EAGLE GUI Library Demos  My Deviant Art Gallery  Spiraloid Preview  A4 FontMaker  Skyline! (Missile Defense) Elizabeth Warren for President 2020!  Modern Allegro 4 and 5 binaries  Allegro 5 compile guide 
verthex
Member #11,340
September 2009

Haven't coded much recently. Went surfing 3 days in row for the first time since the summer of 2011! South shore is finally getting big on Oahu.

Specter Phoenix
Member #1,425
July 2001

Besides programming, I helped put a new rear bumper on my wife's grandfather's truck and been taping and painting their kitchen this past two weeks. Outside of that I have just been doing house chores and taking care of wife and son. "Can't a man even talk to himself without being interrupted?" Krull(1983) 
weapon_S
Member #7,859
October 2006

Hi, William. I can't tell those people who use their real name apart, so I haven't missed you ;p Nice to see you back and doing well. 
verthex
Member #11,340
September 2009

weapon_S said: Modern compilers might do this during optimization.
Its hard to say without benchmarking it.

Niunio
Member #1,975
March 2002

Hi William! Glad to see you. That "pong" looks nice. Does the "quads" rotate? Myself I'm working hard in my Allegro wrapper for Pascal. It does work but only "sometimes". verthex said: I've seem some types of multiplication run slower with the O3 flag (with inline assembler). Go figure. IIRC Allegro 3 used O2 because it had better bechmarking than O3.  
Elias
Member #358
May 2000

Hi William! Good to hear you're doing fine. Is this the game you mentioned half a year ago in Cambridge?  
Dizzy Egg
Member #10,824
March 2009

...aww...Cambs... Hello Willy! I'm eggsellent thanks, glad your still using oxygen (in a good way)
 
AMCerasoli
Member #11,955
May 2010

Hi man!, I'm on my 2nd year since I turned 21, and yesterday I saw a dog walking on the street, I said "GRRR" and the dog said "Hello". And talking about universities here's a joke. A teacher asks her class if anyone can use the word fascinate in a sentence. Brian raises his hand and says, "The sky is fascinating." The teacher says, "No that's fascinating." Jennifer raises her hand and says, "When I saw the tigers at the zoo I was fascinated." The teacher says, "No that's fascinated." So finally Little Johnny raises his hand and says, "My mom bought a new blouse with 12 pearl buttons, but her tit's are so big she could only fasten eight!

