-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.go
66 lines (56 loc) · 1.94 KB
/
object.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
package space
// An Object is something which exists in space
type Object struct {
// location is the location of the
location Cartesian
// orientation is primary Spherical of the object
orientation Spherical
// rotation is secondary Spherical of the object
// rotation will always be orthogonal to direction
rotation Spherical
}
// NewObject creates an object
func NewObject(location Cartesian, orientation, rotation Spherical) *Object {
normalizedRotation := orientation.PortionOrtagonal(rotation)
return &Object{
location: location,
orientation: orientation,
rotation: normalizedRotation,
}
}
// GetLocation returns the physical location of the device
func (o Object) GetLocation() Cartesian {
return o.location
}
// SetLocation changes the physical location of the device
func (o *Object) SetLocation(newLocation Cartesian) {
o.location = newLocation
}
// GetOrientation returns the physical Spherical of the device
func (o Object) GetOrientation() Spherical {
return o.orientation
}
// SetOrientation changes the physical Spherical of the device
func (o *Object) SetOrientation(newOrientation Spherical) {
o.orientation = newOrientation
o.rotation = newOrientation.PortionOrtagonal(o.rotation)
}
// GetRotation returns the physical rotation of the device
func (o Object) GetRotation() Spherical {
return o.rotation
}
// SetRotation changes the physical rotation of the device
func (o *Object) SetRotation(newRotation Spherical) {
o.rotation = o.orientation.PortionOrtagonal(newRotation)
}
// GetBearings returns all properties of the object
func (o Object) GetBearings() (location Cartesian, orientation, rotation Spherical) {
return o.location, o.orientation, o.rotation
}
// Move changes all properties of the object
func (o *Object) Move(location Cartesian, orientation, rotation Spherical) {
normalizedRotation := orientation.PortionOrtagonal(rotation)
o.location = location
o.orientation = orientation
o.rotation = normalizedRotation
}