{
let canvas = html`<canvas width="${width}" height="400"/>`
let projection = glm.mat4.create();
let model = glm.mat4.create();
let view = glm.mat4.create();
let ident = glm.mat4.create();
let sphere = null;
let a = 0;
async function setup(gl) {
gl.enable(gl.DEPTH_TEST);
gl.clearColor(0,0,0,1);
glm.mat4.perspective(projection,(45*Math.PI)/180,width/400,0.1,100);
gl.activeTexture(gl.TEXTURE0);
await gl_utils.textures.load(gl,sol);
gl.activeTexture(gl.TEXTURE1);
await gl_utils.textures.load(gl,mercurio);
gl.activeTexture(gl.TEXTURE2);
await gl_utils.textures.load(gl,venus);
gl.activeTexture(gl.TEXTURE3);
await gl_utils.textures.world(gl);
gl.activeTexture(gl.TEXTURE4);
await gl_utils.textures.load(gl,lua);
gl.activeTexture(gl.TEXTURE5);
await gl_utils.textures.load(gl,marte);
// Jupiter
gl.activeTexture(gl.TEXTURE6);
await gl_utils.textures.load(gl,jupiter);
// Saturno
gl.activeTexture(gl.TEXTURE7);
await gl_utils.textures.load(gl,saturno);
// Urano
gl.activeTexture(gl.TEXTURE8);
await gl_utils.textures.load(gl,urano);
// Netuno
gl.activeTexture(gl.TEXTURE9);
await gl_utils.textures.load(gl,netuno);
sphere = sphereGeometry(gl);
gl_utils.viewHandler(canvas,(x,y,z)=>{
glm.mat4.lookAt(view,[2*x,2*y,2*z],[0,0,0],[0,1,0]);
});
}
function draw(gl) {
// Sol
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
glm.mat4.rotate(model,ident,a,[0,1,0]);
sphere.draw({model, view, projection, textura: 0});
//Mercurio
glm.mat4.rotate(model,ident,-a * 5 ,[0,1,0]);
glm.mat4.translate(model,model,[-3,0,0]);
glm.mat4.scale(model,model,[0.2,0.2,0.2]);
sphere.draw({model, view, projection, textura: 1});
// Venus
glm.mat4.rotate(model,ident,-a * 4,[0,1,0]);
glm.mat4.translate(model,model,[-5,0,0]);
glm.mat4.scale(model,model,[0.2,0.2,0.2]);
sphere.draw({model, view, projection, textura: 2});
//Terra
glm.mat4.rotate(model,ident,-a * 2,[0,1,0]);
glm.mat4.translate(model,model,[-7,0,0]);
glm.mat4.scale(model,model,[0.2,0.2,0.2]);
sphere.draw({model, view, projection, textura: 3});
// Lua
glm.mat4.rotate(model,model,-a,[0,1,0]);
glm.mat4.translate(model,model,[-4,0,0]);
glm.mat4.scale(model,model,[0.2,0.2,0.2]);
sphere.draw({model, view, projection, textura: 4});
// Marte
glm.mat4.rotate(model,ident,-a * 1.8,[0,1,0]);
glm.mat4.translate(model,model,[-9,0,0]);
glm.mat4.scale(model,model,[0.2,0.2,0.2]);
sphere.draw({model, view, projection, textura: 5});
//Jupiter
glm.mat4.rotate(model,ident,-a * 1.4,[0,1,0]);
glm.mat4.translate(model,model,[-11,0,0]);
glm.mat4.scale(model,model,[0.4,0.4,0.4]);
sphere.draw({model, view, projection, textura: 6});
//Saturno
glm.mat4.rotate(model,ident,-a * 1.2,[0,1,0]);
glm.mat4.translate(model,model,[-13,0,0]);
glm.mat4.scale(model,model,[0.3,0.3,0.3]);
sphere.draw({model, view, projection, textura: 7});
//Urano
glm.mat4.rotate(model,ident,-a *1,[0,1,0]);
glm.mat4.translate(model,model,[-15,0,0]);
glm.mat4.scale(model,model,[0.3,0.3,0.3]);
sphere.draw({model, view, projection, textura: 8});
//Netuno
glm.mat4.rotate(model,ident,-a * 0.8,[0,1,0]);
glm.mat4.translate(model,model,[-17,0,0]);
glm.mat4.scale(model,model,[0.2,0.2,0.2]);
sphere.draw({model, view, projection, textura: 9});
a += 0.01;
}
return gl_utils.appLoop(canvas,{setup,draw});
}