Commits

Anonymous committed b4ae0e5

Comments (0)

Files changed (12)

+class: pygame.physics.world
+
+class world(object)
+	####################
+	# methods
+
+	def _init_(self)
+	
+	def add_body(body)  #return body id
+	def remove_body(body)
+	
+	def add_joint(joint) #return joint id
+	def remove_joint(joint)
+	
+	def update() #return collision bodies list
+	#####################
+	#properties
+	
+	self.total_update_time
+	self.since_last_update_time
+	
+	
+class: pygame.physics.body
+
+class body(object)
+	####################
+	# methods
+
+	def _init_(self)
+
+
+	#####################
+	#properties
+	
+	self.mass
+	self.shape
+	self.position
+	self.angle
+	self.force
+	self.torque
+	self.linear_damping
+	self.angle_damping
+	self.resist         # surface property, for collision response by equation : sum(m*v) = -mul(resist)*sum(m*v')
+	
+	self.is_static
+	self.user_data   # user defined other game data
+	
+	
+
+	
+class pygame.physics.joint.joint_base
+(Here I want to explain why I design like this: it's an abstract class, users can write their own joint class by inheriting it, the world maintain joint list inside. Box2d also uses this way)
+
+
+class joint_base(object) 
+	
+	####################
+	# methods
+	def  _init_(self)
+	def  _init_(self, from, to)
+
+	#####################
+	#properties
+	
+	self.from_body
+	self.to_body
+	self.is_collide_connected
+	self.user_data   # user defined other game data
+	
+example joint: distance joint
+
+class pygame.physics.joint.joint_distance
+
+class joint_distance(joint)
+	####################
+	# methods
+	def  _init_(self)
+	def  _init_(self, from, to)
+
+	#####################
+	#properties
+	self.local_anchor1
+	self.local_anchor2
+	self.length
+	
+example code:
+
+	joint = new joint_distance(body1,body2)
+	joint.local_anchor1 = new vector2(0,0)
+	joint.local_anchor2 = new vector2(0,0)
+	joint.length = 10
+	world.add_joint(joint)
+	
+	
+##############################
+# classes for basic physics functions
+module : pygame.physics.basic
+	
+class aabb_box:
+    def collision_with(obb_box):
+
+class obb_box:
+    def collision_with(obb_box):
+    
+    
+class shape:
+    def get_aabb_box():
+    def get_obb_box():
+
+class Polygon(Shape) # override base functions
+class Circle(Shape) # override base functions
+
+
+###############################
+# Math classes 
+
+(Maybe it needs redesigned or we can use a exist python vector math library)
+
+module : pygame.physics.math
+
+class vector2
+	self.x
+	self.y
+	self.z
+	
+	def _init_(self)
+	def _init_(self,x,y,z)
+	
+class matrix2x2
+	self.x11
+	self.x12
+	self.x21
+	self.x22
+	
+	def _init_(self)
+	
+def add_vector2(vec1,vec2) # result = vec1 + vec2
+def sub_vector2(vec1,vec2) # result = vec1 - vec2
+def dot_vector2(vec1,vec2) # result = vec1 dot vec2  (result is a scalar)
+def cross_vector2(vec1,vec2) # result = vec1 cross vec2 (result is a vector)
+
+def add_matrix2x2(mat1,mat2)
+def sub_matrix2x2(mat1,mat2)
+def mul_matrix2x2(mat1,mat2)
+def mul_matrix2x2_vector2(mat,vec) # result = mat * vec  (result is a vec) , for transform and rotation
+
+
+
+2. pygame higher render module
+
+class physics_sprite(SomeKindOfSprite):
+    self.body  #Class Body
+    def update(self, Surface):
+        #do phy updates
+
+    def _init_(self, PhyGroup):
+    # here PhyGroup derive from Group
+    #or
+    #def _init_(self, group)
+    
+    
+class physics_group(group)
+    #physics render here
+    def update(self)
+    def _init(self)
+def phycollision(group,group)

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", "{167010E0-D240-4208-8F4B-76AEEE70DE29}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{167010E0-D240-4208-8F4B-76AEEE70DE29}.Debug|Win32.ActiveCfg = Debug|Win32
+		{167010E0-D240-4208-8F4B-76AEEE70DE29}.Debug|Win32.Build.0 = Debug|Win32
+		{167010E0-D240-4208-8F4B-76AEEE70DE29}.Release|Win32.ActiveCfg = Release|Win32
+		{167010E0-D240-4208-8F4B-76AEEE70DE29}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Pygame Physics.vcproj

+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="Pygame Physics"
+	ProjectGUID="{167010E0-D240-4208-8F4B-76AEEE70DE29}"
+	RootNamespace="PygamePhysics"
+	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"
+				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}"
+			>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\pgBody.h"
+				>
+			</File>
+			<File
+				RelativePath=".\pgJoint.h"
+				>
+			</File>
+			<File
+				RelativePath=".\pgShape.h"
+				>
+			</File>
+			<File
+				RelativePath=".\pgWorld.h"
+				>
+			</File>
+			<Filter
+				Name="Math"
+				>
+				<File
+					RelativePath=".\pgMathTypeDef.h"
+					>
+				</File>
+				<File
+					RelativePath=".\pgMatrix2x2.h"
+					>
+				</File>
+				<File
+					RelativePath=".\pgVector2.h"
+					>
+				</File>
+			</Filter>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Pygame Physics.vcproj.FOXSOFT.Fox Cheung.user

+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioUserFile
+	ProjectType="Visual C++"
+	Version="8.00"
+	ShowAllFiles="false"
+	>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			>
+			<DebugSettings
+				Command=""
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="FOXSOFT"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			>
+			<DebugSettings
+				Command=""
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="FOXSOFT"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+	</Configurations>
+</VisualStudioUserFile>
+========================================================================
+    STATIC LIBRARY : Pygame Physics Project Overview
+========================================================================
+
+AppWizard has created this Pygame Physics library project for you. 
+
+No source files were created as part of your project.
+
+
+Pygame Physics.vcproj
+    This is the main project file for VC++ projects generated using an Application Wizard. 
+    It contains information about the version of Visual C++ that generated the file, and 
+    information about the platforms, configurations, and project features selected with the
+    Application Wizard.
+
+/////////////////////////////////////////////////////////////////////////////
+Other notes:
+
+AppWizard uses "TODO:" comments to indicate parts of the source code you
+should add to or customize.
+
+/////////////////////////////////////////////////////////////////////////////
+#ifndef _PYGAME_PHYSICS_BODY_
+#define _PYGAME_PHYSICS_BODY_
+
+typedef struct _pgBody{
+	
+	pgReal		fMass;
+	pgVector2	vecLinearVelocity;
+	pgReal		fAngleVelocity;
+
+	pgVector2	vecPosition;
+	pgReal		fRotation;
+	pgVector2	vecImpulse;
+	pgVector2	vecForce;
+	pgReal		fTorque;
+} pgBody;
+
+
+
+#endif //_PYGAME_PHYSICS_BODY_
+#ifndef _PYGAME_PHYSICS_JOINT_
+#define _PYGAME_PHYSICS_JOINT_
+
+#include "pgBody.h"
+
+
+typedef struct _pgJoint{
+	pgBody*	body1;
+	pgBody*	body2;
+	bool	isCollideConnect;
+	void	(*SolveConstraint)(_pgJoint* joint,cpReal stepTime);
+} pgJoint;
+
+typedef struct _pgDistanceJoint{
+	pgJoint		joint;
+	pgReal		distance;
+	pgVector2	anchor1,anchor2;
+} pgDistanceJoint;
+
+pgJoint* CreateDistanceJoint(pgBody* _body1,pgBody* _body2,pgReal _dist,pgVector2 anchor1,pgVector2 anchor2);
+pgJoint* DestroyDistanceJoint(pgJoint* joint);
+
+
+#endif //_PYGAME_PHYSICS_JOINT_

src/pgMathTypeDef.h

+#ifndef _PYGAME_MATH_TYPE_DEF_
+#define _PYGAME_MATH_TYPE_DEF_
+
+
+typedef float pgReal;
+
+
+#endif //_PYGAME_MATH_TYPE_DEF_

src/pgMatrix2x2.h

+#ifndef _PYGAME_MATH_MATRIX2X2_
+#define _PYGAME_MATH_MATRIX2X2_
+
+typedef struct _pgMatrix2x2
+{
+	pgReal x11,x12,x21,x22;
+} pgMatrix2x2;
+
+
+
+
+#endif //_PYGAME_MATH_MATRIX2X2_

src/pgShape.h

Empty file added.
+#ifndef _PYGAME_MATH_VECTOR2_
+#define _PYGAME_MATH_VECTOR2_
+
+
+typedef struct _pgVector2
+{
+	pgReal x,y;
+} pgVector2;
+
+static inline pgVector2 pgInitVector2(pgReal x,pgReal y);
+static inline pgVector2 pgAddVector2(const pgVector2 vec1,const pgVector2 vec2);
+static inline pgVector2 pgSubVector2(const pgVector2 vec1,const pgVector2 vec2);
+static inline pgVector2 pgMulVector2(const pgVector2 vec1,const pgVector2 vec2);
+static inline pgVector2 pgMulVector2WithReal(const pgVector2 vec,const pgReal real);
+static inline pgReal	pgDotVector2(const pgVector2 vec1,const pgVector2 vec2);
+static inline pgReal	pgGetLengthVector2(const pgVector2 vec);
+static inline pgReal	pgGetLengthSquareVector2(const pgVector2 vec);
+static inline void		pgNormalizeVector2(pgVector*	pVec);
+static inline pgVector2 pgCrossVector2(const pgVector2 vec1,const pgVector2 vec2);
+
+
+static inline pgVector2 pgMoveVector2(const pgVector2 vec,const pgVector2 moveVec);
+static inline pgVector2 pgScaleVector2(const pgVector2 vec,const pgVector2 scaleVec);
+static inline pgVector2 pgRotate(const pgVector2 vec,const pgVector centerVec,const pgReal angle);
+
+#endif //_PYGAME_MATH_VECTOR2_
+#ifndef _PYGAME_PHYSICS_WORLD_
+#define _PYGAME_PHYSICS_WORLD_
+
+typedef _pgWorld{
+	
+} pgWorld;
+
+void pgAddBodyToWorld(pgWorld* world,pgBody* body);
+void pgRemoveBodyFromWorld(pgWorld* world,pgBody* body);
+void pgAddJointToWorld(pgWorld* world,pgJoint* joint);
+void pgRemoveJointFromWorld(pgWorld* world,pgJoint* joint);
+void pgWorldStepSimulation(pgWorld* world,pgReal stepTime);
+
+#endif