Watch
3
0
Fork
You've already forked raylib-cs
0
This commit is contained in:
Mikael Rasmussen 2018-10-24 21:23:53 +02:00
commit 37f2201054
83 changed files with 6958 additions and 794 deletions

View file

@ -1,9 +1,4 @@
/********************************************************************************************** // Easings - https://github.com/raysan5/raylib/blob/master/src/easings.h
*
* Raylib easings bindings
* Original - https://github.com/raysan5/raylib/blob/master/src/easings.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -13,94 +8,94 @@ namespace Raylib
public static partial class Raylib public static partial class Raylib
{ {
#region Raylib-cs Functions #region Raylib-cs Functions
// Linear Easing functions // Linear Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearNone(float t, float b, float c, float d); public static extern float EaseLinearNone(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearIn(float t, float b, float c, float d); public static extern float EaseLinearIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearOut(float t, float b, float c, float d); public static extern float EaseLinearOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearInOut(float t, float b, float c, float d); public static extern float EaseLinearInOut(float t, float b, float c, float d);
// Sine Easing functions // Sine Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseSineIn(float t, float b, float c, float d); public static extern float EaseSineIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseSineOut(float t, float b, float c, float d); public static extern float EaseSineOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseSineInOut(float t, float b, float c, float d); public static extern float EaseSineInOut(float t, float b, float c, float d);
// Circular Easing functions // Circular Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCircIn(float t, float b, float c, float d); public static extern float EaseCircIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCircOut(float t, float b, float c, float d); public static extern float EaseCircOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCircInOut(float t, float b, float c, float d); public static extern float EaseCircInOut(float t, float b, float c, float d);
// Cubic Easing functions // Cubic Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCubicIn(float t, float b, float c, float d); public static extern float EaseCubicIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCubicOut(float t, float b, float c, float d); public static extern float EaseCubicOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseCubicInOut(float t, float b, float c, float d); public static extern float EaseCubicInOut(float t, float b, float c, float d);
// Quadratic Easing functions // Quadratic Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseQuadIn(float t, float b, float c, float d); public static extern float EaseQuadIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseQuadOut(float t, float b, float c, float d); public static extern float EaseQuadOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseQuadInOut(float t, float b, float c, float d); public static extern float EaseQuadInOut(float t, float b, float c, float d);
// Exponential Easing functions // Exponential Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseExpoIn(float t, float b, float c, float d); public static extern float EaseExpoIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseExpoOut(float t, float b, float c, float d); public static extern float EaseExpoOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseExpoInOut(float t, float b, float c, float d); public static extern float EaseExpoInOut(float t, float b, float c, float d);
// Back Easing functions // Back Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBackIn(float t, float b, float c, float d); public static extern float EaseBackIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBackOut(float t, float b, float c, float d); public static extern float EaseBackOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBackInOut(float t, float b, float c, float d); public static extern float EaseBackInOut(float t, float b, float c, float d);
// Bounce Easing functions // Bounce Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBounceOut(float t, float b, float c, float d); public static extern float EaseBounceOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBounceIn(float t, float b, float c, float d); public static extern float EaseBounceIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseBounceInOut(float t, float b, float c, float d); public static extern float EaseBounceInOut(float t, float b, float c, float d);
// Elastic Easing functions // Elastic Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseElasticIn(float t, float b, float c, float d); public static extern float EaseElasticIn(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseElasticOut(float t, float b, float c, float d); public static extern float EaseElasticOut(float t, float b, float c, float d);
@ -108,6 +103,5 @@ namespace Raylib
public static extern float EaseElasticInOut(float t, float b, float c, float d); public static extern float EaseElasticInOut(float t, float b, float c, float d);
#endregion #endregion
} }
} }

View file

@ -1,9 +1,4 @@
/********************************************************************************************** // Physac - https://github.com/raysan5/raylib/blob/master/src/physac.h
*
* Physac
* Original -https://github.com/raysan5/raylib/blob/master/src/physac.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -37,11 +32,13 @@ namespace Raylib
{ {
public uint vertexCount; // Current used vertex and normals count public uint vertexCount; // Current used vertex and normals count
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)] //[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
public Vector2[] positions; // Polygon vertex positions vectors //public Vector2[] positions; // Polygon vertex positions vectors
public unsafe Vector2* positions;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
public Vector2[] normals; // Polygon vertex normals vectors //[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = Raylib.PHYSAC_MAX_VERTICES)]
//public Vector2[] normals; // Polygon vertex normals vectors
public unsafe Vector2* normals;
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
@ -79,17 +76,18 @@ namespace Raylib
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PhysicsManifoldData public unsafe struct PhysicsManifoldData
{ {
public uint id; // Reference unique identifier public uint id; // Reference unique identifier
public PhysicsBodyData bodyA; // Manifold first physics body reference public PhysicsBodyData bodyA; // Manifold first physics body reference
public PhysicsBodyData bodyB; // Manifold second physics body reference public PhysicsBodyData bodyB; // Manifold second physics body reference
public float penetration; // Depth of penetration from collision public float penetration; // Depth of penetration from collision
public Vector2 normal; // Normal direction vector from 'a' to 'b' public Vector2 normal; // Normal direction vector from 'a' to 'b'
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 2)] //[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 2)]
public Vector2[] contacts; // Points of contact during collision // public fixed Vector2[] contacts; // Points of contact during collision
public unsafe Vector2* contacts;
public uint contactsCount; // Current collision number of contacts public uint contactsCount; // Current collision number of contacts
public float restitution; // Mixed restitution during collision public float restitution; // Mixed restitution during collision
public float dynamicFriction; // Mixed dynamic friction during collision public float dynamicFriction; // Mixed dynamic friction during collision
@ -120,19 +118,23 @@ namespace Raylib
#endregion #endregion
#region Raylib-cs Functions #region Raylib-cs Functions
// Initializes physics values, pointers and creates physics loop thread // Initializes physics values, pointers and creates physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void InitPhysics(); public static extern void InitPhysics();
// Run physics step, to be used if PHYSICS_NO_THREADS is set in your main loop
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void RunPhysicsStep();
// Returns true if physics thread is currently enabled // Returns true if physics thread is currently enabled
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsPhysicsEnabled(); public static extern bool IsPhysicsEnabled();
// Sets physics global gravity force // Sets physics global gravity force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsGravity(float x, float y); public static extern void SetPhysicsGravity(float x, float y);
// Creates a new circle physics body with generic parameters // Creates a new circle physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")] [DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")]
@ -167,23 +169,23 @@ namespace Raylib
// Adds a force to a physics body // Adds a force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force); public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force);
// Adds an angular force to a physics body // Adds an angular force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount); public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount);
// Shatters a polygon shape physics body to little physics bodies with explosion force // Shatters a polygon shape physics body to little physics bodies with explosion force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force); public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force);
// Returns the current amount of created physics bodies // Returns the current amount of created physics bodies
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsBodiesCount(); public static extern int GetPhysicsBodiesCount();
// Returns a physics body of the bodies pool at a specific index // Returns a physics body of the bodies pool at a specific index
[DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")] [DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")]
public static extern IntPtr GetPhysicsBodyImport(int index); public static extern IntPtr GetPhysicsBodyImport(int index);
public static PhysicsBodyData GetPhysicsBody(int index) public static PhysicsBodyData GetPhysicsBody(int index)
{ {
var body = GetPhysicsBodyImport(index); var body = GetPhysicsBodyImport(index);
@ -193,33 +195,32 @@ namespace Raylib
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeType(int index); public static extern int GetPhysicsShapeType(int index);
// Returns the amount of vertices of a physics body shape // Returns the amount of vertices of a physics body shape
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeVerticesCount(int index); public static extern int GetPhysicsShapeVerticesCount(int index);
// Returns transformed position of a body shape (body position + vertex transformed position) // Returns transformed position of a body shape (body position + vertex transformed position)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex); public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex);
// Sets physics body shape transform based on radians parameter // Sets physics body shape transform based on radians parameter
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians); public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians);
// Unitializes and destroy a physics body // Unitializes and destroy a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyPhysicsBody(PhysicsBodyData body); public static extern void DestroyPhysicsBody(PhysicsBodyData body);
// Destroys created physics bodies and manifolds and resets global values // Destroys created physics bodies and manifolds and resets global values
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ResetPhysics(); public static extern void ResetPhysics();
// Unitializes physics pointers and closes physics loop thread // Unitializes physics pointers and closes physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ClosePhysics(); public static extern void ClosePhysics();
#endregion #endregion
} }
} }

View file

@ -1,9 +1,4 @@
/********************************************************************************************** // Raygui - https://github.com/raysan5/raygui/blob/master/src/raygui.h
*
* Raygui
* Original - https://github.com/raysan5/raygui/blob/master/src/raygui.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View file

@ -1,9 +1,5 @@
/********************************************************************************************** // Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h
*
* Raylib - A simple and easy-to-use library to learn videogames programming (www.raylib.com)
* Original - https://github.com/raysan5/raylib/blob/master/src/raylib.h
*
**********************************************************************************************/
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -186,7 +182,7 @@ namespace Raylib
NPT_9PATCH = 0, // 3x3 NPT_9PATCH = 0, // 3x3
NPT_3PATCH_VERTICAL, // 1x3 NPT_3PATCH_VERTICAL, // 1x3
NPT_3PATCH_HORIZONTAL // 3x1 NPT_3PATCH_HORIZONTAL // 3x1
} }
// enum extension for constants // enum extension for constants
// Keyboard Function Keys // Keyboard Function Keys
@ -933,7 +929,7 @@ namespace Raylib
#endregion #endregion
#region Raylib-cs Functions #region Raylib-cs Functions
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Window and Graphics Device Functions (Module: core) // Window and Graphics Device Functions (Module: core)
@ -1354,7 +1350,7 @@ namespace Raylib
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetTouchPointsCount(); public static extern int GetTouchPointsCount();
// Get gesture hold time in milliseconds // Get gesture hold time in milliseconds
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GetGestureHoldDuration(); public static extern float GetGestureHoldDuration();
@ -2396,7 +2392,7 @@ namespace Raylib
// Set pitch for audio stream (1.0 is base level) // Set pitch for audio stream (1.0 is base level)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetAudioStreamPitch(AudioStream stream, float pitch); public static extern void SetAudioStreamPitch(AudioStream stream, float pitch);
#endregion #endregion
} }
} }

View file

@ -1,9 +1,4 @@
/********************************************************************************************** // Raymath - https://github.com/raysan5/raylib/blob/master/src/raymath.h
*
* Raymath v1.2 bindings - Math functions to work with Vector3, Matrix and Quaternions
* Original - https://github.com/raysan5/raylib/blob/master/src/raymath.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View file

@ -1,9 +1,4 @@
/********************************************************************************************** // Rlgl - https://github.com/raysan5/raylib/blob/master/src/rlgl.h
*
* Rlgl
* Original - https://github.com/raysan5/raylib/blob/master/src/rlgl.h
*
**********************************************************************************************/
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -28,6 +23,5 @@ namespace Raylib
#region Raylib-cs Functions #region Raylib-cs Functions
#endregion #endregion
} }
} }

View file

@ -6,23 +6,44 @@ namespace Examples
{ {
public class Test public class Test
{ {
public static string GetExampleDirectory()
{
var dir = Environment.CurrentDirectory;
dir = dir.Substring(0, dir.LastIndexOf("Raylib-cs") + 9) + "\\Examples\\";
return dir;
}
// menu for testing examples // menu for testing examples
// specify name relative to example directory
public static void Run(string[] args) public static void Run(string[] args)
{ {
Console.WriteLine("Welcome to raylib-cs!"); Console.WriteLine("Welcome to raylib-cs!");
Console.WriteLine("---------------------");
var examples = GetExampleDirectory();
Console.WriteLine("Looking for examples relative to " + examples);
Console.WriteLine("For example, core/core_basic_window");
while (true) while (true)
{ {
Console.WriteLine("Enter path to example"); Console.Write("Choose a example: ");
// select example
var filePath = Console.ReadLine(); var filePath = Console.ReadLine();
var name = Path.GetFileNameWithoutExtension(filePath); var name = Path.GetFileNameWithoutExtension(filePath);
var dir = examples + filePath + ".cs";
Console.WriteLine("Running example " + filePath);
ChangeDirectory(Path.GetDirectoryName(filePath)); // run example if it exists
Type.GetType(name)?.GetMethod("Main")?.Invoke(null, args); if (File.Exists(dir))
{
Console.WriteLine(); ChangeDirectory(Path.GetDirectoryName(dir));
Type.GetType(name)?.GetMethod("Main")?.Invoke(null, args);
Console.WriteLine();
}
else
{
Console.WriteLine(filePath + " is not a valid example");
}
} }
} }
} }

File diff suppressed because one or more lines are too long

View file

@ -3,5 +3,96 @@ using static Raylib.Raylib;
public partial class audio_music_stream 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 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; } /*******************************************************************************************
*
* 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,11 +1,119 @@
using System; using System;
using Raylib; using Raylib;
using static Raylib.Raylib; using static Raylib.Raylib;
public partial class audio_raw_stream 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 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 * raylib [audio] example - Raw audio streaming
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; } *
* 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

@ -3,5 +3,70 @@ using static Raylib.Raylib;
public partial class audio_sound_loading 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 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; } /*******************************************************************************************
*
* 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

@ -5,5 +5,100 @@ using static Raylib.CameraMode;
public partial class core_3d_camera_first_person 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 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; } /*******************************************************************************************
*
* 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

@ -5,5 +5,86 @@ using static Raylib.CameraMode;
public partial class core_3d_camera_free 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 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; } /*******************************************************************************************
*
* 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

@ -4,5 +4,76 @@ using static Raylib.CameraType;
public partial class core_3d_mode 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 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; } /*******************************************************************************************
*
* 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

@ -5,5 +5,106 @@ using static Raylib.CameraMode;
public partial class core_3d_picking 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 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; } /*******************************************************************************************
*
* 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,67 @@
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; } } 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

@ -3,5 +3,84 @@ using static Raylib.Raylib;
public partial class Examples public partial class Examples
{ {
/******************************************************************************************* * * raylib [core] example - Basic window (adapted for HTML5 platform) * * This example is prepared to compile for PLATFORM_WEB, PLATFORM_DESKTOP and PLATFORM_RPI * As you will notice, code structure is slightly diferent to the other examples... * To compile it for PLATFORM_WEB just uncomment #define PLATFORM_WEB at beginning * * 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) * ********************************************************************************************/ //#define PLATFORM_WEB #include <emscripten/emscripten.h> //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; //---------------------------------------------------------------------------------- // Module Functions Declaration //---------------------------------------------------------------------------------- void UpdateDrawFrame(void); // Update and Draw one frame //---------------------------------------------------------------------------------- // Main Enry Point //---------------------------------------------------------------------------------- public static void Main() { // Initialization //-------------------------------------------------------------------------------------- InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); emscripten_set_main_loop(UpdateDrawFrame, 0, 1); #else SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { UpdateDrawFrame(); } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } //---------------------------------------------------------------------------------- // Module Functions Definition //---------------------------------------------------------------------------------- void UpdateDrawFrame(void) { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } /*******************************************************************************************
*
* raylib [core] example - Basic window (adapted for HTML5 platform)
*
* This example is prepared to compile for PLATFORM_WEB, PLATFORM_DESKTOP and PLATFORM_RPI
* As you will notice, code structure is slightly diferent to the other examples...
* To compile it for PLATFORM_WEB just uncomment #define PLATFORM_WEB at beginning
*
* 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)
*
********************************************************************************************/
//#define PLATFORM_WEB
#include <emscripten/emscripten.h>
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
// Main Enry Point
//----------------------------------------------------------------------------------
public static void Main()
{
// Initialization
//--------------------------------------------------------------------------------------
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
UpdateDrawFrame();
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
void UpdateDrawFrame(void)
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
} }

View file

@ -3,5 +3,97 @@ using static Raylib.Raylib;
public partial class core_color_select 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 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; } /*******************************************************************************************
*
* 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

@ -3,5 +3,84 @@ using static Raylib.Raylib;
public partial class Examples public partial class Examples
{ {
/******************************************************************************************* * * raylib [core] example - Custom logging * * This example has been created using raylib 2.1 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos) * ********************************************************************************************/ // Custom logging funtion void LogCustom(int msgType, const char *text, va_list args) { char timeStr[64]; time_t now = time(NULL); struct tm *tm_info = localtime(&now); strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info); printf("[%s] ", timeStr); switch (msgType) { case LOG_INFO: printf("[INFO] : "); break; case LOG_ERROR: printf("[ERROR]: "); break; case LOG_WARNING: printf("[WARN] : "); break; case LOG_DEBUG: printf("[DEBUG]: "); break; default: break; } vprintf(text, args); printf("\n"); } public static int core_custom_logging() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; // First thing we do is setting our custom logger to ensure everything raylib logs // will use our own logger instead of its internal one SetTraceLogCallback(LogCustom); InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging"); 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("Check out the console output to see the custom logger in action!", 60, 200, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } /*******************************************************************************************
*
* raylib [core] example - Custom logging
*
* This example has been created using raylib 2.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2018 Ramon Santamaria (@raysan5) and Pablo Marcos Oltra (@pamarcos)
*
********************************************************************************************/
// Custom logging funtion
void LogCustom(int msgType, const char *text, va_list args)
{
char timeStr[64];
time_t now = time(NULL);
struct tm *tm_info = localtime(&now);
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tm_info);
printf("[%s] ", timeStr);
switch (msgType)
{
case LOG_INFO: printf("[INFO] : "); break;
case LOG_ERROR: printf("[ERROR]: "); break;
case LOG_WARNING: printf("[WARN] : "); break;
case LOG_DEBUG: printf("[DEBUG]: "); break;
default: break;
}
vprintf(text, args);
printf("\n");
}
public static int core_custom_logging()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
// First thing we do is setting our custom logger to ensure everything raylib logs
// will use our own logger instead of its internal one
SetTraceLogCallback(LogCustom);
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging");
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("Check out the console output to see the custom logger in action!", 60, 200, 20, LIGHTGRAY);
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