New site content

December 15th, 2009

Hi all,

I’ve just uploaded two new two new projects to the site.

The first is a little physics simulation I did last week.

The second is an application framework for DirectX that provides a basic scene along with camera setup and manipulation, logging, mesh loading and rendering support and direct input support.

You can get them in my downloads section of the site.

Cheers,
Eddie

admin C/C++

Really annoying ActionScript error

December 12th, 2009

Hi,

I’ve been working with ActionScript for the first time and created a really simple class with a couple of getters and setters and wanted to instantiate the class and use a few setters.

So the original class was:

package MyPackage
{
import mx.core.UIComponent;

public class AClass extends UIComponent
{
public function AClass()
{
super();
}

public function get AValue():Number
{
return _aValue;
}

public function set AValue(_newAValue:Number):void
{
_aValue = _newAValue;
}

private var _aValue:Number;
}
}

That looks fine right?

So in my class I call
import MyPackage.AClass at the top of the file.

Next in another class I called

var myClass:AClass = new AClass();

myClass.AValue(20.0);

I figured that this looked fine, you want to call the function AValue with the value 20.0 passed in. However I was getting the cryptic error:

1195: Attempted access of inaccessible method AValue through a reference with static type MyPackage:AClass

Took me a while to figure this one out I thought I had defined the functions incorrectly or wasn’t importing the class right. However the solution is a simple one. When you use get and set you are essentially saying that you can use the assignment operator but for some weird reason you can’t call the functions directly.
So the solution was to do:

var myClass:AClass = new AClass();

myClass.AValue = 20.0;

Use the assignment operator instead of calling the set function directly.

admin Flex

Site update

November 25th, 2009

Hello all,

Well I’ve spent the last few days updating my site, hopefully all the downloads now work with Visual Studio 2005 and the most recent DirectX.

I’ve not got a chance to actually clean up the code yet so don’t expect miracles!

Please let me know if you find anything broken!

Cheers,
Eddie

admin Uncategorized

Setting up a basic OpenGL project on Mac OS Leopard and XCode

October 11th, 2009

I’ve recently setup a basic OpenGL project in XCode to have a black window.

In XCode select File->New Project. Select an Empty Project and name it whatever you want, screenie below:




newproject




Within XCode select Project->New Target again. Select Cocoa on the left then Application and name it whatever you’d like.




targetapp




You will now see a window with a whole bunch of settings. In the General tab press the + button in Linked Libraries. Add OpenGL.Framework and Glut.framework from the list of frameworks in the dialog that appears.




generalwindow




Next select Build in the tabs along the top and clear the bottom field GCC_PREFIX_HEADER so that its blank.




targetsettings




In the Groups and Files explorer right click on the top level project and select Add->New File. Choose C and C++ and select C file. Again choose whatever name you wish.




candc_





Paste the following code into the C file:

[code lang="C"]
#include
#include

void myCustomDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glutSwapBuffers();
}

void myCustomReshape(int width, int height)
{
glViewport(0, 0, width, height);
}

void doSomethingWhenIdle(void)
{
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 600);

glutCreateWindow("My First Window");

glutDisplayFunc(myCustomDisplay);
glutReshapeFunc(myCustomReshape);
glutIdleFunc(doSomethingWhenIdle);

glutMainLoop();
return EXIT_SUCCESS;
}
[/code]

Next Build the application using ‘Build and Go’ and you’ll be presented with a 800×600 empty window with the title ‘My First Window’, easy! I won’t go into the explanation of the different functions, there are plenty of sites out there for that!

edlong C/C++

Display correct text colour on a background colour

September 10th, 2009

Hi,

I haven’t posted for a bit, back to some handy C++. I’ve been working with a lot of text being displayed on a background which can be various colours. Not knowing the background colour is in advance is problematic as if you specify the text colour to be always white and the background colour changes to white then the text is unreadable. Likewise for black and there are a range of colours in between that suffer with the same problem, light grey or dark purple for example.

I needed a way of determining correct text colour based on a given background colour. After doing a little bit of digging I came across this article on CodeProject which almost gives the solution I was looking for. However I want to just display white or black text depending on the background colour. So here is the code I used to do so, it works remarkably well. I’ve pseudo coded it up a bit to remove various bits and pieces that may not be important but you can just replace bits of it with proper objects. Also ignore the magic numbers, they’re there just to show the numbers that worked for me. This algorithm can potentially be used in any language, I’m using C++ here as it is what I’m currently using.

[code lang="C++"]
COLOUR GetTextColourFromBackground(COLOUR BackgroundColour)
{
uint32 uDarkLightColourThreshold(105);
float fRedThresholdValue(0.299);
float fGreenThresholdValue(0.587);
float fBlueThresholdValue(0.114);

uint8 bgDelta = static_cast((BackgroundColour.GetRed() * fRedThresholdValue) + (BackgroundColour.GetGreen() * fGreenThresholdValue) +
(BackgroundColour.GetBlue() * fBlueThresholdValue));

COLOUR TextColour(GetColour(White));
if((255 - bgDelta) < uDarkLightColourThreshold)
{
TextColour = GetColour(Black);
}

return TextColour;
}
[/code]

So on a white background the text colour returned will be black and on a black background the text colour will be white. Also on a light grey background the colour returned will be black and so on.
The formula used above originally comes from the W3C http://www.w3.org/TR/AERT#color-contrast.

edlong C/C++

Quieten XCode’s output to the console

August 6th, 2009

Hi,

During some iPhone dev i noticed that the console on my macbook had many entries like:

Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0×319a380, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0×31bf6e0, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0×3263da0, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0×3274eb0, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0×319a380, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0×31bf6e0, has non-zero refcount = 1

These messages I found out are not actually anything to do with my program, I thought I was doing something wrong and not freeing up resources. It is actually the internal workings of XCode which is automatically freeing up resources. Knowing this, I decided to turn off these annoying console outputs and found this XCode project which basically gobbles up output from XCode in the same mould as above.

Just compile the project and it will install the QuietXCode plugin to ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins. Restart Xcode and fire up the console and you’ll see an inital output of:

06/08/2009 19:34:32 Xcode[5147] <QuietXcode> loaded successfully

You should no longer see the annoying output!

admin C/C++

Disable intellisense in Visual Studio 8

July 10th, 2009

Hi,

The studio I work in use Visual Assist which is a far better version of Intellisense in my opinion. However Intellisense is on by default on Visual Studio and does a far bit of processing in the background, especially when there are significant project changes. So I’ve needed to disable intellisense for this project, to do so is trivial really.

Close your active solution in Visual Studio.
Navigate to: C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcpackages (you may need to find the right directory on your machine depending on where Program FIles are…)
Remove or rename(a better option in case you need it again)

Feacp.dll

Intellisense will now be disabled.

edlong Uncategorized

First forays into iPhone development

July 10th, 2009

Hi,

I’ve just started looking into beginning development on the iPhone. Coming from C++, Objective-C seems a strange and foreign language and so I’ve been looking for useful tutorials online. The best I’ve found so far is a Stanford course that is available on iTunes U. Seems to be a very well put together course taught by Apple developers. I’ve looked at one lecture so far but was impressed.

Check it out

Stanford Lectures on Cocoa Programming

Other handy resources are:

iPhone dev blog
More tutorials

Let me know if anyone knows of other good tutorials.

edlong Uncategorized

Using a single number to contain two other numbers

July 3rd, 2009

Hi,

Due to a certain restrictive pattern being used at work, I’ve recently had the need to pass along two numbers but only had a single number to do so. It’s a bit of a nasty hack but is my first experience with using bit masking and is a useful technique. The integer being used in the pattern was an unsigned 32 bit integer and the two other integers I wanted to pass along were both unsigned 8 bit integers. The way we figured to send along the two numbers is to basically use half of the 32 bit integer to contain the two 8 bit integers using masking. The process is very simple there are two functions, Encode and Decode. Encode takes in two integers (I’ve made them unsigned 16 bits for the moment but you can easily cast the 8 bit unsigned integer to 16 bit) and returns a 32 bit unsigned int that contains the two. The encode function basically shifts the iFirstNumber into the lower 16 bits of the 32 bit integer. Then iSecondNumber is added to this to give a full 32 bit number.

[code lang="C++"]
uint32 Encode(const uint16 iFirstNumber, const uint16 iSecondNumber)
{
uint32 iEncodedValue((iFirstNumber<< 16) + iSecondNumber);

return iEncodedValue;
}
[/code]

To explain it a little clearer suppose we have iFirstNumber set to 3 (0x00000011) and iSecondNumber set to 1 (0x00000001) we would end up with the encoded value being 0x0000001100000001

You can see that the first 16 bits contain iFirstNumber and the second 16 bits contain the second.

To get the two numbers back out again we have a similar Decode function:

[code lang="C++"]
void Decode(uint32 iValue, uint16& iFirstNumber, uint16& iSecondNumber)
{
iFirstNumber = (uint16)((iValue & 0xFFFF0000) >> 16);
iSecondNumber= (uint16)(iValue & 0x0000FFFF);
}
[/code]

The first number is the overall value ANDed with 0xFFFF0000 and then shifted 16 bits to the right. ANDing the number with 0xFFFF0000 indicates that we are only interested in the first half of the bits in the overall value. It will turn all the rest of the bits in the value to be 0000000000. So after that we will be left with 0×0000001100000000. Now we need to narrow the number down to a 16 bit number. To do this we shift the bits 16 places to the right and cast to a uint16. Casting will remove the proceeding 16 bits(which are all now 0 anyway) and leave us with 0×00000011 which translates to 3.
For iSecondPosition we say that we want only the last half of the bits in the overall value. This leaves us with 0×0000000000000001. Casting this to a uint16 will leave us with 0×00000001 or 1.

In the end we actually didn’t need to do it this way but got it working anyhow. Might be handy for someone maybe!

edlong C/C++

Champ Man preview

June 22nd, 2009

Hi all,

Really sorry I haven’t blogged in a while, I’ve found it tough with work commitments and just not being motivated enough recently to do in my spare time! I’m going to try and get it all going again soon.

Edit: We’ve just announced the release date and a special new feature, CM Season Live:

http://www.championshipmanager.co.uk/server/show/ConWebDoc.918?PHPSESSID=a23581a233622d5e50d1dfbc20cabc14
http://www.championshipmanager.co.uk/server/show/ConWebDoc.917?PHPSESSID=a23581a233622d5e50d1dfbc20cabc14

In the meanwhile here a couple of previews of the game on GameReactor.

http://gamereactor.co.uk/grtv/?id=4194
http://gamereactor.co.uk/grtv/?id=4210

edlong General