Rev 1142 |
Rev 1158 |
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.Graphics;
import com.gebauz.bauzoid.graphics.RenderUtil;
import com.gebauz.bauzoid.graphics.sprite.SpriteTransform;
import com.gebauz.bauzoid.math.Line2;
import com.gebauz.bauzoid.math.Vector2;
import com.gebauz.bauzoid.math.Vector4;
import com.gebauz.bauzoid.math.collision.BaseShapeElement;
public class RectElement
extends BaseShapeElement
{
// Constants========================================================================================
// Embedded Types===================================================================================
// Fields===========================================================================================
public float x
;
public float y
;
public float w
;
public float h
;
// Methods==========================================================================================
public RectElement
(Shape shape,
float initX,
float initY,
float initW,
float initH
)
{
super(shape
);
x = initX
; y = initY
; w = initW
; h = initH
;
}
@
Override
public void renderDebug
(Graphics graphics, SpriteTransform t
)
{
RenderUtil.
drawQuad(graphics, x
* t.
w, y
* t.
h,
(x+w
) * t.
w,
(y+h
) * t.
h, t,
new Vector4
(1,
0,
0,
1));
Line2 lines
[] = getLineSegments
();
for (int i =
0; i
< lines.
length; i++
)
{
Vector2 midPoint = lines
[i
].
getMidPoint();
Vector2 lineVec = lines
[i
].
getLineVector();
Vector2 normal =
new Vector2
(lineVec.
y, -lineVec.
x);
normal.
normalize();
final float d =
20;
RenderUtil.
drawArrow(graphics, midPoint.
x, midPoint.
y, midPoint.
x + normal.
x * d, midPoint.
y + normal.
y * d,
new Vector4
(0,
0,
1,
1));
}
}
@
Override
public Vector2
[] getUntransformedPoints
()
{
Vector2
[] points =
new Vector2
[4];
points
[0] =
new Vector2
(x, y
);
points
[1] =
new Vector2
(x + w, y
);
points
[2] =
new Vector2
(x + w, y + h
);
points
[3] =
new Vector2
(x, y + h
);
return points
;
}
@
Override
public Vector2
[] getPoints
()
{
Vector2
[] points =
new Vector2
[4];
SpriteTransform t = getOwner
().
transform;
points
[0] = t.
spriteToWorld(x
* t.
w, y
* t.
h);
points
[1] = t.
spriteToWorld((x + w
) * t.
w, y
* t.
h);
points
[2] = t.
spriteToWorld((x + w
) * t.
w,
(y + h
) * t.
h);
points
[3] = t.
spriteToWorld(x
* t.
w,
(y + h
) * t.
h);
return points
;
}
@
Override
public Line2
[] getUntransformedLineSegments
()
{
Line2
[] lines =
new Line2
[4];
lines
[0] =
new Line2
(x, y, x + w, y
);
lines
[1] =
new Line2
(x + w, y, x + w, y + h
);
lines
[2] =
new Line2
(x + w, y + h, x, y + h
);
lines
[3] =
new Line2
(x, y + h, x, y
);
return lines
;
}
@
Override
public Line2
[] getLineSegments
()
{
Line2
[] lines =
new Line2
[4];
SpriteTransform t = getOwner
().
transform;
Vector2 topLeft = t.
spriteToWorld(x
* t.
w, y
* t.
h);
Vector2 topRight = t.
spriteToWorld((x+w
) * t.
w, y
* t.
h);
Vector2 bottomRight = t.
spriteToWorld((x+w
) * t.
w,
(y+h
) * t.
h);
Vector2 bottomLeft = t.
spriteToWorld(x
* t.
w,
(y+h
) * t.
h);
/*topLeft.x *= t.w; topLeft.y *= t.h;
topRight.x *= t.w; topRight.y *= t.h;
bottomRight.x *= t.w; bottomRight.y *= t.h;
bottomLeft.x *= t.w; bottomLeft.y *= t.h;*/
lines
[0] =
new Line2
(topLeft, topRight
);
lines
[1] =
new Line2
(topRight, bottomRight
);
lines
[2] =
new Line2
(bottomRight, bottomLeft
);
lines
[3] =
new Line2
(bottomLeft, topLeft
);
return lines
;
}
// Getters/Setters==================================================================================
}