forked from deltaphc/raylib-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
2,228 additions
and
1,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
pub mod models_animation; | ||
pub mod models_billboard; | ||
pub mod models_box_collisions; | ||
pub mod models_cubicmap; | ||
pub mod models_first_person_maze; | ||
pub mod models_geometric_shapes; | ||
pub mod models_heightmap; | ||
pub mod models_loading; | ||
pub mod models_material_pbr; | ||
pub mod models_mesh_generation; | ||
pub mod models_mesh_picking; | ||
pub mod models_orthographic_projection; | ||
pub mod models_rlgl_solar_system; | ||
pub mod models_skybox; | ||
pub mod models_waving_cubes; | ||
pub mod models_yaw_pitch_roll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************************* | ||
* | ||
* raylib [models] example - Drawing billboards | ||
* | ||
* This example has been created using raylib 1.3 (www.raylib.com) | ||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | ||
* | ||
* Copyright (c) 2015 Ramon Santamaria (@raysan5) | ||
* | ||
********************************************************************************************/ | ||
|
||
pub use raylib::prelude::*; | ||
|
||
pub fn run(rl: &mut RaylibHandle, thread: &RaylibThread) -> crate::SampleOut { | ||
// Initialization | ||
//-------------------------------------------------------------------------------------- | ||
let screen_width = 800; | ||
let screen_height = 450; | ||
|
||
rl.set_window_title(thread, "raylib [models] example - drawing billboards"); | ||
rl.set_window_size(screen_width, screen_height); | ||
|
||
// Define the camera to look into our 3d world | ||
let mut camera = Camera3D::perspective( | ||
rvec3(5.0, 4.0, 5.0), | ||
rvec3(0.0, 2.0, 0.0), | ||
rvec3(0.0, 1.0, 0.0), | ||
45.0, | ||
); | ||
|
||
let bill = rl.load_texture(thread, "original/models/resources/billboard.png").unwrap(); // Our texture billboard | ||
let billPosition = rvec3(0.0, 2.0, 0.0); // Position where draw billboard | ||
|
||
rl.set_camera_mode(&camera, raylib::consts::CameraMode::CAMERA_ORBITAL); // Set an orbital camera mode | ||
|
||
rl.set_target_fps(60); // Set our game to run at 60 frames-per-second | ||
//-------------------------------------------------------------------------------------- | ||
|
||
// Main game loop | ||
return Box::new(move |rl: &mut RaylibHandle, thread: &RaylibThread| -> () | ||
// Detect window close button or ESC key | ||
{ | ||
// Update | ||
//---------------------------------------------------------------------------------- | ||
rl.update_camera(&mut camera); // Update camera | ||
//---------------------------------------------------------------------------------- | ||
|
||
// Draw | ||
//---------------------------------------------------------------------------------- | ||
let mut d = rl.begin_drawing(thread); | ||
|
||
d.clear_background(Color::RAYWHITE); | ||
|
||
{ | ||
|
||
let mut d = d.begin_mode3D(&camera); | ||
|
||
d.draw_grid(10, 1.0); // Draw a grid | ||
|
||
d.draw_billboard(&camera, &bill, billPosition, 2.0, Color::WHITE); | ||
} | ||
|
||
|
||
|
||
d.draw_fps(10, 10); | ||
|
||
//---------------------------------------------------------------------------------- | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/******************************************************************************************* | ||
* | ||
* raylib [models] example - Detect basic 3d collisions (box vs sphere vs box) | ||
* | ||
* This example has been created using raylib 1.3 (www.raylib.com) | ||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | ||
* | ||
* Copyright (c) 2015 Ramon Santamaria (@raysan5) | ||
* | ||
********************************************************************************************/ | ||
|
||
pub use raylib::prelude::*; | ||
|
||
pub fn run(rl: &mut RaylibHandle, thread: &RaylibThread) -> crate::SampleOut | ||
{ | ||
// Initialization | ||
//-------------------------------------------------------------------------------------- | ||
let screen_width = 800; | ||
let screen_height = 450; | ||
|
||
rl.set_window_title(thread, "raylib [models] example - box collisions"); | ||
rl.set_window_size(screen_width, screen_height); | ||
|
||
// Define the camera to look into our 3d world | ||
let camera = Camera::perspective( rvec3( 0.0, 10.0, 10.0 ), rvec3( 0.0, 0.0, 0.0 ), rvec3( 0.0, 1.0, 0.0 ), 45.0 ); | ||
|
||
let mut playerPosition = rvec3( 0.0, 1.0, 2.0 ); | ||
let playerSize = rvec3( 1.0, 2.0, 1.0 ); | ||
let mut playerColor = Color::GREEN; | ||
|
||
let enemyBoxPos = rvec3( -4.0, 1.0, 0.0 ); | ||
let enemyBoxSize = rvec3( 2.0, 2.0, 2.0 ); | ||
|
||
let enemySpherePos = rvec3( 4.0, 0.0, 0.0 ); | ||
let enemySphereSize = 1.5; | ||
|
||
let mut collision = false; | ||
|
||
rl.set_target_fps(60); // Set our game to run at 60 frames-per-second | ||
//-------------------------------------------------------------------------------------- | ||
|
||
// Main game loop | ||
return Box::new(move |rl: &mut RaylibHandle, thread: &RaylibThread| -> () // Detect window close button or ESC key | ||
{ | ||
// Update | ||
//---------------------------------------------------------------------------------- | ||
|
||
// Move player | ||
if (rl.is_key_down(raylib::consts::KeyboardKey::KEY_RIGHT)){ playerPosition.x += 0.2;} | ||
else if (rl.is_key_down(raylib::consts::KeyboardKey::KEY_LEFT)) {playerPosition.x -= 0.2;} | ||
else if (rl.is_key_down(raylib::consts::KeyboardKey::KEY_DOWN)) {playerPosition.z += 0.2;} | ||
else if (rl.is_key_down(raylib::consts::KeyboardKey::KEY_UP)){ playerPosition.z -= 0.2;} | ||
|
||
collision = false; | ||
|
||
// Check collisions player vs enemy-box | ||
if | ||
BoundingBox::new(rvec3( playerPosition.x - playerSize.x/2.0, | ||
playerPosition.y - playerSize.y/2.0, | ||
playerPosition.z - playerSize.z/2.0 ), | ||
rvec3( playerPosition.x + playerSize.x/2.0, | ||
playerPosition.y + playerSize.y/2.0, | ||
playerPosition.z + playerSize.z/2.0 )).check_collision_boxes( | ||
BoundingBox::new(rvec3( enemyBoxPos.x - enemyBoxSize.x/2.0, | ||
enemyBoxPos.y - enemyBoxSize.y/2.0, | ||
enemyBoxPos.z - enemyBoxSize.z/2.0 ), | ||
rvec3( enemyBoxPos.x + enemyBoxSize.x/2.0, | ||
enemyBoxPos.y + enemyBoxSize.y/2.0, | ||
enemyBoxPos.z + enemyBoxSize.z/2.0 ))) {collision = true;} | ||
|
||
// Check collisions player vs enemy-sphere | ||
if | ||
BoundingBox::new(rvec3( playerPosition.x - playerSize.x/2.0, | ||
playerPosition.y - playerSize.y/2.0, | ||
playerPosition.z - playerSize.z/2.0 ), | ||
rvec3( playerPosition.x + playerSize.x/2.0, | ||
playerPosition.y + playerSize.y/2.0, | ||
playerPosition.z + playerSize.z/2.0 )).check_collision_box_sphere( | ||
enemySpherePos, enemySphereSize) {collision = true;} | ||
|
||
if (collision){ playerColor = Color::RED;} | ||
else {playerColor = Color::GREEN;} | ||
//---------------------------------------------------------------------------------- | ||
|
||
// Draw | ||
//---------------------------------------------------------------------------------- | ||
let mut d = rl.begin_drawing(thread); | ||
|
||
d.clear_background(Color::RAYWHITE); | ||
|
||
{ | ||
|
||
let mut d = d.begin_mode3D(&camera); | ||
|
||
// Draw enemy-box | ||
d.draw_cube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, Color::GRAY); | ||
d.draw_cube_wires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, Color::DARKGRAY); | ||
|
||
// Draw enemy-sphere | ||
d.draw_sphere(enemySpherePos, enemySphereSize, Color::GRAY); | ||
d.draw_sphere_wires(enemySpherePos, enemySphereSize, 16, 16, Color::DARKGRAY); | ||
|
||
// Draw player | ||
d.draw_cube_v(playerPosition, playerSize, playerColor); | ||
|
||
d.draw_grid(10, 1.0); // Draw a grid | ||
} | ||
|
||
d.draw_text("Move player with cursors to collide", 220, 40, 20, Color::GRAY); | ||
|
||
d.draw_fps(10, 10); | ||
|
||
//---------------------------------------------------------------------------------- | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/******************************************************************************************* | ||
* | ||
* raylib [models] example - Cubicmap loading and drawing | ||
* | ||
* This example has been created using raylib 1.8 (www.raylib.com) | ||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | ||
* | ||
* Copyright (c) 2015 Ramon Santamaria (@raysan5) | ||
* | ||
********************************************************************************************/ | ||
|
||
pub use raylib::prelude::*; | ||
|
||
pub fn run(rl: &mut RaylibHandle, thread: &RaylibThread) -> crate::SampleOut { | ||
// Initialization | ||
//-------------------------------------------------------------------------------------- | ||
let screen_width = 800; | ||
let screen_height = 450; | ||
|
||
rl.set_window_title( | ||
thread, | ||
"raylib [models] example - cubesmap loading and drawing", | ||
); | ||
rl.set_window_size(screen_width, screen_height); | ||
|
||
// Define the camera to look into our 3d world | ||
let mut camera = Camera3D::perspective( | ||
rvec3(16.0, 14.0, 16.0), | ||
rvec3(0.0, 0.0, 0.0), | ||
rvec3(0.0, 1.0, 0.0), | ||
45.0, | ||
); | ||
|
||
let image = Image::load_image("original/models/resources/cubicmap.png").unwrap(); // Load cubicmap image (RAM) | ||
let cubicmap = rl.load_texture_from_image(thread, &image).unwrap(); // Convert image to texture to display (VRAM) | ||
|
||
// Because model depends on mesh, we have to make sure mesh lives as long as the model. We make it weak | ||
// to manually control it's lifespan. | ||
let mesh = unsafe { Mesh::gen_mesh_cubicmap(thread, &image, rvec3(1.0, 1.0, 1.0)).make_weak() }; | ||
let mut model = rl.load_model_from_mesh(thread, mesh.clone()).unwrap(); | ||
|
||
// NOTE: By default each cube is mapped to one part of texture atlas | ||
// make texture weak so it lives as long as the model | ||
let texture = unsafe { | ||
rl | ||
.load_texture(thread, "original/models/resources/cubicmap_atlas.png") | ||
.unwrap().make_weak() // Load map texture | ||
|
||
}; | ||
model.materials_mut()[0].maps_mut()[raylib::consts::MaterialMapType::MAP_ALBEDO as usize] | ||
.texture = *texture.as_ref(); // Set map diffuse texture | ||
let mapPosition = rvec3(-16.0, 0.0, -8.0); // Set model position | ||
|
||
rl.set_camera_mode(&camera, raylib::consts::CameraMode::CAMERA_ORBITAL); // Set an orbital camera mode | ||
|
||
rl.set_target_fps(60); // Set our game to run at 60 frames-per-second | ||
//-------------------------------------------------------------------------------------- | ||
|
||
// Main game loop | ||
return Box::new( | ||
move |rl: &mut RaylibHandle, thread: &RaylibThread| -> () // Detect window close button or ESC key | ||
{ | ||
// Update | ||
//---------------------------------------------------------------------------------- | ||
rl.update_camera(&mut camera); // Update camera | ||
//---------------------------------------------------------------------------------- | ||
|
||
{ | ||
// Draw | ||
//---------------------------------------------------------------------------------- | ||
let mut d = rl.begin_drawing(thread); | ||
|
||
d.clear_background(Color::RAYWHITE); | ||
|
||
{ | ||
let mut d = d.begin_mode3D(&camera); | ||
|
||
d.draw_model(&model, mapPosition, 1.0, Color::WHITE); | ||
|
||
} | ||
|
||
|
||
d.draw_texture_ex(&cubicmap, rvec2( screen_width - cubicmap.width*4 - 20, 20 ), 0.0, 4.0, Color::WHITE); | ||
d.draw_rectangle_lines(screen_width - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, Color::GREEN); | ||
|
||
d.draw_text("cubicmap image used to", 658, 90, 10, Color::GRAY); | ||
d.draw_text("generate map 3d model", 658, 104, 10, Color::GRAY); | ||
|
||
d.draw_fps(10, 10); | ||
|
||
//---------------------------------------------------------------------------------- | ||
} | ||
if rl.is_key_pressed(crate::EXIT_KEY) { | ||
unsafe { | ||
rl.unload_texture(thread, texture.clone()); | ||
// Don't need to unload mesh because the model will. | ||
// rl.unload_mesh(thread, mesh.clone()); | ||
} | ||
} | ||
}, | ||
); | ||
} |
Oops, something went wrong.