1. pygame
  2. Untitled project
  3. pygame

Commits

minz  committed 322cd64

  • Participants
  • Parent commits b4ae0e5
  • Branches physics

Comments (0)

Files changed (7)

File src/pgBody.h

View file
 #ifndef _PYGAME_PHYSICS_BODY_
 #define _PYGAME_PHYSICS_BODY_
 
+#include "pgMathTypeDef.h"
+#include "pgVector2.h"
+
+typedef struct _pgShape pgShape;
+
 typedef struct _pgBody{
 	
 	pgReal		fMass;
 	pgVector2	vecImpulse;
 	pgVector2	vecForce;
 	pgReal		fTorque;
+
+	pgReal		fRestitution;
+	pgReal		fFriction;
+
+	pgShape*	shapeBody;
 } pgBody;
 
 

File src/pgJoint.h

View file
 #ifndef _PYGAME_PHYSICS_JOINT_
 #define _PYGAME_PHYSICS_JOINT_
 
-#include "pgBody.h"
+#include "pgMathTypeDef.h"
 
+typedef struct _pgJoint pgJoint;
 
 typedef struct _pgJoint{
 	pgBody*	body1;
 	pgBody*	body2;
 	bool	isCollideConnect;
-	void	(*SolveConstraint)(_pgJoint* joint,cpReal stepTime);
+	void	(*SolveConstraint)(pgJoint* joint,pgReal stepTime);
 } pgJoint;
 
 typedef struct _pgDistanceJoint{
 } pgDistanceJoint;
 
 pgJoint* CreateDistanceJoint(pgBody* _body1,pgBody* _body2,pgReal _dist,pgVector2 anchor1,pgVector2 anchor2);
-pgJoint* DestroyDistanceJoint(pgJoint* joint);
+void	 DestroyDistanceJoint(pgJoint* joint);
 
 
 #endif //_PYGAME_PHYSICS_JOINT_

File src/pgMathTypeDef.h

View file
 
 
 typedef float pgReal;
+typedef	int	  bool;
 
+#define true 1;
+#define false 0;
 
 #endif //_PYGAME_MATH_TYPE_DEF_

File src/pgMatrix2x2.h

View file
 #ifndef _PYGAME_MATH_MATRIX2X2_
 #define _PYGAME_MATH_MATRIX2X2_
 
+#include "pgMathTypeDef.h"
+
 typedef struct _pgMatrix2x2
 {
 	pgReal x11,x12,x21,x22;

File src/pgShape.h

View file
+#ifndef _PYGAME_PHYSICS_SHAPE_
+#define _PYGAME_PHYSICS_SHAPE_
+
+#include "pgVector2.h"
+#include "pgAABBBox.h"
+
+typedef struct _pgBody pgBody;
+
+
+typedef struct _pgShape{
+	pgBody*		body;
+	pgAABBBox	box;
+
+	void (*InitShape)(pgBody* bd);
+	void (*DestroyShape)();
+	void (*UpdateAABBBox)();
+} pgShape;
+
+
+typedef struct _pgPolygonShape{
+	pgShape		shape;
+	
+	int			iVertexNum;
+	pgVector2*	iVertexArray;
+} pgPolygonShape;
+
+typedef struct _pgCircleShape{
+	pgShape		shape;
+
+	pgVector2	vecCenter;
+	pgReal		fRadius;
+} pgCircleShape;
+
+#endif //_PYGAME_PHYSICS_SHAPE_

File src/pgVector2.h

View file
 #ifndef _PYGAME_MATH_VECTOR2_
 #define _PYGAME_MATH_VECTOR2_
 
+#include "pgMathTypeDef.h"
 
 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 pgVector2 pgInitVector2(pgReal x,pgReal y);
+static pgVector2 pgAddVector2(const pgVector2 vec1,const pgVector2 vec2);
+static pgVector2 pgSubVector2(const pgVector2 vec1,const pgVector2 vec2);
+static pgVector2 pgMulVector2(const pgVector2 vec1,const pgVector2 vec2);
+static pgVector2 pgMulVector2WithReal(const pgVector2 vec,const pgReal real);
+static pgReal	pgDotVector2(const pgVector2 vec1,const pgVector2 vec2);
+static pgReal	pgGetLengthVector2(const pgVector2 vec);
+static pgReal	pgGetLengthSquareVector2(const pgVector2 vec);
+static void		pgNormalizeVector2(pgVector2*	pVec);
+static 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);
+static pgVector2 pgMoveVector2(const pgVector2 vec,const pgVector2 moveVec);
+static pgVector2 pgScaleVector2(const pgVector2 vec,const pgVector2 scaleVec);
+static pgVector2 pgRotate(const pgVector2 vec,const pgVector2 centerVec,const pgReal angle);
 
 #endif //_PYGAME_MATH_VECTOR2_

File src/pgWorld.h

View file
 #ifndef _PYGAME_PHYSICS_WORLD_
 #define _PYGAME_PHYSICS_WORLD_
 
-typedef _pgWorld{
-	
+#include <ds.h>
+
+#include "pgMathTypeDef.h"
+#include "pgBody.h"
+#include "pgJoint.h"
+
+
+typedef struct _pgWorld{
+	PARRAY	bodyArray;
+	PARRAY	jointArray;
+
+	pgReal	fGravity;
+	pgReal	fDamping;
 } 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);
+static void pgAddBodyToWorld(pgWorld* world,pgBody* body);
+static void pgRemoveBodyFromWorld(pgWorld* world,pgBody* body);
+static void pgAddJointToWorld(pgWorld* world,pgJoint* joint);
+static void pgRemoveJointFromWorld(pgWorld* world,pgJoint* joint);
+static void pgWorldStepSimulation(pgWorld* world,pgReal stepTime);
 
 #endif