|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package javax.microedition.m3g; |
|
20 |
|
21 public class Transform |
|
22 { |
|
23 //------------------------------------------------------------------ |
|
24 // Static data |
|
25 //------------------------------------------------------------------ |
|
26 |
|
27 //------------------------------------------------------------------ |
|
28 // Instance data |
|
29 //------------------------------------------------------------------ |
|
30 |
|
31 // Check size from m3g_math.h Matrix |
|
32 byte[] matrix = new byte[72]; |
|
33 |
|
34 //------------------------------------------------------------------ |
|
35 // Constructor(s) |
|
36 //------------------------------------------------------------------ |
|
37 |
|
38 public Transform() |
|
39 { |
|
40 if (!Platform.uiThreadAvailable()) |
|
41 { |
|
42 throw new Error("UI thread not initialized"); |
|
43 } |
|
44 setIdentity(); |
|
45 } |
|
46 |
|
47 /** |
|
48 */ |
|
49 public Transform(Transform other) |
|
50 { |
|
51 if (!Platform.uiThreadAvailable()) |
|
52 { |
|
53 throw new Error("UI thread not initialized"); |
|
54 } |
|
55 set(other); |
|
56 } |
|
57 |
|
58 //------------------------------------------------------------------ |
|
59 // Public methods |
|
60 //------------------------------------------------------------------ |
|
61 |
|
62 public void setIdentity() |
|
63 { |
|
64 _setIdentity(matrix); |
|
65 } |
|
66 |
|
67 public void set(Transform transform) |
|
68 { |
|
69 System.arraycopy(transform.matrix, 0, |
|
70 this.matrix, 0, |
|
71 this.matrix.length); |
|
72 } |
|
73 |
|
74 public void set(float[] matrix) |
|
75 { |
|
76 _setMatrix(this.matrix, matrix); |
|
77 } |
|
78 |
|
79 public void get(float[] matrix) |
|
80 { |
|
81 _getMatrix(this.matrix, matrix); |
|
82 } |
|
83 |
|
84 public void invert() |
|
85 { |
|
86 _invert(matrix); |
|
87 } |
|
88 |
|
89 public void transpose() |
|
90 { |
|
91 _transpose(matrix); |
|
92 } |
|
93 |
|
94 public void postMultiply(Transform transform) |
|
95 { |
|
96 _mul(this.matrix, this.matrix, transform.matrix); |
|
97 } |
|
98 |
|
99 public void postScale(float sx, float sy, float sz) |
|
100 { |
|
101 _scale(matrix, sx, sy , sz); |
|
102 } |
|
103 |
|
104 /** |
|
105 */ |
|
106 public void postRotate(float angle, float ax, float ay, float az) |
|
107 { |
|
108 _rotate(matrix, angle, ax, ay, az); |
|
109 } |
|
110 |
|
111 /** |
|
112 */ |
|
113 public void postRotateQuat(float qx, float qy, float qz, float qw) |
|
114 { |
|
115 _rotateQuat(matrix, qx, qy, qz, qw); |
|
116 } |
|
117 |
|
118 /** |
|
119 */ |
|
120 public void postTranslate(float tx, float ty, float tz) |
|
121 { |
|
122 _translate(matrix, tx, ty, tz); |
|
123 } |
|
124 |
|
125 /** |
|
126 */ |
|
127 public void transform(float[] v) |
|
128 { |
|
129 if ((v.length % 4) != 0) |
|
130 { |
|
131 throw new IllegalArgumentException(); |
|
132 } |
|
133 |
|
134 if (v.length != 0) |
|
135 { |
|
136 _transformTable(matrix, v); |
|
137 } |
|
138 } |
|
139 |
|
140 /** |
|
141 */ |
|
142 public void transform(VertexArray in, float[] out, boolean W) |
|
143 { |
|
144 if (in == null || out == null) |
|
145 { |
|
146 throw new NullPointerException(); |
|
147 } |
|
148 |
|
149 _transformArray(matrix, in.handle, out, W); |
|
150 } |
|
151 |
|
152 //------------------------------------------------------------------ |
|
153 // Private methods |
|
154 //------------------------------------------------------------------ |
|
155 |
|
156 // Native methods |
|
157 private static native void _mul(byte[] prod, byte[] left, byte[] right); |
|
158 private static native void _setIdentity(byte[] matrix); |
|
159 private static native void _setMatrix(byte[] matrix, float[] srcMatrix); |
|
160 private static native void _getMatrix(byte[] matrix, float[] dstMatrix); |
|
161 private static native void _invert(byte[] matrix); |
|
162 private static native void _transpose(byte[] matrix); |
|
163 private static native void _rotate(byte[] matrix, float angle, float ax, float ay, float az); |
|
164 private static native void _rotateQuat(byte[] matrix, float qx, float qy, float qz, float qw); |
|
165 private static native void _scale(byte[] matrix, float sx, float sy, float sz); |
|
166 private static native void _translate(byte[] matrix, float tx, float ty, float tz); |
|
167 private static native void _transformTable(byte[] matrix, float[] v); |
|
168 private static native void _transformArray(byte[] matrix, int handle, float[] out, boolean W); |
|
169 } |