05 September 2007

So I dug up the ol' gravitas solution and decided it was time to load a mesh in there. Coding4Fun again proved helpful. Unlike the very uninformative error messages from DirectX. With some playing about, I managed to get the sample heli.x to load and render in stark white.

Then I had to turn on the lights. (device.RenderState.Lighting = true; device.RenderState.Ambient = Color.White;)

For some reason my point list is now ignoring its colours and using the last one that heli did. Sheep.

Posted on Wednesday, September 05, 2007 by David Campey

No comments

14 May 2007

Title says it all. Pictures of walls.

Man some of these are funny.

Great content, amusing presentation, and occasional irony. Nothing quite like the venting of profound, repressed, anonymous vandals.

Posted on Monday, May 14, 2007 by David Campey

No comments

08 May 2007

TeamPlain has a goto work-item search that opens up workitems, oddly enough. I wanted to use the Firefox search box to fire this off.

Using the guide: Creating OpenSearch plug-ins for Firefox, I started putting together an XML OpenSearch description in notepad.

Needing an icon, I Gimped out the logo from the TeamPlain site, took it past the data: URI kitchen and popped it in.


Okay, so it's fugly, but it doesn't look too bad on the search bar.

A glance at the OpenSearch Specification provided final tips when deciding what data should go where. Now I had an XML file and needed someway to consume it

I tried installing the OpenSearch plug-in. I used the Error Console in Firefox, running the command window.external.AddSearchProvider(engineURL); using a file:/// URI for the engineURL, but kept getting a URL formatting error.

Error: Invalid argument passed to 
Unsupported search engine
Source File: file:///C:/Program%20Files/Gran%20Paradiso
Line: 114

Initially I thought this was due to the URL in the XML definition file, so I hacked around with that for a bit, then when that yielded no fruit, I extended the error message in the mentioned .js to include the invalid URL. This was the URL to the XML doc, not the search URL inside the XML. Turns out the URL check in the .js that was throwing the exception was only regexing https?|ftp, so needed a |file appended.

Now that Firefox was playing nicely with the XML, it was happy to load it up and prompt me to install it.

And it worked!

Final code: (adjust search URL to your liking)

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
<ShortName>TeamPlain Item</ShortName>
<Description>Load items from local TeamPlain</Description>
<Image width="16"height="16">
<Url type="text/html" method="GET"
template="http://05rnb-dev02:8090/workitem.aspx?id={searchTerms}" />

Posted on Tuesday, May 08, 2007 by David Campey


03 May 2007

So my screen went on the blink; more like the scramble. It was very upsetting, and it carried on like this for a few weeks. I used an external monitor and sometimes the regular screen would work. It was very unpredictable and would break without any cause, which frustrated the hell out of me.

Eventually while sitting in a friend's loungue I decided I really just had to see my screen. So I grappled with her rather useless screwdrivers and took out the retaining screws for the keyboard. After this was done I flipped the keyboard open, gave the internal screen connector a poke and turned it on.

And it worked. Just like that. And it's been working ever since.

Posted on Thursday, May 03, 2007 by David Campey

No comments

So, I went to the 'My Coke Fest' in Joburg. It was pretty cool. Hoobastank rocked ;) their lead singer looked like he couldn't have been more than 20; turns out the whole band is over 30 -- there's hope for us yet.

The picture (left) is of Hoobastank, with their lead singer standing on his box -- he was so tiny. Apparently he's Incubus' brother, which is kinda cool. They played some Bon Jovi and AC-DC to warm the crowd up for their no. 1 track, "The Reason". It was unexpected to hear an international act covering, but they pulled it off with style. Definitely the high-point of the 12-hour concert for me.

Posted on Thursday, May 03, 2007 by David Campey

No comments

Not only is Rocket Commander a pretty cool looking (but rather boring) MDX game with publicly available source, it turns out they've done a series of 10 30-minute video tutorials on the making of the game. Sweet.

Posted on Thursday, May 03, 2007 by David Campey

No comments

02 May 2007

So, I wanted to add substance to my craft. This was quite easy. I rearranged the points in the VertexBuffer into a list describing a triangle fan and fiddled to get that to work.

pointList_VB = new VertexBuffer(typeof(CustomVertex.PositionColored),
12, device,
Usage.Dynamic | Usage.WriteOnly,

CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[12];

// Triangle #1

verts[0].Position = new Vector3(0.0f, 0.5f, 0.0f);
verts[0].Color = Color.Blue.ToArgb();

verts[1].Position = new Vector3(0.5f, -0.2f, 0.0f);
verts[1].Color = Color.Green.ToArgb();

verts[2].Position = new Vector3(0.0f, 0.0f, 0.2f);
verts[2].Color = Color.Orange.ToArgb();

verts[3].Position = new Vector3(-0.5f, -0.2f, 0.0f);
verts[3].Color = Color.Red.ToArgb();

verts[4].Position = new Vector3(0.0f, 0.0f, -0.2f);
verts[4].Color = Color.Yellow.ToArgb();

verts[5].Position = new Vector3(0.5f, -0.2f, 0.0f);
verts[5].Color = Color.Green.ToArgb();

Yawn. Then I appended some points to that list for a triangle list to close off the object.

verts[6].Position = new Vector3(-0.5f, -0.2f, 0.0f);
verts[6].Color = Color.Red.ToArgb();

verts[7].Position = new Vector3(0.5f, -0.2f, 0.0f);
verts[7].Color = Color.Green.ToArgb();

verts[8].Position = new Vector3(0.0f, 0.0f, -0.2f);
verts[8].Color = Color.Yellow.ToArgb();

verts[9].Position = new Vector3(-0.5f, -0.2f, 0.0f);
verts[9].Color = Color.Red.ToArgb();

verts[10].Position = new Vector3(0.5f, -0.2f, 0.0f);
verts[10].Color = Color.Green.ToArgb();

verts[11].Position = new Vector3(0.0f, 0.0f, 0.2f);
verts[11].Color = Color.Orange.ToArgb();

pointList_VB.SetData(verts, 0, LockFlags.None);

And then drawing it with indexed calls to my VB stream as follows.

d3dDevice.SetStreamSource(0, pointList_VB, 0);
d3dDevice.DrawPrimitives(PrimitiveType.PointList, 0, 7);
d3dDevice.Transform.World = Matrix.Multiply(
Matrix.RotationYawPitchRoll(Geometry.DegreeToRadian(p1.Rotation.X), Geometry.DegreeToRadian(p1.Rotation.Y), Geometry.DegreeToRadian(p1.Rotation.Z)),
Matrix.Translation(p1.Position.X, p1.Position.Y, 20.0f)
d3dDevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, 5);
d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 6, 11);

Drawing it revealed to me that I'd got up & down confused on the y-rotation.. so after fixing that it was all solid.

And it looks something like this. (from a few viewpoints)

Really has to be seen in motion for full effect.

Posted on Wednesday, May 02, 2007 by David Campey

No comments

So, I had collected a lovely bunch of variables to track the position of the craft, looking something like this: (gotta love having your dev history in an SVN repo)
        private Vector3 p1rot;
private Vector3 p1rotInput;
private float p1rotForce;
public Vector3 Player1Rotation
get { return p1rot; }
set { p1rot = value; }
private Vector2 p1;
public Vector2 Player1Location
get { return p1; }
set { p1 = value; }
private Vector2 p1force;
private Vector2 p1spring;
private Vector2 p1grav;

And the time had come to move it out into an object. Which ended up looking like this:

class Player
private Vector2 _position;
private Vector2 _force;
private Vector3 _rotation;
private Vector3 _rotationInput;
private float _thrust;
private float _rotationForce;

public Vector2 Position
get { return _position; }
set { _position = value; }

.. blah blah properties. Thankfully we can use CTRL-R,E in Visual Studio to make a private variable into a public property; no mess, no fuss. There was also dome debate as to where to put the public properties w.r.t. their privates, I went with Turner and used the C++ style approach.

And I even gave the object its very own method to update it's internals. Lucky thing.

public void HandleInput(float dt)
{ ..blah.. }

This also meant that I can now make my property grid show only properties of Player p1.

Which is a lot more useful.

Also evident is the pretty point field I forgot to blog about; this is just a bunch of for loops adding the gravity vector at a point in the grid to the vector to that point.. the result is a point distorted by gravity.

Posted on Wednesday, May 02, 2007 by David Campey

No comments

01 May 2007

So, I demoed my game on battery power.. and it sucked. Interestingly whenever windows showed a tooltip, the game ran at full pelt.. something fishy there. But anyway, I introduced a Δt (delta t for the unicode (or greek) unaware) into my calculations. The first stumbling block was that I was using the tick counter, which sucks a bit. The thing is, even though it has damn good accuracy, it is only updated every now and then. Which is a bit odd. I managed to hack it into working by doing the following:

private void Physics()
    while (System.DateTime.Now.Ticks == Tick) { }
    //time interval
    long thisTick = System.DateTime.Now.Ticks;
    float dt = (Tick - thisTick) / 100000.0f;
    Tick = thisTick;
But that really feels dirty. All that hanging around waiting for the tick. - Spoon! So, anyways. After a bit of ferreting, I found the Coding4Fun: Beginning Game Development article I'd been reading, which contains a section "All about timers". In summary, I grabbed the dxmutmisc.cs file from the sample code (in DirectX SDK\Samples\Managed\Common), commented out everything but NativeMethods and FrameworkTimer, called FrameworkTimer.Start() before starting the Main loop, then did
private void Physics()
    dt = (float)(FrameworkTimer.GetElapsedTime()*1000);
to get the time interval since the last physics call. The *1000 is just to get the number into something I could count on my fingers-and-toes. And, with a little tweaking of cosmological constants, all was working again.

Posted on Tuesday, May 01, 2007 by David Campey

No comments

19 April 2007

I wanted to have my game panel run inside a splitter with a collapsible properties panel. This was quite easy to achieve, merely needing the changing of the handle that directX was pointing at. i.e. changing this:

d3dDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, flags, d3dpp);

to this:

d3dDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this.panel1, flags, d3dpp);


How? The OnKeyDown event doesn't percolate to parents. That truly sucks. Oddly the only key that does percolate is ALT+key which windows needed to get menu key-presses (ALT-F,X) -- ain't that just too hacky. The mechanism is there, but disabled to frustrate us.

I didn't really want my players to have to play while holding ALT ;) so I went and figured out how to use DirectInput, with the aid of Riemer's tutorial. And it just works. Quickly.

I'm polling the input from my main loop now, and compared to the handling of the OnKeyDown event I'm getting squagillions more keypresses. Needless to say ints became floats (Vector3s actually) rather quickly to handle the smaller iterations.

Other changes include having to have to input de-bounce. I do this by copying the previous state's keys and passing them into the next input parse.

private List Input(List laststate)
List seen = new List();
Vector3 rotationInput = new Vector3(0, 0, 0);
KeyboardState keys = keyb.GetCurrentKeyboardState();
if (keys[Key.Escape]) this.Dispose();
if (keys[Key.W]) rotationInput.Y++;
if (keys[Key.P] && !laststate.Contains(Key.P))
PropertyGridVisible = !PropertyGridVisible;
splitContainer1.Panel2Collapsed = !PropertyGridVisible;
OnResetDevice(d3dDevice, null);

return seen;

And in the main loop:

static void Main()
{ ...
using (Game grav = new Game())
{ ...
List laststate = new List();
while (grav.Created) { ...
laststate = grav.Input(laststate);
... }}}

The debouncer was necessary to do 'edge detection' on the squagillion keypresses that I was getting, e.g. to toggle the property pane once only. The extra call to OnResetDevice is to handle the change in FoV which is done based on the current size of the panel.

End of dev iteration.

Posted on Thursday, April 19, 2007 by David Campey

No comments

17 April 2007

Update: I'm using MDX, Rein's using XNA and Colin has joined us using GL.

My first deliverable was to have an object in a scene with tilt-to-steer and gravity.

This is done.


The object

The object is a triangle list primitive with a single triangle in it. Each vertex is differently coloured to help with orientation. It whizzes around quite satisfactorily with a simple spring function restoring it to zero-tilt, resulting in a max thrust of about 70deg.


Gravity... sucks. Really.

Inverse r-squared explodes quite quickly near to the centre, I had great fun experimenting with my singularity-like point-source gravity and watching things magically teleport off into the far reaches of game-space, never to be seen again. Okay, maybe frustration as well as fun ;) .

Other things

  • I'm thinking of a few weapon types: a shotgun of low-damage point-bullets, thrust based rockets (possibly steerable).
  • Planets should bubble into their positioins from the deep below the playing surface, with a bouyant-spring effect upon arriving. The gravity field vis should ripple away from them as they arrive.
  • Thinking of indicating a planet's power charge by encasing the planet in a platonic solid, increasing/decreasing count to indicate power. Maybe CTF-style planet capturing? Perhaps charged planets repel craft.
  • Sitting in a gravity field charges the batteries in proportion to the strength of the field. See, in the future they've figured out how to generate power from gravity: It's a cunning arrangement of pulleys, levers, cats and buttered toast.

Posted on Tuesday, April 17, 2007 by David Campey

No comments

29 March 2007

So, Rein and I decided to have a little compo. To learn DirectX and make something cool. The first thing I've been able to come up with is a remake of an old game that used to go by the name of 'VGA planets', not the VGA planets, mind you. With such a name, it's just not possible to find in amongst the birdmen and the borg ( I think they've assimilated the original).


We have a bunch of planets which remain stationary, players' space ships which are fitted with inertial drives which can be turned off. A ship has fuel and a gun. The gun fires a round that is influenced by the gravity of the planets. The goal is to fire a round that hits your opponent. Probably turn based unless I can figure out a good way to balance timing of firing and try to stop dodging.


Based on my initial thinking I'd like to include these features:
  • bump-mapped planets
  • point sprites spinning into the active player
  • glowy bullets
  • tracers
  • asteroids floating in and around the space
  • side-scroller-esque (or ala crimson land) power ups
  • a pong mode (bounce shields around planets)
  • did I mention glowy bullets
  • maybe some different guns
  • and npcs to feast on
  • landing on planetary bases/docking with orbiting stations for bonuses is hard but rewarding
  • teleport uses a full tank of fuel
  • network play
  • zooming battle field
  • visual of each players ship at full zoom in the corners


Draw grid for gravity, green standard, bending in and getting darker, and bending out and getting yellower for anti-grav. Tilt-based thrust, optional gyro for stabilising; a gyro should align you to the field at that point.
  • elastic physics - springs and things
  • tilt to steer physics

Posted on Thursday, March 29, 2007 by David Campey

No comments

26 March 2007

So, I had a plane trip ahead of me, and I wanted to be able to use .net StringBuilder with operators, below is the bstring class I wrote to do this. It's pretty straightforward, except the * operator behaves like python's and additionally is faster than a looped StringBuilder because of the pre-calculation (and allocation) of capacity. Still trivial, but it makes the StringBuilder useful without having to remember its syntax.

In testing it (obviously) beat the string class and also was indistinguishable from the StringBuilder in all but the * operator, in which case it was faster.

    class bstring
        private string _tstring;
        private StringBuilder _string;
        public StringBuilder Builder
                if (this._string != null) return this._string;
                    this._string = new StringBuilder(_tstring);
                    return this._string;
        public bstring(string value)
            _tstring = value;

        public int Length
            get { return Builder.Length; }


        public static bstring operator + (bstring stringA, bstring stringB)
            return stringA;

        public static bstring operator +(bstring stringA, string stringB)
            return stringA;

        public static bstring operator *(bstring stringA, int howMany)
            if (stringA.Builder.Capacity < stringA.Length * howMany)
                stringA.Builder.Capacity = stringA.Length * howMany;
            string tstring = stringA.ToString();
            for (int i = 0; i < howMany - 1; i++)
            return stringA;

        public override string ToString()
            if (this._string != null) return _string.ToString();
            else return _tstring;

And here's the body of the test class: in the current state it compares a += loop to the * operator:

        static void Main(string[] args)
            bstring bob;
            //bstring joe = new bstring("I am joe. ");
            string bobs = "I am bob. ";
            //string joe = "I am joe";
            int tick = 0;
            int iter = 1000000;
            Console.WriteLine("bstring +");
            tick = Environment.TickCount;
            for (int j = 0; j < 100; j++ )
                bob = new bstring("I am bob. ");

                for (int i = 0; i < iter - 1; i++)
                    bob += bobs;
            Console.WriteLine(Environment.TickCount - tick);
            Console.WriteLine("bstring *");
            tick = Environment.TickCount;
            for (int j = 0; j < 100; j++)
                bob = new bstring("I am bob. ");
                bob = bob * iter;
            Console.WriteLine(Environment.TickCount - tick);

and the output, showing approx 50% speed increase from pre-allocation on 100 runs of a 1 million part string:

bstring +
bstring *

Posted on Monday, March 26, 2007 by David Campey

No comments