We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to fix the coordinate system to match the tutorial.
http://learnopengl.com/img/getting-started/coordinate_systems.png
However by default the results are totally wrong. X axis points down and Y axis points right.
PVector cameraPosition;
float rotation;
void setup()
{
size (500, 500, P3D);
colorMode(RGB, 1); // a trick to color with 0f..1f
setCameraPosition(); // set the camera position
}
void draw()
{
background(0.1);
updateCamera();
updateExampleRotation();
drawAxis();
}
void setCameraPosition()
{
cameraPosition = new PVector();
cameraPosition.z = 100f;
}
void updateCamera()
{
float cx = cameraPosition.x;
float cy = cameraPosition.y;
float cz = cameraPosition.z;
camera(cx, cy, cz, 0, 0, 0, 0, 1, 0);
}
void updateExampleRotation()
{
// set the rotation
if (mousePressed && mouseButton == LEFT)
{
rotation = map(mouseX, 0, width, 0, TWO_PI);
println("Rotation " + rotation);
}
rotateY(rotation);
// set the height
if (mousePressed && mouseButton == RIGHT)
{
cameraPosition.y = map(mouseY, height, 0, 0, 50);
println("Height " + cameraPosition.y);
}
}
void drawAxis()
{
/* http://learnopengl.com/img/getting-started/coordinate_systems.png */
float a = 10;
// X right
stroke(1, 0, 0);
line(0, a, 0, 0, 0, 0);
// Y up
stroke(0, 1, 0);
line(0, 0, 0, a, 0, 0);
// Z forward
stroke(0, 0, 1);
line(0, 0, 0, 0, 0, a);
}
Answers
It's mangled the link to that web page but lines 60 and 64 look wrong to me. Try swapping them.
I tried it but it did not work.
For example in this case if you want to create a simple triangle, it will point down. The X coordinates of the triangle are -10 and 10, and the height will be 30.
Those x and y axes still look wrong in that code.
There's a page about processing coordinate system which explains that it's a bit odd, but I think that's just the 2d case. I thought 3d was better because it just uses opengl space.
If you draw a line in the Y direction and call the the X axis what do you expect. @koogs is right about the draw axis method, lines 32 and 36 need to be swapped.
In OpenGL the Y axis points up but Processing makes the decision that the Y axis should point down so that 2D coordinates behave the same in P2D and P3D.
If you want to match the OpenGL coordinate system you need to reverse the Y direction. Try this._ I have moved the triangle along the positive z axis for clarity_
OK after these corrections the example worked, however a problem that occurred was that the perspective was totally wrong, it looks like it's better to go fully 3D in that case.
I updated the code to support the 3D camera, also I did the hacking to get proper axis coordinates.
If it's any help, some relevant functions where Processing inverts the y axis from the standard OpenGL are frustum (a helper function to perspective) and ortho. And then there is camera itself. You could override Processing's version of these functions with your own, since each sketch you create is a child of PApplet. You have access to a majority of the properties in the sketch's graphics renderer through
PGraphicsOpenGL rndr = (PGraphicsOpenGL)g;
.The last post of this thread happened in March 2016. Over a year ago.
Why the hell are you replying to it now?