Task
Draw a rotating cube.

It should be oriented with one vertex pointing straight up, and its opposite vertex on the main diagonal (the one farthest away) straight down. It can be solid or wire-frame, and you can use ASCII art if your language doesn't have graphical capabilities. Perspective is optional.




Related tasks
 Draw a cuboid
 write language name in 3D ASCII


 
#===================================================================#
# Based on Original Sample from RayLib (https://www.raylib.com/)
# Ported to RingRayLib by Ring Team
#===================================================================#
 
load "raylib.ring"
 
screenWidth = 800
screenHeight = 450
 
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking")
 
camera = Camera3D(
	10, 10, 10,
	0, 0, 0 ,
	0, 1, 0 ,
	45,
	CAMERA_PERSPECTIVE
)
 
cubePosition = Vector3( 0, 1, 0 )
cubeSize = Vector3( 2, 2, 2 )
 
ray = Ray(0,0,0,0,0,0)
 
collision = false
 
SetCameraMode(camera, CAMERA_FREE) 
 
SetTargetFPS(60)
 
while !WindowShouldClose()
 
        UpdateCamera(camera)
 
        if IsMouseButtonPressed(MOUSE_LEFT_BUTTON)
            if !collision
                ray = GetMouseRay(GetMousePosition(), camera)
 
                collision = CheckCollisionRayBox(ray,
 		BoundingBox( cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2,
    		cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 ) )
            else collision = false
 	    ok
	ok
 
        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)
                ok
 
                DrawRay(ray, MAROON)
                DrawGrid(10, 1)
 
            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) ok
 
            DrawFPS(10, 10)
 
        EndDrawing()
end
 
CloseWindow()
 