We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Camera rotation for lookThrough
Page Index Toggle Pages: 1
Camera rotation for lookThrough (Read 445 times)
Camera rotation for lookThrough
Apr 20th, 2010, 6:39am
 
I need help on the math for getting the camera to look through a particular point based on the relative position.  I have an Earth sketch with points identified as locations, I'd like to be able to rotate the Earth to the particular vector when selected from a menu (supplying the location's xyz).  Here is some example code.
Code:
import peasy.*;

PeasyCam cam;

void setup() {
 size(200,200,P3D);
 cam = new PeasyCam(this, 100);
 cam.setMinimumDistance(50);
 cam.setMaximumDistance(500);


}
void draw() {
 rotateX(.5);
 rotateZ(-.5);

 background(0);
 fill(255,0,0);
 box(30);

 pushMatrix();
 translate(0,20,0);  
 fill(0,255,0);    //Green Box
 box(5);
 popMatrix();

 pushMatrix();
 translate(0,0,20);
 fill(0,0,255);    //Blue Box
 box(5);
 popMatrix();

}

void keyPressed() {
 if (key == 'b' || key == 'B') {
   lookThrough(0,0,20);  //Blue box
 }
 if (key == 'g' || key == 'G') {
   lookThrough(0,20,0);  //Green box
 }
}

void lookThrough(int x, int y, int z) {
 float rotx, roty, rotz;

 //What is the math to rotate the camera to look through this point?
 
 cam.rotateX(rotx);
 cam.rotateY(roty);
 cam.rotateZ(rotz);
}
Page Index Toggle Pages: 1