mirror of
https://codeberg.org/Kenta/KaylibKit.git
synced 2024-09-19 11:50:22 -06:00
Introduce allocators to all C calling functions within Kotlin wrappers to avoid memory leaks. Certain types have been disabled until new method is found
This commit is contained in:
parent
8148c1e86b
commit
1702d61296
19 changed files with 1680 additions and 1710 deletions
|
@ -46,8 +46,8 @@ inline fun setMasterVolume(volume: Float) {
|
|||
* @return [Wave]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadWave(fileName: String) : Wave {
|
||||
return LoadWave(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadWave(fileName: String, allocator: AutofreeScope) : Wave {
|
||||
return LoadWave(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,8 +55,8 @@ inline fun loadWave(fileName: String) : Wave {
|
|||
* @return [Wave]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadWaveFromMemory(fileType: String, fileData: UByteVar, dataSize: Int) : Wave {
|
||||
return LoadWaveFromMemory(fileType, fileData.ptr, dataSize).getPointer(MemScope()).pointed
|
||||
inline fun loadWaveFromMemory(fileType: String, fileData: UByteVar, dataSize: Int, allocator: AutofreeScope) : Wave {
|
||||
return LoadWaveFromMemory(fileType, fileData.ptr, dataSize).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,8 +64,8 @@ inline fun loadWaveFromMemory(fileType: String, fileData: UByteVar, dataSize: In
|
|||
* @return [Sound]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadSound(fileName: String) : Sound {
|
||||
return LoadSound(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadSound(fileName: String, allocator: AutofreeScope) : Sound {
|
||||
return LoadSound(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,8 +73,8 @@ inline fun loadSound(fileName: String) : Sound {
|
|||
* @return [Sound]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadSoundFromWave(wave: Wave) : Sound {
|
||||
return LoadSoundFromWave(wave.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun loadSoundFromWave(wave: Wave, allocator: AutofreeScope) : Sound {
|
||||
return LoadSoundFromWave(wave.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -204,8 +204,8 @@ inline fun waveFormat(wave: Wave, sampleRate: Int, sampleSize: Int, channels: In
|
|||
* @return [Wave]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun waveCopy(wave: Wave) : Wave {
|
||||
return WaveCopy(wave.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun waveCopy(wave: Wave, allocator: AutofreeScope) : Wave {
|
||||
return WaveCopy(wave.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,8 +221,8 @@ inline fun waveCrop(wave: Wave, initSample: Int, finalSample: Int) {
|
|||
* @return [FloatVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadWaveSamples(wave: Wave) : FloatVar? {
|
||||
return LoadWaveSamples(wave.readValue())?.getPointer(MemScope())?.pointed
|
||||
inline fun loadWaveSamples(wave: Wave, allocator: AutofreeScope) : FloatVar? {
|
||||
return LoadWaveSamples(wave.readValue())?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,8 +252,8 @@ inline fun isWaveReady(wave: Wave) : Boolean {
|
|||
* @return [Music]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadMusicStream(fileName: String) : Music {
|
||||
return LoadMusicStream(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadMusicStream(fileName: String, allocator: AutofreeScope) : Music {
|
||||
return LoadMusicStream(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -261,8 +261,8 @@ inline fun loadMusicStream(fileName: String) : Music {
|
|||
* @return [Music]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadMusicStreamFromMemory(fileType: String, data: CPointer<UByteVar>, dataSize: Int) : Music {
|
||||
return LoadMusicStreamFromMemory(fileType, data, dataSize).getPointer(MemScope()).pointed
|
||||
inline fun loadMusicStreamFromMemory(fileType: String, data: CPointer<UByteVar>, dataSize: Int, allocator: AutofreeScope) : Music {
|
||||
return LoadMusicStreamFromMemory(fileType, data, dataSize).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -382,8 +382,8 @@ inline fun getMusicTimePlayed(music: Music) : Float {
|
|||
* @return [AudioStream]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadAudioStream(sampleRate: UInt, sampleSize: UInt, channels: UInt) : AudioStream {
|
||||
return LoadAudioStream(sampleRate, sampleSize, channels).getPointer(MemScope()).pointed
|
||||
inline fun loadAudioStream(sampleRate: UInt, sampleSize: UInt, channels: UInt, allocator: AutofreeScope) : AudioStream {
|
||||
return LoadAudioStream(sampleRate, sampleSize, channels).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,8 +14,8 @@ import kotlinx.cinterop.*
|
|||
* @return [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraForward(camera: Camera) : Vector3 {
|
||||
return GetCameraForward(camera.ptr).getPointer(MemScope()).pointed
|
||||
inline fun getCameraForward(camera: Camera, allocator: AutofreeScope) : Vector3 {
|
||||
return GetCameraForward(camera.ptr).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,8 +24,8 @@ inline fun getCameraForward(camera: Camera) : Vector3 {
|
|||
* @return [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraUp(camera: Camera) : Vector3 {
|
||||
return GetCameraUp(camera.ptr).getPointer(MemScope()).pointed
|
||||
inline fun getCameraUp(camera: Camera, allocator: AutofreeScope) : Vector3 {
|
||||
return GetCameraUp(camera.ptr).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,8 +33,8 @@ inline fun getCameraUp(camera: Camera) : Vector3 {
|
|||
* @return [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraRight(camera: Camera) : Vector3 {
|
||||
return GetCameraRight(camera.ptr).getPointer(MemScope()).pointed
|
||||
inline fun getCameraRight(camera: Camera, allocator: AutofreeScope) : Vector3 {
|
||||
return GetCameraRight(camera.ptr).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,8 +107,8 @@ inline fun cameraRoll(camera: Camera, angle: Float) {
|
|||
* @return [Matrix]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraViewMatrix(camera: Camera) : Matrix {
|
||||
return GetCameraViewMatrix(camera.ptr).getPointer(MemScope()).pointed
|
||||
inline fun getCameraViewMatrix(camera: Camera, allocator: AutofreeScope) : Matrix {
|
||||
return GetCameraViewMatrix(camera.ptr).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,8 +116,8 @@ inline fun getCameraViewMatrix(camera: Camera) : Matrix {
|
|||
* @return [Matrix]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraProjectionMatrix(camera: Camera, aspect: Float) : Matrix {
|
||||
return GetCameraProjectionMatrix(camera.ptr, aspect).getPointer(MemScope()).pointed
|
||||
inline fun getCameraProjectionMatrix(camera: Camera, aspect: Float, allocator: AutofreeScope) : Matrix {
|
||||
return GetCameraProjectionMatrix(camera.ptr, aspect).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -220,8 +220,8 @@ inline fun getCurrentMonitor() : Int {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getMonitorPosition(monitor: Int) : Vector2 {
|
||||
return GetMonitorPosition(monitor).getPointer(MemScope()).pointed
|
||||
inline fun getMonitorPosition(monitor: Int, allocator: AutofreeScope) : Vector2 {
|
||||
return GetMonitorPosition(monitor).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -261,8 +261,8 @@ inline fun getMonitorPhysicalHeight(monitor: Int) : Int {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getWindowPosition(): Vector2 {
|
||||
return GetWindowPosition().getPointer(MemScope()).pointed
|
||||
inline fun getWindowPosition(allocator: AutofreeScope): Vector2 {
|
||||
return GetWindowPosition().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,9 +270,10 @@ inline fun getWindowPosition(): Vector2 {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getWindowScaleDPI() : Vector2 {
|
||||
return GetWindowScaleDPI().getPointer(MemScope()).pointed
|
||||
inline fun getWindowScaleDPI(allocator: AutofreeScope) : Vector2 {
|
||||
return GetWindowScaleDPI().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human-readable, UTF-8 encoded name of the primary [monitor]
|
||||
* @return [String]
|
||||
|
@ -593,8 +594,8 @@ inline fun vrMode(config: VrStereoConfig, block: () -> Unit) {
|
|||
* @return [VrStereoConfig]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadVrStereoConfig(device: VrDeviceInfo) : VrStereoConfig {
|
||||
return LoadVrStereoConfig(device.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun loadVrStereoConfig(device: VrDeviceInfo, allocator: AutofreeScope) : VrStereoConfig {
|
||||
return LoadVrStereoConfig(device.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -610,25 +611,25 @@ inline fun unloadVrStereoConfig(config: VrStereoConfig) {
|
|||
//=======================================================//
|
||||
|
||||
/**
|
||||
* Load [shader] from files and bind default locations
|
||||
* Load [Shader] from files and bind default locations
|
||||
* @return [Shader]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadShader(vsFileName: String, fsFileName: String) : Shader {
|
||||
return LoadShader(vsFileName, fsFileName).getPointer(MemScope()).pointed
|
||||
inline fun loadShader(vsFileName: String, fsFileName: String, allocator: AutofreeScope) : Shader {
|
||||
return LoadShader(vsFileName, fsFileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Load [shader] from code strings and bind default locations
|
||||
* Load [Shader] from code strings and bind default locations
|
||||
* @return [Shader]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadShaderFromMemory(vsCode: String, fsCode: String) : Shader {
|
||||
return LoadShaderFromMemory(vsCode, fsCode).getPointer(MemScope()).pointed
|
||||
inline fun loadShaderFromMemory(vsCode: String, fsCode: String, allocator: AutofreeScope) : Shader {
|
||||
return LoadShaderFromMemory(vsCode, fsCode).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [shader] uniform location
|
||||
* Get [Shader] uniform location
|
||||
* @return [Int]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
|
@ -694,8 +695,8 @@ inline fun unloadShader(shader: Shader) {
|
|||
* @return [Ray]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getMouseRay(mousePosition: Vector2, camera: Camera) : Ray {
|
||||
return GetMouseRay(mousePosition.readValue(), camera.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getMouseRay(mousePosition: Vector2, camera: Camera, allocator: AutofreeScope) : Ray {
|
||||
return GetMouseRay(mousePosition.readValue(), camera.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -703,8 +704,8 @@ inline fun getMouseRay(mousePosition: Vector2, camera: Camera) : Ray {
|
|||
* @return [Matrix]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraMatrix(camera: Camera) : Matrix {
|
||||
return GetCameraMatrix(camera.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getCameraMatrix(camera: Camera, allocator: AutofreeScope) : Matrix {
|
||||
return GetCameraMatrix(camera.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -712,8 +713,8 @@ inline fun getCameraMatrix(camera: Camera) : Matrix {
|
|||
* @return [Matrix]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCameraMatrix2D(camera: Camera2D) : Matrix {
|
||||
return GetCameraMatrix2D(camera.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getCameraMatrix2D(camera: Camera2D, allocator: AutofreeScope) : Matrix {
|
||||
return GetCameraMatrix2D(camera.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -721,8 +722,8 @@ inline fun getCameraMatrix2D(camera: Camera2D) : Matrix {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getWorldToScreen(position: Vector3, camera: Camera) : Vector2 {
|
||||
return GetWorldToScreen(position.readValue(), camera.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getWorldToScreen(position: Vector3, camera: Camera, allocator: AutofreeScope) : Vector2 {
|
||||
return GetWorldToScreen(position.readValue(), camera.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -730,8 +731,8 @@ inline fun getWorldToScreen(position: Vector3, camera: Camera) : Vector2 {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getWorldToScreenEx(position: Vector3, camera: Camera, width: Int, height: Int) : Vector2 {
|
||||
return GetWorldToScreenEx(position.readValue(), camera.readValue(), width, height).getPointer(MemScope()).pointed
|
||||
inline fun getWorldToScreenEx(position: Vector3, camera: Camera, width: Int, height: Int, allocator: AutofreeScope) : Vector2 {
|
||||
return GetWorldToScreenEx(position.readValue(), camera.readValue(), width, height).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -739,8 +740,8 @@ inline fun getWorldToScreenEx(position: Vector3, camera: Camera, width: Int, hei
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getWorldToScreen2D(position: Vector2, camera: Camera2D) : Vector2 {
|
||||
return GetWorldToScreen2D(position.readValue(), camera.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getWorldToScreen2D(position: Vector2, camera: Camera2D, allocator: AutofreeScope) : Vector2 {
|
||||
return GetWorldToScreen2D(position.readValue(), camera.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -748,8 +749,8 @@ inline fun getWorldToScreen2D(position: Vector2, camera: Camera2D) : Vector2 {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getScreenToWorld2D(position: Vector2, camera: Camera2D) : Vector2 {
|
||||
return GetScreenToWorld2D(position.readValue(), camera.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getScreenToWorld2D(position: Vector2, camera: Camera2D, allocator: AutofreeScope) : Vector2 {
|
||||
return GetScreenToWorld2D(position.readValue(), camera.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
@ -900,8 +901,8 @@ inline fun setSaveFileTextCallback(callback: SaveFileTextCallback) {
|
|||
* @return [UByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFileData(fileName: String, bytesRead: UIntVar) : UByteVar? {
|
||||
return LoadFileData(fileName, bytesRead.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun loadFileData(fileName: String, bytesRead: UIntVar, allocator: AutofreeScope) : UByteVar? {
|
||||
return LoadFileData(fileName, bytesRead.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -926,8 +927,8 @@ inline fun saveFileData(fileName: String, data: COpaquePointer, bytesToWrite: UI
|
|||
* @return [ByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFileText(fileName: String) : ByteVar? {
|
||||
return LoadFileText(fileName)?.getPointer(MemScope())?.pointed
|
||||
inline fun loadFileText(fileName: String, allocator: AutofreeScope) : ByteVar? {
|
||||
return LoadFileText(fileName)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1030,8 +1031,8 @@ inline fun getWorkingDirectory() : String {
|
|||
* @return [FilePathList]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadDirectoryFiles(dirPath: String) : FilePathList {
|
||||
return LoadDirectoryFiles(dirPath).getPointer(MemScope()).pointed
|
||||
inline fun loadDirectoryFiles(dirPath: String, allocator: AutofreeScope) : FilePathList {
|
||||
return LoadDirectoryFiles(dirPath).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1062,8 +1063,8 @@ inline val isFileDropped: Boolean
|
|||
* @return [FilePathList]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadDroppedFiles() : FilePathList {
|
||||
return LoadDroppedFiles().getPointer(MemScope()).pointed
|
||||
inline fun loadDroppedFiles(allocator: AutofreeScope) : FilePathList {
|
||||
return LoadDroppedFiles().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1092,17 +1093,17 @@ inline fun getFileModTime(fileName: String): Int {
|
|||
* @return [UByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun compressData(data: UByteVar, dataLength: Int, compDataLength: IntVar) : UByteVar? {
|
||||
return CompressData(data.ptr, dataLength, compDataLength.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun compressData(data: UByteVar, dataLength: Int, compDataLength: IntVar, allocator: AutofreeScope) : UByteVar? {
|
||||
return CompressData(data.ptr, dataLength, compDataLength.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompress [data] (DEFLATE algorithm)
|
||||
* Decompress [compData] (DEFLATE algorithm)
|
||||
* @return [UByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun decompressData(compData: UByteVar, compDataLength: Int, dataLength: IntVar) : UByteVar? {
|
||||
return DecompressData(compData.ptr, compDataLength, dataLength.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun decompressData(compData: UByteVar, compDataLength: Int, dataLength: IntVar, allocator: AutofreeScope) : UByteVar? {
|
||||
return DecompressData(compData.ptr, compDataLength, dataLength.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1110,8 +1111,8 @@ inline fun decompressData(compData: UByteVar, compDataLength: Int, dataLength: I
|
|||
* @return [ByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun encodeDataBase64(data: UByteVar, dataLength: Int, outputLength: IntVar) : ByteVar? {
|
||||
return EncodeDataBase64(data.ptr, dataLength, outputLength.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun encodeDataBase64(data: UByteVar, dataLength: Int, outputLength: IntVar, allocator: AutofreeScope) : ByteVar? {
|
||||
return EncodeDataBase64(data.ptr, dataLength, outputLength.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1119,8 +1120,8 @@ inline fun encodeDataBase64(data: UByteVar, dataLength: Int, outputLength: IntVa
|
|||
* @return [UByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun decodeDataBase64(data: UByteVar, outputLength: IntVar) : UByteVar? {
|
||||
return DecodeDataBase64(data.ptr, outputLength.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun decodeDataBase64(data: UByteVar, outputLength: IntVar, allocator: AutofreeScope) : UByteVar? {
|
||||
return DecodeDataBase64(data.ptr, outputLength.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
@ -1331,12 +1332,12 @@ inline fun getMouseY() : Int {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get mouse position XY - This function uses getPointer with passed MemScope() as scope! You can also allocate your arena in the parameter
|
||||
* Get mouse position XY - This function uses getPointer with passed allocator as scope! You can also allocate your arena in the parameter
|
||||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getMousePosition() : Vector2 {
|
||||
return GetMousePosition().getPointer(MemScope()).pointed
|
||||
inline fun getMousePosition(allocator: AutofreeScope) : Vector2 {
|
||||
return GetMousePosition().getPointer(allocator).pointed
|
||||
|
||||
}
|
||||
|
||||
|
@ -1401,8 +1402,8 @@ inline fun getTouchY() : Int {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getTouchPosition(index: Int) : Vector2 {
|
||||
return GetTouchPosition(index).getPointer(MemScope()).pointed
|
||||
inline fun getTouchPosition(index: Int, allocator: AutofreeScope) : Vector2 {
|
||||
return GetTouchPosition(index).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package kaylibkit.kGestures
|
||||
|
||||
import kaylibc.*
|
||||
import kotlinx.cinterop.AutofreeScope
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import kotlinx.cinterop.MemScope
|
||||
import kotlinx.cinterop.pointed
|
||||
|
@ -47,8 +48,8 @@ inline fun getGestureHoldDuration() : Float {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getGestureDragVector() : Vector2 {
|
||||
return GetGestureDragVector().getPointer(MemScope()).pointed
|
||||
inline fun getGestureDragVector(allocator: AutofreeScope) : Vector2 {
|
||||
return GetGestureDragVector().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,8 +65,8 @@ inline fun getGestureDragAngle() : Float {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getGesturePinchVector() : Vector2 {
|
||||
return GetGesturePinchVector().getPointer(MemScope()).pointed
|
||||
inline fun getGesturePinchVector(allocator: AutofreeScope) : Vector2 {
|
||||
return GetGesturePinchVector().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,11 +11,10 @@ import kotlinx.cinterop.*
|
|||
|
||||
/**
|
||||
* Constructor function for [Image].
|
||||
* Important to note that this uses MemScope() by default.
|
||||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kImage(data: COpaquePointer?, width: Int, height: Int, mipmaps: Int, format: Int, allocator: AutofreeScope = MemScope()) : Image {
|
||||
inline fun kImage(data: COpaquePointer?, width: Int, height: Int, mipmaps: Int, format: Int, allocator: AutofreeScope) : Image {
|
||||
return allocator.alloc<Image> {
|
||||
this.data = data
|
||||
this.width = width
|
||||
|
@ -34,8 +33,8 @@ inline fun kImage(data: COpaquePointer?, width: Int, height: Int, mipmaps: Int,
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadImage(fileName: String) : Image {
|
||||
return LoadImage(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadImage(fileName: String, allocator: AutofreeScope) : Image {
|
||||
return LoadImage(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,8 +42,8 @@ inline fun loadImage(fileName: String) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadImageRaw(fileName: String, width: Int, height: Int, format: PixelFormat, headerSize: Int) : Image {
|
||||
return LoadImageRaw(fileName, width, height, format.toInt(), headerSize).getPointer(MemScope()).pointed
|
||||
inline fun loadImageRaw(fileName: String, width: Int, height: Int, format: PixelFormat, headerSize: Int, allocator: AutofreeScope) : Image {
|
||||
return LoadImageRaw(fileName, width, height, format.toInt(), headerSize).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,8 +51,8 @@ inline fun loadImageRaw(fileName: String, width: Int, height: Int, format: Pixel
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadImageAnim(fileName: String, frames: IntVar) : Image {
|
||||
return LoadImageAnim(fileName, frames.ptr).getPointer(MemScope()).pointed
|
||||
inline fun loadImageAnim(fileName: String, frames: IntVar, allocator: AutofreeScope) : Image {
|
||||
return LoadImageAnim(fileName, frames.ptr).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,8 +60,8 @@ inline fun loadImageAnim(fileName: String, frames: IntVar) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadImageFromMemory(fileType: String, fileData: UByteVar, dataSize: Int) : Image {
|
||||
return LoadImageFromMemory(fileType, fileData.ptr, dataSize).getPointer(MemScope()).pointed
|
||||
inline fun loadImageFromMemory(fileType: String, fileData: UByteVar, dataSize: Int, allocator: AutofreeScope) : Image {
|
||||
return LoadImageFromMemory(fileType, fileData.ptr, dataSize).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,8 +69,8 @@ inline fun loadImageFromMemory(fileType: String, fileData: UByteVar, dataSize: I
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadImageFromTexture(texture: Texture2D) : Image {
|
||||
return LoadImageFromTexture(texture.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun loadImageFromTexture(texture: Texture2D, allocator: AutofreeScope) : Image {
|
||||
return LoadImageFromTexture(texture.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,8 +78,8 @@ inline fun loadImageFromTexture(texture: Texture2D) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadImageFromScreen() : Image {
|
||||
return LoadImageFromScreen().getPointer(MemScope()).pointed
|
||||
inline fun loadImageFromScreen(allocator: AutofreeScope) : Image {
|
||||
return LoadImageFromScreen().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,8 +117,8 @@ inline fun exportImageAsCode(image: Image, fileName: String) : Boolean {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageColor(width: Int, height: Int, color: Color) : Image {
|
||||
return GenImageColor(width, height, color.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genImageColor(width: Int, height: Int, color: Color, allocator: AutofreeScope) : Image {
|
||||
return GenImageColor(width, height, color.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,8 +126,8 @@ inline fun genImageColor(width: Int, height: Int, color: Color) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageGradientV(width: Int, height: Int, top: Color, bottom: Color) : Image {
|
||||
return GenImageGradientV(width, height, top.readValue(), bottom.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genImageGradientV(width: Int, height: Int, top: Color, bottom: Color, allocator: AutofreeScope) : Image {
|
||||
return GenImageGradientV(width, height, top.readValue(), bottom.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,8 +135,8 @@ inline fun genImageGradientV(width: Int, height: Int, top: Color, bottom: Color)
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageGradientH(width: Int, height: Int, left: Color, right: Color) : Image {
|
||||
return GenImageGradientH(width, height, left.readValue(), right.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genImageGradientH(width: Int, height: Int, left: Color, right: Color, allocator: AutofreeScope) : Image {
|
||||
return GenImageGradientH(width, height, left.readValue(), right.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,8 +144,8 @@ inline fun genImageGradientH(width: Int, height: Int, left: Color, right: Color)
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageGradientRadial(width: Int, height: Int, density: Float, inner: Color, outer: Color) : Image {
|
||||
return GenImageGradientRadial(width, height, density, inner.readValue(), outer.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genImageGradientRadial(width: Int, height: Int, density: Float, inner: Color, outer: Color, allocator: AutofreeScope) : Image {
|
||||
return GenImageGradientRadial(width, height, density, inner.readValue(), outer.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,8 +153,8 @@ inline fun genImageGradientRadial(width: Int, height: Int, density: Float, inner
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageChecked(width: Int, height: Int, checksX: Int, checksY: Int, col1: Color, col2: Color) : Image {
|
||||
return GenImageChecked(width, height, checksX, checksY, col1.readValue(), col2.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genImageChecked(width: Int, height: Int, checksX: Int, checksY: Int, col1: Color, col2: Color, allocator: AutofreeScope) : Image {
|
||||
return GenImageChecked(width, height, checksX, checksY, col1.readValue(), col2.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,8 +162,8 @@ inline fun genImageChecked(width: Int, height: Int, checksX: Int, checksY: Int,
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageWhiteNoise(width: Int, height: Int, factor: Float) : Image {
|
||||
return GenImageWhiteNoise(width, height, factor).getPointer(MemScope()).pointed
|
||||
inline fun genImageWhiteNoise(width: Int, height: Int, factor: Float, allocator: AutofreeScope) : Image {
|
||||
return GenImageWhiteNoise(width, height, factor).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,8 +171,8 @@ inline fun genImageWhiteNoise(width: Int, height: Int, factor: Float) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageCellular(width: Int, height: Int, tileSize: Int) : Image {
|
||||
return GenImageCellular(width, height, tileSize).getPointer(MemScope()).pointed
|
||||
inline fun genImageCellular(width: Int, height: Int, tileSize: Int, allocator: AutofreeScope) : Image {
|
||||
return GenImageCellular(width, height, tileSize).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
@ -185,8 +184,8 @@ inline fun genImageCellular(width: Int, height: Int, tileSize: Int) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageCopy(image: Image) : Image {
|
||||
return ImageCopy(image.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun imageCopy(image: Image, allocator: AutofreeScope) : Image {
|
||||
return ImageCopy(image.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,8 +193,8 @@ inline fun imageCopy(image: Image) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageFromImage(image: Image, rec: Rectangle) : Image {
|
||||
return ImageFromImage(image.readValue(), rec.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun imageFromImage(image: Image, rec: Rectangle, allocator: AutofreeScope) : Image {
|
||||
return ImageFromImage(image.readValue(), rec.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,8 +202,8 @@ inline fun imageFromImage(image: Image, rec: Rectangle) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageText(text: String, fontSize: Int, color: Color) : Image {
|
||||
return ImageText(text, fontSize, color.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun imageText(text: String, fontSize: Int, color: Color, allocator: AutofreeScope) : Image {
|
||||
return ImageText(text, fontSize, color.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,8 +211,8 @@ inline fun imageText(text: String, fontSize: Int, color: Color) : Image {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageTextEx(font: Font, text: String, fontSize: Float, spacing: Float, tint: Color) : Image {
|
||||
return ImageTextEx(font.readValue(), text, fontSize, spacing, tint.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun imageTextEx(font: Font, text: String, fontSize: Float, spacing: Float, tint: Color, allocator: AutofreeScope) : Image {
|
||||
return ImageTextEx(font.readValue(), text, fontSize, spacing, tint.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -297,7 +296,7 @@ inline fun imageResizeNN(image: Image, newWidth: Int, newHeight: Int) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Resize canvas and fill with [color]
|
||||
* Resize canvas and fill with [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageResizeCanvas(image: Image, newWidth: Int, newHeight: Int, offsetX: Int, offsetY: Int, fill: Color) {
|
||||
|
@ -353,7 +352,7 @@ inline fun imageRotateCCW(image: Image) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Modify [Image] [color]: tint
|
||||
* Modify [Image] [Color]: tint
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageColorTint(image: Image, color: Color) {
|
||||
|
@ -361,7 +360,7 @@ inline fun imageColorTint(image: Image, color: Color) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Modify [Image] [color]: invert
|
||||
* Modify [Image] [Color]: invert
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageColorInvert(image: Image) {
|
||||
|
@ -369,7 +368,7 @@ inline fun imageColorInvert(image: Image) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Modify [Image] [color]: grayscale
|
||||
* Modify [Image] [Color]: grayscale
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageColorGrayscale(image: Image) {
|
||||
|
@ -377,7 +376,7 @@ inline fun imageColorGrayscale(image: Image) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Modify [Image] [color]: contrast (-100 to 100)
|
||||
* Modify [Image] [Color]: contrast (-100 to 100)
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageColorContrast(image: Image, contrast: Float) {
|
||||
|
@ -385,7 +384,7 @@ inline fun imageColorContrast(image: Image, contrast: Float) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Modify [Image] [color]: brightness (-255 to 255)
|
||||
* Modify [Image] [Color]: brightness (-255 to 255)
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun imageColorBrightness(image: Image, brightness: Int) {
|
||||
|
@ -446,8 +445,8 @@ inline fun unloadImagePalette(colors: Color) {
|
|||
* @return [Rectangle]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getImageAlphaBorder(image: Image, threshold: Float) : Rectangle {
|
||||
return GetImageAlphaBorder(image.readValue(), threshold).getPointer(MemScope()).pointed
|
||||
inline fun getImageAlphaBorder(image: Image, threshold: Float, allocator: AutofreeScope) : Rectangle {
|
||||
return GetImageAlphaBorder(image.readValue(), threshold).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -455,8 +454,8 @@ inline fun getImageAlphaBorder(image: Image, threshold: Float) : Rectangle {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getImageColor(image: Image, x: Int, y: Int) : Color {
|
||||
return GetImageColor(image.readValue(), x, y).getPointer(MemScope()).pointed
|
||||
inline fun getImageColor(image: Image, x: Int, y: Int, allocator: AutofreeScope) : Color {
|
||||
return GetImageColor(image.readValue(), x, y).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
|
|
@ -39,229 +39,229 @@ inline fun remap(value: Float, inputStart: Float, inputEnd: Float, outputStart:
|
|||
return (value - inputStart) / (inputEnd - inputStart) * (outputEnd - outputStart) + outputStart
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate [Quaternion] based on the rotation from one vector to another
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun quaternionFromVector3toVector3(from: Vector3, to: Vector3): Quaternion {
|
||||
///**
|
||||
// * Calculate [Quaternion] based on the rotation from one vector to another
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun quaternionFromVector3toVector3(from: Vector3, to: Vector3): Quaternion {
|
||||
//// val result: Quaternion = kQuaternion()
|
||||
////
|
||||
//// val cos2Theta = from.dot(to)
|
||||
////
|
||||
//// val cross: Vector3 = from.crossProduct(to)
|
||||
////
|
||||
////
|
||||
//// result.x = cross.x
|
||||
//// result.y = cross.y
|
||||
//// result.z = cross.z
|
||||
//// result.w = 1.0f + cos2Theta
|
||||
////
|
||||
//// var length: Quaternion = result.normalize()
|
||||
////
|
||||
//// return result
|
||||
//
|
||||
// val result: Quaternion = kQuaternion()
|
||||
//
|
||||
// val cos2Theta = from.dot(to)
|
||||
//
|
||||
// val cross: Vector3 = from.crossProduct(to)
|
||||
// val cos2Theta = from.x * to.x + from.y * to.y + from.z * to.z // Vector3DotProduct(from, to)
|
||||
//
|
||||
// val cross: Vector3 = kVector3(
|
||||
// from.y * to.z - from.z * to.y,
|
||||
// from.z * to.x - from.x * to.z,
|
||||
// from.x * to.y - from.y * to.x
|
||||
// ) // Vector3CrossProduct(from, to)
|
||||
//
|
||||
// result.x = cross.x
|
||||
// result.y = cross.y
|
||||
// result.z = cross.z
|
||||
// result.w = 1.0f + cos2Theta
|
||||
//
|
||||
// var length: Quaternion = result.normalize()
|
||||
// // QuaternionNormalize(q);
|
||||
// // NOTE: Normalize to essentially nlerp the original and identity to 0.5
|
||||
//
|
||||
// var length: Float = sqrt(result.x * result.x + result.y * result.y + result.z * result.z + result.w * result.w)
|
||||
// if (length == 0.0f) length = 1.0f
|
||||
// val ilength = 1.0f / length
|
||||
//
|
||||
// result.x = result.x * ilength
|
||||
// result.y = result.y * ilength
|
||||
// result.z = result.z * ilength
|
||||
// result.w = result.w * ilength
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
val result: Quaternion = kQuaternion()
|
||||
///**
|
||||
// * Get a [Quaternion] for a given rotation matrix
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun quaternionFromMatrix(mat: Matrix): Quaternion {
|
||||
// val result: Quaternion = kQuaternion()
|
||||
//
|
||||
// val fourWSquaredMinus1 = mat.m0 + mat.m5 + mat.m10
|
||||
// val fourXSquaredMinus1 = mat.m0 - mat.m5 - mat.m10
|
||||
// val fourYSquaredMinus1 = mat.m5 - mat.m0 - mat.m10
|
||||
// val fourZSquaredMinus1 = mat.m10 - mat.m0 - mat.m5
|
||||
//
|
||||
// var biggestIndex = 0
|
||||
// var fourBiggestSquaredMinus1 = fourWSquaredMinus1
|
||||
// if (fourXSquaredMinus1 > fourBiggestSquaredMinus1) {
|
||||
// fourBiggestSquaredMinus1 = fourXSquaredMinus1
|
||||
// biggestIndex = 1
|
||||
// }
|
||||
//
|
||||
// if (fourYSquaredMinus1 > fourBiggestSquaredMinus1) {
|
||||
// fourBiggestSquaredMinus1 = fourYSquaredMinus1
|
||||
// biggestIndex = 2
|
||||
// }
|
||||
//
|
||||
// if (fourZSquaredMinus1 > fourBiggestSquaredMinus1) {
|
||||
// fourBiggestSquaredMinus1 = fourZSquaredMinus1
|
||||
// biggestIndex = 3
|
||||
// }
|
||||
//
|
||||
// val biggestVal: Float = sqrt(fourBiggestSquaredMinus1 + 1.0f) * 0.5f
|
||||
// val mult = 0.25f / biggestVal
|
||||
//
|
||||
// when (biggestIndex) {
|
||||
// 0 -> {
|
||||
// result.w = biggestVal
|
||||
// result.x = (mat.m6 - mat.m9) * mult
|
||||
// result.y = (mat.m8 - mat.m2) * mult
|
||||
// result.z = (mat.m1 - mat.m4) * mult
|
||||
// }
|
||||
//
|
||||
// 1 -> {
|
||||
// result.x = biggestVal
|
||||
// result.w = (mat.m6 - mat.m9) * mult
|
||||
// result.y = (mat.m1 + mat.m4) * mult
|
||||
// result.z = (mat.m8 + mat.m2) * mult
|
||||
// }
|
||||
//
|
||||
// 2 -> {
|
||||
// result.y = biggestVal
|
||||
// result.w = (mat.m8 - mat.m2) * mult
|
||||
// result.x = (mat.m1 + mat.m4) * mult
|
||||
// result.z = (mat.m6 + mat.m9) * mult
|
||||
// }
|
||||
//
|
||||
// 3 -> {
|
||||
// result.z = biggestVal
|
||||
// result.w = (mat.m1 - mat.m4) * mult
|
||||
// result.x = (mat.m8 + mat.m2) * mult
|
||||
// result.y = (mat.m6 + mat.m9) * mult
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
val cos2Theta = from.x * to.x + from.y * to.y + from.z * to.z // Vector3DotProduct(from, to)
|
||||
///**
|
||||
// * Get a [Matrix] for a given [Quaternion]
|
||||
// * @return [Matrix]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun quaternionToMatrix(q: Quaternion): Matrix {
|
||||
// val result: Matrix = kMatrix(
|
||||
// 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
// 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
// 0.0f, 0.0f, 1.0f, 0.0f,
|
||||
// 0.0f, 0.0f, 0.0f, 1.0f
|
||||
// ) // MatrixIdentity()
|
||||
//
|
||||
//
|
||||
// val a2: Float = q.x * q.x
|
||||
// val b2: Float = q.y * q.y
|
||||
// val c2: Float = q.z * q.z
|
||||
// val ac: Float = q.x * q.z
|
||||
// val ab: Float = q.x * q.y
|
||||
// val bc: Float = q.y * q.z
|
||||
// val ad: Float = q.w * q.x
|
||||
// val bd: Float = q.w * q.y
|
||||
// val cd: Float = q.w * q.z
|
||||
//
|
||||
// result.m0 = 1 - 2 * (b2 + c2)
|
||||
// result.m1 = 2 * (ab + cd)
|
||||
// result.m2 = 2 * (ac - bd)
|
||||
//
|
||||
// result.m4 = 2 * (ab - cd)
|
||||
// result.m5 = 1 - 2 * (a2 + c2)
|
||||
// result.m6 = 2 * (bc + ad)
|
||||
//
|
||||
// result.m8 = 2 * (ac + bd)
|
||||
// result.m9 = 2 * (bc - ad)
|
||||
// result.m10 = 1 - 2 * (a2 + b2)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
val cross: Vector3 = kVector3(
|
||||
from.y * to.z - from.z * to.y,
|
||||
from.z * to.x - from.x * to.z,
|
||||
from.x * to.y - from.y * to.x
|
||||
) // Vector3CrossProduct(from, to)
|
||||
///**
|
||||
// * Get rotation [Quaternion] for an [angle] and [axis]
|
||||
// *
|
||||
// * NOTE: [angle] must be provided in radians
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun quaternionFromAxisAngle(axis: Vector3, angle: Float): Quaternion {
|
||||
// var ang = angle
|
||||
// val result: Quaternion = kQuaternion(0.0f, 0.0f, 0.0f, 1.0f)
|
||||
//
|
||||
// val axisLength: Float = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
||||
//
|
||||
// if (axisLength != 0.0f) {
|
||||
// ang *= 0.5f
|
||||
// var length: Float
|
||||
// var ilength: Float
|
||||
//
|
||||
// // Vector3Normalize(axis)
|
||||
// length = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
||||
// if (length == 0.0f) length = 1.0f
|
||||
// ilength = 1.0f / length
|
||||
// axis.x *= ilength
|
||||
// axis.y *= ilength
|
||||
// axis.z *= ilength
|
||||
// val sinres: Float = sin(angle)
|
||||
// val cosres: Float = cos(angle)
|
||||
// result.x = axis.x * sinres
|
||||
// result.y = axis.y * sinres
|
||||
// result.z = axis.z * sinres
|
||||
// result.w = cosres
|
||||
//
|
||||
// // QuaternionNormalize(q);
|
||||
// length = sqrt(result.x * result.x + result.y * result.y + result.z * result.z + result.w * result.w)
|
||||
// if (length == 0.0f) length = 1.0f
|
||||
// ilength = 1.0f / length
|
||||
// result.x = result.x * ilength
|
||||
// result.y = result.y * ilength
|
||||
// result.z = result.z * ilength
|
||||
// result.w = result.w * ilength
|
||||
// }
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
result.x = cross.x
|
||||
result.y = cross.y
|
||||
result.z = cross.z
|
||||
result.w = 1.0f + cos2Theta
|
||||
|
||||
// QuaternionNormalize(q);
|
||||
// NOTE: Normalize to essentially nlerp the original and identity to 0.5
|
||||
|
||||
var length: Float = sqrt(result.x * result.x + result.y * result.y + result.z * result.z + result.w * result.w)
|
||||
if (length == 0.0f) length = 1.0f
|
||||
val ilength = 1.0f / length
|
||||
|
||||
result.x = result.x * ilength
|
||||
result.y = result.y * ilength
|
||||
result.z = result.z * ilength
|
||||
result.w = result.w * ilength
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a [Quaternion] for a given rotation matrix
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun quaternionFromMatrix(mat: Matrix): Quaternion {
|
||||
val result: Quaternion = kQuaternion()
|
||||
|
||||
val fourWSquaredMinus1 = mat.m0 + mat.m5 + mat.m10
|
||||
val fourXSquaredMinus1 = mat.m0 - mat.m5 - mat.m10
|
||||
val fourYSquaredMinus1 = mat.m5 - mat.m0 - mat.m10
|
||||
val fourZSquaredMinus1 = mat.m10 - mat.m0 - mat.m5
|
||||
|
||||
var biggestIndex = 0
|
||||
var fourBiggestSquaredMinus1 = fourWSquaredMinus1
|
||||
if (fourXSquaredMinus1 > fourBiggestSquaredMinus1) {
|
||||
fourBiggestSquaredMinus1 = fourXSquaredMinus1
|
||||
biggestIndex = 1
|
||||
}
|
||||
|
||||
if (fourYSquaredMinus1 > fourBiggestSquaredMinus1) {
|
||||
fourBiggestSquaredMinus1 = fourYSquaredMinus1
|
||||
biggestIndex = 2
|
||||
}
|
||||
|
||||
if (fourZSquaredMinus1 > fourBiggestSquaredMinus1) {
|
||||
fourBiggestSquaredMinus1 = fourZSquaredMinus1
|
||||
biggestIndex = 3
|
||||
}
|
||||
|
||||
val biggestVal: Float = sqrt(fourBiggestSquaredMinus1 + 1.0f) * 0.5f
|
||||
val mult = 0.25f / biggestVal
|
||||
|
||||
when (biggestIndex) {
|
||||
0 -> {
|
||||
result.w = biggestVal
|
||||
result.x = (mat.m6 - mat.m9) * mult
|
||||
result.y = (mat.m8 - mat.m2) * mult
|
||||
result.z = (mat.m1 - mat.m4) * mult
|
||||
}
|
||||
|
||||
1 -> {
|
||||
result.x = biggestVal
|
||||
result.w = (mat.m6 - mat.m9) * mult
|
||||
result.y = (mat.m1 + mat.m4) * mult
|
||||
result.z = (mat.m8 + mat.m2) * mult
|
||||
}
|
||||
|
||||
2 -> {
|
||||
result.y = biggestVal
|
||||
result.w = (mat.m8 - mat.m2) * mult
|
||||
result.x = (mat.m1 + mat.m4) * mult
|
||||
result.z = (mat.m6 + mat.m9) * mult
|
||||
}
|
||||
|
||||
3 -> {
|
||||
result.z = biggestVal
|
||||
result.w = (mat.m1 - mat.m4) * mult
|
||||
result.x = (mat.m8 + mat.m2) * mult
|
||||
result.y = (mat.m6 + mat.m9) * mult
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a [Matrix] for a given [Quaternion]
|
||||
* @return [Matrix]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun quaternionToMatrix(q: Quaternion): Matrix {
|
||||
val result: Matrix = kMatrix(
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
) // MatrixIdentity()
|
||||
|
||||
|
||||
val a2: Float = q.x * q.x
|
||||
val b2: Float = q.y * q.y
|
||||
val c2: Float = q.z * q.z
|
||||
val ac: Float = q.x * q.z
|
||||
val ab: Float = q.x * q.y
|
||||
val bc: Float = q.y * q.z
|
||||
val ad: Float = q.w * q.x
|
||||
val bd: Float = q.w * q.y
|
||||
val cd: Float = q.w * q.z
|
||||
|
||||
result.m0 = 1 - 2 * (b2 + c2)
|
||||
result.m1 = 2 * (ab + cd)
|
||||
result.m2 = 2 * (ac - bd)
|
||||
|
||||
result.m4 = 2 * (ab - cd)
|
||||
result.m5 = 1 - 2 * (a2 + c2)
|
||||
result.m6 = 2 * (bc + ad)
|
||||
|
||||
result.m8 = 2 * (ac + bd)
|
||||
result.m9 = 2 * (bc - ad)
|
||||
result.m10 = 1 - 2 * (a2 + b2)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rotation [Quaternion] for an [angle] and [axis]
|
||||
*
|
||||
* NOTE: [angle] must be provided in radians
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun quaternionFromAxisAngle(axis: Vector3, angle: Float): Quaternion {
|
||||
var ang = angle
|
||||
val result: Quaternion = kQuaternion(0.0f, 0.0f, 0.0f, 1.0f)
|
||||
|
||||
val axisLength: Float = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
||||
|
||||
if (axisLength != 0.0f) {
|
||||
ang *= 0.5f
|
||||
var length: Float
|
||||
var ilength: Float
|
||||
|
||||
// Vector3Normalize(axis)
|
||||
length = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
||||
if (length == 0.0f) length = 1.0f
|
||||
ilength = 1.0f / length
|
||||
axis.x *= ilength
|
||||
axis.y *= ilength
|
||||
axis.z *= ilength
|
||||
val sinres: Float = sin(angle)
|
||||
val cosres: Float = cos(angle)
|
||||
result.x = axis.x * sinres
|
||||
result.y = axis.y * sinres
|
||||
result.z = axis.z * sinres
|
||||
result.w = cosres
|
||||
|
||||
// QuaternionNormalize(q);
|
||||
length = sqrt(result.x * result.x + result.y * result.y + result.z * result.z + result.w * result.w)
|
||||
if (length == 0.0f) length = 1.0f
|
||||
ilength = 1.0f / length
|
||||
result.x = result.x * ilength
|
||||
result.y = result.y * ilength
|
||||
result.z = result.z * ilength
|
||||
result.w = result.w * ilength
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [Quaternion] equivalent to Euler angles
|
||||
*
|
||||
* NOTE: Rotation order is ZYX
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun quaternionFromEuler(pitch: Float, yaw: Float, roll: Float): Quaternion {
|
||||
val result: Quaternion = kQuaternion()
|
||||
|
||||
val x0: Float = cos(pitch * 0.5f)
|
||||
val x1: Float = sin(pitch * 0.5f)
|
||||
val y0: Float = cos(yaw * 0.5f)
|
||||
val y1: Float = sin(yaw * 0.5f)
|
||||
val z0: Float = cos(roll * 0.5f)
|
||||
val z1: Float = sin(roll * 0.5f)
|
||||
|
||||
result.x = x1 * y0 * z0 - x0 * y1 * z1
|
||||
result.y = x0 * y1 * z0 + x1 * y0 * z1
|
||||
result.z = x0 * y0 * z1 - x1 * y1 * z0
|
||||
result.w = x0 * y0 * z0 + x1 * y1 * z1
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Get the [Quaternion] equivalent to Euler angles
|
||||
// *
|
||||
// * NOTE: Rotation order is ZYX
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun quaternionFromEuler(pitch: Float, yaw: Float, roll: Float): Quaternion {
|
||||
// val result: Quaternion = kQuaternion()
|
||||
//
|
||||
// val x0: Float = cos(pitch * 0.5f)
|
||||
// val x1: Float = sin(pitch * 0.5f)
|
||||
// val y0: Float = cos(yaw * 0.5f)
|
||||
// val y1: Float = sin(yaw * 0.5f)
|
||||
// val z0: Float = cos(roll * 0.5f)
|
||||
// val z1: Float = sin(roll * 0.5f)
|
||||
//
|
||||
// result.x = x1 * y0 * z0 - x0 * y1 * z1
|
||||
// result.y = x0 * y1 * z0 + x1 * y0 * z1
|
||||
// result.z = x0 * y0 * z1 - x1 * y1 * z0
|
||||
// result.w = x0 * y0 * z0 + x1 * y1 * z1
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,11 +13,10 @@ import kotlin.math.*
|
|||
|
||||
/**
|
||||
* Constructor function for [Quaternion]
|
||||
* @param [allocator] Uses `MemScope()` by default.
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kQuaternion(x: Float = 0F, y: Float = 0F, z: Float = 0F, w: Float = 0F, allocator: AutofreeScope = MemScope()): Quaternion {
|
||||
inline fun kQuaternion(x: Float = 0F, y: Float = 0F, z: Float = 0F, w: Float = 0F, allocator: AutofreeScope): Quaternion {
|
||||
return allocator.alloc<Quaternion> {
|
||||
this.x = x
|
||||
this.y = y
|
||||
|
@ -26,132 +25,132 @@ inline fun kQuaternion(x: Float = 0F, y: Float = 0F, z: Float = 0F, w: Float = 0
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate slerp-optimized interpolation between two [Quaternion]
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Quaternion.nLerp(q2: Vector4, amount: Float): Quaternion {
|
||||
val result: Quaternion = kQuaternion()
|
||||
///**
|
||||
// * Calculate slerp-optimized interpolation between two [Quaternion]
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Quaternion.nLerp(q2: Vector4, amount: Float): Quaternion {
|
||||
// val result: Quaternion = kQuaternion()
|
||||
//
|
||||
// // QuaternionLerp(q1, q2, amount)
|
||||
//
|
||||
// // QuaternionLerp(q1, q2, amount)
|
||||
// result.x = this.x + amount * (q2.x - this.x)
|
||||
// result.y = this.y + amount * (q2.y - this.y)
|
||||
// result.z = this.z + amount * (q2.z - this.z)
|
||||
// result.w = this.w + amount * (q2.w - this.w)
|
||||
//
|
||||
// // QuaternionNormalize(q);
|
||||
//
|
||||
// // QuaternionNormalize(q);
|
||||
// var length: Float = sqrt(result.x * result.x + result.y * result.y + result.z * result.z + result.w * result.w)
|
||||
// if (length == 0.0f) length = 1.0f
|
||||
// val ilength = 1.0f / length
|
||||
//
|
||||
// result.x *= ilength
|
||||
// result.y *= ilength
|
||||
// result.z *= ilength
|
||||
// result.w *= ilength
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
// QuaternionLerp(q1, q2, amount)
|
||||
///**
|
||||
// * Calculates spherical linear interpolation between two [Quaternion]
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Quaternion.sLerp(q2: Vector4, amount: Float): Quaternion {
|
||||
// var result: Quaternion = kQuaternion()
|
||||
//
|
||||
// var cosHalfTheta: Float = this.x * q2.x + this.y * q2.y + this.z * q2.z + this.w * q2.w
|
||||
//
|
||||
// if (cosHalfTheta < 0) {
|
||||
// q2.x = -q2.x
|
||||
// q2.y = -q2.y
|
||||
// q2.z = -q2.z
|
||||
// q2.w = -q2.w
|
||||
// cosHalfTheta = -cosHalfTheta
|
||||
// }
|
||||
//
|
||||
// if (abs(cosHalfTheta) >= 1.0f) result = this else if (cosHalfTheta > 0.95f) result =
|
||||
// this.nLerp(q2, amount) else {
|
||||
// val halfTheta: Float = acos(cosHalfTheta)
|
||||
// val sinHalfTheta: Float = sqrt(1.0f - cosHalfTheta * cosHalfTheta)
|
||||
// if (abs(sinHalfTheta) < 0.001f) {
|
||||
// result.x = this.x * 0.5f + q2.x * 0.5f
|
||||
// result.y = this.y * 0.5f + q2.y * 0.5f
|
||||
// result.z = this.z * 0.5f + q2.z * 0.5f
|
||||
// result.w = this.w * 0.5f + q2.w * 0.5f
|
||||
// } else {
|
||||
// val ratioA: Float = sin((1 - amount) * halfTheta) / sinHalfTheta
|
||||
// val ratioB: Float = sin(amount * halfTheta) / sinHalfTheta
|
||||
// result.x = this.x * ratioA + q2.x * ratioB
|
||||
// result.y = this.y * ratioA + q2.y * ratioB
|
||||
// result.z = this.z * ratioA + q2.z * ratioB
|
||||
// result.w = this.w * ratioA + q2.w * ratioB
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
// QuaternionLerp(q1, q2, amount)
|
||||
result.x = this.x + amount * (q2.x - this.x)
|
||||
result.y = this.y + amount * (q2.y - this.y)
|
||||
result.z = this.z + amount * (q2.z - this.z)
|
||||
result.w = this.w + amount * (q2.w - this.w)
|
||||
///**
|
||||
// * Get the rotation angle and axis for a given [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Quaternion.toAxisAngle(outAxis: CPointer<Vector3>, outAngle: CPointer<FloatVar>) {
|
||||
// QuaternionToAxisAngle(this.readValue(), outAxis, outAngle)
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Get the Euler angles equivalent to [Quaternion] (roll, pitch, yaw)
|
||||
// * NOTE: Angles are returned in a Vector3 struct in radians
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Quaternion.toEuler(): Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// // Roll (x-axis rotation)
|
||||
//
|
||||
// // Roll (x-axis rotation)
|
||||
// val x0: Float = 2.0f * (this.w * this.x + this.y * this.z)
|
||||
// val x1: Float = 1.0f - 2.0f * (this.x * this.x + this.y * this.y)
|
||||
// result.x = atan2(x0, x1)
|
||||
//
|
||||
// // Pitch (y-axis rotation)
|
||||
//
|
||||
// // Pitch (y-axis rotation)
|
||||
// var y0: Float = 2.0f * (this.w * this.y - this.z * this.x)
|
||||
// y0 = if (y0 > 1.0f) 1.0f else y0
|
||||
// y0 = if (y0 < -1.0f) -1.0f else y0
|
||||
// result.y = asin(y0)
|
||||
//
|
||||
// // Yaw (z-axis rotation)
|
||||
//
|
||||
// // Yaw (z-axis rotation)
|
||||
// val z0: Float = 2.0f * (this.w * this.z + this.x * this.y)
|
||||
// val z1: Float = 1.0f - 2.0f * (this.y * this.y + this.z * this.z)
|
||||
// result.z = atan2(z0, z1)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
// QuaternionNormalize(q);
|
||||
|
||||
// QuaternionNormalize(q);
|
||||
var length: Float = sqrt(result.x * result.x + result.y * result.y + result.z * result.z + result.w * result.w)
|
||||
if (length == 0.0f) length = 1.0f
|
||||
val ilength = 1.0f / length
|
||||
|
||||
result.x *= ilength
|
||||
result.y *= ilength
|
||||
result.z *= ilength
|
||||
result.w *= ilength
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates spherical linear interpolation between two [Quaternion]
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Quaternion.sLerp(q2: Vector4, amount: Float): Quaternion {
|
||||
var result: Quaternion = kQuaternion()
|
||||
|
||||
var cosHalfTheta: Float = this.x * q2.x + this.y * q2.y + this.z * q2.z + this.w * q2.w
|
||||
|
||||
if (cosHalfTheta < 0) {
|
||||
q2.x = -q2.x
|
||||
q2.y = -q2.y
|
||||
q2.z = -q2.z
|
||||
q2.w = -q2.w
|
||||
cosHalfTheta = -cosHalfTheta
|
||||
}
|
||||
|
||||
if (abs(cosHalfTheta) >= 1.0f) result = this else if (cosHalfTheta > 0.95f) result =
|
||||
this.nLerp(q2, amount) else {
|
||||
val halfTheta: Float = acos(cosHalfTheta)
|
||||
val sinHalfTheta: Float = sqrt(1.0f - cosHalfTheta * cosHalfTheta)
|
||||
if (abs(sinHalfTheta) < 0.001f) {
|
||||
result.x = this.x * 0.5f + q2.x * 0.5f
|
||||
result.y = this.y * 0.5f + q2.y * 0.5f
|
||||
result.z = this.z * 0.5f + q2.z * 0.5f
|
||||
result.w = this.w * 0.5f + q2.w * 0.5f
|
||||
} else {
|
||||
val ratioA: Float = sin((1 - amount) * halfTheta) / sinHalfTheta
|
||||
val ratioB: Float = sin(amount * halfTheta) / sinHalfTheta
|
||||
result.x = this.x * ratioA + q2.x * ratioB
|
||||
result.y = this.y * ratioA + q2.y * ratioB
|
||||
result.z = this.z * ratioA + q2.z * ratioB
|
||||
result.w = this.w * ratioA + q2.w * ratioB
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rotation angle and axis for a given [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Quaternion.toAxisAngle(outAxis: CPointer<Vector3>, outAngle: CPointer<FloatVar>) {
|
||||
QuaternionToAxisAngle(this.readValue(), outAxis, outAngle)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Euler angles equivalent to [Quaternion] (roll, pitch, yaw)
|
||||
* NOTE: Angles are returned in a Vector3 struct in radians
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Quaternion.toEuler(): Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
|
||||
// Roll (x-axis rotation)
|
||||
|
||||
// Roll (x-axis rotation)
|
||||
val x0: Float = 2.0f * (this.w * this.x + this.y * this.z)
|
||||
val x1: Float = 1.0f - 2.0f * (this.x * this.x + this.y * this.y)
|
||||
result.x = atan2(x0, x1)
|
||||
|
||||
// Pitch (y-axis rotation)
|
||||
|
||||
// Pitch (y-axis rotation)
|
||||
var y0: Float = 2.0f * (this.w * this.y - this.z * this.x)
|
||||
y0 = if (y0 > 1.0f) 1.0f else y0
|
||||
y0 = if (y0 < -1.0f) -1.0f else y0
|
||||
result.y = asin(y0)
|
||||
|
||||
// Yaw (z-axis rotation)
|
||||
|
||||
// Yaw (z-axis rotation)
|
||||
val z0: Float = 2.0f * (this.w * this.z + this.x * this.y)
|
||||
val z1: Float = 1.0f - 2.0f * (this.y * this.y + this.z * this.z)
|
||||
result.z = atan2(z0, z1)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Euler angles equivalent to [Quaternion] (roll, pitch, yaw)
|
||||
* NOTE: Angles are returned in a [Vector3] struct in radians
|
||||
* @return [Quaternion]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Quaternion.transform(mat: Matrix): Quaternion {
|
||||
val result: Quaternion = kQuaternion()
|
||||
|
||||
result.x = mat.m0 * this.x + mat.m4 * this.y + mat.m8 * this.z + mat.m12 * this.w
|
||||
result.y = mat.m1 * this.x + mat.m5 * this.y + mat.m9 * this.z + mat.m13 * this.w
|
||||
result.z = mat.m2 * this.x + mat.m6 * this.y + mat.m10 * this.z + mat.m14 * this.w
|
||||
result.w = mat.m3 * this.x + mat.m7 * this.y + mat.m11 * this.z + mat.m15 * this.w
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Get the Euler angles equivalent to [Quaternion] (roll, pitch, yaw)
|
||||
// * NOTE: Angles are returned in a [Vector3] struct in radians
|
||||
// * @return [Quaternion]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Quaternion.transform(mat: Matrix): Quaternion {
|
||||
// val result: Quaternion = kQuaternion()
|
||||
//
|
||||
// result.x = mat.m0 * this.x + mat.m4 * this.y + mat.m8 * this.z + mat.m12 * this.w
|
||||
// result.y = mat.m1 * this.x + mat.m5 * this.y + mat.m9 * this.z + mat.m13 * this.w
|
||||
// result.z = mat.m2 * this.x + mat.m6 * this.y + mat.m10 * this.z + mat.m14 * this.w
|
||||
// result.w = mat.m3 * this.x + mat.m7 * this.y + mat.m11 * this.z + mat.m15 * this.w
|
||||
//
|
||||
// return result
|
||||
//}
|
|
@ -12,11 +12,10 @@ import kotlin.math.*
|
|||
|
||||
/**
|
||||
* Constructor function for [Vector2]
|
||||
* @param [allocator] Uses `MemScope()` by default.
|
||||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kVector2(x: Float = 0F, y: Float = 0F, allocator: AutofreeScope = MemScope()): Vector2 {
|
||||
inline fun kVector2(x: Float = 0F, y: Float = 0F, allocator: AutofreeScope): Vector2 {
|
||||
return allocator.alloc<Vector2> {
|
||||
this.x = x
|
||||
this.y = y
|
||||
|
@ -181,82 +180,82 @@ inline fun Vector2.lerp(v2: Vector2, amount: Float) : Vector2 {
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate reflected [Vector2] to normal
|
||||
* * @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector2.reflect(normal: Vector2) : Vector2 {
|
||||
val result: Vector2 = kVector2()
|
||||
///**
|
||||
// * Calculate reflected [Vector2] to normal
|
||||
// * * @return [Vector2]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector2.reflect(normal: Vector2) : Vector2 {
|
||||
// val result: Vector2 = kVector2()
|
||||
//
|
||||
// val dotProduct: Float = this.x * normal.x + this.y * normal.y // Dot product
|
||||
//
|
||||
//
|
||||
// result.x = this.x - 2.0f * normal.x * dotProduct
|
||||
// result.y = this.y - 2.0f * normal.y * dotProduct
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
val dotProduct: Float = this.x * normal.x + this.y * normal.y // Dot product
|
||||
///**
|
||||
// * Rotate [Vector2] by [angle]
|
||||
// * @return [Vector2]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector2.rotate(angle: Float) : Vector2 {
|
||||
// val result: Vector2 = kVector2()
|
||||
//
|
||||
// val cosres: Float = cos(angle)
|
||||
// val sinres: Float = sin(angle)
|
||||
//
|
||||
// result.x = this.x * cosres - this.y * sinres
|
||||
// result.y = this.x * sinres + this.y * cosres
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
///**
|
||||
// * Move [Vector2] towards target
|
||||
// * @return [Vector2]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector2.moveTowards(target: Vector2, maxDistance: Float) : Vector2 {
|
||||
// val result: Vector2 = kVector2()
|
||||
//
|
||||
// val dx: Float = target.x - this.x
|
||||
// val dy: Float = target.y - this.y
|
||||
// val value = dx * dx + dy * dy
|
||||
//
|
||||
// if (value == 0f || maxDistance >= 0 && value <= maxDistance * maxDistance) return target
|
||||
//
|
||||
// val dist: Float = sqrt(value)
|
||||
//
|
||||
// result.x = this.x + dx / dist * maxDistance
|
||||
// result.y = this.y + dy / dist * maxDistance
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
result.x = this.x - 2.0f * normal.x * dotProduct
|
||||
result.y = this.y - 2.0f * normal.y * dotProduct
|
||||
///**
|
||||
// * Invert the given [Vector2]
|
||||
// * @return [Vector2]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector2.invert(): Vector2 { return kVector2(1.0f / this.x, 1.0f / this.y) }
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate [Vector2] by [angle]
|
||||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector2.rotate(angle: Float) : Vector2 {
|
||||
val result: Vector2 = kVector2()
|
||||
|
||||
val cosres: Float = cos(angle)
|
||||
val sinres: Float = sin(angle)
|
||||
|
||||
result.x = this.x * cosres - this.y * sinres
|
||||
result.y = this.x * sinres + this.y * cosres
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Move [Vector2] towards target
|
||||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector2.moveTowards(target: Vector2, maxDistance: Float) : Vector2 {
|
||||
val result: Vector2 = kVector2()
|
||||
|
||||
val dx: Float = target.x - this.x
|
||||
val dy: Float = target.y - this.y
|
||||
val value = dx * dx + dy * dy
|
||||
|
||||
if (value == 0f || maxDistance >= 0 && value <= maxDistance * maxDistance) return target
|
||||
|
||||
val dist: Float = sqrt(value)
|
||||
|
||||
result.x = this.x + dx / dist * maxDistance
|
||||
result.y = this.y + dy / dist * maxDistance
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the given [Vector2]
|
||||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector2.invert(): Vector2 { return kVector2(1.0f / this.x, 1.0f / this.y) }
|
||||
|
||||
/**
|
||||
* Clamp the components of the [Vector2] between
|
||||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector2.clamp(min: Vector2, max: Vector2) : Vector2 {
|
||||
val result: Vector2 = kVector2()
|
||||
|
||||
result.x = min(max.x, max(min.x, this.x))
|
||||
result.y = min(max.y, max(min.y, this.y))
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Clamp the components of the [Vector2] between
|
||||
// * @return [Vector2]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector2.clamp(min: Vector2, max: Vector2) : Vector2 {
|
||||
// val result: Vector2 = kVector2()
|
||||
//
|
||||
// result.x = min(max.x, max(min.x, this.x))
|
||||
// result.y = min(max.y, max(min.y, this.y))
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
@Deprecated("Use Kotlin's internal coerceIn function", ReplaceWith("coerceIn()"))
|
||||
/**
|
||||
|
|
|
@ -12,11 +12,10 @@ import kotlin.math.*
|
|||
|
||||
/**
|
||||
* Constructor function for [Vector3]
|
||||
* @param [allocator] Uses `MemScope()` by default.
|
||||
* @return [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kVector3(x: Float = 0F, y: Float = 0F, z: Float = 0F, allocator: AutofreeScope = MemScope()): Vector3 {
|
||||
inline fun kVector3(x: Float = 0F, y: Float = 0F, z: Float = 0F, allocator: AutofreeScope): Vector3 {
|
||||
return allocator.alloc<Vector3> {
|
||||
this.x = x
|
||||
this.y = y
|
||||
|
@ -61,28 +60,28 @@ inline fun Vector3.distance(v3: Vector3) : Float = sqrt((this.x - v3.x)*(this.x
|
|||
*/
|
||||
inline fun Vector3.distanceSqr(v3: Vector3) : Float = ((this.x - v3.x)*(this.x - v3.x) + (this.y - v3.y)*(this.y - v3.y) + (this.z - v3.z)*(this.z - v3.z))
|
||||
|
||||
/**
|
||||
* Calculate angle from two [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.angle(v3: Vector3) : Float {
|
||||
val result: Float
|
||||
///**
|
||||
// * Calculate angle from two [Vector3]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.angle(v3: Vector3) : Float {
|
||||
// val result: Float
|
||||
//
|
||||
// val cross = kVector3(this.y*v3.z - this.z*v3.y, this.z*v3.x - this.x*v3.z, this.x*v3.y - this.y*v3.x )
|
||||
// val len = sqrt(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z)
|
||||
// val dot = (this.x*v3.x + this.y*v3.y + this.z*v3.z)
|
||||
//
|
||||
// result = atan2(len, dot)
|
||||
// return result
|
||||
//}
|
||||
|
||||
val cross = kVector3(this.y*v3.z - this.z*v3.y, this.z*v3.x - this.x*v3.z, this.x*v3.y - this.y*v3.x )
|
||||
val len = sqrt(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z)
|
||||
val dot = (this.x*v3.x + this.y*v3.y + this.z*v3.z)
|
||||
|
||||
result = atan2(len, dot)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate two [Vector3] cross product
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.crossProduct(v2: Vector3): Vector3 {
|
||||
return kVector3(this.y * v2.z - this.z * v2.y, this.z * v2.x - this.x * v2.z, this.x * v2.y - this.y * v2.x)
|
||||
}
|
||||
///**
|
||||
// * Calculate two [Vector3] cross product
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.crossProduct(v2: Vector3): Vector3 {
|
||||
// return kVector3(this.y * v2.z - this.z * v2.y, this.z * v2.x - this.x * v2.z, this.x * v2.y - this.y * v2.x)
|
||||
//}
|
||||
|
||||
/**
|
||||
* Scale [Vector3] (multiply by value)
|
||||
|
@ -189,89 +188,89 @@ inline fun Vector3.transform(mat: Matrix) : Vector3 {
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a [Vector3] by [Quaternion] rotation
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.rotateByQuaternion(q: Quaternion): Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
///**
|
||||
// * Transform a [Vector3] by [Quaternion] rotation
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.rotateByQuaternion(q: Quaternion): Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// result.x =
|
||||
// this.x * (q.x * q.x + q.w * q.w - q.y * q.y - q.z * q.z) + this.y * (2 * q.x * q.y - 2 * q.w * q.z) + this.z * (2 * q.x * q.z + 2 * q.w * q.y)
|
||||
// result.y =
|
||||
// this.x * (2 * q.w * q.z + 2 * q.x * q.y) + this.y * (q.w * q.w - q.x * q.x + q.y * q.y - q.z * q.z) + this.z * (-2 * q.w * q.x + 2 * q.y * q.z)
|
||||
// result.z =
|
||||
// this.x * (-2 * q.w * q.y + 2 * q.x * q.z) + this.y * (2 * q.w * q.x + 2 * q.y * q.z) + this.z * (q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
result.x =
|
||||
this.x * (q.x * q.x + q.w * q.w - q.y * q.y - q.z * q.z) + this.y * (2 * q.x * q.y - 2 * q.w * q.z) + this.z * (2 * q.x * q.z + 2 * q.w * q.y)
|
||||
result.y =
|
||||
this.x * (2 * q.w * q.z + 2 * q.x * q.y) + this.y * (q.w * q.w - q.x * q.x + q.y * q.y - q.z * q.z) + this.z * (-2 * q.w * q.x + 2 * q.y * q.z)
|
||||
result.z =
|
||||
this.x * (-2 * q.w * q.y + 2 * q.x * q.z) + this.y * (2 * q.w * q.x + 2 * q.y * q.z) + this.z * (q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a [Vector3] around an [axis]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.rotateByAxisAngle(axis: Vector3, angle: Float): Vector3 {
|
||||
// Using Euler-Rodrigues Formula
|
||||
// Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
|
||||
|
||||
// Using Euler-Rodrigues Formula
|
||||
// Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
|
||||
val result: Vector3 = this
|
||||
var ang = angle
|
||||
|
||||
// Vector3Normalize(axis);
|
||||
|
||||
// Vector3Normalize(axis);
|
||||
var length: Float = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
||||
if (length == 0.0f) length = 1.0f
|
||||
val ilength = 1.0f / length
|
||||
axis.x *= ilength
|
||||
axis.y *= ilength
|
||||
axis.z *= ilength
|
||||
|
||||
ang /= 2.0f
|
||||
var a: Float = sin(angle)
|
||||
val b = axis.x * a
|
||||
val c = axis.y * a
|
||||
val d = axis.z * a
|
||||
a = cos(angle)
|
||||
val w: Vector3 = kVector3(b, c, d)
|
||||
|
||||
// Vector3CrossProduct(w, v)
|
||||
|
||||
// Vector3CrossProduct(w, v)
|
||||
val wv: Vector3 = kVector3(w.y * this.z - w.z * this.y, w.z * this.x - w.x * this.z, w.x * this.y - w.y * this.x)
|
||||
|
||||
// Vector3CrossProduct(w, wv)
|
||||
|
||||
// Vector3CrossProduct(w, wv)
|
||||
val wwv: Vector3 = kVector3(w.y * wv.z - w.z * wv.y, w.z * wv.x - w.x * wv.z, w.x * wv.y - w.y * wv.x)
|
||||
|
||||
// Vector3Scale(wv, 2 * a)
|
||||
|
||||
// Vector3Scale(wv, 2 * a)
|
||||
a *= 2f
|
||||
wv.x *= a
|
||||
wv.y *= a
|
||||
wv.z *= a
|
||||
|
||||
// Vector3Scale(wwv, 2)
|
||||
|
||||
// Vector3Scale(wwv, 2)
|
||||
wwv.x *= 2
|
||||
wwv.y *= 2
|
||||
wwv.z *= 2
|
||||
|
||||
result.x += wv.x
|
||||
result.y += wv.y
|
||||
result.z += wv.z
|
||||
|
||||
result.x += wwv.x
|
||||
result.y += wwv.y
|
||||
result.z += wwv.z
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Rotates a [Vector3] around an [axis]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.rotateByAxisAngle(axis: Vector3, angle: Float): Vector3 {
|
||||
// // Using Euler-Rodrigues Formula
|
||||
// // Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
|
||||
//
|
||||
// // Using Euler-Rodrigues Formula
|
||||
// // Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
|
||||
// val result: Vector3 = this
|
||||
// var ang = angle
|
||||
//
|
||||
// // Vector3Normalize(axis);
|
||||
//
|
||||
// // Vector3Normalize(axis);
|
||||
// var length: Float = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
||||
// if (length == 0.0f) length = 1.0f
|
||||
// val ilength = 1.0f / length
|
||||
// axis.x *= ilength
|
||||
// axis.y *= ilength
|
||||
// axis.z *= ilength
|
||||
//
|
||||
// ang /= 2.0f
|
||||
// var a: Float = sin(angle)
|
||||
// val b = axis.x * a
|
||||
// val c = axis.y * a
|
||||
// val d = axis.z * a
|
||||
// a = cos(angle)
|
||||
// val w: Vector3 = kVector3(b, c, d)
|
||||
//
|
||||
// // Vector3CrossProduct(w, v)
|
||||
//
|
||||
// // Vector3CrossProduct(w, v)
|
||||
// val wv: Vector3 = kVector3(w.y * this.z - w.z * this.y, w.z * this.x - w.x * this.z, w.x * this.y - w.y * this.x)
|
||||
//
|
||||
// // Vector3CrossProduct(w, wv)
|
||||
//
|
||||
// // Vector3CrossProduct(w, wv)
|
||||
// val wwv: Vector3 = kVector3(w.y * wv.z - w.z * wv.y, w.z * wv.x - w.x * wv.z, w.x * wv.y - w.y * wv.x)
|
||||
//
|
||||
// // Vector3Scale(wv, 2 * a)
|
||||
//
|
||||
// // Vector3Scale(wv, 2 * a)
|
||||
// a *= 2f
|
||||
// wv.x *= a
|
||||
// wv.y *= a
|
||||
// wv.z *= a
|
||||
//
|
||||
// // Vector3Scale(wwv, 2)
|
||||
//
|
||||
// // Vector3Scale(wwv, 2)
|
||||
// wwv.x *= 2
|
||||
// wwv.y *= 2
|
||||
// wwv.z *= 2
|
||||
//
|
||||
// result.x += wv.x
|
||||
// result.y += wv.y
|
||||
// result.z += wv.z
|
||||
//
|
||||
// result.x += wwv.x
|
||||
// result.y += wwv.y
|
||||
// result.z += wwv.z
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
/**
|
||||
* Calculate linear interpolation between two [Vector3]
|
||||
|
@ -297,267 +296,267 @@ inline fun Vector3.orthoNormalize(v3: CPointer<Vector3>) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate reflected [Vector3] to normal
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.reflect(normal: Vector3) : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
///**
|
||||
// * Calculate reflected [Vector3] to normal
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.reflect(normal: Vector3) : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// // I is the original vector
|
||||
// // N is the normal of the incident plane
|
||||
// // R = I - (2*N*(DotProduct[I, N]))
|
||||
//
|
||||
//
|
||||
// // I is the original vector
|
||||
// // N is the normal of the incident plane
|
||||
// // R = I - (2*N*(DotProduct[I, N]))
|
||||
// val dotProduct: Float = this.x * normal.x + this.y * normal.y + this.z * normal.z
|
||||
//
|
||||
// result.x = this.x - 2.0f * normal.x * dotProduct
|
||||
// result.y = this.y - 2.0f * normal.y * dotProduct
|
||||
// result.z = this.z - 2.0f * normal.z * dotProduct
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
// I is the original vector
|
||||
// N is the normal of the incident plane
|
||||
// R = I - (2*N*(DotProduct[I, N]))
|
||||
///**
|
||||
// * Calculate one [Vector3] perpendicular vector
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.perpendicular() : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// var min = abs(this.x)
|
||||
// var cardinalAxis: Vector3 = kVector3(1.0f, 0.0f, 0.0f)
|
||||
//
|
||||
// if (abs(this.y) < min) {
|
||||
// min = abs(this.y)
|
||||
// val tmp: Vector3 = kVector3(0.0f, 1.0f, 0.0f)
|
||||
// cardinalAxis = tmp
|
||||
// }
|
||||
//
|
||||
// if (abs(this.z) < min) {
|
||||
// val tmp: Vector3 = kVector3(0.0f, 0.0f, 1.0f)
|
||||
// cardinalAxis = tmp
|
||||
// }
|
||||
//
|
||||
// // Cross product between vectors
|
||||
//
|
||||
// // Cross product between vectors
|
||||
// result.x = this.y * cardinalAxis.z - this.z * cardinalAxis.y
|
||||
// result.y = this.z * cardinalAxis.x - this.x * cardinalAxis.z
|
||||
// result.z = this.x * cardinalAxis.y - this.y * cardinalAxis.x
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
///**
|
||||
// * Invert the given [Vector3]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.invert(): Vector3 {
|
||||
//
|
||||
// return kVector3(1.0f / this.x, 1.0f / this.y, 1.0f / this.z)
|
||||
//}
|
||||
|
||||
|
||||
// I is the original vector
|
||||
// N is the normal of the incident plane
|
||||
// R = I - (2*N*(DotProduct[I, N]))
|
||||
val dotProduct: Float = this.x * normal.x + this.y * normal.y + this.z * normal.z
|
||||
///**
|
||||
// * Get min value for each pair of components
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.min(v3: Vector3) : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// result.x = min(this.x, v3.x)
|
||||
// result.y = min(this.y, v3.y)
|
||||
// result.z = min(this.z, v3.z)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
result.x = this.x - 2.0f * normal.x * dotProduct
|
||||
result.y = this.y - 2.0f * normal.y * dotProduct
|
||||
result.z = this.z - 2.0f * normal.z * dotProduct
|
||||
///**
|
||||
// * Get max value for each pair of components
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.max(v3: Vector3) : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// result.x = max(this.x, v3.x)
|
||||
// result.y = max(this.y, v3.y)
|
||||
// result.z = max(this.z, v3.z)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Get max value for each pair of components
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.barycenter(a: Vector3, b: Vector3, c: Vector3) : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// val v0: Vector3 = kVector3(b.x - a.x, b.y - a.y, b.z - a.z) // Vector3Subtract(b, a)
|
||||
//
|
||||
// val v1: Vector3 = kVector3(c.x - a.x, c.y - a.y, c.z - a.z) // Vector3Subtract(c, a)
|
||||
//
|
||||
// val v2: Vector3 = kVector3(this.x - a.x, this.y - a.y, this.z - a.z) // Vector3Subtract(p, a)
|
||||
//
|
||||
// val d00 = v0.x * v0.x + v0.y * v0.y + v0.z * v0.z // Vector3DotProduct(v0, v0)
|
||||
//
|
||||
// val d01 = v0.x * v1.x + v0.y * v1.y + v0.z * v1.z // Vector3DotProduct(v0, v1)
|
||||
//
|
||||
// val d11 = v1.x * v1.x + v1.y * v1.y + v1.z * v1.z // Vector3DotProduct(v1, v1)
|
||||
//
|
||||
// val d20 = v2.x * v0.x + v2.y * v0.y + v2.z * v0.z // Vector3DotProduct(v2, v0)
|
||||
//
|
||||
// val d21 = v2.x * v1.x + v2.y * v1.y + v2.z * v1.z // Vector3DotProduct(v2, v1)
|
||||
//
|
||||
//
|
||||
// val denom = d00 * d11 - d01 * d01
|
||||
//
|
||||
// result.y = (d11 * d20 - d01 * d21) / denom
|
||||
// result.z = (d00 * d21 - d01 * d20) / denom
|
||||
// result.x = 1.0f - (result.z + result.y)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
/**
|
||||
* Calculate one [Vector3] perpendicular vector
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.perpendicular() : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
///**
|
||||
// * Projects a [Vector3] from screen space into object space
|
||||
// * NOTE: We are avoiding calling other raymath functions despite available
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.unproject(projection: Matrix, view: Matrix) : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// // Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
|
||||
//
|
||||
// // Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
|
||||
// val matViewProj: Matrix = kMatrix( // MatrixMultiply(view, projection);
|
||||
// view.m0 * projection.m0 + view.m1 * projection.m4 + view.m2 * projection.m8 + view.m3 * projection.m12,
|
||||
// view.m0 * projection.m1 + view.m1 * projection.m5 + view.m2 * projection.m9 + view.m3 * projection.m13,
|
||||
// view.m0 * projection.m2 + view.m1 * projection.m6 + view.m2 * projection.m10 + view.m3 * projection.m14,
|
||||
// view.m0 * projection.m3 + view.m1 * projection.m7 + view.m2 * projection.m11 + view.m3 * projection.m15,
|
||||
// view.m4 * projection.m0 + view.m5 * projection.m4 + view.m6 * projection.m8 + view.m7 * projection.m12,
|
||||
// view.m4 * projection.m1 + view.m5 * projection.m5 + view.m6 * projection.m9 + view.m7 * projection.m13,
|
||||
// view.m4 * projection.m2 + view.m5 * projection.m6 + view.m6 * projection.m10 + view.m7 * projection.m14,
|
||||
// view.m4 * projection.m3 + view.m5 * projection.m7 + view.m6 * projection.m11 + view.m7 * projection.m15,
|
||||
// view.m8 * projection.m0 + view.m9 * projection.m4 + view.m10 * projection.m8 + view.m11 * projection.m12,
|
||||
// view.m8 * projection.m1 + view.m9 * projection.m5 + view.m10 * projection.m9 + view.m11 * projection.m13,
|
||||
// view.m8 * projection.m2 + view.m9 * projection.m6 + view.m10 * projection.m10 + view.m11 * projection.m14,
|
||||
// view.m8 * projection.m3 + view.m9 * projection.m7 + view.m10 * projection.m11 + view.m11 * projection.m15,
|
||||
// view.m12 * projection.m0 + view.m13 * projection.m4 + view.m14 * projection.m8 + view.m15 * projection.m12,
|
||||
// view.m12 * projection.m1 + view.m13 * projection.m5 + view.m14 * projection.m9 + view.m15 * projection.m13,
|
||||
// view.m12 * projection.m2 + view.m13 * projection.m6 + view.m14 * projection.m10 + view.m15 * projection.m14,
|
||||
// view.m12 * projection.m3 + view.m13 * projection.m7 + view.m14 * projection.m11 + view.m15 * projection.m15
|
||||
// )
|
||||
//
|
||||
// // Calculate inverted matrix -> MatrixInvert(matViewProj);
|
||||
// // Cache the matrix values (speed optimization)
|
||||
//
|
||||
// // Calculate inverted matrix -> MatrixInvert(matViewProj);
|
||||
// // Cache the matrix values (speed optimization)
|
||||
// val a00 = matViewProj.m0
|
||||
// val a01 = matViewProj.m1
|
||||
// val a02 = matViewProj.m2
|
||||
// val a03 = matViewProj.m3
|
||||
// val a10 = matViewProj.m4
|
||||
// val a11 = matViewProj.m5
|
||||
// val a12 = matViewProj.m6
|
||||
// val a13 = matViewProj.m7
|
||||
// val a20 = matViewProj.m8
|
||||
// val a21 = matViewProj.m9
|
||||
// val a22 = matViewProj.m10
|
||||
// val a23 = matViewProj.m11
|
||||
// val a30 = matViewProj.m12
|
||||
// val a31 = matViewProj.m13
|
||||
// val a32 = matViewProj.m14
|
||||
// val a33 = matViewProj.m15
|
||||
//
|
||||
// val b00 = a00 * a11 - a01 * a10
|
||||
// val b01 = a00 * a12 - a02 * a10
|
||||
// val b02 = a00 * a13 - a03 * a10
|
||||
// val b03 = a01 * a12 - a02 * a11
|
||||
// val b04 = a01 * a13 - a03 * a11
|
||||
// val b05 = a02 * a13 - a03 * a12
|
||||
// val b06 = a20 * a31 - a21 * a30
|
||||
// val b07 = a20 * a32 - a22 * a30
|
||||
// val b08 = a20 * a33 - a23 * a30
|
||||
// val b09 = a21 * a32 - a22 * a31
|
||||
// val b10 = a21 * a33 - a23 * a31
|
||||
// val b11 = a22 * a33 - a23 * a32
|
||||
//
|
||||
// // Calculate the invert determinant (inlined to avoid double-caching)
|
||||
//
|
||||
// // Calculate the invert determinant (inlined to avoid double-caching)
|
||||
// val invDet = 1.0f / (b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06)
|
||||
//
|
||||
// val matViewProjInv: Matrix = kMatrix(
|
||||
// (a11 * b11 - a12 * b10 + a13 * b09) * invDet,
|
||||
// (-a01 * b11 + a02 * b10 - a03 * b09) * invDet,
|
||||
// (a31 * b05 - a32 * b04 + a33 * b03) * invDet,
|
||||
// (-a21 * b05 + a22 * b04 - a23 * b03) * invDet,
|
||||
// (-a10 * b11 + a12 * b08 - a13 * b07) * invDet,
|
||||
// (a00 * b11 - a02 * b08 + a03 * b07) * invDet,
|
||||
// (-a30 * b05 + a32 * b02 - a33 * b01) * invDet,
|
||||
// (a20 * b05 - a22 * b02 + a23 * b01) * invDet,
|
||||
// (a10 * b10 - a11 * b08 + a13 * b06) * invDet,
|
||||
// (-a00 * b10 + a01 * b08 - a03 * b06) * invDet,
|
||||
// (a30 * b04 - a31 * b02 + a33 * b00) * invDet,
|
||||
// (-a20 * b04 + a21 * b02 - a23 * b00) * invDet,
|
||||
// (-a10 * b09 + a11 * b07 - a12 * b06) * invDet,
|
||||
// (a00 * b09 - a01 * b07 + a02 * b06) * invDet,
|
||||
// (-a30 * b03 + a31 * b01 - a32 * b00) * invDet,
|
||||
// (a20 * b03 - a21 * b01 + a22 * b00) * invDet
|
||||
// )
|
||||
//
|
||||
// // Create quaternion from source point
|
||||
//
|
||||
// // Create quaternion from source point
|
||||
// val quat: Quaternion = kQuaternion(this.x, this.y, this.z, 1.0f)
|
||||
//
|
||||
// // Multiply quat point by unproject matrix
|
||||
//
|
||||
// // Multiply quat point by unproject matrix
|
||||
// val qtransformed: Quaternion = kQuaternion( // QuaternionTransform(quat, matViewProjInv)
|
||||
// matViewProjInv.m0 * quat.x + matViewProjInv.m4 * quat.y + matViewProjInv.m8 * quat.z + matViewProjInv.m12 * quat.w,
|
||||
// matViewProjInv.m1 * quat.x + matViewProjInv.m5 * quat.y + matViewProjInv.m9 * quat.z + matViewProjInv.m13 * quat.w,
|
||||
// matViewProjInv.m2 * quat.x + matViewProjInv.m6 * quat.y + matViewProjInv.m10 * quat.z + matViewProjInv.m14 * quat.w,
|
||||
// matViewProjInv.m3 * quat.x + matViewProjInv.m7 * quat.y + matViewProjInv.m11 * quat.z + matViewProjInv.m15 * quat.w
|
||||
// )
|
||||
//
|
||||
// // Normalized world points in vectors
|
||||
//
|
||||
// // Normalized world points in vectors
|
||||
// result.x = qtransformed.x / qtransformed.w
|
||||
// result.y = qtransformed.y / qtransformed.w
|
||||
// result.z = qtransformed.z / qtransformed.w
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
var min = abs(this.x)
|
||||
var cardinalAxis: Vector3 = kVector3(1.0f, 0.0f, 0.0f)
|
||||
///**
|
||||
// * Get [Vector3] as float array
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.toFloatV() : float3 {
|
||||
// return Vector3ToFloatV(this.readValue()).getPointer(MemScope()).pointed
|
||||
//}
|
||||
|
||||
if (abs(this.y) < min) {
|
||||
min = abs(this.y)
|
||||
val tmp: Vector3 = kVector3(0.0f, 1.0f, 0.0f)
|
||||
cardinalAxis = tmp
|
||||
}
|
||||
|
||||
if (abs(this.z) < min) {
|
||||
val tmp: Vector3 = kVector3(0.0f, 0.0f, 1.0f)
|
||||
cardinalAxis = tmp
|
||||
}
|
||||
|
||||
// Cross product between vectors
|
||||
|
||||
// Cross product between vectors
|
||||
result.x = this.y * cardinalAxis.z - this.z * cardinalAxis.y
|
||||
result.y = this.z * cardinalAxis.x - this.x * cardinalAxis.z
|
||||
result.z = this.x * cardinalAxis.y - this.y * cardinalAxis.x
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the given [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.invert(): Vector3 {
|
||||
|
||||
return kVector3(1.0f / this.x, 1.0f / this.y, 1.0f / this.z)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get min value for each pair of components
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.min(v3: Vector3) : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
|
||||
result.x = min(this.x, v3.x)
|
||||
result.y = min(this.y, v3.y)
|
||||
result.z = min(this.z, v3.z)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max value for each pair of components
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.max(v3: Vector3) : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
|
||||
result.x = max(this.x, v3.x)
|
||||
result.y = max(this.y, v3.y)
|
||||
result.z = max(this.z, v3.z)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max value for each pair of components
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.barycenter(a: Vector3, b: Vector3, c: Vector3) : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
|
||||
val v0: Vector3 = kVector3(b.x - a.x, b.y - a.y, b.z - a.z) // Vector3Subtract(b, a)
|
||||
|
||||
val v1: Vector3 = kVector3(c.x - a.x, c.y - a.y, c.z - a.z) // Vector3Subtract(c, a)
|
||||
|
||||
val v2: Vector3 = kVector3(this.x - a.x, this.y - a.y, this.z - a.z) // Vector3Subtract(p, a)
|
||||
|
||||
val d00 = v0.x * v0.x + v0.y * v0.y + v0.z * v0.z // Vector3DotProduct(v0, v0)
|
||||
|
||||
val d01 = v0.x * v1.x + v0.y * v1.y + v0.z * v1.z // Vector3DotProduct(v0, v1)
|
||||
|
||||
val d11 = v1.x * v1.x + v1.y * v1.y + v1.z * v1.z // Vector3DotProduct(v1, v1)
|
||||
|
||||
val d20 = v2.x * v0.x + v2.y * v0.y + v2.z * v0.z // Vector3DotProduct(v2, v0)
|
||||
|
||||
val d21 = v2.x * v1.x + v2.y * v1.y + v2.z * v1.z // Vector3DotProduct(v2, v1)
|
||||
|
||||
|
||||
val denom = d00 * d11 - d01 * d01
|
||||
|
||||
result.y = (d11 * d20 - d01 * d21) / denom
|
||||
result.z = (d00 * d21 - d01 * d20) / denom
|
||||
result.x = 1.0f - (result.z + result.y)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Projects a [Vector3] from screen space into object space
|
||||
* NOTE: We are avoiding calling other raymath functions despite available
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.unproject(projection: Matrix, view: Matrix) : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
|
||||
// Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
|
||||
|
||||
// Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
|
||||
val matViewProj: Matrix = kMatrix( // MatrixMultiply(view, projection);
|
||||
view.m0 * projection.m0 + view.m1 * projection.m4 + view.m2 * projection.m8 + view.m3 * projection.m12,
|
||||
view.m0 * projection.m1 + view.m1 * projection.m5 + view.m2 * projection.m9 + view.m3 * projection.m13,
|
||||
view.m0 * projection.m2 + view.m1 * projection.m6 + view.m2 * projection.m10 + view.m3 * projection.m14,
|
||||
view.m0 * projection.m3 + view.m1 * projection.m7 + view.m2 * projection.m11 + view.m3 * projection.m15,
|
||||
view.m4 * projection.m0 + view.m5 * projection.m4 + view.m6 * projection.m8 + view.m7 * projection.m12,
|
||||
view.m4 * projection.m1 + view.m5 * projection.m5 + view.m6 * projection.m9 + view.m7 * projection.m13,
|
||||
view.m4 * projection.m2 + view.m5 * projection.m6 + view.m6 * projection.m10 + view.m7 * projection.m14,
|
||||
view.m4 * projection.m3 + view.m5 * projection.m7 + view.m6 * projection.m11 + view.m7 * projection.m15,
|
||||
view.m8 * projection.m0 + view.m9 * projection.m4 + view.m10 * projection.m8 + view.m11 * projection.m12,
|
||||
view.m8 * projection.m1 + view.m9 * projection.m5 + view.m10 * projection.m9 + view.m11 * projection.m13,
|
||||
view.m8 * projection.m2 + view.m9 * projection.m6 + view.m10 * projection.m10 + view.m11 * projection.m14,
|
||||
view.m8 * projection.m3 + view.m9 * projection.m7 + view.m10 * projection.m11 + view.m11 * projection.m15,
|
||||
view.m12 * projection.m0 + view.m13 * projection.m4 + view.m14 * projection.m8 + view.m15 * projection.m12,
|
||||
view.m12 * projection.m1 + view.m13 * projection.m5 + view.m14 * projection.m9 + view.m15 * projection.m13,
|
||||
view.m12 * projection.m2 + view.m13 * projection.m6 + view.m14 * projection.m10 + view.m15 * projection.m14,
|
||||
view.m12 * projection.m3 + view.m13 * projection.m7 + view.m14 * projection.m11 + view.m15 * projection.m15
|
||||
)
|
||||
|
||||
// Calculate inverted matrix -> MatrixInvert(matViewProj);
|
||||
// Cache the matrix values (speed optimization)
|
||||
|
||||
// Calculate inverted matrix -> MatrixInvert(matViewProj);
|
||||
// Cache the matrix values (speed optimization)
|
||||
val a00 = matViewProj.m0
|
||||
val a01 = matViewProj.m1
|
||||
val a02 = matViewProj.m2
|
||||
val a03 = matViewProj.m3
|
||||
val a10 = matViewProj.m4
|
||||
val a11 = matViewProj.m5
|
||||
val a12 = matViewProj.m6
|
||||
val a13 = matViewProj.m7
|
||||
val a20 = matViewProj.m8
|
||||
val a21 = matViewProj.m9
|
||||
val a22 = matViewProj.m10
|
||||
val a23 = matViewProj.m11
|
||||
val a30 = matViewProj.m12
|
||||
val a31 = matViewProj.m13
|
||||
val a32 = matViewProj.m14
|
||||
val a33 = matViewProj.m15
|
||||
|
||||
val b00 = a00 * a11 - a01 * a10
|
||||
val b01 = a00 * a12 - a02 * a10
|
||||
val b02 = a00 * a13 - a03 * a10
|
||||
val b03 = a01 * a12 - a02 * a11
|
||||
val b04 = a01 * a13 - a03 * a11
|
||||
val b05 = a02 * a13 - a03 * a12
|
||||
val b06 = a20 * a31 - a21 * a30
|
||||
val b07 = a20 * a32 - a22 * a30
|
||||
val b08 = a20 * a33 - a23 * a30
|
||||
val b09 = a21 * a32 - a22 * a31
|
||||
val b10 = a21 * a33 - a23 * a31
|
||||
val b11 = a22 * a33 - a23 * a32
|
||||
|
||||
// Calculate the invert determinant (inlined to avoid double-caching)
|
||||
|
||||
// Calculate the invert determinant (inlined to avoid double-caching)
|
||||
val invDet = 1.0f / (b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06)
|
||||
|
||||
val matViewProjInv: Matrix = kMatrix(
|
||||
(a11 * b11 - a12 * b10 + a13 * b09) * invDet,
|
||||
(-a01 * b11 + a02 * b10 - a03 * b09) * invDet,
|
||||
(a31 * b05 - a32 * b04 + a33 * b03) * invDet,
|
||||
(-a21 * b05 + a22 * b04 - a23 * b03) * invDet,
|
||||
(-a10 * b11 + a12 * b08 - a13 * b07) * invDet,
|
||||
(a00 * b11 - a02 * b08 + a03 * b07) * invDet,
|
||||
(-a30 * b05 + a32 * b02 - a33 * b01) * invDet,
|
||||
(a20 * b05 - a22 * b02 + a23 * b01) * invDet,
|
||||
(a10 * b10 - a11 * b08 + a13 * b06) * invDet,
|
||||
(-a00 * b10 + a01 * b08 - a03 * b06) * invDet,
|
||||
(a30 * b04 - a31 * b02 + a33 * b00) * invDet,
|
||||
(-a20 * b04 + a21 * b02 - a23 * b00) * invDet,
|
||||
(-a10 * b09 + a11 * b07 - a12 * b06) * invDet,
|
||||
(a00 * b09 - a01 * b07 + a02 * b06) * invDet,
|
||||
(-a30 * b03 + a31 * b01 - a32 * b00) * invDet,
|
||||
(a20 * b03 - a21 * b01 + a22 * b00) * invDet
|
||||
)
|
||||
|
||||
// Create quaternion from source point
|
||||
|
||||
// Create quaternion from source point
|
||||
val quat: Quaternion = kQuaternion(this.x, this.y, this.z, 1.0f)
|
||||
|
||||
// Multiply quat point by unproject matrix
|
||||
|
||||
// Multiply quat point by unproject matrix
|
||||
val qtransformed: Quaternion = kQuaternion( // QuaternionTransform(quat, matViewProjInv)
|
||||
matViewProjInv.m0 * quat.x + matViewProjInv.m4 * quat.y + matViewProjInv.m8 * quat.z + matViewProjInv.m12 * quat.w,
|
||||
matViewProjInv.m1 * quat.x + matViewProjInv.m5 * quat.y + matViewProjInv.m9 * quat.z + matViewProjInv.m13 * quat.w,
|
||||
matViewProjInv.m2 * quat.x + matViewProjInv.m6 * quat.y + matViewProjInv.m10 * quat.z + matViewProjInv.m14 * quat.w,
|
||||
matViewProjInv.m3 * quat.x + matViewProjInv.m7 * quat.y + matViewProjInv.m11 * quat.z + matViewProjInv.m15 * quat.w
|
||||
)
|
||||
|
||||
// Normalized world points in vectors
|
||||
|
||||
// Normalized world points in vectors
|
||||
result.x = qtransformed.x / qtransformed.w
|
||||
result.y = qtransformed.y / qtransformed.w
|
||||
result.z = qtransformed.z / qtransformed.w
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [Vector3] as float array
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.toFloatV() : float3 {
|
||||
return Vector3ToFloatV(this.readValue()).getPointer(MemScope()).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp the components of the [Vector3] between
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.clamp(min: Vector3, max: Vector3) : Vector3 {
|
||||
val result: Vector3 = kVector3()
|
||||
|
||||
result.x = min(max.x, max(min.x, this.x))
|
||||
result.y = min(max.y, max(min.y, this.y))
|
||||
result.z = min(max.z, max(min.z, this.z))
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Clamp the components of the [Vector3] between
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.clamp(min: Vector3, max: Vector3) : Vector3 {
|
||||
// val result: Vector3 = kVector3()
|
||||
//
|
||||
// result.x = min(max.x, max(min.x, this.x))
|
||||
// result.y = min(max.y, max(min.y, this.y))
|
||||
// result.z = min(max.z, max(min.z, this.z))
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
@Deprecated("Use Kotlin's internal coerceIn function", ReplaceWith("coerceIn()"))
|
||||
/**
|
||||
|
@ -583,31 +582,31 @@ inline fun Vector3.equalsTo(v: Vector3): Boolean {
|
|||
) && abs(this.z - v.z) <= EPSILON * max(1.0f, max(abs(this.z), abs(v.z))))
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the direction of a refracted ray where v specifies the
|
||||
* normalized direction of the incoming ray, n specifies the
|
||||
* normalized normal vector of the interface of two optical media,
|
||||
* and r specifies the ratio of the refractive index of the medium
|
||||
* from where the ray comes to the refractive index of the medium
|
||||
* on the other side of the surface
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector3.refract(n: Vector3, r: Float) : Vector3 {
|
||||
var result: Vector3 = kVector3()
|
||||
|
||||
val dot: Float = this.x * n.x + this.y * n.y + this.z * n.z
|
||||
var d = 1.0f - r * r * (1.0f - dot * dot)
|
||||
|
||||
if (d >= 0.0f) {
|
||||
d = sqrt(d)
|
||||
this.x = r * this.x - (r * dot + d) * n.x
|
||||
this.y = r * this.y - (r * dot + d) * n.y
|
||||
this.z = r * this.z - (r * dot + d) * n.z
|
||||
result = this
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Compute the direction of a refracted ray where v specifies the
|
||||
// * normalized direction of the incoming ray, n specifies the
|
||||
// * normalized normal vector of the interface of two optical media,
|
||||
// * and r specifies the ratio of the refractive index of the medium
|
||||
// * from where the ray comes to the refractive index of the medium
|
||||
// * on the other side of the surface
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector3.refract(n: Vector3, r: Float) : Vector3 {
|
||||
// var result: Vector3 = kVector3()
|
||||
//
|
||||
// val dot: Float = this.x * n.x + this.y * n.y + this.z * n.z
|
||||
// var d = 1.0f - r * r * (1.0f - dot * dot)
|
||||
//
|
||||
// if (d >= 0.0f) {
|
||||
// d = sqrt(d)
|
||||
// this.x = r * this.x - (r * dot + d) * n.x
|
||||
// this.y = r * this.y - (r * dot + d) * n.y
|
||||
// this.z = r * this.z - (r * dot + d) * n.z
|
||||
// result = this
|
||||
// }
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
/**
|
||||
* Divide vector by [Vector3]
|
||||
|
|
|
@ -12,11 +12,10 @@ import kotlin.math.*
|
|||
|
||||
/**
|
||||
* Constructor function for [Vector4]
|
||||
* @param [allocator] Uses `MemScope()` by default.
|
||||
* @return [Vector4]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kVector4(x: Float = 0F, y: Float = 0F, z: Float = 0F, w: Float = 0F, allocator: AutofreeScope = MemScope()): Vector4 {
|
||||
inline fun kVector4(x: Float = 0F, y: Float = 0F, z: Float = 0F, w: Float = 0F, allocator: AutofreeScope): Vector4 {
|
||||
return allocator.alloc<Vector4> {
|
||||
this.x = x
|
||||
this.y = y
|
||||
|
@ -208,21 +207,21 @@ inline fun Vector4.plus(v4: Vector4) {
|
|||
this.w += v4.w
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate linear interpolation between two [Vector4]
|
||||
* @return [Vector4]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun Vector4.lerp(v4: Vector4, amount: Float): Vector4 {
|
||||
val result: Vector4 = kVector4()
|
||||
|
||||
result.x = this.x + amount * (v4.x - this.x)
|
||||
result.y = this.y + amount * (v4.y - this.y)
|
||||
result.z = this.z + amount * (v4.z - this.z)
|
||||
result.w = this.w + amount * (v4.w - this.w)
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Calculate linear interpolation between two [Vector4]
|
||||
// * @return [Vector4]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun Vector4.lerp(v4: Vector4, amount: Float): Vector4 {
|
||||
// val result: Vector4 = kVector4()
|
||||
//
|
||||
// result.x = this.x + amount * (v4.x - this.x)
|
||||
// result.y = this.y + amount * (v4.y - this.y)
|
||||
// result.z = this.z + amount * (v4.z - this.z)
|
||||
// result.w = this.w + amount * (v4.w - this.w)
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
/**
|
||||
* Due to inability to override equals operator, this is the current workaround checking for equality of the values of a [Vector4]
|
||||
|
@ -335,30 +334,30 @@ inline operator fun Vector4.minusAssign(value: Int) {
|
|||
minusAssign(value.toFloat())
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate two [Vector4] multiplication
|
||||
* @return [Vector4]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline operator fun Vector4.times(v4: Vector4): Vector4 {
|
||||
val result: Vector4 = kVector4()
|
||||
|
||||
val qax: Float = this.x
|
||||
val qay: Float = this.y
|
||||
val qaz: Float = this.z
|
||||
val qaw: Float = this.w
|
||||
val qbx: Float = v4.x
|
||||
val qby: Float = v4.y
|
||||
val qbz: Float = v4.z
|
||||
val qbw: Float = v4.w
|
||||
|
||||
result.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby
|
||||
result.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz
|
||||
result.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx
|
||||
result.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz
|
||||
|
||||
return result
|
||||
}
|
||||
///**
|
||||
// * Calculate two [Vector4] multiplication
|
||||
// * @return [Vector4]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline operator fun Vector4.times(v4: Vector4): Vector4 {
|
||||
// val result: Vector4 = kVector4()
|
||||
//
|
||||
// val qax: Float = this.x
|
||||
// val qay: Float = this.y
|
||||
// val qaz: Float = this.z
|
||||
// val qaw: Float = this.w
|
||||
// val qbx: Float = v4.x
|
||||
// val qby: Float = v4.y
|
||||
// val qbz: Float = v4.z
|
||||
// val qbw: Float = v4.w
|
||||
//
|
||||
// result.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby
|
||||
// result.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz
|
||||
// result.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx
|
||||
// result.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz
|
||||
//
|
||||
// return result
|
||||
//}
|
||||
|
||||
/**
|
||||
* Value will be compared with another [Vector4]
|
||||
|
|
|
@ -186,8 +186,8 @@ inline fun drawGrid(slices: Int, spacing: Float) {
|
|||
* @return [Model]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadModel(fileName: String) : Model {
|
||||
return LoadModel(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadModel(fileName: String, allocator: AutofreeScope) : Model {
|
||||
return LoadModel(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,8 +195,8 @@ inline fun loadModel(fileName: String) : Model {
|
|||
* @return [Model]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadModelFromMesh(mesh: Mesh) : Model {
|
||||
return LoadModelFromMesh(mesh.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun loadModelFromMesh(mesh: Mesh, allocator: AutofreeScope) : Model {
|
||||
return LoadModelFromMesh(mesh.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,8 +212,8 @@ inline fun unloadModel(model: Model) {
|
|||
* @return [Boolean]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getModelBoundingBox(model: Model) : BoundingBox {
|
||||
return GetModelBoundingBox(model.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getModelBoundingBox(model: Model, allocator: AutofreeScope) : BoundingBox {
|
||||
return GetModelBoundingBox(model.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
@ -342,8 +342,8 @@ inline fun exportMesh(mesh: Mesh, fileName: String) : Boolean {
|
|||
* @return [BoundingBox]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getMeshBoundingBox(mesh: Mesh) : BoundingBox {
|
||||
return GetMeshBoundingBox(mesh.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getMeshBoundingBox(mesh: Mesh, allocator: AutofreeScope) : BoundingBox {
|
||||
return GetMeshBoundingBox(mesh.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,8 +363,8 @@ inline fun genMeshTangents(mesh: Mesh) {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshPoly(sides: Int, radius: Float) : Mesh {
|
||||
return GenMeshPoly(sides, radius).getPointer(MemScope()).pointed
|
||||
inline fun genMeshPoly(sides: Int, radius: Float, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshPoly(sides, radius).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,8 +372,8 @@ inline fun genMeshPoly(sides: Int, radius: Float) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshPlane(width: Float, length: Float, resX: Int, resZ: Int) : Mesh {
|
||||
return GenMeshPlane(width, length, resX, resZ).getPointer(MemScope()).pointed
|
||||
inline fun genMeshPlane(width: Float, length: Float, resX: Int, resZ: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshPlane(width, length, resX, resZ).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -381,8 +381,8 @@ inline fun genMeshPlane(width: Float, length: Float, resX: Int, resZ: Int) : Mes
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshCube(width: Float, height: Float, length: Float) : Mesh {
|
||||
return GenMeshCube(width, height, length).getPointer(MemScope()).pointed
|
||||
inline fun genMeshCube(width: Float, height: Float, length: Float, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshCube(width, height, length).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,8 +390,8 @@ inline fun genMeshCube(width: Float, height: Float, length: Float) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshSphere(radius: Float, rings: Int, slices: Int) : Mesh {
|
||||
return GenMeshSphere(radius, rings, slices).getPointer(MemScope()).pointed
|
||||
inline fun genMeshSphere(radius: Float, rings: Int, slices: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshSphere(radius, rings, slices).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -399,8 +399,8 @@ inline fun genMeshSphere(radius: Float, rings: Int, slices: Int) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshHemiSphere(radius: Float, rings: Int, slices: Int) : Mesh {
|
||||
return GenMeshHemiSphere(radius, rings, slices).getPointer(MemScope()).pointed
|
||||
inline fun genMeshHemiSphere(radius: Float, rings: Int, slices: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshHemiSphere(radius, rings, slices).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -408,8 +408,8 @@ inline fun genMeshHemiSphere(radius: Float, rings: Int, slices: Int) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshCylinder(radius: Float, height: Float, slices: Int) : Mesh {
|
||||
return GenMeshCylinder(radius, height, slices).getPointer(MemScope()).pointed
|
||||
inline fun genMeshCylinder(radius: Float, height: Float, slices: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshCylinder(radius, height, slices).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -417,8 +417,8 @@ inline fun genMeshCylinder(radius: Float, height: Float, slices: Int) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshCone(radius: Float, height: Float, slices: Int) : Mesh {
|
||||
return GenMeshCone(radius, height, slices).getPointer(MemScope()).pointed
|
||||
inline fun genMeshCone(radius: Float, height: Float, slices: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshCone(radius, height, slices).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -426,8 +426,8 @@ inline fun genMeshCone(radius: Float, height: Float, slices: Int) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshTorus(radius: Float, size: Float, radSeg: Int, sides: Int) : Mesh {
|
||||
return GenMeshTorus(radius, size, radSeg, sides).getPointer(MemScope()).pointed
|
||||
inline fun genMeshTorus(radius: Float, size: Float, radSeg: Int, sides: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshTorus(radius, size, radSeg, sides).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -435,8 +435,8 @@ inline fun genMeshTorus(radius: Float, size: Float, radSeg: Int, sides: Int) : M
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshKnot(radius: Float, size: Float, radSeg: Int, sides: Int) : Mesh {
|
||||
return GenMeshKnot(radius, size, radSeg, sides).getPointer(MemScope()).pointed
|
||||
inline fun genMeshKnot(radius: Float, size: Float, radSeg: Int, sides: Int, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshKnot(radius, size, radSeg, sides).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -444,8 +444,8 @@ inline fun genMeshKnot(radius: Float, size: Float, radSeg: Int, sides: Int) : Me
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshHeightmap(heightmap: Image, size: Vector3) : Mesh {
|
||||
return GenMeshHeightmap(heightmap.readValue(), size.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genMeshHeightmap(heightmap: Image, size: Vector3, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshHeightmap(heightmap.readValue(), size.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -453,8 +453,8 @@ inline fun genMeshHeightmap(heightmap: Image, size: Vector3) : Mesh {
|
|||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genMeshCubicmap(cubicmap: Image, cubeSize: Vector3) : Mesh {
|
||||
return GenMeshCubicmap(cubicmap.readValue(), cubeSize.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun genMeshCubicmap(cubicmap: Image, cubeSize: Vector3, allocator: AutofreeScope) : Mesh {
|
||||
return GenMeshCubicmap(cubicmap.readValue(), cubeSize.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
@ -465,8 +465,8 @@ inline fun genMeshCubicmap(cubicmap: Image, cubeSize: Vector3) : Mesh {
|
|||
* Load materials from model file
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadMaterials(fileName: String, materialCount: IntVar) : Material? {
|
||||
return LoadMaterials(fileName, materialCount.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun loadMaterials(fileName: String, materialCount: IntVar, allocator: AutofreeScope) : Material? {
|
||||
return LoadMaterials(fileName, materialCount.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -474,8 +474,8 @@ inline fun loadMaterials(fileName: String, materialCount: IntVar) : Material? {
|
|||
* @return [Material]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadMaterialDefault() : Material {
|
||||
return LoadMaterialDefault().getPointer(MemScope()).pointed
|
||||
inline fun loadMaterialDefault(allocator: AutofreeScope) : Material {
|
||||
return LoadMaterialDefault().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -511,8 +511,8 @@ inline fun setModelMeshMaterial(model: Model, meshId: Int, materialId: Int) {
|
|||
* @return [ModelAnimation]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadModelAnimations(fileName: String, animCount: UIntVar) : ModelAnimation? {
|
||||
return LoadModelAnimations(fileName, animCount.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun loadModelAnimations(fileName: String, animCount: UIntVar, allocator: AutofreeScope) : ModelAnimation? {
|
||||
return LoadModelAnimations(fileName, animCount.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -584,8 +584,8 @@ inline fun checkCollisionBoxSphere(box: BoundingBox, center: Vector3, radius: Fl
|
|||
* @return [RayCollision]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getRayCollisionSphere(ray: Ray, center: Vector3, radius: Float) : RayCollision {
|
||||
return GetRayCollisionSphere(ray.readValue(), center.readValue(), radius).getPointer(MemScope()).pointed
|
||||
inline fun getRayCollisionSphere(ray: Ray, center: Vector3, radius: Float, allocator: AutofreeScope) : RayCollision {
|
||||
return GetRayCollisionSphere(ray.readValue(), center.readValue(), radius).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -593,8 +593,8 @@ inline fun getRayCollisionSphere(ray: Ray, center: Vector3, radius: Float) : Ray
|
|||
* @return [RayCollision]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getRayCollisionBox(ray: Ray, box: BoundingBox) : RayCollision {
|
||||
return GetRayCollisionBox(ray.readValue(), box.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getRayCollisionBox(ray: Ray, box: BoundingBox, allocator: AutofreeScope) : RayCollision {
|
||||
return GetRayCollisionBox(ray.readValue(), box.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -602,8 +602,8 @@ inline fun getRayCollisionBox(ray: Ray, box: BoundingBox) : RayCollision {
|
|||
* @return [RayCollision]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getRayCollisionMesh(ray: Ray, mesh: Mesh, transform: Matrix) : RayCollision {
|
||||
return GetRayCollisionMesh(ray.readValue(), mesh.readValue(), transform.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getRayCollisionMesh(ray: Ray, mesh: Mesh, transform: Matrix, allocator: AutofreeScope) : RayCollision {
|
||||
return GetRayCollisionMesh(ray.readValue(), mesh.readValue(), transform.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -611,8 +611,8 @@ inline fun getRayCollisionMesh(ray: Ray, mesh: Mesh, transform: Matrix) : RayCol
|
|||
* @return [RayCollision]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getRayCollisionTriangle(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3) : RayCollision {
|
||||
return GetRayCollisionTriangle(ray.readValue(), p1.readValue(), p2.readValue(), p3.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getRayCollisionTriangle(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3, allocator: AutofreeScope) : RayCollision {
|
||||
return GetRayCollisionTriangle(ray.readValue(), p1.readValue(), p2.readValue(), p3.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -620,8 +620,8 @@ inline fun getRayCollisionTriangle(ray: Ray, p1: Vector3, p2: Vector3, p3: Vecto
|
|||
* @return [RayCollision]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getRayCollisionQuad(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3, p4: Vector3) : RayCollision {
|
||||
return GetRayCollisionQuad(ray.readValue(), p1.readValue(), p2.readValue(), p3.readValue(), p4.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getRayCollisionQuad(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3, p4: Vector3, allocator: AutofreeScope) : RayCollision {
|
||||
return GetRayCollisionQuad(ray.readValue(), p1.readValue(), p2.readValue(), p3.readValue(), p4.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,11 +10,10 @@ import kotlinx.cinterop.ExperimentalForeignApi
|
|||
|
||||
/**
|
||||
* Constructor function for Rectangle using X and Y floats for position.
|
||||
* @param [allocator] Uses `MemScope()` by default.
|
||||
* @return [Rectangle]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kRectangle(x: Float = 0F, y: Float = 0F, width: Float = 0F, height: Float = 0F, allocator: AutofreeScope = MemScope()) : Rectangle {
|
||||
inline fun kRectangle(x: Float = 0F, y: Float = 0F, width: Float = 0F, height: Float = 0F, allocator: AutofreeScope) : Rectangle {
|
||||
return allocator.alloc<Rectangle> {
|
||||
this.x = x
|
||||
this.y = y
|
||||
|
@ -25,11 +24,10 @@ inline fun kRectangle(x: Float = 0F, y: Float = 0F, width: Float = 0F, height: F
|
|||
|
||||
/**
|
||||
* Constructor function for Rectangle that take a kVector2 for position.
|
||||
* @param [allocator] Uses `MemScope()` by default.
|
||||
* @return [Rectangle]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kRectangle(vector2: Vector2 = kVector2(0F, 0F), width: Float = 0F, height: Float = 0F, allocator: AutofreeScope = MemScope()) : Rectangle {
|
||||
inline fun kRectangle(allocator: AutofreeScope, vector2: Vector2 = kVector2(0F, 0F, allocator), width: Float = 0F, height: Float = 0F) : Rectangle {
|
||||
return allocator.alloc<Rectangle> {
|
||||
this.x = vector2.x
|
||||
this.y = vector2.y
|
||||
|
|
|
@ -394,8 +394,8 @@ inline fun checkCollision(point: Vector2, p1: Vector2, p2: Vector2, threshold: I
|
|||
* @return [Rectangle]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getCollision(rec1: Rectangle, rec2: Rectangle) : Rectangle {
|
||||
return GetCollisionRec(rec1.readValue(), rec2.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun getCollision(rec1: Rectangle, rec2: Rectangle, allocator: AutofreeScope) : Rectangle {
|
||||
return GetCollisionRec(rec1.readValue(), rec2.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,8 +14,8 @@ import kotlinx.cinterop.*
|
|||
* @return [Font]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getFontDefault() : Font {
|
||||
return GetFontDefault().getPointer(MemScope()).pointed
|
||||
inline fun getFontDefault(allocator: AutofreeScope) : Font {
|
||||
return GetFontDefault().getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,8 +23,8 @@ inline fun getFontDefault() : Font {
|
|||
* @return [Font]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFont(fileName: String) : Font {
|
||||
return LoadFont(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadFont(fileName: String, allocator: AutofreeScope) : Font {
|
||||
return LoadFont(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,8 +32,8 @@ inline fun loadFont(fileName: String) : Font {
|
|||
* @return [Font]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFont(fileName: String, fontSize: Int, fontChars: IntVar, glyphCount: Int) : Font {
|
||||
return LoadFontEx(fileName, fontSize, fontChars.ptr, glyphCount).getPointer(MemScope()).pointed
|
||||
inline fun loadFont(fileName: String, fontSize: Int, fontChars: IntVar, glyphCount: Int, allocator: AutofreeScope) : Font {
|
||||
return LoadFontEx(fileName, fontSize, fontChars.ptr, glyphCount).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,8 +41,8 @@ inline fun loadFont(fileName: String, fontSize: Int, fontChars: IntVar, glyphCou
|
|||
* @return [Font]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFontFromImage(image: Image, key: Color, firstChar: Int) : Font {
|
||||
return LoadFontFromImage(image.readValue(), key.readValue(), firstChar).getPointer(MemScope()).pointed
|
||||
inline fun loadFontFromImage(image: Image, key: Color, firstChar: Int, allocator: AutofreeScope) : Font {
|
||||
return LoadFontFromImage(image.readValue(), key.readValue(), firstChar).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,8 +50,8 @@ inline fun loadFontFromImage(image: Image, key: Color, firstChar: Int) : Font {
|
|||
* @return [Font]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFontFromMemory(fileType: String, fileData: UByteVar, dataSize: Int, fontSize: Int, fontChars: IntVar, glyphCount: Int) : Font {
|
||||
return LoadFontFromMemory(fileType, fileData.ptr, dataSize, fontSize, fontChars.ptr, glyphCount).getPointer(MemScope()).pointed
|
||||
inline fun loadFontFromMemory(fileType: String, fileData: UByteVar, dataSize: Int, fontSize: Int, fontChars: IntVar, glyphCount: Int, allocator: AutofreeScope) : Font {
|
||||
return LoadFontFromMemory(fileType, fileData.ptr, dataSize, fontSize, fontChars.ptr, glyphCount).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,8 +59,8 @@ inline fun loadFontFromMemory(fileType: String, fileData: UByteVar, dataSize: In
|
|||
* @return [GlyphInfo]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadFontData(fileData: UByteVar, dataSize: Int, fontSize: Int, fontChars: IntVar, glyphCount: Int, type: kaylibkit.kEnums.FontType) : GlyphInfo? {
|
||||
return LoadFontData(fileData.ptr, dataSize, fontSize, fontChars.ptr, glyphCount, type.value)?.getPointer(MemScope())?.pointed
|
||||
inline fun loadFontData(fileData: UByteVar, dataSize: Int, fontSize: Int, fontChars: IntVar, glyphCount: Int, type: kaylibkit.kEnums.FontType, allocator: AutofreeScope) : GlyphInfo? {
|
||||
return LoadFontData(fileData.ptr, dataSize, fontSize, fontChars.ptr, glyphCount, type.value)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,8 +68,8 @@ inline fun loadFontData(fileData: UByteVar, dataSize: Int, fontSize: Int, fontCh
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageFontAtlas(chars: GlyphInfo, recs: CPointerVar<Rectangle>, glyphCount: Int, fontSize: Int, padding: Int, packMethod: Int) : Image {
|
||||
return GenImageFontAtlas(chars.ptr, recs.ptr, glyphCount, fontSize, padding, packMethod).getPointer(MemScope()).pointed
|
||||
inline fun genImageFontAtlas(chars: GlyphInfo, recs: CPointerVar<Rectangle>, glyphCount: Int, fontSize: Int, padding: Int, packMethod: Int, allocator: AutofreeScope) : Image {
|
||||
return GenImageFontAtlas(chars.ptr, recs.ptr, glyphCount, fontSize, padding, packMethod).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,8 +178,8 @@ inline fun textSubtext(text: String, position: Int, length: Int) : String {
|
|||
* @return [String]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun textReplace(text: String, replace: String, by: String) : String {
|
||||
memScoped { return TextReplace(text.cstr.getPointer(MemScope()), replace, by)?.toKString() ?: "Error: Unable to return String" }
|
||||
inline fun textReplace(text: String, replace: String, by: String, allocator: AutofreeScope) : String {
|
||||
memScoped { return TextReplace(text.cstr.getPointer(allocator), replace, by)?.toKString() ?: "Error: Unable to return String" }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -215,8 +215,8 @@ inline fun measureText(text: String, fontSize: Int) : Int {
|
|||
* @return [Vector2]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun measureText(font: Font, text: String, fontSize: Float, spacing: Float) : Vector2 {
|
||||
return MeasureTextEx(font.readValue(), text, fontSize, spacing).getPointer(MemScope()).pointed
|
||||
inline fun measureText(font: Font, text: String, fontSize: Float, spacing: Float, allocator: AutofreeScope) : Vector2 {
|
||||
return MeasureTextEx(font.readValue(), text, fontSize, spacing).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,8 +233,8 @@ inline fun getGlyphIndex(font: Font, codepoint: Int) : Int {
|
|||
* @return [GlyphInfo]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getGlyphInfo(font: Font, codepoint: Int) : GlyphInfo {
|
||||
return GetGlyphInfo(font.readValue(), codepoint).getPointer(MemScope()).pointed
|
||||
inline fun getGlyphInfo(font: Font, codepoint: Int, allocator: AutofreeScope) : GlyphInfo {
|
||||
return GetGlyphInfo(font.readValue(), codepoint).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,8 +242,8 @@ inline fun getGlyphInfo(font: Font, codepoint: Int) : GlyphInfo {
|
|||
* @return [Rectangle]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getGlyphAtlasRec(font: Font, codepoint: Int) : Rectangle {
|
||||
return GetGlyphAtlasRec(font.readValue(), codepoint).getPointer(MemScope()).pointed
|
||||
inline fun getGlyphAtlasRec(font: Font, codepoint: Int, allocator: AutofreeScope) : Rectangle {
|
||||
return GetGlyphAtlasRec(font.readValue(), codepoint).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,8 +14,8 @@ import kotlinx.cinterop.*
|
|||
* @return [Texture2D]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadTexture(fileName: String) : Texture2D {
|
||||
return LoadTexture(fileName).getPointer(MemScope()).pointed
|
||||
inline fun loadTexture(fileName: String, allocator: AutofreeScope) : Texture2D {
|
||||
return LoadTexture(fileName).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,8 +23,8 @@ inline fun loadTexture(fileName: String) : Texture2D {
|
|||
* @return [Texture2D]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadTextureFromImage(image: Image) : Texture2D {
|
||||
return LoadTextureFromImage(image.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun loadTextureFromImage(image: Image, allocator: AutofreeScope) : Texture2D {
|
||||
return LoadTextureFromImage(image.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,8 +32,8 @@ inline fun loadTextureFromImage(image: Image) : Texture2D {
|
|||
* @return [TextureCubemap]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadTextureCubemap(image: Image, layout: CubemapLayout) : TextureCubemap {
|
||||
return LoadTextureCubemap(image.readValue(), layout.toInt()).getPointer(MemScope()).pointed
|
||||
inline fun loadTextureCubemap(image: Image, layout: CubemapLayout, allocator: AutofreeScope) : TextureCubemap {
|
||||
return LoadTextureCubemap(image.readValue(), layout.toInt()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,8 +41,8 @@ inline fun loadTextureCubemap(image: Image, layout: CubemapLayout) : TextureCube
|
|||
* @return [RenderTexture2D]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadRenderTexture(width: Int, height: Int) : RenderTexture2D {
|
||||
return LoadRenderTexture(width, height).getPointer(MemScope()).pointed
|
||||
inline fun loadRenderTexture(width: Int, height: Int, allocator: AutofreeScope) : RenderTexture2D {
|
||||
return LoadRenderTexture(width, height).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,8 +162,8 @@ inline fun drawTextureNPatch(texture: Texture2D, nPatchInfo: NPatchInfo, dest: R
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorBrightness(color: Color, factor: Float) : Color {
|
||||
return ColorBrightness(color.readValue(), factor).getPointer(MemScope()).pointed
|
||||
inline fun colorBrightness(color: Color, factor: Float, allocator: AutofreeScope) : Color {
|
||||
return ColorBrightness(color.readValue(), factor).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,8 +171,8 @@ inline fun colorBrightness(color: Color, factor: Float) : Color {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorTint(color: Color, tint: Color) : Color {
|
||||
return ColorTint(color.readValue(), tint.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun colorTint(color: Color, tint: Color, allocator: AutofreeScope) : Color {
|
||||
return ColorTint(color.readValue(), tint.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,8 +181,8 @@ inline fun colorTint(color: Color, tint: Color) : Color {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorContrast(color: Color, contrast: Float) : Color {
|
||||
return ColorContrast(color.readValue(), contrast).getPointer(MemScope()).pointed
|
||||
inline fun colorContrast(color: Color, contrast: Float, allocator: AutofreeScope) : Color {
|
||||
return ColorContrast(color.readValue(), contrast).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,8 +190,8 @@ inline fun colorContrast(color: Color, contrast: Float) : Color {
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImagePerlinNoise(width: Int, height: Int, offsetX: Int, offsetY: Int, scale: Float) : Image {
|
||||
return GenImagePerlinNoise(width, height, offsetX, offsetY, scale).getPointer(MemScope()).pointed
|
||||
inline fun genImagePerlinNoise(width: Int, height: Int, offsetX: Int, offsetY: Int, scale: Float, allocator: AutofreeScope) : Image {
|
||||
return GenImagePerlinNoise(width, height, offsetX, offsetY, scale).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,8 +199,8 @@ inline fun genImagePerlinNoise(width: Int, height: Int, offsetX: Int, offsetY: I
|
|||
* @return [Image]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun genImageText(width: Int, height: Int, text: String) : Image {
|
||||
return GenImageText(width, height, text).getPointer(MemScope()).pointed
|
||||
inline fun genImageText(width: Int, height: Int, text: String, allocator: AutofreeScope) : Image {
|
||||
return GenImageText(width, height, text).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,11 +18,10 @@ import kotlinx.cinterop.*
|
|||
|
||||
/**
|
||||
* Constructor function for [Color].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kColor(r: UByte = 0U, g: UByte = 0U, b: UByte = 0U, a: UByte = 0U, allocator: AutofreeScope = MemScope()) : Color {
|
||||
inline fun kColor(r: UByte = 0U, g: UByte = 0U, b: UByte = 0U, a: UByte = 0U, allocator: AutofreeScope) : Color {
|
||||
return allocator.alloc<Color> {
|
||||
this.r = r
|
||||
this.g = g
|
||||
|
@ -45,11 +44,10 @@ inline fun Color.set(other: Color) {
|
|||
|
||||
/**
|
||||
* Constructor function for [Texture].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Texture]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kTexture(id: UInt, width:Int, height: Int, mipmaps: Int, format: Int, allocator: AutofreeScope = MemScope()) : Texture {
|
||||
inline fun kTexture(id: UInt, width:Int, height: Int, mipmaps: Int, format: Int, allocator: AutofreeScope) : Texture {
|
||||
return allocator.alloc<Texture> {
|
||||
this.id = id
|
||||
this.width = width
|
||||
|
@ -60,12 +58,11 @@ inline fun kTexture(id: UInt, width:Int, height: Int, mipmaps: Int, format: Int,
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructor function for RenderTexture].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* Constructor function for RenderTexture.
|
||||
* @return [RenderTexture]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kRenderTexture(id: UInt, texture: Texture, depth: Texture, allocator: AutofreeScope = MemScope()) : RenderTexture {
|
||||
inline fun kRenderTexture(id: UInt, texture: Texture, depth: Texture, allocator: AutofreeScope) : RenderTexture {
|
||||
return allocator.alloc<RenderTexture> {
|
||||
this.id = id
|
||||
this.texture.set(texture)
|
||||
|
@ -75,11 +72,10 @@ inline fun kRenderTexture(id: UInt, texture: Texture, depth: Texture, allocator:
|
|||
|
||||
/**
|
||||
* Constructor function for [NPatchInfo].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [NPatchInfo]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kNPatchInfo(source: Rectangle, left: Int, top: Int, right: Int, bottom: Int, layout: Int, allocator: AutofreeScope = MemScope()) : NPatchInfo {
|
||||
inline fun kNPatchInfo(source: Rectangle, left: Int, top: Int, right: Int, bottom: Int, layout: Int, allocator: AutofreeScope) : NPatchInfo {
|
||||
return allocator.alloc<NPatchInfo> {
|
||||
this.source.set(source)
|
||||
this.left = left
|
||||
|
@ -92,11 +88,10 @@ inline fun kNPatchInfo(source: Rectangle, left: Int, top: Int, right: Int, botto
|
|||
|
||||
/**
|
||||
* Constructor function for [GlyphInfo].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [GlyphInfo]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kGlyphInfo(value: Int, offsetX: Int, offsetY: Int, advanceX: Int, image: Image, allocator: AutofreeScope = MemScope()) : GlyphInfo {
|
||||
inline fun kGlyphInfo(value: Int, offsetX: Int, offsetY: Int, advanceX: Int, image: Image, allocator: AutofreeScope) : GlyphInfo {
|
||||
return allocator.alloc<GlyphInfo> {
|
||||
this.value = value
|
||||
this.offsetX = offsetX
|
||||
|
@ -109,11 +104,10 @@ inline fun kGlyphInfo(value: Int, offsetX: Int, offsetY: Int, advanceX: Int, ima
|
|||
|
||||
/**
|
||||
* Constructor function for [Font].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Font]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kFont(baseSize: Int, glyphCount: Int, glyphPadding: Int, texture: Texture, recs: Rectangle, glyphs: GlyphInfo, allocator: AutofreeScope = MemScope()) : Font {
|
||||
inline fun kFont(baseSize: Int, glyphCount: Int, glyphPadding: Int, texture: Texture, recs: Rectangle, glyphs: GlyphInfo, allocator: AutofreeScope) : Font {
|
||||
return allocator.alloc<Font> {
|
||||
this.baseSize = baseSize
|
||||
this.glyphCount = glyphCount
|
||||
|
@ -124,44 +118,41 @@ inline fun kFont(baseSize: Int, glyphCount: Int, glyphPadding: Int, texture: Tex
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [Camera3D].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Camera3D]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kCamera3D(position: Vector3 = kVector3(), target: Vector3 = kVector3(), up: Vector3 = kVector3(), fovy: Float = 0F, projection: kaylibkit.kEnums.CameraProjection, allocator: AutofreeScope = MemScope()) : Camera3D {
|
||||
return allocator.alloc<Camera3D> {
|
||||
this.position.set(position)
|
||||
this.target.set(target)
|
||||
this.up.set(up)
|
||||
this.fovy = fovy
|
||||
this.projection = projection.value
|
||||
}
|
||||
}
|
||||
///**
|
||||
// * Constructor function for [Camera3D].
|
||||
// * @return [Camera3D]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun kCamera3D(position: Vector3 = kVector3(), target: Vector3 = kVector3(), up: Vector3 = kVector3(), fovy: Float = 0F, projection: kaylibkit.kEnums.CameraProjection, allocator: AutofreeScope = MemScope()) : Camera3D {
|
||||
// return allocator.alloc<Camera3D> {
|
||||
// this.position.set(position)
|
||||
// this.target.set(target)
|
||||
// this.up.set(up)
|
||||
// this.fovy = fovy
|
||||
// this.projection = projection.value
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* Constructor function for [Camera2D].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Camera2D]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kCamera2D(offset: Vector2 = kVector2(), target: Vector2 = kVector2(), rotation: Float = 0F, zoom: Float = 0F, allocator: AutofreeScope = MemScope()) : Camera2D {
|
||||
return allocator.alloc<Camera2D> {
|
||||
this.offset.set(offset)
|
||||
this.target.set(target)
|
||||
this.rotation = rotation
|
||||
this.zoom = zoom
|
||||
}
|
||||
}
|
||||
///**
|
||||
// * Constructor function for [Camera2D].
|
||||
// * @return [Camera2D]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun kCamera2D(offset: Vector2 = kVector2(), target: Vector2 = kVector2(), rotation: Float = 0F, zoom: Float = 0F, allocator: AutofreeScope = MemScope()) : Camera2D {
|
||||
// return allocator.alloc<Camera2D> {
|
||||
// this.offset.set(offset)
|
||||
// this.target.set(target)
|
||||
// this.rotation = rotation
|
||||
// this.zoom = zoom
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* Constructor function for [Mesh].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Mesh]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kMesh(vertexCount: Int, triangleCount: Int, vertices: FloatVar, texcoords: FloatVar, texcoords2: FloatVar, normals: FloatVar, tangents: FloatVar, colors: UByteVar, indices: UShortVar, animVertices: FloatVar, animNormals: FloatVar, boneIds: UByteVar, boneWeights: FloatVar, vaoId: UInt, vboId: UIntVar , allocator: AutofreeScope = MemScope()) : Mesh {
|
||||
inline fun kMesh(vertexCount: Int, triangleCount: Int, vertices: FloatVar, texcoords: FloatVar, texcoords2: FloatVar, normals: FloatVar, tangents: FloatVar, colors: UByteVar, indices: UShortVar, animVertices: FloatVar, animNormals: FloatVar, boneIds: UByteVar, boneWeights: FloatVar, vaoId: UInt, vboId: UIntVar , allocator: AutofreeScope) : Mesh {
|
||||
return allocator.alloc<Mesh> {
|
||||
this.vertexCount = vertexCount
|
||||
this.triangleCount = triangleCount
|
||||
|
@ -207,7 +198,6 @@ inline fun Mesh.set(other: Mesh) {
|
|||
|
||||
/**
|
||||
* Constructor function for [Shader].
|
||||
* Important to note that this uses `MemScope(`) by default.
|
||||
* @return [Shader]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
|
@ -231,11 +221,10 @@ inline fun Shader.set(other: Shader) {
|
|||
|
||||
/**
|
||||
* Constructor function for [MaterialMap].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [MaterialMap]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kMaterialMap(texture: Texture2D, color: Color, value: Float, allocator: AutofreeScope = MemScope()) : MaterialMap {
|
||||
inline fun kMaterialMap(texture: Texture2D, color: Color, value: Float, allocator: AutofreeScope) : MaterialMap {
|
||||
return allocator.alloc<MaterialMap> {
|
||||
this.texture.set(texture)
|
||||
this.color.set(color)
|
||||
|
@ -245,21 +234,19 @@ inline fun kMaterialMap(texture: Texture2D, color: Color, value: Float, allocato
|
|||
|
||||
/**
|
||||
* Constructor function for [Material].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Material]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kMaterial(shader: Shader, maps: MaterialMap, params: CArrayPointer<FloatVar>, allocator: AutofreeScope = MemScope()) : Material {
|
||||
inline fun kMaterial(shader: Shader, maps: MaterialMap, params: CArrayPointer<FloatVar>, allocator: AutofreeScope) : Material {
|
||||
return MaterialConstructor(shader.readValue(), maps.ptr, params).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [Transform].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Transform]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kTransform(translation: Vector3, rotation: Quaternion, scale: Vector3, allocator: AutofreeScope = MemScope()) : Transform {
|
||||
inline fun kTransform(translation: Vector3, rotation: Quaternion, scale: Vector3, allocator: AutofreeScope) : Transform {
|
||||
return allocator.alloc<Transform> {
|
||||
this.translation.set(translation)
|
||||
this.rotation.set(rotation)
|
||||
|
@ -269,21 +256,19 @@ inline fun kTransform(translation: Vector3, rotation: Quaternion, scale: Vector3
|
|||
|
||||
/**
|
||||
* Constructor function for [BoneInfo].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [BoneInfo]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kBoneInfo(name: CArrayPointer<ByteVar>, parent: Int, allocator: AutofreeScope = MemScope()) : BoneInfo {
|
||||
inline fun kBoneInfo(name: CArrayPointer<ByteVar>, parent: Int, allocator: AutofreeScope) : BoneInfo {
|
||||
return BoneInfoConstructor(name, parent).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [Model].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Model]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kModel(transform: Matrix, meshCount: Int, materialCount: Int, meshes: Mesh, materials: Material, meshMaterial: IntVar, boneCount: Int, bones: BoneInfo, bindPose: Transform, allocator: AutofreeScope = MemScope()) : Model {
|
||||
inline fun kModel(transform: Matrix, meshCount: Int, materialCount: Int, meshes: Mesh, materials: Material, meshMaterial: IntVar, boneCount: Int, bones: BoneInfo, bindPose: Transform, allocator: AutofreeScope) : Model {
|
||||
return allocator.alloc<Model> {
|
||||
this.transform.set(transform)
|
||||
this.meshCount = meshCount
|
||||
|
@ -299,7 +284,6 @@ inline fun kModel(transform: Matrix, meshCount: Int, materialCount: Int, meshes:
|
|||
|
||||
/**
|
||||
* Constructor function for [ModelAnimation].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [ModelAnimation]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
|
@ -312,54 +296,52 @@ inline fun kModelAnimation(boneCount: Int, frameCount: Int, bones: BoneInfo, fra
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [Ray].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Ray]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kRay(position: Vector3 = kVector3(), direction: Vector3 = kVector3(), allocator: AutofreeScope = MemScope()) : Ray {
|
||||
return allocator.alloc<Ray> {
|
||||
this.position.set(position)
|
||||
this.direction.set(direction)
|
||||
}
|
||||
}
|
||||
///**
|
||||
// * Constructor function for [Ray].
|
||||
// * @return [Ray]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun kRay(position: Vector3 = kVector3(), direction: Vector3 = kVector3(), allocator: AutofreeScope = MemScope()) : Ray {
|
||||
// return allocator.alloc<Ray> {
|
||||
// this.position.set(position)
|
||||
// this.direction.set(direction)
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* Constructor function for [RayCollision].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [RayCollision]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kRayCollision(hit: Boolean = false, distance: Float = 0F, point: Vector3 = kVector3(), normal: Vector3 = kVector3(), allocator: AutofreeScope = MemScope()) : RayCollision {
|
||||
return allocator.alloc<RayCollision> {
|
||||
this.hit = hit
|
||||
this.distance = distance
|
||||
this.point.set(point)
|
||||
this.normal.set(normal)
|
||||
}
|
||||
}
|
||||
///**
|
||||
// * Constructor function for [RayCollision].
|
||||
// * Important to note that this uses `MemScope()` by default.
|
||||
// * @return [RayCollision]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun kRayCollision(hit: Boolean = false, distance: Float = 0F, point: Vector3 = kVector3(), normal: Vector3 = kVector3(), allocator: AutofreeScope = MemScope()) : RayCollision {
|
||||
// return allocator.alloc<RayCollision> {
|
||||
// this.hit = hit
|
||||
// this.distance = distance
|
||||
// this.point.set(point)
|
||||
// this.normal.set(normal)
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* Constructor function for [BoundingBox].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [BoundingBox]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kBoundingBox(min: Vector3 = kVector3(), max: Vector3 = kVector3(), allocator: AutofreeScope = MemScope()) : BoundingBox {
|
||||
return allocator.alloc<BoundingBox> {
|
||||
this.min.set(min)
|
||||
this.max.set(max)
|
||||
}
|
||||
}
|
||||
///**
|
||||
// * Constructor function for [BoundingBox].
|
||||
// * Important to note that this uses `MemScope()` by default.
|
||||
// * @return [BoundingBox]
|
||||
// */
|
||||
//@OptIn(ExperimentalForeignApi::class)
|
||||
//inline fun kBoundingBox(min: Vector3 = kVector3(), max: Vector3 = kVector3(), allocator: AutofreeScope = MemScope()) : BoundingBox {
|
||||
// return allocator.alloc<BoundingBox> {
|
||||
// this.min.set(min)
|
||||
// this.max.set(max)
|
||||
// }
|
||||
//}
|
||||
|
||||
/**
|
||||
* Constructor function for [Wave].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Wave]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kWave(frameCount: UInt, sampleRate: UInt, sampleSize: UInt, channels: UInt, data: COpaquePointer?, allocator: AutofreeScope = MemScope()) : Wave {
|
||||
inline fun kWave(frameCount: UInt, sampleRate: UInt, sampleSize: UInt, channels: UInt, data: COpaquePointer?, allocator: AutofreeScope) : Wave {
|
||||
return allocator.alloc<Wave> {
|
||||
this.frameCount = frameCount
|
||||
this.sampleRate = sampleRate
|
||||
|
@ -371,11 +353,10 @@ inline fun kWave(frameCount: UInt, sampleRate: UInt, sampleSize: UInt, channels:
|
|||
|
||||
/**
|
||||
* Constructor function for [AudioStream].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [AudioStream]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kAudioStream(buffer: rAudioBuffer, processor: rAudioProcessor, sampleRate: UInt, sampleSize: UInt, channels: UInt, allocator: AutofreeScope = MemScope()) : AudioStream {
|
||||
inline fun kAudioStream(buffer: rAudioBuffer, processor: rAudioProcessor, sampleRate: UInt, sampleSize: UInt, channels: UInt, allocator: AutofreeScope) : AudioStream {
|
||||
return allocator.alloc<AudioStream> {
|
||||
this.buffer = buffer.ptr
|
||||
this.processor = processor.ptr
|
||||
|
@ -387,51 +368,46 @@ inline fun kAudioStream(buffer: rAudioBuffer, processor: rAudioProcessor, sample
|
|||
|
||||
/**
|
||||
* Constructor function for [Sound].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Sound]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kSound(stream: AudioStream, frameCount: UInt, allocator: AutofreeScope = MemScope()) : Sound {
|
||||
inline fun kSound(stream: AudioStream, frameCount: UInt, allocator: AutofreeScope) : Sound {
|
||||
return SoundConstructor(stream.readValue(), frameCount).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [Music].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [Music]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kMusic(stream: AudioStream, frameCount: UInt, looping: Boolean, ctxType: Int, data: COpaquePointer?, allocator: AutofreeScope = MemScope()) : Music {
|
||||
inline fun kMusic(stream: AudioStream, frameCount: UInt, looping: Boolean, ctxType: Int, data: COpaquePointer?, allocator: AutofreeScope) : Music {
|
||||
return MusicConstructor(stream.readValue(), frameCount, looping, ctxType, data).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [VrDeviceInfo].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [VrDeviceInfo]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kVrDeviceInfo(hResolution: Int, vResolution: Int, hScreenSize: Float, vScreenSize: Float, vScreenCenter: Float, eyeToScreenDistance: Float, lensSeparationDistance: Float, interpupillaryDistance: Float, lensDistortionValues: CArrayPointer<FloatVar>, chromaAbCorrection: CArrayPointer<FloatVar>, allocator: AutofreeScope = MemScope()) : VrDeviceInfo {
|
||||
inline fun kVrDeviceInfo(hResolution: Int, vResolution: Int, hScreenSize: Float, vScreenSize: Float, vScreenCenter: Float, eyeToScreenDistance: Float, lensSeparationDistance: Float, interpupillaryDistance: Float, lensDistortionValues: CArrayPointer<FloatVar>, chromaAbCorrection: CArrayPointer<FloatVar>, allocator: AutofreeScope) : VrDeviceInfo {
|
||||
return VrDeviceInfoConstructor(hResolution, vResolution, hScreenSize, vScreenSize, vScreenCenter, eyeToScreenDistance, lensSeparationDistance, interpupillaryDistance, lensDistortionValues, chromaAbCorrection).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [VrStereoConfig].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [VrStereoConfig]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kVrStereoConfig(projection: CArrayPointer<Matrix>, viewOffset: CArrayPointer<Matrix>, leftLensCenter: CArrayPointer<FloatVar>, rightLensCenter: CArrayPointer<FloatVar>, leftScreenCenter: CArrayPointer<FloatVar>, rightScreenCenter: CArrayPointer<FloatVar>, scale: CArrayPointer<FloatVar>, scaleIn: CArrayPointer<FloatVar>, allocator: AutofreeScope = MemScope()) : VrStereoConfig {
|
||||
inline fun kVrStereoConfig(projection: CArrayPointer<Matrix>, viewOffset: CArrayPointer<Matrix>, leftLensCenter: CArrayPointer<FloatVar>, rightLensCenter: CArrayPointer<FloatVar>, leftScreenCenter: CArrayPointer<FloatVar>, rightScreenCenter: CArrayPointer<FloatVar>, scale: CArrayPointer<FloatVar>, scaleIn: CArrayPointer<FloatVar>, allocator: AutofreeScope ) : VrStereoConfig {
|
||||
return VrStereoConfigConstructor(projection, viewOffset, leftLensCenter, rightLensCenter, leftScreenCenter, rightScreenCenter, scale, scaleIn).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor function for [FilePathList].
|
||||
* Important to note that this uses `MemScope()` by default.
|
||||
* @return [FilePathList]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun kFilePathList(capacity: UInt, count: UInt, paths: CPointer<CPointerVar<ByteVar>>, allocator: AutofreeScope = MemScope()) : FilePathList {
|
||||
inline fun kFilePathList(capacity: UInt, count: UInt, paths: CPointer<CPointerVar<ByteVar>>, allocator: AutofreeScope) : FilePathList {
|
||||
return allocator.alloc<FilePathList> {
|
||||
this.capacity = capacity
|
||||
this.count = count
|
||||
|
|
|
@ -16,8 +16,8 @@ import kotlinx.cinterop.*
|
|||
* @return [ByteVar]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun loadUTF8(codepoints: IntVar, length: Int): ByteVar? {
|
||||
return LoadUTF8(codepoints.ptr, length)?.getPointer(MemScope())?.pointed
|
||||
inline fun loadUTF8(codepoints: IntVar, length: Int, allocator: AutofreeScope): ByteVar? {
|
||||
return LoadUTF8(codepoints.ptr, length)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,8 +67,8 @@ inline fun getCodepointPrevious(text: String, codepointSize: IntVar) : Int {
|
|||
* Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun codepointToUTF8(codepoint: Int, utf8Size: IntVar) : ByteVar? {
|
||||
return CodepointToUTF8(codepoint, utf8Size.ptr)?.getPointer(MemScope())?.pointed
|
||||
inline fun codepointToUTF8(codepoint: Int, utf8Size: IntVar, allocator: AutofreeScope) : ByteVar? {
|
||||
return CodepointToUTF8(codepoint, utf8Size.ptr)?.getPointer(allocator)?.pointed
|
||||
}
|
||||
|
||||
//=======================================================//
|
||||
|
@ -80,8 +80,8 @@ inline fun codepointToUTF8(codepoint: Int, utf8Size: IntVar) : ByteVar? {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun fade(color: Color, alpha: Float) : Color {
|
||||
return Fade(color.readValue(), alpha).getPointer(MemScope()).pointed
|
||||
inline fun fade(color: Color, alpha: Float, allocator: AutofreeScope) : Color {
|
||||
return Fade(color.readValue(), alpha).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,8 +98,8 @@ inline fun colorToInt(color: Color) : Int {
|
|||
* @return [Vector4]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorNormalize(color: Color) : Vector4 {
|
||||
return ColorNormalize(color.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun colorNormalize(color: Color, allocator: AutofreeScope) : Vector4 {
|
||||
return ColorNormalize(color.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,8 +107,8 @@ inline fun colorNormalize(color: Color) : Vector4 {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorFromNormalized(normalized: Vector4) : Color {
|
||||
return ColorFromNormalized(normalized.readValue()) .getPointer(MemScope()).pointed
|
||||
inline fun colorFromNormalized(normalized: Vector4, allocator: AutofreeScope) : Color {
|
||||
return ColorFromNormalized(normalized.readValue()) .getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,8 +116,8 @@ inline fun colorFromNormalized(normalized: Vector4) : Color {
|
|||
* @return [Vector3]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorToHSV(color: Color) : Vector3 {
|
||||
return ColorToHSV(color.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun colorToHSV(color: Color, allocator: AutofreeScope) : Vector3 {
|
||||
return ColorToHSV(color.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,8 +125,8 @@ inline fun colorToHSV(color: Color) : Vector3 {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorFromHSV(hue: Float, saturation: Float, value: Float) : Color {
|
||||
return ColorFromHSV(hue, saturation, value).getPointer(MemScope()).pointed
|
||||
inline fun colorFromHSV(hue: Float, saturation: Float, value: Float, allocator: AutofreeScope) : Color {
|
||||
return ColorFromHSV(hue, saturation, value).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,8 +134,8 @@ inline fun colorFromHSV(hue: Float, saturation: Float, value: Float) : Color {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorAlpha(color: Color, alpha: Float) : Color {
|
||||
return ColorAlpha(color.readValue(), alpha).getPointer(MemScope()).pointed
|
||||
inline fun colorAlpha(color: Color, alpha: Float, allocator: AutofreeScope) : Color {
|
||||
return ColorAlpha(color.readValue(), alpha).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,8 +143,8 @@ inline fun colorAlpha(color: Color, alpha: Float) : Color {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun colorAlphaBlend(dst: Color, src: Color, tint: Color) : Color {
|
||||
return ColorAlphaBlend(dst.readValue(), src.readValue(), tint.readValue()).getPointer(MemScope()).pointed
|
||||
inline fun colorAlphaBlend(dst: Color, src: Color, tint: Color, allocator: AutofreeScope) : Color {
|
||||
return ColorAlphaBlend(dst.readValue(), src.readValue(), tint.readValue()).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,8 +152,8 @@ inline fun colorAlphaBlend(dst: Color, src: Color, tint: Color) : Color {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getColor(hexValue: UInt) : Color {
|
||||
return GetColor(hexValue).getPointer(MemScope()).pointed
|
||||
inline fun getColor(hexValue: UInt, allocator: AutofreeScope) : Color {
|
||||
return GetColor(hexValue).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,8 +161,8 @@ inline fun getColor(hexValue: UInt) : Color {
|
|||
* @return [Color]
|
||||
*/
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
inline fun getPixelColor(srcPtr: COpaquePointer, format: kaylibkit.kEnums.PixelFormat) : Color {
|
||||
return GetPixelColor(srcPtr, format.value).getPointer(MemScope()).pointed
|
||||
inline fun getPixelColor(srcPtr: COpaquePointer, format: kaylibkit.kEnums.PixelFormat, allocator: AutofreeScope) : Color {
|
||||
return GetPixelColor(srcPtr, format.value).getPointer(allocator).pointed
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
headers = raylib.h raymath.h rcamera.h
|
||||
package = kaylibc
|
||||
staticLibraries = libraylib.a
|
||||
libraryPaths.osx = src/nativeInterop/cinterop/lib/osx/
|
||||
libraryPaths.linux = src/nativeInterop/cinterop/lib/linux/
|
||||
libraryPaths.mingw = src/nativeInterop/cinterop/lib/mingw/
|
||||
libraryPaths.osx = src/nativeInterop/cinterop/lib/osx
|
||||
libraryPaths.linux = src/nativeInterop/cinterop/lib/linux
|
||||
libraryPaths.mingw = src/nativeInterop/cinterop/lib/mingw
|
||||
|
||||
compilerOpts = -Isrc/nativeInterop/cinterop/include/
|
||||
compilerOpts = -Isrc/nativeInterop/cinterop/include
|
||||
linkerOpts.mingw = -lwinmm -lgdi32 -lopengl32 -lkernel32
|
||||
linkerOpts.osx = -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL
|
||||
|
||||
|
|
Loading…
Reference in a new issue