Skip to content

Commit

Permalink
Pass viewIndex in getViewport and getProjectionMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Ninomiya authored and toji committed Jan 14, 2021
1 parent 7a75256 commit 7dd87cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/api/XRFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export default class XRFrame {
let viewerTransform = referenceSpace._getSpaceRelativeTransform(session[SESSION_PRIVATE].viewerSpace);

const views = [];
for (let viewSpace of session[SESSION_PRIVATE].viewSpaces) {
for (const viewSpace of session[SESSION_PRIVATE].viewSpaces) {
viewSpace._ensurePoseUpdated(device, this[PRIVATE].id);
let viewTransform = referenceSpace._getSpaceRelativeTransform(viewSpace);
let view = new XRView(device, viewTransform, viewSpace.eye, this[PRIVATE].sessionId);
let view = new XRView(device, viewTransform, viewSpace.eye, this[PRIVATE].sessionId, viewSpace.viewIndex);
views.push(view);
}
let viewerPose = new XRViewerPose(viewerTransform, views, false /* TODO: emulatedPosition */);
Expand Down
13 changes: 8 additions & 5 deletions src/api/XRView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* limitations under the License.
*/

import * as mat4 from 'gl-matrix/src/gl-matrix/mat4';

import XRViewport from './XRViewport';
import XRRigidTransform from './XRRigidTransform';

Expand All @@ -27,8 +25,9 @@ export default class XRView {
* @param {XRDevice} device
* @param {XREye} eye
* @param {number} sessionId
* @param {number} viewIndex
*/
constructor(device, transform, eye, sessionId) {
constructor(device, transform, eye, sessionId, viewIndex) {
if (!XREyes.includes(eye)) {
throw new Error(`XREye must be one of: ${XREyes}`);
}
Expand All @@ -46,6 +45,7 @@ export default class XRView {
temp,
sessionId,
transform,
viewIndex,
};
}

Expand All @@ -57,7 +57,9 @@ export default class XRView {
/**
* @return {Float32Array}
*/
get projectionMatrix() { return this[PRIVATE].device.getProjectionMatrix(this.eye); }
get projectionMatrix() {
return this[PRIVATE].device.getProjectionMatrix(this.eye, this[PRIVATE].viewIndex);
}

/**
* @return {XRRigidTransform}
Expand All @@ -77,7 +79,8 @@ export default class XRView {
if (this[PRIVATE].device.getViewport(this[PRIVATE].sessionId,
this.eye,
layer,
this[PRIVATE].temp)) {
this[PRIVATE].temp,
this[PRIVATE].viewIndex)) {
return this[PRIVATE].viewport;
}
return undefined;
Expand Down
6 changes: 4 additions & 2 deletions src/devices/XRDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,17 @@ export default class XRDevice extends EventTarget {
* @param {XREye} eye
* @param {XRWebGLLayer} layer
* @param {Object?} target
* @param {number} viewIndex
* @return {boolean}
*/
getViewport(sessionId, eye, layer, target) { throw new Error('Not implemented'); }
getViewport(sessionId, eye, layer, target, viewIndex) { throw new Error('Not implemented'); }

/**
* @param {XREye} eye
* @param {number} viewIndex
* @return {Float32Array}
*/
getProjectionMatrix(eye) { throw new Error('Not implemented'); }
getProjectionMatrix(eye, viewIndex) { throw new Error('Not implemented'); }

/**
* Get model matrix unaffected by frame of reference.
Expand Down

0 comments on commit 7dd87cb

Please sign in to comment.