source: trunk/src/easymesh/easymesh.h @ 1875

Last change on this file since 1875 was 1875, checked in by sam, 8 years ago

easymesh: first shot at a simple, flat shaded torus.

File size: 3.5 KB
Line 
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
21namespace lol
22{
23
24class EasyMesh
25{
26    friend class EasyMeshParser;
27
28public:
29    EasyMesh();
30
31    bool Compile(char const *command);
32    void MeshConvert();
33    void Render(mat4 const &model, float damage = 0.f);
34
35    void OpenBrace();
36    void CloseBrace();
37
38    void SetCurColor(vec4 const &color);
39    void SetCurColor2(vec4 const &color);
40
41private:
42    void AddVertex(vec3 const &coord);
43    void AddDuplicateVertex(int i);
44    void AppendQuad(int i1, int i2, int i3, int i4, int base);
45    void AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base);
46    void AppendTriangle(int i1, int i2, int i3, int base);
47    void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base);
48    void ComputeNormals(int start, int vcount);
49    void SetVertColor(vec4 const &color);
50
51public:
52    void SetCurVertNormal(vec3 const &normal);
53    void SetCurVertColor(vec4 const &color);
54
55    void RadialJitter(float r);
56
57    void Translate(vec3 const &v);
58    void RotateX(float t);
59    void RotateY(float t);
60    void RotateZ(float t);
61    void Rotate(float t, vec3 const &axis);
62    void TaperX(float y, float z, float xoff);
63    void TaperY(float x, float z, float yoff);
64    void TaperZ(float x, float y, float zoff);
65    void Scale(vec3 const &s);
66    void MirrorX();
67    void MirrorY();
68    void MirrorZ();
69    void DupAndScale(vec3 const &s);
70    void Chamfer(float f);
71
72    void AppendCylinder(int nsides, float h, float r1, float r2,
73                        int dualside, int smooth);
74    void AppendCapsule(int ndivisions, float h, float r);
75    void AppendSphere(int ndivisions, vec3 const &size);
76    void AppendTorus(int ndivisions, float r1, float r2);
77    void AppendBox(vec3 const &size, float chamf = 0.f);
78    void AppendSmoothChamfBox(vec3 const &size, float chamf);
79    void AppendFlatChamfBox(vec3 const &size, float chamf);
80    void AppendBox(vec3 const &size, float chamf, bool smooth);
81    void AppendStar(int nbranches, float r1, float r2,
82                    int fade = 0, int fade2 = 0);
83    void AppendExpandedStar(int nbranches, float r1, float r2, float extrar);
84    void AppendDisc(int nsides, float r, int fade = 0);
85    void AppendSimpleTriangle(float size, int fade = 0);
86    void AppendSimpleQuad(float size, int fade = 0);
87    void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0);
88    void AppendCog(int nbsides, float h, float r1, float r2,
89                   float r12, float r22, float sidemul, int offset);
90
91private:
92    vec4 m_color, m_color2;
93    Array<uint16_t> m_indices;
94    Array<vec3, vec3, vec4> m_vert;
95    Array<int, int> m_cursors;
96
97    /* FIXME: put this in a separate class so that we can copy meshes. */
98    struct
99    {
100        Shader *shader;
101        ShaderAttrib coord, norm, color;
102        ShaderUniform modelview, proj, normalmat, damage;
103        VertexDeclaration *vdecl;
104        VertexBuffer *vbo;
105        IndexBuffer *ibo;
106        int vertexcount, indexcount;
107    }
108    m_gpu;
109};
110
111} /* namespace lol */
112
113#endif /* __EASYMESH_EASYMESH_H__ */
114
Note: See TracBrowser for help on using the repository browser.