Package: com.multiversesocial.hyperview
Class: com.multiversesocial.hyperview.GobGeometry
Source: src/com/multiversesocial/hyperview/GobGeometry.java

GobGeometry

HyperView V3.23 — class
version V3.2 class

Summary

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).

  1. Outline: 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.
  2. Hit test: 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.
  3. Helpers: 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).

Source file: GobGeometry.java. Tests: test/.../PhysicsTest.java (outline rotation, z scaling), PickTest.java (alpha holes, rotation). Info demo steps: InfoPhysics (gob-rotation).

Hierarchy

Extends: none

Implements: none

Used by: CollisionManager (outline of rotated Gobs), Gob.containsPoint(), HyperView.pickGob(), HyperView (selection highlight)

Referenced HyperView classes

Media files used

Declaration & members

public class GobGeometry

Declared in src/com/multiversesocial/hyperview/GobGeometry.java, lines 1–237. 0 field(s), 1 constructor(s), 8 method(s). Every member has an anchor you can link to (e.g. GobGeometry.html#<id>).

Fields (0)

DeclarationValue / initializerDescriptionSource

Constructors (1)

SignatureDescriptionSource
private GobGeometry()No comment in source.line 33

Methods (8)

SignatureDescriptionSource
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).line 181
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.line 131
public static double normalizeAngle(double a)Normalise an angle to (-PI, PI]; values within 1e-9 of a full turn become exactly 0.0.line 38
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.line 151
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.line 54
static int round(double v)No comment in source.line 64
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.line 73
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.line 229

Examples

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...
Hits--