#ifndef LS3D_H #define LS3D_H #include #include #include #include #include const float UNIT_PIX_DISTANCE = 1000.0; class ThreeDRenderer; class Entity; class Camera; class Model; class Mesh; class Vertex; class Triangle; struct PointF { public: float x, y, z; PointF(); PointF(float x, float y, float z); }; PointF operator+(const PointF& p1, const PointF& p2); struct PointP { public: int x, y; float z; PointP(); }; struct VectorF { public: float i, j, k; VectorF(); VectorF(float i, float j, float k); float Length(); void Normalize(); }; class ThreeDRenderer { public: std::vector models; bool backfaceCulling; private: SDL_Surface surf; float *zbuffer; public: ThreeDRenderer(); Camera *CreateCamera(); Model *CreateModel(Mesh *mesh); void Render(SDL_Surface *surf, Camera *cam); private: void DrawVertex(SDL_Surface *surf, Vertex *v); void DrawTriangle(SDL_Surface *surf, Triangle *tri); }; class Entity { public: PointF pos; float rotx, roty, rotz; Entity(); }; class Camera : public Entity { }; class Model : public Entity { public: Mesh *mesh; float scalex, scaley, scalez; int color; Model(Mesh *mesh); }; class Mesh { public: std::vector vertexes; std::vector triangles; Vertex *AddVertex(PointF p); Vertex *AddVertex(float x, float y, float z); Triangle *AddTriangle(Vertex *v1, Vertex *v2, Vertex *v3, Uint32 color); void UpdateNormals(); #ifdef DEBUG void DebugDump(); #endif }; class Vertex { public: PointF pos; PointF rpos; PointP ppos; Vertex(PointF p); // Vertex(float x, float y, float z); }; class Triangle { public: Vertex *verts[3]; VectorF normal; VectorF rnormal; Uint32 color; Triangle(Vertex *v1, Vertex *v2, Vertex *v3); void UpdateNormal(); }; #endif