Oz

This user hasn't shared any biographical information


Posts by Oz

Polygon Triangulation

If you’re using OpenGL, you may have a need to triangulate your polygons in order to draw them.

A common algorithm to do this is the ear clipping algorithm. We’ve been on the search for a solid implementation of this for a while, and have finally found one:

http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml

It’s written in c++ and has no dependencies (except for stl). It was really easy to use, and worked well in our tests.

Welcome to the new Spiralstorm Blog

We’ve been so busy lately that we haven’t had any time to share with the world, but have no fear, with the aid of our new, redesigned blog, we’ll finally have a venue to talk about everything Flash, iPhone, and games.

Check back in the upcoming days when we’ll be blogging about what we’ve been up to.

Creating unique variables within your preprocessor macros

Sometimes in your macros you need to use a variable, but you can’t scope it to the macro. If you use this macro more than one in the same scope you get a duplicate variable warning.

For example, let’s say this is your macro:

#define LOOP_10_TIMES \
int i = 0; \
for( i = 0; i < 10; ++i)

And this is your implementation:

LOOP_10_TIMES{
	x += i;
}

This is fine, but what happens when you want to use this macro twice? Like so:

LOOP_10_TIMES
	num += i;

LOOP_10_TIMES
	mun += i;

You’re sure to get a nasty error (or at least a warning).
This is because your code now declares the variable ‘i’ twice in the same scope.

More >

Calling C functions in your C++ code

Have you ever wanted to call a c function located in one file within a different c++ (.mm / .cpp) file?

If you did, you probably know that it can be a royal pain if you don’t know the trick.
So if like me you’ve been looking for the solution, it’s very easy! Just use the extern “C” keyword (not to be confused with plain extern). Here’s an example:

extern "C" #include "my_c_code.h";

This also works with the Objective-C #import keyword:

extern "C" #import "MyObjCClass.h";

or alternatively for multiple includes

extern "C" {
#include "my_c_code.h"
#include "my_other_c_code.h"
}

And that’s the way you include someone else’s C code into your C++ files. Easy!

But…
If you’re writing brand new C code and you want it to be automatically compatible with other C++ code you can build it in a way that will make it #include’able into any source file.

Using the __cplusplus preprocessor variable you can check if the current build target is a c++ file and if so, surround your code with extern “C”

So for example let’s say this is our current C header file:


//my_c_header.h:

int addOne(int n);
int globalVar;
//..etc

To make this code C++ friendly, we’d do this:

//my_cpp_friendly_c_header.h:

#ifdef __cplusplus
extern "C" {
#endif

int addOne(int n);
int globalVar;
//..etc

#ifdef __cplusplus
}
#endif

Now in your C++ file you can just write


// my_cpp_code.cpp

#include "my_cpp_friendly_c_header.h"

So if you know that your C code will be included into C++ source, it’s always a good idea to wrap it in extern “C” { … } to avoid headaches later on…

More info over at: http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html

Woo hoo, It’s out! Get some Flyloop

It’s been 14 very long days, but Apple finally approved Flyloop. Go check it out, here’s the iTunes Link: Download

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

And of course, check out http://www.flyloop.com

New game, Flyloop

It’s been quite a while since we las blogged, but it was for a good reaon!

Well, maybe no reason is good enough but hopefully this makes it excusable.

For the past two months we’ve been working tirelessly on a new game for the iPhone who’s premise is very simple: Catch some butterflies.

We’re getting ready to send it in to Apple so keep your fingers crossed!

Oh, and check out the brand new site we made for it: http://www.flyloopgame.com.

* If you own the domain www.flyloop.com… please stop re-purchasing it soon.