draw a cube using raylib in csharp

To draw a cube using raylib in csharp, you can follow these steps:

  1. Initialize raylib with Raylib.InitWindow() and Raylib.SetTargetFPS()
  2. Set up the camera with Raylib.SetCameraMode() and Raylib.SetCameraPosition()
  3. Define the cube's properties, like position, size, color, etc.
  4. Use Raylib.DrawCube() to draw the cube.

Here's an example code snippet to draw a green cube at (0,0,0) with a length of 2:

main.cs
using Raylib_cs;

public static void DrawCube()
{
    // Initialize raylib
    Raylib.InitWindow(800, 450, "Cube");
    Raylib.SetTargetFPS(60);

    // Set up the camera
    Camera3D camera = new Camera3D();
    camera.position = new Vector3(5.0f, 5.0f, 5.0f);
    camera.target = new Vector3(0.0f, 0.0f, 0.0f);
    camera.up = new Vector3(0.0f, 1.0f, 0.0f);
    camera.fovy = 45.0f;
    Raylib.SetCameraMode(camera, CameraMode.CAMERA_FREE);

    // Define the cube's properties
    Vector3 position = new Vector3(0.0f, 0.0f, 0.0f);
    Color color = Color.GREEN;
    float size = 2.0f;

    // Draw the cube
    while (!Raylib.WindowShouldClose())
    {
        Raylib.BeginDrawing();
        Raylib.ClearBackground(Color.RAYWHITE);

        Raylib.BeginMode3D(camera);
        Raylib.DrawCube(position, size, size, size, color);
        Raylib.EndMode3D();

        Raylib.EndDrawing();
    }

    Raylib.CloseWindow();
}
925 chars
37 lines

related categories

gistlibby LogSnag