Standardizing function declarations

This commit is contained in:
Rob Loach
2022-01-08 23:11:47 -05:00
parent d3a0b5427b
commit 0cec4eb475
14 changed files with 116 additions and 38 deletions

View File

@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [4.0.3] - Unreleased
### Changed
- CMake now used for raylib dependency, rather than git submodules
- Standardized functions across:
- Color
- Material
- Mesh
- Model
- ModelAnimation
- Physics
- Ray
- Rectangle
- Texture
- Window
## [4.0.2] - 2021-12-24
### Added
- `Image::IsLoaded()`

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project (raylib-cpp
VERSION 4.0.2
VERSION 4.0.3
DESCRIPTION "raylib-cpp C++ Object Oriented Wrapper for raylib"
HOMEPAGE_URL "https://github.com/robloach/raylib-cpp"
LANGUAGES C CXX)

View File

@@ -55,7 +55,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
// Delay initialization of variables due to physics reset async
physics.UpdateStep();
physics.Update();
if (needsReset)
{

View File

@@ -162,7 +162,7 @@ class Color : public ::Color {
}
inline Color& DrawText(
const ::Font font,
const ::Font& font,
const std::string& text,
::Vector2 position,
::Vector2 origin,

View File

@@ -91,6 +91,22 @@ class Material : public ::Material {
return *this;
}
/**
* Draw a 3d mesh with material and transform
*/
inline const Material& DrawMesh(const ::Mesh& mesh, ::Matrix transform) const {
::DrawMesh(mesh, *this, transform);
return *this;
}
/**
* Draw multiple mesh instances with material and different transforms
*/
inline const Material& DrawMesh(const ::Mesh& mesh, ::Matrix* transforms, int instances) const {
::DrawMeshInstanced(mesh, *this, transforms, instances);
return *this;
}
private:
inline void set(const ::Material& material) {
shader = material.shader;

View File

@@ -206,11 +206,17 @@ class Mesh : public ::Mesh {
::UpdateMeshBuffer(*this, index, data, dataSize, offset);
}
/**
* Draw a 3d mesh with material and transform
*/
inline void Draw(const ::Material& material, const ::Matrix& transform) {
::DrawMesh(*this, material, transform);
}
inline void DrawInstanced(const ::Material& material, ::Matrix* transforms, int instances) {
/**
* Draw multiple mesh instances with material and different transforms
*/
inline void Draw(const ::Material& material, ::Matrix* transforms, int instances) {
::DrawMeshInstanced(*this, material, transforms, instances);
}
@@ -249,7 +255,7 @@ class Mesh : public ::Mesh {
/**
* Compute mesh tangents
*/
inline Mesh& Tangents() {
inline Mesh& GenTangents() {
::GenMeshTangents(this);
return *this;
}
@@ -257,7 +263,7 @@ class Mesh : public ::Mesh {
/**
* Compute mesh binormals (aka bitangent)
*/
inline Mesh& Binormals() {
inline Mesh& GenBinormals() {
::GenMeshBinormals(this);
return *this;
}

View File

@@ -174,6 +174,20 @@ class Model : public ::Model {
return *this;
}
/**
* Compute model bounding box limits (considers all meshes)
*/
inline BoundingBox GetBoundingBox() const {
return ::GetModelBoundingBox(*this);
}
/**
* Compute model bounding box limits (considers all meshes)
*/
operator BoundingBox() const {
return ::GetModelBoundingBox(*this);
}
private:
inline void set(const ::Model& model) {
transform = model.transform;

View File

@@ -56,7 +56,6 @@ class ModelAnimation : public ::ModelAnimation {
return *this;
}
ModelAnimation& operator=(const ModelAnimation&) = delete;
ModelAnimation& operator=(ModelAnimation&& other) {

View File

@@ -34,13 +34,18 @@ class Physics {
return *this;
}
inline Physics& Close() {
::ClosePhysics();
inline Physics& Update() {
::UpdatePhysics();
return *this;
}
inline Physics& UpdateStep() {
::UpdatePhysicsStep();
inline Physics& Reset() {
::ResetPhysics();
return *this;
}
inline Physics& Close() {
::ClosePhysics();
return *this;
}
@@ -66,6 +71,11 @@ 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;
@@ -81,6 +91,11 @@ class Physics {
return *this;
}
inline Physics& SetBodyRotation(PhysicsBody body, float radians) {
::SetPhysicsBodyRotation(body, radians);
return *this;
}
inline int GetBodiesCount() const {
return ::GetPhysicsBodiesCount();
}
@@ -100,21 +115,6 @@ class Physics {
inline Vector2 GetShapeVertex(PhysicsBody body, int vertex) const {
return ::GetPhysicsShapeVertex(body, vertex);
}
inline Physics& SetBodyRotation(PhysicsBody body, float radians) {
::SetPhysicsBodyRotation(body, radians);
return *this;
}
inline Physics& DestroyBody(PhysicsBody body) {
::DestroyPhysicsBody(body);
return *this;
}
inline Physics& Reset() {
::ResetPhysics();
return *this;
}
};
} // namespace raylib

View File

@@ -47,7 +47,7 @@ class Ray : public ::Ray {
/**
* Get collision information between ray and sphere
*/
inline RayCollision GetCollisionSphere(::Vector3 center, float radius) const {
inline RayCollision GetCollision(::Vector3 center, float radius) const {
return GetRayCollisionSphere(*this, center, radius);
}
@@ -58,13 +58,6 @@ class Ray : public ::Ray {
return GetRayCollisionBox(*this, box).hit;
}
/**
* Get collision information between ray and box
*/
inline RayCollision GetCollision(const ::BoundingBox& box) const {
return GetRayCollisionBox(*this, box);
}
/**
* Get collision info between ray and model
*/
@@ -72,13 +65,27 @@ class Ray : public ::Ray {
return GetRayCollisionModel(*this, model);
}
/**
* Get collision information between ray and mesh
*/
inline RayCollision GetCollision(const ::Mesh& mesh, const ::Matrix& transform) const {
return GetRayCollisionMesh(*this, mesh, transform);
}
/**
* Get collision info between ray and triangle
*/
inline RayCollision GetCollisionTriangle(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
return GetRayCollisionTriangle(*this, p1, p2, p3);
}
/**
* Get collision info between ray and quad
*/
inline RayCollision GetCollision(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4) const {
return GetRayCollisionQuad(*this, p1, p2, p3, p4);
}
private:
inline void set(const ::Ray& ray) {
position = ray.position;

View File

@@ -139,6 +139,11 @@ class Rectangle : public ::Rectangle {
return SetSize(size.x, size.y);
}
inline Rectangle& SetShapesTexture(const ::Texture2D& texture) {
::SetShapesTexture(texture, *this);
return *this;
}
inline ::Vector2 GetPosition() {
return {x, y};
}

View File

@@ -130,7 +130,7 @@ class Texture : public ::Texture {
/**
* Update GPU texture rectangle with new data
*/
inline Texture& UpdateRec(::Rectangle rec, const void *pixels) {
inline Texture& Update(::Rectangle rec, const void *pixels) {
UpdateTextureRec(*this, rec, pixels);
return *this;
}
@@ -263,6 +263,14 @@ class Texture : public ::Texture {
return *this;
}
/**
* Set shader uniform value for texture (sampler2d)
*/
inline Texture& SetShaderValue(const ::Shader& shader, int locIndex) {
::SetShaderValueTexture(shader, locIndex, *this);
return *this;
}
private:
inline void set(const ::Texture& texture) {
id = texture.id;

View File

@@ -229,6 +229,14 @@ class Window {
return *this;
}
/**
* Set window minimum dimensions
*/
inline Window& SetMinSize(const ::Vector2& size) {
::SetWindowMinSize(static_cast<int>(size.x), static_cast<int>(size.y));
return *this;
}
/**
* Set window dimensions
*/
@@ -247,7 +255,7 @@ class Window {
/**
* Get the screen's width and height.
*/
inline ::Vector2 GetSize() {
inline Vector2 GetSize() {
return {static_cast<float>(GetWidth()), static_cast<float>(GetHeight())};
}

View File

@@ -1,6 +1,6 @@
{
"name": "raylib-cpp",
"version": "4.0.2",
"version": "4.0.3",
"description": "raylib-cpp: C++ Object-Oriented Wrapper for raylib",
"homepage": "https://github.com/robloach/raylib-cpp",
"bugs": {