1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
void VGL_TesslatedSprite::Draw(){
if ((flags & VGL_VISIBLE)==0){
return;
}
Vector2 elm_size = Vector2(size.x/(float)tes_x,size.y/(float)tes_y);
Vector2 elm_pos,variable_elm_size,sprite_center;
Vector2 base_pos = (pos + size - Vector2(0,elm_size.y));
SubSprite sub;
VGL_Color CurrentColor;
sprite_center = pos + Vector2(size.x*0.5f,size.y*0.5f);
float tex_size_x = 1.0f / (float)tes_x;
float tex_size_y = 1.0f / (float)tes_y;
float cx,cy;
int k,l;
BIND(texid);
for (int i=0;i<tes_x*tes_y;i++){
cx = float(i%tes_x)/(float)tes_x;
cy = float(i/tes_y)/(float)tes_y;
k = i%tes_x;
l = (int)::floor(i/(float)tes_y);
elm_pos = base_pos - Vector2((1-cx)*size.x,(cy)*size.y);
variable_elm_size = elm_size;
sub.t1.x = cx ; sub.t1.y = 1.0f - cy;
sub.t2.x = cx+tex_size_x ; sub.t2.y = 1.0f - cy;
sub.t3.x = cx+tex_size_x ; sub.t3.y = 1.0f - (cy+tex_size_y);
sub.t4.x = cx ; sub.t4.y = 1.0f - (cy+tex_size_y);
glBegin(GL_QUADS);
float d = distance2d(Vector2(elm_pos.x ,elm_pos.y+variable_elm_size.y ),pLightSource->GetPos());
float Alpha = 1 / (Kc + Kl*d + Kq*(d*d));
Alpha = clamp<float>(Alpha,0,1);
CDebug::GetSingleton()->Add("1- Kc = %f, Kl*d= %f, Kq*d²= %f, Alpha= %f, distance= %f",Kc, Kl*d, Kq*(d*d), Alpha, d);
CurrentColor.Combine(pLightSource->Ambiante,pLightSource->Light, Alpha * pLightSource->GetIntensity());
glColor4f(CurrentColor.r,CurrentColor.g, CurrentColor.b, CurrentColor.alpha);
glTexCoord2f(sub.t1.x, sub.t1.y);
glVertex2f(elm_pos.x, elm_pos.y+variable_elm_size.y ); // Vertex Coord (Bottom Left)
d = distance2d(Vector2(elm_pos.x + variable_elm_size.x , elm_pos.y+elm_size.y),pLightSource->GetPos());
Alpha = 1 / (Kc + Kl*d + Kq*(d*d));
Alpha = clamp<float>(Alpha,0,1);
CDebug::GetSingleton()->Add("2- Kc = %f, Kl*d= %f, Kq*d²= %f, Alpha= %f, distance= %f",Kc, Kl*d, Kq*(d*d), Alpha, d);
CurrentColor.Combine(pLightSource->Ambiante,pLightSource->Light, Alpha * pLightSource->GetIntensity());
glColor4f(CurrentColor.r,CurrentColor.g, CurrentColor.b, CurrentColor.alpha);
glTexCoord2f(sub.t2.x, sub.t2.y);
glVertex2f(elm_pos.x + variable_elm_size.x, elm_pos.y+elm_size.y ); // Vertex Coord (Bottom Right)
d = distance2d(Vector2(elm_pos.x + variable_elm_size.x ,elm_pos.y),pLightSource->GetPos());
Alpha = 1 / (Kc + Kl*d + Kq*(d*d));
Alpha = clamp<float>(Alpha,0,1);
CDebug::GetSingleton()->Add("3- Kc = %f, Kl*d= %f, Kq*d²= %f, Alpha= %f, distance= %f",Kc, Kl*d, Kq*(d*d), Alpha, d);
CurrentColor.Combine(pLightSource->Ambiante,pLightSource->Light, Alpha * pLightSource->GetIntensity());
glColor4f(CurrentColor.r,CurrentColor.g, CurrentColor.b, CurrentColor.alpha);
glTexCoord2f(sub.t3.x, sub.t3.y);
glVertex2f(elm_pos.x + variable_elm_size.x, elm_pos.y ); // Vertex Coord (Top Right)
d = distance2d(Vector2(elm_pos.x ,elm_pos.y),pLightSource->GetPos());
Alpha = 1 / (Kc + Kl*d + Kq*(d*d));
Alpha = clamp<float>(Alpha,0,1);
CDebug::GetSingleton()->Add("4- Kc = %f, Kl*d= %f, Kq*d²= %f, Alpha= %f, distance= %f",Kc, Kl*d, Kq*(d*d), Alpha, d);
CurrentColor.Combine(pLightSource->Ambiante,pLightSource->Light, Alpha * pLightSource->GetIntensity());
glColor4f(CurrentColor.r,CurrentColor.g, CurrentColor.b, CurrentColor.alpha);
glTexCoord2f(sub.t4.x, sub.t4.y );
glVertex2f(elm_pos.x, elm_pos.y );
glEnd();
/*glBegin(GL_LINES);
glColor3ub(255,255,255);
glVertex2f(elm_pos.x, elm_pos.y+variable_elm_size.y ); // Vertex Coord (Bottom Left)
glVertex2f(elm_pos.x + variable_elm_size.x, elm_pos.y+elm_size.y ); // Vertex Coord (Bottom Right)
glVertex2f(elm_pos.x, elm_pos.y ); // Vertex Coord (Top Right)
glVertex2f(elm_pos.x, elm_pos.y + elm_pos.y+elm_size.y);
glEnd();*/
glPointSize( 5 );
glBegin(GL_POINTS);
glVertex2f(pLightSource->GetPos().x, pLightSource->GetPos().y ); // Vertex Coord (Bottom Left)
glEnd();
}
} |
Partager