Initial revision

This commit is contained in:
Hans Lambermont
2002-10-12 11:37:38 +00:00
commit 12315f4d0e
1699 changed files with 444708 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/**
* blenlib/BLI_editVert.h mar 2001 Nzc
*
* These callbacks are needed in the lib
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BLI_CALLBACKS_H
#define BLI_CALLBACKS_H
// This is blenlib internal only
void callLocalErrorCallBack(char* msg);
int callLocalInterruptCallBack(void);
#endif

View File

@@ -0,0 +1,115 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Dynamically sized string ADT
*/
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
/***/
typedef struct DynStrElem DynStrElem;
struct DynStrElem {
DynStrElem *next;
char *str;
};
struct DynStr {
DynStrElem *elems, *last;
int curlen;
};
/***/
DynStr *BLI_dynstr_new(void) {
DynStr *ds= MEM_mallocN(sizeof(*ds), "DynStr");
ds->elems= ds->last= NULL;
ds->curlen= 0;
return ds;
}
void BLI_dynstr_append(DynStr *ds, char *cstr) {
DynStrElem *dse= malloc(sizeof(*dse));
int cstrlen= strlen(cstr);
dse->str= malloc(cstrlen+1);
memcpy(dse->str, cstr, cstrlen+1);
dse->next= NULL;
if (!ds->last)
ds->last= ds->elems= dse;
else
ds->last= ds->last->next= dse;
ds->curlen+= cstrlen;
}
int BLI_dynstr_get_len(DynStr *ds) {
return ds->curlen;
}
char *BLI_dynstr_get_cstring(DynStr *ds) {
char *s, *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring");
DynStrElem *dse;
for (s= rets, dse= ds->elems; dse; dse= dse->next) {
int slen= strlen(dse->str);
memcpy(s, dse->str, slen);
s+= slen;
}
rets[ds->curlen]= '\0';
return rets;
}
void BLI_dynstr_free(DynStr *ds) {
DynStrElem *dse;
for (dse= ds->elems; dse; ) {
DynStrElem *n= dse->next;
free(dse->str);
free(dse);
dse= n;
}
MEM_freeN(ds);
}

View File

@@ -0,0 +1,49 @@
/**
* blenlib/BLI_listBase.h mar 2001 Nzc
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
* More low-level fileops from Daniel Dunbar. Two functions were also
* defined in storage.c. These are the old fop_ prefixes. There is
* definitely some redundancy here!
* */
#ifndef BLI_FILEOPS_H
#define BLI_FILEOPS_H
char *first_slash(char *string);
/* only for the sane unix world: direct calls to system functions :( */
#ifndef WIN32
void BLI_setCmdCallBack(int (*f)(char*));
#endif
#endif

View File

@@ -0,0 +1,184 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* A general (pointer -> pointer) hash table ADT
*/
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
/***/
static unsigned int hashsizes[]= {
1, 3, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209,
16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169,
4194319, 8388617, 16777259, 33554467, 67108879, 134217757,
268435459
};
/***/
typedef struct Entry Entry;
struct Entry {
Entry *next;
void *key, *val;
};
struct GHash {
GHashHashFP hashfp;
GHashCmpFP cmpfp;
Entry **buckets;
int nbuckets, nentries, cursize;
};
/***/
GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp) {
GHash *gh= MEM_mallocN(sizeof(*gh), "GHash");
gh->hashfp= hashfp;
gh->cmpfp= cmpfp;
gh->cursize= 0;
gh->nentries= 0;
gh->nbuckets= hashsizes[gh->cursize];
gh->buckets= malloc(gh->nbuckets*sizeof(*gh->buckets));
memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets));
return gh;
}
void BLI_ghash_insert(GHash *gh, void *key, void *val) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e= malloc(sizeof(*e));
e->key= key;
e->val= val;
e->next= gh->buckets[hash];
gh->buckets[hash]= e;
if (++gh->nentries>gh->nbuckets*3) {
Entry *e, **old= gh->buckets;
int i, nold= gh->nbuckets;
gh->nbuckets= hashsizes[++gh->cursize];
gh->buckets= malloc(gh->nbuckets*sizeof(*gh->buckets));
memset(gh->buckets, 0, gh->nbuckets*sizeof(*gh->buckets));
for (i=0; i<nold; i++) {
for (e= old[i]; e;) {
Entry *n= e->next;
hash= gh->hashfp(e->key)%gh->nbuckets;
e->next= gh->buckets[hash];
gh->buckets[hash]= e;
e= n;
}
}
free(old);
}
}
void* BLI_ghash_lookup(GHash *gh, void *key) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e;
for (e= gh->buckets[hash]; e; e= e->next)
if (gh->cmpfp(key, e->key)==0)
return e->val;
return NULL;
}
int BLI_ghash_haskey(GHash *gh, void *key) {
unsigned int hash= gh->hashfp(key)%gh->nbuckets;
Entry *e;
for (e= gh->buckets[hash]; e; e= e->next)
if (gh->cmpfp(key, e->key)==0)
return 1;
return 0;
}
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) {
int i;
for (i=0; i<gh->nbuckets; i++) {
Entry *e;
for (e= gh->buckets[i]; e; ) {
Entry *n= e->next;
if (keyfreefp) keyfreefp(e->key);
if (valfreefp) valfreefp(e->val);
free(e);
e= n;
}
}
free(gh->buckets);
MEM_freeN(gh);
}
/***/
unsigned int BLI_ghashutil_ptrhash(void *key) {
return (unsigned int) key;
}
int BLI_ghashutil_ptrcmp(void *a, void *b) {
if (a==b)
return 0;
else
return (a<b)?-1:1;
}
unsigned int BLI_ghashutil_strhash(void *ptr) {
char *s= ptr;
unsigned int i= 0;
unsigned char c;
while (c= *s++)
i= i*37 + c;
return i;
}
int BLI_ghashutil_strcmp(void *a, void *b) {
return strcmp(a, b);
}

View File

@@ -0,0 +1,98 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Support for linked lists.
*/
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_linklist.h"
#include "BLI_memarena.h"
int BLI_linklist_length(LinkNode *list) {
if (0) {
return list?(1+BLI_linklist_length(list->next)):0;
} else {
int len;
for (len=0; list; list= list->next)
len++;
return len;
}
}
void BLI_linklist_reverse(LinkNode **listp) {
LinkNode *rhead= NULL, *cur= *listp;
while (cur) {
LinkNode *next= cur->next;
cur->next= rhead;
rhead= cur;
cur= next;
}
*listp= rhead;
}
void BLI_linklist_prepend(LinkNode **listp, void *ptr) {
LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink");
nlink->link= ptr;
nlink->next= *listp;
*listp= nlink;
}
void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) {
LinkNode *nlink= BLI_memarena_alloc(ma, sizeof(*nlink));
nlink->link= ptr;
nlink->next= *listp;
*listp= nlink;
}
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) {
while (list) {
LinkNode *next= list->next;
if (freefunc)
freefunc(list->link);
MEM_freeN(list);
list= next;
}
}
void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc) {
for (; list; list= list->next)
applyfunc(list->link);
}

View File

@@ -0,0 +1,80 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Efficient memory allocation for lots of similar small chunks.
*/
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_memarena.h"
#include "BLI_linklist.h"
struct MemArena {
unsigned char *curbuf;
int bufsize, cursize;
LinkNode *bufs;
};
MemArena *BLI_memarena_new(int bufsize) {
MemArena *ma= MEM_callocN(sizeof(*ma), "memarena");
ma->bufsize= bufsize;
return ma;
}
void BLI_memarena_free(MemArena *ma) {
BLI_linklist_free(ma->bufs, MEM_freeN);
MEM_freeN(ma);
}
/* amt must be power of two */
#define PADUP(num, amt) ((num+(amt-1))&~(amt-1))
void *BLI_memarena_alloc(MemArena *ma, int size) {
void *ptr;
/* ensure proper alignment by rounding
* size up to multiple of 8 */
size= PADUP(size, 8);
if (size>=ma->cursize) {
ma->cursize= (size>ma->bufsize)?size:ma->bufsize;
ma->curbuf= MEM_mallocN(ma->cursize, "ma->curbuf");
BLI_linklist_prepend(&ma->bufs, ma->curbuf);
}
ptr= ma->curbuf;
ma->curbuf+= size;
ma->cursize-= size;
return ptr;
}

View File

@@ -0,0 +1,41 @@
/**
* blenlib/BLI_scanfill.h mar 2001 Nzc
*
* Filling meshes.
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BLI_SCANFILL_H
#define BLI_SCANFILL_H
#endif

View File

@@ -0,0 +1,40 @@
/* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BLI_STORAGE_H
#define BLI_STORAGE_H
#include "BLI_storage_types.h"
void BLI_adddirstrings(void);
void BLI_builddir(char *dirname, char *relname);
int BLI_compare(struct direntry *entry1, struct direntry *entry2);
#endif /* BLI_STORAGE_H */

View File

@@ -0,0 +1,47 @@
/**
* blenlib/BLI_storage_types.h
*
* Some types for dealing with directories
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BLI_UTIL_H
#define BLI_UTIL_H
#define mallocstructN(x,y,name) (x*)MEM_mallocN((y)* sizeof(x),name)
#define callocstructN(x,y,name) (x*)MEM_callocN((y)* sizeof(x),name)
struct ListBase;
/* void addlisttolist(struct ListBase *list1, struct ListBase *list2); */
#endif

View File

@@ -0,0 +1,51 @@
#
# $Id$
#
# ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. The Blender
# Foundation also sells licenses for use in proprietary software under
# the Blender License. See http://www.blender.org/BL/ for information
# about this.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL/BL DUAL LICENSE BLOCK *****
#
#
LIBNAME = blenlib
DIR = $(OCGDIR)/blender/$(LIBNAME)
include nan_compile.mk
ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows"))
CFLAGS += -funsigned-char
endif
CPPFLAGS += $(LEVEL_2_C_WARNINGS)
# path to SDNA types
CPPFLAGS += -I../../makesdna
# path to our own external headerfiles
CPPFLAGS += -I..
# path to the guarded memory allocator
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,146 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "../PIL_dynlib.h"
/*
* XXX, should use mallocN so we can see
* handle's not being released. fixme zr
*/
#ifdef WIN32
#include <windows.h>
struct PILdynlib {
void *handle;
};
PILdynlib *PIL_dynlib_open(char *name) {
void *handle= LoadLibrary(name);
if (handle) {
PILdynlib *lib= malloc(sizeof(*lib));
lib->handle= handle;
return lib;
} else {
return NULL;
}
}
void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
return GetProcAddress(lib->handle, symname);
}
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
int err= GetLastError();
if (err) {
static char buf[1024];
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf,
sizeof(buf),
NULL))
return buf;
}
return NULL;
}
void PIL_dynlib_close(PILdynlib *lib) {
FreeLibrary(lib->handle);
free(lib);
}
#else
#ifdef __APPLE__
PILdynlib *PIL_dynlib_open(char *name) {
return NULL;
}
void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
return NULL;
}
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
return "Plugins are currently unsupported on OSX";
}
void PIL_dynlib_close(PILdynlib *lib) {
;
}
#else /* Unix */
#include <dlfcn.h>
struct PILdynlib {
void *handle;
};
PILdynlib *PIL_dynlib_open(char *name) {
void *handle= dlopen(name, RTLD_LAZY);
if (handle) {
PILdynlib *lib= malloc(sizeof(*lib));
lib->handle= handle;
return lib;
} else {
return NULL;
}
}
void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) {
return dlsym(lib->handle, symname);
}
char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
return dlerror();
}
void PIL_dynlib_close(PILdynlib *lib) {
dlclose(lib->handle);
free(lib);
}
#endif
#endif

View File

@@ -0,0 +1,293 @@
/*
* blenlib/fileops.h
*
* cleaned up (a bit) mar-01 nzc
*
* More low-level file things.
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include <stdio.h>
#ifdef WIN32
#include "BLI_winstuff.h"
#else
#include <sys/param.h>
#endif
#include "BLI_blenlib.h"
#include "BLI_storage.h"
#include "BLI_fileops.h"
#include "BLI_callbacks.h"
/* implementations: */
char *first_slash(char *string) {
char *ffslash, *fbslash;
ffslash= strchr(string, '/');
fbslash= strchr(string, '\\');
if (!ffslash) return fbslash;
else if (!fbslash) return ffslash;
if ((int)ffslash < (int)fbslash) return ffslash;
else return fbslash;
}
char *BLI_last_slash(char *string) {
char *lfslash, *lbslash;
lfslash= strrchr(string, '/');
lbslash= strrchr(string, '\\');
if (!lfslash) return lbslash;
else if (!lbslash) return lfslash;
if ((int)lfslash < (int)lbslash) return lbslash;
else return lfslash;
}
#ifdef WIN32
static char str[MAXPATHLEN+12];
int BLI_delete(char *file, int dir, int recursive) {
int err;
if (recursive) {
callLocalErrorCallBack("Recursive delete is unsupported on Windows");
err= 1;
} else if (dir) {
err= !RemoveDirectory(file);
if (err) printf ("Unable to remove directory");
} else {
err= !DeleteFile(file);
if (err) callLocalErrorCallBack("Unable to delete file");
}
return err;
}
int BLI_touch(char *file) {
callLocalErrorCallBack("Touching files is unsupported on Windows");
return 1;
}
int BLI_move(char *file, char *to) {
int err;
// windows doesn't support moveing to a directory
// it has to be 'mv filename filename' and not
// 'mv filename destdir'
strcpy(str, to);
// points 'to' to a directory ?
if (BLI_last_slash(str) == (str + strlen(str) - 1)) {
if (BLI_last_slash(file) != NULL) {
strcat(str, BLI_last_slash(file) + 1);
}
}
err= !MoveFile(file, str);
if (err) {
callLocalErrorCallBack("Unable to move file");
printf(" Move from '%s' to '%s' failed\n", file, str);
}
return err;
}
int BLI_copy_fileops(char *file, char *to) {
int err;
// windows doesn't support copying to a directory
// it has to be 'cp filename filename' and not
// 'cp filename destdir'
strcpy(str, to);
// points 'to' to a directory ?
if (BLI_last_slash(str) == (str + strlen(str) - 1)) {
if (BLI_last_slash(file) != NULL) {
strcat(str, BLI_last_slash(file) + 1);
}
}
err= !CopyFile(file,str,FALSE);
if (err) {
callLocalErrorCallBack("Unable to copy file!");
printf(" Copy from '%s' to '%s' failed\n", file, str);
}
return err;
}
int BLI_link(char *file, char *to) {
callLocalErrorCallBack("Linking files is unsupported on Windows");
return 1;
}
int BLI_backup(char *file, char *from, char *to) {
callLocalErrorCallBack("Backing up files is unsupported on Windows");
return 1;
}
int BLI_exists(char *file) {
return (GetFileAttributes(file) != 0xFFFFFFFF);
}
void BLI_recurdir_fileops(char *dirname) {
char *lslash;
char tmp[MAXPATHLEN];
// First remove possible slash at the end of the dirname.
// This routine otherwise tries to create
// blah1/blah2/ (with slash) after creating
// blah1/blah2 (without slash)
strcpy(tmp, dirname);
lslash= BLI_last_slash(tmp);
if (lslash == tmp + strlen(tmp) - 1) {
*lslash = 0;
}
if (BLI_exists(tmp)) return;
lslash= BLI_last_slash(tmp);
if (lslash) {
/* Split about the last slash and recurse */
*lslash = 0;
BLI_recurdir_fileops(tmp);
}
if (!CreateDirectory(dirname, NULL))
callLocalErrorCallBack("Unable to create directory\n");
}
int BLI_rename(char *from, char *to) {
if (!BLI_exists(from)) return 0;
if (BLI_exists(to))
if(BLI_delete(to, 0, 0)) return 1;
return rename(from, to);
}
#else /* The sane UNIX world */
/*
* but the sane UNIX world is tied to the interface, and the system
* timer, and... We implement a callback mechanism. The system will
* have to initialise the callback before the functions will work!
* */
static char str[MAXPATHLEN+12];
int BLI_delete(char *file, int dir, int recursive) {
if (recursive) sprintf(str, "/bin/rm -rf %s", file);
else if (dir) sprintf(str, "/bin/rmdir \"%s\"", file);
else sprintf(str, "/bin/rm -f \"%s\"", file);
return system(str);
}
int BLI_touch(char *file)
{
if( BLI_exists("/bin/touch") )
sprintf(str, "/bin/touch %s", file);
else
sprintf(str, "/usr/bin/touch %s", file);
return system(str);
}
int BLI_move(char *file, char *to) {
sprintf(str, "/bin/mv -f %s %s", file, to);
return system(str);
}
int BLI_copy_fileops(char *file, char *to) {
sprintf(str, "/bin/cp -rf \"%s\" %s", file, to);
return system(str);
}
int BLI_link(char *file, char *to) {
sprintf(str, "/bin/ln -f %s %s", file, to);
return system(str);
}
int BLI_backup(char *file, char *from, char *to) {
sprintf(str, "/bin/su root -c 'cd %s; /bin/tar cf - \"%s\" | (/bin/cd %s; /bin/tar xf -)'", from, file, to);
return system(str);
}
int BLI_exists(char *file) {
return BLI_exist(file);
}
void BLI_recurdir_fileops(char *dirname) {
char *lslash;
char tmp[MAXPATHLEN];
if (BLI_exists(dirname)) return;
strcpy(tmp, dirname);
lslash= BLI_last_slash(tmp);
if (lslash) {
/* Split about the last slash and recurse */
*lslash = 0;
BLI_recurdir_fileops(tmp);
}
mkdir(dirname, 0777);
}
int BLI_rename(char *from, char *to) {
if (!BLI_exists(from)) return 0;
if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1;
return rename(from, to);
}
#endif

View File

@@ -0,0 +1,112 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_gsqueue.h"
typedef struct _GSQueueElem GSQueueElem;
struct _GSQueueElem {
GSQueueElem *next;
};
struct _GSQueue {
GSQueueElem *head;
GSQueueElem *tail;
int elem_size;
};
GSQueue *BLI_gsqueue_new(int elem_size)
{
GSQueue *gq= MEM_mallocN(sizeof(*gq), "gqueue_new");
gq->head= gq->tail= NULL;
gq->elem_size= elem_size;
return gq;
}
int BLI_gsqueue_is_empty(GSQueue *gq)
{
return (gq->head==NULL);
}
void BLI_gsqueue_peek(GSQueue *gq, void *item_r)
{
memcpy(item_r, &gq->head[1], gq->elem_size);
}
void BLI_gsqueue_pop(GSQueue *gq, void *item_r)
{
GSQueueElem *elem= gq->head;
if (elem==gq->tail) {
gq->head= gq->tail= NULL;
} else {
gq->head= gq->head->next;
}
if (item_r) memcpy(item_r, &elem[1], gq->elem_size);
MEM_freeN(elem);
}
void BLI_gsqueue_push(GSQueue *gq, void *item)
{
GSQueueElem *elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push");
memcpy(&elem[1], item, gq->elem_size);
elem->next= NULL;
if (BLI_gsqueue_is_empty(gq)) {
gq->tail= gq->head= elem;
} else {
gq->tail= gq->tail->next= elem;
}
}
void BLI_gsqueue_pushback(GSQueue *gq, void *item)
{
GSQueueElem *elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push");
memcpy(&elem[1], item, gq->elem_size);
elem->next= gq->head;
if (BLI_gsqueue_is_empty(gq)) {
gq->head= gq->tail= elem;
} else {
gq->head= elem;
}
}
void BLI_gsqueue_free(GSQueue *gq)
{
while (gq->head) {
BLI_gsqueue_pop(gq, NULL);
}
MEM_freeN(gq);
}

View File

@@ -0,0 +1,440 @@
/*
*
* Some matrix operations.
*
* Always use
* - vector with x components : float x[3], int x[3], etc
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/* ------------------------------------------------------------------------- */
#include <string.h>
#include "MTC_matrixops.h"
#include "MTC_vectorops.h"
/* ------------------------------------------------------------------------- */
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#ifdef __sun__
#include <strings.h>
#endif
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
void MTC_Mat4CpyMat4(float m1[][4], float m2[][4])
{
memcpy(m1, m2, 4*4*sizeof(float));
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4MulSerie(float answ[][4],
float m1[][4], float m2[][4], float m3[][4],
float m4[][4], float m5[][4], float m6[][4],
float m7[][4], float m8[][4])
{
float temp[4][4];
if(m1==0 || m2==0) return;
MTC_Mat4MulMat4(answ, m2, m1);
if(m3) {
MTC_Mat4MulMat4(temp, m3, answ);
if(m4) {
MTC_Mat4MulMat4(answ, m4, temp);
if(m5) {
MTC_Mat4MulMat4(temp, m5, answ);
if(m6) {
MTC_Mat4MulMat4(answ, m6, temp);
if(m7) {
MTC_Mat4MulMat4(temp, m7, answ);
if(m8) {
MTC_Mat4MulMat4(answ, m8, temp);
}
else MTC_Mat4CpyMat4(answ, temp);
}
}
else MTC_Mat4CpyMat4(answ, temp);
}
}
else MTC_Mat4CpyMat4(answ, temp);
}
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4MulMat4(float m1[][4], float m2[][4], float m3[][4])
{
/* matrix product: c[j][k] = a[j][i].b[i][k] */
m1[0][0] = m2[0][0]*m3[0][0] + m2[0][1]*m3[1][0] + m2[0][2]*m3[2][0] + m2[0][3]*m3[3][0];
m1[0][1] = m2[0][0]*m3[0][1] + m2[0][1]*m3[1][1] + m2[0][2]*m3[2][1] + m2[0][3]*m3[3][1];
m1[0][2] = m2[0][0]*m3[0][2] + m2[0][1]*m3[1][2] + m2[0][2]*m3[2][2] + m2[0][3]*m3[3][2];
m1[0][3] = m2[0][0]*m3[0][3] + m2[0][1]*m3[1][3] + m2[0][2]*m3[2][3] + m2[0][3]*m3[3][3];
m1[1][0] = m2[1][0]*m3[0][0] + m2[1][1]*m3[1][0] + m2[1][2]*m3[2][0] + m2[1][3]*m3[3][0];
m1[1][1] = m2[1][0]*m3[0][1] + m2[1][1]*m3[1][1] + m2[1][2]*m3[2][1] + m2[1][3]*m3[3][1];
m1[1][2] = m2[1][0]*m3[0][2] + m2[1][1]*m3[1][2] + m2[1][2]*m3[2][2] + m2[1][3]*m3[3][2];
m1[1][3] = m2[1][0]*m3[0][3] + m2[1][1]*m3[1][3] + m2[1][2]*m3[2][3] + m2[1][3]*m3[3][3];
m1[2][0] = m2[2][0]*m3[0][0] + m2[2][1]*m3[1][0] + m2[2][2]*m3[2][0] + m2[2][3]*m3[3][0];
m1[2][1] = m2[2][0]*m3[0][1] + m2[2][1]*m3[1][1] + m2[2][2]*m3[2][1] + m2[2][3]*m3[3][1];
m1[2][2] = m2[2][0]*m3[0][2] + m2[2][1]*m3[1][2] + m2[2][2]*m3[2][2] + m2[2][3]*m3[3][2];
m1[2][3] = m2[2][0]*m3[0][3] + m2[2][1]*m3[1][3] + m2[2][2]*m3[2][3] + m2[2][3]*m3[3][3];
m1[3][0] = m2[3][0]*m3[0][0] + m2[3][1]*m3[1][0] + m2[3][2]*m3[2][0] + m2[3][3]*m3[3][0];
m1[3][1] = m2[3][0]*m3[0][1] + m2[3][1]*m3[1][1] + m2[3][2]*m3[2][1] + m2[3][3]*m3[3][1];
m1[3][2] = m2[3][0]*m3[0][2] + m2[3][1]*m3[1][2] + m2[3][2]*m3[2][2] + m2[3][3]*m3[3][2];
m1[3][3] = m2[3][0]*m3[0][3] + m2[3][1]*m3[1][3] + m2[3][2]*m3[2][3] + m2[3][3]*m3[3][3];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4MulVecfl(float mat[][4], float *vec)
{
float x,y;
x=vec[0];
y=vec[1];
vec[0]=x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2] + mat[3][0];
vec[1]=x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2] + mat[3][1];
vec[2]=x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2] + mat[3][2];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat3MulVecfl(float mat[][3], float *vec)
{
float x,y;
x=vec[0];
y=vec[1];
vec[0]= x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2];
vec[1]= x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2];
vec[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2];
}
/* ------------------------------------------------------------------------- */
int MTC_Mat4Invert(float inverse[][4], float mat[][4])
{
int i, j, k;
double temp;
float tempmat[4][4];
float max;
int maxj;
/* Set inverse to identity */
for (i=0; i<4; i++)
for (j=0; j<4; j++)
inverse[i][j] = 0;
for (i=0; i<4; i++)
inverse[i][i] = 1;
/* Copy original matrix so we don't mess it up */
for(i = 0; i < 4; i++)
for(j = 0; j <4; j++)
tempmat[i][j] = mat[i][j];
for(i = 0; i < 4; i++) {
/* Look for row with max pivot */
max = ABS(tempmat[i][i]);
maxj = i;
for(j = i + 1; j < 4; j++) {
if(ABS(tempmat[j][i]) > max) {
max = ABS(tempmat[j][i]);
maxj = j;
}
}
/* Swap rows if necessary */
if (maxj != i) {
for( k = 0; k < 4; k++) {
SWAP(float, tempmat[i][k], tempmat[maxj][k]);
SWAP(float, inverse[i][k], inverse[maxj][k]);
}
}
temp = tempmat[i][i];
if (temp == 0)
return 0; /* No non-zero pivot */
for(k = 0; k < 4; k++) {
tempmat[i][k] /= temp;
inverse[i][k] /= temp;
}
for(j = 0; j < 4; j++) {
if(j != i) {
temp = tempmat[j][i];
for(k = 0; k < 4; k++) {
tempmat[j][k] -= tempmat[i][k]*temp;
inverse[j][k] -= inverse[i][k]*temp;
}
}
}
}
return 1;
}
/* ------------------------------------------------------------------------- */
void MTC_Mat3CpyMat4(float m1[][3], float m2[][4])
{
m1[0][0]= m2[0][0];
m1[0][1]= m2[0][1];
m1[0][2]= m2[0][2];
m1[1][0]= m2[1][0];
m1[1][1]= m2[1][1];
m1[1][2]= m2[1][2];
m1[2][0]= m2[2][0];
m1[2][1]= m2[2][1];
m1[2][2]= m2[2][2];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat3CpyMat3(float m1[][3], float m2[][3])
{
memcpy(m1, m2, 3*3*sizeof(float));
}
/* ------------------------------------------------------------------------- */
/* void Mat3MulMat3(float m1[][3], float m3[][3], float m2[][3]) */
void MTC_Mat3MulMat3(float m1[][3], float m3[][3], float m2[][3])
{
/* be careful about this rewrite... */
/* m1[i][j] = m2[i][k]*m3[k][j], args are flipped! */
m1[0][0]= m2[0][0]*m3[0][0] + m2[0][1]*m3[1][0] + m2[0][2]*m3[2][0];
m1[0][1]= m2[0][0]*m3[0][1] + m2[0][1]*m3[1][1] + m2[0][2]*m3[2][1];
m1[0][2]= m2[0][0]*m3[0][2] + m2[0][1]*m3[1][2] + m2[0][2]*m3[2][2];
m1[1][0]= m2[1][0]*m3[0][0] + m2[1][1]*m3[1][0] + m2[1][2]*m3[2][0];
m1[1][1]= m2[1][0]*m3[0][1] + m2[1][1]*m3[1][1] + m2[1][2]*m3[2][1];
m1[1][2]= m2[1][0]*m3[0][2] + m2[1][1]*m3[1][2] + m2[1][2]*m3[2][2];
m1[2][0]= m2[2][0]*m3[0][0] + m2[2][1]*m3[1][0] + m2[2][2]*m3[2][0];
m1[2][1]= m2[2][0]*m3[0][1] + m2[2][1]*m3[1][1] + m2[2][2]*m3[2][1];
m1[2][2]= m2[2][0]*m3[0][2] + m2[2][1]*m3[1][2] + m2[2][2]*m3[2][2];
/* m1[0]= m2[0]*m3[0] + m2[1]*m3[3] + m2[2]*m3[6]; */
/* m1[1]= m2[0]*m3[1] + m2[1]*m3[4] + m2[2]*m3[7]; */
/* m1[2]= m2[0]*m3[2] + m2[1]*m3[5] + m2[2]*m3[8]; */
/* m1+=3; */
/* m2+=3; */
/* m1[0]= m2[0]*m3[0] + m2[1]*m3[3] + m2[2]*m3[6]; */
/* m1[1]= m2[0]*m3[1] + m2[1]*m3[4] + m2[2]*m3[7]; */
/* m1[2]= m2[0]*m3[2] + m2[1]*m3[5] + m2[2]*m3[8]; */
/* m1+=3; */
/* m2+=3; */
/* m1[0]= m2[0]*m3[0] + m2[1]*m3[3] + m2[2]*m3[6]; */
/* m1[1]= m2[0]*m3[1] + m2[1]*m3[4] + m2[2]*m3[7]; */
/* m1[2]= m2[0]*m3[2] + m2[1]*m3[5] + m2[2]*m3[8]; */
} /* end of void Mat3MulMat3(float m1[][3], float m3[][3], float m2[][3]) */
/* ------------------------------------------------------------------------- */
void MTC_Mat4Ortho(float mat[][4])
{
float len;
len= MTC_normalise3DF(mat[0]);
if(len!=0.0) mat[0][3]/= len;
len= MTC_normalise3DF(mat[1]);
if(len!=0.0) mat[1][3]/= len;
len= MTC_normalise3DF(mat[2]);
if(len!=0.0) mat[2][3]/= len;
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4Mul3Vecfl(float mat[][4], float *vec)
{
float x,y;
/* vec = mat^T dot vec !!! or vec a row, then vec = vec dot mat*/
x= vec[0];
y= vec[1];
vec[0]= x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2];
vec[1]= x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2];
vec[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4One(float m[][4])
{
m[0][0]= m[1][1]= m[2][2]= m[3][3]= 1.0;
m[0][1]= m[0][2]= m[0][3]= 0.0;
m[1][0]= m[1][2]= m[1][3]= 0.0;
m[2][0]= m[2][1]= m[2][3]= 0.0;
m[3][0]= m[3][1]= m[3][2]= 0.0;
}
/* ------------------------------------------------------------------------- */
/* Result is a 3-vector!*/
void MTC_Mat3MulVecd(float mat[][3], double *vec)
{
double x,y;
/* vec = mat^T dot vec !!! or vec a row, then vec = vec dot mat*/
x=vec[0];
y=vec[1];
vec[0]= x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2];
vec[1]= x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2];
vec[2]= x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat3Inv(float m1[][3], float m2[][3])
{
short a,b;
float det;
/* eerst adjoint */
MTC_Mat3Adj(m1,m2);
/* dan det oude mat! */
det= m2[0][0]* (m2[1][1]*m2[2][2] - m2[1][2]*m2[2][1])
-m2[1][0]* (m2[0][1]*m2[2][2] - m2[0][2]*m2[2][1])
+m2[2][0]* (m2[0][1]*m2[1][2] - m2[0][2]*m2[1][1]);
if(det==0) det=1;
det= 1/det;
for(a=0;a<3;a++) {
for(b=0;b<3;b++) {
m1[a][b]*=det;
}
}
}
/* ------------------------------------------------------------------------- */
void MTC_Mat3Adj(float m1[][3], float m[][3])
{
m1[0][0]=m[1][1]*m[2][2]-m[1][2]*m[2][1];
m1[0][1]= -m[0][1]*m[2][2]+m[0][2]*m[2][1];
m1[0][2]=m[0][1]*m[1][2]-m[0][2]*m[1][1];
m1[1][0]= -m[1][0]*m[2][2]+m[1][2]*m[2][0];
m1[1][1]=m[0][0]*m[2][2]-m[0][2]*m[2][0];
m1[1][2]= -m[0][0]*m[1][2]+m[0][2]*m[1][0];
m1[2][0]=m[1][0]*m[2][1]-m[1][1]*m[2][0];
m1[2][1]= -m[0][0]*m[2][1]+m[0][1]*m[2][0];
m1[2][2]=m[0][0]*m[1][1]-m[0][1]*m[1][0];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat3One(float m[][3])
{
m[0][0]= m[1][1]= m[2][2]= 1.0;
m[0][1]= m[0][2]= 0.0;
m[1][0]= m[1][2]= 0.0;
m[2][0]= m[2][1]= 0.0;
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4SwapMat4(float m1[][4], float m2[][4])
{
float t;
int i, j;
for(i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
t = m1[i][j];
m1[i][j] = m2[i][j];
m2[i][j] = t;
}
}
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4MulVec4fl(float mat[][4], float *vec)
{
float x,y,z;
x = vec[0];
y = vec[1];
z = vec[2];
vec[0] = x*mat[0][0] + y*mat[1][0] + z*mat[2][0] + mat[3][0]*vec[3];
vec[1] = x*mat[0][1] + y*mat[1][1] + z*mat[2][1] + mat[3][1]*vec[3];
vec[2] = x*mat[0][2] + y*mat[1][2] + z*mat[2][2] + mat[3][2]*vec[3];
vec[3] = x*mat[0][3] + y*mat[1][3] + z*mat[2][3] + mat[3][3]*vec[3];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4CpyMat3nc(float m1[][4], float m2[][3]) /* no clear */
{
m1[0][0]= m2[0][0];
m1[0][1]= m2[0][1];
m1[0][2]= m2[0][2];
m1[1][0]= m2[1][0];
m1[1][1]= m2[1][1];
m1[1][2]= m2[1][2];
m1[2][0]= m2[2][0];
m1[2][1]= m2[2][1];
m1[2][2]= m2[2][2];
}
/* ------------------------------------------------------------------------- */
void MTC_Mat4MulMat33(float m1[][3], float m2[][4], float m3[][3])
{
/* m1_i_j = m2_i_k * m3_k_j ? */
m1[0][0] = m2[0][0]*m3[0][0] + m2[0][1]*m3[1][0] + m2[0][2]*m3[2][0];
m1[0][1] = m2[0][0]*m3[0][1] + m2[0][1]*m3[1][1] + m2[0][2]*m3[2][1];
m1[0][2] = m2[0][0]*m3[0][2] + m2[0][1]*m3[1][2] + m2[0][2]*m3[2][2];
m1[1][0] = m2[1][0]*m3[0][0] + m2[1][1]*m3[1][0] + m2[1][2]*m3[2][0];
m1[1][1] = m2[1][0]*m3[0][1] + m2[1][1]*m3[1][1] + m2[1][2]*m3[2][1];
m1[1][2] = m2[1][0]*m3[0][2] + m2[1][1]*m3[1][2] + m2[1][2]*m3[2][2];
m1[2][0] = m2[2][0]*m3[0][0] + m2[2][1]*m3[1][0] + m2[2][2]*m3[2][0];
m1[2][1] = m2[2][0]*m3[0][1] + m2[2][1]*m3[1][1] + m2[2][2]*m3[2][1];
m1[2][2] = m2[2][0]*m3[0][2] + m2[2][1]*m3[1][2] + m2[2][2]*m3[2][2];
}
/* ------------------------------------------------------------------------- */
/* eof */

View File

@@ -0,0 +1,390 @@
/*
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
*/
#include <math.h>
#include "BLI_blenlib.h"
#ifdef _WIN32
#pragma warning (once : 4244) // "conversion from double to float"
#pragma warning (once : 4305) // "truncation from const double to float"
#endif
/* local */
float noise3_perlin(float vec[3]);
float turbulence_perlin(float *point, float lofreq, float hifreq);
float turbulencep(float noisesize, float x, float y, float z, int nr);
#define HASHVEC(x,y,z) hashvectf+3*hash[ (hash[ (hash[(z) & 255]+(y)) & 255]+(x)) & 255]
unsigned char hash[512]= {
0xA2,0xA0,0x19,0x3B,0xF8,0xEB,0xAA,0xEE,0xF3,0x1C,0x67,0x28,0x1D,0xED,0x0,0xDE,0x95,0x2E,0xDC,0x3F,0x3A,0x82,0x35,0x4D,0x6C,0xBA,0x36,0xD0,0xF6,0xC,0x79,0x32,0xD1,0x59,0xF4,0x8,0x8B,0x63,0x89,0x2F,0xB8,0xB4,0x97,0x83,0xF2,0x8F,0x18,0xC7,0x51,0x14,0x65,0x87,0x48,0x20,0x42,0xA8,0x80,0xB5,0x40,0x13,0xB2,0x22,0x7E,0x57,
0xBC,0x7F,0x6B,0x9D,0x86,0x4C,0xC8,0xDB,0x7C,0xD5,0x25,0x4E,0x5A,0x55,0x74,0x50,0xCD,0xB3,0x7A,0xBB,0xC3,0xCB,0xB6,0xE2,0xE4,0xEC,0xFD,0x98,0xB,0x96,0xD3,0x9E,0x5C,0xA1,0x64,0xF1,0x81,0x61,0xE1,0xC4,0x24,0x72,0x49,0x8C,0x90,0x4B,0x84,0x34,0x38,0xAB,0x78,0xCA,0x1F,0x1,0xD7,0x93,0x11,0xC1,0x58,0xA9,0x31,0xF9,0x44,0x6D,
0xBF,0x33,0x9C,0x5F,0x9,0x94,0xA3,0x85,0x6,0xC6,0x9A,0x1E,0x7B,0x46,0x15,0x30,0x27,0x2B,0x1B,0x71,0x3C,0x5B,0xD6,0x6F,0x62,0xAC,0x4F,0xC2,0xC0,0xE,0xB1,0x23,0xA7,0xDF,0x47,0xB0,0x77,0x69,0x5,0xE9,0xE6,0xE7,0x76,0x73,0xF,0xFE,0x6E,0x9B,0x56,0xEF,0x12,0xA5,0x37,0xFC,0xAE,0xD9,0x3,0x8E,0xDD,0x10,0xB9,0xCE,0xC9,0x8D,
0xDA,0x2A,0xBD,0x68,0x17,0x9F,0xBE,0xD4,0xA,0xCC,0xD2,0xE8,0x43,0x3D,0x70,0xB7,0x2,0x7D,0x99,0xD8,0xD,0x60,0x8A,0x4,0x2C,0x3E,0x92,0xE5,0xAF,0x53,0x7,0xE0,0x29,0xA6,0xC5,0xE3,0xF5,0xF7,0x4A,0x41,0x26,0x6A,0x16,0x5E,0x52,0x2D,0x21,0xAD,0xF0,0x91,0xFF,0xEA,0x54,0xFA,0x66,0x1A,0x45,0x39,0xCF,0x75,0xA4,0x88,0xFB,0x5D,
0xA2,0xA0,0x19,0x3B,0xF8,0xEB,0xAA,0xEE,0xF3,0x1C,0x67,0x28,0x1D,0xED,0x0,0xDE,0x95,0x2E,0xDC,0x3F,0x3A,0x82,0x35,0x4D,0x6C,0xBA,0x36,0xD0,0xF6,0xC,0x79,0x32,0xD1,0x59,0xF4,0x8,0x8B,0x63,0x89,0x2F,0xB8,0xB4,0x97,0x83,0xF2,0x8F,0x18,0xC7,0x51,0x14,0x65,0x87,0x48,0x20,0x42,0xA8,0x80,0xB5,0x40,0x13,0xB2,0x22,0x7E,0x57,
0xBC,0x7F,0x6B,0x9D,0x86,0x4C,0xC8,0xDB,0x7C,0xD5,0x25,0x4E,0x5A,0x55,0x74,0x50,0xCD,0xB3,0x7A,0xBB,0xC3,0xCB,0xB6,0xE2,0xE4,0xEC,0xFD,0x98,0xB,0x96,0xD3,0x9E,0x5C,0xA1,0x64,0xF1,0x81,0x61,0xE1,0xC4,0x24,0x72,0x49,0x8C,0x90,0x4B,0x84,0x34,0x38,0xAB,0x78,0xCA,0x1F,0x1,0xD7,0x93,0x11,0xC1,0x58,0xA9,0x31,0xF9,0x44,0x6D,
0xBF,0x33,0x9C,0x5F,0x9,0x94,0xA3,0x85,0x6,0xC6,0x9A,0x1E,0x7B,0x46,0x15,0x30,0x27,0x2B,0x1B,0x71,0x3C,0x5B,0xD6,0x6F,0x62,0xAC,0x4F,0xC2,0xC0,0xE,0xB1,0x23,0xA7,0xDF,0x47,0xB0,0x77,0x69,0x5,0xE9,0xE6,0xE7,0x76,0x73,0xF,0xFE,0x6E,0x9B,0x56,0xEF,0x12,0xA5,0x37,0xFC,0xAE,0xD9,0x3,0x8E,0xDD,0x10,0xB9,0xCE,0xC9,0x8D,
0xDA,0x2A,0xBD,0x68,0x17,0x9F,0xBE,0xD4,0xA,0xCC,0xD2,0xE8,0x43,0x3D,0x70,0xB7,0x2,0x7D,0x99,0xD8,0xD,0x60,0x8A,0x4,0x2C,0x3E,0x92,0xE5,0xAF,0x53,0x7,0xE0,0x29,0xA6,0xC5,0xE3,0xF5,0xF7,0x4A,0x41,0x26,0x6A,0x16,0x5E,0x52,0x2D,0x21,0xAD,0xF0,0x91,0xFF,0xEA,0x54,0xFA,0x66,0x1A,0x45,0x39,0xCF,0x75,0xA4,0x88,0xFB,0x5D,
};
float hashvectf[768]= {
0.33783,0.715698,-0.611206,-0.944031,-0.326599,-0.045624,-0.101074,-0.416443,-0.903503,0.799286,0.49411,-0.341949,-0.854645,0.518036,0.033936,0.42514,-0.437866,-0.792114,-0.358948,0.597046,0.717377,-0.985413,0.144714,0.089294,-0.601776,-0.33728,-0.723907,-0.449921,0.594513,0.666382,0.208313,-0.10791,
0.972076,0.575317,0.060425,0.815643,0.293365,-0.875702,-0.383453,0.293762,0.465759,0.834686,-0.846008,-0.233398,-0.47934,-0.115814,0.143036,-0.98291,0.204681,-0.949036,-0.239532,0.946716,-0.263947,0.184326,-0.235596,0.573822,0.784332,0.203705,-0.372253,-0.905487,0.756989,-0.651031,0.055298,0.497803,
0.814697,-0.297363,-0.16214,0.063995,-0.98468,-0.329254,0.834381,0.441925,0.703827,-0.527039,-0.476227,0.956421,0.266113,0.119781,0.480133,0.482849,0.7323,-0.18631,0.961212,-0.203125,-0.748474,-0.656921,-0.090393,-0.085052,-0.165253,0.982544,-0.76947,0.628174,-0.115234,0.383148,0.537659,0.751068,
0.616486,-0.668488,-0.415924,-0.259979,-0.630005,0.73175,0.570953,-0.087952,0.816223,-0.458008,0.023254,0.888611,-0.196167,0.976563,-0.088287,-0.263885,-0.69812,-0.665527,0.437134,-0.892273,-0.112793,-0.621674,-0.230438,0.748566,0.232422,0.900574,-0.367249,0.22229,-0.796143,0.562744,-0.665497,-0.73764,
0.11377,0.670135,0.704803,0.232605,0.895599,0.429749,-0.114655,-0.11557,-0.474243,0.872742,0.621826,0.604004,-0.498444,-0.832214,0.012756,0.55426,-0.702484,0.705994,-0.089661,-0.692017,0.649292,0.315399,-0.175995,-0.977997,0.111877,0.096954,-0.04953,0.994019,0.635284,-0.606689,-0.477783,-0.261261,
-0.607422,-0.750153,0.983276,0.165436,0.075958,-0.29837,0.404083,-0.864655,-0.638672,0.507721,0.578156,0.388214,0.412079,0.824249,0.556183,-0.208832,0.804352,0.778442,0.562012,0.27951,-0.616577,0.781921,-0.091522,0.196289,0.051056,0.979187,-0.121216,0.207153,-0.970734,-0.173401,-0.384735,0.906555,
0.161499,-0.723236,-0.671387,0.178497,-0.006226,-0.983887,-0.126038,0.15799,0.97934,0.830475,-0.024811,0.556458,-0.510132,-0.76944,0.384247,0.81424,0.200104,-0.544891,-0.112549,-0.393311,-0.912445,0.56189,0.152222,-0.813049,0.198914,-0.254517,-0.946381,-0.41217,0.690979,-0.593811,-0.407257,0.324524,
0.853668,-0.690186,0.366119,-0.624115,-0.428345,0.844147,-0.322296,-0.21228,-0.297546,-0.930756,-0.273071,0.516113,0.811798,0.928314,0.371643,0.007233,0.785828,-0.479218,-0.390778,-0.704895,0.058929,0.706818,0.173248,0.203583,0.963562,0.422211,-0.904297,-0.062469,-0.363312,-0.182465,0.913605,0.254028,
-0.552307,-0.793945,-0.28891,-0.765747,-0.574554,0.058319,0.291382,0.954803,0.946136,-0.303925,0.111267,-0.078156,0.443695,-0.892731,0.182098,0.89389,0.409515,-0.680298,-0.213318,0.701141,0.062469,0.848389,-0.525635,-0.72879,-0.641846,0.238342,-0.88089,0.427673,0.202637,-0.532501,-0.21405,0.818878,
0.948975,-0.305084,0.07962,0.925446,0.374664,0.055817,0.820923,0.565491,0.079102,0.25882,0.099792,-0.960724,-0.294617,0.910522,0.289978,0.137115,0.320038,-0.937408,-0.908386,0.345276,-0.235718,-0.936218,0.138763,0.322754,0.366577,0.925934,-0.090637,0.309296,-0.686829,-0.657684,0.66983,0.024445,
0.742065,-0.917999,-0.059113,-0.392059,0.365509,0.462158,-0.807922,0.083374,0.996399,-0.014801,0.593842,0.253143,-0.763672,0.974976,-0.165466,0.148285,0.918976,0.137299,0.369537,0.294952,0.694977,0.655731,0.943085,0.152618,-0.295319,0.58783,-0.598236,0.544495,0.203796,0.678223,0.705994,-0.478821,
-0.661011,0.577667,0.719055,-0.1698,-0.673828,-0.132172,-0.965332,0.225006,-0.981873,-0.14502,0.121979,0.763458,0.579742,0.284546,-0.893188,0.079681,0.442474,-0.795776,-0.523804,0.303802,0.734955,0.67804,-0.007446,0.15506,0.986267,-0.056183,0.258026,0.571503,-0.778931,-0.681549,-0.702087,-0.206116,
-0.96286,-0.177185,0.203613,-0.470978,-0.515106,0.716095,-0.740326,0.57135,0.354095,-0.56012,-0.824982,-0.074982,-0.507874,0.753204,0.417969,-0.503113,0.038147,0.863342,0.594025,0.673553,-0.439758,-0.119873,-0.005524,-0.992737,0.098267,-0.213776,0.971893,-0.615631,0.643951,0.454163,0.896851,-0.441071,
0.032166,-0.555023,0.750763,-0.358093,0.398773,0.304688,0.864929,-0.722961,0.303589,0.620544,-0.63559,-0.621948,-0.457306,-0.293243,0.072327,0.953278,-0.491638,0.661041,-0.566772,-0.304199,-0.572083,-0.761688,0.908081,-0.398956,0.127014,-0.523621,-0.549683,-0.650848,-0.932922,-0.19986,0.299408,0.099426,
0.140869,0.984985,-0.020325,-0.999756,-0.002319,0.952667,0.280853,-0.11615,-0.971893,0.082581,0.220337,0.65921,0.705292,-0.260651,0.733063,-0.175537,0.657043,-0.555206,0.429504,-0.712189,0.400421,-0.89859,0.179352,0.750885,-0.19696,0.630341,0.785675,-0.569336,0.241821,-0.058899,-0.464111,0.883789,
0.129608,-0.94519,0.299622,-0.357819,0.907654,0.219238,-0.842133,-0.439117,-0.312927,-0.313477,0.84433,0.434479,-0.241211,0.053253,0.968994,0.063873,0.823273,0.563965,0.476288,0.862152,-0.172516,0.620941,-0.298126,0.724915,0.25238,-0.749359,-0.612122,-0.577545,0.386566,0.718994,-0.406342,-0.737976,
0.538696,0.04718,0.556305,0.82959,-0.802856,0.587463,0.101166,-0.707733,-0.705963,0.026428,0.374908,0.68457,0.625092,0.472137,0.208405,-0.856506,-0.703064,-0.581085,-0.409821,-0.417206,-0.736328,0.532623,-0.447876,-0.20285,-0.870728,0.086945,-0.990417,0.107086,0.183685,0.018341,-0.982788,0.560638,
-0.428864,0.708282,0.296722,-0.952576,-0.0672,0.135773,0.990265,0.030243,-0.068787,0.654724,0.752686,0.762604,-0.551758,0.337585,-0.819611,-0.407684,0.402466,-0.727844,-0.55072,-0.408539,-0.855774,-0.480011,0.19281,0.693176,-0.079285,0.716339,0.226013,0.650116,-0.725433,0.246704,0.953369,-0.173553,
-0.970398,-0.239227,-0.03244,0.136383,-0.394318,0.908752,0.813232,0.558167,0.164368,0.40451,0.549042,-0.731323,-0.380249,-0.566711,0.730865,0.022156,0.932739,0.359741,0.00824,0.996552,-0.082306,0.956635,-0.065338,-0.283722,-0.743561,0.008209,0.668579,-0.859589,-0.509674,0.035767,-0.852234,0.363678,
-0.375977,-0.201965,-0.970795,-0.12915,0.313477,0.947327,0.06546,-0.254028,-0.528259,0.81015,0.628052,0.601105,0.49411,-0.494385,0.868378,0.037933,0.275635,-0.086426,0.957336,-0.197937,0.468903,-0.860748,0.895599,0.399384,0.195801,0.560791,0.825012,-0.069214,0.304199,-0.849487,0.43103,0.096375,
0.93576,0.339111,-0.051422,0.408966,-0.911072,0.330444,0.942841,-0.042389,-0.452362,-0.786407,0.420563,0.134308,-0.933472,-0.332489,0.80191,-0.566711,-0.188934,-0.987946,-0.105988,0.112518,-0.24408,0.892242,-0.379791,-0.920502,0.229095,-0.316376,0.7789,0.325958,0.535706,-0.912872,0.185211,-0.36377,
-0.184784,0.565369,-0.803833,-0.018463,0.119537,0.992615,-0.259247,-0.935608,0.239532,-0.82373,-0.449127,-0.345947,-0.433105,0.659515,0.614349,-0.822754,0.378845,-0.423676,0.687195,-0.674835,-0.26889,-0.246582,-0.800842,0.545715,-0.729187,-0.207794,0.651978,0.653534,-0.610443,-0.447388,0.492584,-0.023346,
0.869934,0.609039,0.009094,-0.79306,0.962494,-0.271088,-0.00885,0.2659,-0.004913,0.963959,0.651245,0.553619,-0.518951,0.280548,-0.84314,0.458618,-0.175293,-0.983215,0.049805,0.035339,-0.979919,0.196045,-0.982941,0.164307,-0.082245,0.233734,-0.97226,-0.005005,-0.747253,-0.611328,0.260437,0.645599,
0.592773,0.481384,0.117706,-0.949524,-0.29068,-0.535004,-0.791901,-0.294312,-0.627167,-0.214447,0.748718,-0.047974,-0.813477,-0.57959,-0.175537,0.477264,-0.860992,0.738556,-0.414246,-0.53183,0.562561,-0.704071,0.433289,-0.754944,0.64801,-0.100586,0.114716,0.044525,-0.992371,0.966003,0.244873,-0.082764,
};
float BLI_hnoise(float noisesize, float x, float y, float z)
{
register float cn1, cn2, cn3, cn4, cn5, cn6, i, *h;
float ox, oy, oz, jx, jy, jz;
float n= 0.5;
int ix, iy, iz, b00, b01, b10, b11, b20, b21;
if(noisesize==0.0) return 0.0;
x= (1.0+x)/noisesize;
y= (1.0+y)/noisesize;
z= (1.0+z)/noisesize;
ox= (x- (ix= (int)floor(x)) );
oy= (y- (iy= (int)floor(y)) );
oz= (z- (iz= (int)floor(z)) );
jx= ox-1;
jy= oy-1;
jz= oz-1;
cn1=ox*ox; cn2=oy*oy; cn3=oz*oz;
cn4=jx*jx; cn5=jy*jy; cn6=jz*jz;
cn1= 1.0-3.0*cn1+2.0*cn1*ox;
cn2= 1.0-3.0*cn2+2.0*cn2*oy;
cn3= 1.0-3.0*cn3+2.0*cn3*oz;
cn4= 1.0-3.0*cn4-2.0*cn4*jx;
cn5= 1.0-3.0*cn5-2.0*cn5*jy;
cn6= 1.0-3.0*cn6-2.0*cn6*jz;
b00= hash[ hash[ix & 255]+(iy & 255)];
b10= hash[ hash[(ix+1) & 255]+(iy & 255)];
b01= hash[ hash[ix & 255]+((iy+1) & 255)];
b11= hash[ hash[(ix+1) & 255]+((iy+1) & 255)];
b20=iz & 255; b21= (iz+1) & 255;
/* 0 */
i= (cn1*cn2*cn3);
h=hashvectf+ 3*hash[b20+b00];
n+= i*(h[0]*ox+h[1]*oy+h[2]*oz);
/* 1 */
i= (cn1*cn2*cn6);
h=hashvectf+ 3*hash[b21+b00];
n+= i*(h[0]*ox+h[1]*oy+h[2]*jz);
/* 2 */
i= (cn1*cn5*cn3);
h=hashvectf+ 3*hash[b20+b01];
n+= i*(h[0]*ox+h[1]*jy+h[2]*oz);
/* 3 */
i= (cn1*cn5*cn6);
h=hashvectf+ 3*hash[b21+b01];
n+= i*(h[0]*ox+h[1]*jy+h[2]*jz);
/* 4 */
i= cn4*cn2*cn3;
h=hashvectf+ 3*hash[b20+b10];
n+= i*(h[0]*jx+h[1]*oy+h[2]*oz);
/* 5 */
i= cn4*cn2*cn6;
h=hashvectf+ 3*hash[b21+b10];
n+= i*(h[0]*jx+h[1]*oy+h[2]*jz);
/* 6 */
i= cn4*cn5*cn3;
h=hashvectf+ 3*hash[b20+b11];
n+= i*(h[0]*jx+h[1]*jy+h[2]*oz);
/* 7 */
i= (cn4*cn5*cn6);
h=hashvectf+ 3*hash[b21+b11];
n+= i*(h[0]*jx+h[1]*jy+h[2]*jz);
if(n<0.0) n=0.0; else if(n>1.0) n=1.0 ;
return n;
}
float BLI_turbulence(float noisesize, float x, float y, float z, int nr)
{
float s, d= 0.5, div=1.0;
s= BLI_hnoise(noisesize, x, y, z);
while(nr>0) {
s+= d*BLI_hnoise(noisesize*d, x, y, z);
div+= d;
d*= 0.5;
nr--;
}
return s/div;
}
float BLI_turbulence1(float noisesize, float x, float y, float z, int nr)
{
float s, d= 0.5, div=1.0;
s= fabs( (-1.0+2.0*BLI_hnoise(noisesize, x, y, z)));
while(nr>0) {
s+= fabs(d* (-1.0+2.0*BLI_hnoise(noisesize*d, x, y, z)));
div+= d;
d*= 0.5;
nr--;
}
return s/div;
}
/* ********************* VAN PERLIN HIMSELF: ******************** */
static char p[512+2]= {
0xA2,0xA0,0x19,0x3B,0xF8,0xEB,0xAA,0xEE,0xF3,0x1C,0x67,0x28,0x1D,0xED,0x0,0xDE,0x95,0x2E,0xDC,0x3F,0x3A,0x82,0x35,0x4D,0x6C,0xBA,0x36,0xD0,0xF6,0xC,0x79,0x32,0xD1,0x59,0xF4,0x8,0x8B,0x63,0x89,0x2F,0xB8,0xB4,0x97,0x83,0xF2,0x8F,0x18,0xC7,0x51,0x14,0x65,0x87,0x48,0x20,0x42,0xA8,0x80,0xB5,0x40,0x13,0xB2,0x22,0x7E,0x57,
0xBC,0x7F,0x6B,0x9D,0x86,0x4C,0xC8,0xDB,0x7C,0xD5,0x25,0x4E,0x5A,0x55,0x74,0x50,0xCD,0xB3,0x7A,0xBB,0xC3,0xCB,0xB6,0xE2,0xE4,0xEC,0xFD,0x98,0xB,0x96,0xD3,0x9E,0x5C,0xA1,0x64,0xF1,0x81,0x61,0xE1,0xC4,0x24,0x72,0x49,0x8C,0x90,0x4B,0x84,0x34,0x38,0xAB,0x78,0xCA,0x1F,0x1,0xD7,0x93,0x11,0xC1,0x58,0xA9,0x31,0xF9,0x44,0x6D,
0xBF,0x33,0x9C,0x5F,0x9,0x94,0xA3,0x85,0x6,0xC6,0x9A,0x1E,0x7B,0x46,0x15,0x30,0x27,0x2B,0x1B,0x71,0x3C,0x5B,0xD6,0x6F,0x62,0xAC,0x4F,0xC2,0xC0,0xE,0xB1,0x23,0xA7,0xDF,0x47,0xB0,0x77,0x69,0x5,0xE9,0xE6,0xE7,0x76,0x73,0xF,0xFE,0x6E,0x9B,0x56,0xEF,0x12,0xA5,0x37,0xFC,0xAE,0xD9,0x3,0x8E,0xDD,0x10,0xB9,0xCE,0xC9,0x8D,
0xDA,0x2A,0xBD,0x68,0x17,0x9F,0xBE,0xD4,0xA,0xCC,0xD2,0xE8,0x43,0x3D,0x70,0xB7,0x2,0x7D,0x99,0xD8,0xD,0x60,0x8A,0x4,0x2C,0x3E,0x92,0xE5,0xAF,0x53,0x7,0xE0,0x29,0xA6,0xC5,0xE3,0xF5,0xF7,0x4A,0x41,0x26,0x6A,0x16,0x5E,0x52,0x2D,0x21,0xAD,0xF0,0x91,0xFF,0xEA,0x54,0xFA,0x66,0x1A,0x45,0x39,0xCF,0x75,0xA4,0x88,0xFB,0x5D,
0xA2,0xA0,0x19,0x3B,0xF8,0xEB,0xAA,0xEE,0xF3,0x1C,0x67,0x28,0x1D,0xED,0x0,0xDE,0x95,0x2E,0xDC,0x3F,0x3A,0x82,0x35,0x4D,0x6C,0xBA,0x36,0xD0,0xF6,0xC,0x79,0x32,0xD1,0x59,0xF4,0x8,0x8B,0x63,0x89,0x2F,0xB8,0xB4,0x97,0x83,0xF2,0x8F,0x18,0xC7,0x51,0x14,0x65,0x87,0x48,0x20,0x42,0xA8,0x80,0xB5,0x40,0x13,0xB2,0x22,0x7E,0x57,
0xBC,0x7F,0x6B,0x9D,0x86,0x4C,0xC8,0xDB,0x7C,0xD5,0x25,0x4E,0x5A,0x55,0x74,0x50,0xCD,0xB3,0x7A,0xBB,0xC3,0xCB,0xB6,0xE2,0xE4,0xEC,0xFD,0x98,0xB,0x96,0xD3,0x9E,0x5C,0xA1,0x64,0xF1,0x81,0x61,0xE1,0xC4,0x24,0x72,0x49,0x8C,0x90,0x4B,0x84,0x34,0x38,0xAB,0x78,0xCA,0x1F,0x1,0xD7,0x93,0x11,0xC1,0x58,0xA9,0x31,0xF9,0x44,0x6D,
0xBF,0x33,0x9C,0x5F,0x9,0x94,0xA3,0x85,0x6,0xC6,0x9A,0x1E,0x7B,0x46,0x15,0x30,0x27,0x2B,0x1B,0x71,0x3C,0x5B,0xD6,0x6F,0x62,0xAC,0x4F,0xC2,0xC0,0xE,0xB1,0x23,0xA7,0xDF,0x47,0xB0,0x77,0x69,0x5,0xE9,0xE6,0xE7,0x76,0x73,0xF,0xFE,0x6E,0x9B,0x56,0xEF,0x12,0xA5,0x37,0xFC,0xAE,0xD9,0x3,0x8E,0xDD,0x10,0xB9,0xCE,0xC9,0x8D,
0xDA,0x2A,0xBD,0x68,0x17,0x9F,0xBE,0xD4,0xA,0xCC,0xD2,0xE8,0x43,0x3D,0x70,0xB7,0x2,0x7D,0x99,0xD8,0xD,0x60,0x8A,0x4,0x2C,0x3E,0x92,0xE5,0xAF,0x53,0x7,0xE0,0x29,0xA6,0xC5,0xE3,0xF5,0xF7,0x4A,0x41,0x26,0x6A,0x16,0x5E,0x52,0x2D,0x21,0xAD,0xF0,0x91,0xFF,0xEA,0x54,0xFA,0x66,0x1A,0x45,0x39,0xCF,0x75,0xA4,0x88,0xFB,0x5D,
0xA2,0xA0};
float g[512+2][3]= {
0.33783,0.715698,-0.611206,-0.944031,-0.326599,-0.045624,-0.101074,-0.416443,-0.903503,0.799286,0.49411,-0.341949,-0.854645,0.518036,0.033936,0.42514,-0.437866,-0.792114,-0.358948,0.597046,0.717377,-0.985413,0.144714,0.089294,-0.601776,-0.33728,-0.723907,-0.449921,0.594513,0.666382,0.208313,-0.10791,
0.972076,0.575317,0.060425,0.815643,0.293365,-0.875702,-0.383453,0.293762,0.465759,0.834686,-0.846008,-0.233398,-0.47934,-0.115814,0.143036,-0.98291,0.204681,-0.949036,-0.239532,0.946716,-0.263947,0.184326,-0.235596,0.573822,0.784332,0.203705,-0.372253,-0.905487,0.756989,-0.651031,0.055298,0.497803,
0.814697,-0.297363,-0.16214,0.063995,-0.98468,-0.329254,0.834381,0.441925,0.703827,-0.527039,-0.476227,0.956421,0.266113,0.119781,0.480133,0.482849,0.7323,-0.18631,0.961212,-0.203125,-0.748474,-0.656921,-0.090393,-0.085052,-0.165253,0.982544,-0.76947,0.628174,-0.115234,0.383148,0.537659,0.751068,
0.616486,-0.668488,-0.415924,-0.259979,-0.630005,0.73175,0.570953,-0.087952,0.816223,-0.458008,0.023254,0.888611,-0.196167,0.976563,-0.088287,-0.263885,-0.69812,-0.665527,0.437134,-0.892273,-0.112793,-0.621674,-0.230438,0.748566,0.232422,0.900574,-0.367249,0.22229,-0.796143,0.562744,-0.665497,-0.73764,
0.11377,0.670135,0.704803,0.232605,0.895599,0.429749,-0.114655,-0.11557,-0.474243,0.872742,0.621826,0.604004,-0.498444,-0.832214,0.012756,0.55426,-0.702484,0.705994,-0.089661,-0.692017,0.649292,0.315399,-0.175995,-0.977997,0.111877,0.096954,-0.04953,0.994019,0.635284,-0.606689,-0.477783,-0.261261,
-0.607422,-0.750153,0.983276,0.165436,0.075958,-0.29837,0.404083,-0.864655,-0.638672,0.507721,0.578156,0.388214,0.412079,0.824249,0.556183,-0.208832,0.804352,0.778442,0.562012,0.27951,-0.616577,0.781921,-0.091522,0.196289,0.051056,0.979187,-0.121216,0.207153,-0.970734,-0.173401,-0.384735,0.906555,
0.161499,-0.723236,-0.671387,0.178497,-0.006226,-0.983887,-0.126038,0.15799,0.97934,0.830475,-0.024811,0.556458,-0.510132,-0.76944,0.384247,0.81424,0.200104,-0.544891,-0.112549,-0.393311,-0.912445,0.56189,0.152222,-0.813049,0.198914,-0.254517,-0.946381,-0.41217,0.690979,-0.593811,-0.407257,0.324524,
0.853668,-0.690186,0.366119,-0.624115,-0.428345,0.844147,-0.322296,-0.21228,-0.297546,-0.930756,-0.273071,0.516113,0.811798,0.928314,0.371643,0.007233,0.785828,-0.479218,-0.390778,-0.704895,0.058929,0.706818,0.173248,0.203583,0.963562,0.422211,-0.904297,-0.062469,-0.363312,-0.182465,0.913605,0.254028,
-0.552307,-0.793945,-0.28891,-0.765747,-0.574554,0.058319,0.291382,0.954803,0.946136,-0.303925,0.111267,-0.078156,0.443695,-0.892731,0.182098,0.89389,0.409515,-0.680298,-0.213318,0.701141,0.062469,0.848389,-0.525635,-0.72879,-0.641846,0.238342,-0.88089,0.427673,0.202637,-0.532501,-0.21405,0.818878,
0.948975,-0.305084,0.07962,0.925446,0.374664,0.055817,0.820923,0.565491,0.079102,0.25882,0.099792,-0.960724,-0.294617,0.910522,0.289978,0.137115,0.320038,-0.937408,-0.908386,0.345276,-0.235718,-0.936218,0.138763,0.322754,0.366577,0.925934,-0.090637,0.309296,-0.686829,-0.657684,0.66983,0.024445,
0.742065,-0.917999,-0.059113,-0.392059,0.365509,0.462158,-0.807922,0.083374,0.996399,-0.014801,0.593842,0.253143,-0.763672,0.974976,-0.165466,0.148285,0.918976,0.137299,0.369537,0.294952,0.694977,0.655731,0.943085,0.152618,-0.295319,0.58783,-0.598236,0.544495,0.203796,0.678223,0.705994,-0.478821,
-0.661011,0.577667,0.719055,-0.1698,-0.673828,-0.132172,-0.965332,0.225006,-0.981873,-0.14502,0.121979,0.763458,0.579742,0.284546,-0.893188,0.079681,0.442474,-0.795776,-0.523804,0.303802,0.734955,0.67804,-0.007446,0.15506,0.986267,-0.056183,0.258026,0.571503,-0.778931,-0.681549,-0.702087,-0.206116,
-0.96286,-0.177185,0.203613,-0.470978,-0.515106,0.716095,-0.740326,0.57135,0.354095,-0.56012,-0.824982,-0.074982,-0.507874,0.753204,0.417969,-0.503113,0.038147,0.863342,0.594025,0.673553,-0.439758,-0.119873,-0.005524,-0.992737,0.098267,-0.213776,0.971893,-0.615631,0.643951,0.454163,0.896851,-0.441071,
0.032166,-0.555023,0.750763,-0.358093,0.398773,0.304688,0.864929,-0.722961,0.303589,0.620544,-0.63559,-0.621948,-0.457306,-0.293243,0.072327,0.953278,-0.491638,0.661041,-0.566772,-0.304199,-0.572083,-0.761688,0.908081,-0.398956,0.127014,-0.523621,-0.549683,-0.650848,-0.932922,-0.19986,0.299408,0.099426,
0.140869,0.984985,-0.020325,-0.999756,-0.002319,0.952667,0.280853,-0.11615,-0.971893,0.082581,0.220337,0.65921,0.705292,-0.260651,0.733063,-0.175537,0.657043,-0.555206,0.429504,-0.712189,0.400421,-0.89859,0.179352,0.750885,-0.19696,0.630341,0.785675,-0.569336,0.241821,-0.058899,-0.464111,0.883789,
0.129608,-0.94519,0.299622,-0.357819,0.907654,0.219238,-0.842133,-0.439117,-0.312927,-0.313477,0.84433,0.434479,-0.241211,0.053253,0.968994,0.063873,0.823273,0.563965,0.476288,0.862152,-0.172516,0.620941,-0.298126,0.724915,0.25238,-0.749359,-0.612122,-0.577545,0.386566,0.718994,-0.406342,-0.737976,
0.538696,0.04718,0.556305,0.82959,-0.802856,0.587463,0.101166,-0.707733,-0.705963,0.026428,0.374908,0.68457,0.625092,0.472137,0.208405,-0.856506,-0.703064,-0.581085,-0.409821,-0.417206,-0.736328,0.532623,-0.447876,-0.20285,-0.870728,0.086945,-0.990417,0.107086,0.183685,0.018341,-0.982788,0.560638,
-0.428864,0.708282,0.296722,-0.952576,-0.0672,0.135773,0.990265,0.030243,-0.068787,0.654724,0.752686,0.762604,-0.551758,0.337585,-0.819611,-0.407684,0.402466,-0.727844,-0.55072,-0.408539,-0.855774,-0.480011,0.19281,0.693176,-0.079285,0.716339,0.226013,0.650116,-0.725433,0.246704,0.953369,-0.173553,
-0.970398,-0.239227,-0.03244,0.136383,-0.394318,0.908752,0.813232,0.558167,0.164368,0.40451,0.549042,-0.731323,-0.380249,-0.566711,0.730865,0.022156,0.932739,0.359741,0.00824,0.996552,-0.082306,0.956635,-0.065338,-0.283722,-0.743561,0.008209,0.668579,-0.859589,-0.509674,0.035767,-0.852234,0.363678,
-0.375977,-0.201965,-0.970795,-0.12915,0.313477,0.947327,0.06546,-0.254028,-0.528259,0.81015,0.628052,0.601105,0.49411,-0.494385,0.868378,0.037933,0.275635,-0.086426,0.957336,-0.197937,0.468903,-0.860748,0.895599,0.399384,0.195801,0.560791,0.825012,-0.069214,0.304199,-0.849487,0.43103,0.096375,
0.93576,0.339111,-0.051422,0.408966,-0.911072,0.330444,0.942841,-0.042389,-0.452362,-0.786407,0.420563,0.134308,-0.933472,-0.332489,0.80191,-0.566711,-0.188934,-0.987946,-0.105988,0.112518,-0.24408,0.892242,-0.379791,-0.920502,0.229095,-0.316376,0.7789,0.325958,0.535706,-0.912872,0.185211,-0.36377,
-0.184784,0.565369,-0.803833,-0.018463,0.119537,0.992615,-0.259247,-0.935608,0.239532,-0.82373,-0.449127,-0.345947,-0.433105,0.659515,0.614349,-0.822754,0.378845,-0.423676,0.687195,-0.674835,-0.26889,-0.246582,-0.800842,0.545715,-0.729187,-0.207794,0.651978,0.653534,-0.610443,-0.447388,0.492584,-0.023346,
0.869934,0.609039,0.009094,-0.79306,0.962494,-0.271088,-0.00885,0.2659,-0.004913,0.963959,0.651245,0.553619,-0.518951,0.280548,-0.84314,0.458618,-0.175293,-0.983215,0.049805,0.035339,-0.979919,0.196045,-0.982941,0.164307,-0.082245,0.233734,-0.97226,-0.005005,-0.747253,-0.611328,0.260437,0.645599,
0.592773,0.481384,0.117706,-0.949524,-0.29068,-0.535004,-0.791901,-0.294312,-0.627167,-0.214447,0.748718,-0.047974,-0.813477,-0.57959,-0.175537,0.477264,-0.860992,0.738556,-0.414246,-0.53183,0.562561,-0.704071,0.433289,-0.754944,0.64801,-0.100586,0.114716,0.044525,-0.992371,0.966003,0.244873,-0.082764,
0.33783,0.715698,-0.611206,-0.944031,-0.326599,-0.045624,-0.101074,-0.416443,-0.903503,0.799286,0.49411,-0.341949,-0.854645,0.518036,0.033936,0.42514,-0.437866,-0.792114,-0.358948,0.597046,0.717377,-0.985413,0.144714,0.089294,-0.601776,-0.33728,-0.723907,-0.449921,0.594513,0.666382,0.208313,-0.10791,
0.972076,0.575317,0.060425,0.815643,0.293365,-0.875702,-0.383453,0.293762,0.465759,0.834686,-0.846008,-0.233398,-0.47934,-0.115814,0.143036,-0.98291,0.204681,-0.949036,-0.239532,0.946716,-0.263947,0.184326,-0.235596,0.573822,0.784332,0.203705,-0.372253,-0.905487,0.756989,-0.651031,0.055298,0.497803,
0.814697,-0.297363,-0.16214,0.063995,-0.98468,-0.329254,0.834381,0.441925,0.703827,-0.527039,-0.476227,0.956421,0.266113,0.119781,0.480133,0.482849,0.7323,-0.18631,0.961212,-0.203125,-0.748474,-0.656921,-0.090393,-0.085052,-0.165253,0.982544,-0.76947,0.628174,-0.115234,0.383148,0.537659,0.751068,
0.616486,-0.668488,-0.415924,-0.259979,-0.630005,0.73175,0.570953,-0.087952,0.816223,-0.458008,0.023254,0.888611,-0.196167,0.976563,-0.088287,-0.263885,-0.69812,-0.665527,0.437134,-0.892273,-0.112793,-0.621674,-0.230438,0.748566,0.232422,0.900574,-0.367249,0.22229,-0.796143,0.562744,-0.665497,-0.73764,
0.11377,0.670135,0.704803,0.232605,0.895599,0.429749,-0.114655,-0.11557,-0.474243,0.872742,0.621826,0.604004,-0.498444,-0.832214,0.012756,0.55426,-0.702484,0.705994,-0.089661,-0.692017,0.649292,0.315399,-0.175995,-0.977997,0.111877,0.096954,-0.04953,0.994019,0.635284,-0.606689,-0.477783,-0.261261,
-0.607422,-0.750153,0.983276,0.165436,0.075958,-0.29837,0.404083,-0.864655,-0.638672,0.507721,0.578156,0.388214,0.412079,0.824249,0.556183,-0.208832,0.804352,0.778442,0.562012,0.27951,-0.616577,0.781921,-0.091522,0.196289,0.051056,0.979187,-0.121216,0.207153,-0.970734,-0.173401,-0.384735,0.906555,
0.161499,-0.723236,-0.671387,0.178497,-0.006226,-0.983887,-0.126038,0.15799,0.97934,0.830475,-0.024811,0.556458,-0.510132,-0.76944,0.384247,0.81424,0.200104,-0.544891,-0.112549,-0.393311,-0.912445,0.56189,0.152222,-0.813049,0.198914,-0.254517,-0.946381,-0.41217,0.690979,-0.593811,-0.407257,0.324524,
0.853668,-0.690186,0.366119,-0.624115,-0.428345,0.844147,-0.322296,-0.21228,-0.297546,-0.930756,-0.273071,0.516113,0.811798,0.928314,0.371643,0.007233,0.785828,-0.479218,-0.390778,-0.704895,0.058929,0.706818,0.173248,0.203583,0.963562,0.422211,-0.904297,-0.062469,-0.363312,-0.182465,0.913605,0.254028,
-0.552307,-0.793945,-0.28891,-0.765747,-0.574554,0.058319,0.291382,0.954803,0.946136,-0.303925,0.111267,-0.078156,0.443695,-0.892731,0.182098,0.89389,0.409515,-0.680298,-0.213318,0.701141,0.062469,0.848389,-0.525635,-0.72879,-0.641846,0.238342,-0.88089,0.427673,0.202637,-0.532501,-0.21405,0.818878,
0.948975,-0.305084,0.07962,0.925446,0.374664,0.055817,0.820923,0.565491,0.079102,0.25882,0.099792,-0.960724,-0.294617,0.910522,0.289978,0.137115,0.320038,-0.937408,-0.908386,0.345276,-0.235718,-0.936218,0.138763,0.322754,0.366577,0.925934,-0.090637,0.309296,-0.686829,-0.657684,0.66983,0.024445,
0.742065,-0.917999,-0.059113,-0.392059,0.365509,0.462158,-0.807922,0.083374,0.996399,-0.014801,0.593842,0.253143,-0.763672,0.974976,-0.165466,0.148285,0.918976,0.137299,0.369537,0.294952,0.694977,0.655731,0.943085,0.152618,-0.295319,0.58783,-0.598236,0.544495,0.203796,0.678223,0.705994,-0.478821,
-0.661011,0.577667,0.719055,-0.1698,-0.673828,-0.132172,-0.965332,0.225006,-0.981873,-0.14502,0.121979,0.763458,0.579742,0.284546,-0.893188,0.079681,0.442474,-0.795776,-0.523804,0.303802,0.734955,0.67804,-0.007446,0.15506,0.986267,-0.056183,0.258026,0.571503,-0.778931,-0.681549,-0.702087,-0.206116,
-0.96286,-0.177185,0.203613,-0.470978,-0.515106,0.716095,-0.740326,0.57135,0.354095,-0.56012,-0.824982,-0.074982,-0.507874,0.753204,0.417969,-0.503113,0.038147,0.863342,0.594025,0.673553,-0.439758,-0.119873,-0.005524,-0.992737,0.098267,-0.213776,0.971893,-0.615631,0.643951,0.454163,0.896851,-0.441071,
0.032166,-0.555023,0.750763,-0.358093,0.398773,0.304688,0.864929,-0.722961,0.303589,0.620544,-0.63559,-0.621948,-0.457306,-0.293243,0.072327,0.953278,-0.491638,0.661041,-0.566772,-0.304199,-0.572083,-0.761688,0.908081,-0.398956,0.127014,-0.523621,-0.549683,-0.650848,-0.932922,-0.19986,0.299408,0.099426,
0.140869,0.984985,-0.020325,-0.999756,-0.002319,0.952667,0.280853,-0.11615,-0.971893,0.082581,0.220337,0.65921,0.705292,-0.260651,0.733063,-0.175537,0.657043,-0.555206,0.429504,-0.712189,0.400421,-0.89859,0.179352,0.750885,-0.19696,0.630341,0.785675,-0.569336,0.241821,-0.058899,-0.464111,0.883789,
0.129608,-0.94519,0.299622,-0.357819,0.907654,0.219238,-0.842133,-0.439117,-0.312927,-0.313477,0.84433,0.434479,-0.241211,0.053253,0.968994,0.063873,0.823273,0.563965,0.476288,0.862152,-0.172516,0.620941,-0.298126,0.724915,0.25238,-0.749359,-0.612122,-0.577545,0.386566,0.718994,-0.406342,-0.737976,
0.538696,0.04718,0.556305,0.82959,-0.802856,0.587463,0.101166,-0.707733,-0.705963,0.026428,0.374908,0.68457,0.625092,0.472137,0.208405,-0.856506,-0.703064,-0.581085,-0.409821,-0.417206,-0.736328,0.532623,-0.447876,-0.20285,-0.870728,0.086945,-0.990417,0.107086,0.183685,0.018341,-0.982788,0.560638,
-0.428864,0.708282,0.296722,-0.952576,-0.0672,0.135773,0.990265,0.030243,-0.068787,0.654724,0.752686,0.762604,-0.551758,0.337585,-0.819611,-0.407684,0.402466,-0.727844,-0.55072,-0.408539,-0.855774,-0.480011,0.19281,0.693176,-0.079285,0.716339,0.226013,0.650116,-0.725433,0.246704,0.953369,-0.173553,
-0.970398,-0.239227,-0.03244,0.136383,-0.394318,0.908752,0.813232,0.558167,0.164368,0.40451,0.549042,-0.731323,-0.380249,-0.566711,0.730865,0.022156,0.932739,0.359741,0.00824,0.996552,-0.082306,0.956635,-0.065338,-0.283722,-0.743561,0.008209,0.668579,-0.859589,-0.509674,0.035767,-0.852234,0.363678,
-0.375977,-0.201965,-0.970795,-0.12915,0.313477,0.947327,0.06546,-0.254028,-0.528259,0.81015,0.628052,0.601105,0.49411,-0.494385,0.868378,0.037933,0.275635,-0.086426,0.957336,-0.197937,0.468903,-0.860748,0.895599,0.399384,0.195801,0.560791,0.825012,-0.069214,0.304199,-0.849487,0.43103,0.096375,
0.93576,0.339111,-0.051422,0.408966,-0.911072,0.330444,0.942841,-0.042389,-0.452362,-0.786407,0.420563,0.134308,-0.933472,-0.332489,0.80191,-0.566711,-0.188934,-0.987946,-0.105988,0.112518,-0.24408,0.892242,-0.379791,-0.920502,0.229095,-0.316376,0.7789,0.325958,0.535706,-0.912872,0.185211,-0.36377,
-0.184784,0.565369,-0.803833,-0.018463,0.119537,0.992615,-0.259247,-0.935608,0.239532,-0.82373,-0.449127,-0.345947,-0.433105,0.659515,0.614349,-0.822754,0.378845,-0.423676,0.687195,-0.674835,-0.26889,-0.246582,-0.800842,0.545715,-0.729187,-0.207794,0.651978,0.653534,-0.610443,-0.447388,0.492584,-0.023346,
0.869934,0.609039,0.009094,-0.79306,0.962494,-0.271088,-0.00885,0.2659,-0.004913,0.963959,0.651245,0.553619,-0.518951,0.280548,-0.84314,0.458618,-0.175293,-0.983215,0.049805,0.035339,-0.979919,0.196045,-0.982941,0.164307,-0.082245,0.233734,-0.97226,-0.005005,-0.747253,-0.611328,0.260437,0.645599,
0.592773,0.481384,0.117706,-0.949524,-0.29068,-0.535004,-0.791901,-0.294312,-0.627167,-0.214447,0.748718,-0.047974,-0.813477,-0.57959,-0.175537,0.477264,-0.860992,0.738556,-0.414246,-0.53183,0.562561,-0.704071,0.433289,-0.754944,0.64801,-0.100586,0.114716,0.044525,-0.992371,0.966003,0.244873,-0.082764,
0.33783,0.715698,-0.611206,-0.944031,-0.326599,-0.045624};
#define DOT(a,b) (a[0] * b[0] + a[1] * b[1] + a[2] * b[2])
#define setup(i,b0,b1,r0,r1) \
t = vec[i] + 10000.; \
b0 = ((int)t) & 255; \
b1 = (b0+1) & 255; \
r0 = t - (int)t; \
r1 = r0 - 1.;
float noise3_perlin(float vec[3])
{
int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, rz0, rz1, *q, sx, sy, sz, a, b, c, d, t, u, v;
register int i, j;
setup(0, bx0,bx1, rx0,rx1);
setup(1, by0,by1, ry0,ry1);
setup(2, bz0,bz1, rz0,rz1);
i = p[ bx0 ];
j = p[ bx1 ];
b00 = p[ i + by0 ];
b10 = p[ j + by0 ];
b01 = p[ i + by1 ];
b11 = p[ j + by1 ];
#define at(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
#define surve(t) ( t * t * (3. - 2. * t) )
#define lerp(t, a, b) ( a + t * (b - a) )
sx = surve(rx0);
sy = surve(ry0);
sz = surve(rz0);
q = g[ b00 + bz0 ] ;
u = at(rx0,ry0,rz0);
q = g[ b10 + bz0 ] ;
v = at(rx1,ry0,rz0);
a = lerp(sx, u, v);
q = g[ b01 + bz0 ] ;
u = at(rx0,ry1,rz0);
q = g[ b11 + bz0 ] ;
v = at(rx1,ry1,rz0);
b = lerp(sx, u, v);
c = lerp(sy, a, b); /* interpolate in y at lo x */
q = g[ b00 + bz1 ] ;
u = at(rx0,ry0,rz1);
q = g[ b10 + bz1 ] ;
v = at(rx1,ry0,rz1);
a = lerp(sx, u, v);
q = g[ b01 + bz1 ] ;
u = at(rx0,ry1,rz1);
q = g[ b11 + bz1 ] ;
v = at(rx1,ry1,rz1);
b = lerp(sx, u, v);
d = lerp(sy, a, b); /* interpolate in y at hi x */
return 1.5 * lerp(sz, c, d); /* interpolate in z */
}
float turbulence_perlin(float *point, float lofreq, float hifreq)
{
float freq, t, p[3];
p[0] = point[0] + 123.456;
p[1] = point[1];
p[2] = point[2];
t = 0;
for (freq = lofreq ; freq < hifreq ; freq *= 2.) {
t += fabs(noise3_perlin(p)) / freq;
p[0] *= 2.;
p[1] *= 2.;
p[2] *= 2.;
}
return t - 0.3; /* readjust to make mean value = 0.0 */
}
/* *************** AANROEPEN ALS: *************** */
float BLI_hnoisep(float noisesize, float x, float y, float z)
{
float vec[3];
vec[0]= x/noisesize;
vec[1]= y/noisesize;
vec[2]= z/noisesize;
return noise3_perlin(vec);
}
float turbulencep(float noisesize, float x, float y, float z, int nr)
{
float vec[3];
vec[0]= x/noisesize;
vec[1]= y/noisesize;
vec[2]= z/noisesize;
nr++;
return turbulence_perlin(vec, 1.0, (float)(1<<nr));
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "PIL_time.h"
#include "BLI_rand.h"
#ifdef WIN32
typedef unsigned __int64 r_uint64;
#else
typedef unsigned long long r_uint64;
#endif
#define MULTIPLIER 0x5DEECE66D
#define ADDEND 0xB
#define LOWSEED 0x330E
static r_uint64 X= 0;
void BLI_srand(unsigned int seed) {
X= (((r_uint64) seed)<<16) | LOWSEED;
}
int BLI_rand(void) {
X= (MULTIPLIER*X + ADDEND)&0x0000FFFFFFFFFFFF;
return (int) (X>>17);
}
double BLI_drand(void) {
return (double) BLI_rand()/0x80000000;
}
float BLI_frand(void) {
return (float) BLI_rand()/0x80000000;
}
void BLI_storerand(unsigned int loc_r[2]) {
loc_r[0]= (unsigned int) (X>>32);
loc_r[1]= (unsigned int) (X&0xFFFFFFFF);
}
void BLI_restorerand(unsigned int loc[2]) {
X= ((r_uint64) loc[0])<<32;
X|= loc[1];
}
void BLI_fillrand(void *addr, int len) {
unsigned char *p= addr;
unsigned int save[2];
BLI_storerand(save);
BLI_srand((unsigned int) (PIL_check_seconds_timer()*0x7FFFFFFF));
while (len--) *p++= BLI_rand()&0xFF;
BLI_restorerand(save);
}

View File

@@ -0,0 +1,115 @@
/*
*
* rct.c
*
* april 95
*
* $Id$
*
* A minimalist lib for functions doing stuff with rectangle structs.
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
*/
#include "DNA_vec_types.h"
#include "BLI_blenlib.h"
int BLI_rcti_is_empty(rcti * rect)
{
return ((rect->xmax<=rect->xmin) ||
(rect->ymax<=rect->ymin));
}
int BLI_in_rcti(rcti * rect, int x, int y)
{
if(x<rect->xmin) return 0;
if(x>rect->xmax) return 0;
if(y<rect->ymin) return 0;
if(y>rect->ymax) return 0;
return 1;
}
int BLI_in_rctf(rctf *rect, float x, float y)
{
if(x<rect->xmin) return 0;
if(x>rect->xmax) return 0;
if(y<rect->ymin) return 0;
if(y>rect->ymax) return 0;
return 1;
}
void BLI_union_rctf(rctf *rct1, rctf *rct2)
{
if(rct1->xmin>rct2->xmin) rct1->xmin= rct2->xmin;
if(rct1->xmax<rct2->xmax) rct1->xmax= rct2->xmax;
if(rct1->ymin>rct2->ymin) rct1->ymin= rct2->ymin;
if(rct1->ymax<rct2->ymax) rct1->ymax= rct2->ymax;
}
void BLI_init_rctf(rctf *rect, float xmin, float xmax, float ymin, float ymax)
{
rect->xmin= xmin;
rect->xmax= xmax;
rect->ymin= ymin;
rect->ymax= ymax;
}
int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest)
{
float xmin, xmax;
float ymin, ymax;
xmin = (src1->xmin) > (src2->xmin) ? (src1->xmin) : (src2->xmin);
xmax = (src1->xmax) < (src2->xmax) ? (src1->xmax) : (src2->xmax);
ymin = (src1->ymin) > (src2->ymin) ? (src1->ymin) : (src2->ymin);
ymax = (src1->ymax) < (src2->ymax) ? (src1->ymax) : (src2->ymax);
if(xmax>=xmin && ymax>=ymin) {
if(dest) {
dest->xmin = xmin;
dest->xmax = xmax;
dest->ymin = ymin;
dest->ymax = ymax;
}
return 1;
}
else {
if(dest) {
dest->xmin = 0;
dest->xmax = 0;
dest->ymin = 0;
dest->ymax = 0;
}
return 0;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,568 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Reorganised mar-01 nzc
* Some really low-level file thingies.
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h> /* voorkomt dat je bij malloc type moet aangeven */
#ifdef WIN32
#include <windows.h>
#include "BLI_winstuff.h"
#include <sys/types.h>
#include <io.h>
#include <direct.h>
#endif
#ifndef WIN32
#include <dirent.h>
#endif
#include <time.h>
#include <sys/stat.h>
#if defined(__sgi) || defined(__sun__)
#include <sys/statfs.h>
#endif
#ifdef __FreeBSD__
#include <sys/param.h>
#include <sys/mount.h>
#endif
#if defined(linux) || defined(__CYGWIN32__)
#include <sys/vfs.h>
#endif
#ifdef __BeOS
struct statfs {
int f_bsize;
int f_bfree;
};
#endif
#ifdef __APPLE__
/* For statfs */
#include <sys/param.h>
#include <sys/mount.h>
#endif /* __APPLE__ */
#include <fcntl.h>
#if !defined(__BeOS) && !defined(WIN32)
#include <sys/mtio.h> /* tape comando's */
#endif
#include <string.h> /* strcpy etc.. */
#ifndef WIN32
#include <sys/ioctl.h>
#include <unistd.h> /* */
#include <pwd.h>
#endif
/* MAART: #ifndef __FreeBSD__ */
#if !defined(__FreeBSD__) && !defined(__APPLE__)
#include <malloc.h>
#endif
/* lib includes */
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "BLI_blenlib.h"
#include "BLI_storage.h"
#include "BLI_storage_types.h"
#include "BLI_util.h"
#include "BLI_linklist.h"
/* functions */
void BLI_buildpwtable(struct passwd **pwtable);
void BLI_freepwtable(struct passwd *pwtable);
char *BLI_findpwtable(struct passwd *pwtable, unsigned short user);
/* vars: */
static int totnum,actnum;
static struct direntry *files;
static struct ListBase dirbase_={
0,0};
static struct ListBase *dirbase = &dirbase_;
char *BLI_getwdN(char *dir)
{
char *pwd;
if (dir) {
pwd = getenv("PWD");
if (pwd){
strcpy(dir, pwd);
return(dir);
}
/* 160 is FILE_MAXDIR in filesel.c */
return( getcwd(dir, 160) );
}
return(0);
}
int BLI_compare(struct direntry *entry1, struct direntry *entry2)
{
/* type is gelijk aan stat.st_mode */
if (S_ISDIR(entry1->type)){
if (S_ISDIR(entry2->type)==0) return (-1);
} else{
if (S_ISDIR(entry2->type)) return (1);
}
if (S_ISREG(entry1->type)){
if (S_ISREG(entry2->type)==0) return (-1);
} else{
if (S_ISREG(entry2->type)) return (1);
}
if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
return (strcasecmp(entry1->relname,entry2->relname));
}
double BLI_diskfree(char *dir)
{
#ifdef WIN32
DWORD sectorspc, bytesps, freec, clusters;
char tmp[4];
tmp[0]='\\'; tmp[1]=0; /* Just a failsafe */
if (dir[0]=='/' || dir[0]=='\\') {
tmp[0]='\\';
tmp[1]=0;
} else if (dir[1]==':') {
tmp[0]=dir[0];
tmp[1]=':';
tmp[2]='\\';
tmp[3]=0;
}
GetDiskFreeSpace(tmp,&sectorspc, &bytesps, &freec, &clusters);
return (double) (freec*bytesps*sectorspc);
#else
struct statfs disk;
char name[100],*slash;
strcpy(name,dir);
if(strlen(name)){
slash = strrchr(name,'/');
if (slash) slash[1] = 0;
} else strcpy(name,"/");
#if defined __FreeBSD__ || defined linux
if (statfs(name, &disk)) return(-1);
#endif
#ifdef __BeOS
return -1;
#endif
#if defined __sgi || defined __sun__
if (statfs(name, &disk, sizeof(struct statfs), 0)){
/* printf("diskfree: Couldn't get information about %s.\n",dir); */
return(-1);
}
#endif
return ( ((double) disk.f_bsize) * ((double) disk.f_bfree));
#endif
}
static int hide_dot= 0;
void BLI_hide_dot_files(int set)
{
if(set) hide_dot= 1;
else hide_dot= 0;
}
void BLI_builddir(char *dirname, char *relname)
{
struct dirent *fname;
struct dirlink *dlink;
int rellen, newnum = 0, seen_ = 0, seen__ = 0;
char buf[256];
DIR *dir;
strcpy(buf,relname);
rellen=strlen(relname);
if (rellen){
buf[rellen]='/';
rellen++;
}
if (chdir(dirname) == -1){
perror(dirname);
return;
}
if (dir = (DIR *)opendir(".")){
while ((fname = (struct dirent*) readdir(dir)) != NULL) {
if(hide_dot && fname->d_name[0]=='.' && fname->d_name[1]!='.' && fname->d_name[1]!=0);
else {
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
if (dlink){
strcpy(buf+rellen,fname->d_name);
dlink->name = strdup(buf);
if (dlink->name[0] == '.') {
if (dlink->name[1] == 0) seen_ = 1;
else if (dlink->name[1] == '.') {
if (dlink->name[2] == 0) seen__ = 1;
}
}
BLI_addhead(dirbase,dlink);
newnum++;
}
}
}
if (newnum){
#ifndef WIN32
if (seen_ == 0) { /* Cachefs PATCH */
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
strcpy(buf+rellen,"./.");
dlink->name = strdup(buf);
BLI_addhead(dirbase,dlink);
newnum++;
}
if (seen__ == 0) { /* MAC PATCH */
dlink = (struct dirlink *)malloc(sizeof(struct dirlink));
strcpy(buf+rellen,"./..");
dlink->name = strdup(buf);
BLI_addhead(dirbase,dlink);
newnum++;
}
#endif
if (files) files=(struct direntry *)realloc(files,(totnum+newnum) * sizeof(struct direntry));
else files=(struct direntry *)malloc(newnum * sizeof(struct direntry));
if (files){
dlink = (struct dirlink *) dirbase->first;
while(dlink){
memset(&files[actnum], 0 , sizeof(struct direntry));
files[actnum].relname = dlink->name;
stat(dlink->name,&files[actnum].s);
files[actnum].type=files[actnum].s.st_mode;
files[actnum].flags = 0;
totnum++;
actnum++;
dlink = dlink->next;
}
} else{
printf("Couldn't get memory for dir\n");
exit(1);
}
BLI_freelist(dirbase);
if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))BLI_compare);
} else {
printf("%s empty directory\n",dirname);
}
closedir(dir);
} else {
printf("%s non-existant directory\n",dirname);
}
}
#ifndef WIN32
void BLI_buildpwtable(struct passwd **pwtable)
{
int count=0,slen;
struct passwd *pw,*pwtab;
do{
pw=getpwent();
if (pw){
count++;
}
}while(pw);
endpwent();
pwtab = (struct passwd *)calloc(count+1,sizeof(struct passwd));
count=0;
do{
pw=getpwent();
if (pw){
pwtab[count] = *pw;
slen = strlen(pw->pw_name);
pwtab[count].pw_name = malloc(slen+1);
strcpy(pwtab[count].pw_name,pw->pw_name);
count ++;
}
}while(pw);
pwtab[count].pw_name = 0;
endpwent();
*(pwtable) = pwtab;
}
void BLI_freepwtable(struct passwd *pwtable)
{
int count=0;
do{
if (pwtable[count].pw_name) free(pwtable[count].pw_name);
else break;
count++;
}while (1);
free(pwtable);
}
char *BLI_findpwtable(struct passwd *pwtable, ushort user)
{
static char string[32];
while (pwtable->pw_name){
if (pwtable->pw_uid == user){
return (pwtable->pw_name);
}
pwtable++;
}
sprintf(string, "%d", user);
return (string);
}
#endif
void BLI_adddirstrings()
{
char datum[100];
char buf[250];
char size[250];
static char * types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
int num, mode;
int num1, num2, num3, num4, st_size;
#ifndef WIN32
struct passwd *pwtable;
#endif
struct direntry * file;
struct tm *tm;
#ifndef WIN32
BLI_buildpwtable(&pwtable);
#endif
file = &files[0];
for(num=0;num<actnum;num++){
#ifdef WIN32
mode = 0;
strcpy(file->mode1, types[0]);
strcpy(file->mode2, types[0]);
strcpy(file->mode3, types[0]);
#else
mode = file->s.st_mode;
strcpy(file->mode1, types[(mode & 0700) >> 6]);
strcpy(file->mode2, types[(mode & 0070) >> 3]);
strcpy(file->mode3, types[(mode & 0007)]);
if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2]=='-'))file->mode2[2]='l';
if (mode & (S_ISUID | S_ISGID)){
if (file->mode1[2]=='x') file->mode1[2]='s';
else file->mode1[2]='S';
if (file->mode2[2]=='x')file->mode2[2]='s';
}
if (mode & S_ISVTX){
if (file->mode3[2] == 'x') file->mode3[2] = 't';
else file->mode3[2] = 'T';
}
#endif
#ifdef WIN32
strcpy(files[num].owner,"user");
#else
strcpy(files[num].owner, BLI_findpwtable(pwtable,files[num].s.st_uid));
#endif
tm= localtime(&files[num].s.st_mtime);
strftime(files[num].time, 8, "%H:%M", tm);
strftime(files[num].date, 16, "%d-%b-%y", tm);
st_size= (int)files[num].s.st_size;
num1= st_size % 1000;
num2= st_size/1000;
num2= num2 % 1000;
num3= st_size/(1000*1000);
num3= num3 % 1000;
num4= st_size/(1000*1000*1000);
num4= num4 % 1000;
if(num4) sprintf(files[num].size, "%3d %03d %03d %03d", num4, num3, num2, num1);
else if(num3) sprintf(files[num].size, "%7d %03d %03d", num3, num2, num1);
else if(num2) sprintf(files[num].size, "%11d %03d", num2, num1);
else if(num1) sprintf(files[num].size, "%15d", num1);
else sprintf(files[num].size, "");
strftime(datum, 32, "%d-%b-%y %R", tm);
if (st_size < 1000) {
sprintf(size, "%10d", st_size);
} else if (st_size < 1000 * 1000) {
sprintf(size, "%6d %03d", st_size / 1000, st_size % 1000);
} else if (st_size < 100 * 1000 * 1000) {
sprintf(size, "%2d %03d %03d", st_size / (1000 * 1000), (st_size / 1000) % 1000, st_size % 1000);
} else {
sprintf(size, "> %4.1f M", st_size / (1024.0 * 1024.0));
sprintf(size, "%10d", st_size);
}
sprintf(buf,"%s %s %10s %s", files[num].date, files[num].time, size,
files[num].relname);
sprintf(buf,"%s %s %s %7s %s %s %10s %s", file->mode1, file->mode2, file->mode3, files[num].owner, files[num].date, files[num].time, size,
files[num].relname);
files[num].string=malloc(strlen(buf)+1);
if (files[num].string){
strcpy(files[num].string,buf);
}
file++;
}
#ifndef WIN32
BLI_freepwtable(pwtable);
#endif
}
unsigned int BLI_getdir(char *dirname, struct direntry **filelist)
{
// reset global variables
// memory stored in files is free()'d in
// filesel.c:freefilelist()
actnum = totnum = 0;
files = 0;
BLI_builddir(dirname,"");
BLI_adddirstrings();
if (files) {
*(filelist) = files;
} else {
// keep blender happy. Blender stores this in a variable
// where 0 has special meaning.....
*(filelist) = files = malloc(sizeof(struct direntry));
}
return(actnum);
}
int BLI_filesize(int file)
{
struct stat buf;
if (file <= 0) return (-1);
fstat(file, &buf);
return (buf.st_size);
}
int BLI_exist(char *name)
{
struct stat st;
if (stat(name,&st)) return(0);
return(st.st_mode);
}
LinkNode *BLI_read_file_as_lines(char *name)
{
FILE *fp= fopen(name, "r");
LinkNode *lines= NULL;
char *buf;
int size;
if (!fp) return NULL;
fseek(fp, 0, SEEK_END);
size= ftell(fp);
fseek(fp, 0, SEEK_SET);
buf= malloc(size);
if (buf) {
int i, last= 0;
/*
* size = because on win32 reading
* all the bytes in the file will return
* less bytes because of crnl changes.
*/
size= fread(buf, 1, size, fp);
for (i=0; i<=size; i++) {
if (i==size || buf[i]=='\n') {
char *line= BLI_strdupn(&buf[last], i-last);
BLI_linklist_prepend(&lines, line);
last= i+1;
}
}
free(buf);
}
fclose(fp);
BLI_linklist_reverse(&lines);
return lines;
}
void BLI_free_file_lines(LinkNode *lines)
{
BLI_linklist_free(lines, (void(*)(void*)) MEM_freeN);
}

View File

@@ -0,0 +1,101 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "PIL_time.h"
#ifdef WIN32
#include <windows.h>
double PIL_check_seconds_timer(void)
{
static int hasperfcounter= -1; /* -1==unknown */
static double perffreq;
if (hasperfcounter==-1) {
__int64 ifreq;
hasperfcounter= QueryPerformanceFrequency((LARGE_INTEGER*) &ifreq);
perffreq= (double) ifreq;
}
if (hasperfcounter) {
__int64 count;
QueryPerformanceCounter((LARGE_INTEGER*) &count);
return count/perffreq;
} else {
static double accum= 0.0;
static int ltick= 0;
int ntick= GetTickCount();
if (ntick<ltick) {
accum+= (0xFFFFFFFF-ltick+ntick)/1000.0;
} else {
accum+= (ntick-ltick)/1000.0;
}
ltick= ntick;
return accum;
}
}
void PIL_sleep_ms(int ms)
{
Sleep(ms);
}
#else
#include <unistd.h>
#include <sys/time.h>
double PIL_check_seconds_timer(void)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return ((double) tv.tv_sec + tv.tv_usec/1000000.0);
}
void PIL_sleep_ms(int ms)
{
if (ms>=1000) {
sleep(ms/1000);
ms= (ms%1000);
}
usleep(ms*1000);
}
#endif

View File

@@ -0,0 +1,828 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Diverse string, file, list operations.
*/
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "DNA_listBase.h"
#include "BLI_storage.h"
#include "BLI_storage_types.h"
#include "BLI_util.h"
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#ifndef WIN32
#include <sys/time.h>
#endif
/* local */
static int add_win32_extension(char *name);
/* implementation */
/* Ripped this from blender.c
*/
void addlisttolist(ListBase *list1, ListBase *list2)
{
if(list2->first==0) return;
if(list1->first==0) {
list1->first= list2->first;
list1->last= list2->last;
}
else {
((struct Link *)list1->last)->next= list2->first;
((struct Link *)list2->first)->prev= list1->last;
list1->last= list2->last;
}
list2->first= list2->last= 0;
}
int BLI_stringdec(char *string, char *kop, char *staart, unsigned short *numlen)
{
unsigned short len, len2, nums = 0, nume = 0;
short i, found = 0;
len2 = len = strlen( string);
if (len > 6) {
if (strncasecmp(string + len - 6, ".blend", 6) == 0) len -= 6;
else if (strncasecmp(string + len - 6, ".trace", 6) == 0) len -= 6;
}
if (len == len2) {
if (len > 4) {
/* .jf0 en .jf1 voor jstreams afvangen */
if (strncasecmp(string + len - 4, ".jf", 3) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".tga", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".jpg", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".png", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".txt", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".cyc", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".enh", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".rgb", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".psx", 4) == 0) len -= 4;
else if (strncasecmp(string + len - 4, ".ble", 4) == 0) len -= 4;
}
}
for (i = len - 1; i >= 0; i--){
if (string[i] == '/') break;
if (isdigit(string[i])) {
if (found){
nums = i;
}
else{
nume = i;
nums = i;
found = 1;
}
}
else{
if (found) break;
}
}
if (found){
if (staart) strcpy(staart,&string[nume+1]);
if (kop) {
strcpy(kop,string);
kop[nums]=0;
}
if (numlen) *numlen = nume-nums+1;
return ((int)atoi(&(string[nums])));
}
if (staart) strcpy(staart, string + len);
if (kop) {
strncpy(kop, string, len);
kop[len] = 0;
}
if (numlen) *numlen=0;
return 0;
}
void BLI_stringenc(char *string, char *kop, char *staart, unsigned short numlen, int pic)
{
char numstr[10]="";
unsigned short len,i;
strcpy(string,kop);
if (pic>0 || numlen==4) {
len= sprintf(numstr,"%d",pic);
for(i=len;i<numlen;i++){
strcat(string,"0");
}
strcat(string,numstr);
}
strcat(string,staart);
}
void BLI_newname(char * name, int add)
{
char head[128], tail[128];
int pic;
unsigned short digits;
pic = BLI_stringdec(name, head, tail, &digits);
/* gaan we van 100 -> 99 of van 10 naar 9 */
if (add < 0 && digits < 4 && digits > 0) {
int i, exp;
exp = 1;
for (i = digits; i > 1; i--) exp *= 10;
if (pic >= exp && (pic + add) < exp) digits--;
}
pic += add;
if(digits==4 && pic<0) pic= 0;
BLI_stringenc(name, head, tail, digits, pic);
}
void BLI_addhead(ListBase *listbase, void *vlink)
{
struct Link *link= vlink;
if (link == 0) return;
if (listbase == 0) return;
link->next = listbase->first;
link->prev = 0;
if (listbase->first) ((struct Link *)listbase->first)->prev = link;
if (listbase->last == 0) listbase->last = link;
listbase->first = link;
}
void BLI_addtail(ListBase *listbase, void *vlink)
{
struct Link *link= vlink;
if (link == 0) return;
if (listbase == 0) return;
link->next = 0;
link->prev = listbase->last;
if (listbase->last) ((struct Link *)listbase->last)->next = link;
if (listbase->first == 0) listbase->first = link;
listbase->last = link;
}
void BLI_remlink(ListBase *listbase, void *vlink)
{
struct Link *link= vlink;
if (link == 0) return;
if (listbase == 0) return;
if (link->next) link->next->prev = link->prev;
if (link->prev) link->prev->next = link->next;
if (listbase->last == link) listbase->last = link->prev;
if (listbase->first == link) listbase->first = link->next;
}
void BLI_freelinkN(ListBase *listbase, void *vlink)
{
struct Link *link= vlink;
if (link == 0) return;
if (listbase == 0) return;
BLI_remlink(listbase,link);
MEM_freeN(link);
}
void BLI_insertlink(ListBase *listbase, void *vprevlink, void *vnewlink)
{
struct Link *prevlink= vprevlink, *newlink= vnewlink;
/* newlink komt na prevlink */
if (newlink == 0) return;
if (listbase == 0) return;
if(listbase->first==0) { /* lege lijst */
listbase->first= newlink;
listbase->last= newlink;
return;
}
if (prevlink== 0) { /* inserten voor eerste element */
newlink->next= listbase->first;
newlink->prev= 0;
newlink->next->prev= newlink;
listbase->first= newlink;
return;
}
if (listbase->last== prevlink) /* aan einde lijst */
listbase->last = newlink;
newlink->next= prevlink->next;
prevlink->next= newlink;
if(newlink->next) newlink->next->prev= newlink;
newlink->prev= prevlink;
}
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink)
{
struct Link *nextlink= vnextlink, *newlink= vnewlink;
/* newlink komt voor nextlink */
if (newlink == 0) return;
if (listbase == 0) return;
if(listbase->first==0) { /* lege lijst */
listbase->first= newlink;
listbase->last= newlink;
return;
}
if (nextlink== 0) { /* inserten aan einde lijst */
newlink->prev= listbase->last;
newlink->next= 0;
((struct Link *)listbase->last)->next= newlink;
listbase->last= newlink;
return;
}
if (listbase->first== nextlink) /* aan begin lijst */
listbase->first = newlink;
newlink->next= nextlink;
newlink->prev= nextlink->prev;
nextlink->prev= newlink;
if(newlink->prev) newlink->prev->next= newlink;
}
void BLI_freelist(ListBase *listbase)
{
struct Link *link,*next;
if (listbase == 0) return;
link= listbase->first;
while(link) {
next= link->next;
free(link);
link= next;
}
listbase->first=0;
listbase->last=0;
}
void BLI_freelistN(ListBase *listbase)
{
struct Link *link,*next;
if (listbase == 0) return;
link= listbase->first;
while(link) {
next= link->next;
MEM_freeN(link);
link= next;
}
listbase->first=0;
listbase->last=0;
}
int BLI_countlist(ListBase *listbase)
{
Link * link;
int count = 0;
if (listbase){
link = listbase->first;
while(link) {
count++;
link= link->next;
}
}
return(count);
}
void * BLI_findlink(ListBase *listbase, int number)
{
Link * link = NULL;
if (number >= 0) {
link = listbase->first;
while (link != NULL && number != 0) {
number--;
link = link->next;
}
}
return (link);
}
char *BLI_strdupn(char *str, int len) {
char *n= MEM_mallocN(len+1, "strdup");
memcpy(n, str, len);
n[len]= '\0';
return n;
}
char *BLI_strdup(char *str) {
return BLI_strdupn(str, strlen(str));
}
char *BLI_strncpy(char *dst, char *src, int maxncpy) {
int srclen= strlen(src);
int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen;
memcpy(dst, src, cpylen);
dst[cpylen]= '\0';
return dst;
}
int BLI_streq(char *a, char *b) {
return (strcmp(a, b)==0);
}
int BLI_strcaseeq(char *a, char *b) {
return (strcasecmp(a, b)==0);
}
void BLI_makestringcode(char *fromfile, char *str)
{
char *slash, len, temp[512];
strcpy(temp, fromfile);
/* Find the last slash */
slash = (strrchr(temp, '/')>strrchr(temp, '\\'))
? strrchr(temp, '/') : strrchr(temp, '\\');
if(slash) {
*(slash+1)= 0;
len= strlen(temp);
if(len) {
if(strncmp(str, temp, len)==0) {
temp[0]= '/';
temp[1]= '/';
strcpy(temp+2, str+len);
strcpy(str, temp);
}
}
}
}
int BLI_convertstringcode(char *path, char *basepath, int framenum)
{
int len, wasrelative= (strncmp(path, "//", 2)==0);
if (path[0] == '/' && path[1] == '/') {
char *filepart= BLI_strdup(path+2); /* skip code */
char *lslash= BLI_last_slash(basepath);
if (lslash) {
int baselen= (int) (lslash-basepath) + 1;
memcpy(path, basepath, baselen);
strcpy(path+baselen, filepart);
} else {
strcpy(path, filepart);
}
MEM_freeN(filepart);
}
len= strlen(path);
if(len && path[len-1]=='#') {
sprintf(path+len-1, "%04d", framenum);
}
return wasrelative;
}
void BLI_splitdirstring(char *di,char *fi)
{
char *lslash= BLI_last_slash(di);
if (lslash) {
strcpy(fi, lslash+1);
*(lslash+1)=0;
} else {
strcpy(fi, di);
di[0]= 0;
}
}
char *BLI_gethome(void) {
#ifdef __BeOS
return "/boot/home/"; /* BeOS 4.5: doubleclick at icon doesnt give home env */
#elif !defined(WIN32)
return getenv("HOME");
#else /* Windows */
char * ret;
static char dir[512];
ret = getenv("HOME");
if(ret) {
if (BLI_exists(ret)) return ret;
}
// add user profile support for WIN 2K / NT
ret = getenv("USERPROFILE");
if (ret) {
if (BLI_exists(ret)) { /* from fop, also below... */
sprintf(dir, "%s/Application Data/Not a Number/Blender", ret);
BLI_recurdir_fileops(dir);
if (BLI_exists(dir)) {
return(dir);
} else {
return(ret);
}
}
}
ret = getenv("WINDOWS");
if (ret) {
if(BLI_exists(ret)) return ret;
}
ret = getenv("WINDIR");
if (ret) {
if(BLI_exists(ret)) return ret;
}
return "C:\\Temp";
#endif
}
static void char_switch(char *string, char from, char to)
{
while (*string != 0) {
if (*string == from) *string = to;
string++;
}
}
void BLI_make_exist(char *dir)
{
int a;
#ifdef WIN32
char_switch(dir, '/', '\\');
#else
char_switch(dir, '\\', '/');
#endif
a = strlen(dir);
#ifdef WIN32
while(BLI_exists(dir) == 0){
a --;
while(dir[a] != '\\'){
a--;
if (a <= 0) break;
}
if (a >= 0) dir[a+1] = 0;
else {
strcpy(dir,"\\");
break;
}
}
#else
while(BLI_exist(dir) == 0){
a --;
while(dir[a] != '/'){
a--;
if (a <= 0) break;
}
if (a >= 0) dir[a+1] = 0;
else {
strcpy(dir,"/");
break;
}
}
#endif
}
void BLI_make_file_string(char *relabase, char *string, char *dir, char *file)
{
if (!string || !dir || !file) return; /* We don't want any NULLs */
string[0]= 0; /* ton */
/* Resolve relative references */
if (relabase && dir[0] == '/' && dir[1] == '/') {
char *lslash;
/* Get the file name, chop everything past the last slash (ie. the filename) */
strcpy(string, relabase);
lslash= (strrchr(string, '/')>strrchr(string, '\\'))?strrchr(string, '/'):strrchr(string, '\\');
if(lslash) *(lslash+1)= 0;
dir+=2; /* Skip over the relative reference */
}
strcat(string, dir);
/* Make sure string ends in one (and only one) slash */
if (string[strlen(string)-1] != '/' && string[strlen(string)-1] != '\\')
strcat(string, "/");
while (*file && (*file == '/' || *file == '\\')) /* Trim slashes from the front of file */
file++;
strcat (string, file);
/* Push all slashes to the system preferred direction */
#ifdef WIN32
char_switch(string, '/', '\\');
#else
char_switch(string, '\\', '/');
#endif
}
int BLI_testextensie(char *str, char *ext)
{
short a, b;
int retval;
a= strlen(str);
b= strlen(ext);
if(a==0 || b==0 || b>=a) {
retval = 0;
} else if (strcasecmp(ext, str + a - b)) {
retval = 0;
} else {
retval = 1;
}
return (retval);
}
void BLI_split_dirfile(char *string, char *dir, char *file)
{
int a;
dir[0]= 0;
file[0]= 0;
#ifdef WIN32
if (strlen(string)) {
if (string[0] == '/' || string[0] == '\\') {
strcpy(dir, string);
} else if (string[1] == ':' && string[2] == '\\') {
strcpy(dir, string);
} else {
BLI_getwdN(dir);
strcat(dir,"/");
strcat(dir,string);
strcpy(string,dir);
}
BLI_make_exist(dir);
if (S_ISDIR(BLI_exist(dir))) {
strcpy(file,string + strlen(dir));
if (strrchr(file,'\\')) strcpy(file,strrchr(file,'\\')+1);
if (a = strlen(dir)) {
if (dir[a-1] != '\\') strcat(dir,"\\");
}
}
else {
a = strlen(dir) - 1;
while(a>0 && dir[a] != '\\') a--;
dir[a + 1] = 0;
strcpy(file, string + strlen(dir));
}
}
else {
strcpy(dir, "\\");
file[0]=0;
}
#else
if (strlen(string)) {
if (string[0] == '/') {
strcpy(dir, string);
} else if (string[1] == ':' && string[2] == '\\') {
string+=2;
strcpy(dir, string);
} else {
BLI_getwdN(dir);
strcat(dir,"/");
strcat(dir,string);
strcpy(string,dir);
}
BLI_make_exist(dir);
if (S_ISDIR(BLI_exist(dir))) {
strcpy(file,string + strlen(dir));
if (strrchr(file,'/')) strcpy(file,strrchr(file,'/')+1);
if ( (a = strlen(dir)) ) {
if (dir[a-1] != '/') strcat(dir,"/");
}
}
else {
a = strlen(dir) - 1;
while(dir[a] != '/') a--;
dir[a + 1] = 0;
strcpy(file, string + strlen(dir));
}
}
else {
BLI_getwdN(dir);
strcat(dir, "/");
file[0] = 0;
}
#endif
}
// copies from BKE_utildefines
#ifndef FILE_MAXDIR
#define FILE_MAXDIR 160
#endif
#ifndef FILE_MAXFILE
#define FILE_MAXFILE 80
#endif
static int add_win32_extension(char *name)
{
int retval = 0;
int type;
type = BLI_exist(name);
if ((type == 0) || S_ISDIR(type)) {
#ifdef _WIN32
char filename[FILE_MAXDIR+FILE_MAXFILE];
char ext[FILE_MAXDIR+FILE_MAXFILE];
char *extensions = getenv("PATHEXT");
if (extensions) {
char *temp;
do {
strcpy(filename, name);
temp = strstr(extensions, ";");
if (temp) {
strncpy(ext, extensions, temp - extensions);
ext[temp - extensions] = 0;
extensions = temp + 1;
strcat(filename, ext);
} else {
strcat(filename, extensions);
}
type = BLI_exist(filename);
if (type && (! S_ISDIR(type))) {
retval = 1;
strcpy(name, filename);
break;
}
} while (temp);
}
#endif
} else {
retval = 1;
}
return (retval);
}
void BLI_where_am_i(char *fullname, char *name)
{
char filename[FILE_MAXDIR+FILE_MAXFILE];
char *path, *temp;
int len;
#ifdef _WIN32
char *seperator = ";";
char *slash = "\\";
#else
char *seperator = ":";
char *slash = "/";
#endif
if (name && fullname && strlen(name)) {
strcpy(fullname, name);
if (name[0] == '.') {
// relative path, prepend cwd
BLI_getwdN(fullname);
len = strlen(fullname);
if (len && fullname[len -1] != slash[0]) {
strcat(fullname, slash);
}
strcat(fullname, name);
add_win32_extension(fullname);
} else if (BLI_last_slash(name)) {
// full path
strcpy(fullname, name);
add_win32_extension(fullname);
} else {
// search for binary in $PATH
path = getenv("PATH");
if (path) {
do {
temp = strstr(path, seperator);
if (temp) {
strncpy(filename, path, temp - path);
filename[temp - path] = 0;
path = temp + 1;
} else {
strncpy(filename, path, sizeof(filename));
}
len = strlen(filename);
if (len && filename[len - 1] != slash[0]) {
strcat(filename, slash);
}
strcat(filename, name);
if (add_win32_extension(filename)) {
strcpy(fullname, filename);
break;
}
} while (temp);
}
}
#ifndef NDEBUG
if (strcmp(name, fullname)) {
printf("guessing '%s' == '%s'\n", name, fullname);
}
#endif
#ifdef _WIN32
// in windows change long filename to short filename because
// win2k doesn't know how to parse a commandline with lots of
// spaces and double-quotes. There's another solution to this
// with spawnv(P_WAIT, bprogname, argv) instead of system() but
// that's even uglier
GetShortPathName(fullname, fullname, FILE_MAXDIR+FILE_MAXFILE);
#ifndef NDEBUG
printf("Shortname = '%s'\n", fullname);
#endif
#endif
}
}

View File

@@ -0,0 +1,165 @@
/*
*
* Some vector operations.
*
* Always use
* - vector with x components : float x[3], int x[3], etc
*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/* ------------------------------------------------------------------------- */
/* General format: op(a, b, c): a = b op c */
/* Copying is done cp <from, to> */
/* ------------------------------------------------------------------------- */
#include "MTC_vectorops.h"
#include <math.h>
void MTC_diff3Int(int v1[3], int v2[3], int v3[3])
{
v1[0] = v2[0] - v3[0];
v1[1] = v2[1] - v3[1];
v1[2] = v2[2] - v3[2];
}
/* ------------------------------------------------------------------------- */
void MTC_diff3Float(float v1[3], float v2[3], float v3[3])
{
v1[0] = v2[0] - v3[0];
v1[1] = v2[1] - v3[1];
v1[2] = v2[2] - v3[2];
}
/* ------------------------------------------------------------------------- */
void MTC_cross3Int(int v1[3], int v2[3], int v3[3])
{
v1[0] = v2[1]*v3[2] - v2[2]*v3[1];
v1[1] = v2[2]*v3[0] - v2[0]*v3[2];
v1[2] = v2[0]*v3[1] - v2[1]*v3[0];
}
/* ------------------------------------------------------------------------- */
void MTC_cross3Float(float v1[3], float v2[3], float v3[3])
{
v1[0] = v2[1]*v3[2] - v2[2]*v3[1];
v1[1] = v2[2]*v3[0] - v2[0]*v3[2];
v1[2] = v2[0]*v3[1] - v2[1]*v3[0];
}
/* ------------------------------------------------------------------------- */
void MTC_cross3Double(double v1[3], double v2[3], double v3[3])
{
v1[0] = v2[1]*v3[2] - v2[2]*v3[1];
v1[1] = v2[2]*v3[0] - v2[0]*v3[2];
v1[2] = v2[0]*v3[1] - v2[1]*v3[0];
}
/* ------------------------------------------------------------------------- */
int MTC_dot3Int(int v1[3], int v2[3])
{
return (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
}
/* ------------------------------------------------------------------------- */
float MTC_dot3Float(float v1[3], float v2[3])
{
return (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
}
/* ------------------------------------------------------------------------- */
void MTC_cp3Float(float v1[3], float v2[3])
{
v2[0] = v1[0];
v2[1] = v1[1];
v2[2] = v1[2];
}
/* ------------------------------------------------------------------------- */
void MTC_cp3FloatInv(float v1[3], float v2[3])
{
v2[0] = -v1[0];
v2[1] = -v1[1];
v2[2] = -v1[2];
}
/* ------------------------------------------------------------------------- */
void MTC_swapInt(int *i1, int *i2)
{
int swap;
swap = *i1;
*i1 = *i2;
*i2 = swap;
}
/* ------------------------------------------------------------------------- */
void MTC_diff3DFF(double v1[3], float v2[3], float v3[3])
{
v1[0] = v2[0] - v3[0];
v1[1] = v2[1] - v3[1];
v1[2] = v2[2] - v3[2];
}
/* ------------------------------------------------------------------------- */
float MTC_normalise3DF(float n[3])
{
float d;
d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
/* FLT_EPSILON is too large! A larger value causes normalise errors in */
/* a scaled down utah teapot */
if(d>0.0000000000001) {
/* d= sqrt(d); This _should_ be sqrt, but internally it's a double*/
/* anyway. This is safe. */
d = sqrt(d);
n[0]/=d;
n[1]/=d;
n[2]/=d;
} else {
n[0]=n[1]=n[2]= 0.0;
d= 0.0;
}
return d;
}
/* ------------------------------------------------------------------------- */
/* eof */

View File

@@ -0,0 +1,193 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Windows-posix compatibility layer, windows-specific functions.
*/
#ifdef WIN32
#include <stdlib.h>
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_util.h"
#include "BLI_winstuff.h"
void RegisterBlendExtension(char * str) {
LONG lresult;
HKEY hkey = 0;
DWORD dwd = 0;
char buffer[128];
lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\shell\\open\\command", 0,
"", REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
if (lresult == ERROR_SUCCESS) {
sprintf(buffer, "\"%s\" \"%%1\"", str);
lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
RegCloseKey(hkey);
}
lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, "blendfile\\DefaultIcon", 0,
"", REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
if (lresult == ERROR_SUCCESS) {
sprintf(buffer, "\"%s\",1", str);
lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
RegCloseKey(hkey);
}
lresult = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".blend", 0,
"", REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd);
if (lresult == ERROR_SUCCESS) {
sprintf(buffer, "%s", "blendfile");
lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, buffer, strlen(buffer) + 1);
RegCloseKey(hkey);
}
}
static void strlower (char *str) {
while (*str) {
*str= tolower(*str);
str++;
}
}
static void strnlower (char *str, int n) {
while (n>0 && *str) {
*str= tolower(*str);
str++;
n--;
}
}
int strcasecmp (char *s1, char *s2) {
char *st1, *st2;
int r;
st1= MEM_mallocN(strlen(s1)+1, "temp string");
strcpy(st1, s1);
st2= MEM_mallocN(strlen(s2)+1, "temp string");
strcpy(st2, s2);
strlower(st1);
strlower(st2);
r= strcmp (st1, st2);
MEM_freeN(st1);
MEM_freeN(st2);
return r;
}
int strncasecmp (char *s1, char *s2, int n) {
char *st1, *st2;
int r;
st1= MEM_mallocN(n, "temp string");
memcpy(st1, s1, n);
st2= MEM_mallocN(n, "temp string");
memcpy(st2, s2, n);
strnlower(st1, n);
strnlower(st2, n);
r= strncmp (st1, st2, n);
MEM_freeN(st1);
MEM_freeN(st2);
return r;
}
DIR *opendir (const char *path) {
if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) {
DIR *newd= MEM_mallocN(sizeof(DIR), "opendir");
newd->handle = INVALID_HANDLE_VALUE;
sprintf(newd->path, "%s/*.*",path);
newd->direntry.d_ino= 0;
newd->direntry.d_off= 0;
newd->direntry.d_reclen= 0;
newd->direntry.d_name= NULL;
return newd;
} else {
return NULL;
}
}
struct dirent *readdir(DIR *dp) {
if (dp->direntry.d_name) {
MEM_freeN(dp->direntry.d_name);
dp->direntry.d_name= NULL;
}
if (dp->handle==INVALID_HANDLE_VALUE) {
dp->handle= FindFirstFile(dp->path, &(dp->data));
if (dp->handle==INVALID_HANDLE_VALUE)
return NULL;
dp->direntry.d_name= BLI_strdup(dp->data.cFileName);
return &dp->direntry;
} else if (FindNextFile (dp->handle, &(dp->data))) {
dp->direntry.d_name= BLI_strdup(dp->data.cFileName);
return &dp->direntry;
} else {
return NULL;
}
}
int closedir (DIR *dp) {
if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name);
if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle);
MEM_freeN(dp);
return 0;
}
#else
void BLI_WINSTUFF_C_IS_EMPTY_FOR_UNIX(void)
{
/*intentionally empty*/
}
#endif