88
Camera.cpp
Normal file
88
Camera.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
|
glm::vec3 CameraOffset;
|
||||||
|
|
||||||
|
float MovementSpeed;
|
||||||
|
float MouseSensitivity;
|
||||||
|
float Zoom;
|
||||||
|
|
||||||
|
Camera::Camera(GLFWwindow* Window)
|
||||||
|
: GameObject(glm::vec3(0.0f), glm::vec3(0.0f), glm::vec3(0.0f)),
|
||||||
|
Window(Window)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 Camera::GetViewMatrix()
|
||||||
|
{
|
||||||
|
return glm::lookAt(Position, Position + Front, Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::SetOffset(glm::vec3 Offset)
|
||||||
|
{
|
||||||
|
this->Offset = Offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::MoveCamera(glm::vec3 Position)
|
||||||
|
{
|
||||||
|
this->Position = Position + Offset;
|
||||||
|
UpdateVectors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::RotateCamera(float Yaw, float Pitch, GLboolean bConstrainPitch)
|
||||||
|
{
|
||||||
|
Rotation.y += Yaw;
|
||||||
|
Rotation.x += Pitch;
|
||||||
|
|
||||||
|
if (bConstrainPitch)
|
||||||
|
{
|
||||||
|
if (Rotation.x > 89.0f)
|
||||||
|
Rotation.x = 89.0f;
|
||||||
|
if (Rotation.x < -89.0f)
|
||||||
|
Rotation.x = -89.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateVectors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::ZoomCamera(float ZoomAmount)
|
||||||
|
{
|
||||||
|
Zoom -= (float)ZoomAmount;
|
||||||
|
if (Zoom < 1.0f)
|
||||||
|
Zoom = 1.0f;
|
||||||
|
if (Zoom > 45.0f)
|
||||||
|
Zoom = 45.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::RenderScene(
|
||||||
|
LevelMap& LevelMap,
|
||||||
|
const std::vector<PointLight>& Lights,
|
||||||
|
int ScreenWidth,
|
||||||
|
int ScreenHeight)
|
||||||
|
{
|
||||||
|
// Set viewport
|
||||||
|
glViewport(0, 0, ScreenWidth, ScreenHeight);
|
||||||
|
|
||||||
|
// Clear buffers
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Calculate matrices
|
||||||
|
glm::mat4 Projection = GetProjectionMatrix(ScreenWidth, ScreenHeight);
|
||||||
|
glm::mat4 View = GetViewMatrix();
|
||||||
|
glm::mat4 Model = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
// Verify matrices are valid
|
||||||
|
if (isnan(Projection[0].x) || isnan(View[0].x)) {
|
||||||
|
std::cerr << "Invalid camera matrices!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 Camera::GetProjectionMatrix(int ScreenWidth, int ScreenHeight) {
|
||||||
|
return glm::perspective(
|
||||||
|
glm::radians(Zoom),
|
||||||
|
(float)ScreenWidth / (float)ScreenHeight,
|
||||||
|
0.1f,
|
||||||
|
100.0f
|
||||||
|
);
|
||||||
|
}
|
||||||
0
EventManager.cpp
Normal file
0
EventManager.cpp
Normal file
41
EventManager.h
Normal file
41
EventManager.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <strstream>
|
||||||
|
#include <FastDelegate.h>
|
||||||
|
|
||||||
|
// {29A32703-A3DB-4E7C-B275-3FBA7F78FE51}
|
||||||
|
// DEFINE_GUID(<< name >> ,
|
||||||
|
// 0x29a32703, 0xa3db, 0x4e7c, 0xb2, 0x75, 0x3f, 0xba, 0x7f, 0x78, 0xfe, 0x51);
|
||||||
|
|
||||||
|
class IEventData;
|
||||||
|
|
||||||
|
typedef unsigned long EventType;
|
||||||
|
typedef std::shared_ptr<IEventData> IEventDataPtr;
|
||||||
|
typedef fastdelegate::FastDelegate1<IEventDataPtr> EventListenerDelegate;
|
||||||
|
|
||||||
|
class IEventData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual const EventType& VGetEventType(void) const = 0;
|
||||||
|
virtual float VGetTimeStamp(void) const = 0;
|
||||||
|
virtual void VSerialize(std::ostrstream& out) const = 0;
|
||||||
|
virtual IEventDataPtr VCopy(void) = 0;
|
||||||
|
virtual const char* GetName(void) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BaseEventData : public IEventData
|
||||||
|
{
|
||||||
|
const float m_TimeStamp;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit BaseEventData(const float timeStamp = 0.0f) :
|
||||||
|
m_TimeStamp(timeStamp) {}
|
||||||
|
virtual ~BaseEventData(void) {}
|
||||||
|
|
||||||
|
// Returns the type of the event
|
||||||
|
virtual const EventType& VGetEventType(void) const = 0;
|
||||||
|
|
||||||
|
float VGetTimeStamp(void) const { return m_TimeStamp; }
|
||||||
|
|
||||||
|
// Serializing for network out
|
||||||
|
virtual void VSerialized(std::ostrstream& out) const {}
|
||||||
|
};
|
||||||
0
Events.cpp
Normal file
0
Events.cpp
Normal file
42
Events.h
Normal file
42
Events.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <EventManager.h>
|
||||||
|
|
||||||
|
typedef unsigned int GameObjectID;
|
||||||
|
|
||||||
|
class EventData_Destroy_GameObject : public BaseEventData
|
||||||
|
{
|
||||||
|
GameObjectID gID;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const EventType sk_EventType;
|
||||||
|
|
||||||
|
explicit EventData_Destroy_GameObject(GameObjectID id)
|
||||||
|
: gID(id) { }
|
||||||
|
|
||||||
|
explicit EventData_Destroy_GameObject(std::istrstream& in)
|
||||||
|
{
|
||||||
|
in >> gID;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const EventType& VGetEventType(void) const
|
||||||
|
{
|
||||||
|
return sk_EventType;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual IEventDataPtr VCopy(void) const
|
||||||
|
{
|
||||||
|
return IEventDataPtr(new EventData_Destroy_GameObject(gID));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void VSerialize(std::ostrstream& out) const
|
||||||
|
{
|
||||||
|
out << gID;
|
||||||
|
}
|
||||||
|
virtual const char* GetName(void) const
|
||||||
|
{
|
||||||
|
return "EventData_Destroy_GameObject";
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObjectID GetID(void) const { return gID; }
|
||||||
|
};
|
||||||
37
GameObject.h
37
GameObject.h
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <InputComponent.h>
|
|
||||||
#include <GraphicsComponent.h>
|
#include <GraphicsComponent.h>
|
||||||
#include <PhysicsComponent.h>
|
#include <PhysicsComponent.h>
|
||||||
|
|
||||||
class GameObject
|
class GameObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
unsigned int GameObjectID;
|
||||||
|
|
||||||
glm::vec3 Position;
|
glm::vec3 Position;
|
||||||
|
|
||||||
glm::vec3 Rotation;
|
glm::vec3 Rotation;
|
||||||
@@ -16,8 +17,7 @@ public:
|
|||||||
glm::vec3 Scale;
|
glm::vec3 Scale;
|
||||||
|
|
||||||
GameObject(glm::vec3 Position, glm::vec3 Rotation, glm::vec3 Scale)
|
GameObject(glm::vec3 Position, glm::vec3 Rotation, glm::vec3 Scale)
|
||||||
: Input(nullptr),
|
: Graphics(nullptr),
|
||||||
Graphics(nullptr),
|
|
||||||
Physics(nullptr),
|
Physics(nullptr),
|
||||||
Position(Position),
|
Position(Position),
|
||||||
Rotation(Rotation),
|
Rotation(Rotation),
|
||||||
@@ -27,11 +27,11 @@ public:
|
|||||||
Right(1.0f, 0.0f, 0.0f),
|
Right(1.0f, 0.0f, 0.0f),
|
||||||
WorldUp(0.0f, 1.0f, 0.0f)
|
WorldUp(0.0f, 1.0f, 0.0f)
|
||||||
{
|
{
|
||||||
|
GameObjectID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObject(InputComponent* Input, GraphicsComponent* Graphics, PhysicsComponent* Physics)
|
GameObject(GraphicsComponent* Graphics, PhysicsComponent* Physics)
|
||||||
: Input(Input),
|
: Graphics(Graphics),
|
||||||
Graphics(Graphics),
|
|
||||||
Physics(Physics),
|
Physics(Physics),
|
||||||
Position(0.0f, 0.0f, 0.0f),
|
Position(0.0f, 0.0f, 0.0f),
|
||||||
Rotation(0.0f, 0.0f, 0.0f),
|
Rotation(0.0f, 0.0f, 0.0f),
|
||||||
@@ -40,17 +40,17 @@ public:
|
|||||||
Up(0.0f, 1.0f, 0.0f),
|
Up(0.0f, 1.0f, 0.0f),
|
||||||
Right(1.0f, 0.0f, 0.0f),
|
Right(1.0f, 0.0f, 0.0f),
|
||||||
WorldUp(0.0f, 1.0f, 0.0f)
|
WorldUp(0.0f, 1.0f, 0.0f)
|
||||||
{}
|
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
{
|
||||||
Input->Update();
|
GameObjectID = 0;
|
||||||
Graphics->Update();
|
}
|
||||||
Physics->Update();
|
|
||||||
|
void Update(float DeltaTime)
|
||||||
|
{
|
||||||
|
//Graphics->Update();
|
||||||
|
//Physics->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
InputComponent* Input;
|
|
||||||
GraphicsComponent* Graphics;
|
GraphicsComponent* Graphics;
|
||||||
PhysicsComponent* Physics;
|
PhysicsComponent* Physics;
|
||||||
|
|
||||||
@@ -58,4 +58,15 @@ protected:
|
|||||||
glm::vec3 Up;
|
glm::vec3 Up;
|
||||||
glm::vec3 Right;
|
glm::vec3 Right;
|
||||||
glm::vec3 WorldUp;
|
glm::vec3 WorldUp;
|
||||||
|
|
||||||
|
void UpdateVectors()
|
||||||
|
{
|
||||||
|
glm::vec3 UpdatedFront;
|
||||||
|
UpdatedFront.x = cos(glm::radians(Rotation.y)) * cos(glm::radians(Rotation.x));
|
||||||
|
UpdatedFront.y = sin(glm::radians(Rotation.x));
|
||||||
|
UpdatedFront.z = sin(glm::radians(Rotation.y)) * cos(glm::radians(Rotation.x));
|
||||||
|
Front = glm::normalize(UpdatedFront);
|
||||||
|
Right = glm::normalize(glm::cross(Front, WorldUp));
|
||||||
|
Up = glm::normalize(glm::cross(Right, Front));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
14
IInputComponent.h
Normal file
14
IInputComponent.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GLFW_INCLUDE_NONE
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
class IInputComponent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IInputComponent(GLFWwindow* Window) : Window(Window) {};
|
||||||
|
virtual ~IInputComponent() {};
|
||||||
|
virtual void Update(float DeltaTime) = 0;
|
||||||
|
protected:
|
||||||
|
GLFWwindow* Window;
|
||||||
|
};
|
||||||
2108
Include/FastDelegate.h
Normal file
2108
Include/FastDelegate.h
Normal file
File diff suppressed because it is too large
Load Diff
243
Include/FastDelegateBind.h
Normal file
243
Include/FastDelegateBind.h
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
// FastDelegateBind.h
|
||||||
|
// Helper file for FastDelegates. Provides bind() function, enabling
|
||||||
|
// FastDelegates to be rapidly compared to programs using boost::function and boost::bind.
|
||||||
|
//
|
||||||
|
// Documentation is found at http://www.codeproject.com/cpp/FastDelegate.asp
|
||||||
|
//
|
||||||
|
// Original author: Jody Hagins.
|
||||||
|
// Minor changes by Don Clugston.
|
||||||
|
//
|
||||||
|
// Warning: The arguments to 'bind' are ignored! No actual binding is performed.
|
||||||
|
// The behaviour is equivalent to boost::bind only when the basic placeholder
|
||||||
|
// arguments _1, _2, _3, etc are used in order.
|
||||||
|
//
|
||||||
|
// HISTORY:
|
||||||
|
// 1.4 Dec 2004. Initial release as part of FastDelegate 1.4.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FASTDELEGATEBIND_H
|
||||||
|
#define FASTDELEGATEBIND_H
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// FastDelegate bind()
|
||||||
|
//
|
||||||
|
// bind() helper function for boost compatibility.
|
||||||
|
// (Original author: Jody Hagins).
|
||||||
|
//
|
||||||
|
// Add another helper, so FastDelegate can be a dropin replacement
|
||||||
|
// for boost::bind (in a fair number of cases).
|
||||||
|
// Note the elipses, because boost::bind() takes place holders
|
||||||
|
// but FastDelegate does not care about them. Getting the place holder
|
||||||
|
// mechanism to work, and play well with boost is a bit tricky, so
|
||||||
|
// we do the "easy" thing...
|
||||||
|
// Assume we have the following code...
|
||||||
|
// using boost::bind;
|
||||||
|
// bind(&Foo:func, &foo, _1, _2);
|
||||||
|
// we should be able to replace the "using" with...
|
||||||
|
// using fastdelegate::bind;
|
||||||
|
// and everything should work fine...
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX
|
||||||
|
|
||||||
|
namespace fastdelegate {
|
||||||
|
|
||||||
|
//N=0
|
||||||
|
template <class X, class Y, class RetType>
|
||||||
|
FastDelegate< RetType ( ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType>
|
||||||
|
FastDelegate< RetType ( ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=1
|
||||||
|
template <class X, class Y, class RetType, class Param1>
|
||||||
|
FastDelegate< RetType ( Param1 p1 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1>
|
||||||
|
FastDelegate< RetType ( Param1 p1 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=2
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=3
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=4
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=5
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=6
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=7
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
//N=8
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ),
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class X, class Y, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
|
||||||
|
FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >
|
||||||
|
bind(
|
||||||
|
RetType (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const,
|
||||||
|
Y * y,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
return FastDelegate< RetType ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) >(y, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX
|
||||||
|
|
||||||
|
} // namespace fastdelegate
|
||||||
|
|
||||||
|
#endif // !defined(FASTDELEGATEBIND_H)
|
||||||
|
|
||||||
27
InputCommand.h
Normal file
27
InputCommand.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <GameObject.h>
|
||||||
|
|
||||||
|
class Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Command() {}
|
||||||
|
virtual void Execute(GameObject& gObject) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class JumpCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Execute(GameObject& gObject)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class MoveCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Execute()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
class InputComponent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~InputComponent() {};
|
|
||||||
virtual void Update() = 0;
|
|
||||||
};
|
|
||||||
9
InputEnums.h
Normal file
9
InputEnums.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum EInputDirection
|
||||||
|
{
|
||||||
|
FORWARD,
|
||||||
|
BACKWARD,
|
||||||
|
LEFT,
|
||||||
|
RIGHT
|
||||||
|
};
|
||||||
6
InputHandler.cpp
Normal file
6
InputHandler.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "InputHandler.h"
|
||||||
|
|
||||||
|
void InputHandler::HandleInput()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
14
InputHandler.h
Normal file
14
InputHandler.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <InputCommand.h>
|
||||||
|
|
||||||
|
class InputHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void HandleInput();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Command* ButtonX;
|
||||||
|
Command* ButtonY;
|
||||||
|
Command* ButtonA;
|
||||||
|
Command* ButtonB;
|
||||||
|
};
|
||||||
@@ -108,7 +108,8 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>C:\Development Projects\LearningOpenGL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>C:\Development Projects\LearningOpenGL\Include;C:\Development Projects\LearningOpenGL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -124,6 +125,8 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>C:\Development Projects\LearningOpenGL\Include;</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -134,17 +137,22 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\Development Tools\glad\src\glad.c" />
|
<ClCompile Include="..\..\Development Tools\glad\src\glad.c" />
|
||||||
|
<ClCompile Include="Camera.cpp" />
|
||||||
|
<ClCompile Include="EventManager.cpp" />
|
||||||
|
<ClCompile Include="Events.cpp" />
|
||||||
<ClCompile Include="imgui\backends\imgui_impl_glfw.cpp" />
|
<ClCompile Include="imgui\backends\imgui_impl_glfw.cpp" />
|
||||||
<ClCompile Include="imgui\backends\imgui_impl_opengl3.cpp" />
|
<ClCompile Include="imgui\backends\imgui_impl_opengl3.cpp" />
|
||||||
<ClCompile Include="imgui\imgui.cpp" />
|
<ClCompile Include="imgui\imgui.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_draw.cpp" />
|
<ClCompile Include="imgui\imgui_draw.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_tables.cpp" />
|
<ClCompile Include="imgui\imgui_tables.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_widgets.cpp" />
|
<ClCompile Include="imgui\imgui_widgets.cpp" />
|
||||||
|
<ClCompile Include="InputHandler.cpp" />
|
||||||
<ClCompile Include="LevelMap.cpp" />
|
<ClCompile Include="LevelMap.cpp" />
|
||||||
<ClCompile Include="Light.cpp" />
|
<ClCompile Include="Light.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="MeshRenderer.cpp" />
|
<ClCompile Include="MeshRenderer.cpp" />
|
||||||
<ClCompile Include="Player.cpp" />
|
<ClCompile Include="Player.cpp" />
|
||||||
|
<ClCompile Include="PlayerInputComponent.cpp" />
|
||||||
<ClCompile Include="PointLight.cpp" />
|
<ClCompile Include="PointLight.cpp" />
|
||||||
<ClCompile Include="ResourceManager.cpp" />
|
<ClCompile Include="ResourceManager.cpp" />
|
||||||
<ClCompile Include="Shader.cpp" />
|
<ClCompile Include="Shader.cpp" />
|
||||||
@@ -168,12 +176,18 @@
|
|||||||
<ClInclude Include="Camera.h" />
|
<ClInclude Include="Camera.h" />
|
||||||
<ClInclude Include="cube.h" />
|
<ClInclude Include="cube.h" />
|
||||||
<ClInclude Include="cubeFactory.h" />
|
<ClInclude Include="cubeFactory.h" />
|
||||||
|
<ClInclude Include="Events.h" />
|
||||||
<ClInclude Include="GameObject.h" />
|
<ClInclude Include="GameObject.h" />
|
||||||
<ClInclude Include="GraphicsComponent.h" />
|
<ClInclude Include="GraphicsComponent.h" />
|
||||||
<ClInclude Include="InputComponent.h" />
|
<ClInclude Include="EventManager.h" />
|
||||||
|
<ClInclude Include="IInputComponent.h" />
|
||||||
|
<ClInclude Include="InputCommand.h" />
|
||||||
|
<ClInclude Include="input.txt" />
|
||||||
|
<ClInclude Include="InputEnums.h" />
|
||||||
|
<ClInclude Include="InputHandler.h" />
|
||||||
<ClInclude Include="LevelMap.h" />
|
<ClInclude Include="LevelMap.h" />
|
||||||
<ClInclude Include="Light.h" />
|
<ClInclude Include="Light.h" />
|
||||||
<ClInclude Include="map_reader.h" />
|
<ClInclude Include="MapReader.h" />
|
||||||
<ClInclude Include="MeshRenderer.h" />
|
<ClInclude Include="MeshRenderer.h" />
|
||||||
<ClInclude Include="PhysicsComponent.h" />
|
<ClInclude Include="PhysicsComponent.h" />
|
||||||
<ClInclude Include="Player.h" />
|
<ClInclude Include="Player.h" />
|
||||||
|
|||||||
@@ -13,35 +13,29 @@
|
|||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Source Files\Events">
|
||||||
|
<UniqueIdentifier>{3b390837-0087-42d6-865a-f407f4e85689}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\Player">
|
||||||
|
<UniqueIdentifier>{92d02b9a-68af-46b6-8a38-2d71c807275a}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\MapReader">
|
||||||
|
<UniqueIdentifier>{b8c509e7-d52d-4bc7-b525-9dcdaa2260ca}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\3rdParty">
|
||||||
|
<UniqueIdentifier>{82df0858-8eaf-4a3d-957a-fe1eaf4f5318}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\Input">
|
||||||
|
<UniqueIdentifier>{2e56c203-baba-4213-b8c3-f6b7750ff274}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\Components">
|
||||||
|
<UniqueIdentifier>{87046629-81da-4f0e-8451-6bbe46ae4a32}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\Development Tools\glad\src\glad.c">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="imgui\imgui.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="imgui\imgui_draw.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="imgui\imgui_tables.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="imgui\imgui_widgets.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="imgui\backends\imgui_impl_glfw.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="imgui\backends\imgui_impl_opengl3.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Player.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="MeshRenderer.cpp">
|
<ClCompile Include="MeshRenderer.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -51,15 +45,54 @@
|
|||||||
<ClCompile Include="ResourceManager.cpp">
|
<ClCompile Include="ResourceManager.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="LevelMap.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Light.cpp">
|
<ClCompile Include="Light.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="PointLight.cpp">
|
<ClCompile Include="PointLight.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="EventManager.cpp">
|
||||||
|
<Filter>Source Files\Events</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Events.cpp">
|
||||||
|
<Filter>Source Files\Events</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Player.cpp">
|
||||||
|
<Filter>Source Files\Player</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="LevelMap.cpp">
|
||||||
|
<Filter>Source Files\MapReader</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui\imgui.cpp">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui\imgui_draw.cpp">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui\backends\imgui_impl_glfw.cpp">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui\backends\imgui_impl_opengl3.cpp">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui\imgui_tables.cpp">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="imgui\imgui_widgets.cpp">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\Development Tools\glad\src\glad.c">
|
||||||
|
<Filter>Source Files\3rdParty</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="InputHandler.cpp">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Camera.cpp">
|
||||||
|
<Filter>Source Files\Components</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="PlayerInputComponent.cpp">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="fragment.frag" />
|
<None Include="fragment.frag" />
|
||||||
@@ -80,27 +113,12 @@
|
|||||||
<ClInclude Include="cube.h">
|
<ClInclude Include="cube.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Camera.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="cubeFactory.h">
|
<ClInclude Include="cubeFactory.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="map_reader.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GameObject.h">
|
<ClInclude Include="GameObject.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Player.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="InputComponent.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="PlayerInputComponent.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="PhysicsComponent.h">
|
<ClInclude Include="PhysicsComponent.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -116,15 +134,48 @@
|
|||||||
<ClInclude Include="ResourceManager.h">
|
<ClInclude Include="ResourceManager.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="LevelMap.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Light.h">
|
<ClInclude Include="Light.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="PointLight.h">
|
<ClInclude Include="PointLight.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="EventManager.h">
|
||||||
|
<Filter>Source Files\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Events.h">
|
||||||
|
<Filter>Source Files\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Player.h">
|
||||||
|
<Filter>Source Files\Player</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="LevelMap.h">
|
||||||
|
<Filter>Source Files\MapReader</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="MapReader.h">
|
||||||
|
<Filter>Source Files\MapReader</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="InputCommand.h">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="InputHandler.h">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="input.txt">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="InputEnums.h">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="IInputComponent.h">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="PlayerInputComponent.h">
|
||||||
|
<Filter>Source Files\Input</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Camera.h">
|
||||||
|
<Filter>Source Files\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="map_test.txt" />
|
<Text Include="map_test.txt" />
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ std::vector<MeshRenderer*> LevelMap::GetMeshes()
|
|||||||
return { &wall_renderer, &floor_renderer, &ceiling_renderer };
|
return { &wall_renderer, &floor_renderer, &ceiling_renderer };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Sector>& LevelMap::GetSectors()
|
||||||
|
{
|
||||||
|
return sectors;
|
||||||
|
}
|
||||||
|
|
||||||
Sector LevelMap::ParseSector(std::string& line)
|
Sector LevelMap::ParseSector(std::string& line)
|
||||||
{
|
{
|
||||||
Sector sector;
|
Sector sector;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
std::vector<MeshRenderer*> GetMeshes();
|
std::vector<MeshRenderer*> GetMeshes();
|
||||||
|
std::vector<Sector>& GetSectors();
|
||||||
private:
|
private:
|
||||||
std::vector<Sector> sectors;
|
std::vector<Sector> sectors;
|
||||||
|
|
||||||
|
|||||||
301
Player.cpp
301
Player.cpp
@@ -1,50 +1,120 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
#include "LevelMap.h"
|
||||||
|
#include "PlayerInputComponent.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Player::Player(glm::vec3 Position, glm::vec3 Rotation)
|
Player::Player(glm::vec3 position, glm::vec3 rotation, std::vector<Sector>& sectors, GLFWwindow* Window)
|
||||||
: GameObject(Position, Rotation, glm::vec3(1.0f, 1.0f, 1.0f)),
|
: GameObject(position, rotation, glm::vec3(1.0f, 1.0f, 1.0f)),
|
||||||
PlayerCamera(new Camera(glm::vec3(0.0f, 1.0f, 0.0f)))
|
PlayerCamera(std::make_unique<Camera>(Window)),
|
||||||
|
cPlayerInput(std::make_unique<PlayerInputComponent>(Window, *this)),
|
||||||
|
LevelSectors(sectors),
|
||||||
|
CurrentSector(§ors[0])
|
||||||
{
|
{
|
||||||
|
PlayerCamera->SetOffset(glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
PlayerCamera->Position = Position + PlayerCamera->CameraOffset;
|
PlayerCamera->MoveCamera(Position);
|
||||||
PlayerCamera->WorldUp = this->WorldUp;
|
PlayerCamera->Rotation = Rotation;
|
||||||
std::cout << "{" << Position.x << ", " << Position.y << ", " << Position.z << "}" << std::endl;
|
|
||||||
std::cout << "{" << PlayerCamera->Position.x << ", " << PlayerCamera->Position.y << ", " << PlayerCamera->Position.z << "}" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Update()
|
void Player::Update(float DeltaTime)
|
||||||
{
|
{
|
||||||
|
GameObject::Update(DeltaTime);
|
||||||
|
cPlayerInput->Update(DeltaTime);
|
||||||
|
|
||||||
|
if (bJumping)
|
||||||
|
{
|
||||||
|
Position.y += JumpVelocity * DeltaTime;
|
||||||
|
JumpVelocity -= GRAVITY * DeltaTime;
|
||||||
|
|
||||||
|
if (Position.y <= CurrentSector->floor_height)
|
||||||
|
{
|
||||||
|
JumpVelocity = 0.0f;
|
||||||
|
Position.y = CurrentSector->floor_height;
|
||||||
|
bJumping = false;
|
||||||
|
std::cout << "STOP JUMPING" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Position.y > CurrentSector->floor_height)
|
||||||
|
{
|
||||||
|
Position.y -= GRAVITY * DeltaTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Position.y = CurrentSector->floor_height;
|
||||||
|
bJumping = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerCamera->MoveCamera(Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::ProcessKeyboard(EInputDirection Direction, float Delta)
|
void Player::Move(EInputDirection Direction, float Delta)
|
||||||
{
|
{
|
||||||
float Velocity = bIsRunning ? RunSpeed : WalkSpeed;
|
float Velocity = bIsRunning ? RunSpeed : WalkSpeed;
|
||||||
Velocity = Velocity * Delta;
|
Velocity = Velocity * Delta;
|
||||||
|
glm::vec3 newPosition = Position;
|
||||||
if (Direction == FORWARD)
|
if (Direction == FORWARD)
|
||||||
Position += Front * Velocity;
|
newPosition += Front * Velocity;
|
||||||
if (Direction == BACKWARD)
|
if (Direction == BACKWARD)
|
||||||
Position -= Front * Velocity;
|
newPosition -= Front * Velocity;
|
||||||
if (Direction == LEFT)
|
if (Direction == LEFT)
|
||||||
Position -= Right * Velocity;
|
newPosition -= Right * Velocity;
|
||||||
if (Direction == RIGHT)
|
if (Direction == RIGHT)
|
||||||
Position += Right * Velocity;
|
newPosition += Right * Velocity;
|
||||||
|
|
||||||
PlayerCamera->Position = Position + PlayerCamera->CameraOffset;
|
if (!CrossingWall(newPosition))
|
||||||
PlayerCamera->WorldUp = this->WorldUp;
|
{
|
||||||
|
Position = newPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Sector& Sector : LevelSectors)
|
||||||
|
{
|
||||||
|
glm::vec2 playerPoint = { Position.x, Position.z };
|
||||||
|
if (PointInPolygon(playerPoint, Sector.walls))
|
||||||
|
{
|
||||||
|
/*if (!bJumping)
|
||||||
|
Position.y = Sector.floor_height;*/
|
||||||
|
if (CurrentSector != &Sector)
|
||||||
|
{
|
||||||
|
std::cout << "Updating CurrentSector ("
|
||||||
|
<< (CurrentSector ? CurrentSector->index : -1)
|
||||||
|
<< ") to Sector (" << Sector.index << ")" << std::endl;
|
||||||
|
CurrentSector = &Sector;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// TO DO: Pretty sure this limits me for sectors that contain sectors, i.e. if I want multiple floor/ceiling heights within a sector it will have to be made of multiple sectors
|
||||||
|
//std::cout << "Player in: " << sector.index << " | Player Y: " << sector.floor_height << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::ProcessMouseMovement(float XOffset, float YOffset, GLboolean bConstrainPitch)
|
void Player::Jump()
|
||||||
{
|
{
|
||||||
XOffset *= MOUSE_SENSITIVITY;
|
if (bJumping) return;
|
||||||
YOffset *= MOUSE_SENSITIVITY;
|
|
||||||
|
|
||||||
Yaw += XOffset;
|
//std::cout << "JUMP!" << std::endl;
|
||||||
PlayerCamera->Yaw = Yaw;
|
bJumping = true;
|
||||||
|
JumpVelocity = JumpForce;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerCamera->ProcessMouseMovement(XOffset, YOffset);
|
void Player::Sprint()
|
||||||
UpdatePlayerVectors();
|
{
|
||||||
|
bIsRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::StopSprint()
|
||||||
|
{
|
||||||
|
bIsRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::Look(float Yaw, float Pitch, GLboolean bConstrainPitch)
|
||||||
|
{
|
||||||
|
Yaw *= MOUSE_SENSITIVITY;
|
||||||
|
Pitch *= MOUSE_SENSITIVITY;
|
||||||
|
|
||||||
|
Rotation.y += Yaw;
|
||||||
|
|
||||||
|
PlayerCamera->RotateCamera(Yaw, Pitch);
|
||||||
|
UpdateVectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 Player::GetViewMatrix() const
|
glm::mat4 Player::GetViewMatrix() const
|
||||||
@@ -52,13 +122,182 @@ glm::mat4 Player::GetViewMatrix() const
|
|||||||
return PlayerCamera->GetViewMatrix();
|
return PlayerCamera->GetViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::UpdatePlayerVectors()
|
bool Player::CrossingWall(glm::vec3 NewPosition)
|
||||||
{
|
{
|
||||||
glm::vec3 UpdatedFront;
|
// Convert 3D positions to 2D (XZ plane) for wall collision
|
||||||
UpdatedFront.x = cos(glm::radians(Yaw)) * cos(0);
|
glm::vec2 CurrentPosition = glm::vec2(Position.x, Position.z);
|
||||||
UpdatedFront.y = sin(0);
|
glm::vec2 NextPosition = glm::vec2(NewPosition.x, NewPosition.z);
|
||||||
UpdatedFront.z = sin(glm::radians(Yaw)) * cos(0);
|
|
||||||
Front = glm::normalize(UpdatedFront);
|
//bool bCrossed = false;
|
||||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
|
||||||
Up = glm::normalize(glm::cross(Right, Front));
|
// Check each wall in the sector
|
||||||
|
for (const Wall& Wall : CurrentSector->walls)
|
||||||
|
{
|
||||||
|
glm::vec2 WallStart = Wall.a;
|
||||||
|
glm::vec2 WallEnd = Wall.b;
|
||||||
|
|
||||||
|
// Check if movement line segment intersects with wall line segment
|
||||||
|
if (LineSegmentsIntersect(CurrentPosition, NextPosition, WallStart, WallEnd))
|
||||||
|
{
|
||||||
|
if (Wall.portal == 0)
|
||||||
|
{
|
||||||
|
return true; // Collision detected
|
||||||
|
}
|
||||||
|
else if (CanFitInNextSector(LevelSectors[Wall.portal-1]))// check if valid portal (floor height < player y and floor and ceiling tall enough for player)
|
||||||
|
{
|
||||||
|
CurrentSector = &LevelSectors[Wall.portal - 1];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//return true; // Collision detected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (bCrossed) return bCrossed; // breakout early, attempting to move through wall
|
||||||
|
|
||||||
|
// Check outward facing sectors to ensure not moving into pillars
|
||||||
|
for (const Sector& Sector : LevelSectors)
|
||||||
|
{
|
||||||
|
if (!Sector.outward_facing)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check each wall in the sector
|
||||||
|
for (const Wall& Wall : Sector.walls)
|
||||||
|
{
|
||||||
|
glm::vec2 WallStart = Wall.a;
|
||||||
|
glm::vec2 WallEnd = Wall.b;
|
||||||
|
|
||||||
|
// Check if movement line segment intersects with wall line segment
|
||||||
|
if (LineSegmentsIntersect(CurrentPosition, NextPosition, WallStart, WallEnd))
|
||||||
|
{
|
||||||
|
//if (Wall.portal != 0)
|
||||||
|
//{
|
||||||
|
// return false; // Collision but to another sector
|
||||||
|
//}
|
||||||
|
return true; // Collision detected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // No collisions detected
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Player::LineSegmentsIntersect(const glm::vec2& StartPosition, const glm::vec2& EndPosition, const glm::vec2& WallPointA, const glm::vec2& WallPointB)
|
||||||
|
{
|
||||||
|
// Implementation of the cross product test for line segment intersection
|
||||||
|
auto cross = [](const glm::vec2& a, const glm::vec2& b) {
|
||||||
|
return a.x * b.y - a.y * b.x;
|
||||||
|
};
|
||||||
|
|
||||||
|
glm::vec2 PlayerNormal = EndPosition - StartPosition;
|
||||||
|
glm::vec2 WallNormal = WallPointB - WallPointA;
|
||||||
|
glm::vec2 WallToPlayerNormal = WallPointA - StartPosition;
|
||||||
|
|
||||||
|
float PlayerWallCross = cross(PlayerNormal, WallNormal);
|
||||||
|
|
||||||
|
// If lines are not parallel
|
||||||
|
if (std::abs(PlayerWallCross) >= std::numeric_limits<float>::epsilon())
|
||||||
|
{
|
||||||
|
float t = cross(WallToPlayerNormal, PlayerNormal) / PlayerWallCross;
|
||||||
|
float u = cross(WallToPlayerNormal, WallNormal) / PlayerWallCross;
|
||||||
|
|
||||||
|
// If intersection point is on both segments
|
||||||
|
if ((t >= 0 && t <= 1) && (u >= 0 && u <= 1))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no intersection, check distance from EndPosition to wall segment
|
||||||
|
return PointToLineSegmentDistance(EndPosition, WallPointA, WallPointB) <= 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Player::PointToLineSegmentDistance(const glm::vec2& point, const glm::vec2& segA, const glm::vec2& segB)
|
||||||
|
{
|
||||||
|
glm::vec2 segVec = segB - segA;
|
||||||
|
float segLengthSquared = glm::dot(segVec, segVec);
|
||||||
|
|
||||||
|
// If segment is actually a point
|
||||||
|
if (segLengthSquared < std::numeric_limits<float>::epsilon())
|
||||||
|
return glm::distance(point, segA);
|
||||||
|
|
||||||
|
// Project point onto the segment
|
||||||
|
float t = glm::dot(point - segA, segVec) / segLengthSquared;
|
||||||
|
t = glm::clamp(t, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
glm::vec2 projection = segA + t * segVec;
|
||||||
|
return glm::distance(point, projection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checking if a point is inside a polygon
|
||||||
|
bool Player::PointInPolygon(glm::vec2 point, std::vector<Wall> polygon)
|
||||||
|
{
|
||||||
|
int num_vertices = polygon.size();
|
||||||
|
double x = point.x, y = point.y;
|
||||||
|
bool inside = false;
|
||||||
|
|
||||||
|
// Store the first point in the polygon and initialize
|
||||||
|
// the second point
|
||||||
|
glm::vec2 p1 = polygon[0].a, p2;
|
||||||
|
|
||||||
|
// Loop through each edge in the polygon
|
||||||
|
for (int i = 1; i <= num_vertices; i++) {
|
||||||
|
// Get the next point in the polygon
|
||||||
|
p2 = polygon[i % num_vertices].a;
|
||||||
|
|
||||||
|
// Check if the point is above the minimum y
|
||||||
|
// coordinate of the edge
|
||||||
|
if (y > std::min(p1.y, p2.y)) {
|
||||||
|
// Check if the point is below the maximum y
|
||||||
|
// coordinate of the edge
|
||||||
|
if (y <= std::max(p1.y, p2.y)) {
|
||||||
|
// Check if the point is to the left of the
|
||||||
|
// maximum x coordinate of the edge
|
||||||
|
if (x <= std::max(p1.x, p2.x)) {
|
||||||
|
// Calculate the x-intersection of the
|
||||||
|
// line connecting the point to the edge
|
||||||
|
double x_intersection
|
||||||
|
= (y - p1.y) * (p2.x - p1.x)
|
||||||
|
/ (p2.y - p1.y)
|
||||||
|
+ p1.x;
|
||||||
|
|
||||||
|
// Check if the point is on the same
|
||||||
|
// line as the edge or to the left of
|
||||||
|
// the x-intersection
|
||||||
|
if (p1.x == p2.x
|
||||||
|
|| x <= x_intersection) {
|
||||||
|
// Flip the inside flag
|
||||||
|
inside = !inside;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the current point as the first point for
|
||||||
|
// the next iteration
|
||||||
|
p1 = p2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the value of the inside flag
|
||||||
|
return inside;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Player::CanFitInNextSector(Sector Sector)
|
||||||
|
{
|
||||||
|
std::cout << "Checking sector " << Sector.index << " | Floor height : " << Sector.floor_height << " | Player Y : " << Position.y << " | Sector height : " << Sector.ceiling_height - Sector.floor_height << std::endl;
|
||||||
|
if (Position.y < Sector.floor_height - STEP_HEIGHT)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Sector.ceiling_height - Sector.floor_height < PLAYER_HEIGHT)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
68
Player.h
68
Player.h
@@ -3,41 +3,59 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/geometric.hpp>
|
||||||
#include <GameObject.h>
|
#include <GameObject.h>
|
||||||
#include <Camera.h>
|
#include <Camera.h>
|
||||||
|
#include <LevelMap.h>
|
||||||
|
#include <InputEnums.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class PlayerInputComponent;
|
||||||
enum EInputDirection
|
|
||||||
{
|
|
||||||
FORWARD,
|
|
||||||
BACKWARD,
|
|
||||||
LEFT,
|
|
||||||
RIGHT
|
|
||||||
};
|
|
||||||
|
|
||||||
class Player : public GameObject
|
class Player : public GameObject
|
||||||
{
|
{
|
||||||
public:
|
std::vector<Sector>& LevelSectors;
|
||||||
Player(glm::vec3 Position, glm::vec3 Rotation);
|
Sector* CurrentSector;
|
||||||
~Player() = default;
|
float Yaw = -90.0f;
|
||||||
|
float MouseSensitivity = 0.1f;
|
||||||
void Update();
|
|
||||||
|
// movement variables
|
||||||
void ProcessKeyboard(EInputDirection Direction, float Delta);
|
|
||||||
void ProcessMouseMovement(float XOffset, float YOffset, GLboolean ConstrainPitch = true);
|
|
||||||
glm::mat4 GetViewMatrix() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Camera* PlayerCamera;
|
|
||||||
float Yaw;
|
|
||||||
float MouseSensitivity;
|
|
||||||
|
|
||||||
float WalkSpeed = 5.0f;
|
float WalkSpeed = 5.0f;
|
||||||
float RunSpeed = 15.0f;
|
float RunSpeed = 15.0f;
|
||||||
|
|
||||||
bool bIsRunning = false;
|
bool bIsRunning = false;
|
||||||
|
|
||||||
void UpdatePlayerVectors();
|
float JumpForce = 5.0f;
|
||||||
|
float JumpVelocity = 0.0f;
|
||||||
|
bool bJumping = false;
|
||||||
|
const float GRAVITY = 9.8f;
|
||||||
|
|
||||||
|
// collision constants
|
||||||
|
const float STEP_HEIGHT = 0.25f;
|
||||||
|
const float PLAYER_HEIGHT = 2.0f;
|
||||||
|
const float PLAYER_RADIUS = 1.0f;
|
||||||
|
|
||||||
|
bool CrossingWall(glm::vec3 NewPosition);
|
||||||
|
bool LineSegmentsIntersect(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& q1, const glm::vec2& q2);
|
||||||
|
float PointToLineSegmentDistance(const glm::vec2& point, const glm::vec2& segA, const glm::vec2& segB);
|
||||||
|
bool PointInPolygon(glm::vec2 point, std::vector<Wall> polygon);
|
||||||
|
bool CanFitInNextSector(Sector Sector);
|
||||||
|
|
||||||
|
std::unique_ptr<PlayerInputComponent> cPlayerInput;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::unique_ptr<Camera> PlayerCamera;
|
||||||
|
|
||||||
|
Player(glm::vec3 Position, glm::vec3 Rotation, std::vector<Sector>& LevelSectors, GLFWwindow* Window);
|
||||||
|
~Player() = default;
|
||||||
|
|
||||||
|
void Update(float DeltaTime);
|
||||||
|
void Move(EInputDirection Direction, float Delta);
|
||||||
|
void Jump();
|
||||||
|
void Sprint();
|
||||||
|
void StopSprint();
|
||||||
|
void Look(float XOffset, float YOffset, GLboolean bConstrainPitch = true);
|
||||||
|
|
||||||
|
glm::mat4 GetViewMatrix() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
112
PlayerInputComponent.cpp
Normal file
112
PlayerInputComponent.cpp
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#include "PlayerInputComponent.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "InputEnums.h"
|
||||||
|
|
||||||
|
PlayerInputComponent::PlayerInputComponent(GLFWwindow* Window, Player& PlayerCharacter)
|
||||||
|
: IInputComponent(Window), PlayerCharacter(PlayerCharacter)
|
||||||
|
{
|
||||||
|
glfwSetWindowUserPointer(Window, this);
|
||||||
|
glfwSetCursorPosCallback(Window, ProcessMouse);
|
||||||
|
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
bFreeMouse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerInputComponent::Update(float DeltaTime)
|
||||||
|
{
|
||||||
|
ProcessKeyboard(DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerInputComponent::ProcessKeyboard(float DeltaTime)
|
||||||
|
{
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_ESCAPE) == GLFW_PRESS && !bFreeMouse) {
|
||||||
|
//glfwSetWindowShouldClose(Window, true);
|
||||||
|
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
bFreeMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_E) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
PlayerCharacter.Move(FORWARD, DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_D) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
PlayerCharacter.Move(BACKWARD, DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
PlayerCharacter.Move(LEFT, DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_F) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
PlayerCharacter.Move(RIGHT, DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
PlayerCharacter.Jump();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
PlayerCharacter.Sprint();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_LEFT_SHIFT) == GLFW_RELEASE)
|
||||||
|
{
|
||||||
|
PlayerCharacter.StopSprint();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
if (bFreeMouse)
|
||||||
|
{
|
||||||
|
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
bFirstMouse = true;
|
||||||
|
bFreeMouse = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerInputComponent::ProcessMouse(GLFWwindow* Window, double xposIn, double yposIn)
|
||||||
|
{
|
||||||
|
PlayerInputComponent* instance = static_cast<PlayerInputComponent*>(glfwGetWindowUserPointer(Window));
|
||||||
|
if (!instance)
|
||||||
|
{
|
||||||
|
std::cout << "Player Input Component not found" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS && instance->bFreeMouse)
|
||||||
|
//{
|
||||||
|
// glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
// instance->bFirstMouse = true;
|
||||||
|
// instance->bFreeMouse = false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
if (instance->bFreeMouse)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//std::cout << "Mouse callback" << std::endl;
|
||||||
|
float xpos = static_cast<float>(xposIn);
|
||||||
|
float ypos = static_cast<float>(yposIn);
|
||||||
|
|
||||||
|
if (instance->bFirstMouse)
|
||||||
|
{
|
||||||
|
instance->lastX = xpos;
|
||||||
|
instance->lastY = ypos;
|
||||||
|
instance->bFirstMouse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float xoffset = xpos - instance->lastX;
|
||||||
|
float yoffset = instance->lastY - ypos;
|
||||||
|
|
||||||
|
instance->lastX = xpos;
|
||||||
|
instance->lastY = ypos;
|
||||||
|
|
||||||
|
instance->PlayerCharacter.Look(xoffset, yoffset);
|
||||||
|
}
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <InputComponent.h>
|
#include <IInputComponent.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <InputEnums.h>
|
||||||
|
|
||||||
enum EInputDirection
|
class Player;
|
||||||
{
|
|
||||||
FORWARD,
|
|
||||||
BACKWARD,
|
|
||||||
LEFT,
|
|
||||||
RIGHT
|
|
||||||
};
|
|
||||||
|
|
||||||
class PlayerInputComponent : public InputComponent
|
class PlayerInputComponent : public IInputComponent
|
||||||
{
|
{
|
||||||
private:
|
Player& PlayerCharacter;
|
||||||
|
float lastX = 1600 / 2.0f;
|
||||||
|
float lastY = 900 / 2.0f;
|
||||||
|
bool bFirstMouse = true;
|
||||||
|
bool bFreeMouse = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Update(float deltaTime)
|
PlayerInputComponent(GLFWwindow* Window, Player& PlayerCharacter);
|
||||||
{
|
void Update(float DeltaTime) override;
|
||||||
|
void ProcessKeyboard(float DeltaTime);
|
||||||
}
|
static void ProcessMouse(GLFWwindow* Window, double xposIn, double yposIn);
|
||||||
};
|
};
|
||||||
|
|||||||
115
camera.h
115
camera.h
@@ -2,17 +2,18 @@
|
|||||||
#ifndef CAMERA_H
|
#ifndef CAMERA_H
|
||||||
#define CAMERA_H
|
#define CAMERA_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
enum Camera_Movement
|
#include <GameObject.h>
|
||||||
{
|
#include <MeshRenderer.h>
|
||||||
_FORWARD,
|
#include <LevelMap.h>
|
||||||
_BACKWARD,
|
#include <PointLight.h>
|
||||||
_LEFT,
|
|
||||||
_RIGHT
|
|
||||||
};
|
|
||||||
|
|
||||||
const float YAW = -90.0f;
|
const float YAW = -90.0f;
|
||||||
const float PITCH = 0.0f;
|
const float PITCH = 0.0f;
|
||||||
@@ -20,97 +21,35 @@ const float SPEED = 5.0f;
|
|||||||
const float MOUSE_SENSITIVITY = 0.1f;
|
const float MOUSE_SENSITIVITY = 0.1f;
|
||||||
const float ZOOM = 45.0f;
|
const float ZOOM = 45.0f;
|
||||||
|
|
||||||
class Camera
|
class Camera : public GameObject
|
||||||
{
|
{
|
||||||
public:
|
glm::vec3 Offset;
|
||||||
glm::vec3 Position;
|
|
||||||
glm::vec3 Front;
|
|
||||||
glm::vec3 Up;
|
|
||||||
glm::vec3 Right;
|
|
||||||
glm::vec3 WorldUp;
|
|
||||||
glm::vec3 CameraOffset;
|
|
||||||
|
|
||||||
float Yaw;
|
float Yaw;
|
||||||
float Pitch;
|
float Pitch;
|
||||||
|
|
||||||
float MovementSpeed;
|
float MovementSpeed;
|
||||||
float MouseSensitivity;
|
float MouseSensitivity;
|
||||||
float Zoom;
|
float Zoom;
|
||||||
|
|
||||||
Camera(
|
GLFWwindow* Window;
|
||||||
glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f),
|
|
||||||
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f),
|
|
||||||
glm::vec3 offset = glm::vec3(0.0f, 1.0f, 0.0f),
|
|
||||||
float yaw = YAW,
|
|
||||||
float pitch = PITCH)
|
|
||||||
:
|
|
||||||
Front(glm::vec3(0.0f, 0.0f, -1.0f)),
|
|
||||||
MovementSpeed(SPEED),
|
|
||||||
MouseSensitivity(MOUSE_SENSITIVITY),
|
|
||||||
Zoom(ZOOM)
|
|
||||||
{
|
|
||||||
Position = position;
|
|
||||||
CameraOffset = offset;
|
|
||||||
WorldUp = up;
|
|
||||||
Yaw = yaw;
|
|
||||||
Pitch = pitch;
|
|
||||||
updateCameraVectors();
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 GetViewMatrix()
|
public:
|
||||||
{
|
Camera(GLFWwindow* Window);
|
||||||
return glm::lookAt(Position, Position + Front, Up);
|
~Camera() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessKeyboard(Camera_Movement direction, float deltaTime)
|
glm::mat4 GetViewMatrix();
|
||||||
{
|
void SetOffset(glm::vec3 Offset);
|
||||||
float velocity = MovementSpeed * deltaTime;
|
void MoveCamera(glm::vec3 Position);
|
||||||
if (direction == _FORWARD)
|
void RotateCamera(float Yaw, float Pitch, GLboolean bConstrainPitch = true);
|
||||||
Position += Front * velocity;
|
void ZoomCamera(float ZoomAmount);
|
||||||
if (direction == _BACKWARD)
|
void RenderScene(
|
||||||
Position -= Front * velocity;
|
LevelMap& LevelMap,
|
||||||
if (direction == _LEFT)
|
const std::vector<PointLight>& Lights,
|
||||||
Position -= Right * velocity;
|
int ScreenWidth,
|
||||||
if (direction == _RIGHT)
|
int ScreenHeight
|
||||||
Position += Right * velocity;
|
);
|
||||||
}
|
glm::mat4 GetProjectionMatrix(int ScreenWidth, int ScreenHeight);
|
||||||
|
|
||||||
void ProcessMouseMovement(float XOffset, float YOffset, GLboolean bConstrainPitch = true)
|
|
||||||
{
|
|
||||||
//Yaw += XOffset;
|
|
||||||
Pitch += YOffset;
|
|
||||||
|
|
||||||
if (bConstrainPitch)
|
|
||||||
{
|
|
||||||
if (Pitch > 89.0f)
|
|
||||||
Pitch = 89.0f;
|
|
||||||
if (Pitch < -89.0f)
|
|
||||||
Pitch = -89.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCameraVectors();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessMouseScroll(float yoffset)
|
|
||||||
{
|
|
||||||
Zoom -= (float)yoffset;
|
|
||||||
if (Zoom < 1.0f)
|
|
||||||
Zoom = 1.0f;
|
|
||||||
if (Zoom > 45.0f)
|
|
||||||
Zoom = 45.0f;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
|
|
||||||
void updateCameraVectors()
|
|
||||||
{
|
|
||||||
glm::vec3 front;
|
|
||||||
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
|
||||||
front.y = sin(glm::radians(Pitch));
|
|
||||||
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
|
||||||
Front = glm::normalize(front);
|
|
||||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
|
||||||
Up = glm::normalize(glm::cross(Right, Front));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,7 +4,7 @@ Size=400,400
|
|||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Settings]
|
[Window][Settings]
|
||||||
Pos=69,71
|
Pos=85,43
|
||||||
Size=445,126
|
Size=445,126
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
|||||||
84
input.txt
Normal file
84
input.txt
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <IInputComponent.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <InputEnums.h>
|
||||||
|
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
|
||||||
|
class deadPlayerInputComponent : public IInputComponent
|
||||||
|
{
|
||||||
|
Player& PlayerCharacter;
|
||||||
|
float lastX = 1600 / 2.0f;
|
||||||
|
float lastY = 900 / 2.0f;
|
||||||
|
bool bFirstMouse = true;
|
||||||
|
|
||||||
|
public:
|
||||||
|
deadPlayerInputComponent(GLFWwindow* Window, Player& PlayerCharacter)
|
||||||
|
: IInputComponent(Window),
|
||||||
|
PlayerCharacter(PlayerCharacter)
|
||||||
|
{
|
||||||
|
glfwSetWindowUserPointer(Window, this);
|
||||||
|
glfwSetCursorPosCallback(Window, ProcessMouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update(float DeltaTime) override
|
||||||
|
{
|
||||||
|
ProcessKeyboard(DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessKeyboard(float DeltaTime)
|
||||||
|
{
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
|
//glfwSetWindowShouldClose(Window, true);
|
||||||
|
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
|
PlayerCharacter.ProcessKeyboard(FORWARD, DeltaTime);
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
|
PlayerCharacter.ProcessKeyboard(BACKWARD, DeltaTime);
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_A) == GLFW_PRESS)
|
||||||
|
PlayerCharacter.ProcessKeyboard(LEFT, DeltaTime);
|
||||||
|
if (glfwGetKey(Window, GLFW_KEY_D) == GLFW_PRESS)
|
||||||
|
PlayerCharacter.ProcessKeyboard(RIGHT, DeltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ProcessMouse(GLFWwindow* Window, double xposIn, double yposIn)
|
||||||
|
{
|
||||||
|
deadPlayerInputComponent* instance = static_cast<deadPlayerInputComponent*>(glfwGetWindowUserPointer(Window));
|
||||||
|
if (!instance)
|
||||||
|
{
|
||||||
|
std::cout << "Player Input Component not found" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
instance->bFirstMouse = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
//std::cout << "Mouse callback" << std::endl;
|
||||||
|
float xpos = static_cast<float>(xposIn);
|
||||||
|
float ypos = static_cast<float>(yposIn);
|
||||||
|
|
||||||
|
if (instance->bFirstMouse)
|
||||||
|
{
|
||||||
|
instance->lastX = xpos;
|
||||||
|
instance->lastY = ypos;
|
||||||
|
instance->bFirstMouse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float xoffset = xpos - instance->lastX;
|
||||||
|
float yoffset = instance->lastY - ypos;
|
||||||
|
|
||||||
|
instance->lastX = xpos;
|
||||||
|
instance->lastY = ypos;
|
||||||
|
|
||||||
|
instance->PlayerCharacter.ProcessMouseMovement(xoffset, yoffset);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
271
main.cpp
271
main.cpp
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@@ -17,52 +18,42 @@
|
|||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
#include "PointLight.h"
|
#include "PointLight.h"
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void FramebufferSizeCallback(GLFWwindow* window, int width, int height);
|
||||||
void processInput(GLFWwindow* window);
|
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
|
||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
|
||||||
|
|
||||||
int SCR_WIDTH = 1600;
|
int SCR_WIDTH = 1600;
|
||||||
int SCR_HEIGHT = 900;
|
int SCR_HEIGHT = 900;
|
||||||
|
|
||||||
//Camera camera(glm::vec3(20.0f, 1.0f, 20.0f));
|
//Camera camera(glm::vec3(20.0f, 1.0f, 20.0f));
|
||||||
glm::vec3 StartingPosition = glm::vec3(20.0f, 0.0f, 20.0f);
|
Player* PlayerCharacter = nullptr;
|
||||||
glm::vec3 StartingRotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
Player PlayerCharacter(StartingPosition, StartingRotation);
|
|
||||||
|
|
||||||
float lastX = SCR_WIDTH / 2.0f;
|
float LastX = SCR_WIDTH / 2.0f;
|
||||||
float lastY = SCR_HEIGHT / 2.0f;
|
float LastY = SCR_HEIGHT / 2.0f;
|
||||||
bool firstMouse = true;
|
bool FirstMouse = true;
|
||||||
|
|
||||||
float deltaTime = 0.0f;
|
float DeltaTime = 0.0f;
|
||||||
float lastFrame = 0.0f;
|
float LastFrame = 0.0f;
|
||||||
float elapsedTime = 0.0f;
|
float ElapsedTime = 0.0f;
|
||||||
|
|
||||||
int amountOfCubes = 1000;
|
|
||||||
|
|
||||||
//glm::vec3 lightPos(1.2f, 1.0f, 2.0f);
|
//glm::vec3 lightPos(1.2f, 1.0f, 2.0f);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const char* glsl_version = "#version 330";
|
const char* GLSLVersion = "#version 330";
|
||||||
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
|
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearningOpenGl", NULL, NULL);
|
GLFWwindow* Window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearningOpenGl", NULL, NULL);
|
||||||
if (window == NULL) {
|
if (Window == NULL) {
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(Window);
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(Window, FramebufferSizeCallback);
|
||||||
glfwSetCursorPosCallback(window, mouse_callback);
|
|
||||||
glfwSetScrollCallback(window, scroll_callback);
|
|
||||||
|
|
||||||
//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
@@ -85,68 +76,44 @@ int main()
|
|||||||
//ImGui_ImplGlfw_InitForOpenGL(window, true);
|
//ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
//ImGui_ImplOpenGL3_Init(glsl_version);
|
//ImGui_ImplOpenGL3_Init(glsl_version);
|
||||||
|
|
||||||
if (!ImGui_ImplGlfw_InitForOpenGL(window, true)) {
|
if (!ImGui_ImplGlfw_InitForOpenGL(Window, true)) {
|
||||||
std::cout << "Failed to initialize ImGui GLFW backend" << std::endl;
|
std::cout << "Failed to initialize ImGui GLFW backend" << std::endl;
|
||||||
}
|
}
|
||||||
if (!ImGui_ImplOpenGL3_Init(glsl_version)) {
|
if (!ImGui_ImplOpenGL3_Init(GLSLVersion)) {
|
||||||
std::cout << "Failed to initialize ImGui OpenGL backend" << std::endl;
|
std::cout << "Failed to initialize ImGui OpenGL backend" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader simple_depth_shader = ResourceManager::LoadShader("point_shadow_depth.vert", "point_shadow_depth.frag", "point_shadow_depth.geom", "simple_depth_shader");
|
Shader SimpleDepthShader = ResourceManager::LoadShader("point_shadow_depth.vert", "point_shadow_depth.frag", "point_shadow_depth.geom", "simple_depth_shader");
|
||||||
|
|
||||||
Shader wall_shader = ResourceManager::LoadShader("wall_test.vert", "wall_test.frag", nullptr, "wall");
|
Shader WallShader = ResourceManager::LoadShader("wall_test.vert", "wall_test.frag", nullptr, "wall");
|
||||||
|
|
||||||
LevelMap level_map = ResourceManager::LoadLevelMap("map_test.txt", "test_level");
|
LevelMap CurrentLevelMap = ResourceManager::LoadLevelMap("map_test.txt", "test_level");
|
||||||
|
|
||||||
level_map.RenderSetup(&wall_shader, &wall_shader, &wall_shader);
|
CurrentLevelMap.RenderSetup(&WallShader, &WallShader, &WallShader);
|
||||||
|
|
||||||
int number_of_point_lights = 0;
|
glm::vec3 StartingPosition = glm::vec3(20.0f, 0.0f, 20.0f);
|
||||||
|
glm::vec3 StartingRotation = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
PlayerCharacter = new Player(StartingPosition, StartingRotation, CurrentLevelMap.GetSectors(), Window);
|
||||||
|
|
||||||
std::vector<PointLight> point_lights_vector;
|
int NumberOfPointLights = 0;
|
||||||
|
std::vector<PointLight> PointLightsVector;
|
||||||
//PointLight point_light3(glm::vec3(30.0f, 3.0f, 30.0f), glm::vec3(1.0f, 1.0f, 1.0f), simple_depth_shader);
|
|
||||||
|
|
||||||
//PointLight point_light2(glm::vec3(70.0f, 2.0f, 55.0f), glm::vec3(1.0f, 1.0f, 1.0f), simple_depth_shader);
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position + glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), WallShader));
|
||||||
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position + glm::vec3(10.0f, 1.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), WallShader));
|
||||||
//PointLight point_light(glm::vec3(20.0f, 3.0f, 35.0f), glm::vec3(1.0f, 1.0f, 1.0f), simple_depth_shader);
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position + glm::vec3(0.0f, 2.0f, 10.0f), glm::vec3(1.0f, 1.0f, 1.0f), WallShader));
|
||||||
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position + glm::vec3(20.0f, 3.0f, 10.0f), glm::vec3(1.0f, 1.0f, 1.0f), WallShader));
|
||||||
//PointLight point_lights[3] = { point_light, point_light2, point_light3 };
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position + glm::vec3(25.0f, 2.0f, 20.0f), glm::vec3(1.0f, 1.0f, 1.0f), WallShader));
|
||||||
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position + glm::vec3(50.0f, 1.0f, 30.0f), glm::vec3(1.0f, 1.0f, 1.0f), WallShader));
|
||||||
/*unsigned int depthCubemap, depthMapFBO;
|
NumberOfPointLights = PointLightsVector.size();
|
||||||
|
|
||||||
glGenFramebuffers(1, &depthMapFBO);
|
|
||||||
glGenTextures(1, &depthCubemap);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 6; ++i)
|
|
||||||
{
|
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
|
||||||
}
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
|
||||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap, 0);
|
|
||||||
glDrawBuffer(GL_NONE);
|
|
||||||
glReadBuffer(GL_NONE);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);*/
|
|
||||||
|
|
||||||
float r = 0.05f, g = 0.05f, b = 0.05f;
|
float r = 0.05f, g = 0.05f, b = 0.05f;
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(Window)) {
|
||||||
//timing
|
//timing
|
||||||
float currentFrame = (float)glfwGetTime();
|
float currentFrame = (float)glfwGetTime();
|
||||||
deltaTime = currentFrame - lastFrame;
|
DeltaTime = currentFrame - LastFrame;
|
||||||
lastFrame = currentFrame;
|
LastFrame = currentFrame;
|
||||||
elapsedTime += deltaTime;
|
ElapsedTime += DeltaTime;
|
||||||
|
|
||||||
//input
|
|
||||||
processInput(window);
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
@@ -154,11 +121,10 @@ int main()
|
|||||||
|
|
||||||
ImGui::Begin("Settings");
|
ImGui::Begin("Settings");
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||||
if (ImGui::Button("Create Light") && number_of_point_lights < 10) {
|
if (ImGui::Button("Create Light") && NumberOfPointLights < 10) {
|
||||||
point_lights_vector.push_back(PointLight(PlayerCharacter.Position, glm::vec3(1.0f, 1.0f, 1.0f), simple_depth_shader));
|
PointLightsVector.push_back(PointLight(PlayerCharacter->Position, glm::vec3(1.0f, 1.0f, 1.0f), SimpleDepthShader));
|
||||||
number_of_point_lights = point_lights_vector.size();
|
NumberOfPointLights = PointLightsVector.size();
|
||||||
}
|
}
|
||||||
//ImGui::SliderInt("Amount of cubes: ", &amountOfCubes, 0, 1000);
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
@@ -168,63 +134,46 @@ int main()
|
|||||||
glClearColor(r, g, b, 1.0f);
|
glClearColor(r, g, b, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
//glDisable(GL_CULL_FACE);
|
for (PointLight& point_light : PointLightsVector)
|
||||||
|
|
||||||
//level_map.GetMeshes();
|
|
||||||
|
|
||||||
for (PointLight& point_light : point_lights_vector)
|
|
||||||
{
|
{
|
||||||
point_light.RenderSceneShadows(level_map.GetMeshes());
|
point_light.RenderSceneShadows(CurrentLevelMap.GetMeshes());
|
||||||
}
|
}
|
||||||
|
|
||||||
//for (int i = 0; i < numOfPointLights; i++)
|
|
||||||
//{
|
|
||||||
// point_lights[i].RenderSceneShadows(level_map.GetMeshes());
|
|
||||||
//}
|
|
||||||
|
|
||||||
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
|
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
wall_shader.Use();
|
WallShader.Use();
|
||||||
// CHANGED PROJECTION TO USE FLAT 45 TO GET PLAYER CHARACTER TO WORK
|
// CHANGED PROJECTION TO USE FLAT 45 TO GET PLAYER CHARACTER TO WORK
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||||
glm::mat4 view = PlayerCharacter.GetViewMatrix();
|
glm::mat4 view = PlayerCharacter->GetViewMatrix();
|
||||||
wall_shader.SetMatrix4("projection", projection);
|
WallShader.SetMatrix4("projection", projection);
|
||||||
wall_shader.SetMatrix4("view", view);
|
WallShader.SetMatrix4("view", view);
|
||||||
wall_shader.SetVector3f("viewPosition", PlayerCharacter.Position);
|
WallShader.SetVector3f("viewPosition", PlayerCharacter->PlayerCamera->Position);
|
||||||
|
|
||||||
wall_shader.SetVector3f("material.ambientColor", glm::vec3(1.0f, 0.0f, 0.0f));
|
WallShader.SetVector3f("material.ambientColor", glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
wall_shader.SetVector3f("material.diffuseColor", glm::vec3(0.5f, 0.5f, 0.5f));
|
WallShader.SetVector3f("material.diffuseColor", glm::vec3(0.5f, 0.5f, 0.5f));
|
||||||
wall_shader.SetVector3f("material.specularColor", glm::vec3(0.0f, 0.0f, 1.0f));
|
WallShader.SetVector3f("material.specularColor", glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
wall_shader.SetFloat("material.shininess", 1.0f);
|
WallShader.SetFloat("material.shininess", 1.0f);
|
||||||
// set lighting uniforms
|
// set lighting uniforms
|
||||||
wall_shader.SetInteger("numOfPointLights", number_of_point_lights);
|
WallShader.SetInteger("numOfPointLights", NumberOfPointLights);
|
||||||
int light_index = 0;
|
int light_index = 0;
|
||||||
for (PointLight& point_light : point_lights_vector)
|
for (PointLight& point_light : PointLightsVector)
|
||||||
{
|
{
|
||||||
std::string name = "pointLights[" + std::to_string(light_index) + "].";
|
std::string name = "pointLights[" + std::to_string(light_index) + "].";
|
||||||
wall_shader.SetVector3f((name + "base.color").c_str(), point_light.color);
|
WallShader.SetVector3f((name + "base.color").c_str(), point_light.color);
|
||||||
wall_shader.SetFloat((name + "base.ambientIntensity").c_str(), point_light.ambient_intensity);
|
WallShader.SetFloat((name + "base.ambientIntensity").c_str(), point_light.ambient_intensity);
|
||||||
wall_shader.SetFloat((name + "base.diffuseIntensity").c_str(), point_light.diffuse_intensity);
|
WallShader.SetFloat((name + "base.diffuseIntensity").c_str(), point_light.diffuse_intensity);
|
||||||
wall_shader.SetFloat((name + "atten.constant").c_str(), point_light.attenuation_constant);
|
WallShader.SetFloat((name + "atten.constant").c_str(), point_light.attenuation_constant);
|
||||||
wall_shader.SetFloat((name + "atten.linear").c_str(), point_light.attenuation_linear);
|
WallShader.SetFloat((name + "atten.linear").c_str(), point_light.attenuation_linear);
|
||||||
wall_shader.SetFloat((name + "atten.exponential").c_str(), point_light.attenuation_exponential);
|
WallShader.SetFloat((name + "atten.exponential").c_str(), point_light.attenuation_exponential);
|
||||||
wall_shader.SetVector3f((name + "position").c_str(), point_light.Position);
|
WallShader.SetVector3f((name + "position").c_str(), point_light.Position);
|
||||||
wall_shader.SetFloat((name + "farPlane").c_str(), point_light.far_plane);
|
WallShader.SetFloat((name + "farPlane").c_str(), point_light.far_plane);
|
||||||
wall_shader.SetInteger((name + "depthMap").c_str(), light_index);
|
WallShader.SetInteger((name + "depthMap").c_str(), light_index);
|
||||||
glActiveTexture(GL_TEXTURE0 + light_index);
|
glActiveTexture(GL_TEXTURE0 + light_index);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, point_light.depth_map);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, point_light.depth_map);
|
||||||
|
|
||||||
light_index++;
|
light_index++;
|
||||||
}
|
}
|
||||||
/*wall_shader.SetVector3f("pointLights[0].base.color", point_light.color);
|
|
||||||
wall_shader.SetVector3f("pointLights[0].base.ambientIntensity", point_light.ambient);
|
|
||||||
wall_shader.SetVector3f("pointLights[0].position", point_light.position);
|
|
||||||
wall_shader.SetVector3f("lightPosition2", point_light2.position);
|
|
||||||
wall_shader.SetVector3f("lightColor", point_light.color);*/
|
|
||||||
//wall_shader.SetInteger("shadows", 1); // enable/disable shadows by pressing 'SPACE'
|
|
||||||
//wall_shader.SetInteger("depthMap", 0);
|
|
||||||
|
|
||||||
|
|
||||||
GLenum err;
|
GLenum err;
|
||||||
while(err = glGetError())
|
while(err = glGetError())
|
||||||
@@ -232,49 +181,18 @@ int main()
|
|||||||
std::cout << "Error: " << err << std::endl;
|
std::cout << "Error: " << err << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* mesh : level_map.GetMeshes())
|
PlayerCharacter->Update(DeltaTime);
|
||||||
|
//PlayerCharacter->PlayerCamera->RenderScene(CurrentLevelMap, PointLightsVector, SCR_WIDTH, SCR_HEIGHT);
|
||||||
|
|
||||||
|
for (auto* mesh : CurrentLevelMap.GetMeshes())
|
||||||
{
|
{
|
||||||
// //std::cout << "Rendering mesh" << std::endl;
|
// //std::cout << "Rendering mesh" << std::endl;
|
||||||
mesh->Render(wall_shader);
|
mesh->Render(WallShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*float near_plane = 1.0f;
|
|
||||||
float far_plane = 50.0f;
|
|
||||||
glm::mat4 shadowProj = glm::perspective(glm::radians(90.0f), (float)SHADOW_WIDTH / (float)SHADOW_HEIGHT, near_plane, far_plane);*/
|
|
||||||
/*std::vector<glm::mat4> shadowTransforms;
|
|
||||||
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
|
|
||||||
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
|
|
||||||
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)));
|
|
||||||
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)));
|
|
||||||
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)));
|
|
||||||
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f)));*/
|
|
||||||
|
|
||||||
/*glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
|
||||||
glCullFace(GL_FRONT);
|
|
||||||
simpleDepthShader.Use();
|
|
||||||
for (unsigned int i = 0; i < 6; ++i)
|
|
||||||
simpleDepthShader.SetMatrix4("shadowMatrices[" + std::to_string(i) + "]", shadowTransforms[i]);
|
|
||||||
simpleDepthShader.SetFloat("far_plane", far_plane);
|
|
||||||
simpleDepthShader.SetVector3f("lightPos", lightPos);
|
|
||||||
levelMap.Update(projection, view);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
|
|
||||||
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap);*/
|
|
||||||
//map.render(projection, view, lightPos, deltaTime, glm::vec3(SCR_WIDTH, SCR_HEIGHT, 0.0f), far_plane);
|
|
||||||
|
|
||||||
//level_map.Update(projection, view, point_light.position, point_light.color, camera.Position);
|
|
||||||
|
|
||||||
//cubeFactory.render(view, projection, lightPos, deltaTime, amountOfCubes);
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
//check and call
|
//check and call
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(Window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,63 +200,12 @@ int main()
|
|||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(Window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
void FramebufferSizeCallback(GLFWwindow* window, int width, int height)
|
||||||
{
|
{
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void processInput(GLFWwindow* window)
|
|
||||||
{
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
|
||||||
glfwSetWindowShouldClose(window, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const float cameraSpeed = 5.0f * deltaTime;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
|
||||||
PlayerCharacter.ProcessKeyboard(FORWARD, deltaTime);
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
|
||||||
PlayerCharacter.ProcessKeyboard(BACKWARD, deltaTime);
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
|
||||||
PlayerCharacter.ProcessKeyboard(LEFT, deltaTime);
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
|
||||||
PlayerCharacter.ProcessKeyboard(RIGHT, deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
|
|
||||||
{
|
|
||||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != GLFW_PRESS)
|
|
||||||
{
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
||||||
firstMouse = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
|
||||||
//std::cout << "Mouse callback" << std::endl;
|
|
||||||
float xpos = static_cast<float>(xposIn);
|
|
||||||
float ypos = static_cast<float>(yposIn);
|
|
||||||
|
|
||||||
if (firstMouse)
|
|
||||||
{
|
|
||||||
lastX = xpos;
|
|
||||||
lastY = ypos;
|
|
||||||
firstMouse = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float xoffset = xpos - lastX;
|
|
||||||
float yoffset = lastY - ypos;
|
|
||||||
|
|
||||||
lastX = xpos;
|
|
||||||
lastY = ypos;
|
|
||||||
|
|
||||||
PlayerCharacter.ProcessMouseMovement(xoffset, yoffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
|
||||||
{
|
|
||||||
//PlayerCharacter.ProcessMouseScroll(static_cast<float>(yoffset));
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user