[1510] | 1 | // |
---|
| 2 | // Lol Engine |
---|
| 3 | // |
---|
| 4 | // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> |
---|
| 5 | // (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> |
---|
| 6 | // (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> |
---|
| 7 | // This program is free software; you can redistribute it and/or |
---|
| 8 | // modify it under the terms of the Do What The Fuck You Want To |
---|
| 9 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
| 10 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
| 11 | // |
---|
| 12 | |
---|
| 13 | // |
---|
| 14 | // The EasyMesh class |
---|
| 15 | // ------------------ |
---|
| 16 | // |
---|
| 17 | |
---|
| 18 | #if !defined __EASYMESH_EASYMESH_H__ |
---|
| 19 | #define __EASYMESH_EASYMESH_H__ |
---|
| 20 | |
---|
| 21 | namespace lol |
---|
| 22 | { |
---|
| 23 | |
---|
| 24 | class EasyMesh |
---|
| 25 | { |
---|
| 26 | friend class EasyMeshParser; |
---|
| 27 | |
---|
| 28 | public: |
---|
| 29 | EasyMesh(); |
---|
| 30 | |
---|
| 31 | bool Compile(char const *command); |
---|
| 32 | void MeshConvert(); |
---|
| 33 | void Render(mat4 const &model, float damage = 0.f); |
---|
| 34 | |
---|
| 35 | private: |
---|
| 36 | void OpenBrace(); |
---|
| 37 | void CloseBrace(); |
---|
| 38 | |
---|
| 39 | void SetCurColor(vec4 const &color); |
---|
| 40 | void SetCurColor2(vec4 const &color); |
---|
| 41 | void AddVertex(vec3 const &coord); |
---|
| 42 | void AddDuplicateVertex(int i); |
---|
| 43 | void AppendQuad(int i1, int i2, int i3, int i4, int base); |
---|
| 44 | void AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base); |
---|
| 45 | void AppendTriangle(int i1, int i2, int i3, int base); |
---|
| 46 | void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base); |
---|
| 47 | void ComputeNormals(int start, int vcount); |
---|
| 48 | void SetVertColor(vec4 const &color); |
---|
| 49 | void SetCurVertNormal(vec3 const &normal); |
---|
| 50 | void SetCurVertColor(vec4 const &color); |
---|
| 51 | |
---|
| 52 | void Translate(vec3 const &v); |
---|
| 53 | void RotateX(float t); |
---|
| 54 | void RotateY(float t); |
---|
| 55 | void RotateZ(float t); |
---|
| 56 | void Rotate(float t, vec3 const &axis); |
---|
| 57 | void TaperX(float y, float z, float xoff); |
---|
| 58 | void TaperY(float x, float z, float yoff); |
---|
| 59 | void TaperZ(float x, float y, float zoff); |
---|
| 60 | void Scale(vec3 const &s); |
---|
| 61 | void MirrorX(); |
---|
| 62 | void MirrorY(); |
---|
| 63 | void MirrorZ(); |
---|
| 64 | void DupAndScale(vec3 const &s); |
---|
| 65 | void Chamfer(float f); |
---|
| 66 | |
---|
| 67 | void AppendCylinder(int nsides, float h, float r1, float r2, |
---|
| 68 | int dualside, int smooth); |
---|
[1619] | 69 | void AppendCapsule(int ndivisions, float h, float r); |
---|
[1510] | 70 | void AppendSphere(int ndivisions, vec3 const &size); |
---|
| 71 | void AppendBox(vec3 const &size, float chamf = 0.f); |
---|
| 72 | void AppendSmoothChamfBox(vec3 const &size, float chamf); |
---|
| 73 | void AppendFlatChamfBox(vec3 const &size, float chamf); |
---|
| 74 | void AppendBox(vec3 const &size, float chamf, bool smooth); |
---|
| 75 | void AppendStar(int nbranches, float r1, float r2, |
---|
| 76 | int fade = 0, int fade2 = 0); |
---|
| 77 | void AppendExpandedStar(int nbranches, float r1, float r2, float extrar); |
---|
| 78 | void AppendDisc(int nsides, float r, int fade = 0); |
---|
| 79 | void AppendSimpleTriangle(float size, int fade = 0); |
---|
| 80 | void AppendSimpleQuad(float size, int fade = 0); |
---|
| 81 | void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0); |
---|
| 82 | void AppendCog(int nbsides, float h, float r1, float r2, |
---|
| 83 | float r12, float r22, float sidemul, int offset); |
---|
| 84 | |
---|
| 85 | private: |
---|
| 86 | vec4 m_color, m_color2; |
---|
| 87 | Array<uint16_t> m_indices; |
---|
| 88 | Array<vec3, vec3, vec4> m_vert; |
---|
| 89 | Array<int, int> m_cursors; |
---|
| 90 | |
---|
| 91 | /* FIXME: put this in a separate class so that we can copy meshes. */ |
---|
| 92 | struct |
---|
| 93 | { |
---|
| 94 | Shader *shader; |
---|
| 95 | ShaderAttrib coord, norm, color; |
---|
| 96 | ShaderUniform modelview, proj, normalmat, damage; |
---|
| 97 | VertexDeclaration *vdecl; |
---|
| 98 | VertexBuffer *vbo; |
---|
| 99 | IndexBuffer *ibo; |
---|
| 100 | int vertexcount, indexcount; |
---|
| 101 | } |
---|
| 102 | m_gpu; |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | } /* namespace lol */ |
---|
| 106 | |
---|
| 107 | #endif /* __EASYMESH_EASYMESH_H__ */ |
---|
| 108 | |
---|