00001
00002
00003
00004
00005
00006
00007 #include <QMouseEvent>
00008
00009 #include "glut.h"
00010 #pragma comment(lib,"glut32.lib")
00011 #include "CLight.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 CLight::CLight(float radius) : IInputHandler()
00023 {
00024 this->radius = radius;
00025
00026 elevation = MY_PI/4.0;
00027 azimuth = MY_PI/4.0;
00028 m_pos.m_Y = radius * sin(elevation);
00029 m_pos.m_X = radius * cos(azimuth) * cos(elevation);
00030 m_pos.m_Z = radius * sin(azimuth) * cos(elevation);
00031 m_resetpos = m_pos;
00032
00033 color = CVector3f(1.0);
00034 bHeadLight = false;
00035 bLocalViewer = true;
00036 bEnabled = false;
00037 bShow = false;
00038 doOrbit = false;
00039
00040 Reset();
00041 }
00042
00043
00044 CLight::~CLight(){}
00045
00046
00047 void CLight::Reset()
00048 {
00049 m_restorepos = m_resetpos;
00050 }
00051
00052
00053 void CLight::SetHeadLight( bool tf )
00054 {
00055 if(tf){
00056 m_pos = CVector3f(0,0,0);
00057 }else{
00058 m_pos = m_restorepos;
00059 }
00060 bHeadLight = tf;
00061 hasChanged = true;
00062 }
00063
00064
00065 void CLight::Draw()
00066 {
00067 glPushMatrix();
00068 glTranslatef(m_pos.m_X,m_pos.m_Y,-m_pos.m_Z);
00069 glBegin(GL_LINES);
00070 glVertex3f(0.0,0.0,0.0);
00071 glVertex3f(-m_pos.m_X/1.2,-m_pos.m_Y/1.2,m_pos.m_Z/1.2);
00072
00073 glutSolidSphere(0.05,20,20);
00074 glPopMatrix();
00075 }
00076
00077
00078
00079
00080
00081 bool CLight::OnMouseMove(sdword sdwX, sdword sdwY, sdword sdwZ){
00082
00083 if(doOrbit)
00084 {
00085
00086 m_pos = m_restorepos;
00087 azimuth -= (sdwX * 0.2)*MY_PI/180.0;
00088 elevation += (sdwY * 0.2)*MY_PI/180.0;
00089 m_pos.m_Y = radius * sin(elevation);
00090 m_pos.m_X = radius * cos(azimuth) * cos(elevation);
00091 m_pos.m_Z = radius * sin(azimuth) * cos(elevation);
00092 m_restorepos = m_pos;
00093 }
00094 hasChanged = true;
00095 return true;
00096 }
00097
00098 bool CLight::OnMouseKeyDown(byte bKey)
00099 {
00100 doOrbit = true;
00101 return true;
00102 }
00103
00104 bool CLight::OnMouseKeyUp(byte bKey)
00105 {
00106 doOrbit = false;
00107 return true;
00108 }