Establishing the direction of the projection matrix in three.js

I came across the following code snippet intended for webgl, and I am looking to rewrite it using three.js. However, I haven't been able to figure out how to do so. Can someone please assist me with this?

pMatrix = mat4.create();
mat4.perspective(pMatrix, 1.01, gl.drawingBufferWidth / gl.drawingBufferHeight, 10.0, 300000.0);
var eciMat = [1,  0,  0,  0,
           0,  0, -1,  0,
           0,  1,  0,  0,
           0,  0,  0,  1
          ];
mat4.mul(pMatrix, pMatrix, eciMat);

Answer №1

When it comes to Matrix classes in Three.js, they offer a high level of sophistication. For detailed information, refer to the documentation available at:

Below is an example of how you can implement Matrix classes in Three.js:

// Define perspective matrix with parameters (fov, aspect, near, far)
var perspectiveMatrix = new THREE.Matrix4().makePerspective(30, 1, 0.01, 20);

// Create ECI matrix
var eciMatrix = new THREE.Matrix4();
eciMatrix.set(
    1,  0,  0,  0,
    0,  0, -1,  0,
    0,  1,  0,  0,
    0,  0,  0,  1
);

// Multiply matrices to get result
var resultMatrix = new THREE.Matrix4();
resultMatrix.multiply(eciMatrix);
resultMatrix.multiply(perspectiveMatrix);
resultMatrix.multiply(perspectiveMatrix);

console.log(resultMatrix);

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

The integration of VueJS with Axios and the Google Maps API

Currently following [this][1] guide to develop a Google Map and now I am looking to execute a GET request with Axios: axios.get("http://localhost:8080/mapjson").then(function(response) { }) in order to integrate the information from my JSON file into the ...

Missing index in the GET variable

I have a div with the class .excelDL. When this div is clicked, a form is submitted using AJAX without refreshing the page, and it works perfectly fine. However, the issue I am facing is that I need to check if $_GET['excel'] has been set to one ...

Getting the value of a JavaScript variable and storing it in a Python variable within a Python-CGI script

Is there a way to capture the value of a JavaScript variable and store it in a Python variable? I have a Python-CGI script that generates a selection box where the user can choose an option from a list. I want to then take this selected value and save it ...

Synchronize custom directive controller data with data from a factory

As a newcomer to angularjs, I stumbled upon this example that I found somewhere and it works perfectly well. However, I am puzzled by how the data within the customized directive controller remains synchronized with the factory data. Here is the snippet of ...

Mobile Drag and Drop with JavaScript

While experimenting with a user interface I created, I utilized jQuery UI's draggable, droppable, and sortable features. However, I observed that the drag and drop functionality does not work in mobile browsers. It seems like events are triggered diff ...

Preserve the scroll location when new items are included in the array within ng-repeat

Is it possible to have a list of messages displayed using ng-repeat and load older messages via ion refresher when the user scrolls to the top? The goal is for the older messages to be added above the current messages while maintaining the scroll position ...

Error: You cannot implement an import statement beyond a module while utilizing reactjs CDN Links

I am developing a Reactjs app using react CDN Links instead of 'npx create-react-app'. I have set up an index.html, index.js, and App.js files. My goal is to import the App.js component into the Index.js file using import App from '../compon ...

Enhance the appearance of the Title Attribute in HTML Textareas

Could someone please assist me with styling the title attribute for an html textarea? I attempted to use this jfiddle link, but it doesn't seem to work correctly. I am working in the Chrome browser. Below is the code snippet: <li> <labe ...

Leveraging arrays generated from two separate MySQL queries for dual selection functionality with JavaScript

I have successfully populated the first HTML select with results from the first query. Now, I would like to store the results from the second query in either a Json file or XML and then use plain javascript (not jQuery) to populate the second HTML select ...

Is there a way to reach a different function within the value of the react Context.Provider?

Right now, I am learning how to utilize the react context API. Within my react Provider class, I have some state data and functions stored in the value={}. But I am curious, how can I call a function inside this value from another function within the same ...

Angular - Execute a function once the observable has finished

I am currently working with a 2 part process that involves importing a list of usernames in Component 1, submitting it to a service, and then using the returned user profile data in Component 2. The issue I am facing is that when I receive the data back f ...

Stop automatic page refresh after submitting a jQuery post request

I've tried various solutions, but unfortunately, neither e.preventDefault() nor return false seem to be working for me. When I use prevent default ajax doesn't make post request. Even using $.post doesn't work as expected. Furthermore, addin ...

What is the best way to structure a web server along with a socket.io server?

I am curious about the capabilities of node.js Is it feasible to utilize multiple server.js files? For example, could there be a primary "server.js" that directs users to another directory where a separate server.js manages websocket connections using so ...

When using Selenium async script in its own thread, it can interrupt the execution of other

Let's consider this situation: Various scripts need to run in the browser. One of them involves sending messages from one browser to another (WebRTC). I am interested in measuring the delay for each operation, especially when it comes to sending mess ...

Error: Unable to access attributes of null object (specifically 'disable click')

Currently, I am integrating react-leaflet with nextjs. Within the markers, there are popups containing buttons that open another page upon click. However, I have encountered an error when navigating to the new page: Unhandled Runtime Error TypeError: Canno ...

Select more than one class within a div and keep track of how many times they have been clicked using pure JavaScript

This code snippet serves the purpose of tracking the number of clicks on buttons with either the testButton or incButton class, and displaying an overlay after two clicks. However, two main issues have been identified: 1: Difficulty in selecting buttons wi ...

Transforming 2-dimensional coordinates into 3-dimensional coordinates

Previously in my project, I was using a 2D Map. Due to customer requirements, they now want a 3D map. However, the third party only provides X and Y coordinates. In the project, some objects are static so I positioned them manually. But for objects that ch ...

Using OpenCV.js to detect QR codes

Currently, I am in the process of creating a web application for detecting QrCodes using Opencv.Js. Everything is working smoothly with functions like findcountour and GaussianBlur, but it appears that cv.QRCodeDetector() is not available. let detector = ...

What is the best way to incorporate interactive columns in DataTables?

I am utilizing jquery datatables to present data. <table class="report-tbl table-bordered" cellspacing="0" width="100%" id="report-tbl"> <thead> <tr> <th></th> ...

What is the best way to alphabetically arrange an array of names in a JavaScript.map?

I am attempting to alphabetically sort an array of first names using JavaScript map function. Additionally, I aim to remove the "undefined" row from the final results: function contacts_callback(obj) { var contactinfo = obj.contacts .filter( ...