汽车仪表盘指针参考

转载自:  http://glslsandbox.com/e#43893.0




#ifdef GL_ES
precision mediump float;
#endif


#extension GL_OES_standard_derivatives : enable


uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;


struct Line {
vec2 a;
vec2 b;
};


Line lightLines[3];
Line wallLines[3];
vec2 rotate(vec2 v, float a) {
float s = sin(a);
float c = cos(a);
mat2 m = mat2(c, -s, s, c);
return m * v;
}


float lightDueTo(in vec2 pos, in float len,in float intensity) {
return (((atan((len-pos.x)/pos.y)+atan(pos.x/pos.y)))/pos.y)*intensity;
}


float light(in vec2 line1,in vec2 line2, in vec2 point,in float intensity) {
vec2 line2Translated = line2 - line1;
vec2 pointTranslated = point - line1;
float len = length(line2Translated);
float theta = atan(line2Translated.y,line2Translated.x);
vec2 pointTransformed = rotate(pointTranslated,theta);
return lightDueTo(pointTransformed,len,intensity);

}




bool get_line_intersection(vec2 p0, vec2 p1 , 
    vec2 p2, vec2 p3, out vec3 i)
{
    float s1_x, s1_y, s2_x, s2_y;
    s1_x = p1.x - p0.x;     s1_y = p1.y - p0.y;
    s2_x = p3.x - p2.x;     s2_y = p3.y - p2.y;


    float s, t;
    s = (-s1_y * (p0.x - p2.x) + s1_x * (p0.y - p2.y)) / (-s2_x * s1_y + s1_x * s2_y);
    t = ( s2_x * (p0.y - p2.y) - s2_y * (p0.x - p2.x)) / (-s2_x * s1_y + s1_x * s2_y);


    if (s >= 0. && s <= 1. && t >= 0. && t <= 1.)
    {
        // Collision detected
        i.x = p0.x + (t * s1_x);
        i.y = p0.y + (t * s1_y);
        return true;
    }


    return false; // No collision
}


void getLinesToUse(vec2 pos, vec2 lights, vec2 walls, out Line[100] newLights, out int newLightsLength) {

}


void main( void ) {
lightLines[0] = Line(vec2(-500.,-500.),vec2(500.,500.0));
lightLines[1] = Line(vec2(500.,-500.),vec2(-500.,500.0));


wallLines[0] = Line(vec2(-500.,-600.),vec2(500.,400.0));
wallLines[1] = Line(vec2(500.,-600.),vec2(-500.,400.0));
wallLines[2] = Line(vec2(0.,-100),vec2(500,-100));

vec2 position = (( gl_FragCoord.xy / resolution.xy )  )* 2000.0  - vec2(1000,1000);

float l =0.;
for(int n = 0; n < 3; n++) {
l+= light(lightLines[n].a,lightLines[n].b,position,(10.*sin(time)/3.14159)+3.14159);
}


gl_FragColor = vec4( l,l,l, 1 );


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值