This commit is contained in:
Milan Nikolic 2017-02-01 01:50:51 +01:00
parent 0682698f0b
commit 969ba1dc21
8 changed files with 125 additions and 81 deletions

View file

@ -9,119 +9,138 @@ import (
// Linear Easing functions
// Linear None
func LinearNone(t, b, c, d float32) float32 {
return c*t/d + b
}
// Linear In
func LinearIn(t, b, c, d float32) float32 {
return c*t/d + b
}
// Linear Out
func LinearOut(t, b, c, d float32) float32 {
return c*t/d + b
}
// Linear In Out
func LinearInOut(t, b, c, d float32) float32 {
return c*t/d + b
}
// Sine Easing functions
// Sine In
func SineIn(t, b, c, d float32) float32 {
return -c*float32(math.Cos(float64(t/d)*(math.Pi/2))) + c + b
}
// Sine Out
func SineOut(t, b, c, d float32) float32 {
return c*float32(math.Sin(float64(t/d)*(math.Pi/2))) + b
}
// Sine In Out
func SineInOut(t, b, c, d float32) float32 {
return -c/2*(float32(math.Cos(math.Pi*float64(t/d)))-1) + b
}
// Circular Easing functions
// Circ In
func CircIn(t, b, c, d float32) float32 {
t = t / d
return -c*(float32(math.Sqrt(float64(1-t*t)))-1) + b
}
// Circ Out
func CircOut(t, b, c, d float32) float32 {
return c*float32(math.Sqrt(1-float64((t/d-1)*t))) + b
}
// Circ In Out
func CircInOut(t, b, c, d float32) float32 {
t = t / d * 2
if t < 1 {
return -c/2*(float32(math.Sqrt(float64(1-t*t)))-1) + b
} else {
}
t = t - 2
return c/2*(float32(math.Sqrt(1-float64(t*t)))+1) + b
}
}
// Cubic Easing functions
// Cubic In
func CubicIn(t, b, c, d float32) float32 {
t = t / d
return c*t*t*t + b
}
// Cubic Out
func CubicOut(t, b, c, d float32) float32 {
t = t/d - 1
return c*(t*t*t+1) + b
}
// Cubic In Out
func CubicInOut(t, b, c, d float32) float32 {
t = t / d * 2
if t < 1 {
return (c/2*t*t*t + b)
} else {
}
t = t - 2
return c/2*(t*t*t+2) + b
}
}
// Quadratic Easing functions
// Quad In
func QuadIn(t, b, c, d float32) float32 {
t = t / d
return c*t*t + b
}
// Quad Out
func QuadOut(t, b, c, d float32) float32 {
t = t / d
return (-c*t*(t-2) + b)
}
// Quad In Out
func QuadInOut(t, b, c, d float32) float32 {
t = t / d * 2
if t < 1 {
return ((c / 2) * (t * t)) + b
} else {
return -c/2*((t-1)*(t-3)-1) + b
}
return -c/2*((t-1)*(t-3)-1) + b
}
// Exponential Easing functions
// Expo In
func ExpoIn(t, b, c, d float32) float32 {
if t == 0 {
return b
} else {
return (c*float32(math.Pow(2, 10*float64(t/d-1))) + b)
}
return (c*float32(math.Pow(2, 10*float64(t/d-1))) + b)
}
// Expo Out
func ExpoOut(t, b, c, d float32) float32 {
if t == d {
return (b + c)
} else {
return c*(-float32(math.Pow(2, -10*float64(t/d)))+1) + b
}
return c*(-float32(math.Pow(2, -10*float64(t/d)))+1) + b
}
// Expo In Out
func ExpoInOut(t, b, c, d float32) float32 {
if t == 0 {
return b
@ -134,26 +153,29 @@ func ExpoInOut(t, b, c, d float32) float32 {
if t < 1 {
return (c/2*float32(math.Pow(2, 10*float64(t-1))) + b)
} else {
}
t = t - 1
return (c/2*(-float32(math.Pow(2, -10*float64(t)))+2) + b)
}
}
// Back Easing functions
// Back In
func BackIn(t, b, c, d float32) float32 {
s := float32(1.70158)
t = t / d
return c*t*t*((s+1)*t-s) + b
}
// Back Out
func BackOut(t, b, c, d float32) float32 {
s := float32(1.70158)
t = t/d - 1
return c*(t*t*((s+1)*t+s)+1) + b
}
// Back In Out
func BackInOut(t, b, c, d float32) float32 {
s := float32(1.70158)
s = s * 1.525
@ -161,18 +183,20 @@ func BackInOut(t, b, c, d float32) float32 {
if t < 1 {
return c/2*(t*t*((s+1)*t-s)) + b
} else {
}
t = t - 2
return c/2*(t*t*((s+1)*t+s)+2) + b
}
}
// Bounce Easing functions
// Bounce In
func BounceIn(t, b, c, d float32) float32 {
return (c - BounceOut(d-t, 0, c, d) + b)
}
// Bounce Out
func BounceOut(t, b, c, d float32) float32 {
t = t / d
if t < (1 / 2.75) {
@ -183,22 +207,24 @@ func BounceOut(t, b, c, d float32) float32 {
} else if t < (2.5 / 2.75) {
t = t - (2.25 / 2.75)
return c*(7.5625*t*t+0.9375) + b
} else {
}
t = t - (2.625 / 2.75)
return c*(7.5625*t*t+0.984375) + b
}
}
// Bounce In Out
func BounceInOut(t, b, c, d float32) float32 {
if t < d/2 {
return BounceIn(t*2, 0, c, d)*0.5 + b
} else {
return BounceOut(t*2-d, 0, c, d)*0.5 + c*0.5 + b
}
return BounceOut(t*2-d, 0, c, d)*0.5 + c*0.5 + b
}
// Elastic Easing functions
// Elastic In
func ElasticIn(t, b, c, d float32) float32 {
if t == 0 {
return b
@ -218,6 +244,7 @@ func ElasticIn(t, b, c, d float32) float32 {
return -(postFix * float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p)))) + b
}
// Elastic Out
func ElasticOut(t, b, c, d float32) float32 {
if t == 0 {
return b
@ -236,6 +263,7 @@ func ElasticOut(t, b, c, d float32) float32 {
return a*float32(math.Pow(2, -10*float64(t)))*float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p))) + c + b
}
// Elastic In Out
func ElasticInOut(t, b, c, d float32) float32 {
if t == 0 {
return b
@ -255,9 +283,9 @@ func ElasticInOut(t, b, c, d float32) float32 {
t = t - 1
postFix := a * float32(math.Pow(2, 10*float64(t)))
return -0.5*(postFix*float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p)))) + b
} else {
}
t = t - 1
postFix := a * float32(math.Pow(2, -10*(float64(t))))
return postFix*float32(math.Sin(float64(t*d-s)*(2*math.Pi)/float64(p)))*0.5 + c + b
}
}

View file

@ -119,7 +119,6 @@ const (
)
// GUI elements states
const (
ButtonDefault = iota
ButtonHover
@ -127,6 +126,7 @@ const (
ButtonClicked
)
// GUI elements states
const (
ToggleUnactive = iota
ToggleHover
@ -134,6 +134,7 @@ const (
ToggleActive
)
// GUI elements states
const (
ComboboxUnactive = iota
ComboboxHover
@ -141,18 +142,21 @@ const (
ComboboxActive
)
// GUI elements states
const (
SpinnerDefault = iota
SpinnerHover
SpinnerPressed
)
// GUI elements states
const (
CheckboxStatus = iota
CheckboxHover
CheckboxPressed
)
// GUI elements states
const (
SliderDefault = iota
SliderHover
@ -160,7 +164,7 @@ const (
)
// Current GUI style (default light)
var style []int = []int{
var style = []int{
0xf5f5f5ff, // GLOBAL_BASE_COLOR
0xf5f5f5ff, // GLOBAL_BORDER_COLOR
0xf5f5f5ff, // GLOBAL_TEXT_COLOR
@ -263,7 +267,7 @@ var style []int = []int{
}
// GUI property names (to read/write style text files)
var propertyName []string = []string{
var propertyName = []string{
"GLOBAL_BASE_COLOR",
"GLOBAL_BORDER_COLOR",
"GLOBAL_TEXT_COLOR",
@ -457,9 +461,9 @@ func Button(bounds raylib.Rectangle, text string) bool {
if buttonState == ButtonClicked {
return true
} else {
return false
}
return false
}
// Toggle Button element, returns true when active
@ -624,7 +628,7 @@ func ComboBox(bounds raylib.Rectangle, comboText []string, comboActive int) int
if raylib.CheckCollisionPointRec(raylib.GetMousePosition(), bounds) || raylib.CheckCollisionPointRec(raylib.GetMousePosition(), click) {
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
comboActive += 1
comboActive++
if comboActive >= comboNum {
comboActive = 0
}
@ -852,8 +856,8 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
buttonSide := 0
framesCounter := 0
valueSpeed := false
var framesCounter int
var valueSpeed bool
// Update control
if raylib.CheckCollisionPointRec(mousePoint, leftButtonBound) || raylib.CheckCollisionPointRec(mousePoint, rightButtonBound) || raylib.CheckCollisionPointRec(mousePoint, labelBoxBound) {
@ -862,14 +866,14 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
buttonSide = 1
if value > minValue {
value -= 1
value--
}
} else if raylib.IsKeyDown(raylib.KeyRight) {
spinnerState = SpinnerPressed
buttonSide = 2
if value < maxValue {
value += 1
value++
}
}
}
@ -892,7 +896,7 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
if value > minValue {
if framesCounter >= 30 {
value -= 1
value--
}
}
}
@ -914,7 +918,7 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
if value < maxValue {
if framesCounter >= 30 {
value += 1
value++
}
}
}

View file

@ -8,8 +8,8 @@ import "C"
import "unsafe"
import "reflect"
// Some basic Defines
const (
// Some basic Defines
Pi = 3.1415927
Deg2rad = 0.017453292
Rad2deg = 57.295776
@ -168,6 +168,7 @@ const (
GamepadXboxAxisRt = 5
)
// Gestures
type Gestures int32
// Gestures type
@ -186,6 +187,7 @@ const (
GesturePinchOut Gestures = C.GESTURE_PINCH_OUT
)
// Camera mode
type CameraMode int32
// Camera system modes
@ -201,57 +203,57 @@ const (
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
var (
// Light Gray
LightGray Color = NewColor(200, 200, 200, 255)
LightGray = NewColor(200, 200, 200, 255)
// Gray
Gray Color = NewColor(130, 130, 130, 255)
Gray = NewColor(130, 130, 130, 255)
// Dark Gray
DarkGray Color = NewColor(80, 80, 80, 255)
DarkGray = NewColor(80, 80, 80, 255)
// Yellow
Yellow Color = NewColor(253, 249, 0, 255)
Yellow = NewColor(253, 249, 0, 255)
// Gold
Gold Color = NewColor(255, 203, 0, 255)
Gold = NewColor(255, 203, 0, 255)
// Orange
Orange Color = NewColor(255, 161, 0, 255)
Orange = NewColor(255, 161, 0, 255)
// Pink
Pink Color = NewColor(255, 109, 194, 255)
Pink = NewColor(255, 109, 194, 255)
// Red
Red Color = NewColor(230, 41, 55, 255)
Red = NewColor(230, 41, 55, 255)
// Maroon
Maroon Color = NewColor(190, 33, 55, 255)
Maroon = NewColor(190, 33, 55, 255)
// Green
Green Color = NewColor(0, 228, 48, 255)
Green = NewColor(0, 228, 48, 255)
// Lime
Lime Color = NewColor(0, 158, 47, 255)
Lime = NewColor(0, 158, 47, 255)
// Dark Green
DarkGreen Color = NewColor(0, 117, 44, 255)
DarkGreen = NewColor(0, 117, 44, 255)
// Sky Blue
SkyBlue Color = NewColor(102, 191, 255, 255)
SkyBlue = NewColor(102, 191, 255, 255)
// Blue
Blue Color = NewColor(0, 121, 241, 255)
Blue = NewColor(0, 121, 241, 255)
// Dark Blue
DarkBlue Color = NewColor(0, 82, 172, 255)
DarkBlue = NewColor(0, 82, 172, 255)
// Purple
Purple Color = NewColor(200, 122, 255, 255)
Purple = NewColor(200, 122, 255, 255)
// Violet
Violet Color = NewColor(135, 60, 190, 255)
Violet = NewColor(135, 60, 190, 255)
// Dark Purple
DarkPurple Color = NewColor(112, 31, 126, 255)
DarkPurple = NewColor(112, 31, 126, 255)
// Beige
Beige Color = NewColor(211, 176, 131, 255)
Beige = NewColor(211, 176, 131, 255)
// Brown
Brown Color = NewColor(127, 106, 79, 255)
Brown = NewColor(127, 106, 79, 255)
// Dark Brown
DarkBrown Color = NewColor(76, 63, 47, 255)
DarkBrown = NewColor(76, 63, 47, 255)
// White
White Color = NewColor(255, 255, 255, 255)
White = NewColor(255, 255, 255, 255)
// Black
Black Color = NewColor(0, 0, 0, 255)
Black = NewColor(0, 0, 0, 255)
// Blank (Transparent)
Blank Color = NewColor(0, 0, 0, 0)
Blank = NewColor(0, 0, 0, 0)
// Magenta
Magenta Color = NewColor(255, 0, 255, 255)
Magenta = NewColor(255, 0, 255, 255)
// Ray White (RayLib Logo White)
RayWhite Color = NewColor(245, 245, 245, 255)
RayWhite = NewColor(245, 245, 245, 255)
)
// Vector2 type

View file

@ -28,9 +28,9 @@ type Mesh struct {
// Vertex indices (in case vertex data comes indexed)
Indices *uint16
// OpenGL Vertex Array Object id
VaoId uint32
VaoID uint32
// OpenGL Vertex Buffer Objects id (7 types of vertex data)
VboId [7]uint32
VboID [7]uint32
}
func (m *Mesh) cptr() *C.Mesh {
@ -38,8 +38,8 @@ func (m *Mesh) cptr() *C.Mesh {
}
// Returns new Mesh
func NewMesh(vertexCount, triangleCount int32, vertices, texcoords, texcoords2, normals, tangents *float32, colors *uint8, indices *uint16, vaoId uint32, vboId [7]uint32) Mesh {
return Mesh{vertexCount, triangleCount, vertices, texcoords, texcoords2, normals, tangents, colors, indices, vaoId, vboId}
func NewMesh(vertexCount, triangleCount int32, vertices, texcoords, texcoords2, normals, tangents *float32, colors *uint8, indices *uint16, vaoID uint32, vboID [7]uint32) Mesh {
return Mesh{vertexCount, triangleCount, vertices, texcoords, texcoords2, normals, tangents, colors, indices, vaoID, vboID}
}
// Returns new Mesh from pointer

View file

@ -12,7 +12,7 @@ import (
// rRES file header (8 byte)
type RRESFileHeader struct {
// File identifier: rRES (4 byte)
Id [4]int8
ID [4]int8
// File version and subversion (2 byte)
Version uint16
// Number of resources in this file (2 byte)
@ -22,7 +22,7 @@ type RRESFileHeader struct {
// rRES info header, every resource includes this header (16 byte + 16 byte)
type RRESInfoHeader struct {
// Resource unique identifier (4 byte)
Id uint32
ID uint32
// Resource data type (1 byte)
DataType uint8
// Resource data compression type (1 byte)
@ -71,6 +71,7 @@ const (
RRESCompBrotli
)
// Image formats
const (
// 8 bit per pixel (no alpha)
RRESImUncompGrayscale = iota + 1
@ -110,6 +111,7 @@ const (
RRESImCompAstc8x8Rgba
)
// RRESVert
const (
RRESVertPosition = iota
RRESVertTexcoord1
@ -122,6 +124,7 @@ const (
RRESVertIndex
)
// RRESVert
const (
RRESVertByte = iota
RRESVertShort
@ -133,12 +136,12 @@ const (
// Load resource from file (only one)
// NOTE: Returns uncompressed data with parameters, only first resource found
func LoadResource(fileName string) []byte {
return LoadResourceById(fileName, 0)
return LoadResourceByID(fileName, 0)
}
// Load resource from file by id
// NOTE: Returns uncompressed data with parameters, search resource by id
func LoadResourceById(fileName string, rresId int) (data []byte) {
func LoadResourceByID(fileName string, rresID int) (data []byte) {
file, err := os.Open(fileName)
if err != nil {
TraceLog(LogWarning, "[%s] rRES raylib resource file could not be opened", fileName)
@ -159,7 +162,7 @@ func LoadResourceById(fileName string, rresId int) (data []byte) {
//fmt.Printf("%+v\n", fileHeader)
// Verify "rRES" identifier
id := fmt.Sprintf("%c", fileHeader.Id)
id := fmt.Sprintf("%c", fileHeader.ID)
if id != "[r R E S]" {
TraceLog(LogWarning, "[%s] This is not a valid raylib resource file", fileName)
return
@ -179,7 +182,7 @@ func LoadResourceById(fileName string, rresId int) (data []byte) {
file.Seek(int64(unsafe.Sizeof(infoHeader)), os.SEEK_CUR)
if int(infoHeader.Id) == rresId {
if int(infoHeader.ID) == rresID {
// Read resource data block
data = make([]byte, infoHeader.DataSize)
file.Read(data)
@ -194,7 +197,7 @@ func LoadResourceById(fileName string, rresId int) (data []byte) {
}
if len(data) > 0 {
TraceLog(LogInfo, "[%s][ID %d] Resource data loaded successfully", fileName, infoHeader.Id)
TraceLog(LogInfo, "[%s][ID %d] Resource data loaded successfully", fileName, infoHeader.ID)
}
} else {
// Skip required data to read next resource infoHeader
@ -203,7 +206,7 @@ func LoadResourceById(fileName string, rresId int) (data []byte) {
}
if len(data) == 0 {
TraceLog(LogInfo, "[%s][ID %d] Requested resource could not be found", fileName, rresId)
TraceLog(LogInfo, "[%s][ID %d] Requested resource could not be found", fileName, rresID)
}
return

View file

@ -8,6 +8,7 @@ import "C"
import "unsafe"
import "reflect"
// Vr device
type VrDevice int32
// Head Mounted Display devices
@ -23,6 +24,7 @@ const (
HmdFoveVr VrDevice = C.HMD_FOVE_VR
)
// Blend mode
type BlendMode int32
// Color blending modes (pre-defined)
@ -35,7 +37,7 @@ const (
// Shader type (generic shader)
type Shader struct {
// Shader program id
Id uint32
ID uint32
// Vertex attribute location point (default-location = 0)
VertexLoc int32
// Texcoord attribute location point (default-location = 1)

View file

@ -7,6 +7,7 @@ package raylib
import "C"
import "unsafe"
// Texture format
type TextureFormat int32
// Texture formats
@ -50,6 +51,7 @@ const (
CompressedAstc8x8Rgba TextureFormat = C.COMPRESSED_ASTC_8x8_RGBA
)
// Texture filter mode
type TextureFilterMode int32
// Texture parameters: filter mode
@ -70,6 +72,7 @@ const (
FilterAnisotropic16x TextureFilterMode = C.FILTER_ANISOTROPIC_16X
)
// Texture wrap mode
type TextureWrapMode int32
// Texture parameters: wrap mode
@ -112,7 +115,7 @@ func NewImageFromPointer(ptr unsafe.Pointer) *Image {
// NOTE: Data stored in GPU memory
type Texture2D struct {
// OpenGL texture id
Id uint32
ID uint32
// Texture base width
Width int32
// Texture base height
@ -140,7 +143,7 @@ func NewTexture2DFromPointer(ptr unsafe.Pointer) Texture2D {
// RenderTexture2D type, for texture rendering
type RenderTexture2D struct {
// Render texture (fbo) id
Id uint32
ID uint32
// Color buffer attachment texture
Texture Texture2D
// Depth buffer attachment texture

View file

@ -17,6 +17,7 @@ const (
var traceDebugMsgs = false
// Trace log
func TraceLog(msgType int, text string, v ...interface{}) {
switch msgType {
case LogInfo:
@ -33,6 +34,7 @@ func TraceLog(msgType int, text string, v ...interface{}) {
}
}
// Set debug messages
func SetDebug(enabled bool) {
traceDebugMsgs = enabled
}