--- a/src/proto2/Physics.cc Mon Nov 24 23:13:19 2008 +0000
+++ b/src/proto2/Physics.cc Fri Nov 28 10:57:10 2008 +0000
@@ -302,17 +302,25 @@
* referring to the DIRECTIONS table in Physics.hh
*/
int getDirectionIndex (Vector dir) {
- int index = 0;
- if(dir.x < -0.1 || (dir.y > 0.1 && dir.x < 0.1)) {
- index += 4;
- }
- if((dir.x == 1 && dir.y >= 0) || (dir.x == -1 && dir.y <= 0)) {
- index += 2;
- }
- if(dir.x != 0 && dir.y != 0) {
- index += 1;
- }
- return index;
+ if(dir.x == 0 && dir.y == -1) {
+ return 0;
+ } else if(dir.x == 1 && dir.y == -1) {
+ return 1;
+ } else if(dir.x == 1 && dir.y == 0) {
+ return 2;
+ } else if(dir.x == 1 && dir.y == 1) {
+ return 3;
+ } else if(dir.x == 0 && dir.y == 1) {
+ return 4;
+ } else if(dir.x == -1 && dir.y == 1) {
+ return 5;
+ } else if(dir.x == -1 && dir.y == 0) {
+ return 6;
+ } else if(dir.x == -1 && dir.y == -1) {
+ return 7;
+ }
+ Engine::log(DEBUG, "physics.getDirectionIndex ") << "invalid direction: " << dir;
+ return 0;
}
/**
@@ -326,20 +334,20 @@
assert(hit != prev);
- int dirIdx = getDirectionIndex(hit-prev);
+ int dirIdx = getDirectionIndex(prev-hit);
float tmp1 = hit.x-prev.x;
float tmp2 = hit.y-prev.y;
- Engine::log(DEBUG, "physics.getNormal ") << dirIdx << " " << tmp1 << " " << tmp2;
+// Engine::log(DEBUG, "physics.getNormal ") << dirIdx << " " << tmp1 << " " << tmp2;
for(int i = 1; i <= 2; i++) {
if(getType(hit+DIRECTIONS[(dirIdx+i) % 8]) == EMPTY)
frees.push_back(DIRECTIONS[(dirIdx+i) % 8]);
- else
+ else
break;
}
for(int i = 1; i <= 2; i++) {
- if(getType(hit+DIRECTIONS[(dirIdx-i) % 8]) == EMPTY)
- frees.push_back(DIRECTIONS[(dirIdx-i) % 8]);
+ if(getType(hit+DIRECTIONS[(dirIdx-i+8) % 8]) == EMPTY)
+ frees.push_back(DIRECTIONS[(dirIdx-i+8) % 8]);
else
break;
}
@@ -349,6 +357,7 @@
for(unsigned int i = 0; i < frees.size(); i++) {
normal += frees[i];
}
+ Engine::log(DEBUG, "physics.getNormal ") << "normal: " << normal;
return normal;
}