31
Support / a question about collision detection
« on: May 18, 2011, 11:09:14 am »I would like to ask the realization principle of collision detection, I saw examples of that on the collision detection, but still very unclear, such as the following code, cube is how to detect a collision with those objects, and collision detection is how to achieve,
Code: [Select]
// Move method
public void move() {
if (up) {
SimpleVector t = cube.getZAxis();
t.scalarMul(SPEED);
moveRes.add(t);
}
if (down) {
SimpleVector t = cube.getZAxis();
t.scalarMul(-SPEED);
moveRes.add(t);
}
if (left) {
cube.rotateY((float) Math.toRadians(-1));
}
if (right) {
cube.rotateY((float) Math.toRadians(1));
}
// Avoid high speed
if (moveRes.length() > SPEED) {
moveRes.makeEqualLength(new SimpleVector(0, 0, MAXSPEED));
}
cube.translate(0, -0.02f, 0);
// collisionEllipsoid
cube.checkForCollisionEllipsoid(moveRes, ellipsoid, 8);
cube.translate(moveRes);
SimpleVector t = new SimpleVector(0, 1, 0);
t = cube.checkForCollisionEllipsoid(t, ellipsoid, 1);
cube.translate(t);
// damping
if (moveRes.length() > DAMPING) {
moveRes.makeEqualLength(new SimpleVector(0, 0, DAMPING));
} else {
moveRes = new SimpleVector(0, 0, 0);
}
}