Revision 75173f81
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
|---|---|---|
| 35 | 35 |
|
| 36 | 36 |
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
| 37 | 37 |
{
|
| 38 |
private final BandagedCreatorView mView; |
|
| 39 |
private final DistortedScreen mScreen; |
|
| 40 |
private final Static3D mScale; |
|
| 41 |
private final BandagedCubit[] mCubits; |
|
| 42 |
private float mScaleValue; |
|
| 43 |
|
|
| 44 | 38 |
static final int COLOR_DEFAULT = 0xffffff55; |
| 45 | 39 |
static final int COLOR_MARKED = 0xffff0000; |
| 46 | 40 |
|
| ... | ... | |
| 77 | 71 |
{ 0.0f, -1.0f, -1.0f },
|
| 78 | 72 |
}; |
| 79 | 73 |
|
| 80 |
Static4D mQuat1, mQuat2; |
|
| 81 |
int mScreenMin; |
|
| 74 |
private final BandagedCreatorView mView; |
|
| 75 |
private final DistortedScreen mScreen; |
|
| 76 |
private final Static3D mScale; |
|
| 77 |
private final BandagedCubit[] mCubits; |
|
| 78 |
private final Static4D mQuat1, mQuat2; |
|
| 79 |
private float mScaleValue; |
|
| 80 |
|
|
| 81 |
private float mX, mY, mZ, mW; |
|
| 82 |
private boolean mResetQuats, mSetQuat1; |
|
| 82 | 83 |
|
| 83 | 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 84 | 85 |
|
| ... | ... | |
| 91 | 92 |
|
| 92 | 93 |
mView = v; |
| 93 | 94 |
|
| 95 |
mResetQuats = false; |
|
| 96 |
mSetQuat1 = false; |
|
| 97 |
|
|
| 94 | 98 |
mScreen = new DistortedScreen(); |
| 95 | 99 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
| 96 | 100 |
mScale = new Static3D(1,1,1); |
| ... | ... | |
| 119 | 123 |
{
|
| 120 | 124 |
long time = System.currentTimeMillis(); |
| 121 | 125 |
mScreen.render(time); |
| 126 |
|
|
| 127 |
if( mSetQuat1 ) |
|
| 128 |
{
|
|
| 129 |
mSetQuat1 = false; |
|
| 130 |
mQuat1.set(mX,mY,mZ,mW); |
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
if( mResetQuats ) |
|
| 134 |
{
|
|
| 135 |
mResetQuats = false; |
|
| 136 |
|
|
| 137 |
float qx = mQuat1.get0(); |
|
| 138 |
float qy = mQuat1.get1(); |
|
| 139 |
float qz = mQuat1.get2(); |
|
| 140 |
float qw = mQuat1.get3(); |
|
| 141 |
|
|
| 142 |
float rx = mQuat2.get0(); |
|
| 143 |
float ry = mQuat2.get1(); |
|
| 144 |
float rz = mQuat2.get2(); |
|
| 145 |
float rw = mQuat2.get3(); |
|
| 146 |
|
|
| 147 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
| 148 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
| 149 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
| 150 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
| 151 |
|
|
| 152 |
mQuat1.set(0f, 0f, 0f, 1f); |
|
| 153 |
mQuat2.set(tx, ty, tz, tw); |
|
| 154 |
} |
|
| 122 | 155 |
} |
| 123 | 156 |
|
| 124 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 142 | 175 |
} |
| 143 | 176 |
|
| 144 | 177 |
mScale.set( mScaleValue,mScaleValue,mScaleValue ); |
| 145 |
mScreenMin = Math.min(width, height); |
|
| 146 | 178 |
mView.setScreenSize(width,height); |
| 147 | 179 |
mScreen.resize(width,height); |
| 148 | 180 |
} |
| ... | ... | |
| 213 | 245 |
} |
| 214 | 246 |
} |
| 215 | 247 |
} |
| 248 |
|
|
| 249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 250 |
|
|
| 251 |
public Static4D getQuat2() |
|
| 252 |
{
|
|
| 253 |
return mQuat2; |
|
| 254 |
} |
|
| 255 |
|
|
| 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 257 |
|
|
| 258 |
public void setQuat1(float x, float y, float z, float w) |
|
| 259 |
{
|
|
| 260 |
mX = x; |
|
| 261 |
mY = y; |
|
| 262 |
mZ = z; |
|
| 263 |
mW = w; |
|
| 264 |
|
|
| 265 |
mSetQuat1 = true; |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 269 |
|
|
| 270 |
public void resetQuats() |
|
| 271 |
{
|
|
| 272 |
mResetQuats = true; |
|
| 273 |
} |
|
| 216 | 274 |
} |
| src/main/java/org/distorted/bandaged/BandagedCreatorView.java | ||
|---|---|---|
| 36 | 36 |
public class BandagedCreatorView extends GLSurfaceView |
| 37 | 37 |
{
|
| 38 | 38 |
private final static int DIRECTION_SENSITIVITY= 12; |
| 39 |
private int mX, mY; |
|
| 40 |
private int mTouchedIndex1, mTouchedIndex2; |
|
| 39 |
|
|
| 41 | 40 |
private BandagedCreatorRenderer mRenderer; |
| 42 | 41 |
private BandagedTouchControl mTouchControl; |
| 43 |
private int mScreenWidth, mScreenHeight; |
|
| 42 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
|
| 43 |
private int mTouchedIndex1, mTouchedIndex2; |
|
| 44 |
private int mX, mY; |
|
| 44 | 45 |
|
| 45 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 | 47 |
// PUBLIC API |
| ... | ... | |
| 92 | 93 |
} |
| 93 | 94 |
} |
| 94 | 95 |
|
| 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 96 |
|
|
| 97 |
private void resetQuats() |
|
| 98 |
{
|
|
| 99 |
float qx = mRenderer.mQuat1.get0(); |
|
| 100 |
float qy = mRenderer.mQuat1.get1(); |
|
| 101 |
float qz = mRenderer.mQuat1.get2(); |
|
| 102 |
float qw = mRenderer.mQuat1.get3(); |
|
| 103 |
|
|
| 104 |
float rx = mRenderer.mQuat2.get0(); |
|
| 105 |
float ry = mRenderer.mQuat2.get1(); |
|
| 106 |
float rz = mRenderer.mQuat2.get2(); |
|
| 107 |
float rw = mRenderer.mQuat2.get3(); |
|
| 108 |
|
|
| 109 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
| 110 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
| 111 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
| 112 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
| 113 |
|
|
| 114 |
mRenderer.mQuat1.set(0f, 0f, 0f, 1f); |
|
| 115 |
mRenderer.mQuat2.set(tx, ty, tz, tw); |
|
| 116 |
} |
|
| 117 |
|
|
| 118 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 119 | 97 |
|
| 120 | 98 |
public void setScreenSize(int width, int height) |
| 121 | 99 |
{
|
| 122 | 100 |
mScreenWidth = width; |
| 123 | 101 |
mScreenHeight= height; |
| 102 |
mScreenMin = Math.min(width, height); |
|
| 124 | 103 |
} |
| 125 | 104 |
|
| 126 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 134 | 113 |
|
| 135 | 114 |
switch(action) |
| 136 | 115 |
{
|
| 137 |
case MotionEvent.ACTION_DOWN: float x1 = (x - mScreenWidth*0.5f)/mRenderer.mScreenMin;
|
|
| 138 |
float y1 = (mScreenHeight*0.5f - y)/mRenderer.mScreenMin;
|
|
| 116 |
case MotionEvent.ACTION_DOWN: float x1 = (x - mScreenWidth*0.5f)/mScreenMin; |
|
| 117 |
float y1 = (mScreenHeight*0.5f - y)/mScreenMin; |
|
| 139 | 118 |
|
| 140 |
int index = mTouchControl.cubitTouched(x1,y1,mRenderer.mQuat2);
|
|
| 119 |
int index = mTouchControl.cubitTouched(x1,y1,mRenderer.getQuat2() );
|
|
| 141 | 120 |
|
| 142 | 121 |
if( index<0 ) |
| 143 | 122 |
{
|
| ... | ... | |
| 180 | 159 |
py /= plen; |
| 181 | 160 |
pz /= plen; |
| 182 | 161 |
|
| 183 |
float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
|
|
| 162 |
float cosA = (float)Math.cos(plen*3.14f/mScreenMin); |
|
| 184 | 163 |
float sinA = (float)Math.sqrt(1-cosA*cosA); |
| 185 | 164 |
|
| 186 |
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
|
|
| 165 |
mRenderer.setQuat1(px*sinA, py*sinA, pz*sinA, cosA);
|
|
| 187 | 166 |
} |
| 188 | 167 |
} |
| 189 |
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
|
|
| 168 |
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mScreenMin*mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
|
|
| 190 | 169 |
{
|
| 191 | 170 |
mX = x; |
| 192 | 171 |
mY = y; |
| 193 |
resetQuats(); |
|
| 172 |
mRenderer.resetQuats();
|
|
| 194 | 173 |
} |
| 195 | 174 |
break; |
| 196 | 175 |
|
| ... | ... | |
| 208 | 187 |
mX = -1; |
| 209 | 188 |
mY = -1; |
| 210 | 189 |
|
| 211 |
resetQuats(); |
|
| 190 |
mRenderer.resetQuats();
|
|
| 212 | 191 |
break; |
| 213 | 192 |
} |
| 214 | 193 |
|
Also available in: Unified diff
Further progress with Bandaged 3x3: correct rotation of the collection of BandagedCubits.