Skip to content

Commit

Permalink
HeightmapTessellator tweaks from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Feb 11, 2013
1 parent d886402 commit 22f66cb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
21 changes: 11 additions & 10 deletions Source/Core/HeightmapTessellator.js
Expand Up @@ -140,7 +140,7 @@ define([
var sqrt = Math.sqrt;
var atan = Math.atan;
var exp = Math.exp;
var piOverTwo = Math.PI / 2.0;
var piOverTwo = CesiumMath.PI_OVER_TWO;
var toRadians = CesiumMath.toRadians;

var vertices = description.vertices;
Expand Down Expand Up @@ -201,8 +201,8 @@ define([

var vertexArrayIndex = 0;

var minHeight = 65536.0;
var maxHeight = -65536.0;
var minimumHeight = 65536.0;
var maximumHeight = -65536.0;

var startRow = 0;
var endRow = height;
Expand Down Expand Up @@ -278,8 +278,8 @@ define([

heightSample = heightSample * heightScale + heightOffset;

maxHeight = Math.max(maxHeight, heightSample);
minHeight = Math.min(minHeight, heightSample);
maximumHeight = Math.max(maximumHeight, heightSample);
minimumHeight = Math.min(minimumHeight, heightSample);

if (colIndex !== col || rowIndex !== row) {
heightSample -= skirtHeight;
Expand All @@ -292,10 +292,11 @@ define([
var kY = radiiSquaredY * nY;

var gamma = sqrt((kX * nX) + (kY * nY) + (kZ * nZ));
var oneOverGamma = 1.0 / gamma;

var rSurfaceX = kX / gamma;
var rSurfaceY = kY / gamma;
var rSurfaceZ = kZ / gamma;
var rSurfaceX = kX * oneOverGamma;
var rSurfaceY = kY * oneOverGamma;
var rSurfaceZ = kZ * oneOverGamma;

vertices[vertexArrayIndex++] = rSurfaceX + nX * heightSample - relativeToCenter.x;
vertices[vertexArrayIndex++] = rSurfaceY + nY * heightSample - relativeToCenter.y;
Expand All @@ -311,8 +312,8 @@ define([
}

return {
maxHeight : maxHeight,
minHeight : minHeight
maximumHeight : maximumHeight,
minimumHeight : minimumHeight
};
};

Expand Down
10 changes: 5 additions & 5 deletions Source/Scene/CentralBodySurface.js
Expand Up @@ -542,7 +542,7 @@ define([

if (frameState.mode !== SceneMode.SCENE3D) {
boundingVolume = boundingSphereScratch;
BoundingSphere.fromExtentWithHeights2D(tile.extent, frameState.scene2D.projection, tile.minHeight, tile.maxHeight, boundingVolume);
BoundingSphere.fromExtentWithHeights2D(tile.extent, frameState.scene2D.projection, tile.minimumHeight, tile.maximumHeight, boundingVolume);
boundingVolume.center = new Cartesian3(boundingVolume.center.z, boundingVolume.center.x, boundingVolume.center.y);

if (frameState.mode === SceneMode.MORPHING) {
Expand Down Expand Up @@ -579,7 +579,7 @@ define([
var southNormal = tile.southNormal;
var eastNormal = tile.eastNormal;
var northNormal = tile.northNormal;
var maxHeight = tile.maxHeight;
var maximumHeight = tile.maximumHeight;

if (frameState.mode !== SceneMode.SCENE3D) {
southwestCornerCartesian = frameState.scene2D.projection.project(tile.extent.getSouthwest(), southwestCornerScratch);
Expand All @@ -594,7 +594,7 @@ define([
eastNormal = Cartesian3.UNIT_Y;
southNormal = negativeUnitZ;
northNormal = Cartesian3.UNIT_Z;
maxHeight = 0.0;
maximumHeight = 0.0;
}

var vectorFromSouthwestCorner = cameraCartesianPosition.subtract(southwestCornerCartesian, vectorScratch);
Expand All @@ -611,7 +611,7 @@ define([
} else {
cameraHeight = cameraCartesianPosition.x;
}
var distanceFromTop = cameraHeight - maxHeight;
var distanceFromTop = cameraHeight - maximumHeight;

var result = 0.0;

Expand Down Expand Up @@ -1481,7 +1481,7 @@ define([
var boundingVolume = tile.boundingSphere3D;

if (frameState.mode !== SceneMode.SCENE3D) {
boundingVolume = BoundingSphere.fromExtentWithHeights2D(tile.extent, frameState.scene2D.projection, tile.minHeight, tile.maxHeight);
boundingVolume = BoundingSphere.fromExtentWithHeights2D(tile.extent, frameState.scene2D.projection, tile.minimumHeight, tile.maximumHeight);
boundingVolume.center = new Cartesian3(boundingVolume.center.z, boundingVolume.center.x, boundingVolume.center.y);

if (frameState.mode === SceneMode.MORPHING) {
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/HeightmapTerrainData.js
Expand Up @@ -149,8 +149,8 @@ define([
center,
new Float32Array(result.vertices),
TerrainProvider.getRegularGridIndices(result.gridWidth, result.gridHeight),
result.minHeight,
result.maxHeight,
result.minimumHeight,
result.maximumHeight,
result.boundingSphere3D,
result.occludeePointInScaledSpace);
});
Expand Down
10 changes: 5 additions & 5 deletions Source/Scene/TerrainMesh.js
Expand Up @@ -17,14 +17,14 @@ define([
* the Cartesian position of the vertex, H is the height above the ellipsoid, and
* U and V are the texture coordinates.
* @param {Uint16Array} indices The indices describing how the vertices are connected to form triangles.
* @param {Number} minHeight The lowest height in the tile, in meters above the ellipsoid.
* @param {Number} maxHeight The highest height in the tile, in meters above the ellipsoid.
* @param {Number} minimumHeight The lowest height in the tile, in meters above the ellipsoid.
* @param {Number} maximumHeight The highest height in the tile, in meters above the ellipsoid.
* @param {BoundingSphere} boundingSphere3D A bounding sphere that completely contains the tile.
* @param {Cartesian3} occludeePointInScaledSpace The occludee point of the tile, represented in ellipsoid-
* scaled space, and used for horizon culling. If this point is below the horizon,
* the tile is considered to be entirely below the horizon.
*/
var TerrainMesh = function TerrainMesh(center, vertices, indices, minHeight, maxHeight, boundingSphere3D, occludeePointInScaledSpace) {
var TerrainMesh = function TerrainMesh(center, vertices, indices, minimumHeight, maximumHeight, boundingSphere3D, occludeePointInScaledSpace) {
/**
* The center of the tile. Vertex positions are specified relative to this center.
* @type {Cartesian3}
Expand All @@ -50,13 +50,13 @@ define([
* The lowest height in the tile, in meters above the ellipsoid.
* @type {Number}
*/
this.minHeight = minHeight;
this.minimumHeight = minimumHeight;

/**
* The highest height in the tile, in meters above the ellipsoid.
* @type {Number}
*/
this.maxHeight = maxHeight;
this.maximumHeight = maximumHeight;

/**
* A bounding sphere that completely contains the tile.
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/Tile.js
Expand Up @@ -199,8 +199,8 @@ define([
this.terrainData = undefined;
this.center = new Cartesian3(0.0, 0.0, 0.0);
this.vertexArray = undefined;
this.minHeight = 0.0;
this.maxHeight = 0.0;
this.minimumHeight = 0.0;
this.maximumHeight = 0.0;
this.boundingSphere3D = new BoundingSphere();
this.boundingSphere2D = new BoundingSphere();
this.occludeePointInScaledSpace = new Cartesian3(0.0, 0.0, 0.0);
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/TileTerrain.js
Expand Up @@ -64,8 +64,8 @@ define([
TileTerrain.prototype.publishToTile = function(tile) {
var mesh = this.mesh;
Cartesian3.clone(mesh.center, tile.center);
tile.minHeight = mesh.minHeight;
tile.maxHeight = mesh.maxHeight;
tile.minimumHeight = mesh.minimumHeight;
tile.maximumHeight = mesh.maximumHeight;
BoundingSphere.clone(mesh.boundingSphere3D, tile.boundingSphere3D);

if (typeof mesh.occludeePointInScaledSpace !== 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions Source/Workers/createVerticesFromHeightmap.js
Expand Up @@ -55,8 +55,8 @@ define([
return {
vertices : vertices.buffer,
numberOfAttributes : numberOfAttributes,
minHeight : statistics.minHeight,
maxHeight : statistics.maxHeight,
minimumHeight : statistics.minimumHeight,
maximumHeight : statistics.maximumHeight,
gridWidth : arrayWidth,
gridHeight : arrayHeight,
boundingSphere3D : boundingSphere3D,
Expand Down

0 comments on commit 22f66cb

Please sign in to comment.