Skip to content

Commit

Permalink
gizmo: add manipulate gizmo
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Oct 29, 2024
1 parent 5369a08 commit fb155e9
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion Gizmo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"github.com/AllenDang/cimgui-go/utils"
)

type GizmoOperation int

Check failure on line 9 in Gizmo.go

View workflow job for this annotation

GitHub Actions / Lint

exported: exported type GizmoOperation should have comment or be unexported (revive)

type GizmoMode int

Check failure on line 11 in Gizmo.go

View workflow job for this annotation

GitHub Actions / Lint

exported: exported type GizmoMode should have comment or be unexported (revive)

// GizmoI should be implemented by every sub-element of GizmoWidget.
type GizmoI interface {
Gizmo(view, projection *HumanReadableMatrix)
Expand Down Expand Up @@ -84,7 +88,8 @@ func (g *GridGizmo) Gizmo(view, projection *HumanReadableMatrix) {
// CubeGizmo draws a 3D cube in the gizmo area.
// View and Projection matrices are provided by GizmoWidget.
type CubeGizmo struct {
matrix *HumanReadableMatrix
matrix *HumanReadableMatrix
manipulate bool
}

func Cube(matrix *HumanReadableMatrix) *CubeGizmo {
Expand All @@ -93,6 +98,12 @@ func Cube(matrix *HumanReadableMatrix) *CubeGizmo {
}
}

// Manipulate adds ManipulateGizmo to the CubeGizmo.
func (c *CubeGizmo) Manipulate() *CubeGizmo {
c.manipulate = true
return c
}

// Gizmo implements GizmoI interface.
func (c *CubeGizmo) Gizmo(view, projection *HumanReadableMatrix) {
imguizmo.DrawCubes(
Expand All @@ -101,6 +112,39 @@ func (c *CubeGizmo) Gizmo(view, projection *HumanReadableMatrix) {
c.matrix.Matrix(),
1,
)

if c.manipulate {
Manipulate(c.matrix).Gizmo(view, projection)
}
}

type ManipulateGizmo struct {
matrix *HumanReadableMatrix
operation GizmoOperation
mode GizmoMode
}

// Manipulate creates a new ManipulateGizmo.
func Manipulate(matrix *HumanReadableMatrix) *ManipulateGizmo {
return &ManipulateGizmo{
matrix: matrix,
mode: GizmoMode(imguizmo.LOCAL),
operation: GizmoOperation(imguizmo.TRANSLATE),
}
}

// Gizmo implements GizmoI interface.
func (m *ManipulateGizmo) Gizmo(view, projection *HumanReadableMatrix) {
imguizmo.ManipulateV(
view.Matrix(),
projection.Matrix(),
imguizmo.OPERATION(m.operation),
imguizmo.MODE(m.mode),
m.matrix.Matrix(),
nil, // this is deltaMatrix (Can't see usecase for now)
nil, // snap idk what is this
nil, // localBounds idk what is this
nil) // boundsSnap idk what is this
}

// [Gizmo helpers]
Expand Down

0 comments on commit fb155e9

Please sign in to comment.