home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2611 / draw_image_xgl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  12.8 KB  |  558 lines

  1. #ifndef lint
  2. static    char    sccsid[] = "@(#)draw_image_xgl.c 1.2 92/05/28 SMI" ;
  3.     /* from draw_image_xgl.c 1.1 90/07/23 SMI */
  4. #endif
  5.  
  6. /*
  7.  * Copyright (c) 1986 by Sun Microsystems, Inc.
  8.  */
  9.  
  10. /*
  11.  * this file draws the image seen on the screen.  It is the top-level
  12.  * graphics routine
  13.  */
  14.  
  15.  
  16. #define    STAT_LEFT    200    /* x-posn of status lines */
  17. #define    LOCK_STAT_LEFT    400    /* x-posn of status lines */
  18.  
  19.  
  20. #include <stdio.h>
  21. #ifdef    XV
  22. #include <xview/window_hs.h>
  23. #else
  24. #include <sunwindow/window_hs.h>
  25. #endif
  26. #include <math.h>
  27. #include "graphics.h"
  28. #include "dstar.h"
  29.  
  30. extern    int    debug_level ;
  31.  
  32. #ifndef    XV
  33. extern    struct pixrect    dstar_pr ;
  34. #endif
  35.  
  36.     Xgl_trans    Idtrans = NULL ;
  37.     Xgl_bounds_f3d    Idwin = {0.,1.,0.,1.,0.,1.} ;
  38.     Xgl_bounds_f3d    Bigwin = {-2000.,2000.,-2000.,2000.,-2000.,2000.} ;
  39. static    Xgl_pt_f3d    cube1[] = { {-.5,-.5,-.5}, { .5,-.5,-.5},
  40.             { .5, .5,-.5}, {-.5, .5,-.5}, {-.5,-.5,-.5},
  41.             {-.5,-.5, .5}, { .5,-.5, .5}, { .5, .5, .5},
  42.             {-.5, .5, .5}, {-.5,-.5, .5}} ;
  43. static    Xgl_pt_f3d    cube2[] = {{ .5,-.5,-.5},{ .5,-.5,.5}} ;
  44. static    Xgl_pt_f3d    cube3[] = {{ .5, .5,-.5},{ .5, .5,.5}} ;
  45. static    Xgl_pt_f3d    cube4[] = {{-.5, .5,-.5},{-.5, .5,.5}} ;
  46. static    Xgl_pt_list    cube[4] ;
  47.  
  48. static    Xgl_pt_flag_f3d    decoration_pts[] = {
  49.      {-100.0, 0.0, 0.0, 0},        /* center */
  50.      { 100.0, 0.0, 0.0, 1},
  51.      {0.0, -100.0, 0.0, 0},
  52.      {0.0,  100.0, 0.0, 1},
  53.      {0.0, 0.0, -100.0, 0},
  54.      {0.0, 0.0,  100.0, 1},
  55.  
  56.      {900.0, -100.0, 0.0, 0},    /* X */
  57.      {1100.0,  100.0, 0.0, 1},
  58.      {900.0,  100.0, 0.0, 0},
  59.      {1100.0, -100.0, 0.0, 1},
  60.  
  61.      {-100.0, 1100.0, 0.0, 0},    /* Y */
  62.      {0.0, 1000.0, 0.0, 1},
  63.      {0.0, 900.0, 0.0, 1},
  64.      {100.0, 1100.0, 0.0, 0},
  65.      {0.0, 1000.0, 0.0, 1},
  66.  
  67.      {-100.0, 100.0, 1000.0, 0},    /* Z */
  68.      { 100.0, 100.0, 1000.0, 1},
  69.      {-100.0,-100.0, 1000.0, 1},
  70.      { 100.0,-100.0, 1000.0, 1}} ;
  71. static    Xgl_pt_list    decorations ;
  72.  
  73. static    Xgl_pt_flag_f3d    center_pts[] = {
  74.     { 0.45, 0.45, 0.0, 0}, { 0.55, 0.45, 0.0, 1},
  75.     { 0.55, 0.55, 0.0, 1}, { 0.45, 0.55, 0.0, 1},
  76.     { 0.45, 0.45, 0.0, 1},
  77.     { 0.45, 0.5, 0.0, 0}, { 0.47, 0.5, 0.0, 1},
  78.     { 0.53, 0.5, 0.0, 0}, { 0.55, 0.5, 0.0, 1},
  79.     { 0.5, 0.45, 0.0, 0}, { 0.5, 0.47, 0.0, 1},
  80.     { 0.5, 0.53, 0.0, 0}, { 0.5, 0.55, 0.0, 1}} ;
  81. static    Xgl_pt_list    center ;
  82.  
  83. static    Xgl_pt_f3d    laserbeam_pts[] = {
  84.       { 0.0, 0.0, 0.0}, { 0., 0., 0.0}, { 1.0, 0.0, 0.0}} ;
  85. static    Xgl_pt_list    laserbeam ;
  86.  
  87. static    Xgl_matrix_f3d    hsi_mat = {    /* viewport matrix for HSI */
  88.       {.1,0.,0.,0.},
  89.       {0.,.3,0.,0.},
  90.       {0.,0.,1.,0.},
  91.       {.15,.5,0.,1.}} ;
  92.  
  93. static    int    dbvalue = 2 ;
  94.  
  95. draw_image()
  96. {
  97.     int    i,j,k,iret ;
  98.     Mat3d    matrix, R_matrix ;
  99.     Pt3d    p, q ;
  100.     Pt3d    p1,p2,p3,p4,p5 ;
  101.     float    dx ;
  102.     Xgl_bounds_f2d    bounds ;
  103. static    Rect    onepix = {0,0,1,1} ;
  104.     Rect    full_rect ;
  105.     char    line[80] ;
  106. register Object    *object ;
  107.     int    color ;
  108.     Xgl_pt    offset ;
  109.     Xgl_pt_f3d    offset_p ;
  110. #ifdef XV
  111. static     Xgl_pt_f2d       radar_pos =  {0.05, 0.25} ,
  112.             armed_pos =  {0.05, 0.50} ,
  113.             remain_pos = {0.05, 0.75} ,
  114.             score_pos =  {0.05, 0.05} ,
  115.             lock_pos =  {0.75, 0.15} ;
  116.  
  117. /* Added score_text_npl - ds */
  118.     Xgl_color    text_color ;
  119. #else
  120. static    int        red_rop=0, yellow_rop, white_rop ;
  121. #endif XV
  122.  
  123.  
  124. #ifdef    DEBUG
  125.     if(debug_level  && missiles[0] != NULL  &&  missiles[0]->target != NULL)
  126.       object = missiles[0] ;
  127.     else
  128. #endif    DEBUG
  129.       object = Me ;
  130.  
  131.     /* set db control and clear back buffer */
  132.  
  133.     dbuf_control(Main_gfx, dbvalue) ;
  134.     xgl_object_get(Main_gfx, XGL_CTX_DC_VIEWPORT, &bounds) ;
  135.     full_rect.r_left = 0 ;
  136.     full_rect.r_top = 0 ;
  137.     full_rect.r_width = bounds.xmax - bounds.xmin ;
  138.     full_rect.r_height = bounds.ymax - bounds.ymin ;
  139. #ifndef    XV
  140.     if( red_rop == 0 ) {
  141.       red_rop = PIX_SRC | PIX_COLOR(dbmap[RED]) ;
  142.       yellow_rop = PIX_SRC | PIX_COLOR(dbmap[YELLOW]);
  143.       white_rop = PIX_SRC | PIX_COLOR(dbmap[WHITE]);
  144.     }
  145. #endif
  146.  
  147.     pw_lock(Main_pw, &full_rect ) ;
  148.     xgl_context_new_frame(Main_gfx) ;
  149.     pw_unlock(Main_pw) ;
  150.  
  151.     pw_lock(Main_pw, &onepix ) ;
  152.  
  153.     /* turn on all clipping except back, set 1:1 view transformation */
  154.  
  155.     Set_color(Main_gfx,WHITE) ;
  156.     xgl_object_set(Main_gfx, XGL_CTX_CLIP_PLANES, 0x3e, 0) ;
  157.  
  158.  
  159.     if( Idtrans == NULL ) {
  160.       Idtrans = xgl_transform_create(XGL_TRANS_DATA_TYPE, XGL_DATA_FLT,
  161.         XGL_TRANS_DIMENSION, XGL_TRANS_3D, 0) ;
  162.       xgl_transform_identity(Idtrans) ;
  163.     }
  164.  
  165.     /* build orientation matrix */
  166.  
  167.     ident_mat(R_matrix) ;
  168.     R_matrix[2][0] = object->Forward.x ;
  169.     R_matrix[2][1] = object->Forward.y ;
  170.     R_matrix[2][2] = object->Forward.z ;
  171.     R_matrix[1][0] = object->Up.x ;
  172.     R_matrix[1][1] = object->Up.y ;
  173.     R_matrix[1][2] = object->Up.z ;
  174.     R_matrix[0][0] = object->Right.x ;
  175.     R_matrix[0][1] = object->Right.y ;
  176.     R_matrix[0][2] = object->Right.z ;
  177.  
  178.     R_matrix[3][0] = object->Posn.x ;
  179.     R_matrix[3][1] = object->Posn.y ;
  180.     R_matrix[3][2] = object->Posn.z ;
  181.     /* OBJ_MAT = users (Me) position and orientation in World Space */
  182.     /* OBJ_MAT = ROTATION * TRANSLATION */
  183.     xgl_transform_write(OBJ_MAT, R_matrix) ;
  184.     R_matrix[3][0] = 0; R_matrix[3][1] = 0; R_matrix[3][2] = 0;
  185.  
  186.     xgl_transform_write(ROT_MAT, R_matrix) ;
  187.     xgl_transform_transpose(ROT_MAT, ROT_MAT) ;
  188.  
  189.     /* build perspective & windowing matrices, draw stars */
  190.  
  191.     xgl_transform_write(TM1, P_matrix) ;
  192.     xgl_transform_multiply(WIN_MAT, ROT_MAT, TM1) ;
  193.     xgl_object_set(Main_gfx, XGL_CTX_GLOBAL_MODEL_TRANS, WIN_MAT, 0) ;
  194.  
  195.     Set_color(Main_gfx,WHITE) ;
  196.     draw_starfield() ;
  197.  
  198.     /* build inverse to position matrix and multiply with ROT_MAT
  199.        to form xform mat for viewed objects */
  200.  
  201.     offset.pt_type = XGL_PT_F3D ;
  202.     offset.pt.f3d = &offset_p ;
  203.     offset_p.x = -object->Posn.x ;
  204.     offset_p.y = -object->Posn.y ;
  205.     offset_p.z = -object->Posn.z ;
  206.     xgl_transform_translate(TM1, &offset, XGL_TRANS_REPLACE) ;
  207.     xgl_transform_multiply(TM3, TM1, ROT_MAT) ;
  208.     xgl_transform_write(TM1, P_matrix) ;
  209.     xgl_transform_multiply(TM2, TM3, TM1) ;
  210.     window_mat(-1.0,1.0, -0.75,0.75, -1.0,1.0, matrix) ;
  211.     xgl_transform_write(TM1, matrix) ;
  212.     xgl_transform_multiply(WIN_MAT, TM2, TM1) ;
  213.  
  214.     /* draw test object */
  215.  
  216. #ifdef    COMMENT
  217.     draw_starfield() ;
  218. #endif    COMMENT
  219.  
  220.     decorations.pt_type = XGL_PT_FLAG_F3D ;
  221.     decorations.bbox = NULL ;    /* TODO */
  222.     decorations.num_pts =
  223.         (sizeof(decoration_pts)/sizeof(Xgl_pt_flag_f3d)) ;
  224.     decorations.pts.flag_f3d = decoration_pts ;
  225.     xgl_multipolyline(Main_gfx, NULL, 1, &decorations) ;
  226.  
  227.     /* draw enemy space ships and other objects */
  228.  
  229.     draw_objects() ;
  230.  
  231.  
  232.     /* set 1:1 view transformation */
  233.  
  234.     window_mat(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, matrix) ;
  235.     xgl_transform_write(WIN_MAT, matrix) ;
  236.  
  237.  
  238.     /* mark screen center */
  239.  
  240.     if( (Me->flags & RADAR_FLAG) == 0)
  241.     {
  242.       Set_color(Main_gfx,BLUE) ;
  243.     }
  244.     else if(Me->target == NULL)
  245.     {
  246.       Set_color(Main_gfx, YELLOW) ;
  247.     }
  248.     else
  249.     {
  250.       Set_color(Main_gfx, RED) ;
  251.     }
  252.     center.pt_type = XGL_PT_FLAG_F3D ;
  253.     center.bbox = NULL ;    /* TODO */
  254.     center.num_pts =
  255.         (sizeof(center_pts)/sizeof(Xgl_pt_flag_f3d)) ;
  256.     center.pts.flag_f3d = center_pts ;
  257.     xgl_multipolyline(Main_gfx, NULL, 1, ¢er) ;
  258.  
  259.     if(auto_pilot  ||  debug_level)
  260.     {
  261.       Mouse_ax = object->Delta.x * (1.0/VIEWSCALE) + .5 ;
  262.       Mouse_ay = object->Delta.y * (1.0/VIEWSCALE) + .5 ;
  263.       Mouse_x = Mouse_ax * full_rect.r_width ;
  264.       Mouse_y = (1.0 - Mouse_ay) * full_rect.r_height ;
  265.     }
  266.  
  267.     /* draw laser beams if appropriate */
  268.  
  269.     if(Me->flags & LASER_FLAG)
  270.     {
  271.       Set_color(Main_gfx,RED) ;
  272.       laserbeam_pts[1].x = Mouse_ax ;
  273.       laserbeam_pts[1].y = Mouse_ay ;
  274.       laserbeam.pt_type = XGL_PT_F3D ;
  275.       laserbeam.bbox = NULL ;    /* TODO */
  276.       laserbeam.num_pts = (sizeof(laserbeam_pts)/sizeof(Xgl_pt_f3d)) ;
  277.       laserbeam.pts.f3d = laserbeam_pts ;
  278.       xgl_multipolyline(Main_gfx, NULL, 1, &laserbeam) ;
  279.     }
  280.  
  281.  
  282.  
  283.     /* draw cursor if appropriate */
  284.  
  285.     if(auto_pilot  ||  debug_level)
  286.     {
  287. #ifndef    XV
  288.       pw_rop(Main_pw, Mouse_x-8, Mouse_y-8, 16, 16,
  289.         PIX_SRC | PIX_DST | PIX_COLOR(0xff), &dstar_pr, 0,0) ;
  290. #else
  291.       Xgl_pt_i2d    pos;
  292.       Xgl_color    rop_color ;
  293.       rop_color.index = dbmap[YELLOW] ;
  294.  
  295.       pos.x = Mouse_x-8;
  296.       pos.y = Mouse_y-8;
  297.       xgl_object_set(Main_gfx, XGL_CTX_SURF_FRONT_COLOR, &rop_color, 0) ;
  298.       xgl_context_copy_raster(Main_gfx, (Xgl_bounds_i2d *)NULL,
  299.         &pos, Cursor_ras);
  300. #endif    XV
  301.     }
  302.  
  303.  
  304.  
  305.     pw_unlock(Main_pw) ;
  306.  
  307.     /* control panel: set db control and clear back buffer */
  308.  
  309.     dbuf_control(Control_gfx, dbvalue) ;
  310. #ifndef    XV
  311.     xgl_context_new_frame(Control_gfx) ;
  312. #endif
  313.  
  314.     pw_lock(Control_pw, &onepix ) ;
  315.  
  316.  
  317.     xgl_transform_write(Ctrl_view_mat, hsi_mat) ;
  318.     draw_hsi(Control_gfx) ;
  319.  
  320.  
  321.     /* radar status */
  322.  
  323.     if( (Me->flags & RADAR_FLAG) != 0)
  324.     {
  325.       if( Me->target == NULL )
  326.       {
  327. #ifndef XV
  328.         pw_text(Control_pw, STAT_LEFT, 10, yellow_rop, NULL, "radar on") ;
  329. #else
  330.         text_color.index = dbmap[YELLOW] ;
  331.         xgl_object_set(Text_gfx, XGL_CTX_SFONT_TEXT_COLOR, &text_color, 0) ;
  332.         xgl_stroke_text(Text_gfx, "radar on", &radar_pos, NULL);
  333. #endif
  334.       }
  335.       else
  336.       {
  337.         register float dx,dy,dz ;
  338.  
  339.         dx = Me->target->Posn.x - Me->Posn.x ;
  340.         dy = Me->target->Posn.y - Me->Posn.y ;
  341.         dz = Me->target->Posn.z - Me->Posn.z ;
  342.         dx = sqrt(dx*dx+dy*dy+dz*dz) ;
  343.         sprintf(line, "radar locked, range =%7.1f %-20.20s",
  344.           dx, Me->target->name) ;
  345. #ifndef XV
  346.         pw_text(Control_pw, STAT_LEFT, 10, red_rop, NULL, line) ;
  347. #else
  348.         text_color.index = dbmap[RED] ;
  349.         xgl_object_set(Text_gfx, XGL_CTX_SFONT_TEXT_COLOR, &text_color, 0) ;
  350.         xgl_stroke_text(Text_gfx, line, &radar_pos, NULL);
  351. #endif
  352.       }
  353.     }
  354.  
  355.     /* score - added by dennis simpson */
  356.  
  357.     sprintf(line,"Score:    %d", Me->score);
  358. #ifndef    XV
  359.     pw_text(Control_pw, STAT_LEFT, 90, white_rop, NULL, line);
  360. #else
  361.     text_color.index = dbmap[WHITE] ;
  362.     xgl_object_set(Text_gfx, XGL_CTX_SFONT_TEXT_COLOR, &text_color, 0) ;
  363.     xgl_stroke_text(Text_gfx, line, &score_pos, NULL);
  364. #endif
  365.  
  366.     /* radar lock added by ds */
  367.  
  368.     {Object *ob;int i;
  369.     ob=&objects[0];
  370.     line[0] = '\0' ;
  371. #ifdef    XV
  372.     lock_pos.y = .75 ;
  373.     text_color.index = dbmap[YELLOW] ;
  374.     xgl_object_set(Text_gfx, XGL_CTX_SFONT_TEXT_COLOR, &text_color, 0) ;
  375.     for(i=0;i<MAX_OBJECTS && lock_pos.y >= 0.;i++)
  376. #else
  377.     j = 50 ;
  378.     for(i=0;i<MAX_OBJECTS && j <= 110;i++)
  379. #endif    XV
  380.     {
  381.         if(ob->class == OBJ_PLAYER &&
  382.             ob->status == OBJ_ACTIVE &&
  383.             ob->target == Me)
  384.         {
  385.             sprintf(line,"Locked by %s score: %d", ob->name,ob->score);
  386. #ifdef    XV
  387.             xgl_stroke_text(Text_gfx, line, &lock_pos, NULL) ;
  388.             lock_pos.y -= .15 ;
  389. #else
  390.             pw_text(Control_pw, LOCK_STAT_LEFT, j,
  391.             yellow_rop, NULL, line);
  392.             j += 20 ;
  393. #endif    XV
  394.         }
  395.         ob++;
  396.     }
  397.             
  398.  
  399.     /* missile armed */
  400.  
  401. #ifdef    XV
  402.     text_color.index = dbmap[WHITE] ;
  403.     xgl_object_set(Text_gfx, XGL_CTX_SFONT_TEXT_COLOR, &text_color, 0) ;
  404. #endif    /* XV */
  405.  
  406.     if( armed_missiles > 0 )
  407.     {
  408. #ifndef    XV
  409.       pw_text(Control_pw, STAT_LEFT, 30, white_rop, NULL, "missile armed") ;
  410. #else
  411.       xgl_stroke_text(Text_gfx, "missile armed", &armed_pos, NULL);
  412.     }
  413. #endif    XV
  414.     }
  415.  
  416.     /* missiles remaining */
  417.  
  418.     sprintf(line,"missiles remaining: %-2d",missiles_remaining) ;
  419. #ifndef    XV
  420.     pw_text(Control_pw, STAT_LEFT, 50, white_rop, NULL, line) ;
  421. #else
  422.     xgl_stroke_text(Text_gfx, line, &remain_pos, NULL);
  423. #endif    XV
  424.  
  425.     pw_unlock(Control_pw) ;
  426.  
  427.     dbuf_swap() ;
  428. }
  429.  
  430.  
  431.  
  432. set_line_color(ctx, i)
  433.     Xgl_3d_ctx    ctx ;
  434.     int        i ;
  435. {
  436.     Xgl_color    color ;
  437.  
  438.     color.index = dbmap[i] ;
  439.     xgl_object_set(ctx, XGL_CTX_LINE_COLOR, &color, 0) ;
  440. }
  441.  
  442.  
  443.  
  444. set_pgon_color(ctx, i)
  445.     Xgl_3d_ctx    ctx ;
  446.     int        i ;
  447. {
  448.     Xgl_color    color ;
  449.  
  450.     color.index = dbmap[i] ;
  451.     xgl_object_set(ctx, XGL_CTX_SURF_FRONT_COLOR, &color, 0) ;
  452. }
  453.  
  454.  
  455.  
  456. static    Mat3d    Identity = {{1.0,0.0,0.0,0.0},
  457.                 {0.0,1.0,0.0,0.0},
  458.                 {0.0,0.0,1.0,0.0},
  459.                 {0.0,0.0,0.0,1.0}} ;
  460.  
  461. static    Mat2d    Identity2 =  {{1.0,0.0},
  462.                   {0.0,1.0},
  463.                   {0.0,0.0}} ;
  464.  
  465.  
  466.  
  467.  
  468.  
  469. ident_mat(matrix)
  470.     Mat3d    matrix ;
  471. {
  472.     bcopy(Identity, matrix, sizeof(Mat3d)) ;
  473. }
  474.  
  475.  
  476. /*
  477.  *   viewplane model of perspective.  calling routine specifies the
  478.  *   z-coordinate from which the model is being viewed (ze) and the
  479.  *   z-coordinate of the viewing projection plane (zp, typically 0.0)
  480.  */
  481.  
  482. void
  483. persp(ze,zp,matrix)
  484.     float    ze,zp ;
  485.     Mat3d    matrix ;
  486. {
  487.     bcopy(Identity, matrix, sizeof(Mat3d)) ;
  488.  
  489.     if(ze!=zp)
  490.     {
  491.       matrix[2][3] = -1.0/(zp-ze) ;
  492.       matrix[3][3] = -ze * matrix[2][3] ;
  493.       matrix[2][2] = matrix[2][3] + matrix[3][3] ;
  494.     }
  495. }
  496.  
  497.  
  498. /*
  499.  * build a matrix that maps the region defined by [x0,y0,z0 x1,y1,z1]
  500.  * to the gp's viewport
  501.  */
  502.  
  503.  
  504. window_mat2(x0,x1,y0,y1,matrix)
  505.     float    x0,x1,y0,y1 ;
  506. register Mat2d    matrix ;
  507. {
  508.     bcopy(Identity2, matrix, sizeof(Mat2d)) ;
  509.  
  510.     matrix[0][0] = 2.0/(x1-x0) ;
  511.     matrix[1][1] = 2.0/(y1-y0) ;
  512.     matrix[2][0] = -1.0 - x0 * matrix[0][0] ;
  513.     matrix[2][1] = -1.0 - y0 * matrix[1][1] ;
  514. }
  515.  
  516.  
  517. window_mat(x0,x1,y0,y1,z0,z1,matrix)
  518.     float    x0,x1,y0,y1,z0,z1 ;
  519. register Mat3d    matrix ;
  520. {
  521.     bcopy(Identity, matrix, sizeof(Mat3d)) ;
  522.  
  523.     matrix[0][0] = 2.0/(x1-x0) ;
  524.     matrix[1][1] = 2.0/(y1-y0) ;
  525.     matrix[2][2] = 1.0/(z1-z0) ;
  526.     matrix[3][0] = -1.0 - x0 * matrix[0][0] ;
  527.     matrix[3][1] = -1.0 - y0 * matrix[1][1] ;
  528.     matrix[3][2] = - z0 * matrix[2][2] ;
  529. }
  530.  
  531.  
  532.  
  533.  
  534. persp_window_mat(ze,zp,x0,x1,y0,y1,z0,z1,matrix)
  535.     float    ze,zp,x0,x1,y0,y1,z0,z1 ;
  536. register Mat3d    matrix ;
  537. {
  538. register float        dist ;
  539.  
  540.     bcopy(Identity, matrix, sizeof(Mat3d)) ;
  541.  
  542.     dist = x1-x0 ;
  543.     matrix[0][0] = 2.0/dist ;
  544.     matrix[3][0] = -(x1+x0)*.5*matrix[0][0] ;
  545.  
  546.     dist = y1-y0 ;
  547.     matrix[1][1] = 2.0/dist ;
  548.     matrix[3][1] = -(y1+y0)*.5*matrix[1][1] ;
  549.  
  550.     dist = zp-ze ;
  551.     matrix[2][3] = 1.0/dist ;
  552.     matrix[3][3] = -ze * matrix[2][3] ;
  553.  
  554.     dist = z1-z0 ;
  555.     matrix[2][2] = (z1*matrix[2][3] + matrix[3][3]) / dist ;
  556.     matrix[3][2] = -z0 * matrix[2][2] ;
  557. }
  558.