mirror of
https://github.com/allankoechke/raylib-cpp.git
synced 2026-11-30 10:59:00 +00:00
Update to raylib 4.2
This commit is contained in:
@@ -15,7 +15,7 @@ if (NOT raylib_FOUND)
|
||||
FetchContent_Declare(
|
||||
raylib
|
||||
GIT_REPOSITORY https://github.com/raysan5/raylib.git
|
||||
GIT_TAG 1f806b555dd1ecb7e77797ed0de57d62a6bdd6f0
|
||||
GIT_TAG 4.2.0
|
||||
)
|
||||
FetchContent_GetProperties(raylib)
|
||||
if (NOT raylib_POPULATED) # Have we downloaded raylib yet?
|
||||
|
||||
@@ -30,7 +30,7 @@ int main() {
|
||||
while (!window.ShouldClose()) { // Detect window close button or ESC key
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
droppedFiles = raylib::GetDroppedFiles();
|
||||
droppedFiles = raylib::LoadDroppedFiles();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
||||
2142
examples/physics/physac.h
Normal file
2142
examples/physics/physac.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,6 +19,7 @@
|
||||
|
||||
#define PHYSAC_IMPLEMENTATION
|
||||
#define PHYSAC_NO_THREADS
|
||||
#include "physac.h"
|
||||
#include "Physics.hpp"
|
||||
|
||||
int main(void)
|
||||
@@ -55,7 +56,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// Delay initialization of variables due to physics reset async
|
||||
physics.Update();
|
||||
physics.RunStep();
|
||||
|
||||
if (needsReset)
|
||||
{
|
||||
@@ -68,13 +69,6 @@ int main(void)
|
||||
needsReset = false;
|
||||
}
|
||||
|
||||
// Reset physics input
|
||||
if (IsKeyPressed('R'))
|
||||
{
|
||||
physics.Reset();
|
||||
needsReset = true;
|
||||
}
|
||||
|
||||
// Physics body creation inputs
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) physics.CreateBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10);
|
||||
else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) physics.CreateBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10);
|
||||
@@ -121,7 +115,6 @@ int main(void)
|
||||
|
||||
raylib::DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE);
|
||||
raylib::DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE);
|
||||
raylib::DrawText("Press 'R' to reset example", 10, 40, 10, WHITE);
|
||||
|
||||
raylib::DrawText("Physac", logoX, logoY, 30, WHITE);
|
||||
raylib::DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE);
|
||||
|
||||
@@ -74,7 +74,7 @@ int main(void)
|
||||
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
|
||||
|
||||
// Load a dropped TTF file dynamically (at current fontSize)
|
||||
for (const auto& file : raylib::GetDroppedFiles()) {
|
||||
for (const auto& file : raylib::LoadDroppedFiles()) {
|
||||
if (raylib::IsFileExtension(file, ".ttf")) {
|
||||
msg.font = font = raylib::Font(file, font.GetBaseSize());
|
||||
}
|
||||
|
||||
@@ -152,11 +152,10 @@ RLCPPAPI inline std::string GetWorkingDirectory() {
|
||||
* Get filenames in a directory path
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
RLCPPAPI std::vector<std::string> GetDirectoryFiles(const std::string& dirPath) {
|
||||
int count;
|
||||
char** files = ::GetDirectoryFiles(dirPath.c_str(), &count);
|
||||
std::vector<std::string> output(files, files + count);
|
||||
::ClearDirectoryFiles();
|
||||
RLCPPAPI std::vector<std::string> LoadDirectoryFiles(const std::string& dirPath) {
|
||||
FilePathList files = ::LoadDirectoryFiles(dirPath.c_str());
|
||||
std::vector<std::string> output(files.paths, files.paths + files.count);
|
||||
::UnloadDirectoryFiles(files);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -171,14 +170,13 @@ RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
|
||||
* Get dropped files names
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
RLCPPAPI std::vector<std::string> GetDroppedFiles() {
|
||||
RLCPPAPI std::vector<std::string> LoadDroppedFiles() {
|
||||
if (!::IsFileDropped()) {
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
int count;
|
||||
char** files = ::GetDroppedFiles(&count);
|
||||
std::vector<std::string> output(files, files + count);
|
||||
::ClearDroppedFiles();
|
||||
FilePathList files = ::LoadDroppedFiles();
|
||||
std::vector<std::string> output(files.paths, files.paths + files.count);
|
||||
::UnloadDroppedFiles(files);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,14 +260,6 @@ class Mesh : public ::Mesh {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute mesh binormals (aka bitangent)
|
||||
*/
|
||||
inline Mesh& GenBinormals() {
|
||||
::GenMeshBinormals(this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load model from generated mesh
|
||||
*/
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
#define RAYLIB_CPP_INCLUDE_PHYSICS_HPP_
|
||||
|
||||
#include "./raylib.hpp"
|
||||
#include "./physac.hpp"
|
||||
#include "./Vector2.hpp"
|
||||
|
||||
namespace raylib {
|
||||
/**
|
||||
* 2D Physics library for videogames
|
||||
*
|
||||
* This requires you to deploy your own version of physac.h over at:
|
||||
* https://github.com/victorfisac/Physac
|
||||
*
|
||||
* @see https://github.com/victorfisac/Physac
|
||||
*/
|
||||
class Physics {
|
||||
public:
|
||||
@@ -34,18 +38,8 @@ class Physics {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& Update() {
|
||||
::UpdatePhysics();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& Reset() {
|
||||
::ResetPhysics();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& Close() {
|
||||
::ClosePhysics();
|
||||
inline Physics& RunStep() {
|
||||
::RunPhysicsStep();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -54,6 +48,10 @@ class Physics {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool IsEnabled() {
|
||||
return ::IsPhysicsEnabled();
|
||||
}
|
||||
|
||||
inline Physics& SetGravity(float x, float y) {
|
||||
::SetPhysicsGravity(x, y);
|
||||
return *this;
|
||||
@@ -71,11 +69,6 @@ class Physics {
|
||||
return ::CreatePhysicsBodyPolygon(pos, radius, sides, density);
|
||||
}
|
||||
|
||||
inline Physics& DestroyBody(PhysicsBody body) {
|
||||
::DestroyPhysicsBody(body);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& AddForce(PhysicsBody body, Vector2 force) {
|
||||
::PhysicsAddForce(body, force);
|
||||
return *this;
|
||||
@@ -91,11 +84,6 @@ class Physics {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& SetBodyRotation(PhysicsBody body, float radians) {
|
||||
::SetPhysicsBodyRotation(body, radians);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int GetBodiesCount() const {
|
||||
return ::GetPhysicsBodiesCount();
|
||||
}
|
||||
@@ -115,6 +103,26 @@ class Physics {
|
||||
inline Vector2 GetShapeVertex(PhysicsBody body, int vertex) const {
|
||||
return ::GetPhysicsShapeVertex(body, vertex);
|
||||
}
|
||||
|
||||
inline Physics& GetBodyRotation(PhysicsBody body, float radians) {
|
||||
::SetPhysicsBodyRotation(body, radians);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& SetBodyRotation(PhysicsBody body, float radians) {
|
||||
::SetPhysicsBodyRotation(body, radians);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& DestroyBody(PhysicsBody body) {
|
||||
::DestroyPhysicsBody(body);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Physics& Close() {
|
||||
::ClosePhysics();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
} // namespace raylib
|
||||
using RPhysics = raylib::Physics;
|
||||
|
||||
@@ -33,13 +33,6 @@ class RayCollision : public ::RayCollision {
|
||||
set(::GetRayCollisionMesh(ray, mesh, transform));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get collision info between ray and model
|
||||
*/
|
||||
RayCollision(const ::Ray& ray, const ::Model& model) {
|
||||
set(::GetRayCollisionModel(ray, model));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get collision info between ray and quad
|
||||
*/
|
||||
|
||||
@@ -33,8 +33,8 @@ class Sound : public ::Sound {
|
||||
Sound(Sound&& other) {
|
||||
set(other);
|
||||
|
||||
other.stream = { 0, 0, 0, 0, 0 };
|
||||
other.frameCount = 0;
|
||||
other.stream = { 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* C++ header to wrap physac.h.
|
||||
*/
|
||||
#ifndef RAYLIB_CPP_INCLUDE_PHYSAC_HPP_
|
||||
#define RAYLIB_CPP_INCLUDE_PHYSAC_HPP_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "extras/physac.h" // NOLINT
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // RAYLIB_CPP_INCLUDE_PHYSAC_HPP_
|
||||
@@ -8,7 +8,7 @@ if (NOT raylib_FOUND)
|
||||
FetchContent_Declare(
|
||||
raylib
|
||||
GIT_REPOSITORY https://github.com/raysan5/raylib.git
|
||||
GIT_TAG 4.0.0
|
||||
GIT_TAG 4.2.0
|
||||
)
|
||||
FetchContent_MakeAvailable(raylib)
|
||||
endif()
|
||||
|
||||
@@ -67,9 +67,9 @@ int main(int argc, char *argv[]) {
|
||||
AssertEqual(image.GetHeight(), 50);
|
||||
}
|
||||
|
||||
// raylib::GetDirectoryFiles()
|
||||
// raylib::LoadDirectoryFiles()
|
||||
{
|
||||
std::vector<std::string> files = raylib::GetDirectoryFiles(::GetWorkingDirectory());
|
||||
std::vector<std::string> files = raylib::LoadDirectoryFiles(::GetWorkingDirectory());
|
||||
Assert(files.size() > 3);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user