Skip to content

Commit

Permalink
fix bounding spheres
Browse files Browse the repository at this point in the history
  • Loading branch information
hpinkos committed Sep 3, 2013
1 parent aafd83c commit eaecef1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 73 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change Log
Beta Releases
-------------

### b21 - 2013-10-01
* Added `CorridorOutlineGeometry`.

### b20 - 2013-09-03

_This releases fixes 2D and other issues with Chrome 29.0.1547.57 ([#1002](https://github.com/AnalyticalGraphicsInc/cesium/issues/1002) and [#1047](https://github.com/AnalyticalGraphicsInc/cesium/issues/1047))._
Expand Down Expand Up @@ -59,7 +62,7 @@ var geometry = BoxGeometry.createGeometry(box);
* Replaced `createPickFragmentShaderSource` with `createShaderSource`.
* Renamed `PolygonPipeline.earClip2D` to `PolygonPipeline.triangulate`.
* Added outline geometries. [#1021](https://github.com/AnalyticalGraphicsInc/cesium/pull/1021).
* Added `CorridorGeometry` and `CorridorOutlineGeometry`.
* Added `CorridorGeometry`.
* Added `Billboard.scaleByDistance` and `NearFarScalar` to control billboard minimum/maximum scale based on camera distance.
* Added `EllipsoidGeodesic`.
* Added `PolylinePipeline.scaleToSurface`.
Expand Down
21 changes: 8 additions & 13 deletions Source/Core/CorridorGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ define([

return {
attributes : attributes,
indices : indices,
boundingSphere : BoundingSphere.fromVertices(finalPositions)
indices : indices
};
}

Expand Down Expand Up @@ -567,7 +566,6 @@ define([
var extrudedHeight = params.extrudedHeight;
var attributes = attr.attributes;
var indices = attr.indices;
var boundingSphere = attr.boundingSphere;
var positions = attributes.position.values;
var length = positions.length;
var newPositions = new Float64Array(length * 6);
Expand All @@ -582,7 +580,6 @@ define([
newPositions.set(positions);
newPositions.set(extrudedPositions, length);
newPositions.set(wallPositions, length * 2);
boundingSphere = BoundingSphere.fromVertices(positions, undefined, 3, boundingSphere);
attributes.position.values = newPositions;

length /= 3;
Expand Down Expand Up @@ -619,8 +616,7 @@ define([

return {
attributes : attributes,
indices : newIndices,
boundingSphere : boundingSphere
indices : newIndices
};
}

Expand Down Expand Up @@ -716,20 +712,19 @@ define([
} else {
var computedPositions = CorridorGeometryLibrary.computePositions(params);
attr = combine(computedPositions, vertexFormat, ellipsoid);
if (!vertexFormat.position) {
attr.attributes.position.values = undefined;
} else {
attr.attributes.position.values = new Float64Array(PolylinePipeline.scaleToGeodeticHeight(attr.attributes.position.values, height, ellipsoid, attr.attributes.position.values));
}

attr.attributes.position.values = new Float64Array(PolylinePipeline.scaleToGeodeticHeight(attr.attributes.position.values, height, ellipsoid, attr.attributes.position.values));
}
var attributes = attr.attributes;
var boundingSphere = BoundingSphere.fromVertices(attributes.position.values, undefined, 3);
if (!vertexFormat.position) {
attr.attributes.position.values = undefined;
}

return new Geometry({
attributes : attributes,
indices : attr.indices,
primitiveType : PrimitiveType.TRIANGLES,
boundingSphere : attr.boundingSphere
boundingSphere : boundingSphere
});
};

Expand Down
30 changes: 24 additions & 6 deletions Source/Core/CorridorGeometryLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define([
"use strict";

/**
* private
* @private
*/
var CorridorGeometryLibrary = {};

Expand All @@ -47,6 +47,9 @@ define([
var originScratch = new Cartesian3();
var nextScratch = new Cartesian3();
var prevScratch = new Cartesian3();
/**
* @private
*/
CorridorGeometryLibrary.angleIsGreaterThanPi = function(forward, backward, position, ellipsoid) {
var tangentPlane = new EllipsoidTangentPlane(position, ellipsoid);
var origin = tangentPlane.projectPointOntoPlane(position, originScratch);
Expand All @@ -61,6 +64,9 @@ define([

var quaterion = new Quaternion();
var rotMatrix = new Matrix3();
/**
* @private
*/
CorridorGeometryLibrary.computeRoundCorner = function (cornerPoint, startPoint, endPoint, cornerType, leftIsOutside, ellipsoid) {
var angle = Cartesian3.angleBetween(startPoint.subtract(cornerPoint, scratch1), endPoint.subtract(cornerPoint, scratch2));
var granularity = (cornerType.value === CornerType.BEVELED.value) ? 1 : Math.ceil(angle / CesiumMath.toRadians(5)) + 1;
Expand Down Expand Up @@ -91,6 +97,9 @@ define([
return array;
};

/**
* @private
*/
CorridorGeometryLibrary.addEndCaps = function (calculatedPositions, width, ellipsoid) {
var cornerPoint = cartesian1;
var startPoint = cartesian2;
Expand All @@ -113,6 +122,9 @@ define([
return [firstEndCap, lastEndCap];
};

/**
* @private
*/
CorridorGeometryLibrary.computeMiteredCorner = function (position, startPoint, leftCornerDirection, lastPoint, leftIsOutside, granularity, ellipsoid) {
var cornerPoint = scratch1;
if (leftIsOutside) {
Expand All @@ -124,6 +136,9 @@ define([
return [cornerPoint.x, cornerPoint.y, cornerPoint.z, lastPoint.x, lastPoint.y, lastPoint.z];
};

/**
* @private
*/
CorridorGeometryLibrary.addAttribute = function (attribute, value, front, back) {
var x = value.x;
var y = value.y;
Expand All @@ -140,7 +155,7 @@ define([
}
};

CorridorGeometryLibrary.addShiftedPositions = function(positions, left, scalar, calculatedPositions) {
function addShiftedPositions (positions, left, scalar, calculatedPositions) {
var rightPositions = new Array(positions.length);
var leftPositions = new Array(positions.length);
var scaledLeft = left.multiplyByScalar(scalar, scratch1);
Expand All @@ -163,8 +178,11 @@ define([
calculatedPositions.push(rightPositions, leftPositions);

return calculatedPositions;
};
}

/**
* @private
*/
CorridorGeometryLibrary.computePositions = function (params) {
var granularity = params.granularity;
var positions = params.positions;
Expand Down Expand Up @@ -222,7 +240,7 @@ define([
scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]);
scaleArray2[1] = Cartesian3.clone(center, scaleArray2[1]);
subdividedPositions = PolylinePipeline.scaleToSurface(scaleArray2, granularity, ellipsoid);
calculatedPositions = CorridorGeometryLibrary.addShiftedPositions(subdividedPositions, left, width, calculatedPositions);
calculatedPositions = addShiftedPositions(subdividedPositions, left, width, calculatedPositions);
if (saveAttributes) {
calculatedLefts.push(left.x, left.y, left.z);
calculatedNormals.push(normal.x, normal.y, normal.z);
Expand All @@ -243,7 +261,7 @@ define([
scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]);
scaleArray2[1] = Cartesian3.clone(center, scaleArray2[1]);
subdividedPositions = PolylinePipeline.scaleToSurface(scaleArray2, granularity, ellipsoid);
calculatedPositions = CorridorGeometryLibrary.addShiftedPositions(subdividedPositions, left, width, calculatedPositions);
calculatedPositions = addShiftedPositions(subdividedPositions, left, width, calculatedPositions);
if (saveAttributes) {
calculatedLefts.push(left.x, left.y, left.z);
calculatedNormals.push(normal.x, normal.y, normal.z);
Expand All @@ -267,7 +285,7 @@ define([
scaleArray2[0] = Cartesian3.clone(previousPos, scaleArray2[0]);
scaleArray2[1] = Cartesian3.clone(position, scaleArray2[1]);
subdividedPositions = PolylinePipeline.scaleToSurface(scaleArray2, granularity, ellipsoid);
calculatedPositions = CorridorGeometryLibrary.addShiftedPositions(subdividedPositions, left, width, calculatedPositions);
calculatedPositions = addShiftedPositions(subdividedPositions, left, width, calculatedPositions);
if (saveAttributes) {
calculatedLefts.push(left.x, left.y, left.z);
calculatedNormals.push(normal.x, normal.y, normal.z);
Expand Down
Loading

0 comments on commit eaecef1

Please sign in to comment.