-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.odin
More file actions
68 lines (56 loc) · 1.51 KB
/
Copy pathmain.odin
File metadata and controls
68 lines (56 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import rg "raygizmo"
import rl "vendor:raylib"
main :: proc() {
rl.InitWindow(1280, 1024, "raygizmo-test")
defer rl.CloseWindow()
// This is a transform that will be edited using the gizmo
cube_transform := rg.GizmoIdentity()
// Example model
cube := rl.GenMeshCube(1, 1, 1)
cube_model := rl.LoadModelFromMesh(cube)
defer rl.UnloadModel(cube_model)
cam := rl.Camera3D {
position = {-10, 2, -5},
target = {0, 0, 0},
projection = .PERSPECTIVE,
up = {0, 1, 0},
fovy = 70,
}
// Camera reference
rg.SetCamera(&cam)
// Flags: they determine what gizmos are active, and in what space: local or view
// NOTE: scale gizmo supports local space only
flags: rg.GizmoFlags = {.Translate, .Local}
for !rl.WindowShouldClose() {
// Switch gizmos with Q, W, or E keys
if rl.IsKeyPressed(.Q) {
flags = {.Translate, .Local}
}
if rl.IsKeyPressed(.W) {
flags = {.Rotate, .Local}
}
if rl.IsKeyPressed(.E) {
flags = {.Scale, .Local}
}
// Reset transform with R key
if rl.IsKeyPressed(.R) {
cube_transform = rg.GizmoIdentity()
}
rl.BeginDrawing()
{
rl.ClearBackground(rl.BLACK)
rl.BeginMode3D(cam)
{
// Transform our gizmo to the model's transform
cube_model.transform = rg.GizmoToMatrix(cube_transform)
rl.DrawModel(cube_model, {0, 0, 0}, 1, rl.GOLD)
rl.DrawModelWires(cube_model, {0, 0, 0}, 1, rl.ORANGE)
// Draw gizmo, update cube_transform
rg.DrawGizmo3D(flags, &cube_transform)
}
rl.EndMode3D()
}
rl.EndDrawing()
}
}