Some rope tweaks
authorunc0rr
Thu, 10 Sep 2009 04:36:26 +0000
changeset 2365 12b5373f4058
parent 2364 272977d2df53
child 2366 b38efe489615
Some rope tweaks
hedgewars/GSHandlers.inc
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Thu Sep 10 03:03:04 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Thu Sep 10 04:36:26 2009 +0000
@@ -850,7 +850,7 @@
 	ny:= ropeDy * len;
 	
 	len:= Gear^.Elasticity - _0_3x70;
-	while len > _0_3 do
+	while len > _3 do
 			begin
 			lx:= hwRound(Gear^.X + mdX * len);
 			ly:= hwRound(Gear^.Y + mdY * len);
@@ -864,6 +864,12 @@
 					b:= (nx * HHGear^.dY) > (ny * HHGear^.dX);
 					dLen:= len
 					end;
+				with RopePoints.rounded[RopePoints.Count] do
+					begin
+					X:= hwRound(Gear^.X);
+					Y:= hwRound(Gear^.Y);
+					end;
+				
 				Gear^.X:= Gear^.X + nx * len;
 				Gear^.Y:= Gear^.Y + ny * len;
 				inc(RopePoints.Count);
--- a/hedgewars/uGears.pas	Thu Sep 10 03:03:04 2009 +0000
+++ b/hedgewars/uGears.pas	Thu Sep 10 04:36:26 2009 +0000
@@ -96,7 +96,7 @@
                                   dLen: hwFloat;
                                   b: boolean;
                                   end;
-                rounded: array[0..MAXROPEPOINTS] of TVertex2i;
+                rounded: array[0..MAXROPEPOINTS + 2] of TVertex2i;
                 end;
 
 procedure DeleteGear(Gear: PGear); forward;
@@ -1260,60 +1260,37 @@
 end;
 
 procedure DrawRopeLinesRQ(Gear: PGear);
-var i, cnt: LongInt;
-	px, py: LongInt;
 begin
-// FIXME: store rounded coordinates in second points array
-cnt:= 0;
 with RopePoints do
-	if RopePoints.Count > 0 then
-		begin
-		i:= 0;
-		cnt:= 0;
-		px:= hwRound(ar[0].X) - 1;
-		while i < Count do
-			begin
-			rounded[cnt].X:= hwRound(ar[i].X) + WorldDx;
-			rounded[cnt].Y:= hwRound(ar[i].Y) + WorldDy;
-			// prevent equal points
-			if (px <> rounded[cnt].X) or (py <> rounded[cnt].Y) then
-				begin
-				px:= rounded[cnt].X;
-				py:= rounded[cnt].Y;
-				inc(cnt)
-				end;
-			inc(i)
-			end;
-		rounded[cnt].X:= hwRound(Gear^.X) + WorldDx;
-		rounded[cnt].Y:= hwRound(Gear^.Y) + WorldDy;
-		inc(cnt);
-		rounded[cnt].X:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx;
-		rounded[cnt].Y:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy;
-		end else
-		if Gear^.Elasticity.QWordValue > 0 then
-			begin
-			cnt:= 1;
-			rounded[0].X:= hwRound(Gear^.X) + WorldDx;
-			rounded[0].Y:= hwRound(Gear^.Y) + WorldDy;
-			rounded[1].X:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X) + WorldDx;
-			rounded[1].Y:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y) + WorldDy;
-			end;
+	begin
+	rounded[Count].X:= hwRound(Gear^.X);
+	rounded[Count].Y:= hwRound(Gear^.Y);
+	rounded[Count + 1].X:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.X);
+	rounded[Count + 1].Y:= hwRound(PHedgehog(Gear^.Hedgehog)^.Gear^.Y);
+	end;
 
-if cnt > 0 then
+if (RopePoints.Count > 0) or (Gear^.Elasticity.QWordValue > 0) then
 	begin
 	glDisable(GL_TEXTURE_2D);
 	glEnable(GL_LINE_SMOOTH);
+
+	glPushMatrix;
+
+	glTranslatef(WorldDx, WorldDy, 0);
 	
 	glLineWidth(4.0);
 
-	glColor4ub($A0, $A0, $A0, $C0);
+	glColor4ub($B0, $B0, $B0, $D0);
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glVertexPointer(2, GL_INT, 0, @RopePoints.rounded[0]);
-	glDrawArrays(GL_LINE_STRIP, 0, cnt + 1);
+	glDrawArrays(GL_LINE_STRIP, 0, RopePoints.Count + 2);
 	glColor4f(1, 1, 1, 1);
+
+	glPopMatrix;
+	
 	glEnable(GL_TEXTURE_2D);
-	glDisable(GL_LINE_SMOOTH);
+	glDisable(GL_LINE_SMOOTH)
 	end
 end;