From 914ca1ffdc4d2f6c69ae3037f58f27a7eda7a67f Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Thu, 11 Nov 2021 18:34:45 +0100 Subject: [PATCH] Add new functions --- raylib/rmodels.go | 29 +++++++++++++++++++++++++++++ raylib/rtext.go | 26 ++++++++++++++++++++++---- raylib/rtextures.go | 11 +++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/raylib/rmodels.go b/raylib/rmodels.go index 461f3fb..45c2574 100644 --- a/raylib/rmodels.go +++ b/raylib/rmodels.go @@ -194,6 +194,14 @@ func UnloadModel(model Model) { C.UnloadModel(*cmodel) } +// GetModelBoundingBox - Compute model bounding box limits (considers all meshes +func GetModelBoundingBox(model Model) BoundingBox { + cmodel := model.cptr() + ret := C.GetModelBoundingBox(*cmodel) + v := newBoundingBoxFromPointer(unsafe.Pointer(&ret)) + return v +} + // UnloadMesh - Unload mesh from memory (RAM and/or VRAM) func UnloadMesh(mesh *Mesh) { cmesh := mesh.cptr() @@ -208,6 +216,16 @@ func ExportMesh(mesh Mesh, fileName string) { C.ExportMesh(*cmesh, cfileName) } +// GenMeshPoly - Generate polygonal mesh +func GenMeshPoly(sides int, radius float32) Mesh { + csides := (C.int)(sides) + cradius := (C.float)(radius) + + ret := C.GenMeshPoly(csides, cradius) + v := newMeshFromPointer(unsafe.Pointer(&ret)) + return v +} + // GenMeshPlane - Generate plane mesh (with subdivisions) func GenMeshPlane(width, length float32, resX, resZ int) Mesh { cwidth := (C.float)(width) @@ -264,6 +282,17 @@ func GenMeshCylinder(radius, height float32, slices int) Mesh { return v } +// GenMeshCone - Generate cone/pyramid mesh +func GenMeshCone(radius, height float32, slices int) Mesh { + cradius := (C.float)(radius) + cheight := (C.float)(height) + cslices := (C.int)(slices) + + ret := C.GenMeshCone(cradius, cheight, cslices) + v := newMeshFromPointer(unsafe.Pointer(&ret)) + return v +} + // GenMeshTorus - Generate torus mesh func GenMeshTorus(radius, size float32, radSeg, sides int) Mesh { cradius := (C.float)(radius) diff --git a/raylib/rtext.go b/raylib/rtext.go index 98e6e97..d6a2d03 100644 --- a/raylib/rtext.go +++ b/raylib/rtext.go @@ -133,15 +133,33 @@ func MeasureTextEx(font Font, text string, fontSize float32, spacing float32) Ve return v } -// GetGlyphIndex - Returns index position for a unicode character on spritefont -func GetGlyphIndex(font Font, character int32) int32 { +// GetGlyphIndex - Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found +func GetGlyphIndex(font Font, codepoint int32) int32 { cfont := font.cptr() - ccharacter := (C.int)(character) - ret := C.GetGlyphIndex(*cfont, ccharacter) + ccodepoint := (C.int)(codepoint) + ret := C.GetGlyphIndex(*cfont, ccodepoint) v := (int32)(ret) return v } +// GetGlyphInfo - Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found +func GetGlyphInfo(font Font, codepoint int32) GlyphInfo { + cfont := font.cptr() + ccodepoint := (C.int)(codepoint) + ret := C.GetGlyphInfo(*cfont, ccodepoint) + v := newGlyphInfoFromPointer(unsafe.Pointer(&ret)) + return v +} + +// GetGlyphAtlasRec - Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found +func GetGlyphAtlasRec(font Font, codepoint int32) Rectangle { + cfont := font.cptr() + ccodepoint := (C.int)(codepoint) + ret := C.GetGlyphAtlasRec(*cfont, ccodepoint) + v := newRectangleFromPointer(unsafe.Pointer(&ret)) + return v +} + // DrawFPS - Shows current FPS func DrawFPS(posX int32, posY int32) { cposX := (C.int)(posX) diff --git a/raylib/rtextures.go b/raylib/rtextures.go index 3a78d99..f7b3bd2 100644 --- a/raylib/rtextures.go +++ b/raylib/rtextures.go @@ -355,6 +355,17 @@ func ImageColorReplace(image *Image, color, replace Color) { C.ImageColorReplace(cimage, *ccolor, *creplace) } +// GetImageColor - Get image pixel color at (x, y) position +func GetImageColor(image Image, x, y int32) Color { + cimage := image.cptr() + cx := (C.int)(x) + cy := (C.int)(y) + + ret := C.GetImageColor(*cimage, cx, cy) + v := newColorFromPointer(unsafe.Pointer(&ret)) + return v +} + // ImageClearBackground - Clear image background with given color func ImageClearBackground(dst *Image, color Color) { cdst := dst.cptr()