Adjust window size while keeping the current zoom level

As I continue to explore three.js, I am becoming familiar with the operations of the camera and renderer. My current focus is on implementing the functionality to drag and resize the canvas that three.js utilizes.

My goal is to enable the canvas to be dragged and resized without scaling up the scene itself. This means that a larger canvas will show more of the scene, rather than making the scene bigger.

Answer №1

In case you're still in search of a solution, I came across a fiddle that might help with what you're trying to achieve: http://jsfiddle.net/psyrendust/8nbpehj3/ (Please note that I do not own this fiddle)

You'll need to make adjustments to the field of view:

// Keeping track of original values
var tanFOV = Math.tan( ( ( Math.PI / 180 ) * camera.fov / 2 ) );
var windowHeight = window.innerHeight;

// Adding Event Listeners
window.addEventListener( 'resize', onWindowResize, false );

function onWindowResize( event ) {

    camera.aspect = window.innerWidth / window.innerHeight;

    // Modifying the FOV
    camera.fov = ( 360 / Math.PI ) * Math.atan( tanFOV * ( window.innerHeight / windowHeight ) );

    camera.updateProjectionMatrix();
    camera.lookAt( scene.position );

    renderer.setSize( window.innerWidth, window.innerHeight );
    renderer.render( scene, camera );

}

I hope this information proves helpful.

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

Mocha maintains the integrity of files during testing

After running a unit test to update a config file, I noticed that the file was altered. My initial thought was to use "before" to cache the file and then restore it with "after". mod = require('../modtotest'); describe('Device Configuratio ...

When a JSON response contains an array of objects with only one element, it is received as a single object

When sending a response from my resource as an array of objects, I encounter an issue where if the array only contains one element, the response is transformed into a single object instead of an array with one object, preventing me from looping through it. ...

Avoiding redundant data in CRUD applications

In a CRUD application (back-end using express and front-end using react-redux), form values are submitted to a mongodb database with the following schema: import mongoose from 'mongoose'; var Schema = mongoose.Schema({ createdAt:{ type: D ...

Steps to dynamically set the value of an input type="time" using JavaScript

Despite the repetitive nature of these questions, I have yet to find a solution to my specific query. Any help would be greatly appreciated. Thank you in advance. The HTML code is as follows: var start="10:30 PM"; $scope.edit={} frtime=start.split("PM ...

Exclude specific fields when updating a document in Firebase using the update()

Currently, I am storing a class in Firebase by using the update() function. Is there a way to stop specific fields (identified by name) of the object from being saved to the Firebase database? It's similar to how we use the transient keyword in Java ...

The .click function in jQuery ceases to function after being utilized once

I've encountered an issue with my .click jQuery function. The desired behavior is that when I click the button, one div should be hidden (display:none) and another div should be shown (display:block). This works as expected the first time the button i ...

Is there a way to automatically remove files from the "dist" directory when deleting the prototype from the "src" folder?

I am new to build systems and seeking assistance with the following question. Here is the structure of my boilerplate: /src (working folder) ___/templates(jade files) ___/scss ___/scripts /dist (compiled files) ___/css ___/js ___.html files In the te ...

Clicking on a row in ng2-smart-table should result in the row being

I have attempted to address the issue, but I am struggling to highlight a row on click event. <ng2-smart-table [settings]="settingsPatient" [source]="sourcePatient" (userRowSelect)="patientStudy($event)" (deleteConfirm)="onDeleteConfirm($event)">" ...

Combine all possible pairings of elements from two distinct arrays

Is there a way to combine the elements of two arrays and return them in a new array? Let's say we have these two arrays: const whoArr = ["my", "your"]; const credentialArr = ["name", "age", "gender" ...

The functionality of AngularJS ng-disable is failing to work on an anchor tag

I am currently facing a challenge in my AngularJS project where I need to disable an icon within an ng-repeat scenario based on a condition. Specifically, I want to check if the owner is null and then disable the icon accordingly. However, despite verifyin ...

Merging scripts to minimize HTTP requests - The Takeover of the Body Swappers

For my website design, I've implemented the Invasion Of The Body Switchers script from brothercake.com. This script involves loading three separate js files in the header. I'm looking to optimize my site by reducing the number of HTTP requests a ...

Implement a vertical scrolling animation in datatables

I am trying to utilize datatables to display all data. My goal is to have the data automatically scroll row by row every 3 seconds. This is my code, and you can also check it out on jsfiddle The intention is to showcase this data on a large screen. < ...

What is the process for inserting a new item into a JavaScript dictionary?

I have a specific dictionary structure that lists different movies along with their respective actors. I want to create a function that allows me to manipulate this dictionary to include additional actors based on certain criteria. Here is an example of t ...

Use jQuery to dynamically add a form when a checkbox is checked

Hey everyone, I am using a checkbox to toggle the form visibility in my web application. Here is the code snippet I have implemented: $('.checkbox-primary').change(function () { $url = $('.form-edit').attr('action'); ...

The text's worth in the code of javascript

Having an issue with my code where I want to add a string to my Confirm() function in JavaScript but it's not working correctly. myData.setValue(i, 9, '<a href="'+scriptDelete+'" onclick="return confirm();" > Delete </a>&ap ...

Leveraging the For loop in the MongoDB Aggregation pipeline

Seeking a more efficient way to query data in MongoDB. In my collection, I store hourly information for each user_id. Each document in the collection corresponds to a unique user_id and date combination. However, a user_id can have multiple entries with d ...

Is relying on getState in Redux considered clunky or ineffective?

Imagine a scenario where the global store contains numerous entities. Oranges Markets Sodas If you want to create a function called getOrangeSodaPrice, there are multiple ways to achieve this: Using parameters function getOrangeSodaPrice(oranges, s ...

Tips for resizing a tooltip using CSS

I am currently working on customizing tooltips and would like them to display right below the hover text in a responsive manner, with the ability to have multiline text. Instead of spreading horizontally, I want the tooltip to expand vertically based on th ...

Are memory allocations made for empty indices in Typescript Arrays?

I am faced with the challenge of replicating a segment of a server-side database for processing within a typescript web application. My goal is to access specific records by their integer ID in typescript. The issue at hand is that the indices may not be s ...

In Vue.js, a blank screen may appear if the created() lifecycle hook is not utilized or if the spread operator (...)

The situation I'm facing is that the code in this example results in a blank screen, as shown in this jsfiddle. Even elements unrelated to the loop are not being displayed. Here's a snippet of the HTML: <div id="app"> <butto ...