Revision 687263cc
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/generic/GenericRenderer.java | ||
---|---|---|
55 | 55 |
|
56 | 56 |
private GLSurfaceView mView; |
57 | 57 |
private DistortedTexture mObjectTexture, mBackgroundTexture, mCenterTexture, mRegionTexture; |
58 |
private DistortedEffects mObjectEffects,mBackgroundEffects,mCenterEffects,mRegionEffects; |
|
58 | 59 |
private DistortedScreen mScreen; |
59 | 60 |
private DistortedNode mCenterNode, mRegionNode; |
60 | 61 |
private int mObjWidth, mObjHeight, mObjDepth; |
... | ... | |
87 | 88 |
mScaleBackground= new Static3D(1,1,1); |
88 | 89 |
|
89 | 90 |
mObjectTexture = act.getTexture(); |
90 |
mBackgroundTexture = new DistortedTexture(100,100);
|
|
91 |
mCenterTexture = new DistortedTexture(100,100);
|
|
92 |
mRegionTexture = new DistortedTexture(100,100);
|
|
91 |
mBackgroundTexture = new DistortedTexture(); |
|
92 |
mCenterTexture = new DistortedTexture(); |
|
93 |
mRegionTexture = new DistortedTexture(); |
|
93 | 94 |
|
94 | 95 |
mFactorObj = 1.0f; |
95 | 96 |
|
96 |
DistortedEffects objectEffects = act.getEffects();
|
|
97 |
DistortedEffects backgroundEffects = new DistortedEffects();
|
|
98 |
DistortedEffects centerEffects = new DistortedEffects();
|
|
99 |
DistortedEffects regionEffects = new DistortedEffects();
|
|
97 |
mObjectEffects = act.getEffects();
|
|
98 |
mBackgroundEffects = new DistortedEffects(1);
|
|
99 |
mCenterEffects = new DistortedEffects(1);
|
|
100 |
mRegionEffects = new DistortedEffects(1);
|
|
100 | 101 |
|
101 |
MeshBase mesh = act.getMesh(); |
|
102 |
MeshRectangles quad = new MeshRectangles(1,1);
|
|
102 |
MeshBase mesh = act.getMesh();
|
|
103 |
MeshRectangles quad = new MeshRectangles(1,1); |
|
103 | 104 |
|
104 | 105 |
mFactor = mesh instanceof MeshSphere ? 1.0f : 0.7f; |
105 | 106 |
|
106 |
mObjWidth = mObjectTexture.getWidth();
|
|
107 |
mObjHeight= mObjectTexture.getHeight();
|
|
108 |
mObjDepth = mObjectTexture.getDepth(mesh);
|
|
107 |
mObjWidth = act.getWidth();
|
|
108 |
mObjHeight= act.getHeight();
|
|
109 |
mObjDepth = act.getDepth();
|
|
109 | 110 |
|
110 | 111 |
mQuat1 = new Static4D(0,0,0,1); // unity |
111 | 112 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
... | ... | |
114 | 115 |
mRegionPoint= new Static3D(0,0,0); |
115 | 116 |
mRegionScalePoint = new Static3D(0,0,0); |
116 | 117 |
|
117 |
mCenterNode = new DistortedNode(mCenterTexture, centerEffects, quad);
|
|
118 |
mRegionNode = new DistortedNode(mRegionTexture, regionEffects, quad);
|
|
118 |
mCenterNode = new DistortedNode(mCenterTexture, mCenterEffects, quad);
|
|
119 |
mRegionNode = new DistortedNode(mRegionTexture, mRegionEffects, quad);
|
|
119 | 120 |
|
120 | 121 |
mScreen = new DistortedScreen(); |
121 | 122 |
mScreen.setProjection(FOV, NEAR); |
122 |
mScreen.attach(mBackgroundTexture, backgroundEffects, quad );
|
|
123 |
mScreen.attach(mObjectTexture , objectEffects , mesh );
|
|
123 |
mScreen.attach(mBackgroundTexture, mBackgroundEffects, quad );
|
|
124 |
mScreen.attach(mObjectTexture , mObjectEffects , mesh );
|
|
124 | 125 |
|
125 |
int regionSize = mRegionTexture.getWidth();
|
|
126 |
int regionSize = mRegionEffects.getStartchX();
|
|
126 | 127 |
mRotateCen = new Static3D(0 ,0, 0); |
127 | 128 |
|
128 | 129 |
MatrixEffectQuaternion quat1cen = new MatrixEffectQuaternion(mQuat1, mRotateCen); |
129 | 130 |
MatrixEffectQuaternion quat2cen = new MatrixEffectQuaternion(mQuat2, mRotateCen); |
130 | 131 |
MatrixEffectMove centerMove = new MatrixEffectMove(mCenterPoint); |
131 | 132 |
|
132 |
centerEffects.apply( new MatrixEffectScale(mScaleCenter) );
|
|
133 |
centerEffects.apply( centerMove );
|
|
134 |
centerEffects.apply( new MatrixEffectMove(mMoveCenter) );
|
|
135 |
centerEffects.apply(quat2cen);
|
|
136 |
centerEffects.apply(quat1cen);
|
|
133 |
mCenterEffects.apply( new MatrixEffectScale(mScaleCenter) );
|
|
134 |
mCenterEffects.apply( centerMove );
|
|
135 |
mCenterEffects.apply( new MatrixEffectMove(mMoveCenter) );
|
|
136 |
mCenterEffects.apply(quat2cen);
|
|
137 |
mCenterEffects.apply(quat1cen);
|
|
137 | 138 |
|
138 |
regionEffects.apply( new MatrixEffectMove(new Static3D( -regionSize*0.5f , -regionSize*0.5f , 0)) );
|
|
139 |
regionEffects.apply( new MatrixEffectScale(mRegionScalePoint) );
|
|
140 |
regionEffects.apply( new MatrixEffectMove(mRegionPoint) );
|
|
141 |
regionEffects.apply( centerMove );
|
|
142 |
regionEffects.apply( new MatrixEffectMove(mMoveRegion) );
|
|
143 |
regionEffects.apply(quat2cen);
|
|
144 |
regionEffects.apply(quat1cen);
|
|
139 |
mRegionEffects.apply( new MatrixEffectMove(new Static3D( -regionSize*0.5f , -regionSize*0.5f , 0)) );
|
|
140 |
mRegionEffects.apply( new MatrixEffectScale(mRegionScalePoint) );
|
|
141 |
mRegionEffects.apply( new MatrixEffectMove(mRegionPoint) );
|
|
142 |
mRegionEffects.apply( centerMove );
|
|
143 |
mRegionEffects.apply( new MatrixEffectMove(mMoveRegion) );
|
|
144 |
mRegionEffects.apply(quat2cen);
|
|
145 |
mRegionEffects.apply(quat1cen);
|
|
145 | 146 |
|
146 | 147 |
resetMatrixEffects(); |
147 | 148 |
|
148 | 149 |
// quite tricky: move the background exactly to the FAR plane! (see InternalOutputSurface.setProjection() ) |
149 |
backgroundEffects.apply(new MatrixEffectScale(mScaleBackground) );
|
|
150 |
backgroundEffects.apply(new MatrixEffectMove(mMoveBackground) );
|
|
150 |
mBackgroundEffects.apply(new MatrixEffectScale(mScaleBackground) );
|
|
151 |
mBackgroundEffects.apply(new MatrixEffectMove(mMoveBackground) );
|
|
151 | 152 |
} |
152 | 153 |
|
153 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
154 | 155 |
|
155 | 156 |
void resetMatrixEffects() |
156 | 157 |
{ |
157 |
GenericActivity2 act = (GenericActivity2)mView.getContext(); |
|
158 |
DistortedEffects objectEffects= act.getEffects(); |
|
159 | 158 |
Static3D rotateObj = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, (float)mObjDepth/2 ); |
160 | 159 |
|
161 | 160 |
MatrixEffectQuaternion quat1obj = new MatrixEffectQuaternion(mQuat1, rotateObj); |
162 | 161 |
MatrixEffectQuaternion quat2obj = new MatrixEffectQuaternion(mQuat2, rotateObj); |
163 | 162 |
|
164 |
objectEffects.apply(quat2obj);
|
|
165 |
objectEffects.apply(quat1obj);
|
|
166 |
objectEffects.apply( new MatrixEffectScale(mScaleObject) );
|
|
167 |
objectEffects.apply( new MatrixEffectMove(mMoveObject));
|
|
163 |
mObjectEffects.apply(quat2obj);
|
|
164 |
mObjectEffects.apply(quat1obj);
|
|
165 |
mObjectEffects.apply( new MatrixEffectScale(mScaleObject) );
|
|
166 |
mObjectEffects.apply( new MatrixEffectMove(mMoveObject));
|
|
168 | 167 |
|
169 | 168 |
mQuat1.set(0,0,0,1); |
170 | 169 |
mQuat2.set(0,0,0,1); |
... | ... | |
217 | 216 |
|
218 | 217 |
void setRegion(float x, float y, float z, float r) |
219 | 218 |
{ |
220 |
float factorReg = 2*mFactorObj*r/mRegionTexture.getWidth();
|
|
219 |
float factorReg = 2*mFactorObj*r/mRegionEffects.getStartchX();
|
|
221 | 220 |
mRegionPoint.set(mFactorObj*x,mFactorObj*y, mFactorObj*z); |
222 | 221 |
mRegionScalePoint.set(factorReg,factorReg,factorReg); |
223 | 222 |
} |
... | ... | |
244 | 243 |
mScreenMin = width<height ? width:height; |
245 | 244 |
|
246 | 245 |
float factorCen; |
247 |
int centerSize = mCenterTexture.getWidth();
|
|
246 |
int centerSize = mCenterEffects.getStartchX();
|
|
248 | 247 |
|
249 | 248 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
250 | 249 |
{ |
... | ... | |
268 | 267 |
mScaleCenter.set(factorCen,factorCen,factorCen); |
269 | 268 |
mMoveRegion.set( (width -mFactorObj*mObjWidth )/2 ,(height-mFactorObj*mObjHeight)/2 , 12 ); |
270 | 269 |
|
271 |
int backgroundSize = mBackgroundTexture.getWidth();
|
|
270 |
int backgroundSize = mBackgroundEffects.getStartchX();
|
|
272 | 271 |
float factorBackX = ((float)width)/backgroundSize; |
273 | 272 |
float factorBackY = ((float)height)/backgroundSize; |
274 | 273 |
|
Also available in: Unified diff
Move the 'pre-multiply mesh before applying any effects' thing from [(Xsize of texture, Ysize of texture) x Mesh's zFactor] to Effects.setStretch(sx,sy,sz)