We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i'm making a program that displays a 3D model of a Nitrate molecule, however i can't seem to figure out how to get my labels for the Oxygen to follow their respective atoms. My code is all below, can someone tell me what i have to do to get the big "O" to follow a red sphere, however to not rotate with them and just follow them on the outside as if they were on an x y plane??? Also, i haven't yet removed some of the extraneous code from my previous failed attempts so try and ignore that.
float theta;
float thetaY;
void setup(){
size(800,800,OPENGL);
background(0);
noStroke();
textSize(40);
}
void draw(){
background(0);
fill(255,0,0);
translate(400,400);
lights();
//O
pushMatrix();
theta = (PI*mouseX / width)*2;
thetaY = (PI*mouseY / height)*2;
rotateY(theta);
rotateX(thetaY);
translate(width/4,height/3.5);
sphere(30);
fill(0,255,0);
strokeWeight(5);
point(200,200,-100);
fill(255);
//Label
fill(100);
strokeWeight(5);
line(0,0,-width/2,-height/2);
fill(255,0,0);
popMatrix();
pushMatrix();
theta = (PI*mouseX / width)*2;
thetaY = (PI*mouseY / height)*2;
rotateY(theta);
rotateX(thetaY);
translate(-width/4,height/3.5);
sphere(30);
popMatrix();
pushMatrix();
theta = (PI*mouseX / width)*2;
thetaY = (PI*mouseY / height)*2;
rotateY(theta);
rotateX(thetaY);
translate(width/50,-height/3);
sphere(30);
popMatrix();
//N
pushMatrix();
translate(width/500,height/500);
fill(0,0,255);
sphere(30);
fill(255);
text("N",-width/50,height/50,100);
popMatrix();
//Bonds
fill(100);
Label();
}
void Label(){
text("O",200,200,100);
}
void mousePressed(){
println(mouseX,mouseY);
}
Answers
Bump
there are a lot of ways to do that
this one is fairly elegant, since the O looks always in the camera (and is not seen from the side or so)
thank you, this works perfectly! Also, i'm trying to work out how to create a cylinder to represent the bonds. Do you have any suggestions on how to do this, i'm still new to the 3d dimensional stuff.
hi,
I can show you this. You can either use the normal line since it also accepts 3D parameters (from xyz and to xyz) and not only 2D params (from xy and to xy)
also there is an old routine for boxy connection.
but you might want to look at the libraries such as Shapes 3D and peasyCam
http://www.processing.org/reference/libraries
;-)