Fix Mesh, add missing functions, move gestures to file
This commit is contained in:
parent
8fa575dce2
commit
19d2f59142
6 changed files with 165 additions and 113 deletions
|
@ -7,6 +7,18 @@ package raylib
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
// Camera mode
|
||||||
|
type CameraMode int32
|
||||||
|
|
||||||
|
// Camera system modes
|
||||||
|
const (
|
||||||
|
CameraCustom CameraMode = C.CAMERA_CUSTOM
|
||||||
|
CameraFree CameraMode = C.CAMERA_FREE
|
||||||
|
CameraOrbital CameraMode = C.CAMERA_ORBITAL
|
||||||
|
CameraFirstPerson CameraMode = C.CAMERA_FIRST_PERSON
|
||||||
|
CameraThirdPerson CameraMode = C.CAMERA_THIRD_PERSON
|
||||||
|
)
|
||||||
|
|
||||||
// Set camera mode (multiple camera modes available)
|
// Set camera mode (multiple camera modes available)
|
||||||
func SetCameraMode(camera Camera, mode CameraMode) {
|
func SetCameraMode(camera Camera, mode CameraMode) {
|
||||||
ccamera := camera.cptr()
|
ccamera := camera.cptr()
|
||||||
|
|
101
raylib/core.go
101
raylib/core.go
|
@ -172,37 +172,6 @@ const (
|
||||||
GamepadXboxAxisRt = 5
|
GamepadXboxAxisRt = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
// Gestures
|
|
||||||
type Gestures int32
|
|
||||||
|
|
||||||
// Gestures type
|
|
||||||
// NOTE: It could be used as flags to enable only some gestures
|
|
||||||
const (
|
|
||||||
GestureNone Gestures = C.GESTURE_NONE
|
|
||||||
GestureTap Gestures = C.GESTURE_TAP
|
|
||||||
GestureDoubletap Gestures = C.GESTURE_DOUBLETAP
|
|
||||||
GestureHold Gestures = C.GESTURE_HOLD
|
|
||||||
GestureDrag Gestures = C.GESTURE_DRAG
|
|
||||||
GestureSwipeRight Gestures = C.GESTURE_SWIPE_RIGHT
|
|
||||||
GestureSwipeLeft Gestures = C.GESTURE_SWIPE_LEFT
|
|
||||||
GestureSwipeUp Gestures = C.GESTURE_SWIPE_UP
|
|
||||||
GestureSwipeDown Gestures = C.GESTURE_SWIPE_DOWN
|
|
||||||
GesturePinchIn Gestures = C.GESTURE_PINCH_IN
|
|
||||||
GesturePinchOut Gestures = C.GESTURE_PINCH_OUT
|
|
||||||
)
|
|
||||||
|
|
||||||
// Camera mode
|
|
||||||
type CameraMode int32
|
|
||||||
|
|
||||||
// Camera system modes
|
|
||||||
const (
|
|
||||||
CameraCustom CameraMode = C.CAMERA_CUSTOM
|
|
||||||
CameraFree CameraMode = C.CAMERA_FREE
|
|
||||||
CameraOrbital CameraMode = C.CAMERA_ORBITAL
|
|
||||||
CameraFirstPerson CameraMode = C.CAMERA_FIRST_PERSON
|
|
||||||
CameraThirdPerson CameraMode = C.CAMERA_THIRD_PERSON
|
|
||||||
)
|
|
||||||
|
|
||||||
// Some Basic Colors
|
// Some Basic Colors
|
||||||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
||||||
var (
|
var (
|
||||||
|
@ -919,73 +888,3 @@ func GetTouchPosition(index int32) Vector2 {
|
||||||
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable a set of gestures using flags
|
|
||||||
func SetGesturesEnabled(gestureFlags uint32) {
|
|
||||||
cgestureFlags := (C.uint)(gestureFlags)
|
|
||||||
C.SetGesturesEnabled(cgestureFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if a gesture have been detected
|
|
||||||
func IsGestureDetected(gesture Gestures) bool {
|
|
||||||
cgesture := (C.int)(gesture)
|
|
||||||
ret := C.IsGestureDetected(cgesture)
|
|
||||||
v := bool(int(ret) == 1)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get latest detected gesture
|
|
||||||
func GetGestureDetected() Gestures {
|
|
||||||
ret := C.GetGestureDetected()
|
|
||||||
v := (Gestures)(ret)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get touch points count
|
|
||||||
func GetTouchPointsCount() int32 {
|
|
||||||
ret := C.GetTouchPointsCount()
|
|
||||||
v := (int32)(ret)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gesture hold time in milliseconds
|
|
||||||
func GetGestureHoldDuration() float32 {
|
|
||||||
ret := C.GetGestureHoldDuration()
|
|
||||||
v := (float32)(ret)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gesture drag vector
|
|
||||||
func GetGestureDragVector() Vector2 {
|
|
||||||
ret := C.GetGestureDragVector()
|
|
||||||
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gesture drag angle
|
|
||||||
func GetGestureDragAngle() float32 {
|
|
||||||
ret := C.GetGestureDragAngle()
|
|
||||||
v := (float32)(ret)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gesture pinch delta
|
|
||||||
func GetGesturePinchVector() Vector2 {
|
|
||||||
ret := C.GetGesturePinchVector()
|
|
||||||
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gesture pinch angle
|
|
||||||
func GetGesturePinchAngle() float32 {
|
|
||||||
ret := C.GetGesturePinchAngle()
|
|
||||||
v := (float32)(ret)
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shows current FPS
|
|
||||||
func DrawFPS(posX int32, posY int32) {
|
|
||||||
cposX := (C.int)(posX)
|
|
||||||
cposY := (C.int)(posY)
|
|
||||||
C.DrawFPS(cposX, cposY)
|
|
||||||
}
|
|
||||||
|
|
83
raylib/gestures.go
Normal file
83
raylib/gestures.go
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
package raylib
|
||||||
|
|
||||||
|
// Gestures
|
||||||
|
type Gestures int32
|
||||||
|
|
||||||
|
// Gestures type
|
||||||
|
// NOTE: It could be used as flags to enable only some gestures
|
||||||
|
const (
|
||||||
|
GestureNone Gestures = C.GESTURE_NONE
|
||||||
|
GestureTap Gestures = C.GESTURE_TAP
|
||||||
|
GestureDoubletap Gestures = C.GESTURE_DOUBLETAP
|
||||||
|
GestureHold Gestures = C.GESTURE_HOLD
|
||||||
|
GestureDrag Gestures = C.GESTURE_DRAG
|
||||||
|
GestureSwipeRight Gestures = C.GESTURE_SWIPE_RIGHT
|
||||||
|
GestureSwipeLeft Gestures = C.GESTURE_SWIPE_LEFT
|
||||||
|
GestureSwipeUp Gestures = C.GESTURE_SWIPE_UP
|
||||||
|
GestureSwipeDown Gestures = C.GESTURE_SWIPE_DOWN
|
||||||
|
GesturePinchIn Gestures = C.GESTURE_PINCH_IN
|
||||||
|
GesturePinchOut Gestures = C.GESTURE_PINCH_OUT
|
||||||
|
)
|
||||||
|
|
||||||
|
// Enable a set of gestures using flags
|
||||||
|
func SetGesturesEnabled(gestureFlags uint32) {
|
||||||
|
cgestureFlags := (C.uint)(gestureFlags)
|
||||||
|
C.SetGesturesEnabled(cgestureFlags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a gesture have been detected
|
||||||
|
func IsGestureDetected(gesture Gestures) bool {
|
||||||
|
cgesture := (C.int)(gesture)
|
||||||
|
ret := C.IsGestureDetected(cgesture)
|
||||||
|
v := bool(int(ret) == 1)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get latest detected gesture
|
||||||
|
func GetGestureDetected() Gestures {
|
||||||
|
ret := C.GetGestureDetected()
|
||||||
|
v := (Gestures)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get touch points count
|
||||||
|
func GetTouchPointsCount() int32 {
|
||||||
|
ret := C.GetTouchPointsCount()
|
||||||
|
v := (int32)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gesture hold time in milliseconds
|
||||||
|
func GetGestureHoldDuration() float32 {
|
||||||
|
ret := C.GetGestureHoldDuration()
|
||||||
|
v := (float32)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gesture drag vector
|
||||||
|
func GetGestureDragVector() Vector2 {
|
||||||
|
ret := C.GetGestureDragVector()
|
||||||
|
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gesture drag angle
|
||||||
|
func GetGestureDragAngle() float32 {
|
||||||
|
ret := C.GetGestureDragAngle()
|
||||||
|
v := (float32)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gesture pinch delta
|
||||||
|
func GetGesturePinchVector() Vector2 {
|
||||||
|
ret := C.GetGesturePinchVector()
|
||||||
|
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gesture pinch angle
|
||||||
|
func GetGesturePinchAngle() float32 {
|
||||||
|
ret := C.GetGesturePinchAngle()
|
||||||
|
v := (float32)(ret)
|
||||||
|
return v
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ package raylib
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
// Vertex data definning a mesh
|
// Vertex data definning a mesh
|
||||||
type Mesh struct {
|
type Mesh struct {
|
||||||
|
@ -14,19 +15,19 @@ type Mesh struct {
|
||||||
// Number of triangles stored (indexed or not)
|
// Number of triangles stored (indexed or not)
|
||||||
TriangleCount int32
|
TriangleCount int32
|
||||||
// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
||||||
Vertices *float32
|
Vertices *[]float32
|
||||||
// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
||||||
Texcoords *float32
|
Texcoords *[]float32
|
||||||
// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
|
// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
|
||||||
Texcoords2 *float32
|
Texcoords2 *[]float32
|
||||||
// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
|
// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
|
||||||
Normals *float32
|
Normals *[]float32
|
||||||
// Vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
|
// Vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
|
||||||
Tangents *float32
|
Tangents *[]float32
|
||||||
// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
||||||
Colors *uint8
|
Colors *[]uint8
|
||||||
// Vertex indices (in case vertex data comes indexed)
|
// Vertex indices (in case vertex data comes indexed)
|
||||||
Indices *uint16
|
Indices *[]uint16
|
||||||
// OpenGL Vertex Array Object id
|
// OpenGL Vertex Array Object id
|
||||||
VaoID uint32
|
VaoID uint32
|
||||||
// OpenGL Vertex Buffer Objects id (7 types of vertex data)
|
// OpenGL Vertex Buffer Objects id (7 types of vertex data)
|
||||||
|
@ -38,7 +39,7 @@ func (m *Mesh) cptr() *C.Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns new 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 {
|
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}
|
return Mesh{vertexCount, triangleCount, vertices, texcoords, texcoords2, normals, tangents, colors, indices, vaoID, vboID}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +265,28 @@ func DrawGizmo(position Vector3) {
|
||||||
C.DrawGizmo(*cposition)
|
C.DrawGizmo(*cposition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a 3d model (.OBJ)
|
// Load mesh from file
|
||||||
|
func LoadMesh(fileName string) Mesh {
|
||||||
|
cfileName := C.CString(fileName)
|
||||||
|
defer C.free(unsafe.Pointer(cfileName))
|
||||||
|
ret := C.LoadMesh(cfileName)
|
||||||
|
v := NewMeshFromPointer(unsafe.Pointer(&ret))
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load mesh from vertex data
|
||||||
|
func LoadMeshEx(numVertex int32, vData []float32, vtData []float32, vnData []float32, cData []Color) Mesh {
|
||||||
|
cnumVertex := (C.int)(numVertex)
|
||||||
|
cvData := (*C.float)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&vData)).Data))
|
||||||
|
cvtData := (*C.float)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&vtData)).Data))
|
||||||
|
cvnData := (*C.float)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&vnData)).Data))
|
||||||
|
ccData := (*C.Color)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&cData)).Data))
|
||||||
|
ret := C.LoadMeshEx(cnumVertex, cvData, cvtData, cvnData, ccData)
|
||||||
|
v := NewMeshFromPointer(unsafe.Pointer(&ret))
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load model from file
|
||||||
func LoadModel(fileName string) Model {
|
func LoadModel(fileName string) Model {
|
||||||
cfileName := C.CString(fileName)
|
cfileName := C.CString(fileName)
|
||||||
defer C.free(unsafe.Pointer(cfileName))
|
defer C.free(unsafe.Pointer(cfileName))
|
||||||
|
@ -273,7 +295,19 @@ func LoadModel(fileName string) Model {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a heightmap image as a 3d model
|
// Load model from mesh data
|
||||||
|
func LoadModelFromMesh(data Mesh, dynamic bool) Model {
|
||||||
|
cdata := data.cptr()
|
||||||
|
cdynamic := 0
|
||||||
|
if dynamic {
|
||||||
|
cdynamic = 1
|
||||||
|
}
|
||||||
|
ret := C.LoadModelFromMesh(*cdata, C.bool(cdynamic))
|
||||||
|
v := NewModelFromPointer(unsafe.Pointer(&ret))
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load heightmap model from image data
|
||||||
func LoadHeightmap(heightmap *Image, size Vector3) Model {
|
func LoadHeightmap(heightmap *Image, size Vector3) Model {
|
||||||
cheightmap := heightmap.cptr()
|
cheightmap := heightmap.cptr()
|
||||||
csize := size.cptr()
|
csize := size.cptr()
|
||||||
|
@ -282,7 +316,7 @@ func LoadHeightmap(heightmap *Image, size Vector3) Model {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a map image as a 3d model (cubes based)
|
// Load cubes-based map model from image data
|
||||||
func LoadCubicmap(cubicmap *Image) Model {
|
func LoadCubicmap(cubicmap *Image) Model {
|
||||||
ccubicmap := cubicmap.cptr()
|
ccubicmap := cubicmap.cptr()
|
||||||
ret := C.LoadCubicmap(*ccubicmap)
|
ret := C.LoadCubicmap(*ccubicmap)
|
||||||
|
@ -290,7 +324,13 @@ func LoadCubicmap(cubicmap *Image) Model {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unload 3d model from memory
|
// Unload mesh from memory (RAM and/or VRAM)
|
||||||
|
func UnloadMesh(mesh *Mesh) {
|
||||||
|
cmesh := mesh.cptr()
|
||||||
|
C.UnloadMesh(cmesh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload model from memory (RAM and/or VRAM)
|
||||||
func UnloadModel(model Model) {
|
func UnloadModel(model Model) {
|
||||||
cmodel := model.cptr()
|
cmodel := model.cptr()
|
||||||
C.UnloadModel(*cmodel)
|
C.UnloadModel(*cmodel)
|
||||||
|
|
|
@ -139,3 +139,10 @@ func MeasureTextEx(spriteFont SpriteFont, text string, fontSize float32, spacing
|
||||||
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
v := NewVector2FromPointer(unsafe.Pointer(&ret))
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shows current FPS
|
||||||
|
func DrawFPS(posX int32, posY int32) {
|
||||||
|
cposX := (C.int)(posX)
|
||||||
|
cposY := (C.int)(posY)
|
||||||
|
C.DrawFPS(cposX, cposY)
|
||||||
|
}
|
||||||
|
|
|
@ -183,6 +183,17 @@ func LoadImageEx(pixels []Color, width int32, height int32) *Image {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load image from raw data with parameters
|
||||||
|
func LoadImagePro(data []byte, width int32, height int32, format TextureFormat) *Image {
|
||||||
|
cdata := unsafe.Pointer(&data[0])
|
||||||
|
cwidth := (C.int)(width)
|
||||||
|
cheight := (C.int)(height)
|
||||||
|
cformat := (C.int)(format)
|
||||||
|
ret := C.LoadImagePro(cdata, cwidth, cheight, cformat)
|
||||||
|
v := NewImageFromPointer(unsafe.Pointer(&ret))
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// Load image data from RAW file
|
// Load image data from RAW file
|
||||||
func LoadImageRaw(fileName string, width int32, height int32, format TextureFormat, headerSize int32) *Image {
|
func LoadImageRaw(fileName string, width int32, height int32, format TextureFormat, headerSize int32) *Image {
|
||||||
cfileName := C.CString(fileName)
|
cfileName := C.CString(fileName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue