Horde3D
http://horde3d.org/forums/

rotate overlay
http://horde3d.org/forums/viewtopic.php?f=2&t=489
Page 1 of 1

Author:  jimbo [ 04.09.2008, 08:15 ]
Post subject:  rotate overlay

I'd like to rotate an overlay (its a compass), how can I do that?

Author:  Volker [ 04.09.2008, 09:02 ]
Post subject:  Re: rotate overlay

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.

Author:  jimbo [ 05.09.2008, 08:02 ]
Post subject:  Re: rotate overlay

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);

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/