Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@
"misc_exporter_usdz",
"misc_exporter_exr",
"misc_exporter_ktx2",
"misc_lookat",
"misc_raycaster_helper"
],
"css2d": [
Expand Down
145 changes: 0 additions & 145 deletions examples/misc_lookat.html

This file was deleted.

Binary file removed examples/screenshots/misc_lookat.jpg
Binary file not shown.
34 changes: 30 additions & 4 deletions examples/webgl_math_orientation_transform.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@

import * as THREE from 'three';

import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

let camera, scene, renderer, mesh, target;

const spherical = new THREE.Spherical();
const rotationMatrix = new THREE.Matrix4();
const targetQuaternion = new THREE.Quaternion();
const clock = new THREE.Clock();
const speed = 2;
const speed = Math.PI / 2;

const params = {
useLookAt: false,
};

init();

Expand Down Expand Up @@ -78,6 +84,13 @@

//

const gui = new GUI();

gui.add( params, 'useLookAt' );
gui.open();

//

generateTarget();

}
Expand All @@ -95,10 +108,23 @@

const delta = clock.getDelta();

if ( ! mesh.quaternion.equals( targetQuaternion ) ) {
if ( mesh.quaternion.equals( targetQuaternion ) === false ) {

if ( params.useLookAt === true ) {

// using lookAt() will make the mesh instantly look at the target

mesh.lookAt( target.position );

} else {

// using rotateTowards() will gradually rotate the mesh towards the target
// the "speed" variable represents the rotation speed in radians per seconds

const step = speed * delta;
mesh.quaternion.rotateTowards( targetQuaternion, step );

const step = speed * delta;
mesh.quaternion.rotateTowards( targetQuaternion, step );
}

}

Expand Down