Annotation of researchv10no/cmd/view2d/term/camera.c, revision 1.1.1.1

1.1       root        1: #include       <CC/jerq.h>
                      2: #include       "frame.pri"
                      3: #include       "camera.pri"
                      4: #include       "clock.pub"
                      5: 
                      6: static Rectangle part(Rectangle, int, int);
                      7: int sprintf(...);
                      8: int latitude(int);
                      9: long vscale;
                     10: extern long vscale;
                     11: 
                     12: Texture32 blup = {
                     13: #include       "lup.icon"
                     14: }, bldown = {
                     15: #include       "ldown.icon"
                     16: }, brup = {
                     17: #include       "rup.icon"
                     18: }, brdown = {
                     19: #include       "rdown.icon"
                     20: }, a1 = {
                     21: #include       "b1.icon"
                     22: }, a2 = {
                     23: #include       "b2.icon"
                     24: }, a3 = {
                     25: #include       "b3.icon"
                     26: }, a4 = {
                     27: #include       "b4.icon"
                     28: };
                     29: 
                     30: Camera.Camera(Rectangle arena, Rectangle *leftover)
                     31: {
                     32:        Rectangle r;
                     33:        Point o;
                     34: 
                     35:        o = arena.o;
                     36:        obs = new Globepot(raddp(Rect(10, 10, 130, 130), o), 0,
                     37:                45, 45, Pt(160, 0));
                     38:        obs->help = "angle of camera from center of data";
                     39:        dist = new Rulepot(raddp(Rect(200, 70, 400, 90), o), P_HORIZ|P_TICKS, 300,
                     40:                Point(130, -25), Point(50, -25), "distance", 250);
                     41:        dist->help = "distance of camera from center of data";
                     42:        ospin = new Bmappot(raddp(Rect(530, 54, 562, 86), o), P_CIRC,
                     43:                Point(-25, -35), "SPIN TYPE");
                     44:        dist->help = "how the camera position changes over time";
                     45:        ospin->item(Point(21, -25), "none", &a1);
                     46:        ospin->item(Point(21, 11), "lat=c", &a2);
                     47:        ospin->item(Point(-75, 11), "long=c", &a3);
                     48:        ospin->item(Point(-75, -25), "circle", &a4);
                     49:        ospinr = new Rulepot(raddp(Rect(650, 10, 670, 130), o), P_VERT|P_TICKS, 60,
                     50:                Point(72, 60), Point(35, 40), "Spin Rate");
                     51:        ospinr->help = "degrees of spin per time interval";
                     52:        r = arena;
                     53:        r.o.y = o.y+142; r.c.y = o.y+150;
                     54:        rectf(&display, r, F_OR);
                     55:        r.o = add(o, Pt(324, 104));
                     56:        r.c = add(o, Pt(491, 150));
                     57:        string(&defont, "CAMERA POSITION", &display, add(o, Pt(340, 120)), F_OR);
                     58:        bord(&display, r, 8, F_OR);
                     59: 
                     60:        o.y += 150;
                     61:        cam = new Globepot(raddp(Rect(10, 10, 130, 130), o), 0,
                     62:                -45, 225, Pt(160, 0));
                     63:        cam->help = "direction of camera at center to the spot";
                     64:        aim = new Bmappot(raddp(Rect(190, 65, 220, 95), o), P_VERT,
                     65:                Point(-34, 40), "AUTO-CENTER", 1);
                     66:        aim->help = "keep camera aimed at the origin";
                     67:        aim->item(Point(2, -20), "OFF", &blup);
                     68:        aim->item(Point(0, 0), "", &bldown);
                     69:        perspective = new Bmappot(raddp(Rect(320, 65, 350, 95), o), P_VERT,
                     70:                Point(-35, 40), "PERSPECTIVE", 0);
                     71:        perspective->help = "render scaled or perspective";
                     72:        perspective->item(Point(2, -20), "OFF", &brup);
                     73:        perspective->item(Point(0, 0), "", &brdown);
                     74:        cspin = new Bmappot(raddp(Rect(530, 54, 562, 86), o), P_CIRC,
                     75:                Point(-25, -35), "SPIN TYPE");
                     76:        cspin->help = "motion of the camera aim";
                     77:        cspin->item(Point(21, -25), "none", &a1);
                     78:        cspin->item(Point(21, 11), "lat=c", &a2);
                     79:        cspin->item(Point(-75, 11), "long=c", &a3);
                     80:        cspin->item(Point(-75, -25), "circle", &a4);
                     81:        cspinr = new Rulepot(raddp(Rect(650, 10, 670, 130), o), P_VERT|P_TICKS, 60,
                     82:                Point(72, 60), Point(35, 40), "Spin Rate");
                     83:        cspinr->help = "degrees of spin per time interval";
                     84:        r = arena;
                     85:        r.o.y = o.y+142; r.c.y = o.y+150;
                     86:        rectf(&display, r, F_OR);
                     87:        r.o = add(o, Pt(404, 104));
                     88:        r.c = add(o, Pt(526, 150));
                     89:        string(&defont, "CAMERA AIM", &display, add(o, Pt(420, 120)), F_OR);
                     90:        bord(&display, r, 8, F_OR);
                     91: 
                     92:        o.y += 150;
                     93:        m->adv = new Bmappot(raddp(Rect(60, 40, 90, 70), o), P_VERT,
                     94:                Point(-43, 40), "FRAME ADVANCE", 1);
                     95:        m->adv->help = "advance frames while spinning";
                     96:        m->adv->item(Point(2, -20), "OFF", &brup);
                     97:        m->adv->item(Point(0, 0), "", &brdown);
                     98:        m->run = new Bmappot(raddp(Rect(160, 40, 190, 70), o), P_VERT,
                     99:                Point(2, 40), "RUN", 1);
                    100:        m->run->help = "run movie";
                    101:        m->run->item(Point(2, -20), "OFF", &blup);
                    102:        m->run->item(Point(0, 0), "", &bldown);
                    103:        clock->speed = new Rulepot(raddp(Rect(250, 50, 450, 70), o),
                    104:                P_HORIZ|P_TICKS, SPEED, Point(86, 35), Point(1, -25),
                    105:                "delay between frames", 5);
                    106:        clock->speed->help = "delay (in ticks) between frames";
                    107:        m->hide = new Bmappot(raddp(Rect(520, 40, 550, 70), o), P_VERT,
                    108:                Point(-52, 40), "HIDDEN SURFACES", 0);
                    109:        m->hide->help = "eliminate hidden lines";
                    110:        m->hide->item(Point(2, -20), "OFF", &blup);
                    111:        m->hide->item(Point(0, 0), "", &bldown);
                    112:        vertscale = new Rulepot(raddp(Rect(650, 10, 670, 90), o),
                    113:                P_VERT|P_TICKS, 100, Point(56, 60), Point(35, 40), "V Scale", 100);
                    114:        vertscale->help = "vertical scale";
                    115:        r = arena;
                    116:        r.o.y = o.y+112; r.c.y = o.y+120;
                    117:        rectf(&display, r, F_OR);
                    118:        drawpot();
                    119: 
                    120:        *leftover = arena;
                    121:        leftover->o.y = o.y+150;
                    122: }
                    123: 
                    124: void
                    125: Camera.adjust()
                    126: {
                    127:        if(aim->val)
                    128:                cam->setval(-obs->val, (180+obs->w)%360);
                    129:        clat = obs->val;
                    130:        clon = obs->w;
                    131:        cdist = dist->val;
                    132:        alat = cam->val;
                    133:        alon = cam->w;
                    134:        persp = perspective->val;
                    135:        vscale = muldiv(32768, vertscale->val, 100);
                    136: }
                    137: 
                    138: void
                    139: Camera.advance()
                    140: {
                    141:        int a, b;
                    142: 
                    143:        switch(ospin->val)
                    144:        {
                    145:        case 0:
                    146:        case 3:
                    147:                break;
                    148:        case 1:
                    149:                obs->setval(obs->val, (obs->w+ospinr->val)%360);
                    150:                break;
                    151:        case 2:
                    152:                b = obs->w;
                    153:                if(obs->front)
                    154:                {
                    155:                        if((a = obs->val+ospinr->val) > 90)
                    156:                        {
                    157:                                a = 180-a;
                    158:                                b = (b+180)%360;
                    159:                        }
                    160:                }
                    161:                else
                    162:                {
                    163:                        if((a = obs->val-ospinr->val) < -90)
                    164:                        {
                    165:                                a = -180-a;
                    166:                                b = (b+180)%360;
                    167:                        }
                    168:                }
                    169:                obs->setval(a, b);
                    170:                break;
                    171:        }
                    172:        switch(cspin->val)
                    173:        {
                    174:        case 0:
                    175:        case 3:
                    176:                break;
                    177:        case 1:
                    178:                cam->setval(cam->val, (cam->w+cspinr->val)%360);
                    179:                break;
                    180:        case 2:
                    181:                b = cam->w;
                    182:                if(cam->front)
                    183:                {
                    184:                        if((a = cam->val+cspinr->val) > 90)
                    185:                        {
                    186:                                a = 180-a;
                    187:                                b = (b+180)%360;
                    188:                        }
                    189:                }
                    190:                else
                    191:                {
                    192:                        if((a = cam->val-cspinr->val) < -90)
                    193:                        {
                    194:                                a = -180-a;
                    195:                                b = (b+180)%360;
                    196:                        }
                    197:                }
                    198:                cam->setval(a, b);
                    199:                break;
                    200:        }
                    201:        adjust();
                    202: }
                    203: 
                    204: static Rectangle
                    205: part(Rectangle r, int n, int i)
                    206: {
                    207:        int ox;
                    208: 
                    209:        ox = ((n-i)*r.o.x + i*r.c.x)/n;
                    210:        r.c.x = ((n-i-1)*r.o.x + (i+1)*r.c.x)/n;
                    211:        r.o.x = ox;
                    212:        return(r);
                    213: }
                    214: 
                    215: Hcoord
                    216: direct(short lat, short lon, short dist)
                    217: {
                    218:        Hcoord e(0, 0, muldiv(dist, isin(mkangle((lat+360)%360)), ONE), 1);
                    219:        register xx;
                    220:        
                    221:        xx = muldiv(dist, icos(mkangle((lat+360)%360)), ONE);
                    222:        e.x = muldiv(xx, icos(mkangle(lon)), ONE);
                    223:        e.y = muldiv(xx, isin(mkangle(lon)), ONE);
                    224:        return(e);
                    225: }
                    226: 
                    227: latitude(int lat)
                    228: {
                    229:        lat = (lat%360 + 360)%360;
                    230:        if(lat > 180)
                    231:                lat -= 360;
                    232:        return(lat);
                    233: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.