Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How do I rotate a rectangle with the four vertices


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Sam Sandeep   Members   -  Reputation: 123

Like
0Likes
Like

Posted 08 January 2013 - 03:57 AM

Hi,

 

Could anyone please help me out here?

 

I have the top left corner co ordinates of a rectangle.  And also the width and height.  Now, say, I want to rotate the rectangle 30 deg with the top left vertex as it s axis.  How do I calculate the four vertices.  

 

I'm trying to do this in opengl without using the glRotatef function, but for some reason the texture gets distorted with the rectangle rotates.

 

I'm currently using this logic.

 

 

 

currentTopLeftX = Vertices[ 0 ].x;
currentTopLeftY = Vertices[ 0 ].y;


currentTopRightX = Vertices[ 0 ].x + w*cos(angle*PI/180);
currentTopRightY = Vertices[ 0 ].y + w*sin(angle*PI/180);


currentBottomRightX = Vertices[ 0 ].x + w*cos(angle*PI/180) - h*sin(angle*PI/180);
currentBottomRightY = Vertices[ 0 ].y + w*sin(angle*PI/180) - h*cos(angle*PI/180);


currentBottomLeftX = Vertices[ 0 ].x + h*sin(angle*PI/180);
currentBottomLeftY = Vertices[ 0 ].y + h*cos(angle*PI/180);

 

 



Sponsor:

#2 PastelOgre   Members   -  Reputation: 140

Like
2Likes
Like

Posted 08 January 2013 - 05:15 AM

Equation for rotating a point around a center:
(x2,y2) = resulting rotated point
(x1,y1) = original point before rotation
(xc,yc) = center of rotation
x2 = xc+(x1-xc)*cos(angle)-(y1-yc)*sin(angle)
y2 = yc+(x1-xc)*sin(angle)+(y1-yc)*cos(angle)


#3 Sam Sandeep   Members   -  Reputation: 123

Like
0Likes
Like

Posted 08 January 2013 - 06:02 AM

Thank you so much... 

 

I'll try it out and let you know.. :D



#4 Sam Sandeep   Members   -  Reputation: 123

Like
0Likes
Like

Posted 08 January 2013 - 06:09 AM

Equation for rotating a point around a center:
(x2,y2) = resulting rotated point
(x1,y1) = original point before rotation
(xc,yc) = center of rotation
x2 = xc+(x1-xc)*cos(angle)-(y1-yc)*sin(angle)
y2 = yc+(x1-xc)*sin(angle)+(y1-yc)*cos(angle)

 

 

Wow awesome.. it works...  

 

Phew..  and it is so simple.. :|






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS