shithub: tinygl

Download patch

ref: 7ceaaf990116775d287d1683526efa3b2a5c8a08
parent: 55229a0f07a13aeefc6fdda5ddc318307a256fea
author: David <gek@katherine>
date: Sat Mar 6 20:10:32 EST 2021

Automatic commit.

binary files /dev/null b/Raw_Demos/gears differ
--- a/Raw_Demos/include/3dMath.h
+++ b/Raw_Demos/include/3dMath.h
@@ -21,44 +21,7 @@
 typedef struct {CHAD_ALIGN int d[3];} ivec3;
 typedef struct {CHAD_ALIGN f_ d[4];} vec4;
 typedef struct {CHAD_ALIGN f_ d[16];} mat4;
-mat4 swapRowColumnMajor( mat4 in);
-mat4 lookAt( vec3 eye,  vec3 at,  vec3 up);
-vec4 getrow( mat4 a,  uint index);
-vec4 getcol( mat4 a,  uint index);
-mat4 identitymat4();
-mat4 scalemat4( vec4 s);
-int invmat4( mat4 m, mat4* invOut);
-mat4 perspective( f_ fov,  f_ aspect,  f_ near,  f_ far);
-vec3 viewport( uint xdim,  uint ydim,  vec3 input);
-mat4 rotate( vec3 rotation);
-vec3 rotatev3( vec3 in, vec3 axis,  f_ ang);
-mat4 translate( vec3 t);
-f_ clampf( f_ a,  f_ min,  f_ max);
-f_ lengthv3( vec3 a);
-f_ lengthv4( vec4 a);
-vec3 multvec3( vec3 a, vec3 b);
-vec4 multvec4( vec4 a, vec4 b);
 
-vec3 clampvec3( vec3 a,  vec3 min,  vec3 max);
-vec4 clampvec4( vec4 a,  vec4 min,  vec4 max);
-f_ dotv3( vec3 a,  vec3 b);
-f_ dotv4( vec4 a,  vec4 b);
-mat4 multm4( mat4 a,  mat4 b);
-vec4 mat4xvec4( mat4 t,  vec4 v);
-vec3 crossv3( vec3 a,  vec3 b);
-vec3 scalev3( f_ s,  vec3 i);
-
-vec4 scalev4( f_ s,  vec4 i);
-vec3 normalizev3( vec3 a);
-vec4 normalizev4( vec4 a);
-vec3 addv3( vec3 a,  vec3 b);
-vec4 addv4( vec4 a,  vec4 b);
-vec3 subv3( vec3 a,  vec3 b);
-vec4 subv4( vec4 a,  vec4 b);
-vec3 reflect( vec3 in,  vec3 norm);
-vec4 upv3( vec3 in,  f_ w);
-vec3 downv4( vec4 in);
-
 //Collision detection
 //These Algorithms return the penetration vector into
 //the shape in the first argument
@@ -69,14 +32,19 @@
 	vec3 e;
 }aabb;
 typedef aabb colshape; //c.d[3] determines if it's a sphere or box. 0 or less = box, greater than 0 = sphere
-vec4 spherevsphere( vec4 s1,  vec4 s2);
-vec4 boxvbox( aabb b1,  aabb b2);
-vec3 closestpointAABB( aabb b,  vec3 p);
-vec4 spherevaabb( vec4 sph, aabb box);
 
 
-#ifdef CHAD_MATH_IMPL
-mat4 swapRowColumnMajor( mat4 in){
+
+
+static inline vec4 getrow( mat4 a,  uint index){
+	return (vec4){
+		.d[0]=a.d[0*4+index],
+		.d[1]=a.d[1*4+index],
+		.d[2]=a.d[2*4+index],
+		.d[3]=a.d[3*4+index]
+	};
+}
+static inline mat4 swapRowColumnMajor( mat4 in){
 	mat4 result;
 	vec4 t;
 	int i = 0;
@@ -90,75 +58,9 @@
 	memcpy(result.d+i*4, t.d, 4*4);
 	return result;
 }
-mat4 lookAt( vec3 eye,  vec3 at,  vec3 up){
-	mat4 cw = identitymat4();
-	vec3 zaxis = normalizev3(subv3(at,eye));
-	vec3 xaxis = normalizev3(crossv3(zaxis,up));
-	vec3 yaxis = crossv3(xaxis, zaxis);
-	zaxis = scalev3(-1,zaxis);
-	cw.d[0*4+0] = xaxis.d[0];
-	cw.d[1*4+0] = xaxis.d[1];
-	cw.d[2*4+0] = xaxis.d[2];
-	cw.d[3*4+0] = -dotv3(xaxis,eye);
 
-	cw.d[0*4+1] = yaxis.d[0];
-	cw.d[1*4+1] = yaxis.d[1];
-	cw.d[2*4+1] = yaxis.d[2];
-	cw.d[3*4+1] = -dotv3(yaxis,eye);
-
-	cw.d[0*4+2] = zaxis.d[0];
-	cw.d[1*4+2] = zaxis.d[1];
-	cw.d[2*4+2] = zaxis.d[2];
-	cw.d[3*4+2] = -dotv3(zaxis,eye);
-	cw.d[0*4+3] = 0;
-	cw.d[1*4+3] = 0;
-	cw.d[2*4+3] = 0;
-	cw.d[3*4+3] = 1;
-	return cw;
-}
-
-/*
-mat4 lookAt(vec3 eye, vec3 at, vec3 tmp){
-	vec3 forw = normalizev3(subv3(eye,at));
-	
-	vec3 right = crossv3(normalizev3(tmp),forw);
-	vec3 tup = crossv3(forw,right);
-	mat4 cw = identitymat4();
-	cw.d[0*4+0*1] = right.d[0];
-	cw.d[0*4+1*1] = right.d[1];
-	cw.d[0*4+2*1] = right.d[2];
-
-	cw.d[1*4+0*1] = tup.d[0];
-	cw.d[1*4+1*1] = tup.d[1];
-	cw.d[1*4+2*1] = tup.d[2];
-
-	cw.d[2*4+0*1] = forw.d[0];
-	cw.d[2*4+1*1] = forw.d[1];
-	cw.d[2*4+2*1] = forw.d[2];
-	
-	cw.d[3*4+0*1] = eye.d[0];
-	cw.d[3*4+1*1] = eye.d[1];
-	cw.d[3*4+2*1] = eye.d[2];
-	cw.d[3*4+3*1] = 1.0;
-	return cw;
-}
-*/
-vec4 getrow( mat4 a,  uint index){
+static inline vec4 getcol( mat4 a,  uint index){
 	return (vec4){
-		.d[0]=a.d[0*4+index],
-		.d[1]=a.d[1*4+index],
-		.d[2]=a.d[2*4+index],
-		.d[3]=a.d[3*4+index]
-	};
-}
-vec3 rotatev3( vec3 in,  vec3 axis,  f_ ang){
-	vec3 t1 = scalev3(cosf(ang),in);
-	vec3 t2 = scalev3(sinf(ang),crossv3(axis,in));
-	vec3 t3 = scalev3((1-cosf(ang))*dotv3(axis,in),axis);
-	return addv3(t1,addv3(t2,t3));
-}
-vec4 getcol( mat4 a,  uint index){
-	return (vec4){
 		.d[0]=a.d[index*4+0],
 		.d[1]=a.d[index*4+1],
 		.d[2]=a.d[index*4+2],
@@ -165,7 +67,7 @@
 		.d[3]=a.d[index*4+3]
 	};
 }
-mat4 scalemat4( vec4 s){
+static inline mat4 scalemat4( vec4 s){
 	mat4 ret;
 	for(int i = 1; i < 16; i++)
 		ret.d[i]= 0.0;
@@ -175,12 +77,8 @@
 	ret.d[3*4 + 3] = s.d[3]; //w scale
 	return ret;
 }
-mat4 identitymat4(){
-	return scalemat4(
-		(vec4){.d[0]=1.0,.d[1]=1.0,.d[2]=1.0,.d[3]=1.0}
-	);
-}
-int invmat4( mat4 m, mat4* invOut) //returns 1 if successful
+
+static inline int invmat4( mat4 m, mat4* invOut) //returns 1 if successful
 {
     mat4 inv;
     f_ det;
@@ -306,7 +204,7 @@
         invOut->d[i] = inv.d[i] * det;
     return 1;
 }
-mat4 perspective( f_ fov,  f_ aspect,  f_ near,  f_ far){
+static inline mat4 perspective( f_ fov,  f_ aspect,  f_ near,  f_ far){
 	mat4 ret;
 	f_ D2R = 3.14159265358979323 / 180.0;
 	f_ yScale = 1.0/tanf(D2R * fov/2);
@@ -326,7 +224,7 @@
 	*/
 	return ret;
 }
-vec3 viewport( uint xdim,  uint ydim,  vec3 input){
+static inline vec3 viewport( uint xdim,  uint ydim,  vec3 input){
 	input.d[0] += 1;
 	input.d[1] += 1;
 	input.d[0] *= (f_)xdim / 2.0;
@@ -334,7 +232,7 @@
 	input.d[2] = (input.d[2])/2.0;
 	return input;
 }
-mat4 rotate( vec3 rotation){
+static inline mat4 rotate( vec3 rotation){
 	f_ a = rotation.d[0];
 	f_ b = rotation.d[1];
 	f_ c = rotation.d[2];
@@ -358,26 +256,20 @@
 	rm.d[3*4 + 2] = 0;
 	return rm;
 }
-mat4 translate( vec3 t){
-	mat4 tm = identitymat4();
-	tm.d[3*4+0] = t.d[0];
-	tm.d[3*4+1] = t.d[1];
-	tm.d[3*4+2] = t.d[2];
-	return tm;
-}
 
-f_ clampf( f_ a,  f_ min,  f_ max){
+
+static inline f_ clampf( f_ a,  f_ min,  f_ max){
 	if(a<min) return min;
 	if(a>max) return max;
 	return a;
 }
-f_ lengthv3( vec3 a){
+static inline f_ lengthv3( vec3 a){
 	return sqrtf(a.d[0] * a.d[0] + a.d[1] * a.d[1] + a.d[2] * a.d[2]);
 }
-f_ lengthv4( vec4 a){
+static inline f_ lengthv4( vec4 a){
 	return sqrtf(a.d[0] * a.d[0] + a.d[1] * a.d[1] + a.d[2] * a.d[2] + a.d[3] * a.d[3]);
 }
-vec3 multvec3( vec3 a,  vec3 b){
+static inline vec3 multvec3( vec3 a,  vec3 b){
 	return (vec3){
 		.d[0]=a.d[0]*b.d[0],
 		.d[1]=a.d[1]*b.d[1],
@@ -384,7 +276,7 @@
 		.d[2]=a.d[2]*b.d[2]
 	};
 }
-vec4 multvec4( vec4 a,  vec4 b){
+static inline vec4 multvec4( vec4 a,  vec4 b){
 	return (vec4){
 		.d[0]=a.d[0]*b.d[0],
 		.d[1]=a.d[1]*b.d[1],
@@ -392,7 +284,7 @@
 		.d[3]=a.d[3]*b.d[3]
 	};
 }
-vec3 clampvec3( vec3 a,  vec3 min,  vec3 max){
+static inline vec3 clampvec3( vec3 a,  vec3 min,  vec3 max){
 	vec3 ret;
 	ret.d[0] = clampf(a.d[0],min.d[0],max.d[0]);
 	ret.d[1] = clampf(a.d[1],min.d[1],max.d[1]);
@@ -399,7 +291,7 @@
 	ret.d[2] = clampf(a.d[2],min.d[2],max.d[2]);
 	return ret;
 }
-vec4 clampvec4( vec4 a,  vec4 min,  vec4 max){
+static inline vec4 clampvec4( vec4 a,  vec4 min,  vec4 max){
 	vec4 ret;
 	ret.d[0] = clampf(a.d[0],min.d[0],max.d[0]);
 	ret.d[1] = clampf(a.d[1],min.d[1],max.d[1]);
@@ -407,13 +299,13 @@
 	ret.d[3] = clampf(a.d[3],min.d[3],max.d[3]);
 	return ret;
 }
-f_ dotv3( vec3 a,  vec3 b){
+static inline f_ dotv3( vec3 a,  vec3 b){
 	return a.d[0] * b.d[0] + a.d[1] * b.d[1] + a.d[2] * b.d[2]; 
 }
-f_ dotv4( vec4 a,  vec4 b){
+static inline f_ dotv4( vec4 a,  vec4 b){
 	return a.d[0] * b.d[0] + a.d[1] * b.d[1] + a.d[2] * b.d[2] + a.d[3] * b.d[3]; 
 }
-mat4 multm4( mat4 a,  mat4 b){
+static inline mat4 multm4( mat4 a,  mat4 b){
 	mat4 ret;
 	for(int i = 0; i < 4; i++)
 	for(int j = 0; j < 4; j++)
@@ -423,7 +315,7 @@
 		);
 	return ret;
 }
-vec4 mat4xvec4( mat4 t,  vec4 v){
+static inline vec4 mat4xvec4( mat4 t,  vec4 v){
 	uint i = 0;
 	vec4 vr;
 	vr.d[0] = 	t.d[0*4+i] * v.d[0] + 
@@ -447,7 +339,7 @@
 				t.d[3*4+i] * v.d[3];
 	return vr;
 }
-vec3 crossv3( vec3 a,  vec3 b){
+static inline vec3 crossv3( vec3 a,  vec3 b){
 	vec3 retval;
 	retval.d[0] = a.d[1] * b.d[2] - a.d[2] * b.d[1];
 	retval.d[1] = a.d[2] * b.d[0] - a.d[0] * b.d[2];
@@ -454,32 +346,51 @@
 	retval.d[2] = a.d[0] * b.d[1] - a.d[1] * b.d[0];
 	return retval;
 }
-vec3 scalev3( f_ s,  vec3 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s; return i;}
+static inline vec3 scalev3( f_ s,  vec3 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s; return i;}
 
-vec4 scalev4( f_ s,  vec4 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s;i.d[3] *= s; return i;}
-vec3 normalizev3( vec3 a){
+static inline vec4 scalev4( f_ s,  vec4 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s;i.d[3] *= s; return i;}
+
+static inline vec3 normalizev3( vec3 a){
   	if(lengthv3(a)==0) return (vec3){.d[0]=0.0,.d[1]=0.0,.d[2]=1.0};
 	return scalev3(1.0/lengthv3(a), a);
 }
-vec4 normalizev4( vec4 a){
+static inline vec4 normalizev4( vec4 a){
   	if(lengthv4(a)==0) return (vec4){.d[0]=0.0,.d[1]=0.0,.d[2]=1.0,.d[3]=0.0};
 	return scalev4(1.0/lengthv4(a), a);
 }
-vec3 addv3( vec3 aa,  vec3 b){
+static inline vec3 addv3( vec3 aa,  vec3 b){
 	vec3 a = aa;
 	a.d[0] += b.d[0]; a.d[1] += b.d[1]; a.d[2] += b.d[2]; return a;
 }
-vec4 addv4( vec4 aa,  vec4 b){
+static inline vec3 rotatev3( vec3 in,  vec3 axis,  f_ ang){
+	vec3 t1 = scalev3(cosf(ang),in);
+	vec3 t2 = scalev3(sinf(ang),crossv3(axis,in));
+	vec3 t3 = scalev3((1-cosf(ang))*dotv3(axis,in),axis);
+	return addv3(t1,addv3(t2,t3));
+}
+static inline vec4 addv4( vec4 aa,  vec4 b){
 	vec4 a = aa;
 	a.d[0] += b.d[0]; a.d[1] += b.d[1]; a.d[2] += b.d[2]; a.d[3] += b.d[3]; return a;
 }
-vec3 subv3( vec3 a,  vec3 b){
+static inline vec3 subv3( vec3 a,  vec3 b){
 	return addv3(a,scalev3(-1,b));
 }
-vec4 subv4( vec4 a,  vec4 b){
+static inline mat4 identitymat4(){
+	return scalemat4(
+		(vec4){.d[0]=1.0,.d[1]=1.0,.d[2]=1.0,.d[3]=1.0}
+	);
+}
+static inline mat4 translate( vec3 t){
+	mat4 tm = identitymat4();
+	tm.d[3*4+0] = t.d[0];
+	tm.d[3*4+1] = t.d[1];
+	tm.d[3*4+2] = t.d[2];
+	return tm;
+}
+static inline vec4 subv4( vec4 a,  vec4 b){
 	return addv4(a,scalev4(-1,b));
 }
-vec3 reflect( vec3 in,  vec3 norm){
+static inline vec3 reflect( vec3 in,  vec3 norm){
 	return 
 	addv3(in, //I +
 		scalev3(-2.0*dotv3(norm, in), //-2.0 * dotv3(norm,in) * 
@@ -487,7 +398,7 @@
 		)
 	);
 }
-vec4 upv3( vec3 in,  f_ w){
+static inline vec4 upv3( vec3 in,  f_ w){
 	return (vec4){
 		.d[0]=in.d[0],
 		.d[1]=in.d[1],
@@ -495,7 +406,7 @@
 		.d[3]=w
 	};
 }
-vec3 downv4( vec4 in){
+static inline vec3 downv4( vec4 in){
 	return (vec3){
 		.d[0]=in.d[0],
 		.d[1]=in.d[1],
@@ -502,13 +413,39 @@
 		.d[2]=in.d[2]
 	};
 }
+static inline mat4 lookAt( vec3 eye,  vec3 at,  vec3 up){
+	mat4 cw = identitymat4();
+	vec3 zaxis = normalizev3(subv3(at,eye));
+	vec3 xaxis = normalizev3(crossv3(zaxis,up));
+	vec3 yaxis = crossv3(xaxis, zaxis);
+	zaxis = scalev3(-1,zaxis);
+	cw.d[0*4+0] = xaxis.d[0];
+	cw.d[1*4+0] = xaxis.d[1];
+	cw.d[2*4+0] = xaxis.d[2];
+	cw.d[3*4+0] = -dotv3(xaxis,eye);
 
+	cw.d[0*4+1] = yaxis.d[0];
+	cw.d[1*4+1] = yaxis.d[1];
+	cw.d[2*4+1] = yaxis.d[2];
+	cw.d[3*4+1] = -dotv3(yaxis,eye);
+
+	cw.d[0*4+2] = zaxis.d[0];
+	cw.d[1*4+2] = zaxis.d[1];
+	cw.d[2*4+2] = zaxis.d[2];
+	cw.d[3*4+2] = -dotv3(zaxis,eye);
+	cw.d[0*4+3] = 0;
+	cw.d[1*4+3] = 0;
+	cw.d[2*4+3] = 0;
+	cw.d[3*4+3] = 1;
+	return cw;
+}
+
 //Collision detection
 //These Algorithms return the penetration vector into
 //the shape in the first argument
 //With depth of penetration in element 4
 //if depth of penetration is zero or lower then there is no penetration.
-vec4 spherevsphere( vec4 s1,  vec4 s2){ //x,y,z,radius
+static inline vec4 spherevsphere( vec4 s1,  vec4 s2){ //x,y,z,radius
 	vec4 ret;
 	vec3 diff = subv3(
 				downv4(s2),
@@ -528,7 +465,7 @@
 	);
 	return ret;
 }
-vec4 boxvbox( aabb b1,  aabb b2){ //Just points along the minimum separating axis, Nothing fancy.
+static inline vec4 boxvbox( aabb b1,  aabb b2){ //Just points along the minimum separating axis, Nothing fancy.
 	vec4 ret = (vec4){
 		.d[0]=0,
 		.d[1]=0,
@@ -573,12 +510,12 @@
 	}
 	return ret;
 }
-vec3 closestpointAABB( aabb b,  vec3 p){
+static inline vec3 closestpointAABB( aabb b,  vec3 p){
 	vec3 b1min = subv3(downv4(b.c),b.e);
 	vec3 b1max = addv3(downv4(b.c),b.e);
 	return clampvec3(p,b1min,b1max);
 }
-vec4 spherevaabb( vec4 sph,  aabb box){
+static inline vec4 spherevaabb( vec4 sph,  aabb box){
 	vec4 ret;
 	vec3 p = closestpointAABB(box,downv4(sph));
 	vec3 v = subv3(p,downv4(sph));
@@ -611,7 +548,7 @@
 		
 }
 //end of chad math impl
-#endif
+
 //END Math_Library.h~~~~~~~~~~~~~~~~~~~~
 
 #endif
binary files /dev/null b/SDL_Examples/gears differ
binary files /dev/null b/SDL_Examples/helloworld differ
--- a/SDL_Examples/include/3dMath.h
+++ b/SDL_Examples/include/3dMath.h
@@ -21,44 +21,7 @@
 typedef struct {CHAD_ALIGN int d[3];} ivec3;
 typedef struct {CHAD_ALIGN f_ d[4];} vec4;
 typedef struct {CHAD_ALIGN f_ d[16];} mat4;
-mat4 swapRowColumnMajor( mat4 in);
-mat4 lookAt( vec3 eye,  vec3 at,  vec3 up);
-vec4 getrow( mat4 a,  uint index);
-vec4 getcol( mat4 a,  uint index);
-mat4 identitymat4();
-mat4 scalemat4( vec4 s);
-int invmat4( mat4 m, mat4* invOut);
-mat4 perspective( f_ fov,  f_ aspect,  f_ near,  f_ far);
-vec3 viewport( uint xdim,  uint ydim,  vec3 input);
-mat4 rotate( vec3 rotation);
-vec3 rotatev3( vec3 in, vec3 axis,  f_ ang);
-mat4 translate( vec3 t);
-f_ clampf( f_ a,  f_ min,  f_ max);
-f_ lengthv3( vec3 a);
-f_ lengthv4( vec4 a);
-vec3 multvec3( vec3 a, vec3 b);
-vec4 multvec4( vec4 a, vec4 b);
 
-vec3 clampvec3( vec3 a,  vec3 min,  vec3 max);
-vec4 clampvec4( vec4 a,  vec4 min,  vec4 max);
-f_ dotv3( vec3 a,  vec3 b);
-f_ dotv4( vec4 a,  vec4 b);
-mat4 multm4( mat4 a,  mat4 b);
-vec4 mat4xvec4( mat4 t,  vec4 v);
-vec3 crossv3( vec3 a,  vec3 b);
-vec3 scalev3( f_ s,  vec3 i);
-
-vec4 scalev4( f_ s,  vec4 i);
-vec3 normalizev3( vec3 a);
-vec4 normalizev4( vec4 a);
-vec3 addv3( vec3 a,  vec3 b);
-vec4 addv4( vec4 a,  vec4 b);
-vec3 subv3( vec3 a,  vec3 b);
-vec4 subv4( vec4 a,  vec4 b);
-vec3 reflect( vec3 in,  vec3 norm);
-vec4 upv3( vec3 in,  f_ w);
-vec3 downv4( vec4 in);
-
 //Collision detection
 //These Algorithms return the penetration vector into
 //the shape in the first argument
@@ -69,14 +32,19 @@
 	vec3 e;
 }aabb;
 typedef aabb colshape; //c.d[3] determines if it's a sphere or box. 0 or less = box, greater than 0 = sphere
-vec4 spherevsphere( vec4 s1,  vec4 s2);
-vec4 boxvbox( aabb b1,  aabb b2);
-vec3 closestpointAABB( aabb b,  vec3 p);
-vec4 spherevaabb( vec4 sph, aabb box);
 
 
-#ifdef CHAD_MATH_IMPL
-mat4 swapRowColumnMajor( mat4 in){
+
+
+static inline vec4 getrow( mat4 a,  uint index){
+	return (vec4){
+		.d[0]=a.d[0*4+index],
+		.d[1]=a.d[1*4+index],
+		.d[2]=a.d[2*4+index],
+		.d[3]=a.d[3*4+index]
+	};
+}
+static inline mat4 swapRowColumnMajor( mat4 in){
 	mat4 result;
 	vec4 t;
 	int i = 0;
@@ -90,75 +58,9 @@
 	memcpy(result.d+i*4, t.d, 4*4);
 	return result;
 }
-mat4 lookAt( vec3 eye,  vec3 at,  vec3 up){
-	mat4 cw = identitymat4();
-	vec3 zaxis = normalizev3(subv3(at,eye));
-	vec3 xaxis = normalizev3(crossv3(zaxis,up));
-	vec3 yaxis = crossv3(xaxis, zaxis);
-	zaxis = scalev3(-1,zaxis);
-	cw.d[0*4+0] = xaxis.d[0];
-	cw.d[1*4+0] = xaxis.d[1];
-	cw.d[2*4+0] = xaxis.d[2];
-	cw.d[3*4+0] = -dotv3(xaxis,eye);
 
-	cw.d[0*4+1] = yaxis.d[0];
-	cw.d[1*4+1] = yaxis.d[1];
-	cw.d[2*4+1] = yaxis.d[2];
-	cw.d[3*4+1] = -dotv3(yaxis,eye);
-
-	cw.d[0*4+2] = zaxis.d[0];
-	cw.d[1*4+2] = zaxis.d[1];
-	cw.d[2*4+2] = zaxis.d[2];
-	cw.d[3*4+2] = -dotv3(zaxis,eye);
-	cw.d[0*4+3] = 0;
-	cw.d[1*4+3] = 0;
-	cw.d[2*4+3] = 0;
-	cw.d[3*4+3] = 1;
-	return cw;
-}
-
-/*
-mat4 lookAt(vec3 eye, vec3 at, vec3 tmp){
-	vec3 forw = normalizev3(subv3(eye,at));
-	
-	vec3 right = crossv3(normalizev3(tmp),forw);
-	vec3 tup = crossv3(forw,right);
-	mat4 cw = identitymat4();
-	cw.d[0*4+0*1] = right.d[0];
-	cw.d[0*4+1*1] = right.d[1];
-	cw.d[0*4+2*1] = right.d[2];
-
-	cw.d[1*4+0*1] = tup.d[0];
-	cw.d[1*4+1*1] = tup.d[1];
-	cw.d[1*4+2*1] = tup.d[2];
-
-	cw.d[2*4+0*1] = forw.d[0];
-	cw.d[2*4+1*1] = forw.d[1];
-	cw.d[2*4+2*1] = forw.d[2];
-	
-	cw.d[3*4+0*1] = eye.d[0];
-	cw.d[3*4+1*1] = eye.d[1];
-	cw.d[3*4+2*1] = eye.d[2];
-	cw.d[3*4+3*1] = 1.0;
-	return cw;
-}
-*/
-vec4 getrow( mat4 a,  uint index){
+static inline vec4 getcol( mat4 a,  uint index){
 	return (vec4){
-		.d[0]=a.d[0*4+index],
-		.d[1]=a.d[1*4+index],
-		.d[2]=a.d[2*4+index],
-		.d[3]=a.d[3*4+index]
-	};
-}
-vec3 rotatev3( vec3 in,  vec3 axis,  f_ ang){
-	vec3 t1 = scalev3(cosf(ang),in);
-	vec3 t2 = scalev3(sinf(ang),crossv3(axis,in));
-	vec3 t3 = scalev3((1-cosf(ang))*dotv3(axis,in),axis);
-	return addv3(t1,addv3(t2,t3));
-}
-vec4 getcol( mat4 a,  uint index){
-	return (vec4){
 		.d[0]=a.d[index*4+0],
 		.d[1]=a.d[index*4+1],
 		.d[2]=a.d[index*4+2],
@@ -165,7 +67,7 @@
 		.d[3]=a.d[index*4+3]
 	};
 }
-mat4 scalemat4( vec4 s){
+static inline mat4 scalemat4( vec4 s){
 	mat4 ret;
 	for(int i = 1; i < 16; i++)
 		ret.d[i]= 0.0;
@@ -175,12 +77,8 @@
 	ret.d[3*4 + 3] = s.d[3]; //w scale
 	return ret;
 }
-mat4 identitymat4(){
-	return scalemat4(
-		(vec4){.d[0]=1.0,.d[1]=1.0,.d[2]=1.0,.d[3]=1.0}
-	);
-}
-int invmat4( mat4 m, mat4* invOut) //returns 1 if successful
+
+static inline int invmat4( mat4 m, mat4* invOut) //returns 1 if successful
 {
     mat4 inv;
     f_ det;
@@ -306,7 +204,7 @@
         invOut->d[i] = inv.d[i] * det;
     return 1;
 }
-mat4 perspective( f_ fov,  f_ aspect,  f_ near,  f_ far){
+static inline mat4 perspective( f_ fov,  f_ aspect,  f_ near,  f_ far){
 	mat4 ret;
 	f_ D2R = 3.14159265358979323 / 180.0;
 	f_ yScale = 1.0/tanf(D2R * fov/2);
@@ -326,7 +224,7 @@
 	*/
 	return ret;
 }
-vec3 viewport( uint xdim,  uint ydim,  vec3 input){
+static inline vec3 viewport( uint xdim,  uint ydim,  vec3 input){
 	input.d[0] += 1;
 	input.d[1] += 1;
 	input.d[0] *= (f_)xdim / 2.0;
@@ -334,7 +232,7 @@
 	input.d[2] = (input.d[2])/2.0;
 	return input;
 }
-mat4 rotate( vec3 rotation){
+static inline mat4 rotate( vec3 rotation){
 	f_ a = rotation.d[0];
 	f_ b = rotation.d[1];
 	f_ c = rotation.d[2];
@@ -358,26 +256,20 @@
 	rm.d[3*4 + 2] = 0;
 	return rm;
 }
-mat4 translate( vec3 t){
-	mat4 tm = identitymat4();
-	tm.d[3*4+0] = t.d[0];
-	tm.d[3*4+1] = t.d[1];
-	tm.d[3*4+2] = t.d[2];
-	return tm;
-}
 
-f_ clampf( f_ a,  f_ min,  f_ max){
+
+static inline f_ clampf( f_ a,  f_ min,  f_ max){
 	if(a<min) return min;
 	if(a>max) return max;
 	return a;
 }
-f_ lengthv3( vec3 a){
+static inline f_ lengthv3( vec3 a){
 	return sqrtf(a.d[0] * a.d[0] + a.d[1] * a.d[1] + a.d[2] * a.d[2]);
 }
-f_ lengthv4( vec4 a){
+static inline f_ lengthv4( vec4 a){
 	return sqrtf(a.d[0] * a.d[0] + a.d[1] * a.d[1] + a.d[2] * a.d[2] + a.d[3] * a.d[3]);
 }
-vec3 multvec3( vec3 a,  vec3 b){
+static inline vec3 multvec3( vec3 a,  vec3 b){
 	return (vec3){
 		.d[0]=a.d[0]*b.d[0],
 		.d[1]=a.d[1]*b.d[1],
@@ -384,7 +276,7 @@
 		.d[2]=a.d[2]*b.d[2]
 	};
 }
-vec4 multvec4( vec4 a,  vec4 b){
+static inline vec4 multvec4( vec4 a,  vec4 b){
 	return (vec4){
 		.d[0]=a.d[0]*b.d[0],
 		.d[1]=a.d[1]*b.d[1],
@@ -392,7 +284,7 @@
 		.d[3]=a.d[3]*b.d[3]
 	};
 }
-vec3 clampvec3( vec3 a,  vec3 min,  vec3 max){
+static inline vec3 clampvec3( vec3 a,  vec3 min,  vec3 max){
 	vec3 ret;
 	ret.d[0] = clampf(a.d[0],min.d[0],max.d[0]);
 	ret.d[1] = clampf(a.d[1],min.d[1],max.d[1]);
@@ -399,7 +291,7 @@
 	ret.d[2] = clampf(a.d[2],min.d[2],max.d[2]);
 	return ret;
 }
-vec4 clampvec4( vec4 a,  vec4 min,  vec4 max){
+static inline vec4 clampvec4( vec4 a,  vec4 min,  vec4 max){
 	vec4 ret;
 	ret.d[0] = clampf(a.d[0],min.d[0],max.d[0]);
 	ret.d[1] = clampf(a.d[1],min.d[1],max.d[1]);
@@ -407,13 +299,13 @@
 	ret.d[3] = clampf(a.d[3],min.d[3],max.d[3]);
 	return ret;
 }
-f_ dotv3( vec3 a,  vec3 b){
+static inline f_ dotv3( vec3 a,  vec3 b){
 	return a.d[0] * b.d[0] + a.d[1] * b.d[1] + a.d[2] * b.d[2]; 
 }
-f_ dotv4( vec4 a,  vec4 b){
+static inline f_ dotv4( vec4 a,  vec4 b){
 	return a.d[0] * b.d[0] + a.d[1] * b.d[1] + a.d[2] * b.d[2] + a.d[3] * b.d[3]; 
 }
-mat4 multm4( mat4 a,  mat4 b){
+static inline mat4 multm4( mat4 a,  mat4 b){
 	mat4 ret;
 	for(int i = 0; i < 4; i++)
 	for(int j = 0; j < 4; j++)
@@ -423,7 +315,7 @@
 		);
 	return ret;
 }
-vec4 mat4xvec4( mat4 t,  vec4 v){
+static inline vec4 mat4xvec4( mat4 t,  vec4 v){
 	uint i = 0;
 	vec4 vr;
 	vr.d[0] = 	t.d[0*4+i] * v.d[0] + 
@@ -447,7 +339,7 @@
 				t.d[3*4+i] * v.d[3];
 	return vr;
 }
-vec3 crossv3( vec3 a,  vec3 b){
+static inline vec3 crossv3( vec3 a,  vec3 b){
 	vec3 retval;
 	retval.d[0] = a.d[1] * b.d[2] - a.d[2] * b.d[1];
 	retval.d[1] = a.d[2] * b.d[0] - a.d[0] * b.d[2];
@@ -454,32 +346,51 @@
 	retval.d[2] = a.d[0] * b.d[1] - a.d[1] * b.d[0];
 	return retval;
 }
-vec3 scalev3( f_ s,  vec3 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s; return i;}
+static inline vec3 scalev3( f_ s,  vec3 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s; return i;}
 
-vec4 scalev4( f_ s,  vec4 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s;i.d[3] *= s; return i;}
-vec3 normalizev3( vec3 a){
+static inline vec4 scalev4( f_ s,  vec4 i){i.d[0] *= s; i.d[1] *= s; i.d[2] *= s;i.d[3] *= s; return i;}
+
+static inline vec3 normalizev3( vec3 a){
   	if(lengthv3(a)==0) return (vec3){.d[0]=0.0,.d[1]=0.0,.d[2]=1.0};
 	return scalev3(1.0/lengthv3(a), a);
 }
-vec4 normalizev4( vec4 a){
+static inline vec4 normalizev4( vec4 a){
   	if(lengthv4(a)==0) return (vec4){.d[0]=0.0,.d[1]=0.0,.d[2]=1.0,.d[3]=0.0};
 	return scalev4(1.0/lengthv4(a), a);
 }
-vec3 addv3( vec3 aa,  vec3 b){
+static inline vec3 addv3( vec3 aa,  vec3 b){
 	vec3 a = aa;
 	a.d[0] += b.d[0]; a.d[1] += b.d[1]; a.d[2] += b.d[2]; return a;
 }
-vec4 addv4( vec4 aa,  vec4 b){
+static inline vec3 rotatev3( vec3 in,  vec3 axis,  f_ ang){
+	vec3 t1 = scalev3(cosf(ang),in);
+	vec3 t2 = scalev3(sinf(ang),crossv3(axis,in));
+	vec3 t3 = scalev3((1-cosf(ang))*dotv3(axis,in),axis);
+	return addv3(t1,addv3(t2,t3));
+}
+static inline vec4 addv4( vec4 aa,  vec4 b){
 	vec4 a = aa;
 	a.d[0] += b.d[0]; a.d[1] += b.d[1]; a.d[2] += b.d[2]; a.d[3] += b.d[3]; return a;
 }
-vec3 subv3( vec3 a,  vec3 b){
+static inline vec3 subv3( vec3 a,  vec3 b){
 	return addv3(a,scalev3(-1,b));
 }
-vec4 subv4( vec4 a,  vec4 b){
+static inline mat4 identitymat4(){
+	return scalemat4(
+		(vec4){.d[0]=1.0,.d[1]=1.0,.d[2]=1.0,.d[3]=1.0}
+	);
+}
+static inline mat4 translate( vec3 t){
+	mat4 tm = identitymat4();
+	tm.d[3*4+0] = t.d[0];
+	tm.d[3*4+1] = t.d[1];
+	tm.d[3*4+2] = t.d[2];
+	return tm;
+}
+static inline vec4 subv4( vec4 a,  vec4 b){
 	return addv4(a,scalev4(-1,b));
 }
-vec3 reflect( vec3 in,  vec3 norm){
+static inline vec3 reflect( vec3 in,  vec3 norm){
 	return 
 	addv3(in, //I +
 		scalev3(-2.0*dotv3(norm, in), //-2.0 * dotv3(norm,in) * 
@@ -487,7 +398,7 @@
 		)
 	);
 }
-vec4 upv3( vec3 in,  f_ w){
+static inline vec4 upv3( vec3 in,  f_ w){
 	return (vec4){
 		.d[0]=in.d[0],
 		.d[1]=in.d[1],
@@ -495,7 +406,7 @@
 		.d[3]=w
 	};
 }
-vec3 downv4( vec4 in){
+static inline vec3 downv4( vec4 in){
 	return (vec3){
 		.d[0]=in.d[0],
 		.d[1]=in.d[1],
@@ -502,13 +413,39 @@
 		.d[2]=in.d[2]
 	};
 }
+static inline mat4 lookAt( vec3 eye,  vec3 at,  vec3 up){
+	mat4 cw = identitymat4();
+	vec3 zaxis = normalizev3(subv3(at,eye));
+	vec3 xaxis = normalizev3(crossv3(zaxis,up));
+	vec3 yaxis = crossv3(xaxis, zaxis);
+	zaxis = scalev3(-1,zaxis);
+	cw.d[0*4+0] = xaxis.d[0];
+	cw.d[1*4+0] = xaxis.d[1];
+	cw.d[2*4+0] = xaxis.d[2];
+	cw.d[3*4+0] = -dotv3(xaxis,eye);
 
+	cw.d[0*4+1] = yaxis.d[0];
+	cw.d[1*4+1] = yaxis.d[1];
+	cw.d[2*4+1] = yaxis.d[2];
+	cw.d[3*4+1] = -dotv3(yaxis,eye);
+
+	cw.d[0*4+2] = zaxis.d[0];
+	cw.d[1*4+2] = zaxis.d[1];
+	cw.d[2*4+2] = zaxis.d[2];
+	cw.d[3*4+2] = -dotv3(zaxis,eye);
+	cw.d[0*4+3] = 0;
+	cw.d[1*4+3] = 0;
+	cw.d[2*4+3] = 0;
+	cw.d[3*4+3] = 1;
+	return cw;
+}
+
 //Collision detection
 //These Algorithms return the penetration vector into
 //the shape in the first argument
 //With depth of penetration in element 4
 //if depth of penetration is zero or lower then there is no penetration.
-vec4 spherevsphere( vec4 s1,  vec4 s2){ //x,y,z,radius
+static inline vec4 spherevsphere( vec4 s1,  vec4 s2){ //x,y,z,radius
 	vec4 ret;
 	vec3 diff = subv3(
 				downv4(s2),
@@ -528,7 +465,7 @@
 	);
 	return ret;
 }
-vec4 boxvbox( aabb b1,  aabb b2){ //Just points along the minimum separating axis, Nothing fancy.
+static inline vec4 boxvbox( aabb b1,  aabb b2){ //Just points along the minimum separating axis, Nothing fancy.
 	vec4 ret = (vec4){
 		.d[0]=0,
 		.d[1]=0,
@@ -573,12 +510,12 @@
 	}
 	return ret;
 }
-vec3 closestpointAABB( aabb b,  vec3 p){
+static inline vec3 closestpointAABB( aabb b,  vec3 p){
 	vec3 b1min = subv3(downv4(b.c),b.e);
 	vec3 b1max = addv3(downv4(b.c),b.e);
 	return clampvec3(p,b1min,b1max);
 }
-vec4 spherevaabb( vec4 sph,  aabb box){
+static inline vec4 spherevaabb( vec4 sph,  aabb box){
 	vec4 ret;
 	vec3 p = closestpointAABB(box,downv4(sph));
 	vec3 v = subv3(p,downv4(sph));
@@ -611,7 +548,7 @@
 		
 }
 //end of chad math impl
-#endif
+
 //END Math_Library.h~~~~~~~~~~~~~~~~~~~~
 
 #endif
binary files /dev/null b/SDL_Examples/menu differ
binary files /dev/null b/SDL_Examples/model differ
binary files /dev/null b/SDL_Examples/texture differ
binary files /dev/null b/lib/libTinyGL.a differ
binary files /dev/null b/src/accum.o differ
binary files /dev/null b/src/api.o differ
binary files /dev/null b/src/arrays.o differ
binary files /dev/null b/src/clear.o differ
binary files /dev/null b/src/clip.o differ
binary files /dev/null b/src/get.o differ
binary files /dev/null b/src/image_util.o differ
binary files /dev/null b/src/init.o differ
binary files /dev/null b/src/libTinyGL.a differ
binary files /dev/null b/src/light.o differ
binary files /dev/null b/src/list.o differ
binary files /dev/null b/src/matrix.o differ
binary files /dev/null b/src/memory.o differ
binary files /dev/null b/src/misc.o differ
binary files /dev/null b/src/msghandling.o differ
binary files /dev/null b/src/select.o differ
binary files /dev/null b/src/specbuf.o differ
binary files /dev/null b/src/texture.o differ
binary files /dev/null b/src/vertex.o differ
binary files /dev/null b/src/zbuffer.o differ
binary files /dev/null b/src/zline.o differ
binary files /dev/null b/src/zmath.o differ
binary files /dev/null b/src/zraster.o differ
binary files /dev/null b/src/ztext.o differ
binary files /dev/null b/src/ztriangle.o differ