|
Author |
Topic: Rotating an object about itself (Read 300 times) |
|
Ride215
|
Rotating an object about itself
« on: May 6th, 2004, 2:57am » |
|
Hey everyone, I am trying to rotate an object about itself instead of the origin, but for some reason it moves to the x position of 0 instead of staying where I initially put it. The y position seems to stay the same. Where is my flaw? Code: float rot = 0.0; int xPos = 150; int yPos = 150; int di = (int)sqrt(xPos*xPos + yPos*yPos); void setup(){ size(300,300); background(245); framerate(20); } void loop(){ background(245); ball(); rot += PI/48.0; xPos = (int) (di*(sin(rot))); yPos = (int) (di*(cos(rot))); } void ball(){ stroke(0); fill(9; rotate(rot); rect(xPos,yPos,30,70); }
|
|
|
|
narain
|
Re: Rotating an object about itself
« Reply #1 on: May 6th, 2004, 5:45am » |
|
Hmm... Why are you doing one rotation yourself (the di*sin(rot) etc) and one using rotate()? I have a feeling those might be cancelling out or something. This seems to work: Code:translate(xPos,yPos); rotate(rot); rect(0,0,30,70); |
| If you want it to rotate about its centre, you'll have to offset its corner using "rect(-15,-35, 30,70)".
|
|
|
|
narain
|
Re: Rotating an object about itself
« Reply #2 on: May 6th, 2004, 5:47am » |
|
I forgot to mention, the above code works after removing the reassignments of xPos and yPos in loop().
|
|
|
|
Ride215
|
Re: Rotating an object about itself
« Reply #3 on: May 6th, 2004, 5:51am » |
|
haha, wow, alright, that was so much simpler than I was making it now wasn't it.
|
|
|
|
|