Creating a responsive design for off-center objects using an orthographic camera in Three.js

I'm currently exploring the most effective method to adjust the position and scale of a model across various devices without solely relying on match medias. Since using percentages is not an option, I am wondering if Three.js has any built-in features that could assist me in achieving optimal results. Any alternative solutions are also welcomed. As of now, I am utilizing an orthographic camera in my scene.

The issue at hand is as follows: I intend for the model to be positioned like this https://i.sstatic.net/oJHH1ONA.png

However, when I resize the screen, it ends up being cut off like this https://i.sstatic.net/nt7NcbPN.png

My resizing code is quite straightforward:

rendererSize.width = window.innerWidth;
rendererSize.height = window.innerHeight;

aspect = rendererSize.width / rendererSize.height;

//* [ORTHOGRAPHIC CAMERA]
camera.left = -f * aspect;
camera.right = f * aspect;

camera.updateProjectionMatrix();
renderer.setSize(rendererSize.width, rendererSize.height);

Answer №1

You're definitely on the right path, just don't forget one important detail.

It seems like your model's anchor point could be defined as vec2(0.5, 0.5). If you position your object at vec3(0, 0, 0), you'll notice that it is perfectly centered, indicating that the center of your object aligns with the center of your screen.

Chances are, in your resize function, you are adding half of the screen size to position.x. This means you are shifting the anchor point by half the screen width, causing half of your object to be hidden. To adjust this, subtract half of your object's width from your offset. You can determine the width of your object by accessing the boundingBox.

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

Transfer data between an HTML page and a PHP page hosted on separate locations using jQuery

Below is the code snippet I am currently working on: function send_data() { var a=$("#username").val(); var b=$("#password").val(); $.post("http://localhost/login/login.php", {uname: a, pswd: b}, function(data) { $("#result").html(data); }); ...

What is the best way to assign an active class to a specific footer ID on an HTML page using AngularJS?

I tried using the activeLink directive to apply an active class to a specific id on the page, but it didn't work as expected. .directive('activeLink', ['$location', function (location) { return { restrict: 'A', ...

Remove a particular character from a string only if it is found to the left of specific characters

I'm currently working on a problem where I need to filter out specific characters from a string, but only if they appear to the left of certain other characters. For instance, in the string 'abcdarjakffa', I want to remove all instances of & ...

Using a series of identical divs to dynamically update the image URL

Greetings! I am a newcomer to the world of web development and I have decided to hone my skills by creating a small website for my mother! My goal is to replicate a specific div multiple times while changing only the image URL and the heading caption. < ...

Vue.js application failing to display images fetched from the server

When I'm running my Vue.js app locally, the images are loading fine from the "src/assets" folder. However, when I deploy the app to Firebase, the images are not displaying and I get a 404 error. What could be causing this issue? I have tried using: ...

Issues with storing data in localStorage have been identified in the Facebook browser for iOS

When our web app (built using React) is accessed through the Facebook browser on iOS and Android, we have noticed some unusual behavior with the local storage. Our authentication process relies on storing a token in local storage and then retrieving it. Th ...

Ways to store Token in Browser Cache?

I am currently developing a login system for an application at my school. I have successfully implemented user registration, which is saved to my Azure DocumentDB. However, when trying to log in with the user, the token does not get saved so that I can acc ...

Obtaining the date for the previous month using JavaScript or jQuery

I need to retrieve a specific date in JavaScript. My goal is to obtain the current date based on a variable named frequency, which can have values of Daily, Weekly, or Monthly. if(frequency=="daily") { date='current_date -2 days'; } e ...

Retrieving the world normal vector from the hitTest face's normal vector

As I perform a hitTest to generate a section plane based on a face normal, I find that extracting the global normal requires some adjustment to the hitTest.face.normal. While it appears to be almost correct, my resulting normal seems to deviate slightly fr ...

Vue Testing Utilities - issue with data not updating upon click event activation

I recently created a basic test using Vue Test Utils: import { mount } from '@vue/test-utils' const App = { template: ` <p>Count: {{ count }}</p> <button @click="handleClick">Increment</button> `, ...

Confirm that the input into the text box consists of three-digit numbers separated by commas

Customers keep entering 5 digit zip codes instead of 3 digit area codes in the telephone area code textbox on my registration form. I need a jQuery or JavaScript function to validate that the entry is in ###,###,###,### format without any limit. Any sugge ...

What is the best way to generate a new DIV every time a button is clicked?

I am attempting to make a square DIV that is red and measures 100x100 pixels. Each time a button is clicked, I want the square to be created. However, the code I have written is not functioning properly: <html> <title> Create New Div ...

Ways to showcase an item within additional items?

I'm struggling to properly display data in a table. My goal is to iterate through an object within another object inside an array and showcase the source, accountId, name, and sourceId in the table. https://i.sstatic.net/VVIuc.png <tbody clas ...

Ensure that the second y-axis in charts.js consistently shows the 100% tick

I have implemented a scatter chart using recharts and it currently looks like this: The right-y-axis in my chart represents the percentage and is showing the correct values as desired. However, I am looking to make a modification so that the 100% mark is ...

Leveraging Selenium for extracting data from a webpage containing JavaScript

I am trying to extract data from a Google Scholar page that has a 'show more' button. After researching, I found out that this page is not in HTML format but rather in JavaScript. There are different methods to scrape such pages and I attempted t ...

Retrieving information in JSON format

My goal is to retrieve data from the info.php file in order to utilize it in my project. This is what the content of info.php looks like: <?php $dbh = new PDO('mysql:host=localhost;dbname=csgo', 'root', ''); $sth = $dbh ...

What are the steps to create a dynamic background image that adjusts to various

When viewing the website on a computer screen, the entire cat is visible in the background image. However, when switching to a mobile screen size, only a portion of the cat is displayed, appearing as though it has been cut off. The image is not smaller on ...

React has been reported to display a Minified React error even in its development mode

Currently, I am utilizing browserify and babel for transpiling and bundling my script. However, a challenge arises when React 16 is incorporated as it presents the following error message: Uncaught Error: Minified React error #200; for more details, kin ...

The domain retrieval is contingent on the language preference of the user

A task has been assigned to create a script in JavaScript/jQuery (or other suitable technologies) that will return a domain with a .pl extension if the user's browser language is set to Polish. Otherwise, the script should return a .eu domain extensio ...

Detaching the jQuery event where the context is tied to the handler

My current challenge involves removing a jQuery event with a callback function bound using this. The issue arises from the fact that .bind() generates a new function each time it is called, causing difficulties when trying to remove the event. I am strugg ...