Question: please review these codes Did the assignment output include a 3 D object selected from the list? ( Yes / No ) ( Sphere ,

please review these codes
Did the assignment output include a 3D object selected from the list? (Yes/No)(Sphere, Cube, or Torus Knot)
Was the object animated making it move (In both x and y directions) within the viewing area and simulate bouncing off the walls when the edge of the viewing area was reached? (Yes/No)
Was a basic color applied to the object and was the color changed every time the object encountered an edge of the viewing area? (Yes/No)
Did the scene employ a light-yellow light source in a fixed position at the upper left corner to illuminate the object and did the illumination demonstrate both light and shadow on the object? (Yes/No)
Was the JavaScript / Three.js code well documented (Scale of 1-4 where 1 is no comments and 4 is comprehensive comments)
// Setup scene, camera, and renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1,1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Create a sphere with red color
const sphereGeometry = new THREE.SphereGeometry(1,32,32);
const sphereMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000});
const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
scene.add(sphere);
// Set initial position and velocity of the sphere
sphere.position.x =0;
sphere.position.y =0;
let velocity ={ x: 0.03, y: 0.02};
// Add a light-yellow light source at the upper left corner
const light = new THREE.PointLight(0xffffe0,1,100);
light.position.set(-10,10,10);
scene.add(light);
// Animation loop to move the sphere and handle bouncing
function animate(){
requestAnimationFrame(animate);
// Update sphere position based on velocity
sphere.position.x += velocity.x;
sphere.position.y += velocity.y;
// Check boundaries and reverse direction upon collision
if (sphere.position.x >=4|| sphere.position.x <=-4){
velocity.x =-velocity.x; // Reverse direction on X-axis
sphere.material.color.setHex(Math.random()*0xffffff); // Change color randomly
}
if (sphere.position.y >=4|| sphere.position.y <=-4){
velocity.y =-velocity.y; // Reverse direction on Y-axis
sphere.material.color.setHex(Math.random()*0xffffff); // Change color randomly
}
// Render the scene
renderer.render(scene, camera);
}
// Set the camera position and start the animation loop
camera.position.z =5;
animate();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!