Bug 1296 : modelX(), modelY(), and modelZ() are broken by camera() function
Last modified: 2009-07-27 06:49




Status:
RESOLVED
Resolution:
DUPLICATE of bug 1074
Priority:
P2
Severity:
normal

 

Reporter:
Noah Z.
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-07-26 20:51
Processing 1.0.5
OS X 10.5.7(9J61) MacBook Pro 2.33 Radeon X1600-256

The Summary field says it all. I whipped up this example to illustrate. It isn't technically the
smallest possible piece of code, but it's the smallest that I could knock out quickly to
effectively illustrate the problem. This bug renders my VR engine completely useless in
Processing 1.0.x as I cannot easily pull complexly placed points (fingertips, for instance). BIG
problem. In this example, the two spheres should obviously be in the same place.

Example code:

import processing.opengl.*;

float zoom = 300;
float camVert = -15.0;
float camHoriz = 30.0;
float camDist = 200;
int camX = 0;
int camY = 0;
int camZ = 200;
boolean demoRotation = true;
boolean pressed = false;

void setup(){
size(1024,768,OPENGL);
}

void draw(){
background(#000000);
noFill();
camera(camX, camY, camZ, 0, 0, 0, 0.0, 1.0, 0.0);
pushMatrix();
drawGrid(150,15,0);
popMatrix();
pushMatrix();
translate(0,-20,0);
sphere(10);
println(modelX(0,0,0)+" "+modelY(0,0,0)+" "+modelZ(0,0,0));
float buggySphereX = modelX(0,0,0); float buggySphereY = modelY(0,0,0); float
buggySphereZ = modelZ(0,0,0);
popMatrix();
pushMatrix();
translate(buggySphereX, buggySphereY, buggySphereZ);
sphere(10);
popMatrix();
cameraPosition();
if(demoRotation){camHoriz+=1;}
}

void drawGrid(int gridSide, int gridSpacing, int gridY){
pushMatrix();
stroke(#00C000);
strokeWeight(1);
for(int zLine = -gridSide; zLine <= gridSide; zLine += gridSpacing){
line(gridSide,gridY,zLine,-gridSide,gridY,zLine);
}
for(int xLine = -gridSide; xLine <= gridSide; xLine += gridSpacing){
line(xLine,gridY,gridSide,xLine,gridY,-gridSide);
}
popMatrix();
}

void cameraPosition(){

camDist = cos(radians(abs(camVert)))*zoom;
camY = (int)(sin(radians(camVert))*zoom);
camX = (int)(cos(radians(camHoriz))*camDist);
camZ = (int)(sin(radians(camHoriz))*camDist);
}

void keyPressed(){
if (key == CODED) {
if (keyCode == UP) {
camVert += 1;
}
else if (keyCode == DOWN) {
camVert -= 1;
}
else if (keyCode == LEFT) {
camHoriz += 1;
}
else if (keyCode == RIGHT) {
camHoriz -= 1;
}
}
if (key == ' ') {
if(!pressed){
if(demoRotation){demoRotation = false;}
else{demoRotation = true;}
pressed = true;
}
}
if(key == ','){
zoom += 1;
}
if(key == '.'){
zoom -= 1;
}
}

void keyReleased(){
pressed = false;
}
Additional Comment #1 From fry 2009-07-27 06:49


*** This bug has been marked as a duplicate of 1074 ***