-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspace3dwidget.cpp
More file actions
73 lines (58 loc) · 1.47 KB
/
workspace3dwidget.cpp
File metadata and controls
73 lines (58 loc) · 1.47 KB
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
#include "workspace3dwidget.h"
#include <QOpenGLShaderProgram>
#include <QDebug>
Workspace3DWidget::Workspace3DWidget(QWidget* parent)
: QOpenGLWidget(parent)
{
}
Workspace3DWidget::~Workspace3DWidget()
{
}
void Workspace3DWidget::initializeGL()
{
initializeOpenGLFunctions();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // 设置黑色背景
glEnable(GL_DEPTH_TEST); // 开启深度测试
}
void Workspace3DWidget::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
}
void Workspace3DWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// TODO: 添加 3D 渲染代码(如 OpenGL 立方体)
glLoadIdentity(); // 重置变换矩阵
// 绘制 XYZ 坐标轴
drawXYZAxis();
}
void Workspace3DWidget::drawXYZAxis()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// 设置正交投影,使 XYZ 轴固定在左下角
glOrtho(0, width(), 0, height(), -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glLineWidth(2.0f);
glBegin(GL_LINES);
// X 轴 (红色)
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(20, 20);
glVertex2f(50, 20);
// Y 轴 (绿色)
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(20, 20);
glVertex2f(20, 50);
// Z 轴 (蓝色)
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(20, 20);
glVertex2f(35, 35);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}