goat3d

changeset 64:99715321ad6d

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 17 Apr 2014 08:53:42 +0300
parents dad392c710df cd7efb8757e1
children 046f7df5844d
files libs/anim/Makefile libs/anim/anim.c libs/anim/anim.h libs/anim/config.h libs/anim/dynarr.c libs/anim/dynarr.h libs/anim/track.c libs/anim/track.h libs/vmath/Makefile libs/vmath/basis.cc libs/vmath/basis.h libs/vmath/basis_c.c libs/vmath/geom.c libs/vmath/geom.h libs/vmath/matrix.cc libs/vmath/matrix.h libs/vmath/matrix.inl libs/vmath/matrix_c.c libs/vmath/quat.cc libs/vmath/quat.h libs/vmath/quat.inl libs/vmath/quat_c.c libs/vmath/ray.cc libs/vmath/ray.h libs/vmath/ray.inl libs/vmath/ray_c.c libs/vmath/sphvec.cc libs/vmath/sphvec.h libs/vmath/vector.cc libs/vmath/vector.h libs/vmath/vector.inl libs/vmath/vmath.c libs/vmath/vmath.h libs/vmath/vmath.inl libs/vmath/vmath_config.h libs/vmath/vmath_types.h src/goat3d.cc src/goat3d.h src/goat3d_impl.h src/goat3d_write.cc src/goat3d_writexml.cc src/node.cc
diffstat 61 files changed, 1100 insertions(+), 6640 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Thu Apr 17 08:50:36 2014 +0300
     1.2 +++ b/Makefile	Thu Apr 17 08:53:42 2014 +0300
     1.3 @@ -10,11 +10,9 @@
     1.4  
     1.5  openctm = libs/openctm/libopenctm.a
     1.6  tinyxml2 = libs/tinyxml2/libtinyxml2.a
     1.7 -vmath = libs/vmath/libvmath.a
     1.8 -anim = libs/anim/libanim.a
     1.9  
    1.10 -extinc = -Ilibs/openctm -Ilibs/tinyxml2 -Ilibs/anim
    1.11 -extlibs = $(openctm) $(tinyxml2) $(anim) $(vmath)
    1.12 +extinc = -Ilibs/openctm -Ilibs/tinyxml2
    1.13 +extlibs = $(openctm) $(tinyxml2)
    1.14  
    1.15  name = goat3d
    1.16  so_major = 0
    1.17 @@ -37,7 +35,7 @@
    1.18  CC = clang
    1.19  CXX = clang++
    1.20  CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(pic) $(extinc)
    1.21 -LDFLAGS = $(extlibs) -lpthread
    1.22 +LDFLAGS = $(extlibs) -lvmath -lanim -lpthread
    1.23  
    1.24  .PHONY: all
    1.25  all: $(lib_so) $(lib_a)
    1.26 @@ -56,14 +54,6 @@
    1.27  $(tinyxml2):
    1.28  	$(MAKE) -C libs/tinyxml2
    1.29  
    1.30 -.PHONY: $(vmath)
    1.31 -$(vmath):
    1.32 -	$(MAKE) -C libs/vmath
    1.33 -
    1.34 -.PHONY: $(anim)
    1.35 -$(anim):
    1.36 -	$(MAKE) -C libs/anim
    1.37 -
    1.38  -include $(dep)
    1.39  
    1.40  %.d: %.cc
    1.41 @@ -73,6 +63,11 @@
    1.42  clean:
    1.43  	rm -f $(obj) $(lib_a) $(lib_so)
    1.44  
    1.45 +.PHONY: cleanlibs
    1.46 +cleanlibs:
    1.47 +	$(MAKE) -C libs/openctm clean
    1.48 +	$(MAKE) -C libs/tinyxml2 clean
    1.49 +
    1.50  .PHONY: cleandep
    1.51  cleandep:
    1.52  	rm -f $(dep)
     2.1 --- a/converters/ass2goat/.clang_complete	Thu Apr 17 08:50:36 2014 +0300
     2.2 +++ b/converters/ass2goat/.clang_complete	Thu Apr 17 08:53:42 2014 +0300
     2.3 @@ -1,2 +1,3 @@
     2.4  -I../../src
     2.5  -I/usr/local/include
     2.6 +-I/usr/local/include/assimp
     3.1 --- a/converters/ass2goat/src/main.c	Thu Apr 17 08:50:36 2014 +0300
     3.2 +++ b/converters/ass2goat/src/main.c	Thu Apr 17 08:53:42 2014 +0300
     3.3 @@ -5,28 +5,52 @@
     3.4  #include "assimp/postprocess.h"
     3.5  #include "assimp/scene.h"
     3.6  
     3.7 -int convert(const char *infname, const char *outfname);
     3.8 +enum {
     3.9 +	CONV_SCENE,
    3.10 +	CONV_ANIM
    3.11 +};
    3.12 +
    3.13 +int convert(const char *infname);
    3.14 +int convert_anim(const char *infname);
    3.15  void process_material(struct goat3d_material *mtl, struct aiMaterial *aimtl);
    3.16 +void process_mesh(struct goat3d *goat, struct goat3d_mesh *mesh, struct aiMesh *aimesh);
    3.17  void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode);
    3.18 +int process_anim(struct goat3d *goat, struct aiAnimation *aianim);
    3.19 +static int output_filename(char *buf, int bufsz, const char *fname, const char *suffix);
    3.20 +static long assimp_time(const struct aiAnimation *anim, double aitime);
    3.21  
    3.22  int main(int argc, char **argv)
    3.23  {
    3.24  	int i, num_done = 0;
    3.25 +	int conv_targ = CONV_SCENE;
    3.26  
    3.27  	for(i=1; i<argc; i++) {
    3.28  		if(argv[i][0] == '-') {
    3.29 +			if(argv[i][2] != 0) {
    3.30 +				fprintf(stderr, "invalid option: %s\n", argv[i]);
    3.31 +				return 1;
    3.32 +			}
    3.33 +
    3.34 +			switch(argv[i][1]) {
    3.35 +			case 'a':
    3.36 +				conv_targ = CONV_ANIM;
    3.37 +				break;
    3.38 +
    3.39 +			case 's':
    3.40 +				conv_targ = CONV_SCENE;
    3.41 +				break;
    3.42 +
    3.43 +			default:
    3.44 +				fprintf(stderr, "invalid option: %s\n", argv[i]);
    3.45 +				return 1;
    3.46 +			}
    3.47 +
    3.48  		} else {
    3.49 -			char *lastdot;
    3.50 -			char *outfname = malloc(strlen(argv[i]) + 4);
    3.51 -			strcpy(outfname, argv[i]);
    3.52 -
    3.53 -			if((lastdot = strrchr(outfname, '.'))) {
    3.54 -				*lastdot = 0;
    3.55 +			if(conv_targ == CONV_SCENE) {
    3.56 +				convert(argv[i]);
    3.57 +			} else {
    3.58 +				convert_anim(argv[i]);
    3.59  			}
    3.60 -			strcat(outfname, ".xml");
    3.61 -
    3.62 -			printf("converting %s -> %s\n", argv[i], outfname);
    3.63 -			convert(argv[i], outfname);
    3.64  			num_done++;
    3.65  		}
    3.66  	}
    3.67 @@ -39,7 +63,7 @@
    3.68  	return 0;
    3.69  }
    3.70  
    3.71 -#define PPFLAGS	\
    3.72 +#define SCE_PPFLAGS	\
    3.73  	(aiProcess_Triangulate | \
    3.74  	 aiProcess_GenNormals | \
    3.75  	 aiProcess_JoinIdenticalVertices | \
    3.76 @@ -47,13 +71,23 @@
    3.77  	 aiProcess_LimitBoneWeights | \
    3.78  	 aiProcess_GenUVCoords)
    3.79  
    3.80 -int convert(const char *infname, const char *outfname)
    3.81 +#define ANM_PPFLAGS \
    3.82 +	(aiProcess_LimitBoneWeights)
    3.83 +
    3.84 +int convert(const char *infname)
    3.85  {
    3.86 -	int i;
    3.87 +	int i, bufsz;
    3.88  	const struct aiScene *aiscn;
    3.89  	struct goat3d *goat;
    3.90 +	char *outfname;
    3.91  
    3.92 -	if(!(aiscn = aiImportFile(infname, PPFLAGS))) {
    3.93 +	bufsz = output_filename(0, 0, infname, "goat3d");
    3.94 +	outfname = alloca(bufsz);
    3.95 +	output_filename(outfname, bufsz, infname, "goat3d");
    3.96 +	printf("converting %s -> %s\n", infname, outfname);
    3.97 +
    3.98 +
    3.99 +	if(!(aiscn = aiImportFile(infname, SCE_PPFLAGS))) {
   3.100  		fprintf(stderr, "failed to import %s\n", infname);
   3.101  		return -1;
   3.102  	}
   3.103 @@ -68,6 +102,14 @@
   3.104  		goat3d_add_mtl(goat, mat);
   3.105  	}
   3.106  
   3.107 +	for(i=0; i<(int)aiscn->mNumMeshes; i++) {
   3.108 +		struct aiMesh *aimesh = aiscn->mMeshes[i];
   3.109 +		struct goat3d_mesh *mesh = goat3d_create_mesh();
   3.110 +
   3.111 +		process_mesh(goat, mesh, aimesh);
   3.112 +		goat3d_add_mesh(goat, mesh);
   3.113 +	}
   3.114 +
   3.115  	for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) {
   3.116  		process_node(goat, 0, aiscn->mRootNode->mChildren[i]);
   3.117  	}
   3.118 @@ -78,6 +120,42 @@
   3.119  	return 0;
   3.120  }
   3.121  
   3.122 +int convert_anim(const char *infname)
   3.123 +{
   3.124 +	int i, bufsz;
   3.125 +	const struct aiScene *aiscn;
   3.126 +	struct goat3d *goat;
   3.127 +	char *outfname;
   3.128 +
   3.129 +	bufsz = output_filename(0, 0, infname, "goatanim");
   3.130 +	outfname = alloca(bufsz);
   3.131 +	output_filename(outfname, bufsz, infname, "goatanim");
   3.132 +	printf("converting %s -> %s\n", infname, outfname);
   3.133 +
   3.134 +
   3.135 +	if(!(aiscn = aiImportFile(infname, ANM_PPFLAGS))) {
   3.136 +		fprintf(stderr, "failed to import %s\n", infname);
   3.137 +		return -1;
   3.138 +	}
   3.139 +
   3.140 +	goat = goat3d_create();
   3.141 +
   3.142 +	for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) {
   3.143 +		process_node(goat, 0, aiscn->mRootNode->mChildren[i]);
   3.144 +	}
   3.145 +
   3.146 +	for(i=0; i<aiscn->mNumAnimations; i++) {
   3.147 +		if(process_anim(goat, aiscn->mAnimations[i]) == -1) {
   3.148 +			return -1;
   3.149 +		}
   3.150 +	}
   3.151 +
   3.152 +	goat3d_save_anim(goat, outfname);
   3.153 +	goat3d_free(goat);
   3.154 +	aiReleaseImport(aiscn);
   3.155 +	return 0;
   3.156 +}
   3.157 +
   3.158  void process_material(struct goat3d_material *mtl, struct aiMaterial *aimtl)
   3.159  {
   3.160  	struct aiString aistr;
   3.161 @@ -126,11 +204,60 @@
   3.162  		goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_REFLECTION, aistr.data);
   3.163  	}
   3.164  	if(aiGetMaterialString(aimtl, AI_MATKEY_TEXTURE_OPACITY(0), &aistr) == aiReturn_SUCCESS) {
   3.165 -		// TODO this is semantically inverted... maybe add an alpha attribute?
   3.166 +		/* TODO this is semantically inverted... maybe add an alpha attribute? */
   3.167  		goat3d_set_mtl_attrib_map(mtl, GOAT3D_MAT_ATTR_TRANSMISSION, aistr.data);
   3.168  	}
   3.169  }
   3.170  
   3.171 +void process_mesh(struct goat3d *goat, struct goat3d_mesh *mesh, struct aiMesh *aimesh)
   3.172 +{
   3.173 +	int i, num_verts, num_faces;
   3.174 +	struct goat3d_material *mtl;
   3.175 +
   3.176 +	if(aimesh->mName.length > 0) {
   3.177 +		goat3d_set_mesh_name(mesh, aimesh->mName.data);
   3.178 +	}
   3.179 +
   3.180 +	if((mtl = goat3d_get_mtl(goat, aimesh->mMaterialIndex))) {
   3.181 +		goat3d_set_mesh_mtl(mesh, mtl);
   3.182 +	}
   3.183 +
   3.184 +	num_verts = aimesh->mNumVertices;
   3.185 +	num_faces = aimesh->mNumFaces;
   3.186 +
   3.187 +	for(i=0; i<num_verts; i++) {
   3.188 +		struct aiVector3D *v;
   3.189 +		struct aiColor4D *col;
   3.190 +
   3.191 +		v = aimesh->mVertices + i;
   3.192 +		goat3d_add_mesh_attrib3f(mesh, GOAT3D_MESH_ATTR_VERTEX, v->x, v->y, v->z);
   3.193 +
   3.194 +		if(aimesh->mNormals) {
   3.195 +			v = aimesh->mNormals + i;
   3.196 +			goat3d_add_mesh_attrib3f(mesh, GOAT3D_MESH_ATTR_NORMAL, v->x, v->y, v->z);
   3.197 +		}
   3.198 +		if(aimesh->mTangents) {
   3.199 +			v = aimesh->mTangents + i;
   3.200 +			goat3d_add_mesh_attrib3f(mesh, GOAT3D_MESH_ATTR_TANGENT, v->x, v->y, v->z);
   3.201 +		}
   3.202 +		if(aimesh->mTextureCoords[0]) {
   3.203 +			v = aimesh->mTextureCoords[0] + i;
   3.204 +			goat3d_add_mesh_attrib2f(mesh, GOAT3D_MESH_ATTR_TEXCOORD, v->x, v->y);
   3.205 +		}
   3.206 +		if(aimesh->mColors[0]) {
   3.207 +			col = aimesh->mColors[0] + i;
   3.208 +			goat3d_add_mesh_attrib4f(mesh, GOAT3D_MESH_ATTR_COLOR, col->r, col->g, col->b, col->a);
   3.209 +		}
   3.210 +		/* TODO: add bones */
   3.211 +	}
   3.212 +
   3.213 +	for(i=0; i<num_faces; i++) {
   3.214 +		struct aiFace *face = aimesh->mFaces + i;
   3.215 +
   3.216 +		goat3d_add_mesh_face(mesh, face->mIndices[0], face->mIndices[1], face->mIndices[2]);
   3.217 +	}
   3.218 +}
   3.219 +
   3.220  void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode)
   3.221  {
   3.222  	int i;
   3.223 @@ -145,3 +272,108 @@
   3.224  
   3.225  	goat3d_add_node(goat, node);
   3.226  }
   3.227 +
   3.228 +int process_anim(struct goat3d *goat, struct aiAnimation *aianim)
   3.229 +{
   3.230 +	int i, j, num_nodes, rnodes_count;
   3.231 +	const char *anim_name;
   3.232 +
   3.233 +	if(aianim->mName.length <= 0) {
   3.234 +		anim_name = "unnamed";
   3.235 +	} else {
   3.236 +		anim_name = aianim->mName.data;
   3.237 +	}
   3.238 +
   3.239 +	num_nodes = goat3d_get_node_count(goat);
   3.240 +
   3.241 +	rnodes_count = 0;
   3.242 +	for(i=0; i<num_nodes; i++) {
   3.243 +		int anim_idx;
   3.244 +		struct goat3d_node *n = goat3d_get_node(goat, i);
   3.245 +		/* skip non-root nodes */
   3.246 +		if(goat3d_get_node_parent(n)) {
   3.247 +			break;
   3.248 +		}
   3.249 +
   3.250 +		/* then add another animation to those root nodes */
   3.251 +		anim_idx = goat3d_get_anim_count(n);
   3.252 +		goat3d_add_anim(n);
   3.253 +		goat3d_use_anim(n, anim_idx);
   3.254 +
   3.255 +		goat3d_set_anim_name(n, anim_name);
   3.256 +	}
   3.257 +
   3.258 +	/* for each animation "channel" ... */
   3.259 +	for(i=0; i<(int)aianim->mNumChannels; i++) {
   3.260 +		struct goat3d_node *node;
   3.261 +		struct aiNodeAnim *ainodeanim = aianim->mChannels[i];
   3.262 +
   3.263 +		/* find the node it refers to */
   3.264 +		const char *nodename = ainodeanim->mNodeName.data;
   3.265 +		if(!(node = goat3d_get_node_by_name(goat, nodename))) {
   3.266 +			fprintf(stderr, "failed to process animation for unknown node: %s\n", nodename);
   3.267 +			return -1;
   3.268 +		}
   3.269 +
   3.270 +		/* add all the keys ... */
   3.271 +		for(j=0; j<(int)ainodeanim->mNumPositionKeys; j++) {
   3.272 +			struct aiVectorKey *key = ainodeanim->mPositionKeys + j;
   3.273 +			long tm = assimp_time(aianim, key->mTime);
   3.274 +			goat3d_set_node_position(node, key->mValue.x, key->mValue.y, key->mValue.z, tm);
   3.275 +		}
   3.276 +
   3.277 +		for(j=0; j<(int)ainodeanim->mNumRotationKeys; j++) {
   3.278 +			struct aiQuatKey *key = ainodeanim->mRotationKeys + j;
   3.279 +			long tm = assimp_time(aianim, key->mTime);
   3.280 +			goat3d_set_node_rotation(node, key->mValue.x, key->mValue.y, key->mValue.z, key->mValue.w, tm);
   3.281 +		}
   3.282 +
   3.283 +		for(j=0; j<(int)ainodeanim->mNumScalingKeys; j++) {
   3.284 +			struct aiVectorKey *key = ainodeanim->mScalingKeys + j;
   3.285 +			long tm = assimp_time(aianim, key->mTime);
   3.286 +			goat3d_set_node_scaling(node, key->mValue.x, key->mValue.y, key->mValue.z, tm);
   3.287 +		}
   3.288 +	}
   3.289 +
   3.290 +	return 0;
   3.291 +}
   3.292 +
   3.293 +static int output_filename(char *buf, int bufsz, const char *fname, const char *suffix)
   3.294 +{
   3.295 +	int reqsz, namesz;
   3.296 +	char *tmpfname;
   3.297 +	const char *fname_end, *lastdot;
   3.298 +
   3.299 +	lastdot = strrchr(fname, '.');
   3.300 +
   3.301 +	fname_end = lastdot ? lastdot : fname + strlen(fname);
   3.302 +	namesz = fname_end - fname;
   3.303 +	reqsz = namesz + strlen(suffix) + 2;	/* plus 1 for the dot */
   3.304 +
   3.305 +	if(buf && bufsz) {
   3.306 +		tmpfname = alloca(namesz + 1);
   3.307 +		memcpy(tmpfname, fname, namesz);
   3.308 +		tmpfname[namesz] = 0;
   3.309 +
   3.310 +		if(suffix) {
   3.311 +			snprintf(buf, bufsz, "%s.%s", tmpfname, suffix);
   3.312 +		} else {
   3.313 +			strncpy(buf, tmpfname, bufsz);
   3.314 +		}
   3.315 +		buf[bufsz - 1] = 0;
   3.316 +	}
   3.317 +
   3.318 +	return reqsz;
   3.319 +}
   3.320 +
   3.321 +static long assimp_time(const struct aiAnimation *anim, double aitime)
   3.322 +{
   3.323 +	double sec;
   3.324 +	if(anim->mTicksPerSecond < 1e-6) {
   3.325 +		/* assume time in frames? */
   3.326 +		sec = aitime / 30.0;
   3.327 +	} else {
   3.328 +		sec = aitime / anim->mTicksPerSecond;
   3.329 +	}
   3.330 +	return (long)(sec * 1000.0);
   3.331 +}
     4.1 Binary file exporters/maxgoat/maxgoat.rc has changed
     5.1 --- a/exporters/maxgoat/maxgoat.vcxproj	Thu Apr 17 08:50:36 2014 +0300
     5.2 +++ b/exporters/maxgoat/maxgoat.vcxproj	Thu Apr 17 08:53:42 2014 +0300
     5.3 @@ -100,16 +100,16 @@
     5.4        <Optimization>Disabled</Optimization>
     5.5        <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions);BUILD_MAXPLUGIN</PreprocessorDefinitions>
     5.6        <DisableSpecificWarnings>4996;4244</DisableSpecificWarnings>
     5.7 -      <AdditionalIncludeDirectories>$(SolutionDir)\src</AdditionalIncludeDirectories>
     5.8 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(ProjectDir)</AdditionalIncludeDirectories>
     5.9      </ClCompile>
    5.10      <Link>
    5.11        <SubSystem>Windows</SubSystem>
    5.12        <GenerateDebugInformation>true</GenerateDebugInformation>
    5.13 -      <AdditionalDependencies>goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.14 +      <AdditionalDependencies>libvmath-x64-dbg.lib;libanim-x64.lib;goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.15        <AdditionalLibraryDirectories>$(TargetDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    5.16      </Link>
    5.17      <PostBuildEvent>
    5.18 -      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
    5.19 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(TargetFileName)"</Command>
    5.20      </PostBuildEvent>
    5.21    </ItemDefinitionGroup>
    5.22    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    5.23 @@ -140,22 +140,36 @@
    5.24        <IntrinsicFunctions>true</IntrinsicFunctions>
    5.25        <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    5.26        <DisableSpecificWarnings>4996;4244</DisableSpecificWarnings>
    5.27 -      <AdditionalIncludeDirectories>$(SolutionDir)\src</AdditionalIncludeDirectories>
    5.28 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(ProjectDir)</AdditionalIncludeDirectories>
    5.29      </ClCompile>
    5.30      <Link>
    5.31        <SubSystem>Windows</SubSystem>
    5.32        <GenerateDebugInformation>true</GenerateDebugInformation>
    5.33        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    5.34        <OptimizeReferences>true</OptimizeReferences>
    5.35 -      <AdditionalDependencies>goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.36 +      <AdditionalDependencies>libvmath-x64.lib;libanim-x64.lib;goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.37        <AdditionalLibraryDirectories>$(TargetDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    5.38      </Link>
    5.39      <PostBuildEvent>
    5.40 -      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
    5.41 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(TargetFileName)"</Command>
    5.42      </PostBuildEvent>
    5.43    </ItemDefinitionGroup>
    5.44    <ItemGroup>
    5.45 +    <ClCompile Include="src\logger.cc" />
    5.46      <ClCompile Include="src\maxgoat.cc" />
    5.47 +    <ClCompile Include="src\minwin.cc" />
    5.48 +  </ItemGroup>
    5.49 +  <ItemGroup>
    5.50 +    <ClInclude Include="resource.h" />
    5.51 +    <ClInclude Include="src\logger.h" />
    5.52 +    <ClInclude Include="src\minwin.h" />
    5.53 +  </ItemGroup>
    5.54 +  <ItemGroup>
    5.55 +    <ResourceCompile Include="maxgoat.rc" />
    5.56 +  </ItemGroup>
    5.57 +  <ItemGroup>
    5.58 +    <None Include="msglogo3d.bmp" />
    5.59 +    <None Include="msglogo3d.png" />
    5.60    </ItemGroup>
    5.61    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    5.62    <ImportGroup Label="ExtensionTargets">
     6.1 --- a/exporters/maxgoat/maxgoat.vcxproj.filters	Thu Apr 17 08:50:36 2014 +0300
     6.2 +++ b/exporters/maxgoat/maxgoat.vcxproj.filters	Thu Apr 17 08:53:42 2014 +0300
     6.3 @@ -3,12 +3,36 @@
     6.4    <ItemGroup>
     6.5      <Filter Include="src">
     6.6        <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     6.7 -      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
     6.8 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h</Extensions>
     6.9      </Filter>
    6.10    </ItemGroup>
    6.11    <ItemGroup>
    6.12      <ClCompile Include="src\maxgoat.cc">
    6.13        <Filter>src</Filter>
    6.14      </ClCompile>
    6.15 +    <ClCompile Include="src\minwin.cc">
    6.16 +      <Filter>src</Filter>
    6.17 +    </ClCompile>
    6.18 +    <ClCompile Include="src\logger.cc">
    6.19 +      <Filter>src</Filter>
    6.20 +    </ClCompile>
    6.21 +  </ItemGroup>
    6.22 +  <ItemGroup>
    6.23 +    <ClInclude Include="src\minwin.h">
    6.24 +      <Filter>src</Filter>
    6.25 +    </ClInclude>
    6.26 +    <ClInclude Include="src\logger.h">
    6.27 +      <Filter>src</Filter>
    6.28 +    </ClInclude>
    6.29 +    <ClInclude Include="resource.h">
    6.30 +      <Filter>src</Filter>
    6.31 +    </ClInclude>
    6.32 +  </ItemGroup>
    6.33 +  <ItemGroup>
    6.34 +    <ResourceCompile Include="maxgoat.rc" />
    6.35 +  </ItemGroup>
    6.36 +  <ItemGroup>
    6.37 +    <None Include="msglogo3d.png" />
    6.38 +    <None Include="msglogo3d.bmp" />
    6.39    </ItemGroup>
    6.40  </Project>
    6.41 \ No newline at end of file
     7.1 Binary file exporters/maxgoat/msglogo3d.bmp has changed
     8.1 Binary file exporters/maxgoat/resource.h has changed
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/exporters/maxgoat/src/logger.cc	Thu Apr 17 08:53:42 2014 +0300
     9.3 @@ -0,0 +1,31 @@
     9.4 +#include <stdio.h>
     9.5 +#include <stdarg.h>
     9.6 +#include "logger.h"
     9.7 +
     9.8 +static FILE *logfile;
     9.9 +
    9.10 +bool maxlog_open(const char *fname)
    9.11 +{
    9.12 +	if(!(logfile = fopen(fname, "wb"))) {
    9.13 +		return false;
    9.14 +	}
    9.15 +	setvbuf(logfile, 0, _IONBF, 0);
    9.16 +	return true;
    9.17 +}
    9.18 +
    9.19 +void maxlog_close()
    9.20 +{
    9.21 +	if(logfile) {
    9.22 +		fclose(logfile);
    9.23 +	}
    9.24 +}
    9.25 +
    9.26 +void maxlog(const char *fmt, ...)
    9.27 +{
    9.28 +	if(!logfile) return;
    9.29 +
    9.30 +	va_list ap;
    9.31 +	va_start(ap, fmt);
    9.32 +	vfprintf(logfile, fmt, ap);
    9.33 +	va_end(ap);
    9.34 +}
    9.35 \ No newline at end of file
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/exporters/maxgoat/src/logger.h	Thu Apr 17 08:53:42 2014 +0300
    10.3 @@ -0,0 +1,8 @@
    10.4 +#ifndef MAXLOGGER_H_
    10.5 +#define MAXLOGGER_H_
    10.6 +
    10.7 +bool maxlog_open(const char *fname);
    10.8 +void maxlog_close();
    10.9 +void maxlog(const char *fmt, ...);
   10.10 +
   10.11 +#endif	/* MAXLOGGER_H_ */
   10.12 \ No newline at end of file
    11.1 --- a/exporters/maxgoat/src/maxgoat.cc	Thu Apr 17 08:50:36 2014 +0300
    11.2 +++ b/exporters/maxgoat/src/maxgoat.cc	Thu Apr 17 08:53:42 2014 +0300
    11.3 @@ -13,7 +13,10 @@
    11.4  #include "IGameExport.h"
    11.5  #include "IConversionmanager.h"
    11.6  #include "goat3d.h"
    11.7 +#include "minwin.h"
    11.8  #include "config.h"
    11.9 +#include "logger.h"
   11.10 +#include "resource.h"
   11.11  
   11.12  
   11.13  #pragma comment (lib, "core.lib")
   11.14 @@ -31,8 +34,7 @@
   11.15  #define VERSION(major, minor) \
   11.16  	((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor)))
   11.17  
   11.18 -static FILE *logfile;
   11.19 -static HINSTANCE hinst;
   11.20 +HINSTANCE hinst;
   11.21  
   11.22  class GoatExporter : public SceneExport {
   11.23  private:
   11.24 @@ -115,17 +117,55 @@
   11.25  	MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0);
   11.26  }
   11.27  
   11.28 +static INT_PTR CALLBACK handle_dlg_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
   11.29 +{
   11.30 +	switch(msg) {
   11.31 +	case WM_INITDIALOG:
   11.32 +		CheckDlgButton(win, IDC_GOAT_NODES, 1);
   11.33 +		CheckDlgButton(win, IDC_GOAT_MESHES, 1);
   11.34 +		CheckDlgButton(win, IDC_GOAT_LIGHTS, 1);
   11.35 +		CheckDlgButton(win, IDC_GOAT_CAMERAS, 1);
   11.36 +		break;
   11.37 +
   11.38 +	case WM_COMMAND:
   11.39 +		switch(LOWORD(wparam)) {
   11.40 +		case IDOK:
   11.41 +			EndDialog(win, 1);
   11.42 +			break;
   11.43 +
   11.44 +		case IDCANCEL:
   11.45 +			EndDialog(win, 0);
   11.46 +			break;
   11.47 +
   11.48 +		default:
   11.49 +			return 0;
   11.50 +		}
   11.51 +		break;
   11.52 +
   11.53 +	default:
   11.54 +		return 0;
   11.55 +	}
   11.56 +
   11.57 +	return 1;
   11.58 +}
   11.59 +
   11.60  int GoatExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface,
   11.61  		BOOL non_interactive, DWORD opt)
   11.62  {
   11.63 +	if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_SCE), 0, handle_dlg_events)) {
   11.64 +		maxlog("canceled!\n");
   11.65 +		return IMPEXP_CANCEL;
   11.66 +	}
   11.67 +
   11.68  	mtlmap.clear();
   11.69  	nodemap.clear();
   11.70  
   11.71  	char fname[512];
   11.72  	wcstombs(fname, name, sizeof fname - 1);
   11.73  
   11.74 +	maxlog("Exporting Goat3D Scene (text) file: %s\n", fname);
   11.75  	if(!(igame = GetIGameInterface())) {
   11.76 -		fprintf(logfile, "failed to get the igame interface\n");
   11.77 +		maxlog("failed to get the igame interface\n");
   11.78  		return IMPEXP_FAIL;
   11.79  	}
   11.80  	IGameConversionManager *cm = GetConversionManager();
   11.81 @@ -406,6 +446,7 @@
   11.82  	HINSTANCE HInstance() { return hinst; }
   11.83  };
   11.84  
   11.85 +// TODO: make 2 class descriptors, one for goat3d, one for goat3danim
   11.86  static GoatClassDesc class_desc;
   11.87  
   11.88  BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved)
   11.89 @@ -446,18 +487,13 @@
   11.90  	SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path);
   11.91  	strcat(path, "/testexp.log");
   11.92  
   11.93 -	if((logfile = fopen(path, "w"))) {
   11.94 -		setvbuf(logfile, 0, _IONBF, 0);
   11.95 -	}
   11.96 +	maxlog_open(path);
   11.97  	return TRUE;
   11.98  }
   11.99  
  11.100  __declspec(dllexport) int LibShutdown()
  11.101  {
  11.102 -	if(logfile) {
  11.103 -		fclose(logfile);
  11.104 -		logfile = 0;
  11.105 -	}
  11.106 +	maxlog_close();
  11.107  	return TRUE;
  11.108  }
  11.109  
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/exporters/maxgoat/src/minwin.cc	Thu Apr 17 08:53:42 2014 +0300
    12.3 @@ -0,0 +1,170 @@
    12.4 +#include <string.h>
    12.5 +#include <windows.h>
    12.6 +#include "minwin.h"
    12.7 +#include "logger.h"
    12.8 +
    12.9 +#define GOATSCE_WCLASS	"goatsce-window"
   12.10 +
   12.11 +struct MinWidget {
   12.12 +	HWND win;
   12.13 +
   12.14 +	MWCallback cbfunc;
   12.15 +	void *cbcls;
   12.16 +
   12.17 +	MinWidget() { win = 0; cbfunc = 0; cbcls = 0; }
   12.18 +};
   12.19 +
   12.20 +static void init();
   12.21 +static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name,
   12.22 +		unsigned int style, int x, int y, int xsz, int ysz);
   12.23 +static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
   12.24 +
   12.25 +extern HINSTANCE hinst;	// defined in maxgoat.cc
   12.26 +
   12.27 +void mw_set_callback(MinWidget *w, MWCallback func, void *cls)
   12.28 +{
   12.29 +	w->cbfunc = func;
   12.30 +	w->cbcls = cls;
   12.31 +}
   12.32 +
   12.33 +MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz)
   12.34 +{
   12.35 +	unsigned int style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
   12.36 +	if(parent) {
   12.37 +		style |= WS_CHILD;
   12.38 +	}
   12.39 +
   12.40 +	maxlog("creating window: %s\n", name);
   12.41 +
   12.42 +	MinWidget *w = createwin(parent, GOATSCE_WCLASS, name, style, x, y, xsz, ysz);
   12.43 +	return w;
   12.44 +}
   12.45 +
   12.46 +MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz)
   12.47 +{
   12.48 +	unsigned int style = BS_PUSHBUTTON | WS_VISIBLE;
   12.49 +	if(parent) {
   12.50 +		style |= WS_CHILD;
   12.51 +	}
   12.52 +
   12.53 +	maxlog("creating button: %s\n", text);
   12.54 +
   12.55 +	MinWidget *w = createwin(parent, "BUTTON", text, style, x, y, xsz, ysz);
   12.56 +	return w;
   12.57 +}
   12.58 +
   12.59 +MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked)
   12.60 +{
   12.61 +	unsigned int style = BS_CHECKBOX | WS_VISIBLE;
   12.62 +	if(parent) {
   12.63 +		style |= WS_CHILD;
   12.64 +	}
   12.65 +
   12.66 +	maxlog("creating checkbox: %s\n", text);
   12.67 +
   12.68 +	MinWidget *w = createwin(parent, "CHECKBOX", text, style, x, y, xsz, ysz);
   12.69 +	return w;
   12.70 +}
   12.71 +
   12.72 +static DWORD WINAPI gui_thread_func(void *cls);
   12.73 +
   12.74 +void mw_test()
   12.75 +{
   12.76 +	init();
   12.77 +
   12.78 +	HANDLE thread = CreateThread(0, 0, gui_thread_func, 0, 0, 0);
   12.79 +	//WaitForSingleObject(thread, 5000);
   12.80 +}
   12.81 +
   12.82 +static DWORD WINAPI gui_thread_func(void *cls)
   12.83 +{
   12.84 +	MinWidget *win = mw_create_window(0, "test window!", -1, -1, 400, 400);
   12.85 +	MinWidget *bn_ok = mw_create_button(win, "Ok", 50, 100, 150, 40);
   12.86 +	MinWidget *bn_cancel = mw_create_button(win, "Cancel", 250, 100, 150, 40);
   12.87 +	MinWidget *ck_lights = mw_create_checkbox(win, "Export lights", 20, 20, 250, 40, true);
   12.88 +	MinWidget *ck_cameras = mw_create_checkbox(win, "Export cameras", 20, 60, 250, 40, true);
   12.89 +
   12.90 +	MSG msg;
   12.91 +	while(GetMessage(&msg, win->win, 0, 0)) {
   12.92 +		TranslateMessage(&msg);
   12.93 +		DispatchMessage(&msg);
   12.94 +	}
   12.95 +
   12.96 +	DestroyWindow(win->win);
   12.97 +	delete bn_ok;
   12.98 +	delete bn_cancel;
   12.99 +	delete ck_lights;
  12.100 +	delete ck_cameras;
  12.101 +	delete win;
  12.102 +
  12.103 +	return 0;
  12.104 +}
  12.105 +
  12.106 +static void init()
  12.107 +{
  12.108 +	static bool done_init;
  12.109 +	if(done_init) {
  12.110 +		return;
  12.111 +	}
  12.112 +	done_init = true;
  12.113 +
  12.114 +	size_t sz = mbstowcs(0, GOATSCE_WCLASS, 0);
  12.115 +	wchar_t *cname = new wchar_t[sz + 1];
  12.116 +	mbstowcs(cname, GOATSCE_WCLASS, sz + 1);
  12.117 +
  12.118 +	WNDCLASS wc;
  12.119 +	memset(&wc, 0, sizeof wc);
  12.120 +	wc.lpszClassName = cname;
  12.121 +	wc.hInstance = hinst;
  12.122 +	wc.lpfnWndProc = handle_msg;
  12.123 +	wc.style = CS_HREDRAW | CS_VREDRAW;
  12.124 +	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  12.125 +	wc.hCursor = LoadCursor(0, IDC_ARROW);
  12.126 +
  12.127 +	RegisterClass(&wc);
  12.128 +}
  12.129 +
  12.130 +static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name,
  12.131 +		unsigned int style, int x, int y, int xsz, int ysz)
  12.132 +{
  12.133 +	init();
  12.134 +
  12.135 +	MinWidget *w = new MinWidget;
  12.136 +
  12.137 +	size_t sz = mbstowcs(0, cls, 0);
  12.138 +	wchar_t *wcls = new wchar_t[sz + 1];
  12.139 +	mbstowcs(wcls, cls, sz + 1);
  12.140 +
  12.141 +	sz = mbstowcs(0, name, 0);
  12.142 +	wchar_t *wname = new wchar_t[sz + 1];
  12.143 +	mbstowcs(wname, name, sz + 1);
  12.144 +
  12.145 +	if(x <= 0) x = CW_USEDEFAULT;
  12.146 +	if(y <= 0) y = CW_USEDEFAULT;
  12.147 +
  12.148 +	w->win = CreateWindow(wcls, wname, style, x, y, xsz, ysz, parent ? parent->win : 0, 0, hinst, 0);
  12.149 +
  12.150 +	delete [] wcls;
  12.151 +	delete [] wname;
  12.152 +
  12.153 +	if(!w->win) {
  12.154 +		delete w;
  12.155 +		return 0;
  12.156 +	}
  12.157 +	return w;
  12.158 +}
  12.159 +
  12.160 +
  12.161 +static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
  12.162 +{
  12.163 +	switch(msg) {
  12.164 +	case WM_CLOSE:
  12.165 +		DestroyWindow(win);
  12.166 +		break;
  12.167 +
  12.168 +	default:
  12.169 +		return DefWindowProc(win, msg, wparam, lparam);
  12.170 +	}
  12.171 +
  12.172 +	return 0;
  12.173 +}
  12.174 \ No newline at end of file
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/exporters/maxgoat/src/minwin.h	Thu Apr 17 08:53:42 2014 +0300
    13.3 @@ -0,0 +1,15 @@
    13.4 +#ifndef MINWIN_H_
    13.5 +#define MINWIN_H_
    13.6 +
    13.7 +struct MinWidget;
    13.8 +typedef void (*MWCallback)(MinWidget*, void*);
    13.9 +
   13.10 +void mw_set_callback(MinWidget *w, MWCallback func, void *cls);
   13.11 +
   13.12 +MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz);
   13.13 +MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz);
   13.14 +MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked);
   13.15 +
   13.16 +void mw_test();
   13.17 +
   13.18 +#endif	// MINWIN_H_
   13.19 \ No newline at end of file
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/exporters/maxgoat_stub/maxgoat_stub.vcxproj	Thu Apr 17 08:53:42 2014 +0300
    14.3 @@ -0,0 +1,155 @@
    14.4 +<?xml version="1.0" encoding="utf-8"?>
    14.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    14.6 +  <ItemGroup Label="ProjectConfigurations">
    14.7 +    <ProjectConfiguration Include="Debug|Win32">
    14.8 +      <Configuration>Debug</Configuration>
    14.9 +      <Platform>Win32</Platform>
   14.10 +    </ProjectConfiguration>
   14.11 +    <ProjectConfiguration Include="Debug|x64">
   14.12 +      <Configuration>Debug</Configuration>
   14.13 +      <Platform>x64</Platform>
   14.14 +    </ProjectConfiguration>
   14.15 +    <ProjectConfiguration Include="Release|Win32">
   14.16 +      <Configuration>Release</Configuration>
   14.17 +      <Platform>Win32</Platform>
   14.18 +    </ProjectConfiguration>
   14.19 +    <ProjectConfiguration Include="Release|x64">
   14.20 +      <Configuration>Release</Configuration>
   14.21 +      <Platform>x64</Platform>
   14.22 +    </ProjectConfiguration>
   14.23 +  </ItemGroup>
   14.24 +  <PropertyGroup Label="Globals">
   14.25 +    <ProjectGuid>{941007A1-6375-4507-8745-FC3EA9DF010B}</ProjectGuid>
   14.26 +    <Keyword>Win32Proj</Keyword>
   14.27 +    <RootNamespace>maxgoat_stub</RootNamespace>
   14.28 +  </PropertyGroup>
   14.29 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   14.30 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
   14.31 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
   14.32 +    <UseDebugLibraries>true</UseDebugLibraries>
   14.33 +    <PlatformToolset>v100</PlatformToolset>
   14.34 +    <CharacterSet>Unicode</CharacterSet>
   14.35 +  </PropertyGroup>
   14.36 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
   14.37 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
   14.38 +    <UseDebugLibraries>true</UseDebugLibraries>
   14.39 +    <PlatformToolset>v100</PlatformToolset>
   14.40 +    <CharacterSet>Unicode</CharacterSet>
   14.41 +  </PropertyGroup>
   14.42 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
   14.43 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
   14.44 +    <UseDebugLibraries>false</UseDebugLibraries>
   14.45 +    <PlatformToolset>v100</PlatformToolset>
   14.46 +    <WholeProgramOptimization>true</WholeProgramOptimization>
   14.47 +    <CharacterSet>Unicode</CharacterSet>
   14.48 +  </PropertyGroup>
   14.49 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
   14.50 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
   14.51 +    <UseDebugLibraries>false</UseDebugLibraries>
   14.52 +    <PlatformToolset>v100</PlatformToolset>
   14.53 +    <WholeProgramOptimization>true</WholeProgramOptimization>
   14.54 +    <CharacterSet>Unicode</CharacterSet>
   14.55 +  </PropertyGroup>
   14.56 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   14.57 +  <ImportGroup Label="ExtensionSettings">
   14.58 +  </ImportGroup>
   14.59 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
   14.60 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   14.61 +  </ImportGroup>
   14.62 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
   14.63 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   14.64 +  </ImportGroup>
   14.65 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
   14.66 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   14.67 +  </ImportGroup>
   14.68 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
   14.69 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   14.70 +  </ImportGroup>
   14.71 +  <PropertyGroup Label="UserMacros" />
   14.72 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
   14.73 +    <LinkIncremental>true</LinkIncremental>
   14.74 +  </PropertyGroup>
   14.75 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   14.76 +    <LinkIncremental>false</LinkIncremental>
   14.77 +  </PropertyGroup>
   14.78 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
   14.79 +    <LinkIncremental>false</LinkIncremental>
   14.80 +  </PropertyGroup>
   14.81 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   14.82 +    <LinkIncremental>false</LinkIncremental>
   14.83 +  </PropertyGroup>
   14.84 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
   14.85 +    <ClCompile>
   14.86 +      <PrecompiledHeader>
   14.87 +      </PrecompiledHeader>
   14.88 +      <WarningLevel>Level3</WarningLevel>
   14.89 +      <Optimization>Disabled</Optimization>
   14.90 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   14.91 +    </ClCompile>
   14.92 +    <Link>
   14.93 +      <SubSystem>Windows</SubSystem>
   14.94 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   14.95 +    </Link>
   14.96 +  </ItemDefinitionGroup>
   14.97 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   14.98 +    <ClCompile>
   14.99 +      <PrecompiledHeader>
  14.100 +      </PrecompiledHeader>
  14.101 +      <WarningLevel>Level3</WarningLevel>
  14.102 +      <Optimization>Disabled</Optimization>
  14.103 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  14.104 +      <DisableSpecificWarnings>4996</DisableSpecificWarnings>
  14.105 +    </ClCompile>
  14.106 +    <Link>
  14.107 +      <SubSystem>Windows</SubSystem>
  14.108 +      <GenerateDebugInformation>true</GenerateDebugInformation>
  14.109 +    </Link>
  14.110 +    <PostBuildEvent>
  14.111 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
  14.112 +    </PostBuildEvent>
  14.113 +  </ItemDefinitionGroup>
  14.114 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  14.115 +    <ClCompile>
  14.116 +      <WarningLevel>Level3</WarningLevel>
  14.117 +      <PrecompiledHeader>
  14.118 +      </PrecompiledHeader>
  14.119 +      <Optimization>MaxSpeed</Optimization>
  14.120 +      <FunctionLevelLinking>true</FunctionLevelLinking>
  14.121 +      <IntrinsicFunctions>true</IntrinsicFunctions>
  14.122 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  14.123 +    </ClCompile>
  14.124 +    <Link>
  14.125 +      <SubSystem>Windows</SubSystem>
  14.126 +      <GenerateDebugInformation>true</GenerateDebugInformation>
  14.127 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
  14.128 +      <OptimizeReferences>true</OptimizeReferences>
  14.129 +    </Link>
  14.130 +  </ItemDefinitionGroup>
  14.131 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  14.132 +    <ClCompile>
  14.133 +      <WarningLevel>Level3</WarningLevel>
  14.134 +      <PrecompiledHeader>
  14.135 +      </PrecompiledHeader>
  14.136 +      <Optimization>MaxSpeed</Optimization>
  14.137 +      <FunctionLevelLinking>true</FunctionLevelLinking>
  14.138 +      <IntrinsicFunctions>true</IntrinsicFunctions>
  14.139 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  14.140 +      <DisableSpecificWarnings>4996</DisableSpecificWarnings>
  14.141 +    </ClCompile>
  14.142 +    <Link>
  14.143 +      <SubSystem>Windows</SubSystem>
  14.144 +      <GenerateDebugInformation>true</GenerateDebugInformation>
  14.145 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
  14.146 +      <OptimizeReferences>true</OptimizeReferences>
  14.147 +    </Link>
  14.148 +    <PostBuildEvent>
  14.149 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
  14.150 +    </PostBuildEvent>
  14.151 +  </ItemDefinitionGroup>
  14.152 +  <ItemGroup>
  14.153 +    <ClCompile Include="src\stub.cc" />
  14.154 +  </ItemGroup>
  14.155 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  14.156 +  <ImportGroup Label="ExtensionTargets">
  14.157 +  </ImportGroup>
  14.158 +</Project>
  14.159 \ No newline at end of file
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/exporters/maxgoat_stub/maxgoat_stub.vcxproj.filters	Thu Apr 17 08:53:42 2014 +0300
    15.3 @@ -0,0 +1,22 @@
    15.4 +<?xml version="1.0" encoding="utf-8"?>
    15.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    15.6 +  <ItemGroup>
    15.7 +    <Filter Include="Source Files">
    15.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
    15.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
   15.10 +    </Filter>
   15.11 +    <Filter Include="Header Files">
   15.12 +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
   15.13 +      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
   15.14 +    </Filter>
   15.15 +    <Filter Include="Resource Files">
   15.16 +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
   15.17 +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
   15.18 +    </Filter>
   15.19 +  </ItemGroup>
   15.20 +  <ItemGroup>
   15.21 +    <ClCompile Include="src\stub.cc">
   15.22 +      <Filter>Source Files</Filter>
   15.23 +    </ClCompile>
   15.24 +  </ItemGroup>
   15.25 +</Project>
   15.26 \ No newline at end of file
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/exporters/maxgoat_stub/src/stub.cc	Thu Apr 17 08:53:42 2014 +0300
    16.3 @@ -0,0 +1,267 @@
    16.4 +#include <stdio.h>
    16.5 +#include <string.h>
    16.6 +#include <stdlib.h>
    16.7 +#include <errno.h>
    16.8 +#include <map>
    16.9 +#include <windows.h>
   16.10 +#include <shlobj.h>
   16.11 +#include "max.h"
   16.12 +#include "impexp.h"		// SceneExport
   16.13 +#include "iparamb2.h"	// ClassDesc2
   16.14 +#include "plugapi.h"
   16.15 +#include "IGame.h"
   16.16 +#include "IGameExport.h"
   16.17 +#include "IConversionmanager.h"
   16.18 +
   16.19 +
   16.20 +#pragma comment (lib, "core.lib")
   16.21 +#pragma comment (lib, "geom.lib")
   16.22 +#pragma comment (lib, "gfx.lib")
   16.23 +#pragma comment (lib, "mesh.lib")
   16.24 +#pragma comment (lib, "maxutil.lib")
   16.25 +#pragma comment (lib, "maxscrpt.lib")
   16.26 +#pragma comment (lib, "paramblk2.lib")
   16.27 +#pragma comment (lib, "msxml2.lib")
   16.28 +#pragma comment (lib, "igame.lib")
   16.29 +#pragma comment (lib, "comctl32.lib")
   16.30 +
   16.31 +
   16.32 +#define VER_MAJOR	1
   16.33 +#define VER_MINOR	0
   16.34 +#define VERSION(major, minor) \
   16.35 +	((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor)))
   16.36 +
   16.37 +typedef int (*PluginInitFunc)();
   16.38 +typedef int (*PluginShutdownFunc)();
   16.39 +typedef ClassDesc *(*PluginClassDescFunc)(int);
   16.40 +
   16.41 +static FILE *logfile;
   16.42 +static HINSTANCE hinst;
   16.43 +static const wchar_t *copyright_str = L"Copyright 2013 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details.";
   16.44 +
   16.45 +class GoatExporterStub : public SceneExport {
   16.46 +public:
   16.47 +	IGameScene *igame;
   16.48 +
   16.49 +	int ExtCount() { return 1; }
   16.50 +	const TCHAR *Ext(int n) { return L"goatsce"; }
   16.51 +	const TCHAR *LongDesc() { return L"Goat3D Scene file"; }
   16.52 +	const TCHAR *ShortDesc() { return L"Goat3D Scene"; }
   16.53 +	const TCHAR *AuthorName() { return L"John Tsiombikas"; }
   16.54 +	const TCHAR *CopyrightMessage() { return copyright_str; }
   16.55 +	const TCHAR *OtherMessage1() { return L"foo1"; }
   16.56 +	const TCHAR *OtherMessage2() { return L"foo2"; }
   16.57 +	unsigned int Version() { return VERSION(VER_MAJOR, VER_MINOR); }
   16.58 +	void ShowAbout(HWND win) { MessageBoxA(win, "Goat3D exporter", "About this plugin", 0); }
   16.59 +
   16.60 +	int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0);
   16.61 +};
   16.62 +
   16.63 +class GoatAnimExporterStub : public SceneExport {
   16.64 +public:
   16.65 +	IGameScene *igame;
   16.66 +
   16.67 +	int ExtCount() { return 1; }
   16.68 +	const TCHAR *Ext(int n) { return L"goatanm"; }
   16.69 +	const TCHAR *LongDesc() { return L"Goat3D Animation file"; }
   16.70 +	const TCHAR *ShortDesc() { return L"Goat3D Animation"; }
   16.71 +	const TCHAR *AuthorName() { return L"John Tsiombikas"; }
   16.72 +	const TCHAR *CopyrightMessage() { return copyright_str; }
   16.73 +	const TCHAR *OtherMessage1() { return L"bar1"; }
   16.74 +	const TCHAR *OtherMessage2() { return L"bar2"; }
   16.75 +	unsigned int Version() { return VERSION(VER_MAJOR, VER_MINOR); }
   16.76 +	void ShowAbout(HWND win) { MessageBoxA(win, "Goat3D anim exporter", "About this plugin", 0); }
   16.77 +
   16.78 +	int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0);
   16.79 +};
   16.80 +
   16.81 +static const char *find_dll_dir()
   16.82 +{
   16.83 +	static char path[MAX_PATH];
   16.84 +
   16.85 +	HMODULE dll;
   16.86 +	if(!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
   16.87 +			(LPCSTR)find_dll_dir, &dll)) {
   16.88 +		return 0;
   16.89 +	}
   16.90 +	GetModuleFileNameA(dll, path, sizeof path);
   16.91 +
   16.92 +	char *last_slash = strrchr(path, '\\');
   16.93 +	if(last_slash && last_slash[1]) {
   16.94 +		*last_slash = 0;
   16.95 +	}
   16.96 +
   16.97 +	return path;
   16.98 +}
   16.99 +
  16.100 +static int do_export(int which, const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL non_int, DWORD opt)
  16.101 +{
  16.102 +	const char *dll_fname = "maxgoat.dll";
  16.103 +	char *dll_path;
  16.104 +	HMODULE dll = 0;
  16.105 +	PluginInitFunc init;
  16.106 +	PluginShutdownFunc shutdown;
  16.107 +	PluginClassDescFunc get_class_desc;
  16.108 +	ClassDesc *desc;
  16.109 +	SceneExport *ex;
  16.110 +	int result = IMPEXP_FAIL;
  16.111 +
  16.112 +	const char *plugdir = find_dll_dir();
  16.113 +	if(plugdir) {
  16.114 +		dll_path = new char[strlen(dll_fname) + strlen(plugdir) + 2];
  16.115 +		sprintf(dll_path, "%s\\%s", plugdir, dll_fname);
  16.116 +	} else {
  16.117 +		dll_path = new char[strlen(dll_fname) + 1];
  16.118 +		strcpy(dll_path, dll_fname);
  16.119 +	}
  16.120 +
  16.121 +	if(!(dll = LoadLibraryA(dll_path))) {
  16.122 +		fprintf(logfile, "failed to load exporter: %s\n", dll_path);
  16.123 +		goto done;
  16.124 +	}
  16.125 +
  16.126 +	if(!(get_class_desc = (PluginClassDescFunc)GetProcAddress(dll, "LibClassDesc"))) {
  16.127 +		fprintf(logfile, "maxgoat.dll is invalid (no LibClassDesc function)\n");
  16.128 +		goto done;
  16.129 +	}
  16.130 +
  16.131 +	// first initialize the library
  16.132 +	if((init = (PluginInitFunc)GetProcAddress(dll, "LibInitialize"))) {
  16.133 +		if(!init()) {
  16.134 +			fprintf(logfile, "exporter initialization failed!\n");
  16.135 +			goto done;
  16.136 +		}
  16.137 +	}
  16.138 +
  16.139 +	if(!(desc = get_class_desc(which))) {
  16.140 +		fprintf(logfile, "failed to get the class descriptor\n");
  16.141 +		goto done;
  16.142 +	}
  16.143 +
  16.144 +	if(!(ex = (SceneExport*)desc->Create())) {
  16.145 +		fprintf(logfile, "failed to create exporter class instance\n");
  16.146 +		goto done;
  16.147 +	}
  16.148 +
  16.149 +	result = ex->DoExport(name, eiface, iface);
  16.150 +	delete ex;
  16.151 +
  16.152 +	if((shutdown = (PluginShutdownFunc)GetProcAddress(dll, "LibShutdown"))) {
  16.153 +		shutdown();
  16.154 +	}
  16.155 +
  16.156 +done:
  16.157 +	delete [] dll_path;
  16.158 +	if(dll) {
  16.159 +		FreeLibrary(dll);
  16.160 +	}
  16.161 +	return result;
  16.162 +}
  16.163 +
  16.164 +int GoatExporterStub::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface,
  16.165 +		BOOL non_interactive, DWORD opt)
  16.166 +{
  16.167 +	return do_export(0, name, eiface, iface, non_interactive, opt);
  16.168 +}
  16.169 +
  16.170 +
  16.171 +int GoatAnimExporterStub::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface,
  16.172 +		BOOL non_interactive, DWORD opt)
  16.173 +{
  16.174 +	return do_export(1, name, eiface, iface, non_interactive, opt);
  16.175 +}
  16.176 +
  16.177 +// ------------------------------------------
  16.178 +
  16.179 +class GoatClassDesc : public ClassDesc2 {
  16.180 +public:
  16.181 +	int IsPublic() { return TRUE; }
  16.182 +	void *Create(BOOL loading = FALSE) { return new GoatExporterStub; }
  16.183 +	const TCHAR *ClassName() { return L"GoatExporterStub"; }
  16.184 +	SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
  16.185 +	Class_ID ClassID() { return Class_ID(0x2e4e6311, 0x2b154d91); }
  16.186 +	const TCHAR *Category() { return L"Mutant Stargoat"; }
  16.187 +
  16.188 +	const TCHAR *InternalName() { return L"GoatExporterStub"; }
  16.189 +	HINSTANCE HInstance() { return hinst; }
  16.190 +};
  16.191 +
  16.192 +class GoatAnimClassDesc : public ClassDesc2 {
  16.193 +public:
  16.194 +	int IsPublic() { return TRUE; }
  16.195 +	void *Create(BOOL loading = FALSE) { return new GoatAnimExporterStub; }
  16.196 +	const TCHAR *ClassName() { return L"GoatAnimExporterStub"; }
  16.197 +	SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
  16.198 +	Class_ID ClassID() { return Class_ID(0x75054666, 0x45487285); }
  16.199 +	const TCHAR *Category() { return L"Mutant Stargoat"; }
  16.200 +
  16.201 +	const TCHAR *InternalName() { return L"GoatAnimExporterStub"; }
  16.202 +	HINSTANCE HInstance() { return hinst; }
  16.203 +};
  16.204 +
  16.205 +
  16.206 +static GoatClassDesc class_desc;
  16.207 +static GoatAnimClassDesc anim_class_desc;
  16.208 +
  16.209 +BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved)
  16.210 +{
  16.211 +	if(reason == DLL_PROCESS_ATTACH) {
  16.212 +		hinst = inst_handle;
  16.213 +		DisableThreadLibraryCalls(hinst);
  16.214 +	}
  16.215 +	return TRUE;
  16.216 +}
  16.217 +
  16.218 +extern "C" {
  16.219 +
  16.220 +__declspec(dllexport) const TCHAR *LibDescription()
  16.221 +{
  16.222 +	return L"Goat3D exporter stub";
  16.223 +}
  16.224 +
  16.225 +__declspec(dllexport) int LibNumberClasses()
  16.226 +{
  16.227 +	return 2;
  16.228 +}
  16.229 +
  16.230 +__declspec(dllexport) ClassDesc *LibClassDesc(int i)
  16.231 +{
  16.232 +	switch(i) {
  16.233 +	case 0:
  16.234 +		return &class_desc;
  16.235 +	case 1:
  16.236 +		return &anim_class_desc;
  16.237 +	default:
  16.238 +		break;
  16.239 +	}
  16.240 +	return 0;
  16.241 +}
  16.242 +
  16.243 +__declspec(dllexport) ULONG LibVersion()
  16.244 +{
  16.245 +	return Get3DSMAXVersion();
  16.246 +}
  16.247 +
  16.248 +__declspec(dllexport) int LibInitialize()
  16.249 +{
  16.250 +	static char path[1024];
  16.251 +
  16.252 +	SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path);
  16.253 +	strcat(path, "/testexpstub.log");
  16.254 +
  16.255 +	if((logfile = fopen(path, "w"))) {
  16.256 +		setvbuf(logfile, 0, _IONBF, 0);
  16.257 +	}
  16.258 +	return TRUE;
  16.259 +}
  16.260 +
  16.261 +__declspec(dllexport) int LibShutdown()
  16.262 +{
  16.263 +	if(logfile) {
  16.264 +		fclose(logfile);
  16.265 +		logfile = 0;
  16.266 +	}
  16.267 +	return TRUE;
  16.268 +}
  16.269 +
  16.270 +}	// extern "C"
  16.271 \ No newline at end of file
    17.1 --- a/goat3d-vs2012.sln	Thu Apr 17 08:50:36 2014 +0300
    17.2 +++ b/goat3d-vs2012.sln	Thu Apr 17 08:53:42 2014 +0300
    17.3 @@ -8,30 +8,53 @@
    17.4  		{86BF319B-9222-4805-918D-DC1B9F77BCEF} = {86BF319B-9222-4805-918D-DC1B9F77BCEF}
    17.5  	EndProjectSection
    17.6  EndProject
    17.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "maxgoat_stub", "exporters\maxgoat_stub\maxgoat_stub.vcxproj", "{941007A1-6375-4507-8745-FC3EA9DF010B}"
    17.8 +EndProject
    17.9  Global
   17.10  	GlobalSection(SolutionConfigurationPlatforms) = preSolution
   17.11 +		Debug|Mixed Platforms = Debug|Mixed Platforms
   17.12  		Debug|Win32 = Debug|Win32
   17.13  		Debug|x64 = Debug|x64
   17.14 +		Release|Mixed Platforms = Release|Mixed Platforms
   17.15  		Release|Win32 = Release|Win32
   17.16  		Release|x64 = Release|x64
   17.17  	EndGlobalSection
   17.18  	GlobalSection(ProjectConfigurationPlatforms) = postSolution
   17.19 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
   17.20 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Mixed Platforms.Build.0 = Debug|Win32
   17.21  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Win32.ActiveCfg = Debug|Win32
   17.22  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Win32.Build.0 = Debug|Win32
   17.23  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|x64.ActiveCfg = Debug|x64
   17.24  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|x64.Build.0 = Debug|x64
   17.25 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Mixed Platforms.ActiveCfg = Release|Win32
   17.26 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Mixed Platforms.Build.0 = Release|Win32
   17.27  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Win32.ActiveCfg = Release|Win32
   17.28  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Win32.Build.0 = Release|Win32
   17.29  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|x64.ActiveCfg = Release|x64
   17.30  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|x64.Build.0 = Release|x64
   17.31 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
   17.32 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Mixed Platforms.Build.0 = Debug|Win32
   17.33  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Win32.ActiveCfg = Debug|Win32
   17.34  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Win32.Build.0 = Debug|Win32
   17.35  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|x64.ActiveCfg = Debug|x64
   17.36  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|x64.Build.0 = Debug|x64
   17.37 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Mixed Platforms.ActiveCfg = Release|Win32
   17.38 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Mixed Platforms.Build.0 = Release|Win32
   17.39  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Win32.ActiveCfg = Release|Win32
   17.40  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Win32.Build.0 = Release|Win32
   17.41  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|x64.ActiveCfg = Release|x64
   17.42  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|x64.Build.0 = Release|x64
   17.43 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
   17.44 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Mixed Platforms.Build.0 = Debug|Win32
   17.45 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Win32.ActiveCfg = Debug|Win32
   17.46 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Win32.Build.0 = Debug|Win32
   17.47 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|x64.ActiveCfg = Debug|x64
   17.48 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|x64.Build.0 = Debug|x64
   17.49 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Mixed Platforms.ActiveCfg = Release|Win32
   17.50 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Mixed Platforms.Build.0 = Release|Win32
   17.51 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Win32.ActiveCfg = Release|Win32
   17.52 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Win32.Build.0 = Release|Win32
   17.53 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|x64.ActiveCfg = Release|Win32
   17.54  	EndGlobalSection
   17.55  	GlobalSection(SolutionProperties) = preSolution
   17.56  		HideSolutionNode = FALSE
    18.1 --- a/goat3d.vcxproj	Thu Apr 17 08:50:36 2014 +0300
    18.2 +++ b/goat3d.vcxproj	Thu Apr 17 08:53:42 2014 +0300
    18.3 @@ -19,9 +19,6 @@
    18.4      </ProjectConfiguration>
    18.5    </ItemGroup>
    18.6    <ItemGroup>
    18.7 -    <ClInclude Include="libs\anim\anim.h" />
    18.8 -    <ClInclude Include="libs\anim\dynarr.h" />
    18.9 -    <ClInclude Include="libs\anim\track.h" />
   18.10      <ClInclude Include="libs\openctm\internal.h" />
   18.11      <ClInclude Include="libs\openctm\liblzma\Alloc.h" />
   18.12      <ClInclude Include="libs\openctm\liblzma\LzFind.h" />
   18.13 @@ -34,16 +31,6 @@
   18.14      <ClInclude Include="libs\openctm\openctm.h" />
   18.15      <ClInclude Include="libs\openctm\openctmpp.h" />
   18.16      <ClInclude Include="libs\tinyxml2\tinyxml2.h" />
   18.17 -    <ClInclude Include="libs\vmath\basis.h" />
   18.18 -    <ClInclude Include="libs\vmath\geom.h" />
   18.19 -    <ClInclude Include="libs\vmath\matrix.h" />
   18.20 -    <ClInclude Include="libs\vmath\quat.h" />
   18.21 -    <ClInclude Include="libs\vmath\ray.h" />
   18.22 -    <ClInclude Include="libs\vmath\sphvec.h" />
   18.23 -    <ClInclude Include="libs\vmath\vector.h" />
   18.24 -    <ClInclude Include="libs\vmath\vmath.h" />
   18.25 -    <ClInclude Include="libs\vmath\vmath_config.h" />
   18.26 -    <ClInclude Include="libs\vmath\vmath_types.h" />
   18.27      <ClInclude Include="src\camera.h" />
   18.28      <ClInclude Include="src\chunk.h" />
   18.29      <ClInclude Include="src\goat3d.h" />
   18.30 @@ -57,9 +44,6 @@
   18.31      <ClInclude Include="src\xform_node.h" />
   18.32    </ItemGroup>
   18.33    <ItemGroup>
   18.34 -    <ClCompile Include="libs\anim\anim.c" />
   18.35 -    <ClCompile Include="libs\anim\dynarr.c" />
   18.36 -    <ClCompile Include="libs\anim\track.c" />
   18.37      <ClCompile Include="libs\openctm\compressMG1.c" />
   18.38      <ClCompile Include="libs\openctm\compressMG2.c" />
   18.39      <ClCompile Include="libs\openctm\compressRAW.c" />
   18.40 @@ -71,21 +55,10 @@
   18.41      <ClCompile Include="libs\openctm\openctm.c" />
   18.42      <ClCompile Include="libs\openctm\stream.c" />
   18.43      <ClCompile Include="libs\tinyxml2\tinyxml2.cpp" />
   18.44 -    <ClCompile Include="libs\vmath\basis.cc" />
   18.45 -    <ClCompile Include="libs\vmath\basis_c.c" />
   18.46 -    <ClCompile Include="libs\vmath\geom.c" />
   18.47 -    <ClCompile Include="libs\vmath\matrix.cc" />
   18.48 -    <ClCompile Include="libs\vmath\matrix_c.c" />
   18.49 -    <ClCompile Include="libs\vmath\quat.cc" />
   18.50 -    <ClCompile Include="libs\vmath\quat_c.c" />
   18.51 -    <ClCompile Include="libs\vmath\ray.cc" />
   18.52 -    <ClCompile Include="libs\vmath\ray_c.c" />
   18.53 -    <ClCompile Include="libs\vmath\sphvec.cc" />
   18.54 -    <ClCompile Include="libs\vmath\vector.cc" />
   18.55 -    <ClCompile Include="libs\vmath\vmath.c" />
   18.56      <ClCompile Include="src\camera.cc" />
   18.57      <ClCompile Include="src\chunk.cc" />
   18.58      <ClCompile Include="src\goat3d.cc" />
   18.59 +    <ClCompile Include="src\goat3d_read.cc" />
   18.60      <ClCompile Include="src\goat3d_readxml.cc" />
   18.61      <ClCompile Include="src\goat3d_write.cc" />
   18.62      <ClCompile Include="src\goat3d_writexml.cc" />
   18.63 @@ -97,13 +70,6 @@
   18.64      <ClCompile Include="src\scene.cc" />
   18.65      <ClCompile Include="src\xform_node.cc" />
   18.66    </ItemGroup>
   18.67 -  <ItemGroup>
   18.68 -    <None Include="libs\vmath\matrix.inl" />
   18.69 -    <None Include="libs\vmath\quat.inl" />
   18.70 -    <None Include="libs\vmath\ray.inl" />
   18.71 -    <None Include="libs\vmath\vector.inl" />
   18.72 -    <None Include="libs\vmath\vmath.inl" />
   18.73 -  </ItemGroup>
   18.74    <PropertyGroup Label="Globals">
   18.75      <ProjectGuid>{86BF319B-9222-4805-918D-DC1B9F77BCEF}</ProjectGuid>
   18.76      <Keyword>Win32Proj</Keyword>
   18.77 @@ -164,8 +130,9 @@
   18.78        </PrecompiledHeader>
   18.79        <WarningLevel>Level3</WarningLevel>
   18.80        <Optimization>Disabled</Optimization>
   18.81 -      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   18.82 -      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
   18.83 +      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;OPENCTM_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   18.84 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   18.85 +      <AdditionalIncludeDirectories>$(ProjectDir)\libs\openctm;$(ProjectDir)\libs\openctm\liblzma;$(ProjectDir)\libs\tinyxml2</AdditionalIncludeDirectories>
   18.86      </ClCompile>
   18.87      <Link>
   18.88        <SubSystem>Windows</SubSystem>
   18.89 @@ -180,7 +147,7 @@
   18.90        <Optimization>Disabled</Optimization>
   18.91        <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC;BUILD_MAXPLUGIN</PreprocessorDefinitions>
   18.92        <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   18.93 -      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath</AdditionalIncludeDirectories>
   18.94 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2</AdditionalIncludeDirectories>
   18.95      </ClCompile>
   18.96      <Link>
   18.97        <SubSystem>Windows</SubSystem>
   18.98 @@ -199,8 +166,9 @@
   18.99        <Optimization>MaxSpeed</Optimization>
  18.100        <FunctionLevelLinking>true</FunctionLevelLinking>
  18.101        <IntrinsicFunctions>true</IntrinsicFunctions>
  18.102 -      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  18.103 -      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
  18.104 +      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;OPENCTM_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  18.105 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
  18.106 +      <AdditionalIncludeDirectories>$(ProjectDir)\libs\openctm;$(ProjectDir)\libs\openctm\liblzma;$(ProjectDir)\libs\tinyxml2</AdditionalIncludeDirectories>
  18.107      </ClCompile>
  18.108      <Link>
  18.109        <SubSystem>Windows</SubSystem>
  18.110 @@ -219,7 +187,7 @@
  18.111        <IntrinsicFunctions>true</IntrinsicFunctions>
  18.112        <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC</PreprocessorDefinitions>
  18.113        <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
  18.114 -      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath</AdditionalIncludeDirectories>
  18.115 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2</AdditionalIncludeDirectories>
  18.116      </ClCompile>
  18.117      <Link>
  18.118        <SubSystem>Windows</SubSystem>
    19.1 --- a/goat3d.vcxproj.filters	Thu Apr 17 08:50:36 2014 +0300
    19.2 +++ b/goat3d.vcxproj.filters	Thu Apr 17 08:53:42 2014 +0300
    19.3 @@ -17,12 +17,6 @@
    19.4      <Filter Include="libs\openctm\liblzma">
    19.5        <UniqueIdentifier>{18a85bea-ddb2-49a1-a7b1-bd11b23d5549}</UniqueIdentifier>
    19.6      </Filter>
    19.7 -    <Filter Include="libs\vmath">
    19.8 -      <UniqueIdentifier>{dc4ab435-af1e-4786-8011-a7a793e229eb}</UniqueIdentifier>
    19.9 -    </Filter>
   19.10 -    <Filter Include="libs\anim">
   19.11 -      <UniqueIdentifier>{05d8010d-b4d9-4829-80ea-8c8d018e1e04}</UniqueIdentifier>
   19.12 -    </Filter>
   19.13    </ItemGroup>
   19.14    <ItemGroup>
   19.15      <ClInclude Include="src\camera.h">
   19.16 @@ -94,45 +88,6 @@
   19.17      <ClInclude Include="libs\openctm\liblzma\Types.h">
   19.18        <Filter>libs\openctm\liblzma</Filter>
   19.19      </ClInclude>
   19.20 -    <ClInclude Include="libs\anim\anim.h">
   19.21 -      <Filter>libs\anim</Filter>
   19.22 -    </ClInclude>
   19.23 -    <ClInclude Include="libs\anim\dynarr.h">
   19.24 -      <Filter>libs\anim</Filter>
   19.25 -    </ClInclude>
   19.26 -    <ClInclude Include="libs\anim\track.h">
   19.27 -      <Filter>libs\anim</Filter>
   19.28 -    </ClInclude>
   19.29 -    <ClInclude Include="libs\vmath\basis.h">
   19.30 -      <Filter>libs\vmath</Filter>
   19.31 -    </ClInclude>
   19.32 -    <ClInclude Include="libs\vmath\geom.h">
   19.33 -      <Filter>libs\vmath</Filter>
   19.34 -    </ClInclude>
   19.35 -    <ClInclude Include="libs\vmath\matrix.h">
   19.36 -      <Filter>libs\vmath</Filter>
   19.37 -    </ClInclude>
   19.38 -    <ClInclude Include="libs\vmath\quat.h">
   19.39 -      <Filter>libs\vmath</Filter>
   19.40 -    </ClInclude>
   19.41 -    <ClInclude Include="libs\vmath\ray.h">
   19.42 -      <Filter>libs\vmath</Filter>
   19.43 -    </ClInclude>
   19.44 -    <ClInclude Include="libs\vmath\sphvec.h">
   19.45 -      <Filter>libs\vmath</Filter>
   19.46 -    </ClInclude>
   19.47 -    <ClInclude Include="libs\vmath\vector.h">
   19.48 -      <Filter>libs\vmath</Filter>
   19.49 -    </ClInclude>
   19.50 -    <ClInclude Include="libs\vmath\vmath.h">
   19.51 -      <Filter>libs\vmath</Filter>
   19.52 -    </ClInclude>
   19.53 -    <ClInclude Include="libs\vmath\vmath_config.h">
   19.54 -      <Filter>libs\vmath</Filter>
   19.55 -    </ClInclude>
   19.56 -    <ClInclude Include="libs\vmath\vmath_types.h">
   19.57 -      <Filter>libs\vmath</Filter>
   19.58 -    </ClInclude>
   19.59    </ItemGroup>
   19.60    <ItemGroup>
   19.61      <ClCompile Include="src\goat3d.cc">
   19.62 @@ -207,67 +162,8 @@
   19.63      <ClCompile Include="libs\openctm\liblzma\LzmaLib.c">
   19.64        <Filter>libs\openctm\liblzma</Filter>
   19.65      </ClCompile>
   19.66 -    <ClCompile Include="libs\anim\anim.c">
   19.67 -      <Filter>libs\anim</Filter>
   19.68 -    </ClCompile>
   19.69 -    <ClCompile Include="libs\anim\dynarr.c">
   19.70 -      <Filter>libs\anim</Filter>
   19.71 -    </ClCompile>
   19.72 -    <ClCompile Include="libs\anim\track.c">
   19.73 -      <Filter>libs\anim</Filter>
   19.74 -    </ClCompile>
   19.75 -    <ClCompile Include="libs\vmath\basis.cc">
   19.76 -      <Filter>libs\vmath</Filter>
   19.77 -    </ClCompile>
   19.78 -    <ClCompile Include="libs\vmath\basis_c.c">
   19.79 -      <Filter>libs\vmath</Filter>
   19.80 -    </ClCompile>
   19.81 -    <ClCompile Include="libs\vmath\geom.c">
   19.82 -      <Filter>libs\vmath</Filter>
   19.83 -    </ClCompile>
   19.84 -    <ClCompile Include="libs\vmath\matrix.cc">
   19.85 -      <Filter>libs\vmath</Filter>
   19.86 -    </ClCompile>
   19.87 -    <ClCompile Include="libs\vmath\matrix_c.c">
   19.88 -      <Filter>libs\vmath</Filter>
   19.89 -    </ClCompile>
   19.90 -    <ClCompile Include="libs\vmath\quat.cc">
   19.91 -      <Filter>libs\vmath</Filter>
   19.92 -    </ClCompile>
   19.93 -    <ClCompile Include="libs\vmath\quat_c.c">
   19.94 -      <Filter>libs\vmath</Filter>
   19.95 -    </ClCompile>
   19.96 -    <ClCompile Include="libs\vmath\ray.cc">
   19.97 -      <Filter>libs\vmath</Filter>
   19.98 -    </ClCompile>
   19.99 -    <ClCompile Include="libs\vmath\ray_c.c">
  19.100 -      <Filter>libs\vmath</Filter>
  19.101 -    </ClCompile>
  19.102 -    <ClCompile Include="libs\vmath\sphvec.cc">
  19.103 -      <Filter>libs\vmath</Filter>
  19.104 -    </ClCompile>
  19.105 -    <ClCompile Include="libs\vmath\vector.cc">
  19.106 -      <Filter>libs\vmath</Filter>
  19.107 -    </ClCompile>
  19.108 -    <ClCompile Include="libs\vmath\vmath.c">
  19.109 -      <Filter>libs\vmath</Filter>
  19.110 +    <ClCompile Include="src\goat3d_read.cc">
  19.111 +      <Filter>src</Filter>
  19.112      </ClCompile>
  19.113    </ItemGroup>
  19.114 -  <ItemGroup>
  19.115 -    <None Include="libs\vmath\matrix.inl">
  19.116 -      <Filter>libs\vmath</Filter>
  19.117 -    </None>
  19.118 -    <None Include="libs\vmath\quat.inl">
  19.119 -      <Filter>libs\vmath</Filter>
  19.120 -    </None>
  19.121 -    <None Include="libs\vmath\ray.inl">
  19.122 -      <Filter>libs\vmath</Filter>
  19.123 -    </None>
  19.124 -    <None Include="libs\vmath\vector.inl">
  19.125 -      <Filter>libs\vmath</Filter>
  19.126 -    </None>
  19.127 -    <None Include="libs\vmath\vmath.inl">
  19.128 -      <Filter>libs\vmath</Filter>
  19.129 -    </None>
  19.130 -  </ItemGroup>
  19.131  </Project>
  19.132 \ No newline at end of file
    20.1 --- a/libs/anim/Makefile	Thu Apr 17 08:50:36 2014 +0300
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,17 +0,0 @@
    20.4 -src = $(wildcard *.c)
    20.5 -obj = $(src:.c=.o)
    20.6 -lib = libanim.a
    20.7 -
    20.8 -ifneq ($(shell uname -s), Darwin)
    20.9 -	pic = -fPIC
   20.10 -endif
   20.11 -
   20.12 -CFLAGS = -pedantic -Wall -g $(pic)
   20.13 -CXXFLAGS = -pedantic -Wall -g $(pic)
   20.14 -
   20.15 -$(lib): $(obj)
   20.16 -	$(AR) rcs $@ $(obj)
   20.17 -
   20.18 -.PHONY: clean
   20.19 -clean:
   20.20 -	rm -f $(obj) $(lib)
    21.1 --- a/libs/anim/anim.c	Thu Apr 17 08:50:36 2014 +0300
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,946 +0,0 @@
    21.4 -#include <stdlib.h>
    21.5 -#include <limits.h>
    21.6 -#include <assert.h>
    21.7 -#include "anim.h"
    21.8 -#include "dynarr.h"
    21.9 -
   21.10 -#define ROT_USE_SLERP
   21.11 -
   21.12 -static void invalidate_cache(struct anm_node *node);
   21.13 -
   21.14 -int anm_init_animation(struct anm_animation *anim)
   21.15 -{
   21.16 -	int i, j;
   21.17 -	static const float defaults[] = {
   21.18 -		0.0f, 0.0f, 0.0f,		/* default position */
   21.19 -		0.0f, 0.0f, 0.0f, 1.0f,	/* default rotation quat */
   21.20 -		1.0f, 1.0f, 1.0f		/* default scale factor */
   21.21 -	};
   21.22 -
   21.23 -	anim->name = 0;
   21.24 -
   21.25 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
   21.26 -		if(anm_init_track(anim->tracks + i) == -1) {
   21.27 -			for(j=0; j<i; j++) {
   21.28 -				anm_destroy_track(anim->tracks + i);
   21.29 -			}
   21.30 -		}
   21.31 -		anm_set_track_default(anim->tracks + i, defaults[i]);
   21.32 -	}
   21.33 -	return 0;
   21.34 -}
   21.35 -
   21.36 -void anm_destroy_animation(struct anm_animation *anim)
   21.37 -{
   21.38 -	int i;
   21.39 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
   21.40 -		anm_destroy_track(anim->tracks + i);
   21.41 -	}
   21.42 -	free(anim->name);
   21.43 -}
   21.44 -
   21.45 -void anm_set_animation_name(struct anm_animation *anim, const char *name)
   21.46 -{
   21.47 -	char *newname = malloc(strlen(name) + 1);
   21.48 -	if(!newname) return;
   21.49 -
   21.50 -	strcpy(newname, name);
   21.51 -
   21.52 -	free(anim->name);
   21.53 -	anim->name = newname;
   21.54 -}
   21.55 -
   21.56 -/* ---- node implementation ----- */
   21.57 -
   21.58 -int anm_init_node(struct anm_node *node)
   21.59 -{
   21.60 -	memset(node, 0, sizeof *node);
   21.61 -
   21.62 -	node->cur_anim[1] = -1;
   21.63 -
   21.64 -	if(!(node->animations = dynarr_alloc(1, sizeof *node->animations))) {
   21.65 -		return -1;
   21.66 -	}
   21.67 -	if(anm_init_animation(node->animations) == -1) {
   21.68 -		dynarr_free(node->animations);
   21.69 -		return -1;
   21.70 -	}
   21.71 -
   21.72 -	/* initialize thread-local matrix cache */
   21.73 -	pthread_key_create(&node->cache_key, 0);
   21.74 -	pthread_mutex_init(&node->cache_list_lock, 0);
   21.75 -
   21.76 -	return 0;
   21.77 -}
   21.78 -
   21.79 -void anm_destroy_node(struct anm_node *node)
   21.80 -{
   21.81 -	int i;
   21.82 -	free(node->name);
   21.83 -
   21.84 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
   21.85 -		anm_destroy_animation(node->animations + i);
   21.86 -	}
   21.87 -	dynarr_free(node->animations);
   21.88 -
   21.89 -	/* destroy thread-specific cache */
   21.90 -	pthread_key_delete(node->cache_key);
   21.91 -
   21.92 -	while(node->cache_list) {
   21.93 -		struct mat_cache *tmp = node->cache_list;
   21.94 -		node->cache_list = tmp->next;
   21.95 -		free(tmp);
   21.96 -	}
   21.97 -}
   21.98 -
   21.99 -void anm_destroy_node_tree(struct anm_node *tree)
  21.100 -{
  21.101 -	struct anm_node *c, *tmp;
  21.102 -
  21.103 -	if(!tree) return;
  21.104 -
  21.105 -	c = tree->child;
  21.106 -	while(c) {
  21.107 -		tmp = c;
  21.108 -		c = c->next;
  21.109 -
  21.110 -		anm_destroy_node_tree(tmp);
  21.111 -	}
  21.112 -	anm_destroy_node(tree);
  21.113 -}
  21.114 -
  21.115 -struct anm_node *anm_create_node(void)
  21.116 -{
  21.117 -	struct anm_node *n;
  21.118 -
  21.119 -	if((n = malloc(sizeof *n))) {
  21.120 -		if(anm_init_node(n) == -1) {
  21.121 -			free(n);
  21.122 -			return 0;
  21.123 -		}
  21.124 -	}
  21.125 -	return n;
  21.126 -}
  21.127 -
  21.128 -void anm_free_node(struct anm_node *node)
  21.129 -{
  21.130 -	anm_destroy_node(node);
  21.131 -	free(node);
  21.132 -}
  21.133 -
  21.134 -void anm_free_node_tree(struct anm_node *tree)
  21.135 -{
  21.136 -	struct anm_node *c, *tmp;
  21.137 -
  21.138 -	if(!tree) return;
  21.139 -
  21.140 -	c = tree->child;
  21.141 -	while(c) {
  21.142 -		tmp = c;
  21.143 -		c = c->next;
  21.144 -
  21.145 -		anm_free_node_tree(tmp);
  21.146 -	}
  21.147 -
  21.148 -	anm_free_node(tree);
  21.149 -}
  21.150 -
  21.151 -int anm_set_node_name(struct anm_node *node, const char *name)
  21.152 -{
  21.153 -	char *str;
  21.154 -
  21.155 -	if(!(str = malloc(strlen(name) + 1))) {
  21.156 -		return -1;
  21.157 -	}
  21.158 -	strcpy(str, name);
  21.159 -	free(node->name);
  21.160 -	node->name = str;
  21.161 -	return 0;
  21.162 -}
  21.163 -
  21.164 -const char *anm_get_node_name(struct anm_node *node)
  21.165 -{
  21.166 -	return node->name ? node->name : "";
  21.167 -}
  21.168 -
  21.169 -void anm_link_node(struct anm_node *p, struct anm_node *c)
  21.170 -{
  21.171 -	c->next = p->child;
  21.172 -	p->child = c;
  21.173 -
  21.174 -	c->parent = p;
  21.175 -	invalidate_cache(c);
  21.176 -}
  21.177 -
  21.178 -int anm_unlink_node(struct anm_node *p, struct anm_node *c)
  21.179 -{
  21.180 -	struct anm_node *iter;
  21.181 -
  21.182 -	if(p->child == c) {
  21.183 -		p->child = c->next;
  21.184 -		c->next = 0;
  21.185 -		invalidate_cache(c);
  21.186 -		return 0;
  21.187 -	}
  21.188 -
  21.189 -	iter = p->child;
  21.190 -	while(iter->next) {
  21.191 -		if(iter->next == c) {
  21.192 -			iter->next = c->next;
  21.193 -			c->next = 0;
  21.194 -			invalidate_cache(c);
  21.195 -			return 0;
  21.196 -		}
  21.197 -	}
  21.198 -	return -1;
  21.199 -}
  21.200 -
  21.201 -void anm_set_pivot(struct anm_node *node, vec3_t piv)
  21.202 -{
  21.203 -	node->pivot = piv;
  21.204 -}
  21.205 -
  21.206 -vec3_t anm_get_pivot(struct anm_node *node)
  21.207 -{
  21.208 -	return node->pivot;
  21.209 -}
  21.210 -
  21.211 -
  21.212 -/* animation management */
  21.213 -
  21.214 -int anm_use_node_animation(struct anm_node *node, int aidx)
  21.215 -{
  21.216 -	if(aidx == node->cur_anim[0] && node->cur_anim[1] == -1) {
  21.217 -		return 0;	/* no change, no invalidation */
  21.218 -	}
  21.219 -
  21.220 -	if(aidx < 0 || aidx >= anm_get_animation_count(node)) {
  21.221 -		return -1;
  21.222 -	}
  21.223 -
  21.224 -	node->cur_anim[0] = aidx;
  21.225 -	node->cur_anim[1] = -1;
  21.226 -	node->cur_mix = 0;
  21.227 -	node->blend_dur = -1;
  21.228 -
  21.229 -	invalidate_cache(node);
  21.230 -	return 0;
  21.231 -}
  21.232 -
  21.233 -int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t)
  21.234 -{
  21.235 -	int num_anim;
  21.236 -
  21.237 -	if(node->cur_anim[0] == aidx && node->cur_anim[1] == bidx &&
  21.238 -			fabs(t - node->cur_mix) < 1e-6) {
  21.239 -		return 0;	/* no change, no invalidation */
  21.240 -	}
  21.241 -
  21.242 -	num_anim = anm_get_animation_count(node);
  21.243 -	if(aidx < 0 || aidx >= num_anim) {
  21.244 -		return anm_use_animation(node, bidx);
  21.245 -	}
  21.246 -	if(bidx < 0 || bidx >= num_anim) {
  21.247 -		return anm_use_animation(node, aidx);
  21.248 -	}
  21.249 -	node->cur_anim[0] = aidx;
  21.250 -	node->cur_anim[1] = bidx;
  21.251 -	node->cur_mix = t;
  21.252 -
  21.253 -	invalidate_cache(node);
  21.254 -	return 0;
  21.255 -}
  21.256 -
  21.257 -int anm_use_animation(struct anm_node *node, int aidx)
  21.258 -{
  21.259 -	struct anm_node *child;
  21.260 -
  21.261 -	if(anm_use_node_animation(node, aidx) == -1) {
  21.262 -		return -1;
  21.263 -	}
  21.264 -
  21.265 -	child = node->child;
  21.266 -	while(child) {
  21.267 -		if(anm_use_animation(child, aidx) == -1) {
  21.268 -			return -1;
  21.269 -		}
  21.270 -		child = child->next;
  21.271 -	}
  21.272 -	return 0;
  21.273 -}
  21.274 -
  21.275 -int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t)
  21.276 -{
  21.277 -	struct anm_node *child;
  21.278 -
  21.279 -	if(anm_use_node_animations(node, aidx, bidx, t) == -1) {
  21.280 -		return -1;
  21.281 -	}
  21.282 -
  21.283 -	child = node->child;
  21.284 -	while(child) {
  21.285 -		if(anm_use_animations(child, aidx, bidx, t) == -1) {
  21.286 -			return -1;
  21.287 -		}
  21.288 -		child = child->next;
  21.289 -	}
  21.290 -	return 0;
  21.291 -
  21.292 -}
  21.293 -
  21.294 -void anm_set_node_animation_offset(struct anm_node *node, anm_time_t offs, int which)
  21.295 -{
  21.296 -	if(which < 0 || which >= 2) {
  21.297 -		return;
  21.298 -	}
  21.299 -	node->cur_anim_offset[which] = offs;
  21.300 -}
  21.301 -
  21.302 -anm_time_t anm_get_animation_offset(const struct anm_node *node, int which)
  21.303 -{
  21.304 -	if(which < 0 || which >= 2) {
  21.305 -		return 0;
  21.306 -	}
  21.307 -	return node->cur_anim_offset[which];
  21.308 -}
  21.309 -
  21.310 -void anm_set_animation_offset(struct anm_node *node, anm_time_t offs, int which)
  21.311 -{
  21.312 -	struct anm_node *c = node->child;
  21.313 -	while(c) {
  21.314 -		anm_set_animation_offset(c, offs, which);
  21.315 -		c = c->next;
  21.316 -	}
  21.317 -
  21.318 -	anm_set_node_animation_offset(node, offs, which);
  21.319 -}
  21.320 -
  21.321 -int anm_get_active_animation_index(const struct anm_node *node, int which)
  21.322 -{
  21.323 -	if(which < 0 || which >= 2) return -1;
  21.324 -	return node->cur_anim[which];
  21.325 -}
  21.326 -
  21.327 -struct anm_animation *anm_get_active_animation(const struct anm_node *node, int which)
  21.328 -{
  21.329 -	int idx = anm_get_active_animation_index(node, which);
  21.330 -	if(idx < 0 || idx >= anm_get_animation_count(node)) {
  21.331 -		return 0;
  21.332 -	}
  21.333 -	return node->animations + idx;
  21.334 -}
  21.335 -
  21.336 -float anm_get_active_animation_mix(const struct anm_node *node)
  21.337 -{
  21.338 -	return node->cur_mix;
  21.339 -}
  21.340 -
  21.341 -int anm_get_animation_count(const struct anm_node *node)
  21.342 -{
  21.343 -	return dynarr_size(node->animations);
  21.344 -}
  21.345 -
  21.346 -int anm_add_node_animation(struct anm_node *node)
  21.347 -{
  21.348 -	struct anm_animation newanim;
  21.349 -	anm_init_animation(&newanim);
  21.350 -
  21.351 -	node->animations = dynarr_push(node->animations, &newanim);
  21.352 -	return 0;
  21.353 -}
  21.354 -
  21.355 -int anm_remove_node_animation(struct anm_node *node, int idx)
  21.356 -{
  21.357 -	fprintf(stderr, "anm_remove_animation: unimplemented!");
  21.358 -	abort();
  21.359 -	return 0;
  21.360 -}
  21.361 -
  21.362 -int anm_add_animation(struct anm_node *node)
  21.363 -{
  21.364 -	struct anm_node *child;
  21.365 -
  21.366 -	if(anm_add_node_animation(node) == -1) {
  21.367 -		return -1;
  21.368 -	}
  21.369 -
  21.370 -	child = node->child;
  21.371 -	while(child) {
  21.372 -		if(anm_add_animation(child)) {
  21.373 -			return -1;
  21.374 -		}
  21.375 -		child = child->next;
  21.376 -	}
  21.377 -	return 0;
  21.378 -}
  21.379 -
  21.380 -int anm_remove_animation(struct anm_node *node, int idx)
  21.381 -{
  21.382 -	struct anm_node *child;
  21.383 -
  21.384 -	if(anm_remove_node_animation(node, idx) == -1) {
  21.385 -		return -1;
  21.386 -	}
  21.387 -
  21.388 -	child = node->child;
  21.389 -	while(child) {
  21.390 -		if(anm_remove_animation(child, idx) == -1) {
  21.391 -			return -1;
  21.392 -		}
  21.393 -		child = child->next;
  21.394 -	}
  21.395 -	return 0;
  21.396 -}
  21.397 -
  21.398 -struct anm_animation *anm_get_animation(struct anm_node *node, int idx)
  21.399 -{
  21.400 -	if(idx < 0 || idx > anm_get_animation_count(node)) {
  21.401 -		return 0;
  21.402 -	}
  21.403 -	return node->animations + idx;
  21.404 -}
  21.405 -
  21.406 -struct anm_animation *anm_get_animation_by_name(struct anm_node *node, const char *name)
  21.407 -{
  21.408 -	return anm_get_animation(node, anm_find_animation(node, name));
  21.409 -}
  21.410 -
  21.411 -int anm_find_animation(struct anm_node *node, const char *name)
  21.412 -{
  21.413 -	int i, count = anm_get_animation_count(node);
  21.414 -	for(i=0; i<count; i++) {
  21.415 -		if(strcmp(node->animations[i].name, name) == 0) {
  21.416 -			return i;
  21.417 -		}
  21.418 -	}
  21.419 -	return -1;
  21.420 -}
  21.421 -
  21.422 -/* all the rest act on the current animation(s) */
  21.423 -
  21.424 -void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in)
  21.425 -{
  21.426 -	int i;
  21.427 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.428 -	if(!anim) return;
  21.429 -
  21.430 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
  21.431 -		anm_set_track_interpolator(anim->tracks + i, in);
  21.432 -	}
  21.433 -	invalidate_cache(node);
  21.434 -}
  21.435 -
  21.436 -void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex)
  21.437 -{
  21.438 -	int i;
  21.439 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.440 -	if(!anim) return;
  21.441 -
  21.442 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
  21.443 -		anm_set_track_extrapolator(anim->tracks + i, ex);
  21.444 -	}
  21.445 -	invalidate_cache(node);
  21.446 -}
  21.447 -
  21.448 -void anm_set_node_active_animation_name(struct anm_node *node, const char *name)
  21.449 -{
  21.450 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.451 -	if(!anim) return;
  21.452 -
  21.453 -	anm_set_animation_name(anim, name);
  21.454 -}
  21.455 -
  21.456 -void anm_set_active_animation_name(struct anm_node *node, const char *name)
  21.457 -{
  21.458 -	struct anm_node *child;
  21.459 -
  21.460 -	anm_set_node_active_animation_name(node, name);
  21.461 -
  21.462 -	child = node->child;
  21.463 -	while(child) {
  21.464 -		anm_set_active_animation_name(child, name);
  21.465 -		child = child->next;
  21.466 -	}
  21.467 -}
  21.468 -
  21.469 -const char *anm_get_active_animation_name(struct anm_node *node)
  21.470 -{
  21.471 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.472 -	if(anim) {
  21.473 -		return anim->name;
  21.474 -	}
  21.475 -	return 0;
  21.476 -}
  21.477 -
  21.478 -/* ---- high level animation blending ---- */
  21.479 -void anm_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur)
  21.480 -{
  21.481 -	struct anm_node *c = node->child;
  21.482 -
  21.483 -	if(anmidx == node->cur_anim[0]) {
  21.484 -		return;
  21.485 -	}
  21.486 -
  21.487 -	while(c) {
  21.488 -		anm_transition(c, anmidx, start, dur);
  21.489 -		c = c->next;
  21.490 -	}
  21.491 -
  21.492 -	anm_node_transition(node, anmidx, start, dur);
  21.493 -}
  21.494 -
  21.495 -void anm_node_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur)
  21.496 -{
  21.497 -	if(anmidx == node->cur_anim[0]) {
  21.498 -		return;
  21.499 -	}
  21.500 -
  21.501 -	node->cur_anim[1] = anmidx;
  21.502 -	node->cur_anim_offset[1] = start;
  21.503 -	node->blend_dur = dur;
  21.504 -}
  21.505 -
  21.506 -
  21.507 -#define BLEND_START_TM	node->cur_anim_offset[1]
  21.508 -
  21.509 -static anm_time_t animation_time(struct anm_node *node, anm_time_t tm, int which)
  21.510 -{
  21.511 -	float t;
  21.512 -
  21.513 -	if(node->blend_dur >= 0) {
  21.514 -		/* we're in transition... */
  21.515 -		t = (float)(tm - BLEND_START_TM) / (float)node->blend_dur;
  21.516 -		if(t < 0.0) t = 0.0;
  21.517 -
  21.518 -		node->cur_mix = t;
  21.519 -
  21.520 -		if(t > 1.0) {
  21.521 -			/* switch completely over to the target animation and stop blending */
  21.522 -			anm_use_node_animation(node, node->cur_anim[1]);
  21.523 -			node->cur_anim_offset[0] = node->cur_anim_offset[1];
  21.524 -		}
  21.525 -	}
  21.526 -
  21.527 -	return tm - node->cur_anim_offset[which];
  21.528 -}
  21.529 -
  21.530 -
  21.531 -void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm)
  21.532 -{
  21.533 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.534 -	if(!anim) return;
  21.535 -
  21.536 -	anm_set_value(anim->tracks + ANM_TRACK_POS_X, tm, pos.x);
  21.537 -	anm_set_value(anim->tracks + ANM_TRACK_POS_Y, tm, pos.y);
  21.538 -	anm_set_value(anim->tracks + ANM_TRACK_POS_Z, tm, pos.z);
  21.539 -	invalidate_cache(node);
  21.540 -}
  21.541 -
  21.542 -
  21.543 -vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm)
  21.544 -{
  21.545 -	vec3_t v;
  21.546 -	anm_time_t tm0 = animation_time(node, tm, 0);
  21.547 -	struct anm_animation *anim0 = anm_get_active_animation(node, 0);
  21.548 -	struct anm_animation *anim1 = anm_get_active_animation(node, 1);
  21.549 -
  21.550 -	if(!anim0) {
  21.551 -		return v3_cons(0, 0, 0);
  21.552 -	}
  21.553 -
  21.554 -	v.x = anm_get_value(anim0->tracks + ANM_TRACK_POS_X, tm0);
  21.555 -	v.y = anm_get_value(anim0->tracks + ANM_TRACK_POS_Y, tm0);
  21.556 -	v.z = anm_get_value(anim0->tracks + ANM_TRACK_POS_Z, tm0);
  21.557 -
  21.558 -	if(anim1) {
  21.559 -		vec3_t v1;
  21.560 -		anm_time_t tm1 = animation_time(node, tm, 1);
  21.561 -		v1.x = anm_get_value(anim1->tracks + ANM_TRACK_POS_X, tm1);
  21.562 -		v1.y = anm_get_value(anim1->tracks + ANM_TRACK_POS_Y, tm1);
  21.563 -		v1.z = anm_get_value(anim1->tracks + ANM_TRACK_POS_Z, tm1);
  21.564 -
  21.565 -		v.x = v.x + (v1.x - v.x) * node->cur_mix;
  21.566 -		v.y = v.y + (v1.y - v.y) * node->cur_mix;
  21.567 -		v.z = v.z + (v1.z - v.z) * node->cur_mix;
  21.568 -	}
  21.569 -
  21.570 -	return v;
  21.571 -}
  21.572 -
  21.573 -void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm)
  21.574 -{
  21.575 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.576 -	if(!anim) return;
  21.577 -
  21.578 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_X, tm, rot.x);
  21.579 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_Y, tm, rot.y);
  21.580 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_Z, tm, rot.z);
  21.581 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_W, tm, rot.w);
  21.582 -	invalidate_cache(node);
  21.583 -}
  21.584 -
  21.585 -static quat_t get_node_rotation(struct anm_node *node, anm_time_t tm, struct anm_animation *anim)
  21.586 -{
  21.587 -#ifndef ROT_USE_SLERP
  21.588 -	quat_t q;
  21.589 -	q.x = anm_get_value(anim->tracks + ANM_TRACK_ROT_X, tm);
  21.590 -	q.y = anm_get_value(anim->tracks + ANM_TRACK_ROT_Y, tm);
  21.591 -	q.z = anm_get_value(anim->tracks + ANM_TRACK_ROT_Z, tm);
  21.592 -	q.w = anm_get_value(anim->tracks + ANM_TRACK_ROT_W, tm);
  21.593 -	return q;
  21.594 -#else
  21.595 -	int idx0, idx1, last_idx;
  21.596 -	anm_time_t tstart, tend;
  21.597 -	float t, dt;
  21.598 -	struct anm_track *track_x, *track_y, *track_z, *track_w;
  21.599 -	quat_t q, q1, q2;
  21.600 -
  21.601 -	track_x = anim->tracks + ANM_TRACK_ROT_X;
  21.602 -	track_y = anim->tracks + ANM_TRACK_ROT_Y;
  21.603 -	track_z = anim->tracks + ANM_TRACK_ROT_Z;
  21.604 -	track_w = anim->tracks + ANM_TRACK_ROT_W;
  21.605 -
  21.606 -	if(!track_x->count) {
  21.607 -		q.x = track_x->def_val;
  21.608 -		q.y = track_y->def_val;
  21.609 -		q.z = track_z->def_val;
  21.610 -		q.w = track_w->def_val;
  21.611 -		return q;
  21.612 -	}
  21.613 -
  21.614 -	last_idx = track_x->count - 1;
  21.615 -
  21.616 -	tstart = track_x->keys[0].time;
  21.617 -	tend = track_x->keys[last_idx].time;
  21.618 -
  21.619 -	if(tstart == tend) {
  21.620 -		q.x = track_x->keys[0].val;
  21.621 -		q.y = track_y->keys[0].val;
  21.622 -		q.z = track_z->keys[0].val;
  21.623 -		q.w = track_w->keys[0].val;
  21.624 -		return q;
  21.625 -	}
  21.626 -
  21.627 -	tm = anm_remap_time(track_x, tm, tstart, tend);
  21.628 -
  21.629 -	idx0 = anm_get_key_interval(track_x, tm);
  21.630 -	assert(idx0 >= 0 && idx0 < track_x->count);
  21.631 -	idx1 = idx0 + 1;
  21.632 -
  21.633 -	if(idx0 == last_idx) {
  21.634 -		q.x = track_x->keys[idx0].val;
  21.635 -		q.y = track_y->keys[idx0].val;
  21.636 -		q.z = track_z->keys[idx0].val;
  21.637 -		q.w = track_w->keys[idx0].val;
  21.638 -		return q;
  21.639 -	}
  21.640 -
  21.641 -	dt = (float)(track_x->keys[idx1].time - track_x->keys[idx0].time);
  21.642 -	t = (float)(tm - track_x->keys[idx0].time) / dt;
  21.643 -
  21.644 -	q1.x = track_x->keys[idx0].val;
  21.645 -	q1.y = track_y->keys[idx0].val;
  21.646 -	q1.z = track_z->keys[idx0].val;
  21.647 -	q1.w = track_w->keys[idx0].val;
  21.648 -
  21.649 -	q2.x = track_x->keys[idx1].val;
  21.650 -	q2.y = track_y->keys[idx1].val;
  21.651 -	q2.z = track_z->keys[idx1].val;
  21.652 -	q2.w = track_w->keys[idx1].val;
  21.653 -
  21.654 -	/*q1 = quat_normalize(q1);
  21.655 -	q2 = quat_normalize(q2);*/
  21.656 -
  21.657 -	return quat_slerp(q1, q2, t);
  21.658 -#endif
  21.659 -}
  21.660 -
  21.661 -quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm)
  21.662 -{
  21.663 -	quat_t q;
  21.664 -	anm_time_t tm0 = animation_time(node, tm, 0);
  21.665 -	struct anm_animation *anim0 = anm_get_active_animation(node, 0);
  21.666 -	struct anm_animation *anim1 = anm_get_active_animation(node, 1);
  21.667 -
  21.668 -	if(!anim0) {
  21.669 -		return quat_identity();
  21.670 -	}
  21.671 -
  21.672 -	q = get_node_rotation(node, tm0, anim0);
  21.673 -
  21.674 -	if(anim1) {
  21.675 -		anm_time_t tm1 = animation_time(node, tm, 1);
  21.676 -		quat_t q1 = get_node_rotation(node, tm1, anim1);
  21.677 -
  21.678 -		q = quat_slerp(q, q1, node->cur_mix);
  21.679 -	}
  21.680 -	return q;
  21.681 -}
  21.682 -
  21.683 -void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm)
  21.684 -{
  21.685 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  21.686 -	if(!anim) return;
  21.687 -
  21.688 -	anm_set_value(anim->tracks + ANM_TRACK_SCL_X, tm, scl.x);
  21.689 -	anm_set_value(anim->tracks + ANM_TRACK_SCL_Y, tm, scl.y);
  21.690 -	anm_set_value(anim->tracks + ANM_TRACK_SCL_Z, tm, scl.z);
  21.691 -	invalidate_cache(node);
  21.692 -}
  21.693 -
  21.694 -vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm)
  21.695 -{
  21.696 -	vec3_t v;
  21.697 -	anm_time_t tm0 = animation_time(node, tm, 0);
  21.698 -	struct anm_animation *anim0 = anm_get_active_animation(node, 0);
  21.699 -	struct anm_animation *anim1 = anm_get_active_animation(node, 1);
  21.700 -
  21.701 -	if(!anim0) {
  21.702 -		return v3_cons(1, 1, 1);
  21.703 -	}
  21.704 -
  21.705 -	v.x = anm_get_value(anim0->tracks + ANM_TRACK_SCL_X, tm0);
  21.706 -	v.y = anm_get_value(anim0->tracks + ANM_TRACK_SCL_Y, tm0);
  21.707 -	v.z = anm_get_value(anim0->tracks + ANM_TRACK_SCL_Z, tm0);
  21.708 -
  21.709 -	if(anim1) {
  21.710 -		vec3_t v1;
  21.711 -		anm_time_t tm1 = animation_time(node, tm, 1);
  21.712 -		v1.x = anm_get_value(anim1->tracks + ANM_TRACK_SCL_X, tm1);
  21.713 -		v1.y = anm_get_value(anim1->tracks + ANM_TRACK_SCL_Y, tm1);
  21.714 -		v1.z = anm_get_value(anim1->tracks + ANM_TRACK_SCL_Z, tm1);
  21.715 -
  21.716 -		v.x = v.x + (v1.x - v.x) * node->cur_mix;
  21.717 -		v.y = v.y + (v1.y - v.y) * node->cur_mix;
  21.718 -		v.z = v.z + (v1.z - v.z) * node->cur_mix;
  21.719 -	}
  21.720 -
  21.721 -	return v;
  21.722 -}
  21.723 -
  21.724 -
  21.725 -vec3_t anm_get_position(struct anm_node *node, anm_time_t tm)
  21.726 -{
  21.727 -	mat4_t xform;
  21.728 -	vec3_t pos = {0.0, 0.0, 0.0};
  21.729 -
  21.730 -	if(!node->parent) {
  21.731 -		return anm_get_node_position(node, tm);
  21.732 -	}
  21.733 -
  21.734 -	anm_get_matrix(node, xform, tm);
  21.735 -	return v3_transform(pos, xform);
  21.736 -}
  21.737 -
  21.738 -quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm)
  21.739 -{
  21.740 -	quat_t rot, prot;
  21.741 -	rot = anm_get_node_rotation(node, tm);
  21.742 -
  21.743 -	if(!node->parent) {
  21.744 -		return rot;
  21.745 -	}
  21.746 -
  21.747 -	prot = anm_get_rotation(node->parent, tm);
  21.748 -	return quat_mul(prot, rot);
  21.749 -}
  21.750 -
  21.751 -vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm)
  21.752 -{
  21.753 -	vec3_t s, ps;
  21.754 -	s = anm_get_node_scaling(node, tm);
  21.755 -
  21.756 -	if(!node->parent) {
  21.757 -		return s;
  21.758 -	}
  21.759 -
  21.760 -	ps = anm_get_scaling(node->parent, tm);
  21.761 -	return v3_mul(s, ps);
  21.762 -}
  21.763 -
  21.764 -void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  21.765 -{
  21.766 -	int i;
  21.767 -	mat4_t rmat;
  21.768 -	vec3_t pos, scale;
  21.769 -	quat_t rot;
  21.770 -
  21.771 -	pos = anm_get_node_position(node, tm);
  21.772 -	rot = anm_get_node_rotation(node, tm);
  21.773 -	scale = anm_get_node_scaling(node, tm);
  21.774 -
  21.775 -	m4_set_translation(mat, node->pivot.x, node->pivot.y, node->pivot.z);
  21.776 -
  21.777 -	quat_to_mat4(rmat, rot);
  21.778 -	for(i=0; i<3; i++) {
  21.779 -		mat[i][0] = rmat[i][0];
  21.780 -		mat[i][1] = rmat[i][1];
  21.781 -		mat[i][2] = rmat[i][2];
  21.782 -	}
  21.783 -	/* this loop is equivalent to: m4_mult(mat, mat, rmat); */
  21.784 -
  21.785 -	mat[0][0] *= scale.x; mat[0][1] *= scale.y; mat[0][2] *= scale.z; mat[0][3] += pos.x;
  21.786 -	mat[1][0] *= scale.x; mat[1][1] *= scale.y; mat[1][2] *= scale.z; mat[1][3] += pos.y;
  21.787 -	mat[2][0] *= scale.x; mat[2][1] *= scale.y; mat[2][2] *= scale.z; mat[2][3] += pos.z;
  21.788 -
  21.789 -	m4_translate(mat, -node->pivot.x, -node->pivot.y, -node->pivot.z);
  21.790 -
  21.791 -	/* that's basically: pivot * rotation * translation * scaling * -pivot */
  21.792 -}
  21.793 -
  21.794 -void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  21.795 -{
  21.796 -	mat4_t tmp;
  21.797 -	anm_get_node_matrix(node, tmp, tm);
  21.798 -	m4_inverse(mat, tmp);
  21.799 -}
  21.800 -
  21.801 -void anm_eval_node(struct anm_node *node, anm_time_t tm)
  21.802 -{
  21.803 -	anm_get_node_matrix(node, node->matrix, tm);
  21.804 -}
  21.805 -
  21.806 -void anm_eval(struct anm_node *node, anm_time_t tm)
  21.807 -{
  21.808 -	struct anm_node *c;
  21.809 -
  21.810 -	anm_eval_node(node, tm);
  21.811 -
  21.812 -	if(node->parent) {
  21.813 -		/* due to post-order traversal, the parent matrix is already evaluated */
  21.814 -		m4_mult(node->matrix, node->parent->matrix, node->matrix);
  21.815 -	}
  21.816 -
  21.817 -	/* recersively evaluate all children */
  21.818 -	c = node->child;
  21.819 -	while(c) {
  21.820 -		anm_eval(c, tm);
  21.821 -		c = c->next;
  21.822 -	}
  21.823 -}
  21.824 -
  21.825 -void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  21.826 -{
  21.827 -	struct mat_cache *cache = pthread_getspecific(node->cache_key);
  21.828 -	if(!cache) {
  21.829 -		cache = malloc(sizeof *cache);
  21.830 -		assert(cache);
  21.831 -
  21.832 -		pthread_mutex_lock(&node->cache_list_lock);
  21.833 -		cache->next = node->cache_list;
  21.834 -		node->cache_list = cache;
  21.835 -		pthread_mutex_unlock(&node->cache_list_lock);
  21.836 -
  21.837 -		cache->time = ANM_TIME_INVAL;
  21.838 -		cache->inv_time = ANM_TIME_INVAL;
  21.839 -		pthread_setspecific(node->cache_key, cache);
  21.840 -	}
  21.841 -
  21.842 -	if(cache->time != tm) {
  21.843 -		anm_get_node_matrix(node, cache->matrix, tm);
  21.844 -
  21.845 -		if(node->parent) {
  21.846 -			mat4_t parent_mat;
  21.847 -
  21.848 -			anm_get_matrix(node->parent, parent_mat, tm);
  21.849 -			m4_mult(cache->matrix, parent_mat, cache->matrix);
  21.850 -		}
  21.851 -		cache->time = tm;
  21.852 -	}
  21.853 -	m4_copy(mat, cache->matrix);
  21.854 -}
  21.855 -
  21.856 -void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  21.857 -{
  21.858 -	struct mat_cache *cache = pthread_getspecific(node->cache_key);
  21.859 -	if(!cache) {
  21.860 -		cache = malloc(sizeof *cache);
  21.861 -		assert(cache);
  21.862 -
  21.863 -		pthread_mutex_lock(&node->cache_list_lock);
  21.864 -		cache->next = node->cache_list;
  21.865 -		node->cache_list = cache;
  21.866 -		pthread_mutex_unlock(&node->cache_list_lock);
  21.867 -
  21.868 -		cache->inv_time = ANM_TIME_INVAL;
  21.869 -		cache->inv_time = ANM_TIME_INVAL;
  21.870 -		pthread_setspecific(node->cache_key, cache);
  21.871 -	}
  21.872 -
  21.873 -	if(cache->inv_time != tm) {
  21.874 -		anm_get_matrix(node, mat, tm);
  21.875 -		m4_inverse(cache->inv_matrix, mat);
  21.876 -		cache->inv_time = tm;
  21.877 -	}
  21.878 -	m4_copy(mat, cache->inv_matrix);
  21.879 -}
  21.880 -
  21.881 -anm_time_t anm_get_start_time(struct anm_node *node)
  21.882 -{
  21.883 -	int i, j;
  21.884 -	struct anm_node *c;
  21.885 -	anm_time_t res = LONG_MAX;
  21.886 -
  21.887 -	for(j=0; j<2; j++) {
  21.888 -		struct anm_animation *anim = anm_get_active_animation(node, j);
  21.889 -		if(!anim) break;
  21.890 -
  21.891 -		for(i=0; i<ANM_NUM_TRACKS; i++) {
  21.892 -			if(anim->tracks[i].count) {
  21.893 -				anm_time_t tm = anim->tracks[i].keys[0].time;
  21.894 -				if(tm < res) {
  21.895 -					res = tm;
  21.896 -				}
  21.897 -			}
  21.898 -		}
  21.899 -	}
  21.900 -
  21.901 -	c = node->child;
  21.902 -	while(c) {
  21.903 -		anm_time_t tm = anm_get_start_time(c);
  21.904 -		if(tm < res) {
  21.905 -			res = tm;
  21.906 -		}
  21.907 -		c = c->next;
  21.908 -	}
  21.909 -	return res;
  21.910 -}
  21.911 -
  21.912 -anm_time_t anm_get_end_time(struct anm_node *node)
  21.913 -{
  21.914 -	int i, j;
  21.915 -	struct anm_node *c;
  21.916 -	anm_time_t res = LONG_MIN;
  21.917 -
  21.918 -	for(j=0; j<2; j++) {
  21.919 -		struct anm_animation *anim = anm_get_active_animation(node, j);
  21.920 -		if(!anim) break;
  21.921 -
  21.922 -		for(i=0; i<ANM_NUM_TRACKS; i++) {
  21.923 -			if(anim->tracks[i].count) {
  21.924 -				anm_time_t tm = anim->tracks[i].keys[anim->tracks[i].count - 1].time;
  21.925 -				if(tm > res) {
  21.926 -					res = tm;
  21.927 -				}
  21.928 -			}
  21.929 -		}
  21.930 -	}
  21.931 -
  21.932 -	c = node->child;
  21.933 -	while(c) {
  21.934 -		anm_time_t tm = anm_get_end_time(c);
  21.935 -		if(tm > res) {
  21.936 -			res = tm;
  21.937 -		}
  21.938 -		c = c->next;
  21.939 -	}
  21.940 -	return res;
  21.941 -}
  21.942 -
  21.943 -static void invalidate_cache(struct anm_node *node)
  21.944 -{
  21.945 -	struct mat_cache *cache = pthread_getspecific(node->cache_key);
  21.946 -	if(cache) {
  21.947 -	   cache->time = cache->inv_time = ANM_TIME_INVAL;
  21.948 -	}
  21.949 -}
    22.1 --- a/libs/anim/anim.h	Thu Apr 17 08:50:36 2014 +0300
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,219 +0,0 @@
    22.4 -#ifndef LIBANIM_H_
    22.5 -#define LIBANIM_H_
    22.6 -
    22.7 -#include "config.h"
    22.8 -
    22.9 -#include <pthread.h>
   22.10 -
   22.11 -#include <vmath/vector.h>
   22.12 -#include <vmath/quat.h>
   22.13 -#include <vmath/matrix.h>
   22.14 -#include "track.h"
   22.15 -
   22.16 -enum {
   22.17 -	ANM_TRACK_POS_X,
   22.18 -	ANM_TRACK_POS_Y,
   22.19 -	ANM_TRACK_POS_Z,
   22.20 -
   22.21 -	ANM_TRACK_ROT_X,
   22.22 -	ANM_TRACK_ROT_Y,
   22.23 -	ANM_TRACK_ROT_Z,
   22.24 -	ANM_TRACK_ROT_W,
   22.25 -
   22.26 -	ANM_TRACK_SCL_X,
   22.27 -	ANM_TRACK_SCL_Y,
   22.28 -	ANM_TRACK_SCL_Z,
   22.29 -
   22.30 -	ANM_NUM_TRACKS
   22.31 -};
   22.32 -
   22.33 -struct anm_animation {
   22.34 -	char *name;
   22.35 -	struct anm_track tracks[ANM_NUM_TRACKS];
   22.36 -};
   22.37 -
   22.38 -struct anm_node {
   22.39 -	char *name;
   22.40 -
   22.41 -	int cur_anim[2];
   22.42 -	anm_time_t cur_anim_offset[2];
   22.43 -	float cur_mix;
   22.44 -
   22.45 -	/* high-level animation blending transition duration */
   22.46 -	anm_time_t blend_dur;
   22.47 -
   22.48 -	struct anm_animation *animations;
   22.49 -	vec3_t pivot;
   22.50 -
   22.51 -	/* matrix cache */
   22.52 -	struct mat_cache {
   22.53 -		mat4_t matrix, inv_matrix;
   22.54 -		anm_time_t time, inv_time;
   22.55 -		struct mat_cache *next;
   22.56 -	} *cache_list;
   22.57 -	pthread_key_t cache_key;
   22.58 -	pthread_mutex_t cache_list_lock;
   22.59 -
   22.60 -	/* matrix calculated by anm_eval functions (no locking, meant as a pre-pass) */
   22.61 -	mat4_t matrix;
   22.62 -
   22.63 -	struct anm_node *parent;
   22.64 -	struct anm_node *child;
   22.65 -	struct anm_node *next;
   22.66 -};
   22.67 -
   22.68 -#ifdef __cplusplus
   22.69 -extern "C" {
   22.70 -#endif
   22.71 -
   22.72 -int anm_init_animation(struct anm_animation *anim);
   22.73 -void anm_destroy_animation(struct anm_animation *anim);
   22.74 -
   22.75 -void anm_set_animation_name(struct anm_animation *anim, const char *name);
   22.76 -
   22.77 -
   22.78 -/* ---- node/hierarchy management ---- */
   22.79 -
   22.80 -/* node constructor and destructor */
   22.81 -int anm_init_node(struct anm_node *node);
   22.82 -void anm_destroy_node(struct anm_node *node);
   22.83 -
   22.84 -/* recursively destroy an animation node tree */
   22.85 -void anm_destroy_node_tree(struct anm_node *tree);
   22.86 -
   22.87 -/* helper functions to allocate/construct and destroy/free with
   22.88 - * a single call. They call anm_init_node and anm_destroy_node
   22.89 - * internally.
   22.90 - */
   22.91 -struct anm_node *anm_create_node(void);
   22.92 -void anm_free_node(struct anm_node *node);
   22.93 -
   22.94 -/* recursively destroy and free the nodes of a node tree */
   22.95 -void anm_free_node_tree(struct anm_node *tree);
   22.96 -
   22.97 -int anm_set_node_name(struct anm_node *node, const char *name);
   22.98 -const char *anm_get_node_name(struct anm_node *node);
   22.99 -
  22.100 -/* link and unlink nodes with parent/child relations */
  22.101 -void anm_link_node(struct anm_node *parent, struct anm_node *child);
  22.102 -int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
  22.103 -
  22.104 -void anm_set_pivot(struct anm_node *node, vec3_t pivot);
  22.105 -vec3_t anm_get_pivot(struct anm_node *node);
  22.106 -
  22.107 -/* ---- multiple animations and animation blending ---- */
  22.108 -
  22.109 -/* set active animation(s) */
  22.110 -int anm_use_node_animation(struct anm_node *node, int aidx);
  22.111 -int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t);
  22.112 -/* recursive variants */
  22.113 -int anm_use_animation(struct anm_node *node, int aidx);
  22.114 -int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t);
  22.115 -
  22.116 -/* set/get current animation offset(s) */
  22.117 -void anm_set_node_animation_offset(struct anm_node *node, anm_time_t offs, int which);
  22.118 -anm_time_t anm_get_animation_offset(const struct anm_node *node, int which);
  22.119 -/* recursive variant */
  22.120 -void anm_set_animation_offset(struct anm_node *node, anm_time_t offs, int which);
  22.121 -
  22.122 -/* returns the requested current animation index, which can be 0 or 1 */
  22.123 -int anm_get_active_animation_index(const struct anm_node *node, int which);
  22.124 -/* returns the requested current animation, which can be 0 or 1 */
  22.125 -struct anm_animation *anm_get_active_animation(const struct anm_node *node, int which);
  22.126 -float anm_get_active_animation_mix(const struct anm_node *node);
  22.127 -
  22.128 -int anm_get_animation_count(const struct anm_node *node);
  22.129 -
  22.130 -/* add/remove an animation to the specified node */
  22.131 -int anm_add_node_animation(struct anm_node *node);
  22.132 -int anm_remove_node_animation(struct anm_node *node, int idx);
  22.133 -
  22.134 -/* add/remove an animation to the specified node and all it's descendants */
  22.135 -int anm_add_animation(struct anm_node *node);
  22.136 -int anm_remove_animation(struct anm_node *node, int idx);
  22.137 -
  22.138 -struct anm_animation *anm_get_animation(struct anm_node *node, int idx);
  22.139 -struct anm_animation *anm_get_animation_by_name(struct anm_node *node, const char *name);
  22.140 -
  22.141 -int anm_find_animation(struct anm_node *node, const char *name);
  22.142 -
  22.143 -/* set the interpolator for the (first) currently active animation */
  22.144 -void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
  22.145 -/* set the extrapolator for the (first) currently active animation */
  22.146 -void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
  22.147 -
  22.148 -/* set the name of the currently active animation of this node only */
  22.149 -void anm_set_node_active_animation_name(struct anm_node *node, const char *name);
  22.150 -/* recursively set the name of the currently active animation for this node
  22.151 - * and all it's descendants */
  22.152 -void anm_set_active_animation_name(struct anm_node *node, const char *name);
  22.153 -/* get the name of the currently active animation of this node */
  22.154 -const char *anm_get_active_animation_name(struct anm_node *node);
  22.155 -
  22.156 -
  22.157 -/* ---- high level animation blending interface ---- */
  22.158 -/* XXX this convenience interface assumes monotonically increasing time values
  22.159 - *     in all subsequent calls to anm_get_* and anm_eval_* functions.
  22.160 - *
  22.161 - * anmidx: index of the animation to transition to
  22.162 - * start: when to start the transition
  22.163 - * dur: transition duration
  22.164 - *
  22.165 - * sets up a transition from the current animation (cur_anim[0]) to another animation.
  22.166 - * at time start + dur, the transition will be completed, cur_anim[0] will be the new
  22.167 - * animation and cur_anim_offset[0] will be equal to start.
  22.168 - */
  22.169 -void anm_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur);
  22.170 -/* non-recursive variant, acts on a single node (you probably DON'T want to use this) */
  22.171 -void anm_node_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur);
  22.172 -
  22.173 -
  22.174 -/* ---- keyframes / PRS interpolation ---- */
  22.175 -
  22.176 -void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
  22.177 -vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
  22.178 -
  22.179 -void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
  22.180 -quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
  22.181 -
  22.182 -void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
  22.183 -vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
  22.184 -
  22.185 -/* these three return the full p/r/s taking hierarchy into account */
  22.186 -vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
  22.187 -quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
  22.188 -vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
  22.189 -
  22.190 -/* those return the start and end times of the whole tree */
  22.191 -anm_time_t anm_get_start_time(struct anm_node *node);
  22.192 -anm_time_t anm_get_end_time(struct anm_node *node);
  22.193 -
  22.194 -
  22.195 -/* ---- transformation matrices ---- */
  22.196 -
  22.197 -/* these calculate the matrix and inverse matrix of this node alone */
  22.198 -void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  22.199 -void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  22.200 -
  22.201 -/* ---- top-down matrix calculation interface ---- */
  22.202 -
  22.203 -/* calculate and set the matrix of this node */
  22.204 -void anm_eval_node(struct anm_node *node, anm_time_t tm);
  22.205 -/* calculate and set the matrix of this node and all its children recursively */
  22.206 -void anm_eval(struct anm_node *node, anm_time_t tm);
  22.207 -
  22.208 -
  22.209 -/* ---- bottom-up lazy matrix calculation interface ---- */
  22.210 -
  22.211 -/* These calculate the matrix and inverse matrix of this node taking hierarchy
  22.212 - * into account. The results are cached in thread-specific storage and returned
  22.213 - * if there's no change in time or tracks from the last query...
  22.214 - */
  22.215 -void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  22.216 -void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  22.217 -
  22.218 -#ifdef __cplusplus
  22.219 -}
  22.220 -#endif
  22.221 -
  22.222 -#endif	/* LIBANIM_H_ */
    23.1 --- a/libs/anim/config.h	Thu Apr 17 08:50:36 2014 +0300
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,6 +0,0 @@
    23.4 -#ifndef ANIM_CONFIG_H_
    23.5 -#define ANIM_CONFIG_H_
    23.6 -
    23.7 -#undef ANIM_THREAD_SAFE
    23.8 -
    23.9 -#endif	/* ANIM_CONFIG_H_ */
    24.1 --- a/libs/anim/dynarr.c	Thu Apr 17 08:50:36 2014 +0300
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,122 +0,0 @@
    24.4 -#include <stdio.h>
    24.5 -#include <stdlib.h>
    24.6 -#include <string.h>
    24.7 -#include "dynarr.h"
    24.8 -
    24.9 -/* The array descriptor keeps auxilliary information needed to manipulate
   24.10 - * the dynamic array. It's allocated adjacent to the array buffer.
   24.11 - */
   24.12 -struct arrdesc {
   24.13 -	int nelem, szelem;
   24.14 -	int max_elem;
   24.15 -	int bufsz;	/* not including the descriptor */
   24.16 -};
   24.17 -
   24.18 -#define DESC(x)		((struct arrdesc*)((char*)(x) - sizeof(struct arrdesc)))
   24.19 -
   24.20 -void *dynarr_alloc(int elem, int szelem)
   24.21 -{
   24.22 -	struct arrdesc *desc;
   24.23 -
   24.24 -	if(!(desc = malloc(elem * szelem + sizeof *desc))) {
   24.25 -		return 0;
   24.26 -	}
   24.27 -	desc->nelem = desc->max_elem = elem;
   24.28 -	desc->szelem = szelem;
   24.29 -	desc->bufsz = elem * szelem;
   24.30 -	return (char*)desc + sizeof *desc;
   24.31 -}
   24.32 -
   24.33 -void dynarr_free(void *da)
   24.34 -{
   24.35 -	if(da) {
   24.36 -		free(DESC(da));
   24.37 -	}
   24.38 -}
   24.39 -
   24.40 -void *dynarr_resize(void *da, int elem)
   24.41 -{
   24.42 -	int newsz;
   24.43 -	void *tmp;
   24.44 -	struct arrdesc *desc;
   24.45 -
   24.46 -	if(!da) return 0;
   24.47 -	desc = DESC(da);
   24.48 -
   24.49 -	newsz = desc->szelem * elem;
   24.50 -
   24.51 -	if(!(tmp = realloc(desc, newsz + sizeof *desc))) {
   24.52 -		return 0;
   24.53 -	}
   24.54 -	desc = tmp;
   24.55 -
   24.56 -	desc->nelem = desc->max_elem = elem;
   24.57 -	desc->bufsz = newsz;
   24.58 -	return (char*)desc + sizeof *desc;
   24.59 -}
   24.60 -
   24.61 -int dynarr_empty(void *da)
   24.62 -{
   24.63 -	return DESC(da)->nelem ? 0 : 1;
   24.64 -}
   24.65 -
   24.66 -int dynarr_size(void *da)
   24.67 -{
   24.68 -	return DESC(da)->nelem;
   24.69 -}
   24.70 -
   24.71 -
   24.72 -/* stack semantics */
   24.73 -void *dynarr_push(void *da, void *item)
   24.74 -{
   24.75 -	struct arrdesc *desc;
   24.76 -	int nelem;
   24.77 -
   24.78 -	desc = DESC(da);
   24.79 -	nelem = desc->nelem;
   24.80 -
   24.81 -	if(nelem >= desc->max_elem) {
   24.82 -		/* need to resize */
   24.83 -		struct arrdesc *tmp;
   24.84 -		int newsz = desc->max_elem ? desc->max_elem * 2 : 1;
   24.85 -
   24.86 -		if(!(tmp = dynarr_resize(da, newsz))) {
   24.87 -			fprintf(stderr, "failed to resize\n");
   24.88 -			return da;
   24.89 -		}
   24.90 -		da = tmp;
   24.91 -		desc = DESC(da);
   24.92 -		desc->nelem = nelem;
   24.93 -	}
   24.94 -
   24.95 -	memcpy((char*)da + desc->nelem++ * desc->szelem, item, desc->szelem);
   24.96 -	return da;
   24.97 -}
   24.98 -
   24.99 -void *dynarr_pop(void *da)
  24.100 -{
  24.101 -	struct arrdesc *desc;
  24.102 -	int nelem;
  24.103 -
  24.104 -	desc = DESC(da);
  24.105 -	nelem = desc->nelem;
  24.106 -
  24.107 -	if(!nelem) return da;
  24.108 -
  24.109 -	if(nelem <= desc->max_elem / 3) {
  24.110 -		/* reclaim space */
  24.111 -		struct arrdesc *tmp;
  24.112 -		int newsz = desc->max_elem / 2;
  24.113 -
  24.114 -		if(!(tmp = dynarr_resize(da, newsz))) {
  24.115 -			fprintf(stderr, "failed to resize\n");
  24.116 -			return da;
  24.117 -		}
  24.118 -		da = tmp;
  24.119 -		desc = DESC(da);
  24.120 -		desc->nelem = nelem;
  24.121 -	}
  24.122 -	desc->nelem--;
  24.123 -
  24.124 -	return da;
  24.125 -}
    25.1 --- a/libs/anim/dynarr.h	Thu Apr 17 08:50:36 2014 +0300
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,16 +0,0 @@
    25.4 -#ifndef DYNARR_H_
    25.5 -#define DYNARR_H_
    25.6 -
    25.7 -void *dynarr_alloc(int elem, int szelem);
    25.8 -void dynarr_free(void *da);
    25.9 -void *dynarr_resize(void *da, int elem);
   25.10 -
   25.11 -int dynarr_empty(void *da);
   25.12 -int dynarr_size(void *da);
   25.13 -
   25.14 -/* stack semantics */
   25.15 -void *dynarr_push(void *da, void *item);
   25.16 -void *dynarr_pop(void *da);
   25.17 -
   25.18 -
   25.19 -#endif	/* DYNARR_H_ */
    26.1 --- a/libs/anim/track.c	Thu Apr 17 08:50:36 2014 +0300
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,316 +0,0 @@
    26.4 -#include <stdlib.h>
    26.5 -#include <string.h>
    26.6 -#include <assert.h>
    26.7 -#include "track.h"
    26.8 -#include "dynarr.h"
    26.9 -
   26.10 -static int keycmp(const void *a, const void *b);
   26.11 -static int find_prev_key(struct anm_keyframe *arr, int start, int end, anm_time_t tm);
   26.12 -
   26.13 -static float interp_step(float v0, float v1, float v2, float v3, float t);
   26.14 -static float interp_linear(float v0, float v1, float v2, float v3, float t);
   26.15 -static float interp_cubic(float v0, float v1, float v2, float v3, float t);
   26.16 -
   26.17 -static anm_time_t remap_extend(anm_time_t tm, anm_time_t start, anm_time_t end);
   26.18 -static anm_time_t remap_clamp(anm_time_t tm, anm_time_t start, anm_time_t end);
   26.19 -static anm_time_t remap_repeat(anm_time_t tm, anm_time_t start, anm_time_t end);
   26.20 -static anm_time_t remap_pingpong(anm_time_t tm, anm_time_t start, anm_time_t end);
   26.21 -
   26.22 -/* XXX keep this in sync with enum anm_interpolator at track.h */
   26.23 -static float (*interp[])(float, float, float, float, float) = {
   26.24 -	interp_step,
   26.25 -	interp_linear,
   26.26 -	interp_cubic,
   26.27 -	0
   26.28 -};
   26.29 -
   26.30 -/* XXX keep this in sync with enum anm_extrapolator at track.h */
   26.31 -static anm_time_t (*remap_time[])(anm_time_t, anm_time_t, anm_time_t) = {
   26.32 -	remap_extend,
   26.33 -	remap_clamp,
   26.34 -	remap_repeat,
   26.35 -	remap_pingpong,
   26.36 -	0
   26.37 -};
   26.38 -
   26.39 -int anm_init_track(struct anm_track *track)
   26.40 -{
   26.41 -	memset(track, 0, sizeof *track);
   26.42 -
   26.43 -	if(!(track->keys = dynarr_alloc(0, sizeof *track->keys))) {
   26.44 -		return -1;
   26.45 -	}
   26.46 -	track->interp = ANM_INTERP_LINEAR;
   26.47 -	track->extrap = ANM_EXTRAP_CLAMP;
   26.48 -	return 0;
   26.49 -}
   26.50 -
   26.51 -void anm_destroy_track(struct anm_track *track)
   26.52 -{
   26.53 -	dynarr_free(track->keys);
   26.54 -}
   26.55 -
   26.56 -struct anm_track *anm_create_track(void)
   26.57 -{
   26.58 -	struct anm_track *track;
   26.59 -
   26.60 -	if((track = malloc(sizeof *track))) {
   26.61 -		if(anm_init_track(track) == -1) {
   26.62 -			free(track);
   26.63 -			return 0;
   26.64 -		}
   26.65 -	}
   26.66 -	return track;
   26.67 -}
   26.68 -
   26.69 -void anm_free_track(struct anm_track *track)
   26.70 -{
   26.71 -	anm_destroy_track(track);
   26.72 -	free(track);
   26.73 -}
   26.74 -
   26.75 -void anm_copy_track(struct anm_track *dest, const struct anm_track *src)
   26.76 -{
   26.77 -	free(dest->name);
   26.78 -	if(dest->keys) {
   26.79 -		dynarr_free(dest->keys);
   26.80 -	}
   26.81 -
   26.82 -	if(src->name) {
   26.83 -		dest->name = malloc(strlen(src->name) + 1);
   26.84 -		strcpy(dest->name, src->name);
   26.85 -	}
   26.86 -
   26.87 -	dest->count = src->count;
   26.88 -	dest->keys = dynarr_alloc(src->count, sizeof *dest->keys);
   26.89 -	memcpy(dest->keys, src->keys, src->count * sizeof *dest->keys);
   26.90 -
   26.91 -	dest->def_val = src->def_val;
   26.92 -	dest->interp = src->interp;
   26.93 -	dest->extrap = src->extrap;
   26.94 -}
   26.95 -
   26.96 -int anm_set_track_name(struct anm_track *track, const char *name)
   26.97 -{
   26.98 -	char *tmp;
   26.99 -
  26.100 -	if(!(tmp = malloc(strlen(name) + 1))) {
  26.101 -		return -1;
  26.102 -	}
  26.103 -	free(track->name);
  26.104 -	track->name = tmp;
  26.105 -	return 0;
  26.106 -}
  26.107 -
  26.108 -const char *anm_get_track_name(struct anm_track *track)
  26.109 -{
  26.110 -	return track->name;
  26.111 -}
  26.112 -
  26.113 -void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in)
  26.114 -{
  26.115 -	track->interp = in;
  26.116 -}
  26.117 -
  26.118 -void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex)
  26.119 -{
  26.120 -	track->extrap = ex;
  26.121 -}
  26.122 -
  26.123 -anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end)
  26.124 -{
  26.125 -	return remap_time[track->extrap](tm, start, end);
  26.126 -}
  26.127 -
  26.128 -void anm_set_track_default(struct anm_track *track, float def)
  26.129 -{
  26.130 -	track->def_val = def;
  26.131 -}
  26.132 -
  26.133 -int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key)
  26.134 -{
  26.135 -	int idx = anm_get_key_interval(track, key->time);
  26.136 -
  26.137 -	/* if we got a valid keyframe index, compare them... */
  26.138 -	if(idx >= 0 && idx < track->count && keycmp(key, track->keys + idx) == 0) {
  26.139 -		/* ... it's the same key, just update the value */
  26.140 -		track->keys[idx].val = key->val;
  26.141 -	} else {
  26.142 -		/* ... it's a new key, add it and re-sort them */
  26.143 -		void *tmp;
  26.144 -		if(!(tmp = dynarr_push(track->keys, key))) {
  26.145 -			return -1;
  26.146 -		}
  26.147 -		track->keys = tmp;
  26.148 -		/* TODO lazy qsort */
  26.149 -		qsort(track->keys, ++track->count, sizeof *track->keys, keycmp);
  26.150 -	}
  26.151 -	return 0;
  26.152 -}
  26.153 -
  26.154 -static int keycmp(const void *a, const void *b)
  26.155 -{
  26.156 -	return ((struct anm_keyframe*)a)->time - ((struct anm_keyframe*)b)->time;
  26.157 -}
  26.158 -
  26.159 -struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx)
  26.160 -{
  26.161 -	if(idx < 0 || idx >= track->count) {
  26.162 -		return 0;
  26.163 -	}
  26.164 -	return track->keys + idx;
  26.165 -}
  26.166 -
  26.167 -int anm_get_key_interval(struct anm_track *track, anm_time_t tm)
  26.168 -{
  26.169 -	int last;
  26.170 -
  26.171 -	if(!track->count || tm < track->keys[0].time) {
  26.172 -		return -1;
  26.173 -	}
  26.174 -
  26.175 -	last = track->count - 1;
  26.176 -	if(tm > track->keys[last].time) {
  26.177 -		return last;
  26.178 -	}
  26.179 -
  26.180 -	return find_prev_key(track->keys, 0, last, tm);
  26.181 -}
  26.182 -
  26.183 -static int find_prev_key(struct anm_keyframe *arr, int start, int end, anm_time_t tm)
  26.184 -{
  26.185 -	int mid;
  26.186 -
  26.187 -	if(end - start <= 1) {
  26.188 -		return start;
  26.189 -	}
  26.190 -
  26.191 -	mid = (start + end) / 2;
  26.192 -	if(tm < arr[mid].time) {
  26.193 -		return find_prev_key(arr, start, mid, tm);
  26.194 -	}
  26.195 -	if(tm > arr[mid].time) {
  26.196 -		return find_prev_key(arr, mid, end, tm);
  26.197 -	}
  26.198 -	return mid;
  26.199 -}
  26.200 -
  26.201 -int anm_set_value(struct anm_track *track, anm_time_t tm, float val)
  26.202 -{
  26.203 -	struct anm_keyframe key;
  26.204 -	key.time = tm;
  26.205 -	key.val = val;
  26.206 -
  26.207 -	return anm_set_keyframe(track, &key);
  26.208 -}
  26.209 -
  26.210 -float anm_get_value(struct anm_track *track, anm_time_t tm)
  26.211 -{
  26.212 -	int idx0, idx1, last_idx;
  26.213 -	anm_time_t tstart, tend;
  26.214 -	float t, dt;
  26.215 -	float v0, v1, v2, v3;
  26.216 -
  26.217 -	if(!track->count) {
  26.218 -		return track->def_val;
  26.219 -	}
  26.220 -
  26.221 -	last_idx = track->count - 1;
  26.222 -
  26.223 -	tstart = track->keys[0].time;
  26.224 -	tend = track->keys[last_idx].time;
  26.225 -
  26.226 -	if(tstart == tend) {
  26.227 -		return track->keys[0].val;
  26.228 -	}
  26.229 -
  26.230 -	tm = remap_time[track->extrap](tm, tstart, tend);
  26.231 -
  26.232 -	idx0 = anm_get_key_interval(track, tm);
  26.233 -	assert(idx0 >= 0 && idx0 < track->count);
  26.234 -	idx1 = idx0 + 1;
  26.235 -
  26.236 -	if(idx0 == last_idx) {
  26.237 -		return track->keys[idx0].val;
  26.238 -	}
  26.239 -
  26.240 -	dt = (float)(track->keys[idx1].time - track->keys[idx0].time);
  26.241 -	t = (float)(tm - track->keys[idx0].time) / dt;
  26.242 -
  26.243 -	v1 = track->keys[idx0].val;
  26.244 -	v2 = track->keys[idx1].val;
  26.245 -
  26.246 -	/* get the neigboring values to allow for cubic interpolation */
  26.247 -	v0 = idx0 > 0 ? track->keys[idx0 - 1].val : v1;
  26.248 -	v3 = idx1 < last_idx ? track->keys[idx1 + 1].val : v2;
  26.249 -
  26.250 -	return interp[track->interp](v0, v1, v2, v3, t);
  26.251 -}
  26.252 -
  26.253 -
  26.254 -static float interp_step(float v0, float v1, float v2, float v3, float t)
  26.255 -{
  26.256 -	return v1;
  26.257 -}
  26.258 -
  26.259 -static float interp_linear(float v0, float v1, float v2, float v3, float t)
  26.260 -{
  26.261 -	return v1 + (v2 - v1) * t;
  26.262 -}
  26.263 -
  26.264 -static float interp_cubic(float a, float b, float c, float d, float t)
  26.265 -{
  26.266 -	float x, y, z, w;
  26.267 -	float tsq = t * t;
  26.268 -
  26.269 -	x = -a + 3.0 * b - 3.0 * c + d;
  26.270 -	y = 2.0 * a - 5.0 * b + 4.0 * c - d;
  26.271 -	z = c - a;
  26.272 -	w = 2.0 * b;
  26.273 -
  26.274 -	return 0.5 * (x * tsq * t + y * tsq + z * t + w);
  26.275 -}
  26.276 -
  26.277 -static anm_time_t remap_extend(anm_time_t tm, anm_time_t start, anm_time_t end)
  26.278 -{
  26.279 -	return remap_repeat(tm, start, end);
  26.280 -}
  26.281 -
  26.282 -static anm_time_t remap_clamp(anm_time_t tm, anm_time_t start, anm_time_t end)
  26.283 -{
  26.284 -	if(start == end) {
  26.285 -		return start;
  26.286 -	}
  26.287 -	return tm < start ? start : (tm >= end ? end - 1 : tm);
  26.288 -}
  26.289 -
  26.290 -static anm_time_t remap_repeat(anm_time_t tm, anm_time_t start, anm_time_t end)
  26.291 -{
  26.292 -	anm_time_t x, interv = end - start;
  26.293 -
  26.294 -	if(interv == 0) {
  26.295 -		return start;
  26.296 -	}
  26.297 -
  26.298 -	x = (tm - start) % interv;
  26.299 -	if(x < 0) {
  26.300 -		x += interv;
  26.301 -	}
  26.302 -	return x + start;
  26.303 -
  26.304 -	/*if(tm < start) {
  26.305 -		while(tm < start) {
  26.306 -			tm += interv;
  26.307 -		}
  26.308 -		return tm;
  26.309 -	}
  26.310 -	return (tm - start) % interv + start;*/
  26.311 -}
  26.312 -
  26.313 -static anm_time_t remap_pingpong(anm_time_t tm, anm_time_t start, anm_time_t end)
  26.314 -{
  26.315 -	anm_time_t interv = end - start;
  26.316 -	anm_time_t x = remap_repeat(tm, start, end + interv);
  26.317 -
  26.318 -	return x > end ? end + interv - x : x;
  26.319 -}
    27.1 --- a/libs/anim/track.h	Thu Apr 17 08:50:36 2014 +0300
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,101 +0,0 @@
    27.4 -/* An animation track defines the values of a single scalar over time
    27.5 - * and supports various interpolation and extrapolation modes.
    27.6 - */
    27.7 -#ifndef LIBANIM_TRACK_H_
    27.8 -#define LIBANIM_TRACK_H_
    27.9 -
   27.10 -#include <limits.h>
   27.11 -#include "config.h"
   27.12 -
   27.13 -enum anm_interpolator {
   27.14 -	ANM_INTERP_STEP,
   27.15 -	ANM_INTERP_LINEAR,
   27.16 -	ANM_INTERP_CUBIC
   27.17 -};
   27.18 -
   27.19 -enum anm_extrapolator {
   27.20 -	ANM_EXTRAP_EXTEND,	/* extend to infinity */
   27.21 -	ANM_EXTRAP_CLAMP,	/* clamp to last value */
   27.22 -	ANM_EXTRAP_REPEAT,	/* repeat motion */
   27.23 -	ANM_EXTRAP_PINGPONG	/* repeat with mirroring */
   27.24 -};
   27.25 -
   27.26 -typedef long anm_time_t;
   27.27 -#define ANM_TIME_INVAL	LONG_MIN
   27.28 -
   27.29 -#define ANM_SEC2TM(x)	((anm_time_t)((x) * 1000))
   27.30 -#define ANM_MSEC2TM(x)	((anm_time_t)(x))
   27.31 -#define ANM_TM2SEC(x)	((x) / 1000.0)
   27.32 -#define ANM_TM2MSEC(x)	(x)
   27.33 -
   27.34 -struct anm_keyframe {
   27.35 -	anm_time_t time;
   27.36 -	float val;
   27.37 -};
   27.38 -
   27.39 -struct anm_track {
   27.40 -	char *name;
   27.41 -	int count;
   27.42 -	struct anm_keyframe *keys;
   27.43 -
   27.44 -	float def_val;
   27.45 -
   27.46 -	enum anm_interpolator interp;
   27.47 -	enum anm_extrapolator extrap;
   27.48 -};
   27.49 -
   27.50 -#ifdef __cplusplus
   27.51 -extern "C" {
   27.52 -#endif
   27.53 -
   27.54 -/* track constructor and destructor */
   27.55 -int anm_init_track(struct anm_track *track);
   27.56 -void anm_destroy_track(struct anm_track *track);
   27.57 -
   27.58 -/* helper functions that use anm_init_track and anm_destroy_track internally */
   27.59 -struct anm_track *anm_create_track(void);
   27.60 -void anm_free_track(struct anm_track *track);
   27.61 -
   27.62 -/* copies track src to dest
   27.63 - * XXX: dest must have been initialized first
   27.64 - */
   27.65 -void anm_copy_track(struct anm_track *dest, const struct anm_track *src);
   27.66 -
   27.67 -int anm_set_track_name(struct anm_track *track, const char *name);
   27.68 -const char *anm_get_track_name(struct anm_track *track);
   27.69 -
   27.70 -void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
   27.71 -void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
   27.72 -
   27.73 -anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
   27.74 -
   27.75 -void anm_set_track_default(struct anm_track *track, float def);
   27.76 -
   27.77 -/* set or update a keyframe */
   27.78 -int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
   27.79 -
   27.80 -/* get the idx-th keyframe, returns null if it doesn't exist */
   27.81 -struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
   27.82 -
   27.83 -/* Finds the 0-based index of the intra-keyframe interval which corresponds
   27.84 - * to the specified time. If the time falls exactly onto the N-th keyframe
   27.85 - * the function returns N.
   27.86 - *
   27.87 - * Special cases:
   27.88 - * - if the time is before the first keyframe -1 is returned.
   27.89 - * - if the time is after the last keyframe, the index of the last keyframe
   27.90 - *   is returned.
   27.91 - */
   27.92 -int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
   27.93 -
   27.94 -int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
   27.95 -
   27.96 -/* evaluates and returns the value of the track for a particular time */
   27.97 -float anm_get_value(struct anm_track *track, anm_time_t tm);
   27.98 -
   27.99 -#ifdef __cplusplus
  27.100 -}
  27.101 -#endif
  27.102 -
  27.103 -
  27.104 -#endif	/* LIBANIM_TRACK_H_ */
    28.1 --- a/libs/vmath/Makefile	Thu Apr 17 08:50:36 2014 +0300
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,18 +0,0 @@
    28.4 -csrc = $(wildcard *.c)
    28.5 -ccsrc = $(wildcard *.cc)
    28.6 -obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)
    28.7 -lib = libvmath.a
    28.8 -
    28.9 -ifneq ($(shell uname -s), Darwin)
   28.10 -	pic = -fPIC
   28.11 -endif
   28.12 -
   28.13 -CFLAGS = -pedantic -Wall -g $(pic)
   28.14 -CXXFLAGS = -pedantic -Wall -g $(pic)
   28.15 -
   28.16 -$(lib): $(obj)
   28.17 -	$(AR) rcs $@ $(obj)
   28.18 -
   28.19 -.PHONY: clean
   28.20 -clean:
   28.21 -	rm -f $(obj) $(lib)
    29.1 --- a/libs/vmath/basis.cc	Thu Apr 17 08:50:36 2014 +0300
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,63 +0,0 @@
    29.4 -#include "basis.h"
    29.5 -#include "vmath.h"
    29.6 -
    29.7 -Basis::Basis()
    29.8 -{
    29.9 -	i = Vector3(1, 0, 0);
   29.10 -	j = Vector3(0, 1, 0);
   29.11 -	k = Vector3(0, 0, 1);
   29.12 -}
   29.13 -
   29.14 -Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k)
   29.15 -{
   29.16 -	this->i = i;
   29.17 -	this->j = j;
   29.18 -	this->k = k;
   29.19 -}
   29.20 -
   29.21 -Basis::Basis(const Vector3 &dir, bool left_handed)
   29.22 -{
   29.23 -	k = dir;
   29.24 -	j = Vector3(0, 1, 0);
   29.25 -	i = cross_product(j, k);
   29.26 -	j = cross_product(k, i);
   29.27 -}
   29.28 -
   29.29 -/** Rotate with euler angles */
   29.30 -void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) {
   29.31 -	Matrix4x4 RotMat;
   29.32 -	RotMat.set_rotation(Vector3(x, y, z));
   29.33 -	i.transform(RotMat);
   29.34 -	j.transform(RotMat);
   29.35 -	k.transform(RotMat);
   29.36 -}
   29.37 -
   29.38 -/** Rotate by axis-angle specification */
   29.39 -void Basis::rotate(const Vector3 &axis, scalar_t angle) {
   29.40 -	Quaternion q;
   29.41 -	q.set_rotation(axis, angle);
   29.42 -	i.transform(q);
   29.43 -	j.transform(q);
   29.44 -	k.transform(q);
   29.45 -}
   29.46 -
   29.47 -/** Rotate with a 4x4 matrix */
   29.48 -void Basis::rotate(const Matrix4x4 &mat) {
   29.49 -	i.transform(mat);
   29.50 -	j.transform(mat);
   29.51 -	k.transform(mat);
   29.52 -}
   29.53 -
   29.54 -/** Rotate with a quaternion */
   29.55 -void Basis::rotate(const Quaternion &quat) {
   29.56 -	i.transform(quat);
   29.57 -	j.transform(quat);
   29.58 -	k.transform(quat);
   29.59 -}
   29.60 -
   29.61 -/** Extract a rotation matrix from the orthogonal basis */
   29.62 -Matrix3x3 Basis::create_rotation_matrix() const {
   29.63 -	return Matrix3x3(	i.x, j.x, k.x,
   29.64 -						i.y, j.y, k.y,
   29.65 -						i.z, j.z, k.z);
   29.66 -}
    30.1 --- a/libs/vmath/basis.h	Thu Apr 17 08:50:36 2014 +0300
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,57 +0,0 @@
    30.4 -/*
    30.5 -libvmath - a vector math library
    30.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    30.7 -
    30.8 -This program is free software: you can redistribute it and/or modify
    30.9 -it under the terms of the GNU Lesser General Public License as published
   30.10 -by the Free Software Foundation, either version 3 of the License, or
   30.11 -(at your option) any later version.
   30.12 -
   30.13 -This program is distributed in the hope that it will be useful,
   30.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   30.16 -GNU Lesser General Public License for more details.
   30.17 -
   30.18 -You should have received a copy of the GNU Lesser General Public License
   30.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   30.20 -*/
   30.21 -
   30.22 -#ifndef VMATH_BASIS_H_
   30.23 -#define VMATH_BASIS_H_
   30.24 -
   30.25 -#include "vector.h"
   30.26 -#include "matrix.h"
   30.27 -
   30.28 -enum {
   30.29 -	LEFT_HANDED,
   30.30 -	RIGHT_HANDED
   30.31 -};
   30.32 -
   30.33 -#ifdef __cplusplus
   30.34 -extern "C" {
   30.35 -#endif	/* __cplusplus */
   30.36 -
   30.37 -void basis_matrix(mat4_t res, vec3_t i, vec3_t j, vec3_t k);
   30.38 -void basis_matrix_dir(mat4_t res, vec3_t dir);
   30.39 -
   30.40 -#ifdef __cplusplus
   30.41 -}	/* extern "C" */
   30.42 -
   30.43 -class Basis {
   30.44 -public:
   30.45 -	Vector3 i, j, k;
   30.46 -
   30.47 -	Basis();
   30.48 -	Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k);
   30.49 -	Basis(const Vector3 &dir, bool left_handed = true);
   30.50 -
   30.51 -	void rotate(scalar_t x, scalar_t y, scalar_t z);
   30.52 -	void rotate(const Vector3 &axis, scalar_t angle);
   30.53 -	void rotate(const Matrix4x4 &mat);
   30.54 -	void rotate(const Quaternion &quat);
   30.55 -
   30.56 -	Matrix3x3 create_rotation_matrix() const;
   30.57 -};
   30.58 -#endif	/* __cplusplus */
   30.59 -
   30.60 -#endif	/* VMATH_BASIS_H_ */
    31.1 --- a/libs/vmath/basis_c.c	Thu Apr 17 08:50:36 2014 +0300
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,37 +0,0 @@
    31.4 -/*
    31.5 -libvmath - a vector math library
    31.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    31.7 -
    31.8 -This program is free software: you can redistribute it and/or modify
    31.9 -it under the terms of the GNU Lesser General Public License as published
   31.10 -by the Free Software Foundation, either version 3 of the License, or
   31.11 -(at your option) any later version.
   31.12 -
   31.13 -This program is distributed in the hope that it will be useful,
   31.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   31.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   31.16 -GNU Lesser General Public License for more details.
   31.17 -
   31.18 -You should have received a copy of the GNU Lesser General Public License
   31.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   31.20 -*/
   31.21 -
   31.22 -#include "basis.h"
   31.23 -#include "matrix.h"
   31.24 -
   31.25 -void basis_matrix(mat4_t res, vec3_t i, vec3_t j, vec3_t k)
   31.26 -{
   31.27 -	m4_identity(res);
   31.28 -	m4_set_column(res, v4_cons(i.x, i.y, i.z, 1.0), 0);
   31.29 -	m4_set_column(res, v4_cons(j.x, j.y, j.z, 1.0), 1);
   31.30 -	m4_set_column(res, v4_cons(k.x, k.y, k.z, 1.0), 2);
   31.31 -}
   31.32 -
   31.33 -void basis_matrix_dir(mat4_t res, vec3_t dir)
   31.34 -{
   31.35 -	vec3_t k = v3_normalize(dir);
   31.36 -	vec3_t j = {0, 1, 0};
   31.37 -	vec3_t i = v3_cross(j, k);
   31.38 -	j = v3_cross(k, i);
   31.39 -	basis_matrix(res, i, j, k);
   31.40 -}
    32.1 --- a/libs/vmath/geom.c	Thu Apr 17 08:50:36 2014 +0300
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,150 +0,0 @@
    32.4 -/*
    32.5 -libvmath - a vector math library
    32.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    32.7 -
    32.8 -This program is free software: you can redistribute it and/or modify
    32.9 -it under the terms of the GNU Lesser General Public License as published
   32.10 -by the Free Software Foundation, either version 3 of the License, or
   32.11 -(at your option) any later version.
   32.12 -
   32.13 -This program is distributed in the hope that it will be useful,
   32.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   32.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   32.16 -GNU Lesser General Public License for more details.
   32.17 -
   32.18 -You should have received a copy of the GNU Lesser General Public License
   32.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   32.20 -*/
   32.21 -
   32.22 -
   32.23 -#include <math.h>
   32.24 -#include "geom.h"
   32.25 -#include "vector.h"
   32.26 -
   32.27 -plane_t plane_cons(scalar_t nx, scalar_t ny, scalar_t nz, scalar_t d)
   32.28 -{
   32.29 -	plane_t p;
   32.30 -	p.norm.x = nx;
   32.31 -	p.norm.y = ny;
   32.32 -	p.norm.z = nz;
   32.33 -	p.d = d;
   32.34 -	return p;
   32.35 -}
   32.36 -
   32.37 -plane_t plane_poly(vec3_t v0, vec3_t v1, vec3_t v2)
   32.38 -{
   32.39 -	vec3_t a, b, norm;
   32.40 -
   32.41 -	a = v3_sub(v1, v0);
   32.42 -	b = v3_sub(v2, v0);
   32.43 -	norm = v3_cross(a, b);
   32.44 -	norm = v3_normalize(norm);
   32.45 -
   32.46 -	return plane_ptnorm(v0, norm);
   32.47 -}
   32.48 -
   32.49 -plane_t plane_ptnorm(vec3_t pt, vec3_t normal)
   32.50 -{
   32.51 -	plane_t plane;
   32.52 -
   32.53 -	plane.norm = normal;
   32.54 -	plane.d = v3_dot(pt, normal);
   32.55 -
   32.56 -	return plane;
   32.57 -}
   32.58 -
   32.59 -plane_t plane_invert(plane_t p)
   32.60 -{
   32.61 -	p.norm = v3_neg(p.norm);
   32.62 -	p.d = -p.d;
   32.63 -	return p;
   32.64 -}
   32.65 -
   32.66 -scalar_t plane_signed_dist(plane_t plane, vec3_t pt)
   32.67 -{
   32.68 -	vec3_t pp = plane_point(plane);
   32.69 -	vec3_t pptopt = v3_sub(pt, pp);
   32.70 -	return v3_dot(pptopt, plane.norm);
   32.71 -}
   32.72 -
   32.73 -scalar_t plane_dist(plane_t plane, vec3_t pt)
   32.74 -{
   32.75 -	return fabs(plane_signed_dist(plane, pt));
   32.76 -}
   32.77 -
   32.78 -vec3_t plane_point(plane_t plane)
   32.79 -{
   32.80 -	return v3_scale(plane.norm, plane.d);
   32.81 -}
   32.82 -
   32.83 -int plane_ray_intersect(ray_t ray, plane_t plane, scalar_t *pos)
   32.84 -{
   32.85 -	vec3_t pt, orig_to_pt;
   32.86 -	scalar_t ndotdir;
   32.87 -
   32.88 -	pt = plane_point(plane);
   32.89 -	ndotdir = v3_dot(plane.norm, ray.dir);
   32.90 -
   32.91 -	if(fabs(ndotdir) < 1e-7) {
   32.92 -		return 0;
   32.93 -	}
   32.94 -
   32.95 -	if(pos) {
   32.96 -		orig_to_pt = v3_sub(pt, ray.origin);
   32.97 -		*pos = v3_dot(plane.norm, orig_to_pt) / ndotdir;
   32.98 -	}
   32.99 -	return 1;
  32.100 -}
  32.101 -
  32.102 -sphere_t sphere_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t rad)
  32.103 -{
  32.104 -	sphere_t sph;
  32.105 -	sph.pos.x = x;
  32.106 -	sph.pos.y = y;
  32.107 -	sph.pos.z = z;
  32.108 -	sph.rad = rad;
  32.109 -	return sph;
  32.110 -}
  32.111 -
  32.112 -int sphere_ray_intersect(ray_t ray, sphere_t sph, scalar_t *pos)
  32.113 -{
  32.114 -	scalar_t a, b, c, d, sqrt_d, t1, t2, t;
  32.115 -
  32.116 -	a = v3_dot(ray.dir, ray.dir);
  32.117 -	b = 2.0 * ray.dir.x * (ray.origin.x - sph.pos.x) +
  32.118 -		2.0 * ray.dir.y * (ray.origin.y - sph.pos.y) +
  32.119 -		2.0 * ray.dir.z * (ray.origin.z - sph.pos.z);
  32.120 -	c = v3_dot(sph.pos, sph.pos) + v3_dot(ray.origin, ray.origin) +
  32.121 -		2.0 * v3_dot(v3_neg(sph.pos), ray.origin) - sph.rad * sph.rad;
  32.122 -
  32.123 -	d = b * b - 4.0 * a * c;
  32.124 -	if(d < 0.0) {
  32.125 -		return 0;
  32.126 -	}
  32.127 -
  32.128 -	sqrt_d = sqrt(d);
  32.129 -	t1 = (-b + sqrt_d) / (2.0 * a);
  32.130 -	t2 = (-b - sqrt_d) / (2.0 * a);
  32.131 -
  32.132 -	if(t1 < 1e-7 || t1 > 1.0) {
  32.133 -		t1 = t2;
  32.134 -	}
  32.135 -	if(t2 < 1e-7 || t2 > 1.0) {
  32.136 -		t2 = t1;
  32.137 -	}
  32.138 -	t = t1 < t2 ? t1 : t2;
  32.139 -
  32.140 -	if(t < 1e-7 || t > 1.0) {
  32.141 -		return 0;
  32.142 -	}
  32.143 -
  32.144 -	if(pos) {
  32.145 -		*pos = t;
  32.146 -	}
  32.147 -	return 1;
  32.148 -}
  32.149 -
  32.150 -int sphere_sphere_intersect(sphere_t sph1, sphere_t sph2, scalar_t *pos, scalar_t *rad)
  32.151 -{
  32.152 -	return -1;
  32.153 -}
    33.1 --- a/libs/vmath/geom.h	Thu Apr 17 08:50:36 2014 +0300
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,72 +0,0 @@
    33.4 -/*
    33.5 -libvmath - a vector math library
    33.6 -Copyright (C) 2004-2012 John Tsiombikas <nuclear@member.fsf.org>
    33.7 -
    33.8 -This program is free software: you can redistribute it and/or modify
    33.9 -it under the terms of the GNU Lesser General Public License as published
   33.10 -by the Free Software Foundation, either version 3 of the License, or
   33.11 -(at your option) any later version.
   33.12 -
   33.13 -This program is distributed in the hope that it will be useful,
   33.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   33.16 -GNU Lesser General Public License for more details.
   33.17 -
   33.18 -You should have received a copy of the GNU Lesser General Public License
   33.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   33.20 -*/
   33.21 -#ifndef LIBVMATH_GEOM_H_
   33.22 -#define LIBVMATH_GEOM_H_
   33.23 -
   33.24 -#include "vector.h"
   33.25 -#include "ray.h"
   33.26 -
   33.27 -typedef struct {
   33.28 -	vec3_t norm;
   33.29 -	scalar_t d;
   33.30 -} plane_t;
   33.31 -
   33.32 -typedef struct {
   33.33 -	vec3_t pos;
   33.34 -	scalar_t rad;
   33.35 -} sphere_t;
   33.36 -
   33.37 -typedef struct {
   33.38 -	vec3_t min, max;
   33.39 -} aabox_t;
   33.40 -
   33.41 -#ifdef __cplusplus
   33.42 -extern "C" {
   33.43 -#endif
   33.44 -
   33.45 -/* planes are good... you need planes, yes you do */
   33.46 -plane_t plane_cons(scalar_t nx, scalar_t ny, scalar_t nz, scalar_t d);
   33.47 -plane_t plane_poly(vec3_t v0, vec3_t v1, vec3_t v2);
   33.48 -plane_t plane_ptnorm(vec3_t pt, vec3_t normal);
   33.49 -
   33.50 -plane_t plane_invert(plane_t p);
   33.51 -
   33.52 -scalar_t plane_signed_dist(plane_t plane, vec3_t pt);
   33.53 -scalar_t plane_dist(plane_t plane, vec3_t pt);
   33.54 -vec3_t plane_point(plane_t plane);
   33.55 -
   33.56 -int plane_ray_intersect(ray_t ray, plane_t plane, scalar_t *pos);
   33.57 -
   33.58 -/* spheres always come in handy */
   33.59 -sphere_t sphere_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t rad);
   33.60 -
   33.61 -int sphere_ray_intersect(ray_t ray, sphere_t sph, scalar_t *pos);
   33.62 -int sphere_sphere_intersect(sphere_t sph1, sphere_t sph2, scalar_t *pos, scalar_t *rad);
   33.63 -
   33.64 -#ifdef __cplusplus
   33.65 -}
   33.66 -
   33.67 -/* TODO
   33.68 -class Plane : public plane_t {
   33.69 -public:
   33.70 -};
   33.71 -*/
   33.72 -
   33.73 -#endif
   33.74 -
   33.75 -#endif	/* LIBVMATH_GEOM_H_ */
    34.1 --- a/libs/vmath/matrix.cc	Thu Apr 17 08:50:36 2014 +0300
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,821 +0,0 @@
    34.4 -#include <cstdio>
    34.5 -#include <cmath>
    34.6 -#include "matrix.h"
    34.7 -#include "vector.h"
    34.8 -#include "quat.h"
    34.9 -
   34.10 -using namespace std;
   34.11 -
   34.12 -// ----------- Matrix3x3 --------------
   34.13 -
   34.14 -Matrix3x3 Matrix3x3::identity = Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);
   34.15 -
   34.16 -Matrix3x3::Matrix3x3()
   34.17 -{
   34.18 -	*this = Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);
   34.19 -}
   34.20 -
   34.21 -Matrix3x3::Matrix3x3(	scalar_t m11, scalar_t m12, scalar_t m13,
   34.22 -						scalar_t m21, scalar_t m22, scalar_t m23,
   34.23 -						scalar_t m31, scalar_t m32, scalar_t m33)
   34.24 -{
   34.25 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13;
   34.26 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23;
   34.27 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33;
   34.28 -}
   34.29 -
   34.30 -Matrix3x3::Matrix3x3(const Vector3 &ivec, const Vector3 &jvec, const Vector3 &kvec)
   34.31 -{
   34.32 -	set_row_vector(ivec, 0);
   34.33 -	set_row_vector(jvec, 1);
   34.34 -	set_row_vector(kvec, 2);
   34.35 -}
   34.36 -
   34.37 -Matrix3x3::Matrix3x3(const mat3_t cmat)
   34.38 -{
   34.39 -	memcpy(m, cmat, sizeof(mat3_t));
   34.40 -}
   34.41 -
   34.42 -Matrix3x3::Matrix3x3(const Matrix4x4 &mat4x4)
   34.43 -{
   34.44 -	for(int i=0; i<3; i++) {
   34.45 -		for(int j=0; j<3; j++) {
   34.46 -			m[i][j] = mat4x4[i][j];
   34.47 -		}
   34.48 -	}
   34.49 -}
   34.50 -
   34.51 -Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2)
   34.52 -{
   34.53 -	Matrix3x3 res;
   34.54 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
   34.55 -	scalar_t *dest = res.m[0];
   34.56 -
   34.57 -	for(int i=0; i<9; i++) {
   34.58 -		*dest++ = *op1++ + *op2++;
   34.59 -	}
   34.60 -	return res;
   34.61 -}
   34.62 -
   34.63 -Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2)
   34.64 -{
   34.65 -	Matrix3x3 res;
   34.66 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
   34.67 -	scalar_t *dest = res.m[0];
   34.68 -
   34.69 -	for(int i=0; i<9; i++) {
   34.70 -		*dest++ = *op1++ - *op2++;
   34.71 -	}
   34.72 -	return res;
   34.73 -}
   34.74 -
   34.75 -Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2)
   34.76 -{
   34.77 -	Matrix3x3 res;
   34.78 -	for(int i=0; i<3; i++) {
   34.79 -		for(int j=0; j<3; j++) {
   34.80 -			res.m[i][j] = m1.m[i][0] * m2.m[0][j] + m1.m[i][1] * m2.m[1][j] + m1.m[i][2] * m2.m[2][j];
   34.81 -		}
   34.82 -	}
   34.83 -	return res;
   34.84 -}
   34.85 -
   34.86 -void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2)
   34.87 -{
   34.88 -	scalar_t *op1 = m1.m[0];
   34.89 -	const scalar_t *op2 = m2.m[0];
   34.90 -
   34.91 -	for(int i=0; i<9; i++) {
   34.92 -		*op1++ += *op2++;
   34.93 -	}
   34.94 -}
   34.95 -
   34.96 -void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2)
   34.97 -{
   34.98 -	scalar_t *op1 = m1.m[0];
   34.99 -	const scalar_t *op2 = m2.m[0];
  34.100 -
  34.101 -	for(int i=0; i<9; i++) {
  34.102 -		*op1++ -= *op2++;
  34.103 -	}
  34.104 -}
  34.105 -
  34.106 -void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2)
  34.107 -{
  34.108 -	Matrix3x3 res;
  34.109 -	for(int i=0; i<3; i++) {
  34.110 -		for(int j=0; j<3; j++) {
  34.111 -			res.m[i][j] = m1.m[i][0] * m2.m[0][j] + m1.m[i][1] * m2.m[1][j] + m1.m[i][2] * m2.m[2][j];
  34.112 -		}
  34.113 -	}
  34.114 -	memcpy(m1.m, res.m, 9 * sizeof(scalar_t));
  34.115 -}
  34.116 -
  34.117 -Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar)
  34.118 -{
  34.119 -	Matrix3x3 res;
  34.120 -	const scalar_t *mptr = mat.m[0];
  34.121 -	scalar_t *dptr = res.m[0];
  34.122 -
  34.123 -	for(int i=0; i<9; i++) {
  34.124 -		*dptr++ = *mptr++ * scalar;
  34.125 -	}
  34.126 -	return res;
  34.127 -}
  34.128 -
  34.129 -Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat)
  34.130 -{
  34.131 -	Matrix3x3 res;
  34.132 -	const scalar_t *mptr = mat.m[0];
  34.133 -	scalar_t *dptr = res.m[0];
  34.134 -
  34.135 -	for(int i=0; i<9; i++) {
  34.136 -		*dptr++ = *mptr++ * scalar;
  34.137 -	}
  34.138 -	return res;
  34.139 -}
  34.140 -
  34.141 -void operator *=(Matrix3x3 &mat, scalar_t scalar)
  34.142 -{
  34.143 -	scalar_t *mptr = mat.m[0];
  34.144 -
  34.145 -	for(int i=0; i<9; i++) {
  34.146 -		*mptr++ *= scalar;
  34.147 -	}
  34.148 -}
  34.149 -
  34.150 -void Matrix3x3::translate(const Vector2 &trans)
  34.151 -{
  34.152 -	Matrix3x3 tmat(1, 0, trans.x, 0, 1, trans.y, 0, 0, 1);
  34.153 -	*this *= tmat;
  34.154 -}
  34.155 -
  34.156 -void Matrix3x3::set_translation(const Vector2 &trans)
  34.157 -{
  34.158 -	*this = Matrix3x3(1, 0, trans.x, 0, 1, trans.y, 0, 0, 1);
  34.159 -}
  34.160 -
  34.161 -void Matrix3x3::rotate(scalar_t angle)
  34.162 -{
  34.163 -	scalar_t cos_a = cos(angle);
  34.164 -	scalar_t sin_a = sin(angle);
  34.165 -	Matrix3x3 rmat(	cos_a,	-sin_a,		0,
  34.166 -					sin_a,	cos_a,		0,
  34.167 -					0,		0,			1);
  34.168 -	*this *= rmat;
  34.169 -}
  34.170 -
  34.171 -void Matrix3x3::set_rotation(scalar_t angle)
  34.172 -{
  34.173 -	scalar_t cos_a = cos(angle);
  34.174 -	scalar_t sin_a = sin(angle);
  34.175 -	*this = Matrix3x3(cos_a, -sin_a, 0, sin_a, cos_a, 0, 0, 0, 1);
  34.176 -}
  34.177 -
  34.178 -void Matrix3x3::rotate(const Vector3 &euler_angles)
  34.179 -{
  34.180 -	Matrix3x3 xrot, yrot, zrot;
  34.181 -
  34.182 -	xrot = Matrix3x3(	1,			0,					0,
  34.183 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  34.184 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  34.185 -
  34.186 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  34.187 -								0,				1,				0,
  34.188 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  34.189 -
  34.190 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  34.191 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  34.192 -								0,						0,				1);
  34.193 -
  34.194 -	*this *= xrot * yrot * zrot;
  34.195 -}
  34.196 -
  34.197 -void Matrix3x3::set_rotation(const Vector3 &euler_angles)
  34.198 -{
  34.199 -	Matrix3x3 xrot, yrot, zrot;
  34.200 -
  34.201 -	xrot = Matrix3x3(	1,			0,					0,
  34.202 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  34.203 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  34.204 -
  34.205 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  34.206 -								0,				1,				0,
  34.207 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  34.208 -
  34.209 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  34.210 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  34.211 -								0,						0,				1);
  34.212 -
  34.213 -	*this = xrot * yrot * zrot;
  34.214 -}
  34.215 -
  34.216 -void Matrix3x3::rotate(const Vector3 &axis, scalar_t angle)
  34.217 -{
  34.218 -	scalar_t sina = (scalar_t)sin(angle);
  34.219 -	scalar_t cosa = (scalar_t)cos(angle);
  34.220 -	scalar_t invcosa = 1-cosa;
  34.221 -	scalar_t nxsq = axis.x * axis.x;
  34.222 -	scalar_t nysq = axis.y * axis.y;
  34.223 -	scalar_t nzsq = axis.z * axis.z;
  34.224 -
  34.225 -	Matrix3x3 xform;
  34.226 -	xform.m[0][0] = nxsq + (1-nxsq) * cosa;
  34.227 -	xform.m[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  34.228 -	xform.m[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  34.229 -
  34.230 -	xform.m[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  34.231 -	xform.m[1][1] = nysq + (1-nysq) * cosa;
  34.232 -	xform.m[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  34.233 -
  34.234 -	xform.m[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  34.235 -	xform.m[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  34.236 -	xform.m[2][2] = nzsq + (1-nzsq) * cosa;
  34.237 -
  34.238 -	*this *= xform;
  34.239 -}
  34.240 -
  34.241 -void Matrix3x3::set_rotation(const Vector3 &axis, scalar_t angle)
  34.242 -{
  34.243 -	scalar_t sina = (scalar_t)sin(angle);
  34.244 -	scalar_t cosa = (scalar_t)cos(angle);
  34.245 -	scalar_t invcosa = 1-cosa;
  34.246 -	scalar_t nxsq = axis.x * axis.x;
  34.247 -	scalar_t nysq = axis.y * axis.y;
  34.248 -	scalar_t nzsq = axis.z * axis.z;
  34.249 -
  34.250 -	reset_identity();
  34.251 -	m[0][0] = nxsq + (1-nxsq) * cosa;
  34.252 -	m[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  34.253 -	m[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  34.254 -	m[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  34.255 -	m[1][1] = nysq + (1-nysq) * cosa;
  34.256 -	m[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  34.257 -	m[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  34.258 -	m[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  34.259 -	m[2][2] = nzsq + (1-nzsq) * cosa;
  34.260 -}
  34.261 -
  34.262 -// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  34.263 -// article "Quaternion Calculus and Fast Animation".
  34.264 -// adapted from: http://www.geometrictools.com/LibMathematics/Algebra/Wm5Quaternion.inl
  34.265 -Quaternion Matrix3x3::get_rotation_quat() const
  34.266 -{
  34.267 -	static const int next[3] = {1, 2, 0};
  34.268 -
  34.269 -	float quat[4];
  34.270 -
  34.271 -	scalar_t trace = m[0][0] + m[1][1] + m[2][2];
  34.272 -	scalar_t root;
  34.273 -
  34.274 -	if(trace > 0.0f) {
  34.275 -		// |w| > 1/2
  34.276 -		root = sqrt(trace + 1.0f);	// 2w
  34.277 -		quat[0] = 0.5f * root;
  34.278 -		root = 0.5f / root;	// 1 / 4w
  34.279 -		quat[1] = (m[2][1] - m[1][2]) * root;
  34.280 -		quat[2] = (m[0][2] - m[2][0]) * root;
  34.281 -		quat[3] = (m[1][0] - m[0][1]) * root;
  34.282 -	} else {
  34.283 -		// |w| <= 1/2
  34.284 -		int i = 0;
  34.285 -		if(m[1][1] > m[0][0]) {
  34.286 -			i = 1;
  34.287 -		}
  34.288 -		if(m[2][2] > m[i][i]) {
  34.289 -			i = 2;
  34.290 -		}
  34.291 -		int j = next[i];
  34.292 -		int k = next[j];
  34.293 -
  34.294 -		root = sqrt(m[i][i] - m[j][j] - m[k][k] + 1.0f);
  34.295 -		quat[i + 1] = 0.5f * root;
  34.296 -		root = 0.5f / root;
  34.297 -		quat[0] = (m[k][j] - m[j][k]) * root;
  34.298 -		quat[j + 1] = (m[j][i] - m[i][j]) * root;
  34.299 -		quat[k + 1] = (m[k][i] - m[i][k]) * root;
  34.300 -	}
  34.301 -	return Quaternion(quat[0], quat[1], quat[2], quat[3]);
  34.302 -}
  34.303 -
  34.304 -void Matrix3x3::scale(const Vector3 &scale_vec)
  34.305 -{
  34.306 -	Matrix3x3 smat(	scale_vec.x, 0, 0,
  34.307 -					0, scale_vec.y, 0,
  34.308 -					0, 0, scale_vec.z);
  34.309 -	*this *= smat;
  34.310 -}
  34.311 -
  34.312 -void Matrix3x3::set_scaling(const Vector3 &scale_vec)
  34.313 -{
  34.314 -	*this = Matrix3x3(	scale_vec.x, 0, 0,
  34.315 -						0, scale_vec.y, 0,
  34.316 -						0, 0, scale_vec.z);
  34.317 -}
  34.318 -
  34.319 -void Matrix3x3::set_column_vector(const Vector3 &vec, unsigned int col_index)
  34.320 -{
  34.321 -	m[0][col_index] = vec.x;
  34.322 -	m[1][col_index] = vec.y;
  34.323 -	m[2][col_index] = vec.z;
  34.324 -}
  34.325 -
  34.326 -void Matrix3x3::set_row_vector(const Vector3 &vec, unsigned int row_index)
  34.327 -{
  34.328 -	m[row_index][0] = vec.x;
  34.329 -	m[row_index][1] = vec.y;
  34.330 -	m[row_index][2] = vec.z;
  34.331 -}
  34.332 -
  34.333 -Vector3 Matrix3x3::get_column_vector(unsigned int col_index) const
  34.334 -{
  34.335 -	return Vector3(m[0][col_index], m[1][col_index], m[2][col_index]);
  34.336 -}
  34.337 -
  34.338 -Vector3 Matrix3x3::get_row_vector(unsigned int row_index) const
  34.339 -{
  34.340 -	return Vector3(m[row_index][0], m[row_index][1], m[row_index][2]);
  34.341 -}
  34.342 -
  34.343 -void Matrix3x3::transpose()
  34.344 -{
  34.345 -	Matrix3x3 tmp = *this;
  34.346 -	for(int i=0; i<3; i++) {
  34.347 -		for(int j=0; j<3; j++) {
  34.348 -			m[i][j] = tmp[j][i];
  34.349 -		}
  34.350 -	}
  34.351 -}
  34.352 -
  34.353 -Matrix3x3 Matrix3x3::transposed() const
  34.354 -{
  34.355 -	Matrix3x3 res;
  34.356 -	for(int i=0; i<3; i++) {
  34.357 -		for(int j=0; j<3; j++) {
  34.358 -			res[i][j] = m[j][i];
  34.359 -		}
  34.360 -	}
  34.361 -	return res;
  34.362 -}
  34.363 -
  34.364 -scalar_t Matrix3x3::determinant() const
  34.365 -{
  34.366 -	return	m[0][0] * (m[1][1]*m[2][2] - m[1][2]*m[2][1]) -
  34.367 -			m[0][1] * (m[1][0]*m[2][2] - m[1][2]*m[2][0]) +
  34.368 -			m[0][2] * (m[1][0]*m[2][1] - m[1][1]*m[2][0]);
  34.369 -}
  34.370 -
  34.371 -Matrix3x3 Matrix3x3::inverse() const
  34.372 -{
  34.373 -	// TODO: implement 3x3 inverse
  34.374 -	return *this;
  34.375 -}
  34.376 -
  34.377 -ostream &operator <<(ostream &out, const Matrix3x3 &mat)
  34.378 -{
  34.379 -	for(int i=0; i<3; i++) {
  34.380 -		char str[100];
  34.381 -		sprintf(str, "[ %12.5f %12.5f %12.5f ]\n", (float)mat.m[i][0], (float)mat.m[i][1], (float)mat.m[i][2]);
  34.382 -		out << str;
  34.383 -	}
  34.384 -	return out;
  34.385 -}
  34.386 -
  34.387 -
  34.388 -
  34.389 -/* ----------------- Matrix4x4 implementation --------------- */
  34.390 -
  34.391 -Matrix4x4 Matrix4x4::identity = Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  34.392 -
  34.393 -Matrix4x4::Matrix4x4()
  34.394 -{
  34.395 -	*this = Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  34.396 -}
  34.397 -
  34.398 -Matrix4x4::Matrix4x4(	scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
  34.399 -						scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
  34.400 -						scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
  34.401 -						scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44)
  34.402 -{
  34.403 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13; m[0][3] = m14;
  34.404 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23; m[1][3] = m24;
  34.405 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33; m[2][3] = m34;
  34.406 -	m[3][0] = m41; m[3][1] = m42; m[3][2] = m43; m[3][3] = m44;
  34.407 -}
  34.408 -
  34.409 -Matrix4x4::Matrix4x4(const mat4_t cmat)
  34.410 -{
  34.411 -	memcpy(m, cmat, sizeof(mat4_t));
  34.412 -}
  34.413 -
  34.414 -Matrix4x4::Matrix4x4(const Matrix3x3 &mat3x3)
  34.415 -{
  34.416 -	reset_identity();
  34.417 -	for(int i=0; i<3; i++) {
  34.418 -		for(int j=0; j<3; j++) {
  34.419 -			m[i][j] = mat3x3[i][j];
  34.420 -		}
  34.421 -	}
  34.422 -}
  34.423 -
  34.424 -Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2)
  34.425 -{
  34.426 -	Matrix4x4 res;
  34.427 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
  34.428 -	scalar_t *dest = res.m[0];
  34.429 -
  34.430 -	for(int i=0; i<16; i++) {
  34.431 -		*dest++ = *op1++ + *op2++;
  34.432 -	}
  34.433 -	return res;
  34.434 -}
  34.435 -
  34.436 -Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2)
  34.437 -{
  34.438 -	Matrix4x4 res;
  34.439 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
  34.440 -	scalar_t *dest = res.m[0];
  34.441 -
  34.442 -	for(int i=0; i<16; i++) {
  34.443 -		*dest++ = *op1++ - *op2++;
  34.444 -	}
  34.445 -	return res;
  34.446 -}
  34.447 -
  34.448 -void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2)
  34.449 -{
  34.450 -	scalar_t *op1 = m1.m[0];
  34.451 -	const scalar_t *op2 = m2.m[0];
  34.452 -
  34.453 -	for(int i=0; i<16; i++) {
  34.454 -		*op1++ += *op2++;
  34.455 -	}
  34.456 -}
  34.457 -
  34.458 -void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2)
  34.459 -{
  34.460 -	scalar_t *op1 = m1.m[0];
  34.461 -	const scalar_t *op2 = m2.m[0];
  34.462 -
  34.463 -	for(int i=0; i<16; i++) {
  34.464 -		*op1++ -= *op2++;
  34.465 -	}
  34.466 -}
  34.467 -
  34.468 -Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar)
  34.469 -{
  34.470 -	Matrix4x4 res;
  34.471 -	const scalar_t *mptr = mat.m[0];
  34.472 -	scalar_t *dptr = res.m[0];
  34.473 -
  34.474 -	for(int i=0; i<16; i++) {
  34.475 -		*dptr++ = *mptr++ * scalar;
  34.476 -	}
  34.477 -	return res;
  34.478 -}
  34.479 -
  34.480 -Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat)
  34.481 -{
  34.482 -	Matrix4x4 res;
  34.483 -	const scalar_t *mptr = mat.m[0];
  34.484 -	scalar_t *dptr = res.m[0];
  34.485 -
  34.486 -	for(int i=0; i<16; i++) {
  34.487 -		*dptr++ = *mptr++ * scalar;
  34.488 -	}
  34.489 -	return res;
  34.490 -}
  34.491 -
  34.492 -void operator *=(Matrix4x4 &mat, scalar_t scalar)
  34.493 -{
  34.494 -	scalar_t *mptr = mat.m[0];
  34.495 -
  34.496 -	for(int i=0; i<16; i++) {
  34.497 -		*mptr++ *= scalar;
  34.498 -	}
  34.499 -}
  34.500 -
  34.501 -void Matrix4x4::translate(const Vector3 &trans)
  34.502 -{
  34.503 -	Matrix4x4 tmat(1, 0, 0, trans.x, 0, 1, 0, trans.y, 0, 0, 1, trans.z, 0, 0, 0, 1);
  34.504 -	*this *= tmat;
  34.505 -}
  34.506 -
  34.507 -void Matrix4x4::set_translation(const Vector3 &trans)
  34.508 -{
  34.509 -	*this = Matrix4x4(1, 0, 0, trans.x, 0, 1, 0, trans.y, 0, 0, 1, trans.z, 0, 0, 0, 1);
  34.510 -}
  34.511 -
  34.512 -Vector3 Matrix4x4::get_translation() const
  34.513 -{
  34.514 -	return Vector3(m[0][3], m[1][3], m[2][3]);
  34.515 -}
  34.516 -
  34.517 -void Matrix4x4::rotate(const Vector3 &euler_angles)
  34.518 -{
  34.519 -	Matrix3x3 xrot, yrot, zrot;
  34.520 -
  34.521 -	xrot = Matrix3x3(	1,			0,					0,
  34.522 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  34.523 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  34.524 -
  34.525 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  34.526 -								0,				1,				0,
  34.527 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  34.528 -
  34.529 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  34.530 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  34.531 -								0,						0,				1);
  34.532 -
  34.533 -	*this *= Matrix4x4(xrot * yrot * zrot);
  34.534 -}
  34.535 -
  34.536 -void Matrix4x4::set_rotation(const Vector3 &euler_angles)
  34.537 -{
  34.538 -	Matrix3x3 xrot, yrot, zrot;
  34.539 -
  34.540 -	xrot = Matrix3x3(	1,			0,					0,
  34.541 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  34.542 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  34.543 -
  34.544 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  34.545 -								0,				1,				0,
  34.546 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  34.547 -
  34.548 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  34.549 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  34.550 -								0,						0,				1);
  34.551 -
  34.552 -	*this = Matrix4x4(xrot * yrot * zrot);
  34.553 -}
  34.554 -
  34.555 -void Matrix4x4::rotate(const Vector3 &axis, scalar_t angle)
  34.556 -{
  34.557 -	scalar_t sina = (scalar_t)sin(angle);
  34.558 -	scalar_t cosa = (scalar_t)cos(angle);
  34.559 -	scalar_t invcosa = 1-cosa;
  34.560 -	scalar_t nxsq = axis.x * axis.x;
  34.561 -	scalar_t nysq = axis.y * axis.y;
  34.562 -	scalar_t nzsq = axis.z * axis.z;
  34.563 -
  34.564 -	Matrix4x4 xform;
  34.565 -	xform[0][0] = nxsq + (1-nxsq) * cosa;
  34.566 -	xform[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  34.567 -	xform[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  34.568 -	xform[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  34.569 -	xform[1][1] = nysq + (1-nysq) * cosa;
  34.570 -	xform[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  34.571 -	xform[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  34.572 -	xform[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  34.573 -	xform[2][2] = nzsq + (1-nzsq) * cosa;
  34.574 -
  34.575 -	*this *= xform;
  34.576 -}
  34.577 -
  34.578 -void Matrix4x4::set_rotation(const Vector3 &axis, scalar_t angle)
  34.579 -{
  34.580 -	scalar_t sina = (scalar_t)sin(angle);
  34.581 -	scalar_t cosa = (scalar_t)cos(angle);
  34.582 -	scalar_t invcosa = 1-cosa;
  34.583 -	scalar_t nxsq = axis.x * axis.x;
  34.584 -	scalar_t nysq = axis.y * axis.y;
  34.585 -	scalar_t nzsq = axis.z * axis.z;
  34.586 -
  34.587 -	reset_identity();
  34.588 -	m[0][0] = nxsq + (1-nxsq) * cosa;
  34.589 -	m[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  34.590 -	m[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  34.591 -	m[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  34.592 -	m[1][1] = nysq + (1-nysq) * cosa;
  34.593 -	m[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  34.594 -	m[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  34.595 -	m[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  34.596 -	m[2][2] = nzsq + (1-nzsq) * cosa;
  34.597 -}
  34.598 -
  34.599 -void Matrix4x4::rotate(const Quaternion &quat)
  34.600 -{
  34.601 -	*this *= quat.get_rotation_matrix();
  34.602 -}
  34.603 -
  34.604 -void Matrix4x4::set_rotation(const Quaternion &quat)
  34.605 -{
  34.606 -	*this = quat.get_rotation_matrix();
  34.607 -}
  34.608 -
  34.609 -Quaternion Matrix4x4::get_rotation_quat() const
  34.610 -{
  34.611 -	Matrix3x3 mat3 = *this;
  34.612 -	return mat3.get_rotation_quat();
  34.613 -}
  34.614 -
  34.615 -void Matrix4x4::scale(const Vector4 &scale_vec)
  34.616 -{
  34.617 -	Matrix4x4 smat(	scale_vec.x, 0, 0, 0,
  34.618 -					0, scale_vec.y, 0, 0,
  34.619 -					0, 0, scale_vec.z, 0,
  34.620 -					0, 0, 0, scale_vec.w);
  34.621 -	*this *= smat;
  34.622 -}
  34.623 -
  34.624 -void Matrix4x4::set_scaling(const Vector4 &scale_vec)
  34.625 -{
  34.626 -	*this = Matrix4x4(	scale_vec.x, 0, 0, 0,
  34.627 -						0, scale_vec.y, 0, 0,
  34.628 -						0, 0, scale_vec.z, 0,
  34.629 -						0, 0, 0, scale_vec.w);
  34.630 -}
  34.631 -
  34.632 -Vector3 Matrix4x4::get_scaling() const
  34.633 -{
  34.634 -	Vector3 vi = get_row_vector(0);
  34.635 -	Vector3 vj = get_row_vector(1);
  34.636 -	Vector3 vk = get_row_vector(2);
  34.637 -
  34.638 -	return Vector3(vi.length(), vj.length(), vk.length());
  34.639 -}
  34.640 -
  34.641 -void Matrix4x4::set_perspective(float vfov, float aspect, float znear, float zfar)
  34.642 -{
  34.643 -	float f = 1.0f / tan(vfov * 0.5f);
  34.644 -    float dz = znear - zfar;
  34.645 -
  34.646 -	reset_identity();
  34.647 -
  34.648 -	m[0][0] = f / aspect;
  34.649 -    m[1][1] = f;
  34.650 -    m[2][2] = (zfar + znear) / dz;
  34.651 -    m[3][2] = -1.0f;
  34.652 -    m[2][3] = 2.0f * zfar * znear / dz;
  34.653 -    m[3][3] = 0.0f;
  34.654 -}
  34.655 -
  34.656 -void Matrix4x4::set_orthographic(float left, float right, float bottom, float top, float znear, float zfar)
  34.657 -{
  34.658 -	float dx = right - left;
  34.659 -	float dy = top - bottom;
  34.660 -	float dz = zfar - znear;
  34.661 -
  34.662 -	reset_identity();
  34.663 -
  34.664 -	m[0][0] = 2.0 / dx;
  34.665 -	m[1][1] = 2.0 / dy;
  34.666 -	m[2][2] = -2.0 / dz;
  34.667 -	m[0][3] = -(right + left) / dx;
  34.668 -	m[1][3] = -(top + bottom) / dy;
  34.669 -	m[2][3] = -(zfar + znear) / dz;
  34.670 -}
  34.671 -
  34.672 -void Matrix4x4::set_column_vector(const Vector4 &vec, unsigned int col_index)
  34.673 -{
  34.674 -	m[0][col_index] = vec.x;
  34.675 -	m[1][col_index] = vec.y;
  34.676 -	m[2][col_index] = vec.z;
  34.677 -	m[3][col_index] = vec.w;
  34.678 -}
  34.679 -
  34.680 -void Matrix4x4::set_row_vector(const Vector4 &vec, unsigned int row_index)
  34.681 -{
  34.682 -	m[row_index][0] = vec.x;
  34.683 -	m[row_index][1] = vec.y;
  34.684 -	m[row_index][2] = vec.z;
  34.685 -	m[row_index][3] = vec.w;
  34.686 -}
  34.687 -
  34.688 -Vector4 Matrix4x4::get_column_vector(unsigned int col_index) const
  34.689 -{
  34.690 -	return Vector4(m[0][col_index], m[1][col_index], m[2][col_index], m[3][col_index]);
  34.691 -}
  34.692 -
  34.693 -Vector4 Matrix4x4::get_row_vector(unsigned int row_index) const
  34.694 -{
  34.695 -	return Vector4(m[row_index][0], m[row_index][1], m[row_index][2], m[row_index][3]);
  34.696 -}
  34.697 -
  34.698 -void Matrix4x4::transpose()
  34.699 -{
  34.700 -	Matrix4x4 tmp = *this;
  34.701 -	for(int i=0; i<4; i++) {
  34.702 -		for(int j=0; j<4; j++) {
  34.703 -			m[i][j] = tmp[j][i];
  34.704 -		}
  34.705 -	}
  34.706 -}
  34.707 -
  34.708 -Matrix4x4 Matrix4x4::transposed() const
  34.709 -{
  34.710 -	Matrix4x4 res;
  34.711 -	for(int i=0; i<4; i++) {
  34.712 -		for(int j=0; j<4; j++) {
  34.713 -			res[i][j] = m[j][i];
  34.714 -		}
  34.715 -	}
  34.716 -	return res;
  34.717 -}
  34.718 -
  34.719 -scalar_t Matrix4x4::determinant() const
  34.720 -{
  34.721 -	scalar_t det11 =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  34.722 -						(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  34.723 -						(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  34.724 -
  34.725 -	scalar_t det12 =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  34.726 -						(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  34.727 -						(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  34.728 -
  34.729 -	scalar_t det13 =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  34.730 -						(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  34.731 -						(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  34.732 -
  34.733 -	scalar_t det14 =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  34.734 -						(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  34.735 -						(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  34.736 -
  34.737 -	return m[0][0] * det11 - m[0][1] * det12 + m[0][2] * det13 - m[0][3] * det14;
  34.738 -}
  34.739 -
  34.740 -
  34.741 -Matrix4x4 Matrix4x4::adjoint() const
  34.742 -{
  34.743 -	Matrix4x4 coef;
  34.744 -
  34.745 -	coef.m[0][0] =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  34.746 -					(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  34.747 -					(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  34.748 -	coef.m[0][1] =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  34.749 -					(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  34.750 -					(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  34.751 -	coef.m[0][2] =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  34.752 -					(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  34.753 -					(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  34.754 -	coef.m[0][3] =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  34.755 -					(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  34.756 -					(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  34.757 -
  34.758 -	coef.m[1][0] =	(m[0][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  34.759 -					(m[0][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  34.760 -					(m[0][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  34.761 -	coef.m[1][1] =	(m[0][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  34.762 -					(m[0][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  34.763 -					(m[0][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  34.764 -	coef.m[1][2] =	(m[0][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  34.765 -					(m[0][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  34.766 -					(m[0][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  34.767 -	coef.m[1][3] =	(m[0][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  34.768 -					(m[0][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  34.769 -					(m[0][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  34.770 -
  34.771 -	coef.m[2][0] =	(m[0][1] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  34.772 -					(m[0][2] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) +
  34.773 -					(m[0][3] * (m[1][1] * m[3][2] - m[3][1] * m[1][2]));
  34.774 -	coef.m[2][1] =	(m[0][0] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  34.775 -					(m[0][2] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  34.776 -					(m[0][3] * (m[1][0] * m[3][2] - m[3][0] * m[1][2]));
  34.777 -	coef.m[2][2] =	(m[0][0] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) -
  34.778 -					(m[0][1] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  34.779 -					(m[0][3] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  34.780 -	coef.m[2][3] =	(m[0][0] * (m[1][1] * m[3][2] - m[3][1] * m[1][2])) -
  34.781 -					(m[0][1] * (m[1][0] * m[3][2] - m[3][0] * m[1][2])) +
  34.782 -					(m[0][2] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  34.783 -
  34.784 -	coef.m[3][0] =	(m[0][1] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  34.785 -					(m[0][2] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) +
  34.786 -					(m[0][3] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]));
  34.787 -	coef.m[3][1] =	(m[0][0] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  34.788 -					(m[0][2] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  34.789 -					(m[0][3] * (m[1][0] * m[2][2] - m[2][0] * m[1][2]));
  34.790 -	coef.m[3][2] =	(m[0][0] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) -
  34.791 -					(m[0][1] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  34.792 -					(m[0][3] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  34.793 -	coef.m[3][3] =	(m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])) -
  34.794 -					(m[0][1] * (m[1][0] * m[2][2] - m[2][0] * m[1][2])) +
  34.795 -					(m[0][2] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  34.796 -
  34.797 -	coef.transpose();
  34.798 -
  34.799 -	for(int i=0; i<4; i++) {
  34.800 -		for(int j=0; j<4; j++) {
  34.801 -			coef.m[i][j] = j%2 ? -coef.m[i][j] : coef.m[i][j];
  34.802 -			if(i%2) coef.m[i][j] = -coef.m[i][j];
  34.803 -		}
  34.804 -	}
  34.805 -
  34.806 -	return coef;
  34.807 -}
  34.808 -
  34.809 -Matrix4x4 Matrix4x4::inverse() const
  34.810 -{
  34.811 -	Matrix4x4 adj = adjoint();
  34.812 -
  34.813 -	return adj * (1.0f / determinant());
  34.814 -}
  34.815 -
  34.816 -ostream &operator <<(ostream &out, const Matrix4x4 &mat)
  34.817 -{
  34.818 -	for(int i=0; i<4; i++) {
  34.819 -		char str[100];
  34.820 -		sprintf(str, "[ %12.5f %12.5f %12.5f %12.5f ]\n", (float)mat.m[i][0], (float)mat.m[i][1], (float)mat.m[i][2], (float)mat.m[i][3]);
  34.821 -		out << str;
  34.822 -	}
  34.823 -	return out;
  34.824 -}
    35.1 --- a/libs/vmath/matrix.h	Thu Apr 17 08:50:36 2014 +0300
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,260 +0,0 @@
    35.4 -/*
    35.5 -libvmath - a vector math library
    35.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    35.7 -
    35.8 -This program is free software: you can redistribute it and/or modify
    35.9 -it under the terms of the GNU Lesser General Public License as published
   35.10 -by the Free Software Foundation, either version 3 of the License, or
   35.11 -(at your option) any later version.
   35.12 -
   35.13 -This program is distributed in the hope that it will be useful,
   35.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   35.16 -GNU Lesser General Public License for more details.
   35.17 -
   35.18 -You should have received a copy of the GNU Lesser General Public License
   35.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   35.20 -*/
   35.21 -
   35.22 -#ifndef VMATH_MATRIX_H_
   35.23 -#define VMATH_MATRIX_H_
   35.24 -
   35.25 -#include <stdio.h>
   35.26 -#include "vmath_types.h"
   35.27 -
   35.28 -#ifdef __cplusplus
   35.29 -extern "C" {
   35.30 -#endif	/* __cplusplus */
   35.31 -
   35.32 -/* C matrix 3x3 functions */
   35.33 -static VMATH_INLINE void m3_identity(mat3_t m);
   35.34 -static VMATH_INLINE void m3_cons(mat3_t m,
   35.35 -		scalar_t m11, scalar_t m12, scalar_t m13,
   35.36 -		scalar_t m21, scalar_t m22, scalar_t m23,
   35.37 -		scalar_t m31, scalar_t m32, scalar_t m33);
   35.38 -static VMATH_INLINE void m3_copy(mat3_t dest, mat3_t src);
   35.39 -void m3_to_m4(mat4_t dest, mat3_t src);
   35.40 -
   35.41 -void m3_print(FILE *fp, mat3_t m);
   35.42 -
   35.43 -/* C matrix 4x4 functions */
   35.44 -static VMATH_INLINE void m4_identity(mat4_t m);
   35.45 -static VMATH_INLINE void m4_cons(mat4_t m,
   35.46 -		scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
   35.47 -		scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
   35.48 -		scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
   35.49 -		scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
   35.50 -static VMATH_INLINE void m4_copy(mat4_t dest, mat4_t src);
   35.51 -void m4_to_m3(mat3_t dest, mat4_t src);
   35.52 -
   35.53 -static VMATH_INLINE void m4_mult(mat4_t res, mat4_t m1, mat4_t m2);
   35.54 -
   35.55 -void m4_set_translation(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   35.56 -void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   35.57 -
   35.58 -void m4_rotate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   35.59 -
   35.60 -void m4_set_rotation_x(mat4_t m, scalar_t angle);
   35.61 -void m4_rotate_x(mat4_t m, scalar_t angle);
   35.62 -void m4_set_rotation_y(mat4_t m, scalar_t angle);
   35.63 -void m4_rotate_y(mat4_t m, scalar_t angle);
   35.64 -void m4_set_rotation_z(mat4_t m, scalar_t angle);
   35.65 -void m4_rotate_z(mat4_t m, scalar_t angle);
   35.66 -/* axis-angle rotation */
   35.67 -void m4_set_rotation_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   35.68 -void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   35.69 -/* concatentate a rotation quaternion */
   35.70 -void m4_rotate_quat(mat4_t m, quat_t q);
   35.71 -
   35.72 -void m4_set_scaling(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   35.73 -void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   35.74 -
   35.75 -static VMATH_INLINE void m4_set_column(mat4_t m, vec4_t v, int idx);
   35.76 -static VMATH_INLINE void m4_set_row(mat4_t m, vec4_t v, int idx);
   35.77 -
   35.78 -void m4_transpose(mat4_t res, mat4_t m);
   35.79 -scalar_t m4_determinant(mat4_t m);
   35.80 -void m4_adjoint(mat4_t res, mat4_t m);
   35.81 -void m4_inverse(mat4_t res, mat4_t m);
   35.82 -
   35.83 -void m4_print(FILE *fp, mat4_t m);
   35.84 -
   35.85 -#ifdef __cplusplus
   35.86 -}
   35.87 -
   35.88 -/* when included from C++ source files, also define the matrix classes */
   35.89 -#include <iostream>
   35.90 -
   35.91 -/** 3x3 matrix */
   35.92 -class Matrix3x3 {
   35.93 -public:
   35.94 -	scalar_t m[3][3];
   35.95 -
   35.96 -	static Matrix3x3 identity;
   35.97 -
   35.98 -	Matrix3x3();
   35.99 -	Matrix3x3(	scalar_t m11, scalar_t m12, scalar_t m13,
  35.100 -				scalar_t m21, scalar_t m22, scalar_t m23,
  35.101 -				scalar_t m31, scalar_t m32, scalar_t m33);
  35.102 -	Matrix3x3(const Vector3 &ivec, const Vector3 &jvec, const Vector3 &kvec);
  35.103 -	Matrix3x3(const mat3_t cmat);
  35.104 -
  35.105 -	Matrix3x3(const Matrix4x4 &mat4x4);
  35.106 -
  35.107 -	/* binary operations matrix (op) matrix */
  35.108 -	friend Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
  35.109 -	friend Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
  35.110 -	friend Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
  35.111 -
  35.112 -	friend void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
  35.113 -	friend void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
  35.114 -	friend void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
  35.115 -
  35.116 -	/* binary operations matrix (op) scalar and scalar (op) matrix */
  35.117 -	friend Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
  35.118 -	friend Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
  35.119 -
  35.120 -	friend void operator *=(Matrix3x3 &mat, scalar_t scalar);
  35.121 -
  35.122 -	VMATH_INLINE scalar_t *operator [](int index);
  35.123 -	VMATH_INLINE const scalar_t *operator [](int index) const;
  35.124 -
  35.125 -	VMATH_INLINE void reset_identity();
  35.126 -
  35.127 -	void translate(const Vector2 &trans);
  35.128 -	void set_translation(const Vector2 &trans);
  35.129 -
  35.130 -	void rotate(scalar_t angle);						/* 2d rotation */
  35.131 -	void rotate(const Vector3 &euler_angles);			/* 3d rotation with euler angles */
  35.132 -	void rotate(const Vector3 &axis, scalar_t angle);	/* 3d axis/angle rotation */
  35.133 -	void set_rotation(scalar_t angle);
  35.134 -	void set_rotation(const Vector3 &euler_angles);
  35.135 -	void set_rotation(const Vector3 &axis, scalar_t angle);
  35.136 -	Quaternion get_rotation_quat() const;
  35.137 -
  35.138 -	void scale(const Vector3 &scale_vec);
  35.139 -	void set_scaling(const Vector3 &scale_vec);
  35.140 -
  35.141 -	void set_column_vector(const Vector3 &vec, unsigned int col_index);
  35.142 -	void set_row_vector(const Vector3 &vec, unsigned int row_index);
  35.143 -	Vector3 get_column_vector(unsigned int col_index) const;
  35.144 -	Vector3 get_row_vector(unsigned int row_index) const;
  35.145 -
  35.146 -	void transpose();
  35.147 -	Matrix3x3 transposed() const;
  35.148 -	scalar_t determinant() const;
  35.149 -	Matrix3x3 inverse() const;
  35.150 -
  35.151 -	friend std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
  35.152 -};
  35.153 -
  35.154 -/* binary operations matrix (op) matrix */
  35.155 -Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
  35.156 -Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
  35.157 -Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
  35.158 -
  35.159 -void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
  35.160 -void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
  35.161 -void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
  35.162 -
  35.163 -/* binary operations matrix (op) scalar and scalar (op) matrix */
  35.164 -Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
  35.165 -Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
  35.166 -
  35.167 -void operator *=(Matrix3x3 &mat, scalar_t scalar);
  35.168 -
  35.169 -std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
  35.170 -
  35.171 -
  35.172 -
  35.173 -/** 4x4 matrix */
  35.174 -class Matrix4x4 {
  35.175 -public:
  35.176 -	scalar_t m[4][4];
  35.177 -
  35.178 -	static Matrix4x4 identity;
  35.179 -
  35.180 -	Matrix4x4();
  35.181 -	Matrix4x4(	scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
  35.182 -				scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
  35.183 -				scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
  35.184 -				scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
  35.185 -	Matrix4x4(const mat4_t cmat);
  35.186 -
  35.187 -	Matrix4x4(const Matrix3x3 &mat3x3);
  35.188 -
  35.189 -	/* binary operations matrix (op) matrix */
  35.190 -	friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
  35.191 -	friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
  35.192 -	friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
  35.193 -
  35.194 -	friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
  35.195 -	friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
  35.196 -	friend VMATH_INLINE void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
  35.197 -
  35.198 -	/* binary operations matrix (op) scalar and scalar (op) matrix */
  35.199 -	friend Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
  35.200 -	friend Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
  35.201 -
  35.202 -	friend void operator *=(Matrix4x4 &mat, scalar_t scalar);
  35.203 -
  35.204 -	VMATH_INLINE scalar_t *operator [](int index);
  35.205 -	VMATH_INLINE const scalar_t *operator [](int index) const;
  35.206 -
  35.207 -	VMATH_INLINE void reset_identity();
  35.208 -
  35.209 -	void translate(const Vector3 &trans);
  35.210 -	void set_translation(const Vector3 &trans);
  35.211 -	Vector3 get_translation() const;	/* extract translation */
  35.212 -
  35.213 -	void rotate(const Vector3 &euler_angles);			/* 3d rotation with euler angles */
  35.214 -	void rotate(const Vector3 &axis, scalar_t angle);	/* 3d axis/angle rotation */
  35.215 -	void rotate(const Quaternion &quat);
  35.216 -	void set_rotation(const Vector3 &euler_angles);
  35.217 -	void set_rotation(const Vector3 &axis, scalar_t angle);
  35.218 -	void set_rotation(const Quaternion &quat);
  35.219 -	Quaternion get_rotation_quat() const;		/* extract rotation */
  35.220 -
  35.221 -	void scale(const Vector4 &scale_vec);
  35.222 -	void set_scaling(const Vector4 &scale_vec);
  35.223 -	Vector3 get_scaling() const;		/* extract scaling */
  35.224 -
  35.225 -	void set_perspective(float vfov, float aspect, float znear, float zfar);
  35.226 -	void set_orthographic(float left, float right, float bottom, float top, float znear = -1.0, float zfar = 1.0);
  35.227 -
  35.228 -	void set_column_vector(const Vector4 &vec, unsigned int col_index);
  35.229 -	void set_row_vector(const Vector4 &vec, unsigned int row_index);
  35.230 -	Vector4 get_column_vector(unsigned int col_index) const;
  35.231 -	Vector4 get_row_vector(unsigned int row_index) const;
  35.232 -
  35.233 -	void transpose();
  35.234 -	Matrix4x4 transposed() const;
  35.235 -	scalar_t determinant() const;
  35.236 -	Matrix4x4 adjoint() const;
  35.237 -	Matrix4x4 inverse() const;
  35.238 -
  35.239 -	friend std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
  35.240 -};
  35.241 -
  35.242 -/* binary operations matrix (op) matrix */
  35.243 -Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
  35.244 -Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
  35.245 -VMATH_INLINE Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
  35.246 -
  35.247 -void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
  35.248 -void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
  35.249 -VMATH_INLINE void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
  35.250 -
  35.251 -/* binary operations matrix (op) scalar and scalar (op) matrix */
  35.252 -Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
  35.253 -Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
  35.254 -
  35.255 -void operator *=(Matrix4x4 &mat, scalar_t scalar);
  35.256 -
  35.257 -std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
  35.258 -
  35.259 -#endif	/* __cplusplus */
  35.260 -
  35.261 -#include "matrix.inl"
  35.262 -
  35.263 -#endif	/* VMATH_MATRIX_H_ */
    36.1 --- a/libs/vmath/matrix.inl	Thu Apr 17 08:50:36 2014 +0300
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,200 +0,0 @@
    36.4 -/*
    36.5 -libvmath - a vector math library
    36.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    36.7 -
    36.8 -This program is free software: you can redistribute it and/or modify
    36.9 -it under the terms of the GNU Lesser General Public License as published
   36.10 -by the Free Software Foundation, either version 3 of the License, or
   36.11 -(at your option) any later version.
   36.12 -
   36.13 -This program is distributed in the hope that it will be useful,
   36.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   36.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   36.16 -GNU Lesser General Public License for more details.
   36.17 -
   36.18 -You should have received a copy of the GNU Lesser General Public License
   36.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   36.20 -*/
   36.21 -
   36.22 -#include <string.h>
   36.23 -
   36.24 -#ifdef __cplusplus
   36.25 -extern "C" {
   36.26 -#endif	/* __cplusplus */
   36.27 -
   36.28 -/* C matrix 3x3 functions */
   36.29 -static VMATH_INLINE void m3_identity(mat3_t m)
   36.30 -{
   36.31 -	static const mat3_t id = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
   36.32 -	memcpy(m, id, sizeof id);
   36.33 -}
   36.34 -
   36.35 -static VMATH_INLINE void m3_cons(mat3_t m,
   36.36 -		scalar_t m11, scalar_t m12, scalar_t m13,
   36.37 -		scalar_t m21, scalar_t m22, scalar_t m23,
   36.38 -		scalar_t m31, scalar_t m32, scalar_t m33)
   36.39 -{
   36.40 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13;
   36.41 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23;
   36.42 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33;
   36.43 -}
   36.44 -
   36.45 -static VMATH_INLINE void m3_copy(mat3_t dest, mat3_t src)
   36.46 -{
   36.47 -	memcpy(dest, src, sizeof(mat3_t));
   36.48 -}
   36.49 -
   36.50 -
   36.51 -/* C matrix 4x4 functions */
   36.52 -static VMATH_INLINE void m4_identity(mat4_t m)
   36.53 -{
   36.54 -	static const mat4_t id = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
   36.55 -	memcpy(m, id, sizeof id);
   36.56 -}
   36.57 -
   36.58 -static VMATH_INLINE void m4_cons(mat4_t m,
   36.59 -		scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
   36.60 -		scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
   36.61 -		scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
   36.62 -		scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44)
   36.63 -{
   36.64 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13; m[0][3] = m14;
   36.65 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23; m[1][3] = m24;
   36.66 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33; m[2][3] = m34;
   36.67 -	m[3][0] = m41; m[3][1] = m42; m[3][2] = m43; m[3][3] = m44;
   36.68 -}
   36.69 -
   36.70 -static VMATH_INLINE void m4_copy(mat4_t dest, mat4_t src)
   36.71 -{
   36.72 -	memcpy(dest, src, sizeof(mat4_t));
   36.73 -}
   36.74 -
   36.75 -static VMATH_INLINE void m4_mult(mat4_t res, mat4_t m1, mat4_t m2)
   36.76 -{
   36.77 -	mat4_t tmp;
   36.78 -
   36.79 -	/*
   36.80 -	int i, j;
   36.81 -	for(i=0; i<4; i++) {
   36.82 -		for(j=0; j<4; j++) {
   36.83 -			tmp[i][j] = m1[i][0] * m2[0][j] + m1[i][1] * m2[1][j] + m1[i][2] * m2[2][j] + m1[i][3] * m2[3][j];
   36.84 -		}
   36.85 -	}
   36.86 -	*/
   36.87 -
   36.88 -	tmp[0][0] = m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0] + m1[0][2] * m2[2][0] + m1[0][3] * m2[3][0];
   36.89 -	tmp[0][1] = m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1] + m1[0][2] * m2[2][1] + m1[0][3] * m2[3][1];
   36.90 -	tmp[0][2] = m1[0][0] * m2[0][2] + m1[0][1] * m2[1][2] + m1[0][2] * m2[2][2] + m1[0][3] * m2[3][2];
   36.91 -	tmp[0][3] = m1[0][0] * m2[0][3] + m1[0][1] * m2[1][3] + m1[0][2] * m2[2][3] + m1[0][3] * m2[3][3];
   36.92 -
   36.93 -	tmp[1][0] = m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0] + m1[1][2] * m2[2][0] + m1[1][3] * m2[3][0];
   36.94 -	tmp[1][1] = m1[1][0] * m2[0][1] + m1[1][1] * m2[1][1] + m1[1][2] * m2[2][1] + m1[1][3] * m2[3][1];
   36.95 -	tmp[1][2] = m1[1][0] * m2[0][2] + m1[1][1] * m2[1][2] + m1[1][2] * m2[2][2] + m1[1][3] * m2[3][2];
   36.96 -	tmp[1][3] = m1[1][0] * m2[0][3] + m1[1][1] * m2[1][3] + m1[1][2] * m2[2][3] + m1[1][3] * m2[3][3];
   36.97 -
   36.98 -	tmp[2][0] = m1[2][0] * m2[0][0] + m1[2][1] * m2[1][0] + m1[2][2] * m2[2][0] + m1[2][3] * m2[3][0];
   36.99 -	tmp[2][1] = m1[2][0] * m2[0][1] + m1[2][1] * m2[1][1] + m1[2][2] * m2[2][1] + m1[2][3] * m2[3][1];
  36.100 -	tmp[2][2] = m1[2][0] * m2[0][2] + m1[2][1] * m2[1][2] + m1[2][2] * m2[2][2] + m1[2][3] * m2[3][2];
  36.101 -	tmp[2][3] = m1[2][0] * m2[0][3] + m1[2][1] * m2[1][3] + m1[2][2] * m2[2][3] + m1[2][3] * m2[3][3];
  36.102 -
  36.103 -	tmp[3][0] = m1[3][0] * m2[0][0] + m1[3][1] * m2[1][0] + m1[3][2] * m2[2][0] + m1[3][3] * m2[3][0];
  36.104 -	tmp[3][1] = m1[3][0] * m2[0][1] + m1[3][1] * m2[1][1] + m1[3][2] * m2[2][1] + m1[3][3] * m2[3][1];
  36.105 -	tmp[3][2] = m1[3][0] * m2[0][2] + m1[3][1] * m2[1][2] + m1[3][2] * m2[2][2] + m1[3][3] * m2[3][2];
  36.106 -	tmp[3][3] = m1[3][0] * m2[0][3] + m1[3][1] * m2[1][3] + m1[3][2] * m2[2][3] + m1[3][3] * m2[3][3];
  36.107 -
  36.108 -	m4_copy(res, tmp);
  36.109 -}
  36.110 -
  36.111 -static VMATH_INLINE void m4_set_column(mat4_t m, vec4_t v, int idx)
  36.112 -{
  36.113 -	m[0][idx] = v.x;
  36.114 -	m[1][idx] = v.y;
  36.115 -	m[2][idx] = v.z;
  36.116 -	m[3][idx] = v.w;
  36.117 -}
  36.118 -
  36.119 -static VMATH_INLINE void m4_set_row(mat4_t m, vec4_t v, int idx)
  36.120 -{
  36.121 -	m[idx][0] = v.x;
  36.122 -	m[idx][1] = v.y;
  36.123 -	m[idx][2] = v.z;
  36.124 -	m[idx][3] = v.w;
  36.125 -}
  36.126 -
  36.127 -#ifdef __cplusplus
  36.128 -}	/* extern "C" */
  36.129 -
  36.130 -
  36.131 -/* unrolled to hell and VMATH_INLINE */
  36.132 -VMATH_INLINE Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2)
  36.133 -{
  36.134 -	Matrix4x4 res;
  36.135 -
  36.136 -	/*
  36.137 -	for(i=0; i<4; i++) {
  36.138 -		for(j=0; j<4; j++) {
  36.139 -			res.m[i][j] = m1.m[i][0] * m2.m[0][j] + m1.m[i][1] * m2.m[1][j] + m1.m[i][2] * m2.m[2][j] + m1.m[i][3] * m2.m[3][j];
  36.140 -		}
  36.141 -	}
  36.142 -	*/
  36.143 -
  36.144 -	res.m[0][0] = m1.m[0][0] * m2.m[0][0] + m1.m[0][1] * m2.m[1][0] + m1.m[0][2] * m2.m[2][0] + m1.m[0][3] * m2.m[3][0];
  36.145 -	res.m[0][1] = m1.m[0][0] * m2.m[0][1] + m1.m[0][1] * m2.m[1][1] + m1.m[0][2] * m2.m[2][1] + m1.m[0][3] * m2.m[3][1];
  36.146 -	res.m[0][2] = m1.m[0][0] * m2.m[0][2] + m1.m[0][1] * m2.m[1][2] + m1.m[0][2] * m2.m[2][2] + m1.m[0][3] * m2.m[3][2];
  36.147 -	res.m[0][3] = m1.m[0][0] * m2.m[0][3] + m1.m[0][1] * m2.m[1][3] + m1.m[0][2] * m2.m[2][3] + m1.m[0][3] * m2.m[3][3];
  36.148 -
  36.149 -	res.m[1][0] = m1.m[1][0] * m2.m[0][0] + m1.m[1][1] * m2.m[1][0] + m1.m[1][2] * m2.m[2][0] + m1.m[1][3] * m2.m[3][0];
  36.150 -	res.m[1][1] = m1.m[1][0] * m2.m[0][1] + m1.m[1][1] * m2.m[1][1] + m1.m[1][2] * m2.m[2][1] + m1.m[1][3] * m2.m[3][1];
  36.151 -	res.m[1][2] = m1.m[1][0] * m2.m[0][2] + m1.m[1][1] * m2.m[1][2] + m1.m[1][2] * m2.m[2][2] + m1.m[1][3] * m2.m[3][2];
  36.152 -	res.m[1][3] = m1.m[1][0] * m2.m[0][3] + m1.m[1][1] * m2.m[1][3] + m1.m[1][2] * m2.m[2][3] + m1.m[1][3] * m2.m[3][3];
  36.153 -
  36.154 -	res.m[2][0] = m1.m[2][0] * m2.m[0][0] + m1.m[2][1] * m2.m[1][0] + m1.m[2][2] * m2.m[2][0] + m1.m[2][3] * m2.m[3][0];
  36.155 -	res.m[2][1] = m1.m[2][0] * m2.m[0][1] + m1.m[2][1] * m2.m[1][1] + m1.m[2][2] * m2.m[2][1] + m1.m[2][3] * m2.m[3][1];
  36.156 -	res.m[2][2] = m1.m[2][0] * m2.m[0][2] + m1.m[2][1] * m2.m[1][2] + m1.m[2][2] * m2.m[2][2] + m1.m[2][3] * m2.m[3][2];
  36.157 -	res.m[2][3] = m1.m[2][0] * m2.m[0][3] + m1.m[2][1] * m2.m[1][3] + m1.m[2][2] * m2.m[2][3] + m1.m[2][3] * m2.m[3][3];
  36.158 -
  36.159 -	res.m[3][0] = m1.m[3][0] * m2.m[0][0] + m1.m[3][1] * m2.m[1][0] + m1.m[3][2] * m2.m[2][0] + m1.m[3][3] * m2.m[3][0];
  36.160 -	res.m[3][1] = m1.m[3][0] * m2.m[0][1] + m1.m[3][1] * m2.m[1][1] + m1.m[3][2] * m2.m[2][1] + m1.m[3][3] * m2.m[3][1];
  36.161 -	res.m[3][2] = m1.m[3][0] * m2.m[0][2] + m1.m[3][1] * m2.m[1][2] + m1.m[3][2] * m2.m[2][2] + m1.m[3][3] * m2.m[3][2];
  36.162 -	res.m[3][3] = m1.m[3][0] * m2.m[0][3] + m1.m[3][1] * m2.m[1][3] + m1.m[3][2] * m2.m[2][3] + m1.m[3][3] * m2.m[3][3];
  36.163 -
  36.164 -	return res;
  36.165 -}
  36.166 -
  36.167 -VMATH_INLINE void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2)
  36.168 -{
  36.169 -	Matrix4x4 res = m1 * m2;
  36.170 -	m1 = res;
  36.171 -}
  36.172 -
  36.173 -
  36.174 -VMATH_INLINE scalar_t *Matrix3x3::operator [](int index)
  36.175 -{
  36.176 -	return m[index];
  36.177 -}
  36.178 -
  36.179 -VMATH_INLINE const scalar_t *Matrix3x3::operator [](int index) const
  36.180 -{
  36.181 -	return m[index];
  36.182 -}
  36.183 -
  36.184 -VMATH_INLINE void Matrix3x3::reset_identity()
  36.185 -{
  36.186 -	*this = identity;
  36.187 -}
  36.188 -
  36.189 -VMATH_INLINE scalar_t *Matrix4x4::operator [](int index)
  36.190 -{
  36.191 -	return m[index];
  36.192 -}
  36.193 -
  36.194 -VMATH_INLINE const scalar_t *Matrix4x4::operator [](int index) const
  36.195 -{
  36.196 -	return m[index];
  36.197 -}
  36.198 -
  36.199 -VMATH_INLINE void Matrix4x4::reset_identity()
  36.200 -{
  36.201 -	*this = identity;
  36.202 -}
  36.203 -#endif	/* __cplusplus */
    37.1 --- a/libs/vmath/matrix_c.c	Thu Apr 17 08:50:36 2014 +0300
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,292 +0,0 @@
    37.4 -/*
    37.5 -libvmath - a vector math library
    37.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    37.7 -
    37.8 -This program is free software: you can redistribute it and/or modify
    37.9 -it under the terms of the GNU Lesser General Public License as published
   37.10 -by the Free Software Foundation, either version 3 of the License, or
   37.11 -(at your option) any later version.
   37.12 -
   37.13 -This program is distributed in the hope that it will be useful,
   37.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   37.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   37.16 -GNU Lesser General Public License for more details.
   37.17 -
   37.18 -You should have received a copy of the GNU Lesser General Public License
   37.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   37.20 -*/
   37.21 -
   37.22 -
   37.23 -#include <stdio.h>
   37.24 -#include "matrix.h"
   37.25 -#include "vector.h"
   37.26 -#include "quat.h"
   37.27 -
   37.28 -void m3_to_m4(mat4_t dest, mat3_t src)
   37.29 -{
   37.30 -	int i, j;
   37.31 -
   37.32 -	memset(dest, 0, sizeof(mat4_t));
   37.33 -	for(i=0; i<3; i++) {
   37.34 -		for(j=0; j<3; j++) {
   37.35 -			dest[i][j] = src[i][j];
   37.36 -		}
   37.37 -	}
   37.38 -	dest[3][3] = 1.0;
   37.39 -}
   37.40 -
   37.41 -void m3_print(FILE *fp, mat3_t m)
   37.42 -{
   37.43 -	int i;
   37.44 -	for(i=0; i<3; i++) {
   37.45 -		fprintf(fp, "[ %12.5f %12.5f %12.5f ]\n", (float)m[i][0], (float)m[i][1], (float)m[i][2]);
   37.46 -	}
   37.47 -}
   37.48 -
   37.49 -/* C matrix 4x4 functions */
   37.50 -void m4_to_m3(mat3_t dest, mat4_t src)
   37.51 -{
   37.52 -	int i, j;
   37.53 -	for(i=0; i<3; i++) {
   37.54 -		for(j=0; j<3; j++) {
   37.55 -			dest[i][j] = src[i][j];
   37.56 -		}
   37.57 -	}
   37.58 -}
   37.59 -
   37.60 -void m4_set_translation(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
   37.61 -{
   37.62 -	m4_identity(m);
   37.63 -	m[0][3] = x;
   37.64 -	m[1][3] = y;
   37.65 -	m[2][3] = z;
   37.66 -}
   37.67 -
   37.68 -void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
   37.69 -{
   37.70 -	mat4_t tm;
   37.71 -	m4_set_translation(tm, x, y, z);
   37.72 -	m4_mult(m, m, tm);
   37.73 -}
   37.74 -
   37.75 -void m4_rotate(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
   37.76 -{
   37.77 -	m4_rotate_x(m, x);
   37.78 -	m4_rotate_y(m, y);
   37.79 -	m4_rotate_z(m, z);
   37.80 -}
   37.81 -
   37.82 -void m4_set_rotation_x(mat4_t m, scalar_t angle)
   37.83 -{
   37.84 -	m4_identity(m);
   37.85 -	m[1][1] = cos(angle); m[1][2] = -sin(angle);
   37.86 -	m[2][1] = sin(angle); m[2][2] = cos(angle);
   37.87 -}
   37.88 -
   37.89 -void m4_rotate_x(mat4_t m, scalar_t angle)
   37.90 -{
   37.91 -	mat4_t rm;
   37.92 -	m4_set_rotation_x(m, angle);
   37.93 -	m4_mult(m, m, rm);
   37.94 -}
   37.95 -
   37.96 -void m4_set_rotation_y(mat4_t m, scalar_t angle)
   37.97 -{
   37.98 -	m4_identity(m);
   37.99 -	m[0][0] = cos(angle); m[0][2] = sin(angle);
  37.100 -	m[2][0] = -sin(angle); m[2][2] = cos(angle);
  37.101 -}
  37.102 -
  37.103 -void m4_rotate_y(mat4_t m, scalar_t angle)
  37.104 -{
  37.105 -	mat4_t rm;
  37.106 -	m4_set_rotation_y(rm, angle);
  37.107 -	m4_mult(m, m, rm);
  37.108 -}
  37.109 -
  37.110 -void m4_set_rotation_z(mat4_t m, scalar_t angle)
  37.111 -{
  37.112 -	m4_identity(m);
  37.113 -	m[0][0] = cos(angle); m[0][1] = -sin(angle);
  37.114 -	m[1][0] = sin(angle); m[1][1] = cos(angle);
  37.115 -}
  37.116 -
  37.117 -void m4_rotate_z(mat4_t m, scalar_t angle)
  37.118 -{
  37.119 -	mat4_t rm;
  37.120 -	m4_set_rotation_z(rm, angle);
  37.121 -	m4_mult(m, m, rm);
  37.122 -}
  37.123 -
  37.124 -void m4_set_rotation_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
  37.125 -{
  37.126 -	scalar_t sina = sin(angle);
  37.127 -	scalar_t cosa = cos(angle);
  37.128 -	scalar_t one_minus_cosa = 1.0 - cosa;
  37.129 -	scalar_t nxsq = x * x;
  37.130 -	scalar_t nysq = y * y;
  37.131 -	scalar_t nzsq = z * z;
  37.132 -
  37.133 -	m[0][0] = nxsq + (1.0 - nxsq) * cosa;
  37.134 -	m[0][1] = x * y * one_minus_cosa - z * sina;
  37.135 -	m[0][2] = x * z * one_minus_cosa + y * sina;
  37.136 -	m[1][0] = x * y * one_minus_cosa + z * sina;
  37.137 -	m[1][1] = nysq + (1.0 - nysq) * cosa;
  37.138 -	m[1][2] = y * z * one_minus_cosa - x * sina;
  37.139 -	m[2][0] = x * z * one_minus_cosa - y * sina;
  37.140 -	m[2][1] = y * z * one_minus_cosa + x * sina;
  37.141 -	m[2][2] = nzsq + (1.0 - nzsq) * cosa;
  37.142 -
  37.143 -	/* the rest are identity */
  37.144 -	m[3][0] = m[3][1] = m[3][2] = m[0][3] = m[1][3] = m[2][3] = 0.0;
  37.145 -	m[3][3] = 1.0;
  37.146 -}
  37.147 -
  37.148 -void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
  37.149 -{
  37.150 -	mat4_t xform;
  37.151 -	m4_set_rotation_axis(xform, angle, x, y, z);
  37.152 -	m4_mult(m, m, xform);
  37.153 -}
  37.154 -
  37.155 -void m4_rotate_quat(mat4_t m, quat_t q)
  37.156 -{
  37.157 -	mat4_t rm;
  37.158 -	quat_to_mat4(rm, q);
  37.159 -	m4_mult(m, m, rm);
  37.160 -}
  37.161 -
  37.162 -void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
  37.163 -{
  37.164 -	mat4_t sm;
  37.165 -	m4_identity(sm);
  37.166 -	sm[0][0] = x;
  37.167 -	sm[1][1] = y;
  37.168 -	sm[2][2] = z;
  37.169 -	m4_mult(m, m, sm);
  37.170 -}
  37.171 -
  37.172 -void m4_transpose(mat4_t res, mat4_t m)
  37.173 -{
  37.174 -	int i, j;
  37.175 -	mat4_t tmp;
  37.176 -	m4_copy(tmp, m);
  37.177 -
  37.178 -	for(i=0; i<4; i++) {
  37.179 -		for(j=0; j<4; j++) {
  37.180 -			res[i][j] = tmp[j][i];
  37.181 -		}
  37.182 -	}
  37.183 -}
  37.184 -
  37.185 -scalar_t m4_determinant(mat4_t m)
  37.186 -{
  37.187 -	scalar_t det11 =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  37.188 -						(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  37.189 -						(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  37.190 -
  37.191 -	scalar_t det12 =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  37.192 -						(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  37.193 -						(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  37.194 -
  37.195 -	scalar_t det13 =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  37.196 -						(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  37.197 -						(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  37.198 -
  37.199 -	scalar_t det14 =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  37.200 -						(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  37.201 -						(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  37.202 -
  37.203 -	return m[0][0] * det11 - m[0][1] * det12 + m[0][2] * det13 - m[0][3] * det14;
  37.204 -}
  37.205 -
  37.206 -void m4_adjoint(mat4_t res, mat4_t m)
  37.207 -{
  37.208 -	int i, j;
  37.209 -	mat4_t coef;
  37.210 -
  37.211 -	coef[0][0] =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  37.212 -					(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  37.213 -					(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  37.214 -	coef[0][1] =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  37.215 -					(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  37.216 -					(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  37.217 -	coef[0][2] =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  37.218 -					(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  37.219 -					(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  37.220 -	coef[0][3] =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  37.221 -					(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  37.222 -					(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  37.223 -
  37.224 -	coef[1][0] =	(m[0][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  37.225 -					(m[0][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  37.226 -					(m[0][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  37.227 -	coef[1][1] =	(m[0][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  37.228 -					(m[0][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  37.229 -					(m[0][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  37.230 -	coef[1][2] =	(m[0][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  37.231 -					(m[0][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  37.232 -					(m[0][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  37.233 -	coef[1][3] =	(m[0][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  37.234 -					(m[0][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  37.235 -					(m[0][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  37.236 -
  37.237 -	coef[2][0] =	(m[0][1] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  37.238 -					(m[0][2] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) +
  37.239 -					(m[0][3] * (m[1][1] * m[3][2] - m[3][1] * m[1][2]));
  37.240 -	coef[2][1] =	(m[0][0] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  37.241 -					(m[0][2] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  37.242 -					(m[0][3] * (m[1][0] * m[3][2] - m[3][0] * m[1][2]));
  37.243 -	coef[2][2] =	(m[0][0] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) -
  37.244 -					(m[0][1] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  37.245 -					(m[0][3] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  37.246 -	coef[2][3] =	(m[0][0] * (m[1][1] * m[3][2] - m[3][1] * m[1][2])) -
  37.247 -					(m[0][1] * (m[1][0] * m[3][2] - m[3][0] * m[1][2])) +
  37.248 -					(m[0][2] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  37.249 -
  37.250 -	coef[3][0] =	(m[0][1] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  37.251 -					(m[0][2] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) +
  37.252 -					(m[0][3] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]));
  37.253 -	coef[3][1] =	(m[0][0] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  37.254 -					(m[0][2] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  37.255 -					(m[0][3] * (m[1][0] * m[2][2] - m[2][0] * m[1][2]));
  37.256 -	coef[3][2] =	(m[0][0] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) -
  37.257 -					(m[0][1] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  37.258 -					(m[0][3] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  37.259 -	coef[3][3] =	(m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])) -
  37.260 -					(m[0][1] * (m[1][0] * m[2][2] - m[2][0] * m[1][2])) +
  37.261 -					(m[0][2] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  37.262 -
  37.263 -	m4_transpose(res, coef);
  37.264 -
  37.265 -	for(i=0; i<4; i++) {
  37.266 -		for(j=0; j<4; j++) {
  37.267 -			res[i][j] = j % 2 ? -res[i][j] : res[i][j];
  37.268 -			if(i % 2) res[i][j] = -res[i][j];
  37.269 -		}
  37.270 -	}
  37.271 -}
  37.272 -
  37.273 -void m4_inverse(mat4_t res, mat4_t m)
  37.274 -{
  37.275 -	int i, j;
  37.276 -	mat4_t adj;
  37.277 -	scalar_t det;
  37.278 -
  37.279 -	m4_adjoint(adj, m);
  37.280 -	det = m4_determinant(m);
  37.281 -	
  37.282 -	for(i=0; i<4; i++) {
  37.283 -		for(j=0; j<4; j++) {
  37.284 -			res[i][j] = adj[i][j] / det;
  37.285 -		}
  37.286 -	}
  37.287 -}
  37.288 -
  37.289 -void m4_print(FILE *fp, mat4_t m)
  37.290 -{
  37.291 -	int i;
  37.292 -	for(i=0; i<4; i++) {
  37.293 -		fprintf(fp, "[ %12.5f %12.5f %12.5f %12.5f ]\n", (float)m[i][0], (float)m[i][1], (float)m[i][2], (float)m[i][3]);
  37.294 -	}
  37.295 -}
    38.1 --- a/libs/vmath/quat.cc	Thu Apr 17 08:50:36 2014 +0300
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,212 +0,0 @@
    38.4 -#include "quat.h"
    38.5 -#include "vmath.h"
    38.6 -
    38.7 -Quaternion::Quaternion()
    38.8 -{
    38.9 -	s = 1.0;
   38.10 -	v.x = v.y = v.z = 0.0;
   38.11 -}
   38.12 -
   38.13 -Quaternion::Quaternion(scalar_t s, const Vector3 &v)
   38.14 -{
   38.15 -	this->s = s;
   38.16 -	this->v = v;
   38.17 -}
   38.18 -
   38.19 -Quaternion::Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z)
   38.20 -{
   38.21 -	v.x = x;
   38.22 -	v.y = y;
   38.23 -	v.z = z;
   38.24 -	this->s = s;
   38.25 -}
   38.26 -
   38.27 -Quaternion::Quaternion(const Vector3 &axis, scalar_t angle)
   38.28 -{
   38.29 -	set_rotation(axis, angle);
   38.30 -}
   38.31 -
   38.32 -Quaternion::Quaternion(const quat_t &quat)
   38.33 -{
   38.34 -	v.x = quat.x;
   38.35 -	v.y = quat.y;
   38.36 -	v.z = quat.z;
   38.37 -	s = quat.w;
   38.38 -}
   38.39 -
   38.40 -Quaternion Quaternion::operator +(const Quaternion &quat) const
   38.41 -{
   38.42 -	return Quaternion(s + quat.s, v + quat.v);
   38.43 -}
   38.44 -
   38.45 -Quaternion Quaternion::operator -(const Quaternion &quat) const
   38.46 -{
   38.47 -	return Quaternion(s - quat.s, v - quat.v);
   38.48 -}
   38.49 -
   38.50 -Quaternion Quaternion::operator -() const
   38.51 -{
   38.52 -	return Quaternion(-s, -v);
   38.53 -}
   38.54 -
   38.55 -/** Quaternion Multiplication:
   38.56 - * Q1*Q2 = [s1*s2 - v1.v2,  s1*v2 + s2*v1 + v1(x)v2]
   38.57 - */
   38.58 -Quaternion Quaternion::operator *(const Quaternion &quat) const
   38.59 -{
   38.60 -	Quaternion newq;
   38.61 -	newq.s = s * quat.s - dot_product(v, quat.v);
   38.62 -	newq.v = quat.v * s + v * quat.s + cross_product(v, quat.v);
   38.63 -	return newq;
   38.64 -}
   38.65 -
   38.66 -void Quaternion::operator +=(const Quaternion &quat)
   38.67 -{
   38.68 -	*this = Quaternion(s + quat.s, v + quat.v);
   38.69 -}
   38.70 -
   38.71 -void Quaternion::operator -=(const Quaternion &quat)
   38.72 -{
   38.73 -	*this = Quaternion(s - quat.s, v - quat.v);
   38.74 -}
   38.75 -
   38.76 -void Quaternion::operator *=(const Quaternion &quat)
   38.77 -{
   38.78 -	*this = *this * quat;
   38.79 -}
   38.80 -
   38.81 -void Quaternion::reset_identity()
   38.82 -{
   38.83 -	s = 1.0;
   38.84 -	v.x = v.y = v.z = 0.0;
   38.85 -}
   38.86 -
   38.87 -Quaternion Quaternion::conjugate() const
   38.88 -{
   38.89 -	return Quaternion(s, -v);
   38.90 -}
   38.91 -
   38.92 -scalar_t Quaternion::length() const
   38.93 -{
   38.94 -	return (scalar_t)sqrt(v.x*v.x + v.y*v.y + v.z*v.z + s*s);
   38.95 -}
   38.96 -
   38.97 -/** Q * ~Q = ||Q||^2 */
   38.98 -scalar_t Quaternion::length_sq() const
   38.99 -{
  38.100 -	return v.x*v.x + v.y*v.y + v.z*v.z + s*s;
  38.101 -}
  38.102 -
  38.103 -void Quaternion::normalize()
  38.104 -{
  38.105 -	scalar_t len = (scalar_t)sqrt(v.x*v.x + v.y*v.y + v.z*v.z + s*s);
  38.106 -	v.x /= len;
  38.107 -	v.y /= len;
  38.108 -	v.z /= len;
  38.109 -	s /= len;
  38.110 -}
  38.111 -
  38.112 -Quaternion Quaternion::normalized() const
  38.113 -{
  38.114 -	Quaternion nq = *this;
  38.115 -	scalar_t len = (scalar_t)sqrt(v.x*v.x + v.y*v.y + v.z*v.z + s*s);
  38.116 -	nq.v.x /= len;
  38.117 -	nq.v.y /= len;
  38.118 -	nq.v.z /= len;
  38.119 -	nq.s /= len;
  38.120 -	return nq;
  38.121 -}
  38.122 -
  38.123 -/** Quaternion Inversion: Q^-1 = ~Q / ||Q||^2 */
  38.124 -Quaternion Quaternion::inverse() const
  38.125 -{
  38.126 -	Quaternion inv = conjugate();
  38.127 -	scalar_t lensq = length_sq();
  38.128 -	inv.v /= lensq;
  38.129 -	inv.s /= lensq;
  38.130 -
  38.131 -	return inv;
  38.132 -}
  38.133 -
  38.134 -
  38.135 -void Quaternion::set_rotation(const Vector3 &axis, scalar_t angle)
  38.136 -{
  38.137 -	scalar_t half_angle = angle / 2.0;
  38.138 -	s = cos(half_angle);
  38.139 -	v = axis * sin(half_angle);
  38.140 -}
  38.141 -
  38.142 -void Quaternion::rotate(const Vector3 &axis, scalar_t angle)
  38.143 -{
  38.144 -	Quaternion q;
  38.145 -	scalar_t half_angle = angle / 2.0;
  38.146 -	q.s = cos(half_angle);
  38.147 -	q.v = axis * sin(half_angle);
  38.148 -
  38.149 -	*this *= q;
  38.150 -}
  38.151 -
  38.152 -void Quaternion::rotate(const Quaternion &q)
  38.153 -{
  38.154 -	*this = q * *this * q.conjugate();
  38.155 -}
  38.156 -
  38.157 -Matrix3x3 Quaternion::get_rotation_matrix() const
  38.158 -{
  38.159 -	return Matrix3x3(
  38.160 -			1.0 - 2.0 * v.y*v.y - 2.0 * v.z*v.z,	2.0 * v.x * v.y - 2.0 * s * v.z,		2.0 * v.z * v.x + 2.0 * s * v.y,
  38.161 -			2.0 * v.x * v.y + 2.0 * s * v.z,		1.0 - 2.0 * v.x*v.x - 2.0 * v.z*v.z,	2.0 * v.y * v.z - 2.0 * s * v.x,
  38.162 -			2.0 * v.z * v.x - 2.0 * s * v.y,		2.0 * v.y * v.z + 2.0 * s * v.x,		1.0 - 2.0 * v.x*v.x - 2.0 * v.y*v.y);
  38.163 -}
  38.164 -
  38.165 -
  38.166 -/** Spherical linear interpolation (slerp) */
  38.167 -Quaternion slerp(const Quaternion &quat1, const Quaternion &q2, scalar_t t)
  38.168 -{
  38.169 -	Quaternion q1;
  38.170 -	scalar_t dot = q1.s * q2.s + q1.v.x * q2.v.x + q1.v.y * q2.v.y + q1.v.z * q2.v.z;
  38.171 -
  38.172 -	if(dot < 0.0) {
  38.173 -		/* make sure we interpolate across the shortest arc */
  38.174 -		q1 = -quat1;
  38.175 -		dot = -dot;
  38.176 -	} else {
  38.177 -		q1 = quat1;
  38.178 -	}
  38.179 -
  38.180 -	/* clamp dot to [-1, 1] in order to avoid domain errors in acos due to
  38.181 -	 * floating point imprecisions
  38.182 -	 */
  38.183 -	if(dot < -1.0) dot = -1.0;
  38.184 -	if(dot > 1.0) dot = 1.0;
  38.185 -
  38.186 -	scalar_t angle = acos(dot);
  38.187 -	scalar_t a, b;
  38.188 -
  38.189 -	scalar_t sin_angle = sin(angle);
  38.190 -	if(fabs(sin_angle) < SMALL_NUMBER) {
  38.191 -		/* for very small angles or completely opposite orientations
  38.192 -		 * use linear interpolation to avoid div/zero (in the first case it makes sense,
  38.193 -		 * the second case is pretty much undefined anyway I guess ...
  38.194 -		 */
  38.195 -		a = 1.0f - t;
  38.196 -		b = t;
  38.197 -	} else {
  38.198 -		a = sin((1.0f - t) * angle) / sin_angle;
  38.199 -		b = sin(t * angle) / sin_angle;
  38.200 -	}
  38.201 -
  38.202 -	scalar_t x = q1.v.x * a + q2.v.x * b;
  38.203 -	scalar_t y = q1.v.y * a + q2.v.y * b;
  38.204 -	scalar_t z = q1.v.z * a + q2.v.z * b;
  38.205 -	scalar_t s = q1.s * a + q2.s * b;
  38.206 -
  38.207 -	return Quaternion(s, Vector3(x, y, z));
  38.208 -}
  38.209 -
  38.210 -
  38.211 -std::ostream &operator <<(std::ostream &out, const Quaternion &q)
  38.212 -{
  38.213 -	out << "(" << q.s << ", " << q.v << ")";
  38.214 -	return out;
  38.215 -}
    39.1 --- a/libs/vmath/quat.h	Thu Apr 17 08:50:36 2014 +0300
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,118 +0,0 @@
    39.4 -/*
    39.5 -libvmath - a vector math library
    39.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    39.7 -
    39.8 -This program is free software: you can redistribute it and/or modify
    39.9 -it under the terms of the GNU Lesser General Public License as published
   39.10 -by the Free Software Foundation, either version 3 of the License, or
   39.11 -(at your option) any later version.
   39.12 -
   39.13 -This program is distributed in the hope that it will be useful,
   39.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   39.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   39.16 -GNU Lesser General Public License for more details.
   39.17 -
   39.18 -You should have received a copy of the GNU Lesser General Public License
   39.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   39.20 -*/
   39.21 -
   39.22 -#ifndef VMATH_QUATERNION_H_
   39.23 -#define VMATH_QUATERNION_H_
   39.24 -
   39.25 -#include <stdio.h>
   39.26 -#include "vmath_types.h"
   39.27 -#include "vector.h"
   39.28 -
   39.29 -#ifdef __cplusplus
   39.30 -extern "C" {
   39.31 -#endif	/* __cplusplus */
   39.32 -
   39.33 -#define quat_cons(s, x, y, z)	v4_cons(x, y, z, s)
   39.34 -#define quat_vec(q)				v3_cons((q).x, (q).y, (q).z)
   39.35 -#define quat_s(q)				((q).w)
   39.36 -#define quat_identity()			quat_cons(1.0, 0.0, 0.0, 0.0)
   39.37 -void quat_print(FILE *fp, quat_t q);
   39.38 -
   39.39 -#define quat_add		v4_add
   39.40 -#define quat_sub		v4_sub
   39.41 -#define quat_neg		v4_neg
   39.42 -
   39.43 -static VMATH_INLINE quat_t quat_mul(quat_t q1, quat_t q2);
   39.44 -
   39.45 -static VMATH_INLINE quat_t quat_conjugate(quat_t q);
   39.46 -
   39.47 -#define quat_length		v4_length
   39.48 -#define quat_length_sq	v4_length_sq
   39.49 -
   39.50 -#define quat_normalize	v4_normalize
   39.51 -static VMATH_INLINE quat_t quat_inverse(quat_t q);
   39.52 -
   39.53 -quat_t quat_rotate(quat_t q, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   39.54 -quat_t quat_rotate_quat(quat_t q, quat_t rotq);
   39.55 -
   39.56 -static VMATH_INLINE void quat_to_mat3(mat3_t res, quat_t q);
   39.57 -static VMATH_INLINE void quat_to_mat4(mat4_t res, quat_t q);
   39.58 -
   39.59 -#define quat_lerp quat_slerp
   39.60 -quat_t quat_slerp(quat_t q1, quat_t q2, scalar_t t);
   39.61 -
   39.62 -
   39.63 -#ifdef __cplusplus
   39.64 -}	/* extern "C" */
   39.65 -
   39.66 -#include <iostream>
   39.67 -
   39.68 -/* Quaternion */
   39.69 -class Quaternion {
   39.70 -public:
   39.71 -	scalar_t s;
   39.72 -	Vector3 v;
   39.73 -
   39.74 -	Quaternion();
   39.75 -	Quaternion(scalar_t s, const Vector3 &v);
   39.76 -	Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z);
   39.77 -	Quaternion(const Vector3 &axis, scalar_t angle);
   39.78 -	Quaternion(const quat_t &quat);
   39.79 -
   39.80 -	Quaternion operator +(const Quaternion &quat) const;
   39.81 -	Quaternion operator -(const Quaternion &quat) const;
   39.82 -	Quaternion operator -() const;
   39.83 -	Quaternion operator *(const Quaternion &quat) const;
   39.84 -
   39.85 -	void operator +=(const Quaternion &quat);
   39.86 -	void operator -=(const Quaternion &quat);
   39.87 -	void operator *=(const Quaternion &quat);
   39.88 -
   39.89 -	void reset_identity();
   39.90 -
   39.91 -	Quaternion conjugate() const;
   39.92 -
   39.93 -	scalar_t length() const;
   39.94 -	scalar_t length_sq() const;
   39.95 -
   39.96 -	void normalize();
   39.97 -	Quaternion normalized() const;
   39.98 -
   39.99 -	Quaternion inverse() const;
  39.100 -
  39.101 -	void set_rotation(const Vector3 &axis, scalar_t angle);
  39.102 -	void rotate(const Vector3 &axis, scalar_t angle);
  39.103 -	/* note: this is a totally different operation from the above
  39.104 -	 * this treats the quaternion as signifying direction and rotates
  39.105 -	 * it by a rotation quaternion by rot * q * rot'
  39.106 -	 */
  39.107 -	void rotate(const Quaternion &q);
  39.108 -
  39.109 -	Matrix3x3 get_rotation_matrix() const;
  39.110 -};
  39.111 -
  39.112 -Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
  39.113 -VMATH_INLINE Quaternion lerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
  39.114 -
  39.115 -std::ostream &operator <<(std::ostream &out, const Quaternion &q);
  39.116 -
  39.117 -#endif	/* __cplusplus */
  39.118 -
  39.119 -#include "quat.inl"
  39.120 -
  39.121 -#endif	/* VMATH_QUATERNION_H_ */
    40.1 --- a/libs/vmath/quat.inl	Thu Apr 17 08:50:36 2014 +0300
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,81 +0,0 @@
    40.4 -/*
    40.5 -libvmath - a vector math library
    40.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    40.7 -
    40.8 -This program is free software: you can redistribute it and/or modify
    40.9 -it under the terms of the GNU Lesser General Public License as published
   40.10 -by the Free Software Foundation, either version 3 of the License, or
   40.11 -(at your option) any later version.
   40.12 -
   40.13 -This program is distributed in the hope that it will be useful,
   40.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   40.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   40.16 -GNU Lesser General Public License for more details.
   40.17 -
   40.18 -You should have received a copy of the GNU Lesser General Public License
   40.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   40.20 -*/
   40.21 -
   40.22 -#include "vector.h"
   40.23 -#include "matrix.h"
   40.24 -
   40.25 -#ifdef __cplusplus
   40.26 -extern "C" {
   40.27 -#endif	/* __cplusplus */
   40.28 -
   40.29 -static VMATH_INLINE quat_t quat_mul(quat_t q1, quat_t q2)
   40.30 -{
   40.31 -	quat_t res;
   40.32 -	vec3_t v1 = quat_vec(q1);
   40.33 -	vec3_t v2 = quat_vec(q2);
   40.34 -
   40.35 -	res.w = q1.w * q2.w - v3_dot(v1, v2);
   40.36 -	/* resvec = v2 * q1 + v1 * q2 + cross(v1, v2) */
   40.37 -	res.x = v2.x * q1.w + v1.x * q2.w + (v1.y * v2.z - v1.z * v2.y);
   40.38 -	res.y = v2.y * q1.w + v1.y * q2.w + (v1.z * v2.x - v1.x * v2.z);
   40.39 -	res.z = v2.z * q1.w + v1.z * q2.w + (v1.x * v2.y - v1.y * v2.x);
   40.40 -	return res;
   40.41 -}
   40.42 -
   40.43 -static VMATH_INLINE quat_t quat_conjugate(quat_t q)
   40.44 -{
   40.45 -	q.x = -q.x;
   40.46 -	q.y = -q.y;
   40.47 -	q.z = -q.z;
   40.48 -	return q;
   40.49 -}
   40.50 -
   40.51 -static VMATH_INLINE quat_t quat_inverse(quat_t q)
   40.52 -{
   40.53 -	scalar_t lensq = quat_length_sq(q);
   40.54 -	q = quat_conjugate(q);
   40.55 -	q.x /= lensq;
   40.56 -	q.y /= lensq;
   40.57 -	q.z /= lensq;
   40.58 -	q.w /= lensq;
   40.59 -	return q;
   40.60 -}
   40.61 -
   40.62 -static VMATH_INLINE void quat_to_mat3(mat3_t res, quat_t q)
   40.63 -{
   40.64 -	m3_cons(res, 1.0 - 2.0 * q.y*q.y - 2.0 * q.z*q.z, 2.0 * q.x * q.y - 2.0 * q.w * q.z,   2.0 * q.z * q.x + 2.0 * q.w * q.y,
   40.65 -				 2.0 * q.x * q.y + 2.0 * q.w * q.z,   1.0 - 2.0 * q.x*q.x - 2.0 * q.z*q.z, 2.0 * q.y * q.z - 2.0 * q.w * q.x,
   40.66 -				 2.0 * q.z * q.x - 2.0 * q.w * q.y,   2.0 * q.y * q.z + 2.0 * q.w * q.x,   1.0 - 2.0 * q.x*q.x - 2.0 * q.y*q.y);
   40.67 -}
   40.68 -
   40.69 -static VMATH_INLINE void quat_to_mat4(mat4_t res, quat_t q)
   40.70 -{
   40.71 -	m4_cons(res, 1.0 - 2.0 * q.y*q.y - 2.0 * q.z*q.z, 2.0 * q.x * q.y - 2.0 * q.w * q.z,   2.0 * q.z * q.x + 2.0 * q.w * q.y,   0,
   40.72 -				 2.0 * q.x * q.y + 2.0 * q.w * q.z,   1.0 - 2.0 * q.x*q.x - 2.0 * q.z*q.z, 2.0 * q.y * q.z - 2.0 * q.w * q.x,   0,
   40.73 -				 2.0 * q.z * q.x - 2.0 * q.w * q.y,   2.0 * q.y * q.z + 2.0 * q.w * q.x,   1.0 - 2.0 * q.x*q.x - 2.0 * q.y*q.y, 0,
   40.74 -				 0, 0, 0, 1);
   40.75 -}
   40.76 -
   40.77 -#ifdef __cplusplus
   40.78 -}	/* extern "C" */
   40.79 -
   40.80 -VMATH_INLINE Quaternion lerp(const Quaternion &a, const Quaternion &b, scalar_t t)
   40.81 -{
   40.82 -	return slerp(a, b, t);
   40.83 -}
   40.84 -#endif	/* __cplusplus */
    41.1 --- a/libs/vmath/quat_c.c	Thu Apr 17 08:50:36 2014 +0300
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,89 +0,0 @@
    41.4 -/*
    41.5 -libvmath - a vector math library
    41.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    41.7 -
    41.8 -This program is free software: you can redistribute it and/or modify
    41.9 -it under the terms of the GNU Lesser General Public License as published
   41.10 -by the Free Software Foundation, either version 3 of the License, or
   41.11 -(at your option) any later version.
   41.12 -
   41.13 -This program is distributed in the hope that it will be useful,
   41.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   41.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   41.16 -GNU Lesser General Public License for more details.
   41.17 -
   41.18 -You should have received a copy of the GNU Lesser General Public License
   41.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   41.20 -*/
   41.21 -
   41.22 -
   41.23 -#include <stdio.h>
   41.24 -#include <math.h>
   41.25 -#include "quat.h"
   41.26 -
   41.27 -void quat_print(FILE *fp, quat_t q)
   41.28 -{
   41.29 -	fprintf(fp, "([ %.4f %.4f %.4f ] %.4f)", q.x, q.y, q.z, q.w);
   41.30 -}
   41.31 -
   41.32 -quat_t quat_rotate(quat_t q, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
   41.33 -{
   41.34 -	quat_t rq;
   41.35 -	scalar_t half_angle = angle * 0.5;
   41.36 -	scalar_t sin_half = sin(half_angle);
   41.37 -
   41.38 -	rq.w = cos(half_angle);
   41.39 -	rq.x = x * sin_half;
   41.40 -	rq.y = y * sin_half;
   41.41 -	rq.z = z * sin_half;
   41.42 -
   41.43 -	return quat_mul(q, rq);
   41.44 -}
   41.45 -
   41.46 -quat_t quat_rotate_quat(quat_t q, quat_t rotq)
   41.47 -{
   41.48 -	return quat_mul(quat_mul(rotq, q), quat_conjugate(rotq));
   41.49 -}
   41.50 -
   41.51 -quat_t quat_slerp(quat_t q1, quat_t q2, scalar_t t)
   41.52 -{
   41.53 -	quat_t res;
   41.54 -	scalar_t a, b, angle, sin_angle, dot;
   41.55 -
   41.56 -	dot = q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z;
   41.57 -	if(dot < 0.0) {
   41.58 -		/* make sure we interpolate across the shortest arc */
   41.59 -		q1.x = -q1.x;
   41.60 -		q1.y = -q1.y;
   41.61 -		q1.z = -q1.z;
   41.62 -		q1.w = -q1.w;
   41.63 -		dot = -dot;
   41.64 -	}
   41.65 -
   41.66 -	/* clamp dot to [-1, 1] in order to avoid domain errors in acos due to
   41.67 -	 * floating point imprecisions
   41.68 -	 */
   41.69 -	if(dot < -1.0) dot = -1.0;
   41.70 -	if(dot > 1.0) dot = 1.0;
   41.71 -
   41.72 -	angle = acos(dot);
   41.73 -	sin_angle = sin(angle);
   41.74 -
   41.75 -	if(fabs(sin_angle) < SMALL_NUMBER) {
   41.76 -		/* for very small angles or completely opposite orientations
   41.77 -		 * use linear interpolation to avoid div/zero (in the first case it makes sense,
   41.78 -		 * the second case is pretty much undefined anyway I guess ...
   41.79 -		 */
   41.80 -		a = 1.0f - t;
   41.81 -		b = t;
   41.82 -	} else {
   41.83 -		a = sin((1.0f - t) * angle) / sin_angle;
   41.84 -		b = sin(t * angle) / sin_angle;
   41.85 -	}
   41.86 -
   41.87 -	res.x = q1.x * a + q2.x * b;
   41.88 -	res.y = q1.y * a + q2.y * b;
   41.89 -	res.z = q1.z * a + q2.z * b;
   41.90 -	res.w = q1.w * a + q2.w * b;
   41.91 -	return res;
   41.92 -}
    42.1 --- a/libs/vmath/ray.cc	Thu Apr 17 08:50:36 2014 +0300
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,39 +0,0 @@
    42.4 -#include "ray.h"
    42.5 -#include "vector.h"
    42.6 -
    42.7 -scalar_t Ray::env_ior = 1.0;
    42.8 -
    42.9 -Ray::Ray()
   42.10 -{
   42.11 -	ior = env_ior;
   42.12 -	energy = 1.0;
   42.13 -	time = 0;
   42.14 -	iter = 0;
   42.15 -}
   42.16 -
   42.17 -Ray::Ray(const Vector3 &origin, const Vector3 &dir)
   42.18 -{
   42.19 -	this->origin = origin;
   42.20 -	this->dir = dir;
   42.21 -	ior = env_ior;
   42.22 -	energy = 1.0;
   42.23 -	time = 0;
   42.24 -	iter = 0;
   42.25 -}
   42.26 -
   42.27 -void Ray::transform(const Matrix4x4 &xform)
   42.28 -{
   42.29 -	Matrix4x4 upper = xform;
   42.30 -	upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
   42.31 -	upper[3][3] = 1.0;
   42.32 -
   42.33 -	dir.transform(upper);
   42.34 -	origin.transform(xform);
   42.35 -}
   42.36 -
   42.37 -Ray Ray::transformed(const Matrix4x4 &xform) const
   42.38 -{
   42.39 -	Ray foo = *this;
   42.40 -	foo.transform(xform);
   42.41 -	return foo;
   42.42 -}
    43.1 --- a/libs/vmath/ray.h	Thu Apr 17 08:50:36 2014 +0300
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,64 +0,0 @@
    43.4 -/*
    43.5 -libvmath - a vector math library
    43.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    43.7 -
    43.8 -This program is free software: you can redistribute it and/or modify
    43.9 -it under the terms of the GNU Lesser General Public License as published
   43.10 -by the Free Software Foundation, either version 3 of the License, or
   43.11 -(at your option) any later version.
   43.12 -
   43.13 -This program is distributed in the hope that it will be useful,
   43.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   43.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   43.16 -GNU Lesser General Public License for more details.
   43.17 -
   43.18 -You should have received a copy of the GNU Lesser General Public License
   43.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   43.20 -*/
   43.21 -
   43.22 -#ifndef VMATH_RAY_H_
   43.23 -#define VMATH_RAY_H_
   43.24 -
   43.25 -#include "matrix.h"
   43.26 -#include "vector.h"
   43.27 -
   43.28 -typedef struct {
   43.29 -	vec3_t origin, dir;
   43.30 -} ray_t;
   43.31 -
   43.32 -#ifdef __cplusplus
   43.33 -extern "C" {
   43.34 -#endif	/* __cplusplus */
   43.35 -
   43.36 -static VMATH_INLINE ray_t ray_cons(vec3_t origin, vec3_t dir);
   43.37 -ray_t ray_transform(ray_t r, mat4_t m);
   43.38 -
   43.39 -#ifdef __cplusplus
   43.40 -}	/* __cplusplus */
   43.41 -
   43.42 -#include <stack>
   43.43 -
   43.44 -class Ray {
   43.45 -public:
   43.46 -	static scalar_t env_ior;
   43.47 -
   43.48 -	Vector3 origin, dir;
   43.49 -	scalar_t energy;
   43.50 -	int iter;
   43.51 -	scalar_t ior;
   43.52 -	long time;
   43.53 -
   43.54 -	Ray();
   43.55 -	Ray(const Vector3 &origin, const Vector3 &dir);
   43.56 -
   43.57 -	void transform(const Matrix4x4 &xform);
   43.58 -	Ray transformed(const Matrix4x4 &xform) const;
   43.59 -};
   43.60 -
   43.61 -VMATH_INLINE Ray reflect_ray(const Ray &inray, const Vector3 &norm);
   43.62 -VMATH_INLINE Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t from_ior, scalar_t to_ior);
   43.63 -#endif	/* __cplusplus */
   43.64 -
   43.65 -#include "ray.inl"
   43.66 -
   43.67 -#endif	/* VMATH_RAY_H_ */
    44.1 --- a/libs/vmath/ray.inl	Thu Apr 17 08:50:36 2014 +0300
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,52 +0,0 @@
    44.4 -/*
    44.5 -libvmath - a vector math library
    44.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    44.7 -
    44.8 -This program is free software: you can redistribute it and/or modify
    44.9 -it under the terms of the GNU Lesser General Public License as published
   44.10 -by the Free Software Foundation, either version 3 of the License, or
   44.11 -(at your option) any later version.
   44.12 -
   44.13 -This program is distributed in the hope that it will be useful,
   44.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   44.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   44.16 -GNU Lesser General Public License for more details.
   44.17 -
   44.18 -You should have received a copy of the GNU Lesser General Public License
   44.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   44.20 -*/
   44.21 -
   44.22 -#ifdef __cplusplus
   44.23 -extern "C" {
   44.24 -#endif	/* __cplusplus */
   44.25 -
   44.26 -static VMATH_INLINE ray_t ray_cons(vec3_t origin, vec3_t dir)
   44.27 -{
   44.28 -	ray_t r;
   44.29 -	r.origin = origin;
   44.30 -	r.dir = dir;
   44.31 -	return r;
   44.32 -}
   44.33 -
   44.34 -#ifdef __cplusplus
   44.35 -}
   44.36 -
   44.37 -VMATH_INLINE Ray reflect_ray(const Ray &inray, const Vector3 &norm)
   44.38 -{
   44.39 -	Ray ray = inray;
   44.40 -	ray.dir = ray.dir.reflection(norm);
   44.41 -	return ray;
   44.42 -}
   44.43 -
   44.44 -VMATH_INLINE Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t from_ior, scalar_t to_ior)
   44.45 -{
   44.46 -	Ray ray = inray;
   44.47 -	ray.dir = ray.dir.refraction(norm, from_ior, to_ior);
   44.48 -
   44.49 -	/* check TIR */
   44.50 -	if(dot_product(ray.dir, norm) > 0.0) {
   44.51 -		return reflect_ray(inray, norm);
   44.52 -	}
   44.53 -	return ray;
   44.54 -}
   44.55 -#endif	/* __cplusplus */
    45.1 --- a/libs/vmath/ray_c.c	Thu Apr 17 08:50:36 2014 +0300
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,36 +0,0 @@
    45.4 -/*
    45.5 -libvmath - a vector math library
    45.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    45.7 -
    45.8 -This program is free software: you can redistribute it and/or modify
    45.9 -it under the terms of the GNU Lesser General Public License as published
   45.10 -by the Free Software Foundation, either version 3 of the License, or
   45.11 -(at your option) any later version.
   45.12 -
   45.13 -This program is distributed in the hope that it will be useful,
   45.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   45.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   45.16 -GNU Lesser General Public License for more details.
   45.17 -
   45.18 -You should have received a copy of the GNU Lesser General Public License
   45.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   45.20 -*/
   45.21 -
   45.22 -#include "ray.h"
   45.23 -#include "vector.h"
   45.24 -
   45.25 -ray_t ray_transform(ray_t r, mat4_t xform)
   45.26 -{
   45.27 -	mat4_t upper;
   45.28 -	vec3_t dir;
   45.29 -
   45.30 -	m4_copy(upper, xform);
   45.31 -	upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
   45.32 -	upper[3][3] = 1.0;
   45.33 -
   45.34 -	dir = v3_sub(r.dir, r.origin);
   45.35 -	dir = v3_transform(dir, upper);
   45.36 -	r.origin = v3_transform(r.origin, xform);
   45.37 -	r.dir = v3_add(dir, r.origin);
   45.38 -	return r;
   45.39 -}
    46.1 --- a/libs/vmath/sphvec.cc	Thu Apr 17 08:50:36 2014 +0300
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,27 +0,0 @@
    46.4 -#include "sphvec.h"
    46.5 -#include "vector.h"
    46.6 -
    46.7 -/* theta: 0 <= theta <= 2pi, the angle around Y axis.
    46.8 - * phi: 0 <= phi <= pi, the angle from Y axis.
    46.9 - * r: radius.
   46.10 - */
   46.11 -SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) {
   46.12 -	this->theta = theta;
   46.13 -	this->phi = phi;
   46.14 -	this->r = r;
   46.15 -}
   46.16 -
   46.17 -/* Constructs a spherical coordinate vector from a cartesian vector */
   46.18 -SphVector::SphVector(const Vector3 &cvec) {
   46.19 -	*this = cvec;
   46.20 -}
   46.21 -
   46.22 -/* Assignment operator that converts cartesian to spherical coords */
   46.23 -SphVector &SphVector::operator =(const Vector3 &cvec) {
   46.24 -	r = cvec.length();
   46.25 -	//theta = atan2(cvec.y, cvec.x);
   46.26 -	theta = atan2(cvec.z, cvec.x);
   46.27 -	//phi = acos(cvec.z / r);
   46.28 -	phi = acos(cvec.y / r);
   46.29 -	return *this;
   46.30 -}
    47.1 --- a/libs/vmath/sphvec.h	Thu Apr 17 08:50:36 2014 +0300
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,36 +0,0 @@
    47.4 -/*
    47.5 -libvmath - a vector math library
    47.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    47.7 -
    47.8 -This program is free software: you can redistribute it and/or modify
    47.9 -it under the terms of the GNU Lesser General Public License as published
   47.10 -by the Free Software Foundation, either version 3 of the License, or
   47.11 -(at your option) any later version.
   47.12 -
   47.13 -This program is distributed in the hope that it will be useful,
   47.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   47.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   47.16 -GNU Lesser General Public License for more details.
   47.17 -
   47.18 -You should have received a copy of the GNU Lesser General Public License
   47.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   47.20 -*/
   47.21 -
   47.22 -#ifndef VMATH_SPHVEC_H_
   47.23 -#define VMATH_SPHVEC_H_
   47.24 -
   47.25 -#include "vmath_types.h"
   47.26 -
   47.27 -#ifdef __cplusplus
   47.28 -/* Vector in spherical coordinates */
   47.29 -class SphVector {
   47.30 -public:
   47.31 -	scalar_t theta, phi, r;
   47.32 -
   47.33 -	SphVector(scalar_t theta = 0.0, scalar_t phi = 0.0, scalar_t r = 1.0);
   47.34 -	SphVector(const Vector3 &cvec);
   47.35 -	SphVector &operator =(const Vector3 &cvec);
   47.36 -};
   47.37 -#endif	/* __cplusplus */
   47.38 -
   47.39 -#endif	/* VMATH_SPHVEC_H_ */
    48.1 --- a/libs/vmath/vector.cc	Thu Apr 17 08:50:36 2014 +0300
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,326 +0,0 @@
    48.4 -#include "vector.h"
    48.5 -#include "vmath.h"
    48.6 -
    48.7 -// ---------- Vector2 -----------
    48.8 -
    48.9 -Vector2::Vector2(scalar_t x, scalar_t y)
   48.10 -{
   48.11 -	this->x = x;
   48.12 -	this->y = y;
   48.13 -}
   48.14 -
   48.15 -Vector2::Vector2(const vec2_t &vec)
   48.16 -{
   48.17 -	x = vec.x;
   48.18 -	y = vec.y;
   48.19 -}
   48.20 -
   48.21 -Vector2::Vector2(const Vector3 &vec)
   48.22 -{
   48.23 -	x = vec.x;
   48.24 -	y = vec.y;
   48.25 -}
   48.26 -
   48.27 -Vector2::Vector2(const Vector4 &vec)
   48.28 -{
   48.29 -	x = vec.x;
   48.30 -	y = vec.y;
   48.31 -}
   48.32 -
   48.33 -void Vector2::normalize()
   48.34 -{
   48.35 -	scalar_t len = length();
   48.36 -	x /= len;
   48.37 -	y /= len;
   48.38 -}
   48.39 -
   48.40 -Vector2 Vector2::normalized() const
   48.41 -{
   48.42 -	scalar_t len = length();
   48.43 -	return Vector2(x / len, y / len);
   48.44 -}
   48.45 -
   48.46 -void Vector2::transform(const Matrix3x3 &mat)
   48.47 -{
   48.48 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2];
   48.49 -	y = mat[1][0] * x + mat[1][1] * y + mat[1][2];
   48.50 -	x = nx;
   48.51 -}
   48.52 -
   48.53 -Vector2 Vector2::transformed(const Matrix3x3 &mat) const
   48.54 -{
   48.55 -	Vector2 vec;
   48.56 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2];
   48.57 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2];
   48.58 -	return vec;
   48.59 -}
   48.60 -
   48.61 -void Vector2::rotate(scalar_t angle)
   48.62 -{
   48.63 -	*this = Vector2(cos(angle) * x - sin(angle) * y, sin(angle) * x + cos(angle) * y);
   48.64 -}
   48.65 -
   48.66 -Vector2 Vector2::rotated(scalar_t angle) const
   48.67 -{
   48.68 -	return Vector2(cos(angle) * x - sin(angle) * y, sin(angle) * x + cos(angle) * y);
   48.69 -}
   48.70 -
   48.71 -Vector2 Vector2::reflection(const Vector2 &normal) const
   48.72 -{
   48.73 -	return 2.0 * dot_product(*this, normal) * normal - *this;
   48.74 -}
   48.75 -
   48.76 -Vector2 Vector2::refraction(const Vector2 &normal, scalar_t src_ior, scalar_t dst_ior) const
   48.77 -{
   48.78 -	// quick and dirty implementation :)
   48.79 -	Vector3 v3refr = Vector3(this->x, this->y, 1.0).refraction(Vector3(this->x, this->y, 1), src_ior, dst_ior);
   48.80 -	return Vector2(v3refr.x, v3refr.y);
   48.81 -}
   48.82 -
   48.83 -std::ostream &operator <<(std::ostream &out, const Vector2 &vec)
   48.84 -{
   48.85 -	out << "[" << vec.x << " " << vec.y << "]";
   48.86 -	return out;
   48.87 -}
   48.88 -
   48.89 -
   48.90 -
   48.91 -// --------- Vector3 ----------
   48.92 -
   48.93 -Vector3::Vector3(scalar_t x, scalar_t y, scalar_t z)
   48.94 -{
   48.95 -	this->x = x;
   48.96 -	this->y = y;
   48.97 -	this->z = z;
   48.98 -}
   48.99 -
  48.100 -Vector3::Vector3(const vec3_t &vec)
  48.101 -{
  48.102 -	x = vec.x;
  48.103 -	y = vec.y;
  48.104 -	z = vec.z;
  48.105 -}
  48.106 -
  48.107 -Vector3::Vector3(const Vector2 &vec)
  48.108 -{
  48.109 -	x = vec.x;
  48.110 -	y = vec.y;
  48.111 -	z = 1;
  48.112 -}
  48.113 -
  48.114 -Vector3::Vector3(const Vector4 &vec)
  48.115 -{
  48.116 -	x = vec.x;
  48.117 -	y = vec.y;
  48.118 -	z = vec.z;
  48.119 -}
  48.120 -
  48.121 -Vector3::Vector3(const SphVector &sph)
  48.122 -{
  48.123 -	*this = sph;
  48.124 -}
  48.125 -
  48.126 -Vector3 &Vector3::operator =(const SphVector &sph)
  48.127 -{
  48.128 -	x = sph.r * cos(sph.theta) * sin(sph.phi);
  48.129 -	z = sph.r * sin(sph.theta) * sin(sph.phi);
  48.130 -	y = sph.r * cos(sph.phi);
  48.131 -	return *this;
  48.132 -}
  48.133 -
  48.134 -void Vector3::normalize()
  48.135 -{
  48.136 -	scalar_t len = length();
  48.137 -	x /= len;
  48.138 -	y /= len;
  48.139 -	z /= len;
  48.140 -}
  48.141 -
  48.142 -Vector3 Vector3::normalized() const
  48.143 -{
  48.144 -	scalar_t len = length();
  48.145 -	return Vector3(x / len, y / len, z / len);
  48.146 -}
  48.147 -
  48.148 -Vector3 Vector3::reflection(const Vector3 &normal) const
  48.149 -{
  48.150 -	return 2.0 * dot_product(*this, normal) * normal - *this;
  48.151 -}
  48.152 -
  48.153 -Vector3 Vector3::refraction(const Vector3 &normal, scalar_t src_ior, scalar_t dst_ior) const
  48.154 -{
  48.155 -	return refraction(normal, src_ior / dst_ior);
  48.156 -}
  48.157 -
  48.158 -Vector3 Vector3::refraction(const Vector3 &normal, scalar_t ior) const
  48.159 -{
  48.160 -	scalar_t cos_inc = dot_product(*this, -normal);
  48.161 -
  48.162 -	scalar_t radical = 1.0 + SQ(ior) * (SQ(cos_inc) - 1.0);
  48.163 -
  48.164 -	if(radical < 0.0) {		// total internal reflection
  48.165 -		return -reflection(normal);
  48.166 -	}
  48.167 -
  48.168 -	scalar_t beta = ior * cos_inc - sqrt(radical);
  48.169 -
  48.170 -	return *this * ior + normal * beta;
  48.171 -}
  48.172 -
  48.173 -void Vector3::transform(const Matrix3x3 &mat)
  48.174 -{
  48.175 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z;
  48.176 -	scalar_t ny = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z;
  48.177 -	z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z;
  48.178 -	x = nx;
  48.179 -	y = ny;
  48.180 -}
  48.181 -
  48.182 -Vector3 Vector3::transformed(const Matrix3x3 &mat) const
  48.183 -{
  48.184 -	Vector3 vec;
  48.185 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z;
  48.186 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z;
  48.187 -	vec.z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z;
  48.188 -	return vec;
  48.189 -}
  48.190 -
  48.191 -void Vector3::transform(const Matrix4x4 &mat)
  48.192 -{
  48.193 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
  48.194 -	scalar_t ny = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
  48.195 -	z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
  48.196 -	x = nx;
  48.197 -	y = ny;
  48.198 -}
  48.199 -
  48.200 -Vector3 Vector3::transformed(const Matrix4x4 &mat) const
  48.201 -{
  48.202 -	Vector3 vec;
  48.203 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
  48.204 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
  48.205 -	vec.z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
  48.206 -	return vec;
  48.207 -}
  48.208 -
  48.209 -void Vector3::transform(const Quaternion &quat)
  48.210 -{
  48.211 -	Quaternion vq(0.0f, *this);
  48.212 -	vq = quat * vq * quat.inverse();
  48.213 -	*this = vq.v;
  48.214 -}
  48.215 -
  48.216 -Vector3 Vector3::transformed(const Quaternion &quat) const
  48.217 -{
  48.218 -	Quaternion vq(0.0f, *this);
  48.219 -	vq = quat * vq * quat.inverse();
  48.220 -	return vq.v;
  48.221 -}
  48.222 -
  48.223 -void Vector3::rotate(const Vector3 &euler)
  48.224 -{
  48.225 -	Matrix4x4 rot;
  48.226 -	rot.set_rotation(euler);
  48.227 -	transform(rot);
  48.228 -}
  48.229 -
  48.230 -Vector3 Vector3::rotated(const Vector3 &euler) const
  48.231 -{
  48.232 -	Matrix4x4 rot;
  48.233 -	rot.set_rotation(euler);
  48.234 -	return transformed(rot);
  48.235 -}
  48.236 -
  48.237 -std::ostream &operator <<(std::ostream &out, const Vector3 &vec)
  48.238 -{
  48.239 -	out << "[" << vec.x << " " << vec.y << " " << vec.z << "]";
  48.240 -	return out;
  48.241 -}
  48.242 -
  48.243 -
  48.244 -// -------------- Vector4 --------------
  48.245 -Vector4::Vector4(scalar_t x, scalar_t y, scalar_t z, scalar_t w)
  48.246 -{
  48.247 -	this->x = x;
  48.248 -	this->y = y;
  48.249 -	this->z = z;
  48.250 -	this->w = w;
  48.251 -}
  48.252 -
  48.253 -Vector4::Vector4(const vec4_t &vec)
  48.254 -{
  48.255 -	x = vec.x;
  48.256 -	y = vec.y;
  48.257 -	z = vec.z;
  48.258 -	w = vec.w;
  48.259 -}
  48.260 -
  48.261 -Vector4::Vector4(const Vector2 &vec)
  48.262 -{
  48.263 -	x = vec.x;
  48.264 -	y = vec.y;
  48.265 -	z = 1;
  48.266 -	w = 1;
  48.267 -}
  48.268 -
  48.269 -Vector4::Vector4(const Vector3 &vec)
  48.270 -{
  48.271 -	x = vec.x;
  48.272 -	y = vec.y;
  48.273 -	z = vec.z;
  48.274 -	w = 1;
  48.275 -}
  48.276 -
  48.277 -void Vector4::normalize()
  48.278 -{
  48.279 -	scalar_t len = (scalar_t)sqrt(x*x + y*y + z*z + w*w);
  48.280 -	x /= len;
  48.281 -	y /= len;
  48.282 -	z /= len;
  48.283 -	w /= len;
  48.284 -}
  48.285 -
  48.286 -Vector4 Vector4::normalized() const
  48.287 -{
  48.288 -	scalar_t len = (scalar_t)sqrt(x*x + y*y + z*z + w*w);
  48.289 -	return Vector4(x / len, y / len, z / len, w / len);
  48.290 -}
  48.291 -
  48.292 -void Vector4::transform(const Matrix4x4 &mat)
  48.293 -{
  48.294 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3] * w;
  48.295 -	scalar_t ny = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3] * w;
  48.296 -	scalar_t nz = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3] * w;
  48.297 -	w = mat[3][0] * x + mat[3][1] * y + mat[3][2] * z + mat[3][3] * w;
  48.298 -	x = nx;
  48.299 -	y = ny;
  48.300 -	z = nz;
  48.301 -}
  48.302 -
  48.303 -Vector4 Vector4::transformed(const Matrix4x4 &mat) const
  48.304 -{
  48.305 -	Vector4 vec;
  48.306 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3] * w;
  48.307 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3] * w;
  48.308 -	vec.z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3] * w;
  48.309 -	vec.w = mat[3][0] * x + mat[3][1] * y + mat[3][2] * z + mat[3][3] * w;
  48.310 -	return vec;
  48.311 -}
  48.312 -
  48.313 -// TODO: implement 4D vector reflection
  48.314 -Vector4 Vector4::reflection(const Vector4 &normal) const
  48.315 -{
  48.316 -	return *this;
  48.317 -}
  48.318 -
  48.319 -// TODO: implement 4D vector refraction
  48.320 -Vector4 Vector4::refraction(const Vector4 &normal, scalar_t src_ior, scalar_t dst_ior) const
  48.321 -{
  48.322 -	return *this;
  48.323 -}
  48.324 -
  48.325 -std::ostream &operator <<(std::ostream &out, const Vector4 &vec)
  48.326 -{
  48.327 -	out << "[" << vec.x << " " << vec.y << " " << vec.z << " " << vec.w << "]";
  48.328 -	return out;
  48.329 -}
    49.1 --- a/libs/vmath/vector.h	Thu Apr 17 08:50:36 2014 +0300
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,292 +0,0 @@
    49.4 -/*
    49.5 -libvmath - a vector math library
    49.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    49.7 -
    49.8 -This program is free software: you can redistribute it and/or modify
    49.9 -it under the terms of the GNU Lesser General Public License as published
   49.10 -by the Free Software Foundation, either version 3 of the License, or
   49.11 -(at your option) any later version.
   49.12 -
   49.13 -This program is distributed in the hope that it will be useful,
   49.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   49.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   49.16 -GNU Lesser General Public License for more details.
   49.17 -
   49.18 -You should have received a copy of the GNU Lesser General Public License
   49.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   49.20 -*/
   49.21 -
   49.22 -#ifndef VMATH_VECTOR_H_
   49.23 -#define VMATH_VECTOR_H_
   49.24 -
   49.25 -#include <stdio.h>
   49.26 -#include "vmath_types.h"
   49.27 -
   49.28 -#ifdef __cplusplus
   49.29 -extern "C" {
   49.30 -#endif	/* __cplusplus */
   49.31 -
   49.32 -/* C 2D vector functions */
   49.33 -static VMATH_INLINE vec2_t v2_cons(scalar_t x, scalar_t y);
   49.34 -static VMATH_INLINE void v2_print(FILE *fp, vec2_t v);
   49.35 -
   49.36 -static VMATH_INLINE vec2_t v2_add(vec2_t v1, vec2_t v2);
   49.37 -static VMATH_INLINE vec2_t v2_sub(vec2_t v1, vec2_t v2);
   49.38 -static VMATH_INLINE vec2_t v2_scale(vec2_t v, scalar_t s);
   49.39 -static VMATH_INLINE scalar_t v2_dot(vec2_t v1, vec2_t v2);
   49.40 -static VMATH_INLINE scalar_t v2_length(vec2_t v);
   49.41 -static VMATH_INLINE scalar_t v2_length_sq(vec2_t v);
   49.42 -static VMATH_INLINE vec2_t v2_normalize(vec2_t v);
   49.43 -
   49.44 -static VMATH_INLINE vec2_t v2_lerp(vec2_t v1, vec2_t v2, scalar_t t);
   49.45 -
   49.46 -/* C 3D vector functions */
   49.47 -static VMATH_INLINE vec3_t v3_cons(scalar_t x, scalar_t y, scalar_t z);
   49.48 -static VMATH_INLINE void v3_print(FILE *fp, vec3_t v);
   49.49 -
   49.50 -static VMATH_INLINE vec3_t v3_add(vec3_t v1, vec3_t v2);
   49.51 -static VMATH_INLINE vec3_t v3_sub(vec3_t v1, vec3_t v2);
   49.52 -static VMATH_INLINE vec3_t v3_neg(vec3_t v);
   49.53 -static VMATH_INLINE vec3_t v3_mul(vec3_t v1, vec3_t v2);
   49.54 -static VMATH_INLINE vec3_t v3_scale(vec3_t v1, scalar_t s);
   49.55 -static VMATH_INLINE scalar_t v3_dot(vec3_t v1, vec3_t v2);
   49.56 -static VMATH_INLINE vec3_t v3_cross(vec3_t v1, vec3_t v2);
   49.57 -static VMATH_INLINE scalar_t v3_length(vec3_t v);
   49.58 -static VMATH_INLINE scalar_t v3_length_sq(vec3_t v);
   49.59 -static VMATH_INLINE vec3_t v3_normalize(vec3_t v);
   49.60 -static VMATH_INLINE vec3_t v3_transform(vec3_t v, mat4_t m);
   49.61 -
   49.62 -static VMATH_INLINE vec3_t v3_rotate(vec3_t v, scalar_t x, scalar_t y, scalar_t z);
   49.63 -static VMATH_INLINE vec3_t v3_rotate_axis(vec3_t v, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   49.64 -static VMATH_INLINE vec3_t v3_rotate_quat(vec3_t v, quat_t q);
   49.65 -
   49.66 -static VMATH_INLINE vec3_t v3_reflect(vec3_t v, vec3_t n);
   49.67 -
   49.68 -static VMATH_INLINE vec3_t v3_lerp(vec3_t v1, vec3_t v2, scalar_t t);
   49.69 -
   49.70 -/* C 4D vector functions */
   49.71 -static VMATH_INLINE vec4_t v4_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t w);
   49.72 -static VMATH_INLINE void v4_print(FILE *fp, vec4_t v);
   49.73 -
   49.74 -static VMATH_INLINE vec4_t v4_add(vec4_t v1, vec4_t v2);
   49.75 -static VMATH_INLINE vec4_t v4_sub(vec4_t v1, vec4_t v2);
   49.76 -static VMATH_INLINE vec4_t v4_neg(vec4_t v);
   49.77 -static VMATH_INLINE vec4_t v4_mul(vec4_t v1, vec4_t v2);
   49.78 -static VMATH_INLINE vec4_t v4_scale(vec4_t v, scalar_t s);
   49.79 -static VMATH_INLINE scalar_t v4_dot(vec4_t v1, vec4_t v2);
   49.80 -static VMATH_INLINE scalar_t v4_length(vec4_t v);
   49.81 -static VMATH_INLINE scalar_t v4_length_sq(vec4_t v);
   49.82 -static VMATH_INLINE vec4_t v4_normalize(vec4_t v);
   49.83 -static VMATH_INLINE vec4_t v4_transform(vec4_t v, mat4_t m);
   49.84 -
   49.85 -#ifdef __cplusplus
   49.86 -}	/* extern "C" */
   49.87 -
   49.88 -/* when included from C++ source files, also define the vector classes */
   49.89 -#include <iostream>
   49.90 -
   49.91 -/** 2D Vector */
   49.92 -class Vector2 {
   49.93 -public:
   49.94 -	scalar_t x, y;
   49.95 -
   49.96 -	Vector2(scalar_t x = 0.0, scalar_t y = 0.0);
   49.97 -	Vector2(const vec2_t &vec);
   49.98 -	Vector2(const Vector3 &vec);
   49.99 -	Vector2(const Vector4 &vec);
  49.100 -
  49.101 -	VMATH_INLINE scalar_t &operator [](int elem);
  49.102 -	VMATH_INLINE const scalar_t &operator [](int elem) const;
  49.103 -
  49.104 -	VMATH_INLINE scalar_t length() const;
  49.105 -	VMATH_INLINE scalar_t length_sq() const;
  49.106 -	void normalize();
  49.107 -	Vector2 normalized() const;
  49.108 -
  49.109 -	void transform(const Matrix3x3 &mat);
  49.110 -	Vector2 transformed(const Matrix3x3 &mat) const;
  49.111 -
  49.112 -	void rotate(scalar_t angle);
  49.113 -	Vector2 rotated(scalar_t angle) const;
  49.114 -
  49.115 -	Vector2 reflection(const Vector2 &normal) const;
  49.116 -	Vector2 refraction(const Vector2 &normal, scalar_t src_ior, scalar_t dst_ior) const;
  49.117 -};
  49.118 -
  49.119 -/* unary operations */
  49.120 -VMATH_INLINE Vector2 operator -(const Vector2 &vec);
  49.121 -
  49.122 -/* binary vector (op) vector operations */
  49.123 -VMATH_INLINE scalar_t dot_product(const Vector2 &v1, const Vector2 &v2);
  49.124 -
  49.125 -VMATH_INLINE Vector2 operator +(const Vector2 &v1, const Vector2 &v2);
  49.126 -VMATH_INLINE Vector2 operator -(const Vector2 &v1, const Vector2 &v2);
  49.127 -VMATH_INLINE Vector2 operator *(const Vector2 &v1, const Vector2 &v2);
  49.128 -VMATH_INLINE Vector2 operator /(const Vector2 &v1, const Vector2 &v2);
  49.129 -VMATH_INLINE bool operator ==(const Vector2 &v1, const Vector2 &v2);
  49.130 -
  49.131 -VMATH_INLINE void operator +=(Vector2 &v1, const Vector2 &v2);
  49.132 -VMATH_INLINE void operator -=(Vector2 &v1, const Vector2 &v2);
  49.133 -VMATH_INLINE void operator *=(Vector2 &v1, const Vector2 &v2);
  49.134 -VMATH_INLINE void operator /=(Vector2 &v1, const Vector2 &v2);
  49.135 -
  49.136 -/* binary vector (op) scalar and scalar (op) vector operations */
  49.137 -VMATH_INLINE Vector2 operator +(const Vector2 &vec, scalar_t scalar);
  49.138 -VMATH_INLINE Vector2 operator +(scalar_t scalar, const Vector2 &vec);
  49.139 -VMATH_INLINE Vector2 operator -(const Vector2 &vec, scalar_t scalar);
  49.140 -VMATH_INLINE Vector2 operator *(const Vector2 &vec, scalar_t scalar);
  49.141 -VMATH_INLINE Vector2 operator *(scalar_t scalar, const Vector2 &vec);
  49.142 -VMATH_INLINE Vector2 operator /(const Vector2 &vec, scalar_t scalar);
  49.143 -
  49.144 -VMATH_INLINE void operator +=(Vector2 &vec, scalar_t scalar);
  49.145 -VMATH_INLINE void operator -=(Vector2 &vec, scalar_t scalar);
  49.146 -VMATH_INLINE void operator *=(Vector2 &vec, scalar_t scalar);
  49.147 -VMATH_INLINE void operator /=(Vector2 &vec, scalar_t scalar);
  49.148 -
  49.149 -std::ostream &operator <<(std::ostream &out, const Vector2 &vec);
  49.150 -
  49.151 -VMATH_INLINE Vector2 lerp(const Vector2 &a, const Vector2 &b, scalar_t t);
  49.152 -VMATH_INLINE Vector2 catmull_rom_spline(const Vector2 &v0, const Vector2 &v1,
  49.153 -		const Vector2 &v2, const Vector2 &v3, scalar_t t);
  49.154 -
  49.155 -/* 3D Vector */
  49.156 -class Vector3 {
  49.157 -public:
  49.158 -	scalar_t x, y, z;
  49.159 -
  49.160 -	Vector3(scalar_t x = 0.0, scalar_t y = 0.0, scalar_t z = 0.0);
  49.161 -	Vector3(const vec3_t &vec);
  49.162 -	Vector3(const Vector2 &vec);
  49.163 -	Vector3(const Vector4 &vec);
  49.164 -	Vector3(const SphVector &sph);
  49.165 -
  49.166 -	Vector3 &operator =(const SphVector &sph);
  49.167 -
  49.168 -	VMATH_INLINE scalar_t &operator [](int elem);
  49.169 -	VMATH_INLINE const scalar_t &operator [](int elem) const;
  49.170 -
  49.171 -	VMATH_INLINE scalar_t length() const;
  49.172 -	VMATH_INLINE scalar_t length_sq() const;
  49.173 -	void normalize();
  49.174 -	Vector3 normalized() const;
  49.175 -
  49.176 -	void transform(const Matrix3x3 &mat);
  49.177 -	Vector3 transformed(const Matrix3x3 &mat) const;
  49.178 -	void transform(const Matrix4x4 &mat);
  49.179 -	Vector3 transformed(const Matrix4x4 &mat) const;
  49.180 -	void transform(const Quaternion &quat);
  49.181 -	Vector3 transformed(const Quaternion &quat) const;
  49.182 -
  49.183 -	void rotate(const Vector3 &euler);
  49.184 -	Vector3 rotated(const Vector3 &euler) const;
  49.185 -
  49.186 -	Vector3 reflection(const Vector3 &normal) const;
  49.187 -	Vector3 refraction(const Vector3 &normal, scalar_t src_ior, scalar_t dst_ior) const;
  49.188 -	Vector3 refraction(const Vector3 &normal, scalar_t ior) const;
  49.189 -};
  49.190 -
  49.191 -/* unary operations */
  49.192 -VMATH_INLINE Vector3 operator -(const Vector3 &vec);
  49.193 -
  49.194 -/* binary vector (op) vector operations */
  49.195 -VMATH_INLINE scalar_t dot_product(const Vector3 &v1, const Vector3 &v2);
  49.196 -VMATH_INLINE Vector3 cross_product(const Vector3 &v1, const Vector3 &v2);
  49.197 -
  49.198 -VMATH_INLINE Vector3 operator +(const Vector3 &v1, const Vector3 &v2);
  49.199 -VMATH_INLINE Vector3 operator -(const Vector3 &v1, const Vector3 &v2);
  49.200 -VMATH_INLINE Vector3 operator *(const Vector3 &v1, const Vector3 &v2);
  49.201 -VMATH_INLINE Vector3 operator /(const Vector3 &v1, const Vector3 &v2);
  49.202 -VMATH_INLINE bool operator ==(const Vector3 &v1, const Vector3 &v2);
  49.203 -
  49.204 -VMATH_INLINE void operator +=(Vector3 &v1, const Vector3 &v2);
  49.205 -VMATH_INLINE void operator -=(Vector3 &v1, const Vector3 &v2);
  49.206 -VMATH_INLINE void operator *=(Vector3 &v1, const Vector3 &v2);
  49.207 -VMATH_INLINE void operator /=(Vector3 &v1, const Vector3 &v2);
  49.208 -
  49.209 -/* binary vector (op) scalar and scalar (op) vector operations */
  49.210 -VMATH_INLINE Vector3 operator +(const Vector3 &vec, scalar_t scalar);
  49.211 -VMATH_INLINE Vector3 operator +(scalar_t scalar, const Vector3 &vec);
  49.212 -VMATH_INLINE Vector3 operator -(const Vector3 &vec, scalar_t scalar);
  49.213 -VMATH_INLINE Vector3 operator *(const Vector3 &vec, scalar_t scalar);
  49.214 -VMATH_INLINE Vector3 operator *(scalar_t scalar, const Vector3 &vec);
  49.215 -VMATH_INLINE Vector3 operator /(const Vector3 &vec, scalar_t scalar);
  49.216 -
  49.217 -VMATH_INLINE void operator +=(Vector3 &vec, scalar_t scalar);
  49.218 -VMATH_INLINE void operator -=(Vector3 &vec, scalar_t scalar);
  49.219 -VMATH_INLINE void operator *=(Vector3 &vec, scalar_t scalar);
  49.220 -VMATH_INLINE void operator /=(Vector3 &vec, scalar_t scalar);
  49.221 -
  49.222 -std::ostream &operator <<(std::ostream &out, const Vector3 &vec);
  49.223 -
  49.224 -VMATH_INLINE Vector3 lerp(const Vector3 &a, const Vector3 &b, scalar_t t);
  49.225 -VMATH_INLINE Vector3 catmull_rom_spline(const Vector3 &v0, const Vector3 &v1,
  49.226 -		const Vector3 &v2, const Vector3 &v3, scalar_t t);
  49.227 -
  49.228 -/* 4D Vector */
  49.229 -class Vector4 {
  49.230 -public:
  49.231 -	scalar_t x, y, z, w;
  49.232 -
  49.233 -	Vector4(scalar_t x = 0.0, scalar_t y = 0.0, scalar_t z = 0.0, scalar_t w = 0.0);
  49.234 -	Vector4(const vec4_t &vec);
  49.235 -	Vector4(const Vector2 &vec);
  49.236 -	Vector4(const Vector3 &vec);
  49.237 -
  49.238 -	VMATH_INLINE scalar_t &operator [](int elem);
  49.239 -	VMATH_INLINE const scalar_t &operator [](int elem) const;
  49.240 -
  49.241 -	VMATH_INLINE scalar_t length() const;
  49.242 -	VMATH_INLINE scalar_t length_sq() const;
  49.243 -	void normalize();
  49.244 -	Vector4 normalized() const;
  49.245 -
  49.246 -	void transform(const Matrix4x4 &mat);
  49.247 -	Vector4 transformed(const Matrix4x4 &mat) const;
  49.248 -
  49.249 -	Vector4 reflection(const Vector4 &normal) const;
  49.250 -	Vector4 refraction(const Vector4 &normal, scalar_t src_ior, scalar_t dst_ior) const;
  49.251 -};
  49.252 -
  49.253 -
  49.254 -/* unary operations */
  49.255 -VMATH_INLINE Vector4 operator -(const Vector4 &vec);
  49.256 -
  49.257 -/* binary vector (op) vector operations */
  49.258 -VMATH_INLINE scalar_t dot_product(const Vector4 &v1, const Vector4 &v2);
  49.259 -VMATH_INLINE Vector4 cross_product(const Vector4 &v1, const Vector4 &v2, const Vector4 &v3);
  49.260 -
  49.261 -VMATH_INLINE Vector4 operator +(const Vector4 &v1, const Vector4 &v2);
  49.262 -VMATH_INLINE Vector4 operator -(const Vector4 &v1, const Vector4 &v2);
  49.263 -VMATH_INLINE Vector4 operator *(const Vector4 &v1, const Vector4 &v2);
  49.264 -VMATH_INLINE Vector4 operator /(const Vector4 &v1, const Vector4 &v2);
  49.265 -VMATH_INLINE bool operator ==(const Vector4 &v1, const Vector4 &v2);
  49.266 -
  49.267 -VMATH_INLINE void operator +=(Vector4 &v1, const Vector4 &v2);
  49.268 -VMATH_INLINE void operator -=(Vector4 &v1, const Vector4 &v2);
  49.269 -VMATH_INLINE void operator *=(Vector4 &v1, const Vector4 &v2);
  49.270 -VMATH_INLINE void operator /=(Vector4 &v1, const Vector4 &v2);
  49.271 -
  49.272 -/* binary vector (op) scalar and scalar (op) vector operations */
  49.273 -VMATH_INLINE Vector4 operator +(const Vector4 &vec, scalar_t scalar);
  49.274 -VMATH_INLINE Vector4 operator +(scalar_t scalar, const Vector4 &vec);
  49.275 -VMATH_INLINE Vector4 operator -(const Vector4 &vec, scalar_t scalar);
  49.276 -VMATH_INLINE Vector4 operator *(const Vector4 &vec, scalar_t scalar);
  49.277 -VMATH_INLINE Vector4 operator *(scalar_t scalar, const Vector4 &vec);
  49.278 -VMATH_INLINE Vector4 operator /(const Vector4 &vec, scalar_t scalar);
  49.279 -
  49.280 -VMATH_INLINE void operator +=(Vector4 &vec, scalar_t scalar);
  49.281 -VMATH_INLINE void operator -=(Vector4 &vec, scalar_t scalar);
  49.282 -VMATH_INLINE void operator *=(Vector4 &vec, scalar_t scalar);
  49.283 -VMATH_INLINE void operator /=(Vector4 &vec, scalar_t scalar);
  49.284 -
  49.285 -std::ostream &operator <<(std::ostream &out, const Vector4 &vec);
  49.286 -
  49.287 -VMATH_INLINE Vector4 lerp(const Vector4 &v0, const Vector4 &v1, scalar_t t);
  49.288 -VMATH_INLINE Vector4 catmull_rom_spline(const Vector4 &v0, const Vector4 &v1,
  49.289 -		const Vector4 &v2, const Vector4 &v3, scalar_t t);
  49.290 -
  49.291 -#endif	/* __cplusplus */
  49.292 -
  49.293 -#include "vector.inl"
  49.294 -
  49.295 -#endif	/* VMATH_VECTOR_H_ */
    50.1 --- a/libs/vmath/vector.inl	Thu Apr 17 08:50:36 2014 +0300
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,761 +0,0 @@
    50.4 -/*
    50.5 -libvmath - a vector math library
    50.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    50.7 -
    50.8 -This program is free software: you can redistribute it and/or modify
    50.9 -it under the terms of the GNU Lesser General Public License as published
   50.10 -by the Free Software Foundation, either version 3 of the License, or
   50.11 -(at your option) any later version.
   50.12 -
   50.13 -This program is distributed in the hope that it will be useful,
   50.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   50.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   50.16 -GNU Lesser General Public License for more details.
   50.17 -
   50.18 -You should have received a copy of the GNU Lesser General Public License
   50.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   50.20 -*/
   50.21 -
   50.22 -#include <math.h>
   50.23 -
   50.24 -#ifdef __cplusplus
   50.25 -extern "C" {
   50.26 -#endif	/* __cplusplus */
   50.27 -
   50.28 -/* C 2D vector functions */
   50.29 -static VMATH_INLINE vec2_t v2_cons(scalar_t x, scalar_t y)
   50.30 -{
   50.31 -	vec2_t v;
   50.32 -	v.x = x;
   50.33 -	v.y = y;
   50.34 -	return v;
   50.35 -}
   50.36 -
   50.37 -static VMATH_INLINE void v2_print(FILE *fp, vec2_t v)
   50.38 -{
   50.39 -	fprintf(fp, "[ %.4f %.4f ]", v.x, v.y);
   50.40 -}
   50.41 -
   50.42 -static VMATH_INLINE vec2_t v2_add(vec2_t v1, vec2_t v2)
   50.43 -{
   50.44 -	vec2_t res;
   50.45 -	res.x = v1.x + v2.x;
   50.46 -	res.y = v1.y + v2.y;
   50.47 -	return res;
   50.48 -}
   50.49 -
   50.50 -static VMATH_INLINE vec2_t v2_sub(vec2_t v1, vec2_t v2)
   50.51 -{
   50.52 -	vec2_t res;
   50.53 -	res.x = v1.x - v2.x;
   50.54 -	res.y = v1.y - v2.y;
   50.55 -	return res;
   50.56 -}
   50.57 -
   50.58 -static VMATH_INLINE vec2_t v2_scale(vec2_t v, scalar_t s)
   50.59 -{
   50.60 -	vec2_t res;
   50.61 -	res.x = v.x * s;
   50.62 -	res.y = v.y * s;
   50.63 -	return res;
   50.64 -}
   50.65 -
   50.66 -static VMATH_INLINE scalar_t v2_dot(vec2_t v1, vec2_t v2)
   50.67 -{
   50.68 -	return v1.x * v2.x + v1.y * v2.y;
   50.69 -}
   50.70 -
   50.71 -static VMATH_INLINE scalar_t v2_length(vec2_t v)
   50.72 -{
   50.73 -	return sqrt(v.x * v.x + v.y * v.y);
   50.74 -}
   50.75 -
   50.76 -static VMATH_INLINE scalar_t v2_length_sq(vec2_t v)
   50.77 -{
   50.78 -	return v.x * v.x + v.y * v.y;
   50.79 -}
   50.80 -
   50.81 -static VMATH_INLINE vec2_t v2_normalize(vec2_t v)
   50.82 -{
   50.83 -	scalar_t len = (scalar_t)sqrt(v.x * v.x + v.y * v.y);
   50.84 -	v.x /= len;
   50.85 -	v.y /= len;
   50.86 -	return v;
   50.87 -}
   50.88 -
   50.89 -static VMATH_INLINE vec2_t v2_lerp(vec2_t v1, vec2_t v2, scalar_t t)
   50.90 -{
   50.91 -	vec2_t res;
   50.92 -	res.x = v1.x + (v2.x - v1.x) * t;
   50.93 -	res.y = v1.y + (v2.y - v1.y) * t;
   50.94 -	return res;
   50.95 -}
   50.96 -
   50.97 -
   50.98 -/* C 3D vector functions */
   50.99 -static VMATH_INLINE vec3_t v3_cons(scalar_t x, scalar_t y, scalar_t z)
  50.100 -{
  50.101 -	vec3_t v;
  50.102 -	v.x = x;
  50.103 -	v.y = y;
  50.104 -	v.z = z;
  50.105 -	return v;
  50.106 -}
  50.107 -
  50.108 -static VMATH_INLINE void v3_print(FILE *fp, vec3_t v)
  50.109 -{
  50.110 -	fprintf(fp, "[ %.4f %.4f %.4f ]", v.x, v.y, v.z);
  50.111 -}
  50.112 -
  50.113 -static VMATH_INLINE vec3_t v3_add(vec3_t v1, vec3_t v2)
  50.114 -{
  50.115 -	v1.x += v2.x;
  50.116 -	v1.y += v2.y;
  50.117 -	v1.z += v2.z;
  50.118 -	return v1;
  50.119 -}
  50.120 -
  50.121 -static VMATH_INLINE vec3_t v3_sub(vec3_t v1, vec3_t v2)
  50.122 -{
  50.123 -	v1.x -= v2.x;
  50.124 -	v1.y -= v2.y;
  50.125 -	v1.z -= v2.z;
  50.126 -	return v1;
  50.127 -}
  50.128 -
  50.129 -static VMATH_INLINE vec3_t v3_neg(vec3_t v)
  50.130 -{
  50.131 -	v.x = -v.x;
  50.132 -	v.y = -v.y;
  50.133 -	v.z = -v.z;
  50.134 -	return v;
  50.135 -}
  50.136 -
  50.137 -static VMATH_INLINE vec3_t v3_mul(vec3_t v1, vec3_t v2)
  50.138 -{
  50.139 -	v1.x *= v2.x;
  50.140 -	v1.y *= v2.y;
  50.141 -	v1.z *= v2.z;
  50.142 -	return v1;
  50.143 -}
  50.144 -
  50.145 -static VMATH_INLINE vec3_t v3_scale(vec3_t v1, scalar_t s)
  50.146 -{
  50.147 -	v1.x *= s;
  50.148 -	v1.y *= s;
  50.149 -	v1.z *= s;
  50.150 -	return v1;
  50.151 -}
  50.152 -
  50.153 -static VMATH_INLINE scalar_t v3_dot(vec3_t v1, vec3_t v2)
  50.154 -{
  50.155 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
  50.156 -}
  50.157 -
  50.158 -static VMATH_INLINE vec3_t v3_cross(vec3_t v1, vec3_t v2)
  50.159 -{
  50.160 -	vec3_t v;
  50.161 -	v.x = v1.y * v2.z - v1.z * v2.y;
  50.162 -	v.y = v1.z * v2.x - v1.x * v2.z;
  50.163 -	v.z = v1.x * v2.y - v1.y * v2.x;
  50.164 -	return v;
  50.165 -}
  50.166 -
  50.167 -static VMATH_INLINE scalar_t v3_length(vec3_t v)
  50.168 -{
  50.169 -	return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
  50.170 -}
  50.171 -
  50.172 -static VMATH_INLINE scalar_t v3_length_sq(vec3_t v)
  50.173 -{
  50.174 -	return v.x * v.x + v.y * v.y + v.z * v.z;
  50.175 -}
  50.176 -
  50.177 -static VMATH_INLINE vec3_t v3_normalize(vec3_t v)
  50.178 -{
  50.179 -	scalar_t len = sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
  50.180 -	v.x /= len;
  50.181 -	v.y /= len;
  50.182 -	v.z /= len;
  50.183 -	return v;
  50.184 -}
  50.185 -
  50.186 -static VMATH_INLINE vec3_t v3_transform(vec3_t v, mat4_t m)
  50.187 -{
  50.188 -	vec3_t res;
  50.189 -	res.x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3];
  50.190 -	res.y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3];
  50.191 -	res.z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3];
  50.192 -	return res;
  50.193 -}
  50.194 -
  50.195 -static VMATH_INLINE vec3_t v3_rotate(vec3_t v, scalar_t x, scalar_t y, scalar_t z)
  50.196 -{
  50.197 -	void m4_rotate(mat4_t, scalar_t, scalar_t, scalar_t);
  50.198 -
  50.199 -	mat4_t m = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
  50.200 -	m4_rotate(m, x, y, z);
  50.201 -	return v3_transform(v, m);
  50.202 -}
  50.203 -
  50.204 -static VMATH_INLINE vec3_t v3_rotate_axis(vec3_t v, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
  50.205 -{
  50.206 -	void m4_rotate_axis(mat4_t, scalar_t, scalar_t, scalar_t, scalar_t);
  50.207 -
  50.208 -	mat4_t m = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
  50.209 -	m4_rotate_axis(m, angle, x, y, z);
  50.210 -	return v3_transform(v, m);
  50.211 -}
  50.212 -
  50.213 -static VMATH_INLINE vec3_t v3_rotate_quat(vec3_t v, quat_t q)
  50.214 -{
  50.215 -	quat_t quat_rotate_quat(quat_t, quat_t);
  50.216 -
  50.217 -	quat_t vq = v4_cons(v.x, v.y, v.z, 0.0);
  50.218 -	quat_t res = quat_rotate_quat(vq, q);
  50.219 -	return v3_cons(res.x, res.y, res.z);
  50.220 -}
  50.221 -
  50.222 -static VMATH_INLINE vec3_t v3_reflect(vec3_t v, vec3_t n)
  50.223 -{
  50.224 -	scalar_t dot = v3_dot(v, n);
  50.225 -	return v3_sub(v3_scale(n, dot * 2.0), v);
  50.226 -}
  50.227 -
  50.228 -static VMATH_INLINE vec3_t v3_lerp(vec3_t v1, vec3_t v2, scalar_t t)
  50.229 -{
  50.230 -	v1.x += (v2.x - v1.x) * t;
  50.231 -	v1.y += (v2.y - v1.y) * t;
  50.232 -	v1.z += (v2.z - v1.z) * t;
  50.233 -	return v1;
  50.234 -}
  50.235 -
  50.236 -/* C 4D vector functions */
  50.237 -static VMATH_INLINE vec4_t v4_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t w)
  50.238 -{
  50.239 -	vec4_t v;
  50.240 -	v.x = x;
  50.241 -	v.y = y;
  50.242 -	v.z = z;
  50.243 -	v.w = w;
  50.244 -	return v;
  50.245 -}
  50.246 -
  50.247 -static VMATH_INLINE void v4_print(FILE *fp, vec4_t v)
  50.248 -{
  50.249 -	fprintf(fp, "[ %.4f %.4f %.4f %.4f ]", v.x, v.y, v.z, v.w);
  50.250 -}
  50.251 -
  50.252 -static VMATH_INLINE vec4_t v4_add(vec4_t v1, vec4_t v2)
  50.253 -{
  50.254 -	v1.x += v2.x;
  50.255 -	v1.y += v2.y;
  50.256 -	v1.z += v2.z;
  50.257 -	v1.w += v2.w;
  50.258 -	return v1;
  50.259 -}
  50.260 -
  50.261 -static VMATH_INLINE vec4_t v4_sub(vec4_t v1, vec4_t v2)
  50.262 -{
  50.263 -	v1.x -= v2.x;
  50.264 -	v1.y -= v2.y;
  50.265 -	v1.z -= v2.z;
  50.266 -	v1.w -= v2.w;
  50.267 -	return v1;
  50.268 -}
  50.269 -
  50.270 -static VMATH_INLINE vec4_t v4_neg(vec4_t v)
  50.271 -{
  50.272 -	v.x = -v.x;
  50.273 -	v.y = -v.y;
  50.274 -	v.z = -v.z;
  50.275 -	v.w = -v.w;
  50.276 -	return v;
  50.277 -}
  50.278 -
  50.279 -static VMATH_INLINE vec4_t v4_mul(vec4_t v1, vec4_t v2)
  50.280 -{
  50.281 -	v1.x *= v2.x;
  50.282 -	v1.y *= v2.y;
  50.283 -	v1.z *= v2.z;
  50.284 -	v1.w *= v2.w;
  50.285 -	return v1;
  50.286 -}
  50.287 -
  50.288 -static VMATH_INLINE vec4_t v4_scale(vec4_t v, scalar_t s)
  50.289 -{
  50.290 -	v.x *= s;
  50.291 -	v.y *= s;
  50.292 -	v.z *= s;
  50.293 -	v.w *= s;
  50.294 -	return v;
  50.295 -}
  50.296 -
  50.297 -static VMATH_INLINE scalar_t v4_dot(vec4_t v1, vec4_t v2)
  50.298 -{
  50.299 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
  50.300 -}
  50.301 -
  50.302 -static VMATH_INLINE scalar_t v4_length(vec4_t v)
  50.303 -{
  50.304 -	return sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
  50.305 -}
  50.306 -
  50.307 -static VMATH_INLINE scalar_t v4_length_sq(vec4_t v)
  50.308 -{
  50.309 -	return v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w;
  50.310 -}
  50.311 -
  50.312 -static VMATH_INLINE vec4_t v4_normalize(vec4_t v)
  50.313 -{
  50.314 -	scalar_t len = sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
  50.315 -	v.x /= len;
  50.316 -	v.y /= len;
  50.317 -	v.z /= len;
  50.318 -	v.w /= len;
  50.319 -	return v;
  50.320 -}
  50.321 -
  50.322 -static VMATH_INLINE vec4_t v4_transform(vec4_t v, mat4_t m)
  50.323 -{
  50.324 -	vec4_t res;
  50.325 -	res.x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w;
  50.326 -	res.y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w;
  50.327 -	res.z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w;
  50.328 -	res.w = m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w;
  50.329 -	return res;
  50.330 -}
  50.331 -
  50.332 -#ifdef __cplusplus
  50.333 -}	/* extern "C" */
  50.334 -
  50.335 -
  50.336 -/* --------------- C++ part -------------- */
  50.337 -
  50.338 -VMATH_INLINE scalar_t &Vector2::operator [](int elem) {
  50.339 -	return elem ? y : x;
  50.340 -}
  50.341 -
  50.342 -VMATH_INLINE const scalar_t &Vector2::operator [](int elem) const {
  50.343 -	return elem ? y : x;
  50.344 -}
  50.345 -
  50.346 -VMATH_INLINE Vector2 operator -(const Vector2 &vec) {
  50.347 -	return Vector2(-vec.x, -vec.y);
  50.348 -}
  50.349 -
  50.350 -VMATH_INLINE scalar_t dot_product(const Vector2 &v1, const Vector2 &v2) {
  50.351 -	return v1.x * v2.x + v1.y * v2.y;
  50.352 -}
  50.353 -
  50.354 -VMATH_INLINE Vector2 operator +(const Vector2 &v1, const Vector2 &v2) {
  50.355 -	return Vector2(v1.x + v2.x, v1.y + v2.y);
  50.356 -}
  50.357 -
  50.358 -VMATH_INLINE Vector2 operator -(const Vector2 &v1, const Vector2 &v2) {
  50.359 -	return Vector2(v1.x - v2.x, v1.y - v2.y);
  50.360 -}
  50.361 -
  50.362 -VMATH_INLINE Vector2 operator *(const Vector2 &v1, const Vector2 &v2) {
  50.363 -	return Vector2(v1.x * v2.x, v1.y * v2.y);
  50.364 -}
  50.365 -
  50.366 -VMATH_INLINE Vector2 operator /(const Vector2 &v1, const Vector2 &v2) {
  50.367 -	return Vector2(v1.x / v2.x, v1.y / v2.y);
  50.368 -}
  50.369 -
  50.370 -VMATH_INLINE bool operator ==(const Vector2 &v1, const Vector2 &v2) {
  50.371 -	return (fabs(v1.x - v2.x) < XSMALL_NUMBER) && (fabs(v1.y - v2.x) < XSMALL_NUMBER);
  50.372 -}
  50.373 -
  50.374 -VMATH_INLINE void operator +=(Vector2 &v1, const Vector2 &v2) {
  50.375 -	v1.x += v2.x;
  50.376 -	v1.y += v2.y;
  50.377 -}
  50.378 -
  50.379 -VMATH_INLINE void operator -=(Vector2 &v1, const Vector2 &v2) {
  50.380 -	v1.x -= v2.x;
  50.381 -	v1.y -= v2.y;
  50.382 -}
  50.383 -
  50.384 -VMATH_INLINE void operator *=(Vector2 &v1, const Vector2 &v2) {
  50.385 -	v1.x *= v2.x;
  50.386 -	v1.y *= v2.y;
  50.387 -}
  50.388 -
  50.389 -VMATH_INLINE void operator /=(Vector2 &v1, const Vector2 &v2) {
  50.390 -	v1.x /= v2.x;
  50.391 -	v1.y /= v2.y;
  50.392 -}
  50.393 -
  50.394 -VMATH_INLINE Vector2 operator +(const Vector2 &vec, scalar_t scalar) {
  50.395 -	return Vector2(vec.x + scalar, vec.y + scalar);
  50.396 -}
  50.397 -
  50.398 -VMATH_INLINE Vector2 operator +(scalar_t scalar, const Vector2 &vec) {
  50.399 -	return Vector2(vec.x + scalar, vec.y + scalar);
  50.400 -}
  50.401 -
  50.402 -VMATH_INLINE Vector2 operator -(scalar_t scalar, const Vector2 &vec) {
  50.403 -	return Vector2(vec.x - scalar, vec.y - scalar);
  50.404 -}
  50.405 -
  50.406 -VMATH_INLINE Vector2 operator *(const Vector2 &vec, scalar_t scalar) {
  50.407 -	return Vector2(vec.x * scalar, vec.y * scalar);
  50.408 -}
  50.409 -
  50.410 -VMATH_INLINE Vector2 operator *(scalar_t scalar, const Vector2 &vec) {
  50.411 -	return Vector2(vec.x * scalar, vec.y * scalar);
  50.412 -}
  50.413 -
  50.414 -VMATH_INLINE Vector2 operator /(const Vector2 &vec, scalar_t scalar) {
  50.415 -	return Vector2(vec.x / scalar, vec.y / scalar);
  50.416 -}
  50.417 -
  50.418 -VMATH_INLINE void operator +=(Vector2 &vec, scalar_t scalar) {
  50.419 -	vec.x += scalar;
  50.420 -	vec.y += scalar;
  50.421 -}
  50.422 -
  50.423 -VMATH_INLINE void operator -=(Vector2 &vec, scalar_t scalar) {
  50.424 -	vec.x -= scalar;
  50.425 -	vec.y -= scalar;
  50.426 -}
  50.427 -
  50.428 -VMATH_INLINE void operator *=(Vector2 &vec, scalar_t scalar) {
  50.429 -	vec.x *= scalar;
  50.430 -	vec.y *= scalar;
  50.431 -}
  50.432 -
  50.433 -VMATH_INLINE void operator /=(Vector2 &vec, scalar_t scalar) {
  50.434 -	vec.x /= scalar;
  50.435 -	vec.y /= scalar;
  50.436 -}
  50.437 -
  50.438 -VMATH_INLINE scalar_t Vector2::length() const {
  50.439 -	return sqrt(x*x + y*y);
  50.440 -}
  50.441 -
  50.442 -VMATH_INLINE scalar_t Vector2::length_sq() const {
  50.443 -	return x*x + y*y;
  50.444 -}
  50.445 -
  50.446 -VMATH_INLINE Vector2 lerp(const Vector2 &a, const Vector2 &b, scalar_t t)
  50.447 -{
  50.448 -	return a + (b - a) * t;
  50.449 -}
  50.450 -
  50.451 -VMATH_INLINE Vector2 catmull_rom_spline(const Vector2 &v0, const Vector2 &v1,
  50.452 -		const Vector2 &v2, const Vector2 &v3, scalar_t t)
  50.453 -{
  50.454 -	scalar_t spline(scalar_t, scalar_t, scalar_t, scalar_t, scalar_t);
  50.455 -	scalar_t x = spline(v0.x, v1.x, v2.x, v3.x, t);
  50.456 -	scalar_t y = spline(v0.y, v1.y, v2.y, v3.y, t);
  50.457 -	return Vector2(x, y);
  50.458 -}
  50.459 -
  50.460 -
  50.461 -/* ------------- Vector3 -------------- */
  50.462 -
  50.463 -VMATH_INLINE scalar_t &Vector3::operator [](int elem) {
  50.464 -	return elem ? (elem == 1 ? y : z) : x;
  50.465 -}
  50.466 -
  50.467 -VMATH_INLINE const scalar_t &Vector3::operator [](int elem) const {
  50.468 -	return elem ? (elem == 1 ? y : z) : x;
  50.469 -}
  50.470 -
  50.471 -/* unary operations */
  50.472 -VMATH_INLINE Vector3 operator -(const Vector3 &vec) {
  50.473 -	return Vector3(-vec.x, -vec.y, -vec.z);
  50.474 -}
  50.475 -
  50.476 -/* binary vector (op) vector operations */
  50.477 -VMATH_INLINE scalar_t dot_product(const Vector3 &v1, const Vector3 &v2) {
  50.478 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
  50.479 -}
  50.480 -
  50.481 -VMATH_INLINE Vector3 cross_product(const Vector3 &v1, const Vector3 &v2) {
  50.482 -	return Vector3(v1.y * v2.z - v1.z * v2.y,  v1.z * v2.x - v1.x * v2.z,  v1.x * v2.y - v1.y * v2.x);
  50.483 -}
  50.484 -
  50.485 -
  50.486 -VMATH_INLINE Vector3 operator +(const Vector3 &v1, const Vector3 &v2) {
  50.487 -	return Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
  50.488 -}
  50.489 -
  50.490 -VMATH_INLINE Vector3 operator -(const Vector3 &v1, const Vector3 &v2) {
  50.491 -	return Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
  50.492 -}
  50.493 -
  50.494 -VMATH_INLINE Vector3 operator *(const Vector3 &v1, const Vector3 &v2) {
  50.495 -	return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
  50.496 -}
  50.497 -
  50.498 -VMATH_INLINE Vector3 operator /(const Vector3 &v1, const Vector3 &v2) {
  50.499 -	return Vector3(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z);
  50.500 -}
  50.501 -
  50.502 -VMATH_INLINE bool operator ==(const Vector3 &v1, const Vector3 &v2) {
  50.503 -	return (fabs(v1.x - v2.x) < XSMALL_NUMBER) && (fabs(v1.y - v2.y) < XSMALL_NUMBER) && (fabs(v1.z - v2.z) < XSMALL_NUMBER);
  50.504 -}
  50.505 -
  50.506 -VMATH_INLINE void operator +=(Vector3 &v1, const Vector3 &v2) {
  50.507 -	v1.x += v2.x;
  50.508 -	v1.y += v2.y;
  50.509 -	v1.z += v2.z;
  50.510 -}
  50.511 -
  50.512 -VMATH_INLINE void operator -=(Vector3 &v1, const Vector3 &v2) {
  50.513 -	v1.x -= v2.x;
  50.514 -	v1.y -= v2.y;
  50.515 -	v1.z -= v2.z;
  50.516 -}
  50.517 -
  50.518 -VMATH_INLINE void operator *=(Vector3 &v1, const Vector3 &v2) {
  50.519 -	v1.x *= v2.x;
  50.520 -	v1.y *= v2.y;
  50.521 -	v1.z *= v2.z;
  50.522 -}
  50.523 -
  50.524 -VMATH_INLINE void operator /=(Vector3 &v1, const Vector3 &v2) {
  50.525 -	v1.x /= v2.x;
  50.526 -	v1.y /= v2.y;
  50.527 -	v1.z /= v2.z;
  50.528 -}
  50.529 -/* binary vector (op) scalar and scalar (op) vector operations */
  50.530 -VMATH_INLINE Vector3 operator +(const Vector3 &vec, scalar_t scalar) {
  50.531 -	return Vector3(vec.x + scalar, vec.y + scalar, vec.z + scalar);
  50.532 -}
  50.533 -
  50.534 -VMATH_INLINE Vector3 operator +(scalar_t scalar, const Vector3 &vec) {
  50.535 -	return Vector3(vec.x + scalar, vec.y + scalar, vec.z + scalar);
  50.536 -}
  50.537 -
  50.538 -VMATH_INLINE Vector3 operator -(const Vector3 &vec, scalar_t scalar) {
  50.539 -	return Vector3(vec.x - scalar, vec.y - scalar, vec.z - scalar);
  50.540 -}
  50.541 -
  50.542 -VMATH_INLINE Vector3 operator *(const Vector3 &vec, scalar_t scalar) {
  50.543 -	return Vector3(vec.x * scalar, vec.y * scalar, vec.z * scalar);
  50.544 -}
  50.545 -
  50.546 -VMATH_INLINE Vector3 operator *(scalar_t scalar, const Vector3 &vec) {
  50.547 -	return Vector3(vec.x * scalar, vec.y * scalar, vec.z * scalar);
  50.548 -}
  50.549 -
  50.550 -VMATH_INLINE Vector3 operator /(const Vector3 &vec, scalar_t scalar) {
  50.551 -	return Vector3(vec.x / scalar, vec.y / scalar, vec.z / scalar);
  50.552 -}
  50.553 -
  50.554 -VMATH_INLINE void operator +=(Vector3 &vec, scalar_t scalar) {
  50.555 -	vec.x += scalar;
  50.556 -	vec.y += scalar;
  50.557 -	vec.z += scalar;
  50.558 -}
  50.559 -
  50.560 -VMATH_INLINE void operator -=(Vector3 &vec, scalar_t scalar) {
  50.561 -	vec.x -= scalar;
  50.562 -	vec.y -= scalar;
  50.563 -	vec.z -= scalar;
  50.564 -}
  50.565 -
  50.566 -VMATH_INLINE void operator *=(Vector3 &vec, scalar_t scalar) {
  50.567 -	vec.x *= scalar;
  50.568 -	vec.y *= scalar;
  50.569 -	vec.z *= scalar;
  50.570 -}
  50.571 -
  50.572 -VMATH_INLINE void operator /=(Vector3 &vec, scalar_t scalar) {
  50.573 -	vec.x /= scalar;
  50.574 -	vec.y /= scalar;
  50.575 -	vec.z /= scalar;
  50.576 -}
  50.577 -
  50.578 -VMATH_INLINE scalar_t Vector3::length() const {
  50.579 -	return sqrt(x*x + y*y + z*z);
  50.580 -}
  50.581 -VMATH_INLINE scalar_t Vector3::length_sq() const {
  50.582 -	return x*x + y*y + z*z;
  50.583 -}
  50.584 -
  50.585 -VMATH_INLINE Vector3 lerp(const Vector3 &a, const Vector3 &b, scalar_t t) {
  50.586 -	return a + (b - a) * t;
  50.587 -}
  50.588 -
  50.589 -VMATH_INLINE Vector3 catmull_rom_spline(const Vector3 &v0, const Vector3 &v1,
  50.590 -		const Vector3 &v2, const Vector3 &v3, scalar_t t)
  50.591 -{
  50.592 -	scalar_t spline(scalar_t, scalar_t, scalar_t, scalar_t, scalar_t);
  50.593 -	scalar_t x = spline(v0.x, v1.x, v2.x, v3.x, t);
  50.594 -	scalar_t y = spline(v0.y, v1.y, v2.y, v3.y, t);
  50.595 -	scalar_t z = spline(v0.z, v1.z, v2.z, v3.z, t);
  50.596 -	return Vector3(x, y, z);
  50.597 -}
  50.598 -
  50.599 -/* ----------- Vector4 ----------------- */
  50.600 -
  50.601 -VMATH_INLINE scalar_t &Vector4::operator [](int elem) {
  50.602 -	return elem ? (elem == 1 ? y : (elem == 2 ? z : w)) : x;
  50.603 -}
  50.604 -
  50.605 -VMATH_INLINE const scalar_t &Vector4::operator [](int elem) const {
  50.606 -	return elem ? (elem == 1 ? y : (elem == 2 ? z : w)) : x;
  50.607 -}
  50.608 -
  50.609 -VMATH_INLINE Vector4 operator -(const Vector4 &vec) {
  50.610 -	return Vector4(-vec.x, -vec.y, -vec.z, -vec.w);
  50.611 -}
  50.612 -
  50.613 -VMATH_INLINE scalar_t dot_product(const Vector4 &v1, const Vector4 &v2) {
  50.614 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
  50.615 -}
  50.616 -
  50.617 -VMATH_INLINE Vector4 cross_product(const Vector4 &v1, const Vector4 &v2, const Vector4 &v3) {
  50.618 -	scalar_t a, b, c, d, e, f;       /* Intermediate Values */
  50.619 -    Vector4 result;
  50.620 -
  50.621 -    /* Calculate intermediate values. */
  50.622 -    a = (v2.x * v3.y) - (v2.y * v3.x);
  50.623 -    b = (v2.x * v3.z) - (v2.z * v3.x);
  50.624 -    c = (v2.x * v3.w) - (v2.w * v3.x);
  50.625 -    d = (v2.y * v3.z) - (v2.z * v3.y);
  50.626 -    e = (v2.y * v3.w) - (v2.w * v3.y);
  50.627 -    f = (v2.z * v3.w) - (v2.w * v3.z);
  50.628 -
  50.629 -    /* Calculate the result-vector components. */
  50.630 -    result.x =   (v1.y * f) - (v1.z * e) + (v1.w * d);
  50.631 -    result.y = - (v1.x * f) + (v1.z * c) - (v1.w * b);
  50.632 -    result.z =   (v1.x * e) - (v1.y * c) + (v1.w * a);
  50.633 -    result.w = - (v1.x * d) + (v1.y * b) - (v1.z * a);
  50.634 -    return result;
  50.635 -}
  50.636 -
  50.637 -VMATH_INLINE Vector4 operator +(const Vector4 &v1, const Vector4 &v2) {
  50.638 -	return Vector4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
  50.639 -}
  50.640 -
  50.641 -VMATH_INLINE Vector4 operator -(const Vector4 &v1, const Vector4 &v2) {
  50.642 -	return Vector4(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
  50.643 -}
  50.644 -
  50.645 -VMATH_INLINE Vector4 operator *(const Vector4 &v1, const Vector4 &v2) {
  50.646 -	return Vector4(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w);
  50.647 -}
  50.648 -
  50.649 -VMATH_INLINE Vector4 operator /(const Vector4 &v1, const Vector4 &v2) {
  50.650 -	return Vector4(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w);
  50.651 -}
  50.652 -
  50.653 -VMATH_INLINE bool operator ==(const Vector4 &v1, const Vector4 &v2) {
  50.654 -	return	(fabs(v1.x - v2.x) < XSMALL_NUMBER) &&
  50.655 -			(fabs(v1.y - v2.y) < XSMALL_NUMBER) &&
  50.656 -			(fabs(v1.z - v2.z) < XSMALL_NUMBER) &&
  50.657 -			(fabs(v1.w - v2.w) < XSMALL_NUMBER);
  50.658 -}
  50.659 -
  50.660 -VMATH_INLINE void operator +=(Vector4 &v1, const Vector4 &v2) {
  50.661 -	v1.x += v2.x;
  50.662 -	v1.y += v2.y;
  50.663 -	v1.z += v2.z;
  50.664 -	v1.w += v2.w;
  50.665 -}
  50.666 -
  50.667 -VMATH_INLINE void operator -=(Vector4 &v1, const Vector4 &v2) {
  50.668 -	v1.x -= v2.x;
  50.669 -	v1.y -= v2.y;
  50.670 -	v1.z -= v2.z;
  50.671 -	v1.w -= v2.w;
  50.672 -}
  50.673 -
  50.674 -VMATH_INLINE void operator *=(Vector4 &v1, const Vector4 &v2) {
  50.675 -	v1.x *= v2.x;
  50.676 -	v1.y *= v2.y;
  50.677 -	v1.z *= v2.z;
  50.678 -	v1.w *= v2.w;
  50.679 -}
  50.680 -
  50.681 -VMATH_INLINE void operator /=(Vector4 &v1, const Vector4 &v2) {
  50.682 -	v1.x /= v2.x;
  50.683 -	v1.y /= v2.y;
  50.684 -	v1.z /= v2.z;
  50.685 -	v1.w /= v2.w;
  50.686 -}
  50.687 -
  50.688 -/* binary vector (op) scalar and scalar (op) vector operations */
  50.689 -VMATH_INLINE Vector4 operator +(const Vector4 &vec, scalar_t scalar) {
  50.690 -	return Vector4(vec.x + scalar, vec.y + scalar, vec.z + scalar, vec.w + scalar);
  50.691 -}
  50.692 -
  50.693 -VMATH_INLINE Vector4 operator +(scalar_t scalar, const Vector4 &vec) {
  50.694 -	return Vector4(vec.x + scalar, vec.y + scalar, vec.z + scalar, vec.w + scalar);
  50.695 -}
  50.696 -
  50.697 -VMATH_INLINE Vector4 operator -(const Vector4 &vec, scalar_t scalar) {
  50.698 -	return Vector4(vec.x - scalar, vec.y - scalar, vec.z - scalar, vec.w - scalar);
  50.699 -}
  50.700 -
  50.701 -VMATH_INLINE Vector4 operator *(const Vector4 &vec, scalar_t scalar) {
  50.702 -	return Vector4(vec.x * scalar, vec.y * scalar, vec.z * scalar, vec.w * scalar);
  50.703 -}
  50.704 -
  50.705 -VMATH_INLINE Vector4 operator *(scalar_t scalar, const Vector4 &vec) {
  50.706 -	return Vector4(vec.x * scalar, vec.y * scalar, vec.z * scalar, vec.w * scalar);
  50.707 -}
  50.708 -
  50.709 -VMATH_INLINE Vector4 operator /(const Vector4 &vec, scalar_t scalar) {
  50.710 -	return Vector4(vec.x / scalar, vec.y / scalar, vec.z / scalar, vec.w / scalar);
  50.711 -}
  50.712 -
  50.713 -VMATH_INLINE void operator +=(Vector4 &vec, scalar_t scalar) {
  50.714 -	vec.x += scalar;
  50.715 -	vec.y += scalar;
  50.716 -	vec.z += scalar;
  50.717 -	vec.w += scalar;
  50.718 -}
  50.719 -
  50.720 -VMATH_INLINE void operator -=(Vector4 &vec, scalar_t scalar) {
  50.721 -	vec.x -= scalar;
  50.722 -	vec.y -= scalar;
  50.723 -	vec.z -= scalar;
  50.724 -	vec.w -= scalar;
  50.725 -}
  50.726 -
  50.727 -VMATH_INLINE void operator *=(Vector4 &vec, scalar_t scalar) {
  50.728 -	vec.x *= scalar;
  50.729 -	vec.y *= scalar;
  50.730 -	vec.z *= scalar;
  50.731 -	vec.w *= scalar;
  50.732 -}
  50.733 -
  50.734 -VMATH_INLINE void operator /=(Vector4 &vec, scalar_t scalar) {
  50.735 -	vec.x /= scalar;
  50.736 -	vec.y /= scalar;
  50.737 -	vec.z /= scalar;
  50.738 -	vec.w /= scalar;
  50.739 -}
  50.740 -
  50.741 -VMATH_INLINE scalar_t Vector4::length() const {
  50.742 -	return sqrt(x*x + y*y + z*z + w*w);
  50.743 -}
  50.744 -VMATH_INLINE scalar_t Vector4::length_sq() const {
  50.745 -	return x*x + y*y + z*z + w*w;
  50.746 -}
  50.747 -
  50.748 -VMATH_INLINE Vector4 lerp(const Vector4 &v0, const Vector4 &v1, scalar_t t)
  50.749 -{
  50.750 -	return v0 + (v1 - v0) * t;
  50.751 -}
  50.752 -
  50.753 -VMATH_INLINE Vector4 catmull_rom_spline(const Vector4 &v0, const Vector4 &v1,
  50.754 -		const Vector4 &v2, const Vector4 &v3, scalar_t t)
  50.755 -{
  50.756 -	scalar_t spline(scalar_t, scalar_t, scalar_t, scalar_t, scalar_t);
  50.757 -	scalar_t x = spline(v0.x, v1.x, v2.x, v3.x, t);
  50.758 -	scalar_t y = spline(v0.y, v1.y, v2.y, v3.y, t);
  50.759 -	scalar_t z = spline(v0.z, v1.z, v2.z, v3.z, t);
  50.760 -	scalar_t w = spline(v0.w, v1.w, v2.w, v3.w, t);
  50.761 -	return Vector4(x, y, z, w);
  50.762 -}
  50.763 -
  50.764 -#endif	/* __cplusplus */
    51.1 --- a/libs/vmath/vmath.c	Thu Apr 17 08:50:36 2014 +0300
    51.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.3 @@ -1,336 +0,0 @@
    51.4 -/*
    51.5 -libvmath - a vector math library
    51.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    51.7 -
    51.8 -This program is free software: you can redistribute it and/or modify
    51.9 -it under the terms of the GNU Lesser General Public License as published
   51.10 -by the Free Software Foundation, either version 3 of the License, or
   51.11 -(at your option) any later version.
   51.12 -
   51.13 -This program is distributed in the hope that it will be useful,
   51.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   51.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   51.16 -GNU Lesser General Public License for more details.
   51.17 -
   51.18 -You should have received a copy of the GNU Lesser General Public License
   51.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   51.20 -*/
   51.21 -
   51.22 -#include <stdlib.h>
   51.23 -#include <math.h>
   51.24 -#include "vmath.h"
   51.25 -
   51.26 -/** Numerical calculation of integrals using simpson's rule */
   51.27 -scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples)
   51.28 -{
   51.29 -	int i;
   51.30 -	scalar_t h = (high - low) / (scalar_t)samples;
   51.31 -	scalar_t sum = 0.0;
   51.32 -
   51.33 -	for(i=0; i<samples+1; i++) {
   51.34 -		scalar_t y = f((scalar_t)i * h + low);
   51.35 -		sum += ((!i || i == samples) ? y : ((i % 2) ? 4.0 * y : 2.0 * y)) * (h / 3.0);
   51.36 -	}
   51.37 -	return sum;
   51.38 -}
   51.39 -
   51.40 -/** Gaussuan function */
   51.41 -scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev)
   51.42 -{
   51.43 -	scalar_t exponent = -SQ(x - mean) / (2.0 * SQ(sdev));
   51.44 -	return 1.0 - -pow(M_E, exponent) / (sdev * sqrt(TWO_PI));
   51.45 -}
   51.46 -
   51.47 -
   51.48 -/** b-spline approximation */
   51.49 -scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t)
   51.50 -{
   51.51 -	vec4_t tmp;
   51.52 -	scalar_t tsq = t * t;
   51.53 -
   51.54 -	static mat4_t bspline_mat = {
   51.55 -		{-1,  3, -3,  1},
   51.56 -		{3, -6,  3,  0},
   51.57 -		{-3,  0,  3,  0},
   51.58 -		{1,  4,  1,  0}
   51.59 -	};
   51.60 -
   51.61 -	tmp = v4_scale(v4_transform(v4_cons(a, b, c, d), bspline_mat), 1.0 / 6.0);
   51.62 -	return v4_dot(v4_cons(tsq * t, tsq, t, 1.0), tmp);
   51.63 -}
   51.64 -
   51.65 -/** Catmull-rom spline interpolation */
   51.66 -scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t)
   51.67 -{
   51.68 -	vec4_t tmp;
   51.69 -	scalar_t tsq = t * t;
   51.70 -
   51.71 -	static mat4_t crspline_mat = {
   51.72 -		{-1,  3, -3,  1},
   51.73 -		{2, -5,  4, -1},
   51.74 -		{-1,  0,  1,  0},
   51.75 -		{0,  2,  0,  0}
   51.76 -	};
   51.77 -
   51.78 -	tmp = v4_scale(v4_transform(v4_cons(a, b, c, d), crspline_mat), 0.5);
   51.79 -	return v4_dot(v4_cons(tsq * t, tsq, t, 1.0), tmp);
   51.80 -}
   51.81 -
   51.82 -/** Bezier interpolation */
   51.83 -scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t)
   51.84 -{
   51.85 -	scalar_t omt, omt3, t3, f;
   51.86 -	t3 = t * t * t;
   51.87 -	omt = 1.0f - t;
   51.88 -	omt3 = omt * omt * omt;
   51.89 -	f = 3 * t * omt;
   51.90 -
   51.91 -	return (a * omt3) + (b * f * omt) + (c * f * t) + (d * t3);
   51.92 -}
   51.93 -
   51.94 -/* ---- Ken Perlin's implementation of noise ---- */
   51.95 -
   51.96 -#define B	0x100
   51.97 -#define BM	0xff
   51.98 -#define N	0x1000
   51.99 -#define NP	12   /* 2^N */
  51.100 -#define NM	0xfff
  51.101 -
  51.102 -#define s_curve(t) (t * t * (3.0f - 2.0f * t))
  51.103 -
  51.104 -#define setup(elem, b0, b1, r0, r1) \
  51.105 -	do {							\
  51.106 -		scalar_t t = elem + N;		\
  51.107 -		b0 = ((int)t) & BM;			\
  51.108 -		b1 = (b0 + 1) & BM;			\
  51.109 -		r0 = t - (int)t;			\
  51.110 -		r1 = r0 - 1.0f;				\
  51.111 -	} while(0)
  51.112 -
  51.113 -
  51.114 -static int perm[B + B + 2];			/* permuted index from g_n onto themselves */
  51.115 -static vec3_t grad3[B + B + 2];		/* 3D random gradients */
  51.116 -static vec2_t grad2[B + B + 2];		/* 2D random gradients */
  51.117 -static scalar_t grad1[B + B + 2];	/* 1D random ... slopes */
  51.118 -static int tables_valid;
  51.119 -
  51.120 -static void init_noise()
  51.121 -{
  51.122 -	int i;
  51.123 -
  51.124 -	/* calculate random gradients */
  51.125 -	for(i=0; i<B; i++) {
  51.126 -		perm[i] = i;	/* .. and initialize permutation mapping to identity */
  51.127 -
  51.128 -		grad1[i] = (scalar_t)((rand() % (B + B)) - B) / B;
  51.129 -
  51.130 -		grad2[i].x = (scalar_t)((rand() % (B + B)) - B) / B;
  51.131 -		grad2[i].y = (scalar_t)((rand() % (B + B)) - B) / B;
  51.132 -		grad2[i] = v2_normalize(grad2[i]);
  51.133 -
  51.134 -		grad3[i].x = (scalar_t)((rand() % (B + B)) - B) / B;
  51.135 -		grad3[i].y = (scalar_t)((rand() % (B + B)) - B) / B;
  51.136 -		grad3[i].z = (scalar_t)((rand() % (B + B)) - B) / B;
  51.137 -		grad3[i] = v3_normalize(grad3[i]);
  51.138 -	}
  51.139 -
  51.140 -	/* permute indices by swapping them randomly */
  51.141 -	for(i=0; i<B; i++) {
  51.142 -		int rand_idx = rand() % B;
  51.143 -
  51.144 -		int tmp = perm[i];
  51.145 -		perm[i] = perm[rand_idx];
  51.146 -		perm[rand_idx] = tmp;
  51.147 -	}
  51.148 -
  51.149 -	/* fill up the rest of the arrays by duplicating the existing gradients */
  51.150 -	/* and permutations */
  51.151 -	for(i=0; i<B+2; i++) {
  51.152 -		perm[B + i] = perm[i];
  51.153 -		grad1[B + i] = grad1[i];
  51.154 -		grad2[B + i] = grad2[i];
  51.155 -		grad3[B + i] = grad3[i];
  51.156 -	}
  51.157 -}
  51.158 -
  51.159 -scalar_t noise1(scalar_t x)
  51.160 -{
  51.161 -	int bx0, bx1;
  51.162 -	scalar_t rx0, rx1, sx, u, v;
  51.163 -
  51.164 -	if(!tables_valid) {
  51.165 -		init_noise();
  51.166 -		tables_valid = 1;
  51.167 -	}
  51.168 -
  51.169 -	setup(x, bx0, bx1, rx0, rx1);
  51.170 -	sx = s_curve(rx0);
  51.171 -	u = rx0 * grad1[perm[bx0]];
  51.172 -	v = rx1 * grad1[perm[bx1]];
  51.173 -
  51.174 -	return lerp(u, v, sx);
  51.175 -}
  51.176 -
  51.177 -scalar_t noise2(scalar_t x, scalar_t y)
  51.178 -{
  51.179 -	int i, j, b00, b10, b01, b11;
  51.180 -	int bx0, bx1, by0, by1;
  51.181 -	scalar_t rx0, rx1, ry0, ry1;
  51.182 -	scalar_t sx, sy, u, v, a, b;
  51.183 -
  51.184 -	if(!tables_valid) {
  51.185 -		init_noise();
  51.186 -		tables_valid = 1;
  51.187 -	}
  51.188 -
  51.189 -	setup(x, bx0, bx1, rx0, rx1);
  51.190 -	setup(y, by0, by1, ry0, ry1);
  51.191 -
  51.192 -	i = perm[bx0];
  51.193 -	j = perm[bx1];
  51.194 -
  51.195 -	b00 = perm[i + by0];
  51.196 -	b10 = perm[j + by0];
  51.197 -	b01 = perm[i + by1];
  51.198 -	b11 = perm[j + by1];
  51.199 -
  51.200 -	/* calculate hermite inteprolating factors */
  51.201 -	sx = s_curve(rx0);
  51.202 -	sy = s_curve(ry0);
  51.203 -
  51.204 -	/* interpolate along the left edge */
  51.205 -	u = v2_dot(grad2[b00], v2_cons(rx0, ry0));
  51.206 -	v = v2_dot(grad2[b10], v2_cons(rx1, ry0));
  51.207 -	a = lerp(u, v, sx);
  51.208 -
  51.209 -	/* interpolate along the right edge */
  51.210 -	u = v2_dot(grad2[b01], v2_cons(rx0, ry1));
  51.211 -	v = v2_dot(grad2[b11], v2_cons(rx1, ry1));
  51.212 -	b = lerp(u, v, sx);
  51.213 -
  51.214 -	/* interpolate between them */
  51.215 -	return lerp(a, b, sy);
  51.216 -}
  51.217 -
  51.218 -scalar_t noise3(scalar_t x, scalar_t y, scalar_t z)
  51.219 -{
  51.220 -	int i, j;
  51.221 -	int bx0, bx1, by0, by1, bz0, bz1;
  51.222 -	int b00, b10, b01, b11;
  51.223 -	scalar_t rx0, rx1, ry0, ry1, rz0, rz1;
  51.224 -	scalar_t sx, sy, sz;
  51.225 -	scalar_t u, v, a, b, c, d;
  51.226 -
  51.227 -	if(!tables_valid) {
  51.228 -		init_noise();
  51.229 -		tables_valid = 1;
  51.230 -	}
  51.231 -
  51.232 -	setup(x, bx0, bx1, rx0, rx1);
  51.233 -	setup(y, by0, by1, ry0, ry1);
  51.234 -	setup(z, bz0, bz1, rz0, rz1);
  51.235 -
  51.236 -	i = perm[bx0];
  51.237 -	j = perm[bx1];
  51.238 -
  51.239 -	b00 = perm[i + by0];
  51.240 -	b10 = perm[j + by0];
  51.241 -	b01 = perm[i + by1];
  51.242 -	b11 = perm[j + by1];
  51.243 -
  51.244 -	/* calculate hermite interpolating factors */
  51.245 -	sx = s_curve(rx0);
  51.246 -	sy = s_curve(ry0);
  51.247 -	sz = s_curve(rz0);
  51.248 -
  51.249 -	/* interpolate along the top slice of the cell */
  51.250 -	u = v3_dot(grad3[b00 + bz0], v3_cons(rx0, ry0, rz0));
  51.251 -	v = v3_dot(grad3[b10 + bz0], v3_cons(rx1, ry0, rz0));
  51.252 -	a = lerp(u, v, sx);
  51.253 -
  51.254 -	u = v3_dot(grad3[b01 + bz0], v3_cons(rx0, ry1, rz0));
  51.255 -	v = v3_dot(grad3[b11 + bz0], v3_cons(rx1, ry1, rz0));
  51.256 -	b = lerp(u, v, sx);
  51.257 -
  51.258 -	c = lerp(a, b, sy);
  51.259 -
  51.260 -	/* interpolate along the bottom slice of the cell */
  51.261 -	u = v3_dot(grad3[b00 + bz0], v3_cons(rx0, ry0, rz1));
  51.262 -	v = v3_dot(grad3[b10 + bz0], v3_cons(rx1, ry0, rz1));
  51.263 -	a = lerp(u, v, sx);
  51.264 -
  51.265 -	u = v3_dot(grad3[b01 + bz0], v3_cons(rx0, ry1, rz1));
  51.266 -	v = v3_dot(grad3[b11 + bz0], v3_cons(rx1, ry1, rz1));
  51.267 -	b = lerp(u, v, sx);
  51.268 -
  51.269 -	d = lerp(a, b, sy);
  51.270 -
  51.271 -	/* interpolate between slices */
  51.272 -	return lerp(c, d, sz);
  51.273 -}
  51.274 -
  51.275 -scalar_t fbm1(scalar_t x, int octaves)
  51.276 -{
  51.277 -	int i;
  51.278 -	scalar_t res = 0.0f, freq = 1.0f;
  51.279 -	for(i=0; i<octaves; i++) {
  51.280 -		res += noise1(x * freq) / freq;
  51.281 -		freq *= 2.0f;
  51.282 -	}
  51.283 -	return res;
  51.284 -}
  51.285 -
  51.286 -scalar_t fbm2(scalar_t x, scalar_t y, int octaves)
  51.287 -{
  51.288 -	int i;
  51.289 -	scalar_t res = 0.0f, freq = 1.0f;
  51.290 -	for(i=0; i<octaves; i++) {
  51.291 -		res += noise2(x * freq, y * freq) / freq;
  51.292 -		freq *= 2.0f;
  51.293 -	}
  51.294 -	return res;
  51.295 -}
  51.296 -
  51.297 -scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves)
  51.298 -{
  51.299 -	int i;
  51.300 -	scalar_t res = 0.0f, freq = 1.0f;
  51.301 -	for(i=0; i<octaves; i++) {
  51.302 -		res += noise3(x * freq, y * freq, z * freq) / freq;
  51.303 -		freq *= 2.0f;
  51.304 -	}
  51.305 -	return res;
  51.306 -}
  51.307 -
  51.308 -scalar_t turbulence1(scalar_t x, int octaves)
  51.309 -{
  51.310 -	int i;
  51.311 -	scalar_t res = 0.0f, freq = 1.0f;
  51.312 -	for(i=0; i<octaves; i++) {
  51.313 -		res += fabs(noise1(x * freq) / freq);
  51.314 -		freq *= 2.0f;
  51.315 -	}
  51.316 -	return res;
  51.317 -}
  51.318 -
  51.319 -scalar_t turbulence2(scalar_t x, scalar_t y, int octaves)
  51.320 -{
  51.321 -	int i;
  51.322 -	scalar_t res = 0.0f, freq = 1.0f;
  51.323 -	for(i=0; i<octaves; i++) {
  51.324 -		res += fabs(noise2(x * freq, y * freq) / freq);
  51.325 -		freq *= 2.0f;
  51.326 -	}
  51.327 -	return res;
  51.328 -}
  51.329 -
  51.330 -scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves)
  51.331 -{
  51.332 -	int i;
  51.333 -	scalar_t res = 0.0f, freq = 1.0f;
  51.334 -	for(i=0; i<octaves; i++) {
  51.335 -		res += fabs(noise3(x * freq, y * freq, z * freq) / freq);
  51.336 -		freq *= 2.0f;
  51.337 -	}
  51.338 -	return res;
  51.339 -}
    52.1 --- a/libs/vmath/vmath.h	Thu Apr 17 08:50:36 2014 +0300
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,94 +0,0 @@
    52.4 -/*
    52.5 -libvmath - a vector math library
    52.6 -Copyright (C) 2004-2013 John Tsiombikas <nuclear@member.fsf.org>
    52.7 -
    52.8 -This program is free software: you can redistribute it and/or modify
    52.9 -it under the terms of the GNU Lesser General Public License as published
   52.10 -by the Free Software Foundation, either version 3 of the License, or
   52.11 -(at your option) any later version.
   52.12 -
   52.13 -This program is distributed in the hope that it will be useful,
   52.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   52.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   52.16 -GNU Lesser General Public License for more details.
   52.17 -
   52.18 -You should have received a copy of the GNU Lesser General Public License
   52.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   52.20 -*/
   52.21 -
   52.22 -#ifndef VMATH_H_
   52.23 -#define VMATH_H_
   52.24 -
   52.25 -#include <math.h>
   52.26 -#include "vmath_types.h"
   52.27 -
   52.28 -#ifndef M_PI
   52.29 -#define M_PI	PI
   52.30 -#endif
   52.31 -
   52.32 -#ifndef M_E
   52.33 -#define M_E				2.718281828459045
   52.34 -#endif
   52.35 -
   52.36 -#define PI				3.141592653589793
   52.37 -#define HALF_PI			1.570796326794897
   52.38 -#define QUARTER_PI		0.785398163397448
   52.39 -#define TWO_PI			6.283185307179586
   52.40 -
   52.41 -
   52.42 -#define RAD_TO_DEG(a) ((((scalar_t)a) * 360.0) / TWO_PI)
   52.43 -#define DEG_TO_RAD(a) (((scalar_t)a) * (PI / 180.0))
   52.44 -
   52.45 -#define SQ(x) ((x) * (x))
   52.46 -
   52.47 -#define MIN(a, b)	((a) < (b) ? (a) : (b))
   52.48 -#define MAX(a, b)	((a) > (b) ? (a) : (b))
   52.49 -
   52.50 -#ifndef __GNUC__
   52.51 -#define round(x)	((x) >= 0 ? (x) + 0.5 : (x) - 0.5)
   52.52 -#endif
   52.53 -
   52.54 -#ifdef __cplusplus
   52.55 -extern "C" {
   52.56 -#endif	/* __cplusplus */
   52.57 -
   52.58 -static VMATH_INLINE scalar_t smoothstep(float a, float b, float x);
   52.59 -
   52.60 -static VMATH_INLINE scalar_t frand(scalar_t range);
   52.61 -static VMATH_INLINE vec3_t sphrand(scalar_t rad);
   52.62 -
   52.63 -scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples);
   52.64 -scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev);
   52.65 -
   52.66 -static VMATH_INLINE scalar_t lerp(scalar_t a, scalar_t b, scalar_t t);
   52.67 -
   52.68 -scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
   52.69 -scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
   52.70 -scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
   52.71 -
   52.72 -scalar_t noise1(scalar_t x);
   52.73 -scalar_t noise2(scalar_t x, scalar_t y);
   52.74 -scalar_t noise3(scalar_t x, scalar_t y, scalar_t z);
   52.75 -
   52.76 -scalar_t fbm1(scalar_t x, int octaves);
   52.77 -scalar_t fbm2(scalar_t x, scalar_t y, int octaves);
   52.78 -scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves);
   52.79 -
   52.80 -scalar_t turbulence1(scalar_t x, int octaves);
   52.81 -scalar_t turbulence2(scalar_t x, scalar_t y, int octaves);
   52.82 -scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves);
   52.83 -
   52.84 -#ifdef __cplusplus
   52.85 -}
   52.86 -#endif	/* __cplusplus */
   52.87 -
   52.88 -#include "vmath.inl"
   52.89 -
   52.90 -#include "vector.h"
   52.91 -#include "matrix.h"
   52.92 -#include "quat.h"
   52.93 -#include "sphvec.h"
   52.94 -#include "ray.h"
   52.95 -#include "geom.h"
   52.96 -
   52.97 -#endif	/* VMATH_H_ */
    53.1 --- a/libs/vmath/vmath.inl	Thu Apr 17 08:50:36 2014 +0300
    53.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.3 @@ -1,56 +0,0 @@
    53.4 -/*
    53.5 -libvmath - a vector math library
    53.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    53.7 -
    53.8 -This program is free software: you can redistribute it and/or modify
    53.9 -it under the terms of the GNU Lesser General Public License as published
   53.10 -by the Free Software Foundation, either version 3 of the License, or
   53.11 -(at your option) any later version.
   53.12 -
   53.13 -This program is distributed in the hope that it will be useful,
   53.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   53.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   53.16 -GNU Lesser General Public License for more details.
   53.17 -
   53.18 -You should have received a copy of the GNU Lesser General Public License
   53.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   53.20 -*/
   53.21 -
   53.22 -#include <stdlib.h>
   53.23 -
   53.24 -static VMATH_INLINE scalar_t smoothstep(float a, float b, float x)
   53.25 -{
   53.26 -	if(x < a) return 0.0;
   53.27 -	if(x >= b) return 1.0;
   53.28 -
   53.29 -	x = (x - a) / (b - a);
   53.30 -	return x * x * (3.0 - 2.0 * x);
   53.31 -}
   53.32 -
   53.33 -/** Generates a random number in [0, range) */
   53.34 -static VMATH_INLINE scalar_t frand(scalar_t range)
   53.35 -{
   53.36 -	return range * (scalar_t)rand() / (scalar_t)RAND_MAX;
   53.37 -}
   53.38 -
   53.39 -/** Generates a random vector on the surface of a sphere */
   53.40 -static VMATH_INLINE vec3_t sphrand(scalar_t rad)
   53.41 -{
   53.42 -	scalar_t u = (scalar_t)rand() / RAND_MAX;
   53.43 -	scalar_t v = (scalar_t)rand() / RAND_MAX;
   53.44 -
   53.45 -	scalar_t theta = 2.0 * M_PI * u;
   53.46 -	scalar_t phi = acos(2.0 * v - 1.0);
   53.47 -
   53.48 -	vec3_t res;
   53.49 -	res.x = rad * cos(theta) * sin(phi);
   53.50 -	res.y = rad * sin(theta) * sin(phi);
   53.51 -	res.z = rad * cos(phi);
   53.52 -	return res;
   53.53 -}
   53.54 -
   53.55 -/** linear interpolation */
   53.56 -static VMATH_INLINE scalar_t lerp(scalar_t a, scalar_t b, scalar_t t)
   53.57 -{
   53.58 -	return a + (b - a) * t;
   53.59 -}
    54.1 --- a/libs/vmath/vmath_config.h	Thu Apr 17 08:50:36 2014 +0300
    54.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.3 @@ -1,21 +0,0 @@
    54.4 -#ifndef VMATH_CONFIG_H_
    54.5 -#define VMATH_CONFIG_H_
    54.6 -
    54.7 -#ifdef __cplusplus
    54.8 -#define VMATH_INLINE inline
    54.9 -#elif (__STDC_VERSION__ < 199999)
   54.10 -#if defined(__GNUC__) || defined(_MSC_VER)
   54.11 -#define VMATH_INLINE __inline
   54.12 -#else
   54.13 -#define VMATH_INLINE
   54.14 -
   54.15 -#ifdef VECTOR_H_
   54.16 -#warning "compiling vector operations without inline, performance might suffer"
   54.17 -#endif	/* VECTOR_H_ */
   54.18 -
   54.19 -#endif	/* gcc/msvc */
   54.20 -#endif	/* not C99 */
   54.21 -
   54.22 -#define SINGLE_PRECISION_MATH
   54.23 -
   54.24 -#endif	/* VMATH_CONFIG_H_ */
    55.1 --- a/libs/vmath/vmath_types.h	Thu Apr 17 08:50:36 2014 +0300
    55.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.3 @@ -1,58 +0,0 @@
    55.4 -/*
    55.5 -libvmath - a vector math library
    55.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    55.7 -
    55.8 -This program is free software: you can redistribute it and/or modify
    55.9 -it under the terms of the GNU Lesser General Public License as published
   55.10 -by the Free Software Foundation, either version 3 of the License, or
   55.11 -(at your option) any later version.
   55.12 -
   55.13 -This program is distributed in the hope that it will be useful,
   55.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   55.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   55.16 -GNU Lesser General Public License for more details.
   55.17 -
   55.18 -You should have received a copy of the GNU Lesser General Public License
   55.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   55.20 -*/
   55.21 -
   55.22 -#ifndef VMATH_TYPES_H_
   55.23 -#define VMATH_TYPES_H_
   55.24 -
   55.25 -#include "vmath_config.h"
   55.26 -
   55.27 -#define SMALL_NUMBER	1.e-4
   55.28 -#define XSMALL_NUMBER	1.e-8
   55.29 -#define ERROR_MARGIN	1.e-6
   55.30 -
   55.31 -
   55.32 -#ifdef SINGLE_PRECISION_MATH
   55.33 -typedef float scalar_t;
   55.34 -#else
   55.35 -typedef double scalar_t;
   55.36 -#endif	/* floating point precision */
   55.37 -
   55.38 -/* vectors */
   55.39 -typedef struct { scalar_t x, y; } vec2_t;
   55.40 -typedef struct { scalar_t x, y, z; } vec3_t;
   55.41 -typedef struct { scalar_t x, y, z, w; } vec4_t;
   55.42 -
   55.43 -/* quaternions */
   55.44 -typedef vec4_t quat_t;
   55.45 -
   55.46 -/* matrices */
   55.47 -typedef scalar_t mat3_t[3][3];
   55.48 -typedef scalar_t mat4_t[4][4];
   55.49 -
   55.50 -
   55.51 -#ifdef __cplusplus
   55.52 -class Vector2;
   55.53 -class Vector3;
   55.54 -class Vector4;
   55.55 -class Quaternion;
   55.56 -class Matrix3x3;
   55.57 -class Matrix4x4;
   55.58 -class SphVector;
   55.59 -#endif	/* __cplusplus */
   55.60 -
   55.61 -#endif	/* VMATH_TYPES_H_ */
    56.1 --- a/src/goat3d.cc	Thu Apr 17 08:50:36 2014 +0300
    56.2 +++ b/src/goat3d.cc	Thu Apr 17 08:53:42 2014 +0300
    56.3 @@ -179,14 +179,14 @@
    56.4  	return res;
    56.5  }
    56.6  
    56.7 -GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const struct goat3d_node *root, const char *fname)
    56.8 +GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const char *fname)
    56.9  {
   56.10  	FILE *fp = fopen(fname, "wb");
   56.11  	if(!fp) {
   56.12  		return -1;
   56.13  	}
   56.14  
   56.15 -	int res = goat3d_save_anim_file(g, root, fp);
   56.16 +	int res = goat3d_save_anim_file(g, fp);
   56.17  	fclose(fp);
   56.18  	return res;
   56.19  }
   56.20 @@ -202,7 +202,7 @@
   56.21  	return goat3d_load_anim_io(g, &io);
   56.22  }
   56.23  
   56.24 -GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, const struct goat3d_node *root, FILE *fp)
   56.25 +GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, FILE *fp)
   56.26  {
   56.27  	goat3d_io io;
   56.28  	io.cls = fp;
   56.29 @@ -210,7 +210,7 @@
   56.30  	io.write = write_file;
   56.31  	io.seek = seek_file;
   56.32  
   56.33 -	return goat3d_save_anim_io(g, root, &io);
   56.34 +	return goat3d_save_anim_io(g, &io);
   56.35  }
   56.36  
   56.37  GOAT3DAPI int goat3d_load_anim_io(struct goat3d *g, struct goat3d_io *io)
   56.38 @@ -223,12 +223,12 @@
   56.39  	return 0;
   56.40  }
   56.41  
   56.42 -GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, const struct goat3d_node *root, struct goat3d_io *io)
   56.43 +GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, struct goat3d_io *io)
   56.44  {
   56.45  	if(goat3d_getopt(g, GOAT3D_OPT_SAVEXML)) {
   56.46 -		return g->scn->save_anim_xml(root, io) ? 0 : -1;
   56.47 +		return g->scn->save_anim_xml(io) ? 0 : -1;
   56.48  	}
   56.49 -	return g->scn->save_anim(root, io) ? 0 : -1;
   56.50 +	return g->scn->save_anim(io) ? 0 : -1;
   56.51  }
   56.52  
   56.53  
   56.54 @@ -264,6 +264,21 @@
   56.55  	g->scn->add_material(mtl);
   56.56  }
   56.57  
   56.58 +GOAT3DAPI int goat3d_get_mtl_count(struct goat3d *g)
   56.59 +{
   56.60 +	return g->scn->get_material_count();
   56.61 +}
   56.62 +
   56.63 +GOAT3DAPI struct goat3d_material *goat3d_get_mtl(struct goat3d *g, int idx)
   56.64 +{
   56.65 +	return (goat3d_material*)g->scn->get_material(idx);
   56.66 +}
   56.67 +
   56.68 +GOAT3DAPI struct goat3d_material *goat3d_get_mtl_by_name(struct goat3d *g, const char *name)
   56.69 +{
   56.70 +	return (goat3d_material*)g->scn->get_material(name);
   56.71 +}
   56.72 +
   56.73  GOAT3DAPI struct goat3d_material *goat3d_create_mtl(void)
   56.74  {
   56.75  	return new goat3d_material;
   56.76 @@ -422,6 +437,12 @@
   56.77  	goat3d_add_mesh_attrib4f(mesh, attrib, val, 0, 0, 1);
   56.78  }
   56.79  
   56.80 +GOAT3DAPI void goat3d_add_mesh_attrib2f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
   56.81 +		float x, float y)
   56.82 +{
   56.83 +	goat3d_add_mesh_attrib4f(mesh, attrib, x, y, 0, 1);
   56.84 +}
   56.85 +
   56.86  GOAT3DAPI void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
   56.87  		float x, float y, float z)
   56.88  {
    57.1 --- a/src/goat3d.h	Thu Apr 17 08:50:36 2014 +0300
    57.2 +++ b/src/goat3d.h	Thu Apr 17 08:53:42 2014 +0300
    57.3 @@ -107,13 +107,13 @@
    57.4  
    57.5  /* load/save animation files (g must already be loaded to load animations) */
    57.6  GOAT3DAPI int goat3d_load_anim(struct goat3d *g, const char *fname);
    57.7 -GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const struct goat3d_node *root, const char *fname);
    57.8 +GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const char *fname);
    57.9  
   57.10  GOAT3DAPI int goat3d_load_anim_file(struct goat3d *g, FILE *fp);
   57.11 -GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, const struct goat3d_node *root, FILE *fp);
   57.12 +GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, FILE *fp);
   57.13  
   57.14  GOAT3DAPI int goat3d_load_anim_io(struct goat3d *g, struct goat3d_io *io);
   57.15 -GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, const struct goat3d_node *root, struct goat3d_io *io);
   57.16 +GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, struct goat3d_io *io);
   57.17  
   57.18  /* misc scene properties */
   57.19  GOAT3DAPI int goat3d_set_name(struct goat3d *g, const char *name);
   57.20 @@ -125,6 +125,9 @@
   57.21  
   57.22  /* materials */
   57.23  GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl);
   57.24 +GOAT3DAPI int goat3d_get_mtl_count(struct goat3d *g);
   57.25 +GOAT3DAPI struct goat3d_material *goat3d_get_mtl(struct goat3d *g, int idx);
   57.26 +GOAT3DAPI struct goat3d_material *goat3d_get_mtl_by_name(struct goat3d *g, const char *name);
   57.27  
   57.28  GOAT3DAPI struct goat3d_material *goat3d_create_mtl(void);
   57.29  GOAT3DAPI void goat3d_destroy_mtl(struct goat3d_material *mtl);
   57.30 @@ -173,6 +176,8 @@
   57.31  GOAT3DAPI void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
   57.32  		const void *data, int vnum);
   57.33  GOAT3DAPI void goat3d_add_mesh_attrib1f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, float val);
   57.34 +GOAT3DAPI void goat3d_add_mesh_attrib2f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
   57.35 +		float x, float y);
   57.36  GOAT3DAPI void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
   57.37  		float x, float y, float z);
   57.38  GOAT3DAPI void goat3d_add_mesh_attrib4f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
    58.1 --- a/src/goat3d_impl.h	Thu Apr 17 08:50:36 2014 +0300
    58.2 +++ b/src/goat3d_impl.h	Thu Apr 17 08:53:42 2014 +0300
    58.3 @@ -98,10 +98,10 @@
    58.4  	bool savexml(goat3d_io *io) const;
    58.5  
    58.6  	bool load_anim(goat3d_io *io);
    58.7 -	bool save_anim(const XFormNode *node, goat3d_io *io) const;
    58.8 +	bool save_anim(goat3d_io *io) const;
    58.9  
   58.10  	bool load_anim_xml(goat3d_io *io);
   58.11 -	bool save_anim_xml(const XFormNode *node, goat3d_io *io) const;
   58.12 +	bool save_anim_xml(goat3d_io *io) const;
   58.13  };
   58.14  
   58.15  void io_fprintf(goat3d_io *io, const char *fmt, ...);
    59.1 --- a/src/goat3d_write.cc	Thu Apr 17 08:50:36 2014 +0300
    59.2 +++ b/src/goat3d_write.cc	Thu Apr 17 08:53:42 2014 +0300
    59.3 @@ -85,7 +85,7 @@
    59.4  	return false;
    59.5  }
    59.6  
    59.7 -bool Scene::save_anim(const XFormNode *node, goat3d_io *io) const
    59.8 +bool Scene::save_anim(goat3d_io *io) const
    59.9  {
   59.10  	return false;
   59.11  }
    60.1 --- a/src/goat3d_writexml.cc	Thu Apr 17 08:50:36 2014 +0300
    60.2 +++ b/src/goat3d_writexml.cc	Thu Apr 17 08:53:42 2014 +0300
    60.3 @@ -44,7 +44,7 @@
    60.4  		write_material(this, io, materials[i], 1);
    60.5  	}
    60.6  	for(size_t i=0; i<meshes.size(); i++) {
    60.7 -		write_mesh(this, io, meshes[i], i, 1);
    60.8 +		write_mesh(this, io, meshes[i], (int)i, 1);
    60.9  	}
   60.10  	for(size_t i=0; i<lights.size(); i++) {
   60.11  		write_light(this, io, lights[i], 1);
   60.12 @@ -60,33 +60,19 @@
   60.13  	return true;
   60.14  }
   60.15  
   60.16 -static void collect_nodes(std::list<const XFormNode*> *res, const XFormNode *node)
   60.17 -{
   60.18 -	if(!node) return;
   60.19 -
   60.20 -	res->push_back(node);
   60.21 -
   60.22 -	for(int i=0; i<node->get_children_count(); i++) {
   60.23 -		collect_nodes(res, node->get_child(i));
   60.24 -	}
   60.25 -}
   60.26 -
   60.27 -bool Scene::save_anim_xml(const XFormNode *node, goat3d_io *io) const
   60.28 +bool Scene::save_anim_xml(goat3d_io *io) const
   60.29  {
   60.30  	xmlout(io, 0, "<anim>\n");
   60.31  
   60.32 -	const char *anim_name = node->get_animation_name();
   60.33 -	if(anim_name && *anim_name) {
   60.34 -		xmlout(io, 1, "<name string=\"%s\"/>\n", anim_name);
   60.35 +	if(!nodes.empty()) {
   60.36 +		const char *anim_name = nodes[0]->get_animation_name();
   60.37 +		if(anim_name && *anim_name) {
   60.38 +			xmlout(io, 1, "<name string=\"%s\"/>\n", anim_name);
   60.39 +		}
   60.40  	}
   60.41  
   60.42 -	std::list<const XFormNode*> allnodes;
   60.43 -	collect_nodes(&allnodes, node);
   60.44 -
   60.45 -	std::list<const XFormNode*>::const_iterator it = allnodes.begin();
   60.46 -	while(it != allnodes.end()) {
   60.47 -		const XFormNode *n = *it++;
   60.48 -		write_node_anim(io, n, 1);
   60.49 +	for(size_t i=0; i<nodes.size(); i++) {
   60.50 +		write_node_anim(io, nodes[i], 1);
   60.51  	}
   60.52  
   60.53  	xmlout(io, 0, "</anim>\n");
    61.1 --- a/src/node.cc	Thu Apr 17 08:50:36 2014 +0300
    61.2 +++ b/src/node.cc	Thu Apr 17 08:53:42 2014 +0300
    61.3 @@ -43,6 +43,8 @@
    61.4  
    61.5  void g3dimpl::delete_node_tree(Node *n)
    61.6  {
    61.7 +	if(!n) return;
    61.8 +
    61.9  	for(int i=0; i<n->get_children_count(); i++) {
   61.10  		delete_node_tree((Node*)n->get_child(i));
   61.11  	}