Ejemplo n.º 1
0
            public void update(Frame3f handF)
            {
                curHandF = handF;

                // [RMS] this function updates the position of object based on hand frame
                //  Not clear how this should work, there are lots of options...

                // [1] scaled relative motion of hand inherited by object  (lags ray though)
                //Vector3f dt = startHandF.ToFrameP(handF.Origin);
                //dt *= 10.0f;
                //Frame3f fNew = new Frame3f(startObjFW);
                //fNew.Origin += dt;

                // [2] object stays on ray, inherits a bit of xform
                //   - resulting orientation is weird. works well for rotate in-place around ray,
                //     but up/down/left/right tilts are impossible w/o moving object
                Frame3f fNew = handF.FromFrame(this.startObjRelF);

                if (RotationSpeed != 1.0f)
                {
                    fNew.Rotation = Quaternionf.Slerp(startObjFW.Rotation, fNew.Rotation, RotationSpeed);
                }
                if (TranslationSpeed != 1.0f)
                {
                    fNew.Origin = Vector3f.Lerp(startObjFW.Origin, fNew.Origin, TranslationSpeed);
                }

                // [3] object stays on ray but no rotation
                //   - weird if you rotate left/right, because distance stays same but it
                //     keeps pointing in same direction
                //   - we have gizmo for this kind of translation.
                //Frame3 fNew = handF.FromFrame(this.startObjRelF);
                //fNew.Rotation = startObjFW.Rotation;

                // [4] object stays in place, rotate by hand rotation
                //   - pretty hard to control, but would be good for approx orienting...
                //   - definitely needs damping!!
                //Frame3 fNew = startObjFW;
                //Quaternion relative = handF.Rotation * Quaternion.Inverse(startHandF.Rotation);
                //fNew.Rotation = relative * fNew.Rotation;

                // apply stick rotation  DOESN"T WORK
                //Quaternion stickY = Quaternion.AngleAxis(stickDelta[1], startHandF.X);
                //fNew.Rotation = fNew.Rotation * stickY;

                // shift in/out along hand-ray by Z
                fNew.Origin += StickSpeed * stickDelta[1] * handF.Z * so.GetScene().GetSceneScale();

                curHandTargetF = fNew;
                curUseTargetF  = new Frame3f(curHandTargetF);

                // update so
                so.SetLocalFrame(curUseTargetF, CoordSpace.WorldCoords);
            }