Added Camera and first-person and UI camera types; Added mouse tracking to aid this
This commit is contained in:
1 parent
d628bbb184
commit
48821afd76
18 files changed
+291
-42
No files matched your search
@@ -28,7 +28,10 @@ namespace nf {
|
||||
const Config& getConfig() const;
|
||||
int getFPS() const;
|
||||
bool isInput(unsigned int code);
|
||||
void trackMouse(bool track);
|
||||
void getMouseDiff(int& x, int& y);
|
||||
|
||||
void quit();
|
||||
~Application();
|
||||
private:
|
||||
void registerWindowClass();
|
||||
@@ -44,6 +47,7 @@ namespace nf {
|
||||
|
||||
Config m_currentConfig;
|
||||
bool m_running;
|
||||
bool m_quit;
|
||||
HINSTANCE m_hInst;
|
||||
LPCWSTR m_wclassName;
|
||||
HWND m_window;
|
||||
@@ -71,6 +75,9 @@ namespace nf {
|
||||
|
||||
//Array of booleans that represent keyboard and mouse input minus the scrollwheel
|
||||
bool m_input[164];
|
||||
int m_mouseX, m_mouseY;
|
||||
bool m_trackingMouse;
|
||||
int m_mouseDiffX, m_mouseDiffY;
|
||||
|
||||
//Renderer object to use OpenGL to render the current state
|
||||
Renderer* m_renderer;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include"Utility.h"
|
||||
|
||||
namespace nf {
|
||||
class Application;
|
||||
class Shader;
|
||||
//TODO: Make sure there are always newlines here;
|
||||
class Camera {
|
||||
public:
|
||||
enum class Type {
|
||||
NF_CAMERA_UI,
|
||||
NF_CAMERA_FIRST_PERSON,
|
||||
NF_CAMERA_ORBIT,
|
||||
NF_CAMERA_FIXED
|
||||
};
|
||||
Camera(Application* app);
|
||||
|
||||
void setType(Type cameraType);
|
||||
Type getType() const;
|
||||
|
||||
void moveForward(double speed);
|
||||
void moveBackward(double speed);
|
||||
void moveRight(double speed);
|
||||
void moveLeft(double speed);
|
||||
void setPosition(double x, double y, double z);
|
||||
void setPosition(const Vec3& position);
|
||||
|
||||
void bind(Shader* shader);
|
||||
|
||||
~Camera();
|
||||
private:
|
||||
Application* m_app;
|
||||
Type m_type;
|
||||
|
||||
Vec3 m_position;
|
||||
Vec3 m_front;
|
||||
};
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
#pragma once
|
||||
#include "Model.h"
|
||||
#include "Assets.h"
|
||||
#include "Utility.h"
|
||||
|
||||
namespace nf {
|
||||
class Entity {
|
||||
struct Vec3 {
|
||||
Vec3(double x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(double x1, double y1, double z1) : x(x1), y(y1), z(z1) {}
|
||||
double x, y, z;
|
||||
};
|
||||
public:
|
||||
Entity();
|
||||
|
||||
void create(Asset* modelAsset, Asset* textureAsset = nullptr);
|
||||
|
||||
void setPosition(double x, double y, double z);
|
||||
void setPosition(const Vec3& position);
|
||||
void setRotation(double x, double y, double z);
|
||||
void setRotation(const Vec3& rotation);
|
||||
void setScale(double x);
|
||||
void setScale(double x, double y, double z);
|
||||
void setScale(const Vec3& scale);
|
||||
|
||||
void bind(Shader* shader);
|
||||
Model* getModel() const;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "Camera.h"
|
||||
|
||||
namespace nf {
|
||||
class Application;
|
||||
@@ -13,11 +14,12 @@ namespace nf {
|
||||
virtual void onEnter();
|
||||
|
||||
virtual void update(double deltaTime);
|
||||
Camera* getCamera();
|
||||
virtual void render(Renderer& renderer);
|
||||
|
||||
virtual void onExit();
|
||||
protected:
|
||||
Application* m_app;
|
||||
//Resource identifier?
|
||||
Camera m_camera;
|
||||
};
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#ifdef NFENGINE
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/matrix_transform.hpp"
|
||||
#endif
|
||||
|
||||
#include "Drawable.h"
|
||||
#include "Texture.h"
|
||||
|
||||
namespace nf {
|
||||
class Drawable;
|
||||
class Texture;
|
||||
class Model : public Drawable {
|
||||
public:
|
||||
Model();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Windows.h>
|
||||
|
||||
#include "Config.h"
|
||||
#include "Utility.h"
|
||||
#include "IntroGamestate.h"
|
||||
#include "Assets.h"
|
||||
|
||||
@@ -15,20 +16,18 @@ namespace nf {
|
||||
class Model;
|
||||
|
||||
class Entity {
|
||||
struct Vec3 {
|
||||
Vec3(double x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(double x1, double y1, double z1) : x(x1), y(y1), z(z1) {}
|
||||
double x, y, z;
|
||||
};
|
||||
public:
|
||||
Entity();
|
||||
|
||||
void create(Asset* modelAsset, Asset* textureAsset = nullptr);
|
||||
|
||||
void setPosition(double x, double y, double z);
|
||||
void setPosition(const Vec3& position);
|
||||
void setRotation(double x, double y, double z);
|
||||
void setRotation(const Vec3& rotation);
|
||||
void setScale(double x);
|
||||
void setScale(double x, double y, double z);
|
||||
void setScale(const Vec3& scale);
|
||||
|
||||
void bind(Shader* shader);
|
||||
Model* getModel() const;
|
||||
@@ -49,8 +48,9 @@ namespace nf {
|
||||
Renderer(Application* app);
|
||||
|
||||
void render(Entity& in);
|
||||
//TODO: Create second render function for UIElements
|
||||
|
||||
void doFrame();
|
||||
void doFrame(Camera* camera);
|
||||
|
||||
~Renderer();
|
||||
private:
|
||||
@@ -59,10 +59,8 @@ namespace nf {
|
||||
HDC m_hdc;
|
||||
HGLRC m_hglrc;
|
||||
|
||||
std::vector<Drawable*> m_lGame;
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<Drawable*> m_lUI;
|
||||
const char* m_defaultVertex;
|
||||
const char* m_defaultFragment;
|
||||
Shader* m_defaultShader;
|
||||
};
|
||||
|
||||
@@ -85,13 +83,17 @@ namespace nf {
|
||||
const Config& getConfig() const;
|
||||
int getFPS() const;
|
||||
bool isInput(unsigned int code);
|
||||
void trackMouse(bool track);
|
||||
void getMouseDiff(int& x, int& y);
|
||||
|
||||
void quit();
|
||||
~Application();
|
||||
private:
|
||||
void registerWindowClass();
|
||||
RECT getWindowRect() const;
|
||||
void calculateNewWindowPos(int& x, int& y);
|
||||
void toggleFullscreen();
|
||||
void updateInput();
|
||||
void runMainGameThread();
|
||||
void startIntroState();
|
||||
void doStateChange();
|
||||
@@ -100,6 +102,7 @@ namespace nf {
|
||||
|
||||
Config m_currentConfig;
|
||||
bool m_running;
|
||||
bool m_quit;
|
||||
HINSTANCE m_hInst;
|
||||
LPCWSTR m_wclassName;
|
||||
HWND m_window;
|
||||
@@ -127,10 +130,12 @@ namespace nf {
|
||||
|
||||
//Array of booleans that represent keyboard and mouse input minus the scrollwheel
|
||||
bool m_input[164];
|
||||
int m_mouseX, m_mouseY;
|
||||
bool m_trackingMouse;
|
||||
int m_mouseDiffX, m_mouseDiffY;
|
||||
|
||||
//Renderer object to use OpenGL to render the current state
|
||||
Renderer* m_renderer;
|
||||
};
|
||||
}
|
||||
#include "Input.h"
|
||||
#include "Utility.h"
|
||||
#include "Input.h"
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <Windows.h>
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Camera.h"
|
||||
|
||||
namespace nf {
|
||||
class Application;
|
||||
@@ -15,7 +15,7 @@ namespace nf {
|
||||
void render(Entity& in);
|
||||
//TODO: Create second render function for UIElements
|
||||
|
||||
void doFrame();
|
||||
void doFrame(Camera* camera);
|
||||
|
||||
~Renderer();
|
||||
private:
|
||||
@@ -27,7 +27,5 @@ namespace nf {
|
||||
std::vector<Entity*> m_lGame;
|
||||
std::vector<Drawable*> m_lUI;
|
||||
Shader* m_defaultShader;
|
||||
|
||||
glm::mat4 proj;
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
#include <unordered_map>
|
||||
#ifdef NFENGINE
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/type_ptr.hpp"
|
||||
#endif
|
||||
|
||||
namespace nf {
|
||||
class Shader {
|
||||
|
||||
@@ -39,12 +39,23 @@ __debugbreak();}
|
||||
std::exit(-1);}
|
||||
#endif
|
||||
|
||||
//TODO: Delete this after moving everything to base.nfpack
|
||||
struct Win32Res {
|
||||
Win32Res(int id);
|
||||
void* ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct Vec3 {
|
||||
Vec3() {}
|
||||
Vec3(double x1) : x(x1), y(x1), z(x1) {}
|
||||
Vec3(double x1, double y1, double z1) : x(x1), y(y1), z(z1) {}
|
||||
Vec3 operator*(const double scalar) {
|
||||
return Vec3(x * scalar, y * scalar, z * scalar);
|
||||
}
|
||||
double x, y, z;
|
||||
};
|
||||
|
||||
const wchar_t* toWide(const char* in);
|
||||
const wchar_t* toWide(const std::string& in);
|
||||
void writeFile(const std::string& filename, const std::string& in, bool encrypted = false);
|
||||
|
||||
Reference in new issue
Block a user