|
@@ -106,9 +106,12 @@ export class ImageTrackerTrackingState extends ImageTrackerState
|
106
|
106
|
/** the number of consecutive frames in which we have lost the tracking */
|
107
|
107
|
private _lostCounter: number;
|
108
|
108
|
|
109
|
|
- /** camera model */
|
|
109
|
+ /** camera model linked to the tracked image */
|
110
|
110
|
private _camera: CameraModel;
|
111
|
111
|
|
|
112
|
+ /** a camera model that is fixed at the origin */
|
|
113
|
+ private _fixedCamera: CameraModel;
|
|
114
|
+
|
112
|
115
|
|
113
|
116
|
|
114
|
117
|
/**
|
|
@@ -130,6 +133,7 @@ export class ImageTrackerTrackingState extends ImageTrackerState
|
130
|
133
|
this._counter = 0;
|
131
|
134
|
this._lostCounter = 0;
|
132
|
135
|
this._camera = new CameraModel();
|
|
136
|
+ this._fixedCamera = new CameraModel();
|
133
|
137
|
}
|
134
|
138
|
|
135
|
139
|
/**
|
|
@@ -164,9 +168,10 @@ export class ImageTrackerTrackingState extends ImageTrackerState
|
164
|
168
|
// setup portals
|
165
|
169
|
keypointPortalSource.source = templateKeypointPortalSink;
|
166
|
170
|
|
167
|
|
- // setup camera
|
|
171
|
+ // setup the cameras
|
168
|
172
|
const aspectRatio = initialScreenSize.width / initialScreenSize.height;
|
169
|
173
|
this._camera.init(aspectRatio);
|
|
174
|
+ this._fixedCamera.init(aspectRatio);
|
170
|
175
|
|
171
|
176
|
// emit event
|
172
|
177
|
const ev = new ImageTrackerEvent('targetfound', referenceImage);
|
|
@@ -184,7 +189,8 @@ export class ImageTrackerTrackingState extends ImageTrackerState
|
184
|
189
|
// log
|
185
|
190
|
Utils.log(`No longer tracking image "${this._referenceImage!.name}"!`);
|
186
|
191
|
|
187
|
|
- // release the camera
|
|
192
|
+ // release the cameras
|
|
193
|
+ this._fixedCamera.release();
|
188
|
194
|
this._camera.release();
|
189
|
195
|
|
190
|
196
|
// emit event
|
|
@@ -335,16 +341,33 @@ export class ImageTrackerTrackingState extends ImageTrackerState
|
335
|
341
|
})
|
336
|
342
|
.then(() => {
|
337
|
343
|
|
338
|
|
- // we let the target object be at the origin of the world space
|
339
|
|
- // (identity transform). We also perform a change of coordinates,
|
340
|
|
- // so that we move out from pixel space and into normalized space
|
341
|
|
- const modelMatrix = Speedy.Matrix.Eye(4);
|
|
344
|
+ /*
|
|
345
|
+
|
|
346
|
+ Q: should the camera move relative to the target image, or should
|
|
347
|
+ the target image move relative to the camera?
|
|
348
|
+
|
|
349
|
+ A: the target image should move and the camera should stay fixed.
|
|
350
|
+ Movements of the target image in the video should not affect the
|
|
351
|
+ rendering of all virtual elements in world space. They should
|
|
352
|
+ only affect the rendering of virtual elements positioned at the
|
|
353
|
+ local space linked to the target ("ar.root").
|
|
354
|
+
|
|
355
|
+ */
|
|
356
|
+
|
|
357
|
+ // the target moves and the camera stays fixed at the origin
|
|
358
|
+ const modelMatrix = this._camera.computeViewMatrix(); // p_view = V M p_model
|
342
|
359
|
const transform = new Transform(modelMatrix);
|
343
|
360
|
const pose = new Pose(transform);
|
|
361
|
+ const viewer = new Viewer(this._fixedCamera); // view matrix = I
|
344
|
362
|
|
345
|
|
- // given the current state of the camera model, we get a viewer
|
346
|
|
- // compatible with the pose of the target
|
|
363
|
+ /*
|
|
364
|
+ // this is the opposite reasoning: the camera moves and the target
|
|
365
|
+ // image stays fixed at the origin of world space
|
|
366
|
+ const modelMatrix = Speedy.Matrix.Eye(4);
|
|
367
|
+ const transform = new Transform(modelMatrix);
|
|
368
|
+ const pose = new Pose(transform);
|
347
|
369
|
const viewer = new Viewer(this._camera);
|
|
370
|
+ */
|
348
|
371
|
|
349
|
372
|
// the trackable object
|
350
|
373
|
const trackable: TrackableImage = {
|