math docs
This commit is contained in:
parent
674b479ad8
commit
9d7c573a1a
2 changed files with 20 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#import,file "./module.jai"(true);
|
#import,file "./module.jai"(true);
|
||||||
#import,file "./encoding/module.jai"(true);
|
#import,file "./encoding/module.jai"(true);
|
||||||
#import,file "./hash/module.jai"(true);
|
#import,file "./hash/module.jai"(true);
|
||||||
|
|
||||||
rmath :: #import,file "./math/module.jai"(.radians, true);
|
rmath :: #import,file "./math/module.jai"(.radians, true);
|
||||||
dmath :: #import,file "./math/module.jai"(.degrees, true);
|
dmath :: #import,file "./math/module.jai"(.degrees, true);
|
||||||
tmath :: #import,file "./math/module.jai"(.turns, true);
|
tmath :: #import,file "./math/module.jai"(.turns, true);
|
||||||
|
|
|
||||||
20
math/vec.jai
20
math/vec.jai
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Vec is a generic set of N named values of type T.
|
Vec is a generic set of N named values of type T (aka. a mathematical vector)
|
||||||
|
|
||||||
The values can be accessed via array index or their common component names:
|
The values can be accessed via array index or their common component names:
|
||||||
|
|
||||||
|
|
@ -14,13 +14,31 @@
|
||||||
Vec3 : Vec(3, float)
|
Vec3 : Vec(3, float)
|
||||||
Vec4 : Vec(4, float)
|
Vec4 : Vec(4, float)
|
||||||
Quat : Vec(4, float)
|
Quat : Vec(4, float)
|
||||||
|
|
||||||
|
Sadly, Vec does *NOT* solve the problem of interfacing with
|
||||||
|
external vector types (including Jai's 'Math' module).
|
||||||
|
|
||||||
|
To fix this, create two helper macros:
|
||||||
|
|
||||||
|
to_jai :: (v: Vec4) -> jmath.Vector4 #expand {
|
||||||
|
return v.(jmath.Vector4,force);
|
||||||
|
}
|
||||||
|
to_jai :: (v: *Vec4) -> *jmath.Vector4 #expand {
|
||||||
|
return v.(*jmath.Vector4);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
Vec :: struct(N: int, T: Type)
|
Vec :: struct(N: int, T: Type)
|
||||||
#modify {
|
#modify {
|
||||||
|
|
||||||
info := T.(*Type_Info);
|
info := T.(*Type_Info);
|
||||||
return info.type == .INTEGER || info.type == .FLOAT, "Vec T must be a numeric type (int or float)";
|
return info.type == .INTEGER || info.type == .FLOAT, "Vec T must be a numeric type (int or float)";
|
||||||
} {
|
} {
|
||||||
|
#assert (N > 0) "Vec N cannot be <= 0";
|
||||||
|
|
||||||
|
// Vecs are backed by an array internally. The #insert block below
|
||||||
|
// generates #place'd unions of named fields or cN fields when N is > 4.
|
||||||
#as components: [N]T;
|
#as components: [N]T;
|
||||||
|
|
||||||
#insert -> string {
|
#insert -> string {
|
||||||
b: basic.String_Builder;
|
b: basic.String_Builder;
|
||||||
basic.append(*b, "#place components;\n");
|
basic.append(*b, "#place components;\n");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue