Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
gridgeometry.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "gridgeometry_p.h"
5#include <QtQuick3DRuntimeRender/private/qssgrendergeometry_p.h>
6
66{
67 updateData();
68}
69
74
76{
77 return m_horLines;
78}
79
81{
82 return m_vertLines;
83}
84
86{
87 return m_horStep;
88}
89
91{
92 return m_vertStep;
93}
94
96{
97 count = qMax(count, 1);
98 if (m_horLines == count)
99 return;
100 m_horLines = qMax(count, 1);
102 updateData();
103 update();
104}
105
107{
108 count = qMax(count, 1);
109 if (m_vertLines == count)
110 return;
111 m_vertLines = qMax(count, 1);
113 updateData();
114 update();
115}
116
118{
119 step = qMax(step, 0.0f);
120 if (qFuzzyCompare(m_horStep, step))
121 return;
122 m_horStep = step;
124 updateData();
125 update();
126}
127
129{
130 step = qMax(step, 0.0f);
131 if (qFuzzyCompare(m_vertStep, step))
132 return;
133 m_vertStep = step;
135 updateData();
136 update();
137}
138
139static void fillVertexData(QByteArray &vertexData, int horLines, float horStep,
140 int vertLines, float vertStep)
141{
142 const int size = (horLines + vertLines) * sizeof(float) * 8 * 2;
143 vertexData.resize(size);
144 float *dataPtr = reinterpret_cast<float *>(vertexData.data());
145
146 float y0 = -float(horLines - 1) * horStep * .5f;
147 float x0 = -float(vertLines - 1) * vertStep * .5f;
148 float y1 = -y0;
149 float x1 = -x0;
150
151 for (int i = 0; i < horLines; ++i) {
152 // start position
153 dataPtr[0] = x0;
154 dataPtr[1] = y0 + i * horStep;
155 dataPtr[2] = .0f;
156 dataPtr[3] = 1.f;
157
158 dataPtr[4] = 0;
159 dataPtr[5] = 0;
160 dataPtr[6] = 1.f;
161 dataPtr[7] = 0;
162
163 dataPtr += 8;
164
165 // end position
166 dataPtr[0] = x1;
167 dataPtr[1] = y0 + i * horStep;
168 dataPtr[2] = .0f;
169 dataPtr[3] = 1.f;
170
171 dataPtr[4] = 0;
172 dataPtr[5] = 0;
173 dataPtr[6] = 1.f;
174 dataPtr[7] = 0;
175
176 dataPtr += 8;
177 }
178
179 for (int i = 0; i < vertLines; ++i) {
180 // start position
181 dataPtr[0] = x0 + i * vertStep;
182 dataPtr[1] = y0;
183 dataPtr[2] = .0f;
184 dataPtr[3] = 1.f;
185
186 dataPtr[4] = 0;
187 dataPtr[5] = 0;
188 dataPtr[6] = 1.f;
189 dataPtr[7] = 0;
190
191 dataPtr += 8;
192
193 // end position
194 dataPtr[0] = x0 + i * vertStep;
195 dataPtr[1] = y1;
196 dataPtr[2] = .0f;
197 dataPtr[3] = 1.f;
198
199 dataPtr[4] = 0;
200 dataPtr[5] = 0;
201 dataPtr[6] = 1.f;
202 dataPtr[7] = 0;
203
204 dataPtr += 8;
205 }
206}
207
208void GridGeometry::updateData()
209{
211 fillVertexData(vertexData, m_horLines, m_horStep, m_vertLines, m_vertStep);
212 clear();
217 setStride(32);
220 setBounds(QVector3D(float(-m_vertLines / 2), float(-m_horLines / 2), 0.0f) * m_horStep,
221 QVector3D(float(m_vertLines / 2), float(m_horLines / 2), 0.0f) * m_vertStep);
222}
GridGeometry()
\qmltype GridGeometry \inqmlmodule QtQuick3D.Helpers \inherits Geometry
void setVerticalStep(float step)
void setVerticalLines(int count)
void verticalLinesChanged()
void horizontalLinesChanged()
void horizontalStepChanged()
void verticalStepChanged()
void setHorizontalLines(int count)
~GridGeometry() override
void setHorizontalStep(float step)
\inmodule QtCore
Definition qbytearray.h:57
\qmltype Geometry \inherits Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DGeometry
void setPrimitiveType(PrimitiveType type)
Sets the primitive type used for rendering to type.
void setStride(int stride)
Sets the stride of the vertex buffer to stride, measured in bytes.
void addAttribute(Attribute::Semantic semantic, int offset, Attribute::ComponentType componentType)
Adds vertex attribute description.
void setVertexData(const QByteArray &data)
Sets the vertex buffer data.
void clear()
Resets the geometry to its initial state, clearing previously set vertex and index data as well as at...
void setBounds(const QVector3D &min, const QVector3D &max)
Sets the bounding volume of the geometry to the cube defined by the points min and max.
QByteArray vertexData() const
Returns the vertex buffer data set by setVertexData.
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
static void fillVertexData(QByteArray &vertexData, int horLines, float horStep, int vertLines, float vertStep)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLfloat GLfloat GLfloat x1
GLenum GLenum GLsizei count
GLuint GLfloat x0
GLuint GLfloat GLfloat y0
#define emit
float vertexData[]