Package: com.multiversesocial.hyperview
Class: com.multiversesocial.hyperview.GobGeometry
Source: src/com/multiversesocial/hyperview/GobGeometry.java
Geometry of a rotated, z-scaled Gob (V3.23). All methods are static and need no HyperView and no display. The angle is in radians, positive = clockwise on the screen (y points down); a Gob turns about the centre of its drawn rectangle, pixel index ((w-1)/2, (h-1)/2).
updateOutlineRotated(Gob) is called by CollisionManager when Gob.angle is not 0: the outline (the traced OutlineTracer polygon, already scaled with z / the width-height ratio) is turned about that centre and written to the world polygon and the bounding box (worldX/worldY/worldN, boundX1..boundY2). With angle 0 the V3.22 code runs unchanged.containsPoint(Gob,x,y) rejects with the bounding rectangle of the turned sprite first, then the polygon (point in polygon on doubles), then — for Gobs with the outline flag and pickAlpha — the sprite's alpha mask, so a click in a transparent hole falls through. This is what HyperView.pickGob() uses.normalizeAngle (to (-PI, PI], a full turn is exactly 0), rotate, drawnBounds, pointInPolyD, worldPolygon (a java.awt.Polygon of the current world outline, for drawing).Extends: none
Implements: none
Used by: CollisionManager (outline of rotated Gobs), Gob.containsPoint(), HyperView.pickGob(), HyperView (selection highlight)
public class GobGeometry
| Declaration | Value / initializer | Description | Source |
|---|
| Signature | Description | Source |
|---|---|---|
private GobGeometry() | No comment in source. |
| Signature | Description | Source |
|---|---|---|
public static boolean containsPoint(Gob g, int px, int py) | Is the screen pixel px,py on Gob g? See the class comment (rectangle, outline polygon, alpha). The Gob's current x,y,angle and z size are used. Safe to call from another thread than the display thread (reads the fields once; the worst case is a wrong answer for the frame in which the Gob changes its image). | |
public static void drawnBounds(Gob g, int w, int h, int[] out) | Screen bounding box [x1,y1,x2,y2] (x2,y2 exclusive: pixels x1 .. x2-1) of the drawn, rotated rectangle of g. Used to widen the screen update area. With angle == 0 it is x,y,x+w,y+h. | |
public static double normalizeAngle(double a) | Normalise an angle to (-PI, PI]; values within 1e-9 of a full turn become exactly 0.0. | |
public static boolean pointInPolyD(int[] px, int[] py, int n, double x, double y) | Even-odd point in polygon with doubles; a point on an edge (within 1e-9) counts as inside. n < 3 is never inside. | |
public static void rotate(double px, double py, double cx, double cy, double angle, double[] out) | Rotate p about c by angle (clockwise on screen); out[0],out[1] = the result. | |
static int round(double v) | No comment in source. | |
static void updateOutlineRotated(Gob g) | CollisionManager.updateOutline() for a rotated Gob (angle != 0): rebuild g.worldX/worldY/worldN and the bounding box from the outline (or the box polygon of the drawn rectangle), the z scale, the rotation and the position. | |
public static Polygon worldPolygon(Gob g) | The current outline polygon of g in screen pixels, computed now (does not depend on a collision pass). A copy. |
Gob g = new Gob(view,pixels,w,h,GOB_ON_DISPLAY); g.setImageOutlineEnabled(true); // GOB_COLLISION_OUTLINE: traced from the alpha channel g.setAngleDegrees(90.0); // drawn rotated; the polygon turns with it view.addGob(g); Polygon p = GobGeometry.worldPolygon(g); // the turned outline in view coordinates (after a collision pass) boolean hit = GobGeometry.containsPoint(g,mouseX,mouseY); // bounding box, polygon, alpha mask double a = GobGeometry.normalizeAngle(7.0); // 7 - 2 PI = 0.7168...