Issue with angular gradient algorithm
Posted
by user146780
on Stack Overflow
See other posts from Stack Overflow
or by user146780
Published on 2010-06-10T00:39:20Z
Indexed on
2010/06/10
0:42 UTC
Read the original article
Hit count: 372
I have an angular gradient algorithm:
GLuint OGLENGINEFUNCTIONS::CreateAngularGradient( std::vector<ARGBCOLORF> &input,POINTFLOAT start, POINTFLOAT end, int width, int height )
{
std::vector<GLubyte> pdata(width * height * 4);
float pi = 3.1415;
float cx;
float cy;
float r1;
float r2;
float ang;
float px;
float py;
float t;
cx = start.x;
cy = start.y;
r1 = 0;
r2 = 500;
ang = end.x / 100;
ARGBCOLORF color;
for (unsigned int i = 0; i < height; i++) {
for (unsigned int j = 0; j < width; j++) {
px = j;
py = i;
if( px * px + py * py <= r2 * r2 && px * px + py * py >= r1 * r1 )
{
t= atan2(py-cy,px-cx) + ang;
t= t+ pi;
if (t > 2* pi)
{
t=t-2*pi;
t=t/(2*pi);
}
}
//end + start
color.r = (0 * t) + (120 * (1 - t));
color.g = (50 * t) + (255 * (1 - t));
color.b = (0 * t) + (50 * (1 - t));
color.a = (255 * t) + (200 * (1 - t));
pdata[i * 4 * width + j * 4 + 0] = (GLubyte) color.r;
pdata[i * 4 * width + j * 4 + 1] = (GLubyte) color.g;
pdata[i * 4 * width + j * 4 + 2] = (GLubyte) 12;
pdata[i * 4 * width + j * 4 + 3] = (GLubyte) 255;
}
}
It works fine except the ang variable only controls the end sweep, not the start sweep. The start sweep is always facing the middle left as seen here: http://img810.imageshack.us/img810/9623/uhoh.png
Basically I have no control over the end one going this <- way. How could I control this one?
Thanks
© Stack Overflow or respective owner