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 & HelpOpenGL and 3D Libraries › scale(x); cause problems.
Page Index Toggle Pages: 1
scale(x); cause problems. (Read 500 times)
scale(x); cause problems.
Mar 4th, 2009, 8:51pm
 

Hi, I am programming a space navigation motion with stars comming out from the center to the edges of the processing window and it's working ok, but when i want to add the scale function to have a best motion result the if conditional making to come back the star objects to the center when reach the edge seems stop working and all the star objects start to go away without coming back.

i hope i splained my self clear!,

any help will be appreciate,
thaks...
Re: scale(x); cause problems.
Reply #1 - Mar 5th, 2009, 3:02pm
 
It is quite difficult to help you without a piece of your code.

But I may give you some hints what could have gone wrong:

1.
Do you also use a translate(x, y) command to get your stars to the center? If so, it might just be a question of order: first translate, then scale, or the other way round.

2.
When using scale (or any of the other transformation commands: translate or rotation) the coordinates of your stars are not any more in the coordinate system of the canvas. That means, that checking wether the position of a star is beyond one of the borders of the canvas with width and height is not correct any more. It is quite probable, that your problem is of this kind.
Re: scale(x); cause problems.
Reply #2 - Mar 5th, 2009, 6:53pm
 
hi bohnacker, thanks for your reply!.

I have two objects in class one is Bowl which are just circles and the other object is Star.

the problem is that if I change the coordanates to 0,0 if I use translate then affects all the objects on the screen,

i just want to scale the stars in this case, but need to control every object behaviour separatly, so i can rotate the circles in class bowl for example and scale the stars.

code:

class Star{

 float xPos;
 float yPos;
 float zPos;
 float starSize;
 float xdirection=0.3;
 float ydirection=0.3;

 float sc=1;

 // constructor variables to create new objects with different values.
 Star(float x, float y,  float tstarSize){
   xPos = x;
   yPos = y;


   starSize = tstarSize;
 }
 void display(){
   sc+=0.01;
   fill(127,127,127);
   scale(sc);
   ellipse(xPos,yPos,starSize,starSize);

 }

 void move(){

   if(xPos<width/2 && yPos<height/2){
     xdirection = -0.3;
     ydirection = -0.3;

   }....
Re: scale(x); cause problems.
Reply #3 - Mar 6th, 2009, 9:27am
 
OK, I think I see the problem. Try putting pushMatrix() and popMatrix() around your scaling and drawing:

void display(){
 sc+=0.01;
 fill(127,127,127);
 pushMatrix();
 scale(sc);
 ellipse(xPos,yPos,starSize,starSize);
 popMatrix();
}

If you use one of the transformation commands like scale you're modifying the global transformation matrix. Therefore all your scaling adds up. With pushMatrix() you store the actual transformation matrix, do the scaling of the star, draw it and with popMatrix() you restore the previous matrix.

I think, this should work.
Re: scale(x); cause problems.
Reply #4 - Mar 6th, 2009, 9:47pm
 
got it working thanks to you !
had to add translate too at the top, now I can mix objects with 3d effects and objects only with 2d effects, wicked.
I take a note of your email, and will send you my final year project so you can have a look on what you contribute.

thanks for your help amigo !.



void display(){
    pushMatrix();
   
   translate(xPos,yPos);
 
   sc+=0.01;
   fill(127,127,127);
   
   scale(sc);
   ellipse(0,0,starSize,starSize);
   popMatrix();

 }
Re: scale(x); cause problems.
Reply #5 - Mar 7th, 2009, 12:36pm
 
Great. It would be nice to see what you're doing. I'm looking forward to it.
Page Index Toggle Pages: 1