Add NoclipPlayerController
This commit is contained in:
parent
e618d735e1
commit
1a6678537f
@ -2,19 +2,17 @@
|
||||
#include "ui.h"
|
||||
#include "uielements.h"
|
||||
#include "defaultplayercontroller.h"
|
||||
#include "noclipplayercontroller.h"
|
||||
#include "internal.h"
|
||||
#include "internal/ui.h"
|
||||
#include "internal/physics.h"
|
||||
|
||||
namespace kek::Defaults {
|
||||
|
||||
static DefaultPlayerController *defaultController;
|
||||
static NoclipPlayerController *noclipController;
|
||||
|
||||
static KeyBinding
|
||||
/*keyForward,
|
||||
keyBackward,
|
||||
keyLeft,
|
||||
keyRight,
|
||||
keyUp,
|
||||
keyDown,*/
|
||||
keyOptions,
|
||||
keyToggleCursorMode,
|
||||
keyToggleNoclip,
|
||||
@ -48,6 +46,7 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac
|
||||
|
||||
if(key == Input::getKeyBinding(keyToggleNoclip).key && action == GLFW_PRESS) {
|
||||
kekData.player->noclip = !kekData.player->noclip;
|
||||
kekData.player->controller = kekData.player->noclip ? (PlayerController *) noclipController : (PlayerController *) defaultController;
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,13 +111,14 @@ static void defaultMouseButtonCallback(GLFWwindow* window, int button, int actio
|
||||
}
|
||||
|
||||
void init() {
|
||||
DefaultPlayerController *controller = new DefaultPlayerController();
|
||||
controller->keyForward = Input::createKeyBinding("Forward", GLFW_KEY_W);
|
||||
controller->keyBackward = Input::createKeyBinding("Backward", GLFW_KEY_S);
|
||||
controller->keyLeft = Input::createKeyBinding("Left", GLFW_KEY_A);
|
||||
controller->keyRight = Input::createKeyBinding("Right", GLFW_KEY_D);
|
||||
controller->keyJump = Input::createKeyBinding("Up", GLFW_KEY_SPACE);
|
||||
//keyDown = Input::createKeyBinding("Down", GLFW_KEY_LEFT_CONTROL);
|
||||
defaultController = new DefaultPlayerController();
|
||||
noclipController = new NoclipPlayerController();
|
||||
defaultController->keyForward = noclipController->keyForward = Input::createKeyBinding("Forward", GLFW_KEY_W);
|
||||
defaultController->keyBackward = noclipController->keyBackward = Input::createKeyBinding("Backward", GLFW_KEY_S);
|
||||
defaultController->keyLeft = noclipController->keyLeft = Input::createKeyBinding("Left", GLFW_KEY_A);
|
||||
defaultController->keyRight = noclipController->keyRight = Input::createKeyBinding("Right", GLFW_KEY_D);
|
||||
defaultController->keyJump = noclipController->keyUp = Input::createKeyBinding("Jump", GLFW_KEY_SPACE);
|
||||
noclipController->keyDown = Input::createKeyBinding("Down", GLFW_KEY_LEFT_CONTROL);
|
||||
keyOptions = Input::createKeyBinding("Options", GLFW_KEY_Q);
|
||||
keyToggleCursorMode = Input::createKeyBinding("Toggle Cursor Mode", GLFW_KEY_TAB);
|
||||
keyToggleNoclip = Input::createKeyBinding("Toggle Noclip", GLFW_KEY_N);
|
||||
@ -158,7 +158,7 @@ void init() {
|
||||
kekData.player->physics = new PlayerPhysicsObjectData();
|
||||
kekData.player->physics->body = body;
|
||||
kekData.player->moveTo(glm::vec3(5,10,0));
|
||||
kekData.player->controller = controller;
|
||||
kekData.player->controller = defaultController;
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
|
@ -38,15 +38,9 @@ void step(float deltaT) {
|
||||
}
|
||||
}
|
||||
|
||||
//kekData.player->physics->jumpCollider->getWorldTransform().setOrigin(Physics::fromGLM(kekData.player->getFootPosition() + glm::vec3(0, KEK_PLAYER_RADIUS / 2, 0)));
|
||||
|
||||
kekData.physics->world->stepSimulation(deltaT, 100);
|
||||
|
||||
//kekData.player->onGround = kekData.player->physics->jumpCollider->getNumOverlappingObjects() > 1; // TODO: improve
|
||||
|
||||
if(!kekData.player->noclip) {
|
||||
kekData.activeCamera->moveTo(kekData.player->getEyePosition());
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 toGLM(btVector3 vec) {
|
||||
|
@ -135,7 +135,7 @@ void DefaultPlayerController::update() {
|
||||
move += direction;
|
||||
}
|
||||
|
||||
kekData.player->controller->move(move * (kekData.lastFrameTime));
|
||||
this->move(move * kekData.lastFrameTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
53
src/kekengine/cpp/player/noclipplayercontroller.cpp
Normal file
53
src/kekengine/cpp/player/noclipplayercontroller.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "noclipplayercontroller.h"
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
namespace kek {
|
||||
|
||||
NoclipPlayerController::NoclipPlayerController() {
|
||||
|
||||
}
|
||||
|
||||
NoclipPlayerController::~NoclipPlayerController() {
|
||||
|
||||
}
|
||||
|
||||
glm::vec3 NoclipPlayerController::move(glm::vec3 movement) {
|
||||
kekData.player->translate(movement);
|
||||
return movement;
|
||||
}
|
||||
|
||||
void NoclipPlayerController::update() {
|
||||
glm::vec3 direction = glm::vec3(0);
|
||||
|
||||
if(Input::getKeyState(keyForward) == GLFW_PRESS) {
|
||||
direction += kekData.activeCamera->direction;
|
||||
}
|
||||
|
||||
if(Input::getKeyState(keyBackward) == GLFW_PRESS) {
|
||||
direction += -kekData.activeCamera->direction;
|
||||
}
|
||||
|
||||
if(Input::getKeyState(keyLeft) == GLFW_PRESS) {
|
||||
direction += -glm::normalize(glm::cross(kekData.activeCamera->direction, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
}
|
||||
|
||||
if(Input::getKeyState(keyRight) == GLFW_PRESS) {
|
||||
direction += glm::normalize(glm::cross(kekData.activeCamera->direction, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
}
|
||||
|
||||
if(Input::getKeyState(keyUp) == GLFW_PRESS) {
|
||||
direction += glm::vec3(0, 1, 0);
|
||||
}
|
||||
|
||||
if(Input::getKeyState(keyDown) == GLFW_PRESS) {
|
||||
direction += glm::vec3(0, -1, 0);
|
||||
}
|
||||
|
||||
if(glm::length2(direction) > 0) {
|
||||
direction = glm::normalize(direction) * noclipSpeed * kekData.lastFrameTime;
|
||||
move(direction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
30
src/kekengine/include/noclipplayercontroller.h
Normal file
30
src/kekengine/include/noclipplayercontroller.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "playercontroller.h"
|
||||
#include "input.h"
|
||||
|
||||
namespace kek {
|
||||
|
||||
class NoclipPlayerController: public PlayerController {
|
||||
|
||||
public:
|
||||
float noclipSpeed = 6;
|
||||
|
||||
KeyBinding keyForward = KEK_INVALID_ID;
|
||||
KeyBinding keyBackward = KEK_INVALID_ID;
|
||||
KeyBinding keyLeft = KEK_INVALID_ID;
|
||||
KeyBinding keyRight = KEK_INVALID_ID;
|
||||
KeyBinding keyUp = KEK_INVALID_ID;
|
||||
KeyBinding keyDown = KEK_INVALID_ID;
|
||||
|
||||
glm::vec3 velocity = glm::vec3(0);
|
||||
|
||||
NoclipPlayerController();
|
||||
virtual ~NoclipPlayerController();
|
||||
|
||||
virtual glm::vec3 move(glm::vec3 movement);
|
||||
virtual void update();
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -89,14 +89,14 @@ int main(int argc, char **argv) {
|
||||
test3->moveTo(glm::vec3(2, 1, 2));
|
||||
scene->addObject(test3);
|
||||
|
||||
/*for(int i = 0; i < 10; i++) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
GameObject *test2 = new GameObject();
|
||||
btCollisionShape *shape = new btBoxShape(btVector3(1,1,1));
|
||||
test2->addPhysics(shape, 10);
|
||||
test2->addMesh(ObjParser::loadMesh("object/cube_colored/Cube.obj"));
|
||||
test2->moveTo(glm::vec3(1.0f, 5.0f, 3 * i));
|
||||
scene->addObject(test2);
|
||||
}*/
|
||||
}
|
||||
|
||||
PointLight *light = new PointLight(glm::vec3(1), 1, 0, 0.1);
|
||||
light->moveTo(glm::vec3(0,1,0));
|
||||
|
@ -6,12 +6,15 @@ set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||
set(CMAKE_C_FLAGS -w)
|
||||
set(CMAKE_CXX_FLAGS -w)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32/)
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
||||
set(CMAKE_PREFIX_PATH /usr/x86_64-w64-mingw32)
|
||||
set(ENV{PKG_CONFIG_PATH} "${CMAKE_PREFIX_PATH}/sys-root/mingw/lib/pkgconfig/")
|
||||
link_directories(windows/lib/)
|
||||
include_directories(windows/include/)
|
||||
link_directories(dependencies/openvr/bin/win64)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
Loading…
Reference in New Issue
Block a user