示例#1
0
文件: Scene.cpp 项目: etcwilde/Cloth
Scene::Scene() :
        mDragging(false),
        mPaused(true),
        mPrevTime(0.0),
        _movementType(Scene::MoveType::CAMERA),
        _viewing(Scene::ViewType::USER_VIEW),
        mSplineCam(mSpline),
        mCloth(Cloth(8, 8))
{
        glDepthFunc(GL_LEQUAL);
        glEnable(GL_DEPTH_TEST);
        glShadeModel(GL_FLAT);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
        glDisable(GL_CULL_FACE);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
示例#2
0
void normal_keys(unsigned char key, int x, int y) {

	switch(key) {
	case 's':
		cout<<"s pressed"<<endl;
		cout<<"shade type is" << shade_type;
		if (shade_type == GL_SMOOTH) shade_type = GL_FLAT;
		else if (shade_type == GL_FLAT) shade_type = SHADE_NORMAL;
		else if (shade_type == SHADE_NORMAL) shade_type = GL_SMOOTH;
		else cout<< "shade type error" <<endl;

		myShader.updateShadeType(shade_type);
		break;
	case 'f':
		if (fill_type == GL_LINE) fill_type = GL_POINT;
		else if (fill_type == GL_POINT) fill_type = GL_FILL;
		else if (fill_type == GL_FILL) fill_type = GL_LINE;
		else cout << "fill type error" << endl;

		myShader.updateFillType(fill_type);
		break;
	case 'q':
		frozen_toggle = !frozen_toggle;
		break;
	case 'l':
		follow_cam = !follow_cam;
		break;

	case PLUS:
		zoom += ZOOM_STEP;
		break;
	case MINUS:
		zoom -= ZOOM_STEP;
		break;
	case 'r':

		if (!leftMouseDown && !rightMouseDown) myCloth = Cloth(width, height, step);
		break;
	case 'W':
		windmod += .05f;
		break;
	case 'w':
		windmod -= .05f;
		break;
	case 'd':
		if (windtog) wind = glm::vec3(0);
		windtog = !windtog;
		break;
	case 'b':
		myBall.radius -= .3334;
		break;
	case 'B':
		myBall.radius += .3334;
		break;

	case 'm':
		GLint viewport[4];
		glGetIntegerv(GL_VIEWPORT, viewport);

		GLdouble modelview[16];
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview);

		GLdouble projection[16];
		glGetDoublev(GL_PROJECTION_MATRIX, projection);

		POINT mouse;
		GetCursorPos(&mouse);

		GLfloat winX, winY, winZ;

		winX = (float)mouse.x;
		winY = (float)mouse.y;
		winY = (float)viewport[3] - winY;

		glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);

		GLdouble posX, posY, posZ;

		gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

		myBall = Ball(4, glm::vec3(posX, posY, posZ));



	}

}