-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransformable.go
155 lines (133 loc) · 4.65 KB
/
transformable.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (C) 2012-2014 by krepa098. All rights reserved.
// Use of this source code is governed by a zlib-style
// license that can be found in the license.txt file.
package gosfml2
// #include <SFML/Graphics/Transformable.h>
import "C"
import "runtime"
/////////////////////////////////////
/// STRUCTS
/////////////////////////////////////
type Transformable struct {
cptr *C.sfTransformable
}
/////////////////////////////////////
/// FUNCS
/////////////////////////////////////
// Create a new transformable
func NewTransformable() *Transformable {
transformable := &Transformable{C.sfTransformable_create()}
runtime.SetFinalizer(transformable, (*Transformable).destroy)
return transformable
}
// Destroy an existing transformable
func (this *Transformable) destroy() {
C.sfTransformable_destroy(this.cptr)
}
// Copy an existing transformable
func (this *Transformable) Copy() *Transformable {
transformable := &Transformable{C.sfTransformable_copy(this.cptr)}
runtime.SetFinalizer(transformable, (*Transformable).destroy)
return transformable
}
// Set the position of a transformable
//
// This function completely overwrites the previous position.
// See Transformable.Move to apply an offset based on the previous position instead.
// The default position of a transformable Transformable object is (0, 0).
//
// position: New position
func (this *Transformable) SetPosition(pos Vector2f) {
C.sfTransformable_setPosition(this.cptr, pos.toC())
}
// Set the scale factors of a transformable
//
// This function completely overwrites the previous scale.
// See Transformable.Scale to add a factor based on the previous scale instead.
// The default scale of a transformable Transformable object is (1, 1).
//
// scale: New scale factors
func (this *Transformable) SetScale(scale Vector2f) {
C.sfTransformable_setScale(this.cptr, scale.toC())
}
// Set the orientation of a transformable
//
// This function completely overwrites the previous rotation.
// See Transformable.Rotate to add an angle based on the previous rotation instead.
// The default rotation of a transformable Transformable object is 0.
//
// angle: New rotation, in degrees
func (this *Transformable) SetRotation(rot float32) {
C.sfTransformable_setRotation(this.cptr, C.float(rot))
}
// Set the local origin of a transformable
//
// The origin of an object defines the center point for
// all transformations (position, scale, rotation).
// The coordinates of this point must be relative to the
// top-left corner of the object, and ignore all
// transformations (position, scale, rotation).
// The default origin of a transformable Transformable object is (0, 0).
//
// origin: New origin
func (this *Transformable) SetOrigin(orig Vector2f) {
C.sfTransformable_setOrigin(this.cptr, orig.toC())
}
// Get the orientation of a transformable
//
// The rotation is always in the range [0, 360].
func (this *Transformable) GetRotation() float32 {
return float32(C.sfTransformable_getRotation(this.cptr))
}
// Get the position of a transformable
func (this *Transformable) GetPosition() (pos Vector2f) {
pos.fromC(C.sfTransformable_getPosition(this.cptr))
return
}
// Get the current scale of a transformable
func (this *Transformable) GetScale() (scale Vector2f) {
scale.fromC(C.sfTransformable_getScale(this.cptr))
return
}
// Get the local origin of a transformable
func (this *Transformable) GetOrigin() (origin Vector2f) {
origin.fromC(C.sfTransformable_getOrigin(this.cptr))
return
}
// Move a transformable by a given offset
//
// This function adds to the current position of the object,
// unlike Transformable.SetPosition which overwrites it.
//
// offset: Offset
func (this *Transformable) Move(offset Vector2f) {
C.sfTransformable_move(this.cptr, offset.toC())
}
// Scale a transformable
//
// This function multiplies the current scale of the object,
// unlike Transformable.SetScale which overwrites it.
//
// factors: Scale factors
func (this *Transformable) Scale(factor Vector2f) {
C.sfTransformable_scale(this.cptr, factor.toC())
}
// Rotate a transformable
//
// This function adds to the current rotation of the object,
// unlike Transformable.SetRotation which overwrites it.
//
// angle: Angle of rotation, in degrees
func (this *Transformable) Rotate(angle float32) {
C.sfTransformable_rotate(this.cptr, C.float(angle))
}
// Get the combined transform of a transformable
func (this *Transformable) GetTransform() (trans Transform) {
trans.fromC(C.sfTransformable_getTransform(this.cptr))
return
}
// Get the inverse of the combined transform of a transformable
func (this *Transformable) GetInverseTransform() (transform Transform) {
transform.fromC(C.sfTransformable_getInverseTransform(this.cptr))
return
}