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
Scale bounding sphere #1155
Scale bounding sphere #1155
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -701,6 +701,7 @@ define([ | |
* @exception {DeveloperError} sphere is required. | ||
* @exception {DeveloperError} transform is required. | ||
*/ | ||
var radiusScratch = new Cartesian3(); | ||
BoundingSphere.transform = function(sphere, transform, result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test explicitly for this to |
||
if (!defined(sphere)) { | ||
throw new DeveloperError('sphere is required.'); | ||
|
@@ -716,8 +717,12 @@ define([ | |
|
||
Matrix4.multiplyByPoint(transform, sphere.center, transformCart4); | ||
|
||
Cartesian3.clone(transformCart4, result.center); | ||
result.radius = sphere.radius; | ||
result.center = Cartesian3.clone(transformCart4, result.center); | ||
var r = Cartesian3.magnitude(Matrix4.getColumn(transform, 0, radiusScratch)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
r = Math.max(r, Cartesian3.magnitude(Matrix4.getColumn(transform, 1, radiusScratch))); | ||
r = Math.max(r, Cartesian3.magnitude(Matrix4.getColumn(transform, 2, radiusScratch))); | ||
result.radius = r * sphere.radius; | ||
|
||
return result; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -765,7 +765,8 @@ define([ | |
for (var i = 0; i < length; i += 3) { | ||
Cartesian3.unpack(values, i, scratchCartesian3); | ||
Matrix3.multiplyByVector(matrix, scratchCartesian3, scratchCartesian4); | ||
Cartesian3.pack(scratchCartesian4, values, i); | ||
scratchCartesian3 = Cartesian3.normalize(scratchCartesian4, scratchCartesian3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need another scratch variable, right? The input can be the same as the output so we can just use |
||
Cartesian3.pack(scratchCartesian3, values, i); | ||
} | ||
} | ||
} | ||
|
@@ -827,8 +828,7 @@ define([ | |
var boundingSphere = instance.geometry.boundingSphere; | ||
|
||
if (defined(boundingSphere)) { | ||
Matrix4.multiplyByPoint(modelMatrix, boundingSphere.center, boundingSphere.center); | ||
boundingSphere.center = Cartesian3.fromCartesian4(boundingSphere.center); | ||
instance.geometry.boundingSphere = BoundingSphere.transform(boundingSphere, modelMatrix, boundingSphere); | ||
} | ||
|
||
instance.modelMatrix = Matrix4.IDENTITY.clone(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -812,6 +812,49 @@ defineSuite([ | |
expect(transformed.modelMatrix).toEqual(Matrix4.IDENTITY); | ||
}); | ||
|
||
it('transformToWorldCoordinates with uniform scale', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to test with a non-uniform scale? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need both tests now? |
||
var instance = new GeometryInstance({ | ||
geometry : new Geometry({ | ||
attributes : { | ||
position : new GeometryAttribute({ | ||
componentDatatype : ComponentDatatype.FLOAT, | ||
componentsPerAttribute : 3, | ||
values : [ | ||
0.0, 0.0, 0.0, | ||
1.0, 0.0, 0.0, | ||
0.0, 1.0, 0.0 | ||
] | ||
}), | ||
normal : new GeometryAttribute({ | ||
componentDatatype : ComponentDatatype.FLOAT, | ||
componentsPerAttribute : 3, | ||
values : [ | ||
0.0, 0.0, 1.0, | ||
0.0, 0.0, 1.0, | ||
0.0, 0.0, 1.0 | ||
] | ||
}) | ||
}, | ||
indices : [0, 1, 2], | ||
primitiveType : PrimitiveType.TRIANGLES, | ||
boundingSphere : new BoundingSphere(new Cartesian3(0.5, 0.5, 0.0), 1.0) | ||
}), | ||
modelMatrix : Matrix4.multiplyByUniformScale(new Matrix4(0.0, 0.0, 1.0, 0.0, | ||
1.0, 0.0, 0.0, 0.0, | ||
0.0, 1.0, 0.0, 0.0, | ||
0.0, 0.0, 0.0, 1.0), 2) | ||
}); | ||
|
||
var transformed = GeometryPipeline.transformToWorldCoordinates(instance); | ||
var transformedPositions = [0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 2.0]; | ||
var transformedNormals = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0]; | ||
|
||
expect(transformed.geometry.attributes.position.values).toEqual(transformedPositions); | ||
expect(transformed.geometry.attributes.normal.values).toEqual(transformedNormals); | ||
expect(transformed.geometry.boundingSphere).toEqual(new BoundingSphere(new Cartesian3(0.0, 1.0, 1.0), 2.0)); | ||
expect(transformed.modelMatrix).toEqual(Matrix4.IDENTITY); | ||
}); | ||
|
||
it('transformToWorldCoordinates does nothing when already in world coordinates', function() { | ||
var instance = new GeometryInstance({ | ||
geometry : new Geometry({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a better name. Radius is a scalar. This is a vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable also needs to be placed before the JSDoc comment above, so that the JSDoc is correctly attached to
BoundingSphere.transform
.