RAYS CAUSE WE BASED N SHIT

master
BuildTools 5 years ago
parent 4cac2beb4f
commit 233d07b573
  1. 20
      main.cpp
  2. 1
      stuff/globals/globals.cpp
  3. 2
      stuff/globals/globals.h
  4. 5
      stuff/objects/camera.h
  5. 4
      stuff/objects/cube.h
  6. 40
      stuff/objects/ray2D.h
  7. 2
      threedee.vcxproj
  8. 6
      threedee.vcxproj.filters

@ -1,9 +1,11 @@
#include <Windows.h>
#include <stdio.h>
#include <iostream>
#include "SDL.h"
#include "stuff/objects/vector2.h"
#include "stuff/objects/vector3.h"
#include "stuff/objects/ray2D.h"
#include "stuff/globals/globals.h"
#include "stuff/callbacks/callbacks.h"
@ -13,21 +15,35 @@ int main(int argc, char** argv)
{
SDL_Window* window = nullptr;
SDL_Surface* surface = nullptr;
SDL_Renderer* renderer = nullptr;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("threedee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN);
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateRenderer(window, -1, NULL);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_Event eventHandler;
global::entList.push_back(square(200, 200, 50));
//global::entList3D.push_back(cube(200, 200, 100, 50));
while (global::running)
{
callbacks::handleCallbacks(&eventHandler);
global::entList.run(surface);
//SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0, 0, 0));
ray2D ray = ray2D::trace(vector2(0, 200), vector2(1, 0));
//SDL_RenderClear(renderer);
SDL_RenderDrawLine(renderer, ray.start.x, ray.start.y, ray.end.x, ray.end.y);
SDL_RenderPresent(renderer);
//global::entList.run(surface);
//global::entList3D.run(surface);
SDL_UpdateWindowSurface(window);
//SDL_UpdateWindowSurface(window);
SDL_Delay(1);
}
SDL_DestroyWindow(window);

@ -3,3 +3,4 @@
bool global::running = true;
vector2 global::mousePos;
entityList2D global::entList;
entityList3D global::entList3D;

@ -1,9 +1,11 @@
#pragma once
#include "../objects/vector3.h"
#include "../objects/entityList2D.h"
#include "../objects/entityList3D.h"
namespace global
{
extern bool running;
extern vector2 mousePos;
extern entityList2D entList;
extern entityList3D entList3D;
}

@ -0,0 +1,5 @@
#pragma once
struct camera
{
};

@ -16,7 +16,7 @@ struct cube : public square
}
void run(SDL_Surface* surface)
{
SDL_Rect rect{ this->x, this->y, this->radius, this->radius };
SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
//SDL_Rect rect{ this->x, this->y, this->radius, this->radius };
//SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
}
};

@ -0,0 +1,40 @@
#pragma once
#include "../globals/globals.h"
#include "vector2.h"
//temp
bool inRect(vector2 point, vector2 a, vector2 b)
{
return (point.x > a.x && point.y > a.y && point.x < b.x && point.y < b.y);
}
struct ray2D
{
vector2 start;
vector2 end;
float dist;
static ray2D trace(vector2 start, vector2 direction)
{
ray2D ray { start, start, 19 };
vector2 point = start;
bool hit = false;
while (!hit)
{
for (square object : global::entList)
{
if (inRect(point, vector2(object.x - (object.radius / 2), object.y - (object.radius / 2)), vector2(object.x + (object.radius / 2), object.y + (object.radius / 2))))
{
ray.start = start;
ray.end = point;
ray.dist = 19;
hit = true;
break;
}
}
point.x += direction.x;
point.y += direction.y;
}
return ray;
}
};

@ -241,10 +241,12 @@
<ClInclude Include="sdl\include\SDL_video.h" />
<ClInclude Include="sdl\include\SDL_vulkan.h" />
<ClInclude Include="stuff\callbacks\callbacks.h" />
<ClInclude Include="stuff\objects\camera.h" />
<ClInclude Include="stuff\objects\entityList3D.h" />
<ClInclude Include="stuff\globals\globals.h" />
<ClInclude Include="stuff\objects\cube.h" />
<ClInclude Include="stuff\objects\entityList2D.h" />
<ClInclude Include="stuff\objects\ray2D.h" />
<ClInclude Include="stuff\objects\square.h" />
<ClInclude Include="stuff\objects\vector2.h" />
<ClInclude Include="stuff\objects\vector3.h" />

@ -297,6 +297,12 @@
<ClInclude Include="stuff\objects\entityList3D.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\camera.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\ray2D.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">

Loading…
Cancel
Save