Working on collisions
This commit is contained in:
parent
8f3533405a
commit
58f9176dfc
@ -1,6 +1,7 @@
|
||||
math_3d_floor_collision_work false
|
||||
vid_2d_background false
|
||||
vid_3d_renderer true
|
||||
vid_3d_grid false
|
||||
vid_3d_cull_sky false
|
||||
vid_3d_cull_clips true
|
||||
vid_3d_cull_triggers true
|
||||
vid_3d_cull_triggers true
|
||||
|
41
mpfw/MPFW_Backend_raylib.cpp
Normal file
41
mpfw/MPFW_Backend_raylib.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "MPFW_Backend_raylib.h"
|
||||
#include <raylib.h>
|
||||
#include <vector>
|
||||
std::vector<Font> _fonts_RL;
|
||||
|
||||
void BackEnd_Raylib::Create(MPFW::Backends::Video::ContextParameters param)
|
||||
{
|
||||
InitWindow(param.width, param.height, param.name.c_str());
|
||||
SetTargetFPS(param.desiredFps);
|
||||
}
|
||||
|
||||
int BackEnd_Raylib::BE_LoadFont(std::string path)
|
||||
{
|
||||
_fonts_RL.push_back(LoadFontEx(path.c_str(), 360, 0, 4000));
|
||||
return _fonts_RL.size() - 1;
|
||||
}
|
||||
|
||||
void BackEnd_Raylib::BE_DrawText(int fontId, std::string text, int x, int y, int fontSize)
|
||||
{
|
||||
DrawTextEx(_fonts_RL[fontId], text.c_str(), { (float)x,(float)y }, fontSize, 0, WHITE);
|
||||
}
|
||||
|
||||
int BackEnd_Raylib::BE_LoadTexture(MPFW::Backends::Video::Agnostic::Picture pic)
|
||||
{
|
||||
Image i;
|
||||
i.data = malloc(pic.width * pic.height * 4);
|
||||
i.width = pic.width;
|
||||
i.height = pic.height;
|
||||
std::memcpy(i.data, pic.data.data(), pic.data.size()*4);
|
||||
i.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
|
||||
Texture t = LoadTextureFromImage(i);
|
||||
|
||||
free(i.data);
|
||||
|
||||
return t.id;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
22
mpfw/MPFW_Backend_raylib.h
Normal file
22
mpfw/MPFW_Backend_raylib.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "MPFW_BackendDefinition.h"
|
||||
|
||||
|
||||
class BackEnd_Raylib : public MPFW::Backends::Video::BackEnd {
|
||||
public:
|
||||
void Create(MPFW::Backends::Video::ContextParameters param);
|
||||
|
||||
int BE_LoadFont(std::string path);
|
||||
void BE_DrawText(int fontId, std::string text, int x, int y, int fontSize);
|
||||
|
||||
int BE_LoadTexture(MPFW::Backends::Video::Agnostic::Picture pic);
|
||||
void BE_UnloadTexture(int picId);
|
||||
void BE_DrawColorTriangle(MPFW::Backends::Video::Agnostic::Triangle tri, MPFW::Backends::Video::Agnostic::Color col);
|
||||
void BE_DrawTexturedTriangle(MPFW::Backends::Video::Agnostic::TexturedTriangle tri);
|
||||
|
||||
void BE_ImGui_Begin();
|
||||
void BE_ImGui_End();
|
||||
|
||||
void BE_StartFrame();
|
||||
void BE_EndFrame();
|
||||
};
|
@ -431,6 +431,17 @@ void MPFW::Quake::Maps::MapFile::LoadBSPMap(std::string path)
|
||||
|
||||
}
|
||||
|
||||
data.planes.clear();
|
||||
data.planes.resize(data.header.planes.size / sizeof(Plane));
|
||||
|
||||
std::memcpy(
|
||||
data.planes.data(),
|
||||
Utils::Strings::IterativeStringExcerpt(buffer, data.header.planes.offset, data.header.planes.size).data(),
|
||||
data.header.planes.size
|
||||
);
|
||||
|
||||
|
||||
|
||||
ds = Debug::DONE;
|
||||
|
||||
|
||||
|
@ -112,6 +112,12 @@ namespace MPFW {
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct Plane {
|
||||
Vector3 normal;
|
||||
float dist;
|
||||
long type;
|
||||
};
|
||||
|
||||
struct cMipHeader {
|
||||
long numtex;
|
||||
@ -176,7 +182,7 @@ namespace MPFW {
|
||||
std::vector<int> ledges;
|
||||
std::vector<rlMipTex> textures;
|
||||
|
||||
|
||||
std::vector<Plane> planes;
|
||||
|
||||
std::vector<CalculatedFace> renderFaces;
|
||||
|
||||
|
116
mpfw/main.cpp
116
mpfw/main.cpp
@ -11,6 +11,8 @@
|
||||
#include <rlgl.h>
|
||||
#include <thread>
|
||||
#include "MPFW_UI.h"
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
|
||||
// turn quake miptex into rl texture
|
||||
Texture2D RLMT_QUAKE(MPFW::Quake::Maps::rlMipTex rlmt) {
|
||||
@ -47,7 +49,47 @@ void Look() {
|
||||
}
|
||||
|
||||
|
||||
BoundingBox GenerateTriangleBoundingBox(Vector3 a, Vector3 b, Vector3 c) {
|
||||
BoundingBox retval;
|
||||
retval.min = {
|
||||
a.x < b.x && a.x < c.x ? a.x :
|
||||
b.x < a.x && b.x < c.x ? b.x : c.x,
|
||||
|
||||
a.y < b.y && a.y < c.y ? a.y :
|
||||
b.y < a.y && b.y < c.y ? b.y : c.y,
|
||||
|
||||
a.z < b.z && a.z < c.z ? a.z :
|
||||
b.z < a.z && b.z < c.z ? b.z : c.z
|
||||
};
|
||||
|
||||
|
||||
retval.max = {
|
||||
a.x > b.x && a.x > c.x ? a.x :
|
||||
b.x > a.x && b.x > c.x ? b.x : c.x,
|
||||
|
||||
a.y > b.y && a.y > c.y ? a.y :
|
||||
b.y > a.y && b.y > c.y ? b.y : c.y,
|
||||
|
||||
a.z > b.z && a.z > c.z ? a.z :
|
||||
b.z > a.z && b.z > c.z ? b.z : c.z
|
||||
};
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
BoundingBox GenerateBoundingBoxPolygon(std::vector<Vector3> poly) {
|
||||
std::vector<Vector3> polyCopy = poly;
|
||||
|
||||
std::sort(polyCopy.begin(), polyCopy.end(), [](Vector3 a, Vector3 b) {
|
||||
return Vector3Distance({ 0,0,0 }, a) < Vector3Distance({ 0,0,0 }, b);
|
||||
});
|
||||
|
||||
BoundingBox retval;
|
||||
retval.min = polyCopy[0];
|
||||
retval.max = polyCopy[polyCopy.size() - 1];
|
||||
return retval;
|
||||
}
|
||||
|
||||
// because quake can't normalize vectors like a civilized piece of software
|
||||
|
||||
@ -66,7 +108,7 @@ qNVec qNormalize(Vector3 v) {
|
||||
Vector3 wishDir = { 0,0,0 };
|
||||
double wishSpeed;
|
||||
|
||||
|
||||
float collisionFloor = 5;
|
||||
void Accelerate() {
|
||||
|
||||
double addSpeed, accelSpeed, currentSpeed;
|
||||
@ -106,6 +148,20 @@ void ___test___(T a, T b) {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool consoleOn = false;
|
||||
bool waitingForFrameToFinish = false;
|
||||
bool physicsThreadShouldDie = false;
|
||||
void PhysicsThread(MPFW::Console::CommandHandlerResources* chr) {
|
||||
float ctime = GetTime();
|
||||
while(!physicsThreadShouldDie){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
@ -141,7 +197,7 @@ int main() {
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
|
||||
InitWindow(1280, 720, TextFormat("mpfw"));
|
||||
SetTargetFPS(60);
|
||||
// SetTargetFPS(60);
|
||||
SetExitKey(0);
|
||||
DisableCursor();
|
||||
|
||||
@ -160,6 +216,7 @@ int main() {
|
||||
cmdH.RunScript("data/cfg/startup.cfg");
|
||||
|
||||
uiRenderer.cmh = &cmdH;
|
||||
|
||||
|
||||
|
||||
// MPFW::UI::Window wndw("data/menus/test.wnd");
|
||||
@ -175,11 +232,13 @@ int main() {
|
||||
|
||||
bool indivFaceMode = false;
|
||||
int indivFace = 0;
|
||||
bool consoleOn = false;
|
||||
std::string cmdBuf = "";
|
||||
int framebuffer = 0;
|
||||
std::thread physics(PhysicsThread, &chr);
|
||||
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
|
||||
|
||||
|
||||
if (framebuffer < 5 && !uiRenderer.showCursorOnLaunch) {
|
||||
|
||||
@ -190,7 +249,23 @@ int main() {
|
||||
if (IsKeyPressed(KEY_APOSTROPHE)) {
|
||||
consoleOn = !consoleOn;
|
||||
}
|
||||
if(!consoleOn && IsCursorHidden()){
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_ESCAPE) && !chr.gameDisabled) {
|
||||
if (IsCursorHidden()) {
|
||||
EnableCursor();
|
||||
uiRenderer.rendererIsActive = true;
|
||||
}
|
||||
else {
|
||||
DisableCursor();
|
||||
uiRenderer.rendererIsActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
if(IsCursorHidden() && !consoleOn){
|
||||
Look();
|
||||
Vector3 wishVel = { 0,0,0 };
|
||||
wishSpeed = 320;
|
||||
@ -212,11 +287,12 @@ int main() {
|
||||
wishVel = Vector3Multiply(Vector3Normalize(wishVel), { 320, 320, 320 });
|
||||
|
||||
wishDir = Vector3Normalize(wishVel);
|
||||
if (camera.position.y <= 5) {
|
||||
camera.position.y = 5;
|
||||
|
||||
if (camera.position.y <= collisionFloor) {
|
||||
camera.position.y = collisionFloor;
|
||||
velocity.y = 0;
|
||||
if(IsKeyPressed(KEY_SPACE)){
|
||||
velocity.y += wishSpeed*0.5*GetFrameTime();
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
velocity.y += wishSpeed * 0.5 * GetFrameTime();
|
||||
}
|
||||
Accelerate();
|
||||
|
||||
@ -225,32 +301,22 @@ int main() {
|
||||
AirAccelerate(wishVel);
|
||||
velocity.y -= 10 * GetFrameTime();
|
||||
}
|
||||
if (IsKeyPressed(KEY_LEFT) && indivFace > 0) indivFace--;
|
||||
if (IsKeyPressed(KEY_RIGHT) && indivFace < map.data.faces.size() - 1) indivFace++;
|
||||
if (IsKeyPressed(KEY_F)) indivFaceMode = !indivFaceMode;
|
||||
|
||||
|
||||
velocity *= {GetFrameTime(), 1, GetFrameTime()};
|
||||
camera.position += velocity;
|
||||
camera.target = camera.position + rotation;
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_ESCAPE) && !chr.gameDisabled) {
|
||||
if (IsCursorHidden()) {
|
||||
EnableCursor();
|
||||
uiRenderer.rendererIsActive = true;
|
||||
}
|
||||
else {
|
||||
DisableCursor();
|
||||
uiRenderer.rendererIsActive = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
if (chr.cvars["vid_2d_background"] == "true") DrawRectangleGradientV(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE, LIGHTGRAY);
|
||||
|
||||
if (chr.cvars["vid_3d_renderer"] == "true") {
|
||||
|
||||
BeginMode3D(camera);
|
||||
if(chr.cvars["vid_3d_grid"] == "true") DrawGrid(10000, 10);
|
||||
for (int i = 0; i < map.data.renderFaces.size(); i++) {
|
||||
@ -321,6 +387,8 @@ int main() {
|
||||
uiRenderer.Render();
|
||||
EndDrawing();
|
||||
}
|
||||
physicsThreadShouldDie = true;
|
||||
physics.join();
|
||||
|
||||
CloseWindow();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?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">
|
||||
@ -145,6 +145,7 @@
|
||||
<ClCompile Include="..\deps\include\pugixml.cpp" />
|
||||
<ClCompile Include="..\deps\include\rlImGui.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="MPFW_Backend_raylib.cpp" />
|
||||
<ClCompile Include="MPFW_Console.cpp" />
|
||||
<ClCompile Include="MPFW_HL.cpp" />
|
||||
<ClCompile Include="MPFW_Net.cpp" />
|
||||
@ -153,6 +154,8 @@
|
||||
<ClCompile Include="MPFW_Utils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MPFW_BackendDefinition.h" />
|
||||
<ClInclude Include="MPFW_Backend_raylib.h" />
|
||||
<ClInclude Include="MPFW_Console.h" />
|
||||
<ClInclude Include="MPFW_HL.h" />
|
||||
<ClInclude Include="MPFW_MPFWMF.h" />
|
||||
|
@ -16,6 +16,9 @@
|
||||
<Filter Include="ext.">
|
||||
<UniqueIdentifier>{4f8f0e99-b4e5-46ed-8593-5de637bd7032}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Backends">
|
||||
<UniqueIdentifier>{563323f5-04e3-405d-9047-db638c5bf1fd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
@ -60,6 +63,9 @@
|
||||
<ClCompile Include="MPFW_Net.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MPFW_Backend_raylib.cpp">
|
||||
<Filter>Backends</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MPFW_HL.h">
|
||||
@ -83,5 +89,11 @@
|
||||
<ClInclude Include="MPFW_Net.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MPFW_BackendDefinition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MPFW_Backend_raylib.h">
|
||||
<Filter>Backends</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user