Przeglądaj źródła

Rebuilt and updated 2D Physics module, ported particle system to support 2D

Ivan Safrin 15 lat temu
rodzic
commit
9bfa6cf3d3
38 zmienionych plików z 937 dodań i 248 usunięć
  1. 1 0
      .gitignore
  2. 1 0
      Core/Contents/Include/PolyCocoaCore.h
  3. 1 0
      Core/Contents/Include/PolyEntity.h
  4. 1 1
      Core/Contents/Include/PolyGLRenderer.h
  5. 2 0
      Core/Contents/Include/PolyMesh.h
  6. 6 2
      Core/Contents/Include/PolyParticle.h
  7. 31 9
      Core/Contents/Include/PolyParticleEmitter.h
  8. 1 1
      Core/Contents/Include/PolyRenderer.h
  9. 7 0
      Core/Contents/Include/PolyScreen.h
  10. 49 7
      Core/Contents/Source/PolyCocoaCore.cpp
  11. 1 1
      Core/Contents/Source/PolyCoreServices.cpp
  12. 4 0
      Core/Contents/Source/PolyEntity.cpp
  13. 14 5
      Core/Contents/Source/PolyGLRenderer.cpp
  14. 6 0
      Core/Contents/Source/PolyGLVertexBuffer.cpp
  15. 9 4
      Core/Contents/Source/PolyMesh.cpp
  16. 43 7
      Core/Contents/Source/PolyParticle.cpp
  17. 68 27
      Core/Contents/Source/PolyParticleEmitter.cpp
  18. 6 0
      Core/Contents/Source/PolyScreen.cpp
  19. 12 1
      Core/Contents/Source/PolyScreenManager.cpp
  20. 1 1
      IDE/Contents/Include/PolycodeGlobals.h
  21. 3 0
      IDE/Contents/Include/PolycodeIDEApp.h
  22. 7 0
      IDE/Contents/Resources/FileTemplates/2D/Screen.screen
  23. 14 2
      IDE/Contents/Source/PolycodeIDEApp.cpp
  24. 164 26
      Modules/Build/Mac OS X/Modules.xcodeproj/project.pbxproj
  25. 16 7
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h
  26. 3 2
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h
  27. 5 0
      Modules/Contents/2DPhysics/Include/Polycode2DPhysics.h
  28. 50 41
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp
  29. 48 41
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp
  30. 5 4
      Modules/Contents/3DPhysics/Include/PolyCollisionScene.h
  31. 16 10
      Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h
  32. 46 0
      Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h
  33. 62 0
      Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h
  34. 3 1
      Modules/Contents/3DPhysics/Include/Polycode3DPhysics.h
  35. 9 3
      Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp
  36. 35 45
      Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp
  37. 88 0
      Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp
  38. 99 0
      Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp

+ 1 - 0
.gitignore

@@ -16,6 +16,7 @@ Tools/Build/Mac\ OS\ X/build
 Player/Build/Mac\ OS\ X/build
 Bindings/Build/Mac\ OS\ X/build
 Core/Dependencies
+IDE/Dependencies
 
 # OS generated files #
 ######################

+ 1 - 0
Core/Contents/Include/PolyCocoaCore.h

@@ -20,6 +20,7 @@
 #include <OpenGL/OpenGL.h>
 #include "PolyGLRenderer.h"
 #include <mach/mach_time.h>
+#include <unistd.h>
 
 #import <Cocoa/Cocoa.h>
 

+ 1 - 0
Core/Contents/Include/PolyEntity.h

@@ -96,6 +96,7 @@ namespace Polycode {
 			Matrix4 getConcatenatedRollMatrix();		
 		
 			void setTransformByMatrix(Matrix4 matrix);	
+			void setTransformByMatrixPure(Matrix4 matrix);	
 		
 			void setRenderer(Renderer *renderer);
 			

+ 1 - 1
Core/Contents/Include/PolyGLRenderer.h

@@ -125,7 +125,7 @@ namespace Polycode {
 		void setRenderArrayData(RenderDataArray *array, float *arrayData);
 		void drawArrays(int drawType);		
 				
-		void setOrthoMode();
+		void setOrthoMode(float xSize=0.0f, float ySize=0.0f);
 		void setPerspectiveMode();
 		
 		void enableBackfaceCulling(bool val);

+ 2 - 0
Core/Contents/Include/PolyMesh.h

@@ -26,6 +26,8 @@ namespace Polycode {
 	class _PolyExport VertexBuffer {
 		public:	
 			int getVertexCount() { return vertexCount;}
+		
+			int verticesPerFace;
 		protected:
 		int vertexCount;
 			

+ 6 - 2
Core/Contents/Include/PolyParticle.h

@@ -12,6 +12,7 @@
 #include "PolyString.h"
 #include "PolyGlobals.h"
 #include "PolySceneEntity.h"
+#include "PolyScreenShape.h"
 #include "PolyScenePrimitive.h"
 #include "PolyCoreServices.h"
 
@@ -20,11 +21,14 @@ namespace Polycode {
 
 	class _PolyExport Particle {
 		public:
-			Particle(int particleType, Material *texture, Mesh *particleMesh);
+			Particle(int particleType, bool isScreenParticle, Material *material, Texture *texture, Mesh *particleMesh);
 			~Particle();
 			void Reset();
 			
-			SceneEntity *particleBody;						
+			void createSceneParticle(int particleType, Material *material, Mesh *particleMesh);
+			void createScreenParticle(int particleType, Texture *texture, Mesh *particleMesh);
+		
+			Entity *particleBody;						
 			
 			Vector3 velVector;
 			Vector3 dirVector;	

+ 31 - 9
Core/Contents/Include/PolyParticleEmitter.h

@@ -14,6 +14,7 @@
 #include "PolyGlobals.h"
 #include "PolyEntity.h"
 #include "PolyScenePrimitive.h"
+#include "PolyScreenMesh.h"
 #include "PolyCoreServices.h"
 #include "PolyParticle.h"
 #include <vector>
@@ -21,14 +22,17 @@
 using std::vector;
 
 namespace Polycode {
-	class _PolyExport ParticleEmitter : public SceneEntity {
+	class _PolyExport ParticleEmitter {
 		public:
-			ParticleEmitter(String imageFile, Mesh *particleMesh, SceneMesh *emitter, Scene *particleParentScene, int particleType, int emitterType, float lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
-			~ParticleEmitter();
+			ParticleEmitter(String imageFile, Mesh *particleMesh, int particleType, int emitterType, float lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
+			virtual ~ParticleEmitter();
+		
+			void createParticles();
+			
 			void setRotationSpeed(float speed);
 			void setStartingColor(Color c);
 			void setEndingColor(Color c);
-			void setBlendingMode(int mode);
+			void setParticleBlendingMode(int mode);
 			void setDepthWrite(bool val);
 			void setAlphaTest(bool val);
 		
@@ -49,11 +53,14 @@ namespace Polycode {
 			
 			void setPerlinModSize(float size);
 			void setParticleCount(int count);
-
+		
+			virtual void addParticleBody(Entity *particleBody) = 0;
+			virtual Matrix4 getBaseMatrix() = 0;
+		
 			float particleSpeedMod;
 			float brightnessDeviation;
 			
-			void Update();
+			void updateEmitter();
 
 			static const int CONTINUOUS_EMITTER = 0;
 			static const int TRIGGERED_EMITTER = 1;
@@ -76,13 +83,16 @@ namespace Polycode {
 		
 		protected:
 		
-			SceneMesh *emitterMesh;
+			bool isScreenEmitter;
 			Mesh *pMesh;
 		
 			bool allAtOnce;
 			int emitterType;
 			int particleType;
 			Material *particleMaterial;
+			Texture *particleTexture;
+		
+			String textureFile;
 		
 			bool isEmitterEnabled;
 		
@@ -95,8 +105,6 @@ namespace Polycode {
 			float startingScaleMod;
 			float endingScaleMod;
 			
-			Scene *particleParentScene;			
-			
 			Color startingColor;
 			Color endingColor;
 			
@@ -108,4 +116,18 @@ namespace Polycode {
 			Timer *timer;
 	};
 
+	
+	class _PolyExport ScreenParticleEmitter : public ScreenEntity, public ParticleEmitter {
+	public:
+		ScreenParticleEmitter(String imageFile, Mesh *particleMesh, ScreenMesh *emitter, Screen *particleParentScreen, int particleType, int emitterType, float lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
+		~ScreenParticleEmitter();		
+		
+		void addParticleBody(Entity *particleBody);
+		Matrix4 getBaseMatrix();
+		void Update();
+		
+	protected:
+		ScreenMesh *emitterMesh;		
+		Screen *particleParentScreen;
+	};		
 }

+ 1 - 1
Core/Contents/Include/PolyRenderer.h

@@ -61,7 +61,7 @@ namespace Polycode {
 		virtual void setViewportSize(int w, int h, float fov=45.0f) = 0;
 		
 		virtual void loadIdentity() = 0;		
-		virtual void setOrthoMode() = 0;
+		virtual void setOrthoMode(float xSize=0.0f, float ySize=0.0f) = 0;
 		virtual void setPerspectiveMode() = 0;
 		
 		virtual void setTexture(Texture *texture) = 0;		

+ 7 - 0
Core/Contents/Include/PolyScreen.h

@@ -40,6 +40,7 @@ namespace Polycode {
 		void Render();
 		void setRenderer(Renderer *renderer);
 		
+		void setNormalizedCoordinates(bool newVal, float yCoordinateSize = 1.0f);
 		void setScreenShader(String shaderName);
 		
 		void handleEvent(Event *event);
@@ -52,6 +53,9 @@ namespace Polycode {
 		bool hasFilterShader();
 		void drawFilter();
 		
+		bool usesNormalizedCoordinates() { return useNormalizedCoordinates; }
+		float getYCoordinateSize() { return yCoordinateSize; }
+		
 		bool Lua_EntitiesEqual(ScreenEntity *ent1, ScreenEntity *ent2) { return ent1 == ent2; }
 		
 		ScreenEntity *getRootEntity() { return rootEntity; }
@@ -60,6 +64,9 @@ namespace Polycode {
 		
 	protected:
 		
+		bool useNormalizedCoordinates;
+		float yCoordinateSize;		
+		
 		ScreenEntity *rootEntity;
 		
 		Vector2 offset;

+ 49 - 7
Core/Contents/Source/PolyCocoaCore.cpp

@@ -20,11 +20,24 @@ long getThreadID() {
 CocoaCore::CocoaCore(SubstanceView *view, int xRes, int yRes, bool fullScreen,int aaLevel, int frameRate) : Core(xRes, yRes, fullScreen,aaLevel, frameRate) {	
 	eventMutex = createMutex();
 	
+//	NSLog(@"BUNDLE: %@", [[NSBundle mainBundle] bundlePath]);
+	chdir([[[NSBundle mainBundle] bundlePath] UTF8String]);
+	
 	NSOpenGLPixelFormatAttribute attrs[] =
 	{
-		NSOpenGLPFADoubleBuffer,
-		NSOpenGLPFADepthSize, 24,
-		0
+			NSOpenGLPFADoubleBuffer,	
+		NSOpenGLPFADepthSize, 16,
+//		NSOpenGLPFAFullScreen,
+//		NSOpenGLPFAScreenMask,
+//		CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
+		//		NSOpenGLPFASampleBuffers, 1,
+//		NSOpenGLPFASamples,  aaLevel,
+//		NSOpenGLPFANoRecovery,	
+//		NSOpenGLPFAWindow,
+//		NSOpenGLPFAMultisample,
+//		NSOpenGLPFAAccelerated,
+//		NSOpenGLPFAAccumSize, 0,
+		nil
 	};	
 	
 	[view lockContext];
@@ -32,9 +45,30 @@ CocoaCore::CocoaCore(SubstanceView *view, int xRes, int yRes, bool fullScreen,in
 	[view setCore:this];	
 	NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
 	context = [[NSOpenGLContext alloc] initWithFormat: format shareContext:nil];
-	[view clearGLContext];
-	[view setOpenGLContext:context];	
-	[context setView: view];	
+
+	if (context == nil) {
+        NSLog(@"Failed to create open gl context");
+	}	
+	
+	if(fullScreen) {
+	
+		[context makeCurrentContext];
+		[context setFullScreen];
+		CGDisplayCapture (kCGDirectMainDisplay ) ;		
+//		CGDisplayCapture (kCGDirectMainDisplay ) ;
+//		CGDisplaySwitchToMode (kCGDirectMainDisplay,
+//							   CGDisplayBestModeForParameters (kCGDirectMainDisplay,
+//															   32, xRes, yRes, NULL) );		
+		
+		[context clearDrawable];
+        [context release];		
+	} else {
+		[view clearGLContext];
+		[view setOpenGLContext:context];	
+		[context setView: view];					
+	}
+	
+	
 	
 	glView = view;
 	
@@ -47,7 +81,7 @@ CocoaCore::CocoaCore(SubstanceView *view, int xRes, int yRes, bool fullScreen,in
 	renderer = new OpenGLRenderer();
 	services->setRenderer(renderer);	
 	[view unlockContext];			
-	setVideoMode(xRes,yRes,fullScreen,aaLevel);
+	setVideoMode(xRes,yRes,fullScreen,aaLevel);		
 
 
 }
@@ -88,6 +122,14 @@ void CocoaCore::setVideoMode(int xRes, int yRes, bool fullScreen, int aaLevel) {
 //	frame.origin.y = (visibleFrame.size.height - frame.size.height) * (9.0/10.0);
 	
 	[[glView window] setFrame: frame display: YES animate: NO];
+	
+	/*
+	if(aaLevel > 0) {
+		glEnable( GL_MULTISAMPLE_ARB );	
+	} else {
+		glDisable( GL_MULTISAMPLE_ARB );			
+	}
+	*/
 }
 
 void CocoaCore::resizeTo(int xRes, int yRes) {

+ 1 - 1
Core/Contents/Source/PolyCoreServices.cpp

@@ -140,7 +140,7 @@ void CoreServices::Update(int elapsed) {
 	sceneManager->UpdateVirtual();
 	renderer->clearScreen();
 	sceneManager->Update();
-	renderer->setOrthoMode();
+//	renderer->setOrthoMode();
 	screenManager->Update();
 }
 

+ 4 - 0
Core/Contents/Source/PolyEntity.cpp

@@ -451,6 +451,10 @@ float Entity::getRoll() {
 	return roll;
 }
 
+void Entity::setTransformByMatrixPure(Matrix4 matrix) {
+	transformMatrix = matrix;
+}
+
 void Entity::setTransformByMatrix(Matrix4 matrix) {
 	setPosition(matrix.getPosition());	
 	float x,y,z;

+ 14 - 5
Core/Contents/Source/PolyGLRenderer.cpp

@@ -292,7 +292,10 @@ void OpenGLRenderer::drawVertexBuffer(VertexBuffer *buffer) {
 	glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getTextCoordBufferID());
 	glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
 	
-	glDrawArrays( GL_TRIANGLES, 0, buffer->getVertexCount() );
+	if(buffer->verticesPerFace == 3)
+		glDrawArrays( GL_TRIANGLES, 0, buffer->getVertexCount() );
+	else
+		glDrawArrays( GL_QUADS, 0, buffer->getVertexCount() );
 	
 	glDisableClientState( GL_VERTEX_ARRAY);	
 	glDisableClientState( GL_TEXTURE_COORD_ARRAY );		
@@ -318,7 +321,7 @@ void OpenGLRenderer::setBlendingMode(int blendingMode) {
 				glBlendFunc (GL_SRC_ALPHA, GL_ONE);
 		break;
 		case BLEND_MODE_COLOR:
-				glBlendFunc (GL_DST_COLOR, GL_ONE);
+				glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
 		break;
 		default:
 			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -377,7 +380,14 @@ void OpenGLRenderer::setFogProperties(int fogMode, Color color, float density, f
 	glClearColor(color.r, color.g, color.b, color.a);
 }
 
-void OpenGLRenderer::setOrthoMode() {
+void OpenGLRenderer::setOrthoMode(float xSize, float ySize) {
+	
+	if(xSize == 0)
+		xSize = xRes;
+
+	if(ySize == 0)
+		ySize = yRes;
+		
 	setBlendingMode(BLEND_MODE_NORMAL);
 	if(!orthoMode) {
 		glDisable(GL_LIGHTING);
@@ -385,8 +395,7 @@ void OpenGLRenderer::setOrthoMode() {
 		glDisable(GL_CULL_FACE);
 		glPushMatrix();
 		glLoadIdentity();
-		glOrtho(0.0f,xRes,yRes,0,-1.0f,1.0f);
-//		glOrtho(0.0f,2500.0f,2500.0f,0,-1.0f,1.0f);
+		glOrtho(0.0f,xSize,ySize,0,-1.0f,1.0f);
 		orthoMode = true;
 	}
 	glMatrixMode(GL_MODELVIEW);	

+ 6 - 0
Core/Contents/Source/PolyGLVertexBuffer.cpp

@@ -12,6 +12,12 @@
 using namespace Polycode;
 
 OpenGLVertexBuffer::OpenGLVertexBuffer(Mesh *mesh) : VertexBuffer() {
+	if(mesh->getMeshType() == Mesh::QUAD_MESH) {
+		verticesPerFace = 4;		
+	} else {
+		verticesPerFace = 3;				
+	}
+
 	
 	glGenBuffersARB(1, &vertexBufferID);
 	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferID);

+ 9 - 4
Core/Contents/Source/PolyMesh.cpp

@@ -259,11 +259,16 @@ namespace Polycode {
 	
 	Vector3 Mesh::calculateBBox() {
 		Vector3 retVec;
-		for(int i=0; i < vertices.size(); i++) {
-			retVec.x = max(retVec.x,fabsf(vertices[i]->x));
-			retVec.y = max(retVec.y,fabsf(vertices[i]->y));
-			retVec.z = max(retVec.z,fabsf(vertices[i]->z));			
+		
+		for(int i=0; i < polygons.size(); i++) {
+			for(int j=0; j < polygons[i]->getVertexCount(); j++) {				
+				retVec.x = max(retVec.x,fabsf(polygons[i]->getVertex(j)->x));
+				retVec.y = max(retVec.y,fabsf(polygons[i]->getVertex(j)->y));
+				retVec.z = max(retVec.z,fabsf(polygons[i]->getVertex(j)->z));							
+				
+			}
 		}
+		
 		return retVec*2;
 	}
 	

+ 43 - 7
Core/Contents/Source/PolyParticle.cpp

@@ -11,37 +11,73 @@
 
 using namespace Polycode;
 
-Particle::Particle(int particleType, Material *texture, Mesh *particleMesh) {
+Particle::Particle(int particleType, bool isScreenParticle, Material *material, Texture *texture, Mesh *particleMesh) {
+	life = 0;
+	if(isScreenParticle) {
+		createScreenParticle(particleType, texture, particleMesh);		
+	} else {
+		createSceneParticle(particleType, material, particleMesh);
+	}
+	
+	Reset();
+}
+
+void Particle::createSceneParticle(int particleType, Material *material, Mesh *particleMesh) {
 	switch(particleType) {
 		case BILLBOARD_PARTICLE:
 		{
 			ScenePrimitive *primitive = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 1.0f, 1.0f);
-			primitive->setMaterial(texture);
+			primitive->setMaterial(material);
 			primitive->billboardMode = true;
 			primitive->billboardRoll = true;
 			primitive->setDepthWrite(false);
 			primitive->backfaceCulled = false;
 			particleBody = primitive;			
 		}
-		break;
+			break;
 		case MESH_PARTICLE: 
 		{
 			SceneMesh *primitive = new SceneMesh(particleMesh);
 			if(particleMesh->getMeshType() == Mesh::TRI_MESH)
 				primitive->cacheToVertexBuffer(true);
-			primitive->setMaterial(texture);
+			primitive->setMaterial(material);
 			//			primitive->billboardMode = true;
 			//			primitive->billboardRoll = true;
 			//primitive->depthTest = false;
 			//			primitive->backfaceCulled = false;
 			particleBody = primitive;						
 		}			
-		break;
+			break;
 	}
-	life = 0;
-	Reset();
 }
 
+void Particle::createScreenParticle(int particleType, Texture *texture, Mesh *particleMesh) {
+	
+	ScreenShape *primitive = new ScreenShape(ScreenShape::SHAPE_RECT, 1.0f, 1.0f);
+	primitive->setTexture(texture);	
+	particleBody = primitive;			
+	return;
+	
+	switch(particleType) {
+		case BILLBOARD_PARTICLE:
+		{
+			ScreenShape *primitive = new ScreenShape(ScreenShape::SHAPE_RECT, 1.0f, 1.0f);
+//			primitive->setTexture(texture->get)
+			particleBody = primitive;			
+		}
+			break;
+		case MESH_PARTICLE: 
+		{
+//			ScreenMesh *primitive = new ScreenMesh(particleMesh);
+//			primitive->cacheToVertexBuffer(true);
+//			primitive->setMaterial(texture);
+//			particleBody = primitive;						
+		}			
+			break;
+	}	
+}
+
+
 void Particle::Reset() {
 	if(life > lifespan)
 		life = 0 + (life - lifespan);

+ 68 - 27
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -11,14 +11,39 @@
 
 using namespace Polycode;
 
-ParticleEmitter::ParticleEmitter(String imageFile, Mesh *particleMesh, SceneMesh *emitter, Scene *particleParentScene, int particleType, int emitterType, float lifespan, unsigned int numParticles,  Vector3 direction, Vector3 gravity, Vector3 deviation) 
-: SceneEntity() {
+
+ScreenParticleEmitter::ScreenParticleEmitter(String imageFile, Mesh *particleMesh, ScreenMesh *emitter, Screen *particleParentScreen, int particleType, int emitterType, float lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation) 
+: ParticleEmitter(imageFile, particleMesh, particleType, emitterType, lifespan, numParticles,  direction, gravity, deviation),
+ScreenEntity()
+{
+	isScreenEmitter = true;
+	emitterMesh = emitter;	
+	this->particleParentScreen = particleParentScreen;	
+	createParticles();
+}
+
+ScreenParticleEmitter::~ScreenParticleEmitter(){ 
+	
+}
+
+void ScreenParticleEmitter::Update() {
+	updateEmitter();
+}
+
+void ScreenParticleEmitter::addParticleBody(Entity *particleBody) {
+	particleParentScreen->addChild((ScreenEntity*)particleBody);
+}
+
+Matrix4 ScreenParticleEmitter::getBaseMatrix() {
+	return getConcatenatedMatrix();
+}
+
+ParticleEmitter::ParticleEmitter(String imageFile, Mesh *particleMesh, int particleType, int emitterType, float lifespan, unsigned int numParticles,  Vector3 direction, Vector3 gravity, Vector3 deviation)  {
 	
-	emitterMesh = emitter;
+	isScreenEmitter = false;
 	dirVector = direction;
 	gravVector = gravity;
 	this->emitterType = emitterType;
-	this->particleParentScene = particleParentScene;
 	this->emitSpeed = emitSpeed;
 	this->deviation = deviation;
 	pMesh = particleMesh;
@@ -37,28 +62,37 @@ ParticleEmitter::ParticleEmitter(String imageFile, Mesh *particleMesh, SceneMesh
 	emitRotationDeviance.set(360.0f, 360.0f, 360.0f);
 	isEmitterEnabled = true;
 	allAtOnce = false;
-//	particleTexture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(imageFile);	
-	particleMaterial = (Material*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_MATERIAL, imageFile);
-	Particle *particle;
+	
 	this->numParticles = numParticles;
 
 	this->lifespan = lifespan;
+	timer = new Timer(true, 1);	
+	motionPerlin = new Perlin(3,5,1.0,rand());
+	
+	textureFile = imageFile;
+}
+
+void ParticleEmitter::createParticles() {
 	
+	if(isScreenEmitter)
+		particleTexture = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile(textureFile);	
+	else
+		particleMaterial = (Material*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_MATERIAL, textureFile);	
+	
+	
+	Particle *particle;	
 	for(int i=0; i < numParticles; i++) {
-		particle = new Particle(particleType, particleMaterial,particleMesh);
+		particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
 		particle->velVector = dirVector;
 		particle->dirVector = dirVector;
 		particle->deviation = deviation;
 		particle->lifespan = lifespan;
 		particles.push_back(particle);
-		particleParentScene->addEntity(particle->particleBody);		
+		addParticleBody(particle->particleBody);					
 		resetParticle(particle);
 		particle->life = lifespan * ((float)rand()/RAND_MAX);		
 	}
-	timer = new Timer(true, 1);
-	
-	motionPerlin = new Perlin(3,5,1.0,rand());
-	Update();
+	updateEmitter();	
 }
 
 void ParticleEmitter::setEmitterRadius(float rad) {
@@ -85,7 +119,7 @@ void ParticleEmitter::setEndingScaleModifier(float mod) {
 	endingScaleMod = mod;
 }
 
-void ParticleEmitter::setBlendingMode(int mode) {
+void ParticleEmitter::setParticleBlendingMode(int mode) {
 	for(int i=0;i < particles.size(); i++) {
 		particles[i]->particleBody->setBlendingMode(mode);
 	}
@@ -130,14 +164,14 @@ void ParticleEmitter::setParticleCount(int count) {
 		int oldSize  = count-particles.size();
 		Particle *particle;
 		for(int i=0; i  < oldSize; i++) {
-			particle = new Particle(particleType, particleMaterial, pMesh);
+			particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
 			particle->velVector = dirVector;
 			particle->dirVector = dirVector;
 			particle->deviation = deviation;
 			particle->lifespan = lifespan;
 			particle->life = lifespan * ((float)rand()/RAND_MAX);
 			particles.push_back(particle);
-			particleParentScene->addEntity(particle->particleBody);
+			addParticleBody(particle->particleBody);
 		}
 	}
 	numParticles = count;
@@ -179,15 +213,17 @@ bool ParticleEmitter::emitterEnabled() {
 void ParticleEmitter::resetParticle(Particle *particle) {
 	particle->particleBody->visible = true;
 	particle->lifespan  = lifespan;
-	Matrix4 concatMatrix = getConcatenatedMatrix();
+	Matrix4 concatMatrix = getBaseMatrix();
 	Vector3	startVector;
-	if(emitterMesh) {
-		Polygon *randPoly = emitterMesh->getMesh()->getPolygon(rand() % emitterMesh->getMesh()->getPolygonCount());		
-		startVector = *randPoly->getVertex(rand() % 3);
-		startVector = emitterMesh->getConcatenatedMatrix() * startVector;
-	} else {
+	
+//	if(emitterMesh) {
+//		Polygon *randPoly = emitterMesh->getMesh()->getPolygon(rand() % emitterMesh->getMesh()->getPolygonCount());		
+//		startVector = *randPoly->getVertex(rand() % 3);
+//		startVector = emitterMesh->getConcatenatedMatrix() * startVector;
+//	} else {
 		startVector = Vector3(-(emitterRadius/2.0f)+emitterRadius*((float)rand()/RAND_MAX),-(emitterRadius/2.0f)+emitterRadius*((float)rand()/RAND_MAX),-(emitterRadius/2.0f)+emitterRadius*((float)rand()/RAND_MAX));	
-	}
+//	}
+	
 	particle->Reset();	
 	particle->velVector = particle->dirVector;
 	float dev = ((deviation.x/2.0f)*-1.0f) + ((deviation.x)*((float)rand()/RAND_MAX));
@@ -230,7 +266,8 @@ void ParticleEmitter::setAllAtOnce(bool val) {
 	}
 }
 
-void ParticleEmitter::Update() {
+void ParticleEmitter::updateEmitter() {	
+	
 	Vector3 translationVector;
 	float elapsed = timer->getElapsedf();
 	
@@ -257,9 +294,13 @@ void ParticleEmitter::Update() {
 		if(rotationFollowsPath)  {
 			particle->particleBody->lookAt(*particle->particleBody->getPosition() + translationVector, Vector3(1,0,0));			
 		} else {
-			particle->particleBody->Roll(rotationSpeed*elapsed);
-			particle->particleBody->Pitch(rotationSpeed*elapsed);
-			particle->particleBody->Yaw(rotationSpeed*elapsed);						
+			if(isScreenEmitter) {
+				particle->particleBody->Roll(rotationSpeed*elapsed);
+			} else {
+				particle->particleBody->Roll(rotationSpeed*elapsed);
+				particle->particleBody->Pitch(rotationSpeed*elapsed);
+				particle->particleBody->Yaw(rotationSpeed*elapsed);						
+			}
 		}		
 		
 		particle->particleBody->color.setColor(colorCurveR.getHeightAt(normLife)*particle->brightnessDeviation,

+ 6 - 0
Core/Contents/Source/PolyScreen.cpp

@@ -19,6 +19,7 @@ Screen::Screen() : EventDispatcher() {
 	CoreServices::getInstance()->getScreenManager()->addScreen(this);
 	filterShaderMaterial = NULL;
 	_hasFilterShader = false;
+	useNormalizedCoordinates = false;
 	rootEntity = new ScreenEntity();
 	addChild(rootEntity);
 }
@@ -29,6 +30,11 @@ Screen::~Screen() {
 	}
 }
 
+void Screen::setNormalizedCoordinates(bool newVal, float yCoordinateSize) {
+	useNormalizedCoordinates = newVal;
+	this->yCoordinateSize = yCoordinateSize;
+}
+
 void Screen::handleInputEvent(InputEvent *inputEvent) {
 	
 	for(int i=children.size()-1; i >= 0; i--) {

+ 12 - 1
Core/Contents/Source/PolyScreenManager.cpp

@@ -62,12 +62,23 @@ Screen *ScreenManager::createScreen(int screenType) {
 */
 
 void ScreenManager::Update() {
+
+	Renderer *renderer = CoreServices::getInstance()->getRenderer();
 	for(int i=0;i<screens.size();i++) {
-		if(screens[i]->enabled)
+		if(screens[i]->enabled) {
+			if(!screens[i]->usesNormalizedCoordinates()) {
+				renderer->setOrthoMode(renderer->getXRes(), renderer->getYRes());
+			} else {
+				float yCoordinateSize = screens[i]->getYCoordinateSize();
+				float ratio = ((float)renderer->getXRes())/((float)renderer->getYRes());
+				renderer->setOrthoMode(ratio*yCoordinateSize, yCoordinateSize);								
+			}
+		
 			if(screens[i]->hasFilterShader()) {
 				screens[i]->drawFilter();
 			} else {
 				screens[i]->Render();
 			}
+		}
 	}
 }

+ 1 - 1
IDE/Contents/Include/PolycodeGlobals.h

@@ -1,4 +1,4 @@
 
 #pragma once
 
-#define RESOURCE_PATH "Polycode.app/Contents/Resources/"
+#define RESOURCE_PATH "Contents/Resources/"

+ 3 - 0
IDE/Contents/Include/PolycodeIDEApp.h

@@ -37,6 +37,9 @@ public:
 	void handleEvent(Event *event);	
 	bool Update();
 	
+	void saveConfigFile();
+	void loadConfigFile();
+	
 	// menu commands
 	void newProject();
 	void newFile();	

+ 7 - 0
IDE/Contents/Resources/FileTemplates/2D/Screen.screen

@@ -0,0 +1,7 @@
+<?xml version="1.0" ?>
+<polycode_screen>
+	<config>		
+	</config>
+	<entities>
+	</entities>
+</polycode_screen>

+ 14 - 2
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -53,12 +53,12 @@ PolycodeIDEApp::PolycodeIDEApp(SubstanceView *view) : EventHandler() {
 	core->setVideoMode(1000, 600, false, 0);
 	
 	
-	CoreServices::getInstance()->getResourceManager()->addArchive(RESOURCE_PATH"tomato.polyapp");
+//	CoreServices::getInstance()->getResourceManager()->addArchive(RESOURCE_PATH"tomato.polyapp");
 	
 //	ScreenImage *img = new ScreenImage("tomato.png");
 //	screen->addChild(img);
 	
-	
+	loadConfigFile();
 }
 
 void PolycodeIDEApp::newProject() {
@@ -139,7 +139,19 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 	}
 }
 
+void PolycodeIDEApp::saveConfigFile() {
+	
+}
+
+void PolycodeIDEApp::loadConfigFile() {
+	
+}
+
+
 PolycodeIDEApp::~PolycodeIDEApp() {
+	
+	saveConfigFile();
+	
 	delete core;
 }
 

+ 164 - 26
Modules/Build/Mac OS X/Modules.xcodeproj/project.pbxproj

@@ -7,11 +7,19 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		6D690D8412C1D99700C444B0 /* Polycode3DPhysics.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D690D7E12C1D99700C444B0 /* Polycode3DPhysics.h */; };
-		6D690D8512C1D99700C444B0 /* PolyCollisionScene.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D690D7F12C1D99700C444B0 /* PolyCollisionScene.h */; };
-		6D690D8612C1D99700C444B0 /* PolyCollisionSceneEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D690D8012C1D99700C444B0 /* PolyCollisionSceneEntity.h */; };
-		6D690D8712C1D99700C444B0 /* PolyCollisionScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D690D8212C1D99700C444B0 /* PolyCollisionScene.cpp */; };
-		6D690D8812C1D99700C444B0 /* PolyCollisionSceneEntity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D690D8312C1D99700C444B0 /* PolyCollisionSceneEntity.cpp */; };
+		6D1B705012C29AFE0076D5C4 /* Polycode3DPhysics.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D1B704612C29AFE0076D5C4 /* Polycode3DPhysics.h */; };
+		6D1B705112C29AFE0076D5C4 /* PolyCollisionScene.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D1B704712C29AFE0076D5C4 /* PolyCollisionScene.h */; };
+		6D1B705212C29AFE0076D5C4 /* PolyCollisionSceneEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D1B704812C29AFE0076D5C4 /* PolyCollisionSceneEntity.h */; };
+		6D1B705312C29AFE0076D5C4 /* PolyPhysicsScene.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D1B704912C29AFE0076D5C4 /* PolyPhysicsScene.h */; };
+		6D1B705412C29AFE0076D5C4 /* PolyPhysicsSceneEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D1B704A12C29AFE0076D5C4 /* PolyPhysicsSceneEntity.h */; };
+		6D1B705512C29AFE0076D5C4 /* PolyCollisionScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D1B704C12C29AFE0076D5C4 /* PolyCollisionScene.cpp */; };
+		6D1B705612C29AFE0076D5C4 /* PolyCollisionSceneEntity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D1B704D12C29AFE0076D5C4 /* PolyCollisionSceneEntity.cpp */; };
+		6D1B705712C29AFE0076D5C4 /* PolyPhysicsScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D1B704E12C29AFE0076D5C4 /* PolyPhysicsScene.cpp */; };
+		6D1B705812C29AFE0076D5C4 /* PolyPhysicsSceneEntity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D1B704F12C29AFE0076D5C4 /* PolyPhysicsSceneEntity.cpp */; };
+		6D580E0A12D29FB5006FB999 /* PolyPhysicsScreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D580E0512D29FB5006FB999 /* PolyPhysicsScreen.h */; };
+		6D580E0B12D29FB5006FB999 /* PolyPhysicsScreenEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D580E0612D29FB5006FB999 /* PolyPhysicsScreenEntity.h */; };
+		6D580E0C12D29FB5006FB999 /* PolyPhysicsScreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D580E0812D29FB5006FB999 /* PolyPhysicsScreen.cpp */; };
+		6D580E0D12D29FB5006FB999 /* PolyPhysicsScreenEntity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D580E0912D29FB5006FB999 /* PolyPhysicsScreenEntity.cpp */; };
 		6DFB01D112A741EB00C43A7D /* PolyCGProgram.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFB01CA12A741EB00C43A7D /* PolyCGProgram.h */; };
 		6DFB01D212A741EB00C43A7D /* PolyCGShader.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFB01CB12A741EB00C43A7D /* PolyCGShader.h */; };
 		6DFB01D312A741EB00C43A7D /* PolyCGShaderModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFB01CC12A741EB00C43A7D /* PolyCGShaderModule.h */; };
@@ -49,12 +57,21 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		6D1B704612C29AFE0076D5C4 /* Polycode3DPhysics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Polycode3DPhysics.h; sourceTree = "<group>"; };
+		6D1B704712C29AFE0076D5C4 /* PolyCollisionScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyCollisionScene.h; sourceTree = "<group>"; };
+		6D1B704812C29AFE0076D5C4 /* PolyCollisionSceneEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyCollisionSceneEntity.h; sourceTree = "<group>"; };
+		6D1B704912C29AFE0076D5C4 /* PolyPhysicsScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyPhysicsScene.h; sourceTree = "<group>"; };
+		6D1B704A12C29AFE0076D5C4 /* PolyPhysicsSceneEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyPhysicsSceneEntity.h; sourceTree = "<group>"; };
+		6D1B704C12C29AFE0076D5C4 /* PolyCollisionScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyCollisionScene.cpp; sourceTree = "<group>"; };
+		6D1B704D12C29AFE0076D5C4 /* PolyCollisionSceneEntity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyCollisionSceneEntity.cpp; sourceTree = "<group>"; };
+		6D1B704E12C29AFE0076D5C4 /* PolyPhysicsScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyPhysicsScene.cpp; sourceTree = "<group>"; };
+		6D1B704F12C29AFE0076D5C4 /* PolyPhysicsSceneEntity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyPhysicsSceneEntity.cpp; sourceTree = "<group>"; };
+		6D580DF112D29F52006FB999 /* libPolycode2DPhysics.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPolycode2DPhysics.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		6D580E0512D29FB5006FB999 /* PolyPhysicsScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyPhysicsScreen.h; sourceTree = "<group>"; };
+		6D580E0612D29FB5006FB999 /* PolyPhysicsScreenEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyPhysicsScreenEntity.h; sourceTree = "<group>"; };
+		6D580E0812D29FB5006FB999 /* PolyPhysicsScreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyPhysicsScreen.cpp; sourceTree = "<group>"; };
+		6D580E0912D29FB5006FB999 /* PolyPhysicsScreenEntity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyPhysicsScreenEntity.cpp; sourceTree = "<group>"; };
 		6D690D1B12C1D74A00C444B0 /* libPolycode3DPhysics.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPolycode3DPhysics.a; sourceTree = BUILT_PRODUCTS_DIR; };
-		6D690D7E12C1D99700C444B0 /* Polycode3DPhysics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Polycode3DPhysics.h; sourceTree = "<group>"; };
-		6D690D7F12C1D99700C444B0 /* PolyCollisionScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyCollisionScene.h; sourceTree = "<group>"; };
-		6D690D8012C1D99700C444B0 /* PolyCollisionSceneEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyCollisionSceneEntity.h; sourceTree = "<group>"; };
-		6D690D8212C1D99700C444B0 /* PolyCollisionScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyCollisionScene.cpp; sourceTree = "<group>"; };
-		6D690D8312C1D99700C444B0 /* PolyCollisionSceneEntity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyCollisionSceneEntity.cpp; sourceTree = "<group>"; };
 		6DFB00FC12A736A900C43A7D /* libPolycodeCg.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPolycodeCg.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		6DFB01CA12A741EB00C43A7D /* PolyCGProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyCGProgram.h; path = ../../Contents/CgShading/Include/PolyCGProgram.h; sourceTree = "<group>"; };
 		6DFB01CB12A741EB00C43A7D /* PolyCGShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyCGShader.h; path = ../../Contents/CgShading/Include/PolyCGShader.h; sourceTree = "<group>"; };
@@ -94,6 +111,13 @@
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
+		6D580DEF12D29F52006FB999 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		6D690D1912C1D74A00C444B0 /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
@@ -131,7 +155,8 @@
 		08FB7795FE84155DC02AAC07 /* Source */ = {
 			isa = PBXGroup;
 			children = (
-				6D690D7C12C1D99700C444B0 /* 3DPhysics */,
+				6D580E0312D29FB5006FB999 /* 2DPhysics */,
+				6D1B704412C29AFE0076D5C4 /* 3DPhysics */,
 				6DFB00F012A7364300C43A7D /* PolycodeCg */,
 				6DFB00C012A71A5B00C43A7D /* PolycodeUI */,
 			);
@@ -144,35 +169,68 @@
 				6DFBF84712A3F24F00C43A7D /* libPolycodeUI.a */,
 				6DFB00FC12A736A900C43A7D /* libPolycodeCg.a */,
 				6D690D1B12C1D74A00C444B0 /* libPolycode3DPhysics.a */,
+				6D580DF112D29F52006FB999 /* libPolycode2DPhysics.a */,
 			);
 			name = Products;
 			sourceTree = "<group>";
 		};
-		6D690D7C12C1D99700C444B0 /* 3DPhysics */ = {
+		6D1B704412C29AFE0076D5C4 /* 3DPhysics */ = {
 			isa = PBXGroup;
 			children = (
-				6D690D7D12C1D99700C444B0 /* Include */,
-				6D690D8112C1D99700C444B0 /* Source */,
+				6D1B704512C29AFE0076D5C4 /* Include */,
+				6D1B704B12C29AFE0076D5C4 /* Source */,
 			);
 			name = 3DPhysics;
 			path = ../../Contents/3DPhysics;
 			sourceTree = SOURCE_ROOT;
 		};
-		6D690D7D12C1D99700C444B0 /* Include */ = {
+		6D1B704512C29AFE0076D5C4 /* Include */ = {
+			isa = PBXGroup;
+			children = (
+				6D1B704612C29AFE0076D5C4 /* Polycode3DPhysics.h */,
+				6D1B704712C29AFE0076D5C4 /* PolyCollisionScene.h */,
+				6D1B704812C29AFE0076D5C4 /* PolyCollisionSceneEntity.h */,
+				6D1B704912C29AFE0076D5C4 /* PolyPhysicsScene.h */,
+				6D1B704A12C29AFE0076D5C4 /* PolyPhysicsSceneEntity.h */,
+			);
+			path = Include;
+			sourceTree = "<group>";
+		};
+		6D1B704B12C29AFE0076D5C4 /* Source */ = {
+			isa = PBXGroup;
+			children = (
+				6D1B704C12C29AFE0076D5C4 /* PolyCollisionScene.cpp */,
+				6D1B704D12C29AFE0076D5C4 /* PolyCollisionSceneEntity.cpp */,
+				6D1B704E12C29AFE0076D5C4 /* PolyPhysicsScene.cpp */,
+				6D1B704F12C29AFE0076D5C4 /* PolyPhysicsSceneEntity.cpp */,
+			);
+			path = Source;
+			sourceTree = "<group>";
+		};
+		6D580E0312D29FB5006FB999 /* 2DPhysics */ = {
+			isa = PBXGroup;
+			children = (
+				6D580E0412D29FB5006FB999 /* Include */,
+				6D580E0712D29FB5006FB999 /* Source */,
+			);
+			name = 2DPhysics;
+			path = ../../Contents/2DPhysics;
+			sourceTree = SOURCE_ROOT;
+		};
+		6D580E0412D29FB5006FB999 /* Include */ = {
 			isa = PBXGroup;
 			children = (
-				6D690D7E12C1D99700C444B0 /* Polycode3DPhysics.h */,
-				6D690D7F12C1D99700C444B0 /* PolyCollisionScene.h */,
-				6D690D8012C1D99700C444B0 /* PolyCollisionSceneEntity.h */,
+				6D580E0512D29FB5006FB999 /* PolyPhysicsScreen.h */,
+				6D580E0612D29FB5006FB999 /* PolyPhysicsScreenEntity.h */,
 			);
 			path = Include;
 			sourceTree = "<group>";
 		};
-		6D690D8112C1D99700C444B0 /* Source */ = {
+		6D580E0712D29FB5006FB999 /* Source */ = {
 			isa = PBXGroup;
 			children = (
-				6D690D8212C1D99700C444B0 /* PolyCollisionScene.cpp */,
-				6D690D8312C1D99700C444B0 /* PolyCollisionSceneEntity.cpp */,
+				6D580E0812D29FB5006FB999 /* PolyPhysicsScreen.cpp */,
+				6D580E0912D29FB5006FB999 /* PolyPhysicsScreenEntity.cpp */,
 			);
 			path = Source;
 			sourceTree = "<group>";
@@ -235,13 +293,24 @@
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
+		6D580DED12D29F52006FB999 /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				6D580E0A12D29FB5006FB999 /* PolyPhysicsScreen.h in Headers */,
+				6D580E0B12D29FB5006FB999 /* PolyPhysicsScreenEntity.h in Headers */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		6D690D1712C1D74A00C444B0 /* Headers */ = {
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				6D690D8412C1D99700C444B0 /* Polycode3DPhysics.h in Headers */,
-				6D690D8512C1D99700C444B0 /* PolyCollisionScene.h in Headers */,
-				6D690D8612C1D99700C444B0 /* PolyCollisionSceneEntity.h in Headers */,
+				6D1B705012C29AFE0076D5C4 /* Polycode3DPhysics.h in Headers */,
+				6D1B705112C29AFE0076D5C4 /* PolyCollisionScene.h in Headers */,
+				6D1B705212C29AFE0076D5C4 /* PolyCollisionSceneEntity.h in Headers */,
+				6D1B705312C29AFE0076D5C4 /* PolyPhysicsScene.h in Headers */,
+				6D1B705412C29AFE0076D5C4 /* PolyPhysicsSceneEntity.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -279,6 +348,23 @@
 /* End PBXHeadersBuildPhase section */
 
 /* Begin PBXNativeTarget section */
+		6D580DF012D29F52006FB999 /* Polycode2DPhysics */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 6D580DF512D29F55006FB999 /* Build configuration list for PBXNativeTarget "Polycode2DPhysics" */;
+			buildPhases = (
+				6D580DED12D29F52006FB999 /* Headers */,
+				6D580DEE12D29F52006FB999 /* Sources */,
+				6D580DEF12D29F52006FB999 /* Frameworks */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = Polycode2DPhysics;
+			productName = Polycode2DPhysics;
+			productReference = 6D580DF112D29F52006FB999 /* libPolycode2DPhysics.a */;
+			productType = "com.apple.product-type.library.static";
+		};
 		6D690D1A12C1D74A00C444B0 /* Polycode3DPhysics */ = {
 			isa = PBXNativeTarget;
 			buildConfigurationList = 6D690D2012C1D76A00C444B0 /* Build configuration list for PBXNativeTarget "Polycode3DPhysics" */;
@@ -352,17 +438,29 @@
 				6DFBF84612A3F24F00C43A7D /* PolycodeUI */,
 				6DFB00FB12A736A900C43A7D /* PolycodeCg */,
 				6D690D1A12C1D74A00C444B0 /* Polycode3DPhysics */,
+				6D580DF012D29F52006FB999 /* Polycode2DPhysics */,
 			);
 		};
 /* End PBXProject section */
 
 /* Begin PBXSourcesBuildPhase section */
+		6D580DEE12D29F52006FB999 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				6D580E0C12D29FB5006FB999 /* PolyPhysicsScreen.cpp in Sources */,
+				6D580E0D12D29FB5006FB999 /* PolyPhysicsScreenEntity.cpp in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		6D690D1812C1D74A00C444B0 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				6D690D8712C1D99700C444B0 /* PolyCollisionScene.cpp in Sources */,
-				6D690D8812C1D99700C444B0 /* PolyCollisionSceneEntity.cpp in Sources */,
+				6D1B705512C29AFE0076D5C4 /* PolyCollisionScene.cpp in Sources */,
+				6D1B705612C29AFE0076D5C4 /* PolyCollisionSceneEntity.cpp in Sources */,
+				6D1B705712C29AFE0076D5C4 /* PolyPhysicsScene.cpp in Sources */,
+				6D1B705812C29AFE0076D5C4 /* PolyPhysicsSceneEntity.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -409,6 +507,7 @@
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
 				HEADER_SEARCH_PATHS = (
+					../../../Core/Dependencies/box2d/Box2D,
 					../../../Core/Contents/Include,
 					../../../Core/Dependencies/bullet/src,
 					../../../Core/Dependencies/libvorbis/include,
@@ -437,6 +536,36 @@
 			};
 			name = Release;
 		};
+		6D580DF212D29F52006FB999 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				COPY_PHASE_STRIP = NO;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_ENABLE_FIX_AND_CONTINUE = YES;
+				GCC_MODEL_TUNING = G5;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				INSTALL_PATH = /usr/local/lib;
+				PREBINDING = NO;
+				PRODUCT_NAME = Polycode2DPhysics;
+			};
+			name = Debug;
+		};
+		6D580DF312D29F52006FB999 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				COPY_PHASE_STRIP = YES;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				GCC_ENABLE_FIX_AND_CONTINUE = NO;
+				GCC_MODEL_TUNING = G5;
+				INSTALL_PATH = /usr/local/lib;
+				PREBINDING = NO;
+				PRODUCT_NAME = Polycode2DPhysics;
+				ZERO_LINK = NO;
+			};
+			name = Release;
+		};
 		6D690D1C12C1D74A00C444B0 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
@@ -548,6 +677,15 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
+		6D580DF512D29F55006FB999 /* Build configuration list for PBXNativeTarget "Polycode2DPhysics" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				6D580DF212D29F52006FB999 /* Debug */,
+				6D580DF312D29F52006FB999 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
 		6D690D2012C1D76A00C444B0 /* Build configuration list for PBXNativeTarget "Polycode3DPhysics" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (

+ 16 - 7
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -12,7 +12,7 @@
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyScreen.h"
-#include "Box2D.h"
+#include "Box2D/Box2D.h"
 //#include "PolyCoreServices.h"
 #include "PolyScreenLine.h"
 #include "PolyPhysicsScreenEntity.h"
@@ -58,13 +58,12 @@ class _PolyExport PhysicsScreen : public Screen, b2ContactListener {
 
 public:
 	PhysicsScreen();
-	PhysicsScreen(float freq);
-	
-	PhysicsScreen(Vector2 physicsWorldLowerBound, Vector2 physicsWorldUpperBound);
+	PhysicsScreen(float worldScale, float freq);
+
 	~PhysicsScreen();
 	
 	void Update();
-	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, float friction, float density, float restitution = 0, bool isSensor = false);
+	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, float friction, float density, float restitution = 0, bool isSensor = false, bool fixedRotation = false);
 	void removePhysicsChild(PhysicsScreenEntity *entityToRemove);
 	
 	PhysicsScreenEntity *addCollisionChild(ScreenEntity *newEntity, int entType);
@@ -72,19 +71,26 @@ public:
 	void createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected);
 	void createPrismaticJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected);
 	b2RevoluteJoint *createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, float ax, float ay, bool enableLimit, float lowerLimit, float upperLimit, bool motorEnabled, float motorSpeed, float maxTorque);
-	b2MouseJoint *createMouseJoint(ScreenEntity *ent1, Vector2 *mp);
+//	b2MouseJoint *createMouseJoint(ScreenEntity *ent1, Vector2 *mp);
 	void applyForce(ScreenEntity *ent, float fx, float fy);
 	void applyImpulse(ScreenEntity *ent, float fx, float fy);
 	
+	void setGravity(Vector2 newGravity);
+	
 	PhysicsScreenEntity *getPhysicsEntityByShape(b2Shape *shape);
 	
 	void setVelocity(ScreenEntity *ent, float fx, float fy);	
 	void setVelocityX(ScreenEntity *ent, float fx);	
 	void setVelocityY(ScreenEntity *ent, float fy);	
 	
+	/*
 	void Add(const b2ContactPoint* point);
 	void Persist(const b2ContactPoint* point);
 	void Remove(const b2ContactPoint* point);				
+	*/
+		
+	void BeginContact (b2Contact *contact);
+	void EndContact (b2Contact *contact);	
 	
 	void wakeUp(ScreenEntity *ent);
 	
@@ -104,7 +110,10 @@ public:
 
 protected:
 	
-	void init(Vector2 physicsWorldLowerBound, Vector2 physicsWorldUpperBound, float physicsTimeStep, int physicsIterations, Vector2 physicsGravity);
+	
+	float worldScale;
+	
+	void init(float worldScale, float physicsTimeStep, int physicsIterations, Vector2 physicsGravity);
 
 	Timer *updateTimer;
 	vector <PhysicsScreenEntity*> physicsChildren;

+ 3 - 2
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -12,13 +12,13 @@
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyScreenEntity.h"
-#include "Box2D.h"
+#include "Box2D/Box2D.h"
 
 namespace Polycode {
 
 	class _PolyExport PhysicsScreenEntity {
 		public:
-			PhysicsScreenEntity(ScreenEntity *entity, b2World *world, int entType, float friction, float density, float restitution, bool isSensor);
+			PhysicsScreenEntity(ScreenEntity *entity, b2World *world, float worldScale, int entType, float friction, float density, float restitution, bool isSensor, bool fixedRotation);
 			~PhysicsScreenEntity();		
 			
 			ScreenEntity *getScreenEntity();
@@ -40,6 +40,7 @@ namespace Polycode {
 		
 		protected:
 		
+		float worldScale;
 		Vector2 lastPosition;
 		float lastRotation;
 			

+ 5 - 0
Modules/Contents/2DPhysics/Include/Polycode2DPhysics.h

@@ -0,0 +1,5 @@
+
+#pragma once
+
+#include "PolyPhysicsScreen.h"
+#include "PolyPhysicsScreenEntity.h"

+ 50 - 41
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -12,7 +12,7 @@
 
 using namespace Polycode;
 
-
+/*
 void PhysicsScreen::Add(const b2ContactPoint* point) {
 	if (numContactPoints == MAX_B2DCONTACTPOINTS) {
 		return;
@@ -60,32 +60,36 @@ void PhysicsScreen::Remove(const b2ContactPoint* point) {
 	
 	++numContactPoints;
 }
+*/
 
-PhysicsScreen::PhysicsScreen() : Screen() {
-	init(Vector2(-200.0f, -100.0f),Vector2(8500.0f, 1000.0f),1.0f/60.0f,10,Vector2(0.0f, 10.0f));
+void PhysicsScreen::BeginContact (b2Contact *contact) {
+	
+}
+
+void PhysicsScreen::EndContact (b2Contact *contact) {
+	
 }
 
-PhysicsScreen::PhysicsScreen(float freq) : Screen() {
-	init(Vector2(-200.0f, -100.0f),Vector2(8500.0f, 1000.0f),1.0f/freq,10,Vector2(0.0f, 10.0f));	
+
+PhysicsScreen::PhysicsScreen() : Screen() {
+	init(10.0f, 1.0f/60.0f,10,Vector2(0.0f, 10.0f));
 }
 
-PhysicsScreen::PhysicsScreen(Vector2 physicsWorldLowerBound, Vector2 physicsWorldUpperBound)
-{
-	init(physicsWorldLowerBound,physicsWorldUpperBound,1.0f/60.0f,10,Vector2(0.0f, 10.0f));
+PhysicsScreen::PhysicsScreen(float worldScale, float freq) : Screen() {
+	init(worldScale, 1.0f/freq,10,Vector2(0.0f, 10.0f));	
 }
 
-void PhysicsScreen::init(Vector2 physicsWorldLowerBound, Vector2 physicsWorldUpperBound, float physicsTimeStep, int physicsIterations, Vector2 physicsGravity) {
+void PhysicsScreen::init(float worldScale, float physicsTimeStep, int physicsIterations, Vector2 physicsGravity) {
+	
+	this->worldScale = worldScale;
+	
 	numContactPoints = 0;	
 	timeStep = physicsTimeStep;
 	iterations = physicsIterations;
 	
-	b2AABB worldAABB;
-	worldAABB.lowerBound.Set(physicsWorldLowerBound.x/10.0,physicsWorldLowerBound.y/10.0);
-	worldAABB.upperBound.Set(physicsWorldUpperBound.x/10.0,physicsWorldUpperBound.y/10.0);
-	
 	b2Vec2 gravity(physicsGravity.x,physicsGravity.y);
 	bool doSleep = true;
-	world  = new b2World(worldAABB, gravity, doSleep);
+	world  = new b2World(gravity, doSleep);
 	
 	world->SetContactListener(this);
 
@@ -93,6 +97,10 @@ void PhysicsScreen::init(Vector2 physicsWorldLowerBound, Vector2 physicsWorldUpp
 	updateTimer->addEventListener(this, Timer::EVENT_TRIGGER);
 }
 
+void PhysicsScreen::setGravity(Vector2 newGravity) {
+	world->SetGravity(b2Vec2(newGravity.x, newGravity.y));
+}
+
 PhysicsScreenEntity *PhysicsScreen::getPhysicsByScreenEntity(ScreenEntity *ent) {
 	for(int i=0; i<physicsChildren.size();i++) {
 		if(physicsChildren[i]->getScreenEntity() == ent)
@@ -107,7 +115,7 @@ b2RevoluteJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEn
 	if(pEnt1 == NULL || pEnt2 == NULL)
 		return NULL;
 	
-	b2Vec2 anchor((ent1->getPosition()->x+ax)/10.0f, (ent1->getPosition()->y+ay)/10.0f);
+	b2Vec2 anchor((ent1->getPosition()->x+ax)/worldScale, (ent1->getPosition()->y+ay)/worldScale);
 	b2RevoluteJointDef *jointDef = new b2RevoluteJointDef();
 	jointDef->collideConnected = false;
 	jointDef->lowerAngle = lowerLimit * (PI/180.0f);
@@ -130,15 +138,16 @@ void PhysicsScreen::wakeUp(ScreenEntity *ent) {
 	if(pEnt == NULL)
 		return;
 		
-	pEnt->body->WakeUp();
+	pEnt->body->SetAwake(true);
 }
 
+
 void PhysicsScreen::setVelocity(ScreenEntity *ent, float fx, float fy) {
 	PhysicsScreenEntity *pEnt = getPhysicsByScreenEntity(ent);
 	if(pEnt == NULL)
 		return;
 	
-	pEnt->body->WakeUp();
+	pEnt->body->SetAwake(true);
 	b2Vec2 f = pEnt->body->GetLinearVelocity();
 	if(fx != 0)
 		f.x = fx;
@@ -153,7 +162,7 @@ void PhysicsScreen::setVelocityX(ScreenEntity *ent, float fx) {
 	if(pEnt == NULL)
 		return;
 	
-	pEnt->body->WakeUp();
+	pEnt->body->SetAwake(true);
 	b2Vec2 f = pEnt->body->GetLinearVelocity();
 	f.x = fx;	
 	pEnt->body->SetLinearVelocity(f);
@@ -165,7 +174,7 @@ void PhysicsScreen::setVelocityY(ScreenEntity *ent, float fy) {
 	if(pEnt == NULL)
 		return;
 	
-	pEnt->body->WakeUp();
+	pEnt->body->SetAwake(true);
 	b2Vec2 f = pEnt->body->GetLinearVelocity();
 	f.y = fy;	
 	pEnt->body->SetLinearVelocity(f);	
@@ -184,7 +193,7 @@ void PhysicsScreen::applyForce(ScreenEntity *ent, float fx, float fy) {
 	if(pEnt == NULL)
 		return;
 
-	pEnt->body->WakeUp();
+	pEnt->body->SetAwake(true);
 	b2Vec2 f =  b2Vec2(fx,fy);
 	b2Vec2 p = pEnt->body->GetWorldPoint(b2Vec2(0.0f, 0.0f));
 		
@@ -196,11 +205,10 @@ void PhysicsScreen::applyImpulse(ScreenEntity *ent, float fx, float fy) {
 	if(pEnt == NULL)
 		return;
 	
-	pEnt->body->WakeUp();
+	pEnt->body->SetAwake(true);
 	b2Vec2 f =  b2Vec2(fx,fy);
-	b2Vec2 p = pEnt->body->GetWorldPoint(b2Vec2(0.0f, 0.0f));
-	
-	pEnt->body->ApplyImpulse(f, p);	
+	b2Vec2 p = pEnt->body->GetWorldPoint(b2Vec2(0.0f, 0.0f));	
+	pEnt->body->ApplyLinearImpulse(f, p);	
 }
 
 
@@ -211,24 +219,24 @@ void PhysicsScreen::createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2,
 	if(pEnt1 == NULL || pEnt2 == NULL)
 		return;
 	
-	b2Vec2 a1(ent1->getPosition()->x/10.0f, ent1->getPosition()->y/10.0f);
-	b2Vec2 a2(ent2->getPosition()->x/10.0f, ent2->getPosition()->y/10.0f);
+	b2Vec2 a1(ent1->getPosition()->x/worldScale, ent1->getPosition()->y/worldScale);
+	b2Vec2 a2(ent2->getPosition()->x/worldScale, ent2->getPosition()->y/worldScale);
 	b2DistanceJointDef *jointDef = new b2DistanceJointDef();
 	jointDef->Initialize(pEnt1->body, pEnt2->body, a1, a2);
 	jointDef->collideConnected = collideConnected;
 	world->CreateJoint(jointDef);
 }
-
+/*
 b2MouseJoint *PhysicsScreen::createMouseJoint(ScreenEntity *ent1, Vector2 *mp) {
 	
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
 	if(pEnt1 == NULL)
 		return NULL;
 
-	b2MouseJointDef *mj = new b2MouseJointDef();
+	b2MouseJointDef *mj = new b2MouseJointDef();	
+	mj->bodyA = world->GetGroundBody();
+	mj->bodyB = pEnt1->body;
 	
-	mj->body1 = world->GetGroundBody();
-	mj->body2 = pEnt1->body;
 	b2Vec2 mpos(mp->x/10.0f, mp->y/10.0f);
 	mj->target = mpos;
 #ifdef TARGET_FLOAT32_IS_FIXED
@@ -237,10 +245,11 @@ b2MouseJoint *PhysicsScreen::createMouseJoint(ScreenEntity *ent1, Vector2 *mp) {
 	mj->maxForce = 1000.0f * pEnt1->body->GetMass();
 #endif
 	b2MouseJoint *m_mouseJoint = (b2MouseJoint*)world->CreateJoint(mj);
-	pEnt1->body->WakeUp();
+	pEnt1->body->SetAwake(true);
 	Logger::log("OK %d!\n", m_mouseJoint);
 	return m_mouseJoint;
 }
+*/
 
 Vector2 PhysicsScreen::getEntityCollisionNormal(ScreenEntity *ent1, ScreenEntity *ent2) {
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
@@ -292,12 +301,12 @@ ScreenEntity *PhysicsScreen::getEntityAtPosition(float x, float y) {
 	ScreenEntity *ret = NULL;
 	
 	b2Vec2 mousePosition;
-	mousePosition.x = x/10.0f;
-	mousePosition.y = y/10.0f;
+	mousePosition.x = x/worldScale;
+	mousePosition.y = y/worldScale;
 	
 	for(int i=0;i<physicsChildren.size();i++) {
 		PhysicsScreenEntity *ent = physicsChildren[i];
-		if(ent->shape->TestPoint(ent->body->GetXForm(), mousePosition))
+		if(ent->shape->TestPoint(ent->body->GetTransform(), mousePosition))
 			return ent->getScreenEntity();
 	}	
 	return ret;
@@ -310,10 +319,10 @@ bool PhysicsScreen::testEntityAtPosition(ScreenEntity *ent, float x, float y) {
 		return false;
 	
 	b2Vec2 mousePosition;
-	mousePosition.x = x/10.0f;
-	mousePosition.y = y/10.0f;
+	mousePosition.x = x/worldScale;
+	mousePosition.y = y/worldScale;
 	
-	if(pEnt->shape->TestPoint(pEnt->body->GetXForm(), mousePosition))
+	if(pEnt->shape->TestPoint(pEnt->body->GetTransform(), mousePosition))
 		return true;
 	else
 		return false;
@@ -325,12 +334,12 @@ void PhysicsScreen::destroyMouseJoint(b2MouseJoint *mJoint) {
 		mJoint = NULL;
 }
 
-PhysicsScreenEntity *PhysicsScreen::addPhysicsChild(ScreenEntity *newEntity, int entType, float friction, float density, float restitution, bool isSensor) {
+PhysicsScreenEntity *PhysicsScreen::addPhysicsChild(ScreenEntity *newEntity, int entType, float friction, float density, float restitution, bool isSensor, bool fixedRotation) {
 	addChild(newEntity);
 	newEntity->setPositionMode(ScreenEntity::POSITION_CENTER);
-	PhysicsScreenEntity *newPhysicsEntity = new PhysicsScreenEntity(newEntity, world, entType, friction, density, restitution, isSensor);
+	PhysicsScreenEntity *newPhysicsEntity = new PhysicsScreenEntity(newEntity, world, worldScale, entType, friction, density, restitution, isSensor,fixedRotation);
 	physicsChildren.push_back(newPhysicsEntity);
-	newPhysicsEntity->body->WakeUp();
+	newPhysicsEntity->body->SetAwake(true);
 	return newPhysicsEntity;
 }
 
@@ -369,7 +378,7 @@ void PhysicsScreen::handleEvent(Event *event) {
 	numContactPoints = 0;
 	
 	if(event->getDispatcher() == updateTimer) {		
-		world->Step(timeStep, iterations);
+		world->Step(timeStep, iterations,iterations);
 	}
 	
 	for (int32 i = 0; i < numContactPoints; ++i)

+ 48 - 41
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -13,52 +13,58 @@
 
 using namespace Polycode;
 
-PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, int entType, float friction, float density, float restitution, bool isSensor) {
+PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, float worldScale, int entType, float friction, float density, float restitution, bool isSensor, bool fixedRotation) {
+	
+	this->worldScale = worldScale;
+	
 	screenEntity = entity;
 	
 	bodyDef = new b2BodyDef();
-	bodyDef->position.Set(screenEntity->getPosition()->x/10.0f, screenEntity->getPosition()->y/10.0f);
-	bodyDef->angle = screenEntity->getRotation()*(PI/180.0f);
+	bodyDef->position.Set(screenEntity->getPosition()->x/worldScale, screenEntity->getPosition()->y/worldScale);
+	bodyDef->angle = screenEntity->getRotation()*(PI/180.0f);	
+	bodyDef->bullet = isSensor;	
+	bodyDef->fixedRotation = fixedRotation;
+	
+	if(entType != ENTITY_STATICRECT)
+		bodyDef->type = b2_dynamicBody;	
+	
 	body = world->CreateBody(bodyDef);
-	bodyDef->isBullet = isSensor;
 	
+	b2FixtureDef fDef;
+	fDef.friction = friction;
+	fDef.restitution = restitution;
+	fDef.density = density;
+	fDef.isSensor = isSensor;
+		
 	switch(entType) {
-		case ENTITY_STATICRECT:{
-			b2PolygonDef *groundShapeDef = new b2PolygonDef();
-			groundShapeDef->isSensor = isSensor;
-			groundShapeDef->SetAsBox(screenEntity->getWidth()/20.0f, screenEntity->getHeight()/20.0f);
-			shape = body->CreateShape(groundShapeDef);
+		case ENTITY_STATICRECT:
+		{
+			b2PolygonShape b2shape;			
+			b2shape.SetAsBox(screenEntity->getWidth()/(worldScale*2.0f), screenEntity->getHeight()/(worldScale*2.0f));
+			fDef.shape = &b2shape;			
 		}
 		break;
-		case ENTITY_RECT: {
-			b2PolygonDef *shapeDef;
-			shapeDef = new b2PolygonDef();
-			shapeDef->SetAsBox(screenEntity->getWidth()/20.0f, screenEntity->getHeight()/20.0f);
-			shapeDef->density = density;
-			shapeDef->friction = friction;
-			shapeDef->restitution = restitution;
-			shapeDef->isSensor = isSensor;			
-			shape = body->CreateShape(shapeDef);
-			}
+		case ENTITY_RECT: 
+		{
+			b2PolygonShape b2shape;			
+			b2shape.SetAsBox(screenEntity->getWidth()/(worldScale*2.0f), screenEntity->getHeight()/(worldScale*2.0f));
+			fDef.shape = &b2shape;						
+		}
 		break;			
-		case ENTITY_CIRCLE: {
-			b2CircleDef *shapeDef = new b2CircleDef();
-			shapeDef->radius = screenEntity->getWidth()/20.0f;
-			shapeDef->density = density;
-//			shapeDef->SetAsBox(screenEntity->getWidth()/20.0f, screenEntity->getHeight()/20.0f);
-			shapeDef->friction = friction;
-			shapeDef->restitution = restitution;
-			shapeDef->isSensor = isSensor;				
-			shape = body->CreateShape(shapeDef);
-			}
+		case ENTITY_CIRCLE:
+		{			
+			b2CircleShape b2shape;
+			b2shape.m_radius = screenEntity->getWidth()/(worldScale*2.0f);
+			fDef.shape = &b2shape;
+		}
 		break;
 	}
 	
+	body->CreateFixture(&fDef);	
+	
 	lastPosition.x = screenEntity->getPosition2D().x;
 	lastPosition.y = screenEntity->getPosition2D().y;
 
-	body->SetMassFromShapes();
-
 	collisionOnly = false;
 }
 
@@ -67,7 +73,7 @@ void PhysicsScreenEntity::applyTorque(float torque) {
 }
 
 void PhysicsScreenEntity::applyForce(Vector2 force){
-	body->WakeUp();
+	body->SetAwake(true);
 	body->ApplyForce(b2Vec2(force.x,force.y), b2Vec2(body->GetPosition().x,body->GetPosition().y));
 }
 
@@ -79,25 +85,26 @@ void PhysicsScreenEntity::Update() {
 	b2Vec2 position = body->GetPosition();
 	float32 angle = body->GetAngle();
 
+	
 	if(lastRotation != screenEntity->getRotation() || collisionOnly) {
-		body->SetXForm(position, screenEntity->getRotation()*(PI/180.0f));		
+		body->SetTransform(position, screenEntity->getRotation()*(PI/180.0f));		
 	} else {
 		screenEntity->setRotation(angle*(180.0f/PI));	
 	}
 	
 	if(lastPosition != screenEntity->getPosition2D() || collisionOnly) {
 		b2Vec2 newPos;
-		newPos.x = screenEntity->getPosition2D().x/10.0f; 
-		newPos.y = screenEntity->getPosition2D().y/10.0f;				
-		body->SetXForm(newPos, screenEntity->getRotation()*(PI/180.0f));
-		position.x = screenEntity->getPosition2D().x/10.0f; 
-		position.y = screenEntity->getPosition2D().y/10.0f; 				
+		newPos.x = screenEntity->getPosition2D().x/worldScale; 
+		newPos.y = screenEntity->getPosition2D().y/worldScale;				
+		body->SetTransform(newPos, screenEntity->getRotation()*(PI/180.0f));
+		position.x = screenEntity->getPosition2D().x/worldScale; 
+		position.y = screenEntity->getPosition2D().y/worldScale; 				
 	} else {
-		screenEntity->setPosition(position.x*10.0f, position.y*10.0f);
+		screenEntity->setPosition(position.x*worldScale, position.y*worldScale);
 	}
 	
-	lastPosition.x = position.x*10.0f;
-	lastPosition.y = position.y*10.0f;	
+	lastPosition.x = position.x*worldScale;
+	lastPosition.y = position.y*worldScale;	
 	
 	lastRotation = angle * (180.0f/PI);
 }

+ 5 - 4
Modules/Contents/3DPhysics/Include/PolyCollisionScene.h

@@ -36,15 +36,16 @@ struct CollisionResult {
 		Vector3 position;
 	};
 
+	
 	class _PolyExport CollisionScene : public GenericScene {
 		public:
 			CollisionScene();
 			CollisionScene(bool virtualScene);		
-			~CollisionScene();
+			virtual ~CollisionScene();
 		
 			void initCollisionScene();
 		
-			void Update();		
+			virtual void Update();		
 			void enableCollision(SceneEntity *entity, bool val);		
 			CollisionSceneEntity *getCollisionEntityByObject(btCollisionObject *collisionObject);		
 			RayTestResult getFirstEntityInRay(const Vector3 &origin,  const Vector3 &dest);
@@ -60,10 +61,10 @@ struct CollisionResult {
 			void loadCollisionChild(SceneEntity *entity, bool autoCollide=false, int type=0);
 			void enableGravity(SceneEntity *entity);
 			
-			CollisionSceneEntity *addCollisionChild(SceneEntity *newEntity, bool autoCollide=false, int type=0);
+			virtual CollisionSceneEntity *addCollisionChild(SceneEntity *newEntity, bool autoCollide=false, int type=0);
 			CollisionSceneEntity *trackCollision(SceneEntity *newEntity, bool autoCollide, int type=0);
 			void adjustForCollision(CollisionSceneEntity *collisionEntity);
-		private:
+		protected:
 		
 			vector<CollisionSceneEntity*> collisionChildren;
 			btCollisionWorld *world;

+ 16 - 10
Modules/Contents/3DPhysics/Include/PolyCollisionSceneEntity.h

@@ -24,10 +24,12 @@ namespace Polycode {
 			~CollisionSceneEntity();
 			
 			SceneEntity *getSceneEntity();
-			void Update();
-		
+			virtual void Update();
 			int getType() { return type; }
-			btConvexShape *getShape(){ return shape; }
+		
+			btConvexShape *getConvexShape(){ return convexShape; }
+					
+			btCollisionShape *createCollisionShape(SceneEntity *entity, int type);
 		
 			btCollisionObject *collisionObject;
 			bool gravityEnabled;
@@ -38,17 +40,21 @@ namespace Polycode {
 		
 			Vector3 lastPosition;
 		
-			static const int SHAPE_BOX = 0;
-			static const int SHAPE_TERRAIN = 1;
-			static const int SHAPE_SPHERE = 2;	
-			static const int SHAPE_MESH = 3;			
+		static const int SHAPE_BOX = 0;
+		static const int SHAPE_TERRAIN = 1;
+		static const int SHAPE_SPHERE = 2;	
+		static const int SHAPE_MESH = 3;			
+		static const int CHARACTER_CONTROLLER = 4;
+		static const int SHAPE_CAPSULE = 5;		
 		
 			bool enabled;
+			btCollisionShape *shape;
 		
-		private:
+		protected:
 		
-			
-			btConvexShape *shape;
+
+			btConvexShape *convexShape;
+			btConcaveShape *concaveShape;
 		
 			int type;
 			SceneEntity *sceneEntity;

+ 46 - 0
Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h

@@ -0,0 +1,46 @@
+/*
+ *  PolyPhysicsScene.h
+ *  Modules
+ *
+ *  Created by Ivan Safrin on 12/22/10.
+ *  Copyright 2010 Local Projects. All rights reserved.
+ *
+ */
+
+// @package SceneDynamics
+
+#pragma once
+#include "btBulletCollisionCommon.h"
+#include "btBulletDynamicsCommon.h"
+#include "PolyLogger.h"
+#include "PolyGlobals.h"
+#include "PolyCollisionScene.h"
+#include "PolyVector3.h"
+#include "PolyPhysicsSceneEntity.h"
+#include <vector>
+
+using std::vector;
+
+namespace Polycode {
+
+	class _PolyExport PhysicsScene : public CollisionScene {
+	public:
+		PhysicsScene();
+		virtual ~PhysicsScene();	
+		
+		void Update();		
+		
+		PhysicsSceneEntity *addPhysicsChild(SceneEntity *newEntity, int type=0, float mass = 0.0f, float friction=1, float restitution=0);		
+		PhysicsCharacter *addCharacterChild(SceneEntity *newEntity, float mass, float friction, float stepSize);
+		
+	protected:
+		
+		void initPhysicsScene();		
+		
+		btDiscreteDynamicsWorld* physicsWorld;
+		vector<PhysicsSceneEntity*> physicsChildren;		
+		
+	};
+	
+}
+

+ 62 - 0
Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h

@@ -0,0 +1,62 @@
+
+#pragma once
+#include "PolyLogger.h"
+#include "PolyGlobals.h"
+#include "PolySceneEntity.h"
+#include "PolyCollisionSceneEntity.h"
+#include "btBulletCollisionCommon.h"
+#include "btBulletDynamicsCommon.h"
+#include "PolyCoreServices.h"
+#include "PolySceneMesh.h"
+#include "BulletDynamics/Character/btKinematicCharacterController.h"
+#include "BulletCollision/CollisionDispatch/btGhostObject.h"
+
+
+//class btKinematicCharacterController;
+
+namespace Polycode {
+	
+	class _PolyExport PhysicsSceneEntity : public CollisionSceneEntity {
+	public:
+		PhysicsSceneEntity(SceneEntity *entity, int type, float mass, float friction, float restitution);
+		virtual ~PhysicsSceneEntity();
+		
+		SceneEntity *getSceneEntity();
+		virtual void Update();
+		void setFriction(float friction);
+		
+		int getType() { return type; }	
+		
+		static const int SHAPE_BOX = 0;
+		static const int SHAPE_TERRAIN = 1;
+		static const int SHAPE_SPHERE = 2;	
+		static const int SHAPE_MESH = 3;			
+		static const int CHARACTER_CONTROLLER = 4;
+		static const int SHAPE_CAPSULE = 5;		
+		
+		bool enabled;
+		
+		btRigidBody* rigidBody;
+		
+	protected:
+	
+		float mass;
+	};
+	
+	
+	class _PolyExport PhysicsCharacter : public PhysicsSceneEntity {
+		public:
+			PhysicsCharacter(SceneEntity *entity, float mass, float friction, float stepSize);
+			virtual ~PhysicsCharacter();
+	
+			void setWalkDirection(Vector3 direction);
+			void jump();
+			virtual void Update();
+		
+			btKinematicCharacterController *character;
+			btPairCachingGhostObject *ghostObject;
+				
+		
+		protected:
+	};
+}

+ 3 - 1
Modules/Contents/3DPhysics/Include/Polycode3DPhysics.h

@@ -1,4 +1,6 @@
 
 #pragma once
+
 #include "PolyCollisionScene.h"
-#include "PolyCollisionSceneEntity.h"
+#include "PolyCollisionSceneEntity.h"
+#include "PolyPhysicsScene.h"

+ 9 - 3
Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp

@@ -230,7 +230,7 @@ CollisionResult CollisionScene::testCollisionOnCollisionChild_RayTest(CollisionS
 	CollisionResult result;
 	result.collided = false;
 	result.setOldPosition = false;
-	btConvexShape *shape = cEnt1->getShape();
+	btConvexShape *shape = cEnt1->getConvexShape();
 	if(!shape)
 		return result;
 	
@@ -288,7 +288,7 @@ CollisionResult CollisionScene::testCollisionOnCollisionChild_RayTest(CollisionS
 }
 
 CollisionResult CollisionScene::testCollisionOnCollisionChild(CollisionSceneEntity *cEnt1, CollisionSceneEntity *cEnt2) {
-	if(cEnt2->getType() == CollisionSceneEntity::SHAPE_TERRAIN || cEnt2->getType() == CollisionSceneEntity::SHAPE_MESH) {
+	if(cEnt2->getType() == CollisionSceneEntity::SHAPE_MESH) {
 		return testCollisionOnCollisionChild_RayTest(cEnt1, cEnt2);		
 	} else {
 		return testCollisionOnCollisionChild_Convex(cEnt1, cEnt2);
@@ -322,7 +322,13 @@ void CollisionScene::loadCollisionChild(SceneEntity *entity, bool autoCollide, i
 
 CollisionSceneEntity *CollisionScene::trackCollision(SceneEntity *newEntity, bool autoCollide, int type) {
 	CollisionSceneEntity *newCollisionEntity = new CollisionSceneEntity(newEntity,autoCollide, type);
-	world->addCollisionObject(newCollisionEntity->collisionObject);
+
+	if(type == CollisionSceneEntity::CHARACTER_CONTROLLER) {
+		world->addCollisionObject(newCollisionEntity->collisionObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);		
+	} else {
+		world->addCollisionObject(newCollisionEntity->collisionObject);		
+	}
+	
 	collisionChildren.push_back(newCollisionEntity);
 //	newCollisionEntity->Update();
 	return newCollisionEntity;

+ 35 - 45
Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp

@@ -21,33 +21,48 @@ CollisionSceneEntity::CollisionSceneEntity(SceneEntity *entity, bool autoCollide
 	enabled = true;
 	
 	gravityStrength = 5.0f;
+	lastPosition = *entity->getPosition();	
+	
 	
 	btMatrix3x3 basisA;
 	basisA.setIdentity();
+	
 	collisionObject = new btCollisionObject();
 	collisionObject->getWorldTransform().setBasis(basisA);
 	
-	lastPosition = *entity->getPosition();
-	
-	shape = NULL;
+
+	shape = createCollisionShape(entity, type);;
+	if(shape) {
+		collisionObject->setCollisionShape(shape);
+	}	
 	
-	btBoxShape* box;
-	btSphereShape* sphere;	
-	SceneMesh *sceneMesh;
+	if(type == SHAPE_MESH) {		
+		concaveShape = dynamic_cast<btConcaveShape*>(shape);
+	} else {
+		convexShape	= dynamic_cast<btConvexShape*>(shape);		
+	}
+		
+	gVelocity.set(0,0,0);
+}
 
+btCollisionShape *CollisionSceneEntity::createCollisionShape(SceneEntity *entity, int type) {
+	
+	btCollisionShape *collisionShape = NULL;	
+	
 	switch(type) {
-		case SHAPE_BOX:
-			box = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));
-			collisionObject->setCollisionShape(box);
-			shape = box;
+		case SHAPE_CAPSULE:
+		case CHARACTER_CONTROLLER:
+			collisionShape = new btCapsuleShape(entity->bBox.x/2.0f, entity->bBox.y/2.0f);			
 		break;
+		case SHAPE_BOX:
+			collisionShape = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));			
+			break;
 		case SHAPE_SPHERE:
-			sphere = new btSphereShape(entity->bBox.x/2.0f);
-			collisionObject->setCollisionShape(sphere);
-			shape = sphere;			
-		break;
+			collisionShape = new btSphereShape(entity->bBox.x/2.0f);
+			break;
 		case SHAPE_MESH:
-			sceneMesh = dynamic_cast<SceneMesh*>(entity);
+		{
+			SceneMesh* sceneMesh = dynamic_cast<SceneMesh*>(entity);
 			if(sceneMesh != NULL) {
 				btTriangleMesh *btMesh = new btTriangleMesh();
 				for(int i=0; i < sceneMesh->getMesh()->getPolygonCount(); i++) {
@@ -57,40 +72,15 @@ CollisionSceneEntity::CollisionSceneEntity(SceneEntity *entity, bool autoCollide
 					btVector3 v2= btVector3(btScalar(poly->getVertex(2)->x),btScalar(poly->getVertex(2)->y),btScalar(poly->getVertex(2)->z));					
 					btMesh->addTriangle(v2,v1,v0);
 				}
-				btBvhTriangleMeshShape *concaveShape = new btBvhTriangleMeshShape(btMesh, true);
-				collisionObject->setCollisionShape(concaveShape);
+				collisionShape = new btBvhTriangleMeshShape(btMesh, true);
 			} else {
 				Logger::log("Tried to make a mesh collision object from a non-mesh\n");
-				box = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));			
-				collisionObject->setCollisionShape(box);	
-				shape = box;				
-			}			
-		break;
-		case SHAPE_TERRAIN:			
-			/*
-			Terrain *terrain = dynamic_cast<Terrain*>(entity);
-			if(terrain != NULL) {
-//				btHeightfieldTerrainShape *hf = new btHeightfieldTerrainShape(ter
-				btTriangleMesh *btMesh = new btTriangleMesh();
-				for(int i=0; i < terrain->getMesh()->getPolygonCount(); i++) {
-					Polygon *poly = terrain->getMesh()->getPolygon(i);
-					btVector3 v0 = btVector3(btScalar(poly->getVertex(0)->x),btScalar(poly->getVertex(0)->y),btScalar(poly->getVertex(0)->z));
-					btVector3 v1= btVector3(btScalar(poly->getVertex(1)->x),btScalar(poly->getVertex(1)->y),btScalar(poly->getVertex(1)->z));
-					btVector3 v2= btVector3(btScalar(poly->getVertex(2)->x),btScalar(poly->getVertex(2)->y),btScalar(poly->getVertex(2)->z));					
-					btMesh->addTriangle(v2,v1,v0);
-				}
-				btBvhTriangleMeshShape *concaveShape = new btBvhTriangleMeshShape(btMesh, true);
-				collisionObject->setCollisionShape(concaveShape);
-			} else {
-				Logger::log("Tried to make a terrain collision object from a non-terrain\n");
-				box = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));			
-				collisionObject->setCollisionShape(box);	
-				shape = box;				
+				collisionShape = new btBoxShape(btVector3(entity->bBox.x/2.0f, entity->bBox.y/2.0f,entity->bBox.z/2.0f));			
 			}
-			 */
+		}
 		break;
-	}
-	gVelocity.set(0,0,0);
+	}	
+	return collisionShape; 
 }
 
 void CollisionSceneEntity::Update() {

+ 88 - 0
Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp

@@ -0,0 +1,88 @@
+/*
+ *  PolyPhysicsScene.cpp
+ *  Modules
+ *
+ *  Created by Ivan Safrin on 12/22/10.
+ *  Copyright 2010 Local Projects. All rights reserved.
+ *
+ */
+
+#include "PolyPhysicsScene.h"
+
+PhysicsScene::PhysicsScene() : CollisionScene() {
+	initPhysicsScene();	
+}
+
+PhysicsScene::~PhysicsScene() {
+	
+}
+
+void PhysicsScene::initPhysicsScene() {
+		
+	
+ btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
+//	btDbvtBroadphase* broadphase = new btDbvtBroadphase();
+	
+	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);	
+	
+	btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
+	
+	btVector3 worldMin(-1000,-1000,-1000);
+	btVector3 worldMax(1000,1000,1000);
+	btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);	
+	
+	physicsWorld = new btDiscreteDynamicsWorld(dispatcher,sweepBP,solver,collisionConfiguration);
+	
+	physicsWorld->getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER;
+	physicsWorld->setGravity(btVector3(0,-10,0));
+	
+	
+	sweepBP->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
+	
+	world = physicsWorld;
+}
+
+void PhysicsScene::Update() {
+	
+	for(int i=0; i < physicsChildren.size(); i++) {
+//		if(physicsChildren[i]->enabled)
+			physicsChildren[i]->Update();
+	}
+	
+	
+	float elapsed = CoreServices::getInstance()->getCore()->getElapsed();
+	physicsWorld->stepSimulation(elapsed);	
+
+	
+	CollisionScene::Update();
+	
+}
+
+PhysicsCharacter *PhysicsScene::addCharacterChild(SceneEntity *newEntity,float mass, float friction, float stepSize) {
+	addEntity(newEntity);	
+	PhysicsCharacter *newPhysicsEntity = new PhysicsCharacter(newEntity, mass, friction, stepSize);
+	
+	physicsWorld->addCollisionObject(newPhysicsEntity->ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
+	physicsWorld->addAction(newPhysicsEntity->character);
+	
+	
+	physicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(newPhysicsEntity->ghostObject->getBroadphaseHandle(),physicsWorld->getDispatcher());
+	
+	newPhysicsEntity->character->reset ();
+	
+	newPhysicsEntity->character->setUseGhostSweepTest(false);
+	
+	physicsChildren.push_back(newPhysicsEntity);
+	return newPhysicsEntity;
+	
+}
+
+PhysicsSceneEntity *PhysicsScene::addPhysicsChild(SceneEntity *newEntity, int type, float mass, float friction, float restitution) {
+	addEntity(newEntity);	
+	PhysicsSceneEntity *newPhysicsEntity = new PhysicsSceneEntity(newEntity, type, mass, friction,restitution);
+	physicsWorld->addRigidBody(newPhysicsEntity->rigidBody);	
+	newPhysicsEntity->rigidBody->setActivationState(ISLAND_SLEEPING);	
+	physicsChildren.push_back(newPhysicsEntity);
+	return newPhysicsEntity;
+	
+}

+ 99 - 0
Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp

@@ -0,0 +1,99 @@
+
+/*
+ *  PolyPhysicsSceneEntity.cpp
+ *  Poly
+ *
+ *  Created by Ivan Safrin on 6/17/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "PolyPhysicsSceneEntity.h"
+
+using namespace Polycode;
+
+PhysicsCharacter::PhysicsCharacter(SceneEntity *entity, float mass, float friction, float stepSize) : PhysicsSceneEntity(entity, PhysicsSceneEntity::CHARACTER_CONTROLLER, mass, friction, 1) {	
+	ghostObject = new btPairCachingGhostObject();
+	
+	Vector3 *pos = entity->getPosition();	
+	btTransform transform;
+	transform.setIdentity();		
+	transform.setOrigin(btVector3(pos->x,pos->y,pos->z));	
+	
+	ghostObject->setWorldTransform(transform);	
+	ghostObject->setCollisionShape (shape);
+	
+	ghostObject->setFriction(friction);	
+	
+	ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);	
+	character = new btKinematicCharacterController (ghostObject,convexShape,btScalar(stepSize));			
+	
+}
+
+
+void PhysicsCharacter::setWalkDirection(Vector3 direction) {
+	character->setWalkDirection(btVector3(direction.x, direction.y, direction.z));	
+}
+
+void PhysicsCharacter::jump() {
+	character->jump();	
+}
+
+void PhysicsCharacter::Update() {
+	btVector3 pos = ghostObject->getWorldTransform().getOrigin();
+	sceneEntity->setPosition(pos.x(), pos.y(), pos.z());
+//	sceneEntity->rebuildTransformMatrix();
+	sceneEntity->dirtyMatrix(true);
+}
+
+PhysicsCharacter::~PhysicsCharacter() {
+	
+}
+
+PhysicsSceneEntity::PhysicsSceneEntity(SceneEntity *entity, int type, float mass, float friction, float restitution) : CollisionSceneEntity(entity, false, type) {
+
+	this->mass = mass;
+	btVector3 localInertia(0,0,0);
+	Vector3 *pos = entity->getPosition();	
+	btTransform transform;
+	transform.setIdentity();		
+	transform.setOrigin(btVector3(pos->x,pos->y,pos->z));
+	
+	if(mass != 0.0f) {
+		shape->calculateLocalInertia(mass,localInertia);
+	}	
+	
+	if(type == CHARACTER_CONTROLLER) {
+		
+	} else {	
+		btDefaultMotionState* myMotionState = new btDefaultMotionState(transform);
+		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
+		rigidBody = new btRigidBody(rbInfo);
+		rigidBody->setActivationState(ISLAND_SLEEPING);		
+		rigidBody->setFriction(friction);
+		rigidBody->setRestitution(restitution);
+	}
+}
+
+void PhysicsSceneEntity::Update() {		
+	Matrix4 m;
+		
+	btScalar* mat = (btScalar*) malloc(sizeof(btScalar) * 16);				
+		
+	rigidBody->getWorldTransform().getOpenGLMatrix(mat);
+	for(int i=0; i < 16; i++) {
+		m.ml[i] = mat[i];
+	}
+	
+	free(mat);
+		
+	sceneEntity->setTransformByMatrixPure(m);			
+}
+
+SceneEntity *PhysicsSceneEntity::getSceneEntity() {
+	return sceneEntity;
+}
+
+PhysicsSceneEntity::~PhysicsSceneEntity() {
+	
+}