eukirne
YaBB Newbies
Offline
Posts: 2
Perspective, FOV and OPENGL
Mar 11th , 2009, 4:28pm
Hi, I have this piece of code to pan and rotate around a cube, and seems to be working perfectly in P3D, but when I try to run the sketch using OPENGL, the FOV doesn't reset when I reset the perspective. Could anybody help me with this? This is the code: //----------------------------------------------- import processing.opengl.*; float alpha1 = 10.594999; float alpha2 = 1.1074983; float alpha1_ = 0; float alpha2_ = 0; float distance = 0.4113693; int mouse_x, mouse_y; float translate1 = 0.6165447; float translate2 = 0.4113693; float translate3 = 3.977392; float fov = 0.5; void setup(){ size(1200,920,P3D); } void draw(){ //--------------- This should reset the settings camera(); perspective(); background(0); lights(); //--------------- After this, the box stays static box(50,50,50); //--------------- This rotates the scene camera(width/2.0 , height/2.0, distance *(height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, -1 * (height/2.0) / tan(PI*60.0 / 360.0), 0, 1, 0); perspective(fov, float(width)/float(height), distance *((height/2.0) / tan(PI*60.0/360.0))/10.0, ((height/2.0) / tan(PI*60.0/360.0))*10.0); translate(width/2,height/2); //scale(2.5); alpha2_ = alpha2 + sin(frameCount/130.0)*0.00008; alpha1_ = alpha1 + sin(frameCount/123.0)*0.00008; rotateX(alpha2_); rotateZ(alpha1_); translate(translate1,translate2,translate3); //----------------------------------------------------- After this, the cube rotates with the mouse box(50,50,50); } void mousePressed () { mouse_x = mouseX; mouse_y = mouseY; } void mouseDragged() { if (mouseButton == LEFT) { alpha1 +=(mouse_x - mouseX)/100.0; alpha2 +=(mouse_y - mouseY)/100.0; } if (mouseButton == RIGHT) { float msx = (mouse_x - mouseX); float msy = (mouse_y - mouseY)*cos(alpha2); float msz = (mouse_y - mouseY); translate1 -=( cos(alpha1)*msx + sin(alpha1)*msy)/2.50; translate2 -=( -sin(alpha1)*msx + cos(alpha1)*msy)/2.50; translate3 +=( sin(alpha2)*msz)/2.50; } if (mouseButton == CENTER) { fov = fov * (mouseY - mouse_y + width) / width ; }; mouse_x=mouseX; mouse_y=mouseY; }