Revision 392e16fd
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
|
30 |
import org.distorted.library.DistortedFramebuffer; |
|
30 | 31 |
import org.distorted.library.DistortedObjectTree; |
31 | 32 |
import org.distorted.library.EffectTypes; |
32 | 33 |
import org.distorted.library.type.Dynamic1D; |
... | ... | |
51 | 52 |
private static final int NUM_LEAVES = 8; |
52 | 53 |
|
53 | 54 |
private GLSurfaceView mView; |
54 |
private DistortedObjectTree mScreen;
|
|
55 |
private DistortedObjectTree mRoot;
|
|
55 | 56 |
private DistortedTexture mLeaf; |
56 |
|
|
57 |
private DistortedFramebuffer mScreen; |
|
57 | 58 |
private int mScreenW, mScreenH; |
58 | 59 |
|
59 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
64 | 65 |
|
65 | 66 |
mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE); |
66 | 67 |
GridFlat grid = new GridFlat(1,1); |
67 |
DistortedEffectQueues queue = new DistortedEffectQueues();
|
|
68 |
DistortedEffectQueues effects = new DistortedEffectQueues();
|
|
68 | 69 |
|
69 | 70 |
mScreenW = 9*LEAF_SIZE; |
70 | 71 |
mScreenH = 9*LEAF_SIZE; |
71 |
mScreen = new DistortedObjectTree(new DistortedTexture(mScreenW,mScreenH), queue, grid);
|
|
72 |
mRoot = new DistortedObjectTree(new DistortedTexture(mScreenW,mScreenH), effects, grid);
|
|
72 | 73 |
|
73 | 74 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
74 | 75 |
rot.setMode(Dynamic1D.MODE_JUMP); |
... | ... | |
88 | 89 |
{ |
89 | 90 |
if( i<=1 ) |
90 | 91 |
{ |
91 |
queue = new DistortedEffectQueues();
|
|
92 |
mCircleNode[i] = new DistortedObjectTree(new DistortedTexture(3*LEAF_SIZE,3*LEAF_SIZE), queue, grid);
|
|
92 |
effects = new DistortedEffectQueues();
|
|
93 |
mCircleNode[i] = new DistortedObjectTree(new DistortedTexture(3*LEAF_SIZE,3*LEAF_SIZE), effects, grid);
|
|
93 | 94 |
|
94 | 95 |
for(int j=0; j<NUM_LEAVES-i; j++) |
95 | 96 |
{ |
96 |
queue = new DistortedEffectQueues();
|
|
97 |
mCircleNode[i].attach(mLeaf, queue, grid);
|
|
98 |
queue.rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
|
|
99 |
queue.move(moveVector);
|
|
97 |
effects = new DistortedEffectQueues();
|
|
98 |
mCircleNode[i].attach(mLeaf, effects, grid);
|
|
99 |
effects.rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
|
|
100 |
effects.move(moveVector);
|
|
100 | 101 |
} |
101 | 102 |
} |
102 | 103 |
else |
... | ... | |
104 | 105 |
mCircleNode[i] = new DistortedObjectTree(mCircleNode[0], Distorted.CLONE_BITMAP|Distorted.CLONE_CHILDREN); |
105 | 106 |
} |
106 | 107 |
|
107 |
mScreen.attach(mCircleNode[i]);
|
|
108 |
queue = mCircleNode[i].getQueues();
|
|
109 |
queue.move( new Static3D(positions[2*i], positions[2*i+1], 0) );
|
|
110 |
queue.rotate( rot, axis, center );
|
|
111 |
queue.chroma( new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2]) );
|
|
108 |
mRoot.attach(mCircleNode[i]);
|
|
109 |
effects = mCircleNode[i].getQueues();
|
|
110 |
effects.move( new Static3D(positions[2*i], positions[2*i+1], 0) );
|
|
111 |
effects.rotate( rot, axis, center );
|
|
112 |
effects.chroma( new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2]) );
|
|
112 | 113 |
} |
114 |
|
|
115 |
mScreen = new DistortedFramebuffer(0); |
|
113 | 116 |
} |
114 | 117 |
|
115 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
117 | 120 |
public void onDrawFrame(GL10 glUnused) |
118 | 121 |
{ |
119 | 122 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
120 |
mScreen.draw(System.currentTimeMillis());
|
|
123 |
mRoot.draw(System.currentTimeMillis(),mScreen);
|
|
121 | 124 |
} |
122 | 125 |
|
123 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 127 |
|
125 | 128 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
126 | 129 |
{ |
127 |
DistortedEffectQueues queues = mScreen.getQueues();
|
|
130 |
DistortedEffectQueues effects = mRoot.getQueues();
|
|
128 | 131 |
|
129 |
queues.abortEffects(EffectTypes.MATRIX);
|
|
132 |
effects.abortEffects(EffectTypes.MATRIX);
|
|
130 | 133 |
|
131 | 134 |
if( (float)mScreenH/mScreenW > (float)height/width ) |
132 | 135 |
{ |
133 | 136 |
int w = (height*mScreenW)/mScreenH; |
134 | 137 |
float factor = (float)height/mScreenH; |
135 | 138 |
|
136 |
queues.move( new Static3D((width-w)/2 ,0, 0) );
|
|
137 |
queues.scale( factor );
|
|
139 |
effects.move( new Static3D((width-w)/2 ,0, 0) );
|
|
140 |
effects.scale( factor );
|
|
138 | 141 |
} |
139 | 142 |
else |
140 | 143 |
{ |
141 | 144 |
int h = (width*mScreenH)/mScreenW; |
142 | 145 |
float factor = (float)width/mScreenW; |
143 | 146 |
|
144 |
queues.move( new Static3D(0,(height-h)/2,0) );
|
|
145 |
queues.scale( factor );
|
|
147 |
effects.move( new Static3D(0,(height-h)/2,0) );
|
|
148 |
effects.scale( factor );
|
|
146 | 149 |
} |
147 | 150 |
|
148 |
Distorted.onSurfaceChanged(width, height);
|
|
151 |
mScreen.resize(width, height);
|
|
149 | 152 |
} |
150 | 153 |
|
151 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Change in the API: we always have to create a DistortedFramebuffer to render to.