organize, add some objects and event callbacks

master
BuildTools 5 years ago
parent 6f4b292709
commit 7761e67c2f
  1. 47
      main.cpp
  2. 17
      stuff/callbacks/callbacks.cpp
  3. 18
      stuff/callbacks/callbacks.h
  4. 4
      stuff/globals/globals.cpp
  5. 7
      stuff/globals/globals.h
  6. 21
      stuff/objects/vector.h
  7. 18
      stuff/objects/vector2.h
  8. 6
      threedee.vcxproj
  9. 18
      threedee.vcxproj.filters

@ -2,28 +2,16 @@
#include <stdio.h>
#include "SDL.h"
struct Vector2
{
float x, y;
Vector2()
{
this->x = 0.f;
this->y = 0.f;
}
Vector2(float x_, float y_)
{
this->x = x_;
this->y = y_;
}
};
#include "stuff/objects/vector2.h"
#include "stuff/objects/vector.h"
#include "stuff/globals/globals.h"
#include "stuff/callbacks/callbacks.h"
int main(int argc, char** argv)
{
bool running = true;
Vector2 mousePos;
SDL_Window* window = nullptr;;
SDL_Surface* surface = nullptr;;
SDL_Window* window = nullptr;
SDL_Surface* surface = nullptr;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("threedee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN);
@ -31,25 +19,10 @@ int main(int argc, char** argv)
SDL_Event eventHandler;
while (running)
{
while (SDL_PollEvent(&eventHandler))
{
switch (eventHandler.type)
while (global::running)
{
case SDL_QUIT:
running = false;
break;
case SDL_MOUSEMOTION:
mousePos = Vector2(eventHandler.motion.x, eventHandler.motion.y);
break;
}
}
SDL_Rect cursor;
cursor.x = mousePos.x;
cursor.y = mousePos.y;
cursor.w = 5;
cursor.h = 5;
callbacks::handleCallbacks(&eventHandler);
SDL_Rect cursor{ global::mousePos.x, global::mousePos.y, 5, 5 };
SDL_FillRect(surface, &cursor, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
SDL_UpdateWindowSurface(window);

@ -0,0 +1,17 @@
#include "callbacks.h"
void callbacks::handleCallbacks(SDL_Event* eventHandler)
{
while (SDL_PollEvent(eventHandler))
{
switch (eventHandler->type)
{
case SDL_QUIT:
global::running = false;
break;
case SDL_MOUSEMOTION:
callbacks::mouseMotion(eventHandler);
break;
}
}
}

@ -0,0 +1,18 @@
#pragma once
#include <iostream>
#include "SDL.h"
#include "../globals/globals.h"
namespace callbacks
{
inline void mouseMotion(SDL_Event* eventResponse)
{
global::mousePos = vector2(eventResponse->motion.x, eventResponse->motion.y);
}
inline void quit(SDL_Event* eventResponse)
{
global::running = false;
}
void handleCallbacks(SDL_Event* eventHandler);
}

@ -0,0 +1,4 @@
#include "globals.h"
bool global::running = true;
vector2 global::mousePos;

@ -0,0 +1,7 @@
#pragma once
#include "../objects/vector.h"
namespace global
{
extern bool running;
extern vector2 mousePos;
}

@ -0,0 +1,21 @@
#pragma once
#include "vector2.h"
/*
vectors extend vector2s and hold 3D cartesian coordinates
*/
struct vector : public vector2
{
float z;
vector()
{
this->x = 0.f;
this->y = 0.f;
this->z = 0.f;
}
vector(float x_, float y_, float z_)
{
this->x = x_;
this->y = y_;
this->z = z_;
}
};

@ -0,0 +1,18 @@
#pragma once
/*
vector2s hold 2D cartesian coordinates
*/
struct vector2
{
float x, y;
vector2()
{
this->x = 0.f;
this->y = 0.f;
}
vector2(float x_, float y_)
{
this->x = x_;
this->y = y_;
}
};

@ -240,9 +240,15 @@
<ClInclude Include="sdl\include\SDL_version.h" />
<ClInclude Include="sdl\include\SDL_video.h" />
<ClInclude Include="sdl\include\SDL_vulkan.h" />
<ClInclude Include="stuff\callbacks\callbacks.h" />
<ClInclude Include="stuff\globals\globals.h" />
<ClInclude Include="stuff\objects\vector2.h" />
<ClInclude Include="stuff\objects\vector.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="stuff\callbacks\callbacks.cpp" />
<ClCompile Include="stuff\globals\globals.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

@ -273,10 +273,28 @@
<ClInclude Include="sdl\include\SDL_vulkan.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\vector2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\vector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\globals\globals.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\callbacks\callbacks.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stuff\callbacks\callbacks.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stuff\globals\globals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading…
Cancel
Save