Просмотр исходного кода

Various fixes plus Kinect module

Ivan Safrin 15 лет назад
Родитель
Сommit
b6e0a118d0
30 измененных файлов с 1024 добавлено и 48 удалено
  1. 1 0
      .gitignore
  2. 8 0
      Core/Build/Mac OS X/PolyCore.xcodeproj/project.pbxproj
  3. 2 0
      Core/Contents/Include/PolyColor.h
  4. 2 2
      Core/Contents/Include/PolyData.h
  5. 5 0
      Core/Contents/Include/PolyMesh.h
  6. 101 0
      Core/Contents/Include/PolyObject.h
  7. 2 0
      Core/Contents/Include/PolySceneMesh.h
  8. 1 0
      Core/Contents/Include/Polycode.h
  9. 14 0
      Core/Contents/Source/PolyColor.cpp
  10. 7 7
      Core/Contents/Source/PolyGLRenderer.cpp
  11. 4 4
      Core/Contents/Source/PolyMesh.cpp
  12. 150 0
      Core/Contents/Source/PolyObject.cpp
  13. 5 0
      Core/Contents/Source/PolyPolygon.cpp
  14. 12 2
      Core/Contents/Source/PolySceneMesh.cpp
  15. 4 0
      IDE/Build/Mac OS X/PolycodeAppDelegate.h
  16. 1 0
      IDE/Build/Mac OS X/PolycodeAppDelegate.m
  17. 3 1
      IDE/Contents/Include/PolycodeIDEApp.h
  18. 3 1
      IDE/Contents/Include/PolycodeProject.h
  19. 3 0
      IDE/Contents/Include/PolycodeProjectManager.h
  20. 9 4
      IDE/Contents/Resources/FileTemplates/2D/Screen.screen
  21. 27 4
      IDE/Contents/Source/PolycodeIDEApp.cpp
  22. 2 1
      IDE/Contents/Source/PolycodeProject.cpp
  23. 1 1
      IDE/Contents/Source/PolycodeProjectManager.cpp
  24. 115 0
      Modules/Build/Mac OS X/Modules.xcodeproj/project.pbxproj
  25. 17 8
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h
  26. 3 0
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h
  27. 49 5
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp
  28. 17 8
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp
  29. 92 0
      Modules/Contents/Kinect/Include/PolycodeKinect.h
  30. 364 0
      Modules/Contents/Kinect/Source/PolycodeKinect.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
+Modules/Dependencies
 IDE/Dependencies
 
 # OS generated files #

+ 8 - 0
Core/Build/Mac OS X/PolyCore.xcodeproj/project.pbxproj

@@ -184,6 +184,8 @@
 		6DFBF46912A3184E00C43A7D /* tinyxmlerror.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6DFBF3BA12A3184E00C43A7D /* tinyxmlerror.cpp */; };
 		6DFBF46A12A3184E00C43A7D /* tinyxmlparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6DFBF3BB12A3184E00C43A7D /* tinyxmlparser.cpp */; };
 		6DFBF46B12A3184E00C43A7D /* xmltest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6DFBF3BC12A3184E00C43A7D /* xmltest.cpp */; };
+		6DFE5FC512D450C30005B100 /* PolyObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFE5FC412D450C30005B100 /* PolyObject.h */; };
+		6DFE5FC812D450CB0005B100 /* PolyObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6DFE5FC712D450CB0005B100 /* PolyObject.cpp */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -368,6 +370,8 @@
 		6DFBF3BA12A3184E00C43A7D /* tinyxmlerror.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tinyxmlerror.cpp; sourceTree = "<group>"; };
 		6DFBF3BB12A3184E00C43A7D /* tinyxmlparser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tinyxmlparser.cpp; sourceTree = "<group>"; };
 		6DFBF3BC12A3184E00C43A7D /* xmltest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xmltest.cpp; sourceTree = "<group>"; };
+		6DFE5FC412D450C30005B100 /* PolyObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyObject.h; sourceTree = "<group>"; };
+		6DFE5FC712D450CB0005B100 /* PolyObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolyObject.cpp; sourceTree = "<group>"; };
 		D2AAC046055464E500DB518D /* libPolyCore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPolyCore.a; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
 
@@ -421,6 +425,7 @@
 		6DFBF30B12A3184E00C43A7D /* Include */ = {
 			isa = PBXGroup;
 			children = (
+				6DFE5FC412D450C30005B100 /* PolyObject.h */,
 				6D865AC112B07363008A486E /* PolyData.h */,
 				6D8656A812AF5FCD008A486E /* PolyString.h */,
 				6DFBF30D12A3184E00C43A7D /* OSBasics.h */,
@@ -520,6 +525,7 @@
 		6DFBF36612A3184E00C43A7D /* Source */ = {
 			isa = PBXGroup;
 			children = (
+				6DFE5FC712D450CB0005B100 /* PolyObject.cpp */,
 				6D865AC312B0736C008A486E /* PolyData.cpp */,
 				6D8656AA12AF5FD5008A486E /* PolyString.cpp */,
 				6DFBF36712A3184E00C43A7D /* OSBasics.cpp */,
@@ -719,6 +725,7 @@
 				6DFB016F12A73BC200C43A7D /* PolyModule.h in Headers */,
 				6D8656A912AF5FCD008A486E /* PolyString.h in Headers */,
 				6D865AC212B07363008A486E /* PolyData.h in Headers */,
+				6DFE5FC512D450C30005B100 /* PolyObject.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -856,6 +863,7 @@
 				6DFB017112A73BCF00C43A7D /* PolyModule.cpp in Sources */,
 				6D8656AB12AF5FD5008A486E /* PolyString.cpp in Sources */,
 				6D865AC412B0736C008A486E /* PolyData.cpp in Sources */,
+				6DFE5FC812D450CB0005B100 /* PolyObject.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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

@@ -36,6 +36,8 @@ namespace Polycode {
 			}			
 			
 			void setColorHex(unsigned int hex);
+			void setColorHexRGB(unsigned int hex);
+		
 			void setColorHSV(float h, float s, float v);
 			void setColorRGBA(int r, int g, int b, int a);
 			void setColorRGB(int r, int g, int b);

+ 2 - 2
Core/Contents/Include/PolyData.h

@@ -4,9 +4,9 @@
 #include "PolyString.h"
 #include "OSBasics.h"
 
-namespace _PolyExport Polycode {
+namespace Polycode {
 
-	class Data {
+	class _PolyExport Data {
 		public:
 			Data();
 			~Data();

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

@@ -25,6 +25,9 @@ namespace Polycode {
 	
 	class _PolyExport VertexBuffer {
 		public:	
+			VertexBuffer(){}
+			virtual ~VertexBuffer(){}
+		
 			int getVertexCount() { return vertexCount;}
 		
 			int verticesPerFace;
@@ -123,6 +126,8 @@ namespace Polycode {
 			bool arrayDirtyMap[16];
 			RenderDataArray *renderDataArrays[16];
 		
+			bool useVertexColors;
+		
 		private:
 		
 				

+ 101 - 0
Core/Contents/Include/PolyObject.h

@@ -0,0 +1,101 @@
+
+
+#include "PolyGlobals.h"
+#include "PolyString.h"
+#include "tinyxml.h"
+
+namespace Polycode {
+
+	class _PolyExport ObjectEntry {
+	public:
+		
+		ObjectEntry() { type = ObjectEntry::CONTAINER_ENTRY; }
+		
+		int type;
+		String name;
+		
+		float floatVal;
+		int intVal;
+		String stringVal;
+		bool boolVal;		
+		int length;
+		
+		ObjectEntry *addChild(String name) {
+			ObjectEntry *entry = new ObjectEntry();
+			entry->type = ObjectEntry::CONTAINER_ENTRY;			
+			entry->name = name;
+			children.push_back(entry);
+			length = children.size();
+			return entry;
+		}
+		
+		
+		ObjectEntry *addChild(String name, float val) {
+			ObjectEntry *entry = new ObjectEntry();
+			entry->type = ObjectEntry::FLOAT_ENTRY;			
+			entry->floatVal = val;
+			entry->name = name;
+			children.push_back(entry);
+			length = children.size();			
+			return entry;			
+		}
+
+		ObjectEntry *addChild(String name, int val) {
+			ObjectEntry *entry = new ObjectEntry();
+			entry->type = ObjectEntry::INT_ENTRY;
+			entry->intVal = val;
+			entry->name = name;
+			children.push_back(entry);	
+			length = children.size();			
+			return entry;			
+		}
+
+		ObjectEntry *addChild(String name, String val) {
+			ObjectEntry *entry = new ObjectEntry();
+			entry->type = ObjectEntry::STRING_ENTRY;
+			entry->stringVal = val;
+			entry->name = name;
+			children.push_back(entry);
+			length = children.size();			
+			return entry;			
+		}		
+		
+		ObjectEntry *addChild(String name, bool val) {
+			ObjectEntry *entry = new ObjectEntry();
+			entry->type = ObjectEntry::BOOL_ENTRY;			
+			entry->boolVal = val;
+			entry->name = name;
+			children.push_back(entry);
+			length = children.size();			
+			return entry;			
+		}
+		
+		
+		static const int FLOAT_ENTRY = 0;		
+		static const int INT_ENTRY = 1;
+		static const int BOOL_ENTRY = 2;
+		static const int ARRAY_ENTRY = 3;
+		static const int STRING_ENTRY = 4;	
+		static const int CONTAINER_ENTRY = 5;	
+		
+		inline ObjectEntry *operator [] ( int index) { return children[index];}
+		inline ObjectEntry *operator [] ( String key) { for(int i=0; i < children.size(); i++) { if(children[i]->name == key) { return children[i]; } } return NULL; }		
+		
+		vector<ObjectEntry*> children;		
+	};
+	
+	class _PolyExport Object {
+	public:
+		Object();
+		~Object();
+		
+		void loadFromXML(String fileName);
+		void saveToXML(String fileName);
+		void createFromXMLElement(TiXmlElement *element, ObjectEntry *entry);
+		TiXmlElement *createElementFromObjectEntry(ObjectEntry *entry);
+		
+		ObjectEntry root;
+		
+	};
+	
+}

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

@@ -45,6 +45,7 @@ namespace Polycode {
 			void setTexture(Texture *texture);
 			void setMaterial(Material *material);
 			void setMaterial(String materialName);
+			void setMesh(Mesh *mesh);
 		
 			void setSkeleton(Skeleton *skeleton);
 			Skeleton *getSkeleton();
@@ -56,6 +57,7 @@ namespace Polycode {
 			unsigned int lightmapIndex;
 			
 			bool showVertexNormals;
+			
 		
 		protected:
 		

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

@@ -11,6 +11,7 @@
 
 #include "PolyString.h"
 #include "PolyData.h"
+#include "PolyObject.h"
 #include "PolyLogger.h"
 #include "PolyConfig.h"
 #include "PolyEntity.h"

+ 14 - 0
Core/Contents/Source/PolyColor.cpp

@@ -31,6 +31,20 @@ Color::Color(unsigned int hex) {
 	setColorHex(hex);
 }
 
+void Color::setColorHexRGB(unsigned int hex) {
+
+	int tr = (hex >> 24) & 0xFF;
+	int tb = (hex >> 16) & 0xFF;
+	int tg = (hex >> 8) & 0xFF;
+//	int ta = (hex ) & 0xFF;
+	
+	r = ((float)tr)/255.0f;
+	g = ((float)tg)/255.0f;
+	b = ((float)tb)/255.0f;
+//	a = ((float)ta)/255.0f;	
+	
+}
+
 void Color::setColorHex(unsigned int hex) {
 	int tr = (hex >> 24) & 0xFF;
 	int tg = (hex >> 16) & 0xFF;

+ 7 - 7
Core/Contents/Source/PolyGLRenderer.cpp

@@ -281,10 +281,10 @@ void OpenGLRenderer::drawVertexBuffer(VertexBuffer *buffer) {
 	glEnableClientState(GL_VERTEX_ARRAY);		
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	glEnableClientState(GL_NORMAL_ARRAY);	
-//	glEnableClientState(GL_COLOR_ARRAY);		
+	glEnableClientState(GL_COLOR_ARRAY);		
 		
-//	glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getColorBufferID());
-//	glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );	
+	glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getColorBufferID());
+	glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );	
 	glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getVertexBufferID());
 	glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );	
 	glBindBufferARB( GL_ARRAY_BUFFER_ARB, glVertexBuffer->getNormalBufferID());
@@ -300,7 +300,7 @@ void OpenGLRenderer::drawVertexBuffer(VertexBuffer *buffer) {
 	glDisableClientState( GL_VERTEX_ARRAY);	
 	glDisableClientState( GL_TEXTURE_COORD_ARRAY );		
 	glDisableClientState( GL_NORMAL_ARRAY );
-//	glDisableClientState( GL_COLOR_ARRAY );	
+	glDisableClientState( GL_COLOR_ARRAY );	
 }
 
 void OpenGLRenderer::enableFog(bool enable) {
@@ -654,8 +654,8 @@ void OpenGLRenderer::pushRenderDataArray(RenderDataArray *array) {
 			verticesToDraw = array->count;
 		break;
 		case RenderDataArray::COLOR_DATA_ARRAY:			
-	//		glColorPointer(array->size, GL_FLOAT, 0, array->arrayPtr);			
-	//		glEnableClientState(GL_COLOR_ARRAY);
+			glColorPointer(array->size, GL_FLOAT, 0, array->arrayPtr);			
+			glEnableClientState(GL_COLOR_ARRAY);
 		break;
 		case RenderDataArray::TEXCOORD_DATA_ARRAY:
 			glEnableClientState(GL_TEXTURE_COORD_ARRAY);						
@@ -842,7 +842,7 @@ void OpenGLRenderer::drawArrays(int drawType) {
 	glDisableClientState( GL_VERTEX_ARRAY);	
 	glDisableClientState( GL_TEXTURE_COORD_ARRAY );		
 	glDisableClientState( GL_NORMAL_ARRAY );
-//	glDisableClientState( GL_COLOR_ARRAY );		
+	glDisableClientState( GL_COLOR_ARRAY );		
 }
 
 /*

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

@@ -24,6 +24,7 @@ namespace Polycode {
 		meshHasVertexBuffer = false;
 		loadMesh(fileName);
 		vertexBuffer = NULL;			
+		useVertexColors = false;
 			}
 	
 	Mesh::Mesh(int meshType) {
@@ -35,21 +36,20 @@ namespace Polycode {
 		meshHasVertexBuffer = false;		
 		numUVs = 1;
 		vertexBuffer = NULL;
-				
+		useVertexColors = false;				
 	}
 	
 	
 	Mesh::~Mesh() {
-		Logger::log("deleting mesh...\n");
 		for(int i=0; i < vertices.size(); i++) {	
 			delete vertices[i];
 		}
 		vertices.clear();
 		for(int i=0; i < polygons.size(); i++) {	
-//			delete polygons[i];
+			delete polygons[i];
 		}
 		polygons.clear();
-
+		delete vertexBuffer;
 	}
 	
 	VertexBuffer *Mesh::getVertexBuffer() {

+ 150 - 0
Core/Contents/Source/PolyObject.cpp

@@ -0,0 +1,150 @@
+
+#include "PolyObject.h"
+
+
+using namespace Polycode;
+
+Object::Object() {
+	
+}
+
+Object::~Object() {
+	
+}
+
+void Object::saveToXML(String fileName) {
+	TiXmlDocument doc;  	
+	TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );  
+	doc.LinkEndChild( decl ); 
+ 
+	TiXmlElement * rootElement = createElementFromObjectEntry(&root);
+	doc.LinkEndChild(rootElement);  	
+	
+	doc.SaveFile(fileName.c_str()); 
+}
+
+
+TiXmlElement *Object::createElementFromObjectEntry(ObjectEntry *entry) {
+	TiXmlElement *newElement = new TiXmlElement(entry->name.c_str());  
+	
+	for(int i=0; i < entry->children.size(); i++) {
+		ObjectEntry *childEntry = entry->children[i];
+		
+		printf("Parsing %s (type: %d)\n", childEntry->name.c_str(), childEntry->type);
+		
+		switch(childEntry->type) {
+			case ObjectEntry::BOOL_ENTRY:
+				if(childEntry->boolVal)
+					newElement->SetAttribute(childEntry->name.c_str(), "true");
+				else
+					newElement->SetAttribute(childEntry->name.c_str(), "false");
+			break;
+			case ObjectEntry::FLOAT_ENTRY:
+				newElement->SetAttribute(childEntry->name.c_str(), String::floatToString(childEntry->floatVal).c_str());								
+			break;
+			case ObjectEntry::INT_ENTRY:				
+				newElement->SetAttribute(childEntry->name.c_str(), childEntry->intVal);												
+			break;
+			case ObjectEntry::STRING_ENTRY: 
+			{
+				TiXmlElement *childElement = new TiXmlElement(childEntry->name.c_str());  
+				childElement->LinkEndChild( new TiXmlText(childEntry->stringVal.c_str()));
+				newElement->LinkEndChild(childElement);								
+			}
+				break;				
+			default:
+			{
+				TiXmlElement *childElement = createElementFromObjectEntry(entry->children[i]);
+				newElement->LinkEndChild(childElement);				
+			}
+			break;
+		}
+	}
+	
+	return newElement;
+}
+
+void Object::loadFromXML(String fileName) {
+
+	TiXmlDocument doc(fileName.c_str());
+	doc.LoadFile();
+
+	if(doc.Error()) {
+		Logger::log("Error loading xml file: %s\n", doc.ErrorDesc());
+		return;
+	}
+	
+	TiXmlElement *rootElement = doc.RootElement();
+	createFromXMLElement(rootElement, &root);
+}
+
+
+void Object::createFromXMLElement(TiXmlElement *element, ObjectEntry *entry) {
+	entry->name = element->Value();
+	entry->type = ObjectEntry::CONTAINER_ENTRY;
+	
+	// run through the attributes
+	TiXmlAttribute* pAttrib=element->FirstAttribute();
+	int i=0;
+	int ival;
+	double dval;
+	while (pAttrib)
+	{
+		ObjectEntry *newEntry = new ObjectEntry();
+		newEntry->type = ObjectEntry::STRING_ENTRY;		
+		newEntry->stringVal = pAttrib->Value();
+		newEntry->name = pAttrib->Name();
+		
+		if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS) {
+			
+			if(newEntry->stringVal.find(".") != -1 && pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) {
+				newEntry->floatVal = dval;
+				newEntry->type = ObjectEntry::FLOAT_ENTRY;				
+			} else {
+				newEntry->intVal = ival;
+				newEntry->type = ObjectEntry::INT_ENTRY;
+			}
+		}
+
+		
+		if(newEntry->stringVal == "true") {
+			newEntry->boolVal = true;
+			newEntry->type = ObjectEntry::BOOL_ENTRY;
+		}
+		if(newEntry->stringVal == "false") {
+			newEntry->boolVal = false;
+			newEntry->type = ObjectEntry::BOOL_ENTRY;
+		}
+		
+		entry->children.push_back(newEntry);
+	
+		i++;
+		pAttrib=pAttrib->Next();
+	}	
+
+	// check if has a value
+	if(element->GetText()) {
+		entry->stringVal = element->GetText();
+		entry->type = ObjectEntry::STRING_ENTRY;
+		return;
+	}
+		
+	// then through the children	
+	TiXmlNode* pChild;	
+
+	String lastName = "";
+	int count = 0;
+	for (pChild = element->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
+		ObjectEntry *newEntry = new ObjectEntry();		
+		createFromXMLElement(pChild->ToElement(), newEntry);
+		entry->children.push_back(newEntry);		
+		if(entry->name == lastName) {
+			entry->type = ObjectEntry::ARRAY_ENTRY;
+		}
+		lastName = entry->name;			
+		count++;
+	}
+	
+	entry->length = count;
+
+}

+ 5 - 0
Core/Contents/Source/PolyPolygon.cpp

@@ -27,6 +27,11 @@ Polygon::~Polygon() {
 		delete texCoords2[i];
 	}
 	texCoords2.clear();
+	
+	for(int i=0; i < vertices.size(); i++) {	
+		delete vertices[i];
+	}
+	vertices.clear();
 }
 	
 void Polygon::flipUVY() {

+ 12 - 2
Core/Contents/Source/PolySceneMesh.cpp

@@ -41,6 +41,14 @@ SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL) {
 	useVertexBuffer = false;	
 }
 
+void SceneMesh::setMesh(Mesh *mesh) {
+	this->mesh = mesh;
+	bBoxRadius = mesh->getRadius();
+	bBox = mesh->calculateBBox();
+	showVertexNormals = false;	
+	useVertexBuffer = false;	
+}
+
 
 SceneMesh::~SceneMesh() {
 	Logger::log("Destroying Scene Mesh...\n");
@@ -160,8 +168,10 @@ void SceneMesh::renderMeshLocally() {
 		//CoreServices::getInstance()->getRenderer()->draw3DPolygon(mesh->getPolygon(i));
 	}
 */
-	
-//	renderer->pushDataArrayForMesh(mesh, RenderDataArray::COLOR_DATA_ARRAY);
+
+//	if(mesh->useVertexColors) {
+//		renderer->pushDataArrayForMesh(mesh, RenderDataArray::COLOR_DATA_ARRAY);
+//	}
 	 
 	renderer->pushDataArrayForMesh(mesh, RenderDataArray::VERTEX_DATA_ARRAY);
 	renderer->pushDataArrayForMesh(mesh, RenderDataArray::NORMAL_DATA_ARRAY);		

+ 4 - 0
IDE/Build/Mac OS X/PolycodeAppDelegate.h

@@ -11,6 +11,10 @@
 
 #include "PolycodeIDEApp.h"
 
+class PolycodeAppEventHandler : public EventHandler() {
+	<#declarations#>
+};
+
 @interface PolycodeAppDelegate : NSObject <NSApplicationDelegate> {
     NSWindow *window;	
 	PolycodeIDEApp *app;

+ 1 - 0
IDE/Build/Mac OS X/PolycodeAppDelegate.m

@@ -17,6 +17,7 @@
 	// Insert code here to initialize your application 
 	
 	app = new PolycodeIDEApp(substanceView);
+	app->addEventListener(eventHandler, PolycodeIDEApp::EVENT_SHOW_MENU);
 	
 	timer = [NSTimer timerWithTimeInterval:(1.0f/90.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
 	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

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

@@ -29,7 +29,7 @@ extern "C" {
 	
 using namespace Polycode;
 
-class PolycodeIDEApp : public EventHandler {
+class PolycodeIDEApp : public EventDispatcher {
 public:
 	PolycodeIDEApp(SubstanceView *view);
 	~PolycodeIDEApp();
@@ -46,6 +46,8 @@ public:
 	void openProject();
 	void saveFile();
 	
+	const static int EVENT_SHOW_MENU = 1;
+	
 protected:	
 	PolycodeFrame *frame;
 	CocoaCore *core;

+ 3 - 1
IDE/Contents/Include/PolycodeProject.h

@@ -8,13 +8,15 @@ using namespace Polycode;
 
 class PolycodeProject {
 	public:
-		PolycodeProject(String name, String path);
+		PolycodeProject(String name, String path, String file);
 		~PolycodeProject();	
 	
 		String getProjectName() { return projectName; }
+		String getProjectFile() { return projectFile; }	
 		String getRootFolder() { return projectFolder; }	
 	
 private:
+	String projectFile;
 	String projectFolder;	
 	String projectName;
 };

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

@@ -22,6 +22,9 @@ class PolycodeProjectManager {
 	PolycodeProject* getActiveProject() { return activeProject; }
 	void setActiveProject(PolycodeProject* project) { activeProject = project; }
 	
+	int getProjectCount() { return projects.size(); }
+	PolycodeProject *getProjectByIndex(int index) { return projects[index]; }
+	
 protected:
 	
 	PolycodeProject* activeProject;

+ 9 - 4
IDE/Contents/Resources/FileTemplates/2D/Screen.screen

@@ -1,7 +1,12 @@
 <?xml version="1.0" ?>
-<polycode_screen>
-	<config>		
-	</config>
+<screen>	
 	<entities>
+		<entity type="image" x="100" y="200" rot="35" tint="#ff00ff" alpha="1" scaleX="1" scaleY="1">
+			<image_path>tomato.png</image_path>
+		</entity>
+		<entity type="shape" x="300" y="200" rot="35" tint="#ff00ff" alpha="1" scaleX="1" scaleY="1">
+			<shape type="rect" width="100" height="50" texture="Whatever"></shape>
+			<physics type="static_rect" density="1" friction="1" restitution="0" sensor="false" noRotate="false"></physics>
+		</entity>
 	</entities>
-</polycode_screen>
+</screen>

+ 27 - 4
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -13,7 +13,7 @@
 
 using namespace Polycode;
 
-PolycodeIDEApp::PolycodeIDEApp(SubstanceView *view) : EventHandler() {
+PolycodeIDEApp::PolycodeIDEApp(SubstanceView *view) : EventDispatcher() {
 	core = new CocoaCore(view, 800,600,false,0,60);	
 	core->addEventListener(this, Core::EVENT_CORE_RESIZE);	
 	CoreServices::getInstance()->getRenderer()->setClearColor(0.4,0.4,0.4);
@@ -130,7 +130,7 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 			}
 		}
 	}	
-	
+
 	if(event->getDispatcher() == frame->newProjectWindow) {
 		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
 			projectManager->createNewProject(frame->newProjectWindow->getTemplateFolder(), frame->newProjectWindow->getProjectName(), frame->newProjectWindow->getProjectLocation());
@@ -140,11 +140,34 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 }
 
 void PolycodeIDEApp::saveConfigFile() {
-	
+	Object configFile;
+	configFile.root.name = "config";
+	configFile.root.addChild("open_projects");
+	for(int i=0; i < projectManager->getProjectCount(); i++) {
+		PolycodeProject *project = projectManager->getProjectByIndex(i);		
+		ObjectEntry *projectEntry = configFile.root["open_projects"]->addChild("project");
+		projectEntry->addChild("name", project->getProjectName());
+		projectEntry->addChild("path", project->getProjectFile());
+	}
+	core->createFolder("/Users/ivansafrin/Library/Application Support/Polycode");
+	configFile.saveToXML("/Users/ivansafrin/Library/Application Support/Polycode/config.xml");		
 }
 
 void PolycodeIDEApp::loadConfigFile() {
-	
+
+	Object configFile;
+	configFile.loadFromXML("/Users/ivansafrin/Library/Application Support/Polycode/config.xml");		
+	if(configFile.root["open_projects"]) {
+		ObjectEntry *projects = configFile.root["open_projects"];
+		if(projects) {
+		for(int i=0; i < projects->length; i++) {
+			ObjectEntry *entry = (*(*projects)[i])["path"];
+			if(entry) {
+				projectManager->openProject(entry->stringVal);	
+			}
+		}
+		}
+	}
 }
 
 

+ 2 - 1
IDE/Contents/Source/PolycodeProject.cpp

@@ -1,12 +1,13 @@
 
 #include "PolycodeProject.h"
 
-PolycodeProject::PolycodeProject(String name, String path) {
+PolycodeProject::PolycodeProject(String name, String path, String file) {
 	
 	printf("CREATING PROJECT %s %s\n", name.c_str(), path.c_str());
 	
 	projectName = name;
 	projectFolder = path;
+	projectFile = file;
 	
 }
 

+ 1 - 1
IDE/Contents/Source/PolycodeProjectManager.cpp

@@ -23,7 +23,7 @@ PolycodeProject* PolycodeProjectManager::openProject(String path) {
 	
 	String projectName = bits[bits.size()-2];
 	
-	PolycodeProject* newProject = new PolycodeProject(projectName, projectPath);
+	PolycodeProject* newProject = new PolycodeProject(projectName, projectPath, path);
 	projects.push_back(newProject);
 	
 	projectBrowser->addProject(newProject);

+ 115 - 0
Modules/Build/Mac OS X/Modules.xcodeproj/project.pbxproj

@@ -54,6 +54,8 @@
 		6DFBF88012A3F27B00C43A7D /* PolyUITreeEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFBF87212A3F27B00C43A7D /* PolyUITreeEvent.h */; };
 		6DFBF88112A3F27B00C43A7D /* PolyUIVScrollBar.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFBF87312A3F27B00C43A7D /* PolyUIVScrollBar.h */; };
 		6DFBF88212A3F27B00C43A7D /* PolyUIWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFBF87412A3F27B00C43A7D /* PolyUIWindow.h */; };
+		6DFD118412DEAA1F0080A2BE /* PolycodeKinect.h in Headers */ = {isa = PBXBuildFile; fileRef = 6DFD118112DEAA1F0080A2BE /* PolycodeKinect.h */; };
+		6DFD118512DEAA1F0080A2BE /* PolycodeKinect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6DFD118312DEAA1F0080A2BE /* PolycodeKinect.cpp */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -108,6 +110,9 @@
 		6DFBF87212A3F27B00C43A7D /* PolyUITreeEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyUITreeEvent.h; path = ../../Contents/UI/Include/PolyUITreeEvent.h; sourceTree = SOURCE_ROOT; };
 		6DFBF87312A3F27B00C43A7D /* PolyUIVScrollBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyUIVScrollBar.h; path = ../../Contents/UI/Include/PolyUIVScrollBar.h; sourceTree = SOURCE_ROOT; };
 		6DFBF87412A3F27B00C43A7D /* PolyUIWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyUIWindow.h; path = ../../Contents/UI/Include/PolyUIWindow.h; sourceTree = SOURCE_ROOT; };
+		6DFD116912DEA9C60080A2BE /* libPolycodeKinect.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPolycodeKinect.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		6DFD118112DEAA1F0080A2BE /* PolycodeKinect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolycodeKinect.h; sourceTree = "<group>"; };
+		6DFD118312DEAA1F0080A2BE /* PolycodeKinect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolycodeKinect.cpp; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -139,6 +144,13 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		6DFD116712DEA9C60080A2BE /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
@@ -155,6 +167,7 @@
 		08FB7795FE84155DC02AAC07 /* Source */ = {
 			isa = PBXGroup;
 			children = (
+				6DFD117F12DEAA1F0080A2BE /* Kinect */,
 				6D580E0312D29FB5006FB999 /* 2DPhysics */,
 				6D1B704412C29AFE0076D5C4 /* 3DPhysics */,
 				6DFB00F012A7364300C43A7D /* PolycodeCg */,
@@ -170,6 +183,7 @@
 				6DFB00FC12A736A900C43A7D /* libPolycodeCg.a */,
 				6D690D1B12C1D74A00C444B0 /* libPolycode3DPhysics.a */,
 				6D580DF112D29F52006FB999 /* libPolycode2DPhysics.a */,
+				6DFD116912DEA9C60080A2BE /* libPolycodeKinect.a */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -283,6 +297,32 @@
 			name = PolycodeCg;
 			sourceTree = "<group>";
 		};
+		6DFD117F12DEAA1F0080A2BE /* Kinect */ = {
+			isa = PBXGroup;
+			children = (
+				6DFD118012DEAA1F0080A2BE /* Include */,
+				6DFD118212DEAA1F0080A2BE /* Source */,
+			);
+			name = Kinect;
+			path = ../../Contents/Kinect;
+			sourceTree = SOURCE_ROOT;
+		};
+		6DFD118012DEAA1F0080A2BE /* Include */ = {
+			isa = PBXGroup;
+			children = (
+				6DFD118112DEAA1F0080A2BE /* PolycodeKinect.h */,
+			);
+			path = Include;
+			sourceTree = "<group>";
+		};
+		6DFD118212DEAA1F0080A2BE /* Source */ = {
+			isa = PBXGroup;
+			children = (
+				6DFD118312DEAA1F0080A2BE /* PolycodeKinect.cpp */,
+			);
+			path = Source;
+			sourceTree = "<group>";
+		};
 		C6A0FF2B0290797F04C91782 /* Documentation */ = {
 			isa = PBXGroup;
 			children = (
@@ -345,6 +385,14 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		6DFD116512DEA9C60080A2BE /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				6DFD118412DEAA1F0080A2BE /* PolycodeKinect.h in Headers */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXHeadersBuildPhase section */
 
 /* Begin PBXNativeTarget section */
@@ -416,6 +464,23 @@
 			productReference = 6DFBF84712A3F24F00C43A7D /* libPolycodeUI.a */;
 			productType = "com.apple.product-type.library.static";
 		};
+		6DFD116812DEA9C60080A2BE /* PolycodeKinect */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 6DFD117012DEA9DD0080A2BE /* Build configuration list for PBXNativeTarget "PolycodeKinect" */;
+			buildPhases = (
+				6DFD116512DEA9C60080A2BE /* Headers */,
+				6DFD116612DEA9C60080A2BE /* Sources */,
+				6DFD116712DEA9C60080A2BE /* Frameworks */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = PolycodeKinect;
+			productName = PolycodeKinect;
+			productReference = 6DFD116912DEA9C60080A2BE /* libPolycodeKinect.a */;
+			productType = "com.apple.product-type.library.static";
+		};
 /* End PBXNativeTarget section */
 
 /* Begin PBXProject section */
@@ -439,6 +504,7 @@
 				6DFB00FB12A736A900C43A7D /* PolycodeCg */,
 				6D690D1A12C1D74A00C444B0 /* Polycode3DPhysics */,
 				6D580DF012D29F52006FB999 /* Polycode2DPhysics */,
+				6DFD116812DEA9C60080A2BE /* PolycodeKinect */,
 			);
 		};
 /* End PBXProject section */
@@ -495,6 +561,14 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		6DFD116612DEA9C60080A2BE /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				6DFD118512DEAA1F0080A2BE /* PolycodeKinect.cpp in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXSourcesBuildPhase section */
 
 /* Begin XCBuildConfiguration section */
@@ -507,6 +581,8 @@
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
 				HEADER_SEARCH_PATHS = (
+					/usr/local/include/,
+					/usr/local/include/libfreenect,
 					../../../Core/Dependencies/box2d/Box2D,
 					../../../Core/Contents/Include,
 					../../../Core/Dependencies/bullet/src,
@@ -665,6 +741,36 @@
 			};
 			name = Release;
 		};
+		6DFD116A12DEA9C70080A2BE /* 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 = PolycodeKinect;
+			};
+			name = Debug;
+		};
+		6DFD116B12DEA9C70080A2BE /* 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 = PolycodeKinect;
+				ZERO_LINK = NO;
+			};
+			name = Release;
+		};
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
@@ -713,6 +819,15 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
+		6DFD117012DEA9DD0080A2BE /* Build configuration list for PBXNativeTarget "PolycodeKinect" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				6DFD116A12DEA9C70080A2BE /* Debug */,
+				6DFD116B12DEA9C70080A2BE /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
 /* End XCConfigurationList section */
 	};
 	rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;

+ 17 - 8
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -53,6 +53,14 @@ struct ContactPoint
 	ContactState state;
 };
 	
+
+class _PolyExport PhysicsJoint {
+public:
+	PhysicsJoint() {}
+	~PhysicsJoint() {}
+	b2Joint *box2DJoint;
+	
+};
 	
 class _PolyExport PhysicsScreen : public Screen, b2ContactListener {
 
@@ -63,32 +71,33 @@ public:
 	~PhysicsScreen();
 	
 	void Update();
-	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, float friction, float density, float restitution = 0, bool isSensor = false, bool fixedRotation = false);
+	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, float friction=0.1, float density=1, float restitution = 0, bool isSensor = false, bool fixedRotation = false);
 	void removePhysicsChild(PhysicsScreenEntity *entityToRemove);
 	
 	PhysicsScreenEntity *addCollisionChild(ScreenEntity *newEntity, int entType);
 	
+	void destroyJoint(PhysicsJoint *joint);
 	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);
+	PhysicsJoint *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);
 	void applyForce(ScreenEntity *ent, float fx, float fy);
 	void applyImpulse(ScreenEntity *ent, float fx, float fy);
 	
 	void setGravity(Vector2 newGravity);
 	
+	void setTransform(ScreenEntity *ent, Vector2 pos, float angle);
+	
 	PhysicsScreenEntity *getPhysicsEntityByShape(b2Shape *shape);
+	PhysicsScreenEntity *getPhysicsEntityByFixture(b2Fixture *fixture);
 	
 	void setVelocity(ScreenEntity *ent, float fx, float fy);	
 	void setVelocityX(ScreenEntity *ent, float fx);	
 	void setVelocityY(ScreenEntity *ent, float fy);	
+	void setSpin(ScreenEntity *ent, float spin);
 	
-	/*
-	void Add(const b2ContactPoint* point);
-	void Persist(const b2ContactPoint* point);
-	void Remove(const b2ContactPoint* point);				
-	*/
-		
+	Vector2 getVelocity(ScreenEntity *ent);
+			
 	void BeginContact (b2Contact *contact);
 	void EndContact (b2Contact *contact);	
 	

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

@@ -25,6 +25,8 @@ namespace Polycode {
 			
 			void applyTorque(float torque);
 			void applyForce(Vector2 force);
+		
+			void setTransform(Vector2 pos, float angle);
 			
 			void Update();
 			
@@ -32,6 +34,7 @@ namespace Polycode {
 			static const int ENTITY_CIRCLE = 2;	
 			static const int ENTITY_STATICRECT = 3;
 		
+			b2Fixture *fixture;		
 			b2Body* body;
 			b2BodyDef *bodyDef;
 			b2Shape *shape;

+ 49 - 5
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -63,7 +63,10 @@ void PhysicsScreen::Remove(const b2ContactPoint* point) {
 */
 
 void PhysicsScreen::BeginContact (b2Contact *contact) {
-	
+	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
+	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA());
+	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB());			
+	dispatchEvent(newEvent, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
 }
 
 void PhysicsScreen::EndContact (b2Contact *contact) {
@@ -109,7 +112,12 @@ PhysicsScreenEntity *PhysicsScreen::getPhysicsByScreenEntity(ScreenEntity *ent)
 	return NULL;
 }
 
-b2RevoluteJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, float ax, float ay, bool enableLimit, float lowerLimit, float upperLimit, bool motorEnabled, float motorSpeed, float maxTorque) {
+void PhysicsScreen::destroyJoint(PhysicsJoint *joint) {
+	world->DestroyJoint(joint->box2DJoint);
+}
+
+
+PhysicsJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, float ax, float ay, bool enableLimit, float lowerLimit, float upperLimit, bool motorEnabled, float motorSpeed, float maxTorque) {
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
 	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);
 	if(pEnt1 == NULL || pEnt2 == NULL)
@@ -125,8 +133,12 @@ b2RevoluteJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEn
 	jointDef->maxMotorTorque = maxTorque;
 	jointDef->enableMotor = motorEnabled;	
 	jointDef->Initialize(pEnt1->body, pEnt2->body, anchor);
-	b2RevoluteJoint *joint = (b2RevoluteJoint*)world->CreateJoint(jointDef);
+	
+	PhysicsJoint *joint = new PhysicsJoint();
+	
+	joint->box2DJoint = world->CreateJoint(jointDef);
 	return joint;
+	
 }
 
 void PhysicsScreen::createPrismaticJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected) {
@@ -142,6 +154,23 @@ void PhysicsScreen::wakeUp(ScreenEntity *ent) {
 }
 
 
+Vector2 PhysicsScreen::getVelocity(ScreenEntity *ent) {
+	PhysicsScreenEntity *pEnt = getPhysicsByScreenEntity(ent);
+	if(pEnt == NULL)
+		return Vector2(0,0);
+	
+	b2Vec2 vec = pEnt->body->GetLinearVelocity();
+	return Vector2(vec.x, vec.y);
+}
+
+void PhysicsScreen::setSpin(ScreenEntity *ent, float spin) {
+	PhysicsScreenEntity *pEnt = getPhysicsByScreenEntity(ent);
+	if(pEnt == NULL)
+		return;
+
+	pEnt->body->SetAngularVelocity(spin);
+}
+
 void PhysicsScreen::setVelocity(ScreenEntity *ent, float fx, float fy) {
 	PhysicsScreenEntity *pEnt = getPhysicsByScreenEntity(ent);
 	if(pEnt == NULL)
@@ -188,6 +217,13 @@ PhysicsScreenEntity *PhysicsScreen::addCollisionChild(ScreenEntity *newEntity, i
 	return ret;
 }
 
+void PhysicsScreen::setTransform(ScreenEntity *ent, Vector2 pos, float angle) {
+	PhysicsScreenEntity *pEnt = getPhysicsByScreenEntity(ent);
+	if(pEnt == NULL)
+		return;
+	pEnt->setTransform(pos, angle);
+}
+
 void PhysicsScreen::applyForce(ScreenEntity *ent, float fx, float fy) {
 	PhysicsScreenEntity *pEnt = getPhysicsByScreenEntity(ent);
 	if(pEnt == NULL)
@@ -365,6 +401,14 @@ PhysicsScreen::~PhysicsScreen() {
 	}
 }
 
+PhysicsScreenEntity *PhysicsScreen::getPhysicsEntityByFixture(b2Fixture *fixture) {
+	for(int i=0; i < physicsChildren.size(); i++) {
+		if(physicsChildren[i]->fixture == fixture)
+			return physicsChildren[i];
+	}
+	return NULL;	
+}
+
 PhysicsScreenEntity *PhysicsScreen::getPhysicsEntityByShape(b2Shape *shape) {
 	for(int i=0; i < physicsChildren.size(); i++) {
 		if(physicsChildren[i]->shape == shape)
@@ -380,7 +424,7 @@ void PhysicsScreen::handleEvent(Event *event) {
 	if(event->getDispatcher() == updateTimer) {		
 		world->Step(timeStep, iterations,iterations);
 	}
-	
+	/*
 	for (int32 i = 0; i < numContactPoints; ++i)
 	{
 		ContactPoint* point = m_points + i;		
@@ -399,7 +443,7 @@ void PhysicsScreen::handleEvent(Event *event) {
 			dispatchEvent(new PhysicsScreenEvent(), PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION);			
 		}
 	}
-	
+	*/
 	Screen::handleEvent(event);
 }
 

+ 17 - 8
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -29,7 +29,7 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, f
 		bodyDef->type = b2_dynamicBody;	
 	
 	body = world->CreateBody(bodyDef);
-	
+		
 	b2FixtureDef fDef;
 	fDef.friction = friction;
 	fDef.restitution = restitution;
@@ -60,7 +60,7 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, f
 		break;
 	}
 	
-	body->CreateFixture(&fDef);	
+	fixture = body->CreateFixture(&fDef);	
 	
 	lastPosition.x = screenEntity->getPosition2D().x;
 	lastPosition.y = screenEntity->getPosition2D().y;
@@ -81,17 +81,22 @@ ScreenEntity *PhysicsScreenEntity::getScreenEntity() {
 	return screenEntity;
 }
 			
+
+void PhysicsScreenEntity::setTransform(Vector2 pos, float angle) {
+	body->SetTransform(b2Vec2(pos.x/worldScale, pos.y/worldScale), angle*(PI/180.0f));
+}
+
 void PhysicsScreenEntity::Update() {
 	b2Vec2 position = body->GetPosition();
 	float32 angle = body->GetAngle();
 
 	
-	if(lastRotation != screenEntity->getRotation() || collisionOnly) {
-		body->SetTransform(position, screenEntity->getRotation()*(PI/180.0f));		
-	} else {
+//	if(lastRotation != screenEntity->getRotation() || collisionOnly) {
+//		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/worldScale; 
@@ -100,8 +105,12 @@ void PhysicsScreenEntity::Update() {
 		position.x = screenEntity->getPosition2D().x/worldScale; 
 		position.y = screenEntity->getPosition2D().y/worldScale; 				
 	} else {
+ */
 		screenEntity->setPosition(position.x*worldScale, position.y*worldScale);
-	}
+//	}
+	
+	screenEntity->dirtyMatrix(true);
+	screenEntity->rebuildTransformMatrix();
 	
 	lastPosition.x = position.x*worldScale;
 	lastPosition.y = position.y*worldScale;	

+ 92 - 0
Modules/Contents/Kinect/Include/PolycodeKinect.h

@@ -0,0 +1,92 @@
+/*
+ *  PolycodeKinect.h
+ *  PolycodeKinectTest
+ *
+ *  Created by Ivan Safrin on 12/2/10.
+ *  Copyright 2010 Local Projects. All rights reserved.
+ *
+ */
+#pragma once
+
+#include "Polycode.h"
+#include "libfreenect.h"
+
+using namespace Polycode;
+
+void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp);
+void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp);
+
+
+#define MAX_KINECT_POINTS	6000
+
+class PolycodeRunner : public Threaded {
+public:
+	PolycodeRunner();
+	~PolycodeRunner();
+	
+	void runThread();
+	void updateThread() {}
+	
+	void rgbCallback(freenect_device *dev, void *rgb, uint32_t timestamp);
+	void depthCallback(freenect_device *dev, void *v_depth, uint32_t timestamp);
+	
+//	static void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp);
+//	static void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp);
+	
+	int initKinect();
+	
+	void tiltUp();
+	void tiltDown();
+	void Level();	
+	
+	CoreMutex *drawMutex;
+		
+	uint8_t *depth_mid, *depth_front;
+	uint8_t *rgb_back, *rgb_mid, *rgb_front;
+		
+	freenect_context *f_ctx;
+	freenect_device *f_dev;
+	
+	
+protected:
+	
+	uint16_t t_gamma[2048];
+	
+	
+	int freenect_angle;
+	freenect_video_format current_format;
+	freenect_video_format requested_format;
+	
+	
+};
+
+class PolycodeKinect : EventHandler {
+	public:
+		PolycodeKinect(bool calculatePoints);
+		~PolycodeKinect();
+	
+		Texture *getRGBTexture();
+		Texture *getCloseDepthTexture();
+	
+		void tiltUp();
+		void tiltDown();
+		void Level();
+	
+		void handleEvent(Event *event);
+	
+		Vector3 points[MAX_KINECT_POINTS];	
+		Color colors[MAX_KINECT_POINTS];
+protected:
+	
+	Timer *updateTimer;
+
+	bool calculatePoints;
+	bool calculateColors;
+	
+	uint8_t *rgbPtr;
+	Texture *rgbTexture;
+	Texture *closeDepthTexture;
+	PolycodeRunner *runner;
+	
+};
+

+ 364 - 0
Modules/Contents/Kinect/Source/PolycodeKinect.cpp

@@ -0,0 +1,364 @@
+/*
+ *  PolycodeKinect.cpp
+ *  PolycodeKinectTest
+ *
+ *  Created by Ivan Safrin on 12/2/10.
+ *  Copyright 2010 Local Projects. All rights reserved.
+ *
+ */
+
+#include "PolycodeKinect.h"
+
+
+using namespace Polycode;
+
+PolycodeRunner *polycodeRunner;
+pthread_mutex_t gl_backbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t usbMutex = PTHREAD_MUTEX_INITIALIZER;
+
+PolycodeRunner::PolycodeRunner() : Threaded() {
+	
+	polycodeRunner = this;
+	
+	current_format = FREENECT_VIDEO_RGB;
+	requested_format = FREENECT_VIDEO_RGB;
+	freenect_angle = 0;		
+	
+	depth_mid = (uint8_t*)malloc(640*480*3);
+	depth_front = (uint8_t*)malloc(640*480*3);
+	rgb_back = (uint8_t*)malloc(640*480*3);
+	rgb_mid = (uint8_t*)malloc(640*480*3);
+	rgb_front = (uint8_t*)malloc(640*480*3);
+	
+	
+	int i;
+	for (i=0; i<2048; i++) {
+		float v = i/2048.0;
+		v = powf(v, 3)* 5;
+		t_gamma[i] = v*6*256;
+	}
+	
+	
+	initKinect();	
+}
+
+
+int PolycodeRunner::initKinect() {
+	if (freenect_init(&f_ctx, NULL) < 0) {
+		printf("freenect_init() failed\n");
+		return 0;
+	}
+	
+	freenect_set_log_level(f_ctx, FREENECT_LOG_FATAL);
+	
+	int nr_devices = freenect_num_devices (f_ctx);
+	printf ("Number of devices found: %d\n", nr_devices);
+	
+	
+	if (freenect_open_device(f_ctx, &f_dev, 0) < 0) {
+		printf("Could not open device\n");
+		return 1;
+	}
+		
+	return 1;
+}
+
+PolycodeRunner::~PolycodeRunner() {
+	
+}
+
+void PolycodeRunner::runThread() {
+	
+	
+	freenect_set_tilt_degs(f_dev,freenect_angle);
+	freenect_set_led(f_dev,LED_BLINK_YELLOW);
+	freenect_set_depth_callback(f_dev, depth_cb);
+	freenect_set_video_callback(f_dev, rgb_cb);
+	freenect_set_video_format(f_dev, current_format);
+	freenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT);
+	freenect_set_video_buffer(f_dev, rgb_back);
+	
+	freenect_start_depth(f_dev);
+	freenect_start_video(f_dev);
+	
+	while (threadRunning && freenect_process_events(f_ctx) >= 0) {
+		pthread_mutex_lock(&usbMutex);				
+		freenect_raw_tilt_state* state;
+		freenect_update_tilt_state(f_dev);
+		state = freenect_get_tilt_state(f_dev);
+		double dx,dy,dz;
+		freenect_get_mks_accel(state, &dx, &dy, &dz);
+		printf("\r raw acceleration: %4d %4d %4d  mks acceleration: %4f %4f %4f", state->accelerometer_x, state->accelerometer_y, state->accelerometer_z, dx, dy, dz);
+		fflush(stdout);
+		
+		if (requested_format != current_format) {
+			freenect_stop_video(f_dev);
+			freenect_set_video_format(f_dev, requested_format);
+			freenect_start_video(f_dev);
+			current_format = requested_format;
+		}
+		pthread_mutex_unlock(&usbMutex);				
+	}
+	
+	printf("\nshutting down streams...\n");	
+	printf("Cleaning freenect...\n");
+	
+	free(depth_mid);
+	free(depth_front);
+	free(rgb_back);
+	free(rgb_mid);
+	free(rgb_front);
+	
+	
+	freenect_stop_depth(f_dev);
+	freenect_stop_video(f_dev);
+	
+	freenect_close_device(f_dev);
+	freenect_shutdown(f_ctx);	
+}
+
+void PolycodeRunner::rgbCallback(freenect_device *dev, void *rgb, uint32_t timestamp) {
+	rgb_back = rgb_mid;
+	freenect_set_video_buffer(dev, rgb_back);
+	rgb_mid = (uint8_t*)rgb;	
+}
+
+void PolycodeRunner::depthCallback(freenect_device *dev, void *v_depth, uint32_t timestamp) {
+	
+	int i;
+	uint16_t *depth = (uint16_t*)v_depth;
+	
+//	pthread_mutex_lock(&gl_backbuf_mutex);
+	
+	for (i=0; i<FREENECT_FRAME_PIX; i++) {
+		int pval = t_gamma[depth[i]];
+		int lb = pval & 0xff;
+		
+		/*
+		if(pval>>8 == 0) {
+			depth_mid[3*i+0] = 255-lb;
+			depth_mid[3*i+1] = 255-lb;
+			depth_mid[3*i+2] = 255-lb;
+		} else {
+			depth_mid[3*i+0] = 0;
+			depth_mid[3*i+1] = 0;
+			depth_mid[3*i+2] = 0;
+		}
+		 */
+
+		switch (pval>>8) {
+			case 0:
+				depth_mid[3*i+0] = 255;
+				depth_mid[3*i+1] = 255-lb;
+				depth_mid[3*i+2] = 255-lb;
+				break;
+			case 1:
+				depth_mid[3*i+0] = 255;
+				depth_mid[3*i+1] = lb;
+				depth_mid[3*i+2] = 0;
+				break;
+			case 2:
+				depth_mid[3*i+0] = 255-lb;
+				depth_mid[3*i+1] = 255;
+				depth_mid[3*i+2] = 0;
+				break;
+			case 3:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 255;
+				depth_mid[3*i+2] = lb;
+				break;
+			case 4:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 255-lb;
+				depth_mid[3*i+2] = 255;
+				break;
+			case 5:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 255-lb;
+				break;
+			default:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+		}
+			/*	
+		 
+			case 0:
+				depth_mid[3*i+0] = 255;
+				depth_mid[3*i+1] = 255;
+				depth_mid[3*i+2] = 255;
+				break;
+			case 1:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+			case 2:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+			case 3:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+			case 4:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+			case 5:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+			default:
+				depth_mid[3*i+0] = 0;
+				depth_mid[3*i+1] = 0;
+				depth_mid[3*i+2] = 0;
+				break;
+				
+		}
+			 */			 
+	}
+	
+}
+
+
+void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp) {
+	pthread_mutex_lock(&gl_backbuf_mutex);	
+	polycodeRunner->depthCallback(dev, v_depth, timestamp);	
+	pthread_mutex_unlock(&gl_backbuf_mutex);
+}
+
+void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp) {
+	pthread_mutex_lock(&gl_backbuf_mutex);		
+	polycodeRunner->rgbCallback(dev, rgb, timestamp);
+	pthread_mutex_unlock(&gl_backbuf_mutex);	
+}
+
+void PolycodeRunner::tiltUp() {
+	pthread_mutex_lock(&usbMutex);		
+	freenect_angle++;
+	if (freenect_angle > 30) {
+		freenect_angle = 30;
+	}	
+	freenect_set_tilt_degs(f_dev,freenect_angle);	
+	pthread_mutex_unlock(&usbMutex);		
+}
+
+void PolycodeRunner::tiltDown() {
+	pthread_mutex_lock(&usbMutex);		
+	freenect_angle--;
+	if (freenect_angle < -30) {
+		freenect_angle = -30;
+	}
+	freenect_set_tilt_degs(f_dev,freenect_angle);	
+	pthread_mutex_unlock(&usbMutex);		
+	
+}
+
+void PolycodeRunner::Level() {
+	pthread_mutex_lock(&usbMutex);		
+	freenect_angle = 0;
+	freenect_set_tilt_degs(f_dev,freenect_angle);	
+	pthread_mutex_unlock(&usbMutex);		
+	
+}
+
+PolycodeKinect::PolycodeKinect(bool calculatePoints) : EventHandler() {
+	
+	this->calculatePoints = calculatePoints;
+	this->calculateColors = true;
+	rgbTexture = NULL;
+	
+	updateTimer = new Timer(true, 10);
+	updateTimer->addEventListener(this, Timer::EVENT_TRIGGER);
+	
+	
+	runner = new PolycodeRunner();
+	rgbPtr = runner->rgb_front;
+	
+	rgbTexture = CoreServices::getInstance()->getMaterialManager()->createTexture(640, 480, (char*)runner->rgb_front, false, Image::IMAGE_RGB);						
+	closeDepthTexture = CoreServices::getInstance()->getMaterialManager()->createTexture(640, 480, (char*)runner->depth_mid, false, Image::IMAGE_RGB);
+	CoreServices::getInstance()->getCore()->createThread(runner);	
+}
+
+void PolycodeKinect::handleEvent(Event *event) {
+	if(event->getDispatcher() == updateTimer) {
+		Image *newImage = new Image((char*)runner->rgb_back, 640, 480, Image::IMAGE_RGB);
+		rgbTexture->setImageData(newImage);
+		rgbTexture->recreateFromImageData();
+		delete newImage;
+		
+		newImage = new Image((char*)runner->depth_mid, 640, 480, Image::IMAGE_RGB);
+		closeDepthTexture->setImageData(newImage);
+		closeDepthTexture->recreateFromImageData();
+		delete newImage;
+
+		if(calculatePoints || calculateColors) {
+			for(int i=0; i < MAX_KINECT_POINTS; i++) {
+				points[i] = Vector3(0,0,0);
+				colors[i].setColorRGB(0,0,0);
+			}
+			
+			int ptIndex = 0;
+			char *data = closeDepthTexture->getTextureData();
+			char *colorData = rgbTexture->getTextureData();
+			
+				for(int y=0; y < 480; y+= 7) {							
+					for(int x=0; x < 640; x += 7) {					
+					char *testArr = data + ((x*3)+(y*640*3));
+					unsigned int testArrColor = *((unsigned int*) (colorData + ((x-30)*3)+((y+30)*640*3)));
+					
+					if(testArr[1] > 0) {
+						if(ptIndex < MAX_KINECT_POINTS) {							
+							if(calculateColors) {
+								colors[ptIndex].setColorHexRGB(testArrColor);
+							}
+							if(calculatePoints) {
+								points[ptIndex] = Vector3(x, y, testArr[1]);
+							}
+							
+							ptIndex++;
+						} else {
+							return;
+						}
+					}
+				}
+			}			
+			
+		}
+		
+	}
+}
+
+void PolycodeKinect::tiltUp() {
+	runner->tiltUp();
+}
+
+void PolycodeKinect::tiltDown() {
+	runner->tiltDown();	
+}
+
+void PolycodeKinect::Level() {
+	runner->Level();
+}
+
+
+Texture *PolycodeKinect::getCloseDepthTexture() {
+	return closeDepthTexture;
+}
+
+Texture *PolycodeKinect::getRGBTexture() {
+	return rgbTexture;
+}
+
+						
+PolycodeKinect::~PolycodeKinect() {
+	printf("Cleaning kinect\n");	
+	runner->killThread();
+}