EddyVerbruggen / nativescript-ar

Augmented Reality NativeScript plugin
https://www.nativescript.org/blog/preview-of-augmented-reality-in-nativescript
MIT License
118 stars 36 forks source link

Add a "getPositionOnScreen" function to map 3D AR World objects to x/y screen coordinates #83

Closed EddyVerbruggen closed 4 years ago

EddyVerbruggen commented 4 years ago

It would be helpful to fi. programmatically know if an object is in a certain place (x/y) on the screen. So fi. when a sphere/model is in or near the center of the screen we can consider the user looking at it.

EddyVerbruggen commented 4 years ago

Here's a nice demo of how this can be used.

nickolanack commented 4 years ago

just out of curiosity, what happens if an object is directly behind you (and the camera)? -- with apologies since i could check myself...

nickolanack commented 4 years ago

Ok, I checked... items directly behind you also have onscreen x, y coordinates (which is what I thought would happen).

EddyVerbruggen commented 4 years ago

You're right. That makes it a bit harder to do what I wanted to achieve, but I've found a satisfactory way around it. Will test on Android tomorrow a little and update the repo.

nickolanack commented 4 years ago

Btw - There is a Dot product rule to test if an object is in front or behind

nickolanack commented 4 years ago

Dot product of: direction vector (camera to object), and camera look direction vector

nickolanack commented 4 years ago

It would also be cool (feature) if there was a way to expose hit testing/raytracing

EddyVerbruggen commented 4 years ago

That sounds like a much better approach, but I need this feature for a presentation I'm doing soon so I'll stick to the half-baked solution I have now. Sounds like a great plan though, to add a node.isInFrontOfCamera() function to the plugin. Or maybe even something like node.getPositionRelativeToCamera().