MFC opengl 太阳

// 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

// 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值