Project

General

Profile

« Previous | Next » 

Revision 9aabc9eb

Added by Leszek Koltunski almost 3 years ago

Dynamics: introduce two speed modes - smooth and segment_constant.
Prepare the third mode - globally_constant.

View differences:

src/main/java/org/distorted/library/type/Dynamic3D.java
44 44
    curr = vv.elementAt(c);
45 45
    next = vv.elementAt(n);
46 46

  
47
    tmp1 = vc.elementAt(c);
47
    tmpCache1 = vc.elementAt(c);
48 48
    
49 49
    float px = curr.x - prev.x;
50 50
    float py = curr.y - prev.y;
......
61 61
      
62 62
      if( q>1 )
63 63
        {
64
        tmp1.tangent[0] = nx+px/q;
65
        tmp1.tangent[1] = ny+py/q;
66
        tmp1.tangent[2] = nz+pz/q;
64
        tmpCache1.velocity[0] = nx+px/q;
65
        tmpCache1.velocity[1] = ny+py/q;
66
        tmpCache1.velocity[2] = nz+pz/q;
67 67
        }
68 68
      else
69 69
        {
70
        tmp1.tangent[0] = px+nx*q;
71
        tmp1.tangent[1] = py+ny*q;
72
        tmp1.tangent[2] = pz+nz*q;
70
        tmpCache1.velocity[0] = px+nx*q;
71
        tmpCache1.velocity[1] = py+ny*q;
72
        tmpCache1.velocity[2] = pz+nz*q;
73 73
        }
74 74
      }
75 75
    else
76 76
      {
77
      tmp1.tangent[0] = 0.0f;
78
      tmp1.tangent[1] = 0.0f;
79
      tmp1.tangent[2] = 0.0f;
77
      tmpCache1.velocity[0] = 0.0f;
78
      tmpCache1.velocity[1] = 0.0f;
79
      tmpCache1.velocity[2] = 0.0f;
80 80
      }
81 81
    }
82 82
    
......
86 86
    {  
87 87
    if( numPoints==1 )
88 88
      {
89
      tmp1= vc.elementAt(0);
89
      tmpCache1 = vc.elementAt(0);
90 90
      curr= vv.elementAt(0);
91 91
        
92
      tmp1.a[0] = tmp1.a[1] = tmp1.a[2] = 0.0f;
93
      tmp1.b[0] = tmp1.b[1] = tmp1.b[2] = 0.0f;
94
      tmp1.c[0] = curr.x;
95
      tmp1.c[1] = curr.y;
96
      tmp1.c[2] = curr.z;
97
      tmp1.d[0] = tmp1.d[1] = tmp1.d[2] = 0.0f;
92
      tmpCache1.a[0] = tmpCache1.a[1] = tmpCache1.a[2] = 0.0f;
93
      tmpCache1.b[0] = tmpCache1.b[1] = tmpCache1.b[2] = 0.0f;
94
      tmpCache1.c[0] = curr.x;
95
      tmpCache1.c[1] = curr.y;
96
      tmpCache1.c[2] = curr.z;
97
      tmpCache1.d[0] = tmpCache1.d[1] = tmpCache1.d[2] = 0.0f;
98 98
      }
99 99
    else if( numPoints==2 )
100 100
      {
101
      tmp1= vc.elementAt(0);
102
      tmp2= vc.elementAt(1);
101
      tmpCache1 = vc.elementAt(0);
102
      tmpCache2 = vc.elementAt(1);
103 103
      curr= vv.elementAt(0);
104 104
      next= vv.elementAt(1);
105 105
          
106
      tmp1.a[0] = tmp1.a[1] = tmp1.a[2] = 0.0f;
107
      tmp1.b[0] = tmp1.b[1] = tmp1.b[2] = 0.0f;
108
      tmp1.c[0] = next.x - curr.x;
109
      tmp1.c[1] = next.y - curr.y;
110
      tmp1.c[2] = next.z - curr.z;
111
      tmp1.d[0] = curr.x;
112
      tmp1.d[1] = curr.y;
113
      tmp1.d[2] = curr.z;
106
      tmpCache1.a[0] = tmpCache1.a[1] = tmpCache1.a[2] = 0.0f;
107
      tmpCache1.b[0] = tmpCache1.b[1] = tmpCache1.b[2] = 0.0f;
108
      tmpCache1.c[0] = next.x - curr.x;
109
      tmpCache1.c[1] = next.y - curr.y;
110
      tmpCache1.c[2] = next.z - curr.z;
111
      tmpCache1.d[0] = curr.x;
112
      tmpCache1.d[1] = curr.y;
113
      tmpCache1.d[2] = curr.z;
114 114
      
115
      tmp2.a[0] = tmp2.a[1] = tmp2.a[2] = 0.0f;
116
      tmp2.b[0] = tmp2.b[1] = tmp2.b[2] = 0.0f;
117
      tmp2.c[0] = curr.x - next.x;
118
      tmp2.c[1] = curr.y - next.y;
119
      tmp2.c[2] = curr.z - next.z;
120
      tmp2.d[0] = next.x;
121
      tmp2.d[1] = next.y;
122
      tmp2.d[2] = next.z;
115
      tmpCache2.a[0] = tmpCache2.a[1] = tmpCache2.a[2] = 0.0f;
116
      tmpCache2.b[0] = tmpCache2.b[1] = tmpCache2.b[2] = 0.0f;
117
      tmpCache2.c[0] = curr.x - next.x;
118
      tmpCache2.c[1] = curr.y - next.y;
119
      tmpCache2.c[2] = curr.z - next.z;
120
      tmpCache2.d[0] = next.x;
121
      tmpCache2.d[1] = next.y;
122
      tmpCache2.d[2] = next.z;
123 123
      }
124 124
    else
125 125
      {
......
131 131
        {
132 132
        n = i<numPoints-1 ? i+1:0;  
133 133
      
134
        tmp1= vc.elementAt(i);
135
        tmp2= vc.elementAt(n);
134
        tmpCache1 = vc.elementAt(i);
135
        tmpCache2 = vc.elementAt(n);
136 136
        curr= vv.elementAt(i);
137 137
        next= vv.elementAt(n);
138 138
      
139
        tmp1.cached[0] = curr.x;
140
        tmp1.cached[1] = curr.y;
141
        tmp1.cached[2] = curr.z;
139
        tmpCache1.cached[0] = curr.x;
140
        tmpCache1.cached[1] = curr.y;
141
        tmpCache1.cached[2] = curr.z;
142 142
        
143
        tmp1.a[0] = mConvexity*( 2*curr.x +   tmp1.tangent[0] - 2*next.x + tmp2.tangent[0]);
144
        tmp1.b[0] = mConvexity*(-3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0]);
145
        tmp1.c[0] = mConvexity*(tmp1.tangent[0]) + (1.0f-mConvexity)*(next.x-curr.x);
146
        tmp1.d[0] = curr.x;
143
        tmpCache1.a[0] = mConvexity*( 2*curr.x +   tmpCache1.velocity[0] - 2*next.x + tmpCache2.velocity[0]);
144
        tmpCache1.b[0] = mConvexity*(-3*curr.x - 2* tmpCache1.velocity[0] + 3*next.x - tmpCache2.velocity[0]);
145
        tmpCache1.c[0] = mConvexity*(tmpCache1.velocity[0]) + (1.0f-mConvexity)*(next.x-curr.x);
146
        tmpCache1.d[0] = curr.x;
147 147
      
148
        tmp1.a[1] = mConvexity*( 2*curr.y +   tmp1.tangent[1] - 2*next.y + tmp2.tangent[1]);
149
        tmp1.b[1] = mConvexity*(-3*curr.y - 2*tmp1.tangent[1] + 3*next.y - tmp2.tangent[1]);
150
        tmp1.c[1] = mConvexity*(tmp1.tangent[1]) + (1.0f-mConvexity)*(next.y-curr.y);
151
        tmp1.d[1] = curr.y;
148
        tmpCache1.a[1] = mConvexity*( 2*curr.y +   tmpCache1.velocity[1] - 2*next.y + tmpCache2.velocity[1]);
149
        tmpCache1.b[1] = mConvexity*(-3*curr.y - 2* tmpCache1.velocity[1] + 3*next.y - tmpCache2.velocity[1]);
150
        tmpCache1.c[1] = mConvexity*(tmpCache1.velocity[1]) + (1.0f-mConvexity)*(next.y-curr.y);
151
        tmpCache1.d[1] = curr.y;
152 152
      
153
        tmp1.a[2] = mConvexity*( 2*curr.z +   tmp1.tangent[2] - 2*next.z + tmp2.tangent[2]);
154
        tmp1.b[2] = mConvexity*(-3*curr.z - 2*tmp1.tangent[2] + 3*next.z - tmp2.tangent[2]);
155
        tmp1.c[2] = mConvexity*(tmp1.tangent[2]) + (1.0f-mConvexity)*(next.z-curr.z);
156
        tmp1.d[2] = curr.z;
153
        tmpCache1.a[2] = mConvexity*( 2*curr.z +   tmpCache1.velocity[2] - 2*next.z + tmpCache2.velocity[2]);
154
        tmpCache1.b[2] = mConvexity*(-3*curr.z - 2* tmpCache1.velocity[2] + 3*next.z - tmpCache2.velocity[2]);
155
        tmpCache1.c[2] = mConvexity*(tmpCache1.velocity[2]) + (1.0f-mConvexity)*(next.z-curr.z);
156
        tmpCache1.d[2] = curr.z;
157

  
158
        if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) smoothOutSegment(tmpCache1);
157 159
        }
158 160
      }
159 161
   
......
499 501
                  {
500 502
                  int vecNext = getNext(vecCurr,t);
501 503
                  next = vv.elementAt(vecNext);
502
                  tmp2 = vc.elementAt(vecNext);
504
                  tmpCache2 = vc.elementAt(vecNext);
503 505

  
504
                  if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y || tmp2.cached[2]!=next.z ) recomputeCache();
506
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y || tmpCache2.cached[2]!=next.z ) recomputeCache();
505 507
                  }
506 508

  
507 509
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
508 510

  
509 511
                mSegment = segment;
510

  
511 512
                time = time-vecCurr;
512
            
513
                tmp1 = vc.elementAt(vecCurr);
513
                tmpCache1 = vc.elementAt(vecCurr);
514
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
514 515

  
515 516
                if( vn!=null )
516 517
                  {
517 518
                  time = noise(time,vecCurr);
518 519
              
519
                  computeOrthonormalBaseMore(time,tmp1);
520
                  computeOrthonormalBaseMore(time, tmpCache1);
520 521
                 
521
                  buffer[offset  ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0] + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1]);
522
                  buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1] + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1]);
523
                  buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2] + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1]);
522
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0] + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1]);
523
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1] + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1]);
524
                  buffer[offset+2]= ((tmpCache1.a[2]*time+ tmpCache1.b[2])*time+ tmpCache1.c[2])*time+ tmpCache1.d[2] + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1]);
524 525
                  }
525 526
                else
526 527
                  {
527
                  buffer[offset  ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
528
                  buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1];
529
                  buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2];
528
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0];
529
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1];
530
                  buffer[offset+2]= ((tmpCache1.a[2]*time+ tmpCache1.b[2])*time+ tmpCache1.c[2])*time+ tmpCache1.d[2];
530 531
                  }
531 532
               
532 533
                break;

Also available in: Unified diff