Skip to content

Commit

Permalink
BaseApplication: add the a CameraInputProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Aug 9, 2023
1 parent b398564 commit 83ba1fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*/
package com.github.stephengold.vsport;

import com.github.stephengold.vsport.input.CameraInputProcessor;
import com.github.stephengold.vsport.input.InputManager;
import com.github.stephengold.vsport.input.InputProcessor;
import java.io.PrintStream;
Expand Down Expand Up @@ -140,6 +141,10 @@ public abstract class BaseApplication {
* not created
*/
private static Callback debugMessengerCallback;
/**
* process user input for the camera
*/
private static CameraInputProcessor cameraInputProcessor;
/**
* resources that depend on the swap chain
*/
Expand Down Expand Up @@ -387,6 +392,16 @@ public static Camera getCamera() {
return result;
}

/**
* Access the camera's input processor.
*
* @return the pre-existing instance (not null)
*/
public static CameraInputProcessor getCameraInputProcessor() {
assert cameraInputProcessor != null;
return cameraInputProcessor;
}

/**
* Access the graphics queue for commands.
*
Expand Down Expand Up @@ -608,6 +623,9 @@ public void start(
int appVersion = VK10.VK_MAKE_VERSION(appMajor, appMinor, appPatch);
initializeVulkan(appName, appVersion);

cameraInputProcessor = new CameraInputProcessor(windowHandle);
inputManager.add(cameraInputProcessor);

inputManager.add(new InputProcessor() {
@Override
public void onKeyboard(int keyId, boolean isPress) {
Expand Down Expand Up @@ -1774,6 +1792,7 @@ private void selectPhysicalDevice() {
private void updateBase() {
render();
GLFW.glfwPollEvents();
cameraInputProcessor.update();

Frame frame = inFlightFrames[currentFrameIndex];
renderFrame(frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void setRotationRate(float newRate) {
/**
* Poll each camera-movement key and move the camera accordingly.
*/
void update() {
public void update() {
int forwardSignal = 0;
int rightSignal = 0;
int upSignal = 0;
Expand Down

0 comments on commit 83ba1fa

Please sign in to comment.