dcsegraves
YaBB Newbies
Offline
Posts: 2
Freaky Camera / Geometry Movement
Dec 9th , 2009, 8:36am
Here's a freaky one (this may be a question about libraries or 3D or OPENGL): In OPENGL I have imported 3ds geometry using the Mri3ds library. Great. I have built other 3D geometries inside Processing to go along with these imported geometries. Great. I have a lovely camera that works a lot like google earth. All works great. Camera orbiting and panning is lovely. Then- when I use perspective() simply to make the far clipping plane a little further away: The 3ds geometry and the Processing geometry orbit in different directions!! As in- when the camera orbits up to look at the top of the geometry made in processing, the 3ds geometries are moving in the opposite manner such that you end up looking at their bottom! It's a very freaky experience. Also freaky- I tried it on an older version (1.0.3) of Processing on a different computer- no problem. Any ideas? (in case this is related- the new version of processing that I've been using, 1.0.9, can never find the 'libraries' folder. I have to put all my libraries in a 'code' folder in each sketch. It also can't create web apps... who knows) The camera, if you're interested (I'm pretty proud of it ; ) // Perspective float fov = PI/3.0; float cameraZ = (height/2.0) / tan(fov/2.0); float clipfactor = 100; perspective( fov, float(width)/float(height), cameraZ/clipfactor, cameraZ*clipfactor); // Mouse control if(mousePressed) { if(mouseButton==LEFT){ TargetXVelocity -= (mouseX-pmouseX) * 4; TargetYVelocity -= (mouseY-pmouseY) * 4; } else if(mouseButton==RIGHT) { CamRVelocity += (mouseX-pmouseX) * .1; CamTVelocity += (mouseY-pmouseY) * .05; } } CameraRadius = CamZoom; TargetHeight = 100; //Camera rotation CamRotation += CamRVelocity; CamRVelocity *= .8; CamTilt += CamTVelocity; CamTVelocity *= .8; //restrict camera tilt if (CamTilt < -180) { CamTilt = -179.9; } else if (CamTilt > -90) { CamTilt = -90.1; } RotateAngle = radians(CamRotation); TiltAngle = radians(CamTilt); //Camera position TargetXVelocity *= .8; TargetYVelocity *= .8; TargetX += sin(RotateAngle-PI) * TargetXVelocity + cos(RotateAngle-PI) * TargetYVelocity; TargetY += cos(RotateAngle) * TargetXVelocity + sin(RotateAngle-PI) * TargetYVelocity; L = cos(TiltAngle) * CameraRadius; CameraX = cos(RotateAngle) * L + TargetX; CameraY = sin(RotateAngle) * L + TargetY; CameraZ = (sin(TiltAngle)) * CameraRadius - TargetHeight; camera(CameraX, CameraZ, CameraY, TargetX, -TargetHeight, TargetY, 0,1,0);