Revision e4c556f9
Added by Leszek Koltunski 11 months ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 63 | 63 |
<activity android:name=".meshfile.MeshFileActivity"/> |
| 64 | 64 |
<activity android:name=".flatblur.FlatBlurActivity"/> |
| 65 | 65 |
<activity android:name=".flatblur2.FlatBlur2Activity"/> |
| 66 |
<activity android:name=".polymesh.PolymeshActivity"/>
|
|
| 66 |
<activity android:name=".twocomponents.TwoComponentsActivity"/>
|
|
| 67 | 67 |
</application> |
| 68 | 68 |
</manifest> |
| src/main/java/org/distorted/examples/TableOfContents.java | ||
|---|---|---|
| 59 | 59 |
import org.distorted.examples.surfaceview.SurfaceViewActivity; |
| 60 | 60 |
import org.distorted.examples.save.SaveActivity; |
| 61 | 61 |
import org.distorted.examples.flag.FlagActivity; |
| 62 |
import org.distorted.examples.twocomponents.TwoComponentsActivity; |
|
| 62 | 63 |
import org.distorted.examples.wind.WindActivity; |
| 63 | 64 |
import org.distorted.examples.aroundtheworld.AroundTheWorldActivity; |
| 64 | 65 |
import org.distorted.examples.mirror.MirrorActivity; |
| ... | ... | |
| 129 | 130 |
SINGLEMESH (R.drawable.icon_example_singlemesh , R.string.example_singlemesh , R.string.example_singlemesh_subtitle , SingleMeshActivity.class), |
| 130 | 131 |
FLATBLUR2 (R.drawable.icon_example_flatblur , R.string.example_flatblur , R.string.example_flatblur_subtitle , FlatBlur2Activity.class ), |
| 131 | 132 |
MESHFILE (R.drawable.icon_example_meshfile , R.string.example_meshfile , R.string.example_meshfile_subtitle , MeshFileActivity.class), |
| 133 |
TWOCOMPONENTS (R.drawable.icon_example_wip , R.string.example_twocomponents , R.string.example_twocomponents_subtitle , TwoComponentsActivity.class), |
|
| 132 | 134 |
; |
| 133 | 135 |
|
| 134 | 136 |
final int icon, title, subtitle; |
| src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java | ||
|---|---|---|
| 76 | 76 |
mScale= new Static3D(1,1,1); |
| 77 | 77 |
Static3D center=new Static3D(0,0,0); |
| 78 | 78 |
|
| 79 |
Dynamic1D sink = new Dynamic1D(5000,0.0f); |
|
| 80 |
sink.add( new Static1D(0.5f) ); |
|
| 81 |
sink.add( new Static1D(2.0f) ); |
|
| 82 |
|
|
| 83 | 79 |
mQuat1 = new Static4D(0,0,0,1); |
| 84 | 80 |
mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
| 85 | 81 |
|
| src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java | ||
|---|---|---|
| 206 | 206 |
|
| 207 | 207 |
VertexEffectRotate.enable(); |
| 208 | 208 |
VertexEffectDisappear.enable(); |
| 209 |
PostprocessEffectGlow.enable(); |
|
| 209 | 210 |
|
| 210 | 211 |
DistortedLibrary.onSurfaceCreated(this); |
| 211 | 212 |
} |
| ... | ... | |
| 411 | 412 |
|
| 412 | 413 |
for(int i=0; i<NUM_CUBITS; i++) |
| 413 | 414 |
{
|
| 414 |
cubits[i] = cubits[NUM_CUBITS-1].copy(true); |
|
| 415 |
if( i<NUM_CUBITS-1 ) cubits[i] = cubits[NUM_CUBITS-1].copy(true);
|
|
| 415 | 416 |
cubits[i].apply( new MatrixEffectMove(CUBIT_MOVES[i]), 1,0); |
| 416 | 417 |
cubits[i].setTextureMap(TEXTURE_MAP[i],0); |
| 417 | 418 |
} |
| src/main/java/org/distorted/examples/twocomponents/TwoComponentsActivity.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2024 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.examples.twocomponents; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.opengl.GLSurfaceView; |
|
| 24 |
import android.os.Bundle; |
|
| 25 |
import android.view.View; |
|
| 26 |
import android.widget.Button; |
|
| 27 |
import android.widget.CheckBox; |
|
| 28 |
|
|
| 29 |
import org.distorted.examples.R; |
|
| 30 |
import org.distorted.library.main.DistortedLibrary; |
|
| 31 |
|
|
| 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 33 |
|
|
| 34 |
public class TwoComponentsActivity extends Activity |
|
| 35 |
{
|
|
| 36 |
@Override |
|
| 37 |
protected void onCreate(Bundle icicle) |
|
| 38 |
{
|
|
| 39 |
super.onCreate(icicle); |
|
| 40 |
DistortedLibrary.onCreate(); |
|
| 41 |
setContentView(R.layout.twocomponentslayout); |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
@Override |
|
| 47 |
protected void onPause() |
|
| 48 |
{
|
|
| 49 |
super.onPause(); |
|
| 50 |
GLSurfaceView view = this.findViewById(R.id.twocomponentsSurfaceView); |
|
| 51 |
view.onPause(); |
|
| 52 |
DistortedLibrary.onPause(); |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
|
|
| 57 |
@Override |
|
| 58 |
protected void onResume() |
|
| 59 |
{
|
|
| 60 |
super.onResume(); |
|
| 61 |
GLSurfaceView view = this.findViewById(R.id.twocomponentsSurfaceView); |
|
| 62 |
view.onResume(); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
@Override |
|
| 68 |
protected void onDestroy() |
|
| 69 |
{
|
|
| 70 |
DistortedLibrary.onDestroy(); |
|
| 71 |
super.onDestroy(); |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 75 |
|
|
| 76 |
public void onClick(View view) |
|
| 77 |
{
|
|
| 78 |
Button butt = (Button)view; |
|
| 79 |
int id = butt.getId(); |
|
| 80 |
TwoComponentsSurfaceView v = findViewById(R.id.twocomponentsSurfaceView); |
|
| 81 |
TwoComponentsRenderer r = v.getRenderer(); |
|
| 82 |
|
|
| 83 |
if( id == R.id.twocomponentsButton0 ) r.apply(0); |
|
| 84 |
if( id == R.id.twocomponentsButton1 ) r.apply(1); |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 88 |
|
|
| 89 |
public void onVisible(View view) |
|
| 90 |
{
|
|
| 91 |
CheckBox check = (CheckBox)view; |
|
| 92 |
int id = check.getId(); |
|
| 93 |
TwoComponentsSurfaceView v = findViewById(R.id.twocomponentsSurfaceView); |
|
| 94 |
TwoComponentsRenderer r = v.getRenderer(); |
|
| 95 |
|
|
| 96 |
if( id == R.id.twocomponentsCheckBox0 ) r.visible(true); |
|
| 97 |
if( id == R.id.twocomponentsCheckBox1 ) r.visible(false); |
|
| 98 |
} |
|
| 99 |
} |
|
| src/main/java/org/distorted/examples/twocomponents/TwoComponentsRenderer.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2024 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.examples.twocomponents; |
|
| 21 |
|
|
| 22 |
import android.content.res.Resources; |
|
| 23 |
import android.graphics.Bitmap; |
|
| 24 |
import android.graphics.Canvas; |
|
| 25 |
import android.graphics.Paint; |
|
| 26 |
import android.opengl.GLSurfaceView; |
|
| 27 |
|
|
| 28 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 29 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
| 30 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 31 |
import org.distorted.library.effect.PostprocessEffectGlow; |
|
| 32 |
import org.distorted.library.effect.VertexEffectDisappear; |
|
| 33 |
import org.distorted.library.effect.VertexEffectMove; |
|
| 34 |
import org.distorted.library.effect.VertexEffectRotate; |
|
| 35 |
import org.distorted.library.main.DistortedEffects; |
|
| 36 |
import org.distorted.library.main.DistortedLibrary; |
|
| 37 |
import org.distorted.library.main.DistortedScreen; |
|
| 38 |
import org.distorted.library.main.DistortedTexture; |
|
| 39 |
import org.distorted.library.mesh.MeshBase; |
|
| 40 |
import org.distorted.library.mesh.MeshJoined; |
|
| 41 |
import org.distorted.library.mesh.MeshTriangle; |
|
| 42 |
import org.distorted.library.type.Dynamic1D; |
|
| 43 |
import org.distorted.library.type.DynamicQuat; |
|
| 44 |
import org.distorted.library.type.Static1D; |
|
| 45 |
import org.distorted.library.type.Static2D; |
|
| 46 |
import org.distorted.library.type.Static3D; |
|
| 47 |
import org.distorted.library.type.Static4D; |
|
| 48 |
|
|
| 49 |
import java.io.InputStream; |
|
| 50 |
|
|
| 51 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 52 |
import javax.microedition.khronos.opengles.GL10; |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
class TwoComponentsRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser |
|
| 57 |
{
|
|
| 58 |
private final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
|
|
| 59 |
|
|
| 60 |
private final Resources mResources; |
|
| 61 |
private final DistortedScreen mScreen; |
|
| 62 |
private final DistortedEffects mEffects; |
|
| 63 |
private final Static3D mScale; |
|
| 64 |
private final VertexEffectRotate mRotate; |
|
| 65 |
private final VertexEffectDisappear mDisappear; |
|
| 66 |
private final Dynamic1D mAngleDyn; |
|
| 67 |
private final Static1D mAngle; |
|
| 68 |
|
|
| 69 |
private DistortedTexture mTexture; |
|
| 70 |
private MeshBase mMesh; |
|
| 71 |
private boolean mInvisibleLeft, mInvisibleRight; |
|
| 72 |
|
|
| 73 |
Static4D mQuat1, mQuat2; |
|
| 74 |
int mScreenMin; |
|
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
TwoComponentsRenderer(GLSurfaceView v) |
|
| 79 |
{
|
|
| 80 |
mResources = v.getResources(); |
|
| 81 |
|
|
| 82 |
mScreen = new DistortedScreen(); |
|
| 83 |
mScale= new Static3D(1,1,1); |
|
| 84 |
Static3D center=new Static3D(0,0,0); |
|
| 85 |
|
|
| 86 |
mQuat1 = new Static4D(0,0,0,1); |
|
| 87 |
mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
|
| 88 |
|
|
| 89 |
DynamicQuat quatInt1 = new DynamicQuat(0,0.5f); |
|
| 90 |
DynamicQuat quatInt2 = new DynamicQuat(0,0.5f); |
|
| 91 |
|
|
| 92 |
quatInt1.add(mQuat1); |
|
| 93 |
quatInt2.add(mQuat2); |
|
| 94 |
|
|
| 95 |
mAngle = new Static1D(0); |
|
| 96 |
|
|
| 97 |
mAngleDyn = new Dynamic1D(2000,0.5f); |
|
| 98 |
mAngleDyn.add(new Static1D(0)); |
|
| 99 |
mAngleDyn.add( mAngle ); |
|
| 100 |
|
|
| 101 |
mRotate = new VertexEffectRotate( mAngleDyn, new Static3D(1,0,0), new Static3D(0,0,0) ); |
|
| 102 |
|
|
| 103 |
mDisappear = new VertexEffectDisappear(); |
|
| 104 |
mDisappear.setMeshAssociation(0,-1); |
|
| 105 |
|
|
| 106 |
final float HALO_TO_RADIUS = 0.2f; |
|
| 107 |
Static2D haloRadius= new Static2D(25*HALO_TO_RADIUS,25); |
|
| 108 |
Static4D color = new Static4D(1.0f,0.0f,0.0f,0.5f); // half-transparent red |
|
| 109 |
|
|
| 110 |
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color); |
|
| 111 |
|
|
| 112 |
mEffects = new DistortedEffects(); |
|
| 113 |
mEffects.apply( mDisappear ); |
|
| 114 |
mEffects.apply( mRotate ); |
|
| 115 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) ); |
|
| 116 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
|
| 117 |
mEffects.apply( new MatrixEffectScale(mScale)); |
|
| 118 |
mEffects.apply(glow); |
|
| 119 |
|
|
| 120 |
mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
|
|
| 125 |
public void onDrawFrame(GL10 glUnused) |
|
| 126 |
{
|
|
| 127 |
mScreen.render( System.currentTimeMillis() ); |
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 131 |
|
|
| 132 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 133 |
{
|
|
| 134 |
final float SCALE = 0.4f; |
|
| 135 |
mScreenMin = Math.min(width, height); |
|
| 136 |
float factor = SCALE*mScreenMin; |
|
| 137 |
mScale.set(factor,factor,factor); |
|
| 138 |
mScreen.resize(width, height); |
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 142 |
|
|
| 143 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 144 |
{
|
|
| 145 |
if( mTexture==null ) mTexture = new DistortedTexture(); |
|
| 146 |
mTexture.setTexture( createTexture() ); |
|
| 147 |
|
|
| 148 |
if( mMesh==null ) mMesh = createMesh(1); // has to be <=FACE_COLORS.length; |
|
| 149 |
|
|
| 150 |
mScreen.detachAll(); |
|
| 151 |
mScreen.attach(mTexture,mEffects,mMesh); |
|
| 152 |
|
|
| 153 |
VertexEffectRotate.enable(); |
|
| 154 |
VertexEffectDisappear.enable(); |
|
| 155 |
PostprocessEffectGlow.enable(); |
|
| 156 |
|
|
| 157 |
DistortedLibrary.onSurfaceCreated(this); |
|
| 158 |
} |
|
| 159 |
|
|
| 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 161 |
|
|
| 162 |
void apply(int number) |
|
| 163 |
{
|
|
| 164 |
mRotate.setMeshAssociation(0,number); |
|
| 165 |
mAngle.set(360); |
|
| 166 |
mAngleDyn.resetToBeginning(); |
|
| 167 |
} |
|
| 168 |
|
|
| 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 170 |
|
|
| 171 |
void visible(boolean left) |
|
| 172 |
{
|
|
| 173 |
if( left ) |
|
| 174 |
{
|
|
| 175 |
mInvisibleLeft = !mInvisibleLeft; |
|
| 176 |
mDisappear.setMeshAssociation(0, mInvisibleLeft ? 0 : -1 ); |
|
| 177 |
} |
|
| 178 |
else |
|
| 179 |
{
|
|
| 180 |
mInvisibleRight= !mInvisibleRight; |
|
| 181 |
mDisappear.setMeshAssociation(0, mInvisibleRight ? 1 : -1 ); |
|
| 182 |
} |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
|
|
| 187 |
private MeshBase createMesh(int numMeshes) |
|
| 188 |
{
|
|
| 189 |
MeshBase[] meshes = new MeshTriangle[numMeshes]; |
|
| 190 |
VertexEffectMove[] moveEffect = new VertexEffectMove[numMeshes]; |
|
| 191 |
|
|
| 192 |
meshes[0] = new MeshTriangle(1); |
|
| 193 |
meshes[0].setEffectAssociation(0,1,0); |
|
| 194 |
|
|
| 195 |
for(int i=1; i<numMeshes; i++) |
|
| 196 |
{
|
|
| 197 |
meshes[i] = meshes[0].copy(true); |
|
| 198 |
meshes[i].setEffectAssociation(0,1,i); |
|
| 199 |
} |
|
| 200 |
|
|
| 201 |
Static4D[] textureMaps = new Static4D[numMeshes]; |
|
| 202 |
|
|
| 203 |
for(int i=0; i<numMeshes; i++) |
|
| 204 |
{
|
|
| 205 |
textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f); |
|
| 206 |
} |
|
| 207 |
|
|
| 208 |
MeshBase[] tmp = new MeshBase[2]; |
|
| 209 |
|
|
| 210 |
tmp[0] = new MeshJoined(meshes); |
|
| 211 |
|
|
| 212 |
for(int i=0; i<numMeshes; i++) |
|
| 213 |
{
|
|
| 214 |
Static3D mv = new Static3D(0,0, numMeshes>1 ? (0.5f-i/(numMeshes-1.0f)) : 0 ); |
|
| 215 |
moveEffect[i] = new VertexEffectMove(mv); |
|
| 216 |
moveEffect[i].setMeshAssociation(0,i); |
|
| 217 |
tmp[0].apply(moveEffect[i]); |
|
| 218 |
} |
|
| 219 |
|
|
| 220 |
tmp[1] = tmp[0].copy(true); |
|
| 221 |
|
|
| 222 |
tmp[0].mergeEffComponents(); |
|
| 223 |
tmp[1].mergeEffComponents(); |
|
| 224 |
|
|
| 225 |
tmp[0].setEffectAssociation(0,0,0); // set the equAssoc of the 0th (the only) component to 0 |
|
| 226 |
tmp[1].setEffectAssociation(0,0,1); // set the equAssoc of the 0th (the only) component to 1 |
|
| 227 |
|
|
| 228 |
MeshBase combined = new MeshJoined(tmp); |
|
| 229 |
|
|
| 230 |
MatrixEffectMove moveL = new MatrixEffectMove( new Static3D(-0.6f,0,0) ); |
|
| 231 |
MatrixEffectMove moveR = new MatrixEffectMove( new Static3D(+0.6f,0,0) ); |
|
| 232 |
|
|
| 233 |
combined.apply(moveL,0,0); |
|
| 234 |
combined.apply(moveR,0,1); |
|
| 235 |
|
|
| 236 |
combined.setTextureMap(textureMaps,0); |
|
| 237 |
combined.setTextureMap(textureMaps,numMeshes); |
|
| 238 |
|
|
| 239 |
combined.setComponentCenter(0,-0.6f,0,0); |
|
| 240 |
combined.setComponentCenter(1,+0.6f,0,0); |
|
| 241 |
|
|
| 242 |
return combined; |
|
| 243 |
} |
|
| 244 |
|
|
| 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 |
|
|
| 247 |
private Bitmap createTexture() |
|
| 248 |
{
|
|
| 249 |
final int FACES=FACE_COLORS.length; |
|
| 250 |
int SIZE = 200; |
|
| 251 |
float STROKE = 0.05f*SIZE; |
|
| 252 |
float OFF = STROKE/2 -1; |
|
| 253 |
float OFF2 = 0.5f*SIZE + OFF; |
|
| 254 |
float HEIGHT = SIZE - OFF; |
|
| 255 |
float RADIUS = SIZE/12.0f; |
|
| 256 |
float ARC1_H = 0.2f*SIZE; |
|
| 257 |
float ARC1_W = SIZE*0.5f; |
|
| 258 |
float ARC2_W = 0.153f*SIZE; |
|
| 259 |
float ARC2_H = 0.905f*SIZE; |
|
| 260 |
float ARC3_W = SIZE-ARC2_W; |
|
| 261 |
|
|
| 262 |
Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888); |
|
| 263 |
Canvas canvas = new Canvas(result); |
|
| 264 |
Paint paint = new Paint(); |
|
| 265 |
paint.setAntiAlias(true); |
|
| 266 |
paint.setStrokeWidth(STROKE); |
|
| 267 |
|
|
| 268 |
for(int i=0; i<FACES; i++) |
|
| 269 |
{
|
|
| 270 |
paint.setColor(FACE_COLORS[i]); |
|
| 271 |
paint.setStyle(Paint.Style.FILL); |
|
| 272 |
|
|
| 273 |
canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint); |
|
| 274 |
|
|
| 275 |
paint.setColor(0xff000000); |
|
| 276 |
paint.setStyle(Paint.Style.STROKE); |
|
| 277 |
|
|
| 278 |
canvas.drawLine( i*SIZE, HEIGHT, SIZE +i*SIZE, HEIGHT, paint); |
|
| 279 |
canvas.drawLine( OFF +i*SIZE, SIZE, OFF2 +i*SIZE, 0, paint); |
|
| 280 |
canvas.drawLine((SIZE-OFF)+i*SIZE, SIZE, (SIZE-OFF2) +i*SIZE, 0, paint); |
|
| 281 |
|
|
| 282 |
canvas.drawArc( ARC1_W-RADIUS+i*SIZE, ARC1_H-RADIUS, ARC1_W+RADIUS+i*SIZE, ARC1_H+RADIUS, 225, 90, false, paint); |
|
| 283 |
canvas.drawArc( ARC2_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC2_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 105, 90, false, paint); |
|
| 284 |
canvas.drawArc( ARC3_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC3_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 345, 90, false, paint); |
|
| 285 |
} |
|
| 286 |
|
|
| 287 |
return result; |
|
| 288 |
} |
|
| 289 |
|
|
| 290 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 291 |
|
|
| 292 |
public void distortedException(Exception ex) |
|
| 293 |
{
|
|
| 294 |
android.util.Log.e("TwoComponents", ex.getMessage() );
|
|
| 295 |
} |
|
| 296 |
|
|
| 297 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 298 |
|
|
| 299 |
public InputStream localFile(int fileID) |
|
| 300 |
{
|
|
| 301 |
return mResources.openRawResource(fileID); |
|
| 302 |
} |
|
| 303 |
|
|
| 304 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 305 |
|
|
| 306 |
public void logMessage(String message) |
|
| 307 |
{
|
|
| 308 |
android.util.Log.e("TwoComponents", message );
|
|
| 309 |
} |
|
| 310 |
} |
|
| src/main/java/org/distorted/examples/twocomponents/TwoComponentsSurfaceView.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2024 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.examples.twocomponents; |
|
| 21 |
|
|
| 22 |
import android.app.ActivityManager; |
|
| 23 |
import android.content.Context; |
|
| 24 |
import android.content.pm.ConfigurationInfo; |
|
| 25 |
import android.opengl.GLSurfaceView; |
|
| 26 |
import android.util.AttributeSet; |
|
| 27 |
import android.view.MotionEvent; |
|
| 28 |
|
|
| 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
class TwoComponentsSurfaceView extends GLSurfaceView |
|
| 32 |
{
|
|
| 33 |
private final static int DIRECTION_SENSITIVITY= 12; |
|
| 34 |
private int mX, mY; |
|
| 35 |
private TwoComponentsRenderer mRenderer; |
|
| 36 |
|
|
| 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 38 |
|
|
| 39 |
public TwoComponentsSurfaceView(Context context, AttributeSet attrs) |
|
| 40 |
{
|
|
| 41 |
super(context,attrs); |
|
| 42 |
|
|
| 43 |
mX = -1; |
|
| 44 |
mY = -1; |
|
| 45 |
|
|
| 46 |
if(!isInEditMode()) |
|
| 47 |
{
|
|
| 48 |
mRenderer = new TwoComponentsRenderer(this); |
|
| 49 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 50 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 51 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
| 52 |
setRenderer(mRenderer); |
|
| 53 |
} |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
public TwoComponentsRenderer getRenderer() |
|
| 59 |
{
|
|
| 60 |
return mRenderer; |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 64 |
|
|
| 65 |
private void resetQuats() |
|
| 66 |
{
|
|
| 67 |
float qx = mRenderer.mQuat1.get0(); |
|
| 68 |
float qy = mRenderer.mQuat1.get1(); |
|
| 69 |
float qz = mRenderer.mQuat1.get2(); |
|
| 70 |
float qw = mRenderer.mQuat1.get3(); |
|
| 71 |
|
|
| 72 |
float rx = mRenderer.mQuat2.get0(); |
|
| 73 |
float ry = mRenderer.mQuat2.get1(); |
|
| 74 |
float rz = mRenderer.mQuat2.get2(); |
|
| 75 |
float rw = mRenderer.mQuat2.get3(); |
|
| 76 |
|
|
| 77 |
// This is quaternion multiplication. (tx,ty,tz,tw) |
|
| 78 |
// is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw) |
|
| 79 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
| 80 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
| 81 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
| 82 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
| 83 |
|
|
| 84 |
// The point of this is so that there are always |
|
| 85 |
// exactly 2 quaternions: Quat1 representing the rotation |
|
| 86 |
// accumulating only since the last screen touch, and Quat2 |
|
| 87 |
// which remembers the combined effect of all previous |
|
| 88 |
// swipes. |
|
| 89 |
// We cannot be accumulating an ever-growing list of quaternions |
|
| 90 |
// and add a new one every time user swipes the screen - there |
|
| 91 |
// is a limited number of slots in the EffectQueueMatrix! |
|
| 92 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
| 93 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 97 |
|
|
| 98 |
@Override public boolean onTouchEvent(MotionEvent event) |
|
| 99 |
{
|
|
| 100 |
int action = event.getAction(); |
|
| 101 |
int x = (int)event.getX(); |
|
| 102 |
int y = (int)event.getY(); |
|
| 103 |
|
|
| 104 |
switch(action) |
|
| 105 |
{
|
|
| 106 |
case MotionEvent.ACTION_DOWN: mX = x; |
|
| 107 |
mY = y; |
|
| 108 |
break; |
|
| 109 |
|
|
| 110 |
case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 ) |
|
| 111 |
{
|
|
| 112 |
float px = mY-y; |
|
| 113 |
float py = mX-x; |
|
| 114 |
float pz = 0; |
|
| 115 |
float plen = (float)Math.sqrt(px*px + py*py + pz*pz); |
|
| 116 |
|
|
| 117 |
if( plen>0 ) |
|
| 118 |
{
|
|
| 119 |
px /= plen; |
|
| 120 |
py /= plen; |
|
| 121 |
pz /= plen; |
|
| 122 |
|
|
| 123 |
float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin); |
|
| 124 |
float sinA = (float)Math.sqrt(1-cosA*cosA); |
|
| 125 |
|
|
| 126 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA); |
|
| 127 |
} |
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) ) |
|
| 131 |
{
|
|
| 132 |
mX = x; |
|
| 133 |
mY = y; |
|
| 134 |
resetQuats(); |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
break; |
|
| 138 |
|
|
| 139 |
case MotionEvent.ACTION_UP : mX = -1; |
|
| 140 |
mY = -1; |
|
| 141 |
resetQuats(); |
|
| 142 |
break; |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
return true; |
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
} |
|
| 149 |
|
|
| src/main/res/layout/twocomponentslayout.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="fill_parent" |
|
| 4 |
android:layout_height="fill_parent" |
|
| 5 |
android:orientation="vertical" > |
|
| 6 |
|
|
| 7 |
<org.distorted.examples.twocomponents.TwoComponentsSurfaceView |
|
| 8 |
android:id="@+id/twocomponentsSurfaceView" |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="0dp" |
|
| 11 |
android:layout_weight="1" /> |
|
| 12 |
|
|
| 13 |
<LinearLayout |
|
| 14 |
android:orientation="horizontal" |
|
| 15 |
android:layout_width="match_parent" |
|
| 16 |
android:layout_height="wrap_content"> |
|
| 17 |
|
|
| 18 |
<Button |
|
| 19 |
android:id="@+id/twocomponentsButton0" |
|
| 20 |
android:layout_width="wrap_content" |
|
| 21 |
android:layout_height="match_parent" |
|
| 22 |
android:text="@string/rotate_left" |
|
| 23 |
android:onClick="onClick" |
|
| 24 |
android:layout_weight="1"/> |
|
| 25 |
<CheckBox |
|
| 26 |
android:id="@+id/twocomponentsCheckBox0" |
|
| 27 |
android:layout_width="wrap_content" |
|
| 28 |
android:layout_height="match_parent" |
|
| 29 |
android:text="" |
|
| 30 |
android:onClick="onVisible" |
|
| 31 |
android:layout_weight="1" |
|
| 32 |
android:checked="false"/> |
|
| 33 |
<Button |
|
| 34 |
android:id="@+id/twocomponentsButton1" |
|
| 35 |
android:layout_width="wrap_content" |
|
| 36 |
android:layout_height="match_parent" |
|
| 37 |
android:text="@string/rotate_right" |
|
| 38 |
android:onClick="onClick" |
|
| 39 |
android:layout_weight="1"/> |
|
| 40 |
<CheckBox |
|
| 41 |
android:id="@+id/twocomponentsCheckBox1" |
|
| 42 |
android:layout_width="wrap_content" |
|
| 43 |
android:layout_height="match_parent" |
|
| 44 |
android:text="" |
|
| 45 |
android:onClick="onVisible" |
|
| 46 |
android:layout_weight="1" |
|
| 47 |
android:checked="false"/> |
|
| 48 |
|
|
| 49 |
</LinearLayout> |
|
| 50 |
|
|
| 51 |
</LinearLayout> |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 217 | 217 |
<string name="example_meshfile_subtitle">Explore Distorted\'s own Mesh format, dmesh. Open .dmesh files and explore their contents.</string> |
| 218 | 218 |
<string name="example_flatblur">Flat Blur</string> |
| 219 | 219 |
<string name="example_flatblur_subtitle">Unit test to see two partially obstructing flat objects, one of them blurred.</string> |
| 220 |
<string name="example_polymesh">Polygon Mesh</string>
|
|
| 221 |
<string name="example_polymesh_subtitle">Test to be able to generate various polygon meshes with different parameters.</string>
|
|
| 220 |
<string name="example_twocomponents">Glow Part of Mesh</string>
|
|
| 221 |
<string name="example_twocomponents_subtitle">Attempt to apply a postprocess effect, GLOW, to only one vertex subcomponent of a Mesh.</string>
|
|
| 222 | 222 |
|
| 223 | 223 |
<string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string> |
| 224 | 224 |
<string name="example_rotate_toast">Rotate the scene by swiping the screen</string> |
Also available in: Unified diff
new app 'TwoComponents' : apply a postprocessing effect to only part of a Mesh (a single vertex component)