collision.c in Collision.rar
Sponsored links
#include <stdlib.h>
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <time.h>
// 光源定义
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {10.0, 10.0, 30.0, 1.0};
int win_id;
static GLuint texName;
// SETUP DATASTRUCTURE FOR OBJECTS
#define MAXGUYS 300
#define MAXOBJS 80
int NUMOBJS;
int TEXENABLE;
int DEBUGENABLE;
int frame;
// 点的数据结构
struct point
{
float x;
float y;
float z;
};
// 有关弹性碰撞的数据结构
struct spring
{
struct point* p1;
struct point* p2;
struct point* v1;
struct point* v2;
float* m1;
float* m2;
float length;
float stiff;
float damp;
float breaklen;
};
// 有关碰撞线的数据结构
struct cdline
{
struct point* p1;
struct point* p2;
struct point* v1;
struct point* v2;
struct point* vi1;
struct point* vi2;
struct point min;
struct point max;
float* mass;
float fric;
};
// 对象的面的数据结构
struct face
{
struct point* p1;
struct point* p2;
struct point* p3;
struct point* v1;
struct point* v2;
struct point* v3;
struct point* vi1;
struct point* vi2;
struct point* vi3;
float* m1;
float* m2;
float* m3;
struct point min;
struct point max;
float fric;
struct point nor;
};
// 有关对象的数据结构
struct object
{
int NUMPTS;
int NUMSPRINGS;
int NUMFACES;
int NUMCDLINES;
float mass[MAXGUYS];
float r,g,b,a;
struct point points[MAXGUYS];
struct point vel[MAXGUYS];
struct point velinc[MAXGUYS];
struct spring springs[MAXGUYS];
struct cdline cdlines[MAXGUYS];
struct face faces[MAXGUYS];
struct point max; // 对象的边界盒
struct point min;
int texture;
int NUMTEXPTS;
int texmap[64][64];
struct point texpoints[MAXGUYS];
struct face texfaces[MAXGUYS];
};
struct object objects[MAXOBJS];
// 定义一些底层函数
#define sqa(A) (A*fabs(A))
#define length(A) sq
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.