1
0
Fork 0
blockofighter/src/mesh.h

107 lines
1.7 KiB
C
Raw Permalink Normal View History

2014-02-16 14:32:28 +00:00
#ifndef __MESH_H_INCLUDED__
#define __MESH_H_INCLUDED__
#include "object.h"
#define X_AXIS 0
#define Y_AXIS 1
#define Z_AXIS 2
2015-06-03 12:29:34 +00:00
class Vertex {
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
float position[3];
float oldposition[3];
float normal[3];
2014-02-16 14:32:28 +00:00
float texcoords[2];
2015-06-03 12:29:34 +00:00
Vertex(void);
Vertex(float x, float y, float z);
Vertex(float x, float y, float z, float nx, float ny, float nz);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void setTexCoords(float u, float v);
2014-02-16 14:32:28 +00:00
};
class Edge;
2015-06-03 12:29:34 +00:00
class Polygon {
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
float planenormal[3];
float planedistance;
bool smooth;
bool realsmooth;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int vertexcount;
Vertex **vertices;
int edgecount;
Edge **edges;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Polygon(void);
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
class Edge {
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
Vertex *v1, *v2;
class Polygon *p1, *p2;
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
class Mesh {
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
int vertexcount;
Vertex *vertices;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int polygoncount;
class Polygon *polygons;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Edge *edges;
int edgecount;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
Mesh(void);
~Mesh(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void createPlanes(void);
void createVertexnormals(void);
void createEdges(void);
float calculateScale(float targetLength, int axis);
void scale(float targetLength, int axis);
2014-02-16 14:32:28 +00:00
void scale(float scale);
};
2015-06-03 12:29:34 +00:00
class MeshObject : public Object {
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
Mesh *mesh;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
MeshObject(Mesh *mesh);
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
class MeshAppearance : public Appearance {
2014-02-16 14:32:28 +00:00
private:
2015-06-03 12:29:34 +00:00
Mesh *mesh;
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
MeshAppearance(Mesh *mesh);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
void draw(void);
2014-02-16 14:32:28 +00:00
};
2015-06-03 12:29:34 +00:00
// Geometry of sphere
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
class MeshShape : public Shape {
2014-02-16 14:32:28 +00:00
private:
2015-06-03 12:29:34 +00:00
Mesh *mesh;
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
MeshShape(MeshObject *meshobject);
MeshShape(Object *object, Mesh *mesh);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float calculateMomentOfInertia(float *rotationvector);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool checkCollision(Object *target);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
bool checkCollisionPeer(SphereShape *target);
bool checkCollisionPeer(MeshShape *target);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
friend class SphereShape;
2014-02-16 14:32:28 +00:00
};
#endif