Head Track Release Candidate

Posted in C0BRA on November 18th, 2012 by C0BRA – 10 Comments

I wanted to get coordinate remapping in before a release candidate, unfortunately I can’t seem to make it happen so the device will have one specific orientation that it will need to be placed in for it to work correctly (if you can help me with this then please don’t hesitate to contact me!).

You can edit the way the filtering/scaling is done by modifying “/lua/default.lua” and “/lua/scale.lua”, the one I used in the video is EWMA filtering, so you can use that by backing up “/lua/default.lua” and renaming “/lua/ewma.lua” to “/lua/default.lua”.

I will be writing better instructions and usage guide at http://xiatek.org/headtrack at a later date, but for now please report any bugs you encounter at http://bugs.xiatek.org/

Thank you.

Download:

Android application (direct link to APK)
Server

FreeTrack via Android Phone

Posted in C0BRA on October 16th, 2012 by C0BRA – 3 Comments

Over the past few weeks, I’ve been experimenting with FreeTrack and the gyroscope built into my phone (Galaxy Nexus); if you attempt to pipe the orientation obtained from the device straight into a FreeTrack compatible game, you will end up with a shaky and temperamental camera that isn’t quite sure where it wants to go (gyroscope drift + correction using the magnetic field) as seen here:

You can just slap a moving average on, but it results in undesirable input lag. Over the past week or two, I’ve been continually improving the algorithm to smooth the input, yet keep it snappy with as little input lag as possible; right now it is around 66ms input lag, which is almost unnoticeable when playing. Currently, the camera does not drift with slow movements, yet it does not loose sync with the true orientation, plotting this, we can compare a previous attempt with the current one:

Blue is input, and red is output; you can see that there is very little input lag and the latest one does not drift away, yet does not become out of sync; this keeps you immersed in the game without anything distracting you.

A limitation that should be noted when compared to other similar devices is, this does not have movement, only orientation.

Here is me using it when I’m in Arma 2 flying the Apache:

As you can see, this requires mounting your phone to your head some way; I’ve done it with velcro.

Thread Pool

Posted in C0BRA on July 11th, 2012 by C0BRA – Be the first to comment

I keep writing this, so I’m also putting it here for future reference:

using System;
using System.Collections.Generic;
using System.Text;

using System.Threading;

namespace SharePointWorkflowLocator
{
    [Flags]
    public enum ThreadPoolOptions
    {
        StopThreadWhenQueueEmpty = 1,
        Background = 1 << 1
    }

    public class ThreadPool<T>
    {
        private Action<T> _Action;
        private Queue<T> _Queue = new Queue<T>();
        private float Added = 0;
        private float Done = 0;
        private int _ThreadCount = 0;
        private Thread[] _Threads;
        private ThreadPoolOptions _Options;

        public ThreadPool(Action<T> action, int Threads, ThreadPoolOptions options = 0)
        {
            _Action = action;
            _Threads = new Thread[Threads];
            _ThreadCount = Threads;
            _Options = options;

            for (int i = 0; i < Threads; i++)
            {
                int ii = i; // So it can refer to itself
                _Threads[i] = new Thread(new ThreadStart(delegate
                    {
                        while (true)
                        {
                            T o = GetNext();
                            if (o != null)
                                action.Invoke(o);
                            else if ((_Options & ThreadPoolOptions.StopThreadWhenQueueEmpty) == ThreadPoolOptions.StopThreadWhenQueueEmpty)
                                _Threads[ii].Abort();
                            else
                                Thread.Sleep(100);
                        }
                    }));
            }
        }

        public void Start()
        {
            for (int i = 0; i < _ThreadCount; i++)
                _Threads[i].Start();
        }

        public void Abort()
        {
            for (int i = 0; i < _ThreadCount; i++)
                _Threads[i].Abort();
        }

        public T GetNext()
        {
            lock(_Action)
            {
                if (_Queue.Count == 0)
                    return default(T);

                Done++;
                return _Queue.Dequeue();
            }
        }

        public float GetQueueProgress()
        {
            lock (_Action)
            {
                return Added / Done;
            }
        }

        public void Enqueu(T Arg)
        {
            lock (_Action)
            {
                Added++;
                _Queue.Enqueue(Arg);
            }
        }
    }
}

Bit Orchestra

Posted in DrSchnz on November 13th, 2011 by drschnz – 3 Comments

Run a C program such as

int main() {
    int t;
    for (t = 0;;t++) {
        putchar((t >> 6 | t | t >> (t >> 16)) * 10 + ((t >> 11) & 7));
    }
}

and you’ll get pseudo-random gibberish, but pipe the output of the same program into a 8-bit 8kHz pcm sound device and you’ll get something not far from a chip-tune symphony. There’s been a recent trend in the demoscene community of making simple, short programs that produce surprisingly complex music. Now, I don’t have anything for the hardcore demoscene artists who want to fit a techno song in a 12 byte program, but I do have something for those who want to experiment with algorithmic music.

Bit Orchestra!

Bit Orchestra is a tool for quickly testing and prototyping expressions for create interesting noises (and sometimes even music!). It has some helpful music related functions and allows you to hear the output immediately. You can download Bit Orchestra here (sorry, Windows only, at the moment at least) or view the (MIT-licensed) source here. Once you’ve download it, load and try out the included samples.

Also look at this.

Create ZIP archives in C#

Posted in C0BRA on October 7th, 2011 by C0BRA – Be the first to comment

I was looking for a way to do this not to long ago; I came across some examples that used a third party libary and was over complicated, so I created this class based of one of MSDNs examples.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.IO.Packaging;  
using System.IO;  

public class ZipSticle  
{  
    Package package;  

    public ZipSticle(Stream s)  
    {  
        package = ZipPackage.Open(s, FileMode.Create);  
    }  

    public void Add(Stream stream, string Name)  
    {  
        Uri partUriDocument = PackUriHelper.CreatePartUri(new Uri(Name, UriKind.Relative));  
        PackagePart packagePartDocument = package.CreatePart(partUriDocument, "");  

        CopyStream(stream, packagePartDocument.GetStream());  
        stream.Close();  
    }  

    private static void CopyStream(Stream source, Stream target)  
    {  
        const int bufSize = 0x1000;  
        byte[] buf = new byte[bufSize];  
        int bytesRead = 0;  
        while ((bytesRead = source.Read(buf, 0, bufSize)) > 0)  
            target.Write(buf, 0, bytesRead);  
    }  

    public void Close()  
    {  
        package.Close();  
    }  
}

You can then use it like this:

FileStream str = File.Open("MyAwesomeZip.zip", FileMode.Create);  
ZipSticle zip = new ZipSticle(str);  

zip.Add(File.OpenRead("C:/Users/C0BRA/SimpleFile.txt"), "Some directory/SimpleFile.txt");  
zip.Add(File.OpenRead("C:/Users/C0BRA/Hurp.derp"), "hurp.Derp");  

zip.Close();
str.Close();

You can pass a MemoryStream (or any Stream) to ZipSticle.Add such as:

FileStream str = File.Open("MyAwesomeZip.zip", FileMode.Create);  
ZipSticle zip = new ZipSticle(str);  

byte[] fileinmem = new byte[1000];
// Do stuff to FileInMemory
MemoryStream memstr = new MemoryStream(fileinmem);
zip.Add(memstr, "Some directory/SimpleFile.txt");

memstr.Close();
zip.Close();
str.Close();

MineViewer 1.6 Update

Posted in MineViewer on May 26th, 2011 by C0BRA – 14 Comments

Added the new block types:

  • Booster
  • TrackPressurePad
  • TrapDoor
  • Bed
  • Web
  • TallGrass
  • DeadShrubs

And fixed a bug that stopped you from opening your save while Minecraft is currently running.

Download:
MediaFire