15
01/2012

Shape Designer

Written by arthur

Today I am going to show you one other tool I worked on for my physics engine. It's called ShapeDesigner, mainly because it helps to design shapes (really?!) or collision geometry for the engine. Well, I could have done it with triangulation from an image. But all geometry would have been made of triangles whereas circles save a lot of resources and increase accuracy.

shape designer

So here I am with this tool. It allows to load an image, and then we can draw all basics shapes (such as circle, triangle or quad), and export it in a compliant xml format for the physics engine.

<shape name="bloc_18.png">
  <triangle x1="0" y1="64" x2="0" y2="28" x3="55" y3="64" />
  <circle x="31" y="32" radius="31" />
  <triangle x1="55" y1="64" x2="62" y2="37" x3="0" y3="28" />
</shape>

You can also take a look at the code (it was made with visual studio 2010, in C#) if you want to fork it.

Classified in : Tools - Tags : iphone, opengl, C#, windows, atlas, packer - 1 comment

21
12/2011

Tool - Texture atlas maker

Written by arthur

I told you that I started iPhone development. After testing Unity3D and cocos2d, I decided that I will better write my own 2d engine with opengl-es. Maybe it's more extra-work, but I prefer truely understand what I am working with. Moreover I did a similar engine on Windows. But the downside was the performance, how to manage a lot of graphics on such limited hardware? (Yes, iPhone 3G, I am speaking of you.)
On windows I was loading one texture for one sprite. If I had 300 images in my application I would load 300 textures. Not very efficient, but it worked on nowadays computer. Of course it couldn’t work on iPhone. Plus, on iOS we can’t load texture that have not a power-of-two size. For example a 257x300 pixel wide image would require a space of 512x512 pixels in ram. That means a lot of wasted space.
One common approach is to pack all images in a big one, and then at the rendering compute the convenient UV mapping for each image. In doing that we get rid of glBindTexture and other opengl calls which can slow down the rendering.

texture packer atlas example

You are going to ask me why I develop windows tool for iPhone development, the answer is simple: I like the .Net Framework and C#, and tools are made to save time! And this tool helps for two things:
  • Textures packing
  • Animations maker
It works for animations too because the problem is the same(a lot of different graphics, but with limited space in ram).
If you are brave enough, you can try it by yourself in downloading the application here (it requires .Net Framework 4.0 though).

Classified in : Tools - Tags : iphone, opengl, C#, windows, atlas, packer - 1 comment

07
11/2010

3D softbody physics

Written by arthur

Well, I can't stop on 2D. 3D was mandatory. As you could have read in this post I am currently very focused on physics simulation, especially softbody physics.
blob 3d blob 3d
So the principle is the same as in 2D, but it becomes a lot more complicated in 3D (just think collision detection between 320 faces and a complete environment). I think a way to improve the speed and increase the complexity could be the use of GPU with OpenCL. But it is not the case in this demo. And it runs already smoothly at 60 fps. Check by yourself here.

Classified in : Projects - Tags : 3d, opengl, c++, physics, soft, body - 2 comments

15
10/2010

Softbody Physics - Demo

Written by arthur

I have always been fascinated by physics simulation - in real time. And when games are mixing physics simulation with traditional gameplay, it give often really good games! My main references are locoroco, gish, world of goo and even bridge builder, this is what I tried to make possible with my own physics engine. I made a few things with that engine, but I didn't release the source code, mainly because it's not clean enough, but you can still enjoy the demos.

Blob - Nintendo DS
blob
The goal of this demo was to be the closest of what we find in locoroco, but for the Nintendo DS. Unfortunately it doesn't succeed, but it's still nice to see physics simulation running on such limited hardware.
Download the demo.

Bridge Builder - World of Goo like - Nintendo DS
blob
Well, this is an unfinished bridge-builder/world of goo like for the nintendo ds, you place points with the stylus and all the structure is moving.
Download the demo.

Blob Volley - Windows
blob
Another example of what my engine is capable of. It was a game which was targeted to be released on gp2x, but I have never finished it. But you can still enjoy the windows work in progress!
Download the demo.

Technical tips
It is all about a spring/mass physics problem. I use a simple euler method for integration, it can be inacurate but the result is almost the same as a Runge-Kutta 4 method in a game. I also use a fixed timestep for the simulation, it is often more convenient if you don't think your simulation could have a drop in performance.
I think I can sum up a softbody physics engine by the code below. If you have any question or tips you want to share, don't hesitate to post a comment!
typedef struct {
    float px, py, vx, vy, ax, ay, mass, fx, fy, last_px, last_py;
} Mass;

typedef struct {
    float d, k;
    Mass* a;
    Mass* b;
} Spring;

void mass_update(Mass *m, float dt) 
{
    float inv_mass = 1.0f / m->mass;
    m->ax = m->fx * inv_mass;
    m->ay = m->fy * inv_mass;

    m->vx += m->ax * dt;
    m->vy += m->ay * dt;

    m->last_px = m->px;
    m->last_py = m->py;

    m->px += m->vx * dt;
    m->py += m->vy * dt;

    m->fx = m->fy = 0;
}

void spring_update(Spring* s)
{
    float distance = sqrtf((s->a->px - s->b->px) * (s->a->px - s->b->px) + (s->a->py - s->b->py) * (s->a->py - s->b->py));
    float delta_distance = distance - s->d;

    if(distance > EPSILON)
    {
        float inv_distance = 1.0f / distance;
        float ex = (s->a->px - s->b->px) * inv_distance;
        float ey = (s->a->py - s->b->py) * inv_distance;

        s->a->fx -= ex * s->k * delta_distance;
        s->a->fy -= ey * s->k * delta_distance;
        s->b->fx += ex * s->k * delta_distance;
        s->b->fy += ey * s->k * delta_distance;
    }
}

Classified in : Projects - Tags : physics, soft, simulation, blob, pc, c++ - no comments

07
09/2008

Crocodingus In Cube Island - Nintendo DS

Written by arthur


Crocodinugs is a game I worked on during the summer in 2008. It's the result of two intensive months of development with madpxl. So, this game was made with a custom 3d engine, which I developed for the limited hardware of the Nintendo DS. Yet, the result is nice, and it runs at a smooth 60fps!

The game
You control the crocodile using the stylus, your goal is to catch all bananas(crocodiles eat bananas, it's well kown) and stars. Beware of monkeys, they can kill you if you're not watchful enough, of course you can get rid of them using your tail (very logical, I know). Well, this game can be sometimes tricky, so be careful not to get stuck when you are moving a crate!

The technical side of Crocodingus
  • A game made in collaboration with Madpxl in two months.
  • A custom 3D engine for the Nintendo DS:
    • Textures management (paletted, alpha-blended)
    • MD2 animation loading
    • OBJ loading and conversion to display list
    • Dynamic third person camera
    • Culling
  • Easy level creation with Mappy (a tilemap editor)
  • 60 frames per second guaranteed!

Links and download

Classified in : Projects - Tags : nintendo ds, homebrew, 3d, c++ - no comments