Last active
December 27, 2015 04:48
-
-
Save TIHan/7269099 to your computer and use it in GitHub Desktop.
Sample Inline Math Function Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FSharpSandbox2.Main | |
open System | |
open System.Runtime.InteropServices | |
/// Vector3 | |
#if MATH_RECORD_TYPES | |
[<StructLayout (LayoutKind.Sequential)>] | |
type Vector3 = | |
{ X: single; Y: single; Z: single } | |
static member inline Create (x, y, z) = | |
{ X = x; Y = y; Z = z } | |
#else | |
[<Struct>] | |
[<StructLayout (LayoutKind.Sequential)>] | |
type Vector3 = | |
val X : single | |
val Y : single | |
val Z : single | |
new (x, y, z) = { X = x; Y = y; Z = z } | |
static member inline Create (x, y, z) = | |
Vector3 (x, y, z) | |
#endif | |
/// Vector3 Module | |
[<RequireQualifiedAccess>] | |
[<CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>] | |
module Vector3 = | |
let inline create x y z = | |
Vector3.Create (x, y, z) | |
let inline dotProduct (v1: Vector3) (v2: Vector3) = | |
(v1.X * v2.X) + (v1.Y * v2.Y) + (v1.Z * v2.Z) | |
/// Axis | |
#if MATH_RECORD_TYPES | |
[<StructLayout (LayoutKind.Sequential)>] | |
type Axis = | |
{ X: Vector3; Y: Vector3; Z: Vector3 } | |
static member inline Create (x, y, z) = | |
{ X = x; Y = y; Z = z } | |
#else | |
[<Struct>] | |
[<StructLayout (LayoutKind.Sequential)>] | |
type Axis = | |
val X : Vector3 | |
val Y : Vector3 | |
val Z : Vector3 | |
new (x, y, z) = { X = x; Y = y; Z = z } | |
static member inline Create (x, y, z) = | |
Axis (x, y, z) | |
#endif | |
member inline this.Item | |
with get (i) = | |
match i with | |
| 0 -> this.X | 1 -> this.Y | 2 -> this.Z | |
| _ -> raise <| IndexOutOfRangeException () | |
/// <summary> | |
/// Based on Q3: orientationr_t | |
/// OrientationR | |
/// | |
/// Note: Should this be a record type? It is over 64 bytes, don't know for sure. | |
/// </summary> | |
type OrientationR = | |
{ | |
/// <summary> | |
/// orientation in world | |
/// </summary> | |
Axis : Axis; | |
} | |
/// <summary> | |
/// Based on Q3: R_WorldToLocal | |
/// WorldToLocal | |
/// </summary> | |
let worldToLocal (world: Vector3) (orientation: OrientationR) = | |
Vector3.create | |
(Vector3.dotProduct world orientation.Axis.[0]) | |
(Vector3.dotProduct world orientation.Axis.[1]) | |
(Vector3.dotProduct world orientation.Axis.[2]) | |
[<EntryPoint>] | |
let main args = | |
0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment