Exemplo n.º 1
0
void Pipeline::offsetOrientation(ObjectTransforms::TransformType ttype, const glm::vec3 &axis, const float fAngDeg)
{
	if (ttype == ObjectTransforms::T_MODEL)
		offsetOrientation(worldTransforms.model().params().orientation, axis, fAngDeg);
	else if (ttype == ObjectTransforms::T_VIEW)
		offsetOrientation(worldTransforms.view().params().orientation, axis, fAngDeg);
	else if (ttype == ObjectTransforms::T_EXTRA)
		offsetOrientation(worldTransforms.model().params().orientation, axis, fAngDeg);
}
Exemplo n.º 2
0
void Camera::onMouseMove(int x, int y)
{
	if(m_isMouseDown)
	{
		float dx = (x - m_mx);
		float dy = (y - m_my);
		m_mx = x; 
		m_my = y; 
		offsetOrientation(dx, dy);
	}
}
void FirstPersonCamera::update(double elapsedTime)
{
	glm::vec2 movementAmount = glm::vec2(0.0f);
	bool changedPosition = false;
    
	if (mInput.isKeyDown(GLFW_KEY_W)) {
        movementAmount.y = 1.0f;
		changedPosition = true;
    }

    if (mInput.isKeyDown(GLFW_KEY_S)) {
        movementAmount.y = -1.0f;
		changedPosition = true;
    }

    if (mInput.isKeyDown(GLFW_KEY_A)) {
        movementAmount.x = 1.0f;
		changedPosition = true;
    }

	if (mInput.isKeyDown(GLFW_KEY_D)) {
        movementAmount.x = -1.0f;
		changedPosition = true;
    }

	const float fElapsedTime = static_cast<float>(elapsedTime);
	bool changedOrientation = false;
	glm::vec2 mouseDelta(0.0f);

	//if (mInput.isMouseButtonDown(GLFW_MOUSE_BUTTON_LEFT)) {
		const glm::vec2 mousePos = mInput.getMousePosition();
		mouseDelta = mousePos - mPrevMousePos;
		mPrevMousePos = mousePos;
		changedOrientation = (mouseDelta != glm::vec2(0.0f));
	//}

	if (changedOrientation) {
		const float pitch = mouseDelta.y * mMouseSensitivity * mRotationRate * fElapsedTime;
		const float yaw = -mouseDelta.x * mMouseSensitivity * mRotationRate * fElapsedTime;
		offsetOrientation(pitch, yaw);
	}

	if (changedPosition) {
		glm::vec2 movement = movementAmount * mMovementRate * fElapsedTime;
		glm::vec3 strafe = getRight() * movement.x;
		glm::vec3 forward = getForward() * movement.y;
		setPosition(getPosition() + strafe + forward);
	}

	Camera::update(elapsedTime);
}
Exemplo n.º 4
0
void GlCamera::move() {
       if (motionState.getForward()) {
               offsetPosition(0.1f * forward());
       }

       if (motionState.getBackward()) {
               offsetPosition(0.1f * -forward());
       }

       if (motionState.getLeft()) {
               offsetPosition(0.1f * -right());
       }

       if (motionState.getRight()) {
               offsetPosition(0.1f * right());
       }
       offsetOrientation(motionState.getPitch(), motionState.getYaw());
}
//-----------------------------------------------------------------------------------------------
void FirstPersonControllerStrategy::UpdateOrientationFromBlendedPosition( const Vector3f& blendedPosition )
{
	Vector3f pointToLookAt = ( m_lookAtdistance * GetNonOffsetForwardViewVector() ) - ( m_pose.m_position - blendedPosition );

	float rotationZ = 0.f;
	float rotationY = 0.f;

	rotationZ = atan2( pointToLookAt.y, pointToLookAt.x );

	if( m_pose.m_orientation.yawDegreesAboutZ < 0.f && rotationZ > 0.f )
	{
		rotationZ = rotationZ - TWO_PI;
	}
	else if( m_pose.m_orientation.yawDegreesAboutZ > 0.f && rotationZ < 0.f )
	{
		rotationZ = TWO_PI + rotationZ;
	}

	if( pointToLookAt.x >= 0 )
	{
		rotationY = -atan2( pointToLookAt.z * cos( rotationZ ), pointToLookAt.x  );
	}
	else
	{
		rotationY = atan2( pointToLookAt.z * cos( rotationZ ), -pointToLookAt.x  );
	}

	rotationY = ConvertRadiansToDegrees( rotationY );
	rotationZ = ConvertRadiansToDegrees( rotationZ );

	EulerAnglesf offsetOrientation( EulerAnglesf::Zero() );

	offsetOrientation.pitchDegreesAboutY = rotationY;
	offsetOrientation.yawDegreesAboutZ   = rotationZ;

	offsetOrientation = m_pose.m_orientation - offsetOrientation;
	offsetOrientation = offsetOrientation * m_focusedOnPointAmount;

	m_pose.m_orientation += offsetOrientation;
}
Exemplo n.º 6
0
bool Pipeline::onKeyboard(INPUT_KEY key)
{
	camera.onKeyboard(key);
	
	bool retVal = true;
	switch (key)
	{
	
		// Camera orientation model
		case INPUT_KEY_SPACE:
			{
				int& orientationModel = camera.getOrientationModel();
				orientationModel += 1;
				orientationModel = orientationModel % NUM_OF_OFFSET_RELATIVES;
				{
					switch (orientationModel)
					{
						case MODEL_RELATIVE: printf("Model Relative\n"); break;
						case WORLD_RELATIVE: printf("World Relative\n"); break;
						case CAMERA_RELATIVE: printf("Camera Relative\n"); break;
					}
				}
			}
			break;

		case INPUT_KEY_W:
			offsetOrientation(ObjectTransforms::T_VIEW, glm::vec3(1.0f, 0.0f, 0.0f), SMALL_ANGLE_INCREMENT);
			break;
		case INPUT_KEY_S:
			offsetOrientation(ObjectTransforms::T_VIEW, glm::vec3(1.0f, 0.0f, 0.0f), -SMALL_ANGLE_INCREMENT);
			break;
		case INPUT_KEY_A:
			offsetOrientation(ObjectTransforms::T_VIEW, glm::vec3(0.0f, 0.0f, 1.0f), SMALL_ANGLE_INCREMENT);
			break;
		case INPUT_KEY_D:
			offsetOrientation(ObjectTransforms::T_VIEW, glm::vec3(0.0f, 0.0f, 1.0f), -SMALL_ANGLE_INCREMENT);
			break;
		case INPUT_KEY_Q:
			offsetOrientation(ObjectTransforms::T_VIEW, glm::vec3(0.0f, 1.0f, 0.0f), SMALL_ANGLE_INCREMENT);
			break;
		case INPUT_KEY_E:
			offsetOrientation(ObjectTransforms::T_VIEW, glm::vec3(0.0f, 1.0f, 0.0f), -SMALL_ANGLE_INCREMENT);
			break;
	
		case INPUT_KEY_F1:	//Switch between mono and stereoscopic display
			{
				eDisplayOption = static_cast<DisplayOptions>(eDisplayOption + 1);
				eDisplayOption = static_cast<DisplayOptions>(eDisplayOption % NUM_OF_DISPLAY_OPTIONS); // Loop through all sketch drawing options
		
				switch (eDisplayOption)
				{
					case MONO: printf("MONO: Singular projection\n"); break;
					case STEREO_SIDE_BY_SIDE: printf("STEREO_SIDE_BY_SIDE: Draw using half the horizontal resolution for each eye\n"); break;
					case STEREO_TOP_AND_BOTTOM: printf("STEREO_TOP_AND_BOTTOM: Draw using half the vertical resolution for each eye\n"); break;
					case STEREO_QUAD_BUFFER: printf("STEREO_QUAD_BUFFER: OpenGL - Quad buffered Stereo\n"); break;
				}
			}
			break;

		default:
			retVal = false;
	}

	// Depth maps from [fWindowZNear+epsilon, fWindowZFar-epsilon] in Window Space coords to [-1, 1] in NDC, Normalized Device Coordinates.
	const float epsilon = 1e-8f; // Avoid positions at +/- 'infinity' = where camera near plane/far plane are.
	fWindowDepthValue = glm::clamp(fWindowDepthValue, fWindowZNear + epsilon, fWindowZFar - epsilon);

	return retVal;
}