Initial commit
This commit is contained in:
commit
d7ff68b487
196 changed files with 286314 additions and 0 deletions
BIN
examples/models/billboard/billboard.png
Normal file
BIN
examples/models/billboard/billboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
47
examples/models/billboard/main.go
Normal file
47
examples/models/billboard/main.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(5.0, 4.0, 5.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 2.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
bill := raylib.LoadTexture("billboard.png") // Our texture billboard
|
||||
billPosition := raylib.NewVector3(0.0, 2.0, 0.0) // Position where draw billboard
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawBillboard(camera, bill, billPosition, 2.0, raylib.White)
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(bill) // Unload texture
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
109
examples/models/box_collisions/main.go
Normal file
109
examples/models/box_collisions/main.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
playerPosition := raylib.NewVector3(0.0, 1.0, 2.0)
|
||||
playerSize := raylib.NewVector3(1.0, 2.0, 1.0)
|
||||
playerColor := raylib.Green
|
||||
|
||||
enemyBoxPos := raylib.NewVector3(-4.0, 1.0, 0.0)
|
||||
enemyBoxSize := raylib.NewVector3(2.0, 2.0, 2.0)
|
||||
|
||||
enemySpherePos := raylib.NewVector3(4.0, 0.0, 0.0)
|
||||
enemySphereSize := float32(1.5)
|
||||
|
||||
collision := false
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
// Move player
|
||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
playerPosition.X += 0.2
|
||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
playerPosition.X -= 0.2
|
||||
} else if raylib.IsKeyDown(raylib.KeyDown) {
|
||||
playerPosition.Z += 0.2
|
||||
} else if raylib.IsKeyDown(raylib.KeyUp) {
|
||||
playerPosition.Z -= 0.2
|
||||
}
|
||||
|
||||
collision = false
|
||||
|
||||
// Check collisions player vs enemy-box
|
||||
if raylib.CheckCollisionBoxes(
|
||||
raylib.NewBoundingBox(
|
||||
raylib.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||
raylib.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||
raylib.NewBoundingBox(
|
||||
raylib.NewVector3(enemyBoxPos.X-enemyBoxSize.X/2, enemyBoxPos.Y-enemyBoxSize.Y/2, enemyBoxPos.Z-enemyBoxSize.Z/2),
|
||||
raylib.NewVector3(enemyBoxPos.X+enemyBoxSize.X/2, enemyBoxPos.Y+enemyBoxSize.Y/2, enemyBoxPos.Z+enemyBoxSize.Z/2)),
|
||||
) {
|
||||
collision = true
|
||||
}
|
||||
|
||||
// Check collisions player vs enemy-sphere
|
||||
if raylib.CheckCollisionBoxSphere(
|
||||
raylib.NewBoundingBox(
|
||||
raylib.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||
raylib.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||
enemySpherePos,
|
||||
enemySphereSize,
|
||||
) {
|
||||
collision = true
|
||||
}
|
||||
|
||||
if collision {
|
||||
playerColor = raylib.Red
|
||||
} else {
|
||||
playerColor = raylib.Green
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
// Draw enemy-box
|
||||
raylib.DrawCube(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, raylib.Gray)
|
||||
raylib.DrawCubeWires(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, raylib.DarkGray)
|
||||
|
||||
// Draw enemy-sphere
|
||||
raylib.DrawSphere(enemySpherePos, enemySphereSize, raylib.Gray)
|
||||
raylib.DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, raylib.DarkGray)
|
||||
|
||||
// Draw player
|
||||
raylib.DrawCubeV(playerPosition, playerSize, playerColor)
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawText("Move player with cursors to collide", 220, 40, 20, raylib.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/models/cubicmap/cubicmap.png
Normal file
BIN
examples/models/cubicmap/cubicmap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 201 B |
BIN
examples/models/cubicmap/cubicmap_atlas.png
Normal file
BIN
examples/models/cubicmap/cubicmap_atlas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
68
examples/models/cubicmap/main.go
Normal file
68
examples/models/cubicmap/main.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(16.0, 14.0, 16.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||
cubic := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||
cubicmap := raylib.LoadCubicmap(image) // Load cubicmap model (generate model from image)
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||
cubicmap.Material.TexDiffuse = texture // Set map diffuse texture
|
||||
|
||||
mapPosition := raylib.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
||||
|
||||
raylib.UnloadImage(image) // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawModel(cubicmap, mapPosition, 1.0, raylib.White)
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawTextureEx(cubic, raylib.NewVector2(float32(screenWidth-cubic.Width*4-20), 20), 0.0, 4.0, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth-cubic.Width*4-20, 20, cubic.Width*4, cubic.Height*4, raylib.Green)
|
||||
|
||||
raylib.DrawText("cubicmap image used to", 658, 90, 10, raylib.Gray)
|
||||
raylib.DrawText("generate map 3d model", 658, 104, 10, raylib.Gray)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(cubic) // Unload cubicmap texture
|
||||
raylib.UnloadTexture(texture) // Unload map texture
|
||||
raylib.UnloadModel(cubicmap) // Unload map model
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
52
examples/models/geometric_shapes/main.go
Normal file
52
examples/models/geometric_shapes/main.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(0.1, 10.0, 10.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawCube(raylib.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, raylib.Red)
|
||||
raylib.DrawCubeWires(raylib.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, raylib.Gold)
|
||||
raylib.DrawCubeWires(raylib.NewVector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, raylib.Maroon)
|
||||
|
||||
raylib.DrawSphere(raylib.NewVector3(-1.0, 0.0, -2.0), 1.0, raylib.Green)
|
||||
raylib.DrawSphereWires(raylib.NewVector3(1.0, 0.0, 2.0), 2.0, 16, 16, raylib.Lime)
|
||||
|
||||
raylib.DrawCylinder(raylib.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, raylib.SkyBlue)
|
||||
raylib.DrawCylinderWires(raylib.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, raylib.DarkBlue)
|
||||
raylib.DrawCylinderWires(raylib.NewVector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, raylib.Brown)
|
||||
|
||||
raylib.DrawCylinder(raylib.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, raylib.Gold)
|
||||
raylib.DrawCylinderWires(raylib.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, raylib.Pink)
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/models/heightmap/heightmap.png
Normal file
BIN
examples/models/heightmap/heightmap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
63
examples/models/heightmap/main.go
Normal file
63
examples/models/heightmap/main.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(18.0, 16.0, 18.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
||||
texture := raylib.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
||||
hmap := raylib.LoadHeightmap(image, raylib.NewVector3(16, 8, 16)) // Load heightmap model with defined size
|
||||
hmap.Material.TexDiffuse = texture // Set map diffuse texture
|
||||
mapPosition := raylib.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||
|
||||
raylib.UnloadImage(image) // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||
|
||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
raylib.UpdateCamera(&camera) // Update camera
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
// NOTE: Model is scaled to 1/4 of its original size (128x128 units)
|
||||
raylib.DrawModel(hmap, mapPosition, 1.0, raylib.Red)
|
||||
|
||||
raylib.DrawGrid(20, 1.0)
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth-texture.Width-20, 20, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth-texture.Width-20, 20, texture.Width, texture.Height, raylib.Green)
|
||||
|
||||
raylib.DrawFPS(10, 10)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture) // Unload map texture
|
||||
raylib.UnloadModel(hmap) // Unload map model
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
54966
examples/models/obj_loading/dwarf.obj
Normal file
54966
examples/models/obj_loading/dwarf.obj
Normal file
File diff suppressed because it is too large
Load diff
BIN
examples/models/obj_loading/dwarf_diffuse.png
Normal file
BIN
examples/models/obj_loading/dwarf_diffuse.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
52
examples/models/obj_loading/main.go
Normal file
52
examples/models/obj_loading/main.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
||||
|
||||
camera := raylib.Camera{}
|
||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
||||
camera.Fovy = 45.0
|
||||
|
||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||
|
||||
dwarf.Material.TexDiffuse = texture // Set dwarf model diffuse texture
|
||||
|
||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.Begin3dMode(camera)
|
||||
|
||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
||||
|
||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
||||
|
||||
raylib.DrawGizmo(position) // Draw gizmo
|
||||
|
||||
raylib.End3dMode()
|
||||
|
||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture) // Unload texture
|
||||
raylib.UnloadModel(dwarf) // Unload model
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue