// MySolarsysView.h : interface of the CMySolarsysView class
//
/
#if !defined(AFX_MYSDOPENGLVIEW_H__75C5AAEC_37B0_4A8B_9132_9A0C663F6DDC__INCLUDED_)
#define AFX_MYSDOPENGLVIEW_H__75C5AAEC_37B0_4A8B_9132_9A0C663F6DDC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Textures.h"
#define MAX_NO_TEXTURES 9
#define PI 3.141592654
#define DEG2RAD(angle) angle * (PI / 180) // 将角度转换为弧度
#define ROTATION_SPEED 10 // 此参数定义一步相当于几分钟
#define MERCURY 0
#define VENUS 1
#define EARTH 2
#define MARS 3
#define JUPITER 4
#define SATURN 5
#define URANUS 6
#define NEPTUNE 7
#define PLUTO 8
#define NUM_PLANETS 9
class CPlanet
{
public:
float m_size, m_sections;
float m_posX, m_posY, m_posZ;
float m_SolarAngle, m_OwnAxisAngle;
int m_TextureID;
float m_SolarT, m_selfT; // 公转和自转周期,单位:天
public:
void SetPara(float size, float sections, float posX, float posY, float posZ, float SolarAngle, float OwnAxisAngle, int TextureID, float selfT, float SolarT)
{
m_size = size, m_sections = sections;
m_posX = posX, m_posY = posY, m_posZ = posZ;
m_SolarAngle = SolarAngle, m_OwnAxisAngle = OwnAxisAngle;
m_TextureID = TextureID;
m_SolarT = SolarT, m_selfT = selfT;
}
void Rotate(float time)
{ // 按给定时间调整行星位置和角度,time单位为分钟
time /= (24*60); // 转化为周期单位:天
// solar rotation
m_SolarAngle += (time/ m_SolarT) * 360*50; // 为增强视觉效果,将公转速度增加50倍
if (m_SolarAngle >= 360)
m_SolarAngle -= 360;
else if (m_SolarAngle < 0)
m_SolarAngle += 360;
// axis rotation
m_OwnAxisAngle += (time / m_selfT) * 360;
if (m_OwnAxisAngle >= 360)
m_OwnAxisAngle -= 360;
else if (m_OwnAxisAngle < 0)
m_OwnAxisAngle += 360;
}
void DrawOrbit()
{
glDisable(GL_LIGHTING);
glColor3f(0.7, 0.7, 0.7);
glBegin(GL_LINE_LOOP);
for (int i = 0; i < 360; i++)
{
glVertex3f(cos(DEG2RAD(i))*m_posZ, 0, sin(DEG2RAD(i))*m_posZ);
}
glEnd();
glEnable(GL_LIGHTING);
}
void Draw()
{
glPushMatrix();
glRotatef(m_SolarAngle, 0, -1, 0);
glTranslatef(m_posX, m_posY, m_posZ);
glRotatef(m_OwnAxisAngle, 0, -1, 0);
glRotatef(90.0, 1.0, 0.0, 0.0);
GLUquadricObj* q = gluNewQuadric();
gluQuadricDrawStyle(q, GLU_FILL);
gluQuadricNormals(q, GLU_SMOOTH);
gluQuadricTexture(q, GL_TRUE);
gluSphere(q, m_size, m_sections,m_sections);
gluDeleteQuadric(q);
glPopMatrix();
}
} ;
class CMySolarsysView : public CView
{
protected: // create from serialization only
CMySolarsysView();
DECLARE_DYNCREATE(CMySolarsysView)
// Attributes
public:
CMySolarsysDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{
{AFX_VIRTUAL(CMySolarsysView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
//
MFC opengl 太阳
最新推荐文章于 2022-11-11 23:30:00 发布