[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "math/transform.hh"
|
---|
| 10 |
|
---|
| 11 | i4_transform_class& i4_transform_class::multiply(const i4_transform_class &a, const i4_transform_class &b)
|
---|
| 12 | {
|
---|
| 13 | // expanded transform multiply
|
---|
| 14 | x.x = a.x.x*b.x.x + a.y.x*b.x.y + a.z.x*b.x.z;
|
---|
| 15 | x.y = a.x.y*b.x.x + a.y.y*b.x.y + a.z.y*b.x.z;
|
---|
| 16 | x.z = a.x.z*b.x.x + a.y.z*b.x.y + a.z.z*b.x.z;
|
---|
| 17 | y.x = a.x.x*b.y.x + a.y.x*b.y.y + a.z.x*b.y.z;
|
---|
| 18 | y.y = a.x.y*b.y.x + a.y.y*b.y.y + a.z.y*b.y.z;
|
---|
| 19 | y.z = a.x.z*b.y.x + a.y.z*b.y.y + a.z.z*b.y.z;
|
---|
| 20 | z.x = a.x.x*b.z.x + a.y.x*b.z.y + a.z.x*b.z.z;
|
---|
| 21 | z.y = a.x.y*b.z.x + a.y.y*b.z.y + a.z.y*b.z.z;
|
---|
| 22 | z.z = a.x.z*b.z.x + a.y.z*b.z.y + a.z.z*b.z.z;
|
---|
| 23 | t.x = a.x.x*b.t.x + a.y.x*b.t.y + a.z.x*b.t.z + a.t.x;
|
---|
| 24 | t.y = a.x.y*b.t.x + a.y.y*b.t.y + a.z.y*b.t.z + a.t.y;
|
---|
| 25 | t.z = a.x.z*b.t.x + a.y.z*b.t.y + a.z.z*b.t.z + a.t.z;
|
---|
| 26 | /*
|
---|
| 27 | _asm
|
---|
| 28 | {
|
---|
| 29 | mov eax,this
|
---|
| 30 | mov ecx,a
|
---|
| 31 | mov edx,b
|
---|
| 32 |
|
---|
| 33 | fld dword ptr [ecx+0]
|
---|
| 34 | fld st
|
---|
| 35 | fmul dword ptr [edx+0]
|
---|
| 36 | fld dword ptr [ecx+4]
|
---|
| 37 | fld st
|
---|
| 38 | fmul dword ptr [edx+0]
|
---|
| 39 | fld dword ptr [ecx+8]
|
---|
| 40 | fld st
|
---|
| 41 | fmul dword ptr [edx+0]
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | */
|
---|
| 45 | return *this;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | i4_transform_class& i4_transform_class::translate(const i4_3d_vector& offset)
|
---|
| 49 | {
|
---|
| 50 | x.set(i4_float(1),i4_float(0),i4_float(0));
|
---|
| 51 | y.set(i4_float(0),i4_float(1),i4_float(0));
|
---|
| 52 | z.set(i4_float(0),i4_float(0),i4_float(1));
|
---|
| 53 | t = offset;
|
---|
| 54 |
|
---|
| 55 | return *this;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | i4_transform_class& i4_transform_class::mult_translate(const i4_3d_vector& offset)
|
---|
| 60 | {
|
---|
| 61 | t.x += x.x*offset.x + y.x*offset.y + z.x*offset.z;
|
---|
| 62 | t.y += x.y*offset.x + y.y*offset.y + z.y*offset.z;
|
---|
| 63 | t.z += x.z*offset.x + y.z*offset.y + z.z*offset.z;
|
---|
| 64 |
|
---|
| 65 | return *this;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | i4_transform_class& i4_transform_class::rotate_z(i4_angle th)
|
---|
| 69 | {
|
---|
| 70 | i4_float cos_th=cos(th);
|
---|
| 71 | i4_float sin_th=sin(th);
|
---|
| 72 |
|
---|
| 73 | x.set( cos_th, sin_th, i4_float(0));
|
---|
| 74 | y.set( -sin_th, cos_th, i4_float(0));
|
---|
| 75 | z.set( i4_float(0), i4_float(0), i4_float(1));
|
---|
| 76 | t.set( i4_float(0), i4_float(0), i4_float(0));
|
---|
| 77 | return *this;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | i4_transform_class& i4_transform_class::mult_rotate_z(i4_angle th)
|
---|
| 81 | {
|
---|
| 82 | i4_float cos_th=cos(th);
|
---|
| 83 | i4_float sin_th=sin(th);
|
---|
| 84 | i4_float xx, xy, xz, yx, yy, yz;
|
---|
| 85 |
|
---|
| 86 | xx = y.x*sin_th + x.x*cos_th;
|
---|
| 87 | xy = y.y*sin_th + x.y*cos_th;
|
---|
| 88 | xz = y.z*sin_th + x.z*cos_th;
|
---|
| 89 | yx = y.x*cos_th - x.x*sin_th;
|
---|
| 90 | yy = y.y*cos_th - x.y*sin_th;
|
---|
| 91 | yz = y.z*cos_th - x.z*sin_th;
|
---|
| 92 |
|
---|
| 93 | x.set(xx,xy,xz);
|
---|
| 94 | y.set(yx,yy,yz);
|
---|
| 95 | return *this;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | i4_transform_class& i4_transform_class::rotate_y(i4_angle th)
|
---|
| 99 | {
|
---|
| 100 | i4_float cos_th=cos(th);
|
---|
| 101 | i4_float sin_th=sin(th);
|
---|
| 102 |
|
---|
| 103 | x.set( cos_th, i4_float(0), -sin_th );
|
---|
| 104 | y.set( i4_float(0), i4_float(1), i4_float(0) );
|
---|
| 105 | z.set( sin_th, i4_float(0), cos_th );
|
---|
| 106 | t.set( i4_float(0), i4_float(0), i4_float(0) );
|
---|
| 107 | return *this;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | i4_transform_class& i4_transform_class::mult_rotate_y(i4_angle th)
|
---|
| 112 | {
|
---|
| 113 | i4_float cos_th=cos(th);
|
---|
| 114 | i4_float sin_th=sin(th);
|
---|
| 115 | i4_float xx, xy, xz, zx, zy, zz;
|
---|
| 116 |
|
---|
| 117 | xx = x.x*cos_th - z.x*sin_th;
|
---|
| 118 | xy = x.y*cos_th - z.y*sin_th;
|
---|
| 119 | xz = x.z*cos_th - z.z*sin_th;
|
---|
| 120 | zx = x.x*sin_th + z.x*cos_th;
|
---|
| 121 | zy = x.y*sin_th + z.y*cos_th;
|
---|
| 122 | zz = x.z*sin_th + z.z*cos_th;
|
---|
| 123 |
|
---|
| 124 | x.set(xx,xy,xz);
|
---|
| 125 | z.set(zx,zy,zz);
|
---|
| 126 | return *this;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | i4_transform_class& i4_transform_class::rotate_x(i4_angle th)
|
---|
| 130 | {
|
---|
| 131 | i4_float cos_th=cos(th);
|
---|
| 132 | i4_float sin_th=sin(th);
|
---|
| 133 |
|
---|
| 134 | x.set( i4_float(1), i4_float(0), i4_float(0) );
|
---|
| 135 | y.set( i4_float(0), cos_th, sin_th );
|
---|
| 136 | z.set( i4_float(0), -sin_th, cos_th );
|
---|
| 137 | t.set( i4_float(0), i4_float(0), i4_float(0) );
|
---|
| 138 | return *this;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | i4_transform_class& i4_transform_class::mult_rotate_x(i4_angle th)
|
---|
| 142 | {
|
---|
| 143 | i4_float cos_th=cos(th);
|
---|
| 144 | i4_float sin_th=sin(th);
|
---|
| 145 | i4_float yx, yy, yz, zx, zy, zz;
|
---|
| 146 |
|
---|
| 147 | yx = z.x*sin_th + y.x*cos_th;
|
---|
| 148 | yy = z.y*sin_th + y.y*cos_th;
|
---|
| 149 | yz = z.z*sin_th + y.z*cos_th;
|
---|
| 150 | zx = z.x*cos_th - y.x*sin_th;
|
---|
| 151 | zy = z.y*cos_th - y.y*sin_th;
|
---|
| 152 | zz = z.z*cos_th - y.z*sin_th;
|
---|
| 153 |
|
---|
| 154 | y.set(yx,yy,yz);
|
---|
| 155 | z.set(zx,zy,zz);
|
---|
| 156 | return *this;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | i4_transform_class& i4_transform_class::scale(const i4_3d_vector& scale)
|
---|
| 160 | {
|
---|
| 161 | x.set( scale.x, i4_float(0), i4_float(0) );
|
---|
| 162 | y.set( i4_float(0), scale.y, i4_float(0) );
|
---|
| 163 | z.set( i4_float(0), i4_float(0), scale.z );
|
---|
| 164 | t.set( i4_float(0), i4_float(0), i4_float(0) );
|
---|
| 165 |
|
---|
| 166 | return *this;
|
---|
| 167 | }
|
---|