Vectors.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package imgui
  2. // #include "imguiWrapperTypes.h"
  3. import "C"
  4. // Vec2 represents a two-dimensional vector.
  5. type Vec2 struct {
  6. X float32
  7. Y float32
  8. }
  9. func (vec *Vec2) wrapped() (out *C.IggVec2, finisher func()) {
  10. if vec != nil {
  11. out = &C.IggVec2{
  12. x: C.float(vec.X),
  13. y: C.float(vec.Y),
  14. }
  15. finisher = func() {
  16. vec.X = float32(out.x) // nolint: gotype
  17. vec.Y = float32(out.y) // nolint: gotype
  18. }
  19. } else {
  20. finisher = func() {}
  21. }
  22. return
  23. }
  24. // Set sets values of the vec with args.
  25. func (vec *Vec2) Set(x, y float32) {
  26. vec.X = x
  27. vec.Y = y
  28. }
  29. // Plus returns vec + other.
  30. func (vec Vec2) Plus(other Vec2) Vec2 {
  31. return Vec2{
  32. X: vec.X + other.X,
  33. Y: vec.Y + other.Y,
  34. }
  35. }
  36. // Minus returns vec - other.
  37. func (vec Vec2) Minus(other Vec2) Vec2 {
  38. return Vec2{
  39. X: vec.X - other.X,
  40. Y: vec.Y - other.Y,
  41. }
  42. }
  43. // Times returns vec * value.
  44. func (vec Vec2) Times(value float32) Vec2 {
  45. return Vec2{
  46. X: vec.X * value,
  47. Y: vec.Y * value,
  48. }
  49. }
  50. // Vec4 represents a four-dimensional vector.
  51. type Vec4 struct {
  52. X float32
  53. Y float32
  54. Z float32
  55. W float32
  56. }
  57. func (vec *Vec4) wrapped() (out *C.IggVec4, finisher func()) {
  58. if vec != nil {
  59. out = &C.IggVec4{
  60. x: C.float(vec.X),
  61. y: C.float(vec.Y),
  62. z: C.float(vec.Z),
  63. w: C.float(vec.W),
  64. }
  65. finisher = func() {
  66. vec.X = float32(out.x) // nolint: gotype
  67. vec.Y = float32(out.y) // nolint: gotype
  68. vec.Z = float32(out.z) // nolint: gotype
  69. vec.W = float32(out.w) // nolint: gotype
  70. }
  71. } else {
  72. finisher = func() {}
  73. }
  74. return
  75. }
  76. // Set sets values of the vec with args.
  77. func (vec *Vec4) Set(x, y, z, w float32) {
  78. vec.X = x
  79. vec.Y = y
  80. vec.Z = z
  81. vec.W = w
  82. }
  83. // Plus returns vec + other.
  84. func (vec Vec4) Plus(other Vec4) Vec4 {
  85. return Vec4{
  86. X: vec.X + other.X,
  87. Y: vec.Y + other.Y,
  88. Z: vec.Z + other.Z,
  89. W: vec.W + other.W,
  90. }
  91. }
  92. // Minus returns vec - other.
  93. func (vec Vec4) Minus(other Vec4) Vec4 {
  94. return Vec4{
  95. X: vec.X - other.X,
  96. Y: vec.Y - other.Y,
  97. Z: vec.Z - other.Z,
  98. W: vec.W - other.W,
  99. }
  100. }
  101. // Times returns vec * value.
  102. func (vec Vec4) Times(value float32) Vec4 {
  103. return Vec4{
  104. X: vec.X * value,
  105. Y: vec.Y * value,
  106. Z: vec.Z * value,
  107. W: vec.W * value,
  108. }
  109. }