/**
*公司:杭州图华科技有限公司
*版权信息:图华所有
*任务:太阳系模拟构建实习作业
*描述:绘图界面实现
*
*版本:1.1
*作者:叶广平
*日期:2019/4/25
**/
#include "OpenglWidget.h"
#include "Mainwindow.h"
#include "MainWidget.h"
#include"constant.h"
#include<GL/glut.h>
#include"planet.h"
#include<ctime>
#include<Windows.h>
#include<iostream>
#include<cmath>
OpenglWidget::OpenglWidget(QWidget *parent)
:QOpenGLWidget(parent),current_planet(Sun),speed(60),pause(GL_FALSE),lightSwitch(GL_FALSE)
{
projM.setToIdentity();
projM.perspective(75,13.0/9.0, 0.2, 1000);
}
OpenglWidget::~OpenglWidget()
{
delete[] solarsystem;
delete[] camera;
}
void OpenglWidget::initializeGL()
{
solarsystem = new solarSystem();
camera=new Camera();
solarsystem->calculatePositions(times);
glShadeModel(GL_SMOOTH);
}
void OpenglWidget::paintGL()
{
solarsystem->calculatePositions(times);
check_current_planet();
solarsystem->render_system(QOpenGLContext::currentContext()->extraFunctions(),
projM,camera,lightSwitch);
calculate_frame_rate();
if (pause == GL_FALSE)
times += speed;
else if(pause == GL_TRUE)
times = times;
update();
}
void OpenglWidget::resizeGL(int w, int h)
{
projM.setToIdentity();
projM.perspective(75.0f, GLfloat(w) / (GLfloat)h, 1.0f, 1000.0f);
}
void OpenglWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void OpenglWidget::mouseMoveEvent(QMouseEvent *event)
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton)
{
camera->angle_xy += dx * rate;
camera->angle_z += dy * rate;
if (camera->angle_xy > PI*5/4)
camera->angle_xy = PI*5/4;
if (camera->angle_xy < PI*3/4)
camera->angle_xy = PI*3/4;
if (camera->angle_z > PI / 6)
camera->angle_z = PI / 6 ;
if (camera->angle_z < PI/32)
camera->angle_z = PI/32;
}
else if (event->buttons() & Qt::RightButton)
{
camera->distance += dy*15*rate;
if (camera->distance > 100)
camera->distance = 100;
if (camera->distance < 2.5)
camera->distance = 2.5;
}
lastPos = event->pos();
}
void OpenglWidget::check_current_planet()
{
switch (current_planet)
{
case Sun:
{
camera->m_target[0] = 0.0f;
camera->m_target[1] = 0.0f;
camera->m_target[2] = 0.0f;
camera->m_eye[0] = camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
case Mercury:
{
camera->m_target[0] = solarsystem->mercury->position[0] * distanceScale;
camera->m_target[1] = solarsystem->mercury->position[1] * distanceScale;
camera->m_target[2] = solarsystem->mercury->position[2] * distanceScale;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
case Venus:
{
camera->m_target[0] = solarsystem->venus->position[0] * distanceScale;
camera->m_target[1] = solarsystem->venus->position[1] * distanceScale;
camera->m_target[2] = solarsystem->venus->position[2] * distanceScale;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
case Earth:
{
camera->m_target[0] = solarsystem->earth->position[0] * distanceScale;
camera->m_target[1] = solarsystem->earth->position[1] * distanceScale;
camera->m_target[2] = solarsystem->earth->position[2] * distanceScale;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D{ 0,0,1 };
/* camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));*/
break;
}
case Mars:
{
camera->m_target[0] = solarsystem->mars->position[0] * distanceScale;
camera->m_target[1] = solarsystem->mars->position[1] * distanceScale;
camera->m_target[2] = solarsystem->mars->position[2] * distanceScale;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
case Jupiter:
{
camera->m_target[0] = solarsystem->jupiter->position[0] * distanceScale;
camera->m_target[1] = solarsystem->jupiter->position[1] * distanceScale;
camera->m_target[2] = solarsystem->jupiter->position[2] * distanceScale;
if (camera->distance < 10)
camera->distance = 10;
camera->m_eye[0] =(camera->m_target[0] + camera->distance * abs(cos(camera->angle_z))*cos(camera->angle_xy));
camera->m_eye[1] = (camera->m_target[1] + camera->distance * abs(cos(camera->angle_z))*sin(camera->angle_xy));
camera->m_eye[2] =(camera->m_target[2] + camera->distance * abs(sin(camera->angle_z)));
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
} /*(solarsystem->jupiter->radius)/10000**/
case Saturn:
{
camera->m_target[0] = solarsystem->saturn->position[0] * distanceScale;
camera->m_target[1] = solarsystem->saturn->position[1] * distanceScale;
camera->m_target[2] = solarsystem->saturn->position[2] * distanceScale;
if (camera->distance < 8)
camera->distance = 8;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
case Uranus:
{
camera->m_target[0] = solarsystem->uranus->position[0] * distanceScale;
camera->m_target[1] = solarsystem->uranus->position[1] * distanceScale;
camera->m_target[2] = solarsystem->uranus->position[2] * distanceScale;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
case Neptune:
{
camera->m_target[0] = solarsystem->neptune->position[0] * distanceScale;
camera->m_target[1] = solarsystem->neptune->position[1] * distanceScale;
camera->m_target[2] = solarsystem->neptune->position[2] * distanceScale;
camera->m_eye[0] = camera->m_target[0] + camera->distance * cos(camera->angle_z)*cos(camera->angle_xy);
camera->m_eye[1] = camera->m_target[1] + camera->distance * cos(camera->angle_z)*sin(camera->angle_xy);
camera->m_eye[2] = camera->m_target[2] + camera->distance * sin(camera->angle_z);
camera->m_up = QVector3D::crossProduct(camera->m_eye - camera->m_target, QVector3D(0, -1, 0));
break;
}
}
}
void OpenglWidget::sun()
妄北y
- 粉丝: 2w+
- 资源: 1万+
最新资源
- Comsol 仿真微纳米结构电场诱导过程 聚合物电流体力学构图是一种独特的微米和纳米结构技术,它将电压施加到由图案模板和聚合物涂层基底组成的电极对上,电极对要么接触,要么被气隙隔开,以驱动流变聚合物的
- GAMS代码:多家庭微网能量管理与优化调度 关键词:家庭微网 能量管理 优化调度 多微网 参考文档:Optimization of Prosumer’s Flexibility Taking
- carsimsimulink联合仿真,无人驾驶基于mpc控制算法高速108km h车速下模拟跟踪五次多项式道场景,carsim2019,matlab2018
- 两电平三相光伏并网逆变器 光伏电池采用受控电流源替代 LCL滤波 电压电流双闭环控制
- MATLAB代码:电动汽车需求响应电厂 关键词:电动汽车;需求响应;电厂;竞标策略;多类电力市场 参考文档:《计及电动汽车和需求响应的多类电力市场下电厂竞标模型》 仿真平台:MATLAB 主要内容:分
- MATLAB代码:考虑V2G的光储充一体化微网多目标优化调度策略 关键词:光储充微网 电电汽车V2G 多目标优化 蓄电池优化 调度 参考文档:光伏微网下考虑V2G补偿蓄电池容量的双目标优化调度策略
- MATLAB代码:考虑潮流约束的电力系统机组组合 关键词:机组组合 电力系统优化调度 潮流约束 网络拓扑 仿真平台:MATLAB 主要内容:基于matlab平台开发的电力系统机组组合优化调度模
- MATLAB代码:CPLEX二阶锥规划考虑Wind+CB+SVG+OLTC+ESS多时段24h 关键词:二阶锥 最优潮流 SOCP 参考文档:《主动配电网多源协同运行优化研究》 仿真平台:MATLA
- yolo的原理完整版PDF
- 数组导函数转变为素组原函数
- 闭环伺服步进电机(磁编码器)全套方案 步进电机 闭环控制器 42步进电机 包含说明文档,AD工程文件,Keil源代码,固件,双主控支持 闭环步进参数: 主控芯片:航顺HK32F030C8T6(软硬件完
- PCA-LSTM多变量回归预测(Matlab) PCA降维结合LSTM神经网络预测算法,程序注释清楚,直接运行出结果 更数据集简单,直接运行即可 1.data是数据集 2.PCALSTM是程序文件
- 粒子群(PSO)、量子粒子群(QPSO)优化LSTM网络超参数,以均方差为适应度,找出一组网络超参数,解决网络设置参数盲目性的问题 可用于负荷预测,风电功率预测,光伏发电预测等时序序列,matlab
- ubuntu及TinyOS的安装PDF
- 乘用车商用车油刹制动系统计算模板,excel表格,含乘用车商用车、手刹EPB、盘式鼓式通用制动系统等;所有公式可编辑
- matlab 常用数字基带信号编码及其功率谱:单极性非归零码、双极性非归零码、单极性归零码、双极性归零码、传号差分码、空号差分码、数字双相码、密勒码、传号反转码、AMI码、HDB3码 程序注释详细
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈