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 › rotate around center || and why does it leave th..
Page Index Toggle Pages: 1
rotate around center || and why does it leave th.. (Read 1013 times)
rotate around center || and why does it leave th..
Apr 15th, 2009, 11:01am
 
I'm loading pixels from a webcam and I set them in a 3d space where the
red = x
green = y
blue = z axis, so basicly it should stay within a 255, 255, 255 area right?
For some reason it fills a bigger area, on the screen the setup size is 350, 350, P3D. As you can see it leaves the edges, how does this become?

...
(hsb goes even worse of the screen)

Also I want to rotate it from the center point, not the top corner, how can I do that?
Re: rotate around center || and why does it leave th..
Reply #1 - Apr 15th, 2009, 11:44am
 
maybe code helps...

Code:
import processing.video.*;

Capture cam;

String mode = "HSB";

void setup(){
size(350, 350, P3D);

cam = new Capture(this, 320, 240);
}


void draw() {
background(204);
if (cam.available() == true) {
cam.read();
//image(cam, 0, 0); //set(160, 100, cam);

translate(50, 50, 50);

for (int i = 0; i < cam.pixels.length; i++){
if (mode == "RGB"){
stroke(color(cam.pixels[i]));
point(red(cam.pixels[i]), green(cam.pixels[i]), blue(cam.pixels[i]));
}
else if(mode == "HSB"){
stroke(color(cam.pixels[i]));
point(hue(cam.pixels[i]), saturation(cam.pixels[i]), brightness(cam.pixels[i]));

}

}
}
if (frameCount % 15 == 0){
saveFrame();
}
}

Re: rotate around center || and why does it leave th..
Reply #2 - Apr 15th, 2009, 12:45pm
 
Dont know how its supposed to look like but looks good to me if i change the 50,50,50 to     translate(0, 0, -100);

Re: rotate around center || and why does it leave th..
Reply #3 - Apr 15th, 2009, 12:55pm
 
yeah that helps, thx dude

and for the rotation, someone?
Re: rotate around center || and why does it leave th..
Reply #4 - Apr 15th, 2009, 12:59pm
 
didnt see that. how do you want to rotate it. by mouse input? or just once within the sketch?
Re: rotate around center || and why does it leave th..
Reply #5 - Apr 15th, 2009, 1:19pm
 
I didn't expect you to want answer both Smiley

mouse input so I can move my mouse to rotate around the center of it.
Re: rotate around center || and why does it leave th..
Reply #6 - Apr 15th, 2009, 1:50pm
 
far away from perfect... but i added a rotation effekt...

maybe you get a better effect by using peasy cam:
http://mrfeinberg.com/peasycam/



Code:

import processing.video.*;
Capture cam;

String mode = "RGB";
float rx,ry;
void setup(){
size(350, 350, P3D);



cam = new Capture(this, 320, 240);
}


void draw() {
background(204);
translate( 0, 0, -100);


rx+=((width/2-mouseX)*0.01f-rx)*0.1f;
ry+=((height/2-mouseY)*0.01f-ry)*0.1f;
rotateY(rx);
rotateX(ry);



if (cam.available() == true) {
cam.read();
//image(cam, 0, 0); //set(160, 100, cam);


strokeWeight(3);
for (int i = 0; i < cam.pixels.length; i++){
if (mode == "RGB"){
stroke(color(cam.pixels[i]));
point(red(cam.pixels[i]), green(cam.pixels[i]), blue(cam.pixels[i]));
}
else if(mode == "HSB"){
stroke(color(cam.pixels[i]));
point(hue(cam.pixels[i]), saturation(cam.pixels[i]), brightness(cam.pixels[i]));

}

}
}
if (frameCount % 15 == 0){
saveFrame();
}
translate(width/2,height/2);
}
Re: rotate around center || and why does it leave th..
Reply #7 - Apr 15th, 2009, 2:16pm
 
your code rotates around left top of the color object, but thx anyway.

The peasy cam is nice maybe I look for implention later, if someone else can give a simpler solution a try then that would be nice.
Re: rotate around center || and why does it leave th..
Reply #8 - Apr 15th, 2009, 2:27pm
 
you are right... i guess you came up with this solution yourself Smiley
i will take another look at it later.
Re: rotate around center || and why does it leave th..
Reply #9 - Apr 15th, 2009, 2:41pm
 
To rotate around center, could you subtract 128 from each of your RGB values?
Re: rotate around center || and why does it leave th..
Reply #10 - Apr 15th, 2009, 2:52pm
 
Alright, here we go :

import processing.video.*;
Capture cam;

String mode = "RGB";
float rx,ry;

void setup(){

 size(350, 350, P3D);
rectMode(CENTER);
 noFill();

 cam = new Capture(this, 320, 240);
}


void draw() {
 background(204);


 pushMatrix();
 translate(width/2, height/2, 0);

 rotateX( radians(mouseY));
 rotateY( radians(mouseX));
 box(250);

translate( -125,   -125, -125);
 if (cam.available() == true) {
   cam.read();
   //image(cam, 0, 0); //set(160, 100, cam);

   
strokeWeight(3);
   for (int i = 0; i < cam.pixels.length; i++){
     if (mode == "RGB"){
       stroke(color(cam.pixels[i]));
       point(red(cam.pixels[i]), green(cam.pixels[i]), blue(cam.pixels[i]));
     }
     else if(mode == "HSB"){
       stroke(color(cam.pixels[i]));
       point(hue(cam.pixels[i]), saturation(cam.pixels[i]), brightness(cam.pixels[i]));
       
     }

   }
 }
 if (frameCount % 15 == 0){
    saveFrame();
 }

 popMatrix();
}

Re: rotate around center || and why does it leave th..
Reply #11 - Apr 15th, 2009, 2:55pm
 
yeah thx, that works great Smiley

for who's intrested, this works great for rotation then:

       rotateY(map(mouseX, 0, width, -PI, PI));
       rotateX(map(mouseY, 0, height, PI, -PI));

edit:

cederic, I saw your post after I posted, thx specially seing the box is helpfull.

edit2:

why is it getting so slow with another strokeweight then default?
Page Index Toggle Pages: 1