Revision 950511ed
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.DistortedBitmap; |
30 | 30 |
import org.distorted.library.DistortedObject; |
31 | 31 |
import org.distorted.library.EffectTypes; |
32 |
import org.distorted.library.type.Dynamic3D; |
|
32 | 33 |
import org.distorted.library.type.DynamicQuat; |
33 | 34 |
import org.distorted.library.type.Static3D; |
34 | 35 |
import org.distorted.library.type.Static4D; |
... | ... | |
46 | 47 |
private GLSurfaceView mView; |
47 | 48 |
private DistortedObject mObject; |
48 | 49 |
private DistortedBitmap mBackground; |
50 |
private DistortedBitmap mCenter; |
|
49 | 51 |
private int mObjWidth, mObjHeight; |
50 | 52 |
private DynamicQuat mQuatInt1, mQuatInt2; |
53 |
|
|
54 |
private Dynamic3D mMoveInter; |
|
55 |
private Static3D mMovePoint; |
|
56 |
private float mFactorObj; |
|
57 |
|
|
51 | 58 |
Static4D mQuat1, mQuat2; |
52 | 59 |
int mScreenMin; |
53 | 60 |
|
61 |
|
|
54 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 63 |
|
56 | 64 |
public Vertex3DRenderer(GLSurfaceView v) |
... | ... | |
59 | 67 |
|
60 | 68 |
mObject = ((Vertex3DActivity)v.getContext()).getObject(); |
61 | 69 |
mBackground = new DistortedBitmap(100, 100, 1); |
70 |
mCenter = new DistortedBitmap(100, 100, 1); |
|
62 | 71 |
|
63 | 72 |
mObjWidth = mObject.getWidth(); |
64 | 73 |
mObjHeight= mObject.getHeight(); |
... | ... | |
71 | 80 |
|
72 | 81 |
mQuatInt1.add(mQuat1); |
73 | 82 |
mQuatInt2.add(mQuat2); |
83 |
|
|
84 |
mMovePoint= new Static3D(0,0,0); |
|
85 |
mMoveInter= new Dynamic3D(); |
|
86 |
mMoveInter.add(mMovePoint); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
public void setCenter(float x, float y) |
|
92 |
{ |
|
93 |
mMovePoint.set(mFactorObj*x,mFactorObj*y,0); |
|
74 | 94 |
} |
75 | 95 |
|
76 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
84 | 104 |
|
85 | 105 |
mBackground.draw(time); |
86 | 106 |
mObject.draw(time); |
107 |
mCenter.draw(time); |
|
87 | 108 |
} |
88 | 109 |
|
89 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
94 | 115 |
|
95 | 116 |
mObject.abortEffects(EffectTypes.MATRIX); |
96 | 117 |
mBackground.abortEffects(EffectTypes.MATRIX); |
97 |
float factorObj; |
|
118 |
mCenter.abortEffects(EffectTypes.MATRIX); |
|
119 |
|
|
120 |
float factorCen; |
|
121 |
int centerSize = mCenter.getWidth(); |
|
98 | 122 |
|
99 | 123 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
100 | 124 |
{ |
101 |
factorObj = (0.80f*height)/mObjHeight; |
|
125 |
mFactorObj = (0.80f*height)/mObjHeight; |
|
126 |
factorCen = (0.08f*height)/centerSize; |
|
102 | 127 |
} |
103 | 128 |
else |
104 | 129 |
{ |
105 |
factorObj = (0.80f*width)/mObjWidth; |
|
130 |
mFactorObj = (0.80f*width)/mObjWidth; |
|
131 |
factorCen = (0.08f*width)/centerSize; |
|
106 | 132 |
} |
107 | 133 |
|
134 |
Vertex3DActivity act = (Vertex3DActivity)mView.getContext(); |
|
135 |
mMovePoint.set(mFactorObj*act.getCenterX(),mFactorObj*act.getCenterY(),0); |
|
136 |
|
|
108 | 137 |
Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0); |
109 | 138 |
|
110 |
mObject.move( new Static3D( (width-factorObj*mObjWidth)/2 , (height-factorObj*mObjHeight)/2 , 0) );
|
|
111 |
mObject.scale(factorObj);
|
|
139 |
mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
|
|
140 |
mObject.scale(mFactorObj);
|
|
112 | 141 |
mObject.quaternion(mQuatInt1, rotateObj); |
113 | 142 |
mObject.quaternion(mQuatInt2, rotateObj); |
114 | 143 |
|
144 |
Static3D rotateCen = new Static3D(width/2,height/2, 0); |
|
145 |
|
|
146 |
mCenter.quaternion(mQuatInt1, rotateCen); |
|
147 |
mCenter.quaternion(mQuatInt2, rotateCen); |
|
148 |
|
|
149 |
mCenter.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 , |
|
150 |
(height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) ); |
|
151 |
mCenter.move(mMoveInter); |
|
152 |
mCenter.scale(factorCen); |
|
153 |
|
|
115 | 154 |
int backgroundSize = mBackground.getWidth(); |
116 | 155 |
float factorBackX = ((float)width)/backgroundSize; |
117 | 156 |
float factorBackY = ((float)height)/backgroundSize; |
118 | 157 |
|
119 |
mBackground.move(new Static3D( -width/2, -height/2,-factorObj*(mObjWidth+mObjHeight)/2) );
|
|
158 |
mBackground.move(new Static3D( -width/2, -height/2,-mFactorObj*(mObjWidth+mObjHeight)/2) );
|
|
120 | 159 |
mBackground.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) ); |
121 | 160 |
|
122 | 161 |
Distorted.onSurfaceChanged(width, height); |
... | ... | |
130 | 169 |
|
131 | 170 |
InputStream is1 = act.getResources().openRawResource(act.getBitmap()); |
132 | 171 |
InputStream is2 = act.getResources().openRawResource(R.raw.water); |
172 |
InputStream is3 = act.getResources().openRawResource(R.raw.center); |
|
133 | 173 |
|
134 |
Bitmap bitmap1,bitmap2; |
|
174 |
Bitmap bitmap1,bitmap2,bitmap3;
|
|
135 | 175 |
|
136 | 176 |
try |
137 | 177 |
{ |
138 | 178 |
bitmap1 = BitmapFactory.decodeStream(is1); |
139 | 179 |
bitmap2 = BitmapFactory.decodeStream(is2); |
180 |
bitmap3 = BitmapFactory.decodeStream(is3); |
|
140 | 181 |
} |
141 | 182 |
finally |
142 | 183 |
{ |
... | ... | |
144 | 185 |
{ |
145 | 186 |
is1.close(); |
146 | 187 |
is2.close(); |
188 |
is3.close(); |
|
147 | 189 |
} |
148 | 190 |
catch(IOException e) { } |
149 | 191 |
} |
150 | 192 |
|
151 | 193 |
mObject.setBitmap(bitmap1); |
152 |
mBackground.setBitmap(bitmap2) |
|
153 |
; |
|
194 |
mBackground.setBitmap(bitmap2); |
|
195 |
mCenter.setBitmap(bitmap3); |
|
196 |
|
|
154 | 197 |
try |
155 | 198 |
{ |
156 | 199 |
Distorted.onSurfaceCreated(mView.getContext()); |
Also available in: Unified diff
re-add center to Vertex3D