Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit 130b056

Browse files
committed
Merge pull request #87 from OpenGeoscience/view-array-type
Allow setting the camera view matrix as a specific datatype.
2 parents 1c28288 + 1bd79d5 commit 130b056

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/camera.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,16 @@ vgl.camera = function (arg) {
425425
* it won't be recomputed unless something else changes.
426426
*
427427
* @param {mat4} view: new view matrix.
428+
* @param {boolean} preserveType: if true, clone the input using slice. This
429+
* can be used to ensure the array is a specific precision.
428430
*/
429431
////////////////////////////////////////////////////////////////////////////
430-
this.setViewMatrix = function (view) {
431-
mat4.copy(m_viewMatrix, view);
432+
this.setViewMatrix = function (view, preserveType) {
433+
if (!preserveType) {
434+
mat4.copy(m_viewMatrix, view);
435+
} else {
436+
m_viewMatrix = view.slice();
437+
}
432438
m_computeModelViewMatrixTime.modified();
433439
};
434440

src/renderer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,14 @@ vgl.renderer = function (arg) {
266266
actor = sortedActors[i][1];
267267
if (actor.referenceFrame() ===
268268
vgl.boundingObject.ReferenceFrame.Relative) {
269-
mat4.multiply(renSt.m_modelViewMatrix, m_this.m_camera.viewMatrix(),
270-
actor.matrix());
269+
var view = m_this.m_camera.viewMatrix();
270+
/* If the view matrix is a plain array, keep it as such. This is
271+
* intended to preserve precision, and will only be the case if the
272+
* view matrix was created by delibrately setting it as an array. */
273+
if (view instanceof Array) {
274+
renSt.m_modelViewMatrix = new Array(16);
275+
}
276+
mat4.multiply(renSt.m_modelViewMatrix, view, actor.matrix());
271277
renSt.m_projectionMatrix = m_this.m_camera.projectionMatrix();
272278
renSt.m_modelViewAlignment = m_this.m_camera.viewAlignment();
273279
} else {

0 commit comments

Comments
 (0)