Watch
3
0
Fork
You've already forked raylib-cs
0

Porting examples

- Test.Common now used for Examples project.
- Testing examples alot.
This commit is contained in:
Chris 2018-10-22 16:10:20 +01:00
commit 6a02bb9d08
97 changed files with 516 additions and 366 deletions

1
.gitignore vendored
View file

@ -31,7 +31,6 @@ bld/
[Dd]ebug [Dd]ebug
[Oo]bj/ [Oo]bj/
[Ll]og/ [Ll]og/
[Ee]xamples/
# Visual Studio 2015 cache/options directory # Visual Studio 2015 cache/options directory
.vs/ .vs/

View file

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>36e54e2a-5899-4d4d-9d78-120db1b4c7b2</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Test.Common</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)audio\audio_module_playing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)audio\audio_music_stream.cs" />
<Compile Include="$(MSBuildThisFileDirectory)audio\audio_raw_stream.cs" />
<Compile Include="$(MSBuildThisFileDirectory)audio\audio_sound_loading.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_2d_camera.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_3d_camera_first_person.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_3d_camera_free.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_3d_mode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_3d_picking.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_basic_window.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_color_select.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_drop_files.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_gestures_detection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_input_gamepad.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_input_keys.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_input_mouse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_mouse_wheel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_random_values.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_storage_values.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_vr_simulator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)core\core_world_screen.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_billboard.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_box_collisions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_cubicmap.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_geometric_shapes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_heightmap.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_material_pbr.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_mesh_generation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_mesh_picking.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_obj_loading.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_orthographic_projection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_skybox.cs" />
<Compile Include="$(MSBuildThisFileDirectory)models\models_yaw_pitch_roll.cs" />
<Compile Include="$(MSBuildThisFileDirectory)others\bunnymark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)physac\physics_demo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)physac\physics_friction.cs" />
<Compile Include="$(MSBuildThisFileDirectory)physac\physics_movement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)physac\physics_restitution.cs" />
<Compile Include="$(MSBuildThisFileDirectory)physac\physics_shatter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shaders\shaders_custom_uniform.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shaders\shaders_model_shader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shaders\shaders_postprocessing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shaders\shaders_shapes_textures.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shapes\shapes_basic_shapes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shapes\shapes_colors_palette.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shapes\shapes_lines_bezier.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shapes\shapes_logo_raylib.cs" />
<Compile Include="$(MSBuildThisFileDirectory)shapes\shapes_logo_raylib_anim.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_image_drawing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_image_generation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_image_loading.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_image_processing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_image_text.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_logo_raylib.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_particles_blending.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_raw_data.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_rectangle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_srcrec_dstrec.cs" />
<Compile Include="$(MSBuildThisFileDirectory)textures\textures_to_image.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_bmfont_ttf.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_bmfont_unordered.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_font_sdf.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_format_text.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_input_box.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_raylib_fonts.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_sprite_fonts.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_ttf_loading.cs" />
<Compile Include="$(MSBuildThisFileDirectory)text\text_writing_anim.cs" />
</ItemGroup>
</Project>

13
Examples/Examples.shproj Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>36e54e2a-5899-4d4d-9d78-120db1b4c7b2</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Examples.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

View file

@ -1,102 +0,0 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static Raylib.Raylib;
namespace Raylib
{
public partial class RayForms : Form
{
private Panel gamePanel;
private bool windowAttached = false;
#region WinAPI Entry Points
[DllImport("user32.dll")]
private static extern IntPtr SetWindowPos(IntPtr handle, IntPtr handleAfter, int x, int y, int cx, int cy, uint flags);
[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr child, IntPtr newParent);
[DllImport("user32.dll")]
private static extern IntPtr ShowWindow(IntPtr handle, int command);
#endregion
public RayForms()
{
Size = new Size(1024, 700);
Text = "Rayforms";
gamePanel = new Panel();
gamePanel.Size = new Size(800, 500);
gamePanel.Location = new Point(50, 50);
Button button = new Button();
button.Text = "Attach window";
button.Size = new Size(150, 20);
button.Location = new Point(
(Size.Width / 2) - (button.Size.Width / 2),
gamePanel.Location.Y + gamePanel.Size.Height + 10
);
button.Click += new EventHandler(ClickedButton);
Controls.Add(button);
Controls.Add(gamePanel);
}
private void ClickedButton(object sender, EventArgs e)
{
if (!windowAttached)
{
// new Thread(Test).Start();
Test();
}
}
private void Test()
{
SetConfigFlags((int)Flag.WINDOW_UNDECORATED);
InitWindow(800, 480, "Rayforms test");
SetTargetFPS(60);
IntPtr winHandle = GetWindowHandle();
Invoke(new Action(() =>
{
SetWindowPos(winHandle, Handle, 0, 0, 0, 0, 0x0401 /*NOSIZE | SHOWWINDOW */);
SetParent(winHandle, gamePanel.Handle);
ShowWindow(winHandle, 1);
windowAttached = true;
}));
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON);
DrawText(GetFrameTime().ToString(), 100, 10, 15, MAROON);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
CloseWindow();
}
public static void Run()
{
Application.Run(new RayForms());
}
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
public partial class Examples public partial class audio_music_stream
{ {
/******************************************************************************************* * * raylib [audio] example - IntPtr playing (streaming) * * NOTE: This example requires OpenAL Soft library installed * * 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) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); InitAudioDevice(); // Initialize audio device IntPtr music = LoadMusicStream("resources/guitar_noodling.ogg"); PlayMusicStream(music); float timePlayed = 0.0f; bool pause = false; 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 //---------------------------------------------------------------------------------- UpdateMusicStream(music); // Update music buffer with new stream data // Restart music playing (stop and play) if (IsKeyPressed((int)Key.SPACE)) { StopMusicStream(music); PlayMusicStream(music); } // Pause/Resume music playing if (IsKeyPressed((int)Key.P)) { pause = !pause; if (pause) PauseMusicStream(music); else ResumeMusicStream(music); } // Get timePlayed scaled to bar dimensions (400 pixels) timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); DrawRectangle(200, 200, 400, 12, LIGHTGRAY); DrawRectangle(200, 200, (int)timePlayed, 12, MAROON); DrawRectangleLines(200, 200, 400, 12, GRAY); DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY); DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadMusicStream(music); // Unload music stream buffers from RAM CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [audio] example - IntPtr playing (streaming) * * NOTE: This example requires OpenAL Soft library installed * * 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) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); InitAudioDevice(); // Initialize audio device var music = LoadMusicStream("resources/guitar_noodling.ogg"); PlayMusicStream(music); float timePlayed = 0.0f; bool pause = false; 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 //---------------------------------------------------------------------------------- UpdateMusicStream(music); // Update music buffer with new stream data // Restart music playing (stop and play) if (IsKeyPressed(KEY_SPACE)) { StopMusicStream(music); PlayMusicStream(music); } // Pause/Resume music playing if (IsKeyPressed(KEY_P)) { pause = !pause; if (pause) PauseMusicStream(music); else ResumeMusicStream(music); } // Get timePlayed scaled to bar dimensions (400 pixels) timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); DrawRectangle(200, 200, 400, 12, LIGHTGRAY); DrawRectangle(200, 200, (int)timePlayed, 12, MAROON); DrawRectangleLines(200, 200, 400, 12, GRAY); DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY); DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadMusicStream(music); // Unload music stream buffers from RAM CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1,7 +1,11 @@
using Raylib; using System;
using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
public partial class Examples public partial class audio_raw_stream
{ {
/******************************************************************************************* * * raylib [audio] example - Raw audio streaming * * NOTE: This example requires OpenAL Soft library installed * * This example has been created using raylib 1.6 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2015 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public const #define MAX_SAMPLES 22050 public const #define MAX_SAMPLES_PER_UPDATE 4096 public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming"); InitAudioDevice(); // Initialize audio device // Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) AudioStream stream = InitAudioStream(22050, 16, 1); // Generate samples data from sine wave short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES); // TODO: Review data generation, it seems data is discontinued for loop, // for that reason, there is a clip everytime audio stream is looped... for (int i = 0; i < MAX_SAMPLES; i++) { data[i] = (short)(sinf(((2*PI*(float)i)/2)*DEG2RAD)*32000); } PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently) int totalSamples = MAX_SAMPLES; int samplesLeft = totalSamples; Vector2 position = { 0, 0 }; SetTargetFPS(30); // Set our game to run at 30 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // Refill audio stream if required // NOTE: Every update we check if stream data has been already consumed and we update // buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE), // but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data... if (IsAudioBufferProcessed(stream)) { int numSamples = 0; if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE; else numSamples = samplesLeft; UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples); samplesLeft -= numSamples; // Reset samples feeding (loop audio) if (samplesLeft <= 0) samplesLeft = totalSamples; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY); // NOTE: Draw a part of the sine wave (only screen width, proportional values) for (int i = 0; i < GetScreenWidth(); i++) { position.x = i; position.y = 250 + 50*data[i]/32000; DrawPixelV(position, RED); } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- free(data); // Unload sine wave data CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [audio] example - Raw audio streaming * * NOTE: This example requires OpenAL Soft library installed * * This example has been created using raylib 1.6 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2015 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public const int MAX_SAMPLES = 22050; public const int MAX_SAMPLES_PER_UPDATE = 4096; public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming"); InitAudioDevice(); // Initialize audio device // Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) AudioStream stream = InitAudioStream(22050, 16, 1);
// Generate samples data from sine wave
short[] data = new short[MAX_SAMPLES]; //short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES); // TODO: Review data generation, it seems data is discontinued for loop, // for that reason, there is a clip everytime audio stream is looped... for (int i = 0; i < MAX_SAMPLES; i++) { data[i] = (short)(Math.Sin(((2*Math.PI*(float)i)/2)*DEG2RAD)*32000); } PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently) int totalSamples = MAX_SAMPLES; int samplesLeft = totalSamples; Vector2 position = new Vector2( 0, 0 ); SetTargetFPS(30); // Set our game to run at 30 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // Refill audio stream if required // NOTE: Every update we check if stream data has been already consumed and we update // buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE), // but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data... if (IsAudioBufferProcessed(stream)) { int numSamples = 0; if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE; else numSamples = samplesLeft; // UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples); samplesLeft -= numSamples; // Reset samples feeding (loop audio) if (samplesLeft <= 0) samplesLeft = totalSamples; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY); // NOTE: Draw a part of the sine wave (only screen width, proportional values) for (int i = 0; i < GetScreenWidth(); i++) { position.x = i; position.y = 250 + 50*data[i]/32000; DrawPixelV(position, RED); } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- // free(data); // Unload sine wave data CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1,7 +1,7 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
public partial class Examples public partial class audio_sound_loading
{ {
/******************************************************************************************* * * raylib [audio] example - Sound loading and playing * * NOTE: This example requires OpenAL Soft library installed * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing"); InitAudioDevice(); // Initialize audio device Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed((int)Key.SPACE)) PlaySound(fxWav); // Play WAV sound if (IsKeyPressed((int)Key.ENTER)) PlaySound(fxOgg); // Play OGG sound //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadSound(fxWav); // Unload sound data UnloadSound(fxOgg); // Unload sound data CloseAudioDevice(); // Close audio device CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [audio] example - Sound loading and playing * * NOTE: This example requires OpenAL Soft library installed * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing"); InitAudioDevice(); // Initialize audio device Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadSound(fxWav); // Unload sound data UnloadSound(fxOgg); // Unload sound data CloseAudioDevice(); // Close audio device CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,9 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
using static Raylib.CameraType;
using static Raylib.CameraMode;
public partial class Examples public partial class core_3d_camera_first_person
{ {
/******************************************************************************************* * * raylib [core] example - 3d camera first person * * 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) * ********************************************************************************************/ public const #define MAX_COLUMNS 20 public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); // Define the camera to look into our 3d world (position, target, up vector) Camera camera = { 0 }; camera.position = new Vector3( 4.0f, 2.0f, 4.0f );; camera.target = new Vector3( 0.0f, 1.8f, 0.0f );; camera.up = new Vector3( 0.0f, 1.0f, 0.0f );; camera.fovy = 60.0f; camera.type = CAMERA_PERSPECTIVE; // Generates some random columns float[] heights = new float[MAX_COLUMNS]; Vector3[] positions = new Vector3[MAX_COLUMNS]; Color[] colors = new Color[MAX_COLUMNS]; for (int i = 0; i < MAX_COLUMNS; i++) { heights[i] = (float)GetRandomValue(1, 12); positions[i] = new Vector3( GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) );; colors[i] = new Color( GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 );; } SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode 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 //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); DrawPlane(new Vector3( 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f );, LIGHTGRAY); // Draw ground DrawCube(new Vector3( -16.0f, 2.5f, 0.0f );, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall DrawCube(new Vector3( 16.0f, 2.5f, 0.0f );, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall DrawCube(new Vector3( 0.0f, 2.5f, 16.0f );, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall // Draw some cubes around for (int i = 0; i < MAX_COLUMNS; i++) { DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]); DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON); } EndMode3D(); DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 220, 70, BLUE); DrawText("First person camera default controls:", 20, 20, 10, BLACK); DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [core] example - 3d camera first person * * 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) * ********************************************************************************************/ public const int MAX_COLUMNS = 20; public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); // Define the camera to look into our 3d world (position, target, up vector) Camera3D camera = new Camera3D(); camera.position = new Vector3( 4.0f, 2.0f, 4.0f ); camera.target = new Vector3( 0.0f, 1.8f, 0.0f ); camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); camera.fovy = 60.0f; camera.type = (int)CAMERA_PERSPECTIVE; // Generates some random columns float[] heights = new float[MAX_COLUMNS]; Vector3[] positions = new Vector3[MAX_COLUMNS]; Color[] colors = new Color[MAX_COLUMNS]; for (int i = 0; i < MAX_COLUMNS; i++) { heights[i] = (float)GetRandomValue(1, 12); positions[i] = new Vector3( GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) ); colors[i] = new Color( GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 ); } SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode 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 //---------------------------------------------------------------------------------- UpdateCamera(ref camera); // Update camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); DrawPlane(new Vector3( 0.0f, 0.0f, 0.0f ), new Vector2( 32.0f, 32.0f ), LIGHTGRAY); // Draw ground DrawCube(new Vector3( -16.0f, 2.5f, 0.0f ), 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall DrawCube(new Vector3( 16.0f, 2.5f, 0.0f ), 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall DrawCube(new Vector3( 0.0f, 2.5f, 16.0f ), 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall // Draw some cubes around for (int i = 0; i < MAX_COLUMNS; i++) { DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]); DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON); } EndMode3D(); DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 220, 70, BLUE); DrawText("First person camera default controls:", 20, 20, 10, BLACK); DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1,7 +1,9 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
using static Raylib.CameraType;
using static Raylib.CameraMode;
public partial class Examples public partial class core_3d_camera_free
{ {
/******************************************************************************************* * * raylib [core] example - Initialize 3d camera free * * 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) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world Camera3D camera; camera.position = new Vector3( 10.0f, 10.0f, 10.0f );; // Camera position camera.target = new Vector3( 0.0f, 0.0f, 0.0f );; // Camera looking at point camera.up = new Vector3( 0.0f, 1.0f, 0.0f );; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y camera.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode 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 //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera if (IsKeyDown('Z')) camera.target = new Vector3( 0.0f, 0.0f, 0.0f );; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); EndMode3D(); DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 320, 133, BLUE); DrawText("Free camera default controls:", 20, 20, 10, BLACK); DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY); DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY); DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY); DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY); DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [core] example - Initialize 3d camera free * * 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) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world Camera3D camera; camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); // Camera3D position camera.target = new Vector3( 0.0f, 0.0f, 0.0f ); // Camera3D looking at point camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target) camera.fovy = 45.0f; // Camera3D field-of-view Y camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f ); SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode 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 //---------------------------------------------------------------------------------- UpdateCamera(ref camera); // Update camera if (IsKeyDown('Z')) camera.target = new Vector3( 0.0f, 0.0f, 0.0f ); //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); EndMode3D(); DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 320, 133, BLUE); DrawText("Free camera default controls:", 20, 20, 10, BLACK); DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY); DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY); DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY); DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY); DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1,7 +1,8 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
using static Raylib.CameraType;
public partial class Examples public partial class core_3d_mode
{ {
/******************************************************************************************* * * raylib [core] example - Initialize 3d mode * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode"); // Define the camera to look into our 3d world Camera3D camera; camera.position = new Vector3( 0.0f, 10.0f, 10.0f );; // Camera position camera.target = new Vector3( 0.0f, 0.0f, 0.0f );; // Camera looking at point camera.up = new Vector3( 0.0f, 1.0f, 0.0f );; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y camera.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; 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(RAYWHITE); BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); EndMode3D(); DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [core] example - Initialize 3d mode * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode"); // Define the camera to look into our 3d world Camera3D camera; camera.position = new Vector3( 0.0f, 10.0f, 10.0f ); // Camera3D position camera.target = new Vector3( 0.0f, 0.0f, 0.0f ); // Camera3D looking at point camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target) camera.fovy = 45.0f; // Camera3D field-of-view Y camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type Vector3 cubePosition = new Vector3( 0.0f, 0.0f, 0.0f ); 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(RAYWHITE); BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); EndMode3D(); DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1,7 +1,9 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
using static Raylib.CameraType;
using static Raylib.CameraMode;
public partial class Examples public partial class core_3d_picking
{ {
/******************************************************************************************* * * raylib [core] example - Picking in 3d mode * * 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) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking"); // Define the camera to look into our 3d world Camera camera; camera.position = new Vector3( 10.0f, 10.0f, 10.0f );; // Camera position camera.target = new Vector3( 0.0f, 0.0f, 0.0f );; // Camera looking at point camera.up = new Vector3( 0.0f, 1.0f, 0.0f );; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y camera.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray bool collision = false; SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode 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 //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera if (IsMouseButtonPressed((int)Mouse.LEFT_BUTTON)) { ray = GetMouseRay(GetMousePosition(), camera); // Check collision between ray and box collision = CheckCollisionRayBox(ray, new BoundingBox((Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 );, new Vector3( cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 });); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); if (collision) { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); DrawCubeWires(cubePosition, cubeSize.x + 0.2f, cubeSize.y + 0.2f, cubeSize.z + 0.2f, GREEN); } else { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); } DrawRay(ray, MAROON); DrawGrid(10, 1.0f); EndMode3D(); DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [core] example - Picking in 3d mode * * 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) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking"); // Define the camera to look into our 3d world Camera3D camera; camera.position = new Vector3( 10.0f, 10.0f, 10.0f ); // Camera3D position camera.target = new Vector3( 0.0f, 0.0f, 0.0f ); // Camera3D looking at point camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target) camera.fovy = 45.0f; // Camera3D field-of-view Y camera.type = (int)CAMERA_PERSPECTIVE; // Camera3D mode type Vector3 cubePosition = new Vector3( 0.0f, 1.0f, 0.0f ); Vector3 cubeSize = new Vector3( 2.0f, 2.0f, 2.0f ); Ray ray = new Ray(new Vector3(0.0f, 0.0f, 0.0f), Vector3.Zero); // Picking line ray bool collision = false; SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode 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 //---------------------------------------------------------------------------------- UpdateCamera(ref camera); // Update camera if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { ray = GetMouseRay(GetMousePosition(), camera); // Check collision between ray and box collision = CheckCollisionRayBox(ray, new BoundingBox(new Vector3( cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 ), new Vector3( cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 ))); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); if (collision) { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); DrawCubeWires(cubePosition, cubeSize.x + 0.2f, cubeSize.y + 0.2f, cubeSize.z + 0.2f, GREEN); } else { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); } DrawRay(ray, MAROON); DrawGrid(10, 1.0f); EndMode3D(); DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, (int)(screenHeight * 0.1f), 30, GREEN); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1 +1 @@
using Raylib; using static Raylib.Raylib; public partial class Examples { /******************************************************************************************* * * raylib [core] example - Basic window * * Welcome to raylib! * * To test examples, just press F6 and execute raylib_compile_execute script * Note that compiled executable is placed in the same folder as .c file * * You can find all basic examples on C:\raylib\raylib\examples folder or * raylib official webpage: www.raylib.com * * Enjoy using raylib. :) * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- } } using Raylib; using static Raylib.Raylib; public partial class core_basic_window { /******************************************************************************************* * * raylib [core] example - Basic window * * Welcome to raylib! * * To test examples, just press F6 and execute raylib_compile_execute script * Note that compiled executable is placed in the same folder as .c file * * You can find all basic examples on C:\raylib\raylib\examples folder or * raylib official webpage: www.raylib.com * * Enjoy using raylib. :) * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Congrats! You created your first window!", 190, 200, 20, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } }

View file

@ -1,7 +1,7 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
public partial class Examples public partial class core_color_select
{ {
/******************************************************************************************* * * raylib [core] example - Color selection by mouse (collision detection) * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)"); Color colors[21] = { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE }; Rectangle[] colorsRecs = new Rectangle[21]; // Rectangles array // Fills colorsRecs data (for every rectangle) for (int i = 0; i < 21; i++) { colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7); colorsRecs[i].y = 60 + 100*(i/7) + 10*(i/7); colorsRecs[i].width = 100; colorsRecs[i].height = 100; } bool selected[21] = { false }; // Selected rectangles indicator Vector2 mousePoint; 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 //---------------------------------------------------------------------------------- mousePoint = GetMousePosition(); for (int i = 0; i < 21; i++) // Iterate along all the rectangles { if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) { colors[i].a = 120; if (IsMouseButtonPressed((int)Mouse.LEFT_BUTTON)) selected[i] = !selected[i]; } else colors[i].a = 255; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); for (int i = 0; i < 21; i++) // Draw all rectangles { DrawRectangleRec(colorsRecs[i], colors[i]); // Draw four rectangles around selected rectangle if (selected[i]) { DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 100, 10, RAYWHITE); // Square top rectangle DrawRectangle(colorsRecs[i].x, colorsRecs[i].y, 10, 100, RAYWHITE); // Square left rectangle DrawRectangle(colorsRecs[i].x + 90, colorsRecs[i].y, 10, 100, RAYWHITE); // Square right rectangle DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle } } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [core] example - Color selection by mouse (collision detection) * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - color selection (collision detection)"); Color[] colors = new Color[21] { DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN, GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE }; Rectangle[] colorsRecs = new Rectangle[21]; // Rectangles array // Fills colorsRecs data (for every rectangle) for (int i = 0; i < 21; i++) { colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7); colorsRecs[i].y = 60 + 100*(i/7) + 10*(i/7); colorsRecs[i].width = 100; colorsRecs[i].height = 100; } bool[] selected = new bool[21]; // Selected rectangles indicator Vector2 mousePoint; 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 //---------------------------------------------------------------------------------- mousePoint = GetMousePosition(); for (int i = 0; i < 21; i++) // Iterate along all the rectangles { if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) { colors[i].a = 120; if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) selected[i] = !selected[i]; } else colors[i].a = 255; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); for (int i = 0; i < 21; i++) // Draw all rectangles { DrawRectangleRec(colorsRecs[i], colors[i]); // Draw four rectangles around selected rectangle if (selected[i]) { DrawRectangle((int)colorsRecs[i].x, (int)colorsRecs[i].y, 100, 10, RAYWHITE); // Square top rectangle DrawRectangle((int)colorsRecs[i].x, (int)colorsRecs[i].y, 10, 100, RAYWHITE); // Square left rectangle DrawRectangle((int)colorsRecs[i].x + 90, (int)colorsRecs[i].y, 10, 100, RAYWHITE); // Square right rectangle DrawRectangle((int)colorsRecs[i].x, (int)colorsRecs[i].y + 90, 100, 10, RAYWHITE); // Square bottom rectangle } } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

View file

@ -1,7 +1,7 @@
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
public partial class Examples public partial class core_drop_files
{ {
/******************************************************************************************* * * raylib [core] example - Windows drop files * * This example only works on platforms that support drag & drop (Windows, Linux, OSX, Html5?) * * 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) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); int count = 0; char **droppedFiles = { 0 }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsFileDropped()) { droppedFiles = GetDroppedFiles(&count); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); else { DrawText("Dropped files:", 100, 40, 20, DARKGRAY); for (int i = 0; i < count; i++) { if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY); } DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY); } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- ClearDroppedFiles(); // Clear internal buffers CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /******************************************************************************************* * * raylib [core] example - Windows drop files * * This example only works on platforms that support drag ref drop (Windows, Linux, OSX, Html5?) * * 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) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); int count = 0; string[] droppedFiles = { }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsFileDropped()) { droppedFiles = GetDroppedFiles(ref count); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); else { DrawText("Dropped files:", 100, 40, 20, DARKGRAY); for (int i = 0; i < count; i++) { if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY); } DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY); } EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- ClearDroppedFiles(); // Clear internal buffers CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1 +1,7 @@
using Raylib; using static Raylib.Raylib; public partial class Examples { /******************************************************************************************* * * raylib [core] example - Keyboard input * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); Vector2 ballPosition = new Vector2( (float)screenWidth/2, (float)screenHeight/2 ); SetTargetFPS(60); // Set target frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyDown((int)Key.RIGHT)) ballPosition.x += 2.0f; if (IsKeyDown((int)Key.LEFT)) ballPosition.x -= 2.0f; if (IsKeyDown((int)Key.UP)) ballPosition.y -= 2.0f; if (IsKeyDown((int)Key.DOWN)) ballPosition.y += 2.0f; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); DrawCircleV(ballPosition, 50, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- } } using Raylib;
using static Raylib.Raylib;
public partial class core_input_keys
{
/******************************************************************************************* * * raylib [core] example - Keyboard input * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); Vector2 ballPosition = new Vector2( (float)screenWidth/2, (float)screenHeight/2 ); SetTargetFPS(60); // Set target frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f; if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f; if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f; if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); DrawCircleV(ballPosition, 50, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
}

View file

@ -1 +1,7 @@
using Raylib; using static Raylib.Raylib; public partial class Examples { /******************************************************************************************* * * raylib [core] example - Mouse input * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static void Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); Vector2 ballPosition = new Vector2( -100.0f, -100.0f ); Color ballColor = DARKBLUE; SetTargetFPS(60); //--------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- ballPosition = GetMousePosition(); if (IsMouseButtonPressed((int)Mouse.LEFT_BUTTON)) ballColor = MAROON; else if (IsMouseButtonPressed((int)Mouse.MIDDLE_BUTTON)) ballColor = LIME; else if (IsMouseButtonPressed((int)Mouse.RIGHT_BUTTON)) ballColor = DARKBLUE; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawCircleV(ballPosition, 40, ballColor); DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- } } using Raylib;
using static Raylib.Raylib;
public partial class core_input_mouse
{
/******************************************************************************************* * * raylib [core] example - Mouse input * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ public static int Main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); Vector2 ballPosition = new Vector2( -100.0f, -100.0f ); Color ballColor = DARKBLUE; SetTargetFPS(60); //--------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- ballPosition = GetMousePosition(); if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) ballColor = MAROON; else if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) ballColor = LIME; else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawCircleV(ballPosition, 40, ballColor); DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
}

Some files were not shown because too many files have changed in this diff Show more