home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglw.zip / tensor.c < prev    next >
C/C++ Source or Header  |  1997-02-13  |  2KB  |  92 lines

  1. #include "vogl.h"
  2.  
  3. /*
  4.  *  premulttensor
  5.  *
  6.  *  Premultiply the tensor b by the matrix a and place the result
  7.  *  into the tensor c.
  8.  */
  9. void
  10. premulttensor(c, a, b)
  11.     Tensor    b, c;
  12.     Matrix    a;
  13. {
  14.     register    int    i, j, k;
  15.     float        x1, x2, x3, x4;
  16.  
  17.     for (i = 0; i < 4; i++)
  18.         for (j = 0; j < 4; j++) {
  19.             x1 = x2 = x3 = x4 = 0.0;
  20.             for (k = 0; k < 4; k++) {
  21.                 x1 += a[i][k] * b[0][k][j];
  22.                 x2 += a[i][k] * b[1][k][j];
  23.                 x3 += a[i][k] * b[2][k][j];
  24.                 x4 += a[i][k] * b[3][k][j];
  25.             }
  26.             c[0][i][j] = x1;
  27.             c[1][i][j] = x2;
  28.             c[2][i][j] = x3;
  29.             c[3][i][j] = x4;
  30.         }
  31. }
  32.  
  33. /*
  34.  *  multtensor
  35.  *
  36.  *  Multiply the tensor b by the matrix a and place the result
  37.  *  into the tensor c.
  38.  */
  39. void
  40. multtensor(c, a, b)
  41.     Tensor    b, c;
  42.     Matrix    a;
  43. {
  44.     register    int    i, j, k;
  45.     float        x1, x2, x3, x4;
  46.  
  47.     for (i = 0; i < 4; i++)
  48.         for (j = 0; j < 4; j++) {
  49.             x1 = x2 = x3 = x4 = 0.0;
  50.             for (k = 0; k < 4; k++) {
  51.                 x1 += b[0][i][k] * a[k][j];
  52.                 x2 += b[1][i][k] * a[k][j];
  53.                 x3 += b[2][i][k] * a[k][j];
  54.                 x4 += b[3][i][k] * a[k][j];
  55.             }
  56.             c[0][i][j] = x1;
  57.             c[1][i][j] = x2;
  58.             c[2][i][j] = x3;
  59.             c[3][i][j] = x4;
  60.         }
  61. }
  62.  
  63. /*
  64.  * Copy the tensor a into b.
  65.  */
  66. void
  67. copytensor(b, a)
  68.     Tensor    a, b;
  69. {
  70.     register    int    i, j, k;
  71.     
  72.     for (i = 0; i < 4; i++)
  73.         for (j = 0; j < 4; j++)
  74.             for (k = 0; k < 4; k++)
  75.                 b[i][j][k] = a[i][j][k];
  76. }
  77.  
  78. /*
  79.  * Copy the tensor a into b "transposed".
  80.  */
  81. void
  82. copytensortrans(b, a)
  83.     Tensor    a, b;
  84. {
  85.     register    int    i, j, k;
  86.  
  87.     for (i = 0; i < 4; i++)
  88.         for (j = 0; j < 4; j++)
  89.             for (k = 0; k < 4; k++)
  90.                 b[i][j][k] = a[i][k][j];
  91. }
  92.