Revision 698ad0a8
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/generic/GenericRenderer.java | ||
---|---|---|
35 | 35 |
import org.distorted.library.main.DistortedScreen; |
36 | 36 |
import org.distorted.library.main.DistortedTexture; |
37 | 37 |
import org.distorted.library.mesh.MeshBase; |
38 |
import org.distorted.library.mesh.MeshRectangles;
|
|
38 |
import org.distorted.library.mesh.MeshQuad;
|
|
39 | 39 |
import org.distorted.library.mesh.MeshSphere; |
40 | 40 |
import org.distorted.library.type.Static3D; |
41 | 41 |
import org.distorted.library.type.Static4D; |
... | ... | |
55 | 55 |
|
56 | 56 |
private GLSurfaceView mView; |
57 | 57 |
private DistortedTexture mObjectTexture, mBackgroundTexture, mCenterTexture, mRegionTexture; |
58 |
private DistortedEffects mObjectEffects,mBackgroundEffects,mCenterEffects,mRegionEffects;
|
|
58 |
private DistortedEffects mObjectEffects; |
|
59 | 59 |
private DistortedScreen mScreen; |
60 |
private MeshQuad mRegionQuad, mCenterQuad, mBackgroundQuad; |
|
60 | 61 |
private DistortedNode mCenterNode, mRegionNode; |
61 |
private int mObjWidth, mObjHeight, mObjDepth;
|
|
62 |
private float mObjWidth, mObjHeight, mObjDepth;
|
|
62 | 63 |
private Static3D mCenterPoint, mRegionPoint, mRegionScalePoint; |
63 | 64 |
private Static3D mRotateCen, mMoveObject, mScaleObject, mMoveCenter, mScaleCenter, mMoveRegion, mMoveBackground, mScaleBackground; |
64 | 65 |
private boolean mShowingCenter=false; |
... | ... | |
94 | 95 |
|
95 | 96 |
mFactorObj = 1.0f; |
96 | 97 |
|
97 |
mObjectEffects = act.getEffects();
|
|
98 |
mBackgroundEffects = new DistortedEffects(1);
|
|
99 |
mCenterEffects = new DistortedEffects(1);
|
|
100 |
mRegionEffects = new DistortedEffects(1);
|
|
98 |
mObjectEffects = act.getEffects(); |
|
99 |
DistortedEffects backgroundEffects = new DistortedEffects();
|
|
100 |
DistortedEffects centerEffects = new DistortedEffects();
|
|
101 |
DistortedEffects regionEffects = new DistortedEffects();
|
|
101 | 102 |
|
102 |
MeshBase mesh = act.getMesh(); |
|
103 |
MeshRectangles quad = new MeshRectangles(1,1); |
|
103 |
MeshBase mesh = act.getMesh(); |
|
104 |
mRegionQuad = new MeshQuad(); |
|
105 |
mCenterQuad = new MeshQuad(); |
|
106 |
mBackgroundQuad = new MeshQuad(); |
|
104 | 107 |
|
105 | 108 |
mFactor = mesh instanceof MeshSphere ? 1.0f : 0.7f; |
106 | 109 |
|
... | ... | |
115 | 118 |
mRegionPoint= new Static3D(0,0,0); |
116 | 119 |
mRegionScalePoint = new Static3D(0,0,0); |
117 | 120 |
|
118 |
mCenterNode = new DistortedNode(mCenterTexture, mCenterEffects, quad);
|
|
119 |
mRegionNode = new DistortedNode(mRegionTexture, mRegionEffects, quad);
|
|
121 |
mCenterNode = new DistortedNode(mCenterTexture, centerEffects, mCenterQuad);
|
|
122 |
mRegionNode = new DistortedNode(mRegionTexture, regionEffects, mRegionQuad);
|
|
120 | 123 |
|
121 | 124 |
mScreen = new DistortedScreen(); |
122 | 125 |
mScreen.setProjection(FOV, NEAR); |
123 |
mScreen.attach(mBackgroundTexture, mBackgroundEffects, quad );
|
|
124 |
mScreen.attach(mObjectTexture , mObjectEffects , mesh );
|
|
126 |
mScreen.attach(mBackgroundTexture, backgroundEffects, mBackgroundQuad );
|
|
127 |
mScreen.attach(mObjectTexture , mObjectEffects , mesh ); |
|
125 | 128 |
|
126 |
int regionSize = mRegionEffects.getStartchX();
|
|
129 |
float regionSize = mRegionQuad.getStretchX();
|
|
127 | 130 |
mRotateCen = new Static3D(0 ,0, 0); |
128 | 131 |
|
129 | 132 |
MatrixEffectQuaternion quat1cen = new MatrixEffectQuaternion(mQuat1, mRotateCen); |
130 | 133 |
MatrixEffectQuaternion quat2cen = new MatrixEffectQuaternion(mQuat2, mRotateCen); |
131 | 134 |
MatrixEffectMove centerMove = new MatrixEffectMove(mCenterPoint); |
132 | 135 |
|
133 |
mCenterEffects.apply( new MatrixEffectScale(mScaleCenter) );
|
|
134 |
mCenterEffects.apply( centerMove );
|
|
135 |
mCenterEffects.apply( new MatrixEffectMove(mMoveCenter) );
|
|
136 |
mCenterEffects.apply(quat2cen);
|
|
137 |
mCenterEffects.apply(quat1cen);
|
|
136 |
centerEffects.apply( new MatrixEffectScale(mScaleCenter) );
|
|
137 |
centerEffects.apply( centerMove );
|
|
138 |
centerEffects.apply( new MatrixEffectMove(mMoveCenter) );
|
|
139 |
centerEffects.apply(quat2cen);
|
|
140 |
centerEffects.apply(quat1cen);
|
|
138 | 141 |
|
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);
|
|
142 |
regionEffects.apply( new MatrixEffectMove(new Static3D( -regionSize*0.5f , -regionSize*0.5f , 0)) );
|
|
143 |
regionEffects.apply( new MatrixEffectScale(mRegionScalePoint) );
|
|
144 |
regionEffects.apply( new MatrixEffectMove(mRegionPoint) );
|
|
145 |
regionEffects.apply( centerMove );
|
|
146 |
regionEffects.apply( new MatrixEffectMove(mMoveRegion) );
|
|
147 |
regionEffects.apply(quat2cen);
|
|
148 |
regionEffects.apply(quat1cen);
|
|
146 | 149 |
|
147 | 150 |
resetMatrixEffects(); |
148 | 151 |
|
149 | 152 |
// quite tricky: move the background exactly to the FAR plane! (see InternalOutputSurface.setProjection() ) |
150 |
mBackgroundEffects.apply(new MatrixEffectScale(mScaleBackground) );
|
|
151 |
mBackgroundEffects.apply(new MatrixEffectMove(mMoveBackground) );
|
|
153 |
backgroundEffects.apply(new MatrixEffectScale(mScaleBackground) );
|
|
154 |
backgroundEffects.apply(new MatrixEffectMove(mMoveBackground) );
|
|
152 | 155 |
} |
153 | 156 |
|
154 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
216 | 219 |
|
217 | 220 |
void setRegion(float x, float y, float z, float r) |
218 | 221 |
{ |
219 |
float factorReg = 2*mFactorObj*r/mRegionEffects.getStartchX();
|
|
222 |
float factorReg = 2*mFactorObj*r/mRegionQuad.getStretchX();
|
|
220 | 223 |
mRegionPoint.set(mFactorObj*x,mFactorObj*y, mFactorObj*z); |
221 | 224 |
mRegionScalePoint.set(factorReg,factorReg,factorReg); |
222 | 225 |
} |
... | ... | |
243 | 246 |
mScreenMin = width<height ? width:height; |
244 | 247 |
|
245 | 248 |
float factorCen; |
246 |
int centerSize = mCenterEffects.getStartchX();
|
|
249 |
float centerSize = mCenterQuad.getStretchX();
|
|
247 | 250 |
|
248 | 251 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
249 | 252 |
{ |
... | ... | |
267 | 270 |
mScaleCenter.set(factorCen,factorCen,factorCen); |
268 | 271 |
mMoveRegion.set( (width -mFactorObj*mObjWidth )/2 ,(height-mFactorObj*mObjHeight)/2 , 12 ); |
269 | 272 |
|
270 |
int backgroundSize = mBackgroundEffects.getStartchX();
|
|
273 |
float backgroundSize = mBackgroundQuad.getStretchX();
|
|
271 | 274 |
float factorBackX = ((float)width)/backgroundSize; |
272 | 275 |
float factorBackY = ((float)height)/backgroundSize; |
273 | 276 |
|
Also available in: Unified diff
Move the Effects.setStretch to Meshbase.setStretch