//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 if ( FInput.PinIsChanged || FRadius.PinIsChanged || FFactor.PinIsChanged || FSpreadCount.PinIsChanged ) { List <Vector3D> outVec = new List <Vector3D>(); double curXSlice, curYSlice, curZSlice, xPos, yPos, zPos; double tmpSize, currentRadius, currentFactor; int currentBinSize = 0, myIncrement = 0; double dlong, l, dz, z, r; //part of the formula dlong = Math.PI * (3 - Math.Sqrt(5.0)); //part of the formula FOutput.SliceCount = 0; //loop for maximal spread count for (int i = 0; i < SpreadMax; i++) { FInput.GetValue3D(i, out curXSlice, out curYSlice, out curZSlice); FRadius.GetValue(i, out currentRadius); FFactor.GetValue(i, out currentFactor); FSpreadCount.GetValue(i, out tmpSize); currentBinSize = (int)Math.Round(tmpSize); //use spreadcount as an integer dz = (currentFactor * 2.0) / currentBinSize; //part of the formula z = 1.0 - dz / 2.0; //part of the formula l = 0.0; //part of the formula //loop for each bin size for (int j = 0; j < currentBinSize; j++) { r = Math.Sqrt(1.0 - z * z); xPos = Math.Cos(l) * r * currentRadius; yPos = Math.Sin(l) * r * currentRadius; zPos = z * currentRadius; z = z - dz; l = l + dlong; //set output outVec.Add(new Vector3D(xPos + curXSlice, yPos + curYSlice, zPos + curZSlice)); } myIncrement += currentBinSize; } FOutput.SliceCount = outVec.Count; for (int i = 0; i < outVec.Count; i++) { FOutput.SetValue3D(i, outVec[i].x, outVec[i].y, outVec[i].z); } } }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { /* originally it was * int sliceCount = VMath.Binomial(FMyValueInput.SliceCount, 2)*2; * but this algorithm is better */ int sliceCount = 0; for (int i = 1; i < FMyValueInput.SliceCount; i++) { sliceCount += i; } sliceCount *= 2; //FHost.Log(TLogType.Debug, "sliceCount = " + sliceCount); //if any of the inputs has changed //recompute the outputs if (FMyValueInput.PinIsChanged) { FMyValueOutput.SliceCount = sliceCount; double x1, y1, z1, x2, y2, z2; int counter = 0; //loop for all slices for (int i = 0; i < FMyValueInput.SliceCount; i++) { //read data from inputs FMyValueInput.GetValue3D(i, out x1, out y1, out z1); for (int j = i + 1; j < FMyValueInput.SliceCount; j++) { FMyValueOutput.SetValue3D(counter, x1, y1, z1); counter++; FMyValueInput.GetValue3D(j, out x2, out y2, out z2); FMyValueOutput.SetValue3D(counter, x2, y2, z2); counter++; } } } }
//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 if (FPinInVertices.PinIsChanged || FPinInCenter.PinIsChanged || FPinInRadius.PinIsChanged) { /* * FHost.Log(TLogType.Debug, "FPinInVertices.SliceCount " + FPinInVertices.SliceCount); * FHost.Log(TLogType.Debug, "FPinInCenter.SliceCount " + FPinInCenter.SliceCount); * FHost.Log(TLogType.Debug, "FPinInRadius.SliceCount " + FPinInRadius.SliceCount); */ FPinOutVertices.SliceCount = FPinInVertices.SliceCount * FPinInCenter.SliceCount * FPinInRadius.SliceCount; int index = 0; double pointX, pointY, pointZ; double radius; double centerX, centerY, centerZ; double inversionFactor; //loop for all slices for (int i = 0; i < FPinInVertices.SliceCount; i++) { FPinInVertices.GetValue3D(i, out pointX, out pointY, out pointZ); for (int j = 0; j < FPinInCenter.SliceCount; j++) { FPinInCenter.GetValue3D(j, out centerX, out centerY, out centerZ); pointX -= centerX; pointY -= centerY; pointZ -= centerZ; for (int k = 0; k < FPinInRadius.SliceCount; k++) { FPinInRadius.GetValue(k, out radius); inversionFactor = radius * radius / (pointX * pointX + pointY * pointY + pointZ * pointZ); pointX *= inversionFactor; pointY *= inversionFactor; pointZ *= inversionFactor; pointX += centerX; pointY += centerY; pointZ += centerZ; FPinOutVertices.SetValue3D(index, pointX, pointY, pointZ); index++; } } } } }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { FPositionPin.SetValue3D(0, FSensor.Translation.X, FSensor.Translation.Y, FSensor.Translation.Z); FRotationPin.SetValue3D(0, FSensor.Rotation.X, FSensor.Rotation.Y, FSensor.Rotation.Z); FAnglePin.SetValue(0, FSensor.Rotation.Angle); for (int i = 0; i < FKeyboard.Keys; i++) { if (FKeyboard.IsKeyDown(i + 1)) { FKeyboardPin.SetValue(i, 1); } else { FKeyboardPin.SetValue(i, 0); } } FDeviceTypePin.SetValue(0, FDeviceType); }
private void Nunchuk() { FPinOutputExtButtons.SliceCount = 1; FPinOutputExtButtons.SetValue(0, FRemote.WiimoteState.NunchukState.C?1d:0d); FPinOutputExtButtons.SetValue(1, FRemote.WiimoteState.NunchukState.Z?1d:0d); FPinOutputExtTilt.SliceCount = 1; FPinOutputExtTilt.SetValue3D(0, FRemote.WiimoteState.NunchukState.AccelState.Values.X, FRemote.WiimoteState.NunchukState.AccelState.Values.Y, FRemote.WiimoteState.NunchukState.AccelState.Values.Z); double[] normalizedA = new double[3]; normalizedA[0] = (double)((FRemote.WiimoteState.NunchukState.AccelState.RawValues.X - 128)) / 128d; normalizedA[1] = (double)((FRemote.WiimoteState.NunchukState.AccelState.RawValues.Y - 128)) / 128d; normalizedA[2] = (double)((FRemote.WiimoteState.NunchukState.AccelState.RawValues.Z - 128)) / 128d; FPinOutputExtAccelleration.SliceCount = 1; FPinOutputExtAccelleration.SetValue3D(0, normalizedA[0], normalizedA[1], normalizedA[2]); FPinOutputExtJoystickLeft.SliceCount = 1; FPinOutputExtJoystickLeft.SetValue(0, FRemote.WiimoteState.NunchukState.Joystick.X * 2); FPinOutputExtJoystickLeft.SetValue(1, FRemote.WiimoteState.NunchukState.Joystick.Y * 2); }
public void Evaluate(int SpreadMax) { //calc input spreadcount int inputSpreadCount = SpreadMax; //create or delete systems int diff = inputSpreadCount - FParticleSystemsList.Count; if (diff > 0) { for (int i = 0; i < diff; i++) { FParticleSystemsList.Add(new ParticleSystem()); } } else if (diff < 0) { for (int i = 0; i < -diff; i++) { FParticleSystemsList.RemoveAt(FParticleSystemsList.Count - 1 - i); } } //update 3D parameters int slice; if (FInitPositionsIn.PinIsChanged || FVelDirectionIn.PinIsChanged || FVelDeviationIn.PinIsChanged || FAccDirectionIn.PinIsChanged || FAccDeviationIn.PinIsChanged) { for (slice = 0; slice < inputSpreadCount; slice++) { ParticleSystem ps = (ParticleSystem)FParticleSystemsList[slice]; double x, y, z; //update origins FInitPositionsIn.GetValue3D(slice, out x, out y, out z); ps.origin = new Vector3D(x, y, z); //update directions FVelDirectionIn.GetValue3D(slice, out x, out y, out z); ps.direction = new Vector3D(x, y, z); //update deviation FVelDeviationIn.GetValue3D(slice, out x, out y, out z); ps.deviation = new Vector3D(x, y, z); //update acceleration deviation FAccDirectionIn.GetValue3D(slice, out x, out y, out z); ps.accDirection = new Vector3D(x, y, z); //update acceleration deviation FAccDeviationIn.GetValue3D(slice, out x, out y, out z); ps.accDeviation = new Vector3D(x, y, z); } } //update single parameters if (FMassIn.PinIsChanged || FMassDeviationIn.PinIsChanged || FLifetimeIn.PinIsChanged || FLifetimeDeviationIn.PinIsChanged || FIsInfluencedIn.PinIsChanged || FInfluenceIn.PinIsChanged || FInfluenceAmountIn.PinIsChanged || FdtIn.PinIsChanged) { for (slice = 0; slice < inputSpreadCount; slice++) { ParticleSystem ps = (ParticleSystem)FParticleSystemsList[slice]; double mass, massDeviation; double lifetimeIn, lifetimeDeviation; double isInfluenced, influenceAmount, influences; double dt; FMassIn.GetValue(slice, out mass); FMassDeviationIn.GetValue(slice, out massDeviation); FLifetimeIn.GetValue(slice, out lifetimeIn); FLifetimeDeviationIn.GetValue(slice, out lifetimeDeviation); FIsInfluencedIn.GetValue(slice, out isInfluenced); FInfluenceAmountIn.GetValue(slice, out influenceAmount); FInfluenceIn.GetValue(slice, out influences); FdtIn.GetValue(slice, out dt); ps.mass = mass; ps.massDeviation = massDeviation; ps.lifetime = lifetimeIn; ps.lifetimeDeviation = lifetimeDeviation; ps.influences = (influences >= 0.5); ps.isInfluenced = (isInfluenced >= 0.5); ps.influenceAmount = influenceAmount; ps.dt = dt; } } //force calculation UpdateForce(); // Cycle through all particle systems, run them and get particle counts FSpreadCountsOut.SliceCount = FParticleSystemsList.Count; int outcount = 0; slice = 0; for (slice = 0; slice < inputSpreadCount; slice++) { ParticleSystem ps = (ParticleSystem)FParticleSystemsList[slice]; //add new particle ? double emit; FEmitIn.GetValue(slice, out emit); if (emit >= 0.5) { ps.addParticle(); } //update system double time; FHost.GetCurrentTime(out time); ps.run(0.1); FLastTime = time; //check particle count outcount += ps.particles.Count; FSpreadCountsOut.SetValue(slice, ps.particles.Count); } //write output to pins FPosOut.SliceCount = outcount; FAgeOut.SliceCount = outcount; FHeadingOut.SliceCount = outcount; slice = 0; for (int i = 0; i < inputSpreadCount; i++) { ParticleSystem ps = (ParticleSystem)FParticleSystemsList[i]; int pcount = ps.particles.Count; for (int j = 0; j < pcount; j++) { Particle p = (Particle)ps.particles[j]; FPosOut.SetValue3D(slice, p.loc.x, p.loc.y, p.loc.z); FHeadingOut.SetValue3D(slice, p.vel.x, p.vel.y, p.vel.z); FAgeOut.SetValue(slice, 1 - p.age()); slice++; } } }
//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 FP1.SliceCount = SpreadMax; FP2.SliceCount = SpreadMax; FIntersections.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { double Ax, Ay, Az; double Bx, By, Bz; double Cx, Cy, Cz; FA.GetValue3D(0, out Ax, out Ay, out Az); FB.GetValue3D(0, out Bx, out By, out Bz); FC.GetValue3D(0, out Cx, out Cy, out Cz); double r_a, r_b, r_c; FRA.GetValue(i, out r_a); FRB.GetValue(i, out r_b); FRC.GetValue(i, out r_c); double P1x = 0, P1y = 0, P1z = 0; double P2x = 0, P2y = 0, P2z = 0; double Asquare = Math.Pow(Ax, 2) + Math.Pow(Ay, 2) + Math.Pow(Az, 2); double Bsquare = Math.Pow(Bx, 2) + Math.Pow(By, 2) + Math.Pow(Bz, 2); double Csquare = Math.Pow(Cx, 2) + Math.Pow(Cy, 2) + Math.Pow(Cz, 2); double ABx = Bx - Ax; double ABy = By - Ay; double ABz = Bz - Az; double ACx = Cx - Ax; double ACy = Cy - Ay; double ACz = Cz - Az; double m = (Math.Pow(r_a, 2) - Math.Pow(r_b, 2) - Asquare + Bsquare) * ACz; double n = (Math.Pow(r_a, 2) - Math.Pow(r_c, 2) - Asquare + Csquare) * ABz; double o = ABy * ACz - ACy * ABz; double q = ACx * ABz - ABx * ACz; double v = (Math.Pow(r_a, 2) - Math.Pow(r_b, 2) - Asquare + Bsquare) / (2 * ABz) - Az; double w = (1 + Math.Pow(ABy, 2) / Math.Pow(ABz, 2)); double r = ABx / ABz; double s = ABy / ABz; double t = Math.Pow(Ax, 2) + Math.Pow(Ay, 2) + Math.Pow(v, 2) - Math.Pow(r_a, 2); double a = (m - n) / (2 * o); double b = q / o; //(1+r^2+b^2*w+2brs)P.x^2 + (2abw+2ars-2A.x-2rv-2b(A.y + sv))P.x + w*a^2 - 2a(A.y + sv) + t = 0 int solutions; QuadraticEquation(1 + Math.Pow(r, 2) + Math.Pow(b, 2) * w + 2 * b * r * s, 2 * a * b * w + 2 * a * r * s - 2 * Ax - 2 * r * v - 2 * b * (Ay + s * v), w * Math.Pow(a, 2) - 2 * a * (Ay + s * v) + t, out P1x, out P2x, out solutions); FIntersections.SetValue(i, solutions); P1y = P1x * b + a; //P.z = (r_a^2 - r_b^2 - 2*P.x*AB.x - 2*P.y*AB.y - |A|^2 + |B|^2) / (2*AB.z) P1z = (Math.Pow(r_a, 2) - Math.Pow(r_b, 2) - 2 * P1x * ABx - 2 * P1y * ABy - Asquare + Bsquare) / (2 * ABz); P2y = P2x * b + a; P2z = (Math.Pow(r_a, 2) - Math.Pow(r_b, 2) - 2 * P2x * ABx - 2 * P2y * ABy - Asquare + Bsquare) / (2 * ABz); FP1.SetValue3D(i, P1x, P1y, P1z); FP2.SetValue3D(i, P2x, P2y, P2z); } }
//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); } }