Skip to content

Commit 8e038e1

Browse files
author
Release Manager
committed
gh-pr-34960: Improve camera positioning for threejs Fixes #34822. The template says that we are not yet accepting PRs. But I will just go ahead. URL: #34960 Reported by: Kwankyu Lee Reviewer(s): Dima Pasechnik
2 parents 9773108 + 952a6c9 commit 8e038e1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/sage/ext_data/threejs/threejs_template.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,17 @@
214214
camera.up.set( 0, 0, 1 );
215215
camera.position.set( a[0]*xMid, a[1]*yMid, a[2]*zMid );
216216

217-
var offset = new THREE.Vector3( a[0]*xRange, a[1]*yRange, a[2]*zRange );
217+
// camera is positioned so that the line from the camera to the center
218+
// of the bounding sphere of the objects makes an angle of 60 degrees with x-axis
219+
// and an angle of 30 degrees with z-axis and the field of view of the camera looking
220+
// at the center has an angle of 45 degrees.
221+
const sin8 = Math.sin(Math.PI / 8);
222+
const sin5 = Math.sin(Math.PI / 5);
223+
const cos5 = Math.cos(Math.PI / 5);
224+
const sin3 = Math.sin(Math.PI / 3);
225+
const cos3 = Math.cos(Math.PI / 3);
226+
var r = midToCorner / sin8;
227+
var offset = new THREE.Vector3( r * sin3 * cos5, r * sin3 * sin5, r * cos3 );
218228

219229
if ( options.viewpoint ) {
220230

@@ -569,7 +579,7 @@
569579
setTimeout( function() { m.style.display = 'none'; }, 2000 );
570580

571581
}
572-
582+
573583
</script>
574584

575585
<div id="menu-container" onclick="toggleMenu()">&#x24d8;

0 commit comments

Comments
 (0)