Project

General

Profile

« Previous | Next » 

Revision ea9b68db

Added by Leszek Koltunski about 4 years ago

Progress with MeshJoin app.
Fix rotating in some apps.

View differences:

src/main/java/org/distorted/examples/meshjoin/MeshJoinSurfaceView.java
29 29

  
30 30
class MeshJoinSurfaceView extends GLSurfaceView
31 31
{
32
    private final static int DIRECTION_SENSITIVITY=  12;
32 33
    private int mX, mY;
33 34
    private MeshJoinRenderer mRenderer;
34 35
	
......
56 57
      }
57 58

  
58 59
///////////////////////////////////////////////////////////////////////////////////////////////////
59
    
60

  
61
    private void resetQuats()
62
      {
63
      float qx = mRenderer.mQuat1.get0();
64
      float qy = mRenderer.mQuat1.get1();
65
      float qz = mRenderer.mQuat1.get2();
66
      float qw = mRenderer.mQuat1.get3();
67

  
68
      float rx = mRenderer.mQuat2.get0();
69
      float ry = mRenderer.mQuat2.get1();
70
      float rz = mRenderer.mQuat2.get2();
71
      float rw = mRenderer.mQuat2.get3();
72

  
73
       // This is quaternion multiplication. (tx,ty,tz,tw)
74
       // is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw)
75
       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
76
       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
77
       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
78
       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
79

  
80
       // The point of this is so that there are always
81
       // exactly 2 quaternions: Quat1 representing the rotation
82
       // accumulating only since the last screen touch, and Quat2
83
       // which remembers the combined effect of all previous
84
       // swipes.
85
       // We cannot be accumulating an ever-growing list of quaternions
86
       // and add a new one every time user swipes the screen - there
87
       // is a limited number of slots in the EffectQueueMatrix!
88
       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
89
       mRenderer.mQuat2.set(tx, ty, tz, tw);
90
       }
91

  
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

  
60 94
    @Override public boolean onTouchEvent(MotionEvent event) 
61 95
      {
62 96
      int action = event.getAction();
......
87 121
                                         
88 122
                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
89 123
                                           }
90
                                         }                             
124
                                         }
125

  
126
                                       if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
127
                                         {
128
                                         mX = x;
129
                                         mY = y;
130
                                         resetQuats();
131
                                         }
132

  
91 133
                                       break;
92 134
                                       
93 135
         case MotionEvent.ACTION_UP  : mX = -1;
94 136
                                       mY = -1;
95
        	                           
96
                                       float qx = mRenderer.mQuat1.get0();
97
                                       float qy = mRenderer.mQuat1.get1();
98
                                       float qz = mRenderer.mQuat1.get2();
99
                                       float qw = mRenderer.mQuat1.get3();
100

  
101
                                       float rx = mRenderer.mQuat2.get0();
102
                                       float ry = mRenderer.mQuat2.get1();
103
                                       float rz = mRenderer.mQuat2.get2();
104
                                       float rw = mRenderer.mQuat2.get3();
105

  
106
                                       // This is quaternion multiplication. (tx,ty,tz,tw)
107
                                       // is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw)
108
                                       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
109
                                       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
110
                                       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
111
                                       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
112

  
113
                                       // The point of this is so that there are always
114
                                       // exactly 2 quaternions: Quat1 representing the rotation
115
                                       // accumulating only since the last screen touch, and Quat2
116
                                       // which remembers the combined effect of all previous
117
                                       // swipes.
118
                                       // We cannot be accumulating an ever-growing list of quaternions
119
                                       // and add a new one every time user swipes the screen - there
120
                                       // is a limited number of slots in the EffectQueueMatrix!
121
                                       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
122
                                       mRenderer.mQuat2.set(tx, ty, tz, tw);
123
                                       
137
                                       resetQuats();
124 138
                                       break;
125 139
         }
126 140
             

Also available in: Unified diff