inline dot product

This commit is contained in:
Hannes Janetzek 2013-06-04 11:40:07 +02:00
parent 8299423e6d
commit dc5b264a0a

View File

@ -34,15 +34,18 @@ public class OBB2D {
// Returns true if other overlaps one dimension of this. // Returns true if other overlaps one dimension of this.
private boolean overlaps1Way(OBB2D other) { private boolean overlaps1Way(OBB2D other) {
for (int a = 0; a < 2; a++) { for (int a = 0; a < 2; a++) {
float ax = axis[a * 2];
float ay = axis[a * 2 + 1];
double t = Vec2.dot(other.corner, 0, axis, a); // dot product
float t = ax * other.corner[0] + ay * other.corner[1];
// Find the extent of box 2 on axis a // Find the extent of box 2 on axis a
double tMin = t; float tMin = t;
double tMax = t; float tMax = t;
for (int c = 1; c < 4; c++) { for (int c = 2; c < 8; c += 2) {
t = Vec2.dot(other.corner, c, axis, a); t = ax * other.corner[c] + ay * other.corner[c + 1];
if (t < tMin) { if (t < tMin) {
tMin = t; tMin = t;
@ -52,7 +55,6 @@ public class OBB2D {
} }
// We have to subtract off the origin // We have to subtract off the origin
// See if [tMin, tMax] intersects [0, 1] // See if [tMin, tMax] intersects [0, 1]
if ((tMin > 1 + origin[a]) || (tMax < origin[a])) { if ((tMin > 1 + origin[a]) || (tMax < origin[a])) {
// There was no intersection along this dimension; // There was no intersection along this dimension;
@ -105,7 +107,7 @@ public class OBB2D {
computeAxes(); computeAxes();
} }
public OBB2D(){ public OBB2D() {
} }
@ -160,7 +162,7 @@ public class OBB2D {
computeAxes(); computeAxes();
} }
public void set(float cx, float cy, float dx, float dy, float width, float height){ public void set(float cx, float cy, float dx, float dy, float width, float height) {
float vx = cx - dx; float vx = cx - dx;
float vy = cy - dy; float vy = cy - dy;
@ -191,6 +193,7 @@ public class OBB2D {
computeAxes(); computeAxes();
} }
public OBB2D(float cx, float cy, float dx, float dy, float width, float height) { public OBB2D(float cx, float cy, float dx, float dy, float width, float height) {
float vx = cx - dx; float vx = cx - dx;