Having trouble connecting and establishing an onmousemove event?

I am looking to implement a mouse move event handler in my three.js project, but I have been struggling to connect it with the mouse and make it work. It would be greatly appreciated if someone could provide guidance on how to achieve this. I am not sure where exactly I should use mouse-related coordinates and I'm concerned about making changes that might impact my calculations.

root = document.getElementById("WebGL");

window.addEventListener('resize', onWindowResize(width, height), false);
root.addEventListener('mousemove', MouseMoveGoogleMapsUpdate(), false);


function MouseMoveGoogleMapsUpdate(){

    var angle = onMouseMove();

    line.setMap(null);  //removing the old lines on circle


            var newstartpoint   = pointGoogleMaps(circle.getRadius() * Math.cos(-angle[0]),
                                        circle.getRadius() * Math.sin(-angle[0]), origin);

            var  viewdir        = pointGoogleMaps(circle.getRadius() * Math.cos(-angle[1]),
                                        circle.getRadius() * Math.sin(-angle[1]), origin);

            var newendpoint    = pointGoogleMaps(circle.getRadius() * Math.cos(angle[2]),
                                        circle.getRadius() * Math.sin(angle[2]), origin);

            line = new google.maps.Polyline({
            path: [newstartpoint, origin, newendpoint],
            geodesic: true,  //By setting it to true the distance is cal in meters
            strokeColor: '#0000FF',
            strokeOpacity: 0.8,
            strokeWeight: 2,            
            map: map
            });

}


function onMouseMove(){

    var degrees = Math.PI/180.0;
    var raycaster = new THREE.Raycaster();
    var viewingDir = camera.getWorldDirection();
    var Vectors = [0,0,0];
    var Angles = [0,0,0];

    for(i=0; i<3; i++)
    {
        Vectors[i] = new THREE.Vector3(i-1, 0, 0.5);
        raycaster.setFromCamera(Vectors[i], camera);
        Vectors[i].sub(camera.position);
        Vectors[i].normalize();

    }

    for(i=0; i<3; i+=2)
    {
        var dotp = Vectors[i].x * Vectors[1].x + Vectors[i].y * Vectors[1].y + Vectors[i].z * Vectors[1].z;
        if (dotp >= 1)
            Angles[i] = 0.0;
        else if (dotp <= -1)
            Angles[i] = Math.PI;
        else
            Angles[i] = Math.acos(dotp);
    }

    Angles[1] = Math.atan2(viewingDir.x, -viewingDir.z);
    fov = Angles[0] + Angles[2];
    Angles[0] = Angles[1] - 0.5 * fov; //x-dir
    Angles[2] = Angles[1] + 0.5 * fov; //y-dir

    return Angles;

}

Answer №1

document.addEventListener('mousemove', handleMouseMove);
function handleMouseMove(e) {
    e.preventDefault();
    posX = (e.clientX / window.innerWidth) * 2 - 1;
    posY = -(e.clientY / window.innerHeight) * 2 + 1;
}

It appears that the event variable is missing from your code...

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

Having trouble with Angular ngRoute functionality?

I'm currently working on configuring a basic Angular app. Here is my main HTML: <html ng-app="CostumerApp"> <head> <title> Customers </title> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstr ...

Vue in d3 - the property ownerDocument is not defined

I'm currently working on integrating d3 charts with Vue. I've noticed that using a ref seems to trigger an error, but is that the correct approach? <template> <div ref="chart"></div> </template> const char ...

Issue with submitting forms in modal using Bootstrap

In the model box below, I am using it for login. When I click on either button, the page just reloads itself. Upon checking in Firebug, I found something like this: localhost\index.php?submit=Login <div class="modal fade" id="loginModal" tabindex= ...

How come defining the state using setTimeout does not display the accurate properties of a child component?

Presented here is a component designed to render a list of items and include an input for filtering. If no items are present or if the items are still loading, a message should be displayed. import { useState } from "react"; export const List = ...

Guide on utilizing node-modules installed via npm in a template

I am attempting to utilize a library installed via npm in the Go template. By running 'npm install three', I have successfully installed the required three libraries, which are saved in the root folder as depicted in the provided screenshot belo ...

Concurrent AJAX requests within the Vaadin JavaScript extension

Currently, I am in the process of developing a straightforward Vaadin Extension using javascript where I subclass AbstractJavaScriptExtension. The main objective is to trigger a method call on the server side that will involve tasks such as loading data an ...

Unable to retrieve data upon page refresh in Next.js

I encountered an issue while trying to develop a basic Next.js page using data fetched from the backend. I am utilizing useSWR for fetching the data. When I refresh the page or load it for the first time after running in development mode, I face a TypeScr ...

Issue with promises in angular.js + node.js/electron integration is causing malfunctions

I have integrated angular.js with electron and node-orm to communicate with a database. The find/get functions in Node-orm are asynchronous, so I attempted to use Promises in a service to retrieve data like this: app.service('SearchService', fu ...

Exploring the Node.js Connector: Utilizing Collection.remove

I can't wrap my head around the meaning of this: w, {Number/String, > -1 || ‘majority’ || tag name} the write concern for the operation where < 1 is no acknowlegement of write and w >= 1, w = ‘majority’ or tag acknowledges the ...

Execute the JavaScript function window.print() with a designated URL provided

In my asp.net mvc 2.0, I have created a report in the View which includes a header, footer, and content from searching for each record. The goal is to provide users with a preview of what they want to print before allowing them to click on a link or button ...

Retrieving information from a function within a Node module

Struggling to get data returned from a function in my Node module. I've researched and read but can't seem to crack it. Using the request plugin to fetch JSON data from an API and aiming to pass that data back for use. Below is my module code: ...

Page resizing is disabled in Chrome after an Ajax load

I've been tirelessly working on the CSS for a website I'm building, and I've encountered a strange issue that only seems to affect Chrome. Firefox and Internet Explorer work perfectly fine. I am using jQuery to load HTML stubs and a signifi ...

How can I find the week of the month using Moment.js? (similar to Google Calendar)

Currently leveraging the fantastic features of Moment.js, I am facing a dilemma. How can I determine which week of the month a particular date falls into? The documentation for Moment js only seems to provide information on "week of year." For instance, if ...

Viewing information from the database without the need to refresh the page

HTML <textarea>Enter your question here</textarea><button class="askButton">SUBMIT</button> Upon clicking the button, the question is stored in the database using Ajax, jQuery, and Laravel. However, the question only appears after ...

Obtain the attribute value from an HTML option element

Here is the code snippet I am working with: <select class="form-control valid"> <option isday="False" value="2">Value 1</option> <option isday="True" value="3">Value 2</option> <option isday="True" value="4"> ...

Guide to writing a Jasmine test case to verify Toggle class behavior within a click event

My directive is responsible for toggling classes on an element, and it's working as expected. However, I seem to be encountering an issue with the jasmine test case for it. // Code for toggling class fileSearch.directive('toggleClass', func ...

Mistakenly appearing at the top of the window instead of the bottom of the window

Utilizing Vue.js to fetch resources from a Laravel API periodically and paginate(), after retrieving the initial 10 instances, I aim to get the next 10. Here's how my method looks: scroll () { window.onscroll = () => { let bottomOf ...

What is the proper placement for index.html <head/> class helper functions within a ReactJS Component?

My custom helper functions are stored in a JavaScript file called classie.js: ( function( window ) { 'use strict'; function classReg( className ) { return new RegExp("(^|\\s+)" + className + "(\\s+|$)"); } var hasClass, ...

Access the child scope's attribute within the parent scope in AngularJS

angular.module('myApp',[]) .controller('Parent',['$scope',function($scope){ //no specific definition }]).controller('Child',['$scope',function($scope){ $scope.user={name:''}; //create a us ...

What is the technique for hiding the bottom tab navigator upon leaving a specific screen in React Native version 5?

In the home screen, I want only the bottom tab navigator to be visible, and then hidden until the user returns to the home screen. The example provided below is tailored for working in the App.js file, but my situation is different. const Tab = createBot ...