Box2D Forums

It is currently Mon May 20, 2013 12:30 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sat Feb 09, 2008 4:10 pm 
Offline

Joined: Sat Feb 09, 2008 4:00 pm
Posts: 75
I compiled box2d for my pocket pc (windows mobile 6).Box2d and the HelloWorld sample compile fine and run fast (as console application) without changing anything in the sources. Cool ! :)
Image


Now, the graphics ...,the TestBed sample
I tried the following libraries:
For freeglut glutes , needs open gl, works, but some gl... functions are missing (glBegin, glVertex.., glEnd,...) Somebody knows about graphics programing for windows mobile ? Has someone a minimal example of box2d using graphics (like the HelloWorld Example, but instead of printf a Draw...() function ?

Regards and thx, nimodo


Top
 Profile  
 
PostPosted: Mon Feb 11, 2008 11:58 pm 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
I don't know much (err, anything) about Windows Mobile or OpenGL ES, but at http://www.zeuscmd.com/tutorials/opengles/index.php there are some tutorials, and it appears that the bread and butter drawing stuff is done via vertex arrays:
Quote:
Primitives in OpenGL ES are drawn using Vertex Arrays. You need to set the current vertices to use. This is accomplished by using the glVertexPointer function.
(from http://www.zeuscmd.com/tutorials/opengl ... ection.php)

I'd look through the tutorials there, they seem to explain how to set up a window and everything. As for getting the testbed working, you're likely to have a hell of a struggle to get all the GLUI stuff working, so I would concentrate on just getting a single test rendering without any of that. I doubt if someone's done it already for that platform, but most of the important code should move over pretty well once you figure out how to draw a shape.


Top
 Profile  
 
PostPosted: Tue Feb 12, 2008 6:50 pm 
Offline

Joined: Sat Feb 09, 2008 4:00 pm
Posts: 75
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


Top
 Profile  
 
PostPosted: Sat Feb 16, 2008 6:36 pm 
Offline

Joined: Sat Feb 09, 2008 4:00 pm
Posts: 75
Image
For Box2D 1.4
/Box2D/Examples/../Render.cpp,h for Pocket PC/Smartphone/WM5 and WM6 using OPENGL ES and GLUT ES, see above.
regards, nimodo


Attachments:
Render.h [1.74 KiB]
Downloaded 281 times
Render.cpp [8.24 KiB]
Downloaded 302 times
Top
 Profile  
 
PostPosted: Sun Feb 17, 2008 9:08 am 
Offline

Joined: Fri Sep 14, 2007 1:57 pm
Posts: 22
Hi nimodo, I would like to know how many FPS did you get with "Pyramid" example, as I get less than 1fps, even with no drawing...
I'm testing on a 400Mhz ARM926 machine, could you please upload your project somewhere? I'm using eVC++ 4 to compile btw.
Thanks.


Top
 Profile  
 
PostPosted: Sun Feb 17, 2008 12:06 pm 
Offline

Joined: Sat Feb 09, 2008 4:00 pm
Posts: 75
Hello
I think to much bodies resp. contacts in the pyramides sample for the 400Mhz ARM.
I reduced the number of pieces, my measurements :)
B57/C98/J00 and B57/C98/J00
ImageImage
With B19/C17/J10 there are acceptable 16-20 fps
Image

I do not know about EV. I'm using Microsoft Visual C++ 2005, and configured my project to produce either Pocket 2003 ARM and Win32 (easier experimenting) .Maybe these libs can be used in EVC ?

To Box2D 1.4.3 added (compiled)
  • Box2D/Library/glutes.lib
  • Box2D/Library/libGLES_CM.lib
  • Box2D/Library/box2d_ppc_arm.lib
    and the include files
  • Box2D/Contrib/glutes/*.h
The following
  • glutes.dll
  • libGLES_CM.dll
must be copied to pocket pc, same location as exe, or win system directory.
You may download the OPENGL ES and GLUT ES libs from above links, or if allowed, i could upload above libraries and (~900kb) here.
regards, nimodo


Attachments:
File comment: glutes.dll +libGLES_CM.dll
ogles.zip [218.21 KiB]
Downloaded 476 times


Last edited by nimodo on Wed Mar 12, 2008 3:32 pm, edited 1 time in total.
Top
 Profile  
 
PostPosted: Sun Feb 17, 2008 12:46 pm 
Offline

Joined: Fri Sep 14, 2007 1:57 pm
Posts: 22
Thank you :) I'm using custom drawing functios, as my devices display is not recognized by those libraries :/
I can see in your screen shots, that you are getting very low FPS for quite simple scenes, so we would have to use fixed point math to gain some speed.
The problem is that all "portable" fixed point templates I've found, use "long long" data types, which is not standar c++ and not supported by eVC++4 compiler.
I'm searching for a 32bit fixed point library, written on ARM asm so it doesn't use "long long" internally, but I couldn't find any :(


Top
 Profile  
 
PostPosted: Thu Feb 28, 2008 1:20 pm 
Offline

Joined: Sat Feb 09, 2008 4:00 pm
Posts: 75
a small summary on my box2d activities
Image

The TestBed is now running on my Pocket PC. There were only a few changes:
- a new renderer/wrapper for OPENGL|ES
- some DrawXYZ (...String/Segment/...) added in a base debug drawing class (copied from erin)
- some additional _WIN32_WCE #ifdefs
- some Keyboard/Specialkeyboard adaptions (dont have a keyboard on my Ppc)

Box2D V2 itself remains untouched !

Image

As expected, the ARM 400MHz processor is too slow for examples like the Pyramide,(or the OS (Windows Mobile) does not use the processor "correctly", ...) but this isnt really important for me, as my primary interest is physical experimenting and education.
Box2D on PocketPc is really fun, even more when traveling !! For something like crayon physics, the pocket pc's performance is good enough.

my codes are of course under the same license as erin's box2d, if somebody interested and wants a starting point for "PocketBox2D", i'll attach it here.

regards, nimodo

ps: I added libgd to box2d/contrib/ for gif rendering (only win32 platform tested) to produce some simple animated gif, like above.
There is still something, that does not do as i'like to. I set the delay between frames to the minimum (1 = 0.01 sec), but the gif is slower, as the box2d... Box2D is running standard (60Hz integration). Still a lot to study...

pps: PocketTest.exe
Menu: Enter key
Scroll/Move objects: Stylus
Zoom: Up/Down or Wheel
Left/Right/1/2: Depending on example
Camera button: Launch bomb


Attachments:
File comment: Box2D Pocket TestBed Exe for Pocket PC2003 WM5&6 ARM Processor (needs ogles.zip, see above)
Updated: 2008-03-18

PocketTest.zip [99.73 KiB]
Downloaded 352 times


Last edited by nimodo on Tue Mar 18, 2008 10:01 am, edited 1 time in total.
Top
 Profile  
 
PostPosted: Sat Mar 15, 2008 4:38 am 
Offline

Joined: Sat Feb 09, 2008 4:00 pm
Posts: 75
PocketTest Sources

Examples/PocketTest/
PocketTest sources

Examples/PocketTest/Tests/
the testbed samples

Contrib/glutes/
includes if target platform is windows mobile (libs: see links above)

Contrib/libgd/
includes if GIF rendering added (libs: see links above)
int32 color must be added in struct b2Color in b2WorldCallbacks.h

Tested under Windows XP (Intel) and Windows Mobile 6 (Qualcomm ARM)


Attachments:
File comment: PocketTest (TestBed) C++ Sources Examples/PocketTest
PocketTestSources.zip [95.44 KiB]
Downloaded 359 times
Top
 Profile  
 
PostPosted: Tue Jun 09, 2009 1:35 pm 
Offline

Joined: Tue Jun 09, 2009 4:08 am
Posts: 40
this looks really interesting, although I dont use pocket pc. is there any way in which you could put all of your files in to one zip and post it here. it looks more simple than the test bed examples (famous last words possibly?) but more complicated than the hello world example. is there any way that you could put the entirety of your first pocket pc project (the mini box2d) on the forum? please?

thanks...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group