Rev 913 |
Rev 924 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.bauzoid.math.collision;
import com.gebauz.bauzoid.graphics.sprite.Sprite;
import com.gebauz.bauzoid.graphics.sprite.SpriteParameters;
import com.gebauz.bauzoid.math.Line2;
import com.gebauz.bauzoid.math.Vector2;
public class RectElement
extends BaseShapeElement
{
// Constants========================================================================================
public static final int NUM_LINE_SEGMENTS =
4;
public static final int TOP_LEFT =
0;
public static final int TOP_RIGHT =
1;
public static final int BOTTOM_RIGHT =
2;
public static final int BOTTOM_LEFT =
3;
// Embedded Types===================================================================================
// Fields===========================================================================================
public float x
;
public float y
;
public float w
;
public float h
;
// Methods==========================================================================================
public RectElement
(float initX,
float initY,
float initW,
float initH
)
{
x = initX
; y = initY
; w = initW
; h = initH
;
}
@
Override
public boolean isInside
(float pX,
float pY
)
{
if ((pX
>= x
) && (pX
<=
(x + w
)) &&
(pY
>= y
) && (pY
<=
(y + h
)))
return true;
return false;
}
@
Override
public boolean intersects
(Shape shape, SpriteParameters param
)
{
// generate bounding line segments and transform them
Vector2 points
[] =
new Vector2
[NUM_LINE_SEGMENTS
];
points
[TOP_LEFT
] = param.
transformPoint(x, y
);
points
[TOP_RIGHT
] = param.
transformPoint(x + w, y
);
points
[BOTTOM_RIGHT
] = param.
transformPoint(x + w, y + h
);
points
[BOTTOM_LEFT
] = param.
transformPoint(x, y + h
);
for (int i =
0; i
< NUM_LINE_SEGMENTS
; i++
)
{
int j =
(i +
1) % (NUM_LINE_SEGMENTS-
1);
if (shape.
isInside(points
[i
].
x, points
[i
].
y) != shape.
isInside(points
[j
].
x, points
[j
].
y))
return true;
}
return false;
}
public void debugRender
(Sprite sprite
)
{
}
// Getters/Setters==================================================================================
}