From 24703953db832aedd37872b7cd598124a90fcb4d Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 15 Sep 2016 11:53:23 +0100 Subject: [PATCH] Rudimentary face points --- src/Models/Hit.php | 27 ++++++++++++++++----------- www/faces.php | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Models/Hit.php b/src/Models/Hit.php index ef7505e..e0bcca7 100644 --- a/src/Models/Hit.php +++ b/src/Models/Hit.php @@ -150,13 +150,20 @@ class Hit return $this->points; } - + /** + * @param \EmotionHero\Models\Game $game + * @return \EmotionHero\Models\Hit + */ public function setGame(Game $game) { $this->game = $game; $game->addHit($this); return $this; } + /** + * @param \EmotionHero\Models\Target $target + * @return \EmotionHero\Models\Hit + */ public function setTarget(Target $target) { $this->target = $target; $target->addHit($this); @@ -1328,8 +1335,6 @@ class Points{ } return $this; - $a = $this->getNormalisedPoints(); - } /** @@ -1350,8 +1355,8 @@ class Points{ public function getNormalisedPoints() { $points = $this->getAsArray(); $xs = array_map(function(Point $a){return $a->getX();}, $points); - $ys = array_map(function(Point $a){return $a->getX();}, $points); - + $ys = array_map(function(Point $a){return $a->getY();}, $points); + $minx = min($xs); $maxx = max($xs); @@ -1362,15 +1367,15 @@ class Points{ $sizey = $maxy-$miny; $scale = max($sizex, $sizey); // divide by largest diff. - + //used to center the face within the square: - $diffx = ($scale - $sizex)/2; - $diffy = ($scale - $sizey)/2; - + $diffx = (($scale - $sizex)/(2 * $scale)) * 100; + $diffy = (($scale - $sizey)/(2 * $scale)) * 100; + $normalised_points = []; foreach($points as $i => $point) { - $x = (($point->getX() - $minx) / $scale) + $diffx; - $y = (($point->getY() - $miny) / $scale) + $diffy; + $x = (($point->getX() - $minx) / $scale) * 100 + $diffx; + $y = (($point->getY() - $miny) / $scale) * 100 + $diffy; $normalised_points[$i] = new Point($x, $y); } diff --git a/www/faces.php b/www/faces.php index db73013..40c7bb0 100644 --- a/www/faces.php +++ b/www/faces.php @@ -155,7 +155,7 @@ echo <<< EOSVG