1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "GLUTSceneContainer.h"
#include "AbstractScene.h"

#include "stdlib.h"
#include "stdio.h"
#include "string.h"

#if !defined(GLUT_WHEEL_UP)
#  define GLUT_WHEEL_UP   3
#  define GLUT_WHEEL_DOWN 4
#endif

//static int detectorX ;
//static int detectorY ;
static int W_WIDTH;
static int W_HEIGHT;
static double W_ds;
#include <iostream>
using namespace  std;
static bool  IsNeedR=true;
GLUTSceneContainer* GLUTSceneContainer::GetMainWindow(int *wh, double ds)
{
	W_ds=ds;
	W_WIDTH=wh[0];
	W_HEIGHT=wh[1];
	//detectorX=w*W_ds;
	//detectorY=h*W_ds;
	if (!s_pMainWindow)
		s_pMainWindow=new GLUTSceneContainer;
	return s_pMainWindow;
}

void GLUTSceneContainer::SetSize(int width,int height)
{
	m_Size[0]=width;
	m_Size[1]=height;
//


}

void GLUTSceneContainer::GetSize(int &width,int &height) const
{
	width=m_Size[0];
	height=m_Size[1];

	
}

void GLUTSceneContainer::SetTitle(const char* title)
{
	strcpy(m_Title,title);
}

const char* GLUTSceneContainer::GetTitle() const
{
	return m_Title;
}

void GLUTSceneContainer::SetScene(AbstractScene* scene)
{
	m_Scene=scene;
}

AbstractScene* GLUTSceneContainer::GetScene() const
{
	return m_Scene;
}

void GLUTSceneContainer::Create(int posX,int posY)
{
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
	glutInitWindowPosition(posX,posY);
	glutInitWindowSize(W_WIDTH,W_HEIGHT);
	m_WindowID=glutCreateWindow(m_Title);
	if (m_FullScreen) glutFullScreen();
	glutDisplayFunc(s_display);
//	glutKeyboardFunc(s_keyboard);
	glutSpecialFunc(s_speckey);
	glutReshapeFunc(s_reshape);
//	glutMouseFunc(s_mouse);
	glutMotionFunc(s_motion);
	
	if (m_Scene) m_Scene->Init();
	glutMainLoop();
}

void GLUTSceneContainer::s_display()
{
	if(IsNeedR)
	{
	if (s_pMainWindow->m_Scene) s_pMainWindow->m_Scene->Render();
	glutSwapBuffers();
	IsNeedR=false;
	}
}



void GLUTSceneContainer::s_speckey(GLint key, GLint x, GLint y)
{
	bool redis=false;
	if (s_pMainWindow->m_Scene) s_pMainWindow->m_Scene->Speckey(key,x,y,redis);
	if (redis) glutPostRedisplay(); 
}

void GLUTSceneContainer::s_reshape(int width, int height)
{

	if (s_pMainWindow->m_Scene) s_pMainWindow->m_Scene->Resize(W_WIDTH,W_HEIGHT); 
	
	glutPostRedisplay();
}



void GLUTSceneContainer::s_motion(int x, int y)
{
	bool redis=false;
	if (s_pMainWindow->m_Scene) s_pMainWindow->m_Scene->MouseMove(x,y,redis);
	if (redis) glutPostRedisplay();
}

GLUTSceneContainer::GLUTSceneContainer()
{
	
	m_Size[0]=W_WIDTH;
	m_Size[1]=W_HEIGHT;
	m_Title[0]=0;
	m_FullScreen=false;
	m_WindowID=0;
	m_Scene=0;
}

GLUTSceneContainer::~GLUTSceneContainer()
{
}

void GLUTSceneContainer::Exit(int i)
{
	if (s_pMainWindow) delete s_pMainWindow;
	exit(i);
}

GLUTSceneContainer* GLUTSceneContainer::s_pMainWindow=0;