JS newbie help with JSUI dial

Dan Nigrin's icon

I'm trying to hack some modifications to the built in jsui 3ddial, and my JS and orthogonal math are both not that great.

I would like to limit the range of the dial to just 270 degrees, like the built in Max dial object defaults to. I've manged to get the background sphere and foreground arc to draw the way I want them to be drawn, but I can't figure out how to get the arc outline to be right. Here's the relevant bit of code - can someone help? Please also see image:

[img]index.php?t=getfile&id=619&private=0[/img]

function draw()
{
    var theta;
    var width = box.rect[2] - box.rect[0];

    switch(vmode) {
    default: // 3d sphere
        with (sketch) {
            glenable("depth_test");            
            shapeslice(40,10);
            glcullface("back");        
            // wireframe on/off
            if (vwire) {    
                glpolygonmode("front","line");            
                glpolygonmode("back","line");            
            } else {
                glpolygonmode("front","fill");            
                glpolygonmode("back","fill");            
            }
            // erase background
            glclearcolor(vbrgb);
            glclear();    

            // fill bg sphere            
            glcolor(vrgb2);
            moveto(0,0,0);
            sphere(0.8,-45,225,0,90);                        
            // fill fg arc
            glclear("depth");            
            glcolor(vfrgb);
            sphere(0.8,-135-val*270,-135,0,90);                        
            // draw arc outline
            gldisable("depth_test");            
            glenable("line_smooth");            
            shapeslice(80,1);
            glcolor(0,0,0,1);
            framecircle(0.8,-135-val*270,-135);    
            glcolor(0,0,0,1);
            moveto(0,0);
            lineto(0,-0.8);
            moveto(0,0);
            theta = (0.75-val)*2*Math.PI;
            lineto(0.8*Math.cos(theta),0.8*Math.sin(theta));        
        }
    }
}