Skip to content

Commit

Permalink
Improve MarkerTracking
Browse files Browse the repository at this point in the history
  • Loading branch information
heini208 committed Feb 22, 2024
1 parent 3fdc430 commit 8f706ec
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions frontend-vue/src/components/ar-component/ArComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Zone } from './Zone';
import { CardService } from './CardService';
import { ConnectionService } from '@/services/ConnectionService';
import { ref } from 'vue';
import { faScaleBalanced } from '@fortawesome/free-solid-svg-icons';
const props = defineProps({
cardService: {
Expand All @@ -23,6 +24,8 @@ var foundCardMarkers = [];
var foundZoneMarkers = [];
var handZone;
const cardAspectRatio = 63/88;
props.conService.onConnection(() => {
AFRAME.registerComponent('markers_start', {
init: function () {
Expand Down Expand Up @@ -60,9 +63,10 @@ props.conService.onConnection(() => {
var ImageEl = document.createElement('a-image');
ImageEl.setAttribute('src', props.cardService.cardBack);
ImageEl.setAttribute('id', 'card');
//set aspect ratio of a normal playing card
ImageEl.object3D.scale.set(1.26, 1.76, 1);
ImageEl.object3D.position.set(0, 0.0, 0);
ImageEl.object3D.rotation.set(-90, 0, 0);
rotateCardOntoMarker(markerEl, ImageEl)
markerEl.appendChild(ImageEl);
}
handZone = new Zone("/markers/ZoneMarker1.patt", "/markers/ZoneMarker2.patt", sceneEl, "hand", foundZoneMarkers);
Expand All @@ -76,7 +80,9 @@ props.conService.onConnection(() => {
marker.addEventListener("markerFound", () => {
var markerId = marker.id;
addFoundMarker(marker, foundCardMarkers)
addFoundMarker(marker, foundCardMarkers);
//rotateCardOntoMarker(marker);
if (handZone.markerInZone(marker)) {
turnCard(marker);
}
Expand Down Expand Up @@ -143,7 +149,15 @@ props.conService.onConnection(() => {
connected.value = true;
});
function rotateCardOntoMarker(marker, ImageEl) {
const markerRotation = marker.object3D.rotation;
if (Math.abs(markerRotation.x % (Math.PI * 2)) === Math.PI / 2) {
// If the marker is rotated 90 or -90 degrees around the x-axis
ImageEl.object3D.rotation.set(-Math.sign(markerRotation.x) * Math.PI / 2, 0, 0);
} else {
ImageEl.object3D.rotation.set(Math.PI / 2, 0, 0);
}
}
function isCardBack(marker) {
if (!marker) return false;
const imageEl = marker.querySelector('#card');
Expand Down

0 comments on commit 8f706ec

Please sign in to comment.