Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2D rotation problem

Status
Not open for further replies.

fugigoose

Programmer
Jun 20, 2001
241
US
I'm having problems with my 2d rotation script. Basically, it is supposed to rotate a list of objects around a central point (refered to by "this"). Here's the script, but it doesn't work properly, the points do not rotate about the center, they just sorta randomly fly around and distort in a perverted manner. This section of code is located in a for loop that goes through all the child objects and rotates each one about the parent object 'this':

Code:
//convert the angle to radians and switch the start axis
ang = (Math.PI/ 180) * (this.rotation + 90);

//get the relative coordinates on the object from the center
this.children[i].x = this.children[i].x - this.x;
this.children[i].y = -this.children[i].y + this.y;

//do calculation to procure new location
this.children[i].x = (Math.cos(ang) * this.children[i].x)-(Math.sin(ang) * this.children[i].y)
this.children[i].y = (Math.sin(ang) * this.children[i].x)+(Math.cos(ang) * this.children[i].y)

//convert back into normal coordinates
this.children[i].x += this.x;
this.children[i].y += this.y;

Thanks to anyone who can figure this out. I've gotten this to work before in director, and i basically copied the script and converted it to JS, but it still refuses to work correctly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top