Esempio n. 1
0
void
Camera::strafeCamera(float speed)
{
	// Strafing is quite simple if you understand what the cross product is.
	// If you have 2 vectors (say the up vVector and the view vVector) you can
	// use the cross product formula to get a vVector that is 90 degrees from the 2 vectors.
	// For a better explanation on how this works, check out the OpenGL "Normals" tutorial at our site.
	// In our new Update() function, we set the strafing vector (m_vStrafe).  Due
	// to the fact that we need this vector for many things including the strafing
	// movement and camera rotation (up and down), we just calculate it once.
	//
	// Like our MoveCamera() function, we add the strafing vector to our current position
	// and view.  It's as simple as that.  It has already been calculated in Update().

	V3f vStrafe = V3f::cross(mView - mEye, mUp);
	vStrafe.normalize();

	// Add the strafe vector to our position
	*mEye.x += vStrafe.getX() * speed;
	*mEye.z += vStrafe.getZ() * speed;

	// Add the strafe vector to our view
	*mView.x += vStrafe.getX() * speed;
	*mView.z += vStrafe.getZ() * speed;
//	applyToGL();
}
Esempio n. 2
0
void
Camera::rotateView(float angle, const V3f& vec)
{
	rotateView(angle, vec.getX(), vec.getY(), vec.getZ());
}