Project

General

Profile

« Previous | Next » 

Revision e6129574

Added by Leszek Koltunski over 4 years ago

Progress with the Predeform app; deepCopy for the Meshes; various fixes.

View differences:

src/main/java/org/distorted/examples/predeform/PredeformActivity.java
34 34
import org.distorted.library.effect.Effect;
35 35
import org.distorted.library.effect.EffectName;
36 36
import org.distorted.library.effect.EffectType;
37
import org.distorted.library.effect.VertexEffect;
37 38
import org.distorted.library.type.Static4D;
38 39

  
39 40
import java.util.ArrayList;
......
230 231

  
231 232
    Effect effect = eff.createEffect();
232 233

  
233
    PredeformEffectList.addNew(effect);
234
    PredeformEffectList.addNew( (VertexEffect)effect );
234 235
    }
235 236

  
236 237
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/predeform/PredeformActivity2.java
119 119
    public void showNormal(View view)
120 120
      {
121 121
      CheckBox box = (CheckBox)view;
122
      boolean showNormal = box.isChecked();
122
      boolean show = box.isChecked();
123 123

  
124
      if ( mMesh!=null )
125
        {
126
        mMesh.setShowNormals(showNormal);
127
        }
124
      PredeformSurfaceView v = findViewById(R.id.predeformSurfaceView);
125
      PredeformRenderer renderer = v.getRenderer();
126

  
127
      renderer.showNormal(show);
128 128
      }
129 129

  
130 130
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/predeform/PredeformEffectList.java
19 19

  
20 20
package org.distorted.examples.predeform;
21 21

  
22
import org.distorted.library.effect.Effect;
22
import org.distorted.library.effect.VertexEffect;
23 23

  
24 24
import java.util.ArrayList;
25 25

  
......
27 27

  
28 28
public class PredeformEffectList
29 29
  {
30
  private static ArrayList<Effect> mList = new ArrayList<>();
30
  private static ArrayList<VertexEffect> mList = new ArrayList<>();
31 31

  
32 32
///////////////////////////////////////////////////////////////////////////////////////////////////
33 33

  
34
  static void addNew(Effect effect)
34
  static void addNew(VertexEffect effect)
35 35
    {
36 36
    mList.add(effect);
37 37
    }
......
48 48
  static void remove(long id)
49 49
    {
50 50
    int size = mList.size();
51
    Effect effect;
51
    VertexEffect effect;
52 52

  
53 53
    for (int i=0; i<size; i++)
54 54
      {
......
64 64

  
65 65
///////////////////////////////////////////////////////////////////////////////////////////////////
66 66

  
67
  static ArrayList<Effect> getEffectList()
67
  static ArrayList<VertexEffect> getEffectList()
68 68
    {
69 69
    return mList;
70 70
    }
src/main/java/org/distorted/examples/predeform/PredeformRenderer.java
21 21

  
22 22
import android.opengl.GLSurfaceView;
23 23

  
24
import org.distorted.library.effect.FragmentEffectAlpha;
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.MatrixEffectMove;
25 26
import org.distorted.library.effect.MatrixEffectQuaternion;
26 27
import org.distorted.library.effect.MatrixEffectScale;
28
import org.distorted.library.effect.VertexEffect;
29
import org.distorted.library.effect.Effect;
27 30
import org.distorted.library.effect.VertexEffectScale;
28 31
import org.distorted.library.main.DistortedEffects;
29 32
import org.distorted.library.main.DistortedLibrary;
......
34 37
import org.distorted.library.type.Static3D;
35 38
import org.distorted.library.type.Static4D;
36 39

  
40
import java.util.ArrayList;
41

  
37 42
import javax.microedition.khronos.egl.EGLConfig;
38 43
import javax.microedition.khronos.opengles.GL10;
39 44

  
......
46 51

  
47 52
    private GLSurfaceView mView;
48 53
    private DistortedTexture mTexture;
49
    private DistortedEffects mEffects;
50
    private MeshBase mMesh;
54
    private DistortedEffects mEffects1, mEffects2;
55
    private MeshBase mMesh1, mMesh2;
51 56
    private DistortedScreen mScreen;
52 57
    private float mObjWidth, mObjHeight, mObjDepth;
53
    private Static3D mScale;
58
    private Static3D mScale, mMove1, mMove2;
54 59

  
55 60
    Static4D mQuat1, mQuat2;
56 61
    int mScreenMin;
......
62 67
      mView = v;
63 68

  
64 69
      mScale= new Static3D(1,1,1);
70
      mMove1= new Static3D(0,0,0);
71
      mMove2= new Static3D(0,0,0);
65 72

  
66 73
      Static3D center=new Static3D(0,0,0);
67 74

  
68 75
      PredeformActivity2 act = (PredeformActivity2)v.getContext();
69 76

  
70 77
      mTexture = act.getTexture();
71
      mMesh    = act.getMesh();
78
      mMesh1   = act.getMesh();
79
      mMesh2   = mMesh1.deepCopy();
72 80

  
73 81
      mObjWidth = act.getCols();
74 82
      mObjHeight= act.getRows();
......
83 91
      quatInt1.add(mQuat1);
84 92
      quatInt2.add(mQuat2);
85 93

  
86
      mEffects = new DistortedEffects();
87
      mEffects.apply( new VertexEffectScale(new Static3D(mObjWidth,mObjHeight,mObjDepth) ) );
88
      mEffects.apply( new MatrixEffectScale(mScale));
89
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
90
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
94
      ArrayList<VertexEffect> effectList = PredeformEffectList.getEffectList();
95
      int numEffects = effectList.size();
96

  
97
      for(int i=0; i<numEffects; i++)
98
        {
99
        mMesh2.apply(effectList.get(i));
100
        }
101

  
102
      mEffects1 = new DistortedEffects();
103
      mEffects1.apply( new VertexEffectScale(new Static3D(mObjWidth,mObjHeight,mObjDepth) ) );
104

  
105
      for(int i=0; i<numEffects; i++)
106
        {
107
        mEffects1.apply(effectList.get(i));
108
        }
109

  
110
      mEffects1.apply( new MatrixEffectScale(mScale));
111
      mEffects1.apply( new MatrixEffectQuaternion(quatInt2, center) );
112
      mEffects1.apply( new MatrixEffectQuaternion(quatInt1, center) );
113
      mEffects1.apply( new MatrixEffectMove(mMove1));
114

  
115
      mEffects2 = new DistortedEffects();
116
      mEffects2.apply( new VertexEffectScale(new Static3D(mObjWidth,mObjHeight,mObjDepth) ) );
117
      mEffects2.apply( new MatrixEffectScale(mScale));
118
      mEffects2.apply( new MatrixEffectQuaternion(quatInt2, center) );
119
      mEffects2.apply( new MatrixEffectQuaternion(quatInt1, center) );
120
      mEffects2.apply( new MatrixEffectMove(mMove2));
91 121

  
92 122
      mScreen = new DistortedScreen();
93 123
      mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
......
105 135
    
106 136
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
107 137
      {
108
      final float SCALE = 0.75f;
138
      final float SCALE = 0.6f;
139

  
140
      if( width<height )
141
        {
142
        float factor = SCALE*(Math.min(width/mObjWidth, 0.5f*height/mObjHeight));
143
        mScale.set(factor,factor,factor);
144
        mMove1.set(0,+height*0.25f,0);
145
        mMove2.set(0,-height*0.25f,0);
146
        }
147
      else
148
        {
149
        float factor = SCALE*(Math.min( 0.5f*width/mObjWidth, height/mObjHeight));
150
        mScale.set(factor,factor,factor);
151
        mMove1.set(+width*0.25f,0,0);
152
        mMove2.set(-width*0.25f,0,0);
153
        }
109 154

  
110 155
      mScreenMin = Math.min(width, height);
111
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight :  (SCALE*width)/mObjWidth;
112
      mScale.set(factor,factor,factor);
113 156
      mScreen.resize(width, height);
114 157
      }
115 158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161
    void showNormal(boolean show)
162
      {
163
      mMesh1.setShowNormals(show);
164
      mMesh2.setShowNormals(show);
165
      }
166

  
116 167
///////////////////////////////////////////////////////////////////////////////////////////////////
117 168

  
118 169
    float setLevel(int level)
119 170
      {
120 171
      float inflateLevel = (level-50)/50.0f;
121
      mMesh.setInflate(inflateLevel);
172
      mMesh1.setInflate(inflateLevel);
173
      mMesh2.setInflate(inflateLevel);
122 174

  
123 175
      return inflateLevel;
124 176
      }
......
131 183

  
132 184
      mTexture.setTexture( act.getBitmap() );
133 185
      mScreen.detachAll();
134
      mScreen.attach(mTexture,mEffects,mMesh);
186
      mScreen.attach(mTexture,mEffects1,mMesh1);
187
      mScreen.attach(mTexture,mEffects2,mMesh2);
135 188

  
136
      VertexEffectScale.enable();
137
      FragmentEffectAlpha.enable();
189
      Effect.enableEffects(EffectType.VERTEX);
138 190

  
139 191
      try
140 192
        {

Also available in: Unified diff