//import processing.opengl.*; //import net.java.games.jogl.*; float a; //GL gl; void setup() { size(400,400,P3D); // gl=((PGraphicsGL)g).gl; perspective(PI/3.0,1, 1,1000); noCursor(); noStroke(); a=0; sphereDetail(7); } void draw() { a+=0.01; background(0); lights(); camera(0,-50,50,0,0,0,0,0,-1); fill(128,200,128); beginShape(QUADS); { vertex(-50,-50,0); vertex(50,-50,0); vertex(50,50,0); vertex(-50,50,0); } endShape(); Vector camPos=new Vector(0,-50,50); Vector camDir=new Vector(0,1,-1); fill(255,0,0); Vector left=cross(new Vector(0,0,1),camDir); Vector up=cross(camDir,left); // printVector("camDir",camDir); // printVector("left",left); // printVector("up",up); Vector tmp=rotate(camDir,up,-PI/6.0); // printVector("tmp",tmp); Vector tmp2=rotate(camDir,left,-PI/6.0); // printVector("tmp2",tmp2); /* pushMatrix(); translate(0,-50,50); // vectors from camera, not world-coords pushMatrix(); translate(50*camDir.x,50*camDir.y,50*camDir.z); fill(255,0,0); sphere(3); popMatrix(); pushMatrix(); translate(50*tmp.x,50*tmp.y,50*tmp.z); fill(0,255,0); sphere(3); popMatrix(); pushMatrix(); translate(50*tmp2.x,50*tmp2.y,50*tmp2.z); fill(0,0,255); sphere(3); popMatrix(); popMatrix();*/ Vector[] camPlane=new Vector[3]; camPlane[0]=add(new Vector(0,0,0),add(mul(left,1000),mul(up,1000))); camPlane[1]=add(new Vector(0,0,0),add(mul(left,1000),mul(up,-1000))); camPlane[2]=add(new Vector(0,0,0),mul(left,-1000)); Vector mid=intersectPoint(camPlane[0],camPlane[1],camPlane[2],camPos,add(camPos,mul(camDir,300))); Vector leftEdge=intersectPoint(camPlane[0],camPlane[1],camPlane[2],camPos,add(camPos,mul(tmp,300))); Vector topEdge=intersectPoint(camPlane[0],camPlane[1],camPlane[2],camPos,add(camPos,mul(tmp2,300))); // printVector("mid",mid); // printVector("leftEdge",leftEdge); // printVector("topEdge",topEdge); Vector deltaX=div(dir(mid,leftEdge),(float)width/2.0); // printVector("deltaX",deltaX); Vector deltaY=div(dir(mid,topEdge),(float)height/2.0); // printVector("deltaY",deltaY); Vector mouseVectorX=add(leftEdge,mul(deltaX,constrain(mouseX,0,width-1))); Vector mouseVectorY=add(topEdge,mul(deltaY,constrain(mouseY,0,height-1))); Vector mousePlaneVector=add(mouseVectorX,mouseVectorY); Vector mouseCameraVector=mul(dir(camPos,mousePlaneVector),100); Vector ip=intersectPoint(new Vector(-1000,-1000,0),new Vector(0,1000,0),new Vector(1000,-1000,0),camPos,add(camPos,mouseCameraVector)); // translate(0,-50,50); pushMatrix(); translate(mid.x,mid.y,mid.z); fill(255,0,0); sphere(3); popMatrix(); pushMatrix(); translate(leftEdge.x,leftEdge.y,leftEdge.z); fill(0,255,0); sphere(3); popMatrix(); pushMatrix(); translate(topEdge.x,topEdge.y,topEdge.z); fill(0,0,255); sphere(3); popMatrix(); /* pushMatrix(); translate(mousePlaneVector.x,mousePlaneVector.y,mousePlaneVector.z); fill(255,0,255); sphere(3); popMatrix();*/ pushMatrix(); translate(ip.x,ip.y,ip.z); fill(255,255,0); box(3); popMatrix(); // println("Dot:"+Dot(new Vector(0.806,0.806,0),new Vector(0,100,0))); /* a+=0.01; background(0); Vector axis=new Vector(0,-100,0); Vector thing=new Vector(-100,100,0); Vector res=rotate(thing,axis,a); translate(width/2,height/2,0); rotateY(mouseX/(float)width); beginShape(LINES); { stroke(255,0,0); vertex(0,0,0); vertex(axis.x,axis.y,axis.z); stroke(0,255,0); vertex(0,0,0); vertex(thing.x,thing.y,thing.z); stroke(0,0,255); vertex(0,0,0); vertex(res.x,res.y,res.z); } endShape(); */ }