fizzle

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2017 License: BSD-2-Clause Imports: 12 Imported by: 12

README

FIZZLE v0.3.1

Fizzle is an OpenGL rendering engine written in the Go programming language that currently has a forward rendering pipeline with basic animation and shader support.

In some regards, it is the spiritual successor to my first 3d engine, PortableGLUE.

UNDER CONSTRUCTION

The engine is currently in an alpha state, but you are welcome to see how it's progressing. Any API break should increment the minor version number and any patch release tags should remain compatible even in development 0.x versions.

Requirements

  • GLFW (v3.1) - native library and go binding for window creation
  • Mathgl - for 3d math
  • Freetype - for dynamic font texture generation
  • Groggy - for flexible logging
  • Gombz - provides a serializable data structure for 3d models and animations
  • EweyGewey (v0.3.2) some examples and editors use this GUI library

Additionally, a backend graphics provider needs to be used. At present, fizzle supports the following:

  • Go GL - pre-generated OpenGL bindings using their glow project
  • Opengles2 - Go bindings to the OpenGL ES 2.0 library

These are included when the graphicsprovider subpackage is used and direct importing is not required.

Installation

The dependency Go libraries can be installed with the following commands.

go get github.com/go-gl/glfw/v3.1/glfw
go get github.com/go-gl/mathgl/mgl32
go get github.com/golang/freetype
go get github.com/tbogdala/groggy
go get github.com/tbogdala/gombz
go get github.com/tbogdala/eweygewey

An OpenGL library will also be required for desktop applications; install the OpenGL 3.3 library with the following command:

go get github.com/go-gl/gl/v3.3-core/gl

If you're compiling for Android/iOS, then you will need an OpenGL ES library, and that can be installed with the following command instead:

go get github.com/remogatto/opengles2

This does assume that you have the native GLFW 3.1 library installed already accessible to Go tools.

Current Features

  • forward rendering engine with limited dynamic lighting
  • limited dynamic shadow support
  • components system using JSON files
  • skeletal animations
  • basic camera support
  • basic particle editor (cmd/particles)
  • basic shader explorer (examples/shaders)
  • basic entity system (examples/testscene)

TODO

The following need to be addressed in order to start releases:

  • documentation
  • api comments
  • samples
  • code cleanups
  • possibly remove use of Groggy

LICENSE

Fizzle is released under the BSD license. See the LICENSE file for more details.

Documentation

Overview

Fizzle is a library to make rendering graphics via OpenGL easier.

At present, the best way to learn how to use the library is to look at the example applications in the 'examples' folder.

Index

Constants

View Source
const (
	X = 1 << iota
	Y
	Z
)

axis for forming planes

View Source
const (
	FaceTop    = 0
	FaceFront  = 1
	FaceLeft   = 2
	FaceBottom = 3
	FaceRight  = 4
	FaceBack   = 5
)

constants used to define faces for use in functions that need to act differently based on the face.

View Source
const (
	// MaxCustomTextures is the maximum number of custom textures that can get assigned
	// to a renderable.
	MaxCustomTextures = 8
)

Variables

This section is empty.

Functions

func DebugCheckForError

func DebugCheckForError(msg string)

DebugCheckForError repeatedly calls OpenGL's GetError() and prints out the error codes with a customized message string.

func DegreesToRadians

func DegreesToRadians(x float64) float64

DegreesToRadians converts degrees to radians.

func GenerateMipmaps

func GenerateMipmaps(t graphics.Texture)

GenerateMipmaps will generate the mipmap textures for a given texture object.

func GetGraphics

func GetGraphics() graphics.GraphicsProvider

GetGraphics returns the currently initialized GraphicsProvider if one has been set using SetGraphics().

func LoadImageToTexture

func LoadImageToTexture(filePath string) (graphics.Texture, error)

LoadImageToTexture loads an image from a file into an OpenGL texture.

func LoadPNGToTexture

func LoadPNGToTexture(data []byte) (graphics.Texture, error)

LoadPNGToTexture loads a byte slice as a PNG image and buffers it into a new OpenGL texture.

func LoadRGBAToTexture

func LoadRGBAToTexture(rgba []byte, imageSize int32) graphics.Texture

LoadRGBAToTexture takes a byte slice and throws it into an OpenGL texture.

func LoadRGBAToTextureExt

func LoadRGBAToTextureExt(rgba []byte, imageSize, magFilter, minFilter, wrapS, wrapT int32) graphics.Texture

LoadRGBAToTextureExt takes a byte slice and throws it into an OpenGL texture and takes a set of flags to set texture parameters for filtering and texture wrapping.

func LoadRGBToTexture

func LoadRGBToTexture(rgb []byte, imageSize int32) graphics.Texture

LoadRGBToTexture takes a byte slice and throws it into an OpenGL texture.

func LoadRGBToTextureExt

func LoadRGBToTextureExt(rgb []byte, imageSize, magFilter, minFilter, wrapS, wrapT int32) graphics.Texture

LoadRGBToTextureExt takes a byte slice and throws it into an OpenGL texture and takes a set of flags to set texture parameters for filtering and texture wrapping.

func MapUvToCubemap

func MapUvToCubemap(side int, s, t float32) (float32, float32)

MapUvToCubemap takes a UV coordinate that is in range ([0..1],[0..1]) with respect to one side and returns a UV coordinate s and t value that is mapped to a single cubemap texture looking something like this:

.____.
|    |
| T  |

.____.____.____.____. | | | | | | L | F | R | Bk | .----.----.----.----.

|    |
| Bt |
.----.

The resulting coordintes are for a texture wrapped around the outside of the cube.

func RadiansToDegrees

func RadiansToDegrees(x float64) float64

RadiansToDegrees converts radians to degrees.

func SetGraphics

func SetGraphics(g graphics.GraphicsProvider)

SetGraphics sets the GraphicsProvider to use for all operations in the fizzle package.

Types

type Camera

type Camera interface {
	GetViewMatrix() mgl.Mat4
	GetPosition() mgl.Vec3
}

Camera is an interface defining a common interface between different styles of cameras.

type Material added in v0.3.0

type Material struct {
	// Shader is the program used to render this material; This can be overridden
	// by using a DrawWithShader* function so that this material's shader doesn't
	// get used.
	Shader *RenderShader

	// DiffuseTex is the diffuse texture for the material.
	DiffuseTex graphics.Texture

	// NormalsTex is the normal map texture for the material.
	NormalsTex graphics.Texture

	// SpecularTex is the spcular map texture for the material.
	SpecularTex graphics.Texture

	// CustomTex is an array of textures that can be used for specific purposes
	// by client code that are not covered by other textures specified in this
	// structure.
	CustomTex [MaxCustomTextures]graphics.Texture

	// DiffuseColor is the material color for the renderable. This is
	// displayed outright by the shader or often blended with the
	// diffuse texture.
	DiffuseColor mgl.Vec4

	// SpecularColor is the material specular color for the renderable
	// and is used to control the color of the specular highlight.
	//
	// It can be thought of the topcoat layer color to the DiffuseColor's
	// base paint layer color.
	SpecularColor mgl.Vec4

	// Shininess is the specular coefficient used to control the tightness
	// of the specular highlight. It represents the power the specular factor will
	// be raised to -- therefore values between (0.0 - 1.0) will yield different
	// results than values >= 1.0.
	Shininess float32
}

Material is a type that represents the visual properties for a Renderable.

func NewMaterial added in v0.3.0

func NewMaterial() *Material

NewMaterial creates a new material with sane defaults.

type OrbitCamera

type OrbitCamera struct {
	// contains filtered or unexported fields
}

OrbitCamera makes a camera orbit at a given angle away with the distance controlled by a parameter. This poor ASCII art illustrates the relation of the target position, the angle between the camera and the up vector and where the camera ends up getting positioned.

Camera   up
 \       |
  \      |
   \-ang-|
    \    |
     \   |
      \  |
     {target}

After that's calculated, Camera->Up is used as a radius for a circle to then orbit the camera around the target based on the rotation parameter.

func NewOrbitCamera

func NewOrbitCamera(target mgl.Vec3, vertAngle float32, distance float32, rotation float32) *OrbitCamera

NewOrbitCamera that looks at a target at a given vertAngle and at a given distance. See the OrbitCamera struct for ascii art on this.

func (*OrbitCamera) AddDistance

func (c *OrbitCamera) AddDistance(delta float32)

AddDistance adds a value to the distance of the camera away from the target and then updates the internal data.

func (*OrbitCamera) GetDistance

func (c *OrbitCamera) GetDistance() float32

GetDistance returns the distance of the camera away from the target.

func (*OrbitCamera) GetForwardVector

func (c *OrbitCamera) GetForwardVector() mgl.Vec3

GetForwardVector returns the vector representing the forward direction of the camera.

func (*OrbitCamera) GetPosition

func (c *OrbitCamera) GetPosition() mgl.Vec3

GetPosition returns the eye position of the camera.

func (*OrbitCamera) GetTarget

func (c *OrbitCamera) GetTarget() mgl.Vec3

GetTarget returns the target position of the camera.

func (*OrbitCamera) GetViewMatrix

func (c *OrbitCamera) GetViewMatrix() mgl.Mat4

GetViewMatrix returns a 4x4 matrix for the view rot/trans/scale.

func (*OrbitCamera) Rotate

func (c *OrbitCamera) Rotate(delta float32)

Rotate updates the rotation of the camera orbiting around the target.

func (*OrbitCamera) RotateVertical

func (c *OrbitCamera) RotateVertical(delta float32)

RotateVertical updates the vertical rotation of the camera orbiting around the target.

func (*OrbitCamera) SetDistance

func (c *OrbitCamera) SetDistance(d float32)

SetDistance sets the distance of the camera from the target and updates the internal data.

func (*OrbitCamera) SetTarget

func (c *OrbitCamera) SetTarget(t mgl.Vec3)

SetTarget changes the target position of the camera.

type PreLinkBinder

type PreLinkBinder func(p graphics.Program)

PreLinkBinder is a prototype for a function to be called before a shader program is linked

type Rectangle3D

type Rectangle3D struct {
	// Bottom defines the bottom corner opposite of Top.
	Bottom mgl.Vec3

	// TOp defines the top corner opposite of Bottom.
	Top mgl.Vec3
}

Rectangle3D defines a rectangular 3d structure by two points.

func GetBoundingRect

func GetBoundingRect(verts []float32) (r Rectangle3D)

GetBoundingRect calculates a bounding Rectangle3D for all of the vertices pssed in.

func (*Rectangle3D) DeltaX

func (rect *Rectangle3D) DeltaX() float32

DeltaX is the change of the X-axis component of a Rectangle3D.

func (*Rectangle3D) DeltaY

func (rect *Rectangle3D) DeltaY() float32

DeltaY is the change of the Y-axis component of a Rectangle3D.

func (*Rectangle3D) DeltaZ

func (rect *Rectangle3D) DeltaZ() float32

DeltaZ is the change of the Z-axis component of a Rectangle3D.

type RenderShader

type RenderShader struct {
	// Prog is the OpenGL program associated with the RenderShader.
	Prog graphics.Program
	// contains filtered or unexported fields
}

RenderShader is an OpenGL shader that is used for easier access to uniforms and attributes at runtime.

func LoadShaderProgram

func LoadShaderProgram(vertShader, fragShader string, prelink PreLinkBinder) (*RenderShader, error)

LoadShaderProgram loads shaders from code passed in as strings, compiles and then attaches them to a new program. preLink is an optional function that will be called just prior to linking the shaders into a program.

func LoadShaderProgramFromFiles

func LoadShaderProgramFromFiles(baseFilename string, prelink PreLinkBinder) (*RenderShader, error)

LoadShaderProgramFromFiles loads the GLSL shaders from the files specified. This function expects that the vertex and fragment shader files can be opened by appending the '.vs' and '.fs' extensions respectively to the baseFilename. preLink is an optional function that will be called just prior to linking the shaders into a program.

func NewRenderShader

func NewRenderShader(p graphics.Program) *RenderShader

NewRenderShader creates a new RenderShader object with the OpenGL shader specified.

func (*RenderShader) AssertAttribsExist

func (rs *RenderShader) AssertAttribsExist(names ...string) error

AssertAttribsExist attempts to get attributes for the names passed in and returns an error value if a name doesn't exist.

func (*RenderShader) AssertUniformsExist

func (rs *RenderShader) AssertUniformsExist(names ...string) error

AssertUniformsExist attempts to get uniforms for the names passed in and returns an error value if a name doesn't exist.

func (*RenderShader) Destroy

func (rs *RenderShader) Destroy()

Destroy deallocates the shader from OpenGL.

func (*RenderShader) GetAttribLocation

func (rs *RenderShader) GetAttribLocation(name string) int32

GetAttribLocation gets the location of a attribute variable, preferably from an internal cached value stored in a map.

func (*RenderShader) GetUniformLocation

func (rs *RenderShader) GetUniformLocation(name string) int32

GetUniformLocation gets the location of a uniform variable, preferably from an internal cached value stored in a map.

type Renderable

type Renderable struct {
	// FaceCount specifies how many elements to draw when rendered.
	FaceCount uint32

	// Scale is the scaling vector for the Renderable used to modify
	// the size of the object.
	Scale mgl.Vec3

	// Location is the world-space location of Renderable.
	Location mgl.Vec3

	// Rotation is the world-space rotation quaternion of the Renderable, which is
	// different than LocalRotation and the pivot is {0,0,0} in world-space.
	Rotation mgl.Quat

	// LocalRotation is the local rotation quaternion for the Renderable, which is
	// different than the Rotation property and pivots around the model's origin.
	LocalRotation mgl.Quat

	// AnimationTime keeps track of the time value to use for the animation
	// currently applied (if any) to the Renderable.
	AnimationTime float32

	// BoundingRect is the unscaled, unrotated bounding rectangle for the renderable.
	BoundingRect Rectangle3D

	// IsVisible should be set to true if the object is to be rendered.
	IsVisible bool

	// IsGroup should be set to true if the renderable should only render its children objects
	// and that this Renderable itself should not be drawn.
	IsGroup bool

	// Core is the RenderableCore object that contains the renderable data that can
	// be shadered between multiple Renderable objects if needed.
	Core *RenderableCore

	// Material is the material for the object that will controll visible properties
	// used during rendering.
	Material *Material

	// Parent can be set to a Renderable that should be considered this Renderable's
	// 'Parent' which will make some properties relative to this parent object (e.g.
	// Location).
	Parent *Renderable

	// Children is a slice of Renderables that are the Renderable's children objects
	// that should be drawn with this renderable.
	Children []*Renderable
}

Renderable defines the data necessary to draw an object in OpenGL. This structure focuses more on 'instance' type of data which is typically not sharable between multiple Renderable instances.

func CreateCube

func CreateCube(xmin, ymin, zmin, xmax, ymax, zmax float32) *Renderable

CreateCube creates a cube based on the dimensions specified.

func CreateCubeMappedSphere

func CreateCubeMappedSphere(gridSize int, radius float32, cubemapUvs bool) *Renderable

CreateCubeMappedSphere creates a sphere that can be used for cubemaps based on the dimensions specified. If the cubemapUvs parameter is true, it will map face UVs to a single cubemap texture; if this parameter is false, then each face is mapped [0..1] for UVs.

func CreateFromGombz

func CreateFromGombz(srcMesh *gombz.Mesh) *Renderable

CreateFromGombz creates a new Renderable based on model data from a GOMBZ file. (http://www.github.com/tbogdala/gombz)

func CreateLine

func CreateLine(x0, y0, z0, x1, y1, z1 float32) *Renderable

CreateLine makes a line between a two points rendered as graphics.LINES.

func CreateLineV added in v0.2.0

func CreateLineV(a, b mgl.Vec3) *Renderable

CreateLine makes a line between a two points rendered as graphics.LINES.

func CreatePlaneXY

func CreatePlaneXY(x0, y0, x1, y1 float32) *Renderable

CreatePlaneXY makes a 2d Renderable object on the XY plane for the given size, where (x0,y0) is the lower left and (x1, y1) is the upper right coordinate.

func CreatePlaneXZ

func CreatePlaneXZ(x0, z0, x1, z1 float32) *Renderable

CreatePlaneXZ makes a 2d Renderable object on the XZ plane for the given size, where (x0,z0) is the lower left and (x1, z1) is the upper right coordinate.

func CreateSphere

func CreateSphere(radius float32, rings int, sectors int) *Renderable

CreateSphere generates a 3d uv-sphere with the given radius and returns a Renderable.

func CreateWireframeCircle

func CreateWireframeCircle(xmin, ymin, zmin, radius float32, segments int, axis int) *Renderable

CreateWireframeCircle makes a cirle with vertex and element VBO objects designed to be rendered as graphics.LINES.

func CreateWireframeConeSegmentXZ

func CreateWireframeConeSegmentXZ(xmin, ymin, zmin, bottomRadius, topRadius, length float32, circleSegments, sideSegments int) *Renderable

CreateWireframeConeSegmentXZ makes a cone segment with vertex and element VBO objects designed to be rendered as graphics.LINES wtih the default orientation of the cone segment along +Y.

func CreateWireframeCube

func CreateWireframeCube(xmin, ymin, zmin, xmax, ymax, zmax float32) *Renderable

CreateWireframeCube makes a cube with vertex and element VBO objects designed to be rendered as graphics.LINES.

func NewRenderable

func NewRenderable() *Renderable

NewRenderable creates a new Renderable object and a new RenderableCore.

func (*Renderable) AddChild

func (r *Renderable) AddChild(child *Renderable)

AddChild sets the Renderable passed in as a child of the renderable.

func (*Renderable) Clone

func (r *Renderable) Clone() *Renderable

Clone makes a new Renderable object but shares the Core member between the two. This allows for a different location, scale, rotation, etc ...

func (*Renderable) Destroy

func (r *Renderable) Destroy()

Destroy releases the RenderableCore data.

func (*Renderable) GetTransformMat4

func (r *Renderable) GetTransformMat4() mgl.Mat4

GetTransformMat4 creates a transform matrix that can be used to transform a vertex of the Renderable into world space.

func (*Renderable) HasSkeleton

func (r *Renderable) HasSkeleton() bool

HasSkeleton returns true if the Renderable has bones associated with it.

func (*Renderable) HasSkeletonDeep

func (r *Renderable) HasSkeletonDeep() bool

HasSkeletonDeep returns true if the Renderable, or any child, has bones associated with it.

func (*Renderable) Map

func (r *Renderable) Map(f RenderableMapF)

Map takes a function as a parameter that will be called for the Renderable and all child Renderable objects recursively.

type RenderableCore

type RenderableCore struct {
	// Skeleton is the animatable skeleton object for the renderable.
	Skeleton *Skeleton

	// Vao is the OpenGL vertex array object for the renderable.
	Vao uint32

	// VaoInitialized indicates whether or not the Vao has been bound yet.
	VaoInitialized bool

	// VertVBO indicates the VBO that contains the vertex data.
	VertVBO graphics.Buffer

	// UvVBO indicates the VBO that contains the UV data.
	UvVBO graphics.Buffer

	// NormsVBO indicates the VBO that contains the normal vector data.
	NormsVBO graphics.Buffer

	// TangentsVBO indicates the VBO that contains the tangent vector data.
	TangentsVBO graphics.Buffer

	// ElementsVBO indicates the VBO that defines the element indices data.
	ElementsVBO graphics.Buffer

	// BoneFidsVBO indicates the VBO that defines what bones affect a given vertex.
	// These are passed to the shader as floats due to better compatability with GLSL.
	BoneFidsVBO graphics.Buffer

	// BoneWeightsVBO indicates the VBO that defines how strong a bone affects a given vertex.
	BoneWeightsVBO graphics.Buffer

	// ComboVBO1 is a user-customizable VBO object to be bound to the RenderShader.
	ComboVBO1 graphics.Buffer

	// ComboVBO2 is a user-customizable VBO object to be bound to the RenderShader.
	ComboVBO2 graphics.Buffer

	// VBOStride should be set to the total number of bytes that exist in a VBO for
	// a single object.
	//
	// This is set to non-zero when members like VertVBO, UvVBO,
	// NormsVBO, etc... are set tot the same VBO object but the data is interleaved.
	// When this is the case, the corresponding Offset members (e.g. VertVBOOffset)
	// should be set as well.
	VBOStride int32

	// VertVBOOffset is the offset in bytes from the start of a vertex definition needed
	// to read the vertex information.
	VertVBOOffset int

	// UvVBOOffset is the offset in bytes from the start of a vertex definition needed
	// to read the UV information.
	UvVBOOffset int

	// NormsVBOOffset is the offset in bytes from the start of a vertex definition needed
	// to read the normal vector information.
	NormsVBOOffset int

	// TangentsVBOOffset is the offset in bytes from the start of a vertex definition needed
	// to read the tangent vector information.
	TangentsVBOOffset int

	// BoneFidsVBOOffset is the offset in bytes from the start of a vertex definition needed
	// to read the bone float id information.
	BoneFidsVBOOffset int

	// BoneWeightsVBOOffset is the offset in bytes from the start of a vertex definition needed
	// to read the bone weighting information.
	BoneWeightsVBOOffset int

	// ComboVBO1Offset is the offset in bytes from the start of a vertex definition needed
	// to read the customizable information.
	ComboVBO1Offset int

	// ComboVBO2Offset is the offset in bytes from the start of a vertex definition needed
	// to read the customizable information.
	ComboVBO2Offset int

	// IsDestroyed should be set to true if the Renderable has been Destroy()'d.
	IsDestroyed bool
}

RenderableCore contains data that is needed to draw an object on the screen. Further, data here can be shared between multiple Renderable instances.

func NewRenderableCore

func NewRenderableCore() *RenderableCore

NewRenderableCore creates a new RenderableCore object.

func (*RenderableCore) DestroyCore

func (r *RenderableCore) DestroyCore()

DestroyCore releases the OpenGL VBO and VAO objects but does not release things that could be shared like Tex0 and then marks the object as destroyed.

type RenderableMapF

type RenderableMapF func(r *Renderable)

RenderableMapF defines the type of a function that can be passed to Renderable.Map().

type Skeleton

type Skeleton struct {
	// Bones is a slice of Bone objects defined for the mesh. This
	// will not be modified by the Skeleton methods and can be shared
	// between many instances of Skeleton.
	Bones []gombz.Bone

	// Animations is a slice of Animation objects that are compatible
	// with the Bones of the Skeleton.
	Animations []gombz.Animation

	// PoseTransforms are the final updated matrices for each bone
	// that represents it current position, scale and rotation in the pose.
	// This is the matrix stack that can get passed to OpenGL to transform vertices.
	PoseTransforms []mgl.Mat4
	// contains filtered or unexported fields
}

Skeleton contains data for Bones and all of the matrix transforms for them based on animations.

func NewSkeleton

func NewSkeleton(bones []gombz.Bone, animations []gombz.Animation) *Skeleton

NewSkeleton creates a new Skeleton that shares a bones slice.

func (*Skeleton) Animate

func (skel *Skeleton) Animate(animation *gombz.Animation, time float32)

Animate interpolates the animation at the given time then calculates the bone transformation matrixes.

type TextureArray

type TextureArray struct {
	// TextureIndexes is a map between the texture name to an index in the texture array object.
	TextureIndexes TextureArrayIndexes

	// Texture is the OpenGL texture object for all the loaded textures.
	Texture graphics.Texture
}

TextureArray encapsulates the map of texture indexes within a texture array and the texture array OpenGL object itself.

func NewTextureArray

func NewTextureArray(texsize int32, count int32) *TextureArray

NewTextureArray creates a new TextureArray object with an empty map.

func (*TextureArray) LoadImageAsPNG

func (texArray *TextureArray) LoadImageAsPNG(texName string, data []byte, size int32, arrayIndex int32) error

LoadImageAsPNG loads an image byte array as a PNG and buffers it into the texture array object

func (*TextureArray) LoadImageFromFiles

func (texArray *TextureArray) LoadImageFromFiles(texName string, filePath string, size int32, arrayIndex int32) error

LoadImageFromFiles loads an image file and buffers it into the texture array object

func (*TextureArray) LoadImagesFromFiles

func (texArray *TextureArray) LoadImagesFromFiles(filepaths map[string]string, size int32, startingIndex int32) error

LoadImagesFromFiles loads image files and buffers them into the texture array object

type TextureArrayIndexes

type TextureArrayIndexes map[string]int32

TextureArrayIndexes is the type for a map that has a 'user friendly' texture name to a index for a given texture.

type TextureManager

type TextureManager struct {
	// contains filtered or unexported fields
}

TextureManager provides an easy way to load textures to OpenGL and to access the textures by name elsewhere.

func NewTextureManager

func NewTextureManager() *TextureManager

NewTextureManager creates a new TextureManager object with empty storage.

func (*TextureManager) Destroy

func (tm *TextureManager) Destroy()

Destroy deletes all of the stored textures from OpenGL and resets the storage map.

func (*TextureManager) GetTexture

func (tm *TextureManager) GetTexture(keyToUse string) (graphics.Texture, bool)

GetTexture attempts to access the texture by name in storage and returns the OpenGL object and a bool indicating if the texture was found in storage.

func (*TextureManager) LoadTexture

func (tm *TextureManager) LoadTexture(keyToUse string, path string) (graphics.Texture, error)

LoadTexture loads a texture specified by path into OpenGL and then stores the object in the storage map under the specified keyToUse.

type YawPitchCamera

type YawPitchCamera struct {
	// contains filtered or unexported fields
}

YawPitchCamera keeps track of the view rotation and position and provides utility methods to generate a view matrix. It provides a free-moving camera that is adjusted by yaw and pitch which, at default, looks down -Z with +Y as the up vector.

func NewYawPitchCamera

func NewYawPitchCamera(eyePosition mgl.Vec3) *YawPitchCamera

NewYawPitchCamera will create a new camera at a given position with no rotations applied.

func (*YawPitchCamera) GetForwardVector

func (c *YawPitchCamera) GetForwardVector() mgl.Vec3

GetForwardVector returns a unit vector rotated in the same direction that the camera is rotated.

func (*YawPitchCamera) GetPitch

func (c *YawPitchCamera) GetPitch() float32

GetPitch returns the pitch of the camera in radians

func (*YawPitchCamera) GetPosition

func (c *YawPitchCamera) GetPosition() mgl.Vec3

GetPosition returns the eye position of the camera

func (*YawPitchCamera) GetRoll

func (c *YawPitchCamera) GetRoll() float32

GetRoll returns the roll of the camera in radians

func (*YawPitchCamera) GetRotation

func (c *YawPitchCamera) GetRotation() mgl.Quat

GetRotation gets the rotation quaternion for the camera. This is calculated automatically when the yaw and pitch values get updated through other methods.

func (*YawPitchCamera) GetSideVector

func (c *YawPitchCamera) GetSideVector() mgl.Vec3

GetSideVector returns a unit vector rotated in the same direction that the camera is rotated, but perpendicular and oriented to the 'side'. If {0, 0, 1} is forward then the side will be {-1, 0, 0}.

func (*YawPitchCamera) GetUpVector

func (c *YawPitchCamera) GetUpVector() mgl.Vec3

GetUpVector returns a unit vector rotated in the same direction that the camera is rotated, but perpendicular and oriented to the 'up'. If {0, 0, 1} is forward then the up will be {0, 1, 0}.

func (*YawPitchCamera) GetViewMatrix

func (c *YawPitchCamera) GetViewMatrix() mgl.Mat4

GetViewMatrix returns a 4x4 matrix for the view rot/trans/scale.

func (*YawPitchCamera) GetYaw

func (c *YawPitchCamera) GetYaw() float32

GetYaw returns the yaw of the camera in radians

func (*YawPitchCamera) LookAt

func (c *YawPitchCamera) LookAt(target mgl.Vec3, distance float32)

LookAt adjusts the position of the camera based on the camera yaw/pitch and the target location passed in. It does automatically adjust the camera's internal rotation quaternion.

func (*YawPitchCamera) LookAtDirect

func (c *YawPitchCamera) LookAtDirect(target mgl.Vec3)

LookAtDirect calculates a view rotation using the current Camera position so that it will look at the target coordinate. Uses standard up axis of {0,1,0}.

func (*YawPitchCamera) SetPosition

func (c *YawPitchCamera) SetPosition(x, y, z float32)

SetPosition sets the position of the camera with an absolute coordinate.

func (*YawPitchCamera) SetRotation

func (c *YawPitchCamera) SetRotation(q mgl.Quat)

SetRotation allows the caller to set the rotation of the camera; this will then derive the yaw, pitch and roll from the quaternion parameter.

func (*YawPitchCamera) SetYawAndPitch

func (c *YawPitchCamera) SetYawAndPitch(yaw, pitch float32)

SetYawAndPitch sets the yaw and pitch radians directly for the camera

func (*YawPitchCamera) UpdatePitch

func (c *YawPitchCamera) UpdatePitch(delta float32)

UpdatePitch adds a delta to the camera pitch and regenerates the rotation quaternion.

func (*YawPitchCamera) UpdatePosition

func (c *YawPitchCamera) UpdatePosition(dX, dY, dZ float32)

UpdatePosition adds delta values to the eye position vector.

func (*YawPitchCamera) UpdateRoll

func (c *YawPitchCamera) UpdateRoll(delta float32)

UpdateRoll adds a delta to the camera roll and regenerates the rotation quaternion.

func (*YawPitchCamera) UpdateYaw

func (c *YawPitchCamera) UpdateYaw(delta float32)

UpdateYaw adds a delta to the camera yaw and regenerates the rotation quaternion.

Directories

Path Synopsis
cmd
Package component consists of a Manager type that can load component files defined in JSON so that application assets can be defined outside of the binary.
Package component consists of a Manager type that can load component files defined in JSON so that application assets can be defined outside of the binary.
examples
input
Package renderer is a package that defines a common interface for the deferred and forward renderers.
Package renderer is a package that defines a common interface for the deferred and forward renderers.
forward
Package forward is a package that defines an OpenGL forward renderer.
Package forward is a package that defines an OpenGL forward renderer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL