diff --git a/.gitignore b/.gitignore index 575caf2..750f658 100755 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ raylib-headers/raylib.h raylib-headers/raymath.h **/.DS_Store +**/CMakeLists.txt +**/cmake-build-debug **.c \ No newline at end of file diff --git a/build.zig b/build.zig index 743e0e5..703d180 100755 --- a/build.zig +++ b/build.zig @@ -15,7 +15,6 @@ pub fn createExe(b: *Builder, name: []const u8, source: []const u8, desc: []cons var exe = b.addExecutable(name, source); exe.setBuildMode(mode); exe.linkSystemLibrary("raylib"); - exe.addIncludeDir("lib/workaround/"); exe.addCSourceFile("lib/workaround/workaround.c", &[_][]const u8{}); exe.addPackagePath("raylib", "lib/raylib-zig.zig"); exe.addPackagePath("raylib-math", "lib/raylib-zig-math.zig"); @@ -35,7 +34,7 @@ pub fn build(b: *Builder) void var inputMultitouch = createExe(b, "input_multitouch" , "examples/core/input_multitouch.zig" , "Multitouch input"); var twoDCamera = createExe(b, "2d_camera" , "examples/core/2d_camera.zig" , "Shows the functionality of a 2D camera"); var modelsLoading = createExe(b, "models_loading" , "examples/models/models_loading.zig" , "Loads a model and renders it"); - var mouseRay = createExe(b, "ray" , "tests/ray.zig" , "Testing workaround on Ray functions"); + var mouseRay = createExe(b, "draw_2d" , "tests/draw_2d.zig" , "Testing workaround on 2D drawing functions"); var drawSphere = createExe(b, "draw_sphere" , "tests/draw_sphere.zig" , "Testing workaround on DrawSphere"); const examplesStep = b.step("examples", "Builds all the examples"); diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index 7a05183..038b3ef 100755 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -870,47 +870,47 @@ pub extern fn SetCameraPanControl(panKey: c_int) void; pub extern fn SetCameraAltControl(altKey: c_int) void; pub extern fn SetCameraSmoothZoomControl(szKey: c_int) void; pub extern fn SetCameraMoveControls(frontKey: c_int, backKey: c_int, rightKey: c_int, leftKey: c_int, upKey: c_int, downKey: c_int) void; -pub extern fn DrawPixel(posX: c_int, posY: c_int, color: Color) void; -pub extern fn DrawPixelV(position: Vector2, color: Color) void; -pub extern fn DrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void; -pub extern fn DrawLineV(startPos: Vector2, endPos: Vector2, color: Color) void; -pub extern fn DrawLineEx(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void; -pub extern fn DrawLineBezier(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void; -pub extern fn DrawLineStrip(points: [*c]Vector2, numPoints: c_int, color: Color) void; -pub extern fn DrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: Color) void; -pub extern fn DrawCircleSector(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; -pub extern fn DrawCircleSectorLines(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; -pub extern fn DrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, color1: Color, color2: Color) void; -pub extern fn DrawCircleV(center: Vector2, radius: f32, color: Color) void; -pub extern fn DrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: Color) void; -pub extern fn DrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void; -pub extern fn DrawEllipseLines(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void; -pub extern fn DrawRing(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; -pub extern fn DrawRingLines(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; -pub extern fn DrawRectangle(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void; -pub extern fn DrawRectangleV(position: Vector2, size: Vector2, color: Color) void; -pub extern fn DrawRectangleRec(rec: Rectangle, color: Color) void; -pub extern fn DrawRectanglePro(rec: Rectangle, origin: Vector2, rotation: f32, color: Color) void; -pub extern fn DrawRectangleGradientV(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void; -pub extern fn DrawRectangleGradientH(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void; -pub extern fn DrawRectangleGradientEx(rec: Rectangle, col1: Color, col2: Color, col3: Color, col4: Color) void; -pub extern fn DrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void; -pub extern fn DrawRectangleLinesEx(rec: Rectangle, lineThick: c_int, color: Color) void; -pub extern fn DrawRectangleRounded(rec: Rectangle, roundness: f32, segments: c_int, color: Color) void; -pub extern fn DrawRectangleRoundedLines(rec: Rectangle, roundness: f32, segments: c_int, lineThick: c_int, color: Color) void; -pub extern fn DrawTriangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void; -pub extern fn DrawTriangleLines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void; -pub extern fn DrawTriangleFan(points: [*c]Vector2, numPoints: c_int, color: Color) void; -pub extern fn DrawTriangleStrip(points: [*c]Vector2, pointsCount: c_int, color: Color) void; -pub extern fn DrawPoly(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void; -pub extern fn DrawPolyLines(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void; -pub extern fn CheckCollisionRecs(rec1: Rectangle, rec2: Rectangle) bool; -pub extern fn CheckCollisionCircles(center1: Vector2, radius1: f32, center2: Vector2, radius2: f32) bool; -pub extern fn CheckCollisionCircleRec(center: Vector2, radius: f32, rec: Rectangle) bool; -pub extern fn GetCollisionRec(rec1: Rectangle, rec2: Rectangle) Rectangle; -pub extern fn CheckCollisionPointRec(point: Vector2, rec: Rectangle) bool; -pub extern fn CheckCollisionPointCircle(point: Vector2, center: Vector2, radius: f32) bool; -pub extern fn CheckCollisionPointTriangle(point: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) bool; +//pub extern fn DrawPixel(posX: c_int, posY: c_int, color: Color) void; +//pub extern fn DrawPixelV(position: Vector2, color: Color) void; +//pub extern fn DrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void; +//pub extern fn DrawLineV(startPos: Vector2, endPos: Vector2, color: Color) void; +//pub extern fn DrawLineEx(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void; +//pub extern fn DrawLineBezier(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void; +//pub extern fn DrawLineStrip(points: [*c]Vector2, numPoints: c_int, color: Color) void; +//pub extern fn DrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: Color) void; +//pub extern fn DrawCircleSector(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; +//pub extern fn DrawCircleSectorLines(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; +//pub extern fn DrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, color1: Color, color2: Color) void; +//pub extern fn DrawCircleV(center: Vector2, radius: f32, color: Color) void; +//pub extern fn DrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: Color) void; +//pub extern fn DrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void; +//pub extern fn DrawEllipseLines(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void; +//pub extern fn DrawRing(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; +//pub extern fn DrawRingLines(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void; +//pub extern fn DrawRectangle(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void; +//pub extern fn DrawRectangleV(position: Vector2, size: Vector2, color: Color) void; +//pub extern fn DrawRectangleRec(rec: Rectangle, color: Color) void; +//pub extern fn DrawRectanglePro(rec: Rectangle, origin: Vector2, rotation: f32, color: Color) void; +//pub extern fn DrawRectangleGradientV(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void; +//pub extern fn DrawRectangleGradientH(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void; +//pub extern fn DrawRectangleGradientEx(rec: Rectangle, col1: Color, col2: Color, col3: Color, col4: Color) void; +//pub extern fn DrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void; +//pub extern fn DrawRectangleLinesEx(rec: Rectangle, lineThick: c_int, color: Color) void; +//pub extern fn DrawRectangleRounded(rec: Rectangle, roundness: f32, segments: c_int, color: Color) void; +//pub extern fn DrawRectangleRoundedLines(rec: Rectangle, roundness: f32, segments: c_int, lineThick: c_int, color: Color) void; +//pub extern fn DrawTriangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void; +//pub extern fn DrawTriangleLines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void; +//pub extern fn DrawTriangleFan(points: [*c]Vector2, numPoints: c_int, color: Color) void; +//pub extern fn DrawTriangleStrip(points: [*c]Vector2, pointsCount: c_int, color: Color) void; +//pub extern fn DrawPoly(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void; +//pub extern fn DrawPolyLines(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void; +//pub extern fn CheckCollisionRecs(rec1: Rectangle, rec2: Rectangle) bool; +//pub extern fn CheckCollisionCircles(center1: Vector2, radius1: f32, center2: Vector2, radius2: f32) bool; +//pub extern fn CheckCollisionCircleRec(center: Vector2, radius: f32, rec: Rectangle) bool; +//pub extern fn GetCollisionRec(rec1: Rectangle, rec2: Rectangle) Rectangle; +//pub extern fn CheckCollisionPointRec(point: Vector2, rec: Rectangle) bool; +//pub extern fn CheckCollisionPointCircle(point: Vector2, center: Vector2, radius: f32) bool; +//pub extern fn CheckCollisionPointTriangle(point: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) bool; pub extern fn LoadImage(fileName: [*c]const u8) Image; pub extern fn LoadImageEx(pixels: [*c]Color, width: c_int, height: c_int) Image; pub extern fn LoadImagePro(data: ?*c_void, width: c_int, height: c_int, format: PixelFormat) Image; @@ -1189,6 +1189,49 @@ pub const FormatText = TextFormat; // ---------- WORKAROUND ---------- pub extern fn WGetMouseRay(mousePosition: [*c]const Vector2, camera: Camera) Ray; + +pub extern fn WDrawPixel(posX: c_int, posY: c_int, color: [*c]const Color) void; +pub extern fn WDrawPixelV(position: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: [*c]const Color) void; +pub extern fn WDrawLineV(startPos: [*c]const Vector2, endPos: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawLineEx(startPos: [*c]const Vector2, endPos: [*c]const Vector2, thick: f32, color: [*c]const Color) void; +pub extern fn WDrawLineBezier(startPos: [*c]const Vector2, endPos: [*c]const Vector2, thick: f32, color: [*c]const Color) void; +pub extern fn WDrawLineStrip(points: [*c]const Vector2, numPoints: c_int, color: [*c]const Color) void; +pub extern fn WDrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: [*c]const Color) void; +pub extern fn WDrawCircleSector(center: [*c]const Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawCircleSectorLines(center: [*c]const Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, color1: [*c]const Color, color2: [*c]const Color) void; +pub extern fn WDrawCircleV(center: [*c]const Vector2, radius: f32, color: [*c]const Color) void; +pub extern fn WDrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: [*c]const Color) void; +pub extern fn WDrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: [*c]const Color) void; +pub extern fn WDrawEllipseLines(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: [*c]const Color) void; +pub extern fn WDrawRing(center: [*c]const Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawRingLines(center: [*c]const Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangle(posX: c_int, posY: c_int, width: c_int, height: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleV(position: [*c]const Vector2, size: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawRectangleRec(rec: [*c]const Rectangle, color: [*c]const Color) void; +pub extern fn WDrawRectanglePro(rec: [*c]const Rectangle, origin: [*c]const Vector2, rotation: f32, color: [*c]const Color) void; +pub extern fn WDrawRectangleGradientV(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: [*c]const Color, color2: [*c]const Color) void; +pub extern fn WDrawRectangleGradientH(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: [*c]const Color, color2: [*c]const Color) void; +pub extern fn WDrawRectangleGradientEx(rec: [*c]const Rectangle, col1: [*c]const Color, col2: [*c]const Color, col3: [*c]const Color, col4: [*c]const Color) void; +pub extern fn WDrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleLinesEx(rec: [*c]const Rectangle, lineThick: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleRounded(rec: [*c]const Rectangle, roundness: f32, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleRoundedLines(rec: [*c]const Rectangle, roundness: f32, segments: c_int, lineThick: c_int, color: [*c]const Color) void; +pub extern fn WDrawTriangle(v1: [*c]const Vector2, v2: [*c]const Vector2, v3: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawTriangleLines(v1: [*c]const Vector2, v2: [*c]const Vector2, v3: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawTriangleFan(points: [*c]const Vector2, numPoints: c_int, color: [*c]const Color) void; +pub extern fn WDrawTriangleStrip(points: [*c]const Vector2, pointsCount: c_int, color: [*c]const Color) void; +pub extern fn WDrawPoly(center: [*c]const Vector2, sides: c_int, radius: f32, rotation: f32, color: [*c]const Color) void; +pub extern fn WDrawPolyLines(center: [*c]const Vector2, sides: c_int, radius: f32, rotation: f32, color: [*c]const Color) void; +pub extern fn WCheckCollisionRecs(rec1: [*c]const Rectangle, rec2: [*c]const Rectangle) bool; +pub extern fn WCheckCollisionCircles(center1: [*c]const Vector2, radius1: f32, center2: [*c]const Vector2, radius2: f32) bool; +pub extern fn WCheckCollisionCircleRec(center: [*c]const Vector2, radius: f32, rec: [*c]const Rectangle) bool; +pub extern fn WGetCollisionRec(rec1: [*c]const Rectangle, rec2: [*c]const Rectangle) [*c]const Rectangle; +pub extern fn WCheckCollisionPointRec(point: [*c]const Vector2, rec: [*c]const Rectangle) bool; +pub extern fn WCheckCollisionPointCircle(point: [*c]const Vector2, center: [*c]const Vector2, radius: f32) bool; +pub extern fn WCheckCollisionPointTriangle(point: [*c]const Vector2, p1: [*c]const Vector2, p2: [*c]const Vector2, p3: [*c]const Vector2) bool; + pub extern fn WDrawSphere(centerPos: [*c]const Vector3, radius: f32, color: [*c]const Color) void; pub extern fn WDrawRay(ray: Ray, color: [*c]const Color) void; @@ -1198,6 +1241,211 @@ pub fn GetMouseRay(mousePosition: Vector2, camera: Camera) Ray return WGetMouseRay(&mousePosition, camera); } +pub fn DrawPixel(posX: c_int, posY: c_int, color: Color) void +{ + WDrawPixel(posX, posY, &color); +} + +pub fn DrawPixelV(position: Vector2, color: Color) void +{ + WDrawPixelV(&position, &color); +} + +pub fn DrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void +{ + WDrawLine(startPosX, startPosY, endPosX, endPosY, &color); +} + +pub fn DrawLineV(startPos: Vector2, endPos: Vector2, color: Color) void +{ + WDrawLineV(&startPos, &endPos, &color); +} + +pub fn DrawLineEx(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void +{ + WDrawLineEx(&startPos, &endPos, thick, &color); +} + +pub fn DrawLineBezier(startPos: Vector2, endPos: Vector2, thick: f32, color: Color) void +{ + WDrawLineBezier(&startPos, &endPos, thick, &color); +} + +pub fn DrawLineStrip(points: []const Vector2, numPoints: c_int, color: Color) void +{ + WDrawLineStrip(&points[0], numPoints, &color); +} + +pub fn DrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: Color) void +{ + WDrawCircle(centerX, centerY, radius, &color); +} + +pub fn DrawCircleSector(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void +{ + WDrawCircleSector(¢er, radius, startAngle, endAngle, segments, &color); +} + +pub fn DrawCircleSectorLines(center: Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void +{ + WDrawCircleSectorLines(¢er, radius, startAngle, endAngle, segments, &color); +} + +pub fn DrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, color1: Color, color2: Color) void +{ + WDrawCircleGradient(centerX, centerY, radius, &color1, &color2); +} + +pub fn DrawCircleV(center: Vector2, radius: f32, color: Color) void +{ + WDrawCircleV(¢er, radius, &color); +} + +pub fn DrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: Color) void +{ + WDrawCircleLines(centerX, centerY, radius, &color); +} + +pub fn DrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void +{ + WDrawEllipse(centerX, centerY, radiusH, radiusV, &color); +} + +pub fn DrawEllipseLines(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: Color) void +{ + WDrawEllipseLines(centerX, centerY, radiusH, radiusV, &color); +} + +pub fn DrawRing(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void +{ + WDrawRing(¢er, innerRadius, outerRadius, startAngle, endAngle, segments, &color); +} + +pub fn DrawRingLines(center: Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: Color) void +{ + WDrawRingLines(¢er, innerRadius, outerRadius, startAngle, endAngle, segments, &color); +} + +pub fn DrawRectangle(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void +{ + WDrawRectangle(posX, posY, width, height, &color); +} + +pub fn DrawRectangleV(position: Vector2, size: Vector2, color: Color) void +{ + WDrawRectangleV(&position, &size, &color); +} + +pub fn DrawRectangleRec(rec: Rectangle, color: Color) void +{ + WDrawRectangleRec(&rec, &color); +} + +pub fn DrawRectanglePro(rec: Rectangle, origin: Vector2, rotation: f32, color: Color) void +{ + WDrawRectanglePro(&rec, &origin, rotation, &color); +} + +pub fn DrawRectangleGradientV(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void +{ + WDrawRectangleGradientV(posX, posY, width, height, &color1, &color2); +} + +pub fn DrawRectangleGradientH(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: Color, color2: Color) void +{ + WDrawRectangleGradientH(posX, posY, width, height, &color1, &color2); +} + +pub fn DrawRectangleGradientEx(rec: Rectangle, col1: Color, col2: Color, col3: Color, col4: Color) void +{ + WDrawRectangleGradientEx(&rec, &col1, &col2, &col3, &col4); +} + +pub fn DrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void +{ + WDrawRectangleLines(posX, posY, width, height, &color); +} + +pub fn DrawRectangleLinesEx(rec: Rectangle, lineThick: c_int, color: Color) void +{ + WDrawRectangleLinesEx(&rec, lineThick, &color); +} + +pub fn DrawRectangleRounded(rec: Rectangle, roundness: f32, segments: c_int, color: Color) void +{ + WDrawRectangleRounded(&rec, roundness, segments, &color); +} + +pub fn DrawRectangleRoundedLines(rec: Rectangle, roundness: f32, segments: c_int, lineThick: c_int, color: Color) void +{ + WDrawRectangleRoundedLines(&rec, roundness, segments, lineThick, &color); +} + +pub fn DrawTriangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void +{ + WDrawTriangle(&v1, &v2, &v3, &color); +} + +pub fn DrawTriangleLines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) void +{ + WDrawTriangleLines(&v1, &v2, &v3, &color); +} + +pub fn DrawTriangleFan(points: []const Vector2, numPoints: c_int, color: Color) void +{ + WDrawTriangleFan(&points[0], numPoints, &color); +} + +pub fn DrawTriangleStrip(points: []const Vector2, pointsCount: c_int, color: Color) void +{ + WDrawTriangleStrip(&points[0], pointsCount, &color); +} + +pub fn DrawPoly(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void +{ + WDrawPoly(¢er, sides, radius, rotation, &color); +} + +pub fn DrawPolyLines(center: Vector2, sides: c_int, radius: f32, rotation: f32, color: Color) void +{ + WDrawPolyLines(¢er, sides, radius, rotation, &color); +} + +pub fn CheckCollisionRecs(rec1: Rectangle, rec2: Rectangle) bool +{ + WCheckCollisionRecs(&rec1, &rec2); +} + +pub fn CheckCollisionCircles(center1: Vector2, radius1: f32, center2: Vector2, radius2: f32) bool +{ + WCheckCollisionCircles(¢er1, radius1, ¢er2, radius2); +} + +pub fn CheckCollisionCircleRec(center: Vector2, radius: f32, rec: Rectangle) bool +{ + WCheckCollisionCircleRec(¢er, radius, &rec); +} + +pub fn GetCollisionRec(rec1: Rectangle, rec2: Rectangle) [*c]const Rectangle +{ + WGetCollisionRec(&rec1, &rec2); +} + +pub fn CheckCollisionPointRec(point: Vector2, rec: Rectangle) bool +{ + WCheckCollisionPointRec(&point, &rec); +} + +pub fn CheckCollisionPointCircle(point: Vector2, center: Vector2, radius: f32) bool +{ + WCheckCollisionPointCircle(&point, ¢er, radius); +} + +pub fn CheckCollisionPointTriangle(point: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) bool +{ + WCheckCollisionPointTriangle(&point, &p1, &p2, &p3); +} + pub fn DrawSphere(centerPos: Vector3, radius: f32, color: Color) void { WDrawSphere(¢erPos, radius, &color); diff --git a/lib/workaround/functions b/lib/workaround/functions new file mode 100644 index 0000000..8b046be --- /dev/null +++ b/lib/workaround/functions @@ -0,0 +1,41 @@ +pub extern fn WDrawPixel(posX: c_int, posY: c_int, color: [*c]const Color) void; +pub extern fn WDrawPixelV(position: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawLine(startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: [*c]const Color) void; +pub extern fn WDrawLineV(startPos: [*c]const Vector2, endPos: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawLineEx(startPos: [*c]const Vector2, endPos: [*c]const Vector2, thick: f32, color: [*c]const Color) void; +pub extern fn WDrawLineBezier(startPos: [*c]const Vector2, endPos: [*c]const Vector2, thick: f32, color: [*c]const Color) void; +pub extern fn WDrawLineStrip(points: [*c]const Vector2, numPoints: c_int, color: [*c]const Color) void; +pub extern fn WDrawCircle(centerX: c_int, centerY: c_int, radius: f32, color: [*c]const Color) void; +pub extern fn WDrawCircleSector(center: [*c]const Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawCircleSectorLines(center: [*c]const Vector2, radius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawCircleGradient(centerX: c_int, centerY: c_int, radius: f32, color1: [*c]const Color, color2: [*c]const Color) void; +pub extern fn WDrawCircleV(center: [*c]const Vector2, radius: f32, color: [*c]const Color) void; +pub extern fn WDrawCircleLines(centerX: c_int, centerY: c_int, radius: f32, color: [*c]const Color) void; +pub extern fn WDrawEllipse(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: [*c]const Color) void; +pub extern fn WDrawEllipseLines(centerX: c_int, centerY: c_int, radiusH: f32, radiusV: f32, color: [*c]const Color) void; +pub extern fn WDrawRing(center: [*c]const Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawRingLines(center: [*c]const Vector2, innerRadius: f32, outerRadius: f32, startAngle: c_int, endAngle: c_int, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangle(posX: c_int, posY: c_int, width: c_int, height: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleV(position: [*c]const Vector2, size: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawRectangleRec(rec: [*c]const Rectangle, color: [*c]const Color) void; +pub extern fn WDrawRectanglePro(rec: [*c]const Rectangle, origin: [*c]const Vector2, rotation: f32, color: [*c]const Color) void; +pub extern fn WDrawRectangleGradientV(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: [*c]const Color, color2: [*c]const Color) void; +pub extern fn WDrawRectangleGradientH(posX: c_int, posY: c_int, width: c_int, height: c_int, color1: [*c]const Color, color2: [*c]const Color) void; +pub extern fn WDrawRectangleGradientEx(rec: [*c]const Rectangle, col1: [*c]const Color, col2: [*c]const Color, col3: [*c]const Color, col4: [*c]const Color) void; +pub extern fn WDrawRectangleLines(posX: c_int, posY: c_int, width: c_int, height: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleLinesEx(rec: [*c]const Rectangle, lineThick: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleRounded(rec: [*c]const Rectangle, roundness: f32, segments: c_int, color: [*c]const Color) void; +pub extern fn WDrawRectangleRoundedLines(rec: [*c]const Rectangle, roundness: f32, segments: c_int, lineThick: c_int, color: [*c]const Color) void; +pub extern fn WDrawTriangle(v1: [*c]const Vector2, v2: [*c]const Vector2, v3: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawTriangleLines(v1: [*c]const Vector2, v2: [*c]const Vector2, v3: [*c]const Vector2, color: [*c]const Color) void; +pub extern fn WDrawTriangleFan(points: [*c]const Vector2, numPoints: c_int, color: [*c]const Color) void; +pub extern fn WDrawTriangleStrip(points: [*c]const Vector2, pointsCount: c_int, color: [*c]const Color) void; +pub extern fn WDrawPoly(center: [*c]const Vector2, sides: c_int, radius: f32, rotation: f32, color: [*c]const Color) void; +pub extern fn WDrawPolyLines(center: [*c]const Vector2, sides: c_int, radius: f32, rotation: f32, color: [*c]const Color) void; +pub extern fn WCheckCollisionRecs(rec1: [*c]const Rectangle, rec2: [*c]const Rectangle) bool; +pub extern fn WCheckCollisionCircles(center1: [*c]const Vector2, radius1: f32, center2: [*c]const Vector2, radius2: f32) bool; +pub extern fn WCheckCollisionCircleRec(center: [*c]const Vector2, radius: f32, rec: [*c]const Rectangle) bool; +pub extern fn WGetCollisionRec(rec1: [*c]const Rectangle, rec2: [*c]const Rectangle) [*c]const Rectangle; +pub extern fn WCheckCollisionPointRec(point: [*c]const Vector2, rec: [*c]const Rectangle) bool; +pub extern fn WCheckCollisionPointCircle(point: [*c]const Vector2, center: [*c]const Vector2, radius: f32) bool; +pub extern fn WCheckCollisionPointTriangle(point: [*c]const Vector2, p1: [*c]const Vector2, p2: [*c]const Vector2, p3: [*c]const Vector2) bool; \ No newline at end of file diff --git a/lib/workaround/generate_functions.py b/lib/workaround/generate_functions.py new file mode 100644 index 0000000..fbbfb30 --- /dev/null +++ b/lib/workaround/generate_functions.py @@ -0,0 +1,36 @@ +import re + +""" +Automatic utility for generating function calls to workaround functions +""" + +if __name__ == "__main__": + pass + +raymath = open("functions") + + +for line in raymath.readlines(): + # each (.*) is some variable value + result = re.search("pub extern fn (.*)start_arg(.*)end_arg (.*);", line.replace("(", "start_arg").replace(")", "end_arg")) + + # get whats in the (.*)'s + func_name = result.group(1) + arguments = result.group(2) + return_type = result.group(3) + + args = [] + names = [] + for arg in arguments.split(", "): + result = re.search("(.*): (.*)", arg) + arg_name = result.group(1) + arg_type = result.group(2) + args.append(arg_name + ": " + arg_type.replace("[*c]", "").replace("const ", "")) # put everything together + if "[*c]" in arg_type: + arg_name = "&" + arg_name + names.append(arg_name) + args = ", ".join(args) + print("pub fn " + func_name[1:] + "(" + args + ") " + return_type) + print("{") + print(" " + func_name + "(" + (", ".join(names)) + ");") + print("}\n") diff --git a/lib/workaround/workaround.h b/lib/workaround/workaround.h deleted file mode 100644 index 51a6db4..0000000 --- a/lib/workaround/workaround.h +++ /dev/null @@ -1,13 +0,0 @@ -// raylib-zig (c) Nikolas Wipper 2020 - -#ifndef RAYLIB_ZIG_WORKAROUND_H -#define RAYLIB_ZIG_WORKAROUND_H - -#include - -Ray WGetMouseRay(Vector2 * mousePosition, Camera camera); - -void WDrawSphere(Vector3 * centerPos, float radius, Color * color); -void WDrawRay(Ray ray, Color * color); - -#endif //RAYLIB_ZIG_WORKAROUND_H diff --git a/tests/ray.zig b/tests/draw_2d.zig similarity index 63% rename from tests/ray.zig rename to tests/draw_2d.zig index 39c675f..091a38a 100644 --- a/tests/ray.zig +++ b/tests/draw_2d.zig @@ -14,15 +14,7 @@ pub fn main() anyerror!void const screenWidth = 800; const screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib-zig [core] test - mouse ray"); - - var camera = Camera { - .position = Vector3 { .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera position - .target = Vector3 { .x = 0.0, .y = 0.0, .z = 1.0 }, // Camera looking at point - .up = Vector3 { .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target) - .fovy = 80.0, // Camera field-of-view Y - .type = CameraType.CAMERA_PERSPECTIVE // Camera mode type - }; + InitWindow(screenWidth, screenHeight, "raylib-zig [core] test - draw 2d"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -41,18 +33,12 @@ pub fn main() anyerror!void ClearBackground(WHITE); - camera.Begin(); - - var ray = GetMouseRay(Vector2{.x = screenWidth / 2, .y = screenHeight / 2}, camera); - - var ray2 = Ray { - .position = Vector3{ .x = 1, .y = 0, .z = 1 }, - .direction = Vector3{ .x = -1, .y = 0, .z = 1 }, - }; - - DrawRay(ray2, RED); - - camera.End(); + DrawLineV(Vector2{.x=0, .y=0}, Vector2{.x=100, .y=100}, RED); + DrawLineEx(Vector2{.x=10, .y=0}, Vector2{.x=110, .y=100}, 5, RED); + DrawLineBezier(Vector2{.x=50, .y=0}, Vector2{.x=150, .y=100}, 5, RED); + DrawLineStrip(&[_]Vector2{ Vector2{.x=100, .y=0}, Vector2{.x=160, .y=40}, Vector2{.x=200, .y=100} }, 3, RED); + // TODO: More testing on all the functions + // I'm just getting everything is fine, but you never know EndDrawing(); //----------------------------------------------------------------------------------