Procházet zdrojové kódy

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

customisations
alemart před 9 měsíci
rodič
revize
12c3257e8d

+ 1
- 1
src/geometry/camera-model.ts Zobrazit soubor

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

+ 32
- 9
src/trackers/image-tracker/states/tracking.ts Zobrazit soubor

@@ -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 = {

Načítá se…
Zrušit
Uložit