Skip to content

Commit 5f28d01

Browse files
update to raylib 4.0-dev and add physac and raygui
1 parent 8c4d2af commit 5f28d01

13 files changed

+1090
-614
lines changed

dynamic/test_pyray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
pos = pr.get_mouse_position()
2525
ray = pr.get_mouse_ray(pos, camera)
26-
rayhit = pr.get_collision_ray_ground(ray, 0)
26+
rayhit = pr.get_ray_collision_ground(ray, 0)
2727
print(str(rayhit.position.x))
2828

2929
while not pr.window_should_close():
@@ -39,7 +39,7 @@
3939

4040
pos = pr.get_mouse_position()
4141
ray = pr.get_mouse_ray(pos, camera)
42-
rayhit = pr.get_collision_ray_ground(ray, 0)
42+
rayhit = pr.get_ray_collision_ground(ray, 0)
4343
#print(str(rayhit.position.x))
4444

4545
pr.close_window()

portable_window.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from raylib import *
2+
import pyray as pr
3+
4+
screenWidth = 800
5+
screenHeight = 600
6+
7+
SetConfigFlags(FLAG_WINDOW_UNDECORATED)
8+
InitWindow(screenWidth, screenHeight, b"raygui - portable window")
9+
10+
11+
mousePosition = pr.Vector2(0, 0)
12+
windowPosition = pr.Vector2(500, 200 )
13+
panOffset = mousePosition
14+
dragWindow = False
15+
16+
SetWindowPosition(int(windowPosition.x), int(windowPosition.y))
17+
18+
exitWindow = False
19+
20+
SetTargetFPS(60)
21+
22+
23+
while not exitWindow and not WindowShouldClose():
24+
25+
mousePosition = GetMousePosition()
26+
27+
if IsMouseButtonPressed(MOUSE_LEFT_BUTTON):
28+
if CheckCollisionPointRec(mousePosition, pr.Rectangle(0, 0, screenWidth, 20) ):
29+
dragWindow = True
30+
panOffset = mousePosition
31+
32+
33+
34+
if (dragWindow):
35+
windowPosition.x += (mousePosition.x - panOffset.x)
36+
windowPosition.y += (mousePosition.y - panOffset.y)
37+
if IsMouseButtonReleased(MOUSE_LEFT_BUTTON):
38+
dragWindow = False
39+
40+
SetWindowPosition(int(windowPosition.x), int(windowPosition.y))
41+
42+
43+
BeginDrawing()
44+
ClearBackground(RAYWHITE)
45+
exitWindow = GuiWindowBox(pr.Rectangle(0, 0, screenWidth, screenHeight) , b"#198# PORTABLE WINDOW")
46+
pr.draw_text(f"Mouse Position: {mousePosition.x} {mousePosition.y}", 10, 40, 10, DARKGRAY)
47+
EndDrawing()
48+
49+
CloseWindow()

raylib-c

Submodule raylib-c updated 412 files

raylib/build.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727
def build_linux():
2828
print("BUILDING FOR LINUX")
2929
ffibuilder.cdef(open("raylib/raylib_modified.h").read().replace('RLAPI ', ''))
30+
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
31+
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
3032
ffibuilder.set_source("raylib._raylib_cffi",
3133
"""
3234
#include "raylib.h"
35+
#define RAYGUI_IMPLEMENTATION
36+
#define RAYGUI_SUPPORT_RICONS
37+
#include "../raylib-c/src/extras/raygui.h"
38+
#define PHYSAC_IMPLEMENTATION
39+
#include "../raylib-c/src/extras/physac.h"
3340
""",
3441
extra_link_args=['/usr/local/lib/libraylib.a','-lm', '-lpthread', '-lGLU', '-lGL', '-lrt', '-lm', '-ldl', '-lX11', '-lpthread'],
3542
libraries=['GL','m','pthread', 'dl', 'rt', 'X11']

raylib/physac_modified.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
#define PHYSAC_MAX_BODIES 64 // Maximum number of physic bodies supported
3+
#define PHYSAC_MAX_MANIFOLDS 4096 // Maximum number of physic bodies interactions (64x64)
4+
#define PHYSAC_MAX_VERTICES 24 // Maximum number of vertex for polygons shapes
5+
#define PHYSAC_DEFAULT_CIRCLE_VERTICES 24 // Default number of vertices for circle shapes
6+
7+
8+
9+
10+
typedef enum PhysicsShapeType { PHYSICS_CIRCLE = 0, PHYSICS_POLYGON } PhysicsShapeType;
11+
12+
// Previously defined to be used in PhysicsShape struct as circular dependencies
13+
typedef struct PhysicsBodyData *PhysicsBody;
14+
15+
16+
// Matrix2x2 type (used for polygon shape rotation matrix)
17+
typedef struct Matrix2x2 {
18+
float m00;
19+
float m01;
20+
float m10;
21+
float m11;
22+
} Matrix2x2;
23+
24+
typedef struct PhysicsVertexData {
25+
unsigned int vertexCount; // Vertex count (positions and normals)
26+
Vector2 positions[PHYSAC_MAX_VERTICES]; // Vertex positions vectors
27+
Vector2 normals[PHYSAC_MAX_VERTICES]; // Vertex normals vectors
28+
} PhysicsVertexData;
29+
30+
typedef struct PhysicsShape {
31+
PhysicsShapeType type; // Shape type (circle or polygon)
32+
PhysicsBody body; // Shape physics body data pointer
33+
PhysicsVertexData vertexData; // Shape vertices data (used for polygon shapes)
34+
float radius; // Shape radius (used for circle shapes)
35+
Matrix2x2 transform; // Vertices transform matrix 2x2
36+
} PhysicsShape;
37+
38+
typedef struct PhysicsBodyData {
39+
unsigned int id; // Unique identifier
40+
bool enabled; // Enabled dynamics state (collisions are calculated anyway)
41+
Vector2 position; // Physics body shape pivot
42+
Vector2 velocity; // Current linear velocity applied to position
43+
Vector2 force; // Current linear force (reset to 0 every step)
44+
float angularVelocity; // Current angular velocity applied to orient
45+
float torque; // Current angular force (reset to 0 every step)
46+
float orient; // Rotation in radians
47+
float inertia; // Moment of inertia
48+
float inverseInertia; // Inverse value of inertia
49+
float mass; // Physics body mass
50+
float inverseMass; // Inverse value of mass
51+
float staticFriction; // Friction when the body has not movement (0 to 1)
52+
float dynamicFriction; // Friction when the body has movement (0 to 1)
53+
float restitution; // Restitution coefficient of the body (0 to 1)
54+
bool useGravity; // Apply gravity force to dynamics
55+
bool isGrounded; // Physics grounded on other body state
56+
bool freezeOrient; // Physics rotation constraint
57+
PhysicsShape shape; // Physics body shape information (type, radius, vertices, transform)
58+
} PhysicsBodyData;
59+
60+
typedef struct PhysicsManifoldData {
61+
unsigned int id; // Unique identifier
62+
PhysicsBody bodyA; // Manifold first physics body reference
63+
PhysicsBody bodyB; // Manifold second physics body reference
64+
float penetration; // Depth of penetration from collision
65+
Vector2 normal; // Normal direction vector from 'a' to 'b'
66+
Vector2 contacts[2]; // Points of contact during collision
67+
unsigned int contactsCount; // Current collision number of contacts
68+
float restitution; // Mixed restitution during collision
69+
float dynamicFriction; // Mixed dynamic friction during collision
70+
float staticFriction; // Mixed static friction during collision
71+
} PhysicsManifoldData, *PhysicsManifold;
72+
73+
74+
PHYSACDEF void InitPhysics(void); // Initializes physics system
75+
PHYSACDEF void UpdatePhysics(void); // Update physics system
76+
PHYSACDEF void ResetPhysics(void); // Reset physics system (global variables)
77+
PHYSACDEF void ClosePhysics(void); // Close physics system and unload used memory
78+
PHYSACDEF void SetPhysicsTimeStep(double delta); // Sets physics fixed time step in milliseconds. 1.666666 by default
79+
PHYSACDEF void SetPhysicsGravity(float x, float y); // Sets physics global gravity force
80+
81+
// Physic body creation/destroy
82+
PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); // Creates a new circle physics body with generic parameters
83+
PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density); // Creates a new rectangle physics body with generic parameters
84+
PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density); // Creates a new polygon physics body with generic parameters
85+
PHYSACDEF void DestroyPhysicsBody(PhysicsBody body); // Destroy a physics body
86+
87+
// Physic body forces
88+
PHYSACDEF void PhysicsAddForce(PhysicsBody body, Vector2 force); // Adds a force to a physics body
89+
PHYSACDEF void PhysicsAddTorque(PhysicsBody body, float amount); // Adds an angular force to a physics body
90+
PHYSACDEF void PhysicsShatter(PhysicsBody body, Vector2 position, float force); // Shatters a polygon shape physics body to little physics bodies with explosion force
91+
PHYSACDEF void SetPhysicsBodyRotation(PhysicsBody body, float radians); // Sets physics body shape transform based on radians parameter
92+
93+
// Query physics info
94+
PHYSACDEF PhysicsBody GetPhysicsBody(int index); // Returns a physics body of the bodies pool at a specific index
95+
PHYSACDEF int GetPhysicsBodiesCount(void); // Returns the current amount of created physics bodies
96+
PHYSACDEF int GetPhysicsShapeType(int index); // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
97+
PHYSACDEF int GetPhysicsShapeVerticesCount(int index); // Returns the amount of vertices of a physics body shape
98+
PHYSACDEF Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex); // Returns transformed position of a body shape (body position + vertex transformed position)

0 commit comments

Comments
 (0)