| .. | .. | 
|---|
| 26 | 26 |  public class Mocap extends Object3D | 
|---|
| 27 | 27 |  { | 
|---|
| 28 | 28 |      static final long serialVersionUID = 7437391692559853707L; | 
|---|
 | 29 | +  | 
|---|
 | 30 | +    void Fade()  | 
|---|
 | 31 | +    {  | 
|---|
 | 32 | +        if (true) // currentbones == null || CameraPane.fullreset)  | 
|---|
 | 33 | +            return;  | 
|---|
 | 34 | +          | 
|---|
 | 35 | +        cVector temp = new cVector();  | 
|---|
 | 36 | +  | 
|---|
 | 37 | +        int numframes = bvh.animation.getNumFrames();  | 
|---|
 | 38 | +          | 
|---|
 | 39 | +        int b;  | 
|---|
 | 40 | +        float[] data;  | 
|---|
 | 41 | +        Quat4d quatstart = new Quat4d();  | 
|---|
 | 42 | +        Quat4d quatend = new Quat4d();  | 
|---|
 | 43 | +        Quat4d quat = new Quat4d();  | 
|---|
 | 44 | +        Matrix4d mat4d = new Matrix4d();  | 
|---|
 | 45 | +        double[][] rot = new double[4][4];  | 
|---|
 | 46 | +        for (b=numbones; --b>=0;) // HIP ROTATION: 0;)  | 
|---|
 | 47 | +        {  | 
|---|
 | 48 | +            // int hipindex = get(0)._index;  | 
|---|
 | 49 | +  | 
|---|
 | 50 | +//                        assert(get(0).get(0)._isHip);  | 
|---|
 | 51 | +  | 
|---|
 | 52 | +  //          if (b == hipindex)  | 
|---|
 | 53 | +  //              continue;  | 
|---|
 | 54 | +  | 
|---|
 | 55 | +            data = bvh.animation.getBoneData(b);  | 
|---|
 | 56 | +  | 
|---|
 | 57 | +            int dof = 3; // data.length/numframes;  | 
|---|
 | 58 | +  | 
|---|
 | 59 | +            if (b == 0)  | 
|---|
 | 60 | +            {  | 
|---|
 | 61 | +                dof = 6;  | 
|---|
 | 62 | +            }  | 
|---|
 | 63 | +          //  assert(dof == 3);  | 
|---|
 | 64 | +  | 
|---|
 | 65 | +            int boneframe3 = (b-1)*3; // dof;  | 
|---|
 | 66 | +  | 
|---|
 | 67 | +         //   System.err.println("Bone #" + b + ": dof = " + dof);  | 
|---|
 | 68 | +            int fadein = 45; // 120;  | 
|---|
 | 69 | +  | 
|---|
 | 70 | +        //    if (b == hipindex)  | 
|---|
 | 71 | +        //        fadein *= 5;  | 
|---|
 | 72 | +  | 
|---|
 | 73 | +            if (fadein > numframes)  | 
|---|
 | 74 | +                fadein = 0; // numframes;  | 
|---|
 | 75 | +  | 
|---|
 | 76 | +            for (int fi=fadein; --fi>=0;)  | 
|---|
 | 77 | +            //for (int f=numframes; --f>=0;)  | 
|---|
 | 78 | +            {  | 
|---|
 | 79 | +                int f = fi + GetFirstFrame();  | 
|---|
 | 80 | +  | 
|---|
 | 81 | +                int f3 = f*dof;  | 
|---|
 | 82 | +  | 
|---|
 | 83 | +                float k = fi;  | 
|---|
 | 84 | +  | 
|---|
 | 85 | +                k /= fadein - 1;  | 
|---|
 | 86 | +  | 
|---|
 | 87 | +                if (Float.isNaN(k))  | 
|---|
 | 88 | +                    k = 1; // 0/0  | 
|---|
 | 89 | +  | 
|---|
 | 90 | +                k = (float) (-Math.cos(k*Math.PI));  | 
|---|
 | 91 | +                k += 1;  | 
|---|
 | 92 | +                k /= 2;  | 
|---|
 | 93 | +  | 
|---|
 | 94 | +                int start = 3;  | 
|---|
 | 95 | +                int end = 0;  | 
|---|
 | 96 | +  | 
|---|
 | 97 | +                if (dof == 6)  | 
|---|
 | 98 | +                {  | 
|---|
 | 99 | +                    start = 6;  | 
|---|
 | 100 | +                    end = 3;  | 
|---|
 | 101 | +                }  | 
|---|
 | 102 | +  | 
|---|
 | 103 | +                if (b == 0)  | 
|---|
 | 104 | +                {  | 
|---|
 | 105 | +                    for (int i=start; --i>=end;)  | 
|---|
 | 106 | +                    {  | 
|---|
 | 107 | +                        //data[f3 + i] += pos[i] - data[frame3 + i];  | 
|---|
 | 108 | +//                                data[f3 + i] = k*data[f3+i] + (1-k)*  | 
|---|
 | 109 | +//                                        currentbones[boneframe3 + i-end];  | 
|---|
 | 110 | +                        data[f3 + i] = (float)CurveAngle(data[f3+i], currenthip[i], 1-k);  | 
|---|
 | 111 | +                    }  | 
|---|
 | 112 | +                      | 
|---|
 | 113 | +                    // TODO: translation  | 
|---|
 | 114 | +                      | 
|---|
 | 115 | +//                    _t1.setIdentity();  | 
|---|
 | 116 | +//                    _t2.setIdentity();  | 
|---|
 | 117 | +//                    _t2.rotZ(currentbones[boneframe3 + start-1-end]);  | 
|---|
 | 118 | +//                    _t1.mul(_t2);  | 
|---|
 | 119 | +//                    _t2.setIdentity();  | 
|---|
 | 120 | +//                    if (b == 0)  | 
|---|
 | 121 | +//                    {  | 
|---|
 | 122 | +//                        _t2.rotY(currentbones[boneframe3 + start-2-end]);  | 
|---|
 | 123 | +//                        _t1.mul(_t2);  | 
|---|
 | 124 | +//                        _t2.setIdentity();  | 
|---|
 | 125 | +//                        _t2.rotX(currentbones[boneframe3 + start-3-end]);  | 
|---|
 | 126 | +//                    }  | 
|---|
 | 127 | +//                    else  | 
|---|
 | 128 | +//                    {  | 
|---|
 | 129 | +//                        _t2.rotX(currentbones[boneframe3 + start-2-end]);  | 
|---|
 | 130 | +//                        _t1.mul(_t2);  | 
|---|
 | 131 | +//                        _t2.setIdentity();  | 
|---|
 | 132 | +//                        _t2.rotY(currentbones[boneframe3 + start-3-end]);  | 
|---|
 | 133 | +//                    }  | 
|---|
 | 134 | +//                    _t1.mul(_t2);  | 
|---|
 | 135 | +//                    _t2.setIdentity();  | 
|---|
 | 136 | +//  | 
|---|
 | 137 | +//                    _t1.get(mat4d);  | 
|---|
 | 138 | +//  | 
|---|
 | 139 | +//                    mat4d.get(quatstart);  | 
|---|
 | 140 | +//  | 
|---|
 | 141 | +//                    _t1.setIdentity();  | 
|---|
 | 142 | +//                    _t2.setIdentity();  | 
|---|
 | 143 | +//                    _t2.rotZ(data[f3 + start-1]);  | 
|---|
 | 144 | +//                    _t1.mul(_t2);  | 
|---|
 | 145 | +//                    _t2.setIdentity();  | 
|---|
 | 146 | +//                    if (b == 0)  | 
|---|
 | 147 | +//                    {  | 
|---|
 | 148 | +//                        _t2.rotY(data[f3 + start-2]);  | 
|---|
 | 149 | +//                        _t1.mul(_t2);  | 
|---|
 | 150 | +//                        _t2.setIdentity();  | 
|---|
 | 151 | +//                        _t2.rotX(data[f3 + start-3]);  | 
|---|
 | 152 | +//                    }  | 
|---|
 | 153 | +//                    else  | 
|---|
 | 154 | +//                    {  | 
|---|
 | 155 | +//                        _t2.rotX(data[f3 + start-2]);  | 
|---|
 | 156 | +//                        _t1.mul(_t2);  | 
|---|
 | 157 | +//                        _t2.setIdentity();  | 
|---|
 | 158 | +//                        _t2.rotY(data[f3 + start-3]);  | 
|---|
 | 159 | +//                    }  | 
|---|
 | 160 | +//  | 
|---|
 | 161 | +//                    _t1.mul(_t2);  | 
|---|
 | 162 | +//                    _t2.setIdentity();  | 
|---|
 | 163 | +//  | 
|---|
 | 164 | +//                    _t1.get(mat4d);  | 
|---|
 | 165 | +//  | 
|---|
 | 166 | +//                    mat4d.get(quatend);  | 
|---|
 | 167 | +//  | 
|---|
 | 168 | +//                    double dot = quatstart.x*quatend.x +  | 
|---|
 | 169 | +//                            quatstart.y*quatend.y +  | 
|---|
 | 170 | +//                            quatstart.z*quatend.z +  | 
|---|
 | 171 | +//                            quatstart.w*quatend.w  | 
|---|
 | 172 | +//                            ;  | 
|---|
 | 173 | +//  | 
|---|
 | 174 | +//                    if (dot < 0)  | 
|---|
 | 175 | +//                    {  | 
|---|
 | 176 | +//                        quatend.x *= -1;  | 
|---|
 | 177 | +//                        quatend.y *= -1;  | 
|---|
 | 178 | +//                        quatend.z *= -1;  | 
|---|
 | 179 | +//                        quatend.w *= -1;  | 
|---|
 | 180 | +//                    }  | 
|---|
 | 181 | +//  | 
|---|
 | 182 | +//                   // k = 1-k;  | 
|---|
 | 183 | +//  | 
|---|
 | 184 | +//                    quat.x = (1-k)*quatstart.x + k*quatend.x;  | 
|---|
 | 185 | +//                    quat.y = (1-k)*quatstart.y + k*quatend.y;  | 
|---|
 | 186 | +//                    quat.z = (1-k)*quatstart.z + k*quatend.z;  | 
|---|
 | 187 | +//                    quat.w = (1-k)*quatstart.w + k*quatend.w;  | 
|---|
 | 188 | +//  | 
|---|
 | 189 | +//                    quat.normalize();  | 
|---|
 | 190 | +//  | 
|---|
 | 191 | +//                    mat4d.set(quat);  | 
|---|
 | 192 | +//  | 
|---|
 | 193 | +//                    cJ3D.SetTransform(rot, mat4d);  | 
|---|
 | 194 | +//  | 
|---|
 | 195 | +//                    matrixToEulerXYZ(rot, temp);  | 
|---|
 | 196 | +//  | 
|---|
 | 197 | +//                    data[f3 + start-1] = -(float)temp.z;  | 
|---|
 | 198 | +//  | 
|---|
 | 199 | +//                    if (b == 0)  | 
|---|
 | 200 | +//                    {  | 
|---|
 | 201 | +//                        data[f3 + start-2] = -(float)temp.y;  | 
|---|
 | 202 | +//                        data[f3 + start-3] = -(float)temp.x;  | 
|---|
 | 203 | +//                    }  | 
|---|
 | 204 | +//                    else  | 
|---|
 | 205 | +//                    {  | 
|---|
 | 206 | +//                        data[f3 + start-2] = -(float)temp.x;  | 
|---|
 | 207 | +//                        data[f3 + start-3] = -(float)temp.y;  | 
|---|
 | 208 | +//                    }  | 
|---|
 | 209 | +                }  | 
|---|
 | 210 | +                else  | 
|---|
 | 211 | +                {  | 
|---|
 | 212 | +                    for (int i=start; --i>=end;)  | 
|---|
 | 213 | +                    {  | 
|---|
 | 214 | +                        //data[f3 + i] += pos[i] - data[frame3 + i];  | 
|---|
 | 215 | +//                                data[f3 + i] = k*data[f3+i] + (1-k)*  | 
|---|
 | 216 | +//                                        currentbones[boneframe3 + i-end];  | 
|---|
 | 217 | +                        data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i/*-end*/], 1-k);  | 
|---|
 | 218 | +                    }  | 
|---|
 | 219 | +                }  | 
|---|
 | 220 | +            }  | 
|---|
 | 221 | +        }  | 
|---|
 | 222 | +    }  | 
|---|
 | 223 | +  | 
|---|
 | 224 | +    // Updates the toParent matrix to keep the same position and orientation  | 
|---|
 | 225 | +    // before resetting the mocap data.  | 
|---|
 | 226 | +    void SetGlobalTransform()  | 
|---|
 | 227 | +    {  | 
|---|
 | 228 | +        SetCurrentBones(frame);  | 
|---|
 | 229 | +          | 
|---|
 | 230 | +        cVector temp = new cVector();  | 
|---|
 | 231 | +        cVector pos = new cVector();  | 
|---|
 | 232 | +        cVector poship = new cVector();  | 
|---|
 | 233 | +          | 
|---|
 | 234 | +        double angleY = 0;  | 
|---|
 | 235 | +        double angleYhip = 0;  | 
|---|
 | 236 | +          | 
|---|
 | 237 | +        Object3D hip = get(0);  | 
|---|
 | 238 | +          | 
|---|
 | 239 | +        LA.matConcat(toParent, hip.get(0).toParent, matrix);  | 
|---|
 | 240 | +        poship.x = matrix[3][0];  | 
|---|
 | 241 | +        poship.y = matrix[3][1];  | 
|---|
 | 242 | +        poship.z = matrix[3][2];  | 
|---|
 | 243 | +          | 
|---|
 | 244 | +        temp.x = 1;  | 
|---|
 | 245 | +        temp.y = 0;  | 
|---|
 | 246 | +        temp.z = 0;  | 
|---|
 | 247 | +  | 
|---|
 | 248 | +        LA.xformDir(temp, matrix, temp);  | 
|---|
 | 249 | +  | 
|---|
 | 250 | +        angleYhip = Math.atan2(-temp.z, temp.x);  | 
|---|
 | 251 | +          | 
|---|
 | 252 | +        LA.matIdentity(toParent);  | 
|---|
 | 253 | +        LA.matYRotate(toParent, angleYhip);  | 
|---|
 | 254 | +        LA.matTranslate(toParent, poship.x, poship.y, poship.z);  | 
|---|
 | 255 | +          | 
|---|
 | 256 | +//    LA.matConcat(toParent, hip.get(0).toParent, toParent);  | 
|---|
 | 257 | +          | 
|---|
 | 258 | +        CameraPane.debugpoint.toParent[3][0] = poship.x;  | 
|---|
 | 259 | +        CameraPane.debugpoint.toParent[3][1] = poship.y;  | 
|---|
 | 260 | +        CameraPane.debugpoint.toParent[3][2] = poship.z;          | 
|---|
 | 261 | +          | 
|---|
 | 262 | +        LA.matInvert(toParent, fromParent);  | 
|---|
 | 263 | +          | 
|---|
 | 264 | +        LA.matIdentity(hip.get(0).toParent);  | 
|---|
 | 265 | +        LA.matIdentity(hip.get(0).fromParent);  | 
|---|
 | 266 | +  | 
|---|
 | 267 | +//        if (true)  | 
|---|
 | 268 | +//            return;  | 
|---|
 | 269 | +          | 
|---|
 | 270 | +        // Updates hip.get(0).toParent  | 
|---|
 | 271 | +        setPose(hip, GetFirstFrame(), bvh.animation.getBoneData(hip._index));  | 
|---|
 | 272 | +          | 
|---|
 | 273 | +        // A = toParent; B = hip.get(0).toParent  | 
|---|
 | 274 | +        // A'*B = A  | 
|---|
 | 275 | +        // A' = A * B-1  | 
|---|
 | 276 | +          | 
|---|
 | 277 | +        poship.x = hip.get(0).toParent[3][0];  | 
|---|
 | 278 | +        poship.y = hip.get(0).toParent[3][1];  | 
|---|
 | 279 | +        poship.z = hip.get(0).toParent[3][2];  | 
|---|
 | 280 | +          | 
|---|
 | 281 | +        // AT*AR = A'T*BT*A'R*BR  | 
|---|
 | 282 | +        //   | 
|---|
 | 283 | +        LA.matInvert(hip.get(0).toParent, matrix);  | 
|---|
 | 284 | +          | 
|---|
 | 285 | +        //LA.matIdentity(matrix);  | 
|---|
 | 286 | +        //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);  | 
|---|
 | 287 | +          | 
|---|
 | 288 | +        LA.matConcat(toParent, matrix, toParent);  | 
|---|
 | 289 | +          | 
|---|
 | 290 | +//        poship.x = hip.get(0).toParent[3][0];  | 
|---|
 | 291 | +//        poship.y = hip.get(0).toParent[3][1];  | 
|---|
 | 292 | +//        poship.z = hip.get(0).toParent[3][2];  | 
|---|
 | 293 | +//  | 
|---|
 | 294 | +//        temp.x = 1;  | 
|---|
 | 295 | +//        temp.y = 0;  | 
|---|
 | 296 | +//        temp.z = 0;  | 
|---|
 | 297 | +//  | 
|---|
 | 298 | +//        LA.xformDir(temp, hip.get(0).toParent, temp);  | 
|---|
 | 299 | +//  | 
|---|
 | 300 | +//        angleYhip = Math.atan2(-temp.z, temp.x);  | 
|---|
 | 301 | +          | 
|---|
 | 302 | +        LA.matConcat(toParent, hip.get(0).toParent, matrix);  | 
|---|
 | 303 | +        pos.x = hip.get(0).toParent[3][0];  | 
|---|
 | 304 | +        pos.y = hip.get(0).toParent[3][1];  | 
|---|
 | 305 | +        pos.z = hip.get(0).toParent[3][2];  | 
|---|
 | 306 | +        LA.xformPos(new cVector(), hip.get(0).toParent, pos);  | 
|---|
 | 307 | +        LA.xformPos(pos, toParent, pos);  | 
|---|
 | 308 | +  | 
|---|
 | 309 | +//        temp.x = 1;  | 
|---|
 | 310 | +//        temp.y = 0;  | 
|---|
 | 311 | +//        temp.z = 0;  | 
|---|
 | 312 | +//  | 
|---|
 | 313 | +//        LA.xformDir(temp, toParent, temp);  | 
|---|
 | 314 | +//  | 
|---|
 | 315 | +//        angleY = Math.atan2(-temp.z, temp.x);  | 
|---|
 | 316 | +//          | 
|---|
 | 317 | +//        LA.matIdentity(toParent);  | 
|---|
 | 318 | +//        LA.matYRotate(toParent, angleY - angleYhip);  | 
|---|
 | 319 | +//        LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);  | 
|---|
 | 320 | +          | 
|---|
 | 321 | +        CameraPane.debugpoint2.toParent[3][0] = pos.x;  | 
|---|
 | 322 | +        CameraPane.debugpoint2.toParent[3][1] = pos.y;  | 
|---|
 | 323 | +        CameraPane.debugpoint2.toParent[3][2] = pos.z;          | 
|---|
 | 324 | +          | 
|---|
 | 325 | +        CameraPane.debugpoint3.toParent[3][0] = poship.x;  | 
|---|
 | 326 | +        CameraPane.debugpoint3.toParent[3][1] = poship.y;  | 
|---|
 | 327 | +        CameraPane.debugpoint3.toParent[3][2] = poship.z;          | 
|---|
 | 328 | +          | 
|---|
 | 329 | +        poship.x = toParent[3][0];  | 
|---|
 | 330 | +        poship.y = toParent[3][1];  | 
|---|
 | 331 | +        poship.z = toParent[3][2];  | 
|---|
 | 332 | +          | 
|---|
 | 333 | +        CameraPane.debugpoint4.toParent[3][0] = poship.x;  | 
|---|
 | 334 | +        CameraPane.debugpoint4.toParent[3][1] = poship.y;  | 
|---|
 | 335 | +        CameraPane.debugpoint4.toParent[3][2] = poship.z;          | 
|---|
 | 336 | +          | 
|---|
 | 337 | +        LA.matInvert(toParent, fromParent);  | 
|---|
 | 338 | +    }  | 
|---|
 | 339 | +      | 
|---|
 | 340 | +    void LoadData()  | 
|---|
 | 341 | +    {  | 
|---|
 | 342 | +        float[] thedata = bvh.animation.getBoneData(0);  | 
|---|
 | 343 | +          | 
|---|
 | 344 | +//        thedata[0] = 0;  | 
|---|
 | 345 | +//        thedata[1] = 0;  | 
|---|
 | 346 | +//        thedata[2] = 0;  | 
|---|
 | 347 | +//        thedata[3] = 0;  | 
|---|
 | 348 | +//        thedata[4] = 0;  | 
|---|
 | 349 | +//        thedata[5] = 0;  | 
|---|
 | 350 | +          | 
|---|
 | 351 | +        if (true)  | 
|---|
 | 352 | +            return;  | 
|---|
 | 353 | +          | 
|---|
 | 354 | +        for (int b=numbones; --b>=0;)  | 
|---|
 | 355 | +        //int b = 0;  | 
|---|
 | 356 | +        {  | 
|---|
 | 357 | +            thedata = bvh.animation.getBoneData(b);  | 
|---|
 | 358 | +  | 
|---|
 | 359 | +            int numframes = bvh.animation.getNumFrames();  | 
|---|
 | 360 | +  | 
|---|
 | 361 | +            int dof = 6; // thedata.length/numframes;  | 
|---|
 | 362 | +              | 
|---|
 | 363 | +            if (b > 0)  | 
|---|
 | 364 | +                dof = 3;  | 
|---|
 | 365 | +              | 
|---|
 | 366 | +            if (dof != thedata.length/numframes)  | 
|---|
 | 367 | +            {  | 
|---|
 | 368 | +                System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));  | 
|---|
 | 369 | +                dof = thedata.length/numframes;  | 
|---|
 | 370 | +            }  | 
|---|
 | 371 | +              | 
|---|
 | 372 | +            //for (int f=numframes; --f>=offset;)  | 
|---|
 | 373 | +            int firstframe = GetFirstFrame();  | 
|---|
 | 374 | +            for (int f=0; f<numframes-firstframe; f++)  | 
|---|
 | 375 | +            {  | 
|---|
 | 376 | +                int f3 = f*dof;  | 
|---|
 | 377 | +  | 
|---|
 | 378 | +                //for (int i=3/*dof*/; --i>=0;)  | 
|---|
 | 379 | +                for (int i=dof; --i>=0;)  | 
|---|
 | 380 | +                {  | 
|---|
 | 381 | +                    //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];  | 
|---|
 | 382 | +                    thedata[f3 + i] = thedata[f3 + firstframe*dof + i];  | 
|---|
 | 383 | +                }  | 
|---|
 | 384 | +            }  | 
|---|
 | 385 | +        }  | 
|---|
 | 386 | +    }  | 
|---|
 | 387 | +  | 
|---|
 | 388 | +    void ResetZero()  | 
|---|
 | 389 | +    {  | 
|---|
 | 390 | +        for (int b=numbones; --b>=0;)  | 
|---|
 | 391 | +        {  | 
|---|
 | 392 | +            float[] thedata = bvh.animation.getBoneData(b);  | 
|---|
 | 393 | +  | 
|---|
 | 394 | +            int numframes = bvh.animation.getNumFrames();  | 
|---|
 | 395 | +  | 
|---|
 | 396 | +            int dof = 6;  | 
|---|
 | 397 | +              | 
|---|
 | 398 | +            if (b > 0)  | 
|---|
 | 399 | +                dof = 3;  | 
|---|
 | 400 | +              | 
|---|
 | 401 | +            for (int i=dof; --i>=0;)  | 
|---|
 | 402 | +            {  | 
|---|
 | 403 | +                thedata[i] = 0;  | 
|---|
 | 404 | +            }  | 
|---|
 | 405 | +        }  | 
|---|
 | 406 | +    }  | 
|---|
 | 407 | +  | 
|---|
 | 408 | +    void SetCurrentBones(int frame)  | 
|---|
 | 409 | +    {  | 
|---|
 | 410 | +        if (frame == 0)  | 
|---|
 | 411 | +        {  | 
|---|
 | 412 | +            //frame = 1;  | 
|---|
 | 413 | +        }  | 
|---|
 | 414 | +          | 
|---|
 | 415 | +        if (currentbones == null)  | 
|---|
 | 416 | +        {  | 
|---|
 | 417 | +            currentbones = new double[(numbones-1)*3];  | 
|---|
 | 418 | +            currenthip = new double[6];  | 
|---|
 | 419 | +        }  | 
|---|
 | 420 | +          | 
|---|
 | 421 | +        for (int b=numbones; --b>=1;) // HIP ROTATION: 0;)  | 
|---|
 | 422 | +        //int b = 0;  | 
|---|
 | 423 | +        {  | 
|---|
 | 424 | +            float[] data = bvh.animation.getBoneData(b);  | 
|---|
 | 425 | +              | 
|---|
 | 426 | +            // int numframes = bvh.animation.getNumFrames();  | 
|---|
 | 427 | +  | 
|---|
 | 428 | +            int dof = 6; // data.length/numframes;  | 
|---|
 | 429 | +              | 
|---|
 | 430 | +            if (b > 0)  | 
|---|
 | 431 | +                dof = 3;  | 
|---|
 | 432 | +  | 
|---|
 | 433 | +            //assert(dof == 3);  | 
|---|
 | 434 | +  | 
|---|
 | 435 | +         //   System.err.println("Bone #" + b + ": dof = " + dof);  | 
|---|
 | 436 | +            int theframe = // 1; // baseframe;  | 
|---|
 | 437 | +                            frame;  | 
|---|
 | 438 | +  | 
|---|
 | 439 | +            int frame3 = theframe*dof;  | 
|---|
 | 440 | +            int bone3 = (b-1)*dof;  | 
|---|
 | 441 | +  | 
|---|
 | 442 | +            int start = 3;  | 
|---|
 | 443 | +            int end = 0;  | 
|---|
 | 444 | +              | 
|---|
 | 445 | +            if (dof == 6)  | 
|---|
 | 446 | +            {  | 
|---|
 | 447 | +                start = 6;  | 
|---|
 | 448 | +                //end = 3;  | 
|---|
 | 449 | +            }  | 
|---|
 | 450 | +              | 
|---|
 | 451 | +            for (int i=start; --i>=end;)  | 
|---|
 | 452 | +            {  | 
|---|
 | 453 | +                currentbones[bone3 + i/*-end*/] = data[frame3 + i];  | 
|---|
 | 454 | +            }  | 
|---|
 | 455 | +        }  | 
|---|
 | 456 | +          | 
|---|
 | 457 | +        float[] data = bvh.animation.getBoneData(0);  | 
|---|
 | 458 | +  | 
|---|
 | 459 | +        int dof = 6;  | 
|---|
 | 460 | +  | 
|---|
 | 461 | +        int theframe = frame;  | 
|---|
 | 462 | +  | 
|---|
 | 463 | +        int frame3 = theframe*dof;  | 
|---|
 | 464 | +  | 
|---|
 | 465 | +        int start = 6;  | 
|---|
 | 466 | +        int end = 0;  | 
|---|
 | 467 | +  | 
|---|
 | 468 | +        for (int i=start; --i>=end;)  | 
|---|
 | 469 | +        {  | 
|---|
 | 470 | +            currenthip[i] = data[frame3 + i];  | 
|---|
 | 471 | +        }  | 
|---|
 | 472 | +    }  | 
|---|
| 29 | 473 |       | 
|---|
| 30 | 474 |      void WriteTo(java.io.Writer writer) throws Exception | 
|---|
| 31 | 475 |      { | 
|---|
| .. | .. | 
|---|
| 705 | 1149 |              // skip first node: translation | 
|---|
| 706 | 1150 |  //            Object3D b = input.get(0); | 
|---|
| 707 | 1151 |   | 
|---|
| 708 |  | -            setPose(input, f, data.getBoneData(input._index), false); //, null);  | 
|---|
 | 1152 | +            setPose(input, f, data.getBoneData(input._index)); //, false); //, null);  | 
|---|
| 709 | 1153 |          } | 
|---|
| 710 | 1154 |           | 
|---|
| 711 | 1155 |          //mocap.figure.Bone[] children = b.getChildren(); | 
|---|
| .. | .. | 
|---|
| 921 | 1365 |              //groundz += sourcenode.parent.toParent[3][2] - posz; | 
|---|
| 922 | 1366 |          } | 
|---|
| 923 | 1367 |           | 
|---|
| 924 |  | -        boolean footcontact = CameraPane.FOOTCONTACT; // false;  | 
|---|
 | 1368 | +        boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;  | 
|---|
| 925 | 1369 |           | 
|---|
| 926 | 1370 |          if (footcontact && ground != -123456) | 
|---|
| 927 | 1371 |          { | 
|---|
| .. | .. | 
|---|
| 1220 | 1664 |          src.x = 0; | 
|---|
| 1221 | 1665 |          src.y = 0; | 
|---|
| 1222 | 1666 |          src.z = 0; | 
|---|
 | 1667 | +        LA.xformPos(src, get(0).get(0).toParent, src);  | 
|---|
| 1223 | 1668 |          LA.xformPos(src, get(0).toParent, src); | 
|---|
| 1224 | 1669 |          LA.xformPos(src, toParent, src); | 
|---|
| 1225 | 1670 |  //        LA.xformPos(src, rotsourcenode.toParent, src); | 
|---|
| .. | .. | 
|---|
| 1563 | 2008 |                  toParent = LA.newMatrix(); | 
|---|
| 1564 | 2009 |                  fromParent = LA.newMatrix(); | 
|---|
| 1565 | 2010 |              } | 
|---|
 | 2011 | +              | 
|---|
| 1566 | 2012 |              LA.matConcat(toParent, rotsourcenode.toParent, toParent); | 
|---|
| 1567 | 2013 |              LA.matInvert(toParent, fromParent); | 
|---|
| 1568 | 2014 |               | 
|---|
| .. | .. | 
|---|
| 1698 | 2144 |              } | 
|---|
| 1699 | 2145 |   | 
|---|
| 1700 | 2146 |              if (!smoothed) | 
|---|
| 1701 |  | -                for (int i=4; --i>=0;)  | 
|---|
 | 2147 | +                for (int i=0; --i>=0;)  | 
|---|
| 1702 | 2148 |                      SmoothAnimData(); // much reduces shakiness | 
|---|
| 1703 | 2149 |   | 
|---|
| 1704 | 2150 |              smoothed = true; | 
|---|
| .. | .. | 
|---|
| 1780 | 2226 |          if (!live) // aout 2013 | 
|---|
| 1781 | 2227 |              return; | 
|---|
| 1782 | 2228 |           | 
|---|
| 1783 |  | -    cVector centroid = new cVector();  | 
|---|
| 1784 |  | -    cVector floor = new cVector();  | 
|---|
| 1785 |  | -  | 
|---|
| 1786 |  | -    Object3D sourcenode = GetFileRoot();  | 
|---|
 | 2229 | +        //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);  | 
|---|
 | 2230 | +        try  | 
|---|
 | 2231 | +        {  | 
|---|
 | 2232 | +            SetPose(GetSkeleton(), bvh.animation, f);  | 
|---|
 | 2233 | +            SetCurrentBones(frame);  | 
|---|
 | 2234 | +        }  | 
|---|
 | 2235 | +        catch (Exception e)  | 
|---|
 | 2236 | +        {  | 
|---|
 | 2237 | +            e.printStackTrace();  | 
|---|
 | 2238 | +        }  | 
|---|
| 1787 | 2239 |           | 
|---|
| 1788 |  | -    boolean success; // = sourcenode.getCentroid(centroid);  | 
|---|
 | 2240 | +    if (true)  | 
|---|
 | 2241 | +        return;  | 
|---|
 | 2242 | +  | 
|---|
 | 2243 | +        cVector centroid = new cVector();  | 
|---|
 | 2244 | +        cVector floor = new cVector();  | 
|---|
 | 2245 | +  | 
|---|
 | 2246 | +        Object3D sourcenode = GetFileRoot();  | 
|---|
 | 2247 | +  | 
|---|
 | 2248 | +        boolean success; // = sourcenode.getCentroid(centroid);  | 
|---|
| 1789 | 2249 |  //    if (!success) | 
|---|
| 1790 | 2250 |  //    { | 
|---|
| 1791 | 2251 |  //        //assert(success); | 
|---|
| .. | .. | 
|---|
| 1793 | 2253 |  //        System.out.println("No centroid for " + sourcenode); | 
|---|
| 1794 | 2254 |  //    } | 
|---|
| 1795 | 2255 |   | 
|---|
| 1796 |  | -        //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);  | 
|---|
| 1797 |  | -        try  | 
|---|
| 1798 |  | -        {  | 
|---|
| 1799 |  | -            SetPose(GetSkeleton(), bvh.animation, f);  | 
|---|
| 1800 |  | -        }  | 
|---|
| 1801 |  | -        catch (Exception e)  | 
|---|
| 1802 |  | -        {  | 
|---|
| 1803 |  | -            e.printStackTrace();  | 
|---|
| 1804 |  | -        }  | 
|---|
| 1805 |  | -          | 
|---|
| 1806 | 2256 |          if (sourcenode.parent == null && sourcenode.fileparent == null) | 
|---|
| 1807 | 2257 |          { | 
|---|
| 1808 | 2258 |              // No GFD | 
|---|
| .. | .. | 
|---|
| 2050 | 2500 |       * @param frame | 
|---|
| 2051 | 2501 |       *            Frame number | 
|---|
| 2052 | 2502 |       */ | 
|---|
| 2053 |  | -    public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)  | 
|---|
 | 2503 | +    public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)  | 
|---|
| 2054 | 2504 |      { | 
|---|
| 2055 | 2505 |          if (!live) // aout 2013 | 
|---|
| 2056 | 2506 |              return; | 
|---|
| .. | .. | 
|---|
| 2058 | 2508 |          cVector temp = new cVector(); | 
|---|
| 2059 | 2509 |          cVector temp0 = new cVector(); | 
|---|
| 2060 | 2510 |          double pos[] = new double[3]; | 
|---|
 | 2511 | +        double angleY = 0;  | 
|---|
 | 2512 | +        double sinY = 0;  | 
|---|
 | 2513 | +        double cosY = 0;  | 
|---|
 | 2514 | +          | 
|---|
 | 2515 | +        if (false) // bone._isRoot && firsttimeafterload && frame > 0)  | 
|---|
 | 2516 | +        {  | 
|---|
 | 2517 | +            bone.get(0).GlobalTransformInv();  | 
|---|
 | 2518 | +  | 
|---|
 | 2519 | +            temp.x = bone.get(0).globalTransform[3][0];  | 
|---|
 | 2520 | +            temp.y = bone.get(0).globalTransform[3][1];  | 
|---|
 | 2521 | +            temp.z = bone.get(0).globalTransform[3][2];  | 
|---|
 | 2522 | +  | 
|---|
 | 2523 | +            pos[0] = temp.x;  | 
|---|
 | 2524 | +            pos[1] = temp.y;  | 
|---|
 | 2525 | +            pos[2] = temp.z;  | 
|---|
 | 2526 | +  | 
|---|
 | 2527 | +            temp.x = 1;  | 
|---|
 | 2528 | +            temp.y = 0;  | 
|---|
 | 2529 | +            temp.z = 0;  | 
|---|
 | 2530 | +  | 
|---|
 | 2531 | +            LA.xformDir(temp, bone.get(0).globalTransform, temp);  | 
|---|
 | 2532 | +              | 
|---|
 | 2533 | +            sinY = temp.z;  | 
|---|
 | 2534 | +            cosY = temp.x;  | 
|---|
 | 2535 | +              | 
|---|
 | 2536 | +            angleY = Math.atan2(-sinY, cosY);  | 
|---|
 | 2537 | +        }  | 
|---|
| 2061 | 2538 |           | 
|---|
| 2062 | 2539 |  //        Object3D obj = get(0); | 
|---|
| 2063 | 2540 |  //        Object3D gp = this.parent; | 
|---|
| .. | .. | 
|---|
| 2187 | 2664 |                  // set rotation | 
|---|
| 2188 | 2665 |                  //if (bone._rotationEnabled) | 
|---|
| 2189 | 2666 |                  if (//frame > 0 && | 
|---|
| 2190 |  | -                    !bone.skipmocap &&  | 
|---|
| 2191 |  | -                    !bone.name.contains("head") &&  | 
|---|
 | 2667 | +                    !bone.skipmocap //&&  | 
|---|
 | 2668 | +                    //!bone.name.contains("head") &&  | 
|---|
| 2192 | 2669 |                   //   !bone.name.contains("rFoot") && | 
|---|
| 2193 | 2670 |                   //   !bone.name.contains("lFoot") && | 
|---|
| 2194 |  | -                    !bone.name.contains("Pinky") &&  | 
|---|
| 2195 |  | -                    !bone.name.contains("Ring") &&  | 
|---|
| 2196 |  | -                    !bone.name.contains("Mid") &&  | 
|---|
| 2197 |  | -                    !bone.name.contains("Index") &&  | 
|---|
| 2198 |  | -                    !bone.name.contains("Thumb")  | 
|---|
 | 2671 | +//                    !bone.name.contains("Pinky") &&  | 
|---|
 | 2672 | +//                    !bone.name.contains("Ring") &&  | 
|---|
 | 2673 | +//                    !bone.name.contains("Mid") &&  | 
|---|
 | 2674 | +//                    !bone.name.contains("Index") &&  | 
|---|
 | 2675 | +//                    !bone.name.contains("Thumb")  | 
|---|
| 2199 | 2676 |                     ) | 
|---|
| 2200 | 2677 |                  { | 
|---|
| 2201 | 2678 |                      //_rotTG.setTransform(_t1); | 
|---|
| .. | .. | 
|---|
| 2228 | 2705 |                          // CROWD | 
|---|
| 2229 | 2706 |                          //cJ3D.GetTranslation(bone, _trans0); | 
|---|
| 2230 | 2707 |                          //_trans.add(_trans0); | 
|---|
| 2231 |  | -                        _transTF.setIdentity();  | 
|---|
 | 2708 | +                        //_transTF.setIdentity();  | 
|---|
 | 2709 | +                        _transTF.set(_t1);  | 
|---|
| 2232 | 2710 |                          _transTF.setTranslation(_trans); | 
|---|
| 2233 | 2711 |          //      System.err.println("Translate: " + _transTF); | 
|---|
| 2234 | 2712 |                          //_transTG.setTransform(_transTF); | 
|---|
| 2235 |  | -                        cJ3D.ResetTransform(bone, _transTF, true); // translation node  | 
|---|
 | 2713 | +                        cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node  | 
|---|
 | 2714 | +                        //cJ3D.ResetTransform(bone, _transTF, true); // translation node  | 
|---|
| 2236 | 2715 |                      } | 
|---|
| 2237 | 2716 |                  } | 
|---|
| 2238 | 2717 |                   | 
|---|
| 2239 |  | -                if (bone._isRoot && firsttimeafterload && frame > 0)  | 
|---|
 | 2718 | +                if (false) // bone._isRoot && firsttimeafterload && frame > 0)  | 
|---|
| 2240 | 2719 |                  { | 
|---|
| 2241 | 2720 |                      assert(bone == get(0)); | 
|---|
| 2242 | 2721 |                       | 
|---|
| .. | .. | 
|---|
| 2252 | 2731 |  //                    LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1 | 
|---|
| 2253 | 2732 |  //                     | 
|---|
| 2254 | 2733 |   | 
|---|
| 2255 |  | -        Invariants();  | 
|---|
| 2256 |  | -        bone.Invariants();  | 
|---|
| 2257 |  | -        bone.get(0).Invariants();  | 
|---|
| 2258 |  | -   //     if (origin == null)  | 
|---|
| 2259 |  | -   //         origin = null;  | 
|---|
| 2260 |  | -        origin.Invariants();  | 
|---|
| 2261 |  | -        origin0.Invariants();  | 
|---|
 | 2734 | +                    Invariants();  | 
|---|
 | 2735 | +                    bone.Invariants();  | 
|---|
 | 2736 | +                    bone.get(0).Invariants();  | 
|---|
 | 2737 | +                    //     if (origin == null)  | 
|---|
 | 2738 | +                    //         origin = null;  | 
|---|
 | 2739 | +                    origin.Invariants();  | 
|---|
 | 2740 | +                    origin0.Invariants();  | 
|---|
| 2262 | 2741 |   | 
|---|
| 2263 |  | -           | 
|---|
| 2264 |  | -                    LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'  | 
|---|
| 2265 |  | -                    LA.matConcat(origin.toParent, tempmatrix, toParent);  | 
|---|
 | 2742 | +          | 
|---|
 | 2743 | +//??                    LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'  | 
|---|
 | 2744 | +//??                    LA.matConcat(origin.toParent, tempmatrix, toParent);  | 
|---|
| 2266 | 2745 |                       | 
|---|
| 2267 | 2746 |             //         matrixToEulerXYZ(toParent, temp); | 
|---|
| 2268 | 2747 |  //                    matrixToEulerXYZ(bone.get(0).toParent, temp); | 
|---|
| .. | .. | 
|---|
| 2296 | 2775 |  //                     | 
|---|
| 2297 | 2776 |  //                    mat4d.get(quat); | 
|---|
| 2298 | 2777 |                       | 
|---|
| 2299 |  | -                    if (true) // hip correction  | 
|---|
 | 2778 | +                    if (false) // hip correction  | 
|---|
| 2300 | 2779 |                      { | 
|---|
| 2301 | 2780 |                          _t2.setIdentity(); | 
|---|
| 2302 | 2781 |   | 
|---|
| .. | .. | 
|---|
| 2337 | 2816 |            //?????          LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C' | 
|---|
| 2338 | 2817 |            //          LA.matConcat(origin.fromParent, tempmatrix, fromParent); | 
|---|
| 2339 | 2818 |                       | 
|---|
| 2340 |  | -        LA.matInvert(toParent, fromParent);  | 
|---|
 | 2819 | +//??        LA.matInvert(toParent, fromParent);  | 
|---|
| 2341 | 2820 |                       | 
|---|
| 2342 |  | -        Invariants();  | 
|---|
| 2343 |  | -        bone.Invariants();  | 
|---|
| 2344 |  | -        bone.get(0).Invariants();  | 
|---|
| 2345 |  | -        origin.Invariants();  | 
|---|
| 2346 |  | -        origin0.Invariants();  | 
|---|
 | 2821 | +                    Invariants();  | 
|---|
 | 2822 | +                    bone.Invariants();  | 
|---|
 | 2823 | +                    bone.get(0).Invariants();  | 
|---|
 | 2824 | +                    origin.Invariants();  | 
|---|
 | 2825 | +                    origin0.Invariants();  | 
|---|
| 2347 | 2826 |           | 
|---|
| 2348 | 2827 |  //         LA.matInvert(fromParent, tempmatrix); | 
|---|
| 2349 | 2828 |  //                     | 
|---|
| .. | .. | 
|---|
| 2364 | 2843 |  //        temp.x = data[0]; | 
|---|
| 2365 | 2844 |  //        temp.y = data[1]; | 
|---|
| 2366 | 2845 |  //        temp.z = data[2]; | 
|---|
| 2367 |  | -        LA.xformPos(temp, origin0.toParent, temp0);  | 
|---|
 | 2846 | +                    LA.xformPos(temp, origin0.toParent, temp0); // NU  | 
|---|
| 2368 | 2847 |           | 
|---|
| 2369 |  | -//        bone.GlobalTransformInv();  | 
|---|
| 2370 |  | -          | 
|---|
| 2371 |  | -        temp0.x = bone.globalTransform[3][0];  | 
|---|
| 2372 |  | -        temp0.y = bone.globalTransform[3][1];  | 
|---|
| 2373 |  | -        temp0.z = bone.globalTransform[3][2];  | 
|---|
| 2374 |  | -  | 
|---|
 | 2848 | +//        bone.get(0).GlobalTransformInv();  | 
|---|
 | 2849 | +//          | 
|---|
 | 2850 | +//        temp0.x = bone.get(0).globalTransform[3][0];  | 
|---|
 | 2851 | +//        temp0.y = bone.get(0).globalTransform[3][1];  | 
|---|
 | 2852 | +//        temp0.z = bone.get(0).globalTransform[3][2];  | 
|---|
 | 2853 | +//  | 
|---|
| 2375 | 2854 |  // MEGA TEST // june 2014: necessary for precision? otherwise comment works | 
|---|
| 2376 |  | -fromParent[3][0] = 0;  | 
|---|
| 2377 |  | -fromParent[3][1] = 0;  | 
|---|
| 2378 |  | -fromParent[3][2] = 0;  | 
|---|
| 2379 |  | -LA.matInvert(fromParent, toParent);  | 
|---|
 | 2855 | +//fromParent[3][0] = 0;  | 
|---|
 | 2856 | +//fromParent[3][1] = 0;  | 
|---|
 | 2857 | +//fromParent[3][2] = 0;  | 
|---|
 | 2858 | +//LA.matInvert(fromParent, toParent);  | 
|---|
| 2380 | 2859 |           | 
|---|
| 2381 |  | -        LA.xformPos(temp0, fromParent, temp);  | 
|---|
 | 2860 | +                    LA.xformPos(temp0, fromParent, temp); // NU  | 
|---|
| 2382 | 2861 |          //LA.xformPos(temp, bone.fromParent, temp); | 
|---|
| 2383 | 2862 |                  //    float[] data; | 
|---|
| 2384 | 2863 |                       | 
|---|
| 2385 |  | -        pos[0] = temp.x;  | 
|---|
| 2386 |  | -        pos[1] = temp.y;  | 
|---|
| 2387 |  | -        pos[2] = temp.z;  | 
|---|
 | 2864 | +//        pos[0] = temp.x;  | 
|---|
 | 2865 | +//        pos[1] = temp.y;  | 
|---|
 | 2866 | +//        pos[2] = temp.z;  | 
|---|
 | 2867 | +//          | 
|---|
 | 2868 | +//        temp.x = 1;  | 
|---|
 | 2869 | +//        temp.y = 0;  | 
|---|
 | 2870 | +//        temp.z = 0;  | 
|---|
 | 2871 | +//          | 
|---|
 | 2872 | +//        LA.xformDir(temp, bone.get(0).globalTransform, temp);  | 
|---|
| 2388 | 2873 |           | 
|---|
| 2389 | 2874 |      //    CameraPane.selectedpoint.toParent[3][0] = temp0.x; | 
|---|
| 2390 | 2875 |      //    CameraPane.selectedpoint.toParent[3][1] = temp0.y; | 
|---|
| 2391 | 2876 |      //    CameraPane.selectedpoint.toParent[3][2] = temp0.z; | 
|---|
| 2392 | 2877 |           | 
|---|
| 2393 |  | -        int numframes = bvh.animation.getNumFrames();  | 
|---|
 | 2878 | +                    int numframes = bvh.animation.getNumFrames();  | 
|---|
| 2394 | 2879 |           | 
|---|
| 2395 | 2880 |                      int b = 0; | 
|---|
| 2396 | 2881 |                      { | 
|---|
| .. | .. | 
|---|
| 2398 | 2883 |   | 
|---|
| 2399 | 2884 |                          int dof = 6; /// data.length/numframes; | 
|---|
| 2400 | 2885 |   | 
|---|
| 2401 |  | -                // july 2014  | 
|---|
| 2402 |  | -                if (dof != data.length/numframes)  | 
|---|
| 2403 |  | -                {  | 
|---|
| 2404 |  | -                    System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));  | 
|---|
| 2405 |  | -                    dof = data.length/numframes;  | 
|---|
| 2406 |  | -                }  | 
|---|
 | 2886 | +                        // july 2014  | 
|---|
 | 2887 | +                        if (dof != data.length/numframes)  | 
|---|
 | 2888 | +                        {  | 
|---|
 | 2889 | +                            System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));  | 
|---|
 | 2890 | +                            dof = data.length/numframes;  | 
|---|
 | 2891 | +                        }  | 
|---|
| 2407 | 2892 |                   | 
|---|
| 2408 | 2893 |                           | 
|---|
| 2409 | 2894 |                          int theframe = 0; // baseframe; | 
|---|
| .. | .. | 
|---|
| 2455 | 2940 |              //                        } | 
|---|
| 2456 | 2941 |              //                    } | 
|---|
| 2457 | 2942 |   | 
|---|
| 2458 |  | -                                data[f3 + i] += pos[i] - data[frame3 + i];  | 
|---|
 | 2943 | +                                data[f3 + i] += /*pos[i]*/ - data[frame3 + i];  | 
|---|
| 2459 | 2944 |                                   | 
|---|
| 2460 | 2945 |  //                                if (f < 3) | 
|---|
| 2461 | 2946 |  //                                { | 
|---|
| 2462 | 2947 |  //                                    System.out.print(data[f3 + i] + " "); | 
|---|
| 2463 | 2948 |  //                                } | 
|---|
| 2464 | 2949 |                              } | 
|---|
| 2465 |  | -//                            if (f < 3)  | 
|---|
| 2466 |  | -//                            {  | 
|---|
| 2467 |  | -//                                System.out.println();  | 
|---|
| 2468 |  | -//                            }  | 
|---|
 | 2950 | +                              | 
|---|
 | 2951 | +                            double t1 = data[f3 + 0];  | 
|---|
 | 2952 | +                            double t2 = data[f3 + 2];  | 
|---|
 | 2953 | +                              | 
|---|
 | 2954 | +                            data[f3 + 0] = (float)(cosY*t1 - sinY*t2);  | 
|---|
 | 2955 | +                            data[f3 + 2] = (float)(sinY*t1 + cosY*t2);  | 
|---|
 | 2956 | +                              | 
|---|
 | 2957 | +                            for (int i=3/*dof*/; --i>=0;)  | 
|---|
 | 2958 | +                            {  | 
|---|
 | 2959 | +                                data[f3 + i] += pos[i];  | 
|---|
 | 2960 | +                            }  | 
|---|
 | 2961 | +                              | 
|---|
 | 2962 | +                            data[f3 + 4] += angleY - data[frame3 + 4];  | 
|---|
| 2469 | 2963 |                          } | 
|---|
| 2470 | 2964 |                      } | 
|---|
| 2471 | 2965 |                       | 
|---|
| .. | .. | 
|---|
| 2479 | 2973 |  //        temp.y = data[1]; | 
|---|
| 2480 | 2974 |  //        temp.z = data[2]; | 
|---|
| 2481 | 2975 |   | 
|---|
| 2482 |  | -        if (fade && currentbones != null && !CameraPane.fullreset)  | 
|---|
| 2483 |  | -        {  | 
|---|
| 2484 |  | -                    Quat4d quatstart = new Quat4d();  | 
|---|
| 2485 |  | -                    Quat4d quatend = new Quat4d();  | 
|---|
| 2486 |  | -                    Quat4d quat = new Quat4d();  | 
|---|
| 2487 |  | -                    Matrix4d mat4d = new Matrix4d();  | 
|---|
| 2488 |  | -                    double[][] rot = new double[4][4];  | 
|---|
| 2489 |  | -                      | 
|---|
| 2490 |  | -                    for (b=numbones; --b>=1;) // HIP ROTATION: 0;)  | 
|---|
| 2491 |  | -                    {  | 
|---|
| 2492 |  | -                        int hipindex = get(0)._index;  | 
|---|
| 2493 |  | -                          | 
|---|
| 2494 |  | -//                        assert(get(0).get(0)._isHip);  | 
|---|
| 2495 |  | -                          | 
|---|
| 2496 |  | -              //          if (b == hipindex)  | 
|---|
| 2497 |  | -              //              continue;  | 
|---|
| 2498 |  | -                          | 
|---|
| 2499 |  | -                        data = bvh.animation.getBoneData(b);  | 
|---|
| 2500 |  | -                          | 
|---|
| 2501 |  | -                        int dof = 3; // data.length/numframes;  | 
|---|
| 2502 |  | -  | 
|---|
| 2503 |  | -                      //  assert(dof == 3);  | 
|---|
| 2504 |  | -  | 
|---|
| 2505 |  | -                        int boneframe3 = b*3; // dof;  | 
|---|
| 2506 |  | -                          | 
|---|
| 2507 |  | -                     //   System.err.println("Bone #" + b + ": dof = " + dof);  | 
|---|
| 2508 |  | -                        int fadein = 45; // 120;  | 
|---|
| 2509 |  | -                          | 
|---|
| 2510 |  | -                    //    if (b == hipindex)  | 
|---|
| 2511 |  | -                    //        fadein *= 5;  | 
|---|
| 2512 |  | -                          | 
|---|
| 2513 |  | -                        if (fadein > numframes)  | 
|---|
| 2514 |  | -                            fadein = 0; // numframes;  | 
|---|
| 2515 |  | -                          | 
|---|
| 2516 |  | -                        for (int fi=fadein; --fi>=0;)  | 
|---|
| 2517 |  | -                        //for (int f=numframes; --f>=0;)  | 
|---|
| 2518 |  | -                        {  | 
|---|
| 2519 |  | -                            int f = fi + GetFirstFrame();  | 
|---|
| 2520 |  | -                              | 
|---|
| 2521 |  | -                            int f3 = f*dof;  | 
|---|
| 2522 |  | -                              | 
|---|
| 2523 |  | -                            float k = fi;  | 
|---|
| 2524 |  | -                              | 
|---|
| 2525 |  | -                            k /= fadein - 1;  | 
|---|
| 2526 |  | -                              | 
|---|
| 2527 |  | -                            if (Float.isNaN(k))  | 
|---|
| 2528 |  | -                                k = 1; // 0/0  | 
|---|
| 2529 |  | -                              | 
|---|
| 2530 |  | -                            k = (float) (-Math.cos(k*Math.PI));  | 
|---|
| 2531 |  | -                            k += 1;  | 
|---|
| 2532 |  | -                            k /= 2;  | 
|---|
| 2533 |  | -                              | 
|---|
| 2534 |  | -                            int start = 3;  | 
|---|
| 2535 |  | -                            int end = 0;  | 
|---|
| 2536 |  | -  | 
|---|
| 2537 |  | -                            if (dof == 6)  | 
|---|
| 2538 |  | -                            {  | 
|---|
| 2539 |  | -                                start = 6;  | 
|---|
| 2540 |  | -                                end = 3;  | 
|---|
| 2541 |  | -                            }  | 
|---|
| 2542 |  | -                              | 
|---|
| 2543 |  | -                            if (b == 0)  | 
|---|
| 2544 |  | -                            {  | 
|---|
| 2545 |  | -                                _t1.setIdentity();  | 
|---|
| 2546 |  | -                                _t2.setIdentity();  | 
|---|
| 2547 |  | -                                _t2.rotZ(currentbones[boneframe3 + start-1-end]);  | 
|---|
| 2548 |  | -                                _t1.mul(_t2);  | 
|---|
| 2549 |  | -                                _t2.setIdentity();  | 
|---|
| 2550 |  | -                                if (b == 0)  | 
|---|
| 2551 |  | -                                {  | 
|---|
| 2552 |  | -                                    _t2.rotY(currentbones[boneframe3 + start-2-end]);  | 
|---|
| 2553 |  | -                                    _t1.mul(_t2);  | 
|---|
| 2554 |  | -                                    _t2.setIdentity();  | 
|---|
| 2555 |  | -                                    _t2.rotX(currentbones[boneframe3 + start-3-end]);  | 
|---|
| 2556 |  | -                                }  | 
|---|
| 2557 |  | -                                else  | 
|---|
| 2558 |  | -                                {  | 
|---|
| 2559 |  | -                                    _t2.rotX(currentbones[boneframe3 + start-2-end]);  | 
|---|
| 2560 |  | -                                    _t1.mul(_t2);  | 
|---|
| 2561 |  | -                                    _t2.setIdentity();  | 
|---|
| 2562 |  | -                                    _t2.rotY(currentbones[boneframe3 + start-3-end]);  | 
|---|
| 2563 |  | -                                }  | 
|---|
| 2564 |  | -                                _t1.mul(_t2);  | 
|---|
| 2565 |  | -                                _t2.setIdentity();  | 
|---|
| 2566 |  | -  | 
|---|
| 2567 |  | -                                _t1.get(mat4d);  | 
|---|
| 2568 |  | -  | 
|---|
| 2569 |  | -                                mat4d.get(quatstart);  | 
|---|
| 2570 |  | -  | 
|---|
| 2571 |  | -                                _t1.setIdentity();  | 
|---|
| 2572 |  | -                                _t2.setIdentity();  | 
|---|
| 2573 |  | -                                _t2.rotZ(data[f3 + start-1]);  | 
|---|
| 2574 |  | -                                _t1.mul(_t2);  | 
|---|
| 2575 |  | -                                _t2.setIdentity();  | 
|---|
| 2576 |  | -                                if (b == 0)  | 
|---|
| 2577 |  | -                                {  | 
|---|
| 2578 |  | -                                    _t2.rotY(data[f3 + start-2]);  | 
|---|
| 2579 |  | -                                    _t1.mul(_t2);  | 
|---|
| 2580 |  | -                                    _t2.setIdentity();  | 
|---|
| 2581 |  | -                                    _t2.rotX(data[f3 + start-3]);  | 
|---|
| 2582 |  | -                                }  | 
|---|
| 2583 |  | -                                else  | 
|---|
| 2584 |  | -                                {  | 
|---|
| 2585 |  | -                                    _t2.rotX(data[f3 + start-2]);  | 
|---|
| 2586 |  | -                                    _t1.mul(_t2);  | 
|---|
| 2587 |  | -                                    _t2.setIdentity();  | 
|---|
| 2588 |  | -                                    _t2.rotY(data[f3 + start-3]);  | 
|---|
| 2589 |  | -                                }  | 
|---|
| 2590 |  | -                             | 
|---|
| 2591 |  | -                                _t1.mul(_t2);  | 
|---|
| 2592 |  | -                                _t2.setIdentity();  | 
|---|
| 2593 |  | -  | 
|---|
| 2594 |  | -                                _t1.get(mat4d);  | 
|---|
| 2595 |  | -  | 
|---|
| 2596 |  | -                                mat4d.get(quatend);  | 
|---|
| 2597 |  | -  | 
|---|
| 2598 |  | -                                double dot = quatstart.x*quatend.x +  | 
|---|
| 2599 |  | -                                        quatstart.y*quatend.y +  | 
|---|
| 2600 |  | -                                        quatstart.z*quatend.z +  | 
|---|
| 2601 |  | -                                        quatstart.w*quatend.w  | 
|---|
| 2602 |  | -                                        ;  | 
|---|
| 2603 |  | -  | 
|---|
| 2604 |  | -                                if (dot < 0)  | 
|---|
| 2605 |  | -                                {  | 
|---|
| 2606 |  | -                                    quatend.x *= -1;  | 
|---|
| 2607 |  | -                                    quatend.y *= -1;  | 
|---|
| 2608 |  | -                                    quatend.z *= -1;  | 
|---|
| 2609 |  | -                                    quatend.w *= -1;  | 
|---|
| 2610 |  | -                                }  | 
|---|
| 2611 |  | -  | 
|---|
| 2612 |  | -                               // k = 1-k;  | 
|---|
| 2613 |  | -  | 
|---|
| 2614 |  | -                                quat.x = (1-k)*quatstart.x + k*quatend.x;  | 
|---|
| 2615 |  | -                                quat.y = (1-k)*quatstart.y + k*quatend.y;  | 
|---|
| 2616 |  | -                                quat.z = (1-k)*quatstart.z + k*quatend.z;  | 
|---|
| 2617 |  | -                                quat.w = (1-k)*quatstart.w + k*quatend.w;  | 
|---|
| 2618 |  | -  | 
|---|
| 2619 |  | -                                quat.normalize();  | 
|---|
| 2620 |  | -  | 
|---|
| 2621 |  | -                                mat4d.set(quat);  | 
|---|
| 2622 |  | -  | 
|---|
| 2623 |  | -                                cJ3D.SetTransform(rot, mat4d);  | 
|---|
| 2624 |  | -  | 
|---|
| 2625 |  | -                                matrixToEulerXYZ(rot, temp);  | 
|---|
| 2626 |  | -  | 
|---|
| 2627 |  | -                                data[f3 + start-1] = -(float)temp.z;  | 
|---|
| 2628 |  | -                                  | 
|---|
| 2629 |  | -                                if (b == 0)  | 
|---|
| 2630 |  | -                                {  | 
|---|
| 2631 |  | -                                    data[f3 + start-2] = -(float)temp.y;  | 
|---|
| 2632 |  | -                                    data[f3 + start-3] = -(float)temp.x;  | 
|---|
| 2633 |  | -                                }  | 
|---|
| 2634 |  | -                                else  | 
|---|
| 2635 |  | -                                {  | 
|---|
| 2636 |  | -                                    data[f3 + start-2] = -(float)temp.x;  | 
|---|
| 2637 |  | -                                    data[f3 + start-3] = -(float)temp.y;  | 
|---|
| 2638 |  | -                                }  | 
|---|
| 2639 |  | -                            }  | 
|---|
| 2640 |  | -                            else  | 
|---|
| 2641 |  | -                            {  | 
|---|
| 2642 |  | -                                for (int i=start; --i>=end;)  | 
|---|
| 2643 |  | -                                {  | 
|---|
| 2644 |  | -                                    //data[f3 + i] += pos[i] - data[frame3 + i];  | 
|---|
| 2645 |  | -    //                                data[f3 + i] = k*data[f3+i] + (1-k)*  | 
|---|
| 2646 |  | -    //                                        currentbones[boneframe3 + i-end];  | 
|---|
| 2647 |  | -                                    data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);  | 
|---|
| 2648 |  | -                                }  | 
|---|
| 2649 |  | -                            }  | 
|---|
| 2650 |  | -                      | 
|---|
| 2651 |  | -                        }  | 
|---|
| 2652 |  | -                    }  | 
|---|
| 2653 |  | -              | 
|---|
| 2654 |  | -        }  | 
|---|
 | 2976 | +//                    if (fade && currentbones != null && !CameraPane.fullreset)  | 
|---|
 | 2977 | +//                    {  | 
|---|
 | 2978 | +//                        Fade();  | 
|---|
 | 2979 | +//                    }  | 
|---|
| 2655 | 2980 |                  } | 
|---|
| 2656 |  | -                  | 
|---|
 | 2981 | +  | 
|---|
| 2657 | 2982 |                  if (false) // doesn't change anything bone._isRoot) | 
|---|
| 2658 | 2983 |                  { | 
|---|
| 2659 | 2984 |                      // Reset orientation | 
|---|
| 2660 | 2985 |                      _t2.setIdentity(); | 
|---|
| 2661 |  | -                      | 
|---|
 | 2986 | +  | 
|---|
| 2662 | 2987 |                      double tx = bone.toParent[3][0]; | 
|---|
| 2663 | 2988 |                      double ty = bone.toParent[3][1]; | 
|---|
| 2664 | 2989 |                      double tz = bone.toParent[3][2]; | 
|---|
| .. | .. | 
|---|
| 2667 | 2992 |                      temp.y = 0; | 
|---|
| 2668 | 2993 |                      temp.z = 0; | 
|---|
| 2669 | 2994 |                      LA.xformDir(temp, bone.toParent, temp); | 
|---|
| 2670 |  | -                      | 
|---|
 | 2995 | +  | 
|---|
| 2671 | 2996 |                      double angle = Math.atan2(-temp.z, temp.x); | 
|---|
| 2672 |  | -                      | 
|---|
 | 2997 | +  | 
|---|
| 2673 | 2998 |                      _t2.rotY(angle); | 
|---|
| 2674 | 2999 |  //                    _t1.setIdentity(); | 
|---|
| 2675 | 3000 |  //                    _t1.rotX(temp.x); | 
|---|
| .. | .. | 
|---|
| 2682 | 3007 |  //                    _t1.setIdentity(); | 
|---|
| 2683 | 3008 |  //                    _t1.rotZ(temp.z); | 
|---|
| 2684 | 3009 |  //                    _t2.mul(_t1); | 
|---|
| 2685 |  | -                      | 
|---|
 | 3010 | +  | 
|---|
| 2686 | 3011 |                      cJ3D.ResetTransform(bone, _t2, false); | 
|---|
| 2687 |  | -                      | 
|---|
 | 3012 | +  | 
|---|
| 2688 | 3013 |                      bone.toParent[3][0] = tx; | 
|---|
| 2689 | 3014 |                      bone.toParent[3][1] = ty; | 
|---|
| 2690 | 3015 |                      bone.toParent[3][2] = tz; | 
|---|
| 2691 | 3016 |                  } | 
|---|
| 2692 | 3017 |              } | 
|---|
| 2693 | 3018 |               | 
|---|
| 2694 |  | -        if (currentbones == null)  | 
|---|
| 2695 |  | -            currentbones = new double[numbones*3];  | 
|---|
| 2696 |  | -          | 
|---|
| 2697 |  | -            for (int b=numbones; --b>=1;) // 0;)  | 
|---|
| 2698 |  | -            //int b = 0;  | 
|---|
| 2699 |  | -            {  | 
|---|
| 2700 |  | -                data = bvh.animation.getBoneData(b);  | 
|---|
| 2701 |  | -                  | 
|---|
| 2702 |  | -                int numframes = bvh.animation.getNumFrames();  | 
|---|
| 2703 |  | -  | 
|---|
| 2704 |  | -                int dof = 6; // data.length/numframes;  | 
|---|
| 2705 |  | -                  | 
|---|
| 2706 |  | -                if (b > 0)  | 
|---|
| 2707 |  | -                    dof = 3;  | 
|---|
| 2708 |  | -  | 
|---|
| 2709 |  | -                //assert(dof == 3);  | 
|---|
| 2710 |  | -  | 
|---|
| 2711 |  | -             //   System.err.println("Bone #" + b + ": dof = " + dof);  | 
|---|
| 2712 |  | -                int theframe = // 1; // baseframe;  | 
|---|
| 2713 |  | -                                frame;  | 
|---|
| 2714 |  | -  | 
|---|
| 2715 |  | -                int frame3 = theframe*dof;  | 
|---|
| 2716 |  | -                int bone3 = b*3; // dof;  | 
|---|
| 2717 |  | -  | 
|---|
| 2718 |  | -                int start = 3;  | 
|---|
| 2719 |  | -                int end = 0;  | 
|---|
| 2720 |  | -                  | 
|---|
| 2721 |  | -                if (dof == 6)  | 
|---|
| 2722 |  | -                {  | 
|---|
| 2723 |  | -                    start = 6;  | 
|---|
| 2724 |  | -                    end = 3;  | 
|---|
| 2725 |  | -                }  | 
|---|
| 2726 |  | -                for (int i=start; --i>=end;)  | 
|---|
| 2727 |  | -                {  | 
|---|
| 2728 |  | -                    currentbones[bone3 + i-end] = data[frame3 + i];  | 
|---|
| 2729 |  | -                }  | 
|---|
| 2730 |  | -            }  | 
|---|
 | 3019 | +            // SetCurrentBones(frame);  | 
|---|
| 2731 | 3020 |          } | 
|---|
| 2732 | 3021 |      } | 
|---|
| 2733 | 3022 |       | 
|---|
| .. | .. | 
|---|
| 2767 | 3056 |           | 
|---|
| 2768 | 3057 |  //        assert(obj.name.equals("hip")); | 
|---|
| 2769 | 3058 |           | 
|---|
| 2770 |  | -        Object3D rot = hip.get(0);  | 
|---|
 | 3059 | +        //Object3D rot = hip.get(0);  | 
|---|
| 2771 | 3060 |           | 
|---|
| 2772 | 3061 |     //     assert(obj.name == null); // .equals("hip#")); | 
|---|
| 2773 | 3062 |           | 
|---|
| .. | .. | 
|---|
| 2777 | 3066 |              hip.fromParent = LA.newMatrix(); | 
|---|
| 2778 | 3067 |          } | 
|---|
| 2779 | 3068 |           | 
|---|
| 2780 |  | -        hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;  | 
|---|
| 2781 |  | -        hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;  | 
|---|
 | 3069 | +        //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;  | 
|---|
 | 3070 | +        //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;  | 
|---|
| 2782 | 3071 |           | 
|---|
| 2783 | 3072 |          if (toParent == null) | 
|---|
| 2784 | 3073 |          { | 
|---|
| .. | .. | 
|---|
| 2790 | 3079 |          LA.matIdentity(fromParent); | 
|---|
| 2791 | 3080 |  //        LA.matIdentity(hip.toParent); | 
|---|
| 2792 | 3081 |  //        LA.matIdentity(hip.fromParent); | 
|---|
| 2793 |  | -        if (rot.toParent == null)  | 
|---|
| 2794 |  | -        {  | 
|---|
| 2795 |  | -            // june 2014  | 
|---|
| 2796 |  | -            rot.toParent = LA.newMatrix();  | 
|---|
| 2797 |  | -            rot.fromParent = LA.newMatrix();  | 
|---|
| 2798 |  | -        }  | 
|---|
| 2799 |  | -        LA.matIdentity(rot.toParent);  | 
|---|
| 2800 |  | -        LA.matIdentity(rot.fromParent);  | 
|---|
 | 3082 | +//        if (rot.toParent == null)  | 
|---|
 | 3083 | +//        {  | 
|---|
 | 3084 | +//            // june 2014  | 
|---|
 | 3085 | +//            rot.toParent = LA.newMatrix();  | 
|---|
 | 3086 | +//            rot.fromParent = LA.newMatrix();  | 
|---|
 | 3087 | +//        }  | 
|---|
 | 3088 | +//        LA.matIdentity(rot.toParent);  | 
|---|
 | 3089 | +//        LA.matIdentity(rot.fromParent);  | 
|---|
| 2801 | 3090 |   | 
|---|
| 2802 | 3091 |          // july 2014 | 
|---|
| 2803 | 3092 |          goalx = goalz = 0; | 
|---|
| 2804 | 3093 |          targetx = targetz = 0; | 
|---|
| 2805 | 3094 |           | 
|---|
| 2806 |  | -        SetPositionDelta(true, true, true, false);  | 
|---|
 | 3095 | +        //SetPositionDelta(true, true, true, false);  | 
|---|
 | 3096 | +//        LoadData();  | 
|---|
 | 3097 | +//        Rewind();  | 
|---|
| 2807 | 3098 |           | 
|---|
| 2808 | 3099 |          baseframe = frame = 0; // T pose. No offset. | 
|---|
| 2809 | 3100 |           | 
|---|
| 2810 | 3101 |  // aout 2013        endframe = 0; // june 2013 | 
|---|
| 2811 | 3102 |           | 
|---|
 | 3103 | +        //ResetZero();  | 
|---|
| 2812 | 3104 |          setPose(frame); | 
|---|
| 2813 | 3105 |      } | 
|---|
| 2814 | 3106 |       | 
|---|
| .. | .. | 
|---|
| 2880 | 3172 |                      { | 
|---|
| 2881 | 3173 |                          bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh; | 
|---|
| 2882 | 3174 |   | 
|---|
| 2883 |  | -                        SetPositionDelta(false, true, true, true);  | 
|---|
 | 3175 | +                        // SetPositionDelta(false, true, true, true);  | 
|---|
 | 3176 | +                        LoadData();  | 
|---|
 | 3177 | +                        Rewind();  | 
|---|
 | 3178 | +                        Fade();  | 
|---|
| 2884 | 3179 |                      } | 
|---|
| 2885 | 3180 |                      catch (Exception e) | 
|---|
| 2886 | 3181 |                      { | 
|---|
| .. | .. | 
|---|
| 3193 | 3488 |      //static | 
|---|
| 3194 | 3489 |      transient | 
|---|
| 3195 | 3490 |              double[] currentbones; | 
|---|
 | 3491 | +    double[] currenthip;  | 
|---|
 | 3492 | +      | 
|---|
| 3196 | 3493 |      transient boolean inbetween; | 
|---|
| 3197 | 3494 |       | 
|---|
| 3198 | 3495 |      void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade) | 
|---|
| .. | .. | 
|---|
| 3203 | 3500 |          //assert(dim == numframes*6); | 
|---|
| 3204 | 3501 |           | 
|---|
| 3205 | 3502 |          if (load) | 
|---|
| 3206 |  | -            for (int b=numbones; --b>=0;)  | 
|---|
| 3207 |  | -            //int b = 0;  | 
|---|
| 3208 |  | -            {  | 
|---|
| 3209 |  | -                float[] thedata = bvh.animation.getBoneData(b);  | 
|---|
| 3210 |  | -  | 
|---|
| 3211 |  | -                int numframes = bvh.animation.getNumFrames();  | 
|---|
| 3212 |  | -  | 
|---|
| 3213 |  | -                int dof = 6; // thedata.length/numframes;  | 
|---|
| 3214 |  | -                  | 
|---|
| 3215 |  | -                if (b > 0)  | 
|---|
| 3216 |  | -                    dof = 3;  | 
|---|
| 3217 |  | -                  | 
|---|
| 3218 |  | -                if (dof != thedata.length/numframes)  | 
|---|
| 3219 |  | -                {  | 
|---|
| 3220 |  | -                    System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));  | 
|---|
| 3221 |  | -                    dof = thedata.length/numframes;  | 
|---|
| 3222 |  | -                }  | 
|---|
| 3223 |  | -                  | 
|---|
| 3224 |  | -                //for (int f=numframes; --f>=offset;)  | 
|---|
| 3225 |  | -                int firstframe = GetFirstFrame();  | 
|---|
| 3226 |  | -                for (int f=0; f<numframes-firstframe; f++)  | 
|---|
| 3227 |  | -                {  | 
|---|
| 3228 |  | -                    int f3 = f*dof;  | 
|---|
| 3229 |  | -  | 
|---|
| 3230 |  | -                    //for (int i=3/*dof*/; --i>=0;)  | 
|---|
| 3231 |  | -                    for (int i=dof; --i>=0;)  | 
|---|
| 3232 |  | -                    {  | 
|---|
| 3233 |  | -                        //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];  | 
|---|
| 3234 |  | -                        thedata[f3 + i] = thedata[f3 + firstframe*dof + i];  | 
|---|
| 3235 |  | -                    }  | 
|---|
| 3236 |  | -                }  | 
|---|
| 3237 |  | -            }  | 
|---|
 | 3503 | +        {  | 
|---|
 | 3504 | +            LoadData();  | 
|---|
 | 3505 | +        }  | 
|---|
| 3238 | 3506 |               | 
|---|
| 3239 | 3507 |         //     assert(thedata[0] == 0); | 
|---|
| 3240 | 3508 |         //     assert(thedata[1] == 0); | 
|---|
| .. | .. | 
|---|
| 3244 | 3512 |         //     assert(thedata[7] == 0); | 
|---|
| 3245 | 3513 |         //     assert(thedata[8] == 0); | 
|---|
| 3246 | 3514 |               | 
|---|
| 3247 |  | -        Object3D obj = get(0);  | 
|---|
 | 3515 | +        Object3D hip = get(0);  | 
|---|
| 3248 | 3516 |           | 
|---|
| 3249 | 3517 |  //        assert(obj.name.equals("hip")); | 
|---|
| 3250 | 3518 |           | 
|---|
| 3251 |  | -        Object3D rot = obj.get(0);  | 
|---|
 | 3519 | +        Object3D rot = hip.get(0);  | 
|---|
| 3252 | 3520 |           | 
|---|
| 3253 | 3521 |  //        if (toParent == null) | 
|---|
| 3254 | 3522 |  //        { | 
|---|
| .. | .. | 
|---|
| 3260 | 3528 |  //    //    assert(obj.name == null); // .equals("hip#")); | 
|---|
| 3261 | 3529 |           | 
|---|
| 3262 | 3530 |          Invariants(); | 
|---|
| 3263 |  | -        obj.Invariants();  | 
|---|
 | 3531 | +        hip.Invariants();  | 
|---|
| 3264 | 3532 |          rot.Invariants(); | 
|---|
| 3265 | 3533 |           | 
|---|
| 3266 | 3534 |          if (origin == null) | 
|---|
| .. | .. | 
|---|
| 3281 | 3549 |              fromParent = LA.newMatrix();             | 
|---|
| 3282 | 3550 |          } | 
|---|
| 3283 | 3551 |           | 
|---|
| 3284 |  | -        if (obj.toParent == null) // june 2014  | 
|---|
 | 3552 | +        if (hip.toParent == null) // june 2014  | 
|---|
| 3285 | 3553 |          { | 
|---|
| 3286 |  | -            obj.toParent = LA.newMatrix();  | 
|---|
| 3287 |  | -            obj.fromParent = LA.newMatrix();              | 
|---|
 | 3554 | +            hip.toParent = LA.newMatrix();  | 
|---|
 | 3555 | +            hip.fromParent = LA.newMatrix();              | 
|---|
| 3288 | 3556 |          } | 
|---|
| 3289 | 3557 |           | 
|---|
| 3290 |  | -        LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB  | 
|---|
 | 3558 | +        LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB  | 
|---|
| 3291 | 3559 |          Object3D gp = this.parent; | 
|---|
| 3292 | 3560 |          this.parent = null; | 
|---|
| 3293 |  | -        obj.GlobalTransformInv();  | 
|---|
 | 3561 | +        hip.GlobalTransformInv();  | 
|---|
| 3294 | 3562 |          this.parent = gp; | 
|---|
| 3295 | 3563 |           | 
|---|
| 3296 | 3564 |          if (rot.toParent == null) | 
|---|
| .. | .. | 
|---|
| 3313 | 3581 |          LA.matInvert(origin.toParent, origin.fromParent); | 
|---|
| 3314 | 3582 |   | 
|---|
| 3315 | 3583 |          Invariants(); | 
|---|
| 3316 |  | -        obj.Invariants();  | 
|---|
 | 3584 | +        hip.Invariants();  | 
|---|
| 3317 | 3585 |          rot.Invariants(); | 
|---|
| 3318 | 3586 |          origin.Invariants(); | 
|---|
| 3319 | 3587 |          origin0.Invariants(); | 
|---|
| 3320 | 3588 |   | 
|---|
| 3321 |  | -        firsttimeafterload = true;  | 
|---|
 | 3589 | +        firsttimeafterload = false; // true;  | 
|---|
| 3322 | 3590 |            | 
|---|
| 3323 | 3591 |          if (rewind) | 
|---|
| 3324 | 3592 |              Rewind(); | 
|---|
| 3325 | 3593 |           | 
|---|
| 3326 |  | -        setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);  | 
|---|
 | 3594 | +        setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);  | 
|---|
| 3327 | 3595 |           | 
|---|
| 3328 |  | -        if (true)  | 
|---|
| 3329 |  | -            return;  | 
|---|
 | 3596 | +    if (true)  | 
|---|
 | 3597 | +        return;  | 
|---|
| 3330 | 3598 |           | 
|---|
| 3331 | 3599 |          double pos[] = new double[6]; | 
|---|
| 3332 | 3600 |           | 
|---|
| 3333 | 3601 |          if (!reset) | 
|---|
| 3334 | 3602 |          { | 
|---|
| 3335 |  | -            assert(obj.tx == obj.toParent[3][0]);  | 
|---|
| 3336 |  | -            assert(obj.ty == obj.toParent[3][1]);  | 
|---|
| 3337 |  | -            assert(obj.tz == obj.toParent[3][2]);  | 
|---|
 | 3603 | +            assert(hip.tx == hip.toParent[3][0]);  | 
|---|
 | 3604 | +            assert(hip.ty == hip.toParent[3][1]);  | 
|---|
 | 3605 | +            assert(hip.tz == hip.toParent[3][2]);  | 
|---|
| 3338 | 3606 |   | 
|---|
| 3339 |  | -            pos[0] = obj.tx; // obj.toParent[3][0];  | 
|---|
| 3340 |  | -            pos[1] = obj.ty; // obj.toParent[3][1];  | 
|---|
| 3341 |  | -            pos[2] = obj.tz; // obj.toParent[3][2];  | 
|---|
| 3342 |  | -            pos[3] = obj.rz;  | 
|---|
| 3343 |  | -            pos[4] = obj.ry;  | 
|---|
| 3344 |  | -            pos[5] = obj.rx;  | 
|---|
 | 3607 | +            pos[0] = hip.tx; // obj.toParent[3][0];  | 
|---|
 | 3608 | +            pos[1] = hip.ty; // obj.toParent[3][1];  | 
|---|
 | 3609 | +            pos[2] = hip.tz; // obj.toParent[3][2];  | 
|---|
 | 3610 | +            pos[3] = hip.rz;  | 
|---|
 | 3611 | +            pos[4] = hip.ry;  | 
|---|
 | 3612 | +            pos[5] = hip.rx;  | 
|---|
| 3345 | 3613 |          } | 
|---|
| 3346 | 3614 |           | 
|---|
| 3347 | 3615 |          cVector temp = new cVector(); | 
|---|
| 3348 |  | -        temp.x = obj.globalTransform[3][0];  | 
|---|
| 3349 |  | -        temp.y = obj.globalTransform[3][1];  | 
|---|
| 3350 |  | -        temp.z = obj.globalTransform[3][2];  | 
|---|
 | 3616 | +        temp.x = hip.globalTransform[3][0];  | 
|---|
 | 3617 | +        temp.y = hip.globalTransform[3][1];  | 
|---|
 | 3618 | +        temp.z = hip.globalTransform[3][2];  | 
|---|
| 3351 | 3619 |  //        LA.xformPos(temp, origin0.toParent, temp); | 
|---|
| 3352 | 3620 |  //        System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";"); | 
|---|
| 3353 | 3621 |           | 
|---|
| .. | .. | 
|---|
| 3431 | 3699 |          } | 
|---|
| 3432 | 3700 |           | 
|---|
| 3433 | 3701 |  //        Rewind(); | 
|---|
| 3434 |  | -        setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);  | 
|---|
 | 3702 | +        setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);  | 
|---|
| 3435 | 3703 |      } | 
|---|
| 3436 | 3704 |       | 
|---|
| 3437 | 3705 |      void Rewind() | 
|---|