Commits

Anonymous committed aa2c959

Comments (0)

Files changed (17)

Pygame_Physics.sln

+ďťż
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pygame_Physics", "Pygame_Physics.vcproj", "{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcproj", "{04AC4F22-E18F-4297-A791-A65126FAB7AA}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8} = {DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}
+	EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Document", "Document", "{86532ADD-793B-4E68-A6C0-E911FD382476}"
+	ProjectSection(SolutionItems) = preProject
+		ToDoList.txt = ToDoList.txt
+	EndProjectSection
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}.Debug|Win32.ActiveCfg = Debug|Win32
+		{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}.Debug|Win32.Build.0 = Debug|Win32
+		{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}.Release|Win32.ActiveCfg = Release|Win32
+		{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}.Release|Win32.Build.0 = Release|Win32
+		{04AC4F22-E18F-4297-A791-A65126FAB7AA}.Debug|Win32.ActiveCfg = Debug|Win32
+		{04AC4F22-E18F-4297-A791-A65126FAB7AA}.Debug|Win32.Build.0 = Debug|Win32
+		{04AC4F22-E18F-4297-A791-A65126FAB7AA}.Release|Win32.ActiveCfg = Release|Win32
+		{04AC4F22-E18F-4297-A791-A65126FAB7AA}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Binary file added.

Pygame_Physics.vcproj

+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="Pygame_Physics"
+	ProjectGUID="{DCBBE6BC-CD5F-4F51-B5C0-66715D9A72D8}"
+	RootNamespace="Pygame_Physics"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="4"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="4"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\Src\pgBodyObject.c"
+				>
+			</File>
+			<File
+				RelativePath=".\Src\pgComplexExtensions.c"
+				>
+			</File>
+			<File
+				RelativePath=".\Src\pgWorldObject.c"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\include\pgAABBBox.h"
+				>
+			</File>
+			<File
+				RelativePath=".\include\pgBodyObject.h"
+				>
+			</File>
+			<File
+				RelativePath=".\include\pgComplexExtensions.h"
+				>
+			</File>
+			<File
+				RelativePath=".\pgJointObject.h"
+				>
+			</File>
+			<File
+				RelativePath=".\pgShapeObject.h"
+				>
+			</File>
+			<File
+				RelativePath=".\include\pgWorldObject.h"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
+#include <GL/glut.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#define HEIGHT 600
+#define WIDTH 600
+#define MAX_STR_LEN 1000
+
+/*-------------------------------˛âĘÔš¤žß----------------------------*/
+
+#include "pgPhysicsRenderer.h"
+
+static pgWorldObject* s_world = NULL;
+static double s_updateTime = 0.0;
+
+//ĹÜąí
+static double s_time;
+static int s_first = 1;
+
+void watch_start()
+{
+	s_time = (double)clock();
+}
+
+//źĆËă´ÓĹÜąí´ňżŞľ˝ÍŁÖšš˛ž­ŔúÁËśŕÉŮĂë
+double watch_stop()
+{
+	return ((double)clock() - s_time)/CLOCKS_PER_SEC;
+}
+
+//äÖČžÎÄ×Ö, ˝öĎŢÓ˘ÎÄŁŹ(x, y)ĘÇÎÄ×ÖžŘŐó×óÉĎ˝Ç×řąę
+//Ăż¸ö×Öˇű×Öˇűżí9ĎńËŘŁŹ¸ß15ĎńËŘ
+void draw_text(int x, int y, char *str)
+{
+	int len, i, w, h;
+
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+	w = glutGet(GLUT_WINDOW_WIDTH);
+	h = glutGet(GLUT_WINDOW_HEIGHT);
+	gluOrtho2D(0, w, h, 0);
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glColor3f(0.6f, 0.8f, 0.6f);
+	glRasterPos2i(x, y + 15);
+	len = (int) strlen(str);
+	for (i = 0; i < len; i++)
+		glutBitmapCharacter(GLUT_BITMAP_9_BY_15, str[i]);
+
+	glPopMatrix();
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+	glMatrixMode(GL_MODELVIEW);
+}
+
+//´ňÓĄÎÄ×Öľ˝ĆÁÄťŁŹŔŕËĆprintfŁŹÍĆźö
+void glprintf(int x, int y, const char* fmt, ...)
+{
+	static char buf[MAX_STR_LEN];
+	va_list p;
+	va_start(p, fmt);
+	memset(buf, 0, sizeof(buf));
+	vsprintf(buf, fmt, p);
+	draw_text(x, y, buf);
+}
+
+
+
+
+
+/*-------------------------------˛âĘÔşŻĘý----------------------------*/
+
+//äÖČžşŻĘý
+void do_render()
+{
+	//glprintf(0, 0, "Your RP value is: %d", 0);
+	glColor3f(1.f, 1.f, 1.f);
+	/*glBegin(GL_LINES);
+	glVertex2f(-10, 0);
+	glVertex2f(10, 0);
+	glEnd();*/
+	PGT_RenderWorld(s_world);
+
+}
+
+
+
+//keyboardĘäČëĎěÓŚ
+void keyboard (unsigned char key, int x, int y)
+{
+	switch(key)
+	{
+	case 27:
+		exit(0);
+		break;
+	}
+}
+
+
+
+
+
+/*-------------------------------ÉčÖĂşŻĘý----------------------------*/
+
+
+void InitGL()
+{
+	glShadeModel(GL_SMOOTH);	
+	glPointSize(3.f);
+	glEnable(GL_LINE_SMOOTH);
+	glEnable(GL_POINT_SMOOTH);
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
+	glHint(GL_POINT_SMOOTH_HINT, GL_DONT_CARE);
+	glLineWidth(2.5f);
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(-WIDTH/2, WIDTH/2, -HEIGHT/2, HEIGHT/2, -1.f, 1.f);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+}
+
+
+void display(void)
+{
+	double dt;
+	//watch_start();
+
+	
+
+	if(s_first)
+	{
+		watch_start();
+		s_first = 0;
+		return;
+	}
+	dt = watch_stop();
+	/*s_updateTime += dt;
+	if(s_updateTime >= s_world->fStepTime)
+	{
+		PG_Update(s_world,s_updateTime);
+		s_updateTime = 0.0;
+
+		glClear(GL_COLOR_BUFFER_BIT);
+		glLoadIdentity();
+		do_render();
+		glutSwapBuffers();
+	}*/
+	PG_Update(s_world,dt);
+	watch_start();
+	glClear(GL_COLOR_BUFFER_BIT);
+	glLoadIdentity();
+	do_render();
+	glutSwapBuffers();
+
+	
+	
+}
+
+//Őâ¸öşŻĘýŇťżŞĘźžÍťáąťľ÷ÓĂŁŹšĘgluPerspectiveşŻĘýĂťąŘŇŞÔÚinitGLťňŐßdisplayşŻĘýŔďľ÷ÓĂ
+void reshape (int width , int height)
+{
+	if(height == 0)										
+		height = 1;										
+
+	glViewport(0,0,width,height);						
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(-width/2, width/2, -height/2, height/2, -1.f, 1.f);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();									
+}
+
+void InitWorld()
+{
+	pgBodyObject* body;
+	s_world = PG_WorldNew();
+	s_world->fStepTime = 0.03;
+	body = PG_BodyNew();
+	body->vecPosition.real = 0;
+	body->vecPosition.imag = 0;
+	body->vecLinearVelocity.real = 10;
+	PG_AddBodyToWorld(s_world,body);
+}
+
+
+int main (int argc, char** argv)
+{
+	glutInit(&argc, argv);
+	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
+	glutInitWindowSize(WIDTH, HEIGHT);
+	glutCreateWindow("test physics");
+	InitWorld();
+	InitGL();
+	glutDisplayFunc(display);
+	glutKeyboardFunc(keyboard);
+	glutIdleFunc(display);
+	glutMainLoop();
+	return 0;
+}
+
+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="Test"
+	ProjectGUID="{04AC4F22-E18F-4297-A791-A65126FAB7AA}"
+	RootNamespace="Test"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_TERMINATE_DEFINED"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="..\Debug\Pygame_Physics.lib"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="..\"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_TERMINATE_DEFINED"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="..\Debug\Pygame_Physics.lib"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\Main.c"
+				>
+			</File>
+			<File
+				RelativePath=".\pgPhysicsRenderer.c"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\pgPhysicsRenderer.h"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Test/pgPhysicsRenderer.c

+#include "pgPhysicsRenderer.h"
+#include <gl/glut.h>
+
+void PGT_RenderWorld(pgWorldObject* world)
+{
+	Py_ssize_t size = PyList_Size((PyObject*)(world->bodyList));
+	Py_ssize_t i;
+	for (i = 0;i < size;i++)
+	{
+		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList),i));
+		PGT_RenderBody(body);
+	}
+}
+
+void PGT_RenderBody(pgBodyObject* body)
+{
+	glColor3f(1,0,0);
+	glPointSize(20);
+	glBegin(GL_POINTS);
+		glVertex2d(body->vecPosition.real,body->vecPosition.imag);
+	glEnd();
+}

Test/pgPhysicsRenderer.h

+#ifndef _PYGAME_PHYSICS_RENDERER_
+#define _PYGAME_PHYSICS_RENDERER_
+
+
+#include "pgBodyObject.h"
+#include "pgWorldObject.h"
+
+void PGT_RenderWorld(pgWorldObject* world);
+void PGT_RenderBody(pgBodyObject* body);
+
+#endif //_PYGAME_PHYSICS_RENDERER_
+1. Finish Pygame Physics Code Frame   ***DONE****
+2. Finish Test Code Frame   ****DONE****
+3. Algorithm For particle simulation   *****DONE*******
+4. Algorithm For Rigid Body simulation   
+5. Shape Defination , Collision Detection
+6. Joint Defination , Joint Solver
+7. Final Test
+8. Pygame Physics Sprite Integration
+9. Demo

include/pgAABBBox.h

+#ifndef _PYGAME_MATH_AABBBOX_
+#define _PYGAME_MATH_AABBBOX_
+
+
+
+typedef struct _pgAABBBox{
+	double left,right,bottom,top;
+} pgAABBBox;
+
+#endif //_PYGAME_MATH_AABBBOX_

include/pgBodyObject.h

+#ifndef _PYGAME_PHYSICS_BODY_
+#define _PYGAME_PHYSICS_BODY_
+
+
+#include <Python.h>
+
+typedef struct _pgWorldObject pgWorldObject;
+
+typedef struct _pgBodyObject{
+	PyObject_HEAD
+
+	double		fMass;
+	Py_complex	vecLinearVelocity;
+	double		fAngleVelocity;
+
+	Py_complex	vecPosition;
+	double		fRotation;
+	Py_complex	vecImpulse;
+	Py_complex	vecForce;
+	double		fTorque;
+
+	double		fRestitution;
+	double		fFriction;
+} pgBodyObject;
+
+pgBodyObject* PG_BodyNew();
+void	PG_BodyDestroy(pgBodyObject* body);
+
+void PG_FreeUpdateBody(pgWorldObject* world,pgBodyObject* body,double dt);
+
+
+#endif //_PYGAME_PHYSICS_BODY_

include/pgComplexExtensions.h

+#ifndef _PYGAME_COMPLEX_EXTENSIONS_
+#define _PYGAME_COMPLEX_EXTENSIONS_
+
+
+#include <Python.h>
+
+double c_get_length_square(Py_complex c);
+double c_get_length(Py_complex c);
+Py_complex c_mul_complex_with_real(Py_complex c,double d);
+
+#endif //_PYGAME_COMPLEX_EXTENSIONS_

include/pgJointObject.h

+#ifndef _PYGAME_PHYSICS_JOINT_
+#define _PYGAME_PHYSICS_JOINT_
+
+#include "pgBodyObject.h"
+
+typedef struct _pgJoint pgJoint;
+
+typedef struct _pgJoint{
+	PyObject_HEAD
+
+	pgBodyObject*	body1;
+	pgBodyObject*	body2;
+	bool	isCollideConnect;
+	void	(*SolveConstraint)(pgJoint* joint,double stepTime);
+} pgJoint;
+
+typedef struct _pgDistanceJoint{
+	pgJoint		joint;
+	double		distance;
+	Py_complex	anchor1,anchor2;
+} pgDistanceJoint;
+
+
+
+#endif //_PYGAME_PHYSICS_JOINT_

include/pgShapeObject.h

+#ifndef _PYGAME_PHYSICS_SHAPE_
+#define _PYGAME_PHYSICS_SHAPE_
+
+#include <Python.h>
+#include "pgAABBBox.h"
+
+typedef struct _pgBodyObject pgBodyObject;
+
+
+// shape base type
+typedef struct _pgShapeObject{
+	PyObject_HEAD
+
+	pgBodyObject*		body;
+	pgAABBBox	box;
+
+	void (*DestroyShape)();
+	void (*UpdateAABBBox)();
+} pgShapeObject;
+
+void	PG_ShapeDestroy(pgShapeObject* shape);
+
+//subclass type
+
+typedef struct _pgRectShape{
+	pgShapeObject		shape;
+
+	pgAABBBox			rectBox;
+} pgPolygonShape;
+
+pgShapeObject*	PG_RectShapeNew(pgAABBBox rect);
+
+
+typedef struct _pgPolygonShape{
+	pgShapeObject		shape;
+
+	PyListObject*		vertexList;
+};
+
+#endif //_PYGAME_PHYSICS_SHAPE_

include/pgWorldObject.h

+#ifndef _PYGAME_PHYSICS_WORLD_
+#define _PYGAME_PHYSICS_WORLD_
+
+
+#include <Python.h>
+#include "pgAABBBox.h"
+
+typedef struct _pgBodyObject pgBodyObject;
+
+typedef struct _pgWorldObject 
+{
+	PyObject_HEAD
+
+	PyListObject*	bodyList;
+	PyListObject*	jointList;
+
+	Py_complex		vecGravity;
+	double			fDamping;
+
+	double			fStepTime;
+	double			fTotalTime;
+	pgAABBBox		worldBox;
+
+} pgWorldObject;
+
+pgWorldObject* PG_WorldNew();
+void	PG_WorldDestroy(pgWorldObject* world);
+
+void	PG_Update(pgWorldObject* world,double stepTime);
+void	PG_AddBodyToWorld(pgWorldObject* world,pgBodyObject* body);
+void	PG_RemoveBodyFromWorld(pgWorldObject* world,pgBodyObject* body);
+
+#endif

src/pgBodyObject.c

+#include "pgBodyObject.h"
+#include "pgWorldObject.h"
+#include "pgComplexExtensions.h"
+#include <structmember.h>
+
+
+void PG_FreeUpdateBody(pgWorldObject* world,pgBodyObject* body, double dt)
+{
+	Py_complex totalVelAdd,totalPosAdd;
+	double k;
+	totalVelAdd = c_sum(body->vecForce,world->vecGravity);
+	k = dt / body->fMass;
+	totalVelAdd = c_mul_complex_with_real(totalVelAdd,k);
+	body->vecLinearVelocity = c_sum(body->vecLinearVelocity,totalVelAdd);
+
+	totalPosAdd = c_mul_complex_with_real(body->vecLinearVelocity,dt);
+	body->vecPosition = c_sum(body->vecPosition,totalPosAdd);
+}
+
+void PG_BodyInit(pgBodyObject* body)
+{
+	body->fAngleVelocity = 0.0;
+	body->fFriction = 0.0;
+	body->fMass = 1.0;
+	body->fRestitution = 1.0;
+	body->fRotation = 0.0;
+	body->fTorque = 0.0;
+	body->vecForce.real = 0.0;
+	body->vecForce.imag = 0.0;
+	body->vecImpulse.real = 0.0;
+	body->vecImpulse.imag = 0.0;
+	body->vecLinearVelocity.real = 0.0;
+	body->vecLinearVelocity.imag = 0.0;
+	body->vecPosition.real = 0.0;
+	body->vecPosition.imag = 0.0;
+}
+
+pgBodyObject* PG_BodyNew()
+{
+	pgBodyObject* op;
+	op = (pgBodyObject*)PyObject_MALLOC(sizeof(pgBodyObject));
+	PG_BodyInit(op);
+	return op;
+}
+
+
+
+
+
+//static PyMemberDef Body_members[] = {
+//	{"mass", T_FLOAT, offsetof(pgBodyObject,fMass), 0,"Mass"},
+//	{"linear_velocity",T_DOUBLE,offsetof(pyBodyObject,vecLinearVelocity),"Linear Velocity"},
+//	{"angle_velocity", T_FLOAT, offsetof(pgBodyObject,fAngleVelocity), 0,"Angle Velocity"},
+//	{"position", T_DOUBLE, offsetof(pgBodyObject,vecPosition), 0,"position"},
+//	{"rotation", T_FLOAT, offsetof(pgBodyObject,fRotation), 0,"Rotation"},
+//    {NULL}  /* Sentinel */
+//};
+//
+//static PyMethodDef Body_methods[] = {
+//    {NULL}  /* Sentinel */
+//};
+//
+//static PyTypeObject BodyType = {
+//    PyObject_HEAD_INIT(NULL)
+//    0,                         /*ob_size*/
+//    "physics.body",			/*tp_name*/
+//    sizeof(pgBodyObject),	/*tp_basicsize*/
+//    0,                         /*tp_itemsize*/
+//    (destructor)Body_dealloc, /*tp_dealloc*/
+//    0,                         /*tp_print*/
+//    0,                         /*tp_getattr*/
+//    0,                         /*tp_setattr*/
+//    0,                         /*tp_compare*/
+//    0,                         /*tp_repr*/
+//    0,                         /*tp_as_number*/
+//    0,                         /*tp_as_sequence*/
+//    0,                         /*tp_as_mapping*/
+//    0,                         /*tp_hash */
+//    0,                         /*tp_call*/
+//    0,                         /*tp_str*/
+//    0,                         /*tp_getattro*/
+//    0,                         /*tp_setattro*/
+//    0,                         /*tp_as_buffer*/
+//    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+//    "Body objects",           /* tp_doc */
+//    0,		               /* tp_traverse */
+//    0,		               /* tp_clear */
+//    0,		               /* tp_richcompare */
+//    0,		               /* tp_weaklistoffset */
+//    0,		               /* tp_iter */
+//    0,		               /* tp_iternext */
+//    Body_methods,             /* tp_methods */
+//    Body_members,             /* tp_members */
+//    0,                         /* tp_getset */
+//    0,                         /* tp_base */
+//    0,                         /* tp_dict */
+//    0,                         /* tp_descr_get */
+//    0,                         /* tp_descr_set */
+//    0,                         /* tp_dictoffset */
+//    (initproc)Body_init,      /* tp_init */
+//    0,                         /* tp_alloc */
+//    Body_new,                 /* tp_new */
+//};
+
+

src/pgComplexExtensions.c

+#include "pgComplexExtensions.h"
+
+double c_get_length_square(Py_complex c)
+{
+	double r;
+	r = c.real * c.real;
+	r += (c.imag * c.imag);
+	return r;
+}
+
+double c_get_length(Py_complex c)
+{
+	double r;
+	r = c.real * c.real;
+	r += (c.imag * c.imag);
+	return sqrt(r);
+}
+
+Py_complex c_mul_complex_with_real(Py_complex c,double d)
+{
+	Py_complex r;
+	r.real = c.real * d;
+	r.imag = c.imag * d;
+	return r;
+}
+

src/pgWorldObject.c

+#include "pgWorldObject.h"
+#include "pgBodyObject.h"
+
+void _PG_FreeBodySimulation(pgWorldObject* world,double stepTime)
+{
+	Py_ssize_t size = PyList_Size((PyObject*)(world->bodyList));
+	Py_ssize_t i;
+	for (i = 0;i < size;i++)
+	{
+		pgBodyObject* body = (pgBodyObject*)(PyList_GetItem((PyObject*)(world->bodyList),i));
+		PG_FreeUpdateBody(world,body,stepTime);
+	}
+}
+
+void PG_Update(pgWorldObject* world,double stepTime)
+{
+	_PG_FreeBodySimulation(world,stepTime);
+}
+
+
+void PG_AddBodyToWorld(pgWorldObject* world,pgBodyObject* body)
+{
+	PyList_Append((PyObject*)world->bodyList,(PyObject*)body);
+}
+
+void PG_RemoveBodyFromWorld(pgWorldObject* world,pgBodyObject* body)
+{
+	
+}
+
+void PG_WorldInit(pgWorldObject* world)
+{
+	world->bodyList = (PyListObject*)PyList_New(0);
+	world->jointList = (PyListObject*)PyList_New(0);
+	world->fDamping = 0.0;
+	world->fStepTime = 0.1;
+	world->fTotalTime = 0.0;
+	world->vecGravity.real = 0.0;
+	world->vecGravity.imag = -9.8;
+}
+
+pgWorldObject* PG_WorldNew()
+{
+	pgWorldObject* op;
+	op = (pgWorldObject*)PyObject_MALLOC(sizeof(pgWorldObject));
+	PG_WorldInit(op);
+	return op;
+}
+
+void	PG_WorldDestroy(pgWorldObject* world);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.