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.
IndexProgramming Questions & HelpSyntax Questions › modelx/y/z equivalent for rotation
Page Index Toggle Pages: 1
modelx/y/z equivalent for rotation (Read 279 times)
modelx/y/z equivalent for rotation
Nov 26th, 2008, 10:47pm
 
Hey all,

I'm not exactly sure how to phrase this (which is probably why I haven't been able to find the answer elsewhere in the discourse), but I have a complex series of nested matrix transformations, each within several levels of push and pop matrixes. I'm able to use modelx/y/z to get the absolute location of the innermost transformation so I can aim a camera at it outside of the nested transformations.

However, I haven't hit on a way to position my camera to look at that point from the proper location. In other words, if I'm placing text on screen in the middle of these complex transformations, I know *where* to look, but not *from where* to look so I'm facing the front text instead of the back of it.

I hope that makes sense. Is there a way to figure that out?
Re: modelx/y/z equivalent for rotation
Reply #1 - Nov 26th, 2008, 11:40pm
 
// Simplified example:

import processing.opengl.*;
import damkjer.ocd.*;

PFont myFont;
Camera viewCamera;

void setup() {
 size(320, 240, OPENGL);

 myFont = createFont("Arial", 32);
 textFont(myFont);
 viewCamera = new Camera(this);
}

void draw() {
 float absX, absY, absZ;
 background(0);

 pushMatrix();
 translate(50,25);
 rotateY(radians(45));
 
 pushMatrix();
 translate(100,200,300);
 rotateY(radians(90));
 
 pushMatrix();
 translate(20,30,40);
 rotateY(radians(45));
 text("LOOK AT ME!", 0, 0);
 absX = modelX(0,0,0);
 absY = modelY(0,0,0);
 absZ = modelZ(0,0,0);
 popMatrix();
 
 popMatrix();
   
 popMatrix();
 
 // I know where to look thanks to modelx/y/z
 viewCamera.aim(absX, absY, absZ);
 // But how do I know where to look from?
 viewCamera.jump(absX, absY, absZ + 500); // This is the wrong side
 viewCamera.feed();
}

Re:modelx/y/z equivalent for rotation [SOLVED/BUG]
Reply #2 - Nov 27th, 2008, 10:57pm
 
Just for future reference, I figured out an obvious solution which is to set the camera eye location at the same time as the target (duh)! However, there seems to be a bug in 1.0 that makes everything freak out when you try to aim a camera and use modelx/y/z. At any rate, here's the code as I believe it *should* work and I've filed bug 1074.

// Simplified example:

import processing.opengl.*;
import damkjer.ocd.*;

PFont myFont;
Camera viewCamera;

void setup() {
 size(320, 240, OPENGL);

 myFont = createFont("Arial", 32);
 textFont(myFont);
 viewCamera = new Camera(this);
}

void draw() {
 float targetX, targetY, targetZ;
   float eyeX, eyeY, eyeZ;
 background(0);

 pushMatrix();
 translate(50,25);
 rotateY(radians(45));
 
 pushMatrix();
 translate(100,200,300);
 rotateY(radians(90));
 
 pushMatrix();
 translate(20,30,40);
 rotateY(radians(45));
 text("LOOK AT ME!", 0, 0);
 targetX = modelX(0,0,0);
 targetY = modelY(0,0,0);
 targetZ = modelZ(0,0,0);
 eyeX = modelX(0,0,500);
 eyeY = modelY(0,0,500);
 eyeZ = modelZ(0,0,500);
 popMatrix();
 
 popMatrix();
   
 popMatrix();
 
 // I know where to look thanks to modelx/y/z
 viewCamera.aim(targetX, targetY, targetZ);
 // And this is where I should look from, but processing hates it right now.
 viewCamera.jump(eyeX, eyeY, eyeZ);
 viewCamera.feed();
}
Page Index Toggle Pages: 1