我是靠谱客的博主 聪明芒果,这篇文章主要介绍QEasingCurve的绘制,现在分享给大家,希望可以做个参考。

QEasingCurve的介绍链接:

http://doc.qt.io/qt-5/qeasingcurve.html

把QT中QEasingCurve组件提取出来,在glut中实现了绘制。

QEasingCurve中支持四十多种曲线,而且代码也相对独立。提取出来不是特别难。

效果如图:

 

代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include < vector > #include < GL / glut.h > #include < cmath > #include < gl / glaux.h > #include "QEasingCurve.h" using namespace std; GLfloat g_fAngle[3] = { 0.0 }; int g_iAreaSizeX = 64; int g_iAreaSizeY = 64; class Painter { public: Painter(): mPreX(0), mPreY(0), mBegin(0) {} void drawLine(qreal bgX, qreal bgY, qreal edX, qreal edY) { glPushMatrix(); { glBegin(GL_LINES); glVertex3f(bgX, bgY, 0); glVertex3f(edX, edY, 0); glEnd(); } glPopMatrix(); } void moveTo(qreal x, qreal y) { mBegin = true; mPreX = x; mPreY = y; } void lineTo(qreal x, qreal y) { if (!mBegin) return; drawLine(mPreX, mPreY, x, y); mPreX = x; mPreY = y; } private: bool mBegin; qreal mPreX; qreal mPreY; }; struct CurveControl { enum { Range = 41 }; CurveControl() { mCurveType = 0; mCurve = new QEasingCurve((QEasingCurve::Type) mCurveType); } void setRegion(int l, int b, int w, int h) { mLeft = l; mBottom = b; mWidth = w; mHeight = h; } void renderCurve() { glColor3f(0.5 f, 0.5 f, 0.5 f); glRectd(mLeft, mBottom, mLeft + mWidth, mBottom + mHeight); glLineWidth(3.0 f); glColor3f(1.0 f, 1.0 f, 0.0 f); Painter painter; //qreal xAxis = mHeight/1.5;//qreal yAxis = mWidth/3; qreal xAxis = mBottom; qreal yAxis = mLeft; painter.drawLine(mLeft, xAxis, mLeft + mWidth, xAxis); painter.drawLine(yAxis, mBottom, yAxis, mBottom + mHeight); qreal curveScale = mHeight * 0.8; painter.moveTo(yAxis, xAxis - curveScale * mCurve - > valueForProgress(0)); for (qreal t = 0; t <= 1.0; t += 1.0 / curveScale) { painter.lineTo(yAxis + curveScale * t, xAxis + curveScale * mCurve - > valueForProgress(t)); } } //MAX: QEasingCurve::NCurveTypes - 1 //MIN: 0 void decreTypeIdx() { mCurveType = (mCurveType - 1 + Range) % Range; update(); } void increTypeIdx() { mCurveType = (mCurveType + 1) % Range; update(); } void update() { mCurve - > setType((QEasingCurve::Type) mCurveType); } qreal mLeft; qreal mBottom; qreal mWidth; qreal mHeight; int mCurveType; QEasingCurve * mCurve; }; CurveControl g_CurveControl; void init(); void display(); void keyboard(unsigned char key, int x, int y); void reshape(int w, int h); int main(int argc, char * * argv) { glutInit( & argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; } void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); g_CurveControl.setRegion(0, 0, g_iAreaSizeX, g_iAreaSizeY); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); /* clear the matrix */ /* viewing transformation */ gluLookAt(0.0, 0.0, 120.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glRotatef(g_fAngle[0], 0.0, 1.0, 0.0); glRotatef(g_fAngle[1], 1.0, .0, 0.0); glRotatef(g_fAngle[2], 0.0, .0, 1.0); //Render Scene~ //Painter painter; //painter.drawLine(0, 0, 64, 64); //glutSolidCube(1.0f); CurveControl leftTopRegion; leftTopRegion.setRegion(-g_iAreaSizeX, 0, g_iAreaSizeX, g_iAreaSizeY); leftTopRegion.increTypeIdx(); leftTopRegion.renderCurve(); CurveControl leftBottomRegion; leftBottomRegion.setRegion(-g_iAreaSizeX, -g_iAreaSizeY, g_iAreaSizeX, g_iAreaSizeY); leftBottomRegion.increTypeIdx(); leftBottomRegion.increTypeIdx(); leftBottomRegion.renderCurve(); CurveControl rightBottomRegion; rightBottomRegion.setRegion(0, -g_iAreaSizeY, g_iAreaSizeX, g_iAreaSizeY); rightBottomRegion.increTypeIdx(); rightBottomRegion.increTypeIdx(); rightBottomRegion.increTypeIdx(); rightBottomRegion.renderCurve(); g_CurveControl.renderCurve(); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); gluPerspective(60, 1.0, 1.5, 500); //gluOrtho2D( 0, w, 0, h ); glMatrixMode(GL_MODELVIEW); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; case 'i': g_CurveControl.increTypeIdx(); printf("%d/n", g_CurveControl.mCurveType); break; case 'd': g_CurveControl.decreTypeIdx(); printf("%d/n", g_CurveControl.mCurveType); break; } glutPostRedisplay(); }

 

最后

以上就是聪明芒果最近收集整理的关于QEasingCurve的绘制的全部内容,更多相关QEasingCurve内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部