Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1051 | chris | 1 | package com.gebauz.bauzoid.math.collisionx; |
| 2 | |||
| 3 | import java.util.Vector; |
||
| 4 | |||
| 5 | import com.gebauz.bauzoid.graphics.spritex.Sprite; |
||
| 6 | import com.gebauz.bauzoid.math.Line2; |
||
| 7 | import com.gebauz.bauzoid.math.Matrix4; |
||
| 8 | import com.gebauz.bauzoid.math.Vector2; |
||
| 9 | |||
| 10 | /** A shape that is composed of several shape elements. */ |
||
| 11 | public class Shape |
||
| 12 | { |
||
| 13 | |||
| 14 | |||
| 15 | // Constants======================================================================================== |
||
| 16 | |||
| 17 | // Embedded Types=================================================================================== |
||
| 18 | |||
| 19 | // Fields=========================================================================================== |
||
| 20 | |||
| 21 | private Vector<BaseShapeElement> mElements = new Vector<BaseShapeElement>(); |
||
| 22 | |||
| 23 | // Methods========================================================================================== |
||
| 24 | |||
| 25 | public Shape() |
||
| 26 | { |
||
| 27 | |||
| 28 | } |
||
| 29 | |||
| 30 | public void addElement(BaseShapeElement element) |
||
| 31 | { |
||
| 32 | mElements.add(element); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** Check if the point is inside any of the shape elements in this shape - meaning it's also in the whole shape. */ |
||
| 36 | public boolean isInside(float x, float y) |
||
| 37 | { |
||
| 38 | for (int i = 0; i < mElements.size(); i++) |
||
| 39 | { |
||
| 40 | BaseShapeElement element = mElements.get(i); |
||
| 41 | if (element.isInside(x, y)) |
||
| 42 | return true; |
||
| 43 | } |
||
| 44 | |||
| 45 | return false; |
||
| 46 | } |
||
| 47 | |||
| 48 | public boolean intersects(Shape shape, Matrix4 transform) |
||
| 49 | { |
||
| 50 | for (int i = 0; i < mElements.size(); i++) |
||
| 51 | { |
||
| 52 | BaseShapeElement element = mElements.get(i); |
||
| 53 | if (element.intersects(shape, transform)) |
||
| 54 | return true; |
||
| 55 | } |
||
| 56 | |||
| 57 | return false; |
||
| 58 | } |
||
| 59 | |||
| 60 | public boolean intersects(Shape shape, Matrix4 transform, Vector2 displaceVector) |
||
| 61 | { |
||
| 62 | for (int i = 0; i < mElements.size(); i++) |
||
| 63 | { |
||
| 64 | BaseShapeElement element = mElements.get(i); |
||
| 65 | if (element.intersects(shape, transform, displaceVector)) |
||
| 66 | return true; |
||
| 67 | } |
||
| 68 | |||
| 69 | return false; |
||
| 70 | } |
||
| 71 | |||
| 72 | public boolean intersectsLine(Line2 line) |
||
| 73 | { |
||
| 74 | for (int i = 0; i < mElements.size(); i++) |
||
| 75 | { |
||
| 76 | BaseShapeElement element = mElements.get(i); |
||
| 77 | if (element.intersectsLine(line)) |
||
| 78 | return true; |
||
| 79 | } |
||
| 80 | |||
| 81 | return false; |
||
| 82 | } |
||
| 83 | |||
| 84 | public void debugRender(Sprite sprite) |
||
| 85 | { |
||
| 86 | for (int i = 0; i < mElements.size(); i++) |
||
| 87 | { |
||
| 88 | mElements.get(i).debugRender(sprite); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | // Getters/Setters================================================================================== |
||
| 93 | |||
| 94 | public final int getNumElements() { return mElements.size(); } |
||
| 95 | public final BaseShapeElement getElement(int i) { return mElements.get(i); } |
||
| 96 | |||
| 97 | } |
||
| 98 | |||
| 99 | |||
| 100 |