Project

General

Profile

« Previous | Next » 

Revision 37b324c4

Added by Leszek Koltunski almost 7 years ago

Further progress with Apps.

View differences:

src/main/java/org/distorted/examples/cubes/CubesRenderer.java
27 27

  
28 28
import org.distorted.examples.R;
29 29

  
30
import org.distorted.library.effect.MatrixEffectMove;
31
import org.distorted.library.effect.MatrixEffectQuaternion;
32
import org.distorted.library.effect.MatrixEffectScale;
30 33
import org.distorted.library.main.DistortedEffects;
31 34
import org.distorted.library.main.DistortedScreen;
32 35
import org.distorted.library.main.DistortedTexture;
33 36
import org.distorted.library.main.MeshObject;
34
import org.distorted.library.EffectTypes;
35 37
import org.distorted.library.type.DynamicQuat;
36 38
import org.distorted.library.type.Static4D;
37 39
import org.distorted.library.type.Static3D;
......
50 52
    private DistortedEffects mEffects;
51 53
    private MeshObject mMesh;
52 54
    private DistortedScreen mScreen;
53
    private DynamicQuat mQuatInt1, mQuatInt2;
54 55
    private int mObjWidth, mObjHeight, mObjDepth;
56
    private Static3D mMove, mScale, mCenter;
55 57

  
56 58
    Static4D mQuat1, mQuat2;
57 59
    int mScreenMin;
......
62 64
      {
63 65
      mView = v;
64 66

  
67
      mMove = new Static3D(0,0,0);
68
      mScale= new Static3D(1,1,1);
69
      mCenter=new Static3D(0,0,0);
70

  
65 71
      CubesActivity act = (CubesActivity)v.getContext();
66 72

  
67
      mEffects = new DistortedEffects();
68 73
      mTexture = act.getTexture();
69 74
      mMesh = act.getMesh();
70 75

  
......
75 80
      mQuat1 = new Static4D(0,0,0,1);  // unity
76 81
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
77 82
      
78
      mQuatInt1 = new DynamicQuat(0,0.5f);
79
      mQuatInt2 = new DynamicQuat(0,0.5f);
83
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
84
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
85

  
86
      quatInt1.add(mQuat1);
87
      quatInt2.add(mQuat2);
80 88

  
81
      mQuatInt1.add(mQuat1);
82
      mQuatInt2.add(mQuat2);
89
      mEffects = new DistortedEffects();
90
      mEffects.apply( new MatrixEffectMove(mMove) );
91
      mEffects.apply( new MatrixEffectScale(mScale));
92
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
93
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
83 94

  
84 95
      mScreen = new DistortedScreen(mView);
85 96
      }
......
96 107
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
97 108
      {
98 109
      mScreenMin = width<height ? width:height;
99
    	
100
      mEffects.abortEffects(EffectTypes.MATRIX);
101
      float factor;
102

  
103
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
104
        {
105
        factor = (0.75f*height)/mObjHeight;
106
        }
107
      else
108
        {
109
        factor = (0.75f*width)/mObjWidth;
110
        }
111

  
112
      mEffects.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
113
      mEffects.scale(factor);
114
      Static3D center = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
115

  
116
      mEffects.quaternion(mQuatInt1, center);
117
      mEffects.quaternion(mQuatInt2, center);
118
       
110
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.75f*height)/mObjHeight :  (0.75f*width)/mObjWidth;
111
      mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
112
      mScale.set(factor,factor,factor);
113
      mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
119 114
      mScreen.resize(width, height);
120 115
      }
121 116

  

Also available in: Unified diff