Locating marker coordinates on the screen with AR.js

After implementing the code below, I successfully retrieved the marker's position:

this.marker.object3D.getWorldPosition(vector);

Now, I am eager to understand if there is a way to convert this position (x,y,z) into its corresponding screen coordinates (width, height).

I would greatly appreciate any suggestions or solutions you can offer to help me address this matter.

Answer №1

To achieve this desired effect, follow these two simple steps:

  • Firstly, convert the position in world space to NDC (Normalized Device Coordinates) space using the Vector3.project() method.
  • Secondly, ensure you utilize the dimensions of your canvas by making use of the width and height values for accurate screen space conversion.
const vector = new THREE.Vector3();
vector.project( camera ); 

vector.x = ( vector.x + 1) * width / 2;
vector.y = - ( vector.y - 1) * height / 2;
vector.z = 0;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing Highchart within a pop-up modal

Currently, I am developing a webpage that utilizes highchart. My goal is to display the same highchart as a modal window when a button is clicked. The technologies I am using include HTML, Bootstrap, and JavaScript. This is the code I have implemented: & ...

Retrieving nested array elements in MongoDB using parent ID element (JavaScript)

Suppose I have a MongoDB collection structured as follows: _id: ObjectId(" <a objectid> ") id: " <a userid> " __v: 0 subscribedTo: Object Regardless of whether or not Mongoose is being used, how can I execute a query to acc ...

What is the best way to create a reusable component for a dialog box or modal window?

I have been working on developing a reusable dialog component with a yes or no button at the bottom. The main idea behind this is to create a user confirmation dialog that prompts the user to confirm their entered information before proceeding. import Re ...

Creating interactive web pages for scheduling tasks

I'm struggling with how to implement this concept. Imagine I have a School website that features a schedule page for 30 upcoming courses. When a course is clicked, it should lead to a new page displaying specific information about that course (such a ...

Scroll up and down to witness the enchanting interplay of fading in and out

Looking to expand upon the solution given in this response. The existing code effectively fades in an element while scrolling down and fades out an image when scrolling up; however, it lacks the functionality to fade out when scrolling down. I am aiming ...

Generating an Xpath for the selected element with the help of Javascript or Jquery - here's how!

On my website, I have implemented a click event on an element. When a user clicks on this element, I want to generate the XPath of that particular element starting from either the html or body tag, also known as the Absolute Xpath. For example, if I click ...

passport.use does not exist as a method

I'm facing an issue while trying to integrate passport service into my app. Despite installing all the necessary dependencies, I encountered the following error which I couldn't find any solutions for. Your assistance would be greatly appreciated ...

Encountered a server issue (500 Internal Server Error) when attempting to send a POST

I have been working on a social media app project using React and MongoDB. However, every time I try to register a user, I encounter a POST error in the console. I have reviewed both my client-side and server-side code, but I am still unable to successfull ...

Proper method for updating page content without refreshing the entire page and causing a reload

Greetings everyone, I am currently developing a content management system for educational purposes but keep facing the same challenge. When, for example, updating a blog post, I aim to have the changes reflected without the page having to reload. This pro ...

Determine the Orientation of an Accelerometer using a JavaScript function in Node-RED

Is there a way to determine the orientation of a sensor using a JavaScript function? I came across an example on 3D Accelerometer calculate the orientation, but I'm struggling to understand how to utilize the values of msg.payload.xAxis/yAxis/zAxis fo ...

How to retrieve and use path parameters within the router.use() function in Express

In the scenario presented below, how can I access the 'pathId' within the 'router.use' function? Is it feasible or do I need to implement a different approach? var router = require('express').Router(); function someMiddlewar ...

What is the best way to transfer data from R to JS in a Shiny app and incorporate it into the user interface?

I am looking to add a custom news button to the header of my shinyapp, which will display information from a specific dataset. I want the button to show the number of news items available, similar to how shinyDashboard::notificationItem() works but with mo ...

AngularJS - returning dynamic functions

index.html <div ng-repeat="object in objects" ng-style="getStyle(object.id)"></div> controller.js [...] $scope.startWidth = 100; $scope.getObject = [...] $scope.getStyle = function(id) { var widthVal = $scope.startWidth; $scope.star ...

Generating a tag filter using elements from a collection of profiles

I have an array of profiles containing various skills. Each profile has its own set of tags to describe their skills. For example: profiles = [ { name: "John", skills: ["react", "javascript"]}, { name: "Jane", skil ...

Customizing the style of an element in Vue depending on the size of the window

I am struggling to update the appearance of an HTML element when the window size is below 500px. Currently, I have a computed property that sets a background-image for the element. I attempted to use an if statement within the computed property to check if ...

What is the best approach to converting a set of vertex indices greater than four into a usable format?

I am developing a method to transform the data from 3D files into THREE geometries. The data is formatted as follows: {"N":"name of the block","V":[[0,1,2]..[N1,N2,N3]],"F":[[0,1,2]..[M1,M2,M3]],"P":[[O1,O2,P3,..,Op]..[..]]} The meaning of N is self-expl ...

Error: Cannot read property 'X' of undefined in JavaScript when using Django framework

Using p5.js, I am creating drawings with data from a JSON provided by my Django backend. The draw function is defined at the base level of my HTML document within the script element: function draw(json) { if (json["leaf_text"]) { stroke(100) el ...

Restricting array elements through union types in TypeScript

Imagine a scenario where we have an event type defined as follows: interface Event { type: 'a' | 'b' | 'c'; value: string; } interface App { elements: Event[]; } Now, consider the following code snippet: const app: App ...

Exploring the implementation of --history-api-fallback in webpack

let path = require('path') module.exports = { entry:path.resolve('public/src/index.js'), output: { path:__dirname + "/public", filename: "bundle.js" }, module: { loaders: [{ exclude: / ...

Node.js is having trouble locating a specific folder module within the local directory

My Typescript and NodeJS Visual Studio project compiles successfully, but I encounter a node runtime error regarding the inability to locate a local module. This is the specific error message: https://i.sstatic.net/6ydxj.png I find it perplexing that th ...