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.
Page Index Toggle Pages: 1
camera position (Read 454 times)
camera position
Nov 30th, 2009, 12:02pm
 
hello,

i am new in processing.
i have a problem concerning my camera position. i want to circle it around my object by using the mouse or keyboard. i have a center point (x, y, z) and radius. and want the camera to recognize the past positions of my object.

here is my code:

import processing.opengl.*;

Essen e[] = new Essen[1];
Kacken k[] = new Kacken[1];
Schlafen s[] = new Schlafen[1];

color white = color(255, 255, 255, 80);
color red = color(255, 0, 0, 50);
color green = color(0, 255, 0, 50);
color blue = color(0, 0, 255, 50);
color back = color(95, 95, 95);



void setup () {
 size (700, 700, P3D);
 background (back);
 stroke (white);
 smooth();
 noLoop();

 for (int i=0; i < e.length; i++) {
   float x = random (250, 450);
   float y = random (250, 450);
   float z = random (250, 450);
   e[i] = new Essen (x, y, z);
 }

 for (int i=0; i < k.length; i++) {
   float x = random (250, 450);
   float y = random (250, 450);
   float z = random (250, 450);
   k[i] = new Kacken (x, y, z);
 }

 for (int i=0; i < s.length; i++) {
   float x = random (250, 450);
   float y = random (250, 450);
   float z = random (250, 450);
   s[i] = new Schlafen (x, y, z);
 }
}

void draw () {
 //background (back);
   smooth();
   

   
 for (int i=0; i < e.length; i++) {
   e[i].move ();
   point (e[i].position.x, e[i].position.y, e[i].position.z);

 }

 for (int i=0; i < k.length; i++) {
   k[i].move ();
   point (k[i].position.x, k[i].position.y, k[i].position.z);
 }

 for (int i=0; i < k.length; i++) {
   s[i].move ();
   point (s[i].position.x, s[i].position.y, s[i].position.z);
 }

 for (int i=0; i < e.length; i++) {
   e[i].move ();
   stroke(red);
   line(e[i].position.x, e[i].position.y, e[i].position.z, k[i].position.x, k[i].position.y, k[i].position.z);
   stroke(green);
   line(k[i].position.x, k[i].position.y, k[i].position.z, s[i].position.x, s[i].position.y, s[i].position.z);
   stroke(blue);
   line(s[i].position.x, s[i].position.y, s[i].position.z, e[i].position.x, e[i].position.y, e[i].position.z);
 }
}

void mousePressed() {
 loop();
}

TAG 1

class Essen {

 PVector position;
 PVector target;

 Essen (float theX, float theY, float theZ) {
   position = new PVector (theX, theY, theZ);
   target   = new PVector ();
   newTarget ();
 }

 void move () {
   PVector step = new PVector ();
   step.set (position);
   step.sub (target);
   step.div (40);
   position.sub (step);

   if (position.dist (target) < 3) {
     newTarget ();
   }
 }

 void newTarget () {
   target.x = random (250, 450);
   target.y = random (250, 450);
   target.z = random (250, 450);
 }
}

TAG 2

class Kacken {

 PVector position;
 PVector target;

 Kacken (float theX, float theY, float theZ) {
   position = new PVector (theX, theY, theZ);
   target   = new PVector ();
   newTarget ();
 }

 void move () {
   PVector step = new PVector ();
   step.set (position);
   step.sub (target);
   step.div (40);
   position.sub (step);

   if (position.dist (target) < 3) {
     newTarget ();
   }
 }

 void newTarget () {
   target.x = random (250, 450);
   target.y = random (250, 450);
   target.z = random (250, 450);
 }
}

TAG3

class Schlafen {

 PVector position;
 PVector target;

 Schlafen (float theX, float theY, float theZ) {
   position = new PVector (theX, theY, theZ);
   target   = new PVector ();
   newTarget ();
 }

 void move () {
   PVector step = new PVector ();
   step.set (position);
   step.sub (target);
   step.div (40);
   position.sub (step);

   if (position.dist (target) < 3) {
     newTarget ();
   }
 }

 void newTarget () {
   target.x = random (250, 450);
   target.y = random (250, 450);
   target.z = random (250, 450);
 }
}



thanks for your help



Re: camera position
Reply #1 - Nov 30th, 2009, 3:29pm
 
I suggest that you try the PeasyCam library

http://processing.org/reference/libraries/#3d
Re: camera position
Reply #2 - Nov 30th, 2009, 3:59pm
 
thank you.

as i wrote, i am new in processing.
so might you show me a possiblity to integrate this in my code please.



Page Index Toggle Pages: 1