|
Author |
Topic: Hacking Perspective (Read 1552 times) |
|
edwardgeorge
|
Hacking Perspective
« on: Jun 9th, 2003, 12:41pm » |
|
Just knocked this up, messy but works... Hacking perspective This generates a rectangle which from one angle looks to be flat but upon rotation is many blocks lying on different planes. simple mouse rotation based on mouseX, put mouse at left edge for 0degrees rotation and it should look like a flat rectangle. Code:void setup(){ size(520,350); background(255); camz=0; fill(255,0,0); depths=new int[10*20]; for(int i=0;i<10*20;i++){ depths[i]=(int)random(300); } smooth(); } float camz; int[] depths; void loop(){ translate(width/2,height/2,0); rotateY(radians(mouseX)); if(camz==0){ camz=camZ()-0.001; } for(int i=0;i<20;i++){ for(int ii=0;ii<10;ii++){ beginShape(POLYGON); int dp=depths[i*10+ii]; vertex(projX(i*10,dp),projY(ii*10,dp),-dp); vertex(projX(i*10+10,dp),projY(ii*10,dp),-dp); vertex(projX(i*10+10,dp),projY(ii*10+10,dp),-dp); vertex(projX(i*10,dp),projY(ii*10+10,dp),-dp); endShape(); } } } float camZ(){ float avs=(float)0; float num=(float)0; for(int i=10;i<(width/2)-10;i++){ float opp=screenX(i,0,-100)-(width/2); float ang=(i-opp)/100; float adj=opp/ang; avs+=adj; num++; } return avs/num; //println(avs/num); } float projX(int x,int z){ return x+((x/camz)*z); } float projY(int y,int z){ return y+((y/camz)*z); } |
| the camZ function retruns an approximate location of the camera in the Z plane, this allows us to draw lines to each point in space. It does this by performing trig. on points calculated by using screenX. The projX+projY functions take a point in 2d space (first argument) and extrapolates it into three dimensions along a line from the camera to a certain z position(second argument) Thus from the camera all object appear to be as if they are drawn at 0 on the z-axis whereas they are at random positions. Now working at mapping images to the rectangles. All the best,
|
Ed, Suppose, Nottingham, UK http://www.suppose.co.uk http://ed.suppose.co.uk
|
|
|
arielm
|
Re: Hacking Perspective
« Reply #1 on: Jun 9th, 2003, 3:52pm » |
|
nice concept!!! i was thinking of doing something similar with text sometime, but i had absolutly no idea how to start with... now the door is open!
|
Ariel Malka | www.chronotext.org
|
|
|
edwardgeorge
|
Re: Hacking Perspective
« Reply #2 on: Jun 9th, 2003, 5:26pm » |
|
i've only tried it with positive x+y co-ords it might fall over with negative coords so might need modifying - only slightly. but as I say i haven't tried it yet. Yeah, if you have all the points of the text for constructing with vertex's (the rectangles are mapped by each corner point) so it would work with points on typefaces. All the Best, Ed
|
Ed, Suppose, Nottingham, UK http://www.suppose.co.uk http://ed.suppose.co.uk
|
|
|
benelek
|
Re: Hacking Perspective
« Reply #3 on: Jun 11th, 2003, 4:05am » |
|
text could probably be done quite easily with texturing, but it would require you to break the text image up into smaller img files to be pieced back together in Processing.
|
|
|
|
|