Sphere position error

edited July 2015 in Questions about Code

Hello,

I want to position a sphere on the edge of the window. However when I do that the drawn Sphere looks more like a ellipse than a sphere. Here is the code use to try. The commented out lines are things I tested with no different result. Only if I put the Sphere in the Middle of the window the drawn Sphere looks like a Sphere. Is this normal ?

`void setup () { //size(800, 600, OPENGL); size(800, 600, P3D); background(0); }

void draw() { pushMatrix(); { colorMode(HSB); // translate(width, -100, -1200); // translate(width/2, height/2, -1200); translate(0, 0, -900); stroke(255); noFill(); stroke(255); sphereDetail(10); sphere(400); }popMatrix(); }`

Answers

  • Here is the Code again sorry for the wrong format

    void setup () { //size(800, 600, OPENGL);P3D size(800, 600, P3D); background(0); } void draw() { pushMatrix(); { colorMode(HSB); // translate(width, -100, -1200); translate(0, 0, -900); // translate(width/2, height/2, -1200); stroke(255); noFill(); stroke(255); sphereDetail(10); sphere(400); }popMatrix(); }

  • Answer ✓

    Yes, this is normal. The "distortion" you are seeing is because the default 3D mode is perspective, not orthogonal. Look up ortho() in the reference is you'd like to know how to change this.

  • thanks TfGuy44. I still don't get it quite, but now I have moved the Sphere in the down left corner :) .. will try now to move it to the top right where I want it.

  • ok with ortho(0, width*4 , 0, height*4); translate(width*3, -height*2, -1200); the Sphere is in the top right corner .. but like I said I now I have to read about perspective and orthogonal .. to understand why this ortho and translate values work,

  • after I draw the sphere I use float fov = PI/3; float cameraZ = (height) / tan(fov/2.0); perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0); to continue draw the other elements.

    read https://processing.org/tutorials/p3d/

Sign In or Register to comment.