FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   CameraXYZ
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: CameraXYZ  (Read 2608 times)
skloopy

WWW
CameraXYZ
« on: Apr 1st, 2003, 12:56am »

Now that the camera is implemented, is there a way to get the current camera location or set it? I'm having a problem where i'm trying to calculate the facingRatio for some polys (to compensate for p5's non z-buffered lines) but i can't get the position of the camera. Thanks!
 
Also, is it possibe to get the world coordinates after a series or transformations? Say I was to rotate and then translate, how could i find out the XYZ coords of where i am?
« Last Edit: Apr 2nd, 2003, 1:18am by skloopy »  
fry


WWW
Re: CameraXYZ
« Reply #1 on: Apr 2nd, 2003, 3:09am »

this is the code that's used internally for the default camera: Code:
//these are the defaults:
 
fov = 60; // at least for now
eyeX = width / 2.0f;
eyeY = height / 2.0f;
eyeDist = eyeY / ((float) tan(PI * fov / 360f));
nearDist = eyeDist / 10.0f;
farDist = eyeDist * 10.0f;
aspect = (float)width / (float)height;
 
// default code for camera setup  
// put at beginning of loop()
beginCamera();
perspective(fov, aspect, nearDist, farDist);
lookat(eyeX, eyeY, eyeDist,  eyeX, eyeY, 0,  0, 1, 0);
endCamera();

by modifying parameters for eyeX, eyeY and eyeDist, you'll be able to control how the camera is working.
 
perspective and lookat work the same as their opengl equivalents.. check google for "opengl man pages" which is the documentation, and it'll have the nitty gritty details on how these work.  
 
examples would be most welcome, i haven't had a chance to code with this much yet to do fancier camera movement.
 
fry


WWW
Re: CameraXYZ
« Reply #2 on: Apr 2nd, 2003, 3:12am »

on Apr 1st, 2003, 12:56am, Ryan Alexander wrote:
Also, is it possibe to get the world coordinates after a series or transformations Say I was to rotate and then translate, how could i find out the XYZ coords of where i am

this is what objectX(), objectY() and objectZ() do, and it works like the screenX, screenY and screenZ functions. see the mention in revisions.txt.
 
skloopy

WWW
Re: CameraXYZ
« Reply #3 on: Apr 2nd, 2003, 8:40am »

Oops my bad on the objectX() and such. I tried it earlier and it didn't work how i thought but now it's cool.
 
Anyway I was trying to do this demo to test out the camera, but i'm still not exactly sure how the lookAt() command works. For example I was looking at the OpenGL docs and it seems like the lookAt there uses a Cam XYZ and a Obj XYZ for the point being looked at, so i'm still not sure how to get the camera to look at something, or translate the camera to postion XYZ.
 
Here's my demo code so far. I'm trying to get the camera to look at the box().
 
Code:
// Fun Fun Camera
// by Ryan Z Queseoff ScloopDogg Jonze
// http://elfman.vendetta.com/ryan
 
float fov, eyeX, eyeY, lookX, lookY, eyeDist, nearDist, farDist, aspect;
 
int frame = 1;
float crazy;
 
float interval = 200;
 
void setup()
{
  size(200,200);
   
  fov = 60;
  eyeX = 0;
  eyeY = 0;
  eyeDist = 100;
  nearDist = eyeDist / 10.0f;
  farDist = eyeDist * 10.0f;
  aspect = (float)width / (float)height;
}
 
void loop()
{
  beginCamera();
  perspective(fov, aspect, nearDist, farDist);
  //lookat(eyeX + sin(frame*.02f) * 40f,  
  //  eyeY + -100 + sin(frame*.01f) * 80f,  
  //  eyeDist + sin(frame*.01f) * 50f, lookX, lookY, 0, 0, 1, 0);
  lookat(eyeX,  
    eyeY + -100,  
    eyeDist, lookX, lookY, 0, 0, 1, 0);
  endCamera();
   
  push();
   
  // Draw on the XZ plane
  rotateX(HALF_PI);
   
  // Draw Smile
  stroke(128);
  noFill();
  smile();
   
  // Dot
  noStroke();
  fill(255*crazy,0,0);
  rect(crazy(47),crazy(-3),6,6);
   
  if (frame % interval == 0) {
    crazy = 1.0f;
  }
  fill(255);
  stroke(0);
   
  rotateZ((TWO_PI / interval) * frame);
  translate(50,0,0);
  box(15);
  lookX = objectX(0,0,0);
  lookY = objectY(0,0,0);
   
  pop();
   
  crazy *= .95f;
  frame++;
}
 
void smile()
{
  // Face
  beginShape(LINE_LOOP);
  for(int i=0; i<24; i++) {
    push();
    rotateY((TWO_PI / 24) * i);
    translate(random(-crazy*10,crazy*10),0,0);
    vertex(objectX(50,0,0),objectY(50,0,0));
    pop();
  }
  endShape();
   
  // Eyes
  line(crazy(-20),crazy(-25),crazy(-20),crazy(-5));
  line(crazy(20),crazy(-25),crazy(20),crazy(-5));
   
  // Mouth
  bezier(crazy(-35),crazy(5), crazy(-30),crazy(45), crazy(30),crazy(45), crazy(35),crazy(5));
}
 
float crazy(float n)
{
  return n + random(-crazy*10,crazy*10);
}

 
Maybe someone can help out with explaining the camera stuff. Sorry if this seems a little basic for all of you guys but i'm just used to a program like Maya where things are based on XYZ. Thanks!
 
Pages: 1 

« Previous topic | Next topic »