Skip to content

Commit 070920d

Browse files
committed
Improve MarkerTracking
1 parent 3fdc430 commit 070920d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

frontend-vue/src/components/ar-component/ArComponent.vue

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Zone } from './Zone';
44
import { CardService } from './CardService';
55
import { ConnectionService } from '@/services/ConnectionService';
66
import { ref } from 'vue';
7+
import { faScaleBalanced } from '@fortawesome/free-solid-svg-icons';
78
89
const props = defineProps({
910
cardService: {
@@ -60,9 +61,10 @@ props.conService.onConnection(() => {
6061
var ImageEl = document.createElement('a-image');
6162
ImageEl.setAttribute('src', props.cardService.cardBack);
6263
ImageEl.setAttribute('id', 'card');
63-
64+
//set aspect ratio of a normal playing card
65+
ImageEl.object3D.scale.set(1.26, 1.76, 1);
6466
ImageEl.object3D.position.set(0, 0.0, 0);
65-
ImageEl.object3D.rotation.set(-90, 0, 0);
67+
rotateCardOntoMarker(markerEl, ImageEl)
6668
markerEl.appendChild(ImageEl);
6769
}
6870
handZone = new Zone("/markers/ZoneMarker1.patt", "/markers/ZoneMarker2.patt", sceneEl, "hand", foundZoneMarkers);
@@ -76,7 +78,8 @@ props.conService.onConnection(() => {
7678
7779
marker.addEventListener("markerFound", () => {
7880
var markerId = marker.id;
79-
addFoundMarker(marker, foundCardMarkers)
81+
addFoundMarker(marker, foundCardMarkers);
82+
8083
if (handZone.markerInZone(marker)) {
8184
turnCard(marker);
8285
}
@@ -143,7 +146,15 @@ props.conService.onConnection(() => {
143146
connected.value = true;
144147
});
145148
146-
149+
function rotateCardOntoMarker(marker, ImageEl) {
150+
const markerRotation = marker.object3D.rotation;
151+
if (Math.abs(markerRotation.x % (Math.PI * 2)) === Math.PI / 2) {
152+
// If the marker is rotated 90 or -90 degrees around the x-axis
153+
ImageEl.object3D.rotation.set(-Math.sign(markerRotation.x) * Math.PI / 2, 0, 0);
154+
} else {
155+
ImageEl.object3D.rotation.set(Math.PI / 2, 0, 0);
156+
}
157+
}
147158
function isCardBack(marker) {
148159
if (!marker) return false;
149160
const imageEl = marker.querySelector('#card');

0 commit comments

Comments
 (0)