"Drips in Elmer's Glue", Cameras are hard.

This commit is contained in:
Edward R. Gonzalez 2020-02-15 02:21:27 -05:00
parent 2b71f57284
commit b3b81b65fe
12 changed files with 699 additions and 130 deletions

View File

@ -21,6 +21,10 @@ This merely removes the need to use operators I don't like and wraps them in eas
#include <stdexcept>
#include <string>
#include <vector>
#include <chrono>
#include <thread>
#include <memory>
#include <functional>
@ -53,6 +57,12 @@ using ptr = Type*;
template<typename ReturnType, typename... ParamTypes>
using FnPtr = ReturnType(*)(ParamTypes...);
template<typename FnType>
using Delegate = std::function<FnType>;
template<typename ReturnType, typename... ParamTypes>
using Func = ReturnType(ParamTypes...);
// Strings
template<typename CharType>

72
DGL.hpp
View File

@ -19,7 +19,7 @@
namespace GL
namespace DGL
{
// Aliases
@ -31,10 +31,10 @@ namespace GL
// GLFW
using Monitor = GLFWmonitor ;
using TimeValInt = uint64_t ;
using TimeValDec = double ;
using Window = GLFWwindow ;
using Monitor = GLFWmonitor;
using TimeValInt = uint64_t;
using TimeValDec = double;
using Window = GLFWwindow;
using WindowRefList = std::vector< ptr<Window> >;
@ -65,10 +65,10 @@ namespace GL
sfn CreateWindow
(
int _width ,
int _height ,
RawString<const char> _title ,
ptr <Monitor > _monitorToFullscreen ,
int _width,
int _height,
RawString<const char> _title,
ptr <Monitor > _monitorToFullscreen,
ptr <Window > _windowToShareResourcesWith
)
-> ptr<Window>
@ -109,6 +109,16 @@ namespace GL
return;
}
sfn CanUseRawMouse()
{
return glfwRawMouseMotionSupported();
}
sfn CursorPositionUpdateBind(ptr<Window> _window, FnPtr<void, double, double> _functionToCall)
{
glfwSetCursorPosCallback(_window, GLFWcursorposfun(_functionToCall));
}
sfn DrawArrays(EPrimitives _primitive, gInt _startingIndex, gInt _numToRender)
{
glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle.
@ -119,6 +129,22 @@ namespace GL
glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex);
}
sfn KeyPressed(ptr<Window> _contextWindowRef, EKeyCodes _keyToCheck) -> bool
{
return glfwGetKey(_contextWindowRef, int(_keyToCheck)) ;
}
template<typename... CodeType, typename = EKeyCodes>
sfn KeysPressed(ptr<Window> _contextWindowRef, CodeType... _otherKeys) -> bool
{
return ( KeyPressed(_contextWindowRef, _otherKeys) && ... ) == true;
}
sfn GetMouseInputMode(ptr<Window> _contextWindowRef, EMouseMode _mode)
{
return glfwGetInputMode(_contextWindowRef, GLenum(_mode));
}
sfn GetTime() -> TimeValDec
{
return glfwGetTime();
@ -129,6 +155,19 @@ namespace GL
return glfwGetTimerValue();
}
sfn GetCursorPosition(ptr<Window> _window, ptr<double> _xAxis, ptr<double> _yAxis)
{
glfwGetCursorPos(_window, _xAxis, _yAxis);
}
sfn ResetCursor(ptr<Window> _window, gFloat _screenCenterWidth, gFloat _screenCenterHeight)
{
glfwSetCursorPos(_window, _screenCenterWidth, _screenCenterHeight);
glfwSetCursorPos(_window, 0, 0);
}
sfn InitalizeGLFW()
{
try
@ -202,7 +241,7 @@ namespace GL
return;
}
sfn RunBasicWindowLoop_Timed(const ptr<Window> _window, TimeValDec _interval, FnPtr<void> _renderProcedure)
sfn RunBasicWindowLoop_Timed(const ptr<Window> _window, TimeValDec _interval, Delegate< Func<void>> _renderProcedure)
{
TimeValDec start, end, deltaSinceClear = 0.0;
@ -236,6 +275,17 @@ namespace GL
return;
}
sfn SetClearColor(LinearColor _colorToSet)
{
glClearColor(_colorToSet.Red, _colorToSet.Green, _colorToSet.Blue, _colorToSet.Alpha);
}
template<typename ModeParam>
sfn SetInputMode(ptr<Window> _window, EMouseMode _mouseMode, ModeParam _modeParam)
{
glfwSetInputMode(_window, GLenum(_mouseMode), GLenum(_modeParam));
}
sfn RunTimingLoop()
{
return;
@ -266,7 +316,7 @@ namespace GL
return;
}
sfn SetPolygonMode(EFace _desiredFaces, EMode _desiredMode)
sfn SetPolygonMode(EFace _desiredFaces, ERenderMode _desiredMode)
{
glPolygonMode(GLenum(_desiredFaces), GLenum(_desiredMode));
}

View File

@ -13,7 +13,7 @@
namespace GL
namespace DGL
{
sfn BindBuffer(const EBufferTarget _targetType, const ID<Buffer> _buffer)
{

View File

@ -5,14 +5,40 @@
namespace GL
namespace DGL
{
enum class EAxis
{
X, Y, Z
};
enum class ERotationAxis
{
Pitch, Yaw, Roll
};
enum class EBool
{
True = GL_TRUE ,
False = GL_FALSE
};
enum class EMouseMode
{
Cursor = GLFW_CURSOR ,
RawMouse = GLFW_RAW_MOUSE_MOTION ,
StickyKeys = GLFW_STICKY_KEYS ,
StickMouse = GLFW_STICKY_MOUSE_BUTTONS,
LockKey = GLFW_LOCK_KEY_MODS ,
};
enum class ECursorMode
{
Normal = GLFW_CURSOR_NORMAL ,
Hidden = GLFW_CURSOR_HIDDEN ,
Disable = GLFW_CURSOR_DISABLED
};
enum class EBufferTarget
{
VertexAttributes = GL_ARRAY_BUFFER ,
@ -66,10 +92,20 @@ namespace GL
Double = GL_DOUBLE
};
enum class EDirection
{
Up ,
Down ,
Left ,
Right ,
Forward ,
Backward
};
enum class EFace
{
Front = GL_FRONT,
Back = GL_BACK,
Front = GL_FRONT ,
Back = GL_BACK ,
Front_and_Back = GL_FRONT_AND_BACK
};
@ -81,6 +117,24 @@ namespace GL
Stencil = GL_STENCIL_BUFFER_BIT
};
enum class EKeyCodes
{
F1 = GLFW_KEY_F1 ,
A = GLFW_KEY_A ,
D = GLFW_KEY_D ,
E = GLFW_KEY_E ,
Q = GLFW_KEY_Q ,
S = GLFW_KEY_S ,
W = GLFW_KEY_W ,
LeftShift = GLFW_KEY_LEFT_SHIFT
};
enum class EKeyState
{
Pressed = GLFW_PRESS ,
Released = GLFW_RELEASE
};
enum class ELODBias
{
Max = GL_MAX_TEXTURE_LOD_BIAS
@ -102,13 +156,15 @@ namespace GL
LinearToLinear = GL_LINEAR_MIPMAP_LINEAR
};
enum class EMode
enum class ERenderMode
{
Point = GL_POINT,
Line = GL_LINE ,
Fill = GL_FILL
};
enum class EPrimitives
{
Points = GL_POINTS,

View File

@ -5,14 +5,15 @@
namespace GL
namespace DGL
{
// Fundamental Types
using gChar = GLchar ;
using gBitfield = GLbitfield;
using gFloat = GLfloat ;
using gInt = GLint ;
using gUInt = GLuint ;
using gSize = GLsizei ;
using gChar = GLchar ;
using gBitfield = GLbitfield;
using gFloat = GLfloat ;
using gFloatClamped = GLclampf ;
using gInt = GLint ;
using gUInt = GLuint ;
using gSize = GLsizei ;
}

View File

@ -13,7 +13,7 @@
namespace GL
namespace DGL
{
namespace Generic
{
@ -26,6 +26,15 @@ namespace GL
template<typename ReferenceType>
using ID = gUInt;
struct LinearColor
{
gFloatClamped Red, Green, Blue, Alpha;
LinearColor(gFloatClamped _red, gFloatClamped _green, gFloatClamped _blue, gFloatClamped _alpha) :
Red(_red), Green(_green), Blue(_blue), Alpha(_alpha) {};
};
// ID Reference Types
class Buffer;

View File

@ -5,7 +5,7 @@
namespace GL
namespace DGL
{
struct Primitive

View File

@ -8,7 +8,7 @@
namespace GL
namespace DGL
{
// Some Raw Source Defaults:
@ -45,10 +45,10 @@ namespace GL
// Forward Declarations
sfn GetShaderInfo(ID<Shader> _shader , gSize _logLength , ptr<gSize> _infoLengthRef , RawString<gChar> _infoLogRef) -> void;
sfn QueryShader (ID<Shader> _shaderToQuery, EShaderInfo _shaderInfoDesired, ptr<gInt > _requestedInfoObject ) -> void;
sfn MakeShader(Ref(ID<Shader>) _shaderIDHolder, EShaderType _typeOfShader, uInt64 _numberOfStringElements, ptr<RawString<const gChar>> _sourceCode, ptr<const gInt> _lengthsOfStrings) -> void;
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder, const ID<Shader> _vertexShader, const ID<Shader> _fragShader) -> void;
sfn GetShaderInfo ( ID<Shader > _shader , gSize _logLength , ptr<gSize> _infoLengthRef , RawString<gChar> _infoLogRef) -> void;
sfn QueryShader ( ID<Shader > _shaderToQuery , EShaderInfo _shaderInfoDesired, ptr<gInt > _requestedInfoObject ) -> void;
sfn MakeShader (Ref(ID<Shader >) _shaderIDHolder , EShaderType _typeOfShader , uInt64 _numberOfStringElements, ptr<RawString<const gChar>> _sourceCode, ptr<const gInt> _lengthsOfStrings) -> void;
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder, const ID<Shader> _vertexShader, const ID<Shader> _fragShader) -> void;
@ -155,6 +155,8 @@ namespace GL
sfn GetShaderProgramInfo(ID<ShaderProgram> _shaderProgram, gSize _logLength, ptr<gSize> _infoLengthRef, RawString<gChar> _infoLogRef) -> void
{
glGetProgramInfoLog(_shaderProgram, _logLength, _infoLengthRef, _infoLogRef);
return;
}
sfn GetUniformVariable(const ID<ShaderProgram> _programID, RawString<const char> _nameOfVariable) -> ID<Matrix>
@ -172,11 +174,15 @@ namespace GL
sfn QueryShader(ID<Shader> _shaderToQuery, EShaderInfo _shaderInfoDesired, ptr<gInt> _requestedInfoObject) -> void
{
glGetShaderiv(_shaderToQuery, GLenum(_shaderInfoDesired), _requestedInfoObject);
return;
}
sfn QueryShaderProgram(ID<ShaderProgram> _shaderToQuery, EShaderProgramInfo _shaderProgramInfoDesired, ptr<gInt> _requestedInfoObject) -> void
{
glGetProgramiv(_shaderToQuery, GLenum(_shaderProgramInfoDesired), _requestedInfoObject);
return;
}
sfn LoadShaders(RawString<const char> _vertexShaderFilePath, RawString<const char> _fragmentShaderFilePath) -> ID<ShaderProgram>
@ -263,25 +269,31 @@ namespace GL
ID<Shader> VertexShader ;
ID<Shader> FragmentShader;
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(GL::RawVertextShaderSource ), NULL);
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(GL::RawFragmentShaderSource), NULL);
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(DGL::RawVertextShaderSource ), NULL);
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(DGL::RawFragmentShaderSource), NULL);
GL::MakeShaderProgram(RawShader, VertexShader, FragmentShader);
DGL::MakeShaderProgram(RawShader, VertexShader, FragmentShader);
GL::DeleteShader(VertexShader );
GL::DeleteShader(FragmentShader);
DGL::DeleteShader(VertexShader );
DGL::DeleteShader(FragmentShader);
return;
}
sfn LoadSimpleShader()
{
SimpleShader = LoadShaders("SimpleVertexShader.vert", "SimpleFragmentShader.frag");
return;
}
sfn LoadSimpleShader_Transformed()
{
SimpleShader_Transformed = LoadShaders("SimpleTransform.vert", "SingleColor.frag");
ScreenSpaceVarID = GL::GetUniformVariable(GL::SimpleShader_Transformed, "modelViewProjection");
ScreenSpaceVarID = DGL::GetUniformVariable(DGL::SimpleShader_Transformed, "modelViewProjection");
return;
}
sfn LoadDefaultShaders()
@ -289,6 +301,8 @@ namespace GL
LoadRawShader ();
LoadSimpleShader ();
LoadSimpleShader_Transformed();
return;
}
sfn MakeShader
@ -306,6 +320,8 @@ namespace GL
BindShaderSource(_shaderIDHolder, _numberOfStringElements, _sourceCode, _lengthsOfStrings);
CompileShader(_shaderIDHolder);
return;
}
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder, const ID<Shader> _vertexShader, const ID<Shader> _fragShader) -> void
@ -350,6 +366,8 @@ namespace GL
sfn SetUniformVariable_MatrixVariableArray(const ID<Matrix> _matrixID, const gSize _numMatricies, const EBool _shouldTransposeValues, ptr<const float> _dataPtr)
{
glUniformMatrix4fv(_matrixID, _numMatricies, GLenum(_shouldTransposeValues), _dataPtr);
return;
}
sfn UseProgramShader(ID<ShaderProgram> _shaderProgramToUse)

View File

@ -10,7 +10,7 @@
namespace GL
namespace DGL
{
using CoordSpace = Matrix4x4;
using Projection = Matrix4x4;
@ -18,6 +18,16 @@ namespace GL
// Function
sfn Cosine(gFloat _angleInRadians)
{
return glm::cos(_angleInRadians);
}
sfn Sine(gFloat _angleInRadians)
{
return glm::sin(_angleInRadians);
}
template<typename Type>
sfn CreateLookAtView(const Generic::Vector3<Type> _viewPosition, const Generic::Vector3<Type> _lookAtPosition, const Generic::Vector3<Type> _upDirection) -> Matrix4x4
{
@ -35,6 +45,11 @@ namespace GL
return glm::perspective(_fieldOfView, _aspectRatio, _nearPlane, _farPlane);
}
sfn Translate(const Matrix4x4 _matrix, Vector3 _translationAmount)
{
return glm::translate(_matrix, _translationAmount);
}
sfn Rotate(const Matrix4x4 _matrix, gFloat _rotationAngleAmount, Vector3 _axis) -> Matrix4x4
{
return glm::rotate(_matrix, _rotationAngleAmount, _axis);
@ -46,6 +61,18 @@ namespace GL
return glm::radians(_degrees);
}
sfn GetCrossNormal(Vector3 _subj, Vector3 _ref) -> Vector3
{
return glm::cross(_subj, _ref);
}
sfn GetDirection(Vector3 _vectorSpecified)
{
return glm::normalize(_vectorSpecified);
}
struct ClippingPlanes
{
gFloat Near, Far;
@ -61,24 +88,28 @@ namespace GL
NearClippingPlane = 0.1f ,
FarClippingPlane = 100.0f ;
Vector3 CameraPosition(-3, 0, 0),
LookAtPosition( 0, 0, 0),
UpDirection ( 0, 1, 0) ;
Vector3 CameraPosition( 0, 0, 2),
LookAtPosition( 0, 0, 0),
RightDirection( 1, 0, 0),
UpDirection ( 0, 1, 0),
FrontDirection( 0, 0, 1) ;
gFloat ScreenWidth = 720.0f, ScreenHeight = 450.0f;
gFloat ScreenWidth = 720.0f, ScreenHeight = 540.0f, ScreenCenterWidth = ScreenWidth / 2, ScreenCenterHeight = ScreenHeight / 2;
}
using std::cout; using std::endl;
struct Camera
{
gFloat AspectRatio, FieldOfView;
gFloat AspectRatio, FieldOfView, Yaw, Pitch, Roll;
ClippingPlanes ClipSpace;
CoordSpace ViewPort;
CoordSpace Viewport;
Projection Orthographic, Perspective;
Vector3 Position, LookAtPosition, UpDirection;
Vector3 Position, LookAtPosition, UpDirection, FrontDirection, RightDirection;
Camera
@ -88,29 +119,211 @@ namespace GL
ClippingPlanes _clippingPlanes,
Vector3 _position ,
Vector3 _lookAtPosition,
Vector3 _upDirection
Vector3 _upDirection ,
Vector3 _frontDirection
) :
AspectRatio (_aspectRatio ),
FieldOfView (_fieldOfView ),
ClipSpace (_clippingPlanes),
Position (_position ),
LookAtPosition(_lookAtPosition),
UpDirection (_upDirection )
UpDirection (_upDirection ),
FrontDirection(_frontDirection)
{
ViewPort = CreateLookAtView(Position, LookAtPosition, UpDirection);
std::cout << UpDirection.x << ", " << UpDirection.y << ", " << UpDirection.z << std::endl;
Yaw = -90.0f; Pitch = 0; Roll = 0;
//Yaw = 0;
UpdateCamera();
std::cout << UpDirection.x << ", " << UpDirection.y << ", " << UpDirection.z << std::endl;
Orthographic = CreateOrthographic(0.0f, DefaultSpace::ScreenWidth, 0.0f, DefaultSpace::ScreenHeight, ClipSpace.Near, ClipSpace.Far);
Perspective = CreatePerspective<gFloat>(ToRadians(FieldOfView), AspectRatio, ClipSpace.Near, ClipSpace.Far);
}
sfn Move(EDirection _direction, gFloat _translationAmount, gFloat _deltaTime)
{
switch (_direction)
{
case EDirection::Up:
{
Position += UpDirection * _translationAmount * _deltaTime;
LookAtPosition += UpDirection * _translationAmount * _deltaTime;
break;
}
case EDirection::Down:
{
Position -= UpDirection * _translationAmount * _deltaTime;
LookAtPosition -= UpDirection * _translationAmount * _deltaTime;
break;
}
case EDirection::Left:
{
Position += GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
//LookAtPosition += GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
break;
}
case EDirection::Right:
{
Position -= GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
//LookAtPosition -= GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
break;
}
case EDirection::Forward:
{
Position -= FrontDirection * _translationAmount * _deltaTime;
LookAtPosition -= FrontDirection * _translationAmount * _deltaTime;
break;
}
case EDirection::Backward:
{
Position += FrontDirection * _translationAmount * _deltaTime;
LookAtPosition += FrontDirection * _translationAmount * _deltaTime;
break;
}
default:
{
throw std::logic_error("Direction move not defined.");
}
}
}
sfn Move(Vector3 _translationAmount, Ref(gFloat) _deltaTime)
{
Position += _translationAmount * _deltaTime;
}
sfn Rotate(ERotationAxis _pivot, gFloat _rotationAmount, gFloat _deltaTime)
{
switch (_pivot)
{
case ERotationAxis::Pitch:
{
Pitch -= _rotationAmount * _deltaTime;
if (Pitch > 89.9f)
{
Pitch = 89.9f;
}
else if (Pitch < -89.9f)
{
Pitch = -89.9f;
}
//std::cout << "Pitch: " << Pitch << std::endl;
break;
}
case ERotationAxis::Roll:
{
Roll += _rotationAmount * _deltaTime;
if (Roll > 89.9f)
{
Roll = 89.9f;
}
else if (Roll < -89.9f)
{
Roll = -89.9f;
}
break;
}
case ERotationAxis::Yaw:
{
Yaw += _rotationAmount * _deltaTime;
/*if (Yaw > 89.9f)
{
Yaw = 89.9f;
}
else if (Yaw < -89.9f)
{
Pitch = -89.9f;
}*/
//std::cout << "Yaw: " << Yaw << std::endl;
break;
}
}
/*std::cout << "Front Direction: " << FrontDirection.x << ", " << FrontDirection.y << ", " << FrontDirection.z << std::endl;
std::cout << "Right Direction: " << RightDirection.x << ", " << RightDirection.y << ", " << RightDirection.z << std::endl;
std::cout << "Up Direction: " << UpDirection.x << ", " << UpDirection.y << ", " << UpDirection.z << std::endl;*/
}
sfn UpdateCamera() -> void
{
//cout << Pitch << Yaw << Roll << endl;
//cout << "Cosine: " << Cosine(ToRadians(Yaw)) << endl;
FrontDirection.x = Cosine(ToRadians(Yaw )) * Cosine(ToRadians(Pitch));
FrontDirection.y = Sine (ToRadians(Pitch)) ;
FrontDirection.z = Sine (ToRadians(Yaw )) * Cosine(ToRadians(Pitch));
FrontDirection = GetDirection(FrontDirection );
RightDirection = GetDirection(GetCrossNormal(FrontDirection, DefaultSpace::UpDirection ));
UpDirection = GetDirection(GetCrossNormal(RightDirection, FrontDirection));
//Matrix4x4 mRoll = glm::rotate(mRoll , Roll , DefaultSpace::FrontDirection);
//Matrix4x4 mPitch = glm::rotate(mPitch, Pitch, DefaultSpace::RightDirection);
//Matrix4x4 mYaw = glm::rotate(mYaw , Roll , DefaultSpace::UpDirection );
//Matrix4x4 rotation = mPitch * mYaw;
Viewport = CreateLookAtView(Position, LookAtPosition - FrontDirection, UpDirection);
//glm::mat4 translate = glm::mat4(1.0f);
//translate = glm::translate(translate, -LookAtPosition);
//Viewport = rotation * translate;
}
};
namespace DefaultSpace
{
Camera WorldCamera(AspectRatio, FieldOfView, ClippingPlanes(NearClippingPlane, FarClippingPlane), CameraPosition, LookAtPosition, UpDirection);
Camera WorldCamera
(
AspectRatio,
FieldOfView,
ClippingPlanes(NearClippingPlane, FarClippingPlane),
CameraPosition,
LookAtPosition,
UpDirection,
FrontDirection
);
CoordSpace WorldSpace(Matrix4x4(1.0f));
CoordSpace Screenspace = WorldCamera.Perspective * WorldCamera.ViewPort * WorldSpace;
CoordSpace Screenspace = WorldCamera.Perspective * WorldCamera.Viewport * WorldSpace;
sfn UpdateScreenspace()
{
//Screenspace = WorldCamera.Perspective * WorldCamera.Viewport * WorldSpace;
}
}
}

View File

@ -1,9 +1,4 @@
// Cpp STL
#include <chrono>
#include <thread>
#include <memory>
// Project
#include "DGL.hpp"
@ -23,6 +18,8 @@ namespace Execution
using std::thread;
template<typename Type>
using UPtr = std::unique_ptr<Type>;
@ -36,53 +33,92 @@ namespace Execution
// GL
using GL::TimeValDec;
using GL::Window ;
using GL::Matrix ;
using GL::Matrix4x4 ;
using GL::Vector3 ;
using GL::gFloat ;
using DGL::TimeValDec;
using DGL::Window ;
using DGL::Matrix ;
using DGL::Matrix4x4 ;
using DGL::Vector3 ;
using DGL::gFloat ;
bool Exist = true;
TimeValDec CycleStart, CycleEnd, DeltaTime, InputPollingInterval = 1.0f / 240.0f, RenderInterval = 1.0f / 60.0f;
TimeValDec CycleStart, CycleEnd, DeltaTime, InputPollingInterval = 1.0f / 240.0f, PhysicsInterval = 1.0f / 120.0f, RenderInterval = 1.0f / 60.0f;
UPtr<thread> BasicLoop, BasicTimedLoop;
ptr<Window> DefaultWindow;
gFloat CamMoveSpeed = 3.0f, CamRotationSpeed = 1.0f;
enum class CameraActions
{
};
enum class EMovement
{
};
template<typename Device>
struct ActionBind
{
Delegate< Func<void>> Action;
};
struct Keyboard
{
};
struct ActionBinds
{
static ActionBind<Keyboard> MoveFoward;
};
// Testing
// Foward Declares
// Forward Declares
sfn RenderProcedure () -> void;
sfn PrepareRenderObjects() -> void;
sfn CreateWindow_BasicLoop()
{
GL::InitalizeGLFW();
DGL::InitalizeGLFW();
deduce windowObj = GL::CreateWindow(720, 450, "Assignment 1: RawLoop", GL::WindowedMode(), GL::NotShared());
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: RawLoop", DGL::WindowedMode(), DGL::NotShared());
GL::SetCurrentContext(windowObj);
DGL::SetCurrentContext(windowObj);
GL::RunBasicWindowLoop(windowObj);
DGL::RunBasicWindowLoop(windowObj);
}
sfn CreateWindow_TimedRender()
{
GL::InitalizeGLFW();
DGL::InitalizeGLFW();
deduce windowObj = GL::CreateWindow(720, 540, "Assignment 1: Timed Render", GL::WindowedMode(), GL::NotShared());
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: Timed Render", DGL::WindowedMode(), DGL::NotShared());
GL::SetCurrentContext(windowObj);
DGL::SetCurrentContext(windowObj);
GL::InitalizeGLEW();
DGL::InitalizeGLEW();
PrepareRenderObjects();
GL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure));
DGL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure));
}
sfn PrepareRenderObjects() -> void
@ -91,70 +127,248 @@ namespace Execution
RAW_BindAndBufferDataToIDs();
GL::LoadDefaultShaders();
DGL::LoadDefaultShaders();
GL::FormatVertexAttributes<Vertex3>(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::True);
DGL::FormatVertexAttributes<Vertex3>(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
GL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
GL::BindVertexArray(0);
DGL::BindVertexArray(0);
}
sfn Cycler(FnPtr<void> _inputProcedure, FnPtr<void> _renderProcedure)
using DGL::EFrameBuffer;
using DGL::LinearColor;
using DGL::DefaultSpace::WorldCamera;
using std::cout; using std::endl;
using DGL::KeyPressed;
using DGL::EKeyCodes;
using DGL::DefaultSpace::WorldCamera;
using DGL::EDirection;
struct CamShouldMove
{
bool Up, Down, Left, Right, Forward, Backward;
short int numActive;
};
CamShouldMove CamMoveRequests = { false, false, false, false, false, false, 0 };
double CursorX, CursorY;
using DGL::DefaultSpace::ScreenCenterWidth; using DGL::DefaultSpace::ScreenCenterHeight;
TimeValDec InputDelta = 0.0, PhysicsDelta = 0.0, RenderDelta = 0.0;
using DGL::DefaultSpace::Screenspace;
sfn Cycler(Delegate< Func<void, ptr<Window>> > _inputProcedure, Delegate< Func<void>> _renderProcedure)
{
while (Exist)
{
CycleStart = GL::GetTime();
CycleStart = DGL::GetTime();
if (DeltaTime >= InputPollingInterval)
if (InputDelta >= InputPollingInterval)
{
GL::PollEvents();
DGL::PollEvents();
_inputProcedure();
glfwGetCursorPos(DefaultWindow, Address(CursorX), Address(CursorY));
_inputProcedure(DefaultWindow);
DGL::ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
InputDelta = 0.0;
}
if (DeltaTime >= RenderInterval)
if (PhysicsDelta >= PhysicsInterval)
{
if (CamMoveRequests.Up ) WorldCamera.Move(EDirection::Up , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
if (CamMoveRequests.Down ) WorldCamera.Move(EDirection::Down , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
if (CamMoveRequests.Left ) WorldCamera.Move(EDirection::Left , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
if (CamMoveRequests.Right ) WorldCamera.Move(EDirection::Right , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
if (CamMoveRequests.Forward ) WorldCamera.Move(EDirection::Forward , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
if (CamMoveRequests.Backward) WorldCamera.Move(EDirection::Backward, CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
WorldCamera.UpdateCamera();
//WorldCamera.Position.y = 0.0;
//WorldCamera.LookAtPosition.y = 0.0;
DGL::DefaultSpace::UpdateScreenspace();
CamMoveRequests = { false, false, false, false, false, false, 0 };
PhysicsDelta = 0.0;
}
if (RenderDelta >= RenderInterval)
{
DGL::ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
DGL::SetClearColor(LinearColor(0.12f, 0.12f, 0.12f, 1.0f));
_renderProcedure();
DGL::SwapBuffers(DefaultWindow);
RenderDelta = 0.0;
}
CycleEnd = GL::GetTime();
CycleEnd = DGL::GetTime();
DeltaTime = DeltaTime + CycleEnd - CycleStart;
DeltaTime = CycleEnd - CycleStart;
InputDelta += DeltaTime;
PhysicsDelta += DeltaTime;
RenderDelta += DeltaTime;
}
return;
}
sfn InputProcedure()
{
using DGL::EMouseMode; using DGL::ECursorMode;
using DGL::DefaultSpace::ScreenCenterWidth; using DGL::DefaultSpace::ScreenCenterHeight;
sfn InputProcedure(ptr<Window> _currentWindowContext)
{
if (KeysPressed(_currentWindowContext, EKeyCodes::LeftShift, EKeyCodes::F1))
{
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden)
{
SetInputMode(_currentWindowContext, EMouseMode::Cursor, ECursorMode::Disable);
}
else
{
SetInputMode(_currentWindowContext, EMouseMode::Cursor, ECursorMode::Normal);
}
}
if (CursorX != 0)//!= ScreenCenterWidth)
{
WorldCamera.Rotate(DGL::ERotationAxis::Yaw, CursorX * CamMoveSpeed, InputDelta);
//cout << "Cursor X: " << CursorX << endl;
}
if (CursorY != 0)
{
WorldCamera.Rotate(DGL::ERotationAxis::Pitch, CursorY * CamMoveSpeed, InputDelta);
//cout << "Cursor Y: " << CursorX << endl;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::E))
{
WorldCamera.Move(EDirection::Up, CamMoveSpeed, InputDelta);
CamMoveRequests.Up = true;
CamMoveRequests.numActive++;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::Q))
{
WorldCamera.Move(EDirection::Down, CamMoveSpeed, InputDelta);
CamMoveRequests.Down = true;
CamMoveRequests.numActive++;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::A))
{
WorldCamera.Move(EDirection::Left, CamMoveSpeed, InputDelta);
CamMoveRequests.Left = true;
CamMoveRequests.numActive++;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::D))
{
WorldCamera.Move(EDirection::Right, CamMoveSpeed, InputDelta);
CamMoveRequests.Right = true;
CamMoveRequests.numActive++;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::W))
{
WorldCamera.Move(EDirection::Forward, CamMoveSpeed, InputDelta);
CamMoveRequests.Forward = true;
CamMoveRequests.numActive++;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::S))
{
WorldCamera.Move(EDirection::Backward, CamMoveSpeed, InputDelta);
CamMoveRequests.Backward = true;
CamMoveRequests.numActive++;
}
}
sfn RenderProcedure() -> void
{
GL::EnableVertexAttributeArray(VertexAttributeIndex);
DGL::EnableVertexAttributeArray(VertexAttributeIndex);
GL::SetPolygonMode(GL::EFace::Front_and_Back, GL::EMode::Fill);
DGL::SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Line);
GL::DefaultSpace::WorldSpace = GL::Rotate(GL::DefaultSpace::WorldSpace, 0.0035f, Vector3(0.0f, 0.5f, 0.0f));
DGL::DefaultSpace::WorldSpace = DGL::Rotate(DGL::DefaultSpace::WorldSpace, 0.0035f, Vector3(0.0f, 0.5f, 0.0f));
GL::DefaultSpace::Screenspace = GL::DefaultSpace::WorldCamera.Perspective * GL::DefaultSpace::WorldCamera.ViewPort * GL::DefaultSpace::WorldSpace;
DGL::DefaultSpace::Screenspace = DGL::DefaultSpace::WorldCamera.Perspective * DGL::DefaultSpace::WorldCamera.Viewport * DGL::DefaultSpace::WorldSpace;
GL::UseProgramShader(GL::SimpleShader_Transformed);
DGL::UseProgramShader(DGL::SimpleShader_Transformed);
GL::SetUniformVariable_MatrixVariableArray(GL::ScreenSpaceVarID, 1, GL::EBool::False, Address(GL::DefaultSpace::Screenspace[0][0]));
DGL::SetUniformVariable_MatrixVariableArray(DGL::ScreenSpaceVarID, 1, DGL::EBool::False, Address(DGL::DefaultSpace::Screenspace[0][0]));
GL::BindVertexArray(VertexArrayObj);
DGL::BindVertexArray(VertexArrayObj);
GL::DrawArrays(GL::EPrimitives::Triangles, 0, TriangleRaw::VertexCount());
DGL::DrawArrays(DGL::EPrimitives::Triangles, 0, TriangleRaw::VertexCount());
GL::DisableVertexAttributeArray(VertexAttributeIndex);
DGL::DrawElements(DGL::EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset());
//GL::BindVertexArray(0);
DGL::DisableVertexAttributeArray(VertexAttributeIndex);
}
sfn PrepWorkspace()
{
using DGL::DefaultSpace::ScreenWidth ;
using DGL::DefaultSpace::ScreenHeight;
DGL::InitalizeGLFW();
DefaultWindow = DGL::CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Cam Movement Test", DGL::WindowedMode(), DGL::NotShared());
DGL::SetCurrentContext(DefaultWindow);
DGL::SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
DGL::ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
if (DGL::CanUseRawMouse())
{
DGL::SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
}
DGL::InitalizeGLEW();
PrepareRenderObjects();
}
@ -162,13 +376,11 @@ namespace Execution
sfn Execute() -> ExitCode
{
/*PrepWorkspace();*/
PrepWorkspace();
//Cycler(Address(InputProcedure), Address(RenderProcedure));
Cycler(InputProcedure, RenderProcedure);
CreateWindow_TimedRender();
GL::TerminateGLFW();
DGL::TerminateGLFW();
return ExitCode::Success;
}

View File

@ -88,7 +88,7 @@ public:
checkCompileErrors(geometry, "GEOMETRY");
}
GL::MakeShaderProgram(ID, vertex, fragment);
DGL::MakeShaderProgram(ID, vertex, fragment);
// shader Program
/* ID = glCreateProgram();

View File

@ -6,14 +6,14 @@
using GL::gFloat;
using GL::VertexBuffer;
using GL::EBufferTarget;
using GL::EBufferUsage;
using GL::Buffer;
using GL::ID;
using GL::gInt;
using GL::gSize;
using DGL::gFloat;
using DGL::VertexBuffer;
using DGL::EBufferTarget;
using DGL::EBufferUsage;
using DGL::Buffer;
using DGL::ID;
using DGL::gInt;
using DGL::gSize;
@ -37,9 +37,9 @@ struct TriangleRaw
TriangleRaw EquilateralTriangleVerticies =
{
{ -1.0f, -1.0f, 0.0f },
{ 1.0f, -1.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f }
{ -1.0f, -1.0f, 0.0f }, // Vert1
{ 1.0f, -1.0f, 0.0f }, // Vert2
{ 0.0f, 1.0f, 0.0f } // Vert 3
};
@ -87,10 +87,10 @@ struct RectangleIndices
RectangleCompressed rectCompress =
{
{ 0.5f, 0.5f, 0.0f },
{ 0.5f, -0.5f, 0.0f },
{ -0.5f, -0.5f, 0.0f },
{ -0.5f, 0.5f, 0.0f }
{ 1.0f, 1.0f, 0.0f },
{ 1.0f, -1.0f, 0.0f },
{ -1.0f, -1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f }
};
RectangleIndices rectIndices =
@ -99,7 +99,7 @@ RectangleIndices rectIndices =
{ 1, 2, 3 }
};
using GL::ElementBuffer;
using DGL::ElementBuffer;
ID<ElementBuffer> ElemBufferObj;
@ -124,35 +124,35 @@ TriTexCoords textureCoords =
sfn RAW_SetupBuffers()
{
GL::GenerateVertexBuffers(Address(VertexArrayObj ), 1);
GL::GenerateBuffers (Address(VertexBufferObj), 1);
GL::GenerateBuffers (Address(ElemBufferObj ), 1);
DGL::GenerateVertexBuffers(Address(VertexArrayObj ), 1);
DGL::GenerateBuffers (Address(VertexBufferObj), 1);
DGL::GenerateBuffers (Address(ElemBufferObj ), 1);
}
sfn RAW_SetupTriangleBuffer()
{
GL::GenerateBuffers(Address(VertexBufferObj), 1);
DGL::GenerateBuffers(Address(VertexBufferObj), 1);
}
sfn RAW_BindAndBufferDataToIDs()
{
GL::BindVertexArray(VertexArrayObj);
DGL::BindVertexArray(VertexArrayObj);
GL::BindBuffer(EBufferTarget::VertexAttributes, VertexBufferObj);
DGL::BindBuffer(EBufferTarget::VertexAttributes, VertexBufferObj);
GL::BufferData<TriangleRaw>(Address(EquilateralTriangleVerticies), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
//GL::BufferData<TriangleRaw>(Address(EquilateralTriangleVerticies), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
//GL::BufferData<RectangleCompressed>(Address(rectCompress), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BufferData<RectangleCompressed>(Address(rectCompress), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
//GL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj);
DGL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj);
//GL::BufferData<RectangleIndices>(Address(rectIndices), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
DGL::BufferData<RectangleIndices>(Address(rectIndices), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
}
GL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0).
DGL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0).
using GL::EBool ;
using GL::EDataType;
using DGL::EBool ;
using DGL::EDataType;
constexpr sfn ZeroOffset() -> ptr<void>
{