Documentation ¶
Overview ¶
Package vu - the virtual universe engine, provides 3D game support. Vu wraps subsystems like rendering, physics, asset loading, audio, etc. to provide higher level functionality that includes:
- Transform graphs and composite objects.
- Timestepped update/render loop.
- Access to user input events.
- Cameras and transform manipulation.
- Loading and controlling groups of graphics and audio assets.
Refer to the vu/eg package for examples of engine functionality.
Vu dependencies are:
- Vulkan for graphics card access. See package vu/render.
- OpenAL for sound card access. See package vu/audio.
- WinAPI for Windows display and input. See package vu/device.
Index ¶
- Constants
- type Attr
- type Body
- type Camera
- func (c *Camera) At() (x, y, z float64)
- func (c *Camera) Lookat() *lin.Q
- func (c *Camera) Move(x, y, z float64, q *lin.Q)
- func (c *Camera) Ray(mx, my, ww, wh int) (x, y, z float64, err error)
- func (c *Camera) RayCastDisk(ray, center, normal *lin.V3, radius float64) (hit bool)
- func (c *Camera) RayCastSphere(ray, sphere *lin.V3, radius float64) (hit bool)
- func (c *Camera) Screen(wx, wy, wz float64, ww, wh int) (sx, sy int)
- func (c *Camera) SetAt(x, y, z float64) *Camera
- func (c *Camera) SetClip(near, far float64) *Camera
- func (c *Camera) SetFov(deg float64) *Camera
- func (c *Camera) SetLook(q *lin.Q)
- func (c *Camera) SetPitch(deg float64) *Camera
- func (c *Camera) SetYaw(deg float64) *Camera
- type Config
- type Engine
- func (eng *Engine) AddScene(st SceneType) *Entity
- func (eng *Engine) AddSound(name string) (soundID uint32)
- func (eng *Engine) ImportAssets(assetFilenames ...string)
- func (eng *Engine) MakeMeshes(name string, meshes []load.MeshData) (err error)
- func (eng *Engine) Run(updator Updator)
- func (eng *Engine) SetResizeListener(resizer Resizer)
- func (eng *Engine) Shutdown()
- func (eng *Engine) ToggleFullscreen()
- type Entity
- func (e *Entity) AddInstancedModel(assets ...string) (me *Entity)
- func (e *Entity) AddLabel(s string, wrap int, assets ...string) (me *Entity)
- func (e *Entity) AddLight(lightType int) *Entity
- func (e *Entity) AddModel(assets ...string) (me *Entity)
- func (e *Entity) AddPart() *Entity
- func (e *Entity) AddToSimulation(b Body) *Entity
- func (e *Entity) AddUpdatableTexture(eng *Engine, name string, img *image.NRGBA) *Entity
- func (e *Entity) At() (x, y, z float64)
- func (e *Entity) Body() Body
- func (e *Entity) Cam() *Camera
- func (e *Entity) Cull(culled bool)
- func (e *Entity) Culled() bool
- func (e *Entity) Dispose(eng *Engine)
- func (e *Entity) DisposeBody()
- func (e *Entity) Exists() bool
- func (e *Entity) LabelSize() (w, h int)
- func (e *Entity) Move(x, y, z float64, dir *lin.Q)
- func (e *Entity) PlaySound(soundID uint32)
- func (e *Entity) Push(x, y, z float64)
- func (e *Entity) Scale() (x, y, z float64)
- func (e *Entity) SetAa(x, y, z, angleInRadians float64) *Entity
- func (e *Entity) SetAt(x, y, z float64) *Entity
- func (e *Entity) SetColor(r, g, b, a float64) *Entity
- func (e *Entity) SetInstanceData(eng *Engine, count uint32, data []load.Buffer) (me *Entity)
- func (e *Entity) SetLayer(layer uint8) *Entity
- func (e *Entity) SetLight(r, g, b, intensity float32) *Entity
- func (e *Entity) SetListener()
- func (e *Entity) SetMetallicRoughness(metallic bool, roughness float64) *Entity
- func (e *Entity) SetModelUniform(uniform string, data interface{}) *Entity
- func (e *Entity) SetScale(x, y, z float64) *Entity
- func (e *Entity) SetSpin(x, y, z float64) *Entity
- func (e *Entity) SetView(q *lin.Q) *Entity
- func (e *Entity) Spin(x, y, z float64) *Entity
- func (e *Entity) UpdateTexture(eng *Engine, img *image.NRGBA) *Entity
- func (e *Entity) View() (q *lin.Q)
- func (e *Entity) World() (wx, wy, wz float64)
- func (e *Entity) WorldRot() (q *lin.Q)
- func (e *Entity) WriteImageText(fontID, s string, xoff, yoff int, dst *image.NRGBA) (me *Entity)
- type Input
- type Resizer
- type SceneType
- type Updator
Constants ¶
const ( K0 = device.K0 // 0 48 Standard keyboard numbers. K1 = device.K1 // 1 49 " K2 = device.K2 // 2 50 " K3 = device.K3 // 3 51 " K4 = device.K4 // 4 52 " K5 = device.K5 // 5 53 " K6 = device.K6 // 6 54 " K7 = device.K7 // 7 55 " K8 = device.K8 // 8 56 " K9 = device.K9 // 9 57 " KA = device.KA // A 65 Standard keyboard letters. KB = device.KB // B 66 " KC = device.KC // C 67 " KD = device.KD // D 68 " KE = device.KE // E 69 " KF = device.KF // F 70 " KG = device.KG // G 71 " KH = device.KH // H 72 " KI = device.KI // I 73 " KJ = device.KJ // J 74 " KK = device.KK // K 75 " KL = device.KL // L 76 " KM = device.KM // M 77 " KN = device.KN // N 78 " KO = device.KO // O 79 " KP = device.KP // P 80 " KQ = device.KQ // Q 81 " KR = device.KR // R 82 " KS = device.KS // S 83 " KT = device.KT // T 84 " KU = device.KU // U 85 " KV = device.KV // V 86 " KW = device.KW // W 87 " KX = device.KX // X 88 " KY = device.KY // Y 89 " KZ = device.KZ // Z 90 " KEqual = device.KEqual // = 61 Standard keyboard punctuation keys. KMinus = device.KMinus // - 45 " KRBkt = device.KRBkt // ] 93 " KLBkt = device.KLBkt // [ 91 " KQuote = device.KQuote // " 34 " KSemi = device.KSemi // ; 59 " KBSl = device.KBSl // \ 92 " KComma = device.KComma // , 44 " KSlash = device.KSlash // / 47 " KDot = device.KDot // . 46 " KGrave = device.KGrave // ~ 126 " KRet = device.KRet // ⇦ 8678 " KTab = device.KTab // ⇨ 8680 " KSpace = device.KSpace // ▭ 9645 " KDel = device.KDel // ⇍ 8653 " KEsc = device.KEsc // ⊶ 8886 " KF1 = device.KF1 // α 945 General Function keys. KF2 = device.KF2 // β 946 " KF3 = device.KF3 // γ 947 " KF4 = device.KF4 // δ 948 " KF5 = device.KF5 // ε 949 " KF6 = device.KF6 // ζ 950 " KF7 = device.KF7 // η 951 " KF8 = device.KF8 // θ 952 " KF9 = device.KF9 // ι 953 " KF10 = device.KF10 // κ 954 " KF11 = device.KF11 // λ 955 " KF12 = device.KF12 // μ 956 " KF13 = device.KF13 // ν 957 " KF14 = device.KF14 // ξ 958 " KF15 = device.KF15 // ο 959 " KF16 = device.KF16 // π 960 " KF17 = device.KF17 // ρ 961 " KF18 = device.KF18 // ς 962 " KF19 = device.KF19 // σ 963 " KHome = device.KHome // ◈ 9672 Specific function keys. KPgUp = device.KPgUp // ⇑ 8657 " KFDel = device.KFDel // ⇏ 8655 " KEnd = device.KEnd // ▣ 9635 " KPgDn = device.KPgDn // ⇓ 8659 " KALeft = device.KALeft // ◀ 9664 Arrow keys KARight = device.KARight // ▶ 9654 " KADown = device.KADown // ▼ 9660 " KAUp = device.KAUp // ▲ 9650 " KPDot = device.KPDot // ⊙ 8857 Extended keyboard keypad keys KPMlt = device.KPMlt // ⊗ 8855 " KPAdd = device.KPAdd // ⊕ 8853 " KPClr = device.KPClr // ⊠ 8864 " KPDiv = device.KPDiv // ⊘ 8856 " KPEnt = device.KPEnt // ⇐ 8656 " KPSub = device.KPSub // ⊖ 8854 " KPEql = device.KPEql // ⊜ 8860 " KP0 = device.KP0 // ₀ 8320 " KP1 = device.KP1 // ₁ 8321 " KP2 = device.KP2 // ₂ 8322 " KP3 = device.KP3 // ₃ 8323 " KP4 = device.KP4 // ₄ 8324 " KP5 = device.KP5 // ₅ 8325 " KP6 = device.KP6 // ₆ 8326 " KP7 = device.KP7 // ₇ 8327 " KP8 = device.KP8 // ₈ 8328 " KP9 = device.KP9 // ₉ 8329 " KML = device.KML // ◐ 9680 Mouse buttons treated like keys. KMM = device.KMM // ◓ 9683 " KMR = device.KMR // ◑ 9681 " KCtl = device.KCtl // ● 9679 Modifier keys. KFn = device.KFn // ◍ 9677 " KShift = device.KShift // ⇧ 8679 " KCmd = device.KCmd // ◆ 9670 " KAlt = device.KAlt // ◇ 9671 " )
Expose the device package keys as a convenience so the device package does not always need to be included. The symbol associated to each key is shown in the comments.
Keys are expected to be used for controlling game actions. There is no text entry or text layout support.
const ( DirectionalLight = iota // no falloff ie: the sun PointLight // falloff ie: light bulb )
Types of lights
const ( KinematicSim bool = false // movable StaticSim bool = true // immovable )
Simulated bodies can either be kinematic-movable or static-immovable.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attr ¶ added in v0.20.0
type Attr func(*Config) // type for attribute overrides
Attr defines optional application attributes that can be used to configure the engine.
eng, err := vu.NewEngine( vu.Title("Keyboard Controller"), vu.Size(200, 200, 900, 400), vu.Background(0.45, 0.45, 0.45, 1.0), )
func Background ¶ added in v0.20.0
Background display clear color.
func Size ¶ added in v0.8.0
Size sets the window top left corner location and size in pixels when using windowed mode.
type Body ¶ added in v0.8.0
Body wraps physics.Body allowing the engine app to access common physics methods without including the physics package.
type Camera ¶
type Camera struct {
// contains filtered or unexported fields
}
Camera makes rendered models visible within a frame. A camera is associated with a scene where it is used to render the scenes models.
Camera combines a location+orientation using separate pitch angle tracking. This allows use as a first-person camera which can limit up/down to a given range (often 180 degrees). Overall orientation is calculated by combining Pitch and Yaw. Look is for walking cameras, Lookat is for flying cameras.
func (*Camera) Lookat ¶
Lookat returns the current camera rotation. The rotation is created from Pitch and Yaw.
func (*Camera) Move ¶
Move adjusts the camera location relative to the given orientation. For orientation, use Lookat() to fly, use Look to run along XZ.
func (*Camera) Ray ¶
Ray applies inverse transforms to derive world space coordinates for a ray projected from the camera through the mouse's mx,my screen position given window width and height ww,wh.
func (*Camera) RayCastDisk ¶ added in v0.21.0
RayCastDisk checks for collision between a ray originating from the camera and a circle in world space. The ray must be a unit vector, see: camera.Ray(). See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
func (*Camera) RayCastSphere ¶ added in v0.20.0
RayCastSphere checks for collision between a ray originating from the camera and a sphere in world space. The ray must be a unit vector, see: camera.Ray().
- see: http://en.wikipedia.org/wiki/Line–sphere_intersection
func (*Camera) Screen ¶
Screen applies the camera transform on a 3D point in world space wx,wy,wz and returns the 2D screen coordinate sx,sy. The window width and height ww,wh are needed. Essentially the reverse of the Ray method and duplicates what is done in the rendering pipeline. Returns -1,-1 if the point is outside the screen area.
func (*Camera) SetAt ¶ added in v0.6.5
SetAt positions the camera in world space The camera instance is returned.
func (*Camera) SetClip ¶ added in v0.8.0
SetClip sets the near and far clipping planes for perspective and orthographic cameras.
func (*Camera) SetFov ¶ added in v0.8.0
SetFov sets the field of view for perspective projection cameras. Ignored for orthographic projection cameras.
func (*Camera) SetLook ¶ added in v0.21.0
SetLook directly sets the camera orientation to the given quaternion. The orientation will be overwritten with new calls to SetPitch and SetYaw.
type Config ¶ added in v0.20.0
type Config struct {
// contains filtered or unexported fields
}
Config contains configuration attributes that can be set by the game before running the engine game loop.
type Engine ¶ added in v0.20.0
type Engine struct {
// contains filtered or unexported fields
}
Engine controls the engine subsystems and the run loop.
eng.Run(updater) // Run the engine.
func NewEngine ¶ added in v0.20.0
NewEngine is called by the game to initialize the engine and its subsystems like rendering, physics, and audio. Eg:
eng, err := vu.NewEngine(vu.Windowed())
The app uses eng to create the initial scenes prior to running the engine.
func (*Engine) AddScene ¶ added in v0.20.0
AddScene creates a new application scene graph and camera. Scene graphs use zero to indicate that this is a root node.
func (*Engine) AddSound ¶ added in v0.20.0
AddSound loads audio data and returns a unique sound identifier. Passing the sound identifier to an entity PlaySound() method will assigned using SetListener(). Sounds are louder the closer the played sound to the sound listener.
name is the sound asset filename without the .wav extension.
func (*Engine) ImportAssets ¶ added in v0.20.0
ImportAssets creates assets from the given asset files. Expected to be called at least once initialization to create the assets referenced by models in a scene.
func (*Engine) MakeMeshes ¶ added in v0.21.0
MakeMeshes loads application generated mesh data.
func (*Engine) Run ¶ added in v0.20.0
Run the game engine. This method starts the game loop and does not return until the game shuts down. The game Update method is called each time the game loop updates.
func (*Engine) SetResizeListener ¶ added in v0.20.0
SetResizeListener sets the application callback for when the window is resized.
func (*Engine) Shutdown ¶ added in v0.20.0
func (eng *Engine) Shutdown()
Shutdown is an application request to close down the engine. Mark the engine as shutdown which will cause the game loop to exit.
func (*Engine) ToggleFullscreen ¶ added in v0.21.0
func (eng *Engine) ToggleFullscreen()
ToggleFullscreen switches between a borderless fullscreen window and a bordered window.
type Entity ¶ added in v0.20.0
type Entity struct {
// contains filtered or unexported fields
}
Entity track resoures created by the application. Common application entities are scenes and models, eg:
scene := eng.AddScene(vu.Scene3D) model := scene.AddModel("shd:pbr0", "msh:box0", "mat:box0")
Scenes are used to group models with cameras. Models are used to group assets with shaders. Together they are used to render frames.
func (*Entity) AddInstancedModel ¶ added in v0.20.0
AddInstancedModel adds a model where the immediate children are instances of the parent model. The parent model will be rendered for each childs transform data.
func (*Entity) AddLabel ¶ added in v0.20.0
AddLabel creates a static string model for 2D or 3D text display. It is intended for single letters, words or small phrases. eg:
letter2D := scene.AddLabel("text", 0, "shd:icon", "fnt:lucon18", "tex:color:lucon18")
A label requires a texture based shader, font mapping data, and a font texture atlas. The mesh is calculated from the string once the font assets have loaded.
func (*Entity) AddLight ¶ added in v0.20.0
AddLight adds a light to a scene. Lighting aware shaders combine the light with the models material values. Objects in the scene with lighting capable shaders will be influenced by the light.
Each light is has a position and orientation in world space. The default position is 0,0,0 and the default direction is 0,0,-1. A lights default color is white 1,1,1.
Depends on Eng.AddScene.
func (*Entity) AddModel ¶ added in v0.20.0
AddModel adds a new transform with a model component to the given entity.
func (*Entity) AddPart ¶ added in v0.21.0
AddPart creates a new entity with a point-of-view component (pov). A pov adds a location and orientation to an entity. The entity can now be positioned and rotated.
The entity is also added to the scene graph so that this entities world pov is affected by its parents and will also affect any child entities created from this one.
func (*Entity) AddToSimulation ¶ added in v0.20.0
AddToSimulation Bodies are generally set on top level pov transforms which always have valid world coordindates.
b: a physics body eg: vu.Box, vu.Sphere.
func (*Entity) AddUpdatableTexture ¶ added in v0.21.0
AddUpdatableTexture uploads 2 textures to the GPU. One is for rendering and one is for updating.
func (*Entity) At ¶ added in v0.20.0
At gets the local space location. This is world space if the entity does not have a parent.
Returns 0,0,0 if there is no transform component.
func (*Entity) Body ¶ added in v0.20.0
Body returns the physics body for this entity, returning nil if no physics body exists.
func (*Entity) Cam ¶ added in v0.20.0
Cam returns the camera instace for a scene, returning nil if the entity is not a scene.
Depends on Eng.AddScene.
func (*Entity) Culled ¶ added in v0.20.0
Culled returns true if entity has been culled from rendering.
Depends on transform. Returns true if there was no part component.
func (*Entity) Dispose ¶ added in v0.20.0
Dispose all components for this entity. If the entity is a scene or a part with child entities, then all child entities are also disposed.
func (*Entity) DisposeBody ¶ added in v0.20.0
func (e *Entity) DisposeBody()
DisposeBody removes the physics body from the given entity. Does nothing if there was no physics body.
func (*Entity) Exists ¶ added in v0.20.0
Exists returns true if the entity has been created and not yet disposed.
func (*Entity) LabelSize ¶ added in v0.20.0
LabelSize returns the Label width, height in pixels. Returns 0 if not loaded.
Depends on Ent.AddLabel.
func (*Entity) Move ¶ added in v0.20.0
Move directly affects the location by the given translation amounts along the given direction. Physics bodies should use Body.Push which affects velocity.
Depends on transform.
func (*Entity) PlaySound ¶ added in v0.20.0
PlaySound plays the given sound at this entities location.
- soundID : entity created with Eng.AddSound.
Depends on Entity.AddSound.
func (*Entity) Push ¶ added in v0.20.0
Push adds to the body's linear velocity. It is a wrapper for physics.Body.Push
Depends on AddToSimultation.
func (*Entity) Scale ¶ added in v0.20.0
Scale retrieves the local per-axis scale values at 3 separate XYZ values. World scale needs to incorporate any parents values.
Depends on transform. Returns 0,0,0 if there is no part component.
func (*Entity) SetAa ¶ added in v0.20.0
SetAa sets the orientation using the given axis and angle information.
Depends on transform.
func (*Entity) SetAt ¶ added in v0.20.0
SetAt sets the local space location, ie: relative to its parent. This is world space if there is no parent location.
Depends on transform.
func (*Entity) SetColor ¶ added in v0.20.0
SetColor sets the solid color for this model - not the texture color information. This affects shaders like pbr0 and label that use model uniform "color" The color is passed per object instance in the shader push constants.
Depends on Entity.AddModel.
func (*Entity) SetInstanceData ¶ added in v0.20.0
SetInstanceData sets the instance data for an instanced model.
func (*Entity) SetLayer ¶ added in v0.21.0
SetLayer helps to order draws - normally 2D UI elements. Layer values are 0 (first) to 15 (last). Normally packets are drawn in the creation order, but this allows specific ordering.
Depends on Entity.AddModel.
func (*Entity) SetLight ¶ added in v0.20.0
SetLight assigns a color and intensity to the light. The lights color is combined with objects material color to produce a final color. The R,G,B light values are between 0 (no color), and 1 (full color).
Depends on Entity.AddLight.
func (*Entity) SetListener ¶ added in v0.20.0
func (e *Entity) SetListener()
SetListener sets the location of the sound listener to be this entity.
Depends on Entity.AddSound.
func (*Entity) SetMetallicRoughness ¶ added in v0.20.0
SetMetallicRoughness sets the PBR material attributes for this model, not the texture material information. This affects pbr0 or pbr1 shaders. The PBR material is passed per object instance in the shader push constants.
Depends on Entity.AddModel.
func (*Entity) SetModelUniform ¶ added in v0.21.0
SetModelUniform sets data for the given uniform. The uniform data is passed to the shader.
func (*Entity) SetScale ¶ added in v0.20.0
SetScale assigns the XYZ per-axis scale values. Scale default is 1, greater than 1 enlarges, a positive fraction shrinks.
Depends on transform.
func (*Entity) SetSpin ¶ added in v0.20.0
SetSpin sets the rotation to 0 before spinning the entity like the Spin method.
Depends on transform.
func (*Entity) SetView ¶ added in v0.20.0
SetView directly sets the parts orientation. Often used to align this part with the orientation of another. Orientation is relative to parent. World space if no parent orientation.
Depends on transform.
func (*Entity) Spin ¶ added in v0.20.0
Spin rotates x,y,z degrees about the X,Y,Z axis. The spins are combined in XYZ order, but generally this is used to spin about a single axis at a time.
Depends on transform.
func (*Entity) UpdateTexture ¶ added in v0.21.0
UpdateTexture uploads the image to the updatable texture and then swaps the updatable texture with the render texture.
func (*Entity) View ¶ added in v0.20.0
View returns the orientation of the Part. Orientation is a rotation about a axis. Orientation is relative to any parent Parts. It is world space if there is no parent orientation. Direct updates to the rotation matrix must be done with SetView or SetAa.
Depends on transform.
func (*Entity) World ¶ added in v0.20.0
World returns the world space coordinates for this entity. World space is recalculated immediately on any change.
Depends on transform.
func (*Entity) WorldRot ¶ added in v0.20.0
WorldRot returns the world rotation for this entity. WorldRot space is recalculated immediately on any change and returns nil if the entity does not have a part.
Depends on transform.
func (*Entity) WriteImageText ¶ added in v0.21.0
WriteImageText uses the font assets associated with this model to write a string to the given image. The starting string location is specified by indent is in pixels line number is based on the font size.
type Input ¶
Input is used to communicate user input to the application.
User input is the current cursor location, current pressed keys, mouse buttons, and modifiers. These are sent to the game each Update() callback. Overall the keyboard is treated like a gamepad controller. Keys and buttons are pressed or not pressed.
type Resizer ¶ added in v0.20.0
type Resizer interface { // Resize is called when the window is resized. Resize(windowLeft, windowTop int32, windowWidth, windowHeight uint32) }
Resizer is responsible for updating an application when the window is resized. It is implemented by the user app and set on startup.
type SceneType ¶ added in v0.20.0
type SceneType uint32
SceneType corresponds to a render pass.
- Scene3D for the normal world rendering.
- Scene2D for the UI overlay rendering.
type Updator ¶ added in v0.20.0
type Updator interface { // Update allows applications to change state prior to the next render. // Update is called each game loop update (many times a second) while the // game is running. // eng : the game // i : user input refreshed prior to each call. Update(eng *Engine, i *Input, delta time.Duration) }
Updator is responsible for updating application state each render frame. It is implemented by the user app and passed to eng.Run().
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
assets
|
|
shaders
Package shaders contains the builtin engine shaders.
|
Package shaders contains the builtin engine shaders. |
Package audio plays sounds at 3D locations.
|
Package audio plays sounds at 3D locations. |
Package eg is used to test and demo different aspects of the vu engine.
|
Package eg is used to test and demo different aspects of the vu engine. |
internal
|
|
Package load fetches disk based 3D asset data.
|
Package load fetches disk based 3D asset data. |
math
|
|
lin
Package lin provides a linear math library intended for games.
|
Package lin provides a linear math library intended for games. |
Package physics is a real-time simulation of real-world physics.
|
Package physics is a real-time simulation of real-world physics. |