Merge branch 'devel' of https://github.com/Not-Nik/raylib-zig into devel

Local pull, I'm sorry
This commit is contained in:
Not-Nik 2021-07-25 02:19:11 +02:00
commit a8d8d4b9bc

View File

@ -7,8 +7,9 @@
usingnamespace @import("raylib"); usingnamespace @import("raylib");
pub fn main() anyerror!void const resourceDir = "raylib/examples/models/resources/";
{
pub fn main() anyerror!void {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const screenWidth = 800; const screenWidth = 800;
@ -17,19 +18,19 @@ pub fn main() anyerror!void
InitWindow(screenWidth, screenHeight, "raylib [models] example - models loading"); InitWindow(screenWidth, screenHeight, "raylib [models] example - models loading");
// Define the camera to look into our 3d world // Define the camera to look into our 3d world
var camera = Camera { var camera = Camera{
.position = Vector3 { .x = 50.0, .y = 50.0, .z = 50.0 }, // Camera position .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 .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) .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 .fovy = 45.0, // Camera field-of-view Y
.type = CameraType.CAMERA_PERSPECTIVE // Camera mode type .type = CameraType.CAMERA_PERSPECTIVE, // Camera mode type
}; };
var model = LoadModel("resources/models/castle.obj"); // Load model var model = LoadModel(resourceDir ++ "models/castle.obj"); // Load model
var texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture var texture = LoadTexture(resourceDir ++ "models/castle_diffuse.png"); // Load model texture
model.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture; // Set map diffuse texture model.materials[0].maps[@enumToInt(MAP_DIFFUSE)].texture = texture; // Set map diffuse texture
//var position = Vector3 { .x = 0.0, .y = 0.0, .z = 0.0 }; // Set model position var position = Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }; // Set model position
var bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds var bounds = MeshBoundingBox(model.meshes[0]); // Set model bounds
@ -51,8 +52,7 @@ pub fn main() anyerror!void
camera.Update(); camera.Update();
// Load new models/textures on drag&drop // Load new models/textures on drag&drop
if (IsFileDropped()) if (IsFileDropped()) {
{
var count: c_int = 0; var count: c_int = 0;
var droppedFiles = GetDroppedFiles(&count); var droppedFiles = GetDroppedFiles(&count);
@ -69,8 +69,7 @@ pub fn main() anyerror!void
bounds = MeshBoundingBox(model.meshes[0]); bounds = MeshBoundingBox(model.meshes[0]);
// TODO: Move camera position from target enough distance to visualize model properly // TODO: Move camera position from target enough distance to visualize model properly
} } else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
else if (IsFileExtension(droppedFiles[0], ".png")) // Texture file formats supported
{ {
// Unload current model texture and load new one // Unload current model texture and load new one
UnloadTexture(texture); UnloadTexture(texture);
@ -83,17 +82,13 @@ pub fn main() anyerror!void
} }
// Select model on mouse click // Select model on mouse click
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) {
{
// Check collision between ray and box // Check collision between ray and box
//if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) if (CheckCollisionRayBox(GetMouseRay(GetMousePosition(), camera), bounds)) {
//{ selected = !selected;
// selected = !selected; } else {
//} selected = false;
//else }
//{
// selected = false;
//}
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -105,7 +100,7 @@ pub fn main() anyerror!void
camera.Begin(); camera.Begin();
//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 DrawGrid(20, 10.0); // Draw a grid