-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.go
117 lines (88 loc) · 1.67 KB
/
component.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
package wengine
import "github.com/go-gl/mathgl/mgl32"
const (
COMPO_CAMERA = iota
COMPO_LIGHT
COMPO_MESH
COMPO_SPRITE
)
type Component interface {
Type() int
Object() *Object
setObject(object *Object)
}
type componentBase struct {
parentObject *Object
}
func (c *componentBase) setObject(object *Object) {
c.parentObject = object
}
func (c *componentBase) Object() *Object {
return c.parentObject
}
const (
CAMERA_MODE_PERSPECTIVE = iota
CAMERA_MODE_ORTHOGRAPHIC
)
type CameraComponent struct {
Depth int
Mode int
NearPlane float32
FarPlane float32
Ambient mgl32.Vec3
ClearColor, ClearDepth bool
ViewportX, ViewportY, ViewportW, ViewportH float32
// perspective only
FOV float32
// orthographic only
Width float32
componentBase
}
func (CameraComponent) Type() int {
return COMPO_CAMERA
}
type MeshComponent struct {
Mesh string
Material string
Shader string
CastShadow bool
ReceiveShader bool
componentBase
}
func (MeshComponent) Type() int {
return COMPO_MESH
}
const (
LIGHT_SOURCE_DIRECTIONAL = iota
LIGHT_SOURCE_POINT
LIGHT_SOURCE_SPOT
)
const (
LIGHT_SHADOW_TYPE_NONE = iota
LIGHT_SHADOW_TYPE_SOFT
LIGHT_SHADOW_TYPE_HARD
)
type LightComponent struct {
LightSource int
ShadowType int
// common values
Diffuse mgl32.Vec3
Specular mgl32.Vec3
// point light & spot light
Range float32
// spot light
Angle float32
componentBase
}
func (LightComponent) Type() int {
return COMPO_LIGHT
}
type SpriteComponent struct {
Mesh string
Material string
Shader string
componentBase
}
func (SpriteComponent) Type() int {
return COMPO_SPRITE
}