He estado un poco ausente este mes debido a mi exámenes finales de mi Universidad. Felizmente todo ha salido como esperaba y ahora retomo mi blog con un post que muchos esperaban.

Esta contribución llega desde España. Mi amigo Ivan Flores que es el desarrollador de este ejemplo ha decidido liberar su trabajo bajo licencia commons by-nc-sa (Lee la licencia antes de usar el trabajo)

Su trabajo comprende en la creación de orbitas, movimientos independientes  y sombras. Aún está en fase alpha pero promete enseñarnos cuando lo concluya.

A continuación les dejo el código:

//Ivan Flores
//http://twitter.com/kebesweb

import processing.video.*;
import jp.nyatla.nyar4psg.*;
import processing.opengl.*;
import javax.media.opengl.*;

Capture cam;
NyARBoard mark1;

float angSol = 0.0,
angPlaneta1 = 0.0,
angPlaneta2 = PI/3.0,
angPlaneta3 = 2.0*PI/3.0,
angLuna1 = 0.0,
angLuna2 = PI;

void setup() {

size(800,600,OPENGL);
colorMode(RGB, 100);
frameRate(200);
smooth();
noStroke();

cam=new Capture(this,width,height);
mark1=new NyARBoard(this,width,height,”camera_para.dat”,”patt.hiro”,80);

mark1.gsThreshold=120;
mark1.cfThreshold=0.4;

}

void draw() {

if (cam.available() !=true) {
return;
}
cam.read();

hint(DISABLE_DEPTH_TEST);
image(cam,0,0);
hint(ENABLE_DEPTH_TEST);

if(mark1.detect(cam)){

PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
mark1.beginTransform(pgl);

dibujar();

mark1.endTransform();
}
}
void dibujar(){
lights();
directionalLight(126, 126, 126, 0, 0, 1);
//pointLight(126, 126, 126, 0, 0, 0);

pushMatrix();
translate(0, 0, 40);
stroke(0,50);
noFill();
ellipse(0,0,200,200);
noStroke();
popMatrix();

//SOL
pushMatrix();
rotateZ(angSol += 0.01);
translate(0, 100, 0);
fill(0,50);
ellipse(0,0,40,40);
translate(0, 0, 40);
fill(#F1FA03);
sphere(40);

//radios

stroke(0,50);
noFill();
ellipse(0,0,150,150);
ellipse(0,0,300,300);
ellipse(0,0,500,500);
noStroke();

//PLANETA1
pushMatrix();
rotateZ(angPlaneta1 += 0.1);
translate(0, 70, 0);
fill(#05FA03);
sphere(20);
pushMatrix();
translate(0,0,-40);
fill(0,50);
ellipse(0,0,20,20);
popMatrix();
popMatrix();

//PLANETA2
pushMatrix();
rotateZ(angPlaneta2 += 0.05);
translate(0, 150, 0);
fill(#0BA00A);
sphere(20);
pushMatrix();
translate(0,0,-40);
fill(0,50);
ellipse(0,0,20,20);
popMatrix();

//radios

stroke(0,50);
noFill();
ellipse(0,0,60,60);
ellipse(0,0,100,100);
noStroke();

//Luna1
pushMatrix();
rotateZ(angLuna1 += 0.01);
translate(0, 30, 0);
fill(#08E4FF);
sphere(5);
pushMatrix();
translate(0,0,-40);
fill(0,50);
ellipse(0,0,5,5);
popMatrix();
popMatrix();

//Luna2
pushMatrix();
rotateZ(angLuna2 += 0.05);
translate(0, 50, 0);
fill(#118998);
sphere(8);
pushMatrix();
translate(0,0,-40);
fill(0,50);
ellipse(0,0,8,8);
popMatrix();
popMatrix();
popMatrix();

//PLANETA3
pushMatrix();
rotateZ(angPlaneta3 += 0.025);
translate(0, 250, 0);
fill(#075806);
sphere(15);
ellipse(0,0,40,40);
pushMatrix();
translate(0,0,-40);
fill(0,50);
ellipse(0,0,15,15);
popMatrix();
popMatrix();

popMatrix();//sol
}

Aquí dejo el link de descarga

2 COMMENTS

  1. Pido perdón ya que es una versión muy verde del sistema solar la que he compartido, ahora ya estoy importando modelos 3D para visualizar los planetas. Se admiten sugerencias!

Deja un comentario

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.