Horde3D

Next-Generation Graphics Engine
It is currently 25.11.2024, 21:55

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: rotate overlay
PostPosted: 04.09.2008, 08:15 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
I'd like to rotate an overlay (its a compass), how can I do that?


Top
 Profile  
Reply with quote  
 Post subject: Re: rotate overlay
PostPosted: 04.09.2008, 09:02 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Rotate the overlay x and y coordinates. Just like you would do it, if you paint a rectangle and transform it with a 2D rotation matrix on the z-axis.


Top
 Profile  
Reply with quote  
 Post subject: Re: rotate overlay
PostPosted: 05.09.2008, 08:02 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
Thanks that works, here's some (semi-pseudo) code to rotate an overlay in the lower left corner:
Code:
#define DEG2RAD(x)  (((x)/180)*3.14159265)

typedef struct {
   float x,y;
} point;

point ll = {0.0, 0.0};
point lr = {0.1, 0.0};
point ur = {0.1, 0.1};
point ul = {0.0, 0.1};

point center;
center.x = (ll.x + lr.x) / 2.0;
center.y = (ll.x + ul.y) / 2.0;

float rot = DEG2RAD(45); // rotate 45 degrees

void rotate_2d(point &p) {
   float newx = (cos(rot) * (p.x - center.x)) + (sin(rot) * (p.y - center.y));
   float newy = (-sin(rot) * (p.x - center.x)) + (cos(rot) * (p.y - center.y));

   p.x = newx + center.x;
   p.y = newx + center.y;
}

rotate_2d(ll);
rotate_2d(lr);
rotate_2d(ur);
rotate_2d(ul);

Horde3D::showOverlay(ll.x, ll.y, 0, 0, lr.x, lr.y, 1, 0, ur.x, ur.y, 1, 1, ul.x, ul.y, 0, 1, 1, res);


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Bing [Bot] and 34 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group