@srsergio/taptapp-ar 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -158,8 +158,8 @@ class SimpleAR {
158
158
  }
159
159
  const scaleX = displayW / effectiveBufferW;
160
160
  const scaleY = displayH / effectiveBufferH;
161
- // 3. Focal Length (MUST match Controller.js projection)
162
- // Controller.js uses inputHeight / 2 as the vertical reference.
161
+ // 3. Focal Length (MUST match Controller.js)
162
+ // Controller uses inputHeight / 2 (sensor's vertical dimension) as the baseline.
163
163
  const f = videoH / 2 / Math.tan((45.0 * Math.PI / 180) / 2);
164
164
  // 4. Project marker center into camera space
165
165
  const tx = mVT[0][0] * (markerW / 2) + mVT[0][1] * (markerH / 2) + mVT[0][3];
@@ -182,20 +182,19 @@ class SimpleAR {
182
182
  //atan2 gives angle of world X-axis in camera space.
183
183
  let rotation = Math.atan2(mVT[1][0], mVT[0][0]);
184
184
  if (needsRotation) {
185
- rotation += Math.PI / 2; // Compensate for the 90deg rotation of the video element
185
+ rotation -= Math.PI / 2; // Mapping Sensor frame to Portrait Screen frame
186
186
  }
187
- // 7. Scale calculation
187
+ // 7. Scale calculation (Robust Method)
188
+ // Instead of detecting intrinsic width (unstable), we force a base CSS width
189
+ // and calculate the scale to match the marker's projected screen width.
190
+ const BASE_CSS_WIDTH = 1000;
188
191
  const matrixScale = Math.sqrt(mVT[0][0] ** 2 + mVT[1][0] ** 2);
189
192
  const perspectiveScale = (f / tz) * scaleX;
190
- const intrinsicWidth = (this.overlay instanceof HTMLVideoElement)
191
- ? this.overlay.videoWidth
192
- : (this.overlay instanceof HTMLImageElement ? this.overlay.naturalWidth : 0);
193
- const baseScale = intrinsicWidth > 0
194
- ? (matrixScale * markerW * perspectiveScale) / intrinsicWidth
195
- : 1.0;
196
- const finalScale = baseScale * this.scaleMultiplier;
197
- // Apply transform
198
- this.overlay.style.width = 'auto';
193
+ // Target pixel width on screen = markerW * matrixScale * perspectiveScale
194
+ const targetScreenWidth = markerW * matrixScale * perspectiveScale;
195
+ const finalScale = (targetScreenWidth / BASE_CSS_WIDTH) * this.scaleMultiplier;
196
+ // Apply
197
+ this.overlay.style.width = `${BASE_CSS_WIDTH}px`;
199
198
  this.overlay.style.height = 'auto';
200
199
  this.overlay.style.position = 'absolute';
201
200
  this.overlay.style.transformOrigin = 'center center';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srsergio/taptapp-ar",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "AR Compiler for Node.js and Browser",
5
5
  "repository": {
6
6
  "type": "git",
@@ -188,8 +188,8 @@ class SimpleAR {
188
188
  const scaleX = displayW / effectiveBufferW;
189
189
  const scaleY = displayH / effectiveBufferH;
190
190
 
191
- // 3. Focal Length (MUST match Controller.js projection)
192
- // Controller.js uses inputHeight / 2 as the vertical reference.
191
+ // 3. Focal Length (MUST match Controller.js)
192
+ // Controller uses inputHeight / 2 (sensor's vertical dimension) as the baseline.
193
193
  const f = videoH / 2 / Math.tan((45.0 * Math.PI / 180) / 2);
194
194
 
195
195
  // 4. Project marker center into camera space
@@ -214,25 +214,22 @@ class SimpleAR {
214
214
  //atan2 gives angle of world X-axis in camera space.
215
215
  let rotation = Math.atan2(mVT[1][0], mVT[0][0]);
216
216
  if (needsRotation) {
217
- rotation += Math.PI / 2; // Compensate for the 90deg rotation of the video element
217
+ rotation -= Math.PI / 2; // Mapping Sensor frame to Portrait Screen frame
218
218
  }
219
219
 
220
- // 7. Scale calculation
220
+ // 7. Scale calculation (Robust Method)
221
+ // Instead of detecting intrinsic width (unstable), we force a base CSS width
222
+ // and calculate the scale to match the marker's projected screen width.
223
+ const BASE_CSS_WIDTH = 1000;
221
224
  const matrixScale = Math.sqrt(mVT[0][0] ** 2 + mVT[1][0] ** 2);
222
225
  const perspectiveScale = (f / tz) * scaleX;
223
226
 
224
- const intrinsicWidth = (this.overlay instanceof HTMLVideoElement)
225
- ? this.overlay.videoWidth
226
- : (this.overlay instanceof HTMLImageElement ? this.overlay.naturalWidth : 0);
227
+ // Target pixel width on screen = markerW * matrixScale * perspectiveScale
228
+ const targetScreenWidth = markerW * matrixScale * perspectiveScale;
229
+ const finalScale = (targetScreenWidth / BASE_CSS_WIDTH) * this.scaleMultiplier;
227
230
 
228
- const baseScale = intrinsicWidth > 0
229
- ? (matrixScale * markerW * perspectiveScale) / intrinsicWidth
230
- : 1.0;
231
-
232
- const finalScale = baseScale * this.scaleMultiplier;
233
-
234
- // Apply transform
235
- this.overlay.style.width = 'auto';
231
+ // Apply
232
+ this.overlay.style.width = `${BASE_CSS_WIDTH}px`;
236
233
  this.overlay.style.height = 'auto';
237
234
  this.overlay.style.position = 'absolute';
238
235
  this.overlay.style.transformOrigin = 'center center';