Zoom implementation code for 3D field of view in three.js

Through Threejs Basic Learning – Modifying Edition knows about creating a camera-related knowledge point

  VAR Camera = New Three.PerspectiveCamera (Fov, Aspect, Near, FAR)  

Visual corner: FOV here (some places called shooting distance), the smaller the object in the scene, the smaller the horizontal angle, the object in the scene The larger than
Aspect (3D object width / high proportion)
The camera is close to the volume: NEAR
The camera is away from the farthest size: FAR
where the FOV is angle (The larger the shooting distance), the smaller the object in the scene. The smaller the field of FOV (shooting distance), the larger the object in the scene.

three.js中3D视野的缩放实现代码 three.js中3D视野的缩放实现代码 Perspective camera (near large far less) PerspectiveCamera


// Perspective camera parameters Set VAR FOV = 45, // The larger the visual view of the shooting distance, the smaller the object in the scene, the smaller NEAR = 1, // The camera is close to the volume of the most recent distance FAR = 1000, // The camera is farthest aspect = Window.innerWidth / Window.innerHeight; // Aspected VAR Camera = New Three.PerspectiveCamera (FOV, Aspect, NEAR, FAR);

 Change the value of the FOV, And update this camera   
/ / Change the FOV value, and update the rendering of the scene Camera.fov = fov; Camera.UpdateProjectionMatrIX (); renderer.render (Scene, Camera); // updateInfo ();
Mouse-down slide implementation amplification reduction effect code is as follows


// Monitor mouse scroll event canvas.addeventListener (‘Mousewheel’, Mousewheel, False);
   

// Mouse pulley – mouse upside slide to enlarge the reduction effect Function MouseWheel (E) {E.PreventDefault (); //e.stoppropagation (); if (e.wheeldelta) {// Judgment browser IE, Google pulley event if (E.wheeldelta> 0) {// FOV – = (Near
0) {// when the pulley is scrolling up, fov – = 1;} if (E.DETAIL

 Implementation of the full code labeling specific case is personal original   
  < fov ? 1 : 0);
 }
 if (e.wheelDelta < 0) { //当滑轮向下滚动时
  fov += (fov  Zoom in Threejs < 0) { //当滑轮向下滚动时
  fov += 1;
 }
 }
 //改变fov值,并更新场景的渲染
 camera.fov = fov;
 camera.updateProjectionMatrix();
 renderer.render(scene, camera);
 //updateinfo();
}
 
# canvas-frame {width: 100%; Height: 600px;}

   VAR RENDERER, // Renderer Width = Document.GtelementByid ('Canvas-Frame ") .ClientWidth, // Canvas wide Height = Document.getlementByid ('canvas-frame'). ClientHeight; // Canvas high // camera configuration var fov = 45, // shooting distance viewing angle value, the larger in the scene Small Near = 1, // Minimum range FAR = 1000; // Maximum range // DOM object var canvas = null; // Initialization DOM object function initdom () {canvas = document.getElementByid ("canvas-frame"; } // initialize renderer function initThree () {renderer = new THREE.WebGLRenderer ({antialias: true // canvas: document.getElementById ( 'canvas-frame')}); renderer.setSize (width, height); renderer. setClearColor (0xFFFFFF, 1.0);. document.getElementById ( 'canvas-frame') appendChild (renderer.domElement); renderer.setClearColor (0xFFFFFF, 1.0);} // initialize scene var scene; function initScene () {scene = new Three.Scene ();} var camera; function initcamera () {// Perspective camera Camera = New Three.PerspectiveCamera (fov, width / hEIGHT, NEAR, FAR); Camera.Position.x = 150; Camera.Position.y = 150; Camera.position.z = 250; Camera.up.x = 0; Camera.up.y = 1; // Camera Direction-camera is Y-axis Camera.up.z = 0; Camera.Lookat ({// Central Point x: 0, Y: 0, Z: 0});} function initlight () {// light - Use ambient light // var Light = new three.directionallight (0xfffff); / * Directional light source * / ///light.position.set (600, 1000, 800); / * var Light = new Three.ambientlightLight (0xfffffff); // simulate a diffuse light source light.position.set (600, 1000, 800); // can ignore the direction and angle when using Ambient Light, consider the position of the light source Scene.Add (Light); * /} Function initObject () {// Initialization Object // Initialization floor initfloor ();} function initGrid () {// Auxiliary Grid Var helper = New Three.GridHelper (1000, 50); helper.setcolors (0x0000FF, 0x808080); Scene.Add (helper);} function initfloor () {// Create a cube var geometry = New Three.BoxGeometrY (80, 20, 80); for (var i = 0; i  0) {// FOV - = (Near  0) {// When the pulley is scrolling upward when the pulley is scrolling = 1;} if (e.detail     Article Zoom source: Three.js Implementation 3D visual field zoom effect   All of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.  
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment