Example #1
0
static void MoveCamera(OrbitingCamera &cam, fwk::GfxDevice &device, float speed) {
	auto input = device.inputState();

	if(input.isKeyPressed(InputKey::lshift)) speed *= 5.f;
	if(input.isMouseButtonPressed(InputButton::left) || input.isMouseButtonPressed(InputButton::right)) {
		float flip = input.isMouseButtonPressed(InputButton::right)? -1 : 1;

		device.grabMouse(true);
		float dx = input.mouseMove().x * flip;
		float dy = input.mouseMove().y * flip;

		if(dx) cam.Rotate(-dx * 0.01);
		if(dy) cam.RotateY(dy * 0.01);
	}
	else {
		device.grabMouse(false);
	}
		
	if(input.isKeyPressed(InputKey::left)) cam.Rotate(0.01);
	if(input.isKeyPressed(InputKey::right)) cam.Rotate(-0.01);
	
	float zoom = 0;
	zoom = input.mouseWheelMove() * 4;
	if(input.isKeyPressed('R')) zoom = 1;
	if(input.isKeyPressed('F')) zoom = -1;

	if(zoom)
		cam.Zoom(zoom * speed);

	Vec3f move(0, 0, 0);
	Camera tcam = (Camera)cam;

	if(input.isKeyPressed('w')) move += tcam.front;
	if(input.isKeyPressed('s')) move -= tcam.front;
	if(input.isKeyPressed('a')) move -= tcam.right;
	if(input.isKeyPressed('d')) move += tcam.right;

	cam.target += move * speed;
	cam.pos += move * speed;
}
Example #2
0
static void MoveCamera(OrbitingCamera &cam, GLWindow &window, float speed) {
	if(window.Key(Key_lshift)) speed *= 5.f;
	if(window.MouseKey(0) || window.MouseKey(1)) {
		float flip = window.MouseKey(1)? -1 : 1;

		window.GrabMouse(1);
		float dx = window.MouseMove().x * flip;
		float dy = window.MouseMove().y * flip;

		if(dx) cam.Rotate(-dx * 0.005);
		if(dy) cam.RotateY(dy * 0.005);
	}
	else window.GrabMouse(0);
		
	if(window.Key(Key_left)) cam.Rotate(0.01);
	if(window.Key(Key_right)) cam.Rotate(-0.01);
	
	float zoom = 0;
	zoom = window.MouseMove().z;
	if(window.Key('R')) zoom = 1;
	if(window.Key('F')) zoom = -1;

	if(zoom)
		cam.Zoom(zoom * speed);

	Vec3f move(0, 0, 0);
	Camera tcam = (Camera)cam;

	if(window.Key('W')) move += tcam.front;
	if(window.Key('S')) move -= tcam.front;
	if(window.Key('A')) move -= tcam.right;
	if(window.Key('D')) move += tcam.right;

	cam.target += move * speed;
	cam.pos += move * speed;
}