Project

General

Profile

« Previous | Next » 

Revision 815687bb

Added by Leszek Koltunski over 7 years ago

Progress with 'Wind'

View differences:

src/main/java/org/distorted/examples/wind/WindRenderer.java
29 29
import org.distorted.library.DistortedCubes;
30 30
import org.distorted.library.DistortedObject;
31 31
import org.distorted.library.EffectTypes;
32
import org.distorted.library.type.DynamicQuat;
32
import org.distorted.library.type.Static1D;
33 33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35 34

  
36 35
import java.io.IOException;
37 36
import java.io.InputStream;
......
45 44
{
46 45
   private GLSurfaceView mView;
47 46
   private DistortedObject mObject;
48
   private DynamicQuat mQuatInt1, mQuatInt2;
49
   private int mWind;
47
   private WindEffectsManager mEffects;
50 48
   private int mObjWidth, mObjHeight;
51 49

  
52
   Static4D mQuat1, mQuat2;
53
   int mScreenMin;
54

  
55 50
///////////////////////////////////////////////////////////////////////////////////////////////////
56 51

  
57 52
   WindRenderer(GLSurfaceView view)
......
59 54
      mView = view;
60 55

  
61 56
      mObject = new DistortedCubes(50,30,10,false);
57
      mEffects = new WindEffectsManager();
62 58

  
63 59
      mObjWidth = mObject.getWidth();
64 60
      mObjHeight= mObject.getHeight();
65

  
66
      mQuat1 = new Static4D(           0,         0,           0,          1);  // unity quaternion
67
      mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);  // something semi-random that looks good
68

  
69
      mQuatInt1 = new DynamicQuat(0,0.5f);
70
      mQuatInt2 = new DynamicQuat(0,0.5f);
71

  
72
      mQuatInt1.add(mQuat1);
73
      mQuatInt2.add(mQuat2);
74 61
      }
75 62

  
76 63
///////////////////////////////////////////////////////////////////////////////////////////////////
77 64

  
78 65
   void setWind(int wind)
79 66
      {
80
      mWind = wind;
67
      mEffects.apply(mObject,wind);
81 68
      }
82 69
   
83 70
///////////////////////////////////////////////////////////////////////////////////////////////////
......
94 81
    
95 82
   public void onSurfaceChanged(GL10 glUnused, int width, int height) 
96 83
      {
97
      mScreenMin = width<height ? width:height;
98

  
99 84
      mObject.abortEffects(EffectTypes.MATRIX);
100
      float factor;
85
      float factor = 0.8f*(width<height? width:height)/mObjWidth;
101 86

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

  
111
      mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
87
      mObject.move( new Static3D( (width-factor*mObjWidth)/2 + width/8 , (height-factor*mObjHeight)/2 -height/4 , 0) );
112 88
      mObject.scale(factor);
113
      Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0);
114 89

  
115
      mObject.quaternion(mQuatInt1, center);
116
      mObject.quaternion(mQuatInt2, center);
90
      Static1D angle = new Static1D(-45);
91
      Static3D axis  = new Static3D(0,0,1);
92
      Static3D center= new Static3D(0,mObjHeight/2,0);
93

  
94
      mObject.rotate(angle, axis, center);
117 95

  
118 96
      Distorted.onSurfaceChanged(width, height);
119 97
      }

Also available in: Unified diff