-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectInteraction.js
More file actions
28 lines (24 loc) · 888 Bytes
/
Copy pathobjectInteraction.js
File metadata and controls
28 lines (24 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Object Interaction Module
* Handles click detection and object interaction within scenes
*/
import { detectHit } from './hitDetection.js';
class ObjectInteraction {
constructor(canvas, sceneRenderer, sceneManager) {
this.canvas = canvas;
this.sceneRenderer = sceneRenderer;
this.sceneManager = sceneManager;
this.canvas.addEventListener('click', this.handleClick.bind(this));
}
handleClick(event) {
const rect = this.canvas.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const scene = this.sceneManager.getCurrentScene();
const clickedObject = detectHit(x, y, scene.objects);
if (clickedObject) {
this.sceneRenderer.handleInteraction(clickedObject.id, this.sceneManager);
}
}
}
export { ObjectInteraction };