Skip to content

Commit

Permalink
Fix broken mapObjIsAboveGround and incorrect lighting normals due to …
Browse files Browse the repository at this point in the history
…ELEVATION_SCALE.

Changelog: Fix projectiles going through terrain due to bad terrain height calculations.
Changelog: Fix terrain shading.
  • Loading branch information
Cyp committed Nov 16, 2010
1 parent 1aad6e7 commit 08f9fa5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
48 changes: 24 additions & 24 deletions src/lighting.c
Expand Up @@ -155,17 +155,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX + 1),
world_coord(tileY),
tileRight->height - rMod
tileRight->height * ELEVATION_SCALE - rMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY + 1),
tileDownRight->height - drMod
tileDownRight->height * ELEVATION_SCALE - drMod
},
corner3 = {
world_coord(tileX),
world_coord(tileY + 1),
tileDown->height - dMod
tileDown->height * ELEVATION_SCALE - dMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -176,17 +176,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX),
world_coord(tileY),
psTile->height - nMod
psTile->height * ELEVATION_SCALE - nMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY),
tileRight->height - rMod
tileRight->height * ELEVATION_SCALE - rMod
},
corner3 = {
world_coord(tileX),
world_coord(tileY + 1),
tileDown->height - dMod
tileDown->height * ELEVATION_SCALE - dMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -200,17 +200,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX),
world_coord(tileY),
psTile->height - nMod
psTile->height * ELEVATION_SCALE - nMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY),
tileRight->height - rMod
tileRight->height * ELEVATION_SCALE - rMod
},
corner3 = {
world_coord(tileX + 1),
world_coord(tileY + 1),
tileDownRight->height - drMod
tileDownRight->height * ELEVATION_SCALE - drMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -221,17 +221,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX),
world_coord(tileY),
psTile->height - nMod
psTile->height * ELEVATION_SCALE - nMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY + 1),
tileDownRight->height - drMod
tileDownRight->height * ELEVATION_SCALE - drMod
},
corner3 = {
world_coord(tileX),
world_coord(tileY + 1),
tileDown->height - dMod
tileDown->height * ELEVATION_SCALE - dMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -248,17 +248,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX),
world_coord(tileY),
psTile->height - nMod
psTile->height * ELEVATION_SCALE - nMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY),
tileRight->height - rMod
tileRight->height * ELEVATION_SCALE - rMod
},
corner3 = {
world_coord(tileX),
world_coord(tileY + 1),
tileDown->height - dMod
tileDown->height * ELEVATION_SCALE - dMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -269,17 +269,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX + 1),
world_coord(tileY),
tileRight->height - rMod
tileRight->height * ELEVATION_SCALE - rMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY + 1),
tileDownRight->height - drMod
tileDownRight->height * ELEVATION_SCALE - drMod
},
corner3 = {
world_coord(tileX),
world_coord(tileY + 1),
tileDown->height - dMod
tileDown->height * ELEVATION_SCALE - dMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -293,17 +293,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX),
world_coord(tileY),
psTile->height - nMod
psTile->height * ELEVATION_SCALE - nMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY + 1),
tileDownRight->height - drMod
tileDownRight->height * ELEVATION_SCALE - drMod
},
corner3 = {
world_coord(tileX),
world_coord(tileY + 1),
tileDown->height - dMod
tileDown->height * ELEVATION_SCALE - dMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand All @@ -314,17 +314,17 @@ static void normalsOnTile(unsigned int tileX, unsigned int tileY, unsigned int q
corner1 = {
world_coord(tileX),
world_coord(tileY),
psTile->height - nMod
psTile->height * ELEVATION_SCALE - nMod
},
corner2 = {
world_coord(tileX + 1),
world_coord(tileY),
tileRight->height - rMod
tileRight->height * ELEVATION_SCALE - rMod
},
corner3 = {
world_coord(tileX + 1),
world_coord(tileY + 1),
tileDownRight->height - drMod
tileDownRight->height * ELEVATION_SCALE - drMod
};

normals[(*numNormals)++] = pie_SurfaceNormal3fv( corner1, corner2, corner3);
Expand Down
8 changes: 4 additions & 4 deletions src/map.c
Expand Up @@ -1329,10 +1329,10 @@ extern BOOL mapObjIsAboveGround( BASE_OBJECT *psObj )
tileY = map_coord(psObj->pos.y),
tileYOffset1 = (tileY * mapWidth),
tileYOffset2 = ((tileY+1) * mapWidth),
h1 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset1 + tileX) ].height,
h2 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset1 + tileX + 1)].height,
h3 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset2 + tileX) ].height,
h4 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset2 + tileX + 1)].height;
h1 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset1 + tileX) ].height * ELEVATION_SCALE,
h2 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset1 + tileX + 1)].height * ELEVATION_SCALE,
h3 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset2 + tileX) ].height * ELEVATION_SCALE,
h4 = psMapTiles[MIN(mapWidth * mapHeight, tileYOffset2 + tileX + 1)].height * ELEVATION_SCALE;

/* trivial test above */
if ( (psObj->pos.z > h1) && (psObj->pos.z > h2) &&
Expand Down

0 comments on commit 08f9fa5

Please sign in to comment.