Initial Commit
This commit is contained in:
commit
27fb4cf7ea
332
.gitignore
vendored
Normal file
332
.gitignore
vendored
Normal file
@ -0,0 +1,332 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
31
OpenGLEngine.sln
Normal file
31
OpenGLEngine.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27703.2026
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGLEngine", "OpenGLEngine\OpenGLEngine.vcxproj", "{C03B666E-F3CE-4223-977D-9D6E2952F22E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Debug|x64.Build.0 = Debug|x64
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Debug|x86.Build.0 = Debug|Win32
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Release|x64.ActiveCfg = Release|x64
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Release|x64.Build.0 = Release|x64
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Release|x86.ActiveCfg = Release|Win32
|
||||
{C03B666E-F3CE-4223-977D-9D6E2952F22E}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A995539A-1D75-4A7C-81F6-F614D05D9BA6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
76
OpenGLEngine/Application.cpp
Normal file
76
OpenGLEngine/Application.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include <gl/GL.h>
|
||||
|
||||
#pragma comment(lib, "opengl32.lib")
|
||||
|
||||
Application::Application(const char* class_name, HINSTANCE h_instance)
|
||||
: m_window(class_name, h_instance), m_input_manager(&m_window.get_input_manager()), m_client_size(1280, 720)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
HGLRC h_glrc = m_window.get_h_glrc();
|
||||
if (h_glrc != nullptr) {
|
||||
// Unset the current OpenGL Rendering Context and Device
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(h_glrc);
|
||||
m_window.set_h_glrc(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int Application::run()
|
||||
{
|
||||
if (!base_init()) return 1;
|
||||
|
||||
MessageResponse resp(UNSET);
|
||||
while (resp != QUIT_MESSAGE) {
|
||||
// Handle all messages
|
||||
while ((resp = m_window.handle_message()) == HANDLED_MESSAGE) {}
|
||||
float delta_time = m_fps.mark();
|
||||
clock_t clock = m_fps.get_clock();
|
||||
update(delta_time, clock);
|
||||
render();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Application::close()
|
||||
{
|
||||
}
|
||||
|
||||
bool Application::base_init()
|
||||
{
|
||||
if (!m_window.register_class()) return false;
|
||||
if (!m_window.create_window("OpenGLEngine", -1, -1, m_client_size.x, m_client_size.y)) return false;
|
||||
|
||||
// Initialize window with OpenGL (May want to move this into MyApplication to allow application customization)
|
||||
// https://www.khronos.org/opengl/wiki/Creating_an_OpenGL_Context_(WGL)
|
||||
HDC device_context = GetDC(m_window.get_h_wnd());
|
||||
|
||||
// PIXELFORMATDESCRIPTOR https://msdn.microsoft.com/en-us/library/cc231189.aspx
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cDepthBits = 24;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
|
||||
m_window.set_h_glrc(wglCreateContext(device_context));
|
||||
|
||||
m_window.show(SW_NORMAL);
|
||||
m_fps.prepare();
|
||||
|
||||
return init();
|
||||
}
|
||||
|
||||
void Application::base_close()
|
||||
{
|
||||
close();
|
||||
}
|
45
OpenGLEngine/Application.h
Normal file
45
OpenGLEngine/Application.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include "vec2.h"
|
||||
|
||||
#include "Window.h"
|
||||
#include "FPS.h"
|
||||
|
||||
// TODO: Close without rendering next frame.
|
||||
|
||||
class Application
|
||||
{
|
||||
public:
|
||||
Application(const char* class_name, HINSTANCE h_instance);
|
||||
~Application();
|
||||
|
||||
int run();
|
||||
protected:
|
||||
// Called on initialization of the application (called by base_init)
|
||||
virtual bool init() = 0;
|
||||
|
||||
virtual void update(float delta_time, clock_t clock) = 0;
|
||||
|
||||
virtual void render() = 0;
|
||||
|
||||
// Called on closing of the application (called before base_close)
|
||||
virtual void close();
|
||||
|
||||
// The size of the window
|
||||
ivec2 m_client_size;
|
||||
|
||||
// The window that is used by this application
|
||||
Window m_window;
|
||||
|
||||
// The input manager for the window of this application
|
||||
const InputManager* m_input_manager;
|
||||
|
||||
// The FPS counter of this application
|
||||
FPS m_fps;
|
||||
private:
|
||||
bool base_init();
|
||||
void base_close();
|
||||
};
|
||||
|
48
OpenGLEngine/FPS.cpp
Normal file
48
OpenGLEngine/FPS.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "FPS.h"
|
||||
|
||||
FPS::FPS(unsigned short frames /* = 2 */) :
|
||||
m_iter(frames), m_frames(frames)
|
||||
{
|
||||
if (frames < 2)
|
||||
throw "Frames is too small";
|
||||
m_clocks = new clock_t[m_frames];
|
||||
}
|
||||
|
||||
|
||||
FPS::~FPS()
|
||||
{
|
||||
if (m_clocks)
|
||||
delete[] m_clocks;
|
||||
}
|
||||
|
||||
const clock_t& FPS::get_clock() const
|
||||
{
|
||||
return m_clocks[m_iter];
|
||||
}
|
||||
|
||||
float FPS::get_spf() const
|
||||
{
|
||||
clock_t diff = (m_clocks[m_iter] - m_clocks[(m_iter + 1) % m_frames]) / (m_frames - 1);
|
||||
return ((float)diff) / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
float FPS::get_fps() const
|
||||
{
|
||||
clock_t diff = (m_clocks[m_iter] - m_clocks[(m_iter + 1) % m_frames]) / (m_frames - 1);
|
||||
return ((float)CLOCKS_PER_SEC) / diff;
|
||||
}
|
||||
|
||||
void FPS::prepare()
|
||||
{
|
||||
clock_t c = clock();
|
||||
for (unsigned short i = 0; i < m_frames; ++i)
|
||||
m_clocks[i] = c;
|
||||
}
|
||||
|
||||
float FPS::mark()
|
||||
{
|
||||
(++m_iter) %= m_frames;
|
||||
m_clocks[m_iter] = clock();
|
||||
clock_t diff = (m_clocks[m_iter] - m_clocks[(m_iter > 0 ? m_iter - 1 : m_frames - 1)]);
|
||||
return ((float)diff) / CLOCKS_PER_SEC;
|
||||
}
|
44
OpenGLEngine/FPS.h
Normal file
44
OpenGLEngine/FPS.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
|
||||
//A class to handle the FPS of the game
|
||||
//Calculations are done per the number of frames specified
|
||||
//Frames must be a value from 2 - 255
|
||||
//Recommended numbers for frames is 2 (Instant), 5 (Slightly Smoothed), 60 (Smoothed)
|
||||
//Max number for frames = 255
|
||||
//Lower frames = jumpy, instant updates
|
||||
//Higher frames = smoother, flowing updates
|
||||
class FPS
|
||||
{
|
||||
public:
|
||||
FPS(unsigned short frames = 2);
|
||||
~FPS();
|
||||
|
||||
//Returns the clock of the last mark() call
|
||||
const clock_t& get_clock() const;
|
||||
|
||||
//Returns FPS (frames per second) of the game (based on the last marked frame)
|
||||
//CLOCKS_PER_SECOND / (m_clock - m_prevClock)
|
||||
float get_spf() const;
|
||||
|
||||
//Returns FPS (frames per second) of the game (based on the last marked frame)
|
||||
//CLOCKS_PER_SECOND / (m_clock - m_prevClock)
|
||||
float get_fps() const;
|
||||
|
||||
//Fills the clocks with the current clock() value (to prevent unreasonable clock counts at the first few frames)
|
||||
void prepare();
|
||||
|
||||
//Marks the end of the frame (resets the clock)
|
||||
//Should be called right before the update() and render() functions
|
||||
//Also calculates the seconds per frame (able to be considered the dTime)
|
||||
//(m_clock - m_prevClock) / CLOCKS_PER_SEC
|
||||
float mark();
|
||||
|
||||
private:
|
||||
//m_iter marks the place of the next mark
|
||||
unsigned short m_iter;
|
||||
unsigned short m_frames;
|
||||
|
||||
clock_t* m_clocks = nullptr;
|
||||
};
|
81
OpenGLEngine/InputManager.cpp
Normal file
81
OpenGLEngine/InputManager.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "InputManager.h"
|
||||
|
||||
InputManager::InputManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InputManager::~InputManager()
|
||||
{
|
||||
}
|
||||
|
||||
void InputManager::mark()
|
||||
{
|
||||
m_keys_pressed.clear();
|
||||
m_mouse_delta = { 0, 0 };
|
||||
m_scroll_distance = 0;
|
||||
}
|
||||
|
||||
void InputManager::key_down(const unsigned long& keyCode)
|
||||
{
|
||||
if (!m_keys_down[keyCode])
|
||||
{
|
||||
m_keys_down[keyCode] = true;
|
||||
m_keys_pressed[keyCode] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void InputManager::key_up(const unsigned long& keyCode)
|
||||
{
|
||||
m_keys_down[keyCode] = false;
|
||||
m_keys_pressed[keyCode] = false;
|
||||
}
|
||||
|
||||
void InputManager::mouse_move(const ivec2& position)
|
||||
{
|
||||
m_mouse_delta += position - m_mouse_position;
|
||||
m_mouse_position = position;
|
||||
}
|
||||
|
||||
void InputManager::mouse_scroll(const unsigned int& distance)
|
||||
{
|
||||
m_scroll_distance += distance;
|
||||
}
|
||||
|
||||
bool InputManager::is_key_down(const unsigned long& keyCode)
|
||||
{
|
||||
return m_keys_down[keyCode];
|
||||
}
|
||||
|
||||
bool InputManager::is_key_pressed(const unsigned long& keyCode)
|
||||
{
|
||||
auto iter = m_keys_pressed.find(keyCode);
|
||||
if (iter == m_keys_pressed.end())
|
||||
return false;
|
||||
else
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
bool InputManager::is_key_released(const unsigned long& keyCode)
|
||||
{
|
||||
auto iter = m_keys_pressed.find(keyCode);
|
||||
if (iter == m_keys_pressed.end())
|
||||
return false;
|
||||
else
|
||||
return !iter->second;
|
||||
}
|
||||
|
||||
const ivec2& InputManager::get_mouse_position()
|
||||
{
|
||||
return m_mouse_position;
|
||||
}
|
||||
|
||||
const ivec2& InputManager::get_mouse_delta()
|
||||
{
|
||||
return m_mouse_delta;
|
||||
}
|
||||
|
||||
const int& InputManager::get_scroll_distance()
|
||||
{
|
||||
return m_scroll_distance;
|
||||
}
|
90
OpenGLEngine/InputManager.h
Normal file
90
OpenGLEngine/InputManager.h
Normal file
@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "vec2.h"
|
||||
|
||||
//Define the Virtual Keys for the numbers & letters
|
||||
|
||||
#define K_0 0x30
|
||||
#define K_1 0x31
|
||||
#define K_2 0x32
|
||||
#define K_3 0x33
|
||||
#define K_4 0x34
|
||||
#define K_5 0x35
|
||||
#define K_6 0x36
|
||||
#define K_7 0x37
|
||||
#define K_8 0x38
|
||||
#define K_9 0x39
|
||||
|
||||
#define K_A 0x41
|
||||
#define K_B 0x42
|
||||
#define K_C 0x43
|
||||
#define K_D 0x44
|
||||
#define K_E 0x45
|
||||
#define K_F 0x46
|
||||
#define K_G 0x47
|
||||
#define K_H 0x48
|
||||
#define K_I 0x49
|
||||
#define K_J 0x4a
|
||||
#define K_K 0x4b
|
||||
#define K_L 0x4c
|
||||
#define K_M 0x4d
|
||||
#define K_N 0x4e
|
||||
#define K_O 0x4f
|
||||
#define K_P 0x50
|
||||
#define K_Q 0x51
|
||||
#define K_R 0x52
|
||||
#define K_S 0x53
|
||||
#define K_T 0x54
|
||||
#define K_U 0x55
|
||||
#define K_V 0x56
|
||||
#define K_W 0x57
|
||||
#define K_X 0x58
|
||||
#define K_Y 0x59
|
||||
#define K_Z 0x5A
|
||||
|
||||
using namespace egm;
|
||||
|
||||
class InputManager
|
||||
{
|
||||
public:
|
||||
InputManager();
|
||||
~InputManager();
|
||||
|
||||
//Should be called after each frame to reset the keysPressed
|
||||
void mark();
|
||||
|
||||
void key_down(const unsigned long& keyCode);
|
||||
void key_up(const unsigned long& keyCode);
|
||||
void mouse_move(const ivec2& position);
|
||||
void mouse_scroll(const unsigned int& distance);
|
||||
|
||||
bool is_key_down(const unsigned long& keyCode);
|
||||
bool is_key_pressed(const unsigned long& keyCode);
|
||||
bool is_key_released(const unsigned long& keyCode);
|
||||
const ivec2& get_mouse_position();
|
||||
const ivec2& get_mouse_delta();
|
||||
const int& get_scroll_distance();
|
||||
|
||||
private:
|
||||
//Keys pressed since the last frame
|
||||
//The existance of a value in this array means that the key has changed to that state
|
||||
//since the last mark() call.
|
||||
//A value of true means the key was pressed, false means the value was released
|
||||
std::map<unsigned long, bool> m_keys_pressed;
|
||||
|
||||
//Keys that are down
|
||||
std::map<unsigned long, bool> m_keys_down;
|
||||
|
||||
//Current Mouse Position
|
||||
ivec2 m_mouse_position;
|
||||
|
||||
//Change in mouse position since last mark() call
|
||||
ivec2 m_mouse_delta;
|
||||
|
||||
//The change in scroll (mouse wheel) sinc ethe last mark() call
|
||||
int m_scroll_distance;
|
||||
|
||||
//TODO: Controller Movement
|
||||
};
|
36
OpenGLEngine/MyApplication.cpp
Normal file
36
OpenGLEngine/MyApplication.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "MyApplication.h"
|
||||
|
||||
|
||||
|
||||
MyApplication::MyApplication(const char* class_name, HINSTANCE h_instance)
|
||||
: Application(class_name, h_instance)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MyApplication::~MyApplication()
|
||||
{
|
||||
}
|
||||
|
||||
bool MyApplication::init()
|
||||
{
|
||||
m_scene.use();
|
||||
return true;
|
||||
}
|
||||
|
||||
void MyApplication::update(float delta_time, clock_t clock)
|
||||
{
|
||||
m_scene.update(delta_time, clock);
|
||||
}
|
||||
|
||||
void MyApplication::render()
|
||||
{
|
||||
m_scene.render();
|
||||
}
|
||||
|
||||
void MyApplication::close()
|
||||
{
|
||||
m_scene.unuse();
|
||||
}
|
||||
|
||||
|
24
OpenGLEngine/MyApplication.h
Normal file
24
OpenGLEngine/MyApplication.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "Application.h"
|
||||
|
||||
#include "MySimpleScene.h"
|
||||
|
||||
class MyApplication :
|
||||
public Application
|
||||
{
|
||||
public:
|
||||
MyApplication(const char* class_name, HINSTANCE h_instance);
|
||||
~MyApplication();
|
||||
|
||||
bool init() override;
|
||||
|
||||
void update(float delta_time, clock_t clock) override;
|
||||
|
||||
void render() override;
|
||||
|
||||
void close() override;
|
||||
|
||||
private:
|
||||
MySimpleScene m_scene;
|
||||
};
|
||||
|
26
OpenGLEngine/MySimpleScene.cpp
Normal file
26
OpenGLEngine/MySimpleScene.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "MySimpleScene.h"
|
||||
|
||||
MySimpleScene::MySimpleScene()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MySimpleScene::~MySimpleScene()
|
||||
{
|
||||
}
|
||||
|
||||
void MySimpleScene::use()
|
||||
{
|
||||
}
|
||||
|
||||
void MySimpleScene::unuse()
|
||||
{
|
||||
}
|
||||
|
||||
void MySimpleScene::update(float delta_time, clock_t clock)
|
||||
{
|
||||
}
|
||||
|
||||
void MySimpleScene::render()
|
||||
{
|
||||
}
|
22
OpenGLEngine/MySimpleScene.h
Normal file
22
OpenGLEngine/MySimpleScene.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "Scene.h"
|
||||
|
||||
class MySimpleScene :
|
||||
public Scene
|
||||
{
|
||||
public:
|
||||
MySimpleScene();
|
||||
~MySimpleScene();
|
||||
|
||||
void use() override;
|
||||
|
||||
void unuse() override;
|
||||
|
||||
void update(float delta_time, clock_t clock) override;
|
||||
|
||||
void render() override;
|
||||
};
|
||||
|
144
OpenGLEngine/OpenGLEngine.vcxproj
Normal file
144
OpenGLEngine/OpenGLEngine.vcxproj
Normal file
@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{C03B666E-F3CE-4223-977D-9D6E2952F22E}</ProjectGuid>
|
||||
<RootNamespace>OpenGLEngine</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>C:\Users\peterm8\source\repos\OpenGLEngine\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>C:\Users\peterm8\source\repos\OpenGLEngine\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Application.cpp" />
|
||||
<ClCompile Include="FPS.cpp" />
|
||||
<ClCompile Include="InputManager.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="MyApplication.cpp" />
|
||||
<ClCompile Include="MySimpleScene.cpp" />
|
||||
<ClCompile Include="Window.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Application.h" />
|
||||
<ClInclude Include="FPS.h" />
|
||||
<ClInclude Include="InputManager.h" />
|
||||
<ClInclude Include="mat4x4.h" />
|
||||
<ClInclude Include="MyApplication.h" />
|
||||
<ClInclude Include="MySimpleScene.h" />
|
||||
<ClInclude Include="Scene.h" />
|
||||
<ClInclude Include="vec2.h" />
|
||||
<ClInclude Include="vec3.h" />
|
||||
<ClInclude Include="vec4.h" />
|
||||
<ClInclude Include="Window.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
84
OpenGLEngine/OpenGLEngine.vcxproj.filters
Normal file
84
OpenGLEngine/OpenGLEngine.vcxproj.filters
Normal file
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<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>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\math">
|
||||
<UniqueIdentifier>{3011da99-7ced-44b5-b379-754b5db0a1c3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Example">
|
||||
<UniqueIdentifier>{6a527248-fa21-4720-8864-49088116987e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Example">
|
||||
<UniqueIdentifier>{6f8b9833-6eed-478e-a52d-38bdb2573b92}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Window.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="InputManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Application.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FPS.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MyApplication.cpp">
|
||||
<Filter>Source Files\Example</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MySimpleScene.cpp">
|
||||
<Filter>Source Files\Example</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files\Example</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Window.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="InputManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="mat4x4.h">
|
||||
<Filter>Header Files\math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="vec2.h">
|
||||
<Filter>Header Files\math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="vec3.h">
|
||||
<Filter>Header Files\math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="vec4.h">
|
||||
<Filter>Header Files\math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Application.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MyApplication.h">
|
||||
<Filter>Header Files\Example</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Scene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FPS.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MySimpleScene.h">
|
||||
<Filter>Header Files\Example</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
22
OpenGLEngine/Scene.h
Normal file
22
OpenGLEngine/Scene.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
// Called when the scene is going to be used
|
||||
// Should allocate all graphics memory.
|
||||
virtual void use() = 0;
|
||||
|
||||
// Called when the scene is no longer going to be used
|
||||
// Should release all graphics memory
|
||||
virtual void unuse() = 0;
|
||||
|
||||
// Called when the frame is being updated
|
||||
virtual void update(float delta_time, clock_t clock) = 0;
|
||||
|
||||
// Called when the frame is being rendered
|
||||
virtual void render() = 0;
|
||||
};
|
||||
|
207
OpenGLEngine/Window.cpp
Normal file
207
OpenGLEngine/Window.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
#include "Window.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "vec2.h"
|
||||
|
||||
namespace {
|
||||
// Only one Window can be created per HWND
|
||||
std::map<HWND, Window*> g_windows;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK main_wnd_proc(HWND h_wnd, UINT msg, WPARAM w_param, LPARAM l_param) {
|
||||
auto w = g_windows.find(h_wnd);
|
||||
if (w == g_windows.end())
|
||||
{
|
||||
return DefWindowProc(h_wnd, msg, w_param, l_param);
|
||||
}
|
||||
else
|
||||
{
|
||||
return w->second->wnd_proc(h_wnd, msg, w_param, l_param);
|
||||
}
|
||||
}
|
||||
|
||||
Window::Window(const char* class_name, HINSTANCE h_instance)
|
||||
: m_class_name(class_name), m_h_instance(h_instance)
|
||||
{
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
if (m_h_wnd != nullptr)
|
||||
{
|
||||
g_windows.erase(m_h_wnd);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Window::wnd_proc(HWND h_wnd, UINT msg, WPARAM w_param, LPARAM l_param)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
m_input_manager.key_down(l_param);
|
||||
return DefWindowProc(h_wnd, msg, w_param, l_param);
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
m_input_manager.key_up((unsigned long)l_param);
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
m_input_manager.key_down(VK_LBUTTON);
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
m_input_manager.key_up(VK_LBUTTON);
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
m_input_manager.key_down(VK_RBUTTON);
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
m_input_manager.key_up(VK_RBUTTON);
|
||||
break;
|
||||
case WM_MBUTTONDOWN:
|
||||
m_input_manager.key_down(VK_MBUTTON);
|
||||
break;
|
||||
case WM_MBUTTONUP:
|
||||
m_input_manager.key_up(VK_MBUTTON);
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
m_input_manager.mouse_move(ivec2(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param)));
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
m_input_manager.mouse_scroll(GET_WHEEL_DELTA_WPARAM(w_param) / WHEEL_DELTA);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
return DefWindowProc(h_wnd, msg, w_param, l_param);
|
||||
}
|
||||
|
||||
bool Window::register_class()
|
||||
{
|
||||
m_wc.style = 0;
|
||||
|
||||
m_wc.cbSize = sizeof(WNDCLASSEX);
|
||||
m_wc.cbClsExtra = 0;
|
||||
m_wc.cbWndExtra = 0;
|
||||
|
||||
m_wc.hInstance = m_h_instance;
|
||||
|
||||
m_wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
m_wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
m_wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
m_wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
|
||||
|
||||
m_wc.lpszClassName = m_class_name;
|
||||
m_wc.lpszMenuName = NULL;
|
||||
|
||||
m_wc.lpfnWndProc = main_wnd_proc;
|
||||
|
||||
return RegisterClassEx(&m_wc);
|
||||
}
|
||||
|
||||
bool Window::create_window(const char* title, int x, int y, int w, int h)
|
||||
{
|
||||
if (m_h_wnd != NULL)
|
||||
{
|
||||
g_windows.erase(m_h_wnd);
|
||||
}
|
||||
|
||||
// Fix for window border with width and height
|
||||
DWORD style = WS_POPUP | WS_VISIBLE | WS_SYSMENU;
|
||||
RECT window_rect = { 0, 0, w, h };
|
||||
AdjustWindowRect(&window_rect, style, false);
|
||||
int width = window_rect.right - window_rect.left;
|
||||
int height = window_rect.bottom - window_rect.top;
|
||||
|
||||
if (x == -1)
|
||||
{
|
||||
// Center x-position
|
||||
x = GetSystemMetrics(SM_CXSCREEN) / 2 - width / 2;
|
||||
}
|
||||
|
||||
if (y == -1)
|
||||
{
|
||||
// Center y-position
|
||||
y = GetSystemMetrics(SM_CYSCREEN) / 2 - height / 2;
|
||||
}
|
||||
|
||||
m_h_wnd = CreateWindow
|
||||
(
|
||||
m_class_name,
|
||||
title,
|
||||
style,
|
||||
x, y,
|
||||
width, height,
|
||||
NULL,
|
||||
NULL,
|
||||
m_h_instance,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (m_h_wnd != NULL)
|
||||
{
|
||||
// TODO: Figure out why value_type is needed here...
|
||||
g_windows.insert(std::map<HWND, Window*>::value_type(m_h_wnd, this));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
MessageResponse Window::handle_message()
|
||||
{
|
||||
MSG msg = { 0 };
|
||||
if (!PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
|
||||
{
|
||||
return NO_MESSAGE;
|
||||
}
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
return QUIT_MESSAGE;
|
||||
}
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
return HANDLED_MESSAGE;
|
||||
}
|
||||
|
||||
void Window::show(int cmd_show)
|
||||
{
|
||||
ShowWindow(m_h_wnd, cmd_show);
|
||||
}
|
||||
|
||||
void Window::update()
|
||||
{
|
||||
UpdateWindow(m_h_wnd);
|
||||
}
|
||||
|
||||
void Window::close()
|
||||
{
|
||||
CloseWindow(m_h_wnd);
|
||||
}
|
||||
|
||||
void Window::set_h_glrc(HGLRC h_glrc)
|
||||
{
|
||||
m_h_glrc = h_glrc;
|
||||
}
|
||||
|
||||
HGLRC Window::get_h_glrc()
|
||||
{
|
||||
return m_h_glrc;
|
||||
}
|
||||
|
||||
HWND Window::get_h_wnd()
|
||||
{
|
||||
return m_h_wnd;
|
||||
}
|
||||
|
||||
const InputManager & Window::get_input_manager()
|
||||
{
|
||||
return m_input_manager;
|
||||
}
|
66
OpenGLEngine/Window.h
Normal file
66
OpenGLEngine/Window.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include "InputManager.h"
|
||||
|
||||
enum MessageResponse {
|
||||
UNSET,
|
||||
NO_MESSAGE,
|
||||
HANDLED_MESSAGE,
|
||||
QUIT_MESSAGE
|
||||
};
|
||||
|
||||
// A class to create a window in windows.
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
Window(const char* class_name, HINSTANCE h_instance);
|
||||
~Window();
|
||||
|
||||
LRESULT CALLBACK wnd_proc(HWND h_wnd, UINT msg, WPARAM w_param, LPARAM l_param);
|
||||
|
||||
// Registers m_wc with windows.
|
||||
bool register_class();
|
||||
|
||||
// Creates the window
|
||||
// Use -1 for x and/or y to specify centered relative to the screen.
|
||||
bool create_window(const char* title, int x, int y, int w, int h);
|
||||
|
||||
// Peeks the next message for the window, translates it, and then
|
||||
// dispatches it.
|
||||
// Returns true for a regular message. False for an exit message.
|
||||
// When the message is an exit message, the message will not be translated
|
||||
// or dispatched.
|
||||
MessageResponse handle_message();
|
||||
|
||||
// Calls ShowWindow on the HWND
|
||||
void show(int cmd_show);
|
||||
|
||||
// Calls UpdateWindow on the HWND
|
||||
void update();
|
||||
|
||||
// Calls CloseWindow on the HWND
|
||||
void close();
|
||||
|
||||
void set_h_glrc(HGLRC h_glrc);
|
||||
|
||||
// Returns the HWND
|
||||
HWND get_h_wnd();
|
||||
|
||||
HGLRC get_h_glrc();
|
||||
|
||||
// Returns the InputManager
|
||||
const InputManager& get_input_manager();
|
||||
|
||||
private:
|
||||
const char* m_class_name;
|
||||
|
||||
HINSTANCE m_h_instance = nullptr;
|
||||
WNDCLASSEX m_wc;
|
||||
HWND m_h_wnd = nullptr;
|
||||
HGLRC m_h_glrc = nullptr; // The OpenGL Rendering Context (Extra variable used by application)
|
||||
|
||||
InputManager m_input_manager;
|
||||
};
|
||||
|
6
OpenGLEngine/main.cpp
Normal file
6
OpenGLEngine/main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "MyApplication.h"
|
||||
|
||||
int WINAPI WinMain(HINSTANCE h_instance, HINSTANCE h_prev_instance, LPSTR cmd_line, int n_cmd_show) {
|
||||
MyApplication my_app("my_app", h_instance);
|
||||
return my_app.run();
|
||||
}
|
248
OpenGLEngine/mat4x4.h
Normal file
248
OpenGLEngine/mat4x4.h
Normal file
@ -0,0 +1,248 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "vec4.h"
|
||||
|
||||
namespace egm
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct tmat4x4
|
||||
{
|
||||
//a = Row 1
|
||||
//b = Row 2
|
||||
//c = Row 3
|
||||
//d = Row 4
|
||||
//x = Column 1
|
||||
//y = Column 2
|
||||
//z = Column 3
|
||||
//w = Column 4
|
||||
tvec4<T> a;
|
||||
tvec4<T> b;
|
||||
tvec4<T> c;
|
||||
tvec4<T> d;
|
||||
|
||||
//Identity Matrix
|
||||
tmat4x4() : a(1, 0, 0, 0), b(0, 1, 0, 0), c(0, 0, 1, 0), d(0, 0, 0, 1) {}
|
||||
|
||||
//Sets row by row
|
||||
tmat4x4(const tvec4<T>& a, const tvec4<T>& b, const tvec4<T>& c, const tvec4<T>& d) : a(a), b(b), c(c), d(d) {}
|
||||
|
||||
//Sets by value (letter = row, number = column)
|
||||
tmat4x4(
|
||||
const T& a1, const T& a2, const T& a3, const T& a4,
|
||||
const T& b1, const T& b2, const T& b3, const T& b4,
|
||||
const T& c1, const T& c2, const T& c3, const T& c4,
|
||||
const T& d1, const T& d2, const T& d3, const T& d4
|
||||
) :
|
||||
a(a1, a2, a3, a4),
|
||||
b(b1, b2, b3, b4),
|
||||
c(c1, c2, c3, c4),
|
||||
d(d1, d2, d3, d4)
|
||||
{}
|
||||
|
||||
tvec4<T>& operator[](const unsigned int& index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return a;
|
||||
case 1:
|
||||
return b;
|
||||
case 2:
|
||||
return c;
|
||||
case 3:
|
||||
return d;
|
||||
default:
|
||||
throw "Index Out Of Bounds";
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const tmat4x4<T>& o)
|
||||
{
|
||||
return (o.a == a && o.b == b && o.c == c && o.d == d);
|
||||
}
|
||||
|
||||
tmat4x4<T>& operator=(const tmat4x4<T>& o)
|
||||
{
|
||||
a = o.a;
|
||||
b = o.b;
|
||||
c = o.c;
|
||||
d = o.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tmat4x4<T> operator+(const tmat4x4<T>& o) const
|
||||
{
|
||||
return {
|
||||
a + o.a,
|
||||
b + o.b,
|
||||
c + o.c,
|
||||
d + o.d
|
||||
}
|
||||
}
|
||||
|
||||
tmat4x4<T>& operator+=(const tmat4x4<T>& o)
|
||||
{
|
||||
a += o.a;
|
||||
b += o.b;
|
||||
c += o.c;
|
||||
d += o.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tmat4x4<T> operator-(const tmat4x4<T>& o) const
|
||||
{
|
||||
return {
|
||||
a - o.a,
|
||||
b - o.b,
|
||||
c - o.c,
|
||||
d - o.d
|
||||
}
|
||||
}
|
||||
|
||||
tmat4x4<T>& operator-=(const tmat4x4<T>& o)
|
||||
{
|
||||
a -= o.a;
|
||||
b -= o.b;
|
||||
c -= o.c;
|
||||
d -= o.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator*(const tvec4<T>& v) const
|
||||
{
|
||||
return {
|
||||
a.x * v.x + a.y * v.y + a.z * v.z + a.w * v.w,//mRow 1 dot v
|
||||
b.x * v.x + b.y * v.y + b.z * v.z + b.w * v.w,//mRow 2 dot v
|
||||
c.x * v.x + c.y * v.y + c.z * v.z + c.w * v.w,//mRow 3 dot v
|
||||
d.x * v.x + d.y * v.y + d.z * v.z + d.w * v.w //mRow 4 dot v
|
||||
};
|
||||
}
|
||||
|
||||
tmat4x4<T> operator*(const tmat4x4<T>& m) const
|
||||
{
|
||||
return {
|
||||
//Row 1a
|
||||
m.a.x * a.x + m.b.x * a.y + m.c.x * a.z + m.d.x * a.w,//Column 1b
|
||||
m.a.y * a.x + m.b.y * a.y + m.c.y * a.z + m.d.y * a.w,//Column 2b
|
||||
m.a.z * a.x + m.b.z * a.y + m.c.z * a.z + m.d.z * a.w,//Column 3b
|
||||
m.a.w * a.x + m.b.w * a.y + m.c.w * a.z + m.d.w * a.w,//Column 4b
|
||||
|
||||
//Row 2a
|
||||
m.a.x * b.x + m.b.x * b.y + m.c.x * b.z + m.d.x * b.w,//Column 1b
|
||||
m.a.y * b.x + m.b.y * b.y + m.c.y * b.z + m.d.y * b.w,//Column 2b
|
||||
m.a.z * b.x + m.b.z * b.y + m.c.z * b.z + m.d.z * b.w,//Column 3b
|
||||
m.a.w * b.x + m.b.w * b.y + m.c.w * b.z + m.d.w * b.w,//Column 4b
|
||||
|
||||
//Row 3a
|
||||
m.a.x * c.x + m.b.x * c.y + m.c.x * c.z + m.d.x * c.w,//Column 1b
|
||||
m.a.y * c.x + m.b.y * c.y + m.c.y * c.z + m.d.y * c.w,//Column 2b
|
||||
m.a.z * c.x + m.b.z * c.y + m.c.z * c.z + m.d.z * c.w,//Column 3b
|
||||
m.a.w * c.x + m.b.w * c.y + m.c.w * c.z + m.d.w * c.w,//Column 4b
|
||||
|
||||
//Row 4a
|
||||
m.a.x * d.x + m.b.x * d.y + m.c.x * d.z + m.d.x * d.w,//Column 1b
|
||||
m.a.y * d.x + m.b.y * d.y + m.c.y * d.z + m.d.y * d.w,//Column 2b
|
||||
m.a.z * d.x + m.b.z * d.y + m.c.z * d.z + m.d.z * d.w,//Column 3b
|
||||
m.a.w * d.x + m.b.w * d.y + m.c.w * d.z + m.d.w * d.w,//Column 4b
|
||||
};
|
||||
//Backwards
|
||||
/*return {
|
||||
//Row 1b
|
||||
a.x * m.a.x + b.x * m.a.y + c.x * m.a.z + d.x * m.a.w,//Column 1a
|
||||
a.y * m.a.x + b.y * m.a.y + c.y * m.a.z + d.y * m.a.w,//Column 2a
|
||||
a.z * m.a.x + b.z * m.a.y + c.z * m.a.z + d.z * m.a.w,//Column 3a
|
||||
a.w * m.a.x + b.w * m.a.y + c.w * m.a.z + d.w * m.a.w,//Column 4a
|
||||
|
||||
//Row 2b
|
||||
a.x * m.b.x + b.x * m.b.y + c.x * m.b.z + d.x * m.b.w,//Column 1a
|
||||
a.y * m.b.x + b.y * m.b.y + c.y * m.b.z + d.y * m.b.w,//Column 2a
|
||||
a.z * m.b.x + b.z * m.b.y + c.z * m.b.z + d.z * m.b.w,//Column 3a
|
||||
a.w * m.b.x + b.w * m.b.y + c.w * m.b.z + d.w * m.b.w,//Column 4a
|
||||
|
||||
//Row 3b
|
||||
a.x * m.c.x + b.x * m.c.y + c.x * m.c.z + d.x * m.c.w,//Column 1a
|
||||
a.y * m.c.x + b.y * m.c.y + c.y * m.c.z + d.y * m.c.w,//Column 2a
|
||||
a.z * m.c.x + b.z * m.c.y + c.z * m.c.z + d.z * m.c.w,//Column 3a
|
||||
a.w * m.c.x + b.w * m.c.y + c.w * m.c.z + d.w * m.c.w,//Column 4a
|
||||
|
||||
//Row 4b
|
||||
a.x * m.d.x + b.x * m.d.y + c.x * m.d.z + d.x * m.d.w,//Column 1a
|
||||
a.y * m.d.x + b.y * m.d.y + c.y * m.d.z + d.y * m.d.w,//Column 2a
|
||||
a.z * m.d.x + b.z * m.d.y + c.z * m.d.z + d.z * m.d.w,//Column 3a
|
||||
a.w * m.d.x + b.w * m.d.y + c.w * m.d.z + d.w * m.d.w,//Column 4a
|
||||
};*/
|
||||
}
|
||||
|
||||
tmat4x4<T>& operator*=(const tmat4x4<T>& o)
|
||||
{
|
||||
*this = *this * o;
|
||||
}
|
||||
|
||||
tmat4x4<T> operator*(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
a * scalar,
|
||||
b * scalar,
|
||||
c * scalar,
|
||||
d * scalar
|
||||
}
|
||||
}
|
||||
|
||||
tmat4x4<T>& operator*=(const T& scalar)
|
||||
{
|
||||
a *= scalar;
|
||||
b *= scalar;
|
||||
c *= scalar;
|
||||
d *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tmat4x4<T> operator/(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
a / scalar,
|
||||
b / scalar,
|
||||
c / scalar,
|
||||
d / scalar
|
||||
}
|
||||
}
|
||||
|
||||
tmat4x4<T>& operator/=(const T& scalar)
|
||||
{
|
||||
a /= scalar;
|
||||
b /= scalar;
|
||||
c /= scalar;
|
||||
d /= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator RECT()
|
||||
{
|
||||
return {
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
}
|
||||
}
|
||||
|
||||
float* data()
|
||||
{
|
||||
return &(a.x);
|
||||
}
|
||||
};
|
||||
|
||||
typedef tmat4x4<float> mat4x4;
|
||||
typedef tmat4x4<double> dmat4x4;
|
||||
typedef tmat4x4<int> imat4x4;
|
||||
|
||||
const mat4x4 IDENTITY_MATRIX(
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
}
|
145
OpenGLEngine/vec2.h
Normal file
145
OpenGLEngine/vec2.h
Normal file
@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
namespace egm
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct tvec2
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
|
||||
tvec2() : x(0), y(0) {}
|
||||
tvec2(const tvec2<T>& v) : x(v.x), y(v.y) {}
|
||||
template <typename U>
|
||||
tvec2(const tvec2<U>& v) : x((T)v.x), y((T)v.y) {}
|
||||
tvec2(const T& scalar) : x(scalar), y(scalar) {}
|
||||
tvec2(const T& scalar1, const T& scalar2) : x(scalar1), y(scalar2) {}
|
||||
|
||||
T& operator[](const unsigned int& index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
throw "Index Out Of Bounds";
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const tvec2<T>& o)
|
||||
{
|
||||
return (o.x == x && o.y == y);
|
||||
}
|
||||
|
||||
tvec2<T>& operator=(const tvec2<T>& o)
|
||||
{
|
||||
x = o.x;
|
||||
y = o.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec2<T> operator+(const tvec2<T>& o) const
|
||||
{
|
||||
return {
|
||||
x + o.x,
|
||||
y + o.y
|
||||
};
|
||||
}
|
||||
|
||||
tvec2<T>& operator+=(const tvec2<T>& o)
|
||||
{
|
||||
x += o.x;
|
||||
y += o.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec2<T> operator-(const tvec2<T>& o) const
|
||||
{
|
||||
return {
|
||||
x - o.x,
|
||||
y - o.y
|
||||
};
|
||||
}
|
||||
|
||||
tvec2<T>& operator-=(const tvec2<T>& o)
|
||||
{
|
||||
x -= o.x;
|
||||
y -= o.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec2<T> operator*(const tvec2<T>& o) const
|
||||
{
|
||||
return {
|
||||
x * o.x,
|
||||
y * o.y
|
||||
};
|
||||
}
|
||||
|
||||
tvec2<T>& operator*=(const tvec2<T>& o)
|
||||
{
|
||||
x *= o.x;
|
||||
y *= o.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec2<T> operator*(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
x * scalar,
|
||||
y * scalar
|
||||
};
|
||||
}
|
||||
|
||||
tvec2<T>& operator*=(const T& scalar)
|
||||
{
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec2<T> operator/(const tvec2<T>& o) const
|
||||
{
|
||||
return {
|
||||
x / o.x,
|
||||
y / o.y
|
||||
};
|
||||
}
|
||||
|
||||
tvec2<T>& operator/=(const tvec2<T>& o)
|
||||
{
|
||||
x /= o.x;
|
||||
y /= o.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec2<T> operator/(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
x / scalar,
|
||||
y / scalar
|
||||
};
|
||||
}
|
||||
|
||||
tvec2<T>& operator/=(const T& scalar)
|
||||
{
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float* data()
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef tvec2<float> vec2;
|
||||
typedef tvec2<double> dvec2;
|
||||
typedef tvec2<int> ivec2;
|
||||
}
|
161
OpenGLEngine/vec3.h
Normal file
161
OpenGLEngine/vec3.h
Normal file
@ -0,0 +1,161 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
namespace egm
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct tvec3
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
tvec3() : x(0), y(0), z(0) {}
|
||||
tvec3(const tvec3<T>& v) : x(v.x), y(v.y), z(v.z) {}
|
||||
template <typename U>
|
||||
tvec3(const tvec3<U>& v) : x((T)v.x), y((T)v.y), z((T)v.z) {}
|
||||
tvec3(const T& scalar) : x(scalar), y(scalar), z(scalar) {}
|
||||
tvec3(const T& scalar1, const T& scalar2, const T& scalar3) : x(scalar1), y(scalar2), z(scalar3) {}
|
||||
|
||||
T& operator[](const unsigned int& index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
throw "Index Out Of Bounds";
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const tvec3<T>& o)
|
||||
{
|
||||
return (o.x == x && o.y == y && o.z == z);
|
||||
}
|
||||
|
||||
tvec3<T>& operator=(const tvec3<T>& o)
|
||||
{
|
||||
x = o.x;
|
||||
y = o.y;
|
||||
z = o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec3<T> operator+(const tvec3<T>& o) const
|
||||
{
|
||||
return {
|
||||
x + o.x,
|
||||
y + o.y,
|
||||
z + o.z
|
||||
};
|
||||
}
|
||||
|
||||
tvec3<T>& operator+=(const tvec3<T>& o)
|
||||
{
|
||||
x += o.x;
|
||||
y += o.y;
|
||||
z += o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec3<T> operator-(const tvec3<T>& o) const
|
||||
{
|
||||
return {
|
||||
x - o.x,
|
||||
y - o.y,
|
||||
z - o.z
|
||||
};
|
||||
}
|
||||
|
||||
tvec3<T>& operator-=(const tvec3<T>& o)
|
||||
{
|
||||
x -= o.x;
|
||||
y -= o.y;
|
||||
z -= o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec3<T> operator*(const tvec3<T>& o) const
|
||||
{
|
||||
return {
|
||||
x * o.x,
|
||||
y * o.y,
|
||||
z * o.z
|
||||
};
|
||||
}
|
||||
|
||||
tvec3<T>& operator*=(const tvec3<T>& o)
|
||||
{
|
||||
x *= o.x;
|
||||
y *= o.y;
|
||||
z *= o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec3<T> operator*(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
x * scalar,
|
||||
y * scalar,
|
||||
z * scalar
|
||||
};
|
||||
}
|
||||
|
||||
tvec3<T>& operator*=(const T& scalar)
|
||||
{
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec3<T> operator/(const tvec3<T>& o) const
|
||||
{
|
||||
return {
|
||||
x / o.x,
|
||||
y / o.y,
|
||||
z / o.z
|
||||
};
|
||||
}
|
||||
|
||||
tvec3<T>& operator/=(const tvec3<T>& o)
|
||||
{
|
||||
x /= o.x;
|
||||
y /= o.y;
|
||||
z /= o.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec3<T> operator/(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
x / scalar,
|
||||
y / scalar,
|
||||
z / scalar
|
||||
};
|
||||
}
|
||||
|
||||
tvec3<T>& operator/=(const T& scalar)
|
||||
{
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
z /= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float* data()
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef tvec3<float> vec3;
|
||||
typedef tvec3<double> dvec3;
|
||||
typedef tvec3<int> ivec3;
|
||||
}
|
190
OpenGLEngine/vec4.h
Normal file
190
OpenGLEngine/vec4.h
Normal file
@ -0,0 +1,190 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "vec2.h"
|
||||
|
||||
namespace egm
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct tvec4
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
|
||||
tvec4() : x(0), y(0), z(0), w(0) {}
|
||||
tvec4(const tvec4<T>& v) : x(v.x), y(v.y), z(v.z), w(v.w) {}
|
||||
template <typename U>
|
||||
tvec4(const tvec4<U>& v) : x((T)v.x), y((T)v.y), z((T)v.z), w((T)v.w) {}
|
||||
tvec4(const tvec2<T>& a, const tvec2<T>& b) : x(a.x), y(a.y), z(b.x), w(b.y) {}
|
||||
tvec4(const T& scalar) : x(scalar), y(scalar), z(scalar), w(scalar) {}
|
||||
tvec4(const T& scalar1, const T& scalar2, const T& scalar3, const T& scalar4) : x(scalar1), y(scalar2), z(scalar3), w(scalar4) {}
|
||||
|
||||
T& operator[](const unsigned int& index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
case 3:
|
||||
return w;
|
||||
default:
|
||||
throw "Index Out Of Bounds";
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const tvec4<T>& o)
|
||||
{
|
||||
return (o.x == x && o.y == y && o.z == z && o.w == w);
|
||||
}
|
||||
|
||||
tvec4<T>& operator=(const tvec4<T>& o)
|
||||
{
|
||||
x = o.x;
|
||||
y = o.y;
|
||||
z = o.z;
|
||||
w = o.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator+(const tvec4<T>& o) const
|
||||
{
|
||||
return {
|
||||
x + o.x,
|
||||
y + o.y,
|
||||
z + o.z,
|
||||
w + o.w
|
||||
}
|
||||
}
|
||||
|
||||
tvec4<T>& operator+=(const tvec4<T>& o)
|
||||
{
|
||||
x += o.x;
|
||||
y += o.y;
|
||||
z += o.z;
|
||||
w += o.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator-(const tvec4<T>& o) const
|
||||
{
|
||||
return {
|
||||
x - o.x,
|
||||
y - o.y,
|
||||
z - o.z,
|
||||
w - o.w
|
||||
}
|
||||
}
|
||||
|
||||
tvec4<T>& operator-=(const tvec4<T>& o)
|
||||
{
|
||||
x -= o.x;
|
||||
y -= o.y;
|
||||
z -= o.z;
|
||||
w -= o.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator*(const tvec4<T>& o) const
|
||||
{
|
||||
return {
|
||||
x * o.x,
|
||||
y * o.y,
|
||||
z * o.z,
|
||||
w * o.w
|
||||
}
|
||||
}
|
||||
|
||||
tvec4<T>& operator*=(const tvec4<T>& o)
|
||||
{
|
||||
x *= o.x;
|
||||
y *= o.y;
|
||||
z *= o.z;
|
||||
w *= o.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator*(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
x * scalar,
|
||||
y * scalar,
|
||||
z * scalar,
|
||||
w * scalar
|
||||
}
|
||||
}
|
||||
|
||||
tvec4<T>& operator*=(const T& scalar)
|
||||
{
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
w *= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator/(const tvec4<T>& o) const
|
||||
{
|
||||
return {
|
||||
x / o.x,
|
||||
y / o.y,
|
||||
z / o.z,
|
||||
w / o.w
|
||||
}
|
||||
}
|
||||
|
||||
tvec4<T>& operator/=(const tvec4<T>& o)
|
||||
{
|
||||
x /= o.x;
|
||||
y /= o.y;
|
||||
z /= o.z;
|
||||
w /= o.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
tvec4<T> operator/(const T& scalar) const
|
||||
{
|
||||
return {
|
||||
x / scalar,
|
||||
y / scalar,
|
||||
z / scalar,
|
||||
w / scalar
|
||||
};
|
||||
}
|
||||
|
||||
tvec4<T>& operator/=(const T& scalar)
|
||||
{
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
z /= scalar;
|
||||
w /= scalar;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator RECT()
|
||||
{
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
w
|
||||
}
|
||||
}
|
||||
|
||||
float* data()
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef tvec4<float> vec4;
|
||||
typedef tvec4<double> dvec4;
|
||||
typedef tvec4<int> ivec4;
|
||||
}
|
2618
include/glew/eglew.h
Normal file
2618
include/glew/eglew.h
Normal file
File diff suppressed because it is too large
Load Diff
23686
include/glew/glew.h
Normal file
23686
include/glew/glew.h
Normal file
File diff suppressed because it is too large
Load Diff
1775
include/glew/glxew.h
Normal file
1775
include/glew/glxew.h
Normal file
File diff suppressed because it is too large
Load Diff
1447
include/glew/wglew.h
Normal file
1447
include/glew/wglew.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user