Revision 550db260
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
---|---|---|
38 | 38 |
private final BandagedCreatorView mView; |
39 | 39 |
private final DistortedScreen mScreen; |
40 | 40 |
private final Static3D mScale; |
41 |
private final Static3D mMoveWhole; |
|
42 |
private final Static3D[] mMove; |
|
43 |
private final Static3D[] mMoveUnscaled; |
|
41 |
private final Static3D mMoveY; |
|
44 | 42 |
private final BandagedCubit[] mCubits; |
43 |
private float mScaleValue; |
|
45 | 44 |
|
46 | 45 |
static final int COLOR_DEFAULT = 0xffffff55; |
47 | 46 |
static final int COLOR_MARKED = 0xffff0000; |
... | ... | |
95 | 94 |
|
96 | 95 |
mScreen = new DistortedScreen(); |
97 | 96 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
98 |
mScale= new Static3D(1,1,1); |
|
99 |
mMoveWhole = new Static3D(0,0,0); |
|
100 |
|
|
101 |
int len = POSITIONS.length; |
|
102 |
mMove = new Static3D[len]; |
|
103 |
mMoveUnscaled = new Static3D[len]; |
|
104 |
|
|
105 |
for(int i=0; i<len; i++) |
|
106 |
{ |
|
107 |
mMove[i] = new Static3D(0,0,0); |
|
108 |
mMoveUnscaled[i] = new Static3D(0,0,0); |
|
109 |
} |
|
110 |
|
|
111 |
mCubits = createCubits(); |
|
97 |
mScale = new Static3D(1,1,1); |
|
98 |
mMoveY = new Static3D(0,0,0); |
|
99 |
mCubits= createCubits(); |
|
112 | 100 |
} |
113 | 101 |
|
114 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
120 | 108 |
|
121 | 109 |
for(int c=0; c<len; c++) |
122 | 110 |
{ |
123 |
computeMove(mMoveUnscaled[c],POSITIONS[c]); |
|
124 |
cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mMove[c],mMoveWhole,mScale, COLOR_DEFAULT); |
|
111 |
cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mMoveY,mScale,COLOR_DEFAULT); |
|
125 | 112 |
} |
126 | 113 |
|
127 | 114 |
return cubits; |
128 | 115 |
} |
129 | 116 |
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
|
|
132 |
private void computeMove(Static3D move, float[] position) |
|
133 |
{ |
|
134 |
int numCenters = position.length/3; |
|
135 |
float totalX=0.0f, totalY=0.0f, totalZ=0.0f; |
|
136 |
|
|
137 |
for(int center=0; center<numCenters; center++) |
|
138 |
{ |
|
139 |
totalX += position[3*center ]; |
|
140 |
totalY += position[3*center+1]; |
|
141 |
totalZ += position[3*center+2]; |
|
142 |
} |
|
143 |
|
|
144 |
totalX /= numCenters; |
|
145 |
totalY /= numCenters; |
|
146 |
totalZ /= numCenters; |
|
147 |
|
|
148 |
move.set(totalX,totalY,totalZ); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
public BandagedCubit[] getCubits() |
|
154 |
{ |
|
155 |
return mCubits; |
|
156 |
} |
|
157 |
|
|
158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 |
|
|
160 |
public DistortedScreen getScreen() |
|
161 |
{ |
|
162 |
return mScreen; |
|
163 |
} |
|
164 |
|
|
165 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
166 | 118 |
|
167 | 119 |
@Override |
... | ... | |
177 | 129 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
178 | 130 |
{ |
179 | 131 |
final float Q = SCREEN_RATIO/OBJECT_SIZE; |
180 |
float scale = width<height ? Q*width : Q*height;
|
|
132 |
mScaleValue = width<height ? Q*width : Q*height;
|
|
181 | 133 |
|
182 | 134 |
mScreen.detachAll(); |
183 | 135 |
int len = POSITIONS.length; |
184 | 136 |
|
185 | 137 |
for(int i=0; i<len; i++) |
186 | 138 |
{ |
187 |
float x = mMoveUnscaled[i].get0(); |
|
188 |
float y = mMoveUnscaled[i].get1(); |
|
189 |
float z = mMoveUnscaled[i].get2(); |
|
190 |
|
|
191 |
mMove[i].set(x*scale,y*scale,z*scale); |
|
192 |
|
|
139 |
mCubits[i].scaleMove(mScaleValue); |
|
193 | 140 |
mCubits[i].setTexture(COLOR_DEFAULT); |
194 | 141 |
DistortedNode node = mCubits[i].getNode(); |
195 | 142 |
mScreen.attach(node); |
... | ... | |
198 | 145 |
float RB = BandagedCreatorActivity.RATIO_BAR; |
199 | 146 |
float RS = BandagedCreatorActivity.RATIO_SCROLL; |
200 | 147 |
float yOffset = (0.5f*RB/(1-RS))*height; |
201 |
mMoveWhole.set1(yOffset);
|
|
148 |
mMoveY.set1(yOffset);
|
|
202 | 149 |
|
203 |
mScale.set( scale,scale,scale );
|
|
150 |
mScale.set( mScaleValue,mScaleValue,mScaleValue );
|
|
204 | 151 |
mScreenMin = Math.min(width, height); |
205 | 152 |
mView.setScreenSize(width,height, (int)yOffset); |
206 | 153 |
mScreen.resize(width,height); |
... | ... | |
220 | 167 |
{ |
221 | 168 |
android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() ); |
222 | 169 |
} |
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
public BandagedCubit[] getCubits() |
|
174 |
{ |
|
175 |
return mCubits; |
|
176 |
} |
|
177 |
|
|
178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 |
|
|
180 |
public DistortedScreen getScreen() |
|
181 |
{ |
|
182 |
return mScreen; |
|
183 |
} |
|
184 |
|
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
|
|
187 |
private boolean isAdjacent(float[] pos1, float[] pos2) |
|
188 |
{ |
|
189 |
int len1 = pos1.length/3; |
|
190 |
int len2 = pos2.length/3; |
|
191 |
|
|
192 |
for(int i=0; i<len1; i++) |
|
193 |
for(int j=0; j<len2; j++) |
|
194 |
{ |
|
195 |
float d0 = pos1[3*i ] - pos2[3*j ]; |
|
196 |
float d1 = pos1[3*i+1] - pos2[3*j+1]; |
|
197 |
float d2 = pos1[3*i+2] - pos2[3*j+2]; |
|
198 |
|
|
199 |
if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true; |
|
200 |
} |
|
201 |
|
|
202 |
return false; |
|
203 |
} |
|
204 |
|
|
205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
206 |
|
|
207 |
public void tryConnectingCubits(int index1, int index2) |
|
208 |
{ |
|
209 |
if( index1!=index2 ) |
|
210 |
{ |
|
211 |
float[] pos1 = mCubits[index1].getPosition(); |
|
212 |
float[] pos2 = mCubits[index2].getPosition(); |
|
213 |
|
|
214 |
if( isAdjacent(pos1,pos2) ) |
|
215 |
{ |
|
216 |
mCubits[index2].prepareJoin(pos1); |
|
217 |
|
|
218 |
mCubits[index1].detach(); |
|
219 |
DistortedNode node1 = mCubits[index1].getNode(); |
|
220 |
mScreen.detach(node1); |
|
221 |
DistortedNode node2 = mCubits[index2].getNode(); |
|
222 |
mScreen.detach(node2); |
|
223 |
mCubits[index2].swapNodes(mScaleValue); |
|
224 |
DistortedNode node3 = mCubits[index2].getNode(); |
|
225 |
mScreen.attach(node3); |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
223 | 229 |
} |
Also available in: Unified diff
Progress with BandagedCreator: joining cubits together. Still at least one (probably two) bugs here remain:
1) sometimes some of the walls of the newly creaed joined cubit are incorrectly rotated
2) there is an unpleasant flash when joining