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 & HelpOpenGL and 3D Libraries › OCD : cannot change the UP direction
Page Index Toggle Pages: 1
OCD : cannot change the UP direction ? (Read 1131 times)
OCD : cannot change the UP direction ?
Apr 9th, 2010, 11:21pm
 
hello all,
i'm now getting into a problem with OCD, which i think very useful one, though. my problem is that OCD seems not to refine the UP direction from its default state... even if i set the UP direction to (0,0,1), OCD seems to ignore or define it as (0,1,0)...
although i searched whether someone had the same problem, i couldn't find it out so far. is this my misunderstanding or a known issue or due to the difference of right- or left hand system? please try the code below. you can see my problem if you mouse-clicked. please help me!

Code:
import damkjer.ocd.*;
Camera cam;
float cam_field_of_view; //view angle
float cam_aspect;//aspect ratio
float cam_shotLength;//distance from camera to objects
float cam_nearClippingPLane, cam_farClippingPLane; //distance from the camera to each clipping plane


void setup(){
 size(1024,768, P3D);
 cam_field_of_view = PI/3.0;
 cam_aspect = (float)width/(float)height;
 cam_shotLength = height * 0.5 / tan(cam_field_of_view * 0.5);
 cam_nearClippingPLane = 0.1 * cam_shotLength;
 cam_farClippingPLane = 10 * cam_shotLength;
 
 cam = new Camera(this,
        500.0, 0.0, 0.0,
        0.0, 0.0, 0.0,
        0.0, 0.0, 1.0,
        cam_field_of_view, cam_aspect,
        cam_nearClippingPLane, cam_farClippingPLane);
}

void draw(){
 cam.feed();
 //camera(500,1000,500,0,0,0,0,0,1);
 drawAxes();

}
 
void mouseClicked() {
 float[] up = cam.up();
 println("Up X: " + up[0]);
 println("Up Y: " + up[1]);
 println("Up Z: " + up[2]);
}

void drawAxes(){
 //origin
 noStroke();
 fill(200,0,0);
 sphere(10);
 
 strokeWeight(10);
 //x axis
 color myred = color(255,5,135);
 stroke(myred);
 line(0, 0, 0, 500, 0, 0);
 //y axis
 color mygreen = color(171,255,6);
 stroke(mygreen);
 line(0, 0, 0, 0, 500, 0);
 //z axis
 color myblue = color(18,116,245);
 stroke(myblue);
 line(0, 0, 0, 0, 0, 500);
}


Re: OCD : cannot change the UP direction ?
Reply #1 - Apr 10th, 2010, 1:29am
 
this is a self-answer, since i figured out why this should happen, by reading the source code. this OCD always assume the up-down direction as Y direction. we cannot change this state by the lines below in this library.

Code:
// Describe the new vector between the camera and the target
     theDeltaX = theCameraX - theTargetX;
     theDeltaY = theCameraY - theTargetY;
     theDeltaZ = theCameraZ - theTargetZ;

     // Calculate the new "up" vector for the camera
     theUpX = -theDeltaX * theDeltaY;
     theUpY =  theDeltaZ * theDeltaZ + theDeltaX * theDeltaX;
     theUpZ = -theDeltaZ * theDeltaY;


this way always calculates the upward vector for the camera with assuming the initial upward is Y... probably, this is not an issue as long as we set the upward as Y. But for architects like me, we prefer Z to Y as the upward...

in that case, it might be a bit confusing to include the upward direction within constructors as an argument from a beginner's point of view...

anyway, thanks for a handy library!
Page Index Toggle Pages: 1