mirror of
https://github.com/raylib-zig/raylib-zig.git
synced 2026-02-14 13:28:48 +00:00
Start working around
This commit is contained in:
parent
add088f69d
commit
9ed2f2c5d2
@ -15,6 +15,8 @@ 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");
|
||||
|
||||
@ -33,6 +35,8 @@ 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 drawSphere = createExe(b, "draw_sphere" , "tests/draw_sphere.zig" , "Testing workaround on DrawSphere");
|
||||
|
||||
const examplesStep = b.step("examples", "Builds all the examples");
|
||||
examplesStep.dependOn(&basicWindow.step);
|
||||
|
||||
@ -21,8 +21,8 @@ pub fn main() anyerror!void
|
||||
.position = Vector3 { .x = 50.0, .y = 50.0, .z = 50.0 }, // Camera position
|
||||
.target = Vector3 { .x = 0.0, .y = 10.0, .z = 0.0 }, // Camera looking at point
|
||||
.up = Vector3 { .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target)
|
||||
.fovy = 45.0, // Camera field-of-view Y
|
||||
.type = CameraType.CAMERA_PERSPECTIVE // Camera mode type
|
||||
.fovy = 45.0, // Camera field-of-view Y
|
||||
.type = CameraType.CAMERA_PERSPECTIVE // Camera mode type
|
||||
};
|
||||
|
||||
var model = LoadModel("resources/models/castle.obj"); // Load model
|
||||
|
||||
@ -775,6 +775,7 @@ pub extern fn EndTextureMode() void;
|
||||
pub extern fn BeginScissorMode(x: c_int, y: c_int, width: c_int, height: c_int) void;
|
||||
pub extern fn EndScissorMode() void;
|
||||
pub extern fn GetMouseRay(mousePosition: Vector2, camera: Camera) Ray;
|
||||
pub extern fn WGetMouseRay(mouseX: f32, mouseY: f32, camera: Camera) Ray;
|
||||
pub extern fn GetCameraMatrix(camera: Camera) Matrix;
|
||||
pub extern fn GetCameraMatrix2D(camera: Camera2D) Matrix;
|
||||
pub extern fn GetWorldToScreen(position: Vector3, camera: Camera) Vector2;
|
||||
@ -1034,12 +1035,14 @@ pub extern fn DrawCubeWires(position: Vector3, width: f32, height: f32, length:
|
||||
pub extern fn DrawCubeWiresV(position: Vector3, size: Vector3, color: Color) void;
|
||||
pub extern fn DrawCubeTexture(texture: Texture2D, position: Vector3, width: f32, height: f32, length: f32, color: Color) void;
|
||||
pub extern fn DrawSphere(centerPos: Vector3, radius: f32, color: Color) void;
|
||||
pub extern fn WDrawSphere(posX: f32, posY: f32, posZ: f32, radius: f32, r: u8, g: u8, b: u8, a: u8) void;
|
||||
pub extern fn DrawSphereEx(centerPos: Vector3, radius: f32, rings: c_int, slices: c_int, color: Color) void;
|
||||
pub extern fn DrawSphereWires(centerPos: Vector3, radius: f32, rings: c_int, slices: c_int, color: Color) void;
|
||||
pub extern fn DrawCylinder(position: Vector3, radiusTop: f32, radiusBottom: f32, height: f32, slices: c_int, color: Color) void;
|
||||
pub extern fn DrawCylinderWires(position: Vector3, radiusTop: f32, radiusBottom: f32, height: f32, slices: c_int, color: Color) void;
|
||||
pub extern fn DrawPlane(centerPos: Vector3, size: Vector2, color: Color) void;
|
||||
pub extern fn DrawRay(ray: Ray, color: Color) void;
|
||||
pub extern fn WDrawRay(ray: Ray, r: u8, g: u8, b: u8, a: u8) void;
|
||||
pub extern fn DrawGrid(slices: c_int, spacing: f32) void;
|
||||
pub extern fn DrawGizmo(position: Vector3) void;
|
||||
pub extern fn LoadModel(fileName: [*c]const u8) Model;
|
||||
|
||||
17
lib/workaround/workaround.h
Normal file
17
lib/workaround/workaround.h
Normal file
@ -0,0 +1,17 @@
|
||||
// raylib-zig (c) Nikolas Wipper 2020
|
||||
|
||||
#ifndef RAYLIB_ZIG_WORKAROUND_H
|
||||
#define RAYLIB_ZIG_WORKAROUND_H
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
#define VECTOR2 float x, float y
|
||||
#define VECTOR3 float x, float y, float z
|
||||
#define COLOR unsigned char r, unsigned char g, unsigned char b, unsigned char a
|
||||
|
||||
Ray WGetMouseRay(float mouseX, float mouseY, Camera camera);
|
||||
|
||||
void WDrawSphere(VECTOR3, float radius, COLOR);
|
||||
void WDrawRay(Ray ray, COLOR);
|
||||
|
||||
#endif //RAYLIB_ZIG_WORKAROUND_H
|
||||
55
tests/draw_sphere.zig
Normal file
55
tests/draw_sphere.zig
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// mouse_ray
|
||||
// Zig version: 0.6.0
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-15
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
|
||||
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 = 2.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
|
||||
};
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(WHITE);
|
||||
|
||||
camera.Begin();
|
||||
|
||||
WDrawSphere(0, 0, 2, 1, 255, 0, 0, 255);
|
||||
|
||||
camera.End();
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
66
tests/ray.zig
Normal file
66
tests/ray.zig
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// mouse_ray
|
||||
// Zig version: 0.6.0
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-15
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
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
|
||||
};
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(WHITE);
|
||||
|
||||
camera.Begin();
|
||||
|
||||
var ray = WGetMouseRay(screenWidth / 2, screenHeight / 2, camera);
|
||||
|
||||
var ray2 = Ray {
|
||||
.position = Vector3{ .x = 1, .y = 0, .z = 1 },
|
||||
.direction = Vector3{ .x = -1, .y = 0, .z = 1 },
|
||||
};
|
||||
|
||||
WDrawRay(ray2, 255, 0, 0, 255);
|
||||
|
||||
camera.End();
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user