We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to match a scene from Sketchup in Processing/OpenGL but can't seem to get the measurements right.
I'm using these simply commands in the Ruby Console in Sketchup:
model = Sketchup.active_model
cam = model.active_view.camera
print cam.eye, cam.direction, cam.fov
Which prints these values for my file:
(1668.854717mm, -1723.414322mm, 131.550996mm)(-0.688802494154077, 0.649067164730165, 0.322897723306109)63.6653435710446nil
The FOV seems to work, but I don't think I've figured out the camera position(units) yet. Here's my attempt:
float camEyeX = 1668.854717f;
float camEyeY = -1723.414322f;
float camEyeZ = 131.550996f;
float camTargetX = -0.688802494154077f;
float camTargetY = 0.649067164730165f;
float camTargetZ = 0.322897723306109f;
float camFOV = 63.665f;
float div = 10;
void setup(){
size(1280,720,P3D);
}
void draw(){
background(255);
perspective(radians(camFOV), width/height, camEyeZ * 0.1f, camEyeZ * 10);
camera(camEyeX/div, camEyeY/div, camEyeZ/div, camTargetX, camTargetY, camTargetZ, 1, 0, 0);
drawGrid(20,10,10,0);
drawGrid(20,10,10,1);
drawGrid(20,10,10,2);
}
void keyPressed(){
if(keyCode == UP) div++;
if(keyCode == DOWN) div--;
}
void drawGrid(int size,int w,int h,int plane){
pushStyle();
noFill();
if(plane == 0) stroke(255,0,0);
if(plane == 1) stroke(0,255,0);
if(plane == 2) stroke(0,0,255);
int total = w * h;
int tw = w * size;
int th = h * size;
beginShape(LINES);
for(int i = 0 ; i < total; i++){
int x = (i % w) * size;
int y = (i / w) * size;
if(plane == 0){
vertex(0,x,0);vertex(0,x,th);
vertex(0,0,y);vertex(0,tw,y);
}
if(plane == 1){
vertex(x,0,0);vertex(x,0,th);
vertex(0,0,y);vertex(tw,0,y);
}
if(plane == 2){
vertex(x,0,0);vertex(x,th,0);
vertex(0,y,0);vertex(tw,y,0);
}
}
endShape();
popStyle();
}
The grids look ok above using the perspective() call, but if I comment back the camera() call the scene disappears.
Any hints or tips will help. Processing code is ok, but I don't mind raw GL calls/matrices either.
Answers
camera default is 0,1,0 at the end
(1) The values you retrieved included the camera direction i.e the direction that the camera is facing from the eye position. In Processing the second set of 3 coordinates is a 3D position that the camera is looking at.
(2) the camEyeX/Y/Z coordinates should be the ACTUAL camera position so dividing by 10 doesn't make sense. If you are using it to zoom in/ zoom out it would be better to change the fov in the perspective command.
(3) The last 3 parameters are the camera up direction which is usually the positive Y direction hence 0,1,0 as pointed out by Chrisir
So I believe your camera command should be