Beispiel #1
0
 //here we go, thats the method called by vvvv each frame
 //all data handling should be in here
 public void Evaluate(int SpreadMax)
 {
     if (FSpeedInput.PinIsChanged || FNarratorInput.PinIsChanged || FStringInput.PinIsChanged)
     {
         //loop for all slices
         for (int i = 0; i < SpreadMax; i++)
         {
             //read data from inputs
             double rate = 5.0;
             FSpeedInput.GetValue(i, out rate);
             vox.Rate = (int)rate;
             int voiceindex = 0;
             FNarratorInput.GetOrd(i, out voiceindex);
             vox.Voice = vox.GetVoices(string.Empty, string.Empty).Item(voiceindex);
             FStringInput.GetString(i, out input_string);
         }
     }
     if (FSpeakInput.PinIsChanged)
     {
         double speak = 0.0;
         FSpeakInput.GetValue(0, out speak);
         if (speak > 0.5)
         {
             vox.Speak(input_string, SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
         }
     }
     //remember that we are running with autoevaluate == true
     if (done == true)   //endstream was fired
     {
         done = false;
         FDoneOutput.SetValue(0, 1.0);
     }
     else
     {
         FDoneOutput.SetValue(0, 0.0);
     }
 }
Beispiel #2
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs

            bool recalculate = false;

            if (FJointNameInput.PinIsChanged)
            {
                jointNames = new List <string>();
                string jointName;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    FJointNameInput.GetString(i, out jointName);
                    jointNames.Add(jointName);
                }
                recalculate = true;
                if (jointNames.Count == 1 && string.IsNullOrEmpty(jointNames[0]))
                {
                    jointsSelected = false;
                }
                else
                {
                    jointsSelected = true;
                }
            }

            if (FSkeletonInput.PinIsChanged)
            {
                if (FSkeletonInput.IsConnected)
                {
                    object currInterface;
                    FSkeletonInput.GetUpstreamInterface(out currInterface);
                    inputSkeleton = (Skeleton)currInterface;

                    // if there are no specific joints selected via input pin, collect them all
                    if (jointNames == null || !jointsSelected)
                    {
                        jointNames = new List <string>();
                        foreach (KeyValuePair <string, IJoint> pair in inputSkeleton.JointTable)
                        {
                            // Only add those with a valid array index.
                            // It's not a must that all bones are used as skinning matrices.
                            if (pair.Value.Id >= 0)
                            {
                                jointNames.Add(pair.Key);
                            }
                        }
                    }
                }
                else
                {
                    inputSkeleton = null;
                }
                recalculate = true;
            }

            if (FInverseBindPoseInput.PinIsChanged)
            {
                recalculate = true;
            }

            if (FOutputModeInput.PinIsChanged)
            {
                FOutputModeInput.GetOrd(0, out outputMode);
                recalculate = true;
            }

            if (recalculate && inputSkeleton != null)
            {
                inputSkeleton.CalculateCombinedTransforms();
                int jointCount;
                if (outputMode == OUTPUT_MODE_DYNAMIC)
                {
                    jointCount = jointNames.Count;
                }
                else
                {
                    jointCount = 60;
                }
                FTransformOutput.SliceCount = jointCount;
                IJoint    currJoint;
                Matrix4x4 currIBPMatrix;
                int       i = 0;
                for (i = 0; i < jointNames.Count; i++)
                {
                    currJoint = inputSkeleton.JointTable[jointNames[i]];
                    if (currJoint != null)
                    {
                        int sliceIndex;
                        if (outputMode == OUTPUT_MODE_STATIC)
                        {
                            sliceIndex = currJoint.Id;
                        }
                        else
                        {
                            sliceIndex = i;
                        }
                        FInverseBindPoseInput.GetMatrix(sliceIndex, out currIBPMatrix);
                        FTransformOutput.SetMatrix(sliceIndex, currIBPMatrix * currJoint.CombinedTransform);
                    }
                }

                // Pad remaining slices with Identity Matrices
                for (int j = i; j < jointCount; j++)
                {
                    FTransformOutput.SetMatrix(j, VMath.IdentityMatrix);
                }
            }
        }
Beispiel #3
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs

            bool recalculate = false;

            if (FJointNameInput.PinIsChanged || FBaseTransformInput.PinIsChanged || FOffsetModeInput.PinIsChanged || FParentNameInput.PinIsChanged || FConstraintsInput.PinIsChanged || recalculate)
            {
                skeleton = new Skeleton();

                int currId = 0;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    string jointName;
                    string parentName;
                    FJointNameInput.GetString(i % FJointNameInput.SliceCount, out jointName);
                    FParentNameInput.GetString(i % FParentNameInput.SliceCount, out parentName);
                    IJoint    currJoint = new JointInfo(jointName);
                    Matrix4x4 baseTransform;
                    FBaseTransformInput.GetMatrix(i % FBaseTransformInput.SliceCount, out baseTransform);
                    currJoint.BaseTransform = baseTransform;             //VMath.Translate(basePositionX, basePositionY, basePositionZ);
                    currJoint.Constraints.Clear();
                    for (int j = i * 3; j < i * 3 + 3; j++)
                    {
                        double constraintMin, constraintMax;
                        FConstraintsInput.GetValue2D(j % FConstraintsInput.SliceCount, out constraintMin, out constraintMax);
                        currJoint.Constraints.Add(new Vector2D(constraintMin, constraintMax));
                    }
                    if (string.IsNullOrEmpty(parentName))
                    {
                        if (skeleton.Root == null)
                        {
                            skeleton.Root = currJoint;
                            currJoint.Id  = currId;
                            currId++;
                            skeleton.BuildJointTable();
                        }
                    }
                    else
                    {
                        if (skeleton.JointTable.ContainsKey(parentName))
                        {
                            currJoint.Parent = skeleton.JointTable[parentName];
                            currJoint.Id     = currId;
                            currId++;
                        }
                        skeleton.BuildJointTable();
                    }
                }

                int positionInWorldSpace = 0;
                FOffsetModeInput.GetOrd(0, out positionInWorldSpace);
                if (positionInWorldSpace > 0)
                {
                    List <Vector3D> offsetList = new List <Vector3D>();
                    foreach (KeyValuePair <string, IJoint> pair in skeleton.JointTable)
                    {
                        Vector3D worldPos = pair.Value.BaseTransform * (new Vector3D(0));
                        Vector3D parentWorldPos;
                        if (pair.Value.Parent != null)
                        {
                            parentWorldPos = pair.Value.Parent.BaseTransform * (new Vector3D(0));
                        }
                        else
                        {
                            parentWorldPos = new Vector3D(0);
                        }
                        Vector3D offset = worldPos - parentWorldPos;
                        offsetList.Add(offset);
                    }
                    int i = 0;
                    foreach (KeyValuePair <string, IJoint> pair in skeleton.JointTable)
                    {
                        pair.Value.BaseTransform = VMath.Translate(offsetList[i]);
                        i++;
                    }
                }


                FSkeletonOutput.MarkPinAsChanged();
            }

            FSkeletonOutput.SetInterface(skeleton);
        }
Beispiel #4
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here

        // WiiMote is not spreadable (mostly due to the IR thingy and by now also because of the extension architecture
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FPinInputEnable.PinIsChanged || FPinInputID.PinIsChanged)
            {
                Enable();
                FInvalidate = true;
            }

            if (FWorking && (FPinInputMode.PinIsChanged || FPinInputEnable.PinIsChanged))
            {
                FPinInputMode.GetOrd(0, out FIRMode);
                if (FIRMode == 0)
                {
                    FIRMode = 1;
                }

                switch (FIRMode)
                {
                case 3: FRemote.WiimoteState.IRState.Mode = IRMode.Off;
                    break;

                case 2: FRemote.WiimoteState.IRState.Mode = IRMode.Basic;
                    break;

                case 1: FRemote.WiimoteState.IRState.Mode = IRMode.Extended;
                    break;

                case 0: FRemote.WiimoteState.IRState.Mode = IRMode.Full;
                    break;
                }
                FRemote.GetStatus();
                FInvalidate = true;
            }

            FPinOutputWorking.SetString(0, FWorking?"OK: " + FRemote.WiimoteState.IRState.Mode.ToString():FMessage);

            if (!FWorking)
            {
                return;
            }


            if (FPinForceReset.PinIsChanged)
            {
                double reset;
                FPinForceReset.GetValue(0, out reset);

                if (reset == 1d)
                {
                    if (FRemote.WiimoteState.Extension)
                    {
                        FRemote.SetReportType(InputReport.IRExtensionAccel, true);
                    }
                    else
                    {
                        FRemote.SetReportType(InputReport.IRAccel, true);
                    }
                }
            }

            if (FPinInputRumble.PinIsChanged || FPinInputEnable.PinIsChanged)
            {
                double rumble;
                FPinInputRumble.GetValue(0, out rumble);
                FRemote.SetRumble(rumble == 1d?true:false);
            }

            if (FPinInputLED.PinIsChanged || FPinInputEnable.PinIsChanged)
            {
                double[] dLed = new double[4];
                bool[]   led  = new bool[4];
                for (int i = 0; i < 4; i++)
                {
                    FPinInputLED.GetValue(i, out dLed[i]);
                    led[i] = (dLed[i] == 1d)?true:false;
                }
                FRemote.SetLEDs(led[0], led[1], led[2], led[3]);
            }


//			careful with this... it will permanently override all factory calibration of your wiimote.
            if ((FPinInputEnable.PinIsChanged || FPinInputCalibrate.PinIsChanged) && (FPinInputCalibrate.PinIsChanged))
            {
                byte[,] data = new byte[3, 2];
                double output;

                for (int i = 0; i < 3; i++)
                {
                    FPinInputCalibrationOneG.GetValue(i, out output);
                    data[i, 0] = (byte)(output);
                    FPinInputCalibrationZeroG.GetValue(i, out output);
                    data[i, 1] = (byte)(output);
                }

                double calibrate;
                FPinInputCalibrate.GetValue(0, out calibrate);

                if (calibrate == 1d)
                {
                    FRemote.WiimoteState.AccelCalibrationInfo.X0 = data[0, 0];
                    FRemote.WiimoteState.AccelCalibrationInfo.Y0 = data[1, 0];
                    FRemote.WiimoteState.AccelCalibrationInfo.Z0 = data[2, 0];
                    FRemote.WiimoteState.AccelCalibrationInfo.XG = data[0, 1];
                    FRemote.WiimoteState.AccelCalibrationInfo.YG = data[1, 1];
                    FRemote.WiimoteState.AccelCalibrationInfo.ZG = data[2, 1];
                }
                FInvalidate = true;
            }

            if (FInvalidate)
            {
                FPinOutputCursor.SliceCount = 1;
                FPinOutputCursor.SetValue(0, FRemote.WiimoteState.ButtonState.Up?1d:0d);
                FPinOutputCursor.SetValue(1, FRemote.WiimoteState.ButtonState.Down?1d:0d);
                FPinOutputCursor.SetValue(2, FRemote.WiimoteState.ButtonState.Left?1d:0d);
                FPinOutputCursor.SetValue(3, FRemote.WiimoteState.ButtonState.Right?1d:0d);

                FPinOutputControls.SliceCount = 1;
                FPinOutputControls.SetValue(0, FRemote.WiimoteState.ButtonState.Plus?1d:0d);
                FPinOutputControls.SetValue(1, FRemote.WiimoteState.ButtonState.Minus?1d:0d);
                FPinOutputControls.SetValue(2, FRemote.WiimoteState.ButtonState.Home?1d:0d);

                FPinOutputButtons.SliceCount = 1;
                FPinOutputButtons.SetValue(0, FRemote.WiimoteState.ButtonState.A?1d:0d);
                FPinOutputButtons.SetValue(1, FRemote.WiimoteState.ButtonState.B?1d:0d);
                FPinOutputButtons.SetValue(2, FRemote.WiimoteState.ButtonState.One?1d:0d);
                FPinOutputButtons.SetValue(3, FRemote.WiimoteState.ButtonState.Two?1d:0d);

                FPinOutputTilt.SliceCount = 1;
                FPinOutputTilt.SetValue3D(0, FRemote.WiimoteState.AccelState.Values.X, FRemote.WiimoteState.AccelState.Values.Y, FRemote.WiimoteState.AccelState.Values.Z);

                double[] normalizedA = new double[3];
                normalizedA[0] = (double)((FRemote.WiimoteState.AccelState.RawValues.X - 128)) / 128d;
                normalizedA[1] = (double)((FRemote.WiimoteState.AccelState.RawValues.Y - 128)) / 128d;
                normalizedA[2] = (double)((FRemote.WiimoteState.AccelState.RawValues.Z - 128)) / 128d;
                FPinOutputAccelleration.SliceCount = 1;
                FPinOutputAccelleration.SetValue3D(0, normalizedA[0], normalizedA[1], normalizedA[2]);

                FPinOutputBattery.SetValue(0, (double)FRemote.WiimoteState.Battery / 0xFF);

                int irCount = 0;
                if (FIRMode == 0)
                {
                    irCount = 4;                               // Full
                }
                if (FIRMode == 1)
                {
                    irCount = 4;                               // Extended
                }
                if (FIRMode == 2)
                {
                    irCount = 2;                               // Basic
                }
                if (FIRMode == 3)
                {
                    irCount = 0;                               // Of
                }
                FPinOutputInfraredBlobs.SliceCount = irCount;

                for (int i = 0; i < irCount; i++)
                {
                    FPinOutputInfraredBlobs.SetValue3D(i, FRemote.WiimoteState.IRState.IRSensors[i].RawPosition.X, FRemote.WiimoteState.IRState.IRSensors[i].RawPosition.Y, FRemote.WiimoteState.IRState.IRSensors[i].Size);
                }

//			MotionPlus
                if (FUseMotionPlus)
                {
//					MotionPlus();
                }


                FInvalidate = false;

                ExtensionType ext        = FRemote.WiimoteState.ExtensionType;
                string        enabledExt = FRemote.WiimoteState.Extension?" disabled":"";
                if (ext == ExtensionType.Nunchuk && FExtension == 1)
                {
                    Nunchuk();
                    enabledExt = " enabled";
                }

                if (ext == ExtensionType.ClassicController && FExtension == 2)
                {
                    Classic();
                    enabledExt = " enabled";
                }

                if (ext == ExtensionType.BalanceBoard && FExtension == 3)
                {
                    BalanceBoard();
                    enabledExt = " enabled";
                }

                if (ext == ExtensionType.Guitar && FExtension == 4)
                {
                    Guitar();
                    enabledExt = " enabled";
                }
                FPinOutputExtensionFound.SetString(0, ext.ToString() + enabledExt);
            }
        }