mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Add some examples
This commit is contained in:
parent
968f145583
commit
53be5d5871
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ zig-cache/
|
||||
Project/*
|
||||
|
||||
**/.DS_Store
|
||||
**.c
|
@ -1,5 +1,6 @@
|
||||
# raylib-zig
|
||||
Manually tweaked, auto generated [raylib](https://github.com/raysan5/raylib) bindings for zig.
|
||||
Manually tweaked, auto generated [raylib](https://github.com/raysan5/raylib) bindings for zig.<br>
|
||||
Be aware these bindings are for the 2.5.0 release of raylib. 2.6.0 bindings will follow soon.
|
||||
|
||||
## Example
|
||||
Basically we can copy the default example with some minor changes:
|
||||
@ -41,7 +42,11 @@ pub fn main() anyerror!void
|
||||
```
|
||||
|
||||
## Technical restrictions
|
||||
Due to zig being a relatively new language it does [not have full C ABI support](https://github.com/ziglang/zig/issues/1481) at the moment. For use that mainly means we can't use any functions that returns structs that are less then 16 bytes large.
|
||||
Due to zig being a relatively new language it does [not have full C ABI support](https://github.com/ziglang/zig/issues/1481) at the moment. For use that mainly means we can't use any functions that return structs that are less then 16 bytes large.
|
||||
Here is an incomplete list of some functions affected by this:
|
||||
+ DrawCircleV
|
||||
+ DrawRectangleRec
|
||||
+ DrawModel and all its variations
|
||||
|
||||
## Building the examples
|
||||
To build all available examples simply `zig build examples`. To list available examples run `zig build --help`. If you want to run and examples, say `basic_window` run `zig build basic_window`
|
||||
|
57
build.zig
57
build.zig
@ -11,27 +11,76 @@ pub fn build(b: *Builder) void
|
||||
{
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
var basicWindow = b.addExecutable("BasicWindow", "examples/core/basic_window.zig");
|
||||
var basicWindow = b.addExecutable("basic_window", "examples/core/basic_window.zig");
|
||||
basicWindow.setBuildMode(mode);
|
||||
basicWindow.linkSystemLibrary("raylib");
|
||||
basicWindow.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
|
||||
var modelsLoading = b.addExecutable("BasicWindow", "examples/models/models_loading.zig");
|
||||
var inputKeys = b.addExecutable("input_keys", "examples/core/input_keys.zig");
|
||||
inputKeys.setBuildMode(mode);
|
||||
inputKeys.linkSystemLibrary("raylib");
|
||||
inputKeys.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
|
||||
var inputMouse = b.addExecutable("input_mouse", "examples/core/input_mouse.zig");
|
||||
inputMouse.setBuildMode(mode);
|
||||
inputMouse.linkSystemLibrary("raylib");
|
||||
inputMouse.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
|
||||
var inputMouseWheel = b.addExecutable("input_mouse_wheel", "examples/core/input_mouse_wheel.zig");
|
||||
inputMouseWheel.setBuildMode(mode);
|
||||
inputMouseWheel.linkSystemLibrary("raylib");
|
||||
inputMouseWheel.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
|
||||
var inputMultitouch = b.addExecutable("input_multitouch", "examples/core/input_multitouch.zig");
|
||||
inputMultitouch.setBuildMode(mode);
|
||||
inputMultitouch.linkSystemLibrary("raylib");
|
||||
inputMultitouch.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
|
||||
var twoDCamera = b.addExecutable("2d_camera", "examples/core/2d_camera.zig");
|
||||
twoDCamera.setBuildMode(mode);
|
||||
twoDCamera.linkSystemLibrary("raylib");
|
||||
twoDCamera.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
twoDCamera.addPackagePath("raylib-math", "lib/raylib-zig-math.zig");
|
||||
|
||||
var modelsLoading = b.addExecutable("models_loading", "examples/models/models_loading.zig");
|
||||
modelsLoading.setBuildMode(mode);
|
||||
modelsLoading.linkSystemLibrary("raylib");
|
||||
modelsLoading.addPackagePath("raylib", "lib/raylib-zig.zig");
|
||||
|
||||
const examplesStep = b.step("examples", "Builds all the examples");
|
||||
examplesStep.dependOn(&basicWindow.step);
|
||||
examplesStep.dependOn(&inputKeys.step);
|
||||
examplesStep.dependOn(&inputMouse.step);
|
||||
examplesStep.dependOn(&inputMouseWheel.step);
|
||||
examplesStep.dependOn(&inputMultitouch.step);
|
||||
examplesStep.dependOn(&twoDCamera.step);
|
||||
examplesStep.dependOn(&modelsLoading.step);
|
||||
|
||||
const runBasicWindow = basicWindow.run();
|
||||
runBasicWindow.step.dependOn(b.getInstallStep());
|
||||
const basicWindowStep = b.step("basic_window", "Creates a basic window with text");
|
||||
basicWindowStep.dependOn(&runBasicWindow.step);
|
||||
|
||||
const runInputKeys = inputKeys.run();
|
||||
const inputKeysStep = b.step("input_keys", "Simple keyboard input");
|
||||
inputKeysStep.dependOn(&runInputKeys.step);
|
||||
|
||||
const runInputMouse = inputMouse.run();
|
||||
const inputMouseStep = b.step("input_mouse", "Simple mouse input");
|
||||
inputMouseStep.dependOn(&runInputMouse.step);
|
||||
|
||||
const runInputMouseWheel = inputMouseWheel.run();
|
||||
const inputMouseWheelStep = b.step("input_mouse_wheel", "Mouse wheel input");
|
||||
inputMouseWheelStep.dependOn(&runInputMouseWheel.step);
|
||||
|
||||
const runInputMouseWheel = inputMouseWheel.run();
|
||||
const inputMouseWheelStep = b.step("input_mouse_wheel", "Mouse wheel input");
|
||||
inputMouseWheelStep.dependOn(&runInputMouseWheel.step);
|
||||
|
||||
const run2DCamera = twoDCamera.run();
|
||||
const twoDCameraStep = b.step("2d_camera", "Shows the functionality of a 2D camera");
|
||||
twoDCameraStep.dependOn(&run2DCamera.step);
|
||||
|
||||
const runModelsLoading= modelsLoading.run();
|
||||
runModelsLoading.step.dependOn(b.getInstallStep());
|
||||
const modelsLoadingStep = b.step("models_loading", "Loads a model and renders it");
|
||||
modelsLoadingStep.dependOn(&runModelsLoading.step);
|
||||
}
|
||||
|
@ -9,6 +9,14 @@ Examples using raylib core platform functionality like window creation, inputs,
|
||||
| ## | example | developer |
|
||||
|----|----------|:----------:|
|
||||
| 01 | [core_basic_window](core/basic_window.zig) | ray
|
||||
| |
|
||||
| 02 | [core_input_keys](core/input_keys.zig) | ray
|
||||
| |
|
||||
| 04 | [core_input_mouse_wheel](core/input_mouse_wheel.zig) | ray
|
||||
| |
|
||||
| 06 | [core_input_multitouch](core/input_multitouch.zig) | [Berni](https://github.com/Berni8k)
|
||||
| |
|
||||
| 08 | [core_2d_camera](core/2d_camera.zig) | ray
|
||||
|
||||
### category: models
|
||||
|
||||
@ -16,4 +24,4 @@ Examples using raylib models functionality, including models loading/generation
|
||||
|
||||
| ## | example | developer |
|
||||
|----|----------|:----------:|
|
||||
| 74 | [models_loading](models/models_loading.c) ([Won't build](https://github.com/G3bE/raylib-zig#Technical-restrictions)) | ray
|
||||
| 74 | [models_loading](models/models_loading.zig) ([Won't work](https://github.com/G3bE/raylib-zig#Technical-restrictions)) | ray
|
||||
|
134
examples/core/2d_camera.zig
Normal file
134
examples/core/2d_camera.zig
Normal file
@ -0,0 +1,134 @@
|
||||
//
|
||||
// 2d_camera
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-16
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
usingnamespace @import("raylib-math");
|
||||
|
||||
const MAX_BUILDINGS = 100;
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, c"raylib-zig [core] example - 2d camera");
|
||||
|
||||
var player = Rectangle { .x = 400, .y = 280, .width = 40, .height = 40 };
|
||||
var buildings: [MAX_BUILDINGS]Rectangle = undefined;
|
||||
var buildColors: [MAX_BUILDINGS]Color = undefined;
|
||||
|
||||
var spacing: i32 = 0;
|
||||
|
||||
for (buildings) |building, i|
|
||||
{
|
||||
buildings[i].width = @intToFloat(f32, GetRandomValue(50, 200));
|
||||
buildings[i].height = @intToFloat(f32, GetRandomValue(100, 800));
|
||||
buildings[i].y = screenHeight - 130 - buildings[i].height;
|
||||
buildings[i].x = @intToFloat(f32, -6000 + spacing);
|
||||
|
||||
spacing += @floatToInt(i32, buildings[i].width);
|
||||
|
||||
buildColors[i] = Color { .r = @intCast(u8, GetRandomValue(200, 240)), .g = @intCast(u8, GetRandomValue(200, 240)),
|
||||
.b = @intCast(u8, GetRandomValue(200, 250)), .a = 255 };
|
||||
}
|
||||
|
||||
var camera = Camera2D {
|
||||
.target = Vector2 { .x = player.x + 20, .y = player.y + 20 },
|
||||
.offset = Vector2 { .x = screenWidth/2, .y = screenHeight/2 },
|
||||
.rotation = 0,
|
||||
.zoom = 1,
|
||||
};
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Player movement
|
||||
if (IsKeyDown(KeyboardKey.KEY_RIGHT)) { player.x += 2; }
|
||||
else if (IsKeyDown(KeyboardKey.KEY_LEFT)) { player.x -= 2; }
|
||||
|
||||
// Camera target follows player
|
||||
camera.target = Vector2 { .x = player.x + 20, .y = player.y + 20 };
|
||||
|
||||
// Camera rotation controls
|
||||
if (IsKeyDown(KeyboardKey.KEY_A)) { camera.rotation -= 1; }
|
||||
else if (IsKeyDown(KeyboardKey.KEY_S)) { camera.rotation += 1; }
|
||||
|
||||
// Limit camera rotation to 80 degrees (-40 to 40)
|
||||
camera.rotation = Clamp(camera.rotation, -40, 40);
|
||||
|
||||
// Camera zoom controls
|
||||
camera.zoom += @intToFloat(f32, GetMouseWheelMove() * @floatToInt(c_int, 0.05));
|
||||
|
||||
camera.zoom = Clamp(camera.zoom, 0.1, 3.0);
|
||||
|
||||
// Camera reset (zoom and rotation)
|
||||
if (IsKeyPressed(KeyboardKey.KEY_R))
|
||||
{
|
||||
camera.zoom = 1.0;
|
||||
camera.rotation = 0.0;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY);
|
||||
|
||||
for (buildings) |building, i|
|
||||
{
|
||||
//DrawRectangleRec(building, buildColors[i]);
|
||||
DrawRectangle(@floatToInt(c_int, building.x), @floatToInt(c_int, building.y),
|
||||
@floatToInt(c_int, building.width), @floatToInt(c_int, building.height), buildColors[i]);
|
||||
}
|
||||
|
||||
DrawRectangle(@floatToInt(c_int, player.x), @floatToInt(c_int, player.y),
|
||||
@floatToInt(c_int, player.width), @floatToInt(c_int, player.height), DARKGRAY);
|
||||
//DrawRectangleRec(player, RED);
|
||||
|
||||
DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight*10, @floatToInt(c_int, camera.target.x), screenHeight*10, GREEN);
|
||||
DrawLine(-screenWidth*10, @floatToInt(c_int, camera.target.y), screenWidth*10, @floatToInt(c_int, camera.target.y), GREEN);
|
||||
|
||||
EndMode2D();
|
||||
|
||||
DrawText(c"SCREEN AREA", 640, 10, 20, RED);
|
||||
|
||||
DrawRectangle(0, 0, screenWidth, 5, RED);
|
||||
DrawRectangle(0, 5, 5, screenHeight - 10, RED);
|
||||
DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, RED);
|
||||
DrawRectangle(0, screenHeight - 5, screenWidth, 5, RED);
|
||||
|
||||
DrawRectangle( 10, 10, 250, 113, Fade(SKYBLUE, 0.5));
|
||||
DrawRectangleLines( 10, 10, 250, 113, BLUE);
|
||||
|
||||
DrawText(c"Free 2d camera controls:", 20, 20, 10, BLACK);
|
||||
DrawText(c"- Right/Left to move Offset", 40, 40, 10, DARKGRAY);
|
||||
DrawText(c"- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY);
|
||||
DrawText(c"- A / S to Rotate", 40, 80, 10, DARKGRAY);
|
||||
DrawText(c"- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// main
|
||||
// basic_window
|
||||
// Zig version: 0.5.0
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-15
|
||||
|
55
examples/core/input_keys.zig
Normal file
55
examples/core/input_keys.zig
Normal file
@ -0,0 +1,55 @@
|
||||
//
|
||||
// input_keys
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-16
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, c"raylib-zig [core] example - keyboard input");
|
||||
|
||||
var ballPosition = Vector2 { .x = screenWidth/2, .y = screenHeight/2 };
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyDown(KeyboardKey.KEY_RIGHT)) { ballPosition.x += 2.0; }
|
||||
if (IsKeyDown(KeyboardKey.KEY_LEFT)) { ballPosition.x -= 2.0; }
|
||||
if (IsKeyDown(KeyboardKey.KEY_UP)) { ballPosition.y -= 2.0; }
|
||||
if (IsKeyDown(KeyboardKey.KEY_DOWN)) { ballPosition.y += 2.0; }
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText(c"move the ball with arrow keys", 10, 10, 20, DARKGRAY);
|
||||
|
||||
DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, MAROON);
|
||||
//DrawCircleV(ballPosition, 50, MAROON);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
57
examples/core/input_mouse.zig
Normal file
57
examples/core/input_mouse.zig
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// input_mouse
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-16
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, c"raylib-zig [core] example - mouse input");
|
||||
|
||||
var ballPosition = Vector2 { .x = -100.0, .y = -100.0 };
|
||||
var ballColor = DARKBLUE;
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
ballPosition = GetMousePosition();
|
||||
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { ballColor = MAROON; }
|
||||
else if (IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON)) { ballColor = LIME; }
|
||||
else if (IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON)) { ballColor = DARKBLUE; }
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, ballColor);
|
||||
//DrawCircleV(ballPosition, 40, ballColor);
|
||||
|
||||
DrawText(c"move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
53
examples/core/input_mouse_wheel.zig
Normal file
53
examples/core/input_mouse_wheel.zig
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// input_mouse_wheel
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-16
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, c"raylib-zig [core] example - basic window");
|
||||
|
||||
var boxPositionY: i32 = screenHeight / 2 - 40;
|
||||
var scrollSpeed: i32 = 4; // Scrolling speed in pixels
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
boxPositionY -= (GetMouseWheelMove() * scrollSpeed);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(WHITE);
|
||||
|
||||
DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);
|
||||
|
||||
DrawText(c"Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
|
||||
DrawText(FormatText(c"Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
83
examples/core/input_multitouch.zig
Normal file
83
examples/core/input_multitouch.zig
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// input_multitouch
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-16
|
||||
//
|
||||
|
||||
usingnamespace @import("raylib");
|
||||
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, c"raylib-zig [core] example - basic window");
|
||||
|
||||
var ballPosition = Vector2 { .x = -100.0, .y = -100.0 };
|
||||
var ballColor = BEIGE;
|
||||
|
||||
var touchCounter: i32 = 0;
|
||||
var touchPosition = Vector2 { .x = 0.0, .y = 0.0 };
|
||||
|
||||
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
|
||||
//----------------------------------------------------------------------------------
|
||||
ballPosition = GetMousePosition();
|
||||
|
||||
ballColor = BEIGE;
|
||||
|
||||
if (IsMouseButtonDown(MouseButton.MOUSE_LEFT_BUTTON)) { ballColor = MAROON };
|
||||
if (IsMouseButtonDown(MouseButton.MOUSE_MIDDLE_BUTTON)) { ballColor = LIME };
|
||||
if (IsMouseButtonDown(MouseButton.MOUSE_RIGHT_BUTTON)) { ballColor = DARKBLUE };
|
||||
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { touchCounter = 10 };
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON)) { touchCounter = 10 };
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON)) { touchCounter = 10 };
|
||||
|
||||
if (touchCounter > 0) { touchCounter -= 1; };
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Multitouch
|
||||
for (int i = 0; i < MAX_TOUCH_POINTS; ++i)
|
||||
{
|
||||
touchPosition = GetTouchPosition(i); // Get the touch point
|
||||
|
||||
if ((touchPosition.x >= 0) && (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it
|
||||
{
|
||||
// Draw circle and touch index number
|
||||
DrawCircleV(touchPosition, 34, ORANGE);
|
||||
DrawText(FormatText("%d", i), touchPosition.x - 10, touchPosition.y - 70, 40, BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the normal mouse location
|
||||
DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 30 + (touchCounter*3), ballColor);
|
||||
//DrawCircleV(ballPosition, 30 + (touchCounter*3), ballColor);
|
||||
|
||||
DrawText(c"move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
|
||||
DrawText(c"touch the screen at multiple locations to get multiple balls", 10, 30, 20, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// ModelsLoading
|
||||
// models_loading
|
||||
// Zig version:
|
||||
// Author: Nikolas Wipper
|
||||
// Date: 2020-02-15
|
||||
@ -86,14 +86,14 @@ pub fn main() anyerror!void
|
||||
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
// Check collision between ray and box
|
||||
if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds))
|
||||
{
|
||||
selected = !selected;
|
||||
}
|
||||
else
|
||||
{
|
||||
selected = false;
|
||||
}
|
||||
//if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds))
|
||||
//{
|
||||
// selected = !selected;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// selected = false;
|
||||
//}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -105,7 +105,7 @@ pub fn main() anyerror!void
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(model, position, 1.0, WHITE); // Draw 3d model with texture
|
||||
//DrawModel(model, position, 1.0, WHITE); // Draw 3d model with texture
|
||||
|
||||
DrawGrid(20, 10.0); // Draw a grid
|
||||
|
||||
|
@ -7,14 +7,6 @@
|
||||
|
||||
usingnamespace @import("raylib-zig.zig");
|
||||
|
||||
pub const float3 = extern struct {
|
||||
v: [3]f32,
|
||||
};
|
||||
|
||||
pub const float16 = extern struct {
|
||||
v: [16]f32,
|
||||
};
|
||||
|
||||
pub extern fn acosf(arg0: f32) f32;
|
||||
pub extern fn acos(arg0: f64) f64;
|
||||
pub extern fn acosl(arg0: c_longdouble) c_longdouble;
|
||||
@ -228,6 +220,11 @@ pub fn Vector2Distance(v1: Vector2, v2: Vector2) f32 {
|
||||
var result: f32 = sqrtf(((v1.x - v2.x) * (v1.x - v2.x)) + ((v1.y - v2.y) * (v1.y - v2.y)));
|
||||
return result;
|
||||
}
|
||||
pub fn Vector2Angle(v1: Vector2, v2: Vector2) f32 {
|
||||
var result: f32 = atan2f(v2.y - v1.y, v2.x - v1.x) * @divTrunc(180.000000, 3.141593);
|
||||
if (result < @intToFloat(f32, 0)) result += 360.000000;
|
||||
return result;
|
||||
}
|
||||
pub fn Vector2Normalize(v: Vector2) Vector2 {
|
||||
var result: Vector2 = Vector2Divide(v, Vector2Length(v));
|
||||
return result;
|
||||
@ -309,25 +306,6 @@ pub fn MatrixSubtract(left: Matrix, right: Matrix) Matrix {
|
||||
result.m15 = (left.m15 - right.m15);
|
||||
return result;
|
||||
}
|
||||
pub fn MatrixRotateXYZ(ang: Vector3) Matrix {
|
||||
var result: Matrix = MatrixIdentity();
|
||||
var cosz: f32 = cosf(-ang.z);
|
||||
var sinz: f32 = sinf(-ang.z);
|
||||
var cosy: f32 = cosf(-ang.y);
|
||||
var siny: f32 = sinf(-ang.y);
|
||||
var cosx: f32 = cosf(-ang.x);
|
||||
var sinx: f32 = sinf(-ang.x);
|
||||
result.m0 = (cosz * cosy);
|
||||
result.m4 = (((cosz * siny) * sinx) - (sinz * cosx));
|
||||
result.m8 = (((cosz * siny) * cosx) + (sinz * sinx));
|
||||
result.m1 = (sinz * cosy);
|
||||
result.m5 = (((sinz * siny) * sinx) + (cosz * cosx));
|
||||
result.m9 = (((sinz * siny) * cosx) - (cosz * sinx));
|
||||
result.m2 = (-siny);
|
||||
result.m6 = (cosy * sinx);
|
||||
result.m10 = (cosy * cosx);
|
||||
return result;
|
||||
}
|
||||
pub fn MatrixRotateX(angle: f32) Matrix {
|
||||
var result: Matrix = MatrixIdentity();
|
||||
var cosres: f32 = cosf(angle);
|
||||
@ -370,15 +348,10 @@ pub fn QuaternionNlerp(q1: Quaternion, q2: Quaternion, amount: f32) Quaternion {
|
||||
return result;
|
||||
}
|
||||
|
||||
pub const M_PI_2 = 1.570796;
|
||||
pub const M_1_PI = 0.318310;
|
||||
pub const M_2_SQRTPI = 1.128379;
|
||||
pub const M_2_PI = 0.636620;
|
||||
pub const M_PI_4 = 0.785398;
|
||||
pub const M_PI = 3.141593;
|
||||
|
||||
pub const FP_FAST_FMA = 1;
|
||||
|
||||
pub const M_PI_2 = 1.570796;
|
||||
|
||||
pub const M_LOG10E = 0.434294;
|
||||
pub const FP_SUPERNORMAL = 6;
|
||||
pub const FP_SNAN = FP_NAN;
|
||||
@ -389,7 +362,6 @@ pub const SING = 2;
|
||||
pub const FP_INFINITE = 2;
|
||||
pub const FP_QNAN = FP_NAN;
|
||||
pub const PLOSS = 6;
|
||||
pub const FP_ILOGBNAN = if (@typeId(@typeOf(-1)) == @import("builtin").TypeId.Pointer) @ptrCast(-2147483647, -1) else if (@typeId(@typeOf(-1)) == @import("builtin").TypeId.Int) @intToPtr(-2147483647, -1) else (-2147483647)(-1);
|
||||
pub const M_LN2 = 0.693147;
|
||||
pub const MATH_ERRNO = 1;
|
||||
pub const FP_ZERO = 3;
|
||||
@ -398,7 +370,6 @@ pub const UNDERFLOW = 4;
|
||||
pub const DOMAIN = 1;
|
||||
pub const FP_SUBNORMAL = 5;
|
||||
pub const X_TLOSS = 14148475504056880.000000;
|
||||
pub const FP_ILOGB0 = if (@typeId(@typeOf(-1)) == @import("builtin").TypeId.Pointer) @ptrCast(-2147483647, -1) else if (@typeId(@typeOf(-1)) == @import("builtin").TypeId.Int) @intToPtr(-2147483647, -1) else (-2147483647)(-1);
|
||||
pub const MATH_ERREXCEPT = 2;
|
||||
pub const FP_NAN = 1;
|
||||
pub const M_SQRT2 = 1.414214;
|
||||
|
@ -682,12 +682,12 @@ pub extern fn GetFileModTime(fileName: [*c]const u8) c_long;
|
||||
pub extern fn StorageSaveValue(position: c_int, value: c_int) void;
|
||||
pub extern fn StorageLoadValue(position: c_int) c_int;
|
||||
pub extern fn OpenURL(url: [*c]const u8) void;
|
||||
pub extern fn IsKeyPressed(key: c_int) bool;
|
||||
pub extern fn IsKeyDown(key: c_int) bool;
|
||||
pub extern fn IsKeyReleased(key: c_int) bool;
|
||||
pub extern fn IsKeyUp(key: c_int) bool;
|
||||
pub extern fn GetKeyPressed() c_int;
|
||||
pub extern fn SetExitKey(key: c_int) void;
|
||||
pub extern fn IsKeyPressed(key: KeyboardKey) bool;
|
||||
pub extern fn IsKeyDown(key: KeyboardKey) bool;
|
||||
pub extern fn IsKeyReleased(key: KeyboardKey) bool;
|
||||
pub extern fn IsKeyUp(key: KeyboardKey) bool;
|
||||
pub extern fn GetKeyPressed() KeyboardKey;
|
||||
pub extern fn SetExitKey(key: KeyboardKey) void;
|
||||
pub extern fn IsGamepadAvailable(gamepad: c_int) bool;
|
||||
pub extern fn IsGamepadName(gamepad: c_int, name: [*c]const u8) bool;
|
||||
pub extern fn GetGamepadName(gamepad: c_int) [*c]const u8;
|
||||
@ -1009,12 +1009,14 @@ pub const MAP_DIFFUSE = MaterialMapType.MAP_ALBEDO;
|
||||
pub const MAP_SPECULAR = MaterialMapType.MAP_METALNESS;
|
||||
pub const LOC_MAP_SPECULAR = LOC_MAP_METALNESS;
|
||||
pub const LOC_MAP_DIFFUSE = LOC_MAP_ALBEDO;
|
||||
|
||||
pub const MAX_TOUCH_POINTS = 10;
|
||||
pub const ShowWindow = UnhideWindow;
|
||||
pub const FormatText = TextFormat;
|
||||
pub const PI = 3.141593;
|
||||
pub const CLITERAL = Color;
|
||||
pub const MAX_MATERIAL_MAPS = 12;
|
||||
pub const MAX_SHADER_LOCATIONS = 32;
|
||||
|
||||
pub const PI = 3.141593;
|
||||
|
||||
pub const SpriteFont = Font;
|
||||
pub const SubText = TextSubtext;
|
||||
pub const MAX_MATERIAL_MAPS = 12;
|
||||
pub const ShowWindow = UnhideWindow;
|
||||
pub const FormatText = TextFormat;
|
||||
|
Loading…
x
Reference in New Issue
Block a user