What I want is a stationary camera to rotate via the mouse to view stars all around.
To face a star, move the mouse towards it and it comes into center frame.
The problem is, rotating around the X and Y axis does not accomplish this correctly.
How is this code be improved so the star moves in a strait line to the center frame?
Code:import processing.opengl.*;
final static int R = 1000;
float u, v;
float[][] stars;
void setup()
{
size(800, 800, OPENGL);
frameRate(30);
sphereDetail(1);
textFont(createFont("Monaco", 14));
stars = new float[1000][3];
for(int i = 0; i < stars.length; i++)
{
float[] star = { random(-R, R), random(-R, R), random(-R, R) };
stars[i] = star;
}
}
void draw()
{
u += (mouseY - height / 2.0) / height / 20;
v += (mouseX - width / 2.0) / width / 20;
background(0);
lights();
camera(0, 0, 0, 0, 0, R, 0, 1, 0);
rotateX(u); rotateY(v);
noStroke();
for(int i = 0; i < stars.length; i++)
{
pushMatrix();
translate(stars[i][0], stars[i][1], stars[i][2]);
sphere(5);
popMatrix();
}
camera();
stroke(255);
line(width / 2 - 5, height / 2 - 0, width / 2 + 4, height / 2 + 0);
line(width / 2 - 0, height / 2 - 5, width / 2 + 0, height / 2 + 4);
text("u: " + int(degrees(u)) + " v: " + int(degrees(v)), 5, 17);
}
void mousePressed() { u = v = 0; }