Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4b2e1051d4e2c8d4f5b47c61aeaa4381a2f781c5 Stefan Goodchild committed Jun 4, 2010
Showing with 129 additions and 0 deletions.
  1. +19 −0 README
  2. +9 −0 Render.pde
  3. +78 −0 SphereCamera.pde
  4. +23 −0 SphereCameraClass.pde
19 README
@@ -0,0 +1,19 @@
+A 3d camera class for Processing to control an inward pointing camera with zenith and azimuth angles instead of cartesian coords.
+
+The movement is damped so you set the targets, not the actual angles like so...
+
+sCam.camAzimuthTarget = random(-85,85);
+sCam.camZenithTarget = random(0,360);
+sCam.camSphereRadiusTarget = random(400)+500;
+sCam.camTargTarget = random(1,10);
+
+And it will make it's way there.
+
+To slow down or speed up the movement you use the integer passed in to the drawCamera() method in the render loop. Lower numbers are faster.
+
+sCam.drawCamera(64);
+
+The targTarget is the cartesian coords of what the camera is pointing at but only accepts one number and adjusts X, Y and Z all at once which is a bit crap but I never really ever used it to do anything but slightly adjust the view so never got round to making it a full coord.
+
+The sCam.axis() method called in the render loop will draw an XYZ axis at 0,0,0 cartesian to give you a starting point.
+
9 Render.pde
@@ -0,0 +1,9 @@
+void setupRender() {
+ size(800,600,OPENGL);
+}
+
+void render() {
+ background(0);
+ sCam.axis();
+ sCam.drawCamera(64);
+}
78 SphereCamera.pde
@@ -0,0 +1,78 @@
+public class SphereCamera {
+
+ float camSphereRadius = 1000;
+ boolean handheld = false; // Adds a perlin noise wobble to give a handheld feel
+
+ float camAzimuth = 0;
+ float camZenith = 0;
+
+ float camAzimuthTarget = 0;
+ float camZenithTarget = 0;
+ float camSphereRadiusTarget = 500;
+
+ float camTarg = 0;
+ float camTargTarget = 0;
+ float camTargX, camTargY, camTargZ;
+ float handNoiseX, handNoiseY, handNoiseZ;
+
+ float camXPos, camYPos, camZPos;
+
+ float noiseScale=0.004;
+
+ void drawCamera(int camSpeed) {
+ if (camAzimuthTarget > camAzimuth) {
+ camAzimuth = camAzimuth + ((radians(camAzimuthTarget) - camAzimuth) / camSpeed);
+ } else {
+ camAzimuth = camAzimuth - ((camAzimuth - radians(camAzimuthTarget)) / camSpeed);
+ }
+
+ if (camZenithTarget > camZenith) {
+ camZenith = camZenith + ((radians(camZenithTarget) - camZenith) / camSpeed);
+ } else {
+ camZenith = camZenith - ((camZenith - radians(camZenithTarget)) / camSpeed);
+ }
+
+ if (camSphereRadiusTarget > camSphereRadius) {
+ camSphereRadius = camSphereRadius + ((camSphereRadiusTarget - camSphereRadius) / camSpeed);
+ } else {
+ camSphereRadius = camSphereRadius - ((camSphereRadius - camSphereRadiusTarget) / camSpeed);
+ }
+
+ if (camTargTarget > camTarg) {
+ camTarg = camTarg + ((camTargTarget - camTarg) / camSpeed);
+ } else {
+ camTarg = camTarg - ((camTarg - camTargTarget) / camSpeed);
+ }
+
+ camXPos = camSphereRadius * (sin(camZenith) * cos(camAzimuth));
+ camYPos = camSphereRadius * (sin(camZenith) * sin(camAzimuth));
+ camZPos = camSphereRadius * (cos(camZenith));
+
+ if (handheld) {
+ float handNoiseX = noise((frameCount)*noiseScale)-.5;
+ float handNoiseY = noise((frameCount)*noiseScale, (frameCount)*noiseScale)-.5;
+ float handNoiseZ = noise((frameCount)*noiseScale, (frameCount)*noiseScale, (frameCount)*noiseScale)-.5;
+ camTargX = camTarg+handNoiseX*100;
+ camTargY = camTarg+handNoiseY*100;
+ camTargZ = camTarg+handNoiseZ*100;
+
+ }
+
+ camera( camXPos, camYPos, camZPos,
+ camTargX, camTargY, camTargZ,
+ 0.0, 1.0, 0.0
+ );
+ }
+
+ void axis() {
+ strokeWeight(3);
+ stroke(255,0,0);
+ line(-50,0,0,50,0,0);
+ stroke(0,255,0);
+ line(0,-50,0,0,50,0);
+ stroke(0,0,255);
+ line(0,0,-50,0,0,50);
+ }
+
+}
+
23 SphereCameraClass.pde
@@ -0,0 +1,23 @@
+import processing.opengl.*;
+
+SphereCamera sCam;
+
+void setup() {
+ setupRender();
+ sCam = new SphereCamera();
+}
+
+void draw() {
+ render();
+}
+
+void mousePressed() {
+ sCamPosition();
+}
+
+void sCamPosition() {
+ sCam.camAzimuthTarget = random(-85,85);
+ sCam.camZenithTarget = random(0,360);
+ sCam.camSphereRadiusTarget = random(400)+500;
+ sCam.camTargTarget = random(1,10);
+}

0 comments on commit 4b2e105

Please sign in to comment.
Something went wrong with that request. Please try again.