
Just some stuff I'm messing around with...
int Iterations = 128; float2 Pan = float2(0.5, 0); float Zoom = 3; float Aspect = 1; float2 JuliaSeed = float2(0.39, -0.2); float3 ColorScale = float3(4, 5, 6); float ComputeValue(float2 v, float2 offset) { float vxsquare = 0; float vysquare = 0; int iteration = 0; int lastIteration = Iterations; do { vxsquare = v.x * v.x; vysquare = v.y * v.y; v = float2(vxsquare - vysquare, v.x * v.y * 2) + offset; iteration++; if ((lastIteration == Iterations) && (vxsquare + vysquare) > 4.0) { lastIteration = iteration + 1; } } while (iteration < lastIteration); return (float(iteration) - (log(log(sqrt(vxsquare + vysquare))) / log(2.0))) / float(Iterations); } float4 Mandelbrot_PixelShader(float2 texCoord : TEXCOORD0) : COLOR0 { float2 v = (texCoord - 0.5) * Zoom * float2(1, Aspect) - Pan; float val = ComputeValue(v, v); return float4(sin(val * ColorScale.x), sin(val * ColorScale.y), sin(val * ColorScale.z), 1); } float4 Julia_PixelShader(float2 texCoord : TEXCOORD0) : COLOR0 { float2 v = (texCoord - 0.5) * Zoom * float2(1, Aspect) - Pan; float val = ComputeValue(v, JuliaSeed); return float4(sin(val * ColorScale.x), sin(val * ColorScale.y), sin(val * ColorScale.z), 1); } technique Mandelbrot { pass { PixelShader = compile ps_3_0 Mandelbrot_PixelShader(); } } technique Julia { pass { PixelShader = compile ps_3_0 Julia_PixelShader(); } }
renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, 1,
format, GraphicsDevice.DepthStencilBuffer.MultiSampleType, GraphicsDevice.PresentationParameters.MultiSampleQuality);
renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, 1,
format, GraphicsDevice.DepthStencilBuffer.MultiSampleType, GraphicsDevice.PresentationParameters.MultiSampleQuality);
public class Vibration
{
float leftMotor;
float rightMotor;
float msLeft;
public float LeftMotor
{
get { return leftMotor; }
set { leftMotor = value; }
}
public float RightMotor
{
get { return rightMotor; }
set { rightMotor = value; }
}
public float MSLeft
{
get { return msLeft; }
set { msLeft = value; }
}
public Vibration(float leftMotor, float rightMotor, float durationMS)
{
this.leftMotor = leftMotor;
this.rightMotor = rightMotor;
this.msLeft = durationMS;
}
}
public class ForceFeedbackManager
{
private PlayerIndex playerIndex;
List<Vibration> vibrations = new List<Vibration>();
public ForceFeedbackManager(PlayerIndex playerIndex)
{
this.playerIndex = playerIndex;
}
public void AddVibration(float leftMotor, float rightMotor, float durationMS)
{
vibrations.Add(new Vibration(leftMotor, rightMotor, durationMS));
}
public void Update(float msElapsed)
{
List<Vibration> toDelete = new List<Vibration>();
foreach (Vibration vibration in vibrations)
{
vibration.MSLeft -= msElapsed;
if (vibration.MSLeft < 0.0f)
{
toDelete.Add(vibration);
}
}
foreach (Vibration vibration in toDelete)
{
vibrations.Remove(vibration);
}
float leftMotor;
float rightMotor;
GetVibration(out leftMotor, out rightMotor);
GamePad.SetVibration(playerIndex, leftMotor, rightMotor);
}
public void GetVibration(out float leftMotor, out float rightMotor)
{
leftMotor = 0.0f;
rightMotor = 0.0f;
foreach (Vibration vibration in vibrations)
{
leftMotor = Math.Max(leftMotor, vibration.LeftMotor);
rightMotor = Math.Max(rightMotor, vibration.RightMotor);
}
}
}
public delegate void ProgressWorkerDelegate(IProgressContext progressContext); public partial class ProgressDialog : Window, IProgressContext { private bool canceled = false; private ProgressWorkerDelegate workDelegate = null; public bool Canceled { get { return canceled; } } public ProgressDialog() : this(null) { } public ProgressDialog(ProgressWorkerDelegate workDelegate) : this(workDelegate, false) { } public ProgressDialog(ProgressWorkerDelegate workDelegate, bool startInBackground) { this.workDelegate = workDelegate; InitializeComponent(); CancelButton.Click += new RoutedEventHandler(CancelButton_Click); if (workDelegate != null) { if (startInBackground) { new Thread(new ThreadStart(StartWork)).Start(); } else { StartWork(); } } } private void StartWork() { workDelegate(this); } void CancelButton_Click(object sender, RoutedEventArgs e) { canceled = true; CancelButton.IsEnabled = false; } public void UpdateProgress(double progress) { Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { Progress.SetValue(ProgressBar.ValueProperty, progress); }, null); } public void UpdateStatus(string status) { Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { StatusText.SetValue(TextBlock.TextProperty, status); }, null); } public void Finish() { Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { Close(); }, null); } }
ProgressDialog progressDialog = new ProgressDialog(MyWorkFunction, true); progressDialog.ShowDialog();
void MyWorkFunction(IProgressContext progressContext) { for (int i = 0; i < 100; i++) { if (myProgressContext.Canceled) break; progressContext.UpdateProgress((double)i / 100.0); progressContext.UpdateStatus("Doing Step " + i); } progressContext.Finish(); }