Documentation ¶
Index ¶
- Variables
- type Base
- func (b *Base) Angle() float32
- func (b *Base) AttachToWorld(world World)
- func (b *Base) Bounds() image.Rectangle
- func (b *Base) Center() (float32, float32)
- func (b *Base) Color() color.Color
- func (b *Base) Move(dx, dy float32)
- func (b *Base) MoveTo(x, y float32)
- func (b *Base) NColor() [4]float32
- func (b *Base) Rotate(angle float32)
- func (b *Base) RotateAround(x, y, angle float32)
- func (b *Base) Scale(sx, sy float32)
- func (b *Base) SetCenter(x, y float32)
- func (s *Base) SetColor(c color.Color)
- func (b *Base) SetTexture(texture uint32, texCoords []float32) error
- func (b *Base) String() string
- func (b *Base) Vertices() []float32
- type Box
- type Group
- func (g *Group) Angle() float32
- func (g *Group) Append(s Shape)
- func (g *Group) AttachToWorld(world World)
- func (g *Group) Bounds() image.Rectangle
- func (g *Group) Center() (float32, float32)
- func (g *Group) Clone() Shape
- func (g *Group) Draw()
- func (g *Group) GetAt(id int) Shape
- func (g *Group) Move(dx, dy float32)
- func (g *Group) MoveTo(x, y float32)
- func (g *Group) Rotate(angle float32)
- func (g *Group) RotateAround(x, y, angle float32)
- func (g *Group) Scale(sx, sy float32)
- func (g *Group) SetCenter(x, y float32)
- func (g *Group) SetTexture(texture uint32, texCoords []float32) error
- func (g *Group) String() string
- func (g *Group) Vertices() []float32
- type Segment
- type Shape
- type World
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultBoxVS is a default vertex shader for boxes. DefaultBoxVS = (shaders.VertexShader)( ` precision mediump float; attribute vec4 pos; attribute vec4 color; attribute vec2 texIn; varying vec2 texOut; varying vec4 vColor; uniform mat4 model; uniform mat4 projection; uniform mat4 view; void main() { gl_Position = projection*model*view*pos; vColor = color; texOut = texIn; }`) // DefaultBoxVS is a default fragment shader for boxes. DefaultBoxFS = (shaders.FragmentShader)( ` precision mediump float; varying vec4 vColor; varying vec2 texOut; uniform sampler2D texture; uniform float texRatio; void main() { vec2 flippedTexCoords = vec2(texOut.x, 1.0 - texOut.y); vec4 texColor = texture2D(texture, flippedTexCoords) * texRatio; vec4 vertColor = vColor * (1.0 - texRatio); gl_FragColor = texColor + vertColor; }`) )
var ( // DefaultSegmentVS is a default vertex shader for the segment. DefaultSegmentVS = (shaders.VertexShader)( `precision mediump float; attribute vec4 pos; attribute vec4 color; varying vec4 vColor; uniform mat4 model; uniform mat4 projection; uniform mat4 view; void main() { gl_Position = projection*model*view*pos; vColor = color; }`) // DefaultSegmentVS is a default fragment shader for the // segment. DefaultSegmentFS = (shaders.FragmentShader)( `precision mediump float; varying vec4 vColor; void main() { gl_FragColor = vColor; }`) )
var ( // The default color for shapes is blue. DefaultColor = color.RGBA{0, 0, 0xff, 0xff} )
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base represent a basic structure for shapes.
func (*Base) AttachToWorld ¶
AttachToWorld fills projection and view matrices with world's matrices.
func (*Base) RotateAround ¶
RotateAround rotates the shape around the given point, by the given angle in degrees.
func (*Base) SetTexture ¶
SetTexture sets a texture for the shape. Texture argument is an uint32 value returned by the OpenGL context. It's a client-code responsibility to provide that value.
type Box ¶
type Box struct {
Base
}
Box represents a box shape.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a structure for grouping shapes. It implements Shape.
func (*Group) AttachToWorld ¶
AttachToWorld attaches the group to a world.
func (*Group) Draw ¶
func (g *Group) Draw()
Draw draws all the shapes in the group calling their Draw method.
func (*Group) RotateAround ¶
RotateAround rotates the group around the given point, by the given angle in degrees.
func (*Group) SetTexture ¶
SetTexture sets the same texture to all shapes in the group.
type Segment ¶
type Segment struct { Base // contains filtered or unexported fields }
Segment is a structure representing a segment.
func NewSegment ¶
NewSegment returns a new segment object. It takes a program shader and segment coordinates as arguments.
type Shape ¶
type Shape interface { // Rotate rotates the shape by angle in degree. Rotate(angle float32) // RotateAround rotates the shape around the given point, by // the given angle in degrees. RotateAround(x, y, angle float32) // Scale scales the shape by (sx,sy) factor. Scale(sx, sy float32) // Move moves the shape by (dx, dy). Move(dx, dy float32) // MoveTo moves the (center of the) shape in position (x,y). MoveTo(x, y float32) // Draw renders the shape on the surface. Draw() // Vertices returns the vertices slice of the shape. Vertices() []float32 // Center returns the center coordinates of the shape. Center() (float32, float32) // Angle returns the rotation angle of the shape. Angle() float32 // Bounds returns the bounding rectangle of the shape. Bounds() image.Rectangle // String returns a string representation of the shape. String() string // AttachToWorld attaches the shape to a world. AttachToWorld(world World) // Clone clones the current shape and returns a new shape. Clone() Shape // SetTexture sets a texture for the shape. SetTexture(texture uint32, texCoords []float32) error }
Shape is an interface describing a shape.
type World ¶
type World interface { // Projection returns the projection matrix used to render // the objects in the World. Projection() mathgl.Mat4f // View returns the view matrix used to render the World from // the point-of-view of a camera. View() mathgl.Mat4f }
World in an interface for projection and view matrix.