src/Terrain.cc
changeset 377 01d3c340b372
parent 370 39e59dd36b6e
child 406 a2e35ca66c74
equal deleted inserted replaced
376:2fd7fd2ee1a1 377:01d3c340b372
   347 Vector Terrain::getNormal(Vector point, Vector prevPoint) const {
   347 Vector Terrain::getNormal(Vector point, Vector prevPoint) const {
   348     PixelCoordinate p = getPixelCoordinate(point);
   348     PixelCoordinate p = getPixelCoordinate(point);
   349 
   349 
   350     assert(point != prevPoint);
   350     assert(point != prevPoint);
   351 
   351 
   352     Vector normal(0,0);
   352     Vector normal(0, 0);
   353 
   353 
   354     // These two must be rounded separately
   354     // These two must be rounded separately
   355     int dirIdx = getDirectionIndex(prevPoint.roundToInt() - point.roundToInt());
   355     int dirIdx = getDirectionIndex(prevPoint.roundToInt() - point.roundToInt());
   356 
   356 
   357     normal += DIRECTIONS[dirIdx];
   357     normal += DIRECTIONS[dirIdx];
   358 
   358 
   359     for (int i = 1; i <= 2; i++) {
   359     for (int i = 1; i <= 2; i++) {
   360         if (getType(point + DIRECTIONS[(dirIdx+i+8)%8]) == TERRAIN_EMPTY) {
   360         if (getType(point + DIRECTIONS[(dirIdx + i + 8) % 8]) == TERRAIN_EMPTY) {
   361             normal += DIRECTIONS[(dirIdx+i+8)%8];
   361             normal += DIRECTIONS[(dirIdx + i + 8) % 8];
   362         }
   362         }
   363     }
   363     }
   364 
   364 
   365     for (int i = 1; i <= 2; i++) {
   365     for (int i = 1; i <= 2; i++) {
   366         if (getType(point + DIRECTIONS[(dirIdx-i+8)%8]) == TERRAIN_EMPTY) {
   366         if (getType(point + DIRECTIONS[(dirIdx - i + 8) % 8]) == TERRAIN_EMPTY) {
   367             normal += DIRECTIONS[(dirIdx-i+8)%8];
   367             normal += DIRECTIONS[(dirIdx - i + 8) % 8];
   368         }
   368         }
   369     }
   369     }
   370 
   370 
   371     if (getType(point) == TERRAIN_EMPTY || getType(prevPoint) != TERRAIN_EMPTY) {
   371     if (getType(point) == TERRAIN_EMPTY || getType(prevPoint) != TERRAIN_EMPTY) {
   372         Engine::log(DEBUG, "Physics.getNormal ") << "logic ground error";
   372         Engine::log(DEBUG, "Physics.getNormal ") << "logic ground error";