Prechádzať zdrojové kódy

changed roundrect parameters : use full width/height

ncannasse 11 rokov pred
rodič
commit
72cd331478
2 zmenil súbory, kde vykonal 11 pridanie a 9 odobranie
  1. 9 8
      h2d/col/RoundRect.hx
  2. 2 1
      samples/col/TestCol.hx

+ 9 - 8
h2d/col/RoundRect.hx

@@ -10,20 +10,21 @@ class RoundRect {
 	var lenSq : Float;
 	var invLenSq : Float;
 	
-	public inline function new(x:Float,y:Float,rayW:Float,rayH:Float,rotation:Float) {
-		if( rayW < rayH ) {
-			var tmp = rayW;
-			rayW = rayH;
-			rayH = tmp;
+	public inline function new(x:Float,y:Float,w:Float,h:Float,rotation:Float) {
+		if( w < h ) {
+			var tmp = w;
+			w = h;
+			h = tmp;
 			rotation += Math.PI / 2;
 		}
-		this.ray = rayH;
-		var dx = (rayW - rayH) * Math.cos(rotation);
-		var dy = (rayW - rayH) * Math.sin(rotation);
+		var hseg = (w - h) * 0.5;
+		var dx = hseg * Math.cos(rotation);
+		var dy = hseg * Math.sin(rotation);
 		this.x = x - dx;
 		this.y = y - dy;
 		this.dx = dx * 2;
 		this.dy = dy * 2;
+		this.ray = h * 0.5;
 		lenSq = this.dx * this.dx + this.dy * this.dy;
 		invLenSq = 1 / lenSq;
 	}

+ 2 - 1
samples/col/TestCol.hx

@@ -58,8 +58,9 @@ class TestCol extends hxd.App {
 	override function update(dt:Float) {
 		var px = s2d.mouseX;
 		var py = s2d.mouseY;
-		var r = new h2d.col.RoundRect(rrect.x, rrect.y, RW, RH, rrect.rotation);
+		var r = new h2d.col.RoundRect(rrect.x, rrect.y, RW * 2, RH * 2, rrect.rotation);
 		
+		rrect.rotation += 0.01;
 		
 		rrect.color.set(0, 0, 1);