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 › 2D shifting of a 3D scene
Page Index Toggle Pages: 1
2D shifting of a 3D scene? (Read 577 times)
2D shifting of a 3D scene?
Apr 20th, 2008, 4:17pm
 
Hello,

How can I shift a 3D scene up/down or left/right on my screen, without changing the 3D perspective.
(Using the translate command changes this perspective.)
I just want to determine where on the 2D screen the 3D scene is drawn.

Any ideas?

Thanks!!
Re: 2D shifting of a 3D scene?
Reply #1 - Apr 20th, 2008, 5:38pm
 
Translate actually moves the whole coordinate space, so if you do translate(10,10,0) the origin (0,0,0) is now set at (10,10,0) and this is where objects will be drawn.  translate commands are cumulative so if you
translate(10,10,0);  
translate(2,5,0);
then your new origin will be at (12,15,0).  If you want to keep the "camera" in the same spot but change where an object is drawn you need to use pushMatrix and popMatrix commands.

if original origin is at (0,0,0)
pushMatrix(); //saves coordinate space (0,0,0)
translate(10,10,0);  // moves origin to x 10, y 10, z 0
box(5); //draws a box at (10,10,0)
popMatrix(); restores the original coord space (0,0,0)
box(5); // draw box at (0,0,0);

hope that helps.
Re: 2D shifting of a 3D scene?
Reply #2 - Apr 21st, 2008, 6:59am
 
hello sgrules,

thank you for your reply.
maybe i am missing something here.

if i draw a box at (10,0,0) - then then this box LOOKS different than the box i draw with box(0,0,0) - it is viewed from a different perspective. (the lines of the box are at different angles to each other as the box gets translated through space)

my question though is how to shift the box i draw with box(0,0,0) around on the screen without changing the box's perspective, in other words i want to shift the 3D scene that i have drawn around and place it at different points of my 2D screen without changing the way the objects in the 3D scene look.

any ideas?

thanks!
Re: 2D shifting of a 3D scene?
Reply #3 - Apr 21st, 2008, 4:18pm
 
The box looks different because perspective is applied to the scene. If you want to get rid of the perspective then you'll have to use an orthographic view.

use:

ortho(0, width, 0, height, -50, 50);

Keep in mind that when using an orthographic projection objects in the distance will not get any smaller since perspective is not applied.

heres a link for documentation on using ortho()
http://processing.org/reference/ortho_.html
Re: 2D shifting of a 3D scene?
Reply #4 - Apr 21st, 2008, 7:40pm
 
try frustum() as shown below (or use native opengl calls to alter the viewport, not shown)

Quote:


import processing.opengl.*;

void setup() {
 size(400,400,OPENGL);
}

void draw() {
 background(0);
 // center the viewing frustum on the mouse position
 float xofs = width/2f - mouseX;
 float yofs = mouseY - height/2f;
 frustum(-width/2f+xofs, width/2f+xofs, -height/2f+yofs, height/2f+yofs, (height/2f)/tan(PI/6f), 5000);
 // draw stuff...
 camera(0,0,500, 0,0,0, 0,1,0);
 lights();
 rotateX(radians(frameCount));
 rotateY(radians(frameCount*2));
 box(100);
}

Re: 2D shifting of a 3D scene?
Reply #5 - Apr 21st, 2008, 7:57pm
 
thank you very much davbol!!

works perfectly - just what i was looking for.

vou are dave bollinger i assume?
have seen your stuff on flickr - great images - keep it up!!

thanks again
michael
Re: 2D shifting of a 3D scene?
Reply #6 - Apr 21st, 2008, 8:57pm
 
ah... i misunderstood the problem, thankfully dave saves the day again Smiley
Page Index Toggle Pages: 1