The mouse pointer position in THREE.js does not align with the arrow tip during events

I am currently grappling with figuring out how to accurately determine the position of click events on the screen while using THREE.js alongside an Orthographic camera.

Unfortunately, the position that I have managed to calculate (similarly to what is described here) is not entirely accurate. It seems to be within the area of the mouse pointer but does not align perfectly with the tip.

In reviewing various online examples, it appears that this issue only affects orthographic cameras whereas for perspective cameras it functions correctly.

My question is whether this behavior is expected or if there might be an error in my code causing this misalignment. Is there a method to adjust the calculated position to accurately match the arrow tip?

function onDocumentMouseDown(event) {
    event.preventDefault();
    var vector = new THREE.Vector3((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1);
    projector = new THREE.Projector();
    var ray = projector.pickingRay(vector, camera);
    pointer.position = vector.clone();
    pointer.position.z = 0;

    renderer.render(scene, camera);
}

You can view a functioning example here

Answer №1

To achieve the desired layout, a little CSS is required:

body { margin: 0 }

Check out this demonstration on jsfiddle: http://jsfiddle.net/y6yS4/4/

For more information, take a look at this related answer.

This solution is applicable for three.js version r.65

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

What is the best way to transform a JSON object from a remote source into an Array using JavaScript?

Attempting to transform the JSON object retrieved from my Icecast server into an array for easy access to current listener statistics to display in HTML. Below is the JavaScript code being used: const endpoint = 'http://stream.8k.nz:8000/status-json ...

``When you click, the image vanishes into thin

Could you please explain why the image disappears once I close the lightbox? Access with password: chough ...

Ways to retrieve directory information in Next.js hosted on Netlify

Having trouble retrieving a list of directories in Next.js on Netlify. The code works fine on localhost, but once deployed to Netlify, an error is triggered: { "errorType": "Runtime.UnhandledPromiseRejection", "errorMessage": ...

Invoke a Wordpress shortcode using AJAX

Trying to implement a shortcode in Wordpress that can be triggered by clicking a button using jQuery. After researching various websites and tutorials, I am still having trouble understanding the issue. In my function.php file, I have the following code: ...

struggles with integrating arrays into object attributes in JavaScript

When working with object attributes, keep in mind that they only hold the first element of the assigned value let groupedDepActivities=[] groupedDepActivities.push({ id:1, term_activity:{ terms:[{id:1},{from:'her ...

Tips on using b-table attributes thClass, tdClass, or class

<template> <b-table striped hover :fields="fields" :items="list" class="table" > </template> <style lang="scss" scoped> .table >>> .bTableThStyle { max-width: 12rem; text-overflow: ellipsis; } < ...

Using Physi.js in Three.js, how to implement a chase camera for a moving sphere on a plane without the camera matching the sphere's rotation?

In my current project, I am working with a flat plane and using Physi.js to move a sphere along it by pressing up, down, right, and left. I am trying to implement a chase camera to follow the sphere, but I am facing an issue where the camera rotates along ...

Verify the REST call for access to Google APIs

Having issues with authenticating a REST request for Google APIs. Typically, Google provides client packages to handle this process. Currently using the Document Translation service which is still in preview, so unable to use the package. The documentatio ...

Enable the text to wrap around an interactive object that the user can freely manipulate

Looking for a solution where I can have a floating div that can be moved up and down using javascript while the text wraps around it seamlessly. Similar to how an object positioned in a word document behaves, I want the text to flow around the div both ab ...

Adjusting the size of images with precision after downloading from Google Cloud Storage

Struggling to resize an image after retrieving it from Google Cloud Storage. The streaming process is successful, but resizing seems to be an issue. The goal is to pass the image object to the sharpjs resize function, which will then resize the image and r ...

Yearly Grouping with MongoDB's Aggregate Framework

I've been experimenting with the aggregate function to group date fields by year: db.identities.aggregate([ { $group : { _id : { year : {$year : "$birth_date"}}, total : {$sum : 1} } } ]) However, I encountered a c ...

Issue with Safari: Ajax GET request with jQuery is returning null

I'm going absolutely crazy trying to troubleshoot an issue I am experiencing exclusively in Safari 5.1. The problem arises when making a simple ajax GET request using jQuery: $.ajax({ type: "GET", url: "get_values.cgi", ...

Why does tween animation appear instant rather than smooth?

I am trying to achieve a camera movement effect where the camera transitions from its current position to the center of a mesh (which is a sphere and I want to be inside of it) when a button is clicked. I have implemented a function with a tween for this ...

AngularJS Datepicker - calendar dropdown does not update when the model changes

I've been facing a challenge with the AngularJs datepicker in my project for some time now. Within my application, users have the option to either manually select a date using the calendar or click on "This Month" to automatically set the date to the ...

AngularJS - Viewless and Issue-Free

I'm currently working on a project that involves using AngularJS and PHP. I made some changes, but now it's not functioning properly... The issue is that there are no errors in the console, Angular works (I can retrieve its version), but my vi ...

What is the most effective method for retrieving a key and value from an Axios response object?

I currently have a Mongoose schema set up to store key:value pairs in a mixed type array, represented like this: Mongoose const budgetSchema = new Schema({ earnings: Number, expenses: [mongoose.Schema.Types.Mixed] }); budget:{ earning:1000, exp ...

How to automatically open JQuery Accordion panels when the page loads

My Accordion loads with the 1st panel open upon page load, but I am looking for a way to have the entire Accordion closed by default. Any help or suggestions on how to achieve this would be highly appreciated. Thank you for your assistance. FIDDLE http:// ...

Maintaining the current zoom level while updating a timeseries in Apache Echarts

Is there a way to maintain the current data zoom when updating timeseries data on my chart? Every minute I update the data, but the zoom resets to 100 each time. Additionally, how can I modify the text color of the label for the data zoom? I have been unab ...

Tips for sending an array of inputs to the query selector in Node.js using Cloudant

Currently, I am attempting to retrieve documents from a cloudant database using node.js. While I have successfully managed to obtain results for a single input value, I am encountering difficulty when it comes to querying with an array of inputs. For a si ...

How can I apply a CSS class to a group of radio buttons within a radio button list?

I'm attempting to validate a radio button group and apply a specific CSS class to it. Since this is a server control, I can only apply the class one way. However, upon checking with jQuery, I discovered that the class is actually being attached to the ...