whipz Posted March 2, 2017 Share Posted March 2, 2017 I have no idea on how to do it; everything I have tried is always just slightly off, its driving me insane ): will post what I got if needed but obviously mines wrong lol Quote Link to comment Share on other sites More sharing options...
Deceiver Posted March 2, 2017 Share Posted March 2, 2017 isnt area like position x = area.getcentertile(); or getcenter? Quote Link to comment Share on other sites More sharing options...
whipz Posted March 2, 2017 Author Share Posted March 2, 2017 13 minutes ago, raijin said: isnt area like position x = area.getcentertile(); or getcenter? i dunno ill try and report back xD 15 minutes ago, raijin said: isnt area like position x = area.getcentertile(); or getcenter? Nope that doesnt work there is no getCenter Quote Link to comment Share on other sites More sharing options...
Stimpack Posted March 2, 2017 Share Posted March 2, 2017 Try averaging out the x and y points of the tile's polygon and use the result as your new point. If the polygon isn't too complex i think it should be close to what you need. https://en.m.wikipedia.org/wiki/Centroid#Of_a_finite_set_of_points Quote Link to comment Share on other sites More sharing options...
whipz Posted March 2, 2017 Author Share Posted March 2, 2017 5 minutes ago, Stimpack said: Try averaging out the x and y points of the tile's polygon and use the result as your new point. If the polygon isn't too complex i think it should be close to what you need. https://en.m.wikipedia.org/wiki/Centroid#Of_a_finite_set_of_points I figured it out using this int mouseSpotX = Math.toIntExact((long) hoverTile.getPolygon(getBot()).getBounds().getCenterX()); int mouseSpotY = Math.toIntExact((long) hoverTile.getPolygon(getBot()).getBounds().getCenterY()); mouse.move really needs to have both x and y but also sometimes z ): Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted March 2, 2017 Share Posted March 2, 2017 You can do some math and then do: int x = x + width / 2 int y = y + height / 2 (or subtract depending on if up is -y or +y) 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted March 2, 2017 Author Share Posted March 2, 2017 (edited) 49 minutes ago, LoudPacks said: You can do some math and then do: int x = x + width / 2 int y = y + height / 2 (or subtract depending on if up is -y or +y) Ill give that a shot as well, I have found that different camera angles play a part, thats why I want mouse.move to contain z axis as this will help with the height why do I divide by 2 ? just asking Edited March 2, 2017 by whipz Quote Link to comment Share on other sites More sharing options...
Alek Posted March 3, 2017 Share Posted March 3, 2017 Areas can be polygons, not rectangles. Not sure if you specifically meant rectangle areas. Quote Link to comment Share on other sites More sharing options...
Explv Posted March 3, 2017 Share Posted March 3, 2017 (edited) Edit: Nevermind @whipz What exactly are you trying to achieve here? Edited March 3, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
whipz Posted March 3, 2017 Author Share Posted March 3, 2017 4 hours ago, Explv said: Edit: Nevermind @whipz What exactly are you trying to achieve here? i want to get the mouse to move on the z axis on a tile ): Quote Link to comment Share on other sites More sharing options...
Polymorphism Posted March 4, 2017 Share Posted March 4, 2017 Here is finding the center using Centroid finite set of points. I passed in Area#getPolygon(), not sure how it'd react to Position#getPolygon() The function output Point2D.Double[6703.75, 3367.75] In my use I will always be rounding up, but you may choose to do either way. public Point2D.Double calcPolygonCenter(Polygon polygon) { double x = 0; double y = 0; int points = polygon.npoints; for (int i = 0; i < polygon.xpoints.length; i++) { x += polygon.xpoints[i]; } for (int i = 0; i < polygon.ypoints.length; i++) { y += polygon.ypoints[i]; } x = x / points; y = y / points; return new Point2D.Double(x, y); } Quote Link to comment Share on other sites More sharing options...