Revision af662543
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java | ||
|---|---|---|
| 48 | 48 |
|
| 49 | 49 |
class Effects3DRenderer implements GLSurfaceView.Renderer |
| 50 | 50 |
{
|
| 51 |
private static final float FOV = 70.0f; |
|
| 52 |
private static final float NEAR = 0.1f; |
|
| 53 |
|
|
| 51 | 54 |
private GLSurfaceView mView; |
| 52 | 55 |
private DistortedTexture mObjectTexture, mBackgroundTexture, mCenterTexture, mRegionTexture; |
| 53 | 56 |
private DistortedEffects mObjectEffects, mBackgroundEffects, mCenterEffects, mRegionEffects; |
| ... | ... | |
| 87 | 90 |
MeshObject meshO = act.getMesh(); |
| 88 | 91 |
MeshFlat quad = new MeshFlat(1,1); |
| 89 | 92 |
|
| 90 |
|
|
| 91 | 93 |
mObjWidth = mObjectTexture.getWidth(); |
| 92 | 94 |
mObjHeight= mObjectTexture.getHeight(); |
| 93 | 95 |
mObjDepth = mObjectTexture.getDepth(meshO); |
| ... | ... | |
| 117 | 119 |
mRegionNode = new DistortedNode(mRegionTexture, mRegionEffects, quad); |
| 118 | 120 |
|
| 119 | 121 |
mScreen = new DistortedScreen(); |
| 122 |
mScreen.setProjection(FOV, NEAR); |
|
| 120 | 123 |
mScreen.attach(mBackgroundTexture, mBackgroundEffects, quad ); |
| 121 | 124 |
mScreen.attach(mObjectTexture , mObjectEffects , meshO); |
| 122 | 125 |
} |
| ... | ... | |
| 230 | 233 |
float factorBackX = ((float)width)/backgroundSize; |
| 231 | 234 |
float factorBackY = ((float)height)/backgroundSize; |
| 232 | 235 |
|
| 233 |
mBackgroundEffects.move(new Static3D( -width/2, -height/2,-mFactorObj*(mObjWidth+mObjHeight)/2) ); |
|
| 236 |
// quite tricky: move the background exactly to the FAR plane! (see DistortedOutputSurface.setProjection() ) |
|
| 237 |
mBackgroundEffects.move(new Static3D( -width/2, -height/2, -height*(1.0f-NEAR)/(2.0f*(float)Math.tan(FOV*Math.PI/360))) ); |
|
| 234 | 238 |
mBackgroundEffects.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) ); |
| 235 | 239 |
|
| 236 | 240 |
mScreen.resize(width, height); |
| src/main/java/org/distorted/examples/fbo/FBORenderer.java | ||
|---|---|---|
| 74 | 74 |
if( depth ) mRoot.glEnable (GLES30.GL_DEPTH_TEST); |
| 75 | 75 |
else mRoot.glDisable(GLES30.GL_DEPTH_TEST); |
| 76 | 76 |
|
| 77 |
mRoot.glDepthMask(depth); |
|
| 77 |
// TODO for some reason this does not work - investigate. |
|
| 78 |
//mRoot.glDepthMask(depth); |
|
| 78 | 79 |
|
| 79 | 80 |
// we can also, to save memory, delete/recreate |
| 80 | 81 |
// the depth buffer each time. This is optional. |
| src/main/java/org/distorted/examples/projection/ProjectionActivity.java | ||
|---|---|---|
| 33 | 33 |
|
| 34 | 34 |
public class ProjectionActivity extends Activity implements OnSeekBarChangeListener |
| 35 | 35 |
{
|
| 36 |
private TextView textF, textX, textY;
|
|
| 36 |
private TextView textF, textN;
|
|
| 37 | 37 |
|
| 38 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 39 | 39 |
|
| ... | ... | |
| 44 | 44 |
setContentView(R.layout.projectionlayout); |
| 45 | 45 |
|
| 46 | 46 |
textF = (TextView)findViewById(R.id.projectionTextFOV); |
| 47 |
textX = (TextView)findViewById(R.id.projectionTextX); |
|
| 48 |
textY = (TextView)findViewById(R.id.projectionTextY); |
|
| 47 |
textN = (TextView)findViewById(R.id.projectionTextNear); |
|
| 49 | 48 |
|
| 50 | 49 |
SeekBar bar; |
| 51 | 50 |
|
| 52 | 51 |
bar = (SeekBar)findViewById(R.id.projectionSeekFOV); |
| 53 | 52 |
bar.setOnSeekBarChangeListener(this); |
| 54 | 53 |
bar.setProgress(50); |
| 55 |
bar = (SeekBar)findViewById(R.id.projectionSeekX); |
|
| 56 |
bar.setOnSeekBarChangeListener(this); |
|
| 57 |
bar.setProgress(50); |
|
| 58 |
bar = (SeekBar)findViewById(R.id.projectionSeekY); |
|
| 54 |
bar = (SeekBar)findViewById(R.id.projectionSeekNear); |
|
| 59 | 55 |
bar.setOnSeekBarChangeListener(this); |
| 60 | 56 |
bar.setProgress(50); |
| 61 | 57 |
} |
| ... | ... | |
| 95 | 91 |
|
| 96 | 92 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
| 97 | 93 |
{
|
| 98 |
int ret;
|
|
| 94 |
float ret;
|
|
| 99 | 95 |
ProjectionSurfaceView view = (ProjectionSurfaceView)findViewById(R.id.surfaceViewProjection); |
| 100 | 96 |
ProjectionRenderer renderer = view.getRenderer(); |
| 101 | 97 |
|
| 102 | 98 |
switch (bar.getId()) |
| 103 | 99 |
{
|
| 104 |
case R.id.projectionSeekFOV: ret = renderer.setFOV(progress); |
|
| 105 |
textF.setText(getString(R.string.fov_placeholder,ret)); |
|
| 106 |
break; |
|
| 107 |
case R.id.projectionSeekX : ret = renderer.setX(progress); |
|
| 108 |
textX.setText(getString(R.string.x_placeholder,ret)); |
|
| 109 |
break; |
|
| 110 |
case R.id.projectionSeekY : ret = renderer.setY(progress); |
|
| 111 |
textY.setText(getString(R.string.y_placeholder,ret)); |
|
| 112 |
break; |
|
| 100 |
case R.id.projectionSeekFOV : ret = renderer.setFOV(progress); |
|
| 101 |
textF.setText(getString(R.string.fov_placeholder,(int)ret)); |
|
| 102 |
break; |
|
| 103 |
case R.id.projectionSeekNear: ret = renderer.setNear(progress); |
|
| 104 |
textN.setText(getString(R.string.near_placeholder,ret)); |
|
| 105 |
break; |
|
| 113 | 106 |
} |
| 114 | 107 |
} |
| 115 | 108 |
|
| src/main/java/org/distorted/examples/projection/ProjectionRenderer.java | ||
|---|---|---|
| 45 | 45 |
private DistortedEffects mEffects; |
| 46 | 46 |
private DistortedScreen mScreen; |
| 47 | 47 |
|
| 48 |
private float mF, mX, mY; |
|
| 49 |
private int mWidth, mHeight; |
|
| 48 |
private float mF, mNear; |
|
| 50 | 49 |
|
| 51 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 52 | 51 |
|
| ... | ... | |
| 59 | 58 |
|
| 60 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | 60 |
|
| 62 |
int setFOV(int f)
|
|
| 61 |
float setFOV(int f)
|
|
| 63 | 62 |
{
|
| 64 | 63 |
mF = f; |
| 65 |
mScreen.setProjection(mF,mX,mY);
|
|
| 66 |
return (int)mF;
|
|
| 64 |
mScreen.setProjection(mF,mNear);
|
|
| 65 |
return mF; |
|
| 67 | 66 |
} |
| 68 | 67 |
|
| 69 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 70 | 69 |
|
| 71 |
int setX(int x)
|
|
| 70 |
float setNear(int near)
|
|
| 72 | 71 |
{
|
| 73 |
mX = (x-50)*0.02f*mWidth; |
|
| 74 |
mScreen.setProjection(mF,mX,mY); |
|
| 75 |
return (int)mX; |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 79 |
|
|
| 80 |
int setY(int y) |
|
| 81 |
{
|
|
| 82 |
mY = (y-50)*0.02f*mHeight; |
|
| 83 |
mScreen.setProjection(mF,mX,mY); |
|
| 84 |
return (int)mY; |
|
| 72 |
mNear = near/100.0f; |
|
| 73 |
mScreen.setProjection(mF,mNear); |
|
| 74 |
return mNear; |
|
| 85 | 75 |
} |
| 86 | 76 |
|
| 87 | 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 96 | 86 |
|
| 97 | 87 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 98 | 88 |
{
|
| 99 |
mWidth = width; |
|
| 100 |
mHeight= height; |
|
| 101 |
|
|
| 102 |
mScreen.setProjection(mF,mX,mY); |
|
| 89 |
mScreen.setProjection(mF,mNear); |
|
| 103 | 90 |
mEffects.abortAllEffects(); |
| 104 | 91 |
|
| 105 | 92 |
Paint paint = new Paint(); |
| src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
|---|---|---|
| 137 | 137 |
} |
| 138 | 138 |
|
| 139 | 139 |
mScreen = new DistortedScreen(); |
| 140 |
mScreen.setProjection(60.0f, 0.0f, 0.0f);
|
|
| 140 |
mScreen.setProjection(60.0f, 0.02f);
|
|
| 141 | 141 |
} |
| 142 | 142 |
|
| 143 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/res/layout/projectionlayout.xml | ||
|---|---|---|
| 46 | 46 |
android:paddingTop="5dp" > |
| 47 | 47 |
|
| 48 | 48 |
<TextView |
| 49 |
android:id="@+id/projectionTextX"
|
|
| 49 |
android:id="@+id/projectionTextNear"
|
|
| 50 | 50 |
android:layout_width="0dp" |
| 51 | 51 |
android:layout_height="wrap_content" |
| 52 | 52 |
android:layout_weight="0.5" |
| ... | ... | |
| 54 | 54 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
| 55 | 55 |
|
| 56 | 56 |
<SeekBar |
| 57 |
android:id="@+id/projectionSeekX" |
|
| 58 |
android:layout_width="wrap_content" |
|
| 59 |
android:layout_height="wrap_content" |
|
| 60 |
android:layout_weight="1" |
|
| 61 |
android:paddingStart="15dp" |
|
| 62 |
android:paddingEnd="15dp" /> |
|
| 63 |
</LinearLayout> |
|
| 64 |
|
|
| 65 |
<LinearLayout |
|
| 66 |
android:id="@+id/linearLayout3" |
|
| 67 |
android:layout_width="fill_parent" |
|
| 68 |
android:layout_height="wrap_content" |
|
| 69 |
android:gravity="center|fill_horizontal" |
|
| 70 |
android:orientation="horizontal" |
|
| 71 |
android:paddingBottom="5dp" |
|
| 72 |
android:paddingTop="5dp" > |
|
| 73 |
|
|
| 74 |
<TextView |
|
| 75 |
android:id="@+id/projectionTextY" |
|
| 76 |
android:layout_width="0dp" |
|
| 77 |
android:layout_height="wrap_content" |
|
| 78 |
android:layout_weight="0.5" |
|
| 79 |
android:paddingStart="15dp" |
|
| 80 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
| 81 |
|
|
| 82 |
<SeekBar |
|
| 83 |
android:id="@+id/projectionSeekY" |
|
| 57 |
android:id="@+id/projectionSeekNear" |
|
| 84 | 58 |
android:layout_width="wrap_content" |
| 85 | 59 |
android:layout_height="wrap_content" |
| 86 | 60 |
android:layout_weight="1" |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 72 | 72 |
<string name="size_placeholder">Size %1$.1f</string> |
| 73 | 73 |
<string name="hips_placeholder">Hips %1$d</string> |
| 74 | 74 |
<string name="fov_placeholder">FOV: %1$d</string> |
| 75 |
<string name="x_placeholder">X: %1$d</string> |
|
| 76 |
<string name="y_placeholder">Y: %1$d</string> |
|
| 75 |
<string name="near_placeholder">Near: %1$.2f</string> |
|
| 77 | 76 |
<string name="wind_placeholder">Wind: %1$d</string> |
| 78 | 77 |
<string name="blur_placeholder">Blur: %1$d</string> |
| 79 | 78 |
|
Also available in: Unified diff
Fixes for z-fighting.