Example #1
0
void Camera::RotateByY( float angle )
{
	Vec3 dir = _pos - _at;
	dir.rotatexzBy(angle, Vec3(0, 0, 0));
	_pos = _at + dir;
	UpdateViewProj();
}
Example #2
0
void Camera::Right( float displacement )
{
	Vec3 dir = _at - _pos;
	Vec3 right = Vec3(dir.x, 0, dir.z);
	right.normalize();
	right.rotatexzBy(-90, Vec3(0, 0, 0));
	_pos += right * displacement;
	_at = _pos + dir;
	UpdateViewProj();
}
Example #3
0
void Camera::Pitch( float angle )
{
	Vec3 dir = _at - _pos;
	Vec3 axis = dir.cross(Vec3(0, 1, 0));
	axis.normalize();
	Quat q;
	q.FromAxisAngle(axis, angle * QUAT_PI / 360.f);
	q.ToMatrix().TransformVec3(dir.x, dir.y, dir.z);
	_at = _pos + dir;

	UpdateViewProj();
}
Example #4
0
void Camera::Yaw(float angle) {
	Vec3 dir = _at - _pos;
	Quat q;
	q.FromAxisAngle(Vec3(0.f, 1.0f, 0.f), angle * QUAT_PI / 360.f);
	q.ToMatrix().TransformVec3(dir.x, dir.y, dir.z);
	_at = _pos + dir;

	//Sys_Printf("%f %f %f \n", _dir.x, _dir.y, _dir.z);

	//_at.rotatexzBy(angle, vec3(_pos.x, _pos.y, _pos.z));
	//Sys_Printf("%f %f %f \n", dir.x, dir.y, dir.z);
	UpdateViewProj();
}
void FlyCamera::update(float dt)
{
	GLFWwindow* curr_window = glfwGetCurrentContext();

	if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_W) == GLFW_PRESS)
	{
		m_world[3] -= m_world[2] * m_speed * dt; //forwards
	}
	if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_S) == GLFW_PRESS)
	{
		m_world[3] += m_world[2] * m_speed * dt; //backwards
	}
	if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_A) == GLFW_PRESS)
	{
		m_world[3] -= m_world[0] * m_speed * dt; //left
	}
	if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_D) == GLFW_PRESS)
	{
		m_world[3] += m_world[0] * m_speed * dt; //right
	}
	if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_Q) == GLFW_PRESS)
	{
		m_world[3] += m_world[1] * m_speed * dt; //up
	}
	if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_E) == GLFW_PRESS)
	{
		m_world[3] -= m_world[1] * m_speed * dt; //down
	}

	m_world[3][3] = 1;

	
	double x_delta, y_delta;

	
	if (glfwGetMouseButton(curr_window, 1))
	{
		glfwGetCursorPos(curr_window, &x_delta, &y_delta);
		glfwSetCursorPos(curr_window, 1280.f / 2.f, 720.f / 2.f);

		x_delta -= (1280.f / 2.f);
		y_delta -= (720.f / 2.f);

		x_delta /= (1280.f / 2.f);
		y_delta /= (720.f / 2.f);

		x_delta *= -0.5f;
		y_delta *= -0.5f;


		vec3 camera_right = (vec3)m_world[0];

		mat4 yaw = glm::rotate((float)x_delta, vec3(0, 1, 0));
		mat4 pitch = glm::rotate((float)y_delta, camera_right);
		mat4 rot = yaw * pitch;

		m_world[0] = rot * m_world[0];
		m_world[1] = rot * m_world[1];
		m_world[2] = rot * m_world[2];

	}

	m_view = glm::inverse(m_world);
	UpdateViewProj();

}
void Camera::setPosition(vec3 pos)
{
	m_world[3] = vec4(pos, 1);
	m_view = glm::inverse(m_world);
	UpdateViewProj();
}
void Camera::setLookAt(vec3 pos, vec3 target, vec3 up)
{
	m_view = glm::lookAt(pos, target, up);
	m_world = glm::inverse(m_view);
	UpdateViewProj();
}
void Camera::setPerspective(float FoV, float aspectRatio, float nearView, float farView)
{
	m_proj = glm::perspective(FoV, aspectRatio, nearView, farView);
	UpdateViewProj();
}
Example #9
0
void Camera::RotateByAxis( Vec3 axis, float angle ) {
	Quat q;
	q.FromAxisAngle(axis, angle * QUAT_PI / 360.f);
	q.ToMatrix().TransformVec3(_pos.x, _pos.y, _pos.z);
	UpdateViewProj();
}
Example #10
0
void Camera::Setup3DCamera(int width, int height) {
	_matProj.BuildPerspectiveProjection(PI / 3, float(width)/(height), 0.1f, 800.f);
	_pos.set(0.f, 0.f, 1.f);
	UpdateViewProj();
}
Example #11
0
void Camera::LookAt( float x, float y, float z )
{
	_at.set(x, y, z);
	UpdateViewProj();
}