Thank you !
With above linked tutorials i finished now my mini box2d for pocketpc sample.
It works great and fast
To contribute a litte bit, I post my first exercise hier
Code:
//PocketBox2d Minisample
//Box2d and graphics on a PocketPc (HTC P3300/200 MHZ / ARM)
//Compiled,linked with Microsoft Visual C++ 2005 (Platform: Pocket PC 2003)
//See HelloWorld example from Box2d/Examples for world descriptions
//Required are glutes.dll and libGLES_CM.dll
#include "stdafx.h"
#include <windows.h>
#include "box2D.h"
#include "glutes.h"
// Pocket world globals and settings
b2World *gWorld = NULL;
b2Vec2 gGravity ( 0.0f, -0.1f );
bool gDoSleep = true;
float32 gTimeStep = 1.0f / 60.0f;
int32 gIterations = 10;
// Graphics
void drawPolyShape(const b2Shape *shape,
GLfloat cr,GLfloat cg, GLfloat cb)
{
GLfloat *v;
b2Vec2 p;
int32 i,j;
const b2PolyShape* s = (const b2PolyShape*)shape;
//...the new constructor could be a problem for the performance ?
v = new GLfloat [s->m_vertexCount*2] ;
for (i=0, j=0; i < s->m_vertexCount; ++i,j+=2) {
p = s->m_position + b2Mul(s->m_R, s->m_vertices[i]);
v[j] = p.x ;
v[j+1]= p.y ;
}
glColor4f(cr, cg, cb, 1.0f);
glShadeModel(GL_FLAT);
glVertexPointer(2, GL_FLOAT, 0, v);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_LOOP, 0, 4);
delete [] v;
}
void display()
{
glClear (GL_COLOR_BUFFER_BIT);
for (b2Body* b = gWorld->m_bodyList; b; b = b->m_next) {
for (b2Shape* s = b->m_shapeList; s; s = s->m_next) {
if (b->IsStatic()) {
drawPolyShape(s, 0.5f, 0.5f, 0.5f);
}
else if (b->IsSleeping()) {
drawPolyShape(s, 0.5f, 0.5f, 0.9f);
}
else {
drawPolyShape(s, 0.9f, 0.9f, 0.9f);
}
}
}
glFlush ();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void simpleWorld() // see Box2D/Examples/HelloWorld
{
b2AABB worldAABB;
worldAABB.minVertex.Set(0.0f, 0.0f);
worldAABB.maxVertex.Set(1.0f, 1.0f);
gWorld = new b2World(worldAABB, gGravity, gDoSleep);
// static body
b2BoxDef groundBoxDef;
groundBoxDef.extents.Set(1.0f, 0.1f);
groundBoxDef.density = 0.0f;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0.0f, 0.0f);
groundBodyDef.AddShape(&groundBoxDef);
gWorld->CreateBody(&groundBodyDef);
// dynamic body 1
b2BoxDef boxDef;
boxDef.extents.Set(0.02f, 0.06f);
boxDef.density = 1.0f;
boxDef.friction = 0.1f;
b2BodyDef bodyDef;
bodyDef.position.Set(b2Random(0.3f,0.7f), 0.8f);
bodyDef.rotation = b2Random(-1.0f, 1.0f);
bodyDef.AddShape(&boxDef);
b2Body* body = gWorld->CreateBody(&bodyDef);
}
void idle(void) // Is this the correct location for the Box2D-Step?
{
gWorld->Step(gTimeStep, gIterations);
glutPostRedisplay();
}
// A minimal user interface
enum { CMD_QUIT=100, CMD_RESTART };
void menu(int entry)
{
switch(entry) {
case CMD_QUIT: exit(0); break;
case CMD_RESTART:
if ( gWorld ) delete gWorld;
simpleWorld();
glutPostRedisplay();
break;
default: break;
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case '\n':
glutSimulateButton(GLUT_RIGHT_BUTTON, 10, 20);
break;
default: break;
}
}
void mouse(int button, int state, int x, int y)
{
glutSimulateButton(GLUT_RIGHT_BUTTON, x, y);
}
// The main...
int _tmain(int argc, _TCHAR *argv[])
{
int32 mainWindow; //actually not used
glutInit(&argc, (char**)argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
mainWindow = glutCreateWindow("Box2D-PocketPc-Test");
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutReshapeFunc(reshape);
glutCreateMenu(menu);
glutAddMenuEntry("Restart", CMD_RESTART);
glutAddMenuEntry("Quit", CMD_QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
simpleWorld();
glutMainLoop();
if ( gWorld ) delete gWorld;
return 0;
}
Now I'l go into Box2D understanding. My "vision" is to have a box2d world edit & play for the pocketpc.
Regards, nimodo