pygame / Test / pgPhysicsRenderer.c

#include "pgPhysicsRenderer.h"
#include "pgShapeObject.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);
	}

	size = PyList_Size((PyObject*)(world->jointList));
	for (i = 0;i < size;i++)
	{
		pgJointObject* joint = (pgJointObject*)(PyList_GetItem((PyObject*)(world->jointList),i));
		PGT_RenderJoint(joint);
	}
}

void PGT_RenderBody(pgBodyObject* body)
{
	pgVector2 gp[4];
	int i;
	pgRectShape* rect = (pgRectShape*)body->shape;

	for(i = 0; i < 4; ++i)
		gp[i] = PG_GetGlobalCor(body, &(rect->point[i]));

	glColor3f(1.f, 1.f, 0.f);
	glLineWidth(2.f);
	glBegin(GL_LINE_LOOP);
	glVertex2d(gp[0].real, gp[0].imag);
	glVertex2d(gp[1].real, gp[1].imag);
	glVertex2d(gp[2].real, gp[2].imag);
	glVertex2d(gp[3].real, gp[3].imag);
	glVertex2d(gp[0].real, gp[0].imag);
	glEnd();
	glLineWidth(1.f);
}

void PGT_RenderJoint(pgJointObject* joint)
{
	pgDistanceJoint* pj = (pgDistanceJoint*)joint;
	glColor3f(1.f, 0.f, 0.f);
	glLineWidth(2.f);
	glBegin(GL_LINES);
	glVertex2d(joint->body1->vecPosition.real,joint->body1->vecPosition.imag);
	glVertex2d(pj->anchor2.real,pj->anchor2.imag);
	glEnd();
	glLineWidth(1.f);
}
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.