Skip to content

Commit

Permalink
Incorporate some changes from Billboards in #2669.
Browse files Browse the repository at this point in the history
  • Loading branch information
emackey committed Apr 29, 2015
1 parent 62a4593 commit 31c7920
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions Source/Scene/PointPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ define([
var scratchMatrix4 = new Matrix4();
var scratchCartesian4 = new Cartesian4();

PointPrimitive._computeScreenSpacePosition = function(modelMatrix, position, scene) {
PointPrimitive._computeScreenSpacePosition = function(modelMatrix, position, scene, result) {
// This function is basically a stripped-down JavaScript version of PointPrimitiveCollectionVS.glsl
var camera = scene.camera;
var view = camera.viewMatrix;
Expand All @@ -401,7 +401,7 @@ define([
var mv = Matrix4.multiplyTransformation(view, modelMatrix, scratchMatrix4);
var positionEC = Matrix4.multiplyByVector(mv, Cartesian4.fromElements(position.x, position.y, position.z, 1, scratchCartesian4), scratchCartesian4);
var positionCC = Matrix4.multiplyByVector(projection, positionEC, scratchCartesian4); // clip coordinates
var positionWC = SceneTransforms.clipToGLWindowCoordinates(scene, positionCC, new Cartesian2());
var positionWC = SceneTransforms.clipToGLWindowCoordinates(scene, positionCC, result);

return positionWC;
};
Expand All @@ -412,15 +412,19 @@ define([
* left to right, and <code>y</code> increases from top to bottom.
*
* @param {Scene} scene The scene.
* @param {Cartesian2} [result] The object onto which to store the result.
* @returns {Cartesian2} The screen-space position of the point.
*
* @exception {DeveloperError} PointPrimitive must be in a collection.
*
* @example
* console.log(p.computeScreenSpacePosition(scene).toString());
*/
PointPrimitive.prototype.computeScreenSpacePosition = function(scene) {
PointPrimitive.prototype.computeScreenSpacePosition = function(scene, result) {
var pointPrimitiveCollection = this._pointPrimitiveCollection;
if (!defined(result)) {
result = new Cartesian2();
}

//>>includeStart('debug', pragmas.debug);
if (!defined(pointPrimitiveCollection)) {
Expand All @@ -432,7 +436,7 @@ define([
//>>includeEnd('debug');

var modelMatrix = pointPrimitiveCollection.modelMatrix;
var windowCoordinates = PointPrimitive._computeScreenSpacePosition(modelMatrix, this._actualPosition, scene);
var windowCoordinates = PointPrimitive._computeScreenSpacePosition(modelMatrix, this._actualPosition, scene, result);
windowCoordinates.y = scene.canvas.clientHeight - windowCoordinates.y;
return windowCoordinates;
};
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/PointPrimitiveCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ define([
boundingVolume.radius += size;
}

var writers = [];
var scratchWriterArray = [];

/**
* @private
Expand Down Expand Up @@ -725,6 +725,7 @@ define([
} else {
// PointPrimitives were modified, but none were added or removed.
if (pointPrimitivesToUpdateLength > 0) {
var writers = scratchWriterArray;
writers.length = 0;

if (properties[POSITION_INDEX] || properties[OUTLINE_WIDTH_INDEX] || properties[PIXEL_SIZE_INDEX]) {
Expand Down
7 changes: 7 additions & 0 deletions Specs/Scene/PointPrimitiveCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ defineSuite([
expect(pointPrimitives.contains(new Cartesian2())).toEqual(false);
});

it('does not render when constructed', function() {
expect(scene.renderForSpecs()).toEqual([0, 0, 0, 255]);
});

it('modifies and removes a pointPrimitive, then renders', function() {
var p1 = pointPrimitives.add({
position : Cartesian3.ZERO,
Expand Down Expand Up @@ -659,6 +663,7 @@ defineSuite([
}
});

// This tests the `PointPrimitiveCollection.equals` function itself, not simple equality.
expect(p.equals(p2)).toEqual(true);
});

Expand All @@ -670,10 +675,12 @@ defineSuite([
position : new Cartesian3(4.0, 5.0, 6.0)
});

// This tests the `PointPrimitiveCollection.equals` function itself, not simple equality.
expect(p.equals(p2)).toEqual(false);
});

it('does not equal undefined', function() {
// This tests the `PointPrimitiveCollection.equals` function itself, not simple equality.
var pointPrimitive = pointPrimitives.add();
expect(pointPrimitive.equals(undefined)).toEqual(false);
});
Expand Down

0 comments on commit 31c7920

Please sign in to comment.