Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ellipse texture coords #2475

Merged
merged 2 commits into from
Feb 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

### 1.7 - 2015-03-02

* Fixed incorrect ellipse texture coordinates. [#2363](https://github.com/AnalyticalGraphicsInc/cesium/issues/2363) and [#2465](https://github.com/AnalyticalGraphicsInc/cesium/issues/2465)

### 1.6 - 2015-02-02

* Breaking changes
Expand Down
41 changes: 39 additions & 2 deletions Source/Core/EllipseGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ define([
var scratchCartographic = new Cartographic();
var projectedCenterScratch = new Cartesian3();

var scratchMinTexCoord = new Cartesian2();
var scratchMaxTexCoord = new Cartesian2();

function computeTopBottomAttributes(positions, options, extrude) {
var vertexFormat = options.vertexFormat;
var center = options.center;
var semiMajorAxis = options.semiMajorAxis;
var semiMinorAxis = options.semiMinorAxis;
var ellipsoid = options.ellipsoid;
var stRotation = options.stRotation;
var size = (extrude) ? positions.length / 3 * 2 : positions.length / 3;
Expand All @@ -91,6 +95,9 @@ define([
var rotation = Quaternion.fromAxisAngle(geodeticNormal, stRotation, quaternionScratch);
var textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrixScratch);

var minTexCoord = Cartesian2.fromElements(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, scratchMinTexCoord);
var maxTexCoord = Cartesian2.fromElements(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, scratchMaxTexCoord);

var length = positions.length;
var bottomOffset = (extrude) ? length : 0;
var stOffset = bottomOffset / 3 * 2;
Expand All @@ -105,7 +112,12 @@ define([
Cartesian3.subtract(projectedPoint, projectedCenter, projectedPoint);

texCoordScratch.x = (projectedPoint.x + semiMajorAxis) / (2.0 * semiMajorAxis);
texCoordScratch.y = (projectedPoint.y + semiMajorAxis) / (2.0 * semiMajorAxis);
texCoordScratch.y = (projectedPoint.y + semiMinorAxis) / (2.0 * semiMinorAxis);

minTexCoord.x = Math.min(texCoordScratch.x, minTexCoord.x);
minTexCoord.y = Math.min(texCoordScratch.y, minTexCoord.y);
maxTexCoord.x = Math.max(texCoordScratch.x, maxTexCoord.x);
maxTexCoord.y = Math.max(texCoordScratch.y, maxTexCoord.y);

if (extrude) {
textureCoordinates[textureCoordIndex + stOffset] = texCoordScratch.x;
Expand Down Expand Up @@ -159,6 +171,14 @@ define([
}
}

if (vertexFormat.st) {
length = textureCoordinates.length;
for (var k = 0; k < length; k += 2) {
textureCoordinates[k] = (textureCoordinates[k] - minTexCoord.x) / (maxTexCoord.x - minTexCoord.x);
textureCoordinates[k + 1] = (textureCoordinates[k + 1] - minTexCoord.y) / (maxTexCoord.y - minTexCoord.y);
}
}

var attributes = new GeometryAttributes();

if (vertexFormat.position) {
Expand Down Expand Up @@ -311,6 +331,7 @@ define([
var vertexFormat = options.vertexFormat;
var center = options.center;
var semiMajorAxis = options.semiMajorAxis;
var semiMinorAxis = options.semiMinorAxis;
var ellipsoid = options.ellipsoid;
var height = options.height;
var extrudedHeight = options.extrudedHeight;
Expand Down Expand Up @@ -339,6 +360,9 @@ define([
var rotation = Quaternion.fromAxisAngle(geodeticNormal, stRotation, quaternionScratch);
var textureMatrix = Matrix3.fromQuaternion(rotation, textureMatrixScratch);

var minTexCoord = Cartesian2.fromElements(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, scratchMinTexCoord);
var maxTexCoord = Cartesian2.fromElements(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, scratchMaxTexCoord);

var length = positions.length;
var stOffset = length / 3 * 2;
for ( var i = 0; i < length; i += 3) {
Expand All @@ -353,7 +377,12 @@ define([
Cartesian3.subtract(projectedPoint, projectedCenter, projectedPoint);

texCoordScratch.x = (projectedPoint.x + semiMajorAxis) / (2.0 * semiMajorAxis);
texCoordScratch.y = (projectedPoint.y + semiMajorAxis) / (2.0 * semiMajorAxis);
texCoordScratch.y = (projectedPoint.y + semiMinorAxis) / (2.0 * semiMinorAxis);

minTexCoord.x = Math.min(texCoordScratch.x, minTexCoord.x);
minTexCoord.y = Math.min(texCoordScratch.y, minTexCoord.y);
maxTexCoord.x = Math.max(texCoordScratch.x, maxTexCoord.x);
maxTexCoord.y = Math.max(texCoordScratch.y, maxTexCoord.y);

textureCoordinates[textureCoordIndex + stOffset] = texCoordScratch.x;
textureCoordinates[textureCoordIndex + 1 + stOffset] = texCoordScratch.y;
Expand Down Expand Up @@ -422,6 +451,14 @@ define([
}
}

if (vertexFormat.st) {
length = textureCoordinates.length;
for (var k = 0; k < length; k += 2) {
textureCoordinates[k] = (textureCoordinates[k] - minTexCoord.x) / (maxTexCoord.x - minTexCoord.x);
textureCoordinates[k + 1] = (textureCoordinates[k + 1] - minTexCoord.y) / (maxTexCoord.y - minTexCoord.y);
}
}

var attributes = new GeometryAttributes();

if (vertexFormat.position) {
Expand Down