MultiShotsOpenglView::MultiShotsOpenglView(QWidget * pParent, QGLWidget* pShareWidget)
: QGLWidget(new GLC_Context(QGLFormat(QGL::SampleBuffers)), pParent, pShareWidget)
, m_GlView()
, m_World()
, m_MotionTimer()
, m_RotationVector()
, m_Camera()
, m_Angle()
, m_pOpenglView(dynamic_cast<OpenglView*>(pShareWidget))
, m_MotionStep(1)
, m_MotionLength(1000)
{

	// Set backroundImage
	m_GlView.loadBackGroundImage(":images/default_background.png");

	// Signal and slot connection
	connect(&m_MotionTimer, SIGNAL(timeout()), this, SLOT(rotateView()));

}
void keyboardCallBack(unsigned char key, int x, int y) {
	printf("Keyboard call back: key=%c, x=%d, y=%d\n", key, x, y);
	switch(key)
	{
        //fills in the front colouring
        case 'f': case 'F':
            glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
            break;
        //switches to line mode
        case 'l': case 'L':
            glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
            break;
        //toggles the grid
        case 'g': case 'G':
            lines=!lines;
            break;
        //toggles rotation
        case 'r': case 'R':
            rotating= !rotating;
            rotateView(rotating);
            break;
        //toggle jelly legs independently
        case 'j': case 'J': 
            if ( sineTimer->isStopped() )
            {
                sineTimer->start() ;
                glutIdleFunc( animate ) ;
            }
            else
            {
                sineTimer->stop() ;
                glutIdleFunc( NULL ) ;
            }
            break;
        //toggle movement independently
        case 'm': case 'M': 
            if ( movementTimer->isStopped() )
            {
                move = true;
                movementTimer->start() ;
                glutIdleFunc( animate ) ;
            }
            else
            {
                movementTimer->stop() ;
                glutIdleFunc( NULL ) ;
            }
            break;
        //toggle boddy swimming effect independently
        case 's': case 'S': 
            swimming= !swimming;
            jellySwim(swimming);
            break;
        //toggle body, legs, and movement at once
        case 'a': case 'A': 
            if ( sineTimer->isStopped() )
            {
                sineTimer->start() ;
                glutIdleFunc( animate ) ;
            }
            else
            {
                sineTimer->stop() ;
                glutIdleFunc( NULL ) ;
            }
            
            if ( movementTimer->isStopped() )
            {
                move = true;
                movementTimer->start() ;
                glutIdleFunc( animate ) ;
            }
            else
            {
                movementTimer->stop() ;
                glutIdleFunc( NULL ) ;
            }
            
            swimming= !swimming;
            jellySwim(swimming);
            break;

        //default:
            
	}
	glutPostRedisplay();
}
Esempio n. 3
0
//////////////////////////////////////////////////////////////
//
//	This function rotates the view based on a vector and angle
//
//////////////////////////////////////////////////////////////
void Camera::rotateView(float angle, Vector3 vector)
{
	rotateView(angle, vector.x, vector.y, vector.z);
}
Esempio n. 4
0
/** 用鼠标旋转摄像机 */
void Camera::setViewByMouse()
{
	POINT mousePos;									  /**< 保存当前鼠标位置 */
	int middleX = GetSystemMetrics(SM_CXSCREEN) >> 1; /**< 得到屏幕宽度的一半 */
	int middleY = GetSystemMetrics(SM_CYSCREEN) >> 1; /**< 得到屏幕高度的一半 */
	float angleY = 0.0f;							  /**< 摄像机左右旋转角度 */
	float angleZ = 0.0f;		                      /**< 摄像机上下旋转角度 */					
	static float currentRotX = 0.0f;
	
	/** 得到当前鼠标位置 */
	GetCursorPos(&mousePos);						
	ShowCursor(TRUE);
	
	/** 如果鼠标没有移动,则不用更新 */
	if( (mousePos.x == middleX) && (mousePos.y == middleY) )
		return;

	/** 设置鼠标位置在屏幕中心 */
	SetCursorPos(middleX, middleY);	
	
	/**< 得到鼠标移动方向 */
	angleY = (float)( (middleX - mousePos.x) ) / 1000.0f;		
	angleZ = (float)( (middleY - mousePos.y) ) / 1000.0f;		

    static float lastRotX = 0.0f;      /**< 用于保存旋转角度 */
 	lastRotX = currentRotX; 
	
	/** 跟踪摄像机上下旋转角度 */
	currentRotX += angleZ;
 
	///** 如果上下旋转弧度大于1.0,我们截取到1.0并旋转 */
	//if(currentRotX > 1.0f)     
	//{
	//	currentRotX = 1.0f;
	//	
	//	/** 根据保存的角度旋转方向 */
	//	if(lastRotX != 1.0f) 
	//	{
	//		/** 通过叉积找到与旋转方向垂直的向量 */
	//		Vector3 vAxis = m_View - m_Position;
	//		vAxis = vAxis.crossProduct(m_UpVector);
	//		vAxis = vAxis.normalize();
	//		
	//		///旋转
	//		rotateView( 1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z);
	//	}
	//}
	///** 如果旋转弧度小于-1.0,则也截取到-1.0并旋转 */
	//else if(currentRotX < -1.0f)
	//{
	//	currentRotX = -1.0f;
	//			
	//	if(lastRotX != -1.0f)
	//	{
	//		
	//		/** 通过叉积找到与旋转方向垂直的向量 */
	//		Vector3 vAxis = m_View - m_Position;
	//		vAxis = vAxis.crossProduct(m_UpVector);
	//		vAxis = vAxis.normalize();
	//		
	//		///旋转
	//		rotateView( -1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z);
	//	}
	//}
	///** 否则就旋转angleZ度 */
	//else 
	//{	
	//	/** 找到与旋转方向垂直向量 */
	//	Vector3 vAxis = m_View - m_Position;
	//	vAxis = vAxis.crossProduct(m_UpVector);
	//	vAxis = vAxis.normalize();
	
		///旋转
	//	rotateView(angleZ, vAxis.x, vAxis.y, vAxis.z);
	//}

	/** 总是左右旋转摄像机 */
	rotateView(angleY, 0, 1, 0);

	/** 总是上下旋转摄像机 */
	rotateView(angleZ, 1, 0, 0);
}
Esempio n. 5
0
//////////////////////////////////////////////////////////////
//
//	This function will tell the camera to be handled by the mouse
//
//////////////////////////////////////////////////////////////
void Camera::moveCameraByMouse()
{
	float angleX = 0;
	float angleY = 0;
	float currentRotationX = 0;
	float lastRotationX = 0;
	float modifier = 0;
	Vector3 axis = getAxis();

	if (moveByMouse && GAME_STATE != GAME_PAUSED)
	{
		if (joystick->isUsable())
		{
			static Vector2 pos;
			Vector2 newPos = joystick->getCoordsFromRStick();
			newPos = (newPos * joystick->sensitivity) * 5.0;
		
			float mag = joystick->getStickMagnitude(XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE);

			if ((pos.x == newPos.x && pos.y == newPos.y) || mag == 0)
			{
				return;
			}

			//	Distance from the new post and last pos
			angleX = (newPos.x - pos.x) / 100.0f;
			angleY = (newPos.y - pos.y) / 100.0f;
			
			angleY *= (invertYAxis ? -1 : 1);

			lastRotationX = currentRotationX;
			currentRotationX += mag;		
		}
		else
		{		
			POINT mousePoint;
			GetCursorPos(&mousePoint);

			if (mousePoint.x == middle.x && mousePoint.y == middle.y)
			{
				return;
			}
			
			//	Invert the mouse or not
			SetCursorPos(middle.x, middle.y);
			angleX = (middle.x - mousePoint.x) / 1000.0f;
			angleY = (middle.y - mousePoint.y) / 1000.0f;

			angleY *= (invertYAxis ? -1 : 1);
			lastRotationX = currentRotationX;
			currentRotationX += angleY;									
		}

		if (currentRotationX > 1.0f)
		{
			currentRotationX = 1.0f;

			if (lastRotationX != 1.0f)
			{				
				modifier = 1.0f - lastRotationX;
			}
		}
		else if (currentRotationX < -1.0f)
		{
			currentRotationX = -1.0f;

			if (lastRotationX != -1.0f)
			{
				modifier = -1 - lastRotationX;
			}
		}
		else
		{
			modifier = angleY;
		}

		rotateView(angleX, 0, 1, 0);
		rotateView(modifier, axis.x, axis.y, axis.z);	
	}
}
Esempio n. 6
0
void Navigation::rotateViewHorz(float angle) {
    rotateView(angle, getCamera()->getUpVector());
}
Esempio n. 7
0
// This is just for convenience since the rotation about the strafe-, the look-
// and the up-Vector are used in a lot of cases.
void Navigation::rotateViewVert(float angle) {
    rotateView(angle, getCamera()->getStrafe());
}
Esempio n. 8
0
void Navigation::rotateView(float angle, float x, float y, float z) {
    rotateView(angle, vec3(x, y, z));
}
Esempio n. 9
0
void
Camera::rotateView(float angle, const V3f& vec)
{
	rotateView(angle, vec.getX(), vec.getY(), vec.getZ());
}