Project

General

Profile

« Previous | Next » 

Revision 550db260

Added by Leszek Koltunski over 2 years ago

Progress with BandagedCreator: joining cubits together. Still at least one (probably two) bugs here remain:

1) sometimes some of the walls of the newly creaed joined cubit are incorrectly rotated
2) there is an unpleasant flash when joining

View differences:

src/main/java/org/distorted/bandaged/BandagedCubit.java
36 36
{
37 37
    private static final Static3D CENTER = new Static3D(0,0,0);
38 38

  
39
    private final DistortedNode mNode;
39
    private DistortedNode mNode, mNewNode;
40 40
    private final DistortedTexture mTexture;
41 41
    private final DistortedEffects mEffects;
42
    private final MeshBase mMesh;
43
    private final float[] mPosition;
42
    private final Static3D mMove;
43

  
44
    private float mUnscaledX, mUnscaledY, mUnscaledZ;
45
    private float[] mPosition, mNewPosition;
44 46
    private boolean mIsAttached;
45 47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
    private void computeMove(float[] position)
51
      {
52
      int numCenters = position.length/3;
53
      mUnscaledX=0.0f;
54
      mUnscaledY=0.0f;
55
      mUnscaledZ=0.0f;
56

  
57
      for(int center=0; center<numCenters; center++)
58
        {
59
        mUnscaledX += position[3*center  ];
60
        mUnscaledY += position[3*center+1];
61
        mUnscaledZ += position[3*center+2];
62
        }
63

  
64
      mUnscaledX /= numCenters;
65
      mUnscaledY /= numCenters;
66
      mUnscaledZ /= numCenters;
67
      }
68

  
46 69
///////////////////////////////////////////////////////////////////////////////////////////////////
47 70
// PUBLIC API
48 71
///////////////////////////////////////////////////////////////////////////////////////////////////
49 72

  
50
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D move1, Static3D move2, Static3D scale, int color)
73
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D moveY, Static3D scale, int color)
51 74
      {
52 75
      mPosition = position;
53 76
      mIsAttached = true;
54 77

  
78
      computeMove(mPosition);
79
      mMove = new Static3D(0,0,0);
80

  
55 81
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
56
      mMesh = factory.createMesh(position);
82
      MeshBase mesh = factory.createMesh(mPosition);
57 83

  
58 84
      mTexture = new DistortedTexture();
59 85
      mTexture.setColorARGB(color);
......
61 87
      MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
62 88
      MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER);
63 89
      MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER);
64
      MatrixEffectMove move1Effect = new MatrixEffectMove(move1);
65
      MatrixEffectMove move2Effect = new MatrixEffectMove(move2);
90
      MatrixEffectMove moveSEffect = new MatrixEffectMove(mMove);
91
      MatrixEffectMove moveYEffect = new MatrixEffectMove(moveY);
66 92

  
67 93
      mEffects = new DistortedEffects();
68 94
      mEffects.apply(scaleEffect);
69
      mEffects.apply(move1Effect);
95
      mEffects.apply(moveSEffect);
70 96
      mEffects.apply(quat2Effect);
71 97
      mEffects.apply(quat1Effect);
72
      mEffects.apply(move2Effect);
98
      mEffects.apply(moveYEffect);
99

  
100
      mNode = new DistortedNode(mTexture,mEffects,mesh);
101
      }
102

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

  
105
    public void prepareJoin(float[] position)
106
      {
107
      int len1 = mPosition.length;
108
      int len2 = position.length;
109

  
110
      mNewPosition = new float[len1+len2];
73 111

  
74
      mNode = new DistortedNode(mTexture,mEffects,mMesh);
112
      System.arraycopy(mPosition, 0, mNewPosition,    0, len1);
113
      System.arraycopy(position , 0, mNewPosition, len1, len2);
114

  
115
/*
116
int l= mPosition.length/3;
117
String s="";
118
for(int i=0; i<l; i++) s += (mPosition[3*i]+" "+mPosition[3*i+1]+" "+mPosition[3*i+2]+"\n");
119
android.util.Log.e("D", "pos after joining: \n"+s);
120
*/
121
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
122
      MeshBase mesh = factory.createMesh(mNewPosition);
123
      mNewNode = new DistortedNode(mTexture,mEffects,mesh);
124

  
125
      computeMove(mNewPosition);
126
      }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
    public void swapNodes(float scale)
131
      {
132
      mPosition = mNewPosition;
133
      mNode = mNewNode;
134
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
135
      }
136

  
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

  
139
    public void scaleMove(float scale)
140
      {
141
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
75 142
      }
76 143

  
77 144
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff