cleanup build. add demo project. add timing features to sync. switch to more std::string and std::vector usage over custom, hacky Array template

This commit is contained in:
2025-09-01 21:56:43 -05:00
parent b4e90dce4d
commit 75e72ba9ca
25 changed files with 663 additions and 1759 deletions

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ x64**
**.pdb
**.exe
.cache**
tags

View File

@@ -5,6 +5,8 @@ VisualStudioVersion = 17.12.35707.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LivePlotter", "LivePlotter.vcxproj", "{74C0F84F-216F-4A12-9F91-6AFC83CF9257}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{1873E9A4-995B-4327-98CA-2524EE2D8030}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -27,6 +29,18 @@ Global
{74C0F84F-216F-4A12-9F91-6AFC83CF9257}.Release|x64.Build.0 = Release|x64
{74C0F84F-216F-4A12-9F91-6AFC83CF9257}.Release|x86.ActiveCfg = Release|Win32
{74C0F84F-216F-4A12-9F91-6AFC83CF9257}.Release|x86.Build.0 = Release|Win32
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Debug|x64.ActiveCfg = Debug|x64
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Debug|x64.Build.0 = Debug|x64
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Debug|x86.ActiveCfg = Debug|Win32
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Debug|x86.Build.0 = Debug|Win32
{1873E9A4-995B-4327-98CA-2524EE2D8030}.DLLDebug|x64.ActiveCfg = Debug|x64
{1873E9A4-995B-4327-98CA-2524EE2D8030}.DLLDebug|x64.Build.0 = Debug|x64
{1873E9A4-995B-4327-98CA-2524EE2D8030}.DLLDebug|x86.ActiveCfg = Debug|Win32
{1873E9A4-995B-4327-98CA-2524EE2D8030}.DLLDebug|x86.Build.0 = Debug|Win32
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Release|x64.ActiveCfg = Release|x64
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Release|x64.Build.0 = Release|x64
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Release|x86.ActiveCfg = Release|Win32
{1873E9A4-995B-4327-98CA-2524EE2D8030}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -97,14 +97,14 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LibraryPath>$(ProjectDir)lib;$(ProjectDir)ext\glfw\build\src;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<LibraryPath>$(ProjectDir)ext\glfw\build\src\$(Configuration);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<IncludePath>$(ProjectDir)ext\glm;$(ProjectDir)ext\glfw\include;$(ProjectDir)inc;$(IncludePath)</IncludePath>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
<SourcePath>$(ProjectDir)src;$(SourcePath)</SourcePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDLL|x64'">
<LibraryPath>$(ProjectDir)lib;$(ProjectDir)ext\glfw\build\src;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<LibraryPath>$(ProjectDir)ext\glfw\build\src\$(Configuration);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<IncludePath>$(ProjectDir)ext\glm;$(ProjectDir)ext\glfw\include;$(ProjectDir)inc;$(IncludePath)</IncludePath>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
@@ -122,6 +122,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
<LibraryPath>$(ProjectDir)ext\glfw\build\src\$(Configuration);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
<IncludePath>$(ProjectDir)ext\glm;$(ProjectDir)ext\glfw\include;$(ProjectDir)inc;$(IncludePath)</IncludePath>
<SourcePath>$(ProjectDir)src;$(SourcePath)</SourcePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@@ -221,6 +224,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -235,12 +239,10 @@
<ItemGroup>
<ClCompile Include="src\body.cpp" />
<ClCompile Include="src\camera.cpp" />
<ClCompile Include="src\camera_poses.cpp" />
<ClCompile Include="src\glad.c" />
<ClCompile Include="src\live_plotter.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\shaders.cpp" />
<ClCompile Include="src\util.cpp" />
<ClCompile Include="util.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\body.hpp" />
@@ -249,6 +251,7 @@
<ClInclude Include="inc\live_plotter.hpp" />
<ClInclude Include="inc\shaders.hpp" />
<ClInclude Include="inc\util.hpp" />
<ClInclude Include="logger.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -15,30 +15,24 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\shaders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\glad.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\body.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\camera_poses.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\live_plotter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\body.hpp">
@@ -59,5 +53,8 @@
<ClInclude Include="inc\util.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="logger.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

156
Test.vcxproj Normal file
View File

@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>
<ItemGroup>
<ClCompile Include="src\demo.cpp" />
<ClCompile Include="util.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="LivePlotter.vcxproj">
<Project>{74c0f84f-216f-4a12-9f91-6afc83cf9257}</Project>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\util.hpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{1873e9a4-995b-4327-98ca-2524ee2d8030}</ProjectGuid>
<RootNamespace>Test</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>Demo</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
<IncludePath>$(ProjectDir)ext\glm;$(ProjectDir)inc;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\lib\x64;$(ProjectDir)bin\$(PlatformShortName)\$(Configuration);($(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)obj\$(Platform)\$(Configuration)\</IntDir>
<IncludePath>$(ProjectDir)ext\glm;$(ProjectDir)inc;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\lib\x64;$(ProjectDir)bin\$(PlatformShortName)\$(Configuration);($(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

30
Test.vcxproj.filters Normal file
View File

@@ -0,0 +1,30 @@
<?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;c++;cppm;ixx;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;h++;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>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\demo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="inc\util.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

4
Test.vcxproj.user Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
#include <glm/ext/matrix_float4x4.hpp>
#include <glm/glm.hpp>
#include <string>
#include "util.hpp"
struct Body {
@@ -11,11 +12,11 @@ struct Body {
uint vao;
uint vbo;
uint shader;
Array<float> verts;
Array<int> faces;
std::vector<float> verts;
std::vector<int> faces;
glm::vec4 color;
};
bool load_body(Body* out_body, const char* obj_filepath);
bool load_body(Body* out_body, std::string filepath);
void draw_body(const Body& b);
void create_new_sphere(Body* b, float scale=1.0f);

View File

@@ -1,5 +1,3 @@
#pragma once
#include "util.hpp"
bool parse_poses(Array<glm::mat2x3>* locs_out, const char* filepath);
bool parse_poses(std::vector<glm::mat2x3>* locs_out, const char* filepath);

10
inc/logger.hpp Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
#include <string>
void log(const char* msg);
void log(std::string msg);
void log(char*, int len);
void flush(const char* filepath);
void start_auto_flush_thread(const char* filepath, double period);
void start_auto_flush_thread();

180
inc/sync.hpp Normal file
View File

@@ -0,0 +1,180 @@
#pragma once
#ifdef _WIN32
#include "windows.h"
#endif
namespace sync {
#ifdef _WIN32
typedef CRITICAL_SECTION Mutex;
typedef CONDITION_VARIABLE ConditionVar;
typedef HANDLE Semaphore;
typedef HANDLE Thread;
typedef LARGE_INTEGER TimeSpan;
typedef DWORD (WINAPI *ThreadFunc)(_In_ LPVOID lpParameter);
typedef LPVOID ThreadArg;
const TimeSpan infinite_ts = LLONG_MAX;
static const LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
#endif
Thread make_thread(ThreadFunc t, ThreadArg a);
void join(Thread t);
Mutex make_mutex();
void lock(Mutex &m);
bool trylock(Mutex &m);
void unlock(Mutex &m);
void dispose(Mutex &m);
ConditionVar make_condition_var();
void wait(ConditionVar &c, Mutex &m, TimeSpan ts);
void wake_one(ConditionVar &c);
void wake_all(ConditionVar &c);
void dispose(ConditionVar &c);
Semaphore make_semaphore(int initial, int max);
void wait(Semaphore &s);
void post(Semaphore &s);
void dispose(Semaphore &s);
TimeSpan from_ms(double milliseconds);
TimeSpan from_s(double seconds);
TimeSpan from_min(double minutes);
TimeSpan from_hours(double hours);
TimeSpan now();
TimeSpan operator-(const TimeSpan &a, const TimeSpan &b);
double to_ms(TimeSpan &sp);
double to_s(TimeSpan &sp);
double to_min(TimeSpan &sp);
double to_hours(TimeSpan &sp);
#ifdef _WIN32
Thread make_thread(ThreadFunc f, ThreadArg a) {
DWORD tid;
return CreateThread(NULL, 0, f, a, 0, &tid);
}
void join(Thread t) {
WaitForSingleObject(t, infinite_ts);
}
Mutex make_mutex() {
Mutex m;
InitializeCriticalSection(&m);
return m;
}
void lock(Mutex &m) {
EnterCriticalSection(&m);
}
bool trylock(Mutex &m) {
return TryEnterCriticalSection(&m);
}
void unlock(Mutex &m) {
LeaveCriticalSection(&m);
}
void dispose(Mutex &m) {
DeleteCriticalSection(&m);
}
ConditionVar make_condition_var() {
ConditionVar c;
InitializeConditionVariable(&c);
return c;
}
void wait(ConditionVar &c, Mutex &m, TimeSpan ts) {
SleepConditionVariableCS(&c, &m, ts);
}
void wake_one(ConditionVar &c) {
WakeConditionVariable(&c);
}
void wake_all(ConditionVar &c) {
WakeAllConditionVariable(&c);
}
void dispose(ConditionVar &c) {
return; // Windows doesn't have a delete condition variable func
}
Semaphore make_semaphore(int initial, int max) {
return CreateSemaphoreA(NULL, (long)initial, (long)max, NULL);
}
void wait(Semaphore &s) {
WaitForSingleObject(s, infinite_ts);
}
void post(Semaphore &s) {
ReleaseSemaphore(s, 1, NULL);
}
void dispose(Semaphore &s) {
CloseHandle(s);
}
TimeSpan from_ms(double milliseconds) {
TimeSpan ts;
ts.QuadPart = static_cast<int64_t>(milliseconds/1000.0)*freq.QuadPart;
return ts;
}
TimeSpan from_s(double seconds) {
TimeSpan ts;
ts.QuadPart = static_cast<int64_t>(seconds)*freq.QuadPart;
return ts;
}
TimeSpan from_min(double minutes) {
TimeSpan ts;
ts.QuadPart = static_cast<int64_t>(minutes*60.0)*freq.QuadPart;
return ts;
}
TimeSpan from_hours(double hours) {
TimeSpan ts;
ts.QuadPart = static_cast<int64_t>(hours*60.0*60.0)*freq.QuadPart;
return ts;
}
TimeSpan now() {
TimeSpan ts;
QueryPerformanceCounter(&ts);
return ts;
}
TimeSpan operator-(const TimeSpan &a, TimeSpan &b) {
TimeSpan ts;
ts.QuadPart = a.QuadPart - b.QuadPart;
return ts;
}
double to_ms(TimeSpan &sp) {
return static_cast<double>(sp.QuadPart*1000)/static_cast<double>(freq.QuadPart);
}
double to_s(TimeSpan &sp) {
return static_cast<double>(sp.QuadPart)/static_cast<double>(freq.QuadPart);
}
double to_min(TimeSpan &sp) {
return static_cast<double>(sp.QuadPart)/static_cast<double>(freq.QuadPart*60);
}
double to_hours(TimeSpan &sp) {
return static_cast<double>(sp.QuadPart)/static_cast<double>(freq.QuadPart*60*60);
}
#endif
} // namespace sync

View File

@@ -2,30 +2,18 @@
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <fstream>
#include <sstream>
#include <glm/ext/matrix_float4x4.hpp>
#include <glm/ext/quaternion_float.hpp>
#include <glm/ext/vector_float4.hpp>
typedef unsigned int uint;
template<class T> struct Array {
T* data;
size_t len;
size_t cap;
inline T& operator[](int i) { return data[i]; }
};
template<class T> void append(Array<T>& a, T el);
template<class T> T pop(Array<T>& a);
template<class T> void resize(Array<T>& a, size_t new_cap);
template<class T> void clear(Array<T>& a);
bool read_file(Array<char>* out, const char* filepath);
Array<char*> split_str(const char* s, char delimiter);
Array<char*> split_str(const char* s);
bool read_file(std::string* s, const char* filepath);
std::vector<std::string> split_str(std::string s, char delim);
glm::mat4 quat_to_mat4(glm::quat q);
float randf();
template<class T> T lerp(T start, T end, float t) { return t * end + (1 - t) * start; }
template<class T> float ilerp(T start, T end, T pos) { return (pos - start) / (end - start); }
float randf(); // returns a float between 0 and 1
template<class T> float ilerp(T start, T end, T pos) { return (pos - start) / (end - start); }

BIN
lib/WS2_32.Lib (Stored with Git LFS)

Binary file not shown.

View File

@@ -1,9 +1,15 @@
#include <cassert>
#include <glad/glad.h>
#include <map>
#include <string>
#include <optional>
#include "util.hpp"
#include "body.hpp"
#include "shaders.hpp"
using namespace std;
enum class ParserState {
PREFIX,
VERTEX,
@@ -11,72 +17,29 @@ enum class ParserState {
FACE_SKIP,
};
static map<string, pair<vector<float>, vector<int>>> cache;
optional<pair<vector<float>, vector<int>>> _parse_obj(const char* obj_filepath);
bool load_body(Body* out_body, const char* obj_filepath) {
Array<char> source;
if (!read_file(&source, obj_filepath)) {
vector<float> verts;
vector<int> faces;
if (auto it = cache.find(obj_filepath); it != cache.end()) {
verts = it->second.first;
faces = it->second.second;
} else if (auto pair = _parse_obj(obj_filepath); pair.has_value()) {
verts = pair.value().first;
faces = pair.value().second;
cache[obj_filepath] = pair.value();
} else {
return false;
}
size_t num_verts = 0;
size_t num_faces = 0;
for (int i = 1; i < source.len; i++) {
if (source[i] == ' ' && source[i - 1] == 'v') {
num_verts++;
} else if (source[i] == ' ' && source[i - 1] == 'f') {
num_faces++;
}
}
Array<float> verts = { (float*)malloc(sizeof(float) * num_verts * 3), num_verts * 3 };
Array<int> faces = { (int*)malloc(sizeof(int) * num_faces * 3), num_faces*3 };
// Get ready for the parsing loop
ParserState state = ParserState::PREFIX;
int vert_i = 0;
int face_i = 0;
int start = 0;
for (int i = 1; i < source.len; i++) {
switch (state) {
case ParserState::PREFIX:
if (source[i - 1] == 'v' && source[i] == ' ') {
state = ParserState::VERTEX;
start = i + 1;
} else if (i > 0 && source[i - 1] == 'f' && source[i] == ' ') {
state = ParserState::FACE;
start = i + 1;
}
break;
case ParserState::VERTEX:
if (iswspace(source[i])) {
verts[vert_i] = atof(&source[start]);
vert_i++;
start = i + 1;
}
break;
case ParserState::FACE:
if (source[i] == '/') {
state = ParserState::FACE_SKIP;
faces[face_i] = atoi(&source[start]) - 1;
face_i++;
}
break;
case ParserState::FACE_SKIP:
if (iswspace(source[i])) {
state = ParserState::FACE;
start = i + 1;
}
}
if (source[i] == '\n' || source[i] == '\r') {
state = ParserState::PREFIX;
continue;
}
}
// Need a good validation check here. This is a stand in.
if (verts.len == 0 || faces.len == 0) {
if (verts.size() == 0 || faces.size() == 0) {
printf(
"Obj file appears incomplete or corrupted. Num verts %zu. Num Faces %zu.\n", verts.len, faces.len);
"Obj file appears incomplete or corrupted. Num verts %zu. Num Faces %zu.\n", verts.size(), faces.size());
return false;
}
@@ -92,10 +55,10 @@ bool load_body(Body* out_body, const char* obj_filepath) {
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, verts.len * sizeof(float), verts.data, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(float), &verts[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces.len * sizeof(int), faces.data, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces.size() * sizeof(int), &faces[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
@@ -116,10 +79,69 @@ void draw_body(const Body& b) {
set_uniform(b.shader, "global_t", glm::scale(b.pose, glm::vec3(b.scale)));
set_uniform(b.shader, "color", b.color);
glBindVertexArray(b.vao);
glDrawElements(GL_TRIANGLES, b.faces.len, GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, b.faces.size(), GL_UNSIGNED_INT, 0);
}
void create_new_sphere(Body* b, float scale) {
assert(load_body(b, "Icosphere.obj"));
b->scale = scale;
}
optional<pair<vector<float>, vector<int>>> _parse_obj(const char* obj_filepath) {
string source;
if (!read_file(&source, obj_filepath)) {
return {};
}
size_t num_verts = 0;
size_t num_faces = 0;
for (int i = 1; i < source.size(); i++) {
if (source[i] == ' ' && source[i - 1] == 'v') {
num_verts++;
} else if (source[i] == ' ' && source[i - 1] == 'f') {
num_faces++;
}
}
vector<float> verts;
vector<int> faces;
// Get ready for the parsing loop
ParserState state = ParserState::PREFIX;
int start = 0;
for (int i = 1; i < source.size(); i++) {
switch (state) {
case ParserState::PREFIX:
if (source[i - 1] == 'v' && source[i] == ' ') {
state = ParserState::VERTEX;
start = i + 1;
} else if (i > 0 && source[i - 1] == 'f' && source[i] == ' ') {
state = ParserState::FACE;
start = i + 1;
}
break;
case ParserState::VERTEX:
if (iswspace(source[i])) {
verts.push_back(atof(&source[start]));
start = i + 1;
}
break;
case ParserState::FACE:
if (source[i] == '/') {
state = ParserState::FACE_SKIP;
faces.push_back(atoi(&source[start]) - 1);
}
break;
case ParserState::FACE_SKIP:
if (iswspace(source[i])) {
state = ParserState::FACE;
start = i + 1;
}
}
if (source[i] == '\n' || source[i] == '\r') {
state = ParserState::PREFIX;
continue;
}
}
}

View File

@@ -1,62 +0,0 @@
#include <body.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <glm/glm.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/vector_float3.hpp>
#include <glm/matrix.hpp>
#include <util.hpp>
#include "camera_poses.hpp"
#define LINE_BUF_SIZE 256
#define NUM_SPHERES_PER_AXE 25
#define SPACE_PER_SPHERE 10.0f
bool parse_poses(Array<glm::mat2x3>* locs_out, const char* filepath) {
FILE* fp;
if (fopen_s(&fp, filepath, "rb")) {
printf("Error parsing %s\n", filepath);
return false;
}
char delim = ',';
char line[LINE_BUF_SIZE];
// because clang refuses to cooperate with my append implementation and generate the function code...
*locs_out = { (glm::mat2x3*)malloc(sizeof(glm::mat2x3) * 3 * NUM_SPHERES_PER_AXE * 14),
3 * NUM_SPHERES_PER_AXE * 14 };
// read in header
fgets(line, LINE_BUF_SIZE, fp);
fgets(line, LINE_BUF_SIZE, fp);
for (int camera_i = 0; !feof(fp); camera_i++) {
Array<char*> words = split_str(line, delim);
float x = atof(words[0]);
float y = atof(words[1]);
float z = atof(words[2]);
float w = atof(words[3]);
float i = atof(words[4]);
float j = atof(words[5]);
float k = atof(words[6]);
glm::mat4 pose = quat_to_mat4(glm::quat(w, i, j, k));
pose[3] = glm::vec4(x, y, z, 1);
// Generate axis spheres
for (int m = 0; m < 3; m++) {
for (int n = 0; n < NUM_SPHERES_PER_AXE; n++) {
glm::mat2x3 loc_color = glm::mat2x3(0.0);
loc_color[0][m] = n * SPACE_PER_SPHERE;
loc_color[0] = pose * glm::vec4(loc_color[0], 1);
loc_color[1] = glm::vec3(0);
loc_color[1][m] = 1.0f;
locs_out->data[camera_i*3*NUM_SPHERES_PER_AXE + m*NUM_SPHERES_PER_AXE + n] = loc_color;
}
}
fgets(line, LINE_BUF_SIZE, fp);
}
return true;
}

101
src/demo.cpp Normal file
View File

@@ -0,0 +1,101 @@
#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <glm/glm.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/vector_float3.hpp>
#include <glm/matrix.hpp>
#include "util.hpp"
#include "live_plotter.hpp"
#pragma comment(lib, "LivePlotter.lib")
using namespace std;
static map<string, pointid> name_to_id;
#define LINE_BUF_SIZE 256
#define NUM_SPHERES_PER_AXE 25
#define SPACE_PER_SPHERE 10.0f
bool parse_poses(std::vector<glm::mat2x3>& locs_out, const char* filepath) {
ifstream file(filepath);
if (!file.is_open()) {
return false;
}
string line;
getline(file, line);
while (getline(file, line)) {
std::vector<std::string> words = split_str(line, ',');
float x = stof(words[0]);
float y = stof(words[1]);
float z = stof(words[2]);
float w = stof(words[3]);
float i = stof(words[4]);
float j = stof(words[5]);
float k = stof(words[6]);
glm::mat4 pose = quat_to_mat4(glm::quat(w, i, j, k));
pose[3] = glm::vec4(x, y, z, 1);
// Generate axis spheres
for (int m = 0; m < 3; m++) {
for (int n = 0; n < NUM_SPHERES_PER_AXE; n++) {
glm::mat2x3 loc_color = glm::mat2x3(0.0);
loc_color[0][m] = n * SPACE_PER_SPHERE;
loc_color[0] = pose * glm::vec4(loc_color[0], 1);
loc_color[1] = glm::vec3(0);
loc_color[1][m] = 1.0f;
locs_out.push_back(loc_color);
}
}
}
return true;
}
int main() {
vector<glm::mat2x3> camera_pose_axes;
if (!parse_poses(camera_pose_axes, "poses.csv")) {
return -1;
}
start(800, 800);
while (true)
;
//for (int i = 0; i < camera_pose_axes.size(); i++) {
// glm::vec3 p = camera_pose_axes[i][0];
// glm::vec3 color = camera_pose_axes[i][1];
// pointid id = create_point(p.x, p.y, p.z);
// set_color(id, color.x, color.y, color.z);
// set_scale(id, 10);
//}
//while (true) {
// string line;
// getline(cin, line);
// vector<string> words = split_str(line, ' ');
// if (!words.size() == 4)
// return NULL;
// printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
// string name = words[0];
// float x = stof(words[1]);
// float y = stof(words[2]);
// float z = stof(words[3]);
// if (auto it = name_to_id.find(name); it != name_to_id.end()) {
// update_point(it->second, x, y, z);
// } else {
// name_to_id[name] = create_point(x, y, z);
// set_lifetime(name_to_id[name], 0.2);
// set_scale(name_to_id[name], 15);
// }
//}
}

View File

@@ -20,6 +20,7 @@
#include <winnt.h>
#include <algorithm>
#include "sync.hpp"
#include "util.hpp"
#include "shaders.hpp"
#include "body.hpp"
@@ -29,6 +30,8 @@
#define LERP_MOVE_PERIOD_S 0.05
#define STOP_WAIT_TIME_MS 500
using namespace sync;
struct Point {
bool initialized;
glm::vec3 startloc;
@@ -44,10 +47,9 @@ static double prev_cursor_x, prev_cursor_y;
static bool mouse_pressed, scroll_pressed, stop_flag, running;
static Camera camera;
static Viewport viewport;
static Thread t;
static Mutex m;
static uint shader;
static CRITICAL_SECTION cs;
static HANDLE win_thread_h;
static DWORD win_thread_id;
static LARGE_INTEGER fr;
static pointid next_id = 0;
static std::map<uint, Point*> id_to_point; // Use a pool allocator possibly later
@@ -68,14 +70,13 @@ void _refresh_win();
double _time();
extern DllExport bool __cdecl start(int win_w, int win_h) {
if (!InitializeCriticalSectionAndSpinCount(&cs, 0x00000400))
return false;
if (running) {
printf("Already running! Call stop before calling stop again\n");
return false;
}
m = make_mutex();
if (!QueryPerformanceFrequency(&fr)) {
printf("Failed to get the performance counter frequency.\n");
return false;
@@ -84,9 +85,9 @@ extern DllExport bool __cdecl start(int win_w, int win_h) {
glm::vec2* winsize = (glm::vec2*)malloc(sizeof(glm::vec2));
*winsize = glm::vec2(win_w, win_h);
stop_flag = false;
win_thread_h = CreateThread(NULL, 0, _win_thread, winsize, 0, &win_thread_id);
t = make_thread(_win_thread, winsize);
running = win_thread_h != NULL;
running = t != NULL;
if (!running)
printf("Error while creating the live plotter window thread.\n");
return running;
@@ -94,18 +95,17 @@ extern DllExport bool __cdecl start(int win_w, int win_h) {
extern DllExport bool __cdecl stop() {
stop_flag = true;
DWORD res = WaitForSingleObject(win_thread_h, STOP_WAIT_TIME_MS);
DWORD res = WaitForSingleObject(t, STOP_WAIT_TIME_MS);
bool success = res == WAIT_OBJECT_0;
running = !success; // Consider the app still running if we didn't shut down properly...?
// TODO: Please wrap away win api synch stuff. thank you
if (!running) DeleteCriticalSection(&cs);
if (!running) dispose(m);
return success;
}
extern DllExport pointid __cdecl create_point(float x, float y, float z) {
EnterCriticalSection(&cs);
lock(m);
Point* p = (Point*)malloc(sizeof(Point));
*p = {
.initialized = false,
@@ -120,48 +120,48 @@ extern DllExport pointid __cdecl create_point(float x, float y, float z) {
pointid id = next_id++;
id_to_point[id] = p;
point_to_id[p] = id;
LeaveCriticalSection(&cs);
unlock(m);
return id;
}
extern DllExport void __cdecl set_color(pointid id, float r, float g, float b) {
EnterCriticalSection(&cs);
lock(m);
Point* p = id_to_point[id];
p->b.color = { r, g, b, p->b.color[3] };
LeaveCriticalSection(&cs);
unlock(m);
}
extern DllExport void __cdecl set_scale(pointid id, float scale) {
EnterCriticalSection(&cs);
lock(m);
Point* p = id_to_point[id];
p->b.scale = scale;
LeaveCriticalSection(&cs);
unlock(m);
}
extern DllExport void __cdecl update_point(pointid id, float x, float y, float z) {
EnterCriticalSection(&cs);
lock(m);
Point* p = id_to_point[id];
p->targetloc = { x, y, z };
p->startloc = p->b.pose[3];
p->start_s = _time();
LeaveCriticalSection(&cs);
unlock(m);
}
extern DllExport void __cdecl set_lifetime(pointid id, float new_lifetime_s) {
EnterCriticalSection(&cs);
lock(m);
Point* p = id_to_point[id];
p->start_s = _time();
p->lifetime_s = new_lifetime_s;
LeaveCriticalSection(&cs);
unlock(m);
}
extern DllExport void __cdecl clear_point(pointid id) {
EnterCriticalSection(&cs);
lock(m);
Point* p = id_to_point[id];
id_to_point.erase(id);
point_to_id.erase(p);
free(p);
LeaveCriticalSection(&cs);
unlock(m);
}
void _resize_cb(GLFWwindow* win, int w, int h) {
@@ -254,7 +254,7 @@ void _refresh_win() {
set_uniform(shader, "camera_t", world_to_camera(camera));
set_uniform(shader, "projection_t", camera_to_projection(viewport));
if (TryEnterCriticalSection(&cs)) {
if (trylock(m)) {
for (const auto& [id, p] : id_to_point) {
// Initialize if not done so yet
if (!p->initialized) {
@@ -276,7 +276,7 @@ void _refresh_win() {
p->b.pose[3] = glm::vec4(lerp(p->startloc, p->targetloc, t), 1);
draw_body(p->b);
}
LeaveCriticalSection(&cs);
unlock(m);
}
glfwSwapBuffers(win);
glfwPollEvents();

11
src/logger.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include "sync.hpp"
#include "logger.hpp"
static Mutex m;
static Thread t;
static std::vector<string> backlog;
void log(const char* msg) {
}

View File

@@ -1,46 +0,0 @@
//#include <iostream>
//#include <string>
//#include <map>
//
//#include "camera_poses.hpp"
//#include "live_plotter.hpp"
//
//static std::map<std::string, pointid> name_to_id;
//
//int main() {
// Array<glm::mat2x3> camera_pose_axes = { NULL, 0 };
// if (!parse_poses(&camera_pose_axes, "poses.csv")) {
// return -1;
// }
//
// start(800, 800);
//
// for (int i = 0; i < camera_pose_axes.len; i++) {
// glm::vec3 p = camera_pose_axes[i][0];
// glm::vec3 color = camera_pose_axes[i][1];
// pointid id = create_point(p.x, p.y, p.z);
// set_color(id, color.x, color.y, color.z);
// set_scale(id, 10);
// }
//
// while (true) {
// std::string line;
// std::getline(std::cin, line);
// Array<char*> words = split_str(line.c_str());
// if (!words.len == 4)
// return NULL;
// printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
// std::string name = std::string(words[0]);
// float x = atof(words[1]);
// float y = atof(words[2]);
// float z = atof(words[3]);
//
// if (auto it = name_to_id.find(name); it != name_to_id.end()) {
// update_point(it->second, x, y, z);
// } else {
// name_to_id[name] = create_point(x, y, z);
// set_lifetime(name_to_id[name], 0.2);
// set_scale(name_to_id[name], 15);
// }
// }
//}

View File

@@ -68,23 +68,22 @@ void set_uniform(uint id, const char* name, uniform_variant value) {
}
bool _compile_shader(uint *out_id, const char* filepath, int shader_type) {
Array<char> source;
std::string source;
if (!read_file(&source, filepath))
return false;
uint id = glCreateShader(shader_type);
glShaderSource(id, 1, &source.data, (int*)&source.len);
int sz = source.size();
const char* data = source.c_str();
glShaderSource(id, 1, &data, &sz);
glCompileShader(id);
free(source.data);
int status;
glGetShaderiv(id, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE) {
char err_msg[MAX_ERR_MSG_LEN];
glGetShaderInfoLog(id, MAX_ERR_MSG_LEN, NULL, err_msg);
printf("Error compiling shader %s\n", filepath);
printf("%.*s\n", (int)source.len, source.data);
printf("Error msg: %s\n", err_msg);
}
*out_id = id;

View File

@@ -1,94 +1,25 @@
#include <cstdio>
#include <assert.h>
#include <cstring>
#include <cwctype>
#include <stdlib.h>
#include <glm/ext/quaternion_float.hpp>
#include <glm/mat4x4.hpp>
#include <string>
#include <fstream>
#include <sstream>
#include "util.hpp"
#include "body.hpp"
Array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws);
using namespace std;
template<class T> void append(Array<T>& a, T el) {
if (a.len == a.cap) {
resize(a, std::max((size_t)8, a.cap * 2));
}
a[a.len] = el;
a.len++;
}
template<class T> T pop(Array<T>& a) {
assert(a.len >= 1);
a.len--;
return a.data[a.len + 1];
}
template<class T> void resize(Array<T>& a, size_t new_cap) {
T* new_data = (T*)malloc(sizeof(T) * new_cap);
if (a.len > 0) {
memcpy(new_data, a.data, std::min(a.len, new_cap));
}
free(a.data);
a.data = new_data;
a.len = std::min(a.len, new_cap);
a.cap = new_cap;
}
template<class T> void clear(Array<T>& a) {
a.len = 0;
}
bool read_file(Array<char>* out, const char* filepath) {
FILE* fp = NULL;
if (fopen_s(&fp, filepath, "rb") != 0) {
printf("ERROR Failed to open file %s\n", filepath);
bool read_file(string* s, const char* filepath) {
ifstream file(filepath);
if (!file.is_open()) {
return false;
}
fseek(fp, 0L, SEEK_END);
size_t sz = ftell(fp);
fseek(fp, 0, SEEK_SET);
char* data = (char*)malloc(sizeof(char) * sz);
fread(data, sizeof(char), sz, fp);
fclose(fp);
out->data = data;
out->len = sz;
return true;
*s = { istreambuf_iterator<char>(file), istreambuf_iterator<char>() };
}
Array<char*> split_str(const char* s, char delimiter) { return _split_str_inner(s, delimiter, false); }
Array<char*> split_str(const char* s) { return _split_str_inner(s, ' ', true); }
Array<char*> _split_str_inner(const char* s, char delim, bool just_check_ws) {
Array<char*> res = { NULL, 0, 0 };
char c;
int i = 0;
Array<char> cur_word = { NULL, 0, 0 };
while (true) {
c = s[i++];
bool is_delim = just_check_ws ? iswspace(c) : c == delim;
if ((is_delim || c == '\0') && cur_word.len > 0) {
char* word = (char*)malloc(sizeof(char) * cur_word.len + 1);
memcpy(word, cur_word.data, cur_word.len);
word[cur_word.len] = '\0';
append(res, word);
clear(cur_word);
if (c == '\0') {
break;
}
continue;
} else {
append(cur_word, c);
}
if (c == '\0') {
break;
}
vector<string> split_str(string s, char delim) {
vector<string> res;
string cur_word;
istringstream ss(s);
while (getline(ss, cur_word, delim)) {
res.push_back(cur_word);
}
return res;
}
@@ -109,6 +40,4 @@ glm::mat4 quat_to_mat4(glm::quat q) {
return glm::mat4(col0, col1, col2, col3);
}
float randf() {
return (float)rand() / (float)RAND_MAX;
}
float randf() { return (float)rand() / (float)RAND_MAX; }