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);
}