FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 486 : modelX/Y/Z still having trouble in 0123
Last modified: 2008-12-29 17:06
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
FIXED -
Pr
i
ority:
P2
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
fry
Assigned To:
fry
Attachment
Type
Created
Size
Actions
Description
: Opened: 2007-01-18 18:36
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1169166086
found by gdunne, this seems to not be working:
// written in processing v123
import processing.opengl.*;
void setup(){
size(500,500,OPENGL);
noFill();
}
float cx, cy, cz;
float x,y,z;
// rotate vars
float ryoffset = radians(random(360));
float rzoffset = radians(random(360));
float rinc = 0;
float radius = 150;
void draw(){
background(0);
cx = width/2;
cy = height/2;
cz = 0;
pushMatrix();
{
// overall translation (center point)
translate(cx,cy,cz);
// drawing the center
ellipse(0,0,5,5);
// some offset rotation
rotateY(ryoffset);
rotateZ(rzoffset);
// and actual rotation movement
rotateX(rinc);
// offset from center
translate(0,radius,0);
stroke(255,0,0);
// the object
box(20,20,20);
// get the location of this particular matrix, assign it to x,y,z
x = modelX(0,0,0);
y = modelY(0,0,0);
z = modelZ(0,0,0);
}
popMatrix();
// increment the rotation for animation
rinc+=.02;
// draw a line from the center to the worldpace of the matrix
stroke(0,255,255);
line(cx,cy,cz,x,y,z);
// and draw a shape
pushMatrix();
translate(x,y,z);
box(20,20,20);
popMatrix();
}
Additional Comment
#1 From fry 2007-01-18 18:36
this is related to
bug #386
, which seemed to have fixed the problem, but
apparently not for all cases.
Additional Comment
#2 From gdunne 2007-01-21 17:13
I have recompiled a version of processing for myself to allow access to the
modelview matrix, from which I can get the worldspace location. You can do
the same by making forwardTransform and reverseTransform PUBLIC in
PGraphics3D.java, and grabbing .m03, m13, and m23 for x,y,z respectively.
[code]
// written in processing v0123
/**
modelX(), modelY(), modelZ() HACK
recompiled version of Processing 0123 with the following change in the build:
lines 87 and 88 in PGraphics3D.java currently are:
protected PMatrix forwardTransform;
protected PMatrix reverseTransform;
changed to:
public PMatrix forwardTransform;
public PMatrix reverseTransform;
-- without this change, you will receive the following error, and the
below code will not work
/tmp/build33151.tmp/Temporary_9542_3326.java:68:18:68:33:
Semantic Error: The field "forwardTransform" in type
"processing.core.PGraphics3D"
has protected access and is not accessible here.
*/
import processing.opengl.*;
import javax.media.opengl.*;
void setup(){
size(500,500,OPENGL);
noFill();
stroke(0,255,255);
}
float cx, cy, cz;
float x,y,z;
// rotate vars
float ryoffset = radians(random(360));
float rzoffset = radians(random(360));
float rinc = 0;
float radius = 150;
void draw(){
background(0);
// define center
cx = width/2;
cy = height/2;
cz = 0;
// grab the openGL obj
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
// push into a new matrix
pushMatrix();
// move to center of screen
// (GL space requires mult by 2)
translate(cx*2, cy*2, cz*2);
// draw center
ellipse(0,0,5,5);
// some offset rotation
rotateY(ryoffset);
rotateZ(rzoffset);
rotateX(rinc);
// radius
translate(0,radius*2,0);
// get world space
double modelview[] = new double[16];
gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, modelview, 0);
// get coords of current model matrix
float tx = pgl.forwardTransform.m03;
float ty = pgl.forwardTransform.m13;
float tz = pgl.forwardTransform.m23;
stroke(255,0,255);
// draw a shape in the current matrix
box(30,30,30);
// pop out of the matrix
popMatrix();
// get out of the GL object
pgl.endGL();
// push into a new matrix and translate to the models' worldspace
// draw a locator
pushMatrix();
stroke(255,0,0);
translate(tx, ty, tz);
line(-100,0,100,0);
line(0,-100,0,100);
line(0,0,-100,0,0,100);
popMatrix();
// draw a line from the center to the worldpace of the matrix
stroke(0,255,255);
line(cx,cy,cz,tx,ty,tz);
// increment the rotation for animation
rinc+=.04;
}
[/code]
Additional Comment
#3 From fry 2007-01-29 19:58
thanks for the additional info, i'll try to get things fixed soon.
Additional Comment
#4 From fry 2007-11-21 08:42
now fixed in rev 0135.
Additional Comment
#5 From MrFeinberg 2008-12-29 17:06
From the trunk of modelX:
float ox =
cameraInv.m00*ax + cameraInv.m01*ay +
cameraInv.m02*az + cameraInv.m03*aw;
float ow =
cameraInv.m30*ax + cameraInv.m31*ay +
cameraInv.m32*az + cameraInv.m33*aw;
Why is the camera being queried at all? The position (and indeed,
existence) of the camera shouldn't in any way affect the world transform, ya?