I've been exploring different options for rotating objects, but I'm not sure how to implement them. As a newcomer to JavaScript, I managed to create a cube and a sphere that rotates around its own axis. However, I need the sphere to rotate around the cube instead. Any guidance would be appreciated.
<html>
<head>
<title>Exploring Three.js</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="js/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 100, window.innerWidth/window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
camera.position.z = 25;
var loader = new THREE.TextureLoader();
var texture = loader.load('crate.jpg');
var geometry = new THREE.BoxGeometry( 7, 7, 7 );
var material = new THREE.MeshBasicMaterial({map: texture});
var cube = new THREE.Mesh(geometry, material);
cube.rotation.x += 0.6;
cube.rotation.y += 0.6;
scene.add( cube );
var loader = new THREE.TextureLoader();
var texture = loader.load('earth.jpg');
var geometry = new THREE.SphereGeometry( 1, 50, 50 );
var material = new THREE.MeshBasicMaterial( {map: texture} );
var sphere = new THREE.Mesh( geometry, material );
scene.add( sphere );
var render = function () {
requestAnimationFrame( render );
sphere.position.set(6, 0, 15);
sphere.rotation.y += 0.01;
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>