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

Last change on this file since 2289 was 2289, checked in by sam, 7 years ago

easymesh: interface the shiny shader with new Light objects.

File size: 4.1 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//            (c) 2009-2013 Cédric Lecacheur <jordx@free.fr>
6//            (c) 2009-2013 Benjamin "Touky" 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://www.wtfpl.net/ 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(Shader* ProvidedShader = NULL);
33    void Render(mat4 const &model, float damage = 0.f);
34
35private:
36    void UpdateVertexDict(Array< int, int > &vertex_dict);
37//DEBUG
38public:
39#define CSG_UNION       0
40#define CSG_SUBSTRACT   1
41#define CSG_AND         2
42#define CSG_XOR         3
43
44    void MeshCsg(int csg_operation);
45    void CsgUnion()     { MeshCsg(CSG_UNION); }
46    void CsgSubstract() { MeshCsg(CSG_SUBSTRACT); }
47    void CsgAnd()       { MeshCsg(CSG_AND); }
48    void CsgXor()       { MeshCsg(CSG_XOR); }
49
50public:
51    void OpenBrace();
52    void CloseBrace();
53
54    void ToggleScaleWinding();
55    void SetCurColor(vec4 const &color);
56    void SetCurColor2(vec4 const &color);
57
58private:
59    void AddVertex(vec3 const &coord);
60    void AddDuplicateVertex(int i);
61    void AppendQuad(int i1, int i2, int i3, int i4, int base);
62    void AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base);
63    void AppendTriangle(int i1, int i2, int i3, int base);
64    void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base);
65    void ComputeNormals(int start, int vcount);
66    void SetVertColor(vec4 const &color);
67
68public:
69    void SetCurVertNormal(vec3 const &normal);
70    void SetCurVertColor(vec4 const &color);
71
72    void RadialJitter(float r);
73
74    void Translate(vec3 const &v);
75    void RotateX(float t);
76    void RotateY(float t);
77    void RotateZ(float t);
78    void Rotate(float t, vec3 const &axis);
79    void TaperX(float y, float z, float xoff);
80    void TaperY(float x, float z, float yoff);
81    void TaperZ(float x, float y, float zoff);
82    void Scale(vec3 const &s);
83    void MirrorX();
84    void MirrorY();
85    void MirrorZ();
86    void DupAndScale(vec3 const &s);
87    void Chamfer(float f);
88
89    void AppendCylinder(int nsides, float h, float r1, float r2,
90                        int dualside, int smooth);
91    void AppendCapsule(int ndivisions, float h, float r);
92    void AppendSphere(int ndivisions, vec3 const &size);
93    void AppendTorus(int ndivisions, float r1, float r2);
94    void AppendBox(vec3 const &size, float chamf = 0.f);
95    void AppendSmoothChamfBox(vec3 const &size, float chamf);
96    void AppendFlatChamfBox(vec3 const &size, float chamf);
97    void AppendBox(vec3 const &size, float chamf, bool smooth);
98    void AppendStar(int nbranches, float r1, float r2,
99                    int fade = 0, int fade2 = 0);
100    void AppendExpandedStar(int nbranches, float r1, float r2, float extrar);
101    void AppendDisc(int nsides, float r, int fade = 0);
102    void AppendSimpleTriangle(float size, int fade = 0);
103    void AppendSimpleQuad(float size, int fade = 0);
104    void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0);
105    void AppendCog(int nbsides, float h, float r10, float r20, float r1,
106                   float r2, float r12, float r22, float sidemul, int offset);
107
108private:
109    vec4 m_color, m_color2;
110    Array<uint16_t> m_indices;
111    //<coord, norm, color>
112    Array<vec3, vec3, vec4> m_vert;
113    //<vert count, indices count>
114    Array<int, int> m_cursors;
115    bool m_ignore_winding_on_scale;
116
117    /* FIXME: put this in a separate class so that we can copy meshes. */
118    struct
119    {
120        Shader *shader;
121        ShaderAttrib coord, norm, color;
122        ShaderUniform modelview, view, invview, proj, normalmat, damage, lights;
123        VertexDeclaration *vdecl;
124        VertexBuffer *vbo;
125        IndexBuffer *ibo;
126        int vertexcount, indexcount;
127    }
128    m_gpu;
129};
130
131} /* namespace lol */
132
133#endif /* __EASYMESH_EASYMESH_H__ */
134
Note: See TracBrowser for help on using the repository browser.