| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.renderscript; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
@Deprecated |
| 28 |
public class Matrix3f { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public Matrix3f() { |
| 34 |
mMat = new float[9]; |
| 35 |
loadIdentity(); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public Matrix3f(float[] dataArray) { |
| 46 |
mMat = new float[9]; |
| 47 |
System.arraycopy(dataArray, 0, mMat, 0, mMat.length); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public float[] getArray() { |
| 57 |
return mMat; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public float get(int x, int y) { |
| 69 |
return mMat[x*3 + y]; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public void set(int x, int y, float v) { |
| 79 |
mMat[x*3 + y] = v; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public void loadIdentity() { |
| 86 |
mMat[0] = 1; |
| 87 |
mMat[1] = 0; |
| 88 |
mMat[2] = 0; |
| 89 |
|
| 90 |
mMat[3] = 0; |
| 91 |
mMat[4] = 1; |
| 92 |
mMat[5] = 0; |
| 93 |
|
| 94 |
mMat[6] = 0; |
| 95 |
mMat[7] = 0; |
| 96 |
mMat[8] = 1; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public void load(Matrix3f src) { |
| 105 |
System.arraycopy(src.getArray(), 0, mMat, 0, mMat.length); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public void loadRotate(float rot, float x, float y, float z) { |
| 118 |
float c, s; |
| 119 |
rot *= (float)(java.lang.Math.PI / 180.0f); |
| 120 |
c = (float)java.lang.Math.cos(rot); |
| 121 |
s = (float)java.lang.Math.sin(rot); |
| 122 |
|
| 123 |
float len = (float)java.lang.Math.sqrt(x*x + y*y + z*z); |
| 124 |
if (!(len != 1)) { |
| 125 |
float recipLen = 1.f / len; |
| 126 |
x *= recipLen; |
| 127 |
y *= recipLen; |
| 128 |
z *= recipLen; |
| 129 |
} |
| 130 |
float nc = 1.0f - c; |
| 131 |
float xy = x * y; |
| 132 |
float yz = y * z; |
| 133 |
float zx = z * x; |
| 134 |
float xs = x * s; |
| 135 |
float ys = y * s; |
| 136 |
float zs = z * s; |
| 137 |
mMat[0] = x*x*nc + c; |
| 138 |
mMat[3] = xy*nc - zs; |
| 139 |
mMat[6] = zx*nc + ys; |
| 140 |
mMat[1] = xy*nc + zs; |
| 141 |
mMat[4] = y*y*nc + c; |
| 142 |
mMat[7] = yz*nc - xs; |
| 143 |
mMat[2] = zx*nc - ys; |
| 144 |
mMat[5] = yz*nc + xs; |
| 145 |
mMat[8] = z*z*nc + c; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public void loadRotate(float rot) { |
| 154 |
loadIdentity(); |
| 155 |
float c, s; |
| 156 |
rot *= (float)(java.lang.Math.PI / 180.0f); |
| 157 |
c = (float)java.lang.Math.cos(rot); |
| 158 |
s = (float)java.lang.Math.sin(rot); |
| 159 |
mMat[0] = c; |
| 160 |
mMat[1] = -s; |
| 161 |
mMat[3] = s; |
| 162 |
mMat[4] = c; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public void loadScale(float x, float y) { |
| 172 |
loadIdentity(); |
| 173 |
mMat[0] = x; |
| 174 |
mMat[4] = y; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public void loadScale(float x, float y, float z) { |
| 185 |
loadIdentity(); |
| 186 |
mMat[0] = x; |
| 187 |
mMat[4] = y; |
| 188 |
mMat[8] = z; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
public void loadTranslate(float x, float y) { |
| 199 |
loadIdentity(); |
| 200 |
mMat[6] = x; |
| 201 |
mMat[7] = y; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public void loadMultiply(Matrix3f lhs, Matrix3f rhs) { |
| 212 |
for (int i=0 ; i<3 ; i++) { |
| 213 |
float ri0 = 0; |
| 214 |
float ri1 = 0; |
| 215 |
float ri2 = 0; |
| 216 |
for (int j=0 ; j<3 ; j++) { |
| 217 |
float rhs_ij = rhs.get(i,j); |
| 218 |
ri0 += lhs.get(j,0) * rhs_ij; |
| 219 |
ri1 += lhs.get(j,1) * rhs_ij; |
| 220 |
ri2 += lhs.get(j,2) * rhs_ij; |
| 221 |
} |
| 222 |
set(i,0, ri0); |
| 223 |
set(i,1, ri1); |
| 224 |
set(i,2, ri2); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public void multiply(Matrix3f rhs) { |
| 234 |
Matrix3f tmp = new Matrix3f(); |
| 235 |
tmp.loadMultiply(this, rhs); |
| 236 |
load(tmp); |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public void rotate(float rot, float x, float y, float z) { |
| 249 |
Matrix3f tmp = new Matrix3f(); |
| 250 |
tmp.loadRotate(rot, x, y, z); |
| 251 |
multiply(tmp); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
public void rotate(float rot) { |
| 261 |
Matrix3f tmp = new Matrix3f(); |
| 262 |
tmp.loadRotate(rot); |
| 263 |
multiply(tmp); |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
public void scale(float x, float y) { |
| 274 |
Matrix3f tmp = new Matrix3f(); |
| 275 |
tmp.loadScale(x, y); |
| 276 |
multiply(tmp); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
public void scale(float x, float y, float z) { |
| 288 |
Matrix3f tmp = new Matrix3f(); |
| 289 |
tmp.loadScale(x, y, z); |
| 290 |
multiply(tmp); |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
public void translate(float x, float y) { |
| 301 |
Matrix3f tmp = new Matrix3f(); |
| 302 |
tmp.loadTranslate(x, y); |
| 303 |
multiply(tmp); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public void transpose() { |
| 310 |
for(int i = 0; i < 2; ++i) { |
| 311 |
for(int j = i + 1; j < 3; ++j) { |
| 312 |
float temp = mMat[i*3 + j]; |
| 313 |
mMat[i*3 + j] = mMat[j*3 + i]; |
| 314 |
mMat[j*3 + i] = temp; |
| 315 |
} |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
final float[] mMat; |
| 320 |
} |
| 321 |
|
| 322 |
|