void viewInfo::SetGlViewTo() const
{
	// this->GetAnchor()
	// in OpenGL, up is +Y and look is -Z (left is +X)
	// in my conventions, up is +Z and look is +X (left is +Y)
	mdsVector<3, double> eyePos = GetPosition();
	mdsVector<3, double> upDir = GetUpDir();
	// glTranslated(-viewPos.x(), -viewPos.y(), -viewPos.z());
	
	gluLookAt(GetPosition()[0], GetPosition()[1], GetPosition()[2],
		GetAnchor()[0], GetAnchor()[1], GetAnchor()[2],
		GetUpDir()[0], GetUpDir()[1], GetUpDir()[2]);

	// glTranslated(-viewPos.y(), -viewPos.z(), viewPos.x());
	// mdsVector<3, double> 
	// glTranslated(viewPos.x(), viewPos.y(), viewPos.z());
	// glTranslated(0.0, 0.0, m_viewOffset[0]);

}
Example #2
0
void Camera::LookAt(glm::vec3 const & eye, glm::vec3 const & center)
{
	m_scale = glm::vec3(1.0f);
	m_position = eye;

	glm::vec3 vdir = center-eye;
		
	float rotY = (vdir.x == 0.0f && vdir.z == 0.0f) ? 0.0f : AngleBetween(glm::vec2(0.0f,-1.0f),glm::vec2(vdir.x, vdir.z));  vdir = glm::vec3(glm::rotateY(glm::vec4(vdir,1.0f),-rotY));
	float rotX = (vdir.x == 0.0f && vdir.y == 0.0f) ? 0.0f : AngleBetween(glm::vec2(0.0f, 1.0f),glm::vec2(vdir.y, vdir.z));
	float rotZ = 0.0f;

	m_rotation = -glm::vec3(rotX,rotY,rotZ);

	UpdateModelMatrix();

	if (GetUpDir().y < 0) m_rotation += glm::vec3(180.0f,0,0);
}