goat3d

changeset 58:d317eb4f83da

- made everything compile properly on windows again - removed libanim/libvmath, we'll use them as external dependencies - added new maxgoat_stub 3dsmax plugin project. Gets loaded as a max plugin and loads the actual maxgoat (and later maxgoat_anim) exporters on demand, to allow reloading the actual exporters without having to restart 3dsmax (which takes AGES).
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Mar 2014 03:19:55 +0200
parents 76d0f55f9d5f
children b0bf3786bd5b
files exporters/maxgoat/maxgoat.vcxproj exporters/maxgoat/src/maxgoat.cc exporters/maxgoat_stub/maxgoat_stub.vcxproj exporters/maxgoat_stub/maxgoat_stub.vcxproj.filters exporters/maxgoat_stub/src/stub.cc goat3d-vs2012.sln goat3d.vcxproj goat3d.vcxproj.filters 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_writexml.cc
diffstat 45 files changed, 488 insertions(+), 6564 deletions(-) [+]
line diff
     1.1 --- a/exporters/maxgoat/maxgoat.vcxproj	Thu Jan 23 03:57:15 2014 +0200
     1.2 +++ b/exporters/maxgoat/maxgoat.vcxproj	Tue Mar 25 03:19:55 2014 +0200
     1.3 @@ -105,11 +105,11 @@
     1.4      <Link>
     1.5        <SubSystem>Windows</SubSystem>
     1.6        <GenerateDebugInformation>true</GenerateDebugInformation>
     1.7 -      <AdditionalDependencies>goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.8 +      <AdditionalDependencies>libvmath-x64-dbg.lib;libanim-x64.lib;goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.9        <AdditionalLibraryDirectories>$(TargetDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    1.10      </Link>
    1.11      <PostBuildEvent>
    1.12 -      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
    1.13 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(TargetFileName)"</Command>
    1.14      </PostBuildEvent>
    1.15    </ItemDefinitionGroup>
    1.16    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    1.17 @@ -147,11 +147,11 @@
    1.18        <GenerateDebugInformation>true</GenerateDebugInformation>
    1.19        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    1.20        <OptimizeReferences>true</OptimizeReferences>
    1.21 -      <AdditionalDependencies>goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.22 +      <AdditionalDependencies>libvmath-x64.lib;libanim-x64.lib;goat3d-x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
    1.23        <AdditionalLibraryDirectories>$(TargetDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    1.24      </Link>
    1.25      <PostBuildEvent>
    1.26 -      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
    1.27 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(TargetFileName)"</Command>
    1.28      </PostBuildEvent>
    1.29    </ItemDefinitionGroup>
    1.30    <ItemGroup>
     2.1 --- a/exporters/maxgoat/src/maxgoat.cc	Thu Jan 23 03:57:15 2014 +0200
     2.2 +++ b/exporters/maxgoat/src/maxgoat.cc	Tue Mar 25 03:19:55 2014 +0200
     2.3 @@ -124,6 +124,7 @@
     2.4  	char fname[512];
     2.5  	wcstombs(fname, name, sizeof fname - 1);
     2.6  
     2.7 +	fprintf(logfile, "Exporting Goat3D Scene (text) file: %s\n", fname);
     2.8  	if(!(igame = GetIGameInterface())) {
     2.9  		fprintf(logfile, "failed to get the igame interface\n");
    2.10  		return IMPEXP_FAIL;
    2.11 @@ -406,6 +407,7 @@
    2.12  	HINSTANCE HInstance() { return hinst; }
    2.13  };
    2.14  
    2.15 +// TODO: make 2 class descriptors, one for goat3d, one for goat3danim
    2.16  static GoatClassDesc class_desc;
    2.17  
    2.18  BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/exporters/maxgoat_stub/maxgoat_stub.vcxproj	Tue Mar 25 03:19:55 2014 +0200
     3.3 @@ -0,0 +1,155 @@
     3.4 +<?xml version="1.0" encoding="utf-8"?>
     3.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     3.6 +  <ItemGroup Label="ProjectConfigurations">
     3.7 +    <ProjectConfiguration Include="Debug|Win32">
     3.8 +      <Configuration>Debug</Configuration>
     3.9 +      <Platform>Win32</Platform>
    3.10 +    </ProjectConfiguration>
    3.11 +    <ProjectConfiguration Include="Debug|x64">
    3.12 +      <Configuration>Debug</Configuration>
    3.13 +      <Platform>x64</Platform>
    3.14 +    </ProjectConfiguration>
    3.15 +    <ProjectConfiguration Include="Release|Win32">
    3.16 +      <Configuration>Release</Configuration>
    3.17 +      <Platform>Win32</Platform>
    3.18 +    </ProjectConfiguration>
    3.19 +    <ProjectConfiguration Include="Release|x64">
    3.20 +      <Configuration>Release</Configuration>
    3.21 +      <Platform>x64</Platform>
    3.22 +    </ProjectConfiguration>
    3.23 +  </ItemGroup>
    3.24 +  <PropertyGroup Label="Globals">
    3.25 +    <ProjectGuid>{941007A1-6375-4507-8745-FC3EA9DF010B}</ProjectGuid>
    3.26 +    <Keyword>Win32Proj</Keyword>
    3.27 +    <RootNamespace>maxgoat_stub</RootNamespace>
    3.28 +  </PropertyGroup>
    3.29 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    3.30 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    3.31 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
    3.32 +    <UseDebugLibraries>true</UseDebugLibraries>
    3.33 +    <PlatformToolset>v100</PlatformToolset>
    3.34 +    <CharacterSet>Unicode</CharacterSet>
    3.35 +  </PropertyGroup>
    3.36 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    3.37 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
    3.38 +    <UseDebugLibraries>true</UseDebugLibraries>
    3.39 +    <PlatformToolset>v100</PlatformToolset>
    3.40 +    <CharacterSet>Unicode</CharacterSet>
    3.41 +  </PropertyGroup>
    3.42 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    3.43 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
    3.44 +    <UseDebugLibraries>false</UseDebugLibraries>
    3.45 +    <PlatformToolset>v100</PlatformToolset>
    3.46 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    3.47 +    <CharacterSet>Unicode</CharacterSet>
    3.48 +  </PropertyGroup>
    3.49 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    3.50 +    <ConfigurationType>DynamicLibrary</ConfigurationType>
    3.51 +    <UseDebugLibraries>false</UseDebugLibraries>
    3.52 +    <PlatformToolset>v100</PlatformToolset>
    3.53 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    3.54 +    <CharacterSet>Unicode</CharacterSet>
    3.55 +  </PropertyGroup>
    3.56 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    3.57 +  <ImportGroup Label="ExtensionSettings">
    3.58 +  </ImportGroup>
    3.59 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.60 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    3.61 +  </ImportGroup>
    3.62 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
    3.63 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    3.64 +  </ImportGroup>
    3.65 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.66 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    3.67 +  </ImportGroup>
    3.68 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    3.69 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    3.70 +  </ImportGroup>
    3.71 +  <PropertyGroup Label="UserMacros" />
    3.72 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.73 +    <LinkIncremental>true</LinkIncremental>
    3.74 +  </PropertyGroup>
    3.75 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    3.76 +    <LinkIncremental>false</LinkIncremental>
    3.77 +  </PropertyGroup>
    3.78 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    3.79 +    <LinkIncremental>false</LinkIncremental>
    3.80 +  </PropertyGroup>
    3.81 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    3.82 +    <LinkIncremental>false</LinkIncremental>
    3.83 +  </PropertyGroup>
    3.84 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    3.85 +    <ClCompile>
    3.86 +      <PrecompiledHeader>
    3.87 +      </PrecompiledHeader>
    3.88 +      <WarningLevel>Level3</WarningLevel>
    3.89 +      <Optimization>Disabled</Optimization>
    3.90 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    3.91 +    </ClCompile>
    3.92 +    <Link>
    3.93 +      <SubSystem>Windows</SubSystem>
    3.94 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    3.95 +    </Link>
    3.96 +  </ItemDefinitionGroup>
    3.97 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    3.98 +    <ClCompile>
    3.99 +      <PrecompiledHeader>
   3.100 +      </PrecompiledHeader>
   3.101 +      <WarningLevel>Level3</WarningLevel>
   3.102 +      <Optimization>Disabled</Optimization>
   3.103 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   3.104 +      <DisableSpecificWarnings>4996</DisableSpecificWarnings>
   3.105 +    </ClCompile>
   3.106 +    <Link>
   3.107 +      <SubSystem>Windows</SubSystem>
   3.108 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   3.109 +    </Link>
   3.110 +    <PostBuildEvent>
   3.111 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
   3.112 +    </PostBuildEvent>
   3.113 +  </ItemDefinitionGroup>
   3.114 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
   3.115 +    <ClCompile>
   3.116 +      <WarningLevel>Level3</WarningLevel>
   3.117 +      <PrecompiledHeader>
   3.118 +      </PrecompiledHeader>
   3.119 +      <Optimization>MaxSpeed</Optimization>
   3.120 +      <FunctionLevelLinking>true</FunctionLevelLinking>
   3.121 +      <IntrinsicFunctions>true</IntrinsicFunctions>
   3.122 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   3.123 +    </ClCompile>
   3.124 +    <Link>
   3.125 +      <SubSystem>Windows</SubSystem>
   3.126 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   3.127 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
   3.128 +      <OptimizeReferences>true</OptimizeReferences>
   3.129 +    </Link>
   3.130 +  </ItemDefinitionGroup>
   3.131 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   3.132 +    <ClCompile>
   3.133 +      <WarningLevel>Level3</WarningLevel>
   3.134 +      <PrecompiledHeader>
   3.135 +      </PrecompiledHeader>
   3.136 +      <Optimization>MaxSpeed</Optimization>
   3.137 +      <FunctionLevelLinking>true</FunctionLevelLinking>
   3.138 +      <IntrinsicFunctions>true</IntrinsicFunctions>
   3.139 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MAXGOAT_STUB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   3.140 +      <DisableSpecificWarnings>4996</DisableSpecificWarnings>
   3.141 +    </ClCompile>
   3.142 +    <Link>
   3.143 +      <SubSystem>Windows</SubSystem>
   3.144 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   3.145 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
   3.146 +      <OptimizeReferences>true</OptimizeReferences>
   3.147 +    </Link>
   3.148 +    <PostBuildEvent>
   3.149 +      <Command>copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle"</Command>
   3.150 +    </PostBuildEvent>
   3.151 +  </ItemDefinitionGroup>
   3.152 +  <ItemGroup>
   3.153 +    <ClCompile Include="src\stub.cc" />
   3.154 +  </ItemGroup>
   3.155 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   3.156 +  <ImportGroup Label="ExtensionTargets">
   3.157 +  </ImportGroup>
   3.158 +</Project>
   3.159 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/exporters/maxgoat_stub/maxgoat_stub.vcxproj.filters	Tue Mar 25 03:19:55 2014 +0200
     4.3 @@ -0,0 +1,22 @@
     4.4 +<?xml version="1.0" encoding="utf-8"?>
     4.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     4.6 +  <ItemGroup>
     4.7 +    <Filter Include="Source Files">
     4.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     4.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    4.10 +    </Filter>
    4.11 +    <Filter Include="Header Files">
    4.12 +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
    4.13 +      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
    4.14 +    </Filter>
    4.15 +    <Filter Include="Resource Files">
    4.16 +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
    4.17 +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    4.18 +    </Filter>
    4.19 +  </ItemGroup>
    4.20 +  <ItemGroup>
    4.21 +    <ClCompile Include="src\stub.cc">
    4.22 +      <Filter>Source Files</Filter>
    4.23 +    </ClCompile>
    4.24 +  </ItemGroup>
    4.25 +</Project>
    4.26 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/exporters/maxgoat_stub/src/stub.cc	Tue Mar 25 03:19:55 2014 +0200
     5.3 @@ -0,0 +1,270 @@
     5.4 +#include <stdio.h>
     5.5 +#include <string.h>
     5.6 +#include <stdlib.h>
     5.7 +#include <errno.h>
     5.8 +#include <map>
     5.9 +#include <windows.h>
    5.10 +#include <shlobj.h>
    5.11 +#include "max.h"
    5.12 +#include "impexp.h"		// SceneExport
    5.13 +#include "iparamb2.h"	// ClassDesc2
    5.14 +#include "plugapi.h"
    5.15 +#include "IGame.h"
    5.16 +#include "IGameExport.h"
    5.17 +#include "IConversionmanager.h"
    5.18 +
    5.19 +
    5.20 +#pragma comment (lib, "core.lib")
    5.21 +#pragma comment (lib, "geom.lib")
    5.22 +#pragma comment (lib, "gfx.lib")
    5.23 +#pragma comment (lib, "mesh.lib")
    5.24 +#pragma comment (lib, "maxutil.lib")
    5.25 +#pragma comment (lib, "maxscrpt.lib")
    5.26 +#pragma comment (lib, "paramblk2.lib")
    5.27 +#pragma comment (lib, "msxml2.lib")
    5.28 +#pragma comment (lib, "igame.lib")
    5.29 +#pragma comment (lib, "comctl32.lib")
    5.30 +
    5.31 +
    5.32 +#define VER_MAJOR	1
    5.33 +#define VER_MINOR	0
    5.34 +#define VERSION(major, minor) \
    5.35 +	((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor)))
    5.36 +
    5.37 +typedef int (*PluginInitFunc)();
    5.38 +typedef int (*PluginShutdownFunc)();
    5.39 +typedef ClassDesc *(*PluginClassDescFunc)(int);
    5.40 +
    5.41 +static FILE *logfile;
    5.42 +static HINSTANCE hinst;
    5.43 +
    5.44 +class GoatExporterStub : public SceneExport {
    5.45 +private:
    5.46 +
    5.47 +public:
    5.48 +	IGameScene *igame;
    5.49 +
    5.50 +	int ExtCount();
    5.51 +	const TCHAR *Ext(int n);
    5.52 +	const TCHAR *LongDesc();
    5.53 +	const TCHAR *ShortDesc();
    5.54 +	const TCHAR *AuthorName();
    5.55 +	const TCHAR *CopyrightMessage();
    5.56 +	const TCHAR *OtherMessage1();
    5.57 +	const TCHAR *OtherMessage2();
    5.58 +	unsigned int Version();
    5.59 +	void ShowAbout(HWND win);
    5.60 +
    5.61 +	int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0);
    5.62 +};
    5.63 +
    5.64 +
    5.65 +int GoatExporterStub::ExtCount()
    5.66 +{
    5.67 +	return 1;
    5.68 +}
    5.69 +
    5.70 +const TCHAR *GoatExporterStub::Ext(int n)
    5.71 +{
    5.72 +	return L"xml";
    5.73 +}
    5.74 +
    5.75 +const TCHAR *GoatExporterStub::LongDesc()
    5.76 +{
    5.77 +	return L"Goat3D scene file";
    5.78 +}
    5.79 +
    5.80 +const TCHAR *GoatExporterStub::ShortDesc()
    5.81 +{
    5.82 +	return L"Goat3D";
    5.83 +}
    5.84 +
    5.85 +const TCHAR *GoatExporterStub::AuthorName()
    5.86 +{
    5.87 +	return L"John Tsiombikas";
    5.88 +}
    5.89 +
    5.90 +const TCHAR *GoatExporterStub::CopyrightMessage()
    5.91 +{
    5.92 +	return L"Copyright 2013 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details.";
    5.93 +}
    5.94 +
    5.95 +const TCHAR *GoatExporterStub::OtherMessage1()
    5.96 +{
    5.97 +	return L"other1";
    5.98 +}
    5.99 +
   5.100 +const TCHAR *GoatExporterStub::OtherMessage2()
   5.101 +{
   5.102 +	return L"other2";
   5.103 +}
   5.104 +
   5.105 +unsigned int GoatExporterStub::Version()
   5.106 +{
   5.107 +	return VERSION(VER_MAJOR, VER_MINOR);
   5.108 +}
   5.109 +
   5.110 +void GoatExporterStub::ShowAbout(HWND win)
   5.111 +{
   5.112 +	MessageBoxA(win, "Goat3D exporter stub", "About this plugin", 0);
   5.113 +}
   5.114 +
   5.115 +static const char *find_dll_dir()
   5.116 +{
   5.117 +	static char path[MAX_PATH];
   5.118 +
   5.119 +	HMODULE dll;
   5.120 +	if(!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
   5.121 +			(LPCSTR)find_dll_dir, &dll)) {
   5.122 +		return 0;
   5.123 +	}
   5.124 +	GetModuleFileNameA(dll, path, sizeof path);
   5.125 +
   5.126 +	char *last_slash = strrchr(path, '\\');
   5.127 +	if(last_slash && last_slash[1]) {
   5.128 +		*last_slash = 0;
   5.129 +	}
   5.130 +
   5.131 +	return path;
   5.132 +}
   5.133 +
   5.134 +/* TODO: open a dialog, let the user select goat3d or goat3danim, then load the correct dll
   5.135 + */
   5.136 +int GoatExporterStub::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface,
   5.137 +		BOOL non_interactive, DWORD opt)
   5.138 +{
   5.139 +	const char *dll_fname = "maxgoat.dll";
   5.140 +	char *dll_path;
   5.141 +	HMODULE dll = 0;
   5.142 +	PluginInitFunc init;
   5.143 +	PluginShutdownFunc shutdown;
   5.144 +	PluginClassDescFunc get_class_desc;
   5.145 +	ClassDesc *desc;
   5.146 +	SceneExport *ex;
   5.147 +	int result = IMPEXP_FAIL;
   5.148 +
   5.149 +	const char *plugdir = find_dll_dir();
   5.150 +	if(plugdir) {
   5.151 +		dll_path = new char[strlen(dll_fname) + strlen(plugdir) + 2];
   5.152 +		sprintf(dll_path, "%s\\%s", plugdir, dll_fname);
   5.153 +	} else {
   5.154 +		dll_path = new char[strlen(dll_fname) + 1];
   5.155 +		strcpy(dll_path, dll_fname);
   5.156 +	}
   5.157 +
   5.158 +	if(!(dll = LoadLibraryA(dll_path))) {
   5.159 +		fprintf(logfile, "failed to load exporter: %s\n", dll_path);
   5.160 +		goto done;
   5.161 +	}
   5.162 +
   5.163 +	if(!(get_class_desc = (PluginClassDescFunc)GetProcAddress(dll, "LibClassDesc"))) {
   5.164 +		fprintf(logfile, "maxgoat.dll is invalid (no LibClassDesc function)\n");
   5.165 +		goto done;
   5.166 +	}
   5.167 +
   5.168 +	// first initialize the library
   5.169 +	if((init = (PluginInitFunc)GetProcAddress(dll, "LibInitialize"))) {
   5.170 +		if(!init()) {
   5.171 +			fprintf(logfile, "exporter initialization failed!\n");
   5.172 +			goto done;
   5.173 +		}
   5.174 +	}
   5.175 +
   5.176 +	// TODO: pass 1 for anim
   5.177 +	if(!(desc = get_class_desc(0))) {
   5.178 +		fprintf(logfile, "failed to get the class descriptor\n");
   5.179 +		goto done;
   5.180 +	}
   5.181 +
   5.182 +	if(!(ex = (SceneExport*)desc->Create())) {
   5.183 +		fprintf(logfile, "failed to create exporter class instance\n");
   5.184 +		goto done;
   5.185 +	}
   5.186 +
   5.187 +	result = ex->DoExport(name, eiface, iface);
   5.188 +	delete ex;
   5.189 +
   5.190 +	if((shutdown = (PluginShutdownFunc)GetProcAddress(dll, "LibShutdown"))) {
   5.191 +		shutdown();
   5.192 +	}
   5.193 +
   5.194 +done:
   5.195 +	delete [] dll_path;
   5.196 +	if(dll) {
   5.197 +		FreeLibrary(dll);
   5.198 +	}
   5.199 +	return result;
   5.200 +}
   5.201 +
   5.202 +
   5.203 +// ------------------------------------------
   5.204 +
   5.205 +class GoatClassDesc : public ClassDesc2 {
   5.206 +public:
   5.207 +	int IsPublic() { return TRUE; }
   5.208 +	void *Create(BOOL loading = FALSE) { return new GoatExporterStub; }
   5.209 +	const TCHAR *ClassName() { return L"GoatExporterStub"; }
   5.210 +	SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
   5.211 +	Class_ID ClassID() { return Class_ID(0x2e4e6311, 0x2b154d91); }
   5.212 +	const TCHAR *Category() { return L"Mutant Stargoat"; }
   5.213 +
   5.214 +	const TCHAR *InternalName() { return L"GoatExporterStub"; }
   5.215 +	HINSTANCE HInstance() { return hinst; }
   5.216 +};
   5.217 +
   5.218 +static GoatClassDesc class_desc;
   5.219 +
   5.220 +BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved)
   5.221 +{
   5.222 +	if(reason == DLL_PROCESS_ATTACH) {
   5.223 +		hinst = inst_handle;
   5.224 +		DisableThreadLibraryCalls(hinst);
   5.225 +	}
   5.226 +	return TRUE;
   5.227 +}
   5.228 +
   5.229 +extern "C" {
   5.230 +
   5.231 +__declspec(dllexport) const TCHAR *LibDescription()
   5.232 +{
   5.233 +	return L"Goat3D exporter stub";
   5.234 +}
   5.235 +
   5.236 +__declspec(dllexport) int LibNumberClasses()
   5.237 +{
   5.238 +	return 1;
   5.239 +}
   5.240 +
   5.241 +__declspec(dllexport) ClassDesc *LibClassDesc(int i)
   5.242 +{
   5.243 +	return i == 0 ? &class_desc : 0;
   5.244 +}
   5.245 +
   5.246 +__declspec(dllexport) ULONG LibVersion()
   5.247 +{
   5.248 +	return Get3DSMAXVersion();
   5.249 +}
   5.250 +
   5.251 +__declspec(dllexport) int LibInitialize()
   5.252 +{
   5.253 +	static char path[1024];
   5.254 +
   5.255 +	SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path);
   5.256 +	strcat(path, "/testexpstub.log");
   5.257 +
   5.258 +	if((logfile = fopen(path, "w"))) {
   5.259 +		setvbuf(logfile, 0, _IONBF, 0);
   5.260 +	}
   5.261 +	return TRUE;
   5.262 +}
   5.263 +
   5.264 +__declspec(dllexport) int LibShutdown()
   5.265 +{
   5.266 +	if(logfile) {
   5.267 +		fclose(logfile);
   5.268 +		logfile = 0;
   5.269 +	}
   5.270 +	return TRUE;
   5.271 +}
   5.272 +
   5.273 +}	// extern "C"
   5.274 \ No newline at end of file
     6.1 --- a/goat3d-vs2012.sln	Thu Jan 23 03:57:15 2014 +0200
     6.2 +++ b/goat3d-vs2012.sln	Tue Mar 25 03:19:55 2014 +0200
     6.3 @@ -8,30 +8,53 @@
     6.4  		{86BF319B-9222-4805-918D-DC1B9F77BCEF} = {86BF319B-9222-4805-918D-DC1B9F77BCEF}
     6.5  	EndProjectSection
     6.6  EndProject
     6.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "maxgoat_stub", "exporters\maxgoat_stub\maxgoat_stub.vcxproj", "{941007A1-6375-4507-8745-FC3EA9DF010B}"
     6.8 +EndProject
     6.9  Global
    6.10  	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    6.11 +		Debug|Mixed Platforms = Debug|Mixed Platforms
    6.12  		Debug|Win32 = Debug|Win32
    6.13  		Debug|x64 = Debug|x64
    6.14 +		Release|Mixed Platforms = Release|Mixed Platforms
    6.15  		Release|Win32 = Release|Win32
    6.16  		Release|x64 = Release|x64
    6.17  	EndGlobalSection
    6.18  	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    6.19 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
    6.20 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Mixed Platforms.Build.0 = Debug|Win32
    6.21  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Win32.ActiveCfg = Debug|Win32
    6.22  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|Win32.Build.0 = Debug|Win32
    6.23  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|x64.ActiveCfg = Debug|x64
    6.24  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Debug|x64.Build.0 = Debug|x64
    6.25 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Mixed Platforms.ActiveCfg = Release|Win32
    6.26 +		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Mixed Platforms.Build.0 = Release|Win32
    6.27  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Win32.ActiveCfg = Release|Win32
    6.28  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|Win32.Build.0 = Release|Win32
    6.29  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|x64.ActiveCfg = Release|x64
    6.30  		{86BF319B-9222-4805-918D-DC1B9F77BCEF}.Release|x64.Build.0 = Release|x64
    6.31 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
    6.32 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Mixed Platforms.Build.0 = Debug|Win32
    6.33  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Win32.ActiveCfg = Debug|Win32
    6.34  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|Win32.Build.0 = Debug|Win32
    6.35  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|x64.ActiveCfg = Debug|x64
    6.36  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Debug|x64.Build.0 = Debug|x64
    6.37 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Mixed Platforms.ActiveCfg = Release|Win32
    6.38 +		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Mixed Platforms.Build.0 = Release|Win32
    6.39  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Win32.ActiveCfg = Release|Win32
    6.40  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|Win32.Build.0 = Release|Win32
    6.41  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|x64.ActiveCfg = Release|x64
    6.42  		{5BDDFFC1-7900-45D2-92F5-525361057554}.Release|x64.Build.0 = Release|x64
    6.43 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
    6.44 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Mixed Platforms.Build.0 = Debug|Win32
    6.45 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Win32.ActiveCfg = Debug|Win32
    6.46 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|Win32.Build.0 = Debug|Win32
    6.47 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|x64.ActiveCfg = Debug|x64
    6.48 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Debug|x64.Build.0 = Debug|x64
    6.49 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Mixed Platforms.ActiveCfg = Release|Win32
    6.50 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Mixed Platforms.Build.0 = Release|Win32
    6.51 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Win32.ActiveCfg = Release|Win32
    6.52 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Win32.Build.0 = Release|Win32
    6.53 +		{941007A1-6375-4507-8745-FC3EA9DF010B}.Release|x64.ActiveCfg = Release|Win32
    6.54  	EndGlobalSection
    6.55  	GlobalSection(SolutionProperties) = preSolution
    6.56  		HideSolutionNode = FALSE
     7.1 --- a/goat3d.vcxproj	Thu Jan 23 03:57:15 2014 +0200
     7.2 +++ b/goat3d.vcxproj	Tue Mar 25 03:19:55 2014 +0200
     7.3 @@ -19,9 +19,6 @@
     7.4      </ProjectConfiguration>
     7.5    </ItemGroup>
     7.6    <ItemGroup>
     7.7 -    <ClInclude Include="libs\anim\anim.h" />
     7.8 -    <ClInclude Include="libs\anim\dynarr.h" />
     7.9 -    <ClInclude Include="libs\anim\track.h" />
    7.10      <ClInclude Include="libs\openctm\internal.h" />
    7.11      <ClInclude Include="libs\openctm\liblzma\Alloc.h" />
    7.12      <ClInclude Include="libs\openctm\liblzma\LzFind.h" />
    7.13 @@ -34,16 +31,6 @@
    7.14      <ClInclude Include="libs\openctm\openctm.h" />
    7.15      <ClInclude Include="libs\openctm\openctmpp.h" />
    7.16      <ClInclude Include="libs\tinyxml2\tinyxml2.h" />
    7.17 -    <ClInclude Include="libs\vmath\basis.h" />
    7.18 -    <ClInclude Include="libs\vmath\geom.h" />
    7.19 -    <ClInclude Include="libs\vmath\matrix.h" />
    7.20 -    <ClInclude Include="libs\vmath\quat.h" />
    7.21 -    <ClInclude Include="libs\vmath\ray.h" />
    7.22 -    <ClInclude Include="libs\vmath\sphvec.h" />
    7.23 -    <ClInclude Include="libs\vmath\vector.h" />
    7.24 -    <ClInclude Include="libs\vmath\vmath.h" />
    7.25 -    <ClInclude Include="libs\vmath\vmath_config.h" />
    7.26 -    <ClInclude Include="libs\vmath\vmath_types.h" />
    7.27      <ClInclude Include="src\camera.h" />
    7.28      <ClInclude Include="src\chunk.h" />
    7.29      <ClInclude Include="src\goat3d.h" />
    7.30 @@ -57,9 +44,6 @@
    7.31      <ClInclude Include="src\xform_node.h" />
    7.32    </ItemGroup>
    7.33    <ItemGroup>
    7.34 -    <ClCompile Include="libs\anim\anim.c" />
    7.35 -    <ClCompile Include="libs\anim\dynarr.c" />
    7.36 -    <ClCompile Include="libs\anim\track.c" />
    7.37      <ClCompile Include="libs\openctm\compressMG1.c" />
    7.38      <ClCompile Include="libs\openctm\compressMG2.c" />
    7.39      <ClCompile Include="libs\openctm\compressRAW.c" />
    7.40 @@ -71,21 +55,10 @@
    7.41      <ClCompile Include="libs\openctm\openctm.c" />
    7.42      <ClCompile Include="libs\openctm\stream.c" />
    7.43      <ClCompile Include="libs\tinyxml2\tinyxml2.cpp" />
    7.44 -    <ClCompile Include="libs\vmath\basis.cc" />
    7.45 -    <ClCompile Include="libs\vmath\basis_c.c" />
    7.46 -    <ClCompile Include="libs\vmath\geom.c" />
    7.47 -    <ClCompile Include="libs\vmath\matrix.cc" />
    7.48 -    <ClCompile Include="libs\vmath\matrix_c.c" />
    7.49 -    <ClCompile Include="libs\vmath\quat.cc" />
    7.50 -    <ClCompile Include="libs\vmath\quat_c.c" />
    7.51 -    <ClCompile Include="libs\vmath\ray.cc" />
    7.52 -    <ClCompile Include="libs\vmath\ray_c.c" />
    7.53 -    <ClCompile Include="libs\vmath\sphvec.cc" />
    7.54 -    <ClCompile Include="libs\vmath\vector.cc" />
    7.55 -    <ClCompile Include="libs\vmath\vmath.c" />
    7.56      <ClCompile Include="src\camera.cc" />
    7.57      <ClCompile Include="src\chunk.cc" />
    7.58      <ClCompile Include="src\goat3d.cc" />
    7.59 +    <ClCompile Include="src\goat3d_read.cc" />
    7.60      <ClCompile Include="src\goat3d_readxml.cc" />
    7.61      <ClCompile Include="src\goat3d_write.cc" />
    7.62      <ClCompile Include="src\goat3d_writexml.cc" />
    7.63 @@ -97,13 +70,6 @@
    7.64      <ClCompile Include="src\scene.cc" />
    7.65      <ClCompile Include="src\xform_node.cc" />
    7.66    </ItemGroup>
    7.67 -  <ItemGroup>
    7.68 -    <None Include="libs\vmath\matrix.inl" />
    7.69 -    <None Include="libs\vmath\quat.inl" />
    7.70 -    <None Include="libs\vmath\ray.inl" />
    7.71 -    <None Include="libs\vmath\vector.inl" />
    7.72 -    <None Include="libs\vmath\vmath.inl" />
    7.73 -  </ItemGroup>
    7.74    <PropertyGroup Label="Globals">
    7.75      <ProjectGuid>{86BF319B-9222-4805-918D-DC1B9F77BCEF}</ProjectGuid>
    7.76      <Keyword>Win32Proj</Keyword>
    7.77 @@ -164,8 +130,9 @@
    7.78        </PrecompiledHeader>
    7.79        <WarningLevel>Level3</WarningLevel>
    7.80        <Optimization>Disabled</Optimization>
    7.81 -      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    7.82 -      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
    7.83 +      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;OPENCTM_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    7.84 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
    7.85 +      <AdditionalIncludeDirectories>$(ProjectDir)\libs\openctm;$(ProjectDir)\libs\openctm\liblzma;$(ProjectDir)\libs\tinyxml2</AdditionalIncludeDirectories>
    7.86      </ClCompile>
    7.87      <Link>
    7.88        <SubSystem>Windows</SubSystem>
    7.89 @@ -180,7 +147,7 @@
    7.90        <Optimization>Disabled</Optimization>
    7.91        <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC;BUILD_MAXPLUGIN</PreprocessorDefinitions>
    7.92        <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
    7.93 -      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath</AdditionalIncludeDirectories>
    7.94 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2</AdditionalIncludeDirectories>
    7.95      </ClCompile>
    7.96      <Link>
    7.97        <SubSystem>Windows</SubSystem>
    7.98 @@ -199,8 +166,9 @@
    7.99        <Optimization>MaxSpeed</Optimization>
   7.100        <FunctionLevelLinking>true</FunctionLevelLinking>
   7.101        <IntrinsicFunctions>true</IntrinsicFunctions>
   7.102 -      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   7.103 -      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
   7.104 +      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;OPENCTM_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   7.105 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   7.106 +      <AdditionalIncludeDirectories>$(ProjectDir)\libs\openctm;$(ProjectDir)\libs\openctm\liblzma;$(ProjectDir)\libs\tinyxml2</AdditionalIncludeDirectories>
   7.107      </ClCompile>
   7.108      <Link>
   7.109        <SubSystem>Windows</SubSystem>
   7.110 @@ -219,7 +187,7 @@
   7.111        <IntrinsicFunctions>true</IntrinsicFunctions>
   7.112        <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);OPENCTM_STATIC</PreprocessorDefinitions>
   7.113        <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   7.114 -      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2;$(SolutionDir)\libs\anim;$(SolutionDir)\libs\vmath</AdditionalIncludeDirectories>
   7.115 +      <AdditionalIncludeDirectories>$(SolutionDir)\src;$(SolutionDir)\libs\openctm;$(SolutionDir)\libs\openctm\liblzma;$(SolutionDir)\libs\tinyxml2</AdditionalIncludeDirectories>
   7.116      </ClCompile>
   7.117      <Link>
   7.118        <SubSystem>Windows</SubSystem>
     8.1 --- a/goat3d.vcxproj.filters	Thu Jan 23 03:57:15 2014 +0200
     8.2 +++ b/goat3d.vcxproj.filters	Tue Mar 25 03:19:55 2014 +0200
     8.3 @@ -17,12 +17,6 @@
     8.4      <Filter Include="libs\openctm\liblzma">
     8.5        <UniqueIdentifier>{18a85bea-ddb2-49a1-a7b1-bd11b23d5549}</UniqueIdentifier>
     8.6      </Filter>
     8.7 -    <Filter Include="libs\vmath">
     8.8 -      <UniqueIdentifier>{dc4ab435-af1e-4786-8011-a7a793e229eb}</UniqueIdentifier>
     8.9 -    </Filter>
    8.10 -    <Filter Include="libs\anim">
    8.11 -      <UniqueIdentifier>{05d8010d-b4d9-4829-80ea-8c8d018e1e04}</UniqueIdentifier>
    8.12 -    </Filter>
    8.13    </ItemGroup>
    8.14    <ItemGroup>
    8.15      <ClInclude Include="src\camera.h">
    8.16 @@ -94,45 +88,6 @@
    8.17      <ClInclude Include="libs\openctm\liblzma\Types.h">
    8.18        <Filter>libs\openctm\liblzma</Filter>
    8.19      </ClInclude>
    8.20 -    <ClInclude Include="libs\anim\anim.h">
    8.21 -      <Filter>libs\anim</Filter>
    8.22 -    </ClInclude>
    8.23 -    <ClInclude Include="libs\anim\dynarr.h">
    8.24 -      <Filter>libs\anim</Filter>
    8.25 -    </ClInclude>
    8.26 -    <ClInclude Include="libs\anim\track.h">
    8.27 -      <Filter>libs\anim</Filter>
    8.28 -    </ClInclude>
    8.29 -    <ClInclude Include="libs\vmath\basis.h">
    8.30 -      <Filter>libs\vmath</Filter>
    8.31 -    </ClInclude>
    8.32 -    <ClInclude Include="libs\vmath\geom.h">
    8.33 -      <Filter>libs\vmath</Filter>
    8.34 -    </ClInclude>
    8.35 -    <ClInclude Include="libs\vmath\matrix.h">
    8.36 -      <Filter>libs\vmath</Filter>
    8.37 -    </ClInclude>
    8.38 -    <ClInclude Include="libs\vmath\quat.h">
    8.39 -      <Filter>libs\vmath</Filter>
    8.40 -    </ClInclude>
    8.41 -    <ClInclude Include="libs\vmath\ray.h">
    8.42 -      <Filter>libs\vmath</Filter>
    8.43 -    </ClInclude>
    8.44 -    <ClInclude Include="libs\vmath\sphvec.h">
    8.45 -      <Filter>libs\vmath</Filter>
    8.46 -    </ClInclude>
    8.47 -    <ClInclude Include="libs\vmath\vector.h">
    8.48 -      <Filter>libs\vmath</Filter>
    8.49 -    </ClInclude>
    8.50 -    <ClInclude Include="libs\vmath\vmath.h">
    8.51 -      <Filter>libs\vmath</Filter>
    8.52 -    </ClInclude>
    8.53 -    <ClInclude Include="libs\vmath\vmath_config.h">
    8.54 -      <Filter>libs\vmath</Filter>
    8.55 -    </ClInclude>
    8.56 -    <ClInclude Include="libs\vmath\vmath_types.h">
    8.57 -      <Filter>libs\vmath</Filter>
    8.58 -    </ClInclude>
    8.59    </ItemGroup>
    8.60    <ItemGroup>
    8.61      <ClCompile Include="src\goat3d.cc">
    8.62 @@ -207,67 +162,8 @@
    8.63      <ClCompile Include="libs\openctm\liblzma\LzmaLib.c">
    8.64        <Filter>libs\openctm\liblzma</Filter>
    8.65      </ClCompile>
    8.66 -    <ClCompile Include="libs\anim\anim.c">
    8.67 -      <Filter>libs\anim</Filter>
    8.68 -    </ClCompile>
    8.69 -    <ClCompile Include="libs\anim\dynarr.c">
    8.70 -      <Filter>libs\anim</Filter>
    8.71 -    </ClCompile>
    8.72 -    <ClCompile Include="libs\anim\track.c">
    8.73 -      <Filter>libs\anim</Filter>
    8.74 -    </ClCompile>
    8.75 -    <ClCompile Include="libs\vmath\basis.cc">
    8.76 -      <Filter>libs\vmath</Filter>
    8.77 -    </ClCompile>
    8.78 -    <ClCompile Include="libs\vmath\basis_c.c">
    8.79 -      <Filter>libs\vmath</Filter>
    8.80 -    </ClCompile>
    8.81 -    <ClCompile Include="libs\vmath\geom.c">
    8.82 -      <Filter>libs\vmath</Filter>
    8.83 -    </ClCompile>
    8.84 -    <ClCompile Include="libs\vmath\matrix.cc">
    8.85 -      <Filter>libs\vmath</Filter>
    8.86 -    </ClCompile>
    8.87 -    <ClCompile Include="libs\vmath\matrix_c.c">
    8.88 -      <Filter>libs\vmath</Filter>
    8.89 -    </ClCompile>
    8.90 -    <ClCompile Include="libs\vmath\quat.cc">
    8.91 -      <Filter>libs\vmath</Filter>
    8.92 -    </ClCompile>
    8.93 -    <ClCompile Include="libs\vmath\quat_c.c">
    8.94 -      <Filter>libs\vmath</Filter>
    8.95 -    </ClCompile>
    8.96 -    <ClCompile Include="libs\vmath\ray.cc">
    8.97 -      <Filter>libs\vmath</Filter>
    8.98 -    </ClCompile>
    8.99 -    <ClCompile Include="libs\vmath\ray_c.c">
   8.100 -      <Filter>libs\vmath</Filter>
   8.101 -    </ClCompile>
   8.102 -    <ClCompile Include="libs\vmath\sphvec.cc">
   8.103 -      <Filter>libs\vmath</Filter>
   8.104 -    </ClCompile>
   8.105 -    <ClCompile Include="libs\vmath\vector.cc">
   8.106 -      <Filter>libs\vmath</Filter>
   8.107 -    </ClCompile>
   8.108 -    <ClCompile Include="libs\vmath\vmath.c">
   8.109 -      <Filter>libs\vmath</Filter>
   8.110 +    <ClCompile Include="src\goat3d_read.cc">
   8.111 +      <Filter>src</Filter>
   8.112      </ClCompile>
   8.113    </ItemGroup>
   8.114 -  <ItemGroup>
   8.115 -    <None Include="libs\vmath\matrix.inl">
   8.116 -      <Filter>libs\vmath</Filter>
   8.117 -    </None>
   8.118 -    <None Include="libs\vmath\quat.inl">
   8.119 -      <Filter>libs\vmath</Filter>
   8.120 -    </None>
   8.121 -    <None Include="libs\vmath\ray.inl">
   8.122 -      <Filter>libs\vmath</Filter>
   8.123 -    </None>
   8.124 -    <None Include="libs\vmath\vector.inl">
   8.125 -      <Filter>libs\vmath</Filter>
   8.126 -    </None>
   8.127 -    <None Include="libs\vmath\vmath.inl">
   8.128 -      <Filter>libs\vmath</Filter>
   8.129 -    </None>
   8.130 -  </ItemGroup>
   8.131  </Project>
   8.132 \ No newline at end of file
     9.1 --- a/libs/anim/Makefile	Thu Jan 23 03:57:15 2014 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,17 +0,0 @@
     9.4 -src = $(wildcard *.c)
     9.5 -obj = $(src:.c=.o)
     9.6 -lib = libanim.a
     9.7 -
     9.8 -ifneq ($(shell uname -s), Darwin)
     9.9 -	pic = -fPIC
    9.10 -endif
    9.11 -
    9.12 -CFLAGS = -pedantic -Wall -g $(pic)
    9.13 -CXXFLAGS = -pedantic -Wall -g $(pic)
    9.14 -
    9.15 -$(lib): $(obj)
    9.16 -	$(AR) rcs $@ $(obj)
    9.17 -
    9.18 -.PHONY: clean
    9.19 -clean:
    9.20 -	rm -f $(obj) $(lib)
    10.1 --- a/libs/anim/anim.c	Thu Jan 23 03:57:15 2014 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,947 +0,0 @@
    10.4 -#include <stdlib.h>
    10.5 -#include <limits.h>
    10.6 -#include <assert.h>
    10.7 -#include "anim.h"
    10.8 -#include "dynarr.h"
    10.9 -
   10.10 -#define ROT_USE_SLERP
   10.11 -
   10.12 -static void invalidate_cache(struct anm_node *node);
   10.13 -
   10.14 -int anm_init_animation(struct anm_animation *anim)
   10.15 -{
   10.16 -	int i, j;
   10.17 -	static const float defaults[] = {
   10.18 -		0.0f, 0.0f, 0.0f,		/* default position */
   10.19 -		0.0f, 0.0f, 0.0f, 1.0f,	/* default rotation quat */
   10.20 -		1.0f, 1.0f, 1.0f		/* default scale factor */
   10.21 -	};
   10.22 -
   10.23 -	anim->name = 0;
   10.24 -
   10.25 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
   10.26 -		if(anm_init_track(anim->tracks + i) == -1) {
   10.27 -			for(j=0; j<i; j++) {
   10.28 -				anm_destroy_track(anim->tracks + i);
   10.29 -			}
   10.30 -		}
   10.31 -		anm_set_track_default(anim->tracks + i, defaults[i]);
   10.32 -	}
   10.33 -	return 0;
   10.34 -}
   10.35 -
   10.36 -void anm_destroy_animation(struct anm_animation *anim)
   10.37 -{
   10.38 -	int i;
   10.39 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
   10.40 -		anm_destroy_track(anim->tracks + i);
   10.41 -	}
   10.42 -	free(anim->name);
   10.43 -}
   10.44 -
   10.45 -void anm_set_animation_name(struct anm_animation *anim, const char *name)
   10.46 -{
   10.47 -	char *newname = malloc(strlen(name) + 1);
   10.48 -	if(!newname) return;
   10.49 -
   10.50 -	strcpy(newname, name);
   10.51 -
   10.52 -	free(anim->name);
   10.53 -	anim->name = newname;
   10.54 -}
   10.55 -
   10.56 -/* ---- node implementation ----- */
   10.57 -
   10.58 -int anm_init_node(struct anm_node *node)
   10.59 -{
   10.60 -	memset(node, 0, sizeof *node);
   10.61 -
   10.62 -	node->cur_anim[1] = -1;
   10.63 -
   10.64 -	if(!(node->animations = dynarr_alloc(1, sizeof *node->animations))) {
   10.65 -		return -1;
   10.66 -	}
   10.67 -	if(anm_init_animation(node->animations) == -1) {
   10.68 -		dynarr_free(node->animations);
   10.69 -		return -1;
   10.70 -	}
   10.71 -
   10.72 -	/* initialize thread-local matrix cache */
   10.73 -	pthread_key_create(&node->cache_key, 0);
   10.74 -	pthread_mutex_init(&node->cache_list_lock, 0);
   10.75 -
   10.76 -	return 0;
   10.77 -}
   10.78 -
   10.79 -void anm_destroy_node(struct anm_node *node)
   10.80 -{
   10.81 -	int i, num_anim;
   10.82 -	free(node->name);
   10.83 -
   10.84 -	num_anim = anm_get_animation_count(node);
   10.85 -	for(i=0; i<num_anim; i++) {
   10.86 -		anm_destroy_animation(node->animations + i);
   10.87 -	}
   10.88 -	dynarr_free(node->animations);
   10.89 -
   10.90 -	/* destroy thread-specific cache */
   10.91 -	pthread_key_delete(node->cache_key);
   10.92 -
   10.93 -	while(node->cache_list) {
   10.94 -		struct mat_cache *tmp = node->cache_list;
   10.95 -		node->cache_list = tmp->next;
   10.96 -		free(tmp);
   10.97 -	}
   10.98 -}
   10.99 -
  10.100 -void anm_destroy_node_tree(struct anm_node *tree)
  10.101 -{
  10.102 -	struct anm_node *c, *tmp;
  10.103 -
  10.104 -	if(!tree) return;
  10.105 -
  10.106 -	c = tree->child;
  10.107 -	while(c) {
  10.108 -		tmp = c;
  10.109 -		c = c->next;
  10.110 -
  10.111 -		anm_destroy_node_tree(tmp);
  10.112 -	}
  10.113 -	anm_destroy_node(tree);
  10.114 -}
  10.115 -
  10.116 -struct anm_node *anm_create_node(void)
  10.117 -{
  10.118 -	struct anm_node *n;
  10.119 -
  10.120 -	if((n = malloc(sizeof *n))) {
  10.121 -		if(anm_init_node(n) == -1) {
  10.122 -			free(n);
  10.123 -			return 0;
  10.124 -		}
  10.125 -	}
  10.126 -	return n;
  10.127 -}
  10.128 -
  10.129 -void anm_free_node(struct anm_node *node)
  10.130 -{
  10.131 -	anm_destroy_node(node);
  10.132 -	free(node);
  10.133 -}
  10.134 -
  10.135 -void anm_free_node_tree(struct anm_node *tree)
  10.136 -{
  10.137 -	struct anm_node *c, *tmp;
  10.138 -
  10.139 -	if(!tree) return;
  10.140 -
  10.141 -	c = tree->child;
  10.142 -	while(c) {
  10.143 -		tmp = c;
  10.144 -		c = c->next;
  10.145 -
  10.146 -		anm_free_node_tree(tmp);
  10.147 -	}
  10.148 -
  10.149 -	anm_free_node(tree);
  10.150 -}
  10.151 -
  10.152 -int anm_set_node_name(struct anm_node *node, const char *name)
  10.153 -{
  10.154 -	char *str;
  10.155 -
  10.156 -	if(!(str = malloc(strlen(name) + 1))) {
  10.157 -		return -1;
  10.158 -	}
  10.159 -	strcpy(str, name);
  10.160 -	free(node->name);
  10.161 -	node->name = str;
  10.162 -	return 0;
  10.163 -}
  10.164 -
  10.165 -const char *anm_get_node_name(struct anm_node *node)
  10.166 -{
  10.167 -	return node->name ? node->name : "";
  10.168 -}
  10.169 -
  10.170 -void anm_link_node(struct anm_node *p, struct anm_node *c)
  10.171 -{
  10.172 -	c->next = p->child;
  10.173 -	p->child = c;
  10.174 -
  10.175 -	c->parent = p;
  10.176 -	invalidate_cache(c);
  10.177 -}
  10.178 -
  10.179 -int anm_unlink_node(struct anm_node *p, struct anm_node *c)
  10.180 -{
  10.181 -	struct anm_node *iter;
  10.182 -
  10.183 -	if(p->child == c) {
  10.184 -		p->child = c->next;
  10.185 -		c->next = 0;
  10.186 -		invalidate_cache(c);
  10.187 -		return 0;
  10.188 -	}
  10.189 -
  10.190 -	iter = p->child;
  10.191 -	while(iter->next) {
  10.192 -		if(iter->next == c) {
  10.193 -			iter->next = c->next;
  10.194 -			c->next = 0;
  10.195 -			invalidate_cache(c);
  10.196 -			return 0;
  10.197 -		}
  10.198 -	}
  10.199 -	return -1;
  10.200 -}
  10.201 -
  10.202 -void anm_set_pivot(struct anm_node *node, vec3_t piv)
  10.203 -{
  10.204 -	node->pivot = piv;
  10.205 -}
  10.206 -
  10.207 -vec3_t anm_get_pivot(struct anm_node *node)
  10.208 -{
  10.209 -	return node->pivot;
  10.210 -}
  10.211 -
  10.212 -
  10.213 -/* animation management */
  10.214 -
  10.215 -int anm_use_node_animation(struct anm_node *node, int aidx)
  10.216 -{
  10.217 -	if(aidx == node->cur_anim[0] && node->cur_anim[1] == -1) {
  10.218 -		return 0;	/* no change, no invalidation */
  10.219 -	}
  10.220 -
  10.221 -	if(aidx < 0 || aidx >= anm_get_animation_count(node)) {
  10.222 -		return -1;
  10.223 -	}
  10.224 -
  10.225 -	node->cur_anim[0] = aidx;
  10.226 -	node->cur_anim[1] = -1;
  10.227 -	node->cur_mix = 0;
  10.228 -	node->blend_dur = -1;
  10.229 -
  10.230 -	invalidate_cache(node);
  10.231 -	return 0;
  10.232 -}
  10.233 -
  10.234 -int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t)
  10.235 -{
  10.236 -	int num_anim;
  10.237 -
  10.238 -	if(node->cur_anim[0] == aidx && node->cur_anim[1] == bidx &&
  10.239 -			fabs(t - node->cur_mix) < 1e-6) {
  10.240 -		return 0;	/* no change, no invalidation */
  10.241 -	}
  10.242 -
  10.243 -	num_anim = anm_get_animation_count(node);
  10.244 -	if(aidx < 0 || aidx >= num_anim) {
  10.245 -		return anm_use_animation(node, bidx);
  10.246 -	}
  10.247 -	if(bidx < 0 || bidx >= num_anim) {
  10.248 -		return anm_use_animation(node, aidx);
  10.249 -	}
  10.250 -	node->cur_anim[0] = aidx;
  10.251 -	node->cur_anim[1] = bidx;
  10.252 -	node->cur_mix = t;
  10.253 -
  10.254 -	invalidate_cache(node);
  10.255 -	return 0;
  10.256 -}
  10.257 -
  10.258 -int anm_use_animation(struct anm_node *node, int aidx)
  10.259 -{
  10.260 -	struct anm_node *child;
  10.261 -
  10.262 -	if(anm_use_node_animation(node, aidx) == -1) {
  10.263 -		return -1;
  10.264 -	}
  10.265 -
  10.266 -	child = node->child;
  10.267 -	while(child) {
  10.268 -		if(anm_use_animation(child, aidx) == -1) {
  10.269 -			return -1;
  10.270 -		}
  10.271 -		child = child->next;
  10.272 -	}
  10.273 -	return 0;
  10.274 -}
  10.275 -
  10.276 -int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t)
  10.277 -{
  10.278 -	struct anm_node *child;
  10.279 -
  10.280 -	if(anm_use_node_animations(node, aidx, bidx, t) == -1) {
  10.281 -		return -1;
  10.282 -	}
  10.283 -
  10.284 -	child = node->child;
  10.285 -	while(child) {
  10.286 -		if(anm_use_animations(child, aidx, bidx, t) == -1) {
  10.287 -			return -1;
  10.288 -		}
  10.289 -		child = child->next;
  10.290 -	}
  10.291 -	return 0;
  10.292 -
  10.293 -}
  10.294 -
  10.295 -void anm_set_node_animation_offset(struct anm_node *node, anm_time_t offs, int which)
  10.296 -{
  10.297 -	if(which < 0 || which >= 2) {
  10.298 -		return;
  10.299 -	}
  10.300 -	node->cur_anim_offset[which] = offs;
  10.301 -}
  10.302 -
  10.303 -anm_time_t anm_get_animation_offset(const struct anm_node *node, int which)
  10.304 -{
  10.305 -	if(which < 0 || which >= 2) {
  10.306 -		return 0;
  10.307 -	}
  10.308 -	return node->cur_anim_offset[which];
  10.309 -}
  10.310 -
  10.311 -void anm_set_animation_offset(struct anm_node *node, anm_time_t offs, int which)
  10.312 -{
  10.313 -	struct anm_node *c = node->child;
  10.314 -	while(c) {
  10.315 -		anm_set_animation_offset(c, offs, which);
  10.316 -		c = c->next;
  10.317 -	}
  10.318 -
  10.319 -	anm_set_node_animation_offset(node, offs, which);
  10.320 -}
  10.321 -
  10.322 -int anm_get_active_animation_index(const struct anm_node *node, int which)
  10.323 -{
  10.324 -	if(which < 0 || which >= 2) return -1;
  10.325 -	return node->cur_anim[which];
  10.326 -}
  10.327 -
  10.328 -struct anm_animation *anm_get_active_animation(const struct anm_node *node, int which)
  10.329 -{
  10.330 -	int idx = anm_get_active_animation_index(node, which);
  10.331 -	if(idx < 0 || idx >= anm_get_animation_count(node)) {
  10.332 -		return 0;
  10.333 -	}
  10.334 -	return node->animations + idx;
  10.335 -}
  10.336 -
  10.337 -float anm_get_active_animation_mix(const struct anm_node *node)
  10.338 -{
  10.339 -	return node->cur_mix;
  10.340 -}
  10.341 -
  10.342 -int anm_get_animation_count(const struct anm_node *node)
  10.343 -{
  10.344 -	return dynarr_size(node->animations);
  10.345 -}
  10.346 -
  10.347 -int anm_add_node_animation(struct anm_node *node)
  10.348 -{
  10.349 -	struct anm_animation newanim;
  10.350 -	anm_init_animation(&newanim);
  10.351 -
  10.352 -	node->animations = dynarr_push(node->animations, &newanim);
  10.353 -	return 0;
  10.354 -}
  10.355 -
  10.356 -int anm_remove_node_animation(struct anm_node *node, int idx)
  10.357 -{
  10.358 -	fprintf(stderr, "anm_remove_animation: unimplemented!");
  10.359 -	abort();
  10.360 -	return 0;
  10.361 -}
  10.362 -
  10.363 -int anm_add_animation(struct anm_node *node)
  10.364 -{
  10.365 -	struct anm_node *child;
  10.366 -
  10.367 -	if(anm_add_node_animation(node) == -1) {
  10.368 -		return -1;
  10.369 -	}
  10.370 -
  10.371 -	child = node->child;
  10.372 -	while(child) {
  10.373 -		if(anm_add_animation(child)) {
  10.374 -			return -1;
  10.375 -		}
  10.376 -		child = child->next;
  10.377 -	}
  10.378 -	return 0;
  10.379 -}
  10.380 -
  10.381 -int anm_remove_animation(struct anm_node *node, int idx)
  10.382 -{
  10.383 -	struct anm_node *child;
  10.384 -
  10.385 -	if(anm_remove_node_animation(node, idx) == -1) {
  10.386 -		return -1;
  10.387 -	}
  10.388 -
  10.389 -	child = node->child;
  10.390 -	while(child) {
  10.391 -		if(anm_remove_animation(child, idx) == -1) {
  10.392 -			return -1;
  10.393 -		}
  10.394 -		child = child->next;
  10.395 -	}
  10.396 -	return 0;
  10.397 -}
  10.398 -
  10.399 -struct anm_animation *anm_get_animation(struct anm_node *node, int idx)
  10.400 -{
  10.401 -	if(idx < 0 || idx > anm_get_animation_count(node)) {
  10.402 -		return 0;
  10.403 -	}
  10.404 -	return node->animations + idx;
  10.405 -}
  10.406 -
  10.407 -struct anm_animation *anm_get_animation_by_name(struct anm_node *node, const char *name)
  10.408 -{
  10.409 -	return anm_get_animation(node, anm_find_animation(node, name));
  10.410 -}
  10.411 -
  10.412 -int anm_find_animation(struct anm_node *node, const char *name)
  10.413 -{
  10.414 -	int i, count = anm_get_animation_count(node);
  10.415 -	for(i=0; i<count; i++) {
  10.416 -		if(strcmp(node->animations[i].name, name) == 0) {
  10.417 -			return i;
  10.418 -		}
  10.419 -	}
  10.420 -	return -1;
  10.421 -}
  10.422 -
  10.423 -/* all the rest act on the current animation(s) */
  10.424 -
  10.425 -void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in)
  10.426 -{
  10.427 -	int i;
  10.428 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.429 -	if(!anim) return;
  10.430 -
  10.431 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
  10.432 -		anm_set_track_interpolator(anim->tracks + i, in);
  10.433 -	}
  10.434 -	invalidate_cache(node);
  10.435 -}
  10.436 -
  10.437 -void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex)
  10.438 -{
  10.439 -	int i;
  10.440 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.441 -	if(!anim) return;
  10.442 -
  10.443 -	for(i=0; i<ANM_NUM_TRACKS; i++) {
  10.444 -		anm_set_track_extrapolator(anim->tracks + i, ex);
  10.445 -	}
  10.446 -	invalidate_cache(node);
  10.447 -}
  10.448 -
  10.449 -void anm_set_node_active_animation_name(struct anm_node *node, const char *name)
  10.450 -{
  10.451 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.452 -	if(!anim) return;
  10.453 -
  10.454 -	anm_set_animation_name(anim, name);
  10.455 -}
  10.456 -
  10.457 -void anm_set_active_animation_name(struct anm_node *node, const char *name)
  10.458 -{
  10.459 -	struct anm_node *child;
  10.460 -
  10.461 -	anm_set_node_active_animation_name(node, name);
  10.462 -
  10.463 -	child = node->child;
  10.464 -	while(child) {
  10.465 -		anm_set_active_animation_name(child, name);
  10.466 -		child = child->next;
  10.467 -	}
  10.468 -}
  10.469 -
  10.470 -const char *anm_get_active_animation_name(struct anm_node *node)
  10.471 -{
  10.472 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.473 -	if(anim) {
  10.474 -		return anim->name;
  10.475 -	}
  10.476 -	return 0;
  10.477 -}
  10.478 -
  10.479 -/* ---- high level animation blending ---- */
  10.480 -void anm_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur)
  10.481 -{
  10.482 -	struct anm_node *c = node->child;
  10.483 -
  10.484 -	if(anmidx == node->cur_anim[0]) {
  10.485 -		return;
  10.486 -	}
  10.487 -
  10.488 -	while(c) {
  10.489 -		anm_transition(c, anmidx, start, dur);
  10.490 -		c = c->next;
  10.491 -	}
  10.492 -
  10.493 -	anm_node_transition(node, anmidx, start, dur);
  10.494 -}
  10.495 -
  10.496 -void anm_node_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur)
  10.497 -{
  10.498 -	if(anmidx == node->cur_anim[0]) {
  10.499 -		return;
  10.500 -	}
  10.501 -
  10.502 -	node->cur_anim[1] = anmidx;
  10.503 -	node->cur_anim_offset[1] = start;
  10.504 -	node->blend_dur = dur;
  10.505 -}
  10.506 -
  10.507 -
  10.508 -#define BLEND_START_TM	node->cur_anim_offset[1]
  10.509 -
  10.510 -static anm_time_t animation_time(struct anm_node *node, anm_time_t tm, int which)
  10.511 -{
  10.512 -	float t;
  10.513 -
  10.514 -	if(node->blend_dur >= 0) {
  10.515 -		/* we're in transition... */
  10.516 -		t = (float)(tm - BLEND_START_TM) / (float)node->blend_dur;
  10.517 -		if(t < 0.0) t = 0.0;
  10.518 -
  10.519 -		node->cur_mix = t;
  10.520 -
  10.521 -		if(t > 1.0) {
  10.522 -			/* switch completely over to the target animation and stop blending */
  10.523 -			anm_use_node_animation(node, node->cur_anim[1]);
  10.524 -			node->cur_anim_offset[0] = node->cur_anim_offset[1];
  10.525 -		}
  10.526 -	}
  10.527 -
  10.528 -	return tm - node->cur_anim_offset[which];
  10.529 -}
  10.530 -
  10.531 -
  10.532 -void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm)
  10.533 -{
  10.534 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.535 -	if(!anim) return;
  10.536 -
  10.537 -	anm_set_value(anim->tracks + ANM_TRACK_POS_X, tm, pos.x);
  10.538 -	anm_set_value(anim->tracks + ANM_TRACK_POS_Y, tm, pos.y);
  10.539 -	anm_set_value(anim->tracks + ANM_TRACK_POS_Z, tm, pos.z);
  10.540 -	invalidate_cache(node);
  10.541 -}
  10.542 -
  10.543 -
  10.544 -vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm)
  10.545 -{
  10.546 -	vec3_t v;
  10.547 -	anm_time_t tm0 = animation_time(node, tm, 0);
  10.548 -	struct anm_animation *anim0 = anm_get_active_animation(node, 0);
  10.549 -	struct anm_animation *anim1 = anm_get_active_animation(node, 1);
  10.550 -
  10.551 -	if(!anim0) {
  10.552 -		return v3_cons(0, 0, 0);
  10.553 -	}
  10.554 -
  10.555 -	v.x = anm_get_value(anim0->tracks + ANM_TRACK_POS_X, tm0);
  10.556 -	v.y = anm_get_value(anim0->tracks + ANM_TRACK_POS_Y, tm0);
  10.557 -	v.z = anm_get_value(anim0->tracks + ANM_TRACK_POS_Z, tm0);
  10.558 -
  10.559 -	if(anim1) {
  10.560 -		vec3_t v1;
  10.561 -		anm_time_t tm1 = animation_time(node, tm, 1);
  10.562 -		v1.x = anm_get_value(anim1->tracks + ANM_TRACK_POS_X, tm1);
  10.563 -		v1.y = anm_get_value(anim1->tracks + ANM_TRACK_POS_Y, tm1);
  10.564 -		v1.z = anm_get_value(anim1->tracks + ANM_TRACK_POS_Z, tm1);
  10.565 -
  10.566 -		v.x = v.x + (v1.x - v.x) * node->cur_mix;
  10.567 -		v.y = v.y + (v1.y - v.y) * node->cur_mix;
  10.568 -		v.z = v.z + (v1.z - v.z) * node->cur_mix;
  10.569 -	}
  10.570 -
  10.571 -	return v;
  10.572 -}
  10.573 -
  10.574 -void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm)
  10.575 -{
  10.576 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.577 -	if(!anim) return;
  10.578 -
  10.579 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_X, tm, rot.x);
  10.580 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_Y, tm, rot.y);
  10.581 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_Z, tm, rot.z);
  10.582 -	anm_set_value(anim->tracks + ANM_TRACK_ROT_W, tm, rot.w);
  10.583 -	invalidate_cache(node);
  10.584 -}
  10.585 -
  10.586 -static quat_t get_node_rotation(struct anm_node *node, anm_time_t tm, struct anm_animation *anim)
  10.587 -{
  10.588 -#ifndef ROT_USE_SLERP
  10.589 -	quat_t q;
  10.590 -	q.x = anm_get_value(anim->tracks + ANM_TRACK_ROT_X, tm);
  10.591 -	q.y = anm_get_value(anim->tracks + ANM_TRACK_ROT_Y, tm);
  10.592 -	q.z = anm_get_value(anim->tracks + ANM_TRACK_ROT_Z, tm);
  10.593 -	q.w = anm_get_value(anim->tracks + ANM_TRACK_ROT_W, tm);
  10.594 -	return q;
  10.595 -#else
  10.596 -	int idx0, idx1, last_idx;
  10.597 -	anm_time_t tstart, tend;
  10.598 -	float t, dt;
  10.599 -	struct anm_track *track_x, *track_y, *track_z, *track_w;
  10.600 -	quat_t q, q1, q2;
  10.601 -
  10.602 -	track_x = anim->tracks + ANM_TRACK_ROT_X;
  10.603 -	track_y = anim->tracks + ANM_TRACK_ROT_Y;
  10.604 -	track_z = anim->tracks + ANM_TRACK_ROT_Z;
  10.605 -	track_w = anim->tracks + ANM_TRACK_ROT_W;
  10.606 -
  10.607 -	if(!track_x->count) {
  10.608 -		q.x = track_x->def_val;
  10.609 -		q.y = track_y->def_val;
  10.610 -		q.z = track_z->def_val;
  10.611 -		q.w = track_w->def_val;
  10.612 -		return q;
  10.613 -	}
  10.614 -
  10.615 -	last_idx = track_x->count - 1;
  10.616 -
  10.617 -	tstart = track_x->keys[0].time;
  10.618 -	tend = track_x->keys[last_idx].time;
  10.619 -
  10.620 -	if(tstart == tend) {
  10.621 -		q.x = track_x->keys[0].val;
  10.622 -		q.y = track_y->keys[0].val;
  10.623 -		q.z = track_z->keys[0].val;
  10.624 -		q.w = track_w->keys[0].val;
  10.625 -		return q;
  10.626 -	}
  10.627 -
  10.628 -	tm = anm_remap_time(track_x, tm, tstart, tend);
  10.629 -
  10.630 -	idx0 = anm_get_key_interval(track_x, tm);
  10.631 -	assert(idx0 >= 0 && idx0 < track_x->count);
  10.632 -	idx1 = idx0 + 1;
  10.633 -
  10.634 -	if(idx0 == last_idx) {
  10.635 -		q.x = track_x->keys[idx0].val;
  10.636 -		q.y = track_y->keys[idx0].val;
  10.637 -		q.z = track_z->keys[idx0].val;
  10.638 -		q.w = track_w->keys[idx0].val;
  10.639 -		return q;
  10.640 -	}
  10.641 -
  10.642 -	dt = (float)(track_x->keys[idx1].time - track_x->keys[idx0].time);
  10.643 -	t = (float)(tm - track_x->keys[idx0].time) / dt;
  10.644 -
  10.645 -	q1.x = track_x->keys[idx0].val;
  10.646 -	q1.y = track_y->keys[idx0].val;
  10.647 -	q1.z = track_z->keys[idx0].val;
  10.648 -	q1.w = track_w->keys[idx0].val;
  10.649 -
  10.650 -	q2.x = track_x->keys[idx1].val;
  10.651 -	q2.y = track_y->keys[idx1].val;
  10.652 -	q2.z = track_z->keys[idx1].val;
  10.653 -	q2.w = track_w->keys[idx1].val;
  10.654 -
  10.655 -	/*q1 = quat_normalize(q1);
  10.656 -	q2 = quat_normalize(q2);*/
  10.657 -
  10.658 -	return quat_slerp(q1, q2, t);
  10.659 -#endif
  10.660 -}
  10.661 -
  10.662 -quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm)
  10.663 -{
  10.664 -	quat_t q;
  10.665 -	anm_time_t tm0 = animation_time(node, tm, 0);
  10.666 -	struct anm_animation *anim0 = anm_get_active_animation(node, 0);
  10.667 -	struct anm_animation *anim1 = anm_get_active_animation(node, 1);
  10.668 -
  10.669 -	if(!anim0) {
  10.670 -		return quat_identity();
  10.671 -	}
  10.672 -
  10.673 -	q = get_node_rotation(node, tm0, anim0);
  10.674 -
  10.675 -	if(anim1) {
  10.676 -		anm_time_t tm1 = animation_time(node, tm, 1);
  10.677 -		quat_t q1 = get_node_rotation(node, tm1, anim1);
  10.678 -
  10.679 -		q = quat_slerp(q, q1, node->cur_mix);
  10.680 -	}
  10.681 -	return q;
  10.682 -}
  10.683 -
  10.684 -void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm)
  10.685 -{
  10.686 -	struct anm_animation *anim = anm_get_active_animation(node, 0);
  10.687 -	if(!anim) return;
  10.688 -
  10.689 -	anm_set_value(anim->tracks + ANM_TRACK_SCL_X, tm, scl.x);
  10.690 -	anm_set_value(anim->tracks + ANM_TRACK_SCL_Y, tm, scl.y);
  10.691 -	anm_set_value(anim->tracks + ANM_TRACK_SCL_Z, tm, scl.z);
  10.692 -	invalidate_cache(node);
  10.693 -}
  10.694 -
  10.695 -vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm)
  10.696 -{
  10.697 -	vec3_t v;
  10.698 -	anm_time_t tm0 = animation_time(node, tm, 0);
  10.699 -	struct anm_animation *anim0 = anm_get_active_animation(node, 0);
  10.700 -	struct anm_animation *anim1 = anm_get_active_animation(node, 1);
  10.701 -
  10.702 -	if(!anim0) {
  10.703 -		return v3_cons(1, 1, 1);
  10.704 -	}
  10.705 -
  10.706 -	v.x = anm_get_value(anim0->tracks + ANM_TRACK_SCL_X, tm0);
  10.707 -	v.y = anm_get_value(anim0->tracks + ANM_TRACK_SCL_Y, tm0);
  10.708 -	v.z = anm_get_value(anim0->tracks + ANM_TRACK_SCL_Z, tm0);
  10.709 -
  10.710 -	if(anim1) {
  10.711 -		vec3_t v1;
  10.712 -		anm_time_t tm1 = animation_time(node, tm, 1);
  10.713 -		v1.x = anm_get_value(anim1->tracks + ANM_TRACK_SCL_X, tm1);
  10.714 -		v1.y = anm_get_value(anim1->tracks + ANM_TRACK_SCL_Y, tm1);
  10.715 -		v1.z = anm_get_value(anim1->tracks + ANM_TRACK_SCL_Z, tm1);
  10.716 -
  10.717 -		v.x = v.x + (v1.x - v.x) * node->cur_mix;
  10.718 -		v.y = v.y + (v1.y - v.y) * node->cur_mix;
  10.719 -		v.z = v.z + (v1.z - v.z) * node->cur_mix;
  10.720 -	}
  10.721 -
  10.722 -	return v;
  10.723 -}
  10.724 -
  10.725 -
  10.726 -vec3_t anm_get_position(struct anm_node *node, anm_time_t tm)
  10.727 -{
  10.728 -	mat4_t xform;
  10.729 -	vec3_t pos = {0.0, 0.0, 0.0};
  10.730 -
  10.731 -	if(!node->parent) {
  10.732 -		return anm_get_node_position(node, tm);
  10.733 -	}
  10.734 -
  10.735 -	anm_get_matrix(node, xform, tm);
  10.736 -	return v3_transform(pos, xform);
  10.737 -}
  10.738 -
  10.739 -quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm)
  10.740 -{
  10.741 -	quat_t rot, prot;
  10.742 -	rot = anm_get_node_rotation(node, tm);
  10.743 -
  10.744 -	if(!node->parent) {
  10.745 -		return rot;
  10.746 -	}
  10.747 -
  10.748 -	prot = anm_get_rotation(node->parent, tm);
  10.749 -	return quat_mul(prot, rot);
  10.750 -}
  10.751 -
  10.752 -vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm)
  10.753 -{
  10.754 -	vec3_t s, ps;
  10.755 -	s = anm_get_node_scaling(node, tm);
  10.756 -
  10.757 -	if(!node->parent) {
  10.758 -		return s;
  10.759 -	}
  10.760 -
  10.761 -	ps = anm_get_scaling(node->parent, tm);
  10.762 -	return v3_mul(s, ps);
  10.763 -}
  10.764 -
  10.765 -void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  10.766 -{
  10.767 -	int i;
  10.768 -	mat4_t rmat;
  10.769 -	vec3_t pos, scale;
  10.770 -	quat_t rot;
  10.771 -
  10.772 -	pos = anm_get_node_position(node, tm);
  10.773 -	rot = anm_get_node_rotation(node, tm);
  10.774 -	scale = anm_get_node_scaling(node, tm);
  10.775 -
  10.776 -	m4_set_translation(mat, node->pivot.x, node->pivot.y, node->pivot.z);
  10.777 -
  10.778 -	quat_to_mat4(rmat, rot);
  10.779 -	for(i=0; i<3; i++) {
  10.780 -		mat[i][0] = rmat[i][0];
  10.781 -		mat[i][1] = rmat[i][1];
  10.782 -		mat[i][2] = rmat[i][2];
  10.783 -	}
  10.784 -	/* this loop is equivalent to: m4_mult(mat, mat, rmat); */
  10.785 -
  10.786 -	mat[0][0] *= scale.x; mat[0][1] *= scale.y; mat[0][2] *= scale.z; mat[0][3] += pos.x;
  10.787 -	mat[1][0] *= scale.x; mat[1][1] *= scale.y; mat[1][2] *= scale.z; mat[1][3] += pos.y;
  10.788 -	mat[2][0] *= scale.x; mat[2][1] *= scale.y; mat[2][2] *= scale.z; mat[2][3] += pos.z;
  10.789 -
  10.790 -	m4_translate(mat, -node->pivot.x, -node->pivot.y, -node->pivot.z);
  10.791 -
  10.792 -	/* that's basically: pivot * rotation * translation * scaling * -pivot */
  10.793 -}
  10.794 -
  10.795 -void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  10.796 -{
  10.797 -	mat4_t tmp;
  10.798 -	anm_get_node_matrix(node, tmp, tm);
  10.799 -	m4_inverse(mat, tmp);
  10.800 -}
  10.801 -
  10.802 -void anm_eval_node(struct anm_node *node, anm_time_t tm)
  10.803 -{
  10.804 -	anm_get_node_matrix(node, node->matrix, tm);
  10.805 -}
  10.806 -
  10.807 -void anm_eval(struct anm_node *node, anm_time_t tm)
  10.808 -{
  10.809 -	struct anm_node *c;
  10.810 -
  10.811 -	anm_eval_node(node, tm);
  10.812 -
  10.813 -	if(node->parent) {
  10.814 -		/* due to post-order traversal, the parent matrix is already evaluated */
  10.815 -		m4_mult(node->matrix, node->parent->matrix, node->matrix);
  10.816 -	}
  10.817 -
  10.818 -	/* recersively evaluate all children */
  10.819 -	c = node->child;
  10.820 -	while(c) {
  10.821 -		anm_eval(c, tm);
  10.822 -		c = c->next;
  10.823 -	}
  10.824 -}
  10.825 -
  10.826 -void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  10.827 -{
  10.828 -	struct mat_cache *cache = pthread_getspecific(node->cache_key);
  10.829 -	if(!cache) {
  10.830 -		cache = malloc(sizeof *cache);
  10.831 -		assert(cache);
  10.832 -
  10.833 -		pthread_mutex_lock(&node->cache_list_lock);
  10.834 -		cache->next = node->cache_list;
  10.835 -		node->cache_list = cache;
  10.836 -		pthread_mutex_unlock(&node->cache_list_lock);
  10.837 -
  10.838 -		cache->time = ANM_TIME_INVAL;
  10.839 -		cache->inv_time = ANM_TIME_INVAL;
  10.840 -		pthread_setspecific(node->cache_key, cache);
  10.841 -	}
  10.842 -
  10.843 -	if(cache->time != tm) {
  10.844 -		anm_get_node_matrix(node, cache->matrix, tm);
  10.845 -
  10.846 -		if(node->parent) {
  10.847 -			mat4_t parent_mat;
  10.848 -
  10.849 -			anm_get_matrix(node->parent, parent_mat, tm);
  10.850 -			m4_mult(cache->matrix, parent_mat, cache->matrix);
  10.851 -		}
  10.852 -		cache->time = tm;
  10.853 -	}
  10.854 -	m4_copy(mat, cache->matrix);
  10.855 -}
  10.856 -
  10.857 -void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm)
  10.858 -{
  10.859 -	struct mat_cache *cache = pthread_getspecific(node->cache_key);
  10.860 -	if(!cache) {
  10.861 -		cache = malloc(sizeof *cache);
  10.862 -		assert(cache);
  10.863 -
  10.864 -		pthread_mutex_lock(&node->cache_list_lock);
  10.865 -		cache->next = node->cache_list;
  10.866 -		node->cache_list = cache;
  10.867 -		pthread_mutex_unlock(&node->cache_list_lock);
  10.868 -
  10.869 -		cache->inv_time = ANM_TIME_INVAL;
  10.870 -		cache->inv_time = ANM_TIME_INVAL;
  10.871 -		pthread_setspecific(node->cache_key, cache);
  10.872 -	}
  10.873 -
  10.874 -	if(cache->inv_time != tm) {
  10.875 -		anm_get_matrix(node, mat, tm);
  10.876 -		m4_inverse(cache->inv_matrix, mat);
  10.877 -		cache->inv_time = tm;
  10.878 -	}
  10.879 -	m4_copy(mat, cache->inv_matrix);
  10.880 -}
  10.881 -
  10.882 -anm_time_t anm_get_start_time(struct anm_node *node)
  10.883 -{
  10.884 -	int i, j;
  10.885 -	struct anm_node *c;
  10.886 -	anm_time_t res = LONG_MAX;
  10.887 -
  10.888 -	for(j=0; j<2; j++) {
  10.889 -		struct anm_animation *anim = anm_get_active_animation(node, j);
  10.890 -		if(!anim) break;
  10.891 -
  10.892 -		for(i=0; i<ANM_NUM_TRACKS; i++) {
  10.893 -			if(anim->tracks[i].count) {
  10.894 -				anm_time_t tm = anim->tracks[i].keys[0].time;
  10.895 -				if(tm < res) {
  10.896 -					res = tm;
  10.897 -				}
  10.898 -			}
  10.899 -		}
  10.900 -	}
  10.901 -
  10.902 -	c = node->child;
  10.903 -	while(c) {
  10.904 -		anm_time_t tm = anm_get_start_time(c);
  10.905 -		if(tm < res) {
  10.906 -			res = tm;
  10.907 -		}
  10.908 -		c = c->next;
  10.909 -	}
  10.910 -	return res;
  10.911 -}
  10.912 -
  10.913 -anm_time_t anm_get_end_time(struct anm_node *node)
  10.914 -{
  10.915 -	int i, j;
  10.916 -	struct anm_node *c;
  10.917 -	anm_time_t res = LONG_MIN;
  10.918 -
  10.919 -	for(j=0; j<2; j++) {
  10.920 -		struct anm_animation *anim = anm_get_active_animation(node, j);
  10.921 -		if(!anim) break;
  10.922 -
  10.923 -		for(i=0; i<ANM_NUM_TRACKS; i++) {
  10.924 -			if(anim->tracks[i].count) {
  10.925 -				anm_time_t tm = anim->tracks[i].keys[anim->tracks[i].count - 1].time;
  10.926 -				if(tm > res) {
  10.927 -					res = tm;
  10.928 -				}
  10.929 -			}
  10.930 -		}
  10.931 -	}
  10.932 -
  10.933 -	c = node->child;
  10.934 -	while(c) {
  10.935 -		anm_time_t tm = anm_get_end_time(c);
  10.936 -		if(tm > res) {
  10.937 -			res = tm;
  10.938 -		}
  10.939 -		c = c->next;
  10.940 -	}
  10.941 -	return res;
  10.942 -}
  10.943 -
  10.944 -static void invalidate_cache(struct anm_node *node)
  10.945 -{
  10.946 -	struct mat_cache *cache = pthread_getspecific(node->cache_key);
  10.947 -	if(cache) {
  10.948 -	   cache->time = cache->inv_time = ANM_TIME_INVAL;
  10.949 -	}
  10.950 -}
    11.1 --- a/libs/anim/anim.h	Thu Jan 23 03:57:15 2014 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,219 +0,0 @@
    11.4 -#ifndef LIBANIM_H_
    11.5 -#define LIBANIM_H_
    11.6 -
    11.7 -#include "config.h"
    11.8 -
    11.9 -#include <pthread.h>
   11.10 -
   11.11 -#include <vmath/vector.h>
   11.12 -#include <vmath/quat.h>
   11.13 -#include <vmath/matrix.h>
   11.14 -#include "track.h"
   11.15 -
   11.16 -enum {
   11.17 -	ANM_TRACK_POS_X,
   11.18 -	ANM_TRACK_POS_Y,
   11.19 -	ANM_TRACK_POS_Z,
   11.20 -
   11.21 -	ANM_TRACK_ROT_X,
   11.22 -	ANM_TRACK_ROT_Y,
   11.23 -	ANM_TRACK_ROT_Z,
   11.24 -	ANM_TRACK_ROT_W,
   11.25 -
   11.26 -	ANM_TRACK_SCL_X,
   11.27 -	ANM_TRACK_SCL_Y,
   11.28 -	ANM_TRACK_SCL_Z,
   11.29 -
   11.30 -	ANM_NUM_TRACKS
   11.31 -};
   11.32 -
   11.33 -struct anm_animation {
   11.34 -	char *name;
   11.35 -	struct anm_track tracks[ANM_NUM_TRACKS];
   11.36 -};
   11.37 -
   11.38 -struct anm_node {
   11.39 -	char *name;
   11.40 -
   11.41 -	int cur_anim[2];
   11.42 -	anm_time_t cur_anim_offset[2];
   11.43 -	float cur_mix;
   11.44 -
   11.45 -	/* high-level animation blending transition duration */
   11.46 -	anm_time_t blend_dur;
   11.47 -
   11.48 -	struct anm_animation *animations;
   11.49 -	vec3_t pivot;
   11.50 -
   11.51 -	/* matrix cache */
   11.52 -	struct mat_cache {
   11.53 -		mat4_t matrix, inv_matrix;
   11.54 -		anm_time_t time, inv_time;
   11.55 -		struct mat_cache *next;
   11.56 -	} *cache_list;
   11.57 -	pthread_key_t cache_key;
   11.58 -	pthread_mutex_t cache_list_lock;
   11.59 -
   11.60 -	/* matrix calculated by anm_eval functions (no locking, meant as a pre-pass) */
   11.61 -	mat4_t matrix;
   11.62 -
   11.63 -	struct anm_node *parent;
   11.64 -	struct anm_node *child;
   11.65 -	struct anm_node *next;
   11.66 -};
   11.67 -
   11.68 -#ifdef __cplusplus
   11.69 -extern "C" {
   11.70 -#endif
   11.71 -
   11.72 -int anm_init_animation(struct anm_animation *anim);
   11.73 -void anm_destroy_animation(struct anm_animation *anim);
   11.74 -
   11.75 -void anm_set_animation_name(struct anm_animation *anim, const char *name);
   11.76 -
   11.77 -
   11.78 -/* ---- node/hierarchy management ---- */
   11.79 -
   11.80 -/* node constructor and destructor */
   11.81 -int anm_init_node(struct anm_node *node);
   11.82 -void anm_destroy_node(struct anm_node *node);
   11.83 -
   11.84 -/* recursively destroy an animation node tree */
   11.85 -void anm_destroy_node_tree(struct anm_node *tree);
   11.86 -
   11.87 -/* helper functions to allocate/construct and destroy/free with
   11.88 - * a single call. They call anm_init_node and anm_destroy_node
   11.89 - * internally.
   11.90 - */
   11.91 -struct anm_node *anm_create_node(void);
   11.92 -void anm_free_node(struct anm_node *node);
   11.93 -
   11.94 -/* recursively destroy and free the nodes of a node tree */
   11.95 -void anm_free_node_tree(struct anm_node *tree);
   11.96 -
   11.97 -int anm_set_node_name(struct anm_node *node, const char *name);
   11.98 -const char *anm_get_node_name(struct anm_node *node);
   11.99 -
  11.100 -/* link and unlink nodes with parent/child relations */
  11.101 -void anm_link_node(struct anm_node *parent, struct anm_node *child);
  11.102 -int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
  11.103 -
  11.104 -void anm_set_pivot(struct anm_node *node, vec3_t pivot);
  11.105 -vec3_t anm_get_pivot(struct anm_node *node);
  11.106 -
  11.107 -/* ---- multiple animations and animation blending ---- */
  11.108 -
  11.109 -/* set active animation(s) */
  11.110 -int anm_use_node_animation(struct anm_node *node, int aidx);
  11.111 -int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t);
  11.112 -/* recursive variants */
  11.113 -int anm_use_animation(struct anm_node *node, int aidx);
  11.114 -int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t);
  11.115 -
  11.116 -/* set/get current animation offset(s) */
  11.117 -void anm_set_node_animation_offset(struct anm_node *node, anm_time_t offs, int which);
  11.118 -anm_time_t anm_get_animation_offset(const struct anm_node *node, int which);
  11.119 -/* recursive variant */
  11.120 -void anm_set_animation_offset(struct anm_node *node, anm_time_t offs, int which);
  11.121 -
  11.122 -/* returns the requested current animation index, which can be 0 or 1 */
  11.123 -int anm_get_active_animation_index(const struct anm_node *node, int which);
  11.124 -/* returns the requested current animation, which can be 0 or 1 */
  11.125 -struct anm_animation *anm_get_active_animation(const struct anm_node *node, int which);
  11.126 -float anm_get_active_animation_mix(const struct anm_node *node);
  11.127 -
  11.128 -int anm_get_animation_count(const struct anm_node *node);
  11.129 -
  11.130 -/* add/remove an animation to the specified node */
  11.131 -int anm_add_node_animation(struct anm_node *node);
  11.132 -int anm_remove_node_animation(struct anm_node *node, int idx);
  11.133 -
  11.134 -/* add/remove an animation to the specified node and all it's descendants */
  11.135 -int anm_add_animation(struct anm_node *node);
  11.136 -int anm_remove_animation(struct anm_node *node, int idx);
  11.137 -
  11.138 -struct anm_animation *anm_get_animation(struct anm_node *node, int idx);
  11.139 -struct anm_animation *anm_get_animation_by_name(struct anm_node *node, const char *name);
  11.140 -
  11.141 -int anm_find_animation(struct anm_node *node, const char *name);
  11.142 -
  11.143 -/* set the interpolator for the (first) currently active animation */
  11.144 -void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
  11.145 -/* set the extrapolator for the (first) currently active animation */
  11.146 -void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
  11.147 -
  11.148 -/* set the name of the currently active animation of this node only */
  11.149 -void anm_set_node_active_animation_name(struct anm_node *node, const char *name);
  11.150 -/* recursively set the name of the currently active animation for this node
  11.151 - * and all it's descendants */
  11.152 -void anm_set_active_animation_name(struct anm_node *node, const char *name);
  11.153 -/* get the name of the currently active animation of this node */
  11.154 -const char *anm_get_active_animation_name(struct anm_node *node);
  11.155 -
  11.156 -
  11.157 -/* ---- high level animation blending interface ---- */
  11.158 -/* XXX this convenience interface assumes monotonically increasing time values
  11.159 - *     in all subsequent calls to anm_get_* and anm_eval_* functions.
  11.160 - *
  11.161 - * anmidx: index of the animation to transition to
  11.162 - * start: when to start the transition
  11.163 - * dur: transition duration
  11.164 - *
  11.165 - * sets up a transition from the current animation (cur_anim[0]) to another animation.
  11.166 - * at time start + dur, the transition will be completed, cur_anim[0] will be the new
  11.167 - * animation and cur_anim_offset[0] will be equal to start.
  11.168 - */
  11.169 -void anm_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur);
  11.170 -/* non-recursive variant, acts on a single node (you probably DON'T want to use this) */
  11.171 -void anm_node_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur);
  11.172 -
  11.173 -
  11.174 -/* ---- keyframes / PRS interpolation ---- */
  11.175 -
  11.176 -void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
  11.177 -vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
  11.178 -
  11.179 -void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
  11.180 -quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
  11.181 -
  11.182 -void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
  11.183 -vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
  11.184 -
  11.185 -/* these three return the full p/r/s taking hierarchy into account */
  11.186 -vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
  11.187 -quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
  11.188 -vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
  11.189 -
  11.190 -/* those return the start and end times of the whole tree */
  11.191 -anm_time_t anm_get_start_time(struct anm_node *node);
  11.192 -anm_time_t anm_get_end_time(struct anm_node *node);
  11.193 -
  11.194 -
  11.195 -/* ---- transformation matrices ---- */
  11.196 -
  11.197 -/* these calculate the matrix and inverse matrix of this node alone */
  11.198 -void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  11.199 -void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  11.200 -
  11.201 -/* ---- top-down matrix calculation interface ---- */
  11.202 -
  11.203 -/* calculate and set the matrix of this node */
  11.204 -void anm_eval_node(struct anm_node *node, anm_time_t tm);
  11.205 -/* calculate and set the matrix of this node and all its children recursively */
  11.206 -void anm_eval(struct anm_node *node, anm_time_t tm);
  11.207 -
  11.208 -
  11.209 -/* ---- bottom-up lazy matrix calculation interface ---- */
  11.210 -
  11.211 -/* These calculate the matrix and inverse matrix of this node taking hierarchy
  11.212 - * into account. The results are cached in thread-specific storage and returned
  11.213 - * if there's no change in time or tracks from the last query...
  11.214 - */
  11.215 -void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  11.216 -void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
  11.217 -
  11.218 -#ifdef __cplusplus
  11.219 -}
  11.220 -#endif
  11.221 -
  11.222 -#endif	/* LIBANIM_H_ */
    12.1 --- a/libs/anim/config.h	Thu Jan 23 03:57:15 2014 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,6 +0,0 @@
    12.4 -#ifndef ANIM_CONFIG_H_
    12.5 -#define ANIM_CONFIG_H_
    12.6 -
    12.7 -#undef ANIM_THREAD_SAFE
    12.8 -
    12.9 -#endif	/* ANIM_CONFIG_H_ */
    13.1 --- a/libs/anim/dynarr.c	Thu Jan 23 03:57:15 2014 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,122 +0,0 @@
    13.4 -#include <stdio.h>
    13.5 -#include <stdlib.h>
    13.6 -#include <string.h>
    13.7 -#include "dynarr.h"
    13.8 -
    13.9 -/* The array descriptor keeps auxilliary information needed to manipulate
   13.10 - * the dynamic array. It's allocated adjacent to the array buffer.
   13.11 - */
   13.12 -struct arrdesc {
   13.13 -	int nelem, szelem;
   13.14 -	int max_elem;
   13.15 -	int bufsz;	/* not including the descriptor */
   13.16 -};
   13.17 -
   13.18 -#define DESC(x)		((struct arrdesc*)((char*)(x) - sizeof(struct arrdesc)))
   13.19 -
   13.20 -void *dynarr_alloc(int elem, int szelem)
   13.21 -{
   13.22 -	struct arrdesc *desc;
   13.23 -
   13.24 -	if(!(desc = malloc(elem * szelem + sizeof *desc))) {
   13.25 -		return 0;
   13.26 -	}
   13.27 -	desc->nelem = desc->max_elem = elem;
   13.28 -	desc->szelem = szelem;
   13.29 -	desc->bufsz = elem * szelem;
   13.30 -	return (char*)desc + sizeof *desc;
   13.31 -}
   13.32 -
   13.33 -void dynarr_free(void *da)
   13.34 -{
   13.35 -	if(da) {
   13.36 -		free(DESC(da));
   13.37 -	}
   13.38 -}
   13.39 -
   13.40 -void *dynarr_resize(void *da, int elem)
   13.41 -{
   13.42 -	int newsz;
   13.43 -	void *tmp;
   13.44 -	struct arrdesc *desc;
   13.45 -
   13.46 -	if(!da) return 0;
   13.47 -	desc = DESC(da);
   13.48 -
   13.49 -	newsz = desc->szelem * elem;
   13.50 -
   13.51 -	if(!(tmp = realloc(desc, newsz + sizeof *desc))) {
   13.52 -		return 0;
   13.53 -	}
   13.54 -	desc = tmp;
   13.55 -
   13.56 -	desc->nelem = desc->max_elem = elem;
   13.57 -	desc->bufsz = newsz;
   13.58 -	return (char*)desc + sizeof *desc;
   13.59 -}
   13.60 -
   13.61 -int dynarr_empty(void *da)
   13.62 -{
   13.63 -	return DESC(da)->nelem ? 0 : 1;
   13.64 -}
   13.65 -
   13.66 -int dynarr_size(void *da)
   13.67 -{
   13.68 -	return DESC(da)->nelem;
   13.69 -}
   13.70 -
   13.71 -
   13.72 -/* stack semantics */
   13.73 -void *dynarr_push(void *da, void *item)
   13.74 -{
   13.75 -	struct arrdesc *desc;
   13.76 -	int nelem;
   13.77 -
   13.78 -	desc = DESC(da);
   13.79 -	nelem = desc->nelem;
   13.80 -
   13.81 -	if(nelem >= desc->max_elem) {
   13.82 -		/* need to resize */
   13.83 -		struct arrdesc *tmp;
   13.84 -		int newsz = desc->max_elem ? desc->max_elem * 2 : 1;
   13.85 -
   13.86 -		if(!(tmp = dynarr_resize(da, newsz))) {
   13.87 -			fprintf(stderr, "failed to resize\n");
   13.88 -			return da;
   13.89 -		}
   13.90 -		da = tmp;
   13.91 -		desc = DESC(da);
   13.92 -		desc->nelem = nelem;
   13.93 -	}
   13.94 -
   13.95 -	memcpy((char*)da + desc->nelem++ * desc->szelem, item, desc->szelem);
   13.96 -	return da;
   13.97 -}
   13.98 -
   13.99 -void *dynarr_pop(void *da)
  13.100 -{
  13.101 -	struct arrdesc *desc;
  13.102 -	int nelem;
  13.103 -
  13.104 -	desc = DESC(da);
  13.105 -	nelem = desc->nelem;
  13.106 -
  13.107 -	if(!nelem) return da;
  13.108 -
  13.109 -	if(nelem <= desc->max_elem / 3) {
  13.110 -		/* reclaim space */
  13.111 -		struct arrdesc *tmp;
  13.112 -		int newsz = desc->max_elem / 2;
  13.113 -
  13.114 -		if(!(tmp = dynarr_resize(da, newsz))) {
  13.115 -			fprintf(stderr, "failed to resize\n");
  13.116 -			return da;
  13.117 -		}
  13.118 -		da = tmp;
  13.119 -		desc = DESC(da);
  13.120 -		desc->nelem = nelem;
  13.121 -	}
  13.122 -	desc->nelem--;
  13.123 -
  13.124 -	return da;
  13.125 -}
    14.1 --- a/libs/anim/dynarr.h	Thu Jan 23 03:57:15 2014 +0200
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,16 +0,0 @@
    14.4 -#ifndef DYNARR_H_
    14.5 -#define DYNARR_H_
    14.6 -
    14.7 -void *dynarr_alloc(int elem, int szelem);
    14.8 -void dynarr_free(void *da);
    14.9 -void *dynarr_resize(void *da, int elem);
   14.10 -
   14.11 -int dynarr_empty(void *da);
   14.12 -int dynarr_size(void *da);
   14.13 -
   14.14 -/* stack semantics */
   14.15 -void *dynarr_push(void *da, void *item);
   14.16 -void *dynarr_pop(void *da);
   14.17 -
   14.18 -
   14.19 -#endif	/* DYNARR_H_ */
    15.1 --- a/libs/anim/track.c	Thu Jan 23 03:57:15 2014 +0200
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,316 +0,0 @@
    15.4 -#include <stdlib.h>
    15.5 -#include <string.h>
    15.6 -#include <assert.h>
    15.7 -#include "track.h"
    15.8 -#include "dynarr.h"
    15.9 -
   15.10 -static int keycmp(const void *a, const void *b);
   15.11 -static int find_prev_key(struct anm_keyframe *arr, int start, int end, anm_time_t tm);
   15.12 -
   15.13 -static float interp_step(float v0, float v1, float v2, float v3, float t);
   15.14 -static float interp_linear(float v0, float v1, float v2, float v3, float t);
   15.15 -static float interp_cubic(float v0, float v1, float v2, float v3, float t);
   15.16 -
   15.17 -static anm_time_t remap_extend(anm_time_t tm, anm_time_t start, anm_time_t end);
   15.18 -static anm_time_t remap_clamp(anm_time_t tm, anm_time_t start, anm_time_t end);
   15.19 -static anm_time_t remap_repeat(anm_time_t tm, anm_time_t start, anm_time_t end);
   15.20 -static anm_time_t remap_pingpong(anm_time_t tm, anm_time_t start, anm_time_t end);
   15.21 -
   15.22 -/* XXX keep this in sync with enum anm_interpolator at track.h */
   15.23 -static float (*interp[])(float, float, float, float, float) = {
   15.24 -	interp_step,
   15.25 -	interp_linear,
   15.26 -	interp_cubic,
   15.27 -	0
   15.28 -};
   15.29 -
   15.30 -/* XXX keep this in sync with enum anm_extrapolator at track.h */
   15.31 -static anm_time_t (*remap_time[])(anm_time_t, anm_time_t, anm_time_t) = {
   15.32 -	remap_extend,
   15.33 -	remap_clamp,
   15.34 -	remap_repeat,
   15.35 -	remap_pingpong,
   15.36 -	0
   15.37 -};
   15.38 -
   15.39 -int anm_init_track(struct anm_track *track)
   15.40 -{
   15.41 -	memset(track, 0, sizeof *track);
   15.42 -
   15.43 -	if(!(track->keys = dynarr_alloc(0, sizeof *track->keys))) {
   15.44 -		return -1;
   15.45 -	}
   15.46 -	track->interp = ANM_INTERP_LINEAR;
   15.47 -	track->extrap = ANM_EXTRAP_CLAMP;
   15.48 -	return 0;
   15.49 -}
   15.50 -
   15.51 -void anm_destroy_track(struct anm_track *track)
   15.52 -{
   15.53 -	dynarr_free(track->keys);
   15.54 -}
   15.55 -
   15.56 -struct anm_track *anm_create_track(void)
   15.57 -{
   15.58 -	struct anm_track *track;
   15.59 -
   15.60 -	if((track = malloc(sizeof *track))) {
   15.61 -		if(anm_init_track(track) == -1) {
   15.62 -			free(track);
   15.63 -			return 0;
   15.64 -		}
   15.65 -	}
   15.66 -	return track;
   15.67 -}
   15.68 -
   15.69 -void anm_free_track(struct anm_track *track)
   15.70 -{
   15.71 -	anm_destroy_track(track);
   15.72 -	free(track);
   15.73 -}
   15.74 -
   15.75 -void anm_copy_track(struct anm_track *dest, const struct anm_track *src)
   15.76 -{
   15.77 -	free(dest->name);
   15.78 -	if(dest->keys) {
   15.79 -		dynarr_free(dest->keys);
   15.80 -	}
   15.81 -
   15.82 -	if(src->name) {
   15.83 -		dest->name = malloc(strlen(src->name) + 1);
   15.84 -		strcpy(dest->name, src->name);
   15.85 -	}
   15.86 -
   15.87 -	dest->count = src->count;
   15.88 -	dest->keys = dynarr_alloc(src->count, sizeof *dest->keys);
   15.89 -	memcpy(dest->keys, src->keys, src->count * sizeof *dest->keys);
   15.90 -
   15.91 -	dest->def_val = src->def_val;
   15.92 -	dest->interp = src->interp;
   15.93 -	dest->extrap = src->extrap;
   15.94 -}
   15.95 -
   15.96 -int anm_set_track_name(struct anm_track *track, const char *name)
   15.97 -{
   15.98 -	char *tmp;
   15.99 -
  15.100 -	if(!(tmp = malloc(strlen(name) + 1))) {
  15.101 -		return -1;
  15.102 -	}
  15.103 -	free(track->name);
  15.104 -	track->name = tmp;
  15.105 -	return 0;
  15.106 -}
  15.107 -
  15.108 -const char *anm_get_track_name(struct anm_track *track)
  15.109 -{
  15.110 -	return track->name;
  15.111 -}
  15.112 -
  15.113 -void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in)
  15.114 -{
  15.115 -	track->interp = in;
  15.116 -}
  15.117 -
  15.118 -void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex)
  15.119 -{
  15.120 -	track->extrap = ex;
  15.121 -}
  15.122 -
  15.123 -anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end)
  15.124 -{
  15.125 -	return remap_time[track->extrap](tm, start, end);
  15.126 -}
  15.127 -
  15.128 -void anm_set_track_default(struct anm_track *track, float def)
  15.129 -{
  15.130 -	track->def_val = def;
  15.131 -}
  15.132 -
  15.133 -int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key)
  15.134 -{
  15.135 -	int idx = anm_get_key_interval(track, key->time);
  15.136 -
  15.137 -	/* if we got a valid keyframe index, compare them... */
  15.138 -	if(idx >= 0 && idx < track->count && keycmp(key, track->keys + idx) == 0) {
  15.139 -		/* ... it's the same key, just update the value */
  15.140 -		track->keys[idx].val = key->val;
  15.141 -	} else {
  15.142 -		/* ... it's a new key, add it and re-sort them */
  15.143 -		void *tmp;
  15.144 -		if(!(tmp = dynarr_push(track->keys, key))) {
  15.145 -			return -1;
  15.146 -		}
  15.147 -		track->keys = tmp;
  15.148 -		/* TODO lazy qsort */
  15.149 -		qsort(track->keys, ++track->count, sizeof *track->keys, keycmp);
  15.150 -	}
  15.151 -	return 0;
  15.152 -}
  15.153 -
  15.154 -static int keycmp(const void *a, const void *b)
  15.155 -{
  15.156 -	return ((struct anm_keyframe*)a)->time - ((struct anm_keyframe*)b)->time;
  15.157 -}
  15.158 -
  15.159 -struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx)
  15.160 -{
  15.161 -	if(idx < 0 || idx >= track->count) {
  15.162 -		return 0;
  15.163 -	}
  15.164 -	return track->keys + idx;
  15.165 -}
  15.166 -
  15.167 -int anm_get_key_interval(struct anm_track *track, anm_time_t tm)
  15.168 -{
  15.169 -	int last;
  15.170 -
  15.171 -	if(!track->count || tm < track->keys[0].time) {
  15.172 -		return -1;
  15.173 -	}
  15.174 -
  15.175 -	last = track->count - 1;
  15.176 -	if(tm > track->keys[last].time) {
  15.177 -		return last;
  15.178 -	}
  15.179 -
  15.180 -	return find_prev_key(track->keys, 0, last, tm);
  15.181 -}
  15.182 -
  15.183 -static int find_prev_key(struct anm_keyframe *arr, int start, int end, anm_time_t tm)
  15.184 -{
  15.185 -	int mid;
  15.186 -
  15.187 -	if(end - start <= 1) {
  15.188 -		return start;
  15.189 -	}
  15.190 -
  15.191 -	mid = (start + end) / 2;
  15.192 -	if(tm < arr[mid].time) {
  15.193 -		return find_prev_key(arr, start, mid, tm);
  15.194 -	}
  15.195 -	if(tm > arr[mid].time) {
  15.196 -		return find_prev_key(arr, mid, end, tm);
  15.197 -	}
  15.198 -	return mid;
  15.199 -}
  15.200 -
  15.201 -int anm_set_value(struct anm_track *track, anm_time_t tm, float val)
  15.202 -{
  15.203 -	struct anm_keyframe key;
  15.204 -	key.time = tm;
  15.205 -	key.val = val;
  15.206 -
  15.207 -	return anm_set_keyframe(track, &key);
  15.208 -}
  15.209 -
  15.210 -float anm_get_value(struct anm_track *track, anm_time_t tm)
  15.211 -{
  15.212 -	int idx0, idx1, last_idx;
  15.213 -	anm_time_t tstart, tend;
  15.214 -	float t, dt;
  15.215 -	float v0, v1, v2, v3;
  15.216 -
  15.217 -	if(!track->count) {
  15.218 -		return track->def_val;
  15.219 -	}
  15.220 -
  15.221 -	last_idx = track->count - 1;
  15.222 -
  15.223 -	tstart = track->keys[0].time;
  15.224 -	tend = track->keys[last_idx].time;
  15.225 -
  15.226 -	if(tstart == tend) {
  15.227 -		return track->keys[0].val;
  15.228 -	}
  15.229 -
  15.230 -	tm = remap_time[track->extrap](tm, tstart, tend);
  15.231 -
  15.232 -	idx0 = anm_get_key_interval(track, tm);
  15.233 -	assert(idx0 >= 0 && idx0 < track->count);
  15.234 -	idx1 = idx0 + 1;
  15.235 -
  15.236 -	if(idx0 == last_idx) {
  15.237 -		return track->keys[idx0].val;
  15.238 -	}
  15.239 -
  15.240 -	dt = (float)(track->keys[idx1].time - track->keys[idx0].time);
  15.241 -	t = (float)(tm - track->keys[idx0].time) / dt;
  15.242 -
  15.243 -	v1 = track->keys[idx0].val;
  15.244 -	v2 = track->keys[idx1].val;
  15.245 -
  15.246 -	/* get the neigboring values to allow for cubic interpolation */
  15.247 -	v0 = idx0 > 0 ? track->keys[idx0 - 1].val : v1;
  15.248 -	v3 = idx1 < last_idx ? track->keys[idx1 + 1].val : v2;
  15.249 -
  15.250 -	return interp[track->interp](v0, v1, v2, v3, t);
  15.251 -}
  15.252 -
  15.253 -
  15.254 -static float interp_step(float v0, float v1, float v2, float v3, float t)
  15.255 -{
  15.256 -	return v1;
  15.257 -}
  15.258 -
  15.259 -static float interp_linear(float v0, float v1, float v2, float v3, float t)
  15.260 -{
  15.261 -	return v1 + (v2 - v1) * t;
  15.262 -}
  15.263 -
  15.264 -static float interp_cubic(float a, float b, float c, float d, float t)
  15.265 -{
  15.266 -	float x, y, z, w;
  15.267 -	float tsq = t * t;
  15.268 -
  15.269 -	x = -a + 3.0 * b - 3.0 * c + d;
  15.270 -	y = 2.0 * a - 5.0 * b + 4.0 * c - d;
  15.271 -	z = c - a;
  15.272 -	w = 2.0 * b;
  15.273 -
  15.274 -	return 0.5 * (x * tsq * t + y * tsq + z * t + w);
  15.275 -}
  15.276 -
  15.277 -static anm_time_t remap_extend(anm_time_t tm, anm_time_t start, anm_time_t end)
  15.278 -{
  15.279 -	return remap_repeat(tm, start, end);
  15.280 -}
  15.281 -
  15.282 -static anm_time_t remap_clamp(anm_time_t tm, anm_time_t start, anm_time_t end)
  15.283 -{
  15.284 -	if(start == end) {
  15.285 -		return start;
  15.286 -	}
  15.287 -	return tm < start ? start : (tm >= end ? end - 1 : tm);
  15.288 -}
  15.289 -
  15.290 -static anm_time_t remap_repeat(anm_time_t tm, anm_time_t start, anm_time_t end)
  15.291 -{
  15.292 -	anm_time_t x, interv = end - start;
  15.293 -
  15.294 -	if(interv == 0) {
  15.295 -		return start;
  15.296 -	}
  15.297 -
  15.298 -	x = (tm - start) % interv;
  15.299 -	if(x < 0) {
  15.300 -		x += interv;
  15.301 -	}
  15.302 -	return x + start;
  15.303 -
  15.304 -	/*if(tm < start) {
  15.305 -		while(tm < start) {
  15.306 -			tm += interv;
  15.307 -		}
  15.308 -		return tm;
  15.309 -	}
  15.310 -	return (tm - start) % interv + start;*/
  15.311 -}
  15.312 -
  15.313 -static anm_time_t remap_pingpong(anm_time_t tm, anm_time_t start, anm_time_t end)
  15.314 -{
  15.315 -	anm_time_t interv = end - start;
  15.316 -	anm_time_t x = remap_repeat(tm, start, end + interv);
  15.317 -
  15.318 -	return x > end ? end + interv - x : x;
  15.319 -}
    16.1 --- a/libs/anim/track.h	Thu Jan 23 03:57:15 2014 +0200
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,101 +0,0 @@
    16.4 -/* An animation track defines the values of a single scalar over time
    16.5 - * and supports various interpolation and extrapolation modes.
    16.6 - */
    16.7 -#ifndef LIBANIM_TRACK_H_
    16.8 -#define LIBANIM_TRACK_H_
    16.9 -
   16.10 -#include <limits.h>
   16.11 -#include "config.h"
   16.12 -
   16.13 -enum anm_interpolator {
   16.14 -	ANM_INTERP_STEP,
   16.15 -	ANM_INTERP_LINEAR,
   16.16 -	ANM_INTERP_CUBIC
   16.17 -};
   16.18 -
   16.19 -enum anm_extrapolator {
   16.20 -	ANM_EXTRAP_EXTEND,	/* extend to infinity */
   16.21 -	ANM_EXTRAP_CLAMP,	/* clamp to last value */
   16.22 -	ANM_EXTRAP_REPEAT,	/* repeat motion */
   16.23 -	ANM_EXTRAP_PINGPONG	/* repeat with mirroring */
   16.24 -};
   16.25 -
   16.26 -typedef long anm_time_t;
   16.27 -#define ANM_TIME_INVAL	LONG_MIN
   16.28 -
   16.29 -#define ANM_SEC2TM(x)	((anm_time_t)((x) * 1000))
   16.30 -#define ANM_MSEC2TM(x)	((anm_time_t)(x))
   16.31 -#define ANM_TM2SEC(x)	((x) / 1000.0)
   16.32 -#define ANM_TM2MSEC(x)	(x)
   16.33 -
   16.34 -struct anm_keyframe {
   16.35 -	anm_time_t time;
   16.36 -	float val;
   16.37 -};
   16.38 -
   16.39 -struct anm_track {
   16.40 -	char *name;
   16.41 -	int count;
   16.42 -	struct anm_keyframe *keys;
   16.43 -
   16.44 -	float def_val;
   16.45 -
   16.46 -	enum anm_interpolator interp;
   16.47 -	enum anm_extrapolator extrap;
   16.48 -};
   16.49 -
   16.50 -#ifdef __cplusplus
   16.51 -extern "C" {
   16.52 -#endif
   16.53 -
   16.54 -/* track constructor and destructor */
   16.55 -int anm_init_track(struct anm_track *track);
   16.56 -void anm_destroy_track(struct anm_track *track);
   16.57 -
   16.58 -/* helper functions that use anm_init_track and anm_destroy_track internally */
   16.59 -struct anm_track *anm_create_track(void);
   16.60 -void anm_free_track(struct anm_track *track);
   16.61 -
   16.62 -/* copies track src to dest
   16.63 - * XXX: dest must have been initialized first
   16.64 - */
   16.65 -void anm_copy_track(struct anm_track *dest, const struct anm_track *src);
   16.66 -
   16.67 -int anm_set_track_name(struct anm_track *track, const char *name);
   16.68 -const char *anm_get_track_name(struct anm_track *track);
   16.69 -
   16.70 -void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
   16.71 -void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
   16.72 -
   16.73 -anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
   16.74 -
   16.75 -void anm_set_track_default(struct anm_track *track, float def);
   16.76 -
   16.77 -/* set or update a keyframe */
   16.78 -int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
   16.79 -
   16.80 -/* get the idx-th keyframe, returns null if it doesn't exist */
   16.81 -struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
   16.82 -
   16.83 -/* Finds the 0-based index of the intra-keyframe interval which corresponds
   16.84 - * to the specified time. If the time falls exactly onto the N-th keyframe
   16.85 - * the function returns N.
   16.86 - *
   16.87 - * Special cases:
   16.88 - * - if the time is before the first keyframe -1 is returned.
   16.89 - * - if the time is after the last keyframe, the index of the last keyframe
   16.90 - *   is returned.
   16.91 - */
   16.92 -int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
   16.93 -
   16.94 -int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
   16.95 -
   16.96 -/* evaluates and returns the value of the track for a particular time */
   16.97 -float anm_get_value(struct anm_track *track, anm_time_t tm);
   16.98 -
   16.99 -#ifdef __cplusplus
  16.100 -}
  16.101 -#endif
  16.102 -
  16.103 -
  16.104 -#endif	/* LIBANIM_TRACK_H_ */
    17.1 --- a/libs/vmath/Makefile	Thu Jan 23 03:57:15 2014 +0200
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,18 +0,0 @@
    17.4 -csrc = $(wildcard *.c)
    17.5 -ccsrc = $(wildcard *.cc)
    17.6 -obj = $(csrc:.c=.o) $(ccsrc:.cc=.o)
    17.7 -lib = libvmath.a
    17.8 -
    17.9 -ifneq ($(shell uname -s), Darwin)
   17.10 -	pic = -fPIC
   17.11 -endif
   17.12 -
   17.13 -CFLAGS = -pedantic -Wall -g $(pic)
   17.14 -CXXFLAGS = -pedantic -Wall -g $(pic)
   17.15 -
   17.16 -$(lib): $(obj)
   17.17 -	$(AR) rcs $@ $(obj)
   17.18 -
   17.19 -.PHONY: clean
   17.20 -clean:
   17.21 -	rm -f $(obj) $(lib)
    18.1 --- a/libs/vmath/basis.cc	Thu Jan 23 03:57:15 2014 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,63 +0,0 @@
    18.4 -#include "basis.h"
    18.5 -#include "vmath.h"
    18.6 -
    18.7 -Basis::Basis()
    18.8 -{
    18.9 -	i = Vector3(1, 0, 0);
   18.10 -	j = Vector3(0, 1, 0);
   18.11 -	k = Vector3(0, 0, 1);
   18.12 -}
   18.13 -
   18.14 -Basis::Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k)
   18.15 -{
   18.16 -	this->i = i;
   18.17 -	this->j = j;
   18.18 -	this->k = k;
   18.19 -}
   18.20 -
   18.21 -Basis::Basis(const Vector3 &dir, bool left_handed)
   18.22 -{
   18.23 -	k = dir;
   18.24 -	j = Vector3(0, 1, 0);
   18.25 -	i = cross_product(j, k);
   18.26 -	j = cross_product(k, i);
   18.27 -}
   18.28 -
   18.29 -/** Rotate with euler angles */
   18.30 -void Basis::rotate(scalar_t x, scalar_t y, scalar_t z) {
   18.31 -	Matrix4x4 RotMat;
   18.32 -	RotMat.set_rotation(Vector3(x, y, z));
   18.33 -	i.transform(RotMat);
   18.34 -	j.transform(RotMat);
   18.35 -	k.transform(RotMat);
   18.36 -}
   18.37 -
   18.38 -/** Rotate by axis-angle specification */
   18.39 -void Basis::rotate(const Vector3 &axis, scalar_t angle) {
   18.40 -	Quaternion q;
   18.41 -	q.set_rotation(axis, angle);
   18.42 -	i.transform(q);
   18.43 -	j.transform(q);
   18.44 -	k.transform(q);
   18.45 -}
   18.46 -
   18.47 -/** Rotate with a 4x4 matrix */
   18.48 -void Basis::rotate(const Matrix4x4 &mat) {
   18.49 -	i.transform(mat);
   18.50 -	j.transform(mat);
   18.51 -	k.transform(mat);
   18.52 -}
   18.53 -
   18.54 -/** Rotate with a quaternion */
   18.55 -void Basis::rotate(const Quaternion &quat) {
   18.56 -	i.transform(quat);
   18.57 -	j.transform(quat);
   18.58 -	k.transform(quat);
   18.59 -}
   18.60 -
   18.61 -/** Extract a rotation matrix from the orthogonal basis */
   18.62 -Matrix3x3 Basis::create_rotation_matrix() const {
   18.63 -	return Matrix3x3(	i.x, j.x, k.x,
   18.64 -						i.y, j.y, k.y,
   18.65 -						i.z, j.z, k.z);
   18.66 -}
    19.1 --- a/libs/vmath/basis.h	Thu Jan 23 03:57:15 2014 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,57 +0,0 @@
    19.4 -/*
    19.5 -libvmath - a vector math library
    19.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    19.7 -
    19.8 -This program is free software: you can redistribute it and/or modify
    19.9 -it under the terms of the GNU Lesser General Public License as published
   19.10 -by the Free Software Foundation, either version 3 of the License, or
   19.11 -(at your option) any later version.
   19.12 -
   19.13 -This program is distributed in the hope that it will be useful,
   19.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.16 -GNU Lesser General Public License for more details.
   19.17 -
   19.18 -You should have received a copy of the GNU Lesser General Public License
   19.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   19.20 -*/
   19.21 -
   19.22 -#ifndef VMATH_BASIS_H_
   19.23 -#define VMATH_BASIS_H_
   19.24 -
   19.25 -#include "vector.h"
   19.26 -#include "matrix.h"
   19.27 -
   19.28 -enum {
   19.29 -	LEFT_HANDED,
   19.30 -	RIGHT_HANDED
   19.31 -};
   19.32 -
   19.33 -#ifdef __cplusplus
   19.34 -extern "C" {
   19.35 -#endif	/* __cplusplus */
   19.36 -
   19.37 -void basis_matrix(mat4_t res, vec3_t i, vec3_t j, vec3_t k);
   19.38 -void basis_matrix_dir(mat4_t res, vec3_t dir);
   19.39 -
   19.40 -#ifdef __cplusplus
   19.41 -}	/* extern "C" */
   19.42 -
   19.43 -class Basis {
   19.44 -public:
   19.45 -	Vector3 i, j, k;
   19.46 -
   19.47 -	Basis();
   19.48 -	Basis(const Vector3 &i, const Vector3 &j, const Vector3 &k);
   19.49 -	Basis(const Vector3 &dir, bool left_handed = true);
   19.50 -
   19.51 -	void rotate(scalar_t x, scalar_t y, scalar_t z);
   19.52 -	void rotate(const Vector3 &axis, scalar_t angle);
   19.53 -	void rotate(const Matrix4x4 &mat);
   19.54 -	void rotate(const Quaternion &quat);
   19.55 -
   19.56 -	Matrix3x3 create_rotation_matrix() const;
   19.57 -};
   19.58 -#endif	/* __cplusplus */
   19.59 -
   19.60 -#endif	/* VMATH_BASIS_H_ */
    20.1 --- a/libs/vmath/basis_c.c	Thu Jan 23 03:57:15 2014 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,37 +0,0 @@
    20.4 -/*
    20.5 -libvmath - a vector math library
    20.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    20.7 -
    20.8 -This program is free software: you can redistribute it and/or modify
    20.9 -it under the terms of the GNU Lesser General Public License as published
   20.10 -by the Free Software Foundation, either version 3 of the License, or
   20.11 -(at your option) any later version.
   20.12 -
   20.13 -This program is distributed in the hope that it will be useful,
   20.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20.16 -GNU Lesser General Public License for more details.
   20.17 -
   20.18 -You should have received a copy of the GNU Lesser General Public License
   20.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   20.20 -*/
   20.21 -
   20.22 -#include "basis.h"
   20.23 -#include "matrix.h"
   20.24 -
   20.25 -void basis_matrix(mat4_t res, vec3_t i, vec3_t j, vec3_t k)
   20.26 -{
   20.27 -	m4_identity(res);
   20.28 -	m4_set_column(res, v4_cons(i.x, i.y, i.z, 1.0), 0);
   20.29 -	m4_set_column(res, v4_cons(j.x, j.y, j.z, 1.0), 1);
   20.30 -	m4_set_column(res, v4_cons(k.x, k.y, k.z, 1.0), 2);
   20.31 -}
   20.32 -
   20.33 -void basis_matrix_dir(mat4_t res, vec3_t dir)
   20.34 -{
   20.35 -	vec3_t k = v3_normalize(dir);
   20.36 -	vec3_t j = {0, 1, 0};
   20.37 -	vec3_t i = v3_cross(j, k);
   20.38 -	j = v3_cross(k, i);
   20.39 -	basis_matrix(res, i, j, k);
   20.40 -}
    21.1 --- a/libs/vmath/geom.c	Thu Jan 23 03:57:15 2014 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,150 +0,0 @@
    21.4 -/*
    21.5 -libvmath - a vector math library
    21.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    21.7 -
    21.8 -This program is free software: you can redistribute it and/or modify
    21.9 -it under the terms of the GNU Lesser General Public License as published
   21.10 -by the Free Software Foundation, either version 3 of the License, or
   21.11 -(at your option) any later version.
   21.12 -
   21.13 -This program is distributed in the hope that it will be useful,
   21.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21.16 -GNU Lesser General Public License for more details.
   21.17 -
   21.18 -You should have received a copy of the GNU Lesser General Public License
   21.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   21.20 -*/
   21.21 -
   21.22 -
   21.23 -#include <math.h>
   21.24 -#include "geom.h"
   21.25 -#include "vector.h"
   21.26 -
   21.27 -plane_t plane_cons(scalar_t nx, scalar_t ny, scalar_t nz, scalar_t d)
   21.28 -{
   21.29 -	plane_t p;
   21.30 -	p.norm.x = nx;
   21.31 -	p.norm.y = ny;
   21.32 -	p.norm.z = nz;
   21.33 -	p.d = d;
   21.34 -	return p;
   21.35 -}
   21.36 -
   21.37 -plane_t plane_poly(vec3_t v0, vec3_t v1, vec3_t v2)
   21.38 -{
   21.39 -	vec3_t a, b, norm;
   21.40 -
   21.41 -	a = v3_sub(v1, v0);
   21.42 -	b = v3_sub(v2, v0);
   21.43 -	norm = v3_cross(a, b);
   21.44 -	norm = v3_normalize(norm);
   21.45 -
   21.46 -	return plane_ptnorm(v0, norm);
   21.47 -}
   21.48 -
   21.49 -plane_t plane_ptnorm(vec3_t pt, vec3_t normal)
   21.50 -{
   21.51 -	plane_t plane;
   21.52 -
   21.53 -	plane.norm = normal;
   21.54 -	plane.d = v3_dot(pt, normal);
   21.55 -
   21.56 -	return plane;
   21.57 -}
   21.58 -
   21.59 -plane_t plane_invert(plane_t p)
   21.60 -{
   21.61 -	p.norm = v3_neg(p.norm);
   21.62 -	p.d = -p.d;
   21.63 -	return p;
   21.64 -}
   21.65 -
   21.66 -scalar_t plane_signed_dist(plane_t plane, vec3_t pt)
   21.67 -{
   21.68 -	vec3_t pp = plane_point(plane);
   21.69 -	vec3_t pptopt = v3_sub(pt, pp);
   21.70 -	return v3_dot(pptopt, plane.norm);
   21.71 -}
   21.72 -
   21.73 -scalar_t plane_dist(plane_t plane, vec3_t pt)
   21.74 -{
   21.75 -	return fabs(plane_signed_dist(plane, pt));
   21.76 -}
   21.77 -
   21.78 -vec3_t plane_point(plane_t plane)
   21.79 -{
   21.80 -	return v3_scale(plane.norm, plane.d);
   21.81 -}
   21.82 -
   21.83 -int plane_ray_intersect(ray_t ray, plane_t plane, scalar_t *pos)
   21.84 -{
   21.85 -	vec3_t pt, orig_to_pt;
   21.86 -	scalar_t ndotdir;
   21.87 -
   21.88 -	pt = plane_point(plane);
   21.89 -	ndotdir = v3_dot(plane.norm, ray.dir);
   21.90 -
   21.91 -	if(fabs(ndotdir) < 1e-7) {
   21.92 -		return 0;
   21.93 -	}
   21.94 -
   21.95 -	if(pos) {
   21.96 -		orig_to_pt = v3_sub(pt, ray.origin);
   21.97 -		*pos = v3_dot(plane.norm, orig_to_pt) / ndotdir;
   21.98 -	}
   21.99 -	return 1;
  21.100 -}
  21.101 -
  21.102 -sphere_t sphere_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t rad)
  21.103 -{
  21.104 -	sphere_t sph;
  21.105 -	sph.pos.x = x;
  21.106 -	sph.pos.y = y;
  21.107 -	sph.pos.z = z;
  21.108 -	sph.rad = rad;
  21.109 -	return sph;
  21.110 -}
  21.111 -
  21.112 -int sphere_ray_intersect(ray_t ray, sphere_t sph, scalar_t *pos)
  21.113 -{
  21.114 -	scalar_t a, b, c, d, sqrt_d, t1, t2, t;
  21.115 -
  21.116 -	a = v3_dot(ray.dir, ray.dir);
  21.117 -	b = 2.0 * ray.dir.x * (ray.origin.x - sph.pos.x) +
  21.118 -		2.0 * ray.dir.y * (ray.origin.y - sph.pos.y) +
  21.119 -		2.0 * ray.dir.z * (ray.origin.z - sph.pos.z);
  21.120 -	c = v3_dot(sph.pos, sph.pos) + v3_dot(ray.origin, ray.origin) +
  21.121 -		2.0 * v3_dot(v3_neg(sph.pos), ray.origin) - sph.rad * sph.rad;
  21.122 -
  21.123 -	d = b * b - 4.0 * a * c;
  21.124 -	if(d < 0.0) {
  21.125 -		return 0;
  21.126 -	}
  21.127 -
  21.128 -	sqrt_d = sqrt(d);
  21.129 -	t1 = (-b + sqrt_d) / (2.0 * a);
  21.130 -	t2 = (-b - sqrt_d) / (2.0 * a);
  21.131 -
  21.132 -	if(t1 < 1e-7 || t1 > 1.0) {
  21.133 -		t1 = t2;
  21.134 -	}
  21.135 -	if(t2 < 1e-7 || t2 > 1.0) {
  21.136 -		t2 = t1;
  21.137 -	}
  21.138 -	t = t1 < t2 ? t1 : t2;
  21.139 -
  21.140 -	if(t < 1e-7 || t > 1.0) {
  21.141 -		return 0;
  21.142 -	}
  21.143 -
  21.144 -	if(pos) {
  21.145 -		*pos = t;
  21.146 -	}
  21.147 -	return 1;
  21.148 -}
  21.149 -
  21.150 -int sphere_sphere_intersect(sphere_t sph1, sphere_t sph2, scalar_t *pos, scalar_t *rad)
  21.151 -{
  21.152 -	return -1;
  21.153 -}
    22.1 --- a/libs/vmath/geom.h	Thu Jan 23 03:57:15 2014 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,72 +0,0 @@
    22.4 -/*
    22.5 -libvmath - a vector math library
    22.6 -Copyright (C) 2004-2012 John Tsiombikas <nuclear@member.fsf.org>
    22.7 -
    22.8 -This program is free software: you can redistribute it and/or modify
    22.9 -it under the terms of the GNU Lesser General Public License as published
   22.10 -by the Free Software Foundation, either version 3 of the License, or
   22.11 -(at your option) any later version.
   22.12 -
   22.13 -This program is distributed in the hope that it will be useful,
   22.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22.16 -GNU Lesser General Public License for more details.
   22.17 -
   22.18 -You should have received a copy of the GNU Lesser General Public License
   22.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   22.20 -*/
   22.21 -#ifndef LIBVMATH_GEOM_H_
   22.22 -#define LIBVMATH_GEOM_H_
   22.23 -
   22.24 -#include "vector.h"
   22.25 -#include "ray.h"
   22.26 -
   22.27 -typedef struct {
   22.28 -	vec3_t norm;
   22.29 -	scalar_t d;
   22.30 -} plane_t;
   22.31 -
   22.32 -typedef struct {
   22.33 -	vec3_t pos;
   22.34 -	scalar_t rad;
   22.35 -} sphere_t;
   22.36 -
   22.37 -typedef struct {
   22.38 -	vec3_t min, max;
   22.39 -} aabox_t;
   22.40 -
   22.41 -#ifdef __cplusplus
   22.42 -extern "C" {
   22.43 -#endif
   22.44 -
   22.45 -/* planes are good... you need planes, yes you do */
   22.46 -plane_t plane_cons(scalar_t nx, scalar_t ny, scalar_t nz, scalar_t d);
   22.47 -plane_t plane_poly(vec3_t v0, vec3_t v1, vec3_t v2);
   22.48 -plane_t plane_ptnorm(vec3_t pt, vec3_t normal);
   22.49 -
   22.50 -plane_t plane_invert(plane_t p);
   22.51 -
   22.52 -scalar_t plane_signed_dist(plane_t plane, vec3_t pt);
   22.53 -scalar_t plane_dist(plane_t plane, vec3_t pt);
   22.54 -vec3_t plane_point(plane_t plane);
   22.55 -
   22.56 -int plane_ray_intersect(ray_t ray, plane_t plane, scalar_t *pos);
   22.57 -
   22.58 -/* spheres always come in handy */
   22.59 -sphere_t sphere_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t rad);
   22.60 -
   22.61 -int sphere_ray_intersect(ray_t ray, sphere_t sph, scalar_t *pos);
   22.62 -int sphere_sphere_intersect(sphere_t sph1, sphere_t sph2, scalar_t *pos, scalar_t *rad);
   22.63 -
   22.64 -#ifdef __cplusplus
   22.65 -}
   22.66 -
   22.67 -/* TODO
   22.68 -class Plane : public plane_t {
   22.69 -public:
   22.70 -};
   22.71 -*/
   22.72 -
   22.73 -#endif
   22.74 -
   22.75 -#endif	/* LIBVMATH_GEOM_H_ */
    23.1 --- a/libs/vmath/matrix.cc	Thu Jan 23 03:57:15 2014 +0200
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,821 +0,0 @@
    23.4 -#include <cstdio>
    23.5 -#include <cmath>
    23.6 -#include "matrix.h"
    23.7 -#include "vector.h"
    23.8 -#include "quat.h"
    23.9 -
   23.10 -using namespace std;
   23.11 -
   23.12 -// ----------- Matrix3x3 --------------
   23.13 -
   23.14 -Matrix3x3 Matrix3x3::identity = Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);
   23.15 -
   23.16 -Matrix3x3::Matrix3x3()
   23.17 -{
   23.18 -	*this = Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);
   23.19 -}
   23.20 -
   23.21 -Matrix3x3::Matrix3x3(	scalar_t m11, scalar_t m12, scalar_t m13,
   23.22 -						scalar_t m21, scalar_t m22, scalar_t m23,
   23.23 -						scalar_t m31, scalar_t m32, scalar_t m33)
   23.24 -{
   23.25 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13;
   23.26 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23;
   23.27 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33;
   23.28 -}
   23.29 -
   23.30 -Matrix3x3::Matrix3x3(const Vector3 &ivec, const Vector3 &jvec, const Vector3 &kvec)
   23.31 -{
   23.32 -	set_row_vector(ivec, 0);
   23.33 -	set_row_vector(jvec, 1);
   23.34 -	set_row_vector(kvec, 2);
   23.35 -}
   23.36 -
   23.37 -Matrix3x3::Matrix3x3(const mat3_t cmat)
   23.38 -{
   23.39 -	memcpy(m, cmat, sizeof(mat3_t));
   23.40 -}
   23.41 -
   23.42 -Matrix3x3::Matrix3x3(const Matrix4x4 &mat4x4)
   23.43 -{
   23.44 -	for(int i=0; i<3; i++) {
   23.45 -		for(int j=0; j<3; j++) {
   23.46 -			m[i][j] = mat4x4[i][j];
   23.47 -		}
   23.48 -	}
   23.49 -}
   23.50 -
   23.51 -Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2)
   23.52 -{
   23.53 -	Matrix3x3 res;
   23.54 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
   23.55 -	scalar_t *dest = res.m[0];
   23.56 -
   23.57 -	for(int i=0; i<9; i++) {
   23.58 -		*dest++ = *op1++ + *op2++;
   23.59 -	}
   23.60 -	return res;
   23.61 -}
   23.62 -
   23.63 -Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2)
   23.64 -{
   23.65 -	Matrix3x3 res;
   23.66 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
   23.67 -	scalar_t *dest = res.m[0];
   23.68 -
   23.69 -	for(int i=0; i<9; i++) {
   23.70 -		*dest++ = *op1++ - *op2++;
   23.71 -	}
   23.72 -	return res;
   23.73 -}
   23.74 -
   23.75 -Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2)
   23.76 -{
   23.77 -	Matrix3x3 res;
   23.78 -	for(int i=0; i<3; i++) {
   23.79 -		for(int j=0; j<3; j++) {
   23.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];
   23.81 -		}
   23.82 -	}
   23.83 -	return res;
   23.84 -}
   23.85 -
   23.86 -void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2)
   23.87 -{
   23.88 -	scalar_t *op1 = m1.m[0];
   23.89 -	const scalar_t *op2 = m2.m[0];
   23.90 -
   23.91 -	for(int i=0; i<9; i++) {
   23.92 -		*op1++ += *op2++;
   23.93 -	}
   23.94 -}
   23.95 -
   23.96 -void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2)
   23.97 -{
   23.98 -	scalar_t *op1 = m1.m[0];
   23.99 -	const scalar_t *op2 = m2.m[0];
  23.100 -
  23.101 -	for(int i=0; i<9; i++) {
  23.102 -		*op1++ -= *op2++;
  23.103 -	}
  23.104 -}
  23.105 -
  23.106 -void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2)
  23.107 -{
  23.108 -	Matrix3x3 res;
  23.109 -	for(int i=0; i<3; i++) {
  23.110 -		for(int j=0; j<3; j++) {
  23.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];
  23.112 -		}
  23.113 -	}
  23.114 -	memcpy(m1.m, res.m, 9 * sizeof(scalar_t));
  23.115 -}
  23.116 -
  23.117 -Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar)
  23.118 -{
  23.119 -	Matrix3x3 res;
  23.120 -	const scalar_t *mptr = mat.m[0];
  23.121 -	scalar_t *dptr = res.m[0];
  23.122 -
  23.123 -	for(int i=0; i<9; i++) {
  23.124 -		*dptr++ = *mptr++ * scalar;
  23.125 -	}
  23.126 -	return res;
  23.127 -}
  23.128 -
  23.129 -Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat)
  23.130 -{
  23.131 -	Matrix3x3 res;
  23.132 -	const scalar_t *mptr = mat.m[0];
  23.133 -	scalar_t *dptr = res.m[0];
  23.134 -
  23.135 -	for(int i=0; i<9; i++) {
  23.136 -		*dptr++ = *mptr++ * scalar;
  23.137 -	}
  23.138 -	return res;
  23.139 -}
  23.140 -
  23.141 -void operator *=(Matrix3x3 &mat, scalar_t scalar)
  23.142 -{
  23.143 -	scalar_t *mptr = mat.m[0];
  23.144 -
  23.145 -	for(int i=0; i<9; i++) {
  23.146 -		*mptr++ *= scalar;
  23.147 -	}
  23.148 -}
  23.149 -
  23.150 -void Matrix3x3::translate(const Vector2 &trans)
  23.151 -{
  23.152 -	Matrix3x3 tmat(1, 0, trans.x, 0, 1, trans.y, 0, 0, 1);
  23.153 -	*this *= tmat;
  23.154 -}
  23.155 -
  23.156 -void Matrix3x3::set_translation(const Vector2 &trans)
  23.157 -{
  23.158 -	*this = Matrix3x3(1, 0, trans.x, 0, 1, trans.y, 0, 0, 1);
  23.159 -}
  23.160 -
  23.161 -void Matrix3x3::rotate(scalar_t angle)
  23.162 -{
  23.163 -	scalar_t cos_a = cos(angle);
  23.164 -	scalar_t sin_a = sin(angle);
  23.165 -	Matrix3x3 rmat(	cos_a,	-sin_a,		0,
  23.166 -					sin_a,	cos_a,		0,
  23.167 -					0,		0,			1);
  23.168 -	*this *= rmat;
  23.169 -}
  23.170 -
  23.171 -void Matrix3x3::set_rotation(scalar_t angle)
  23.172 -{
  23.173 -	scalar_t cos_a = cos(angle);
  23.174 -	scalar_t sin_a = sin(angle);
  23.175 -	*this = Matrix3x3(cos_a, -sin_a, 0, sin_a, cos_a, 0, 0, 0, 1);
  23.176 -}
  23.177 -
  23.178 -void Matrix3x3::rotate(const Vector3 &euler_angles)
  23.179 -{
  23.180 -	Matrix3x3 xrot, yrot, zrot;
  23.181 -
  23.182 -	xrot = Matrix3x3(	1,			0,					0,
  23.183 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  23.184 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  23.185 -
  23.186 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  23.187 -								0,				1,				0,
  23.188 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  23.189 -
  23.190 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  23.191 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  23.192 -								0,						0,				1);
  23.193 -
  23.194 -	*this *= xrot * yrot * zrot;
  23.195 -}
  23.196 -
  23.197 -void Matrix3x3::set_rotation(const Vector3 &euler_angles)
  23.198 -{
  23.199 -	Matrix3x3 xrot, yrot, zrot;
  23.200 -
  23.201 -	xrot = Matrix3x3(	1,			0,					0,
  23.202 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  23.203 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  23.204 -
  23.205 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  23.206 -								0,				1,				0,
  23.207 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  23.208 -
  23.209 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  23.210 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  23.211 -								0,						0,				1);
  23.212 -
  23.213 -	*this = xrot * yrot * zrot;
  23.214 -}
  23.215 -
  23.216 -void Matrix3x3::rotate(const Vector3 &axis, scalar_t angle)
  23.217 -{
  23.218 -	scalar_t sina = (scalar_t)sin(angle);
  23.219 -	scalar_t cosa = (scalar_t)cos(angle);
  23.220 -	scalar_t invcosa = 1-cosa;
  23.221 -	scalar_t nxsq = axis.x * axis.x;
  23.222 -	scalar_t nysq = axis.y * axis.y;
  23.223 -	scalar_t nzsq = axis.z * axis.z;
  23.224 -
  23.225 -	Matrix3x3 xform;
  23.226 -	xform.m[0][0] = nxsq + (1-nxsq) * cosa;
  23.227 -	xform.m[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  23.228 -	xform.m[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  23.229 -
  23.230 -	xform.m[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  23.231 -	xform.m[1][1] = nysq + (1-nysq) * cosa;
  23.232 -	xform.m[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  23.233 -
  23.234 -	xform.m[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  23.235 -	xform.m[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  23.236 -	xform.m[2][2] = nzsq + (1-nzsq) * cosa;
  23.237 -
  23.238 -	*this *= xform;
  23.239 -}
  23.240 -
  23.241 -void Matrix3x3::set_rotation(const Vector3 &axis, scalar_t angle)
  23.242 -{
  23.243 -	scalar_t sina = (scalar_t)sin(angle);
  23.244 -	scalar_t cosa = (scalar_t)cos(angle);
  23.245 -	scalar_t invcosa = 1-cosa;
  23.246 -	scalar_t nxsq = axis.x * axis.x;
  23.247 -	scalar_t nysq = axis.y * axis.y;
  23.248 -	scalar_t nzsq = axis.z * axis.z;
  23.249 -
  23.250 -	reset_identity();
  23.251 -	m[0][0] = nxsq + (1-nxsq) * cosa;
  23.252 -	m[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  23.253 -	m[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  23.254 -	m[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  23.255 -	m[1][1] = nysq + (1-nysq) * cosa;
  23.256 -	m[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  23.257 -	m[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  23.258 -	m[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  23.259 -	m[2][2] = nzsq + (1-nzsq) * cosa;
  23.260 -}
  23.261 -
  23.262 -// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  23.263 -// article "Quaternion Calculus and Fast Animation".
  23.264 -// adapted from: http://www.geometrictools.com/LibMathematics/Algebra/Wm5Quaternion.inl
  23.265 -Quaternion Matrix3x3::get_rotation_quat() const
  23.266 -{
  23.267 -	static const int next[3] = {1, 2, 0};
  23.268 -
  23.269 -	float quat[4];
  23.270 -
  23.271 -	scalar_t trace = m[0][0] + m[1][1] + m[2][2];
  23.272 -	scalar_t root;
  23.273 -
  23.274 -	if(trace > 0.0f) {
  23.275 -		// |w| > 1/2
  23.276 -		root = sqrt(trace + 1.0f);	// 2w
  23.277 -		quat[0] = 0.5f * root;
  23.278 -		root = 0.5f / root;	// 1 / 4w
  23.279 -		quat[1] = (m[2][1] - m[1][2]) * root;
  23.280 -		quat[2] = (m[0][2] - m[2][0]) * root;
  23.281 -		quat[3] = (m[1][0] - m[0][1]) * root;
  23.282 -	} else {
  23.283 -		// |w| <= 1/2
  23.284 -		int i = 0;
  23.285 -		if(m[1][1] > m[0][0]) {
  23.286 -			i = 1;
  23.287 -		}
  23.288 -		if(m[2][2] > m[i][i]) {
  23.289 -			i = 2;
  23.290 -		}
  23.291 -		int j = next[i];
  23.292 -		int k = next[j];
  23.293 -
  23.294 -		root = sqrt(m[i][i] - m[j][j] - m[k][k] + 1.0f);
  23.295 -		quat[i + 1] = 0.5f * root;
  23.296 -		root = 0.5f / root;
  23.297 -		quat[0] = (m[k][j] - m[j][k]) * root;
  23.298 -		quat[j + 1] = (m[j][i] - m[i][j]) * root;
  23.299 -		quat[k + 1] = (m[k][i] - m[i][k]) * root;
  23.300 -	}
  23.301 -	return Quaternion(quat[0], quat[1], quat[2], quat[3]);
  23.302 -}
  23.303 -
  23.304 -void Matrix3x3::scale(const Vector3 &scale_vec)
  23.305 -{
  23.306 -	Matrix3x3 smat(	scale_vec.x, 0, 0,
  23.307 -					0, scale_vec.y, 0,
  23.308 -					0, 0, scale_vec.z);
  23.309 -	*this *= smat;
  23.310 -}
  23.311 -
  23.312 -void Matrix3x3::set_scaling(const Vector3 &scale_vec)
  23.313 -{
  23.314 -	*this = Matrix3x3(	scale_vec.x, 0, 0,
  23.315 -						0, scale_vec.y, 0,
  23.316 -						0, 0, scale_vec.z);
  23.317 -}
  23.318 -
  23.319 -void Matrix3x3::set_column_vector(const Vector3 &vec, unsigned int col_index)
  23.320 -{
  23.321 -	m[0][col_index] = vec.x;
  23.322 -	m[1][col_index] = vec.y;
  23.323 -	m[2][col_index] = vec.z;
  23.324 -}
  23.325 -
  23.326 -void Matrix3x3::set_row_vector(const Vector3 &vec, unsigned int row_index)
  23.327 -{
  23.328 -	m[row_index][0] = vec.x;
  23.329 -	m[row_index][1] = vec.y;
  23.330 -	m[row_index][2] = vec.z;
  23.331 -}
  23.332 -
  23.333 -Vector3 Matrix3x3::get_column_vector(unsigned int col_index) const
  23.334 -{
  23.335 -	return Vector3(m[0][col_index], m[1][col_index], m[2][col_index]);
  23.336 -}
  23.337 -
  23.338 -Vector3 Matrix3x3::get_row_vector(unsigned int row_index) const
  23.339 -{
  23.340 -	return Vector3(m[row_index][0], m[row_index][1], m[row_index][2]);
  23.341 -}
  23.342 -
  23.343 -void Matrix3x3::transpose()
  23.344 -{
  23.345 -	Matrix3x3 tmp = *this;
  23.346 -	for(int i=0; i<3; i++) {
  23.347 -		for(int j=0; j<3; j++) {
  23.348 -			m[i][j] = tmp[j][i];
  23.349 -		}
  23.350 -	}
  23.351 -}
  23.352 -
  23.353 -Matrix3x3 Matrix3x3::transposed() const
  23.354 -{
  23.355 -	Matrix3x3 res;
  23.356 -	for(int i=0; i<3; i++) {
  23.357 -		for(int j=0; j<3; j++) {
  23.358 -			res[i][j] = m[j][i];
  23.359 -		}
  23.360 -	}
  23.361 -	return res;
  23.362 -}
  23.363 -
  23.364 -scalar_t Matrix3x3::determinant() const
  23.365 -{
  23.366 -	return	m[0][0] * (m[1][1]*m[2][2] - m[1][2]*m[2][1]) -
  23.367 -			m[0][1] * (m[1][0]*m[2][2] - m[1][2]*m[2][0]) +
  23.368 -			m[0][2] * (m[1][0]*m[2][1] - m[1][1]*m[2][0]);
  23.369 -}
  23.370 -
  23.371 -Matrix3x3 Matrix3x3::inverse() const
  23.372 -{
  23.373 -	// TODO: implement 3x3 inverse
  23.374 -	return *this;
  23.375 -}
  23.376 -
  23.377 -ostream &operator <<(ostream &out, const Matrix3x3 &mat)
  23.378 -{
  23.379 -	for(int i=0; i<3; i++) {
  23.380 -		char str[100];
  23.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]);
  23.382 -		out << str;
  23.383 -	}
  23.384 -	return out;
  23.385 -}
  23.386 -
  23.387 -
  23.388 -
  23.389 -/* ----------------- Matrix4x4 implementation --------------- */
  23.390 -
  23.391 -Matrix4x4 Matrix4x4::identity = Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  23.392 -
  23.393 -Matrix4x4::Matrix4x4()
  23.394 -{
  23.395 -	*this = Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  23.396 -}
  23.397 -
  23.398 -Matrix4x4::Matrix4x4(	scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
  23.399 -						scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
  23.400 -						scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
  23.401 -						scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44)
  23.402 -{
  23.403 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13; m[0][3] = m14;
  23.404 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23; m[1][3] = m24;
  23.405 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33; m[2][3] = m34;
  23.406 -	m[3][0] = m41; m[3][1] = m42; m[3][2] = m43; m[3][3] = m44;
  23.407 -}
  23.408 -
  23.409 -Matrix4x4::Matrix4x4(const mat4_t cmat)
  23.410 -{
  23.411 -	memcpy(m, cmat, sizeof(mat4_t));
  23.412 -}
  23.413 -
  23.414 -Matrix4x4::Matrix4x4(const Matrix3x3 &mat3x3)
  23.415 -{
  23.416 -	reset_identity();
  23.417 -	for(int i=0; i<3; i++) {
  23.418 -		for(int j=0; j<3; j++) {
  23.419 -			m[i][j] = mat3x3[i][j];
  23.420 -		}
  23.421 -	}
  23.422 -}
  23.423 -
  23.424 -Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2)
  23.425 -{
  23.426 -	Matrix4x4 res;
  23.427 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
  23.428 -	scalar_t *dest = res.m[0];
  23.429 -
  23.430 -	for(int i=0; i<16; i++) {
  23.431 -		*dest++ = *op1++ + *op2++;
  23.432 -	}
  23.433 -	return res;
  23.434 -}
  23.435 -
  23.436 -Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2)
  23.437 -{
  23.438 -	Matrix4x4 res;
  23.439 -	const scalar_t *op1 = m1.m[0], *op2 = m2.m[0];
  23.440 -	scalar_t *dest = res.m[0];
  23.441 -
  23.442 -	for(int i=0; i<16; i++) {
  23.443 -		*dest++ = *op1++ - *op2++;
  23.444 -	}
  23.445 -	return res;
  23.446 -}
  23.447 -
  23.448 -void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2)
  23.449 -{
  23.450 -	scalar_t *op1 = m1.m[0];
  23.451 -	const scalar_t *op2 = m2.m[0];
  23.452 -
  23.453 -	for(int i=0; i<16; i++) {
  23.454 -		*op1++ += *op2++;
  23.455 -	}
  23.456 -}
  23.457 -
  23.458 -void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2)
  23.459 -{
  23.460 -	scalar_t *op1 = m1.m[0];
  23.461 -	const scalar_t *op2 = m2.m[0];
  23.462 -
  23.463 -	for(int i=0; i<16; i++) {
  23.464 -		*op1++ -= *op2++;
  23.465 -	}
  23.466 -}
  23.467 -
  23.468 -Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar)
  23.469 -{
  23.470 -	Matrix4x4 res;
  23.471 -	const scalar_t *mptr = mat.m[0];
  23.472 -	scalar_t *dptr = res.m[0];
  23.473 -
  23.474 -	for(int i=0; i<16; i++) {
  23.475 -		*dptr++ = *mptr++ * scalar;
  23.476 -	}
  23.477 -	return res;
  23.478 -}
  23.479 -
  23.480 -Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat)
  23.481 -{
  23.482 -	Matrix4x4 res;
  23.483 -	const scalar_t *mptr = mat.m[0];
  23.484 -	scalar_t *dptr = res.m[0];
  23.485 -
  23.486 -	for(int i=0; i<16; i++) {
  23.487 -		*dptr++ = *mptr++ * scalar;
  23.488 -	}
  23.489 -	return res;
  23.490 -}
  23.491 -
  23.492 -void operator *=(Matrix4x4 &mat, scalar_t scalar)
  23.493 -{
  23.494 -	scalar_t *mptr = mat.m[0];
  23.495 -
  23.496 -	for(int i=0; i<16; i++) {
  23.497 -		*mptr++ *= scalar;
  23.498 -	}
  23.499 -}
  23.500 -
  23.501 -void Matrix4x4::translate(const Vector3 &trans)
  23.502 -{
  23.503 -	Matrix4x4 tmat(1, 0, 0, trans.x, 0, 1, 0, trans.y, 0, 0, 1, trans.z, 0, 0, 0, 1);
  23.504 -	*this *= tmat;
  23.505 -}
  23.506 -
  23.507 -void Matrix4x4::set_translation(const Vector3 &trans)
  23.508 -{
  23.509 -	*this = Matrix4x4(1, 0, 0, trans.x, 0, 1, 0, trans.y, 0, 0, 1, trans.z, 0, 0, 0, 1);
  23.510 -}
  23.511 -
  23.512 -Vector3 Matrix4x4::get_translation() const
  23.513 -{
  23.514 -	return Vector3(m[0][3], m[1][3], m[2][3]);
  23.515 -}
  23.516 -
  23.517 -void Matrix4x4::rotate(const Vector3 &euler_angles)
  23.518 -{
  23.519 -	Matrix3x3 xrot, yrot, zrot;
  23.520 -
  23.521 -	xrot = Matrix3x3(	1,			0,					0,
  23.522 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  23.523 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  23.524 -
  23.525 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  23.526 -								0,				1,				0,
  23.527 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  23.528 -
  23.529 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  23.530 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  23.531 -								0,						0,				1);
  23.532 -
  23.533 -	*this *= Matrix4x4(xrot * yrot * zrot);
  23.534 -}
  23.535 -
  23.536 -void Matrix4x4::set_rotation(const Vector3 &euler_angles)
  23.537 -{
  23.538 -	Matrix3x3 xrot, yrot, zrot;
  23.539 -
  23.540 -	xrot = Matrix3x3(	1,			0,					0,
  23.541 -						0,	cos(euler_angles.x),	-sin(euler_angles.x),
  23.542 -						0,	sin(euler_angles.x),	cos(euler_angles.x));
  23.543 -
  23.544 -	yrot = Matrix3x3(	cos(euler_angles.y),	0,	sin(euler_angles.y),
  23.545 -								0,				1,				0,
  23.546 -						-sin(euler_angles.y),	0,	cos(euler_angles.y));
  23.547 -
  23.548 -	zrot = Matrix3x3(	cos(euler_angles.z),	-sin(euler_angles.z),	0,
  23.549 -						sin(euler_angles.z),	cos(euler_angles.z),	0,
  23.550 -								0,						0,				1);
  23.551 -
  23.552 -	*this = Matrix4x4(xrot * yrot * zrot);
  23.553 -}
  23.554 -
  23.555 -void Matrix4x4::rotate(const Vector3 &axis, scalar_t angle)
  23.556 -{
  23.557 -	scalar_t sina = (scalar_t)sin(angle);
  23.558 -	scalar_t cosa = (scalar_t)cos(angle);
  23.559 -	scalar_t invcosa = 1-cosa;
  23.560 -	scalar_t nxsq = axis.x * axis.x;
  23.561 -	scalar_t nysq = axis.y * axis.y;
  23.562 -	scalar_t nzsq = axis.z * axis.z;
  23.563 -
  23.564 -	Matrix4x4 xform;
  23.565 -	xform[0][0] = nxsq + (1-nxsq) * cosa;
  23.566 -	xform[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  23.567 -	xform[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  23.568 -	xform[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  23.569 -	xform[1][1] = nysq + (1-nysq) * cosa;
  23.570 -	xform[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  23.571 -	xform[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  23.572 -	xform[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  23.573 -	xform[2][2] = nzsq + (1-nzsq) * cosa;
  23.574 -
  23.575 -	*this *= xform;
  23.576 -}
  23.577 -
  23.578 -void Matrix4x4::set_rotation(const Vector3 &axis, scalar_t angle)
  23.579 -{
  23.580 -	scalar_t sina = (scalar_t)sin(angle);
  23.581 -	scalar_t cosa = (scalar_t)cos(angle);
  23.582 -	scalar_t invcosa = 1-cosa;
  23.583 -	scalar_t nxsq = axis.x * axis.x;
  23.584 -	scalar_t nysq = axis.y * axis.y;
  23.585 -	scalar_t nzsq = axis.z * axis.z;
  23.586 -
  23.587 -	reset_identity();
  23.588 -	m[0][0] = nxsq + (1-nxsq) * cosa;
  23.589 -	m[0][1] = axis.x * axis.y * invcosa - axis.z * sina;
  23.590 -	m[0][2] = axis.x * axis.z * invcosa + axis.y * sina;
  23.591 -	m[1][0] = axis.x * axis.y * invcosa + axis.z * sina;
  23.592 -	m[1][1] = nysq + (1-nysq) * cosa;
  23.593 -	m[1][2] = axis.y * axis.z * invcosa - axis.x * sina;
  23.594 -	m[2][0] = axis.x * axis.z * invcosa - axis.y * sina;
  23.595 -	m[2][1] = axis.y * axis.z * invcosa + axis.x * sina;
  23.596 -	m[2][2] = nzsq + (1-nzsq) * cosa;
  23.597 -}
  23.598 -
  23.599 -void Matrix4x4::rotate(const Quaternion &quat)
  23.600 -{
  23.601 -	*this *= quat.get_rotation_matrix();
  23.602 -}
  23.603 -
  23.604 -void Matrix4x4::set_rotation(const Quaternion &quat)
  23.605 -{
  23.606 -	*this = quat.get_rotation_matrix();
  23.607 -}
  23.608 -
  23.609 -Quaternion Matrix4x4::get_rotation_quat() const
  23.610 -{
  23.611 -	Matrix3x3 mat3 = *this;
  23.612 -	return mat3.get_rotation_quat();
  23.613 -}
  23.614 -
  23.615 -void Matrix4x4::scale(const Vector4 &scale_vec)
  23.616 -{
  23.617 -	Matrix4x4 smat(	scale_vec.x, 0, 0, 0,
  23.618 -					0, scale_vec.y, 0, 0,
  23.619 -					0, 0, scale_vec.z, 0,
  23.620 -					0, 0, 0, scale_vec.w);
  23.621 -	*this *= smat;
  23.622 -}
  23.623 -
  23.624 -void Matrix4x4::set_scaling(const Vector4 &scale_vec)
  23.625 -{
  23.626 -	*this = Matrix4x4(	scale_vec.x, 0, 0, 0,
  23.627 -						0, scale_vec.y, 0, 0,
  23.628 -						0, 0, scale_vec.z, 0,
  23.629 -						0, 0, 0, scale_vec.w);
  23.630 -}
  23.631 -
  23.632 -Vector3 Matrix4x4::get_scaling() const
  23.633 -{
  23.634 -	Vector3 vi = get_row_vector(0);
  23.635 -	Vector3 vj = get_row_vector(1);
  23.636 -	Vector3 vk = get_row_vector(2);
  23.637 -
  23.638 -	return Vector3(vi.length(), vj.length(), vk.length());
  23.639 -}
  23.640 -
  23.641 -void Matrix4x4::set_perspective(float vfov, float aspect, float znear, float zfar)
  23.642 -{
  23.643 -	float f = 1.0f / tan(vfov * 0.5f);
  23.644 -    float dz = znear - zfar;
  23.645 -
  23.646 -	reset_identity();
  23.647 -
  23.648 -	m[0][0] = f / aspect;
  23.649 -    m[1][1] = f;
  23.650 -    m[2][2] = (zfar + znear) / dz;
  23.651 -    m[3][2] = -1.0f;
  23.652 -    m[2][3] = 2.0f * zfar * znear / dz;
  23.653 -    m[3][3] = 0.0f;
  23.654 -}
  23.655 -
  23.656 -void Matrix4x4::set_orthographic(float left, float right, float bottom, float top, float znear, float zfar)
  23.657 -{
  23.658 -	float dx = right - left;
  23.659 -	float dy = top - bottom;
  23.660 -	float dz = zfar - znear;
  23.661 -
  23.662 -	reset_identity();
  23.663 -
  23.664 -	m[0][0] = 2.0 / dx;
  23.665 -	m[1][1] = 2.0 / dy;
  23.666 -	m[2][2] = -2.0 / dz;
  23.667 -	m[0][3] = -(right + left) / dx;
  23.668 -	m[1][3] = -(top + bottom) / dy;
  23.669 -	m[2][3] = -(zfar + znear) / dz;
  23.670 -}
  23.671 -
  23.672 -void Matrix4x4::set_column_vector(const Vector4 &vec, unsigned int col_index)
  23.673 -{
  23.674 -	m[0][col_index] = vec.x;
  23.675 -	m[1][col_index] = vec.y;
  23.676 -	m[2][col_index] = vec.z;
  23.677 -	m[3][col_index] = vec.w;
  23.678 -}
  23.679 -
  23.680 -void Matrix4x4::set_row_vector(const Vector4 &vec, unsigned int row_index)
  23.681 -{
  23.682 -	m[row_index][0] = vec.x;
  23.683 -	m[row_index][1] = vec.y;
  23.684 -	m[row_index][2] = vec.z;
  23.685 -	m[row_index][3] = vec.w;
  23.686 -}
  23.687 -
  23.688 -Vector4 Matrix4x4::get_column_vector(unsigned int col_index) const
  23.689 -{
  23.690 -	return Vector4(m[0][col_index], m[1][col_index], m[2][col_index], m[3][col_index]);
  23.691 -}
  23.692 -
  23.693 -Vector4 Matrix4x4::get_row_vector(unsigned int row_index) const
  23.694 -{
  23.695 -	return Vector4(m[row_index][0], m[row_index][1], m[row_index][2], m[row_index][3]);
  23.696 -}
  23.697 -
  23.698 -void Matrix4x4::transpose()
  23.699 -{
  23.700 -	Matrix4x4 tmp = *this;
  23.701 -	for(int i=0; i<4; i++) {
  23.702 -		for(int j=0; j<4; j++) {
  23.703 -			m[i][j] = tmp[j][i];
  23.704 -		}
  23.705 -	}
  23.706 -}
  23.707 -
  23.708 -Matrix4x4 Matrix4x4::transposed() const
  23.709 -{
  23.710 -	Matrix4x4 res;
  23.711 -	for(int i=0; i<4; i++) {
  23.712 -		for(int j=0; j<4; j++) {
  23.713 -			res[i][j] = m[j][i];
  23.714 -		}
  23.715 -	}
  23.716 -	return res;
  23.717 -}
  23.718 -
  23.719 -scalar_t Matrix4x4::determinant() const
  23.720 -{
  23.721 -	scalar_t det11 =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  23.722 -						(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  23.723 -						(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  23.724 -
  23.725 -	scalar_t det12 =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  23.726 -						(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  23.727 -						(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  23.728 -
  23.729 -	scalar_t det13 =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  23.730 -						(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  23.731 -						(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  23.732 -
  23.733 -	scalar_t det14 =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  23.734 -						(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  23.735 -						(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  23.736 -
  23.737 -	return m[0][0] * det11 - m[0][1] * det12 + m[0][2] * det13 - m[0][3] * det14;
  23.738 -}
  23.739 -
  23.740 -
  23.741 -Matrix4x4 Matrix4x4::adjoint() const
  23.742 -{
  23.743 -	Matrix4x4 coef;
  23.744 -
  23.745 -	coef.m[0][0] =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  23.746 -					(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  23.747 -					(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  23.748 -	coef.m[0][1] =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  23.749 -					(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  23.750 -					(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  23.751 -	coef.m[0][2] =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  23.752 -					(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  23.753 -					(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  23.754 -	coef.m[0][3] =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  23.755 -					(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  23.756 -					(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  23.757 -
  23.758 -	coef.m[1][0] =	(m[0][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  23.759 -					(m[0][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  23.760 -					(m[0][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  23.761 -	coef.m[1][1] =	(m[0][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  23.762 -					(m[0][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  23.763 -					(m[0][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  23.764 -	coef.m[1][2] =	(m[0][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  23.765 -					(m[0][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  23.766 -					(m[0][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  23.767 -	coef.m[1][3] =	(m[0][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  23.768 -					(m[0][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  23.769 -					(m[0][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  23.770 -
  23.771 -	coef.m[2][0] =	(m[0][1] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  23.772 -					(m[0][2] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) +
  23.773 -					(m[0][3] * (m[1][1] * m[3][2] - m[3][1] * m[1][2]));
  23.774 -	coef.m[2][1] =	(m[0][0] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  23.775 -					(m[0][2] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  23.776 -					(m[0][3] * (m[1][0] * m[3][2] - m[3][0] * m[1][2]));
  23.777 -	coef.m[2][2] =	(m[0][0] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) -
  23.778 -					(m[0][1] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  23.779 -					(m[0][3] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  23.780 -	coef.m[2][3] =	(m[0][0] * (m[1][1] * m[3][2] - m[3][1] * m[1][2])) -
  23.781 -					(m[0][1] * (m[1][0] * m[3][2] - m[3][0] * m[1][2])) +
  23.782 -					(m[0][2] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  23.783 -
  23.784 -	coef.m[3][0] =	(m[0][1] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  23.785 -					(m[0][2] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) +
  23.786 -					(m[0][3] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]));
  23.787 -	coef.m[3][1] =	(m[0][0] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  23.788 -					(m[0][2] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  23.789 -					(m[0][3] * (m[1][0] * m[2][2] - m[2][0] * m[1][2]));
  23.790 -	coef.m[3][2] =	(m[0][0] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) -
  23.791 -					(m[0][1] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  23.792 -					(m[0][3] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  23.793 -	coef.m[3][3] =	(m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])) -
  23.794 -					(m[0][1] * (m[1][0] * m[2][2] - m[2][0] * m[1][2])) +
  23.795 -					(m[0][2] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  23.796 -
  23.797 -	coef.transpose();
  23.798 -
  23.799 -	for(int i=0; i<4; i++) {
  23.800 -		for(int j=0; j<4; j++) {
  23.801 -			coef.m[i][j] = j%2 ? -coef.m[i][j] : coef.m[i][j];
  23.802 -			if(i%2) coef.m[i][j] = -coef.m[i][j];
  23.803 -		}
  23.804 -	}
  23.805 -
  23.806 -	return coef;
  23.807 -}
  23.808 -
  23.809 -Matrix4x4 Matrix4x4::inverse() const
  23.810 -{
  23.811 -	Matrix4x4 adj = adjoint();
  23.812 -
  23.813 -	return adj * (1.0f / determinant());
  23.814 -}
  23.815 -
  23.816 -ostream &operator <<(ostream &out, const Matrix4x4 &mat)
  23.817 -{
  23.818 -	for(int i=0; i<4; i++) {
  23.819 -		char str[100];
  23.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]);
  23.821 -		out << str;
  23.822 -	}
  23.823 -	return out;
  23.824 -}
    24.1 --- a/libs/vmath/matrix.h	Thu Jan 23 03:57:15 2014 +0200
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,260 +0,0 @@
    24.4 -/*
    24.5 -libvmath - a vector math library
    24.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    24.7 -
    24.8 -This program is free software: you can redistribute it and/or modify
    24.9 -it under the terms of the GNU Lesser General Public License as published
   24.10 -by the Free Software Foundation, either version 3 of the License, or
   24.11 -(at your option) any later version.
   24.12 -
   24.13 -This program is distributed in the hope that it will be useful,
   24.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   24.16 -GNU Lesser General Public License for more details.
   24.17 -
   24.18 -You should have received a copy of the GNU Lesser General Public License
   24.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   24.20 -*/
   24.21 -
   24.22 -#ifndef VMATH_MATRIX_H_
   24.23 -#define VMATH_MATRIX_H_
   24.24 -
   24.25 -#include <stdio.h>
   24.26 -#include "vmath_types.h"
   24.27 -
   24.28 -#ifdef __cplusplus
   24.29 -extern "C" {
   24.30 -#endif	/* __cplusplus */
   24.31 -
   24.32 -/* C matrix 3x3 functions */
   24.33 -static VMATH_INLINE void m3_identity(mat3_t m);
   24.34 -static VMATH_INLINE void m3_cons(mat3_t m,
   24.35 -		scalar_t m11, scalar_t m12, scalar_t m13,
   24.36 -		scalar_t m21, scalar_t m22, scalar_t m23,
   24.37 -		scalar_t m31, scalar_t m32, scalar_t m33);
   24.38 -static VMATH_INLINE void m3_copy(mat3_t dest, mat3_t src);
   24.39 -void m3_to_m4(mat4_t dest, mat3_t src);
   24.40 -
   24.41 -void m3_print(FILE *fp, mat3_t m);
   24.42 -
   24.43 -/* C matrix 4x4 functions */
   24.44 -static VMATH_INLINE void m4_identity(mat4_t m);
   24.45 -static VMATH_INLINE void m4_cons(mat4_t m,
   24.46 -		scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
   24.47 -		scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
   24.48 -		scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
   24.49 -		scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
   24.50 -static VMATH_INLINE void m4_copy(mat4_t dest, mat4_t src);
   24.51 -void m4_to_m3(mat3_t dest, mat4_t src);
   24.52 -
   24.53 -static VMATH_INLINE void m4_mult(mat4_t res, mat4_t m1, mat4_t m2);
   24.54 -
   24.55 -void m4_set_translation(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   24.56 -void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   24.57 -
   24.58 -void m4_rotate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   24.59 -
   24.60 -void m4_set_rotation_x(mat4_t m, scalar_t angle);
   24.61 -void m4_rotate_x(mat4_t m, scalar_t angle);
   24.62 -void m4_set_rotation_y(mat4_t m, scalar_t angle);
   24.63 -void m4_rotate_y(mat4_t m, scalar_t angle);
   24.64 -void m4_set_rotation_z(mat4_t m, scalar_t angle);
   24.65 -void m4_rotate_z(mat4_t m, scalar_t angle);
   24.66 -/* axis-angle rotation */
   24.67 -void m4_set_rotation_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   24.68 -void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   24.69 -/* concatentate a rotation quaternion */
   24.70 -void m4_rotate_quat(mat4_t m, quat_t q);
   24.71 -
   24.72 -void m4_set_scaling(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   24.73 -void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
   24.74 -
   24.75 -static VMATH_INLINE void m4_set_column(mat4_t m, vec4_t v, int idx);
   24.76 -static VMATH_INLINE void m4_set_row(mat4_t m, vec4_t v, int idx);
   24.77 -
   24.78 -void m4_transpose(mat4_t res, mat4_t m);
   24.79 -scalar_t m4_determinant(mat4_t m);
   24.80 -void m4_adjoint(mat4_t res, mat4_t m);
   24.81 -void m4_inverse(mat4_t res, mat4_t m);
   24.82 -
   24.83 -void m4_print(FILE *fp, mat4_t m);
   24.84 -
   24.85 -#ifdef __cplusplus
   24.86 -}
   24.87 -
   24.88 -/* when included from C++ source files, also define the matrix classes */
   24.89 -#include <iostream>
   24.90 -
   24.91 -/** 3x3 matrix */
   24.92 -class Matrix3x3 {
   24.93 -public:
   24.94 -	scalar_t m[3][3];
   24.95 -
   24.96 -	static Matrix3x3 identity;
   24.97 -
   24.98 -	Matrix3x3();
   24.99 -	Matrix3x3(	scalar_t m11, scalar_t m12, scalar_t m13,
  24.100 -				scalar_t m21, scalar_t m22, scalar_t m23,
  24.101 -				scalar_t m31, scalar_t m32, scalar_t m33);
  24.102 -	Matrix3x3(const Vector3 &ivec, const Vector3 &jvec, const Vector3 &kvec);
  24.103 -	Matrix3x3(const mat3_t cmat);
  24.104 -
  24.105 -	Matrix3x3(const Matrix4x4 &mat4x4);
  24.106 -
  24.107 -	/* binary operations matrix (op) matrix */
  24.108 -	friend Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
  24.109 -	friend Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
  24.110 -	friend Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
  24.111 -
  24.112 -	friend void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
  24.113 -	friend void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
  24.114 -	friend void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
  24.115 -
  24.116 -	/* binary operations matrix (op) scalar and scalar (op) matrix */
  24.117 -	friend Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
  24.118 -	friend Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
  24.119 -
  24.120 -	friend void operator *=(Matrix3x3 &mat, scalar_t scalar);
  24.121 -
  24.122 -	VMATH_INLINE scalar_t *operator [](int index);
  24.123 -	VMATH_INLINE const scalar_t *operator [](int index) const;
  24.124 -
  24.125 -	VMATH_INLINE void reset_identity();
  24.126 -
  24.127 -	void translate(const Vector2 &trans);
  24.128 -	void set_translation(const Vector2 &trans);
  24.129 -
  24.130 -	void rotate(scalar_t angle);						/* 2d rotation */
  24.131 -	void rotate(const Vector3 &euler_angles);			/* 3d rotation with euler angles */
  24.132 -	void rotate(const Vector3 &axis, scalar_t angle);	/* 3d axis/angle rotation */
  24.133 -	void set_rotation(scalar_t angle);
  24.134 -	void set_rotation(const Vector3 &euler_angles);
  24.135 -	void set_rotation(const Vector3 &axis, scalar_t angle);
  24.136 -	Quaternion get_rotation_quat() const;
  24.137 -
  24.138 -	void scale(const Vector3 &scale_vec);
  24.139 -	void set_scaling(const Vector3 &scale_vec);
  24.140 -
  24.141 -	void set_column_vector(const Vector3 &vec, unsigned int col_index);
  24.142 -	void set_row_vector(const Vector3 &vec, unsigned int row_index);
  24.143 -	Vector3 get_column_vector(unsigned int col_index) const;
  24.144 -	Vector3 get_row_vector(unsigned int row_index) const;
  24.145 -
  24.146 -	void transpose();
  24.147 -	Matrix3x3 transposed() const;
  24.148 -	scalar_t determinant() const;
  24.149 -	Matrix3x3 inverse() const;
  24.150 -
  24.151 -	friend std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
  24.152 -};
  24.153 -
  24.154 -/* binary operations matrix (op) matrix */
  24.155 -Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
  24.156 -Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
  24.157 -Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
  24.158 -
  24.159 -void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
  24.160 -void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
  24.161 -void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
  24.162 -
  24.163 -/* binary operations matrix (op) scalar and scalar (op) matrix */
  24.164 -Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
  24.165 -Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
  24.166 -
  24.167 -void operator *=(Matrix3x3 &mat, scalar_t scalar);
  24.168 -
  24.169 -std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
  24.170 -
  24.171 -
  24.172 -
  24.173 -/** 4x4 matrix */
  24.174 -class Matrix4x4 {
  24.175 -public:
  24.176 -	scalar_t m[4][4];
  24.177 -
  24.178 -	static Matrix4x4 identity;
  24.179 -
  24.180 -	Matrix4x4();
  24.181 -	Matrix4x4(	scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
  24.182 -				scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
  24.183 -				scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
  24.184 -				scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
  24.185 -	Matrix4x4(const mat4_t cmat);
  24.186 -
  24.187 -	Matrix4x4(const Matrix3x3 &mat3x3);
  24.188 -
  24.189 -	/* binary operations matrix (op) matrix */
  24.190 -	friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
  24.191 -	friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
  24.192 -	friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
  24.193 -
  24.194 -	friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
  24.195 -	friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
  24.196 -	friend VMATH_INLINE void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
  24.197 -
  24.198 -	/* binary operations matrix (op) scalar and scalar (op) matrix */
  24.199 -	friend Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
  24.200 -	friend Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
  24.201 -
  24.202 -	friend void operator *=(Matrix4x4 &mat, scalar_t scalar);
  24.203 -
  24.204 -	VMATH_INLINE scalar_t *operator [](int index);
  24.205 -	VMATH_INLINE const scalar_t *operator [](int index) const;
  24.206 -
  24.207 -	VMATH_INLINE void reset_identity();
  24.208 -
  24.209 -	void translate(const Vector3 &trans);
  24.210 -	void set_translation(const Vector3 &trans);
  24.211 -	Vector3 get_translation() const;	/* extract translation */
  24.212 -
  24.213 -	void rotate(const Vector3 &euler_angles);			/* 3d rotation with euler angles */
  24.214 -	void rotate(const Vector3 &axis, scalar_t angle);	/* 3d axis/angle rotation */
  24.215 -	void rotate(const Quaternion &quat);
  24.216 -	void set_rotation(const Vector3 &euler_angles);
  24.217 -	void set_rotation(const Vector3 &axis, scalar_t angle);
  24.218 -	void set_rotation(const Quaternion &quat);
  24.219 -	Quaternion get_rotation_quat() const;		/* extract rotation */
  24.220 -
  24.221 -	void scale(const Vector4 &scale_vec);
  24.222 -	void set_scaling(const Vector4 &scale_vec);
  24.223 -	Vector3 get_scaling() const;		/* extract scaling */
  24.224 -
  24.225 -	void set_perspective(float vfov, float aspect, float znear, float zfar);
  24.226 -	void set_orthographic(float left, float right, float bottom, float top, float znear = -1.0, float zfar = 1.0);
  24.227 -
  24.228 -	void set_column_vector(const Vector4 &vec, unsigned int col_index);
  24.229 -	void set_row_vector(const Vector4 &vec, unsigned int row_index);
  24.230 -	Vector4 get_column_vector(unsigned int col_index) const;
  24.231 -	Vector4 get_row_vector(unsigned int row_index) const;
  24.232 -
  24.233 -	void transpose();
  24.234 -	Matrix4x4 transposed() const;
  24.235 -	scalar_t determinant() const;
  24.236 -	Matrix4x4 adjoint() const;
  24.237 -	Matrix4x4 inverse() const;
  24.238 -
  24.239 -	friend std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
  24.240 -};
  24.241 -
  24.242 -/* binary operations matrix (op) matrix */
  24.243 -Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
  24.244 -Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
  24.245 -VMATH_INLINE Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
  24.246 -
  24.247 -void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
  24.248 -void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
  24.249 -VMATH_INLINE void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
  24.250 -
  24.251 -/* binary operations matrix (op) scalar and scalar (op) matrix */
  24.252 -Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
  24.253 -Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
  24.254 -
  24.255 -void operator *=(Matrix4x4 &mat, scalar_t scalar);
  24.256 -
  24.257 -std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
  24.258 -
  24.259 -#endif	/* __cplusplus */
  24.260 -
  24.261 -#include "matrix.inl"
  24.262 -
  24.263 -#endif	/* VMATH_MATRIX_H_ */
    25.1 --- a/libs/vmath/matrix.inl	Thu Jan 23 03:57:15 2014 +0200
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,200 +0,0 @@
    25.4 -/*
    25.5 -libvmath - a vector math library
    25.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    25.7 -
    25.8 -This program is free software: you can redistribute it and/or modify
    25.9 -it under the terms of the GNU Lesser General Public License as published
   25.10 -by the Free Software Foundation, either version 3 of the License, or
   25.11 -(at your option) any later version.
   25.12 -
   25.13 -This program is distributed in the hope that it will be useful,
   25.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   25.16 -GNU Lesser General Public License for more details.
   25.17 -
   25.18 -You should have received a copy of the GNU Lesser General Public License
   25.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   25.20 -*/
   25.21 -
   25.22 -#include <string.h>
   25.23 -
   25.24 -#ifdef __cplusplus
   25.25 -extern "C" {
   25.26 -#endif	/* __cplusplus */
   25.27 -
   25.28 -/* C matrix 3x3 functions */
   25.29 -static VMATH_INLINE void m3_identity(mat3_t m)
   25.30 -{
   25.31 -	static const mat3_t id = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
   25.32 -	memcpy(m, id, sizeof id);
   25.33 -}
   25.34 -
   25.35 -static VMATH_INLINE void m3_cons(mat3_t m,
   25.36 -		scalar_t m11, scalar_t m12, scalar_t m13,
   25.37 -		scalar_t m21, scalar_t m22, scalar_t m23,
   25.38 -		scalar_t m31, scalar_t m32, scalar_t m33)
   25.39 -{
   25.40 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13;
   25.41 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23;
   25.42 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33;
   25.43 -}
   25.44 -
   25.45 -static VMATH_INLINE void m3_copy(mat3_t dest, mat3_t src)
   25.46 -{
   25.47 -	memcpy(dest, src, sizeof(mat3_t));
   25.48 -}
   25.49 -
   25.50 -
   25.51 -/* C matrix 4x4 functions */
   25.52 -static VMATH_INLINE void m4_identity(mat4_t m)
   25.53 -{
   25.54 -	static const mat4_t id = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
   25.55 -	memcpy(m, id, sizeof id);
   25.56 -}
   25.57 -
   25.58 -static VMATH_INLINE void m4_cons(mat4_t m,
   25.59 -		scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
   25.60 -		scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
   25.61 -		scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
   25.62 -		scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44)
   25.63 -{
   25.64 -	m[0][0] = m11; m[0][1] = m12; m[0][2] = m13; m[0][3] = m14;
   25.65 -	m[1][0] = m21; m[1][1] = m22; m[1][2] = m23; m[1][3] = m24;
   25.66 -	m[2][0] = m31; m[2][1] = m32; m[2][2] = m33; m[2][3] = m34;
   25.67 -	m[3][0] = m41; m[3][1] = m42; m[3][2] = m43; m[3][3] = m44;
   25.68 -}
   25.69 -
   25.70 -static VMATH_INLINE void m4_copy(mat4_t dest, mat4_t src)
   25.71 -{
   25.72 -	memcpy(dest, src, sizeof(mat4_t));
   25.73 -}
   25.74 -
   25.75 -static VMATH_INLINE void m4_mult(mat4_t res, mat4_t m1, mat4_t m2)
   25.76 -{
   25.77 -	mat4_t tmp;
   25.78 -
   25.79 -	/*
   25.80 -	int i, j;
   25.81 -	for(i=0; i<4; i++) {
   25.82 -		for(j=0; j<4; j++) {
   25.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];
   25.84 -		}
   25.85 -	}
   25.86 -	*/
   25.87 -
   25.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];
   25.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];
   25.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];
   25.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];
   25.92 -
   25.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];
   25.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];
   25.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];
   25.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];
   25.97 -
   25.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];
   25.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];
  25.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];
  25.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];
  25.102 -
  25.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];
  25.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];
  25.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];
  25.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];
  25.107 -
  25.108 -	m4_copy(res, tmp);
  25.109 -}
  25.110 -
  25.111 -static VMATH_INLINE void m4_set_column(mat4_t m, vec4_t v, int idx)
  25.112 -{
  25.113 -	m[0][idx] = v.x;
  25.114 -	m[1][idx] = v.y;
  25.115 -	m[2][idx] = v.z;
  25.116 -	m[3][idx] = v.w;
  25.117 -}
  25.118 -
  25.119 -static VMATH_INLINE void m4_set_row(mat4_t m, vec4_t v, int idx)
  25.120 -{
  25.121 -	m[idx][0] = v.x;
  25.122 -	m[idx][1] = v.y;
  25.123 -	m[idx][2] = v.z;
  25.124 -	m[idx][3] = v.w;
  25.125 -}
  25.126 -
  25.127 -#ifdef __cplusplus
  25.128 -}	/* extern "C" */
  25.129 -
  25.130 -
  25.131 -/* unrolled to hell and VMATH_INLINE */
  25.132 -VMATH_INLINE Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2)
  25.133 -{
  25.134 -	Matrix4x4 res;
  25.135 -
  25.136 -	/*
  25.137 -	for(i=0; i<4; i++) {
  25.138 -		for(j=0; j<4; j++) {
  25.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];
  25.140 -		}
  25.141 -	}
  25.142 -	*/
  25.143 -
  25.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];
  25.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];
  25.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];
  25.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];
  25.148 -
  25.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];
  25.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];
  25.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];
  25.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];
  25.153 -
  25.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];
  25.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];
  25.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];
  25.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];
  25.158 -
  25.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];
  25.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];
  25.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];
  25.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];
  25.163 -
  25.164 -	return res;
  25.165 -}
  25.166 -
  25.167 -VMATH_INLINE void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2)
  25.168 -{
  25.169 -	Matrix4x4 res = m1 * m2;
  25.170 -	m1 = res;
  25.171 -}
  25.172 -
  25.173 -
  25.174 -VMATH_INLINE scalar_t *Matrix3x3::operator [](int index)
  25.175 -{
  25.176 -	return m[index];
  25.177 -}
  25.178 -
  25.179 -VMATH_INLINE const scalar_t *Matrix3x3::operator [](int index) const
  25.180 -{
  25.181 -	return m[index];
  25.182 -}
  25.183 -
  25.184 -VMATH_INLINE void Matrix3x3::reset_identity()
  25.185 -{
  25.186 -	*this = identity;
  25.187 -}
  25.188 -
  25.189 -VMATH_INLINE scalar_t *Matrix4x4::operator [](int index)
  25.190 -{
  25.191 -	return m[index];
  25.192 -}
  25.193 -
  25.194 -VMATH_INLINE const scalar_t *Matrix4x4::operator [](int index) const
  25.195 -{
  25.196 -	return m[index];
  25.197 -}
  25.198 -
  25.199 -VMATH_INLINE void Matrix4x4::reset_identity()
  25.200 -{
  25.201 -	*this = identity;
  25.202 -}
  25.203 -#endif	/* __cplusplus */
    26.1 --- a/libs/vmath/matrix_c.c	Thu Jan 23 03:57:15 2014 +0200
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,292 +0,0 @@
    26.4 -/*
    26.5 -libvmath - a vector math library
    26.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    26.7 -
    26.8 -This program is free software: you can redistribute it and/or modify
    26.9 -it under the terms of the GNU Lesser General Public License as published
   26.10 -by the Free Software Foundation, either version 3 of the License, or
   26.11 -(at your option) any later version.
   26.12 -
   26.13 -This program is distributed in the hope that it will be useful,
   26.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26.16 -GNU Lesser General Public License for more details.
   26.17 -
   26.18 -You should have received a copy of the GNU Lesser General Public License
   26.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   26.20 -*/
   26.21 -
   26.22 -
   26.23 -#include <stdio.h>
   26.24 -#include "matrix.h"
   26.25 -#include "vector.h"
   26.26 -#include "quat.h"
   26.27 -
   26.28 -void m3_to_m4(mat4_t dest, mat3_t src)
   26.29 -{
   26.30 -	int i, j;
   26.31 -
   26.32 -	memset(dest, 0, sizeof(mat4_t));
   26.33 -	for(i=0; i<3; i++) {
   26.34 -		for(j=0; j<3; j++) {
   26.35 -			dest[i][j] = src[i][j];
   26.36 -		}
   26.37 -	}
   26.38 -	dest[3][3] = 1.0;
   26.39 -}
   26.40 -
   26.41 -void m3_print(FILE *fp, mat3_t m)
   26.42 -{
   26.43 -	int i;
   26.44 -	for(i=0; i<3; i++) {
   26.45 -		fprintf(fp, "[ %12.5f %12.5f %12.5f ]\n", (float)m[i][0], (float)m[i][1], (float)m[i][2]);
   26.46 -	}
   26.47 -}
   26.48 -
   26.49 -/* C matrix 4x4 functions */
   26.50 -void m4_to_m3(mat3_t dest, mat4_t src)
   26.51 -{
   26.52 -	int i, j;
   26.53 -	for(i=0; i<3; i++) {
   26.54 -		for(j=0; j<3; j++) {
   26.55 -			dest[i][j] = src[i][j];
   26.56 -		}
   26.57 -	}
   26.58 -}
   26.59 -
   26.60 -void m4_set_translation(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
   26.61 -{
   26.62 -	m4_identity(m);
   26.63 -	m[0][3] = x;
   26.64 -	m[1][3] = y;
   26.65 -	m[2][3] = z;
   26.66 -}
   26.67 -
   26.68 -void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
   26.69 -{
   26.70 -	mat4_t tm;
   26.71 -	m4_set_translation(tm, x, y, z);
   26.72 -	m4_mult(m, m, tm);
   26.73 -}
   26.74 -
   26.75 -void m4_rotate(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
   26.76 -{
   26.77 -	m4_rotate_x(m, x);
   26.78 -	m4_rotate_y(m, y);
   26.79 -	m4_rotate_z(m, z);
   26.80 -}
   26.81 -
   26.82 -void m4_set_rotation_x(mat4_t m, scalar_t angle)
   26.83 -{
   26.84 -	m4_identity(m);
   26.85 -	m[1][1] = cos(angle); m[1][2] = -sin(angle);
   26.86 -	m[2][1] = sin(angle); m[2][2] = cos(angle);
   26.87 -}
   26.88 -
   26.89 -void m4_rotate_x(mat4_t m, scalar_t angle)
   26.90 -{
   26.91 -	mat4_t rm;
   26.92 -	m4_set_rotation_x(m, angle);
   26.93 -	m4_mult(m, m, rm);
   26.94 -}
   26.95 -
   26.96 -void m4_set_rotation_y(mat4_t m, scalar_t angle)
   26.97 -{
   26.98 -	m4_identity(m);
   26.99 -	m[0][0] = cos(angle); m[0][2] = sin(angle);
  26.100 -	m[2][0] = -sin(angle); m[2][2] = cos(angle);
  26.101 -}
  26.102 -
  26.103 -void m4_rotate_y(mat4_t m, scalar_t angle)
  26.104 -{
  26.105 -	mat4_t rm;
  26.106 -	m4_set_rotation_y(rm, angle);
  26.107 -	m4_mult(m, m, rm);
  26.108 -}
  26.109 -
  26.110 -void m4_set_rotation_z(mat4_t m, scalar_t angle)
  26.111 -{
  26.112 -	m4_identity(m);
  26.113 -	m[0][0] = cos(angle); m[0][1] = -sin(angle);
  26.114 -	m[1][0] = sin(angle); m[1][1] = cos(angle);
  26.115 -}
  26.116 -
  26.117 -void m4_rotate_z(mat4_t m, scalar_t angle)
  26.118 -{
  26.119 -	mat4_t rm;
  26.120 -	m4_set_rotation_z(rm, angle);
  26.121 -	m4_mult(m, m, rm);
  26.122 -}
  26.123 -
  26.124 -void m4_set_rotation_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
  26.125 -{
  26.126 -	scalar_t sina = sin(angle);
  26.127 -	scalar_t cosa = cos(angle);
  26.128 -	scalar_t one_minus_cosa = 1.0 - cosa;
  26.129 -	scalar_t nxsq = x * x;
  26.130 -	scalar_t nysq = y * y;
  26.131 -	scalar_t nzsq = z * z;
  26.132 -
  26.133 -	m[0][0] = nxsq + (1.0 - nxsq) * cosa;
  26.134 -	m[0][1] = x * y * one_minus_cosa - z * sina;
  26.135 -	m[0][2] = x * z * one_minus_cosa + y * sina;
  26.136 -	m[1][0] = x * y * one_minus_cosa + z * sina;
  26.137 -	m[1][1] = nysq + (1.0 - nysq) * cosa;
  26.138 -	m[1][2] = y * z * one_minus_cosa - x * sina;
  26.139 -	m[2][0] = x * z * one_minus_cosa - y * sina;
  26.140 -	m[2][1] = y * z * one_minus_cosa + x * sina;
  26.141 -	m[2][2] = nzsq + (1.0 - nzsq) * cosa;
  26.142 -
  26.143 -	/* the rest are identity */
  26.144 -	m[3][0] = m[3][1] = m[3][2] = m[0][3] = m[1][3] = m[2][3] = 0.0;
  26.145 -	m[3][3] = 1.0;
  26.146 -}
  26.147 -
  26.148 -void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
  26.149 -{
  26.150 -	mat4_t xform;
  26.151 -	m4_set_rotation_axis(xform, angle, x, y, z);
  26.152 -	m4_mult(m, m, xform);
  26.153 -}
  26.154 -
  26.155 -void m4_rotate_quat(mat4_t m, quat_t q)
  26.156 -{
  26.157 -	mat4_t rm;
  26.158 -	quat_to_mat4(rm, q);
  26.159 -	m4_mult(m, m, rm);
  26.160 -}
  26.161 -
  26.162 -void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
  26.163 -{
  26.164 -	mat4_t sm;
  26.165 -	m4_identity(sm);
  26.166 -	sm[0][0] = x;
  26.167 -	sm[1][1] = y;
  26.168 -	sm[2][2] = z;
  26.169 -	m4_mult(m, m, sm);
  26.170 -}
  26.171 -
  26.172 -void m4_transpose(mat4_t res, mat4_t m)
  26.173 -{
  26.174 -	int i, j;
  26.175 -	mat4_t tmp;
  26.176 -	m4_copy(tmp, m);
  26.177 -
  26.178 -	for(i=0; i<4; i++) {
  26.179 -		for(j=0; j<4; j++) {
  26.180 -			res[i][j] = tmp[j][i];
  26.181 -		}
  26.182 -	}
  26.183 -}
  26.184 -
  26.185 -scalar_t m4_determinant(mat4_t m)
  26.186 -{
  26.187 -	scalar_t det11 =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  26.188 -						(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  26.189 -						(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  26.190 -
  26.191 -	scalar_t det12 =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  26.192 -						(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  26.193 -						(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  26.194 -
  26.195 -	scalar_t det13 =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  26.196 -						(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  26.197 -						(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  26.198 -
  26.199 -	scalar_t det14 =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  26.200 -						(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  26.201 -						(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  26.202 -
  26.203 -	return m[0][0] * det11 - m[0][1] * det12 + m[0][2] * det13 - m[0][3] * det14;
  26.204 -}
  26.205 -
  26.206 -void m4_adjoint(mat4_t res, mat4_t m)
  26.207 -{
  26.208 -	int i, j;
  26.209 -	mat4_t coef;
  26.210 -
  26.211 -	coef[0][0] =	(m[1][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  26.212 -					(m[1][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  26.213 -					(m[1][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  26.214 -	coef[0][1] =	(m[1][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  26.215 -					(m[1][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  26.216 -					(m[1][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  26.217 -	coef[0][2] =	(m[1][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  26.218 -					(m[1][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  26.219 -					(m[1][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  26.220 -	coef[0][3] =	(m[1][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  26.221 -					(m[1][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  26.222 -					(m[1][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  26.223 -
  26.224 -	coef[1][0] =	(m[0][1] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  26.225 -					(m[0][2] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) +
  26.226 -					(m[0][3] * (m[2][1] * m[3][2] - m[3][1] * m[2][2]));
  26.227 -	coef[1][1] =	(m[0][0] * (m[2][2] * m[3][3] - m[3][2] * m[2][3])) -
  26.228 -					(m[0][2] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  26.229 -					(m[0][3] * (m[2][0] * m[3][2] - m[3][0] * m[2][2]));
  26.230 -	coef[1][2] =	(m[0][0] * (m[2][1] * m[3][3] - m[3][1] * m[2][3])) -
  26.231 -					(m[0][1] * (m[2][0] * m[3][3] - m[3][0] * m[2][3])) +
  26.232 -					(m[0][3] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  26.233 -	coef[1][3] =	(m[0][0] * (m[2][1] * m[3][2] - m[3][1] * m[2][2])) -
  26.234 -					(m[0][1] * (m[2][0] * m[3][2] - m[3][0] * m[2][2])) +
  26.235 -					(m[0][2] * (m[2][0] * m[3][1] - m[3][0] * m[2][1]));
  26.236 -
  26.237 -	coef[2][0] =	(m[0][1] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  26.238 -					(m[0][2] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) +
  26.239 -					(m[0][3] * (m[1][1] * m[3][2] - m[3][1] * m[1][2]));
  26.240 -	coef[2][1] =	(m[0][0] * (m[1][2] * m[3][3] - m[3][2] * m[1][3])) -
  26.241 -					(m[0][2] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  26.242 -					(m[0][3] * (m[1][0] * m[3][2] - m[3][0] * m[1][2]));
  26.243 -	coef[2][2] =	(m[0][0] * (m[1][1] * m[3][3] - m[3][1] * m[1][3])) -
  26.244 -					(m[0][1] * (m[1][0] * m[3][3] - m[3][0] * m[1][3])) +
  26.245 -					(m[0][3] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  26.246 -	coef[2][3] =	(m[0][0] * (m[1][1] * m[3][2] - m[3][1] * m[1][2])) -
  26.247 -					(m[0][1] * (m[1][0] * m[3][2] - m[3][0] * m[1][2])) +
  26.248 -					(m[0][2] * (m[1][0] * m[3][1] - m[3][0] * m[1][1]));
  26.249 -
  26.250 -	coef[3][0] =	(m[0][1] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  26.251 -					(m[0][2] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) +
  26.252 -					(m[0][3] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]));
  26.253 -	coef[3][1] =	(m[0][0] * (m[1][2] * m[2][3] - m[2][2] * m[1][3])) -
  26.254 -					(m[0][2] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  26.255 -					(m[0][3] * (m[1][0] * m[2][2] - m[2][0] * m[1][2]));
  26.256 -	coef[3][2] =	(m[0][0] * (m[1][1] * m[2][3] - m[2][1] * m[1][3])) -
  26.257 -					(m[0][1] * (m[1][0] * m[2][3] - m[2][0] * m[1][3])) +
  26.258 -					(m[0][3] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  26.259 -	coef[3][3] =	(m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])) -
  26.260 -					(m[0][1] * (m[1][0] * m[2][2] - m[2][0] * m[1][2])) +
  26.261 -					(m[0][2] * (m[1][0] * m[2][1] - m[2][0] * m[1][1]));
  26.262 -
  26.263 -	m4_transpose(res, coef);
  26.264 -
  26.265 -	for(i=0; i<4; i++) {
  26.266 -		for(j=0; j<4; j++) {
  26.267 -			res[i][j] = j % 2 ? -res[i][j] : res[i][j];
  26.268 -			if(i % 2) res[i][j] = -res[i][j];
  26.269 -		}
  26.270 -	}
  26.271 -}
  26.272 -
  26.273 -void m4_inverse(mat4_t res, mat4_t m)
  26.274 -{
  26.275 -	int i, j;
  26.276 -	mat4_t adj;
  26.277 -	scalar_t det;
  26.278 -
  26.279 -	m4_adjoint(adj, m);
  26.280 -	det = m4_determinant(m);
  26.281 -	
  26.282 -	for(i=0; i<4; i++) {
  26.283 -		for(j=0; j<4; j++) {
  26.284 -			res[i][j] = adj[i][j] / det;
  26.285 -		}
  26.286 -	}
  26.287 -}
  26.288 -
  26.289 -void m4_print(FILE *fp, mat4_t m)
  26.290 -{
  26.291 -	int i;
  26.292 -	for(i=0; i<4; i++) {
  26.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]);
  26.294 -	}
  26.295 -}
    27.1 --- a/libs/vmath/quat.cc	Thu Jan 23 03:57:15 2014 +0200
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,212 +0,0 @@
    27.4 -#include "quat.h"
    27.5 -#include "vmath.h"
    27.6 -
    27.7 -Quaternion::Quaternion()
    27.8 -{
    27.9 -	s = 1.0;
   27.10 -	v.x = v.y = v.z = 0.0;
   27.11 -}
   27.12 -
   27.13 -Quaternion::Quaternion(scalar_t s, const Vector3 &v)
   27.14 -{
   27.15 -	this->s = s;
   27.16 -	this->v = v;
   27.17 -}
   27.18 -
   27.19 -Quaternion::Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z)
   27.20 -{
   27.21 -	v.x = x;
   27.22 -	v.y = y;
   27.23 -	v.z = z;
   27.24 -	this->s = s;
   27.25 -}
   27.26 -
   27.27 -Quaternion::Quaternion(const Vector3 &axis, scalar_t angle)
   27.28 -{
   27.29 -	set_rotation(axis, angle);
   27.30 -}
   27.31 -
   27.32 -Quaternion::Quaternion(const quat_t &quat)
   27.33 -{
   27.34 -	v.x = quat.x;
   27.35 -	v.y = quat.y;
   27.36 -	v.z = quat.z;
   27.37 -	s = quat.w;
   27.38 -}
   27.39 -
   27.40 -Quaternion Quaternion::operator +(const Quaternion &quat) const
   27.41 -{
   27.42 -	return Quaternion(s + quat.s, v + quat.v);
   27.43 -}
   27.44 -
   27.45 -Quaternion Quaternion::operator -(const Quaternion &quat) const
   27.46 -{
   27.47 -	return Quaternion(s - quat.s, v - quat.v);
   27.48 -}
   27.49 -
   27.50 -Quaternion Quaternion::operator -() const
   27.51 -{
   27.52 -	return Quaternion(-s, -v);
   27.53 -}
   27.54 -
   27.55 -/** Quaternion Multiplication:
   27.56 - * Q1*Q2 = [s1*s2 - v1.v2,  s1*v2 + s2*v1 + v1(x)v2]
   27.57 - */
   27.58 -Quaternion Quaternion::operator *(const Quaternion &quat) const
   27.59 -{
   27.60 -	Quaternion newq;
   27.61 -	newq.s = s * quat.s - dot_product(v, quat.v);
   27.62 -	newq.v = quat.v * s + v * quat.s + cross_product(v, quat.v);
   27.63 -	return newq;
   27.64 -}
   27.65 -
   27.66 -void Quaternion::operator +=(const Quaternion &quat)
   27.67 -{
   27.68 -	*this = Quaternion(s + quat.s, v + quat.v);
   27.69 -}
   27.70 -
   27.71 -void Quaternion::operator -=(const Quaternion &quat)
   27.72 -{
   27.73 -	*this = Quaternion(s - quat.s, v - quat.v);
   27.74 -}
   27.75 -
   27.76 -void Quaternion::operator *=(const Quaternion &quat)
   27.77 -{
   27.78 -	*this = *this * quat;
   27.79 -}
   27.80 -
   27.81 -void Quaternion::reset_identity()
   27.82 -{
   27.83 -	s = 1.0;
   27.84 -	v.x = v.y = v.z = 0.0;
   27.85 -}
   27.86 -
   27.87 -Quaternion Quaternion::conjugate() const
   27.88 -{
   27.89 -	return Quaternion(s, -v);
   27.90 -}
   27.91 -
   27.92 -scalar_t Quaternion::length() const
   27.93 -{
   27.94 -	return (scalar_t)sqrt(v.x*v.x + v.y*v.y + v.z*v.z + s*s);
   27.95 -}
   27.96 -
   27.97 -/** Q * ~Q = ||Q||^2 */
   27.98 -scalar_t Quaternion::length_sq() const
   27.99 -{
  27.100 -	return v.x*v.x + v.y*v.y + v.z*v.z + s*s;
  27.101 -}
  27.102 -
  27.103 -void Quaternion::normalize()
  27.104 -{
  27.105 -	scalar_t len = (scalar_t)sqrt(v.x*v.x + v.y*v.y + v.z*v.z + s*s);
  27.106 -	v.x /= len;
  27.107 -	v.y /= len;
  27.108 -	v.z /= len;
  27.109 -	s /= len;
  27.110 -}
  27.111 -
  27.112 -Quaternion Quaternion::normalized() const
  27.113 -{
  27.114 -	Quaternion nq = *this;
  27.115 -	scalar_t len = (scalar_t)sqrt(v.x*v.x + v.y*v.y + v.z*v.z + s*s);
  27.116 -	nq.v.x /= len;
  27.117 -	nq.v.y /= len;
  27.118 -	nq.v.z /= len;
  27.119 -	nq.s /= len;
  27.120 -	return nq;
  27.121 -}
  27.122 -
  27.123 -/** Quaternion Inversion: Q^-1 = ~Q / ||Q||^2 */
  27.124 -Quaternion Quaternion::inverse() const
  27.125 -{
  27.126 -	Quaternion inv = conjugate();
  27.127 -	scalar_t lensq = length_sq();
  27.128 -	inv.v /= lensq;
  27.129 -	inv.s /= lensq;
  27.130 -
  27.131 -	return inv;
  27.132 -}
  27.133 -
  27.134 -
  27.135 -void Quaternion::set_rotation(const Vector3 &axis, scalar_t angle)
  27.136 -{
  27.137 -	scalar_t half_angle = angle / 2.0;
  27.138 -	s = cos(half_angle);
  27.139 -	v = axis * sin(half_angle);
  27.140 -}
  27.141 -
  27.142 -void Quaternion::rotate(const Vector3 &axis, scalar_t angle)
  27.143 -{
  27.144 -	Quaternion q;
  27.145 -	scalar_t half_angle = angle / 2.0;
  27.146 -	q.s = cos(half_angle);
  27.147 -	q.v = axis * sin(half_angle);
  27.148 -
  27.149 -	*this *= q;
  27.150 -}
  27.151 -
  27.152 -void Quaternion::rotate(const Quaternion &q)
  27.153 -{
  27.154 -	*this = q * *this * q.conjugate();
  27.155 -}
  27.156 -
  27.157 -Matrix3x3 Quaternion::get_rotation_matrix() const
  27.158 -{
  27.159 -	return Matrix3x3(
  27.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,
  27.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,
  27.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);
  27.163 -}
  27.164 -
  27.165 -
  27.166 -/** Spherical linear interpolation (slerp) */
  27.167 -Quaternion slerp(const Quaternion &quat1, const Quaternion &q2, scalar_t t)
  27.168 -{
  27.169 -	Quaternion q1;
  27.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;
  27.171 -
  27.172 -	if(dot < 0.0) {
  27.173 -		/* make sure we interpolate across the shortest arc */
  27.174 -		q1 = -quat1;
  27.175 -		dot = -dot;
  27.176 -	} else {
  27.177 -		q1 = quat1;
  27.178 -	}
  27.179 -
  27.180 -	/* clamp dot to [-1, 1] in order to avoid domain errors in acos due to
  27.181 -	 * floating point imprecisions
  27.182 -	 */
  27.183 -	if(dot < -1.0) dot = -1.0;
  27.184 -	if(dot > 1.0) dot = 1.0;
  27.185 -
  27.186 -	scalar_t angle = acos(dot);
  27.187 -	scalar_t a, b;
  27.188 -
  27.189 -	scalar_t sin_angle = sin(angle);
  27.190 -	if(fabs(sin_angle) < SMALL_NUMBER) {
  27.191 -		/* for very small angles or completely opposite orientations
  27.192 -		 * use linear interpolation to avoid div/zero (in the first case it makes sense,
  27.193 -		 * the second case is pretty much undefined anyway I guess ...
  27.194 -		 */
  27.195 -		a = 1.0f - t;
  27.196 -		b = t;
  27.197 -	} else {
  27.198 -		a = sin((1.0f - t) * angle) / sin_angle;
  27.199 -		b = sin(t * angle) / sin_angle;
  27.200 -	}
  27.201 -
  27.202 -	scalar_t x = q1.v.x * a + q2.v.x * b;
  27.203 -	scalar_t y = q1.v.y * a + q2.v.y * b;
  27.204 -	scalar_t z = q1.v.z * a + q2.v.z * b;
  27.205 -	scalar_t s = q1.s * a + q2.s * b;
  27.206 -
  27.207 -	return Quaternion(s, Vector3(x, y, z));
  27.208 -}
  27.209 -
  27.210 -
  27.211 -std::ostream &operator <<(std::ostream &out, const Quaternion &q)
  27.212 -{
  27.213 -	out << "(" << q.s << ", " << q.v << ")";
  27.214 -	return out;
  27.215 -}
    28.1 --- a/libs/vmath/quat.h	Thu Jan 23 03:57:15 2014 +0200
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,118 +0,0 @@
    28.4 -/*
    28.5 -libvmath - a vector math library
    28.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    28.7 -
    28.8 -This program is free software: you can redistribute it and/or modify
    28.9 -it under the terms of the GNU Lesser General Public License as published
   28.10 -by the Free Software Foundation, either version 3 of the License, or
   28.11 -(at your option) any later version.
   28.12 -
   28.13 -This program is distributed in the hope that it will be useful,
   28.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   28.16 -GNU Lesser General Public License for more details.
   28.17 -
   28.18 -You should have received a copy of the GNU Lesser General Public License
   28.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   28.20 -*/
   28.21 -
   28.22 -#ifndef VMATH_QUATERNION_H_
   28.23 -#define VMATH_QUATERNION_H_
   28.24 -
   28.25 -#include <stdio.h>
   28.26 -#include "vmath_types.h"
   28.27 -#include "vector.h"
   28.28 -
   28.29 -#ifdef __cplusplus
   28.30 -extern "C" {
   28.31 -#endif	/* __cplusplus */
   28.32 -
   28.33 -#define quat_cons(s, x, y, z)	v4_cons(x, y, z, s)
   28.34 -#define quat_vec(q)				v3_cons((q).x, (q).y, (q).z)
   28.35 -#define quat_s(q)				((q).w)
   28.36 -#define quat_identity()			quat_cons(1.0, 0.0, 0.0, 0.0)
   28.37 -void quat_print(FILE *fp, quat_t q);
   28.38 -
   28.39 -#define quat_add		v4_add
   28.40 -#define quat_sub		v4_sub
   28.41 -#define quat_neg		v4_neg
   28.42 -
   28.43 -static VMATH_INLINE quat_t quat_mul(quat_t q1, quat_t q2);
   28.44 -
   28.45 -static VMATH_INLINE quat_t quat_conjugate(quat_t q);
   28.46 -
   28.47 -#define quat_length		v4_length
   28.48 -#define quat_length_sq	v4_length_sq
   28.49 -
   28.50 -#define quat_normalize	v4_normalize
   28.51 -static VMATH_INLINE quat_t quat_inverse(quat_t q);
   28.52 -
   28.53 -quat_t quat_rotate(quat_t q, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   28.54 -quat_t quat_rotate_quat(quat_t q, quat_t rotq);
   28.55 -
   28.56 -static VMATH_INLINE void quat_to_mat3(mat3_t res, quat_t q);
   28.57 -static VMATH_INLINE void quat_to_mat4(mat4_t res, quat_t q);
   28.58 -
   28.59 -#define quat_lerp quat_slerp
   28.60 -quat_t quat_slerp(quat_t q1, quat_t q2, scalar_t t);
   28.61 -
   28.62 -
   28.63 -#ifdef __cplusplus
   28.64 -}	/* extern "C" */
   28.65 -
   28.66 -#include <iostream>
   28.67 -
   28.68 -/* Quaternion */
   28.69 -class Quaternion {
   28.70 -public:
   28.71 -	scalar_t s;
   28.72 -	Vector3 v;
   28.73 -
   28.74 -	Quaternion();
   28.75 -	Quaternion(scalar_t s, const Vector3 &v);
   28.76 -	Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z);
   28.77 -	Quaternion(const Vector3 &axis, scalar_t angle);
   28.78 -	Quaternion(const quat_t &quat);
   28.79 -
   28.80 -	Quaternion operator +(const Quaternion &quat) const;
   28.81 -	Quaternion operator -(const Quaternion &quat) const;
   28.82 -	Quaternion operator -() const;
   28.83 -	Quaternion operator *(const Quaternion &quat) const;
   28.84 -
   28.85 -	void operator +=(const Quaternion &quat);
   28.86 -	void operator -=(const Quaternion &quat);
   28.87 -	void operator *=(const Quaternion &quat);
   28.88 -
   28.89 -	void reset_identity();
   28.90 -
   28.91 -	Quaternion conjugate() const;
   28.92 -
   28.93 -	scalar_t length() const;
   28.94 -	scalar_t length_sq() const;
   28.95 -
   28.96 -	void normalize();
   28.97 -	Quaternion normalized() const;
   28.98 -
   28.99 -	Quaternion inverse() const;
  28.100 -
  28.101 -	void set_rotation(const Vector3 &axis, scalar_t angle);
  28.102 -	void rotate(const Vector3 &axis, scalar_t angle);
  28.103 -	/* note: this is a totally different operation from the above
  28.104 -	 * this treats the quaternion as signifying direction and rotates
  28.105 -	 * it by a rotation quaternion by rot * q * rot'
  28.106 -	 */
  28.107 -	void rotate(const Quaternion &q);
  28.108 -
  28.109 -	Matrix3x3 get_rotation_matrix() const;
  28.110 -};
  28.111 -
  28.112 -Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
  28.113 -VMATH_INLINE Quaternion lerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
  28.114 -
  28.115 -std::ostream &operator <<(std::ostream &out, const Quaternion &q);
  28.116 -
  28.117 -#endif	/* __cplusplus */
  28.118 -
  28.119 -#include "quat.inl"
  28.120 -
  28.121 -#endif	/* VMATH_QUATERNION_H_ */
    29.1 --- a/libs/vmath/quat.inl	Thu Jan 23 03:57:15 2014 +0200
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,81 +0,0 @@
    29.4 -/*
    29.5 -libvmath - a vector math library
    29.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    29.7 -
    29.8 -This program is free software: you can redistribute it and/or modify
    29.9 -it under the terms of the GNU Lesser General Public License as published
   29.10 -by the Free Software Foundation, either version 3 of the License, or
   29.11 -(at your option) any later version.
   29.12 -
   29.13 -This program is distributed in the hope that it will be useful,
   29.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   29.16 -GNU Lesser General Public License for more details.
   29.17 -
   29.18 -You should have received a copy of the GNU Lesser General Public License
   29.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   29.20 -*/
   29.21 -
   29.22 -#include "vector.h"
   29.23 -#include "matrix.h"
   29.24 -
   29.25 -#ifdef __cplusplus
   29.26 -extern "C" {
   29.27 -#endif	/* __cplusplus */
   29.28 -
   29.29 -static VMATH_INLINE quat_t quat_mul(quat_t q1, quat_t q2)
   29.30 -{
   29.31 -	quat_t res;
   29.32 -	vec3_t v1 = quat_vec(q1);
   29.33 -	vec3_t v2 = quat_vec(q2);
   29.34 -
   29.35 -	res.w = q1.w * q2.w - v3_dot(v1, v2);
   29.36 -	/* resvec = v2 * q1 + v1 * q2 + cross(v1, v2) */
   29.37 -	res.x = v2.x * q1.w + v1.x * q2.w + (v1.y * v2.z - v1.z * v2.y);
   29.38 -	res.y = v2.y * q1.w + v1.y * q2.w + (v1.z * v2.x - v1.x * v2.z);
   29.39 -	res.z = v2.z * q1.w + v1.z * q2.w + (v1.x * v2.y - v1.y * v2.x);
   29.40 -	return res;
   29.41 -}
   29.42 -
   29.43 -static VMATH_INLINE quat_t quat_conjugate(quat_t q)
   29.44 -{
   29.45 -	q.x = -q.x;
   29.46 -	q.y = -q.y;
   29.47 -	q.z = -q.z;
   29.48 -	return q;
   29.49 -}
   29.50 -
   29.51 -static VMATH_INLINE quat_t quat_inverse(quat_t q)
   29.52 -{
   29.53 -	scalar_t lensq = quat_length_sq(q);
   29.54 -	q = quat_conjugate(q);
   29.55 -	q.x /= lensq;
   29.56 -	q.y /= lensq;
   29.57 -	q.z /= lensq;
   29.58 -	q.w /= lensq;
   29.59 -	return q;
   29.60 -}
   29.61 -
   29.62 -static VMATH_INLINE void quat_to_mat3(mat3_t res, quat_t q)
   29.63 -{
   29.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,
   29.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,
   29.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);
   29.67 -}
   29.68 -
   29.69 -static VMATH_INLINE void quat_to_mat4(mat4_t res, quat_t q)
   29.70 -{
   29.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,
   29.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,
   29.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,
   29.74 -				 0, 0, 0, 1);
   29.75 -}
   29.76 -
   29.77 -#ifdef __cplusplus
   29.78 -}	/* extern "C" */
   29.79 -
   29.80 -VMATH_INLINE Quaternion lerp(const Quaternion &a, const Quaternion &b, scalar_t t)
   29.81 -{
   29.82 -	return slerp(a, b, t);
   29.83 -}
   29.84 -#endif	/* __cplusplus */
    30.1 --- a/libs/vmath/quat_c.c	Thu Jan 23 03:57:15 2014 +0200
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,89 +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 -
   30.23 -#include <stdio.h>
   30.24 -#include <math.h>
   30.25 -#include "quat.h"
   30.26 -
   30.27 -void quat_print(FILE *fp, quat_t q)
   30.28 -{
   30.29 -	fprintf(fp, "([ %.4f %.4f %.4f ] %.4f)", q.x, q.y, q.z, q.w);
   30.30 -}
   30.31 -
   30.32 -quat_t quat_rotate(quat_t q, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
   30.33 -{
   30.34 -	quat_t rq;
   30.35 -	scalar_t half_angle = angle * 0.5;
   30.36 -	scalar_t sin_half = sin(half_angle);
   30.37 -
   30.38 -	rq.w = cos(half_angle);
   30.39 -	rq.x = x * sin_half;
   30.40 -	rq.y = y * sin_half;
   30.41 -	rq.z = z * sin_half;
   30.42 -
   30.43 -	return quat_mul(q, rq);
   30.44 -}
   30.45 -
   30.46 -quat_t quat_rotate_quat(quat_t q, quat_t rotq)
   30.47 -{
   30.48 -	return quat_mul(quat_mul(rotq, q), quat_conjugate(rotq));
   30.49 -}
   30.50 -
   30.51 -quat_t quat_slerp(quat_t q1, quat_t q2, scalar_t t)
   30.52 -{
   30.53 -	quat_t res;
   30.54 -	scalar_t a, b, angle, sin_angle, dot;
   30.55 -
   30.56 -	dot = q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z;
   30.57 -	if(dot < 0.0) {
   30.58 -		/* make sure we interpolate across the shortest arc */
   30.59 -		q1.x = -q1.x;
   30.60 -		q1.y = -q1.y;
   30.61 -		q1.z = -q1.z;
   30.62 -		q1.w = -q1.w;
   30.63 -		dot = -dot;
   30.64 -	}
   30.65 -
   30.66 -	/* clamp dot to [-1, 1] in order to avoid domain errors in acos due to
   30.67 -	 * floating point imprecisions
   30.68 -	 */
   30.69 -	if(dot < -1.0) dot = -1.0;
   30.70 -	if(dot > 1.0) dot = 1.0;
   30.71 -
   30.72 -	angle = acos(dot);
   30.73 -	sin_angle = sin(angle);
   30.74 -
   30.75 -	if(fabs(sin_angle) < SMALL_NUMBER) {
   30.76 -		/* for very small angles or completely opposite orientations
   30.77 -		 * use linear interpolation to avoid div/zero (in the first case it makes sense,
   30.78 -		 * the second case is pretty much undefined anyway I guess ...
   30.79 -		 */
   30.80 -		a = 1.0f - t;
   30.81 -		b = t;
   30.82 -	} else {
   30.83 -		a = sin((1.0f - t) * angle) / sin_angle;
   30.84 -		b = sin(t * angle) / sin_angle;
   30.85 -	}
   30.86 -
   30.87 -	res.x = q1.x * a + q2.x * b;
   30.88 -	res.y = q1.y * a + q2.y * b;
   30.89 -	res.z = q1.z * a + q2.z * b;
   30.90 -	res.w = q1.w * a + q2.w * b;
   30.91 -	return res;
   30.92 -}
    31.1 --- a/libs/vmath/ray.cc	Thu Jan 23 03:57:15 2014 +0200
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,39 +0,0 @@
    31.4 -#include "ray.h"
    31.5 -#include "vector.h"
    31.6 -
    31.7 -scalar_t Ray::env_ior = 1.0;
    31.8 -
    31.9 -Ray::Ray()
   31.10 -{
   31.11 -	ior = env_ior;
   31.12 -	energy = 1.0;
   31.13 -	time = 0;
   31.14 -	iter = 0;
   31.15 -}
   31.16 -
   31.17 -Ray::Ray(const Vector3 &origin, const Vector3 &dir)
   31.18 -{
   31.19 -	this->origin = origin;
   31.20 -	this->dir = dir;
   31.21 -	ior = env_ior;
   31.22 -	energy = 1.0;
   31.23 -	time = 0;
   31.24 -	iter = 0;
   31.25 -}
   31.26 -
   31.27 -void Ray::transform(const Matrix4x4 &xform)
   31.28 -{
   31.29 -	Matrix4x4 upper = xform;
   31.30 -	upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
   31.31 -	upper[3][3] = 1.0;
   31.32 -
   31.33 -	dir.transform(upper);
   31.34 -	origin.transform(xform);
   31.35 -}
   31.36 -
   31.37 -Ray Ray::transformed(const Matrix4x4 &xform) const
   31.38 -{
   31.39 -	Ray foo = *this;
   31.40 -	foo.transform(xform);
   31.41 -	return foo;
   31.42 -}
    32.1 --- a/libs/vmath/ray.h	Thu Jan 23 03:57:15 2014 +0200
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,64 +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 -#ifndef VMATH_RAY_H_
   32.23 -#define VMATH_RAY_H_
   32.24 -
   32.25 -#include "matrix.h"
   32.26 -#include "vector.h"
   32.27 -
   32.28 -typedef struct {
   32.29 -	vec3_t origin, dir;
   32.30 -} ray_t;
   32.31 -
   32.32 -#ifdef __cplusplus
   32.33 -extern "C" {
   32.34 -#endif	/* __cplusplus */
   32.35 -
   32.36 -static VMATH_INLINE ray_t ray_cons(vec3_t origin, vec3_t dir);
   32.37 -ray_t ray_transform(ray_t r, mat4_t m);
   32.38 -
   32.39 -#ifdef __cplusplus
   32.40 -}	/* __cplusplus */
   32.41 -
   32.42 -#include <stack>
   32.43 -
   32.44 -class Ray {
   32.45 -public:
   32.46 -	static scalar_t env_ior;
   32.47 -
   32.48 -	Vector3 origin, dir;
   32.49 -	scalar_t energy;
   32.50 -	int iter;
   32.51 -	scalar_t ior;
   32.52 -	long time;
   32.53 -
   32.54 -	Ray();
   32.55 -	Ray(const Vector3 &origin, const Vector3 &dir);
   32.56 -
   32.57 -	void transform(const Matrix4x4 &xform);
   32.58 -	Ray transformed(const Matrix4x4 &xform) const;
   32.59 -};
   32.60 -
   32.61 -VMATH_INLINE Ray reflect_ray(const Ray &inray, const Vector3 &norm);
   32.62 -VMATH_INLINE Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t from_ior, scalar_t to_ior);
   32.63 -#endif	/* __cplusplus */
   32.64 -
   32.65 -#include "ray.inl"
   32.66 -
   32.67 -#endif	/* VMATH_RAY_H_ */
    33.1 --- a/libs/vmath/ray.inl	Thu Jan 23 03:57:15 2014 +0200
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,52 +0,0 @@
    33.4 -/*
    33.5 -libvmath - a vector math library
    33.6 -Copyright (C) 2004-2011 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 -
   33.22 -#ifdef __cplusplus
   33.23 -extern "C" {
   33.24 -#endif	/* __cplusplus */
   33.25 -
   33.26 -static VMATH_INLINE ray_t ray_cons(vec3_t origin, vec3_t dir)
   33.27 -{
   33.28 -	ray_t r;
   33.29 -	r.origin = origin;
   33.30 -	r.dir = dir;
   33.31 -	return r;
   33.32 -}
   33.33 -
   33.34 -#ifdef __cplusplus
   33.35 -}
   33.36 -
   33.37 -VMATH_INLINE Ray reflect_ray(const Ray &inray, const Vector3 &norm)
   33.38 -{
   33.39 -	Ray ray = inray;
   33.40 -	ray.dir = ray.dir.reflection(norm);
   33.41 -	return ray;
   33.42 -}
   33.43 -
   33.44 -VMATH_INLINE Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t from_ior, scalar_t to_ior)
   33.45 -{
   33.46 -	Ray ray = inray;
   33.47 -	ray.dir = ray.dir.refraction(norm, from_ior, to_ior);
   33.48 -
   33.49 -	/* check TIR */
   33.50 -	if(dot_product(ray.dir, norm) > 0.0) {
   33.51 -		return reflect_ray(inray, norm);
   33.52 -	}
   33.53 -	return ray;
   33.54 -}
   33.55 -#endif	/* __cplusplus */
    34.1 --- a/libs/vmath/ray_c.c	Thu Jan 23 03:57:15 2014 +0200
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,36 +0,0 @@
    34.4 -/*
    34.5 -libvmath - a vector math library
    34.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    34.7 -
    34.8 -This program is free software: you can redistribute it and/or modify
    34.9 -it under the terms of the GNU Lesser General Public License as published
   34.10 -by the Free Software Foundation, either version 3 of the License, or
   34.11 -(at your option) any later version.
   34.12 -
   34.13 -This program is distributed in the hope that it will be useful,
   34.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   34.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   34.16 -GNU Lesser General Public License for more details.
   34.17 -
   34.18 -You should have received a copy of the GNU Lesser General Public License
   34.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   34.20 -*/
   34.21 -
   34.22 -#include "ray.h"
   34.23 -#include "vector.h"
   34.24 -
   34.25 -ray_t ray_transform(ray_t r, mat4_t xform)
   34.26 -{
   34.27 -	mat4_t upper;
   34.28 -	vec3_t dir;
   34.29 -
   34.30 -	m4_copy(upper, xform);
   34.31 -	upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
   34.32 -	upper[3][3] = 1.0;
   34.33 -
   34.34 -	dir = v3_sub(r.dir, r.origin);
   34.35 -	dir = v3_transform(dir, upper);
   34.36 -	r.origin = v3_transform(r.origin, xform);
   34.37 -	r.dir = v3_add(dir, r.origin);
   34.38 -	return r;
   34.39 -}
    35.1 --- a/libs/vmath/sphvec.cc	Thu Jan 23 03:57:15 2014 +0200
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,27 +0,0 @@
    35.4 -#include "sphvec.h"
    35.5 -#include "vector.h"
    35.6 -
    35.7 -/* theta: 0 <= theta <= 2pi, the angle around Y axis.
    35.8 - * phi: 0 <= phi <= pi, the angle from Y axis.
    35.9 - * r: radius.
   35.10 - */
   35.11 -SphVector::SphVector(scalar_t theta, scalar_t phi, scalar_t r) {
   35.12 -	this->theta = theta;
   35.13 -	this->phi = phi;
   35.14 -	this->r = r;
   35.15 -}
   35.16 -
   35.17 -/* Constructs a spherical coordinate vector from a cartesian vector */
   35.18 -SphVector::SphVector(const Vector3 &cvec) {
   35.19 -	*this = cvec;
   35.20 -}
   35.21 -
   35.22 -/* Assignment operator that converts cartesian to spherical coords */
   35.23 -SphVector &SphVector::operator =(const Vector3 &cvec) {
   35.24 -	r = cvec.length();
   35.25 -	//theta = atan2(cvec.y, cvec.x);
   35.26 -	theta = atan2(cvec.z, cvec.x);
   35.27 -	//phi = acos(cvec.z / r);
   35.28 -	phi = acos(cvec.y / r);
   35.29 -	return *this;
   35.30 -}
    36.1 --- a/libs/vmath/sphvec.h	Thu Jan 23 03:57:15 2014 +0200
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,36 +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 -#ifndef VMATH_SPHVEC_H_
   36.23 -#define VMATH_SPHVEC_H_
   36.24 -
   36.25 -#include "vmath_types.h"
   36.26 -
   36.27 -#ifdef __cplusplus
   36.28 -/* Vector in spherical coordinates */
   36.29 -class SphVector {
   36.30 -public:
   36.31 -	scalar_t theta, phi, r;
   36.32 -
   36.33 -	SphVector(scalar_t theta = 0.0, scalar_t phi = 0.0, scalar_t r = 1.0);
   36.34 -	SphVector(const Vector3 &cvec);
   36.35 -	SphVector &operator =(const Vector3 &cvec);
   36.36 -};
   36.37 -#endif	/* __cplusplus */
   36.38 -
   36.39 -#endif	/* VMATH_SPHVEC_H_ */
    37.1 --- a/libs/vmath/vector.cc	Thu Jan 23 03:57:15 2014 +0200
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,326 +0,0 @@
    37.4 -#include "vector.h"
    37.5 -#include "vmath.h"
    37.6 -
    37.7 -// ---------- Vector2 -----------
    37.8 -
    37.9 -Vector2::Vector2(scalar_t x, scalar_t y)
   37.10 -{
   37.11 -	this->x = x;
   37.12 -	this->y = y;
   37.13 -}
   37.14 -
   37.15 -Vector2::Vector2(const vec2_t &vec)
   37.16 -{
   37.17 -	x = vec.x;
   37.18 -	y = vec.y;
   37.19 -}
   37.20 -
   37.21 -Vector2::Vector2(const Vector3 &vec)
   37.22 -{
   37.23 -	x = vec.x;
   37.24 -	y = vec.y;
   37.25 -}
   37.26 -
   37.27 -Vector2::Vector2(const Vector4 &vec)
   37.28 -{
   37.29 -	x = vec.x;
   37.30 -	y = vec.y;
   37.31 -}
   37.32 -
   37.33 -void Vector2::normalize()
   37.34 -{
   37.35 -	scalar_t len = length();
   37.36 -	x /= len;
   37.37 -	y /= len;
   37.38 -}
   37.39 -
   37.40 -Vector2 Vector2::normalized() const
   37.41 -{
   37.42 -	scalar_t len = length();
   37.43 -	return Vector2(x / len, y / len);
   37.44 -}
   37.45 -
   37.46 -void Vector2::transform(const Matrix3x3 &mat)
   37.47 -{
   37.48 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2];
   37.49 -	y = mat[1][0] * x + mat[1][1] * y + mat[1][2];
   37.50 -	x = nx;
   37.51 -}
   37.52 -
   37.53 -Vector2 Vector2::transformed(const Matrix3x3 &mat) const
   37.54 -{
   37.55 -	Vector2 vec;
   37.56 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2];
   37.57 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2];
   37.58 -	return vec;
   37.59 -}
   37.60 -
   37.61 -void Vector2::rotate(scalar_t angle)
   37.62 -{
   37.63 -	*this = Vector2(cos(angle) * x - sin(angle) * y, sin(angle) * x + cos(angle) * y);
   37.64 -}
   37.65 -
   37.66 -Vector2 Vector2::rotated(scalar_t angle) const
   37.67 -{
   37.68 -	return Vector2(cos(angle) * x - sin(angle) * y, sin(angle) * x + cos(angle) * y);
   37.69 -}
   37.70 -
   37.71 -Vector2 Vector2::reflection(const Vector2 &normal) const
   37.72 -{
   37.73 -	return 2.0 * dot_product(*this, normal) * normal - *this;
   37.74 -}
   37.75 -
   37.76 -Vector2 Vector2::refraction(const Vector2 &normal, scalar_t src_ior, scalar_t dst_ior) const
   37.77 -{
   37.78 -	// quick and dirty implementation :)
   37.79 -	Vector3 v3refr = Vector3(this->x, this->y, 1.0).refraction(Vector3(this->x, this->y, 1), src_ior, dst_ior);
   37.80 -	return Vector2(v3refr.x, v3refr.y);
   37.81 -}
   37.82 -
   37.83 -std::ostream &operator <<(std::ostream &out, const Vector2 &vec)
   37.84 -{
   37.85 -	out << "[" << vec.x << " " << vec.y << "]";
   37.86 -	return out;
   37.87 -}
   37.88 -
   37.89 -
   37.90 -
   37.91 -// --------- Vector3 ----------
   37.92 -
   37.93 -Vector3::Vector3(scalar_t x, scalar_t y, scalar_t z)
   37.94 -{
   37.95 -	this->x = x;
   37.96 -	this->y = y;
   37.97 -	this->z = z;
   37.98 -}
   37.99 -
  37.100 -Vector3::Vector3(const vec3_t &vec)
  37.101 -{
  37.102 -	x = vec.x;
  37.103 -	y = vec.y;
  37.104 -	z = vec.z;
  37.105 -}
  37.106 -
  37.107 -Vector3::Vector3(const Vector2 &vec)
  37.108 -{
  37.109 -	x = vec.x;
  37.110 -	y = vec.y;
  37.111 -	z = 1;
  37.112 -}
  37.113 -
  37.114 -Vector3::Vector3(const Vector4 &vec)
  37.115 -{
  37.116 -	x = vec.x;
  37.117 -	y = vec.y;
  37.118 -	z = vec.z;
  37.119 -}
  37.120 -
  37.121 -Vector3::Vector3(const SphVector &sph)
  37.122 -{
  37.123 -	*this = sph;
  37.124 -}
  37.125 -
  37.126 -Vector3 &Vector3::operator =(const SphVector &sph)
  37.127 -{
  37.128 -	x = sph.r * cos(sph.theta) * sin(sph.phi);
  37.129 -	z = sph.r * sin(sph.theta) * sin(sph.phi);
  37.130 -	y = sph.r * cos(sph.phi);
  37.131 -	return *this;
  37.132 -}
  37.133 -
  37.134 -void Vector3::normalize()
  37.135 -{
  37.136 -	scalar_t len = length();
  37.137 -	x /= len;
  37.138 -	y /= len;
  37.139 -	z /= len;
  37.140 -}
  37.141 -
  37.142 -Vector3 Vector3::normalized() const
  37.143 -{
  37.144 -	scalar_t len = length();
  37.145 -	return Vector3(x / len, y / len, z / len);
  37.146 -}
  37.147 -
  37.148 -Vector3 Vector3::reflection(const Vector3 &normal) const
  37.149 -{
  37.150 -	return 2.0 * dot_product(*this, normal) * normal - *this;
  37.151 -}
  37.152 -
  37.153 -Vector3 Vector3::refraction(const Vector3 &normal, scalar_t src_ior, scalar_t dst_ior) const
  37.154 -{
  37.155 -	return refraction(normal, src_ior / dst_ior);
  37.156 -}
  37.157 -
  37.158 -Vector3 Vector3::refraction(const Vector3 &normal, scalar_t ior) const
  37.159 -{
  37.160 -	scalar_t cos_inc = dot_product(*this, -normal);
  37.161 -
  37.162 -	scalar_t radical = 1.0 + SQ(ior) * (SQ(cos_inc) - 1.0);
  37.163 -
  37.164 -	if(radical < 0.0) {		// total internal reflection
  37.165 -		return -reflection(normal);
  37.166 -	}
  37.167 -
  37.168 -	scalar_t beta = ior * cos_inc - sqrt(radical);
  37.169 -
  37.170 -	return *this * ior + normal * beta;
  37.171 -}
  37.172 -
  37.173 -void Vector3::transform(const Matrix3x3 &mat)
  37.174 -{
  37.175 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z;
  37.176 -	scalar_t ny = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z;
  37.177 -	z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z;
  37.178 -	x = nx;
  37.179 -	y = ny;
  37.180 -}
  37.181 -
  37.182 -Vector3 Vector3::transformed(const Matrix3x3 &mat) const
  37.183 -{
  37.184 -	Vector3 vec;
  37.185 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z;
  37.186 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z;
  37.187 -	vec.z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z;
  37.188 -	return vec;
  37.189 -}
  37.190 -
  37.191 -void Vector3::transform(const Matrix4x4 &mat)
  37.192 -{
  37.193 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
  37.194 -	scalar_t ny = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
  37.195 -	z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
  37.196 -	x = nx;
  37.197 -	y = ny;
  37.198 -}
  37.199 -
  37.200 -Vector3 Vector3::transformed(const Matrix4x4 &mat) const
  37.201 -{
  37.202 -	Vector3 vec;
  37.203 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
  37.204 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
  37.205 -	vec.z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
  37.206 -	return vec;
  37.207 -}
  37.208 -
  37.209 -void Vector3::transform(const Quaternion &quat)
  37.210 -{
  37.211 -	Quaternion vq(0.0f, *this);
  37.212 -	vq = quat * vq * quat.inverse();
  37.213 -	*this = vq.v;
  37.214 -}
  37.215 -
  37.216 -Vector3 Vector3::transformed(const Quaternion &quat) const
  37.217 -{
  37.218 -	Quaternion vq(0.0f, *this);
  37.219 -	vq = quat * vq * quat.inverse();
  37.220 -	return vq.v;
  37.221 -}
  37.222 -
  37.223 -void Vector3::rotate(const Vector3 &euler)
  37.224 -{
  37.225 -	Matrix4x4 rot;
  37.226 -	rot.set_rotation(euler);
  37.227 -	transform(rot);
  37.228 -}
  37.229 -
  37.230 -Vector3 Vector3::rotated(const Vector3 &euler) const
  37.231 -{
  37.232 -	Matrix4x4 rot;
  37.233 -	rot.set_rotation(euler);
  37.234 -	return transformed(rot);
  37.235 -}
  37.236 -
  37.237 -std::ostream &operator <<(std::ostream &out, const Vector3 &vec)
  37.238 -{
  37.239 -	out << "[" << vec.x << " " << vec.y << " " << vec.z << "]";
  37.240 -	return out;
  37.241 -}
  37.242 -
  37.243 -
  37.244 -// -------------- Vector4 --------------
  37.245 -Vector4::Vector4(scalar_t x, scalar_t y, scalar_t z, scalar_t w)
  37.246 -{
  37.247 -	this->x = x;
  37.248 -	this->y = y;
  37.249 -	this->z = z;
  37.250 -	this->w = w;
  37.251 -}
  37.252 -
  37.253 -Vector4::Vector4(const vec4_t &vec)
  37.254 -{
  37.255 -	x = vec.x;
  37.256 -	y = vec.y;
  37.257 -	z = vec.z;
  37.258 -	w = vec.w;
  37.259 -}
  37.260 -
  37.261 -Vector4::Vector4(const Vector2 &vec)
  37.262 -{
  37.263 -	x = vec.x;
  37.264 -	y = vec.y;
  37.265 -	z = 1;
  37.266 -	w = 1;
  37.267 -}
  37.268 -
  37.269 -Vector4::Vector4(const Vector3 &vec)
  37.270 -{
  37.271 -	x = vec.x;
  37.272 -	y = vec.y;
  37.273 -	z = vec.z;
  37.274 -	w = 1;
  37.275 -}
  37.276 -
  37.277 -void Vector4::normalize()
  37.278 -{
  37.279 -	scalar_t len = (scalar_t)sqrt(x*x + y*y + z*z + w*w);
  37.280 -	x /= len;
  37.281 -	y /= len;
  37.282 -	z /= len;
  37.283 -	w /= len;
  37.284 -}
  37.285 -
  37.286 -Vector4 Vector4::normalized() const
  37.287 -{
  37.288 -	scalar_t len = (scalar_t)sqrt(x*x + y*y + z*z + w*w);
  37.289 -	return Vector4(x / len, y / len, z / len, w / len);
  37.290 -}
  37.291 -
  37.292 -void Vector4::transform(const Matrix4x4 &mat)
  37.293 -{
  37.294 -	scalar_t nx = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3] * w;
  37.295 -	scalar_t ny = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3] * w;
  37.296 -	scalar_t nz = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3] * w;
  37.297 -	w = mat[3][0] * x + mat[3][1] * y + mat[3][2] * z + mat[3][3] * w;
  37.298 -	x = nx;
  37.299 -	y = ny;
  37.300 -	z = nz;
  37.301 -}
  37.302 -
  37.303 -Vector4 Vector4::transformed(const Matrix4x4 &mat) const
  37.304 -{
  37.305 -	Vector4 vec;
  37.306 -	vec.x = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3] * w;
  37.307 -	vec.y = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3] * w;
  37.308 -	vec.z = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3] * w;
  37.309 -	vec.w = mat[3][0] * x + mat[3][1] * y + mat[3][2] * z + mat[3][3] * w;
  37.310 -	return vec;
  37.311 -}
  37.312 -
  37.313 -// TODO: implement 4D vector reflection
  37.314 -Vector4 Vector4::reflection(const Vector4 &normal) const
  37.315 -{
  37.316 -	return *this;
  37.317 -}
  37.318 -
  37.319 -// TODO: implement 4D vector refraction
  37.320 -Vector4 Vector4::refraction(const Vector4 &normal, scalar_t src_ior, scalar_t dst_ior) const
  37.321 -{
  37.322 -	return *this;
  37.323 -}
  37.324 -
  37.325 -std::ostream &operator <<(std::ostream &out, const Vector4 &vec)
  37.326 -{
  37.327 -	out << "[" << vec.x << " " << vec.y << " " << vec.z << " " << vec.w << "]";
  37.328 -	return out;
  37.329 -}
    38.1 --- a/libs/vmath/vector.h	Thu Jan 23 03:57:15 2014 +0200
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,292 +0,0 @@
    38.4 -/*
    38.5 -libvmath - a vector math library
    38.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    38.7 -
    38.8 -This program is free software: you can redistribute it and/or modify
    38.9 -it under the terms of the GNU Lesser General Public License as published
   38.10 -by the Free Software Foundation, either version 3 of the License, or
   38.11 -(at your option) any later version.
   38.12 -
   38.13 -This program is distributed in the hope that it will be useful,
   38.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   38.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   38.16 -GNU Lesser General Public License for more details.
   38.17 -
   38.18 -You should have received a copy of the GNU Lesser General Public License
   38.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   38.20 -*/
   38.21 -
   38.22 -#ifndef VMATH_VECTOR_H_
   38.23 -#define VMATH_VECTOR_H_
   38.24 -
   38.25 -#include <stdio.h>
   38.26 -#include "vmath_types.h"
   38.27 -
   38.28 -#ifdef __cplusplus
   38.29 -extern "C" {
   38.30 -#endif	/* __cplusplus */
   38.31 -
   38.32 -/* C 2D vector functions */
   38.33 -static VMATH_INLINE vec2_t v2_cons(scalar_t x, scalar_t y);
   38.34 -static VMATH_INLINE void v2_print(FILE *fp, vec2_t v);
   38.35 -
   38.36 -static VMATH_INLINE vec2_t v2_add(vec2_t v1, vec2_t v2);
   38.37 -static VMATH_INLINE vec2_t v2_sub(vec2_t v1, vec2_t v2);
   38.38 -static VMATH_INLINE vec2_t v2_scale(vec2_t v, scalar_t s);
   38.39 -static VMATH_INLINE scalar_t v2_dot(vec2_t v1, vec2_t v2);
   38.40 -static VMATH_INLINE scalar_t v2_length(vec2_t v);
   38.41 -static VMATH_INLINE scalar_t v2_length_sq(vec2_t v);
   38.42 -static VMATH_INLINE vec2_t v2_normalize(vec2_t v);
   38.43 -
   38.44 -static VMATH_INLINE vec2_t v2_lerp(vec2_t v1, vec2_t v2, scalar_t t);
   38.45 -
   38.46 -/* C 3D vector functions */
   38.47 -static VMATH_INLINE vec3_t v3_cons(scalar_t x, scalar_t y, scalar_t z);
   38.48 -static VMATH_INLINE void v3_print(FILE *fp, vec3_t v);
   38.49 -
   38.50 -static VMATH_INLINE vec3_t v3_add(vec3_t v1, vec3_t v2);
   38.51 -static VMATH_INLINE vec3_t v3_sub(vec3_t v1, vec3_t v2);
   38.52 -static VMATH_INLINE vec3_t v3_neg(vec3_t v);
   38.53 -static VMATH_INLINE vec3_t v3_mul(vec3_t v1, vec3_t v2);
   38.54 -static VMATH_INLINE vec3_t v3_scale(vec3_t v1, scalar_t s);
   38.55 -static VMATH_INLINE scalar_t v3_dot(vec3_t v1, vec3_t v2);
   38.56 -static VMATH_INLINE vec3_t v3_cross(vec3_t v1, vec3_t v2);
   38.57 -static VMATH_INLINE scalar_t v3_length(vec3_t v);
   38.58 -static VMATH_INLINE scalar_t v3_length_sq(vec3_t v);
   38.59 -static VMATH_INLINE vec3_t v3_normalize(vec3_t v);
   38.60 -static VMATH_INLINE vec3_t v3_transform(vec3_t v, mat4_t m);
   38.61 -
   38.62 -static VMATH_INLINE vec3_t v3_rotate(vec3_t v, scalar_t x, scalar_t y, scalar_t z);
   38.63 -static VMATH_INLINE vec3_t v3_rotate_axis(vec3_t v, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
   38.64 -static VMATH_INLINE vec3_t v3_rotate_quat(vec3_t v, quat_t q);
   38.65 -
   38.66 -static VMATH_INLINE vec3_t v3_reflect(vec3_t v, vec3_t n);
   38.67 -
   38.68 -static VMATH_INLINE vec3_t v3_lerp(vec3_t v1, vec3_t v2, scalar_t t);
   38.69 -
   38.70 -/* C 4D vector functions */
   38.71 -static VMATH_INLINE vec4_t v4_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t w);
   38.72 -static VMATH_INLINE void v4_print(FILE *fp, vec4_t v);
   38.73 -
   38.74 -static VMATH_INLINE vec4_t v4_add(vec4_t v1, vec4_t v2);
   38.75 -static VMATH_INLINE vec4_t v4_sub(vec4_t v1, vec4_t v2);
   38.76 -static VMATH_INLINE vec4_t v4_neg(vec4_t v);
   38.77 -static VMATH_INLINE vec4_t v4_mul(vec4_t v1, vec4_t v2);
   38.78 -static VMATH_INLINE vec4_t v4_scale(vec4_t v, scalar_t s);
   38.79 -static VMATH_INLINE scalar_t v4_dot(vec4_t v1, vec4_t v2);
   38.80 -static VMATH_INLINE scalar_t v4_length(vec4_t v);
   38.81 -static VMATH_INLINE scalar_t v4_length_sq(vec4_t v);
   38.82 -static VMATH_INLINE vec4_t v4_normalize(vec4_t v);
   38.83 -static VMATH_INLINE vec4_t v4_transform(vec4_t v, mat4_t m);
   38.84 -
   38.85 -#ifdef __cplusplus
   38.86 -}	/* extern "C" */
   38.87 -
   38.88 -/* when included from C++ source files, also define the vector classes */
   38.89 -#include <iostream>
   38.90 -
   38.91 -/** 2D Vector */
   38.92 -class Vector2 {
   38.93 -public:
   38.94 -	scalar_t x, y;
   38.95 -
   38.96 -	Vector2(scalar_t x = 0.0, scalar_t y = 0.0);
   38.97 -	Vector2(const vec2_t &vec);
   38.98 -	Vector2(const Vector3 &vec);
   38.99 -	Vector2(const Vector4 &vec);
  38.100 -
  38.101 -	VMATH_INLINE scalar_t &operator [](int elem);
  38.102 -	VMATH_INLINE const scalar_t &operator [](int elem) const;
  38.103 -
  38.104 -	VMATH_INLINE scalar_t length() const;
  38.105 -	VMATH_INLINE scalar_t length_sq() const;
  38.106 -	void normalize();
  38.107 -	Vector2 normalized() const;
  38.108 -
  38.109 -	void transform(const Matrix3x3 &mat);
  38.110 -	Vector2 transformed(const Matrix3x3 &mat) const;
  38.111 -
  38.112 -	void rotate(scalar_t angle);
  38.113 -	Vector2 rotated(scalar_t angle) const;
  38.114 -
  38.115 -	Vector2 reflection(const Vector2 &normal) const;
  38.116 -	Vector2 refraction(const Vector2 &normal, scalar_t src_ior, scalar_t dst_ior) const;
  38.117 -};
  38.118 -
  38.119 -/* unary operations */
  38.120 -VMATH_INLINE Vector2 operator -(const Vector2 &vec);
  38.121 -
  38.122 -/* binary vector (op) vector operations */
  38.123 -VMATH_INLINE scalar_t dot_product(const Vector2 &v1, const Vector2 &v2);
  38.124 -
  38.125 -VMATH_INLINE Vector2 operator +(const Vector2 &v1, const Vector2 &v2);
  38.126 -VMATH_INLINE Vector2 operator -(const Vector2 &v1, const Vector2 &v2);
  38.127 -VMATH_INLINE Vector2 operator *(const Vector2 &v1, const Vector2 &v2);
  38.128 -VMATH_INLINE Vector2 operator /(const Vector2 &v1, const Vector2 &v2);
  38.129 -VMATH_INLINE bool operator ==(const Vector2 &v1, const Vector2 &v2);
  38.130 -
  38.131 -VMATH_INLINE void operator +=(Vector2 &v1, const Vector2 &v2);
  38.132 -VMATH_INLINE void operator -=(Vector2 &v1, const Vector2 &v2);
  38.133 -VMATH_INLINE void operator *=(Vector2 &v1, const Vector2 &v2);
  38.134 -VMATH_INLINE void operator /=(Vector2 &v1, const Vector2 &v2);
  38.135 -
  38.136 -/* binary vector (op) scalar and scalar (op) vector operations */
  38.137 -VMATH_INLINE Vector2 operator +(const Vector2 &vec, scalar_t scalar);
  38.138 -VMATH_INLINE Vector2 operator +(scalar_t scalar, const Vector2 &vec);
  38.139 -VMATH_INLINE Vector2 operator -(const Vector2 &vec, scalar_t scalar);
  38.140 -VMATH_INLINE Vector2 operator *(const Vector2 &vec, scalar_t scalar);
  38.141 -VMATH_INLINE Vector2 operator *(scalar_t scalar, const Vector2 &vec);
  38.142 -VMATH_INLINE Vector2 operator /(const Vector2 &vec, scalar_t scalar);
  38.143 -
  38.144 -VMATH_INLINE void operator +=(Vector2 &vec, scalar_t scalar);
  38.145 -VMATH_INLINE void operator -=(Vector2 &vec, scalar_t scalar);
  38.146 -VMATH_INLINE void operator *=(Vector2 &vec, scalar_t scalar);
  38.147 -VMATH_INLINE void operator /=(Vector2 &vec, scalar_t scalar);
  38.148 -
  38.149 -std::ostream &operator <<(std::ostream &out, const Vector2 &vec);
  38.150 -
  38.151 -VMATH_INLINE Vector2 lerp(const Vector2 &a, const Vector2 &b, scalar_t t);
  38.152 -VMATH_INLINE Vector2 catmull_rom_spline(const Vector2 &v0, const Vector2 &v1,
  38.153 -		const Vector2 &v2, const Vector2 &v3, scalar_t t);
  38.154 -
  38.155 -/* 3D Vector */
  38.156 -class Vector3 {
  38.157 -public:
  38.158 -	scalar_t x, y, z;
  38.159 -
  38.160 -	Vector3(scalar_t x = 0.0, scalar_t y = 0.0, scalar_t z = 0.0);
  38.161 -	Vector3(const vec3_t &vec);
  38.162 -	Vector3(const Vector2 &vec);
  38.163 -	Vector3(const Vector4 &vec);
  38.164 -	Vector3(const SphVector &sph);
  38.165 -
  38.166 -	Vector3 &operator =(const SphVector &sph);
  38.167 -
  38.168 -	VMATH_INLINE scalar_t &operator [](int elem);
  38.169 -	VMATH_INLINE const scalar_t &operator [](int elem) const;
  38.170 -
  38.171 -	VMATH_INLINE scalar_t length() const;
  38.172 -	VMATH_INLINE scalar_t length_sq() const;
  38.173 -	void normalize();
  38.174 -	Vector3 normalized() const;
  38.175 -
  38.176 -	void transform(const Matrix3x3 &mat);
  38.177 -	Vector3 transformed(const Matrix3x3 &mat) const;
  38.178 -	void transform(const Matrix4x4 &mat);
  38.179 -	Vector3 transformed(const Matrix4x4 &mat) const;
  38.180 -	void transform(const Quaternion &quat);
  38.181 -	Vector3 transformed(const Quaternion &quat) const;
  38.182 -
  38.183 -	void rotate(const Vector3 &euler);
  38.184 -	Vector3 rotated(const Vector3 &euler) const;
  38.185 -
  38.186 -	Vector3 reflection(const Vector3 &normal) const;
  38.187 -	Vector3 refraction(const Vector3 &normal, scalar_t src_ior, scalar_t dst_ior) const;
  38.188 -	Vector3 refraction(const Vector3 &normal, scalar_t ior) const;
  38.189 -};
  38.190 -
  38.191 -/* unary operations */
  38.192 -VMATH_INLINE Vector3 operator -(const Vector3 &vec);
  38.193 -
  38.194 -/* binary vector (op) vector operations */
  38.195 -VMATH_INLINE scalar_t dot_product(const Vector3 &v1, const Vector3 &v2);
  38.196 -VMATH_INLINE Vector3 cross_product(const Vector3 &v1, const Vector3 &v2);
  38.197 -
  38.198 -VMATH_INLINE Vector3 operator +(const Vector3 &v1, const Vector3 &v2);
  38.199 -VMATH_INLINE Vector3 operator -(const Vector3 &v1, const Vector3 &v2);
  38.200 -VMATH_INLINE Vector3 operator *(const Vector3 &v1, const Vector3 &v2);
  38.201 -VMATH_INLINE Vector3 operator /(const Vector3 &v1, const Vector3 &v2);
  38.202 -VMATH_INLINE bool operator ==(const Vector3 &v1, const Vector3 &v2);
  38.203 -
  38.204 -VMATH_INLINE void operator +=(Vector3 &v1, const Vector3 &v2);
  38.205 -VMATH_INLINE void operator -=(Vector3 &v1, const Vector3 &v2);
  38.206 -VMATH_INLINE void operator *=(Vector3 &v1, const Vector3 &v2);
  38.207 -VMATH_INLINE void operator /=(Vector3 &v1, const Vector3 &v2);
  38.208 -
  38.209 -/* binary vector (op) scalar and scalar (op) vector operations */
  38.210 -VMATH_INLINE Vector3 operator +(const Vector3 &vec, scalar_t scalar);
  38.211 -VMATH_INLINE Vector3 operator +(scalar_t scalar, const Vector3 &vec);
  38.212 -VMATH_INLINE Vector3 operator -(const Vector3 &vec, scalar_t scalar);
  38.213 -VMATH_INLINE Vector3 operator *(const Vector3 &vec, scalar_t scalar);
  38.214 -VMATH_INLINE Vector3 operator *(scalar_t scalar, const Vector3 &vec);
  38.215 -VMATH_INLINE Vector3 operator /(const Vector3 &vec, scalar_t scalar);
  38.216 -
  38.217 -VMATH_INLINE void operator +=(Vector3 &vec, scalar_t scalar);
  38.218 -VMATH_INLINE void operator -=(Vector3 &vec, scalar_t scalar);
  38.219 -VMATH_INLINE void operator *=(Vector3 &vec, scalar_t scalar);
  38.220 -VMATH_INLINE void operator /=(Vector3 &vec, scalar_t scalar);
  38.221 -
  38.222 -std::ostream &operator <<(std::ostream &out, const Vector3 &vec);
  38.223 -
  38.224 -VMATH_INLINE Vector3 lerp(const Vector3 &a, const Vector3 &b, scalar_t t);
  38.225 -VMATH_INLINE Vector3 catmull_rom_spline(const Vector3 &v0, const Vector3 &v1,
  38.226 -		const Vector3 &v2, const Vector3 &v3, scalar_t t);
  38.227 -
  38.228 -/* 4D Vector */
  38.229 -class Vector4 {
  38.230 -public:
  38.231 -	scalar_t x, y, z, w;
  38.232 -
  38.233 -	Vector4(scalar_t x = 0.0, scalar_t y = 0.0, scalar_t z = 0.0, scalar_t w = 0.0);
  38.234 -	Vector4(const vec4_t &vec);
  38.235 -	Vector4(const Vector2 &vec);
  38.236 -	Vector4(const Vector3 &vec);
  38.237 -
  38.238 -	VMATH_INLINE scalar_t &operator [](int elem);
  38.239 -	VMATH_INLINE const scalar_t &operator [](int elem) const;
  38.240 -
  38.241 -	VMATH_INLINE scalar_t length() const;
  38.242 -	VMATH_INLINE scalar_t length_sq() const;
  38.243 -	void normalize();
  38.244 -	Vector4 normalized() const;
  38.245 -
  38.246 -	void transform(const Matrix4x4 &mat);
  38.247 -	Vector4 transformed(const Matrix4x4 &mat) const;
  38.248 -
  38.249 -	Vector4 reflection(const Vector4 &normal) const;
  38.250 -	Vector4 refraction(const Vector4 &normal, scalar_t src_ior, scalar_t dst_ior) const;
  38.251 -};
  38.252 -
  38.253 -
  38.254 -/* unary operations */
  38.255 -VMATH_INLINE Vector4 operator -(const Vector4 &vec);
  38.256 -
  38.257 -/* binary vector (op) vector operations */
  38.258 -VMATH_INLINE scalar_t dot_product(const Vector4 &v1, const Vector4 &v2);
  38.259 -VMATH_INLINE Vector4 cross_product(const Vector4 &v1, const Vector4 &v2, const Vector4 &v3);
  38.260 -
  38.261 -VMATH_INLINE Vector4 operator +(const Vector4 &v1, const Vector4 &v2);
  38.262 -VMATH_INLINE Vector4 operator -(const Vector4 &v1, const Vector4 &v2);
  38.263 -VMATH_INLINE Vector4 operator *(const Vector4 &v1, const Vector4 &v2);
  38.264 -VMATH_INLINE Vector4 operator /(const Vector4 &v1, const Vector4 &v2);
  38.265 -VMATH_INLINE bool operator ==(const Vector4 &v1, const Vector4 &v2);
  38.266 -
  38.267 -VMATH_INLINE void operator +=(Vector4 &v1, const Vector4 &v2);
  38.268 -VMATH_INLINE void operator -=(Vector4 &v1, const Vector4 &v2);
  38.269 -VMATH_INLINE void operator *=(Vector4 &v1, const Vector4 &v2);
  38.270 -VMATH_INLINE void operator /=(Vector4 &v1, const Vector4 &v2);
  38.271 -
  38.272 -/* binary vector (op) scalar and scalar (op) vector operations */
  38.273 -VMATH_INLINE Vector4 operator +(const Vector4 &vec, scalar_t scalar);
  38.274 -VMATH_INLINE Vector4 operator +(scalar_t scalar, const Vector4 &vec);
  38.275 -VMATH_INLINE Vector4 operator -(const Vector4 &vec, scalar_t scalar);
  38.276 -VMATH_INLINE Vector4 operator *(const Vector4 &vec, scalar_t scalar);
  38.277 -VMATH_INLINE Vector4 operator *(scalar_t scalar, const Vector4 &vec);
  38.278 -VMATH_INLINE Vector4 operator /(const Vector4 &vec, scalar_t scalar);
  38.279 -
  38.280 -VMATH_INLINE void operator +=(Vector4 &vec, scalar_t scalar);
  38.281 -VMATH_INLINE void operator -=(Vector4 &vec, scalar_t scalar);
  38.282 -VMATH_INLINE void operator *=(Vector4 &vec, scalar_t scalar);
  38.283 -VMATH_INLINE void operator /=(Vector4 &vec, scalar_t scalar);
  38.284 -
  38.285 -std::ostream &operator <<(std::ostream &out, const Vector4 &vec);
  38.286 -
  38.287 -VMATH_INLINE Vector4 lerp(const Vector4 &v0, const Vector4 &v1, scalar_t t);
  38.288 -VMATH_INLINE Vector4 catmull_rom_spline(const Vector4 &v0, const Vector4 &v1,
  38.289 -		const Vector4 &v2, const Vector4 &v3, scalar_t t);
  38.290 -
  38.291 -#endif	/* __cplusplus */
  38.292 -
  38.293 -#include "vector.inl"
  38.294 -
  38.295 -#endif	/* VMATH_VECTOR_H_ */
    39.1 --- a/libs/vmath/vector.inl	Thu Jan 23 03:57:15 2014 +0200
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,761 +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 -#include <math.h>
   39.23 -
   39.24 -#ifdef __cplusplus
   39.25 -extern "C" {
   39.26 -#endif	/* __cplusplus */
   39.27 -
   39.28 -/* C 2D vector functions */
   39.29 -static VMATH_INLINE vec2_t v2_cons(scalar_t x, scalar_t y)
   39.30 -{
   39.31 -	vec2_t v;
   39.32 -	v.x = x;
   39.33 -	v.y = y;
   39.34 -	return v;
   39.35 -}
   39.36 -
   39.37 -static VMATH_INLINE void v2_print(FILE *fp, vec2_t v)
   39.38 -{
   39.39 -	fprintf(fp, "[ %.4f %.4f ]", v.x, v.y);
   39.40 -}
   39.41 -
   39.42 -static VMATH_INLINE vec2_t v2_add(vec2_t v1, vec2_t v2)
   39.43 -{
   39.44 -	vec2_t res;
   39.45 -	res.x = v1.x + v2.x;
   39.46 -	res.y = v1.y + v2.y;
   39.47 -	return res;
   39.48 -}
   39.49 -
   39.50 -static VMATH_INLINE vec2_t v2_sub(vec2_t v1, vec2_t v2)
   39.51 -{
   39.52 -	vec2_t res;
   39.53 -	res.x = v1.x - v2.x;
   39.54 -	res.y = v1.y - v2.y;
   39.55 -	return res;
   39.56 -}
   39.57 -
   39.58 -static VMATH_INLINE vec2_t v2_scale(vec2_t v, scalar_t s)
   39.59 -{
   39.60 -	vec2_t res;
   39.61 -	res.x = v.x * s;
   39.62 -	res.y = v.y * s;
   39.63 -	return res;
   39.64 -}
   39.65 -
   39.66 -static VMATH_INLINE scalar_t v2_dot(vec2_t v1, vec2_t v2)
   39.67 -{
   39.68 -	return v1.x * v2.x + v1.y * v2.y;
   39.69 -}
   39.70 -
   39.71 -static VMATH_INLINE scalar_t v2_length(vec2_t v)
   39.72 -{
   39.73 -	return sqrt(v.x * v.x + v.y * v.y);
   39.74 -}
   39.75 -
   39.76 -static VMATH_INLINE scalar_t v2_length_sq(vec2_t v)
   39.77 -{
   39.78 -	return v.x * v.x + v.y * v.y;
   39.79 -}
   39.80 -
   39.81 -static VMATH_INLINE vec2_t v2_normalize(vec2_t v)
   39.82 -{
   39.83 -	scalar_t len = (scalar_t)sqrt(v.x * v.x + v.y * v.y);
   39.84 -	v.x /= len;
   39.85 -	v.y /= len;
   39.86 -	return v;
   39.87 -}
   39.88 -
   39.89 -static VMATH_INLINE vec2_t v2_lerp(vec2_t v1, vec2_t v2, scalar_t t)
   39.90 -{
   39.91 -	vec2_t res;
   39.92 -	res.x = v1.x + (v2.x - v1.x) * t;
   39.93 -	res.y = v1.y + (v2.y - v1.y) * t;
   39.94 -	return res;
   39.95 -}
   39.96 -
   39.97 -
   39.98 -/* C 3D vector functions */
   39.99 -static VMATH_INLINE vec3_t v3_cons(scalar_t x, scalar_t y, scalar_t z)
  39.100 -{
  39.101 -	vec3_t v;
  39.102 -	v.x = x;
  39.103 -	v.y = y;
  39.104 -	v.z = z;
  39.105 -	return v;
  39.106 -}
  39.107 -
  39.108 -static VMATH_INLINE void v3_print(FILE *fp, vec3_t v)
  39.109 -{
  39.110 -	fprintf(fp, "[ %.4f %.4f %.4f ]", v.x, v.y, v.z);
  39.111 -}
  39.112 -
  39.113 -static VMATH_INLINE vec3_t v3_add(vec3_t v1, vec3_t v2)
  39.114 -{
  39.115 -	v1.x += v2.x;
  39.116 -	v1.y += v2.y;
  39.117 -	v1.z += v2.z;
  39.118 -	return v1;
  39.119 -}
  39.120 -
  39.121 -static VMATH_INLINE vec3_t v3_sub(vec3_t v1, vec3_t v2)
  39.122 -{
  39.123 -	v1.x -= v2.x;
  39.124 -	v1.y -= v2.y;
  39.125 -	v1.z -= v2.z;
  39.126 -	return v1;
  39.127 -}
  39.128 -
  39.129 -static VMATH_INLINE vec3_t v3_neg(vec3_t v)
  39.130 -{
  39.131 -	v.x = -v.x;
  39.132 -	v.y = -v.y;
  39.133 -	v.z = -v.z;
  39.134 -	return v;
  39.135 -}
  39.136 -
  39.137 -static VMATH_INLINE vec3_t v3_mul(vec3_t v1, vec3_t v2)
  39.138 -{
  39.139 -	v1.x *= v2.x;
  39.140 -	v1.y *= v2.y;
  39.141 -	v1.z *= v2.z;
  39.142 -	return v1;
  39.143 -}
  39.144 -
  39.145 -static VMATH_INLINE vec3_t v3_scale(vec3_t v1, scalar_t s)
  39.146 -{
  39.147 -	v1.x *= s;
  39.148 -	v1.y *= s;
  39.149 -	v1.z *= s;
  39.150 -	return v1;
  39.151 -}
  39.152 -
  39.153 -static VMATH_INLINE scalar_t v3_dot(vec3_t v1, vec3_t v2)
  39.154 -{
  39.155 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
  39.156 -}
  39.157 -
  39.158 -static VMATH_INLINE vec3_t v3_cross(vec3_t v1, vec3_t v2)
  39.159 -{
  39.160 -	vec3_t v;
  39.161 -	v.x = v1.y * v2.z - v1.z * v2.y;
  39.162 -	v.y = v1.z * v2.x - v1.x * v2.z;
  39.163 -	v.z = v1.x * v2.y - v1.y * v2.x;
  39.164 -	return v;
  39.165 -}
  39.166 -
  39.167 -static VMATH_INLINE scalar_t v3_length(vec3_t v)
  39.168 -{
  39.169 -	return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
  39.170 -}
  39.171 -
  39.172 -static VMATH_INLINE scalar_t v3_length_sq(vec3_t v)
  39.173 -{
  39.174 -	return v.x * v.x + v.y * v.y + v.z * v.z;
  39.175 -}
  39.176 -
  39.177 -static VMATH_INLINE vec3_t v3_normalize(vec3_t v)
  39.178 -{
  39.179 -	scalar_t len = sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
  39.180 -	v.x /= len;
  39.181 -	v.y /= len;
  39.182 -	v.z /= len;
  39.183 -	return v;
  39.184 -}
  39.185 -
  39.186 -static VMATH_INLINE vec3_t v3_transform(vec3_t v, mat4_t m)
  39.187 -{
  39.188 -	vec3_t res;
  39.189 -	res.x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3];
  39.190 -	res.y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3];
  39.191 -	res.z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3];
  39.192 -	return res;
  39.193 -}
  39.194 -
  39.195 -static VMATH_INLINE vec3_t v3_rotate(vec3_t v, scalar_t x, scalar_t y, scalar_t z)
  39.196 -{
  39.197 -	void m4_rotate(mat4_t, scalar_t, scalar_t, scalar_t);
  39.198 -
  39.199 -	mat4_t m = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
  39.200 -	m4_rotate(m, x, y, z);
  39.201 -	return v3_transform(v, m);
  39.202 -}
  39.203 -
  39.204 -static VMATH_INLINE vec3_t v3_rotate_axis(vec3_t v, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
  39.205 -{
  39.206 -	void m4_rotate_axis(mat4_t, scalar_t, scalar_t, scalar_t, scalar_t);
  39.207 -
  39.208 -	mat4_t m = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
  39.209 -	m4_rotate_axis(m, angle, x, y, z);
  39.210 -	return v3_transform(v, m);
  39.211 -}
  39.212 -
  39.213 -static VMATH_INLINE vec3_t v3_rotate_quat(vec3_t v, quat_t q)
  39.214 -{
  39.215 -	quat_t quat_rotate_quat(quat_t, quat_t);
  39.216 -
  39.217 -	quat_t vq = v4_cons(v.x, v.y, v.z, 0.0);
  39.218 -	quat_t res = quat_rotate_quat(vq, q);
  39.219 -	return v3_cons(res.x, res.y, res.z);
  39.220 -}
  39.221 -
  39.222 -static VMATH_INLINE vec3_t v3_reflect(vec3_t v, vec3_t n)
  39.223 -{
  39.224 -	scalar_t dot = v3_dot(v, n);
  39.225 -	return v3_sub(v3_scale(n, dot * 2.0), v);
  39.226 -}
  39.227 -
  39.228 -static VMATH_INLINE vec3_t v3_lerp(vec3_t v1, vec3_t v2, scalar_t t)
  39.229 -{
  39.230 -	v1.x += (v2.x - v1.x) * t;
  39.231 -	v1.y += (v2.y - v1.y) * t;
  39.232 -	v1.z += (v2.z - v1.z) * t;
  39.233 -	return v1;
  39.234 -}
  39.235 -
  39.236 -/* C 4D vector functions */
  39.237 -static VMATH_INLINE vec4_t v4_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t w)
  39.238 -{
  39.239 -	vec4_t v;
  39.240 -	v.x = x;
  39.241 -	v.y = y;
  39.242 -	v.z = z;
  39.243 -	v.w = w;
  39.244 -	return v;
  39.245 -}
  39.246 -
  39.247 -static VMATH_INLINE void v4_print(FILE *fp, vec4_t v)
  39.248 -{
  39.249 -	fprintf(fp, "[ %.4f %.4f %.4f %.4f ]", v.x, v.y, v.z, v.w);
  39.250 -}
  39.251 -
  39.252 -static VMATH_INLINE vec4_t v4_add(vec4_t v1, vec4_t v2)
  39.253 -{
  39.254 -	v1.x += v2.x;
  39.255 -	v1.y += v2.y;
  39.256 -	v1.z += v2.z;
  39.257 -	v1.w += v2.w;
  39.258 -	return v1;
  39.259 -}
  39.260 -
  39.261 -static VMATH_INLINE vec4_t v4_sub(vec4_t v1, vec4_t v2)
  39.262 -{
  39.263 -	v1.x -= v2.x;
  39.264 -	v1.y -= v2.y;
  39.265 -	v1.z -= v2.z;
  39.266 -	v1.w -= v2.w;
  39.267 -	return v1;
  39.268 -}
  39.269 -
  39.270 -static VMATH_INLINE vec4_t v4_neg(vec4_t v)
  39.271 -{
  39.272 -	v.x = -v.x;
  39.273 -	v.y = -v.y;
  39.274 -	v.z = -v.z;
  39.275 -	v.w = -v.w;
  39.276 -	return v;
  39.277 -}
  39.278 -
  39.279 -static VMATH_INLINE vec4_t v4_mul(vec4_t v1, vec4_t v2)
  39.280 -{
  39.281 -	v1.x *= v2.x;
  39.282 -	v1.y *= v2.y;
  39.283 -	v1.z *= v2.z;
  39.284 -	v1.w *= v2.w;
  39.285 -	return v1;
  39.286 -}
  39.287 -
  39.288 -static VMATH_INLINE vec4_t v4_scale(vec4_t v, scalar_t s)
  39.289 -{
  39.290 -	v.x *= s;
  39.291 -	v.y *= s;
  39.292 -	v.z *= s;
  39.293 -	v.w *= s;
  39.294 -	return v;
  39.295 -}
  39.296 -
  39.297 -static VMATH_INLINE scalar_t v4_dot(vec4_t v1, vec4_t v2)
  39.298 -{
  39.299 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
  39.300 -}
  39.301 -
  39.302 -static VMATH_INLINE scalar_t v4_length(vec4_t v)
  39.303 -{
  39.304 -	return sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
  39.305 -}
  39.306 -
  39.307 -static VMATH_INLINE scalar_t v4_length_sq(vec4_t v)
  39.308 -{
  39.309 -	return v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w;
  39.310 -}
  39.311 -
  39.312 -static VMATH_INLINE vec4_t v4_normalize(vec4_t v)
  39.313 -{
  39.314 -	scalar_t len = sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
  39.315 -	v.x /= len;
  39.316 -	v.y /= len;
  39.317 -	v.z /= len;
  39.318 -	v.w /= len;
  39.319 -	return v;
  39.320 -}
  39.321 -
  39.322 -static VMATH_INLINE vec4_t v4_transform(vec4_t v, mat4_t m)
  39.323 -{
  39.324 -	vec4_t res;
  39.325 -	res.x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w;
  39.326 -	res.y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w;
  39.327 -	res.z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w;
  39.328 -	res.w = m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w;
  39.329 -	return res;
  39.330 -}
  39.331 -
  39.332 -#ifdef __cplusplus
  39.333 -}	/* extern "C" */
  39.334 -
  39.335 -
  39.336 -/* --------------- C++ part -------------- */
  39.337 -
  39.338 -VMATH_INLINE scalar_t &Vector2::operator [](int elem) {
  39.339 -	return elem ? y : x;
  39.340 -}
  39.341 -
  39.342 -VMATH_INLINE const scalar_t &Vector2::operator [](int elem) const {
  39.343 -	return elem ? y : x;
  39.344 -}
  39.345 -
  39.346 -VMATH_INLINE Vector2 operator -(const Vector2 &vec) {
  39.347 -	return Vector2(-vec.x, -vec.y);
  39.348 -}
  39.349 -
  39.350 -VMATH_INLINE scalar_t dot_product(const Vector2 &v1, const Vector2 &v2) {
  39.351 -	return v1.x * v2.x + v1.y * v2.y;
  39.352 -}
  39.353 -
  39.354 -VMATH_INLINE Vector2 operator +(const Vector2 &v1, const Vector2 &v2) {
  39.355 -	return Vector2(v1.x + v2.x, v1.y + v2.y);
  39.356 -}
  39.357 -
  39.358 -VMATH_INLINE Vector2 operator -(const Vector2 &v1, const Vector2 &v2) {
  39.359 -	return Vector2(v1.x - v2.x, v1.y - v2.y);
  39.360 -}
  39.361 -
  39.362 -VMATH_INLINE Vector2 operator *(const Vector2 &v1, const Vector2 &v2) {
  39.363 -	return Vector2(v1.x * v2.x, v1.y * v2.y);
  39.364 -}
  39.365 -
  39.366 -VMATH_INLINE Vector2 operator /(const Vector2 &v1, const Vector2 &v2) {
  39.367 -	return Vector2(v1.x / v2.x, v1.y / v2.y);
  39.368 -}
  39.369 -
  39.370 -VMATH_INLINE bool operator ==(const Vector2 &v1, const Vector2 &v2) {
  39.371 -	return (fabs(v1.x - v2.x) < XSMALL_NUMBER) && (fabs(v1.y - v2.x) < XSMALL_NUMBER);
  39.372 -}
  39.373 -
  39.374 -VMATH_INLINE void operator +=(Vector2 &v1, const Vector2 &v2) {
  39.375 -	v1.x += v2.x;
  39.376 -	v1.y += v2.y;
  39.377 -}
  39.378 -
  39.379 -VMATH_INLINE void operator -=(Vector2 &v1, const Vector2 &v2) {
  39.380 -	v1.x -= v2.x;
  39.381 -	v1.y -= v2.y;
  39.382 -}
  39.383 -
  39.384 -VMATH_INLINE void operator *=(Vector2 &v1, const Vector2 &v2) {
  39.385 -	v1.x *= v2.x;
  39.386 -	v1.y *= v2.y;
  39.387 -}
  39.388 -
  39.389 -VMATH_INLINE void operator /=(Vector2 &v1, const Vector2 &v2) {
  39.390 -	v1.x /= v2.x;
  39.391 -	v1.y /= v2.y;
  39.392 -}
  39.393 -
  39.394 -VMATH_INLINE Vector2 operator +(const Vector2 &vec, scalar_t scalar) {
  39.395 -	return Vector2(vec.x + scalar, vec.y + scalar);
  39.396 -}
  39.397 -
  39.398 -VMATH_INLINE Vector2 operator +(scalar_t scalar, const Vector2 &vec) {
  39.399 -	return Vector2(vec.x + scalar, vec.y + scalar);
  39.400 -}
  39.401 -
  39.402 -VMATH_INLINE Vector2 operator -(scalar_t scalar, const Vector2 &vec) {
  39.403 -	return Vector2(vec.x - scalar, vec.y - scalar);
  39.404 -}
  39.405 -
  39.406 -VMATH_INLINE Vector2 operator *(const Vector2 &vec, scalar_t scalar) {
  39.407 -	return Vector2(vec.x * scalar, vec.y * scalar);
  39.408 -}
  39.409 -
  39.410 -VMATH_INLINE Vector2 operator *(scalar_t scalar, const Vector2 &vec) {
  39.411 -	return Vector2(vec.x * scalar, vec.y * scalar);
  39.412 -}
  39.413 -
  39.414 -VMATH_INLINE Vector2 operator /(const Vector2 &vec, scalar_t scalar) {
  39.415 -	return Vector2(vec.x / scalar, vec.y / scalar);
  39.416 -}
  39.417 -
  39.418 -VMATH_INLINE void operator +=(Vector2 &vec, scalar_t scalar) {
  39.419 -	vec.x += scalar;
  39.420 -	vec.y += scalar;
  39.421 -}
  39.422 -
  39.423 -VMATH_INLINE void operator -=(Vector2 &vec, scalar_t scalar) {
  39.424 -	vec.x -= scalar;
  39.425 -	vec.y -= scalar;
  39.426 -}
  39.427 -
  39.428 -VMATH_INLINE void operator *=(Vector2 &vec, scalar_t scalar) {
  39.429 -	vec.x *= scalar;
  39.430 -	vec.y *= scalar;
  39.431 -}
  39.432 -
  39.433 -VMATH_INLINE void operator /=(Vector2 &vec, scalar_t scalar) {
  39.434 -	vec.x /= scalar;
  39.435 -	vec.y /= scalar;
  39.436 -}
  39.437 -
  39.438 -VMATH_INLINE scalar_t Vector2::length() const {
  39.439 -	return sqrt(x*x + y*y);
  39.440 -}
  39.441 -
  39.442 -VMATH_INLINE scalar_t Vector2::length_sq() const {
  39.443 -	return x*x + y*y;
  39.444 -}
  39.445 -
  39.446 -VMATH_INLINE Vector2 lerp(const Vector2 &a, const Vector2 &b, scalar_t t)
  39.447 -{
  39.448 -	return a + (b - a) * t;
  39.449 -}
  39.450 -
  39.451 -VMATH_INLINE Vector2 catmull_rom_spline(const Vector2 &v0, const Vector2 &v1,
  39.452 -		const Vector2 &v2, const Vector2 &v3, scalar_t t)
  39.453 -{
  39.454 -	scalar_t spline(scalar_t, scalar_t, scalar_t, scalar_t, scalar_t);
  39.455 -	scalar_t x = spline(v0.x, v1.x, v2.x, v3.x, t);
  39.456 -	scalar_t y = spline(v0.y, v1.y, v2.y, v3.y, t);
  39.457 -	return Vector2(x, y);
  39.458 -}
  39.459 -
  39.460 -
  39.461 -/* ------------- Vector3 -------------- */
  39.462 -
  39.463 -VMATH_INLINE scalar_t &Vector3::operator [](int elem) {
  39.464 -	return elem ? (elem == 1 ? y : z) : x;
  39.465 -}
  39.466 -
  39.467 -VMATH_INLINE const scalar_t &Vector3::operator [](int elem) const {
  39.468 -	return elem ? (elem == 1 ? y : z) : x;
  39.469 -}
  39.470 -
  39.471 -/* unary operations */
  39.472 -VMATH_INLINE Vector3 operator -(const Vector3 &vec) {
  39.473 -	return Vector3(-vec.x, -vec.y, -vec.z);
  39.474 -}
  39.475 -
  39.476 -/* binary vector (op) vector operations */
  39.477 -VMATH_INLINE scalar_t dot_product(const Vector3 &v1, const Vector3 &v2) {
  39.478 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
  39.479 -}
  39.480 -
  39.481 -VMATH_INLINE Vector3 cross_product(const Vector3 &v1, const Vector3 &v2) {
  39.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);
  39.483 -}
  39.484 -
  39.485 -
  39.486 -VMATH_INLINE Vector3 operator +(const Vector3 &v1, const Vector3 &v2) {
  39.487 -	return Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
  39.488 -}
  39.489 -
  39.490 -VMATH_INLINE Vector3 operator -(const Vector3 &v1, const Vector3 &v2) {
  39.491 -	return Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
  39.492 -}
  39.493 -
  39.494 -VMATH_INLINE Vector3 operator *(const Vector3 &v1, const Vector3 &v2) {
  39.495 -	return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
  39.496 -}
  39.497 -
  39.498 -VMATH_INLINE Vector3 operator /(const Vector3 &v1, const Vector3 &v2) {
  39.499 -	return Vector3(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z);
  39.500 -}
  39.501 -
  39.502 -VMATH_INLINE bool operator ==(const Vector3 &v1, const Vector3 &v2) {
  39.503 -	return (fabs(v1.x - v2.x) < XSMALL_NUMBER) && (fabs(v1.y - v2.y) < XSMALL_NUMBER) && (fabs(v1.z - v2.z) < XSMALL_NUMBER);
  39.504 -}
  39.505 -
  39.506 -VMATH_INLINE void operator +=(Vector3 &v1, const Vector3 &v2) {
  39.507 -	v1.x += v2.x;
  39.508 -	v1.y += v2.y;
  39.509 -	v1.z += v2.z;
  39.510 -}
  39.511 -
  39.512 -VMATH_INLINE void operator -=(Vector3 &v1, const Vector3 &v2) {
  39.513 -	v1.x -= v2.x;
  39.514 -	v1.y -= v2.y;
  39.515 -	v1.z -= v2.z;
  39.516 -}
  39.517 -
  39.518 -VMATH_INLINE void operator *=(Vector3 &v1, const Vector3 &v2) {
  39.519 -	v1.x *= v2.x;
  39.520 -	v1.y *= v2.y;
  39.521 -	v1.z *= v2.z;
  39.522 -}
  39.523 -
  39.524 -VMATH_INLINE void operator /=(Vector3 &v1, const Vector3 &v2) {
  39.525 -	v1.x /= v2.x;
  39.526 -	v1.y /= v2.y;
  39.527 -	v1.z /= v2.z;
  39.528 -}
  39.529 -/* binary vector (op) scalar and scalar (op) vector operations */
  39.530 -VMATH_INLINE Vector3 operator +(const Vector3 &vec, scalar_t scalar) {
  39.531 -	return Vector3(vec.x + scalar, vec.y + scalar, vec.z + scalar);
  39.532 -}
  39.533 -
  39.534 -VMATH_INLINE Vector3 operator +(scalar_t scalar, const Vector3 &vec) {
  39.535 -	return Vector3(vec.x + scalar, vec.y + scalar, vec.z + scalar);
  39.536 -}
  39.537 -
  39.538 -VMATH_INLINE Vector3 operator -(const Vector3 &vec, scalar_t scalar) {
  39.539 -	return Vector3(vec.x - scalar, vec.y - scalar, vec.z - scalar);
  39.540 -}
  39.541 -
  39.542 -VMATH_INLINE Vector3 operator *(const Vector3 &vec, scalar_t scalar) {
  39.543 -	return Vector3(vec.x * scalar, vec.y * scalar, vec.z * scalar);
  39.544 -}
  39.545 -
  39.546 -VMATH_INLINE Vector3 operator *(scalar_t scalar, const Vector3 &vec) {
  39.547 -	return Vector3(vec.x * scalar, vec.y * scalar, vec.z * scalar);
  39.548 -}
  39.549 -
  39.550 -VMATH_INLINE Vector3 operator /(const Vector3 &vec, scalar_t scalar) {
  39.551 -	return Vector3(vec.x / scalar, vec.y / scalar, vec.z / scalar);
  39.552 -}
  39.553 -
  39.554 -VMATH_INLINE void operator +=(Vector3 &vec, scalar_t scalar) {
  39.555 -	vec.x += scalar;
  39.556 -	vec.y += scalar;
  39.557 -	vec.z += scalar;
  39.558 -}
  39.559 -
  39.560 -VMATH_INLINE void operator -=(Vector3 &vec, scalar_t scalar) {
  39.561 -	vec.x -= scalar;
  39.562 -	vec.y -= scalar;
  39.563 -	vec.z -= scalar;
  39.564 -}
  39.565 -
  39.566 -VMATH_INLINE void operator *=(Vector3 &vec, scalar_t scalar) {
  39.567 -	vec.x *= scalar;
  39.568 -	vec.y *= scalar;
  39.569 -	vec.z *= scalar;
  39.570 -}
  39.571 -
  39.572 -VMATH_INLINE void operator /=(Vector3 &vec, scalar_t scalar) {
  39.573 -	vec.x /= scalar;
  39.574 -	vec.y /= scalar;
  39.575 -	vec.z /= scalar;
  39.576 -}
  39.577 -
  39.578 -VMATH_INLINE scalar_t Vector3::length() const {
  39.579 -	return sqrt(x*x + y*y + z*z);
  39.580 -}
  39.581 -VMATH_INLINE scalar_t Vector3::length_sq() const {
  39.582 -	return x*x + y*y + z*z;
  39.583 -}
  39.584 -
  39.585 -VMATH_INLINE Vector3 lerp(const Vector3 &a, const Vector3 &b, scalar_t t) {
  39.586 -	return a + (b - a) * t;
  39.587 -}
  39.588 -
  39.589 -VMATH_INLINE Vector3 catmull_rom_spline(const Vector3 &v0, const Vector3 &v1,
  39.590 -		const Vector3 &v2, const Vector3 &v3, scalar_t t)
  39.591 -{
  39.592 -	scalar_t spline(scalar_t, scalar_t, scalar_t, scalar_t, scalar_t);
  39.593 -	scalar_t x = spline(v0.x, v1.x, v2.x, v3.x, t);
  39.594 -	scalar_t y = spline(v0.y, v1.y, v2.y, v3.y, t);
  39.595 -	scalar_t z = spline(v0.z, v1.z, v2.z, v3.z, t);
  39.596 -	return Vector3(x, y, z);
  39.597 -}
  39.598 -
  39.599 -/* ----------- Vector4 ----------------- */
  39.600 -
  39.601 -VMATH_INLINE scalar_t &Vector4::operator [](int elem) {
  39.602 -	return elem ? (elem == 1 ? y : (elem == 2 ? z : w)) : x;
  39.603 -}
  39.604 -
  39.605 -VMATH_INLINE const scalar_t &Vector4::operator [](int elem) const {
  39.606 -	return elem ? (elem == 1 ? y : (elem == 2 ? z : w)) : x;
  39.607 -}
  39.608 -
  39.609 -VMATH_INLINE Vector4 operator -(const Vector4 &vec) {
  39.610 -	return Vector4(-vec.x, -vec.y, -vec.z, -vec.w);
  39.611 -}
  39.612 -
  39.613 -VMATH_INLINE scalar_t dot_product(const Vector4 &v1, const Vector4 &v2) {
  39.614 -	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
  39.615 -}
  39.616 -
  39.617 -VMATH_INLINE Vector4 cross_product(const Vector4 &v1, const Vector4 &v2, const Vector4 &v3) {
  39.618 -	scalar_t a, b, c, d, e, f;       /* Intermediate Values */
  39.619 -    Vector4 result;
  39.620 -
  39.621 -    /* Calculate intermediate values. */
  39.622 -    a = (v2.x * v3.y) - (v2.y * v3.x);
  39.623 -    b = (v2.x * v3.z) - (v2.z * v3.x);
  39.624 -    c = (v2.x * v3.w) - (v2.w * v3.x);
  39.625 -    d = (v2.y * v3.z) - (v2.z * v3.y);
  39.626 -    e = (v2.y * v3.w) - (v2.w * v3.y);
  39.627 -    f = (v2.z * v3.w) - (v2.w * v3.z);
  39.628 -
  39.629 -    /* Calculate the result-vector components. */
  39.630 -    result.x =   (v1.y * f) - (v1.z * e) + (v1.w * d);
  39.631 -    result.y = - (v1.x * f) + (v1.z * c) - (v1.w * b);
  39.632 -    result.z =   (v1.x * e) - (v1.y * c) + (v1.w * a);
  39.633 -    result.w = - (v1.x * d) + (v1.y * b) - (v1.z * a);
  39.634 -    return result;
  39.635 -}
  39.636 -
  39.637 -VMATH_INLINE Vector4 operator +(const Vector4 &v1, const Vector4 &v2) {
  39.638 -	return Vector4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
  39.639 -}
  39.640 -
  39.641 -VMATH_INLINE Vector4 operator -(const Vector4 &v1, const Vector4 &v2) {
  39.642 -	return Vector4(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
  39.643 -}
  39.644 -
  39.645 -VMATH_INLINE Vector4 operator *(const Vector4 &v1, const Vector4 &v2) {
  39.646 -	return Vector4(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w);
  39.647 -}
  39.648 -
  39.649 -VMATH_INLINE Vector4 operator /(const Vector4 &v1, const Vector4 &v2) {
  39.650 -	return Vector4(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w);
  39.651 -}
  39.652 -
  39.653 -VMATH_INLINE bool operator ==(const Vector4 &v1, const Vector4 &v2) {
  39.654 -	return	(fabs(v1.x - v2.x) < XSMALL_NUMBER) &&
  39.655 -			(fabs(v1.y - v2.y) < XSMALL_NUMBER) &&
  39.656 -			(fabs(v1.z - v2.z) < XSMALL_NUMBER) &&
  39.657 -			(fabs(v1.w - v2.w) < XSMALL_NUMBER);
  39.658 -}
  39.659 -
  39.660 -VMATH_INLINE void operator +=(Vector4 &v1, const Vector4 &v2) {
  39.661 -	v1.x += v2.x;
  39.662 -	v1.y += v2.y;
  39.663 -	v1.z += v2.z;
  39.664 -	v1.w += v2.w;
  39.665 -}
  39.666 -
  39.667 -VMATH_INLINE void operator -=(Vector4 &v1, const Vector4 &v2) {
  39.668 -	v1.x -= v2.x;
  39.669 -	v1.y -= v2.y;
  39.670 -	v1.z -= v2.z;
  39.671 -	v1.w -= v2.w;
  39.672 -}
  39.673 -
  39.674 -VMATH_INLINE void operator *=(Vector4 &v1, const Vector4 &v2) {
  39.675 -	v1.x *= v2.x;
  39.676 -	v1.y *= v2.y;
  39.677 -	v1.z *= v2.z;
  39.678 -	v1.w *= v2.w;
  39.679 -}
  39.680 -
  39.681 -VMATH_INLINE void operator /=(Vector4 &v1, const Vector4 &v2) {
  39.682 -	v1.x /= v2.x;
  39.683 -	v1.y /= v2.y;
  39.684 -	v1.z /= v2.z;
  39.685 -	v1.w /= v2.w;
  39.686 -}
  39.687 -
  39.688 -/* binary vector (op) scalar and scalar (op) vector operations */
  39.689 -VMATH_INLINE Vector4 operator +(const Vector4 &vec, scalar_t scalar) {
  39.690 -	return Vector4(vec.x + scalar, vec.y + scalar, vec.z + scalar, vec.w + scalar);
  39.691 -}
  39.692 -
  39.693 -VMATH_INLINE Vector4 operator +(scalar_t scalar, const Vector4 &vec) {
  39.694 -	return Vector4(vec.x + scalar, vec.y + scalar, vec.z + scalar, vec.w + scalar);
  39.695 -}
  39.696 -
  39.697 -VMATH_INLINE Vector4 operator -(const Vector4 &vec, scalar_t scalar) {
  39.698 -	return Vector4(vec.x - scalar, vec.y - scalar, vec.z - scalar, vec.w - scalar);
  39.699 -}
  39.700 -
  39.701 -VMATH_INLINE Vector4 operator *(const Vector4 &vec, scalar_t scalar) {
  39.702 -	return Vector4(vec.x * scalar, vec.y * scalar, vec.z * scalar, vec.w * scalar);
  39.703 -}
  39.704 -
  39.705 -VMATH_INLINE Vector4 operator *(scalar_t scalar, const Vector4 &vec) {
  39.706 -	return Vector4(vec.x * scalar, vec.y * scalar, vec.z * scalar, vec.w * scalar);
  39.707 -}
  39.708 -
  39.709 -VMATH_INLINE Vector4 operator /(const Vector4 &vec, scalar_t scalar) {
  39.710 -	return Vector4(vec.x / scalar, vec.y / scalar, vec.z / scalar, vec.w / scalar);
  39.711 -}
  39.712 -
  39.713 -VMATH_INLINE void operator +=(Vector4 &vec, scalar_t scalar) {
  39.714 -	vec.x += scalar;
  39.715 -	vec.y += scalar;
  39.716 -	vec.z += scalar;
  39.717 -	vec.w += scalar;
  39.718 -}
  39.719 -
  39.720 -VMATH_INLINE void operator -=(Vector4 &vec, scalar_t scalar) {
  39.721 -	vec.x -= scalar;
  39.722 -	vec.y -= scalar;
  39.723 -	vec.z -= scalar;
  39.724 -	vec.w -= scalar;
  39.725 -}
  39.726 -
  39.727 -VMATH_INLINE void operator *=(Vector4 &vec, scalar_t scalar) {
  39.728 -	vec.x *= scalar;
  39.729 -	vec.y *= scalar;
  39.730 -	vec.z *= scalar;
  39.731 -	vec.w *= scalar;
  39.732 -}
  39.733 -
  39.734 -VMATH_INLINE void operator /=(Vector4 &vec, scalar_t scalar) {
  39.735 -	vec.x /= scalar;
  39.736 -	vec.y /= scalar;
  39.737 -	vec.z /= scalar;
  39.738 -	vec.w /= scalar;
  39.739 -}
  39.740 -
  39.741 -VMATH_INLINE scalar_t Vector4::length() const {
  39.742 -	return sqrt(x*x + y*y + z*z + w*w);
  39.743 -}
  39.744 -VMATH_INLINE scalar_t Vector4::length_sq() const {
  39.745 -	return x*x + y*y + z*z + w*w;
  39.746 -}
  39.747 -
  39.748 -VMATH_INLINE Vector4 lerp(const Vector4 &v0, const Vector4 &v1, scalar_t t)
  39.749 -{
  39.750 -	return v0 + (v1 - v0) * t;
  39.751 -}
  39.752 -
  39.753 -VMATH_INLINE Vector4 catmull_rom_spline(const Vector4 &v0, const Vector4 &v1,
  39.754 -		const Vector4 &v2, const Vector4 &v3, scalar_t t)
  39.755 -{
  39.756 -	scalar_t spline(scalar_t, scalar_t, scalar_t, scalar_t, scalar_t);
  39.757 -	scalar_t x = spline(v0.x, v1.x, v2.x, v3.x, t);
  39.758 -	scalar_t y = spline(v0.y, v1.y, v2.y, v3.y, t);
  39.759 -	scalar_t z = spline(v0.z, v1.z, v2.z, v3.z, t);
  39.760 -	scalar_t w = spline(v0.w, v1.w, v2.w, v3.w, t);
  39.761 -	return Vector4(x, y, z, w);
  39.762 -}
  39.763 -
  39.764 -#endif	/* __cplusplus */
    40.1 --- a/libs/vmath/vmath.c	Thu Jan 23 03:57:15 2014 +0200
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,336 +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 <stdlib.h>
   40.23 -#include <math.h>
   40.24 -#include "vmath.h"
   40.25 -
   40.26 -/** Numerical calculation of integrals using simpson's rule */
   40.27 -scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples)
   40.28 -{
   40.29 -	int i;
   40.30 -	scalar_t h = (high - low) / (scalar_t)samples;
   40.31 -	scalar_t sum = 0.0;
   40.32 -
   40.33 -	for(i=0; i<samples+1; i++) {
   40.34 -		scalar_t y = f((scalar_t)i * h + low);
   40.35 -		sum += ((!i || i == samples) ? y : ((i % 2) ? 4.0 * y : 2.0 * y)) * (h / 3.0);
   40.36 -	}
   40.37 -	return sum;
   40.38 -}
   40.39 -
   40.40 -/** Gaussuan function */
   40.41 -scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev)
   40.42 -{
   40.43 -	scalar_t exponent = -SQ(x - mean) / (2.0 * SQ(sdev));
   40.44 -	return 1.0 - -pow(M_E, exponent) / (sdev * sqrt(TWO_PI));
   40.45 -}
   40.46 -
   40.47 -
   40.48 -/** b-spline approximation */
   40.49 -scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t)
   40.50 -{
   40.51 -	vec4_t tmp;
   40.52 -	scalar_t tsq = t * t;
   40.53 -
   40.54 -	static mat4_t bspline_mat = {
   40.55 -		{-1,  3, -3,  1},
   40.56 -		{3, -6,  3,  0},
   40.57 -		{-3,  0,  3,  0},
   40.58 -		{1,  4,  1,  0}
   40.59 -	};
   40.60 -
   40.61 -	tmp = v4_scale(v4_transform(v4_cons(a, b, c, d), bspline_mat), 1.0 / 6.0);
   40.62 -	return v4_dot(v4_cons(tsq * t, tsq, t, 1.0), tmp);
   40.63 -}
   40.64 -
   40.65 -/** Catmull-rom spline interpolation */
   40.66 -scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t)
   40.67 -{
   40.68 -	vec4_t tmp;
   40.69 -	scalar_t tsq = t * t;
   40.70 -
   40.71 -	static mat4_t crspline_mat = {
   40.72 -		{-1,  3, -3,  1},
   40.73 -		{2, -5,  4, -1},
   40.74 -		{-1,  0,  1,  0},
   40.75 -		{0,  2,  0,  0}
   40.76 -	};
   40.77 -
   40.78 -	tmp = v4_scale(v4_transform(v4_cons(a, b, c, d), crspline_mat), 0.5);
   40.79 -	return v4_dot(v4_cons(tsq * t, tsq, t, 1.0), tmp);
   40.80 -}
   40.81 -
   40.82 -/** Bezier interpolation */
   40.83 -scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t)
   40.84 -{
   40.85 -	scalar_t omt, omt3, t3, f;
   40.86 -	t3 = t * t * t;
   40.87 -	omt = 1.0f - t;
   40.88 -	omt3 = omt * omt * omt;
   40.89 -	f = 3 * t * omt;
   40.90 -
   40.91 -	return (a * omt3) + (b * f * omt) + (c * f * t) + (d * t3);
   40.92 -}
   40.93 -
   40.94 -/* ---- Ken Perlin's implementation of noise ---- */
   40.95 -
   40.96 -#define B	0x100
   40.97 -#define BM	0xff
   40.98 -#define N	0x1000
   40.99 -#define NP	12   /* 2^N */
  40.100 -#define NM	0xfff
  40.101 -
  40.102 -#define s_curve(t) (t * t * (3.0f - 2.0f * t))
  40.103 -
  40.104 -#define setup(elem, b0, b1, r0, r1) \
  40.105 -	do {							\
  40.106 -		scalar_t t = elem + N;		\
  40.107 -		b0 = ((int)t) & BM;			\
  40.108 -		b1 = (b0 + 1) & BM;			\
  40.109 -		r0 = t - (int)t;			\
  40.110 -		r1 = r0 - 1.0f;				\
  40.111 -	} while(0)
  40.112 -
  40.113 -
  40.114 -static int perm[B + B + 2];			/* permuted index from g_n onto themselves */
  40.115 -static vec3_t grad3[B + B + 2];		/* 3D random gradients */
  40.116 -static vec2_t grad2[B + B + 2];		/* 2D random gradients */
  40.117 -static scalar_t grad1[B + B + 2];	/* 1D random ... slopes */
  40.118 -static int tables_valid;
  40.119 -
  40.120 -static void init_noise()
  40.121 -{
  40.122 -	int i;
  40.123 -
  40.124 -	/* calculate random gradients */
  40.125 -	for(i=0; i<B; i++) {
  40.126 -		perm[i] = i;	/* .. and initialize permutation mapping to identity */
  40.127 -
  40.128 -		grad1[i] = (scalar_t)((rand() % (B + B)) - B) / B;
  40.129 -
  40.130 -		grad2[i].x = (scalar_t)((rand() % (B + B)) - B) / B;
  40.131 -		grad2[i].y = (scalar_t)((rand() % (B + B)) - B) / B;
  40.132 -		grad2[i] = v2_normalize(grad2[i]);
  40.133 -
  40.134 -		grad3[i].x = (scalar_t)((rand() % (B + B)) - B) / B;
  40.135 -		grad3[i].y = (scalar_t)((rand() % (B + B)) - B) / B;
  40.136 -		grad3[i].z = (scalar_t)((rand() % (B + B)) - B) / B;
  40.137 -		grad3[i] = v3_normalize(grad3[i]);
  40.138 -	}
  40.139 -
  40.140 -	/* permute indices by swapping them randomly */
  40.141 -	for(i=0; i<B; i++) {
  40.142 -		int rand_idx = rand() % B;
  40.143 -
  40.144 -		int tmp = perm[i];
  40.145 -		perm[i] = perm[rand_idx];
  40.146 -		perm[rand_idx] = tmp;
  40.147 -	}
  40.148 -
  40.149 -	/* fill up the rest of the arrays by duplicating the existing gradients */
  40.150 -	/* and permutations */
  40.151 -	for(i=0; i<B+2; i++) {
  40.152 -		perm[B + i] = perm[i];
  40.153 -		grad1[B + i] = grad1[i];
  40.154 -		grad2[B + i] = grad2[i];
  40.155 -		grad3[B + i] = grad3[i];
  40.156 -	}
  40.157 -}
  40.158 -
  40.159 -scalar_t noise1(scalar_t x)
  40.160 -{
  40.161 -	int bx0, bx1;
  40.162 -	scalar_t rx0, rx1, sx, u, v;
  40.163 -
  40.164 -	if(!tables_valid) {
  40.165 -		init_noise();
  40.166 -		tables_valid = 1;
  40.167 -	}
  40.168 -
  40.169 -	setup(x, bx0, bx1, rx0, rx1);
  40.170 -	sx = s_curve(rx0);
  40.171 -	u = rx0 * grad1[perm[bx0]];
  40.172 -	v = rx1 * grad1[perm[bx1]];
  40.173 -
  40.174 -	return lerp(u, v, sx);
  40.175 -}
  40.176 -
  40.177 -scalar_t noise2(scalar_t x, scalar_t y)
  40.178 -{
  40.179 -	int i, j, b00, b10, b01, b11;
  40.180 -	int bx0, bx1, by0, by1;
  40.181 -	scalar_t rx0, rx1, ry0, ry1;
  40.182 -	scalar_t sx, sy, u, v, a, b;
  40.183 -
  40.184 -	if(!tables_valid) {
  40.185 -		init_noise();
  40.186 -		tables_valid = 1;
  40.187 -	}
  40.188 -
  40.189 -	setup(x, bx0, bx1, rx0, rx1);
  40.190 -	setup(y, by0, by1, ry0, ry1);
  40.191 -
  40.192 -	i = perm[bx0];
  40.193 -	j = perm[bx1];
  40.194 -
  40.195 -	b00 = perm[i + by0];
  40.196 -	b10 = perm[j + by0];
  40.197 -	b01 = perm[i + by1];
  40.198 -	b11 = perm[j + by1];
  40.199 -
  40.200 -	/* calculate hermite inteprolating factors */
  40.201 -	sx = s_curve(rx0);
  40.202 -	sy = s_curve(ry0);
  40.203 -
  40.204 -	/* interpolate along the left edge */
  40.205 -	u = v2_dot(grad2[b00], v2_cons(rx0, ry0));
  40.206 -	v = v2_dot(grad2[b10], v2_cons(rx1, ry0));
  40.207 -	a = lerp(u, v, sx);
  40.208 -
  40.209 -	/* interpolate along the right edge */
  40.210 -	u = v2_dot(grad2[b01], v2_cons(rx0, ry1));
  40.211 -	v = v2_dot(grad2[b11], v2_cons(rx1, ry1));
  40.212 -	b = lerp(u, v, sx);
  40.213 -
  40.214 -	/* interpolate between them */
  40.215 -	return lerp(a, b, sy);
  40.216 -}
  40.217 -
  40.218 -scalar_t noise3(scalar_t x, scalar_t y, scalar_t z)
  40.219 -{
  40.220 -	int i, j;
  40.221 -	int bx0, bx1, by0, by1, bz0, bz1;
  40.222 -	int b00, b10, b01, b11;
  40.223 -	scalar_t rx0, rx1, ry0, ry1, rz0, rz1;
  40.224 -	scalar_t sx, sy, sz;
  40.225 -	scalar_t u, v, a, b, c, d;
  40.226 -
  40.227 -	if(!tables_valid) {
  40.228 -		init_noise();
  40.229 -		tables_valid = 1;
  40.230 -	}
  40.231 -
  40.232 -	setup(x, bx0, bx1, rx0, rx1);
  40.233 -	setup(y, by0, by1, ry0, ry1);
  40.234 -	setup(z, bz0, bz1, rz0, rz1);
  40.235 -
  40.236 -	i = perm[bx0];
  40.237 -	j = perm[bx1];
  40.238 -
  40.239 -	b00 = perm[i + by0];
  40.240 -	b10 = perm[j + by0];
  40.241 -	b01 = perm[i + by1];
  40.242 -	b11 = perm[j + by1];
  40.243 -
  40.244 -	/* calculate hermite interpolating factors */
  40.245 -	sx = s_curve(rx0);
  40.246 -	sy = s_curve(ry0);
  40.247 -	sz = s_curve(rz0);
  40.248 -
  40.249 -	/* interpolate along the top slice of the cell */
  40.250 -	u = v3_dot(grad3[b00 + bz0], v3_cons(rx0, ry0, rz0));
  40.251 -	v = v3_dot(grad3[b10 + bz0], v3_cons(rx1, ry0, rz0));
  40.252 -	a = lerp(u, v, sx);
  40.253 -
  40.254 -	u = v3_dot(grad3[b01 + bz0], v3_cons(rx0, ry1, rz0));
  40.255 -	v = v3_dot(grad3[b11 + bz0], v3_cons(rx1, ry1, rz0));
  40.256 -	b = lerp(u, v, sx);
  40.257 -
  40.258 -	c = lerp(a, b, sy);
  40.259 -
  40.260 -	/* interpolate along the bottom slice of the cell */
  40.261 -	u = v3_dot(grad3[b00 + bz0], v3_cons(rx0, ry0, rz1));
  40.262 -	v = v3_dot(grad3[b10 + bz0], v3_cons(rx1, ry0, rz1));
  40.263 -	a = lerp(u, v, sx);
  40.264 -
  40.265 -	u = v3_dot(grad3[b01 + bz0], v3_cons(rx0, ry1, rz1));
  40.266 -	v = v3_dot(grad3[b11 + bz0], v3_cons(rx1, ry1, rz1));
  40.267 -	b = lerp(u, v, sx);
  40.268 -
  40.269 -	d = lerp(a, b, sy);
  40.270 -
  40.271 -	/* interpolate between slices */
  40.272 -	return lerp(c, d, sz);
  40.273 -}
  40.274 -
  40.275 -scalar_t fbm1(scalar_t x, int octaves)
  40.276 -{
  40.277 -	int i;
  40.278 -	scalar_t res = 0.0f, freq = 1.0f;
  40.279 -	for(i=0; i<octaves; i++) {
  40.280 -		res += noise1(x * freq) / freq;
  40.281 -		freq *= 2.0f;
  40.282 -	}
  40.283 -	return res;
  40.284 -}
  40.285 -
  40.286 -scalar_t fbm2(scalar_t x, scalar_t y, int octaves)
  40.287 -{
  40.288 -	int i;
  40.289 -	scalar_t res = 0.0f, freq = 1.0f;
  40.290 -	for(i=0; i<octaves; i++) {
  40.291 -		res += noise2(x * freq, y * freq) / freq;
  40.292 -		freq *= 2.0f;
  40.293 -	}
  40.294 -	return res;
  40.295 -}
  40.296 -
  40.297 -scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves)
  40.298 -{
  40.299 -	int i;
  40.300 -	scalar_t res = 0.0f, freq = 1.0f;
  40.301 -	for(i=0; i<octaves; i++) {
  40.302 -		res += noise3(x * freq, y * freq, z * freq) / freq;
  40.303 -		freq *= 2.0f;
  40.304 -	}
  40.305 -	return res;
  40.306 -}
  40.307 -
  40.308 -scalar_t turbulence1(scalar_t x, int octaves)
  40.309 -{
  40.310 -	int i;
  40.311 -	scalar_t res = 0.0f, freq = 1.0f;
  40.312 -	for(i=0; i<octaves; i++) {
  40.313 -		res += fabs(noise1(x * freq) / freq);
  40.314 -		freq *= 2.0f;
  40.315 -	}
  40.316 -	return res;
  40.317 -}
  40.318 -
  40.319 -scalar_t turbulence2(scalar_t x, scalar_t y, int octaves)
  40.320 -{
  40.321 -	int i;
  40.322 -	scalar_t res = 0.0f, freq = 1.0f;
  40.323 -	for(i=0; i<octaves; i++) {
  40.324 -		res += fabs(noise2(x * freq, y * freq) / freq);
  40.325 -		freq *= 2.0f;
  40.326 -	}
  40.327 -	return res;
  40.328 -}
  40.329 -
  40.330 -scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves)
  40.331 -{
  40.332 -	int i;
  40.333 -	scalar_t res = 0.0f, freq = 1.0f;
  40.334 -	for(i=0; i<octaves; i++) {
  40.335 -		res += fabs(noise3(x * freq, y * freq, z * freq) / freq);
  40.336 -		freq *= 2.0f;
  40.337 -	}
  40.338 -	return res;
  40.339 -}
    41.1 --- a/libs/vmath/vmath.h	Thu Jan 23 03:57:15 2014 +0200
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,94 +0,0 @@
    41.4 -/*
    41.5 -libvmath - a vector math library
    41.6 -Copyright (C) 2004-2013 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 -#ifndef VMATH_H_
   41.23 -#define VMATH_H_
   41.24 -
   41.25 -#include <math.h>
   41.26 -#include "vmath_types.h"
   41.27 -
   41.28 -#ifndef M_PI
   41.29 -#define M_PI	PI
   41.30 -#endif
   41.31 -
   41.32 -#ifndef M_E
   41.33 -#define M_E				2.718281828459045
   41.34 -#endif
   41.35 -
   41.36 -#define PI				3.141592653589793
   41.37 -#define HALF_PI			1.570796326794897
   41.38 -#define QUARTER_PI		0.785398163397448
   41.39 -#define TWO_PI			6.283185307179586
   41.40 -
   41.41 -
   41.42 -#define RAD_TO_DEG(a) ((((scalar_t)a) * 360.0) / TWO_PI)
   41.43 -#define DEG_TO_RAD(a) (((scalar_t)a) * (PI / 180.0))
   41.44 -
   41.45 -#define SQ(x) ((x) * (x))
   41.46 -
   41.47 -#define MIN(a, b)	((a) < (b) ? (a) : (b))
   41.48 -#define MAX(a, b)	((a) > (b) ? (a) : (b))
   41.49 -
   41.50 -#ifndef __GNUC__
   41.51 -#define round(x)	((x) >= 0 ? (x) + 0.5 : (x) - 0.5)
   41.52 -#endif
   41.53 -
   41.54 -#ifdef __cplusplus
   41.55 -extern "C" {
   41.56 -#endif	/* __cplusplus */
   41.57 -
   41.58 -static VMATH_INLINE scalar_t smoothstep(float a, float b, float x);
   41.59 -
   41.60 -static VMATH_INLINE scalar_t frand(scalar_t range);
   41.61 -static VMATH_INLINE vec3_t sphrand(scalar_t rad);
   41.62 -
   41.63 -scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples);
   41.64 -scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev);
   41.65 -
   41.66 -static VMATH_INLINE scalar_t lerp(scalar_t a, scalar_t b, scalar_t t);
   41.67 -
   41.68 -scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
   41.69 -scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
   41.70 -scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
   41.71 -
   41.72 -scalar_t noise1(scalar_t x);
   41.73 -scalar_t noise2(scalar_t x, scalar_t y);
   41.74 -scalar_t noise3(scalar_t x, scalar_t y, scalar_t z);
   41.75 -
   41.76 -scalar_t fbm1(scalar_t x, int octaves);
   41.77 -scalar_t fbm2(scalar_t x, scalar_t y, int octaves);
   41.78 -scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves);
   41.79 -
   41.80 -scalar_t turbulence1(scalar_t x, int octaves);
   41.81 -scalar_t turbulence2(scalar_t x, scalar_t y, int octaves);
   41.82 -scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves);
   41.83 -
   41.84 -#ifdef __cplusplus
   41.85 -}
   41.86 -#endif	/* __cplusplus */
   41.87 -
   41.88 -#include "vmath.inl"
   41.89 -
   41.90 -#include "vector.h"
   41.91 -#include "matrix.h"
   41.92 -#include "quat.h"
   41.93 -#include "sphvec.h"
   41.94 -#include "ray.h"
   41.95 -#include "geom.h"
   41.96 -
   41.97 -#endif	/* VMATH_H_ */
    42.1 --- a/libs/vmath/vmath.inl	Thu Jan 23 03:57:15 2014 +0200
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,56 +0,0 @@
    42.4 -/*
    42.5 -libvmath - a vector math library
    42.6 -Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
    42.7 -
    42.8 -This program is free software: you can redistribute it and/or modify
    42.9 -it under the terms of the GNU Lesser General Public License as published
   42.10 -by the Free Software Foundation, either version 3 of the License, or
   42.11 -(at your option) any later version.
   42.12 -
   42.13 -This program is distributed in the hope that it will be useful,
   42.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   42.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   42.16 -GNU Lesser General Public License for more details.
   42.17 -
   42.18 -You should have received a copy of the GNU Lesser General Public License
   42.19 -along with this program.  If not, see <http://www.gnu.org/licenses/>.
   42.20 -*/
   42.21 -
   42.22 -#include <stdlib.h>
   42.23 -
   42.24 -static VMATH_INLINE scalar_t smoothstep(float a, float b, float x)
   42.25 -{
   42.26 -	if(x < a) return 0.0;
   42.27 -	if(x >= b) return 1.0;
   42.28 -
   42.29 -	x = (x - a) / (b - a);
   42.30 -	return x * x * (3.0 - 2.0 * x);
   42.31 -}
   42.32 -
   42.33 -/** Generates a random number in [0, range) */
   42.34 -static VMATH_INLINE scalar_t frand(scalar_t range)
   42.35 -{
   42.36 -	return range * (scalar_t)rand() / (scalar_t)RAND_MAX;
   42.37 -}
   42.38 -
   42.39 -/** Generates a random vector on the surface of a sphere */
   42.40 -static VMATH_INLINE vec3_t sphrand(scalar_t rad)
   42.41 -{
   42.42 -	scalar_t u = (scalar_t)rand() / RAND_MAX;
   42.43 -	scalar_t v = (scalar_t)rand() / RAND_MAX;
   42.44 -
   42.45 -	scalar_t theta = 2.0 * M_PI * u;
   42.46 -	scalar_t phi = acos(2.0 * v - 1.0);
   42.47 -
   42.48 -	vec3_t res;
   42.49 -	res.x = rad * cos(theta) * sin(phi);
   42.50 -	res.y = rad * sin(theta) * sin(phi);
   42.51 -	res.z = rad * cos(phi);
   42.52 -	return res;
   42.53 -}
   42.54 -
   42.55 -/** linear interpolation */
   42.56 -static VMATH_INLINE scalar_t lerp(scalar_t a, scalar_t b, scalar_t t)
   42.57 -{
   42.58 -	return a + (b - a) * t;
   42.59 -}
    43.1 --- a/libs/vmath/vmath_config.h	Thu Jan 23 03:57:15 2014 +0200
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,21 +0,0 @@
    43.4 -#ifndef VMATH_CONFIG_H_
    43.5 -#define VMATH_CONFIG_H_
    43.6 -
    43.7 -#ifdef __cplusplus
    43.8 -#define VMATH_INLINE inline
    43.9 -#elif (__STDC_VERSION__ < 199999)
   43.10 -#if defined(__GNUC__) || defined(_MSC_VER)
   43.11 -#define VMATH_INLINE __inline
   43.12 -#else
   43.13 -#define VMATH_INLINE
   43.14 -
   43.15 -#ifdef VECTOR_H_
   43.16 -#warning "compiling vector operations without inline, performance might suffer"
   43.17 -#endif	/* VECTOR_H_ */
   43.18 -
   43.19 -#endif	/* gcc/msvc */
   43.20 -#endif	/* not C99 */
   43.21 -
   43.22 -#define SINGLE_PRECISION_MATH
   43.23 -
   43.24 -#endif	/* VMATH_CONFIG_H_ */
    44.1 --- a/libs/vmath/vmath_types.h	Thu Jan 23 03:57:15 2014 +0200
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,58 +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 -#ifndef VMATH_TYPES_H_
   44.23 -#define VMATH_TYPES_H_
   44.24 -
   44.25 -#include "vmath_config.h"
   44.26 -
   44.27 -#define SMALL_NUMBER	1.e-4
   44.28 -#define XSMALL_NUMBER	1.e-8
   44.29 -#define ERROR_MARGIN	1.e-6
   44.30 -
   44.31 -
   44.32 -#ifdef SINGLE_PRECISION_MATH
   44.33 -typedef float scalar_t;
   44.34 -#else
   44.35 -typedef double scalar_t;
   44.36 -#endif	/* floating point precision */
   44.37 -
   44.38 -/* vectors */
   44.39 -typedef struct { scalar_t x, y; } vec2_t;
   44.40 -typedef struct { scalar_t x, y, z; } vec3_t;
   44.41 -typedef struct { scalar_t x, y, z, w; } vec4_t;
   44.42 -
   44.43 -/* quaternions */
   44.44 -typedef vec4_t quat_t;
   44.45 -
   44.46 -/* matrices */
   44.47 -typedef scalar_t mat3_t[3][3];
   44.48 -typedef scalar_t mat4_t[4][4];
   44.49 -
   44.50 -
   44.51 -#ifdef __cplusplus
   44.52 -class Vector2;
   44.53 -class Vector3;
   44.54 -class Vector4;
   44.55 -class Quaternion;
   44.56 -class Matrix3x3;
   44.57 -class Matrix4x4;
   44.58 -class SphVector;
   44.59 -#endif	/* __cplusplus */
   44.60 -
   44.61 -#endif	/* VMATH_TYPES_H_ */
    45.1 --- a/src/goat3d_writexml.cc	Thu Jan 23 03:57:15 2014 +0200
    45.2 +++ b/src/goat3d_writexml.cc	Tue Mar 25 03:19:55 2014 +0200
    45.3 @@ -27,7 +27,7 @@
    45.4  		write_material(this, io, materials[i], 1);
    45.5  	}
    45.6  	for(size_t i=0; i<meshes.size(); i++) {
    45.7 -		write_mesh(this, io, meshes[i], i, 1);
    45.8 +		write_mesh(this, io, meshes[i], (int)i, 1);
    45.9  	}
   45.10  	for(size_t i=0; i<lights.size(); i++) {
   45.11  		write_light(this, io, lights[i], 1);