////////////////////////////////// struc_widget.cpp ////////////////////////////////////
#include "struc_widget.h"
#include <QOpenGLWidget>
#include <QtOpenGL>
#include <QtWidgets>
#include <iostream>
using namespace std;
#include "struc_window.h"
struc_widget
::struc_widget(QWidget *parent
) : QOpenGLWidget
(parent
){
xrot = 0;
yrot = 0;
zrot = 0;
norm_angle_x = 0;
norm_angle_y = 0;
norm_angle_z = 0;
struc_window *struc_window_ptr = qobject_cast<struc_window*>(this->parent()); !!!!!!!!!!!!!!!!!!!!!!!!!!!! this is a zero pointer??????????????????
cout << struc_window_ptr << endl;
//struc_window_ptr->set_nodes();
//struc_window_ptr->set_nodes();
}
void struc_widget::initializeGL()
{
glClearColor(0.5,0.5,0.5,0.4);
}
void struc_widget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glLineWidth(2.5);
normalize_angle_x(xrot);
normalize_angle_y(yrot);
normalize_angle_z(zrot);
glRotatef(norm_angle_x,1,0,0);
glRotatef(norm_angle_y,0,1,0);
glRotatef(norm_angle_z,0,0,1);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(-1,-1,0);
glColor3f(0,1,0);
glVertex3f(1,-1,0);
glColor3f(0,0,1);
glVertex3f(0,1,0);
glEnd();
}
void struc_widget::resizeGL(int width, int height)
{
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
#ifdef QT_OPENGL_ES_1
glOrthof(-2, +2, -2, +2,-10, 10);
#else
glOrtho(-2, +2, -2, +2, -10, 10);
#endif
glMatrixMode(GL_MODELVIEW);
h = height;
b = width;
}
{
lastPos = event->pos();
}
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton)
{
setXRotation(xrot + dy);
}
else if (event->buttons() & Qt::RightButton)
{
setYRotation(yrot + dx);
}
else if (event->buttons() & Qt::MiddleButton)
{
setZRotation(zrot + dx);
}
lastPos = event->pos();
}
// x-rotation
void struc_widget::setXRotation(int angle)
{
if (angle != xrot) {
xrot = angle;
update();
}
}
// y-rotation
void struc_widget::setYRotation(int angle)
{
if (angle != yrot) {
yrot = angle;
update();
}
}
// z-rotation
void struc_widget::setZRotation(int angle)
{
if (angle != zrot) {
zrot = angle;
update();
}
}
// normalize angles
void struc_widget::normalize_angle_x(int angle)
{
norm_angle_x = 180.0 / h * angle;
}
void struc_widget::normalize_angle_y(int angle)
{
norm_angle_y = 180.0 / b * angle;
}
void struc_widget::normalize_angle_z(int angle)
{
norm_angle_z = 180.0 / b * angle;
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////// structural data /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void struc_widget::draw_structure()
{
}
///////////////////////////////////////////////////////
/// slot function
///////////////////////////////////////////////////////
//void struc_widget::getsignal(){
/////////////////////////////////////////////////////////// END OF THE CODE
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////