Переглянути джерело

Change the convention used to determine the model and the view matrices

customisations
alemart 9 місяці тому
джерело
коміт
12c3257e8d

+ 1
- 1
src/geometry/camera-model.ts Переглянути файл

378
      */
378
      */
379
     private _normalizeHomography(homography: SpeedyMatrix): SpeedyMatrix
379
     private _normalizeHomography(homography: SpeedyMatrix): SpeedyMatrix
380
     {
380
     {
381
-        const h = homography.read();
382
         const u0 = this._intrinsics[U0];
381
         const u0 = this._intrinsics[U0];
383
         const v0 = this._intrinsics[V0];
382
         const v0 = this._intrinsics[V0];
384
         const fx = this._intrinsics[FX];
383
         const fx = this._intrinsics[FX];
386
         const u0fx = u0 / fx;
385
         const u0fx = u0 / fx;
387
         const v0fy = v0 / fy;
386
         const v0fy = v0 / fy;
388
 
387
 
388
+        const h = homography.read();
389
         const h11 = h[0] / fx - u0fx * h[2], h12 = h[3] / fx - u0fx * h[5], h13 = h[6] / fx - u0fx * h[8];
389
         const h11 = h[0] / fx - u0fx * h[2], h12 = h[3] / fx - u0fx * h[5], h13 = h[6] / fx - u0fx * h[8];
390
         const h21 = h[1] / fy - v0fy * h[2], h22 = h[4] / fy - v0fy * h[5], h23 = h[7] / fy - v0fy * h[8];
390
         const h21 = h[1] / fy - v0fy * h[2], h22 = h[4] / fy - v0fy * h[5], h23 = h[7] / fy - v0fy * h[8];
391
         const h31 = h[2], h32 = h[5], h33 = h[8];
391
         const h31 = h[2], h32 = h[5], h33 = h[8];

+ 32
- 9
src/trackers/image-tracker/states/tracking.ts Переглянути файл

106
     /** the number of consecutive frames in which we have lost the tracking */
106
     /** the number of consecutive frames in which we have lost the tracking */
107
     private _lostCounter: number;
107
     private _lostCounter: number;
108
 
108
 
109
-    /** camera model */
109
+    /** camera model linked to the tracked image */
110
     private _camera: CameraModel;
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
         this._counter = 0;
133
         this._counter = 0;
131
         this._lostCounter = 0;
134
         this._lostCounter = 0;
132
         this._camera = new CameraModel();
135
         this._camera = new CameraModel();
136
+        this._fixedCamera = new CameraModel();
133
     }
137
     }
134
 
138
 
135
     /**
139
     /**
164
         // setup portals
168
         // setup portals
165
         keypointPortalSource.source = templateKeypointPortalSink;
169
         keypointPortalSource.source = templateKeypointPortalSink;
166
 
170
 
167
-        // setup camera
171
+        // setup the cameras
168
         const aspectRatio = initialScreenSize.width / initialScreenSize.height;
172
         const aspectRatio = initialScreenSize.width / initialScreenSize.height;
169
         this._camera.init(aspectRatio);
173
         this._camera.init(aspectRatio);
174
+        this._fixedCamera.init(aspectRatio);
170
 
175
 
171
         // emit event
176
         // emit event
172
         const ev = new ImageTrackerEvent('targetfound', referenceImage);
177
         const ev = new ImageTrackerEvent('targetfound', referenceImage);
184
         // log
189
         // log
185
         Utils.log(`No longer tracking image "${this._referenceImage!.name}"!`);
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
         this._camera.release();
194
         this._camera.release();
189
 
195
 
190
         // emit event
196
         // emit event
335
         })
341
         })
336
         .then(() => {
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
             const transform = new Transform(modelMatrix);
359
             const transform = new Transform(modelMatrix);
343
             const pose = new Pose(transform);
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
             const viewer = new Viewer(this._camera);
369
             const viewer = new Viewer(this._camera);
370
+            */
348
 
371
 
349
             // the trackable object
372
             // the trackable object
350
             const trackable: TrackableImage = {
373
             const trackable: TrackableImage = {

Завантаження…
Відмінити
Зберегти