Otclient  14/8/2020
vertexarray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef VERTEXARRAY_H
24 #define VERTEXARRAY_H
25 
26 #include "declarations.h"
28 
30 {
31 public:
32  inline void addVertex(float x, float y) { m_buffer << x << y; }
33  inline void addTriangle(const Point& a, const Point& b, const Point& c) {
34  addVertex(a.x, a.y);
35  addVertex(b.x, b.y);
36  addVertex(c.x, c.y);
37  }
38  inline void addRect(const Rect& rect) {
39  float top = rect.top();
40  float right = rect.right()+1;
41  float bottom = rect.bottom()+1;
42  float left = rect.left();
43 
44  addVertex(left, top);
45  addVertex(right, top);
46  addVertex(left, bottom);
47  addVertex(left, bottom);
48  addVertex(right, top);
49  addVertex(right, bottom);
50  }
51 
52  inline void addQuad(const Rect& rect) {
53  float top = rect.top();
54  float right = rect.right()+1;
55  float bottom = rect.bottom()+1;
56  float left = rect.left();
57 
58  addVertex(left, top);
59  addVertex(right, top);
60  addVertex(left, bottom);
61  addVertex(right, bottom);
62  }
63 
64  inline void addUpsideDownQuad(const Rect& rect) {
65  float top = rect.top();
66  float right = rect.right()+1;
67  float bottom = rect.bottom()+1;
68  float left = rect.left();
69 
70  addVertex(left, bottom);
71  addVertex(right, bottom);
72  addVertex(left, top);
73  addVertex(right, top);
74  }
75 
76  void clear() { m_buffer.reset(); }
77  float *vertices() const { return m_buffer.data(); }
78  int vertexCount() const { return m_buffer.size() / 2; }
79  int size() const { return m_buffer.size(); }
80 
81 private:
82  DataBuffer<float> m_buffer;
83 };
84 
85 #endif
databuffer.h
TPoint::y
T y
Definition: point.h:83
TRect< int >
VertexArray::addTriangle
void addTriangle(const Point &a, const Point &b, const Point &c)
Definition: vertexarray.h:33
DataBuffer< float >
TRect::left
T left() const
Definition: rect.h:52
VertexArray
Definition: vertexarray.h:29
DataBuffer::size
uint size() const
Definition: databuffer.h:47
TRect::bottom
T bottom() const
Definition: rect.h:55
DataBuffer::reset
void reset()
Definition: databuffer.h:38
VertexArray::addVertex
void addVertex(float x, float y)
Definition: vertexarray.h:32
VertexArray::vertexCount
int vertexCount() const
Definition: vertexarray.h:78
VertexArray::clear
void clear()
Definition: vertexarray.h:76
VertexArray::addUpsideDownQuad
void addUpsideDownQuad(const Rect &rect)
Definition: vertexarray.h:64
TPoint::x
T x
Definition: point.h:83
DataBuffer::data
T * data() const
Definition: databuffer.h:48
VertexArray::size
int size() const
Definition: vertexarray.h:79
VertexArray::addRect
void addRect(const Rect &rect)
Definition: vertexarray.h:38
TRect::right
T right() const
Definition: rect.h:54
declarations.h
VertexArray::vertices
float * vertices() const
Definition: vertexarray.h:77
TRect::top
T top() const
Definition: rect.h:53
TPoint< int >
VertexArray::addQuad
void addQuad(const Rect &rect)
Definition: vertexarray.h:52