diff options
439 files changed, 17124 insertions, 14933 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9360d930a5a..01f1dd69a9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,18 +91,6 @@ IF(NOT WITH_GAMEENGINE AND WITH_PLAYER) MESSAGE("WARNING: WITH_PLAYER needs WITH_GAMEENGINE") ENDIF(NOT WITH_GAMEENGINE AND WITH_PLAYER) -IF (WITH_OPENCOLLADA AND NOT APPLE) -SET(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory") -SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}) -SET(OPENCOLLADA_LIB OpenCollada) -SET(PCRE /usr CACHE FILEPATH "PCRE Directory") -SET(PCRE_LIBPATH ${PCRE}/lib) -SET(PCRE_LIB pcre) -SET(EXPAT /usr CACHE FILEPATH "Expat Directory") -SET(EXPAT_LIBPATH ${EXPAT}/lib) -SET(EXPAT_LIB expat) -ENDIF (WITH_OPENCOLLADA AND NOT APPLE) - # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g: # On Unix: # cmake -D PYTHON_LIB=/usr/local/lib/python2.3/config/libpython2.3.so -D PYTHON_INC=/usr/local/include/python2.3 -D PYTHON_BINARY=/usr/local/bin/python2.3 -G "Unix Makefiles" ../blender @@ -119,6 +107,8 @@ INCLUDE(CMake/macros.cmake) #Platform specifics IF(UNIX AND NOT APPLE) + + IF(WITH_OPENAL) FIND_PACKAGE(OpenAL) IF(OPENAL_FOUND) @@ -217,6 +207,20 @@ IF(UNIX AND NOT APPLE) FIND_PACKAGE(ZLIB REQUIRED) + IF (WITH_OPENCOLLADA) + SET(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory") + SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}) + SET(OPENCOLLADA_LIB OpenCollada) + SET(OPENCOLLADA_INC ${OPENCOLLADA}) + SET(PCRE /usr CACHE FILEPATH "PCRE Directory") + SET(PCRE_LIBPATH ${PCRE}/lib) + SET(PCRE_LIB pcre) + SET(EXPAT /usr CACHE FILEPATH "Expat Directory") + SET(EXPAT_LIBPATH ${EXPAT}/lib) + SET(EXPAT_LIB expat) + ENDIF (WITH_OPENCOLLADA) + + # Could use ${X11_Xinput_LIB} ${X11_X11_LIB} too SET(LLIBS "-lXi -lutil -lc -lm -lpthread -lstdc++ -lX11") @@ -400,6 +404,16 @@ IF(WIN32) SET(WINTAB_INC ${LIBDIR}/wintab/include) + SET(OPENCOLLADA ${LIBDIR}/opencollada) + SET(OPENCOLLADA_INC ${OPENCOLLADA}/include) + SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib) + SET(OPENCOLLADA_LIB OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils OpenCOLLADAStreamWriter MathMLSolver GeneratedSaxParser UTF xml2 ) + #pcre is bundled with openCollada + #SET(PCRE ${LIBDIR}/pcre) + #SET(PCRE_LIBPATH ${PCRE}/lib) + SET(PCRE_LIB pcre) + + IF(CMAKE_CL_64) SET(PLATFORM_LINKFLAGS "/MACHINE:X64 /NODEFAULTLIB:libc.lib;MSVCRT.lib ") ELSE(CMAKE_CL_64) @@ -532,10 +546,10 @@ IF(APPLE) #SET(PCRE ${LIBDIR}/pcre) #SET(PCRE_LIBPATH ${PCRE}/lib) SET(PCRE_LIB pcre) - #native OSX libxml2 is used + #libxml2 is used #SET(EXPAT ${LIBDIR}/expat) #SET(EXPAT_LIBPATH ${EXPAT}/lib) - #SET(EXPAT_LIB expat) + SET(EXPAT_LIB) ENDIF (WITH_OPENCOLLADA) SET(SDL ${LIBDIR}/sdl) diff --git a/config/darwin-config.py b/config/darwin-config.py index 8a1b0eff6c1..03cc4eb1f8c 100644 --- a/config/darwin-config.py +++ b/config/darwin-config.py @@ -31,7 +31,7 @@ elif cmd_res[0]=='9': elif cmd_res[0]=='10': MAC_CUR_VER='10.6' -if MAC_PROC == 'powerpc': +if MACOSX_ARCHITECTURE == 'ppc': LCGDIR = '#../lib/darwin-6.1-powerpc' else : LCGDIR = '#../lib/darwin-9.x.universal' @@ -39,7 +39,7 @@ LIBDIR = '${LCGDIR}' BF_PYTHON_VERSION = '3.1' -if MAC_PROC == 'powerpc' and BF_PYTHON_VERSION == '2.3': +if MACOSX_ARCHITECTURE == 'ppc' and BF_PYTHON_VERSION == '2.3': MAC_MIN_VERS = '10.3' MACOSX_SDK='/Developer/SDKs/MacOSX10.3.9.sdk' CC = 'gcc' @@ -247,7 +247,20 @@ BF_OPENGL_LIBPATH = '/System/Library/Frameworks/OpenGL.framework/Libraries' BF_OPENGL_LINKFLAGS = ['-framework', 'OpenGL'] #OpenCollada flags -WITH_BF_COLLADA = False +WITH_BF_COLLADA = True +BF_COLLADA = '#source/blender/collada' +BF_COLLADA_INC = '${BF_COLLADA}' +BF_COLLADA_LIB = 'bf_collada' +BF_OPENCOLLADA = LIBDIR + '/opencollada' +BF_OPENCOLLADA_INC = '${BF_OPENCOLLADA}/include' +BF_OPENCOLLADA_LIB = 'OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils OpenCOLLADAStreamWriter MathMLSolver GeneratedSaxParser UTF xml2' +BF_OPENCOLLADA_LIBPATH = LIBDIR + '/opencollada' +BF_PCRE = LIBDIR + '/opencollada' +BF_PCRE_LIB = 'pcre' +BF_PCRE_LIBPATH = '${BF_PCRE}/lib' +#BF_EXPAT = '/usr' +#BF_EXPAT_LIB = 'expat' +#BF_EXPAT_LIBPATH = '/usr/lib' ############################################################################# ################### various compile settings and flags ################## diff --git a/extern/Makefile b/extern/Makefile index a30cd1d7ca3..4a2e7a6d59b 100644 --- a/extern/Makefile +++ b/extern/Makefile @@ -34,7 +34,7 @@ DIRS = glew/src # Cloth requires it ifeq ($(NAN_USE_BULLET), true) - DIRS += bullet2 + DIRS += bullet2 endif ifeq ($(WITH_BINRELOC), true) @@ -42,7 +42,9 @@ ifeq ($(WITH_BINRELOC), true) endif ifeq ($(WITH_OPENJPEG), true) - DIRS += libopenjpeg + ifndef BF_OPENJPEG + DIRS += libopenjpeg + endif endif ifeq ($(WITH_LZO), true) diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index bd812177f17..5e434c0eaa0 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -406,6 +406,17 @@ extern GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle, GHOST_TButtonMask mask, int* isDown); + +/*************************************************************************************** + ** Drag'n'drop operations + ***************************************************************************************/ + +/** + * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop + */ +extern void GHOST_setAcceptDragOperation(GHOST_SystemHandle systemhandle, GHOST_TInt8 canAccept); + + /** * Returns the event type. * @param eventhandle The handle to the event diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index 08794dfd085..e56a0dae879 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -351,6 +351,11 @@ public: */ virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0; + + /*************************************************************************************** + ** Access to clipboard. + ***************************************************************************************/ + /** * Returns the selection buffer * @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer @@ -363,6 +368,22 @@ public: */ virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0; + + /*************************************************************************************** + ** Drag'n'drop operations + ***************************************************************************************/ + + /** + * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop + */ + virtual void setAcceptDragOperation(bool canAccept) = 0; + + /** + * Returns acceptance of the dropped object + * Usually called by the "object dropped" event handling function + */ + virtual bool canAcceptDragOperation() const = 0; + protected: /** * Initialize the system. diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index e98e58740ad..5c888e218d8 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -167,6 +167,12 @@ typedef enum { GHOST_kEventWindowUpdate, GHOST_kEventWindowSize, GHOST_kEventWindowMove, + + GHOST_kEventDraggingEntered, + GHOST_kEventDraggingUpdated, + GHOST_kEventDraggingExited, + GHOST_kEventDraggingDropDone, + GHOST_kEventDraggingDropOnIcon, GHOST_kEventTimer, @@ -368,6 +374,30 @@ typedef struct { } GHOST_TEventWheelData; +typedef enum { + GHOST_kDragnDropTypeUnknown =0, + GHOST_kDragnDropTypeFilenames, /*Array of strings representing file names (full path) */ + GHOST_kDragnDropTypeString, /* Unformatted text UTF-8 string */ + GHOST_kDragnDropTypeBitmap /*Bitmap image data */ +} GHOST_TDragnDropTypes; + +typedef struct { + /** The x-coordinate of the cursor position. */ + GHOST_TInt32 x; + /** The y-coordinate of the cursor position. */ + GHOST_TInt32 y; + /** The dropped item type */ + GHOST_TDragnDropTypes dataType; + /** The "dropped content" */ + GHOST_TEventDataPtr data; +} GHOST_TEventDragnDropData; + +typedef struct { + int count; + GHOST_TUns8 **strings; +} GHOST_TStringArray; + + /* original patch used floats, but the driver return ints and uns. We will calibrate in view, no sense on doing conversions twice */ /* as all USB device controls are likely to use ints, this is also more future proof */ //typedef struct { diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index 0160df552cc..76b3d7caf7e 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -404,6 +404,13 @@ GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle, } +void GHOST_setAcceptDragOperation(GHOST_SystemHandle systemhandle, GHOST_TInt8 canAccept) +{ + GHOST_ISystem* system = (GHOST_ISystem*) systemhandle; + + system->setAcceptDragOperation(canAccept); +} + GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle) { diff --git a/intern/ghost/intern/GHOST_EventDragnDrop.h b/intern/ghost/intern/GHOST_EventDragnDrop.h new file mode 100644 index 00000000000..f1810b0eb0a --- /dev/null +++ b/intern/ghost/intern/GHOST_EventDragnDrop.h @@ -0,0 +1,91 @@ +/** + * $Id$ + * ***** BEGIN GPL 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. + * + * 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): Damien Plisson 11/2009 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef _GHOST_EVENT_DRAGNDROP_H_ +#define _GHOST_EVENT_DRAGNDROP_H_ + +#include "GHOST_Event.h" + +/** + * Drag & drop event + * + * The dragging sequence is performed in four phases: + * + * <li> Start sequence (GHOST_kEventDraggingEntered) that tells a drag'n'drop operation has started. Already gives the object data type, + * and the entering mouse location + * + * <li> Update mouse position (GHOST_kEventDraggingUpdated) sent upon each mouse move until the drag'n'drop operation stops, to give the updated mouse position. + * Useful to highlight a potential destination, and update the status (through GHOST_setAcceptDragOperation) telling if the object can be dropped at + * the current cursor position. + * + * <li> Abort drag'n'drop sequence (GHOST_kEventDraggingExited) sent when the user moved the mouse outside the window. + * + * <li> Send the dropped data (GHOST_kEventDraggingDropDone) + * + * <li> Outside of the normal sequence, dropped data can be sent (GHOST_kEventDraggingDropOnIcon). This can happen when the user drops an object + * on the application icon. (Also used in OSX to pass the filename of the document the user doubled-clicked in the finder) + * + * <br><br>Note that the event handler is responsible for freeing the received data. + * <br>And the mouse positions are given in Blender coordinates (y=0 at bottom) + * + * <br>Currently supported object types : + * <li>UTF-8 string + * <li>array of strings representing filenames (GHOST_TStringArray) + * <li>bitmap image + */ +class GHOST_EventDragnDrop : public GHOST_Event +{ +public: + /** + * Constructor. + * @param time The time this event was generated. + * @param type The type of this event. + * @param dataType The type of the drop candidate object + * @param window The window where the event occured + * @param x The x-coordinate of the location the cursor was at at the time of the event. + * @param y The y-coordinate of the location the cursor was at at the time of the event. + * @param data The "content" dropped in the window + */ + GHOST_EventDragnDrop(GHOST_TUns64 time, GHOST_TEventType type, GHOST_TDragnDropTypes dataType, GHOST_IWindow* window, + int x, int y, GHOST_TEventDataPtr data) + : GHOST_Event(time, type, window) + { + m_dragnDropEventData.x = x; + m_dragnDropEventData.y = y; + m_dragnDropEventData.dataType = dataType; + m_dragnDropEventData.data = data; + m_data = &m_dragnDropEventData; + } + +protected: + /** The x,y-coordinates of the cursor position. */ + GHOST_TEventDragnDropData m_dragnDropEventData; +}; + +#endif // _GHOST_EVENT_DRAGNDROP_H_ + diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp index 84298d3e3ff..cccee12d696 100644 --- a/intern/ghost/intern/GHOST_System.cpp +++ b/intern/ghost/intern/GHOST_System.cpp @@ -54,6 +54,7 @@ GHOST_System::GHOST_System() : m_displayManager(0), m_timerManager(0), m_windowManager(0), m_eventManager(0), m_ndofManager(0) { + m_canAcceptDragOperation = false; } @@ -275,6 +276,15 @@ GHOST_TSuccess GHOST_System::getButtonState(GHOST_TButtonMask mask, bool& isDown return success; } +void GHOST_System::setAcceptDragOperation(bool canAccept) +{ + m_canAcceptDragOperation = canAccept; +} + +bool GHOST_System::canAcceptDragOperation() const +{ + return m_canAcceptDragOperation; +} GHOST_TSuccess GHOST_System::init() { diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index 066fe4b93d3..542553e830e 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -231,6 +231,21 @@ public: * @return Indication of success. */ virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const; + + /*************************************************************************************** + ** Drag'n'drop operations + ***************************************************************************************/ + + /** + * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop + */ + virtual void setAcceptDragOperation(bool canAccept); + + /** + * Returns acceptance of the dropped object + * Usually called by the "object dropped" event handling function + */ + virtual bool canAcceptDragOperation() const; /*************************************************************************************** ** Other (internal) functionality. @@ -332,6 +347,9 @@ protected: /** The N-degree of freedom device manager */ GHOST_NDOFManager* m_ndofManager; + + /** The acceptance of the "drop candidate" of the current drag'n'drop operation */ + bool m_canAcceptDragOperation; /** Prints all the events. */ #ifdef GHOST_DEBUG diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h index e880f851267..5ba3a2b373b 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -194,11 +194,25 @@ public: /** * Handles a window event. Called by GHOST_WindowCocoa window delegate - * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++) + * @param eventType The type of window event + * @param window The window on which the event occured * @return Indication whether the event was handled. */ GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window); + + /** + * Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass + * @param eventType The type of drag'n'drop event + * @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image) + * @param mouseX x mouse coordinate (in cocoa base window coordinates) + * @param mouseY y mouse coordinate + * @param window The window on which the event occured + * @return Indication whether the event was handled. + */ + GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, + GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data); + protected: /** * Initializes the system. diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 73be363dff1..c7127e26a4a 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -41,6 +41,7 @@ #include "GHOST_EventCursor.h" #include "GHOST_EventWheel.h" #include "GHOST_EventNDOF.h" +#include "GHOST_EventDragnDrop.h" #include "GHOST_TimerManager.h" #include "GHOST_TimerTask.h" @@ -413,6 +414,7 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { NSLog(@"\nGet open file event from cocoa : %@",filename); + systemCocoa->handleDraggingEvent(GHOST_kEventDraggingDropOnIcon, GHOST_kDragnDropTypeFilenames, nil, 0, 0, [NSArray arrayWithObject:filename]); return YES; } @@ -880,6 +882,102 @@ GHOST_TSuccess GHOST_SystemCocoa::handleWindowEvent(GHOST_TEventType eventType, return GHOST_kSuccess; } +//Note: called from NSWindow subclass +GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, + GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data) +{ + if (!validWindow(window)) { + return GHOST_kFailure; + } + switch(eventType) + { + case GHOST_kEventDraggingEntered: + setAcceptDragOperation(FALSE); //Drag operation needs to be accepted explicitely by the event manager + case GHOST_kEventDraggingUpdated: + case GHOST_kEventDraggingExited: + pushEvent(new GHOST_EventDragnDrop(getMilliSeconds(),GHOST_kEventDraggingEntered,draggedObjectType,window,mouseX,mouseY,NULL)); + break; + + case GHOST_kEventDraggingDropDone: + case GHOST_kEventDraggingDropOnIcon: + { + GHOST_TUns8 * temp_buff; + GHOST_TStringArray *strArray; + NSArray *droppedArray; + size_t pastedTextSize; + NSString *droppedStr; + GHOST_TEventDataPtr eventData; + int i; + + if (!data) return GHOST_kFailure; + + switch (draggedObjectType) { + case GHOST_kDragnDropTypeBitmap: + //TODO: implement bitmap conversion to a blender friendly format + break; + case GHOST_kDragnDropTypeFilenames: + droppedArray = (NSArray*)data; + + strArray = (GHOST_TStringArray*)malloc(sizeof(GHOST_TStringArray)); + if (!strArray) return GHOST_kFailure; + + strArray->count = [droppedArray count]; + if (strArray->count == 0) return GHOST_kFailure; + + strArray->strings = (GHOST_TUns8**) malloc(strArray->count*sizeof(GHOST_TUns8*)); + + for (i=0;i<strArray->count;i++) + { + droppedStr = [droppedArray objectAtIndex:i]; + + pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); + + if (!temp_buff) { + strArray->count = i; + break; + } + + strncpy((char*)temp_buff, [droppedStr UTF8String], pastedTextSize); + temp_buff[pastedTextSize] = '\0'; + + strArray->strings[i] = temp_buff; + } + + eventData = (GHOST_TEventDataPtr) strArray; + break; + + case GHOST_kDragnDropTypeString: + droppedStr = (NSString*)data; + pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + + temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); + + if (temp_buff == NULL) { + return GHOST_kFailure; + } + + strncpy((char*)temp_buff, [droppedStr UTF8String], pastedTextSize); + + temp_buff[pastedTextSize] = '\0'; + + eventData = (GHOST_TEventDataPtr) temp_buff; + break; + + default: + return GHOST_kFailure; + break; + } + pushEvent(new GHOST_EventDragnDrop(getMilliSeconds(),GHOST_kEventDraggingEntered,draggedObjectType,window,mouseX,mouseY,eventData)); + } + break; + default: + return GHOST_kFailure; + } + return GHOST_kSuccess; +} + + GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest() { GHOST_Window* window = (GHOST_Window*)m_windowManager->getActiveWindow(); diff --git a/intern/ghost/intern/GHOST_WindowCocoa.h b/intern/ghost/intern/GHOST_WindowCocoa.h index e3479ada5d6..e59d9c17333 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.h +++ b/intern/ghost/intern/GHOST_WindowCocoa.h @@ -40,6 +40,8 @@ #include "GHOST_Window.h" #include "STR_String.h" +@class CocoaWindow; + class GHOST_SystemCocoa; /** @@ -264,7 +266,7 @@ protected: virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY); /** The window containing the OpenGL view */ - NSWindow *m_window; + CocoaWindow *m_window; /** The openGL view */ NSOpenGLView *m_openGLView; diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index f0bc8dd4d0f..459a4a54ee3 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -124,16 +124,86 @@ extern "C" { //We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events) @interface CocoaWindow: NSWindow { - + GHOST_SystemCocoa *systemCocoa; + GHOST_WindowCocoa *associatedWindow; + GHOST_TDragnDropTypes m_draggedObjectType; } +- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa; @end @implementation CocoaWindow +- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa +{ + systemCocoa = sysCocoa; + associatedWindow = winCocoa; +} -(BOOL)canBecomeKeyWindow { return YES; } +//The drag'n'drop dragging destination methods +- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender +{ + NSPoint mouseLocation = [sender draggingLocation]; + NSPasteboard *draggingPBoard = [sender draggingPasteboard]; + + if ([[draggingPBoard types] containsObject:NSTIFFPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeBitmap; + else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeFilenames; + else if ([[draggingPBoard types] containsObject:NSStringPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeString; + else return NSDragOperationNone; + + systemCocoa->handleDraggingEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil); + return NSDragOperationCopy; +} + + +- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender +{ + NSPoint mouseLocation = [sender draggingLocation]; + + systemCocoa->handleDraggingEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil); + return NSDragOperationCopy; +} + +- (void)draggingExited:(id < NSDraggingInfo >)sender +{ + systemCocoa->handleDraggingEvent(GHOST_kEventDraggingExited, m_draggedObjectType, associatedWindow, 0, 0, nil); + m_draggedObjectType = GHOST_kDragnDropTypeUnknown; +} + +- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender +{ + if (systemCocoa->canAcceptDragOperation()) + return YES; + else + return NO; +} + +- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender +{ + NSPoint mouseLocation = [sender draggingLocation]; + NSPasteboard *draggingPBoard = [sender draggingPasteboard]; + id data; + + switch (m_draggedObjectType) { + case GHOST_kDragnDropTypeBitmap: + data = [draggingPBoard dataForType:NSTIFFPboardType]; + break; + case GHOST_kDragnDropTypeFilenames: + data = [draggingPBoard propertyListForType:NSFilenamesPboardType]; + break; + case GHOST_kDragnDropTypeString: + data = [draggingPBoard stringForType:@"public.utf8-plain-text"]; + break; + default: + return NO; + break; + } + systemCocoa->handleDraggingEvent(GHOST_kEventDraggingDropDone, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, (void*)data); + return YES; +} + @end @@ -207,6 +277,8 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( return; } + [m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this]; + //Forbid to resize the window below the blender defined minimum one minSize.width = 320; minSize.height = 240; @@ -259,6 +331,9 @@ GHOST_WindowCocoa::GHOST_WindowCocoa( [m_window setAcceptsMouseMovedEvents:YES]; + [m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, + NSStringPboardType, NSTIFFPboardType, nil]]; + if (state == GHOST_kWindowStateFullScreen) setState(GHOST_kWindowStateFullScreen); @@ -684,10 +759,18 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order) { GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid") if (order == GHOST_kWindowOrderTop) { - [m_window orderFront:nil]; + [m_window makeKeyAndOrderFront:nil]; } else { + NSArray *windowsList; + [m_window orderBack:nil]; + + //Check for other blender opened windows and make the frontmost key + windowsList = [NSApp orderedWindows]; + if ([windowsList count]) { + [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil]; + } } return GHOST_kSuccess; } diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 9e3927314d3..e404f174935 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -73,6 +73,12 @@ extern "C" { */ short MEM_freeN(void *vmemh); + + /** + * Return zero if memory is not in allocated list + */ + short MEM_testN(void *vmemh); + /** * Duplicates a block of memory, and returns a pointer to the * newly allocated block. */ @@ -102,6 +108,9 @@ extern "C" { * blocks. */ void MEM_printmemlist(void); + /** calls the function on all allocated memory blocks. */ + void MEM_callbackmemlist(void (*func)(void*)); + /** Print statistics about memory usage */ void MEM_printmemlist_stats(void); diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index ca7f2a4d506..d1114af2437 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -460,6 +460,47 @@ static void MEM_printmemlist_internal( int pydict ) mem_unlock_thread(); } +void MEM_callbackmemlist(void (*func)(void*)) { + MemHead *membl; + + mem_lock_thread(); + + membl = membase->first; + if (membl) membl = MEMNEXT(membl); + + while(membl) { + func(membl+1); + if(membl->next) + membl= MEMNEXT(membl->next); + else break; + } + + mem_unlock_thread(); +} + +short MEM_testN(void *vmemh) { + MemHead *membl; + + mem_lock_thread(); + + membl = membase->first; + if (membl) membl = MEMNEXT(membl); + + while(membl) { + if (vmemh == membl+1) + return 1; + + if(membl->next) + membl= MEMNEXT(membl->next); + else break; + } + + mem_unlock_thread(); + + print_error("Memoryblock %p: pointer not in memlist\n", vmemh); + return 0; +} + void MEM_printmemlist( void ) { MEM_printmemlist_internal(0); } @@ -500,7 +541,6 @@ short MEM_freeN(void *vmemh) /* anders compileertie niet meer */ } mem_lock_thread(); - if ((memh->tag1 == MEMTAG1) && (memh->tag2 == MEMTAG2) && ((memh->len & 0x3) == 0)) { memt = (MemTail *)(((char *) memh) + sizeof(MemHead) + memh->len); if (memt->tag3 == MEMTAG3){ diff --git a/intern/smoke/intern/Makefile b/intern/smoke/intern/Makefile index 2cdd7d3853e..760b1627a91 100644 --- a/intern/smoke/intern/Makefile +++ b/intern/smoke/intern/Makefile @@ -41,6 +41,11 @@ ifeq ($(WITH_BF_OPENMP),true) CPPFLAGS += -DPARALLEL endif +ifeq ($(WITH_FFTW3),true) + CPPFLAGS += -DFFTW3=1 + CPPFLAGS += $(BF_FFTW3_INC) +endif + CPPFLAGS += -I. CPPFLAGS += -I../extern CPPFLAGS += -I$(NAN_PNG)/include diff --git a/projectfiles_vc9/blender/makesrna/RNA_makesrna.vcproj b/projectfiles_vc9/blender/makesrna/RNA_makesrna.vcproj index f52dd193150..c0a13bbe26b 100644 --- a/projectfiles_vc9/blender/makesrna/RNA_makesrna.vcproj +++ b/projectfiles_vc9/blender/makesrna/RNA_makesrna.vcproj @@ -662,6 +662,10 @@ >
</File>
<File
+ RelativePath="..\..\..\source\blender\makesrna\intern\rna_fcurve_api.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\source\blender\makesrna\intern\rna_fluidsim.c"
>
</File>
diff --git a/release/datafiles/datatoc.py b/release/datafiles/datatoc.py index 70bb348ad02..a78b64c5095 100755 --- a/release/datafiles/datatoc.py +++ b/release/datafiles/datatoc.py @@ -48,6 +48,7 @@ if filename[0] == ".": cname = filename + ".c" sys.stdout.write("Making C file <%s>\n" % cname) +filename = filename.split("/")[-1].split("\\")[-1] filename = filename.replace(".", "_") sys.stdout.write(str(size)) sys.stdout.write("\n") diff --git a/release/scripts/io/netrender/client.py b/release/scripts/io/netrender/client.py index 52643af7d73..9cb176972e6 100644 --- a/release/scripts/io/netrender/client.py +++ b/release/scripts/io/netrender/client.py @@ -34,7 +34,9 @@ def addFluidFiles(job, path): match = pattern.match(fluid_file) if match: - current_frame = int(match.groups()[1]) + # fluid frames starts at 0, which explains the +1 + # This is stupid + current_frame = int(match.groups()[1]) + 1 job.addFile(path + fluid_file, current_frame, current_frame) def addPointCache(job, ob, point_cache, default_path): diff --git a/release/scripts/modules/bpy_ext/Mesh.py b/release/scripts/modules/bpy_ext/Mesh.py index 961ff83cc06..e69de29bb2d 100644 --- a/release/scripts/modules/bpy_ext/Mesh.py +++ b/release/scripts/modules/bpy_ext/Mesh.py @@ -1,72 +0,0 @@ -# ##### BEGIN GPL 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. -# -# 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. -# -# ##### END GPL LICENSE BLOCK ##### - -def ord_ind(i1,i2): - if i1<i2: return i1,i2 - return i2,i1 - -def edge_key(ed): - v1, v2 = tuple(ed.verts) - return ord_ind(v1, v2) - -def face_edge_keys(face): - verts = tuple(face.verts) - if len(verts)==3: - return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[0]) - - return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[3]), ord_ind(verts[3], verts[0]) - -def mesh_edge_keys(mesh): - return [edge_key for face in mesh.faces for edge_key in face.edge_keys()] - -def mesh_edge_face_count_dict(mesh, face_edge_keys=None): - - # Optional speedup - if face_edge_keys==None: - face_edge_keys = [face.edge_keys() for face in face_list] - - face_edge_count = {} - for face_keys in face_edge_keys: - for key in face_keys: - try: - face_edge_count[key] += 1 - except: - face_edge_count[key] = 1 - - - return face_edge_count - -def mesh_edge_face_count(mesh, face_edge_keys=None): - edge_face_count_dict = mesh.edge_face_count_dict(face_edge_keys) - return [edge_face_count_dict.get(ed.key(), 0) for ed in mesh.edges] - -import bpy - -# * Edge * -class_obj = bpy.types.MeshEdge -class_obj.key = edge_key - -# * Face * -class_obj = bpy.types.MeshFace -class_obj.edge_keys = face_edge_keys - -# * Mesh * -class_obj = bpy.types.Mesh -class_obj.edge_keys = mesh_edge_keys -class_obj.edge_face_count = mesh_edge_face_count -class_obj.edge_face_count_dict = mesh_edge_face_count_dict diff --git a/release/scripts/modules/bpy_ext/Object.py b/release/scripts/modules/bpy_ext/Object.py index 59c2ca3ebda..e69de29bb2d 100644 --- a/release/scripts/modules/bpy_ext/Object.py +++ b/release/scripts/modules/bpy_ext/Object.py @@ -1,22 +0,0 @@ -# ##### BEGIN GPL 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. -# -# 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. -# -# ##### END GPL LICENSE BLOCK ##### - -import bpy -class_obj = bpy.types.Object - -class_obj.getChildren = lambda self: [child for child in bpy.data.objects if child.parent == self] diff --git a/release/scripts/modules/bpy_ext/__init__.py b/release/scripts/modules/bpy_ext/__init__.py index 435c545dc75..e69de29bb2d 100644 --- a/release/scripts/modules/bpy_ext/__init__.py +++ b/release/scripts/modules/bpy_ext/__init__.py @@ -1,20 +0,0 @@ -# ##### BEGIN GPL 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. -# -# 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. -# -# ##### END GPL LICENSE BLOCK ##### - -import bpy_ext.Object -import bpy_ext.Mesh diff --git a/release/scripts/modules/bpy_ops.py b/release/scripts/modules/bpy_ops.py index 8078816f982..35d986fe09d 100644 --- a/release/scripts/modules/bpy_ops.py +++ b/release/scripts/modules/bpy_ops.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. @@ -127,11 +127,11 @@ class bpy_ops_submodule_op(object): ''' __keys__ = ('module', 'func') - - + + def _get_doc(self): return op_as_string(self.idname()) - + __doc__ = property(_get_doc) def __init__(self, module, func): diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py new file mode 100644 index 00000000000..5a8b46c92d6 --- /dev/null +++ b/release/scripts/modules/bpy_types.py @@ -0,0 +1,94 @@ +# ##### BEGIN GPL 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. +# +# 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. +# +# ##### END GPL LICENSE BLOCK ##### + +import bpy + +StructRNA = bpy.types.Struct.__bases__[0] +# StructRNA = bpy.types.Struct + + +class Context(StructRNA): + + def copy(self): + new_context = {} + generic_keys = StructRNA.__dict__.keys() + for item in dir(self): + if item not in generic_keys: + new_context[item] = getattr(self, item) + + return new_context + + +class Object(bpy.types.ID): + + def _get_children(self): + return [child for child in bpy.data.objects if child.parent == self] + + children = property(_get_children) + + +def ord_ind(i1,i2): + if i1<i2: return i1,i2 + return i2,i1 + +class Mesh(bpy.types.ID): + + def _get_edge_keys(self): + return [edge_key for face in self.faces for edge_key in face.edge_keys] + + edge_keys = property(_get_edge_keys) + + def _get_edge_face_count_dict(self): + face_edge_keys = [face.edge_keys for face in self.faces] + face_edge_count = {} + for face_keys in face_edge_keys: + for key in face_keys: + try: + face_edge_count[key] += 1 + except: + face_edge_count[key] = 1 + + return face_edge_count + + edge_face_count_dict = property(_get_edge_face_count_dict) + + def _get_edge_face_count(self): + edge_face_count_dict = self.edge_face_count_dict + return [edge_face_count_dict.get(ed.key, 0) for ed in mesh.edges] + + edge_face_count = property(_get_edge_face_count) + + +class MeshEdge(StructRNA): + + def _get_key(self): + return ord_ind(*tuple(self.verts)) + + key = property(_get_key) + + +class MeshFace(StructRNA): + + def _get_edge_keys(self): + verts = tuple(self.verts) + if len(verts)==3: + return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[0]) + + return ord_ind(verts[0], verts[1]), ord_ind(verts[1], verts[2]), ord_ind(verts[2], verts[3]), ord_ind(verts[3], verts[0]) + + edge_keys = property(_get_edge_keys) diff --git a/release/scripts/modules/bpy_utils.py b/release/scripts/modules/bpy_utils.py index dde01152dae..5a73364c1b1 100644 --- a/release/scripts/modules/bpy_utils.py +++ b/release/scripts/modules/bpy_utils.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/modules/console/complete_calltip.py b/release/scripts/modules/console/complete_calltip.py new file mode 100644 index 00000000000..486f9469d60 --- /dev/null +++ b/release/scripts/modules/console/complete_calltip.py @@ -0,0 +1,190 @@ +# Copyright (c) 2009 www.stani.be (GPL license) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import inspect +import re + + +# regular expression constants +DEF_DOC = '%s\s*(\(.*?\))' +DEF_SOURCE = 'def\s+%s\s*(\(.*?\)):' +RE_EMPTY_LINE = re.compile('^\s*\n') +RE_FLAG = re.MULTILINE | re.DOTALL +RE_NEWLINE = re.compile('\n+') +RE_SPACE = re.compile('\s+') +RE_DEF_COMPLETE = re.compile( + # don't start with a quote + '''(?:^|[^"'a-zA-Z0-9_])''' + # start with a \w = [a-zA-Z0-9_] + '''((\w+''' + # allow also dots and closed bracket pairs [] + '''(?:\w|[.]|\[.+?\])*''' + # allow empty string + '''|)''' + # allow opening bracket(s) + '''(?:\(|\s)*)$''') + + +def reduce_newlines(text): + """Reduces multiple newlines to a single newline. + + :param text: text with multiple newlines + :type text: str + :returns: text with single newlines + :rtype: str + + >>> reduce_newlines('hello\\n\\nworld') + 'hello\\nworld' + """ + return RE_NEWLINE.sub('\n', text) + + +def reduce_spaces(text): + """Reduces multiple whitespaces to a single space. + + :param text: text with multiple spaces + :type text: str + :returns: text with single spaces + :rtype: str + + >>> reduce_spaces('hello \\nworld') + 'hello world' + """ + return RE_SPACE.sub(' ', text) + + +def get_doc(object): + """Get the doc string or comments for an object. + + :param object: object + :returns: doc string + :rtype: str + + >>> get_doc(abs) + 'abs(number) -> number\\n\\nReturn the absolute value of the argument.' + """ + result = inspect.getdoc(object) or inspect.getcomments(object) + return result and RE_EMPTY_LINE.sub('', result.rstrip()) or '' + + +def get_argspec(func, strip_self=True, doc=None, source=None): + """Get argument specifications. + + :param strip_self: strip `self` from argspec + :type strip_self: bool + :param doc: doc string of func (optional) + :type doc: str + :param source: source code of func (optional) + :type source: str + :returns: argument specification + :rtype: str + + >>> get_argspec(inspect.getclasstree) + '(classes, unique=0)' + >>> get_argspec(abs) + '(number)' + """ + # get the function object of the class + try: + func = func.__func__ + except AttributeError: + try: + # py 2.X + func = func.im_func + except AttributeError: + pass + # is callable? + if not hasattr(func, '__call__'): + return '' + # func should have a name + try: + func_name = func.__name__ + except AttributeError: + return '' + # from docstring + if doc is None: + doc = get_doc(func) + match = re.search(DEF_DOC % func_name, doc, RE_FLAG) + # from source code + if not match: + if source is None: + try: + source = inspect.getsource(func) + except TypeError: + source = '' + if source: + match = re.search(DEF_SOURCE % func_name, source, RE_FLAG) + if match: + argspec = reduce_spaces(match.group(1)) + else: + # try with the inspect.getarg* functions + try: + argspec = inspect.formatargspec(*inspect.getfullargspec(func)) + except: + try: + # py 2.X + argspec = inspect.formatargspec(*inspect.getargspec(func)) + except: + try: + argspec = inspect.formatargvalues( + *inspect.getargvalues(func)) + except: + argspec = '' + if strip_self: + argspec = argspec.replace('self, ', '') + return argspec + + +def complete(line, cursor, namespace): + """Complete callable with calltip. + + :param line: incomplete text line + :type line: str + :param cursor: current character position + :type cursor: int + :param namespace: namespace + :type namespace: dict + :returns: (matches, world, scrollback) + :rtype: (list of str, str, str) + + >>> import os + >>> complete('os.path.isdir(', 14, {'os': os})[-1] + 'isdir(s)\\nReturn true if the pathname refers to an existing directory.' + >>> complete('abs(', 4, {})[-1] + 'abs(number) -> number\\nReturn the absolute value of the argument.' + """ + matches = [] + match = RE_DEF_COMPLETE.search(line[:cursor]) + if match: + word = match.group(1) + func_word = match.group(2) + try: + func = eval(func_word, namespace) + except Exception: + func = None + scrollback = '' + if func: + doc = get_doc(func) + argspec = get_argspec(func, doc=doc) + scrollback = func_word.split('.')[-1] + (argspec or '()') + if doc.startswith(scrollback): + scrollback = doc + elif doc: + scrollback += '\n' + doc + scrollback = reduce_newlines(scrollback) + else: + word = '' + scrollback = '' + return matches, word, scrollback diff --git a/release/scripts/modules/dynamic_menu.py b/release/scripts/modules/dynamic_menu.py index 8d124f222a1..e176626aac3 100644 --- a/release/scripts/modules/dynamic_menu.py +++ b/release/scripts/modules/dynamic_menu.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/op/console_shell.py b/release/scripts/op/console_shell.py index 4bf20e470e8..874101d1c79 100644 --- a/release/scripts/op/console_shell.py +++ b/release/scripts/op/console_shell.py @@ -18,8 +18,11 @@ # <pep8 compliant> import sys +import os + import bpy + language_id = 'shell' def add_scrollback(text, text_type): @@ -27,10 +30,17 @@ def add_scrollback(text, text_type): bpy.ops.console.scrollback_append(text=l.replace('\t', ' '), type=text_type) - def shell_run(text): - import os - add_scrollback(os.popen(text).read(), 'OUTPUT') + import subprocess + val, output= subprocess.getstatusoutput(text) + + if not val: + style= 'OUTPUT' + else: + style= 'ERROR' + + add_scrollback(output, style) + class ShellConsoleExec(bpy.types.Operator): '''Execute the current console line as a python expression.''' @@ -64,6 +74,7 @@ class ShellConsoleExec(bpy.types.Operator): bpy.ops.console.history_append(text="", current_character=0, remove_duplicates=True) + sc.prompt = os.getcwd()+ShellConsoleExec.PROMPT return ('FINISHED',) @@ -93,7 +104,7 @@ class ShellConsoleBanner(bpy.types.Operator): sc = context.space_data shell_run("bash --version") - sc.prompt = ShellConsoleExec.PROMPT + sc.prompt = os.getcwd()+ShellConsoleExec.PROMPT return ('FINISHED',) diff --git a/release/scripts/op/mesh.py b/release/scripts/op/mesh.py index 8ea9ea03062..f78e33730f0 100644 --- a/release/scripts/op/mesh.py +++ b/release/scripts/op/mesh.py @@ -28,9 +28,9 @@ def main(context): mesh = ob.data face_list = [face for face in mesh.faces] - face_edge_keys = [face.edge_keys() for face in face_list] + face_edge_keys = [face.edge_keys for face in face_list] - edge_face_count = mesh.edge_face_count_dict(face_edge_keys) + edge_face_count = mesh.edge_face_count_dict def test_interior(index): for key in face_edge_keys[index]: diff --git a/release/scripts/op/mesh_skin.py b/release/scripts/op/mesh_skin.py index 85df6463eb0..f9a92c8cd82 100644 --- a/release/scripts/op/mesh_skin.py +++ b/release/scripts/op/mesh_skin.py @@ -256,11 +256,11 @@ def getSelectedEdges(context, me, ob): if MESH_MODE == 'FACE': context.scene.tool_settings.mesh_selection_mode = 'EDGE' # value is [edge, face_sel_user_in] - edge_dict= dict((ed.key(), [ed, 0]) for ed in me.edges) + edge_dict= dict((ed.key, [ed, 0]) for ed in me.edges) for f in me.faces: if f.selected: - for edkey in f.edge_keys(): + for edkey in f.edge_keys: edge_dict[edkey][1] += 1 context.scene.tool_settings.mesh_selection_mode = MESH_MODE @@ -280,7 +280,7 @@ def getVertLoops(selEdges, me): vert_used = [False] * tot for ed in selEdges: - i1, i2 = ed.key() + i1, i2 = ed.key vert_siblings[i1].append(i2) vert_siblings[i2].append(i1) diff --git a/release/scripts/op/uvcalc_smart_project.py b/release/scripts/op/uvcalc_smart_project.py index 454cb2f23ec..11202329a3d 100644 --- a/release/scripts/op/uvcalc_smart_project.py +++ b/release/scripts/op/uvcalc_smart_project.py @@ -800,7 +800,7 @@ class thickface(object): self.no = face.normal self.area = face.area - self.edge_keys = face.edge_keys() + self.edge_keys = face.edge_keys global ob ob = None diff --git a/release/scripts/op/vertexpaint_dirt.py b/release/scripts/op/vertexpaint_dirt.py index 7d32c153d04..04398dfa8ce 100644 --- a/release/scripts/op/vertexpaint_dirt.py +++ b/release/scripts/op/vertexpaint_dirt.py @@ -117,7 +117,7 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, active_col_layer = me.vertex_colors[0].data if not active_col_layer: - return("CANCELLED", ) + return('CANCELLED', ) for i, f in enumerate(me.faces): if not me.use_paint_mask or f.selected: diff --git a/release/scripts/templates/gamelogic.py b/release/scripts/templates/gamelogic.py index 203a693de5a..37d354d0e6b 100644 --- a/release/scripts/templates/gamelogic.py +++ b/release/scripts/templates/gamelogic.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/templates/gamelogic_basic.py b/release/scripts/templates/gamelogic_basic.py index b3fe0a4a6ca..0accb57ccc2 100644 --- a/release/scripts/templates/gamelogic_basic.py +++ b/release/scripts/templates/gamelogic_basic.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/templates/gamelogic_module.py b/release/scripts/templates/gamelogic_module.py index c19ec7d9116..8cb4fd7ca8d 100644 --- a/release/scripts/templates/gamelogic_module.py +++ b/release/scripts/templates/gamelogic_module.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/templates/operator.py b/release/scripts/templates/operator.py index 7eb21ad4f8b..1ed45f3e211 100644 --- a/release/scripts/templates/operator.py +++ b/release/scripts/templates/operator.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/templates/operator_simple.py b/release/scripts/templates/operator_simple.py index 6e166a3e970..438df083d4d 100644 --- a/release/scripts/templates/operator_simple.py +++ b/release/scripts/templates/operator_simple.py @@ -4,12 +4,12 @@ # 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. -# +# # 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. diff --git a/release/scripts/ui/properties_data_mesh.py b/release/scripts/ui/properties_data_mesh.py index 76d37a5931f..49e26a2e8c2 100644 --- a/release/scripts/ui/properties_data_mesh.py +++ b/release/scripts/ui/properties_data_mesh.py @@ -159,42 +159,42 @@ class DATA_PT_shape_keys(DataButtonsPanel): col = row.column() - subcol = col.column(align=True) - subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="") - subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="") + sub = col.column(align=True) + sub.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="") + sub.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="") if kb: col.itemS() - subcol = col.column(align=True) - subcol.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="") - subcol.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="") + sub = col.column(align=True) + sub.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="") + sub.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="") split = layout.split(percentage=0.4) - sub = split.row() - sub.enabled = enable_edit - sub.itemR(key, "relative") + row = split.row() + row.enabled = enable_edit + row.itemR(key, "relative") - sub = split.row() - sub.alignment = 'RIGHT' + row = split.row() + row.alignment = 'RIGHT' - subrow = sub.row(align=True) - subrow1 = subrow.row(align=True) - subrow1.active = enable_edit_value + sub = row.row(align=True) + subsub = sub.row(align=True) + subsub.active = enable_edit_value if ob.shape_key_lock: - subrow1.itemR(ob, "shape_key_lock", icon='ICON_PINNED', text="") + subsub.itemR(ob, "shape_key_lock", icon='ICON_PINNED', text="") else: - subrow1.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="") + subsub.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="") if kb.mute: - subrow1.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="") + subsub.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="") else: - subrow1.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="") - subrow.itemR(ob, "shape_key_edit_mode", text="") - - subrow = sub.row(align=True) - subrow.itemO("object.shape_key_mirror", icon='ICON_ARROW_LEFTRIGHT', text="") - subrow.itemO("object.shape_key_clear", icon='ICON_X', text="") - + subsub.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="") + sub.itemR(ob, "shape_key_edit_mode", text="") + + sub = row.row(align=True) + sub.itemO("object.shape_key_mirror", icon='ICON_ARROW_LEFTRIGHT', text="") + sub.itemO("object.shape_key_clear", icon='ICON_X', text="") + row = layout.row() row.itemR(kb, "name") @@ -206,17 +206,18 @@ class DATA_PT_shape_keys(DataButtonsPanel): row.itemR(kb, "value") split = layout.split() - sub = split.column(align=True) - sub.active = enable_edit_value - sub.itemL(text="Range:") - sub.itemR(kb, "slider_min", text="Min") - sub.itemR(kb, "slider_max", text="Max") - - sub = split.column(align=True) - sub.active = enable_edit_value - sub.itemL(text="Blend:") - sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="") - sub.item_pointerR(kb, "relative_key", key, "keys", text="") + + col = split.column(align=True) + col.active = enable_edit_value + col.itemL(text="Range:") + col.itemR(kb, "slider_min", text="Min") + col.itemR(kb, "slider_max", text="Max") + + col = split.column(align=True) + col.active = enable_edit_value + col.itemL(text="Blend:") + col.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="") + col.item_pointerR(kb, "relative_key", key, "keys", text="") else: row = layout.row() diff --git a/release/scripts/ui/properties_material.py b/release/scripts/ui/properties_material.py index 67d9cea0934..8cdc53a5094 100644 --- a/release/scripts/ui/properties_material.py +++ b/release/scripts/ui/properties_material.py @@ -19,6 +19,7 @@ # <pep8 compliant> import bpy +narrowui = 180 def active_node_mat(mat): # TODO, 2.4x has a pipeline section, for 2.5 we need to communicate @@ -72,6 +73,7 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel): ob = context.object slot = context.material_slot space = context.space_data + col2 = context.region.width > narrowui if ob: row = layout.row() @@ -89,22 +91,28 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel): row.itemO("object.material_slot_select", text="Select") row.itemO("object.material_slot_deselect", text="Deselect") - split = layout.split(percentage=0.65) - - if ob: - split.template_ID(ob, "active_material", new="material.new") - row = split.row() - if slot: - row.itemR(slot, "link", text="") - else: - row.itemL() - elif mat: - split.template_ID(space, "pin_id") - split.itemS() + if col2: + split = layout.split(percentage=0.65) + + if ob: + split.template_ID(ob, "active_material", new="material.new") + row = split.row() + if slot: + row.itemR(slot, "link", text="") + else: + row.itemL() + elif mat: + split.template_ID(space, "pin_id") + split.itemS() + else: + layout.template_ID(ob, "active_material", new="material.new") if mat: - layout.itemR(mat, "type", expand=True) - + if col2: + layout.itemR(mat, "type", expand=True) + else: + layout.itemR(mat, "type", text="") + class MATERIAL_PT_shading(MaterialButtonsPanel): bl_label = "Shading" @@ -119,6 +127,7 @@ class MATERIAL_PT_shading(MaterialButtonsPanel): layout = self.layout mat = active_node_mat(context.material) + col2 = context.region.width > narrowui if mat.type in ('SURFACE', 'WIRE'): split = layout.split() @@ -131,7 +140,8 @@ class MATERIAL_PT_shading(MaterialButtonsPanel): sub = col.column() sub.itemR(mat, "translucency") - col = split.column() + if col2: + col = split.column() col.itemR(mat, "shadeless") sub = col.column() sub.active = not mat.shadeless @@ -157,21 +167,24 @@ class MATERIAL_PT_strand(MaterialButtonsPanel): mat = context.material # dont use node material tan = mat.strand + col2 = context.region.width > narrowui split = layout.split() - col = split.column(align=True) - col.itemL(text="Size:") - col.itemR(tan, "root_size", text="Root") - col.itemR(tan, "tip_size", text="Tip") - col.itemR(tan, "min_size", text="Minimum") - col.itemR(tan, "blender_units") + col = split.column() + sub = col.column(align=True) + sub.itemL(text="Size:") + sub.itemR(tan, "root_size", text="Root") + sub.itemR(tan, "tip_size", text="Tip") + sub.itemR(tan, "min_size", text="Minimum") + sub.itemR(tan, "blender_units") sub = col.column() sub.active = (not mat.shadeless) sub.itemR(tan, "tangent_shading") col.itemR(tan, "shape") - col = split.column() + if col2: + col = split.column() col.itemL(text="Shading:") col.itemR(tan, "width_fade") ob = context.object @@ -196,7 +209,8 @@ class MATERIAL_PT_physics(MaterialButtonsPanel): layout = self.layout phys = context.material.physics # dont use node material - + col2 = context.region.width > narrowui + split = layout.split() col = split.column() @@ -204,7 +218,8 @@ class MATERIAL_PT_physics(MaterialButtonsPanel): col.itemR(phys, "friction") col.itemR(phys, "align_to_normal") - col = split.column() + if col2: + col = split.column() col.itemR(phys, "force", slider=True) col.itemR(phys, "elasticity", slider=True) col.itemR(phys, "damp", slider=True) @@ -223,6 +238,7 @@ class MATERIAL_PT_options(MaterialButtonsPanel): layout = self.layout mat = active_node_mat(context.material) + col2 = context.region.width > narrowui split = layout.split() @@ -242,7 +258,8 @@ class MATERIAL_PT_options(MaterialButtonsPanel): row.active = mat.light_group row.itemR(mat, "light_group_exclusive", text="Exclusive") - col = split.column() + if col2: + col = split.column() col.itemR(mat, "face_texture") sub = col.column() sub.active = mat.face_texture @@ -267,6 +284,7 @@ class MATERIAL_PT_shadow(MaterialButtonsPanel): layout = self.layout mat = active_node_mat(context.material) + col2 = context.region.width > narrowui split = layout.split() @@ -277,7 +295,8 @@ class MATERIAL_PT_shadow(MaterialButtonsPanel): col.itemR(mat, "cast_shadows_only", text="Cast Only") col.itemR(mat, "shadow_casting_alpha", text="Casting Alpha") - col = split.column() + if col2: + col = split.column() col.itemR(mat, "cast_buffer_shadows") sub = col.column() sub.active = mat.cast_buffer_shadows @@ -301,6 +320,7 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel): layout = self.layout mat = active_node_mat(context.material) + col2 = context.region.width > narrowui split = layout.split() @@ -310,7 +330,8 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel): sub.active = (not mat.shadeless) sub.itemR(mat, "diffuse_intensity", text="Intensity") - col = split.column() + if col2: + col = split.column() col.active = (not mat.shadeless) col.itemR(mat, "diffuse_shader", text="") col.itemR(mat, "use_diffuse_ramp", text="Ramp") @@ -322,25 +343,37 @@ class MATERIAL_PT_diffuse(MaterialButtonsPanel): elif mat.diffuse_shader == 'MINNAERT': col.itemR(mat, "darkness") elif mat.diffuse_shader == 'TOON': - row = col.row() - row.itemR(mat, "diffuse_toon_size", text="Size") - row.itemR(mat, "diffuse_toon_smooth", text="Smooth") + split = col.split() + + col = split.column() + col.itemR(mat, "diffuse_toon_size", text="Size") + + if col2: + col = split.column() + col.itemR(mat, "diffuse_toon_smooth", text="Smooth") elif mat.diffuse_shader == 'FRESNEL': - row = col.row() - row.itemR(mat, "diffuse_fresnel", text="Fresnel") - row.itemR(mat, "diffuse_fresnel_factor", text="Factor") + split = col.split() + + col = split.column() + col.itemR(mat, "diffuse_fresnel", text="Fresnel") + + if col2: + col = split.column() + col.itemR(mat, "diffuse_fresnel_factor", text="Factor") if mat.use_diffuse_ramp: layout.itemS() layout.template_color_ramp(mat, "diffuse_ramp", expand=True) layout.itemS() - row = layout.row() - split = row.split(percentage=0.3) - split.itemL(text="Input:") - split.itemR(mat, "diffuse_ramp_input", text="") - split = row.split(percentage=0.3) - split.itemL(text="Blend:") - split.itemR(mat, "diffuse_ramp_blend", text="") + + split = layout.split() + + col = split.column() + col.itemR(mat, "diffuse_ramp_input", text="Input") + + if col2: + col = split.column() + col.itemR(mat, "diffuse_ramp_blend", text="Blend") row = layout.row() row.itemR(mat, "diffuse_ramp_factor", text="Factor") @@ -358,6 +391,7 @@ class MATERIAL_PT_specular(MaterialButtonsPanel): layout = self.layout mat = active_node_mat(context.material) + col2 = context.region.width > narrowui layout.active = (not mat.shadeless) @@ -367,7 +401,8 @@ class MATERIAL_PT_specular(MaterialButtonsPanel): col.itemR(mat, "specular_color", text="") col.itemR(mat, "specular_intensity", text="Intensity") - col = split.column() + if col2: + col = split.column() col.itemR(mat, "specular_shader", text="") col.itemR(mat, "use_specular_ramp", text="Ramp") @@ -375,27 +410,39 @@ class MATERIAL_PT_specular(MaterialButtonsPanel): if mat.specular_shader in ('COOKTORR', 'PHONG'): col.itemR(mat, "specular_hardness", text="Hardness") elif mat.specular_shader == 'BLINN': - row = col.row() - row.itemR(mat, "specular_hardness", text="Hardness") - row.itemR(mat, "specular_ior", text="IOR") + split = layout.split() + + col = split.column() + col.itemR(mat, "specular_hardness", text="Hardness") + + if col2: + col = split.column() + col.itemR(mat, "specular_ior", text="IOR") elif mat.specular_shader == 'WARDISO': col.itemR(mat, "specular_slope", text="Slope") elif mat.specular_shader == 'TOON': - row = col.row() - row.itemR(mat, "specular_toon_size", text="Size") - row.itemR(mat, "specular_toon_smooth", text="Smooth") + split = layout.split() + + col = split.column() + col.itemR(mat, "specular_toon_size", text="Size") + + if col2: + col = split.column() + col.itemR(mat, "specular_toon_smooth", text="Smooth") if mat.use_specular_ramp: layout.itemS() layout.template_color_ramp(mat, "specular_ramp", expand=True) layout.itemS() - row = layout.row() - split = row.split(percentage=0.3) - split.itemL(text="Input:") - split.itemR(mat, "specular_ramp_input", text="") - split = row.split(percentage=0.3) - split.itemL(text="Blend:") - split.itemR(mat, "specular_ramp_blend", text="") + split = layout.split() + + col = split.column() + col.itemR(mat, "specular_ramp_input", text="Input") + + if col2: + col = split.column() + col.itemR(mat, "specular_ramp_blend", text="Blend") + row = layout.row() row.itemR(mat, "specular_ramp_factor", text="Factor") @@ -422,6 +469,7 @@ class MATERIAL_PT_sss(MaterialButtonsPanel): mat = active_node_mat(context.material) sss = mat.subsurface_scattering + col2 = context.region.width > narrowui layout.active = sss.enabled @@ -434,7 +482,8 @@ class MATERIAL_PT_sss(MaterialButtonsPanel): col.itemR(sss, "color", text="") col.itemR(sss, "radius", text="RGB Radius") - col = split.column() + if col2: + col = split.column() sub = col.column(align=True) sub.itemL(text="Blend:") sub.itemR(sss, "color_factor", text="Color") @@ -466,6 +515,7 @@ class MATERIAL_PT_mirror(MaterialButtonsPanel): mat = active_node_mat(context.material) raym = mat.raytrace_mirror + col2 = context.region.width > narrowui layout.active = raym.enabled @@ -475,7 +525,8 @@ class MATERIAL_PT_mirror(MaterialButtonsPanel): col.itemR(raym, "reflect_factor") col.itemR(mat, "mirror_color", text="") - col = split.column() + if col2: + col = split.column() col.itemR(raym, "fresnel") sub = col.column() sub.active = raym.fresnel > 0 @@ -492,7 +543,8 @@ class MATERIAL_PT_mirror(MaterialButtonsPanel): sub.itemL(text="Fade To:") sub.itemR(raym, "fade_to", text="") - col = split.column() + if col2: + col = split.column() col.itemL(text="Gloss:") col.itemR(raym, "gloss_factor", text="Amount") sub = col.column() @@ -522,10 +574,14 @@ class MATERIAL_PT_transp(MaterialButtonsPanel): mat = active_node_mat(context.material) rayt = mat.raytrace_transparency + col2 = context.region.width > narrowui row = layout.row() row.active = mat.transparency and (not mat.shadeless) - row.itemR(mat, "transparency_method", expand=True) + if col2: + row.itemR(mat, "transparency_method", expand=True) + else: + row.itemR(mat, "transparency_method", text="") split = layout.split() @@ -535,7 +591,8 @@ class MATERIAL_PT_transp(MaterialButtonsPanel): row.active = mat.transparency and (not mat.shadeless) row.itemR(mat, "specular_alpha", text="Specular") - col = split.column() + if col2: + col = split.column() col.active = (not mat.shadeless) col.itemR(rayt, "fresnel") sub = col.column() @@ -554,7 +611,8 @@ class MATERIAL_PT_transp(MaterialButtonsPanel): col.itemR(rayt, "limit") col.itemR(rayt, "depth") - col = split.column() + if col2: + col = split.column() col.itemL(text="Gloss:") col.itemR(rayt, "gloss_factor", text="Amount") sub = col.column() @@ -577,6 +635,7 @@ class MATERIAL_PT_halo(MaterialButtonsPanel): mat = context.material # dont use node material halo = mat.halo + col2 = context.region.width > narrowui split = layout.split() @@ -592,7 +651,8 @@ class MATERIAL_PT_halo(MaterialButtonsPanel): col.itemR(halo, "shaded") col.itemR(halo, "soft") - col = split.column() + if col2: + col = split.column() col.itemR(halo, "ring") sub = col.column() sub.active = halo.ring @@ -630,6 +690,7 @@ class MATERIAL_PT_flare(MaterialButtonsPanel): mat = context.material # dont use node material halo = mat.halo + col2 = context.region.width > narrowui layout.active = halo.flare_mode @@ -639,7 +700,8 @@ class MATERIAL_PT_flare(MaterialButtonsPanel): col.itemR(halo, "flare_size", text="Size") col.itemR(halo, "flare_boost", text="Boost") col.itemR(halo, "flare_seed", text="Seed") - col = split.column() + if col2: + col = split.column() col.itemR(halo, "flares_sub", text="Subflares") col.itemR(halo, "flare_subsize", text="Subsize") @@ -679,11 +741,15 @@ class MATERIAL_PT_volume_density(VolumeButtonsPanel): layout = self.layout vol = context.material.volume # dont use node material + col2 = context.region.width > narrowui split = layout.split() - row = split.row() - row.itemR(vol, "density") - row.itemR(vol, "density_scale") + col = split.column() + col.itemR(vol, "density") + + if col2: + col = split.column() + col.itemR(vol, "density_scale") class MATERIAL_PT_volume_shading(VolumeButtonsPanel): @@ -695,6 +761,7 @@ class MATERIAL_PT_volume_shading(VolumeButtonsPanel): layout = self.layout vol = context.material.volume # dont use node material + col2 = context.region.width > narrowui split = layout.split() @@ -703,7 +770,8 @@ class MATERIAL_PT_volume_shading(VolumeButtonsPanel): col.itemR(vol, "asymmetry") col.itemR(vol, "transmission_color") - col = split.column() + if col2: + col = split.column() sub = col.column(align=True) sub.itemR(vol, "emission") sub.itemR(vol, "emission_color", text="") @@ -721,13 +789,15 @@ class MATERIAL_PT_volume_lighting(VolumeButtonsPanel): layout = self.layout vol = context.material.volume # dont use node material + col2 = context.region.width > narrowui split = layout.split() col = split.column() col.itemR(vol, "lighting_mode", text="") - col = split.column() + if col2: + col = split.column() if vol.lighting_mode == 'SHADED': col.itemR(vol, "external_shadows") @@ -756,8 +826,12 @@ class MATERIAL_PT_volume_transp(VolumeButtonsPanel): layout = self.layout mat = context.material # dont use node material + col2 = context.region.width > narrowui - layout.itemR(mat, "transparency_method", expand=True) + if col2: + layout.itemR(mat, "transparency_method", expand=True) + else: + layout.itemR(mat, "transparency_method", text="") class MATERIAL_PT_volume_integration(VolumeButtonsPanel): @@ -769,6 +843,7 @@ class MATERIAL_PT_volume_integration(VolumeButtonsPanel): layout = self.layout vol = context.material.volume # dont use node material + col2 = context.region.width > narrowui split = layout.split() @@ -778,7 +853,8 @@ class MATERIAL_PT_volume_integration(VolumeButtonsPanel): col = col.column(align=True) col.itemR(vol, "step_size") - col = split.column() + if col2: + col = split.column() col.itemL() col.itemR(vol, "depth_cutoff") diff --git a/release/scripts/ui/properties_object.py b/release/scripts/ui/properties_object.py index fe1458a080a..68bf57e9238 100644 --- a/release/scripts/ui/properties_object.py +++ b/release/scripts/ui/properties_object.py @@ -19,6 +19,7 @@ # <pep8 compliant> import bpy +narrowui = 180 class ObjectButtonsPanel(bpy.types.Panel): bl_space_type = 'PROPERTIES' @@ -47,23 +48,36 @@ class OBJECT_PT_transform(ObjectButtonsPanel): layout = self.layout ob = context.object + col2 = context.region.width > narrowui - row = layout.row() - - row.column().itemR(ob, "location") - if ob.rotation_mode == 'QUATERNION': - row.column().itemR(ob, "rotation_quaternion", text="Rotation") - elif ob.rotation_mode == 'AXIS_ANGLE': - #row.column().itemL(text="Rotation") - #row.column().itemR(pchan, "rotation_angle", text="Angle") - #row.column().itemR(pchan, "rotation_axis", text="Axis") - row.column().itemR(ob, "rotation_axis_angle", text="Rotation") + if col2: + row = layout.row() + + row.column().itemR(ob, "location") + if ob.rotation_mode == 'QUATERNION': + row.column().itemR(ob, "rotation_quaternion", text="Rotation") + elif ob.rotation_mode == 'AXIS_ANGLE': + #row.column().itemL(text="Rotation") + #row.column().itemR(pchan, "rotation_angle", text="Angle") + #row.column().itemR(pchan, "rotation_axis", text="Axis") + row.column().itemR(ob, "rotation_axis_angle", text="Rotation") + else: + row.column().itemR(ob, "rotation_euler", text="Rotation") + + row.column().itemR(ob, "scale") + + layout.itemR(ob, "rotation_mode") else: - row.column().itemR(ob, "rotation_euler", text="Rotation") - - row.column().itemR(ob, "scale") - - layout.itemR(ob, "rotation_mode") + col = layout.column() + col.itemR(ob, "location") + col.itemR(ob, "rotation_mode", text="") + if ob.rotation_mode == 'QUATERNION': + col.itemR(ob, "rotation_quaternion") + elif ob.rotation_mode == 'AXIS_ANGLE': + col.itemR(ob, "rotation_axis_angle", text="Rotation") + else: + col.itemR(ob, "rotation_euler", text="Rotation") + col.itemR(ob, "scale") class OBJECT_PT_transform_locks(ObjectButtonsPanel): @@ -74,22 +88,23 @@ class OBJECT_PT_transform_locks(ObjectButtonsPanel): layout = self.layout ob = context.object + col2 = context.region.width > narrowui row = layout.row() col = row.column() - col.itemR(ob, "lock_location") + col.itemR(ob, "lock_location", text="Location") col = row.column() if ob.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'): - col.itemR(ob, "lock_rotations_4d", text="Lock Rotation") + col.itemR(ob, "lock_rotations_4d", text="Rotation") if ob.lock_rotations_4d: col.itemR(ob, "lock_rotation_w", text="W") col.itemR(ob, "lock_rotation", text="") else: col.itemR(ob, "lock_rotation", text="Rotation") - row.column().itemR(ob, "lock_scale") + row.column().itemR(ob, "lock_scale", text="Scale") class OBJECT_PT_relations(ObjectButtonsPanel): @@ -99,6 +114,7 @@ class OBJECT_PT_relations(ObjectButtonsPanel): layout = self.layout ob = context.object + col2 = context.region.width > narrowui split = layout.split() @@ -107,14 +123,13 @@ class OBJECT_PT_relations(ObjectButtonsPanel): col.itemS() col.itemR(ob, "pass_index") - col = split.column() + if col2: + col = split.column() col.itemL(text="Parent:") col.itemR(ob, "parent", text="") sub = col.column() - split = sub.split(percentage=0.3) - split.itemL(text="Type:") - split.itemR(ob, "parent_type", text="") + sub.itemR(ob, "parent_type", text="") parent = ob.parent if parent and ob.parent_type == 'BONE' and parent.type == 'ARMATURE': sub.item_pointerR(ob, "parent_bone", parent.data, "bones", text="") @@ -128,10 +143,14 @@ class OBJECT_PT_groups(ObjectButtonsPanel): layout = self.layout ob = context.object - - split = layout.split() - split.item_menu_enumO("object.group_add", "group", text="Add to Group") - split.itemL() + col2 = context.region.width > narrowui + + if col2: + split = layout.split() + split.item_menu_enumO("object.group_add", "group", text="Add to Group") + split.itemL() + else: + layout.item_menu_enumO("object.group_add", "group", text="Add to Group") for group in bpy.data.groups: if ob.name in group.objects: @@ -144,8 +163,13 @@ class OBJECT_PT_groups(ObjectButtonsPanel): row.itemO("object.group_remove", text="", icon='VICON_X') split = col.box().split() - split.column().itemR(group, "layer", text="Dupli") - split.column().itemR(group, "dupli_offset", text="") + + col = split.column() + col.itemR(group, "layer", text="Dupli") + + if col2: + col = split.column() + col.itemR(group, "dupli_offset", text="") class OBJECT_PT_display(ObjectButtonsPanel): @@ -155,24 +179,32 @@ class OBJECT_PT_display(ObjectButtonsPanel): layout = self.layout ob = context.object - + col2 = context.region.width > narrowui + split = layout.split() col = split.column() col.itemR(ob, "max_draw_type", text="Type") - col = split.column() + + if col2: + col = split.column() row = col.row() row.itemR(ob, "draw_bounds", text="Bounds") sub = row.row() sub.active = ob.draw_bounds sub.itemR(ob, "draw_bounds_type", text="") - flow = layout.column_flow() - flow.itemR(ob, "draw_name", text="Name") - flow.itemR(ob, "draw_axis", text="Axis") - flow.itemR(ob, "draw_wire", text="Wire") - flow.itemR(ob, "draw_texture_space", text="Texture Space") - flow.itemR(ob, "x_ray", text="X-Ray") - flow.itemR(ob, "draw_transparent", text="Transparency") + split = layout.split() + + col = split.column() + col.itemR(ob, "draw_name", text="Name") + col.itemR(ob, "draw_axis", text="Axis") + col.itemR(ob, "draw_wire", text="Wire") + + if col2: + col = split.column() + col.itemR(ob, "draw_texture_space", text="Texture Space") + col.itemR(ob, "x_ray", text="X-Ray") + col.itemR(ob, "draw_transparent", text="Transparency") class OBJECT_PT_duplication(ObjectButtonsPanel): @@ -182,9 +214,13 @@ class OBJECT_PT_duplication(ObjectButtonsPanel): layout = self.layout ob = context.object - - layout.itemR(ob, "dupli_type", expand=True) - + col2 = context.region.width > narrowui + + if col2: + layout.itemR(ob, "dupli_type", expand=True) + else: + layout.itemR(ob, "dupli_type", text="") + if ob.dupli_type == 'FRAMES': split = layout.split() @@ -192,7 +228,8 @@ class OBJECT_PT_duplication(ObjectButtonsPanel): col.itemR(ob, "dupli_frames_start", text="Start") col.itemR(ob, "dupli_frames_end", text="End") - col = split.column(align=True) + if col2: + col = split.column(align=True) col.itemR(ob, "dupli_frames_on", text="On") col.itemR(ob, "dupli_frames_off", text="Off") @@ -202,12 +239,20 @@ class OBJECT_PT_duplication(ObjectButtonsPanel): layout.itemR(ob, "dupli_verts_rotation", text="Rotation") elif ob.dupli_type == 'FACES': - row = layout.row() - row.itemR(ob, "dupli_faces_scale", text="Scale") - row.itemR(ob, "dupli_faces_inherit_scale", text="Inherit Scale") + split = layout.split() + + col = split.column() + col.itemR(ob, "dupli_faces_scale", text="Scale") + + if col2: + col = split.column() + col.itemR(ob, "dupli_faces_inherit_scale", text="Inherit Scale") elif ob.dupli_type == 'GROUP': - layout.itemR(ob, "dupli_group", text="Group") + if col2: + layout.itemR(ob, "dupli_group", text="Group") + else: + layout.itemR(ob, "dupli_group", text="") class OBJECT_PT_animation(ObjectButtonsPanel): @@ -217,7 +262,8 @@ class OBJECT_PT_animation(ObjectButtonsPanel): layout = self.layout ob = context.object - + col2 = context.region.width > narrowui + split = layout.split() col = split.column() @@ -234,7 +280,8 @@ class OBJECT_PT_animation(ObjectButtonsPanel): row.active = ob.parent != None col.itemR(ob, "time_offset", text="Offset") - col = split.column() + if col2: + col = split.column() col.itemL(text="Track:") col.itemR(ob, "track", text="") col.itemR(ob, "track_axis", text="Axis") diff --git a/release/scripts/ui/properties_object_constraint.py b/release/scripts/ui/properties_object_constraint.py index e6c68c081f3..49a228f38c9 100644 --- a/release/scripts/ui/properties_object_constraint.py +++ b/release/scripts/ui/properties_object_constraint.py @@ -88,7 +88,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): col = split.column() col.itemR(con, "chain_length") col.itemR(con, "targetless") - + def CHILD_OF(self, context, layout, con): self.target_template(layout, con) @@ -129,11 +129,11 @@ class ConstraintButtonsPanel(bpy.types.Panel): row.itemR(con, "target_z") self.space_template(layout, con) - + def IK(self, context, layout, con): if context.object.pose.ik_solver == "ITASC": layout.itemR(con, "ik_type") - getattr(self, "IK_" + con.ik_type)(context, layout, con) + getattr(self, 'IK_' + con.ik_type)(context, layout, con) else: # Legacy IK constraint self.target_template(layout, con) @@ -168,7 +168,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): sub = col.column() sub.active = con.rotation sub.itemR(con, "orient_weight", text="Rotation", slider=True) - + def IK_COPY_POSE(self, context, layout, con): self.target_template(layout, con) self.ik_template(layout, con) @@ -212,7 +212,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): row = layout.row() row.itemR(con, "weight", text="Weight", slider=True) row.itemR(con, "distance", text="Distance", slider=True) - + def FOLLOW_PATH(self, context, layout, con): self.target_template(layout, con) @@ -310,7 +310,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): row = layout.row() row.itemL(text="Convert:") row.itemR(con, "owner_space", text="") - + def LIMIT_SCALE(self, context, layout, con): split = layout.split() @@ -351,7 +351,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): row = layout.row() row.itemL(text="Convert:") row.itemR(con, "owner_space", text="") - + def COPY_ROTATION(self, context, layout, con): self.target_template(layout, con) @@ -378,7 +378,7 @@ class ConstraintButtonsPanel(bpy.types.Panel): layout.itemR(con, "offset") self.space_template(layout, con) - + def COPY_LOCATION(self, context, layout, con): self.target_template(layout, con) @@ -602,11 +602,11 @@ class ConstraintButtonsPanel(bpy.types.Panel): col.itemL(text="Spline Fitting:") col.itemR(con, "chain_length") col.itemR(con, "even_divisions") - #col.itemR(con, "affect_root") # XXX: this is not that useful yet + col.itemR(con, "chain_offset") col = layout.column() col.itemL(text="Chain Scaling:") - col.itemR(con, "keep_max_length") + col.itemR(con, "y_scaling") col.itemR(con, "xz_scaling_mode") @@ -702,7 +702,7 @@ class BONE_PT_inverse_kinematics(ConstraintButtonsPanel): split.itemR(pchan, "ik_stretch", text="Stretch", slider=True) split.itemL() - if ob.pose.ik_solver == "ITASC": + if ob.pose.ik_solver == 'ITASC': row = layout.row() row.itemR(pchan, "ik_rot_control", text="Control Rotation") row.itemR(pchan, "ik_rot_weight", text="Weight", slider=True) @@ -723,7 +723,7 @@ class BONE_PT_iksolver_itasc(ConstraintButtonsPanel): if ob and bone: pchan = ob.pose.pose_channels[bone.name] - return pchan.has_ik and ob.pose.ik_solver == "ITASC" and ob.pose.ik_param + return pchan.has_ik and ob.pose.ik_solver == 'ITASC' and ob.pose.ik_param return False @@ -734,7 +734,7 @@ class BONE_PT_iksolver_itasc(ConstraintButtonsPanel): itasc = ob.pose.ik_param layout.itemR(itasc, "mode", expand=True) - simulation = itasc.mode == "SIMULATION" + simulation = itasc.mode == 'SIMULATION' if simulation: layout.itemL(text="Reiteration:") layout.itemR(itasc, "reiteration", expand=True) @@ -742,7 +742,7 @@ class BONE_PT_iksolver_itasc(ConstraintButtonsPanel): flow = layout.column_flow() flow.itemR(itasc, "precision", text="Prec") flow.itemR(itasc, "num_iter", text="Iter") - flow.active = not simulation or itasc.reiteration != "NEVER" + flow.active = not simulation or itasc.reiteration != 'NEVER' if simulation: layout.itemR(itasc, "auto_step") @@ -757,7 +757,7 @@ class BONE_PT_iksolver_itasc(ConstraintButtonsPanel): if simulation: layout.itemR(itasc, "feedback") layout.itemR(itasc, "max_velocity") - if itasc.solver == "DLS": + if itasc.solver == 'DLS': row = layout.row() row.itemR(itasc, "dampmax", text="Damp", slider=True) row.itemR(itasc, "dampeps", text="Eps", slider=True) diff --git a/release/scripts/ui/properties_physics_field.py b/release/scripts/ui/properties_physics_field.py index b61f2172d94..3e2630e38f5 100644 --- a/release/scripts/ui/properties_physics_field.py +++ b/release/scripts/ui/properties_physics_field.py @@ -77,7 +77,7 @@ class PHYSICS_PT_field(PhysicButtonsPanel): layout.itemS() layout.itemR(field, "guide_kink_type") - if (field.guide_kink_type != "NONE"): + if (field.guide_kink_type != 'NONE'): layout.itemR(field, "guide_kink_axis") flow = layout.column_flow() diff --git a/release/scripts/ui/properties_render.py b/release/scripts/ui/properties_render.py index 6aafc808502..51b381478d7 100644 --- a/release/scripts/ui/properties_render.py +++ b/release/scripts/ui/properties_render.py @@ -19,6 +19,7 @@ # <pep8 compliant> import bpy +narrowui = 180 class RenderButtonsPanel(bpy.types.Panel): bl_space_type = 'PROPERTIES' @@ -26,10 +27,13 @@ class RenderButtonsPanel(bpy.types.Panel): bl_context = "render" # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here + + def poll(self, context): rd = context.scene.render_data return (context.scene and rd.use_game_engine == False) and (rd.engine in self.COMPAT_ENGINES) - + + class RENDER_PT_render(RenderButtonsPanel): bl_label = "Render" @@ -39,10 +43,16 @@ class RENDER_PT_render(RenderButtonsPanel): layout = self.layout rd = context.scene.render_data - - row = layout.row() - row.itemO("screen.render", text="Image", icon='ICON_RENDER_STILL') - row.item_booleanO("screen.render", "animation", True, text="Animation", icon='ICON_RENDER_ANIMATION') + col2 = context.region.width > narrowui + + split = layout.split() + + col = split.column() + col.itemO("screen.render", text="Image", icon='ICON_RENDER_STILL') + + if col2: + col = split.column() + col.item_booleanO("screen.render", "animation", True, text="Animation", icon='ICON_RENDER_ANIMATION') layout.itemR(rd, "display_mode", text="Display") @@ -57,7 +67,8 @@ class RENDER_PT_layers(RenderButtonsPanel): scene = context.scene rd = scene.render_data - + col2 = context.region.width > narrowui + row = layout.row() row.template_list(rd, "layers", rd, "active_layer_index", rows=2) @@ -74,7 +85,8 @@ class RENDER_PT_layers(RenderButtonsPanel): col = split.column() col.itemR(scene, "visible_layers", text="Scene") - col = split.column() + if col2: + col = split.column() col.itemR(rl, "visible_layers", text="Layer") layout.itemR(rl, "light_override", text="Light") @@ -121,7 +133,8 @@ class RENDER_PT_layers(RenderButtonsPanel): col.itemR(rl, "pass_mist") col.itemR(rl, "pass_object_index") - col = split.column() + if col2: + col = split.column() col.itemL() col.itemR(rl, "pass_color") col.itemR(rl, "pass_diffuse") @@ -150,7 +163,8 @@ class RENDER_PT_shading(RenderButtonsPanel): layout = self.layout rd = context.scene.render_data - + col2 = context.region.width > narrowui + split = layout.split() col = split.column() @@ -158,8 +172,9 @@ class RENDER_PT_shading(RenderButtonsPanel): col.itemR(rd, "render_shadows", text="Shadows") col.itemR(rd, "render_sss", text="Subsurface Scattering") col.itemR(rd, "render_envmaps", text="Environment Map") - - col = split.column() + + if col2: + col = split.column() col.itemR(rd, "render_raytracing", text="Ray Tracing") col.itemR(rd, "color_management") col.itemR(rd, "alpha_mode", text="Alpha") @@ -174,7 +189,8 @@ class RENDER_PT_performance(RenderButtonsPanel): layout = self.layout rd = context.scene.render_data - + col2 = context.region.width > narrowui + split = layout.split() col = split.column(align=True) @@ -187,7 +203,8 @@ class RENDER_PT_performance(RenderButtonsPanel): col.itemR(rd, "parts_x", text="X") col.itemR(rd, "parts_y", text="Y") - col = split.column() + if col2: + col = split.column() col.itemL(text="Memory:") sub = col.column() sub.itemR(rd, "save_buffers") @@ -199,7 +216,7 @@ class RENDER_PT_performance(RenderButtonsPanel): sub.active = rd.render_raytracing sub.itemL(text="Acceleration structure:") sub.itemR(rd, "raytrace_structure", text="") - if rd.raytrace_structure == "OCTREE": + if rd.raytrace_structure == 'OCTREE': sub.itemR(rd, "octree_resolution", text="Resolution") else: sub.itemR(rd, "use_instances", text="Instances") @@ -213,16 +230,18 @@ class RENDER_PT_post_processing(RenderButtonsPanel): def draw(self, context): layout = self.layout - + rd = context.scene.render_data - + col2 = context.region.width > narrowui + split = layout.split() col = split.column() col.itemR(rd, "use_compositing") col.itemR(rd, "use_sequencer") - col = split.column() + if col2: + col = split.column() col.itemR(rd, "dither_intensity", text="Dither", slider=True) layout.itemS() @@ -236,7 +255,11 @@ class RENDER_PT_post_processing(RenderButtonsPanel): sub.row().itemR(rd, "field_order", expand=True) sub.itemR(rd, "fields_still", text="Still") - col = split.column() + + if col2: + col = split.column() + else: + col.itemS() col.itemR(rd, "edge") sub = col.column() sub.active = rd.edge @@ -250,9 +273,10 @@ class RENDER_PT_output(RenderButtonsPanel): def draw(self, context): layout = self.layout - + rd = context.scene.render_data - + col2 = context.region.width > narrowui + layout.itemR(rd, "output_path", text="") split = layout.split() @@ -260,7 +284,8 @@ class RENDER_PT_output(RenderButtonsPanel): col.itemR(rd, "file_format", text="") col.row().itemR(rd, "color_mode", text="Color", expand=True) - col = split.column() + if col2: + col = split.column() col.itemR(rd, "file_extensions") col.itemR(rd, "use_overwrite") col.itemR(rd, "use_placeholder") @@ -275,12 +300,15 @@ class RENDER_PT_output(RenderButtonsPanel): col = split.column() col.itemL(text="Codec:") col.itemR(rd, "exr_codec", text="") - - subsplit = split.split() - col = subsplit.column() + + if col2: + subsplit = split.split() + col = subsplit.column() col.itemR(rd, "exr_half") col.itemR(rd, "exr_zbuf") - col = subsplit.column() + + if col2: + col = subsplit.column() col.itemR(rd, "exr_preview") elif rd.file_format == 'JPEG2000': @@ -289,7 +317,8 @@ class RENDER_PT_output(RenderButtonsPanel): col.itemL(text="Depth:") col.row().itemR(rd, "jpeg2k_depth", expand=True) - col = split.column() + if col2: + col = split.column() col.itemR(rd, "jpeg2k_preset", text="") col.itemR(rd, "jpeg2k_ycc") @@ -298,7 +327,8 @@ class RENDER_PT_output(RenderButtonsPanel): col = split.column() col.itemR(rd, "cineon_log", text="Convert to Log") - col = split.column(align=True) + if col2: + col = split.column(align=True) col.active = rd.cineon_log col.itemR(rd, "cineon_black", text="Black") col.itemR(rd, "cineon_white", text="White") @@ -322,6 +352,7 @@ class RENDER_PT_encoding(RenderButtonsPanel): layout = self.layout rd = context.scene.render_data + col2 = context.region.width > narrowui split = layout.split() @@ -340,7 +371,8 @@ class RENDER_PT_encoding(RenderButtonsPanel): col.itemR(rd, "ffmpeg_maxrate", text="Maximum") col.itemR(rd, "ffmpeg_buffersize", text="Buffer") - col = split.column() + if col2: + col = split.column() col.itemR(rd, "ffmpeg_gopsize") col.itemR(rd, "ffmpeg_autosplit") col.itemL(text="Mux:") @@ -357,7 +389,9 @@ class RENDER_PT_encoding(RenderButtonsPanel): col = split.column() col.itemR(rd, "ffmpeg_audio_bitrate") col.itemR(rd, "ffmpeg_audio_mixrate") - col = split.column() + + if col2: + col = split.column() col.itemR(rd, "ffmpeg_multiplex_audio") col.itemR(rd, "ffmpeg_audio_volume") @@ -375,16 +409,17 @@ class RENDER_PT_antialiasing(RenderButtonsPanel): layout = self.layout rd = context.scene.render_data - + col2 = context.region.width > narrowui layout.active = rd.antialiasing - + split = layout.split() col = split.column() col.row().itemR(rd, "antialiasing_samples", expand=True) col.itemR(rd, "full_sample") - col = split.column() + if col2: + col = split.column() col.itemR(rd, "pixel_filter", text="") col.itemR(rd, "filter_size", text="Size", slider=True) @@ -398,7 +433,8 @@ class RENDER_PT_dimensions(RenderButtonsPanel): scene = context.scene rd = scene.render_data - + col2 = context.region.width > narrowui + split = layout.split() col = split.column() @@ -418,15 +454,18 @@ class RENDER_PT_dimensions(RenderButtonsPanel): rowsub.active = rd.use_border rowsub.itemR(rd, "crop_to_border", text="Crop") - col = split.column(align=True) - col.itemL(text="Frame Range:") - col.itemR(scene, "start_frame", text="Start") - col.itemR(scene, "end_frame", text="End") - col.itemR(scene, "frame_step", text="Step") - - col.itemL(text="Frame Rate:") - col.itemR(rd, "fps") - col.itemR(rd, "fps_base", text="/") + if col2: + col = split.column() + sub = col.column(align=True) + sub.itemL(text="Frame Range:") + sub.itemR(scene, "start_frame", text="Start") + sub.itemR(scene, "end_frame", text="End") + sub.itemR(scene, "frame_step", text="Step") + + sub = col.column(align=True) + sub.itemL(text="Frame Rate:") + sub.itemR(rd, "fps") + sub.itemR(rd, "fps_base", text="/") class RENDER_PT_stamp(RenderButtonsPanel): @@ -443,6 +482,7 @@ class RENDER_PT_stamp(RenderButtonsPanel): layout = self.layout rd = context.scene.render_data + col2 = context.region.width > narrowui layout.active = rd.render_stamp @@ -459,7 +499,8 @@ class RENDER_PT_stamp(RenderButtonsPanel): col.itemR(rd, "stamp_marker", text="Marker") col.itemR(rd, "stamp_sequence_strip", text="Seq. Strip") - col = split.column() + if col2: + col = split.column() col.active = rd.render_stamp col.itemR(rd, "stamp_foreground", slider=True) col.itemR(rd, "stamp_background", slider=True) diff --git a/release/scripts/ui/properties_scene.py b/release/scripts/ui/properties_scene.py index 9ab431a2d6d..170c561820d 100644 --- a/release/scripts/ui/properties_scene.py +++ b/release/scripts/ui/properties_scene.py @@ -19,6 +19,7 @@ # <pep8 compliant> import bpy +narrowui = 180 class SceneButtonsPanel(bpy.types.Panel): bl_space_type = 'PROPERTIES' @@ -37,9 +38,13 @@ class SCENE_PT_scene(SceneButtonsPanel): layout = self.layout scene = context.scene - - layout.itemR(scene, "camera") - layout.itemR(scene, "set", text="Background") + + if col2: + layout.itemR(scene, "camera") + layout.itemR(scene, "set", text="Background") + else: + layout.itemR(scene, "camera", text="") + layout.itemR(scene, "set", text="") class SCENE_PT_unit(SceneButtonsPanel): @@ -48,16 +53,21 @@ class SCENE_PT_unit(SceneButtonsPanel): def draw(self, context): layout = self.layout - + col2 = context.region.width > narrowui unit = context.scene.unit_settings col = layout.column() col.row().itemR(unit, "system", expand=True) - row = layout.row() - row.active = (unit.system != 'NONE') - row.itemR(unit, "scale_length", text="Scale") - row.itemR(unit, "use_separate") + split = layout.split() + split.active = (unit.system != 'NONE') + + col = split.column() + col.itemR(unit, "scale_length", text="Scale") + + if col2: + col = split.column() + col.itemR(unit, "use_separate") class SCENE_PT_keying_sets(SceneButtonsPanel): @@ -67,7 +77,7 @@ class SCENE_PT_keying_sets(SceneButtonsPanel): layout = self.layout scene = context.scene - + col2 = context.region.width > narrowui row = layout.row() col = row.column() @@ -85,7 +95,8 @@ class SCENE_PT_keying_sets(SceneButtonsPanel): col.itemR(ks, "name") col.itemR(ks, "absolute") - col = row.column() + if col2: + col = row.column() col.itemL(text="Keyframing Settings:") col.itemR(ks, "insertkey_needed", text="Needed") col.itemR(ks, "insertkey_visual", text="Visual") @@ -102,6 +113,7 @@ class SCENE_PT_keying_set_paths(SceneButtonsPanel): scene = context.scene ks = scene.active_keying_set + col2 = context.region.width > narrowui row = layout.row() row.itemL(text="Paths:") @@ -131,7 +143,8 @@ class SCENE_PT_keying_set_paths(SceneButtonsPanel): if ksp.entire_array == False: col.itemR(ksp, "array_index") - col = row.column() + if col2: + col = row.column() col.itemL(text="F-Curve Grouping:") col.itemR(ksp, "grouping") if ksp.grouping == 'NAMED': @@ -149,10 +162,14 @@ class SCENE_PT_physics(SceneButtonsPanel): layout = self.layout scene = context.scene - + col2 = context.region.width > narrowui + layout.active = scene.use_gravity - - layout.itemR(scene, "gravity", text="") + + if col2: + layout.itemR(scene, "gravity", text="") + else: + layout.column().itemR(scene, "gravity", text="") bpy.types.register(SCENE_PT_scene) bpy.types.register(SCENE_PT_unit) diff --git a/release/scripts/ui/properties_world.py b/release/scripts/ui/properties_world.py index d00592470f0..f08cff38dfc 100644 --- a/release/scripts/ui/properties_world.py +++ b/release/scripts/ui/properties_world.py @@ -19,6 +19,7 @@ # <pep8 compliant> import bpy +narrowui = 180 class WorldButtonsPanel(bpy.types.Panel): bl_space_type = 'PROPERTIES' @@ -69,13 +70,19 @@ class WORLD_PT_world(WorldButtonsPanel): def draw(self, context): layout = self.layout - + col2 = context.region.width > narrowui world = context.world - - row = layout.row() - row.itemR(world, "paper_sky") - row.itemR(world, "blend_sky") - row.itemR(world, "real_sky") + + if col2: + row = layout.row() + row.itemR(world, "paper_sky") + row.itemR(world, "blend_sky") + row.itemR(world, "real_sky") + else: + col = layout.column() + col.itemR(world, "paper_sky") + col.itemR(world, "blend_sky") + col.itemR(world, "real_sky") row = layout.row() row.column().itemR(world, "horizon_color") @@ -96,16 +103,21 @@ class WORLD_PT_mist(WorldButtonsPanel): def draw(self, context): layout = self.layout - + col2 = context.region.width > narrowui world = context.world layout.active = world.mist.enabled + + split = layout.split() + + col = split.column() + col.itemR(world.mist, "intensity", slider=True) + col.itemR(world.mist, "start") - flow = layout.column_flow() - flow.itemR(world.mist, "intensity", slider=True) - flow.itemR(world.mist, "start") - flow.itemR(world.mist, "depth") - flow.itemR(world.mist, "height") + if col2: + col = split.column() + col.itemR(world.mist, "depth") + col.itemR(world.mist, "height") layout.itemR(world.mist, "falloff") @@ -121,16 +133,21 @@ class WORLD_PT_stars(WorldButtonsPanel): def draw(self, context): layout = self.layout - + col2 = context.region.width > narrowui world = context.world layout.active = world.stars.enabled - flow = layout.column_flow() - flow.itemR(world.stars, "size") - flow.itemR(world.stars, "color_randomization", text="Colors") - flow.itemR(world.stars, "min_distance", text="Min. Dist") - flow.itemR(world.stars, "average_separation", text="Separation") + split = layout.split() + + col = split.column() + col.itemR(world.stars, "size") + col.itemR(world.stars, "color_randomization", text="Colors") + + if col2: + col = split.column() + col.itemR(world.stars, "min_distance", text="Min. Dist") + col.itemR(world.stars, "average_separation", text="Separation") class WORLD_PT_ambient_occlusion(WorldButtonsPanel): @@ -144,7 +161,7 @@ class WORLD_PT_ambient_occlusion(WorldButtonsPanel): def draw(self, context): layout = self.layout - + col2 = context.region.width > narrowui ao = context.world.ambient_occlusion layout.active = ao.enabled @@ -163,7 +180,8 @@ class WORLD_PT_ambient_occlusion(WorldButtonsPanel): sub.itemR(ao, "falloff_strength", text="Strength") if ao.gather_method == 'RAYTRACE': - col = split.column() + if col2: + col = split.column() col.itemL(text="Sampling:") col.itemR(ao, "sample_method", text="") @@ -178,7 +196,8 @@ class WORLD_PT_ambient_occlusion(WorldButtonsPanel): sub.itemR(ao, "bias") if ao.gather_method == 'APPROXIMATE': - col = split.column() + if col2: + col = split.column() col.itemL(text="Sampling:") col.itemR(ao, "passes") @@ -196,10 +215,9 @@ class WORLD_PT_ambient_occlusion(WorldButtonsPanel): col = split.column() col.itemR(ao, "energy") - col = split.column() - sub = col.split(percentage=0.3) - sub.itemL(text="Color:") - sub.itemR(ao, "color", text="") + if col2: + col = split.column() + col.itemR(ao, "color") bpy.types.register(WORLD_PT_context_world) bpy.types.register(WORLD_PT_preview) diff --git a/release/scripts/ui/space_console.py b/release/scripts/ui/space_console.py index 06754ea81cb..d5392645387 100644 --- a/release/scripts/ui/space_console.py +++ b/release/scripts/ui/space_console.py @@ -89,16 +89,16 @@ class CONSOLE_MT_language(bpy.types.Menu): def draw(self, context): layout = self.layout layout.column() - + mod = bpy.ops.console languages = [] for opname in dir(mod): # execute_python, execute_shell etc. if opname.startswith("execute_"): languages.append(opname.split('_', 1)[-1]) - + languages.sort() - + for language in languages: layout.item_stringO("console.language", "language", language, text=language[0].upper() + language[1:]) @@ -155,13 +155,13 @@ class ConsoleBanner(bpy.types.Operator): def execute(self, context): sc = context.space_data - + # default to python if not sc.language: sc.language = 'python' banner = getattr(bpy.ops.console, "banner_" + sc.language, None) - + if banner: banner() else: @@ -178,12 +178,12 @@ class ConsoleLanguage(bpy.types.Operator): def execute(self, context): sc = context.space_data - + # defailt to python sc.language = self.language - + bpy.ops.console.banner() - + # insert a new blank line bpy.ops.console.history_append(text="", current_character=0, remove_duplicates=True) diff --git a/release/scripts/ui/space_info.py b/release/scripts/ui/space_info.py index cb1112c9dac..b5e73e60582 100644 --- a/release/scripts/ui/space_info.py +++ b/release/scripts/ui/space_info.py @@ -123,7 +123,8 @@ class INFO_MT_file_import(dynamic_menu.DynMenu): bl_label = "Import" def draw(self, context): - self.layout.itemO("WM_OT_collada_import", text="COLLADA (.dae)...") + if "collada_import" in dir(bpy.ops.wm): + self.layout.itemO("wm.collada_import", text="COLLADA (.dae)...") class INFO_MT_file_export(dynamic_menu.DynMenu): @@ -131,7 +132,8 @@ class INFO_MT_file_export(dynamic_menu.DynMenu): bl_label = "Export" def draw(self, context): - self.layout.itemO("WM_OT_collada_export", text="COLLADA (.dae)...") + if "collada_export" in dir(bpy.ops.wm): + self.layout.itemO("wm.collada_export", text="COLLADA (.dae)...") class INFO_MT_file_external_data(bpy.types.Menu): @@ -187,9 +189,9 @@ class INFO_MT_add(bpy.types.Menu): layout.itemO("object.text_add", text="Text", icon='ICON_OUTLINER_OB_FONT') layout.itemS() - + layout.operator_context = "INVOKE_SCREEN" - + layout.itemO("object.armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE') layout.item_enumO("object.add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE') layout.item_enumO("object.add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY') @@ -197,9 +199,9 @@ class INFO_MT_add(bpy.types.Menu): layout.itemS() layout.item_enumO("object.add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA') - + layout.operator_context = "EXEC_SCREEN" - + layout.item_menu_enumO("object.lamp_add", "type", 'LAMP', text="Lamp", icon='ICON_OUTLINER_OB_LAMP') layout.itemS() diff --git a/release/scripts/ui/space_node.py b/release/scripts/ui/space_node.py index 9880a320e25..5c93bede635 100644 --- a/release/scripts/ui/space_node.py +++ b/release/scripts/ui/space_node.py @@ -72,6 +72,9 @@ class NODE_MT_view(bpy.types.Menu): def draw(self, context): layout = self.layout + + layout.itemO("node.properties", icon='ICON_MENU_PANEL') + layout.itemS() # layout.itemO("grease_pencil..") # layout.itemS() diff --git a/release/scripts/ui/space_sequencer.py b/release/scripts/ui/space_sequencer.py index ec90d15968d..9468510c7a5 100644 --- a/release/scripts/ui/space_sequencer.py +++ b/release/scripts/ui/space_sequencer.py @@ -245,12 +245,14 @@ class SEQUENCER_MT_strip(bpy.types.Menu): elif stype == 'IMAGE': layout.itemS() layout.itemO("sequencer.image_change") + layout.itemO("sequencer.rendersize") elif stype == 'SCENE': layout.itemS() layout.itemO("sequencer.scene_change", text="Change Scene") elif stype == 'MOVIE': layout.itemS() layout.itemO("sequencer.movie_change") + layout.itemO("sequencer.rendersize") layout.itemS() diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 935e3b40874..68f01146026 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -371,29 +371,26 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(v3d, "back") - col.itemR(v3d, "title") - col.itemR(v3d, "text") - col.itemR(v3d, "text_hi") + col.itemR(v3d, "button") + col.itemR(v3d, "button_title") + col.itemR(v3d, "button_text") col.itemR(v3d, "header") - col.itemR(v3d, "header_text") col = split.column() - col.itemR(v3d, "header_text_hi") col.itemR(v3d, "grid") - col.itemR(v3d, "panel", slider=True) col.itemR(v3d, "wire") col.itemR(v3d, "lamp", slider=True) + col.itemR(v3d, "editmesh_active", slider=True) col = split.column() - col.itemR(v3d, "current_frame") - col.itemR(v3d, "editmesh_active", slider=True) + col.itemR(v3d, "object_selected") col.itemR(v3d, "object_active") col.itemR(v3d, "object_grouped") col.itemR(v3d, "object_grouped_active") + col.itemR(v3d, "transform") col = split.column() - col.itemR(v3d, "transform") col.itemR(v3d, "vertex") col.itemR(v3d, "face", slider=True) col.itemR(v3d, "normal") @@ -736,54 +733,46 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(graph, "back") - col.itemR(graph, "title") - col.itemR(graph, "text") - col.itemR(graph, "text_hi") - col.itemR(graph, "header") - + col.itemR(graph, "button") + col.itemR(graph, "button_title") + col.itemR(graph, "button_text") + col = split.column() - col.itemR(graph, "header_text") - col.itemR(graph, "header_text_hi") + col.itemR(graph, "header") col.itemR(graph, "grid") - col.itemR(graph, "panel") - col.itemR(graph, "window_sliders") - + col.itemR(graph, "list") + col.itemR(graph, "channel_group") + col = split.column() - col.itemR(graph, "channels_region") + col.itemR(graph, "active_channels_group") + col.itemR(graph, "dopesheet_channel") + col.itemR(graph, "dopesheet_subchannel") col.itemR(graph, "vertex") + + col = split.column() col.itemR(graph, "current_frame") col.itemR(graph, "handle_vertex") col.itemR(graph, "handle_vertex_select") - - col = split.column() + col.itemS() col.itemR(graph, "handle_vertex_size") - col.itemR(graph, "channel_group") - col.itemR(graph, "active_channels_group") - col.itemR(graph, "dopesheet_channel") - col.itemR(graph, "dopesheet_subchannel") - - + elif theme.active_theme == 'FILE_BROWSER': file = theme.file_browser col = split.column() col.itemR(file, "back") - col.itemR(file, "title") col.itemR(file, "text") col.itemR(file, "text_hi") col = split.column() col.itemR(file, "header") - col.itemR(file, "header_text") - col.itemR(file, "header_text_hi") + col.itemR(file, "list") col = split.column() col.itemR(file, "selected_file") col.itemR(file, "tiles") - col.itemR(file, "scrollbar") col = split.column() - col.itemR(file, "scroll_handle") col.itemR(file, "active_file") col.itemR(file, "active_file_text") @@ -792,21 +781,19 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(nla, "back") - col.itemR(nla, "title") - col.itemR(nla, "text") - col.itemR(nla, "text_hi") - + col.itemR(nla, "button") + col.itemR(nla, "button_title") + col = split.column() + col.itemR(nla, "button_text") + col.itemR(nla, "text") col.itemR(nla, "header") - col.itemR(nla, "header_text") - col.itemR(nla, "header_text_hi") - col.itemR(nla, "grid") - + col = split.column() - col.itemR(nla, "view_sliders") + col.itemR(nla, "grid") col.itemR(nla, "bars") col.itemR(nla, "bars_selected") - + col = split.column() col.itemR(nla, "strips") col.itemR(nla, "strips_selected") @@ -817,27 +804,22 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(dope, "back") - col.itemR(dope, "title") + col.itemR(dope, "list") col.itemR(dope, "text") - col.itemR(dope, "text_hi") col.itemR(dope, "header") col = split.column() - col.itemR(dope, "header_text") - col.itemR(dope, "header_text_hi") col.itemR(dope, "grid") - col.itemR(dope, "value_sliders") - col.itemR(dope, "view_sliders") - - col = split.column() col.itemR(dope, "channels") col.itemR(dope, "channels_selected") col.itemR(dope, "channel_group") + + col = split.column() col.itemR(dope, "active_channels_group") col.itemR(dope, "long_key") + col.itemR(dope, "long_key_selected") col = split.column() - col.itemR(dope, "long_key_selected") col.itemR(dope, "current_frame") col.itemR(dope, "dopesheet_channel") col.itemR(dope, "dopesheet_subchannel") @@ -847,18 +829,16 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(image, "back") - col.itemR(image, "title") - + col.itemR(image, "button") + col = split.column() - col.itemR(image, "text") - col.itemR(image, "text_hi") + col.itemR(image, "button_title") + col.itemR(image, "button_text") col = split.column() col.itemR(image, "header") - col.itemR(image, "header_text") col = split.column() - col.itemR(image, "header_text_hi") col.itemR(image, "editmesh_active", slider=True) elif theme.active_theme == 'SEQUENCE_EDITOR': @@ -866,27 +846,25 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(seq, "back") - col.itemR(seq, "title") + col.itemR(seq, "button") + col.itemR(seq, "button_title") + col.itemR(seq, "button_text") col.itemR(seq, "text") - col.itemR(seq, "text_hi") - col.itemR(seq, "header") col = split.column() - col.itemR(seq, "header_text") - col.itemR(seq, "header_text_hi") + col.itemR(seq, "header") col.itemR(seq, "grid") - col.itemR(seq, "window_sliders") col.itemR(seq, "movie_strip") - - col = split.column() col.itemR(seq, "image_strip") col.itemR(seq, "scene_strip") + + col = split.column() col.itemR(seq, "audio_strip") col.itemR(seq, "effect_strip") col.itemR(seq, "plugin_strip") + col.itemR(seq, "transition_strip") col = split.column() - col.itemR(seq, "transition_strip") col.itemR(seq, "meta_strip") col.itemR(seq, "current_frame") col.itemR(seq, "keyframe") @@ -897,43 +875,38 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(prop, "back") + + col = split.column() col.itemR(prop, "title") col = split.column() col.itemR(prop, "text") - col.itemR(prop, "text_hi") col = split.column() col.itemR(prop, "header") - col.itemR(prop, "header_text") - - col = split.column() - col.itemR(prop, "header_text_hi") - col.itemR(prop, "panel") elif theme.active_theme == 'TEXT_EDITOR': text = theme.text_editor col = split.column() col.itemR(text, "back") - col.itemR(text, "title") + col.itemR(text, "button") + col.itemR(text, "button_title") + col.itemR(text, "button_text") + + col = split.column() col.itemR(text, "text") col.itemR(text, "text_hi") - - col = split.column() col.itemR(text, "header") - col.itemR(text, "header_text") - col.itemR(text, "header_text_hi") col.itemR(text, "line_numbers_background") col = split.column() - col.itemR(text, "scroll_bar") col.itemR(text, "selected_text") col.itemR(text, "cursor") col.itemR(text, "syntax_builtin") + col.itemR(text, "syntax_special") col = split.column() - col.itemR(text, "syntax_special") col.itemR(text, "syntax_comment") col.itemR(text, "syntax_string") col.itemR(text, "syntax_numbers") @@ -943,19 +916,15 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(time, "back") - col.itemR(time, "title") col.itemR(time, "text") col = split.column() - col.itemR(time, "text_hi") col.itemR(time, "header") col = split.column() - col.itemR(time, "header_text") - col.itemR(time, "header_text_hi") - - col = split.column() col.itemR(time, "grid") + + col = split.column() col.itemR(time, "current_frame") elif theme.active_theme == 'NODE_EDITOR': @@ -963,20 +932,21 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(node, "back") - col.itemR(node, "title") - col.itemR(node, "text") - col.itemR(node, "text_hi") + col.itemR(node, "button") + col.itemR(node, "button_title") + col.itemR(node, "button_text") + col = split.column() + col.itemR(node, "text") + col.itemR(node, "text_hi") col.itemR(node, "header") - col.itemR(node, "header_text") - col.itemR(node, "header_text_hi") col.itemR(node, "wires") col = split.column() col.itemR(node, "wire_select") col.itemR(node, "selected_text") - col.itemR(node, "node_backdrop") + col.itemR(node, "node_backdrop", slider=True) col.itemR(node, "in_out_node") col = split.column() @@ -989,18 +959,17 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(logic, "back") - col.itemR(logic, "title") + col.itemR(logic, "button") col = split.column() - col.itemR(logic, "text") - col.itemR(logic, "text_hi") + col.itemR(logic, "button_title") + col.itemR(logic, "button_text") col = split.column() + col.itemR(logic, "text") col.itemR(logic, "header") - col.itemR(logic, "header_text") col = split.column() - col.itemR(logic, "header_text_hi") col.itemR(logic, "panel") elif theme.active_theme == 'OUTLINER': @@ -1008,54 +977,44 @@ class USERPREF_PT_theme(bpy.types.Panel): col = split.column() col.itemR(out, "back") - col.itemR(out, "title") col = split.column() col.itemR(out, "text") + + col = split.column() col.itemR(out, "text_hi") col = split.column() col.itemR(out, "header") - col.itemR(out, "header_text") - - col = split.column() - col.itemR(out, "header_text_hi") elif theme.active_theme == 'INFO': info = theme.info col = split.column() col.itemR(info, "back") - col.itemR(info, "title") col = split.column() - col.itemR(info, "text") - col.itemR(info, "text_hi") + col.itemR(info, "header") col = split.column() - col.itemR(info, "header") col.itemR(info, "header_text") col = split.column() - col.itemR(info, "header_text_hi") elif theme.active_theme == 'USER_PREFERENCES': prefs = theme.user_preferences col = split.column() col.itemR(prefs, "back") - col.itemR(prefs, "title") col = split.column() col.itemR(prefs, "text") - col.itemR(prefs, "text_hi") - + col = split.column() col.itemR(prefs, "header") - col.itemR(prefs, "header_text") col = split.column() - col.itemR(prefs, "header_text_hi") + col.itemR(prefs, "header_text") class USERPREF_PT_file(bpy.types.Panel): @@ -1224,16 +1183,16 @@ class USERPREF_PT_input(bpy.types.Panel): row = subcol.row() if kmi.expanded: - row.itemR(kmi, "expanded", text="", icon="ICON_TRIA_DOWN") + row.itemR(kmi, "expanded", text="", icon='ICON_TRIA_DOWN') else: - row.itemR(kmi, "expanded", text="", icon="ICON_TRIA_RIGHT") + row.itemR(kmi, "expanded", text="", icon='ICON_TRIA_RIGHT') itemrow = row.row() itemrow.enabled = km.user_defined if kmi.active: - itemrow.itemR(kmi, "active", text="", icon="ICON_CHECKBOX_HLT") + itemrow.itemR(kmi, "active", text="", icon='ICON_CHECKBOX_HLT') else: - itemrow.itemR(kmi, "active", text="", icon="ICON_CHECKBOX_DEHLT") + itemrow.itemR(kmi, "active", text="", icon='ICON_CHECKBOX_DEHLT') itemcol = itemrow.column() itemcol.active = kmi.active @@ -1290,11 +1249,11 @@ class USERPREF_PT_input(bpy.types.Panel): itemcol.itemS() - itemrow.itemO("wm.keyitem_remove", text="", icon="ICON_ZOOMOUT") + itemrow.itemO("wm.keyitem_remove", text="", icon='ICON_ZOOMOUT') itemrow = col.row() itemrow.itemL() - itemrow.itemO("wm.keyitem_add", text="", icon="ICON_ZOOMIN") + itemrow.itemO("wm.keyitem_add", text="", icon='ICON_ZOOMIN') itemrow.enabled = km.user_defined bpy.types.register(USERPREF_HT_header) @@ -1439,7 +1398,7 @@ class WM_OT_keyitem_add(bpy.types.Operator): def execute(self, context): wm = context.manager km = wm.active_keymap - kmi = km.add_item("", "A", "PRESS") + kmi = km.add_item("", 'A', 'PRESS') return ('FINISHED',) diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index 863bab35f13..309d46307e7 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -306,12 +306,18 @@ class VIEW3D_MT_select_particle(bpy.types.Menu): layout.itemO("particle.select_all_toggle", text="Select/Deselect All") layout.itemO("particle.select_linked") + layout.itemO("particle.select_inverse") layout.itemS() layout.itemO("particle.select_more") layout.itemO("particle.select_less") + layout.itemS() + + layout.itemO("particle.select_first", text="Roots") + layout.itemO("particle.select_last", text="Tips") + class VIEW3D_MT_select_edit_mesh(bpy.types.Menu): bl_label = "Select" @@ -644,7 +650,7 @@ class VIEW3D_MT_make_links(bpy.types.Menu): def draw(self, context): layout = self.layout - + layout.item_menu_enumO("object.make_links_scene", "type", text="Objects to Scene...") layout.items_enumO("object.make_links_data", property="type") # inline @@ -1373,29 +1379,25 @@ class VIEW3D_PT_3dview_item(bpy.types.Panel): bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_label = "Item" - + def poll(self, context): - return (context.active_object or context.bone or context.edit_bone) - + return (context.active_object or context.active_bone or context.active_pchan) + def draw(self, context): layout = self.layout - - ob = context.object - + + ob = context.active_object + row = layout.row() row.itemL(text="", icon='ICON_OBJECT_DATA') row.itemR(ob, "name", text="") - - if ((context.active_bone or context.active_pchan) and ob.type == 'ARMATURE' and (ob.mode == 'EDIT' or ob.mode == 'POSE')): + + if ob.type == 'ARMATURE' and ob.mode in ('EDIT', 'POSE'): bone = context.active_bone - if not bone: - pchan = context.active_pchan - if pchan: - bone = pchan.bone - - row = layout.row() - row.itemL(text="", icon='ICON_BONE_DATA') - row.itemR(bone, "name", text="") + if bone: + row = layout.row() + row.itemL(text="", icon='ICON_BONE_DATA') + row.itemR(bone, "name", text="") class VIEW3D_PT_3dview_display(bpy.types.Panel): bl_space_type = 'VIEW_3D' @@ -1592,13 +1594,13 @@ class VIEW3D_PT_etch_a_ton(bpy.types.Panel): col.itemR(toolsettings, "etch_convert_mode") - if toolsettings.etch_convert_mode == "LENGTH": + if toolsettings.etch_convert_mode == 'LENGTH': col.itemR(toolsettings, "etch_length_limit") - elif toolsettings.etch_convert_mode == "ADAPTIVE": + elif toolsettings.etch_convert_mode == 'ADAPTIVE': col.itemR(toolsettings, "etch_adaptive_limit") - elif toolsettings.etch_convert_mode == "FIXED": + elif toolsettings.etch_convert_mode == 'FIXED': col.itemR(toolsettings, "etch_subdivision_number") - elif toolsettings.etch_convert_mode == "RETARGET": + elif toolsettings.etch_convert_mode == 'RETARGET': col.itemR(toolsettings, "etch_template") col.itemR(toolsettings, "etch_roll_mode") col.itemR(toolsettings, "etch_autoname") diff --git a/release/scripts/ui/space_view3d_toolbar.py b/release/scripts/ui/space_view3d_toolbar.py index 49c28427724..771e1e9046b 100644 --- a/release/scripts/ui/space_view3d_toolbar.py +++ b/release/scripts/ui/space_view3d_toolbar.py @@ -111,7 +111,7 @@ class VIEW3D_PT_tools_meshedit(View3DPanel): col = layout.column(align=True) col.itemL(text="UV Mapping:") col.item_stringO("wm.call_menu", "name", "VIEW3D_MT_uv_map", text="Unwrap") - + col.itemO("mesh.uvs_rotate") col.itemO("mesh.uvs_mirror") diff --git a/source/Makefile b/source/Makefile index 783b51b81de..a106e655e78 100644 --- a/source/Makefile +++ b/source/Makefile @@ -188,7 +188,11 @@ ifeq ($(WITH_OPENEXR), true) endif ifeq ($(WITH_OPENJPEG), true) - COMLIB += $(OCGDIR)/extern/openjpeg/$(DEBUG_DIR)libopenjpeg.a + ifndef BF_OPENJPEG_LIBS + COMLIB += $(OCGDIR)/extern/openjpeg/$(DEBUG_DIR)libopenjpeg.a + else + COMLIB += $(BF_OPENJPEG_LIBS) + endif endif COMLIB += $(OCGDIR)/blender/imbuf/cineon/$(DEBUG_DIR)libcineon.a diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 8721e49f06b..c1b54c393c7 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -46,7 +46,7 @@ #include "BLI_blenlib.h" #include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BIF_gl.h" #include "BLF_api.h" @@ -459,7 +459,7 @@ static void blf_font_fill(FontBLF *font) font->pos[0]= 0.0f; font->pos[1]= 0.0f; font->angle= 0.0f; - Mat4One(font->mat); + unit_m4(font->mat); font->clip_rec.xmin= 0.0f; font->clip_rec.xmax= 0.0f; font->clip_rec.ymin= 0.0f; diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 7d1e43a38df..1174197dce7 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -131,7 +131,8 @@ void blf_glyph_cache_free(GlyphCacheBLF *gc) } } - glDeleteTextures(gc->cur_tex+1, gc->textures); + if (gc->cur_tex+1 > 0) + glDeleteTextures(gc->cur_tex+1, gc->textures); free((void *)gc->textures); MEM_freeN(gc); } diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index e5b3adbd0c0..54dd82317fc 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -38,7 +38,7 @@ #include "BKE_DerivedMesh.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_edgehash.h" #include "DNA_cloth_types.h" diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h index 6446b48d553..7e0bb9fa08e 100644 --- a/source/blender/blenkernel/BKE_constraint.h +++ b/source/blender/blenkernel/BKE_constraint.h @@ -52,7 +52,7 @@ typedef struct bConstraintOb { float startmat[4][4]; /* original matrix (before constraint solving) */ short type; /* type of owner */ - short rotOrder; /* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_arithb.h) */ + short rotOrder; /* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_math.h) */ } bConstraintOb; /* ---------------------------------------------------------------------------- */ @@ -102,6 +102,9 @@ typedef struct bConstraintTypeInfo { bConstraintTypeInfo *constraint_get_typeinfo(struct bConstraint *con); bConstraintTypeInfo *get_constraint_typeinfo(int type); +struct bConstraint *add_ob_constraint(struct Object *ob, const char *name, short type); +struct bConstraint *add_pose_constraint(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type); + /* ---------------------------------------------------------------------------- */ /* Useful macros for testing various common flag combinations */ diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index feba39ee11d..7f64538b10d 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -174,7 +174,7 @@ PointerRNA CTX_data_pointer_get(const bContext *C, const char *member); PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type); ListBase CTX_data_collection_get(const bContext *C, const char *member); ListBase CTX_data_dir_get(const bContext *C); -void CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb); +int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb); void CTX_data_id_pointer_set(bContextDataResult *result, struct ID *id); void CTX_data_pointer_set(bContextDataResult *result, struct ID *id, StructRNA *type, void *data); diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h index b66ddf13527..877e09b037f 100644 --- a/source/blender/blenkernel/BKE_group.h +++ b/source/blender/blenkernel/BKE_group.h @@ -42,8 +42,8 @@ void free_group(struct Group *group); void unlink_group(struct Group *group); struct Group *add_group(char *name); struct Group *copy_group(struct Group *group); -void add_to_group(struct Group *group, struct Object *ob); -int rem_from_group(struct Group *group, struct Object *ob); +int add_to_group(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base); +int rem_from_group(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base); struct Group *find_group(struct Object *ob, struct Group *group); int object_in_group(struct Object *ob, struct Group *group); int group_is_animated(struct Object *parent, struct Group *group); diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index b70801a9edd..c81d837689f 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -60,6 +60,7 @@ float *do_ob_key(struct Scene *scene, struct Object *ob); struct Key *ob_get_key(struct Object *ob); struct KeyBlock *ob_get_keyblock(struct Object *ob); +struct KeyBlock *ob_get_reference_keyblock(struct Object *ob); struct KeyBlock *key_get_keyblock(struct Key *key, int index); struct KeyBlock *key_get_named_keyblock(struct Key *key, const char name[]); char *key_get_curValue_rnaPath(struct Key *key, struct KeyBlock *kb); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 66776d086d6..f9130e24a08 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -53,6 +53,7 @@ struct GPUMaterial; struct GPUNode; struct GPUNodeStack; struct PointerRNA; +struct bContext; /* ************** NODE TYPE DEFINITIONS ***** */ @@ -83,7 +84,7 @@ typedef struct bNodeType { void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **); /* this line is set on startup of blender */ - void (*uifunc)(struct uiLayout *, struct PointerRNA *ptr); + void (*uifunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr); void (*initfunc)(struct bNode *); void (*freestoragefunc)(struct bNode *); @@ -161,6 +162,7 @@ void nodeVerifyType(struct bNodeTree *ntree, struct bNode *node); void nodeAddToPreview(struct bNode *, float *, int, int); void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node); +void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node); void nodeAddSockets(struct bNode *node, struct bNodeType *ntype); struct bNode *nodeAddNodeType(struct bNodeTree *ntree, int type, struct bNodeTree *ngroup, struct ID *id); void nodeRegisterType(struct ListBase *typelist, const struct bNodeType *ntype) ; diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index ba42aca1872..b532b0820d7 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -68,6 +68,9 @@ typedef struct SculptSession { struct MFace *mface; int totvert, totface; float *face_normals; + + struct Object *ob; + struct KeyBlock *kb, *refkb; /* Mesh connectivity */ struct ListBase *fmap; diff --git a/source/blender/blenkernel/intern/BME_tools.c b/source/blender/blenkernel/intern/BME_tools.c index 32065ea5151..d92e8fe4227 100644 --- a/source/blender/blenkernel/intern/BME_tools.c +++ b/source/blender/blenkernel/intern/BME_tools.c @@ -42,7 +42,7 @@ #include "BKE_utildefines.h" #include "BKE_bmesh.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" /*split this all into a seperate bevel.c file in src*/ @@ -88,7 +88,7 @@ BME_TransData *BME_assign_transdata(BME_TransData_Head *td, BME_Mesh *bm, BME_Ve else if (org != NULL) VECCOPY(vtd->org,org); if (vec != NULL) { VECCOPY(vtd->vec,vec); - Normalize(vtd->vec); + normalize_v3(vtd->vec); } vtd->loc = loc; @@ -261,7 +261,7 @@ static BME_Vert *BME_split_edge(BME_Mesh *bm, BME_Vert *v, BME_Edge *e, BME_Edge nv = BME_SEMV(bm,v,e,ne); if (nv == NULL) return NULL; VECSUB(nv->co,v2->co,v->co); - len = VecLength(nv->co); + len = len_v3(nv->co); VECADDFAC(nv->co,v->co,nv->co,len*percent); nv->flag = v->flag; nv->bweight = v->bweight; @@ -335,17 +335,17 @@ static int BME_bevel_get_vec(float *vec, BME_Vert *v1, BME_Vert *v2, BME_TransDa /* compare the transform origins to see if we can use the vert co's; * if they belong to different origins, then we will use the origins to determine * the vector */ - if (VecCompare(vtd1->org,vtd2->org,0.000001f)) { + if (compare_v3v3(vtd1->org,vtd2->org,0.000001f)) { VECSUB(vec,v2->co,v1->co); - if (VecLength(vec) < 0.000001f) { - VecMulf(vec,0); + if (len_v3(vec) < 0.000001f) { + mul_v3_fl(vec,0); } return 0; } else { VECSUB(vec,vtd2->org,vtd1->org); - if (VecLength(vec) < 0.000001f) { - VecMulf(vec,0); + if (len_v3(vec) < 0.000001f) { + mul_v3_fl(vec,0); } return 1; } @@ -363,18 +363,18 @@ static int BME_bevel_get_vec(float *vec, BME_Vert *v1, BME_Vert *v2, BME_TransDa static float BME_bevel_project_vec(float *vec1, float *vec2, float *up_vec, int is_forward, BME_TransData_Head *td) { float factor, vec3[3], tmp[3],c1,c2; - Crossf(tmp,vec1,vec2); - Normalize(tmp); - factor = Inpf(up_vec,tmp); + cross_v3_v3v3(tmp,vec1,vec2); + normalize_v3(tmp); + factor = dot_v3v3(up_vec,tmp); if ((factor > 0 && is_forward) || (factor < 0 && !is_forward)) { - Crossf(vec3,vec2,tmp); /* hmm, maybe up_vec should be used instead of tmp */ + cross_v3_v3v3(vec3,vec2,tmp); /* hmm, maybe up_vec should be used instead of tmp */ } else { - Crossf(vec3,tmp,vec2); /* hmm, maybe up_vec should be used instead of tmp */ + cross_v3_v3v3(vec3,tmp,vec2); /* hmm, maybe up_vec should be used instead of tmp */ } - Normalize(vec3); - c1 = Inpf(vec3,vec1); - c2 = Inpf(vec1,vec1); + normalize_v3(vec3); + c1 = dot_v3v3(vec3,vec1); + c2 = dot_v3v3(vec1,vec1); if (fabs(c1) < 0.000001f || fabs(c2) < 0.000001f) { factor = 0.0f; } @@ -435,8 +435,8 @@ static BME_Vert *BME_bevel_split_edge(BME_Mesh *bm, BME_Vert *v, BME_Vert *v1, B ne->tflag1 = BME_BEVEL_ORIG; /* mark edge as original, even though it isn't */ BME_bevel_get_vec(vec1,v1,v,td); BME_bevel_get_vec(vec2,v2,v,td); - Crossf(t_up_vec,vec1,vec2); - Normalize(t_up_vec); + cross_v3_v3v3(t_up_vec,vec1,vec2); + normalize_v3(t_up_vec); up_vec = t_up_vec; } else { @@ -486,8 +486,8 @@ static BME_Vert *BME_bevel_split_edge(BME_Mesh *bm, BME_Vert *v, BME_Vert *v1, B is_edge = BME_bevel_get_vec(vec1,v,v1,td); /* get the vector we will be projecting onto */ BME_bevel_get_vec(vec2,v,v2,td); /* get the vector we will be projecting parallel to */ - len = VecLength(vec1); - Normalize(vec1); + len = len_v3(vec1); + normalize_v3(vec1); vtd = BME_get_transdata(td, sv); vtd1 = BME_get_transdata(td, v); @@ -525,8 +525,8 @@ static BME_Vert *BME_bevel_split_edge(BME_Mesh *bm, BME_Vert *v, BME_Vert *v1, B } VECADDFAC(sv->co,v->co,vec1,dis); VECSUB(vec1,sv->co,vtd1->org); - dis = VecLength(vec1); - Normalize(vec1); + dis = len_v3(vec1); + normalize_v3(vec1); BME_assign_transdata(td, bm, sv, vtd1->org, vtd1->org, vec1, sv->co, dis, scale, maxfactor, vtd->max); return sv; @@ -545,10 +545,10 @@ static float BME_bevel_set_max(BME_Vert *v1, BME_Vert *v2, float value, BME_Tran } else { VECCOPY(vec2,vtd1->vec); - VecMulf(vec2,vtd1->factor); - if (Inpf(vec1, vec1)) { - Projf(vec2,vec2,vec1); - fac1 = VecLength(vec2)/value; + mul_v3_fl(vec2,vtd1->factor); + if (dot_v3v3(vec1, vec1)) { + project_v3_v3v3(vec2,vec2,vec1); + fac1 = len_v3(vec2)/value; } else { fac1 = 0; @@ -560,10 +560,10 @@ static float BME_bevel_set_max(BME_Vert *v1, BME_Vert *v2, float value, BME_Tran } else { VECCOPY(vec3,vtd2->vec); - VecMulf(vec3,vtd2->factor); - if (Inpf(vec1, vec1)) { - Projf(vec2,vec3,vec1); - fac2 = VecLength(vec2)/value; + mul_v3_fl(vec3,vtd2->factor); + if (dot_v3v3(vec1, vec1)) { + project_v3_v3v3(vec2,vec3,vec1); + fac2 = len_v3(vec2)/value; } else { fac2 = 0; @@ -571,7 +571,7 @@ static float BME_bevel_set_max(BME_Vert *v1, BME_Vert *v2, float value, BME_Tran } if (fac1 || fac2) { - max = VecLength(vec1)/(fac1 + fac2); + max = len_v3(vec1)/(fac1 + fac2); if (vtd1->max && (*vtd1->max < 0 || max < *vtd1->max)) { *vtd1->max = max; } @@ -760,12 +760,12 @@ static BME_Poly *BME_bevel_poly(BME_Mesh *bm, BME_Poly *f, float value, int opti for (i=0,ol=f->loopbase,l=ol->next; l->next!=ol; l=l->next) { BME_bevel_get_vec(vec1,l->next->v,ol->v,td); BME_bevel_get_vec(vec2,l->v,ol->v,td); - Crossf(vec3,vec2,vec1); + cross_v3_v3v3(vec3,vec2,vec1); VECADD(up_vec,up_vec,vec3); i++; } - VecMulf(up_vec,1.0f/i); - Normalize(up_vec); + mul_v3_fl(up_vec,1.0f/i); + normalize_v3(up_vec); for (i=0,len=f->len; i<len; i++,l=l->next) { if ((l->e->tflag1 & BME_BEVEL_BEVEL) && (l->e->tflag1 & BME_BEVEL_ORIG)) { @@ -791,10 +791,10 @@ static BME_Poly *BME_bevel_poly(BME_Mesh *bm, BME_Poly *f, float value, int opti } else { VECCOPY(vec2,vtd1->vec); - VecMulf(vec2,vtd1->factor); - if (Inpf(vec1, vec1)) { - Projf(vec2,vec2,vec1); - fac1 = VecLength(vec2)/value; + mul_v3_fl(vec2,vtd1->factor); + if (dot_v3v3(vec1, vec1)) { + project_v3_v3v3(vec2,vec2,vec1); + fac1 = len_v3(vec2)/value; } else { fac1 = 0; @@ -805,17 +805,17 @@ static BME_Poly *BME_bevel_poly(BME_Mesh *bm, BME_Poly *f, float value, int opti } else { VECCOPY(vec3,vtd2->vec); - VecMulf(vec3,vtd2->factor); - if (Inpf(vec1, vec1)) { - Projf(vec2,vec3,vec1); - fac2 = VecLength(vec2)/value; + mul_v3_fl(vec3,vtd2->factor); + if (dot_v3v3(vec1, vec1)) { + project_v3_v3v3(vec2,vec3,vec1); + fac2 = len_v3(vec2)/value; } else { fac2 = 0; } } if (fac1 || fac2) { - max = VecLength(vec1)/(fac1 + fac2); + max = len_v3(vec1)/(fac1 + fac2); if (vtd1->max && (*vtd1->max < 0 || max < *vtd1->max)) { *vtd1->max = max; } @@ -880,7 +880,7 @@ static float BME_bevel_get_angle(BME_Mesh *bm, BME_Edge *e, BME_Vert *v) { } VECSUB(vec1,v1->co,v->co); VECSUB(vec2,v2->co,v->co); - Crossf(vec3,vec1,vec2); + cross_v3_v3v3(vec3,vec1,vec2); l1 = l2; if (l1->v == v) { @@ -893,12 +893,12 @@ static float BME_bevel_get_angle(BME_Mesh *bm, BME_Edge *e, BME_Vert *v) { } VECSUB(vec1,v1->co,v->co); VECSUB(vec2,v2->co,v->co); - Crossf(vec4,vec2,vec1); + cross_v3_v3v3(vec4,vec2,vec1); - Normalize(vec3); - Normalize(vec4); + normalize_v3(vec3); + normalize_v3(vec4); - return Inpf(vec3,vec4); + return dot_v3v3(vec3,vec4); } static int BME_face_sharededges(BME_Poly *f1, BME_Poly *f2){ BME_Loop *l; diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 11e58203bb3..f9abaa9da02 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -52,7 +52,7 @@ #include "DNA_space_types.h" #include "DNA_particle_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_edgehash.h" #include "BLI_editVert.h" @@ -619,20 +619,20 @@ static void emDM__calcFaceCent(EditFace *efa, float cent[3], float (*vertexCos)[ { if (vertexCos) { VECCOPY(cent, vertexCos[(int) efa->v1->tmp.l]); - VecAddf(cent, cent, vertexCos[(int) efa->v2->tmp.l]); - VecAddf(cent, cent, vertexCos[(int) efa->v3->tmp.l]); - if (efa->v4) VecAddf(cent, cent, vertexCos[(int) efa->v4->tmp.l]); + add_v3_v3v3(cent, cent, vertexCos[(int) efa->v2->tmp.l]); + add_v3_v3v3(cent, cent, vertexCos[(int) efa->v3->tmp.l]); + if (efa->v4) add_v3_v3v3(cent, cent, vertexCos[(int) efa->v4->tmp.l]); } else { VECCOPY(cent, efa->v1->co); - VecAddf(cent, cent, efa->v2->co); - VecAddf(cent, cent, efa->v3->co); - if (efa->v4) VecAddf(cent, cent, efa->v4->co); + add_v3_v3v3(cent, cent, efa->v2->co); + add_v3_v3v3(cent, cent, efa->v3->co); + if (efa->v4) add_v3_v3v3(cent, cent, efa->v4->co); } if (efa->v4) { - VecMulf(cent, 0.25f); + mul_v3_fl(cent, 0.25f); } else { - VecMulf(cent, 0.33333333333f); + mul_v3_fl(cent, 0.33333333333f); } } static void emDM_foreachMappedFaceCenter(DerivedMesh *dm, void (*func)(void *userData, int index, float *co, float *no), void *userData) @@ -1498,25 +1498,25 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob, if(efa->v4) { float *v4 = vertexCos[(int) efa->v4->tmp.l]; - CalcNormFloat4(v1, v2, v3, v4, no); - VecAddf(emdm->vertexNos[(int) efa->v4->tmp.l], emdm->vertexNos[(int) efa->v4->tmp.l], no); + normal_quad_v3( no,v1, v2, v3, v4); + add_v3_v3v3(emdm->vertexNos[(int) efa->v4->tmp.l], emdm->vertexNos[(int) efa->v4->tmp.l], no); } else { - CalcNormFloat(v1, v2, v3, no); + normal_tri_v3( no,v1, v2, v3); } - VecAddf(emdm->vertexNos[(int) efa->v1->tmp.l], emdm->vertexNos[(int) efa->v1->tmp.l], no); - VecAddf(emdm->vertexNos[(int) efa->v2->tmp.l], emdm->vertexNos[(int) efa->v2->tmp.l], no); - VecAddf(emdm->vertexNos[(int) efa->v3->tmp.l], emdm->vertexNos[(int) efa->v3->tmp.l], no); + add_v3_v3v3(emdm->vertexNos[(int) efa->v1->tmp.l], emdm->vertexNos[(int) efa->v1->tmp.l], no); + add_v3_v3v3(emdm->vertexNos[(int) efa->v2->tmp.l], emdm->vertexNos[(int) efa->v2->tmp.l], no); + add_v3_v3v3(emdm->vertexNos[(int) efa->v3->tmp.l], emdm->vertexNos[(int) efa->v3->tmp.l], no); } for(i=0, eve= em->verts.first; eve; i++, eve=eve->next) { float *no = emdm->vertexNos[i]; /* following Mesh convention; we use vertex coordinate itself * for normal in this case */ - if (Normalize(no)==0.0) { + if (normalize_v3(no)==0.0) { VECCOPY(no, vertexCos[i]); - Normalize(no); + normalize_v3(no); } } } @@ -2482,7 +2482,7 @@ int editmesh_get_first_deform_matrices(Object *ob, EditMesh *em, float (**deform defmats= MEM_callocN(sizeof(*defmats)*numVerts, "defmats"); for(a=0; a<numVerts; a++) - Mat3One(defmats[a]); + unit_m3(defmats[a]); } mti->deformMatricesEM(md, ob, em, dm, deformedVerts, defmats, @@ -2554,11 +2554,11 @@ void DM_add_tangent_layer(DerivedMesh *dm) if (mf->v4) { v4= &mvert[mf->v4]; - CalcNormFloat4(v4->co, v3->co, v2->co, v1->co, fno); + normal_quad_v3( fno,v4->co, v3->co, v2->co, v1->co); } else { v4= NULL; - CalcNormFloat(v3->co, v2->co, v1->co, fno); + normal_tri_v3( fno,v3->co, v2->co, v1->co); } if(mtface) { @@ -2569,11 +2569,11 @@ void DM_add_tangent_layer(DerivedMesh *dm) } else { uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; - spheremap(orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2], &uv[0][0], &uv[0][1]); - spheremap(orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2], &uv[1][0], &uv[1][1]); - spheremap(orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2], &uv[2][0], &uv[2][1]); + map_to_sphere( &uv[0][0], &uv[0][1],orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]); + map_to_sphere( &uv[1][0], &uv[1][1],orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]); + map_to_sphere( &uv[2][0], &uv[2][1],orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]); if(v4) - spheremap(orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2], &uv[3][0], &uv[3][1]); + map_to_sphere( &uv[3][0], &uv[3][1],orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]); } tangent_from_uv(uv1, uv2, uv3, v1->co, v2->co, v3->co, fno, tang); @@ -2603,11 +2603,11 @@ void DM_add_tangent_layer(DerivedMesh *dm) } else { uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; - spheremap(orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2], &uv[0][0], &uv[0][1]); - spheremap(orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2], &uv[1][0], &uv[1][1]); - spheremap(orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2], &uv[2][0], &uv[2][1]); + map_to_sphere( &uv[0][0], &uv[0][1],orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2]); + map_to_sphere( &uv[1][0], &uv[1][1],orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2]); + map_to_sphere( &uv[2][0], &uv[2][1],orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2]); if(len==4) - spheremap(orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2], &uv[3][0], &uv[3][1]); + map_to_sphere( &uv[3][0], &uv[3][1],orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2]); } mf_vi[0]= mf->v1; @@ -2619,7 +2619,7 @@ void DM_add_tangent_layer(DerivedMesh *dm) vtang= find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]); VECCOPY(tangent[j], vtang); - Normalize(tangent[j]); + normalize_v3(tangent[j]); } } diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 2dec76d1b6b..358a482c3cf 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -64,7 +64,7 @@ #include "BKE_utildefines.h" #include "BIK_api.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" @@ -453,7 +453,7 @@ bPoseChannel *verify_pose_channel(bPose* pose, const char* name) chan->limitmax[0]= chan->limitmax[1]= chan->limitmax[2]= 180.0f; chan->stiffness[0]= chan->stiffness[1]= chan->stiffness[2]= 0.0f; chan->ikrotweight = chan->iklinweight = 0.0f; - Mat4One(chan->constinv); + unit_m4(chan->constinv); BLI_addtail(&pose->chanbase, chan); @@ -471,7 +471,7 @@ bPoseChannel *get_active_posechannel (Object *ob) /* find active */ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if ((pchan->bone) && (pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) + if ((pchan->bone) && (pchan->bone == arm->act_bone) && (pchan->bone->layer & arm->layer)) return pchan; } @@ -611,8 +611,8 @@ static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan pchan->rotAngle= chan->rotAngle; QUATCOPY(pchan->quat, chan->quat); pchan->rotmode= chan->rotmode; - Mat4CpyMat4(pchan->chan_mat, (float(*)[4])chan->chan_mat); - Mat4CpyMat4(pchan->pose_mat, (float(*)[4])chan->pose_mat); + copy_m4_m4(pchan->chan_mat, (float(*)[4])chan->chan_mat); + copy_m4_m4(pchan->pose_mat, (float(*)[4])chan->pose_mat); pchan->flag= chan->flag; con= chan->constraints.first; @@ -1013,8 +1013,8 @@ void copy_pose_result(bPose *to, bPose *from) for(pchanfrom= from->chanbase.first; pchanfrom; pchanfrom= pchanfrom->next) { pchanto= get_pose_channel(to, pchanfrom->name); if(pchanto) { - Mat4CpyMat4(pchanto->pose_mat, pchanfrom->pose_mat); - Mat4CpyMat4(pchanto->chan_mat, pchanfrom->chan_mat); + copy_m4_m4(pchanto->pose_mat, pchanfrom->pose_mat); + copy_m4_m4(pchanto->chan_mat, pchanfrom->chan_mat); /* used for local constraints */ VECCOPY(pchanto->loc, pchanfrom->loc); @@ -1040,9 +1040,9 @@ void what_does_obaction (Scene *scene, Object *ob, Object *workob, bPose *pose, clear_workob(workob); /* init workob */ - Mat4CpyMat4(workob->obmat, ob->obmat); - Mat4CpyMat4(workob->parentinv, ob->parentinv); - Mat4CpyMat4(workob->constinv, ob->constinv); + copy_m4_m4(workob->obmat, ob->obmat); + copy_m4_m4(workob->parentinv, ob->parentinv); + copy_m4_m4(workob->constinv, ob->constinv); workob->parent= ob->parent; workob->track= ob->track; @@ -1109,7 +1109,7 @@ static void blend_pose_strides(bPose *dst, bPose *src, float srcweight, short mo dstweight = 1.0F; } - VecLerpf(dst->stride_offset, dst->stride_offset, src->stride_offset, srcweight); + interp_v3_v3v3(dst->stride_offset, dst->stride_offset, src->stride_offset, srcweight); } @@ -1169,27 +1169,27 @@ static void blend_pose_offset_bone(bActionStrip *strip, bPose *dst, bPose *src, execute_action_ipo(achan, &pchan); /* store offset that moves src to location of pchan */ - VecSubf(vec, dpchan->loc, pchan.loc); + sub_v3_v3v3(vec, dpchan->loc, pchan.loc); - Mat4Mul3Vecfl(dpchan->bone->arm_mat, vec); + mul_mat3_m4_v3(dpchan->bone->arm_mat, vec); } } else { /* store offset that moves src to location of dst */ - VecSubf(vec, dpchan->loc, spchan->loc); - Mat4Mul3Vecfl(dpchan->bone->arm_mat, vec); + sub_v3_v3v3(vec, dpchan->loc, spchan->loc); + mul_mat3_m4_v3(dpchan->bone->arm_mat, vec); } /* if blending, we only add with factor scrweight */ - VecMulf(vec, srcweight); + mul_v3_fl(vec, srcweight); - VecAddf(dst->cyclic_offset, dst->cyclic_offset, vec); + add_v3_v3v3(dst->cyclic_offset, dst->cyclic_offset, vec); } } } - VecAddf(dst->cyclic_offset, dst->cyclic_offset, src->cyclic_offset); + add_v3_v3v3(dst->cyclic_offset, dst->cyclic_offset, src->cyclic_offset); } /* added "sizecorr" here, to allow armatures to be scaled and still have striding. @@ -1249,14 +1249,14 @@ static float stridechannel_frame(Object *ob, float sizecorr, bActionStrip *strip if (pdistNewNormalized <= 1) { // search for correction in positive path-direction where_on_path(ob, pdistNewNormalized, vec2, dir); /* vec needs size 4 */ - VecSubf(stride_offset, vec2, vec1); + sub_v3_v3v3(stride_offset, vec2, vec1); } else { // we reached the end of the path, search backwards instead where_on_path(ob, (pathdist-pdist)/path->totdist, vec2, dir); /* vec needs size 4 */ - VecSubf(stride_offset, vec1, vec2); + sub_v3_v3v3(stride_offset, vec1, vec2); } - Mat4Mul3Vecfl(ob->obmat, stride_offset); + mul_mat3_m4_v3(ob->obmat, stride_offset); return striptime; } } @@ -1295,10 +1295,10 @@ static void cyclic_offs_bone(Object *ob, bPose *pose, bActionStrip *strip, float } if(foundvert) { /* bring it into armature space */ - VecSubf(min, max, min); + sub_v3_v3v3(min, max, min); bone= get_named_bone(ob->data, strip->offs_bone); /* weak */ if(bone) { - Mat4Mul3Vecfl(bone->arm_mat, min); + mul_mat3_m4_v3(bone->arm_mat, min); /* dominant motion, cyclic_offset was cleared in rest_pose */ if (strip->flag & (ACTSTRIP_CYCLIC_USEX | ACTSTRIP_CYCLIC_USEY | ACTSTRIP_CYCLIC_USEZ)) { @@ -1549,7 +1549,7 @@ static void do_nla(Scene *scene, Object *ob, int blocktype) } else if(blocktype==ID_AR) { /* apply stride offset to object */ - VecAddf(ob->obmat[3], ob->obmat[3], ob->pose->stride_offset); + add_v3_v3v3(ob->obmat[3], ob->obmat[3], ob->pose->stride_offset); } /* free */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 5cae2418e89..a1b138b9a74 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -35,7 +35,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "DNA_listBase.h" @@ -134,11 +134,11 @@ void calc_curvepath(Object *ob) for(a=0; a<tot; a++) { fp++; if(cycl && a==tot-1) - VecSubf(xyz, bevpfirst->vec, bevp->vec); + sub_v3_v3v3(xyz, bevpfirst->vec, bevp->vec); else - VecSubf(xyz, (bevp+1)->vec, bevp->vec); + sub_v3_v3v3(xyz, (bevp+1)->vec, bevp->vec); - *fp= *(fp-1)+VecLength(xyz); + *fp= *(fp-1)+len_v3(xyz); bevp++; } @@ -176,11 +176,11 @@ void calc_curvepath(Object *ob) fac1= fac2/fac1; fac2= 1.0f-fac1; - VecLerpf(pp->vec, bevp->vec, bevpn->vec, fac2); + interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2); pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa; pp->radius= fac1*bevp->radius + fac2*bevpn->radius; - QuatInterpol(pp->quat, bevp->quat, bevpn->quat, fac2); - NormalQuat(pp->quat); + interp_qt_qtqt(pp->quat, bevp->quat, bevpn->quat, fac2); + normalize_qt(pp->quat); pp++; } @@ -284,20 +284,20 @@ int where_on_path(Object *ob, float ctime, float *vec, float *dir, float *quat, * to more then one index in data which can give divide by zero error */ /* totfac= data[0]+data[1]; - if(totfac>0.000001) QuatInterpol(q1, p0->quat, p1->quat, data[0] / totfac); + if(totfac>0.000001) interp_qt_qtqt(q1, p0->quat, p1->quat, data[0] / totfac); else QUATCOPY(q1, p1->quat); - NormalQuat(q1); + normalize_qt(q1); totfac= data[2]+data[3]; - if(totfac>0.000001) QuatInterpol(q2, p2->quat, p3->quat, data[2] / totfac); + if(totfac>0.000001) interp_qt_qtqt(q2, p2->quat, p3->quat, data[2] / totfac); else QUATCOPY(q1, p3->quat); - NormalQuat(q2); + normalize_qt(q2); totfac = data[0]+data[1]+data[2]+data[3]; - if(totfac>0.000001) QuatInterpol(quat, q1, q2, (data[0]+data[1]) / totfac); + if(totfac>0.000001) interp_qt_qtqt(quat, q1, q2, (data[0]+data[1]) / totfac); else QUATCOPY(quat, q2); - NormalQuat(quat); + normalize_qt(quat); */ // XXX - find some way to make quat interpolation work correctly, above code fails in rare but nasty cases. QUATCOPY(quat, p1->quat); @@ -317,8 +317,8 @@ static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], i BLI_addtail(lb, dob); dob->ob= ob; - Mat4CpyMat4(dob->mat, mat); - Mat4CpyMat4(dob->omat, ob->obmat); + copy_m4_m4(dob->mat, mat); + copy_m4_m4(dob->omat, ob->obmat); dob->origlay= ob->lay; dob->index= index; dob->type= type; @@ -352,20 +352,20 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i /* Group Dupli Offset, should apply after everything else */ if (group->dupli_ofs[0] || group->dupli_ofs[1] || group->dupli_ofs[2]) { - Mat4CpyMat4(tmat, go->ob->obmat); - VecSubf(tmat[3], tmat[3], group->dupli_ofs); - Mat4MulMat4(mat, tmat, ob->obmat); + copy_m4_m4(tmat, go->ob->obmat); + sub_v3_v3v3(tmat[3], tmat[3], group->dupli_ofs); + mul_m4_m4m4(mat, tmat, ob->obmat); } else { - Mat4MulMat4(mat, go->ob->obmat, ob->obmat); + mul_m4_m4m4(mat, go->ob->obmat, ob->obmat); } dob= new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated); dob->no_draw= (dob->origlay & group->layer)==0; if(go->ob->transflag & OB_DUPLI) { - Mat4CpyMat4(dob->ob->obmat, dob->mat); + copy_m4_m4(dob->ob->obmat, dob->mat); object_duplilist_recursive((ID *)group, scene, go->ob, lb, ob->obmat, level+1, animated); - Mat4CpyMat4(dob->ob->obmat, dob->omat); + copy_m4_m4(dob->ob->obmat, dob->omat); } } } @@ -402,7 +402,7 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, #endif // XXX old animation system where_is_object_time(scene, ob, (float)scene->r.cfra); dob= new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, OB_DUPLIFRAMES, animated); - Mat4CpyMat4(dob->omat, copyob.obmat); + copy_m4_m4(dob->omat, copyob.obmat); } } @@ -430,11 +430,11 @@ static void vertex_dupli__mapFunc(void *userData, int index, float *co, float *n float vec[3], q2[4], mat[3][3], tmat[4][4], obmat[4][4]; VECCOPY(vec, co); - Mat4MulVecfl(vdd->pmat, vec); - VecSubf(vec, vec, vdd->pmat[3]); - VecAddf(vec, vec, vdd->obmat[3]); + mul_m4_v3(vdd->pmat, vec); + sub_v3_v3v3(vec, vec, vdd->pmat[3]); + add_v3_v3v3(vec, vec, vdd->obmat[3]); - Mat4CpyMat4(obmat, vdd->obmat); + copy_m4_m4(obmat, vdd->obmat); VECCOPY(obmat[3], vec); if(vdd->par->transflag & OB_DUPLIROT) { @@ -445,11 +445,11 @@ static void vertex_dupli__mapFunc(void *userData, int index, float *co, float *n vec[0]= -no_s[0]; vec[1]= -no_s[1]; vec[2]= -no_s[2]; } - vectoquat(vec, vdd->ob->trackflag, vdd->ob->upflag, q2); + vec_to_quat( q2,vec, vdd->ob->trackflag, vdd->ob->upflag); - QuatToMat3(q2, mat); - Mat4CpyMat4(tmat, obmat); - Mat4MulMat43(obmat, tmat, mat); + quat_to_mat3( mat,q2); + copy_m4_m4(tmat, obmat); + mul_m4_m4m3(obmat, tmat, mat); } dob= new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS, vdd->animated); if(vdd->orco) @@ -457,10 +457,10 @@ static void vertex_dupli__mapFunc(void *userData, int index, float *co, float *n if(vdd->ob->transflag & OB_DUPLI) { float tmpmat[4][4]; - Mat4CpyMat4(tmpmat, vdd->ob->obmat); - Mat4CpyMat4(vdd->ob->obmat, obmat); /* pretend we are really this mat */ + copy_m4_m4(tmpmat, vdd->ob->obmat); + copy_m4_m4(vdd->ob->obmat, obmat); /* pretend we are really this mat */ object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->level+1, vdd->animated); - Mat4CpyMat4(vdd->ob->obmat, tmpmat); + copy_m4_m4(vdd->ob->obmat, tmpmat); } } @@ -478,7 +478,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl float vec[3], no[3], pmat[4][4]; int lay, totvert, a, oblay; - Mat4CpyMat4(pmat, par->obmat); + copy_m4_m4(pmat, par->obmat); /* simple preventing of too deep nested groups */ if(level>MAX_DUPLI_RECUR) return; @@ -533,9 +533,9 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl when par_space_mat is NULL ob->obmat can be used instead of ob__obmat */ if(par_space_mat) - Mat4MulMat4(vdd.obmat, ob->obmat, par_space_mat); + mul_m4_m4m4(vdd.obmat, ob->obmat, par_space_mat); else - Mat4CpyMat4(vdd.obmat, ob->obmat); + copy_m4_m4(vdd.obmat, ob->obmat); vdd.id= id; vdd.level= level; @@ -544,7 +544,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl vdd.ob= ob; vdd.scene= scene; vdd.par= par; - Mat4CpyMat4(vdd.pmat, pmat); + copy_m4_m4(vdd.pmat, pmat); /* mballs have a different dupli handling */ if(ob->type!=OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ @@ -596,7 +596,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa /* simple preventing of too deep nested groups */ if(level>MAX_DUPLI_RECUR) return; - Mat4CpyMat4(pmat, par->obmat); + copy_m4_m4(pmat, par->obmat); em = BKE_mesh_get_editmesh(me); if(em) { @@ -664,11 +664,11 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa when par_space_mat is NULL ob->obmat can be used instead of ob__obmat */ if(par_space_mat) - Mat4MulMat4(ob__obmat, ob->obmat, par_space_mat); + mul_m4_m4m4(ob__obmat, ob->obmat, par_space_mat); else - Mat4CpyMat4(ob__obmat, ob->obmat); + copy_m4_m4(ob__obmat, ob->obmat); - Mat3CpyMat4(imat, ob->parentinv); + copy_m3_m4(imat, ob->parentinv); /* mballs have a different dupli handling */ if(ob->type!=OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ @@ -686,34 +686,34 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa /* translation */ if(v4) - CalcCent4f(cent, v1, v2, v3, v4); + cent_quad_v3(cent, v1, v2, v3, v4); else - CalcCent3f(cent, v1, v2, v3); - Mat4MulVecfl(pmat, cent); + cent_tri_v3(cent, v1, v2, v3); + mul_m4_v3(pmat, cent); - VecSubf(cent, cent, pmat[3]); - VecAddf(cent, cent, ob__obmat[3]); + sub_v3_v3v3(cent, cent, pmat[3]); + add_v3_v3v3(cent, cent, ob__obmat[3]); - Mat4CpyMat4(obmat, ob__obmat); + copy_m4_m4(obmat, ob__obmat); VECCOPY(obmat[3], cent); /* rotation */ - triatoquat(v1, v2, v3, quat); - QuatToMat3(quat, mat); + tri_to_quat( quat,v1, v2, v3); + quat_to_mat3( mat,quat); /* scale */ if(par->transflag & OB_DUPLIFACES_SCALE) { - float size= v4?AreaQ3Dfl(v1, v2, v3, v4):AreaT3Dfl(v1, v2, v3); + float size= v4? area_quad_v3(v1, v2, v3, v4): area_tri_v3(v1, v2, v3); size= sqrt(size) * par->dupfacesca; - Mat3MulFloat(mat[0], size); + mul_m3_fl(mat, size); } - Mat3CpyMat3(mat3, mat); - Mat3MulMat3(mat, imat, mat3); + copy_m3_m3(mat3, mat); + mul_m3_m3m3(mat, imat, mat3); - Mat4CpyMat4(tmat, obmat); - Mat4MulMat43(obmat, tmat, mat); + copy_m4_m4(tmat, obmat); + mul_m4_m4m3(obmat, tmat, mat); dob= new_dupli_object(lb, ob, obmat, lay, a, OB_DUPLIFACES, animated); if(G.rendering) { @@ -744,10 +744,10 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa if(ob->transflag & OB_DUPLI) { float tmpmat[4][4]; - Mat4CpyMat4(tmpmat, ob->obmat); - Mat4CpyMat4(ob->obmat, obmat); /* pretend we are really this mat */ + copy_m4_m4(tmpmat, ob->obmat); + copy_m4_m4(ob->obmat, obmat); /* pretend we are really this mat */ object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, level+1, animated); - Mat4CpyMat4(ob->obmat, tmpmat); + copy_m4_m4(ob->obmat, tmpmat); } } @@ -935,22 +935,22 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if(psys_get_particle_state(&sim, a, &state, 0) == 0) continue; - QuatToMat4(state.rot, pamat); + quat_to_mat4( pamat,state.rot); VECCOPY(pamat[3], state.co); pamat[3][3]= 1.0f; } if(part->ren_as==PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) { for(go= part->dup_group->gobject.first, b=0; go; go= go->next, b++) { - Mat4MulMat4(tmat, oblist[b]->obmat, pamat); - Mat4MulFloat3((float *)tmat, size*scale); + mul_m4_m4m4(tmat, oblist[b]->obmat, pamat); + mul_mat3_m4_fl(tmat, size*scale); if(par_space_mat) - Mat4MulMat4(mat, tmat, par_space_mat); + mul_m4_m4m4(mat, tmat, par_space_mat); else - Mat4CpyMat4(mat, tmat); + copy_m4_m4(mat, tmat); dob= new_dupli_object(lb, go->ob, mat, par->lay, counter, OB_DUPLIPARTS, animated); - Mat4CpyMat4(dob->omat, obcopylist[b].obmat); + copy_m4_m4(dob->omat, obcopylist[b].obmat); if(G.rendering) psys_get_dupli_texture(par, part, sim.psmd, pa, cpa, dob->uv, dob->orco); } @@ -962,21 +962,21 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p VECCOPY(vec, obmat[3]); obmat[3][0] = obmat[3][1] = obmat[3][2] = 0.0f; - Mat4CpyMat4(mat, pamat); + copy_m4_m4(mat, pamat); - Mat4MulMat4(tmat, obmat, mat); - Mat4MulFloat3((float *)tmat, size*scale); + mul_m4_m4m4(tmat, obmat, mat); + mul_mat3_m4_fl(tmat, size*scale); if(part->draw & PART_DRAW_GLOBAL_OB) VECADD(tmat[3], tmat[3], vec); if(par_space_mat) - Mat4MulMat4(mat, tmat, par_space_mat); + mul_m4_m4m4(mat, tmat, par_space_mat); else - Mat4CpyMat4(mat, tmat); + copy_m4_m4(mat, tmat); dob= new_dupli_object(lb, ob, mat, ob->lay, counter, OB_DUPLIPARTS, animated); - Mat4CpyMat4(dob->omat, oldobmat); + copy_m4_m4(dob->omat, oldobmat); if(G.rendering) psys_get_dupli_texture(par, part, sim.psmd, pa, cpa, dob->uv, dob->orco); } @@ -1037,7 +1037,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i /* simple preventing of too deep nested groups */ if(level>MAX_DUPLI_RECUR) return; - Mat4CpyMat4(pmat, par->obmat); + copy_m4_m4(pmat, par->obmat); /* in par the family name is stored, use this to find the other objects */ @@ -1062,9 +1062,9 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i vec[1]= fsize*(ct->yof - yof); vec[2]= 0.0; - Mat4MulVecfl(pmat, vec); + mul_m4_v3(pmat, vec); - Mat4CpyMat4(obmat, par->obmat); + copy_m4_m4(obmat, par->obmat); VECCOPY(obmat[3], vec); new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIVERTS, animated); @@ -1122,7 +1122,7 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas if (level==0) { for(dob= duplilist->first; dob; dob= dob->next) if(dob->type == OB_DUPLIGROUP) - Mat4CpyMat4(dob->ob->obmat, dob->mat); + copy_m4_m4(dob->ob->obmat, dob->mat); } } } @@ -1143,7 +1143,7 @@ void free_object_duplilist(ListBase *lb) for(dob= lb->first; dob; dob= dob->next) { dob->ob->lay= dob->origlay; - Mat4CpyMat4(dob->ob->obmat, dob->omat); + copy_m4_m4(dob->ob->obmat, dob->omat); } BLI_freelistN(lb); diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 61e754ffbec..e2849825862 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "DNA_anim_types.h" diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index f178553d796..cf84fea1f68 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_armature_types.h" @@ -169,10 +169,13 @@ void make_local_armature(bArmature *arm) } } -static void copy_bonechildren (Bone* newBone, Bone* oldBone) +static void copy_bonechildren (Bone* newBone, Bone* oldBone, Bone* actBone, Bone **newActBone) { Bone *curBone, *newChildBone; + if(oldBone == actBone) + *newActBone= newBone; + /* Copy this bone's list*/ BLI_duplicatelist(&newBone->childbase, &oldBone->childbase); @@ -180,7 +183,7 @@ static void copy_bonechildren (Bone* newBone, Bone* oldBone) newChildBone=newBone->childbase.first; for (curBone=oldBone->childbase.first;curBone;curBone=curBone->next){ newChildBone->parent=newBone; - copy_bonechildren(newChildBone,curBone); + copy_bonechildren(newChildBone, curBone, actBone, newActBone); newChildBone=newChildBone->next; } } @@ -189,6 +192,7 @@ bArmature *copy_armature(bArmature *arm) { bArmature *newArm; Bone *oldBone, *newBone; + Bone *newActBone= NULL; newArm= copy_libblock (arm); BLI_duplicatelist(&newArm->bonebase, &arm->bonebase); @@ -197,10 +201,11 @@ bArmature *copy_armature(bArmature *arm) newBone=newArm->bonebase.first; for (oldBone=arm->bonebase.first;oldBone;oldBone=oldBone->next){ newBone->parent=NULL; - copy_bonechildren (newBone, oldBone); + copy_bonechildren (newBone, oldBone, arm->act_bone, &newActBone); newBone=newBone->next; }; + newArm->act_bone= newActBone; return newArm; } @@ -477,7 +482,7 @@ static void equalize_bezier(float *data, int desired) pdist[0]= 0.0f; for(a=0, fp= data; a<MAX_BBONE_SUBDIV; a++, fp+=4) { QUATCOPY(temp[a], fp); - pdist[a+1]= pdist[a]+VecLenf(fp, fp+4); + pdist[a+1]= pdist[a]+len_v3v3(fp, fp+4); } /* do last point */ QUATCOPY(temp[a], fp); @@ -527,16 +532,16 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) if(!rest) { /* check if we need to take non-uniform bone scaling into account */ - scale[0]= VecLength(pchan->pose_mat[0]); - scale[1]= VecLength(pchan->pose_mat[1]); - scale[2]= VecLength(pchan->pose_mat[2]); + scale[0]= len_v3(pchan->pose_mat[0]); + scale[1]= len_v3(pchan->pose_mat[1]); + scale[2]= len_v3(pchan->pose_mat[2]); if(fabs(scale[0] - scale[1]) > 1e-6f || fabs(scale[1] - scale[2]) > 1e-6f) { - Mat4One(scalemat); + unit_m4(scalemat); scalemat[0][0]= scale[0]; scalemat[1][1]= scale[1]; scalemat[2][2]= scale[2]; - Mat4Invert(iscalemat, scalemat); + invert_m4_m4(iscalemat, scalemat); length *= scale[1]; doscale = 1; @@ -559,15 +564,15 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) last point = (0, length, 0) */ if(rest) { - Mat4Invert(imat, pchan->bone->arm_mat); + invert_m4_m4(imat, pchan->bone->arm_mat); } else if(doscale) { - Mat4CpyMat4(posemat, pchan->pose_mat); - Mat4Ortho(posemat); - Mat4Invert(imat, posemat); + copy_m4_m4(posemat, pchan->pose_mat); + normalize_m4(posemat); + invert_m4_m4(imat, posemat); } else - Mat4Invert(imat, pchan->pose_mat); + invert_m4_m4(imat, pchan->pose_mat); if(prev) { float difmat[4][4], result[3][3], imat3[3][3]; @@ -577,7 +582,7 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) VECCOPY(h1, prev->bone->arm_head) else VECCOPY(h1, prev->pose_head) - Mat4MulVecfl(imat, h1); + mul_m4_v3(imat, h1); if(prev->bone->segments>1) { /* if previous bone is B-bone too, use average handle direction */ @@ -585,21 +590,21 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) roll1= 0.0f; } - Normalize(h1); - VecMulf(h1, -hlength1); + normalize_v3(h1); + mul_v3_fl(h1, -hlength1); if(prev->bone->segments==1) { /* find the previous roll to interpolate */ if(rest) - Mat4MulMat4(difmat, prev->bone->arm_mat, imat); + mul_m4_m4m4(difmat, prev->bone->arm_mat, imat); else - Mat4MulMat4(difmat, prev->pose_mat, imat); - Mat3CpyMat4(result, difmat); // the desired rotation at beginning of next bone + mul_m4_m4m4(difmat, prev->pose_mat, imat); + copy_m3_m4(result, difmat); // the desired rotation at beginning of next bone vec_roll_to_mat3(h1, 0.0f, mat3); // the result of vec_roll without roll - Mat3Inv(imat3, mat3); - Mat3MulMat3(mat3, result, imat3); // the matrix transforming vec_roll to desired roll + invert_m3_m3(imat3, mat3); + mul_m3_m3m3(mat3, result, imat3); // the matrix transforming vec_roll to desired roll roll1= (float)atan2(mat3[2][0], mat3[2][2]); } @@ -616,28 +621,28 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) VECCOPY(h2, next->bone->arm_tail) else VECCOPY(h2, next->pose_tail) - Mat4MulVecfl(imat, h2); + mul_m4_v3(imat, h2); /* if next bone is B-bone too, use average handle direction */ if(next->bone->segments>1); else h2[1]-= length; - Normalize(h2); + normalize_v3(h2); /* find the next roll to interpolate as well */ if(rest) - Mat4MulMat4(difmat, next->bone->arm_mat, imat); + mul_m4_m4m4(difmat, next->bone->arm_mat, imat); else - Mat4MulMat4(difmat, next->pose_mat, imat); - Mat3CpyMat4(result, difmat); // the desired rotation at beginning of next bone + mul_m4_m4m4(difmat, next->pose_mat, imat); + copy_m3_m4(result, difmat); // the desired rotation at beginning of next bone vec_roll_to_mat3(h2, 0.0f, mat3); // the result of vec_roll without roll - Mat3Inv(imat3, mat3); - Mat3MulMat3(mat3, imat3, result); // the matrix transforming vec_roll to desired roll + invert_m3_m3(imat3, mat3); + mul_m3_m3m3(mat3, imat3, result); // the matrix transforming vec_roll to desired roll roll2= (float)atan2(mat3[2][0], mat3[2][2]); /* and only now negate handle */ - VecMulf(h2, -hlength2); + mul_v3_fl(h2, -hlength2); } else { h2[0]= 0.0f; h2[1]= -hlength2; h2[2]= 0.0f; @@ -657,15 +662,15 @@ Mat4 *b_bone_spline_setup(bPoseChannel *pchan, int rest) /* make transformation matrices for the segments for drawing */ for(a=0, fp= data[0]; a<bone->segments; a++, fp+=4) { - VecSubf(h1, fp+4, fp); + sub_v3_v3v3(h1, fp+4, fp); vec_roll_to_mat3(h1, fp[3], mat3); // fp[3] is roll - Mat4CpyMat3(result_array[a].mat, mat3); + copy_m4_m3(result_array[a].mat, mat3); VECCOPY(result_array[a].mat[3], fp); if(doscale) { /* correct for scaling when this matrix is used in scaled space */ - Mat4MulSerie(result_array[a].mat, iscalemat, result_array[a].mat, + mul_serie_m4(result_array[a].mat, iscalemat, result_array[a].mat, scalemat, NULL, NULL, NULL, NULL, NULL); } } @@ -696,26 +701,26 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, int use_quaternion, int re /* first matrix is the inverse arm_mat, to bring points in local bone space for finding out which segment it belongs to */ - Mat4Invert(b_bone_mats[0].mat, bone->arm_mat); + invert_m4_m4(b_bone_mats[0].mat, bone->arm_mat); /* then we make the b_bone_mats: - first transform to local bone space - translate over the curve to the bbone mat space - transform with b_bone matrix - transform back into global space */ - Mat4One(tmat); + unit_m4(tmat); for(a=0; a<bone->segments; a++) { if(b_bone_rest) - Mat4Invert(tmat, b_bone_rest[a].mat); + invert_m4_m4(tmat, b_bone_rest[a].mat); else tmat[3][1] = -a*(bone->length/(float)bone->segments); - Mat4MulSerie(b_bone_mats[a+1].mat, pchan->chan_mat, bone->arm_mat, + mul_serie_m4(b_bone_mats[a+1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat, NULL, NULL, NULL); if(use_quaternion) - Mat4ToDQuat(bone->arm_mat, b_bone_mats[a+1].mat, &b_bone_dual_quats[a]); + mat4_to_dquat( &b_bone_dual_quats[a],bone->arm_mat, b_bone_mats[a+1].mat); } } @@ -738,13 +743,13 @@ static void b_bone_deform(bPoseChannel *pchan, Bone *bone, float *co, DualQuat * CLAMP(a, 0, bone->segments-1); if(dq) { - DQuatCpyDQuat(dq, &((DualQuat*)pchan->b_bone_dual_quats)[a]); + copy_dq_dq(dq, &((DualQuat*)pchan->b_bone_dual_quats)[a]); } else { - Mat4MulVecfl(b_bone[a+1].mat, co); + mul_m4_v3(b_bone[a+1].mat, co); if(defmat) - Mat3CpyMat4(defmat, b_bone[a+1].mat); + copy_m3_m4(defmat, b_bone[a+1].mat); } } @@ -756,10 +761,10 @@ float distfactor_to_bone (float vec[3], float b1[3], float b2[3], float rad1, fl float pdelta[3]; float hsqr, a, l, rad; - VecSubf (bdelta, b2, b1); - l = Normalize (bdelta); + sub_v3_v3v3(bdelta, b2, b1); + l = normalize_v3(bdelta); - VecSubf (pdelta, vec, b1); + sub_v3_v3v3(pdelta, vec, b1); a = bdelta[0]*pdelta[0] + bdelta[1]*pdelta[1] + bdelta[2]*pdelta[2]; hsqr = ((pdelta[0]*pdelta[0]) + (pdelta[1]*pdelta[1]) + (pdelta[2]*pdelta[2])); @@ -804,12 +809,12 @@ static void pchan_deform_mat_add(bPoseChannel *pchan, float weight, float bbonem float wmat[3][3]; if(pchan->bone->segments>1) - Mat3CpyMat3(wmat, bbonemat); + copy_m3_m3(wmat, bbonemat); else - Mat3CpyMat4(wmat, pchan->chan_mat); + copy_m3_m4(wmat, pchan->chan_mat); - Mat3MulFloat((float*)wmat, weight); - Mat3AddMat3(mat, mat, wmat); + mul_m3_fl(wmat, weight); + add_m3_m3m3(mat, mat, wmat); } static float dist_bone_deform(bPoseChannel *pchan, float *vec, DualQuat *dq, float mat[][3], float *co) @@ -835,12 +840,12 @@ static float dist_bone_deform(bPoseChannel *pchan, float *vec, DualQuat *dq, flo // applies on cop and bbonemat b_bone_deform(pchan, bone, cop, NULL, (mat)?bbonemat:NULL); else - Mat4MulVecfl(pchan->chan_mat, cop); + mul_m4_v3(pchan->chan_mat, cop); // Make this a delta from the base position - VecSubf (cop, cop, co); + sub_v3_v3v3(cop, cop, co); cop[0]*=fac; cop[1]*=fac; cop[2]*=fac; - VecAddf (vec, vec, cop); + add_v3_v3v3(vec, vec, cop); if(mat) pchan_deform_mat_add(pchan, fac, bbonemat, mat); @@ -848,10 +853,10 @@ static float dist_bone_deform(bPoseChannel *pchan, float *vec, DualQuat *dq, flo else { if(bone->segments>1) { b_bone_deform(pchan, bone, cop, &bbonedq, NULL); - DQuatAddWeighted(dq, &bbonedq, fac); + add_weighted_dq_dq(dq, &bbonedq, fac); } else - DQuatAddWeighted(dq, pchan->dual_quat, fac); + add_weighted_dq_dq(dq, pchan->dual_quat, fac); } } } @@ -874,7 +879,7 @@ static void pchan_bone_deform(bPoseChannel *pchan, float weight, float *vec, Dua // applies on cop and bbonemat b_bone_deform(pchan, pchan->bone, cop, NULL, (mat)?bbonemat:NULL); else - Mat4MulVecfl(pchan->chan_mat, cop); + mul_m4_v3(pchan->chan_mat, cop); vec[0]+=(cop[0]-co[0])*weight; vec[1]+=(cop[1]-co[1])*weight; @@ -886,10 +891,10 @@ static void pchan_bone_deform(bPoseChannel *pchan, float weight, float *vec, Dua else { if(pchan->bone->segments>1) { b_bone_deform(pchan, pchan->bone, cop, &bbonedq, NULL); - DQuatAddWeighted(dq, &bbonedq, weight); + add_weighted_dq_dq(dq, &bbonedq, weight); } else - DQuatAddWeighted(dq, pchan->dual_quat, weight); + add_weighted_dq_dq(dq, pchan->dual_quat, weight); } (*contrib)+=weight; @@ -918,10 +923,10 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, if(arm->edbo) return; - Mat4Invert(obinv, target->obmat); - Mat4CpyMat4(premat, target->obmat); - Mat4MulMat4(postmat, armOb->obmat, obinv); - Mat4Invert(premat, postmat); + invert_m4_m4(obinv, target->obmat); + copy_m4_m4(premat, target->obmat); + mul_m4_m4m4(postmat, armOb->obmat, obinv); + invert_m4_m4(premat, postmat); /* bone defmats are already in the channels, chan_mat */ @@ -939,7 +944,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, if(use_quaternion) { pchan->dual_quat= &dualquats[totchan++]; - Mat4ToDQuat(pchan->bone->arm_mat, pchan->chan_mat, pchan->dual_quat); + mat4_to_dquat( pchan->dual_quat,pchan->bone->arm_mat, pchan->chan_mat); } } } @@ -1008,7 +1013,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, vec= sumvec; if(defMats) { - Mat3Clr((float*)summat); + zero_m3(summat); smat = summat; } } @@ -1045,7 +1050,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, co= prevCos?prevCos[i]:vertexCos[i]; /* Apply the object's matrix */ - Mat4MulVecfl(premat, co); + mul_m4_v3(premat, co); if(use_dverts && dvert && dvert->totweight) { // use weight groups ? int deformed = 0; @@ -1091,42 +1096,42 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, /* actually should be EPSILON? weight values and contrib can be like 10e-39 small */ if(contrib > 0.0001f) { if(use_quaternion) { - DQuatNormalize(dq, contrib); + normalize_dq(dq, contrib); if(armature_weight != 1.0f) { VECCOPY(dco, co); - DQuatMulVecfl(dq, dco, (defMats)? summat: NULL); - VecSubf(dco, dco, co); - VecMulf(dco, armature_weight); - VecAddf(co, co, dco); + mul_v3m3_dq( dco, (defMats)? summat: NULL,dq); + sub_v3_v3v3(dco, dco, co); + mul_v3_fl(dco, armature_weight); + add_v3_v3v3(co, co, dco); } else - DQuatMulVecfl(dq, co, (defMats)? summat: NULL); + mul_v3m3_dq( co, (defMats)? summat: NULL,dq); smat = summat; } else { - VecMulf(vec, armature_weight/contrib); - VecAddf(co, vec, co); + mul_v3_fl(vec, armature_weight/contrib); + add_v3_v3v3(co, vec, co); } if(defMats) { float pre[3][3], post[3][3], tmpmat[3][3]; - Mat3CpyMat4(pre, premat); - Mat3CpyMat4(post, postmat); - Mat3CpyMat3(tmpmat, defMats[i]); + copy_m3_m4(pre, premat); + copy_m3_m4(post, postmat); + copy_m3_m3(tmpmat, defMats[i]); if(!use_quaternion) /* quaternion already is scale corrected */ - Mat3MulFloat((float*)smat, armature_weight/contrib); + mul_m3_fl(smat, armature_weight/contrib); - Mat3MulSerie(defMats[i], tmpmat, pre, smat, post, + mul_serie_m3(defMats[i], tmpmat, pre, smat, post, NULL, NULL, NULL, NULL); } } /* always, check above code */ - Mat4MulVecfl(postmat, co); + mul_m4_v3(postmat, co); /* interpolate with previous modifier position using weight group */ @@ -1160,7 +1165,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, void get_objectspace_bone_matrix (struct Bone* bone, float M_accumulatedMatrix[][4], int root, int posed) { - Mat4CpyMat4(M_accumulatedMatrix, bone->arm_mat); + copy_m4_m4(M_accumulatedMatrix, bone->arm_mat); } /* **************** Space to Space API ****************** */ @@ -1174,10 +1179,10 @@ void armature_mat_world_to_pose(Object *ob, float inmat[][4], float outmat[][4]) if (ob==NULL) return; /* get inverse of (armature) object's matrix */ - Mat4Invert(obmat, ob->obmat); + invert_m4_m4(obmat, ob->obmat); /* multiply given matrix by object's-inverse to find pose-space matrix */ - Mat4MulMat4(outmat, obmat, inmat); + mul_m4_m4m4(outmat, obmat, inmat); } /* Convert Wolrd-Space Location to Pose-Space Location @@ -1190,7 +1195,7 @@ void armature_loc_world_to_pose(Object *ob, float *inloc, float *outloc) float nLocMat[4][4]; /* build matrix for location */ - Mat4One(xLocMat); + unit_m4(xLocMat); VECCOPY(xLocMat[3], inloc); /* get bone-space cursor matrix and extract location */ @@ -1212,24 +1217,24 @@ void armature_mat_pose_to_bone(bPoseChannel *pchan, float inmat[][4], float outm /* get the inverse matrix of the pchan's transforms */ if (pchan->rotmode) - LocEulSizeToMat4(pc_trans, pchan->loc, pchan->eul, pchan->size); + loc_eul_size_to_mat4(pc_trans, pchan->loc, pchan->eul, pchan->size); else - LocQuatSizeToMat4(pc_trans, pchan->loc, pchan->quat, pchan->size); - Mat4Invert(inv_trans, pc_trans); + loc_quat_size_to_mat4(pc_trans, pchan->loc, pchan->quat, pchan->size); + invert_m4_m4(inv_trans, pc_trans); /* Remove the pchan's transforms from it's pose_mat. * This should leave behind the effects of restpose + * parenting + constraints */ - Mat4MulMat4(pc_posemat, inv_trans, pchan->pose_mat); + mul_m4_m4m4(pc_posemat, inv_trans, pchan->pose_mat); /* get the inverse of the leftovers so that we can remove * that component from the supplied matrix */ - Mat4Invert(inv_posemat, pc_posemat); + invert_m4_m4(inv_posemat, pc_posemat); /* get the new matrix */ - Mat4MulMat4(outmat, inmat, inv_posemat); + mul_m4_m4m4(outmat, inmat, inv_posemat); } /* Convert Pose-Space Location to Bone-Space Location @@ -1242,7 +1247,7 @@ void armature_loc_pose_to_bone(bPoseChannel *pchan, float *inloc, float *outloc) float nLocMat[4][4]; /* build matrix for location */ - Mat4One(xLocMat); + unit_m4(xLocMat); VECCOPY(xLocMat[3], inloc); /* get bone-space cursor matrix and extract location */ @@ -1258,8 +1263,8 @@ void armature_mat_pose_to_delta(float delta_mat[][4], float pose_mat[][4], float { float imat[4][4]; - Mat4Invert(imat, arm_mat); - Mat4MulMat4(delta_mat, pose_mat, imat); + invert_m4_m4(imat, arm_mat); + mul_m4_m4m4(delta_mat, pose_mat, imat); } /* **************** Rotation Mode Conversions ****************************** */ @@ -1275,33 +1280,33 @@ void BKE_rotMode_change_values (float quat[4], float eul[3], float axis[3], floa if (newMode > 0) { /* to euler */ if (oldMode == ROT_MODE_AXISANGLE) { /* axis-angle to euler */ - AxisAngleToEulO(axis, *angle, eul, newMode); + axis_angle_to_eulO( eul, newMode,axis, *angle); } else if (oldMode == ROT_MODE_QUAT) { /* quat to euler */ - QuatToEulO(quat, eul, newMode); + quat_to_eulO( eul, newMode,quat); } /* else { no conversion needed } */ } else if (newMode == ROT_MODE_QUAT) { /* to quat */ if (oldMode == ROT_MODE_AXISANGLE) { /* axis angle to quat */ - AxisAngleToQuat(quat, axis, *angle); + axis_angle_to_quat(quat, axis, *angle); } else if (oldMode > 0) { /* euler to quat */ - EulOToQuat(eul, oldMode, quat); + eulO_to_quat( quat,eul, oldMode); } /* else { no conversion needed } */ } else if (newMode == ROT_MODE_AXISANGLE) { /* to axis-angle */ if (oldMode > 0) { /* euler to axis angle */ - EulOToAxisAngle(eul, oldMode, axis, angle); + eulO_to_axis_angle( axis, angle,eul, oldMode); } else if (oldMode == ROT_MODE_QUAT) { /* quat to axis angle */ - QuatToAxisAngle(quat, axis, angle); + quat_to_axis_angle( axis, angle,quat); } /* when converting to axis-angle, we need a special exception for the case when there is no axis */ @@ -1336,14 +1341,14 @@ void BKE_rotMode_change_values (float quat[4], float eul[3], float axis[3], floa void mat3_to_vec_roll(float mat[][3], float *vec, float *roll) { if (vec) - VecCopyf(vec, mat[1]); + copy_v3_v3(vec, mat[1]); if (roll) { float vecmat[3][3], vecmatinv[3][3], rollmat[3][3]; vec_roll_to_mat3(mat[1], 0.0f, vecmat); - Mat3Inv(vecmatinv, vecmat); - Mat3MulMat3(rollmat, vecmatinv, mat); + invert_m3_m3(vecmatinv, vecmat); + mul_m3_m3m3(rollmat, vecmatinv, mat); *roll= (float)atan2(rollmat[2][0], rollmat[2][2]); } @@ -1358,26 +1363,26 @@ void vec_roll_to_mat3(float *vec, float roll, float mat[][3]) float rMatrix[3][3], bMatrix[3][3]; VECCOPY (nor, vec); - Normalize (nor); + normalize_v3(nor); /* Find Axis & Amount for bone matrix*/ - Crossf (axis,target,nor); + cross_v3_v3v3(axis,target,nor); - if (Inpf(axis,axis) > 0.0000000000001) { + if (dot_v3v3(axis,axis) > 0.0000000000001) { /* if nor is *not* a multiple of target ... */ - Normalize (axis); + normalize_v3(axis); - theta= NormalizedVecAngle2(target, nor); + theta= angle_normalized_v3v3(target, nor); /* Make Bone matrix*/ - VecRotToMat3(axis, theta, bMatrix); + vec_rot_to_mat3( bMatrix,axis, theta); } else { /* if nor is a multiple of target ... */ float updown; /* point same direction, or opposite? */ - updown = ( Inpf (target,nor) > 0 ) ? 1.0f : -1.0f; + updown = ( dot_v3v3(target,nor) > 0 ) ? 1.0f : -1.0f; /* I think this should work ... */ bMatrix[0][0]=updown; bMatrix[0][1]=0.0; bMatrix[0][2]=0.0; @@ -1386,10 +1391,10 @@ void vec_roll_to_mat3(float *vec, float roll, float mat[][3]) } /* Make Roll matrix*/ - VecRotToMat3(nor, roll, rMatrix); + vec_rot_to_mat3( rMatrix,nor, roll); /* Combine and output result*/ - Mat3MulMat3 (mat, rMatrix, bMatrix); + mul_m3_m3m3(mat, rMatrix, bMatrix); } @@ -1400,10 +1405,10 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) float vec[3]; /* Bone Space */ - VecSubf (vec, bone->tail, bone->head); + sub_v3_v3v3(vec, bone->tail, bone->head); vec_roll_to_mat3(vec, bone->roll, bone->bone_mat); - bone->length= VecLenf(bone->head, bone->tail); + bone->length= len_v3v3(bone->head, bone->tail); /* this is called on old file reading too... */ if(bone->xwidth==0.0) { @@ -1416,7 +1421,7 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) float offs_bone[4][4]; // yoffs(b-1) + root(b) + bonemat(b) /* bone transform itself */ - Mat4CpyMat3(offs_bone, bone->bone_mat); + copy_m4_m3(offs_bone, bone->bone_mat); /* The bone's root offset (is in the parent's coordinate system) */ VECCOPY(offs_bone[3], bone->head); @@ -1425,10 +1430,10 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) offs_bone[3][1]+= prevbone->length; /* Compose the matrix for this bone */ - Mat4MulMat4(bone->arm_mat, offs_bone, prevbone->arm_mat); + mul_m4_m4m4(bone->arm_mat, offs_bone, prevbone->arm_mat); } else { - Mat4CpyMat3(bone->arm_mat, bone->bone_mat); + copy_m4_m3(bone->arm_mat, bone->bone_mat); VECCOPY(bone->arm_mat[3], bone->head); } @@ -1436,8 +1441,8 @@ void where_is_armature_bone(Bone *bone, Bone *prevbone) VECCOPY(bone->arm_head, bone->arm_mat[3]); /* tail is in current local coord system */ VECCOPY(vec, bone->arm_mat[1]); - VecMulf(vec, bone->length); - VecAddf(bone->arm_tail, bone->arm_head, vec); + mul_v3_fl(vec, bone->length); + add_v3_v3v3(bone->arm_tail, bone->arm_head, vec); /* and the kiddies */ prevbone= bone; @@ -1689,8 +1694,6 @@ static void splineik_init_tree_from_pchan(Object *ob, bPoseChannel *pchan_tip) /* setup new empty array for the points list */ if (ikData->points) MEM_freeN(ikData->points); - // NOTE: just do chainlen+1 always for now, since we may get crashes otherwise - //ikData->numpoints= (ikData->flag & CONSTRAINT_SPLINEIK_NO_ROOT)? ikData->chainlen : ikData->chainlen+1; ikData->numpoints= ikData->chainlen+1; ikData->points= MEM_callocN(sizeof(float)*ikData->numpoints, "Spline IK Binding"); @@ -1704,7 +1707,7 @@ static void splineik_init_tree_from_pchan(Object *ob, bPoseChannel *pchan_tip) */ if ((ikData->flag & CONSTRAINT_SPLINEIK_EVENSPLITS) || (totLength == 0.0f)) { /* 1) equi-spaced joints */ - ikData->points[i]= segmentLen; + ikData->points[i]= ikData->points[i-1] - segmentLen; } else { /* 2) to find this point on the curve, we take a step from the previous joint @@ -1749,6 +1752,7 @@ static void splineik_init_tree_from_pchan(Object *ob, bPoseChannel *pchan_tip) maxScale = totLength / splineLen; /* apply scaling correction to all of the temporary points */ + // TODO: this is really not adequate enough on really short chains for (i = 0; i < segcount; i++) jointPoints[i] *= maxScale; } @@ -1807,9 +1811,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o { bSplineIKConstraint *ikData= tree->ikData; float poseHead[3], poseTail[3], poseMat[4][4]; - float splineVec[3], scaleFac; - float rad, radius=1.0f; - float vec[4], dir[3]; + float splineVec[3], scaleFac, radius=1.0f; /* firstly, calculate the bone matrix the standard way, since this is needed for roll control */ where_is_pose_bone(scene, ob, pchan, ctime); @@ -1817,39 +1819,49 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o VECCOPY(poseHead, pchan->pose_head); VECCOPY(poseTail, pchan->pose_tail); - /* step 1a: get xyz positions for the tail endpoint of the bone */ - if ( where_on_path(ikData->tar, tree->points[index], vec, dir, NULL, &rad) ) { - /* convert the position to pose-space, then store it */ - Mat4MulVecfl(ob->imat, vec); - VECCOPY(poseTail, vec); + /* step 1: determine the positions for the endpoints of the bone */ + { + float vec[4], dir[3], rad; + float tailBlendFac= 1.0f; + + /* determine if the bone should still be affected by SplineIK */ + if (tree->points[index+1] >= 1.0f) { + /* spline doesn't affect the bone anymore, so done... */ + pchan->flag |= POSE_DONE; + return; + } + else if ((tree->points[index] >= 1.0f) && (tree->points[index+1] < 1.0f)) { + /* blending factor depends on the amount of the bone still left on the chain */ + tailBlendFac= (1.0f - tree->points[index+1]) / (tree->points[index] - tree->points[index+1]); + } - /* set the new radius */ - radius= rad; - } - - /* step 1b: get xyz positions for the head endpoint of the bone */ - /* firstly, calculate the position that the path suggests */ - if ( where_on_path(ikData->tar, tree->points[index+1], vec, dir, NULL, &rad) ) { - /* store the position, and convert it to pose space */ - Mat4MulVecfl(ob->imat, vec); - VECCOPY(poseHead, vec); + /* tail endpoint */ + if ( where_on_path(ikData->tar, tree->points[index], vec, dir, NULL, &rad) ) { + /* convert the position to pose-space, then store it */ + mul_m4_v3(ob->imat, vec); + interp_v3_v3v3(poseTail, pchan->pose_tail, vec, tailBlendFac); + + /* set the new radius */ + radius= rad; + } - /* set the new radius (it should be the average value) */ - radius = (radius+rad) / 2; - } - if ((ikData->flag & CONSTRAINT_SPLINEIK_NO_ROOT) && (pchan == tree->root)) - { - // this is the root bone, and it can be controlled however we like... - // TODO: how do we calculate the offset of the root, if we don't even know the binding? - VECCOPY(poseHead, pchan->pose_head); + /* head endpoint */ + if ( where_on_path(ikData->tar, tree->points[index+1], vec, dir, NULL, &rad) ) { + /* store the position, and convert it to pose space */ + mul_m4_v3(ob->imat, vec); + VECCOPY(poseHead, vec); + + /* set the new radius (it should be the average value) */ + radius = (radius+rad) / 2; + } } /* step 2: determine the implied transform from these endpoints * - splineVec: the vector direction that the spline applies on the bone * - scaleFac: the factor that the bone length is scaled by to get the desired amount */ - VecSubf(splineVec, poseTail, poseHead); - scaleFac= VecLength(splineVec) / pchan->bone->length; + sub_v3_v3v3(splineVec, poseTail, poseHead); + scaleFac= len_v3(splineVec) / pchan->bone->length; /* step 3: compute the shortest rotation needed to map from the bone rotation to the current axis * - this uses the same method as is used for the Damped Track Constraint (see the code there for details) @@ -1864,45 +1876,45 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o VECCOPY(rmat[0], pchan->pose_mat[0]); VECCOPY(rmat[1], pchan->pose_mat[1]); VECCOPY(rmat[2], pchan->pose_mat[2]); - Mat3Ortho(rmat); + normalize_m3(rmat); /* also, normalise the orientation imposed by the bone, now that we've extracted the scale factor */ - Normalize(splineVec); + normalize_v3(splineVec); /* calculate smallest axis-angle rotation necessary for getting from the * current orientation of the bone, to the spline-imposed direction */ - Crossf(raxis, rmat[1], splineVec); + cross_v3_v3v3(raxis, rmat[1], splineVec); - rangle= Inpf(rmat[1], splineVec); + rangle= dot_v3v3(rmat[1], splineVec); rangle= acos( MAX2(-1.0f, MIN2(1.0f, rangle)) ); /* construct rotation matrix from the axis-angle rotation found above * - this call takes care to make sure that the axis provided is a unit vector first */ - AxisAngleToMat3(raxis, rangle, dmat); + axis_angle_to_mat3( dmat,raxis, rangle); /* combine these rotations so that the y-axis of the bone is now aligned as the spline dictates, * while still maintaining roll control from the existing bone animation */ - Mat3MulMat3(tmat, dmat, rmat); // m1, m3, m2 - Mat3Ortho(tmat); /* attempt to reduce shearing, though I doubt this'll really help too much now... */ - Mat4CpyMat3(poseMat, tmat); + mul_m3_m3m3(tmat, dmat, rmat); // m1, m3, m2 + normalize_m3(tmat); /* attempt to reduce shearing, though I doubt this'll really help too much now... */ + copy_m4_m3(poseMat, tmat); } /* step 4: set the scaling factors for the axes */ // TODO: include a no-scale option? { /* only multiply the y-axis by the scaling factor to get nice volume-preservation */ - VecMulf(poseMat[1], scaleFac); + mul_v3_fl(poseMat[1], scaleFac); /* set the scaling factors of the x and z axes from... */ switch (ikData->xzScaleMode) { case CONSTRAINT_SPLINEIK_XZS_RADIUS: { /* radius of curve */ - VecMulf(poseMat[0], radius); - VecMulf(poseMat[2], radius); + mul_v3_fl(poseMat[0], radius); + mul_v3_fl(poseMat[2], radius); } break; case CONSTRAINT_SPLINEIK_XZS_ORIGINAL: @@ -1911,21 +1923,29 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o float scale; /* x-axis scale */ - scale= VecLength(pchan->pose_mat[0]); - VecMulf(poseMat[0], scale); + scale= len_v3(pchan->pose_mat[0]); + mul_v3_fl(poseMat[0], scale); /* z-axis scale */ - scale= VecLength(pchan->pose_mat[2]); - VecMulf(poseMat[2], scale); + scale= len_v3(pchan->pose_mat[2]); + mul_v3_fl(poseMat[2], scale); } break; } } - /* step 5: set the location of the bone in the matrix */ - VECCOPY(poseMat[3], pchan->pose_head); + /* step 5: set the location of the bone in the matrix + * - when the 'no-root' option is affected, the chain can retain + * the shape but be moved elsewhere + */ + if (ikData->flag & CONSTRAINT_SPLINEIK_NO_ROOT) { + VECCOPY(poseMat[3], pchan->pose_head); + } + else { + VECCOPY(poseMat[3], poseHead); + } /* finally, store the new transform */ - Mat4CpyMat4(pchan->pose_mat, poseMat); + copy_m4_m4(pchan->pose_mat, poseMat); VECCOPY(pchan->pose_head, poseHead); VECCOPY(pchan->pose_tail, poseTail); @@ -1977,26 +1997,26 @@ void chan_calc_mat(bPoseChannel *chan) float tmat[3][3]; /* get scaling matrix */ - SizeToMat3(chan->size, smat); + size_to_mat3( smat,chan->size); /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ if (chan->rotmode > 0) { /* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */ - EulOToMat3(chan->eul, chan->rotmode, rmat); + eulO_to_mat3( rmat,chan->eul, chan->rotmode); } else if (chan->rotmode == ROT_MODE_AXISANGLE) { /* axis-angle - not really that great for 3D-changing orientations */ - AxisAngleToMat3(chan->rotAxis, chan->rotAngle, rmat); + axis_angle_to_mat3( rmat,chan->rotAxis, chan->rotAngle); } else { /* quats are normalised before use to eliminate scaling issues */ - NormalQuat(chan->quat); // TODO: do this with local vars only! - QuatToMat3(chan->quat, rmat); + normalize_qt(chan->quat); // TODO: do this with local vars only! + quat_to_mat3( rmat,chan->quat); } /* calculate matrix of bone (as 3x3 matrix, but then copy the 4x4) */ - Mat3MulMat3(tmat, rmat, smat); - Mat4CpyMat3(chan->chan_mat, tmat); + mul_m3_m3m3(tmat, rmat, smat); + copy_m4_m3(chan->chan_mat, tmat); /* prevent action channels breaking chains */ /* need to check for bone here, CONSTRAINT_TYPE_ACTION uses this call */ @@ -2060,8 +2080,8 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha float mat4[4][4], mat3[3][3]; curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis); - Mat4CpyMat4(mat4, pchan->pose_mat); - Mat4MulMat34(pchan->pose_mat, mat3, mat4); + copy_m4_m4(mat4, pchan->pose_mat); + mul_m4_m3m4(pchan->pose_mat, mat3, mat4); } } @@ -2078,8 +2098,8 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha /* make a copy of starting conditions */ VECCOPY(loc, pchan->pose_mat[3]); - Mat4ToEul(pchan->pose_mat, eul); - Mat4ToSize(pchan->pose_mat, size); + mat4_to_eul( eul,pchan->pose_mat); + mat4_to_size( size,pchan->pose_mat); VECCOPY(eulo, eul); VECCOPY(sizeo, size); @@ -2089,14 +2109,14 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha nor[0] = BLI_gNoise(amod->noisesize, size[0]+ofs, size[1], size[2], 0, 0) - ofs; nor[1] = BLI_gNoise(amod->noisesize, size[0], size[1]+ofs, size[2], 0, 0) - ofs; nor[2] = BLI_gNoise(amod->noisesize, size[0], size[1], size[2]+ofs, 0, 0) - ofs; - VecAddf(size, size, nor); + add_v3_v3v3(size, size, nor); if (sizeo[0] != 0) - VecMulf(pchan->pose_mat[0], size[0] / sizeo[0]); + mul_v3_fl(pchan->pose_mat[0], size[0] / sizeo[0]); if (sizeo[1] != 0) - VecMulf(pchan->pose_mat[1], size[1] / sizeo[1]); + mul_v3_fl(pchan->pose_mat[1], size[1] / sizeo[1]); if (sizeo[2] != 0) - VecMulf(pchan->pose_mat[2], size[2] / sizeo[2]); + mul_v3_fl(pchan->pose_mat[2], size[2] / sizeo[2]); } if (amod->channels & 2) { /* for rotation */ @@ -2105,10 +2125,10 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha nor[2] = BLI_gNoise(amod->noisesize, eul[0], eul[1], eul[2]+ofs, 0, 0) - ofs; compatible_eul(nor, eulo); - VecAddf(eul, eul, nor); + add_v3_v3v3(eul, eul, nor); compatible_eul(eul, eulo); - LocEulSizeToMat4(pchan->pose_mat, loc, eul, size); + loc_eul_size_to_mat4(pchan->pose_mat, loc, eul, size); } if (amod->channels & 1) { /* for location */ @@ -2116,7 +2136,7 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha nor[1] = BLI_gNoise(amod->noisesize, loc[0], loc[1]+ofs, loc[2], 0, 0) - ofs; nor[2] = BLI_gNoise(amod->noisesize, loc[0], loc[1], loc[2]+ofs, 0, 0) - ofs; - VecAddf(pchan->pose_mat[3], loc, nor); + add_v3_v3v3(pchan->pose_mat[3], loc, nor); } } } @@ -2151,7 +2171,7 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti float offs_bone[4][4]; // yoffs(b-1) + root(b) + bonemat(b) /* bone transform itself */ - Mat4CpyMat3(offs_bone, bone->bone_mat); + copy_m4_m3(offs_bone, bone->bone_mat); /* The bone's root offset (is in the parent's coordinate system) */ VECCOPY(offs_bone[3], bone->head); @@ -2164,39 +2184,39 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti float tmat[4][4]; /* the rotation of the parent restposition */ - Mat4CpyMat4(tmat, parbone->arm_mat); + copy_m4_m4(tmat, parbone->arm_mat); /* the location of actual parent transform */ VECCOPY(tmat[3], offs_bone[3]); offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f; - Mat4MulVecfl(parchan->pose_mat, tmat[3]); + mul_m4_v3(parchan->pose_mat, tmat[3]); - Mat4MulSerie(pchan->pose_mat, tmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(pchan->pose_mat, tmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); } else if(bone->flag & BONE_NO_SCALE) { float orthmat[4][4]; /* get the official transform, but we only use the vector from it (optimize...) */ - Mat4MulSerie(pchan->pose_mat, parchan->pose_mat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(pchan->pose_mat, parchan->pose_mat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); VECCOPY(vec, pchan->pose_mat[3]); /* do this again, but with an ortho-parent matrix */ - Mat4CpyMat4(orthmat, parchan->pose_mat); - Mat4Ortho(orthmat); - Mat4MulSerie(pchan->pose_mat, orthmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); + copy_m4_m4(orthmat, parchan->pose_mat); + normalize_m4(orthmat); + mul_serie_m4(pchan->pose_mat, orthmat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); /* copy correct transform */ VECCOPY(pchan->pose_mat[3], vec); } else - Mat4MulSerie(pchan->pose_mat, parchan->pose_mat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(pchan->pose_mat, parchan->pose_mat, offs_bone, pchan->chan_mat, NULL, NULL, NULL, NULL, NULL); } else { - Mat4MulMat4(pchan->pose_mat, pchan->chan_mat, bone->arm_mat); + mul_m4_m4m4(pchan->pose_mat, pchan->chan_mat, bone->arm_mat); /* only rootbones get the cyclic offset (unless user doesn't want that) */ if ((bone->flag & BONE_NO_CYCLICOFFSET) == 0) - VecAddf(pchan->pose_mat[3], pchan->pose_mat[3], ob->pose->cyclic_offset); + add_v3_v3v3(pchan->pose_mat[3], pchan->pose_mat[3], ob->pose->cyclic_offset); } /* do NLA strip modifiers - i.e. curve follow */ @@ -2232,8 +2252,8 @@ void where_is_pose_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float cti VECCOPY(pchan->pose_head, pchan->pose_mat[3]); /* calculate tail */ VECCOPY(vec, pchan->pose_mat[1]); - VecMulf(vec, bone->length); - VecAddf(pchan->pose_tail, pchan->pose_head, vec); + mul_v3_fl(vec, bone->length); + add_v3_v3v3(pchan->pose_tail, pchan->pose_head, vec); } /* This only reads anim data from channels, and writes to channels */ @@ -2261,14 +2281,14 @@ void where_is_pose (Scene *scene, Object *ob) for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { bone= pchan->bone; if(bone) { - Mat4CpyMat4(pchan->pose_mat, bone->arm_mat); + copy_m4_m4(pchan->pose_mat, bone->arm_mat); VECCOPY(pchan->pose_head, bone->arm_head); VECCOPY(pchan->pose_tail, bone->arm_tail); } } } else { - Mat4Invert(ob->imat, ob->obmat); // imat is needed + invert_m4_m4(ob->imat, ob->obmat); // imat is needed /* 1. clear flags */ for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { @@ -2306,8 +2326,8 @@ void where_is_pose (Scene *scene, Object *ob) /* calculating deform matrices */ for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if(pchan->bone) { - Mat4Invert(imat, pchan->bone->arm_mat); - Mat4MulMat4(pchan->chan_mat, imat, pchan->pose_mat); + invert_m4_m4(imat, pchan->bone->arm_mat); + mul_m4_m4m4(pchan->chan_mat, imat, pchan->pose_mat); } } } diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index 712fb13cfc0..389009cca76 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -43,7 +43,7 @@ #include "DNA_listBase.h" #include "BLI_rand.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_kdtree.h" #include "BLI_kdopbvh.h" @@ -135,10 +135,10 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, /* estimate future location of target */ get_effector_data(eff, &efd, &epoint, 1); - VecMulf(efd.vel, efd.distance / (val->max_speed * bbd->timestep)); - VecAddf(efd.loc, efd.loc, efd.vel); - VecSubf(efd.vec_to_point, pa->prev_state.co, efd.loc); - efd.distance = VecLength(efd.vec_to_point); + mul_v3_fl(efd.vel, efd.distance / (val->max_speed * bbd->timestep)); + add_v3_v3v3(efd.loc, efd.loc, efd.vel); + sub_v3_v3v3(efd.vec_to_point, pa->prev_state.co, efd.loc); + efd.distance = len_v3(efd.vec_to_point); } if(rule->type == eBoidRuleType_Goal && boids->options & BOID_ALLOW_CLIMB && surface!=0.0f) { @@ -152,17 +152,17 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, priority > 2.0f * gabr->fear_factor) { /* detach from surface and try to fly away from danger */ VECCOPY(efd.vec_to_point, bpa->gravity); - VecMulf(efd.vec_to_point, -1.0f); + mul_v3_fl(efd.vec_to_point, -1.0f); } VECCOPY(bbd->wanted_co, efd.vec_to_point); - VecMulf(bbd->wanted_co, mul); + mul_v3_fl(bbd->wanted_co, mul); bbd->wanted_speed = val->max_speed * priority; /* with goals factor is approach velocity factor */ if(rule->type == eBoidRuleType_Goal && boids->landing_smoothness > 0.0f) { - float len2 = 2.0f*VecLength(pa->prev_state.vel); + float len2 = 2.0f*len_v3(pa->prev_state.vel); surface *= pa->size * boids->height; @@ -198,12 +198,12 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * float radius = val->personal_space * pa->size, ray_dir[3]; VECCOPY(col.co1, pa->prev_state.co); - VecAddf(col.co2, pa->prev_state.co, pa->prev_state.vel); - VecSubf(ray_dir, col.co2, col.co1); - VecMulf(ray_dir, acbr->look_ahead); + add_v3_v3v3(col.co2, pa->prev_state.co, pa->prev_state.vel); + sub_v3_v3v3(ray_dir, col.co2, col.co1); + mul_v3_fl(ray_dir, acbr->look_ahead); col.t = 0.0f; hit.index = -1; - hit.dist = col.ray_len = VecLength(ray_dir); + hit.dist = col.ray_len = len_v3(ray_dir); /* find out closest deflector object */ for(coll = bbd->sim->colliders->first; coll; coll=coll->next) { @@ -224,9 +224,9 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * VECCOPY(bbd->wanted_co, col.nor); - VecMulf(bbd->wanted_co, (1.0f - t) * val->personal_space * pa->size); + mul_v3_fl(bbd->wanted_co, (1.0f - t) * val->personal_space * pa->size); - bbd->wanted_speed = sqrt(t) * VecLength(pa->prev_state.vel); + bbd->wanted_speed = sqrt(t) * len_v3(pa->prev_state.vel); return 1; } @@ -235,39 +235,39 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * //check boids in own system if(acbr->options & BRULE_ACOLL_WITH_BOIDS) { - neighbors = BLI_kdtree_range_search(bbd->sim->psys->tree, acbr->look_ahead * VecLength(pa->prev_state.vel), pa->prev_state.co, pa->prev_state.ave, &ptn); + neighbors = BLI_kdtree_range_search(bbd->sim->psys->tree, acbr->look_ahead * len_v3(pa->prev_state.vel), pa->prev_state.co, pa->prev_state.ave, &ptn); if(neighbors > 1) for(n=1; n<neighbors; n++) { VECCOPY(co1, pa->prev_state.co); VECCOPY(vel1, pa->prev_state.vel); VECCOPY(co2, (bbd->sim->psys->particles + ptn[n].index)->prev_state.co); VECCOPY(vel2, (bbd->sim->psys->particles + ptn[n].index)->prev_state.vel); - VecSubf(loc, co1, co2); + sub_v3_v3v3(loc, co1, co2); - VecSubf(vec, vel1, vel2); + sub_v3_v3v3(vec, vel1, vel2); - inp = Inpf(vec,vec); + inp = dot_v3v3(vec,vec); /* velocities not parallel */ if(inp != 0.0f) { - t = -Inpf(loc, vec)/inp; + t = -dot_v3v3(loc, vec)/inp; /* cpa is not too far in the future so investigate further */ if(t > 0.0f && t < t_min) { VECADDFAC(co1, co1, vel1, t); VECADDFAC(co2, co2, vel2, t); - VecSubf(vec, co2, co1); + sub_v3_v3v3(vec, co2, co1); - len = Normalize(vec); + len = normalize_v3(vec); /* distance of cpa is close enough */ if(len < 2.0f * val->personal_space * pa->size) { t_min = t; - VecMulf(vec, VecLength(vel1)); - VecMulf(vec, (2.0f - t)/2.0f); - VecSubf(bbd->wanted_co, vel1, vec); - bbd->wanted_speed = VecLength(bbd->wanted_co); + mul_v3_fl(vec, len_v3(vel1)); + mul_v3_fl(vec, (2.0f - t)/2.0f); + sub_v3_v3v3(bbd->wanted_co, vel1, vec); + bbd->wanted_speed = len_v3(bbd->wanted_co); ret = 1; } } @@ -281,39 +281,39 @@ static int rule_avoid_collision(BoidRule *rule, BoidBrainData *bbd, BoidValues * ParticleSystem *epsys = psys_get_target_system(bbd->sim->ob, pt); if(epsys) { - neighbors = BLI_kdtree_range_search(epsys->tree, acbr->look_ahead * VecLength(pa->prev_state.vel), pa->prev_state.co, pa->prev_state.ave, &ptn); + neighbors = BLI_kdtree_range_search(epsys->tree, acbr->look_ahead * len_v3(pa->prev_state.vel), pa->prev_state.co, pa->prev_state.ave, &ptn); if(neighbors > 0) for(n=0; n<neighbors; n++) { VECCOPY(co1, pa->prev_state.co); VECCOPY(vel1, pa->prev_state.vel); VECCOPY(co2, (epsys->particles + ptn[n].index)->prev_state.co); VECCOPY(vel2, (epsys->particles + ptn[n].index)->prev_state.vel); - VecSubf(loc, co1, co2); + sub_v3_v3v3(loc, co1, co2); - VecSubf(vec, vel1, vel2); + sub_v3_v3v3(vec, vel1, vel2); - inp = Inpf(vec,vec); + inp = dot_v3v3(vec,vec); /* velocities not parallel */ if(inp != 0.0f) { - t = -Inpf(loc, vec)/inp; + t = -dot_v3v3(loc, vec)/inp; /* cpa is not too far in the future so investigate further */ if(t > 0.0f && t < t_min) { VECADDFAC(co1, co1, vel1, t); VECADDFAC(co2, co2, vel2, t); - VecSubf(vec, co2, co1); + sub_v3_v3v3(vec, co2, co1); - len = Normalize(vec); + len = normalize_v3(vec); /* distance of cpa is close enough */ if(len < 2.0f * val->personal_space * pa->size) { t_min = t; - VecMulf(vec, VecLength(vel1)); - VecMulf(vec, (2.0f - t)/2.0f); - VecSubf(bbd->wanted_co, vel1, vec); - bbd->wanted_speed = VecLength(bbd->wanted_co); + mul_v3_fl(vec, len_v3(vel1)); + mul_v3_fl(vec, (2.0f - t)/2.0f); + sub_v3_v3v3(bbd->wanted_co, vel1, vec); + bbd->wanted_speed = len_v3(bbd->wanted_co); ret = 1; } } @@ -340,9 +340,9 @@ static int rule_separate(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Pa int ret = 0; if(neighbors > 1 && ptn[1].dist!=0.0f) { - VecSubf(vec, pa->prev_state.co, bbd->sim->psys->particles[ptn[1].index].state.co); - VecMulf(vec, (2.0f * val->personal_space * pa->size - ptn[1].dist) / ptn[1].dist); - VecAddf(bbd->wanted_co, bbd->wanted_co, vec); + sub_v3_v3v3(vec, pa->prev_state.co, bbd->sim->psys->particles[ptn[1].index].state.co); + mul_v3_fl(vec, (2.0f * val->personal_space * pa->size - ptn[1].dist) / ptn[1].dist); + add_v3_v3v3(bbd->wanted_co, bbd->wanted_co, vec); bbd->wanted_speed = val->max_speed; len = ptn[1].dist; ret = 1; @@ -357,9 +357,9 @@ static int rule_separate(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Pa neighbors = BLI_kdtree_range_search(epsys->tree, 2.0f * val->personal_space * pa->size, pa->prev_state.co, NULL, &ptn); if(neighbors > 0 && ptn[0].dist < len) { - VecSubf(vec, pa->prev_state.co, ptn[0].co); - VecMulf(vec, (2.0f * val->personal_space * pa->size - ptn[0].dist) / ptn[1].dist); - VecAddf(bbd->wanted_co, bbd->wanted_co, vec); + sub_v3_v3v3(vec, pa->prev_state.co, ptn[0].co); + mul_v3_fl(vec, (2.0f * val->personal_space * pa->size - ptn[0].dist) / ptn[1].dist); + add_v3_v3v3(bbd->wanted_co, bbd->wanted_co, vec); bbd->wanted_speed = val->max_speed; len = ptn[0].dist; ret = 1; @@ -380,19 +380,19 @@ static int rule_flock(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti if(neighbors > 1) { for(n=1; n<neighbors; n++) { - VecAddf(loc, loc, bbd->sim->psys->particles[ptn[n].index].prev_state.co); - VecAddf(vec, vec, bbd->sim->psys->particles[ptn[n].index].prev_state.vel); + add_v3_v3v3(loc, loc, bbd->sim->psys->particles[ptn[n].index].prev_state.co); + add_v3_v3v3(vec, vec, bbd->sim->psys->particles[ptn[n].index].prev_state.vel); } - VecMulf(loc, 1.0f/((float)neighbors - 1.0f)); - VecMulf(vec, 1.0f/((float)neighbors - 1.0f)); + mul_v3_fl(loc, 1.0f/((float)neighbors - 1.0f)); + mul_v3_fl(vec, 1.0f/((float)neighbors - 1.0f)); - VecSubf(loc, loc, pa->prev_state.co); - VecSubf(vec, vec, pa->prev_state.vel); + sub_v3_v3v3(loc, loc, pa->prev_state.co); + sub_v3_v3v3(vec, vec, pa->prev_state.vel); - VecAddf(bbd->wanted_co, bbd->wanted_co, vec); - VecAddf(bbd->wanted_co, bbd->wanted_co, loc); - bbd->wanted_speed = VecLength(bbd->wanted_co); + add_v3_v3v3(bbd->wanted_co, bbd->wanted_co, vec); + add_v3_v3v3(bbd->wanted_co, bbd->wanted_co, loc); + bbd->wanted_speed = len_v3(bbd->wanted_co); ret = 1; } @@ -410,16 +410,16 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va float vec2[3], t; /* first check we're not blocking the leader*/ - VecSubf(vec, flbr->loc, flbr->oloc); - VecMulf(vec, 1.0f/bbd->timestep); + sub_v3_v3v3(vec, flbr->loc, flbr->oloc); + mul_v3_fl(vec, 1.0f/bbd->timestep); - VecSubf(loc, pa->prev_state.co, flbr->oloc); + sub_v3_v3v3(loc, pa->prev_state.co, flbr->oloc); - mul = Inpf(vec, vec); + mul = dot_v3v3(vec, vec); /* leader is not moving */ if(mul < 0.01) { - len = VecLength(loc); + len = len_v3(loc); /* too close to leader */ if(len < 2.0f * val->personal_space * pa->size) { VECCOPY(bbd->wanted_co, loc); @@ -428,16 +428,16 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va } } else { - t = Inpf(loc, vec)/mul; + t = dot_v3v3(loc, vec)/mul; /* possible blocking of leader in near future */ if(t > 0.0f && t < 3.0f) { VECCOPY(vec2, vec); - VecMulf(vec2, t); + mul_v3_fl(vec2, t); - VecSubf(vec2, loc, vec2); + sub_v3_v3v3(vec2, loc, vec2); - len = VecLength(vec2); + len = len_v3(vec2); if(len < 2.0f * val->personal_space * pa->size) { VECCOPY(bbd->wanted_co, vec2); @@ -454,15 +454,15 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va } else { VECCOPY(loc, flbr->oloc); - VecSubf(vec, flbr->loc, flbr->oloc); - VecMulf(vec, 1.0/bbd->timestep); + sub_v3_v3v3(vec, flbr->loc, flbr->oloc); + mul_v3_fl(vec, 1.0/bbd->timestep); } /* fac is seconds behind leader */ VECADDFAC(loc, loc, vec, -flbr->distance); - VecSubf(bbd->wanted_co, loc, pa->prev_state.co); - bbd->wanted_speed = VecLength(bbd->wanted_co); + sub_v3_v3v3(bbd->wanted_co, loc, pa->prev_state.co); + bbd->wanted_speed = len_v3(bbd->wanted_co); ret = 1; } @@ -473,13 +473,13 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va for(i = 0; i< bbd->sim->psys->totpart; i+=n){ VECCOPY(vec, bbd->sim->psys->particles[i].prev_state.vel); - VecSubf(loc, pa->prev_state.co, bbd->sim->psys->particles[i].prev_state.co); + sub_v3_v3v3(loc, pa->prev_state.co, bbd->sim->psys->particles[i].prev_state.co); - mul = Inpf(vec, vec); + mul = dot_v3v3(vec, vec); /* leader is not moving */ if(mul < 0.01) { - len = VecLength(loc); + len = len_v3(loc); /* too close to leader */ if(len < 2.0f * val->personal_space * pa->size) { VECCOPY(bbd->wanted_co, loc); @@ -488,16 +488,16 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va } } else { - t = Inpf(loc, vec)/mul; + t = dot_v3v3(loc, vec)/mul; /* possible blocking of leader in near future */ if(t > 0.0f && t < t_min) { VECCOPY(vec2, vec); - VecMulf(vec2, t); + mul_v3_fl(vec2, t); - VecSubf(vec2, loc, vec2); + sub_v3_v3v3(vec2, loc, vec2); - len = VecLength(vec2); + len = len_v3(vec2); if(len < 2.0f * val->personal_space * pa->size) { t_min = t; @@ -524,8 +524,8 @@ static int rule_follow_leader(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* fac is seconds behind leader */ VECADDFAC(loc, loc, vec, -flbr->distance); - VecSubf(bbd->wanted_co, loc, pa->prev_state.co); - bbd->wanted_speed = VecLength(bbd->wanted_co); + sub_v3_v3v3(bbd->wanted_co, loc, pa->prev_state.co); + bbd->wanted_speed = len_v3(bbd->wanted_co); ret = 1; } @@ -544,30 +544,30 @@ static int rule_average_speed(BoidRule *rule, BoidBrainData *bbd, BoidValues *va bpa->wander[1] += asbr->wander * (-1.0f + 2.0f * BLI_frand()); bpa->wander[2] += asbr->wander * (-1.0f + 2.0f * BLI_frand()); - Normalize(bpa->wander); + normalize_v3(bpa->wander); VECCOPY(vec, bpa->wander); - QuatMulVecf(pa->prev_state.rot, vec); + mul_qt_v3(pa->prev_state.rot, vec); VECCOPY(bbd->wanted_co, pa->prev_state.ave); - VecMulf(bbd->wanted_co, 1.1f); + mul_v3_fl(bbd->wanted_co, 1.1f); - VecAddf(bbd->wanted_co, bbd->wanted_co, vec); + add_v3_v3v3(bbd->wanted_co, bbd->wanted_co, vec); /* leveling */ if(asbr->level > 0.0f) { - Projf(vec, bbd->wanted_co, bbd->sim->psys->part->acc); - VecMulf(vec, asbr->level); - VecSubf(bbd->wanted_co, bbd->wanted_co, vec); + project_v3_v3v3(vec, bbd->wanted_co, bbd->sim->psys->part->acc); + mul_v3_fl(vec, asbr->level); + sub_v3_v3v3(bbd->wanted_co, bbd->wanted_co, vec); } } else { VECCOPY(bbd->wanted_co, pa->prev_state.ave); /* may happen at birth */ - if(Inp2f(bbd->wanted_co,bbd->wanted_co)==0.0f) { + if(dot_v2v2(bbd->wanted_co,bbd->wanted_co)==0.0f) { bbd->wanted_co[0] = 2.0f*(0.5f - BLI_frand()); bbd->wanted_co[1] = 2.0f*(0.5f - BLI_frand()); bbd->wanted_co[2] = 2.0f*(0.5f - BLI_frand()); @@ -575,9 +575,9 @@ static int rule_average_speed(BoidRule *rule, BoidBrainData *bbd, BoidValues *va /* leveling */ if(asbr->level > 0.0f) { - Projf(vec, bbd->wanted_co, bbd->sim->psys->part->acc); - VecMulf(vec, asbr->level); - VecSubf(bbd->wanted_co, bbd->wanted_co, vec); + project_v3_v3v3(vec, bbd->wanted_co, bbd->sim->psys->part->acc); + mul_v3_fl(vec, asbr->level); + sub_v3_v3v3(bbd->wanted_co, bbd->wanted_co, vec); } } @@ -641,20 +641,20 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti } /* decide action if enemy presence found */ if(e_strength > 0.0f) { - VecSubf(bbd->wanted_co, closest_enemy, pa->prev_state.co); + sub_v3_v3v3(bbd->wanted_co, closest_enemy, pa->prev_state.co); /* attack if in range */ if(closest_dist <= bbd->part->boids->range + pa->size + enemy_pa->size) { float damage = BLI_frand(); float enemy_dir[3] = {bbd->wanted_co[0],bbd->wanted_co[1],bbd->wanted_co[2]}; - Normalize(enemy_dir); + normalize_v3(enemy_dir); /* fight mode */ bbd->wanted_speed = 0.0f; /* must face enemy to fight */ - if(Inpf(pa->prev_state.ave, enemy_dir)>0.5f) { + if(dot_v3v3(pa->prev_state.ave, enemy_dir)>0.5f) { bpa = enemy_pa->boid; bpa->data.health -= bbd->part->boids->strength * bbd->timestep * ((1.0f-bbd->part->boids->accuracy)*damage + bbd->part->boids->accuracy); } @@ -669,7 +669,7 @@ static int rule_fight(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, Parti if(bpa->data.health/bbd->part->boids->health * bbd->part->boids->aggression < e_strength / f_strength) { /* decide to flee */ if(closest_dist < fbr->flee_distance * fbr->distance) { - VecMulf(bbd->wanted_co, -1.0f); + mul_v3_fl(bbd->wanted_co, -1.0f); bbd->wanted_speed = val->max_speed; } else { /* wait for better odds */ @@ -735,7 +735,7 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro /* take surface velocity into account */ closest_point_on_surface(surmd, pa->state.co, x, NULL, v); - VecAddf(x, x, v); + add_v3_v3v3(x, x, v); /* get actual position on surface */ closest_point_on_surface(surmd, x, ground_co, ground_nor, NULL); @@ -754,12 +754,12 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro VECCOPY(col.co1, pa->state.co); VECCOPY(col.co2, pa->state.co); - VecAddf(col.co1, col.co1, zvec); - VecSubf(col.co2, col.co2, zvec); - VecSubf(ray_dir, col.co2, col.co1); + add_v3_v3v3(col.co1, col.co1, zvec); + sub_v3_v3v3(col.co2, col.co2, zvec); + sub_v3_v3v3(ray_dir, col.co2, col.co1); col.t = 0.0f; hit.index = -1; - hit.dist = col.ray_len = VecLength(ray_dir); + hit.dist = col.ray_len = len_v3(ray_dir); /* find out upmost deflector object */ for(coll = bbd->sim->colliders->first; coll; coll = coll->next){ @@ -772,9 +772,9 @@ static Object *boid_find_ground(BoidBrainData *bbd, ParticleData *pa, float *gro /* then use that object */ if(hit.index>=0) { t = hit.dist/col.ray_len; - VecLerpf(ground_co, col.co1, col.co2, t); + interp_v3_v3v3(ground_co, col.co1, col.co2, t); VECCOPY(ground_nor, col.nor); - Normalize(ground_nor); + normalize_v3(ground_nor); return col.hit_ob; } else { @@ -829,23 +829,23 @@ static void boid_climb(BoidSettings *boids, ParticleData *pa, float *surface_co, /* gather apparent gravity */ VECADDFAC(bpa->gravity, bpa->gravity, surface_nor, -1.0); - Normalize(bpa->gravity); + normalize_v3(bpa->gravity); /* raise boid it's size from surface */ - VecMulf(nor, pa->size * boids->height); - VecAddf(pa->state.co, surface_co, nor); + mul_v3_fl(nor, pa->size * boids->height); + add_v3_v3v3(pa->state.co, surface_co, nor); /* remove normal component from velocity */ - Projf(vel, pa->state.vel, surface_nor); - VecSubf(pa->state.vel, pa->state.vel, vel); + project_v3_v3v3(vel, pa->state.vel, surface_nor); + sub_v3_v3v3(pa->state.vel, pa->state.vel, vel); } static float boid_goal_signed_dist(float *boid_co, float *goal_co, float *goal_nor) { float vec[3]; - VecSubf(vec, boid_co, goal_co); + sub_v3_v3v3(vec, boid_co, goal_co); - return Inpf(vec, goal_nor); + return dot_v3v3(vec, goal_nor); } /* wanted_co is relative to boid location */ static int apply_boid_rule(BoidBrainData *bbd, BoidRule *rule, BoidValues *val, ParticleData *pa, float fuzziness) @@ -859,7 +859,7 @@ static int apply_boid_rule(BoidBrainData *bbd, BoidRule *rule, BoidValues *val, if(boid_rules[rule->type](rule, bbd, val, pa)==0) return 0; - if(fuzziness < 0.0f || VecLenCompare(bbd->wanted_co, pa->prev_state.vel, fuzziness * VecLength(pa->prev_state.vel))==0) + if(fuzziness < 0.0f || compare_len_v3v3(bbd->wanted_co, pa->prev_state.vel, fuzziness * len_v3(pa->prev_state.vel))==0) return 1; else return 0; @@ -943,7 +943,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) int n = 0; for(rule = state->rules.first; rule; rule=rule->next) { if(apply_boid_rule(bbd, rule, &val, pa, -1.0f)) { - VecAddf(wanted_co, wanted_co, bbd->wanted_co); + add_v3_v3v3(wanted_co, wanted_co, bbd->wanted_co); wanted_speed += bbd->wanted_speed; n++; bbd->wanted_co[0]=bbd->wanted_co[1]=bbd->wanted_co[2]=bbd->wanted_speed=0.0f; @@ -951,7 +951,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) } if(n > 1) { - VecMulf(wanted_co, 1.0f/(float)n); + mul_v3_fl(wanted_co, 1.0f/(float)n); wanted_speed /= (float)n; } @@ -971,12 +971,12 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) float cvel[3], dir[3]; VECCOPY(dir, pa->prev_state.ave); - Normalize2(dir); + normalize_v2(dir); VECCOPY(cvel, bbd->wanted_co); - Normalize2(cvel); + normalize_v2(cvel); - if(Inp2f(cvel, dir) > 0.95 / mul) + if(dot_v2v2(cvel, dir) > 0.95 / mul) bpa->data.mode = eBoidMode_Liftoff; } else if(val.jump_speed > 0.0f) { @@ -990,20 +990,20 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) float len; VECCOPY(dir, pa->prev_state.ave); - Normalize2(dir); + normalize_v2(dir); VECCOPY(cvel, bbd->wanted_co); - Normalize2(cvel); + normalize_v2(cvel); - len = Vec2Length(pa->prev_state.vel); + len = len_v2(pa->prev_state.vel); /* first of all, are we going in a suitable direction? */ /* or at a suitably slow speed */ - if(Inp2f(cvel, dir) > 0.95f / mul || len <= state->rule_fuzziness) { + if(dot_v2v2(cvel, dir) > 0.95f / mul || len <= state->rule_fuzziness) { /* try to reach goal at highest point of the parabolic path */ - cur_v = Vec2Length(pa->prev_state.vel); + cur_v = len_v2(pa->prev_state.vel); z_v = sasqrt(-2.0f * bbd->part->acc[2] * bbd->wanted_co[2]); - ground_v = Vec2Length(bbd->wanted_co)*sasqrt(-0.5f * bbd->part->acc[2] / bbd->wanted_co[2]); + ground_v = len_v2(bbd->wanted_co)*sasqrt(-0.5f * bbd->part->acc[2] / bbd->wanted_co[2]); len = sasqrt((ground_v-cur_v)*(ground_v-cur_v) + z_v*z_v); @@ -1014,11 +1014,11 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) VECCOPY(jump_v, dir); jump_v[2] = z_v; - VecMulf(jump_v, ground_v); + mul_v3_fl(jump_v, ground_v); - Normalize(jump_v); - VecMulf(jump_v, len); - Vec2Addf(jump_v, jump_v, pa->prev_state.vel); + normalize_v3(jump_v); + mul_v3_fl(jump_v, len); + add_v2_v2v2(jump_v, jump_v, pa->prev_state.vel); } } } @@ -1103,7 +1103,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) VECCOPY(old_dir, pa->prev_state.ave); VECCOPY(wanted_dir, bbd->wanted_co); - new_speed = Normalize(wanted_dir); + new_speed = normalize_v3(wanted_dir); /* first check if we have valid direction we want to go towards */ if(new_speed == 0.0f) { @@ -1111,39 +1111,39 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) } else { float old_dir2[2], wanted_dir2[2], nor[3], angle; - Vec2Copyf(old_dir2, old_dir); - Normalize2(old_dir2); - Vec2Copyf(wanted_dir2, wanted_dir); - Normalize2(wanted_dir2); + copy_v2_v2(old_dir2, old_dir); + normalize_v2(old_dir2); + copy_v2_v2(wanted_dir2, wanted_dir); + normalize_v2(wanted_dir2); /* choose random direction to turn if wanted velocity */ /* is directly behind regardless of z-coordinate */ - if(Inp2f(old_dir2, wanted_dir2) < -0.99f) { + if(dot_v2v2(old_dir2, wanted_dir2) < -0.99f) { wanted_dir[0] = 2.0f*(0.5f - BLI_frand()); wanted_dir[1] = 2.0f*(0.5f - BLI_frand()); wanted_dir[2] = 2.0f*(0.5f - BLI_frand()); - Normalize(wanted_dir); + normalize_v3(wanted_dir); } /* constrain direction with maximum angular velocity */ - angle = saacos(Inpf(old_dir, wanted_dir)); + angle = saacos(dot_v3v3(old_dir, wanted_dir)); angle = MIN2(angle, val.max_ave); - Crossf(nor, old_dir, wanted_dir); - VecRotToQuat(nor, angle, q); + cross_v3_v3v3(nor, old_dir, wanted_dir); + axis_angle_to_quat( q,nor, angle); VECCOPY(new_dir, old_dir); - QuatMulVecf(q, new_dir); - Normalize(new_dir); + mul_qt_v3(q, new_dir); + normalize_v3(new_dir); /* save direction in case resulting velocity too small */ - VecRotToQuat(nor, angle*dtime, q); + axis_angle_to_quat( q,nor, angle*dtime); VECCOPY(pa->state.ave, old_dir); - QuatMulVecf(q, pa->state.ave); - Normalize(pa->state.ave); + mul_qt_v3(q, pa->state.ave); + normalize_v3(pa->state.ave); } /* constrain speed with maximum acceleration */ - old_speed = VecLength(pa->prev_state.vel); + old_speed = len_v3(pa->prev_state.vel); if(bbd->wanted_speed < old_speed) new_speed = MAX2(bbd->wanted_speed, old_speed - val.max_acc); @@ -1152,11 +1152,11 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* combine direction and speed */ VECCOPY(new_vel, new_dir); - VecMulf(new_vel, new_speed); + mul_v3_fl(new_vel, new_speed); /* maintain minimum flying velocity if not landing */ if(level >= landing_level) { - float len2 = Inp2f(new_vel,new_vel); + float len2 = dot_v2v2(new_vel,new_vel); float root; len2 = MAX2(len2, val.min_speed*val.min_speed); @@ -1164,20 +1164,20 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) new_vel[2] = new_vel[2] < 0.0f ? -root : root; - Normalize2(new_vel); - Vec2Mulf(new_vel, sasqrt(len2)); + normalize_v2(new_vel); + mul_v2_fl(new_vel, sasqrt(len2)); } /* finally constrain speed to max speed */ - new_speed = Normalize(new_vel); - VecMulf(new_vel, MIN2(new_speed, val.max_speed)); + new_speed = normalize_v3(new_vel); + mul_v3_fl(new_vel, MIN2(new_speed, val.max_speed)); /* get acceleration from difference of velocities */ - VecSubf(acc, new_vel, pa->prev_state.vel); + sub_v3_v3v3(acc, new_vel, pa->prev_state.vel); /* break acceleration to components */ - Projf(tan_acc, acc, pa->prev_state.ave); - VecSubf(nor_acc, acc, tan_acc); + project_v3_v3v3(tan_acc, acc, pa->prev_state.ave); + sub_v3_v3v3(nor_acc, acc, tan_acc); } /* account for effectors */ @@ -1185,32 +1185,32 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) pdDoEffectors(bbd->sim->psys->effectors, bbd->sim->colliders, bbd->part->effector_weights, &epoint, force, NULL); if(ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)) { - float length = Normalize(force); + float length = normalize_v3(force); length = MAX2(0.0f, length - boids->land_stick_force); - VecMulf(force, length); + mul_v3_fl(force, length); } - VecAddf(acc, acc, force); + add_v3_v3v3(acc, acc, force); /* store smoothed acceleration for nice banking etc. */ VECADDFAC(bpa->data.acc, bpa->data.acc, acc, dtime); - VecMulf(bpa->data.acc, 1.0f / (1.0f + dtime)); + mul_v3_fl(bpa->data.acc, 1.0f / (1.0f + dtime)); /* integrate new location & velocity */ /* by regarding the acceleration as a force at this stage we*/ /* can get better control allthough it's a bit unphysical */ - VecMulf(acc, 1.0f/pa_mass); + mul_v3_fl(acc, 1.0f/pa_mass); VECCOPY(dvec, acc); - VecMulf(dvec, dtime*dtime*0.5f); + mul_v3_fl(dvec, dtime*dtime*0.5f); VECCOPY(bvec, pa->prev_state.vel); - VecMulf(bvec, dtime); - VecAddf(dvec, dvec, bvec); - VecAddf(pa->state.co, pa->state.co, dvec); + mul_v3_fl(bvec, dtime); + add_v3_v3v3(dvec, dvec, bvec); + add_v3_v3v3(pa->state.co, pa->state.co, dvec); VECADDFAC(pa->state.vel, pa->state.vel, acc, dtime); @@ -1224,9 +1224,9 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) float grav[3] = {0.0f, 0.0f, bbd->part->acc[2] < 0.0f ? -1.0f : 0.0f}; /* don't take forward acceleration into account (better banking) */ - if(Inpf(bpa->data.acc, pa->state.vel) > 0.0f) { - Projf(dvec, bpa->data.acc, pa->state.vel); - VecSubf(dvec, bpa->data.acc, dvec); + if(dot_v3v3(bpa->data.acc, pa->state.vel) > 0.0f) { + project_v3_v3v3(dvec, bpa->data.acc, pa->state.vel); + sub_v3_v3v3(dvec, bpa->data.acc, dvec); } else { VECCOPY(dvec, bpa->data.acc); @@ -1234,7 +1234,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* gather apparent gravity */ VECADDFAC(bpa->gravity, grav, dvec, -boids->banking); - Normalize(bpa->gravity); + normalize_v3(bpa->gravity); /* stick boid on goal when close enough */ if(bbd->goal_ob && boid_goal_signed_dist(pa->state.co, bbd->goal_co, bbd->goal_nor) <= pa->size * boids->height) { @@ -1257,7 +1257,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* gather apparent gravity */ VECADDFAC(bpa->gravity, bpa->gravity, grav, dtime); - Normalize(bpa->gravity); + normalize_v3(bpa->gravity); if(boids->options & BOID_ALLOW_LAND) { /* stick boid on goal when close enough */ @@ -1289,15 +1289,15 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) ///* gather apparent gravity to r_ve */ //VECADDFAC(pa->r_ve, pa->r_ve, ground_nor, -1.0); - //Normalize(pa->r_ve); + //normalize_v3(pa->r_ve); ///* raise boid it's size from surface */ - //VecMulf(nor, pa->size * boids->height); - //VecAddf(pa->state.co, ground_co, nor); + //mul_v3_fl(nor, pa->size * boids->height); + //add_v3_v3v3(pa->state.co, ground_co, nor); ///* remove normal component from velocity */ - //Projf(v, pa->state.vel, ground_nor); - //VecSubf(pa->state.vel, pa->state.vel, v); + //project_v3_v3v3(v, pa->state.vel, ground_nor); + //sub_v3_v3v3(pa->state.vel, pa->state.vel, v); break; } case eBoidMode_OnLand: @@ -1323,19 +1323,19 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* Don't take gravity's strength in to account, */ /* otherwise amount of banking is hard to control. */ VECCOPY(grav, ground_nor); - VecMulf(grav, -1.0f); + mul_v3_fl(grav, -1.0f); - Projf(dvec, bpa->data.acc, pa->state.vel); - VecSubf(dvec, bpa->data.acc, dvec); + project_v3_v3v3(dvec, bpa->data.acc, pa->state.vel); + sub_v3_v3v3(dvec, bpa->data.acc, dvec); /* gather apparent gravity */ VECADDFAC(bpa->gravity, grav, dvec, -boids->banking); - Normalize(bpa->gravity); + normalize_v3(bpa->gravity); } else { /* gather negative surface normal */ VECADDFAC(bpa->gravity, bpa->gravity, ground_nor, -1.0f); - Normalize(bpa->gravity); + normalize_v3(bpa->gravity); } break; } @@ -1343,36 +1343,36 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* save direction to state.ave unless the boid is falling */ /* (boids can't effect their direction when falling) */ - if(bpa->data.mode!=eBoidMode_Falling && VecLength(pa->state.vel) > 0.1*pa->size) { + if(bpa->data.mode!=eBoidMode_Falling && len_v3(pa->state.vel) > 0.1*pa->size) { VECCOPY(pa->state.ave, pa->state.vel); - Normalize(pa->state.ave); + normalize_v3(pa->state.ave); } /* apply damping */ if(ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)) - VecMulf(pa->state.vel, 1.0f - 0.2f*bbd->part->dampfac); + mul_v3_fl(pa->state.vel, 1.0f - 0.2f*bbd->part->dampfac); /* calculate rotation matrix based on forward & down vectors */ if(bpa->data.mode == eBoidMode_InAir) { VECCOPY(mat[0], pa->state.ave); - Projf(dvec, bpa->gravity, pa->state.ave); - VecSubf(mat[2], bpa->gravity, dvec); - Normalize(mat[2]); + project_v3_v3v3(dvec, bpa->gravity, pa->state.ave); + sub_v3_v3v3(mat[2], bpa->gravity, dvec); + normalize_v3(mat[2]); } else { - Projf(dvec, pa->state.ave, bpa->gravity); - VecSubf(mat[0], pa->state.ave, dvec); - Normalize(mat[0]); + project_v3_v3v3(dvec, pa->state.ave, bpa->gravity); + sub_v3_v3v3(mat[0], pa->state.ave, dvec); + normalize_v3(mat[0]); VECCOPY(mat[2], bpa->gravity); } - VecMulf(mat[2], -1.0f); - Crossf(mat[1], mat[2], mat[0]); + mul_v3_fl(mat[2], -1.0f); + cross_v3_v3v3(mat[1], mat[2], mat[0]); /* apply rotation */ - Mat3ToQuat_is_ok(mat, q); - QuatCopy(pa->state.rot, q); + mat3_to_quat_is_ok( q,mat); + copy_qt_qt(pa->state.rot, q); } BoidRule *boid_new_rule(int type) diff --git a/source/blender/blenkernel/intern/booleanops.c b/source/blender/blenkernel/intern/booleanops.c index 1f6457199fb..68e1f61a800 100644 --- a/source/blender/blenkernel/intern/booleanops.c +++ b/source/blender/blenkernel/intern/booleanops.c @@ -33,7 +33,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" @@ -104,7 +104,7 @@ static void VertexIt_Fill(CSG_IteratorPtr it, CSG_IVertex *vert) float global_pos[3]; /* boolean happens in global space, transform both with obmat */ - VecMat4MulVecfl( + mul_v3_m4v3( global_pos, iterator->ob->obmat, verts[iterator->pos].co @@ -327,11 +327,11 @@ static void InterpCSGFace( for (j = 0; j < nr; j++) { // get coordinate into the space of the original mesh if (mapmat) - VecMat4MulVecfl(obco, mapmat, co[j]); + mul_v3_m4v3(obco, mapmat, co[j]); else - VecCopyf(obco, co[j]); + copy_v3_v3(obco, co[j]); - InterpWeightsQ3Dfl(orig_co[0], orig_co[1], orig_co[2], orig_co[3], obco, w[j]); + interp_weights_face_v3( w[j],orig_co[0], orig_co[1], orig_co[2], orig_co[3], obco); } CustomData_interp(&orig_dm->faceData, &dm->faceData, &orig_index, NULL, (float*)w, 1, index); @@ -375,7 +375,7 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh( // we have to map the vertex coordinates back in the coordinate frame // of the resulting object, since it was computed in world space - VecMat4MulVecfl(mvert->co, parinv, csgvert.position); + mul_v3_m4v3(mvert->co, parinv, csgvert.position); } // a hash table to remap materials to indices @@ -478,9 +478,9 @@ DerivedMesh *NewBooleanDerivedMesh_intern( // we map the final object back into ob's local coordinate space. For this // we need to compute the inverse transform from global to ob (inv_mat), // and the transform from ob to ob_select for use in interpolation (map_mat) - Mat4Invert(inv_mat, ob->obmat); - Mat4MulMat4(map_mat, ob_select->obmat, inv_mat); - Mat4Invert(inv_mat, ob_select->obmat); + invert_m4_m4(inv_mat, ob->obmat); + mul_m4_m4m4(map_mat, ob_select->obmat, inv_mat); + invert_m4_m4(inv_mat, ob_select->obmat); { // interface with the boolean module: diff --git a/source/blender/blenkernel/intern/booleanops_mesh.c b/source/blender/blenkernel/intern/booleanops_mesh.c index 14e32873dbd..15a3d042622 100644 --- a/source/blender/blenkernel/intern/booleanops_mesh.c +++ b/source/blender/blenkernel/intern/booleanops_mesh.c @@ -47,7 +47,7 @@ #include "BKE_library.h" #include "BKE_material.h" -#include "BLI_arithb.h" +#include "BLI_math.h" /** * Implementation of boolean ops mesh interface. @@ -151,7 +151,7 @@ CSG_AddMeshToBlender( if (mesh == NULL) return 0; if (mesh->base == NULL) return 0; - Mat4Invert(inv_mat,mesh->base->object->obmat); + invert_m4_m4(inv_mat,mesh->base->object->obmat); // Create a new blender mesh object - using 'base' as // a template for the new object. diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 115d31b587c..ccee5a266f2 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -42,7 +42,7 @@ #include "RNA_access.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" @@ -845,8 +845,8 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl /* setup starting time, direction vector and accumulated time */ starttime= painter->accumtime; - Vec2Subf(dmousepos, pos, painter->lastmousepos); - len= Normalize2(dmousepos); + sub_v2_v2v2(dmousepos, pos, painter->lastmousepos); + len= normalize_v2(dmousepos); painter->accumtime += curtime - painter->lasttime; /* do paint op over unpainted time distance */ @@ -880,8 +880,8 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl /* setup starting distance, direction vector and accumulated distance */ startdistance= painter->accumdistance; - Vec2Subf(dmousepos, pos, painter->lastmousepos); - len= Normalize2(dmousepos); + sub_v2_v2v2(dmousepos, pos, painter->lastmousepos); + len= normalize_v2(dmousepos); painter->accumdistance += len; /* do paint op over unpainted distance */ diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index f2526231d50..5945be51aac 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -45,7 +45,7 @@ #include "BKE_displist.h" #include "BKE_global.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_linklist.h" #include "MEM_guardedalloc.h" @@ -55,7 +55,7 @@ static float ray_tri_intersection(const BVHTreeRay *ray, const float m_dist, con { float dist; - if(RayIntersectsTriangle((float*)ray->origin, (float*)ray->direction, (float*)v0, (float*)v1, (float*)v2, &dist, NULL)) + if(isect_ray_tri_v3((float*)ray->origin, (float*)ray->direction, (float*)v0, (float*)v1, (float*)v2, &dist, NULL)) return dist; return FLT_MAX; @@ -68,10 +68,10 @@ static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, con float p1[3]; float plane_normal[3], hit_point[3]; - CalcNormFloat((float*)v0, (float*)v1, (float*)v2, plane_normal); + normal_tri_v3( plane_normal,(float*)v0, (float*)v1, (float*)v2); VECADDFAC( p1, ray->origin, ray->direction, m_dist); - if(SweepingSphereIntersectsTriangleUV((float*)ray->origin, p1, radius, (float*)v0, (float*)v1, (float*)v2, &idist, hit_point)) + if(isect_sweeping_sphere_tri_v3((float*)ray->origin, p1, radius, (float*)v0, (float*)v1, (float*)v2, &idist, hit_point)) { return idist * m_dist; } @@ -384,9 +384,9 @@ static float nearest_point_in_tri_surface(const float *v0,const float *v1,const float w[3], x[3], y[3], z[3]; VECCOPY(w, v0); VECCOPY(x, e0); - VecMulf(x, S); + mul_v3_fl(x, S); VECCOPY(y, e1); - VecMulf(y, T); + mul_v3_fl(y, T); VECADD(z, w, x); VECADD(z, z, y); //VECSUB(d, p, z); @@ -430,7 +430,7 @@ static void mesh_faces_nearest_point(void *userdata, int index, const float *co, nearest->index = index; nearest->dist = dist; VECCOPY(nearest->co, nearest_tmp); - CalcNormFloat(t0, t1, t2, nearest->no); + normal_tri_v3( nearest->no,t0, t1, t2); } t1 = t2; @@ -469,7 +469,7 @@ static void mesh_faces_spherecast(void *userdata, int index, const BVHTreeRay *r hit->dist = dist; VECADDFAC(hit->co, ray->origin, ray->direction, dist); - CalcNormFloat(t0, t1, t2, hit->no); + normal_tri_v3( hit->no,t0, t1, t2); } t1 = t2; @@ -492,16 +492,17 @@ static void mesh_edges_nearest_point(void *userdata, int index, const float *co, t0 = vert[ edge->v1 ].co; t1 = vert[ edge->v2 ].co; - PclosestVL3Dfl(nearest_tmp, co, t0, t1); - dist = VecLenf(nearest_tmp, co); + // NOTE: casts to "float*" here are due to co being "const float*" + closest_to_line_segment_v3(nearest_tmp, (float*)co, t0, t1); + dist = len_v3v3(nearest_tmp, (float*)co); if(dist < nearest->dist) { nearest->index = index; nearest->dist = dist; VECCOPY(nearest->co, nearest_tmp); - VecSubf(nearest->no, t0, t1); - Normalize(nearest->no); + sub_v3_v3v3(nearest->no, t0, t1); + normalize_v3(nearest->no); } } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index e38bb00fe8d..30d1b65cc8b 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -45,7 +45,7 @@ #include "BKE_multires.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_edgehash.h" #include "BLI_editVert.h" @@ -405,12 +405,9 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *a /* TODO make this better (cache facenormals as layer?) */ float nor[3]; if(mface->v4) { - CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co, - mvert[mface->v3].co, mvert[mface->v4].co, - nor); + normal_quad_v3( nor,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co); } else { - CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co, - mvert[mface->v3].co, nor); + normal_tri_v3( nor,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co); } glNormal3fv(nor); } @@ -579,12 +576,9 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, else { float nor[3]; if(mf->v4) { - CalcNormFloat4(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, mv[mf->v4].co, - nor); + normal_quad_v3( nor,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, mv[mf->v4].co); } else { - CalcNormFloat(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, nor); + normal_tri_v3( nor,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co); } glNormal3fv(nor); } @@ -754,12 +748,9 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us else { float nor[3]; if(mf->v4) { - CalcNormFloat4(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, mv[mf->v4].co, - nor); + normal_quad_v3( nor,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, mv[mf->v4].co); } else { - CalcNormFloat(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, nor); + normal_tri_v3( nor,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co); } glNormal3fv(nor); } @@ -929,12 +920,9 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo /* TODO ideally a normal layer should always be available */ float nor[3]; if(mface->v4) { - CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co, - mvert[mface->v3].co, mvert[mface->v4].co, - nor); + normal_quad_v3( nor,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co); } else { - CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co, - mvert[mface->v3].co, nor); + normal_tri_v3( nor,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co); } glNormal3fv(nor); } @@ -1271,18 +1259,16 @@ static void cdDM_foreachMappedFaceCenter( orig = i; VECCOPY(cent, mv[mf->v1].co); - VecAddf(cent, cent, mv[mf->v2].co); - VecAddf(cent, cent, mv[mf->v3].co); + add_v3_v3v3(cent, cent, mv[mf->v2].co); + add_v3_v3v3(cent, cent, mv[mf->v3].co); if (mf->v4) { - CalcNormFloat4(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, mv[mf->v4].co, no); - VecAddf(cent, cent, mv[mf->v4].co); - VecMulf(cent, 0.25f); + normal_quad_v3( no,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, mv[mf->v4].co); + add_v3_v3v3(cent, cent, mv[mf->v4].co); + mul_v3_fl(cent, 0.25f); } else { - CalcNormFloat(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, no); - VecMulf(cent, 0.33333333333f); + normal_tri_v3( no,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co); + mul_v3_fl(cent, 0.33333333333f); } func(userData, orig, cent, no); @@ -1630,26 +1616,24 @@ void CDDM_calc_normals(DerivedMesh *dm) float *f_no = face_nors[i]; if(mf->v4) - CalcNormFloat4(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, mv[mf->v4].co, f_no); + normal_quad_v3( f_no,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, mv[mf->v4].co); else - CalcNormFloat(mv[mf->v1].co, mv[mf->v2].co, - mv[mf->v3].co, f_no); + normal_tri_v3( f_no,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co); - VecAddf(temp_nors[mf->v1], temp_nors[mf->v1], f_no); - VecAddf(temp_nors[mf->v2], temp_nors[mf->v2], f_no); - VecAddf(temp_nors[mf->v3], temp_nors[mf->v3], f_no); + add_v3_v3v3(temp_nors[mf->v1], temp_nors[mf->v1], f_no); + add_v3_v3v3(temp_nors[mf->v2], temp_nors[mf->v2], f_no); + add_v3_v3v3(temp_nors[mf->v3], temp_nors[mf->v3], f_no); if(mf->v4) - VecAddf(temp_nors[mf->v4], temp_nors[mf->v4], f_no); + add_v3_v3v3(temp_nors[mf->v4], temp_nors[mf->v4], f_no); } /* normalize vertex normals and assign */ for(i = 0; i < numVerts; i++, mv++) { float *no = temp_nors[i]; - if (Normalize(no) == 0.0) { + if (normalize_v3(no) == 0.0) { VECCOPY(no, mv->co); - Normalize(no); + normalize_v3(no); } mv->no[0] = (short)(no[0] * 32767.0); @@ -1860,7 +1844,7 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts mvert = CustomData_get_layer(&orig->vertData, CD_MVERT); mrdm->orco = MEM_callocN(sizeof(float) * 3 * orig->getNumVerts(orig), "multires orco"); for(i = 0; i < orig->getNumVerts(orig); ++i) - VecCopyf(mrdm->orco[i], mvert[i].co); + copy_v3_v3(mrdm->orco[i], mvert[i].co); } else DM_init(dm, numVerts, numEdges, numFaces); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 74f88a77e63..4a9cb237c01 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -403,7 +403,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul /* Get the current position. */ VECCOPY(verts->xconst, mvert[i].co); - Mat4MulVecfl(ob->obmat, verts->xconst); + mul_m4_v3(ob->obmat, verts->xconst); } effectors = pdInitEffectors(clmd->scene, ob, NULL, clmd->sim_parms->effector_weights); @@ -723,7 +723,7 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh * if (clmd->clothObject) { /* inverse matrix is not uptodate... */ - Mat4Invert (ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); mvert = CDDM_get_verts(dm); numverts = dm->getNumVerts(dm); @@ -731,7 +731,7 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, DerivedMesh * for (i = 0; i < numverts; i++) { VECCOPY (mvert[i].co, cloth->verts[i].x); - Mat4MulVecfl (ob->imat, mvert[i].co); /* cloth is in global coords */ + mul_m4_v3(ob->imat, mvert[i].co); /* cloth is in global coords */ } } } @@ -867,7 +867,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d if(first) { VECCOPY ( verts->x, mvert[i].co ); - Mat4MulVecfl ( ob->obmat, verts->x ); + mul_m4_v3( ob->obmat, verts->x ); } /* no GUI interface yet */ @@ -884,7 +884,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d VECCOPY ( verts->xconst, verts->x ); VECCOPY ( verts->txold, verts->x ); VECCOPY ( verts->tx, verts->x ); - VecMulf ( verts->v, 0.0f ); + mul_v3_fl( verts->v, 0.0f ); verts->impulse_count = 0; VECCOPY ( verts->impulse, tnull ); diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 8c664bc1a57..2ea54ac1f03 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -529,7 +529,7 @@ int cloth_collision_response_static ( ClothModifierData *clmd, CollisionModifier // calculate tangential velocity VECCOPY ( temp, collpair->normal ); - VecMulf ( temp, magrelVel ); + mul_v3_fl( temp, magrelVel ); VECSUB ( vrel_t_pre, relativeVelocity, temp ); // Decrease in magnitude of relative tangential velocity due to coulomb friction @@ -539,7 +539,7 @@ int cloth_collision_response_static ( ClothModifierData *clmd, CollisionModifier // Apply friction impulse. if ( magtangent > ALMOST_ZERO ) { - Normalize ( vrel_t_pre ); + normalize_v3( vrel_t_pre ); impulse = magtangent / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); // 2.0 * VECADDMUL ( cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse ); @@ -681,7 +681,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap if ( distance <= ( epsilon1 + epsilon2 + ALMOST_ZERO ) ) { VECCOPY ( collpair->normal, collpair->vector ); - Normalize ( collpair->normal ); + normalize_v3( collpair->normal ); collpair->distance = distance; collpair->flag = 0; @@ -726,6 +726,7 @@ CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap return collpair; } +#if 0 static int cloth_collision_response_moving( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) { int result = 0; @@ -778,7 +779,7 @@ static int cloth_collision_response_moving( ClothModifierData *clmd, CollisionMo // calculate tangential velocity VECCOPY ( temp, collpair->normal ); - VecMulf ( temp, magrelVel ); + mul_v3_fl( temp, magrelVel ); VECSUB ( vrel_t_pre, relativeVelocity, temp ); // Decrease in magnitude of relative tangential velocity due to coulomb friction @@ -788,7 +789,7 @@ static int cloth_collision_response_moving( ClothModifierData *clmd, CollisionMo // Apply friction impulse. if ( magtangent > ALMOST_ZERO ) { - Normalize ( vrel_t_pre ); + normalize_v3( vrel_t_pre ); impulse = 2.0 * magtangent / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); VECADDMUL ( cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse ); @@ -834,6 +835,7 @@ static int cloth_collision_response_moving( ClothModifierData *clmd, CollisionMo } return result; } +#endif static float projectPointOntoLine(float *p, float *a, float *b) { @@ -853,15 +855,15 @@ static void calculateEENormal(float *np1, float *np2, float *np3, float *np4,flo // printf("l1: %f, l1: %f, l2: %f, l2: %f\n", line1[0], line1[1], line2[0], line2[1]); - Crossf(out_normal, line1, line2); + cross_v3_v3v3(out_normal, line1, line2); - length = Normalize(out_normal); + length = normalize_v3(out_normal); if (length <= FLT_EPSILON) { // lines are collinear VECSUB(out_normal, np2, np1); - Normalize(out_normal); + normalize_v3(out_normal); } } @@ -901,7 +903,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float VECSUB(line1, np12, np11); VECSUB(line2, np22, np21); - Crossf(cross, line1, line2); + cross_v3_v3v3(cross, line1, line2); length = INPR(cross, cross); if (length < FLT_EPSILON) @@ -912,7 +914,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float *out_a1 = 0; calculateEENormal(np11, np12, np21, np22, out_normal); VECSUB(temp, np22, np21); - VecMulf(temp, *out_a2); + mul_v3_fl(temp, *out_a2); VECADD(temp2, temp, np21); VECADD(temp2, temp2, np11); return INPR(temp2, temp2); @@ -928,7 +930,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // return (np22 - (np11 + (np12 - np11) * out_a1)).lengthSquared(); VECSUB(temp, np12, np11); - VecMulf(temp, *out_a1); + mul_v3_fl(temp, *out_a1); VECADD(temp2, temp, np11); VECSUB(temp2, np22, temp2); return INPR(temp2, temp2); @@ -943,7 +945,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // return (np21 - (np11 + (np12 - np11) * out_a1)).lengthSquared(); VECSUB(temp, np12, np11); - VecMulf(temp, *out_a1); + mul_v3_fl(temp, *out_a1); VECADD(temp2, temp, np11); VECSUB(temp2, np21, temp2); return INPR(temp2, temp2); @@ -991,12 +993,12 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // p1= np11 + (np12 - np11) * out_a1; VECSUB(temp, np12, np11); - VecMulf(temp, *out_a1); + mul_v3_fl(temp, *out_a1); VECADD(p1, np11, temp); // p2 = np21 + (np22 - np21) * out_a2; VECSUB(temp, np22, np21); - VecMulf(temp, *out_a2); + mul_v3_fl(temp, *out_a2); VECADD(p2, np21, temp); calculateEENormal(np11, np12, np21, np22, out_normal); @@ -1022,7 +1024,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // p1 = np11 + (np12 - np11) * out_a1; VECSUB(temp, np12, np11); - VecMulf(temp, *out_a1); + mul_v3_fl(temp, *out_a1); VECADD(p1, np11, temp); *out_a2 = projectPointOntoLine(p1, np21, np22); @@ -1032,7 +1034,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // return (p1 - (np21 + (np22 - np21) * out_a2)).lengthSquared(); VECSUB(temp, np22, np21); - VecMulf(temp, *out_a2); + mul_v3_fl(temp, *out_a2); VECADD(temp, temp, np21); VECSUB(temp, p1, temp); return INPR(temp, temp); @@ -1044,7 +1046,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // p2 = np21 + (np22 - np21) * out_a2; VECSUB(temp, np22, np21); - VecMulf(temp, *out_a2); + mul_v3_fl(temp, *out_a2); VECADD(p2, np21, temp); *out_a1 = projectPointOntoLine(p2, np11, np12); @@ -1054,7 +1056,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float // return ((np11 + (np12 - np11) * out_a1) - p2).lengthSquared(); VECSUB(temp, np12, np11); - VecMulf(temp, *out_a1); + mul_v3_fl(temp, *out_a1); VECADD(temp, temp, np11); VECSUB(temp, temp, p2); return INPR(temp, temp); @@ -1065,6 +1067,7 @@ static float edgedge_distance(float np11[3], float np12[3], float np21[3], float return 0; } +#if 0 static int cloth_collision_moving_edges ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair ) { EdgeCollPair edgecollpair; @@ -1217,16 +1220,16 @@ static int cloth_collision_moving_edges ( ClothModifierData *clmd, CollisionModi float desiredVn; VECCOPY(vrel_1_to_2, verts1[edgecollpair.p11].tv); - VecMulf(vrel_1_to_2, 1.0 - a); + mul_v3_fl(vrel_1_to_2, 1.0 - a); VECCOPY(temp, verts1[edgecollpair.p12].tv); - VecMulf(temp, a); + mul_v3_fl(temp, a); VECADD(vrel_1_to_2, vrel_1_to_2, temp); VECCOPY(temp, verts1[edgecollpair.p21].tv); - VecMulf(temp, 1.0 - b); + mul_v3_fl(temp, 1.0 - b); VECCOPY(temp2, verts1[edgecollpair.p22].tv); - VecMulf(temp2, b); + mul_v3_fl(temp2, b); VECADD(temp, temp, temp2); VECSUB(vrel_1_to_2, vrel_1_to_2, temp); @@ -1237,7 +1240,7 @@ static int cloth_collision_moving_edges ( ClothModifierData *clmd, CollisionModi if(out_normalVelocity < 0.0) { out_normalVelocity*= -1.0; - VecNegf(out_normal); + negate_v3(out_normal); } */ /* Inelastic repulsion impulse. */ @@ -1292,6 +1295,7 @@ static int cloth_collision_moving ( ClothModifierData *clmd, CollisionModifierDa return 1; } +#endif // return all collision objects in scene @@ -1707,7 +1711,7 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl continue; } - length = Normalize ( temp ); + length = normalize_v3( temp ); if ( length < mindistance ) { @@ -1715,17 +1719,17 @@ int cloth_bvh_objcollision (Object *ob, ClothModifierData * clmd, float step, fl if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) { - VecMulf ( temp, -correction ); + mul_v3_fl( temp, -correction ); VECADD ( verts[j].tx, verts[j].tx, temp ); } else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) { - VecMulf ( temp, correction ); + mul_v3_fl( temp, correction ); VECADD ( verts[i].tx, verts[i].tx, temp ); } else { - VecMulf ( temp, -correction*0.5 ); + mul_v3_fl( temp, -correction*0.5 ); VECADD ( verts[j].tx, verts[j].tx, temp ); VECSUB ( verts[i].tx, verts[i].tx, temp ); diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 8cd64ae2ece..f3448a60b5a 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -52,7 +52,7 @@ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_threads.h" #include "IMB_imbuf.h" @@ -462,35 +462,35 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) if(bezt[0].h2==HD_AUTO) { - hlen= VecLenf(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */ + hlen= len_v3v3(bezt[0].vec[1], bezt[0].vec[2]); /* original handle length */ /* clip handle point */ VECCOPY(vec, bezt[1].vec[0]); if(vec[0] < bezt[0].vec[1][0]) vec[0]= bezt[0].vec[1][0]; - VecSubf(vec, vec, bezt[0].vec[1]); - nlen= VecLength(vec); + sub_v3_v3v3(vec, vec, bezt[0].vec[1]); + nlen= len_v3(vec); if(nlen>FLT_EPSILON) { - VecMulf(vec, hlen/nlen); - VecAddf(bezt[0].vec[2], vec, bezt[0].vec[1]); - VecSubf(bezt[0].vec[0], bezt[0].vec[1], vec); + mul_v3_fl(vec, hlen/nlen); + add_v3_v3v3(bezt[0].vec[2], vec, bezt[0].vec[1]); + sub_v3_v3v3(bezt[0].vec[0], bezt[0].vec[1], vec); } } a= cuma->totpoint-1; if(bezt[a].h2==HD_AUTO) { - hlen= VecLenf(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */ + hlen= len_v3v3(bezt[a].vec[1], bezt[a].vec[0]); /* original handle length */ /* clip handle point */ VECCOPY(vec, bezt[a-1].vec[2]); if(vec[0] > bezt[a].vec[1][0]) vec[0]= bezt[a].vec[1][0]; - VecSubf(vec, vec, bezt[a].vec[1]); - nlen= VecLength(vec); + sub_v3_v3v3(vec, vec, bezt[a].vec[1]); + nlen= len_v3(vec); if(nlen>FLT_EPSILON) { - VecMulf(vec, hlen/nlen); - VecAddf(bezt[a].vec[0], vec, bezt[a].vec[1]); - VecSubf(bezt[a].vec[2], bezt[a].vec[1], vec); + mul_v3_fl(vec, hlen/nlen); + add_v3_v3v3(bezt[a].vec[0], vec, bezt[a].vec[1]); + sub_v3_v3v3(bezt[a].vec[2], bezt[a].vec[1], vec); } } } diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index a319838a56f..6fce9a29962 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "DNA_armature_types.h" @@ -122,12 +122,12 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, cob->ob = ob; cob->type = datatype; cob->rotOrder = EULER_ORDER_DEFAULT; // TODO: when objects have rotation order too, use that - Mat4CpyMat4(cob->matrix, ob->obmat); + copy_m4_m4(cob->matrix, ob->obmat); } else - Mat4One(cob->matrix); + unit_m4(cob->matrix); - Mat4CpyMat4(cob->startmat, cob->matrix); + copy_m4_m4(cob->startmat, cob->matrix); } break; case CONSTRAINT_OBTYPE_BONE: @@ -148,18 +148,18 @@ bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, } /* matrix in world-space */ - Mat4MulMat4(cob->matrix, cob->pchan->pose_mat, ob->obmat); + mul_m4_m4m4(cob->matrix, cob->pchan->pose_mat, ob->obmat); } else - Mat4One(cob->matrix); + unit_m4(cob->matrix); - Mat4CpyMat4(cob->startmat, cob->matrix); + copy_m4_m4(cob->startmat, cob->matrix); } break; default: /* other types not yet handled */ - Mat4One(cob->matrix); - Mat4One(cob->startmat); + unit_m4(cob->matrix); + unit_m4(cob->startmat); break; } @@ -176,8 +176,8 @@ void constraints_clear_evalob (bConstraintOb *cob) return; /* calculate delta of constraints evaluation */ - Mat4Invert(imat, cob->startmat); - Mat4MulMat4(delta, imat, cob->matrix); + invert_m4_m4(imat, cob->startmat); + mul_m4_m4m4(delta, imat, cob->matrix); /* copy matrices back to source */ switch (cob->type) { @@ -186,10 +186,10 @@ void constraints_clear_evalob (bConstraintOb *cob) /* cob->ob might not exist! */ if (cob->ob) { /* copy new ob-matrix back to owner */ - Mat4CpyMat4(cob->ob->obmat, cob->matrix); + copy_m4_m4(cob->ob->obmat, cob->matrix); /* copy inverse of delta back to owner */ - Mat4Invert(cob->ob->constinv, delta); + invert_m4_m4(cob->ob->constinv, delta); } } break; @@ -198,10 +198,10 @@ void constraints_clear_evalob (bConstraintOb *cob) /* cob->ob or cob->pchan might not exist */ if (cob->ob && cob->pchan) { /* copy new pose-matrix back to owner */ - Mat4MulMat4(cob->pchan->pose_mat, cob->matrix, cob->ob->imat); + mul_m4_m4m4(cob->pchan->pose_mat, cob->matrix, cob->ob->imat); /* copy inverse of delta back to owner */ - Mat4Invert(cob->pchan->constinv, delta); + invert_m4_m4(cob->pchan->constinv, delta); } } break; @@ -235,9 +235,9 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 case CONSTRAINT_SPACE_WORLD: /* ---------- FROM WORLDSPACE ---------- */ { /* world to pose */ - Mat4Invert(imat, ob->obmat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, imat); + invert_m4_m4(imat, ob->obmat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, imat); /* use pose-space as stepping stone for other spaces... */ if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_PARLOCAL)) { @@ -250,8 +250,8 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 { /* pose to world */ if (to == CONSTRAINT_SPACE_WORLD) { - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, ob->obmat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, ob->obmat); } /* pose to local */ else if (to == CONSTRAINT_SPACE_LOCAL) { @@ -260,7 +260,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 float offs_bone[4][4]; /* construct offs_bone the same way it is done in armature.c */ - Mat4CpyMat3(offs_bone, pchan->bone->bone_mat); + copy_m4_m3(offs_bone, pchan->bone->bone_mat); VECCOPY(offs_bone[3], pchan->bone->head); offs_bone[3][1]+= pchan->bone->parent->length; @@ -269,37 +269,37 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 float tmat[4][4]; /* the rotation of the parent restposition */ - Mat4CpyMat4(tmat, pchan->bone->parent->arm_mat); + copy_m4_m4(tmat, pchan->bone->parent->arm_mat); /* the location of actual parent transform */ VECCOPY(tmat[3], offs_bone[3]); offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f; - Mat4MulVecfl(pchan->parent->pose_mat, tmat[3]); + mul_m4_v3(pchan->parent->pose_mat, tmat[3]); - Mat4MulMat4(diff_mat, offs_bone, tmat); - Mat4Invert(imat, diff_mat); + mul_m4_m4m4(diff_mat, offs_bone, tmat); + invert_m4_m4(imat, diff_mat); } else { /* pose_mat = par_pose_mat * bone_mat * chan_mat */ - Mat4MulMat4(diff_mat, offs_bone, pchan->parent->pose_mat); - Mat4Invert(imat, diff_mat); + mul_m4_m4m4(diff_mat, offs_bone, pchan->parent->pose_mat); + invert_m4_m4(imat, diff_mat); } } else { /* pose_mat = chan_mat * arm_mat */ - Mat4Invert(imat, pchan->bone->arm_mat); + invert_m4_m4(imat, pchan->bone->arm_mat); } - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, imat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, imat); } } /* pose to local with parent */ else if (to == CONSTRAINT_SPACE_PARLOCAL) { if (pchan->bone) { - Mat4Invert(imat, pchan->bone->arm_mat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, imat); + invert_m4_m4(imat, pchan->bone->arm_mat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, imat); } } } @@ -313,7 +313,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 float offs_bone[4][4]; /* construct offs_bone the same way it is done in armature.c */ - Mat4CpyMat3(offs_bone, pchan->bone->bone_mat); + copy_m4_m3(offs_bone, pchan->bone->bone_mat); VECCOPY(offs_bone[3], pchan->bone->head); offs_bone[3][1]+= pchan->bone->parent->length; @@ -322,29 +322,29 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 float tmat[4][4]; /* the rotation of the parent restposition */ - Mat4CpyMat4(tmat, pchan->bone->parent->arm_mat); + copy_m4_m4(tmat, pchan->bone->parent->arm_mat); /* the location of actual parent transform */ VECCOPY(tmat[3], offs_bone[3]); offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f; - Mat4MulVecfl(pchan->parent->pose_mat, tmat[3]); + mul_m4_v3(pchan->parent->pose_mat, tmat[3]); - Mat4MulMat4(diff_mat, offs_bone, tmat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, diff_mat); + mul_m4_m4m4(diff_mat, offs_bone, tmat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, diff_mat); } else { /* pose_mat = par_pose_mat * bone_mat * chan_mat */ - Mat4MulMat4(diff_mat, offs_bone, pchan->parent->pose_mat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, diff_mat); + mul_m4_m4m4(diff_mat, offs_bone, pchan->parent->pose_mat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, diff_mat); } } else { - Mat4CpyMat4(diff_mat, pchan->bone->arm_mat); + copy_m4_m4(diff_mat, pchan->bone->arm_mat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, diff_mat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, diff_mat); } } @@ -359,9 +359,9 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 { /* local + parent to pose */ if (pchan->bone) { - Mat4CpyMat4(diff_mat, pchan->bone->arm_mat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, diff_mat, tempmat); + copy_m4_m4(diff_mat, pchan->bone->arm_mat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, diff_mat, tempmat); } /* use pose-space as stepping stone for other spaces */ @@ -379,19 +379,19 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4 /* check if object has a parent - otherwise this won't work */ if (ob->parent) { /* 'subtract' parent's effects from owner */ - Mat4MulMat4(diff_mat, ob->parentinv, ob->parent->obmat); - Mat4Invert(imat, diff_mat); - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(mat, tempmat, imat); + mul_m4_m4m4(diff_mat, ob->parentinv, ob->parent->obmat); + invert_m4_m4(imat, diff_mat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(mat, tempmat, imat); } } else if (from==CONSTRAINT_SPACE_LOCAL && to==CONSTRAINT_SPACE_WORLD) { /* check that object has a parent - otherwise this won't work */ if (ob->parent) { /* 'add' parent's effect back to owner */ - Mat4CpyMat4(tempmat, mat); - Mat4MulMat4(diff_mat, ob->parentinv, ob->parent->obmat); - Mat4MulMat4(mat, tempmat, diff_mat); + copy_m4_m4(tempmat, mat); + mul_m4_m4m4(diff_mat, ob->parentinv, ob->parent->obmat); + mul_m4_m4m4(mat, tempmat, diff_mat); } } } @@ -412,7 +412,7 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f short freeDM = 0; /* initialize target matrix using target matrix */ - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); /* get index of vertex group */ dgroup = get_named_vertexgroup_num(ob, substring); @@ -454,8 +454,8 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f if (dvert[i].dw[j].def_nr == dgroup) { dm->getVertCo(dm, i, co); dm->getVertNo(dm, i, nor); - VecAddf(vec, vec, co); - VecAddf(normal, normal, nor); + add_v3_v3v3(vec, vec, co); + add_v3_v3v3(normal, normal, nor); count++; break; } @@ -466,8 +466,8 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f /* calculate averages of normal and coordinates */ if (count > 0) { - VecMulf(vec, 1.0f / count); - VecMulf(normal, 1.0f / count); + mul_v3_fl(vec, 1.0f / count); + mul_v3_fl(normal, 1.0f / count); } @@ -476,25 +476,25 @@ static void contarget_get_mesh_mat (Scene *scene, Object *ob, char *substring, f * calc_manipulator_stats, V3D_MANIP_NORMAL case */ /* we need the transpose of the inverse for a normal... */ - Mat3CpyMat4(imat, ob->obmat); + copy_m3_m4(imat, ob->obmat); - Mat3Inv(tmat, imat); - Mat3Transp(tmat); - Mat3MulVecfl(tmat, normal); + invert_m3_m3(tmat, imat); + transpose_m3(tmat); + mul_m3_v3(tmat, normal); - Normalize(normal); + normalize_v3(normal); VECCOPY(plane, tmat[1]); VECCOPY(tmat[2], normal); - Crossf(tmat[0], normal, plane); - Crossf(tmat[1], tmat[2], tmat[0]); + cross_v3_v3v3(tmat[0], normal, plane); + cross_v3_v3v3(tmat[1], tmat[2], tmat[0]); - Mat4CpyMat3(mat, tmat); - Mat4Ortho(mat); + copy_m4_m3(mat, tmat); + normalize_m4(mat); /* apply the average coordinate as the new location */ - VecMat4MulVecfl(tvec, ob->obmat, vec); + mul_v3_m4v3(tvec, ob->obmat, vec); VECCOPY(mat[3], tvec); } } @@ -522,7 +522,7 @@ static void contarget_get_lattice_mat (Object *ob, char *substring, float mat[][ int i, n; /* initialize target matrix using target matrix */ - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); /* get index of vertex group */ dgroup = get_named_vertexgroup_num(ob, substring); @@ -542,7 +542,7 @@ static void contarget_get_lattice_mat (Object *ob, char *substring, float mat[][ else memcpy(tvec, bp->vec, 3*sizeof(float)); - VecAddf(vec, vec, tvec); + add_v3_v3v3(vec, vec, tvec); grouped++; break; @@ -556,8 +556,8 @@ static void contarget_get_lattice_mat (Object *ob, char *substring, float mat[][ /* find average location, then multiply by ob->obmat to find world-space location */ if (grouped) - VecMulf(vec, 1.0f / grouped); - VecMat4MulVecfl(tvec, ob->obmat, vec); + mul_v3_fl(vec, 1.0f / grouped); + mul_v3_m4v3(tvec, ob->obmat, vec); /* copy new location to matrix */ VECCOPY(mat[3], tvec); @@ -569,7 +569,7 @@ static void constraint_target_to_mat4 (Scene *scene, Object *ob, char *substring { /* Case OBJECT */ if (!strlen(substring)) { - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); constraint_mat_convertspace(ob, NULL, mat, from, to); } /* Case VERTEXGROUP */ @@ -601,23 +601,23 @@ static void constraint_target_to_mat4 (Scene *scene, Object *ob, char *substring */ if (headtail < 0.000001) { /* skip length interpolation if set to head */ - Mat4MulMat4(mat, pchan->pose_mat, ob->obmat); + mul_m4_m4m4(mat, pchan->pose_mat, ob->obmat); } else { float tempmat[4][4], loc[3]; /* interpolate along length of bone */ - VecLerpf(loc, pchan->pose_head, pchan->pose_tail, headtail); + interp_v3_v3v3(loc, pchan->pose_head, pchan->pose_tail, headtail); /* use interpolated distance for subtarget */ - Mat4CpyMat4(tempmat, pchan->pose_mat); - VecCopyf(tempmat[3], loc); + copy_m4_m4(tempmat, pchan->pose_mat); + copy_v3_v3(tempmat[3], loc); - Mat4MulMat4(mat, tempmat, ob->obmat); + mul_m4_m4m4(mat, tempmat, ob->obmat); } } else - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); /* convert matrix space as required */ constraint_mat_convertspace(ob, pchan, mat, from, to); @@ -666,7 +666,7 @@ static void default_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain if (VALID_CONS_TARGET(ct)) constraint_target_to_mat4(cob->scene, ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail); else if (ct) - Mat4One(ct->matrix); + unit_m4(ct->matrix); } /* This following macro should be used for all standard single-target *_get_tars functions @@ -772,7 +772,7 @@ static void childof_new_data (void *cdata) data->flag = (CHILDOF_LOCX | CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX |CHILDOF_ROTY | CHILDOF_ROTZ | CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ); - Mat4One(data->invmat); + unit_m4(data->invmat); } static int childof_get_tars (bConstraint *con, ListBase *list) @@ -813,16 +813,16 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float loco[3], eulo[3], sizo[3]; /* get offset (parent-inverse) matrix */ - Mat4CpyMat4(invmat, data->invmat); + copy_m4_m4(invmat, data->invmat); /* extract components of both matrices */ VECCOPY(loc, ct->matrix[3]); - Mat4ToEulO(ct->matrix, eul, ct->rotOrder); - Mat4ToSize(ct->matrix, size); + mat4_to_eulO( eul, ct->rotOrder,ct->matrix); + mat4_to_size( size,ct->matrix); VECCOPY(loco, invmat[3]); - Mat4ToEulO(invmat, eulo, cob->rotOrder); - Mat4ToSize(invmat, sizo); + mat4_to_eulO( eulo, cob->rotOrder,invmat); + mat4_to_size( sizo,invmat); /* disable channels not enabled */ if (!(data->flag & CHILDOF_LOCX)) loc[0]= loco[0]= 0.0f; @@ -836,19 +836,19 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta if (!(data->flag & CHILDOF_SIZEZ)) size[2]= sizo[2]= 1.0f; /* make new target mat and offset mat */ - LocEulOSizeToMat4(ct->matrix, loc, eul, size, ct->rotOrder); - LocEulOSizeToMat4(invmat, loco, eulo, sizo, cob->rotOrder); + loc_eulO_size_to_mat4(ct->matrix, loc, eul, size, ct->rotOrder); + loc_eulO_size_to_mat4(invmat, loco, eulo, sizo, cob->rotOrder); /* multiply target (parent matrix) by offset (parent inverse) to get * the effect of the parent that will be exherted on the owner */ - Mat4MulMat4(parmat, invmat, ct->matrix); + mul_m4_m4m4(parmat, invmat, ct->matrix); /* now multiply the parent matrix by the owner matrix to get the * the effect of this constraint (i.e. owner is 'parented' to parent) */ - Mat4CpyMat4(tempmat, cob->matrix); - Mat4MulMat4(cob->matrix, tempmat, parmat); + copy_m4_m4(tempmat, cob->matrix); + mul_m4_m4m4(cob->matrix, tempmat, parmat); } } @@ -929,14 +929,14 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh float neg = -1; int right_index; - VecCopyf(n, vec); - if (Normalize(n) == 0.0) { + copy_v3_v3(n, vec); + if (normalize_v3(n) == 0.0) { n[0] = 0.0; n[1] = 0.0; n[2] = 1.0; } if (axis > 2) axis -= 3; - else VecNegf(n); + else negate_v3(n); /* n specifies the transformation of the track axis */ if (flags & TARGET_Z_UP) { @@ -953,19 +953,19 @@ static void vectomat (float *vec, float *target_up, short axis, short upflag, sh } /* project the up vector onto the plane specified by n */ - Projf(proj, u, n); /* first u onto n... */ - VecSubf(proj, u, proj); /* then onto the plane */ + project_v3_v3v3(proj, u, n); /* first u onto n... */ + sub_v3_v3v3(proj, u, proj); /* then onto the plane */ /* proj specifies the transformation of the up axis */ - if (Normalize(proj) == 0.0) { /* degenerate projection */ + if (normalize_v3(proj) == 0.0) { /* degenerate projection */ proj[0] = 0.0; proj[1] = 1.0; proj[2] = 0.0; } /* Normalized cross product of n and proj specifies transformation of the right axis */ - Crossf(right, proj, n); - Normalize(right); + cross_v3_v3v3(right, proj, n); + normalize_v3(right); if (axis != upflag) { right_index = 3 - axis - upflag; @@ -1005,7 +1005,7 @@ static void trackto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float tmat[4][4]; /* Get size property, since ob->size is only the object's own relative size, not its global one */ - Mat4ToSize(cob->matrix, size); + mat4_to_size( size,cob->matrix); /* Clear the object's rotation */ cob->matrix[0][0]=size[0]; @@ -1021,13 +1021,13 @@ static void trackto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta /* targetmat[2] instead of ownermat[2] is passed to vectomat * for backwards compatability it seems... (Aligorith) */ - VecSubf(vec, cob->matrix[3], ct->matrix[3]); + sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]); vectomat(vec, ct->matrix[2], (short)data->reserved1, (short)data->reserved2, data->flags, totmat); - Mat4CpyMat4(tmat, cob->matrix); - Mat4MulMat34(cob->matrix, totmat, tmat); + copy_m4_m4(tmat, cob->matrix); + mul_m4_m3m4(cob->matrix, totmat, tmat); } } @@ -1098,19 +1098,19 @@ static void kinematic_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstra Object *ob= cob->ob; if (ob == NULL) { - Mat4One(ct->matrix); + unit_m4(ct->matrix); } else { float vec[3]; /* move grabtarget into world space */ VECCOPY(vec, data->grabtarget); - Mat4MulVecfl(ob->obmat, vec); - Mat4CpyMat4(ct->matrix, ob->obmat); + mul_m4_v3(ob->obmat, vec); + copy_m4_m4(ct->matrix, ob->obmat); VECCOPY(ct->matrix[3], vec); } } else - Mat4One(ct->matrix); + unit_m4(ct->matrix); } } @@ -1177,8 +1177,8 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr float totmat[4][4]; float curvetime; - Mat4One(totmat); - Mat4One(ct->matrix); + unit_m4(totmat); + unit_m4(ct->matrix); /* note: when creating constraints that follow path, the curve gets the CU_PATH set now, * currently for paths to work it needs to go through the bevlist/displist system (ton) @@ -1212,34 +1212,34 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr if ( where_on_path(ct->tar, curvetime, vec, dir, NULL, &radius) ) { if (data->followflag & FOLLOWPATH_FOLLOW) { - vectoquat(dir, (short) data->trackflag, (short) data->upflag, quat); + vec_to_quat( quat,dir, (short) data->trackflag, (short) data->upflag); - Normalize(dir); + normalize_v3(dir); q[0]= (float)cos(0.5*vec[3]); x1= (float)sin(0.5*vec[3]); q[1]= -x1*dir[0]; q[2]= -x1*dir[1]; q[3]= -x1*dir[2]; - QuatMul(quat, q, quat); + mul_qt_qtqt(quat, q, quat); - QuatToMat4(quat, totmat); + quat_to_mat4( totmat,quat); } if (data->followflag & FOLLOWPATH_RADIUS) { float tmat[4][4], rmat[4][4]; - Mat4Scale(tmat, radius); - Mat4MulMat4(rmat, totmat, tmat); - Mat4CpyMat4(totmat, rmat); + scale_m4_fl(tmat, radius); + mul_m4_m4m4(rmat, totmat, tmat); + copy_m4_m4(totmat, rmat); } VECCOPY(totmat[3], vec); - Mat4MulSerie(ct->matrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(ct->matrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL); } } } else if (ct) - Mat4One(ct->matrix); + unit_m4(ct->matrix); } static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) @@ -1254,25 +1254,25 @@ static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase /* get Object local transform (loc/rot/size) to determine transformation from path */ //object_to_mat4(ob, obmat); - Mat4CpyMat4(obmat, cob->matrix); // FIXME!!! + copy_m4_m4(obmat, cob->matrix); // FIXME!!! /* get scaling of object before applying constraint */ - Mat4ToSize(cob->matrix, size); + mat4_to_size( size,cob->matrix); /* apply targetmat - containing location on path, and rotation */ - Mat4MulSerie(cob->matrix, ct->matrix, obmat, NULL, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(cob->matrix, ct->matrix, obmat, NULL, NULL, NULL, NULL, NULL, NULL); /* un-apply scaling caused by path */ if ((data->followflag & FOLLOWPATH_RADIUS)==0) { /* XXX - assume that scale correction means that radius will have some scale error in it - Campbell */ float obsize[3]; - Mat4ToSize(cob->matrix, obsize); + mat4_to_size( obsize,cob->matrix); if (obsize[0]) - VecMulf(cob->matrix[0], size[0] / obsize[0]); + mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); if (obsize[1]) - VecMulf(cob->matrix[1], size[1] / obsize[1]); + mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); if (obsize[2]) - VecMulf(cob->matrix[2], size[2] / obsize[2]); + mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); } } } @@ -1350,9 +1350,9 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t float size[3]; VECCOPY(loc, cob->matrix[3]); - Mat4ToSize(cob->matrix, size); + mat4_to_size( size,cob->matrix); - Mat4ToEulO(cob->matrix, eul, cob->rotOrder); + mat4_to_eulO( eul, cob->rotOrder,cob->matrix); /* eulers: radians to degrees! */ eul[0] = (float)(eul[0] / M_PI * 180); @@ -1387,7 +1387,7 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t eul[1] = (float)(eul[1] / 180 * M_PI); eul[2] = (float)(eul[2] / 180 * M_PI); - LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder); + loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder); } static bConstraintTypeInfo CTI_ROTLIMIT = { @@ -1413,8 +1413,8 @@ static void sizelimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * bSizeLimitConstraint *data = con->data; float obsize[3], size[3]; - Mat4ToSize(cob->matrix, size); - Mat4ToSize(cob->matrix, obsize); + mat4_to_size( size,cob->matrix); + mat4_to_size( obsize,cob->matrix); if (data->flag & LIMIT_XMIN) { if (size[0] < data->xmin) @@ -1442,11 +1442,11 @@ static void sizelimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * } if (obsize[0]) - VecMulf(cob->matrix[0], size[0]/obsize[0]); + mul_v3_fl(cob->matrix[0], size[0]/obsize[0]); if (obsize[1]) - VecMulf(cob->matrix[1], size[1]/obsize[1]); + mul_v3_fl(cob->matrix[1], size[1]/obsize[1]); if (obsize[2]) - VecMulf(cob->matrix[2], size[2]/obsize[2]); + mul_v3_fl(cob->matrix[2], size[2]/obsize[2]); } static bConstraintTypeInfo CTI_SIZELIMIT = { @@ -1592,17 +1592,17 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float size[3]; VECCOPY(loc, cob->matrix[3]); - Mat4ToSize(cob->matrix, size); + mat4_to_size( size,cob->matrix); /* to allow compatible rotations, must get both rotations in the order of the owner... */ - Mat4ToEulO(ct->matrix, eul, cob->rotOrder); - Mat4ToEulO(cob->matrix, obeul, cob->rotOrder); + mat4_to_eulO( eul, cob->rotOrder,ct->matrix); + mat4_to_eulO( obeul, cob->rotOrder,cob->matrix); if ((data->flag & ROTLIKE_X)==0) eul[0] = obeul[0]; else { if (data->flag & ROTLIKE_OFFSET) - eulerO_rot(eul, obeul[0], 'x', cob->rotOrder); + rotate_eulO(eul, cob->rotOrder, 'x', obeul[0]); if (data->flag & ROTLIKE_X_INVERT) eul[0] *= -1; @@ -1612,7 +1612,7 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta eul[1] = obeul[1]; else { if (data->flag & ROTLIKE_OFFSET) - eulerO_rot(eul, obeul[1], 'y', cob->rotOrder); + rotate_eulO(eul, cob->rotOrder, 'y', obeul[1]); if (data->flag & ROTLIKE_Y_INVERT) eul[1] *= -1; @@ -1622,14 +1622,14 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta eul[2] = obeul[2]; else { if (data->flag & ROTLIKE_OFFSET) - eulerO_rot(eul, obeul[2], 'z', cob->rotOrder); + rotate_eulO(eul, cob->rotOrder, 'z', obeul[2]); if (data->flag & ROTLIKE_Z_INVERT) eul[2] *= -1; } compatible_eul(eul, obeul); - LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder); + loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder); } } @@ -1691,32 +1691,32 @@ static void sizelike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t if (VALID_CONS_TARGET(ct)) { float obsize[3], size[3]; - Mat4ToSize(ct->matrix, size); - Mat4ToSize(cob->matrix, obsize); + mat4_to_size( size,ct->matrix); + mat4_to_size( obsize,cob->matrix); if ((data->flag & SIZELIKE_X) && (obsize[0] != 0)) { if (data->flag & SIZELIKE_OFFSET) { size[0] += (obsize[0] - 1.0f); - VecMulf(cob->matrix[0], size[0] / obsize[0]); + mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); } else - VecMulf(cob->matrix[0], size[0] / obsize[0]); + mul_v3_fl(cob->matrix[0], size[0] / obsize[0]); } if ((data->flag & SIZELIKE_Y) && (obsize[1] != 0)) { if (data->flag & SIZELIKE_OFFSET) { size[1] += (obsize[1] - 1.0f); - VecMulf(cob->matrix[1], size[1] / obsize[1]); + mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); } else - VecMulf(cob->matrix[1], size[1] / obsize[1]); + mul_v3_fl(cob->matrix[1], size[1] / obsize[1]); } if ((data->flag & SIZELIKE_Z) && (obsize[2] != 0)) { if (data->flag & SIZELIKE_OFFSET) { size[2] += (obsize[2] - 1.0f); - VecMulf(cob->matrix[2], size[2] / obsize[2]); + mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); } else - VecMulf(cob->matrix[2], size[2] / obsize[2]); + mul_v3_fl(cob->matrix[2], size[2] / obsize[2]); } } } @@ -1817,7 +1817,7 @@ static void pycon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintT #endif } else if (ct) - Mat4One(ct->matrix); + unit_m4(ct->matrix); } static void pycon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) @@ -1912,7 +1912,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint short axis; /* initialise return matrix */ - Mat4One(ct->matrix); + unit_m4(ct->matrix); /* get the transform matrix of the target */ constraint_target_to_mat4(cob->scene, ct->tar, ct->subtarget, tempmat, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail); @@ -1925,7 +1925,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint */ if (data->type < 10) { /* extract rotation (is in whatever space target should be in) */ - Mat4ToEul(tempmat, vec); + mat4_to_eul( vec,tempmat); vec[0] *= (float)(180.0/M_PI); vec[1] *= (float)(180.0/M_PI); vec[2] *= (float)(180.0/M_PI); @@ -1933,7 +1933,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint } else if (data->type < 20) { /* extract scaling (is in whatever space target should be in) */ - Mat4ToSize(tempmat, vec); + mat4_to_size( vec,tempmat); axis= data->type - 10; } else { @@ -1968,7 +1968,7 @@ static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraint /* convert animation to matrices for use here */ chan_calc_mat(tchan); - Mat4CpyMat4(ct->matrix, tchan->chan_mat); + copy_m4_m4(ct->matrix, tchan->chan_mat); /* Clean up */ free_pose(pose); @@ -1998,8 +1998,8 @@ static void actcon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *tar /* Nice and simple... we just need to multiply the matrices, as the get_target_matrix * function has already taken care of everything else. */ - Mat4CpyMat4(temp, cob->matrix); - Mat4MulMat4(cob->matrix, ct->matrix, temp); + copy_m4_m4(temp, cob->matrix); + mul_m4_m4m4(cob->matrix, ct->matrix, temp); } } @@ -2068,7 +2068,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * float mdet; /* Vector object -> target */ - VecSubf(vec, ct->matrix[3], cob->matrix[3]); + sub_v3_v3v3(vec, ct->matrix[3], cob->matrix[3]); switch (data->lockflag){ case LOCK_X: /* LOCK X */ { @@ -2076,71 +2076,71 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * case TRACK_Y: /* LOCK X TRACK Y */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[0]); - VecSubf(totmat[1], vec, vec2); - Normalize(totmat[1]); + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); /* the x axis is fixed */ totmat[0][0] = cob->matrix[0][0]; totmat[0][1] = cob->matrix[0][1]; totmat[0][2] = cob->matrix[0][2]; - Normalize(totmat[0]); + normalize_v3(totmat[0]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[2], totmat[0], totmat[1]); + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); } break; case TRACK_Z: /* LOCK X TRACK Z */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[0]); - VecSubf(totmat[2], vec, vec2); - Normalize(totmat[2]); + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); /* the x axis is fixed */ totmat[0][0] = cob->matrix[0][0]; totmat[0][1] = cob->matrix[0][1]; totmat[0][2] = cob->matrix[0][2]; - Normalize(totmat[0]); + normalize_v3(totmat[0]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[1], totmat[2], totmat[0]); + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); } break; case TRACK_nY: /* LOCK X TRACK -Y */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[0]); - VecSubf(totmat[1], vec, vec2); - Normalize(totmat[1]); - VecNegf(totmat[1]); + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); + negate_v3(totmat[1]); /* the x axis is fixed */ totmat[0][0] = cob->matrix[0][0]; totmat[0][1] = cob->matrix[0][1]; totmat[0][2] = cob->matrix[0][2]; - Normalize(totmat[0]); + normalize_v3(totmat[0]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[2], totmat[0], totmat[1]); + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); } break; case TRACK_nZ: /* LOCK X TRACK -Z */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[0]); - VecSubf(totmat[2], vec, vec2); - Normalize(totmat[2]); - VecNegf(totmat[2]); + project_v3_v3v3(vec2, vec, cob->matrix[0]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); + negate_v3(totmat[2]); /* the x axis is fixed */ totmat[0][0] = cob->matrix[0][0]; totmat[0][1] = cob->matrix[0][1]; totmat[0][2] = cob->matrix[0][2]; - Normalize(totmat[0]); + normalize_v3(totmat[0]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[1], totmat[2], totmat[0]); + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); } break; default: @@ -2159,71 +2159,71 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * case TRACK_X: /* LOCK Y TRACK X */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[1]); - VecSubf(totmat[0], vec, vec2); - Normalize(totmat[0]); + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); /* the y axis is fixed */ totmat[1][0] = cob->matrix[1][0]; totmat[1][1] = cob->matrix[1][1]; totmat[1][2] = cob->matrix[1][2]; - Normalize(totmat[1]); + normalize_v3(totmat[1]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[2], totmat[0], totmat[1]); + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); } break; case TRACK_Z: /* LOCK Y TRACK Z */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[1]); - VecSubf(totmat[2], vec, vec2); - Normalize(totmat[2]); + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); /* the y axis is fixed */ totmat[1][0] = cob->matrix[1][0]; totmat[1][1] = cob->matrix[1][1]; totmat[1][2] = cob->matrix[1][2]; - Normalize(totmat[1]); + normalize_v3(totmat[1]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[0], totmat[1], totmat[2]); + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); } break; case TRACK_nX: /* LOCK Y TRACK -X */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[1]); - VecSubf(totmat[0], vec, vec2); - Normalize(totmat[0]); - VecNegf(totmat[0]); + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); + negate_v3(totmat[0]); /* the y axis is fixed */ totmat[1][0] = cob->matrix[1][0]; totmat[1][1] = cob->matrix[1][1]; totmat[1][2] = cob->matrix[1][2]; - Normalize(totmat[1]); + normalize_v3(totmat[1]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[2], totmat[0], totmat[1]); + cross_v3_v3v3(totmat[2], totmat[0], totmat[1]); } break; case TRACK_nZ: /* LOCK Y TRACK -Z */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[1]); - VecSubf(totmat[2], vec, vec2); - Normalize(totmat[2]); - VecNegf(totmat[2]); + project_v3_v3v3(vec2, vec, cob->matrix[1]); + sub_v3_v3v3(totmat[2], vec, vec2); + normalize_v3(totmat[2]); + negate_v3(totmat[2]); /* the y axis is fixed */ totmat[1][0] = cob->matrix[1][0]; totmat[1][1] = cob->matrix[1][1]; totmat[1][2] = cob->matrix[1][2]; - Normalize(totmat[1]); + normalize_v3(totmat[1]); /* the z axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[0], totmat[1], totmat[2]); + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); } break; default: @@ -2242,71 +2242,71 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * case TRACK_X: /* LOCK Z TRACK X */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[2]); - VecSubf(totmat[0], vec, vec2); - Normalize(totmat[0]); + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); /* the z axis is fixed */ totmat[2][0] = cob->matrix[2][0]; totmat[2][1] = cob->matrix[2][1]; totmat[2][2] = cob->matrix[2][2]; - Normalize(totmat[2]); + normalize_v3(totmat[2]); /* the x axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[1], totmat[2], totmat[0]); + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); } break; case TRACK_Y: /* LOCK Z TRACK Y */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[2]); - VecSubf(totmat[1], vec, vec2); - Normalize(totmat[1]); + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); /* the z axis is fixed */ totmat[2][0] = cob->matrix[2][0]; totmat[2][1] = cob->matrix[2][1]; totmat[2][2] = cob->matrix[2][2]; - Normalize(totmat[2]); + normalize_v3(totmat[2]); /* the x axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[0], totmat[1], totmat[2]); + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); } break; case TRACK_nX: /* LOCK Z TRACK -X */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[2]); - VecSubf(totmat[0], vec, vec2); - Normalize(totmat[0]); - VecNegf(totmat[0]); + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[0], vec, vec2); + normalize_v3(totmat[0]); + negate_v3(totmat[0]); /* the z axis is fixed */ totmat[2][0] = cob->matrix[2][0]; totmat[2][1] = cob->matrix[2][1]; totmat[2][2] = cob->matrix[2][2]; - Normalize(totmat[2]); + normalize_v3(totmat[2]); /* the x axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[1], totmat[2], totmat[0]); + cross_v3_v3v3(totmat[1], totmat[2], totmat[0]); } break; case TRACK_nY: /* LOCK Z TRACK -Y */ { /* Projection of Vector on the plane */ - Projf(vec2, vec, cob->matrix[2]); - VecSubf(totmat[1], vec, vec2); - Normalize(totmat[1]); - VecNegf(totmat[1]); + project_v3_v3v3(vec2, vec, cob->matrix[2]); + sub_v3_v3v3(totmat[1], vec, vec2); + normalize_v3(totmat[1]); + negate_v3(totmat[1]); /* the z axis is fixed */ totmat[2][0] = cob->matrix[2][0]; totmat[2][1] = cob->matrix[2][1]; totmat[2][2] = cob->matrix[2][2]; - Normalize(totmat[2]); + normalize_v3(totmat[2]); /* the x axis gets mapped onto a third orthogonal vector */ - Crossf(totmat[0], totmat[1], totmat[2]); + cross_v3_v3v3(totmat[0], totmat[1], totmat[2]); } break; default: @@ -2331,18 +2331,18 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * tmpmat[0][0] = cob->matrix[0][0];tmpmat[0][1] = cob->matrix[0][1];tmpmat[0][2] = cob->matrix[0][2]; tmpmat[1][0] = cob->matrix[1][0];tmpmat[1][1] = cob->matrix[1][1];tmpmat[1][2] = cob->matrix[1][2]; tmpmat[2][0] = cob->matrix[2][0];tmpmat[2][1] = cob->matrix[2][1];tmpmat[2][2] = cob->matrix[2][2]; - Normalize(tmpmat[0]); - Normalize(tmpmat[1]); - Normalize(tmpmat[2]); - Mat3Inv(invmat, tmpmat); - Mat3MulMat3(tmpmat, totmat, invmat); + normalize_v3(tmpmat[0]); + normalize_v3(tmpmat[1]); + normalize_v3(tmpmat[2]); + invert_m3_m3(invmat, tmpmat); + mul_m3_m3m3(tmpmat, totmat, invmat); totmat[0][0] = tmpmat[0][0];totmat[0][1] = tmpmat[0][1];totmat[0][2] = tmpmat[0][2]; totmat[1][0] = tmpmat[1][0];totmat[1][1] = tmpmat[1][1];totmat[1][2] = tmpmat[1][2]; totmat[2][0] = tmpmat[2][0];totmat[2][1] = tmpmat[2][1];totmat[2][2] = tmpmat[2][2]; - Mat4CpyMat4(tmat, cob->matrix); + copy_m4_m4(tmat, cob->matrix); - mdet = Det3x3( totmat[0][0],totmat[0][1],totmat[0][2], + mdet = determinant_m3( totmat[0][0],totmat[0][1],totmat[0][2], totmat[1][0],totmat[1][1],totmat[1][2], totmat[2][0],totmat[2][1],totmat[2][2]); if (mdet==0) { @@ -2352,7 +2352,7 @@ static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * } /* apply out transformaton to the object */ - Mat4MulMat34(cob->matrix, totmat, tmat); + mul_m4_m3m4(cob->matrix, totmat, tmat); } } @@ -2417,7 +2417,7 @@ static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * short clamp_surf= 0; /* calculate our current distance from the target */ - dist= VecLenf(cob->matrix[3], ct->matrix[3]); + dist= len_v3v3(cob->matrix[3], ct->matrix[3]); /* set distance (flag is only set when user demands it) */ if (data->dist == 0) @@ -2464,7 +2464,7 @@ static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * /* clamp to 'surface' (i.e. move owner so that dist == data->dist) */ if (clamp_surf) { /* simply interpolate along line formed by target -> owner */ - VecLerpf(dvec, ct->matrix[3], cob->matrix[3], sfac); + interp_v3_v3v3(dvec, ct->matrix[3], cob->matrix[3], sfac); /* copy new vector onto owner */ VECCOPY(cob->matrix[3], dvec); @@ -2538,27 +2538,27 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * float dist; /* store scaling before destroying obmat */ - Mat4ToSize(cob->matrix, size); + mat4_to_size( size,cob->matrix); /* store X orientation before destroying obmat */ xx[0] = cob->matrix[0][0]; xx[1] = cob->matrix[0][1]; xx[2] = cob->matrix[0][2]; - Normalize(xx); + normalize_v3(xx); /* store Z orientation before destroying obmat */ zz[0] = cob->matrix[2][0]; zz[1] = cob->matrix[2][1]; zz[2] = cob->matrix[2][2]; - Normalize(zz); + normalize_v3(zz); - VecSubf(vec, cob->matrix[3], ct->matrix[3]); + sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]); vec[0] /= size[0]; vec[1] /= size[1]; vec[2] /= size[2]; - dist = Normalize(vec); - //dist = VecLenf( ob->obmat[3], targetmat[3]); + dist = normalize_v3(vec); + //dist = len_v3v3( ob->obmat[3], targetmat[3]); /* data->orglength==0 occurs on first run, and after 'R' button is clicked */ if (data->orglength == 0) @@ -2601,8 +2601,8 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * cob->matrix[2][1]=0; cob->matrix[2][2]=size[2]*scale[2]; - VecSubf(vec, cob->matrix[3], ct->matrix[3]); - Normalize(vec); + sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]); + normalize_v3(vec); /* new Y aligns object target connection*/ totmat[1][0] = -vec[0]; @@ -2612,8 +2612,8 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * case PLANE_X: /* build new Z vector */ /* othogonal to "new Y" "old X! plane */ - Crossf(orth, vec, xx); - Normalize(orth); + cross_v3_v3v3(orth, vec, xx); + normalize_v3(orth); /* new Z*/ totmat[2][0] = orth[0]; @@ -2621,8 +2621,8 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * totmat[2][2] = orth[2]; /* we decided to keep X plane*/ - Crossf(xx, orth, vec); - Normalize(xx); + cross_v3_v3v3(xx, orth, vec); + normalize_v3(xx); totmat[0][0] = xx[0]; totmat[0][1] = xx[1]; totmat[0][2] = xx[2]; @@ -2630,8 +2630,8 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * case PLANE_Z: /* build new X vector */ /* othogonal to "new Y" "old Z! plane */ - Crossf(orth, vec, zz); - Normalize(orth); + cross_v3_v3v3(orth, vec, zz); + normalize_v3(orth); /* new X */ totmat[0][0] = -orth[0]; @@ -2639,16 +2639,16 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * totmat[0][2] = -orth[2]; /* we decided to keep Z */ - Crossf(zz, orth, vec); - Normalize(zz); + cross_v3_v3v3(zz, orth, vec); + normalize_v3(zz); totmat[2][0] = zz[0]; totmat[2][1] = zz[1]; totmat[2][2] = zz[2]; break; } /* switch (data->plane) */ - Mat4CpyMat4(tmat, cob->matrix); - Mat4MulMat34(cob->matrix, totmat, tmat); + copy_m4_m4(tmat, cob->matrix); + mul_m4_m3m4(cob->matrix, totmat, tmat); } } @@ -2716,15 +2716,15 @@ static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *tar float val1, val2; int index; - Mat4CpyMat4(obmat, cob->matrix); - Mat4CpyMat4(tarmat, ct->matrix); + copy_m4_m4(obmat, cob->matrix); + copy_m4_m4(tarmat, ct->matrix); if (data->flag & MINMAX_USEROT) { /* take rotation of target into account by doing the transaction in target's localspace */ - Mat4Invert(imat, tarmat); - Mat4MulMat4(tmat, obmat, imat); - Mat4CpyMat4(obmat, tmat); - Mat4One(tarmat); + invert_m4_m4(imat, tarmat); + mul_m4_m4m4(tmat, obmat, imat); + copy_m4_m4(obmat, tmat); + unit_m4(tarmat); } switch (data->minmaxflag) { @@ -2775,8 +2775,8 @@ static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *tar } if (data->flag & MINMAX_USEROT) { /* get out of localspace */ - Mat4MulMat4(tmat, obmat, ct->matrix); - Mat4CpyMat4(cob->matrix, tmat); + mul_m4_m4m4(tmat, obmat, ct->matrix); + copy_m4_m4(cob->matrix, tmat); } else { VECCOPY(cob->matrix[3], obmat[3]); @@ -2900,7 +2900,7 @@ static void clampto_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrain * might end up calling this... */ if (ct) - Mat4One(ct->matrix); + unit_m4(ct->matrix); } static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets) @@ -2914,8 +2914,8 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta float obmat[4][4], targetMatrix[4][4], ownLoc[3]; float curveMin[3], curveMax[3]; - Mat4CpyMat4(obmat, cob->matrix); - Mat4One(targetMatrix); + copy_m4_m4(obmat, cob->matrix); + unit_m4(targetMatrix); VECCOPY(ownLoc, obmat[3]); INIT_MINMAX(curveMin, curveMax) @@ -2931,7 +2931,7 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta /* 1. determine which axis to sample on? */ if (data->flag == CLAMPTO_AUTO) { float size[3]; - VecSubf(size, curveMax, curveMin); + sub_v3_v3v3(size, curveMax, curveMin); /* find axis along which the bounding box has the greatest * extent. Otherwise, default to the x-axis, as that is quite @@ -3004,10 +3004,10 @@ static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta /* 3. position on curve */ if (where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL) ) { - Mat4One(totmat); + unit_m4(totmat); VECCOPY(totmat[3], vec); - Mat4MulSerie(targetMatrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(targetMatrix, ct->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL); } } @@ -3082,22 +3082,22 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * /* obtain target effect */ switch (data->from) { case 2: /* scale */ - Mat4ToSize(ct->matrix, dvec); + mat4_to_size( dvec,ct->matrix); break; case 1: /* rotation (convert to degrees first) */ - Mat4ToEulO(ct->matrix, dvec, cob->rotOrder); + mat4_to_eulO( dvec, cob->rotOrder,ct->matrix); for (i=0; i<3; i++) dvec[i] = (float)(dvec[i] / M_PI * 180); break; default: /* location */ - VecCopyf(dvec, ct->matrix[3]); + copy_v3_v3(dvec, ct->matrix[3]); break; } /* extract components of owner's matrix */ VECCOPY(loc, cob->matrix[3]); - Mat4ToEulO(cob->matrix, eul, cob->rotOrder); - Mat4ToSize(cob->matrix, size); + mat4_to_eulO( eul, cob->rotOrder,cob->matrix); + mat4_to_size( size,cob->matrix); /* determine where in range current transforms lie */ if (data->expo) { @@ -3146,12 +3146,12 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * loc[i]= (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]))); /* add original location back on (so that it can still be moved) */ - VecAddf(loc, cob->matrix[3], loc); + add_v3_v3v3(loc, cob->matrix[3], loc); break; } /* apply to matrix */ - LocEulOSizeToMat4(cob->matrix, loc, eul, size, cob->rotOrder); + loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder); } } @@ -3223,7 +3223,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr hit.index = -1; hit.dist = 100000.0f; //TODO should use FLT_MAX.. but normal projection doenst yet supports it - Mat4One(ct->matrix); + unit_m4(ct->matrix); if(target != NULL) { @@ -3249,8 +3249,8 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr BLI_bvhtree_find_nearest(treeData.tree, co, &nearest, treeData.nearest_callback, &treeData); - dist = VecLenf(co, nearest.co); - VecLerpf(co, co, nearest.co, (dist - scon->dist)/dist); /* linear interpolation */ + dist = len_v3v3(co, nearest.co); + interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist)/dist); /* linear interpolation */ space_transform_invert(&transform, co); break; @@ -3265,7 +3265,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr break; } - Normalize(no); + normalize_v3(no); bvhtree_from_mesh_faces(&treeData, target, scon->dist, 4, 6); @@ -3295,7 +3295,7 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr } /* co is in local object coordinates, change it to global and update target position */ - VecMat4MulVecfl(co, cob->matrix, co); + mul_v3_m4v3(co, cob->matrix, co); VECCOPY(ct->matrix[3], co); } } @@ -3379,23 +3379,23 @@ static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * float rmat[3][3], tmat[4][4]; /* find the (unit) direction that the axis we're interested in currently points - * - Mat4Mul3Vecfl() only takes the 3x3 (rotation+scaling) components of the 4x4 matrix + * - mul_mat3_m4_v3() only takes the 3x3 (rotation+scaling) components of the 4x4 matrix * - the normalisation step at the end should take care of any unwanted scaling * left over in the 3x3 matrix we used */ VECCOPY(obvec, track_dir_vecs[data->trackflag]); - Mat4Mul3Vecfl(cob->matrix, obvec); + mul_mat3_m4_v3(cob->matrix, obvec); - if (Normalize(obvec) == 0.0f) { + if (normalize_v3(obvec) == 0.0f) { /* exceptional case - just use the track vector as appropriate */ VECCOPY(obvec, track_dir_vecs[data->trackflag]); } /* find the (unit) direction vector going from the owner to the target */ VECCOPY(obloc, cob->matrix[3]); - VecSubf(tarvec, ct->matrix[3], obloc); + sub_v3_v3v3(tarvec, ct->matrix[3], obloc); - if (Normalize(tarvec) == 0.0f) { + if (normalize_v3(tarvec) == 0.0f) { /* the target is sitting on the owner, so just make them use the same direction vectors */ // FIXME: or would it be better to use the pure direction vector? VECCOPY(tarvec, obvec); @@ -3410,23 +3410,23 @@ static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase * * - the min/max wrappers around (obvec . tarvec) result (stored temporarily in rangle) * are used to ensure that the smallest angle is chosen */ - Crossf(raxis, obvec, tarvec); + cross_v3_v3v3(raxis, obvec, tarvec); - rangle= Inpf(obvec, tarvec); + rangle= dot_v3v3(obvec, tarvec); rangle= acos( MAX2(-1.0f, MIN2(1.0f, rangle)) ); /* construct rotation matrix from the axis-angle rotation found above * - this call takes care to make sure that the axis provided is a unit vector first */ - AxisAngleToMat3(raxis, rangle, rmat); + axis_angle_to_mat3( rmat,raxis, rangle); /* rotate the owner in the way defined by this rotation matrix, then reapply the location since * we may have destroyed that in the process of multiplying the matrix */ - Mat4One(tmat); - Mat4MulMat34(tmat, rmat, cob->matrix); // m1, m3, m2 + unit_m4(tmat); + mul_m4_m3m4(tmat, rmat, cob->matrix); // m1, m3, m2 - Mat4CpyMat4(cob->matrix, tmat); + copy_m4_m4(cob->matrix, tmat); VECCOPY(cob->matrix[3], obloc); } } @@ -3510,7 +3510,7 @@ static void splineik_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstrai * might end up calling this... */ if (ct) - Mat4One(ct->matrix); + unit_m4(ct->matrix); } static bConstraintTypeInfo CTI_SPLINEIK = { @@ -3601,6 +3601,91 @@ bConstraintTypeInfo *constraint_get_typeinfo (bConstraint *con) return NULL; } +/* Creates a new constraint, initialises its data, and returns it */ +static bConstraint *add_new_constraint_internal(const char *name, short type) +{ + bConstraint *con; + bConstraintTypeInfo *cti; + + con = MEM_callocN(sizeof(bConstraint), "Constraint"); + + /* Set up a generic constraint datablock */ + con->type = type; + con->flag |= CONSTRAINT_EXPAND; + con->enforce = 1.0f; + + /* Load the data for it */ + cti = constraint_get_typeinfo(con); + if (cti) { + con->data = MEM_callocN(cti->size, cti->structName); + + /* only constraints that change any settings need this */ + if (cti->new_data) + cti->new_data(con->data); + + /* set the name based on the type of constraint */ + name= name ? name : cti->name; + } + else + name= name ? name : "Const"; + + strcpy(con->name, name); + + return con; +} + +/* if pchan is not NULL then assume we're adding a pose constraint */ +static bConstraint *add_new_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type) +{ + bConstraint *con; + ListBase *list; + + con= add_new_constraint_internal(name, type); + + if(pchan) list= &pchan->constraints; + else list= &ob->constraints; + + if (list) { + bConstraint *coniter; + + /* add new constraint to end of list of constraints before ensuring that it has a unique name + * (otherwise unique-naming code will fail, since it assumes element exists in list) + */ + BLI_addtail(list, con); + unique_constraint_name(con, list); + + /* if the target list is a list on some PoseChannel belonging to a proxy-protected + * Armature layer, we must tag newly added constraints with a flag which allows them + * to persist after proxy syncing has been done + */ + if (proxylocked_constraints_owner(ob, pchan)) + con->flag |= CONSTRAINT_PROXY_LOCAL; + + /* make this constraint the active one + * - since constraint was added at end of stack, we can just go + * through deactivating all previous ones + */ + con->flag |= CONSTRAINT_ACTIVE; + for (coniter= con->prev; coniter; coniter= coniter->prev) + coniter->flag &= ~CONSTRAINT_ACTIVE; + } + + return con; +} + +bConstraint *add_pose_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type) +{ + if(pchan==NULL) + return NULL; + + return add_new_constraint(ob, pchan, name, type); +} + +bConstraint *add_ob_constraint(Object *ob, const char *name, short type) +{ + return add_new_constraint(ob, NULL, name, type); +} + /* ************************* General Constraints API ************************** */ /* The functions here are called by various parts of Blender. Very few (should be none if possible) * constraint-specific code should occur here. @@ -3772,12 +3857,12 @@ void get_constraint_target_matrix (struct Scene *scene, bConstraint *con, int n, cob->ob= (Object *)ownerdata; cob->pchan= NULL; if (cob->ob) { - Mat4CpyMat4(cob->matrix, cob->ob->obmat); - Mat4CpyMat4(cob->startmat, cob->matrix); + copy_m4_m4(cob->matrix, cob->ob->obmat); + copy_m4_m4(cob->startmat, cob->matrix); } else { - Mat4One(cob->matrix); - Mat4One(cob->startmat); + unit_m4(cob->matrix); + unit_m4(cob->startmat); } } break; @@ -3786,12 +3871,12 @@ void get_constraint_target_matrix (struct Scene *scene, bConstraint *con, int n, cob->ob= NULL; /* this might not work at all :/ */ cob->pchan= (bPoseChannel *)ownerdata; if (cob->pchan) { - Mat4CpyMat4(cob->matrix, cob->pchan->pose_mat); - Mat4CpyMat4(cob->startmat, cob->matrix); + copy_m4_m4(cob->matrix, cob->pchan->pose_mat); + copy_m4_m4(cob->startmat, cob->matrix); } else { - Mat4One(cob->matrix); - Mat4One(cob->startmat); + unit_m4(cob->matrix); + unit_m4(cob->startmat); } } break; @@ -3808,7 +3893,7 @@ void get_constraint_target_matrix (struct Scene *scene, bConstraint *con, int n, if (ct) { if (cti->get_target_matrix) cti->get_target_matrix(con, cob, ct, ctime); - Mat4CpyMat4(mat, ct->matrix); + copy_m4_m4(mat, ct->matrix); } /* free targets + 'constraint-ob' */ @@ -3818,7 +3903,7 @@ void get_constraint_target_matrix (struct Scene *scene, bConstraint *con, int n, } else { /* invalid constraint - perhaps... */ - Mat4One(mat); + unit_m4(mat); } } @@ -3861,7 +3946,7 @@ void solve_constraints (ListBase *conlist, bConstraintOb *cob, float ctime) /* move owner matrix into right space */ constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace); - Mat4CpyMat4(oldmat, cob->matrix); + copy_m4_m4(oldmat, cob->matrix); /* prepare targets for constraint solving */ if (cti->get_constraint_targets) { @@ -3882,7 +3967,7 @@ void solve_constraints (ListBase *conlist, bConstraintOb *cob, float ctime) } else { for (ct= targets.first; ct; ct= ct->next) - Mat4One(ct->matrix); + unit_m4(ct->matrix); } } @@ -3899,21 +3984,21 @@ void solve_constraints (ListBase *conlist, bConstraintOb *cob, float ctime) /* Interpolate the enforcement, to blend result of constraint into final owner transform */ /* 1. Remove effects of original matrix from constraint solution ==> delta */ - Mat4Invert(imat, oldmat); - Mat4CpyMat4(solution, cob->matrix); - Mat4MulMat4(delta, solution, imat); + invert_m4_m4(imat, oldmat); + copy_m4_m4(solution, cob->matrix); + mul_m4_m4m4(delta, solution, imat); /* 2. If constraint influence is not full strength, then interpolate * identity_matrix --> delta_matrix to get the effect the constraint actually exerts */ if (enf < 1.0) { float identity[4][4]; - Mat4One(identity); - Mat4BlendMat4(delta, identity, delta, enf); + unit_m4(identity); + blend_m4_m4m4(delta, identity, delta, enf); } /* 3. Now multiply the delta by the matrix in use before the evaluation */ - Mat4MulMat4(cob->matrix, delta, oldmat); + mul_m4_m4m4(cob->matrix, delta, oldmat); /* move owner back into worldspace for next constraint/other business */ if ((con->flag & CONSTRAINT_SPACEONCE) == 0) diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 7f2872c0797..21549f6b147 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -46,6 +46,8 @@ #include "BKE_screen.h" #include "BKE_global.h" +#include "BPY_extern.h" + #include <string.h> /* struct */ @@ -408,16 +410,26 @@ struct bContextDataResult { static int ctx_data_get(bContext *C, const char *member, bContextDataResult *result) { int done= 0, recursion= C->data.recursion; + int ret= 0; memset(result, 0, sizeof(bContextDataResult)); if(CTX_py_dict_get(C)) { - return bpy_context_get(C, member, result); + return BPY_context_get(C, member, result); +// if (BPY_context_get(C, member, result)) +// return 1; } /* we check recursion to ensure that we do not get infinite * loops requesting data from ourselfs in a context callback */ - if(!done && recursion < 1 && C->wm.store) { + + /* Ok, this looks evil... + * if(ret) done= -(-ret | -done); + * + * Values in order of importance + * (0, -1, 1) - Where 1 is highest priority + * */ + if(done!=1 && recursion < 1 && C->wm.store) { bContextStoreEntry *entry; C->data.recursion= 1; @@ -429,21 +441,28 @@ static int ctx_data_get(bContext *C, const char *member, bContextDataResult *res } } } - if(!done && recursion < 2 && C->wm.region) { + if(done!=1 && recursion < 2 && C->wm.region) { C->data.recursion= 2; - if(C->wm.region->type && C->wm.region->type->context) - done= C->wm.region->type->context(C, member, result); + if(C->wm.region->type && C->wm.region->type->context) { + ret = C->wm.region->type->context(C, member, result); + if(ret) done= -(-ret | -done); + + } } - if(!done && recursion < 3 && C->wm.area) { + if(done!=1 && recursion < 3 && C->wm.area) { C->data.recursion= 3; - if(C->wm.area->type && C->wm.area->type->context) - done= C->wm.area->type->context(C, member, result); + if(C->wm.area->type && C->wm.area->type->context) { + ret = C->wm.area->type->context(C, member, result); + if(ret) done= -(-ret | -done); + } } - if(!done && recursion < 4 && C->wm.screen) { + if(done!=1 && recursion < 4 && C->wm.screen) { bContextDataCallback cb= C->wm.screen->context; C->data.recursion= 4; - if(cb) - done= cb(C, member, result); + if(cb) { + ret = cb(C, member, result); + if(ret) done= -(-ret | -done); + } } C->data.recursion= recursion; @@ -455,7 +474,7 @@ static void *ctx_data_pointer_get(const bContext *C, const char *member) { bContextDataResult result; - if(C && ctx_data_get((bContext*)C, member, &result)) + if(C && ctx_data_get((bContext*)C, member, &result)==1) return result.ptr.data; return NULL; @@ -465,7 +484,7 @@ static int ctx_data_pointer_verify(const bContext *C, const char *member, void * { bContextDataResult result; - if(ctx_data_get((bContext*)C, member, &result)) { + if(ctx_data_get((bContext*)C, member, &result)==1) { *pointer= result.ptr.data; return 1; } @@ -479,7 +498,7 @@ static int ctx_data_collection_get(const bContext *C, const char *member, ListBa { bContextDataResult result; - if(ctx_data_get((bContext*)C, member, &result)) { + if(ctx_data_get((bContext*)C, member, &result)==1) { *list= result.list; return 1; } @@ -494,7 +513,7 @@ PointerRNA CTX_data_pointer_get(const bContext *C, const char *member) { bContextDataResult result; - if(ctx_data_get((bContext*)C, member, &result)) + if(ctx_data_get((bContext*)C, member, &result)==1) return result.ptr; else return PointerRNA_NULL; @@ -514,7 +533,7 @@ ListBase CTX_data_collection_get(const bContext *C, const char *member) { bContextDataResult result; - if(ctx_data_get((bContext*)C, member, &result)) { + if(ctx_data_get((bContext*)C, member, &result)==1) { return result.list; } else { @@ -524,11 +543,13 @@ ListBase CTX_data_collection_get(const bContext *C, const char *member) } } -void CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb) +/* 1:found, -1:found but not set, 0:not found */ +int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb) { bContextDataResult result; + int ret= ctx_data_get((bContext*)C, member, &result); - if(ctx_data_get((bContext*)C, member, &result)) { + if(ret==1) { *r_ptr= result.ptr; *r_lb= result.list; } @@ -536,6 +557,8 @@ void CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, List memset(r_ptr, 0, sizeof(*r_ptr)); memset(r_lb, 0, sizeof(*r_lb)); } + + return ret; } static void data_dir_add(ListBase *lb, const char *member) diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 1410e5d29c2..83e2e0c29d9 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_object_types.h" #include "DNA_curve_types.h" @@ -992,7 +992,7 @@ static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float for(i=0; i<3; i++) { p[i]= (-6*t + 6)*p0[i] + (18*t - 12)*p1[i] + (-18*t + 6)*p2[i] + (6*t)*p3[i]; } - Normalize(p); + normalize_v3(p); p = (float *)(((char *)p)+stride); } } @@ -1598,7 +1598,7 @@ static void bevel_list_calc_bisect(BevList *bl) nr= bl->nr; while(nr--) { /* totally simple */ - VecBisect3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); + bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); bevp0= bevp1; bevp1= bevp2; @@ -1616,8 +1616,8 @@ static void bevel_list_flip_tangents(BevList *bl) nr= bl->nr; while(nr--) { - if(RAD2DEG(VecAngle2(bevp0->tan, bevp1->tan)) > 90) - VecNegf(bevp1->tan); + if(RAD2DEG(angle_v2v2(bevp0->tan, bevp1->tan)) > 90) + negate_v3(bevp1->tan); bevp0= bevp1; bevp1= bevp2; @@ -1637,9 +1637,9 @@ static void bevel_list_apply_tilt(BevList *bl) nr= bl->nr; while(nr--) { - AxisAngleToQuat(q, bevp1->dir, bevp1->alfa); - QuatMul(bevp1->quat, q, bevp1->quat); - NormalQuat(bevp1->quat); + axis_angle_to_quat(q, bevp1->dir, bevp1->alfa); + mul_qt_qtqt(bevp1->quat, q, bevp1->quat); + normalize_qt(bevp1->quat); bevp0= bevp1; bevp1= bevp2; @@ -1683,18 +1683,18 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter) while(nr--) { /* interpolate quats */ float zaxis[3] = {0,0,1}, cross[3], q2[4]; - QuatInterpol(q, bevp0_quat, bevp2->quat, 0.5); - NormalQuat(q); + interp_qt_qtqt(q, bevp0_quat, bevp2->quat, 0.5); + normalize_qt(q); - QuatMulVecf(q, zaxis); - Crossf(cross, zaxis, bevp1->dir); - AxisAngleToQuat(q2, cross, NormalizedVecAngle2(zaxis, bevp1->dir)); - NormalQuat(q2); + mul_qt_v3(q, zaxis); + cross_v3_v3v3(cross, zaxis, bevp1->dir); + axis_angle_to_quat(q2, cross, angle_normalized_v3v3(zaxis, bevp1->dir)); + normalize_qt(q2); QUATCOPY(bevp0_quat, bevp1->quat); - QuatMul(q, q2, q); - QuatInterpol(bevp1->quat, bevp1->quat, q, 0.5); - NormalQuat(bevp1->quat); + mul_qt_qtqt(q, q2, q); + interp_qt_qtqt(bevp1->quat, bevp1->quat, q, 0.5); + normalize_qt(bevp1->quat); bevp0= bevp1; @@ -1716,8 +1716,8 @@ static void make_bevel_list_3D_zup(BevList *bl) nr= bl->nr; while(nr--) { /* totally simple */ - VecBisect3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); - vectoquat(bevp1->dir, 5, 1, bevp1->quat); + bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec); + vec_to_quat( bevp1->quat,bevp1->dir, 5, 1); bevp0= bevp1; bevp1= bevp2; @@ -1743,15 +1743,15 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) while(nr--) { if(nr+4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */ - vectoquat(bevp1->dir, 5, 1, bevp1->quat); + vec_to_quat( bevp1->quat,bevp1->dir, 5, 1); } else { - float angle= NormalizedVecAngle2(bevp0->dir, bevp1->dir); + float angle= angle_normalized_v3v3(bevp0->dir, bevp1->dir); if(angle > 0.0f) { /* otherwise we can keep as is */ - Crossf(cross_tmp, bevp0->dir, bevp1->dir); - AxisAngleToQuat(q, cross_tmp, angle); - QuatMul(bevp1->quat, q, bevp0->quat); + cross_v3_v3v3(cross_tmp, bevp0->dir, bevp1->dir); + axis_angle_to_quat(q, cross_tmp, angle); + mul_qt_qtqt(bevp1->quat, q, bevp0->quat); } else { QUATCOPY(bevp1->quat, bevp0->quat); @@ -1788,26 +1788,26 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) bevp_last--; /* quats and vec's are normalized, should not need to re-normalize */ - QuatMulVecf(bevp_first->quat, vec_1); - QuatMulVecf(bevp_last->quat, vec_2); - Normalize(vec_1); - Normalize(vec_2); + mul_qt_v3(bevp_first->quat, vec_1); + mul_qt_v3(bevp_last->quat, vec_2); + normalize_v3(vec_1); + normalize_v3(vec_2); /* align the vector, can avoid this and it looks 98% OK but * better to align the angle quat roll's before comparing */ { - Crossf(cross_tmp, bevp_last->dir, bevp_first->dir); - angle = NormalizedVecAngle2(bevp_first->dir, bevp_last->dir); - AxisAngleToQuat(q, cross_tmp, angle); - QuatMulVecf(q, vec_2); + cross_v3_v3v3(cross_tmp, bevp_last->dir, bevp_first->dir); + angle = angle_normalized_v3v3(bevp_first->dir, bevp_last->dir); + axis_angle_to_quat(q, cross_tmp, angle); + mul_qt_v3(q, vec_2); } - angle= NormalizedVecAngle2(vec_1, vec_2); + angle= angle_normalized_v3v3(vec_1, vec_2); /* flip rotation if needs be */ - Crossf(cross_tmp, vec_1, vec_2); - Normalize(cross_tmp); - if(NormalizedVecAngle2(bevp_first->dir, cross_tmp) < 90/(180.0/M_PI)) + cross_v3_v3v3(cross_tmp, vec_1, vec_2); + normalize_v3(cross_tmp); + if(angle_normalized_v3v3(bevp_first->dir, cross_tmp) < 90/(180.0/M_PI)) angle = -angle; bevp2= (BevPoint *)(bl+1); @@ -1818,8 +1818,8 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl) while(nr--) { ang_fac= angle * (1.0f-((float)nr/bl->nr)); /* also works */ - AxisAngleToQuat(q, bevp1->dir, ang_fac); - QuatMul(bevp1->quat, q, bevp1->quat); + axis_angle_to_quat(q, bevp1->dir, ang_fac); + mul_qt_qtqt(bevp1->quat, q, bevp1->quat); bevp0= bevp1; bevp1= bevp2; @@ -1848,9 +1848,9 @@ static void make_bevel_list_3D_tangent(BevList *bl) nr= bl->nr; while(nr--) { - Crossf(cross_tmp, bevp1->tan, bevp1->dir); - Crossf(bevp1->tan, cross_tmp, bevp1->dir); - Normalize(bevp1->tan); + cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir); + cross_v3_v3v3(bevp1->tan, cross_tmp, bevp1->dir); + normalize_v3(bevp1->tan); bevp0= bevp1; bevp1= bevp2; @@ -1872,9 +1872,9 @@ static void make_bevel_list_3D_tangent(BevList *bl) float cross_tmp[3]; float zero[3] = {0,0,0}; - Crossf(cross_tmp, bevp1->tan, bevp1->dir); - Normalize(cross_tmp); - triatoquat(zero, cross_tmp, bevp1->tan, bevp1->quat); /* XXX - could be faster */ + cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir); + normalize_v3(cross_tmp); + tri_to_quat( bevp1->quat,zero, cross_tmp, bevp1->tan); /* XXX - could be faster */ bevp0= bevp1; bevp1= bevp2; @@ -2280,14 +2280,14 @@ void makeBevelList(Object *ob) bevp1= bevp2+1; /* simple quat/dir */ - VecSubf(bevp1->dir, bevp1->vec, bevp2->vec); - Normalize(bevp1->dir); + sub_v3_v3v3(bevp1->dir, bevp1->vec, bevp2->vec); + normalize_v3(bevp1->dir); - vectoquat(bevp1->dir, 5, 1, bevp1->quat); + vec_to_quat( bevp1->quat,bevp1->dir, 5, 1); - AxisAngleToQuat(q, bevp1->dir, bevp1->alfa); - QuatMul(bevp1->quat, q, bevp1->quat); - NormalQuat(bevp1->quat); + axis_angle_to_quat(q, bevp1->dir, bevp1->alfa); + mul_qt_qtqt(bevp1->quat, q, bevp1->quat); + normalize_qt(bevp1->quat); VECCOPY(bevp2->dir, bevp1->dir); QUATCOPY(bevp2->quat, bevp1->quat); } @@ -2421,10 +2421,10 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) if(leftviolate || rightviolate) { /* align left handle */ float h1[3], h2[3]; - VecSubf(h1, p2-3, p2); - VecSubf(h2, p2, p2+3); - len1= Normalize(h1); - len2= Normalize(h2); + sub_v3_v3v3(h1, p2-3, p2); + sub_v3_v3v3(h2, p2, p2+3); + len1= normalize_v3(h1); + len2= normalize_v3(h2); vz= INPR(h1, h2); @@ -2460,8 +2460,8 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode) *(p2+5)= *(p2+2)+dz1; } - len2= VecLenf(p2, p2+3); - len1= VecLenf(p2, p2-3); + len2= len_v3v3(p2, p2+3); + len1= len_v3v3(p2, p2-3); if(len1==0.0) len1=1.0; if(len2==0.0) len2=1.0; @@ -2588,18 +2588,18 @@ void autocalchandlesNurb(Nurb *nu, int flag) if(flag==0 || (bezt1->f1 & flag) ) { bezt1->h1= 0; /* distance too short: vectorhandle */ - if( VecLenf( bezt1->vec[1], bezt0->vec[1] ) < 0.0001) { + if( len_v3v3( bezt1->vec[1], bezt0->vec[1] ) < 0.0001) { bezt1->h1= HD_VECT; leftsmall= 1; } else { /* aligned handle? */ - if(DistVL2Dfl(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001) { + if(dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001) { align= 1; bezt1->h1= HD_ALIGN; } /* or vector handle? */ - if(DistVL2Dfl(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001) + if(dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001) bezt1->h1= HD_VECT; } @@ -2608,7 +2608,7 @@ void autocalchandlesNurb(Nurb *nu, int flag) if(flag==0 || (bezt1->f3 & flag) ) { bezt1->h2= 0; /* distance too short: vectorhandle */ - if( VecLenf( bezt1->vec[1], bezt2->vec[1] ) < 0.0001) { + if( len_v3v3( bezt1->vec[1], bezt2->vec[1] ) < 0.0001) { bezt1->h2= HD_VECT; rightsmall= 1; } @@ -2617,7 +2617,7 @@ void autocalchandlesNurb(Nurb *nu, int flag) if(align) bezt1->h2= HD_ALIGN; /* or vector handle? */ - if(DistVL2Dfl(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001) + if(dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001) bezt1->h2= HD_VECT; } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 28aaadea9c3..7b754025b6c 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -34,7 +34,7 @@ #include "BKE_customdata.h" #include "BKE_utildefines.h" // CLAMP -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_linklist.h" #include "BLI_mempool.h" @@ -410,21 +410,21 @@ static void mdisps_bilinear(float out[3], float (*disps)[3], int st, float u, fl vrat = v - y; uopp = 1 - urat; - VecCopyf(d[0], disps[y * st + x]); - VecCopyf(d[1], disps[y * st + x2]); - VecCopyf(d[2], disps[y2 * st + x]); - VecCopyf(d[3], disps[y2 * st + x2]); - VecMulf(d[0], uopp); - VecMulf(d[1], urat); - VecMulf(d[2], uopp); - VecMulf(d[3], urat); + copy_v3_v3(d[0], disps[y * st + x]); + copy_v3_v3(d[1], disps[y * st + x2]); + copy_v3_v3(d[2], disps[y2 * st + x]); + copy_v3_v3(d[3], disps[y2 * st + x2]); + mul_v3_fl(d[0], uopp); + mul_v3_fl(d[1], urat); + mul_v3_fl(d[2], uopp); + mul_v3_fl(d[3], urat); - VecAddf(d2[0], d[0], d[1]); - VecAddf(d2[1], d[2], d[3]); - VecMulf(d2[0], 1 - vrat); - VecMulf(d2[1], vrat); + add_v3_v3v3(d2[0], d[0], d[1]); + add_v3_v3v3(d2[1], d[2], d[3]); + mul_v3_fl(d2[0], 1 - vrat); + mul_v3_fl(d2[1], vrat); - VecAddf(out, d2[0], d2[1]); + add_v3_v3v3(out, d2[0], d2[1]); } static void layerSwap_mdisps(void *data, int *ci) @@ -440,7 +440,7 @@ static void layerSwap_mdisps(void *data, int *ci) for(y = 0; y < st; ++y) { for(x = 0; x < st; ++x) { - VecCopyf(d[(st - y - 1) * st + (st - x - 1)], s->disps[y * st + x]); + copy_v3_v3(d[(st - y - 1) * st + (st - x - 1)], s->disps[y * st + x]); } } @@ -462,7 +462,7 @@ static void layerInterp_mdisps(void **sources, float *weights, float *sub_weight /* Initialize the destination */ for(i = 0; i < d->totdisp; ++i) { float z[3] = {0,0,0}; - VecCopyf(d->disps[i], z); + copy_v3_v3(d->disps[i], z); } /* For now, some restrictions on the input */ @@ -493,7 +493,7 @@ static void layerInterp_mdisps(void **sources, float *weights, float *sub_weight float srcdisp[3]; mdisps_bilinear(srcdisp, s->disps, st, mid3[0], mid3[1]); - VecCopyf(d->disps[y * st + x], srcdisp); + copy_v3_v3(d->disps[y * st + x], srcdisp); } } } diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index b7949a6e06f..c1e45243bb5 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -59,7 +59,7 @@ #include "BKE_mesh.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #ifdef HAVE_CONFIG_H #include <config.h> diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 36568ee5667..8b848ac5371 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -34,7 +34,7 @@ #endif #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 64af08d6f6a..48fb283c404 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -56,7 +56,7 @@ #include "DNA_key_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_edgehash.h" @@ -220,12 +220,12 @@ void addnormalsDispList(Object *ob, ListBase *lb) for(; b<dl->nr; b++) { - CalcNormFloat4(v1, v3, v4, v2, nor); + normal_quad_v3( nor,v1, v3, v4, v2); - VecAddf(n1, n1, nor); - VecAddf(n2, n2, nor); - VecAddf(n3, n3, nor); - VecAddf(n4, n4, nor); + add_v3_v3v3(n1, n1, nor); + add_v3_v3v3(n2, n2, nor); + add_v3_v3v3(n3, n3, nor); + add_v3_v3v3(n4, n4, nor); v2= v1; v1+= 3; v4= v3; v3+= 3; @@ -236,7 +236,7 @@ void addnormalsDispList(Object *ob, ListBase *lb) a= dl->parts*dl->nr; v1= ndata; while(a--) { - Normalize(v1); + normalize_v3(v1); v1+= 3; } } @@ -475,11 +475,11 @@ static void init_fastshade_for_ob(Render *re, Object *ob, int *need_orco_r, floa init_fastshade_shadeinput(re); RE_DataBase_GetView(re, tmat); - Mat4MulMat4(mat, ob->obmat, tmat); + mul_m4_m4m4(mat, ob->obmat, tmat); - Mat4Invert(tmat, mat); - Mat3CpyMat4(imat, tmat); - if(ob->transflag & OB_NEG_SCALE) Mat3MulFloat((float *)imat, -1.0); + invert_m4_m4(tmat, mat); + copy_m3_m4(imat, tmat); + if(ob->transflag & OB_NEG_SCALE) mul_m3_fl(imat, -1.0); if (need_orco_r) *need_orco_r= 0; for(a=0; a<ob->totcol; a++) { @@ -563,7 +563,7 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un vn[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn; vn[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn; vn[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn; - Normalize(vn); + normalize_v3(vn); } for (i=0; i<totface; i++) { @@ -586,15 +586,15 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un VECCOPY(nor, &nors[i*3]); } else { if (mf->v4) - CalcNormFloat4(mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co, mvert[mf->v4].co, nor); + normal_quad_v3( nor,mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co, mvert[mf->v4].co); else - CalcNormFloat(mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co, nor); + normal_tri_v3( nor,mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co); } n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2]; n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2]; n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2]; - Normalize(n1); + normalize_v3(n1); for (j=0; j<nverts; j++) { MVert *mv= &mvert[vidx[j]]; @@ -603,7 +603,7 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un float *vn = (mf->flag & ME_SMOOTH)?&vnors[3*vidx[j]]:n1; VECCOPY(vec, mv->co); - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); vec[0]+= 0.001*vn[0]; vec[1]+= 0.001*vn[1]; vec[2]+= 0.001*vn[2]; @@ -708,14 +708,14 @@ void shadeDispList(Scene *scene, Base *base) n1[0]= imat[0][0]*dl->nors[0]+imat[0][1]*dl->nors[1]+imat[0][2]*dl->nors[2]; n1[1]= imat[1][0]*dl->nors[0]+imat[1][1]*dl->nors[1]+imat[1][2]*dl->nors[2]; n1[2]= imat[2][0]*dl->nors[0]+imat[2][1]*dl->nors[1]+imat[2][2]*dl->nors[2]; - Normalize(n1); + normalize_v3(n1); fp= dl->verts; a= dl->nr; while(a--) { VECCOPY(vec, fp); - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); fastshade(vec, n1, fp, ma, (char *)col1, NULL); @@ -731,12 +731,12 @@ void shadeDispList(Scene *scene, Base *base) while(a--) { VECCOPY(vec, fp); - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2]; n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2]; n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2]; - Normalize(n1); + normalize_v3(n1); fastshade(vec, n1, fp, ma, (char *)col1, NULL); @@ -769,13 +769,13 @@ void shadeDispList(Scene *scene, Base *base) a= dl->nr; while(a--) { VECCOPY(vec, fp); - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); /* transpose ! */ n1[0]= imat[0][0]*nor[0]+imat[0][1]*nor[1]+imat[0][2]*nor[2]; n1[1]= imat[1][0]*nor[0]+imat[1][1]*nor[1]+imat[1][2]*nor[2]; n1[2]= imat[2][0]*nor[0]+imat[2][1]*nor[1]+imat[2][2]*nor[2]; - Normalize(n1); + normalize_v3(n1); fastshade(vec, n1, fp, ma, (char *)col1, NULL); @@ -1612,7 +1612,7 @@ void makeDispListCurveTypes(Scene *scene, Object *ob, int forOrco) vec[1]= fp1[2]; vec[2]= 0.0; - QuatMulVecf(bevp->quat, vec); + mul_qt_v3(bevp->quat, vec); data[0]= bevp->vec[0] + fac*vec[0]; data[1]= bevp->vec[1] + fac*vec[1]; diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 9b648e2c05c..6d63553396d 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -52,7 +52,7 @@ #include "DNA_texture_types.h" #include "DNA_scene_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_jitter.h" #include "BLI_listbase.h" @@ -221,8 +221,8 @@ static void precalculate_effector(EffectorCache *eff) if(cu->path && cu->path->data) { where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius); - Mat4MulVecfl(eff->ob->obmat, eff->guide_loc); - Mat4Mul3Vecfl(eff->ob->obmat, eff->guide_dir); + mul_m4_v3(eff->ob->obmat, eff->guide_loc); + mul_mat3_m4_v3(eff->ob->obmat, eff->guide_dir); } } } @@ -433,8 +433,8 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect return visibility; VECCOPY(norm, efd->vec_to_point); - VecNegf(norm); - len = Normalize(norm); + negate_v3(norm); + len = normalize_v3(norm); // check all collision objects for(col = colls->first; col; col = col->next) @@ -520,7 +520,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *poi float falloff = weights ? weights->weight[0] * weights->weight[eff->pd->forcefield] : 1.0f; float fac, r_fac; - fac = Inpf(efd->nor, efd->vec_to_point2); + fac = dot_v3v3(efd->nor, efd->vec_to_point2); if(eff->pd->zdir == PFIELD_Z_POS && fac < 0.0f) falloff=0.0f; @@ -537,7 +537,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *poi break; VECADDFAC(temp, efd->vec_to_point, efd->nor, -fac); - r_fac= VecLength(temp); + r_fac= len_v3(temp); falloff*= falloff_func_rad(eff->pd, r_fac); break; case PFIELD_FALL_CONE: @@ -545,7 +545,7 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *poi if(falloff == 0.0f) break; - r_fac=saacos(fac/VecLength(efd->vec_to_point))*180.0f/(float)M_PI; + r_fac=saacos(fac/len_v3(efd->vec_to_point))*180.0f/(float)M_PI; falloff*= falloff_func_rad(eff->pd, r_fac); break; @@ -574,12 +574,12 @@ int closest_point_on_surface(SurfaceModifierData *surmd, float *co, float *surfa MFace *mface = CDDM_get_face(surmd->dm, nearest.index); VECCOPY(surface_vel, surmd->v[mface->v1].co); - VecAddf(surface_vel, surface_vel, surmd->v[mface->v2].co); - VecAddf(surface_vel, surface_vel, surmd->v[mface->v3].co); + add_v3_v3v3(surface_vel, surface_vel, surmd->v[mface->v2].co); + add_v3_v3v3(surface_vel, surface_vel, surmd->v[mface->v3].co); if(mface->v4) - VecAddf(surface_vel, surface_vel, surmd->v[mface->v4].co); + add_v3_v3v3(surface_vel, surface_vel, surmd->v[mface->v4].co); - VecMulf(surface_vel, mface->v4 ? 0.25f : 0.333f); + mul_v3_fl(surface_vel, mface->v4 ? 0.25f : 0.333f); } return 1; } @@ -596,9 +596,9 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin float vec[3]; /* using velocity corrected location allows for easier sliding over effector surface */ - VecCopyf(vec, point->vel); - VecMulf(vec, point->vel_to_frame); - VecAddf(vec, vec, point->loc); + copy_v3_v3(vec, point->vel); + mul_v3_fl(vec, point->vel_to_frame); + add_v3_v3v3(vec, vec, point->loc); ret = closest_point_on_surface(eff->surmd, vec, efd->loc, efd->nor, real_velocity ? efd->vel : NULL); @@ -612,10 +612,10 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin dm->getVertCo(dm, *efd->index, efd->loc); dm->getVertNo(dm, *efd->index, efd->nor); - Mat4MulVecfl(eff->ob->obmat, efd->loc); - Mat4Mul3Vecfl(eff->ob->obmat, efd->nor); + mul_m4_v3(eff->ob->obmat, efd->loc); + mul_mat3_m4_v3(eff->ob->obmat, efd->nor); - Normalize(efd->nor); + normalize_v3(efd->nor); efd->size = 0.0f; @@ -660,15 +660,15 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin /* use z-axis as normal*/ VECCOPY(efd->nor, ob->obmat[2]); - Normalize(efd->nor); + normalize_v3(efd->nor); /* for vortex the shape chooses between old / new force */ if(eff->pd->shape == PFIELD_SHAPE_PLANE) { /* efd->loc is closes point on effector xy-plane */ float temp[3]; - VecSubf(temp, point->loc, ob->obmat[3]); - Projf(efd->loc, temp, efd->nor); - VecSubf(efd->loc, point->loc, efd->loc); + sub_v3_v3v3(temp, point->loc, ob->obmat[3]); + project_v3_v3v3(efd->loc, temp, efd->nor); + sub_v3_v3v3(efd->loc, point->loc, efd->loc); } else { VECCOPY(efd->loc, ob->obmat[3]); @@ -679,7 +679,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin where_is_object_time(eff->scene, ob, cfra - 1.0); - VecSubf(efd->vel, efd->vel, ob->obmat[3]); + sub_v3_v3v3(efd->vel, efd->vel, ob->obmat[3]); } *eff->ob = obcopy; @@ -690,8 +690,8 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin } if(ret) { - VecSubf(efd->vec_to_point, point->loc, efd->loc); - efd->distance = VecLength(efd->vec_to_point); + sub_v3_v3v3(efd->vec_to_point, point->loc, efd->loc); + efd->distance = len_v3(efd->vec_to_point); if(eff->flag & PE_USE_NORMAL_DATA) { VECCOPY(efd->vec_to_point2, efd->vec_to_point); @@ -699,9 +699,9 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin } else { /* for some effectors we need the object center every time */ - VecSubf(efd->vec_to_point2, point->loc, eff->ob->obmat[3]); + sub_v3_v3v3(efd->vec_to_point2, point->loc, eff->ob->obmat[3]); VECCOPY(efd->nor2, eff->ob->obmat[2]); - Normalize(efd->nor2); + normalize_v3(efd->nor2); } } @@ -764,12 +764,12 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP VECCOPY(tex_co,point->loc); if(eff->pd->flag & PFIELD_TEX_2D) { - float fac=-Inpf(tex_co, efd->nor); + float fac=-dot_v3v3(tex_co, efd->nor); VECADDFAC(tex_co, tex_co, efd->nor, fac); } if(eff->pd->flag & PFIELD_TEX_OBJECT) { - Mat4Mul3Vecfl(eff->ob->obmat, tex_co); + mul_mat3_m4_v3(eff->ob->obmat, tex_co); } hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL,NULL, 1, result); @@ -815,11 +815,11 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP } if(eff->pd->flag & PFIELD_TEX_2D){ - float fac = -Inpf(force, efd->nor); + float fac = -dot_v3v3(force, efd->nor); VECADDFAC(force, force, efd->nor, fac); } - VecAddf(total_force, total_force, force); + add_v3_v3v3(total_force, total_force, force); } void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force) { @@ -844,51 +844,51 @@ void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint * switch(pd->forcefield){ case PFIELD_WIND: VECCOPY(force, efd->nor); - VecMulf(force, strength * efd->falloff); + mul_v3_fl(force, strength * efd->falloff); break; case PFIELD_FORCE: - Normalize(force); - VecMulf(force, strength * efd->falloff); + normalize_v3(force); + mul_v3_fl(force, strength * efd->falloff); break; case PFIELD_VORTEX: /* old vortex force */ if(pd->shape == PFIELD_SHAPE_POINT) { - Crossf(force, efd->nor, efd->vec_to_point); - Normalize(force); - VecMulf(force, strength * efd->distance * efd->falloff); + cross_v3_v3v3(force, efd->nor, efd->vec_to_point); + normalize_v3(force); + mul_v3_fl(force, strength * efd->distance * efd->falloff); } else { /* new vortex force */ - Crossf(temp, efd->nor2, efd->vec_to_point2); - VecMulf(temp, strength * efd->falloff); + cross_v3_v3v3(temp, efd->nor2, efd->vec_to_point2); + mul_v3_fl(temp, strength * efd->falloff); - Crossf(force, efd->nor2, temp); - VecMulf(force, strength * efd->falloff); + cross_v3_v3v3(force, efd->nor2, temp); + mul_v3_fl(force, strength * efd->falloff); VECADDFAC(temp, temp, point->vel, -point->vel_to_sec); - VecAddf(force, force, temp); + add_v3_v3v3(force, force, temp); } break; case PFIELD_MAGNET: if(eff->pd->shape == PFIELD_SHAPE_POINT) /* magnetic field of a moving charge */ - Crossf(temp, efd->nor, efd->vec_to_point); + cross_v3_v3v3(temp, efd->nor, efd->vec_to_point); else - VecCopyf(temp, efd->nor); + copy_v3_v3(temp, efd->nor); - Normalize(temp); - VecMulf(temp, strength * efd->falloff); - Crossf(force, point->vel, temp); - VecMulf(force, point->vel_to_sec); + normalize_v3(temp); + mul_v3_fl(temp, strength * efd->falloff); + cross_v3_v3v3(force, point->vel, temp); + mul_v3_fl(force, point->vel_to_sec); break; case PFIELD_HARMONIC: - VecMulf(force, -strength * efd->falloff); - VecCopyf(temp, point->vel); - VecMulf(temp, -damp * 2.0f * (float)sqrt(fabs(strength)) * point->vel_to_sec); - VecAddf(force, force, temp); + mul_v3_fl(force, -strength * efd->falloff); + copy_v3_v3(temp, point->vel); + mul_v3_fl(temp, -damp * 2.0f * (float)sqrt(fabs(strength)) * point->vel_to_sec); + add_v3_v3v3(force, force, temp); break; case PFIELD_CHARGE: - VecMulf(force, point->charge * strength * efd->falloff); + mul_v3_fl(force, point->charge * strength * efd->falloff); break; case PFIELD_LENNARDJ: fac = pow((efd->size + point->size) / efd->distance, 6.0); @@ -898,7 +898,7 @@ void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint * /* limit the repulsive term drastically to avoid huge forces */ fac = ((fac>2.0) ? 2.0 : fac); - VecMulf(force, strength * fac); + mul_v3_fl(force, strength * fac); break; case PFIELD_BOID: /* Boid field is handled completely in boids code. */ @@ -913,16 +913,16 @@ void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint * force[0] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[0], temp[1], temp[2], 2,0,2); force[1] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[1], temp[2], temp[0], 2,0,2); force[2] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[2], temp[0], temp[1], 2,0,2); - VecMulf(force, strength * efd->falloff); + mul_v3_fl(force, strength * efd->falloff); break; case PFIELD_DRAG: VECCOPY(force, point->vel); - fac = Normalize(force) * point->vel_to_sec; + fac = normalize_v3(force) * point->vel_to_sec; strength = MIN2(strength, 2.0f); damp = MIN2(damp, 2.0f); - VecMulf(force, -efd->falloff * fac * (strength * fac + damp)); + mul_v3_fl(force, -efd->falloff * fac * (strength * fac + damp)); break; } @@ -937,12 +937,12 @@ void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint * if(pd->flag & PFIELD_DO_ROTATION && point->ave && point->rot) { float xvec[3] = {1.0f, 0.0f, 0.0f}; float dave[3]; - QuatMulVecf(point->rot, xvec); - Crossf(dave, xvec, force); + mul_qt_v3(point->rot, xvec); + cross_v3_v3v3(dave, xvec, force); if(pd->f_flow != 0.0f) { VECADDFAC(dave, dave, point->ave, -pd->f_flow * efd->falloff); } - VecAddf(point->ave, point->ave, dave); + add_v3_v3v3(point->ave, point->ave, dave); } } diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c index 8827897a509..48a05c2f6a7 100644 --- a/source/blender/blenkernel/intern/exotic.c +++ b/source/blender/blenkernel/intern/exotic.c @@ -64,7 +64,7 @@ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BKE_blender.h" @@ -180,7 +180,7 @@ static void mesh_add_normals_flags(Mesh *me) v3= me->mvert+mface->v3; v4= me->mvert+mface->v4; - CalcNormFloat(v1->co, v2->co, v3->co, nor); + normal_tri_v3( nor,v1->co, v2->co, v3->co); sno[0]= 32767.0*nor[0]; sno[1]= 32767.0*nor[1]; sno[2]= 32767.0*nor[2]; @@ -1249,7 +1249,7 @@ static void read_inventor(Scene *scene, char *str, struct ListBase *listb) VECCOPY(bp->vec, data); if(coordtype==4) { bp->vec[3]= data[3]; - VecMulf(bp->vec, 1.0f/data[3]); + mul_v3_fl(bp->vec, 1.0f/data[3]); } else bp->vec[3]= 1.0; data+= coordtype; @@ -1837,7 +1837,7 @@ static void write_vert_stl(Object *ob, MVert *verts, int index, FILE *fpSTL) float vert[3]; VECCOPY(vert, verts[(index)].co); - Mat4MulVecfl(ob->obmat, vert); + mul_m4_v3(ob->obmat, vert); if (ENDIAN_ORDER==B_ENDIAN) { SWITCH_INT(vert[0]); @@ -2174,7 +2174,7 @@ static void write_camera_vrml(FILE *fp, Object *ob) Camera *cam; if(ob==0) return; - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); fprintf(fp, "\tMatrixTransform {\n"); @@ -3031,10 +3031,10 @@ static void dxf_read_line(Scene *scene, int noob) { mvert= &me->mvert[(me->totvert-2)]; - VecSubf(mvert->co, cent, vcenter); + sub_v3_v3v3(mvert->co, cent, vcenter); mvert++; if (vspace) { VECCOPY(mvert->co, epoint); - } else VecSubf(mvert->co, epoint, vcenter); + } else sub_v3_v3v3(mvert->co, epoint, vcenter); mface= &(((MFace*)me->mface)[me->totface-1]); mface->v1= me->totvert-2; @@ -3237,7 +3237,7 @@ static void dxf_read_ellipse(Scene *scene, int noob) if (vspace) { VECCOPY(mvert->co, epoint); } else { - VecSubf(mvert->co, epoint, vcenter); + sub_v3_v3v3(mvert->co, epoint, vcenter); } if (v > 0) { @@ -3360,7 +3360,7 @@ static void dxf_read_arc(Scene *scene, int noob) if (vspace) { VECCOPY(mvert->co, epoint); } else { - VecSubf(mvert->co, epoint, vcenter); + sub_v3_v3v3(mvert->co, epoint, vcenter); } if (v > 0) { @@ -3470,7 +3470,7 @@ static void dxf_read_polyline(Scene *scene, int noob) { mvert= &me->mvert[me->totvert-1]; if (vspace) { VECCOPY(mvert->co, vert); - } else VecSubf(mvert->co, vert, vcenter); + } else sub_v3_v3v3(mvert->co, vert, vcenter); } /* make edges */ @@ -3556,7 +3556,7 @@ static void dxf_read_polyline(Scene *scene, int noob) { mvert= &me->mvert[(me->totvert-1)]; if (vspace) { VECCOPY(mvert->co, vert); - } else VecSubf(mvert->co, vert, vcenter); + } else sub_v3_v3v3(mvert->co, vert, vcenter); } else if (vflags & 128) { if(vids[2]==0) { @@ -3687,7 +3687,7 @@ static void dxf_read_lwpolyline(Scene *scene, int noob) { if (vspace) { VECCOPY(mvert->co, vert); } else { - VecSubf(mvert->co, vert, vcenter); + sub_v3_v3v3(mvert->co, vert, vcenter); } if (v > 0) { @@ -3859,20 +3859,20 @@ static void dxf_read_3dface(Scene *scene, int noob) ftmp=NULL; mvert= &me->mvert[(me->totvert-nverts)]; - VecSubf(mvert->co, cent, vcenter); + sub_v3_v3v3(mvert->co, cent, vcenter); mvert++; if (vspace) { VECCOPY(mvert->co, vert2); - } else VecSubf(mvert->co, vert2, vcenter); + } else sub_v3_v3v3(mvert->co, vert2, vcenter); mvert++; if (vspace) { VECCOPY(mvert->co, vert3); - } else VecSubf(mvert->co, vert3, vcenter); + } else sub_v3_v3v3(mvert->co, vert3, vcenter); if (nverts==4) { mvert++; if (vspace) { VECCOPY(mvert->co, vert4); - } else VecSubf(mvert->co, vert4, vcenter); + } else sub_v3_v3v3(mvert->co, vert4, vcenter); } mface= &(((MFace*)me->mface)[me->totface-1]); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 0ecd1fe912b..a1e6570608f 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -43,7 +43,7 @@ #include "DNA_anim_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_noise.h" #include "BKE_fcurve.h" @@ -924,11 +924,11 @@ static float evaluate_driver (ChannelDriver *driver, float evaltime) } /* use the final posed locations */ - Mat4ToQuat(pchan->pose_mat, q1); - Mat4ToQuat(pchan2->pose_mat, q2); + mat4_to_quat( q1,pchan->pose_mat); + mat4_to_quat( q2,pchan2->pose_mat); - QuatInv(q1); - QuatMul(quat, q1, q2); + invert_qt(q1); + mul_qt_qtqt(quat, q1, q2); angle = 2.0f * (saacos(quat[0])); angle= ABS(angle); @@ -1017,13 +1017,13 @@ static int findzero (float x, float q0, float q1, float q2, float q3, float *o) if (d > 0.0) { t= sqrt(d); - o[0]= (float)(Sqrt3d(-q+t) + Sqrt3d(-q-t) - a); + o[0]= (float)(sqrt3d(-q+t) + sqrt3d(-q-t) - a); if ((o[0] >= SMALL) && (o[0] <= 1.000001)) return 1; else return 0; } else if (d == 0.0) { - t= Sqrt3d(-q); + t= sqrt3d(-q); o[0]= (float)(2*t - a); if ((o[0] >= SMALL) && (o[0] <= 1.000001)) nr++; diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index aa163b821c8..9453c2a0ad1 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -40,7 +40,7 @@ #include "DNA_particle_types.h" #include "DNA_scene_types.h" // N_T -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_cdderivedmesh.h" @@ -563,13 +563,13 @@ void fluid_get_bb(MVert *mvert, int totvert, float obmat[][4], float vec[3]; VECCOPY(vec, mvert[0].co); - Mat4MulVecfl(obmat, vec); + mul_m4_v3(obmat, vec); bbsx = vec[0]; bbsy = vec[1]; bbsz = vec[2]; bbex = vec[0]; bbey = vec[1]; bbez = vec[2]; for(i = 1; i < totvert; i++) { VECCOPY(vec, mvert[i].co); - Mat4MulVecfl(obmat, vec); + mul_m4_v3(obmat, vec); if(vec[0] < bbsx){ bbsx= vec[0]; } if(vec[1] < bbsy){ bbsy= vec[1]; } @@ -626,7 +626,7 @@ void initElbeemMesh(struct Scene *scene, struct Object *ob, verts = MEM_callocN( totvert*3*sizeof(float), "elbeemmesh_vertices"); for(i=0; i<totvert; i++) { VECCOPY( &verts[i*3], mvert[i].co); - if(useGlobalCoords) { Mat4MulVecfl(ob->obmat, &verts[i*3]); } + if(useGlobalCoords) { mul_m4_v3(ob->obmat, &verts[i*3]); } } *vertices = verts; diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 4e79f6238b5..f70de4983e3 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -41,7 +41,7 @@ #include "DNA_anim_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_noise.h" #include "BKE_fcurve.h" diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 4e05bf45d3d..e2dccf02b40 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_vfontdata.h" @@ -968,12 +968,12 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode) float minx, maxx, miny, maxy; float timeofs, sizefac; - Mat4Invert(imat, ob->obmat); - Mat3CpyMat4(imat3, imat); + invert_m4_m4(imat, ob->obmat); + copy_m3_m4(imat3, imat); - Mat3CpyMat4(cmat, cu->textoncurve->obmat); - Mat3MulMat3(cmat, cmat, imat3); - sizefac= Normalize(cmat[0])/cu->fsize; + copy_m3_m4(cmat, cu->textoncurve->obmat); + mul_m3_m3m3(cmat, cmat, imat3); + sizefac= normalize_v3(cmat[0])/cu->fsize; minx=miny= 1.0e20f; maxx=maxy= -1.0e20f; @@ -1042,7 +1042,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode) where_on_path(cu->textoncurve, ctime, vec, tvec, NULL, NULL); where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec, NULL, NULL); - VecMulf(vec, sizefac); + mul_v3_fl(vec, sizefac); ct->rot= (float)(M_PI-atan2(rotvec[1], rotvec[0])); @@ -1196,7 +1196,7 @@ struct chartrans *BKE_text_to_curve(Scene *scene, Object *ob, int mode) vecyo[0] = ct->xof; vecyo[1] = ct->yof; vecyo[2] = 0; - Mat4MulVecfl(ob->obmat, vecyo); + mul_m4_v3(ob->obmat, vecyo); VECCOPY(ob->loc, vecyo); outta = 1; cu->sepchar = 0; diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 43c4137e73e..5023d87cef8 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -36,7 +36,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_listBase.h" diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 6bb47bc0f0f..3ab02a576d0 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -51,6 +51,7 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_object.h" +#include "BKE_scene.h" /* object_in_scene */ #ifdef HAVE_CONFIG_H #include <config.h> @@ -95,7 +96,7 @@ void unlink_group(Group *group) /* ensure objects are not in this group */ for(; base; base= base->next) { - if(rem_from_group(group, base->object) && find_group(base->object, NULL)==NULL) { + if(rem_from_group(group, base->object, sce, base) && find_group(base->object, NULL)==NULL) { base->object->flag &= ~OB_FROMGROUP; base->flag &= ~OB_FROMGROUP; } @@ -153,15 +154,15 @@ Group *copy_group(Group *group) } /* external */ -void add_to_group(Group *group, Object *ob) +static int add_to_group_internal(Group *group, Object *ob) { GroupObject *go; - if(group==NULL || ob==NULL) return; + if(group==NULL || ob==NULL) return 0; /* check if the object has been added already */ for(go= group->gobject.first; go; go= go->next) { - if(go->ob==ob) return; + if(go->ob==ob) return 0; } go= MEM_callocN(sizeof(GroupObject), "groupobject"); @@ -169,10 +170,31 @@ void add_to_group(Group *group, Object *ob) go->ob= ob; + return 1; +} + +int add_to_group(Group *group, Object *object, Scene *scene, Base *base) +{ + if(add_to_group_internal(group, object)) { + if((object->flag & OB_FROMGROUP)==0) { + + if(scene && base==NULL) + base= object_in_scene(object, scene); + + object->flag |= OB_FROMGROUP; + + if(base) + base->flag |= OB_FROMGROUP; + } + return 1; + } + else { + return 0; + } } /* also used for ob==NULL */ -int rem_from_group(Group *group, Object *ob) +static int rem_from_group_internal(Group *group, Object *ob) { GroupObject *go, *gon; int removed = 0; @@ -192,6 +214,26 @@ int rem_from_group(Group *group, Object *ob) return removed; } +int rem_from_group(Group *group, Object *object, Scene *scene, Base *base) +{ + if(rem_from_group_internal(group, object)) { + + if(find_group(object, NULL) == NULL) { + if(scene && base==NULL) + base= object_in_scene(object, scene); + + object->flag &= ~OB_FROMGROUP; + + if(base) + base->flag &= ~OB_FROMGROUP; + } + return 1; + } + else { + return 0; + } +} + int object_in_group(Object *ob, Group *group) { GroupObject *go; diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 64e8aff3830..0c6eaffbed2 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -61,7 +61,7 @@ #include "DNA_sequence_types.h" #include "DNA_userdef_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_threads.h" diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index de215ae4af9..f2b737fa3c2 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -297,6 +297,7 @@ DO_INLINE void sub_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], f /////////////////////////// // 3x3 matrix /////////////////////////// +#if 0 /* printf 3x3 matrix on console: for debug output */ static void print_fmatrix(float m3[3][3]) { @@ -304,6 +305,7 @@ static void print_fmatrix(float m3[3][3]) printf("%f\t%f\t%f\n",m3[1][0],m3[1][1],m3[1][2]); printf("%f\t%f\t%f\n\n",m3[2][0],m3[2][1],m3[2][2]); } +#endif /* copy 3x3 matrix */ DO_INLINE void cp_fmatrix(float to[3][3], float from[3][3]) @@ -972,6 +974,7 @@ DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv) } } +#if 0 /* // version 1.3 static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, fmatrix3x3 *P, fmatrix3x3 *Pinv) @@ -1143,6 +1146,7 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector return iterations<conjgrad_looplimit; } +#endif // outer product is NOT cross product!!! DO_INLINE void dfdx_spring_type1(float to[3][3], float extent[3], float length, float L, float dot, float k) @@ -1550,28 +1554,28 @@ static void cloth_calc_force(ClothModifierData *clmd, float frame, lfVector *lF, CalcFloat(lX[mfaces[i].v1],lX[mfaces[i].v2],lX[mfaces[i].v3],triunnormal); VECCOPY(trinormal, triunnormal); - Normalize(trinormal); + normalize_v3(trinormal); // add wind from v1 VECCOPY(tmp, trinormal); - VecMulf(tmp, calculateVertexWindForce(winvec[mfaces[i].v1], triunnormal)); + mul_v3_fl(tmp, calculateVertexWindForce(winvec[mfaces[i].v1], triunnormal)); VECADDS(lF[mfaces[i].v1], lF[mfaces[i].v1], tmp, factor); // add wind from v2 VECCOPY(tmp, trinormal); - VecMulf(tmp, calculateVertexWindForce(winvec[mfaces[i].v2], triunnormal)); + mul_v3_fl(tmp, calculateVertexWindForce(winvec[mfaces[i].v2], triunnormal)); VECADDS(lF[mfaces[i].v2], lF[mfaces[i].v2], tmp, factor); // add wind from v3 VECCOPY(tmp, trinormal); - VecMulf(tmp, calculateVertexWindForce(winvec[mfaces[i].v3], triunnormal)); + mul_v3_fl(tmp, calculateVertexWindForce(winvec[mfaces[i].v3], triunnormal)); VECADDS(lF[mfaces[i].v3], lF[mfaces[i].v3], tmp, factor); // add wind from v4 if(mfaces[i].v4) { VECCOPY(tmp, trinormal); - VecMulf(tmp, calculateVertexWindForce(winvec[mfaces[i].v4], triunnormal)); + mul_v3_fl(tmp, calculateVertexWindForce(winvec[mfaces[i].v4], triunnormal)); VECADDS(lF[mfaces[i].v4], lF[mfaces[i].v4], tmp, factor); } } @@ -1652,7 +1656,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase if(verts [i].flags & CLOTH_VERT_FLAG_PINNED) { VECSUB(id->V[i], verts[i].xconst, verts[i].xold); - // VecMulf(id->V[i], clmd->sim_parms->stepsPerFrame); + // mul_v3_fl(id->V[i], clmd->sim_parms->stepsPerFrame); } } } @@ -1725,7 +1729,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase VECCOPY(id->Xnew[i], verts[i].tx); VECCOPY(id->Vnew[i], verts[i].tv); - VecMulf(id->Vnew[i], clmd->sim_parms->stepsPerFrame); + mul_v3_fl(id->Vnew[i], clmd->sim_parms->stepsPerFrame); } } diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 5dc26143533..9e9a1719952 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -70,7 +70,7 @@ #include "DNA_world_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "BKE_utildefines.h" diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 61f51d61e0b..3822e0322f7 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1192,11 +1192,11 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, int tot) #endif // XXX old animation system flag= setkeys(ctime, &key->block, k, t, 0); - + if(flag==0) - ; /* do_key(a, a+step, tot, (char *)out, key, k, t, 0); */ + do_key(a, a+step, tot, (char *)out, key, actkb, k, t, 0); else - ; /* cp_key(a, a+step, tot, (char *)out, key, k[2],0); */ + cp_key(a, a+step, tot, (char *)out, key, actkb, k[2], NULL, 0); } } else { @@ -1408,6 +1408,16 @@ KeyBlock *ob_get_keyblock(Object *ob) return NULL; } +KeyBlock *ob_get_reference_keyblock(Object *ob) +{ + Key *key= ob_get_key(ob); + + if (key) + return key->refkey; + + return NULL; +} + /* get the appropriate KeyBlock given an index */ KeyBlock *key_get_keyblock(Key *key, int index) { diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index c53101299c6..dc548edbb25 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_armature_types.h" #include "DNA_mesh_types.h" @@ -155,10 +155,10 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) /* prevent using deformed locations */ freedisplist(<Ob->disp); - Mat4CpyMat4(mat, ltOb->obmat); - Mat4One(ltOb->obmat); + copy_m4_m4(mat, ltOb->obmat); + unit_m4(ltOb->obmat); lattice_deform_verts(ltOb, NULL, NULL, vertexCos, uNew*vNew*wNew, NULL); - Mat4CpyMat4(ltOb->obmat, mat); + copy_m4_m4(ltOb->obmat, mat); lt->typeu = typeu; lt->typev = typev; @@ -310,18 +310,18 @@ void init_latt_deform(Object *oblatt, Object *ob) /* for example with a particle system: ob==0 */ if(ob==NULL) { /* in deformspace, calc matrix */ - Mat4Invert(lt->latmat, oblatt->obmat); + invert_m4_m4(lt->latmat, oblatt->obmat); /* back: put in deform array */ - Mat4Invert(imat, lt->latmat); + invert_m4_m4(imat, lt->latmat); } else { /* in deformspace, calc matrix */ - Mat4Invert(imat, oblatt->obmat); - Mat4MulMat4(lt->latmat, ob->obmat, imat); + invert_m4_m4(imat, oblatt->obmat); + mul_m4_m4m4(lt->latmat, ob->obmat, imat); /* back: put in deform array */ - Mat4Invert(imat, lt->latmat); + invert_m4_m4(imat, lt->latmat); } for(w=0,fw=lt->fw; w<lt->pntsw; w++,fw+=lt->dw) { @@ -337,7 +337,7 @@ void init_latt_deform(Object *oblatt, Object *ob) fp[2] = bp->vec[2] - fw; } - Mat4Mul3Vecfl(imat, fp); + mul_mat3_m4_v3(imat, fp); } } } @@ -356,7 +356,7 @@ void calc_latt_deform(Object *ob, float *co, float weight) /* co is in local coords, treat with latmat */ VECCOPY(vec, co); - Mat4MulVecfl(lt->latmat, vec); + mul_m4_v3(lt->latmat, vec); /* u v w coords */ @@ -456,15 +456,15 @@ typedef struct { static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd, int dloc) { - Mat4Invert(ob->imat, ob->obmat); - Mat4MulMat4(cd->objectspace, par->obmat, ob->imat); - Mat4Invert(cd->curvespace, cd->objectspace); - Mat3CpyMat4(cd->objectspace3, cd->objectspace); + invert_m4_m4(ob->imat, ob->obmat); + mul_m4_m4m4(cd->objectspace, par->obmat, ob->imat); + invert_m4_m4(cd->curvespace, cd->objectspace); + copy_m3_m4(cd->objectspace3, cd->objectspace); // offset vector for 'no smear' if(dloc) { - Mat4Invert(par->imat, par->obmat); - VecMat4MulVecfl(cd->dloc, par->imat, ob->obmat[3]); + invert_m4_m4(par->imat, par->obmat); + mul_v3_m4v3(cd->dloc, par->imat, ob->obmat[3]); } else cd->dloc[0]=cd->dloc[1]=cd->dloc[2]= 0.0f; @@ -497,15 +497,15 @@ static int where_on_path_deform(Object *ob, float ctime, float *vec, float *dir, float dvec[3]; if(ctime < 0.0) { - VecSubf(dvec, path->data[1].vec, path->data[0].vec); - VecMulf(dvec, ctime*(float)path->len); + sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec); + mul_v3_fl(dvec, ctime*(float)path->len); VECADD(vec, vec, dvec); if(quat) QUATCOPY(quat, path->data[0].quat); if(radius) *radius= path->data[0].radius; } else if(ctime > 1.0) { - VecSubf(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec); - VecMulf(dvec, (ctime-1.0)*(float)path->len); + sub_v3_v3v3(dvec, path->data[path->len-1].vec, path->data[path->len-2].vec); + mul_v3_fl(dvec, (ctime-1.0)*(float)path->len); VECADD(vec, vec, dvec); if(quat) QUATCOPY(quat, path->data[path->len-1].quat); if(radius) *radius= path->data[path->len-1].radius; @@ -570,28 +570,28 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C dir[cd->no_rot_axis-1]= 0.0f; /* -1 for compatibility with old track defines */ - vectoquat(dir, axis-1, upflag, quat); + vec_to_quat( quat,dir, axis-1, upflag); /* the tilt */ if(loc[3]!=0.0) { - Normalize(dir); + normalize_v3(dir); q[0]= (float)cos(0.5*loc[3]); fac= (float)sin(0.5*loc[3]); q[1]= -fac*dir[0]; q[2]= -fac*dir[1]; q[3]= -fac*dir[2]; - QuatMul(quat, q, quat); + mul_qt_qtqt(quat, q, quat); } #endif - static float q_x90d[4] = {0.70710676908493, 0.70710676908493, 0.0, 0.0}; // float rot_axis[3]= {1,0,0}; AxisAngleToQuat(q, rot_axis, 90 * (M_PI / 180)); - static float q_y90d[4] = {0.70710676908493, 0.0, 0.70710676908493, 0.0}; // float rot_axis[3]= {0,1,0}; AxisAngleToQuat(q, rot_axis, 90 * (M_PI / 180)); - static float q_z90d[4] = {0.70710676908493, 0.0, 0.0, 0.70710676908493}; // float rot_axis[3]= {0,0,2}; AxisAngleToQuat(q, rot_axis, 90 * (M_PI / 180)); + static float q_x90d[4] = {0.70710676908493, 0.70710676908493, 0.0, 0.0}; // float rot_axis[3]= {1,0,0}; axis_angle_to_quat(q, rot_axis, 90 * (M_PI / 180)); + static float q_y90d[4] = {0.70710676908493, 0.0, 0.70710676908493, 0.0}; // float rot_axis[3]= {0,1,0}; axis_angle_to_quat(q, rot_axis, 90 * (M_PI / 180)); + static float q_z90d[4] = {0.70710676908493, 0.0, 0.0, 0.70710676908493}; // float rot_axis[3]= {0,0,2}; axis_angle_to_quat(q, rot_axis, 90 * (M_PI / 180)); - static float q_nx90d[4] = {0.70710676908493, -0.70710676908493, 0.0, 0.0}; // float rot_axis[3]= {1,0,0}; AxisAngleToQuat(q, rot_axis, -90 * (M_PI / 180)); - static float q_ny90d[4] = {0.70710676908493, 0.0, -0.70710676908493, 0.0}; // float rot_axis[3]= {0,1,0}; AxisAngleToQuat(q, rot_axis, -90 * (M_PI / 180)); - static float q_nz90d[4] = {0.70710676908493, 0.0, 0.0, -0.70710676908493}; // float rot_axis[3]= {0,0,2}; AxisAngleToQuat(q, rot_axis, -90 * (M_PI / 180)); + static float q_nx90d[4] = {0.70710676908493, -0.70710676908493, 0.0, 0.0}; // float rot_axis[3]= {1,0,0}; axis_angle_to_quat(q, rot_axis, -90 * (M_PI / 180)); + static float q_ny90d[4] = {0.70710676908493, 0.0, -0.70710676908493, 0.0}; // float rot_axis[3]= {0,1,0}; axis_angle_to_quat(q, rot_axis, -90 * (M_PI / 180)); + static float q_nz90d[4] = {0.70710676908493, 0.0, 0.0, -0.70710676908493}; // float rot_axis[3]= {0,0,2}; axis_angle_to_quat(q, rot_axis, -90 * (M_PI / 180)); if(cd->no_rot_axis) { /* set by caller */ @@ -602,12 +602,12 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C VECCOPY(dir_flat, dir); dir_flat[cd->no_rot_axis-1]= 0.0f; - Normalize(dir); - Normalize(dir_flat); + normalize_v3(dir); + normalize_v3(dir_flat); - RotationBetweenVectorsToQuat(q, dir, dir_flat); /* Could this be done faster? */ + rotation_between_vecs_to_quat(q, dir, dir_flat); /* Could this be done faster? */ - QuatMul(new_quat, q, new_quat); + mul_qt_qtqt(new_quat, q, new_quat); } @@ -624,14 +624,14 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C switch(axis) { case MOD_CURVE_POSX: - QuatMul(quat, new_quat, q_y90d); + mul_qt_qtqt(quat, new_quat, q_y90d); cent[0]= 0.0; cent[1]= co[2]; cent[2]= co[1]; break; case MOD_CURVE_NEGX: - QuatMul(quat, new_quat, q_ny90d); + mul_qt_qtqt(quat, new_quat, q_ny90d); cent[0]= 0.0; cent[1]= -co[1]; @@ -639,28 +639,28 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C break; case MOD_CURVE_POSY: - QuatMul(quat, new_quat, q_x90d); + mul_qt_qtqt(quat, new_quat, q_x90d); cent[0]= co[2]; cent[1]= 0.0; cent[2]= -co[0]; break; case MOD_CURVE_NEGY: - QuatMul(quat, new_quat, q_nx90d); + mul_qt_qtqt(quat, new_quat, q_nx90d); cent[0]= -co[0]; cent[1]= 0.0; cent[2]= -co[2]; break; case MOD_CURVE_POSZ: - QuatMul(quat, new_quat, q_z90d); + mul_qt_qtqt(quat, new_quat, q_z90d); cent[0]= co[1]; cent[1]= -co[0]; cent[2]= 0.0; break; case MOD_CURVE_NEGZ: - QuatMul(quat, new_quat, q_nz90d); + mul_qt_qtqt(quat, new_quat, q_nz90d); cent[0]= co[0]; cent[1]= -co[1]; @@ -670,11 +670,11 @@ static int calc_curve_deform(Scene *scene, Object *par, float *co, short axis, C /* scale if enabled */ if(cu->flag & CU_PATH_RADIUS) - VecMulf(cent, radius); + mul_v3_fl(cent, radius); /* local rotation */ - NormalQuat(quat); - QuatMulVecf(quat, cent); + normalize_qt(quat); + mul_qt_v3(quat, cent); /* translation */ VECADD(co, cent, loc); @@ -739,7 +739,7 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, DerivedMesh for(j = 0; j < dvert->totweight; j++) { if(dvert->dw[j].def_nr == index) { - Mat4MulVecfl(cd.curvespace, vertexCos[a]); + mul_m4_v3(cd.curvespace, vertexCos[a]); DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); break; } @@ -754,9 +754,9 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, DerivedMesh if(dvert->dw[j].def_nr == index) { VECCOPY(vec, vertexCos[a]); calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL); - VecLerpf(vertexCos[a], vertexCos[a], vec, + interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, dvert->dw[j].weight); - Mat4MulVecfl(cd.objectspace, vertexCos[a]); + mul_m4_v3(cd.objectspace, vertexCos[a]); break; } } @@ -766,13 +766,13 @@ void curve_deform_verts(Scene *scene, Object *cuOb, Object *target, DerivedMesh INIT_MINMAX(cd.dmin, cd.dmax); for(a = 0; a < numVerts; a++) { - Mat4MulVecfl(cd.curvespace, vertexCos[a]); + mul_m4_v3(cd.curvespace, vertexCos[a]); DO_MINMAX(vertexCos[a], cd.dmin, cd.dmax); } for(a = 0; a < numVerts; a++) { calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL); - Mat4MulVecfl(cd.objectspace, vertexCos[a]); + mul_m4_v3(cd.objectspace, vertexCos[a]); } } cu->flag = flag; @@ -787,7 +787,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, float *orco float quat[4]; if(cuOb->type != OB_CURVE) { - Mat3One(mat); + unit_m3(mat); return; } @@ -797,18 +797,18 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target, float *orco VECCOPY(cd.dmin, orco); VECCOPY(cd.dmax, orco); - Mat4MulVecfl(cd.curvespace, vec); + mul_m4_v3(cd.curvespace, vec); if(calc_curve_deform(scene, cuOb, vec, target->trackflag+1, &cd, quat)) { float qmat[3][3]; - QuatToMat3(quat, qmat); - Mat3MulMat3(mat, qmat, cd.objectspace3); + quat_to_mat3( qmat,quat); + mul_m3_m3m3(mat, qmat, cd.objectspace3); } else - Mat3One(mat); + unit_m3(mat); - Mat4MulVecfl(cd.objectspace, vec); + mul_m4_v3(cd.objectspace, vec); } @@ -939,7 +939,7 @@ void outside_lattice(Lattice *lt) bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1]; bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2]; - VecMulf(bp->vec, 0.3333333f); + mul_v3_fl(bp->vec, 0.3333333f); } } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index c2260e1e761..a3e0ab04991 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -46,7 +46,7 @@ #include "DNA_userdef_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_animsys.h" #include "BKE_blender.h" diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 3ca7dac4bc9..d731ab4230b 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -47,7 +47,7 @@ #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" @@ -436,7 +436,7 @@ Object *find_basis_mball(Scene *scene, Object *basis) void calc_mballco(MetaElem *ml, float *vec) { if(ml->mat) { - Mat4MulVecfl((float ( * )[4])ml->mat, vec); + mul_m4_v3((float ( * )[4])ml->mat, vec); } } @@ -448,7 +448,7 @@ float densfunc(MetaElem *ball, float x, float y, float z) vec[0]= x; vec[1]= y; vec[2]= z; - Mat4MulVecfl((float ( * )[4])ball->imat, vec); + mul_m4_v3((float ( * )[4])ball->imat, vec); dx= vec[0]; dy= vec[1]; dz= vec[2]; @@ -1508,8 +1508,8 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ int a, obnr, zero_size=0; char obname[32]; - Mat4CpyMat4(obmat, ob->obmat); /* to cope with duplicators from next_object */ - Mat4Invert(obinv, ob->obmat); + copy_m4_m4(obmat, ob->obmat); /* to cope with duplicators from next_object */ + invert_m4_m4(obinv, ob->obmat); a= 0; splitIDname(ob->id.name+2, obname, &obnr); @@ -1581,15 +1581,15 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ if(ml->s > 10.0) ml->s = 10.0; /* Rotation of MetaElem is stored in quat */ - QuatToMat4(ml->quat, temp3); + quat_to_mat4( temp3,ml->quat); /* Translation of MetaElem */ - Mat4One(temp2); + unit_m4(temp2); temp2[3][0]= ml->x; temp2[3][1]= ml->y; temp2[3][2]= ml->z; - Mat4MulMat4(temp1, temp3, temp2); + mul_m4_m4m4(temp1, temp3, temp2); /* make a copy because of duplicates */ mainb[a]= new_pgn_element(sizeof(MetaElem)); @@ -1600,12 +1600,12 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ imat= new_pgn_element(4*4*sizeof(float)); /* mat is the matrix to transform from mball into the basis-mball */ - Mat4Invert(obinv, obmat); - Mat4MulMat4(temp2, bob->obmat, obinv); + invert_m4_m4(obinv, obmat); + mul_m4_m4m4(temp2, bob->obmat, obinv); /* MetaBall transformation */ - Mat4MulMat4(mat, temp1, temp2); + mul_m4_m4m4(mat, temp1, temp2); - Mat4Invert(imat,mat); + invert_m4_m4(imat,mat); mainb[a]->rad2= ml->rad*ml->rad; @@ -1648,7 +1648,7 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ /* transformation of Metalem bb */ for(i=0; i<8; i++) - Mat4MulVecfl((float ( * )[4])mat, mainb[a]->bb->vec[i]); + mul_m4_v3((float ( * )[4])mat, mainb[a]->bb->vec[i]); /* find max and min of transformed bb */ for(i=0; i<8; i++){ diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 6ef557ca879..d5c597b802c 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -70,7 +70,7 @@ #include "BLI_blenlib.h" #include "BLI_editVert.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_edgehash.h" @@ -1086,7 +1086,7 @@ void mesh_to_curve(Scene *scene, Object *ob) /* add points */ vl= polyline.first; for (i=0, bp=nu->bp; i < totpoly; i++, bp++, vl=(VertLink *)vl->next) { - VecCopyf(bp->vec, mverts[vl->index].co); + copy_v3_v3(bp->vec, mverts[vl->index].co); bp->f1= SELECT; bp->radius = bp->weight = 1.0; } @@ -1146,23 +1146,23 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float *f_no= &fnors[i*3]; if (mf->v4) - CalcNormFloat4(mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co, f_no); + normal_quad_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co); else - CalcNormFloat(mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, f_no); + normal_tri_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co); - VecAddf(tnorms[mf->v1], tnorms[mf->v1], f_no); - VecAddf(tnorms[mf->v2], tnorms[mf->v2], f_no); - VecAddf(tnorms[mf->v3], tnorms[mf->v3], f_no); + add_v3_v3v3(tnorms[mf->v1], tnorms[mf->v1], f_no); + add_v3_v3v3(tnorms[mf->v2], tnorms[mf->v2], f_no); + add_v3_v3v3(tnorms[mf->v3], tnorms[mf->v3], f_no); if (mf->v4) - VecAddf(tnorms[mf->v4], tnorms[mf->v4], f_no); + add_v3_v3v3(tnorms[mf->v4], tnorms[mf->v4], f_no); } for (i=0; i<numVerts; i++) { MVert *mv= &mverts[i]; float *no= tnorms[i]; - if (Normalize(no)==0.0) { + if (normalize_v3(no)==0.0) { VECCOPY(no, mv->co); - Normalize(no); + normalize_v3(no); } mv->no[0]= (short)(no[0]*32767.0); @@ -1262,7 +1262,7 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned next= iterv->next; uv2= (tf+iterv->f)->uv[iterv->tfindex]; - Vec2Subf(uvdiff, uv2, uv); + sub_v2_v2v2(uvdiff, uv2, uv); if(fabs(uv[0]-uv2[0]) < limit[0] && fabs(uv[1]-uv2[1]) < limit[1]) { diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 1f4f69bd376..667b86d1893 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -41,7 +41,7 @@ #include "float.h" #include "ctype.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_kdopbvh.h" #include "BLI_kdtree.h" @@ -1187,7 +1187,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, if(amd->end_cap && amd->end_cap != ob) end_cap = amd->end_cap->derivedFinal; - Mat4One(offset); + unit_m4(offset); indexMap = MEM_callocN(sizeof(*indexMap) * dm->getNumVerts(dm), "indexmap"); @@ -1197,7 +1197,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, maxVerts = dm->getNumVerts(dm); if(amd->offset_type & MOD_ARR_OFF_CONST) - VecAddf(offset[3], offset[3], amd->offset); + add_v3_v3v3(offset[3], offset[3], amd->offset); if(amd->offset_type & MOD_ARR_OFF_RELATIVE) { for(j = 0; j < 3; j++) offset[3][j] += amd->scale[j] * vertarray_size(src_mvert, @@ -1209,14 +1209,14 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, float result_mat[4][4]; if(ob) - Mat4Invert(obinv, ob->obmat); + invert_m4_m4(obinv, ob->obmat); else - Mat4One(obinv); + unit_m4(obinv); - Mat4MulSerie(result_mat, offset, + mul_serie_m4(result_mat, offset, obinv, amd->offset_ob->obmat, NULL, NULL, NULL, NULL, NULL); - Mat4CpyMat4(offset, result_mat); + copy_m4_m4(offset, result_mat); } if(amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob) { @@ -1226,7 +1226,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, float scale; object_to_mat3(amd->curve_ob, tmp_mat); - scale = Mat3ToScalef(tmp_mat); + scale = mat3_to_scale(tmp_mat); if(!cu->path) { cu->flag |= CU_PATH; // needed for path & bevlist @@ -1241,7 +1241,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, prescribed length */ if(amd->fit_type == MOD_ARR_FITLENGTH || amd->fit_type == MOD_ARR_FITCURVE) { - float dist = sqrt(Inpf(offset[3], offset[3])); + float dist = sqrt(dot_v3v3(offset[3], offset[3])); if(dist > 1e-6f) /* this gives length = first copy start to last copy end @@ -1274,11 +1274,11 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, result = CDDM_from_template(dm, finalVerts, finalEdges, finalFaces); /* calculate the offset matrix of the final copy (for merging) */ - Mat4One(final_offset); + unit_m4(final_offset); for(j=0; j < count - 1; j++) { - Mat4MulMat4(tmp_mat, final_offset, offset); - Mat4CpyMat4(final_offset, tmp_mat); + mul_m4_m4m4(tmp_mat, final_offset, offset); + copy_m4_m4(final_offset, tmp_mat); } numVerts = numEdges = numFaces = 0; @@ -1314,7 +1314,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, if((count > 1) && (amd->flags & MOD_ARR_MERGE)) { float tmp_co[3]; VECCOPY(tmp_co, mv->co); - Mat4MulVecfl(offset, tmp_co); + mul_m4_v3(offset, tmp_co); for(j = 0; j < maxVerts; j++) { /* if vertex already merged, don't use it */ @@ -1322,15 +1322,15 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, inMV = &src_mvert[j]; /* if this vert is within merge limit, merge */ - if(VecLenCompare(tmp_co, inMV->co, amd->merge_dist)) { + if(compare_len_v3v3(tmp_co, inMV->co, amd->merge_dist)) { indexMap[i].merge = j; /* test for merging with final copy of merge target */ if(amd->flags & MOD_ARR_MERGEFINAL) { VECCOPY(tmp_co, inMV->co); inMV = &src_mvert[i]; - Mat4MulVecfl(final_offset, tmp_co); - if(VecLenCompare(tmp_co, inMV->co, amd->merge_dist)) + mul_m4_v3(final_offset, tmp_co); + if(compare_len_v3v3(tmp_co, inMV->co, amd->merge_dist)) indexMap[i].merge_final = 1; } break; @@ -1347,7 +1347,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, *mv2 = *mv; numVerts++; - Mat4MulVecfl(offset, co); + mul_m4_v3(offset, co); VECCOPY(mv2->co, co); } } else if(indexMap[i].merge != i && indexMap[i].merge_final) { @@ -1504,7 +1504,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, cap_medge = start_cap->getEdgeArray(start_cap); cap_mface = start_cap->getFaceArray(start_cap); - Mat4Invert(startoffset, offset); + invert_m4_m4(startoffset, offset); vert_map = MEM_callocN(sizeof(*vert_map) * capVerts, "arrayModifier_doArray vert_map"); @@ -1520,12 +1520,12 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, int j; VECCOPY(tmp_co, mv->co); - Mat4MulVecfl(startoffset, tmp_co); + mul_m4_v3(startoffset, tmp_co); for(j = 0; j < maxVerts; j++) { in_mv = &src_mvert[j]; /* if this vert is within merge limit, merge */ - if(VecLenCompare(tmp_co, in_mv->co, amd->merge_dist)) { + if(compare_len_v3v3(tmp_co, in_mv->co, amd->merge_dist)) { vert_map[i] = calc_mapping(indexMap, j, 0); merged = 1; break; @@ -1536,7 +1536,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, if(!merged) { DM_copy_vert_data(start_cap, result, i, numVerts, 1); mvert[numVerts] = *mv; - Mat4MulVecfl(startoffset, mvert[numVerts].co); + mul_m4_v3(startoffset, mvert[numVerts].co); origindex[numVerts] = ORIGINDEX_NONE; vert_map[i] = numVerts; @@ -1605,7 +1605,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, cap_medge = end_cap->getEdgeArray(end_cap); cap_mface = end_cap->getFaceArray(end_cap); - Mat4MulMat4(endoffset, final_offset, offset); + mul_m4_m4m4(endoffset, final_offset, offset); vert_map = MEM_callocN(sizeof(*vert_map) * capVerts, "arrayModifier_doArray vert_map"); @@ -1621,12 +1621,12 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, int j; VECCOPY(tmp_co, mv->co); - Mat4MulVecfl(offset, tmp_co); + mul_m4_v3(offset, tmp_co); for(j = 0; j < maxVerts; j++) { in_mv = &src_mvert[j]; /* if this vert is within merge limit, merge */ - if(VecLenCompare(tmp_co, in_mv->co, amd->merge_dist)) { + if(compare_len_v3v3(tmp_co, in_mv->co, amd->merge_dist)) { vert_map[i] = calc_mapping(indexMap, j, count - 1); merged = 1; break; @@ -1637,7 +1637,7 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, if(!merged) { DM_copy_vert_data(end_cap, result, i, numVerts, 1); mvert[numVerts] = *mv; - Mat4MulVecfl(endoffset, mvert[numVerts].co); + mul_m4_v3(endoffset, mvert[numVerts].co); origindex[numVerts] = ORIGINDEX_NONE; vert_map[i] = numVerts; @@ -1921,9 +1921,9 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, if (mmd->mirror_ob) { float obinv[4][4]; - Mat4Invert(obinv, mmd->mirror_ob->obmat); - Mat4MulMat4(mtx, ob->obmat, obinv); - Mat4Invert(imtx, mtx); + invert_m4_m4(obinv, mmd->mirror_ob->obmat); + mul_m4_m4m4(mtx, ob->obmat, obinv); + invert_m4_m4(imtx, mtx); } for(i = 0; i < maxVerts; i++) { @@ -1934,10 +1934,10 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, dm->getVert(dm, i, &inMV); - VecCopyf(co, inMV.co); + copy_v3_v3(co, inMV.co); if (mmd->mirror_ob) { - VecMat4MulVecfl(co, mtx, co); + mul_v3_m4v3(co, mtx, co); } isShared = ABS(co[axis])<=tolerance; @@ -1955,9 +1955,9 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, if(isShared) { co[axis] = 0; if (mmd->mirror_ob) { - VecMat4MulVecfl(co, imtx, co); + mul_v3_m4v3(co, imtx, co); } - VecCopyf(mv->co, co); + copy_v3_v3(mv->co, co); mv->flag |= ME_VERT_MERGED; } else { @@ -1969,9 +1969,9 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, co[axis] = -co[axis]; if (mmd->mirror_ob) { - VecMat4MulVecfl(co, imtx, co); + mul_v3_m4v3(co, imtx, co); } - VecCopyf(mv2->co, co); + copy_v3_v3(mv2->co, co); if (mmd->flag & MOD_MIR_VGROUP){ dvert = DM_get_vert_data(result, numVerts, CD_MDEFORMVERT); @@ -2477,12 +2477,12 @@ static SmoothMesh *smoothmesh_from_derivedmesh(DerivedMesh *dm) if(face->edges[2]->verts[1]->oldIndex == mf.v3) face->flip[2] = 1; face->edges[3] = BLI_edgehash_lookup(edges, mf.v4, mf.v1); if(face->edges[3]->verts[1]->oldIndex == mf.v4) face->flip[3] = 1; - CalcNormFloat4(v1.co, v2.co, v3.co, v4.co, face->normal); + normal_quad_v3( face->normal,v1.co, v2.co, v3.co, v4.co); } else { face->edges[2] = BLI_edgehash_lookup(edges, mf.v3, mf.v1); if(face->edges[2]->verts[1]->oldIndex == mf.v3) face->flip[2] = 1; face->edges[3] = NULL; - CalcNormFloat(v1.co, v2.co, v3.co, face->normal); + normal_tri_v3( face->normal,v1.co, v2.co, v3.co); } for(j = 0; j < SMOOTHFACE_MAX_EDGES && face->edges[j]; j++) { @@ -3179,7 +3179,7 @@ static void tag_and_count_extra_edges(SmoothMesh *mesh, float split_angle, /* we know the edge has 2 faces, so check the angle */ SmoothFace *face1 = edge->faces->link; SmoothFace *face2 = edge->faces->next->link; - float edge_angle_cos = Inpf(face1->normal, + float edge_angle_cos = dot_v3v3(face1->normal, face2->normal); if(edge_angle_cos < threshold) { @@ -3575,7 +3575,7 @@ static void get_texture_coords(DisplaceModifierData *dmd, Object *ob, if(texmapping == MOD_DISP_MAP_OBJECT) { if(dmd->map_object) - Mat4Invert(mapob_imat, dmd->map_object->obmat); + invert_m4_m4(mapob_imat, dmd->map_object->obmat); else /* if there is no map object, default to local */ texmapping = MOD_DISP_MAP_LOCAL; } @@ -3641,12 +3641,12 @@ static void get_texture_coords(DisplaceModifierData *dmd, Object *ob, break; case MOD_DISP_MAP_GLOBAL: VECCOPY(*texco, *co); - Mat4MulVecfl(ob->obmat, *texco); + mul_m4_v3(ob->obmat, *texco); break; case MOD_DISP_MAP_OBJECT: VECCOPY(*texco, *co); - Mat4MulVecfl(ob->obmat, *texco); - Mat4MulVecfl(mapob_imat, *texco); + mul_m4_v3(ob->obmat, *texco); + mul_m4_v3(mapob_imat, *texco); break; } } @@ -3917,7 +3917,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, /* convert coords to world space */ for(i = 0, co = coords; i < numVerts; ++i, ++co) - Mat4MulVecfl(ob->obmat, *co); + mul_m4_v3(ob->obmat, *co); /* calculate a projection matrix and normal for each projector */ for(i = 0; i < num_projectors; ++i) { @@ -3925,7 +3925,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, float offsetmat[4][4]; Camera *cam = NULL; /* calculate projection matrix */ - Mat4Invert(projectors[i].projmat, projectors[i].ob->obmat); + invert_m4_m4(projectors[i].projmat, projectors[i].ob->obmat); if(projectors[i].ob->type == OB_CAMERA) { cam = (Camera *)projectors[i].ob->data; @@ -3947,9 +3947,8 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, xmin = -xmax; ymin = -ymax; - i_window(xmin, xmax, ymin, ymax, - cam->clipsta, cam->clipend, perspmat); - Mat4MulMat4(tmpmat, projectors[i].projmat, perspmat); + perspective_m4( perspmat,xmin, xmax, ymin, ymax, cam->clipsta, cam->clipend); + mul_m4_m4m4(tmpmat, projectors[i].projmat, perspmat); } else if(cam->type == CAM_ORTHO) { float orthomat[4][4]; float xmax; @@ -3967,16 +3966,15 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, xmin = -xmax; ymin = -ymax; - i_ortho(xmin, xmax, ymin, ymax, - cam->clipsta, cam->clipend, orthomat); - Mat4MulMat4(tmpmat, projectors[i].projmat, orthomat); + orthographic_m4( orthomat,xmin, xmax, ymin, ymax, cam->clipsta, cam->clipend); + mul_m4_m4m4(tmpmat, projectors[i].projmat, orthomat); } } else { - Mat4CpyMat4(tmpmat, projectors[i].projmat); + copy_m4_m4(tmpmat, projectors[i].projmat); } - Mat4One(offsetmat); - Mat4MulFloat3(offsetmat[0], 0.5); + unit_m4(offsetmat); + mul_mat3_m4_fl(offsetmat, 0.5); offsetmat[3][0] = offsetmat[3][1] = offsetmat[3][2] = 0.5; if (cam) { @@ -3992,19 +3990,19 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, } } - Mat4MulMat4(projectors[i].projmat, tmpmat, offsetmat); + mul_m4_m4m4(projectors[i].projmat, tmpmat, offsetmat); /* calculate worldspace projector normal (for best projector test) */ projectors[i].normal[0] = 0; projectors[i].normal[1] = 0; projectors[i].normal[2] = 1; - Mat4Mul3Vecfl(projectors[i].ob->obmat, projectors[i].normal); + mul_mat3_m4_v3(projectors[i].ob->obmat, projectors[i].normal); } /* if only one projector, project coords to UVs */ if(num_projectors == 1) for(i = 0, co = coords; i < numVerts; ++i, ++co) - Mat4MulVec3Project(projectors[0].projmat, *co); + mul_project_m4_v4(projectors[0].projmat, *co); mface = dm->getFaceArray(dm); numFaces = dm->getNumFaces(dm); @@ -4041,19 +4039,19 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, /* get the untransformed face normal */ if(mf->v4) { VECCOPY(co4, coords[mf->v4]); - CalcNormFloat4(co1, co2, co3, co4, face_no); + normal_quad_v3( face_no,co1, co2, co3, co4); } else { - CalcNormFloat(co1, co2, co3, face_no); + normal_tri_v3( face_no,co1, co2, co3); } /* find the projector which the face points at most directly * (projector normal with largest dot product is best) */ - best_dot = Inpf(projectors[0].normal, face_no); + best_dot = dot_v3v3(projectors[0].normal, face_no); best_projector = &projectors[0]; for(j = 1; j < num_projectors; ++j) { - float tmp_dot = Inpf(projectors[j].normal, + float tmp_dot = dot_v3v3(projectors[j].normal, face_no); if(tmp_dot > best_dot) { best_dot = tmp_dot; @@ -4061,11 +4059,11 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, } } - Mat4MulVec3Project(best_projector->projmat, co1); - Mat4MulVec3Project(best_projector->projmat, co2); - Mat4MulVec3Project(best_projector->projmat, co3); + mul_project_m4_v4(best_projector->projmat, co1); + mul_project_m4_v4(best_projector->projmat, co2); + mul_project_m4_v4(best_projector->projmat, co3); if(mf->v4) - Mat4MulVec3Project(best_projector->projmat, co4); + mul_project_m4_v4(best_projector->projmat, co4); /* apply transformed coords as UVs */ tface->uv[0][0] = co1[0]; @@ -4360,11 +4358,11 @@ static void smoothModifier_do( if (uctmp[idx1] < 255) { uctmp[idx1]++; - VecAddf(v1, v1, fvec); + add_v3_v3v3(v1, v1, fvec); } if (uctmp[idx2] < 255) { uctmp[idx2]++; - VecAddf(v2, v2, fvec); + add_v3_v3v3(v2, v2, fvec); } } @@ -4578,14 +4576,14 @@ static void castModifier_sphere_do( * we use its location, transformed to ob's local space */ if (ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4Invert(ctrl_ob->imat, ctrl_ob->obmat); - Mat4MulMat4(mat, ob->obmat, ctrl_ob->imat); - Mat4Invert(imat, mat); + invert_m4_m4(ctrl_ob->imat, ctrl_ob->obmat); + mul_m4_m4m4(mat, ob->obmat, ctrl_ob->imat); + invert_m4_m4(imat, mat); } - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); VECCOPY(center, ctrl_ob->obmat[3]); - Mat4MulVecfl(ob->imat, center); + mul_m4_v3(ob->imat, center); } /* now we check which options the user wants */ @@ -4620,7 +4618,7 @@ static void castModifier_sphere_do( if(len <= 0) { for (i = 0; i < numVerts; i++) { - len += VecLenf(center, vertexCos[i]); + len += len_v3v3(center, vertexCos[i]); } len /= numVerts; @@ -4642,9 +4640,9 @@ static void castModifier_sphere_do( VECCOPY(tmp_co, vertexCos[i]); if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(mat, tmp_co); + mul_m4_v3(mat, tmp_co); } else { - VecSubf(tmp_co, tmp_co, center); + sub_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4654,7 +4652,7 @@ static void castModifier_sphere_do( vec[2] = 0.0f; if (has_radius) { - if (VecLength(vec) > cmd->radius) continue; + if (len_v3(vec) > cmd->radius) continue; } for (j = 0; j < dvert[i].totweight; ++j) { @@ -4668,7 +4666,7 @@ static void castModifier_sphere_do( fac = fac_orig * dw->weight; facm = 1.0f - fac; - Normalize(vec); + normalize_v3(vec); if (flag & MOD_CAST_X) tmp_co[0] = fac*vec[0]*len + facm*tmp_co[0]; @@ -4679,9 +4677,9 @@ static void castModifier_sphere_do( if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(imat, tmp_co); + mul_m4_v3(imat, tmp_co); } else { - VecAddf(tmp_co, tmp_co, center); + add_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4697,9 +4695,9 @@ static void castModifier_sphere_do( VECCOPY(tmp_co, vertexCos[i]); if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(mat, tmp_co); + mul_m4_v3(mat, tmp_co); } else { - VecSubf(tmp_co, tmp_co, center); + sub_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4709,10 +4707,10 @@ static void castModifier_sphere_do( vec[2] = 0.0f; if (has_radius) { - if (VecLength(vec) > cmd->radius) continue; + if (len_v3(vec) > cmd->radius) continue; } - Normalize(vec); + normalize_v3(vec); if (flag & MOD_CAST_X) tmp_co[0] = fac*vec[0]*len + facm*tmp_co[0]; @@ -4723,9 +4721,9 @@ static void castModifier_sphere_do( if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(imat, tmp_co); + mul_m4_v3(imat, tmp_co); } else { - VecAddf(tmp_co, tmp_co, center); + add_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4780,14 +4778,14 @@ static void castModifier_cuboid_do( if (ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4Invert(ctrl_ob->imat, ctrl_ob->obmat); - Mat4MulMat4(mat, ob->obmat, ctrl_ob->imat); - Mat4Invert(imat, mat); + invert_m4_m4(ctrl_ob->imat, ctrl_ob->obmat); + mul_m4_m4m4(mat, ob->obmat, ctrl_ob->imat); + invert_m4_m4(imat, mat); } - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); VECCOPY(center, ctrl_ob->obmat[3]); - Mat4MulVecfl(ob->imat, center); + mul_m4_v3(ob->imat, center); } if((flag & MOD_CAST_SIZE_FROM_RADIUS) && has_radius) { @@ -4816,7 +4814,7 @@ static void castModifier_cuboid_do( DO_MINMAX(center, min, max); for (i = 0; i < numVerts; i++) { - VecSubf(vec, vertexCos[i], center); + sub_v3_v3v3(vec, vertexCos[i], center); DO_MINMAX(vec, min, max); } } @@ -4859,9 +4857,9 @@ static void castModifier_cuboid_do( VECCOPY(tmp_co, vertexCos[i]); if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(mat, tmp_co); + mul_m4_v3(mat, tmp_co); } else { - VecSubf(tmp_co, tmp_co, center); + sub_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4897,7 +4895,7 @@ static void castModifier_cuboid_do( if (tmp_co[2] > 0.0f) octant += 4; /* apex is the bb's vertex at the chosen octant */ - VecCopyf(apex, bb[octant]); + copy_v3_v3(apex, bb[octant]); /* find which bb plane is closest to this vertex ... */ d[0] = tmp_co[0] / apex[0]; @@ -4935,9 +4933,9 @@ static void castModifier_cuboid_do( if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(imat, tmp_co); + mul_m4_v3(imat, tmp_co); } else { - VecAddf(tmp_co, tmp_co, center); + add_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4955,9 +4953,9 @@ static void castModifier_cuboid_do( VECCOPY(tmp_co, vertexCos[i]); if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(mat, tmp_co); + mul_m4_v3(mat, tmp_co); } else { - VecSubf(tmp_co, tmp_co, center); + sub_v3_v3v3(tmp_co, tmp_co, center); } } @@ -4972,7 +4970,7 @@ static void castModifier_cuboid_do( if (tmp_co[1] > 0.0f) octant += 2; if (tmp_co[2] > 0.0f) octant += 4; - VecCopyf(apex, bb[octant]); + copy_v3_v3(apex, bb[octant]); d[0] = tmp_co[0] / apex[0]; d[1] = tmp_co[1] / apex[1]; @@ -5003,9 +5001,9 @@ static void castModifier_cuboid_do( if(ctrl_ob) { if(flag & MOD_CAST_USE_OB_TRANSFORM) { - Mat4MulVecfl(imat, tmp_co); + mul_m4_v3(imat, tmp_co); } else { - VecAddf(tmp_co, tmp_co, center); + add_v3_v3v3(tmp_co, tmp_co, center); } } @@ -5170,7 +5168,7 @@ static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob, if(texmapping == MOD_WAV_MAP_OBJECT) { if(wmd->map_object) - Mat4Invert(wmd->map_object->imat, wmd->map_object->obmat); + invert_m4_m4(wmd->map_object->imat, wmd->map_object->obmat); else /* if there is no map object, default to local */ texmapping = MOD_WAV_MAP_LOCAL; } @@ -5236,12 +5234,12 @@ static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob, break; case MOD_WAV_MAP_GLOBAL: VECCOPY(*texco, *co); - Mat4MulVecfl(ob->obmat, *texco); + mul_m4_v3(ob->obmat, *texco); break; case MOD_WAV_MAP_OBJECT: VECCOPY(*texco, *co); - Mat4MulVecfl(ob->obmat, *texco); - Mat4MulVecfl(wmd->map_object->imat, *texco); + mul_m4_v3(ob->obmat, *texco); + mul_m4_v3(wmd->map_object->imat, *texco); break; } } @@ -5267,8 +5265,8 @@ static void waveModifier_do(WaveModifierData *md, if(wmd->objectcenter){ float mat[4][4]; /* get the control object's location in local coordinates */ - Mat4Invert(ob->imat, ob->obmat); - Mat4MulMat4(mat, wmd->objectcenter->obmat, ob->imat); + invert_m4_m4(ob->imat, ob->obmat); + mul_m4_m4m4(mat, wmd->objectcenter->obmat, ob->imat); wmd->startx = mat[3][0]; wmd->starty = mat[3][1]; @@ -5657,14 +5655,14 @@ static void hookModifier_deformVerts( /* get world-space matrix of target, corrected for the space the verts are in */ if (hmd->subtarget[0] && pchan) { /* bone target if there's a matching pose-channel */ - Mat4MulMat4(dmat, pchan->pose_mat, hmd->object->obmat); + mul_m4_m4m4(dmat, pchan->pose_mat, hmd->object->obmat); } else { /* just object target */ - Mat4CpyMat4(dmat, hmd->object->obmat); + copy_m4_m4(dmat, hmd->object->obmat); } - Mat4Invert(ob->imat, ob->obmat); - Mat4MulSerie(mat, ob->imat, dmat, hmd->parentinv, + invert_m4_m4(ob->imat, ob->obmat); + mul_serie_m4(mat, ob->imat, dmat, hmd->parentinv, NULL, NULL, NULL, NULL, NULL); /* vertex indices? */ @@ -5694,29 +5692,29 @@ static void hookModifier_deformVerts( if(orig_index == index) { co = vertexCos[j]; if(hmd->falloff != 0.0) { - float len = VecLenf(co, hmd->cent); + float len = len_v3v3(co, hmd->cent); if(len > hmd->falloff) fac = 0.0; else if(len > 0.0) fac *= sqrt(1.0 - len / hmd->falloff); } if(fac != 0.0) { - VecMat4MulVecfl(vec, mat, co); - VecLerpf(co, co, vec, fac); + mul_v3_m4v3(vec, mat, co); + interp_v3_v3v3(co, co, vec, fac); } } } } else { if(hmd->falloff != 0.0) { - float len = VecLenf(co, hmd->cent); + float len = len_v3v3(co, hmd->cent); if(len > hmd->falloff) fac = 0.0; else if(len > 0.0) fac *= sqrt(1.0 - len / hmd->falloff); } if(fac != 0.0) { - VecMat4MulVecfl(vec, mat, co); - VecLerpf(co, co, vec, fac); + mul_v3_m4v3(vec, mat, co); + interp_v3_v3v3(co, co, vec, fac); } } } @@ -5755,14 +5753,14 @@ static void hookModifier_deformVerts( float *co = vertexCos[i]; if(hmd->falloff != 0.0) { - float len = VecLenf(co, hmd->cent); + float len = len_v3v3(co, hmd->cent); if(len > hmd->falloff) fac = 0.0; else if(len > 0.0) fac *= sqrt(1.0 - len / hmd->falloff); } - VecMat4MulVecfl(vec, mat, co); - VecLerpf(co, co, vec, fac); + mul_v3_m4v3(vec, mat, co); + interp_v3_v3v3(co, co, vec, fac); } } } @@ -6098,7 +6096,7 @@ static void collisionModifier_deformVerts( for ( i = 0; i < numverts; i++ ) { // we save global positions - Mat4MulVecfl ( ob->obmat, collmd->x[i].co ); + mul_m4_v3( ob->obmat, collmd->x[i].co ); } collmd->xnew = MEM_dupallocN(collmd->x); // frame end position @@ -6128,7 +6126,7 @@ static void collisionModifier_deformVerts( for ( i = 0; i < numverts; i++ ) { // we save global positions - Mat4MulVecfl ( ob->obmat, collmd->xnew[i].co ); + mul_m4_v3( ob->obmat, collmd->xnew[i].co ); } memcpy(collmd->current_xnew, collmd->x, numverts*sizeof(MVert)); @@ -6274,14 +6272,14 @@ static void surfaceModifier_deformVerts( /* convert to global coordinates and calculate velocity */ for(i = 0, x = surmd->x, v = surmd->v; i<numverts; i++, x++, v++) { vec = CDDM_get_vert(surmd->dm, i)->co; - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); if(init) v->co[0] = v->co[1] = v->co[2] = 0.0f; else - VecSubf(v->co, vec, x->co); + sub_v3_v3v3(v->co, vec, x->co); - VecCopyf(x->co, vec); + copy_v3_v3(x->co, vec); } surmd->cfra = md->scene->r.cfra; @@ -6715,7 +6713,7 @@ static DerivedMesh * particleInstanceModifier_applyModifier( psys_get_particle_on_path(&sim, first_particle + i/totvert, &state,1); - Normalize(state.vel); + normalize_v3(state.vel); /* TODO: incremental rotations somehow */ if(state.vel[axis] < -0.9999 || state.vel[axis] > 0.9999) { @@ -6726,10 +6724,10 @@ static DerivedMesh * particleInstanceModifier_applyModifier( float temp[3] = {0.0f,0.0f,0.0f}; temp[axis] = 1.0f; - Crossf(cross, temp, state.vel); + cross_v3_v3v3(cross, temp, state.vel); /* state.vel[axis] is the only component surviving from a dot product with the axis */ - VecRotToQuat(cross,saacos(state.vel[axis]),state.rot); + axis_angle_to_quat(state.rot,cross,saacos(state.vel[axis])); } } @@ -6738,9 +6736,9 @@ static DerivedMesh * particleInstanceModifier_applyModifier( psys_get_particle_state(&sim, first_particle + i/totvert, &state,1); } - QuatMulVecf(state.rot,mv->co); + mul_qt_v3(state.rot,mv->co); if(pimd->flag & eParticleInstanceFlag_UseSize) - VecMulf(mv->co, size[i/totvert]); + mul_v3_fl(mv->co, size[i/totvert]); VECADD(mv->co,mv->co,state.co); } @@ -6903,14 +6901,14 @@ static void explodeModifier_createFacepa(ExplodeModifierData *emd, /* set face-particle-indexes to nearest particle to face center */ for(i=0,fa=mface; i<totface; i++,fa++){ - VecAddf(center,mvert[fa->v1].co,mvert[fa->v2].co); - VecAddf(center,center,mvert[fa->v3].co); + add_v3_v3v3(center,mvert[fa->v1].co,mvert[fa->v2].co); + add_v3_v3v3(center,center,mvert[fa->v3].co); if(fa->v4){ - VecAddf(center,center,mvert[fa->v4].co); - VecMulf(center,0.25); + add_v3_v3v3(center,center,mvert[fa->v4].co); + mul_v3_fl(center,0.25); } else - VecMulf(center,0.3333f); + mul_v3_fl(center,0.3333f); p= BLI_kdtree_find_nearest(tree,center,NULL,NULL); @@ -7082,7 +7080,7 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive mv=CDDM_get_vert(splitdm,i); VECADD(dupve->co,dupve->co,mv->co); - VecMulf(dupve->co,0.5); + mul_v3_fl(dupve->co,0.5); } BLI_edgehashIterator_free(ehi); @@ -7298,7 +7296,7 @@ static DerivedMesh * explodeModifier_splitEdges(ExplodeModifierData *emd, Derive VECADD(dupve->co,dupve->co,mv->co); mv=CDDM_get_vert(splitdm,mf->v4); VECADD(dupve->co,dupve->co,mv->co); - VecMulf(dupve->co,0.25); + mul_v3_fl(dupve->co,0.25); df1=CDDM_get_face(splitdm,curdupface); @@ -7474,7 +7472,7 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd, /*dupvert= CDDM_get_verts(explode);*/ /* getting back to object space */ - Mat4Invert(imat,ob->obmat); + invert_m4_m4(imat,ob->obmat); psmd->psys->lattice = psys_get_lattice(&sim); @@ -7501,23 +7499,23 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd, /* get particle state */ psys_particle_on_emitter(psmd,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc0,nor,0,0,0,0); - Mat4MulVecfl(ob->obmat,loc0); + mul_m4_v3(ob->obmat,loc0); state.time=cfra; psys_get_particle_state(&sim, i, &state, 1); vertco=CDDM_get_vert(explode,v)->co; - Mat4MulVecfl(ob->obmat,vertco); + mul_m4_v3(ob->obmat,vertco); VECSUB(vertco,vertco,loc0); /* apply rotation, size & location */ - QuatMulVecf(state.rot,vertco); - VecMulf(vertco,pa->size); + mul_qt_v3(state.rot,vertco); + mul_v3_fl(vertco,pa->size); VECADD(vertco,vertco,state.co); - Mat4MulVecfl(imat,vertco); + mul_m4_v3(imat,vertco); } } BLI_edgehashIterator_free(ehi); @@ -7883,11 +7881,11 @@ static void meshdeformModifier_do( return; /* compute matrices to go in and out of cage object space */ - Mat4Invert(imat, mmd->object->obmat); - Mat4MulMat4(cagemat, ob->obmat, imat); - Mat4MulMat4(cmat, cagemat, mmd->bindmat); - Mat4Invert(iobmat, cmat); - Mat3CpyMat4(icagemat, iobmat); + invert_m4_m4(imat, mmd->object->obmat); + mul_m4_m4m4(cagemat, ob->obmat, imat); + mul_m4_m4m4(cmat, cagemat, mmd->bindmat); + invert_m4_m4(iobmat, cmat); + copy_m3_m4(icagemat, iobmat); /* bind weights if needed */ if(!mmd->bindcos) { @@ -7921,7 +7919,7 @@ static void meshdeformModifier_do( VECCOPY(co, cagemvert[a].co); if(G.rt != 527) { - Mat4MulVecfl(mmd->bindmat, co); + mul_m4_v3(mmd->bindmat, co); /* compute difference with world space bind coord */ VECSUB(dco[a], co, bindcos[a]); } @@ -7975,7 +7973,7 @@ static void meshdeformModifier_do( if(mmd->flag & MOD_MDEF_DYNAMIC_BIND) { /* transform coordinate into cage's local space */ VECCOPY(co, vertexCos[b]); - Mat4MulVecfl(cagemat, co); + mul_m4_v3(cagemat, co); totweight= meshdeform_dynamic_bind(mmd, dco, co); } else { @@ -7992,8 +7990,8 @@ static void meshdeformModifier_do( } if(totweight > 0.0f) { - VecMulf(co, fac/totweight); - Mat3MulVecfl(icagemat, co); + mul_v3_fl(co, fac/totweight); + mul_m3_v3(icagemat, co); if(G.rt != 527) VECADD(vertexCos[b], vertexCos[b], co) else @@ -8084,7 +8082,7 @@ static DerivedMesh *multiresModifier_applyModifier(ModifierData *md, Object *ob, int i; MVert *dst = CDDM_get_verts(final); for(i = 0; i < mmd->undo_verts_tot; ++i) { - VecCopyf(dst[i].co, mmd->undo_verts[i].co); + copy_v3_v3(dst[i].co, mmd->undo_verts[i].co); } CDDM_calc_normals(final); @@ -8365,10 +8363,10 @@ static void shapekeyModifier_deformMatricesEM( int a; if(kb && kb->totelem==numVerts && kb!=key->refkey) { - Mat3Scale(scale, kb->curval); + scale_m3_fl(scale, kb->curval); for(a=0; a<numVerts; a++) - Mat3CpyMat3(defMats[a], scale); + copy_m3_m3(defMats[a], scale); } } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index e1a51a05ca4..47b2914b0f5 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -37,7 +37,7 @@ #include "DNA_scene_types.h" #include "DNA_view3d_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_cdderivedmesh.h" @@ -164,7 +164,7 @@ int multiresModifier_reshape(MultiresModifierData *mmd, Object *dst, Object *src int i; for(i = 0; i < src_me->totvert; ++i) - VecCopyf(mvert[i].co, src_me->mvert[i].co); + copy_v3_v3(mvert[i].co, src_me->mvert[i].co); mrdm->needsFree = 1; MultiresDM_mark_as_modified(mrdm); mrdm->release(mrdm); @@ -178,9 +178,9 @@ int multiresModifier_reshape(MultiresModifierData *mmd, Object *dst, Object *src static void Mat3FromColVecs(float mat[][3], float v1[3], float v2[3], float v3[3]) { - VecCopyf(mat[0], v1); - VecCopyf(mat[1], v2); - VecCopyf(mat[2], v3); + copy_v3_v3(mat[0], v1); + copy_v3_v3(mat[1], v2); + copy_v3_v3(mat[2], v3); } static DerivedMesh *multires_subdisp_pre(DerivedMesh *mrdm, int distance, int simple) @@ -233,7 +233,7 @@ static void multires_subdisp(DerivedMesh *orig, Object *ob, DerivedMesh *final, if(!addverts) { for(i = 0; i < totvert; ++i) { float z[3] = {0,0,0}; - VecCopyf(mvd[i].co, z); + copy_v3_v3(mvd[i].co, z); } } @@ -424,7 +424,7 @@ void multiresModifier_del_levels(struct MultiresModifierData *mmd, struct Object for(j = 0, y = 0; y < st; y += skip) { for(x = 0; x < st; x += skip) { - VecCopyf(disps[j], mdisps[i].disps[y * st + x]); + copy_v3_v3(disps[j], mdisps[i].disps[y * st + x]); ++j; } } @@ -998,27 +998,27 @@ static void calc_disp_mat(MultiresDisplacer *d, float mat[3][3]) if(u < 0) { u = multires_index_at_loc(d->face_index, d->x - 1, d->y, d, &d->edges_primary); - VecSubf(t1, base->co, d->subco[u].co); + sub_v3_v3v3(t1, base->co, d->subco[u].co); } else - VecSubf(t1, d->subco[u].co, base->co); + sub_v3_v3v3(t1, d->subco[u].co, base->co); if(v < 0) { v = multires_index_at_loc(d->face_index, d->x, d->y - 1, d, &d->edges_primary); - VecSubf(t2, base->co, d->subco[v].co); + sub_v3_v3v3(t2, base->co, d->subco[v].co); } else - VecSubf(t2, d->subco[v].co, base->co); + sub_v3_v3v3(t2, d->subco[v].co, base->co); //printf("uu=%d, vv=%d\n", u, v); - Normalize(t1); - Normalize(t2); + normalize_v3(t1); + normalize_v3(t2); Mat3FromColVecs(mat, t1, t2, norm); if(d->invert) { - Mat3Inv(inv, mat); - Mat3CpyMat3(mat, inv); + invert_m3_m3(inv, mat); + copy_m3_m3(mat, inv); } } @@ -1033,23 +1033,23 @@ static void multires_displace(MultiresDisplacer *d, float co[3]) data = d->grid->disps[(d->y * d->spacing) * d->disp_st + (d->x * d->spacing)]; if(d->invert) - VecSubf(disp, co, subco->co); + sub_v3_v3v3(disp, co, subco->co); else - VecCopyf(disp, data); + copy_v3_v3(disp, data); /* Apply ts matrix to displacement */ calc_disp_mat(d, mat); - Mat3MulVecfl(mat, disp); + mul_m3_v3(mat, disp); if(d->invert) { - VecCopyf(data, disp); + copy_v3_v3(data, disp); } else { if(d->type == 4 || d->type == 5) - VecMulf(disp, d->weight); - VecAddf(co, co, disp); + mul_v3_fl(disp, d->weight); + add_v3_v3v3(co, co, disp); } if(d->type == 2) { @@ -1200,7 +1200,7 @@ static void multiresModifier_update(DerivedMesh *dm) /* Subtract the original vertex cos from the new vertex cos */ verts_new = CDDM_get_verts(dm); for(i = 0; i < dm->getNumVerts(dm); ++i) - VecSubf(verts_new[i].co, verts_new[i].co, cur_lvl_orig_verts[i].co); + sub_v3_v3v3(verts_new[i].co, verts_new[i].co, cur_lvl_orig_verts[i].co); final = multires_subdisp_pre(dm, totlvl - lvl, 0); @@ -1579,7 +1579,7 @@ void multires_load_old(DerivedMesh *dm, Multires *mr) /* Transfer verts */ for(i = 0; i < totvert; ++i) - VecCopyf(vdst[i].co, vsrc[vvmap[i]].co); + copy_v3_v3(vdst[i].co, vsrc[vvmap[i]].co); MEM_freeN(vvmap); } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 2776444c8a0..1b0f1f28d2c 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -32,6 +32,7 @@ #endif #include <stdlib.h> +#include <stddef.h> #include <string.h> #include "DNA_ID.h" @@ -53,7 +54,7 @@ #include "BKE_text.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" #include "BLI_threads.h" @@ -903,7 +904,11 @@ void nodeAddSockets(bNode *node, bNodeType *ntype) } } } - +/* Find the first available, non-duplicate name for a given node */ +void nodeUniqueName(bNodeTree *ntree, bNode *node) +{ + BLI_uniquename(&ntree->nodes, node, "Node", '.', offsetof(bNode, name), 32); +} bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup, ID *id) { @@ -937,6 +942,9 @@ bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup, ID *id) } else BLI_strncpy(node->name, ntype->name, NODE_MAXSTR); + + nodeUniqueName(ntree, node); + node->type= ntype->type; node->flag= NODE_SELECT|ntype->flag; node->width= ntype->width; @@ -989,6 +997,8 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node, int internal) bNodeSocket *sock, *oldsock; *nnode= *node; + nodeUniqueName(ntree, nnode); + BLI_addtail(&ntree->nodes, nnode); BLI_duplicatelist(&nnode->inputs, &node->inputs); @@ -1054,7 +1064,7 @@ bNodeTree *ntreeAddTree(int type) if(ntree->type==NTREE_SHADER) BLI_strncpy(ntree->id.name, "NTShader Nodetree", sizeof(ntree->id.name)); else if(ntree->type==NTREE_COMPOSIT) - BLI_strncpy(ntree->id.name, "NTComposit Nodetree", sizeof(ntree->id.name)); + BLI_strncpy(ntree->id.name, "NTCompositing Nodetree", sizeof(ntree->id.name)); else if(ntree->type==NTREE_TEXTURE) BLI_strncpy(ntree->id.name, "NTTexture Nodetree", sizeof(ntree->id.name)); @@ -1662,7 +1672,8 @@ void ntreeSocketUseFlags(bNodeTree *ntree) /* tag all thats in use */ for(link= ntree->links.first; link; link= link->next) { link->fromsock->flag |= SOCK_IN_USE; - link->tosock->flag |= SOCK_IN_USE; + if(link->tosock) // FIXME This can be NULL, when dragging a new link in the UI, should probably copy the node tree for preview render - campbell + link->tosock->flag |= SOCK_IN_USE; } } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index ba8d41f54bb..078ff9d6eeb 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -70,7 +70,7 @@ #include "DNA_world_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BKE_utildefines.h" @@ -622,7 +622,7 @@ void unlink_object(Scene *scene, Object *ob) /* groups */ group= G.main->group.first; while(group) { - rem_from_group(group, ob); + rem_from_group(group, ob, NULL, NULL); group= group->id.next; } @@ -740,13 +740,13 @@ float dof_camera(Object *ob) return 0.0f; if (cam->dof_ob) { /* too simple, better to return the distance on the view axis only - * return VecLenf(ob->obmat[3], cam->dof_ob->obmat[3]); */ + * return len_v3v3(ob->obmat[3], cam->dof_ob->obmat[3]); */ float mat[4][4], obmat[4][4]; - Mat4CpyMat4(obmat, ob->obmat); - Mat4Ortho(obmat); - Mat4Invert(ob->imat, obmat); - Mat4MulMat4(mat, cam->dof_ob->obmat, ob->imat); + copy_m4_m4(obmat, ob->obmat); + normalize_m4(obmat); + invert_m4_m4(ob->imat, obmat); + mul_m4_m4m4(mat, cam->dof_ob->obmat, ob->imat); return (float)fabs(mat[3][2]); } return cam->YF_dofdist; @@ -965,8 +965,8 @@ Object *add_only_object(int type, char *name) /* ob->transflag= OB_QUAT; */ #if 0 /* not used yet */ - QuatOne(ob->quat); - QuatOne(ob->dquat); + unit_qt(ob->quat); + unit_qt(ob->dquat); #endif ob->col[0]= ob->col[1]= ob->col[2]= 1.0; @@ -976,9 +976,9 @@ Object *add_only_object(int type, char *name) ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0; ob->size[0]= ob->size[1]= ob->size[2]= 1.0; - Mat4One(ob->constinv); - Mat4One(ob->parentinv); - Mat4One(ob->obmat); + unit_m4(ob->constinv); + unit_m4(ob->parentinv); + unit_m4(ob->obmat); ob->dt= OB_SHADED; ob->empty_drawtype= OB_ARROWS; ob->empty_drawsize= 1.0; @@ -1464,7 +1464,7 @@ void object_make_proxy(Object *ob, Object *target, Object *gob) } ob->parent= target->parent; /* libdata */ - Mat4CpyMat4(ob->parentinv, target->parentinv); + copy_m4_m4(ob->parentinv, target->parentinv); /* copy animdata stuff - drivers only for now... */ if ((target->adt) && (target->adt->drivers.first)) { @@ -1588,7 +1588,7 @@ void object_scale_to_mat3(Object *ob, float mat[][3]) vec[0]= ob->size[0]+ob->dsize[0]; vec[1]= ob->size[1]+ob->dsize[1]; vec[2]= ob->size[2]+ob->dsize[2]; - SizeToMat3(vec, mat); + size_to_mat3( mat,vec); } // TODO: this should take rotation orders into account later... @@ -1599,29 +1599,29 @@ void object_rot_to_mat3(Object *ob, float mat[][3]) /* initialise the delta-rotation matrix, which will get (pre)multiplied * with the rotation matrix to yield the appropriate rotation */ - Mat3One(dmat); + unit_m3(dmat); /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ if (ob->rotmode > 0) { /* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */ - EulOToMat3(ob->rot, ob->rotmode, rmat); - EulOToMat3(ob->drot, ob->rotmode, dmat); + eulO_to_mat3( rmat,ob->rot, ob->rotmode); + eulO_to_mat3( dmat,ob->drot, ob->rotmode); } else if (ob->rotmode == ROT_MODE_AXISANGLE) { /* axis-angle - not really that great for 3D-changing orientations */ - AxisAngleToMat3(ob->rotAxis, ob->rotAngle, rmat); - AxisAngleToMat3(ob->drotAxis, ob->drotAngle, dmat); + axis_angle_to_mat3( rmat,ob->rotAxis, ob->rotAngle); + axis_angle_to_mat3( dmat,ob->drotAxis, ob->drotAngle); } else { /* quats are normalised before use to eliminate scaling issues */ - NormalQuat(ob->quat); - QuatToMat3(ob->quat, rmat); - QuatToMat3(ob->dquat, dmat); + normalize_qt(ob->quat); + quat_to_mat3( rmat,ob->quat); + quat_to_mat3( dmat,ob->dquat); } /* combine these rotations */ // XXX is this correct? if errors, change the order of multiplication... - Mat3MulMat3(mat, dmat, rmat); + mul_m3_m3m3(mat, dmat, rmat); } void object_to_mat3(Object *ob, float mat[][3]) /* no parent */ @@ -1635,7 +1635,7 @@ void object_to_mat3(Object *ob, float mat[][3]) /* no parent */ /* rot */ object_rot_to_mat3(ob, rmat); - Mat3MulMat3(mat, rmat, smat); + mul_m3_m3m3(mat, rmat, smat); } void object_to_mat4(Object *ob, float mat[][4]) @@ -1644,7 +1644,7 @@ void object_to_mat4(Object *ob, float mat[][4]) object_to_mat3(ob, tmat); - Mat4CpyMat3(mat, tmat); + copy_m4_m3(mat, tmat); mat[3][0]= ob->loc[0] + ob->dloc[0]; mat[3][1]= ob->loc[1] + ob->dloc[1]; @@ -1659,7 +1659,7 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) float q[4], vec[4], dir[3], quat[4], radius, x1, ctime; float timeoffs = 0.0, sf_orig = 0.0; - Mat4One(mat); + unit_m4(mat); cu= par->data; if(cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */ @@ -1707,25 +1707,25 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) if( where_on_path(par, ctime, vec, dir, NULL, &radius) ) { if(cu->flag & CU_FOLLOW) { - vectoquat(dir, ob->trackflag, ob->upflag, quat); + vec_to_quat( quat,dir, ob->trackflag, ob->upflag); /* the tilt */ - Normalize(dir); + normalize_v3(dir); q[0]= (float)cos(0.5*vec[3]); x1= (float)sin(0.5*vec[3]); q[1]= -x1*dir[0]; q[2]= -x1*dir[1]; q[3]= -x1*dir[2]; - QuatMul(quat, q, quat); + mul_qt_qtqt(quat, q, quat); - QuatToMat4(quat, mat); + quat_to_mat4( mat,quat); } if(cu->flag & CU_PATH_RADIUS) { float tmat[4][4], rmat[4][4]; - Mat4Scale(tmat, radius); - Mat4MulMat4(rmat, mat, tmat); - Mat4CpyMat4(mat, rmat); + scale_m4_fl(tmat, radius); + mul_m4_m4m4(rmat, mat, tmat); + copy_m4_m4(mat, rmat); } VECCOPY(mat[3], vec); @@ -1739,7 +1739,7 @@ static void ob_parbone(Object *ob, Object *par, float mat[][4]) float vec[3]; if (par->type!=OB_ARMATURE) { - Mat4One(mat); + unit_m4(mat); return; } @@ -1747,17 +1747,17 @@ static void ob_parbone(Object *ob, Object *par, float mat[][4]) pchan= get_pose_channel(par->pose, ob->parsubstr); if (!pchan){ printf ("Object %s with Bone parent: bone %s doesn't exist\n", ob->id.name+2, ob->parsubstr); - Mat4One(mat); + unit_m4(mat); return; } /* get bone transform */ - Mat4CpyMat4(mat, pchan->pose_mat); + copy_m4_m4(mat, pchan->pose_mat); /* but for backwards compatibility, the child has to move to the tail */ VECCOPY(vec, mat[1]); - VecMulf(vec, pchan->bone->length); - VecAddf(mat[3], mat[3], vec); + mul_v3_fl(vec, pchan->bone->length); + add_v3_v3v3(mat[3], mat[3], vec); } static void give_parvert(Object *par, int nr, float *vec) @@ -1794,7 +1794,7 @@ static void give_parvert(Object *par, int nr, float *vec) for(i = 0; i < numVerts; ++i, ++index) { if(*index == nr) { dm->getVertCo(dm, i, co); - VecAddf(vec, vec, co); + add_v3_v3v3(vec, vec, co); count++; } } @@ -1802,7 +1802,7 @@ static void give_parvert(Object *par, int nr, float *vec) if (count==0) { /* keep as 0,0,0 */ } else if(count > 0) { - VecMulf(vec, 1.0f / count); + mul_v3_fl(vec, 1.0f / count); } else { /* use first index if its out of range */ dm->getVertCo(dm, 0, vec); @@ -1886,7 +1886,7 @@ static void ob_parvert3(Object *ob, Object *par, float mat[][4]) float cmat[3][3], v1[3], v2[3], v3[3], q[4]; /* in local ob space */ - Mat4One(mat); + unit_m4(mat); if (ELEM4(par->type, OB_MESH, OB_SURF, OB_CURVE, OB_LATTICE)) { @@ -1894,17 +1894,17 @@ static void ob_parvert3(Object *ob, Object *par, float mat[][4]) give_parvert(par, ob->par2, v2); give_parvert(par, ob->par3, v3); - triatoquat(v1, v2, v3, q); - QuatToMat3(q, cmat); - Mat4CpyMat3(mat, cmat); + tri_to_quat( q,v1, v2, v3); + quat_to_mat3( cmat,q); + copy_m4_m3(mat, cmat); if(ob->type==OB_CURVE) { VECCOPY(mat[3], v1); } else { - VecAddf(mat[3], v1, v2); - VecAddf(mat[3], mat[3], v3); - VecMulf(mat[3], 0.3333333f); + add_v3_v3v3(mat[3], v1, v2); + add_v3_v3v3(mat[3], mat[3], v3); + mul_v3_fl(mat[3], 0.3333333f); } } } @@ -1992,8 +1992,8 @@ void where_is_object_time(Scene *scene, Object *ob, float ctime) } /* set negative scale flag in object */ - Crossf(vec, ob->obmat[0], ob->obmat[1]); - if( Inpf(vec, ob->obmat[2]) < 0.0 ) ob->transflag |= OB_NEG_SCALE; + cross_v3_v3v3(vec, ob->obmat[0], ob->obmat[1]); + if( dot_v3v3(vec, ob->obmat[2]) < 0.0 ) ob->transflag |= OB_NEG_SCALE; else ob->transflag &= ~OB_NEG_SCALE; } @@ -2007,7 +2007,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ object_to_mat4(ob, locmat); - if(ob->partype & PARSLOW) Mat4CpyMat4(slowmat, obmat); + if(ob->partype & PARSLOW) copy_m4_m4(slowmat, obmat); switch(ob->partype & PARTYPE) { case PAROBJECT: @@ -2019,43 +2019,43 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ } } - if(ok) Mat4MulSerie(totmat, par->obmat, tmat, + if(ok) mul_serie_m4(totmat, par->obmat, tmat, NULL, NULL, NULL, NULL, NULL, NULL); - else Mat4CpyMat4(totmat, par->obmat); + else copy_m4_m4(totmat, par->obmat); break; case PARBONE: ob_parbone(ob, par, tmat); - Mat4MulSerie(totmat, par->obmat, tmat, + mul_serie_m4(totmat, par->obmat, tmat, NULL, NULL, NULL, NULL, NULL, NULL); break; case PARVERT1: - Mat4One(totmat); + unit_m4(totmat); if (simul){ VECCOPY(totmat[3], par->obmat[3]); } else{ give_parvert(par, ob->par1, vec); - VecMat4MulVecfl(totmat[3], par->obmat, vec); + mul_v3_m4v3(totmat[3], par->obmat, vec); } break; case PARVERT3: ob_parvert3(ob, par, tmat); - Mat4MulSerie(totmat, par->obmat, tmat, + mul_serie_m4(totmat, par->obmat, tmat, NULL, NULL, NULL, NULL, NULL, NULL); break; case PARSKEL: - Mat4CpyMat4(totmat, par->obmat); + copy_m4_m4(totmat, par->obmat); break; } // total - Mat4MulSerie(tmat, totmat, ob->parentinv, + mul_serie_m4(tmat, totmat, ob->parentinv, NULL, NULL, NULL, NULL, NULL, NULL); - Mat4MulSerie(obmat, tmat, locmat, + mul_serie_m4(obmat, tmat, locmat, NULL, NULL, NULL, NULL, NULL, NULL); if (simul) { @@ -2063,7 +2063,7 @@ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[ } else{ // external usable originmat - Mat3CpyMat4(originmat, tmat); + copy_m3_m4(originmat, tmat); // origin, voor help line if( (ob->partype & 15)==PARSKEL ) { @@ -2082,9 +2082,9 @@ void solve_tracking (Object *ob, float targetmat[][4]) float totmat[3][3]; float tmat[4][4]; - VecSubf(vec, ob->obmat[3], targetmat[3]); - vectoquat(vec, ob->trackflag, ob->upflag, quat); - QuatToMat3(quat, totmat); + sub_v3_v3v3(vec, ob->obmat[3], targetmat[3]); + vec_to_quat( quat,vec, ob->trackflag, ob->upflag); + quat_to_mat3( totmat,quat); if(ob->parent && (ob->transflag & OB_POWERTRACK)) { /* 'temporal' : clear parent info */ @@ -2097,9 +2097,9 @@ void solve_tracking (Object *ob, float targetmat[][4]) tmat[3][2]= ob->obmat[3][2]; tmat[3][3]= ob->obmat[3][3]; } - else Mat4CpyMat4(tmat, ob->obmat); + else copy_m4_m4(tmat, ob->obmat); - Mat4MulMat34(ob->obmat, totmat, tmat); + mul_m4_m3m4(ob->obmat, totmat, tmat); } @@ -2171,9 +2171,9 @@ void what_does_parent(Scene *scene, Object *ob, Object *workob) { clear_workob(workob); - Mat4One(workob->obmat); - Mat4One(workob->parentinv); - Mat4One(workob->constinv); + unit_m4(workob->obmat); + unit_m4(workob->parentinv); + unit_m4(workob->constinv); workob->parent= ob->parent; workob->track= ob->track; @@ -2261,7 +2261,7 @@ void minmax_object(Object *ob, float *min, float *max) bb= *(cu->bb); for(a=0; a<8; a++) { - Mat4MulVecfl(ob->obmat, bb.vec[a]); + mul_m4_v3(ob->obmat, bb.vec[a]); DO_MINMAX(bb.vec[a], min, max); } break; @@ -2270,10 +2270,10 @@ void minmax_object(Object *ob, float *min, float *max) bPoseChannel *pchan; for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { VECCOPY(vec, pchan->pose_head); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); DO_MINMAX(vec, min, max); VECCOPY(vec, pchan->pose_tail); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); DO_MINMAX(vec, min, max); } break; @@ -2286,7 +2286,7 @@ void minmax_object(Object *ob, float *min, float *max) bb = *mesh_get_bb(ob); for(a=0; a<8; a++) { - Mat4MulVecfl(ob->obmat, bb.vec[a]); + mul_m4_v3(ob->obmat, bb.vec[a]); DO_MINMAX(bb.vec[a], min, max); } } @@ -2298,11 +2298,11 @@ void minmax_object(Object *ob, float *min, float *max) DO_MINMAX(ob->obmat[3], min, max); VECCOPY(vec, ob->obmat[3]); - VecAddf(vec, vec, ob->size); + add_v3_v3v3(vec, vec, ob->size); DO_MINMAX(vec, min, max); VECCOPY(vec, ob->obmat[3]); - VecSubf(vec, vec, ob->size); + sub_v3_v3v3(vec, vec, ob->size); DO_MINMAX(vec, min, max); break; } @@ -2353,11 +2353,11 @@ void object_handle_update(Scene *scene, Object *ob) // printf("ob proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name); if(ob->proxy_from->proxy_group) {/* transform proxy into group space */ Object *obg= ob->proxy_from->proxy_group; - Mat4Invert(obg->imat, obg->obmat); - Mat4MulMat4(ob->obmat, ob->proxy_from->obmat, obg->imat); + invert_m4_m4(obg->imat, obg->obmat); + mul_m4_m4m4(ob->obmat, ob->proxy_from->obmat, obg->imat); } else - Mat4CpyMat4(ob->obmat, ob->proxy_from->obmat); + copy_m4_m4(ob->obmat, ob->proxy_from->obmat); } else where_is_object(scene, ob); @@ -2538,7 +2538,7 @@ int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3 v1 = triangle_indexes[i][0]; v2 = triangle_indexes[i][1]; v3 = triangle_indexes[i][2]; - result = RayIntersectsTriangle(ray_start, ray_normal, bb->vec[v1], bb->vec[v2], bb->vec[v3], &lambda, NULL); + result = isect_ray_tri_v3(ray_start, ray_normal, bb->vec[v1], bb->vec[v2], bb->vec[v3], &lambda, NULL); } return result; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 24d6b229297..e241d5808cd 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -51,7 +51,7 @@ #include "DNA_smoke_types.h" #include "DNA_texture_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_kdtree.h" @@ -618,12 +618,12 @@ static float psys_render_projected_area(ParticleSystem *psys, float *center, flo /* transform to view space */ VECCOPY(co, center); co[3]= 1.0f; - Mat4MulVec4fl(data->viewmat, co); + mul_m4_v4(data->viewmat, co); /* compute two vectors orthogonal to view vector */ VECCOPY(view, co); - Normalize(view); - VecOrthoBasisf(view, ortho1, ortho2); + normalize_v3(view); + ortho_basis_v3v3_v3( ortho1, ortho2,view); /* compute on screen minification */ w= co[2]*data->winmat[2][3] + data->winmat[3][3]; @@ -637,7 +637,7 @@ static float psys_render_projected_area(ParticleSystem *psys, float *center, flo /* viewport of the screen test */ /* project point on screen */ - Mat4MulVec4fl(data->winmat, co); + mul_m4_v4(data->winmat, co); if(co[3] != 0.0f) { co[0]= 0.5f*data->winx*(1.0f + co[0]/co[3]); co[1]= 0.5f*data->winy*(1.0f + co[1]/co[3]); @@ -698,9 +698,9 @@ void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float psys->pathcachebufs.first = psys->pathcachebufs.last = NULL; psys->childcachebufs.first = psys->childcachebufs.last = NULL; - Mat4CpyMat4(data->winmat, winmat); - Mat4MulMat4(data->viewmat, ob->obmat, viewmat); - Mat4MulMat4(data->mat, data->viewmat, winmat); + copy_m4_m4(data->winmat, winmat); + mul_m4_m4m4(data->viewmat, ob->obmat, viewmat); + mul_m4_m4m4(data->mat, data->viewmat, winmat); data->winx= winx; data->winy= winy; @@ -828,11 +828,11 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) if(mf->v4) { VECCOPY(co4, mvert[mf->v4].co); VECADD(facecenter[b], facecenter[b], co4); - facearea[b] += AreaQ3Dfl(co1, co2, co3, co4); + facearea[b] += area_quad_v3(co1, co2, co3, co4); facetotvert[b] += 4; } else { - facearea[b] += AreaT3Dfl(co1, co2, co3); + facearea[b] += area_tri_v3(co1, co2, co3); facetotvert[b] += 3; } } @@ -840,7 +840,7 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) for(a=0; a<totorigface; a++) if(facetotvert[a] > 0) - VecMulf(facecenter[a], 1.0f/facetotvert[a]); + mul_v3_fl(facecenter[a], 1.0f/facetotvert[a]); /* for conversion from BU area / pixel area to reference screen size */ mesh_get_texspace(me, 0, 0, size); @@ -1007,7 +1007,7 @@ void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, Partic float t[4]; if(type<0) { - VecfCubicInterpol(keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt, result->co, result->vel); + interp_cubic_v3( result->co, result->vel,keys[1].co, keys[1].vel, keys[2].co, keys[2].vel, dt); } else { key_curve_position_weights(dt, t, type); @@ -1280,9 +1280,9 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData /* convert velocity to timestep size */ if(pind->keyed || pind->cache || point_vel){ - VecMulf(keys[1].vel, dfra / frs_sec); - VecMulf(keys[2].vel, dfra / frs_sec); - QuatInterpol(result->rot,keys[1].rot,keys[2].rot,keytime); + mul_v3_fl(keys[1].vel, dfra / frs_sec); + mul_v3_fl(keys[2].vel, dfra / frs_sec); + interp_qt_qtqt(result->rot,keys[1].rot,keys[2].rot,keytime); } /* now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between [0,1]->[k2,k3] (k1 & k4 used for cardinal & bspline interpolation)*/ @@ -1292,7 +1292,7 @@ static void do_particle_interpolation(ParticleSystem *psys, int p, ParticleData /* the velocity needs to be converted back from cubic interpolation */ if(pind->keyed || pind->cache || point_vel) - VecMulf(result->vel, frs_sec / dfra); + mul_v3_fl(result->vel, frs_sec / dfra); } /************************************************/ /* Particles on a dm */ @@ -1312,14 +1312,14 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or VECCOPY(n1,(mvert+mface->v1)->no); VECCOPY(n2,(mvert+mface->v2)->no); VECCOPY(n3,(mvert+mface->v3)->no); - Normalize(n1); - Normalize(n2); - Normalize(n3); + normalize_v3(n1); + normalize_v3(n2); + normalize_v3(n3); if(mface->v4) { v4= (mvert+mface->v4)->co; VECCOPY(n4,(mvert+mface->v4)->no); - Normalize(n4); + normalize_v3(n4); vec[0]= w[0]*v1[0] + w[1]*v2[0] + w[2]*v3[0] + w[3]*v4[0]; vec[1]= w[0]*v1[1] + w[1]*v2[1] + w[2]*v3[1] + w[3]*v4[1]; @@ -1332,7 +1332,7 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or nor[2]= w[0]*n1[2] + w[1]*n2[2] + w[2]*n3[2] + w[3]*n4[2]; } else - CalcNormFloat4(v1,v2,v3,v4,nor); + normal_quad_v3(nor,v1,v2,v3,v4); } } else { @@ -1347,7 +1347,7 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or nor[2]= w[0]*n1[2] + w[1]*n2[2] + w[2]*n3[2]; } else - CalcNormFloat(v1,v2,v3,nor); + normal_tri_v3(nor,v1,v2,v3); } } @@ -1361,11 +1361,11 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or } else{ uv1= tuv[0]; uv2= tuv[1]; uv3= tuv[2]; uv4= tuv[3]; - spheremap(v1[0], v1[1], v1[2], uv1, uv1+1); - spheremap(v2[0], v2[1], v2[2], uv2, uv2+1); - spheremap(v3[0], v3[1], v3[2], uv3, uv3+1); + map_to_sphere( uv1, uv1+1,v1[0], v1[1], v1[2]); + map_to_sphere( uv2, uv2+1,v2[0], v2[1], v2[2]); + map_to_sphere( uv3, uv3+1,v3[0], v3[1], v3[2]); if(v4) - spheremap(v4[0], v4[1], v4[2], uv4, uv4+1); + map_to_sphere( uv4, uv4+1,v4[0], v4[1], v4[2]); } if(v4){ @@ -1375,8 +1375,8 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or t1= uv3[1] - uv1[1]; t2= uv4[1] - uv1[1]; - VecSubf(e1, v3, v1); - VecSubf(e2, v4, v1); + sub_v3_v3v3(e1, v3, v1); + sub_v3_v3v3(e2, v4, v1); } else{ s1= uv2[0] - uv1[0]; @@ -1385,8 +1385,8 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or t1= uv2[1] - uv1[1]; t2= uv3[1] - uv1[1]; - VecSubf(e1, v2, v1); - VecSubf(e2, v3, v1); + sub_v3_v3v3(e1, v2, v1); + sub_v3_v3v3(e2, v3, v1); } vtan[0] = (s1*e2[0] - s2*e1[0]); @@ -1411,7 +1411,7 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or orco[2]= w[0]*o1[2] + w[1]*o2[2] + w[2]*o3[2] + w[3]*o4[2]; if(ornor) - CalcNormFloat4(o1, o2, o3, o4, ornor); + normal_quad_v3( ornor,o1, o2, o3, o4); } else { orco[0]= w[0]*o1[0] + w[1]*o2[0] + w[2]*o3[0]; @@ -1419,7 +1419,7 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or orco[2]= w[0]*o1[2] + w[1]*o2[2] + w[2]*o3[2]; if(ornor) - CalcNormFloat(o1, o2, o3, ornor); + normal_tri_v3( ornor,o1, o2, o3); } } else { @@ -1517,10 +1517,10 @@ static void psys_origspace_to_w(OrigSpaceFace *osface, int quad, float *w, float if(quad) { v[3][0]= osface->uv[3][0]; v[3][1]= osface->uv[3][1]; v[3][2]= 0.0f; - MeanValueWeights(v, 4, co, neww); + interp_weights_poly_v3( neww,v, 4, co); } else { - MeanValueWeights(v, 3, co, neww); + interp_weights_poly_v3( neww,v, 3, co); neww[3]= 0.0f; } } @@ -1566,10 +1566,10 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, float * /* check that this intersects - Its possible this misses :/ - * could also check its not between */ if(quad) { - if(IsectPQ2Df(uv, faceuv[0], faceuv[1], faceuv[2], faceuv[3])) + if(isect_point_quad_v2(uv, faceuv[0], faceuv[1], faceuv[2], faceuv[3])) return findex; } - else if(IsectPT2Df(uv, faceuv[0], faceuv[1], faceuv[2])) + else if(isect_point_tri_v2(uv, faceuv[0], faceuv[1], faceuv[2])) return findex; } } @@ -1582,10 +1582,10 @@ int psys_particle_dm_face_lookup(Object *ob, DerivedMesh *dm, int index, float * /* check that this intersects - Its possible this misses :/ - * could also check its not between */ if(quad) { - if(IsectPQ2Df(uv, faceuv[0], faceuv[1], faceuv[2], faceuv[3])) + if(isect_point_quad_v2(uv, faceuv[0], faceuv[1], faceuv[2], faceuv[3])) return findex; } - else if(IsectPT2Df(uv, faceuv[0], faceuv[1], faceuv[2])) + else if(isect_point_tri_v2(uv, faceuv[0], faceuv[1], faceuv[2])) return findex; } } @@ -1678,7 +1678,7 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache if(nor) { dm->getVertNo(dm,mapindex,nor); - Normalize(nor); + normalize_v3(nor); } if(orco) @@ -1686,7 +1686,7 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache if(ornor) { dm->getVertNo(dm,mapindex,nor); - Normalize(nor); + normalize_v3(nor); } if(utan && vtan) { @@ -1711,8 +1711,8 @@ void psys_particle_on_dm(DerivedMesh *dm, int from, int index, int index_dmcache if(nor) VECCOPY(nor,tmpnor); - Normalize(tmpnor); - VecMulf(tmpnor,-foffset); + normalize_v3(tmpnor); + mul_v3_fl(tmpnor,-foffset); VECADD(vec,vec,tmpnor); } else @@ -1835,42 +1835,42 @@ static void do_prekink(ParticleKey *state, ParticleKey *par, float *par_rot, flo if(par_rot) QUATCOPY(q2,par_rot) else - vectoquat(par->vel,axis,(axis+1)%3, q2); - QuatMulVecf(q2,vec); - VecMulf(vec,amplitude); + vec_to_quat( q2,par->vel,axis,(axis+1)%3); + mul_qt_v3(q2,vec); + mul_v3_fl(vec,amplitude); VECADD(state->co,state->co,vec); VECSUB(vec,state->co,par->co); if(t!=0.0) - VecRotToQuat(par->vel,t,q1); + axis_angle_to_quat(q1,par->vel,t); - QuatMulVecf(q1,vec); + mul_qt_v3(q1,vec); VECADD(state->co,par->co,vec); break; case PART_KINK_RADIAL: VECSUB(vec,state->co,par->co); - Normalize(vec); - VecMulf(vec,amplitude*(float)sin(t)); + normalize_v3(vec); + mul_v3_fl(vec,amplitude*(float)sin(t)); VECADD(state->co,state->co,vec); break; case PART_KINK_WAVE: vec[axis]=1.0; if(obmat) - Mat4Mul3Vecfl(obmat,vec); + mul_mat3_m4_v3(obmat,vec); if(par_rot) - QuatMulVecf(par_rot,vec); + mul_qt_v3(par_rot,vec); - Projf(q1,vec,par->vel); + project_v3_v3v3(q1,vec,par->vel); VECSUB(vec,vec,q1); - Normalize(vec); + normalize_v3(vec); - VecMulf(vec,amplitude*(float)sin(t)); + mul_v3_fl(vec,amplitude*(float)sin(t)); VECADD(state->co,state->co,vec); break; @@ -1884,46 +1884,46 @@ static void do_prekink(ParticleKey *state, ParticleKey *par, float *par_rot, flo if(par_rot) QUATCOPY(q2,par_rot) else - vectoquat(par->vel,axis,(axis+1)%3,q2); - QuatMulVecf(q2,y_vec); - QuatMulVecf(q2,z_vec); + vec_to_quat(q2,par->vel,axis,(axis+1)%3); + mul_qt_v3(q2,y_vec); + mul_qt_v3(q2,z_vec); VECSUB(vec_from_par,state->co,par->co); VECCOPY(vec_one,vec_from_par); - radius=Normalize(vec_one); + radius=normalize_v3(vec_one); - inp_y=Inpf(y_vec,vec_one); - inp_z=Inpf(z_vec,vec_one); + inp_y=dot_v3v3(y_vec,vec_one); + inp_z=dot_v3v3(z_vec,vec_one); if(inp_y>0.5){ VECCOPY(state_co,y_vec); - VecMulf(y_vec,amplitude*(float)cos(t)); - VecMulf(z_vec,amplitude/2.0f*(float)sin(2.0f*t)); + mul_v3_fl(y_vec,amplitude*(float)cos(t)); + mul_v3_fl(z_vec,amplitude/2.0f*(float)sin(2.0f*t)); } else if(inp_z>0.0){ VECCOPY(state_co,z_vec); - VecMulf(state_co,(float)sin(M_PI/3.0f)); + mul_v3_fl(state_co,(float)sin(M_PI/3.0f)); VECADDFAC(state_co,state_co,y_vec,-0.5f); - VecMulf(y_vec,-amplitude*(float)cos(t + M_PI/3.0f)); - VecMulf(z_vec,amplitude/2.0f*(float)cos(2.0f*t + M_PI/6.0f)); + mul_v3_fl(y_vec,-amplitude*(float)cos(t + M_PI/3.0f)); + mul_v3_fl(z_vec,amplitude/2.0f*(float)cos(2.0f*t + M_PI/6.0f)); } else{ VECCOPY(state_co,z_vec); - VecMulf(state_co,-(float)sin(M_PI/3.0f)); + mul_v3_fl(state_co,-(float)sin(M_PI/3.0f)); VECADDFAC(state_co,state_co,y_vec,-0.5f); - VecMulf(y_vec,amplitude*(float)-sin(t+M_PI/6.0f)); - VecMulf(z_vec,amplitude/2.0f*(float)-sin(2.0f*t+M_PI/3.0f)); + mul_v3_fl(y_vec,amplitude*(float)-sin(t+M_PI/6.0f)); + mul_v3_fl(z_vec,amplitude/2.0f*(float)-sin(2.0f*t+M_PI/3.0f)); } - VecMulf(state_co,amplitude); + mul_v3_fl(state_co,amplitude); VECADD(state_co,state_co,par->co); VECSUB(vec_from_par,state->co,state_co); - length=Normalize(vec_from_par); - VecMulf(vec_from_par,MIN2(length,amplitude/2.0f)); + length=normalize_v3(vec_from_par); + mul_v3_fl(vec_from_par,MIN2(length,amplitude/2.0f)); VECADD(state_co,par->co,y_vec); VECADD(state_co,state_co,z_vec); @@ -1934,7 +1934,7 @@ static void do_prekink(ParticleKey *state, ParticleKey *par, float *par_rot, flo if(t<shape){ shape=t/shape; shape=(float)sqrt((double)shape); - VecLerpf(state->co,state->co,state_co,shape); + interp_v3_v3v3(state->co,state->co,state_co,shape); } else{ VECCOPY(state->co,state_co); @@ -1958,7 +1958,7 @@ static void do_clump(ParticleKey *state, ParticleKey *par, float time, float clu clump = -clumpfac*pa_clump*(float)pow(1.0-(double)time,(double)cpow); else clump = clumpfac*pa_clump*(float)pow((double)time,(double)cpow); - VecLerpf(state->co,state->co,par->co,clump); + interp_v3_v3v3(state->co,state->co,par->co,clump); } } void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) @@ -1990,7 +1990,7 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) VECSUB(efd.vec_to_point, state.co, eff->guide_loc); VECCOPY(efd.nor, eff->guide_dir); - efd.distance = VecLength(efd.vec_to_point); + efd.distance = len_v3(efd.vec_to_point); VECCOPY(data->vec_to_point, efd.vec_to_point); data->strength = effector_falloff(eff, &efd, &point, weights); @@ -2037,33 +2037,33 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) return 0; } - Mat4MulVecfl(eff->ob->obmat, guidevec); - Mat4Mul3Vecfl(eff->ob->obmat, guidedir); + mul_m4_v3(eff->ob->obmat, guidevec); + mul_mat3_m4_v3(eff->ob->obmat, guidedir); - Normalize(guidedir); + normalize_v3(guidedir); VECCOPY(vec_to_point, data->vec_to_point); if(guidetime != 0.0){ /* curve direction */ - Crossf(temp, eff->guide_dir, guidedir); - angle = Inpf(eff->guide_dir, guidedir)/(VecLength(eff->guide_dir)); + cross_v3_v3v3(temp, eff->guide_dir, guidedir); + angle = dot_v3v3(eff->guide_dir, guidedir)/(len_v3(eff->guide_dir)); angle = saacos(angle); - VecRotToQuat(temp, angle, rot2); - QuatMulVecf(rot2, vec_to_point); + axis_angle_to_quat( rot2,temp, angle); + mul_qt_v3(rot2, vec_to_point); /* curve tilt */ - VecRotToQuat(guidedir, guidevec[3] - eff->guide_loc[3], rot2); - QuatMulVecf(rot2, vec_to_point); + axis_angle_to_quat( rot2,guidedir, guidevec[3] - eff->guide_loc[3]); + mul_qt_v3(rot2, vec_to_point); } /* curve taper */ if(cu->taperobj) - VecMulf(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength*guidetime*100.0), 100)); + mul_v3_fl(vec_to_point, calc_taper(eff->scene, cu->taperobj, (int)(data->strength*guidetime*100.0), 100)); else{ /* curve size*/ if(cu->flag & CU_PATH_RADIUS) { - VecMulf(vec_to_point, radius); + mul_v3_fl(vec_to_point, radius); } } par.co[0] = par.co[1] = par.co[2] = 0.0f; @@ -2081,13 +2081,13 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time) if(totstrength != 0.0){ if(totstrength > 1.0) - VecMulf(effect, 1.0f / totstrength); + mul_v3_fl(effect, 1.0f / totstrength); CLAMP(totstrength, 0.0, 1.0); //VECADD(effect,effect,pa_zero); - VecLerpf(state->co, state->co, effect, totstrength); + interp_v3_v3v3(state->co, state->co, effect, totstrength); - Normalize(veffect); - VecMulf(veffect, VecLength(state->vel)); + normalize_v3(veffect); + mul_v3_fl(veffect, len_v3(state->vel)); VECCOPY(state->vel, veffect); return 1; } @@ -2102,7 +2102,7 @@ static void do_rough(float *loc, float mat[4][4], float t, float fac, float size if((float)fabs((float)(-1.5+loc[0]+loc[1]+loc[2]))<1.5f*thres) return; VECCOPY(rco,loc); - VecMulf(rco,t); + mul_v3_fl(rco,t); rough[0]=-1.0f+2.0f*BLI_gTurbulence(size, rco[0], rco[1], rco[2], 2,0,2); rough[1]=-1.0f+2.0f*BLI_gTurbulence(size, rco[1], rco[2], rco[0], 2,0,2); rough[2]=-1.0f+2.0f*BLI_gTurbulence(size, rco[2], rco[0], rco[1], 2,0,2); @@ -2117,10 +2117,10 @@ static void do_rough_end(float *loc, float mat[4][4], float t, float fac, float float roughfac; roughfac=fac*(float)pow((double)t,shape); - Vec2Copyf(rough,loc); + copy_v2_v2(rough,loc); rough[0]=-1.0f+2.0f*rough[0]; rough[1]=-1.0f+2.0f*rough[1]; - Vec2Mulf(rough,roughfac); + mul_v2_fl(rough,roughfac); VECADDFAC(state->co,state->co,mat[0],rough[0]); VECADDFAC(state->co,state->co,mat[1],rough[1]); @@ -2142,23 +2142,23 @@ static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheK pd_point_from_particle(sim, sim->psys->particles+i, &eff_key, &epoint); pdDoEffectors(sim->psys->effectors, sim->colliders, sim->psys->part->effector_weights, &epoint, force, NULL); - VecMulf(force, effector*pow((float)k / (float)steps, 100.0f * sim->psys->part->eff_hair) / (float)steps); + mul_v3_fl(force, effector*pow((float)k / (float)steps, 100.0f * sim->psys->part->eff_hair) / (float)steps); - VecAddf(force, force, vec); + add_v3_v3v3(force, force, vec); - Normalize(force); + normalize_v3(force); VECADDFAC(ca->co, (ca-1)->co, force, *length); if(k < steps) { - VecSubf(vec, (ca+1)->co, ca->co); - *length = VecLength(vec); + sub_v3_v3v3(vec, (ca+1)->co, ca->co); + *length = len_v3(vec); } } static int check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *state, float max_length, float *cur_length, float length, float *dvec) { if(*cur_length + length > max_length){ - VecMulf(dvec, (max_length - *cur_length) / length); + mul_v3_fl(dvec, (max_length - *cur_length) / length); VECADD(state->co, (state - 1)->co, dvec); keys->steps = k; /* something over the maximum step value */ @@ -2172,13 +2172,13 @@ static int check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *st static void offset_child(ChildParticle *cpa, ParticleKey *par, ParticleKey *child, float flat, float radius) { VECCOPY(child->co,cpa->fuv); - VecMulf(child->co,radius); + mul_v3_fl(child->co,radius); child->co[0]*=flat; VECCOPY(child->vel,par->vel); - QuatMulVecf(par->rot,child->co); + mul_qt_v3(par->rot,child->co); QUATCOPY(child->rot,par->rot); @@ -2247,14 +2247,14 @@ static void get_strand_normal(Material *ma, float *surfnor, float surfdist, floa return; if(ma->mode & MA_STR_SURFDIFF) { - Crossf(cross, surfnor, nor); - Crossf(nstrand, nor, cross); + cross_v3_v3v3(cross, surfnor, nor); + cross_v3_v3v3(nstrand, nor, cross); blend= INPR(nstrand, surfnor); CLAMP(blend, 0.0f, 1.0f); - VecLerpf(vnor, nstrand, surfnor, blend); - Normalize(vnor); + interp_v3_v3v3(vnor, nstrand, surfnor, blend); + normalize_v3(vnor); } else VECCOPY(vnor, nor) @@ -2262,8 +2262,8 @@ static void get_strand_normal(Material *ma, float *surfnor, float surfdist, floa if(ma->strand_surfnor > 0.0f) { if(ma->strand_surfnor > surfdist) { blend= (ma->strand_surfnor - surfdist)/ma->strand_surfnor; - VecLerpf(vnor, vnor, surfnor, blend); - Normalize(vnor); + interp_v3_v3v3(vnor, vnor, surfnor, blend); + normalize_v3(vnor); } } @@ -2440,7 +2440,7 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle if(part->path_start==0.0f) { /* we need to save the actual root position of the child for positioning it accurately to the surface of the emitter */ VECCOPY(cpa_1st,co); - Mat4MulVecfl(ob->obmat,cpa_1st); + mul_m4_v3(ob->obmat,cpa_1st); } pa = psys->particles + cpa->parent; @@ -2538,8 +2538,8 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle do_path_effectors(&ctx->sim, cpa->pa[0], state, k, ctx->steps, keys->co, ptex.effector, 0.0f, ctx->cfra, &eff_length, eff_vec); } else { - VecSubf(eff_vec,(state+1)->co,state->co); - eff_length= VecLength(eff_vec); + sub_v3_v3v3(eff_vec,(state+1)->co,state->co); + eff_length= len_v3(eff_vec); } } } @@ -2599,17 +2599,17 @@ static void psys_thread_create_path(ParticleThread *thread, struct ChildParticle // } // if(i<psys->totpart) - // VecLerpf(state->co, (pcache[i] + k)->co, state->co, branchfac); + // interp_v3_v3v3(state->co, (pcache[i] + k)->co, state->co, branchfac); // else // /* this is not threadsafe, but should only happen for // * branching particles particles, which are not threaded */ - // VecLerpf(state->co, (cache[i - psys->totpart] + k)->co, state->co, branchfac); + // interp_v3_v3v3(state->co, (cache[i - psys->totpart] + k)->co, state->co, branchfac); //} /* we have to correct velocity because of kink & clump */ if(k>1){ VECSUB((state-1)->vel,state->co,(state-2)->co); - VecMulf((state-1)->vel,0.5); + mul_v3_fl((state-1)->vel,0.5); if(ctx->ma && (part->draw & PART_DRAW_MAT_COL)) get_strand_normal(ctx->ma, ornor, cur_length, (state-1)->vel); @@ -2841,9 +2841,9 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /* dynamic hair is in object space */ /* keyed and baked are allready in global space */ if(hair_dm) - Mat4MulVecfl(sim->ob->obmat, result.co); + mul_m4_v3(sim->ob->obmat, result.co); else if(!keyed && !baked && !(psys->flag & PSYS_GLOBAL_HAIR)) - Mat4MulVecfl(hairmat, result.co); + mul_m4_v3(hairmat, result.co); VECCOPY(ca->co, result.co); VECCOPY(ca->col, col); @@ -2851,8 +2851,8 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /*--modify paths and calculate rotation & velocity--*/ - VecSubf(vec,(cache[p]+1)->co,cache[p]->co); - length = VecLength(vec); + sub_v3_v3v3(vec,(cache[p]+1)->co,cache[p]->co); + length = len_v3(vec); effector= 1.0f; if(vg_effector) @@ -2882,7 +2882,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /* calculate initial tangent for incremental rotations */ VECSUB(tangent, ca->co, (ca - 1)->co); VECCOPY(prev_tangent, tangent); - Normalize(prev_tangent); + normalize_v3(prev_tangent); /* First rotation is based on emitting face orientation. */ /* This is way better than having flipping rotations resulting */ @@ -2890,13 +2890,13 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) /* It's not an ideal solution though since it disregards the */ /* initial tangent, but taking that in to account will allow */ /* the possibility of flipping again. -jahka */ - Mat3ToQuat_is_ok(rotmat, (ca-1)->rot); + mat3_to_quat_is_ok( (ca-1)->rot,rotmat); } else { VECSUB(tangent, ca->co, (ca - 1)->co); - Normalize(tangent); + normalize_v3(tangent); - cosangle= Inpf(tangent, prev_tangent); + cosangle= dot_v3v3(tangent, prev_tangent); /* note we do the comparison on cosangle instead of * angle, since floating point accuracy makes it give @@ -2906,9 +2906,9 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra) } else { angle= saacos(cosangle); - Crossf(normal, prev_tangent, tangent); - VecRotToQuat(normal, angle, q); - QuatMul((ca - 1)->rot, q, (ca - 2)->rot); + cross_v3_v3v3(normal, prev_tangent, tangent); + axis_angle_to_quat( q,normal, angle); + mul_qt_qtqt((ca - 1)->rot, q, (ca - 2)->rot); } VECCOPY(prev_tangent, tangent); @@ -3034,7 +3034,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* non-hair points are allready in global space */ if(psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { - Mat4MulVecfl(hairmat, result.co); + mul_m4_v3(hairmat, result.co); /* create rotations for proper creation of children */ if(k) { @@ -3044,7 +3044,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* calculate initial tangent for incremental rotations */ VECSUB(tangent, ca->co, (ca - 1)->co); VECCOPY(prev_tangent, tangent); - Normalize(prev_tangent); + normalize_v3(prev_tangent); /* First rotation is based on emitting face orientation. */ /* This is way better than having flipping rotations resulting */ @@ -3052,13 +3052,13 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf /* It's not an ideal solution though since it disregards the */ /* initial tangent, but taking that in to account will allow */ /* the possibility of flipping again. -jahka */ - Mat3ToQuat_is_ok(rotmat, (ca-1)->rot); + mat3_to_quat_is_ok( (ca-1)->rot,rotmat); } else { VECSUB(tangent, ca->co, (ca - 1)->co); - Normalize(tangent); + normalize_v3(tangent); - cosangle= Inpf(tangent, prev_tangent); + cosangle= dot_v3v3(tangent, prev_tangent); /* note we do the comparison on cosangle instead of * angle, since floating point accuracy makes it give @@ -3068,9 +3068,9 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } else { angle= saacos(cosangle); - Crossf(normal, prev_tangent, tangent); - VecRotToQuat(normal, angle, q); - QuatMul((ca - 1)->rot, q, (ca - 2)->rot); + cross_v3_v3v3(normal, prev_tangent, tangent); + axis_angle_to_quat( q,normal, angle); + mul_qt_qtqt((ca - 1)->rot, q, (ca - 2)->rot); } VECCOPY(prev_tangent, tangent); @@ -3094,13 +3094,13 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf } else{ keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); - VecLerpf(ca->col, sel_col, nosel_col, keytime); + interp_v3_v3v3(ca->col, sel_col, nosel_col, keytime); } } else{ if((ekey + (pind.ekey[1] - point->keys))->flag & PEK_SELECT){ keytime = (t - (*pind.ekey[0]->time))/((*pind.ekey[1]->time) - (*pind.ekey[0]->time)); - VecLerpf(ca->col, nosel_col, sel_col, keytime); + interp_v3_v3v3(ca->col, nosel_col, sel_col, keytime); } else{ VECCOPY(ca->col, nosel_col); @@ -3144,12 +3144,12 @@ static void key_from_object(Object *ob, ParticleKey *key){ VECADD(key->vel,key->vel,key->co); - Mat4MulVecfl(ob->obmat,key->co); - Mat4MulVecfl(ob->obmat,key->vel); - Mat4ToQuat(ob->obmat,q); + mul_m4_v3(ob->obmat,key->co); + mul_m4_v3(ob->obmat,key->vel); + mat4_to_quat(q,ob->obmat); VECSUB(key->vel,key->vel,key->co); - QuatMul(key->rot,q,key->rot); + mul_qt_qtqt(key->rot,q,key->rot); } #endif @@ -3161,7 +3161,7 @@ static void triatomat(float *v1, float *v2, float *v3, float (*uv)[2], float mat mat[3][3]= 1.0f; /* first axis is the normal */ - CalcNormFloat(v1, v2, v3, mat[2]); + normal_tri_v3( mat[2],v1, v2, v3); /* second axis along (1, 0) in uv space */ if(uv) { @@ -3180,18 +3180,18 @@ static void triatomat(float *v1, float *v2, float *v3, float (*uv)[2], float mat mat[1][0]= w1*(v2[0] - v1[0]) + w2*(v3[0] - v1[0]); mat[1][1]= w1*(v2[1] - v1[1]) + w2*(v3[1] - v1[1]); mat[1][2]= w1*(v2[2] - v1[2]) + w2*(v3[2] - v1[2]); - Normalize(mat[1]); + normalize_v3(mat[1]); } else mat[1][0]= mat[1][1]= mat[1][2]= 0.0f; } else { - VecSubf(mat[1], v2, v1); - Normalize(mat[1]); + sub_v3_v3v3(mat[1], v2, v1); + normalize_v3(mat[1]); } /* third as a cross product */ - Crossf(mat[0], mat[1], mat[2]); + cross_v3_v3v3(mat[0], mat[1], mat[2]); } static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float mat[][4], int orco) @@ -3203,7 +3203,7 @@ static void psys_face_mat(Object *ob, DerivedMesh *dm, ParticleData *pa, float m int i = pa->num_dmcache==DMCACHE_NOTFOUND ? pa->num : pa->num_dmcache; - if (i==-1 || i >= dm->getNumFaces(dm)) { Mat4One(mat); return; } + if (i==-1 || i >= dm->getNumFaces(dm)) { unit_m4(mat); return; } mface=dm->getFaceData(dm,i,CD_MFACE); osface=dm->getFaceData(dm,i,CD_ORIGSPACE); @@ -3252,8 +3252,8 @@ void psys_vec_rot_to_face(DerivedMesh *dm, ParticleData *pa, float *vec) float mat[4][4]; psys_face_mat(0, dm, pa, mat, 0); - Mat4Transp(mat); /* cheap inverse for rotation matrix */ - Mat4Mul3Vecfl(mat, vec); + transpose_m4(mat); /* cheap inverse for rotation matrix */ + mul_mat3_m4_v3(mat, vec); } void psys_mat_hair_to_global(Object *ob, DerivedMesh *dm, short from, ParticleData *pa, float hairmat[][4]) @@ -3262,7 +3262,7 @@ void psys_mat_hair_to_global(Object *ob, DerivedMesh *dm, short from, ParticleDa psys_mat_hair_to_object(ob, dm, from, pa, facemat); - Mat4MulMat4(hairmat, facemat, ob->obmat); + mul_m4_m4m4(hairmat, facemat, ob->obmat); } /************************************************/ @@ -3849,8 +3849,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * if(!keyed && !cached) { if((pa->flag & PARS_REKEY)==0) { psys_mat_hair_to_global(sim->ob, sim->psmd->dm, part->from, pa, hairmat); - Mat4MulVecfl(hairmat, state->co); - Mat4Mul3Vecfl(hairmat, state->vel); + mul_m4_v3(hairmat, state->co); + mul_mat3_m4_v3(hairmat, state->vel); if(sim->psys->effectors && (part->flag & PART_CHILD_GUIDE)==0) { do_guides(sim->psys->effectors, state, p, state->time); @@ -3863,7 +3863,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * } } else if(totchild){ - //Mat4Invert(imat,ob->obmat); + //invert_m4_m4(imat,ob->obmat); cpa=psys->child+p-totpart; @@ -3902,7 +3902,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* we need to save the actual root position of the child for positioning it accurately to the surface of the emitter */ //VECCOPY(cpa_1st,co); - //Mat4MulVecfl(ob->obmat,cpa_1st); + //mul_m4_v3(ob->obmat,cpa_1st); pa = psys->particles + cpa->parent; @@ -3979,22 +3979,22 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * /* try to estimate correct velocity */ if(vel){ ParticleKey tstate; - float length = VecLength(state->vel); + float length = len_v3(state->vel); if(t>=0.001f){ tstate.time=t-0.001f; psys_get_particle_on_path(sim,p,&tstate,0); VECSUB(state->vel,state->co,tstate.co); - Normalize(state->vel); + normalize_v3(state->vel); } else{ tstate.time=t+0.001f; psys_get_particle_on_path(sim,p,&tstate,0); VECSUB(state->vel,tstate.co,state->co); - Normalize(state->vel); + normalize_v3(state->vel); } - VecMulf(state->vel, length); + mul_v3_fl(state->vel, length); } } } @@ -4101,16 +4101,16 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta keytime = (state->time - keys[1].time) / dfra; /* convert velocity to timestep size */ - VecMulf(keys[1].vel, dfra * timestep); - VecMulf(keys[2].vel, dfra * timestep); + mul_v3_fl(keys[1].vel, dfra * timestep); + mul_v3_fl(keys[2].vel, dfra * timestep); psys_interpolate_particle(-1, keys, keytime, state, 1); /* convert back to real velocity */ - VecMulf(state->vel, 1.0f / (dfra * timestep)); + mul_v3_fl(state->vel, 1.0f / (dfra * timestep)); - VecLerpf(state->ave, keys[1].ave, keys[2].ave, keytime); - QuatInterpol(state->rot, keys[1].rot, keys[2].rot, keytime); + interp_v3_v3v3(state->ave, keys[1].ave, keys[2].ave, keytime); + interp_qt_qtqt(state->rot, keys[1].rot, keys[2].rot, keytime); } } else { @@ -4184,8 +4184,8 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa float loc[3], nor[3], vec[3], side[3], len, obrotmat[4][4], qmat[4][4]; float xvec[3] = {-1.0, 0.0, 0.0}, q[4]; - VecSubf(vec, (cache+cache->steps-1)->co, cache->co); - len= Normalize(vec); + sub_v3_v3v3(vec, (cache+cache->steps-1)->co, cache->co); + len= normalize_v3(vec); if(pa) psys_particle_on_emitter(psmd,sim->psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,loc,nor,0,0,0,0); @@ -4198,17 +4198,17 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa if(!pa) pa= psys->particles+cpa->pa[0]; - vectoquat(xvec, ob->trackflag, ob->upflag, q); - QuatToMat4(q, obrotmat); + vec_to_quat( q,xvec, ob->trackflag, ob->upflag); + quat_to_mat4( obrotmat,q); obrotmat[3][3]= 1.0f; - QuatToMat4(pa->state.rot, qmat); - Mat4MulMat4(mat, obrotmat, qmat); + quat_to_mat4( qmat,pa->state.rot); + mul_m4_m4m4(mat, obrotmat, qmat); } else { /* make sure that we get a proper side vector */ - if(fabs(Inpf(nor,vec))>0.999999) { - if(fabs(Inpf(nor,xvec))>0.999999) { + if(fabs(dot_v3v3(nor,vec))>0.999999) { + if(fabs(dot_v3v3(nor,xvec))>0.999999) { nor[0] = 0.0f; nor[1] = 1.0f; nor[2] = 0.0f; @@ -4219,11 +4219,11 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa nor[2] = 0.0f; } } - Crossf(side, nor, vec); - Normalize(side); - Crossf(nor, vec, side); + cross_v3_v3v3(side, nor, vec); + normalize_v3(side); + cross_v3_v3v3(nor, vec, side); - Mat4One(mat); + unit_m4(mat); VECCOPY(mat[0], vec); VECCOPY(mat[1], side); VECCOPY(mat[2], nor); @@ -4244,62 +4244,62 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] if(bb->lock && (bb->align == PART_BB_VIEW)) { VECCOPY(xvec, bb->ob->obmat[0]); - Normalize(xvec); + normalize_v3(xvec); VECCOPY(yvec, bb->ob->obmat[1]); - Normalize(yvec); + normalize_v3(yvec); VECCOPY(zvec, bb->ob->obmat[2]); - Normalize(zvec); + normalize_v3(zvec); } else if(bb->align == PART_BB_VEL) { float temp[3]; VECCOPY(temp, bb->vel); - Normalize(temp); + normalize_v3(temp); VECSUB(zvec, bb->ob->obmat[3], bb->vec); if(bb->lock) { - float fac = -Inpf(zvec, temp); + float fac = -dot_v3v3(zvec, temp); VECADDFAC(zvec, zvec, temp, fac); } - Normalize(zvec); + normalize_v3(zvec); - Crossf(xvec,temp,zvec); - Normalize(xvec); + cross_v3_v3v3(xvec,temp,zvec); + normalize_v3(xvec); - Crossf(yvec,zvec,xvec); + cross_v3_v3v3(yvec,zvec,xvec); } else { VECSUB(zvec, bb->ob->obmat[3], bb->vec); if(bb->lock) zvec[bb->align] = 0.0f; - Normalize(zvec); + normalize_v3(zvec); if(bb->align < PART_BB_VIEW) - Crossf(xvec, onevec, zvec); + cross_v3_v3v3(xvec, onevec, zvec); else - Crossf(xvec, bb->ob->obmat[1], zvec); - Normalize(xvec); + cross_v3_v3v3(xvec, bb->ob->obmat[1], zvec); + normalize_v3(xvec); - Crossf(yvec,zvec,xvec); + cross_v3_v3v3(yvec,zvec,xvec); } VECCOPY(tvec, xvec); VECCOPY(tvec2, yvec); - VecMulf(xvec, cos(bb->tilt * (float)M_PI)); - VecMulf(tvec2, sin(bb->tilt * (float)M_PI)); + mul_v3_fl(xvec, cos(bb->tilt * (float)M_PI)); + mul_v3_fl(tvec2, sin(bb->tilt * (float)M_PI)); VECADD(xvec, xvec, tvec2); - VecMulf(yvec, cos(bb->tilt * (float)M_PI)); - VecMulf(tvec, -sin(bb->tilt * (float)M_PI)); + mul_v3_fl(yvec, cos(bb->tilt * (float)M_PI)); + mul_v3_fl(tvec, -sin(bb->tilt * (float)M_PI)); VECADD(yvec, yvec, tvec); - VecMulf(xvec, bb->size); - VecMulf(yvec, bb->size); + mul_v3_fl(xvec, bb->size); + mul_v3_fl(yvec, bb->size); VECADDFAC(center, bb->vec, xvec, bb->offset[0]); VECADDFAC(center, center, yvec, bb->offset[1]); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index d66c990cbe1..075c6f6207f 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -54,7 +54,7 @@ #include "BLI_rand.h" #include "BLI_jitter.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_kdtree.h" #include "BLI_kdopbvh.h" @@ -405,7 +405,7 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys) min[2]-=d/2.0f; for(i=0,mv=mvert; i<totvert; i++,mv++){ - VecSubf(vec,mv->co,min); + sub_v3_v3v3(vec,mv->co,min); vec[0]/=delta[0]; vec[1]/=delta[1]; vec[2]/=delta[2]; @@ -447,7 +447,7 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys) VECCOPY(v2,mvert[mface->v2].co); VECCOPY(v3,mvert[mface->v3].co); - if(AxialLineIntersectsTriangle(a,co1, co2, v2, v3, v1, &lambda)){ + if(isect_axial_line_tri_v3(a,co1, co2, v2, v3, v1, &lambda)){ if(from==PART_FROM_FACE) (pa+(int)(lambda*size[a])*a0mul)->flag &= ~PARS_UNEXIST; else /* store number of intersections */ @@ -457,7 +457,7 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys) if(mface->v4){ VECCOPY(v4,mvert[mface->v4].co); - if(AxialLineIntersectsTriangle(a,co1, co2, v4, v1, v3, &lambda)){ + if(isect_axial_line_tri_v3(a,co1, co2, v4, v1, v3, &lambda)){ if(from==PART_FROM_FACE) (pa+(int)(lambda*size[a])*a0mul)->flag &= ~PARS_UNEXIST; else @@ -577,10 +577,10 @@ static void psys_uv_to_w(float u, float v, int quad, float *w) if(quad) { vert[3][0]= 0.0f; vert[3][1]= 1.0f; vert[3][2]= 0.0f; - MeanValueWeights(vert, 4, co, w); + interp_weights_poly_v3( w,vert, 4, co); } else { - MeanValueWeights(vert, 3, co, w); + interp_weights_poly_v3( w,vert, 3, co); w[3]= 0.0f; } } @@ -669,8 +669,8 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData psys_interpolate_face(mvert,mface,0,0,pa->fuv,co1,nor,0,0,0,0); - Normalize(nor); - VecMulf(nor,-100.0); + normalize_v3(nor); + mul_v3_fl(nor,-100.0); VECADD(co2,co1,nor); @@ -684,7 +684,7 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData v2=mvert[mface->v2].co; v3=mvert[mface->v3].co; - if(LineIntersectsTriangle(co1, co2, v2, v3, v1, &cur_d, 0)){ + if(isect_line_tri_v3(co1, co2, v2, v3, v1, &cur_d, 0)){ if(cur_d<min_d){ min_d=cur_d; pa->foffset=cur_d*50.0f; /* to the middle of volume */ @@ -694,7 +694,7 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData if(mface->v4){ v4=mvert[mface->v4].co; - if(LineIntersectsTriangle(co1, co2, v4, v1, v3, &cur_d, 0)){ + if(isect_line_tri_v3(co1, co2, v4, v1, v3, &cur_d, 0)){ if(cur_d<min_d){ min_d=cur_d; pa->foffset=cur_d*50.0f; /* to the middle of volume */ @@ -776,18 +776,18 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData // int min_seam=0, near_vert=0; // /* find closest seam */ // for(i=0; i<ctx->totseam; i++, seam++){ - // VecSubf(temp,co1,seam->v0); - // inp=Inpf(temp,seam->dir)/seam->length2; + // sub_v3_v3v3(temp,co1,seam->v0); + // inp=dot_v3v3(temp,seam->dir)/seam->length2; // if(inp<0.0f){ - // cur_len=VecLenf(co1,seam->v0); + // cur_len=len_v3v3(co1,seam->v0); // } // else if(inp>1.0f){ - // cur_len=VecLenf(co1,seam->v1); + // cur_len=len_v3v3(co1,seam->v1); // } // else{ - // VecCopyf(temp2,seam->dir); - // VecMulf(temp2,inp); - // cur_len=VecLenf(temp,temp2); + // copy_v3_v3(temp2,seam->dir); + // mul_v3_fl(temp2,inp); + // cur_len=len_v3v3(temp,temp2); // } // if(cur_len<min_len){ // min_len=cur_len; @@ -799,27 +799,27 @@ static void psys_thread_distribute_particle(ParticleThread *thread, ParticleData // } // seam=ctx->seams+min_seam; // - // VecCopyf(temp,seam->v0); + // copy_v3_v3(temp,seam->v0); // // if(near_vert){ // if(near_vert==-1) - // VecSubf(tan,co1,seam->v0); + // sub_v3_v3v3(tan,co1,seam->v0); // else{ - // VecSubf(tan,co1,seam->v1); - // VecCopyf(temp,seam->v1); + // sub_v3_v3v3(tan,co1,seam->v1); + // copy_v3_v3(temp,seam->v1); // } - // Normalize(tan); + // normalize_v3(tan); // } // else{ - // VecCopyf(tan,seam->tan); - // VecSubf(temp2,co1,temp); - // if(Inpf(tan,temp2)<0.0f) - // VecNegf(tan); + // copy_v3_v3(tan,seam->tan); + // sub_v3_v3v3(temp2,co1,temp); + // if(dot_v3v3(tan,temp2)<0.0f) + // negate_v3(tan); // } // for(w=0; w<maxw; w++){ - // VecSubf(temp2,ptn[w].co,temp); - // if(Inpf(tan,temp2)<0.0f){ + // sub_v3_v3v3(temp2,ptn[w].co,temp); + // if(dot_v3v3(tan,temp2)<0.0f){ // parent[w]=-1; // pweight[w]=0.0f; // } @@ -989,12 +989,12 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, // for(p=0, ed=medge; p<totedge; p++,ed++){ // if(ed->flag&ME_SEAM){ - // VecCopyf(cur_seam->v0,(mvert+ed->v1)->co); - // VecCopyf(cur_seam->v1,(mvert+ed->v2)->co); + // copy_v3_v3(cur_seam->v0,(mvert+ed->v1)->co); + // copy_v3_v3(cur_seam->v1,(mvert+ed->v2)->co); - // VecSubf(cur_seam->dir,cur_seam->v1,cur_seam->v0); + // sub_v3_v3v3(cur_seam->dir,cur_seam->v1,cur_seam->v0); - // cur_seam->length2=VecLength(cur_seam->dir); + // cur_seam->length2=len_v3(cur_seam->dir); // cur_seam->length2*=cur_seam->length2; // temp[0]=(float)((mvert+ed->v1)->no[0]); @@ -1004,12 +1004,12 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, // temp2[1]=(float)((mvert+ed->v2)->no[1]); // temp2[2]=(float)((mvert+ed->v2)->no[2]); - // VecAddf(cur_seam->nor,temp,temp2); - // Normalize(cur_seam->nor); + // add_v3_v3v3(cur_seam->nor,temp,temp2); + // normalize_v3(cur_seam->nor); - // Crossf(cur_seam->tan,cur_seam->dir,cur_seam->nor); + // cross_v3_v3v3(cur_seam->tan,cur_seam->dir,cur_seam->nor); - // Normalize(cur_seam->tan); + // normalize_v3(cur_seam->tan); // cur_seam++; // } @@ -1035,7 +1035,7 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, cpa->fuv[0]=2.0f*BLI_frand()-1.0f; cpa->fuv[1]=2.0f*BLI_frand()-1.0f; cpa->fuv[2]=2.0f*BLI_frand()-1.0f; - length=VecLength(cpa->fuv); + length=len_v3(cpa->fuv); } cpa->num=-1; @@ -1176,10 +1176,10 @@ static int psys_threads_init_distribution(ParticleThread *threads, Scene *scene, v4= (MVert*)dm->getVertData(dm,mf->v4,CD_MVERT); VECCOPY(co4, v4->co); } - cur= AreaQ3Dfl(co1, co2, co3, co4); + cur= area_quad_v3(co1, co2, co3, co4); } else - cur= AreaT3Dfl(co1, co2, co3); + cur= area_tri_v3(co1, co2, co3); if(cur>maxweight) maxweight=cur; @@ -1682,7 +1682,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, r_rot[1] = 2.0f * (PSYS_FRAND(p + 17) - 0.5f); r_rot[2] = 2.0f * (PSYS_FRAND(p + 18) - 0.5f); r_rot[3] = 2.0f * (PSYS_FRAND(p + 19) - 0.5f); - NormalQuat(r_rot); + normalize_qt(r_rot); r_phase = PSYS_FRAND(p + 20); @@ -1699,15 +1699,15 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, psys_get_particle_state(&tsim, pa->num, &state, 1); psys_get_from_key(&state, loc, nor, rot, 0); - QuatMulVecf(rot, vtan); - QuatMulVecf(rot, utan); + mul_qt_v3(rot, vtan); + mul_qt_v3(rot, utan); VECCOPY(p_vel, state.vel); - speed=Normalize(p_vel); - VecMulf(p_vel, Inpf(r_vel, p_vel)); + speed=normalize_v3(p_vel); + mul_v3_fl(p_vel, dot_v3v3(r_vel, p_vel)); VECSUB(p_vel, r_vel, p_vel); - Normalize(p_vel); - VecMulf(p_vel, speed); + normalize_v3(p_vel); + mul_v3_fl(p_vel, speed); VECCOPY(pa->fuv, loc); /* abusing pa->fuv (not used for "from particle") for storing emit location */ } @@ -1731,46 +1731,46 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* particles live in global space so */ /* let's convert: */ /* -location */ - Mat4MulVecfl(ob->obmat,loc); + mul_m4_v3(ob->obmat,loc); /* -normal */ - Mat4Mul3Vecfl(ob->obmat,nor); - Normalize(nor); + mul_mat3_m4_v3(ob->obmat,nor); + normalize_v3(nor); /* -tangent */ if(part->tanfac!=0.0){ //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f; float phase=0.0f; - VecMulf(vtan,-(float)cos(M_PI*(part->tanphase+phase))); + mul_v3_fl(vtan,-(float)cos(M_PI*(part->tanphase+phase))); fac=-(float)sin(M_PI*(part->tanphase+phase)); VECADDFAC(vtan,vtan,utan,fac); - Mat4Mul3Vecfl(ob->obmat,vtan); + mul_mat3_m4_v3(ob->obmat,vtan); VECCOPY(utan,nor); - VecMulf(utan,Inpf(vtan,nor)); + mul_v3_fl(utan,dot_v3v3(vtan,nor)); VECSUB(vtan,vtan,utan); - Normalize(vtan); + normalize_v3(vtan); } /* -velocity */ if(part->randfac!=0.0){ - Mat4Mul3Vecfl(ob->obmat,r_vel); - Normalize(r_vel); + mul_mat3_m4_v3(ob->obmat,r_vel); + normalize_v3(r_vel); } /* -angular velocity */ if(part->avemode==PART_AVE_RAND){ - Mat4Mul3Vecfl(ob->obmat,r_ave); - Normalize(r_ave); + mul_mat3_m4_v3(ob->obmat,r_ave); + normalize_v3(r_ave); } /* -rotation */ if(part->randrotfac != 0.0f){ - Mat4ToQuat(ob->obmat,rot); - QuatMul(r_rot,r_rot,rot); + mat4_to_quat(rot,ob->obmat); + mul_qt_qtqt(r_rot,r_rot,rot); } } @@ -1785,8 +1785,8 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* boids store direction in ave */ if(fabs(nor[2])==1.0f) { - VecSubf(pa->state.ave, loc, ob->obmat[3]); - Normalize(pa->state.ave); + sub_v3_v3v3(pa->state.ave, loc, ob->obmat[3]); + normalize_v3(pa->state.ave); } else { VECCOPY(pa->state.ave, nor); @@ -1799,17 +1799,17 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, bpa->gravity[2] = sim->scene->physics_settings.gravity[2]; /* calculate rotation matrix */ - Projf(dvec, r_vel, pa->state.ave); - VecSubf(mat[0], pa->state.ave, dvec); - Normalize(mat[0]); + project_v3_v3v3(dvec, r_vel, pa->state.ave); + sub_v3_v3v3(mat[0], pa->state.ave, dvec); + normalize_v3(mat[0]); VECCOPY(mat[2], r_vel); - VecMulf(mat[2], -1.0f); - Normalize(mat[2]); - Crossf(mat[1], mat[2], mat[0]); + mul_v3_fl(mat[2], -1.0f); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); /* apply rotation */ - Mat3ToQuat_is_ok(mat, q); - QuatCopy(pa->state.rot, q); + mat3_to_quat_is_ok( q,mat); + copy_qt_qt(pa->state.rot, q); bpa->data.health = part->boids->health; bpa->data.mode = eBoidMode_InAir; @@ -1828,7 +1828,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* *emitter velocity */ if(dtime!=0.0 && part->obfac!=0.0){ VECSUB(vel,loc,pa->state.co); - VecMulf(vel,part->obfac/dtime); + mul_v3_fl(vel,part->obfac/dtime); } /* *emitter normal */ @@ -1843,17 +1843,17 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* *emitter object orientation */ if(part->ob_vel[0]!=0.0) { VECCOPY(vec, ob->obmat[0]); - Normalize(vec); + normalize_v3(vec); VECADDFAC(vel, vel, vec, part->ob_vel[0]); } if(part->ob_vel[1]!=0.0) { VECCOPY(vec, ob->obmat[1]); - Normalize(vec); + normalize_v3(vec); VECADDFAC(vel, vel, vec, part->ob_vel[1]); } if(part->ob_vel[2]!=0.0) { VECCOPY(vec, ob->obmat[2]); - Normalize(vec); + normalize_v3(vec); VECADDFAC(vel, vel, vec, part->ob_vel[2]); } @@ -1874,7 +1874,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, // ptex.ivel*=icu->curval; //} - VecMulf(vel,ptex.ivel); + mul_v3_fl(vel,ptex.ivel); VECCOPY(pa->state.vel,vel); @@ -1889,10 +1889,10 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* create vector into which rotation is aligned */ switch(part->rotmode){ case PART_ROT_NOR: - VecCopyf(rot_vec, nor); + copy_v3_v3(rot_vec, nor); break; case PART_ROT_VEL: - VecCopyf(rot_vec, vel); + copy_v3_v3(rot_vec, vel); break; case PART_ROT_GLOB_X: case PART_ROT_GLOB_Y: @@ -1902,28 +1902,28 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, case PART_ROT_OB_X: case PART_ROT_OB_Y: case PART_ROT_OB_Z: - VecCopyf(rot_vec, ob->obmat[part->rotmode - PART_ROT_OB_X]); + copy_v3_v3(rot_vec, ob->obmat[part->rotmode - PART_ROT_OB_X]); break; } /* create rotation quat */ - VecNegf(rot_vec); - vectoquat(rot_vec, OB_POSX, OB_POSZ, q2); + negate_v3(rot_vec); + vec_to_quat( q2,rot_vec, OB_POSX, OB_POSZ); /* randomize rotation quat */ if(part->randrotfac!=0.0f) - QuatInterpol(rot, q2, r_rot, part->randrotfac); + interp_qt_qtqt(rot, q2, r_rot, part->randrotfac); else - QuatCopy(rot,q2); + copy_qt_qt(rot,q2); /* rotation phase */ phasefac = part->phasefac; if(part->randphasefac != 0.0f) phasefac += part->randphasefac * r_phase; - VecRotToQuat(x_vec, phasefac*(float)M_PI, q_phase); + axis_angle_to_quat( q_phase,x_vec, phasefac*(float)M_PI); /* combine base rotation & phase */ - QuatMul(pa->state.rot, rot, q_phase); + mul_qt_qtqt(pa->state.rot, rot, q_phase); } /* -angular velocity */ @@ -1939,13 +1939,13 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, VECCOPY(pa->state.ave,r_ave); break; } - Normalize(pa->state.ave); - VecMulf(pa->state.ave,part->avefac); + normalize_v3(pa->state.ave); + mul_v3_fl(pa->state.ave,part->avefac); //icu=find_ipocurve(psys->part->ipo,PART_EMIT_AVE); //if(icu){ // calc_icu(icu,100*((pa->time-part->sta)/(part->end-part->sta))); - // VecMulf(pa->state.ave,icu->curval); + // mul_v3_fl(pa->state.ave,icu->curval); //} } } @@ -2157,7 +2157,7 @@ static void set_keyed_keys(ParticleSimulationData *sim) // } // } // else{ -// dist=VecLenf(pa->state.co, re->state.co); +// dist=len_v3v3(pa->state.co, re->state.co); // if(dist <= re->size){ // if(pa->alive==PARS_UNBORN){ // pa->time=re->time; @@ -2168,12 +2168,12 @@ static void set_keyed_keys(ParticleSimulationData *sim) // float vec[3]; // VECSUB(vec,pa->state.co, re->state.co); // if(birth==0) -// VecMulf(vec,(float)pow(1.0f-dist/re->size,part->reactshape)); +// mul_v3_fl(vec,(float)pow(1.0f-dist/re->size,part->reactshape)); // VECADDFAC(pa->state.vel,pa->state.vel,vec,part->reactfac); // VECADDFAC(pa->state.vel,pa->state.vel,re->state.vel,part->partfac); // } // if(birth) -// VecMulf(pa->state.vel,(float)pow(1.0f-dist/re->size,part->reactshape)); +// mul_v3_fl(pa->state.vel,(float)pow(1.0f-dist/re->size,part->reactshape)); // } // } // } @@ -2301,7 +2301,7 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra /* calculate air-particle interaction */ if(part->dragfac!=0.0f){ - fac=-part->dragfac*pa->size*pa->size*VecLength(states[i].vel); + fac=-part->dragfac*pa->size*pa->size*len_v3(states[i].vel); VECADDFAC(force,force,states[i].vel,fac); } @@ -2313,7 +2313,7 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra } /* force to acceleration*/ - VecMulf(force,1.0f/pa_mass); + mul_v3_fl(force,1.0f/pa_mass); /* add global acceleration (gravitation) */ if(sim->scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY @@ -2321,7 +2321,7 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra && (part->type != PART_HAIR || part->effector_weights->flag & EFF_WEIGHT_DO_HAIR)) { float gravity[3]; VECCOPY(gravity, sim->scene->physics_settings.gravity); - VecMulf(gravity, part->effector_weights->global_gravity); + mul_v3_fl(gravity, part->effector_weights->global_gravity); VECADD(force,force,gravity); } @@ -2348,9 +2348,9 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra switch(i){ case 0: VECCOPY(dx[0],states->vel); - VecMulf(dx[0],dtime); + mul_v3_fl(dx[0],dtime); VECCOPY(dv[0],force); - VecMulf(dv[0],dtime); + mul_v3_fl(dv[0],dtime); VECADDFAC(states[1].co,states->co,dx[0],0.5f); VECADDFAC(states[1].vel,states->vel,dv[0],0.5f); @@ -2358,18 +2358,18 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra break; case 1: VECADDFAC(dx[1],states->vel,dv[0],0.5f); - VecMulf(dx[1],dtime); + mul_v3_fl(dx[1],dtime); VECCOPY(dv[1],force); - VecMulf(dv[1],dtime); + mul_v3_fl(dv[1],dtime); VECADDFAC(states[2].co,states->co,dx[1],0.5f); VECADDFAC(states[2].vel,states->vel,dv[1],0.5f); break; case 2: VECADDFAC(dx[2],states->vel,dv[1],0.5f); - VecMulf(dx[2],dtime); + mul_v3_fl(dx[2],dtime); VECCOPY(dv[2],force); - VecMulf(dv[2],dtime); + mul_v3_fl(dv[2],dtime); VECADD(states[3].co,states->co,dx[2]); VECADD(states[3].vel,states->vel,dv[2]); @@ -2377,9 +2377,9 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra break; case 3: VECADD(dx[3],states->vel,dv[2]); - VecMulf(dx[3],dtime); + mul_v3_fl(dx[3],dtime); VECCOPY(dv[3],force); - VecMulf(dv[3],dtime); + mul_v3_fl(dv[3],dtime); VECADDFAC(pa->state.co,states->co,dx[0],1.0f/6.0f); VECADDFAC(pa->state.co,pa->state.co,dx[1],1.0f/3.0f); @@ -2397,7 +2397,7 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra /* damp affects final velocity */ if(part->dampfac!=0.0) - VecMulf(pa->state.vel,1.0f-part->dampfac); + mul_v3_fl(pa->state.vel,1.0f-part->dampfac); VECCOPY(pa->state.ave, states->ave); @@ -2414,7 +2414,7 @@ static void apply_particle_forces(ParticleSimulationData *sim, int p, float dfra VECCOPY(pa->state.co,tkey.co); /* guides don't produce valid velocity */ VECSUB(pa->state.vel,tkey.co,pa->prev_state.co); - VecMulf(pa->state.vel,1.0f/dtime); + mul_v3_fl(pa->state.vel,1.0f/dtime); pa->state.time=tkey.time; } } @@ -2426,35 +2426,35 @@ static void rotate_particle(ParticleSettings *part, ParticleData *pa, float dfra if((part->flag & PART_ROT_DYN)==0){ if(part->avemode==PART_AVE_SPIN){ float angle; - float len1 = VecLength(pa->prev_state.vel); - float len2 = VecLength(pa->state.vel); + float len1 = len_v3(pa->prev_state.vel); + float len2 = len_v3(pa->state.vel); if(len1==0.0f || len2==0.0f) pa->state.ave[0]=pa->state.ave[1]=pa->state.ave[2]=0.0f; else{ - Crossf(pa->state.ave,pa->prev_state.vel,pa->state.vel); - Normalize(pa->state.ave); - angle=Inpf(pa->prev_state.vel,pa->state.vel)/(len1*len2); - VecMulf(pa->state.ave,saacos(angle)/dtime); + cross_v3_v3v3(pa->state.ave,pa->prev_state.vel,pa->state.vel); + normalize_v3(pa->state.ave); + angle=dot_v3v3(pa->prev_state.vel,pa->state.vel)/(len1*len2); + mul_v3_fl(pa->state.ave,saacos(angle)/dtime); } - VecRotToQuat(pa->state.vel,dtime*part->avefac,rot2); + axis_angle_to_quat(rot2,pa->state.vel,dtime*part->avefac); } } - rotfac=VecLength(pa->state.ave); - if(rotfac==0.0){ /* QuatOne (in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */ + rotfac=len_v3(pa->state.ave); + if(rotfac==0.0){ /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */ rot1[0]=1.0; rot1[1]=rot1[2]=rot1[3]=0; } else{ - VecRotToQuat(pa->state.ave,rotfac*dtime,rot1); + axis_angle_to_quat(rot1,pa->state.ave,rotfac*dtime); } - QuatMul(pa->state.rot,rot1,pa->prev_state.rot); - QuatMul(pa->state.rot,rot2,pa->state.rot); + mul_qt_qtqt(pa->state.rot,rot1,pa->prev_state.rot); + mul_qt_qtqt(pa->state.rot,rot2,pa->state.rot); /* keep rotation quat in good health */ - NormalQuat(pa->state.rot); + normalize_qt(pa->state.rot); } /* convert from triangle barycentric weights to quad mean value weights */ @@ -2471,7 +2471,7 @@ static void intersect_dm_quad_weights(float *v1, float *v2, float *v3, float *v4 co[1]= v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2] + v4[1]*w[3]; co[2]= v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2] + v4[2]*w[3]; - MeanValueWeights(vert, 4, co, w); + interp_weights_poly_v3( w,vert, 4, co); } /* check intersection with a derivedmesh */ @@ -2537,18 +2537,18 @@ int psys_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float *vert_cos DO_MINMAX(v3,min,max); if(mface->v4) DO_MINMAX(v4,min,max) - if(AabbIntersectAabb(min,max,p_min,p_max)==0) + if(isect_aabb_aabb_v3(min,max,p_min,p_max)==0) continue; } else{ VECCOPY(min, face_minmax+6*i); VECCOPY(max, face_minmax+6*i+3); - if(AabbIntersectAabb(min,max,p_min,p_max)==0) + if(isect_aabb_aabb_v3(min,max,p_min,p_max)==0) continue; } if(radius>0.0f){ - if(SweepingSphereIntersectsTriangleUV(co1, co2, radius, v2, v3, v1, &cur_d, cur_ipoint)){ + if(isect_sweeping_sphere_tri_v3(co1, co2, radius, v2, v3, v1, &cur_d, cur_ipoint)){ if(cur_d<*min_d){ *min_d=cur_d; VECCOPY(ipoint,cur_ipoint); @@ -2557,7 +2557,7 @@ int psys_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float *vert_cos } } if(mface->v4){ - if(SweepingSphereIntersectsTriangleUV(co1, co2, radius, v4, v1, v3, &cur_d, cur_ipoint)){ + if(isect_sweeping_sphere_tri_v3(co1, co2, radius, v4, v1, v3, &cur_d, cur_ipoint)){ if(cur_d<*min_d){ *min_d=cur_d; VECCOPY(ipoint,cur_ipoint); @@ -2568,7 +2568,7 @@ int psys_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float *vert_cos } } else{ - if(LineIntersectsTriangle(co1, co2, v1, v2, v3, &cur_d, cur_uv)){ + if(isect_line_tri_v3(co1, co2, v1, v2, v3, &cur_d, cur_uv)){ if(cur_d<*min_d){ *min_d=cur_d; min_w[0]= 1.0 - cur_uv[0] - cur_uv[1]; @@ -2582,7 +2582,7 @@ int psys_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm, float *vert_cos } } if(mface->v4){ - if(LineIntersectsTriangle(co1, co2, v1, v3, v4, &cur_d, cur_uv)){ + if(isect_line_tri_v3(co1, co2, v1, v3, v4, &cur_d, cur_uv)){ if(cur_d<*min_d){ *min_d=cur_d; min_w[0]= 1.0 - cur_uv[0] - cur_uv[1]; @@ -2618,7 +2618,7 @@ void particle_intersect_face(void *userdata, int index, const BVHTreeRay *ray, B VECCOPY(vel, v[ face->v1 ].co); VECADD(vel, vel, v[ face->v2 ].co); VECADD(vel, vel, v[ face->v3 ].co); - VecMulf(vel, 0.33334f); + mul_v3_fl(vel, 0.33334f); /* substract face velocity, in other words convert to a coordinate system where only the particle moves */ @@ -2628,16 +2628,16 @@ void particle_intersect_face(void *userdata, int index, const BVHTreeRay *ray, B do { if(ray->radius == 0.0f) { - if(LineIntersectsTriangle(co1, co2, t0, t1, t2, &t, uv)) { + if(isect_line_tri_v3(co1, co2, t0, t1, t2, &t, uv)) { if(t >= 0.0f && t < hit->dist/col->ray_len) { hit->dist = col->ray_len * t; hit->index = index; /* calculate normal that's facing the particle */ - CalcNormFloat(t0, t1, t2, col->nor); + normal_tri_v3( col->nor,t0, t1, t2); VECSUB(temp, co2, co1); - if(Inpf(col->nor, temp) > 0.0f) - VecNegf(col->nor); + if(dot_v3v3(col->nor, temp) > 0.0f) + negate_v3(col->nor); VECCOPY(col->vel,vel); @@ -2647,15 +2647,15 @@ void particle_intersect_face(void *userdata, int index, const BVHTreeRay *ray, B } } else { - if(SweepingSphereIntersectsTriangleUV(co1, co2, ray->radius, t0, t1, t2, &t, ipoint)) { + if(isect_sweeping_sphere_tri_v3(co1, co2, ray->radius, t0, t1, t2, &t, ipoint)) { if(t >=0.0f && t < hit->dist/col->ray_len) { hit->dist = col->ray_len * t; hit->index = index; - VecLerpf(temp, co1, co2, t); + interp_v3_v3v3(temp, co1, co2, t); VECSUB(col->nor, temp, ipoint); - Normalize(col->nor); + normalize_v3(col->nor); VECCOPY(col->vel,vel); @@ -2706,7 +2706,7 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo VECSUB(ray_dir, col.co2, col.co1); hit.index = -1; - hit.dist = col.ray_len = VecLength(ray_dir); + hit.dist = col.ray_len = len_v3(ray_dir); /* even if particle is stationary we want to check for moving colliders */ /* if hit.dist is zero the bvhtree_ray_cast will just ignore everything */ @@ -2738,10 +2738,10 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo float t = hit.dist/col.ray_len; /* time of collision between this iteration */ float dt = col.t + t * (1.0f - col.t); /* time of collision between frame change*/ - VecLerpf(co, col.co1, col.co2, t); + interp_v3_v3v3(co, col.co1, col.co2, t); VECSUB(vec, col.co2, col.co1); - VecMulf(col.vel, 1.0f-col.t); + mul_v3_fl(col.vel, 1.0f-col.t); /* particle dies in collision */ if(through == 0 && (part->flag & PART_DIE_ON_COL || pd->flag & PDEFLE_KILL_PART)) { @@ -2752,9 +2752,9 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo VECADDFAC(co, co, col.nor, (through ? -0.0001f : 0.0001f)); VECCOPY(pa->state.co, co); - VecLerpf(pa->state.vel, pa->prev_state.vel, pa->state.vel, dt); - QuatInterpol(pa->state.rot, pa->prev_state.rot, pa->state.rot, dt); - VecLerpf(pa->state.ave, pa->prev_state.ave, pa->state.ave, dt); + interp_v3_v3v3(pa->state.vel, pa->prev_state.vel, pa->state.vel, dt); + interp_qt_qtqt(pa->state.rot, pa->prev_state.rot, pa->state.rot, dt); + interp_v3_v3v3(pa->state.ave, pa->prev_state.ave, pa->state.ave, dt); /* particle is dead so we don't need to calculate further */ deflections=max_deflections; @@ -2772,13 +2772,13 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo CLAMP(frict,0.0,1.0); /* treat normal & tangent components separately */ - inp = Inpf(col.nor, vec); - inp_v = Inpf(col.nor, col.vel); + inp = dot_v3v3(col.nor, vec); + inp_v = dot_v3v3(col.nor, col.vel); VECADDFAC(tan_vec, vec, col.nor, -inp); VECADDFAC(tan_vel, col.vel, col.nor, -inp_v); if((part->flag & PART_ROT_DYN)==0) - VecLerpf(tan_vec, tan_vec, tan_vel, frict); + interp_v3_v3v3(tan_vec, tan_vec, tan_vel, frict); VECCOPY(nor_vec, col.nor); inp *= 1.0f - damp; @@ -2788,9 +2788,9 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo /* special case for object hitting the particle from behind */ if(through==0 && ((inp_v>0 && inp>0 && inp_v>inp) || (inp_v<0 && inp<0 && inp_v<inp))) - VecMulf(nor_vec, inp_v); + mul_v3_fl(nor_vec, inp_v); else - VecMulf(nor_vec, inp_v + (through ? 1.0f : -1.0f) * inp); + mul_v3_fl(nor_vec, inp_v + (through ? 1.0f : -1.0f) * inp); /* angular <-> linear velocity - slightly more physical and looks even nicer than before */ if(part->flag & PART_ROT_DYN) { @@ -2800,37 +2800,37 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo VECSUB(surface_vel, tan_vec, tan_vel); /* direction of rolling friction */ - Crossf(rot_vel, pa->state.ave, col.nor); + cross_v3_v3v3(rot_vel, pa->state.ave, col.nor); /* convert to current dt */ - VecMulf(rot_vel, (timestep*dfra) * (1.0f - col.t)); - VecMulf(rot_vel, pa->size); + mul_v3_fl(rot_vel, (timestep*dfra) * (1.0f - col.t)); + mul_v3_fl(rot_vel, pa->size); /* apply sliding friction */ VECSUB(surface_vel, surface_vel, rot_vel); VECCOPY(friction, surface_vel); - VecMulf(surface_vel, 1.0 - frict); - VecMulf(friction, frict); + mul_v3_fl(surface_vel, 1.0 - frict); + mul_v3_fl(friction, frict); /* sliding changes angular velocity */ - Crossf(dave, col.nor, friction); - VecMulf(dave, 1.0f/MAX2(pa->size, 0.001)); + cross_v3_v3v3(dave, col.nor, friction); + mul_v3_fl(dave, 1.0f/MAX2(pa->size, 0.001)); /* we assume rolling friction is around 0.01 of sliding friction */ - VecMulf(rot_vel, 1.0 - frict*0.01); + mul_v3_fl(rot_vel, 1.0 - frict*0.01); /* change in angular velocity has to be added to the linear velocity too */ - Crossf(dvel, dave, col.nor); - VecMulf(dvel, pa->size); + cross_v3_v3v3(dvel, dave, col.nor); + mul_v3_fl(dvel, pa->size); VECADD(rot_vel, rot_vel, dvel); VECADD(surface_vel, surface_vel, rot_vel); VECADD(tan_vec, surface_vel, tan_vel); /* convert back to normal time */ - VecMulf(dave, 1.0f/MAX2((timestep*dfra) * (1.0f - col.t), 0.00001)); + mul_v3_fl(dave, 1.0f/MAX2((timestep*dfra) * (1.0f - col.t), 0.00001)); - VecMulf(pa->state.ave, 1.0 - frict*0.01); + mul_v3_fl(pa->state.ave, 1.0 - frict*0.01); VECADD(pa->state.ave, pa->state.ave, dave); } @@ -2839,7 +2839,7 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo /* calculate velocity from collision vector */ VECCOPY(vel, vec); - VecMulf(vel, 1.0f/MAX2((timestep*dfra) * (1.0f - col.t), 0.00001)); + mul_v3_fl(vel, 1.0f/MAX2((timestep*dfra) * (1.0f - col.t), 0.00001)); /* make sure we don't hit the current face again */ VECADDFAC(co, co, col.nor, (through ? -0.0001f : 0.0001f)); @@ -2854,15 +2854,15 @@ static void deflect_particle(ParticleSimulationData *sim, int p, float dfra, flo /* store state for reactors */ //VECCOPY(reaction_state.co, co); - //VecLerpf(reaction_state.vel, pa->prev_state.vel, pa->state.vel, dt); - //QuatInterpol(reaction_state.rot, pa->prev_state.rot, pa->state.rot, dt); + //interp_v3_v3v3(reaction_state.vel, pa->prev_state.vel, pa->state.vel, dt); + //interp_qt_qtqt(reaction_state.rot, pa->prev_state.rot, pa->state.rot, dt); /* set coordinates for next iteration */ VECCOPY(col.co1, co); VECADDFAC(col.co2, co, vec, 1.0f - t); col.t = dt; - if(VecLength(vec) < 0.001 && VecLength(pa->state.vel) < 0.001) { + if(len_v3(vec) < 0.001 && len_v3(pa->state.vel) < 0.001) { /* kill speed to stop slipping */ VECCOPY(pa->state.vel,zerovec); VECCOPY(pa->state.co, co); @@ -3011,7 +3011,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) VECSUB(temp, key->co, (key+1)->co); VECCOPY(mvert->co, key->co); VECADD(mvert->co, mvert->co, temp); - Mat4MulVecfl(hairmat, mvert->co); + mul_m4_v3(hairmat, mvert->co); mvert++; medge->v1 = pa->hair_index - 1; @@ -3030,7 +3030,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) } VECCOPY(mvert->co, key->co); - Mat4MulVecfl(hairmat, mvert->co); + mul_m4_v3(hairmat, mvert->co); mvert++; if(k) { @@ -3105,7 +3105,7 @@ static void save_hair(ParticleSimulationData *sim, float cfra){ PARTICLE_P; int totpart; - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); psys->lattice= psys_get_lattice(sim); @@ -3125,8 +3125,8 @@ static void save_hair(ParticleSimulationData *sim, float cfra){ key += pa->totkey; /* convert from global to geometry space */ - VecCopyf(key->co, pa->state.co); - Mat4MulVecfl(ob->imat, key->co); + copy_v3_v3(key->co, pa->state.co); + mul_m4_v3(ob->imat, key->co); if(pa->totkey) { VECSUB(key->co, key->co, root->co); @@ -3941,6 +3941,6 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) system_step(&sim, cfra); /* save matrix for duplicators */ - Mat4Invert(psys->imat, ob->obmat); + invert_m4_m4(psys->imat, ob->obmat); } diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 68f0e33a98f..c2798b4a746 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -170,12 +170,12 @@ static void ptcache_interpolate_softbody(int index, void *soft_v, void **data, f dfra = cfra2 - cfra1; - VecMulf(keys[1].vel, dfra); - VecMulf(keys[2].vel, dfra); + mul_v3_fl(keys[1].vel, dfra); + mul_v3_fl(keys[2].vel, dfra); psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, keys, 1); - VecMulf(keys->vel, 1.0f / dfra); + mul_v3_fl(keys->vel, 1.0f / dfra); VECCOPY(bp->pos, keys->co); VECCOPY(bp->vec, keys->vel); @@ -255,18 +255,18 @@ static void ptcache_read_particle(int index, void *psys_v, void **data, float fr /* determine velocity from previous location */ if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_VELOCITY]) { if(cfra > pa->prev_state.time) { - VecSubf(pa->state.vel, pa->state.co, pa->prev_state.co); - VecMulf(pa->state.vel, (cfra - pa->prev_state.time) / frs_sec); + sub_v3_v3v3(pa->state.vel, pa->state.co, pa->prev_state.co); + mul_v3_fl(pa->state.vel, (cfra - pa->prev_state.time) / frs_sec); } else { - VecSubf(pa->state.vel, pa->prev_state.co, pa->state.co); - VecMulf(pa->state.vel, (pa->prev_state.time - cfra) / frs_sec); + sub_v3_v3v3(pa->state.vel, pa->prev_state.co, pa->state.co); + mul_v3_fl(pa->state.vel, (pa->prev_state.time - cfra) / frs_sec); } } /* determine rotation from velocity */ if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_ROTATION]) { - vectoquat(pa->state.vel, OB_NEGX, OB_POSZ, pa->state.rot); + vec_to_quat( pa->state.rot,pa->state.vel, OB_NEGX, OB_POSZ); } } static void ptcache_interpolate_particle(int index, void *psys_v, void **data, float frs_sec, float cfra, float cfra1, float cfra2, float *old_data) @@ -292,18 +292,18 @@ static void ptcache_interpolate_particle(int index, void *psys_v, void **data, f /* determine velocity from previous location */ if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_VELOCITY]) { if(keys[1].time > keys[2].time) { - VecSubf(keys[2].vel, keys[1].co, keys[2].co); - VecMulf(keys[2].vel, (keys[1].time - keys[2].time) / frs_sec); + sub_v3_v3v3(keys[2].vel, keys[1].co, keys[2].co); + mul_v3_fl(keys[2].vel, (keys[1].time - keys[2].time) / frs_sec); } else { - VecSubf(keys[2].vel, keys[2].co, keys[1].co); - VecMulf(keys[2].vel, (keys[2].time - keys[1].time) / frs_sec); + sub_v3_v3v3(keys[2].vel, keys[2].co, keys[1].co); + mul_v3_fl(keys[2].vel, (keys[2].time - keys[1].time) / frs_sec); } } /* determine rotation from velocity */ if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_ROTATION]) { - vectoquat(keys[2].vel, OB_NEGX, OB_POSZ, keys[2].rot); + vec_to_quat( keys[2].rot,keys[2].vel, OB_NEGX, OB_POSZ); } if(cfra > pa->time) @@ -311,13 +311,13 @@ static void ptcache_interpolate_particle(int index, void *psys_v, void **data, f dfra = cfra2 - cfra1; - VecMulf(keys[1].vel, dfra / frs_sec); - VecMulf(keys[2].vel, dfra / frs_sec); + mul_v3_fl(keys[1].vel, dfra / frs_sec); + mul_v3_fl(keys[2].vel, dfra / frs_sec); psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, &pa->state, 1); - QuatInterpol(pa->state.rot, keys[1].rot, keys[2].rot, (cfra - cfra1) / dfra); + interp_qt_qtqt(pa->state.rot, keys[1].rot, keys[2].rot, (cfra - cfra1) / dfra); - VecMulf(pa->state.vel, frs_sec / dfra); + mul_v3_fl(pa->state.vel, frs_sec / dfra); pa->state.time = cfra; } @@ -425,18 +425,18 @@ static int ptcache_totwrite_particle(void *psys_v) // /* determine velocity from previous location */ // if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_VELOCITY]) { // if(cfra > pa->prev_state.time) { -// VecSubf(pa->state.vel, pa->state.co, pa->prev_state.co); -// VecMulf(pa->state.vel, (cfra - pa->prev_state.time) / frs_sec); +// sub_v3_v3v3(pa->state.vel, pa->state.co, pa->prev_state.co); +// mul_v3_fl(pa->state.vel, (cfra - pa->prev_state.time) / frs_sec); // } // else { -// VecSubf(pa->state.vel, pa->prev_state.co, pa->state.co); -// VecMulf(pa->state.vel, (pa->prev_state.time - cfra) / frs_sec); +// sub_v3_v3v3(pa->state.vel, pa->prev_state.co, pa->state.co); +// mul_v3_fl(pa->state.vel, (pa->prev_state.time - cfra) / frs_sec); // } // } // // /* determine rotation from velocity */ // if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_ROTATION]) { -// vectoquat(pa->state.vel, OB_POSX, OB_POSZ, pa->state.rot); +// vec_to_quat( pa->state.rot,pa->state.vel, OB_POSX, OB_POSZ); // } //} //static void ptcache_interpolate_particle_stream(int index, void *psys_v, void **data, float frs_sec, float cfra, float cfra1, float cfra2, float *old_data) @@ -461,13 +461,13 @@ static int ptcache_totwrite_particle(void *psys_v) // // dfra = cfra2 - cfra1; // -// VecMulf(keys[1].vel, dfra / frs_sec); -// VecMulf(keys[2].vel, dfra / frs_sec); +// mul_v3_fl(keys[1].vel, dfra / frs_sec); +// mul_v3_fl(keys[2].vel, dfra / frs_sec); // // psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, &pa->state, 1); -// QuatInterpol(pa->state.rot, keys[1].rot,keys[2].rot, (cfra - cfra1) / dfra); +// interp_qt_qtqt(pa->state.rot, keys[1].rot,keys[2].rot, (cfra - cfra1) / dfra); // -// VecMulf(pa->state.vel, frs_sec / dfra); +// mul_v3_fl(pa->state.vel, frs_sec / dfra); // // pa->state.time = cfra; //} @@ -525,12 +525,12 @@ static void ptcache_interpolate_cloth(int index, void *cloth_v, void **data, flo dfra = cfra2 - cfra1; - VecMulf(keys[1].vel, dfra); - VecMulf(keys[2].vel, dfra); + mul_v3_fl(keys[1].vel, dfra); + mul_v3_fl(keys[2].vel, dfra); psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, keys, 1); - VecMulf(keys->vel, 1.0f / dfra); + mul_v3_fl(keys->vel, 1.0f / dfra); VECCOPY(vert->x, keys->co); VECCOPY(vert->v, keys->vel); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 4f72ca96f5f..91fd0bac400 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -89,7 +89,7 @@ #include "BPY_extern.h" #endif -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" //XXX #include "nla.h" @@ -323,6 +323,7 @@ Scene *add_scene(char *name) sce->r.cfra= 1; sce->r.sfra= 1; sce->r.efra= 250; + sce->r.frame_step= 1; sce->r.xsch= 1920; sce->r.ysch= 1080; sce->r.xasp= 1; @@ -653,7 +654,7 @@ int next_object(Scene *scene, int val, Base **base, Object **ob) /* handle dupli's */ if(dupob) { - Mat4CpyMat4(dupob->ob->obmat, dupob->mat); + copy_m4_m4(dupob->ob->obmat, dupob->mat); (*base)->flag |= OB_FROMDUPLI; *ob= dupob->ob; @@ -666,7 +667,7 @@ int next_object(Scene *scene, int val, Base **base, Object **ob) (*base)->flag &= ~OB_FROMDUPLI; for(dupob= duplilist->first; dupob; dupob= dupob->next) { - Mat4CpyMat4(dupob->ob->obmat, dupob->omat); + copy_m4_m4(dupob->ob->obmat, dupob->omat); } free_object_duplilist(duplilist); diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 078258092f7..a175ddf975a 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -38,7 +38,7 @@ #include "DNA_sequence_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_global.h" #include "BKE_plugin_types.h" diff --git a/source/blender/blenkernel/intern/sequence.c b/source/blender/blenkernel/intern/sequence.c index 1ab085f5fa8..a986e9d7a94 100644 --- a/source/blender/blenkernel/intern/sequence.c +++ b/source/blender/blenkernel/intern/sequence.c @@ -63,8 +63,8 @@ /* **** XXX ******** */ static int seqrectx= 0; /* bad bad global! */ static int seqrecty= 0; -static void waitcursor(int val) {} -static int blender_test_break() {return 0;} +//static void waitcursor(int val) {} +//static int blender_test_break() {return 0;} /* **** XXX ******** */ @@ -1230,6 +1230,7 @@ static struct ImBuf * seq_proxy_fetch(Scene *scene, Sequence * seq, int cfra, in } } +#if 0 static void do_build_seq_ibuf(Scene *scene, Sequence * seq, TStripElem *se, int cfra, int build_proxy_run, int render_size); @@ -1360,6 +1361,7 @@ static void seq_proxy_rebuild(Scene *scene, Sequence * seq) } waitcursor(0); } +#endif /* ********************************************************************** @@ -2631,6 +2633,7 @@ ImBuf *give_ibuf_seq(Scene *scene, int rectx, int recty, int cfra, int chanshown return i; } +#if 0 /* check used when we need to change seq->blend_mode but not to effect or audio strips */ static int seq_can_blend(Sequence *seq) { @@ -2640,6 +2643,7 @@ static int seq_can_blend(Sequence *seq) return 0; } } +#endif /* *********************** threading api ******************* */ @@ -2651,8 +2655,8 @@ static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t wakeup_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t wakeup_cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t prefetch_ready_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t prefetch_ready_cond = PTHREAD_COND_INITIALIZER; +//static pthread_mutex_t prefetch_ready_lock = PTHREAD_MUTEX_INITIALIZER; +//static pthread_cond_t prefetch_ready_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t frame_done_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t frame_done_cond = PTHREAD_COND_INITIALIZER; @@ -2685,6 +2689,7 @@ typedef struct PrefetchQueueElem { struct ImBuf * ibuf; } PrefetchQueueElem; +#if 0 static void *seq_prefetch_thread(void * This_) { PrefetchThread * This = This_; @@ -2833,6 +2838,7 @@ static void seq_stop_threads() /* deinit malloc mutex */ BLI_end_threads(0); } +#endif void give_ibuf_prefetch_request(int rectx, int recty, int cfra, int chanshown, int render_size) @@ -2859,6 +2865,7 @@ void give_ibuf_prefetch_request(int rectx, int recty, int cfra, int chanshown, pthread_mutex_unlock(&wakeup_lock); } +#if 0 static void seq_wait_for_prefetch_ready() { PrefetchThread *tslot; @@ -2887,6 +2894,7 @@ static void seq_wait_for_prefetch_ready() fprintf(stderr, "SEQ-THREAD: prefetch done\n"); } +#endif ImBuf *give_ibuf_seq_threaded(Scene *scene, int rectx, int recty, int cfra, int chanshown, int render_size) { @@ -2993,6 +3001,7 @@ static void free_anim_seq(Sequence *seq) } } +#if 0 static void free_imbuf_seq_except(Scene *scene, int cfra) { Editing *ed= seq_give_editing(scene, FALSE); @@ -3042,6 +3051,7 @@ static void free_imbuf_seq_except(Scene *scene, int cfra) } SEQ_END } +#endif void free_imbuf_seq(ListBase * seqbase, int check_mem_usage) { @@ -3187,6 +3197,7 @@ void free_imbuf_seq() } #endif +#if 0 // XXX old animation system static void free_imbuf_seq_with_ipo(Scene *scene, struct Ipo *ipo) { /* force update of all sequences with this ipo, on ipo changes */ @@ -3206,6 +3217,7 @@ static void free_imbuf_seq_with_ipo(Scene *scene, struct Ipo *ipo) } SEQ_END } +#endif /* seq funcs's for transforming internally notice the difference between start/end and left/right. diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index efb7db04029..c9bf29ed29c 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -51,7 +51,7 @@ #include "BKE_mesh.h" #include "BKE_subsurf.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_kdtree.h" #include "BLI_kdopbvh.h" #include "BLI_editVert.h" @@ -116,31 +116,31 @@ DerivedMesh *object_get_derived_final(struct Scene *scene, Object *ob, CustomDat void space_transform_from_matrixs(SpaceTransform *data, float local[4][4], float target[4][4]) { float itarget[4][4]; - Mat4Invert(itarget, target); - Mat4MulSerie(data->local2target, itarget, local, 0, 0, 0, 0, 0, 0); - Mat4Invert(data->target2local, data->local2target); + invert_m4_m4(itarget, target); + mul_serie_m4(data->local2target, itarget, local, 0, 0, 0, 0, 0, 0); + invert_m4_m4(data->target2local, data->local2target); } void space_transform_apply(const SpaceTransform *data, float *co) { - VecMat4MulVecfl(co, ((SpaceTransform*)data)->local2target, co); + mul_v3_m4v3(co, ((SpaceTransform*)data)->local2target, co); } void space_transform_invert(const SpaceTransform *data, float *co) { - VecMat4MulVecfl(co, ((SpaceTransform*)data)->target2local, co); + mul_v3_m4v3(co, ((SpaceTransform*)data)->target2local, co); } static void space_transform_apply_normal(const SpaceTransform *data, float *no) { - Mat4Mul3Vecfl( ((SpaceTransform*)data)->local2target, no); - Normalize(no); // TODO: could we just determine de scale value from the matrix? + mul_mat3_m4_v3( ((SpaceTransform*)data)->local2target, no); + normalize_v3(no); // TODO: could we just determine de scale value from the matrix? } static void space_transform_invert_normal(const SpaceTransform *data, float *no) { - Mat4Mul3Vecfl(((SpaceTransform*)data)->target2local, no); - Normalize(no); // TODO: could we just determine de scale value from the matrix? + mul_mat3_m4_v3(((SpaceTransform*)data)->target2local, no); + normalize_v3(no); // TODO: could we just determine de scale value from the matrix? } /* @@ -223,7 +223,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) VECCOPY(tmp_co, nearest.co); space_transform_invert(&calc->local2target, tmp_co); - VecLerpf(co, co, tmp_co, weight); //linear interpolation + interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation } } @@ -258,7 +258,7 @@ int normal_projection_project_vertex(char options, const float *vert, const floa space_transform_apply_normal( transf, tmp_no ); no = tmp_no; - hit_tmp.dist *= Mat4ToScalef( ((SpaceTransform*)transf)->local2target ); + hit_tmp.dist *= mat4_to_scale( ((SpaceTransform*)transf)->local2target ); } else { @@ -285,7 +285,7 @@ int normal_projection_project_vertex(char options, const float *vert, const floa space_transform_invert( transf, hit_tmp.co ); space_transform_invert_normal( transf, hit_tmp.no ); - hit_tmp.dist = VecLenf( (float*)vert, hit_tmp.co ); + hit_tmp.dist = len_v3v3( (float*)vert, hit_tmp.co ); } memcpy(hit, &hit_tmp, sizeof(hit_tmp) ); @@ -331,7 +331,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, struct S if(calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) proj_axis[1] = 1.0f; if(calc->smd->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS) proj_axis[2] = 1.0f; - Normalize(proj_axis); + normalize_v3(proj_axis); //Invalid projection direction if(INPR(proj_axis, proj_axis) < FLT_EPSILON) @@ -364,7 +364,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, struct S { VECCOPY(tmp_co, calc->vert[i].co); if(calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) - NormalShortToFloat(tmp_no, calc->vert[i].no); + normal_short_to_float_v3(tmp_no, calc->vert[i].no); else VECCOPY(tmp_no, proj_axis); } @@ -403,7 +403,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, struct S if(hit.index != -1) { - VecLerpf(co, co, hit.co, weight); + interp_v3_v3v3(co, co, hit.co, weight); } } } @@ -486,14 +486,14 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) //Adjusting the vertex weight, so that after interpolating it keeps a certain distance from the nearest position float dist = sasqrt( nearest.dist ); if(dist > FLT_EPSILON) - VecLerpf(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist)/dist); //linear interpolation + interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist)/dist); //linear interpolation else VECCOPY( tmp_co, nearest.co ); } //Convert the coordinates back to mesh coordinates space_transform_invert(&calc->local2target, tmp_co); - VecLerpf(co, co, tmp_co, weight); //linear interpolation + interp_v3_v3v3(co, co, tmp_co, weight); //linear interpolation } } diff --git a/source/blender/blenkernel/intern/simple_deform.c b/source/blender/blenkernel/intern/simple_deform.c index 2978a6f7f01..b2920615f5a 100644 --- a/source/blender/blenkernel/intern/simple_deform.c +++ b/source/blender/blenkernel/intern/simple_deform.c @@ -35,7 +35,7 @@ #include "BKE_lattice.h" #include "BKE_deform.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_shrinkwrap.h" #include <string.h> @@ -171,8 +171,8 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s } else { - Mat4CpyMat4(transf->local2target, smd->origin->obmat); - Mat4Invert(transf->target2local, transf->local2target); + copy_m4_m4(transf->local2target, smd->origin->obmat); + invert_m4_m4(transf->target2local, transf->local2target); } } @@ -246,7 +246,7 @@ void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, s axis_limit(limit_axis, smd_limit, co, dcut); simpleDeform_callback(smd_factor, dcut, co); //Apply deform - VecLerpf(vertexCos[i], vertexCos[i], co, weight); //Use vertex weight has coef of linear interpolation + interp_v3_v3v3(vertexCos[i], vertexCos[i], co, weight); //Use vertex weight has coef of linear interpolation if(transf) space_transform_invert(transf, vertexCos[i]); } diff --git a/source/blender/blenkernel/intern/sketch.c b/source/blender/blenkernel/intern/sketch.c index 8deae7e8e10..a41c7747b1a 100644 --- a/source/blender/blenkernel/intern/sketch.c +++ b/source/blender/blenkernel/intern/sketch.c @@ -30,7 +30,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_sketch.h" #include "BKE_utildefines.h" @@ -73,7 +73,7 @@ void sk_initPoint(SK_Point *pt, SK_DrawData *dd, float *no) if (no) { VECCOPY(pt->no, no); - Normalize(pt->no); + normalize_v3(pt->no); } else { @@ -235,7 +235,7 @@ void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], f total = end - start; - VecSubf(delta_p, p_end, p_start); + sub_v3_v3v3(delta_p, p_end, p_start); prev = stk->points + start; next = stk->points + end; @@ -259,8 +259,8 @@ void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], f float *p = stk->points[start + 1 + i].p; VECCOPY(p, delta_p); - VecMulf(p, delta); - VecAddf(p, p, p_start); + mul_v3_fl(p, delta); + add_v3_v3v3(p, p, p_start); } } @@ -320,9 +320,9 @@ void sk_flattenStroke(SK_Stroke *stk, int start, int end) VECCOPY(normal, stk->points[start].no); - VecSubf(distance, stk->points[end].p, stk->points[start].p); - Projf(normal, distance, normal); - limit = Normalize(normal); + sub_v3_v3v3(distance, stk->points[end].p, stk->points[start].p); + project_v3_v3v3(normal, distance, normal); + limit = normalize_v3(normal); for (i = 1; i < total - 1; i++) { @@ -330,14 +330,14 @@ void sk_flattenStroke(SK_Stroke *stk, int start, int end) float offset[3]; float *p = stk->points[start + i].p; - VecSubf(distance, p, stk->points[start].p); - Projf(distance, distance, normal); + sub_v3_v3v3(distance, p, stk->points[start].p); + project_v3_v3v3(distance, distance, normal); VECCOPY(offset, normal); - VecMulf(offset, d); + mul_v3_fl(offset, d); - VecSubf(p, p, distance); - VecAddf(p, p, offset); + sub_v3_v3v3(p, p, distance); + add_v3_v3v3(p, p, offset); } } diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index b7fe0bdfc98..0a106b1920d 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -44,7 +44,7 @@ #include "BLI_rand.h" #include "BLI_jitter.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_edgehash.h" #include "BLI_kdtree.h" #include "BLI_kdopbvh.h" @@ -150,7 +150,7 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive float tmp[3]; VECCOPY(tmp, verts[i].co); - Mat4MulVecfl(ob->obmat, tmp); + mul_m4_v3(ob->obmat, tmp); // min BB min[0] = MIN2(min[0], tmp[0]); @@ -262,8 +262,8 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive // bvhtree_from_mesh_faces(smd->flow->bvh, dm, 0.0, 2, 6); // copy obmat - // Mat4CpyMat4(smd->flow->mat, ob->obmat); - // Mat4CpyMat4(smd->flow->mat_old, ob->obmat); + // copy_m4_m4(smd->flow->mat, ob->obmat); + // copy_m4_m4(smd->flow->mat_old, ob->obmat); } */ @@ -283,8 +283,8 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive SmokeCollSettings *scs = smd->coll; // copy obmat - Mat4CpyMat4(scs->mat, ob->obmat); - Mat4CpyMat4(scs->mat_old, ob->obmat); + copy_m4_m4(scs->mat, ob->obmat); + copy_m4_m4(scs->mat_old, ob->obmat); fill_scs_points(ob, dm, scs); } @@ -332,7 +332,7 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) { float tmpvec[3]; VECCOPY(tmpvec, mvert[i].co); - Mat4MulVecfl (ob->obmat, tmpvec); + mul_m4_v3(ob->obmat, tmpvec); VECCOPY(&scs->points[i * 3], tmpvec); } @@ -358,10 +358,10 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) VECSUB(side2, mvert[ mface[i].v3 ].co, mvert[ mface[i].v1 ].co); } - Crossf(trinormorg, side1, side2); - Normalize(trinormorg); + cross_v3_v3v3(trinormorg, side1, side2); + normalize_v3(trinormorg); VECCOPY(trinorm, trinormorg); - VecMulf(trinorm, 0.25 * cell_len); + mul_v3_fl(trinorm, 0.25 * cell_len); for(j = 0; j <= divs1; j++) { @@ -390,9 +390,9 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) VECCOPY(p3, mvert[ mface[i].v3 ].co); } - VecMulf(p1, (1.0-uf-vf)); - VecMulf(p2, uf); - VecMulf(p3, vf); + mul_v3_fl(p1, (1.0-uf-vf)); + mul_v3_fl(p2, uf); + mul_v3_fl(p3, vf); VECADD(p, p1, p2); VECADD(p, p, p3); @@ -403,7 +403,7 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) // mMovPoints.push_back(p + trinorm); VECCOPY(tmpvec, p); VECADD(tmpvec, tmpvec, trinorm); - Mat4MulVecfl (ob->obmat, tmpvec); + mul_m4_v3(ob->obmat, tmpvec); VECCOPY(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); newdivs++; @@ -413,7 +413,7 @@ static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs) // mMovPoints.push_back(p - trinorm); VECCOPY(tmpvec, p); VECSUB(tmpvec, tmpvec, trinorm); - Mat4MulVecfl (ob->obmat, tmpvec); + mul_m4_v3(ob->obmat, tmpvec); VECCOPY(&scs->points[3 * (dm->getNumVerts(dm) + newdivs)], tmpvec); newdivs++; } @@ -466,11 +466,11 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int int divs1=0, divs2=0, divs3=0; VECCOPY(p0, verts[faces[i].v1].co); - Mat4MulVecfl (ob->obmat, p0); + mul_m4_v3(ob->obmat, p0); VECCOPY(p1, verts[faces[i].v2].co); - Mat4MulVecfl (ob->obmat, p1); + mul_m4_v3(ob->obmat, p1); VECCOPY(p2, verts[faces[i].v3].co); - Mat4MulVecfl (ob->obmat, p2); + mul_m4_v3(ob->obmat, p2); VECSUB(side1, p1, p0); VECSUB(side2, p2, p0); @@ -478,12 +478,12 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int if(INPR(side1, side1) > fsTri*fsTri) { - float tmp = Normalize(side1); + float tmp = normalize_v3(side1); divs1 = (int)ceil(tmp/fsTri); } if(INPR(side2, side2) > fsTri*fsTri) { - float tmp = Normalize(side2); + float tmp = normalize_v3(side2); divs2 = (int)ceil(tmp/fsTri); /* @@ -505,11 +505,11 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int facecounter++; VECCOPY(p0, verts[faces[i].v3].co); - Mat4MulVecfl (ob->obmat, p0); + mul_m4_v3(ob->obmat, p0); VECCOPY(p1, verts[faces[i].v4].co); - Mat4MulVecfl (ob->obmat, p1); + mul_m4_v3(ob->obmat, p1); VECCOPY(p2, verts[faces[i].v1].co); - Mat4MulVecfl (ob->obmat, p2); + mul_m4_v3(ob->obmat, p2); VECSUB(side1, p1, p0); VECSUB(side2, p2, p0); @@ -517,12 +517,12 @@ void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *faces, int if(INPR(side1, side1) > fsTri*fsTri) { - float tmp = Normalize(side1); + float tmp = normalize_v3(side1); divs1 = (int)ceil(tmp/fsTri); } if(INPR(side2, side2) > fsTri*fsTri) { - float tmp = Normalize(side2); + float tmp = normalize_v3(side2); divs2 = (int)ceil(tmp/fsTri); } @@ -849,7 +849,7 @@ static void smoke_calc_domain(Scene *scene, Object *ob, SmokeModifierData *smd) else if(pa->alive == PARS_DEAD && (part->flag & PART_DIED)==0) continue; else if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue; // VECCOPY(pos, pa->state.co); - // Mat4MulVecfl (ob->imat, pos); + // mul_m4_v3(ob->imat, pos); // 1. get corresponding cell get_cell(smd->domain->p0, smd->domain->res, smd->domain->dx, pa->state.co, cell, 0); // check if cell is valid (in the domain boundary) @@ -1105,8 +1105,8 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM // rigid movement support /* - Mat4CpyMat4(smd->flow->mat_old, smd->flow->mat); - Mat4CpyMat4(smd->flow->mat, ob->obmat); + copy_m4_m4(smd->flow->mat_old, smd->flow->mat); + copy_m4_m4(smd->flow->mat, ob->obmat); */ } else if(scene->r.cfra < smd->time) @@ -1131,8 +1131,8 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM smd->coll->dm = CDDM_copy(dm); // rigid movement support - Mat4CpyMat4(smd->coll->mat_old, smd->coll->mat); - Mat4CpyMat4(smd->coll->mat, ob->obmat); + copy_m4_m4(smd->coll->mat_old, smd->coll->mat); + copy_m4_m4(smd->coll->mat, ob->obmat); } else if(scene->r.cfra < smd->time) { @@ -1378,7 +1378,7 @@ static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int float tmp[3]; VECSUB(tmp, pos, p0); - VecMulf(tmp, 1.0 / dx); + mul_v3_fl(tmp, 1.0 / dx); if(correct) { diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 6e986325f55..34071b0034c 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -66,7 +66,7 @@ variables on the UI for now #include "DNA_scene_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_ghash.h" #include "BLI_threads.h" @@ -265,7 +265,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob, DerivedMesh *dm) /* ah yeah, put the verices to global coords once */ /* and determine the ortho BB on the fly */ for(i=0; i < pccd_M->totvert; i++){ - Mat4MulVecfl(ob->obmat, pccd_M->mvert[i].co); + mul_m4_v3(ob->obmat, pccd_M->mvert[i].co); /* evaluate limits */ VECCOPY(v,pccd_M->mvert[i].co); @@ -362,7 +362,7 @@ static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M, DerivedMesh *dm) /* ah yeah, put the verices to global coords once */ /* and determine the ortho BB on the fly */ for(i=0; i < pccd_M->totvert; i++){ - Mat4MulVecfl(ob->obmat, pccd_M->mvert[i].co); + mul_m4_v3(ob->obmat, pccd_M->mvert[i].co); /* evaluate limits */ VECCOPY(v,pccd_M->mvert[i].co); @@ -593,7 +593,7 @@ static void add_mesh_quad_diag_springs(Object *ob) if (ob->soft){ int nofquads; - float s_shear = ob->soft->shearstiff*ob->soft->shearstiff; + //float s_shear = ob->soft->shearstiff*ob->soft->shearstiff; nofquads = count_mesh_quads(me); if (nofquads) { @@ -1059,8 +1059,8 @@ static int sb_detect_face_pointCached(float face_v1[3],float face_v2[3],float fa /* calculate face normal once again SIGH */ VECSUB(edge1, face_v1, face_v2); VECSUB(edge2, face_v3, face_v2); - Crossf(d_nvect, edge2, edge1); - Normalize(d_nvect); + cross_v3_v3v3(d_nvect, edge2, edge1); + normalize_v3(d_nvect); hash = vertexowner->soft->scratch->colliderhash; @@ -1103,14 +1103,14 @@ static int sb_detect_face_pointCached(float face_v1[3],float face_v2[3],float fa while(a){ VECCOPY(nv1,mvert[a-1].co); if(mprevvert){ - VecMulf(nv1,time); + mul_v3_fl(nv1,time); Vec3PlusStVec(nv1,(1.0f-time),mprevvert[a-1].co); } /* origin to face_v2*/ VECSUB(nv1, nv1, face_v2); - facedist = Inpf(nv1,d_nvect); + facedist = dot_v3v3(nv1,d_nvect); if (ABS(facedist)<outerfacethickness){ - if (point_in_tri_prism(nv1, face_v1,face_v2,face_v3) ){ + if (isect_point_tri_prism_v3(nv1, face_v1,face_v2,face_v3) ){ float df; if (facedist > 0){ df = (outerfacethickness-facedist)/outerfacethickness; @@ -1218,17 +1218,17 @@ static int sb_detect_face_collisionCached(float face_v1[3],float face_v2[3],floa VECCOPY(nv4,mvert[mface->v4].co); } if (mprevvert){ - VecMulf(nv1,time); + mul_v3_fl(nv1,time); Vec3PlusStVec(nv1,(1.0f-time),mprevvert[mface->v1].co); - VecMulf(nv2,time); + mul_v3_fl(nv2,time); Vec3PlusStVec(nv2,(1.0f-time),mprevvert[mface->v2].co); - VecMulf(nv3,time); + mul_v3_fl(nv3,time); Vec3PlusStVec(nv3,(1.0f-time),mprevvert[mface->v3].co); if (mface->v4){ - VecMulf(nv4,time); + mul_v3_fl(nv4,time); Vec3PlusStVec(nv4,(1.0f-time),mprevvert[mface->v4].co); } } @@ -1237,12 +1237,12 @@ static int sb_detect_face_collisionCached(float face_v1[3],float face_v2[3],floa /* switch origin to be nv2*/ VECSUB(edge1, nv1, nv2); VECSUB(edge2, nv3, nv2); - Crossf(d_nvect, edge2, edge1); - Normalize(d_nvect); + cross_v3_v3v3(d_nvect, edge2, edge1); + normalize_v3(d_nvect); if ( - LineIntersectsTriangle(nv1, nv2, face_v1, face_v2, face_v3, &t, NULL) || - LineIntersectsTriangle(nv2, nv3, face_v1, face_v2, face_v3, &t, NULL) || - LineIntersectsTriangle(nv3, nv1, face_v1, face_v2, face_v3, &t, NULL) ){ + isect_line_tri_v3(nv1, nv2, face_v1, face_v2, face_v3, &t, NULL) || + isect_line_tri_v3(nv2, nv3, face_v1, face_v2, face_v3, &t, NULL) || + isect_line_tri_v3(nv3, nv1, face_v1, face_v2, face_v3, &t, NULL) ){ Vec3PlusStVec(force,-0.5f,d_nvect); *damp=tune*ob->pd->pdef_sbdamp; deflected = 2; @@ -1251,13 +1251,13 @@ static int sb_detect_face_collisionCached(float face_v1[3],float face_v2[3],floa /* switch origin to be nv4 */ VECSUB(edge1, nv3, nv4); VECSUB(edge2, nv1, nv4); - Crossf(d_nvect, edge2, edge1); - Normalize(d_nvect); + cross_v3_v3v3(d_nvect, edge2, edge1); + normalize_v3(d_nvect); if ( - /* LineIntersectsTriangle(nv1, nv3, face_v1, face_v2, face_v3, &t, NULL) || + /* isect_line_tri_v3(nv1, nv3, face_v1, face_v2, face_v3, &t, NULL) || we did that edge allready */ - LineIntersectsTriangle(nv3, nv4, face_v1, face_v2, face_v3, &t, NULL) || - LineIntersectsTriangle(nv4, nv1, face_v1, face_v2, face_v3, &t, NULL) ){ + isect_line_tri_v3(nv3, nv4, face_v1, face_v2, face_v3, &t, NULL) || + isect_line_tri_v3(nv4, nv1, face_v1, face_v2, face_v3, &t, NULL) ){ Vec3PlusStVec(force,-0.5f,d_nvect); *damp=tune*ob->pd->pdef_sbdamp; deflected = 2; @@ -1380,7 +1380,7 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa aabbmax[1] = MAX2(edge_v1[1],edge_v2[1]); aabbmax[2] = MAX2(edge_v1[2],edge_v2[2]); - el = VecLenf(edge_v1,edge_v2); + el = len_v3v3(edge_v1,edge_v2); hash = vertexowner->soft->scratch->colliderhash; ihash = BLI_ghashIterator_new(hash); @@ -1446,17 +1446,17 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa VECCOPY(nv4,mvert[mface->v4].co); } if (mprevvert){ - VecMulf(nv1,time); + mul_v3_fl(nv1,time); Vec3PlusStVec(nv1,(1.0f-time),mprevvert[mface->v1].co); - VecMulf(nv2,time); + mul_v3_fl(nv2,time); Vec3PlusStVec(nv2,(1.0f-time),mprevvert[mface->v2].co); - VecMulf(nv3,time); + mul_v3_fl(nv3,time); Vec3PlusStVec(nv3,(1.0f-time),mprevvert[mface->v3].co); if (mface->v4){ - VecMulf(nv4,time); + mul_v3_fl(nv4,time); Vec3PlusStVec(nv4,(1.0f-time),mprevvert[mface->v4].co); } } @@ -1466,15 +1466,15 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa VECSUB(edge1, nv1, nv2); VECSUB(edge2, nv3, nv2); - Crossf(d_nvect, edge2, edge1); - Normalize(d_nvect); - if ( LineIntersectsTriangle(edge_v1, edge_v2, nv1, nv2, nv3, &t, NULL)){ + cross_v3_v3v3(d_nvect, edge2, edge1); + normalize_v3(d_nvect); + if ( isect_line_tri_v3(edge_v1, edge_v2, nv1, nv2, nv3, &t, NULL)){ float v1[3],v2[3]; float intrusiondepth,i1,i2; VECSUB(v1, edge_v1, nv2); VECSUB(v2, edge_v2, nv2); - i1 = Inpf(v1,d_nvect); - i2 = Inpf(v2,d_nvect); + i1 = dot_v3v3(v1,d_nvect); + i2 = dot_v3v3(v2,d_nvect); intrusiondepth = -MIN2(i1,i2)/el; Vec3PlusStVec(force,intrusiondepth,d_nvect); *damp=ob->pd->pdef_sbdamp; @@ -1485,15 +1485,15 @@ static int sb_detect_edge_collisionCached(float edge_v1[3],float edge_v2[3],floa VECSUB(edge1, nv3, nv4); VECSUB(edge2, nv1, nv4); - Crossf(d_nvect, edge2, edge1); - Normalize(d_nvect); - if (LineIntersectsTriangle( edge_v1, edge_v2,nv1, nv3, nv4, &t, NULL)){ + cross_v3_v3v3(d_nvect, edge2, edge1); + normalize_v3(d_nvect); + if (isect_line_tri_v3( edge_v1, edge_v2,nv1, nv3, nv4, &t, NULL)){ float v1[3],v2[3]; float intrusiondepth,i1,i2; VECSUB(v1, edge_v1, nv4); VECSUB(v2, edge_v2, nv4); - i1 = Inpf(v1,d_nvect); - i2 = Inpf(v2,d_nvect); + i1 = dot_v3v3(v1,d_nvect); + i2 = dot_v3v3(v2,d_nvect); intrusiondepth = -MIN2(i1,i2)/el; @@ -1531,7 +1531,7 @@ static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow, if (ob->softflag & OB_SB_EDGECOLL){ if ( sb_detect_edge_collisionCached (sb->bpoint[bs->v1].pos , sb->bpoint[bs->v2].pos, &damp,feedback,ob->lay,ob,timenow)){ - VecAddf(bs->ext_force,bs->ext_force,feedback); + add_v3_v3v3(bs->ext_force,bs->ext_force,feedback); bs->flag |= BSF_INTERSECT; //bs->cf=damp; bs->cf=sb->choke*0.01f; @@ -1550,30 +1550,30 @@ static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow, EffectedPoint epoint; float speed[3]={0.0f,0.0f,0.0f}; float pos[3]; - VecMidf(pos, sb->bpoint[bs->v1].pos , sb->bpoint[bs->v2].pos); - VecMidf(vel, sb->bpoint[bs->v1].vec , sb->bpoint[bs->v2].vec); + mid_v3_v3v3(pos, sb->bpoint[bs->v1].pos , sb->bpoint[bs->v2].pos); + mid_v3_v3v3(vel, sb->bpoint[bs->v1].vec , sb->bpoint[bs->v2].vec); pd_point_from_soft(scene, pos, vel, -1, &epoint); pdDoEffectors(do_effector, NULL, sb->effector_weights, &epoint, force, speed); - VecMulf(speed,windfactor); - VecAddf(vel,vel,speed); + mul_v3_fl(speed,windfactor); + add_v3_v3v3(vel,vel,speed); } /* media in rest */ else{ VECADD(vel, sb->bpoint[bs->v1].vec , sb->bpoint[bs->v2].vec); } - f = Normalize(vel); + f = normalize_v3(vel); f = -0.0001f*f*f*sb->aeroedge; /* (todo) add a nice angle dependant function done for now BUT */ /* still there could be some nice drag/lift function, but who needs it */ VECSUB(sp, sb->bpoint[bs->v1].pos , sb->bpoint[bs->v2].pos); - Projf(pr,vel,sp); + project_v3_v3v3(pr,vel,sp); VECSUB(vel,vel,pr); - Normalize(vel); + normalize_v3(vel); if (ob->softflag & OB_SB_AERO_ANGLE){ - Normalize(sp); - Vec3PlusStVec(bs->ext_force,f*(1.0f-ABS(Inpf(vel,sp))),vel); + normalize_v3(sp); + Vec3PlusStVec(bs->ext_force,f*(1.0f-ABS(dot_v3v3(vel,sp))),vel); } else{ Vec3PlusStVec(bs->ext_force,f,vel); // to keep compatible with 2.45 release files @@ -1671,15 +1671,15 @@ static int choose_winner(float*w, float* pos,float*a,float*b,float*c,float*ca,fl { float mindist,cp; int winner =1; - mindist = ABS(Inpf(pos,a)); + mindist = ABS(dot_v3v3(pos,a)); - cp = ABS(Inpf(pos,b)); + cp = ABS(dot_v3v3(pos,b)); if ( mindist < cp ){ mindist = cp; winner =2; } - cp = ABS(Inpf(pos,c)); + cp = ABS(dot_v3v3(pos,c)); if (mindist < cp ){ mindist = cp; winner =3; @@ -1805,17 +1805,17 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], VECSUB(vv4,nv4,mprevvert[mface->v4].co); } - VecMulf(nv1,time); + mul_v3_fl(nv1,time); Vec3PlusStVec(nv1,(1.0f-time),mprevvert[mface->v1].co); - VecMulf(nv2,time); + mul_v3_fl(nv2,time); Vec3PlusStVec(nv2,(1.0f-time),mprevvert[mface->v2].co); - VecMulf(nv3,time); + mul_v3_fl(nv3,time); Vec3PlusStVec(nv3,(1.0f-time),mprevvert[mface->v3].co); if (mface->v4){ - VecMulf(nv4,time); + mul_v3_fl(nv4,time); Vec3PlusStVec(nv4,(1.0f-time),mprevvert[mface->v4].co); } } @@ -1826,14 +1826,14 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], VECSUB(edge2, nv3, nv2); VECSUB(dv1,opco,nv2); /* abuse dv1 to have vertex in question at *origin* of triangle */ - Crossf(d_nvect, edge2, edge1); - n_mag = Normalize(d_nvect); - facedist = Inpf(dv1,d_nvect); + cross_v3_v3v3(d_nvect, edge2, edge1); + n_mag = normalize_v3(d_nvect); + facedist = dot_v3v3(dv1,d_nvect); // so rules are // if ((facedist > innerfacethickness) && (facedist < outerfacethickness)){ - if (point_in_tri_prism(opco, nv1, nv2, nv3) ){ + if (isect_point_tri_prism_v3(opco, nv1, nv2, nv3) ){ force_mag_norm =(float)exp(-ee*facedist); if (facedist > outerfacethickness*ff) force_mag_norm =(float)force_mag_norm*fa*(facedist - outerfacethickness)*(facedist - outerfacethickness); @@ -1863,12 +1863,12 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], VECSUB(edge2, nv1, nv4); VECSUB(dv1,opco,nv4); /* abuse dv1 to have vertex in question at *origin* of triangle */ - Crossf(d_nvect, edge2, edge1); - n_mag = Normalize(d_nvect); - facedist = Inpf(dv1,d_nvect); + cross_v3_v3v3(d_nvect, edge2, edge1); + n_mag = normalize_v3(d_nvect); + facedist = dot_v3v3(dv1,d_nvect); if ((facedist > innerfacethickness) && (facedist < outerfacethickness)){ - if (point_in_tri_prism(opco, nv1, nv3, nv4) ){ + if (isect_point_tri_prism_v3(opco, nv1, nv3, nv4) ){ force_mag_norm =(float)exp(-ee*facedist); if (facedist > outerfacethickness*ff) force_mag_norm =(float)force_mag_norm*fa*(facedist - outerfacethickness)*(facedist - outerfacethickness); @@ -1898,45 +1898,45 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], { // see if 'outer' hits an edge float dist; - PclosestVL3Dfl(ve, opco, nv1, nv2); + closest_to_line_segment_v3(ve, opco, nv1, nv2); VECSUB(ve,opco,ve); - dist = Normalize(ve); + dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ VECCOPY(coledge,ve); mindistedge = dist, deflected=1; } - PclosestVL3Dfl(ve, opco, nv2, nv3); + closest_to_line_segment_v3(ve, opco, nv2, nv3); VECSUB(ve,opco,ve); - dist = Normalize(ve); + dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ VECCOPY(coledge,ve); mindistedge = dist, deflected=1; } - PclosestVL3Dfl(ve, opco, nv3, nv1); + closest_to_line_segment_v3(ve, opco, nv3, nv1); VECSUB(ve,opco,ve); - dist = Normalize(ve); + dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ VECCOPY(coledge,ve); mindistedge = dist, deflected=1; } if (mface->v4){ /* quad */ - PclosestVL3Dfl(ve, opco, nv3, nv4); + closest_to_line_segment_v3(ve, opco, nv3, nv4); VECSUB(ve,opco,ve); - dist = Normalize(ve); + dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ VECCOPY(coledge,ve); mindistedge = dist, deflected=1; } - PclosestVL3Dfl(ve, opco, nv1, nv4); + closest_to_line_segment_v3(ve, opco, nv1, nv4); VECSUB(ve,opco,ve); - dist = Normalize(ve); + dist = normalize_v3(ve); if ((dist < outerfacethickness)&&(dist < mindistedge )){ VECCOPY(coledge,ve); mindistedge = dist, @@ -1974,12 +1974,12 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } BLI_ghashIterator_free(ihash); - if (cavel) VecMulf(avel,1.0f/(float)cavel); + if (cavel) mul_v3_fl(avel,1.0f/(float)cavel); VECCOPY(vel,avel); if (ci) *intrusion /= ci; if (deflected){ VECCOPY(facenormal,force); - Normalize(facenormal); + normalize_v3(facenormal); } return deflected; } @@ -2060,8 +2060,8 @@ static void sb_spring_force(Object *ob,int bpi,BodySpring *bs,float iks,float fo } /* do bp1 <--> bp2 elastic */ - VecSubf(dir,bp1->pos,bp2->pos); - distance = Normalize(dir); + sub_v3_v3v3(dir,bp1->pos,bp2->pos); + distance = normalize_v3(dir); if (bs->len < distance) iks = 1.0f/(1.0f-sb->inspring)-1.0f ;/* inner spring constants function */ else @@ -2092,10 +2092,10 @@ static void sb_spring_force(Object *ob,int bpi,BodySpring *bs,float iks,float fo Vec3PlusStVec(bp1->force,(bs->len - distance)*forcefactor,dir); /* do bp1 <--> bp2 viscous */ - VecSubf(dvel,bp1->vec,bp2->vec); + sub_v3_v3v3(dvel,bp1->vec,bp2->vec); kd = sb->infrict * sb_fric_force_scale(ob); - absvel = Normalize(dvel); - projvel = Inpf(dir,dvel); + absvel = normalize_v3(dvel); + projvel = dot_v3v3(dir,dvel); kd *= absvel * projvel; Vec3PlusStVec(bp1->force,-kd,dir); @@ -2169,11 +2169,11 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo for(c=sb->totpoint, obp= sb->bpoint; c>=ifirst+bb; c--, obp++) { compare = (obp->colball + bp->colball); - VecSubf(def, bp->pos, obp->pos); + sub_v3_v3v3(def, bp->pos, obp->pos); /* rather check the AABBoxes before ever calulating the real distance */ /* mathematically it is completly nuts, but performace is pretty much (3) times faster */ if ((ABS(def[0]) > compare) || (ABS(def[1]) > compare) || (ABS(def[2]) > compare)) continue; - distance = Normalize(def); + distance = normalize_v3(def); if (distance < compare ){ /* exclude body points attached with a spring */ attached = 0; @@ -2186,16 +2186,16 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo if (!attached){ float f = bstune/(distance) + bstune/(compare*compare)*distance - 2.0f*bstune/compare ; - VecMidf(velcenter, bp->vec, obp->vec); - VecSubf(dvel,velcenter,bp->vec); - VecMulf(dvel,bp->mass); + mid_v3_v3v3(velcenter, bp->vec, obp->vec); + sub_v3_v3v3(dvel,velcenter,bp->vec); + mul_v3_fl(dvel,bp->mass); Vec3PlusStVec(bp->force,f*(1.0f-sb->balldamp),def); Vec3PlusStVec(bp->force,sb->balldamp,dvel); /* exploit force(a,b) == -force(b,a) part2/2 */ - VecSubf(dvel,velcenter,obp->vec); - VecMulf(dvel,bp->mass); + sub_v3_v3v3(dvel,velcenter,obp->vec); + mul_v3_fl(dvel,bp->mass); Vec3PlusStVec(obp->force,sb->balldamp,dvel); Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def); @@ -2213,16 +2213,16 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo if(ob->softflag & OB_SB_GOAL) { /* true elastic goal */ float ks,kd; - VecSubf(auxvect,bp->pos,bp->origT); + sub_v3_v3v3(auxvect,bp->pos,bp->origT); ks = 1.0f/(1.0f- bp->goal*sb->goalspring)-1.0f ; bp->force[0]+= -ks*(auxvect[0]); bp->force[1]+= -ks*(auxvect[1]); bp->force[2]+= -ks*(auxvect[2]); /* calulate damping forces generated by goals*/ - VecSubf(velgoal,bp->origS, bp->origE); + sub_v3_v3v3(velgoal,bp->origS, bp->origE); kd = sb->goalfrict * sb_fric_force_scale(ob) ; - VecAddf(auxvect,velgoal,bp->vec); + add_v3_v3v3(auxvect,velgoal,bp->vec); if (forcetime > 0.0 ) { /* make sure friction does not become rocket motor on time reversal */ bp->force[0]-= kd * (auxvect[0]); @@ -2241,8 +2241,8 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo if (sb && scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY){ float gravity[3]; VECCOPY(gravity, scene->physics_settings.gravity); - VecMulf(gravity, sb_grav_force_scale(ob)*bp->mass*sb->effector_weights->global_gravity); /* individual mass of node here */ - VecAddf(bp->force, bp->force, gravity); + mul_v3_fl(gravity, sb_grav_force_scale(ob)*bp->mass*sb->effector_weights->global_gravity); /* individual mass of node here */ + add_v3_v3v3(bp->force, bp->force, gravity); } /* particle field & vortex */ @@ -2256,7 +2256,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo pdDoEffectors(do_effector, NULL, sb->effector_weights, &epoint, force, speed); /* apply forcefield*/ - VecMulf(force,fieldfactor* eval_sb_fric_force_scale); + mul_v3_fl(force,fieldfactor* eval_sb_fric_force_scale); VECADD(bp->force, bp->force, force); /* BP friction in moving media */ @@ -2309,7 +2309,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo for(b=bp->nofsprings;b>0;b--){ bs = sb->bspring + bp->springs[b-1]; if (do_springcollision || do_aero){ - VecAddf(bp->force,bp->force,bs->ext_force); + add_v3_v3v3(bp->force,bp->force,bs->ext_force); if (bs->flag & BSF_INTERSECT) bp->choke = bs->cf; @@ -2478,7 +2478,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY){ VECCOPY(gravity, scene->physics_settings.gravity); - VecMulf(gravity, sb_grav_force_scale(ob)*sb->effector_weights->global_gravity); + mul_v3_fl(gravity, sb_grav_force_scale(ob)*sb->effector_weights->global_gravity); } /* check conditions for various options */ @@ -2538,13 +2538,13 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa //if ((bp->octantflag & obp->octantflag) == 0) continue; compare = (obp->colball + bp->colball); - VecSubf(def, bp->pos, obp->pos); + sub_v3_v3v3(def, bp->pos, obp->pos); /* rather check the AABBoxes before ever calulating the real distance */ /* mathematically it is completly nuts, but performace is pretty much (3) times faster */ if ((ABS(def[0]) > compare) || (ABS(def[1]) > compare) || (ABS(def[2]) > compare)) continue; - distance = Normalize(def); + distance = normalize_v3(def); if (distance < compare ){ /* exclude body points attached with a spring */ attached = 0; @@ -2557,9 +2557,9 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa if (!attached){ float f = tune/(distance) + tune/(compare*compare)*distance - 2.0f*tune/compare ; - VecMidf(velcenter, bp->vec, obp->vec); - VecSubf(dvel,velcenter,bp->vec); - VecMulf(dvel,bp->mass); + mid_v3_v3v3(velcenter, bp->vec, obp->vec); + sub_v3_v3v3(dvel,velcenter,bp->vec); + mul_v3_fl(dvel,bp->mass); Vec3PlusStVec(bp->force,f*(1.0f-sb->balldamp),def); Vec3PlusStVec(bp->force,sb->balldamp,dvel); @@ -2589,8 +2589,8 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa } /* exploit force(a,b) == -force(b,a) part2/2 */ - VecSubf(dvel,velcenter,obp->vec); - VecMulf(dvel,(bp->mass+obp->mass)/2.0f); + sub_v3_v3v3(dvel,velcenter,obp->vec); + mul_v3_fl(dvel,(bp->mass+obp->mass)/2.0f); Vec3PlusStVec(obp->force,sb->balldamp,dvel); Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def); @@ -2609,7 +2609,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa /* do goal stuff */ if(ob->softflag & OB_SB_GOAL) { /* true elastic goal */ - VecSubf(auxvect,bp->pos,bp->origT); + sub_v3_v3v3(auxvect,bp->pos,bp->origT); ks = 1.0f/(1.0f- bp->goal*sb->goalspring)-1.0f ; bp->force[0]+= -ks*(auxvect[0]); bp->force[1]+= -ks*(auxvect[1]); @@ -2624,9 +2624,9 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa /* calulate damping forces generated by goals*/ - VecSubf(velgoal,bp->origS, bp->origE); + sub_v3_v3v3(velgoal,bp->origS, bp->origE); kd = sb->goalfrict * sb_fric_force_scale(ob) ; - VecAddf(auxvect,velgoal,bp->vec); + add_v3_v3v3(auxvect,velgoal,bp->vec); if (forcetime > 0.0 ) { /* make sure friction does not become rocket motor on time reversal */ bp->force[0]-= kd * (auxvect[0]); @@ -2634,7 +2634,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa bp->force[2]-= kd * (auxvect[2]); if(nl_flags & NLF_BUILD){ //int ia =3*(sb->totpoint-a); - Normalize(auxvect); + normalize_v3(auxvect); /* depending on my vel */ //dfdv_goal(ia,ia,kd*forcetime); } @@ -2663,7 +2663,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa pdDoEffectors(do_effector, NULL, sb->effector_weights, &epoint, force, speed); /* apply forcefield*/ - VecMulf(force,fieldfactor* eval_sb_fric_force_scale); + mul_v3_fl(force,fieldfactor* eval_sb_fric_force_scale); VECADD(bp->force, bp->force, force); /* BP friction in moving media */ @@ -2750,7 +2750,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa for(b=bp->nofsprings;b>0;b--){ bs = sb->bspring + bp->springs[b-1]; if (do_springcollision || do_aero){ - VecAddf(bp->force,bp->force,bs->ext_force); + add_v3_v3v3(bp->force,bp->force,bs->ext_force); if (bs->flag & BSF_INTERSECT) bp->choke = bs->cf; @@ -2882,7 +2882,7 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * /* the ( ... )' operator denotes derivate respective time */ /* the euler step for velocity then becomes */ /* v(t + dt) = v(t) + a(t) * dt */ - VecMulf(bp->force,timeovermass);/* individual mass of node here */ + mul_v3_fl(bp->force,timeovermass);/* individual mass of node here */ /* some nasty if's to have heun in here too */ VECCOPY(dv,bp->force); @@ -2909,17 +2909,17 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * /* so here is (x)'= v(elocity) */ /* the euler step for location then becomes */ /* x(t + dt) = x(t) + v(t~) * dt */ - VecMulf(dx,forcetime); + mul_v3_fl(dx,forcetime); /* the freezer coming sooner or later */ /* - if ((Inpf(dx,dx)<freezeloc )&&(Inpf(bp->force,bp->force)<freezeforce )){ + if ((dot_v3v3(dx,dx)<freezeloc )&&(dot_v3v3(bp->force,bp->force)<freezeforce )){ bp->frozen /=2; } else{ bp->frozen =MIN2(bp->frozen*1.05f,1.0f); } - VecMulf(dx,bp->frozen); + mul_v3_fl(dx,bp->frozen); */ /* again some nasty if's to have heun in here too */ if (mode ==1){ @@ -2940,10 +2940,10 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * we don't want to end up in deep space so we add some <viscosity> to balance that out */ if (bp->choke2 > 0.0f){ - VecMulf(bp->vec,(1.0f - bp->choke2)); + mul_v3_fl(bp->vec,(1.0f - bp->choke2)); } if (bp->choke > 0.0f){ - VecMulf(bp->vec,(1.0f - bp->choke)); + mul_v3_fl(bp->vec,(1.0f - bp->choke)); } } @@ -2959,7 +2959,7 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * if (bp->flag & SBF_DOFUZZY) fuzzy =1; } /*for*/ - if (sb->totpoint) VecMulf(cm,1.0f/sb->totpoint); + if (sb->totpoint) mul_v3_fl(cm,1.0f/sb->totpoint); if (sb->scratch){ VECCOPY(sb->scratch->aabbmin,aabbmin); VECCOPY(sb->scratch->aabbmax,aabbmax); @@ -3100,7 +3100,7 @@ static void apply_spring_memory(Object *ob) bs = &sb->bspring[a]; bp1 =&sb->bpoint[bs->v1]; bp2 =&sb->bpoint[bs->v2]; - l = VecLenf(bp1->pos,bp2->pos); + l = len_v3v3(bp1->pos,bp2->pos); r = bs->len/l; if (( r > 1.05f) || (r < 0.95)){ bs->len = ((100.0f - b) * bs->len + b*l)/100.0f; @@ -3192,7 +3192,7 @@ static void springs_from_mesh(Object *ob) bp= ob->soft->bpoint; for(a=0; a<me->totvert; a++, bp++) { VECCOPY(bp->origS, me->mvert[a].co); - Mat4MulVecfl(ob->obmat, bp->origS); + mul_m4_v3(ob->obmat, bp->origS); } } @@ -3203,7 +3203,7 @@ static void springs_from_mesh(Object *ob) } for(a=0; a<sb->totspring; a++) { BodySpring *bs = &sb->bspring[a]; - bs->len= scale*VecLenf(sb->bpoint[bs->v1].origS, sb->bpoint[bs->v2].origS); + bs->len= scale*len_v3v3(sb->bpoint[bs->v1].origS, sb->bpoint[bs->v2].origS); } } } @@ -3341,10 +3341,10 @@ static float globallen(float *v1,float *v2,Object *ob) { float p1[3],p2[3]; VECCOPY(p1,v1); - Mat4MulVecfl(ob->obmat, p1); + mul_m4_v3(ob->obmat, p1); VECCOPY(p2,v2); - Mat4MulVecfl(ob->obmat, p2); - return VecLenf(p1,p2); + mul_m4_v3(ob->obmat, p2); + return len_v3v3(p1,p2); } static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff,Object *ob) @@ -3573,12 +3573,12 @@ static void softbody_to_object(Object *ob, float (*vertexCos)[3], int numVerts, int a; /* inverse matrix is not uptodate... */ - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); for(a=0; a<numVerts; a++, bp++) { VECCOPY(vertexCos[a], bp->pos); if(local==0) - Mat4MulVecfl(ob->imat, vertexCos[a]); /* softbody is in global coords, baked optionally not */ + mul_m4_v3(ob->imat, vertexCos[a]); /* softbody is in global coords, baked optionally not */ } } @@ -3706,7 +3706,7 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo /* copy the position of the goals at desired end time */ VECCOPY(bp->origE, vertexCos[a]); /* vertexCos came from local world, go global */ - Mat4MulVecfl(ob->obmat, bp->origE); + mul_m4_v3(ob->obmat, bp->origE); /* just to be save give bp->origT a defined value will be calulated in interpolate_exciter()*/ VECCOPY(bp->origT, bp->origE); @@ -3720,7 +3720,7 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int for(a=0,bp=sb->bpoint; a<numVerts; a++, bp++) { VECCOPY(bp->pos, vertexCos[a]); - Mat4MulVecfl(ob->obmat, bp->pos); /* yep, sofbody is global coords*/ + mul_m4_v3(ob->obmat, bp->pos); /* yep, sofbody is global coords*/ VECCOPY(bp->origS, bp->pos); VECCOPY(bp->origE, bp->pos); VECCOPY(bp->origT, bp->pos); diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 6e95fe7ebc7..cb2e2c437bf 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -54,7 +54,7 @@ #include "BLI_blenlib.h" #include "BLI_editVert.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_linklist.h" #include "BLI_memarena.h" #include "BLI_edgehash.h" @@ -561,7 +561,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, } DM_interp_vert_data(dm, result, vertIdx, weight[0][0], numVerts, i); - VecCopyf(mvert->co, ccgSubSurf_getFaceCenterData(f)); + copy_v3_v3(mvert->co, ccgSubSurf_getFaceCenterData(f)); *origIndex = ORIGINDEX_NONE; ++mvert; ++origIndex; @@ -579,7 +579,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, w[nextS] = weight[x][0][2]; w[otherS] = weight[x][0][3]; DM_interp_vert_data(dm, result, vertIdx, w, numVerts, i); - VecCopyf(mvert->co, + copy_v3_v3(mvert->co, ccgSubSurf_getFaceGridEdgeData(ss, f, S, x)); *origIndex = ORIGINDEX_NONE; @@ -602,7 +602,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, w[nextS] = weight[y * gridFaces + x][0][2]; w[otherS] = weight[y * gridFaces + x][0][3]; DM_interp_vert_data(dm, result, vertIdx, w, numVerts, i); - VecCopyf(mvert->co, + copy_v3_v3(mvert->co, ccgSubSurf_getFaceGridData(ss, f, S, x, y)); *origIndex = ORIGINDEX_NONE; ++mvert; @@ -633,7 +633,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, w[1] = (float) x / (edgeSize - 1); w[0] = 1 - w[1]; DM_interp_vert_data(dm, result, vertIdx, w, 2, i); - VecCopyf(mvert->co, ccgSubSurf_getEdgeData(ss, e, x)); + copy_v3_v3(mvert->co, ccgSubSurf_getEdgeData(ss, e, x)); *origIndex = ORIGINDEX_NONE; ++mvert; ++origIndex; @@ -651,7 +651,7 @@ static DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, vertIdx = GET_INT_FROM_POINTER(ccgSubSurf_getVertVertHandle(v)); DM_copy_vert_data(dm, result, vertIdx, i, 1); - VecCopyf(mvert->co, ccgSubSurf_getVertData(ss, v)); + copy_v3_v3(mvert->co, ccgSubSurf_getVertData(ss, v)); *((int*)ccgSubSurf_getVertUserData(ss, v)) = i; *origIndex = ccgDM_getVertMapIndex(ss, v); @@ -1016,19 +1016,19 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) offset = vertNum - ccgdm->faceMap[i].startVert; if(offset < 1) { - VecCopyf(mv->co, ccgSubSurf_getFaceCenterData(f)); + copy_v3_v3(mv->co, ccgSubSurf_getFaceCenterData(f)); } else if(offset < gridSideEnd) { offset -= 1; grid = offset / gridSideVerts; x = offset % gridSideVerts + 1; - VecCopyf(mv->co, ccgSubSurf_getFaceGridEdgeData(ss, f, grid, x)); + copy_v3_v3(mv->co, ccgSubSurf_getFaceGridEdgeData(ss, f, grid, x)); } else if(offset < gridInternalEnd) { offset -= gridSideEnd; grid = offset / gridInternalVerts; offset %= gridInternalVerts; y = offset / gridSideVerts + 1; x = offset % gridSideVerts + 1; - VecCopyf(mv->co, ccgSubSurf_getFaceGridData(ss, f, grid, x, y)); + copy_v3_v3(mv->co, ccgSubSurf_getFaceGridData(ss, f, grid, x, y)); } } else if((vertNum < ccgdm->vertMap[0].startVert) && (ccgSubSurf_getNumEdges(ss) > 0)) { /* this vert comes from edge data */ @@ -1043,14 +1043,14 @@ static void ccgDM_getFinalVert(DerivedMesh *dm, int vertNum, MVert *mv) e = ccgdm->edgeMap[i].edge; x = vertNum - ccgdm->edgeMap[i].startVert + 1; - VecCopyf(mv->co, ccgSubSurf_getEdgeData(ss, e, x)); + copy_v3_v3(mv->co, ccgSubSurf_getEdgeData(ss, e, x)); } else { /* this vert comes from vert data */ CCGVert *v; i = vertNum - ccgdm->vertMap[0].startVert; v = ccgdm->vertMap[i].vert; - VecCopyf(mv->co, ccgSubSurf_getVertData(ss, v)); + copy_v3_v3(mv->co, ccgSubSurf_getVertData(ss, v)); } } @@ -1188,11 +1188,11 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) CCGFace *f = ccgdm->faceMap[index].face; int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f); - VecCopyf(mvert[i++].co, ccgSubSurf_getFaceCenterData(f)); + copy_v3_v3(mvert[i++].co, ccgSubSurf_getFaceCenterData(f)); for(S = 0; S < numVerts; S++) { for(x = 1; x < gridSize - 1; x++) { - VecCopyf(mvert[i++].co, + copy_v3_v3(mvert[i++].co, ccgSubSurf_getFaceGridEdgeData(ss, f, S, x)); } } @@ -1200,7 +1200,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) for(S = 0; S < numVerts; S++) { for(y = 1; y < gridSize - 1; y++) { for(x = 1; x < gridSize - 1; x++) { - VecCopyf(mvert[i++].co, + copy_v3_v3(mvert[i++].co, ccgSubSurf_getFaceGridData(ss, f, S, x, y)); } } @@ -1213,7 +1213,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) int x; for(x = 1; x < edgeSize - 1; x++) { - VecCopyf(mvert[i++].co, ccgSubSurf_getEdgeData(ss, e, x)); + copy_v3_v3(mvert[i++].co, ccgSubSurf_getEdgeData(ss, e, x)); } } @@ -1221,7 +1221,7 @@ static void ccgDM_copyFinalVertArray(DerivedMesh *dm, MVert *mvert) for(index = 0; index < totvert; index++) { CCGVert *v = ccgdm->vertMap[index].vert; - VecCopyf(mvert[i].co, ccgSubSurf_getVertData(ss, v)); + copy_v3_v3(mvert[i].co, ccgSubSurf_getVertData(ss, v)); i++; } @@ -1397,18 +1397,18 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) { CCGFace *f = faceMap2[index]; int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f); - VecCopyf(cos[i++], ccgSubSurf_getFaceCenterData(f)); + copy_v3_v3(cos[i++], ccgSubSurf_getFaceCenterData(f)); for (S=0; S<numVerts; S++) { for (x=1; x<gridSize-1; x++) { - VecCopyf(cos[i++], ccgSubSurf_getFaceGridEdgeData(ss, f, S, x)); + copy_v3_v3(cos[i++], ccgSubSurf_getFaceGridEdgeData(ss, f, S, x)); } } for (S=0; S<numVerts; S++) { for (y=1; y<gridSize-1; y++) { for (x=1; x<gridSize-1; x++) { - VecCopyf(cos[i++], ccgSubSurf_getFaceGridData(ss, f, S, x, y)); + copy_v3_v3(cos[i++], ccgSubSurf_getFaceGridData(ss, f, S, x, y)); } } } @@ -1419,13 +1419,13 @@ static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) { int x; for (x=1; x<edgeSize-1; x++) { - VecCopyf(cos[i++], ccgSubSurf_getEdgeData(ss, e, x)); + copy_v3_v3(cos[i++], ccgSubSurf_getEdgeData(ss, e, x)); } } for (index=0; index<totvert; index++) { CCGVert *v = vertMap2[index]; - VecCopyf(cos[i++], ccgSubSurf_getVertData(ss, v)); + copy_v3_v3(cos[i++], ccgSubSurf_getVertData(ss, v)); } MEM_freeN(vertMap2); @@ -2709,17 +2709,17 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]) for (i=0; i<N; i++) { CCGEdge *e = ccgSubSurf_getVertEdge(v, i); - VecAddf(edge_sum, edge_sum, ccgSubSurf_getEdgeData(ss, e, 1)); + add_v3_v3v3(edge_sum, edge_sum, ccgSubSurf_getEdgeData(ss, e, 1)); } for (i=0; i<numFaces; i++) { CCGFace *f = ccgSubSurf_getVertFace(v, i); - VecAddf(face_sum, face_sum, ccgSubSurf_getFaceCenterData(f)); + add_v3_v3v3(face_sum, face_sum, ccgSubSurf_getFaceCenterData(f)); } /* ad-hoc correction for boundary vertices, to at least avoid them moving completely out of place (brecht) */ if(numFaces && numFaces != N) - VecMulf(face_sum, (float)N/(float)numFaces); + mul_v3_fl(face_sum, (float)N/(float)numFaces); co = ccgSubSurf_getVertData(ss, v); positions_r[idx][0] = (co[0]*N*N + edge_sum[0]*4 + face_sum[0])/(N*(N+5)); diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 14460423999..0171c58f2c6 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -41,7 +41,7 @@ #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BLI_kdopbvh.h" @@ -215,7 +215,7 @@ TexMapping *add_mapping(void) texmap->size[0]= texmap->size[1]= texmap->size[2]= 1.0f; texmap->max[0]= texmap->max[1]= texmap->max[2]= 1.0f; - Mat4One(texmap->mat); + unit_m4(texmap->mat); return texmap; } @@ -224,16 +224,16 @@ void init_mapping(TexMapping *texmap) { float eul[3], smat[3][3], rmat[3][3], mat[3][3]; - SizeToMat3(texmap->size, smat); + size_to_mat3( smat,texmap->size); eul[0]= (M_PI/180.0f)*texmap->rot[0]; eul[1]= (M_PI/180.0f)*texmap->rot[1]; eul[2]= (M_PI/180.0f)*texmap->rot[2]; - EulToMat3(eul, rmat); + eul_to_mat3( rmat,eul); - Mat3MulMat3(mat, rmat, smat); + mul_m3_m3m3(mat, rmat, smat); - Mat4CpyMat3(texmap->mat, mat); + copy_m4_m3(texmap->mat, mat); VECCOPY(texmap->mat[3], texmap->loc); } diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index c75c9272e5c..b5f8bc81b81 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -42,7 +42,7 @@ #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h deleted file mode 100644 index 16da7d25721..00000000000 --- a/source/blender/blenlib/BLI_arithb.h +++ /dev/null @@ -1,571 +0,0 @@ -#undef TEST_ACTIVE -//#define ACTIVE 1 -/** - * blenlib/BLI_arithb.h mar 2001 Nzc - * - * $Id$ - * - * ***** BEGIN GPL 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. - * - * 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 LICENSE BLOCK ***** - * */ - -#ifndef BLI_ARITHB_H -#define BLI_ARITHB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef WIN32 -#define _USE_MATH_DEFINES -#endif - -#include <math.h> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 -#endif -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 -#endif -#ifndef M_SQRT1_2 -#define M_SQRT1_2 0.70710678118654752440 -#endif -#ifndef M_1_PI -#define M_1_PI 0.318309886183790671538 -#endif - -#ifndef M_E -#define M_E 2.7182818284590452354 -#endif -#ifndef M_LOG2E -#define M_LOG2E 1.4426950408889634074 -#endif -#ifndef M_LOG10E -#define M_LOG10E 0.43429448190325182765 -#endif -#ifndef M_LN2 -#define M_LN2 0.69314718055994530942 -#endif -#ifndef M_LN10 -#define M_LN10 2.30258509299404568402 -#endif - -#ifndef sqrtf -#define sqrtf(a) ((float)sqrt(a)) -#endif -#ifndef powf -#define powf(a, b) ((float)pow(a, b)) -#endif -#ifndef cosf -#define cosf(a) ((float)cos(a)) -#endif -#ifndef sinf -#define sinf(a) ((float)sin(a)) -#endif -#ifndef acosf -#define acosf(a) ((float)acos(a)) -#endif -#ifndef asinf -#define asinf(a) ((float)asin(a)) -#endif -#ifndef atan2f -#define atan2f(a, b) ((float)atan2(a, b)) -#endif -#ifndef tanf -#define tanf(a) ((float)tan(a)) -#endif -#ifndef atanf -#define atanf(a) ((float)atan(a)) -#endif -#ifndef floorf -#define floorf(a) ((float)floor(a)) -#endif -#ifndef ceilf -#define ceilf(a) ((float)ceil(a)) -#endif -#ifndef fabsf -#define fabsf(a) ((float)fabs(a)) -#endif -#ifndef logf -#define logf(a) ((float)log(a)) -#endif -#ifndef expf -#define expf(a) ((float)exp(a)) -#endif -#ifndef fmodf -#define fmodf(a, b) ((float)fmod(a, b)) -#endif - -#ifdef WIN32 - #ifndef FREE_WINDOWS - #define isnan(n) _isnan(n) - #define finite _finite - #endif -#endif - -#define MAT4_UNITY {{ 1.0, 0.0, 0.0, 0.0},\ - { 0.0, 1.0, 0.0, 0.0},\ - { 0.0, 0.0, 1.0, 0.0},\ - { 0.0, 0.0, 0.0, 1.0}} - -#define MAT3_UNITY {{ 1.0, 0.0, 0.0},\ - { 0.0, 1.0, 0.0},\ - { 0.0, 0.0, 1.0}} - - -void CalcCent3f(float *cent, float *v1, float *v2, float *v3); -void CalcCent4f(float *cent, float *v1, float *v2, float *v3, float *v4); - -void Crossf(float *c, float *a, float *b); -void Projf(float *c, float *v1, float *v2); - -float Inpf(float *v1, float *v2); -float Inp2f(float *v1, float *v2); - -float Normalize(float *n); -float Normalize2(float *n); - -float Sqrt3f(float f); -double Sqrt3d(double d); - -float saacos(float fac); -float saasin(float fac); -float sasqrt(float fac); -float saacosf(float fac); -float saasinf(float fac); -float sasqrtf(float fac); - -int FloatCompare(float *v1, float *v2, float limit); -int FloatCompare4(float *v1, float *v2, float limit); -float FloatLerpf(float target, float origin, float fac); - -float CalcNormFloat(float *v1, float *v2, float *v3, float *n); -float CalcNormFloat4(float *v1, float *v2, float *v3, float *v4, float *n); - -void CalcNormLong(int *v1, int *v2, int *v3, float *n); -/* CalcNormShort: is ook uitprodukt - (translates as 'is also out/cross product') */ -void CalcNormShort(short *v1, short *v2, short *v3, float *n); -float power_of_2(float val); - -/** - * @section Euler conversion routines (With Custom Order) - */ - -/* Defines for rotation orders - * WARNING: must match the eRotationModes in DNA_action_types.h - * order matters - types are saved to file! - */ -typedef enum eEulerRotationOrders { - EULER_ORDER_DEFAULT = 1, /* Blender 'default' (classic) is basically XYZ */ - EULER_ORDER_XYZ = 1, /* Blender 'default' (classic) - must be as 1 to sync with PoseChannel rotmode */ - EULER_ORDER_XZY, - EULER_ORDER_YXZ, - EULER_ORDER_YZX, - EULER_ORDER_ZXY, - EULER_ORDER_ZYX, - /* NOTE: there are about 6 more entries when including duplicated entries too */ -} eEulerRotationOrders; - -void EulOToQuat(float eul[3], short order, float quat[4]); -void QuatToEulO(float quat[4], float eul[3], short order); - -void EulOToMat3(float eul[3], short order, float Mat[3][3]); -void EulOToMat4(float eul[3], short order, float Mat[4][4]); - -void Mat3ToEulO(float Mat[3][3], float eul[3], short order); -void Mat4ToEulO(float Mat[4][4], float eul[3], short order); - -void Mat3ToCompatibleEulO(float mat[3][3], float eul[3], float oldrot[3], short order); - -void eulerO_rot(float beul[3], float ang, char axis, short order); - -/** - * @section Euler conversion routines (Blender XYZ) - */ - -void EulToMat3(float *eul, float mat[][3]); -void EulToMat4(float *eul, float mat[][4]); - -void Mat3ToEul(float tmat[][3], float *eul); -void Mat4ToEul(float tmat[][4],float *eul); - -void EulToQuat(float *eul, float *quat); - -void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot); -void EulToGimbalAxis(float gmat[][3], float *eul, short order); - - -void compatible_eul(float *eul, float *oldrot); -void euler_rot(float *beul, float ang, char axis); - - -/** - * @section Quaternion arithmetic routines - */ - -int QuatIsNul(float *q); -void QuatToEul(float *quat, float *eul); -void QuatOne(float *); -void QuatMul(float *, float *, float *); -void QuatMulVecf(float *q, float *v); -void QuatMulf(float *q, float f); -void QuatMulFac(float *q, float fac); - -void NormalQuat(float *); -void VecRotToQuat(float *vec, float phi, float *quat); - -void QuatSub(float *q, float *q1, float *q2); -void QuatConj(float *q); -void QuatInv(float *q); -float QuatDot(float *q1, float *q2); -void QuatCopy(float *q1, float *q2); - -void printquat(char *str, float q[4]); - -void QuatInterpol(float *result, float *quat1, float *quat2, float t); -void QuatAdd(float *result, float *quat1, float *quat2, float t); - -void QuatToMat3(float *q, float m[][3]); -void QuatToMat4(float *q, float m[][4]); - -/** - * @section matrix multiplication and copying routines - */ - -void Mat3MulFloat(float *m, float f); -void Mat4MulFloat(float *m, float f); -void Mat4MulFloat3(float *m, float f); - -void Mat3Transp(float mat[][3]); -void Mat4Transp(float mat[][4]); - -int Mat4Invert(float inverse[][4], float mat[][4]); -void Mat4InvertSimp(float inverse[][4], float mat[][4]); -void Mat4Inv(float *m1, float *m2); -void Mat4InvGG(float out[][4], float in[][4]); -void Mat3Inv(float m1[][3], float m2[][3]); - -void Mat3CpyMat4(float m1[][3],float m2[][4]); -void Mat4CpyMat3(float m1[][4], float m2[][3]); - -void Mat3BlendMat3(float out[][3], float dst[][3], float src[][3], float srcweight); -void Mat4BlendMat4(float out[][4], float dst[][4], float src[][4], float srcweight); - -float Det2x2(float a,float b,float c, float d); - -float Det3x3( - float a1, float a2, float a3, - float b1, float b2, float b3, - float c1, float c2, float c3 -); - -float Det4x4(float m[][4]); - -void Mat3Adj(float m1[][3], float m[][3]); -void Mat4Adj(float out[][4], float in[][4]); - -void Mat4MulMat4(float m1[][4], float m2[][4], float m3[][4]); -void subMat4MulMat4(float *m1, float *m2, float *m3); -#ifndef TEST_ACTIVE -void Mat3MulMat3(float m1[][3], float m3[][3], float m2[][3]); -#else -void Mat3MulMat3(float *m1, float *m3, float *m2); -#endif -void Mat4MulMat34(float (*m1)[4], float (*m3)[3], float (*m2)[4]); -void Mat4CpyMat4(float m1[][4], float m2[][4]); -void Mat4SwapMat4(float m1[][4], float m2[][4]); -void Mat3CpyMat3(float m1[][3], float m2[][3]); - -void Mat3MulSerie(float answ[][3], - float m1[][3], float m2[][3], float m3[][3], - float m4[][3], float m5[][3], float m6[][3], - float m7[][3], float m8[][3] -); - -void 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] -); - -void Mat4Clr(float *m); -void Mat3Clr(float *m); - -void Mat3One(float m[][3]); -void Mat4One(float m[][4]); - -void Mat3Scale(float m[][3], float scale); -void Mat4Scale(float m[][4], float scale); - -/* NOTE: These only normalise the matrix, they don't make it orthogonal */ -void Mat3Ortho(float mat[][3]); -void Mat4Ortho(float mat[][4]); - -int IsMat3Orthogonal(float mat[][3]); -void Mat3Orthogonal(float mat[][3], int axis); /* axis is the one to keep in place (assumes it is non-null) */ -int IsMat4Orthogonal(float mat[][4]); -void Mat4Orthogonal(float mat[][4], int axis); /* axis is the one to keep in place (assumes it is non-null) */ - -void VecMat4MulVecfl(float *in, float mat[][4], float *vec); -void Mat4MulMat43(float (*m1)[4], float (*m3)[4], float (*m2)[3]); -void Mat3IsMat3MulMat4(float m1[][3], float m2[][3], float m3[][4]); - -void Mat4MulVec(float mat[][4],int *vec); -void Mat4MulVecfl(float mat[][4], float *vec); -void Mat4Mul3Vecfl(float mat[][4], float *vec); -void Mat4MulVec3Project(float mat[][4],float *vec); -void Mat4MulVec4fl(float mat[][4], float *vec); -void Mat3MulVec(float mat[][3],int *vec); -void Mat3MulVecfl(float mat[][3], float *vec); -void Mat3MulVecd(float mat[][3], double *vec); -void Mat3TransMulVecfl(float mat[][3], float *vec); - -void Mat3AddMat3(float m1[][3], float m2[][3], float m3[][3]); -void Mat4AddMat4(float m1[][4], float m2[][4], float m3[][4]); - -void VecUpMat3old(float *vec, float mat[][3], short axis); -void VecUpMat3(float *vec, float mat[][3], short axis); - -void VecCopyf(float *v1, float *v2); -int VecLen(int *v1, int *v2); -float VecLenf(float v1[3], float v2[3]); -float VecLength(float *v); -void VecMulf(float *v1, float f); -void VecNegf(float *v1); - -int VecLenCompare(float *v1, float *v2, float limit); -int VecCompare(float *v1, float *v2, float limit); -int VecEqual(float *v1, float *v2); -int VecIsNull(float *v); - -void printvecf(char *str,float v[3]); -void printvec4f(char *str, float v[4]); - -void VecAddf(float *v, float *v1, float *v2); -void VecSubf(float *v, float *v1, float *v2); -void VecMulVecf(float *v, float *v1, float *v2); -void VecLerpf(float *target, const float *a, const float *b, const float t); -void VecLerp3f(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3]); -void VecMidf(float *v, float *v1, float *v2); - -void VecOrthoBasisf(float *v, float *v1, float *v2); - -float Vec2Lenf(float *v1, float *v2); -float Vec2Length(float *v); -void Vec2Mulf(float *v1, float f); -void Vec2Addf(float *v, float *v1, float *v2); -void Vec2Subf(float *v, float *v1, float *v2); -void Vec2Copyf(float *v1, float *v2); -void Vec2Lerpf(float *target, const float *a, const float *b, const float t); -void Vec2Lerp3f(float p[2], const float v1[2], const float v2[2], const float v3[2], const float w[3]); - -void AxisAngleToQuat(float q[4], float axis[3], float angle); -void QuatToAxisAngle(float q[4], float axis[3], float *angle); -void AxisAngleToEulO(float axis[3], float angle, float eul[3], short order); -void EulOToAxisAngle(float eul[3], short order, float axis[3], float *angle); -void AxisAngleToMat3(float axis[3], float angle, float mat[3][3]); -void AxisAngleToMat4(float axis[3], float angle, float mat[4][4]); -void Mat3ToAxisAngle(float mat[3][3], float axis[3], float *angle); -void Mat4ToAxisAngle(float mat[4][4], float axis[3], float *angle); - -void Mat3ToVecRot(float mat[3][3], float axis[3], float *angle); -void Mat4ToVecRot(float mat[4][4], float axis[3], float *angle); -void VecRotToMat3(float *vec, float phi, float mat[][3]); -void VecRotToMat4(float *vec, float phi, float mat[][4]); - -void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]); -void vectoquat(float *vec, short axis, short upflag, float *q); -void Mat3ToQuat_is_ok(float wmat[][3], float *q); - -void VecReflect(float *out, float *v1, float *v2); -void VecBisect3(float *v, float *v1, float *v2, float *v3); -float VecAngle2(float *v1, float *v2); -float VecAngle3(float *v1, float *v2, float *v3); -float NormalizedVecAngle2(float *v1, float *v2); - -float Vec2Angle3(float *v1, float *v2, float *v3); -float NormalizedVecAngle2_2D(float *v1, float *v2); - -void NormalShortToFloat(float *out, short *in); -void NormalFloatToShort(short *out, float *in); - -float DistVL2Dfl(float *v1, float *v2, float *v3); -float PdistVL2Dfl(float *v1, float *v2, float *v3); -float PdistVL3Dfl(float *v1, float *v2, float *v3); -void PclosestVL3Dfl(float *closest, float v1[3], float v2[3], float v3[3]); -float AreaF2Dfl(float *v1, float *v2, float *v3); -float AreaQ3Dfl(float *v1, float *v2, float *v3, float *v4); -float AreaT3Dfl(float *v1, float *v2, float *v3); -float AreaPoly3Dfl(int nr, float *verts, float *normal); - -/* intersect Line-Line - return: - -1: colliniar - 0: no intersection of segments - 1: exact intersection of segments - 2: cross-intersection of segments -*/ -extern short IsectLL2Df(float *v1, float *v2, float *v3, float *v4); -extern short IsectLL2Ds(short *v1, short *v2, short *v3, short *v4); - -/*point in tri, 0 no intersection, 1 intersect */ -int IsectPT2Df(float pt[2], float v1[2], float v2[2], float v3[2]); -/* point in quad, 0 no intersection, 1 intersect */ -int IsectPQ2Df(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2]); - -/* interpolation weights of point in a triangle or quad, v4 may be NULL */ -void InterpWeightsQ3Dfl(float *v1, float *v2, float *v3, float *v4, float *co, float *w); -/* interpolation weights of point in a polygon with >= 3 vertices */ -void MeanValueWeights(float v[][3], int n, float *co, float *w); - -void i_lookat( - float vx, float vy, - float vz, float px, - float py, float pz, - float twist, float mat[][4] -); - -void i_window( - float left, float right, - float bottom, float top, - float nearClip, float farClip, - float mat[][4] -); - -#define BLI_CS_SMPTE 0 -#define BLI_CS_REC709 1 -#define BLI_CS_CIE 2 - -#define RAD2DEG(_rad) ((_rad)*(180.0/M_PI)) -#define DEG2RAD(_deg) ((_deg)*(M_PI/180.0)) - -void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b); -void hex_to_rgb(char *hexcol, float *r, float *g, float *b); -void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv); -void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb); -void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb); -void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr); -void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv); -void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace); -int constrain_rgb(float *r, float *g, float *b); -unsigned int hsv_to_cpack(float h, float s, float v); -unsigned int rgb_to_cpack(float r, float g, float b); -void cpack_to_rgb(unsigned int col, float *r, float *g, float *b); -void MinMaxRGB(short c[]); - - - -void VecStar(float mat[][3],float *vec); - -short EenheidsMat(float mat[][3]); - -void i_ortho(float left, float right, float bottom, float top, float nearClip, float farClip, float matrix[][4]); -void i_polarview(float dist, float azimuth, float incidence, float twist, float Vm[][4]); -void i_translate(float Tx, float Ty, float Tz, float mat[][4]); -void i_multmatrix(float icand[][4], float Vm[][4]); -void i_rotate(float angle, char axis, float mat[][4]); - - - -void MinMax3(float *min, float *max, float *vec); -void SizeToMat3(float *size, float mat[][3]); -void SizeToMat4(float *size, float mat[][4]); - -float Mat3ToScalef(float mat[][3]); -float Mat4ToScalef(float mat[][4]); - -void printmatrix3(char *str, float m[][3]); -void printmatrix4(char *str, float m[][4]); - -/* uit Sig.Proc.85 pag 253 */ -void Mat3ToQuat(float wmat[][3], float *q); -void Mat4ToQuat(float m[][4], float *q); - -void Mat3ToSize(float mat[][3], float *size); -void Mat4ToSize(float mat[][4], float *size); - -void triatoquat(float *v1, float *v2, float *v3, float *quat); - -void LocEulSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3]); -void LocEulOSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder); -void LocQuatSizeToMat4(float mat[4][4], float loc[3], float quat[4], float size[3]); - -void tubemap(float x, float y, float z, float *u, float *v); -void spheremap(float x, float y, float z, float *u, float *v); - -int LineIntersectLine(float v1[3], float v2[3], float v3[3], float v4[3], float i1[3], float i2[3]); -int LineIntersectLineStrict(float v1[3], float v2[3], float v3[3], float v4[3], float vi[3], float *lambda); -int LineIntersectsTriangle(float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv); -int RayIntersectsTriangle(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv); -int RayIntersectsTriangleThreshold(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold); -int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint); -int AxialLineIntersectsTriangle(int axis, float co1[3], float co2[3], float v0[3], float v1[3], float v2[3], float *lambda); -int AabbIntersectAabb(float min1[3], float max1[3], float min2[3], float max2[3]); -void VecfCubicInterpol(float *x1, float *v1, float *x2, float *v2, float t, float *x, float *v); -void PointInQuad2DUV(float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv); -void PointInFace2DUV(int isquad, float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv); -int IsPointInTri2D(float v1[2], float v2[2], float v3[2], float pt[2]); -int IsPointInTri2DInts(int x1, int y1, int x2, int y2, int a, int b); -int point_in_tri_prism(float p[3], float v1[3], float v2[3], float v3[3]); - -float lambda_cp_line_ex(float p[3], float l1[3], float l2[3], float cp[3]); - -float AngleToLength(const float angle); - -typedef struct DualQuat { - float quat[4]; - float trans[4]; - - float scale[4][4]; - float scale_weight; -} DualQuat; - -void Mat4ToDQuat(float basemat[][4], float mat[][4], DualQuat *dq); -void DQuatToMat4(DualQuat *dq, float mat[][4]); -void DQuatAddWeighted(DualQuat *dqsum, DualQuat *dq, float weight); -void DQuatNormalize(DualQuat *dq, float totweight); -void DQuatMulVecfl(DualQuat *dq, float *co, float mat[][3]); -void DQuatCpyDQuat(DualQuat *dq1, DualQuat *dq2); - -/* Tangent stuff */ -typedef struct VertexTangent { - float tang[3], uv[2]; - struct VertexTangent *next; -} VertexTangent; - -void sum_or_add_vertex_tangent(void *arena, VertexTangent **vtang, float *tang, float *uv); -float *find_vertex_tangent(VertexTangent *vtang, float *uv); -void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2, float *co3, float *n, float *tang); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/source/blender/blenlib/BLI_math.h b/source/blender/blenlib/BLI_math.h new file mode 100644 index 00000000000..b1917bc27b7 --- /dev/null +++ b/source/blender/blenlib/BLI_math.h @@ -0,0 +1,64 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH +#define BLI_MATH + +/* Abbreviations: + * + * fl = float + * db = double + * v2 = vec2 = vector 2 + * v3 = vec3 = vector 3 + * v4 = vec4 = vector 4 + * qt = quat = quaternion + * dq = dquat = dual quaternion + * m2 = mat2 = matrix 2x2 + * m3 = mat3 = matrix 3x3 + * m4 = mat4 = matrix 4x4 + * eul = euler rotation + * eulO = euler with order + * + * Variable Names: + * + * f = single value + * a, b, c = vectors + * r = result vector + * A, B, C = matrices + * R = result matrix + * + */ + +#include "BLI_math_base.h" +#include "BLI_math_color.h" +#include "BLI_math_geom.h" +#include "BLI_math_matrix.h" +#include "BLI_math_rotation.h" +#include "BLI_math_vector.h" + +#endif /* BLI_MATH */ + diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h new file mode 100644 index 00000000000..4e845ae35d9 --- /dev/null +++ b/source/blender/blenlib/BLI_math_base.h @@ -0,0 +1,156 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH_BASE +#define BLI_MATH_BASE + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef WIN32 +#define _USE_MATH_DEFINES +#endif + +#include <math.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 +#endif +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 +#endif +#ifndef M_SQRT1_2 +#define M_SQRT1_2 0.70710678118654752440 +#endif +#ifndef M_1_PI +#define M_1_PI 0.318309886183790671538 +#endif +#ifndef M_E +#define M_E 2.7182818284590452354 +#endif +#ifndef M_LOG2E +#define M_LOG2E 1.4426950408889634074 +#endif +#ifndef M_LOG10E +#define M_LOG10E 0.43429448190325182765 +#endif +#ifndef M_LN2 +#define M_LN2 0.69314718055994530942 +#endif +#ifndef M_LN10 +#define M_LN10 2.30258509299404568402 +#endif + +#ifndef sqrtf +#define sqrtf(a) ((float)sqrt(a)) +#endif +#ifndef powf +#define powf(a, b) ((float)pow(a, b)) +#endif +#ifndef cosf +#define cosf(a) ((float)cos(a)) +#endif +#ifndef sinf +#define sinf(a) ((float)sin(a)) +#endif +#ifndef acosf +#define acosf(a) ((float)acos(a)) +#endif +#ifndef asinf +#define asinf(a) ((float)asin(a)) +#endif +#ifndef atan2f +#define atan2f(a, b) ((float)atan2(a, b)) +#endif +#ifndef tanf +#define tanf(a) ((float)tan(a)) +#endif +#ifndef atanf +#define atanf(a) ((float)atan(a)) +#endif +#ifndef floorf +#define floorf(a) ((float)floor(a)) +#endif +#ifndef ceilf +#define ceilf(a) ((float)ceil(a)) +#endif +#ifndef fabsf +#define fabsf(a) ((float)fabs(a)) +#endif +#ifndef logf +#define logf(a) ((float)log(a)) +#endif +#ifndef expf +#define expf(a) ((float)exp(a)) +#endif +#ifndef fmodf +#define fmodf(a, b) ((float)fmod(a, b)) +#endif + +#ifdef WIN32 +#ifndef FREE_WINDOWS +#define isnan(n) _isnan(n) +#define finite _finite +#endif +#endif + +#ifndef SWAP +#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } +#endif + +#ifndef CLAMP +#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c) +#endif + +/******************************* Float ******************************/ + +float sqrt3f(float f); +double sqrt3d(double d); + +float saacosf(float f); +float saasinf(float f); +float sasqrtf(float f); +float saacos(float fac); +float saasin(float fac); +float sasqrt(float fac); + +float interpf(float a, float b, float t); + +float power_of_2(float f); + +float shell_angle_to_dist(float angle); + +#ifdef __cplusplus +} +#endif + +#endif /* BLI_MATH_BASE */ + diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h new file mode 100644 index 00000000000..b2d14f3ecbd --- /dev/null +++ b/source/blender/blenlib/BLI_math_color.h @@ -0,0 +1,66 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH_COLOR +#define BLI_MATH_COLOR + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLI_CS_SMPTE 0 +#define BLI_CS_REC709 1 +#define BLI_CS_CIE 2 + +/******************* Conversion to RGB ********************/ + +void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b); +void hex_to_rgb(char *hexcol, float *r, float *g, float *b); +void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb); +void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb); +void xyz_to_rgb(float x, float y, float z, float *r, float *g, float *b, int colorspace); +void cpack_to_rgb(unsigned int col, float *r, float *g, float *b); + +/***************** Conversion from RGB ********************/ + +void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv); +void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr); +void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv); +unsigned int rgb_to_cpack(float r, float g, float b); +unsigned int hsv_to_cpack(float h, float s, float v); + +/************************** Other *************************/ + +int constrain_rgb(float *r, float *g, float *b); +void minmax_rgb(short c[3]); + +#ifdef __cplusplus +} +#endif + +#endif /* BLI_MATH_COLOR */ + diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h new file mode 100644 index 00000000000..d54be9d5e03 --- /dev/null +++ b/source/blender/blenlib/BLI_math_geom.h @@ -0,0 +1,156 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH_GEOM +#define BLI_MATH_GEOM + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************** Polygons *********************************/ + +void cent_tri_v3(float r[3], float a[3], float b[3], float c[3]); +void cent_quad_v3(float r[3], float a[3], float b[3], float c[3], float d[3]); + +float normal_tri_v3(float r[3], float a[3], float b[3], float c[3]); +float normal_quad_v3(float r[3], float a[3], float b[3], float c[3], float d[3]); + +float area_tri_v2(float a[2], float b[2], float c[2]); +float area_tri_v3(float a[3], float b[3], float c[3]); +float area_quad_v3(float a[3], float b[3], float c[3], float d[3]); +float area_poly_v3(int nr, float verts[][3], float normal[3]); + +/********************************* Distance **********************************/ + +float dist_to_line_v2(float p[2], float l1[2], float l2[2]); +float dist_to_line_segment_v2(float p[2], float l1[2], float l2[2]); + +float dist_to_line_segment_v3(float p[3], float l1[3], float l2[3]); +float closest_to_line_v3(float r[3], float p[3], float l1[3], float l2[3]); +void closest_to_line_segment_v3(float r[3], float p[3], float l1[3], float l2[3]); + +/******************************* Intersection ********************************/ + +/* TODO int return value consistency */ + +/* line-line */ +#define ISECT_LINE_LINE_COLINEAR -1 +#define ISECT_LINE_LINE_NONE 0 +#define ISECT_LINE_LINE_EXACT 1 +#define ISECT_LINE_LINE_CROSS 2 + +int isect_line_line_v2(float a1[2], float a2[2], float b1[2], float b2[2]); +int isect_line_line_v2_short(short a1[2], short a2[2], short b1[2], short b2[2]); + +/* Returns the number of point of interests + * 0 - lines are colinear + * 1 - lines are coplanar, i1 is set to intersection + * 2 - i1 and i2 are the nearest points on line 1 (v1, v2) and line 2 (v3, v4) respectively + * */ + +int isect_line_line_v3(float v1[3], float v2[3], + float v3[3], float v4[3], float i1[3], float i2[3]); +int isect_line_line_strict_v3(float v1[3], float v2[3], + float v3[3], float v4[3], float vi[3], float *lambda); + +/* line/ray triangle */ +int isect_line_tri_v3(float p1[3], float p2[3], + float v0[3], float v1[3], float v2[3], float *lambda, float *uv); +int isect_ray_tri_v3(float p1[3], float d[3], + float v0[3], float v1[3], float v2[3], float *lambda, float *uv); +int isect_ray_tri_threshold_v3(float p1[3], float d[3], + float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold); + +/* point in polygon */ +int isect_point_tri_v2(float p[2], float a[2], float b[2], float c[2]); +int isect_point_quad_v2(float p[2], float a[2], float b[2], float c[2], float d[2]); + +int isect_point_tri_v2(float v1[2], float v2[2], float v3[2], float pt[2]); +int isect_point_tri_v2_int(int x1, int y1, int x2, int y2, int a, int b); +int isect_point_tri_prism_v3(float p[3], float v1[3], float v2[3], float v3[3]); + +void isect_point_quad_uv_v2(float v0[2], float v1[2], float v2[2], float v3[2], + float pt[2], float *uv); +void isect_point_face_uv_v2(int isquad, float v0[2], float v1[2], float v2[2], + float v3[2], float pt[2], float *uv); + +/* other */ +int isect_sweeping_sphere_tri_v3(float p1[3], float p2[3], float radius, + float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint); + +int isect_axial_line_tri_v3(int axis, float co1[3], float co2[3], + float v0[3], float v1[3], float v2[3], float *lambda); + +int isect_aabb_aabb_v3(float min1[3], float max1[3], float min2[3], float max2[3]); + +/****************************** Interpolation ********************************/ + +/* tri or quad, d can be NULL */ +void interp_weights_face_v3(float w[4], + float a[3], float b[3], float c[3], float d[3], float p[3]); +void interp_weights_poly_v3(float w[], float v[][3], int n, float p[3]); + +void interp_cubic_v3(float x[3], float v[3], + float x1[3], float v1[3], float x2[3], float v2[3], float t); + +/***************************** View & Projection *****************************/ + +void lookat_m4(float mat[4][4], float vx, float vy, + float vz, float px, float py, float pz, float twist); +void polarview_m4(float mat[4][4], float dist, float azimuth, + float incidence, float twist); + +void perspective_m4(float mat[4][4], float left, float right, + float bottom, float top, float nearClip, float farClip); +void orthographic_m4(float mat[4][4], float left, float right, + float bottom, float top, float nearClip, float farClip); + +/********************************** Mapping **********************************/ + +void map_to_tube(float *u, float *v, float x, float y, float z); +void map_to_sphere(float *u, float *v, float x, float y, float z); + +/********************************* Tangents **********************************/ + +typedef struct VertexTangent { + float tang[3], uv[2]; + struct VertexTangent *next; +} VertexTangent; + +float *find_vertex_tangent(VertexTangent *vtang, float *uv); +void sum_or_add_vertex_tangent(void *arena, VertexTangent **vtang, + float *tang, float *uv); +void tangent_from_uv(float *uv1, float *uv2, float *uv3, + float *co1, float *co2, float *co3, float *n, float *tang); + +#ifdef __cplusplus +} +#endif + +#endif /* BLI_MATH_GEOM */ + diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h new file mode 100644 index 00000000000..53476e4d03c --- /dev/null +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -0,0 +1,160 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH_MATRIX +#define BLI_MATH_MATRIX + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************* Init **************************************/ + +#define MAT4_UNITY {{ 1.0, 0.0, 0.0, 0.0},\ + { 0.0, 1.0, 0.0, 0.0},\ + { 0.0, 0.0, 1.0, 0.0},\ + { 0.0, 0.0, 0.0, 1.0}} + +#define MAT3_UNITY {{ 1.0, 0.0, 0.0},\ + { 0.0, 1.0, 0.0},\ + { 0.0, 0.0, 1.0}} + +void zero_m3(float R[3][3]); +void zero_m4(float R[4][4]); + +void unit_m3(float R[3][3]); +void unit_m4(float R[4][4]); + +void copy_m3_m3(float R[3][3], float A[3][3]); +void copy_m4_m4(float R[4][4], float A[4][4]); +void copy_m3_m4(float R[3][3], float A[4][4]); +void copy_m4_m3(float R[4][4], float A[3][3]); + +void swap_m3m3(float A[3][3], float B[3][3]); +void swap_m4m4(float A[4][4], float B[4][4]); + +/******************************** Arithmetic *********************************/ + +void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]); +void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]); + +void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]); +void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]); +void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]); +void mul_m4_m4m3(float R[4][4], float A[4][4], float B[3][3]); +void mul_m3_m3m4(float R[3][3], float A[3][3], float B[4][4]); + +void mul_serie_m3(float R[3][3], + float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3], + float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]); +void mul_serie_m4(float R[4][4], + float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4], + float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]); + +void mul_m4_v3(float M[4][4], float r[3]); +void mul_v3_m4v3(float r[3], float M[4][4], float v[3]); +void mul_mat3_m4_v3(float M[4][4], float r[3]); +void mul_m4_v4(float M[4][4], float r[3]); +void mul_project_m4_v4(float M[4][4], float r[3]); + +void mul_m3_v3(float M[3][3], float r[3]); +void mul_transposed_m3_v3(float M[3][3], float r[3]); +void mul_m3_v3_double(float M[3][3], double r[3]); + +void mul_m3_fl(float R[3][3], float f); +void mul_m4_fl(float R[4][4], float f); +void mul_mat3_m4_fl(float R[4][4], float f); + +int invert_m3(float R[3][3]); +int invert_m3_m3(float R[3][3], float A[3][3]); +int invert_m4(float R[4][4]); +int invert_m4_m4(float R[4][4], float A[4][4]); + +/****************************** Linear Algebra *******************************/ + +void transpose_m3(float R[3][3]); +void transpose_m4(float R[4][4]); + +void normalize_m3(float R[3][3]); +void normalize_m4(float R[4][4]); + +void orthogonalize_m3(float R[3][3], int axis); +void orthogonalize_m4(float R[4][4], int axis); + +int is_orthogonal_m3(float mat[3][3]); +int is_orthogonal_m4(float mat[4][4]); + +void adjoint_m3_m3(float R[3][3], float A[3][3]); +void adjoint_m4_m4(float R[4][4], float A[4][4]); + +float determinant_m2( + float a, float b, + float c, float d); +float determinant_m3( + float a, float b, float c, + float d, float e, float f, + float g, float h, float i); +float determinant_m4(float A[4][4]); + +/****************************** Transformations ******************************/ + +void scale_m3_fl(float R[3][3], float scale); +void scale_m4_fl(float R[4][4], float scale); + +float mat3_to_scale(float M[3][3]); +float mat4_to_scale(float M[4][4]); + +void size_to_mat3(float R[3][3], float size[3]); +void size_to_mat4(float R[4][4], float size[3]); + +void mat3_to_size(float r[3], float M[3][3]); +void mat4_to_size(float r[3], float M[4][4]); + +void translate_m4(float mat[4][4], float tx, float ty, float tz); +void rotate_m4(float mat[4][4], char axis, float angle); + +void loc_eul_size_to_mat4(float R[4][4], + float loc[3], float eul[3], float size[3]); +void loc_eulO_size_to_mat4(float R[4][4], + float loc[3], float eul[3], float size[3], short order); +void loc_quat_size_to_mat4(float R[4][4], + float loc[3], float quat[4], float size[3]); + +void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], float t); +void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], float t); + +/*********************************** Other ***********************************/ + +void print_m3(char *str, float M[3][3]); +void print_m4(char *str, float M[3][4]); + +#ifdef __cplusplus +} +#endif + +#endif /* BLI_MATH_MATRIX */ + diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h new file mode 100644 index 00000000000..b221d89487f --- /dev/null +++ b/source/blender/blenlib/BLI_math_rotation.h @@ -0,0 +1,173 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH_ROTATION +#define BLI_MATH_ROTATION + +#ifdef __cplusplus +extern "C" { +#endif + +#define RAD2DEG(_rad) ((_rad)*(180.0/M_PI)) +#define DEG2RAD(_deg) ((_deg)*(M_PI/180.0)) + +/******************************** Quaternions ********************************/ +/* stored in (w, x, y, z) order */ + +/* init */ +void unit_qt(float q[4]); +void copy_qt_qt(float q[4], float a[4]); + +/* arithmetic */ +void mul_qt_qtqt(float q[4], float a[4], float b[4]); +void mul_qt_v3(float q[4], float r[3]); +void mul_qt_fl(float q[4], float f); +void mul_fac_qt_fl(float q[4], float f); + +void sub_qt_qtqt(float q[4], float a[4], float b[4]); + +void invert_qt(float q[4]); +void conjugate_qt(float q[4]); +float dot_qtqt(float a[4], float b[4]); +void normalize_qt(float q[4]); + +/* comparison */ +int is_zero_qt(float q[4]); + +/* interpolation */ +void interp_qt_qtqt(float q[4], float a[4], float b[4], float t); +void add_qt_qtqt(float q[4], float a[4], float b[4], float t); + +/* conversion */ +void quat_to_mat3(float mat[3][3], float q[4]); +void quat_to_mat4(float mat[4][4], float q[4]); + +void mat3_to_quat(float q[4], float mat[3][3]); +void mat4_to_quat(float q[4], float mat[4][4]); +void tri_to_quat(float q[4], float a[3], float b[3], float c[3]); +void vec_to_quat(float q[4], float vec[3], short axis, short upflag); +void rotation_between_vecs_to_quat(float q[4], float v1[3], float v2[3]); + +/* TODO: don't what this is, but it's not the same as mat3_to_quat */ +void mat3_to_quat_is_ok(float q[4], float mat[3][3]); + +/* other */ +void print_qt(char *str, float q[4]); + +/******************************** Axis Angle *********************************/ + +/* conversion */ +void axis_angle_to_quat(float r[4], float axis[3], float angle); +void axis_angle_to_mat3(float R[3][3], float axis[3], float angle); +void axis_angle_to_mat4(float R[4][4], float axis[3], float angle); + +void quat_to_axis_angle(float axis[3], float *angle, float q[4]); +void mat3_to_axis_angle(float axis[3], float *angle, float M[3][3]); +void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]); + +/****************************** Vector/Rotation ******************************/ +/* old axis angle code */ +/* TODO: the following calls should probably be depreceated sometime */ + +/* conversion */ +void mat3_to_vec_rot(float vec[3], float *phi, float mat[3][3]); +void mat4_to_vec_rot(float vec[3], float *phi, float mat[4][4]); + +void vec_rot_to_quat(float quat[4], float vec[3], float phi); +void vec_rot_to_mat3(float mat[3][3], float vec[3], float phi); +void vec_rot_to_mat4(float mat[4][4], float vec[3], float phi); + +/******************************** XYZ Eulers *********************************/ + +void eul_to_quat(float quat[4], float eul[3]); +void eul_to_mat3(float mat[3][3], float eul[3]); +void eul_to_mat4(float mat[4][4], float eul[3]); + +void quat_to_eul(float eul[3], float quat[4]); +void mat3_to_eul(float eul[3], float mat[3][3]); +void mat4_to_eul(float eul[3], float mat[4][4]); + +void compatible_eul(float eul[3], float old[3]); +void mat3_to_compatible_eul(float eul[3], float old[3], float mat[3][3]); + +void rotate_eul(float eul[3], char axis, float angle); + +/************************** Arbitrary Order Eulers ***************************/ + +/* warning: must match the eRotationModes in DNA_action_types.h + * order matters - types are saved to file. */ + +typedef enum eEulerRotationOrders { + EULER_ORDER_DEFAULT = 1, /* blender classic = XYZ */ + EULER_ORDER_XYZ = 1, + EULER_ORDER_XZY, + EULER_ORDER_YXZ, + EULER_ORDER_YZX, + EULER_ORDER_ZXY, + EULER_ORDER_ZYX, + /* there are 6 more entries with dulpicate entries included */ +} eEulerRotationOrders; + +void eulO_to_quat(float quat[4], float eul[3], short order); +void eulO_to_mat3(float mat[3][3], float eul[3], short order); +void eulO_to_mat4(float mat[4][4], float eul[3], short order); +void eulO_to_axis_angle(float axis[3], float *angle, float eul[3], short order); +void eulO_to_gimbal_axis(float gmat[3][3], float eul[3], short order); + +void quat_to_eulO(float eul[3], short order, float quat[4]); +void mat3_to_eulO(float eul[3], short order, float mat[3][3]); +void mat4_to_eulO(float eul[3], short order, float mat[4][4]); +void axis_angle_to_eulO(float eul[3], short order, float axis[3], float angle); + +void mat3_to_compatible_eulO(float eul[3], float old[3], short order, float mat[3][3]); + +void rotate_eulO(float eul[3], short order, char axis, float angle); + +/******************************* Dual Quaternions ****************************/ + +typedef struct DualQuat { + float quat[4]; + float trans[4]; + + float scale[4][4]; + float scale_weight; +} DualQuat; + +void copy_dq_dq(DualQuat *r, DualQuat *dq); +void normalize_dq(DualQuat *dq, float totw); +void add_weighted_dq_dq(DualQuat *r, DualQuat *dq, float weight); +void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq); + +void mat4_to_dquat(DualQuat *r, float base[4][4], float M[4][4]); +void dquat_to_mat4(float R[4][4], DualQuat *dq); + +#ifdef __cplusplus +} +#endif + +#endif /* BLI_MATH_ROTATION */ + diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h new file mode 100644 index 00000000000..26602353425 --- /dev/null +++ b/source/blender/blenlib/BLI_math_vector.h @@ -0,0 +1,149 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#ifndef BLI_MATH_VECTOR +#define BLI_MATH_VECTOR + +#ifdef __cplusplus +extern "C" { +#endif + +/* add platform/compiler checks here if it is not supported */ +#define BLI_MATH_INLINE + +#ifdef BLI_MATH_INLINE +#ifdef _MSC_VER +#define MINLINE static __inline +#else +#define MINLINE static inline +#endif +#include "intern/math_vector_inline.c" +#else +#define MINLINE +#endif + +/************************************* Init ***********************************/ + +MINLINE void zero_v2(float r[2]); +MINLINE void zero_v3(float r[3]); + +MINLINE void copy_v2_v2(float r[2], float a[2]); +MINLINE void copy_v3_v3(float r[3], float a[3]); + +/********************************* Arithmetic ********************************/ + +MINLINE void add_v2_v2(float r[2], float a[2]); +MINLINE void add_v2_v2v2(float r[2], float a[2], float b[2]); +MINLINE void add_v3_v3(float r[3], float a[3]); +MINLINE void add_v3_v3v3(float r[3], float a[3], float b[3]); + +MINLINE void sub_v2_v2(float r[2], float a[2]); +MINLINE void sub_v2_v2v2(float r[2], float a[2], float b[2]); +MINLINE void sub_v3_v3(float r[3], float a[3]); +MINLINE void sub_v3_v3v3(float r[3], float a[3], float b[3]); + +MINLINE void mul_v2_fl(float r[2], float f); +MINLINE void mul_v3_fl(float r[3], float f); +MINLINE void mul_v3_v3fl(float r[3], float a[3], float f); +MINLINE void mul_v3_v3(float r[3], float a[3]); +MINLINE void mul_v3_v3v3(float r[3], float a[3], float b[3]); + +MINLINE void negate_v3(float r[3]); +MINLINE void negate_v3_v3(float r[3], float a[3]); + +MINLINE float dot_v2v2(float a[2], float b[2]); +MINLINE float dot_v3v3(float a[3], float b[3]); + +MINLINE float cross_v2v2(float a[2], float b[2]); +MINLINE void cross_v3_v3v3(float r[3], float a[3], float b[3]); + +MINLINE void star_m3_v3(float R[3][3],float a[3]); + +/*********************************** Length **********************************/ + +MINLINE float len_v2(float a[2]); +MINLINE float len_v2v2(float a[2], float b[2]); +MINLINE float len_v3(float a[3]); +MINLINE float len_v3v3(float a[3], float b[3]); + +MINLINE float normalize_v2(float r[2]); +MINLINE float normalize_v3(float r[3]); + +/******************************* Interpolation *******************************/ + +void interp_v2_v2v2(float r[2], float a[2], float b[2], float t); +void interp_v2_v2v2v2(float r[2], float a[2], float b[2], float c[3], float t[3]); +void interp_v3_v3v3(float r[3], float a[3], float b[3], float t); +void interp_v3_v3v3v3(float p[3], float v1[3], float v2[3], float v3[3], float w[3]); + +void mid_v3_v3v3(float r[3], float a[3], float b[3]); + +/********************************* Comparison ********************************/ + +int is_zero_v3(float a[3]); +int equals_v3v3(float a[3], float b[3]); +int compare_v3v3(float a[3], float b[3], float limit); +int compare_len_v3v3(float a[3], float b[3], float limit); + +int compare_v4v4(float a[4], float b[4], float limit); + +/********************************** Angles ***********************************/ +/* - angle with 2 arguments is angle between vector */ +/* - angle with 3 arguments is angle between 3 points at the middle point */ +/* - angle_normalized_* is faster equivalent if vectors are normalized */ + +float angle_v2v2(float a[2], float b[2]); +float angle_v2v2v2(float a[2], float b[2], float c[2]); +float angle_normalized_v2v2(float a[2], float b[2]); +float angle_v3v3(float a[2], float b[2]); +float angle_v3v3v3(float a[2], float b[2], float c[2]); +float angle_normalized_v3v3(float a[3], float b[3]); + +/********************************* Geometry **********************************/ + +void project_v3_v3v3(float r[3], float p[3], float n[3]); +void reflect_v3_v3v3(float r[3], float v[3], float n[3]); +void ortho_basis_v3v3_v3(float r1[3], float r2[3], float a[3]); +void bisect_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]); + +/*********************************** Other ***********************************/ + +void print_v2(char *str, float a[2]); +void print_v3(char *str, float a[3]); +void print_v4(char *str, float a[4]); + +void normal_short_to_float_v3(float r[3], short n[3]); +void normal_float_to_short_v3(short r[3], float n[3]); + +void minmax_v3_v3v3(float r[3], float min[3], float max[3]); + +#ifdef __cplusplus +} +#endif + +#endif /* BLI_MATH_VECTOR */ + diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index eea49254a0e..3f4b9fbae25 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -37,7 +37,7 @@ #include "BKE_utildefines.h" #include "BLI_kdopbvh.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #ifdef _OPENMP #include <omp.h> @@ -332,10 +332,12 @@ static void sort(BVHNode **a0, int begin, int end, int axis) bvh_insertionsort(a, begin, end, axis); } } +#if 0 static void sort_along_axis(BVHTree *tree, int start, int end, int axis) { sort(tree->nodes, start, end, axis); } +#endif //after a call to this function you can expect one of: // every node to left of a[n] are smaller or equal to it @@ -1532,6 +1534,7 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) } } +#if 0 static void iterative_raycast(BVHRayCastData *data, BVHNode *node) { while(node) @@ -1562,6 +1565,7 @@ static void iterative_raycast(BVHRayCastData *data, BVHNode *node) } } } +#endif int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata) { @@ -1578,7 +1582,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float *co, const float *dir, float VECCOPY(data.ray.direction, dir); data.ray.radius = radius; - Normalize(data.ray.direction); + normalize_v3(data.ray.direction); for(i=0; i<3; i++) { @@ -1635,7 +1639,7 @@ float BLI_bvhtree_bb_raycast(float *bv, float *light_start, float *light_end, fl data.ray.origin[1] = light_start[1]; data.ray.origin[2] = light_start[2]; - Normalize(data.ray.direction); + normalize_v3(data.ray.direction); VECCOPY(data.ray_dot_axis, data.ray.direction); dist = ray_nearest_hit(&data, bv); diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c index ccf79ed42dc..abf61bfb734 100644 --- a/source/blender/blenlib/intern/BLI_kdtree.c +++ b/source/blender/blenlib/intern/BLI_kdtree.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_kdtree.h" #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } @@ -76,8 +76,8 @@ void BLI_kdtree_insert(KDTree *tree, int index, float *co, float *nor) KDTreeNode *node= &tree->nodes[tree->totnode++]; node->index= index; - VecCopyf(node->co, co); - if(nor) VecCopyf(node->nor, nor); + copy_v3_v3(node->co, co); + if(nor) copy_v3_v3(node->nor, nor); } static KDTreeNode *kdtree_balance(KDTreeNode *nodes, int totnode, int axis) @@ -225,7 +225,7 @@ int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest * if(nearest) { nearest->index= min_node->index; nearest->dist= sqrt(min_dist); - VecCopyf(nearest->co, min_node->co); + copy_v3_v3(nearest->co, min_node->co); } if(stack != defaultstack) @@ -249,7 +249,7 @@ static void add_nearest(KDTreeNearest *ptn, int *found, int n, int index, float ptn[i].index= index; ptn[i].dist= dist; - VecCopyf(ptn[i].co, co); + copy_v3_v3(ptn[i].co, co); } /* finds the nearest n entries in tree to specified coordinates */ @@ -366,7 +366,7 @@ static void add_in_range(KDTreeNearest **ptn, int found, int *totfoundstack, int to->index = index; to->dist = sqrt(dist); - VecCopyf(to->co, co); + copy_v3_v3(to->co, co); } int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KDTreeNearest **nearest) { diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c deleted file mode 100644 index 874756135e5..00000000000 --- a/source/blender/blenlib/intern/arithb.c +++ /dev/null @@ -1,5488 +0,0 @@ -/* arithb.c - * - * simple math for blender code - * - * sort of cleaned up mar-01 nzc - * - * $Id$ - * - * ***** BEGIN GPL 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. - * - * 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 LICENSE BLOCK ***** - */ - -/* ************************ FUNKTIES **************************** */ - -#include <stdlib.h> -#include <math.h> -#include <sys/types.h> -#include <string.h> -#include <float.h> - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#if defined(__sun__) || defined( __sun ) || defined (__sparc) || defined (__sparc__) -#include <strings.h> -#endif - -#if !defined(__sgi) && !defined(WIN32) -#include <sys/time.h> -#include <unistd.h> -#endif - -#include <stdio.h> -#include "BLI_arithb.h" -#include "BLI_memarena.h" - -/* A few small defines. Keep'em local! */ -#define SMALL_NUMBER 1.e-8 -#define ABS(x) ((x) < 0 ? -(x) : (x)) -#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } -#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c) - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 -#endif - - -float saacos(float fac) -{ - if(fac<= -1.0f) return (float)M_PI; - else if(fac>=1.0f) return 0.0; - else return (float)acos(fac); -} - -float saasin(float fac) -{ - if(fac<= -1.0f) return (float)-M_PI/2.0f; - else if(fac>=1.0f) return (float)M_PI/2.0f; - else return (float)asin(fac); -} - -float sasqrt(float fac) -{ - if(fac<=0.0) return 0.0; - return (float)sqrt(fac); -} - -float saacosf(float fac) -{ - if(fac<= -1.0f) return (float)M_PI; - else if(fac>=1.0f) return 0.0f; - else return (float)acosf(fac); -} - -float saasinf(float fac) -{ - if(fac<= -1.0f) return (float)-M_PI/2.0f; - else if(fac>=1.0f) return (float)M_PI/2.0f; - else return (float)asinf(fac); -} - -float sasqrtf(float fac) -{ - if(fac<=0.0) return 0.0; - return (float)sqrtf(fac); -} - -float Normalize(float *n) -{ - float d; - - d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; - /* A larger value causes normalize errors in a scaled down models with camera xtreme close */ - if(d>1.0e-35f) { - d= (float)sqrt(d); - - n[0]/=d; - n[1]/=d; - n[2]/=d; - } else { - n[0]=n[1]=n[2]= 0.0f; - d= 0.0f; - } - return d; -} - -/* Crossf stores the cross product c = a x b */ -void Crossf(float *c, float *a, float *b) -{ - c[0] = a[1] * b[2] - a[2] * b[1]; - c[1] = a[2] * b[0] - a[0] * b[2]; - c[2] = a[0] * b[1] - a[1] * b[0]; -} - -/* Inpf returns the dot product, also called the scalar product and inner product */ -float Inpf( float *v1, float *v2) -{ - return v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]; -} - -/* Project v1 on v2 */ -void Projf(float *c, float *v1, float *v2) -{ - float mul; - mul = Inpf(v1, v2) / Inpf(v2, v2); - - c[0] = mul * v2[0]; - c[1] = mul * v2[1]; - c[2] = mul * v2[2]; -} - -void Mat3Transp(float mat[][3]) -{ - float t; - - t = mat[0][1] ; - mat[0][1] = mat[1][0] ; - mat[1][0] = t; - t = mat[0][2] ; - mat[0][2] = mat[2][0] ; - mat[2][0] = t; - t = mat[1][2] ; - mat[1][2] = mat[2][1] ; - mat[2][1] = t; -} - -void Mat4Transp(float mat[][4]) -{ - float t; - - t = mat[0][1] ; - mat[0][1] = mat[1][0] ; - mat[1][0] = t; - t = mat[0][2] ; - mat[0][2] = mat[2][0] ; - mat[2][0] = t; - t = mat[0][3] ; - mat[0][3] = mat[3][0] ; - mat[3][0] = t; - - t = mat[1][2] ; - mat[1][2] = mat[2][1] ; - mat[2][1] = t; - t = mat[1][3] ; - mat[1][3] = mat[3][1] ; - mat[3][1] = t; - - t = mat[2][3] ; - mat[2][3] = mat[3][2] ; - mat[3][2] = t; -} - - -/* - * invertmat - - * computes the inverse of mat and puts it in inverse. Returns - * TRUE on success (i.e. can always find a pivot) and FALSE on failure. - * Uses Gaussian Elimination with partial (maximal column) pivoting. - * - * Mark Segal - 1992 - */ - -int 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] = (float)(tempmat[i][k]/temp); - inverse[i][k] = (float)(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] -= (float)(tempmat[i][k]*temp); - inverse[j][k] -= (float)(inverse[i][k]*temp); - } - } - } - } - return 1; -} -#ifdef TEST_ACTIVE -void Mat4InvertSimp(float inverse[][4], float mat[][4]) -{ - /* only for Matrices that have a rotation */ - /* based at GG IV pag 205 */ - float scale; - - scale= mat[0][0]*mat[0][0] + mat[1][0]*mat[1][0] + mat[2][0]*mat[2][0]; - if(scale==0.0) return; - - scale= 1.0/scale; - - /* transpose and scale */ - inverse[0][0]= scale*mat[0][0]; - inverse[1][0]= scale*mat[0][1]; - inverse[2][0]= scale*mat[0][2]; - inverse[0][1]= scale*mat[1][0]; - inverse[1][1]= scale*mat[1][1]; - inverse[2][1]= scale*mat[1][2]; - inverse[0][2]= scale*mat[2][0]; - inverse[1][2]= scale*mat[2][1]; - inverse[2][2]= scale*mat[2][2]; - - inverse[3][0]= -(inverse[0][0]*mat[3][0] + inverse[1][0]*mat[3][1] + inverse[2][0]*mat[3][2]); - inverse[3][1]= -(inverse[0][1]*mat[3][0] + inverse[1][1]*mat[3][1] + inverse[2][1]*mat[3][2]); - inverse[3][2]= -(inverse[0][2]*mat[3][0] + inverse[1][2]*mat[3][1] + inverse[2][2]*mat[3][2]); - - inverse[0][3]= inverse[1][3]= inverse[2][3]= 0.0; - inverse[3][3]= 1.0; -} -#endif -/* struct Matrix4; */ - -#ifdef TEST_ACTIVE -/* this seems to be unused.. */ - -void Mat4Inv(float *m1, float *m2) -{ - -/* This gets me into trouble: */ - float mat1[3][3], mat2[3][3]; - -/* void Mat3Inv(); */ -/* void Mat3CpyMat4(); */ -/* void Mat4CpyMat3(); */ - - Mat3CpyMat4((float*)mat2,m2); - Mat3Inv((float*)mat1, (float*) mat2); - Mat4CpyMat3(m1, mat1); - -} -#endif - - -float Det2x2(float a,float b,float c,float d) -{ - - return a*d - b*c; -} - - - -float Det3x3(float a1, float a2, float a3, - float b1, float b2, float b3, - float c1, float c2, float c3 ) -{ - float ans; - - ans = a1 * Det2x2( b2, b3, c2, c3 ) - - b1 * Det2x2( a2, a3, c2, c3 ) - + c1 * Det2x2( a2, a3, b2, b3 ); - - return ans; -} - -float Det4x4(float m[][4]) -{ - float ans; - float a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4; - - a1= m[0][0]; - b1= m[0][1]; - c1= m[0][2]; - d1= m[0][3]; - - a2= m[1][0]; - b2= m[1][1]; - c2= m[1][2]; - d2= m[1][3]; - - a3= m[2][0]; - b3= m[2][1]; - c3= m[2][2]; - d3= m[2][3]; - - a4= m[3][0]; - b4= m[3][1]; - c4= m[3][2]; - d4= m[3][3]; - - ans = a1 * Det3x3( b2, b3, b4, c2, c3, c4, d2, d3, d4) - - b1 * Det3x3( a2, a3, a4, c2, c3, c4, d2, d3, d4) - + c1 * Det3x3( a2, a3, a4, b2, b3, b4, d2, d3, d4) - - d1 * Det3x3( a2, a3, a4, b2, b3, b4, c2, c3, c4); - - return ans; -} - - -void Mat4Adj(float out[][4], float in[][4]) /* out = ADJ(in) */ -{ - float a1, a2, a3, a4, b1, b2, b3, b4; - float c1, c2, c3, c4, d1, d2, d3, d4; - - a1= in[0][0]; - b1= in[0][1]; - c1= in[0][2]; - d1= in[0][3]; - - a2= in[1][0]; - b2= in[1][1]; - c2= in[1][2]; - d2= in[1][3]; - - a3= in[2][0]; - b3= in[2][1]; - c3= in[2][2]; - d3= in[2][3]; - - a4= in[3][0]; - b4= in[3][1]; - c4= in[3][2]; - d4= in[3][3]; - - - out[0][0] = Det3x3( b2, b3, b4, c2, c3, c4, d2, d3, d4); - out[1][0] = - Det3x3( a2, a3, a4, c2, c3, c4, d2, d3, d4); - out[2][0] = Det3x3( a2, a3, a4, b2, b3, b4, d2, d3, d4); - out[3][0] = - Det3x3( a2, a3, a4, b2, b3, b4, c2, c3, c4); - - out[0][1] = - Det3x3( b1, b3, b4, c1, c3, c4, d1, d3, d4); - out[1][1] = Det3x3( a1, a3, a4, c1, c3, c4, d1, d3, d4); - out[2][1] = - Det3x3( a1, a3, a4, b1, b3, b4, d1, d3, d4); - out[3][1] = Det3x3( a1, a3, a4, b1, b3, b4, c1, c3, c4); - - out[0][2] = Det3x3( b1, b2, b4, c1, c2, c4, d1, d2, d4); - out[1][2] = - Det3x3( a1, a2, a4, c1, c2, c4, d1, d2, d4); - out[2][2] = Det3x3( a1, a2, a4, b1, b2, b4, d1, d2, d4); - out[3][2] = - Det3x3( a1, a2, a4, b1, b2, b4, c1, c2, c4); - - out[0][3] = - Det3x3( b1, b2, b3, c1, c2, c3, d1, d2, d3); - out[1][3] = Det3x3( a1, a2, a3, c1, c2, c3, d1, d2, d3); - out[2][3] = - Det3x3( a1, a2, a3, b1, b2, b3, d1, d2, d3); - out[3][3] = Det3x3( a1, a2, a3, b1, b2, b3, c1, c2, c3); -} - -void Mat4InvGG(float out[][4], float in[][4]) /* from Graphic Gems I, out= INV(in) */ -{ - int i, j; - float det; - - /* calculate the adjoint matrix */ - - Mat4Adj(out,in); - - det = Det4x4(out); - - if ( fabs( det ) < SMALL_NUMBER) { - return; - } - - /* scale the adjoint matrix to get the inverse */ - - for (i=0; i<4; i++) - for(j=0; j<4; j++) - out[i][j] = out[i][j] / det; - - /* the last factor is not always 1. For that reason an extra division should be implemented? */ -} - - -void Mat3Inv(float m1[][3], float m2[][3]) -{ - short a,b; - float det; - - /* calc adjoint */ - Mat3Adj(m1,m2); - - /* then determinant old matrix! */ - 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 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 Mat4MulMat4(float m1[][4], float m2[][4], float m3[][4]) -{ - /* matrix product: m1[j][k] = m2[j][i].m3[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]; - -} -#ifdef TEST_ACTIVE -void subMat4MulMat4(float *m1, float *m2, float *m3) -{ - - m1[0]= m2[0]*m3[0] + m2[1]*m3[4] + m2[2]*m3[8]; - m1[1]= m2[0]*m3[1] + m2[1]*m3[5] + m2[2]*m3[9]; - m1[2]= m2[0]*m3[2] + m2[1]*m3[6] + m2[2]*m3[10]; - m1[3]= m2[0]*m3[3] + m2[1]*m3[7] + m2[2]*m3[11] + m2[3]; - m1+=4; - m2+=4; - m1[0]= m2[0]*m3[0] + m2[1]*m3[4] + m2[2]*m3[8]; - m1[1]= m2[0]*m3[1] + m2[1]*m3[5] + m2[2]*m3[9]; - m1[2]= m2[0]*m3[2] + m2[1]*m3[6] + m2[2]*m3[10]; - m1[3]= m2[0]*m3[3] + m2[1]*m3[7] + m2[2]*m3[11] + m2[3]; - m1+=4; - m2+=4; - m1[0]= m2[0]*m3[0] + m2[1]*m3[4] + m2[2]*m3[8]; - m1[1]= m2[0]*m3[1] + m2[1]*m3[5] + m2[2]*m3[9]; - m1[2]= m2[0]*m3[2] + m2[1]*m3[6] + m2[2]*m3[10]; - m1[3]= m2[0]*m3[3] + m2[1]*m3[7] + m2[2]*m3[11] + m2[3]; -} -#endif - -#ifndef TEST_ACTIVE -void Mat3MulMat3(float m1[][3], float m3[][3], float m2[][3]) -#else -void Mat3MulMat3(float *m1, float *m3, float *m2) -#endif -{ - /* m1[i][j] = m2[i][k]*m3[k][j], args are flipped! */ -#ifndef TEST_ACTIVE - 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]; -#else - 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]; -#endif -} /* end of void Mat3MulMat3(float m1[][3], float m3[][3], float m2[][3]) */ - -void Mat4MulMat43(float (*m1)[4], float (*m3)[4], float (*m2)[3]) -{ - 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 = m2 * m3, ignore the elements on the 4th row/column of m3*/ -void Mat3IsMat3MulMat4(float m1[][3], float m2[][3], float m3[][4]) -{ - /* 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]; -} - - - -void Mat4MulMat34(float (*m1)[4], float (*m3)[3], float (*m2)[4]) -{ - 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]; -} - -void Mat4CpyMat4(float m1[][4], float m2[][4]) -{ - memcpy(m1, m2, 4*4*sizeof(float)); -} - -void 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; - } - } -} - -typedef float Mat3Row[3]; -typedef float Mat4Row[4]; - -#ifdef TEST_ACTIVE -void Mat3CpyMat4(float *m1p, float *m2p) -#else -void Mat3CpyMat4(float m1[][3], float m2[][4]) -#endif -{ -#ifdef TEST_ACTIVE - int i, j; - Mat3Row *m1= (Mat3Row *)m1p; - Mat4Row *m2= (Mat4Row *)m2p; - for ( i = 0; i++; i < 3) { - for (j = 0; j++; j < 3) { - m1p[3*i + j] = m2p[4*i + j]; - } - } -#endif - 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]; -} - -/* Butched. See .h for comment */ -/* void Mat4CpyMat3(float m1[][4], float m2[][3]) */ -#ifdef TEST_ACTIVE -void Mat4CpyMat3(float* m1, float *m2) -{ - int i; - for (i = 0; i < 3; i++) { - m1[(4*i)] = m2[(3*i)]; - m1[(4*i) + 1]= m2[(3*i) + 1]; - m1[(4*i) + 2]= m2[(3*i) + 2]; - m1[(4*i) + 3]= 0.0; - i++; - } - - m1[12]=m1[13]= m1[14]= 0.0; - m1[15]= 1.0; -} -#else - -void Mat4CpyMat3(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]; - - /* Reevan's Bugfix */ - m1[0][3]=0.0F; - m1[1][3]=0.0F; - m1[2][3]=0.0F; - - m1[3][0]=0.0F; - m1[3][1]=0.0F; - m1[3][2]=0.0F; - m1[3][3]=1.0F; - - -} -#endif - -void Mat3CpyMat3(float m1[][3], float m2[][3]) -{ - /* destination comes first: */ - memcpy(&m1[0], &m2[0], 9*sizeof(float)); -} - -void Mat3MulSerie(float answ[][3], - float m1[][3], float m2[][3], float m3[][3], - float m4[][3], float m5[][3], float m6[][3], - float m7[][3], float m8[][3]) -{ - float temp[3][3]; - - if(m1==0 || m2==0) return; - - - Mat3MulMat3(answ, m2, m1); - if(m3) { - Mat3MulMat3(temp, m3, answ); - if(m4) { - Mat3MulMat3(answ, m4, temp); - if(m5) { - Mat3MulMat3(temp, m5, answ); - if(m6) { - Mat3MulMat3(answ, m6, temp); - if(m7) { - Mat3MulMat3(temp, m7, answ); - if(m8) { - Mat3MulMat3(answ, m8, temp); - } - else Mat3CpyMat3(answ, temp); - } - } - else Mat3CpyMat3(answ, temp); - } - } - else Mat3CpyMat3(answ, temp); - } -} - -void 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; - - Mat4MulMat4(answ, m2, m1); - if(m3) { - Mat4MulMat4(temp, m3, answ); - if(m4) { - Mat4MulMat4(answ, m4, temp); - if(m5) { - Mat4MulMat4(temp, m5, answ); - if(m6) { - Mat4MulMat4(answ, m6, temp); - if(m7) { - Mat4MulMat4(temp, m7, answ); - if(m8) { - Mat4MulMat4(answ, m8, temp); - } - else Mat4CpyMat4(answ, temp); - } - } - else Mat4CpyMat4(answ, temp); - } - } - else Mat4CpyMat4(answ, temp); - } -} - -void Mat3BlendMat3(float out[][3], float dst[][3], float src[][3], float srcweight) -{ - float squat[4], dquat[4], fquat[4]; - float ssize[3], dsize[3], fsize[4]; - float rmat[3][3], smat[3][3]; - - Mat3ToQuat(dst, dquat); - Mat3ToSize(dst, dsize); - - Mat3ToQuat(src, squat); - Mat3ToSize(src, ssize); - - /* do blending */ - QuatInterpol(fquat, dquat, squat, srcweight); - VecLerpf(fsize, dsize, ssize, srcweight); - - /* compose new matrix */ - QuatToMat3(fquat, rmat); - SizeToMat3(fsize, smat); - Mat3MulMat3(out, rmat, smat); -} - -void Mat4BlendMat4(float out[][4], float dst[][4], float src[][4], float srcweight) -{ - float squat[4], dquat[4], fquat[4]; - float ssize[3], dsize[3], fsize[4]; - float sloc[3], dloc[3], floc[3]; - - Mat4ToQuat(dst, dquat); - Mat4ToSize(dst, dsize); - VecCopyf(dloc, dst[3]); - - Mat4ToQuat(src, squat); - Mat4ToSize(src, ssize); - VecCopyf(sloc, src[3]); - - /* do blending */ - VecLerpf(floc, dloc, sloc, srcweight); - QuatInterpol(fquat, dquat, squat, srcweight); - VecLerpf(fsize, dsize, ssize, srcweight); - - /* compose new matrix */ - LocQuatSizeToMat4(out, floc, fquat, fsize); -} - -void Mat4Clr(float *m) -{ - memset(m, 0, 4*4*sizeof(float)); -} - -void Mat3Clr(float *m) -{ - memset(m, 0, 3*3*sizeof(float)); -} - -void 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; -} - -void 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 Mat4Scale(float m[][4], float scale) -{ - - m[0][0]= m[1][1]= m[2][2]= scale; - 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; -} - -void Mat3Scale(float m[][3], float scale) -{ - - m[0][0]= m[1][1]= m[2][2]= scale; - 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 Mat4MulVec( float mat[][4], int *vec) -{ - int x,y; - - x=vec[0]; - y=vec[1]; - vec[0]=(int)(x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2] + mat[3][0]); - vec[1]=(int)(x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2] + mat[3][1]); - vec[2]=(int)(x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2] + mat[3][2]); -} - -void 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 VecMat4MulVecfl(float *in, float mat[][4], float *vec) -{ - float x,y; - - x=vec[0]; - y=vec[1]; - in[0]= x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2] + mat[3][0]; - in[1]= x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2] + mat[3][1]; - in[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2] + mat[3][2]; -} - -void Mat4Mul3Vecfl( 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]; - 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 Mat4MulVec3Project(float mat[][4], float *vec) -{ - float w; - - w = vec[0]*mat[0][3] + vec[1]*mat[1][3] + vec[2]*mat[2][3] + mat[3][3]; - Mat4MulVecfl(mat, vec); - - vec[0] /= w; - vec[1] /= w; - vec[2] /= w; -} - -void 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 Mat3MulVec( float mat[][3], int *vec) -{ - int x,y; - - x=vec[0]; - y=vec[1]; - vec[0]= (int)(x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2]); - vec[1]= (int)(x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2]); - vec[2]= (int)(x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2]); -} - -void 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]; -} - -void Mat3MulVecd( float mat[][3], double *vec) -{ - double 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]; -} - -void Mat3TransMulVecfl( float mat[][3], float *vec) -{ - float x,y; - - x=vec[0]; - y=vec[1]; - vec[0]= x*mat[0][0] + y*mat[0][1] + mat[0][2]*vec[2]; - vec[1]= x*mat[1][0] + y*mat[1][1] + mat[1][2]*vec[2]; - vec[2]= x*mat[2][0] + y*mat[2][1] + mat[2][2]*vec[2]; -} - -void Mat3MulFloat(float *m, float f) -{ - int i; - - for(i=0;i<9;i++) m[i]*=f; -} - -void Mat4MulFloat(float *m, float f) -{ - int i; - - for(i=0;i<16;i++) m[i]*=f; /* count to 12: without vector component */ -} - - -void Mat4MulFloat3(float *m, float f) /* only scale component */ -{ - int i,j; - - for(i=0; i<3; i++) { - for(j=0; j<3; j++) { - - m[4*i+j] *= f; - } - } -} - -void Mat3AddMat3(float m1[][3], float m2[][3], float m3[][3]) -{ - int i, j; - - for(i=0;i<3;i++) - for(j=0;j<3;j++) - m1[i][j]= m2[i][j] + m3[i][j]; -} - -void Mat4AddMat4(float m1[][4], float m2[][4], float m3[][4]) -{ - int i, j; - - for(i=0;i<4;i++) - for(j=0;j<4;j++) - m1[i][j]= m2[i][j] + m3[i][j]; -} - -void VecStar(float mat[][3], float *vec) -{ - - mat[0][0]= mat[1][1]= mat[2][2]= 0.0; - mat[0][1]= -vec[2]; - mat[0][2]= vec[1]; - mat[1][0]= vec[2]; - mat[1][2]= -vec[0]; - mat[2][0]= -vec[1]; - mat[2][1]= vec[0]; - -} -#ifdef TEST_ACTIVE -short EenheidsMat(float mat[][3]) -{ - - if(mat[0][0]==1.0 && mat[0][1]==0.0 && mat[0][2]==0.0) - if(mat[1][0]==0.0 && mat[1][1]==1.0 && mat[1][2]==0.0) - if(mat[2][0]==0.0 && mat[2][1]==0.0 && mat[2][2]==1.0) - return 1; - return 0; -} -#endif - -int FloatCompare( float *v1, float *v2, float limit) -{ - - if( fabs(v1[0]-v2[0])<limit ) { - if( fabs(v1[1]-v2[1])<limit ) { - if( fabs(v1[2]-v2[2])<limit ) return 1; - } - } - return 0; -} - -int FloatCompare4( float *v1, float *v2, float limit) -{ - - if( fabs(v1[0]-v2[0])<limit ) { - if( fabs(v1[1]-v2[1])<limit ) { - if( fabs(v1[2]-v2[2])<limit ) { - if( fabs(v1[3]-v2[3])<limit ) return 1; - } - } - } - return 0; -} - -float FloatLerpf( float target, float origin, float fac) -{ - return (fac*target) + (1.0f-fac)*origin; -} - -void printvecf( char *str, float v[3]) -{ - printf("%s: %.3f %.3f %.3f\n", str, v[0], v[1], v[2]); - -} - -void printquat( char *str, float q[4]) -{ - printf("%s: %.3f %.3f %.3f %.3f\n", str, q[0], q[1], q[2], q[3]); - -} - -void printvec4f( char *str, float v[4]) -{ - printf("%s\n", str); - printf("%f %f %f %f\n",v[0],v[1],v[2], v[3]); - printf("\n"); - -} - -void printmatrix4( char *str, float m[][4]) -{ - printf("%s\n", str); - printf("%f %f %f %f\n",m[0][0],m[1][0],m[2][0],m[3][0]); - printf("%f %f %f %f\n",m[0][1],m[1][1],m[2][1],m[3][1]); - printf("%f %f %f %f\n",m[0][2],m[1][2],m[2][2],m[3][2]); - printf("%f %f %f %f\n",m[0][3],m[1][3],m[2][3],m[3][3]); - printf("\n"); - -} - -void printmatrix3( char *str, float m[][3]) -{ - printf("%s\n", str); - printf("%f %f %f\n",m[0][0],m[1][0],m[2][0]); - printf("%f %f %f\n",m[0][1],m[1][1],m[2][1]); - printf("%f %f %f\n",m[0][2],m[1][2],m[2][2]); - printf("\n"); - -} - -/* **************** QUATERNIONS ********** */ - -int QuatIsNul(float *q) -{ - return (q[0] == 0 && q[1] == 0 && q[2] == 0 && q[3] == 0); -} - -void QuatMul(float *q, float *q1, float *q2) -{ - float t0,t1,t2; - - t0= q1[0]*q2[0]-q1[1]*q2[1]-q1[2]*q2[2]-q1[3]*q2[3]; - t1= q1[0]*q2[1]+q1[1]*q2[0]+q1[2]*q2[3]-q1[3]*q2[2]; - t2= q1[0]*q2[2]+q1[2]*q2[0]+q1[3]*q2[1]-q1[1]*q2[3]; - q[3]= q1[0]*q2[3]+q1[3]*q2[0]+q1[1]*q2[2]-q1[2]*q2[1]; - q[0]=t0; - q[1]=t1; - q[2]=t2; -} - -/* Assumes a unit quaternion */ -void QuatMulVecf(float *q, float *v) -{ - float t0, t1, t2; - - t0= -q[1]*v[0]-q[2]*v[1]-q[3]*v[2]; - t1= q[0]*v[0]+q[2]*v[2]-q[3]*v[1]; - t2= q[0]*v[1]+q[3]*v[0]-q[1]*v[2]; - v[2]= q[0]*v[2]+q[1]*v[1]-q[2]*v[0]; - v[0]=t1; - v[1]=t2; - - t1= t0*-q[1]+v[0]*q[0]-v[1]*q[3]+v[2]*q[2]; - t2= t0*-q[2]+v[1]*q[0]-v[2]*q[1]+v[0]*q[3]; - v[2]= t0*-q[3]+v[2]*q[0]-v[0]*q[2]+v[1]*q[1]; - v[0]=t1; - v[1]=t2; -} - -void QuatConj(float *q) -{ - q[1] = -q[1]; - q[2] = -q[2]; - q[3] = -q[3]; -} - -float QuatDot(float *q1, float *q2) -{ - return q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2] + q1[3]*q2[3]; -} - -void QuatInv(float *q) -{ - float f = QuatDot(q, q); - - if (f == 0.0f) - return; - - QuatConj(q); - QuatMulf(q, 1.0f/f); -} - -/* simple mult */ -void QuatMulf(float *q, float f) -{ - q[0] *= f; - q[1] *= f; - q[2] *= f; - q[3] *= f; -} - -void QuatSub(float *q, float *q1, float *q2) -{ - q2[0]= -q2[0]; - QuatMul(q, q1, q2); - q2[0]= -q2[0]; -} - -/* angular mult factor */ -void QuatMulFac(float *q, float fac) -{ - float angle= fac*saacos(q[0]); /* quat[0]= cos(0.5*angle), but now the 0.5 and 2.0 rule out */ - - float co= (float)cos(angle); - float si= (float)sin(angle); - q[0]= co; - Normalize(q+1); - q[1]*= si; - q[2]*= si; - q[3]*= si; - -} - -void QuatToMat3( float *q, float m[][3]) -{ - double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; - - q0= M_SQRT2 * q[0]; - q1= M_SQRT2 * q[1]; - q2= M_SQRT2 * q[2]; - q3= M_SQRT2 * q[3]; - - qda= q0*q1; - qdb= q0*q2; - qdc= q0*q3; - qaa= q1*q1; - qab= q1*q2; - qac= q1*q3; - qbb= q2*q2; - qbc= q2*q3; - qcc= q3*q3; - - m[0][0]= (float)(1.0-qbb-qcc); - m[0][1]= (float)(qdc+qab); - m[0][2]= (float)(-qdb+qac); - - m[1][0]= (float)(-qdc+qab); - m[1][1]= (float)(1.0-qaa-qcc); - m[1][2]= (float)(qda+qbc); - - m[2][0]= (float)(qdb+qac); - m[2][1]= (float)(-qda+qbc); - m[2][2]= (float)(1.0-qaa-qbb); -} - - -void QuatToMat4( float *q, float m[][4]) -{ - double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; - - q0= M_SQRT2 * q[0]; - q1= M_SQRT2 * q[1]; - q2= M_SQRT2 * q[2]; - q3= M_SQRT2 * q[3]; - - qda= q0*q1; - qdb= q0*q2; - qdc= q0*q3; - qaa= q1*q1; - qab= q1*q2; - qac= q1*q3; - qbb= q2*q2; - qbc= q2*q3; - qcc= q3*q3; - - m[0][0]= (float)(1.0-qbb-qcc); - m[0][1]= (float)(qdc+qab); - m[0][2]= (float)(-qdb+qac); - m[0][3]= 0.0f; - - m[1][0]= (float)(-qdc+qab); - m[1][1]= (float)(1.0-qaa-qcc); - m[1][2]= (float)(qda+qbc); - m[1][3]= 0.0f; - - m[2][0]= (float)(qdb+qac); - m[2][1]= (float)(-qda+qbc); - m[2][2]= (float)(1.0-qaa-qbb); - m[2][3]= 0.0f; - - m[3][0]= m[3][1]= m[3][2]= 0.0f; - m[3][3]= 1.0f; -} - -void Mat3ToQuat(float wmat[][3], float *q) -{ - double tr, s; - float mat[3][3]; - - /* work on a copy */ - Mat3CpyMat3(mat, wmat); - Mat3Ortho(mat); /* this is needed AND a NormalQuat in the end */ - - tr= 0.25*(1.0+mat[0][0]+mat[1][1]+mat[2][2]); - - if(tr>FLT_EPSILON) { - s= sqrt( tr); - q[0]= (float)s; - s= 1.0/(4.0*s); - q[1]= (float)((mat[1][2]-mat[2][1])*s); - q[2]= (float)((mat[2][0]-mat[0][2])*s); - q[3]= (float)((mat[0][1]-mat[1][0])*s); - } - else { - if(mat[0][0] > mat[1][1] && mat[0][0] > mat[2][2]) { - s= 2.0*sqrtf(1.0 + mat[0][0] - mat[1][1] - mat[2][2]); - q[1]= (float)(0.25*s); - - s= 1.0/s; - q[0]= (float)((mat[2][1] - mat[1][2])*s); - q[2]= (float)((mat[1][0] + mat[0][1])*s); - q[3]= (float)((mat[2][0] + mat[0][2])*s); - } - else if(mat[1][1] > mat[2][2]) { - s= 2.0*sqrtf(1.0 + mat[1][1] - mat[0][0] - mat[2][2]); - q[2]= (float)(0.25*s); - - s= 1.0/s; - q[0]= (float)((mat[2][0] - mat[0][2])*s); - q[1]= (float)((mat[1][0] + mat[0][1])*s); - q[3]= (float)((mat[2][1] + mat[1][2])*s); - } - else { - s= 2.0*sqrtf(1.0 + mat[2][2] - mat[0][0] - mat[1][1]); - q[3]= (float)(0.25*s); - - s= 1.0/s; - q[0]= (float)((mat[1][0] - mat[0][1])*s); - q[1]= (float)((mat[2][0] + mat[0][2])*s); - q[2]= (float)((mat[2][1] + mat[1][2])*s); - } - } - NormalQuat(q); -} - -void Mat3ToQuat_is_ok( float wmat[][3], float *q) -{ - float mat[3][3], matr[3][3], matn[3][3], q1[4], q2[4], angle, si, co, nor[3]; - - /* work on a copy */ - Mat3CpyMat3(mat, wmat); - Mat3Ortho(mat); - - /* rotate z-axis of matrix to z-axis */ - - nor[0] = mat[2][1]; /* cross product with (0,0,1) */ - nor[1] = -mat[2][0]; - nor[2] = 0.0; - Normalize(nor); - - co= mat[2][2]; - angle= 0.5f*saacos(co); - - co= (float)cos(angle); - si= (float)sin(angle); - q1[0]= co; - q1[1]= -nor[0]*si; /* negative here, but why? */ - q1[2]= -nor[1]*si; - q1[3]= -nor[2]*si; - - /* rotate back x-axis from mat, using inverse q1 */ - QuatToMat3(q1, matr); - Mat3Inv(matn, matr); - Mat3MulVecfl(matn, mat[0]); - - /* and align x-axes */ - angle= (float)(0.5*atan2(mat[0][1], mat[0][0])); - - co= (float)cos(angle); - si= (float)sin(angle); - q2[0]= co; - q2[1]= 0.0f; - q2[2]= 0.0f; - q2[3]= si; - - QuatMul(q, q1, q2); -} - - -void Mat4ToQuat( float m[][4], float *q) -{ - float mat[3][3]; - - Mat3CpyMat4(mat, m); - Mat3ToQuat(mat, q); - -} - -void QuatOne(float *q) -{ - q[0]= 1.0; - q[1]= q[2]= q[3]= 0.0; -} - -void NormalQuat(float *q) -{ - float len; - - len= (float)sqrt(q[0]*q[0]+q[1]*q[1]+q[2]*q[2]+q[3]*q[3]); - if(len!=0.0) { - q[0]/= len; - q[1]/= len; - q[2]/= len; - q[3]/= len; - } else { - q[1]= 1.0f; - q[0]= q[2]= q[3]= 0.0f; - } -} - -void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]) -{ - float axis[3]; - float angle; - - Crossf(axis, v1, v2); - - angle = NormalizedVecAngle2(v1, v2); - - AxisAngleToQuat(q, axis, angle); -} - -void vectoquat(float *vec, short axis, short upflag, float *q) -{ - float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1; - - /* first rotate to axis */ - if(axis>2) { - x2= vec[0] ; y2= vec[1] ; z2= vec[2]; - axis-= 3; - } - else { - x2= -vec[0] ; y2= -vec[1] ; z2= -vec[2]; - } - - q[0]=1.0; - q[1]=q[2]=q[3]= 0.0; - - len1= (float)sqrt(x2*x2+y2*y2+z2*z2); - if(len1 == 0.0) return; - - /* nasty! I need a good routine for this... - * problem is a rotation of an Y axis to the negative Y-axis for example. - */ - - if(axis==0) { /* x-axis */ - nor[0]= 0.0; - nor[1]= -z2; - nor[2]= y2; - - if(fabs(y2)+fabs(z2)<0.0001) - nor[1]= 1.0; - - co= x2; - } - else if(axis==1) { /* y-axis */ - nor[0]= z2; - nor[1]= 0.0; - nor[2]= -x2; - - if(fabs(x2)+fabs(z2)<0.0001) - nor[2]= 1.0; - - co= y2; - } - else { /* z-axis */ - nor[0]= -y2; - nor[1]= x2; - nor[2]= 0.0; - - if(fabs(x2)+fabs(y2)<0.0001) - nor[0]= 1.0; - - co= z2; - } - co/= len1; - - Normalize(nor); - - angle= 0.5f*saacos(co); - si= (float)sin(angle); - q[0]= (float)cos(angle); - q[1]= nor[0]*si; - q[2]= nor[1]*si; - q[3]= nor[2]*si; - - if(axis!=upflag) { - QuatToMat3(q, mat); - - fp= mat[2]; - if(axis==0) { - if(upflag==1) angle= (float)(0.5*atan2(fp[2], fp[1])); - else angle= (float)(-0.5*atan2(fp[1], fp[2])); - } - else if(axis==1) { - if(upflag==0) angle= (float)(-0.5*atan2(fp[2], fp[0])); - else angle= (float)(0.5*atan2(fp[0], fp[2])); - } - else { - if(upflag==0) angle= (float)(0.5*atan2(-fp[1], -fp[0])); - else angle= (float)(-0.5*atan2(-fp[0], -fp[1])); - } - - co= (float)cos(angle); - si= (float)(sin(angle)/len1); - q2[0]= co; - q2[1]= x2*si; - q2[2]= y2*si; - q2[3]= z2*si; - - QuatMul(q,q2,q); - } -} - -void VecUpMat3old( float *vec, float mat[][3], short axis) -{ - float inp, up[3]; - short cox = 0, coy = 0, coz = 0; - - /* using different up's is not useful, infact there is no real 'up'! - */ - - up[0]= 0.0; - up[1]= 0.0; - up[2]= 1.0; - - if(axis==0) { - cox= 0; coy= 1; coz= 2; /* Y up Z tr */ - } - if(axis==1) { - cox= 1; coy= 2; coz= 0; /* Z up X tr */ - } - if(axis==2) { - cox= 2; coy= 0; coz= 1; /* X up Y tr */ - } - if(axis==3) { - cox= 0; coy= 2; coz= 1; /* */ - } - if(axis==4) { - cox= 1; coy= 0; coz= 2; /* */ - } - if(axis==5) { - cox= 2; coy= 1; coz= 0; /* Y up X tr */ - } - - mat[coz][0]= vec[0]; - mat[coz][1]= vec[1]; - mat[coz][2]= vec[2]; - Normalize((float *)mat[coz]); - - inp= mat[coz][0]*up[0] + mat[coz][1]*up[1] + mat[coz][2]*up[2]; - mat[coy][0]= up[0] - inp*mat[coz][0]; - mat[coy][1]= up[1] - inp*mat[coz][1]; - mat[coy][2]= up[2] - inp*mat[coz][2]; - - Normalize((float *)mat[coy]); - - Crossf(mat[cox], mat[coy], mat[coz]); - -} - -void VecUpMat3(float *vec, float mat[][3], short axis) -{ - float inp; - short cox = 0, coy = 0, coz = 0; - - /* using different up's is not useful, infact there is no real 'up'! - */ - - if(axis==0) { - cox= 0; coy= 1; coz= 2; /* Y up Z tr */ - } - if(axis==1) { - cox= 1; coy= 2; coz= 0; /* Z up X tr */ - } - if(axis==2) { - cox= 2; coy= 0; coz= 1; /* X up Y tr */ - } - if(axis==3) { - cox= 0; coy= 1; coz= 2; /* Y op -Z tr */ - vec[0]= -vec[0]; - vec[1]= -vec[1]; - vec[2]= -vec[2]; - } - if(axis==4) { - cox= 1; coy= 0; coz= 2; /* */ - } - if(axis==5) { - cox= 2; coy= 1; coz= 0; /* Y up X tr */ - } - - mat[coz][0]= vec[0]; - mat[coz][1]= vec[1]; - mat[coz][2]= vec[2]; - Normalize((float *)mat[coz]); - - inp= mat[coz][2]; - mat[coy][0]= - inp*mat[coz][0]; - mat[coy][1]= - inp*mat[coz][1]; - mat[coy][2]= 1.0f - inp*mat[coz][2]; - - Normalize((float *)mat[coy]); - - Crossf(mat[cox], mat[coy], mat[coz]); - -} - -/* A & M Watt, Advanced animation and rendering techniques, 1992 ACM press */ -void QuatInterpolW(float *, float *, float *, float ); // XXX why this? - -void QuatInterpolW(float *result, float *quat1, float *quat2, float t) -{ - float omega, cosom, sinom, sc1, sc2; - - cosom = quat1[0]*quat2[0] + quat1[1]*quat2[1] + quat1[2]*quat2[2] + quat1[3]*quat2[3] ; - - /* rotate around shortest angle */ - if ((1.0f + cosom) > 0.0001f) { - - if ((1.0f - cosom) > 0.0001f) { - omega = (float)acos(cosom); - sinom = (float)sin(omega); - sc1 = (float)sin((1.0 - t) * omega) / sinom; - sc2 = (float)sin(t * omega) / sinom; - } - else { - sc1 = 1.0f - t; - sc2 = t; - } - result[0] = sc1*quat1[0] + sc2*quat2[0]; - result[1] = sc1*quat1[1] + sc2*quat2[1]; - result[2] = sc1*quat1[2] + sc2*quat2[2]; - result[3] = sc1*quat1[3] + sc2*quat2[3]; - } - else { - result[0] = quat2[3]; - result[1] = -quat2[2]; - result[2] = quat2[1]; - result[3] = -quat2[0]; - - sc1 = (float)sin((1.0 - t)*M_PI_2); - sc2 = (float)sin(t*M_PI_2); - - result[0] = sc1*quat1[0] + sc2*result[0]; - result[1] = sc1*quat1[1] + sc2*result[1]; - result[2] = sc1*quat1[2] + sc2*result[2]; - result[3] = sc1*quat1[3] + sc2*result[3]; - } -} - -void QuatInterpol(float *result, float *quat1, float *quat2, float t) -{ - float quat[4], omega, cosom, sinom, sc1, sc2; - - cosom = quat1[0]*quat2[0] + quat1[1]*quat2[1] + quat1[2]*quat2[2] + quat1[3]*quat2[3] ; - - /* rotate around shortest angle */ - if (cosom < 0.0f) { - cosom = -cosom; - quat[0]= -quat1[0]; - quat[1]= -quat1[1]; - quat[2]= -quat1[2]; - quat[3]= -quat1[3]; - } - else { - quat[0]= quat1[0]; - quat[1]= quat1[1]; - quat[2]= quat1[2]; - quat[3]= quat1[3]; - } - - if ((1.0f - cosom) > 0.0001f) { - omega = (float)acos(cosom); - sinom = (float)sin(omega); - sc1 = (float)sin((1 - t) * omega) / sinom; - sc2 = (float)sin(t * omega) / sinom; - } else { - sc1= 1.0f - t; - sc2= t; - } - - result[0] = sc1 * quat[0] + sc2 * quat2[0]; - result[1] = sc1 * quat[1] + sc2 * quat2[1]; - result[2] = sc1 * quat[2] + sc2 * quat2[2]; - result[3] = sc1 * quat[3] + sc2 * quat2[3]; -} - -void QuatAdd(float *result, float *quat1, float *quat2, float t) -{ - result[0]= quat1[0] + t*quat2[0]; - result[1]= quat1[1] + t*quat2[1]; - result[2]= quat1[2] + t*quat2[2]; - result[3]= quat1[3] + t*quat2[3]; -} - -void QuatCopy(float *q1, float *q2) -{ - q1[0]= q2[0]; - q1[1]= q2[1]; - q1[2]= q2[2]; - q1[3]= q2[3]; -} - -/* **************** DUAL QUATERNIONS ************** */ - -/* - Conversion routines between (regular quaternion, translation) and - dual quaternion. - - Version 1.0.0, February 7th, 2007 - - Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights - Reserved - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author(s) be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Author: Ladislav Kavan, kavanl@cs.tcd.ie - - Changes for Blender: - - renaming, style changes and optimizations - - added support for scaling -*/ - -void Mat4ToDQuat(float basemat[][4], float mat[][4], DualQuat *dq) -{ - float *t, *q, dscale[3], scale[3], basequat[4]; - float baseRS[4][4], baseinv[4][4], baseR[4][4], baseRinv[4][4]; - float R[4][4], S[4][4]; - - /* split scaling and rotation, there is probably a faster way to do - this, it's done like this now to correctly get negative scaling */ - Mat4MulMat4(baseRS, basemat, mat); - Mat4ToSize(baseRS, scale); - - VecCopyf(dscale, scale); - dscale[0] -= 1.0f; dscale[1] -= 1.0f; dscale[2] -= 1.0f; - - if((Det4x4(mat) < 0.0f) || VecLength(dscale) > 1e-4) { - /* extract R and S */ - Mat4ToQuat(baseRS, basequat); - QuatToMat4(basequat, baseR); - VecCopyf(baseR[3], baseRS[3]); - - Mat4Invert(baseinv, basemat); - Mat4MulMat4(R, baseinv, baseR); - - Mat4Invert(baseRinv, baseR); - Mat4MulMat4(S, baseRS, baseRinv); - - /* set scaling part */ - Mat4MulSerie(dq->scale, basemat, S, baseinv, 0, 0, 0, 0, 0); - dq->scale_weight= 1.0f; - } - else { - /* matrix does not contain scaling */ - Mat4CpyMat4(R, mat); - dq->scale_weight= 0.0f; - } - - /* non-dual part */ - Mat4ToQuat(R, dq->quat); - - /* dual part */ - t= R[3]; - q= dq->quat; - dq->trans[0]= -0.5f*( t[0]*q[1] + t[1]*q[2] + t[2]*q[3]); - dq->trans[1]= 0.5f*( t[0]*q[0] + t[1]*q[3] - t[2]*q[2]); - dq->trans[2]= 0.5f*(-t[0]*q[3] + t[1]*q[0] + t[2]*q[1]); - dq->trans[3]= 0.5f*( t[0]*q[2] - t[1]*q[1] + t[2]*q[0]); -} - -void DQuatToMat4(DualQuat *dq, float mat[][4]) -{ - float len, *t, q0[4]; - - /* regular quaternion */ - QuatCopy(q0, dq->quat); - - /* normalize */ - len= (float)sqrt(QuatDot(q0, q0)); - if(len != 0.0f) - QuatMulf(q0, 1.0f/len); - - /* rotation */ - QuatToMat4(q0, mat); - - /* translation */ - t= dq->trans; - mat[3][0]= 2.0f*(-t[0]*q0[1] + t[1]*q0[0] - t[2]*q0[3] + t[3]*q0[2]); - mat[3][1]= 2.0f*(-t[0]*q0[2] + t[1]*q0[3] + t[2]*q0[0] - t[3]*q0[1]); - mat[3][2]= 2.0f*(-t[0]*q0[3] - t[1]*q0[2] + t[2]*q0[1] + t[3]*q0[0]); - - /* note: this does not handle scaling */ -} - -void DQuatAddWeighted(DualQuat *dqsum, DualQuat *dq, float weight) -{ - int flipped= 0; - - /* make sure we interpolate quats in the right direction */ - if (QuatDot(dq->quat, dqsum->quat) < 0) { - flipped= 1; - weight= -weight; - } - - /* interpolate rotation and translation */ - dqsum->quat[0] += weight*dq->quat[0]; - dqsum->quat[1] += weight*dq->quat[1]; - dqsum->quat[2] += weight*dq->quat[2]; - dqsum->quat[3] += weight*dq->quat[3]; - - dqsum->trans[0] += weight*dq->trans[0]; - dqsum->trans[1] += weight*dq->trans[1]; - dqsum->trans[2] += weight*dq->trans[2]; - dqsum->trans[3] += weight*dq->trans[3]; - - /* interpolate scale - but only if needed */ - if (dq->scale_weight) { - float wmat[4][4]; - - if(flipped) /* we don't want negative weights for scaling */ - weight= -weight; - - Mat4CpyMat4(wmat, dq->scale); - Mat4MulFloat((float*)wmat, weight); - Mat4AddMat4(dqsum->scale, dqsum->scale, wmat); - dqsum->scale_weight += weight; - } -} - -void DQuatNormalize(DualQuat *dq, float totweight) -{ - float scale= 1.0f/totweight; - - QuatMulf(dq->quat, scale); - QuatMulf(dq->trans, scale); - - if(dq->scale_weight) { - float addweight= totweight - dq->scale_weight; - - if(addweight) { - dq->scale[0][0] += addweight; - dq->scale[1][1] += addweight; - dq->scale[2][2] += addweight; - dq->scale[3][3] += addweight; - } - - Mat4MulFloat((float*)dq->scale, scale); - dq->scale_weight= 1.0f; - } -} - -void DQuatMulVecfl(DualQuat *dq, float *co, float mat[][3]) -{ - float M[3][3], t[3], scalemat[3][3], len2; - float w= dq->quat[0], x= dq->quat[1], y= dq->quat[2], z= dq->quat[3]; - float t0= dq->trans[0], t1= dq->trans[1], t2= dq->trans[2], t3= dq->trans[3]; - - /* rotation matrix */ - M[0][0]= w*w + x*x - y*y - z*z; - M[1][0]= 2*(x*y - w*z); - M[2][0]= 2*(x*z + w*y); - - M[0][1]= 2*(x*y + w*z); - M[1][1]= w*w + y*y - x*x - z*z; - M[2][1]= 2*(y*z - w*x); - - M[0][2]= 2*(x*z - w*y); - M[1][2]= 2*(y*z + w*x); - M[2][2]= w*w + z*z - x*x - y*y; - - len2= QuatDot(dq->quat, dq->quat); - if(len2 > 0.0f) - len2= 1.0f/len2; - - /* translation */ - t[0]= 2*(-t0*x + w*t1 - t2*z + y*t3); - t[1]= 2*(-t0*y + t1*z - x*t3 + w*t2); - t[2]= 2*(-t0*z + x*t2 + w*t3 - t1*y); - - /* apply scaling */ - if(dq->scale_weight) - Mat4MulVecfl(dq->scale, co); - - /* apply rotation and translation */ - Mat3MulVecfl(M, co); - co[0]= (co[0] + t[0])*len2; - co[1]= (co[1] + t[1])*len2; - co[2]= (co[2] + t[2])*len2; - - /* compute crazyspace correction mat */ - if(mat) { - if(dq->scale_weight) { - Mat3CpyMat4(scalemat, dq->scale); - Mat3MulMat3(mat, M, scalemat); - } - else - Mat3CpyMat3(mat, M); - Mat3MulFloat((float*)mat, len2); - } -} - -void DQuatCpyDQuat(DualQuat *dq1, DualQuat *dq2) -{ - memcpy(dq1, dq2, sizeof(DualQuat)); -} - -/* **************** VIEW / PROJECTION ******************************** */ - - -void i_ortho( - float left, float right, - float bottom, float top, - float nearClip, float farClip, - float matrix[][4] -){ - float Xdelta, Ydelta, Zdelta; - - Xdelta = right - left; - Ydelta = top - bottom; - Zdelta = farClip - nearClip; - if (Xdelta == 0.0 || Ydelta == 0.0 || Zdelta == 0.0) { - return; - } - Mat4One(matrix); - matrix[0][0] = 2.0f/Xdelta; - matrix[3][0] = -(right + left)/Xdelta; - matrix[1][1] = 2.0f/Ydelta; - matrix[3][1] = -(top + bottom)/Ydelta; - matrix[2][2] = -2.0f/Zdelta; /* note: negate Z */ - matrix[3][2] = -(farClip + nearClip)/Zdelta; -} - -void i_window( - float left, float right, - float bottom, float top, - float nearClip, float farClip, - float mat[][4] -){ - float Xdelta, Ydelta, Zdelta; - - Xdelta = right - left; - Ydelta = top - bottom; - Zdelta = farClip - nearClip; - - if (Xdelta == 0.0 || Ydelta == 0.0 || Zdelta == 0.0) { - return; - } - mat[0][0] = nearClip * 2.0f/Xdelta; - mat[1][1] = nearClip * 2.0f/Ydelta; - mat[2][0] = (right + left)/Xdelta; /* note: negate Z */ - mat[2][1] = (top + bottom)/Ydelta; - mat[2][2] = -(farClip + nearClip)/Zdelta; - mat[2][3] = -1.0f; - mat[3][2] = (-2.0f * nearClip * farClip)/Zdelta; - mat[0][1] = mat[0][2] = mat[0][3] = - mat[1][0] = mat[1][2] = mat[1][3] = - mat[3][0] = mat[3][1] = mat[3][3] = 0.0; - -} - -void i_translate(float Tx, float Ty, float Tz, float mat[][4]) -{ - mat[3][0] += (Tx*mat[0][0] + Ty*mat[1][0] + Tz*mat[2][0]); - mat[3][1] += (Tx*mat[0][1] + Ty*mat[1][1] + Tz*mat[2][1]); - mat[3][2] += (Tx*mat[0][2] + Ty*mat[1][2] + Tz*mat[2][2]); -} - -void i_multmatrix( float icand[][4], float Vm[][4]) -{ - int row, col; - float temp[4][4]; - - for(row=0 ; row<4 ; row++) - for(col=0 ; col<4 ; col++) - temp[row][col] = icand[row][0] * Vm[0][col] - + icand[row][1] * Vm[1][col] - + icand[row][2] * Vm[2][col] - + icand[row][3] * Vm[3][col]; - Mat4CpyMat4(Vm, temp); -} - -void i_rotate(float angle, char axis, float mat[][4]) -{ - int col; - float temp[4]; - float cosine, sine; - - for(col=0; col<4 ; col++) /* init temp to zero matrix */ - temp[col] = 0; - - angle = (float)(angle*(3.1415926535/180.0)); - cosine = (float)cos(angle); - sine = (float)sin(angle); - switch(axis){ - case 'x': - case 'X': - for(col=0 ; col<4 ; col++) - temp[col] = cosine*mat[1][col] + sine*mat[2][col]; - for(col=0 ; col<4 ; col++) { - mat[2][col] = - sine*mat[1][col] + cosine*mat[2][col]; - mat[1][col] = temp[col]; - } - break; - - case 'y': - case 'Y': - for(col=0 ; col<4 ; col++) - temp[col] = cosine*mat[0][col] - sine*mat[2][col]; - for(col=0 ; col<4 ; col++) { - mat[2][col] = sine*mat[0][col] + cosine*mat[2][col]; - mat[0][col] = temp[col]; - } - break; - - case 'z': - case 'Z': - for(col=0 ; col<4 ; col++) - temp[col] = cosine*mat[0][col] + sine*mat[1][col]; - for(col=0 ; col<4 ; col++) { - mat[1][col] = - sine*mat[0][col] + cosine*mat[1][col]; - mat[0][col] = temp[col]; - } - break; - } -} - -void i_polarview(float dist, float azimuth, float incidence, float twist, float Vm[][4]) -{ - - Mat4One(Vm); - - i_translate(0.0, 0.0, -dist, Vm); - i_rotate(-twist,'z', Vm); - i_rotate(-incidence,'x', Vm); - i_rotate(-azimuth,'z', Vm); -} - -void i_lookat(float vx, float vy, float vz, float px, float py, float pz, float twist, float mat[][4]) -{ - float sine, cosine, hyp, hyp1, dx, dy, dz; - float mat1[4][4]; - - Mat4One(mat); - Mat4One(mat1); - - i_rotate(-twist,'z', mat); - - dx = px - vx; - dy = py - vy; - dz = pz - vz; - hyp = dx * dx + dz * dz; /* hyp squared */ - hyp1 = (float)sqrt(dy*dy + hyp); - hyp = (float)sqrt(hyp); /* the real hyp */ - - if (hyp1 != 0.0) { /* rotate X */ - sine = -dy / hyp1; - cosine = hyp /hyp1; - } else { - sine = 0; - cosine = 1.0f; - } - mat1[1][1] = cosine; - mat1[1][2] = sine; - mat1[2][1] = -sine; - mat1[2][2] = cosine; - - i_multmatrix(mat1, mat); - - mat1[1][1] = mat1[2][2] = 1.0f; /* be careful here to reinit */ - mat1[1][2] = mat1[2][1] = 0.0; /* those modified by the last */ - - /* paragraph */ - if (hyp != 0.0f) { /* rotate Y */ - sine = dx / hyp; - cosine = -dz / hyp; - } else { - sine = 0; - cosine = 1.0f; - } - mat1[0][0] = cosine; - mat1[0][2] = -sine; - mat1[2][0] = sine; - mat1[2][2] = cosine; - - i_multmatrix(mat1, mat); - i_translate(-vx,-vy,-vz, mat); /* translate viewpoint to origin */ -} - - - - - -/* ************************************************ */ - -void Mat3Orthogonal(float mat[][3], int axis) -{ - float size[3]; - size[0] = VecLength(mat[0]); - size[1] = VecLength(mat[1]); - size[2] = VecLength(mat[2]); - Normalize(mat[axis]); - switch(axis) - { - case 0: - if (Inpf(mat[0], mat[1]) < 1) { - Crossf(mat[2], mat[0], mat[1]); - Normalize(mat[2]); - Crossf(mat[1], mat[2], mat[0]); - } else if (Inpf(mat[0], mat[2]) < 1) { - Crossf(mat[1], mat[2], mat[0]); - Normalize(mat[1]); - Crossf(mat[2], mat[0], mat[1]); - } else { - float vec[3] = {mat[0][1], mat[0][2], mat[0][0]}; - - Crossf(mat[2], mat[0], vec); - Normalize(mat[2]); - Crossf(mat[1], mat[2], mat[0]); - } - case 1: - if (Inpf(mat[1], mat[0]) < 1) { - Crossf(mat[2], mat[0], mat[1]); - Normalize(mat[2]); - Crossf(mat[0], mat[1], mat[2]); - } else if (Inpf(mat[0], mat[2]) < 1) { - Crossf(mat[0], mat[1], mat[2]); - Normalize(mat[0]); - Crossf(mat[2], mat[0], mat[1]); - } else { - float vec[3] = {mat[1][1], mat[1][2], mat[1][0]}; - - Crossf(mat[0], mat[1], vec); - Normalize(mat[0]); - Crossf(mat[2], mat[0], mat[1]); - } - case 2: - if (Inpf(mat[2], mat[0]) < 1) { - Crossf(mat[1], mat[2], mat[0]); - Normalize(mat[1]); - Crossf(mat[0], mat[1], mat[2]); - } else if (Inpf(mat[2], mat[1]) < 1) { - Crossf(mat[0], mat[1], mat[2]); - Normalize(mat[0]); - Crossf(mat[1], mat[2], mat[0]); - } else { - float vec[3] = {mat[2][1], mat[2][2], mat[2][0]}; - - Crossf(mat[0], vec, mat[2]); - Normalize(mat[0]); - Crossf(mat[1], mat[2], mat[0]); - } - } - VecMulf(mat[0], size[0]); - VecMulf(mat[1], size[1]); - VecMulf(mat[2], size[2]); -} - -void Mat4Orthogonal(float mat[][4], int axis) -{ - float size[3]; - size[0] = VecLength(mat[0]); - size[1] = VecLength(mat[1]); - size[2] = VecLength(mat[2]); - Normalize(mat[axis]); - switch(axis) - { - case 0: - if (Inpf(mat[0], mat[1]) < 1) { - Crossf(mat[2], mat[0], mat[1]); - Normalize(mat[2]); - Crossf(mat[1], mat[2], mat[0]); - } else if (Inpf(mat[0], mat[2]) < 1) { - Crossf(mat[1], mat[2], mat[0]); - Normalize(mat[1]); - Crossf(mat[2], mat[0], mat[1]); - } else { - float vec[3] = {mat[0][1], mat[0][2], mat[0][0]}; - - Crossf(mat[2], mat[0], vec); - Normalize(mat[2]); - Crossf(mat[1], mat[2], mat[0]); - } - case 1: - Normalize(mat[0]); - if (Inpf(mat[1], mat[0]) < 1) { - Crossf(mat[2], mat[0], mat[1]); - Normalize(mat[2]); - Crossf(mat[0], mat[1], mat[2]); - } else if (Inpf(mat[0], mat[2]) < 1) { - Crossf(mat[0], mat[1], mat[2]); - Normalize(mat[0]); - Crossf(mat[2], mat[0], mat[1]); - } else { - float vec[3] = {mat[1][1], mat[1][2], mat[1][0]}; - - Crossf(mat[0], mat[1], vec); - Normalize(mat[0]); - Crossf(mat[2], mat[0], mat[1]); - } - case 2: - if (Inpf(mat[2], mat[0]) < 1) { - Crossf(mat[1], mat[2], mat[0]); - Normalize(mat[1]); - Crossf(mat[0], mat[1], mat[2]); - } else if (Inpf(mat[2], mat[1]) < 1) { - Crossf(mat[0], mat[1], mat[2]); - Normalize(mat[0]); - Crossf(mat[1], mat[2], mat[0]); - } else { - float vec[3] = {mat[2][1], mat[2][2], mat[2][0]}; - - Crossf(mat[0], vec, mat[2]); - Normalize(mat[0]); - Crossf(mat[1], mat[2], mat[0]); - } - } - VecMulf(mat[0], size[0]); - VecMulf(mat[1], size[1]); - VecMulf(mat[2], size[2]); -} - -int IsMat3Orthogonal(float mat[][3]) -{ - if (fabs(Inpf(mat[0], mat[1])) > 1.5 * FLT_EPSILON) - return 0; - - if (fabs(Inpf(mat[1], mat[2])) > 1.5 * FLT_EPSILON) - return 0; - - if (fabs(Inpf(mat[0], mat[2])) > 1.5 * FLT_EPSILON) - return 0; - - return 1; -} - -int IsMat4Orthogonal(float mat[][4]) -{ - if (fabs(Inpf(mat[0], mat[1])) > 1.5 * FLT_EPSILON) - return 0; - - if (fabs(Inpf(mat[1], mat[2])) > 1.5 * FLT_EPSILON) - return 0; - - if (fabs(Inpf(mat[0], mat[2])) > 1.5 * FLT_EPSILON) - return 0; - - return 1; -} - -void Mat3Ortho(float mat[][3]) -{ - Normalize(mat[0]); - Normalize(mat[1]); - Normalize(mat[2]); -} - -void Mat4Ortho(float mat[][4]) -{ - float len; - - len= Normalize(mat[0]); - if(len!=0.0) mat[0][3]/= len; - len= Normalize(mat[1]); - if(len!=0.0) mat[1][3]/= len; - len= Normalize(mat[2]); - if(len!=0.0) mat[2][3]/= len; -} - -void VecCopyf(float *v1, float *v2) -{ - v1[0]= v2[0]; - v1[1]= v2[1]; - v1[2]= v2[2]; -} - -int VecLen( int *v1, int *v2) -{ - float x,y,z; - - x=(float)(v1[0]-v2[0]); - y=(float)(v1[1]-v2[1]); - z=(float)(v1[2]-v2[2]); - return (int)floor(sqrt(x*x+y*y+z*z)); -} - -float VecLenf(float v1[3], float v2[3]) -{ - float x,y,z; - - x=v1[0]-v2[0]; - y=v1[1]-v2[1]; - z=v1[2]-v2[2]; - return (float)sqrt(x*x+y*y+z*z); -} - -float VecLength(float *v) -{ - return (float) sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); -} - -void VecAddf(float *v, float *v1, float *v2) -{ - v[0]= v1[0]+ v2[0]; - v[1]= v1[1]+ v2[1]; - v[2]= v1[2]+ v2[2]; -} - -void VecSubf(float *v, float *v1, float *v2) -{ - v[0]= v1[0]- v2[0]; - v[1]= v1[1]- v2[1]; - v[2]= v1[2]- v2[2]; -} - -void VecMulVecf(float *v, float *v1, float *v2) -{ - v[0] = v1[0] * v2[0]; - v[1] = v1[1] * v2[1]; - v[2] = v1[2] * v2[2]; -} - -void VecLerpf(float *target, const float *a, const float *b, const float t) -{ - const float s = 1.0f-t; - - target[0]= s*a[0] + t*b[0]; - target[1]= s*a[1] + t*b[1]; - target[2]= s*a[2] + t*b[2]; -} - -void Vec2Lerpf(float *target, const float *a, const float *b, const float t) -{ - const float s = 1.0f-t; - - target[0]= s*a[0] + t*b[0]; - target[1]= s*a[1] + t*b[1]; -} - -/* weight 3 vectors, (VecWeightf in 2.4x) - * 'w' must be unit length but is not a vector, just 3 weights */ -void VecLerp3f(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3]) -{ - p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2]; - p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2]; - p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2]; -} - -/* weight 3 2D vectors, (Vec2Weightf in 2.4x) - * 'w' must be unit length but is not a vector, just 3 weights */ -void Vec2Lerp3f(float p[2], const float v1[2], const float v2[2], const float v3[2], const float w[3]) -{ - p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2]; - p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2]; -} - -void VecMidf(float *v, float *v1, float *v2) -{ - v[0]= 0.5f*(v1[0]+ v2[0]); - v[1]= 0.5f*(v1[1]+ v2[1]); - v[2]= 0.5f*(v1[2]+ v2[2]); -} - -void VecMulf(float *v1, float f) -{ - - v1[0]*= f; - v1[1]*= f; - v1[2]*= f; -} - -void VecNegf(float *v1) -{ - v1[0] = -v1[0]; - v1[1] = -v1[1]; - v1[2] = -v1[2]; -} - -void VecOrthoBasisf(float *v, float *v1, float *v2) -{ - const float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]); - - if (f < 1e-35f) { - // degenerate case - v1[0] = (v[2] < 0.0f) ? -1.0f : 1.0f; - v1[1] = v1[2] = v2[0] = v2[2] = 0.0f; - v2[1] = 1.0f; - } - else { - const float d= 1.0f/f; - - v1[0] = v[1]*d; - v1[1] = -v[0]*d; - v1[2] = 0.0f; - v2[0] = -v[2]*v1[1]; - v2[1] = v[2]*v1[0]; - v2[2] = v[0]*v1[1] - v[1]*v1[0]; - } -} - -int VecLenCompare(float *v1, float *v2, float limit) -{ - float x,y,z; - - x=v1[0]-v2[0]; - y=v1[1]-v2[1]; - z=v1[2]-v2[2]; - - return ((x*x + y*y + z*z) < (limit*limit)); -} - -int VecCompare( float *v1, float *v2, float limit) -{ - if( fabs(v1[0]-v2[0])<limit ) - if( fabs(v1[1]-v2[1])<limit ) - if( fabs(v1[2]-v2[2])<limit ) return 1; - return 0; -} - -int VecEqual(float *v1, float *v2) -{ - return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); -} - -int VecIsNull(float *v) -{ - return (v[0] == 0 && v[1] == 0 && v[2] == 0); -} - -void CalcNormShort( short *v1, short *v2, short *v3, float *n) /* is also cross product */ -{ - float n1[3],n2[3]; - - n1[0]= (float)(v1[0]-v2[0]); - n2[0]= (float)(v2[0]-v3[0]); - n1[1]= (float)(v1[1]-v2[1]); - n2[1]= (float)(v2[1]-v3[1]); - n1[2]= (float)(v1[2]-v2[2]); - n2[2]= (float)(v2[2]-v3[2]); - n[0]= n1[1]*n2[2]-n1[2]*n2[1]; - n[1]= n1[2]*n2[0]-n1[0]*n2[2]; - n[2]= n1[0]*n2[1]-n1[1]*n2[0]; - Normalize(n); -} - -void CalcNormLong( int* v1, int*v2, int*v3, float *n) -{ - float n1[3],n2[3]; - - n1[0]= (float)(v1[0]-v2[0]); - n2[0]= (float)(v2[0]-v3[0]); - n1[1]= (float)(v1[1]-v2[1]); - n2[1]= (float)(v2[1]-v3[1]); - n1[2]= (float)(v1[2]-v2[2]); - n2[2]= (float)(v2[2]-v3[2]); - n[0]= n1[1]*n2[2]-n1[2]*n2[1]; - n[1]= n1[2]*n2[0]-n1[0]*n2[2]; - n[2]= n1[0]*n2[1]-n1[1]*n2[0]; - Normalize(n); -} - -float CalcNormFloat( float *v1, float *v2, float *v3, float *n) -{ - float n1[3],n2[3]; - - n1[0]= v1[0]-v2[0]; - n2[0]= v2[0]-v3[0]; - n1[1]= v1[1]-v2[1]; - n2[1]= v2[1]-v3[1]; - n1[2]= v1[2]-v2[2]; - n2[2]= v2[2]-v3[2]; - n[0]= n1[1]*n2[2]-n1[2]*n2[1]; - n[1]= n1[2]*n2[0]-n1[0]*n2[2]; - n[2]= n1[0]*n2[1]-n1[1]*n2[0]; - return Normalize(n); -} - -float CalcNormFloat4( float *v1, float *v2, float *v3, float *v4, float *n) -{ - /* real cross! */ - float n1[3],n2[3]; - - n1[0]= v1[0]-v3[0]; - n1[1]= v1[1]-v3[1]; - n1[2]= v1[2]-v3[2]; - - n2[0]= v2[0]-v4[0]; - n2[1]= v2[1]-v4[1]; - n2[2]= v2[2]-v4[2]; - - n[0]= n1[1]*n2[2]-n1[2]*n2[1]; - n[1]= n1[2]*n2[0]-n1[0]*n2[2]; - n[2]= n1[0]*n2[1]-n1[1]*n2[0]; - - return Normalize(n); -} - - -void CalcCent3f(float *cent, float *v1, float *v2, float *v3) -{ - - cent[0]= 0.33333f*(v1[0]+v2[0]+v3[0]); - cent[1]= 0.33333f*(v1[1]+v2[1]+v3[1]); - cent[2]= 0.33333f*(v1[2]+v2[2]+v3[2]); -} - -void CalcCent4f(float *cent, float *v1, float *v2, float *v3, float *v4) -{ - - cent[0]= 0.25f*(v1[0]+v2[0]+v3[0]+v4[0]); - cent[1]= 0.25f*(v1[1]+v2[1]+v3[1]+v4[1]); - cent[2]= 0.25f*(v1[2]+v2[2]+v3[2]+v4[2]); -} - -float Sqrt3f(float f) -{ - if(f==0.0) return 0; - if(f<0) return (float)(-exp(log(-f)/3)); - else return (float)(exp(log(f)/3)); -} - -double Sqrt3d(double d) -{ - if(d==0.0) return 0; - if(d<0) return -exp(log(-d)/3); - else return exp(log(d)/3); -} - -void NormalShortToFloat(float *out, short *in) -{ - out[0] = in[0] / 32767.0f; - out[1] = in[1] / 32767.0f; - out[2] = in[2] / 32767.0f; -} - -void NormalFloatToShort(short *out, float *in) -{ - out[0] = (short)(in[0] * 32767.0); - out[1] = (short)(in[1] * 32767.0); - out[2] = (short)(in[2] * 32767.0); -} - -/* distance v1 to line v2-v3 */ -/* using Hesse formula, NO LINE PIECE! */ -float DistVL2Dfl( float *v1, float *v2, float *v3) { - float a[2],deler; - - a[0]= v2[1]-v3[1]; - a[1]= v3[0]-v2[0]; - deler= (float)sqrt(a[0]*a[0]+a[1]*a[1]); - if(deler== 0.0f) return 0; - - return (float)(fabs((v1[0]-v2[0])*a[0]+(v1[1]-v2[1])*a[1])/deler); - -} - -/* distance v1 to line-piece v2-v3 */ -float PdistVL2Dfl( float *v1, float *v2, float *v3) -{ - float labda, rc[2], pt[2], len; - - rc[0]= v3[0]-v2[0]; - rc[1]= v3[1]-v2[1]; - len= rc[0]*rc[0]+ rc[1]*rc[1]; - if(len==0.0) { - rc[0]= v1[0]-v2[0]; - rc[1]= v1[1]-v2[1]; - return (float)(sqrt(rc[0]*rc[0]+ rc[1]*rc[1])); - } - - labda= ( rc[0]*(v1[0]-v2[0]) + rc[1]*(v1[1]-v2[1]) )/len; - if(labda<=0.0) { - pt[0]= v2[0]; - pt[1]= v2[1]; - } - else if(labda>=1.0) { - pt[0]= v3[0]; - pt[1]= v3[1]; - } - else { - pt[0]= labda*rc[0]+v2[0]; - pt[1]= labda*rc[1]+v2[1]; - } - - rc[0]= pt[0]-v1[0]; - rc[1]= pt[1]-v1[1]; - return (float)sqrt(rc[0]*rc[0]+ rc[1]*rc[1]); -} - -float AreaF2Dfl( float *v1, float *v2, float *v3) -{ - return (float)(0.5*fabs( (v1[0]-v2[0])*(v2[1]-v3[1]) + (v1[1]-v2[1])*(v3[0]-v2[0]) )); -} - - -float AreaQ3Dfl( float *v1, float *v2, float *v3, float *v4) /* only convex Quadrilaterals */ -{ - float len, vec1[3], vec2[3], n[3]; - - VecSubf(vec1, v2, v1); - VecSubf(vec2, v4, v1); - Crossf(n, vec1, vec2); - len= Normalize(n); - - VecSubf(vec1, v4, v3); - VecSubf(vec2, v2, v3); - Crossf(n, vec1, vec2); - len+= Normalize(n); - - return (len/2.0f); -} - -float AreaT3Dfl( float *v1, float *v2, float *v3) /* Triangles */ -{ - float len, vec1[3], vec2[3], n[3]; - - VecSubf(vec1, v3, v2); - VecSubf(vec2, v1, v2); - Crossf(n, vec1, vec2); - len= Normalize(n); - - return (len/2.0f); -} - -#define MAX2(x,y) ( (x)>(y) ? (x) : (y) ) -#define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) ) - - -float AreaPoly3Dfl(int nr, float *verts, float *normal) -{ - float x, y, z, area, max; - float *cur, *prev; - int a, px=0, py=1; - - /* first: find dominant axis: 0==X, 1==Y, 2==Z */ - x= (float)fabs(normal[0]); - y= (float)fabs(normal[1]); - z= (float)fabs(normal[2]); - max = MAX3(x, y, z); - if(max==y) py=2; - else if(max==x) { - px=1; - py= 2; - } - - /* The Trapezium Area Rule */ - prev= verts+3*(nr-1); - cur= verts; - area= 0; - for(a=0; a<nr; a++) { - area+= (cur[px]-prev[px])*(cur[py]+prev[py]); - prev= cur; - cur+=3; - } - - return (float)fabs(0.5*area/max); -} - -/* intersect Line-Line, shorts */ -short IsectLL2Ds(short *v1, short *v2, short *v3, short *v4) -{ - /* return: - -1: colliniar - 0: no intersection of segments - 1: exact intersection of segments - 2: cross-intersection of segments - */ - float div, labda, mu; - - div= (float)((v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0])); - if(div==0.0f) return -1; - - labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div; - - mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div; - - if(labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) { - if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return 1; - return 2; - } - return 0; -} - -/* intersect Line-Line, floats */ -short IsectLL2Df(float *v1, float *v2, float *v3, float *v4) -{ - /* return: - -1: colliniar -0: no intersection of segments -1: exact intersection of segments -2: cross-intersection of segments - */ - float div, labda, mu; - - div= (v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]); - if(div==0.0) return -1; - - labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div; - - mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div; - - if(labda>=0.0 && labda<=1.0 && mu>=0.0 && mu<=1.0) { - if(labda==0.0 || labda==1.0 || mu==0.0 || mu==1.0) return 1; - return 2; - } - return 0; -} - -/* --1: colliniar - 1: intersection - -*/ -static short IsectLLPt2Df(float x0,float y0,float x1,float y1, - float x2,float y2,float x3,float y3, float *xi,float *yi) - -{ - /* - this function computes the intersection of the sent lines - and returns the intersection point, note that the function assumes - the lines intersect. the function can handle vertical as well - as horizontal lines. note the function isn't very clever, it simply - applies the math, but we don't need speed since this is a - pre-processing step - */ - float c1,c2, // constants of linear equations - det_inv, // the inverse of the determinant of the coefficient - m1,m2; // the slopes of each line - /* - compute slopes, note the cludge for infinity, however, this will - be close enough - */ - if ( fabs( x1-x0 ) > 0.000001 ) - m1 = ( y1-y0 ) / ( x1-x0 ); - else - return -1; /*m1 = ( float ) 1e+10;*/ // close enough to infinity - - if ( fabs( x3-x2 ) > 0.000001 ) - m2 = ( y3-y2 ) / ( x3-x2 ); - else - return -1; /*m2 = ( float ) 1e+10;*/ // close enough to infinity - - if (fabs(m1-m2) < 0.000001) - return -1; /* paralelle lines */ - -// compute constants - - c1 = ( y0-m1*x0 ); - c2 = ( y2-m2*x2 ); - -// compute the inverse of the determinate - - det_inv = 1.0f / ( -m1 + m2 ); - -// use Kramers rule to compute xi and yi - - *xi= ( ( -c2 + c1 ) *det_inv ); - *yi= ( ( m2*c1 - m1*c2 ) *det_inv ); - - return 1; -} // end Intersect_Lines - -#define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1])) -/* point in tri */ -int IsectPT2Df(float pt[2], float v1[2], float v2[2], float v3[2]) -{ - if (SIDE_OF_LINE(v1,v2,pt)>=0.0) { - if (SIDE_OF_LINE(v2,v3,pt)>=0.0) { - if (SIDE_OF_LINE(v3,v1,pt)>=0.0) { - return 1; - } - } - } else { - if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0) ) { - if (! (SIDE_OF_LINE(v3,v1,pt)>=0.0)) { - return -1; - } - } - } - - return 0; -} -/* point in quad - only convex quads */ -int IsectPQ2Df(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2]) -{ - if (SIDE_OF_LINE(v1,v2,pt)>=0.0) { - if (SIDE_OF_LINE(v2,v3,pt)>=0.0) { - if (SIDE_OF_LINE(v3,v4,pt)>=0.0) { - if (SIDE_OF_LINE(v4,v1,pt)>=0.0) { - return 1; - } - } - } - } else { - if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0) ) { - if (! (SIDE_OF_LINE(v3,v4,pt)>=0.0)) { - if (! (SIDE_OF_LINE(v4,v1,pt)>=0.0)) { - return -1; - } - } - } - } - - return 0; -} - - -/** - * - * @param min - * @param max - * @param vec - */ -void MinMax3(float *min, float *max, float *vec) -{ - if(min[0]>vec[0]) min[0]= vec[0]; - if(min[1]>vec[1]) min[1]= vec[1]; - if(min[2]>vec[2]) min[2]= vec[2]; - - if(max[0]<vec[0]) max[0]= vec[0]; - if(max[1]<vec[1]) max[1]= vec[1]; - if(max[2]<vec[2]) max[2]= vec[2]; -} - -static float TriSignedArea(float *v1, float *v2, float *v3, int i, int j) -{ - return 0.5f*((v1[i]-v2[i])*(v2[j]-v3[j]) + (v1[j]-v2[j])*(v3[i]-v2[i])); -} - -static int BarycentricWeights(float *v1, float *v2, float *v3, float *co, float *n, float *w) -{ - float xn, yn, zn, a1, a2, a3, asum; - short i, j; - - /* find best projection of face XY, XZ or YZ: barycentric weights of - the 2d projected coords are the same and faster to compute */ - xn= (float)fabs(n[0]); - yn= (float)fabs(n[1]); - zn= (float)fabs(n[2]); - if(zn>=xn && zn>=yn) {i= 0; j= 1;} - else if(yn>=xn && yn>=zn) {i= 0; j= 2;} - else {i= 1; j= 2;} - - a1= TriSignedArea(v2, v3, co, i, j); - a2= TriSignedArea(v3, v1, co, i, j); - a3= TriSignedArea(v1, v2, co, i, j); - - asum= a1 + a2 + a3; - - if (fabs(asum) < FLT_EPSILON) { - /* zero area triangle */ - w[0]= w[1]= w[2]= 1.0f/3.0f; - return 1; - } - - asum= 1.0f/asum; - w[0]= a1*asum; - w[1]= a2*asum; - w[2]= a3*asum; - - return 0; -} - -void InterpWeightsQ3Dfl(float *v1, float *v2, float *v3, float *v4, float *co, float *w) -{ - float w2[3]; - - w[0]= w[1]= w[2]= w[3]= 0.0f; - - /* first check for exact match */ - if(VecEqual(co, v1)) - w[0]= 1.0f; - else if(VecEqual(co, v2)) - w[1]= 1.0f; - else if(VecEqual(co, v3)) - w[2]= 1.0f; - else if(v4 && VecEqual(co, v4)) - w[3]= 1.0f; - else { - /* otherwise compute barycentric interpolation weights */ - float n1[3], n2[3], n[3]; - int degenerate; - - VecSubf(n1, v1, v3); - if (v4) { - VecSubf(n2, v2, v4); - } - else { - VecSubf(n2, v2, v3); - } - Crossf(n, n1, n2); - - /* OpenGL seems to split this way, so we do too */ - if (v4) { - degenerate= BarycentricWeights(v1, v2, v4, co, n, w); - SWAP(float, w[2], w[3]); - - if(degenerate || (w[0] < 0.0f)) { - /* if w[1] is negative, co is on the other side of the v1-v3 edge, - so we interpolate using the other triangle */ - degenerate= BarycentricWeights(v2, v3, v4, co, n, w2); - - if(!degenerate) { - w[0]= 0.0f; - w[1]= w2[0]; - w[2]= w2[1]; - w[3]= w2[2]; - } - } - } - else - BarycentricWeights(v1, v2, v3, co, n, w); - } -} - -/* Mean value weights - smooth interpolation weights for polygons with - * more than 3 vertices */ -static float MeanValueHalfTan(float *v1, float *v2, float *v3) -{ - float d2[3], d3[3], cross[3], area, dot, len; - - VecSubf(d2, v2, v1); - VecSubf(d3, v3, v1); - Crossf(cross, d2, d3); - - area= VecLength(cross); - dot= Inpf(d2, d3); - len= VecLength(d2)*VecLength(d3); - - if(area == 0.0f) - return 0.0f; - else - return (len - dot)/area; -} - -void MeanValueWeights(float v[][3], int n, float *co, float *w) -{ - float totweight, t1, t2, len, *vmid, *vprev, *vnext; - int i; - - totweight= 0.0f; - - for(i=0; i<n; i++) { - vmid= v[i]; - vprev= (i == 0)? v[n-1]: v[i-1]; - vnext= (i == n-1)? v[0]: v[i+1]; - - t1= MeanValueHalfTan(co, vprev, vmid); - t2= MeanValueHalfTan(co, vmid, vnext); - - len= VecLenf(co, vmid); - w[i]= (t1+t2)/len; - totweight += w[i]; - } - - if(totweight != 0.0f) - for(i=0; i<n; i++) - w[i] /= totweight; -} - - -/* ************ EULER *************** */ - -/* Euler Rotation Order Code: - * was adapted from - ANSI C code from the article - "Euler Angle Conversion" - by Ken Shoemake, shoemake@graphics.cis.upenn.edu - in "Graphics Gems IV", Academic Press, 1994 - * for use in Blender - */ - -/* Type for rotation order info - see wiki for derivation details */ -typedef struct RotOrderInfo { - short axis[3]; - short parity; /* parity of axis permutation (even=0, odd=1) - 'n' in original code */ -} RotOrderInfo; - -/* Array of info for Rotation Order calculations - * WARNING: must be kept in same order as eEulerRotationOrders - */ -static RotOrderInfo rotOrders[]= { - /* i, j, k, n */ - {{0, 1, 2}, 0}, // XYZ - {{0, 2, 1}, 1}, // XZY - {{1, 0, 2}, 1}, // YXZ - {{1, 2, 0}, 0}, // YZX - {{2, 0, 1}, 0}, // ZXY - {{2, 1, 0}, 1} // ZYZ -}; - -/* Get relevant pointer to rotation order set from the array - * NOTE: since we start at 1 for the values, but arrays index from 0, - * there is -1 factor involved in this process... - */ -#define GET_ROTATIONORDER_INFO(order) (((order)>=1) ? &rotOrders[(order)-1] : &rotOrders[0]) - -/* Construct quaternion from Euler angles (in radians). */ -void EulOToQuat(float e[3], short order, float q[4]) -{ - RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); - short i=R->axis[0], j=R->axis[1], k=R->axis[2]; - double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; - double a[3]; - - ti = e[i]/2; tj = e[j]/2; th = e[k]/2; - - if (R->parity) e[j] = -e[j]; - - ci = cos(ti); cj = cos(tj); ch = cos(th); - si = sin(ti); sj = sin(tj); sh = sin(th); - - cc = ci*ch; cs = ci*sh; - sc = si*ch; ss = si*sh; - - a[i] = cj*sc - sj*cs; - a[j] = cj*ss + sj*cc; - a[k] = cj*cs - sj*sc; - - q[0] = cj*cc + sj*ss; - q[1] = a[0]; - q[2] = a[1]; - q[3] = a[2]; - - if (R->parity) q[j] = -q[j]; -} - -/* Convert quaternion to Euler angles (in radians). */ -void QuatToEulO(float q[4], float e[3], short order) -{ - float M[3][3]; - - QuatToMat3(q, M); - Mat3ToEulO(M, e, order); -} - -/* Construct 3x3 matrix from Euler angles (in radians). */ -void EulOToMat3(float e[3], short order, float M[3][3]) -{ - RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); - short i=R->axis[0], j=R->axis[1], k=R->axis[2]; - double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; - - if (R->parity) { - ti = -e[i]; tj = -e[j]; th = -e[k]; - } - else { - ti = e[i]; tj = e[j]; th = e[k]; - } - - ci = cos(ti); cj = cos(tj); ch = cos(th); - si = sin(ti); sj = sin(tj); sh = sin(th); - - cc = ci*ch; cs = ci*sh; - sc = si*ch; ss = si*sh; - - M[i][i] = cj*ch; M[j][i] = sj*sc-cs; M[k][i] = sj*cc+ss; - M[i][j] = cj*sh; M[j][j] = sj*ss+cc; M[k][j] = sj*cs-sc; - M[i][k] = -sj; M[j][k] = cj*si; M[k][k] = cj*ci; -} - -/* Construct 4x4 matrix from Euler angles (in radians). */ -void EulOToMat4(float e[3], short order, float M[4][4]) -{ - float m[3][3]; - - /* for now, we'll just do this the slow way (i.e. copying matrices) */ - Mat3Ortho(m); - EulOToMat3(e, order, m); - Mat4CpyMat3(M, m); -} - -/* Convert 3x3 matrix to Euler angles (in radians). */ -void Mat3ToEulO(float M[3][3], float e[3], short order) -{ - RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); - short i=R->axis[0], j=R->axis[1], k=R->axis[2]; - double cy = sqrt(M[i][i]*M[i][i] + M[i][j]*M[i][j]); - - if (cy > 16*FLT_EPSILON) { - e[i] = atan2(M[j][k], M[k][k]); - e[j] = atan2(-M[i][k], cy); - e[k] = atan2(M[i][j], M[i][i]); - } - else { - e[i] = atan2(-M[k][j], M[j][j]); - e[j] = atan2(-M[i][k], cy); - e[k] = 0; - } - - if (R->parity) { - e[0] = -e[0]; - e[1] = -e[1]; - e[2] = -e[2]; - } -} - -/* Convert 4x4 matrix to Euler angles (in radians). */ -void Mat4ToEulO(float M[4][4], float e[3], short order) -{ - float m[3][3]; - - /* for now, we'll just do this the slow way (i.e. copying matrices) */ - Mat3CpyMat4(m, M); - Mat3Ortho(m); - Mat3ToEulO(m, e, order); -} - -/* returns two euler calculation methods, so we can pick the best */ -static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, short order) -{ - RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); - short i=R->axis[0], j=R->axis[1], k=R->axis[2]; - float m[3][3]; - double cy; - - /* process the matrix first */ - Mat3CpyMat3(m, M); - Mat3Ortho(m); - - cy= sqrt(m[i][i]*m[i][i] + m[i][j]*m[i][j]); - - if (cy > 16*FLT_EPSILON) { - e1[i] = atan2(m[j][k], m[k][k]); - e1[j] = atan2(-m[i][k], cy); - e1[k] = atan2(m[i][j], m[i][i]); - - e2[i] = atan2(-m[j][k], -m[k][k]); - e2[j] = atan2(-m[i][k], -cy); - e2[k] = atan2(-m[i][j], -m[i][i]); - } - else { - e1[i] = atan2(-m[k][j], m[j][j]); - e1[j] = atan2(-m[i][k], cy); - e1[k] = 0; - - VecCopyf(e2, e1); - } - - if (R->parity) { - e1[0] = -e1[0]; - e1[1] = -e1[1]; - e1[2] = -e1[2]; - - e2[0] = -e2[0]; - e2[1] = -e2[1]; - e2[2] = -e2[2]; - } -} - -/* uses 2 methods to retrieve eulers, and picks the closest */ -void Mat3ToCompatibleEulO(float mat[3][3], float eul[3], float oldrot[3], short order) -{ - float eul1[3], eul2[3]; - float d1, d2; - - mat3_to_eulo2(mat, eul1, eul2, order); - - compatible_eul(eul1, oldrot); - compatible_eul(eul2, oldrot); - - d1= (float)fabs(eul1[0]-oldrot[0]) + (float)fabs(eul1[1]-oldrot[1]) + (float)fabs(eul1[2]-oldrot[2]); - d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]); - - /* return best, which is just the one with lowest difference */ - if (d1 > d2) - VecCopyf(eul, eul2); - else - VecCopyf(eul, eul1); -} - -/* rotate the given euler by the given angle on the specified axis */ -// NOTE: is this safe to do with different axis orders? -void eulerO_rot(float beul[3], float ang, char axis, short order) -{ - float eul[3], mat1[3][3], mat2[3][3], totmat[3][3]; - - eul[0]= eul[1]= eul[2]= 0.0f; - if (axis=='x') - eul[0]= ang; - else if (axis=='y') - eul[1]= ang; - else - eul[2]= ang; - - EulOToMat3(eul, order, mat1); - EulOToMat3(beul, order, mat2); - - Mat3MulMat3(totmat, mat2, mat1); - - Mat3ToEulO(totmat, beul, order); -} - -/* ************ EULER (old XYZ) *************** */ - -/* XYZ order */ -void EulToMat3( float *eul, float mat[][3]) -{ - double ci, cj, ch, si, sj, sh, cc, cs, sc, ss; - - ci = cos(eul[0]); - cj = cos(eul[1]); - ch = cos(eul[2]); - si = sin(eul[0]); - sj = sin(eul[1]); - sh = sin(eul[2]); - cc = ci*ch; - cs = ci*sh; - sc = si*ch; - ss = si*sh; - - mat[0][0] = (float)(cj*ch); - mat[1][0] = (float)(sj*sc-cs); - mat[2][0] = (float)(sj*cc+ss); - mat[0][1] = (float)(cj*sh); - mat[1][1] = (float)(sj*ss+cc); - mat[2][1] = (float)(sj*cs-sc); - mat[0][2] = (float)-sj; - mat[1][2] = (float)(cj*si); - mat[2][2] = (float)(cj*ci); - -} - -/* XYZ order */ -void EulToMat4( float *eul,float mat[][4]) -{ - double ci, cj, ch, si, sj, sh, cc, cs, sc, ss; - - ci = cos(eul[0]); - cj = cos(eul[1]); - ch = cos(eul[2]); - si = sin(eul[0]); - sj = sin(eul[1]); - sh = sin(eul[2]); - cc = ci*ch; - cs = ci*sh; - sc = si*ch; - ss = si*sh; - - mat[0][0] = (float)(cj*ch); - mat[1][0] = (float)(sj*sc-cs); - mat[2][0] = (float)(sj*cc+ss); - mat[0][1] = (float)(cj*sh); - mat[1][1] = (float)(sj*ss+cc); - mat[2][1] = (float)(sj*cs-sc); - mat[0][2] = (float)-sj; - mat[1][2] = (float)(cj*si); - mat[2][2] = (float)(cj*ci); - - - mat[3][0]= mat[3][1]= mat[3][2]= mat[0][3]= mat[1][3]= mat[2][3]= 0.0f; - mat[3][3]= 1.0f; -} - -/* returns two euler calculation methods, so we can pick the best */ -/* XYZ order */ -static void mat3_to_eul2(float tmat[][3], float *eul1, float *eul2) -{ - float cy, quat[4], mat[3][3]; - - Mat3ToQuat(tmat, quat); - QuatToMat3(quat, mat); - Mat3CpyMat3(mat, tmat); - Mat3Ortho(mat); - - cy = (float)sqrt(mat[0][0]*mat[0][0] + mat[0][1]*mat[0][1]); - - if (cy > 16.0*FLT_EPSILON) { - - eul1[0] = (float)atan2(mat[1][2], mat[2][2]); - eul1[1] = (float)atan2(-mat[0][2], cy); - eul1[2] = (float)atan2(mat[0][1], mat[0][0]); - - eul2[0] = (float)atan2(-mat[1][2], -mat[2][2]); - eul2[1] = (float)atan2(-mat[0][2], -cy); - eul2[2] = (float)atan2(-mat[0][1], -mat[0][0]); - - } else { - eul1[0] = (float)atan2(-mat[2][1], mat[1][1]); - eul1[1] = (float)atan2(-mat[0][2], cy); - eul1[2] = 0.0f; - - VecCopyf(eul2, eul1); - } -} - -/* XYZ order */ -void Mat3ToEul(float tmat[][3], float *eul) -{ - float eul1[3], eul2[3]; - - mat3_to_eul2(tmat, eul1, eul2); - - /* return best, which is just the one with lowest values it in */ - if( fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) { - VecCopyf(eul, eul2); - } - else { - VecCopyf(eul, eul1); - } -} - -/* XYZ order */ -void Mat4ToEul(float tmat[][4], float *eul) -{ - float tempMat[3][3]; - - Mat3CpyMat4(tempMat, tmat); - Mat3Ortho(tempMat); - Mat3ToEul(tempMat, eul); -} - -/* XYZ order */ -void QuatToEul(float *quat, float *eul) -{ - float mat[3][3]; - - QuatToMat3(quat, mat); - Mat3ToEul(mat, eul); -} - -/* XYZ order */ -void EulToQuat(float *eul, float *quat) -{ - float ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; - - ti = eul[0]*0.5f; tj = eul[1]*0.5f; th = eul[2]*0.5f; - ci = (float)cos(ti); cj = (float)cos(tj); ch = (float)cos(th); - si = (float)sin(ti); sj = (float)sin(tj); sh = (float)sin(th); - cc = ci*ch; cs = ci*sh; sc = si*ch; ss = si*sh; - - quat[0] = cj*cc + sj*ss; - quat[1] = cj*sc - sj*cs; - quat[2] = cj*ss + sj*cc; - quat[3] = cj*cs - sj*sc; -} - -/* XYZ order */ -void euler_rot(float *beul, float ang, char axis) -{ - float eul[3], mat1[3][3], mat2[3][3], totmat[3][3]; - - eul[0]= eul[1]= eul[2]= 0.0f; - if(axis=='x') eul[0]= ang; - else if(axis=='y') eul[1]= ang; - else eul[2]= ang; - - EulToMat3(eul, mat1); - EulToMat3(beul, mat2); - - Mat3MulMat3(totmat, mat2, mat1); - - Mat3ToEul(totmat, beul); - -} - -/* exported to transform.c */ -/* order independent! */ -void compatible_eul(float *eul, float *oldrot) -{ - float dx, dy, dz; - - /* correct differences of about 360 degrees first */ - dx= eul[0] - oldrot[0]; - dy= eul[1] - oldrot[1]; - dz= eul[2] - oldrot[2]; - - while(fabs(dx) > 5.1) { - if(dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; - dx= eul[0] - oldrot[0]; - } - while(fabs(dy) > 5.1) { - if(dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; - dy= eul[1] - oldrot[1]; - } - while(fabs(dz) > 5.1) { - if(dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; - dz= eul[2] - oldrot[2]; - } - - /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ - if( fabs(dx) > 3.2 && fabs(dy)<1.6 && fabs(dz)<1.6 ) { - if(dx > 0.0) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; - } - if( fabs(dy) > 3.2 && fabs(dz)<1.6 && fabs(dx)<1.6 ) { - if(dy > 0.0) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; - } - if( fabs(dz) > 3.2 && fabs(dx)<1.6 && fabs(dy)<1.6 ) { - if(dz > 0.0) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; - } - - /* the method below was there from ancient days... but why! probably because the code sucks :) - */ -#if 0 - /* calc again */ - dx= eul[0] - oldrot[0]; - dy= eul[1] - oldrot[1]; - dz= eul[2] - oldrot[2]; - - /* special case, tested for x-z */ - - if( (fabs(dx) > 3.1 && fabs(dz) > 1.5 ) || ( fabs(dx) > 1.5 && fabs(dz) > 3.1 ) ) { - if(dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; - if(eul[1] > 0.0) eul[1]= M_PI - eul[1]; else eul[1]= -M_PI - eul[1]; - if(dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; - - } - else if( (fabs(dx) > 3.1 && fabs(dy) > 1.5 ) || ( fabs(dx) > 1.5 && fabs(dy) > 3.1 ) ) { - if(dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; - if(dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; - if(eul[2] > 0.0) eul[2]= M_PI - eul[2]; else eul[2]= -M_PI - eul[2]; - } - else if( (fabs(dy) > 3.1 && fabs(dz) > 1.5 ) || ( fabs(dy) > 1.5 && fabs(dz) > 3.1 ) ) { - if(eul[0] > 0.0) eul[0]= M_PI - eul[0]; else eul[0]= -M_PI - eul[0]; - if(dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; - if(dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; - } -#endif -} - -/* uses 2 methods to retrieve eulers, and picks the closest */ -/* XYZ order */ -void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot) -{ - float eul1[3], eul2[3]; - float d1, d2; - - mat3_to_eul2(mat, eul1, eul2); - - compatible_eul(eul1, oldrot); - compatible_eul(eul2, oldrot); - - d1= (float)fabs(eul1[0]-oldrot[0]) + (float)fabs(eul1[1]-oldrot[1]) + (float)fabs(eul1[2]-oldrot[2]); - d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]); - - /* return best, which is just the one with lowest difference */ - if( d1 > d2) { - VecCopyf(eul, eul2); - } - else { - VecCopyf(eul, eul1); - } - -} - -/* the matrix is written to as 3 axis vectors */ -void EulToGimbalAxis(float gmat[][3], float *eul, short order) -{ - RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); - - float mat[3][3]; - float teul[3]; - - /* first axis is local */ - EulOToMat3(eul, order, mat); - VecCopyf(gmat[R->axis[0]], mat[R->axis[0]]); - - /* second axis is local minus first rotation */ - VecCopyf(teul, eul); - teul[R->axis[0]] = 0; - EulOToMat3(teul, order, mat); - VecCopyf(gmat[R->axis[1]], mat[R->axis[1]]); - - - /* Last axis is global */ - gmat[R->axis[2]][0] = 0; - gmat[R->axis[2]][1] = 0; - gmat[R->axis[2]][2] = 0; - gmat[R->axis[2]][R->axis[2]] = 1; -} - -/* ************ AXIS ANGLE *************** */ - -/* Axis angle to Quaternions */ -void AxisAngleToQuat(float q[4], float axis[3], float angle) -{ - float nor[3]; - float si; - - VecCopyf(nor, axis); - Normalize(nor); - - angle /= 2; - si = (float)sin(angle); - q[0] = (float)cos(angle); - q[1] = nor[0] * si; - q[2] = nor[1] * si; - q[3] = nor[2] * si; -} - -/* Quaternions to Axis Angle */ -void QuatToAxisAngle(float q[4], float axis[3], float *angle) -{ - float ha, si; - - /* calculate angle/2, and sin(angle/2) */ - ha= (float)acos(q[0]); - si= (float)sin(ha); - - /* from half-angle to angle */ - *angle= ha * 2; - - /* prevent division by zero for axis conversion */ - if (fabs(si) < 0.0005) - si= 1.0f; - - axis[0]= q[1] / si; - axis[1]= q[2] / si; - axis[2]= q[3] / si; -} - -/* Axis Angle to Euler Rotation */ -void AxisAngleToEulO(float axis[3], float angle, float eul[3], short order) -{ - float q[4]; - - /* use quaternions as intermediate representation for now... */ - AxisAngleToQuat(q, axis, angle); - QuatToEulO(q, eul, order); -} - -/* Euler Rotation to Axis Angle */ -void EulOToAxisAngle(float eul[3], short order, float axis[3], float *angle) -{ - float q[4]; - - /* use quaternions as intermediate representation for now... */ - EulOToQuat(eul, order, q); - QuatToAxisAngle(q, axis, angle); -} - -/* axis angle to 3x3 matrix - safer version (normalisation of axis performed) */ -void AxisAngleToMat3(float axis[3], float angle, float mat[3][3]) -{ - float nor[3], nsi[3], co, si, ico; - - /* normalise the axis first (to remove unwanted scaling) */ - VecCopyf(nor, axis); - Normalize(nor); - - /* now convert this to a 3x3 matrix */ - co= (float)cos(angle); - si= (float)sin(angle); - - ico= (1.0f - co); - nsi[0]= nor[0]*si; - nsi[1]= nor[1]*si; - nsi[2]= nor[2]*si; - - mat[0][0] = ((nor[0] * nor[0]) * ico) + co; - mat[0][1] = ((nor[0] * nor[1]) * ico) + nsi[2]; - mat[0][2] = ((nor[0] * nor[2]) * ico) - nsi[1]; - mat[1][0] = ((nor[0] * nor[1]) * ico) - nsi[2]; - mat[1][1] = ((nor[1] * nor[1]) * ico) + co; - mat[1][2] = ((nor[1] * nor[2]) * ico) + nsi[0]; - mat[2][0] = ((nor[0] * nor[2]) * ico) + nsi[1]; - mat[2][1] = ((nor[1] * nor[2]) * ico) - nsi[0]; - mat[2][2] = ((nor[2] * nor[2]) * ico) + co; -} - -/* axis angle to 4x4 matrix - safer version (normalisation of axis performed) */ -void AxisAngleToMat4(float axis[3], float angle, float mat[4][4]) -{ - float tmat[3][3]; - - AxisAngleToMat3(axis, angle, tmat); - Mat4One(mat); - Mat4CpyMat3(mat, tmat); -} - -/* 3x3 matrix to axis angle (see Mat4ToVecRot too) */ -void Mat3ToAxisAngle(float mat[3][3], float axis[3], float *angle) -{ - float q[4]; - - /* use quaternions as intermediate representation */ - // TODO: it would be nicer to go straight there... - Mat3ToQuat(mat, q); - QuatToAxisAngle(q, axis, angle); -} - -/* 4x4 matrix to axis angle (see Mat4ToVecRot too) */ -void Mat4ToAxisAngle(float mat[4][4], float axis[3], float *angle) -{ - float q[4]; - - /* use quaternions as intermediate representation */ - // TODO: it would be nicer to go straight there... - Mat4ToQuat(mat, q); - QuatToAxisAngle(q, axis, angle); -} - -/* ************ AXIS ANGLE (unchecked) *************** */ -// TODO: the following calls should probably be depreceated sometime - -/* 3x3 matrix to axis angle */ -void Mat3ToVecRot(float mat[3][3], float axis[3], float *angle) -{ - float q[4]; - - /* use quaternions as intermediate representation */ - // TODO: it would be nicer to go straight there... - Mat3ToQuat(mat, q); - QuatToAxisAngle(q, axis, angle); -} - -/* 4x4 matrix to axis angle */ -void Mat4ToVecRot(float mat[4][4], float axis[3], float *angle) -{ - float q[4]; - - /* use quaternions as intermediate representation */ - // TODO: it would be nicer to go straight there... - Mat4ToQuat(mat, q); - QuatToAxisAngle(q, axis, angle); -} - -/* axis angle to 3x3 matrix */ -void VecRotToMat3(float *vec, float phi, float mat[][3]) -{ - /* rotation of phi radials around vec */ - float vx, vx2, vy, vy2, vz, vz2, co, si; - - vx= vec[0]; - vy= vec[1]; - vz= vec[2]; - vx2= vx*vx; - vy2= vy*vy; - vz2= vz*vz; - co= (float)cos(phi); - si= (float)sin(phi); - - mat[0][0]= vx2+co*(1.0f-vx2); - mat[0][1]= vx*vy*(1.0f-co)+vz*si; - mat[0][2]= vz*vx*(1.0f-co)-vy*si; - mat[1][0]= vx*vy*(1.0f-co)-vz*si; - mat[1][1]= vy2+co*(1.0f-vy2); - mat[1][2]= vy*vz*(1.0f-co)+vx*si; - mat[2][0]= vz*vx*(1.0f-co)+vy*si; - mat[2][1]= vy*vz*(1.0f-co)-vx*si; - mat[2][2]= vz2+co*(1.0f-vz2); -} - -/* axis angle to 4x4 matrix */ -void VecRotToMat4(float *vec, float phi, float mat[][4]) -{ - float tmat[3][3]; - - VecRotToMat3(vec, phi, tmat); - Mat4One(mat); - Mat4CpyMat3(mat, tmat); -} - -/* axis angle to quaternion */ -void VecRotToQuat(float *vec, float phi, float *quat) -{ - /* rotation of phi radials around vec */ - float si; - - quat[1]= vec[0]; - quat[2]= vec[1]; - quat[3]= vec[2]; - - if( Normalize(quat+1) == 0.0f) { - QuatOne(quat); - } - else { - quat[0]= (float)cos( phi/2.0 ); - si= (float)sin( phi/2.0 ); - quat[1] *= si; - quat[2] *= si; - quat[3] *= si; - } -} - -/* ************ VECTORS *************** */ - -/* Returns a vector bisecting the angle at v2 formed by v1, v2 and v3 */ -void VecBisect3(float *out, float *v1, float *v2, float *v3) -{ - float d_12[3], d_23[3]; - VecSubf(d_12, v2, v1); - VecSubf(d_23, v3, v2); - Normalize(d_12); - Normalize(d_23); - VecAddf(out, d_12, d_23); - Normalize(out); -} - -/* Returns a reflection vector from a vector and a normal vector -reflect = vec - ((2 * DotVecs(vec, mirror)) * mirror) -*/ -void VecReflect(float *out, float *v1, float *v2) -{ - float vec[3], normal[3]; - float reflect[3] = {0.0f, 0.0f, 0.0f}; - float dot2; - - VecCopyf(vec, v1); - VecCopyf(normal, v2); - - Normalize(normal); - - dot2 = 2 * Inpf(vec, normal); - - reflect[0] = vec[0] - (dot2 * normal[0]); - reflect[1] = vec[1] - (dot2 * normal[1]); - reflect[2] = vec[2] - (dot2 * normal[2]); - - VecCopyf(out, reflect); -} - -/* Return the angle in degrees between vecs 1-2 and 2-3 in degrees - If v1 is a shoulder, v2 is the elbow and v3 is the hand, - this would return the angle at the elbow */ -float VecAngle3(float *v1, float *v2, float *v3) -{ - float vec1[3], vec2[3]; - - VecSubf(vec1, v2, v1); - VecSubf(vec2, v2, v3); - Normalize(vec1); - Normalize(vec2); - - return NormalizedVecAngle2(vec1, vec2); -} - -float Vec2Angle3(float *v1, float *v2, float *v3) -{ - float vec1[2], vec2[2]; - - vec1[0] = v2[0]-v1[0]; - vec1[1] = v2[1]-v1[1]; - - vec2[0] = v2[0]-v3[0]; - vec2[1] = v2[1]-v3[1]; - - Normalize2(vec1); - Normalize2(vec2); - - return NormalizedVecAngle2_2D(vec1, vec2); -} - -/* Return the shortest angle in degrees between the 2 vectors */ -float VecAngle2(float *v1, float *v2) -{ - float vec1[3], vec2[3]; - - VecCopyf(vec1, v1); - VecCopyf(vec2, v2); - Normalize(vec1); - Normalize(vec2); - - return NormalizedVecAngle2(vec1, vec2); -} - -float NormalizedVecAngle2(float *v1, float *v2) -{ - /* this is the same as acos(Inpf(v1, v2)), but more accurate */ - if (Inpf(v1, v2) < 0.0f) { - float vec[3]; - - vec[0]= -v2[0]; - vec[1]= -v2[1]; - vec[2]= -v2[2]; - - return (float)M_PI - 2.0f*(float)saasin(VecLenf(vec, v1)/2.0f); - } - else - return 2.0f*(float)saasin(VecLenf(v2, v1)/2.0f); -} - -float NormalizedVecAngle2_2D(float *v1, float *v2) -{ - /* this is the same as acos(Inpf(v1, v2)), but more accurate */ - if (Inp2f(v1, v2) < 0.0f) { - float vec[2]; - - vec[0]= -v2[0]; - vec[1]= -v2[1]; - - return (float)M_PI - 2.0f*saasin(Vec2Lenf(vec, v1)/2.0f); - } - else - return 2.0f*(float)saasin(Vec2Lenf(v2, v1)/2.0f); -} - -/* ******************************************** */ - -void SizeToMat3( float *size, float mat[][3]) -{ - mat[0][0]= size[0]; - mat[0][1]= 0.0f; - mat[0][2]= 0.0f; - mat[1][1]= size[1]; - mat[1][0]= 0.0f; - mat[1][2]= 0.0f; - mat[2][2]= size[2]; - mat[2][1]= 0.0f; - mat[2][0]= 0.0f; -} - -void SizeToMat4( float *size, float mat[][4]) -{ - float tmat[3][3]; - - SizeToMat3(size, tmat); - Mat4One(mat); - Mat4CpyMat3(mat, tmat); -} - -void Mat3ToSize( float mat[][3], float *size) -{ - size[0]= VecLength(mat[0]); - size[1]= VecLength(mat[1]); - size[2]= VecLength(mat[2]); -} - -void Mat4ToSize( float mat[][4], float *size) -{ - size[0]= VecLength(mat[0]); - size[1]= VecLength(mat[1]); - size[2]= VecLength(mat[2]); -} - -/* this gets the average scale of a matrix, only use when your scaling - * data that has no idea of scale axis, examples are bone-envelope-radius - * and curve radius */ -float Mat3ToScalef(float mat[][3]) -{ - /* unit length vector */ - float unit_vec[3] = {0.577350269189626f, 0.577350269189626f, 0.577350269189626f}; - Mat3MulVecfl(mat, unit_vec); - return VecLength(unit_vec); -} - -float Mat4ToScalef(float mat[][4]) -{ - float tmat[3][3]; - Mat3CpyMat4(tmat, mat); - return Mat3ToScalef(tmat); -} - - -/* ************* SPECIALS ******************* */ - -void triatoquat( float *v1, float *v2, float *v3, float *quat) -{ - /* imaginary x-axis, y-axis triangle is being rotated */ - float vec[3], q1[4], q2[4], n[3], si, co, angle, mat[3][3], imat[3][3]; - - /* move z-axis to face-normal */ - CalcNormFloat(v1, v2, v3, vec); - - n[0]= vec[1]; - n[1]= -vec[0]; - n[2]= 0.0f; - Normalize(n); - - if(n[0]==0.0f && n[1]==0.0f) n[0]= 1.0f; - - angle= -0.5f*(float)saacos(vec[2]); - co= (float)cos(angle); - si= (float)sin(angle); - q1[0]= co; - q1[1]= n[0]*si; - q1[2]= n[1]*si; - q1[3]= 0.0f; - - /* rotate back line v1-v2 */ - QuatToMat3(q1, mat); - Mat3Inv(imat, mat); - VecSubf(vec, v2, v1); - Mat3MulVecfl(imat, vec); - - /* what angle has this line with x-axis? */ - vec[2]= 0.0f; - Normalize(vec); - - angle= (float)(0.5*atan2(vec[1], vec[0])); - co= (float)cos(angle); - si= (float)sin(angle); - q2[0]= co; - q2[1]= 0.0f; - q2[2]= 0.0f; - q2[3]= si; - - QuatMul(quat, q1, q2); -} - -void MinMaxRGB(short c[]) -{ - if(c[0]>255) c[0]=255; - else if(c[0]<0) c[0]=0; - if(c[1]>255) c[1]=255; - else if(c[1]<0) c[1]=0; - if(c[2]>255) c[2]=255; - else if(c[2]<0) c[2]=0; -} - -float Vec2Lenf(float *v1, float *v2) -{ - float x, y; - - x = v1[0]-v2[0]; - y = v1[1]-v2[1]; - return (float)sqrt(x*x+y*y); -} - -float Vec2Length(float *v) -{ - return (float)sqrt(v[0]*v[0] + v[1]*v[1]); -} - -void Vec2Mulf(float *v1, float f) -{ - v1[0]*= f; - v1[1]*= f; -} - -void Vec2Addf(float *v, float *v1, float *v2) -{ - v[0]= v1[0]+ v2[0]; - v[1]= v1[1]+ v2[1]; -} - -void Vec2Subf(float *v, float *v1, float *v2) -{ - v[0]= v1[0]- v2[0]; - v[1]= v1[1]- v2[1]; -} - -void Vec2Copyf(float *v1, float *v2) -{ - v1[0]= v2[0]; - v1[1]= v2[1]; -} - -float Inp2f(float *v1, float *v2) -{ - return v1[0]*v2[0]+v1[1]*v2[1]; -} - -float Normalize2(float *n) -{ - float d; - - d= n[0]*n[0]+n[1]*n[1]; - - if(d>1.0e-35f) { - d= (float)sqrt(d); - n[0]/=d; - n[1]/=d; - } else { - n[0]=n[1]= 0.0f; - d= 0.0f; - } - return d; -} - -void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b) -{ - int i; - float f, p, q, t; - - h *= 360.0f; - - if(s==0.0f) { - *r = v; - *g = v; - *b = v; - } - else { - if(h== 360.0f) h = 0.0f; - - h /= 60.0f; - i = (int)floor(h); - f = h - i; - p = v*(1.0f-s); - q = v*(1.0f-(s*f)); - t = v*(1.0f-(s*(1.0f-f))); - - switch (i) { - case 0 : - *r = v; - *g = t; - *b = p; - break; - case 1 : - *r = q; - *g = v; - *b = p; - break; - case 2 : - *r = p; - *g = v; - *b = t; - break; - case 3 : - *r = p; - *g = q; - *b = v; - break; - case 4 : - *r = t; - *g = p; - *b = v; - break; - case 5 : - *r = v; - *g = p; - *b = q; - break; - } - } -} - -void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv) -{ - float y, u, v; - y= 0.299f*r + 0.587f*g + 0.114f*b; - u=-0.147f*r - 0.289f*g + 0.436f*b; - v= 0.615f*r - 0.515f*g - 0.100f*b; - - *ly=y; - *lu=u; - *lv=v; -} - -void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb) -{ - float r, g, b; - r=y+1.140f*v; - g=y-0.394f*u - 0.581f*v; - b=y+2.032f*u; - - *lr=r; - *lg=g; - *lb=b; -} - -void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr) -{ - float sr,sg, sb; - float y, cr, cb; - - sr=255.0f*r; - sg=255.0f*g; - sb=255.0f*b; - - - y=(0.257f*sr)+(0.504f*sg)+(0.098f*sb)+16.0f; - cb=(-0.148f*sr)-(0.291f*sg)+(0.439f*sb)+128.0f; - cr=(0.439f*sr)-(0.368f*sg)-(0.071f*sb)+128.0f; - - *ly=y; - *lcb=cb; - *lcr=cr; -} - -void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb) -{ - float r,g,b; - - r=1.164f*(y-16.0f)+1.596f*(cr-128.0f); - g=1.164f*(y-16.0f)-0.813f*(cr-128.0f)-0.392f*(cb-128.0f); - b=1.164f*(y-16.0f)+2.017f*(cb-128.0f); - - *lr=r/255.0f; - *lg=g/255.0f; - *lb=b/255.0f; -} - -void hex_to_rgb(char *hexcol, float *r, float *g, float *b) -{ - unsigned int ri, gi, bi; - - if (hexcol[0] == '#') hexcol++; - - if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)) { - *r = ri / 255.0f; - *g = gi / 255.0f; - *b = bi / 255.0f; - } -} - -void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv) -{ - float h, s, v; - float cmax, cmin, cdelta; - float rc, gc, bc; - - cmax = r; - cmin = r; - cmax = (g>cmax ? g:cmax); - cmin = (g<cmin ? g:cmin); - cmax = (b>cmax ? b:cmax); - cmin = (b<cmin ? b:cmin); - - v = cmax; /* value */ - if (cmax != 0.0f) - s = (cmax - cmin)/cmax; - else { - s = 0.0f; - h = 0.0f; - } - if (s == 0.0f) - h = -1.0f; - else { - cdelta = cmax-cmin; - rc = (cmax-r)/cdelta; - gc = (cmax-g)/cdelta; - bc = (cmax-b)/cdelta; - if (r==cmax) - h = bc-gc; - else - if (g==cmax) - h = 2.0f+rc-bc; - else - h = 4.0f+gc-rc; - h = h*60.0f; - if (h < 0.0f) - h += 360.0f; - } - - *ls = s; - *lh = h / 360.0f; - if(*lh < 0.0f) *lh= 0.0f; - *lv = v; -} - -/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */ - -void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace) -{ - switch (colorspace) { - case BLI_CS_SMPTE: - *r = (3.50570f * xc) + (-1.73964f * yc) + (-0.544011f * zc); - *g = (-1.06906f * xc) + (1.97781f * yc) + (0.0351720f * zc); - *b = (0.0563117f * xc) + (-0.196994f * yc) + (1.05005f * zc); - break; - case BLI_CS_REC709: - *r = (3.240476f * xc) + (-1.537150f * yc) + (-0.498535f * zc); - *g = (-0.969256f * xc) + (1.875992f * yc) + (0.041556f * zc); - *b = (0.055648f * xc) + (-0.204043f * yc) + (1.057311f * zc); - break; - case BLI_CS_CIE: - *r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc); - *g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc); - *b = (0.00572040983140966f * xc) + (-0.0159068485104036f * yc) + (1.0101864083734f * zc); - break; - } -} - -/*If the requested RGB shade contains a negative weight for - one of the primaries, it lies outside the colour gamut - accessible from the given triple of primaries. Desaturate - it by adding white, equal quantities of R, G, and B, enough - to make RGB all positive. The function returns 1 if the - components were modified, zero otherwise.*/ -int constrain_rgb(float *r, float *g, float *b) -{ - float w; - - /* Amount of white needed is w = - min(0, *r, *g, *b) */ - - w = (0 < *r) ? 0 : *r; - w = (w < *g) ? w : *g; - w = (w < *b) ? w : *b; - w = -w; - - /* Add just enough white to make r, g, b all positive. */ - - if (w > 0) { - *r += w; *g += w; *b += w; - return 1; /* Color modified to fit RGB gamut */ - } - - return 0; /* Color within RGB gamut */ -} - - -/* we define a 'cpack' here as a (3 byte color code) number that can be expressed like 0xFFAA66 or so. - for that reason it is sensitive for endianness... with this function it works correctly -*/ - -unsigned int hsv_to_cpack(float h, float s, float v) -{ - short r, g, b; - float rf, gf, bf; - unsigned int col; - - hsv_to_rgb(h, s, v, &rf, &gf, &bf); - - r= (short)(rf*255.0f); - g= (short)(gf*255.0f); - b= (short)(bf*255.0f); - - col= ( r + (g*256) + (b*256*256) ); - return col; -} - - -unsigned int rgb_to_cpack(float r, float g, float b) -{ - int ir, ig, ib; - - ir= (int)floor(255.0*r); - if(ir<0) ir= 0; else if(ir>255) ir= 255; - ig= (int)floor(255.0*g); - if(ig<0) ig= 0; else if(ig>255) ig= 255; - ib= (int)floor(255.0*b); - if(ib<0) ib= 0; else if(ib>255) ib= 255; - - return (ir+ (ig*256) + (ib*256*256)); -} - -void cpack_to_rgb(unsigned int col, float *r, float *g, float *b) -{ - - *r= (float)((col)&0xFF); - *r /= 255.0f; - - *g= (float)(((col)>>8)&0xFF); - *g /= 255.0f; - - *b= (float)(((col)>>16)&0xFF); - *b /= 255.0f; -} - - -/* *************** PROJECTIONS ******************* */ - -void tubemap(float x, float y, float z, float *u, float *v) -{ - float len; - - *v = (z + 1.0f) / 2.0f; - - len= (float)sqrt(x*x+y*y); - if(len > 0.0f) - *u = (float)((1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0); - else - *v = *u = 0.0f; /* to avoid un-initialized variables */ -} - -/* ------------------------------------------------------------------------- */ - -void spheremap(float x, float y, float z, float *u, float *v) -{ - float len; - - len= (float)sqrt(x*x+y*y+z*z); - if(len > 0.0f) { - if(x==0.0f && y==0.0f) *u= 0.0f; /* othwise domain error */ - else *u = (float)((1.0 - (float)atan2(x,y) / M_PI) / 2.0); - - z/=len; - *v = 1.0f - (float)saacos(z)/(float)M_PI; - } else { - *v = *u = 0.0f; /* to avoid un-initialized variables */ - } -} - -/* ------------------------------------------------------------------------- */ - -/* proposed api by ton and zr, not used yet */ -#if 0 -/* ***************** m1 = m2 ***************** */ -static void cpy_m3_m3(float m1[][3], float m2[][3]) -{ - memcpy(m1[0], m2[0], 9*sizeof(float)); -} - -/* ***************** m1 = m2 ***************** */ -static void cpy_m4_m4(float m1[][4], float m2[][4]) -{ - memcpy(m1[0], m2[0], 16*sizeof(float)); -} - -/* ***************** identity matrix ***************** */ -static void ident_m4(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; -} - -/* ***************** m1 = m2 (pre) * m3 (post) ***************** */ -static void mul_m3_m3m3(float m1[][3], float m2[][3], float m3[][3]) -{ - float m[3][3]; - - m[0][0]= m2[0][0]*m3[0][0] + m2[1][0]*m3[0][1] + m2[2][0]*m3[0][2]; - m[0][1]= m2[0][1]*m3[0][0] + m2[1][1]*m3[0][1] + m2[2][1]*m3[0][2]; - m[0][2]= m2[0][2]*m3[0][0] + m2[1][2]*m3[0][1] + m2[2][2]*m3[0][2]; - - m[1][0]= m2[0][0]*m3[1][0] + m2[1][0]*m3[1][1] + m2[2][0]*m3[1][2]; - m[1][1]= m2[0][1]*m3[1][0] + m2[1][1]*m3[1][1] + m2[2][1]*m3[1][2]; - m[1][2]= m2[0][2]*m3[1][0] + m2[1][2]*m3[1][1] + m2[2][2]*m3[1][2]; - - m[2][0]= m2[0][0]*m3[2][0] + m2[1][0]*m3[2][1] + m2[2][0]*m3[2][2]; - m[2][1]= m2[0][1]*m3[2][0] + m2[1][1]*m3[2][1] + m2[2][1]*m3[2][2]; - m[2][2]= m2[0][2]*m3[2][0] + m2[1][2]*m3[2][1] + m2[2][2]*m3[2][2]; - - cpy_m3_m3(m1, m2); -} - -/* ***************** m1 = m2 (pre) * m3 (post) ***************** */ -static void mul_m4_m4m4(float m1[][4], float m2[][4], float m3[][4]) -{ - float m[4][4]; - - m[0][0]= m2[0][0]*m3[0][0] + m2[1][0]*m3[0][1] + m2[2][0]*m3[0][2] + m2[3][0]*m3[0][3]; - m[0][1]= m2[0][1]*m3[0][0] + m2[1][1]*m3[0][1] + m2[2][1]*m3[0][2] + m2[3][1]*m3[0][3]; - m[0][2]= m2[0][2]*m3[0][0] + m2[1][2]*m3[0][1] + m2[2][2]*m3[0][2] + m2[3][2]*m3[0][3]; - m[0][3]= m2[0][3]*m3[0][0] + m2[1][3]*m3[0][1] + m2[2][3]*m3[0][2] + m2[3][3]*m3[0][3]; - - m[1][0]= m2[0][0]*m3[1][0] + m2[1][0]*m3[1][1] + m2[2][0]*m3[1][2] + m2[3][0]*m3[1][3]; - m[1][1]= m2[0][1]*m3[1][0] + m2[1][1]*m3[1][1] + m2[2][1]*m3[1][2] + m2[3][1]*m3[1][3]; - m[1][2]= m2[0][2]*m3[1][0] + m2[1][2]*m3[1][1] + m2[2][2]*m3[1][2] + m2[3][2]*m3[1][3]; - m[1][3]= m2[0][3]*m3[1][0] + m2[1][3]*m3[1][1] + m2[2][3]*m3[1][2] + m2[3][3]*m3[1][3]; - - m[2][0]= m2[0][0]*m3[2][0] + m2[1][0]*m3[2][1] + m2[2][0]*m3[2][2] + m2[3][0]*m3[2][3]; - m[2][1]= m2[0][1]*m3[2][0] + m2[1][1]*m3[2][1] + m2[2][1]*m3[2][2] + m2[3][1]*m3[2][3]; - m[2][2]= m2[0][2]*m3[2][0] + m2[1][2]*m3[2][1] + m2[2][2]*m3[2][2] + m2[3][2]*m3[2][3]; - m[2][3]= m2[0][3]*m3[2][0] + m2[1][3]*m3[2][1] + m2[2][3]*m3[2][2] + m2[3][3]*m3[2][3]; - - m[3][0]= m2[0][0]*m3[3][0] + m2[1][0]*m3[3][1] + m2[2][0]*m3[3][2] + m2[3][0]*m3[3][3]; - m[3][1]= m2[0][1]*m3[3][0] + m2[1][1]*m3[3][1] + m2[2][1]*m3[3][2] + m2[3][1]*m3[3][3]; - m[3][2]= m2[0][2]*m3[3][0] + m2[1][2]*m3[3][1] + m2[2][2]*m3[3][2] + m2[3][2]*m3[3][3]; - m[3][3]= m2[0][3]*m3[3][0] + m2[1][3]*m3[3][1] + m2[2][3]*m3[3][2] + m2[3][3]*m3[3][3]; - - cpy_m4_m4(m1, m2); -} - -/* ***************** m1 = inverse(m2) ***************** */ -static void inv_m3_m3(float m1[][3], float m2[][3]) -{ - short a,b; - float det; - - /* calc adjoint */ - Mat3Adj(m1, m2); - - /* then determinant old matrix! */ - 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.0f) det=1.0f; - det= 1.0f/det; - for(a=0;a<3;a++) { - for(b=0;b<3;b++) { - m1[a][b]*=det; - } - } -} - -/* ***************** m1 = inverse(m2) ***************** */ -static int inv_m4_m4(float inverse[][4], float mat[][4]) -{ - int i, j, k; - double temp; - float tempmat[4][4]; - float max; - int maxj; - - /* Set inverse to identity */ - ident_m4(inverse); - - /* Copy original matrix so we don't mess it up */ - cpy_m4_m4(tempmat, mat); - - 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] = (float)(tempmat[i][k]/temp); - inverse[i][k] = (float)(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] -= (float)(tempmat[i][k]*temp); - inverse[j][k] -= (float)(inverse[i][k]*temp); - } - } - } - } - return 1; -} - -/* ***************** v1 = v2 * mat ***************** */ -static void mul_v3_v3m4(float *v1, float *v2, float mat[][4]) -{ - float x, y; - - x= v2[0]; /* work with a copy, v1 can be same as v2 */ - y= v2[1]; - v1[0]= x*mat[0][0] + y*mat[1][0] + mat[2][0]*v2[2] + mat[3][0]; - v1[1]= x*mat[0][1] + y*mat[1][1] + mat[2][1]*v2[2] + mat[3][1]; - v1[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*v2[2] + mat[3][2]; - -} - -#endif - -/* moved from effect.c - test if the line starting at p1 ending at p2 intersects the triangle v0..v2 - return non zero if it does -*/ -int LineIntersectsTriangle(float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv) -{ - - float p[3], s[3], d[3], e1[3], e2[3], q[3]; - float a, f, u, v; - - VecSubf(e1, v1, v0); - VecSubf(e2, v2, v0); - VecSubf(d, p2, p1); - - Crossf(p, d, e2); - a = Inpf(e1, p); - if ((a > -0.000001) && (a < 0.000001)) return 0; - f = 1.0f/a; - - VecSubf(s, p1, v0); - - Crossf(q, s, e1); - *lambda = f * Inpf(e2, q); - if ((*lambda < 0.0)||(*lambda > 1.0)) return 0; - - u = f * Inpf(s, p); - if ((u < 0.0)||(u > 1.0)) return 0; - - v = f * Inpf(d, q); - if ((v < 0.0)||((u + v) > 1.0)) return 0; - - if(uv) { - uv[0]= u; - uv[1]= v; - } - - return 1; -} - -/* moved from effect.c - test if the ray starting at p1 going in d direction intersects the triangle v0..v2 - return non zero if it does -*/ -int RayIntersectsTriangle(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv) -{ - float p[3], s[3], e1[3], e2[3], q[3]; - float a, f, u, v; - - VecSubf(e1, v1, v0); - VecSubf(e2, v2, v0); - - Crossf(p, d, e2); - a = Inpf(e1, p); - if ((a > -0.000001) && (a < 0.000001)) return 0; - f = 1.0f/a; - - VecSubf(s, p1, v0); - - Crossf(q, s, e1); - *lambda = f * Inpf(e2, q); - if ((*lambda < 0.0)) return 0; - - u = f * Inpf(s, p); - if ((u < 0.0)||(u > 1.0)) return 0; - - v = f * Inpf(d, q); - if ((v < 0.0)||((u + v) > 1.0)) return 0; - - if(uv) { - uv[0]= u; - uv[1]= v; - } - - return 1; -} - -int RayIntersectsTriangleThreshold(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold) -{ - float p[3], s[3], e1[3], e2[3], q[3]; - float a, f, u, v; - float du = 0, dv = 0; - - VecSubf(e1, v1, v0); - VecSubf(e2, v2, v0); - - Crossf(p, d, e2); - a = Inpf(e1, p); - if ((a > -0.000001) && (a < 0.000001)) return 0; - f = 1.0f/a; - - VecSubf(s, p1, v0); - - Crossf(q, s, e1); - *lambda = f * Inpf(e2, q); - if ((*lambda < 0.0)) return 0; - - u = f * Inpf(s, p); - v = f * Inpf(d, q); - - if (u < 0) du = u; - if (u > 1) du = u - 1; - if (v < 0) dv = v; - if (v > 1) dv = v - 1; - if (u > 0 && v > 0 && u + v > 1) - { - float t = u + v - 1; - du = u - t/2; - dv = v - t/2; - } - - VecMulf(e1, du); - VecMulf(e2, dv); - - if (Inpf(e1, e1) + Inpf(e2, e2) > threshold * threshold) - { - return 0; - } - - if(uv) { - uv[0]= u; - uv[1]= v; - } - - return 1; -} - - -/* Adapted from the paper by Kasper Fauerby */ -/* "Improved Collision detection and Response" */ -static int getLowestRoot(float a, float b, float c, float maxR, float* root) -{ - // Check if a solution exists - float determinant = b*b - 4.0f*a*c; - - // If determinant is negative it means no solutions. - if (determinant >= 0.0f) - { - // calculate the two roots: (if determinant == 0 then - // x1==x2 but let’s disregard that slight optimization) - float sqrtD = (float)sqrt(determinant); - float r1 = (-b - sqrtD) / (2.0f*a); - float r2 = (-b + sqrtD) / (2.0f*a); - - // Sort so x1 <= x2 - if (r1 > r2) - SWAP( float, r1, r2); - - // Get lowest root: - if (r1 > 0.0f && r1 < maxR) - { - *root = r1; - return 1; - } - - // It is possible that we want x2 - this can happen - // if x1 < 0 - if (r2 > 0.0f && r2 < maxR) - { - *root = r2; - return 1; - } - } - // No (valid) solutions - return 0; -} - -int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint) -{ - float e1[3], e2[3], e3[3], point[3], vel[3], /*dist[3],*/ nor[3], temp[3], bv[3]; - float a, b, c, d, e, x, y, z, radius2=radius*radius; - float elen2,edotv,edotbv,nordotv,vel2; - float newLambda; - int found_by_sweep=0; - - VecSubf(e1,v1,v0); - VecSubf(e2,v2,v0); - VecSubf(vel,p2,p1); - -/*---test plane of tri---*/ - Crossf(nor,e1,e2); - Normalize(nor); - - /* flip normal */ - if(Inpf(nor,vel)>0.0f) VecNegf(nor); - - a=Inpf(p1,nor)-Inpf(v0,nor); - nordotv=Inpf(nor,vel); - - if (fabs(nordotv) < 0.000001) - { - if(fabs(a)>=radius) - { - return 0; - } - } - else - { - float t0=(-a+radius)/nordotv; - float t1=(-a-radius)/nordotv; - - if(t0>t1) - SWAP(float, t0, t1); - - if(t0>1.0f || t1<0.0f) return 0; - - /* clamp to [0,1] */ - CLAMP(t0, 0.0f, 1.0f); - CLAMP(t1, 0.0f, 1.0f); - - /*---test inside of tri---*/ - /* plane intersection point */ - - point[0] = p1[0] + vel[0]*t0 - nor[0]*radius; - point[1] = p1[1] + vel[1]*t0 - nor[1]*radius; - point[2] = p1[2] + vel[2]*t0 - nor[2]*radius; - - - /* is the point in the tri? */ - a=Inpf(e1,e1); - b=Inpf(e1,e2); - c=Inpf(e2,e2); - - VecSubf(temp,point,v0); - d=Inpf(temp,e1); - e=Inpf(temp,e2); - - x=d*c-e*b; - y=e*a-d*b; - z=x+y-(a*c-b*b); - - - if( z <= 0.0f && (x >= 0.0f && y >= 0.0f)) - { - //( ((unsigned int)z)& ~(((unsigned int)x)|((unsigned int)y)) ) & 0x80000000){ - *lambda=t0; - VecCopyf(ipoint,point); - return 1; - } - } - - - *lambda=1.0f; - -/*---test points---*/ - a=vel2=Inpf(vel,vel); - - /*v0*/ - VecSubf(temp,p1,v0); - b=2.0f*Inpf(vel,temp); - c=Inpf(temp,temp)-radius2; - - if(getLowestRoot(a, b, c, *lambda, lambda)) - { - VecCopyf(ipoint,v0); - found_by_sweep=1; - } - - /*v1*/ - VecSubf(temp,p1,v1); - b=2.0f*Inpf(vel,temp); - c=Inpf(temp,temp)-radius2; - - if(getLowestRoot(a, b, c, *lambda, lambda)) - { - VecCopyf(ipoint,v1); - found_by_sweep=1; - } - - /*v2*/ - VecSubf(temp,p1,v2); - b=2.0f*Inpf(vel,temp); - c=Inpf(temp,temp)-radius2; - - if(getLowestRoot(a, b, c, *lambda, lambda)) - { - VecCopyf(ipoint,v2); - found_by_sweep=1; - } - -/*---test edges---*/ - VecSubf(e3,v2,v1); //wasnt yet calculated - - - /*e1*/ - VecSubf(bv,v0,p1); - - elen2 = Inpf(e1,e1); - edotv = Inpf(e1,vel); - edotbv = Inpf(e1,bv); - - a=elen2*(-Inpf(vel,vel))+edotv*edotv; - b=2.0f*(elen2*Inpf(vel,bv)-edotv*edotbv); - c=elen2*(radius2-Inpf(bv,bv))+edotbv*edotbv; - - if(getLowestRoot(a, b, c, *lambda, &newLambda)) - { - e=(edotv*newLambda-edotbv)/elen2; - - if(e >= 0.0f && e <= 1.0f) - { - *lambda = newLambda; - VecCopyf(ipoint,e1); - VecMulf(ipoint,e); - VecAddf(ipoint,ipoint,v0); - found_by_sweep=1; - } - } - - /*e2*/ - /*bv is same*/ - elen2 = Inpf(e2,e2); - edotv = Inpf(e2,vel); - edotbv = Inpf(e2,bv); - - a=elen2*(-Inpf(vel,vel))+edotv*edotv; - b=2.0f*(elen2*Inpf(vel,bv)-edotv*edotbv); - c=elen2*(radius2-Inpf(bv,bv))+edotbv*edotbv; - - if(getLowestRoot(a, b, c, *lambda, &newLambda)) - { - e=(edotv*newLambda-edotbv)/elen2; - - if(e >= 0.0f && e <= 1.0f) - { - *lambda = newLambda; - VecCopyf(ipoint,e2); - VecMulf(ipoint,e); - VecAddf(ipoint,ipoint,v0); - found_by_sweep=1; - } - } - - /*e3*/ - VecSubf(bv,v0,p1); - elen2 = Inpf(e1,e1); - edotv = Inpf(e1,vel); - edotbv = Inpf(e1,bv); - - VecSubf(bv,v1,p1); - elen2 = Inpf(e3,e3); - edotv = Inpf(e3,vel); - edotbv = Inpf(e3,bv); - - a=elen2*(-Inpf(vel,vel))+edotv*edotv; - b=2.0f*(elen2*Inpf(vel,bv)-edotv*edotbv); - c=elen2*(radius2-Inpf(bv,bv))+edotbv*edotbv; - - if(getLowestRoot(a, b, c, *lambda, &newLambda)) - { - e=(edotv*newLambda-edotbv)/elen2; - - if(e >= 0.0f && e <= 1.0f) - { - *lambda = newLambda; - VecCopyf(ipoint,e3); - VecMulf(ipoint,e); - VecAddf(ipoint,ipoint,v1); - found_by_sweep=1; - } - } - - - return found_by_sweep; -} -int AxialLineIntersectsTriangle(int axis, float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda) -{ - float p[3], e1[3], e2[3]; - float u, v, f; - int a0=axis, a1=(axis+1)%3, a2=(axis+2)%3; - - //return LineIntersectsTriangle(p1,p2,v0,v1,v2,lambda); - - ///* first a simple bounding box test */ - //if(MIN3(v0[a1],v1[a1],v2[a1]) > p1[a1]) return 0; - //if(MIN3(v0[a2],v1[a2],v2[a2]) > p1[a2]) return 0; - //if(MAX3(v0[a1],v1[a1],v2[a1]) < p1[a1]) return 0; - //if(MAX3(v0[a2],v1[a2],v2[a2]) < p1[a2]) return 0; - - ///* then a full intersection test */ - - VecSubf(e1,v1,v0); - VecSubf(e2,v2,v0); - VecSubf(p,v0,p1); - - f= (e2[a1]*e1[a2]-e2[a2]*e1[a1]); - if ((f > -0.000001) && (f < 0.000001)) return 0; - - v= (p[a2]*e1[a1]-p[a1]*e1[a2])/f; - if ((v < 0.0)||(v > 1.0)) return 0; - - f= e1[a1]; - if((f > -0.000001) && (f < 0.000001)){ - f= e1[a2]; - if((f > -0.000001) && (f < 0.000001)) return 0; - u= (-p[a2]-v*e2[a2])/f; - } - else - u= (-p[a1]-v*e2[a1])/f; - - if ((u < 0.0)||((u + v) > 1.0)) return 0; - - *lambda = (p[a0]+u*e1[a0]+v*e2[a0])/(p2[a0]-p1[a0]); - - if ((*lambda < 0.0)||(*lambda > 1.0)) return 0; - - return 1; -} - -/* Returns the number of point of interests - * 0 - lines are colinear - * 1 - lines are coplanar, i1 is set to intersection - * 2 - i1 and i2 are the nearest points on line 1 (v1, v2) and line 2 (v3, v4) respectively - * */ -int LineIntersectLine(float v1[3], float v2[3], float v3[3], float v4[3], float i1[3], float i2[3]) -{ - float a[3], b[3], c[3], ab[3], cb[3], dir1[3], dir2[3]; - float d; - - VecSubf(c, v3, v1); - VecSubf(a, v2, v1); - VecSubf(b, v4, v3); - - VecCopyf(dir1, a); - Normalize(dir1); - VecCopyf(dir2, b); - Normalize(dir2); - d = Inpf(dir1, dir2); - if (d == 1.0f || d == -1.0f) { - /* colinear */ - return 0; - } - - Crossf(ab, a, b); - d = Inpf(c, ab); - - /* test if the two lines are coplanar */ - if (d > -0.000001f && d < 0.000001f) { - Crossf(cb, c, b); - - VecMulf(a, Inpf(cb, ab) / Inpf(ab, ab)); - VecAddf(i1, v1, a); - VecCopyf(i2, i1); - - return 1; /* one intersection only */ - } - /* if not */ - else { - float n[3], t[3]; - float v3t[3], v4t[3]; - VecSubf(t, v1, v3); - - /* offset between both plane where the lines lies */ - Crossf(n, a, b); - Projf(t, t, n); - - /* for the first line, offset the second line until it is coplanar */ - VecAddf(v3t, v3, t); - VecAddf(v4t, v4, t); - - VecSubf(c, v3t, v1); - VecSubf(a, v2, v1); - VecSubf(b, v4t, v3t); - - Crossf(ab, a, b); - Crossf(cb, c, b); - - VecMulf(a, Inpf(cb, ab) / Inpf(ab, ab)); - VecAddf(i1, v1, a); - - /* for the second line, just substract the offset from the first intersection point */ - VecSubf(i2, i1, t); - - return 2; /* two nearest points */ - } -} - -/* Intersection point strictly between the two lines - * 0 when no intersection is found - * */ -int LineIntersectLineStrict(float v1[3], float v2[3], float v3[3], float v4[3], float vi[3], float *lambda) -{ - float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3]; - float d; - float d1; - - VecSubf(c, v3, v1); - VecSubf(a, v2, v1); - VecSubf(b, v4, v3); - - VecCopyf(dir1, a); - Normalize(dir1); - VecCopyf(dir2, b); - Normalize(dir2); - d = Inpf(dir1, dir2); - if (d == 1.0f || d == -1.0f || d == 0) { - /* colinear or one vector is zero-length*/ - return 0; - } - - d1 = d; - - Crossf(ab, a, b); - d = Inpf(c, ab); - - /* test if the two lines are coplanar */ - if (d > -0.000001f && d < 0.000001f) { - float f1, f2; - Crossf(cb, c, b); - Crossf(ca, c, a); - - f1 = Inpf(cb, ab) / Inpf(ab, ab); - f2 = Inpf(ca, ab) / Inpf(ab, ab); - - if (f1 >= 0 && f1 <= 1 && - f2 >= 0 && f2 <= 1) - { - VecMulf(a, f1); - VecAddf(vi, v1, a); - - if (lambda != NULL) - { - *lambda = f1; - } - - return 1; /* intersection found */ - } - else - { - return 0; - } - } - else - { - return 0; - } -} - -int AabbIntersectAabb(float min1[3], float max1[3], float min2[3], float max2[3]) -{ - return (min1[0]<max2[0] && min1[1]<max2[1] && min1[2]<max2[2] && - min2[0]<max1[0] && min2[1]<max1[1] && min2[2]<max1[2]); -} - -/* find closest point to p on line through l1,l2 and return lambda, - * where (0 <= lambda <= 1) when cp is in the line segement l1,l2 - */ -float lambda_cp_line_ex(float p[3], float l1[3], float l2[3], float cp[3]) -{ - float h[3],u[3],lambda; - VecSubf(u, l2, l1); - VecSubf(h, p, l1); - lambda =Inpf(u,h)/Inpf(u,u); - cp[0] = l1[0] + u[0] * lambda; - cp[1] = l1[1] + u[1] * lambda; - cp[2] = l1[2] + u[2] * lambda; - return lambda; -} - -#if 0 -/* little sister we only need to know lambda */ -static float lambda_cp_line(float p[3], float l1[3], float l2[3]) -{ - float h[3],u[3]; - VecSubf(u, l2, l1); - VecSubf(h, p, l1); - return(Inpf(u,h)/Inpf(u,u)); -} -#endif - -/* useful to calculate an even width shell, by taking the angle between 2 planes. - * The return value is a scale on the offset. - * no angle between planes is 1.0, as the angle between the 2 planes approches 180d - * the distance gets very high, 180d would be inf, but this case isn't valid */ -float AngleToLength(const float angle) -{ - return (angle < SMALL_NUMBER) ? 1.0f : fabsf(1.0f / cosf(angle * (M_PI/180.0f))); -} - -/* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */ -void PointInQuad2DUV(float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv) -{ - float x0,y0, x1,y1, wtot, v2d[2], w1, w2; - - /* used for paralelle lines */ - float pt3d[3], l1[3], l2[3], pt_on_line[3]; - - /* compute 2 edges of the quad intersection point */ - if (IsectLLPt2Df(v0[0],v0[1],v1[0],v1[1], v2[0],v2[1],v3[0],v3[1], &x0,&y0) == 1) { - /* the intersection point between the quad-edge intersection and the point in the quad we want the uv's for */ - /* should never be paralle !! */ - /*printf("\tnot paralelle 1\n");*/ - IsectLLPt2Df(pt[0],pt[1],x0,y0, v0[0],v0[1],v3[0],v3[1], &x1,&y1); - - /* Get the weights from the new intersection point, to each edge */ - v2d[0] = x1-v0[0]; - v2d[1] = y1-v0[1]; - w1 = Vec2Length(v2d); - - v2d[0] = x1-v3[0]; /* some but for the other vert */ - v2d[1] = y1-v3[1]; - w2 = Vec2Length(v2d); - wtot = w1+w2; - /*w1 = w1/wtot;*/ - /*w2 = w2/wtot;*/ - uv[0] = w1/wtot; - } else { - /* lines are paralelle, lambda_cp_line_ex is 3d grrr */ - /*printf("\tparalelle1\n");*/ - pt3d[0] = pt[0]; - pt3d[1] = pt[1]; - pt3d[2] = l1[2] = l2[2] = 0.0f; - - l1[0] = v0[0]; l1[1] = v0[1]; - l2[0] = v1[0]; l2[1] = v1[1]; - lambda_cp_line_ex(pt3d, l1, l2, pt_on_line); - v2d[0] = pt[0]-pt_on_line[0]; /* same, for the other vert */ - v2d[1] = pt[1]-pt_on_line[1]; - w1 = Vec2Length(v2d); - - l1[0] = v2[0]; l1[1] = v2[1]; - l2[0] = v3[0]; l2[1] = v3[1]; - lambda_cp_line_ex(pt3d, l1, l2, pt_on_line); - v2d[0] = pt[0]-pt_on_line[0]; /* same, for the other vert */ - v2d[1] = pt[1]-pt_on_line[1]; - w2 = Vec2Length(v2d); - wtot = w1+w2; - uv[0] = w1/wtot; - } - - /* Same as above to calc the uv[1] value, alternate calculation */ - - if (IsectLLPt2Df(v0[0],v0[1],v3[0],v3[1], v1[0],v1[1],v2[0],v2[1], &x0,&y0) == 1) { /* was v0,v1 v2,v3 now v0,v3 v1,v2*/ - /* never paralle if above was not */ - /*printf("\tnot paralelle2\n");*/ - IsectLLPt2Df(pt[0],pt[1],x0,y0, v0[0],v0[1],v1[0],v1[1], &x1,&y1);/* was v0,v3 now v0,v1*/ - - v2d[0] = x1-v0[0]; - v2d[1] = y1-v0[1]; - w1 = Vec2Length(v2d); - - v2d[0] = x1-v1[0]; - v2d[1] = y1-v1[1]; - w2 = Vec2Length(v2d); - wtot = w1+w2; - uv[1] = w1/wtot; - } else { - /* lines are paralelle, lambda_cp_line_ex is 3d grrr */ - /*printf("\tparalelle2\n");*/ - pt3d[0] = pt[0]; - pt3d[1] = pt[1]; - pt3d[2] = l1[2] = l2[2] = 0.0f; - - - l1[0] = v0[0]; l1[1] = v0[1]; - l2[0] = v3[0]; l2[1] = v3[1]; - lambda_cp_line_ex(pt3d, l1, l2, pt_on_line); - v2d[0] = pt[0]-pt_on_line[0]; /* some but for the other vert */ - v2d[1] = pt[1]-pt_on_line[1]; - w1 = Vec2Length(v2d); - - l1[0] = v1[0]; l1[1] = v1[1]; - l2[0] = v2[0]; l2[1] = v2[1]; - lambda_cp_line_ex(pt3d, l1, l2, pt_on_line); - v2d[0] = pt[0]-pt_on_line[0]; /* some but for the other vert */ - v2d[1] = pt[1]-pt_on_line[1]; - w2 = Vec2Length(v2d); - wtot = w1+w2; - uv[1] = w1/wtot; - } - /* may need to flip UV's here */ -} - -/* same as above but does tri's and quads, tri's are a bit of a hack */ -void PointInFace2DUV(int isquad, float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv) -{ - if (isquad) { - PointInQuad2DUV(v0, v1, v2, v3, pt, uv); - } - else { - /* not for quads, use for our abuse of LineIntersectsTriangleUV */ - float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3], lambda; - - p1_3d[0] = p2_3d[0] = uv[0]; - p1_3d[1] = p2_3d[1] = uv[1]; - p1_3d[2] = 1.0f; - p2_3d[2] = -1.0f; - v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0; - - /* generate a new fuv, (this is possibly a non optimal solution, - * since we only need 2d calculation but use 3d func's) - * - * this method makes an imaginary triangle in 2d space using the UV's from the derived mesh face - * Then find new uv coords using the fuv and this face with LineIntersectsTriangleUV. - * This means the new values will be correct in relation to the derived meshes face. - */ - Vec2Copyf(v0_3d, v0); - Vec2Copyf(v1_3d, v1); - Vec2Copyf(v2_3d, v2); - - /* Doing this in 3D is not nice */ - LineIntersectsTriangle(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv); - } -} - -int IsPointInTri2D(float v1[2], float v2[2], float v3[2], float pt[2]) -{ - float inp1, inp2, inp3; - - inp1= (v2[0]-v1[0])*(v1[1]-pt[1]) + (v1[1]-v2[1])*(v1[0]-pt[0]); - inp2= (v3[0]-v2[0])*(v2[1]-pt[1]) + (v2[1]-v3[1])*(v2[0]-pt[0]); - inp3= (v1[0]-v3[0])*(v3[1]-pt[1]) + (v3[1]-v1[1])*(v3[0]-pt[0]); - - if(inp1<=0.0f && inp2<=0.0f && inp3<=0.0f) return 1; - if(inp1>=0.0f && inp2>=0.0f && inp3>=0.0f) return 1; - - return 0; -} - -#if 0 -int IsPointInTri2D(float v0[2], float v1[2], float v2[2], float pt[2]) -{ - /* not for quads, use for our abuse of LineIntersectsTriangleUV */ - float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3]; - /* not used */ - float lambda, uv[3]; - - p1_3d[0] = p2_3d[0] = uv[0]= pt[0]; - p1_3d[1] = p2_3d[1] = uv[1]= uv[2]= pt[1]; - p1_3d[2] = 1.0f; - p2_3d[2] = -1.0f; - v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0; - - /* generate a new fuv, (this is possibly a non optimal solution, - * since we only need 2d calculation but use 3d func's) - * - * this method makes an imaginary triangle in 2d space using the UV's from the derived mesh face - * Then find new uv coords using the fuv and this face with LineIntersectsTriangleUV. - * This means the new values will be correct in relation to the derived meshes face. - */ - Vec2Copyf(v0_3d, v0); - Vec2Copyf(v1_3d, v1); - Vec2Copyf(v2_3d, v2); - - /* Doing this in 3D is not nice */ - return LineIntersectsTriangle(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv); -} -#endif - -/* - - x1,y2 - | \ - | \ .(a,b) - | \ - x1,y1-- x2,y1 - -*/ -int IsPointInTri2DInts(int x1, int y1, int x2, int y2, int a, int b) -{ - float v1[2], v2[2], v3[2], p[2]; - - v1[0]= (float)x1; - v1[1]= (float)y1; - - v2[0]= (float)x1; - v2[1]= (float)y2; - - v3[0]= (float)x2; - v3[1]= (float)y1; - - p[0]= (float)a; - p[1]= (float)b; - - return IsPointInTri2D(v1, v2, v3, p); - -} - -/* (x1,v1)(t1=0)------(x2,v2)(t2=1), 0<t<1 --> (x,v)(t) */ -void VecfCubicInterpol(float *x1, float *v1, float *x2, float *v2, float t, float *x, float *v) -{ - float a[3],b[3]; - float t2= t*t; - float t3= t2*t; - - /* cubic interpolation */ - a[0]= v1[0] + v2[0] + 2*(x1[0] - x2[0]); - a[1]= v1[1] + v2[1] + 2*(x1[1] - x2[1]); - a[2]= v1[2] + v2[2] + 2*(x1[2] - x2[2]); - - b[0]= -2*v1[0] - v2[0] - 3*(x1[0] - x2[0]); - b[1]= -2*v1[1] - v2[1] - 3*(x1[1] - x2[1]); - b[2]= -2*v1[2] - v2[2] - 3*(x1[2] - x2[2]); - - x[0]= a[0]*t3 + b[0]*t2 + v1[0]*t + x1[0]; - x[1]= a[1]*t3 + b[1]*t2 + v1[1]*t + x1[1]; - x[2]= a[2]*t3 + b[2]*t2 + v1[2]*t + x1[2]; - - v[0]= 3*a[0]*t2 + 2*b[0]*t + v1[0]; - v[1]= 3*a[1]*t2 + 2*b[1]*t + v1[1]; - v[2]= 3*a[2]*t2 + 2*b[2]*t + v1[2]; -} - -static int point_in_slice(float p[3], float v1[3], float l1[3], float l2[3]) -{ -/* -what is a slice ? -some maths: -a line including l1,l2 and a point not on the line -define a subset of R3 delimeted by planes parallel to the line and orthogonal -to the (point --> line) distance vector,one plane on the line one on the point, -the room inside usually is rather small compared to R3 though still infinte -useful for restricting (speeding up) searches -e.g. all points of triangular prism are within the intersection of 3 'slices' -onother trivial case : cube -but see a 'spat' which is a deformed cube with paired parallel planes needs only 3 slices too -*/ - float h,rp[3],cp[3],q[3]; - - lambda_cp_line_ex(v1,l1,l2,cp); - VecSubf(q,cp,v1); - - VecSubf(rp,p,v1); - h=Inpf(q,rp)/Inpf(q,q); - if (h < 0.0f || h > 1.0f) return 0; - return 1; -} - -#if 0 -/*adult sister defining the slice planes by the origin and the normal -NOTE |normal| may not be 1 but defining the thickness of the slice*/ -static int point_in_slice_as(float p[3],float origin[3],float normal[3]) -{ - float h,rp[3]; - VecSubf(rp,p,origin); - h=Inpf(normal,rp)/Inpf(normal,normal); - if (h < 0.0f || h > 1.0f) return 0; - return 1; -} - -/*mama (knowing the squared lenght of the normal)*/ -static int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns) -{ - float h,rp[3]; - VecSubf(rp,p,origin); - h=Inpf(normal,rp)/lns; - if (h < 0.0f || h > 1.0f) return 0; - return 1; -} -#endif - - -int point_in_tri_prism(float p[3], float v1[3], float v2[3], float v3[3]) -{ - if(!point_in_slice(p,v1,v2,v3)) return 0; - if(!point_in_slice(p,v2,v3,v1)) return 0; - if(!point_in_slice(p,v3,v1,v2)) return 0; - return 1; -} - -/* point closest to v1 on line v2-v3 in 3D */ -void PclosestVL3Dfl(float *closest, float v1[3], float v2[3], float v3[3]) -{ - float lambda, cp[3]; - - lambda= lambda_cp_line_ex(v1, v2, v3, cp); - - if(lambda <= 0.0f) - VecCopyf(closest, v2); - else if(lambda >= 1.0f) - VecCopyf(closest, v3); - else - VecCopyf(closest, cp); -} - -/* distance v1 to line-piece v2-v3 in 3D */ -float PdistVL3Dfl(float *v1, float *v2, float *v3) -{ - float closest[3]; - - PclosestVL3Dfl(closest, v1, v2, v3); - - return VecLenf(closest, v1); -} - -/********************************************************/ - -/* make a 4x4 matrix out of 3 transform components */ -/* matrices are made in the order: scale * rot * loc */ -// TODO: need to have a version that allows for rotation order... -void LocEulSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3]) -{ - float rmat[3][3], smat[3][3], tmat[3][3]; - - /* initialise new matrix */ - Mat4One(mat); - - /* make rotation + scaling part */ - EulToMat3(eul, rmat); - SizeToMat3(size, smat); - Mat3MulMat3(tmat, rmat, smat); - - /* copy rot/scale part to output matrix*/ - Mat4CpyMat3(mat, tmat); - - /* copy location to matrix */ - mat[3][0] = loc[0]; - mat[3][1] = loc[1]; - mat[3][2] = loc[2]; -} - -/* make a 4x4 matrix out of 3 transform components */ -/* matrices are made in the order: scale * rot * loc */ -void LocEulOSizeToMat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder) -{ - float rmat[3][3], smat[3][3], tmat[3][3]; - - /* initialise new matrix */ - Mat4One(mat); - - /* make rotation + scaling part */ - EulOToMat3(eul, rotOrder, rmat); - SizeToMat3(size, smat); - Mat3MulMat3(tmat, rmat, smat); - - /* copy rot/scale part to output matrix*/ - Mat4CpyMat3(mat, tmat); - - /* copy location to matrix */ - mat[3][0] = loc[0]; - mat[3][1] = loc[1]; - mat[3][2] = loc[2]; -} - - -/* make a 4x4 matrix out of 3 transform components */ -/* matrices are made in the order: scale * rot * loc */ -void LocQuatSizeToMat4(float mat[4][4], float loc[3], float quat[4], float size[3]) -{ - float rmat[3][3], smat[3][3], tmat[3][3]; - - /* initialise new matrix */ - Mat4One(mat); - - /* make rotation + scaling part */ - QuatToMat3(quat, rmat); - SizeToMat3(size, smat); - Mat3MulMat3(tmat, rmat, smat); - - /* copy rot/scale part to output matrix*/ - Mat4CpyMat3(mat, tmat); - - /* copy location to matrix */ - mat[3][0] = loc[0]; - mat[3][1] = loc[1]; - mat[3][2] = loc[2]; -} - -/********************************************************/ - -/* Tangents */ - -/* For normal map tangents we need to detect uv boundaries, and only average - * tangents in case the uvs are connected. Alternative would be to store 1 - * tangent per face rather than 4 per face vertex, but that's not compatible - * with games */ - - -/* from BKE_mesh.h */ -#define STD_UV_CONNECT_LIMIT 0.0001f - -void sum_or_add_vertex_tangent(void *arena, VertexTangent **vtang, float *tang, float *uv) -{ - VertexTangent *vt; - - /* find a tangent with connected uvs */ - for(vt= *vtang; vt; vt=vt->next) { - if(fabs(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabs(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) { - VecAddf(vt->tang, vt->tang, tang); - return; - } - } - - /* if not found, append a new one */ - vt= BLI_memarena_alloc((MemArena *)arena, sizeof(VertexTangent)); - VecCopyf(vt->tang, tang); - vt->uv[0]= uv[0]; - vt->uv[1]= uv[1]; - - if(*vtang) - vt->next= *vtang; - *vtang= vt; -} - -float *find_vertex_tangent(VertexTangent *vtang, float *uv) -{ - VertexTangent *vt; - static float nulltang[3] = {0.0f, 0.0f, 0.0f}; - - for(vt= vtang; vt; vt=vt->next) - if(fabs(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabs(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) - return vt->tang; - - return nulltang; /* shouldn't happen, except for nan or so */ -} - -void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2, float *co3, float *n, float *tang) -{ - float tangv[3], ct[3], e1[3], e2[3], s1, t1, s2, t2, det; - - s1= uv2[0] - uv1[0]; - s2= uv3[0] - uv1[0]; - t1= uv2[1] - uv1[1]; - t2= uv3[1] - uv1[1]; - det= 1.0f / (s1 * t2 - s2 * t1); - - /* normals in render are inversed... */ - VecSubf(e1, co1, co2); - VecSubf(e2, co1, co3); - tang[0] = (t2*e1[0] - t1*e2[0])*det; - tang[1] = (t2*e1[1] - t1*e2[1])*det; - tang[2] = (t2*e1[2] - t1*e2[2])*det; - tangv[0] = (s1*e2[0] - s2*e1[0])*det; - tangv[1] = (s1*e2[1] - s2*e1[1])*det; - tangv[2] = (s1*e2[2] - s2*e1[2])*det; - Crossf(ct, tang, tangv); - - /* check flip */ - if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f) - VecNegf(tang); -} - -/* used for zoom values*/ -float power_of_2(float val) { - return (float)pow(2, ceil(log(val) / log(2))); -} diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c index 7d5e1eec53e..d31bc4e762d 100644 --- a/source/blender/blenlib/intern/boxpack2d.c +++ b/source/blender/blenlib/intern/boxpack2d.c @@ -31,7 +31,7 @@ * The defined Below are for internal use only */ /* free vert flags */ -#define eul 0.0000001f +#define eps 0.0000001f #define BLF 1 #define TRF 2 #define TLF 4 @@ -68,10 +68,10 @@ b->v[TR]->y = f;\ UPDATE_V34Y(b) #define BOXINTERSECT(b1, b2)\ - (!( BOXLEFT(b1)+eul>=BOXRIGHT(b2) ||\ - BOXBOTTOM(b1)+eul>=BOXTOP(b2) ||\ - BOXRIGHT(b1)-eul<=BOXLEFT(b2) ||\ - BOXTOP(b1)-eul<=BOXBOTTOM(b2) )) + (!( BOXLEFT(b1)+eps>=BOXRIGHT(b2) ||\ + BOXBOTTOM(b1)+eps>=BOXTOP(b2) ||\ + BOXRIGHT(b1)-eps<=BOXLEFT(b2) ||\ + BOXTOP(b1)-eps<=BOXBOTTOM(b2) )) #define MIN2(x,y) ( (x)<(y) ? (x) : (y) ) #define MAX2(x,y) ( (x)>(y) ? (x) : (y) ) diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index cb5632df569..f2727f6f259 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -45,7 +45,7 @@ #include "BLI_vfontdata.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" //XXX #include "BIF_toolbox.h" @@ -256,11 +256,11 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf // VecLenf, see if there's a distance between the three points // VecLenf again, to check the angle between the handles // finally, check if one of them is a vector handle - if((DistVL2Dfl(bezt->vec[0],bezt->vec[1],bezt->vec[2]) < 0.001) && - (VecLenf(bezt->vec[0], bezt->vec[1]) > 0.0001) && - (VecLenf(bezt->vec[1], bezt->vec[2]) > 0.0001) && - (VecLenf(bezt->vec[0], bezt->vec[2]) > 0.0002) && - (VecLenf(bezt->vec[0], bezt->vec[2]) > MAX2(VecLenf(bezt->vec[0], bezt->vec[1]), VecLenf(bezt->vec[1], bezt->vec[2]))) && + if((dist_to_line_v2(bezt->vec[0],bezt->vec[1],bezt->vec[2]) < 0.001) && + (len_v3v3(bezt->vec[0], bezt->vec[1]) > 0.0001) && + (len_v3v3(bezt->vec[1], bezt->vec[2]) > 0.0001) && + (len_v3v3(bezt->vec[0], bezt->vec[2]) > 0.0002) && + (len_v3v3(bezt->vec[0], bezt->vec[2]) > MAX2(len_v3v3(bezt->vec[0], bezt->vec[1]), len_v3v3(bezt->vec[1], bezt->vec[2]))) && bezt->h1 != HD_VECT && bezt->h2 != HD_VECT) { bezt->h1= bezt->h2= HD_ALIGN; diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index 49a3cad53f1..fd6bb1a2014 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -30,7 +30,7 @@ #include "BLI_graph.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" @@ -267,7 +267,7 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit) { for(node_replaced = graph->nodes.first; node_replaced; node_replaced = node_replaced->next) { - if (node_replaced != node_src && VecLenf(node_replaced->p, node_src->p) <= limit) + if (node_replaced != node_src && len_v3v3(node_replaced->p, node_src->p) <= limit) { BLI_replaceNode(graph, node_src, node_replaced); } @@ -283,7 +283,7 @@ BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit) for(node = graph->nodes.first; node; node = node->next) { - float distance = VecLenf(p, node->p); + float distance = len_v3v3(p, node->p); if (distance <= limit && (closest_node == NULL || distance < min_distance)) { closest_node = node; @@ -526,10 +526,10 @@ void BLI_mirrorAlongAxis(float v[3], float center[3], float axis[3]) { float dv[3], pv[3]; - VecSubf(dv, v, center); - Projf(pv, dv, axis); - VecMulf(pv, -2); - VecAddf(v, v, pv); + sub_v3_v3v3(dv, v, center); + project_v3_v3v3(pv, dv, axis); + mul_v3_fl(pv, -2); + add_v3_v3v3(v, v, pv); } static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, int total, float axis[3], float limit, int group) @@ -546,7 +546,7 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, for (j = i + 1; j < total; j++) { - float angle = Inpf(ring[i].n, ring[j].n); + float angle = dot_v3v3(ring[i].n, ring[j].n); /* map negative values to 1..2 */ if (angle < 0) @@ -579,8 +579,8 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, float p[3]; int j = (i + 1) % total; /* next arc in the circular list */ - VecAddf(tangent, ring[i].n, ring[j].n); - Crossf(normal, tangent, axis); + add_v3_v3v3(tangent, ring[i].n, ring[j].n); + cross_v3_v3v3(normal, tangent, axis); node1 = BLI_otherNode(ring[i].arc, root_node); node2 = BLI_otherNode(ring[j].arc, root_node); @@ -589,7 +589,7 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, BLI_mirrorAlongAxis(p, root_node->p, normal); /* check if it's within limit before continuing */ - if (VecLenf(node1->p, p) > limit) + if (len_v3v3(node1->p, p) > limit) { symmetric = 0; } @@ -658,11 +658,11 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo unit->arc = connectedArc; /* project the node to node vector on the symmetry plane */ - VecSubf(unit->n, otherNode->p, root_node->p); - Projf(vec, unit->n, axis); - VecSubf(unit->n, unit->n, vec); + sub_v3_v3v3(unit->n, otherNode->p, root_node->p); + project_v3_v3v3(vec, unit->n, axis); + sub_v3_v3v3(unit->n, unit->n, vec); - Normalize(unit->n); + normalize_v3(unit->n); unit++; } @@ -780,9 +780,9 @@ static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int arc->symmetry_group = group; - VecSubf(vec, end_node->p, root_node->p); + sub_v3_v3v3(vec, end_node->p, root_node->p); - if (Inpf(vec, root_node->symmetry_axis) < 0) + if (dot_v3v3(vec, root_node->symmetry_axis) < 0) { arc->symmetry_flag |= SYM_SIDE_NEGATIVE; } @@ -796,26 +796,26 @@ static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNo { float nor[3], vec[3], p[3]; - VecSubf(p, node1->p, root_node->p); - Crossf(nor, p, axis); + sub_v3_v3v3(p, node1->p, root_node->p); + cross_v3_v3v3(nor, p, axis); - VecSubf(p, root_node->p, node2->p); - Crossf(vec, p, axis); - VecAddf(vec, vec, nor); + sub_v3_v3v3(p, root_node->p, node2->p); + cross_v3_v3v3(vec, p, axis); + add_v3_v3v3(vec, vec, nor); - Crossf(nor, vec, axis); + cross_v3_v3v3(nor, vec, axis); if (abs(nor[0]) > abs(nor[1]) && abs(nor[0]) > abs(nor[2]) && nor[0] < 0) { - VecNegf(nor); + negate_v3(nor); } else if (abs(nor[1]) > abs(nor[0]) && abs(nor[1]) > abs(nor[2]) && nor[1] < 0) { - VecNegf(nor); + negate_v3(nor); } else if (abs(nor[2]) > abs(nor[1]) && abs(nor[2]) > abs(nor[0]) && nor[2] < 0) { - VecNegf(nor); + negate_v3(nor); } /* mirror node2 along axis */ @@ -823,7 +823,7 @@ static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNo BLI_mirrorAlongAxis(p, root_node->p, nor); /* check if it's within limit before continuing */ - if (VecLenf(node1->p, p) <= limit) + if (len_v3v3(node1->p, p) <= limit) { /* mark node as symmetric physically */ VECCOPY(root_node->symmetry_axis, nor); @@ -905,12 +905,12 @@ static void markdownSecondarySymmetry(BGraph *graph, BNode *node, int depth, int /* If arc is on the axis */ else if (connectedArc->symmetry_level == level) { - VecAddf(axis, axis, connectedArc->head->p); - VecSubf(axis, axis, connectedArc->tail->p); + add_v3_v3v3(axis, axis, connectedArc->head->p); + sub_v3_v3v3(axis, axis, connectedArc->tail->p); } } - Normalize(axis); + normalize_v3(axis); /* Split between axial and radial symmetry */ if (count == 2) diff --git a/source/blender/blenlib/intern/jitter.c b/source/blender/blenlib/intern/jitter.c index fd658765802..e7933ee98a2 100644 --- a/source/blender/blenlib/intern/jitter.c +++ b/source/blender/blenlib/intern/jitter.c @@ -34,7 +34,7 @@ #include <string.h> #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BLI_jitter.h" diff --git a/source/blender/blenlib/intern/math_base.c b/source/blender/blenlib/intern/math_base.c new file mode 100644 index 00000000000..f3fe09c088f --- /dev/null +++ b/source/blender/blenlib/intern/math_base.c @@ -0,0 +1,111 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "BLI_math.h" + +/* A few small defines. Keep'em local! */ +#define SMALL_NUMBER 1.e-8 + +float sqrt3f(float f) +{ + if(f==0.0) return 0; + if(f<0) return (float)(-exp(log(-f)/3)); + else return (float)(exp(log(f)/3)); +} + +double sqrt3d(double d) +{ + if(d==0.0) return 0; + if(d<0) return -exp(log(-d)/3); + else return exp(log(d)/3); +} + +float saacos(float fac) +{ + if(fac<= -1.0f) return (float)M_PI; + else if(fac>=1.0f) return 0.0; + else return (float)acos(fac); +} + +float saasin(float fac) +{ + if(fac<= -1.0f) return (float)-M_PI/2.0f; + else if(fac>=1.0f) return (float)M_PI/2.0f; + else return (float)asin(fac); +} + +float sasqrt(float fac) +{ + if(fac<=0.0) return 0.0; + return (float)sqrt(fac); +} + +float saacosf(float fac) +{ + if(fac<= -1.0f) return (float)M_PI; + else if(fac>=1.0f) return 0.0f; + else return (float)acosf(fac); +} + +float saasinf(float fac) +{ + if(fac<= -1.0f) return (float)-M_PI/2.0f; + else if(fac>=1.0f) return (float)M_PI/2.0f; + else return (float)asinf(fac); +} + +float sasqrtf(float fac) +{ + if(fac<=0.0) return 0.0; + return (float)sqrtf(fac); +} + +float interpf(float target, float origin, float fac) +{ + return (fac*target) + (1.0f-fac)*origin; +} + +/* useful to calculate an even width shell, by taking the angle between 2 planes. + * The return value is a scale on the offset. + * no angle between planes is 1.0, as the angle between the 2 planes approches 180d + * the distance gets very high, 180d would be inf, but this case isn't valid */ +float shell_angle_to_dist(const float angle) +{ + return (angle < SMALL_NUMBER) ? 1.0f : fabsf(1.0f / cosf(angle * (M_PI/180.0f))); +} + +/* used for zoom values*/ +float power_of_2(float val) +{ + return (float)pow(2, ceil(log(val) / log(2))); +} + diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c new file mode 100644 index 00000000000..7ae380a1dde --- /dev/null +++ b/source/blender/blenlib/intern/math_color.c @@ -0,0 +1,313 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "BLI_math.h" + +void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b) +{ + int i; + float f, p, q, t; + + h *= 360.0f; + + if(s==0.0f) { + *r = v; + *g = v; + *b = v; + } + else { + if(h== 360.0f) h = 0.0f; + + h /= 60.0f; + i = (int)floor(h); + f = h - i; + p = v*(1.0f-s); + q = v*(1.0f-(s*f)); + t = v*(1.0f-(s*(1.0f-f))); + + switch (i) { + case 0 : + *r = v; + *g = t; + *b = p; + break; + case 1 : + *r = q; + *g = v; + *b = p; + break; + case 2 : + *r = p; + *g = v; + *b = t; + break; + case 3 : + *r = p; + *g = q; + *b = v; + break; + case 4 : + *r = t; + *g = p; + *b = v; + break; + case 5 : + *r = v; + *g = p; + *b = q; + break; + } + } +} + +void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv) +{ + float y, u, v; + y= 0.299f*r + 0.587f*g + 0.114f*b; + u=-0.147f*r - 0.289f*g + 0.436f*b; + v= 0.615f*r - 0.515f*g - 0.100f*b; + + *ly=y; + *lu=u; + *lv=v; +} + +void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb) +{ + float r, g, b; + r=y+1.140f*v; + g=y-0.394f*u - 0.581f*v; + b=y+2.032f*u; + + *lr=r; + *lg=g; + *lb=b; +} + +void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr) +{ + float sr,sg, sb; + float y, cr, cb; + + sr=255.0f*r; + sg=255.0f*g; + sb=255.0f*b; + + + y=(0.257f*sr)+(0.504f*sg)+(0.098f*sb)+16.0f; + cb=(-0.148f*sr)-(0.291f*sg)+(0.439f*sb)+128.0f; + cr=(0.439f*sr)-(0.368f*sg)-(0.071f*sb)+128.0f; + + *ly=y; + *lcb=cb; + *lcr=cr; +} + +void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb) +{ + float r,g,b; + + r=1.164f*(y-16.0f)+1.596f*(cr-128.0f); + g=1.164f*(y-16.0f)-0.813f*(cr-128.0f)-0.392f*(cb-128.0f); + b=1.164f*(y-16.0f)+2.017f*(cb-128.0f); + + *lr=r/255.0f; + *lg=g/255.0f; + *lb=b/255.0f; +} + +void hex_to_rgb(char *hexcol, float *r, float *g, float *b) +{ + unsigned int ri, gi, bi; + + if (hexcol[0] == '#') hexcol++; + + if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)) { + *r = ri / 255.0f; + *g = gi / 255.0f; + *b = bi / 255.0f; + } +} + +void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv) +{ + float h, s, v; + float cmax, cmin, cdelta; + float rc, gc, bc; + + cmax = r; + cmin = r; + cmax = (g>cmax ? g:cmax); + cmin = (g<cmin ? g:cmin); + cmax = (b>cmax ? b:cmax); + cmin = (b<cmin ? b:cmin); + + v = cmax; /* value */ + if (cmax != 0.0f) + s = (cmax - cmin)/cmax; + else { + s = 0.0f; + h = 0.0f; + } + if (s == 0.0f) + h = -1.0f; + else { + cdelta = cmax-cmin; + rc = (cmax-r)/cdelta; + gc = (cmax-g)/cdelta; + bc = (cmax-b)/cdelta; + if (r==cmax) + h = bc-gc; + else + if (g==cmax) + h = 2.0f+rc-bc; + else + h = 4.0f+gc-rc; + h = h*60.0f; + if (h < 0.0f) + h += 360.0f; + } + + *ls = s; + *lh = h / 360.0f; + if(*lh < 0.0f) *lh= 0.0f; + *lv = v; +} + +/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */ + +void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace) +{ + switch (colorspace) { + case BLI_CS_SMPTE: + *r = (3.50570f * xc) + (-1.73964f * yc) + (-0.544011f * zc); + *g = (-1.06906f * xc) + (1.97781f * yc) + (0.0351720f * zc); + *b = (0.0563117f * xc) + (-0.196994f * yc) + (1.05005f * zc); + break; + case BLI_CS_REC709: + *r = (3.240476f * xc) + (-1.537150f * yc) + (-0.498535f * zc); + *g = (-0.969256f * xc) + (1.875992f * yc) + (0.041556f * zc); + *b = (0.055648f * xc) + (-0.204043f * yc) + (1.057311f * zc); + break; + case BLI_CS_CIE: + *r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc); + *g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc); + *b = (0.00572040983140966f * xc) + (-0.0159068485104036f * yc) + (1.0101864083734f * zc); + break; + } +} + +/* we define a 'cpack' here as a (3 byte color code) number that can be expressed like 0xFFAA66 or so. + for that reason it is sensitive for endianness... with this function it works correctly +*/ + +unsigned int hsv_to_cpack(float h, float s, float v) +{ + short r, g, b; + float rf, gf, bf; + unsigned int col; + + hsv_to_rgb(h, s, v, &rf, &gf, &bf); + + r= (short)(rf*255.0f); + g= (short)(gf*255.0f); + b= (short)(bf*255.0f); + + col= ( r + (g*256) + (b*256*256) ); + return col; +} + + +unsigned int rgb_to_cpack(float r, float g, float b) +{ + int ir, ig, ib; + + ir= (int)floor(255.0*r); + if(ir<0) ir= 0; else if(ir>255) ir= 255; + ig= (int)floor(255.0*g); + if(ig<0) ig= 0; else if(ig>255) ig= 255; + ib= (int)floor(255.0*b); + if(ib<0) ib= 0; else if(ib>255) ib= 255; + + return (ir+ (ig*256) + (ib*256*256)); +} + +void cpack_to_rgb(unsigned int col, float *r, float *g, float *b) +{ + + *r= (float)((col)&0xFF); + *r /= 255.0f; + + *g= (float)(((col)>>8)&0xFF); + *g /= 255.0f; + + *b= (float)(((col)>>16)&0xFF); + *b /= 255.0f; +} + +void minmax_rgb(short c[]) +{ + if(c[0]>255) c[0]=255; + else if(c[0]<0) c[0]=0; + if(c[1]>255) c[1]=255; + else if(c[1]<0) c[1]=0; + if(c[2]>255) c[2]=255; + else if(c[2]<0) c[2]=0; +} + +/*If the requested RGB shade contains a negative weight for + one of the primaries, it lies outside the colour gamut + accessible from the given triple of primaries. Desaturate + it by adding white, equal quantities of R, G, and B, enough + to make RGB all positive. The function returns 1 if the + components were modified, zero otherwise.*/ +int constrain_rgb(float *r, float *g, float *b) +{ + float w; + + /* Amount of white needed is w = - min(0, *r, *g, *b) */ + + w = (0 < *r) ? 0 : *r; + w = (w < *g) ? w : *g; + w = (w < *b) ? w : *b; + w = -w; + + /* Add just enough white to make r, g, b all positive. */ + + if (w > 0) { + *r += w; *g += w; *b += w; + return 1; /* Color modified to fit RGB gamut */ + } + + return 0; /* Color within RGB gamut */ +} + diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c new file mode 100644 index 00000000000..0b3ab2f0afc --- /dev/null +++ b/source/blender/blenlib/intern/math_geom.c @@ -0,0 +1,1599 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "BLI_math.h" +#include "BLI_memarena.h" + +/********************************** Polygons *********************************/ + +void cent_tri_v3(float *cent, float *v1, float *v2, float *v3) +{ + cent[0]= 0.33333f*(v1[0]+v2[0]+v3[0]); + cent[1]= 0.33333f*(v1[1]+v2[1]+v3[1]); + cent[2]= 0.33333f*(v1[2]+v2[2]+v3[2]); +} + +void cent_quad_v3(float *cent, float *v1, float *v2, float *v3, float *v4) +{ + cent[0]= 0.25f*(v1[0]+v2[0]+v3[0]+v4[0]); + cent[1]= 0.25f*(v1[1]+v2[1]+v3[1]+v4[1]); + cent[2]= 0.25f*(v1[2]+v2[2]+v3[2]+v4[2]); +} + +float normal_tri_v3(float *n, float *v1, float *v2, float *v3) +{ + float n1[3],n2[3]; + + n1[0]= v1[0]-v2[0]; + n2[0]= v2[0]-v3[0]; + n1[1]= v1[1]-v2[1]; + n2[1]= v2[1]-v3[1]; + n1[2]= v1[2]-v2[2]; + n2[2]= v2[2]-v3[2]; + n[0]= n1[1]*n2[2]-n1[2]*n2[1]; + n[1]= n1[2]*n2[0]-n1[0]*n2[2]; + n[2]= n1[0]*n2[1]-n1[1]*n2[0]; + return normalize_v3(n); +} + +float normal_quad_v3(float *n, float *v1, float *v2, float *v3, float *v4) +{ + /* real cross! */ + float n1[3],n2[3]; + + n1[0]= v1[0]-v3[0]; + n1[1]= v1[1]-v3[1]; + n1[2]= v1[2]-v3[2]; + + n2[0]= v2[0]-v4[0]; + n2[1]= v2[1]-v4[1]; + n2[2]= v2[2]-v4[2]; + + n[0]= n1[1]*n2[2]-n1[2]*n2[1]; + n[1]= n1[2]*n2[0]-n1[0]*n2[2]; + n[2]= n1[0]*n2[1]-n1[1]*n2[0]; + + return normalize_v3(n); +} + +float area_tri_v2(float *v1, float *v2, float *v3) +{ + return (float)(0.5*fabs((v1[0]-v2[0])*(v2[1]-v3[1]) + (v1[1]-v2[1])*(v3[0]-v2[0]))); +} + + +float area_quad_v3(float *v1, float *v2, float *v3, float *v4) /* only convex Quadrilaterals */ +{ + float len, vec1[3], vec2[3], n[3]; + + sub_v3_v3v3(vec1, v2, v1); + sub_v3_v3v3(vec2, v4, v1); + cross_v3_v3v3(n, vec1, vec2); + len= normalize_v3(n); + + sub_v3_v3v3(vec1, v4, v3); + sub_v3_v3v3(vec2, v2, v3); + cross_v3_v3v3(n, vec1, vec2); + len+= normalize_v3(n); + + return (len/2.0f); +} + +float area_tri_v3(float *v1, float *v2, float *v3) /* Triangles */ +{ + float len, vec1[3], vec2[3], n[3]; + + sub_v3_v3v3(vec1, v3, v2); + sub_v3_v3v3(vec2, v1, v2); + cross_v3_v3v3(n, vec1, vec2); + len= normalize_v3(n); + + return (len/2.0f); +} + +#define MAX2(x,y) ((x)>(y) ? (x) : (y)) +#define MAX3(x,y,z) MAX2(MAX2((x),(y)) , (z)) + + +float area_poly_v3(int nr, float verts[][3], float *normal) +{ + float x, y, z, area, max; + float *cur, *prev; + int a, px=0, py=1; + + /* first: find dominant axis: 0==X, 1==Y, 2==Z */ + x= (float)fabs(normal[0]); + y= (float)fabs(normal[1]); + z= (float)fabs(normal[2]); + max = MAX3(x, y, z); + if(max==y) py=2; + else if(max==x) { + px=1; + py= 2; + } + + /* The Trapezium Area Rule */ + prev= verts[nr-1]; + cur= verts[0]; + area= 0; + for(a=0; a<nr; a++) { + area+= (cur[px]-prev[px])*(cur[py]+prev[py]); + prev= verts[a]; + cur= verts[a+1]; + } + + return (float)fabs(0.5*area/max); +} + +/********************************* Distance **********************************/ + +/* distance v1 to line v2-v3 */ +/* using Hesse formula, NO LINE PIECE! */ +float dist_to_line_v2(float *v1, float *v2, float *v3) +{ + float a[2],deler; + + a[0]= v2[1]-v3[1]; + a[1]= v3[0]-v2[0]; + deler= (float)sqrt(a[0]*a[0]+a[1]*a[1]); + if(deler== 0.0f) return 0; + + return (float)(fabs((v1[0]-v2[0])*a[0]+(v1[1]-v2[1])*a[1])/deler); + +} + +/* distance v1 to line-piece v2-v3 */ +float dist_to_line_segment_v2(float *v1, float *v2, float *v3) +{ + float labda, rc[2], pt[2], len; + + rc[0]= v3[0]-v2[0]; + rc[1]= v3[1]-v2[1]; + len= rc[0]*rc[0]+ rc[1]*rc[1]; + if(len==0.0) { + rc[0]= v1[0]-v2[0]; + rc[1]= v1[1]-v2[1]; + return (float)(sqrt(rc[0]*rc[0]+ rc[1]*rc[1])); + } + + labda= (rc[0]*(v1[0]-v2[0]) + rc[1]*(v1[1]-v2[1]))/len; + if(labda<=0.0) { + pt[0]= v2[0]; + pt[1]= v2[1]; + } + else if(labda>=1.0) { + pt[0]= v3[0]; + pt[1]= v3[1]; + } + else { + pt[0]= labda*rc[0]+v2[0]; + pt[1]= labda*rc[1]+v2[1]; + } + + rc[0]= pt[0]-v1[0]; + rc[1]= pt[1]-v1[1]; + return (float)sqrt(rc[0]*rc[0]+ rc[1]*rc[1]); +} + +/* point closest to v1 on line v2-v3 in 3D */ +void closest_to_line_segment_v3(float *closest, float v1[3], float v2[3], float v3[3]) +{ + float lambda, cp[3]; + + lambda= closest_to_line_v3(cp,v1, v2, v3); + + if(lambda <= 0.0f) + copy_v3_v3(closest, v2); + else if(lambda >= 1.0f) + copy_v3_v3(closest, v3); + else + copy_v3_v3(closest, cp); +} + +/* distance v1 to line-piece v2-v3 in 3D */ +float dist_to_line_segment_v3(float *v1, float *v2, float *v3) +{ + float closest[3]; + + closest_to_line_segment_v3(closest, v1, v2, v3); + + return len_v3v3(closest, v1); +} + +/******************************* Intersection ********************************/ + +/* intersect Line-Line, shorts */ +int isect_line_line_v2_short(short *v1, short *v2, short *v3, short *v4) +{ + /* return: + -1: colliniar + 0: no intersection of segments + 1: exact intersection of segments + 2: cross-intersection of segments + */ + float div, labda, mu; + + div= (float)((v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0])); + if(div==0.0f) return -1; + + labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div; + + mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div; + + if(labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) { + if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return 1; + return 2; + } + return 0; +} + +/* intersect Line-Line, floats */ +int isect_line_line_v2(float *v1, float *v2, float *v3, float *v4) +{ + /* return: + -1: colliniar +0: no intersection of segments +1: exact intersection of segments +2: cross-intersection of segments + */ + float div, labda, mu; + + div= (v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]); + if(div==0.0) return -1; + + labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div; + + mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div; + + if(labda>=0.0 && labda<=1.0 && mu>=0.0 && mu<=1.0) { + if(labda==0.0 || labda==1.0 || mu==0.0 || mu==1.0) return 1; + return 2; + } + return 0; +} + +/* +-1: colliniar + 1: intersection + +*/ +static short IsectLLPt2Df(float x0,float y0,float x1,float y1, + float x2,float y2,float x3,float y3, float *xi,float *yi) + +{ + /* + this function computes the intersection of the sent lines + and returns the intersection point, note that the function assumes + the lines intersect. the function can handle vertical as well + as horizontal lines. note the function isn't very clever, it simply + applies the math, but we don't need speed since this is a + pre-processing step + */ + float c1,c2, // constants of linear equations + det_inv, // the inverse of the determinant of the coefficient + m1,m2; // the slopes of each line + /* + compute slopes, note the cludge for infinity, however, this will + be close enough + */ + if (fabs(x1-x0) > 0.000001) + m1 = (y1-y0) / (x1-x0); + else + return -1; /*m1 = (float) 1e+10;*/ // close enough to infinity + + if (fabs(x3-x2) > 0.000001) + m2 = (y3-y2) / (x3-x2); + else + return -1; /*m2 = (float) 1e+10;*/ // close enough to infinity + + if (fabs(m1-m2) < 0.000001) + return -1; /* paralelle lines */ + +// compute constants + + c1 = (y0-m1*x0); + c2 = (y2-m2*x2); + +// compute the inverse of the determinate + + det_inv = 1.0f / (-m1 + m2); + +// use Kramers rule to compute xi and yi + + *xi= ((-c2 + c1) *det_inv); + *yi= ((m2*c1 - m1*c2) *det_inv); + + return 1; +} // end Intersect_Lines + +#define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1])) +/* point in tri */ +// XXX was called IsectPT2Df +int isect_point_tri_v2(float pt[2], float v1[2], float v2[2], float v3[2]) +{ + if (SIDE_OF_LINE(v1,v2,pt)>=0.0) { + if (SIDE_OF_LINE(v2,v3,pt)>=0.0) { + if (SIDE_OF_LINE(v3,v1,pt)>=0.0) { + return 1; + } + } + } else { + if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0)) { + if (! (SIDE_OF_LINE(v3,v1,pt)>=0.0)) { + return -1; + } + } + } + + return 0; +} +/* point in quad - only convex quads */ +int isect_point_quad_v2(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2]) +{ + if (SIDE_OF_LINE(v1,v2,pt)>=0.0) { + if (SIDE_OF_LINE(v2,v3,pt)>=0.0) { + if (SIDE_OF_LINE(v3,v4,pt)>=0.0) { + if (SIDE_OF_LINE(v4,v1,pt)>=0.0) { + return 1; + } + } + } + } else { + if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0)) { + if (! (SIDE_OF_LINE(v3,v4,pt)>=0.0)) { + if (! (SIDE_OF_LINE(v4,v1,pt)>=0.0)) { + return -1; + } + } + } + } + + return 0; +} + +/* moved from effect.c + test if the line starting at p1 ending at p2 intersects the triangle v0..v2 + return non zero if it does +*/ +int isect_line_tri_v3(float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv) +{ + + float p[3], s[3], d[3], e1[3], e2[3], q[3]; + float a, f, u, v; + + sub_v3_v3v3(e1, v1, v0); + sub_v3_v3v3(e2, v2, v0); + sub_v3_v3v3(d, p2, p1); + + cross_v3_v3v3(p, d, e2); + a = dot_v3v3(e1, p); + if ((a > -0.000001) && (a < 0.000001)) return 0; + f = 1.0f/a; + + sub_v3_v3v3(s, p1, v0); + + cross_v3_v3v3(q, s, e1); + *lambda = f * dot_v3v3(e2, q); + if ((*lambda < 0.0)||(*lambda > 1.0)) return 0; + + u = f * dot_v3v3(s, p); + if ((u < 0.0)||(u > 1.0)) return 0; + + v = f * dot_v3v3(d, q); + if ((v < 0.0)||((u + v) > 1.0)) return 0; + + if(uv) { + uv[0]= u; + uv[1]= v; + } + + return 1; +} + +/* moved from effect.c + test if the ray starting at p1 going in d direction intersects the triangle v0..v2 + return non zero if it does +*/ +int isect_ray_tri_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv) +{ + float p[3], s[3], e1[3], e2[3], q[3]; + float a, f, u, v; + + sub_v3_v3v3(e1, v1, v0); + sub_v3_v3v3(e2, v2, v0); + + cross_v3_v3v3(p, d, e2); + a = dot_v3v3(e1, p); + /* note: these values were 0.000001 in 2.4x but for projection snapping on + * a human head (1BU==1m), subsurf level 2, this gave many errors - campbell */ + if ((a > -0.00000001) && (a < 0.00000001)) return 0; + f = 1.0f/a; + + sub_v3_v3v3(s, p1, v0); + + cross_v3_v3v3(q, s, e1); + *lambda = f * dot_v3v3(e2, q); + if ((*lambda < 0.0)) return 0; + + u = f * dot_v3v3(s, p); + if ((u < 0.0)||(u > 1.0)) return 0; + + v = f * dot_v3v3(d, q); + if ((v < 0.0)||((u + v) > 1.0)) return 0; + + if(uv) { + uv[0]= u; + uv[1]= v; + } + + return 1; +} + +int isect_ray_tri_threshold_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold) +{ + float p[3], s[3], e1[3], e2[3], q[3]; + float a, f, u, v; + float du = 0, dv = 0; + + sub_v3_v3v3(e1, v1, v0); + sub_v3_v3v3(e2, v2, v0); + + cross_v3_v3v3(p, d, e2); + a = dot_v3v3(e1, p); + if ((a > -0.000001) && (a < 0.000001)) return 0; + f = 1.0f/a; + + sub_v3_v3v3(s, p1, v0); + + cross_v3_v3v3(q, s, e1); + *lambda = f * dot_v3v3(e2, q); + if ((*lambda < 0.0)) return 0; + + u = f * dot_v3v3(s, p); + v = f * dot_v3v3(d, q); + + if (u < 0) du = u; + if (u > 1) du = u - 1; + if (v < 0) dv = v; + if (v > 1) dv = v - 1; + if (u > 0 && v > 0 && u + v > 1) + { + float t = u + v - 1; + du = u - t/2; + dv = v - t/2; + } + + mul_v3_fl(e1, du); + mul_v3_fl(e2, dv); + + if (dot_v3v3(e1, e1) + dot_v3v3(e2, e2) > threshold * threshold) + { + return 0; + } + + if(uv) { + uv[0]= u; + uv[1]= v; + } + + return 1; +} + + +/* Adapted from the paper by Kasper Fauerby */ +/* "Improved Collision detection and Response" */ +static int getLowestRoot(float a, float b, float c, float maxR, float* root) +{ + // Check if a solution exists + float determinant = b*b - 4.0f*a*c; + + // If determinant is negative it means no solutions. + if (determinant >= 0.0f) + { + // calculate the two roots: (if determinant == 0 then + // x1==x2 but let’s disregard that slight optimization) + float sqrtD = (float)sqrt(determinant); + float r1 = (-b - sqrtD) / (2.0f*a); + float r2 = (-b + sqrtD) / (2.0f*a); + + // Sort so x1 <= x2 + if (r1 > r2) + SWAP(float, r1, r2); + + // Get lowest root: + if (r1 > 0.0f && r1 < maxR) + { + *root = r1; + return 1; + } + + // It is possible that we want x2 - this can happen + // if x1 < 0 + if (r2 > 0.0f && r2 < maxR) + { + *root = r2; + return 1; + } + } + // No (valid) solutions + return 0; +} + +int isect_sweeping_sphere_tri_v3(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint) +{ + float e1[3], e2[3], e3[3], point[3], vel[3], /*dist[3],*/ nor[3], temp[3], bv[3]; + float a, b, c, d, e, x, y, z, radius2=radius*radius; + float elen2,edotv,edotbv,nordotv,vel2; + float newLambda; + int found_by_sweep=0; + + sub_v3_v3v3(e1,v1,v0); + sub_v3_v3v3(e2,v2,v0); + sub_v3_v3v3(vel,p2,p1); + +/*---test plane of tri---*/ + cross_v3_v3v3(nor,e1,e2); + normalize_v3(nor); + + /* flip normal */ + if(dot_v3v3(nor,vel)>0.0f) negate_v3(nor); + + a=dot_v3v3(p1,nor)-dot_v3v3(v0,nor); + nordotv=dot_v3v3(nor,vel); + + if (fabs(nordotv) < 0.000001) + { + if(fabs(a)>=radius) + { + return 0; + } + } + else + { + float t0=(-a+radius)/nordotv; + float t1=(-a-radius)/nordotv; + + if(t0>t1) + SWAP(float, t0, t1); + + if(t0>1.0f || t1<0.0f) return 0; + + /* clamp to [0,1] */ + CLAMP(t0, 0.0f, 1.0f); + CLAMP(t1, 0.0f, 1.0f); + + /*---test inside of tri---*/ + /* plane intersection point */ + + point[0] = p1[0] + vel[0]*t0 - nor[0]*radius; + point[1] = p1[1] + vel[1]*t0 - nor[1]*radius; + point[2] = p1[2] + vel[2]*t0 - nor[2]*radius; + + + /* is the point in the tri? */ + a=dot_v3v3(e1,e1); + b=dot_v3v3(e1,e2); + c=dot_v3v3(e2,e2); + + sub_v3_v3v3(temp,point,v0); + d=dot_v3v3(temp,e1); + e=dot_v3v3(temp,e2); + + x=d*c-e*b; + y=e*a-d*b; + z=x+y-(a*c-b*b); + + + if(z <= 0.0f && (x >= 0.0f && y >= 0.0f)) + { + //(((unsigned int)z)& ~(((unsigned int)x)|((unsigned int)y))) & 0x80000000){ + *lambda=t0; + copy_v3_v3(ipoint,point); + return 1; + } + } + + + *lambda=1.0f; + +/*---test points---*/ + a=vel2=dot_v3v3(vel,vel); + + /*v0*/ + sub_v3_v3v3(temp,p1,v0); + b=2.0f*dot_v3v3(vel,temp); + c=dot_v3v3(temp,temp)-radius2; + + if(getLowestRoot(a, b, c, *lambda, lambda)) + { + copy_v3_v3(ipoint,v0); + found_by_sweep=1; + } + + /*v1*/ + sub_v3_v3v3(temp,p1,v1); + b=2.0f*dot_v3v3(vel,temp); + c=dot_v3v3(temp,temp)-radius2; + + if(getLowestRoot(a, b, c, *lambda, lambda)) + { + copy_v3_v3(ipoint,v1); + found_by_sweep=1; + } + + /*v2*/ + sub_v3_v3v3(temp,p1,v2); + b=2.0f*dot_v3v3(vel,temp); + c=dot_v3v3(temp,temp)-radius2; + + if(getLowestRoot(a, b, c, *lambda, lambda)) + { + copy_v3_v3(ipoint,v2); + found_by_sweep=1; + } + +/*---test edges---*/ + sub_v3_v3v3(e3,v2,v1); //wasnt yet calculated + + + /*e1*/ + sub_v3_v3v3(bv,v0,p1); + + elen2 = dot_v3v3(e1,e1); + edotv = dot_v3v3(e1,vel); + edotbv = dot_v3v3(e1,bv); + + a=elen2*(-dot_v3v3(vel,vel))+edotv*edotv; + b=2.0f*(elen2*dot_v3v3(vel,bv)-edotv*edotbv); + c=elen2*(radius2-dot_v3v3(bv,bv))+edotbv*edotbv; + + if(getLowestRoot(a, b, c, *lambda, &newLambda)) + { + e=(edotv*newLambda-edotbv)/elen2; + + if(e >= 0.0f && e <= 1.0f) + { + *lambda = newLambda; + copy_v3_v3(ipoint,e1); + mul_v3_fl(ipoint,e); + add_v3_v3v3(ipoint,ipoint,v0); + found_by_sweep=1; + } + } + + /*e2*/ + /*bv is same*/ + elen2 = dot_v3v3(e2,e2); + edotv = dot_v3v3(e2,vel); + edotbv = dot_v3v3(e2,bv); + + a=elen2*(-dot_v3v3(vel,vel))+edotv*edotv; + b=2.0f*(elen2*dot_v3v3(vel,bv)-edotv*edotbv); + c=elen2*(radius2-dot_v3v3(bv,bv))+edotbv*edotbv; + + if(getLowestRoot(a, b, c, *lambda, &newLambda)) + { + e=(edotv*newLambda-edotbv)/elen2; + + if(e >= 0.0f && e <= 1.0f) + { + *lambda = newLambda; + copy_v3_v3(ipoint,e2); + mul_v3_fl(ipoint,e); + add_v3_v3v3(ipoint,ipoint,v0); + found_by_sweep=1; + } + } + + /*e3*/ + sub_v3_v3v3(bv,v0,p1); + elen2 = dot_v3v3(e1,e1); + edotv = dot_v3v3(e1,vel); + edotbv = dot_v3v3(e1,bv); + + sub_v3_v3v3(bv,v1,p1); + elen2 = dot_v3v3(e3,e3); + edotv = dot_v3v3(e3,vel); + edotbv = dot_v3v3(e3,bv); + + a=elen2*(-dot_v3v3(vel,vel))+edotv*edotv; + b=2.0f*(elen2*dot_v3v3(vel,bv)-edotv*edotbv); + c=elen2*(radius2-dot_v3v3(bv,bv))+edotbv*edotbv; + + if(getLowestRoot(a, b, c, *lambda, &newLambda)) + { + e=(edotv*newLambda-edotbv)/elen2; + + if(e >= 0.0f && e <= 1.0f) + { + *lambda = newLambda; + copy_v3_v3(ipoint,e3); + mul_v3_fl(ipoint,e); + add_v3_v3v3(ipoint,ipoint,v1); + found_by_sweep=1; + } + } + + + return found_by_sweep; +} +int isect_axial_line_tri_v3(int axis, float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda) +{ + float p[3], e1[3], e2[3]; + float u, v, f; + int a0=axis, a1=(axis+1)%3, a2=(axis+2)%3; + + //return isect_line_tri_v3(p1,p2,v0,v1,v2,lambda); + + ///* first a simple bounding box test */ + //if(MIN3(v0[a1],v1[a1],v2[a1]) > p1[a1]) return 0; + //if(MIN3(v0[a2],v1[a2],v2[a2]) > p1[a2]) return 0; + //if(MAX3(v0[a1],v1[a1],v2[a1]) < p1[a1]) return 0; + //if(MAX3(v0[a2],v1[a2],v2[a2]) < p1[a2]) return 0; + + ///* then a full intersection test */ + + sub_v3_v3v3(e1,v1,v0); + sub_v3_v3v3(e2,v2,v0); + sub_v3_v3v3(p,v0,p1); + + f= (e2[a1]*e1[a2]-e2[a2]*e1[a1]); + if ((f > -0.000001) && (f < 0.000001)) return 0; + + v= (p[a2]*e1[a1]-p[a1]*e1[a2])/f; + if ((v < 0.0)||(v > 1.0)) return 0; + + f= e1[a1]; + if((f > -0.000001) && (f < 0.000001)){ + f= e1[a2]; + if((f > -0.000001) && (f < 0.000001)) return 0; + u= (-p[a2]-v*e2[a2])/f; + } + else + u= (-p[a1]-v*e2[a1])/f; + + if ((u < 0.0)||((u + v) > 1.0)) return 0; + + *lambda = (p[a0]+u*e1[a0]+v*e2[a0])/(p2[a0]-p1[a0]); + + if ((*lambda < 0.0)||(*lambda > 1.0)) return 0; + + return 1; +} + +/* Returns the number of point of interests + * 0 - lines are colinear + * 1 - lines are coplanar, i1 is set to intersection + * 2 - i1 and i2 are the nearest points on line 1 (v1, v2) and line 2 (v3, v4) respectively + * */ +int isect_line_line_v3(float v1[3], float v2[3], float v3[3], float v4[3], float i1[3], float i2[3]) +{ + float a[3], b[3], c[3], ab[3], cb[3], dir1[3], dir2[3]; + float d; + + sub_v3_v3v3(c, v3, v1); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v4, v3); + + copy_v3_v3(dir1, a); + normalize_v3(dir1); + copy_v3_v3(dir2, b); + normalize_v3(dir2); + d = dot_v3v3(dir1, dir2); + if (d == 1.0f || d == -1.0f) { + /* colinear */ + return 0; + } + + cross_v3_v3v3(ab, a, b); + d = dot_v3v3(c, ab); + + /* test if the two lines are coplanar */ + if (d > -0.000001f && d < 0.000001f) { + cross_v3_v3v3(cb, c, b); + + mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab)); + add_v3_v3v3(i1, v1, a); + copy_v3_v3(i2, i1); + + return 1; /* one intersection only */ + } + /* if not */ + else { + float n[3], t[3]; + float v3t[3], v4t[3]; + sub_v3_v3v3(t, v1, v3); + + /* offset between both plane where the lines lies */ + cross_v3_v3v3(n, a, b); + project_v3_v3v3(t, t, n); + + /* for the first line, offset the second line until it is coplanar */ + add_v3_v3v3(v3t, v3, t); + add_v3_v3v3(v4t, v4, t); + + sub_v3_v3v3(c, v3t, v1); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v4t, v3t); + + cross_v3_v3v3(ab, a, b); + cross_v3_v3v3(cb, c, b); + + mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab)); + add_v3_v3v3(i1, v1, a); + + /* for the second line, just substract the offset from the first intersection point */ + sub_v3_v3v3(i2, i1, t); + + return 2; /* two nearest points */ + } +} + +/* Intersection point strictly between the two lines + * 0 when no intersection is found + * */ +int isect_line_line_strict_v3(float v1[3], float v2[3], float v3[3], float v4[3], float vi[3], float *lambda) +{ + float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3]; + float d; + float d1; + + sub_v3_v3v3(c, v3, v1); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v4, v3); + + copy_v3_v3(dir1, a); + normalize_v3(dir1); + copy_v3_v3(dir2, b); + normalize_v3(dir2); + d = dot_v3v3(dir1, dir2); + if (d == 1.0f || d == -1.0f || d == 0) { + /* colinear or one vector is zero-length*/ + return 0; + } + + d1 = d; + + cross_v3_v3v3(ab, a, b); + d = dot_v3v3(c, ab); + + /* test if the two lines are coplanar */ + if (d > -0.000001f && d < 0.000001f) { + float f1, f2; + cross_v3_v3v3(cb, c, b); + cross_v3_v3v3(ca, c, a); + + f1 = dot_v3v3(cb, ab) / dot_v3v3(ab, ab); + f2 = dot_v3v3(ca, ab) / dot_v3v3(ab, ab); + + if (f1 >= 0 && f1 <= 1 && + f2 >= 0 && f2 <= 1) + { + mul_v3_fl(a, f1); + add_v3_v3v3(vi, v1, a); + + if (lambda != NULL) + { + *lambda = f1; + } + + return 1; /* intersection found */ + } + else + { + return 0; + } + } + else + { + return 0; + } +} + +int isect_aabb_aabb_v3(float min1[3], float max1[3], float min2[3], float max2[3]) +{ + return (min1[0]<max2[0] && min1[1]<max2[1] && min1[2]<max2[2] && + min2[0]<max1[0] && min2[1]<max1[1] && min2[2]<max1[2]); +} + +/* find closest point to p on line through l1,l2 and return lambda, + * where (0 <= lambda <= 1) when cp is in the line segement l1,l2 + */ +float closest_to_line_v3(float cp[3],float p[3], float l1[3], float l2[3]) +{ + float h[3],u[3],lambda; + sub_v3_v3v3(u, l2, l1); + sub_v3_v3v3(h, p, l1); + lambda =dot_v3v3(u,h)/dot_v3v3(u,u); + cp[0] = l1[0] + u[0] * lambda; + cp[1] = l1[1] + u[1] * lambda; + cp[2] = l1[2] + u[2] * lambda; + return lambda; +} + +#if 0 +/* little sister we only need to know lambda */ +static float lambda_cp_line(float p[3], float l1[3], float l2[3]) +{ + float h[3],u[3]; + sub_v3_v3v3(u, l2, l1); + sub_v3_v3v3(h, p, l1); + return(dot_v3v3(u,h)/dot_v3v3(u,u)); +} +#endif + +/* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */ +void isect_point_quad_uv_v2(float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv) +{ + float x0,y0, x1,y1, wtot, v2d[2], w1, w2; + + /* used for paralelle lines */ + float pt3d[3], l1[3], l2[3], pt_on_line[3]; + + /* compute 2 edges of the quad intersection point */ + if (IsectLLPt2Df(v0[0],v0[1],v1[0],v1[1], v2[0],v2[1],v3[0],v3[1], &x0,&y0) == 1) { + /* the intersection point between the quad-edge intersection and the point in the quad we want the uv's for */ + /* should never be paralle !! */ + /*printf("\tnot paralelle 1\n");*/ + IsectLLPt2Df(pt[0],pt[1],x0,y0, v0[0],v0[1],v3[0],v3[1], &x1,&y1); + + /* Get the weights from the new intersection point, to each edge */ + v2d[0] = x1-v0[0]; + v2d[1] = y1-v0[1]; + w1 = len_v2(v2d); + + v2d[0] = x1-v3[0]; /* some but for the other vert */ + v2d[1] = y1-v3[1]; + w2 = len_v2(v2d); + wtot = w1+w2; + /*w1 = w1/wtot;*/ + /*w2 = w2/wtot;*/ + uv[0] = w1/wtot; + } else { + /* lines are paralelle, lambda_cp_line_ex is 3d grrr */ + /*printf("\tparalelle1\n");*/ + pt3d[0] = pt[0]; + pt3d[1] = pt[1]; + pt3d[2] = l1[2] = l2[2] = 0.0f; + + l1[0] = v0[0]; l1[1] = v0[1]; + l2[0] = v1[0]; l2[1] = v1[1]; + closest_to_line_v3(pt_on_line,pt3d, l1, l2); + v2d[0] = pt[0]-pt_on_line[0]; /* same, for the other vert */ + v2d[1] = pt[1]-pt_on_line[1]; + w1 = len_v2(v2d); + + l1[0] = v2[0]; l1[1] = v2[1]; + l2[0] = v3[0]; l2[1] = v3[1]; + closest_to_line_v3(pt_on_line,pt3d, l1, l2); + v2d[0] = pt[0]-pt_on_line[0]; /* same, for the other vert */ + v2d[1] = pt[1]-pt_on_line[1]; + w2 = len_v2(v2d); + wtot = w1+w2; + uv[0] = w1/wtot; + } + + /* Same as above to calc the uv[1] value, alternate calculation */ + + if (IsectLLPt2Df(v0[0],v0[1],v3[0],v3[1], v1[0],v1[1],v2[0],v2[1], &x0,&y0) == 1) { /* was v0,v1 v2,v3 now v0,v3 v1,v2*/ + /* never paralle if above was not */ + /*printf("\tnot paralelle2\n");*/ + IsectLLPt2Df(pt[0],pt[1],x0,y0, v0[0],v0[1],v1[0],v1[1], &x1,&y1);/* was v0,v3 now v0,v1*/ + + v2d[0] = x1-v0[0]; + v2d[1] = y1-v0[1]; + w1 = len_v2(v2d); + + v2d[0] = x1-v1[0]; + v2d[1] = y1-v1[1]; + w2 = len_v2(v2d); + wtot = w1+w2; + uv[1] = w1/wtot; + } else { + /* lines are paralelle, lambda_cp_line_ex is 3d grrr */ + /*printf("\tparalelle2\n");*/ + pt3d[0] = pt[0]; + pt3d[1] = pt[1]; + pt3d[2] = l1[2] = l2[2] = 0.0f; + + + l1[0] = v0[0]; l1[1] = v0[1]; + l2[0] = v3[0]; l2[1] = v3[1]; + closest_to_line_v3(pt_on_line,pt3d, l1, l2); + v2d[0] = pt[0]-pt_on_line[0]; /* some but for the other vert */ + v2d[1] = pt[1]-pt_on_line[1]; + w1 = len_v2(v2d); + + l1[0] = v1[0]; l1[1] = v1[1]; + l2[0] = v2[0]; l2[1] = v2[1]; + closest_to_line_v3(pt_on_line,pt3d, l1, l2); + v2d[0] = pt[0]-pt_on_line[0]; /* some but for the other vert */ + v2d[1] = pt[1]-pt_on_line[1]; + w2 = len_v2(v2d); + wtot = w1+w2; + uv[1] = w1/wtot; + } + /* may need to flip UV's here */ +} + +/* same as above but does tri's and quads, tri's are a bit of a hack */ +void isect_point_face_uv_v2(int isquad, float v0[2], float v1[2], float v2[2], float v3[2], float pt[2], float *uv) +{ + if (isquad) { + isect_point_quad_uv_v2(v0, v1, v2, v3, pt, uv); + } + else { + /* not for quads, use for our abuse of LineIntersectsTriangleUV */ + float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3], lambda; + + p1_3d[0] = p2_3d[0] = uv[0]; + p1_3d[1] = p2_3d[1] = uv[1]; + p1_3d[2] = 1.0f; + p2_3d[2] = -1.0f; + v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0; + + /* generate a new fuv, (this is possibly a non optimal solution, + * since we only need 2d calculation but use 3d func's) + * + * this method makes an imaginary triangle in 2d space using the UV's from the derived mesh face + * Then find new uv coords using the fuv and this face with LineIntersectsTriangleUV. + * This means the new values will be correct in relation to the derived meshes face. + */ + copy_v2_v2(v0_3d, v0); + copy_v2_v2(v1_3d, v1); + copy_v2_v2(v2_3d, v2); + + /* Doing this in 3D is not nice */ + isect_line_tri_v3(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv); + } +} + +#if 0 // XXX this version used to be used in isect_point_tri_v2_int() and was called IsPointInTri2D +int isect_point_tri_v2(float pt[2], float v1[2], float v2[2], float v3[2]) +{ + float inp1, inp2, inp3; + + inp1= (v2[0]-v1[0])*(v1[1]-pt[1]) + (v1[1]-v2[1])*(v1[0]-pt[0]); + inp2= (v3[0]-v2[0])*(v2[1]-pt[1]) + (v2[1]-v3[1])*(v2[0]-pt[0]); + inp3= (v1[0]-v3[0])*(v3[1]-pt[1]) + (v3[1]-v1[1])*(v3[0]-pt[0]); + + if(inp1<=0.0f && inp2<=0.0f && inp3<=0.0f) return 1; + if(inp1>=0.0f && inp2>=0.0f && inp3>=0.0f) return 1; + + return 0; +} +#endif + +#if 0 +int isect_point_tri_v2(float v0[2], float v1[2], float v2[2], float pt[2]) +{ + /* not for quads, use for our abuse of LineIntersectsTriangleUV */ + float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3]; + /* not used */ + float lambda, uv[3]; + + p1_3d[0] = p2_3d[0] = uv[0]= pt[0]; + p1_3d[1] = p2_3d[1] = uv[1]= uv[2]= pt[1]; + p1_3d[2] = 1.0f; + p2_3d[2] = -1.0f; + v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0; + + /* generate a new fuv, (this is possibly a non optimal solution, + * since we only need 2d calculation but use 3d func's) + * + * this method makes an imaginary triangle in 2d space using the UV's from the derived mesh face + * Then find new uv coords using the fuv and this face with LineIntersectsTriangleUV. + * This means the new values will be correct in relation to the derived meshes face. + */ + copy_v2_v2(v0_3d, v0); + copy_v2_v2(v1_3d, v1); + copy_v2_v2(v2_3d, v2); + + /* Doing this in 3D is not nice */ + return isect_line_tri_v3(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv); +} +#endif + +/* + + x1,y2 + | \ + | \ .(a,b) + | \ + x1,y1-- x2,y1 + +*/ +int isect_point_tri_v2_int(int x1, int y1, int x2, int y2, int a, int b) +{ + float v1[2], v2[2], v3[2], p[2]; + + v1[0]= (float)x1; + v1[1]= (float)y1; + + v2[0]= (float)x1; + v2[1]= (float)y2; + + v3[0]= (float)x2; + v3[1]= (float)y1; + + p[0]= (float)a; + p[1]= (float)b; + + return isect_point_tri_v2(p, v1, v2, v3); +} + +static int point_in_slice(float p[3], float v1[3], float l1[3], float l2[3]) +{ +/* +what is a slice ? +some maths: +a line including l1,l2 and a point not on the line +define a subset of R3 delimeted by planes parallel to the line and orthogonal +to the (point --> line) distance vector,one plane on the line one on the point, +the room inside usually is rather small compared to R3 though still infinte +useful for restricting (speeding up) searches +e.g. all points of triangular prism are within the intersection of 3 'slices' +onother trivial case : cube +but see a 'spat' which is a deformed cube with paired parallel planes needs only 3 slices too +*/ + float h,rp[3],cp[3],q[3]; + + closest_to_line_v3(cp,v1,l1,l2); + sub_v3_v3v3(q,cp,v1); + + sub_v3_v3v3(rp,p,v1); + h=dot_v3v3(q,rp)/dot_v3v3(q,q); + if (h < 0.0f || h > 1.0f) return 0; + return 1; +} + +#if 0 +/*adult sister defining the slice planes by the origin and the normal +NOTE |normal| may not be 1 but defining the thickness of the slice*/ +static int point_in_slice_as(float p[3],float origin[3],float normal[3]) +{ + float h,rp[3]; + sub_v3_v3v3(rp,p,origin); + h=dot_v3v3(normal,rp)/dot_v3v3(normal,normal); + if (h < 0.0f || h > 1.0f) return 0; + return 1; +} + +/*mama (knowing the squared lenght of the normal)*/ +static int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns) +{ + float h,rp[3]; + sub_v3_v3v3(rp,p,origin); + h=dot_v3v3(normal,rp)/lns; + if (h < 0.0f || h > 1.0f) return 0; + return 1; +} +#endif + +int isect_point_tri_prism_v3(float p[3], float v1[3], float v2[3], float v3[3]) +{ + if(!point_in_slice(p,v1,v2,v3)) return 0; + if(!point_in_slice(p,v2,v3,v1)) return 0; + if(!point_in_slice(p,v3,v1,v2)) return 0; + return 1; +} + +/****************************** Interpolation ********************************/ + +static float tri_signed_area(float *v1, float *v2, float *v3, int i, int j) +{ + return 0.5f*((v1[i]-v2[i])*(v2[j]-v3[j]) + (v1[j]-v2[j])*(v3[i]-v2[i])); +} + +static int barycentric_weights(float *v1, float *v2, float *v3, float *co, float *n, float *w) +{ + float xn, yn, zn, a1, a2, a3, asum; + short i, j; + + /* find best projection of face XY, XZ or YZ: barycentric weights of + the 2d projected coords are the same and faster to compute */ + xn= (float)fabs(n[0]); + yn= (float)fabs(n[1]); + zn= (float)fabs(n[2]); + if(zn>=xn && zn>=yn) {i= 0; j= 1;} + else if(yn>=xn && yn>=zn) {i= 0; j= 2;} + else {i= 1; j= 2;} + + a1= tri_signed_area(v2, v3, co, i, j); + a2= tri_signed_area(v3, v1, co, i, j); + a3= tri_signed_area(v1, v2, co, i, j); + + asum= a1 + a2 + a3; + + if (fabs(asum) < FLT_EPSILON) { + /* zero area triangle */ + w[0]= w[1]= w[2]= 1.0f/3.0f; + return 1; + } + + asum= 1.0f/asum; + w[0]= a1*asum; + w[1]= a2*asum; + w[2]= a3*asum; + + return 0; +} + +void interp_weights_face_v3(float *w,float *v1, float *v2, float *v3, float *v4, float *co) +{ + float w2[3]; + + w[0]= w[1]= w[2]= w[3]= 0.0f; + + /* first check for exact match */ + if(equals_v3v3(co, v1)) + w[0]= 1.0f; + else if(equals_v3v3(co, v2)) + w[1]= 1.0f; + else if(equals_v3v3(co, v3)) + w[2]= 1.0f; + else if(v4 && equals_v3v3(co, v4)) + w[3]= 1.0f; + else { + /* otherwise compute barycentric interpolation weights */ + float n1[3], n2[3], n[3]; + int degenerate; + + sub_v3_v3v3(n1, v1, v3); + if (v4) { + sub_v3_v3v3(n2, v2, v4); + } + else { + sub_v3_v3v3(n2, v2, v3); + } + cross_v3_v3v3(n, n1, n2); + + /* OpenGL seems to split this way, so we do too */ + if (v4) { + degenerate= barycentric_weights(v1, v2, v4, co, n, w); + SWAP(float, w[2], w[3]); + + if(degenerate || (w[0] < 0.0f)) { + /* if w[1] is negative, co is on the other side of the v1-v3 edge, + so we interpolate using the other triangle */ + degenerate= barycentric_weights(v2, v3, v4, co, n, w2); + + if(!degenerate) { + w[0]= 0.0f; + w[1]= w2[0]; + w[2]= w2[1]; + w[3]= w2[2]; + } + } + } + else + barycentric_weights(v1, v2, v3, co, n, w); + } +} + +/* Mean value weights - smooth interpolation weights for polygons with + * more than 3 vertices */ +static float mean_value_half_tan(float *v1, float *v2, float *v3) +{ + float d2[3], d3[3], cross[3], area, dot, len; + + sub_v3_v3v3(d2, v2, v1); + sub_v3_v3v3(d3, v3, v1); + cross_v3_v3v3(cross, d2, d3); + + area= len_v3(cross); + dot= dot_v3v3(d2, d3); + len= len_v3(d2)*len_v3(d3); + + if(area == 0.0f) + return 0.0f; + else + return (len - dot)/area; +} + +void interp_weights_poly_v3(float *w,float v[][3], int n, float *co) +{ + float totweight, t1, t2, len, *vmid, *vprev, *vnext; + int i; + + totweight= 0.0f; + + for(i=0; i<n; i++) { + vmid= v[i]; + vprev= (i == 0)? v[n-1]: v[i-1]; + vnext= (i == n-1)? v[0]: v[i+1]; + + t1= mean_value_half_tan(co, vprev, vmid); + t2= mean_value_half_tan(co, vmid, vnext); + + len= len_v3v3(co, vmid); + w[i]= (t1+t2)/len; + totweight += w[i]; + } + + if(totweight != 0.0f) + for(i=0; i<n; i++) + w[i] /= totweight; +} + +/* (x1,v1)(t1=0)------(x2,v2)(t2=1), 0<t<1 --> (x,v)(t) */ +void interp_cubic_v3(float *x, float *v,float *x1, float *v1, float *x2, float *v2, float t) +{ + float a[3],b[3]; + float t2= t*t; + float t3= t2*t; + + /* cubic interpolation */ + a[0]= v1[0] + v2[0] + 2*(x1[0] - x2[0]); + a[1]= v1[1] + v2[1] + 2*(x1[1] - x2[1]); + a[2]= v1[2] + v2[2] + 2*(x1[2] - x2[2]); + + b[0]= -2*v1[0] - v2[0] - 3*(x1[0] - x2[0]); + b[1]= -2*v1[1] - v2[1] - 3*(x1[1] - x2[1]); + b[2]= -2*v1[2] - v2[2] - 3*(x1[2] - x2[2]); + + x[0]= a[0]*t3 + b[0]*t2 + v1[0]*t + x1[0]; + x[1]= a[1]*t3 + b[1]*t2 + v1[1]*t + x1[1]; + x[2]= a[2]*t3 + b[2]*t2 + v1[2]*t + x1[2]; + + v[0]= 3*a[0]*t2 + 2*b[0]*t + v1[0]; + v[1]= 3*a[1]*t2 + 2*b[1]*t + v1[1]; + v[2]= 3*a[2]*t2 + 2*b[2]*t + v1[2]; +} + +/***************************** View & Projection *****************************/ + +void orthographic_m4(float matrix[][4],float left, float right, float bottom, float top, float nearClip, float farClip) +{ + float Xdelta, Ydelta, Zdelta; + + Xdelta = right - left; + Ydelta = top - bottom; + Zdelta = farClip - nearClip; + if (Xdelta == 0.0 || Ydelta == 0.0 || Zdelta == 0.0) { + return; + } + unit_m4(matrix); + matrix[0][0] = 2.0f/Xdelta; + matrix[3][0] = -(right + left)/Xdelta; + matrix[1][1] = 2.0f/Ydelta; + matrix[3][1] = -(top + bottom)/Ydelta; + matrix[2][2] = -2.0f/Zdelta; /* note: negate Z */ + matrix[3][2] = -(farClip + nearClip)/Zdelta; +} + +void perspective_m4(float mat[][4],float left, float right, float bottom, float top, float nearClip, float farClip) +{ + float Xdelta, Ydelta, Zdelta; + + Xdelta = right - left; + Ydelta = top - bottom; + Zdelta = farClip - nearClip; + + if (Xdelta == 0.0 || Ydelta == 0.0 || Zdelta == 0.0) { + return; + } + mat[0][0] = nearClip * 2.0f/Xdelta; + mat[1][1] = nearClip * 2.0f/Ydelta; + mat[2][0] = (right + left)/Xdelta; /* note: negate Z */ + mat[2][1] = (top + bottom)/Ydelta; + mat[2][2] = -(farClip + nearClip)/Zdelta; + mat[2][3] = -1.0f; + mat[3][2] = (-2.0f * nearClip * farClip)/Zdelta; + mat[0][1] = mat[0][2] = mat[0][3] = + mat[1][0] = mat[1][2] = mat[1][3] = + mat[3][0] = mat[3][1] = mat[3][3] = 0.0; + +} + +static void i_multmatrix(float icand[][4], float Vm[][4]) +{ + int row, col; + float temp[4][4]; + + for(row=0 ; row<4 ; row++) + for(col=0 ; col<4 ; col++) + temp[row][col] = icand[row][0] * Vm[0][col] + + icand[row][1] * Vm[1][col] + + icand[row][2] * Vm[2][col] + + icand[row][3] * Vm[3][col]; + copy_m4_m4(Vm, temp); +} + + +void polarview_m4(float Vm[][4],float dist, float azimuth, float incidence, float twist) +{ + + unit_m4(Vm); + + translate_m4(Vm,0.0, 0.0, -dist); + rotate_m4(Vm,'z',-twist); + rotate_m4(Vm,'x',-incidence); + rotate_m4(Vm,'z',-azimuth); +} + +void lookat_m4(float mat[][4],float vx, float vy, float vz, float px, float py, float pz, float twist) +{ + float sine, cosine, hyp, hyp1, dx, dy, dz; + float mat1[4][4]; + + unit_m4(mat); + unit_m4(mat1); + + rotate_m4(mat,'z',-twist); + + dx = px - vx; + dy = py - vy; + dz = pz - vz; + hyp = dx * dx + dz * dz; /* hyp squared */ + hyp1 = (float)sqrt(dy*dy + hyp); + hyp = (float)sqrt(hyp); /* the real hyp */ + + if (hyp1 != 0.0) { /* rotate X */ + sine = -dy / hyp1; + cosine = hyp /hyp1; + } else { + sine = 0; + cosine = 1.0f; + } + mat1[1][1] = cosine; + mat1[1][2] = sine; + mat1[2][1] = -sine; + mat1[2][2] = cosine; + + i_multmatrix(mat1, mat); + + mat1[1][1] = mat1[2][2] = 1.0f; /* be careful here to reinit */ + mat1[1][2] = mat1[2][1] = 0.0; /* those modified by the last */ + + /* paragraph */ + if (hyp != 0.0f) { /* rotate Y */ + sine = dx / hyp; + cosine = -dz / hyp; + } else { + sine = 0; + cosine = 1.0f; + } + mat1[0][0] = cosine; + mat1[0][2] = -sine; + mat1[2][0] = sine; + mat1[2][2] = cosine; + + i_multmatrix(mat1, mat); + translate_m4(mat,-vx,-vy,-vz); /* translate viewpoint to origin */ +} + +/********************************** Mapping **********************************/ + +void map_to_tube(float *u, float *v,float x, float y, float z) +{ + float len; + + *v = (z + 1.0f) / 2.0f; + + len= (float)sqrt(x*x+y*y); + if(len > 0.0f) + *u = (float)((1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0); + else + *v = *u = 0.0f; /* to avoid un-initialized variables */ +} + +void map_to_sphere(float *u, float *v,float x, float y, float z) +{ + float len; + + len= (float)sqrt(x*x+y*y+z*z); + if(len > 0.0f) { + if(x==0.0f && y==0.0f) *u= 0.0f; /* othwise domain error */ + else *u = (float)((1.0 - (float)atan2(x,y) / M_PI) / 2.0); + + z/=len; + *v = 1.0f - (float)saacos(z)/(float)M_PI; + } else { + *v = *u = 0.0f; /* to avoid un-initialized variables */ + } +} + +/********************************************************/ + +/* Tangents */ + +/* For normal map tangents we need to detect uv boundaries, and only average + * tangents in case the uvs are connected. Alternative would be to store 1 + * tangent per face rather than 4 per face vertex, but that's not compatible + * with games */ + + +/* from BKE_mesh.h */ +#define STD_UV_CONNECT_LIMIT 0.0001f + +void sum_or_add_vertex_tangent(void *arena, VertexTangent **vtang, float *tang, float *uv) +{ + VertexTangent *vt; + + /* find a tangent with connected uvs */ + for(vt= *vtang; vt; vt=vt->next) { + if(fabs(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabs(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) { + add_v3_v3v3(vt->tang, vt->tang, tang); + return; + } + } + + /* if not found, append a new one */ + vt= BLI_memarena_alloc((MemArena *)arena, sizeof(VertexTangent)); + copy_v3_v3(vt->tang, tang); + vt->uv[0]= uv[0]; + vt->uv[1]= uv[1]; + + if(*vtang) + vt->next= *vtang; + *vtang= vt; +} + +float *find_vertex_tangent(VertexTangent *vtang, float *uv) +{ + VertexTangent *vt; + static float nulltang[3] = {0.0f, 0.0f, 0.0f}; + + for(vt= vtang; vt; vt=vt->next) + if(fabs(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabs(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) + return vt->tang; + + return nulltang; /* shouldn't happen, except for nan or so */ +} + +void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2, float *co3, float *n, float *tang) +{ + float tangv[3], ct[3], e1[3], e2[3], s1, t1, s2, t2, det; + + s1= uv2[0] - uv1[0]; + s2= uv3[0] - uv1[0]; + t1= uv2[1] - uv1[1]; + t2= uv3[1] - uv1[1]; + det= 1.0f / (s1 * t2 - s2 * t1); + + /* normals in render are inversed... */ + sub_v3_v3v3(e1, co1, co2); + sub_v3_v3v3(e2, co1, co3); + tang[0] = (t2*e1[0] - t1*e2[0])*det; + tang[1] = (t2*e1[1] - t1*e2[1])*det; + tang[2] = (t2*e1[2] - t1*e2[2])*det; + tangv[0] = (s1*e2[0] - s2*e1[0])*det; + tangv[1] = (s1*e2[1] - s2*e1[1])*det; + tangv[2] = (s1*e2[2] - s2*e1[2])*det; + cross_v3_v3v3(ct, tang, tangv); + + /* check flip */ + if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f) + negate_v3(tang); +} + diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c new file mode 100644 index 00000000000..edab1cc2440 --- /dev/null +++ b/source/blender/blenlib/intern/math_matrix.c @@ -0,0 +1,1127 @@ +/* + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "BLI_math.h" + +/********************************* Init **************************************/ + +void zero_m3(float m[3][3]) +{ + memset(m, 0, 3*3*sizeof(float)); +} + +void zero_m4(float m[4][4]) +{ + memset(m, 0, 4*4*sizeof(float)); +} + +void unit_m3(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 unit_m4(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; +} + +void copy_m3_m3(float m1[][3], float m2[][3]) +{ + /* destination comes first: */ + memcpy(&m1[0], &m2[0], 9*sizeof(float)); +} + +void copy_m4_m4(float m1[][4], float m2[][4]) +{ + memcpy(m1, m2, 4*4*sizeof(float)); +} + +void copy_m3_m4(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 copy_m4_m3(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]; + + /* Reevan's Bugfix */ + m1[0][3]=0.0F; + m1[1][3]=0.0F; + m1[2][3]=0.0F; + + m1[3][0]=0.0F; + m1[3][1]=0.0F; + m1[3][2]=0.0F; + m1[3][3]=1.0F; + +} + +void swap_m4m4(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; + } + } +} + +/******************************** Arithmetic *********************************/ + +void mul_m4_m4m4(float m1[][4], float m2[][4], float m3[][4]) +{ + /* matrix product: m1[j][k] = m2[j][i].m3[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 mul_m3_m3m3(float m1[][3], float m3[][3], float m2[][3]) +{ + /* 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]; +} + +void mul_m4_m4m3(float (*m1)[4], float (*m3)[4], float (*m2)[3]) +{ + 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 = m2 * m3, ignore the elements on the 4th row/column of m3*/ +void mul_m3_m3m4(float m1[][3], float m2[][3], float m3[][4]) +{ + /* 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]; +} + +void mul_m4_m3m4(float (*m1)[4], float (*m3)[3], float (*m2)[4]) +{ + 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]; +} + +void mul_serie_m3(float answ[][3], + float m1[][3], float m2[][3], float m3[][3], + float m4[][3], float m5[][3], float m6[][3], + float m7[][3], float m8[][3]) +{ + float temp[3][3]; + + if(m1==0 || m2==0) return; + + mul_m3_m3m3(answ, m2, m1); + if(m3) { + mul_m3_m3m3(temp, m3, answ); + if(m4) { + mul_m3_m3m3(answ, m4, temp); + if(m5) { + mul_m3_m3m3(temp, m5, answ); + if(m6) { + mul_m3_m3m3(answ, m6, temp); + if(m7) { + mul_m3_m3m3(temp, m7, answ); + if(m8) { + mul_m3_m3m3(answ, m8, temp); + } + else copy_m3_m3(answ, temp); + } + } + else copy_m3_m3(answ, temp); + } + } + else copy_m3_m3(answ, temp); + } +} + +void mul_serie_m4(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; + + mul_m4_m4m4(answ, m2, m1); + if(m3) { + mul_m4_m4m4(temp, m3, answ); + if(m4) { + mul_m4_m4m4(answ, m4, temp); + if(m5) { + mul_m4_m4m4(temp, m5, answ); + if(m6) { + mul_m4_m4m4(answ, m6, temp); + if(m7) { + mul_m4_m4m4(temp, m7, answ); + if(m8) { + mul_m4_m4m4(answ, m8, temp); + } + else copy_m4_m4(answ, temp); + } + } + else copy_m4_m4(answ, temp); + } + } + else copy_m4_m4(answ, temp); + } +} + +void mul_m4_v3(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 mul_v3_m4v3(float *in, float mat[][4], float *vec) +{ + float x,y; + + x=vec[0]; + y=vec[1]; + in[0]= x*mat[0][0] + y*mat[1][0] + mat[2][0]*vec[2] + mat[3][0]; + in[1]= x*mat[0][1] + y*mat[1][1] + mat[2][1]*vec[2] + mat[3][1]; + in[2]= x*mat[0][2] + y*mat[1][2] + mat[2][2]*vec[2] + mat[3][2]; +} + +void mul_mat3_m4_v3(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]; + 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 mul_project_m4_v4(float mat[][4], float *vec) +{ + float w; + + w = vec[0]*mat[0][3] + vec[1]*mat[1][3] + vec[2]*mat[2][3] + mat[3][3]; + mul_m4_v3(mat, vec); + + vec[0] /= w; + vec[1] /= w; + vec[2] /= w; +} + +void mul_m4_v4(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 mul_m3_v3(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]; +} + +void mul_transposed_m3_v3(float mat[][3], float *vec) +{ + float x,y; + + x=vec[0]; + y=vec[1]; + vec[0]= x*mat[0][0] + y*mat[0][1] + mat[0][2]*vec[2]; + vec[1]= x*mat[1][0] + y*mat[1][1] + mat[1][2]*vec[2]; + vec[2]= x*mat[2][0] + y*mat[2][1] + mat[2][2]*vec[2]; +} + +void mul_m3_fl(float m[3][3], float f) +{ + int i, j; + + for(i=0;i<3;i++) + for(j=0;j<3;j++) + m[i][j] *= f; +} + +void mul_m4_fl(float m[4][4], float f) +{ + int i, j; + + for(i=0;i<4;i++) + for(j=0;j<4;j++) + m[i][j] *= f; +} + +void mul_mat3_m4_fl(float m[4][4], float f) +{ + int i, j; + + for(i=0; i<3; i++) + for(j=0; j<3; j++) + m[i][j] *= f; +} + +void mul_m3_v3_double(float mat[][3], double *vec) +{ + double 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]; +} + +void add_m3_m3m3(float m1[][3], float m2[][3], float m3[][3]) +{ + int i, j; + + for(i=0;i<3;i++) + for(j=0;j<3;j++) + m1[i][j]= m2[i][j] + m3[i][j]; +} + +void add_m4_m4m4(float m1[][4], float m2[][4], float m3[][4]) +{ + int i, j; + + for(i=0;i<4;i++) + for(j=0;j<4;j++) + m1[i][j]= m2[i][j] + m3[i][j]; +} + +int invert_m3(float m[3][3]) +{ + float tmp[3][3]; + int success; + + success= invert_m3_m3(tmp, m); + copy_m3_m3(m, tmp); + + return success; +} + +int invert_m3_m3(float m1[3][3], float m2[3][3]) +{ + float det; + int a, b, success; + + /* calc adjoint */ + adjoint_m3_m3(m1,m2); + + /* then determinant old matrix! */ + 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]); + + success= (det != 0); + + if(det==0) det=1; + det= 1/det; + for(a=0;a<3;a++) { + for(b=0;b<3;b++) { + m1[a][b]*=det; + } + } + + return success; +} + +int invert_m4(float m[4][4]) +{ + float tmp[4][4]; + int success; + + success= invert_m4_m4(tmp, m); + copy_m4_m4(m, tmp); + + return success; +} + +/* + * invertmat - + * computes the inverse of mat and puts it in inverse. Returns + * TRUE on success (i.e. can always find a pivot) and FALSE on failure. + * Uses Gaussian Elimination with partial (maximal column) pivoting. + * + * Mark Segal - 1992 + */ + +int invert_m4_m4(float inverse[4][4], float mat[4][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 = fabs(tempmat[i][i]); + maxj = i; + for(j = i + 1; j < 4; j++) { + if(fabs(tempmat[j][i]) > max) { + max = fabs(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] = (float)(tempmat[i][k]/temp); + inverse[i][k] = (float)(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] -= (float)(tempmat[i][k]*temp); + inverse[j][k] -= (float)(inverse[i][k]*temp); + } + } + } + } + return 1; +} + +/****************************** Linear Algebra *******************************/ + +void transpose_m3(float mat[][3]) +{ + float t; + + t = mat[0][1] ; + mat[0][1] = mat[1][0] ; + mat[1][0] = t; + t = mat[0][2] ; + mat[0][2] = mat[2][0] ; + mat[2][0] = t; + t = mat[1][2] ; + mat[1][2] = mat[2][1] ; + mat[2][1] = t; +} + +void transpose_m4(float mat[][4]) +{ + float t; + + t = mat[0][1] ; + mat[0][1] = mat[1][0] ; + mat[1][0] = t; + t = mat[0][2] ; + mat[0][2] = mat[2][0] ; + mat[2][0] = t; + t = mat[0][3] ; + mat[0][3] = mat[3][0] ; + mat[3][0] = t; + + t = mat[1][2] ; + mat[1][2] = mat[2][1] ; + mat[2][1] = t; + t = mat[1][3] ; + mat[1][3] = mat[3][1] ; + mat[3][1] = t; + + t = mat[2][3] ; + mat[2][3] = mat[3][2] ; + mat[3][2] = t; +} + +void orthogonalize_m3(float mat[][3], int axis) +{ + float size[3]; + size[0] = len_v3(mat[0]); + size[1] = len_v3(mat[1]); + size[2] = len_v3(mat[2]); + normalize_v3(mat[axis]); + switch(axis) + { + case 0: + if (dot_v3v3(mat[0], mat[1]) < 1) { + cross_v3_v3v3(mat[2], mat[0], mat[1]); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } else if (dot_v3v3(mat[0], mat[2]) < 1) { + cross_v3_v3v3(mat[1], mat[2], mat[0]); + normalize_v3(mat[1]); + cross_v3_v3v3(mat[2], mat[0], mat[1]); + } else { + float vec[3] = {mat[0][1], mat[0][2], mat[0][0]}; + + cross_v3_v3v3(mat[2], mat[0], vec); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } + case 1: + if (dot_v3v3(mat[1], mat[0]) < 1) { + cross_v3_v3v3(mat[2], mat[0], mat[1]); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[0], mat[1], mat[2]); + } else if (dot_v3v3(mat[0], mat[2]) < 1) { + cross_v3_v3v3(mat[0], mat[1], mat[2]); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[2], mat[0], mat[1]); + } else { + float vec[3] = {mat[1][1], mat[1][2], mat[1][0]}; + + cross_v3_v3v3(mat[0], mat[1], vec); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[2], mat[0], mat[1]); + } + case 2: + if (dot_v3v3(mat[2], mat[0]) < 1) { + cross_v3_v3v3(mat[1], mat[2], mat[0]); + normalize_v3(mat[1]); + cross_v3_v3v3(mat[0], mat[1], mat[2]); + } else if (dot_v3v3(mat[2], mat[1]) < 1) { + cross_v3_v3v3(mat[0], mat[1], mat[2]); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } else { + float vec[3] = {mat[2][1], mat[2][2], mat[2][0]}; + + cross_v3_v3v3(mat[0], vec, mat[2]); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } + } + mul_v3_fl(mat[0], size[0]); + mul_v3_fl(mat[1], size[1]); + mul_v3_fl(mat[2], size[2]); +} + +void orthogonalize_m4(float mat[][4], int axis) +{ + float size[3]; + size[0] = len_v3(mat[0]); + size[1] = len_v3(mat[1]); + size[2] = len_v3(mat[2]); + normalize_v3(mat[axis]); + switch(axis) + { + case 0: + if (dot_v3v3(mat[0], mat[1]) < 1) { + cross_v3_v3v3(mat[2], mat[0], mat[1]); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } else if (dot_v3v3(mat[0], mat[2]) < 1) { + cross_v3_v3v3(mat[1], mat[2], mat[0]); + normalize_v3(mat[1]); + cross_v3_v3v3(mat[2], mat[0], mat[1]); + } else { + float vec[3] = {mat[0][1], mat[0][2], mat[0][0]}; + + cross_v3_v3v3(mat[2], mat[0], vec); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } + case 1: + normalize_v3(mat[0]); + if (dot_v3v3(mat[1], mat[0]) < 1) { + cross_v3_v3v3(mat[2], mat[0], mat[1]); + normalize_v3(mat[2]); + cross_v3_v3v3(mat[0], mat[1], mat[2]); + } else if (dot_v3v3(mat[0], mat[2]) < 1) { + cross_v3_v3v3(mat[0], mat[1], mat[2]); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[2], mat[0], mat[1]); + } else { + float vec[3] = {mat[1][1], mat[1][2], mat[1][0]}; + + cross_v3_v3v3(mat[0], mat[1], vec); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[2], mat[0], mat[1]); + } + case 2: + if (dot_v3v3(mat[2], mat[0]) < 1) { + cross_v3_v3v3(mat[1], mat[2], mat[0]); + normalize_v3(mat[1]); + cross_v3_v3v3(mat[0], mat[1], mat[2]); + } else if (dot_v3v3(mat[2], mat[1]) < 1) { + cross_v3_v3v3(mat[0], mat[1], mat[2]); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } else { + float vec[3] = {mat[2][1], mat[2][2], mat[2][0]}; + + cross_v3_v3v3(mat[0], vec, mat[2]); + normalize_v3(mat[0]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); + } + } + mul_v3_fl(mat[0], size[0]); + mul_v3_fl(mat[1], size[1]); + mul_v3_fl(mat[2], size[2]); +} + +int is_orthogonal_m3(float mat[][3]) +{ + if (fabs(dot_v3v3(mat[0], mat[1])) > 1.5 * FLT_EPSILON) + return 0; + + if (fabs(dot_v3v3(mat[1], mat[2])) > 1.5 * FLT_EPSILON) + return 0; + + if (fabs(dot_v3v3(mat[0], mat[2])) > 1.5 * FLT_EPSILON) + return 0; + + return 1; +} + +int is_orthogonal_m4(float mat[][4]) +{ + if (fabs(dot_v3v3(mat[0], mat[1])) > 1.5 * FLT_EPSILON) + return 0; + + if (fabs(dot_v3v3(mat[1], mat[2])) > 1.5 * FLT_EPSILON) + return 0; + + if (fabs(dot_v3v3(mat[0], mat[2])) > 1.5 * FLT_EPSILON) + return 0; + + return 1; +} + +void normalize_m3(float mat[][3]) +{ + normalize_v3(mat[0]); + normalize_v3(mat[1]); + normalize_v3(mat[2]); +} + +void normalize_m4(float mat[][4]) +{ + float len; + + len= normalize_v3(mat[0]); + if(len!=0.0) mat[0][3]/= len; + len= normalize_v3(mat[1]); + if(len!=0.0) mat[1][3]/= len; + len= normalize_v3(mat[2]); + if(len!=0.0) mat[2][3]/= len; +} + +void adjoint_m3_m3(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 adjoint_m4_m4(float out[][4], float in[][4]) /* out = ADJ(in) */ +{ + float a1, a2, a3, a4, b1, b2, b3, b4; + float c1, c2, c3, c4, d1, d2, d3, d4; + + a1= in[0][0]; + b1= in[0][1]; + c1= in[0][2]; + d1= in[0][3]; + + a2= in[1][0]; + b2= in[1][1]; + c2= in[1][2]; + d2= in[1][3]; + + a3= in[2][0]; + b3= in[2][1]; + c3= in[2][2]; + d3= in[2][3]; + + a4= in[3][0]; + b4= in[3][1]; + c4= in[3][2]; + d4= in[3][3]; + + + out[0][0] = determinant_m3(b2, b3, b4, c2, c3, c4, d2, d3, d4); + out[1][0] = - determinant_m3(a2, a3, a4, c2, c3, c4, d2, d3, d4); + out[2][0] = determinant_m3(a2, a3, a4, b2, b3, b4, d2, d3, d4); + out[3][0] = - determinant_m3(a2, a3, a4, b2, b3, b4, c2, c3, c4); + + out[0][1] = - determinant_m3(b1, b3, b4, c1, c3, c4, d1, d3, d4); + out[1][1] = determinant_m3(a1, a3, a4, c1, c3, c4, d1, d3, d4); + out[2][1] = - determinant_m3(a1, a3, a4, b1, b3, b4, d1, d3, d4); + out[3][1] = determinant_m3(a1, a3, a4, b1, b3, b4, c1, c3, c4); + + out[0][2] = determinant_m3(b1, b2, b4, c1, c2, c4, d1, d2, d4); + out[1][2] = - determinant_m3(a1, a2, a4, c1, c2, c4, d1, d2, d4); + out[2][2] = determinant_m3(a1, a2, a4, b1, b2, b4, d1, d2, d4); + out[3][2] = - determinant_m3(a1, a2, a4, b1, b2, b4, c1, c2, c4); + + out[0][3] = - determinant_m3(b1, b2, b3, c1, c2, c3, d1, d2, d3); + out[1][3] = determinant_m3(a1, a2, a3, c1, c2, c3, d1, d2, d3); + out[2][3] = - determinant_m3(a1, a2, a3, b1, b2, b3, d1, d2, d3); + out[3][3] = determinant_m3(a1, a2, a3, b1, b2, b3, c1, c2, c3); +} + +float determinant_m2(float a,float b,float c,float d) +{ + + return a*d - b*c; +} + +float determinant_m3(float a1, float a2, float a3, + float b1, float b2, float b3, + float c1, float c2, float c3) +{ + float ans; + + ans = a1 * determinant_m2(b2, b3, c2, c3) + - b1 * determinant_m2(a2, a3, c2, c3) + + c1 * determinant_m2(a2, a3, b2, b3); + + return ans; +} + +float determinant_m4(float m[][4]) +{ + float ans; + float a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4; + + a1= m[0][0]; + b1= m[0][1]; + c1= m[0][2]; + d1= m[0][3]; + + a2= m[1][0]; + b2= m[1][1]; + c2= m[1][2]; + d2= m[1][3]; + + a3= m[2][0]; + b3= m[2][1]; + c3= m[2][2]; + d3= m[2][3]; + + a4= m[3][0]; + b4= m[3][1]; + c4= m[3][2]; + d4= m[3][3]; + + ans = a1 * determinant_m3(b2, b3, b4, c2, c3, c4, d2, d3, d4) + - b1 * determinant_m3(a2, a3, a4, c2, c3, c4, d2, d3, d4) + + c1 * determinant_m3(a2, a3, a4, b2, b3, b4, d2, d3, d4) + - d1 * determinant_m3(a2, a3, a4, b2, b3, b4, c2, c3, c4); + + return ans; +} + +/****************************** Transformations ******************************/ + +void size_to_mat3(float mat[][3], float *size) +{ + mat[0][0]= size[0]; + mat[0][1]= 0.0f; + mat[0][2]= 0.0f; + mat[1][1]= size[1]; + mat[1][0]= 0.0f; + mat[1][2]= 0.0f; + mat[2][2]= size[2]; + mat[2][1]= 0.0f; + mat[2][0]= 0.0f; +} + +void size_to_mat4(float mat[][4], float *size) +{ + float tmat[3][3]; + + size_to_mat3(tmat,size); + unit_m4(mat); + copy_m4_m3(mat, tmat); +} + +void mat3_to_size(float *size, float mat[][3]) +{ + size[0]= len_v3(mat[0]); + size[1]= len_v3(mat[1]); + size[2]= len_v3(mat[2]); +} + +void mat4_to_size(float *size, float mat[][4]) +{ + size[0]= len_v3(mat[0]); + size[1]= len_v3(mat[1]); + size[2]= len_v3(mat[2]); +} + +/* this gets the average scale of a matrix, only use when your scaling + * data that has no idea of scale axis, examples are bone-envelope-radius + * and curve radius */ +float mat3_to_scale(float mat[][3]) +{ + /* unit length vector */ + float unit_vec[3] = {0.577350269189626f, 0.577350269189626f, 0.577350269189626f}; + mul_m3_v3(mat, unit_vec); + return len_v3(unit_vec); +} + +float mat4_to_scale(float mat[][4]) +{ + float tmat[3][3]; + copy_m3_m4(tmat, mat); + return mat3_to_scale(tmat); +} + +void scale_m3_fl(float m[][3], float scale) +{ + m[0][0]= m[1][1]= m[2][2]= scale; + 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 scale_m4_fl(float m[][4], float scale) +{ + m[0][0]= m[1][1]= m[2][2]= scale; + 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; +} + +void translate_m4(float mat[][4],float Tx, float Ty, float Tz) +{ + mat[3][0] += (Tx*mat[0][0] + Ty*mat[1][0] + Tz*mat[2][0]); + mat[3][1] += (Tx*mat[0][1] + Ty*mat[1][1] + Tz*mat[2][1]); + mat[3][2] += (Tx*mat[0][2] + Ty*mat[1][2] + Tz*mat[2][2]); +} + +void rotate_m4(float mat[][4], char axis,float angle) +{ + int col; + float temp[4]; + float cosine, sine; + + for(col=0; col<4 ; col++) /* init temp to zero matrix */ + temp[col] = 0; + + angle = (float)(angle*(3.1415926535/180.0)); + cosine = (float)cos(angle); + sine = (float)sin(angle); + switch(axis){ + case 'x': + case 'X': + for(col=0 ; col<4 ; col++) + temp[col] = cosine*mat[1][col] + sine*mat[2][col]; + for(col=0 ; col<4 ; col++) { + mat[2][col] = - sine*mat[1][col] + cosine*mat[2][col]; + mat[1][col] = temp[col]; + } + break; + + case 'y': + case 'Y': + for(col=0 ; col<4 ; col++) + temp[col] = cosine*mat[0][col] - sine*mat[2][col]; + for(col=0 ; col<4 ; col++) { + mat[2][col] = sine*mat[0][col] + cosine*mat[2][col]; + mat[0][col] = temp[col]; + } + break; + + case 'z': + case 'Z': + for(col=0 ; col<4 ; col++) + temp[col] = cosine*mat[0][col] + sine*mat[1][col]; + for(col=0 ; col<4 ; col++) { + mat[1][col] = - sine*mat[0][col] + cosine*mat[1][col]; + mat[0][col] = temp[col]; + } + break; + } +} + +void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], float srcweight) +{ + float squat[4], dquat[4], fquat[4]; + float ssize[3], dsize[3], fsize[4]; + float rmat[3][3], smat[3][3]; + + mat3_to_quat(dquat,dst); + mat3_to_size(dsize,dst); + + mat3_to_quat(squat,src); + mat3_to_size(ssize,src); + + /* do blending */ + interp_qt_qtqt(fquat, dquat, squat, srcweight); + interp_v3_v3v3(fsize, dsize, ssize, srcweight); + + /* compose new matrix */ + quat_to_mat3(rmat,fquat); + size_to_mat3(smat,fsize); + mul_m3_m3m3(out, rmat, smat); +} + +void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], float srcweight) +{ + float squat[4], dquat[4], fquat[4]; + float ssize[3], dsize[3], fsize[4]; + float sloc[3], dloc[3], floc[3]; + + mat4_to_quat(dquat,dst); + mat4_to_size(dsize,dst); + copy_v3_v3(dloc, dst[3]); + + mat4_to_quat(squat,src); + mat4_to_size(ssize,src); + copy_v3_v3(sloc, src[3]); + + /* do blending */ + interp_v3_v3v3(floc, dloc, sloc, srcweight); + interp_qt_qtqt(fquat, dquat, squat, srcweight); + interp_v3_v3v3(fsize, dsize, ssize, srcweight); + + /* compose new matrix */ + loc_quat_size_to_mat4(out, floc, fquat, fsize); +} + +/* make a 4x4 matrix out of 3 transform components */ +/* matrices are made in the order: scale * rot * loc */ +// TODO: need to have a version that allows for rotation order... +void loc_eul_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float size[3]) +{ + float rmat[3][3], smat[3][3], tmat[3][3]; + + /* initialise new matrix */ + unit_m4(mat); + + /* make rotation + scaling part */ + eul_to_mat3(rmat,eul); + size_to_mat3(smat,size); + mul_m3_m3m3(tmat, rmat, smat); + + /* copy rot/scale part to output matrix*/ + copy_m4_m3(mat, tmat); + + /* copy location to matrix */ + mat[3][0] = loc[0]; + mat[3][1] = loc[1]; + mat[3][2] = loc[2]; +} + +/* make a 4x4 matrix out of 3 transform components */ +/* matrices are made in the order: scale * rot * loc */ +void loc_eulO_size_to_mat4(float mat[4][4], float loc[3], float eul[3], float size[3], short rotOrder) +{ + float rmat[3][3], smat[3][3], tmat[3][3]; + + /* initialise new matrix */ + unit_m4(mat); + + /* make rotation + scaling part */ + eulO_to_mat3(rmat,eul, rotOrder); + size_to_mat3(smat,size); + mul_m3_m3m3(tmat, rmat, smat); + + /* copy rot/scale part to output matrix*/ + copy_m4_m3(mat, tmat); + + /* copy location to matrix */ + mat[3][0] = loc[0]; + mat[3][1] = loc[1]; + mat[3][2] = loc[2]; +} + + +/* make a 4x4 matrix out of 3 transform components */ +/* matrices are made in the order: scale * rot * loc */ +void loc_quat_size_to_mat4(float mat[4][4], float loc[3], float quat[4], float size[3]) +{ + float rmat[3][3], smat[3][3], tmat[3][3]; + + /* initialise new matrix */ + unit_m4(mat); + + /* make rotation + scaling part */ + quat_to_mat3(rmat,quat); + size_to_mat3(smat,size); + mul_m3_m3m3(tmat, rmat, smat); + + /* copy rot/scale part to output matrix*/ + copy_m4_m3(mat, tmat); + + /* copy location to matrix */ + mat[3][0] = loc[0]; + mat[3][1] = loc[1]; + mat[3][2] = loc[2]; +} + +/*********************************** Other ***********************************/ + +void print_m3(char *str, float m[][3]) +{ + printf("%s\n", str); + printf("%f %f %f\n",m[0][0],m[1][0],m[2][0]); + printf("%f %f %f\n",m[0][1],m[1][1],m[2][1]); + printf("%f %f %f\n",m[0][2],m[1][2],m[2][2]); + printf("\n"); +} + +void print_m4(char *str, float m[][4]) +{ + printf("%s\n", str); + printf("%f %f %f %f\n",m[0][0],m[1][0],m[2][0],m[3][0]); + printf("%f %f %f %f\n",m[0][1],m[1][1],m[2][1],m[3][1]); + printf("%f %f %f %f\n",m[0][2],m[1][2],m[2][2],m[3][2]); + printf("%f %f %f %f\n",m[0][3],m[1][3],m[2][3],m[3][3]); + printf("\n"); +} + diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c new file mode 100644 index 00000000000..084db725409 --- /dev/null +++ b/source/blender/blenlib/intern/math_rotation.c @@ -0,0 +1,1502 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "BLI_math.h" + +/******************************** Quaternions ********************************/ + +void unit_qt(float *q) +{ + q[0]= 1.0f; + q[1]= q[2]= q[3]= 0.0f; +} + +void copy_qt_qt(float *q1, float *q2) +{ + q1[0]= q2[0]; + q1[1]= q2[1]; + q1[2]= q2[2]; + q1[3]= q2[3]; +} + +int is_zero_qt(float *q) +{ + return (q[0] == 0 && q[1] == 0 && q[2] == 0 && q[3] == 0); +} + +void mul_qt_qtqt(float *q, float *q1, float *q2) +{ + float t0,t1,t2; + + t0= q1[0]*q2[0]-q1[1]*q2[1]-q1[2]*q2[2]-q1[3]*q2[3]; + t1= q1[0]*q2[1]+q1[1]*q2[0]+q1[2]*q2[3]-q1[3]*q2[2]; + t2= q1[0]*q2[2]+q1[2]*q2[0]+q1[3]*q2[1]-q1[1]*q2[3]; + q[3]= q1[0]*q2[3]+q1[3]*q2[0]+q1[1]*q2[2]-q1[2]*q2[1]; + q[0]=t0; + q[1]=t1; + q[2]=t2; +} + +/* Assumes a unit quaternion */ +void mul_qt_v3(float *q, float *v) +{ + float t0, t1, t2; + + t0= -q[1]*v[0]-q[2]*v[1]-q[3]*v[2]; + t1= q[0]*v[0]+q[2]*v[2]-q[3]*v[1]; + t2= q[0]*v[1]+q[3]*v[0]-q[1]*v[2]; + v[2]= q[0]*v[2]+q[1]*v[1]-q[2]*v[0]; + v[0]=t1; + v[1]=t2; + + t1= t0*-q[1]+v[0]*q[0]-v[1]*q[3]+v[2]*q[2]; + t2= t0*-q[2]+v[1]*q[0]-v[2]*q[1]+v[0]*q[3]; + v[2]= t0*-q[3]+v[2]*q[0]-v[0]*q[2]+v[1]*q[1]; + v[0]=t1; + v[1]=t2; +} + +void conjugate_qt(float *q) +{ + q[1] = -q[1]; + q[2] = -q[2]; + q[3] = -q[3]; +} + +float dot_qtqt(float *q1, float *q2) +{ + return q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2] + q1[3]*q2[3]; +} + +void invert_qt(float *q) +{ + float f = dot_qtqt(q, q); + + if (f == 0.0f) + return; + + conjugate_qt(q); + mul_qt_fl(q, 1.0f/f); +} + +/* simple mult */ +void mul_qt_fl(float *q, float f) +{ + q[0] *= f; + q[1] *= f; + q[2] *= f; + q[3] *= f; +} + +void sub_qt_qtqt(float *q, float *q1, float *q2) +{ + q2[0]= -q2[0]; + mul_qt_qtqt(q, q1, q2); + q2[0]= -q2[0]; +} + +/* angular mult factor */ +void mul_fac_qt_fl(float *q, float fac) +{ + float angle= fac*saacos(q[0]); /* quat[0]= cos(0.5*angle), but now the 0.5 and 2.0 rule out */ + + float co= (float)cos(angle); + float si= (float)sin(angle); + q[0]= co; + normalize_v3(q+1); + q[1]*= si; + q[2]*= si; + q[3]*= si; + +} + +void quat_to_mat3(float m[][3], float *q) +{ + double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; + + q0= M_SQRT2 * q[0]; + q1= M_SQRT2 * q[1]; + q2= M_SQRT2 * q[2]; + q3= M_SQRT2 * q[3]; + + qda= q0*q1; + qdb= q0*q2; + qdc= q0*q3; + qaa= q1*q1; + qab= q1*q2; + qac= q1*q3; + qbb= q2*q2; + qbc= q2*q3; + qcc= q3*q3; + + m[0][0]= (float)(1.0-qbb-qcc); + m[0][1]= (float)(qdc+qab); + m[0][2]= (float)(-qdb+qac); + + m[1][0]= (float)(-qdc+qab); + m[1][1]= (float)(1.0-qaa-qcc); + m[1][2]= (float)(qda+qbc); + + m[2][0]= (float)(qdb+qac); + m[2][1]= (float)(-qda+qbc); + m[2][2]= (float)(1.0-qaa-qbb); +} + +void quat_to_mat4(float m[][4], float *q) +{ + double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; + + q0= M_SQRT2 * q[0]; + q1= M_SQRT2 * q[1]; + q2= M_SQRT2 * q[2]; + q3= M_SQRT2 * q[3]; + + qda= q0*q1; + qdb= q0*q2; + qdc= q0*q3; + qaa= q1*q1; + qab= q1*q2; + qac= q1*q3; + qbb= q2*q2; + qbc= q2*q3; + qcc= q3*q3; + + m[0][0]= (float)(1.0-qbb-qcc); + m[0][1]= (float)(qdc+qab); + m[0][2]= (float)(-qdb+qac); + m[0][3]= 0.0f; + + m[1][0]= (float)(-qdc+qab); + m[1][1]= (float)(1.0-qaa-qcc); + m[1][2]= (float)(qda+qbc); + m[1][3]= 0.0f; + + m[2][0]= (float)(qdb+qac); + m[2][1]= (float)(-qda+qbc); + m[2][2]= (float)(1.0-qaa-qbb); + m[2][3]= 0.0f; + + m[3][0]= m[3][1]= m[3][2]= 0.0f; + m[3][3]= 1.0f; +} + +void mat3_to_quat(float *q, float wmat[][3]) +{ + double tr, s; + float mat[3][3]; + + /* work on a copy */ + copy_m3_m3(mat, wmat); + normalize_m3(mat); /* this is needed AND a NormalQuat in the end */ + + tr= 0.25*(1.0+mat[0][0]+mat[1][1]+mat[2][2]); + + if(tr>FLT_EPSILON) { + s= sqrt(tr); + q[0]= (float)s; + s= 1.0/(4.0*s); + q[1]= (float)((mat[1][2]-mat[2][1])*s); + q[2]= (float)((mat[2][0]-mat[0][2])*s); + q[3]= (float)((mat[0][1]-mat[1][0])*s); + } + else { + if(mat[0][0] > mat[1][1] && mat[0][0] > mat[2][2]) { + s= 2.0*sqrtf(1.0 + mat[0][0] - mat[1][1] - mat[2][2]); + q[1]= (float)(0.25*s); + + s= 1.0/s; + q[0]= (float)((mat[2][1] - mat[1][2])*s); + q[2]= (float)((mat[1][0] + mat[0][1])*s); + q[3]= (float)((mat[2][0] + mat[0][2])*s); + } + else if(mat[1][1] > mat[2][2]) { + s= 2.0*sqrtf(1.0 + mat[1][1] - mat[0][0] - mat[2][2]); + q[2]= (float)(0.25*s); + + s= 1.0/s; + q[0]= (float)((mat[2][0] - mat[0][2])*s); + q[1]= (float)((mat[1][0] + mat[0][1])*s); + q[3]= (float)((mat[2][1] + mat[1][2])*s); + } + else { + s= 2.0*sqrtf(1.0 + mat[2][2] - mat[0][0] - mat[1][1]); + q[3]= (float)(0.25*s); + + s= 1.0/s; + q[0]= (float)((mat[1][0] - mat[0][1])*s); + q[1]= (float)((mat[2][0] + mat[0][2])*s); + q[2]= (float)((mat[2][1] + mat[1][2])*s); + } + } + + normalize_qt(q); +} + +void mat4_to_quat(float *q, float m[][4]) +{ + float mat[3][3]; + + copy_m3_m4(mat, m); + mat3_to_quat(q,mat); +} + +void mat3_to_quat_is_ok(float q[4], float wmat[3][3]) +{ + float mat[3][3], matr[3][3], matn[3][3], q1[4], q2[4], angle, si, co, nor[3]; + + /* work on a copy */ + copy_m3_m3(mat, wmat); + normalize_m3(mat); + + /* rotate z-axis of matrix to z-axis */ + + nor[0] = mat[2][1]; /* cross product with (0,0,1) */ + nor[1] = -mat[2][0]; + nor[2] = 0.0; + normalize_v3(nor); + + co= mat[2][2]; + angle= 0.5f*saacos(co); + + co= (float)cos(angle); + si= (float)sin(angle); + q1[0]= co; + q1[1]= -nor[0]*si; /* negative here, but why? */ + q1[2]= -nor[1]*si; + q1[3]= -nor[2]*si; + + /* rotate back x-axis from mat, using inverse q1 */ + quat_to_mat3( matr,q1); + invert_m3_m3(matn, matr); + mul_m3_v3(matn, mat[0]); + + /* and align x-axes */ + angle= (float)(0.5*atan2(mat[0][1], mat[0][0])); + + co= (float)cos(angle); + si= (float)sin(angle); + q2[0]= co; + q2[1]= 0.0f; + q2[2]= 0.0f; + q2[3]= si; + + mul_qt_qtqt(q, q1, q2); +} + + +void normalize_qt(float *q) +{ + float len; + + len= (float)sqrt(dot_qtqt(q, q)); + if(len!=0.0) { + mul_qt_fl(q, 1.0f/len); + } + else { + q[1]= 1.0f; + q[0]= q[2]= q[3]= 0.0f; + } +} + +void rotation_between_vecs_to_quat(float *q, float v1[3], float v2[3]) +{ + float axis[3]; + float angle; + + cross_v3_v3v3(axis, v1, v2); + + angle = angle_normalized_v3v3(v1, v2); + + axis_angle_to_quat(q, axis, angle); +} + +void vec_to_quat(float *q,float *vec, short axis, short upflag) +{ + float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1; + + /* first rotate to axis */ + if(axis>2) { + x2= vec[0] ; y2= vec[1] ; z2= vec[2]; + axis-= 3; + } + else { + x2= -vec[0] ; y2= -vec[1] ; z2= -vec[2]; + } + + q[0]=1.0; + q[1]=q[2]=q[3]= 0.0; + + len1= (float)sqrt(x2*x2+y2*y2+z2*z2); + if(len1 == 0.0) return; + + /* nasty! I need a good routine for this... + * problem is a rotation of an Y axis to the negative Y-axis for example. + */ + + if(axis==0) { /* x-axis */ + nor[0]= 0.0; + nor[1]= -z2; + nor[2]= y2; + + if(fabs(y2)+fabs(z2)<0.0001) + nor[1]= 1.0; + + co= x2; + } + else if(axis==1) { /* y-axis */ + nor[0]= z2; + nor[1]= 0.0; + nor[2]= -x2; + + if(fabs(x2)+fabs(z2)<0.0001) + nor[2]= 1.0; + + co= y2; + } + else { /* z-axis */ + nor[0]= -y2; + nor[1]= x2; + nor[2]= 0.0; + + if(fabs(x2)+fabs(y2)<0.0001) + nor[0]= 1.0; + + co= z2; + } + co/= len1; + + normalize_v3(nor); + + angle= 0.5f*saacos(co); + si= (float)sin(angle); + q[0]= (float)cos(angle); + q[1]= nor[0]*si; + q[2]= nor[1]*si; + q[3]= nor[2]*si; + + if(axis!=upflag) { + quat_to_mat3(mat,q); + + fp= mat[2]; + if(axis==0) { + if(upflag==1) angle= (float)(0.5*atan2(fp[2], fp[1])); + else angle= (float)(-0.5*atan2(fp[1], fp[2])); + } + else if(axis==1) { + if(upflag==0) angle= (float)(-0.5*atan2(fp[2], fp[0])); + else angle= (float)(0.5*atan2(fp[0], fp[2])); + } + else { + if(upflag==0) angle= (float)(0.5*atan2(-fp[1], -fp[0])); + else angle= (float)(-0.5*atan2(-fp[0], -fp[1])); + } + + co= (float)cos(angle); + si= (float)(sin(angle)/len1); + q2[0]= co; + q2[1]= x2*si; + q2[2]= y2*si; + q2[3]= z2*si; + + mul_qt_qtqt(q,q2,q); + } +} + +#if 0 +/* A & M Watt, Advanced animation and rendering techniques, 1992 ACM press */ +void QuatInterpolW(float *result, float *quat1, float *quat2, float t) +{ + float omega, cosom, sinom, sc1, sc2; + + cosom = quat1[0]*quat2[0] + quat1[1]*quat2[1] + quat1[2]*quat2[2] + quat1[3]*quat2[3] ; + + /* rotate around shortest angle */ + if ((1.0f + cosom) > 0.0001f) { + + if ((1.0f - cosom) > 0.0001f) { + omega = (float)acos(cosom); + sinom = (float)sin(omega); + sc1 = (float)sin((1.0 - t) * omega) / sinom; + sc2 = (float)sin(t * omega) / sinom; + } + else { + sc1 = 1.0f - t; + sc2 = t; + } + result[0] = sc1*quat1[0] + sc2*quat2[0]; + result[1] = sc1*quat1[1] + sc2*quat2[1]; + result[2] = sc1*quat1[2] + sc2*quat2[2]; + result[3] = sc1*quat1[3] + sc2*quat2[3]; + } + else { + result[0] = quat2[3]; + result[1] = -quat2[2]; + result[2] = quat2[1]; + result[3] = -quat2[0]; + + sc1 = (float)sin((1.0 - t)*M_PI_2); + sc2 = (float)sin(t*M_PI_2); + + result[0] = sc1*quat1[0] + sc2*result[0]; + result[1] = sc1*quat1[1] + sc2*result[1]; + result[2] = sc1*quat1[2] + sc2*result[2]; + result[3] = sc1*quat1[3] + sc2*result[3]; + } +} +#endif + +void interp_qt_qtqt(float *result, float *quat1, float *quat2, float t) +{ + float quat[4], omega, cosom, sinom, sc1, sc2; + + cosom = quat1[0]*quat2[0] + quat1[1]*quat2[1] + quat1[2]*quat2[2] + quat1[3]*quat2[3] ; + + /* rotate around shortest angle */ + if (cosom < 0.0f) { + cosom = -cosom; + quat[0]= -quat1[0]; + quat[1]= -quat1[1]; + quat[2]= -quat1[2]; + quat[3]= -quat1[3]; + } + else { + quat[0]= quat1[0]; + quat[1]= quat1[1]; + quat[2]= quat1[2]; + quat[3]= quat1[3]; + } + + if ((1.0f - cosom) > 0.0001f) { + omega = (float)acos(cosom); + sinom = (float)sin(omega); + sc1 = (float)sin((1 - t) * omega) / sinom; + sc2 = (float)sin(t * omega) / sinom; + } else { + sc1= 1.0f - t; + sc2= t; + } + + result[0] = sc1 * quat[0] + sc2 * quat2[0]; + result[1] = sc1 * quat[1] + sc2 * quat2[1]; + result[2] = sc1 * quat[2] + sc2 * quat2[2]; + result[3] = sc1 * quat[3] + sc2 * quat2[3]; +} + +void add_qt_qtqt(float *result, float *quat1, float *quat2, float t) +{ + result[0]= quat1[0] + t*quat2[0]; + result[1]= quat1[1] + t*quat2[1]; + result[2]= quat1[2] + t*quat2[2]; + result[3]= quat1[3] + t*quat2[3]; +} + +void tri_to_quat(float *quat, float *v1, float *v2, float *v3) +{ + /* imaginary x-axis, y-axis triangle is being rotated */ + float vec[3], q1[4], q2[4], n[3], si, co, angle, mat[3][3], imat[3][3]; + + /* move z-axis to face-normal */ + normal_tri_v3(vec,v1, v2, v3); + + n[0]= vec[1]; + n[1]= -vec[0]; + n[2]= 0.0f; + normalize_v3(n); + + if(n[0]==0.0f && n[1]==0.0f) n[0]= 1.0f; + + angle= -0.5f*(float)saacos(vec[2]); + co= (float)cos(angle); + si= (float)sin(angle); + q1[0]= co; + q1[1]= n[0]*si; + q1[2]= n[1]*si; + q1[3]= 0.0f; + + /* rotate back line v1-v2 */ + quat_to_mat3(mat,q1); + invert_m3_m3(imat, mat); + sub_v3_v3v3(vec, v2, v1); + mul_m3_v3(imat, vec); + + /* what angle has this line with x-axis? */ + vec[2]= 0.0f; + normalize_v3(vec); + + angle= (float)(0.5*atan2(vec[1], vec[0])); + co= (float)cos(angle); + si= (float)sin(angle); + q2[0]= co; + q2[1]= 0.0f; + q2[2]= 0.0f; + q2[3]= si; + + mul_qt_qtqt(quat, q1, q2); +} + +void print_qt(char *str, float q[4]) +{ + printf("%s: %.3f %.3f %.3f %.3f\n", str, q[0], q[1], q[2], q[3]); +} + +/******************************** Axis Angle *********************************/ + +/* Axis angle to Quaternions */ +void axis_angle_to_quat(float q[4], float axis[3], float angle) +{ + float nor[3]; + float si; + + copy_v3_v3(nor, axis); + normalize_v3(nor); + + angle /= 2; + si = (float)sin(angle); + q[0] = (float)cos(angle); + q[1] = nor[0] * si; + q[2] = nor[1] * si; + q[3] = nor[2] * si; +} + +/* Quaternions to Axis Angle */ +void quat_to_axis_angle(float axis[3], float *angle,float q[4]) +{ + float ha, si; + + /* calculate angle/2, and sin(angle/2) */ + ha= (float)acos(q[0]); + si= (float)sin(ha); + + /* from half-angle to angle */ + *angle= ha * 2; + + /* prevent division by zero for axis conversion */ + if (fabs(si) < 0.0005) + si= 1.0f; + + axis[0]= q[1] / si; + axis[1]= q[2] / si; + axis[2]= q[3] / si; +} + +/* Axis Angle to Euler Rotation */ +void axis_angle_to_eulO(float eul[3], short order,float axis[3], float angle) +{ + float q[4]; + + /* use quaternions as intermediate representation for now... */ + axis_angle_to_quat(q, axis, angle); + quat_to_eulO(eul, order,q); +} + +/* Euler Rotation to Axis Angle */ +void eulO_to_axis_angle(float axis[3], float *angle,float eul[3], short order) +{ + float q[4]; + + /* use quaternions as intermediate representation for now... */ + eulO_to_quat(q,eul, order); + quat_to_axis_angle(axis, angle,q); +} + +/* axis angle to 3x3 matrix - safer version (normalisation of axis performed) */ +void axis_angle_to_mat3(float mat[3][3],float axis[3], float angle) +{ + float nor[3], nsi[3], co, si, ico; + + /* normalise the axis first (to remove unwanted scaling) */ + copy_v3_v3(nor, axis); + normalize_v3(nor); + + /* now convert this to a 3x3 matrix */ + co= (float)cos(angle); + si= (float)sin(angle); + + ico= (1.0f - co); + nsi[0]= nor[0]*si; + nsi[1]= nor[1]*si; + nsi[2]= nor[2]*si; + + mat[0][0] = ((nor[0] * nor[0]) * ico) + co; + mat[0][1] = ((nor[0] * nor[1]) * ico) + nsi[2]; + mat[0][2] = ((nor[0] * nor[2]) * ico) - nsi[1]; + mat[1][0] = ((nor[0] * nor[1]) * ico) - nsi[2]; + mat[1][1] = ((nor[1] * nor[1]) * ico) + co; + mat[1][2] = ((nor[1] * nor[2]) * ico) + nsi[0]; + mat[2][0] = ((nor[0] * nor[2]) * ico) + nsi[1]; + mat[2][1] = ((nor[1] * nor[2]) * ico) - nsi[0]; + mat[2][2] = ((nor[2] * nor[2]) * ico) + co; +} + +/* axis angle to 4x4 matrix - safer version (normalisation of axis performed) */ +void axis_angle_to_mat4(float mat[4][4],float axis[3], float angle) +{ + float tmat[3][3]; + + axis_angle_to_mat3(tmat,axis, angle); + unit_m4(mat); + copy_m4_m3(mat, tmat); +} + +/* 3x3 matrix to axis angle (see Mat4ToVecRot too) */ +void mat3_to_axis_angle(float axis[3], float *angle,float mat[3][3]) +{ + float q[4]; + + /* use quaternions as intermediate representation */ + // TODO: it would be nicer to go straight there... + mat3_to_quat(q,mat); + quat_to_axis_angle(axis, angle,q); +} + +/* 4x4 matrix to axis angle (see Mat4ToVecRot too) */ +void mat4_to_axis_angle(float axis[3], float *angle,float mat[4][4]) +{ + float q[4]; + + /* use quaternions as intermediate representation */ + // TODO: it would be nicer to go straight there... + mat4_to_quat(q,mat); + quat_to_axis_angle(axis, angle,q); +} + +/****************************** Vector/Rotation ******************************/ +/* TODO: the following calls should probably be depreceated sometime */ + +/* 3x3 matrix to axis angle */ +void mat3_to_vec_rot(float axis[3], float *angle,float mat[3][3]) +{ + float q[4]; + + /* use quaternions as intermediate representation */ + // TODO: it would be nicer to go straight there... + mat3_to_quat(q,mat); + quat_to_axis_angle(axis, angle,q); +} + +/* 4x4 matrix to axis angle */ +void mat4_to_vec_rot(float axis[3], float *angle,float mat[4][4]) +{ + float q[4]; + + /* use quaternions as intermediate representation */ + // TODO: it would be nicer to go straight there... + mat4_to_quat(q,mat); + quat_to_axis_angle(axis, angle,q); +} + +/* axis angle to 3x3 matrix */ +void vec_rot_to_mat3(float mat[][3],float *vec, float phi) +{ + /* rotation of phi radials around vec */ + float vx, vx2, vy, vy2, vz, vz2, co, si; + + vx= vec[0]; + vy= vec[1]; + vz= vec[2]; + vx2= vx*vx; + vy2= vy*vy; + vz2= vz*vz; + co= (float)cos(phi); + si= (float)sin(phi); + + mat[0][0]= vx2+co*(1.0f-vx2); + mat[0][1]= vx*vy*(1.0f-co)+vz*si; + mat[0][2]= vz*vx*(1.0f-co)-vy*si; + mat[1][0]= vx*vy*(1.0f-co)-vz*si; + mat[1][1]= vy2+co*(1.0f-vy2); + mat[1][2]= vy*vz*(1.0f-co)+vx*si; + mat[2][0]= vz*vx*(1.0f-co)+vy*si; + mat[2][1]= vy*vz*(1.0f-co)-vx*si; + mat[2][2]= vz2+co*(1.0f-vz2); +} + +/* axis angle to 4x4 matrix */ +void vec_rot_to_mat4(float mat[][4],float *vec, float phi) +{ + float tmat[3][3]; + + vec_rot_to_mat3(tmat,vec, phi); + unit_m4(mat); + copy_m4_m3(mat, tmat); +} + +/* axis angle to quaternion */ +void vec_rot_to_quat(float *quat,float *vec, float phi) +{ + /* rotation of phi radials around vec */ + float si; + + quat[1]= vec[0]; + quat[2]= vec[1]; + quat[3]= vec[2]; + + if(normalize_v3(quat+1) == 0.0f) { + unit_qt(quat); + } + else { + quat[0]= (float)cos(phi/2.0); + si= (float)sin(phi/2.0); + quat[1] *= si; + quat[2] *= si; + quat[3] *= si; + } +} + +/******************************** XYZ Eulers *********************************/ + +/* XYZ order */ +void eul_to_mat3(float mat[][3], float *eul) +{ + double ci, cj, ch, si, sj, sh, cc, cs, sc, ss; + + ci = cos(eul[0]); + cj = cos(eul[1]); + ch = cos(eul[2]); + si = sin(eul[0]); + sj = sin(eul[1]); + sh = sin(eul[2]); + cc = ci*ch; + cs = ci*sh; + sc = si*ch; + ss = si*sh; + + mat[0][0] = (float)(cj*ch); + mat[1][0] = (float)(sj*sc-cs); + mat[2][0] = (float)(sj*cc+ss); + mat[0][1] = (float)(cj*sh); + mat[1][1] = (float)(sj*ss+cc); + mat[2][1] = (float)(sj*cs-sc); + mat[0][2] = (float)-sj; + mat[1][2] = (float)(cj*si); + mat[2][2] = (float)(cj*ci); + +} + +/* XYZ order */ +void eul_to_mat4(float mat[][4], float *eul) +{ + double ci, cj, ch, si, sj, sh, cc, cs, sc, ss; + + ci = cos(eul[0]); + cj = cos(eul[1]); + ch = cos(eul[2]); + si = sin(eul[0]); + sj = sin(eul[1]); + sh = sin(eul[2]); + cc = ci*ch; + cs = ci*sh; + sc = si*ch; + ss = si*sh; + + mat[0][0] = (float)(cj*ch); + mat[1][0] = (float)(sj*sc-cs); + mat[2][0] = (float)(sj*cc+ss); + mat[0][1] = (float)(cj*sh); + mat[1][1] = (float)(sj*ss+cc); + mat[2][1] = (float)(sj*cs-sc); + mat[0][2] = (float)-sj; + mat[1][2] = (float)(cj*si); + mat[2][2] = (float)(cj*ci); + + + mat[3][0]= mat[3][1]= mat[3][2]= mat[0][3]= mat[1][3]= mat[2][3]= 0.0f; + mat[3][3]= 1.0f; +} + +/* returns two euler calculation methods, so we can pick the best */ +/* XYZ order */ +static void mat3_to_eul2(float tmat[][3], float *eul1, float *eul2) +{ + float cy, quat[4], mat[3][3]; + + mat3_to_quat(quat,tmat); + quat_to_mat3(mat,quat); + copy_m3_m3(mat, tmat); + normalize_m3(mat); + + cy = (float)sqrt(mat[0][0]*mat[0][0] + mat[0][1]*mat[0][1]); + + if (cy > 16.0*FLT_EPSILON) { + + eul1[0] = (float)atan2(mat[1][2], mat[2][2]); + eul1[1] = (float)atan2(-mat[0][2], cy); + eul1[2] = (float)atan2(mat[0][1], mat[0][0]); + + eul2[0] = (float)atan2(-mat[1][2], -mat[2][2]); + eul2[1] = (float)atan2(-mat[0][2], -cy); + eul2[2] = (float)atan2(-mat[0][1], -mat[0][0]); + + } else { + eul1[0] = (float)atan2(-mat[2][1], mat[1][1]); + eul1[1] = (float)atan2(-mat[0][2], cy); + eul1[2] = 0.0f; + + copy_v3_v3(eul2, eul1); + } +} + +/* XYZ order */ +void mat3_to_eul(float *eul,float tmat[][3]) +{ + float eul1[3], eul2[3]; + + mat3_to_eul2(tmat, eul1, eul2); + + /* return best, which is just the one with lowest values it in */ + if(fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) { + copy_v3_v3(eul, eul2); + } + else { + copy_v3_v3(eul, eul1); + } +} + +/* XYZ order */ +void mat4_to_eul(float *eul,float tmat[][4]) +{ + float tempMat[3][3]; + + copy_m3_m4(tempMat, tmat); + normalize_m3(tempMat); + mat3_to_eul(eul,tempMat); +} + +/* XYZ order */ +void quat_to_eul(float *eul,float *quat) +{ + float mat[3][3]; + + quat_to_mat3(mat,quat); + mat3_to_eul(eul,mat); +} + +/* XYZ order */ +void eul_to_quat(float *quat,float *eul) +{ + float ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; + + ti = eul[0]*0.5f; tj = eul[1]*0.5f; th = eul[2]*0.5f; + ci = (float)cos(ti); cj = (float)cos(tj); ch = (float)cos(th); + si = (float)sin(ti); sj = (float)sin(tj); sh = (float)sin(th); + cc = ci*ch; cs = ci*sh; sc = si*ch; ss = si*sh; + + quat[0] = cj*cc + sj*ss; + quat[1] = cj*sc - sj*cs; + quat[2] = cj*ss + sj*cc; + quat[3] = cj*cs - sj*sc; +} + +/* XYZ order */ +void rotate_eul(float *beul, char axis, float ang) +{ + float eul[3], mat1[3][3], mat2[3][3], totmat[3][3]; + + eul[0]= eul[1]= eul[2]= 0.0f; + if(axis=='x') eul[0]= ang; + else if(axis=='y') eul[1]= ang; + else eul[2]= ang; + + eul_to_mat3(mat1,eul); + eul_to_mat3(mat2,beul); + + mul_m3_m3m3(totmat, mat2, mat1); + + mat3_to_eul(beul,totmat); + +} + +/* exported to transform.c */ +/* order independent! */ +void compatible_eul(float *eul, float *oldrot) +{ + float dx, dy, dz; + + /* correct differences of about 360 degrees first */ + dx= eul[0] - oldrot[0]; + dy= eul[1] - oldrot[1]; + dz= eul[2] - oldrot[2]; + + while(fabs(dx) > 5.1) { + if(dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; + dx= eul[0] - oldrot[0]; + } + while(fabs(dy) > 5.1) { + if(dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; + dy= eul[1] - oldrot[1]; + } + while(fabs(dz) > 5.1) { + if(dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; + dz= eul[2] - oldrot[2]; + } + + /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ + if(fabs(dx) > 3.2 && fabs(dy)<1.6 && fabs(dz)<1.6) { + if(dx > 0.0) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; + } + if(fabs(dy) > 3.2 && fabs(dz)<1.6 && fabs(dx)<1.6) { + if(dy > 0.0) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; + } + if(fabs(dz) > 3.2 && fabs(dx)<1.6 && fabs(dy)<1.6) { + if(dz > 0.0) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; + } + + /* the method below was there from ancient days... but why! probably because the code sucks :) + */ +#if 0 + /* calc again */ + dx= eul[0] - oldrot[0]; + dy= eul[1] - oldrot[1]; + dz= eul[2] - oldrot[2]; + + /* special case, tested for x-z */ + + if((fabs(dx) > 3.1 && fabs(dz) > 1.5) || (fabs(dx) > 1.5 && fabs(dz) > 3.1)) { + if(dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; + if(eul[1] > 0.0) eul[1]= M_PI - eul[1]; else eul[1]= -M_PI - eul[1]; + if(dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; + + } + else if((fabs(dx) > 3.1 && fabs(dy) > 1.5) || (fabs(dx) > 1.5 && fabs(dy) > 3.1)) { + if(dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; + if(dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; + if(eul[2] > 0.0) eul[2]= M_PI - eul[2]; else eul[2]= -M_PI - eul[2]; + } + else if((fabs(dy) > 3.1 && fabs(dz) > 1.5) || (fabs(dy) > 1.5 && fabs(dz) > 3.1)) { + if(eul[0] > 0.0) eul[0]= M_PI - eul[0]; else eul[0]= -M_PI - eul[0]; + if(dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; + if(dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; + } +#endif +} + +/* uses 2 methods to retrieve eulers, and picks the closest */ +/* XYZ order */ +void mat3_to_compatible_eul(float *eul, float *oldrot,float mat[][3]) +{ + float eul1[3], eul2[3]; + float d1, d2; + + mat3_to_eul2(mat, eul1, eul2); + + compatible_eul(eul1, oldrot); + compatible_eul(eul2, oldrot); + + d1= (float)fabs(eul1[0]-oldrot[0]) + (float)fabs(eul1[1]-oldrot[1]) + (float)fabs(eul1[2]-oldrot[2]); + d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]); + + /* return best, which is just the one with lowest difference */ + if(d1 > d2) { + copy_v3_v3(eul, eul2); + } + else { + copy_v3_v3(eul, eul1); + } + +} + +/************************** Arbitrary Order Eulers ***************************/ + +/* Euler Rotation Order Code: + * was adapted from + ANSI C code from the article + "Euler Angle Conversion" + by Ken Shoemake, shoemake@graphics.cis.upenn.edu + in "Graphics Gems IV", Academic Press, 1994 + * for use in Blender + */ + +/* Type for rotation order info - see wiki for derivation details */ +typedef struct RotOrderInfo { + short axis[3]; + short parity; /* parity of axis permutation (even=0, odd=1) - 'n' in original code */ +} RotOrderInfo; + +/* Array of info for Rotation Order calculations + * WARNING: must be kept in same order as eEulerRotationOrders + */ +static RotOrderInfo rotOrders[]= { + /* i, j, k, n */ + {{0, 1, 2}, 0}, // XYZ + {{0, 2, 1}, 1}, // XZY + {{1, 0, 2}, 1}, // YXZ + {{1, 2, 0}, 0}, // YZX + {{2, 0, 1}, 0}, // ZXY + {{2, 1, 0}, 1} // ZYZ +}; + +/* Get relevant pointer to rotation order set from the array + * NOTE: since we start at 1 for the values, but arrays index from 0, + * there is -1 factor involved in this process... + */ +#define GET_ROTATIONORDER_INFO(order) (((order)>=1) ? &rotOrders[(order)-1] : &rotOrders[0]) + +/* Construct quaternion from Euler angles (in radians). */ +void eulO_to_quat(float q[4],float e[3], short order) +{ + RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); + short i=R->axis[0], j=R->axis[1], k=R->axis[2]; + double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; + double a[3]; + + ti = e[i]/2; tj = e[j]/2; th = e[k]/2; + + if (R->parity) e[j] = -e[j]; + + ci = cos(ti); cj = cos(tj); ch = cos(th); + si = sin(ti); sj = sin(tj); sh = sin(th); + + cc = ci*ch; cs = ci*sh; + sc = si*ch; ss = si*sh; + + a[i] = cj*sc - sj*cs; + a[j] = cj*ss + sj*cc; + a[k] = cj*cs - sj*sc; + + q[0] = cj*cc + sj*ss; + q[1] = a[0]; + q[2] = a[1]; + q[3] = a[2]; + + if (R->parity) q[j] = -q[j]; +} + +/* Convert quaternion to Euler angles (in radians). */ +void quat_to_eulO(float e[3], short order,float q[4]) +{ + float M[3][3]; + + quat_to_mat3(M,q); + mat3_to_eulO(e, order,M); +} + +/* Construct 3x3 matrix from Euler angles (in radians). */ +void eulO_to_mat3(float M[3][3],float e[3], short order) +{ + RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); + short i=R->axis[0], j=R->axis[1], k=R->axis[2]; + double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; + + if (R->parity) { + ti = -e[i]; tj = -e[j]; th = -e[k]; + } + else { + ti = e[i]; tj = e[j]; th = e[k]; + } + + ci = cos(ti); cj = cos(tj); ch = cos(th); + si = sin(ti); sj = sin(tj); sh = sin(th); + + cc = ci*ch; cs = ci*sh; + sc = si*ch; ss = si*sh; + + M[i][i] = cj*ch; M[j][i] = sj*sc-cs; M[k][i] = sj*cc+ss; + M[i][j] = cj*sh; M[j][j] = sj*ss+cc; M[k][j] = sj*cs-sc; + M[i][k] = -sj; M[j][k] = cj*si; M[k][k] = cj*ci; +} + +/* Construct 4x4 matrix from Euler angles (in radians). */ +void eulO_to_mat4(float M[4][4],float e[3], short order) +{ + float m[3][3]; + + /* for now, we'll just do this the slow way (i.e. copying matrices) */ + normalize_m3(m); + eulO_to_mat3(m,e, order); + copy_m4_m3(M, m); +} + +/* Convert 3x3 matrix to Euler angles (in radians). */ +void mat3_to_eulO(float e[3], short order,float M[3][3]) +{ + RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); + short i=R->axis[0], j=R->axis[1], k=R->axis[2]; + double cy = sqrt(M[i][i]*M[i][i] + M[i][j]*M[i][j]); + + if (cy > 16*FLT_EPSILON) { + e[i] = atan2(M[j][k], M[k][k]); + e[j] = atan2(-M[i][k], cy); + e[k] = atan2(M[i][j], M[i][i]); + } + else { + e[i] = atan2(-M[k][j], M[j][j]); + e[j] = atan2(-M[i][k], cy); + e[k] = 0; + } + + if (R->parity) { + e[0] = -e[0]; + e[1] = -e[1]; + e[2] = -e[2]; + } +} + +/* Convert 4x4 matrix to Euler angles (in radians). */ +void mat4_to_eulO(float e[3], short order,float M[4][4]) +{ + float m[3][3]; + + /* for now, we'll just do this the slow way (i.e. copying matrices) */ + copy_m3_m4(m, M); + normalize_m3(m); + mat3_to_eulO(e, order,m); +} + +/* returns two euler calculation methods, so we can pick the best */ +static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, short order) +{ + RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); + short i=R->axis[0], j=R->axis[1], k=R->axis[2]; + float m[3][3]; + double cy; + + /* process the matrix first */ + copy_m3_m3(m, M); + normalize_m3(m); + + cy= sqrt(m[i][i]*m[i][i] + m[i][j]*m[i][j]); + + if (cy > 16*FLT_EPSILON) { + e1[i] = atan2(m[j][k], m[k][k]); + e1[j] = atan2(-m[i][k], cy); + e1[k] = atan2(m[i][j], m[i][i]); + + e2[i] = atan2(-m[j][k], -m[k][k]); + e2[j] = atan2(-m[i][k], -cy); + e2[k] = atan2(-m[i][j], -m[i][i]); + } + else { + e1[i] = atan2(-m[k][j], m[j][j]); + e1[j] = atan2(-m[i][k], cy); + e1[k] = 0; + + copy_v3_v3(e2, e1); + } + + if (R->parity) { + e1[0] = -e1[0]; + e1[1] = -e1[1]; + e1[2] = -e1[2]; + + e2[0] = -e2[0]; + e2[1] = -e2[1]; + e2[2] = -e2[2]; + } +} + +/* uses 2 methods to retrieve eulers, and picks the closest */ +void mat3_to_compatible_eulO(float eul[3], float oldrot[3], short order,float mat[3][3]) +{ + float eul1[3], eul2[3]; + float d1, d2; + + mat3_to_eulo2(mat, eul1, eul2, order); + + compatible_eul(eul1, oldrot); + compatible_eul(eul2, oldrot); + + d1= (float)fabs(eul1[0]-oldrot[0]) + (float)fabs(eul1[1]-oldrot[1]) + (float)fabs(eul1[2]-oldrot[2]); + d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]); + + /* return best, which is just the one with lowest difference */ + if (d1 > d2) + copy_v3_v3(eul, eul2); + else + copy_v3_v3(eul, eul1); +} + +/* rotate the given euler by the given angle on the specified axis */ +// NOTE: is this safe to do with different axis orders? +void rotate_eulO(float beul[3], short order, char axis, float ang) +{ + float eul[3], mat1[3][3], mat2[3][3], totmat[3][3]; + + eul[0]= eul[1]= eul[2]= 0.0f; + if (axis=='x') + eul[0]= ang; + else if (axis=='y') + eul[1]= ang; + else + eul[2]= ang; + + eulO_to_mat3(mat1,eul, order); + eulO_to_mat3(mat2,beul, order); + + mul_m3_m3m3(totmat, mat2, mat1); + + mat3_to_eulO(beul, order,totmat); +} + +/* the matrix is written to as 3 axis vectors */ +void eulO_to_gimbal_axis(float gmat[][3], float *eul, short order) +{ + RotOrderInfo *R= GET_ROTATIONORDER_INFO(order); + + float mat[3][3]; + float teul[3]; + + /* first axis is local */ + eulO_to_mat3(mat,eul, order); + copy_v3_v3(gmat[R->axis[0]], mat[R->axis[0]]); + + /* second axis is local minus first rotation */ + copy_v3_v3(teul, eul); + teul[R->axis[0]] = 0; + eulO_to_mat3(mat,teul, order); + copy_v3_v3(gmat[R->axis[1]], mat[R->axis[1]]); + + + /* Last axis is global */ + gmat[R->axis[2]][0] = 0; + gmat[R->axis[2]][1] = 0; + gmat[R->axis[2]][2] = 0; + gmat[R->axis[2]][R->axis[2]] = 1; +} + +/******************************* Dual Quaternions ****************************/ + +/* + Conversion routines between (regular quaternion, translation) and + dual quaternion. + + Version 1.0.0, February 7th, 2007 + + Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights + Reserved + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author(s) be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Author: Ladislav Kavan, kavanl@cs.tcd.ie + + Changes for Blender: + - renaming, style changes and optimizations + - added support for scaling +*/ + +void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4]) +{ + float *t, *q, dscale[3], scale[3], basequat[4]; + float baseRS[4][4], baseinv[4][4], baseR[4][4], baseRinv[4][4]; + float R[4][4], S[4][4]; + + /* split scaling and rotation, there is probably a faster way to do + this, it's done like this now to correctly get negative scaling */ + mul_m4_m4m4(baseRS, basemat, mat); + mat4_to_size(scale,baseRS); + + copy_v3_v3(dscale, scale); + dscale[0] -= 1.0f; dscale[1] -= 1.0f; dscale[2] -= 1.0f; + + if((determinant_m4(mat) < 0.0f) || len_v3(dscale) > 1e-4) { + /* extract R and S */ + mat4_to_quat(basequat,baseRS); + quat_to_mat4(baseR,basequat); + copy_v3_v3(baseR[3], baseRS[3]); + + invert_m4_m4(baseinv, basemat); + mul_m4_m4m4(R, baseinv, baseR); + + invert_m4_m4(baseRinv, baseR); + mul_m4_m4m4(S, baseRS, baseRinv); + + /* set scaling part */ + mul_serie_m4(dq->scale, basemat, S, baseinv, 0, 0, 0, 0, 0); + dq->scale_weight= 1.0f; + } + else { + /* matrix does not contain scaling */ + copy_m4_m4(R, mat); + dq->scale_weight= 0.0f; + } + + /* non-dual part */ + mat4_to_quat(dq->quat,R); + + /* dual part */ + t= R[3]; + q= dq->quat; + dq->trans[0]= -0.5f*(t[0]*q[1] + t[1]*q[2] + t[2]*q[3]); + dq->trans[1]= 0.5f*(t[0]*q[0] + t[1]*q[3] - t[2]*q[2]); + dq->trans[2]= 0.5f*(-t[0]*q[3] + t[1]*q[0] + t[2]*q[1]); + dq->trans[3]= 0.5f*(t[0]*q[2] - t[1]*q[1] + t[2]*q[0]); +} + +void dquat_to_mat4(float mat[][4],DualQuat *dq) +{ + float len, *t, q0[4]; + + /* regular quaternion */ + copy_qt_qt(q0, dq->quat); + + /* normalize */ + len= (float)sqrt(dot_qtqt(q0, q0)); + if(len != 0.0f) + mul_qt_fl(q0, 1.0f/len); + + /* rotation */ + quat_to_mat4(mat,q0); + + /* translation */ + t= dq->trans; + mat[3][0]= 2.0f*(-t[0]*q0[1] + t[1]*q0[0] - t[2]*q0[3] + t[3]*q0[2]); + mat[3][1]= 2.0f*(-t[0]*q0[2] + t[1]*q0[3] + t[2]*q0[0] - t[3]*q0[1]); + mat[3][2]= 2.0f*(-t[0]*q0[3] - t[1]*q0[2] + t[2]*q0[1] + t[3]*q0[0]); + + /* note: this does not handle scaling */ +} + +void add_weighted_dq_dq(DualQuat *dqsum, DualQuat *dq, float weight) +{ + int flipped= 0; + + /* make sure we interpolate quats in the right direction */ + if (dot_qtqt(dq->quat, dqsum->quat) < 0) { + flipped= 1; + weight= -weight; + } + + /* interpolate rotation and translation */ + dqsum->quat[0] += weight*dq->quat[0]; + dqsum->quat[1] += weight*dq->quat[1]; + dqsum->quat[2] += weight*dq->quat[2]; + dqsum->quat[3] += weight*dq->quat[3]; + + dqsum->trans[0] += weight*dq->trans[0]; + dqsum->trans[1] += weight*dq->trans[1]; + dqsum->trans[2] += weight*dq->trans[2]; + dqsum->trans[3] += weight*dq->trans[3]; + + /* interpolate scale - but only if needed */ + if (dq->scale_weight) { + float wmat[4][4]; + + if(flipped) /* we don't want negative weights for scaling */ + weight= -weight; + + copy_m4_m4(wmat, dq->scale); + mul_m4_fl(wmat, weight); + add_m4_m4m4(dqsum->scale, dqsum->scale, wmat); + dqsum->scale_weight += weight; + } +} + +void normalize_dq(DualQuat *dq, float totweight) +{ + float scale= 1.0f/totweight; + + mul_qt_fl(dq->quat, scale); + mul_qt_fl(dq->trans, scale); + + if(dq->scale_weight) { + float addweight= totweight - dq->scale_weight; + + if(addweight) { + dq->scale[0][0] += addweight; + dq->scale[1][1] += addweight; + dq->scale[2][2] += addweight; + dq->scale[3][3] += addweight; + } + + mul_m4_fl(dq->scale, scale); + dq->scale_weight= 1.0f; + } +} + +void mul_v3m3_dq(float *co, float mat[][3],DualQuat *dq) +{ + float M[3][3], t[3], scalemat[3][3], len2; + float w= dq->quat[0], x= dq->quat[1], y= dq->quat[2], z= dq->quat[3]; + float t0= dq->trans[0], t1= dq->trans[1], t2= dq->trans[2], t3= dq->trans[3]; + + /* rotation matrix */ + M[0][0]= w*w + x*x - y*y - z*z; + M[1][0]= 2*(x*y - w*z); + M[2][0]= 2*(x*z + w*y); + + M[0][1]= 2*(x*y + w*z); + M[1][1]= w*w + y*y - x*x - z*z; + M[2][1]= 2*(y*z - w*x); + + M[0][2]= 2*(x*z - w*y); + M[1][2]= 2*(y*z + w*x); + M[2][2]= w*w + z*z - x*x - y*y; + + len2= dot_qtqt(dq->quat, dq->quat); + if(len2 > 0.0f) + len2= 1.0f/len2; + + /* translation */ + t[0]= 2*(-t0*x + w*t1 - t2*z + y*t3); + t[1]= 2*(-t0*y + t1*z - x*t3 + w*t2); + t[2]= 2*(-t0*z + x*t2 + w*t3 - t1*y); + + /* apply scaling */ + if(dq->scale_weight) + mul_m4_v3(dq->scale, co); + + /* apply rotation and translation */ + mul_m3_v3(M, co); + co[0]= (co[0] + t[0])*len2; + co[1]= (co[1] + t[1])*len2; + co[2]= (co[2] + t[2])*len2; + + /* compute crazyspace correction mat */ + if(mat) { + if(dq->scale_weight) { + copy_m3_m4(scalemat, dq->scale); + mul_m3_m3m3(mat, M, scalemat); + } + else + copy_m3_m3(mat, M); + mul_m3_fl(mat, len2); + } +} + +void copy_dq_dq(DualQuat *dq1, DualQuat *dq2) +{ + memcpy(dq1, dq2, sizeof(DualQuat)); +} + diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c new file mode 100644 index 00000000000..8d36c3ac524 --- /dev/null +++ b/source/blender/blenlib/intern/math_vector.c @@ -0,0 +1,310 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include <float.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "BLI_math.h" + +//******************************* Interpolation *******************************/ + +void interp_v2_v2v2(float *target, float *a, float *b, float t) +{ + float s = 1.0f-t; + + target[0]= s*a[0] + t*b[0]; + target[1]= s*a[1] + t*b[1]; +} + +/* weight 3 2D vectors, + * 'w' must be unit length but is not a vector, just 3 weights */ +void interp_v2_v2v2v2(float p[2], float v1[2], float v2[2], float v3[2], float w[3]) +{ + p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2]; + p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2]; +} + +void interp_v3_v3v3(float *target, float *a, float *b, float t) +{ + float s = 1.0f-t; + + target[0]= s*a[0] + t*b[0]; + target[1]= s*a[1] + t*b[1]; + target[2]= s*a[2] + t*b[2]; +} + +/* weight 3 vectors, + * 'w' must be unit length but is not a vector, just 3 weights */ +void interp_v3_v3v3v3(float p[3], float v1[3], float v2[3], float v3[3], float w[3]) +{ + p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2]; + p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2]; + p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2]; +} + +void mid_v3_v3v3(float *v, float *v1, float *v2) +{ + v[0]= 0.5f*(v1[0] + v2[0]); + v[1]= 0.5f*(v1[1] + v2[1]); + v[2]= 0.5f*(v1[2] + v2[2]); +} + +/********************************* Comparison ********************************/ + +int is_zero_v3(float *v) +{ + return (v[0] == 0 && v[1] == 0 && v[2] == 0); +} + +int equals_v3v3(float *v1, float *v2) +{ + return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2])); +} + +int compare_v3v3(float *v1, float *v2, float limit) +{ + if(fabs(v1[0]-v2[0])<limit) + if(fabs(v1[1]-v2[1])<limit) + if(fabs(v1[2]-v2[2])<limit) + return 1; + + return 0; +} + +int compare_len_v3v3(float *v1, float *v2, float limit) +{ + float x,y,z; + + x=v1[0]-v2[0]; + y=v1[1]-v2[1]; + z=v1[2]-v2[2]; + + return ((x*x + y*y + z*z) < (limit*limit)); +} + +int compare_v4v4(float *v1, float *v2, float limit) +{ + if(fabs(v1[0]-v2[0])<limit) + if(fabs(v1[1]-v2[1])<limit) + if(fabs(v1[2]-v2[2])<limit) + if(fabs(v1[3]-v2[3])<limit) + return 1; + + return 0; +} + +/********************************** Angles ***********************************/ + +/* Return the angle in radians between vecs 1-2 and 2-3 in radians + If v1 is a shoulder, v2 is the elbow and v3 is the hand, + this would return the angle at the elbow */ +float angle_v3v3v3(float *v1, float *v2, float *v3) +{ + float vec1[3], vec2[3]; + + sub_v3_v3v3(vec1, v2, v1); + sub_v3_v3v3(vec2, v2, v3); + normalize_v3(vec1); + normalize_v3(vec2); + + return angle_normalized_v3v3(vec1, vec2); +} + +float angle_v2v2v2(float *v1, float *v2, float *v3) +{ + float vec1[2], vec2[2]; + + vec1[0] = v2[0]-v1[0]; + vec1[1] = v2[1]-v1[1]; + + vec2[0] = v2[0]-v3[0]; + vec2[1] = v2[1]-v3[1]; + + normalize_v2(vec1); + normalize_v2(vec2); + + return angle_normalized_v2v2(vec1, vec2); +} + +/* Return the shortest angle in radians between the 2 vectors */ +float angle_v2v2(float *v1, float *v2) +{ + float vec1[3], vec2[3]; + + copy_v3_v3(vec1, v1); + copy_v3_v3(vec2, v2); + normalize_v3(vec1); + normalize_v3(vec2); + + return angle_normalized_v3v3(vec1, vec2); +} + +float angle_normalized_v3v3(float *v1, float *v2) +{ + /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */ + if (dot_v3v3(v1, v2) < 0.0f) { + float vec[3]; + + vec[0]= -v2[0]; + vec[1]= -v2[1]; + vec[2]= -v2[2]; + + return (float)M_PI - 2.0f*(float)saasin(len_v3v3(vec, v1)/2.0f); + } + else + return 2.0f*(float)saasin(len_v3v3(v2, v1)/2.0f); +} + +float angle_normalized_v2v2(float *v1, float *v2) +{ + /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */ + if (dot_v2v2(v1, v2) < 0.0f) { + float vec[2]; + + vec[0]= -v2[0]; + vec[1]= -v2[1]; + + return (float)M_PI - 2.0f*saasin(len_v2v2(vec, v1)/2.0f); + } + else + return 2.0f*(float)saasin(len_v2v2(v2, v1)/2.0f); +} + +/********************************* Geometry **********************************/ + +/* Project v1 on v2 */ +void project_v3_v3v3(float *c, float *v1, float *v2) +{ + float mul; + mul = dot_v3v3(v1, v2) / dot_v3v3(v2, v2); + + c[0] = mul * v2[0]; + c[1] = mul * v2[1]; + c[2] = mul * v2[2]; +} + +/* Returns a vector bisecting the angle at v2 formed by v1, v2 and v3 */ +void bisect_v3_v3v3v3(float *out, float *v1, float *v2, float *v3) +{ + float d_12[3], d_23[3]; + sub_v3_v3v3(d_12, v2, v1); + sub_v3_v3v3(d_23, v3, v2); + normalize_v3(d_12); + normalize_v3(d_23); + add_v3_v3v3(out, d_12, d_23); + normalize_v3(out); +} + +/* Returns a reflection vector from a vector and a normal vector +reflect = vec - ((2 * DotVecs(vec, mirror)) * mirror) +*/ +void reflect_v3_v3v3(float *out, float *v1, float *v2) +{ + float vec[3], normal[3]; + float reflect[3] = {0.0f, 0.0f, 0.0f}; + float dot2; + + copy_v3_v3(vec, v1); + copy_v3_v3(normal, v2); + + normalize_v3(normal); + + dot2 = 2 * dot_v3v3(vec, normal); + + reflect[0] = vec[0] - (dot2 * normal[0]); + reflect[1] = vec[1] - (dot2 * normal[1]); + reflect[2] = vec[2] - (dot2 * normal[2]); + + copy_v3_v3(out, reflect); +} + +void ortho_basis_v3v3_v3(float *v1, float *v2, float *v) +{ + const float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]); + + if (f < 1e-35f) { + // degenerate case + v1[0] = (v[2] < 0.0f) ? -1.0f : 1.0f; + v1[1] = v1[2] = v2[0] = v2[2] = 0.0f; + v2[1] = 1.0f; + } + else { + const float d= 1.0f/f; + + v1[0] = v[1]*d; + v1[1] = -v[0]*d; + v1[2] = 0.0f; + v2[0] = -v[2]*v1[1]; + v2[1] = v[2]*v1[0]; + v2[2] = v[0]*v1[1] - v[1]*v1[0]; + } +} + +/*********************************** Other ***********************************/ + +void print_v2(char *str, float v[2]) +{ + printf("%s: %.3f %.3f\n", str, v[0], v[1]); +} + +void print_v3(char *str, float v[3]) +{ + printf("%s: %.3f %.3f %.3f\n", str, v[0], v[1], v[2]); +} + +void print_v4(char *str, float v[4]) +{ + printf("%s: %.3f %.3f %.3f %.3f\n", str, v[0], v[1], v[2], v[3]); +} + +void normal_short_to_float_v3(float *out, short *in) +{ + out[0] = in[0]*(1.0f/32767.0f); + out[1] = in[1]*(1.0f/32767.0f); + out[2] = in[2]*(1.0f/32767.0f); +} + +void normal_float_to_short_v3(short *out, float *in) +{ + out[0] = (short)(in[0]*32767.0f); + out[1] = (short)(in[1]*32767.0f); + out[2] = (short)(in[2]*32767.0f); +} + +void minmax_v3_v3v3(float *min, float *max, float *vec) +{ + if(min[0]>vec[0]) min[0]= vec[0]; + if(min[1]>vec[1]) min[1]= vec[1]; + if(min[2]>vec[2]) min[2]= vec[2]; + + if(max[0]<vec[0]) max[0]= vec[0]; + if(max[1]<vec[1]) max[1]= vec[1]; + if(max[2]<vec[2]) max[2]= vec[2]; +} + diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c new file mode 100644 index 00000000000..6830f44ae1b --- /dev/null +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -0,0 +1,258 @@ +/** + * $Id$ + * + * ***** BEGIN GPL 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. + * + * 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: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include "BLI_math.h" + +#ifndef BLI_MATH_VECTOR_INLINE +#define BLI_MATH_VECTOR_INLINE + +/********************************** Init *************************************/ + +MINLINE void zero_v2(float r[2]) +{ + r[0]= 0.0f; + r[1]= 0.0f; +} + +MINLINE void zero_v3(float r[3]) +{ + r[0]= 0.0f; + r[1]= 0.0f; + r[2]= 0.0f; +} + +MINLINE void copy_v2_v2(float r[2], float a[2]) +{ + r[0]= a[0]; + r[1]= a[1]; +} + +MINLINE void copy_v3_v3(float r[3], float a[3]) +{ + r[0]= a[0]; + r[1]= a[1]; + r[2]= a[2]; +} + +/********************************* Arithmetic ********************************/ + +MINLINE void add_v2_v2(float *r, float *a) +{ + r[0] += a[0]; + r[1] += a[1]; +} + +MINLINE void add_v2_v2v2(float *r, float *a, float *b) +{ + r[0]= a[0] + b[0]; + r[1]= a[1] + b[1]; +} + +MINLINE void add_v3_v3(float *r, float *a) +{ + r[0] += a[0]; + r[1] += a[1]; + r[1] += a[1]; +} + +MINLINE void add_v3_v3v3(float *r, float *a, float *b) +{ + r[0]= a[0] + b[0]; + r[1]= a[1] + b[1]; + r[2]= a[2] + b[2]; +} + +MINLINE void sub_v2_v2(float *r, float *a) +{ + r[0] -= a[0]; + r[1] -= a[1]; +} + +MINLINE void sub_v2_v2v2(float *r, float *a, float *b) +{ + r[0]= a[0] - b[0]; + r[1]= a[1] - b[1]; +} + +MINLINE void sub_v3_v3(float *r, float *a) +{ + r[0] -= a[0]; + r[1] -= a[1]; + r[1] -= a[1]; +} + +MINLINE void sub_v3_v3v3(float *r, float *a, float *b) +{ + r[0]= a[0] - b[0]; + r[1]= a[1] - b[1]; + r[2]= a[2] - b[2]; +} + +MINLINE void mul_v2_fl(float *v1, float f) +{ + v1[0]*= f; + v1[1]*= f; +} + +MINLINE void mul_v3_fl(float r[3], float f) +{ + r[0] *= f; + r[1] *= f; + r[2] *= f; +} + +MINLINE void mul_v3_v3fl(float r[3], float a[3], float f) +{ + r[0]= a[0]*f; + r[1]= a[1]*f; + r[2]= a[2]*f; +} + +MINLINE void mul_v3_v3(float r[3], float a[3]) +{ + r[0] *= a[0]; + r[1] *= a[1]; + r[2] *= a[2]; +} + +MINLINE void mul_v3_v3v3(float *v, float *v1, float *v2) +{ + v[0] = v1[0] * v2[0]; + v[1] = v1[1] * v2[1]; + v[2] = v1[2] * v2[2]; +} + +MINLINE void negate_v3(float r[3]) +{ + r[0]= -r[0]; + r[1]= -r[1]; + r[2]= -r[2]; +} + +MINLINE void negate_v3_v3(float r[3], float a[3]) +{ + r[0]= -a[0]; + r[1]= -a[1]; + r[2]= -a[2]; +} + +MINLINE float dot_v2v2(float *a, float *b) +{ + return a[0]*b[0] + a[1]*b[1]; +} + +MINLINE float dot_v3v3(float a[3], float b[3]) +{ + return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; +} + +MINLINE float cross_v2v2(float a[2], float b[2]) +{ + return a[0]*b[1] - a[1]*b[0]; +} + +MINLINE void cross_v3_v3v3(float r[3], float a[3], float b[3]) +{ + r[0]= a[1]*b[2] - a[2]*b[1]; + r[1]= a[2]*b[0] - a[0]*b[2]; + r[2]= a[0]*b[1] - a[1]*b[0]; +} + +MINLINE void star_m3_v3(float mat[][3], float *vec) +{ + mat[0][0]= mat[1][1]= mat[2][2]= 0.0; + mat[0][1]= -vec[2]; + mat[0][2]= vec[1]; + mat[1][0]= vec[2]; + mat[1][2]= -vec[0]; + mat[2][0]= -vec[1]; + mat[2][1]= vec[0]; +} + +/*********************************** Length **********************************/ + +MINLINE float len_v2(float *v) +{ + return (float)sqrt(v[0]*v[0] + v[1]*v[1]); +} + +MINLINE float len_v2v2(float *v1, float *v2) +{ + float x, y; + + x = v1[0]-v2[0]; + y = v1[1]-v2[1]; + return (float)sqrt(x*x+y*y); +} + +MINLINE float len_v3(float a[3]) +{ + return sqrtf(dot_v3v3(a, a)); +} + +MINLINE float len_v3v3(float a[3], float b[3]) +{ + float d[3]; + + sub_v3_v3v3(d, b, a); + return len_v3(d); +} + +MINLINE float normalize_v2(float n[2]) +{ + float d= dot_v2v2(n, n); + + if(d > 1.0e-35f) { + d= sqrtf(d); + mul_v2_fl(n, 1.0f/d); + } else { + zero_v2(n); + d= 0.0f; + } + return d; +} + +MINLINE float normalize_v3(float n[3]) +{ + float d= dot_v3v3(n, n); + + /* a larger value causes normalize errors in a + scaled down models with camera xtreme close */ + if(d > 1.0e-35f) { + d= sqrtf(d); + mul_v3_fl(n, 1.0f/d); + } + else { + zero_v3(n); + d= 0.0f; + } + + return d; +} + +#endif /* BLI_MATH_VECTOR_INLINE */ + diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index bd9ed85efa2..e54382c9392 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -40,7 +40,7 @@ #include "DNA_listBase.h" #include "DNA_mesh_types.h" #include "BLI_editVert.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_scanfill.h" #include "BLI_callbacks.h" @@ -432,13 +432,13 @@ static void testvertexnearedge(void) eed= filledgebase.first; while(eed) { if(eve!=eed->v1 && eve!=eed->v2 && eve->xs==eed->f1) { - if(FloatCompare(eve->co,eed->v1->co, COMPLIMIT)) { + if(compare_v3v3(eve->co,eed->v1->co, COMPLIMIT)) { ed1->v2= eed->v1; eed->v1->h++; eve->h= 0; break; } - else if(FloatCompare(eve->co,eed->v2->co, COMPLIMIT)) { + else if(compare_v3v3(eve->co,eed->v2->co, COMPLIMIT)) { ed1->v2= eed->v2; eed->v2->h++; eve->h= 0; @@ -450,7 +450,7 @@ static void testvertexnearedge(void) vec2[0]= eed->v2->co[cox]; vec2[1]= eed->v2->co[coy]; if(boundinsideEV(eed,eve)) { - dist= DistVL2Dfl(vec1,vec2,vec3); + dist= dist_to_line_v2(vec1,vec2,vec3); if(dist<COMPLIMIT) { /* new edge */ ed1= BLI_addfilledge(eed->v1, eve); @@ -819,12 +819,12 @@ int BLI_edgefill(int mode, int mat_nr) eve= fillvertbase.first; while(eve) { if(v2) { - if( FloatCompare(v2, eve->co, COMPLIMIT)==0) { - len= CalcNormFloat(v1, v2, eve->co, norm); + if( compare_v3v3(v2, eve->co, COMPLIMIT)==0) { + len= normal_tri_v3( norm,v1, v2, eve->co); if(len != 0.0) break; } } - else if(FloatCompare(v1, eve->co, COMPLIMIT)==0) { + else if(compare_v3v3(v1, eve->co, COMPLIMIT)==0) { v2= eve->co; } eve= eve->next; diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index e2acbf21624..39afced92bc 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -1403,7 +1403,14 @@ void BLI_where_am_i(char *fullname, const char *name) return; } #endif - + +#ifdef _WIN32 + if(GetModuleFileName(0, fullname, FILE_MAXDIR+FILE_MAXFILE)) { + GetShortPathName(fullname, fullname, FILE_MAXDIR+FILE_MAXFILE); + return; + } +#endif + /* unix and non linux */ if (name && fullname && strlen(name)) { strcpy(fullname, name); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 00f7cbd9eeb..83899473cb4 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -102,7 +102,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_storage_types.h" // for relname flags #include "BKE_animsys.h" @@ -1983,6 +1983,8 @@ static void lib_link_ntree(FileData *fd, ID *id, bNodeTree *ntree) if(ntree->adt) lib_link_animdata(fd, &ntree->id, ntree->adt); + ntree->gpd= newlibadr_us(fd, id->lib, ntree->gpd); + for(node= ntree->nodes.first; node; node= node->next) node->id= newlibadr_us(fd, id->lib, node->id); } @@ -2333,7 +2335,7 @@ static void lib_link_pose(FileData *fd, Object *ob, bPose *pose) rebuild= 1; else if(ob->id.lib==NULL && arm->id.lib) { /* local pose selection copied to armature, bit hackish */ - pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); + pchan->bone->flag &= ~BONE_SELECTED; pchan->bone->flag |= pchan->selectflag; } } @@ -2367,6 +2369,8 @@ static void direct_link_bones(FileData *fd, Bone* bone) bone->prop= newdataadr(fd, bone->prop); if(bone->prop) IDP_DirectLinkProperty(bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + + bone->flag &= ~BONE_DRAW_ACTIVE; link_list(fd, &bone->childbase); @@ -2388,6 +2392,9 @@ static void direct_link_armature(FileData *fd, bArmature *arm) direct_link_bones(fd, bone); bone=bone->next; } + + arm->act_bone= newdataadr(fd, arm->act_bone); + arm->act_edbone= NULL; } /* ************ READ CAMERA ***************** */ @@ -5254,7 +5261,7 @@ static void lib_link_group(FileData *fd, Main *main) go= go->next; } if(add_us) group->id.us++; - rem_from_group(group, NULL); /* removes NULL entries */ + rem_from_group(group, NULL, NULL, NULL); /* removes NULL entries */ } group= group->id.next; } @@ -5983,13 +5990,38 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) ar->regiontype= RGN_TYPE_UI; ar->alignment= RGN_ALIGN_TOP; break; + case SPACE_VIEW3D: + /* toolbar */ + ar= MEM_callocN(sizeof(ARegion), "toolbar for view3d"); + + BLI_addtail(lb, ar); + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_LEFT; + ar->flag = RGN_FLAG_HIDDEN; + + /* tool properties */ + ar= MEM_callocN(sizeof(ARegion), "tool properties for view3d"); + + BLI_addtail(lb, ar); + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV; + ar->flag = RGN_FLAG_HIDDEN; + + /* buttons/list view */ + ar= MEM_callocN(sizeof(ARegion), "buttons for view3d"); + + BLI_addtail(lb, ar); + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_RIGHT; + ar->flag = RGN_FLAG_HIDDEN; #if 0 case SPACE_BUTS: /* context UI region */ ar= MEM_callocN(sizeof(ARegion), "area region from do_versions"); BLI_addtail(lb, ar); - ar->regiontype= RGN_TYPE_CHANNELS; - ar->alignment= RGN_ALIGN_TOP; + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_RIGHT; + break; #endif } @@ -8459,7 +8491,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } /* correctly initialise constinv matrix */ - Mat4One(ob->constinv); + unit_m4(ob->constinv); if (ob->type == OB_ARMATURE) { if (ob->pose) { @@ -8489,7 +8521,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } /* correctly initialise constinv matrix */ - Mat4One(pchan->constinv); + unit_m4(pchan->constinv); } } } @@ -9152,15 +9184,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } - if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 4)){ - Scene *sce= main->scene.first; - while(sce) { - if(sce->frame_step==0) - sce->frame_step= 1; - sce= sce->id.next; - } - } - if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) { Lamp *la= main->lamp.first; for(; la; la= la->id.next) { @@ -9522,7 +9545,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* and composit trees */ for(sce= main->scene.first; sce; sce= sce->id.next) { if(sce->nodetree && strlen(sce->nodetree->id.name)==0) - strcpy(sce->nodetree->id.name, "NTComposit Nodetree"); + strcpy(sce->nodetree->id.name, "NTCompositing Nodetree"); /* move to cameras */ if(sce->r.mode & R_PANORAMA) { @@ -9903,7 +9926,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* Add default gravity to scenes */ for(sce= main->scene.first; sce; sce= sce->id.next) { if((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0 - && VecLength(sce->physics_settings.gravity) == 0.0f) { + && len_v3(sce->physics_settings.gravity) == 0.0f) { sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f; sce->physics_settings.gravity[2] = -9.81f; @@ -10031,6 +10054,28 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* put 2.50 compatibility code here until next subversion bump */ { + { + Scene *sce= main->scene.first; + while(sce) { + if(sce->r.frame_step==0) + sce->r.frame_step= 1; + sce= sce->id.next; + } + } + { + /* ensure all nodes have unique names */ + bNodeTree *ntree= main->nodetree.first; + while(ntree) { + bNode *node=ntree->nodes.first; + + while(node) { + nodeUniqueName(ntree, node); + node= node->next; + } + + ntree= ntree->id.next; + } + } } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ @@ -10465,6 +10510,9 @@ static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree) if(ntree->adt) expand_animdata(fd, mainvar, ntree->adt); + + if(ntree->gpd) + expand_doit(fd, mainvar, ntree->gpd); for(node= ntree->nodes.first; node; node= node->next) if(node->id && node->type!=CMP_NODE_R_LAYERS) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 8ec12496e59..b2147221f9f 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1114,7 +1114,7 @@ static void write_pose(WriteData *wd, bPose *pose) /* prevent crashes with autosave, when a bone duplicated in editmode has not yet been assigned to its posechannel */ if (chan->bone) - chan->selectflag= chan->bone->flag & (BONE_SELECTED|BONE_ACTIVE); /* gets restored on read, for library armatures */ + chan->selectflag= chan->bone->flag & BONE_SELECTED; /* gets restored on read, for library armatures */ writestruct(wd, DATA, "bPoseChannel", 1, chan); } diff --git a/source/blender/collada/CMakeLists.txt b/source/blender/collada/CMakeLists.txt index f510e7ee9ad..a0a4fb78b9b 100644 --- a/source/blender/collada/CMakeLists.txt +++ b/source/blender/collada/CMakeLists.txt @@ -53,10 +53,10 @@ SET(INC ../makesrna ../editors/include ../../../intern/guardedalloc - ${OPENCOLLADA}/COLLADAStreamWriter/include - ${OPENCOLLADA}/COLLADABaseUtils/include - ${OPENCOLLADA}/COLLADAFramework/include - ${OPENCOLLADA}/COLLADASaxFrameworkLoader/include + ${OPENCOLLADA_INC}/COLLADAStreamWriter/include + ${OPENCOLLADA_INC}/COLLADABaseUtils/include + ${OPENCOLLADA_INC}/COLLADAFramework/include + ${OPENCOLLADA_INC}/COLLADASaxFrameworkLoader/include ) ENDIF(APPLE) diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index b626635d021..fac7b2c882a 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -37,7 +37,7 @@ extern "C" #include "BKE_image.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_string.h" #include "BLI_listbase.h" @@ -87,7 +87,7 @@ extern "C" // This function assumes that quat is normalized. // The following document was used as reference: // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm -void QuatToAxisAngle(float *q, float *axis, float *angle) +void quat_to_axis_angle( float *axis, float *angle,float *q) { // quat to axis angle *angle = 2 * acos(q[0]); @@ -666,11 +666,11 @@ protected: if (parent_mat) { float invpar[4][4]; - Mat4Invert(invpar, parent_mat); - Mat4MulMat4(local, mat, invpar); + invert_m4_m4(invpar, parent_mat); + mul_m4_m4m4(local, mat, invpar); } else { - Mat4CpyMat4(local, mat); + copy_m4_m4(local, mat); } TransformBase::decompose(local, loc, rot, size); @@ -681,9 +681,9 @@ protected: float axis[3]; float angle; double angle_deg; - EulToQuat(rot, quat); - NormalQuat(quat); - QuatToAxisAngle(quat, axis, &angle); + eul_to_quat( quat,rot); + normalize_qt(quat); + quat_to_axis_angle( axis, &angle,quat); angle_deg = angle * 180.0f / M_PI; node.addRotate(axis[0], axis[1], axis[2], angle_deg); */ @@ -901,12 +901,12 @@ private: bPoseChannel *parchan = get_pose_channel(ob_arm->pose, bone->parent->name); float invpar[4][4]; - Mat4Invert(invpar, parchan->pose_mat); - Mat4MulMat4(mat, pchan->pose_mat, invpar); + invert_m4_m4(invpar, parchan->pose_mat); + mul_m4_m4m4(mat, pchan->pose_mat, invpar); } else { // get world-space from armature-space - Mat4MulMat4(mat, pchan->pose_mat, ob_arm->obmat); + mul_m4_m4m4(mat, pchan->pose_mat, ob_arm->obmat); } TransformWriter::add_node_transform(node, mat, NULL); @@ -1059,9 +1059,9 @@ private: float inv_bind_mat[4][4]; // make world-space matrix, pose_mat is armature-space - Mat4MulMat4(world, pchan->pose_mat, ob_arm->obmat); + mul_m4_m4m4(world, pchan->pose_mat, ob_arm->obmat); - Mat4Invert(mat, world); + invert_m4_m4(mat, world); converter.mat4_to_dae(inv_bind_mat, mat); source.appendValues(inv_bind_mat); @@ -1241,9 +1241,9 @@ public: if (ob->type == OB_MESH && is_skinned_mesh) // for skinned mesh we write obmat in <bind_shape_matrix> - Mat4One(mat); + unit_m4(mat); else - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); TransformWriter::add_node_transform(node, mat, ob->parent ? ob->parent->obmat : NULL); @@ -2048,7 +2048,7 @@ public: float eul[3]; - QuatToEul(quat, eul); + quat_to_eul( eul,quat); for (int k = 0; k < 3; k++) create_bezt(eulcu[k], frame, eul[k]); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 966e1fa6615..f61fb1f457b 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -50,7 +50,7 @@ extern "C" #include "BKE_depsgraph.h" #include "BLI_util.h" #include "BKE_displist.h" -#include "BLI_arithb.h" +#include "BLI_math.h" } #include "BKE_armature.h" #include "BKE_mesh.h" @@ -62,7 +62,7 @@ extern "C" #include "BKE_utildefines.h" #include "BKE_action.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_string.h" @@ -186,7 +186,7 @@ public: float cur[4][4]; float copy[4][4]; - Mat4One(mat); + unit_m4(mat); for (int i = 0; i < node->getTransformations().getCount(); i++) { @@ -199,7 +199,7 @@ public: COLLADAFW::Translate *tra = (COLLADAFW::Translate*)tm; COLLADABU::Math::Vector3& t = tra->getTranslation(); - Mat4One(cur); + unit_m4(cur); cur[3][0] = (float)t[0]; cur[3][1] = (float)t[1]; cur[3][2] = (float)t[2]; @@ -214,16 +214,16 @@ public: float quat[4]; float rot_copy[3][3]; float mat[3][3]; - AxisAngleToQuat(quat, axis, angle); + axis_angle_to_quat(quat, axis, angle); - QuatToMat4(quat, cur); + quat_to_mat4( cur,quat); } break; case COLLADAFW::Transformation::SCALE: { COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale*)tm)->getScale(); float size[3] = {(float)s[0], (float)s[1], (float)s[2]}; - SizeToMat4(size, cur); + size_to_mat4( cur,size); } break; case COLLADAFW::Transformation::MATRIX: @@ -237,8 +237,8 @@ public: break; } - Mat4CpyMat4(copy, mat); - Mat4MulMat4(mat, cur, copy); + copy_m4_m4(copy, mat); + mul_m4_m4m4(mat, cur, copy); if (animation_map) { // AnimationList that drives this Transformation @@ -346,7 +346,7 @@ private: ob_arm(skin.ob_arm), controller_uid(skin.controller_uid) { - Mat4CpyMat4(bind_shape_matrix, (float (*)[4])skin.bind_shape_matrix); + copy_m4_m4(bind_shape_matrix, (float (*)[4])skin.bind_shape_matrix); transfer_uint_array_data_const(skin.joints_per_vertex, joints_per_vertex); transfer_uint_array_data_const(skin.weight_indices, weight_indices); @@ -438,7 +438,7 @@ private: std::vector<JointData>::iterator it; for (it = joint_data.begin(); it != joint_data.end(); it++) { if ((*it).joint_uid == uid) { - Mat4CpyMat4(inv_bind_mat, (*it).inv_bind_mat); + copy_m4_m4(inv_bind_mat, (*it).inv_bind_mat); return true; } } @@ -491,8 +491,8 @@ private: // we need armature matrix here... where do we get it from I wonder... // root node/joint? or node with <instance_controller>? float parmat[4][4]; - Mat4One(parmat); - Mat4Invert(ob->parentinv, parmat); + unit_m4(parmat); + invert_m4_m4(ob->parentinv, parmat); // create all vertex groups std::vector<JointData>::iterator it; @@ -574,7 +574,7 @@ private: if (skin.get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) { // get original world-space matrix - Mat4Invert(mat, joint_inv_bind_mat); + invert_m4_m4(mat, joint_inv_bind_mat); } // create a bone even if there's no joint data for it (i.e. it has no influence) else { @@ -585,9 +585,9 @@ private: // get world-space if (parent) - Mat4MulMat4(mat, obmat, parent_mat); + mul_m4_m4m4(mat, obmat, parent_mat); else - Mat4CpyMat4(mat, obmat); + copy_m4_m4(mat, obmat); } // TODO rename from Node "name" attrs later @@ -597,21 +597,21 @@ private: if (parent) bone->parent = parent; // set head - VecCopyf(bone->head, mat[3]); + copy_v3_v3(bone->head, mat[3]); // set tail, don't set it to head because 0-length bones are not allowed float vec[3] = {0.0f, 0.5f, 0.0f}; - VecAddf(bone->tail, bone->head, vec); + add_v3_v3v3(bone->tail, bone->head, vec); // set parent tail if (parent && totchild == 1) { - VecCopyf(parent->tail, bone->head); + copy_v3_v3(parent->tail, bone->head); // XXX increase this to prevent "very" small bones? const float epsilon = 0.000001f; // derive leaf bone length - float length = VecLenf(parent->head, parent->tail); + float length = len_v3v3(parent->head, parent->tail); if ((length < leaf_bone_length || totbone == 0) && length > epsilon) { leaf_bone_length = length; } @@ -625,20 +625,20 @@ private: #if 0 // and which row in mat is bone direction float vec[3]; - VecSubf(vec, parent->tail, parent->head); + sub_v3_v3v3(vec, parent->tail, parent->head); #ifdef COLLADA_DEBUG - printvecf("tail - head", vec); - printmatrix4("matrix", parent_mat); + print_v3("tail - head", vec); + print_m4("matrix", parent_mat); #endif for (int i = 0; i < 3; i++) { #ifdef COLLADA_DEBUG char *axis_names[] = {"X", "Y", "Z"}; - printf("%s-axis length is %f\n", axis_names[i], VecLength(parent_mat[i])); + printf("%s-axis length is %f\n", axis_names[i], len_v3(parent_mat[i])); #endif - float angle = VecAngle2(vec, parent_mat[i]); + float angle = angle_v2v2(vec, parent_mat[i]); if (angle < min_angle) { #ifdef COLLADA_DEBUG - printvecf("picking", parent_mat[i]); + print_v3("picking", parent_mat[i]); printf("^ %s axis of %s's matrix\n", axis_names[i], get_dae_name(node)); #endif bone_direction_row = i; @@ -665,7 +665,7 @@ private: LeafBone leaf; leaf.bone = bone; - Mat4CpyMat4(leaf.mat, mat); + copy_m4_m4(leaf.mat, mat); BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name)); leaf_bones.push_back(leaf); @@ -682,10 +682,10 @@ private: // pointing up float vec[3] = {0.0f, 0.0f, 1.0f}; - VecMulf(vec, leaf_bone_length); + mul_v3_fl(vec, leaf_bone_length); - VecCopyf(leaf.bone->tail, leaf.bone->head); - VecAddf(leaf.bone->tail, leaf.bone->head, vec); + copy_v3_v3(leaf.bone->tail, leaf.bone->head); + add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec); } } @@ -2200,7 +2200,7 @@ public: float quat[4]; - EulToQuat(eul, quat); + eul_to_quat( quat,eul); for (int k = 0; k < 4; k++) create_bezt(quatcu[k], frame, quat[k]); diff --git a/source/blender/collada/SConscript b/source/blender/collada/SConscript index 7bf2870d6c5..6a1c71c9c86 100644 --- a/source/blender/collada/SConscript +++ b/source/blender/collada/SConscript @@ -4,7 +4,10 @@ Import ('env') sources = env.Glob('*.cpp') # relative paths to include dirs, space-separated, string -incs = '../blenlib ../blenkernel ../windowmanager ../makesdna ../makesrna ../editors/include ../../../intern/guardedalloc [OPENCOLLADA]/COLLADAStreamWriter/include [OPENCOLLADA]/COLLADABaseUtils/include [OPENCOLLADA]/COLLADAFramework/include [OPENCOLLADA]/COLLADASaxFrameworkLoader/include '.replace('[OPENCOLLADA]', env['BF_OPENCOLLADA_INC']) +if env['OURPLATFORM']=='darwin': + incs = '../blenlib ../blenkernel ../windowmanager ../makesdna ../makesrna ../editors/include ../../../intern/guardedalloc [OPENCOLLADA]/COLLADAStreamWriter [OPENCOLLADA]/COLLADABaseUtils [OPENCOLLADA]/COLLADAFramework [OPENCOLLADA]/COLLADASaxFrameworkLoader '.replace('[OPENCOLLADA]', env['BF_OPENCOLLADA_INC']) +else: + incs = '../blenlib ../blenkernel ../windowmanager ../makesdna ../makesrna ../editors/include ../../../intern/guardedalloc [OPENCOLLADA]/COLLADAStreamWriter/include [OPENCOLLADA]/COLLADABaseUtils/include [OPENCOLLADA]/COLLADAFramework/include [OPENCOLLADA]/COLLADASaxFrameworkLoader/include '.replace('[OPENCOLLADA]', env['BF_OPENCOLLADA_INC']) env.BlenderLib ('bf_collada', sources, Split(incs), [], libtype='core', priority=200 ) diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index c0d74505f72..32c3e7af874 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -39,8 +39,8 @@ public: void mat4_to_dae(float out[][4], float in[][4]) { - Mat4CpyMat4(out, in); - Mat4Transp(out); + copy_m4_m4(out, in); + transpose_m4(out); } void mat4_to_dae_double(double out[][4], float in[][4]) @@ -60,9 +60,9 @@ class TransformBase public: void decompose(float mat[][4], float *loc, float *rot, float *size) { - Mat4ToSize(mat, size); - Mat4ToEul(mat, rot); - VecCopyf(loc, mat[3]); + mat4_to_size( size,mat); + mat4_to_eul( rot,mat); + copy_v3_v3(loc, mat[3]); } }; diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index efbdd505bcb..24a8fb445c7 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_listBase.h" #include "DNA_anim_types.h" @@ -55,6 +55,7 @@ #include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_meta_types.h" +#include "DNA_node_types.h" #include "DNA_userdef_types.h" #include "DNA_gpencil_types.h" #include "DNA_windowmanager_types.h" @@ -1731,10 +1732,83 @@ static bAnimChannelType ACF_DSARM= acf_dsarm_icon, /* icon */ acf_generic_dataexpand_setting_valid, /* has setting */ - acf_dsarm_setting_flag, /* flag for setting */ + acf_dsarm_setting_flag, /* flag for setting */ acf_dsarm_setting_ptr /* pointer for setting */ }; +/* NodeTree Expander ------------------------------------------- */ + +// TODO: just get this from RNA? +static int acf_dsntree_icon(bAnimListElem *ale) +{ + return ICON_NODETREE; +} + +/* get the appropriate flag(s) for the setting when it is valid */ +static int acf_dsntree_setting_flag(int setting, short *neg) +{ + /* clear extra return data first */ + *neg= 0; + + switch (setting) { + case ACHANNEL_SETTING_EXPAND: /* expanded */ + return NTREE_DS_EXPAND; + + case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */ + return ADT_NLA_EVAL_OFF; + + case ACHANNEL_SETTING_VISIBLE: /* visible (only in Graph Editor) */ + *neg= 1; + return ADT_CURVES_NOT_VISIBLE; + + case ACHANNEL_SETTING_SELECT: /* selected */ + return ADT_UI_SELECTED; + + default: /* unsupported */ + return 0; + } +} + +/* get pointer to the setting */ +static void *acf_dsntree_setting_ptr(bAnimListElem *ale, int setting, short *type) +{ + bNodeTree *ntree= (bNodeTree *)ale->data; + + /* clear extra return data first */ + *type= 0; + + switch (setting) { + case ACHANNEL_SETTING_EXPAND: /* expanded */ + GET_ACF_FLAG_PTR(ntree->flag); + + case ACHANNEL_SETTING_SELECT: /* selected */ + case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ + case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ + if (ntree->adt) + GET_ACF_FLAG_PTR(ntree->adt->flag) + else + return NULL; + + default: /* unsupported */ + return NULL; + } +} + +/* node tree expander type define */ +static bAnimChannelType ACF_DSNTREE= +{ + acf_generic_dataexpand_backdrop,/* backdrop */ + acf_generic_indention_1, /* indent level */ // XXX this only works for compositing + acf_generic_basic_offset, /* offset */ + + acf_generic_idblock_name, /* name */ + acf_dsntree_icon, /* icon */ + + acf_generic_dataexpand_setting_valid, /* has setting */ + acf_dsntree_setting_flag, /* flag for setting */ + acf_dsntree_setting_ptr /* pointer for setting */ +}; + /* ShapeKey Entry ------------------------------------------- */ @@ -1867,7 +1941,7 @@ static void dummy_olddraw_gpencil () strcpy(treetype, "Material"); sprintf(name, "Nodes:%s", treetype); - special= ICON_NODE; + special= ICON_NODETREE; } break; case SPACE_SEQ: @@ -1982,6 +2056,7 @@ void ANIM_init_channel_typeinfo_data (void) animchannelTypeInfo[type++]= &ACF_DSCUR; /* Curve Channel */ animchannelTypeInfo[type++]= &ACF_DSSKEY; /* ShapeKey Channel */ animchannelTypeInfo[type++]= &ACF_DSWOR; /* World Channel */ + animchannelTypeInfo[type++]= &ACF_DSNTREE; /* NodeTree Channel */ animchannelTypeInfo[type++]= &ACF_DSPART; /* Particle Channel */ animchannelTypeInfo[type++]= &ACF_DSMBALL; /* MetaBall Channel */ animchannelTypeInfo[type++]= &ACF_DSARM; /* Armature Channel */ @@ -2200,6 +2275,9 @@ void ANIM_channel_draw (bAnimContext *ac, bAnimListElem *ale, float yminc, float UI_icon_draw(offset, ymid, acf->icon(ale)); offset += ICON_WIDTH; } + + /* turn off blending, since not needed anymore... */ + glDisable(GL_BLEND); /* step 4) draw special toggles ................................. * - in Graph Editor, checkboxes for visibility in curves area diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c index 1e5f1eac867..57a0f469458 100644 --- a/source/blender/editors/animation/anim_channels_edit.c +++ b/source/blender/editors/animation/anim_channels_edit.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_listBase.h" #include "DNA_anim_types.h" diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index aa581a7d15a..45512ae82fe 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -343,6 +343,7 @@ short ANIM_headerUI_standard_buttons (const bContext *C, bDopeSheet *ads, uiBloc uiBlockBeginAlign(block); uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSCE, B_REDR, ICON_SCENE_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Scene Animation"); uiDefIconButBitI(block, TOGN, ADS_FILTER_NOWOR, B_REDR, ICON_WORLD_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display World Animation"); + uiDefIconButBitI(block, TOGN, ADS_FILTER_NONTREE, B_REDR, ICON_NODETREE, (short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Node Tree Animation"); if (mainptr && mainptr->key.first) uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_SHAPEKEY_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display ShapeKeys"); if (mainptr && mainptr->mat.first) diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 8c4f10fb222..eab5404f106 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -64,6 +64,7 @@ #include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_meta_types.h" +#include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_particle_types.h" #include "DNA_space_types.h" @@ -599,6 +600,19 @@ bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, s ale->adt= BKE_animdata_from_id(data); } break; + case ANIMTYPE_DSARM: + { + bArmature *arm= (bArmature *)data; + AnimData *adt= arm->adt; + + ale->flag= FILTER_ARM_OBJD(arm); + + ale->key_data= (adt) ? adt->action : NULL; + ale->datatype= ALE_ACT; + + ale->adt= BKE_animdata_from_id(data); + } + break; case ANIMTYPE_DSSKEY: { Key *key= (Key *)data; @@ -625,6 +639,19 @@ bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, s ale->adt= BKE_animdata_from_id(data); } break; + case ANIMTYPE_DSNTREE: + { + bNodeTree *ntree= (bNodeTree *)data; + AnimData *adt= ntree->adt; + + ale->flag= FILTER_NTREE_SCED(ntree); + + ale->key_data= (adt) ? adt->action : NULL; + ale->datatype= ALE_ACT; + + ale->adt= BKE_animdata_from_id(data); + } + break; case ANIMTYPE_DSPART: { ParticleSettings *part= (ParticleSettings*)ale->data; @@ -1485,6 +1512,7 @@ static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, B static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode) { World *wo= sce->world; + bNodeTree *ntree= sce->nodetree; AnimData *adt= NULL; bAnimListElem *ale; int items = 0; @@ -1590,6 +1618,50 @@ static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads } ) } + /* nodetree */ + if ((ntree && ntree->adt) && !(ads->filterflag & ADS_FILTER_NONTREE)) { + /* Action, Drivers, or NLA for Nodetree */ + adt= ntree->adt; + ANIMDATA_FILTER_CASES(ntree, + { /* AnimData blocks - do nothing... */ }, + { /* nla */ + /* add NLA tracks */ + items += animdata_filter_nla(anim_data, ads, adt, filter_mode, ntree, ANIMTYPE_DSNTREE, (ID *)ntree); + }, + { /* drivers */ + /* include nodetree-expand widget? */ + if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) { + ale= make_new_animlistelem(ntree, ANIMTYPE_DSNTREE, sce, ANIMTYPE_SCENE, (ID *)ntree); + if (ale) { + BLI_addtail(anim_data, ale); + items++; + } + } + + /* add F-Curve channels (drivers are F-Curves) */ + if (FILTER_NTREE_SCED(ntree)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) { + // XXX owner info is messed up now... + items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, ntree, ANIMTYPE_DSNTREE, filter_mode, (ID *)ntree); + } + }, + { /* action */ + /* include nodetree-expand widget? */ + if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) { + ale= make_new_animlistelem(ntree, ANIMTYPE_DSNTREE, sce, ANIMTYPE_SCENE, (ID *)sce); + if (ale) { + BLI_addtail(anim_data, ale); + items++; + } + } + + /* add channels */ + if (FILTER_NTREE_SCED(ntree) || (filter_mode & ANIMFILTER_CURVESONLY)) { + items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, ntree, ANIMTYPE_DSNTREE, (ID *)ntree); + } + } + ) + } + // TODO: scene compositing nodes (these aren't standard node-trees) @@ -1616,7 +1688,7 @@ static int animdata_filter_dopesheet (ListBase *anim_data, bAnimContext *ac, bDo /* scene-linked animation */ // TODO: sequencer, composite nodes - are we to include those here too? { - short sceOk= 0, worOk= 0; + short sceOk= 0, worOk= 0, nodeOk=0; /* check filtering-flags if ok */ ANIMDATA_FILTER_CASES(sce, @@ -1643,17 +1715,30 @@ static int animdata_filter_dopesheet (ListBase *anim_data, bAnimContext *ac, bDo worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, worOk= !(ads->filterflag & ADS_FILTER_NOWOR);) } + if (sce->nodetree) { + ANIMDATA_FILTER_CASES(sce->nodetree, + { + /* for the special AnimData blocks only case, we only need to add + * the block if it is valid... then other cases just get skipped (hence ok=0) + */ + ANIMDATA_ADD_ANIMDATA(sce->nodetree); + nodeOk=0; + }, + nodeOk= !(ads->filterflag & ADS_FILTER_NONTREE);, + nodeOk= !(ads->filterflag & ADS_FILTER_NONTREE);, + nodeOk= !(ads->filterflag & ADS_FILTER_NONTREE);) + } /* if only F-Curves with visible flags set can be shown, check that * datablocks haven't been set to invisible */ if (filter_mode & ANIMFILTER_CURVEVISIBLE) { if ((sce->adt) && (sce->adt->flag & ADT_CURVES_NOT_VISIBLE)) - sceOk= worOk= 0; + sceOk= worOk= nodeOk= 0; } /* check if not all bad (i.e. so there is something to show) */ - if ( !(!sceOk && !worOk) ) { + if ( !(!sceOk && !worOk && !nodeOk) ) { /* add scene data to the list of filtered channels */ items += animdata_filter_dopesheet_scene(anim_data, ads, sce, filter_mode); } diff --git a/source/blender/editors/animation/anim_ipo_utils.c b/source/blender/editors/animation/anim_ipo_utils.c index 088fddd2e7e..98b6d0e7097 100644 --- a/source/blender/editors/animation/anim_ipo_utils.c +++ b/source/blender/editors/animation/anim_ipo_utils.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_key_types.h" @@ -61,53 +61,24 @@ /* ----------------------- Getter functions ----------------------- */ -/* gets the appropriate icon for the given blocktype */ -// XXX some of these will be depreceated? -int geticon_anim_blocktype(short blocktype) -{ - switch (blocktype) { - case ID_OB: - return ICON_OBJECT_DATA; - case ID_PO: - return ICON_POSE_HLT; - case ID_KE: - return ICON_SHAPEKEY_DATA; - case ID_MA: - return ICON_MATERIAL; - case ID_WO: - return ICON_WORLD; - case ID_CU: - return ICON_CURVE_DATA; - case ID_CA: - return ICON_CAMERA; - case ID_LA: - return ICON_LAMP; - case ID_TE: - return ICON_TEXTURE; - case ID_CO: - return ICON_CONSTRAINT; - case ID_FLUIDSIM: - return ICON_WORLD; // uggh - default: - return 0; // what about blank icon? - } -} - -/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings) +/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings), + * and return the icon used for the struct that this property refers to * WARNING: name buffer we're writing to cannot exceed 256 chars (check anim_channels_defines.c for details) */ -void getname_anim_fcurve(char *name, ID *id, FCurve *fcu) +int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) { + int icon = 0; + /* sanity checks */ if (name == NULL) - return; + return icon; else if ELEM3(NULL, id, fcu, fcu->rna_path) { if (fcu == NULL) sprintf(name, "<invalid>"); else if (fcu->rna_path == NULL) sprintf(name, "<no path>"); else /* id == NULL */ - BLI_snprintf(name, 128, "%s[%d]", fcu->rna_path, fcu->array_index); + BLI_snprintf(name, 256, "%s[%d]", fcu->rna_path, fcu->array_index); } else { PointerRNA id_ptr, ptr; @@ -182,17 +153,30 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu) /* putting this all together into the buffer */ // XXX we need to check for invalid names... - BLI_snprintf(name, 128, "%s%s (%s)", arrayname, propname, structname); + BLI_snprintf(name, 256, "%s%s (%s)", arrayname, propname, structname); /* free temp name if nameprop is set */ if (free_structname) MEM_freeN(structname); + + + /* Icon for this property's owner: + * use the struct's icon if it is set + */ + icon= RNA_struct_ui_icon(ptr.type); } else { /* invalid path */ - BLI_snprintf(name, 128, "\"%s[%d]\"", fcu->rna_path, fcu->array_index); + BLI_snprintf(name, 256, "\"%s[%d]\"", fcu->rna_path, fcu->array_index); + + /* icon for this should be the icon for the base ID */ + // TODO: or should we just use the error icon? + icon= RNA_struct_ui_icon(id_ptr.type); } } + + /* return the icon that the active data had */ + return icon; } /* ------------------------------- Color Codes for F-Curve Channels ---------------------------- */ diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index c08bf443851..ac2eec6fd21 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "DNA_anim_types.h" @@ -148,6 +148,7 @@ short ANIM_add_driver (ID *id, const char rna_path[], int array_index, short fla PropertyRNA *prop; FCurve *fcu; int array_index_max = array_index+1; + int done = 0; /* validate pointer first - exit if failure */ RNA_id_pointer_create(id, &id_ptr); @@ -198,10 +199,13 @@ short ANIM_add_driver (ID *id, const char rna_path[], int array_index, short fla } } } + + /* set the done status */ + done += (fcu != NULL); } /* done */ - return (fcu != NULL); + return done; } /* Main Driver Management API calls: diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 65c73355ad7..872722607ce 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -47,7 +47,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c index 019ece64132..fb02a88ea2b 100644 --- a/source/blender/editors/animation/keyframes_draw.c +++ b/source/blender/editors/animation/keyframes_draw.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dlrbTree.h" #include "DNA_listBase.h" @@ -58,6 +58,7 @@ #include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_meta_types.h" +#include "DNA_node_types.h" #include "DNA_particle_types.h" #include "DNA_userdef_types.h" #include "DNA_gpencil_types.h" @@ -688,6 +689,15 @@ void scene_to_keylist(bDopeSheet *ads, Scene *sce, DLRBT_Tree *keys, DLRBT_Tree if (adt->action) action_to_keylist(adt, adt->action, keys, blocks); } + + /* nodetree animdata */ + if ((sce->nodetree) && (sce->nodetree->adt) && !(filterflag & ADS_FILTER_NONTREE)) { + adt= sce->nodetree->adt; + + // TODO: when we adapt NLA system, this needs to be the NLA-scaled version + if (adt->action) + action_to_keylist(adt, adt->action, keys, blocks); + } } } diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index 7a167cb6c0c..23daa4a9034 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -32,7 +32,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" @@ -44,6 +44,7 @@ #include "DNA_material_types.h" #include "DNA_object_types.h" #include "DNA_meta_types.h" +#include "DNA_node_types.h" #include "DNA_particle_types.h" #include "DNA_space_types.h" #include "DNA_scene_types.h" @@ -304,6 +305,7 @@ static short ob_keys_bezier_loop(BeztEditData *bed, Object *ob, BeztEditFunc bez static short scene_keys_bezier_loop(BeztEditData *bed, Scene *sce, BeztEditFunc bezt_ok, BeztEditFunc bezt_cb, FcuEditFunc fcu_cb, int filterflag) { World *wo= (sce) ? sce->world : NULL; + bNodeTree *ntree= (sce) ? sce->nodetree : NULL; /* sanity check */ if (sce == NULL) @@ -321,6 +323,13 @@ static short scene_keys_bezier_loop(BeztEditData *bed, Scene *sce, BeztEditFunc return 1; } + /* NodeTree */ + if (ntree && ntree->adt) { + if (adt_keys_bezier_loop(bed, ntree->adt, bezt_ok, bezt_cb, fcu_cb, filterflag)) + return 1; + } + + return 0; } diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 3ad6ddf2c6f..9d3fc7a0fc4 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -33,7 +33,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 0412ee89e51..17a7dd91ed8 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "DNA_anim_types.h" @@ -617,7 +617,7 @@ static float visualkey_get_value (PointerRNA *ptr, PropertyRNA *prop, int array_ else if (strstr(identifier, "rotation")) { float eul[3]; - Mat4ToEul(ob->obmat, eul); + mat4_to_eul( eul,ob->obmat); return eul[array_index]; } } @@ -632,7 +632,7 @@ static float visualkey_get_value (PointerRNA *ptr, PropertyRNA *prop, int array_ * be safe. Therefore, the active object is passed here, and in many cases, this * will be what owns the pose-channel that is getting this anyway. */ - Mat4CpyMat4(tmat, pchan->pose_mat); + copy_m4_m4(tmat, pchan->pose_mat); constraint_mat_convertspace(ob, pchan, tmat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL); /* Loc, Rot/Quat keyframes are supported... */ @@ -647,14 +647,14 @@ static float visualkey_get_value (PointerRNA *ptr, PropertyRNA *prop, int array_ float eul[3]; /* euler-rotation test before standard rotation, as standard rotation does quats */ - Mat4ToEulO(tmat, eul, pchan->rotmode); + mat4_to_eulO( eul, pchan->rotmode,tmat); return eul[array_index]; } else if (strstr(identifier, "rotation_quaternion")) { float trimat[3][3], quat[4]; - Mat3CpyMat4(trimat, tmat); - Mat3ToQuat_is_ok(trimat, quat); + copy_m3_m4(trimat, tmat); + mat3_to_quat_is_ok( quat,trimat); return quat[array_index]; } diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 0f4f29d0091..520247b77c1 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "DNA_anim_types.h" diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index d31a3bda332..012610bfd25 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -136,7 +136,7 @@ struct bArmature; struct EditBone; struct ListBase; -void make_boneList(struct ListBase *edbo, struct ListBase *bones, struct EditBone *parent); +EditBone *make_boneList(struct ListBase *edbo, struct ListBase *bones, struct EditBone *parent, struct Bone *actBone); struct EditBone *addEditBone(struct bArmature *arm, char *name); void BIF_sk_selectStroke(struct bContext *C, short mval[2], short extend); diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index e49e3d99c49..560a1458dfd 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -39,7 +39,7 @@ #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_context.h" diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index c5b01f1cab0..f89caa7b2c1 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -51,7 +51,7 @@ #include "DNA_curve_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_ghash.h" @@ -129,10 +129,30 @@ void ED_armature_sync_selection(ListBase *edbo) } } +void ED_armature_validate_active(struct bArmature *arm) +{ + EditBone *ebone= arm->act_edbone; + + if(ebone) { + if(ebone->flag & BONE_HIDDEN_A || (ebone->flag & BONE_SELECTED)==0) + arm->act_edbone= NULL; + } +} + +void free_edit_bone(bArmature *arm, EditBone *bone) +{ + if(arm->act_edbone==bone) + arm->act_edbone= NULL; + + BLI_freelinkN(arm->edbo, bone); +} + /* converts Bones to EditBone list, used for tools as well */ -void make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent) +EditBone *make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent, Bone *actBone) { EditBone *eBone; + EditBone *eBoneAct= NULL; + EditBone *eBoneTest= NULL; Bone *curBone; float delta[3]; float premat[3][3]; @@ -165,13 +185,13 @@ void make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent) eBone->roll= 0.0f; /* roll fixing */ - VecSubf(delta, eBone->tail, eBone->head); + sub_v3_v3v3(delta, eBone->tail, eBone->head); vec_roll_to_mat3(delta, 0.0f, postmat); - Mat3CpyMat4(premat, curBone->arm_mat); + copy_m3_m4(premat, curBone->arm_mat); - Mat3Inv(imat, postmat); - Mat3MulMat3(difmat, imat, premat); + invert_m3_m3(imat, postmat); + mul_m3_m3m3(difmat, imat, premat); eBone->roll = (float)atan2(difmat[2][0], difmat[2][2]); @@ -194,9 +214,17 @@ void make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent) BLI_addtail(edbo, eBone); /* Add children if necessary */ - if (curBone->childbase.first) - make_boneList(edbo, &curBone->childbase, eBone); + if (curBone->childbase.first) { + eBoneTest= make_boneList(edbo, &curBone->childbase, eBone, actBone); + if(eBoneTest) + eBoneAct= eBoneTest; + } + + if(curBone==actBone) + eBoneAct= eBone; } + + return eBoneAct; } /* nasty stuff for converting roll in editbones into bones */ @@ -222,19 +250,19 @@ static void fix_bonelist_roll (ListBase *bonelist, ListBase *editbonelist) if (ebone) { /* Get the ebone premat */ - VecSubf(delta, ebone->tail, ebone->head); + sub_v3_v3v3(delta, ebone->tail, ebone->head); vec_roll_to_mat3(delta, ebone->roll, premat); /* Get the bone postmat */ - Mat3CpyMat4(postmat, curBone->arm_mat); + copy_m3_m4(postmat, curBone->arm_mat); - Mat3Inv(imat, premat); - Mat3MulMat3(difmat, imat, postmat); + invert_m3_m3(imat, premat); + mul_m3_m3m3(difmat, imat, postmat); #if 0 printf ("Bone %s\n", curBone->name); - printmatrix4("premat", premat); - printmatrix4("postmat", postmat); - printmatrix4("difmat", difmat); + print_m4("premat", premat); + print_m4("postmat", postmat); + print_m4("difmat", difmat); printf ("Roll = %f\n", (-atan2(difmat[2][0], difmat[2][2]) * (180.0/M_PI))); #endif curBone->roll = (float)-atan2(difmat[2][0], difmat[2][2]); @@ -259,7 +287,7 @@ void ED_armature_from_edit(Object *obedit) /* remove zero sized bones, this gives instable restposes */ for (eBone=arm->edbo->first; eBone; eBone= neBone) { - float len= VecLenf(eBone->head, eBone->tail); + float len= len_v3v3(eBone->head, eBone->tail); neBone= eBone->next; if (len <= 0.000001f) { /* FLT_EPSILON is too large? */ EditBone *fBone; @@ -270,7 +298,7 @@ void ED_armature_from_edit(Object *obedit) fBone->parent= eBone->parent; } printf("Warning: removed zero sized bone: %s\n", eBone->name); - BLI_freelinkN(arm->edbo, eBone); + free_edit_bone(arm, eBone); } } @@ -283,8 +311,12 @@ void ED_armature_from_edit(Object *obedit) memcpy(newBone->head, eBone->head, sizeof(float)*3); memcpy(newBone->tail, eBone->tail, sizeof(float)*3); newBone->flag= eBone->flag; - if (eBone->flag & BONE_ACTIVE) + + if (eBone == arm->act_edbone) { newBone->flag |= BONE_SELECTED; /* important, editbones can be active with only 1 point selected */ + arm->act_edbone= NULL; + arm->act_bone= newBone; + } newBone->roll = 0.0f; newBone->weight = eBone->weight; @@ -318,22 +350,22 @@ void ED_armature_from_edit(Object *obedit) float delta[3]; /* Get the parent's matrix (rotation only) */ - VecSubf(delta, eBone->parent->tail, eBone->parent->head); + sub_v3_v3v3(delta, eBone->parent->tail, eBone->parent->head); vec_roll_to_mat3(delta, eBone->parent->roll, M_parentRest); /* Get this bone's matrix (rotation only) */ - VecSubf(delta, eBone->tail, eBone->head); + sub_v3_v3v3(delta, eBone->tail, eBone->head); vec_roll_to_mat3(delta, eBone->roll, M_boneRest); /* Invert the parent matrix */ - Mat3Inv(iM_parentRest, M_parentRest); + invert_m3_m3(iM_parentRest, M_parentRest); /* Get the new head and tail */ - VecSubf(newBone->head, eBone->head, eBone->parent->tail); - VecSubf(newBone->tail, eBone->tail, eBone->parent->tail); + sub_v3_v3v3(newBone->head, eBone->head, eBone->parent->tail); + sub_v3_v3v3(newBone->tail, eBone->tail, eBone->parent->tail); - Mat3MulVecfl(iM_parentRest, newBone->head); - Mat3MulVecfl(iM_parentRest, newBone->tail); + mul_m3_v3(iM_parentRest, newBone->head); + mul_m3_v3(iM_parentRest, newBone->tail); } } /* ...otherwise add this bone to the armature's bonebase */ @@ -358,15 +390,15 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4]) { EditBone *ebone; bArmature *arm= ob->data; - float scale = Mat4ToScalef(mat); /* store the scale of the matrix here to use on envelopes */ + float scale = mat4_to_scale(mat); /* store the scale of the matrix here to use on envelopes */ /* Put the armature into editmode */ ED_armature_to_edit(ob); /* Do the rotations */ for (ebone = arm->edbo->first; ebone; ebone=ebone->next){ - Mat4MulVecfl(mat, ebone->head); - Mat4MulVecfl(mat, ebone->tail); + mul_m4_v3(mat, ebone->head); + mul_m4_v3(mat, ebone->tail); ebone->rad_head *= scale; ebone->rad_tail *= scale; @@ -397,8 +429,8 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) if (centermode == 2) { float *fp= give_cursor(scene, v3d); VECCOPY(cent, fp); - Mat4Invert(ob->imat, ob->obmat); - Mat4MulVecfl(ob->imat, cent); + invert_m4_m4(ob->imat, ob->obmat); + mul_m4_v3(ob->imat, cent); } else { INIT_MINMAX(min, max); @@ -415,8 +447,8 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) /* Do the adjustments */ for (ebone= arm->edbo->first; ebone; ebone=ebone->next) { - VecSubf(ebone->head, ebone->head, cent); - VecSubf(ebone->tail, ebone->tail, cent); + sub_v3_v3v3(ebone->head, ebone->head, cent); + sub_v3_v3v3(ebone->tail, ebone->tail, cent); } /* Turn the list into an armature */ @@ -424,9 +456,9 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) /* Adjust object location for new centerpoint */ if(centermode && obedit==NULL) { - Mat3CpyMat4(omat, ob->obmat); + copy_m3_m4(omat, ob->obmat); - Mat3MulVecfl(omat, cent); + mul_m3_v3(omat, cent); ob->loc[0] += cent[0]; ob->loc[1] += cent[1]; ob->loc[2] += cent[2]; @@ -492,7 +524,7 @@ static void applyarmature_fix_boneparents (Scene *scene, Object *armob) ED_object_apply_obmat(ob); what_does_parent(scene, ob, &workob); - Mat4Invert(ob->parentinv, workob.obmat); + invert_m4_m4(ob->parentinv, workob.obmat); } } } @@ -540,16 +572,16 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op) float delta[3], eul[3]; /* obtain new auto y-rotation */ - VecSubf(delta, curbone->tail, curbone->head); + sub_v3_v3v3(delta, curbone->tail, curbone->head); vec_roll_to_mat3(delta, 0.0f, premat); - Mat3Inv(imat, premat); + invert_m3_m3(imat, premat); /* get pchan 'visual' matrix */ - Mat3CpyMat4(pmat, pchan->pose_mat); + copy_m3_m4(pmat, pchan->pose_mat); /* remove auto from visual and get euler rotation */ - Mat3MulMat3(tmat, imat, pmat); - Mat3ToEul(tmat, eul); + mul_m3_m3m3(tmat, imat, pmat); + mat3_to_eul( eul,tmat); /* just use this euler-y as new roll value */ curbone->roll= eul[1]; @@ -737,8 +769,8 @@ int join_armature_exec(bContext *C, wmOperator *op) //BASACT->flag &= ~OB_MODE_POSE; /* Find the difference matrix */ - Mat4Invert(oimat, ob->obmat); - Mat4MulMat4(mat, base->object->obmat, oimat); + invert_m4_m4(oimat, ob->obmat); + mul_m4_m4m4(mat, base->object->obmat, oimat); /* Copy bones and posechannels from the object to the edit armature */ for (pchan=opose->chanbase.first; pchan; pchan=pchann) { @@ -758,23 +790,23 @@ int join_armature_exec(bContext *C, wmOperator *op) float delta[3]; /* Get the premat */ - VecSubf(delta, curbone->tail, curbone->head); + sub_v3_v3v3(delta, curbone->tail, curbone->head); vec_roll_to_mat3(delta, curbone->roll, temp); - Mat4One(premat); /* Mat4MulMat34 only sets 3x3 part */ - Mat4MulMat34(premat, temp, mat); + unit_m4(premat); /* Mat4MulMat34 only sets 3x3 part */ + mul_m4_m3m4(premat, temp, mat); - Mat4MulVecfl(mat, curbone->head); - Mat4MulVecfl(mat, curbone->tail); + mul_m4_v3(mat, curbone->head); + mul_m4_v3(mat, curbone->tail); /* Get the postmat */ - VecSubf(delta, curbone->tail, curbone->head); + sub_v3_v3v3(delta, curbone->tail, curbone->head); vec_roll_to_mat3(delta, curbone->roll, temp); - Mat4CpyMat3(postmat, temp); + copy_m4_m3(postmat, temp); /* Find the roll */ - Mat4Invert(imat, premat); - Mat4MulMat4(difmat, postmat, imat); + invert_m4_m4(imat, premat); + mul_m4_m4m4(difmat, postmat, imat); curbone->roll -= (float)atan2(difmat[2][0], difmat[2][2]); } @@ -997,7 +1029,7 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel) free_constraints(&pchan->constraints); /* get rid of unneeded bone */ - BLI_freelinkN(arm->edbo, curbone); + free_edit_bone(arm, curbone); BLI_freelinkN(&ob->pose->chanbase, pchan); } } @@ -1633,19 +1665,20 @@ static EditBone *get_nearest_editbonepoint (ViewContext *vc, short mval[2], List return NULL; } -static void delete_bone(ListBase *edbo, EditBone* exBone) +/* warning, wont clear the active bone */ +static void delete_bone(bArmature *arm, EditBone* exBone) { EditBone *curBone; /* Find any bones that refer to this bone */ - for (curBone=edbo->first;curBone;curBone=curBone->next) { + for (curBone=arm->edbo->first; curBone; curBone=curBone->next) { if (curBone->parent==exBone) { curBone->parent=exBone->parent; curBone->flag &= ~BONE_CONNECTED; } } - - BLI_freelinkN(edbo, exBone); + + free_edit_bone(arm, exBone); } /* context: editmode armature */ @@ -1742,8 +1775,10 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *op) for (curBone=arm->edbo->first;curBone;curBone=next) { next=curBone->next; if (arm->layer & curBone->layer) { - if (curBone->flag & BONE_SELECTED) - delete_bone(arm->edbo, curBone); + if (curBone->flag & BONE_SELECTED) { + if(curBone==arm->act_edbone) arm->act_edbone= NULL; + delete_bone(arm, curBone); + } } } @@ -1795,30 +1830,33 @@ void ED_armature_deselectall(Object *obedit, int toggle, int doundo) } else sel= toggle; - /* Set the flags */ - for (eBone=arm->edbo->first;eBone;eBone=eBone->next) { - if (sel==3) { - /* invert selection of bone */ - if ((arm->layer & eBone->layer) && (eBone->flag & BONE_HIDDEN_A)==0) { - eBone->flag ^= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); - eBone->flag &= ~BONE_ACTIVE; + if(sel==2) { + arm->act_edbone= NULL; + } else { + /* Set the flags */ + for (eBone=arm->edbo->first;eBone;eBone=eBone->next) { + if (sel==3) { + /* invert selection of bone */ + if ((arm->layer & eBone->layer) && (eBone->flag & BONE_HIDDEN_A)==0) { + eBone->flag ^= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); + if(arm->act_edbone==eBone) + arm->act_edbone= NULL; + } } - } - else if (sel==1) { - /* select bone */ - if(arm->layer & eBone->layer && (eBone->flag & BONE_HIDDEN_A)==0) { - eBone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); - if(eBone->parent) - eBone->parent->flag |= (BONE_TIPSEL); + else if (sel==1) { + /* select bone */ + if(arm->layer & eBone->layer && (eBone->flag & BONE_HIDDEN_A)==0) { + eBone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); + if(eBone->parent) + eBone->parent->flag |= (BONE_TIPSEL); + } + } + else { + /* deselect bone */ + eBone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); + if(arm->act_edbone==eBone) + arm->act_edbone= NULL; } - } - else if (sel==2) { - /* clear active flag */ - eBone->flag &= ~(BONE_ACTIVE); - } - else { - /* deselect bone */ - eBone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL | BONE_ACTIVE); } } @@ -1836,7 +1874,7 @@ void mouse_armature(bContext *C, short mval[2], int extend) Object *obedit= CTX_data_edit_object(C); bArmature *arm= obedit->data; ViewContext vc; - EditBone *nearBone = NULL, *ebone; + EditBone *nearBone = NULL; int selmask; view3d_set_viewcontext(C, &vc); @@ -1898,8 +1936,7 @@ void mouse_armature(bContext *C, short mval[2], int extend) if(nearBone) { /* then now check for active status */ - for (ebone=arm->edbo->first;ebone;ebone=ebone->next) ebone->flag &= ~BONE_ACTIVE; - if(nearBone->flag & BONE_SELECTED) nearBone->flag |= BONE_ACTIVE; + if(nearBone->flag & BONE_SELECTED) arm->act_edbone= nearBone; } WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, vc.obedit); @@ -1945,7 +1982,8 @@ void ED_armature_to_edit(Object *ob) ED_armature_edit_free(ob); arm->edbo= MEM_callocN(sizeof(ListBase), "edbo armature"); - make_boneList(arm->edbo, &arm->bonebase,NULL); + arm->act_edbone= make_boneList(arm->edbo, &arm->bonebase, NULL, arm->act_bone); + arm->act_bone= NULL; // BIF_freeTemplates(); /* force template update when entering editmode */ } @@ -1959,16 +1997,16 @@ float ED_rollBoneToVector(EditBone *bone, float new_up_axis[3]) float mat[3][3], nor[3], up_axis[3], vec[3]; float roll; - VecSubf(nor, bone->tail, bone->head); + sub_v3_v3v3(nor, bone->tail, bone->head); vec_roll_to_mat3(nor, 0, mat); VECCOPY(up_axis, mat[2]); - roll = NormalizedVecAngle2(new_up_axis, up_axis); + roll = angle_normalized_v3v3(new_up_axis, up_axis); - Crossf(vec, up_axis, new_up_axis); + cross_v3_v3v3(vec, up_axis, new_up_axis); - if (Inpf(vec, nor) < 0) + if (dot_v3v3(vec, nor) < 0) { roll = -roll; } @@ -1985,21 +2023,21 @@ void auto_align_ebone_zaxisup(Scene *scene, View3D *v3d, EditBone *ebone) float targetmat[3][3], imat[3][3], diffmat[3][3]; /* Find the current bone matrix */ - VecSubf(delta, ebone->tail, ebone->head); + sub_v3_v3v3(delta, ebone->tail, ebone->head); vec_roll_to_mat3(delta, 0.0f, curmat); /* Make new matrix based on y axis & z-up */ VECCOPY(yaxis, curmat[1]); - Mat3One(targetmat); + unit_m3(targetmat); VECCOPY(targetmat[0], xaxis); VECCOPY(targetmat[1], yaxis); VECCOPY(targetmat[2], zaxis); - Mat3Ortho(targetmat); + normalize_m3(targetmat); /* Find the difference between the two matrices */ - Mat3Inv(imat, targetmat); - Mat3MulMat3(diffmat, imat, curmat); + invert_m3_m3(imat, targetmat); + mul_m3_m3m3(diffmat, imat, curmat); // old-method... let's see if using mat3_to_vec_roll is more accurate //ebone->roll = atan2(diffmat[2][0], diffmat[2][2]); @@ -2017,28 +2055,28 @@ void auto_align_ebone_tocursor(Scene *scene, View3D *v3d, EditBone *ebone) float vec[3]; /* find the current bone matrix as a 4x4 matrix (in Armature Space) */ - VecSubf(delta, ebone->tail, ebone->head); + sub_v3_v3v3(delta, ebone->tail, ebone->head); vec_roll_to_mat3(delta, ebone->roll, curmat); - Mat4CpyMat3(mat, curmat); + copy_m4_m3(mat, curmat); VECCOPY(mat[3], ebone->head); /* multiply bone-matrix by object matrix (so that bone-matrix is in WorldSpace) */ - Mat4MulMat4(tmat, mat, obedit->obmat); - Mat4Invert(imat, tmat); + mul_m4_m4m4(tmat, mat, obedit->obmat); + invert_m4_m4(imat, tmat); /* find position of cursor relative to bone */ - VecMat4MulVecfl(vec, imat, cursor); + mul_v3_m4v3(vec, imat, cursor); /* check that cursor is in usable position */ if ((IS_EQ(vec[0], 0)==0) && (IS_EQ(vec[2], 0)==0)) { /* Compute a rotation matrix around y */ rot[1] = (float)atan2(vec[0], vec[2]); rot[0] = rot[2] = 0.0f; - EulToMat4(rot, rmat); + eul_to_mat4( rmat,rot); /* Multiply the bone matrix by rotation matrix. This should be new bone-matrix */ - Mat4MulMat4(tmat, rmat, mat); - Mat3CpyMat4(curmat, tmat); + mul_m4_m4m4(tmat, rmat, mat); + copy_m3_m4(curmat, tmat); /* Now convert from new bone-matrix, back to a roll value (in radians) */ mat3_to_vec_roll(curmat, delta, &ebone->roll); @@ -2103,68 +2141,84 @@ void ARMATURE_OT_calculate_roll(wmOperatorType *ot) /* **************** undo for armatures ************** */ -static void undoBones_to_editBones(void *lbuv, void *lbev) +typedef struct UndoArmature { + EditBone *act_edbone; + ListBase lb; +} UndoArmature; + +static void undoBones_to_editBones(void *uarmv, void *armv) { - ListBase *lbu= lbuv; - ListBase *edbo= lbev; + UndoArmature *uarm= uarmv; + bArmature *arm= armv; EditBone *ebo, *newebo; - BLI_freelistN(edbo); + BLI_freelistN(arm->edbo); /* copy */ - for(ebo= lbu->first; ebo; ebo= ebo->next) { + for(ebo= uarm->lb.first; ebo; ebo= ebo->next) { newebo= MEM_dupallocN(ebo); ebo->temp= newebo; - BLI_addtail(edbo, newebo); + BLI_addtail(arm->edbo, newebo); } + /* active bone */ + if(uarm->act_edbone) { + ebo= uarm->act_edbone; + arm->act_edbone= ebo->temp; + } + /* set pointers */ - for(newebo= edbo->first; newebo; newebo= newebo->next) { + for(newebo= arm->edbo->first; newebo; newebo= newebo->next) { if(newebo->parent) newebo->parent= newebo->parent->temp; } /* be sure they dont hang ever */ - for(newebo= edbo->first; newebo; newebo= newebo->next) { + for(newebo= arm->edbo->first; newebo; newebo= newebo->next) { newebo->temp= NULL; } } -static void *editBones_to_undoBones(void *lbev) +static void *editBones_to_undoBones(void *armv) { - ListBase *edbo= lbev; - ListBase *lb; + bArmature *arm= armv; + UndoArmature *uarm; EditBone *ebo, *newebo; - lb= MEM_callocN(sizeof(ListBase), "listbase undo"); + uarm= MEM_callocN(sizeof(UndoArmature), "listbase undo"); /* copy */ - for(ebo= edbo->first; ebo; ebo= ebo->next) { + for(ebo= arm->edbo->first; ebo; ebo= ebo->next) { newebo= MEM_dupallocN(ebo); ebo->temp= newebo; - BLI_addtail(lb, newebo); + BLI_addtail(&uarm->lb, newebo); } + /* active bone */ + if(arm->act_edbone) { + ebo= arm->act_edbone; + uarm->act_edbone= ebo->temp; + } + /* set pointers */ - for(newebo= lb->first; newebo; newebo= newebo->next) { + for(newebo= uarm->lb.first; newebo; newebo= newebo->next) { if(newebo->parent) newebo->parent= newebo->parent->temp; } - return lb; + return uarm; } -static void free_undoBones(void *lbv) +static void free_undoBones(void *uarmv) { - ListBase *lb= lbv; + UndoArmature *uarm= uarmv; - BLI_freelistN(lb); - MEM_freeN(lb); + BLI_freelistN(&uarm->lb); + MEM_freeN(uarm); } static void *get_armature_edit(bContext *C) { Object *obedit= CTX_data_edit_object(C); if(obedit && obedit->type==OB_ARMATURE) { - bArmature *arm= obedit->data; - return arm->edbo; + return obedit->data; } return NULL; } @@ -2224,16 +2278,16 @@ void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d) VECCOPY(curs, give_cursor(scene, v3d)); /* Get inverse point for head and orientation for tail */ - Mat4Invert(obedit->imat, obedit->obmat); - Mat4MulVecfl(obedit->imat, curs); + invert_m4_m4(obedit->imat, obedit->obmat); + mul_m4_v3(obedit->imat, curs); if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) - Mat3CpyMat4(obmat, rv3d->viewmat); - else Mat3One(obmat); + copy_m3_m4(obmat, rv3d->viewmat); + else unit_m3(obmat); - Mat3CpyMat4(viewmat, obedit->obmat); - Mat3MulMat3(totmat, obmat, viewmat); - Mat3Inv(imat, totmat); + copy_m3_m4(viewmat, obedit->obmat); + mul_m3_m3m3(totmat, obmat, viewmat); + invert_m3_m3(imat, totmat); ED_armature_deselectall(obedit, 0, 0); @@ -2243,9 +2297,9 @@ void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d) VECCOPY(bone->head, curs); if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) - VecAddf(bone->tail, bone->head, imat[1]); // bone with unit length 1 + add_v3_v3v3(bone->tail, bone->head, imat[1]); // bone with unit length 1 else - VecAddf(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z + add_v3_v3v3(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z } @@ -2270,7 +2324,7 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *op) /* find the active or selected bone */ for (ebone = arm->edbo->first; ebone; ebone=ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & (BONE_ACTIVE|BONE_TIPSEL)) + if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone) break; } } @@ -2278,7 +2332,7 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *op) if (ebone==NULL) { for (ebone = arm->edbo->first; ebone; ebone=ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & (BONE_ACTIVE|BONE_ROOTSEL)) + if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone) break; } } @@ -2305,7 +2359,7 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *op) } newbone= add_editbone(obedit, ebone->name); - newbone->flag |= BONE_ACTIVE; + arm->act_edbone= newbone; if (to_root) { VECCOPY(newbone->head, ebone->head); @@ -2321,16 +2375,16 @@ static int armature_click_extrude_exec(bContext *C, wmOperator *op) curs= give_cursor(scene, v3d); VECCOPY(newbone->tail, curs); - VecSubf(newbone->tail, newbone->tail, obedit->obmat[3]); + sub_v3_v3v3(newbone->tail, newbone->tail, obedit->obmat[3]); if (a==1) newbone->tail[0]= -newbone->tail[0]; - Mat3CpyMat4(mat, obedit->obmat); - Mat3Inv(imat, mat); - Mat3MulVecfl(imat, newbone->tail); + copy_m3_m4(mat, obedit->obmat); + invert_m3_m3(imat, mat); + mul_m3_v3(imat, newbone->tail); - newbone->length= VecLenf(newbone->head, newbone->tail); + newbone->length= len_v3v3(newbone->head, newbone->tail); newbone->rad_tail= newbone->length*0.05f; newbone->dist= newbone->length*0.25f; @@ -2375,7 +2429,7 @@ static int armature_click_extrude_invoke(bContext *C, wmOperator *op, wmEvent *e if(mval[0]!=IS_CLIPPED) { window_to_3d_delta(ar, dvec, mval[0]-mx, mval[1]-my); - VecSubf(fp, fp, dvec); + sub_v3_v3v3(fp, fp, dvec); } else { @@ -2635,7 +2689,7 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) BLI_addtail(arm->edbo, eBone); if (!firstDup) firstDup=eBone; - + /* Lets duplicate the list of constraints that the * current bone has. */ @@ -2719,12 +2773,21 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op) } } + /* correct the active bone */ + if(arm->act_edbone) { + eBone= arm->act_edbone; + if(eBone->temp) + arm->act_edbone= eBone->temp; + } + /* Deselect the old bones and select the new ones */ for (curBone=arm->edbo->first; curBone && curBone!=firstDup; curBone=curBone->next) { if (EBONE_VISIBLE(arm, curBone)) - curBone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL | BONE_ACTIVE); + curBone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); } + ED_armature_validate_active(arm); + WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, obedit); return OPERATOR_FINISHED; @@ -2822,7 +2885,7 @@ static void fill_add_joint (EditBone *ebo, short eb_tail, ListBase *points) } for (ebp= points->first; ebp; ebp= ebp->next) { - if (VecEqual(ebp->vec, vec)) { + if (equals_v3v3(ebp->vec, vec)) { if (eb_tail) { if ((ebp->head_owner) && (ebp->head_owner->parent == ebo)) { /* so this bone's tail owner is this bone */ @@ -2906,8 +2969,8 @@ static int armature_fill_bones_exec (bContext *C, wmOperator *op) fp= give_cursor(scene, v3d); VECCOPY (curs, fp); - Mat4Invert(obedit->imat, obedit->obmat); - Mat4MulVecfl(obedit->imat, curs); + invert_m4_m4(obedit->imat, obedit->obmat); + mul_m4_v3(obedit->imat, curs); /* Create a bone */ newbone= add_points_bone(obedit, ebp->vec, curs); @@ -2942,14 +3005,14 @@ static int armature_fill_bones_exec (bContext *C, wmOperator *op) /* get cursor location */ VECCOPY(curs, fp); - Mat4Invert(obedit->imat, obedit->obmat); - Mat4MulVecfl(obedit->imat, curs); + invert_m4_m4(obedit->imat, obedit->obmat); + mul_m4_v3(obedit->imat, curs); /* get distances */ - VecSubf(vecA, ebp->vec, curs); - VecSubf(vecB, ebp2->vec, curs); - distA= VecLength(vecA); - distB= VecLength(vecB); + sub_v3_v3v3(vecA, ebp->vec, curs); + sub_v3_v3v3(vecB, ebp2->vec, curs); + distA= len_v3(vecA); + distB= len_v3(vecB); /* compare distances - closer one therefore acts as direction for bone to go */ headtail= (distA < distB) ? 2 : 1; @@ -3046,13 +3109,13 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone * - tail = head/tail of end (default tail) * - parent = parent of start */ - if ((start->flag & BONE_TIPSEL) && !(start->flag & (BONE_SELECTED|BONE_ACTIVE))) { + if ((start->flag & BONE_TIPSEL) && ((start->flag & BONE_SELECTED) || start==arm->act_edbone)==0) { VECCOPY(head, start->tail); } else { VECCOPY(head, start->head); } - if ((end->flag & BONE_ROOTSEL) && !(end->flag & (BONE_SELECTED|BONE_ACTIVE))) { + if ((end->flag & BONE_ROOTSEL) && ((end->flag & BONE_SELECTED) || end==arm->act_edbone)==0) { VECCOPY(tail, end->head); } else { @@ -3090,7 +3153,7 @@ static void bones_merge(Object *obedit, EditBone *start, EditBone *end, EditBone /* step 3: delete all bones between and including start and end */ for (ebo= end; ebo; ebo= ebone) { ebone= (ebo == start) ? (NULL) : (ebo->parent); - BLI_freelinkN(arm->edbo, ebo); + free_edit_bone(arm, ebo); } } @@ -3130,7 +3193,7 @@ static int armature_merge_exec (bContext *C, wmOperator *op) /* check if visible + selected */ if ( EBONE_VISIBLE(arm, ebo) && ((ebo->flag & BONE_CONNECTED) || (ebo->parent==NULL)) && - (ebo->flag & (BONE_SELECTED|BONE_ACTIVE)) ) + ((ebo->flag & BONE_SELECTED) || (ebo==arm->act_edbone)) ) { /* set either end or start (end gets priority, unless it is already set) */ if (bend == NULL) { @@ -3205,17 +3268,20 @@ void hide_selected_armature_bones(Scene *scene) for (ebone = arm->edbo->first; ebone; ebone=ebone->next) { if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & (BONE_SELECTED)) { - ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); + if (ebone->flag & BONE_SELECTED) { + ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL); ebone->flag |= BONE_HIDDEN_A; } } } + ED_armature_validate_active(arm); ED_armature_sync_selection(arm->edbo); BIF_undo_push("Hide Bones"); } -void hide_unselected_armature_bones(Scene *scene) + +#if 0 // remove this? +static void hide_unselected_armature_bones(Scene *scene) { Object *obedit= scene->obedit; // XXX get from context bArmature *arm= obedit->data; @@ -3226,15 +3292,18 @@ void hide_unselected_armature_bones(Scene *scene) if (EBONE_VISIBLE(arm, ebone)) { if (ebone->flag & (BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL)); else { - ebone->flag &= ~BONE_ACTIVE; ebone->flag |= BONE_HIDDEN_A; } } } + + ED_armature_validate_active(arm); ED_armature_sync_selection(arm->edbo); BIF_undo_push("Hide Unselected Bones"); } +#endif +#if 0 // remove this? void show_all_armature_bones(Scene *scene) { Object *obedit= scene->obedit; // XXX get from context @@ -3249,9 +3318,11 @@ void show_all_armature_bones(Scene *scene) } } } + ED_armature_validate_active(arm); ED_armature_sync_selection(arm->edbo); BIF_undo_push("Reveal Bones"); } +#endif /* previously extrude_armature */ /* context; editmode armature */ @@ -3301,7 +3372,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) forked= 0; // we extrude 2 different bones if (flipbone->flag & (BONE_TIPSEL|BONE_ROOTSEL|BONE_SELECTED)) /* don't want this bone to be selected... */ - flipbone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); + flipbone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL); } if ((flipbone==NULL) && (forked)) flipbone= ebone; @@ -3373,14 +3444,17 @@ static int armature_extrude_exec(bContext *C, wmOperator *op) } /* Deselect the old bone */ - ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); + ebone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL); } } /* if only one bone, make this one active */ - if (totbone==1 && first) first->flag |= BONE_ACTIVE; + if (totbone==1 && first) arm->act_edbone= first; if (totbone==0) return OPERATOR_CANCELLED; + if(arm->act_edbone && (((EditBone *)arm->act_edbone)->flag & BONE_SELECTED)==0) + arm->act_edbone= NULL; + /* Transform the endpoints */ ED_armature_sync_selection(arm->edbo); @@ -3420,16 +3494,16 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) VECCOPY(curs, give_cursor(CTX_data_scene(C),CTX_wm_view3d(C))); /* Get inverse point for head and orientation for tail */ - Mat4Invert(obedit->imat, obedit->obmat); - Mat4MulVecfl(obedit->imat, curs); + invert_m4_m4(obedit->imat, obedit->obmat); + mul_m4_v3(obedit->imat, curs); if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) - Mat3CpyMat4(obmat, rv3d->viewmat); - else Mat3One(obmat); + copy_m3_m4(obmat, rv3d->viewmat); + else unit_m3(obmat); - Mat3CpyMat4(viewmat, obedit->obmat); - Mat3MulMat3(totmat, obmat, viewmat); - Mat3Inv(imat, totmat); + copy_m3_m4(viewmat, obedit->obmat); + mul_m3_m3m3(totmat, obmat, viewmat); + invert_m3_m3(imat, totmat); ED_armature_deselectall(obedit, 0, 0); @@ -3439,9 +3513,9 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op) VECCOPY(bone->head, curs); if(rv3d && (U.flag & USER_ADD_VIEWALIGNED)) - VecAddf(bone->tail, bone->head, imat[1]); // bone with unit length 1 + add_v3_v3v3(bone->tail, bone->head, imat[1]); // bone with unit length 1 else - VecAddf(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z + add_v3_v3v3(bone->tail, bone->head, imat[2]); // bone with unit length 1, pointing up Z /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, obedit); @@ -3674,7 +3748,7 @@ static int armature_switch_direction_exec(bContext *C, wmOperator *op) * - connected flag is only set if points are coincidental */ ebo->parent= child; - if ((child) && VecEqual(ebo->head, child->tail)) + if ((child) && equals_v3v3(ebo->head, child->tail)) ebo->flag |= BONE_CONNECTED; else ebo->flag &= ~BONE_CONNECTED; @@ -3760,12 +3834,12 @@ static void bone_connect_to_new_parent(ListBase *edbo, EditBone *selbone, EditBo if (mode == ARM_PAR_CONNECT) { /* Connected: Child bones will be moved to the parent tip */ selbone->flag |= BONE_CONNECTED; - VecSubf(offset, actbone->tail, selbone->head); + sub_v3_v3v3(offset, actbone->tail, selbone->head); VECCOPY(selbone->head, actbone->tail); selbone->rad_head= actbone->rad_tail; - VecAddf(selbone->tail, selbone->tail, offset); + add_v3_v3v3(selbone->tail, selbone->tail, offset); /* offset for all its children */ for (ebone = edbo->first; ebone; ebone=ebone->next) { @@ -3773,8 +3847,8 @@ static void bone_connect_to_new_parent(ListBase *edbo, EditBone *selbone, EditBo for (par= ebone->parent; par; par= par->parent) { if (par==selbone) { - VecAddf(ebone->head, ebone->head, offset); - VecAddf(ebone->tail, ebone->tail, offset); + add_v3_v3v3(ebone->head, ebone->head, offset); + add_v3_v3v3(ebone->tail, ebone->tail, offset); break; } } @@ -3965,7 +4039,6 @@ static int armature_select_inverse_exec(bContext *C, wmOperator *op) if ((ebone->flag & BONE_UNSELECTABLE) == 0) { /* select bone */ ebone->flag ^= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); - ebone->flag &= ~BONE_ACTIVE; } } CTX_DATA_END; @@ -4009,7 +4082,7 @@ static int armature_de_select_all_exec(bContext *C, wmOperator *op) } else { /* deselect bone */ - ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL | BONE_ACTIVE); + ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); } } } @@ -4053,17 +4126,17 @@ static int armature_select_hierarchy_exec(bContext *C, wmOperator *op) for (curbone= arm->edbo->first; curbone; curbone= curbone->next) { /* only work on bone if it is visible and its selection can change */ if (EBONE_VISIBLE(arm, curbone) && (curbone->flag & BONE_UNSELECTABLE)==0) { - if (curbone->flag & (BONE_ACTIVE)) { + if (curbone == arm->act_edbone) { if (direction == BONE_SELECT_PARENT) { if (curbone->parent == NULL) continue; else pabone = curbone->parent; if (EBONE_VISIBLE(arm, pabone)) { - pabone->flag |= (BONE_ACTIVE|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + pabone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_edbone= pabone; if (pabone->parent) pabone->parent->flag |= BONE_TIPSEL; if (!add_to_sel) curbone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - curbone->flag &= ~BONE_ACTIVE; break; } @@ -4073,13 +4146,13 @@ static int armature_select_hierarchy_exec(bContext *C, wmOperator *op) if (chbone == NULL) continue; if (EBONE_VISIBLE(arm, chbone) && (chbone->flag & BONE_UNSELECTABLE)==0) { - chbone->flag |= (BONE_ACTIVE|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + chbone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_edbone= chbone; if (!add_to_sel) { curbone->flag &= ~(BONE_SELECTED|BONE_ROOTSEL); if (curbone->parent) curbone->parent->flag &= ~BONE_TIPSEL; } - curbone->flag &= ~BONE_ACTIVE; break; } } @@ -4126,13 +4199,13 @@ static void fix_connected_bone(EditBone *ebone) { float diff[3]; - if (!(ebone->parent) || !(ebone->flag & BONE_CONNECTED) || VecEqual(ebone->parent->tail, ebone->head)) + if (!(ebone->parent) || !(ebone->flag & BONE_CONNECTED) || equals_v3v3(ebone->parent->tail, ebone->head)) return; /* if the parent has moved we translate child's head and tail accordingly*/ - VecSubf(diff, ebone->parent->tail, ebone->head); - VecAddf(ebone->head, ebone->head, diff); - VecAddf(ebone->tail, ebone->tail, diff); + sub_v3_v3v3(diff, ebone->parent->tail, ebone->head); + add_v3_v3v3(ebone->head, ebone->head, diff); + add_v3_v3v3(ebone->tail, ebone->tail, diff); return; } @@ -4154,14 +4227,14 @@ static void bone_align_to_bone(ListBase *edbo, EditBone *selbone, EditBone *actb { float selboneaxis[3], actboneaxis[3], length; - VecSubf(actboneaxis, actbone->tail, actbone->head); - Normalize(actboneaxis); + sub_v3_v3v3(actboneaxis, actbone->tail, actbone->head); + normalize_v3(actboneaxis); - VecSubf(selboneaxis, selbone->tail, selbone->head); - length = VecLength(selboneaxis); + sub_v3_v3v3(selboneaxis, selbone->tail, selbone->head); + length = len_v3(selboneaxis); - VecMulf(actboneaxis, length); - VecAddf(selbone->tail, selbone->head, actboneaxis); + mul_v3_fl(actboneaxis, length); + add_v3_v3v3(selbone->tail, selbone->head, actboneaxis); selbone->roll = actbone->roll; /* if the bone being aligned has connected descendants they must be moved @@ -4256,14 +4329,6 @@ void ARMATURE_OT_align(wmOperatorType *ot) /* ***************** Pose tools ********************* */ -/* helper for function below */ -static int clear_active_flag(Object *ob, Bone *bone, void *data) -{ - bone->flag &= ~BONE_ACTIVE; - return 0; -} - - // XXX bone_looper is only to be used when we want to access settings (i.e. editability/visibility/selected) that context doesn't offer static int bone_looper(Object *ob, Bone *bone, void *data, int (*bone_func)(Object *, Bone *, void *)) @@ -4310,7 +4375,8 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ if (!(extend) || (base != scene->basact)) { ED_pose_deselectall(ob, 0, 0); - nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); + nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_bone= nearBone; // XXX old cruft! use notifiers instead //select_actionchannel_by_name(ob->action, nearBone->name, 1); @@ -4318,21 +4384,19 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor else { if (nearBone->flag & BONE_SELECTED) { /* if not active, we make it active */ - if((nearBone->flag & BONE_ACTIVE)==0) { - bone_looper(ob, arm->bonebase.first, NULL, clear_active_flag); - nearBone->flag |= BONE_ACTIVE; + if(nearBone != arm->act_bone) { + arm->act_bone= nearBone; } else { - nearBone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); + nearBone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); // XXX old cruft! use notifiers instead //select_actionchannel_by_name(ob->action, nearBone->name, 0); } } else { - bone_looper(ob, arm->bonebase.first, NULL, clear_active_flag); - - nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); + nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + arm->act_bone= nearBone; // XXX old cruft! use notifiers instead //select_actionchannel_by_name(ob->action, nearBone->name, 1); @@ -4341,7 +4405,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor /* in weightpaint we select the associated vertex group too */ if (OBACT && OBACT->mode & OB_MODE_WEIGHT_PAINT) { - if (nearBone->flag & BONE_ACTIVE) { + if (nearBone == arm->act_bone) { ED_vgroup_select_by_name(OBACT, nearBone->name); DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA); } @@ -4387,16 +4451,17 @@ void ED_pose_deselectall (Object *ob, int test, int doundo) if ((pchan->bone->layer & arm->layer) && !(pchan->bone->flag & (BONE_HIDDEN_P|BONE_UNSELECTABLE))) { if (test==3) { pchan->bone->flag ^= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - pchan->bone->flag &= ~BONE_ACTIVE; } else { - if (selectmode==0) pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); + if (selectmode==0) pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); else if (selectmode==1) pchan->bone->flag |= BONE_SELECTED; - else pchan->bone->flag &= ~BONE_ACTIVE; } } } + if(arm->act_bone && (arm->act_bone->flag & BONE_SELECTED)==0) + arm->act_bone= NULL; + //countall(); // XXX need an equivalent to this... if (doundo) { @@ -4655,10 +4720,10 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m /* compute root and tip */ if (bbone) { VECCOPY(root[j], bbone[segments].mat[3]); - Mat4MulVecfl(bone->arm_mat, root[j]); + mul_m4_v3(bone->arm_mat, root[j]); if ((segments+1) < bone->segments) { VECCOPY(tip[j], bbone[segments+1].mat[3]) - Mat4MulVecfl(bone->arm_mat, tip[j]); + mul_m4_v3(bone->arm_mat, tip[j]); } else VECCOPY(tip[j], bone->arm_tail) @@ -4668,8 +4733,8 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m VECCOPY(tip[j], bone->arm_tail); } - Mat4MulVecfl(par->obmat, root[j]); - Mat4MulVecfl(par->obmat, tip[j]); + mul_m4_v3(par->obmat, root[j]); + mul_m4_v3(par->obmat, tip[j]); /* set selected */ if (wpmode) { @@ -4723,7 +4788,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m for (i=0; i < mesh->totvert; i++) { if (!vertsfilled) VECCOPY(verts[i], mesh->mvert[i].co) - Mat4MulVecfl(ob->obmat, verts[i]); + mul_m4_v3(ob->obmat, verts[i]); } /* compute the weights based on gathered vertices and bones */ @@ -4733,7 +4798,7 @@ void add_verts_to_dgroups(Scene *scene, Object *ob, Object *par, int heat, int m } else { envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist, - dgroupflip, root, tip, selected, Mat4ToScalef(par->obmat)); + dgroupflip, root, tip, selected, mat4_to_scale(par->obmat)); } /* free the memory allocated */ @@ -4904,10 +4969,10 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op) if (pchan->rotmode == ROT_MODE_QUAT) { QUATCOPY(quat1, pchan->quat); - QuatToEul(pchan->quat, oldeul); + quat_to_eul( oldeul,pchan->quat); } else if (pchan->rotmode == ROT_MODE_AXISANGLE) { - AxisAngleToEulO(pchan->rotAxis, pchan->rotAngle, oldeul, EULER_ORDER_DEFAULT); + axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,pchan->rotAxis, pchan->rotAngle); } else { VECCOPY(oldeul, pchan->eul); @@ -4923,14 +4988,14 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op) eul[2]= oldeul[2]; if (pchan->rotmode == ROT_MODE_QUAT) { - EulToQuat(eul, pchan->quat); + eul_to_quat( pchan->quat,eul); /* quaternions flip w sign to accumulate rotations correctly */ if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) { - QuatMulf(pchan->quat, -1.0f); + mul_qt_fl(pchan->quat, -1.0f); } } else if (pchan->rotmode == ROT_MODE_AXISANGLE) { - EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, pchan->rotAxis, &pchan->rotAngle); + eulO_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,eul, EULER_ORDER_DEFAULT); } else { VECCOPY(pchan->eul, eul); @@ -4990,7 +5055,6 @@ static int pose_select_inverse_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pchans) { if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) { pchan->bone->flag ^= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - pchan->bone->flag &= ~BONE_ACTIVE; } } CTX_DATA_END; @@ -5026,12 +5090,13 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) /* Set the flags */ CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pchans) { /* select pchan only if selectable, but deselect works always */ - if (sel==0) - pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL|BONE_ACTIVE); + if (sel==0) { + pchan->bone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + } else if ((pchan->bone->flag & BONE_UNSELECTABLE)==0) pchan->bone->flag |= BONE_SELECTED; } - CTX_DATA_END; + CTX_DATA_END; WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, NULL); @@ -5062,11 +5127,11 @@ static int pose_select_parent_exec(bContext *C, wmOperator *op) /* Determine if there is an active bone */ pchan=CTX_data_active_pchan(C); if (pchan) { + bArmature *arm= ob->data; parent=pchan->parent; if ((parent) && !(parent->bone->flag & (BONE_HIDDEN_P|BONE_UNSELECTABLE))) { parent->bone->flag |= BONE_SELECTED; - parent->bone->flag |= BONE_ACTIVE; - pchan->bone->flag &= ~BONE_ACTIVE; + arm->act_bone= parent->bone; } else { return OPERATOR_CANCELLED; @@ -5105,7 +5170,8 @@ static int hide_selected_pose_bone(Object *ob, Bone *bone, void *ptr) if (arm->layer & bone->layer) { if (bone->flag & BONE_SELECTED) { bone->flag |= BONE_HIDDEN_P; - bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); + if(arm->act_bone==bone) + arm->act_bone= NULL; } } return 0; @@ -5117,9 +5183,10 @@ static int hide_unselected_pose_bone(Object *ob, Bone *bone, void *ptr) if (arm->layer & bone->layer) { // hrm... typo here? - if (~bone->flag & BONE_SELECTED) { + if ((bone->flag & BONE_SELECTED)==0) { bone->flag |= BONE_HIDDEN_P; - bone->flag &= ~BONE_ACTIVE; + if(arm->act_bone==bone) + arm->act_bone= NULL; } } return 0; @@ -5551,13 +5618,13 @@ EditBone * subdivideByAngle(Scene *scene, Object *obedit, ReebArc *arc, ReebNode current = iter->p; - VecSubf(vec1, previous, parent->head); - VecSubf(vec2, current, previous); + sub_v3_v3v3(vec1, previous, parent->head); + sub_v3_v3v3(vec2, current, previous); - len1 = Normalize(vec1); - len2 = Normalize(vec2); + len1 = normalize_v3(vec1); + len2 = normalize_v3(vec2); - if (len1 > 0.0f && len2 > 0.0f && Inpf(vec1, vec2) < angleLimit) + if (len1 > 0.0f && len2 > 0.0f && dot_v3v3(vec1, vec2) < angleLimit) { VECCOPY(parent->tail, previous); @@ -5576,7 +5643,8 @@ EditBone * subdivideByAngle(Scene *scene, Object *obedit, ReebArc *arc, ReebNode * */ if (parent == root) { - delete_bone(arm->edbo, parent); + if(parent==arm->act_edbone) arm->act_edbone= NULL; + delete_bone(arm, parent); parent = NULL; } @@ -5617,18 +5685,18 @@ float arcLengthRatio(ReebArc *arc) float embedLength = 0.0f; int i; - arcLength = VecLenf(arc->head->p, arc->tail->p); + arcLength = len_v3v3(arc->head->p, arc->tail->p); if (arc->bcount > 0) { /* Add the embedding */ for ( i = 1; i < arc->bcount; i++) { - embedLength += VecLenf(arc->buckets[i - 1].p, arc->buckets[i].p); + embedLength += len_v3v3(arc->buckets[i - 1].p, arc->buckets[i].p); } /* Add head and tail -> embedding vectors */ - embedLength += VecLenf(arc->head->p, arc->buckets[0].p); - embedLength += VecLenf(arc->tail->p, arc->buckets[arc->bcount - 1].p); + embedLength += len_v3v3(arc->head->p, arc->buckets[0].p); + embedLength += len_v3v3(arc->tail->p, arc->buckets[arc->bcount - 1].p); } else { @@ -5688,8 +5756,8 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg) /* Copy orientation from source */ VECCOPY(dst->loc, src->obmat[3]); - Mat4ToEul(src->obmat, dst->rot); - Mat4ToSize(src->obmat, dst->size); + mat4_to_eul( dst->rot,src->obmat); + mat4_to_size( dst->size,src->obmat); where_is_object(scene, obedit); diff --git a/source/blender/editors/armature/editarmature_generate.c b/source/blender/editors/armature/editarmature_generate.c index d327ed34839..124528811c7 100644 --- a/source/blender/editors/armature/editarmature_generate.c +++ b/source/blender/editors/armature/editarmature_generate.c @@ -39,7 +39,7 @@ #include "DNA_armature_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_graph.h" #include "BKE_utildefines.h" @@ -52,18 +52,18 @@ void setBoneRollFromNormal(EditBone *bone, float *no, float invmat[][4], float tmat[][3]) { - if (no != NULL && !VecIsNull(no)) + if (no != NULL && !is_zero_v3(no)) { float tangent[3], vec[3], normal[3]; VECCOPY(normal, no); - Mat3MulVecfl(tmat, normal); + mul_m3_v3(tmat, normal); - VecSubf(tangent, bone->tail, bone->head); - Projf(vec, tangent, normal); - VecSubf(normal, normal, vec); + sub_v3_v3v3(tangent, bone->tail, bone->head); + project_v3_v3v3(vec, tangent, normal); + sub_v3_v3v3(normal, normal, vec); - Normalize(normal); + normalize_v3(normal); bone->roll = ED_rollBoneToVector(bone, normal); } @@ -86,11 +86,11 @@ float calcArcCorrelation(BArcIterator *iter, int start, int end, float v0[3], fl float v[3]; IT_peek(iter, i); - VecSubf(v, iter->p, v0); - avg_t += Inpf(v, n); + sub_v3_v3v3(v, iter->p, v0); + avg_t += dot_v3v3(v, n); } - avg_t /= Inpf(n, n); + avg_t /= dot_v3v3(n, n); avg_t += 1.0f; /* adding start (0) and end (1) values */ avg_t /= len; @@ -101,14 +101,14 @@ float calcArcCorrelation(BArcIterator *iter, int start, int end, float v0[3], fl float dt; IT_peek(iter, i); - VecSubf(v, iter->p, v0); - Projf(d, v, n); - VecSubf(v, v, d); + sub_v3_v3v3(v, iter->p, v0); + project_v3_v3v3(d, v, n); + sub_v3_v3v3(v, v, d); - dt = VecLength(d) - avg_t; + dt = len_v3(d) - avg_t; s_t += dt * dt; - s_xyz += Inpf(v, v); + s_xyz += dot_v3v3(v, v); } /* adding start(0) and end(1) values to s_t */ @@ -143,7 +143,7 @@ int nextFixedSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int sta IT_peek(iter, i); v2 = iter->p; - stroke_length += VecLenf(v1, v2); + stroke_length += len_v3v3(v1, v2); v1 = v2; } @@ -165,7 +165,7 @@ int nextFixedSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int sta IT_peek(iter, i); v2 = iter->p; - current_length += VecLenf(v1, v2); + current_length += len_v3v3(v1, v2); if (current_length >= length_threshold) { @@ -194,7 +194,7 @@ int nextAdaptativeSubdivision(ToolSettings *toolsettings, BArcIterator *iter, in { /* Calculate normal */ IT_peek(iter, i); - VecSubf(n, iter->p, head); + sub_v3_v3v3(n, iter->p, head); if (calcArcCorrelation(iter, start, i, start_p, n) < correlation_threshold) { @@ -226,7 +226,7 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st vec1 = iter->p; /* If lengthLimit hits the current segment */ - if (VecLenf(vec1, head) > lengthLimit) + if (len_v3v3(vec1, head) > lengthLimit) { if (same == 0) { @@ -234,13 +234,13 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st float a, b, c, f; /* Solve quadratic distance equation */ - VecSubf(dv, vec1, vec0); - a = Inpf(dv, dv); + sub_v3_v3v3(dv, vec1, vec0); + a = dot_v3v3(dv, dv); - VecSubf(off, vec0, head); - b = 2 * Inpf(dv, off); + sub_v3_v3v3(off, vec0, head); + b = 2 * dot_v3v3(dv, off); - c = Inpf(off, off) - (lengthLimit * lengthLimit); + c = dot_v3v3(off, off) - (lengthLimit * lengthLimit); f = (-b + (float)sqrt(b * b - 4 * a * c)) / (2 * a); @@ -249,8 +249,8 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st if (isnan(f) == 0 && f < 1.0f) { VECCOPY(p, dv); - VecMulf(p, f); - VecAddf(p, p, vec0); + mul_v3_fl(p, f); + add_v3_v3v3(p, p, vec0); } else { @@ -261,12 +261,12 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st { float dv[3]; - VecSubf(dv, vec1, vec0); - Normalize(dv); + sub_v3_v3v3(dv, vec1, vec0); + normalize_v3(dv); VECCOPY(p, dv); - VecMulf(p, lengthLimit); - VecAddf(p, p, head); + mul_v3_fl(p, lengthLimit); + add_v3_v3v3(p, p, head); } return i - 1; /* restart at lower bound */ @@ -321,8 +321,8 @@ EditBone * subdivideArcBy(ToolSettings *toolsettings, bArmature *arm, ListBase * } /* going to next bone, fix parent */ - Mat4MulVecfl(invmat, parent->tail); - Mat4MulVecfl(invmat, parent->head); + mul_m4_v3(invmat, parent->tail); + mul_m4_v3(invmat, parent->head); setBoneRollFromNormal(parent, normal, invmat, tmat); parent = child; // new child is next parent @@ -342,8 +342,8 @@ EditBone * subdivideArcBy(ToolSettings *toolsettings, bArmature *arm, ListBase * } /* fix last bone */ - Mat4MulVecfl(invmat, parent->tail); - Mat4MulVecfl(invmat, parent->head); + mul_m4_v3(invmat, parent->tail); + mul_m4_v3(invmat, parent->head); setBoneRollFromNormal(parent, iter->no, invmat, tmat); lastBone = parent; diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index 4d65059c4c6..946b7398773 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -48,7 +48,7 @@ #include "DNA_view3d_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_ghash.h" #include "BLI_graph.h" @@ -162,7 +162,7 @@ void getEditBoneRollUpAxis(EditBone *bone, float roll, float up_axis[3]) { float mat[3][3], nor[3]; - VecSubf(nor, bone->tail, bone->head); + sub_v3_v3v3(nor, bone->tail, bone->head); vec_roll_to_mat3(nor, roll, mat); VECCOPY(up_axis, mat[2]); @@ -173,35 +173,35 @@ float rollBoneByQuatAligned(EditBone *bone, float old_up_axis[3], float qrot[4], float nor[3], new_up_axis[3], x_axis[3], z_axis[3]; VECCOPY(new_up_axis, old_up_axis); - QuatMulVecf(qrot, new_up_axis); + mul_qt_v3(qrot, new_up_axis); - VecSubf(nor, bone->tail, bone->head); + sub_v3_v3v3(nor, bone->tail, bone->head); - Crossf(x_axis, nor, aligned_axis); - Crossf(z_axis, x_axis, nor); + cross_v3_v3v3(x_axis, nor, aligned_axis); + cross_v3_v3v3(z_axis, x_axis, nor); - Normalize(new_up_axis); - Normalize(x_axis); - Normalize(z_axis); + normalize_v3(new_up_axis); + normalize_v3(x_axis); + normalize_v3(z_axis); - if (Inpf(new_up_axis, x_axis) < 0) + if (dot_v3v3(new_up_axis, x_axis) < 0) { - VecMulf(x_axis, -1); + mul_v3_fl(x_axis, -1); } - if (Inpf(new_up_axis, z_axis) < 0) + if (dot_v3v3(new_up_axis, z_axis) < 0) { - VecMulf(z_axis, -1); + mul_v3_fl(z_axis, -1); } - if (NormalizedVecAngle2(x_axis, new_up_axis) < NormalizedVecAngle2(z_axis, new_up_axis)) + if (angle_normalized_v3v3(x_axis, new_up_axis) < angle_normalized_v3v3(z_axis, new_up_axis)) { - RotationBetweenVectorsToQuat(qroll, new_up_axis, x_axis); /* set roll rotation quat */ + rotation_between_vecs_to_quat(qroll, new_up_axis, x_axis); /* set roll rotation quat */ return ED_rollBoneToVector(bone, x_axis); } else { - RotationBetweenVectorsToQuat(qroll, new_up_axis, z_axis); /* set roll rotation quat */ + rotation_between_vecs_to_quat(qroll, new_up_axis, z_axis); /* set roll rotation quat */ return ED_rollBoneToVector(bone, z_axis); } } @@ -220,11 +220,11 @@ float rollBoneByQuatJoint(RigEdge *edge, RigEdge *previous, float qrot[4], float if (previous->bone) { - VecSubf(vec_first, previous->bone->tail, previous->bone->head); + sub_v3_v3v3(vec_first, previous->bone->tail, previous->bone->head); } else if (previous->prev->bone) { - VecSubf(vec_first, edge->bone->head, previous->prev->bone->tail); + sub_v3_v3v3(vec_first, edge->bone->head, previous->prev->bone->tail); } else { @@ -232,25 +232,25 @@ float rollBoneByQuatJoint(RigEdge *edge, RigEdge *previous, float qrot[4], float return rollBoneByQuatAligned(edge->bone, edge->up_axis, qrot, qroll, up_axis); } - VecSubf(vec_second, edge->bone->tail, edge->bone->head); + sub_v3_v3v3(vec_second, edge->bone->tail, edge->bone->head); - Normalize(vec_first); - Normalize(vec_second); + normalize_v3(vec_first); + normalize_v3(vec_second); - Crossf(normal, vec_first, vec_second); - Normalize(normal); + cross_v3_v3v3(normal, vec_first, vec_second); + normalize_v3(normal); - AxisAngleToQuat(qroll, vec_second, edge->up_angle); + axis_angle_to_quat(qroll, vec_second, edge->up_angle); - QuatMulVecf(qroll, normal); + mul_qt_v3(qroll, normal); VECCOPY(new_up_axis, edge->up_axis); - QuatMulVecf(qrot, new_up_axis); + mul_qt_v3(qrot, new_up_axis); - Normalize(new_up_axis); + normalize_v3(new_up_axis); /* real qroll between normal and up_axis */ - RotationBetweenVectorsToQuat(qroll, new_up_axis, normal); + rotation_between_vecs_to_quat(qroll, new_up_axis, normal); return ED_rollBoneToVector(edge->bone, normal); } @@ -261,9 +261,9 @@ float rollBoneByQuat(EditBone *bone, float old_up_axis[3], float qrot[4]) float new_up_axis[3]; VECCOPY(new_up_axis, old_up_axis); - QuatMulVecf(qrot, new_up_axis); + mul_qt_v3(qrot, new_up_axis); - Normalize(new_up_axis); + normalize_v3(new_up_axis); return ED_rollBoneToVector(bone, new_up_axis); } @@ -431,7 +431,7 @@ static void RIG_appendEdgeToArc(RigArc *arc, RigEdge *edge) RIG_calculateEdgeAngles(last_edge, edge); } - edge->length = VecLenf(edge->head, edge->tail); + edge->length = len_v3v3(edge->head, edge->tail); arc->length += edge->length; @@ -509,7 +509,7 @@ static RigControl *cloneControl(RigGraph *rg, RigGraph *src_rg, RigControl *src_ renameTemplateBone(name, src_ctrl->bone->name, rg->editbones, side_string, num_string); ctrl->bone = duplicateEditBoneObjects(src_ctrl->bone, name, rg->editbones, src_rg->ob, rg->ob); - ctrl->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); + ctrl->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL); BLI_ghash_insert(ptr_hash, src_ctrl->bone, ctrl->bone); ctrl->link = src_ctrl->link; @@ -554,7 +554,7 @@ static RigArc *cloneArc(RigGraph *rg, RigGraph *src_rg, RigArc *src_arc, GHash * char name[32]; renameTemplateBone(name, src_edge->bone->name, rg->editbones, side_string, num_string); edge->bone = duplicateEditBoneObjects(src_edge->bone, name, rg->editbones, src_rg->ob, rg->ob); - edge->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL|BONE_ACTIVE); + edge->bone->flag &= ~(BONE_TIPSEL|BONE_SELECTED|BONE_ROOTSEL); BLI_ghash_insert(ptr_hash, src_edge->bone, edge->bone); } @@ -675,22 +675,22 @@ static void RIG_calculateEdgeAngles(RigEdge *edge_first, RigEdge *edge_second) { float vec_first[3], vec_second[3]; - VecSubf(vec_first, edge_first->tail, edge_first->head); - VecSubf(vec_second, edge_second->tail, edge_second->head); + sub_v3_v3v3(vec_first, edge_first->tail, edge_first->head); + sub_v3_v3v3(vec_second, edge_second->tail, edge_second->head); - Normalize(vec_first); - Normalize(vec_second); + normalize_v3(vec_first); + normalize_v3(vec_second); - edge_first->angle = NormalizedVecAngle2(vec_first, vec_second); + edge_first->angle = angle_normalized_v3v3(vec_first, vec_second); if (edge_second->bone != NULL) { float normal[3]; - Crossf(normal, vec_first, vec_second); - Normalize(normal); + cross_v3_v3v3(normal, vec_first, vec_second); + normalize_v3(normal); - edge_second->up_angle = NormalizedVecAngle2(normal, edge_second->up_axis); + edge_second->up_angle = angle_normalized_v3v3(normal, edge_second->up_axis); } } @@ -715,27 +715,27 @@ static int RIG_parentControl(RigControl *ctrl, EditBone *link) float offset[3]; int flag = 0; - VecSubf(offset, ctrl->bone->head, link->head); + sub_v3_v3v3(offset, ctrl->bone->head, link->head); /* if root matches, check for direction too */ - if (Inpf(offset, offset) < 0.0001) + if (dot_v3v3(offset, offset) < 0.0001) { float vbone[3], vparent[3]; flag |= RIG_CTRL_FIT_ROOT; - VecSubf(vbone, ctrl->bone->tail, ctrl->bone->head); - VecSubf(vparent, link->tail, link->head); + sub_v3_v3v3(vbone, ctrl->bone->tail, ctrl->bone->head); + sub_v3_v3v3(vparent, link->tail, link->head); /* test for opposite direction */ - if (Inpf(vbone, vparent) > 0) + if (dot_v3v3(vbone, vparent) > 0) { float nor[3]; float len; - Crossf(nor, vbone, vparent); + cross_v3_v3v3(nor, vbone, vparent); - len = Inpf(nor, nor); + len = dot_v3v3(nor, nor); if (len < 0.0001) { flag |= RIG_CTRL_FIT_BONE; @@ -869,8 +869,8 @@ static void RIG_reconnectControlBones(RigGraph *rg) { int fit = 0; - fit = VecLenf(ctrl->bone->head, edge->bone->head) < 0.0001; - fit = fit || VecLenf(ctrl->bone->tail, edge->bone->tail) < 0.0001; + fit = len_v3v3(ctrl->bone->head, edge->bone->head) < 0.0001; + fit = fit || len_v3v3(ctrl->bone->tail, edge->bone->tail) < 0.0001; if (fit) { @@ -1026,13 +1026,13 @@ static void RIG_reconnectControlBones(RigGraph *rg) /* don't link with parent */ if (bone->parent != ctrl->bone) { - if (VecLenf(ctrl->bone->tail, bone->head) < 0.01) + if (len_v3v3(ctrl->bone->tail, bone->head) < 0.01) { ctrl->tail_mode = TL_HEAD; ctrl->link_tail = bone; break; } - else if (VecLenf(ctrl->bone->tail, bone->tail) < 0.01) + else if (len_v3v3(ctrl->bone->tail, bone->tail) < 0.01) { ctrl->tail_mode = TL_TAIL; ctrl->link_tail = bone; @@ -1132,7 +1132,7 @@ static void RIG_removeUneededOffsets(RigGraph *rg) if (first_edge->bone == NULL) { - if (first_edge->bone == NULL && VecLenf(first_edge->tail, arc->head->p) <= 0.001) + if (first_edge->bone == NULL && len_v3v3(first_edge->tail, arc->head->p) <= 0.001) { BLI_remlink(&arc->edges, first_edge); MEM_freeN(first_edge); @@ -1262,7 +1262,7 @@ static void RIG_removeUneededOffsets(RigGraph *rg) if (last_edge->bone == NULL) { - if (VecLenf(last_edge->head, arc->tail->p) <= 0.001) + if (len_v3v3(last_edge->head, arc->tail->p) <= 0.001) { BLI_remlink(&arc->edges, last_edge); MEM_freeN(last_edge); @@ -1438,7 +1438,7 @@ void RIG_printNode(RigNode *node, char name[]) else if (node->symmetry_flag & SYM_RADIAL) printf("Symmetry RADIAL\n"); - printvecf("symmetry axis", node->symmetry_axis); + print_v3("symmetry axis", node->symmetry_axis); } } @@ -1464,7 +1464,7 @@ void RIG_printCtrl(RigControl *ctrl, char *indent) printf("%sLink: %s\n", indent, ctrl->link ? ctrl->link->name : "!NONE!"); sprintf(text, "%soffset", indent); - printvecf(text, ctrl->offset); + print_v3(text, ctrl->offset); printf("%sFlag: %i\n", indent, ctrl->flag); } @@ -1555,7 +1555,7 @@ RigGraph *RIG_graphFromArmature(const bContext *C, Object *ob, bArmature *arm) else { rg->editbones = MEM_callocN(sizeof(ListBase), "EditBones"); - make_boneList(rg->editbones, &arm->bonebase, NULL); + make_boneList(rg->editbones, &arm->bonebase, NULL, NULL); rg->flag |= RIG_FREE_BONELIST; } @@ -1607,7 +1607,7 @@ RigGraph *armatureSelectedToGraph(bContext *C, Object *ob, bArmature *arm) else { rg->editbones = MEM_callocN(sizeof(ListBase), "EditBones"); - make_boneList(rg->editbones, &arm->bonebase, NULL); + make_boneList(rg->editbones, &arm->bonebase, NULL, NULL); rg->flag |= RIG_FREE_BONELIST; } @@ -1761,15 +1761,15 @@ static void finalizeControl(RigGraph *rigg, RigControl *ctrl, float resize) tail_vec = ctrl->link_tail->head; } - VecSubf(v1, ctrl->bone->tail, ctrl->bone->head); - VecSubf(v2, tail_vec, ctrl->bone->head); + sub_v3_v3v3(v1, ctrl->bone->tail, ctrl->bone->head); + sub_v3_v3v3(v2, tail_vec, ctrl->bone->head); VECCOPY(ctrl->bone->tail, tail_vec); - RotationBetweenVectorsToQuat(qtail, v1, v2); - QuatMul(ctrl->qrot, qtail, ctrl->qrot); + rotation_between_vecs_to_quat(qtail, v1, v2); + mul_qt_qtqt(ctrl->qrot, qtail, ctrl->qrot); - resize = VecLength(v2) / VecLenf(ctrl->head, ctrl->tail); + resize = len_v3(v2) / len_v3v3(ctrl->head, ctrl->tail); } ctrl->bone->roll = rollBoneByQuat(ctrl->bone, ctrl->up_axis, ctrl->qrot); @@ -1801,10 +1801,10 @@ static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], f float parent_offset[3], tail_offset[3]; VECCOPY(parent_offset, ctrl->offset); - VecMulf(parent_offset, resize); - QuatMulVecf(qrot, parent_offset); + mul_v3_fl(parent_offset, resize); + mul_qt_v3(qrot, parent_offset); - VecAddf(ctrl->bone->head, head, parent_offset); + add_v3_v3v3(ctrl->bone->head, head, parent_offset); ctrl->flag |= RIG_CTRL_HEAD_DONE; @@ -1812,11 +1812,11 @@ static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], f if (ctrl->tail_mode == TL_NONE) { - VecSubf(tail_offset, ctrl->tail, ctrl->head); - VecMulf(tail_offset, resize); - QuatMulVecf(qrot, tail_offset); + sub_v3_v3v3(tail_offset, ctrl->tail, ctrl->head); + mul_v3_fl(tail_offset, resize); + mul_qt_v3(qrot, tail_offset); - VecAddf(ctrl->bone->tail, ctrl->bone->head, tail_offset); + add_v3_v3v3(ctrl->bone->tail, ctrl->bone->head, tail_offset); ctrl->flag |= RIG_CTRL_TAIL_DONE; } @@ -1835,20 +1835,20 @@ static void repositionBone(bContext *C, RigGraph *rigg, RigEdge *edge, float vec bone = edge->bone; - VecSubf(v1, edge->tail, edge->head); - VecSubf(v2, vec1, vec0); + sub_v3_v3v3(v1, edge->tail, edge->head); + sub_v3_v3v3(v2, vec1, vec0); - l1 = Normalize(v1); - l2 = Normalize(v2); + l1 = normalize_v3(v1); + l2 = normalize_v3(v2); resize = l2 / l1; - RotationBetweenVectorsToQuat(qrot, v1, v2); + rotation_between_vecs_to_quat(qrot, v1, v2); VECCOPY(bone->head, vec0); VECCOPY(bone->tail, vec1); - if (!VecIsNull(up_axis)) + if (!is_zero_v3(up_axis)) { float qroll[4]; @@ -1862,10 +1862,10 @@ static void repositionBone(bContext *C, RigGraph *rigg, RigEdge *edge, float vec } else { - QuatOne(qroll); + unit_qt(qroll); } - QuatMul(qrot, qroll, qrot); + mul_qt_qtqt(qrot, qroll, qrot); } else { @@ -1979,9 +1979,9 @@ static float costDistance(BArcIterator *iter, float *vec0, float *vec1, int i0, if (distance_weight > 0) { - VecSubf(v1, vec0, vec1); + sub_v3_v3v3(v1, vec0, vec1); - v1_inpf = Inpf(v1, v1); + v1_inpf = dot_v3v3(v1, v1); if (v1_inpf > 0) { @@ -1992,11 +1992,11 @@ static float costDistance(BArcIterator *iter, float *vec0, float *vec1, int i0, bucket = IT_peek(iter, j); - VecSubf(v2, bucket->p, vec1); + sub_v3_v3v3(v2, bucket->p, vec1); - Crossf(c, v1, v2); + cross_v3_v3v3(c, v1, v2); - dist = Inpf(c, c) / v1_inpf; + dist = dot_v3v3(c, c) / v1_inpf; max_dist = dist > max_dist ? dist : max_dist; } @@ -2020,9 +2020,9 @@ static float costAngle(float original_angle, float vec_first[3], float vec_secon { float current_angle; - if (!VecIsNull(vec_first) && !VecIsNull(vec_second)) + if (!is_zero_v3(vec_first) && !is_zero_v3(vec_second)) { - current_angle = saacos(Inpf(vec_first, vec_second)); + current_angle = saacos(dot_v3v3(vec_first, vec_second)); return angle_weight * fabs(current_angle - original_angle); } @@ -2056,8 +2056,8 @@ static float calcCostLengthDistance(BArcIterator *iter, float **vec_cache, RigEd float vec[3]; float length; - VecSubf(vec, vec2, vec1); - length = Normalize(vec); + sub_v3_v3v3(vec, vec2, vec1); + length = normalize_v3(vec); return costLength(edge->length, length) + costDistance(iter, vec1, vec2, i1, i2); } @@ -2069,15 +2069,15 @@ static float calcCostAngleLengthDistance(BArcIterator *iter, float **vec_cache, float length2; float new_cost = 0; - VecSubf(vec_second, vec2, vec1); - length2 = Normalize(vec_second); + sub_v3_v3v3(vec_second, vec2, vec1); + length2 = normalize_v3(vec_second); /* Angle cost */ if (edge->prev) { - VecSubf(vec_first, vec1, vec0); - Normalize(vec_first); + sub_v3_v3v3(vec_first, vec1, vec0); + normalize_v3(vec_first); new_cost += costAngle(edge->prev->angle, vec_first, vec_second, angle_weight); } @@ -2352,13 +2352,13 @@ static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, Ri { vec1 = bucket->p; - embedding_length += VecLenf(vec0, vec1); + embedding_length += len_v3v3(vec0, vec1); vec0 = vec1; bucket = IT_next(iter); } - embedding_length += VecLenf(node_end->p, vec1); + embedding_length += len_v3v3(node_end->p, vec1); /* fit bones */ initArcIterator(iter, earc, node_start); @@ -2377,7 +2377,7 @@ static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, Ri while (bucket && new_bone_length > length) { - length += VecLenf(previous_vec, vec1); + length += len_v3v3(previous_vec, vec1); bucket = IT_next(iter); previous_vec = vec1; vec1 = bucket->p; @@ -2947,6 +2947,8 @@ void BIF_retargetArc(bContext *C, ReebArc *earc, RigGraph *template_rigg) } RIG_freeRigGraph((BGraph*)rigg); + ED_armature_validate_active(armedit); + // XXX // allqueue(REDRAWVIEW3D, 0); } diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index b3dd8f35137..7bb2fa9009d 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -39,7 +39,7 @@ #include "RNA_access.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_graph.h" #include "BLI_ghash.h" @@ -416,10 +416,10 @@ ReebNode *sk_pointToNode(SK_Point *pt, float imat[][4], float tmat[][3]) node = MEM_callocN(sizeof(ReebNode), "reeb node"); VECCOPY(node->p, pt->p); - Mat4MulVecfl(imat, node->p); + mul_m4_v3(imat, node->p); VECCOPY(node->no, pt->no); - Mat3MulVecfl(tmat, node->no); + mul_m3_v3(tmat, node->no); return node; } @@ -439,10 +439,10 @@ ReebArc *sk_strokeToArc(SK_Stroke *stk, float imat[][4], float tmat[][3]) for (i = 0; i < arc->bcount; i++) { VECCOPY(arc->buckets[i].p, stk->points[i + 1].p); - Mat4MulVecfl(imat, arc->buckets[i].p); + mul_m4_v3(imat, arc->buckets[i].p); VECCOPY(arc->buckets[i].no, stk->points[i + 1].no); - Mat3MulVecfl(tmat, arc->buckets[i].no); + mul_m3_v3(tmat, arc->buckets[i].no); } return arc; @@ -457,10 +457,10 @@ void sk_retargetStroke(bContext *C, SK_Stroke *stk) ReebArc *arc; RigGraph *rg; - Mat4Invert(imat, obedit->obmat); + invert_m4_m4(imat, obedit->obmat); - Mat3CpyMat4(tmat, obedit->obmat); - Mat3Transp(tmat); + copy_m3_m4(tmat, obedit->obmat); + transpose_m3(tmat); arc = sk_strokeToArc(stk, imat, tmat); @@ -505,16 +505,16 @@ void sk_drawEdge(GLUquadric *quad, SK_Point *pt0, SK_Point *pt1, float size) float vec1[3], vec2[3] = {0, 0, 1}, axis[3]; float angle, length; - VecSubf(vec1, pt1->p, pt0->p); - length = Normalize(vec1); - Crossf(axis, vec2, vec1); + sub_v3_v3v3(vec1, pt1->p, pt0->p); + length = normalize_v3(vec1); + cross_v3_v3v3(axis, vec2, vec1); - if (VecIsNull(axis)) + if (is_zero_v3(axis)) { axis[1] = 1; } - angle = NormalizedVecAngle2(vec2, vec1); + angle = angle_normalized_v3v3(vec2, vec1); glRotatef(angle * 180 / M_PI + 180, axis[0], axis[1], axis[2]); @@ -528,14 +528,14 @@ void sk_drawNormal(GLUquadric *quad, SK_Point *pt, float size, float height) glPushMatrix(); - Crossf(axis, vec2, pt->no); + cross_v3_v3v3(axis, vec2, pt->no); - if (VecIsNull(axis)) + if (is_zero_v3(axis)) { axis[1] = 1; } - angle = NormalizedVecAngle2(vec2, pt->no); + angle = angle_normalized_v3v3(vec2, pt->no); glRotatef(angle * 180 / M_PI, axis[0], axis[1], axis[2]); @@ -576,8 +576,8 @@ void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int end) float d_rgb[3] = {1, 1, 1}; VECCOPY(rgb, color); - VecSubf(d_rgb, d_rgb, rgb); - VecMulf(d_rgb, 1.0f / (float)stk->nb_points); + sub_v3_v3v3(d_rgb, d_rgb, rgb); + mul_v3_fl(d_rgb, 1.0f / (float)stk->nb_points); for (i = 0; i < stk->nb_points; i++) { @@ -614,7 +614,7 @@ void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int end) glPopMatrix(); - VecAddf(rgb, rgb, d_rgb); + add_v3_v3v3(rgb, rgb, d_rgb); } } @@ -756,7 +756,7 @@ SK_Point *sk_snapPointArmature(bContext *C, Object *ob, ListBase *ebones, short if ((bone->flag & BONE_CONNECTED) == 0) { VECCOPY(vec, bone->head); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); project_short_noclip(ar, vec, pval); pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]); @@ -772,7 +772,7 @@ SK_Point *sk_snapPointArmature(bContext *C, Object *ob, ListBase *ebones, short VECCOPY(vec, bone->tail); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); project_short_noclip(ar, vec, pval); pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]); @@ -977,13 +977,13 @@ float sk_distanceDepth(bContext *C, float p1[3], float p2[3]) float vec[3]; float distance; - VecSubf(vec, p1, p2); + sub_v3_v3v3(vec, p1, p2); - Projf(vec, vec, rv3d->viewinv[2]); + project_v3_v3v3(vec, vec, rv3d->viewinv[2]); - distance = VecLength(vec); + distance = len_v3(vec); - if (Inpf(rv3d->viewinv[2], vec) > 0) + if (dot_v3v3(rv3d->viewinv[2], vec) > 0) { distance *= -1; } @@ -1000,19 +1000,19 @@ void sk_interpolateDepth(bContext *C, SK_Stroke *stk, int start, int end, float float progress = 0; int i; - progress = VecLenf(stk->points[start].p, stk->points[start - 1].p); + progress = len_v3v3(stk->points[start].p, stk->points[start - 1].p); for (i = start; i <= end; i++) { float ray_start[3], ray_normal[3]; - float delta = VecLenf(stk->points[i].p, stk->points[i + 1].p); + float delta = len_v3v3(stk->points[i].p, stk->points[i + 1].p); float pval[2]; project_float(ar, stk->points[i].p, pval); viewray(ar, v3d, pval, ray_start, ray_normal); - VecMulf(ray_normal, distance * progress / length); - VecAddf(stk->points[i].p, stk->points[i].p, ray_normal); + mul_v3_fl(ray_normal, distance * progress / length); + add_v3_v3v3(stk->points[i].p, stk->points[i].p, ray_normal); progress += delta ; } @@ -1037,7 +1037,7 @@ void sk_projectDrawPoint(bContext *C, float vec[3], SK_Stroke *stk, SK_DrawData /* method taken from editview.c - mouse_cursor() */ project_short_noclip(ar, fp, cval); window_to_3d_delta(ar, dvec, cval[0] - dd->mval[0], cval[1] - dd->mval[1]); - VecSubf(vec, fp, dvec); + sub_v3_v3v3(vec, fp, dvec); } int sk_getStrokeDrawPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd) @@ -1132,9 +1132,9 @@ int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, SK_Strok { p2->flag = 1; - VecAddf(vec, p1->p, p2->p); - VecMulf(vec, 0.5f); - new_size = VecLenf(p1->p, p2->p); + add_v3_v3v3(vec, p1->p, p2->p); + mul_v3_fl(vec, 0.5f); + new_size = len_v3v3(p1->p, p2->p); } else { @@ -1149,7 +1149,7 @@ int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, SK_Strok break; } - new_dist = VecLenf(last_p, vec); + new_dist = len_v3v3(last_p, vec); if (new_dist < dist) { @@ -1248,7 +1248,7 @@ int sk_addStrokeSnapPoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_Dra length = 0; for (i = stk->nb_points - 2; i > 0; i--) { - length += VecLenf(stk->points[i].p, stk->points[i + 1].p); + length += len_v3v3(stk->points[i].p, stk->points[i + 1].p); total++; if (stk->points[i].mode == PT_SNAP || stk->points[i].type == PT_EXACT) { @@ -1494,10 +1494,10 @@ void sk_convertStroke(bContext *C, SK_Stroke *stk) head = NULL; - Mat4Invert(invmat, obedit->obmat); + invert_m4_m4(invmat, obedit->obmat); - Mat3CpyMat4(tmat, obedit->obmat); - Mat3Transp(tmat); + copy_m3_m4(tmat, obedit->obmat); + transpose_m3(tmat); for (i = 0; i < stk->nb_points; i++) { @@ -1543,8 +1543,8 @@ void sk_convertStroke(bContext *C, SK_Stroke *stk) VECCOPY(bone->head, head->p); VECCOPY(bone->tail, pt->p); - Mat4MulVecfl(invmat, bone->head); - Mat4MulVecfl(invmat, bone->tail); + mul_m4_v3(invmat, bone->head); + mul_m4_v3(invmat, bone->tail); setBoneRollFromNormal(bone, head->no, invmat, tmat); } @@ -1624,7 +1624,7 @@ int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gesture) project_float(ar, gesture->points[g_i].p, g_p1); project_float(ar, gesture->points[g_i + 1].p, g_p2); - if (LineIntersectLineStrict(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) + if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) { SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection"); @@ -1633,9 +1633,9 @@ int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gesture) isect->after = s_i + 1; isect->stroke = gesture; - VecSubf(isect->p, gesture->points[s_i + 1].p, gesture->points[s_i].p); - VecMulf(isect->p, lambda); - VecAddf(isect->p, isect->p, gesture->points[s_i].p); + sub_v3_v3v3(isect->p, gesture->points[s_i + 1].p, gesture->points[s_i].p); + mul_v3_fl(isect->p, lambda); + add_v3_v3v3(isect->p, isect->p, gesture->points[s_i].p); BLI_addtail(list, isect); @@ -1711,7 +1711,7 @@ int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, SK_Strok project_float(ar, gesture->points[g_i].p, g_p1); project_float(ar, gesture->points[g_i + 1].p, g_p2); - if (LineIntersectLineStrict(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) + if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) { SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection"); float ray_start[3], ray_end[3]; @@ -1727,7 +1727,7 @@ int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, SK_Strok mval[1] = vi[1]; viewline(ar, v3d, mval, ray_start, ray_end); - LineIntersectLine( stk->points[s_i].p, + isect_line_line_v3( stk->points[s_i].p, stk->points[s_i + 1].p, ray_start, ray_end, @@ -1768,7 +1768,7 @@ int sk_getSegments(SK_Stroke *segments, SK_Stroke *gesture) float n[3]; /* Calculate normal */ - VecSubf(n, gesture->points[i].p, vec); + sub_v3_v3v3(n, gesture->points[i].p, vec); if (calcArcCorrelation(iter, j, i, vec, n) < CORRELATION_THRESHOLD) { @@ -1818,10 +1818,10 @@ int sk_detectTrimGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch) float s1[3], s2[3]; float angle; - VecSubf(s1, gest->segments->points[1].p, gest->segments->points[0].p); - VecSubf(s2, gest->segments->points[2].p, gest->segments->points[1].p); + sub_v3_v3v3(s1, gest->segments->points[1].p, gest->segments->points[0].p); + sub_v3_v3v3(s2, gest->segments->points[2].p, gest->segments->points[1].p); - angle = RAD2DEG(VecAngle2(s1, s2)); + angle = RAD2DEG(angle_v2v2(s1, s2)); if (angle > 60 && angle < 120) { @@ -1837,7 +1837,7 @@ void sk_applyTrimGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch) SK_Intersection *isect; float trim_dir[3]; - VecSubf(trim_dir, gest->segments->points[2].p, gest->segments->points[1].p); + sub_v3_v3v3(trim_dir, gest->segments->points[2].p, gest->segments->points[1].p); for (isect = gest->intersections.first; isect; isect = isect->next) { @@ -1849,10 +1849,10 @@ void sk_applyTrimGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch) VECCOPY(pt.p, isect->p); VECCOPY(pt.no, isect->stroke->points[isect->before].no); - VecSubf(stroke_dir, isect->stroke->points[isect->after].p, isect->stroke->points[isect->before].p); + sub_v3_v3v3(stroke_dir, isect->stroke->points[isect->after].p, isect->stroke->points[isect->before].p); /* same direction, trim end */ - if (Inpf(stroke_dir, trim_dir) > 0) + if (dot_v3v3(stroke_dir, trim_dir) > 0) { sk_replaceStrokePoint(isect->stroke, &pt, isect->after); sk_trimStroke(isect->stroke, 0, isect->after); @@ -1936,10 +1936,10 @@ int sk_detectDeleteGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch) float s1[3], s2[3]; float angle; - VecSubf(s1, gest->segments->points[1].p, gest->segments->points[0].p); - VecSubf(s2, gest->segments->points[2].p, gest->segments->points[1].p); + sub_v3_v3v3(s1, gest->segments->points[1].p, gest->segments->points[0].p); + sub_v3_v3v3(s2, gest->segments->points[2].p, gest->segments->points[1].p); - angle = RAD2DEG(VecAngle2(s1, s2)); + angle = RAD2DEG(angle_v2v2(s1, s2)); if (angle > 120) { @@ -2062,16 +2062,16 @@ int sk_detectReverseGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch) if (isect->gesture_index < isect->next->gesture_index) { - VecSubf(start_v, isect->p, gest->stk->points[0].p); - VecSubf(end_v, sk_lastStrokePoint(gest->stk)->p, isect->next->p); + sub_v3_v3v3(start_v, isect->p, gest->stk->points[0].p); + sub_v3_v3v3(end_v, sk_lastStrokePoint(gest->stk)->p, isect->next->p); } else { - VecSubf(start_v, isect->next->p, gest->stk->points[0].p); - VecSubf(end_v, sk_lastStrokePoint(gest->stk)->p, isect->p); + sub_v3_v3v3(start_v, isect->next->p, gest->stk->points[0].p); + sub_v3_v3v3(end_v, sk_lastStrokePoint(gest->stk)->p, isect->p); } - angle = RAD2DEG(VecAngle2(start_v, end_v)); + angle = RAD2DEG(angle_v2v2(start_v, end_v)); if (angle > 120) { diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 9847bdc3283..b9019410348 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -40,7 +40,7 @@ #include "DNA_modifier_types.h" #include "DNA_scene_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_edgehash.h" #include "BLI_memarena.h" @@ -151,16 +151,16 @@ static float cotan_weight(float *v1, float *v2, float *v3) { float a[3], b[3], c[3], clen; - VecSubf(a, v2, v1); - VecSubf(b, v3, v1); - Crossf(c, a, b); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v3, v1); + cross_v3_v3v3(c, a, b); - clen = VecLength(c); + clen = len_v3(c); if (clen == 0.0f) return 0.0f; - return Inpf(a, b)/clen; + return dot_v3v3(a, b)/clen; } static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3) @@ -177,21 +177,21 @@ static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3 t2= cotan_weight(v2, v3, v1); t3= cotan_weight(v3, v1, v2); - if(RAD2DEG(VecAngle3(v2, v1, v3)) > 90) obtuse= 1; - else if(RAD2DEG(VecAngle3(v1, v2, v3)) > 90) obtuse= 2; - else if(RAD2DEG(VecAngle3(v1, v3, v2)) > 90) obtuse= 3; + if(RAD2DEG(angle_v3v3v3(v2, v1, v3)) > 90) obtuse= 1; + else if(RAD2DEG(angle_v3v3v3(v1, v2, v3)) > 90) obtuse= 2; + else if(RAD2DEG(angle_v3v3v3(v1, v3, v2)) > 90) obtuse= 3; if (obtuse > 0) { - area= AreaT3Dfl(v1, v2, v3); + area= area_tri_v3(v1, v2, v3); varea[i1] += (obtuse == 1)? area: area*0.5; varea[i2] += (obtuse == 2)? area: area*0.5; varea[i3] += (obtuse == 3)? area: area*0.5; } else { - len1= VecLenf(v2, v3); - len2= VecLenf(v1, v3); - len3= VecLenf(v1, v2); + len1= len_v3v3(v2, v3); + len2= len_v3v3(v1, v3); + len3= len_v3v3(v1, v2); t1 *= len1*len1; t2 *= len2*len2; @@ -446,7 +446,7 @@ static int heat_ray_bone_visible(LaplacianSystem *sys, int vertex, int bone) VECCOPY(isec.start, sys->heat.verts[vertex]); - PclosestVL3Dfl(end, isec.start, sys->heat.root[bone], sys->heat.tip[bone]); + closest_to_line_segment_v3(end, isec.start, sys->heat.root[bone], sys->heat.tip[bone]); VECSUB(isec.vec, end, isec.start); isec.labda = 1.0f - 1e-5; @@ -462,11 +462,11 @@ static float heat_bone_distance(LaplacianSystem *sys, int vertex, int bone) float closest[3], d[3], dist, cosine; /* compute euclidian distance */ - PclosestVL3Dfl(closest, sys->heat.verts[vertex], + closest_to_line_segment_v3(closest, sys->heat.verts[vertex], sys->heat.root[bone], sys->heat.tip[bone]); - VecSubf(d, sys->heat.verts[vertex], closest); - dist= Normalize(d); + sub_v3_v3v3(d, sys->heat.verts[vertex], closest); + dist= normalize_v3(d); /* if the vertex normal does not point along the bone, increase distance */ cosine= INPR(d, sys->heat.vnors[vertex]); @@ -536,15 +536,15 @@ void heat_calc_vnormals(LaplacianSystem *sys) v2= (*face)[1]; v3= (*face)[2]; - CalcNormFloat(sys->verts[v1], sys->verts[v2], sys->verts[v3], fnor); + normal_tri_v3( fnor,sys->verts[v1], sys->verts[v2], sys->verts[v3]); - VecAddf(sys->heat.vnors[v1], sys->heat.vnors[v1], fnor); - VecAddf(sys->heat.vnors[v2], sys->heat.vnors[v2], fnor); - VecAddf(sys->heat.vnors[v3], sys->heat.vnors[v3], fnor); + add_v3_v3v3(sys->heat.vnors[v1], sys->heat.vnors[v1], fnor); + add_v3_v3v3(sys->heat.vnors[v2], sys->heat.vnors[v2], fnor); + add_v3_v3v3(sys->heat.vnors[v3], sys->heat.vnors[v3], fnor); } for(a=0; a<sys->totvert; a++) - Normalize(sys->heat.vnors[a]); + normalize_v3(sys->heat.vnors[a]); } static void heat_laplacian_create(LaplacianSystem *sys) @@ -746,8 +746,8 @@ static void rigid_add_half_edge_to_R(LaplacianSystem *sys, EditVert *v1, EditVer float e[3], e_[3]; int i; - VecSubf(e, sys->rigid.origco[v1->tmp.l], sys->rigid.origco[v2->tmp.l]); - VecSubf(e_, v1->co, v2->co); + sub_v3_v3v3(e, sys->rigid.origco[v1->tmp.l], sys->rigid.origco[v2->tmp.l]); + sub_v3_v3v3(e_, v1->co, v2->co); /* formula (5) */ for (i=0; i<3; i++) { @@ -767,9 +767,9 @@ static void rigid_orthogonalize_R(float R[][3]) { HMatrix M, Q, S; - Mat4CpyMat3(M, R); + copy_m4_m3(M, R); polar_decomp(M, Q, S); - Mat3CpyMat4(R, Q); + copy_m3_m4(R, Q); } static void rigid_add_half_edge_to_rhs(LaplacianSystem *sys, EditVert *v1, EditVert *v2, float w) @@ -780,15 +780,15 @@ static void rigid_add_half_edge_to_rhs(LaplacianSystem *sys, EditVert *v1, EditV if (sys->vpinned[v1->tmp.l]) return; - Mat3AddMat3(Rsum, sys->rigid.R[v1->tmp.l], sys->rigid.R[v2->tmp.l]); - Mat3Transp(Rsum); + add_m3_m3m3(Rsum, sys->rigid.R[v1->tmp.l], sys->rigid.R[v2->tmp.l]); + transpose_m3(Rsum); - VecSubf(rhs, sys->rigid.origco[v1->tmp.l], sys->rigid.origco[v2->tmp.l]); - Mat3MulVecfl(Rsum, rhs); - VecMulf(rhs, 0.5f); - VecMulf(rhs, w); + sub_v3_v3v3(rhs, sys->rigid.origco[v1->tmp.l], sys->rigid.origco[v2->tmp.l]); + mul_m3_v3(Rsum, rhs); + mul_v3_fl(rhs, 0.5f); + mul_v3_fl(rhs, w); - VecAddf(sys->rigid.rhs[v1->tmp.l], sys->rigid.rhs[v1->tmp.l], rhs); + add_v3_v3v3(sys->rigid.rhs[v1->tmp.l], sys->rigid.rhs[v1->tmp.l], rhs); } static void rigid_add_edge_to_rhs(LaplacianSystem *sys, EditVert *v1, EditVert *v2, float w) @@ -916,7 +916,7 @@ void rigid_deform_begin(EditMesh *em) sys->rigid.origco = MEM_callocN(sizeof(float)*3*totvert, "RigidDeformCo"); for(a=0, eve=em->verts.first; eve; eve=eve->next, a++) - VecCopyf(sys->rigid.origco[a], eve->co); + copy_v3_v3(sys->rigid.origco[a], eve->co); sys->areaweights= 0; sys->storeweights= 1; @@ -940,7 +940,7 @@ void rigid_deform_end(int cancel) if(cancel) for(a=0, eve=em->verts.first; eve; eve=eve->next, a++) if(!eve->pinned) - VecCopyf(eve->co, sys->rigid.origco[a]); + copy_v3_v3(eve->co, sys->rigid.origco[a]); if(sys->rigid.R) MEM_freeN(sys->rigid.R); if(sys->rigid.rhs) MEM_freeN(sys->rigid.rhs); @@ -1034,7 +1034,7 @@ static int meshdeform_tri_intersect(float orig[3], float end[3], float vert0[3], VECSUB(edge2, vert2, vert0); /* begin calculating determinant - also used to calculate U parameter */ - Crossf(pvec, dir, edge2); + cross_v3_v3v3(pvec, dir, edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = INPR(edge1, pvec); @@ -1052,7 +1052,7 @@ static int meshdeform_tri_intersect(float orig[3], float end[3], float vert0[3], return 0; /* prepare to test V parameter */ - Crossf(qvec, tvec, edge1); + cross_v3_v3v3(qvec, tvec, edge1); /* calculate V parameter and test bounds */ v = INPR(dir, qvec) * inv_det; @@ -1158,20 +1158,20 @@ static int meshdeform_intersect(MeshDeformBind *mdb, Isect *isec) hit = meshdeform_tri_intersect(isec->start, end, face[0], face[1], face[2], co, uvw); if(hit) { - CalcNormFloat(face[0], face[1], face[2], nor); + normal_tri_v3( nor,face[0], face[1], face[2]); } else { hit= meshdeform_tri_intersect(isec->start, end, face[0], face[2], face[3], co, uvw); - CalcNormFloat(face[0], face[2], face[3], nor); + normal_tri_v3( nor,face[0], face[2], face[3]); } } else { hit= meshdeform_tri_intersect(isec->start, end, face[0], face[1], face[2], co, uvw); - CalcNormFloat(face[0], face[1], face[2], nor); + normal_tri_v3( nor,face[0], face[1], face[2]); } if(hit) { - len= VecLenf(isec->start, co)/VecLenf(isec->start, end); + len= len_v3v3(isec->start, co)/len_v3v3(isec->start, end); if(len < isec->labda) { isec->labda= len; isec->hit.face = mface; @@ -1219,7 +1219,7 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, float isect->co[1]= co1[1] + isec.vec[1]*len; isect->co[2]= co1[2] + isec.vec[2]*len; - isect->len= VecLenf(co1, isect->co); + isect->len= len_v3v3(co1, isect->co); if(isect->len < MESHDEFORM_LEN_THRESHOLD) isect->len= MESHDEFORM_LEN_THRESHOLD; @@ -1237,7 +1237,7 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, float VECCOPY(vert[1], cagecos[mface->v2]); VECCOPY(vert[2], cagecos[mface->v3]); if(mface->v4) VECCOPY(vert[3], cagecos[mface->v4]); - MeanValueWeights(vert, isect->nvert, isect->co, isect->uvw); + interp_weights_poly_v3( isect->uvw,vert, isect->nvert, isect->co); return isect; } @@ -1260,7 +1260,7 @@ static int meshdeform_inside_cage(MeshDeformBind *mdb, float *co) VECCOPY(start, co); VECSUB(dir, outside, start); - Normalize(dir); + normalize_v3(dir); isect = meshdeform_ray_tree_intersect(mdb, start, outside); if(isect && !isect->facing) @@ -1650,7 +1650,7 @@ static void meshdeform_matrix_solve(MeshDeformBind *mdb) for(b=0; b<mdb->totvert; b++) { if(mdb->inside[b]) { VECCOPY(vec, mdb->vertexcos[b]); - Mat4MulVecfl(mdb->cagemat, vec); + mul_m4_v3(mdb->cagemat, vec); gridvec[0]= (vec[0] - mdb->min[0] - mdb->halfwidth[0])/mdb->width[0]; gridvec[1]= (vec[1] - mdb->min[1] - mdb->halfwidth[1])/mdb->width[1]; gridvec[2]= (vec[2] - mdb->min[2] - mdb->halfwidth[2])/mdb->width[2]; @@ -1720,7 +1720,7 @@ void harmonic_coordinates_bind(Scene *scene, MeshDeformModifierData *mmd, float mdb.cagedm= mesh_create_derived_no_deform(scene, mmd->object, NULL, CD_MASK_BAREMESH); mdb.totcagevert= mdb.cagedm->getNumVerts(mdb.cagedm); mdb.cagecos= MEM_callocN(sizeof(*mdb.cagecos)*mdb.totcagevert, "MeshDeformBindCos"); - Mat4CpyMat4(mdb.cagemat, cagemat); + copy_m4_m4(mdb.cagemat, cagemat); mvert= mdb.cagedm->getVertArray(mdb.cagedm); for(a=0; a<mdb.totcagevert; a++) @@ -1781,7 +1781,7 @@ void harmonic_coordinates_bind(Scene *scene, MeshDeformModifierData *mmd, float totinside= 0; for(a=0; a<mdb.totvert; a++) { VECCOPY(vec, mdb.vertexcos[a]); - Mat4MulVecfl(mdb.cagemat, vec); + mul_m4_v3(mdb.cagemat, vec); mdb.inside[a]= meshdeform_inside_cage(&mdb, vec); if(mdb.inside[a]) totinside++; @@ -1821,7 +1821,7 @@ void harmonic_coordinates_bind(Scene *scene, MeshDeformModifierData *mmd, float mmd->bindcos= (float*)mdb.cagecos; mmd->totvert= mdb.totvert; mmd->totcagevert= mdb.totcagevert; - Mat4CpyMat4(mmd->bindmat, mmd->object->obmat); + copy_m4_m4(mmd->bindmat, mmd->object->obmat); if(mmd->flag & MOD_MDEF_DYNAMIC_BIND) { mmd->totinfluence= 0; @@ -1868,7 +1868,7 @@ void harmonic_coordinates_bind(Scene *scene, MeshDeformModifierData *mmd, float /* transform bindcos to world space */ for(a=0; a<mdb.totcagevert; a++) - Mat4MulVecfl(mmd->object->obmat, mmd->bindcos+a*3); + mul_m4_v3(mmd->object->obmat, mmd->bindcos+a*3); /* free */ mdb.cagedm->release(mdb.cagedm); diff --git a/source/blender/editors/armature/poseSlide.c b/source/blender/editors/armature/poseSlide.c index 1e0df79d0e6..e5d334e4d06 100644 --- a/source/blender/editors/armature/poseSlide.c +++ b/source/blender/editors/armature/poseSlide.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_dlrbTree.h" @@ -461,7 +461,7 @@ static void pose_slide_apply_quat (tPoseSlideOp *pso, tPChanFCurveLink *pfl) /* perform blending */ if (pso->mode == POSESLIDE_BREAKDOWN) { /* just perform the interpol between quat_prev and quat_next using pso->percentage as a guide */ - QuatInterpol(pchan->quat, quat_prev, quat_next, pso->percentage); + interp_qt_qtqt(pchan->quat, quat_prev, quat_next, pso->percentage); } else { float quat_interp[4], quat_orig[4]; @@ -470,16 +470,16 @@ static void pose_slide_apply_quat (tPoseSlideOp *pso, tPChanFCurveLink *pfl) /* perform this blending several times until a satisfactory result is reached */ while (iters-- > 0) { /* calculate the interpolation between the endpoints */ - QuatInterpol(quat_interp, quat_prev, quat_next, (cframe-pso->prevFrame) / (pso->nextFrame-pso->prevFrame) ); + interp_qt_qtqt(quat_interp, quat_prev, quat_next, (cframe-pso->prevFrame) / (pso->nextFrame-pso->prevFrame) ); /* make a copy of the original rotation */ QUATCOPY(quat_orig, pchan->quat); /* tricky interpolations - mode-dependent blending between original and new */ if (pso->mode == POSESLIDE_RELAX) // xxx this was the original code, so should work fine - QuatInterpol(pchan->quat, quat_orig, quat_interp, 1.0f/6.0f); + interp_qt_qtqt(pchan->quat, quat_orig, quat_interp, 1.0f/6.0f); else // I'm just guessing here... - QuatInterpol(pchan->quat, quat_orig, quat_interp, 6.0f/5.0f); + interp_qt_qtqt(pchan->quat, quat_orig, quat_interp, 6.0f/5.0f); } } } diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index f67c94eebc3..0837e9cb48a 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_dlrbTree.h" @@ -382,7 +382,7 @@ static int poselib_add_exec (bContext *C, wmOperator *op) for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) { /* check if available */ if ((pchan->bone) && (arm->layer & pchan->bone->layer)) { - if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) { + if (pchan->bone->flag & BONE_SELECTED || pchan->bone==arm->act_bone) { /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */ cks.pchan= pchan; @@ -762,7 +762,7 @@ static void poselib_apply_pose (tPoseLib_PreviewData *pld) } else if (pchan->bone) { /* only ok if bone is visible and selected */ - if ( (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) && + if ( (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) && (pchan->bone->flag & BONE_HIDDEN_P)==0 && (pchan->bone->layer & arm->layer) ) ok = 1; diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index 696fa65b33a..18750d96f86 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -33,7 +33,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -158,12 +158,12 @@ static short pose_has_protected_selected(Object *ob, short only_selected, short if (ob->proxy) { bPoseChannel *pchan; bArmature *arm= ob->data; - + for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if (pchan->bone && (pchan->bone->layer & arm->layer)) { if (pchan->bone->layer & arm->layer_protected) { - if (only_selected && (pchan->bone->flag & BONE_ACTIVE)); - else if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) + if (only_selected && (pchan->bone == arm->act_bone)); + else if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) break; } } @@ -279,7 +279,7 @@ void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob) VECCOPY(fp, pchan->pose_tail); } - Mat4MulVecfl(ob->obmat, fp); + mul_m4_v3(ob->obmat, fp); } } } @@ -405,7 +405,7 @@ static int pose_calculate_paths_exec (bContext *C, wmOperator *op) VECCOPY(fp, pchan->pose_tail); } - Mat4MulVecfl(ob->obmat, fp); + mul_m4_v3(ob->obmat, fp); } } } @@ -531,7 +531,7 @@ void pose_select_constraint_target(Scene *scene) for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if (arm->layer & pchan->bone->layer) { - if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { + if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) { for (con= pchan->constraints.first; con; con= con->next) { bConstraintTypeInfo *cti= constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; @@ -570,7 +570,7 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *op) for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if (arm->layer & pchan->bone->layer) { - if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { + if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) { for (con= pchan->constraints.first; con; con= con->next) { bConstraintTypeInfo *cti= constraint_get_typeinfo(con); ListBase targets = {NULL, NULL}; @@ -635,7 +635,7 @@ static int pose_select_hierarchy_exec(bContext *C, wmOperator *op) curbone= pchan->bone; if ((arm->layer & curbone->layer) && (curbone->flag & BONE_UNSELECTABLE)==0) { - if (curbone->flag & (BONE_ACTIVE)) { + if (curbone == arm->act_bone) { if (direction == BONE_SELECT_PARENT) { if (pchan->parent == NULL) continue; @@ -644,8 +644,8 @@ static int pose_select_hierarchy_exec(bContext *C, wmOperator *op) if ((arm->layer & pabone->layer) && !(pabone->flag & BONE_HIDDEN_P)) { if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; - curbone->flag &= ~BONE_ACTIVE; - pabone->flag |= (BONE_ACTIVE|BONE_SELECTED); + pabone->flag |= BONE_SELECTED; + arm->act_bone= pabone; found= 1; break; @@ -658,8 +658,8 @@ static int pose_select_hierarchy_exec(bContext *C, wmOperator *op) if ((arm->layer & chbone->layer) && !(chbone->flag & BONE_HIDDEN_P)) { if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; - curbone->flag &= ~BONE_ACTIVE; - chbone->flag |= (BONE_ACTIVE|BONE_SELECTED); + chbone->flag |= BONE_SELECTED; + arm->act_bone= chbone; found= 1; break; @@ -717,11 +717,7 @@ void pose_copy_menu(Scene *scene) if (ELEM(NULL, ob, ob->pose)) return; if ((ob==obedit) || (ob->mode & OB_MODE_POSE)==0) return; - /* find active */ - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if (pchan->bone->flag & BONE_ACTIVE) - break; - } + pchan= get_active_posechannel(ob); if (pchan==NULL) return; pchanact= pchan; @@ -818,13 +814,13 @@ void pose_copy_menu(Scene *scene) float tmp_quat[4]; /* need to convert to quat first (in temp var)... */ - Mat4ToQuat(delta_mat, tmp_quat); - QuatToAxisAngle(tmp_quat, pchan->rotAxis, &pchan->rotAngle); + mat4_to_quat( tmp_quat,delta_mat); + quat_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,tmp_quat); } else if (pchan->rotmode == ROT_MODE_QUAT) - Mat4ToQuat(delta_mat, pchan->quat); + mat4_to_quat( pchan->quat,delta_mat); else - Mat4ToEulO(delta_mat, pchan->eul, pchan->rotmode); + mat4_to_eulO( pchan->eul, pchan->rotmode,delta_mat); } break; case 11: /* Visual Size */ @@ -832,7 +828,7 @@ void pose_copy_menu(Scene *scene) float delta_mat[4][4], size[4]; armature_mat_pose_to_bone(pchan, pchanact->pose_mat, delta_mat); - Mat4ToSize(delta_mat, size); + mat4_to_size( size,delta_mat); VECCOPY(pchan->size, size); } } @@ -1024,23 +1020,23 @@ static int pose_paste_exec (bContext *C, wmOperator *op) else if (pchan->rotmode > 0) { /* quat/axis-angle to euler */ if (chan->rotmode == ROT_MODE_AXISANGLE) - AxisAngleToEulO(chan->rotAxis, chan->rotAngle, pchan->eul, pchan->rotmode); + axis_angle_to_eulO( pchan->eul, pchan->rotmode,chan->rotAxis, chan->rotAngle); else - QuatToEulO(chan->quat, pchan->eul, pchan->rotmode); + quat_to_eulO( pchan->eul, pchan->rotmode,chan->quat); } else if (pchan->rotmode == ROT_MODE_AXISANGLE) { /* quat/euler to axis angle */ if (chan->rotmode > 0) - EulOToAxisAngle(chan->eul, chan->rotmode, pchan->rotAxis, &pchan->rotAngle); + eulO_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,chan->eul, chan->rotmode); else - QuatToAxisAngle(chan->quat, pchan->rotAxis, &pchan->rotAngle); + quat_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,chan->quat); } else { /* euler/axis-angle to quat */ if (chan->rotmode > 0) - EulOToQuat(chan->eul, chan->rotmode, pchan->quat); + eulO_to_quat( pchan->quat,chan->eul, chan->rotmode); else - AxisAngleToQuat(pchan->quat, chan->rotAxis, pchan->rotAngle); + axis_angle_to_quat(pchan->quat, chan->rotAxis, pchan->rotAngle); } /* paste flipped pose? */ @@ -1055,10 +1051,10 @@ static int pose_paste_exec (bContext *C, wmOperator *op) else if (pchan->rotmode == ROT_MODE_AXISANGLE) { float eul[3]; - AxisAngleToEulO(pchan->rotAxis, pchan->rotAngle, eul, EULER_ORDER_DEFAULT); + axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,pchan->rotAxis, pchan->rotAngle); eul[1]*= -1; eul[2]*= -1; - EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, pchan->rotAxis, &pchan->rotAngle); + eulO_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,eul, EULER_ORDER_DEFAULT); // experimental method (uncomment to test): #if 0 @@ -1070,10 +1066,10 @@ static int pose_paste_exec (bContext *C, wmOperator *op) else { float eul[3]; - QuatToEul(pchan->quat, eul); + quat_to_eul( eul,pchan->quat); eul[1]*= -1; eul[2]*= -1; - EulToQuat(eul, pchan->quat); + eul_to_quat( pchan->quat,eul); } } @@ -1397,7 +1393,7 @@ static int pose_group_unassign_exec (bContext *C, wmOperator *op) /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ // NOTE: sync this view3d_context() in space_view3d.c if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) { - if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) { + if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) { if (pchan->agrp_index) { pchan->agrp_index= 0; done= 1; @@ -1444,7 +1440,7 @@ static short pose_select_same_group (Object *ob) /* loop in loop... bad and slow! */ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if (arm->layer & pchan->bone->layer) { - if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { + if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) { /* only if group matches (and is not selected or current bone) */ for (chan= ob->pose->chanbase.first; chan; chan= chan->next) { @@ -1476,7 +1472,7 @@ static short pose_select_same_layer (Object *ob) /* figure out what bones are selected */ for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if (arm->layer & pchan->bone->layer) { - if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { + if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) { layers |= pchan->bone->layer; } } @@ -1637,25 +1633,21 @@ void pose_activate_flipped_bone(Scene *scene) ob= modifiers_isDeformedByArmature(ob); } if(ob && (ob->mode & OB_MODE_POSE)) { - bPoseChannel *pchan, *pchanf; + bPoseChannel *pchanf; - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if(arm->layer & pchan->bone->layer) { - if(pchan->bone->flag & BONE_ACTIVE) - break; - } - } - if(pchan) { + if(arm->act_bone) { char name[32]; - BLI_strncpy(name, pchan->name, 32); + BLI_strncpy(name, arm->act_bone->name, 32); bone_flip_name(name, 1); // 0 = do not strip off number extensions pchanf= get_pose_channel(ob->pose, name); - if(pchanf && pchanf!=pchan) { - pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); - pchanf->bone->flag |= (BONE_SELECTED|BONE_ACTIVE); - + if(pchanf && pchanf->bone != arm->act_bone) { + arm->act_bone->flag &= ~BONE_SELECTED; + pchanf->bone->flag |= BONE_SELECTED; + + arm->act_bone= pchanf->bone; + /* in weightpaint we select the associated vertex group too */ if(ob->mode & OB_MODE_WEIGHT_PAINT) { ED_vgroup_select_by_name(OBACT, name); diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index 132d9edf8d0..05b0dc267ff 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -45,7 +45,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_edgehash.h" #include "BLI_ghash.h" @@ -498,12 +498,12 @@ void repositionNodes(ReebGraph *rg) float p[3]; VECCOPY(p, ((ReebArc*)arc)->buckets[0].p); - VecMulf(p, 1.0f / arc->head->degree); - VecAddf(arc->head->p, arc->head->p, p); + mul_v3_fl(p, 1.0f / arc->head->degree); + add_v3_v3v3(arc->head->p, arc->head->p, p); VECCOPY(p, ((ReebArc*)arc)->buckets[((ReebArc*)arc)->bcount - 1].p); - VecMulf(p, 1.0f / arc->tail->degree); - VecAddf(arc->tail->p, arc->tail->p, p); + mul_v3_fl(p, 1.0f / arc->tail->degree); + add_v3_v3v3(arc->tail->p, arc->tail->p, p); } } } @@ -634,15 +634,15 @@ void verifyMultiResolutionLinks(ReebGraph *rg, int level) void addVertToBucket(EmbedBucket *b, float co[3]) { b->nv++; - VecLerpf(b->p, b->p, co, 1.0f / b->nv); + interp_v3_v3v3(b->p, b->p, co, 1.0f / b->nv); } void removeVertFromBucket(EmbedBucket *b, float co[3]) { - VecMulf(b->p, (float)b->nv); - VecSubf(b->p, b->p, co); + mul_v3_fl(b->p, (float)b->nv); + sub_v3_v3v3(b->p, b->p, co); b->nv--; - VecMulf(b->p, 1.0f / (float)b->nv); + mul_v3_fl(b->p, 1.0f / (float)b->nv); } void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc) @@ -650,7 +650,7 @@ void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc) if (bDst->nv > 0 && bSrc->nv > 0) { bDst->nv += bSrc->nv; - VecLerpf(bDst->p, bDst->p, bSrc->p, (float)bSrc->nv / (float)(bDst->nv)); + interp_v3_v3v3(bDst->p, bDst->p, bSrc->p, (float)bSrc->nv / (float)(bDst->nv)); } else if (bSrc->nv > 0) { @@ -797,7 +797,7 @@ static void interpolateBuckets(ReebArc *arc, float *start_p, float *end_p, int s { EmbedBucket *empty = arc->buckets + j; empty->nv = 1; - VecLerpf(empty->p, start_p, end_p, (float)(j - start_index + 1) / total); + interp_v3_v3v3(empty->p, start_p, end_p, (float)(j - start_index + 1) / total); } } @@ -873,20 +873,20 @@ static void ExtendArcBuckets(ReebArc *arc) previous = iter->p, IT_next(iter) ) { - average_length += VecLenf(previous, iter->p); + average_length += len_v3v3(previous, iter->p); } average_length /= (arc->bcount - 1); first_bucket = arc->buckets; last_bucket = arc->buckets + (arc->bcount - 1); - length = VecLenf(first_bucket->p, arc->head->p); + length = len_v3v3(first_bucket->p, arc->head->p); if (length > 2 * average_length) { padding_head = (int)floor(length / average_length); } - length = VecLenf(last_bucket->p, arc->tail->p); + length = len_v3v3(last_bucket->p, arc->tail->p); if (length > 2 * average_length) { padding_tail = (int)floor(length / average_length); @@ -945,12 +945,12 @@ void calculateArcLength(ReebArc *arc) { vec1 = iter->p; - arc->length += VecLenf(vec0, vec1); + arc->length += len_v3v3(vec0, vec1); vec0 = vec1; } - arc->length += VecLenf(arc->tail->p, vec1); + arc->length += len_v3v3(arc->tail->p, vec1); } void calculateGraphLength(ReebGraph *rg) @@ -982,8 +982,8 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) float normal[3]; int j = i + 1; - VecAddf(tangent, ring[i].n, ring[j].n); - Crossf(normal, tangent, axis); + add_v3_v3v3(tangent, ring[i].n, ring[j].n); + cross_v3_v3v3(normal, tangent, axis); node1 = (ReebNode*)BLI_otherNode(ring[i].arc, root_node); node2 = (ReebNode*)BLI_otherNode(ring[j].arc, root_node); @@ -993,7 +993,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) /* mirror first node and mix with the second */ BLI_mirrorAlongAxis(node1->p, root_node->p, normal); - VecLerpf(node2->p, node2->p, node1->p, 1.0f / (j + 1)); + interp_v3_v3v3(node2->p, node2->p, node1->p, 1.0f / (j + 1)); /* Merge buckets * there shouldn't be any null arcs here, but just to be safe @@ -1030,7 +1030,7 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) /* mirror on axis */ BLI_mirrorAlongAxis(bucket1->p, root_node->p, normal); /* add bucket2 in bucket1 */ - VecLerpf(bucket2->p, bucket2->p, bucket1->p, (float)bucket1->nv / (float)(bucket2->nv)); + interp_v3_v3v3(bucket2->p, bucket2->p, bucket1->p, (float)bucket1->nv / (float)(bucket2->nv)); } } } @@ -1044,8 +1044,8 @@ void REEB_RadialSymmetry(BNode* root_node, RadialArc* ring, int count) float normal[3]; int j = i - 1; - VecAddf(tangent, ring[i].n, ring[j].n); - Crossf(normal, tangent, axis); + add_v3_v3v3(tangent, ring[i].n, ring[j].n); + cross_v3_v3v3(normal, tangent, axis); node1 = (ReebNode*)BLI_otherNode(ring[i].arc, root_node); node2 = (ReebNode*)BLI_otherNode(ring[j].arc, root_node); @@ -1111,8 +1111,8 @@ void REEB_AxialSymmetry(BNode* root_node, BNode* node1, BNode* node2, struct BAr BLI_mirrorAlongAxis(p, root_node->p, nor); /* average with node1 */ - VecAddf(node1->p, node1->p, p); - VecMulf(node1->p, 0.5f); + add_v3_v3v3(node1->p, node1->p, p); + mul_v3_fl(node1->p, 0.5f); /* mirror back on node2 */ VECCOPY(node2->p, node1->p); @@ -1153,7 +1153,7 @@ void REEB_AxialSymmetry(BNode* root_node, BNode* node1, BNode* node2, struct BAr /* mirror on axis */ BLI_mirrorAlongAxis(bucket2->p, root_node->p, nor); /* add bucket2 in bucket1 */ - VecLerpf(bucket1->p, bucket1->p, bucket2->p, (float)bucket2->nv / (float)(bucket1->nv)); + interp_v3_v3v3(bucket1->p, bucket1->p, bucket2->p, (float)bucket2->nv / (float)(bucket1->nv)); /* copy and mirror back to bucket2 */ bucket2->nv = bucket1->nv; @@ -1200,8 +1200,8 @@ void postprocessGraph(ReebGraph *rg, char mode) for(index = 1; index < bcount - 1; index++) { - VecLerpf(buckets[index].p, buckets[index].p, buckets[index - 1].p, fac1 / (fac1 + fac2)); - VecLerpf(buckets[index].p, buckets[index].p, buckets[index + 1].p, fac3 / (fac1 + fac2 + fac3)); + interp_v3_v3v3(buckets[index].p, buckets[index].p, buckets[index - 1].p, fac1 / (fac1 + fac2)); + interp_v3_v3v3(buckets[index].p, buckets[index].p, buckets[index + 1].p, fac3 / (fac1 + fac2 + fac3)); } } } @@ -1339,7 +1339,7 @@ int joinSubgraphsEnds(ReebGraph *rg, float threshold, int nb_subgraphs) { if (end_node->subgraph_index != subgraph) { - float distance = VecLenf(start_node->p, end_node->p); + float distance = len_v3v3(start_node->p, end_node->p); if (distance < threshold && distance < min_distance) { @@ -1597,7 +1597,7 @@ void filterNullReebGraph(ReebGraph *rg) blend = (float)newNode->degree / (float)(newNode->degree + removedNode->degree); // blending factors - VecLerpf(newNode->p, removedNode->p, newNode->p, blend); + interp_v3_v3v3(newNode->p, removedNode->p, newNode->p, blend); filterArc(rg, newNode, removedNode, arc, 0); @@ -1808,16 +1808,16 @@ int filterSmartReebGraph(ReebGraph *rg, float threshold) VECCOPY(midpoint, vec1); - distance = VecLenf(midpoint, efa->cent); + distance = len_v3v3(midpoint, efa->cent); if (min_distance == -1 || distance < min_distance) { min_distance = distance; - VecSubf(tangent, vec1, vec0); - Normalize(tangent); + sub_v3_v3v3(tangent, vec1, vec0); + normalize_v3(tangent); - angle = Inpf(tangent, efa->n); + angle = dot_v3v3(tangent, efa->n); } previous = bucket; @@ -1829,7 +1829,7 @@ int filterSmartReebGraph(ReebGraph *rg, float threshold) efa->tmp.fp = saacos(fabs(angle)); #endif #else - VecAddf(avg_vec, avg_vec, efa->n); + add_v3_v3v3(avg_vec, avg_vec, efa->n); #endif } @@ -1837,8 +1837,8 @@ int filterSmartReebGraph(ReebGraph *rg, float threshold) #if 0 avg_angle /= total; #else - VecMulf(avg_vec, 1.0 / total); - avg_angle = Inpf(avg_vec, avg_vec); + mul_v3_fl(avg_vec, 1.0 / total); + avg_angle = dot_v3v3(avg_vec, avg_vec); #endif arc->angle = avg_angle; @@ -2064,8 +2064,8 @@ void REEB_exportGraph(ReebGraph *rg, int count) fprintf(f, "b nv:%i %f %f %f\n", arc->buckets[i].nv, arc->buckets[i].p[0], arc->buckets[i].p[1], arc->buckets[i].p[2]); } - VecAddf(p, arc->tail->p, arc->head->p); - VecMulf(p, 0.5f); + add_v3_v3v3(p, arc->tail->p, arc->head->p); + mul_v3_fl(p, 0.5f); fprintf(f, "angle %0.3f %0.3f %0.3f %0.3f %i\n", p[0], p[1], p[2], arc->angle, BLI_ghash_size(arc->faces)); exportNode(f, "v2", arc->tail); @@ -2501,7 +2501,7 @@ ReebEdge * createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) float co[3]; float f = (arc->buckets[i].val - offset) / len; - VecLerpf(co, v1->p, v2->p, f); + interp_v3_v3v3(co, v1->p, v2->p, f); addVertToBucket(&(arc->buckets[i]), co); } #endif @@ -2690,16 +2690,16 @@ static float cotan_weight(float *v1, float *v2, float *v3) { float a[3], b[3], c[3], clen; - VecSubf(a, v2, v1); - VecSubf(b, v3, v1); - Crossf(c, a, b); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v3, v1); + cross_v3_v3v3(c, a, b); - clen = VecLength(c); + clen = len_v3(c); if (clen == 0.0f) return 0.0f; - return Inpf(a, b)/clen; + return dot_v3v3(a, b)/clen; } void addTriangle(EditVert *v1, EditVert *v2, EditVert *v3, int e1, int e2, int e3) @@ -3077,7 +3077,7 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) { if (eed->v1->h == 0 && eed->v2->h == 0) { - eed->tmp.fp = VecLenf(eed->v1->co, eed->v2->co); + eed->tmp.fp = len_v3v3(eed->v1->co, eed->v2->co); } } @@ -3112,7 +3112,7 @@ int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges) /* vertex is already processed and distance is smaller than current minimum */ if (closest_eve->f1 == 1) { - float distance = VecLenf(closest_eve->co, eve->co); + float distance = len_v3v3(closest_eve->co, eve->co); if (distance < min_distance) { min_distance = distance; @@ -3688,7 +3688,7 @@ void REEB_draw() if (G.scene->toolsettings->skgen_options & SKGEN_DISP_INDEX) { - VecLerpf(vec, arc->head->p, arc->tail->p, 0.5f); + interp_v3_v3v3(vec, arc->head->p, arc->tail->p, 0.5f); s += sprintf(s, "%i (%i-%i-%i) ", i, arc->symmetry_level, arc->symmetry_flag, arc->symmetry_group); if (G.scene->toolsettings->skgen_options & SKGEN_DISP_WEIGHT) diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index 929e3514990..4c5bcb71499 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -40,7 +40,7 @@ #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_context.h" diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index a58439051e9..7801168dd83 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "BLI_rand.h" @@ -525,7 +525,7 @@ static void rotateflagNurb(ListBase *editnurb, short flag, float *cent, float ro bp->vec[0]-=cent[0]; bp->vec[1]-=cent[1]; bp->vec[2]-=cent[2]; - Mat3MulVecfl(rotmat, bp->vec); + mul_m3_v3(rotmat, bp->vec); bp->vec[0]+=cent[0]; bp->vec[1]+=cent[1]; bp->vec[2]+=cent[2]; @@ -549,9 +549,9 @@ static void translateflagNurb(ListBase *editnurb, short flag, float *vec) a= nu->pntsu; bezt= nu->bezt; while(a--) { - if(bezt->f1 & flag) VecAddf(bezt->vec[0], bezt->vec[0], vec); - if(bezt->f2 & flag) VecAddf(bezt->vec[1], bezt->vec[1], vec); - if(bezt->f3 & flag) VecAddf(bezt->vec[2], bezt->vec[2], vec); + if(bezt->f1 & flag) add_v3_v3v3(bezt->vec[0], bezt->vec[0], vec); + if(bezt->f2 & flag) add_v3_v3v3(bezt->vec[1], bezt->vec[1], vec); + if(bezt->f3 & flag) add_v3_v3v3(bezt->vec[2], bezt->vec[2], vec); bezt++; } } @@ -559,7 +559,7 @@ static void translateflagNurb(ListBase *editnurb, short flag, float *vec) a= nu->pntsu*nu->pntsv; bp= nu->bp; while(a--) { - if(bp->f1 & flag) VecAddf(bp->vec, bp->vec, vec); + if(bp->f1 & flag) add_v3_v3v3(bp->vec, bp->vec, vec); bp++; } } @@ -1868,18 +1868,18 @@ static int subdivide_exec(bContext *C, wmOperator *op) memcpy(beztn, bezt, sizeof(BezTriple)); /* midpoint subdividing */ - VecMidf(vec, prevbezt->vec[1], prevbezt->vec[2]); - VecMidf(vec+3, prevbezt->vec[2], bezt->vec[0]); - VecMidf(vec+6, bezt->vec[0], bezt->vec[1]); + mid_v3_v3v3(vec, prevbezt->vec[1], prevbezt->vec[2]); + mid_v3_v3v3(vec+3, prevbezt->vec[2], bezt->vec[0]); + mid_v3_v3v3(vec+6, bezt->vec[0], bezt->vec[1]); - VecMidf(vec+9, vec, vec+3); - VecMidf(vec+12, vec+3, vec+6); + mid_v3_v3v3(vec+9, vec, vec+3); + mid_v3_v3v3(vec+12, vec+3, vec+6); /* change handle of prev beztn */ VECCOPY((beztn-1)->vec[2], vec); /* new point */ VECCOPY(beztn->vec[0], vec+9); - VecMidf(beztn->vec[1], vec+9, vec+12); + mid_v3_v3v3(beztn->vec[1], vec+9, vec+12); VECCOPY(beztn->vec[2], vec+12); /* handle of next bezt */ if(a==0 && (nu->flagu & CU_CYCLIC)) {VECCOPY(beztnew->vec[0], vec+6);} @@ -2662,10 +2662,10 @@ static void make_selection_list_nurb(ListBase *editnurb) bp= nu->bp; a= nu->pntsu; while(a--) { - VecAddf(nus->vec, nus->vec, bp->vec); + add_v3_v3v3(nus->vec, nus->vec, bp->vec); bp++; } - VecMulf(nus->vec, 1.0/(float)nu->pntsu); + mul_v3_fl(nus->vec, 1.0/(float)nu->pntsu); } @@ -2684,13 +2684,13 @@ static void make_selection_list_nurb(ListBase *editnurb) nustest= nbase.first; while(nustest) { - dist= VecLenf(nustest->vec, ((NurbSort *)nsortbase.first)->vec); + dist= len_v3v3(nustest->vec, ((NurbSort *)nsortbase.first)->vec); if(dist<headdist) { headdist= dist; headdo= nustest; } - dist= VecLenf(nustest->vec, ((NurbSort *)nsortbase.last)->vec); + dist= len_v3v3(nustest->vec, ((NurbSort *)nsortbase.last)->vec); if(dist<taildist) { taildist= dist; @@ -2774,7 +2774,7 @@ static void merge_2_nurb(wmOperator *op, ListBase *editnurb, Nurb *nu1, Nurb *nu len1= 0.0; for(v=0; v<nu1->pntsv; v++, bp1+=nu1->pntsu, bp2+=nu2->pntsu) { - len1+= VecLenf(bp1->vec, bp2->vec); + len1+= len_v3v3(bp1->vec, bp2->vec); } bp1= nu1->bp + nu1->pntsu-1; @@ -2782,7 +2782,7 @@ static void merge_2_nurb(wmOperator *op, ListBase *editnurb, Nurb *nu1, Nurb *nu len2= 0.0; for(v=0; v<nu1->pntsv; v++, bp1+=nu1->pntsu, bp2-=nu2->pntsu) { - len2+= VecLenf(bp1->vec, bp2->vec); + len2+= len_v3v3(bp1->vec, bp2->vec); } /* merge */ @@ -3136,13 +3136,13 @@ static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, sho float persmat[3][3], persinv[3][3]; short a,ok, changed= 0; - if(mode != 2 && rv3d) Mat3CpyMat4(persmat, rv3d->viewmat); - else Mat3One(persmat); - Mat3Inv(persinv, persmat); + if(mode != 2 && rv3d) copy_m3_m4(persmat, rv3d->viewmat); + else unit_m3(persmat); + invert_m3_m3(persinv, persmat); /* imat and center and size */ - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); if(v3d) { curs= give_cursor(scene, v3d); @@ -3151,8 +3151,8 @@ static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, sho else cent[0]= cent[1]= cent[2]= 0.0f; - VecSubf(cent, cent, obedit->obmat[3]); - Mat3MulVecfl(imat,cent); + sub_v3_v3v3(cent, cent, obedit->obmat[3]); + mul_m3_v3(imat,cent); if(dvec || mode==2 || !rv3d) { n[0]=n[1]= 0.0; @@ -3161,7 +3161,7 @@ static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, sho n[0]= rv3d->viewinv[2][0]; n[1]= rv3d->viewinv[2][1]; n[2]= rv3d->viewinv[2][2]; - Normalize(n); + normalize_v3(n); } phi= M_PI/8.0; @@ -3170,27 +3170,27 @@ static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, sho q[1]= n[0]*si; q[2]= n[1]*si; q[3]= n[2]*si; - QuatToMat3(q, cmat); - Mat3MulMat3(tmat, cmat, bmat); - Mat3MulMat3(rotmat, imat, tmat); + quat_to_mat3( cmat,q); + mul_m3_m3m3(tmat, cmat, bmat); + mul_m3_m3m3(rotmat, imat, tmat); - Mat3One(scalemat1); + unit_m3(scalemat1); scalemat1[0][0]= sqrt(2.0); scalemat1[1][1]= sqrt(2.0); - Mat3MulMat3(tmat,persmat,bmat); - Mat3MulMat3(cmat,scalemat1,tmat); - Mat3MulMat3(tmat,persinv,cmat); - Mat3MulMat3(scalemat1,imat,tmat); + mul_m3_m3m3(tmat,persmat,bmat); + mul_m3_m3m3(cmat,scalemat1,tmat); + mul_m3_m3m3(tmat,persinv,cmat); + mul_m3_m3m3(scalemat1,imat,tmat); - Mat3One(scalemat2); + unit_m3(scalemat2); scalemat2[0][0]/= sqrt(2.0); scalemat2[1][1]/= sqrt(2.0); - Mat3MulMat3(tmat,persmat,bmat); - Mat3MulMat3(cmat,scalemat2,tmat); - Mat3MulMat3(tmat,persinv,cmat); - Mat3MulMat3(scalemat2,imat,tmat); + mul_m3_m3m3(tmat,persmat,bmat); + mul_m3_m3m3(cmat,scalemat2,tmat); + mul_m3_m3m3(tmat,persinv,cmat); + mul_m3_m3m3(scalemat2,imat,tmat); ok= 1; @@ -3216,7 +3216,7 @@ static int spin_nurb(bContext *C, Scene *scene, Object *obedit, float *dvec, sho } } if(dvec) { - Mat3MulVecfl(bmat,dvec); + mul_m3_v3(bmat,dvec); translateflagNurb(editnurb, 1,dvec); } } @@ -3275,8 +3275,8 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) BPoint *bp, *newbp = NULL; float mat[3][3],imat[3][3], temp[3]; - Mat3CpyMat4(mat, obedit->obmat); - Mat3Inv(imat,mat); + copy_m3_m4(mat, obedit->obmat); + invert_m3_m3(imat,mat); findselectedNurbvert(editnurb, &nu, &bezt, &bp); if(bezt==0 && bp==0) return OPERATOR_CANCELLED; @@ -3322,11 +3322,11 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) } else { VECCOPY(newbezt->vec[1], location); - VecSubf(newbezt->vec[1],newbezt->vec[1], obedit->obmat[3]); - Mat3MulVecfl(imat,newbezt->vec[1]); - VecSubf(temp, newbezt->vec[1],temp); - VecAddf(newbezt->vec[0], bezt->vec[0],temp); - VecAddf(newbezt->vec[2], bezt->vec[2],temp); + sub_v3_v3v3(newbezt->vec[1],newbezt->vec[1], obedit->obmat[3]); + mul_m3_v3(imat,newbezt->vec[1]); + sub_v3_v3v3(temp, newbezt->vec[1],temp); + add_v3_v3v3(newbezt->vec[0], bezt->vec[0],temp); + add_v3_v3v3(newbezt->vec[2], bezt->vec[2],temp); calchandlesNurb(nu); } } @@ -3368,8 +3368,8 @@ static int addvert_Nurb(bContext *C, short mode, float location[3]) } else { VECCOPY(newbp->vec, location); - VecSubf(newbp->vec, newbp->vec, obedit->obmat[3]); - Mat3MulVecfl(imat,newbp->vec); + sub_v3_v3v3(newbp->vec, newbp->vec, obedit->obmat[3]); + mul_m3_v3(imat,newbp->vec); newbp->vec[3]= 1.0; } } @@ -4633,7 +4633,7 @@ int join_curve_exec(bContext *C, wmOperator *op) tempbase.first= tempbase.last= 0; /* trasnform all selected curves inverse in obact */ - Mat4Invert(imat, ob->obmat); + invert_m4_m4(imat, ob->obmat); CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { if(base->object->type==ob->type) { @@ -4643,7 +4643,7 @@ int join_curve_exec(bContext *C, wmOperator *op) if(cu->nurb.first) { /* watch it: switch order here really goes wrong */ - Mat4MulMat4(cmat, base->object->obmat, imat); + mul_m4_m4m4(cmat, base->object->obmat, imat); nu= cu->nurb.first; while(nu) { @@ -4653,16 +4653,16 @@ int join_curve_exec(bContext *C, wmOperator *op) if( (bezt= newnu->bezt) ) { a= newnu->pntsu; while(a--) { - Mat4MulVecfl(cmat, bezt->vec[0]); - Mat4MulVecfl(cmat, bezt->vec[1]); - Mat4MulVecfl(cmat, bezt->vec[2]); + mul_m4_v3(cmat, bezt->vec[0]); + mul_m4_v3(cmat, bezt->vec[1]); + mul_m4_v3(cmat, bezt->vec[2]); bezt++; } } if( (bp= newnu->bp) ) { a= newnu->pntsu*nu->pntsv; while(a--) { - Mat4MulVecfl(cmat, bp->vec); + mul_m4_v3(cmat, bp->vec); bp++; } } @@ -4716,7 +4716,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) /* imat and center and size */ if(obedit) { - Mat3CpyMat4(mat, obedit->obmat); + copy_m3_m4(mat, obedit->obmat); if(v3d) { curs= give_cursor(scene, v3d); VECCOPY(cent, curs); @@ -4730,16 +4730,16 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) if(rv3d) { if (!newname && (U.flag & USER_ADD_VIEWALIGNED)) - Mat3CpyMat4(imat, rv3d->viewmat); + copy_m3_m4(imat, rv3d->viewmat); else - Mat3One(imat); + unit_m3(imat); - Mat3MulVecfl(imat, cent); - Mat3MulMat3(cmat, imat, mat); - Mat3Inv(imat, cmat); + mul_m3_v3(imat, cent); + mul_m3_m3m3(cmat, imat, mat); + invert_m3_m3(imat, cmat); } else - Mat3One(imat); + unit_m3(imat); setflagsNurb(editnurb, 0); } @@ -4779,7 +4779,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bezt->vec[0][1]+= -0.5*grid; bezt->vec[2][0]+= -0.5*grid; bezt->vec[2][1]+= 0.5*grid; - for(a=0;a<3;a++) Mat3MulVecfl(imat, bezt->vec[a]); + for(a=0;a<3;a++) mul_m3_v3(imat, bezt->vec[a]); bezt++; bezt->h1= bezt->h2= HD_ALIGN; @@ -4790,7 +4790,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) VECCOPY(bezt->vec[a], cent); } bezt->vec[1][0]+= grid; - for(a=0;a<3;a++) Mat3MulVecfl(imat, bezt->vec[a]); + for(a=0;a<3;a++) mul_m3_v3(imat, bezt->vec[a]); calchandlesNurb(nu); } @@ -4821,7 +4821,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp->vec[0]+= 1.5*grid; bp= nu->bp; - for(a=0;a<4;a++, bp++) Mat3MulVecfl(imat,bp->vec); + for(a=0;a<4;a++, bp++) mul_m3_v3(imat,bp->vec); if(cutype==CU_NURBS) { nu->knotsu= 0; /* makeknots allocates */ @@ -4856,7 +4856,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp->vec[0]+= 2.0*grid; bp= nu->bp; - for(a=0;a<5;a++, bp++) Mat3MulVecfl(imat,bp->vec); + for(a=0;a<5;a++, bp++) mul_m3_v3(imat,bp->vec); if(cutype==CU_NURBS) { nu->knotsu= 0; /* makeknots allocates */ @@ -4883,7 +4883,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][0]+= -grid; - for(a=0;a<3;a++) Mat3MulVecfl(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; bezt++; @@ -4893,7 +4893,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][1]+= grid; - for(a=0;a<3;a++) Mat3MulVecfl(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; bezt++; @@ -4903,7 +4903,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][0]+= grid; - for(a=0;a<3;a++) Mat3MulVecfl(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; bezt++; @@ -4913,7 +4913,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bezt->h1= bezt->h2= HD_AUTO; bezt->f1= bezt->f2= bezt->f3= SELECT; bezt->vec[1][1]+= -grid; - for(a=0;a<3;a++) Mat3MulVecfl(imat,bezt->vec[a]); + for(a=0;a<3;a++) mul_m3_v3(imat,bezt->vec[a]); bezt->radius = bezt->weight = 1.0; calchandlesNurb(nu); @@ -4940,7 +4940,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) } if(a & 1) bp->vec[3]= 0.25*sqrt(2.0); else bp->vec[3]= 1.0; - Mat3MulVecfl(imat,bp->vec); + mul_m3_v3(imat,bp->vec); bp->radius = bp->weight = 1.0; bp++; @@ -4977,7 +4977,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) if(a==1 || a==2) if(b==1 || b==2) { bp->vec[2]+= grid; } - Mat3MulVecfl(imat,bp->vec); + mul_m3_v3(imat,bp->vec); bp->vec[3]= 1.0; bp++; } @@ -5000,7 +5000,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) BLI_addtail(editnurb, nu); /* temporal for extrude and translate */ vec[0]=vec[1]= 0.0; vec[2]= -grid; - Mat3MulVecfl(imat, vec); + mul_m3_v3(imat, vec); translateflagNurb(editnurb, 1, vec); extrudeflagNurb(editnurb, 1); vec[0]= -2*vec[0]; @@ -5042,7 +5042,7 @@ Nurb *add_nurbs_primitive(bContext *C, int type, int newname) bp->vec[2]+= nurbcircle[a][1]*grid; if(a & 1) bp->vec[3]= 0.5*sqrt(2.0); else bp->vec[3]= 1.0; - Mat3MulVecfl(imat,bp->vec); + mul_m3_v3(imat,bp->vec); bp++; } nu->flagu= 4; diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 6ebc9c8a1c9..b6b0289e871 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_curve_types.h" #include "DNA_object_types.h" @@ -541,7 +541,7 @@ void ED_text_to_object(bContext *C, Text *text, int split_lines) offset[2] = 0; if(rv3d) - Mat4Mul3Vecfl(rv3d->viewinv, offset); + mul_mat3_m4_v3(rv3d->viewinv, offset); txt_add_object(C, line, 1, offset); diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 81ee2378717..6651c7745bb 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -37,7 +37,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_gpencil_types.h" @@ -326,7 +326,7 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, /* calculate gradient and normal - 'angle'=(ny/nx) */ m1[1]= s1[1] - s0[1]; m1[0]= s1[0] - s0[0]; - Normalize2(m1); + normalize_v2(m1); m2[1]= -m1[0]; m2[0]= m1[1]; @@ -374,7 +374,7 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, /* calculate gradient of bisector (as average of normals) */ mb[0]= (pm[0] + m2[0]) / 2; mb[1]= (pm[1] + m2[1]) / 2; - Normalize2(mb); + normalize_v2(mb); /* calculate gradient to apply * - as basis, use just pthick * bisector gradient @@ -382,7 +382,7 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, */ mt[0]= mb[0] * pthick; mt[1]= mb[1] * pthick; - athick= Vec2Length(mt); + athick= len_v2(mt); dfac= pthick - (athick * 2); if ( ((athick * 2) < pthick) && (IS_EQ(athick, pthick)==0) ) { @@ -442,7 +442,7 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, } /* store stroke's 'natural' normal for next stroke to use */ - Vec2Copyf(pm, m2); + copy_v2_v2(pm, m2); } glEnd(); @@ -744,47 +744,25 @@ void draw_gpencil_2dview (bContext *C, short onlyv2d) /* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, second time with only3d=0 for screen-aligned strokes */ -void draw_gpencil_3dview (bContext *C, short only3d) +void draw_gpencil_3dview_ext (Scene *scene, ARegion *ar, short only3d) { - ARegion *ar= CTX_wm_region(C); - Scene *scene= CTX_data_scene(C); bGPdata *gpd; int dflag = 0; - + /* check that we have grease-pencil stuff to draw */ - gpd= gpencil_data_get_active(C); // XXX - if (gpd == NULL) return; - + gpd= gpencil_data_get_active_v3d(scene); // XXX + if(gpd == NULL) return; + /* draw it! */ if (only3d) dflag |= (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_NOSTATUS); gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag); } -/* draw grease-pencil sketches to opengl render window assuming that matrices are already set correctly */ -// XXX porting note, ogl render will probably be a window with one 3d region -void draw_gpencil_oglrender (bContext *C) +void draw_gpencil_3dview (bContext *C, short only3d) { - ScrArea *sa= CTX_wm_area(C); - View3D *v3d= (View3D *)sa->spacedata.first; ARegion *ar= CTX_wm_region(C); Scene *scene= CTX_data_scene(C); - bGPdata *gpd; - - /* assume gpencil data comes from v3d */ - if (v3d == NULL) return; - gpd= gpencil_data_get_active(C); - if (gpd == NULL) return; - - /* pass 1: draw 3d-strokes ------------ > */ - gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, (GP_DRAWDATA_NOSTATUS|GP_DRAWDATA_ONLY3D)); - - /* pass 2: draw 2d-strokes ------------ > */ - /* adjust view matrices */ - wmOrtho2(-0.375f, (float)(ar->winx)-0.375f, -0.375f, (float)(ar->winy)-0.375f); // XXX may not be correct anymore - glLoadIdentity(); - - /* draw it! */ - gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, GP_DRAWDATA_NOSTATUS); + draw_gpencil_3dview_ext(scene, ar, only3d); } /* ************************************************** */ diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c index beb4ed06810..88ceba88827 100644 --- a/source/blender/editors/gpencil/editaction_gpencil.c +++ b/source/blender/editors/gpencil/editaction_gpencil.c @@ -33,7 +33,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_listBase.h" diff --git a/source/blender/editors/gpencil/gpencil_buttons.c b/source/blender/editors/gpencil/gpencil_buttons.c index b25de4d5f1d..4da5ec02ddc 100644 --- a/source/blender/editors/gpencil/gpencil_buttons.c +++ b/source/blender/editors/gpencil/gpencil_buttons.c @@ -32,7 +32,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_gpencil_types.h" diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 8cf1affa8c6..c2b9a1a4bb9 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -37,7 +37,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_listBase.h" @@ -45,6 +45,7 @@ #include "DNA_curve_types.h" #include "DNA_gpencil_types.h" #include "DNA_object_types.h" +#include "DNA_node_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" @@ -113,9 +114,18 @@ bGPdata **gpencil_data_get_pointers (bContext *C, PointerRNA *ptr) case SPACE_NODE: /* Nodes Editor */ { - //SpaceNode *snode= (SpaceNode *)CTX_wm_space_data(C); + SpaceNode *snode= (SpaceNode *)CTX_wm_space_data(C); /* return the GP data for the active node block/node */ + if (snode && snode->nodetree) { + /* for now, as long as there's an active node tree, default to using that in the Nodes Editor */ + if (ptr) RNA_id_pointer_create(&snode->nodetree->id, ptr); + return &snode->nodetree->gpd; + } + else { + /* even when there is no node-tree, don't allow this to flow to scene */ + return NULL; + } } break; @@ -155,6 +165,13 @@ bGPdata *gpencil_data_get_active (bContext *C) return (gpd_ptr) ? *(gpd_ptr) : NULL; } +/* needed for offscreen rendering */ +bGPdata *gpencil_data_get_active_v3d (Scene *scene) +{ + bGPdata *gpd= scene->basact ? scene->basact->object->gpd : NULL; + return gpd ? gpd : scene->gpd; +} + /* ************************************************ */ /* Panel Operators */ @@ -361,7 +378,7 @@ static void gp_strokepoint_convertcoords (bContext *C, bGPDstroke *gps, bGPDspoi if (gps->flag & GP_STROKE_3DSPACE) { /* directly use 3d-coordinates */ - VecCopyf(p3d, &pt->x); + copy_v3_v3(p3d, &pt->x); } else { float *fp= give_cursor(scene, v3d); @@ -386,7 +403,7 @@ static void gp_strokepoint_convertcoords (bContext *C, bGPDstroke *gps, bGPDspoi */ project_short_noclip(ar, fp, mval); window_to_3d(ar, dvec, mval[0]-mx, mval[1]-my); - VecSubf(p3d, fp, dvec); + sub_v3_v3v3(p3d, fp, dvec); } } @@ -417,7 +434,7 @@ static void gp_stroke_to_path (bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cur /* get coordinates to add at */ gp_strokepoint_convertcoords(C, gps, pt, p3d); - VecCopyf(bp->vec, p3d); + copy_v3_v3(bp->vec, p3d); /* set settings */ bp->f1= SELECT; @@ -453,9 +470,9 @@ static void gp_stroke_to_bezier (bContext *C, bGPDlayer *gpl, bGPDstroke *gps, C gp_strokepoint_convertcoords(C, gps, pt, p3d); /* TODO: maybe in future the handles shouldn't be in same place */ - VecCopyf(bezt->vec[0], p3d); - VecCopyf(bezt->vec[1], p3d); - VecCopyf(bezt->vec[2], p3d); + copy_v3_v3(bezt->vec[0], p3d); + copy_v3_v3(bezt->vec[1], p3d); + copy_v3_v3(bezt->vec[2], p3d); /* set settings */ bezt->h1= bezt->h2= HD_FREE; diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 92ae2400666..4229c66353c 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_gpencil.h" #include "BKE_context.h" @@ -169,11 +169,11 @@ static void gp_get_3d_reference (tGPsdata *p, float *vec) /* active Object * - use relative distance of 3D-cursor from object center */ - VecSubf(vec, fp, ob->loc); + sub_v3_v3v3(vec, fp, ob->loc); } else { /* use 3D-cursor */ - VecCopyf(vec, fp); + copy_v3_v3(vec, fp); } } @@ -228,7 +228,7 @@ static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[]) /* method taken from editview.c - mouse_cursor() */ project_short_noclip(p->ar, rvec, mval); window_to_3d_delta(p->ar, dvec, mval[0]-mx, mval[1]-my); - VecSubf(out, rvec, dvec); + sub_v3_v3v3(out, rvec, dvec); } /* 2d - on 'canvas' (assume that p->v2d is set) */ @@ -808,16 +808,17 @@ static tGPsdata *gp_session_initpaint (bContext *C) #endif } break; -#if 0 // XXX these other spaces will come over time... + case SPACE_NODE: { - SpaceNode *snode= curarea->spacedata.first; + //SpaceNode *snode= curarea->spacedata.first; /* set current area */ p->sa= curarea; p->ar= ar; p->v2d= &ar->v2d; +#if 0 // XXX will this sort of antiquated stuff be restored? /* check that gpencil data is allowed to be drawn */ if ((snode->flag & SNODE_DISPGP)==0) { p->status= GP_STATUS_ERROR; @@ -825,8 +826,10 @@ static tGPsdata *gp_session_initpaint (bContext *C) printf("Error: In active view, Grease Pencil not shown \n"); return; } +#endif } break; +#if 0 // XXX these other spaces will come over time... case SPACE_SEQ: { SpaceSeq *sseq= curarea->spacedata.first; @@ -983,12 +986,13 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode) p->gpd->sbuffer_sflag |= GP_STROKE_3DSPACE; } break; -#if 0 // XXX other spacetypes to be restored in due course + case SPACE_NODE: { p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE; } break; +#if 0 // XXX other spacetypes to be restored in due course case SPACE_SEQ: { SpaceSeq *sseq= (SpaceSeq *)p->sa->spacedata.first; @@ -1298,12 +1302,15 @@ static int gpencil_draw_invoke (bContext *C, wmOperator *op, wmEvent *event) tGPsdata *p = NULL; wmWindow *win= CTX_wm_window(C); - //printf("GPencil - Starting Drawing \n"); + if (G.f & G_DEBUG) + printf("GPencil - Starting Drawing \n"); /* try to initialise context data needed while drawing */ if (!gpencil_draw_init(C, op)) { - if (op->customdata) MEM_freeN(op->customdata); - printf("\tGP - no valid data \n"); + if (op->customdata) + MEM_freeN(op->customdata); + if (G.f & G_DEBUG) + printf("\tGP - no valid data \n"); return OPERATOR_CANCELLED; } else diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 316f1b58d33..5c83d685362 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -140,6 +140,7 @@ typedef enum eAnim_ChannelType { ANIMTYPE_DSCUR, ANIMTYPE_DSSKEY, ANIMTYPE_DSWOR, + ANIMTYPE_DSNTREE, ANIMTYPE_DSPART, ANIMTYPE_DSMBALL, ANIMTYPE_DSARM, @@ -202,6 +203,7 @@ typedef enum eAnimFilter_Flags { #define EXPANDED_SCEC(sce) ((sce->flag & SCE_DS_COLLAPSED)==0) /* 'Sub-Scene' channels (flags stored in Data block) */ #define FILTER_WOR_SCED(wo) ((wo->flag & WO_DS_EXPAND)) +#define FILTER_NTREE_SCED(ntree) ((ntree->flag & NTREE_DS_EXPAND)) /* 'Object' channels */ #define SEL_OBJC(base) ((base->flag & SELECT)) #define EXPANDED_OBJC(ob) ((ob->nlaflag & OB_ADS_COLLAPSED)==0) @@ -424,12 +426,8 @@ void ANIM_uiTemplate_fmodifier_draw(struct uiLayout *layout, struct ID *id, List /* ------------ Animation F-Curves <-> Icons/Names Mapping ------------ */ /* anim_ipo_utils.c */ -/* Get icon for type of setting F-Curve is for */ -// XXX include this in the getname() method via RNA? -int geticon_anim_blocktype(short blocktype); - -/* Get name for channel-list displays for F-Curve */ -void getname_anim_fcurve(char *name, struct ID *id, struct FCurve *fcu); +/* Get icon + name for channel-list displays for F-Curve */ +int getname_anim_fcurve(char *name, struct ID *id, struct FCurve *fcu); /* Automatically determine a color for the nth F-Curve */ void ipo_rainbow(int cur, int tot, float *out); diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 5cc35d4ad77..1836729e419 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -113,6 +113,7 @@ struct Bone *get_indexed_bone (struct Object *ob, int index); float ED_rollBoneToVector(EditBone *bone, float new_up_axis[3]); EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, EditBone *ebo); // XXX this is needed for populating the context iterators void ED_armature_sync_selection(struct ListBase *edbo); +void ED_armature_validate_active(struct bArmature *arm); void add_primitive_bone(struct Scene *scene, struct View3D *v3d, struct RegionView3D *rv3d); EditBone *addEditBone(struct bArmature *arm, char *name); /* used by COLLADA importer */ diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index ff95f8ce6eb..ef5169465ab 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -59,6 +59,7 @@ typedef struct tGPspoint { struct bGPdata **gpencil_data_get_pointers(struct bContext *C, struct PointerRNA *ptr); struct bGPdata *gpencil_data_get_active(struct bContext *C); +struct bGPdata *gpencil_data_get_active_v3d(struct Scene *scene); /* for offscreen rendering */ /* ----------- Grease Pencil Operators ----------------- */ @@ -71,7 +72,7 @@ void ED_operatortypes_gpencil(void); void draw_gpencil_2dimage(struct bContext *C, struct ImBuf *ibuf); void draw_gpencil_2dview(struct bContext *C, short onlyv2d); void draw_gpencil_3dview(struct bContext *C, short only3d); -void draw_gpencil_oglrender(struct bContext *C); +void draw_gpencil_3dview_ext(struct Scene *scene, struct ARegion *ar, short only3d); void gpencil_panel_standard(const struct bContext *C, struct Panel *pa); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index b2d92869a2f..f9cf6edc6ac 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -91,9 +91,6 @@ int object_is_libdata(struct Object *ob); int object_data_is_libdata(struct Object *ob); /* constraints */ -struct bConstraint *add_new_constraint(short type); -void add_constraint_to_object(struct bConstraint *con, struct Object *ob); - struct ListBase *get_active_constraints(struct Object *ob); struct bConstraint *get_active_constraint(struct Object *ob); diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h index ee1a23f242b..a3dd6426f99 100644 --- a/source/blender/editors/include/UI_icons.h +++ b/source/blender/editors/include/UI_icons.h @@ -54,8 +54,8 @@ DEF_ICON(ICON_BLANK005) DEF_ICON(ICON_GO_LEFT) DEF_ICON(ICON_PLUG) DEF_ICON(ICON_UI) -DEF_ICON(ICON_TEXNODE) -DEF_ICON(ICON_TEXNODE_SEL) +DEF_ICON(ICON_NODE) +DEF_ICON(ICON_NODE_SEL) /* ui */ DEF_ICON(ICON_FULLSCREEN) @@ -157,7 +157,7 @@ DEF_ICON(ICON_ACTION) DEF_ICON(ICON_NLA) DEF_ICON(ICON_SCRIPTWIN) DEF_ICON(ICON_TIME) -DEF_ICON(ICON_NODE) +DEF_ICON(ICON_NODETREE) DEF_ICON(ICON_LOGIC) DEF_ICON(ICON_CONSOLE) DEF_ICON(ICON_PREFERENCES) diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index fcc41e4f533..51c38ee859f 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -38,7 +38,7 @@ #include "DNA_texture_types.h" #include "DNA_userdef_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -988,7 +988,7 @@ static void ui_do_active_linklines(uiBlock *block, short *mval) v3[0]= line->to->x1; v3[1]= (line->to->y1+line->to->y2)/2.0; - fac= PdistVL2Dfl(v1, v2, v3); + fac= dist_to_line_segment_v2(v1, v2, v3); if(fac < mindist) { mindist= fac; act= line; diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index cded4753f61..a233a84e6c8 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -37,7 +37,7 @@ #include "DNA_texture_types.h" #include "DNA_userdef_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_colortools.h" #include "BKE_texture.h" @@ -656,6 +656,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *wcol, rcti *rect) float x1, y1, sizex, sizey; float dx, v3[2], v1[2], v2[2], v1a[2], v2a[2]; int a; + float pos, colf[4]; coba= (ColorBand *)(but->editcoba? but->editcoba: but->poin); if(coba==NULL) return; @@ -676,7 +677,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *wcol, rcti *rect) v1[0]+= dx; } - glShadeModel(GL_SMOOTH); + glShadeModel(GL_FLAT); glEnable(GL_BLEND); cbd= coba->data; @@ -690,17 +691,16 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *wcol, rcti *rect) glColor4fv( &cbd->r ); glVertex2fv(v1); glVertex2fv(v2); - for(a=0; a<coba->tot; a++, cbd++) { + for( a = 1; a < sizex; a++ ) { + pos = ((float)a) / (sizex-1); + do_colorband( coba, pos, colf ); - v1[0]=v2[0]= x1+ cbd->pos*sizex; + v1[0]=v2[0]= x1 + a; - glColor4fv( &cbd->r ); + glColor4fv( colf ); glVertex2fv(v1); glVertex2fv(v2); } - v1[0]=v2[0]= x1+ sizex; - glVertex2fv(v1); glVertex2fv(v2); - glEnd(); glShadeModel(GL_FLAT); glDisable(GL_BLEND); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index f085e7054a3..6adee174400 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -38,7 +38,7 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "PIL_time.h" @@ -2652,7 +2652,7 @@ static int ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data, int mx, i fp[2]= -sqrt( radsq-dx*dx-dy*dy ); } } - Normalize(fp); + normalize_v3(fp); data->draglastx= mx; data->draglasty= my; @@ -4486,14 +4486,14 @@ static int ui_mouse_motion_towards_check(uiBlock *block, uiPopupBlockHandle *men newp[0]= mx; newp[1]= my; - if(Vec2Lenf(oldp, newp) < 4.0f) + if(len_v2v2(oldp, newp) < 4.0f) return menu->dotowards; closer= 0; - closer |= IsectPT2Df(newp, oldp, p1, p2); - closer |= IsectPT2Df(newp, oldp, p2, p3); - closer |= IsectPT2Df(newp, oldp, p3, p4); - closer |= IsectPT2Df(newp, oldp, p4, p1); + closer |= isect_point_tri_v2(newp, oldp, p1, p2); + closer |= isect_point_tri_v2(newp, oldp, p2, p3); + closer |= isect_point_tri_v2(newp, oldp, p3, p4); + closer |= isect_point_tri_v2(newp, oldp, p4, p1); if(!closer) menu->dotowards= 0; diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index ad96796213d..23a0ff7d223 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -40,7 +40,7 @@ #include "GPU_extensions.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_storage_types.h" @@ -705,7 +705,7 @@ int UI_icon_get_width(int icon_id) } if (di) - return ICON_DEFAULT_HEIGHT; + return ICON_DEFAULT_WIDTH; return 0; } diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 20cd6ebf971..e73a4fbe977 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -37,7 +37,7 @@ #include "PIL_time.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index e3b7d173961..388b83cff11 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -35,7 +35,7 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_ghash.h" diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 5c058889107..2e8d2a8cb2b 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -35,7 +35,7 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_rect.h" #include "BLI_string.h" diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index a35da38ea66..dbf5eb1d0ea 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -110,7 +110,7 @@ static void id_search_cb(const bContext *C, void *arg_template, char *str, uiSea } /* ID Search browse menu, open */ -static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem) +static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem) { static char search[256]; static TemplateID template; @@ -262,7 +262,7 @@ static void template_ID(bContext *C, uiBlock *block, TemplateID *template, Struc type= idptr.type; if(flag & UI_ID_BROWSE) { - but= uiDefBlockButN(block, search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X*1.6, UI_UNIT_Y, "Browse ID data"); + but= uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X*1.6, UI_UNIT_Y, "Browse ID data"); if(type) { but->icon= RNA_struct_ui_icon(type); but->flag|= UI_HAS_ICON; @@ -448,6 +448,8 @@ void uiTemplateAnyID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propn /********************* RNA Path Builder Template ********************/ +/* ---------- */ + /* This is creating/editing RNA-Paths * * - ptr: struct which holds the path property @@ -497,7 +499,7 @@ void uiTemplatePathBuilder(uiLayout *layout, bContext *C, PointerRNA *ptr, char #include "UI_resources.h" #include "ED_util.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "ED_object.h" diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 65f1f9a2f70..fa577f6be66 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -35,7 +35,7 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_rect.h" @@ -806,6 +806,60 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) } } +static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) +{ + int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10; + int okwidth= rect->xmax-rect->xmin - border; + char *cpoin=NULL; + char *cpend = but->drawstr + strlen(but->drawstr); + + /* need to set this first */ + uiStyleFontSet(fstyle); + + but->strwidth= BLF_width(but->drawstr); + but->ofs= 0; + + /* find the space after ':' separator */ + cpoin= strrchr(but->drawstr, ':'); + + if (cpoin && (cpoin < cpend-2)) { + char *cp2 = cpoin; + + /* chop off the leading text, starting from the right */ + while (but->strwidth > okwidth && cp2 > but->drawstr) { + /* shift the text after and including cp2 back by 1 char, +1 to include null terminator */ + memmove(cp2-1, cp2, strlen(cp2)+1); + cp2--; + + but->strwidth= BLF_width(but->drawstr+but->ofs); + if(but->strwidth < 10) break; + } + + + /* after the leading text is gone, chop off the : and following space, with ofs */ + while ((but->strwidth > okwidth) && (but->ofs < 2)) + { + but->ofs++; + but->strwidth= BLF_width(but->drawstr+but->ofs); + if(but->strwidth < 10) break; + } + + } + + /* once the label's gone, chop off the least significant digits */ + while(but->strwidth > okwidth ) { + int pos= strlen(but->drawstr); + + but->drawstr[ pos-1 ] = 0; + pos--; + + but->strwidth= BLF_width(but->drawstr+but->ofs); + if(but->strwidth < 10) break; + } + +} + + static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect) { // int transopts; @@ -893,9 +947,12 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB { if(but==NULL) return; - - /* cutting off from left part */ - if ELEM5(but->type, NUM, NUMABS, NUMSLI, SLI, TEX) { + + /* clip but->drawstr to fit in available space */ + if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) { + ui_text_label_rightclip(fstyle, but, rect); + } + else if (but->type == TEX) { ui_text_leftclip(fstyle, but, rect); } else but->ofs= 0; @@ -1666,8 +1723,8 @@ static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int round { uiWidgetBase wtb; float rad= 0.5f*(rect->ymax - rect->ymin); - int textoffs; - + float textofs = rad*0.75; + widget_init(&wtb); /* fully rounded */ @@ -1677,19 +1734,13 @@ static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int round if(!(state & UI_TEXTINPUT)) { widget_num_tria(&wtb.tria1, rect, 0.6f, 'l'); widget_num_tria(&wtb.tria2, rect, 0.6f, 'r'); - } + } + widgetbase_draw(&wtb, wcol); /* text space */ - if(!(state & UI_TEXTINPUT)) { - rect->xmin += (rect->ymax-rect->ymin); - rect->xmax -= (rect->ymax-rect->ymin); - } - else { - textoffs= rad; - rect->xmin += textoffs; - rect->xmax -= textoffs; - } + rect->xmin += textofs; + rect->xmax -= textofs; } @@ -1896,7 +1947,6 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s rcti rect1; double value; float offs, fac; - int textoffs; char outline[3]; widget_init(&wtb); @@ -1906,7 +1956,6 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s /* fully rounded */ offs= 0.5f*(rect->ymax - rect->ymin); - textoffs= offs; round_box_edges(&wtb, roundboxalign, rect, offs); wtb.outline= 0; @@ -1948,8 +1997,8 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s widgetbase_draw(&wtb, wcol); /* text space */ - rect->xmin += textoffs; - rect->xmax -= textoffs; + rect->xmin += offs*0.75f; + rect->xmax -= offs*0.75f; } static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 0042ad9483b..5d94fb32438 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -32,7 +32,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_heap.h" #include "BLI_edgehash.h" #include "BLI_editVert.h" @@ -453,7 +453,7 @@ int minmax_tface(Scene *scene, float *min, float *max) me= get_mesh(ob); if(me==0 || me->mtface==0) return ok; - Mat3CpyMat4(bmat, ob->obmat); + copy_m3_m4(bmat, ob->obmat); mv= me->mvert; mf= me->mface; @@ -463,24 +463,24 @@ int minmax_tface(Scene *scene, float *min, float *max) continue; VECCOPY(vec, (mv+mf->v1)->co); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, ob->obmat[3]); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, ob->obmat[3]); DO_MINMAX(vec, min, max); VECCOPY(vec, (mv+mf->v2)->co); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, ob->obmat[3]); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, ob->obmat[3]); DO_MINMAX(vec, min, max); VECCOPY(vec, (mv+mf->v3)->co); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, ob->obmat[3]); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, ob->obmat[3]); DO_MINMAX(vec, min, max); if (mf->v4) { VECCOPY(vec, (mv+mf->v4)->co); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, ob->obmat[3]); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, ob->obmat[3]); DO_MINMAX(vec, min, max); } ok= 1; @@ -500,11 +500,11 @@ static float edgetag_cut_cost(EditMesh *em, int e1, int e2, int vert) EditVert *v2 = EM_get_vert_for_index( (eed2->v1->tmp.l == vert)? eed2->v2->tmp.l: eed2->v1->tmp.l ); float cost, d1[3], d2[3]; - cost = VecLenf(v1->co, v->co); - cost += VecLenf(v->co, v2->co); + cost = len_v3v3(v1->co, v->co); + cost += len_v3v3(v->co, v2->co); - VecSubf(d1, v->co, v1->co); - VecSubf(d2, v2->co, v->co); + sub_v3_v3v3(d1, v->co, v1->co); + sub_v3_v3v3(d2, v2->co, v->co); cost = cost + 0.5f*cost*(2.0f - fabs(d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2])); diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index 81d565a9ba4..bdb1df3b5c1 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -49,7 +49,7 @@ #include "DNA_userdef_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_dynstr.h" #include "BLI_rand.h" @@ -411,12 +411,12 @@ EditFace *addfacelist(EditMesh *em, EditVert *v1, EditVert *v2, EditVert *v3, Ed em->totface++; if(efa->v4) { - CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n); - CalcCent4f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); + normal_quad_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); + cent_quad_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); } else { - CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n); - CalcCent3f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co); + normal_tri_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co); + cent_tri_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co); } return efa; @@ -614,13 +614,13 @@ static void edge_normal_compare(EditEdge *eed, EditFace *efa1) inp= efa1->n[0]*efa2->n[0] + efa1->n[1]*efa2->n[1] + efa1->n[2]*efa2->n[2]; if(inp<0.999 && inp >-0.999) eed->f2= 1; - if(efa1->v4) CalcCent4f(cent1, efa1->v1->co, efa1->v2->co, efa1->v3->co, efa1->v4->co); - else CalcCent3f(cent1, efa1->v1->co, efa1->v2->co, efa1->v3->co); - if(efa2->v4) CalcCent4f(cent2, efa2->v1->co, efa2->v2->co, efa2->v3->co, efa2->v4->co); - else CalcCent3f(cent2, efa2->v1->co, efa2->v2->co, efa2->v3->co); + if(efa1->v4) cent_quad_v3(cent1, efa1->v1->co, efa1->v2->co, efa1->v3->co, efa1->v4->co); + else cent_tri_v3(cent1, efa1->v1->co, efa1->v2->co, efa1->v3->co); + if(efa2->v4) cent_quad_v3(cent2, efa2->v1->co, efa2->v2->co, efa2->v3->co, efa2->v4->co); + else cent_tri_v3(cent2, efa2->v1->co, efa2->v2->co, efa2->v3->co); - VecSubf(cent1, cent2, cent1); - Normalize(cent1); + sub_v3_v3v3(cent1, cent2, cent1); + normalize_v3(cent1); inp= cent1[0]*efa1->n[0] + cent1[1]*efa1->n[1] + cent1[2]*efa1->n[2]; if(inp < -0.001 ) eed->f1= 1; @@ -1004,7 +1004,7 @@ void load_editMesh(Scene *scene, Object *ob) /* vertex normal */ VECCOPY(nor, eve->no); - VecMulf(nor, 32767.0); + mul_v3_fl(nor, 32767.0); VECCOPY(mvert->no, nor); /* note: it used to remove me->dvert when it was not in use, cancelled diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 5905b2021ea..fbe72a54e70 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -49,7 +49,7 @@ #include "RNA_access.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BKE_context.h" @@ -147,40 +147,40 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) done= 0; for(eed= vc.em->edges.first; eed; eed= eed->next) { if( (eed->v1->f & SELECT)+(eed->v2->f & SELECT) == SELECT ) { - if(eed->v1->f & SELECT) VecSubf(vec, eed->v1->co, eed->v2->co); - else VecSubf(vec, eed->v2->co, eed->v1->co); - VecAddf(nor, nor, vec); + if(eed->v1->f & SELECT) sub_v3_v3v3(vec, eed->v1->co, eed->v2->co); + else sub_v3_v3v3(vec, eed->v2->co, eed->v1->co); + add_v3_v3v3(nor, nor, vec); done= 1; } } - if(done) Normalize(nor); + if(done) normalize_v3(nor); /* center */ - VecAddf(cent, min, max); - VecMulf(cent, 0.5f); + add_v3_v3v3(cent, min, max); + mul_v3_fl(cent, 0.5f); VECCOPY(min, cent); - Mat4MulVecfl(vc.obedit->obmat, min); // view space + mul_m4_v3(vc.obedit->obmat, min); // view space view3d_get_view_aligned_coordinate(&vc, min, event->mval); - Mat4Invert(vc.obedit->imat, vc.obedit->obmat); - Mat4MulVecfl(vc.obedit->imat, min); // back in object space + invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); + mul_m4_v3(vc.obedit->imat, min); // back in object space - VecSubf(min, min, cent); + sub_v3_v3v3(min, min, cent); /* calculate rotation */ - Mat3One(mat); + unit_m3(mat); if(done) { float dot; VECCOPY(vec, min); - Normalize(vec); + normalize_v3(vec); dot= INPR(vec, nor); if( fabs(dot)<0.999) { float cross[3], si, q1[4]; - Crossf(cross, nor, vec); - Normalize(cross); + cross_v3_v3v3(cross, nor, vec); + normalize_v3(cross); dot= 0.5f*saacos(dot); si= (float)sin(dot); q1[0]= (float)cos(dot); @@ -188,7 +188,7 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) q1[2]= cross[1]*si; q1[3]= cross[2]*si; - QuatToMat3(q1, mat); + quat_to_mat3( mat,q1); } } @@ -207,12 +207,12 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) eve= addvertlist(vc.em, 0, NULL); - Mat3CpyMat4(mat, vc.obedit->obmat); - Mat3Inv(imat, mat); + copy_m3_m4(mat, vc.obedit->obmat); + invert_m3_m3(imat, mat); VECCOPY(eve->co, min); - Mat3MulVecfl(imat, eve->co); - VecSubf(eve->co, eve->co, vc.obedit->obmat[3]); + mul_m3_v3(imat, eve->co); + sub_v3_v3v3(eve->co, eve->co, vc.obedit->obmat[3]); eve->f= SELECT; } @@ -1011,7 +1011,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se vec[0]= dia*phi; vec[1]= - dia; vec[2]= 0.0f; - Mat4MulVecfl(mat,vec); + mul_m4_v3(mat,vec); eve= addvertlist(em, vec, NULL); eve->f= 1+2+4; if (a) { @@ -1022,7 +1022,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se /* extrude and translate */ vec[0]= vec[2]= 0.0; vec[1]= dia*phid; - Mat4Mul3Vecfl(mat, vec); + mul_mat3_m4_v3(mat, vec); for(a=0;a<seg-1;a++) { extrudeflag_vert(obedit, em, 2, nor); // nor unused @@ -1057,7 +1057,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se q[0]= cos(phi); q[3]= sin(phi); q[1]=q[2]= 0; - QuatToMat3(q, cmat); + quat_to_mat3( cmat,q); for(a=0; a<seg; a++) { extrudeflag_vert(obedit, em, 2, nor); // nor unused @@ -1070,7 +1070,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se eve= em->verts.first; while(eve) { if(eve->f & SELECT) { - Mat4MulVecfl(mat,eve->co); + mul_m4_v3(mat,eve->co); } eve= eve->next; } @@ -1111,7 +1111,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se eve= em->verts.first; while(eve) { if(eve->f & 2) { - Mat4MulVecfl(mat,eve->co); + mul_m4_v3(mat,eve->co); } eve= eve->next; } @@ -1150,7 +1150,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se /* and now do imat */ for(eve= em->verts.first; eve; eve= eve->next) { if(eve->f & SELECT) { - Mat4MulVecfl(mat,eve->co); + mul_m4_v3(mat,eve->co); } } recalc_editnormals(em); @@ -1170,7 +1170,7 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se vec[1]= dia*cos(phi); vec[2]= b?depth:-depth; - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); eve= addvertlist(em, vec, NULL); eve->f= SELECT; if(a==0) { @@ -1187,12 +1187,12 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se if(type == PRIM_CONE || (fill && !ELEM(type, PRIM_PLANE, PRIM_CUBE))) { vec[0]= vec[1]= 0.0f; vec[2]= type==PRIM_CONE ? depth : -depth; - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); vdown= addvertlist(em, vec, NULL); if((ext || type==PRIM_CONE) && fill) { vec[0]= vec[1]= 0.0f; vec[2]= type==PRIM_CONE ? -depth : depth; - Mat4MulVecfl(mat,vec); + mul_m4_v3(mat,vec); vtop= addvertlist(em, vec, NULL); } } else { @@ -1281,25 +1281,25 @@ static float new_primitive_matrix(bContext *C, int view_align, float primmat[][4 RegionView3D *rv3d= ED_view3d_context_rv3d(C); float *curs, mat[3][3], vmat[3][3], cmat[3][3], imat[3][3]; - Mat4One(primmat); + unit_m4(primmat); if(rv3d && view_align) { - Mat3CpyMat4(vmat, rv3d->viewmat); + copy_m3_m4(vmat, rv3d->viewmat); } else - Mat3One(vmat); + unit_m3(vmat); /* inverse transform for view and object */ - Mat3CpyMat4(mat, obedit->obmat); - Mat3MulMat3(cmat, vmat, mat); - Mat3Inv(imat, cmat); - Mat4CpyMat3(primmat, imat); + copy_m3_m4(mat, obedit->obmat); + mul_m3_m3m3(cmat, vmat, mat); + invert_m3_m3(imat, cmat); + copy_m4_m3(primmat, imat); /* center */ curs= give_cursor(scene, v3d); VECCOPY(primmat[3], curs); VECSUB(primmat[3], primmat[3], obedit->obmat[3]); - Mat3Inv(imat, mat); - Mat3MulVecfl(imat, primmat[3]); + invert_m3_m3(imat, mat); + mul_m3_v3(imat, primmat[3]); if(v3d) return v3d->grid; return 1.0f; diff --git a/source/blender/editors/mesh/editmesh_lib.c b/source/blender/editors/mesh/editmesh_lib.c index e1b63022dd4..544dd790dc8 100644 --- a/source/blender/editors/mesh/editmesh_lib.c +++ b/source/blender/editors/mesh/editmesh_lib.c @@ -47,7 +47,7 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data #include "DNA_windowmanager_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BKE_customdata.h" @@ -272,14 +272,14 @@ void EM_editselection_center(float *center, EditSelection *ese) { if (ese->type==EDITVERT) { EditVert *eve= ese->data; - VecCopyf(center, eve->co); + copy_v3_v3(center, eve->co); } else if (ese->type==EDITEDGE) { EditEdge *eed= ese->data; - VecAddf(center, eed->v1->co, eed->v2->co); - VecMulf(center, 0.5); + add_v3_v3v3(center, eed->v1->co, eed->v2->co); + mul_v3_fl(center, 0.5); } else if (ese->type==EDITFACE) { EditFace *efa= ese->data; - VecCopyf(center, efa->cent); + copy_v3_v3(center, efa->cent); } } @@ -287,26 +287,26 @@ void EM_editselection_normal(float *normal, EditSelection *ese) { if (ese->type==EDITVERT) { EditVert *eve= ese->data; - VecCopyf(normal, eve->no); + copy_v3_v3(normal, eve->no); } else if (ese->type==EDITEDGE) { EditEdge *eed= ese->data; float plane[3]; /* need a plane to correct the normal */ float vec[3]; /* temp vec storage */ - VecAddf(normal, eed->v1->no, eed->v2->no); - VecSubf(plane, eed->v2->co, eed->v1->co); + add_v3_v3v3(normal, eed->v1->no, eed->v2->no); + sub_v3_v3v3(plane, eed->v2->co, eed->v1->co); /* the 2 vertex normals will be close but not at rightangles to the edge for rotate about edge we want them to be at right angles, so we need to do some extra colculation to correct the vert normals, we need the plane for this */ - Crossf(vec, normal, plane); - Crossf(normal, plane, vec); - Normalize(normal); + cross_v3_v3v3(vec, normal, plane); + cross_v3_v3v3(normal, plane, vec); + normalize_v3(normal); } else if (ese->type==EDITFACE) { EditFace *efa= ese->data; - VecCopyf(normal, efa->n); + copy_v3_v3(normal, efa->n); } } @@ -321,7 +321,7 @@ void EM_editselection_plane(float *plane, EditSelection *ese) if (ese->prev) { /*use previously selected data to make a usefull vertex plane */ EM_editselection_center(vec, ese->prev); - VecSubf(plane, vec, eve->co); + sub_v3_v3v3(plane, vec, eve->co); } else { /* make a fake plane thats at rightangles to the normal we cant make a crossvec from a vec thats the same as the vec @@ -330,7 +330,7 @@ void EM_editselection_plane(float *plane, EditSelection *ese) if (eve->no[0]<0.5) vec[0]=1; else if (eve->no[1]<0.5) vec[1]=1; else vec[2]=1; - Crossf(plane, eve->no, vec); + cross_v3_v3v3(plane, eve->no, vec); } } else if (ese->type==EDITEDGE) { EditEdge *eed= ese->data; @@ -341,41 +341,41 @@ void EM_editselection_plane(float *plane, EditSelection *ese) (running along the edge).. to flip less often. at least its more pradictable */ if (eed->v2->co[1] > eed->v1->co[1]) /*check which to do first */ - VecSubf(plane, eed->v2->co, eed->v1->co); + sub_v3_v3v3(plane, eed->v2->co, eed->v1->co); else - VecSubf(plane, eed->v1->co, eed->v2->co); + sub_v3_v3v3(plane, eed->v1->co, eed->v2->co); } else if (ese->type==EDITFACE) { EditFace *efa= ese->data; float vec[3]; if (efa->v4) { /*if its a quad- set the plane along the 2 longest edges.*/ float vecA[3], vecB[3]; - VecSubf(vecA, efa->v4->co, efa->v3->co); - VecSubf(vecB, efa->v1->co, efa->v2->co); - VecAddf(plane, vecA, vecB); + sub_v3_v3v3(vecA, efa->v4->co, efa->v3->co); + sub_v3_v3v3(vecB, efa->v1->co, efa->v2->co); + add_v3_v3v3(plane, vecA, vecB); - VecSubf(vecA, efa->v1->co, efa->v4->co); - VecSubf(vecB, efa->v2->co, efa->v3->co); - VecAddf(vec, vecA, vecB); + sub_v3_v3v3(vecA, efa->v1->co, efa->v4->co); + sub_v3_v3v3(vecB, efa->v2->co, efa->v3->co); + add_v3_v3v3(vec, vecA, vecB); /*use the biggest edge length*/ if (plane[0]*plane[0]+plane[1]*plane[1]+plane[2]*plane[2] < vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]) - VecCopyf(plane, vec); + copy_v3_v3(plane, vec); } else { /*start with v1-2 */ - VecSubf(plane, efa->v1->co, efa->v2->co); + sub_v3_v3v3(plane, efa->v1->co, efa->v2->co); /*test the edge between v2-3, use if longer */ - VecSubf(vec, efa->v2->co, efa->v3->co); + sub_v3_v3v3(vec, efa->v2->co, efa->v3->co); if (plane[0]*plane[0]+plane[1]*plane[1]+plane[2]*plane[2] < vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]) - VecCopyf(plane, vec); + copy_v3_v3(plane, vec); /*test the edge between v1-3, use if longer */ - VecSubf(vec, efa->v3->co, efa->v1->co); + sub_v3_v3v3(vec, efa->v3->co, efa->v1->co); if (plane[0]*plane[0]+plane[1]*plane[1]+plane[2]*plane[2] < vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]) - VecCopyf(plane, vec); + copy_v3_v3(plane, vec); } } - Normalize(plane); + normalize_v3(plane); } @@ -908,9 +908,9 @@ void EM_free_data_layer(EditMesh *em, CustomData *data, int type) static void add_normal_aligned(float *nor, float *add) { if( INPR(nor, add) < -0.9999f) - VecSubf(nor, nor, add); + sub_v3_v3v3(nor, nor, add); else - VecAddf(nor, nor, add); + add_v3_v3v3(nor, nor, add); } static void set_edge_directions_f2(EditMesh *em, int val) @@ -1097,7 +1097,7 @@ short extrudeflag_edges_indiv(EditMesh *em, short flag, float *nor) } } } - Normalize(nor); + normalize_v3(nor); /* set correct selection */ EM_clear_flag_all(em, SELECT); @@ -1216,20 +1216,20 @@ static short extrudeflag_edge(Object *obedit, EditMesh *em, short flag, float *n float mtx[4][4]; if (mmd->mirror_ob) { float imtx[4][4]; - Mat4Invert(imtx, mmd->mirror_ob->obmat); - Mat4MulMat4(mtx, obedit->obmat, imtx); + invert_m4_m4(imtx, mmd->mirror_ob->obmat); + mul_m4_m4m4(mtx, obedit->obmat, imtx); } for (eed= em->edges.first; eed; eed= eed->next) { if(eed->f2 == 1) { float co1[3], co2[3]; - VecCopyf(co1, eed->v1->co); - VecCopyf(co2, eed->v2->co); + copy_v3_v3(co1, eed->v1->co); + copy_v3_v3(co2, eed->v2->co); if (mmd->mirror_ob) { - VecMat4MulVecfl(co1, mtx, co1); - VecMat4MulVecfl(co2, mtx, co2); + mul_v3_m4v3(co1, mtx, co1); + mul_v3_m4v3(co2, mtx, co2); } if (mmd->flag & MOD_MIR_AXIS_X) @@ -1380,7 +1380,7 @@ static short extrudeflag_edge(Object *obedit, EditMesh *em, short flag, float *n } } - Normalize(nor); // translation normal grab + normalize_v3(nor); // translation normal grab /* step 7: redo selection */ EM_clear_flag_all(em, SELECT); @@ -1503,20 +1503,20 @@ short extrudeflag_vert(Object *obedit, EditMesh *em, short flag, float *nor) float mtx[4][4]; if (mmd->mirror_ob) { float imtx[4][4]; - Mat4Invert(imtx, mmd->mirror_ob->obmat); - Mat4MulMat4(mtx, obedit->obmat, imtx); + invert_m4_m4(imtx, mmd->mirror_ob->obmat); + mul_m4_m4m4(mtx, obedit->obmat, imtx); } for (eed= em->edges.first; eed; eed= eed->next) { if(eed->f2 == 2) { float co1[3], co2[3]; - VecCopyf(co1, eed->v1->co); - VecCopyf(co2, eed->v2->co); + copy_v3_v3(co1, eed->v1->co); + copy_v3_v3(co2, eed->v2->co); if (mmd->mirror_ob) { - VecMat4MulVecfl(co1, mtx, co1); - VecMat4MulVecfl(co2, mtx, co2); + mul_v3_m4v3(co1, mtx, co1); + mul_v3_m4v3(co2, mtx, co2); } if (mmd->flag & MOD_MIR_AXIS_X) @@ -1652,7 +1652,7 @@ short extrudeflag_vert(Object *obedit, EditMesh *em, short flag, float *nor) efa= nextvl; } - Normalize(nor); // for grab + normalize_v3(nor); // for grab /* for all vertices with eve->tmp.v!=0 if eve->f1==1: make edge @@ -1704,7 +1704,7 @@ void rotateflag(EditMesh *em, short flag, float *cent, float rotmat[][3]) eve->co[0]-=cent[0]; eve->co[1]-=cent[1]; eve->co[2]-=cent[2]; - Mat3MulVecfl(rotmat,eve->co); + mul_m3_v3(rotmat,eve->co); eve->co[0]+=cent[0]; eve->co[1]+=cent[1]; eve->co[2]+=cent[2]; @@ -1913,24 +1913,24 @@ void recalc_editnormals(EditMesh *em) for(efa= em->faces.first; efa; efa=efa->next) { if(efa->v4) { - CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n); - CalcCent4f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); - VecAddf(efa->v4->no, efa->v4->no, efa->n); + normal_quad_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); + cent_quad_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); + add_v3_v3v3(efa->v4->no, efa->v4->no, efa->n); } else { - CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n); - CalcCent3f(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co); + normal_tri_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co); + cent_tri_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co); } - VecAddf(efa->v1->no, efa->v1->no, efa->n); - VecAddf(efa->v2->no, efa->v2->no, efa->n); - VecAddf(efa->v3->no, efa->v3->no, efa->n); + add_v3_v3v3(efa->v1->no, efa->v1->no, efa->n); + add_v3_v3v3(efa->v2->no, efa->v2->no, efa->n); + add_v3_v3v3(efa->v3->no, efa->v3->no, efa->n); } /* following Mesh convention; we use vertex coordinate itself for normal in this case */ for(eve= em->verts.first; eve; eve=eve->next) { - if (Normalize(eve->no)==0.0) { + if (normalize_v3(eve->no)==0.0) { VECCOPY(eve->no, eve->co); - Normalize(eve->no); + normalize_v3(eve->no); } } } @@ -1996,8 +1996,8 @@ int convex(float *v1, float *v2, float *v3, float *v4) float nor[3], nor1[3], nor2[3], vec[4][2]; /* define projection, do both trias apart, quad is undefined! */ - CalcNormFloat(v1, v2, v3, nor1); - CalcNormFloat(v1, v3, v4, nor2); + normal_tri_v3( nor1,v1, v2, v3); + normal_tri_v3( nor2,v1, v3, v4); nor[0]= ABS(nor1[0]) + ABS(nor2[0]); nor[1]= ABS(nor1[1]) + ABS(nor2[1]); nor[2]= ABS(nor1[2]) + ABS(nor2[2]); @@ -2022,7 +2022,7 @@ int convex(float *v1, float *v2, float *v3, float *v4) } /* linetests, the 2 diagonals have to instersect to be convex */ - if( IsectLL2Df(vec[0], vec[2], vec[1], vec[3]) > 0 ) return 1; + if( isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0 ) return 1; return 0; } @@ -2037,22 +2037,22 @@ int convex(float *v1, float *v2, float *v3, float *v4) float EM_face_area(EditFace *efa) { - if(efa->v4) return AreaQ3Dfl(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); - else return AreaT3Dfl(efa->v1->co, efa->v2->co, efa->v3->co); + if(efa->v4) return area_quad_v3(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); + else return area_tri_v3(efa->v1->co, efa->v2->co, efa->v3->co); } float EM_face_perimeter(EditFace *efa) { if(efa->v4) return - VecLenf(efa->v1->co, efa->v2->co)+ - VecLenf(efa->v2->co, efa->v3->co)+ - VecLenf(efa->v3->co, efa->v4->co)+ - VecLenf(efa->v4->co, efa->v1->co); + len_v3v3(efa->v1->co, efa->v2->co)+ + len_v3v3(efa->v2->co, efa->v3->co)+ + len_v3v3(efa->v3->co, efa->v4->co)+ + len_v3v3(efa->v4->co, efa->v1->co); else return - VecLenf(efa->v1->co, efa->v2->co)+ - VecLenf(efa->v2->co, efa->v3->co)+ - VecLenf(efa->v3->co, efa->v1->co); + len_v3v3(efa->v1->co, efa->v2->co)+ + len_v3v3(efa->v2->co, efa->v3->co)+ + len_v3v3(efa->v3->co, efa->v1->co); } void EM_fgon_flags(EditMesh *em) @@ -2240,7 +2240,7 @@ UvVertMap *EM_make_uv_vert_map(EditMesh *em, int selected, int do_face_idx_array tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); uv2 = tf->uv[iterv->tfindex]; - Vec2Subf(uvdiff, uv2, uv); + sub_v2_v2v2(uvdiff, uv2, uv); if(fabs(uv[0]-uv2[0]) < limit[0] && fabs(uv[1]-uv2[1]) < limit[1]) { if(lastv) lastv->next= next; diff --git a/source/blender/editors/mesh/editmesh_loop.c b/source/blender/editors/mesh/editmesh_loop.c index 3dc9c81a213..fd665f07767 100644 --- a/source/blender/editors/mesh/editmesh_loop.c +++ b/source/blender/editors/mesh/editmesh_loop.c @@ -49,7 +49,7 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv #include "DNA_windowmanager_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_ghash.h" @@ -672,7 +672,7 @@ static int knife_cut_exec(bContext *C, wmOperator *op) scr = MEM_mallocN(sizeof(float)*2, "Vertex Screen Coordinates"); VECCOPY(co, eve->co); co[3]= 1.0; - Mat4MulVec4fl(obedit->obmat, co); + mul_m4_v4(obedit->obmat, co); project_float(ar, co, scr); BLI_ghash_insert(gh, eve, scr); eve->f1 = 0; /*store vertex intersection flag here*/ diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 737f658d46f..93bfdb37581 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -53,7 +53,7 @@ editmesh_mods.c, UI level access, no geometry changes #include "DNA_view3d_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -488,7 +488,7 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in v2[0] = x1; v2[1] = y1; - distance= PdistVL2Dfl(data->mval, v1, v2); + distance= dist_to_line_segment_v2(data->mval, v1, v2); if(eed->f & SELECT) distance+=5; if(distance < data->dist) { @@ -499,7 +499,7 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in vec[0]= eed->v1->co[0] + labda*(eed->v2->co[0] - eed->v1->co[0]); vec[1]= eed->v1->co[1] + labda*(eed->v2->co[1] - eed->v1->co[1]); vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]); - Mat4MulVecfl(data->vc.obedit->obmat, vec); + mul_m4_v3(data->vc.obedit->obmat, vec); if(view3d_test_clipping(data->vc.rv3d, vec)==0) { data->dist = distance; @@ -825,7 +825,7 @@ static int similar_face_select__internal(Scene *scene, EditMesh *em, int mode) float angle; for(efa= em->faces.first; efa; efa= efa->next) { if (!(efa->f & SELECT) && !efa->h) { - angle= RAD2DEG(VecAngle2(base_efa->n, efa->n)); + angle= RAD2DEG(angle_v2v2(base_efa->n, efa->n)); if (angle/180.0<=thresh) { EM_select_face(efa, 1); selcount++; @@ -837,12 +837,12 @@ static int similar_face_select__internal(Scene *scene, EditMesh *em, int mode) } } else if (mode==SIMFACE_COPLANAR) { /* same planer */ float angle, base_dot, dot; - base_dot= Inpf(base_efa->cent, base_efa->n); + base_dot= dot_v3v3(base_efa->cent, base_efa->n); for(efa= em->faces.first; efa; efa= efa->next) { if (!(efa->f & SELECT) && !efa->h) { - angle= RAD2DEG(VecAngle2(base_efa->n, efa->n)); + angle= RAD2DEG(angle_v2v2(base_efa->n, efa->n)); if (angle/180.0<=thresh) { - dot=Inpf(efa->cent, base_efa->n); + dot=dot_v3v3(efa->cent, base_efa->n); if (fabs(base_dot-dot) <= thresh) { EM_select_face(efa, 1); selcount++; @@ -916,7 +916,7 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod if (mode==SIMEDGE_LENGTH) { /*store length*/ for(eed= em->edges.first; eed; eed= eed->next) { if (!eed->h) /* dont calc data for hidden edges*/ - eed->tmp.fp= VecLenf(eed->v1->co, eed->v2->co); + eed->tmp.fp= len_v3v3(eed->v1->co, eed->v2->co); } } else if (mode==SIMEDGE_FACE) { /*store face users*/ EditFace *efa; @@ -959,7 +959,7 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod else if (eed->f2==0) /* first access, assign the face */ eed->tmp.f= efa; else if (eed->f2==1) /* second, we assign the angle*/ - eed->tmp.fp= RAD2DEG(VecAngle2(eed->tmp.f->n, efa->n))/180; + eed->tmp.fp= RAD2DEG(angle_v2v2(eed->tmp.f->n, efa->n))/180; eed->f2++; /* f2==0 no face assigned. f2==1 one face found. f2==2 angle calculated.*/ } j++; @@ -985,11 +985,11 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod } } else if (mode==SIMEDGE_DIR) { /* same direction */ float base_dir[3], dir[3], angle; - VecSubf(base_dir, base_eed->v1->co, base_eed->v2->co); + sub_v3_v3v3(base_dir, base_eed->v1->co, base_eed->v2->co); for(eed= em->edges.first; eed; eed= eed->next) { if (!(eed->f & SELECT) && !eed->h) { - VecSubf(dir, eed->v1->co, eed->v2->co); - angle= RAD2DEG(VecAngle2(base_dir, dir)); + sub_v3_v3v3(dir, eed->v1->co, eed->v2->co); + angle= RAD2DEG(angle_v2v2(base_dir, dir)); if (angle>90) /* use the smallest angle between the edges */ angle= fabs(angle-180.0f); @@ -1161,7 +1161,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) float angle; for(eve= em->verts.first; eve; eve= eve->next) { if (!(eve->f & SELECT) && !eve->h) { - angle= RAD2DEG(VecAngle2(base_eve->no, eve->no)); + angle= RAD2DEG(angle_v2v2(base_eve->no, eve->no)); if (angle/180.0<=thresh) { eve->f |= SELECT; selcount++; @@ -1388,34 +1388,34 @@ void EM_mesh_copy_edge(EditMesh *em, short type) break; case 3: /* copy length */ - eed_len_act = VecLenf(eed_act->v1->co, eed_act->v2->co); + eed_len_act = len_v3v3(eed_act->v1->co, eed_act->v2->co); for(eed=em->edges.first; eed; eed=eed->next) { if (eed->f & SELECT && eed != eed_act) { - eed_len = VecLenf(eed->v1->co, eed->v2->co); + eed_len = len_v3v3(eed->v1->co, eed->v2->co); if (eed_len == eed_len_act) continue; /* if this edge is zero length we cont do anything with it*/ if (eed_len == 0.0f) continue; if (eed_len_act == 0.0f) { - VecAddf(vec_mid, eed->v1->co, eed->v2->co); - VecMulf(vec_mid, 0.5); + add_v3_v3v3(vec_mid, eed->v1->co, eed->v2->co); + mul_v3_fl(vec_mid, 0.5); VECCOPY(eed->v1->co, vec_mid); VECCOPY(eed->v2->co, vec_mid); } else { /* copy the edge length */ - VecAddf(vec_mid, eed->v1->co, eed->v2->co); - VecMulf(vec_mid, 0.5); + add_v3_v3v3(vec_mid, eed->v1->co, eed->v2->co); + mul_v3_fl(vec_mid, 0.5); /* SCALE 1 */ - VecSubf(vec, eed->v1->co, vec_mid); - VecMulf(vec, eed_len_act/eed_len); - VecAddf(eed->v1->co, vec, vec_mid); + sub_v3_v3v3(vec, eed->v1->co, vec_mid); + mul_v3_fl(vec, eed_len_act/eed_len); + add_v3_v3v3(eed->v1->co, vec, vec_mid); /* SCALE 2 */ - VecSubf(vec, eed->v2->co, vec_mid); - VecMulf(vec, eed_len_act/eed_len); - VecAddf(eed->v2->co, vec, vec_mid); + sub_v3_v3v3(vec, eed->v2->co, vec_mid); + mul_v3_fl(vec, eed_len_act/eed_len); + add_v3_v3v3(eed->v2->co, vec, vec_mid); } change = 1; } @@ -3873,7 +3873,7 @@ void righthandfaces(EditMesh *em, int select) /* makes faces righthand turning * while(efa) { if(efa->f1) { - CalcCent3f(cent, efa->v1->co, efa->v2->co, efa->v3->co); + cent_tri_v3(cent, efa->v1->co, efa->v2->co, efa->v3->co); cent[0]= cent[0]*cent[0] + cent[1]*cent[1] + cent[2]*cent[2]; if(cent[0]>maxx) { @@ -3882,7 +3882,7 @@ void righthandfaces(EditMesh *em, int select) /* makes faces righthand turning * tria_nr= 0; } if(efa->v4) { - CalcCent3f(cent, efa->v1->co, efa->v3->co, efa->v4->co); + cent_tri_v3(cent, efa->v1->co, efa->v3->co, efa->v4->co); cent[0]= cent[0]*cent[0] + cent[1]*cent[1] + cent[2]*cent[2]; if(cent[0]>maxx) { @@ -3901,11 +3901,11 @@ void righthandfaces(EditMesh *em, int select) /* makes faces righthand turning * /* set first face correct: calc normal */ if(tria_nr==1) { - CalcNormFloat(startvl->v1->co, startvl->v3->co, startvl->v4->co, nor); - CalcCent3f(cent, startvl->v1->co, startvl->v3->co, startvl->v4->co); + normal_tri_v3( nor,startvl->v1->co, startvl->v3->co, startvl->v4->co); + cent_tri_v3(cent, startvl->v1->co, startvl->v3->co, startvl->v4->co); } else { - CalcNormFloat(startvl->v1->co, startvl->v2->co, startvl->v3->co, nor); - CalcCent3f(cent, startvl->v1->co, startvl->v2->co, startvl->v3->co); + normal_tri_v3( nor,startvl->v1->co, startvl->v2->co, startvl->v3->co); + cent_tri_v3(cent, startvl->v1->co, startvl->v2->co, startvl->v3->co); } /* first normal is oriented this way or the other */ if(select) { @@ -4115,9 +4115,9 @@ void faceselect_align_view_to_selected(View3D *v3d, RegionView3D *rv3d, Mesh *me v3= me->mvert[mf->v3].co; if (mf->v4) { float *v4= me->mvert[mf->v4].co; - CalcNormFloat4(v1, v2, v3, v4, fno); + normal_quad_v3( fno,v1, v2, v3, v4); } else { - CalcNormFloat(v1, v2, v3, fno); + normal_tri_v3( fno,v1, v2, v3); } norm[0]+= fno[0]; @@ -4140,18 +4140,18 @@ static void face_getnormal_obspace(Object *obedit, EditFace *efa, float *fno) float vec[4][3]; VECCOPY(vec[0], efa->v1->co); - Mat4Mul3Vecfl(obedit->obmat, vec[0]); + mul_mat3_m4_v3(obedit->obmat, vec[0]); VECCOPY(vec[1], efa->v2->co); - Mat4Mul3Vecfl(obedit->obmat, vec[1]); + mul_mat3_m4_v3(obedit->obmat, vec[1]); VECCOPY(vec[2], efa->v3->co); - Mat4Mul3Vecfl(obedit->obmat, vec[2]); + mul_mat3_m4_v3(obedit->obmat, vec[2]); if(efa->v4) { VECCOPY(vec[3], efa->v4->co); - Mat4Mul3Vecfl(obedit->obmat, vec[3]); + mul_mat3_m4_v3(obedit->obmat, vec[3]); - CalcNormFloat4(vec[0], vec[1], vec[2], vec[3], fno); + normal_quad_v3( fno,vec[0], vec[1], vec[2], vec[3]); } - else CalcNormFloat(vec[0], vec[1], vec[2], fno); + else normal_tri_v3( fno,vec[0], vec[1], vec[2]); } @@ -4187,7 +4187,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o if (eve->f & SELECT) { if (leve) { float tno[3]; - CalcNormFloat(cent, leve->co, eve->co, tno); + normal_tri_v3( tno,cent, leve->co, eve->co); /* XXX, fixme, should be flipped intp a * consistent direction. -zr @@ -4200,7 +4200,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o } } - Mat4Mul3Vecfl(obedit->obmat, norm); + mul_mat3_m4_v3(obedit->obmat, norm); view3d_align_axis_to_vector(v3d, rv3d, axis, norm); } else if (nselverts==2) { /* Align view to edge (or 2 verts) */ @@ -4217,7 +4217,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o leve= eve; } } - Mat4Mul3Vecfl(obedit->obmat, norm); + mul_mat3_m4_v3(obedit->obmat, norm); view3d_align_axis_to_vector(v3d, rv3d, axis, norm); } else if (nselverts==1) { /* Align view to vert normal */ @@ -4231,7 +4231,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o break; /* we know this is the only selected vert, so no need to keep looking */ } } - Mat4Mul3Vecfl(obedit->obmat, norm); + mul_mat3_m4_v3(obedit->obmat, norm); view3d_align_axis_to_vector(v3d, rv3d, axis, norm); } } @@ -4312,11 +4312,11 @@ static int smooth_vertex(bContext *C, wmOperator *op) if((eed->v1->f & SELECT) && eed->v1->f1<255) { eed->v1->f1++; - VecAddf(eed->v1->tmp.p, eed->v1->tmp.p, fvec); + add_v3_v3v3(eed->v1->tmp.p, eed->v1->tmp.p, fvec); } if((eed->v2->f & SELECT) && eed->v2->f1<255) { eed->v2->f1++; - VecAddf(eed->v2->tmp.p, eed->v2->tmp.p, fvec); + add_v3_v3v3(eed->v2->tmp.p, eed->v2->tmp.p, fvec); } } eed= eed->next; @@ -4435,7 +4435,7 @@ void vertexnoise(Object *obedit, EditMesh *em) vec[1]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs, eve->co[2])); vec[2]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]+ofs)); - VecAddf(eve->co, eve->co, vec); + add_v3_v3v3(eve->co, eve->co, vec); } else { float tin, dum; @@ -4466,8 +4466,8 @@ void flipface(EditMesh *em, EditFace *efa) EM_data_interp_from_faces(em, efa, NULL, efa, 0, 2, 1, 3); } - if(efa->v4) CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n); - else CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n); + if(efa->v4) normal_quad_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co); + else normal_tri_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co); } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index cea7ec33d3a..8f2a09866f3 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -58,7 +58,7 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise #include "RNA_access.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_rand.h" #include "BLI_ghash.h" @@ -150,7 +150,7 @@ static void convert_to_triface(EditMesh *em, int direction) if(efa->v4) { if(efa->f & SELECT) { /* choose shortest diagonal for split */ - fac= VecLenf(efa->v1->co, efa->v3->co) - VecLenf(efa->v2->co, efa->v4->co); + fac= len_v3v3(efa->v1->co, efa->v3->co) - len_v3v3(efa->v2->co, efa->v4->co); /* this makes sure exact squares get split different in both cases */ if( (direction==0 && fac<FLT_EPSILON) || (direction && fac>0.0f) ) { efan= EM_face_from_faces(em, efa, NULL, 0, 1, 2, -1); @@ -689,8 +689,8 @@ void extrude_mesh(Scene *scene, Object *obedit, EditMesh *em, wmOperator *op) else { // initTransform(TFM_TRANSLATION, CTX_NO_PET|CTX_NO_MIRROR); if(transmode=='n') { - Mat4MulVecfl(obedit->obmat, nor); - VecSubf(nor, nor, obedit->obmat[3]); + mul_m4_v3(obedit->obmat, nor); + sub_v3_v3v3(nor, nor, obedit->obmat[3]); // BIF_setSingleAxisConstraint(nor, "along normal"); } // Transform(); @@ -816,15 +816,15 @@ static int extrude_repeat_mesh(bContext *C, wmOperator *op) dvec[0]= rv3d->persinv[2][0]; dvec[1]= rv3d->persinv[2][1]; dvec[2]= rv3d->persinv[2][2]; - Normalize(dvec); + normalize_v3(dvec); dvec[0]*= offs; dvec[1]*= offs; dvec[2]*= offs; /* base correction */ - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(tmat, bmat); - Mat3MulVecfl(tmat, dvec); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(tmat, bmat); + mul_m3_v3(tmat, dvec); for(a=0; a<steps; a++) { extrudeflag(obedit, em, SELECT, nor); @@ -879,30 +879,30 @@ static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float RNA_float_get_array(op->ptr, "center", cent); /* imat and center and size */ - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(imat,bmat); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat,bmat); cent[0]-= obedit->obmat[3][0]; cent[1]-= obedit->obmat[3][1]; cent[2]-= obedit->obmat[3][2]; - Mat3MulVecfl(imat, cent); + mul_m3_v3(imat, cent); phi= degr*M_PI/360.0; phi/= steps; if(ts->editbutflag & B_CLOCKWISE) phi= -phi; RNA_float_get_array(op->ptr, "axis", n); - Normalize(n); + normalize_v3(n); q[0]= (float)cos(phi); si= (float)sin(phi); q[1]= n[0]*si; q[2]= n[1]*si; q[3]= n[2]*si; - QuatToMat3(q, cmat); + quat_to_mat3( cmat,q); - Mat3MulMat3(tmat,cmat,bmat); - Mat3MulMat3(bmat,imat,tmat); + mul_m3_m3m3(tmat,cmat,bmat); + mul_m3_m3m3(bmat,imat,tmat); if(dupli==0) if(ts->editbutflag & B_KEEPORIG) @@ -917,7 +917,7 @@ static int spin_mesh(bContext *C, wmOperator *op, float *dvec, int steps, float rotateflag(em, SELECT, cent, bmat); if(dvec) { - Mat3MulVecfl(bmat,dvec); + mul_m3_v3(bmat,dvec); translateflag(em, SELECT, dvec); } } @@ -1362,8 +1362,8 @@ static void alter_co(float *co, EditEdge *edge, float smooth, float fractal, int /* we calculate an offset vector vec1[], to be added to *co */ float len, fac, nor[3], nor1[3], nor2[3]; - VecSubf(nor, edge->v1->co, edge->v2->co); - len= 0.5f*Normalize(nor); + sub_v3_v3v3(nor, edge->v1->co, edge->v2->co); + len= 0.5f*normalize_v3(nor); VECCOPY(nor1, edge->v1->no); VECCOPY(nor2, edge->v2->no); @@ -1394,18 +1394,18 @@ static void alter_co(float *co, EditEdge *edge, float smooth, float fractal, int co[2] += vec1[2]; } else if(beauty & B_SPHERE) { /* subdivide sphere */ - Normalize(co); + normalize_v3(co); co[0]*= smooth; co[1]*= smooth; co[2]*= smooth; } if(beauty & B_FRACTAL) { - fac= fractal*VecLenf(edge->v1->co, edge->v2->co); + fac= fractal*len_v3v3(edge->v1->co, edge->v2->co); vec1[0]= fac*(float)(0.5-BLI_drand()); vec1[1]= fac*(float)(0.5-BLI_drand()); vec1[2]= fac*(float)(0.5-BLI_drand()); - VecAddf(co, co, vec1); + add_v3_v3v3(co, co, vec1); } } @@ -1446,7 +1446,7 @@ static EditVert *subdivide_edge_addvert(EditMesh *em, EditEdge *edge, float smoo ev->no[0] = (edge->v2->no[0]-edge->v1->no[0])*percent + edge->v1->no[0]; ev->no[1] = (edge->v2->no[1]-edge->v1->no[1])*percent + edge->v1->no[1]; ev->no[2] = (edge->v2->no[2]-edge->v1->no[2])*percent + edge->v1->no[2]; - Normalize(ev->no); + normalize_v3(ev->no); return ev; } @@ -1475,11 +1475,11 @@ static void facecopy(EditMesh *em, EditFace *source, EditFace *target) target->flag = source->flag; target->h = source->h; - InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v1->co, w[0]); - InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v2->co, w[1]); - InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v3->co, w[2]); + interp_weights_face_v3( w[0],v1, v2, v3, v4, target->v1->co); + interp_weights_face_v3( w[1],v1, v2, v3, v4, target->v2->co); + interp_weights_face_v3( w[2],v1, v2, v3, v4, target->v3->co); if (target->v4) - InterpWeightsQ3Dfl(v1, v2, v3, v4, target->v4->co, w[3]); + interp_weights_face_v3( w[3],v1, v2, v3, v4, target->v4->co); CustomData_em_interp(&em->fdata, &source->data, NULL, (float*)w, 1, target->data); } @@ -2623,15 +2623,15 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float VECCOPY(v2mat, ef->v2->co); VECCOPY(v3mat, ef->v3->co); VECCOPY(v4mat, ef->v4->co); - Mat4Mul3Vecfl(obedit->obmat, v1mat); - Mat4Mul3Vecfl(obedit->obmat, v2mat); - Mat4Mul3Vecfl(obedit->obmat, v3mat); - Mat4Mul3Vecfl(obedit->obmat, v4mat); - - length[0] = VecLenf(v1mat, v2mat); - length[1] = VecLenf(v2mat, v3mat); - length[2] = VecLenf(v3mat, v4mat); - length[3] = VecLenf(v4mat, v1mat); + mul_mat3_m4_v3(obedit->obmat, v1mat); + mul_mat3_m4_v3(obedit->obmat, v2mat); + mul_mat3_m4_v3(obedit->obmat, v3mat); + mul_mat3_m4_v3(obedit->obmat, v4mat); + + length[0] = len_v3v3(v1mat, v2mat); + length[1] = len_v3v3(v2mat, v3mat); + length[2] = len_v3v3(v3mat, v4mat); + length[3] = len_v3v3(v4mat, v1mat); sort[0] = ef->e1; sort[1] = ef->e2; sort[2] = ef->e3; @@ -3121,43 +3121,43 @@ static float measure_facepair(EditVert *v1, EditVert *v2, EditVert *v3, EditVert minarea, maxarea, areaA, areaB; /*First Test: Normal difference*/ - CalcNormFloat(v1->co, v2->co, v3->co, noA1); - CalcNormFloat(v1->co, v3->co, v4->co, noA2); + normal_tri_v3( noA1,v1->co, v2->co, v3->co); + normal_tri_v3( noA2,v1->co, v3->co, v4->co); if(noA1[0] == noA2[0] && noA1[1] == noA2[1] && noA1[2] == noA2[2]) normalADiff = 0.0; - else normalADiff = RAD2DEG(VecAngle2(noA1, noA2)); + else normalADiff = RAD2DEG(angle_v2v2(noA1, noA2)); //if(!normalADiff) normalADiff = 179; - CalcNormFloat(v2->co, v3->co, v4->co, noB1); - CalcNormFloat(v4->co, v1->co, v2->co, noB2); + normal_tri_v3( noB1,v2->co, v3->co, v4->co); + normal_tri_v3( noB2,v4->co, v1->co, v2->co); if(noB1[0] == noB2[0] && noB1[1] == noB2[1] && noB1[2] == noB2[2]) normalBDiff = 0.0; - else normalBDiff = RAD2DEG(VecAngle2(noB1, noB2)); + else normalBDiff = RAD2DEG(angle_v2v2(noB1, noB2)); //if(!normalBDiff) normalBDiff = 179; measure += (normalADiff/360) + (normalBDiff/360); if(measure > limit) return measure; /*Second test: Colinearity*/ - VecSubf(edgeVec1, v1->co, v2->co); - VecSubf(edgeVec2, v2->co, v3->co); - VecSubf(edgeVec3, v3->co, v4->co); - VecSubf(edgeVec4, v4->co, v1->co); + sub_v3_v3v3(edgeVec1, v1->co, v2->co); + sub_v3_v3v3(edgeVec2, v2->co, v3->co); + sub_v3_v3v3(edgeVec3, v3->co, v4->co); + sub_v3_v3v3(edgeVec4, v4->co, v1->co); diff = 0.0; diff = ( - fabs(RAD2DEG(VecAngle2(edgeVec1, edgeVec2)) - 90) + - fabs(RAD2DEG(VecAngle2(edgeVec2, edgeVec3)) - 90) + - fabs(RAD2DEG(VecAngle2(edgeVec3, edgeVec4)) - 90) + - fabs(RAD2DEG(VecAngle2(edgeVec4, edgeVec1)) - 90)) / 360; + fabs(RAD2DEG(angle_v2v2(edgeVec1, edgeVec2)) - 90) + + fabs(RAD2DEG(angle_v2v2(edgeVec2, edgeVec3)) - 90) + + fabs(RAD2DEG(angle_v2v2(edgeVec3, edgeVec4)) - 90) + + fabs(RAD2DEG(angle_v2v2(edgeVec4, edgeVec1)) - 90)) / 360; if(!diff) return 0.0; measure += diff; if(measure > limit) return measure; /*Third test: Concavity*/ - areaA = AreaT3Dfl(v1->co, v2->co, v3->co) + AreaT3Dfl(v1->co, v3->co, v4->co); - areaB = AreaT3Dfl(v2->co, v3->co, v4->co) + AreaT3Dfl(v4->co, v1->co, v2->co); + areaA = area_tri_v3(v1->co, v2->co, v3->co) + area_tri_v3(v1->co, v3->co, v4->co); + areaB = area_tri_v3(v2->co, v3->co, v4->co) + area_tri_v3(v4->co, v1->co, v2->co); if(areaA <= areaB) minarea = areaA; else minarea = areaB; @@ -3259,7 +3259,7 @@ void join_triangles(EditMesh *em) EVPtr *efaa = NULL; float *creases = NULL; float measure; /*Used to set tolerance*/ - float limit = 0.0f; // XXX scene->toolsettings->jointrilimit; + float limit = 0.8f; // XXX scene->toolsettings->jointrilimit; int i, ok, totedge=0, totseledge=0, complexedges, vindex[4]; /*if we take a long time on very dense meshes we want waitcursor to display*/ @@ -4370,9 +4370,9 @@ useless: } if(prop == 0) { - len = VecLenf(upVert->co,downVert->co)*((perc+1)/2); + len = len_v3v3(upVert->co,downVert->co)*((perc+1)/2); if(flip == 1) { - len = VecLenf(upVert->co,downVert->co) - len; + len = len_v3v3(upVert->co,downVert->co) - len; } } @@ -4387,7 +4387,7 @@ useless: } else { - len = MIN2(perc, VecLenf(upVert->co,downVert->co)); + len = MIN2(perc, len_v3v3(upVert->co,downVert->co)); len = MAX2(len, 0); } } @@ -4405,13 +4405,13 @@ useless: tempsv = BLI_ghash_lookup(vertgh,ev); tempev = editedge_getOtherVert((perc>=0)?tempsv->up:tempsv->down, ev); - VecLerpf(ev->co, tempsv->origvert.co, tempev->co, fabs(perc)); + interp_v3_v3v3(ev->co, tempsv->origvert.co, tempev->co, fabs(perc)); if (0) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { - Vec2Lerpf(uv_tmp, suv->origuv, (perc>=0)?suv->uv_up:suv->uv_down, fabs(perc)); + interp_v2_v2v2(uv_tmp, suv->origuv, (perc>=0)?suv->uv_up:suv->uv_down, fabs(perc)); fuv_link = suv->fuv_list; while (fuv_link) { VECCOPY2D(((float *)fuv_link->link), uv_tmp); @@ -4431,17 +4431,17 @@ useless: float newlen; ev = look->link; tempsv = BLI_ghash_lookup(vertgh,ev); - newlen = (len / VecLenf(editedge_getOtherVert(tempsv->up,ev)->co,editedge_getOtherVert(tempsv->down,ev)->co)); + newlen = (len / len_v3v3(editedge_getOtherVert(tempsv->up,ev)->co,editedge_getOtherVert(tempsv->down,ev)->co)); if(newlen > 1.0) {newlen = 1.0;} if(newlen < 0.0) {newlen = 0.0;} if(flip == 0) { - VecLerpf(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen)); + interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen)); if (0) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { - Vec2Lerpf(uv_tmp, suv->uv_down, suv->uv_up, fabs(newlen)); + interp_v2_v2v2(uv_tmp, suv->uv_down, suv->uv_up, fabs(newlen)); fuv_link = suv->fuv_list; while (fuv_link) { VECCOPY2D(((float *)fuv_link->link), uv_tmp); @@ -4451,14 +4451,14 @@ useless: } } } else{ - VecLerpf(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen)); + interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen)); if (0) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { - Vec2Lerpf(uv_tmp, suv->uv_up, suv->uv_down, fabs(newlen)); + interp_v2_v2v2(uv_tmp, suv->uv_up, suv->uv_down, fabs(newlen)); fuv_link = suv->fuv_list; while (fuv_link) { VECCOPY2D(((float *)fuv_link->link), uv_tmp); @@ -4768,7 +4768,7 @@ static float mesh_rip_edgedist(ARegion *ar, float mat[][4], float *co1, float *c mvalf[0]= (float)mval[0]; mvalf[1]= (float)mval[1]; - return PdistVL2Dfl(mvalf, vec1, vec2); + return dist_to_line_segment_v2(mvalf, vec1, vec2); } /* helper for below */ @@ -5120,11 +5120,11 @@ static int blend_from_shape_exec(bContext *C, wmOperator *op) VECCOPY(co, data + eve->keyindex*3); if(add) { - VecMulf(co, blend); - VecAddf(eve->co, eve->co, co); + mul_v3_fl(co, blend); + add_v3_v3v3(eve->co, eve->co, co); } else - VecLerpf(eve->co, eve->co, co, blend); + interp_v3_v3v3(eve->co, eve->co, co, blend); blended= 1; } @@ -5737,7 +5737,7 @@ static void em_snap_to_center(EditMesh *em) for (eve=em->verts.first; eve; eve=eve->next) { if (eve->f & SELECT) { - VecAddf(cent, cent, eve->co); + add_v3_v3v3(cent, cent, eve->co); i++; } } @@ -5745,7 +5745,7 @@ static void em_snap_to_center(EditMesh *em) if (!i) return; - VecMulf(cent, 1.0f / (float)i); + mul_v3_fl(cent, 1.0f / (float)i); for (eve=em->verts.first; eve; eve=eve->next) { if (eve->f & SELECT) { @@ -5762,11 +5762,11 @@ static void em_snap_to_cursor(EditMesh *em, bContext *C) EditVert *eve; float co[3], *vco, invmat[4][4]; - Mat4Invert(invmat, ob->obmat); + invert_m4_m4(invmat, ob->obmat); vco = give_cursor(scene, v3d); VECCOPY(co, vco); - Mat4MulVecfl(invmat, co); + mul_m4_v3(invmat, co); for (eve=em->verts.first; eve; eve=eve->next) { if (eve->f & SELECT) { @@ -5987,7 +5987,7 @@ static int select_vertex_path_exec(bContext *C, wmOperator *op) newpe = MEM_mallocN(sizeof(PathEdge), "Path Edge"); newpe->v = ((PathNode*)eed->v2->tmp.p)->u; if(physical){ - newpe->w = VecLenf(eed->v1->co, eed->v2->co); + newpe->w = len_v3v3(eed->v1->co, eed->v2->co); } else newpe->w = 1; newpe->next = 0; @@ -5999,7 +5999,7 @@ static int select_vertex_path_exec(bContext *C, wmOperator *op) newpe = MEM_mallocN(sizeof(PathEdge), "Path Edge"); newpe->v = ((PathNode*)eed->v1->tmp.p)->u; if(physical){ - newpe->w = VecLenf(eed->v1->co, eed->v2->co); + newpe->w = len_v3v3(eed->v1->co, eed->v2->co); } else newpe->w = 1; newpe->next = 0; @@ -6813,20 +6813,20 @@ static void beauty_fill(EditMesh *em) * the area divided by the total edge lengths */ - len1= VecLenf(v1->co, v2->co); - len2= VecLenf(v2->co, v3->co); - len3= VecLenf(v3->co, v4->co); - len4= VecLenf(v4->co, v1->co); - len5= VecLenf(v1->co, v3->co); - len6= VecLenf(v2->co, v4->co); + len1= len_v3v3(v1->co, v2->co); + len2= len_v3v3(v2->co, v3->co); + len3= len_v3v3(v3->co, v4->co); + len4= len_v3v3(v4->co, v1->co); + len5= len_v3v3(v1->co, v3->co); + len6= len_v3v3(v2->co, v4->co); - opp1= AreaT3Dfl(v1->co, v2->co, v3->co); - opp2= AreaT3Dfl(v1->co, v3->co, v4->co); + opp1= area_tri_v3(v1->co, v2->co, v3->co); + opp2= area_tri_v3(v1->co, v3->co, v4->co); fac1= opp1/(len1+len2+len5) + opp2/(len3+len4+len5); - opp1= AreaT3Dfl(v2->co, v3->co, v4->co); - opp2= AreaT3Dfl(v2->co, v4->co, v1->co); + opp1= area_tri_v3(v2->co, v3->co, v4->co); + opp2= area_tri_v3(v2->co, v4->co, v1->co); fac2= opp1/(len2+len3+len6) + opp2/(len4+len1+len6); diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 94a7dbebb9c..eb6927cec65 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -38,6 +38,7 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" #include "BKE_context.h" @@ -49,7 +50,7 @@ #include "BKE_mesh.h" #include "BKE_report.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_edgehash.h" @@ -63,6 +64,8 @@ #include "ED_object.h" #include "ED_view3d.h" +#include "RE_render_ext.h" + #include "mesh_intern.h" static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer) @@ -389,13 +392,15 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot) static int sticky_add_exec(bContext *C, wmOperator *op) { + Scene *scene= CTX_data_scene(C); + View3D *v3d= CTX_wm_view3d(C); Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; Mesh *me= ob->data; - if(me->msticky) - return OPERATOR_CANCELLED; + /*if(me->msticky) + return OPERATOR_CANCELLED;*/ - // XXX RE_make_sticky(); + RE_make_sticky(scene, v3d); DAG_id_flush_update(&me->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, me); @@ -566,7 +571,7 @@ void ED_mesh_transform(Mesh *me, float *mat) MVert *mvert= me->mvert; for(i= 0; i < me->totvert; i++, mvert++) - Mat4MulVecfl((float (*)[4])mat, mvert->co); + mul_m4_v3((float (*)[4])mat, mvert->co); mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL); } diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 9f16e7adbf8..ffa9dde4493 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -39,7 +39,7 @@ #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 8bd8629a595..5313b68be9b 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -51,7 +51,7 @@ #include "DNA_windowmanager_types.h" #include "DNA_world_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_ghash.h" @@ -123,7 +123,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) KeyBlock *kb, *okb, *kbn; float imat[4][4], cmat[4][4], *fp1, *fp2, curpos; int a, b, totcol, totmat=0, totedge=0, totvert=0, totface=0, ok=0; - int vertofs, *matmap; + int vertofs, *matmap=NULL; int i, j, index, haskey=0, edgeofs, faceofs; bDeformGroup *dg, *odg; MDeformVert *dvert; @@ -168,7 +168,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* new material indices and material array */ matar= MEM_callocN(sizeof(void*)*totmat, "join_mesh matar"); - matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap"); + if (totmat) matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap"); totcol= ob->totcol; /* obact materials in new main array, is nicer start! */ @@ -305,7 +305,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) faceofs= 0; /* inverse transform for all selected meshes in this object */ - Mat4Invert(imat, ob->obmat); + invert_m4_m4(imat, ob->obmat); CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { /* only join if this is a mesh */ @@ -342,11 +342,11 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* if this is the object we're merging into, no need to do anything */ if(base->object != ob) { /* watch this: switch matmul order really goes wrong */ - Mat4MulMat4(cmat, base->object->obmat, imat); + mul_m4_m4m4(cmat, base->object->obmat, imat); /* transform vertex coordinates into new space */ for(a=0, mv=mvert; a < me->totvert; a++, mv++) { - Mat4MulVecfl(cmat, mv->co); + mul_m4_v3(cmat, mv->co); } /* for each shapekey in destination mesh: @@ -366,7 +366,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) fp2= ((float *)(okb->data)); for(a=0; a < me->totvert; a++, fp1+=3, fp2+=3) { VECCOPY(fp1, fp2); - Mat4MulVecfl(cmat, fp1); + mul_m4_v3(cmat, fp1); } } else { @@ -435,7 +435,10 @@ int join_mesh_exec(bContext *C, wmOperator *op) mface->v3+= vertofs; if(mface->v4) mface->v4+= vertofs; - mface->mat_nr= matmap[(int)mface->mat_nr]; + if (matmap) + mface->mat_nr= matmap[(int)mface->mat_nr]; + else + mface->mat_nr= 0; } faceofs += me->totface; @@ -508,7 +511,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) ob->totcol= me->totcol= totcol; ob->colbits= 0; - MEM_freeN(matmap); + if (matmap) MEM_freeN(matmap); /* other mesh users */ test_object_materials((ID *)me); @@ -630,15 +633,15 @@ void sort_faces(Scene *scene, View3D *v3d) float cur[3]; if (event == 1) - Mat4MulMat4(mat, OBACT->obmat, rv3d->viewmat); /* apply the view matrix to the object matrix */ + mul_m4_m4m4(mat, OBACT->obmat, rv3d->viewmat); /* apply the view matrix to the object matrix */ else if (event == 2) { /* sort from cursor */ if( v3d && v3d->localvd ) { VECCOPY(cur, v3d->cursor); } else { VECCOPY(cur, scene->cursor); } - Mat4Invert(mat, OBACT->obmat); - Mat4MulVecfl(mat, cur); + invert_m4_m4(mat, OBACT->obmat); + mul_m4_v3(mat, cur); } mf= me->mface; @@ -652,21 +655,21 @@ void sort_faces(Scene *scene, View3D *v3d) else face_sort_floats[i] = reverse; } else { /* find the faces center */ - VecAddf(vec, (me->mvert+mf->v1)->co, (me->mvert+mf->v2)->co); + add_v3_v3v3(vec, (me->mvert+mf->v1)->co, (me->mvert+mf->v2)->co); if (mf->v4) { - VecAddf(vec, vec, (me->mvert+mf->v3)->co); - VecAddf(vec, vec, (me->mvert+mf->v4)->co); - VecMulf(vec, 0.25f); + add_v3_v3v3(vec, vec, (me->mvert+mf->v3)->co); + add_v3_v3v3(vec, vec, (me->mvert+mf->v4)->co); + mul_v3_fl(vec, 0.25f); } else { - VecAddf(vec, vec, (me->mvert+mf->v3)->co); - VecMulf(vec, 1.0f/3.0f); + add_v3_v3v3(vec, vec, (me->mvert+mf->v3)->co); + mul_v3_fl(vec, 1.0f/3.0f); } /* done */ if (event == 1) { /* sort on view axis */ - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); face_sort_floats[i] = vec[2] * reverse; } else { /* distance from cursor*/ - face_sort_floats[i] = VecLenf(cur, vec) * reverse; /* back to front */ + face_sort_floats[i] = len_v3v3(cur, vec) * reverse; /* back to front */ } } } @@ -808,12 +811,12 @@ static intptr_t mesh_octree_find_index(MocNode **bt, MVert *mvert, float *co) /* does mesh verts and editmode, code looks potential dangerous, octree should really be filled OK! */ if(mvert) { vec= (mvert+(*bt)->index[a]-1)->co; - if(FloatCompare(vec, co, MOC_THRESH)) + if(compare_v3v3(vec, co, MOC_THRESH)) return (*bt)->index[a]-1; } else { EditVert *eve= (EditVert *)((*bt)->index[a]); - if(FloatCompare(eve->co, co, MOC_THRESH)) + if(compare_v3v3(eve->co, co, MOC_THRESH)) return (*bt)->index[a]; } } @@ -878,12 +881,12 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode) MeshOctree.offs[1]-= MOC_THRESH; MeshOctree.offs[2]-= MOC_THRESH; - VecSubf(MeshOctree.div, max, min); + sub_v3_v3v3(MeshOctree.div, max, min); MeshOctree.div[0]+= 2*MOC_THRESH; /* and divide with 2 threshold unit more extra (try 8x8 unit grid on paint) */ MeshOctree.div[1]+= 2*MOC_THRESH; MeshOctree.div[2]+= 2*MOC_THRESH; - VecMulf(MeshOctree.div, 1.0f/MOC_RES); + mul_v3_fl(MeshOctree.div, 1.0f/MOC_RES); if(MeshOctree.div[0]==0.0f) MeshOctree.div[0]= 1.0f; if(MeshOctree.div[1]==0.0f) MeshOctree.div[1]= 1.0f; if(MeshOctree.div[2]==0.0f) MeshOctree.div[2]= 1.0f; diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index f335e47188f..3751f8875f6 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "DNA_meta_types.h" @@ -116,7 +116,7 @@ MetaElem *add_metaball_primitive(bContext *C, int type, int newname) ml= ml->next; } - Mat3CpyMat4(mat, obedit->obmat); + copy_m3_m4(mat, obedit->obmat); if(v3d) { curs= give_cursor(scene, v3d); VECCOPY(cent, curs); @@ -130,16 +130,16 @@ MetaElem *add_metaball_primitive(bContext *C, int type, int newname) if (rv3d) { if (!(newname) || U.flag & USER_ADD_VIEWALIGNED) - Mat3CpyMat4(imat, rv3d->viewmat); + copy_m3_m4(imat, rv3d->viewmat); else - Mat3One(imat); - Mat3MulVecfl(imat, cent); - Mat3MulMat3(cmat, imat, mat); - Mat3Inv(imat,cmat); - Mat3MulVecfl(imat, cent); + unit_m3(imat); + mul_m3_v3(imat, cent); + mul_m3_m3m3(cmat, imat, mat); + invert_m3_m3(imat,cmat); + mul_m3_v3(imat, cent); } else - Mat3One(imat); + unit_m3(imat); ml= MEM_callocN(sizeof(MetaElem), "metaelem"); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 5378ee47f89..e58170ebab6 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -46,7 +46,7 @@ #include "DNA_view3d_types.h" #include "DNA_vfont_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BKE_anim.h" @@ -126,7 +126,7 @@ void ED_object_base_init_from_view(bContext *C, Base *base, int view_align) RegionView3D *rv3d = CTX_wm_region_view3d(C); if(rv3d) { rv3d->viewquat[0]= -rv3d->viewquat[0]; - QuatToEul(rv3d->viewquat, ob->rot); + quat_to_eul( ob->rot,rv3d->viewquat); rv3d->viewquat[0]= -rv3d->viewquat[0]; } } @@ -928,7 +928,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base) ob->disp.first= ob->disp.last= NULL; ob->transflag &= ~OB_DUPLI; - Mat4CpyMat4(ob->obmat, dob->mat); + copy_m4_m4(ob->obmat, dob->mat); ED_object_apply_obmat(ob); } @@ -1262,9 +1262,8 @@ static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag Group *group; for(group= G.main->group.first; group; group= group->id.next) { if(object_in_group(ob, group)) - add_to_group(group, obn); + add_to_group(group, obn, scene, basen); } - obn->flag |= OB_FROMGROUP; /* this flag is unset with copy_object() */ } /* duplicates using userflags */ diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 35b11571a61..dbc7973b67b 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -33,7 +33,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dynstr.h" #include "DNA_action_types.h" @@ -187,56 +187,6 @@ void update_pyconstraint_cb (void *arg1, void *arg2) #endif } -/* Creates a new constraint, initialises its data, and returns it */ -bConstraint *add_new_constraint (short type) -{ - bConstraint *con; - bConstraintTypeInfo *cti; - - con = MEM_callocN(sizeof(bConstraint), "Constraint"); - - /* Set up a generic constraint datablock */ - con->type = type; - con->flag |= CONSTRAINT_EXPAND; - con->enforce = 1.0f; - - /* Load the data for it */ - cti = constraint_get_typeinfo(con); - if (cti) { - con->data = MEM_callocN(cti->size, cti->structName); - - /* only constraints that change any settings need this */ - if (cti->new_data) - cti->new_data(con->data); - - /* set the name based on the type of constraint */ - strcpy(con->name, cti->name); - } - else - strcpy(con->name, "Const"); - - return con; -} - -/* Adds the given constraint to the Object-level set of constraints for the given Object */ -void add_constraint_to_object (bConstraint *con, Object *ob) -{ - ListBase *list; - list = &ob->constraints; - - if (list) { - unique_constraint_name(con, list); - BLI_addtail(list, con); - - if (proxylocked_constraints_owner(ob, NULL)) - con->flag |= CONSTRAINT_PROXY_LOCAL; - - con->flag |= CONSTRAINT_ACTIVE; - for (con= con->prev; con; con= con->prev) - con->flag &= ~CONSTRAINT_ACTIVE; - } -} - /* helper function for add_constriant - sets the last target for the active constraint */ static void set_constraint_nth_target (bConstraint *con, Object *target, char subtarget[], int index) { @@ -401,9 +351,7 @@ static void test_constraints (Object *owner, const char substring[]) /* if the number of points does not match the amount required by the chain length, * free the points array and request a rebind... */ - if ( (data->points == NULL) || - (!(data->flag & CONSTRAINT_SPLINEIK_NO_ROOT) && (data->numpoints != data->chainlen+1)) || - ( (data->flag & CONSTRAINT_SPLINEIK_NO_ROOT) && (data->numpoints != data->chainlen)) ) + if ((data->points == NULL) || (data->numpoints != data->chainlen+1)) { /* free the points array */ if (data->points) { @@ -577,7 +525,7 @@ static int childof_set_inverse_exec (bContext *C, wmOperator *op) float imat[4][4], tmat[4][4]; /* make copy of pchan's original pose-mat (for use later) */ - Mat4CpyMat4(pmat, pchan->pose_mat); + copy_m4_m4(pmat, pchan->pose_mat); /* disable constraint for pose to be solved without it */ cinf= con->enforce; @@ -590,9 +538,9 @@ static int childof_set_inverse_exec (bContext *C, wmOperator *op) * pchan->pose_mat from the original pchan->pose_mat, thus determining * the effect of the constraint */ - Mat4Invert(imat, pchan->pose_mat); - Mat4MulMat4(tmat, imat, pmat); - Mat4Invert(data->invmat, tmat); + invert_m4_m4(imat, pchan->pose_mat); + mul_m4_m4m4(tmat, imat, pmat); + invert_m4_m4(data->invmat, tmat); /* recalculate pose with new inv-mat */ con->enforce= cinf; @@ -604,10 +552,10 @@ static int childof_set_inverse_exec (bContext *C, wmOperator *op) * NOTE: what_does_parent uses a static workob defined in object.c */ what_does_parent(scene, ob, &workob); - Mat4Invert(data->invmat, workob.obmat); + invert_m4_m4(data->invmat, workob.obmat); } else - Mat4One(data->invmat); + unit_m4(data->invmat); WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob); @@ -637,7 +585,7 @@ static int childof_clear_inverse_exec (bContext *C, wmOperator *op) bChildOfConstraint *data= (bChildOfConstraint *)con->data; /* simply clear the matrix */ - Mat4One(data->invmat); + unit_m4(data->invmat); WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob); @@ -1052,9 +1000,9 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o * if adding a target for an IK Constraint */ if (con_type == CONSTRAINT_TYPE_KINEMATIC) - VecMat4MulVecfl(obt->loc, obact->obmat, pchanact->pose_tail); + mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_tail); else - VecMat4MulVecfl(obt->loc, obact->obmat, pchanact->pose_head); + mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_head); } else VECCOPY(obt->loc, obact->obmat[3]); @@ -1076,9 +1024,14 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, short setTarget) { Scene *scene= CTX_data_scene(C); - bPoseChannel *pchan= get_active_posechannel(ob); + bPoseChannel *pchan; bConstraint *con; + if(list == &ob->constraints) + pchan= NULL; + else + pchan= get_active_posechannel(ob); + /* check if constraint to be added is valid for the given constraints stack */ if (type == CONSTRAINT_TYPE_NULL) { return OPERATOR_CANCELLED; @@ -1097,32 +1050,10 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase } /* create a new constraint of the type requried, and add it to the active/given constraints list */ - con = add_new_constraint(type); - - if (list) { - bConstraint *coniter; - - /* add new constraint to end of list of constraints before ensuring that it has a unique name - * (otherwise unique-naming code will fail, since it assumes element exists in list) - */ - BLI_addtail(list, con); - unique_constraint_name(con, list); - - /* if the target list is a list on some PoseChannel belonging to a proxy-protected - * Armature layer, we must tag newly added constraints with a flag which allows them - * to persist after proxy syncing has been done - */ - if (proxylocked_constraints_owner(ob, pchan)) - con->flag |= CONSTRAINT_PROXY_LOCAL; - - /* make this constraint the active one - * - since constraint was added at end of stack, we can just go - * through deactivating all previous ones - */ - con->flag |= CONSTRAINT_ACTIVE; - for (coniter= con->prev; coniter; coniter= coniter->prev) - coniter->flag &= ~CONSTRAINT_ACTIVE; - } + if(pchan) + con = add_pose_constraint(ob, pchan, NULL, type); + else + con = add_ob_constraint(ob, NULL, type); /* get the first selected object/bone, and make that the target * - apart from the buttons-window add buttons, we shouldn't add in this way diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 0cfdd914222..7bb345bf46c 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -67,7 +67,7 @@ #include "DNA_modifier_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_ghash.h" #include "BLI_rand.h" @@ -161,16 +161,16 @@ void ED_object_apply_obmat(Object *ob) /* from obmat to loc rot size */ if(ob==NULL) return; - Mat3CpyMat4(mat, ob->obmat); + copy_m3_m4(mat, ob->obmat); VECCOPY(ob->loc, ob->obmat[3]); - Mat3ToEul(mat, ob->rot); - EulToMat3(ob->rot, tmat); + mat3_to_eul( ob->rot,mat); + eul_to_mat3( tmat,ob->rot); - Mat3Inv(imat, tmat); + invert_m3_m3(imat, tmat); - Mat3MulMat3(tmat, imat, mat); + mul_m3_m3m3(tmat, imat, mat); ob->size[0]= tmat[0][0]; ob->size[1]= tmat[1][1]; diff --git a/source/blender/editors/object/object_group.c b/source/blender/editors/object/object_group.c index ec8409e9aa1..1e5b93aa6dc 100644 --- a/source/blender/editors/object/object_group.c +++ b/source/blender/editors/object/object_group.c @@ -60,7 +60,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); - Object *ob= OBACT, *obt; + Object *ob= OBACT; Group *group; int ok = 0; @@ -73,11 +73,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) if(object_in_group(ob, group)) { /* Assign groups to selected objects */ CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { - obt= base->object; - add_to_group(group, obt); - obt->flag |= OB_FROMGROUP; - base->flag |= OB_FROMGROUP; - base->object->recalc= OB_RECALC_OB; + add_to_group(group, base->object, scene, base); ok = 1; } CTX_DATA_END; @@ -110,7 +106,7 @@ void GROUP_OT_objects_add_active(wmOperatorType *ot) static int objects_remove_active_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); - Object *ob= OBACT, *obt; + Object *ob= OBACT; Group *group; int ok = 0; @@ -123,11 +119,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op) if(object_in_group(ob, group)) { /* Assign groups to selected objects */ CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { - obt= base->object; - rem_from_group(group, obt); - obt->flag &= ~OB_FROMGROUP; - base->flag &= ~OB_FROMGROUP; - base->object->recalc= OB_RECALC_OB; + rem_from_group(group, base->object, scene, base); ok = 1; } CTX_DATA_END; @@ -165,11 +157,7 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { group = NULL; while((group = find_group(base->object, group))) - rem_from_group(group, base->object); - - base->object->flag &= ~OB_FROMGROUP; - base->flag &= ~OB_FROMGROUP; - base->object->recalc= OB_RECALC_OB; + rem_from_group(group, base->object, scene, base); } CTX_DATA_END; @@ -205,10 +193,7 @@ static int group_create_exec(bContext *C, wmOperator *op) group= add_group(name); CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { - add_to_group(group, base->object); - base->object->flag |= OB_FROMGROUP; - base->flag |= OB_FROMGROUP; - base->object->recalc= OB_RECALC_OB; + add_to_group(group, base->object, scene, base); } CTX_DATA_END; @@ -259,9 +244,7 @@ static int group_add_exec(bContext *C, wmOperator *op) group= BLI_findlink(&bmain->group, value); if(group) { - add_to_group(group, ob); - ob->flag |= OB_FROMGROUP; - base->flag |= OB_FROMGROUP; + add_to_group(group, ob, scene, NULL); /* base will be used if found */ } WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -323,21 +306,11 @@ static int group_remove_exec(bContext *C, wmOperator *op) Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; Group *group= CTX_data_pointer_get_type(C, "group", &RNA_Group).data; - Base *base; if(!ob || !group) return OPERATOR_CANCELLED; - base= object_in_scene(ob, scene); - if(!base) - return OPERATOR_CANCELLED; - - rem_from_group(group, ob); - - if(find_group(ob, NULL) == NULL) { - ob->flag &= ~OB_FROMGROUP; - base->flag &= ~OB_FROMGROUP; - } + rem_from_group(group, ob, scene, NULL); /* base will be used if found */ WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index 22a6329a097..91aebc8b149 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -30,7 +30,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_listbase.h" #include "BLI_string.h" @@ -77,12 +77,12 @@ static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float for(eve= em->verts.first; eve; eve= eve->next) { if(eve->f & SELECT) { *index= nr; index++; - VecAddf(cent, cent, eve->co); + add_v3_v3v3(cent, cent, eve->co); } nr++; } - VecMulf(cent, 1.0f/(float)totvert); + mul_v3_fl(cent, 1.0f/(float)totvert); return totvert; } @@ -105,7 +105,7 @@ static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, floa for(i=0; i<dvert->totweight; i++){ if(dvert->dw[i].def_nr == (obedit->actdef-1)) { totvert++; - VecAddf(cent, cent, eve->co); + add_v3_v3v3(cent, cent, eve->co); } } } @@ -113,7 +113,7 @@ static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, floa if(totvert) { bDeformGroup *defGroup = BLI_findlink(&obedit->defbase, obedit->actdef-1); strcpy(name, defGroup->name); - VecMulf(cent, 1.0f/(float)totvert); + mul_v3_fl(cent, 1.0f/(float)totvert); return 1; } } @@ -170,14 +170,14 @@ static int return_editlattice_indexar(Lattice *editlatt, int *tot, int **indexar if(bp->f1 & SELECT) { if(bp->hide==0) { *index= nr; index++; - VecAddf(cent, cent, bp->vec); + add_v3_v3v3(cent, cent, bp->vec); } } bp++; nr++; } - VecMulf(cent, 1.0f/(float)totvert); + mul_v3_fl(cent, 1.0f/(float)totvert); return totvert; } @@ -243,17 +243,17 @@ static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, flo while(a--) { if(bezt->f1 & SELECT) { *index= nr; index++; - VecAddf(cent, cent, bezt->vec[0]); + add_v3_v3v3(cent, cent, bezt->vec[0]); } nr++; if(bezt->f2 & SELECT) { *index= nr; index++; - VecAddf(cent, cent, bezt->vec[1]); + add_v3_v3v3(cent, cent, bezt->vec[1]); } nr++; if(bezt->f3 & SELECT) { *index= nr; index++; - VecAddf(cent, cent, bezt->vec[2]); + add_v3_v3v3(cent, cent, bezt->vec[2]); } nr++; bezt++; @@ -265,7 +265,7 @@ static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, flo while(a--) { if(bp->f1 & SELECT) { *index= nr; index++; - VecAddf(cent, cent, bp->vec); + add_v3_v3v3(cent, cent, bp->vec); } nr++; bp++; @@ -273,7 +273,7 @@ static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, flo } } - VecMulf(cent, 1.0f/(float)totvert); + mul_v3_fl(cent, 1.0f/(float)totvert); return totvert; } @@ -465,7 +465,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode) ob->lay= newbase->lay; /* transform cent to global coords for loc */ - VecMat4MulVecfl(ob->loc, obedit->obmat, cent); + mul_v3_m4v3(ob->loc, obedit->obmat, cent); /* restore, add_object sets active */ BASACT= base; @@ -489,7 +489,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode) hmd->object= ob; hmd->indexar= indexar; - VecCopyf(hmd->cent, cent); + copy_v3_v3(hmd->cent, cent); hmd->totindex= tot; BLI_strncpy(hmd->name, name, 32); @@ -501,9 +501,9 @@ void add_hook(Scene *scene, View3D *v3d, int mode) where_is_object(scene, ob); - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); /* apparently this call goes from right to left... */ - Mat4MulSerie(hmd->parentinv, ob->imat, obedit->obmat, NULL, + mul_serie_m4(hmd->parentinv, ob->imat, obedit->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } } @@ -520,9 +520,9 @@ void add_hook(Scene *scene, View3D *v3d, int mode) // FIXME: this is now OBJECT_OT_hook_reset operator where_is_object(scene, ob); /* ob is hook->parent */ - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); /* this call goes from right to left... */ - Mat4MulSerie(hmd->parentinv, ob->imat, obedit->obmat, NULL, + mul_serie_m4(hmd->parentinv, ob->imat, obedit->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } @@ -577,8 +577,8 @@ void hookmenu(Scene *scene, View3D *v3d) if (event==1) { if(hmd->object) { - Mat4Invert(hmd->object->imat, hmd->object->obmat); - Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + invert_m4_m4(hmd->object->imat, hmd->object->obmat); + mul_serie_m4(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); changed= 1; DAG_id_flush_update(&ob->id, OB_RECALC_DATA); @@ -589,14 +589,14 @@ void hookmenu(Scene *scene, View3D *v3d) where_is_object(scene, ob); - Mat3CpyMat4(bmat, ob->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, ob->obmat); + invert_m3_m3(imat, bmat); curs= give_cursor(scene, v3d); hmd->cent[0]= curs[0]-ob->obmat[3][0]; hmd->cent[1]= curs[1]-ob->obmat[3][1]; hmd->cent[2]= curs[2]-ob->obmat[3][2]; - Mat3MulVecfl(imat, hmd->cent); + mul_m3_v3(imat, hmd->cent); changed= 1; DAG_id_flush_update(&ob->id, OB_RECALC_DATA); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 0683cb6842f..b84fb47e5ee 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -40,7 +40,7 @@ #include "DNA_object_force.h" #include "DNA_scene_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BKE_action.h" @@ -174,6 +174,9 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod DAG_scene_sort(scene); } + else if(md->type == eModifierType_Smoke) { + ob->dt = OB_SHADED; + } BLI_remlink(&ob->modifiers, md); modifier_free(md); @@ -841,14 +844,14 @@ static int hook_reset_exec(bContext *C, wmOperator *op) float imat[4][4], mat[4][4]; /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ - Mat4MulMat4(mat, pchan->pose_mat, hmd->object->obmat); + mul_m4_m4m4(mat, pchan->pose_mat, hmd->object->obmat); - Mat4Invert(imat, mat); - Mat4MulSerie(hmd->parentinv, imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + invert_m4_m4(imat, mat); + mul_serie_m4(hmd->parentinv, imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } else { - Mat4Invert(hmd->object->imat, hmd->object->obmat); - Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + invert_m4_m4(hmd->object->imat, hmd->object->obmat); + mul_serie_m4(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } } @@ -879,11 +882,11 @@ static int hook_recenter_exec(bContext *C, wmOperator *op) HookModifierData *hmd= ptr.data; float bmat[3][3], imat[3][3]; - Mat3CpyMat4(bmat, ob->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, ob->obmat); + invert_m3_m3(imat, bmat); VECSUB(hmd->cent, scene->cursor, ob->obmat[3]); - Mat3MulVecfl(imat, hmd->cent); + mul_m3_v3(imat, hmd->cent); DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index ccb6e8cdea3..75a95323ce1 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -39,7 +39,7 @@ #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_context.h" diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index cbd1e1be8d5..7e7b1d99825 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -48,7 +48,7 @@ #include "DNA_view3d_types.h" #include "DNA_world_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_listbase.h" #include "BLI_string.h" @@ -221,7 +221,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) /* inverse parent matrix */ what_does_parent(scene, ob, &workob); - Mat4Invert(ob->parentinv, workob.obmat); + invert_m4_m4(ob->parentinv, workob.obmat); } else { ob->partype= PARVERT1; @@ -229,7 +229,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) /* inverse parent matrix */ what_does_parent(scene, ob, &workob); - Mat4Invert(ob->parentinv, workob.obmat); + invert_m4_m4(ob->parentinv, workob.obmat); } } } @@ -451,7 +451,7 @@ static int parent_clear_exec(bContext *C, wmOperator *op) ED_object_apply_obmat(ob); } else if(type == 2) - Mat4One(ob->parentinv); + unit_m4(ob->parentinv); ob->recalc |= OB_RECALC; } @@ -608,16 +608,13 @@ static int parent_set_exec(bContext *C, wmOperator *op) bFollowPathConstraint *data; float cmat[4][4], vec[3]; - con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH); - strcpy (con->name, "AutoPath"); + con = add_ob_constraint(ob, "AutoPath", CONSTRAINT_TYPE_FOLLOWPATH); data = con->data; data->tar = par; - add_constraint_to_object(con, ob); - get_constraint_target_matrix(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra - give_timeoffset(ob)); - VecSubf(vec, ob->obmat[3], cmat[3]); + sub_v3_v3v3(vec, ob->obmat[3], cmat[3]); ob->loc[0] = vec[0]; ob->loc[1] = vec[1]; @@ -637,12 +634,12 @@ static int parent_set_exec(bContext *C, wmOperator *op) ob->partype= PARSKEL; - Mat4Invert(ob->parentinv, workob.obmat); + invert_m4_m4(ob->parentinv, workob.obmat); } else { /* calculate inverse parent matrix */ what_does_parent(scene, ob, &workob); - Mat4Invert(ob->parentinv, workob.obmat); + invert_m4_m4(ob->parentinv, workob.obmat); } ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA; @@ -734,7 +731,7 @@ static int parent_noinv_set_exec(bContext *C, wmOperator *op) } else { /* clear inverse matrix and also the object location */ - Mat4One(ob->parentinv); + unit_m4(ob->parentinv); memset(ob->loc, 0, 3*sizeof(float)); /* set recalc flags */ @@ -923,8 +920,7 @@ static int track_set_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob!=obact) { - con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO); - strcpy (con->name, "AutoTrack"); + con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_TRACKTO); data = con->data; data->tar = obact; @@ -935,8 +931,6 @@ static int track_set_exec(bContext *C, wmOperator *op) data->reserved1 = TRACK_nZ; data->reserved2 = UP_Y; } - - add_constraint_to_object(con, ob); } } CTX_DATA_END; @@ -947,8 +941,7 @@ static int track_set_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob!=obact) { - con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK); - strcpy (con->name, "AutoTrack"); + con = add_ob_constraint(ob, "AutoTrack", CONSTRAINT_TYPE_LOCKTRACK); data = con->data; data->tar = obact; @@ -959,8 +952,6 @@ static int track_set_exec(bContext *C, wmOperator *op) data->trackflag = TRACK_nZ; data->lockflag = LOCK_Y; } - - add_constraint_to_object(con, ob); } } CTX_DATA_END; diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c index 47730496296..20f3ea3df9e 100644 --- a/source/blender/editors/object/object_select.c +++ b/source/blender/editors/object/object_select.c @@ -40,7 +40,7 @@ #include "DNA_scene_types.h" #include "DNA_texture_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_rand.h" #include "BLI_string.h" @@ -524,7 +524,7 @@ static short select_grouped_color(bContext *C, Object *ob) char changed = 0; CTX_DATA_BEGIN(C, Base*, base, selectable_bases) { - if (!(base->flag & SELECT) && (FloatCompare(base->object->col, ob->col, 0.005f))) { + if (!(base->flag & SELECT) && (compare_v3v3(base->object->col, ob->col, 0.005f))) { ED_base_object_select(base, BA_SELECT); changed = 1; } diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c index f52927a1a00..878c61aac48 100644 --- a/source/blender/editors/object/object_shapekey.c +++ b/source/blender/editors/object/object_shapekey.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_action_types.h" #include "DNA_curve_types.h" diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 0c09e0a03de..48db13c0709 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -38,7 +38,7 @@ #include "DNA_screen_types.h" #include "DNA_view3d_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_listbase.h" @@ -159,10 +159,10 @@ static int object_rotation_clear_exec(bContext *C, wmOperator *op) if (ob->rotmode == ROT_MODE_QUAT) { QUATCOPY(quat1, ob->quat); - QuatToEul(ob->quat, oldeul); + quat_to_eul( oldeul,ob->quat); } else if (ob->rotmode == ROT_MODE_AXISANGLE) { - AxisAngleToEulO(ob->rotAxis, ob->rotAngle, oldeul, EULER_ORDER_DEFAULT); + axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,ob->rotAxis, ob->rotAngle); } else { VECCOPY(oldeul, ob->rot); @@ -178,14 +178,14 @@ static int object_rotation_clear_exec(bContext *C, wmOperator *op) eul[2]= oldeul[2]; if (ob->rotmode == ROT_MODE_QUAT) { - EulToQuat(eul, ob->quat); + eul_to_quat( ob->quat,eul); /* quaternions flip w sign to accumulate rotations correctly */ if ((quat1[0]<0.0f && ob->quat[0]>0.0f) || (quat1[0]>0.0f && ob->quat[0]<0.0f)) { - QuatMulf(ob->quat, -1.0f); + mul_qt_fl(ob->quat, -1.0f); } } else if (ob->rotmode == ROT_MODE_AXISANGLE) { - EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, ob->rotAxis, &ob->rotAngle); + eulO_to_axis_angle( ob->rotAxis, &ob->rotAngle,eul, EULER_ORDER_DEFAULT); } else { VECCOPY(ob->rot, eul); @@ -290,12 +290,12 @@ static int object_origin_clear_exec(bContext *C, wmOperator *op) v1= ob->loc; v3= ob->parentinv[3]; - Mat3CpyMat4(mat, ob->parentinv); + copy_m3_m4(mat, ob->parentinv); VECCOPY(v3, v1); v3[0]= -v3[0]; v3[1]= -v3[1]; v3[2]= -v3[2]; - Mat3MulVecfl(mat, v3); + mul_m3_v3(mat, v3); } ob->recalc |= OB_RECALC_OB; } @@ -338,7 +338,7 @@ static void ignore_parent_tx(Main *bmain, Scene *scene, Object *ob ) if(ob_child->parent == ob) { ED_object_apply_obmat(ob_child); what_does_parent(scene, ob_child, &workob); - Mat4Invert(ob_child->parentinv, workob.obmat); + invert_m4_m4(ob_child->parentinv, workob.obmat); } } } @@ -402,20 +402,20 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo else if(apply_rot) object_rot_to_mat3(ob, rsmat); else - Mat3One(rsmat); + unit_m3(rsmat); - Mat4CpyMat3(mat, rsmat); + copy_m4_m3(mat, rsmat); /* calculate translation */ if(apply_loc) { - VecCopyf(mat[3], ob->loc); + copy_v3_v3(mat[3], ob->loc); if(!(apply_scale && apply_rot)) { /* correct for scale and rotation that is still applied */ object_to_mat3(ob, obmat); - Mat3Inv(iobmat, obmat); - Mat3MulMat3(tmat, rsmat, iobmat); - Mat3MulVecfl(tmat, mat[3]); + invert_m3_m3(iobmat, obmat); + mul_m3_m3m3(tmat, rsmat, iobmat); + mul_m3_v3(tmat, mat[3]); } } @@ -426,7 +426,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo /* adjust data */ mvert= me->mvert; for(a=0; a<me->totvert; a++, mvert++) - Mat4MulVecfl(mat, mvert->co); + mul_m4_v3(mat, mvert->co); if(me->key) { KeyBlock *kb; @@ -435,7 +435,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo float *fp= kb->data; for(a=0; a<kb->totelem; a++, fp+=3) - Mat4MulVecfl(mat, fp); + mul_m4_v3(mat, fp); } } @@ -448,15 +448,15 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo else if(ELEM(ob->type, OB_CURVE, OB_SURF)) { cu= ob->data; - scale = Mat3ToScalef(rsmat); + scale = mat3_to_scale(rsmat); for(nu=cu->nurb.first; nu; nu=nu->next) { if(nu->type == CU_BEZIER) { a= nu->pntsu; for(bezt= nu->bezt; a--; bezt++) { - Mat4MulVecfl(mat, bezt->vec[0]); - Mat4MulVecfl(mat, bezt->vec[1]); - Mat4MulVecfl(mat, bezt->vec[2]); + mul_m4_v3(mat, bezt->vec[0]); + mul_m4_v3(mat, bezt->vec[1]); + mul_m4_v3(mat, bezt->vec[2]); bezt->radius *= scale; bezt++; } @@ -464,7 +464,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo else { a= nu->pntsu*nu->pntsv; for(bp= nu->bp; a--; bp++) - Mat4MulVecfl(mat, bp->vec); + mul_m4_v3(mat, bp->vec); } } } @@ -503,8 +503,8 @@ static int visual_transform_apply_exec(bContext *C, wmOperator *op) where_is_object(scene, ob); VECCOPY(ob->loc, ob->obmat[3]); - Mat4ToSize(ob->obmat, ob->size); - Mat4ToEul(ob->obmat, ob->rot); + mat4_to_size( ob->size,ob->obmat); + mat4_to_eul( ob->rot,ob->obmat); where_is_object(scene, ob); @@ -709,7 +709,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) } if(v3d->around==V3D_CENTROID) { - VecMulf(cent, 1.0f/(float)total); + mul_v3_fl(cent, 1.0f/(float)total); } else { cent[0]= (min[0]+max[0])/2.0f; @@ -718,7 +718,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) } for(eve= em->verts.first; eve; eve= eve->next) { - VecSubf(eve->co, eve->co, cent); + sub_v3_v3v3(eve->co, eve->co, cent); } recalc_editnormals(em); @@ -748,8 +748,8 @@ static int object_center_set_exec(bContext *C, wmOperator *op) } else { if(centermode==2) { VECCOPY(cent, give_cursor(scene, v3d)); - Mat4Invert(ob->imat, ob->obmat); - Mat4MulVecfl(ob->imat, cent); + invert_m4_m4(ob->imat, ob->obmat); + mul_m4_v3(ob->imat, cent); } else { INIT_MINMAX(min, max); mvert= me->mvert; @@ -764,7 +764,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) mvert= me->mvert; for(a=0; a<me->totvert; a++, mvert++) { - VecSubf(mvert->co, mvert->co, cent); + sub_v3_v3v3(mvert->co, mvert->co, cent); } if (me->key) { @@ -773,7 +773,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) float *fp= kb->data; for (a=0; a<kb->totelem; a++, fp+=3) { - VecSubf(fp, fp, cent); + sub_v3_v3v3(fp, fp, cent); } } } @@ -781,10 +781,10 @@ static int object_center_set_exec(bContext *C, wmOperator *op) me->flag |= ME_ISDONE; if(centermode) { - Mat3CpyMat4(omat, ob->obmat); + copy_m3_m4(omat, ob->obmat); VECCOPY(centn, cent); - Mat3MulVecfl(omat, centn); + mul_m3_v3(omat, centn); ob->loc[0]+= centn[0]; ob->loc[1]+= centn[1]; ob->loc[2]+= centn[2]; @@ -802,9 +802,9 @@ static int object_center_set_exec(bContext *C, wmOperator *op) ob_other->flag |= OB_DONE; ob_other->recalc= OB_RECALC_OB|OB_RECALC_DATA; - Mat3CpyMat4(omat, ob_other->obmat); + copy_m3_m4(omat, ob_other->obmat); VECCOPY(centn, cent); - Mat3MulVecfl(omat, centn); + mul_m3_v3(omat, centn); ob_other->loc[0]+= centn[0]; ob_other->loc[1]+= centn[1]; ob_other->loc[2]+= centn[2]; @@ -815,7 +815,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) if(tme && (tme->flag & ME_ISDONE)==0) { mvert= tme->mvert; for(a=0; a<tme->totvert; a++, mvert++) { - VecSubf(mvert->co, mvert->co, cent); + sub_v3_v3v3(mvert->co, mvert->co, cent); } if (tme->key) { @@ -824,7 +824,7 @@ static int object_center_set_exec(bContext *C, wmOperator *op) float *fp= kb->data; for (a=0; a<kb->totelem; a++, fp+=3) { - VecSubf(fp, fp, cent); + sub_v3_v3v3(fp, fp, cent); } } } @@ -858,8 +858,8 @@ static int object_center_set_exec(bContext *C, wmOperator *op) } else { if(centermode==2) { VECCOPY(cent, give_cursor(scene, v3d)); - Mat4Invert(ob->imat, ob->obmat); - Mat4MulVecfl(ob->imat, cent); + invert_m4_m4(ob->imat, ob->obmat); + mul_m4_v3(ob->imat, cent); /* don't allow Z change if curve is 2D */ if( !( cu->flag & CU_3D ) ) @@ -884,23 +884,23 @@ static int object_center_set_exec(bContext *C, wmOperator *op) if(nu->type == CU_BEZIER) { a= nu->pntsu; while (a--) { - VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent); - VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent); - VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent); + sub_v3_v3v3(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent); + sub_v3_v3v3(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent); + sub_v3_v3v3(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent); } } else { a= nu->pntsu*nu->pntsv; while (a--) - VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent); + sub_v3_v3v3(nu->bp[a].vec, nu->bp[a].vec, cent); } nu= nu->next; } if(centermode && obedit==NULL) { - Mat3CpyMat4(omat, ob->obmat); + copy_m3_m4(omat, ob->obmat); - Mat3MulVecfl(omat, cent); + mul_m3_v3(omat, cent); ob->loc[0]+= cent[0]; ob->loc[1]+= cent[1]; ob->loc[2]+= cent[2]; diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 438150b25ac..b5007ff72ce 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -60,7 +60,7 @@ #include "BKE_utildefines.h" #include "BKE_pointcache.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_kdtree.h" @@ -587,13 +587,13 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected if(pset->selectmode==SCE_SELECT_PATH) selected= 0; - Mat4One(imat); - Mat4One(mat); + unit_m4(imat); + unit_m4(mat); LOOP_VISIBLE_POINTS { if(edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, psys->particles + p, mat); - Mat4Invert(imat,mat); + invert_m4_m4(imat,mat); } if(pset->selectmode==SCE_SELECT_END) { @@ -698,7 +698,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) key = pa->hair; psys_mat_hair_to_orco(ob, psmd->dm, psys->part->from, pa, mat); VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); BLI_kdtree_insert(tree, p, co, NULL); } @@ -712,7 +712,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys) key = pa->hair; psys_mat_hair_to_orco(ob, psmd->dm, psys->part->from, pa, mat); VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); co[0]= -co[0]; index= BLI_kdtree_find_nearest(tree, co, NULL, &nearest); @@ -785,7 +785,7 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys /* mirror positions and tags */ psys_mat_hair_to_orco(ob, dm, psys->part->from, pa, mat); psys_mat_hair_to_orco(ob, dm, psys->part->from, mpa, mmat); - Mat4Invert(immat, mmat); + invert_m4_m4(immat, mmat); hkey=pa->hair; mhkey=mpa->hair; @@ -793,9 +793,9 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys mkey= mpoint->keys; for(k=0; k<pa->totkey; k++, hkey++, mhkey++, key++, mkey++) { VECCOPY(mhkey->co, hkey->co); - Mat4MulVecfl(mat, mhkey->co); + mul_m4_v3(mat, mhkey->co); mhkey->co[0]= -mhkey->co[0]; - Mat4MulVecfl(immat, mhkey->co); + mul_m4_v3(immat, mhkey->co); if(key->flag & PEK_TAG) mkey->flag |= PEK_TAG; @@ -867,12 +867,12 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, psys->particles + p, hairmat); LOOP_KEYS { - Mat4MulVecfl(hairmat, key->co); + mul_m4_v3(hairmat, key->co); } LOOP_KEYS { if(k==0) { - dist_1st = VecLenf((key+1)->co, key->co); + dist_1st = len_v3v3((key+1)->co, key->co); dist_1st *= 0.75f * pset->emitterdist; } else { @@ -881,32 +881,32 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) vec=edit->emitter_cosnos +index*6; nor=vec+3; - VecSubf(dvec, key->co, vec); + sub_v3_v3v3(dvec, key->co, vec); - dot=Inpf(dvec,nor); + dot=dot_v3v3(dvec,nor); VECCOPY(dvec,nor); if(dot>0.0f) { if(dot<dist_1st) { - Normalize(dvec); - VecMulf(dvec,dist_1st-dot); - VecAddf(key->co,key->co,dvec); + normalize_v3(dvec); + mul_v3_fl(dvec,dist_1st-dot); + add_v3_v3v3(key->co,key->co,dvec); } } else { - Normalize(dvec); - VecMulf(dvec,dist_1st-dot); - VecAddf(key->co,key->co,dvec); + normalize_v3(dvec); + mul_v3_fl(dvec,dist_1st-dot); + add_v3_v3v3(key->co,key->co,dvec); } if(k==1) dist_1st*=1.3333f; } } - Mat4Invert(hairimat,hairmat); + invert_m4_m4(hairimat,hairmat); LOOP_KEYS { - Mat4MulVecfl(hairimat, key->co); + mul_m4_v3(hairimat, key->co); } } } @@ -927,10 +927,10 @@ void PE_apply_lengths(Scene *scene, PTCacheEdit *edit) LOOP_EDITED_POINTS { LOOP_KEYS { if(k) { - VecSubf(dv1, key->co, (key - 1)->co); - Normalize(dv1); - VecMulf(dv1, (key - 1)->length); - VecAddf(key->co, (key - 1)->co, dv1); + sub_v3_v3v3(dv1, key->co, (key - 1)->co); + normalize_v3(dv1); + mul_v3_fl(dv1, (key - 1)->length); + add_v3_v3v3(key->co, (key - 1)->co, dv1); } } } @@ -970,19 +970,19 @@ static void pe_iterate_lengths(Scene *scene, PTCacheEdit *edit) for(; k<point->totkey; k++, key++) { if(k) { - VecSubf(dv0, (key - 1)->co, key->co); - tlen= Normalize(dv0); - VecMulf(dv0, (mul * (tlen - (key - 1)->length))); + sub_v3_v3v3(dv0, (key - 1)->co, key->co); + tlen= normalize_v3(dv0); + mul_v3_fl(dv0, (mul * (tlen - (key - 1)->length))); } if(k < point->totkey - 1) { - VecSubf(dv2, (key + 1)->co, key->co); - tlen= Normalize(dv2); - VecMulf(dv2, mul * (tlen - key->length)); + sub_v3_v3v3(dv2, (key + 1)->co, key->co); + tlen= normalize_v3(dv2); + mul_v3_fl(dv2, mul * (tlen - key->length)); } if(k) { - VecAddf((key-1)->co,(key-1)->co,dv1); + add_v3_v3v3((key-1)->co,(key-1)->co,dv1); } VECADD(dv1,dv0,dv2); @@ -1001,7 +1001,7 @@ static void recalc_lengths(PTCacheEdit *edit) LOOP_EDITED_POINTS { key= point->keys; for(k=0; k<point->totkey-1; k++, key++) { - key->length= VecLenf(key->co, (key + 1)->co); + key->length= len_v3v3(key->co, (key + 1)->co); } } } @@ -1055,12 +1055,12 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys) VECADD(vec,vec,mvert->co); VECADD(nor,nor,mvert->no); - VecMulf(vec,0.25); + mul_v3_fl(vec,0.25); } else - VecMulf(vec,0.3333f); + mul_v3_fl(vec,0.3333f); - Normalize(nor); + normalize_v3(nor); BLI_kdtree_insert(edit->emitter_field, i, vec, NULL); } @@ -1114,7 +1114,7 @@ static void update_world_cos(Object *ob, PTCacheEdit *edit) LOOP_KEYS { VECCOPY(key->world_co,key->co); if(!(psys->flag & PSYS_GLOBAL_HAIR)) - Mat4MulVecfl(hairmat, key->world_co); + mul_m4_v3(hairmat, key->world_co); } } } @@ -1142,7 +1142,7 @@ static void update_velocities(Object *ob, PTCacheEdit *edit) if(point->totkey>2) { VECSUB(vec1, (key+1)->co, (key+2)->co); - Projf(vec2, vec1, key->vel); + project_v3_v3v3(vec2, vec1, key->vel); VECSUB(vec2, vec1, vec2); VECADDFAC(key->vel, key->vel, vec2, 0.5f); } @@ -1157,7 +1157,7 @@ static void update_velocities(Object *ob, PTCacheEdit *edit) if(point->totkey>2) { VECSUB(vec1, (key-2)->co, (key-1)->co); - Projf(vec2, vec1, key->vel); + project_v3_v3v3(vec2, vec1, key->vel); VECSUB(vec2, vec1, vec2); VECADDFAC(key->vel, key->vel, vec2, 0.5f); } @@ -1170,7 +1170,7 @@ static void update_velocities(Object *ob, PTCacheEdit *edit) VECSUB(key->vel, (key+1)->co, (key-1)->co); } - VecMulf(key->vel, frs_sec/dfra); + mul_v3_fl(key->vel, frs_sec/dfra); } } } @@ -1347,6 +1347,7 @@ int PE_mouse_particles(bContext *C, short *mval, int extend) static void select_root(PEData *data, int point_index) { data->edit->points[point_index].keys->flag |= PEK_SELECT; + data->edit->points[point_index].flag |= PEP_EDIT_RECALC; /* redraw selection only */ } static int select_first_exec(bContext *C, wmOperator *op) @@ -1355,6 +1356,8 @@ static int select_first_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); foreach_point(&data, select_root); + + PE_update_selection(data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_SELECT, data.ob); return OPERATOR_FINISHED; @@ -1380,6 +1383,7 @@ static void select_tip(PEData *data, int point_index) { PTCacheEditPoint *point = data->edit->points + point_index; point->keys[point->totkey - 1].flag |= PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ } static int select_last_exec(bContext *C, wmOperator *op) @@ -1388,6 +1392,8 @@ static int select_last_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); foreach_point(&data, select_tip); + + PE_update_selection(data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_SELECT, data.ob); return OPERATOR_FINISHED; @@ -1531,7 +1537,7 @@ int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select) if(!PE_start_edit(edit)) return OPERATOR_CANCELLED; - Mat4One(mat); + unit_m4(mat); LOOP_VISIBLE_POINTS { if(edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR)) @@ -1540,7 +1546,7 @@ int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select) if(pset->selectmode==SCE_SELECT_POINT) { LOOP_KEYS { VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); project_short(ar, co, vertco); if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1])) { if(select && !(key->flag & PEK_SELECT)) { @@ -1558,7 +1564,7 @@ int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select) key= point->keys + point->totkey - 1; VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); project_short(ar, co,vertco); if((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1])) { if(select && !(key->flag & PEK_SELECT)) { @@ -1693,8 +1699,10 @@ static void select_less_keys(PEData *data, int point_index) } LOOP_KEYS { - if(key->flag&PEK_TAG) + if(key->flag&PEK_TAG) { key->flag &= ~(PEK_TAG|PEK_SELECT); + point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ + } } } @@ -1704,6 +1712,8 @@ static int select_less_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); foreach_point(&data, select_less_keys); + + PE_update_selection(data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_SELECT, data.ob); return OPERATOR_FINISHED; @@ -1752,6 +1762,7 @@ static void select_more_keys(PEData *data, int point_index) if(key->flag&PEK_TAG) { key->flag &= ~PEK_TAG; key->flag |= PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ } } } @@ -1762,6 +1773,8 @@ static int select_more_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); foreach_point(&data, select_more_keys); + + PE_update_selection(data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_SELECT, data.ob); return OPERATOR_FINISHED; @@ -1781,6 +1794,43 @@ void PARTICLE_OT_select_more(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +static int select_inverse_exec(bContext *C, wmOperator *op) +{ + PEData data; + PTCacheEdit *edit; + POINT_P; KEY_K; + + PE_set_data(C, &data); + + edit= PE_get_current(data.scene, data.ob); + + LOOP_VISIBLE_POINTS { + LOOP_KEYS { + key->flag ^= PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; /* redraw selection only */ + } + } + + PE_update_selection(data.scene, data.ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_SELECT, data.ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_select_inverse(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select Inverse"; + ot->idname= "PARTICLE_OT_select_inverse"; + + /* api callbacks */ + ot->exec= select_inverse_exec; + ot->poll= PE_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /************************ rekey operator ************************/ static void rekey_particle(PEData *data, int pa_index) @@ -2205,7 +2255,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) LOOP_SELECTED_POINTS { psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, psys->particles+p, mat); VECCOPY(co, point->keys->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); BLI_kdtree_insert(tree, p, co, NULL); } @@ -2215,7 +2265,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op) LOOP_SELECTED_POINTS { psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, psys->particles+p, mat); VECCOPY(co, point->keys->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); totn= BLI_kdtree_find_n_nearest(tree,10,co,NULL,nearest); @@ -2686,8 +2736,8 @@ static void brush_comb(PEData *data, float mat[][4], float imat[][4], int point_ fac= (float)pow((double)(1.0f - data->dist / data->rad), (double)data->combfac); VECCOPY(cvec,data->dvec); - Mat4Mul3Vecfl(imat,cvec); - VecMulf(cvec, fac); + mul_mat3_m4_v3(imat,cvec); + mul_v3_fl(cvec, fac); VECADD(key->co, key->co, cvec); (data->edit->points + point_index)->flag |= PEP_EDIT_RECALC; @@ -2804,7 +2854,7 @@ static void brush_length(PEData *data, int point_index) else { VECSUB(dvec,key->co,pvec); VECCOPY(pvec,key->co); - VecMulf(dvec,data->growfac); + mul_v3_fl(dvec,data->growfac); VECADD(key->co,(key-1)->co,dvec); } } @@ -2823,25 +2873,25 @@ static void brush_puff(PEData *data, int point_index) if(psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global(data->ob, data->dm, psys->part->from, psys->particles + point_index, mat); - Mat4Invert(imat,mat); + invert_m4_m4(imat,mat); } else { - Mat4One(mat); - Mat4One(imat); + unit_m4(mat); + unit_m4(imat); } LOOP_KEYS { if(k==0) { /* find root coordinate and normal on emitter */ VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); point_index= BLI_kdtree_find_nearest(edit->emitter_field, co, NULL, NULL); if(point_index == -1) return; VECCOPY(rootco, co); - VecCopyf(nor, &edit->emitter_cosnos[point_index*6+3]); - Normalize(nor); + copy_v3_v3(nor, &edit->emitter_cosnos[point_index*6+3]); + normalize_v3(nor); length= 0.0f; fac= (float)pow((double)(1.0f - data->dist / data->rad), (double)data->pufffac); @@ -2853,8 +2903,8 @@ static void brush_puff(PEData *data, int point_index) /* compute position as if hair was standing up straight */ VECCOPY(lastco, co); VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); - length += VecLenf(lastco, co); + mul_m4_v3(mat, co); + length += len_v3v3(lastco, co); VECADDFAC(kco, rootco, nor, length); @@ -2863,7 +2913,7 @@ static void brush_puff(PEData *data, int point_index) VECADDFAC(co, co, dco, fac); VECCOPY(key->co, co); - Mat4MulVecfl(imat, key->co); + mul_m4_v3(imat, key->co); } } @@ -2875,8 +2925,8 @@ static void brush_smooth_get(PEData *data, float mat[][4], float imat[][4], int if(key_index) { float dvec[3]; - VecSubf(dvec,key->co,(key-1)->co); - Mat4Mul3Vecfl(mat,dvec); + sub_v3_v3v3(dvec,key->co,(key-1)->co); + mul_mat3_m4_v3(mat,dvec); VECADD(data->vec,data->vec,dvec); data->tot++; } @@ -2888,12 +2938,12 @@ static void brush_smooth_do(PEData *data, float mat[][4], float imat[][4], int p if(key_index) { VECCOPY(vec,data->vec); - Mat4Mul3Vecfl(imat,vec); + mul_mat3_m4_v3(imat,vec); - VecSubf(dvec,key->co,(key-1)->co); + sub_v3_v3v3(dvec,key->co,(key-1)->co); VECSUB(dvec,vec,dvec); - VecMulf(dvec,data->smoothfac); + mul_v3_fl(dvec,data->smoothfac); VECADD(key->co,key->co,dvec); } @@ -2919,7 +2969,7 @@ static int brush_add(PEData *data, short number) short size= pset->brush[PE_BRUSH_ADD].size; short size2= size*size; DerivedMesh *dm=0; - Mat4Invert(imat,ob->obmat); + invert_m4_m4(imat,ob->obmat); if(psys->flag & PSYS_GLOBAL_HAIR) return 0; @@ -2945,8 +2995,8 @@ static int brush_add(PEData *data, short number) mco[1]= data->mval[1] + dmy; viewline(data->vc.ar, data->vc.v3d, mco, co1, co2); - Mat4MulVecfl(imat,co1); - Mat4MulVecfl(imat,co2); + mul_m4_v3(imat,co1); + mul_m4_v3(imat,co2); min_d=2.0; /* warning, returns the derived mesh face */ @@ -3052,18 +3102,18 @@ static int brush_add(PEData *data, short number) key[0].time= hkey->time/ 100.0f; psys_get_particle_on_path(&sim, ptn[0].index, key, 0); - VecMulf(key[0].co, weight[0]); + mul_v3_fl(key[0].co, weight[0]); if(maxw>1) { key[1].time= key[0].time; psys_get_particle_on_path(&sim, ptn[1].index, key + 1, 0); - VecMulf(key[1].co, weight[1]); + mul_v3_fl(key[1].co, weight[1]); VECADD(key[0].co, key[0].co, key[1].co); if(maxw>2) { key[2].time= key[0].time; psys_get_particle_on_path(&sim, ptn[2].index, key + 2, 0); - VecMulf(key[2].co, weight[2]); + mul_v3_fl(key[2].co, weight[2]); VECADD(key[0].co, key[0].co, key[2].co); } } @@ -3084,8 +3134,8 @@ static int brush_add(PEData *data, short number) } for(k=0, hkey=pa->hair; k<pset->totaddkey; k++, hkey++) { psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); - Mat4Invert(imat,hairmat); - Mat4MulVecfl(imat, hkey->co); + invert_m4_m4(imat,hairmat); + mul_m4_v3(imat, hkey->co); } } @@ -3200,7 +3250,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) else data.combfac= 1.0f - data.combfac; - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); window_to_3d_delta(ar, vec, dx, dy); data.dvec= vec; @@ -3270,7 +3320,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.pufffac= 1.0f - data.pufffac; data.invert= (brush->invert ^ flip); - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); foreach_mouse_hit_point(&data, brush_puff, selected); } @@ -3306,12 +3356,12 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) data.smoothfac= (float)(brush->strength / 100.0f); - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); foreach_mouse_hit_key(&data, brush_smooth_get, selected); if(data.tot) { - VecMulf(data.vec, 1.0f / (float)data.tot); + mul_v3_fl(data.vec, 1.0f / (float)data.tot); foreach_mouse_hit_key(&data, brush_smooth_do, selected); } @@ -3734,7 +3784,7 @@ int PE_minmax(Scene *scene, float *min, float *max) if(psys) psmd= psys_get_modifier(ob, psys); else - Mat4One(mat); + unit_m4(mat); LOOP_VISIBLE_POINTS { if(psys) @@ -3742,7 +3792,7 @@ int PE_minmax(Scene *scene, float *min, float *max) LOOP_SELECTED_KEYS { VECCOPY(co, key->co); - Mat4MulVecfl(mat, co); + mul_m4_v3(mat, co); DO_MINMAX(co, min, max); ok= 1; } diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index d763c0500d2..1ef3ffa6c34 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -37,7 +37,7 @@ #include "DNA_scene_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" #include "BKE_context.h" @@ -548,7 +548,7 @@ static void disconnect_hair(Scene *scene, Object *ob, ParticleSystem *psys) psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); for(k=0,key=pa->hair; k<pa->totkey; k++,key++) { - Mat4MulVecfl(hairmat,key->co); + mul_m4_v3(hairmat,key->co); if(ekey) { ekey->flag &= ~PEK_USE_WCO; @@ -638,7 +638,7 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) /* convert to global coordinates */ for (i=0; i<numverts; i++) - Mat4MulVecfl (ob->obmat, CDDM_get_vert(dm, i)->co); + mul_m4_v3(ob->obmat, CDDM_get_vert(dm, i)->co); bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6); @@ -657,21 +657,21 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) mface = CDDM_get_face(dm,nearest.index); - VecCopyf(v[0], CDDM_get_vert(dm,mface->v1)->co); - VecCopyf(v[1], CDDM_get_vert(dm,mface->v2)->co); - VecCopyf(v[2], CDDM_get_vert(dm,mface->v3)->co); + copy_v3_v3(v[0], CDDM_get_vert(dm,mface->v1)->co); + copy_v3_v3(v[1], CDDM_get_vert(dm,mface->v2)->co); + copy_v3_v3(v[2], CDDM_get_vert(dm,mface->v3)->co); if(mface->v4) { - VecCopyf(v[3], CDDM_get_vert(dm,mface->v4)->co); - MeanValueWeights(v, 4, nearest.co, pa->fuv); + copy_v3_v3(v[3], CDDM_get_vert(dm,mface->v4)->co); + interp_weights_poly_v3( pa->fuv,v, 4, nearest.co); } else - MeanValueWeights(v, 3, nearest.co, pa->fuv); + interp_weights_poly_v3( pa->fuv,v, 3, nearest.co); pa->num = nearest.index; pa->num_dmcache = psys_particle_dm_face_lookup(ob,psmd->dm,pa->num,pa->fuv,NULL); psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); - Mat4Invert(imat,hairmat); + invert_m4_m4(imat,hairmat); VECSUB(vec, nearest.co, key->co); @@ -682,7 +682,7 @@ static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) for(k=0,key=pa->hair; k<pa->totkey; k++,key++) { VECADD(key->co, key->co, vec); - Mat4MulVecfl(imat,key->co); + mul_m4_v3(imat,key->co); if(ekey) { ekey->flag |= PEK_USE_WCO; diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index b72c4991094..e5d553dacc7 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -62,7 +62,7 @@ #include "BLI_blenlib.h" #include "BLI_threads.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_blender.h" #include "BKE_context.h" @@ -839,8 +839,8 @@ int fluidsimBake(bContext *C, ReportList *reports, Object *ob) } // init trafo matrix - Mat4CpyMat4(domainMat, fsDomain->obmat); - if(!Mat4Invert(invDomMat, domainMat)) { + copy_m4_m4(domainMat, fsDomain->obmat); + if(!invert_m4_m4(invDomMat, domainMat)) { snprintf(debugStrBuffer,256,"fluidsimBake::error - Invalid obj matrix?\n"); elbeemDebugOut(debugStrBuffer); BKE_report(reports, RPT_ERROR, "Invalid object matrix."); diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h index babaaefe155..e8169adc8dc 100644 --- a/source/blender/editors/physics/physics_intern.h +++ b/source/blender/editors/physics/physics_intern.h @@ -42,6 +42,7 @@ void PARTICLE_OT_select_last(struct wmOperatorType *ot); void PARTICLE_OT_select_linked(struct wmOperatorType *ot); void PARTICLE_OT_select_less(struct wmOperatorType *ot); void PARTICLE_OT_select_more(struct wmOperatorType *ot); +void PARTICLE_OT_select_inverse(struct wmOperatorType *ot); void PARTICLE_OT_hide(struct wmOperatorType *ot); void PARTICLE_OT_reveal(struct wmOperatorType *ot); diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c index 8fb91a6c296..1b9ebf27edc 100644 --- a/source/blender/editors/physics/physics_ops.c +++ b/source/blender/editors/physics/physics_ops.c @@ -49,6 +49,7 @@ static void operatortypes_particle(void) WM_operatortype_append(PARTICLE_OT_select_linked); WM_operatortype_append(PARTICLE_OT_select_less); WM_operatortype_append(PARTICLE_OT_select_more); + WM_operatortype_append(PARTICLE_OT_select_inverse); WM_operatortype_append(PARTICLE_OT_hide); WM_operatortype_append(PARTICLE_OT_reveal); @@ -98,6 +99,7 @@ static void keymap_particle(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0); RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 92380a56d3d..74e1cca5579 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -42,7 +42,7 @@ #include "BLO_readfile.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_threads.h" diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index a9023194271..59b220dec63 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -52,7 +52,7 @@ #include "BKE_utildefines.h" #include "BKE_world.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_listbase.h" diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index be76e153fae..0f22b3041fb 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -35,7 +35,7 @@ #include "DNA_userdef_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_context.h" diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 1445c6b5cf8..742fab07bcc 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -37,7 +37,7 @@ #include "BKE_utildefines.h" #include "BKE_colortools.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_threads.h" #include "BIF_gl.h" diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c index 919cc3f0cfd..1672f8f3325 100644 --- a/source/blender/editors/screen/screen_context.c +++ b/source/blender/editors/screen/screen_context.c @@ -67,7 +67,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult "visible_pchans", "selected_pchans", "active_bone", "active_pchan", "active_base", "active_object", "edit_object", "sculpt_object", "vertex_paint_object", "weight_paint_object", - "texture_paint_object", "brush", "particle_edit_object", NULL}; + "texture_paint_object", "particle_edit_object", NULL}; CTX_data_dir_set(result, dir); return 1; @@ -84,7 +84,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if(selected_objects) CTX_data_id_list_add(result, &base->object->id); else - CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base); + CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); } } @@ -100,7 +100,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if(selected_editable_objects) CTX_data_id_list_add(result, &base->object->id); else - CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base); + CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); } } } @@ -131,18 +131,18 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if (editable_bones) { /* only selected + editable */ if (EBONE_EDITABLE(ebone)) { - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); } } else { /* only include bones if visible */ - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); if ((flipbone) && EBONE_VISIBLE(arm, flipbone)==0) - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); } } } @@ -173,18 +173,18 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult if (selected_editable_bones) { /* only selected + editable */ if (EBONE_EDITABLE(ebone)) { - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); } } else { /* only include bones if selected */ - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, ebone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) - CTX_data_list_add(result, &arm->id, &RNA_UnknownType, flipbone); + CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); } } } @@ -215,7 +215,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult for (pchan= obact->pose->chanbase.first; pchan; pchan= pchan->next) { /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) { - if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) + if (pchan->bone->flag & BONE_SELECTED || pchan->bone == arm->act_bone) CTX_data_list_add(result, &obact->id, &RNA_PoseChannel, pchan); } } @@ -224,21 +224,21 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } } else if(CTX_data_equals(member, "active_bone")) { - bArmature *arm= (obedit) ? obedit->data : NULL; - EditBone *ebone; - - if (arm && arm->edbo) { - for (ebone= arm->edbo->first; ebone; ebone= ebone->next) { - if (EBONE_VISIBLE(arm, ebone)) { - if (ebone->flag & BONE_ACTIVE) { - CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, ebone); - - return 1; - } + if(obact && obact->type == OB_ARMATURE) { + bArmature *arm= obact->data; + if(arm->edbo) { + if(arm->act_edbone) { + CTX_data_pointer_set(result, &arm->id, &RNA_EditBone, arm->act_edbone); + return 1; + } + } + else { + if(arm->act_bone) { + CTX_data_pointer_set(result, &arm->id, &RNA_Bone, arm->act_bone); + return 1; } } } - } else if(CTX_data_equals(member, "active_pchan")) { bPoseChannel *pchan; @@ -251,7 +251,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult } else if(CTX_data_equals(member, "active_base")) { if(base) - CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, base); + CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, base); return 1; } @@ -304,7 +304,10 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult return 1; } + else { + return 0; /* not found */ + } - return 0; + return -1; /* found but not available */ } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index a1537b2ddf5..0df7b326834 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -31,7 +31,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_dlrbTree.h" @@ -400,7 +400,7 @@ AZone *is_in_area_actionzone(ScrArea *sa, int x, int y) for(az= sa->actionzones.first; az; az= az->next) { if(BLI_in_rcti(&az->rect, x, y)) { if(az->type == AZONE_AREA) { - if(IsPointInTri2DInts(az->x1, az->y1, az->x2, az->y2, x, y)) + if(isect_point_tri_v2_int(az->x1, az->y1, az->x2, az->y2, x, y)) break; } else if(az->type == AZONE_REGION) { @@ -2232,7 +2232,7 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event) ScreenAnimData *sad= wt->customdata; ScrArea *sa; int sync; - + /* sync, don't sync, or follow scene setting */ if(sad->flag & ANIMPLAY_FLAG_SYNC) sync= 1; else if(sad->flag & ANIMPLAY_FLAG_NO_SYNC) sync= 0; @@ -2288,12 +2288,12 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event) } } } - + /* since we follow drawflags, we can't send notifier but tag regions ourselves */ ED_update_for_newframe(C, 1); - + sound_update_playing(C); - + for(sa= screen->areabase.first; sa; sa= sa->next) { ARegion *ar; for(ar= sa->regionbase.first; ar; ar= ar->next) { @@ -2305,6 +2305,12 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event) } } + /* recalculate the timestep for the timer now that we've finished calculating this, + * since the frames-per-second value may have been changed + */ + // TODO: this may make evaluation a bit slower if the value doesn't change... any way to avoid this? + wt->timestep= (1.0/FPS); + //WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); return OPERATOR_FINISHED; @@ -2672,7 +2678,7 @@ static int screen_render_exec(bContext *C, wmOperator *op) RE_test_break_cb(re, NULL, (int (*)(void *)) blender_test_break); if(RNA_boolean_get(op->ptr, "animation")) - RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->frame_step); + RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->r.frame_step); else RE_BlenderFrame(re, scene, scene->r.cfra); @@ -2892,7 +2898,7 @@ static void render_startjob(void *rjv, short *stop, short *do_update) rj->do_update= do_update; if(rj->anim) - RE_BlenderAnim(rj->re, rj->scene, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->frame_step); + RE_BlenderAnim(rj->re, rj->scene, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step); else RE_BlenderFrame(rj->re, rj->scene, rj->scene->r.cfra); } @@ -3245,7 +3251,7 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even printf("\n"); /* go to next frame */ - oglrender->nfra += scene->frame_step; + oglrender->nfra += scene->r.frame_step; scene->r.cfra++; WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 929f854242f..ef036da6d7b 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -40,7 +40,7 @@ #ifdef WIN32 #include "BLI_winstuff.h" #endif -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" #include "BLI_linklist.h" @@ -669,7 +669,7 @@ static int project_paint_PickFace(const ProjPaintState *ps, float pt[2], float w v2= ps->screenCoords[mf->v2]; v3= ps->screenCoords[mf->v3]; - if (IsectPT2Df(pt, v1, v2, v3)) { + if (isect_point_tri_v2(pt, v1, v2, v3)) { if (ps->is_ortho) z_depth= VecZDepthOrtho(pt, v1, v2, v3, w_tmp); else z_depth= VecZDepthPersp(pt, v1, v2, v3, w_tmp); @@ -683,7 +683,7 @@ static int project_paint_PickFace(const ProjPaintState *ps, float pt[2], float w else if (mf->v4) { v4= ps->screenCoords[mf->v4]; - if (IsectPT2Df(pt, v1, v3, v4)) { + if (isect_point_tri_v2(pt, v1, v3, v4)) { if (ps->is_ortho) z_depth= VecZDepthOrtho(pt, v1, v3, v4, w_tmp); else z_depth= VecZDepthPersp(pt, v1, v3, v4, w_tmp); @@ -734,10 +734,10 @@ static int project_paint_PickColor(const ProjPaintState *ps, float pt[2], float tf = ps->dm_mtface + face_index; if (side == 0) { - Vec2Lerp3f(uv, tf->uv[0], tf->uv[1], tf->uv[2], w); + interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[1], tf->uv[2], w); } else { /* QUAD */ - Vec2Lerp3f(uv, tf->uv[0], tf->uv[2], tf->uv[3], w); + interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[2], tf->uv[3], w); } ibuf = tf->tpage->ibufs.first; /* we must have got the imbuf before getting here */ @@ -818,7 +818,7 @@ static int project_paint_occlude_ptv(float pt[3], float v1[3], float v2[3], floa return 0; /* do a 2D point in try intersection */ - if (!IsectPT2Df(pt, v1, v2, v3)) + if (!isect_point_tri_v2(pt, v1, v2, v3)) return 0; /* we know there is */ @@ -858,10 +858,10 @@ static int project_paint_occlude_ptv_clip( } /* Test if we're in the clipped area, */ - if (side) VecLerp3f(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w); - else VecLerp3f(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w); + if (side) interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w); + else interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w); - Mat4MulVecfl(ps->ob->obmat, wco); + mul_m4_v3(ps->ob->obmat, wco); if(!view3d_test_clipping(ps->rv3d, wco)) { return 1; } @@ -1162,51 +1162,51 @@ static void uv_image_outset(float (*orig_uv)[2], float (*outset_uv)[2], const fl } /* face edge directions */ - Vec2Subf(dir1, puv[1], puv[0]); - Vec2Subf(dir2, puv[2], puv[1]); - Normalize2(dir1); - Normalize2(dir2); + sub_v2_v2v2(dir1, puv[1], puv[0]); + sub_v2_v2v2(dir2, puv[2], puv[1]); + normalize_v2(dir1); + normalize_v2(dir2); if (is_quad) { - Vec2Subf(dir3, puv[3], puv[2]); - Vec2Subf(dir4, puv[0], puv[3]); - Normalize2(dir3); - Normalize2(dir4); + sub_v2_v2v2(dir3, puv[3], puv[2]); + sub_v2_v2v2(dir4, puv[0], puv[3]); + normalize_v2(dir3); + normalize_v2(dir4); } else { - Vec2Subf(dir3, puv[0], puv[2]); - Normalize2(dir3); + sub_v2_v2v2(dir3, puv[0], puv[2]); + normalize_v2(dir3); } if (is_quad) { - a1 = AngleToLength(NormalizedVecAngle2_2D(dir4, dir1)); - a2 = AngleToLength(NormalizedVecAngle2_2D(dir1, dir2)); - a3 = AngleToLength(NormalizedVecAngle2_2D(dir2, dir3)); - a4 = AngleToLength(NormalizedVecAngle2_2D(dir3, dir4)); + a1 = shell_angle_to_dist(angle_normalized_v2v2(dir4, dir1)); + a2 = shell_angle_to_dist(angle_normalized_v2v2(dir1, dir2)); + a3 = shell_angle_to_dist(angle_normalized_v2v2(dir2, dir3)); + a4 = shell_angle_to_dist(angle_normalized_v2v2(dir3, dir4)); } else { - a1 = AngleToLength(NormalizedVecAngle2_2D(dir3, dir1)); - a2 = AngleToLength(NormalizedVecAngle2_2D(dir1, dir2)); - a3 = AngleToLength(NormalizedVecAngle2_2D(dir2, dir3)); + a1 = shell_angle_to_dist(angle_normalized_v2v2(dir3, dir1)); + a2 = shell_angle_to_dist(angle_normalized_v2v2(dir1, dir2)); + a3 = shell_angle_to_dist(angle_normalized_v2v2(dir2, dir3)); } if (is_quad) { - Vec2Subf(no1, dir4, dir1); - Vec2Subf(no2, dir1, dir2); - Vec2Subf(no3, dir2, dir3); - Vec2Subf(no4, dir3, dir4); - Normalize2(no1); - Normalize2(no2); - Normalize2(no3); - Normalize2(no4); - Vec2Mulf(no1, a1*scaler); - Vec2Mulf(no2, a2*scaler); - Vec2Mulf(no3, a3*scaler); - Vec2Mulf(no4, a4*scaler); - Vec2Addf(outset_uv[0], puv[0], no1); - Vec2Addf(outset_uv[1], puv[1], no2); - Vec2Addf(outset_uv[2], puv[2], no3); - Vec2Addf(outset_uv[3], puv[3], no4); + sub_v2_v2v2(no1, dir4, dir1); + sub_v2_v2v2(no2, dir1, dir2); + sub_v2_v2v2(no3, dir2, dir3); + sub_v2_v2v2(no4, dir3, dir4); + normalize_v2(no1); + normalize_v2(no2); + normalize_v2(no3); + normalize_v2(no4); + mul_v2_fl(no1, a1*scaler); + mul_v2_fl(no2, a2*scaler); + mul_v2_fl(no3, a3*scaler); + mul_v2_fl(no4, a4*scaler); + add_v2_v2v2(outset_uv[0], puv[0], no1); + add_v2_v2v2(outset_uv[1], puv[1], no2); + add_v2_v2v2(outset_uv[2], puv[2], no3); + add_v2_v2v2(outset_uv[3], puv[3], no4); outset_uv[0][0] *= ibuf_x_inv; outset_uv[0][1] *= ibuf_y_inv; @@ -1220,18 +1220,18 @@ static void uv_image_outset(float (*orig_uv)[2], float (*outset_uv)[2], const fl outset_uv[3][1] *= ibuf_y_inv; } else { - Vec2Subf(no1, dir3, dir1); - Vec2Subf(no2, dir1, dir2); - Vec2Subf(no3, dir2, dir3); - Normalize2(no1); - Normalize2(no2); - Normalize2(no3); - Vec2Mulf(no1, a1*scaler); - Vec2Mulf(no2, a2*scaler); - Vec2Mulf(no3, a3*scaler); - Vec2Addf(outset_uv[0], puv[0], no1); - Vec2Addf(outset_uv[1], puv[1], no2); - Vec2Addf(outset_uv[2], puv[2], no3); + sub_v2_v2v2(no1, dir3, dir1); + sub_v2_v2v2(no2, dir1, dir2); + sub_v2_v2v2(no3, dir2, dir3); + normalize_v2(no1); + normalize_v2(no2); + normalize_v2(no3); + mul_v2_fl(no1, a1*scaler); + mul_v2_fl(no2, a2*scaler); + mul_v2_fl(no3, a3*scaler); + add_v2_v2v2(outset_uv[0], puv[0], no1); + add_v2_v2v2(outset_uv[1], puv[1], no2); + add_v2_v2v2(outset_uv[2], puv[2], no3); outset_uv[0][0] *= ibuf_x_inv; outset_uv[0][1] *= ibuf_y_inv; @@ -1288,7 +1288,7 @@ static float lambda_cp_line2(const float p[2], const float l1[2], const float l2 h[0] = p[0] - l1[0]; h[1] = p[1] - l1[1]; - return(Inp2f(u, h)/Inp2f(u, u)); + return(dot_v2v2(u, h)/dot_v2v2(u, u)); } @@ -1304,7 +1304,7 @@ static void screen_px_from_ortho( float w[3]) { BarycentricWeights2f(uv, uv1co, uv2co, uv3co, w); - VecLerp3f(pixelScreenCo, v1co, v2co, v3co, w); + interp_v3_v3v3v3(pixelScreenCo, v1co, v2co, v3co, w); } /* same as screen_px_from_ortho except we need to take into account @@ -1338,7 +1338,7 @@ static void screen_px_from_persp( } /* done re-weighting */ - VecLerp3f(pixelScreenCo, v1co, v2co, v3co, w); + interp_v3_v3v3v3(pixelScreenCo, v1co, v2co, v3co, w); } static void project_face_pixel(const MTFace *tf_other, ImBuf *ibuf_other, const float w[3], int side, unsigned char rgba_ub[4], float rgba_f[4]) @@ -1356,7 +1356,7 @@ static void project_face_pixel(const MTFace *tf_other, ImBuf *ibuf_other, const uvCo3 = (float *)tf_other->uv[2]; } - Vec2Lerp3f(uv_other, uvCo1, uvCo2, uvCo3, w); + interp_v2_v2v2v2(uv_other, uvCo1, uvCo2, uvCo3, (float*)w); /* use */ uvco_to_wrapped_pxco(uv_other, ibuf_other->x, ibuf_other->y, &x, &y); @@ -1432,11 +1432,11 @@ float project_paint_uvpixel_mask( no[0] = w[0]*no1[0] + w[1]*no2[0] + w[2]*no3[0]; no[1] = w[0]*no1[1] + w[1]*no2[1] + w[2]*no3[1]; no[2] = w[0]*no1[2] + w[1]*no2[2] + w[2]*no3[2]; - Normalize(no); + normalize_v3(no); /* now we can use the normal as a mask */ if (ps->is_ortho) { - angle = NormalizedVecAngle2((float *)ps->viewDir, no); + angle = angle_normalized_v3v3((float *)ps->viewDir, no); } else { /* Annoying but for the perspective view we need to get the pixels location in 3D space :/ */ @@ -1456,9 +1456,9 @@ float project_paint_uvpixel_mask( viewDirPersp[0] = (ps->viewPos[0] - (w[0]*co1[0] + w[1]*co2[0] + w[2]*co3[0])); viewDirPersp[1] = (ps->viewPos[1] - (w[0]*co1[1] + w[1]*co2[1] + w[2]*co3[1])); viewDirPersp[2] = (ps->viewPos[2] - (w[0]*co1[2] + w[1]*co2[2] + w[2]*co3[2])); - Normalize(viewDirPersp); + normalize_v3(viewDirPersp); - angle = NormalizedVecAngle2(viewDirPersp, no); + angle = angle_normalized_v3v3(viewDirPersp, no); } if (angle >= ps->normal_angle) { @@ -1578,7 +1578,7 @@ static ProjPixel *project_paint_uvpixel_init( } else { float co[2]; - Vec2Subf(co, projPixel->projCoSS, (float *)ps->cloneOffset); + sub_v2_v2v2(co, projPixel->projCoSS, (float *)ps->cloneOffset); /* no need to initialize the bucket, we're only checking buckets faces and for this * the faces are alredy initialized in project_paint_delayed_face_init(...) */ @@ -1769,20 +1769,20 @@ static void scale_quad(float insetCos[4][3], float *origCos[4], const float inse cent[1] = (origCos[0][1] + origCos[1][1] + origCos[2][1] + origCos[3][1]) / 4.0f; cent[2] = (origCos[0][2] + origCos[1][2] + origCos[2][2] + origCos[3][2]) / 4.0f; - VecSubf(insetCos[0], origCos[0], cent); - VecSubf(insetCos[1], origCos[1], cent); - VecSubf(insetCos[2], origCos[2], cent); - VecSubf(insetCos[3], origCos[3], cent); + sub_v3_v3v3(insetCos[0], origCos[0], cent); + sub_v3_v3v3(insetCos[1], origCos[1], cent); + sub_v3_v3v3(insetCos[2], origCos[2], cent); + sub_v3_v3v3(insetCos[3], origCos[3], cent); - VecMulf(insetCos[0], inset); - VecMulf(insetCos[1], inset); - VecMulf(insetCos[2], inset); - VecMulf(insetCos[3], inset); + mul_v3_fl(insetCos[0], inset); + mul_v3_fl(insetCos[1], inset); + mul_v3_fl(insetCos[2], inset); + mul_v3_fl(insetCos[3], inset); - VecAddf(insetCos[0], insetCos[0], cent); - VecAddf(insetCos[1], insetCos[1], cent); - VecAddf(insetCos[2], insetCos[2], cent); - VecAddf(insetCos[3], insetCos[3], cent); + add_v3_v3v3(insetCos[0], insetCos[0], cent); + add_v3_v3v3(insetCos[1], insetCos[1], cent); + add_v3_v3v3(insetCos[2], insetCos[2], cent); + add_v3_v3v3(insetCos[3], insetCos[3], cent); } @@ -1793,17 +1793,17 @@ static void scale_tri(float insetCos[4][3], float *origCos[4], const float inset cent[1] = (origCos[0][1] + origCos[1][1] + origCos[2][1]) / 3.0f; cent[2] = (origCos[0][2] + origCos[1][2] + origCos[2][2]) / 3.0f; - VecSubf(insetCos[0], origCos[0], cent); - VecSubf(insetCos[1], origCos[1], cent); - VecSubf(insetCos[2], origCos[2], cent); + sub_v3_v3v3(insetCos[0], origCos[0], cent); + sub_v3_v3v3(insetCos[1], origCos[1], cent); + sub_v3_v3v3(insetCos[2], origCos[2], cent); - VecMulf(insetCos[0], inset); - VecMulf(insetCos[1], inset); - VecMulf(insetCos[2], inset); + mul_v3_fl(insetCos[0], inset); + mul_v3_fl(insetCos[1], inset); + mul_v3_fl(insetCos[2], inset); - VecAddf(insetCos[0], insetCos[0], cent); - VecAddf(insetCos[1], insetCos[1], cent); - VecAddf(insetCos[2], insetCos[2], cent); + add_v3_v3v3(insetCos[0], insetCos[0], cent); + add_v3_v3v3(insetCos[1], insetCos[1], cent); + add_v3_v3v3(insetCos[2], insetCos[2], cent); } @@ -1891,22 +1891,22 @@ static void rect_to_uvspace_ortho( uv[0] = bucket_bounds->xmax; uv[1] = bucket_bounds->ymin; BarycentricWeights2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?3:0], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?3:0], uv1co, uv2co, uv3co, w); //uv[0] = bucket_bounds->xmax; // set above uv[1] = bucket_bounds->ymax; BarycentricWeights2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?2:1], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?2:1], uv1co, uv2co, uv3co, w); uv[0] = bucket_bounds->xmin; //uv[1] = bucket_bounds->ymax; // set above BarycentricWeights2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?1:2], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?1:2], uv1co, uv2co, uv3co, w); //uv[0] = bucket_bounds->xmin; // set above uv[1] = bucket_bounds->ymin; BarycentricWeights2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?0:3], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?0:3], uv1co, uv2co, uv3co, w); } /* same as above but use BarycentricWeightsPersp2f */ @@ -1925,22 +1925,22 @@ static void rect_to_uvspace_persp( uv[0] = bucket_bounds->xmax; uv[1] = bucket_bounds->ymin; BarycentricWeightsPersp2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?3:0], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?3:0], uv1co, uv2co, uv3co, w); //uv[0] = bucket_bounds->xmax; // set above uv[1] = bucket_bounds->ymax; BarycentricWeightsPersp2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?2:1], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?2:1], uv1co, uv2co, uv3co, w); uv[0] = bucket_bounds->xmin; //uv[1] = bucket_bounds->ymax; // set above BarycentricWeightsPersp2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?1:2], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?1:2], uv1co, uv2co, uv3co, w); //uv[0] = bucket_bounds->xmin; // set above uv[1] = bucket_bounds->ymin; BarycentricWeightsPersp2f(uv, v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[flip?0:3], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[flip?0:3], uv1co, uv2co, uv3co, w); } /* This works as we need it to but we can save a few steps and not use it */ @@ -1967,7 +1967,7 @@ static float angle_2d_clockwise(const float p1[2], const float p2[2], const floa /* limit must be a fraction over 1.0f */ static int IsectPT2Df_limit(float pt[2], float v1[2], float v2[2], float v3[2], float limit) { - return ((AreaF2Dfl(pt,v1,v2) + AreaF2Dfl(pt,v2,v3) + AreaF2Dfl(pt,v3,v1)) / (AreaF2Dfl(v1,v2,v3))) < limit; + return ((area_tri_v2(pt,v1,v2) + area_tri_v2(pt,v2,v3) + area_tri_v2(pt,v3,v1)) / (area_tri_v2(v1,v2,v3))) < limit; } /* Clip the face by a bucket and set the uv-space bucket_bounds_uv @@ -2184,13 +2184,13 @@ static void project_bucket_clip_face( if (is_ortho) { for(i=0; i<(*tot); i++) { BarycentricWeights2f(isectVCosSS[i], v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); } } else { for(i=0; i<(*tot); i++) { BarycentricWeightsPersp2f(isectVCosSS[i], v1coSS, v2coSS, v3coSS, w); - Vec2Lerp3f(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); + interp_v2_v2v2v2(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); } } } @@ -2445,8 +2445,8 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i /* a pitty we need to get the worldspace pixel location here */ if(ps->rv3d->rflag & RV3D_CLIPPING) { - VecLerp3f(wco, ps->dm_mvert[ (*(&mf->v1 + i1)) ].co, ps->dm_mvert[ (*(&mf->v1 + i2)) ].co, ps->dm_mvert[ (*(&mf->v1 + i3)) ].co, w); - Mat4MulVecfl(ps->ob->obmat, wco); + interp_v3_v3v3v3(wco, ps->dm_mvert[ (*(&mf->v1 + i1)) ].co, ps->dm_mvert[ (*(&mf->v1 + i2)) ].co, ps->dm_mvert[ (*(&mf->v1 + i3)) ].co, w); + mul_m4_v3(ps->ob->obmat, wco); if(view3d_test_clipping(ps->rv3d, wco)) { continue; /* Watch out that no code below this needs to run */ } @@ -2567,7 +2567,7 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i line_clip_rect2f(bucket_bounds, vCoSS[fidx1], vCoSS[fidx2], bucket_clip_edges[0], bucket_clip_edges[1]) ) { - ftot = Vec2Lenf(vCoSS[fidx1], vCoSS[fidx2]); /* screenspace edge length */ + ftot = len_v2v2(vCoSS[fidx1], vCoSS[fidx2]); /* screenspace edge length */ if (ftot > 0.0f) { /* avoid div by zero */ if (mf->v4) { @@ -2575,19 +2575,19 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i else side= 0; } - fac1 = Vec2Lenf(vCoSS[fidx1], bucket_clip_edges[0]) / ftot; - fac2 = Vec2Lenf(vCoSS[fidx1], bucket_clip_edges[1]) / ftot; + fac1 = len_v2v2(vCoSS[fidx1], bucket_clip_edges[0]) / ftot; + fac2 = len_v2v2(vCoSS[fidx1], bucket_clip_edges[1]) / ftot; - Vec2Lerpf(seam_subsection[0], tf_uv_pxoffset[fidx1], tf_uv_pxoffset[fidx2], fac1); - Vec2Lerpf(seam_subsection[1], tf_uv_pxoffset[fidx1], tf_uv_pxoffset[fidx2], fac2); + interp_v2_v2v2(seam_subsection[0], tf_uv_pxoffset[fidx1], tf_uv_pxoffset[fidx2], fac1); + interp_v2_v2v2(seam_subsection[1], tf_uv_pxoffset[fidx1], tf_uv_pxoffset[fidx2], fac2); - Vec2Lerpf(seam_subsection[2], outset_uv[fidx1], outset_uv[fidx2], fac2); - Vec2Lerpf(seam_subsection[3], outset_uv[fidx1], outset_uv[fidx2], fac1); + interp_v2_v2v2(seam_subsection[2], outset_uv[fidx1], outset_uv[fidx2], fac2); + interp_v2_v2v2(seam_subsection[3], outset_uv[fidx1], outset_uv[fidx2], fac1); /* if the bucket_clip_edges values Z values was kept we could avoid this * Inset needs to be added so occlusion tests wont hit adjacent faces */ - VecLerpf(edge_verts_inset_clip[0], insetCos[fidx1], insetCos[fidx2], fac1); - VecLerpf(edge_verts_inset_clip[1], insetCos[fidx1], insetCos[fidx2], fac2); + interp_v3_v3v3(edge_verts_inset_clip[0], insetCos[fidx1], insetCos[fidx2], fac1); + interp_v3_v3v3(edge_verts_inset_clip[1], insetCos[fidx1], insetCos[fidx2], fac2); if (pixel_bounds_uv(seam_subsection[0], seam_subsection[1], seam_subsection[2], seam_subsection[3], &bounds_px, ibuf->x, ibuf->y, 1)) { @@ -2604,7 +2604,7 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i uv[0] = (float)x / ibuf_xf; /* use offset uvs instead */ /* test we're inside uvspace bucket and triangle bounds */ - if (IsectPQ2Df(uv, seam_subsection[0], seam_subsection[1], seam_subsection[2], seam_subsection[3])) { + if (isect_point_quad_v2(uv, seam_subsection[0], seam_subsection[1], seam_subsection[2], seam_subsection[3])) { /* We need to find the closest point along the face edge, * getting the screen_px_from_*** wont work because our actual location @@ -2621,11 +2621,11 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i fac = lambda_cp_line2(uv, seam_subsection[0], seam_subsection[1]); if (fac < 0.0f) { VECCOPY(pixelScreenCo, edge_verts_inset_clip[0]); } else if (fac > 1.0f) { VECCOPY(pixelScreenCo, edge_verts_inset_clip[1]); } - else { VecLerpf(pixelScreenCo, edge_verts_inset_clip[0], edge_verts_inset_clip[1], fac); } + else { interp_v3_v3v3(pixelScreenCo, edge_verts_inset_clip[0], edge_verts_inset_clip[1], fac); } if (!is_ortho) { pixelScreenCo[3] = 1.0f; - Mat4MulVec4fl((float(*)[4])ps->projectMat, pixelScreenCo); /* cast because of const */ + mul_m4_v4((float(*)[4])ps->projectMat, pixelScreenCo); /* cast because of const */ pixelScreenCo[0] = (float)(ps->ar->winx/2.0f)+(ps->ar->winx/2.0f)*pixelScreenCo[0]/pixelScreenCo[3]; pixelScreenCo[1] = (float)(ps->ar->winy/2.0f)+(ps->ar->winy/2.0f)*pixelScreenCo[1]/pixelScreenCo[3]; pixelScreenCo[2] = pixelScreenCo[2]/pixelScreenCo[3]; /* Use the depth for bucket point occlusion */ @@ -2661,10 +2661,10 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i /* a pitty we need to get the worldspace pixel location here */ if(ps->rv3d->rflag & RV3D_CLIPPING) { - if (side) VecLerp3f(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w); - else VecLerp3f(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w); + if (side) interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w); + else interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w); - Mat4MulVecfl(ps->ob->obmat, wco); + mul_m4_v3(ps->ob->obmat, wco); if(view3d_test_clipping(ps->rv3d, wco)) { continue; /* Watch out that no code below this needs to run */ } @@ -2824,23 +2824,23 @@ static int project_bucket_face_isect(ProjPaintState *ps, float min[2], float max p4[0] = bucket_bounds.xmax; p4[1] = bucket_bounds.ymin; if (mf->v4) { - if( IsectPQ2Df(p1, v1, v2, v3, v4) || IsectPQ2Df(p2, v1, v2, v3, v4) || IsectPQ2Df(p3, v1, v2, v3, v4) || IsectPQ2Df(p4, v1, v2, v3, v4) || + if( isect_point_quad_v2(p1, v1, v2, v3, v4) || isect_point_quad_v2(p2, v1, v2, v3, v4) || isect_point_quad_v2(p3, v1, v2, v3, v4) || isect_point_quad_v2(p4, v1, v2, v3, v4) || /* we can avoid testing v3,v1 because another intersection MUST exist if this intersects */ - (IsectLL2Df(p1, p2, v1, v2) || IsectLL2Df(p1, p2, v2, v3) || IsectLL2Df(p1, p2, v3, v4)) || - (IsectLL2Df(p2, p3, v1, v2) || IsectLL2Df(p2, p3, v2, v3) || IsectLL2Df(p2, p3, v3, v4)) || - (IsectLL2Df(p3, p4, v1, v2) || IsectLL2Df(p3, p4, v2, v3) || IsectLL2Df(p3, p4, v3, v4)) || - (IsectLL2Df(p4, p1, v1, v2) || IsectLL2Df(p4, p1, v2, v3) || IsectLL2Df(p4, p1, v3, v4)) + (isect_line_line_v2(p1, p2, v1, v2) || isect_line_line_v2(p1, p2, v2, v3) || isect_line_line_v2(p1, p2, v3, v4)) || + (isect_line_line_v2(p2, p3, v1, v2) || isect_line_line_v2(p2, p3, v2, v3) || isect_line_line_v2(p2, p3, v3, v4)) || + (isect_line_line_v2(p3, p4, v1, v2) || isect_line_line_v2(p3, p4, v2, v3) || isect_line_line_v2(p3, p4, v3, v4)) || + (isect_line_line_v2(p4, p1, v1, v2) || isect_line_line_v2(p4, p1, v2, v3) || isect_line_line_v2(p4, p1, v3, v4)) ) { return 1; } } else { - if( IsectPT2Df(p1, v1, v2, v3) || IsectPT2Df(p2, v1, v2, v3) || IsectPT2Df(p3, v1, v2, v3) || IsectPT2Df(p4, v1, v2, v3) || + if( isect_point_tri_v2(p1, v1, v2, v3) || isect_point_tri_v2(p2, v1, v2, v3) || isect_point_tri_v2(p3, v1, v2, v3) || isect_point_tri_v2(p4, v1, v2, v3) || /* we can avoid testing v3,v1 because another intersection MUST exist if this intersects */ - (IsectLL2Df(p1, p2, v1, v2) || IsectLL2Df(p1, p2, v2, v3)) || - (IsectLL2Df(p2, p3, v1, v2) || IsectLL2Df(p2, p3, v2, v3)) || - (IsectLL2Df(p3, p4, v1, v2) || IsectLL2Df(p3, p4, v2, v3)) || - (IsectLL2Df(p4, p1, v1, v2) || IsectLL2Df(p4, p1, v2, v3)) + (isect_line_line_v2(p1, p2, v1, v2) || isect_line_line_v2(p1, p2, v2, v3)) || + (isect_line_line_v2(p2, p3, v1, v2) || isect_line_line_v2(p2, p3, v2, v3)) || + (isect_line_line_v2(p3, p4, v1, v2) || isect_line_line_v2(p3, p4, v2, v3)) || + (isect_line_line_v2(p4, p1, v1, v2) || isect_line_line_v2(p4, p1, v2, v3)) ) { return 1; } @@ -3000,18 +3000,18 @@ static void project_paint_begin(ProjPaintState *ps) view3d_get_object_project_mat(ps->rv3d, ps->ob, ps->projectMat); /* viewDir - object relative */ - Mat4Invert(ps->ob->imat, ps->ob->obmat); - Mat3CpyMat4(mat, ps->rv3d->viewinv); - Mat3MulVecfl(mat, ps->viewDir); - Mat3CpyMat4(mat, ps->ob->imat); - Mat3MulVecfl(mat, ps->viewDir); - Normalize(ps->viewDir); + invert_m4_m4(ps->ob->imat, ps->ob->obmat); + copy_m3_m4(mat, ps->rv3d->viewinv); + mul_m3_v3(mat, ps->viewDir); + copy_m3_m4(mat, ps->ob->imat); + mul_m3_v3(mat, ps->viewDir); + normalize_v3(ps->viewDir); /* viewPos - object relative */ VECCOPY(ps->viewPos, ps->rv3d->viewinv[3]); - Mat3CpyMat4(mat, ps->ob->imat); - Mat3MulVecfl(mat, ps->viewPos); - VecAddf(ps->viewPos, ps->viewPos, ps->ob->imat[3]); + copy_m3_m4(mat, ps->ob->imat); + mul_m3_v3(mat, ps->viewPos); + add_v3_v3v3(ps->viewPos, ps->viewPos, ps->ob->imat[3]); { /* only use these for running 'get_view3d_viewplane' */ rctf viewplane; @@ -3045,7 +3045,7 @@ static void project_paint_begin(ProjPaintState *ps) if (ps->is_ortho) { for(a=0; a < ps->dm_totvert; a++, projScreenCo++) { VECCOPY((*projScreenCo), ps->dm_mvert[a].co); - Mat4MulVecfl(ps->projectMat, (*projScreenCo)); + mul_m4_v3(ps->projectMat, (*projScreenCo)); /* screen space, not clamped */ (*projScreenCo)[0] = (float)(ps->ar->winx/2.0f)+(ps->ar->winx/2.0f)*(*projScreenCo)[0]; @@ -3058,7 +3058,7 @@ static void project_paint_begin(ProjPaintState *ps) VECCOPY((*projScreenCo), ps->dm_mvert[a].co); (*projScreenCo)[3] = 1.0f; - Mat4MulVec4fl(ps->projectMat, (*projScreenCo)); + mul_m4_v4(ps->projectMat, (*projScreenCo)); if ((*projScreenCo)[3] > ps->clipsta) { @@ -3152,14 +3152,14 @@ static void project_paint_begin(ProjPaintState *ps) no[2] = (float)(v->no[2] / 32767.0f); if (ps->is_ortho) { - if (NormalizedVecAngle2(ps->viewDir, no) >= ps->normal_angle) { /* 1 vert of this face is towards us */ + if (angle_normalized_v3v3(ps->viewDir, no) >= ps->normal_angle) { /* 1 vert of this face is towards us */ ps->vertFlags[a] |= PROJ_VERT_CULL; } } else { - VecSubf(viewDirPersp, ps->viewPos, v->co); - Normalize(viewDirPersp); - if (NormalizedVecAngle2(viewDirPersp, no) >= ps->normal_angle) { /* 1 vert of this face is towards us */ + sub_v3_v3v3(viewDirPersp, ps->viewPos, v->co); + normalize_v3(viewDirPersp); + if (angle_normalized_v3v3(viewDirPersp, no) >= ps->normal_angle) { /* 1 vert of this face is towards us */ ps->vertFlags[a] |= PROJ_VERT_CULL; } } @@ -3298,10 +3298,10 @@ static void project_paint_begin_clone(ProjPaintState *ps, int mouse[2]) float projCo[4]; float *curs= give_cursor(ps->scene, ps->v3d); VECCOPY(projCo, curs); - Mat4MulVecfl(ps->ob->imat, projCo); + mul_m4_v3(ps->ob->imat, projCo); projCo[3] = 1.0f; - Mat4MulVec4fl(ps->projectMat, projCo); + mul_m4_v4(ps->projectMat, projCo); ps->cloneOffset[0] = mouse[0] - ((float)(ps->ar->winx/2.0f)+(ps->ar->winx/2.0f)*projCo[0]/projCo[3]); ps->cloneOffset[1] = mouse[1] - ((float)(ps->ar->winy/2.0f)+(ps->ar->winy/2.0f)*projCo[1]/projCo[3]); } @@ -3742,7 +3742,7 @@ static void *do_projectpaint_thread(void *ph_v) projPixel = (ProjPixel *)node->link; - /*dist = Vec2Lenf(projPixel->projCoSS, pos);*/ /* correct but uses a sqrtf */ + /*dist = len_v2v2(projPixel->projCoSS, pos);*/ /* correct but uses a sqrtf */ dist_nosqrt = Vec2Lenf_nosqrt(projPixel->projCoSS, pos); /*if (dist < s->brush->size) {*/ /* correct but uses a sqrtf */ @@ -3811,7 +3811,7 @@ static void *do_projectpaint_thread(void *ph_v) } break; case PAINT_TOOL_SMEAR: - Vec2Subf(co, projPixel->projCoSS, pos_ofs); + sub_v2_v2v2(co, projPixel->projCoSS, pos_ofs); if (is_floatbuf) do_projectpaint_smear_f(ps, projPixel, rgba, alpha, mask, smearArena, &smearPixels_f, co); else do_projectpaint_smear(ps, projPixel, rgba, alpha, mask, smearArena, &smearPixels, co); @@ -4200,14 +4200,14 @@ static int imapaint_paint_op(void *state, ImBuf *ibufb, float *lastpos, float *p static int texpaint_break_stroke(float *prevuv, float *fwuv, float *bkuv, float *uv) { float d1[2], d2[2]; - float mismatch = Vec2Lenf(fwuv, uv); - float len1 = Vec2Lenf(prevuv, fwuv); - float len2 = Vec2Lenf(bkuv, uv); + float mismatch = len_v2v2(fwuv, uv); + float len1 = len_v2v2(prevuv, fwuv); + float len2 = len_v2v2(bkuv, uv); - Vec2Subf(d1, fwuv, prevuv); - Vec2Subf(d2, uv, bkuv); + sub_v2_v2v2(d1, fwuv, prevuv); + sub_v2_v2v2(d2, uv, bkuv); - return ((Inp2f(d1, d2) < 0.0f) || (mismatch > MAX2(len1, len2)*2)); + return ((dot_v2v2(d1, d2) < 0.0f) || (mismatch > MAX2(len1, len2)*2)); } /* ImagePaint Common */ diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 6e256bee7f2..0b86034958f 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -41,7 +41,7 @@ #include "WM_api.h" #include "WM_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "PIL_time.h" diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 15104068350..24d9e0f4bc1 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -13,7 +13,7 @@ #include "RNA_access.h" #include "RNA_define.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_brush.h" #include "BKE_context.h" @@ -43,9 +43,9 @@ static void imapaint_project(Object *ob, float *model, float *proj, float *co, f VECCOPY(pco, co); pco[3]= 1.0f; - Mat4MulVecfl(ob->obmat, pco); - Mat4MulVecfl((float(*)[4])model, pco); - Mat4MulVec4fl((float(*)[4])proj, pco); + mul_m4_v3(ob->obmat, pco); + mul_m4_v3((float(*)[4])model, pco); + mul_m4_v4((float(*)[4])proj, pco); } static void imapaint_tri_weights(Object *ob, float *v1, float *v2, float *v3, float *co, float *w) @@ -79,15 +79,15 @@ static void imapaint_tri_weights(Object *ob, float *v1, float *v2, float *v3, fl wmat[0][1]= pv1[1]; wmat[1][1]= pv2[1]; wmat[2][1]= pv3[1]; wmat[0][2]= pv1[3]; wmat[1][2]= pv2[3]; wmat[2][2]= pv3[3]; - Mat3Inv(invwmat, wmat); - Mat3MulVecfl(invwmat, h); + invert_m3_m3(invwmat, wmat); + mul_m3_v3(invwmat, h); VECCOPY(w, h); /* w is still divided by perspdiv, make it sum to one */ divw= w[0] + w[1] + w[2]; if(divw != 0.0f) - VecMulf(w, 1.0f/divw); + mul_v3_fl(w, 1.0f/divw); } /* compute uv coordinates of mouse in face */ diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 408f4862b6f..35723769f88 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -42,7 +42,7 @@ #include "IMB_imbuf_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_ghash.h" #include "DNA_anim_types.h" @@ -1104,12 +1104,10 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */ /* verify if active weight group is also active bone */ par= modifiers_isDeformedByArmature(ob); if(par && (par->mode & OB_MODE_POSE)) { - bPoseChannel *pchan; - for(pchan= par->pose->chanbase.first; pchan; pchan= pchan->next) - if(pchan->bone->flag & BONE_ACTIVE) - break; - if(pchan) - ED_vgroup_select_by_name(ob, pchan->name); + bArmature *arm= ob->data; + + if(arm->act_bone) + ED_vgroup_select_by_name(ob, arm->act_bone->name); } } else { @@ -1381,9 +1379,9 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *event) // if(ob->lay & v3d->lay); else error("Active object is not in this layer"); /* imat for normals */ - Mat4MulMat4(mat, ob->obmat, wpd->vc.rv3d->viewmat); - Mat4Invert(imat, mat); - Mat3CpyMat4(wpd->wpimat, imat); + mul_m4_m4m4(mat, ob->obmat, wpd->vc.rv3d->viewmat); + invert_m4_m4(imat, mat); + copy_m3_m4(wpd->wpimat, imat); /* if mirror painting, find the other group */ if(me->editflag & ME_EDIT_MIRROR_X) { @@ -1439,7 +1437,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P mval[0]-= vc->ar->winrct.xmin; mval[1]-= vc->ar->winrct.ymin; - Mat4SwapMat4(wpd->vc.rv3d->persmat, mat); + swap_m4m4(wpd->vc.rv3d->persmat, mat); /* which faces are involved */ if(wp->flag & VP_AREA) { @@ -1564,7 +1562,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P } } - Mat4SwapMat4(vc->rv3d->persmat, mat); + swap_m4m4(vc->rv3d->persmat, mat); DAG_id_flush_update(ob->data, OB_RECALC_DATA); ED_region_tag_redraw(vc->ar); @@ -1797,9 +1795,9 @@ static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent copy_vpaint_prev(vp, (unsigned int *)me->mcol, me->totface); /* some old cruft to sort out later */ - Mat4MulMat4(mat, ob->obmat, vpd->vc.rv3d->viewmat); - Mat4Invert(imat, mat); - Mat3CpyMat4(vpd->vpimat, imat); + mul_m4_m4m4(mat, ob->obmat, vpd->vc.rv3d->viewmat); + invert_m4_m4(imat, mat); + copy_m3_m4(vpd->vpimat, imat); return 1; } @@ -1873,14 +1871,14 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P else totindex= 0; } - Mat4SwapMat4(vc->rv3d->persmat, mat); + swap_m4m4(vc->rv3d->persmat, mat); for(index=0; index<totindex; index++) { if(indexar[index] && indexar[index]<=me->totface) vpaint_paint_face(vp, vpd, ob, indexar[index]-1, mval); } - Mat4SwapMat4(vc->rv3d->persmat, mat); + swap_m4m4(vc->rv3d->persmat, mat); /* was disabled because it is slow, but necessary for blur */ if(vp->mode == VP_BLUR) diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index c4c7f436f12..f4006e63dc0 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -32,7 +32,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dynstr.h" @@ -65,6 +65,7 @@ #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_paint.h" +#include "BKE_report.h" #include "BKE_texture.h" #include "BKE_utildefines.h" #include "BKE_colortools.h" @@ -74,6 +75,7 @@ #include "WM_api.h" #include "WM_types.h" +#include "ED_object.h" #include "ED_screen.h" #include "ED_sculpt.h" #include "ED_space_api.h" @@ -140,6 +142,7 @@ typedef struct StrokeCache { float flip; float pressure; float mouse[2]; + float tex_mouse[2]; /* The rest is temporary storage that isn't saved as a property */ @@ -256,12 +259,12 @@ static void add_norm_if(float view_vec[3], float out[3], float out_flip[3], cons { float fno[3] = {no[0], no[1], no[2]}; - Normalize(fno); + normalize_v3(fno); - if((Inpf(view_vec, fno)) > 0) { - VecAddf(out, out, fno); + if((dot_v3v3(view_vec, fno)) > 0) { + add_v3_v3v3(out, out, fno); } else { - VecAddf(out_flip, out_flip, fno); /* out_flip is used when out is {0,0,0} */ + add_v3_v3v3(out_flip, out_flip, fno); /* out_flip is used when out is {0,0,0} */ } } @@ -291,7 +294,7 @@ static void calc_area_normal(Sculpt *sd, SculptSession *ss, float out[3], const VECCOPY(out, out_flip); } - Normalize(out); + normalize_v3(out); if(out_dir) { out[0] = out_dir[0] * view + out[0] * (10-view); @@ -299,7 +302,7 @@ static void calc_area_normal(Sculpt *sd, SculptSession *ss, float out[3], const out[2] = out_dir[2] * view + out[2] * (10-view); } - Normalize(out); + normalize_v3(out); } static void do_draw_brush(Sculpt *sd, SculptSession *ss, const ListBase* active_verts) @@ -349,7 +352,7 @@ static void neighbor_average(SculptSession *ss, float avg[3], const int vert) /* Don't modify corner vertices */ if(ncount==1) { - VecCopyf(avg, ss->mvert[vert].co); + copy_v3_v3(avg, ss->mvert[vert].co); return; } @@ -365,7 +368,7 @@ static void neighbor_average(SculptSession *ss, float avg[3], const int vert) for(i=0; i<(f->v4?4:3); ++i) { if(i != skip && (ncount!=2 || BLI_countlist(&ss->fmap[(&f->v1)[i]]) <= 2)) { - VecAddf(avg, avg, ss->mvert[(&f->v1)[i]].co); + add_v3_v3v3(avg, avg, ss->mvert[(&f->v1)[i]].co); ++total; } } @@ -374,9 +377,9 @@ static void neighbor_average(SculptSession *ss, float avg[3], const int vert) } if(total>0) - VecMulf(avg, 1.0f / total); + mul_v3_fl(avg, 1.0f / total); else - VecCopyf(avg, ss->mvert[vert].co); + copy_v3_v3(avg, ss->mvert[vert].co); } static void do_smooth_brush(Sculpt *s, SculptSession *ss, const ListBase* active_verts) @@ -443,14 +446,14 @@ static void do_grab_brush(Sculpt *sd, SculptSession *ss) float grab_delta[3]; float *buffer = ss->drawobject!=0?(float *)GPU_buffer_lock( ss->drawobject->vertices ):0; - VecCopyf(grab_delta, ss->cache->grab_delta_symmetry); + copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); while(node) { float *co= ss->mvert[node->Index].co; - VecCopyf(add, grab_delta); - VecMulf(add, node->Fade); - VecAddf(add, add, co); + copy_v3_v3(add, grab_delta); + mul_v3_fl(add, node->Fade); + add_v3_v3v3(add, add, co); if( buffer != 0 ) { IndexLink *cur = &ss->drawobject->indices[node->Index]; @@ -526,11 +529,11 @@ static void do_inflate_brush(Sculpt *s, SculptSession *ss, const ListBase *activ add[0]= no[0]/ 32767.0f; add[1]= no[1]/ 32767.0f; add[2]= no[2]/ 32767.0f; - VecMulf(add, node->Fade * ss->cache->radius); + mul_v3_fl(add, node->Fade * ss->cache->radius); add[0]*= ss->cache->scale[0]; add[1]*= ss->cache->scale[1]; add[2]*= ss->cache->scale[2]; - VecAddf(add, add, co); + add_v3_v3v3(add, add, co); if( buffer != 0 ) { IndexLink *cur = &ss->drawobject->indices[node->Index]; @@ -567,8 +570,8 @@ static void calc_flatten_center(SculptSession *ss, ActiveData *node, float co[3] co[0] = co[1] = co[2] = 0.0f; for(i = 0; i < FLATTEN_SAMPLE_SIZE; ++i) - VecAddf(co, co, ss->mvert[outer[i]->Index].co); - VecMulf(co, 1.0f / FLATTEN_SAMPLE_SIZE); + add_v3_v3v3(co, co, ss->mvert[outer[i]->Index].co); + mul_v3_fl(co, 1.0f / FLATTEN_SAMPLE_SIZE); } /* Projects a point onto a plane along the plane's normal */ @@ -577,12 +580,12 @@ static void point_plane_project(float intr[3], float co[3], float plane_normal[3 float p1[3], sub1[3], sub2[3]; /* Find the intersection between squash-plane and vertex (along the area normal) */ - VecSubf(p1, co, plane_normal); - VecSubf(sub1, plane_center, p1); - VecSubf(sub2, co, p1); - VecSubf(intr, co, p1); - VecMulf(intr, Inpf(plane_normal, sub1) / Inpf(plane_normal, sub2)); - VecAddf(intr, intr, p1); + sub_v3_v3v3(p1, co, plane_normal); + sub_v3_v3v3(sub1, plane_center, p1); + sub_v3_v3v3(sub2, co, p1); + sub_v3_v3v3(intr, co, p1); + mul_v3_fl(intr, dot_v3v3(plane_normal, sub1) / dot_v3v3(plane_normal, sub2)); + add_v3_v3v3(intr, intr, p1); } static int plane_point_side(float co[3], float plane_normal[3], float plane_center[3], int flip) @@ -590,8 +593,8 @@ static int plane_point_side(float co[3], float plane_normal[3], float plane_cent float delta[3]; float d; - VecSubf(delta, co, plane_center); - d = Inpf(plane_normal, delta); + sub_v3_v3v3(delta, co, plane_center); + d = dot_v3v3(plane_normal, delta); if(flip) d = -d; @@ -629,22 +632,22 @@ static void do_flatten_clay_brush(Sculpt *sd, SculptSession *ss, const ListBase /* Find the intersection between squash-plane and vertex (along the area normal) */ point_plane_project(intr, co, area_normal, cntr); - VecSubf(val, intr, co); + sub_v3_v3v3(val, intr, co); if(clay) { if(bstr > FLT_EPSILON) - VecMulf(val, node->Fade / bstr); + mul_v3_fl(val, node->Fade / bstr); else - VecMulf(val, node->Fade); + mul_v3_fl(val, node->Fade); /* Clay displacement */ val[0]+=area_normal[0] * ss->cache->scale[0]*node->Fade; val[1]+=area_normal[1] * ss->cache->scale[1]*node->Fade; val[2]+=area_normal[2] * ss->cache->scale[2]*node->Fade; } else - VecMulf(val, fabs(node->Fade)); + mul_v3_fl(val, fabs(node->Fade)); - VecAddf(val, val, co); + add_v3_v3v3(val, val, co); if( buffer != 0 ) { IndexLink *cur = &ss->drawobject->indices[node->Index]; @@ -747,7 +750,7 @@ static float tex_strength(Sculpt *sd, SculptSession *ss, float *point, const flo /* If the active area is being applied for symmetry, flip it across the symmetry axis in order to project it. This insures that the brush texture will be oriented correctly. */ - VecCopyf(flip, point); + copy_v3_v3(flip, point); flip_coord(flip, flip, ss->cache->symmetry); projectf(ss->cache->mats, flip, point_2d); @@ -777,8 +780,8 @@ static float tex_strength(Sculpt *sd, SculptSession *ss, float *point, const flo avg= get_texcache_pixel_bilinear(ss, ss->texcache_side*px/sx, ss->texcache_side*py/sy); } else if(tex->brush_map_mode == MTEX_MAP_MODE_FIXED) { - float fx= (point_2d[0] - ss->cache->mouse[0]) / bsize; - float fy= (point_2d[1] - ss->cache->mouse[1]) / bsize; + float fx= (point_2d[0] - ss->cache->tex_mouse[0]) / bsize; + float fy= (point_2d[1] - ss->cache->tex_mouse[1]) / bsize; float angle= atan2(fy, fx) - rot; float flen= sqrtf(fx*fx + fy*fy); @@ -836,9 +839,7 @@ static void do_brush_action(Sculpt *sd, SculptSession *ss, StrokeCache *cache) ListBase *grab_active_verts = &ss->cache->grab_active_verts[ss->cache->symmetry]; ActiveData *adata= 0; float *vert; - Mesh *me= NULL; /*XXX: get_mesh(OBACT); */ const float bstrength= brush_strength(sd, cache); - KeyBlock *keyblock= NULL; /*XXX: ob_get_keyblock(OBACT); */ Brush *b = brush; int i; @@ -852,7 +853,7 @@ static void do_brush_action(Sculpt *sd, SculptSession *ss, StrokeCache *cache) if(ss->multires || ss->projverts[i].inside) { //vert= ss->vertexcosnos ? &ss->vertexcosnos[i*6] : a->verts[i].co; vert= ss->mvert[i].co; - av_dist= VecLenf(ss->cache->location, vert); + av_dist= len_v3v3(ss->cache->location, vert); if(av_dist < cache->radius) { adata= (ActiveData*)MEM_mallocN(sizeof(ActiveData), "ActiveData"); @@ -901,19 +902,7 @@ static void do_brush_action(Sculpt *sd, SculptSession *ss, StrokeCache *cache) } /* Copy the modified vertices from mesh to the active key */ - if(keyblock && !ss->multires) { - float *co= keyblock->data; - if(co) { - if(b->sculpt_tool == SCULPT_TOOL_GRAB) - adata = grab_active_verts->first; - else - adata = active_verts.first; - - for(; adata; adata= adata->next) - if(adata->Index < keyblock->totelem) - VecCopyf(&co[adata->Index*3], me->mvert[adata->Index].co); - } - } + if(ss->kb) mesh_to_key(ss->ob->data, ss->kb); if(ss->vertexcosnos && !ss->multires) BLI_freelistN(&active_verts); @@ -940,8 +929,8 @@ static void do_symmetrical_brush_actions(Sculpt *sd, SculptSession *ss) const char symm = sd->flags & 7; int i; - VecCopyf(cache->location, cache->true_location); - VecCopyf(cache->grab_delta_symmetry, cache->grab_delta); + copy_v3_v3(cache->location, cache->true_location); + copy_v3_v3(cache->grab_delta_symmetry, cache->grab_delta); cache->symmetry = 0; do_brush_action(sd, ss, cache); @@ -963,15 +952,15 @@ static void add_face_normal(vec3f *norm, MVert *mvert, const MFace* face, float vec3f s1, s2; float final[3]; - VecSubf(&s1.x,&a.x,&b.x); - VecSubf(&s2.x,&c.x,&b.x); + sub_v3_v3v3(&s1.x,&a.x,&b.x); + sub_v3_v3v3(&s2.x,&c.x,&b.x); final[0] = s1.y * s2.z - s1.z * s2.y; final[1] = s1.z * s2.x - s1.x * s2.z; final[2] = s1.x * s2.y - s1.y * s2.x; if(fn) - VecCopyf(fn, final); + copy_v3_v3(fn, final); norm->x+= final[0]; norm->y+= final[1]; @@ -994,7 +983,7 @@ static void update_damaged_vert(SculptSession *ss, ListBase *lb) add_face_normal(&norm, ss->mvert, &ss->mface[face->index], fn); face= face->next; } - Normalize(&norm.x); + normalize_v3(&norm.x); ss->mvert[vert->Index].no[0]=norm.x*32767; ss->mvert[vert->Index].no[1]=norm.y*32767; @@ -1010,9 +999,9 @@ static void update_damaged_vert(SculptSession *ss, ListBase *lb) else { float norm[3]; if( ss->mface[i].v4 ) - CalcNormFloat4(ss->mvert[ss->mface[i].v1].co, ss->mvert[ss->mface[i].v2].co, ss->mvert[ss->mface[i].v3].co, ss->mvert[ss->mface[i].v4].co, norm); + normal_quad_v3( norm,ss->mvert[ss->mface[i].v1].co, ss->mvert[ss->mface[i].v2].co, ss->mvert[ss->mface[i].v3].co, ss->mvert[ss->mface[i].v4].co); else - CalcNormFloat(ss->mvert[ss->mface[i].v1].co, ss->mvert[ss->mface[i].v2].co, ss->mvert[ss->mface[i].v3].co, norm); + normal_tri_v3( norm,ss->mvert[ss->mface[i].v1].co, ss->mvert[ss->mface[i].v2].co, ss->mvert[ss->mface[i].v3].co); VECCOPY(&buffer[(cur->element-cur->element%3)*3],norm); VECCOPY(&buffer[(cur->element-cur->element%3+1)*3],norm); VECCOPY(&buffer[(cur->element-cur->element%3+2)*3],norm); @@ -1096,7 +1085,7 @@ char sculpt_modifiers_active(Object *ob) ModifierData *md; for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) { - if(md->mode & eModifierMode_Realtime && md->type != eModifierType_Multires) + if(modifier_isEnabled(md, eModifierMode_Realtime) && md->type != eModifierType_Multires) return 1; } @@ -1134,6 +1123,8 @@ static void sculpt_update_mesh_elements(bContext *C) int oldtotvert = ss->totvert; DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH); + ss->ob= ob; + if((ss->multires = sculpt_multires_active(ob))) { //DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH); ss->totvert = dm->getNumVerts(dm); @@ -1166,6 +1157,15 @@ static void sculpt_update_mesh_elements(bContext *C) create_vert_face_map(&ss->fmap, &ss->fmap_mem, ss->mface, ss->totvert, ss->totface); ss->fmap_size = ss->totvert; } + + if((ob->shapeflag & OB_SHAPE_LOCK) && !sculpt_multires_active(ob)) { + ss->kb= ob_get_keyblock(ob); + ss->refkb= ob_get_reference_keyblock(ob); + } + else { + ss->kb= NULL; + ss->refkb= NULL; + } } static int sculpt_mode_poll(bContext *C) @@ -1259,7 +1259,7 @@ static float unproject_brush_radius(SculptSession *ss, float offset) view3d_unproject(ss->cache->mats, brush_edge, ss->cache->initial_mouse[0] + offset, ss->cache->initial_mouse[1], ss->cache->depth); - return VecLenf(ss->cache->true_location, brush_edge); + return len_v3v3(ss->cache->true_location, brush_edge); } static void sculpt_cache_free(StrokeCache *cache) @@ -1292,8 +1292,8 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte RNA_float_get_array(op->ptr, "initial_mouse", cache->initial_mouse); cache->depth = RNA_float_get(op->ptr, "depth"); - cache->mouse[0] = cache->initial_mouse[0]; - cache->mouse[1] = cache->initial_mouse[1]; + copy_v2_v2(cache->mouse, cache->initial_mouse); + copy_v2_v2(cache->tex_mouse, cache->initial_mouse); /* Truly temporary data that isn't stored in properties */ @@ -1318,7 +1318,7 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte ss->mesh_co_orig= MEM_mallocN(sizeof(float) * 3 * ss->totvert, "sculpt mesh vertices copy"); for(i = 0; i < ss->totvert; ++i) - VecCopyf(ss->mesh_co_orig[i], ss->mvert[i].co); + copy_v3_v3(ss->mesh_co_orig[i], ss->mvert[i].co); } if(brush->flag & BRUSH_ANCHORED) { @@ -1333,7 +1333,7 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte float *fn = ss->face_normals; cache->face_norms= MEM_mallocN(sizeof(float) * 3 * ss->totface, "Sculpt face norms"); for(i = 0; i < ss->totface; ++i, fn += 3) - VecCopyf(cache->face_norms[i], fn); + copy_v3_v3(cache->face_norms[i], fn); } } } @@ -1371,6 +1371,9 @@ static void sculpt_update_cache_variants(Sculpt *sd, SculptSession *ss, PointerR else cache->radius = cache->initial_radius; + if(!(brush->flag & BRUSH_ANCHORED)) + copy_v2_v2(cache->tex_mouse, cache->mouse); + if(brush->flag & BRUSH_ANCHORED) { dx = cache->mouse[0] - cache->initial_mouse[0]; dy = cache->mouse[1] - cache->initial_mouse[1]; @@ -1400,8 +1403,8 @@ static void sculpt_update_cache_variants(Sculpt *sd, SculptSession *ss, PointerR if(brush->sculpt_tool == SCULPT_TOOL_GRAB) { view3d_unproject(cache->mats, grab_location, cache->mouse[0], cache->mouse[1], cache->depth); if(!cache->first_time) - VecSubf(cache->grab_delta, grab_location, cache->old_grab_location); - VecCopyf(cache->old_grab_location, grab_location); + sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location); + copy_v3_v3(cache->old_grab_location, grab_location); } } @@ -1448,11 +1451,17 @@ static void sculpt_brush_stroke_init_properties(bContext *C, wmOperator *op, wmE sculpt_update_cache_invariants(sd, ss, C, op); } -static void sculpt_brush_stroke_init(bContext *C) +static int sculpt_brush_stroke_init(bContext *C, ReportList *reports) { + Object *ob= CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; + if(ob_get_key(ob) && !(ob->shapeflag & OB_SHAPE_LOCK)) { + BKE_report(reports, RPT_ERROR, "Shape key sculpting requires a locked shape."); + return 0; + } + view3d_operator_needs_opengl(C); /* TODO: Shouldn't really have to do this at the start of every @@ -1461,6 +1470,10 @@ static void sculpt_brush_stroke_init(bContext *C) sculpt_update_tex(sd, ss); sculpt_update_mesh_elements(C); + + if(ss->kb) key_to_mesh(ss->kb, ss->ob->data); + + return 1; } static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss) @@ -1477,7 +1490,7 @@ static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss) buffer= (float *)GPU_buffer_lock(ss->drawobject->normals); for(i = 0; i < ss->totvert; ++i) { - VecCopyf(ss->mvert[i].co, ss->mesh_co_orig[i]); + copy_v3_v3(ss->mvert[i].co, ss->mesh_co_orig[i]); ss->mvert[i].no[0] = cache->orig_norms[i][0]; ss->mvert[i].no[1] = cache->orig_norms[i][1]; ss->mvert[i].no[2] = cache->orig_norms[i][2]; @@ -1495,7 +1508,7 @@ static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss) if(ss->face_normals) { float *fn = ss->face_normals; for(i = 0; i < ss->totface; ++i, fn += 3) - VecCopyf(fn, cache->face_norms[i]); + copy_v3_v3(fn, cache->face_norms[i]); } if(brush->sculpt_tool == SCULPT_TOOL_LAYER) @@ -1527,6 +1540,9 @@ static void sculpt_flush_update(bContext *C) multires_mark_as_modified(ob); } + if(sculpt_modifiers_active(ob)) + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + ED_region_tag_redraw(ar); } @@ -1567,12 +1583,15 @@ static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *stroke, P static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke) { - SculptSession *ss = CTX_data_active_object(C)->sculpt; + Object *ob= CTX_data_active_object(C); + SculptSession *ss = ob->sculpt; /* Finished */ if(ss->cache) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; + if(ss->refkb) key_to_mesh(ss->refkb, ob->data); + request_depth_update(paint_stroke_view_context(stroke)->rv3d); sculpt_cache_free(ss->cache); ss->cache = NULL; @@ -1582,7 +1601,8 @@ static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke) static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event) { - sculpt_brush_stroke_init(C); + if(!sculpt_brush_stroke_init(C, op->reports)) + return OPERATOR_CANCELLED; op->customdata = paint_stroke_new(C, sculpt_stroke_test_start, sculpt_stroke_update_step, @@ -1601,9 +1621,10 @@ static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op) Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; - op->customdata = paint_stroke_new(C, sculpt_stroke_test_start, sculpt_stroke_update_step, sculpt_stroke_done); + if(!sculpt_brush_stroke_init(C, op->reports)) + return OPERATOR_CANCELLED; - sculpt_brush_stroke_init(C); + op->customdata = paint_stroke_new(C, sculpt_stroke_test_start, sculpt_stroke_update_step, sculpt_stroke_done); sculpt_update_cache_invariants(sd, ss, C, op); sculptmode_update_all_projverts(ss); @@ -1694,7 +1715,8 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); if(ob->mode & OB_MODE_SCULPT) { - multires_force_update(ob); + if(sculpt_multires_active(ob)) + multires_force_update(ob); /* Leave sculptmode */ ob->mode &= ~OB_MODE_SCULPT; diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c index 7f2e1bd09e4..77cfc2cd484 100644 --- a/source/blender/editors/space_action/action_draw.c +++ b/source/blender/editors/space_action/action_draw.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" /* Types --------------------------------------------------------------- */ diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 0bcf4b037cb..a7c012fc654 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index cc8688031b0..c4f2e40e958 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dlrbTree.h" #include "DNA_anim_types.h" diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c index 07de15a26b4..59b690002d2 100644 --- a/source/blender/editors/space_action/space_action.c +++ b/source/blender/editors/space_action/space_action.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" @@ -341,6 +341,13 @@ static void action_main_area_listener(ARegion *ar, wmNotifier *wmn) break; } break; + case NC_NODE: + switch(wmn->action) { + case NA_EDITED: + ED_region_tag_redraw(ar); + break; + } + break; default: if(wmn->data==ND_KEYS) ED_region_tag_redraw(ar); diff --git a/source/blender/editors/space_api/space.c b/source/blender/editors/space_api/space.c index 3112cfffb22..5318eb33b1f 100644 --- a/source/blender/editors/space_api/space.c +++ b/source/blender/editors/space_api/space.c @@ -32,7 +32,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_screen.h" diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 026498f17af..0e2769a3557 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -243,26 +243,9 @@ static int buttons_context_path_material(ButsContextPath *path) return 0; } -static Bone *find_active_bone(Bone *bone) -{ - Bone *active; - - for(; bone; bone=bone->next) { - if(bone->flag & BONE_ACTIVE) - return bone; - - active= find_active_bone(bone->childbase.first); - if(active) - return active; - } - - return NULL; -} - static int buttons_context_path_bone(ButsContextPath *path) { bArmature *arm; - Bone *bone; EditBone *edbo; /* if we have an armature, get the active bone */ @@ -270,19 +253,16 @@ static int buttons_context_path_bone(ButsContextPath *path) arm= path->ptr[path->len-1].data; if(arm->edbo) { - for(edbo=arm->edbo->first; edbo; edbo=edbo->next) { - if(edbo->flag & BONE_ACTIVE) { - RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]); - path->len++; - return 1; - } + if(arm->act_edbone) { + edbo= arm->act_edbone; + RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]); + path->len++; + return 1; } } else { - bone= find_active_bone(arm->bonebase.first); - - if(bone) { - RNA_pointer_create(&arm->id, &RNA_Bone, bone, &path->ptr[path->len]); + if(arm->act_bone) { + RNA_pointer_create(&arm->id, &RNA_Bone, arm->act_bone, &path->ptr[path->len]); path->len++; return 1; } @@ -727,8 +707,11 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r set_pointer_type(path, result, &RNA_Brush); return 1; } + else { + return 0; /* not found */ + } - return 0; + return -1; /* found but not available */ } /************************* Drawing the Path ************************/ @@ -784,7 +767,7 @@ void buttons_context_draw(const bContext *C, uiLayout *layout) ptr= &path->ptr[a]; if(a != 0) - uiDefIconBut(block, LABEL, 0, VICON_SMALL_TRI_RIGHT, 0, 0, 10, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); + uiItemL(row, "", VICON_SMALL_TRI_RIGHT); if(ptr->data) { icon= RNA_struct_ui_icon(ptr->type); diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index f05c652c39d..2c918bd9b30 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -38,7 +38,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index c6565eb6ecc..3dca5a4db4b 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_colortools.h" #include "BKE_context.h" diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 94d90929d80..640f365b073 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -911,7 +911,17 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime) || BLI_testextensie(file->relname, ".movie") || BLI_testextensie(file->relname, ".mp4") || BLI_testextensie(file->relname, ".m4v") - || BLI_testextensie(file->relname, ".mv")) { + || BLI_testextensie(file->relname, ".mv") + || BLI_testextensie(file->relname, ".wmv") + || BLI_testextensie(file->relname, ".ogv") + || BLI_testextensie(file->relname, ".mpeg") + || BLI_testextensie(file->relname, ".mpg") + || BLI_testextensie(file->relname, ".mpg2") + || BLI_testextensie(file->relname, ".vob") + || BLI_testextensie(file->relname, ".mkv") + || BLI_testextensie(file->relname, ".flv") + || BLI_testextensie(file->relname, ".divx") + || BLI_testextensie(file->relname, ".xvid")) { file->flags |= MOVIEFILE; } else if(BLI_testextensie(file->relname, ".wav") @@ -954,8 +964,22 @@ void filelist_setfiletypes(struct FileList* filelist, short has_quicktime) file->flags |= IMAGEFILE; } else if(BLI_testextensie(file->relname, ".avi") + || BLI_testextensie(file->relname, ".flc") + || BLI_testextensie(file->relname, ".mov") + || BLI_testextensie(file->relname, ".movie") || BLI_testextensie(file->relname, ".mp4") - || BLI_testextensie(file->relname, ".mv")) { + || BLI_testextensie(file->relname, ".m4v") + || BLI_testextensie(file->relname, ".mv") + || BLI_testextensie(file->relname, ".wmv") + || BLI_testextensie(file->relname, ".ogv") + || BLI_testextensie(file->relname, ".mpeg") + || BLI_testextensie(file->relname, ".mpg") + || BLI_testextensie(file->relname, ".mpg2") + || BLI_testextensie(file->relname, ".vob") + || BLI_testextensie(file->relname, ".mkv") + || BLI_testextensie(file->relname, ".flv") + || BLI_testextensie(file->relname, ".divx") + || BLI_testextensie(file->relname, ".xvid")) { file->flags |= MOVIEFILE; } else if(BLI_testextensie(file->relname, ".wav") diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 91d917acfe7..576736f026f 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -43,7 +43,7 @@ #include "BLO_readfile.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BLI_storage_types.h" diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index b5d69934ad5..38289e98391 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -173,31 +173,40 @@ static void graph_panel_properties(const bContext *C, Panel *pa) { bAnimListElem *ale; FCurve *fcu; + PointerRNA fcu_ptr; + uiLayout *layout = pa->layout; + uiLayout *col, *row, *subrow; uiBlock *block; - char name[128]; + char name[256]; + int icon = 0; - if(!graph_panel_context(C, &ale, &fcu)) + if (!graph_panel_context(C, &ale, &fcu)) return; - - block= uiLayoutAbsoluteBlock(pa->layout); + + block= uiLayoutGetBlock(layout); uiBlockSetHandleFunc(block, do_graph_region_buttons, NULL); - - /* Info - Active F-Curve */ - uiDefBut(block, LABEL, 1, "Active F-Curve:", 10, 200, 150, 19, NULL, 0.0, 0.0, 0, 0, ""); - if (ale->id) { - // icon of active blocktype - is this really necessary? - int icon= geticon_anim_blocktype(GS(ale->id->name)); - - // xxx type of icon-but is currently "LABEL", as that one is plain... - uiDefIconBut(block, LABEL, 1, icon, 10, 180, 20, 19, NULL, 0, 0, 0, 0, "ID-type that F-Curve belongs to"); - } + /* F-Curve pointer */ + RNA_pointer_create(ale->id, &RNA_FCurve, fcu, &fcu_ptr); - getname_anim_fcurve(name, ale->id, fcu); - uiDefBut(block, LABEL, 1, name, 40, 180, 300, 19, NULL, 0.0, 0.0, 0, 0, "Name of Active F-Curve"); + /* user-friendly 'name' for F-Curve */ + // TODO: only show the path if this is invalid? + col= uiLayoutColumn(layout, 0); + icon= getname_anim_fcurve(name, ale->id, fcu); + uiItemL(col, name, icon); + + /* color settings */ + col= uiLayoutColumn(layout, 1); + uiItemL(col, "Display Color:", 0); + + row= uiLayoutRow(col, 1); + uiItemR(row, "", 0, &fcu_ptr, "color_mode", 0); + + subrow= uiLayoutRow(row, 1); + uiLayoutSetEnabled(subrow, (fcu->color_mode==FCURVE_COLOR_CUSTOM)); + uiItemR(subrow, "", 0, &fcu_ptr, "color", 0); /* TODO: the following settings could be added here - * - F-Curve coloring mode - mode selector + color selector * - Access details (ID-block + RNA-Path + Array Index) * - ... */ @@ -448,13 +457,13 @@ void graph_buttons_register(ARegionType *art) pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel view"); strcpy(pt->idname, "GRAPH_PT_view"); - strcpy(pt->label, "View"); + strcpy(pt->label, "View Properties"); pt->draw= graph_panel_view; BLI_addtail(&art->paneltypes, pt); pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel properties"); strcpy(pt->idname, "GRAPH_PT_properties"); - strcpy(pt->label, "Properties"); + strcpy(pt->label, "Active F-Curve"); pt->draw= graph_panel_properties; pt->poll= graph_panel_poll; BLI_addtail(&art->paneltypes, pt); diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 052c5c4a743..6e0878972f8 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -42,7 +42,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" @@ -308,8 +308,10 @@ void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu) glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); - /* draw the two handles first (if they're shown, and if curve is being edited) */ - if ((fcu->flag & FCURVE_PROTECTED)==0 && (fcu->flag & FCURVE_INT_VALUES)==0 && (sipo->flag & SIPO_NOHANDLES)==0) { + /* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */ + if ((fcu->flag & FCURVE_PROTECTED)==0 && (fcu->flag & FCURVE_INT_VALUES)==0 && + (sipo->flag & SIPO_NOHANDLES)==0 && (fcu->totvert > 1)) + { set_fcurve_vertex_color(sipo, fcu, 0); draw_fcurve_vertices_handles(fcu, v2d, 0); diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index b467d7b4ca0..2088ee4030c 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index 09fde389f6f..8d2e2921b7f 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" diff --git a/source/blender/editors/space_graph/graph_utils.c b/source/blender/editors/space_graph/graph_utils.c index ee4e371e1f1..40fe3393a60 100644 --- a/source/blender/editors/space_graph/graph_utils.c +++ b/source/blender/editors/space_graph/graph_utils.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index 342afab7534..157202190bb 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -38,7 +38,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_context.h" @@ -417,6 +417,13 @@ static void graph_region_listener(ARegion *ar, wmNotifier *wmn) break; } break; + case NC_NODE: + switch(wmn->action) { + case NA_EDITED: + ED_region_tag_redraw(ar); + break; + } + break; default: if(wmn->data==ND_KEYS) ED_region_tag_redraw(ar); diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 87b6ec8bb71..a184ea2b2c4 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -44,7 +44,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_rand.h" diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 8d7295e9f20..9ef7a4d9ae4 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -50,7 +50,7 @@ #include "BKE_report.h" #include "BKE_screen.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "IMB_imbuf.h" diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 36d1573a12c..8478b40092f 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_rand.h" diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index 518553c9a7a..c28e86a6fa6 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_context.h" diff --git a/source/blender/editors/space_logic/logic_buttons.c b/source/blender/editors/space_logic/logic_buttons.c index c8f96fe3373..e159af65c74 100644 --- a/source/blender/editors/space_logic/logic_buttons.c +++ b/source/blender/editors/space_logic/logic_buttons.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_global.h" diff --git a/source/blender/editors/space_logic/space_logic.c b/source/blender/editors/space_logic/space_logic.c index 836ac4c6659..62ed6a0a769 100644 --- a/source/blender/editors/space_logic/space_logic.c +++ b/source/blender/editors/space_logic/space_logic.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_screen.h" diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c index b193b89d65a..6e5da38dd10 100644 --- a/source/blender/editors/space_nla/nla_buttons.c +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -155,6 +155,7 @@ static int nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA case ANIMTYPE_DSCUR: case ANIMTYPE_DSSKEY: case ANIMTYPE_DSWOR: + case ANIMTYPE_DSNTREE: case ANIMTYPE_DSPART: case ANIMTYPE_DSMBALL: case ANIMTYPE_DSARM: diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c index 07dc3f0ad89..ab447dd974a 100644 --- a/source/blender/editors/space_nla/nla_channels.c +++ b/source/blender/editors/space_nla/nla_channels.c @@ -53,7 +53,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_animsys.h" @@ -189,6 +189,7 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho case ANIMTYPE_DSCUR: case ANIMTYPE_DSSKEY: case ANIMTYPE_DSWOR: + case ANIMTYPE_DSNTREE: case ANIMTYPE_DSPART: case ANIMTYPE_DSMBALL: case ANIMTYPE_DSARM: diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c index b21f37ab678..c32058545fb 100644 --- a/source/blender/editors/space_nla/nla_draw.c +++ b/source/blender/editors/space_nla/nla_draw.c @@ -56,7 +56,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BLI_dlrbTree.h" diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index e53ccd004db..12e43465a29 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -42,7 +42,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_animsys.h" diff --git a/source/blender/editors/space_nla/nla_header.c b/source/blender/editors/space_nla/nla_header.c index a2524a1b2dc..0c0deaf75ef 100644 --- a/source/blender/editors/space_nla/nla_header.c +++ b/source/blender/editors/space_nla/nla_header.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_animsys.h" diff --git a/source/blender/editors/space_nla/nla_ops.c b/source/blender/editors/space_nla/nla_ops.c index 6c940f32c24..d210016d201 100644 --- a/source/blender/editors/space_nla/nla_ops.c +++ b/source/blender/editors/space_nla/nla_ops.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_animsys.h" diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index 7c8f2aef9d0..801434c4794 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -41,7 +41,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_animsys.h" diff --git a/source/blender/editors/space_nla/space_nla.c b/source/blender/editors/space_nla/space_nla.c index 5f2f75b7b6f..1e35e9122e6 100644 --- a/source/blender/editors/space_nla/space_nla.c +++ b/source/blender/editors/space_nla/space_nla.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_animsys.h" @@ -432,6 +432,13 @@ static void nla_main_area_listener(ARegion *ar, wmNotifier *wmn) break; } break; + case NC_NODE: + switch(wmn->action) { + case NA_EDITED: + ED_region_tag_redraw(ar); + break; + } + break; default: if(wmn->data==ND_KEYS) ED_region_tag_redraw(ar); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 42304e0daa3..3cc06b7bbb9 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -32,7 +32,7 @@ #include <string.h> #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_ID.h" #include "DNA_node_types.h" @@ -94,48 +94,6 @@ #include "node_intern.h" - -/* autocomplete callback for buttons */ -static void autocomplete_vcol(bContext *C, char *str, void *arg_v) -{ - Mesh *me; - CustomDataLayer *layer; - AutoComplete *autocpl; - int a; - - if(str[0]==0) - return; - - autocpl= autocomplete_begin(str, 32); - - /* search if str matches the beginning of name */ - for(me= G.main->mesh.first; me; me=me->id.next) - for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++) - if(layer->type == CD_MCOL) - autocomplete_do_name(autocpl, layer->name); - - autocomplete_end(autocpl, str); -} - -static int verify_valid_vcol_name(char *str) -{ - Mesh *me; - CustomDataLayer *layer; - int a; - - if(str[0]==0) - return 1; - - /* search if str matches the name */ - for(me= G.main->mesh.first; me; me=me->id.next) - for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++) - if(layer->type == CD_MCOL) - if(strcmp(layer->name, str)==0) - return 1; - - return 0; -} - /* ****************** GENERAL CALLBACKS FOR NODES ***************** */ static void node_ID_title_cb(bContext *C, void *node_v, void *unused_v) @@ -161,7 +119,7 @@ static void node_group_alone_cb(bContext *C, void *node_v, void *unused_v) /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */ -static void node_buts_group(uiLayout *layout, PointerRNA *ptr) +static void node_buts_group(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiBlock *block= uiLayoutAbsoluteBlock(layout); bNode *node= ptr->data; @@ -195,45 +153,33 @@ static void node_buts_group(uiLayout *layout, PointerRNA *ptr) } #endif -static void node_buts_value(uiLayout *layout, PointerRNA *ptr) +static void node_buts_value(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - bNodeSocket *sock= node->outputs.first; /* first socket stores value */ + PointerRNA sockptr; + PropertyRNA *prop; + + /* first socket stores value */ + prop = RNA_struct_find_property(ptr, "outputs"); + RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr); - uiDefButF(block, NUM, B_NODE_EXEC, "", - (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, 20, - sock->ns.vec, sock->ns.min, sock->ns.max, 10, 2, ""); + uiItemR(layout, "", 0, &sockptr, "default_value", 0); } -static void node_buts_rgb(uiLayout *layout, PointerRNA *ptr) +static void node_buts_rgb(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - bNodeSocket *sock= node->outputs.first; /* first socket stores value */ - - if(sock) { - /* enforce square box drawing */ - uiBlockSetEmboss(block, UI_EMBOSSP); - - uiDefButF(block, HSVCUBE, B_NODE_EXEC, "", - (short)butr->xmin, (short)butr->ymin, butr->xmax-butr->xmin, 12, - sock->ns.vec, 0.0f, 1.0f, 3, 0, ""); - uiDefButF(block, HSVCUBE, B_NODE_EXEC, "", - (short)butr->xmin, (short)butr->ymin+15, butr->xmax-butr->xmin, butr->xmax-butr->xmin -15 -15, - sock->ns.vec, 0.0f, 1.0f, 2, 0, ""); - uiDefButF(block, COL, B_NOP, "", - (short)butr->xmin, (short)butr->ymax-12, butr->xmax-butr->xmin, 12, - sock->ns.vec, 0.0, 0.0, -1, 0, ""); - /* the -1 above prevents col button to popup a color picker */ - - uiBlockSetEmboss(block, UI_EMBOSS); - } + uiLayout *col; + PointerRNA sockptr; + PropertyRNA *prop; + + /* first socket stores value */ + prop = RNA_struct_find_property(ptr, "outputs"); + RNA_property_collection_lookup_int(ptr, prop, 0, &sockptr); + + col = uiLayoutColumn(layout, 0); + uiItemR(col, "", 0, &sockptr, "default_value", 0); } -static void node_buts_mix_rgb(uiLayout *layout, PointerRNA *ptr) +static void node_buts_mix_rgb(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *row; @@ -245,7 +191,7 @@ static void node_buts_mix_rgb(uiLayout *layout, PointerRNA *ptr) uiItemR(row, "", ICON_IMAGE_RGB_ALPHA, ptr, "alpha", 0); } -static void node_buts_time(uiLayout *layout, PointerRNA *ptr) +static void node_buts_time(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *row; #if 0 @@ -267,18 +213,12 @@ static void node_buts_time(uiLayout *layout, PointerRNA *ptr) uiItemR(row, "End", 0, ptr, "end", 0); } -static void node_buts_valtorgb(uiLayout *layout, PointerRNA *ptr) +static void node_buts_colorramp(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - - if(node->storage) { - uiBlockColorbandButtons(block, node->storage, butr, B_NODE_EXEC); - } + uiTemplateColorRamp(layout, ptr, "color_ramp", 0); } -static void node_buts_curvevec(uiLayout *layout, PointerRNA *ptr) +static void node_buts_curvevec(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0); } @@ -289,7 +229,7 @@ void node_curvemap_sample(float *col) _sample_col= col; } -static void node_buts_curvecol(uiLayout *layout, PointerRNA *ptr) +static void node_buts_curvecol(uiLayout *layout, bContext *C, PointerRNA *ptr) { bNode *node= ptr->data; CurveMapping *cumap= node->storage; @@ -304,7 +244,7 @@ static void node_buts_curvecol(uiLayout *layout, PointerRNA *ptr) uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0); } -static void node_buts_normal(uiLayout *layout, PointerRNA *ptr) +static void node_buts_normal(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiBlock *block= uiLayoutAbsoluteBlock(layout); bNode *node= ptr->data; @@ -377,7 +317,7 @@ static void node_dynamic_update_cb(bContext *C, void *ntree_v, void *node_v) // XXX BIF_preview_changed(ID_MA); } -static void node_buts_texture(uiLayout *layout, PointerRNA *ptr) +static void node_buts_texture(uiLayout *layout, bContext *C, PointerRNA *ptr) { bNode *node= ptr->data; @@ -396,7 +336,7 @@ static void node_buts_texture(uiLayout *layout, PointerRNA *ptr) } } -static void node_buts_math(uiLayout *layout, PointerRNA *ptr) +static void node_buts_math(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "operation", 0); } @@ -429,223 +369,62 @@ static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v) node->menunr= 0; } -static void node_mat_alone_cb(bContext *C, void *node_v, void *unused) -{ - bNode *node= node_v; - - node->id= (ID *)copy_material((Material *)node->id); - - //BIF_undo_push("Single user material"); - // allqueue(REDRAWBUTSSHADING, 0); - // allqueue(REDRAWNODE, 0); - // allqueue(REDRAWOOPS, 0); -} - -static void node_browse_mat_cb(bContext *C, void *ntree_v, void *node_v) +static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNodeTree *ntree= ntree_v; - bNode *node= node_v; + bNode *node= ptr->data; + uiLayout *col; - if(node->menunr<1) return; + uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL); - if(node->menunr==32767) { /* code for Add New */ - if(node->id) { - /* make copy, but make sure it doesnt have the node tag nor nodes */ - Material *ma= (Material *)node->id; - ma->id.us--; - ma= copy_material(ma); - ma->use_nodes= 0; - if(ma->nodetree) { - ntreeFreeTree(ma->nodetree); - MEM_freeN(ma->nodetree); - } - ma->nodetree= NULL; - node->id= (ID *)ma; - } - else node->id= (ID *)add_material("MatNode"); - } - else { - if(node->id) node->id->us--; - node->id= BLI_findlink(&G.main->mat, node->menunr-1); - id_us_plus(node->id); - } - BLI_strncpy(node->name, node->id->name+2, 21); - - nodeSetActive(ntree, node); - - // allqueue(REDRAWBUTSSHADING, 0); - // allqueue(REDRAWNODE, 0); - // XXX BIF_preview_changed(ID_MA); - - node->menunr= 0; -} - -static void node_new_mat_cb(bContext *C, void *ntree_v, void *node_v) -{ - bNodeTree *ntree= ntree_v; - bNode *node= node_v; + if(!node->id) return; - node->id= (ID *)add_material("MatNode"); - BLI_strncpy(node->name, node->id->name+2, 21); - - nodeSetActive(ntree, node); - - // allqueue(REDRAWBUTSSHADING, 0); - // allqueue(REDRAWNODE, 0); - // XXX BIF_preview_changed(ID_MA); - -} - -static void node_texmap_cb(bContext *C, void *texmap_v, void *unused_v) -{ - init_mapping(texmap_v); + col= uiLayoutColumn(layout, 0); + uiItemR(col, NULL, 0, ptr, "diffuse", 0); + uiItemR(col, NULL, 0, ptr, "specular", 0); + uiItemR(col, NULL, 0, ptr, "invert_normal", 0); } -static void node_shader_buts_material(uiLayout *layout, PointerRNA *ptr) +static void node_shader_buts_mapping(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - bNodeTree *ntree= ptr->id.data; - rctf *butr= &node->butr; - uiBut *bt; - short dx= (short)((butr->xmax-butr->xmin)/3.0f), has_us= (node->id && node->id->us>1); - short dy= (short)butr->ymin; - char *strp; - - /* WATCH IT: we use this callback in material buttons, but then only want first row */ - if(butr->ymax-butr->ymin > 21.0f) dy+= 19; - - uiBlockBeginAlign(block); - /* XXX - if(node->id==NULL) uiBlockSetCol(block, TH_REDALERT); - else if(has_us) uiBlockSetCol(block, TH_BUT_SETTING1); - else uiBlockSetCol(block, TH_BUT_SETTING2); - */ + uiLayout *row; - /* browse button */ - IDnames_to_pupstring(&strp, NULL, "ADD NEW %x32767", &(G.main->mat), NULL, NULL); - node->menunr= 0; - bt= uiDefButS(block, MENU, B_NOP, strp, - butr->xmin, dy, 19, 19, - &node->menunr, 0, 0, 0, 0, "Browses existing choices or adds NEW"); - uiButSetFunc(bt, node_browse_mat_cb, ntree, node); - if(strp) MEM_freeN(strp); + uiItemL(layout, "Location:", 0); + row= uiLayoutRow(layout, 1); + uiItemR(row, "", 0, ptr, "location", 0); - /* Add New button */ - if(node->id==NULL) { - bt= uiDefBut(block, BUT, B_NOP, "Add New", - butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19, - NULL, 0.0, 0.0, 0, 0, "Add new Material"); - uiButSetFunc(bt, node_new_mat_cb, ntree, node); - } - else { - /* name button */ - short width= (short)(butr->xmax-butr->xmin-19.0f - (has_us?19.0f:0.0f)); - bt= uiDefBut(block, TEX, B_NOP, "MA:", - butr->xmin+19, dy, width, 19, - node->id->name+2, 0.0, 19.0, 0, 0, "Material name"); - uiButSetFunc(bt, node_ID_title_cb, node, NULL); - - /* user amount */ - if(has_us) { - char str1[32]; - sprintf(str1, "%d", node->id->us); - bt= uiDefBut(block, BUT, B_NOP, str1, - butr->xmax-19, dy, 19, 19, - NULL, 0, 0, 0, 0, "Displays number of users. Click to make a single-user copy."); - uiButSetFunc(bt, node_mat_alone_cb, node, NULL); - } - - /* WATCH IT: we use this callback in material buttons, but then only want first row */ - if(butr->ymax-butr->ymin > 21.0f) { - /* node options */ - uiDefButBitS(block, TOG, SH_NODE_MAT_DIFF, B_NODE_EXEC, "Diff", - butr->xmin, butr->ymin, dx, 19, - &node->custom1, 0, 0, 0, 0, "Material Node outputs Diffuse"); - uiDefButBitS(block, TOG, SH_NODE_MAT_SPEC, B_NODE_EXEC, "Spec", - butr->xmin+dx, butr->ymin, dx, 19, - &node->custom1, 0, 0, 0, 0, "Material Node outputs Specular"); - uiDefButBitS(block, TOG, SH_NODE_MAT_NEG, B_NODE_EXEC, "Neg Normal", - butr->xmax-dx, butr->ymin, dx, 19, - &node->custom1, 0, 0, 0, 0, "Material Node uses inverted Normal"); - } - } - uiBlockEndAlign(block); -} - -static void node_shader_buts_mapping(uiLayout *layout, PointerRNA *ptr) -{ - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - TexMapping *texmap= node->storage; - short dx= (short)((butr->xmax-butr->xmin)/7.0f); - short dy= (short)(butr->ymax-19); + uiItemL(layout, "Rotation:", 0); + row= uiLayoutRow(layout, 1); + uiItemR(row, "", 0, ptr, "rotation", 0); - uiBlockSetFunc(block, node_texmap_cb, texmap, NULL); /* all buttons get this */ + uiItemL(layout, "Scale:", 0); + row= uiLayoutRow(layout, 1); + uiItemR(row, "", 0, ptr, "scale", 0); - uiBlockBeginAlign(block); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->loc, -1000.0f, 1000.0f, 10, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->loc+1, -1000.0f, 1000.0f, 10, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->loc+2, -1000.0f, 1000.0f, 10, 2, ""); - dy-= 19; - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->rot, -1000.0f, 1000.0f, 1000, 1, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->rot+1, -1000.0f, 1000.0f, 1000, 1, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->rot+2, -1000.0f, 1000.0f, 1000, 1, ""); - dy-= 19; - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->size, -1000.0f, 1000.0f, 10, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->size+1, -1000.0f, 1000.0f, 10, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->size+2, -1000.0f, 1000.0f, 10, 2, ""); - dy-= 25; - uiBlockBeginAlign(block); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->min, -10.0f, 10.0f, 100, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->min+1, -10.0f, 10.0f, 100, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->min+2, -10.0f, 10.0f, 100, 2, ""); - dy-= 19; - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+dx, dy, 2*dx, 19, texmap->max, -10.0f, 10.0f, 10, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+3*dx, dy, 2*dx, 19, texmap->max+1, -10.0f, 10.0f, 10, 2, ""); - uiDefButF(block, NUM, B_NODE_EXEC, "", butr->xmin+5*dx, dy, 2*dx, 19, texmap->max+2, -10.0f, 10.0f, 10, 2, ""); - uiBlockEndAlign(block); + row= uiLayoutRow(layout, 1); + uiItemR(row, "Min", 0, ptr, "clamp_minimum", 0); + uiItemR(row, "", 0, ptr, "minimum", 0); - /* labels/options */ + row= uiLayoutRow(layout, 1); + uiItemR(row, "Max", 0, ptr, "clamp_maximum", 0); + uiItemR(row, "", 0, ptr, "maximum", 0); - dy= (short)(butr->ymax-19); - uiDefBut(block, LABEL, B_NOP, "Loc", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, ""); - dy-= 19; - uiDefBut(block, LABEL, B_NOP, "Rot", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, ""); - dy-= 19; - uiDefBut(block, LABEL, B_NOP, "Size", butr->xmin, dy, dx, 19, NULL, 0.0f, 0.0f, 0, 0, ""); - dy-= 25; - uiDefButBitI(block, TOG, TEXMAP_CLIP_MIN, B_NODE_EXEC, "Min", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, ""); - dy-= 19; - uiDefButBitI(block, TOG, TEXMAP_CLIP_MAX, B_NODE_EXEC, "Max", butr->xmin, dy, dx-4, 19, &texmap->flag, 0.0f, 0.0f, 0, 0, ""); } -static void node_shader_buts_vect_math(uiLayout *layout, PointerRNA *ptr) +static void node_shader_buts_vect_math(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "operation", 0); } -static void node_shader_buts_geometry(uiLayout *layout, PointerRNA *ptr) +static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - uiBut *but; - NodeGeometry *ngeo= (NodeGeometry*)node->storage; - - // XXX if(!verify_valid_uv_name(ngeo->uvname)) - // XXX uiBlockSetCol(block, TH_REDALERT); - but= uiDefBut(block, TEX, B_NODE_EXEC, "UV:", butr->xmin, butr->ymin+20, butr->xmax-butr->xmin, 20, ngeo->uvname, 0, 31, 0, 0, "Set name of UV layer to use, default is active UV layer"); - // XXX uiButSetCompleteFunc(but, autocomplete_uv, NULL); - - if(!verify_valid_vcol_name(ngeo->colname)); -// uiBlockSetCol(block, TH_REDALERT); - but= uiDefBut(block, TEX, B_NODE_EXEC, "Col:", butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, ngeo->colname, 0, 31, 0, 0, "Set name of vertex color layer to use, default is active vertex color layer"); - uiButSetCompleteFunc(but, autocomplete_vcol, NULL); + uiLayout *col; + + col= uiLayoutColumn(layout, 0); + uiItemR(col, "UV", 0, ptr, "uv_layer", 0); + uiItemR(col, "VCol", 0, ptr, "color_layer", 0); } -static void node_shader_buts_dynamic(uiLayout *layout, PointerRNA *ptr) +static void node_shader_buts_dynamic(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiBlock *block= uiLayoutAbsoluteBlock(layout); bNode *node= ptr->data; @@ -718,7 +497,7 @@ static void node_shader_set_butfunc(bNodeType *ntype) ntype->uifunc= node_buts_mix_rgb; break; case SH_NODE_VALTORGB: - ntype->uifunc= node_buts_valtorgb; + ntype->uifunc= node_buts_colorramp; break; case SH_NODE_MATH: ntype->uifunc= node_buts_math; @@ -768,283 +547,72 @@ static void node_active_cb(bContext *C, void *ntree_v, void *node_v) { nodeSetActive(ntree_v, node_v); } -static void node_image_type_cb(bContext *C, void *node_v, void *unused) -{ - - // allqueue(REDRAWNODE, 1); -} -static char *node_image_type_pup(void) +static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { - char *str= MEM_mallocN(256, "image type pup"); - int a; - - str[0]= 0; - - a= sprintf(str, "Image Type %%t|"); - a+= sprintf(str+a, " Image %%x%d %%i%d|", IMA_SRC_FILE, ICON_IMAGE_DATA); - a+= sprintf(str+a, " Movie %%x%d %%i%d|", IMA_SRC_MOVIE, ICON_SEQUENCE); - a+= sprintf(str+a, " Sequence %%x%d %%i%d|", IMA_SRC_SEQUENCE, ICON_IMAGE_COL); - a+= sprintf(str+a, " Generated %%x%d %%i%d", IMA_SRC_GENERATED, ICON_BLANK1); + uiLayout *col; + bNode *node= ptr->data; + PointerRNA imaptr; + PropertyRNA *prop; - return str; -} - -/* copy from buttons_shading.c */ -static char *layer_menu(RenderResult *rr) -{ - RenderLayer *rl; - int len= 40 + 40*BLI_countlist(&rr->layers); - short a, nr; - char *str= MEM_callocN(len, "menu layers"); - - strcpy(str, "Layer %t"); - a= strlen(str); - for(nr=0, rl= rr->layers.first; rl; rl= rl->next, nr++) { - a+= sprintf(str+a, "|%s %%x%d", rl->name, nr); - } + uiTemplateID(layout, C, ptr, "image", NULL, "IMAGE_OT_open", NULL); - return str; -} - -static void image_layer_cb(bContext *C, void *ima_v, void *iuser_v) -{ - Scene *scene= CTX_data_scene(C); + if(!node->id) return; - ntreeCompositForceHidden(scene->nodetree, scene); - BKE_image_multilayer_index(ima_v, iuser_v); - // allqueue(REDRAWNODE, 0); -} - -static void node_composit_buts_image(uiLayout *layout, PointerRNA *ptr) -{ - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - bNodeTree *ntree= ptr->id.data; - rctf *butr= &node->butr; - ImageUser *iuser= node->storage; - uiBut *bt; - short dy= (short)butr->ymax-19; - char *strp; + prop = RNA_struct_find_property(ptr, "image"); + if (!prop || RNA_property_type(prop) != PROP_POINTER) return; + imaptr= RNA_property_pointer_get(ptr, prop); - uiBlockBeginAlign(block); + col= uiLayoutColumn(layout, 0); - /* browse button */ - IMAnames_to_pupstring(&strp, NULL, "LOAD NEW %x32767", &(G.main->image), NULL, NULL); - node->menunr= 0; - bt= uiDefButS(block, MENU, B_NOP, strp, - butr->xmin, dy, 19, 19, - &node->menunr, 0, 0, 0, 0, "Browses existing choices"); - uiButSetFunc(bt, node_browse_image_cb, ntree, node); - if(strp) MEM_freeN(strp); + uiItemR(col, NULL, 0, &imaptr, "source", 0); - /* Add New button */ - if(node->id==NULL) { - bt= uiDefBut(block, BUT, B_NODE_LOADIMAGE, "Load New", - butr->xmin+19, dy, (short)(butr->xmax-butr->xmin-19.0f), 19, - NULL, 0.0, 0.0, 0, 0, "Add new Image"); - uiButSetFunc(bt, node_active_cb, ntree, node); - } - else { - /* name button + type */ - Image *ima= (Image *)node->id; - short xmin= (short)butr->xmin, xmax= (short)butr->xmax; - short width= xmax - xmin - 45; - short icon= ICON_IMAGE_DATA; - - if(ima->source==IMA_SRC_MOVIE) icon= ICON_SEQUENCE; - else if(ima->source==IMA_SRC_SEQUENCE) icon= ICON_IMAGE_COL; - else if(ima->source==IMA_SRC_GENERATED) icon= ICON_BLANK1; - - bt= uiDefBut(block, TEX, B_NOP, "IM:", - xmin+19, dy, width, 19, - node->id->name+2, 0.0, 19.0, 0, 0, "Image name"); - uiButSetFunc(bt, node_ID_title_cb, node, NULL); - - /* buffer type option */ - strp= node_image_type_pup(); - bt= uiDefIconTextButS(block, MENU, B_NOP, icon, strp, - xmax-26, dy, 26, 19, - &ima->source, 0.0, 19.0, 0, 0, "Image type"); - uiButSetFunc(bt, node_image_type_cb, node, ima); - MEM_freeN(strp); - - if( ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) ) { - width= (xmax-xmin)/2; - - dy-= 19; - uiDefButI(block, NUM, B_NODE_EXEC, "Frs:", - xmin, dy, width, 19, - &iuser->frames, 1.0, MAXFRAMEF, 0, 0, "Amount of images used in animation"); - uiDefButI(block, NUM, B_NODE_EXEC, "SFra:", - xmin+width, dy, width, 19, - &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Start frame of animation"); - dy-= 19; - uiDefButI(block, NUM, B_NODE_EXEC, "Offs:", - xmin, dy, width, 19, - &iuser->offset, -MAXFRAMEF, MAXFRAMEF, 0, 0, "Offsets the number of the frame to use in the animation"); - uiDefButS(block, TOG, B_NODE_EXEC, "Cycl", - xmin+width, dy, width-20, 19, - &iuser->cycl, 0.0, 0.0, 0, 0, "Make animation go cyclic"); - uiDefIconButBitS(block, TOG, IMA_ANIM_ALWAYS, B_NODE_EXEC, ICON_AUTO, - xmax-20, dy, 20, 19, - &iuser->flag, 0.0, 0.0, 0, 0, "Always refresh Image on frame changes"); - } - if( ima->type==IMA_TYPE_MULTILAYER && ima->rr) { - RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer); - if(rl) { - width= (xmax-xmin); - dy-= 19; - strp= layer_menu(ima->rr); - bt= uiDefButS(block, MENU, B_NODE_EXEC, strp, - xmin, dy, width, 19, - &iuser->layer, 0.0, 10000.0, 0, 0, "Layer"); - uiButSetFunc(bt, image_layer_cb, ima->rr, node->storage); - MEM_freeN(strp); - } - } - } - - if(node->id) { - /* for each draw we test for anim refresh event */ - if(iuser->flag & IMA_ANIM_REFRESHED) { - iuser->flag &= ~IMA_ANIM_REFRESHED; - // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC); XXX - } + if (ELEM(RNA_enum_get(&imaptr, "source"), IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { + col= uiLayoutColumn(layout, 1); + uiItemR(col, NULL, 0, ptr, "frames", 0); + uiItemR(col, NULL, 0, ptr, "start", 0); + uiItemR(col, NULL, 0, ptr, "offset", 0); + uiItemR(col, NULL, 0, ptr, "cyclic", 0); + uiItemR(col, NULL, 0, ptr, "auto_refresh", UI_ITEM_R_ICON_ONLY); } -} -/* if we use render layers from other scene, we make a nice title */ -static void set_render_layers_title(bContext *C, void *node_v, void *unused) -{ - bNode *node= node_v; - Scene *sce; - SceneRenderLayer *srl; - char str[64]; - - if(node->id) { - BLI_strncpy(str, node->id->name+2, 21); - strcat(str, "|"); - sce= (Scene *)node->id; - } - else { - str[0]= 0; - sce= CTX_data_scene(C); - } - srl= BLI_findlink(&sce->r.layers, node->custom1); - if(srl==NULL) { - node->custom1= 0; - srl= sce->r.layers.first; - } + col= uiLayoutColumn(layout, 0); - strcat(str, srl->name); - BLI_strncpy(node->name, str, 32); + if (RNA_enum_get(&imaptr, "type")== IMA_TYPE_MULTILAYER) + uiItemR(col, NULL, 0, ptr, "layer", 0); } -static char *scene_layer_menu(Scene *sce) +static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr) { - SceneRenderLayer *srl; - int len= 40 + 40*BLI_countlist(&sce->r.layers); - short a, nr; - char *str= MEM_callocN(len, "menu layers"); - - strcpy(str, "Active Layer %t"); - a= strlen(str); - for(nr=0, srl= sce->r.layers.first; srl; srl= srl->next, nr++) { - a+= sprintf(str+a, "|%s %%x%d", srl->name, nr); - } - - return str; -} + bNode *node= ptr->data; + uiLayout *col; -static void node_browse_scene_cb(bContext *C, void *ntree_v, void *node_v) -{ - bNodeTree *ntree= ntree_v; - bNode *node= node_v; - Scene *sce; + uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL); - if(node->menunr<1) return; - - if(node->id) { - node->id->us--; - node->id= NULL; - } - sce= BLI_findlink(&G.main->scene, node->menunr-1); - node->id= &sce->id; - id_us_plus(node->id); - - set_render_layers_title(C, node, NULL); - nodeSetActive(ntree, node); - - // allqueue(REDRAWBUTSSHADING, 0); - // allqueue(REDRAWNODE, 0); - NodeTagChanged(ntree, node); + if(!node->id) return; - node->menunr= 0; -} - - -static void node_composit_buts_renderlayers(uiLayout *layout, PointerRNA *ptr) -{ - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - bNodeTree *ntree= ptr->id.data; - rctf *butr= &node->butr; - - if(node->id) { - Scene *scene= (Scene *)node->id; - uiBut *bt; - char *strp; - - /* browse button scene */ - uiBlockBeginAlign(block); - IDnames_to_pupstring(&strp, NULL, "", &(G.main->scene), NULL, NULL); - node->menunr= 0; - bt= uiDefButS(block, MENU, B_NOP, strp, - butr->xmin, butr->ymin, 20, 19, - &node->menunr, 0, 0, 0, 0, "Browse Scene to use RenderLayer from"); - uiButSetFunc(bt, node_browse_scene_cb, ntree, node); - if(strp) MEM_freeN(strp); - - /* browse button layer */ - strp= scene_layer_menu(node->id?(Scene *)node->id:scene); - if(node->id) - bt= uiDefIconTextButS(block, MENU, B_NODE_EXEC, ICON_RENDERLAYERS, strp, - butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19, - &node->custom1, 0, 0, 0, 0, "Choose Render Layer"); - else - bt= uiDefButS(block, MENU, B_NODE_EXEC, strp, - butr->xmin+20, butr->ymin, (butr->xmax-butr->xmin)-40, 19, - &node->custom1, 0, 0, 0, 0, "Choose Render Layer"); - uiButSetFunc(bt, set_render_layers_title, node, NULL); - MEM_freeN(strp); - - /* re-render */ - /* uses custom2, not the best implementation of the world... but we need it to work now :) */ - bt= uiDefIconButS(block, TOG, B_NODE_EXEC, ICON_SCENE, - butr->xmax-20, butr->ymin, 20, 19, - &node->custom2, 0, 0, 0, 0, "Re-render this Layer"); - - } + col= uiLayoutColumn(layout, 0); + uiItemR(col, "", 0, ptr, "layer", 0); + + /* XXX Missing 're-render this layer' button - needs completely new implementation */ } -static void node_composit_buts_blur(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_blur(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; col= uiLayoutColumn(layout, 0); uiItemR(col, "", 0, ptr, "filter_type", 0); - /* Only for "Fast Gaussian" */ - if (RNA_enum_get(ptr, "filter_type")!= 7) { + if (RNA_enum_get(ptr, "filter_type")!= R_FILTER_FAST_GAUSS) { uiItemR(col, NULL, 0, ptr, "bokeh", 0); uiItemR(col, NULL, 0, ptr, "gamma", 0); } uiItemR(col, NULL, 0, ptr, "relative", 0); col= uiLayoutColumn(layout, 1); - if (RNA_boolean_get(ptr, "relative")== 1) { + if (RNA_boolean_get(ptr, "relative")) { uiItemR(col, "X", 0, ptr, "factor_x", 0); uiItemR(col, "Y", 0, ptr, "factor_y", 0); } @@ -1054,7 +622,7 @@ static void node_composit_buts_blur(uiLayout *layout, PointerRNA *ptr) } } -static void node_composit_buts_dblur(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_dblur(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1078,7 +646,7 @@ static void node_composit_buts_dblur(uiLayout *layout, PointerRNA *ptr) uiItemR(layout, NULL, 0, ptr, "zoom", 0); } -static void node_composit_buts_bilateralblur(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1088,8 +656,7 @@ static void node_composit_buts_bilateralblur(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "sigma_space", 0); } -/* qdn: defocus node */ -static void node_composit_buts_defocus(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_defocus(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *sub, *col; @@ -1106,15 +673,13 @@ static void node_composit_buts_defocus(uiLayout *layout, PointerRNA *ptr) uiItemR(layout, NULL, 0, ptr, "max_blur", 0); uiItemR(layout, NULL, 0, ptr, "threshold", 0); - - // Preview + col = uiLayoutColumn(layout, 0); uiItemR(col, NULL, 0, ptr, "preview", 0); sub = uiLayoutColumn(col, 0); uiLayoutSetActive(sub, RNA_boolean_get(ptr, "preview")); uiItemR(sub, NULL, 0, ptr, "samples", 0); - // Z-Buffer col = uiLayoutColumn(layout, 0); uiItemR(col, NULL, 0, ptr, "use_zbuffer", 0); sub = uiLayoutColumn(col, 0); @@ -1123,7 +688,7 @@ static void node_composit_buts_defocus(uiLayout *layout, PointerRNA *ptr) } /* qdn: glare node */ -static void node_composit_buts_glare(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_glare(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "glare_type", 0); uiItemR(layout, "", 0, ptr, "quality", 0); @@ -1153,8 +718,7 @@ static void node_composit_buts_glare(uiLayout *layout, PointerRNA *ptr) } } -/* qdn: tonemap node */ -static void node_composit_buts_tonemap(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_tonemap(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1173,8 +737,7 @@ static void node_composit_buts_tonemap(uiLayout *layout, PointerRNA *ptr) } } -/* qdn: lens distortion node */ -static void node_composit_buts_lensdist(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_lensdist(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1187,7 +750,7 @@ static void node_composit_buts_lensdist(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "fit", 0); } -static void node_composit_buts_vecblur(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_vecblur(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1203,17 +766,17 @@ static void node_composit_buts_vecblur(uiLayout *layout, PointerRNA *ptr) uiItemR(layout, NULL, 0, ptr, "curved", 0); } -static void node_composit_buts_filter(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_filter(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "filter_type", 0); } -static void node_composit_buts_flip(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_flip(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "axis", 0); } -static void node_composit_buts_crop(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_crop(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1226,7 +789,7 @@ static void node_composit_buts_crop(uiLayout *layout, PointerRNA *ptr) uiItemR(col, "Down", 0, ptr, "y2", 0); } -static void node_composit_buts_splitviewer(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_splitviewer(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *row, *col; @@ -1236,7 +799,7 @@ static void node_composit_buts_splitviewer(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "factor", 0); } -static void node_composit_buts_map_value(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_map_value(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *sub, *col; @@ -1257,18 +820,16 @@ static void node_composit_buts_map_value(uiLayout *layout, PointerRNA *ptr) uiItemR(sub, "", 0, ptr, "max", 0); } -static void node_composit_buts_alphaover(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_alphaover(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; col =uiLayoutColumn(layout, 1); - /* alpha type */ uiItemR(col, NULL, 0, ptr, "convert_premul", 0); - /* mix factor */ uiItemR(col, NULL, 0, ptr, "premul", 0); } -static void node_composit_buts_hue_sat(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_hue_sat(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1278,12 +839,12 @@ static void node_composit_buts_hue_sat(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "val", UI_ITEM_R_SLIDER); } -static void node_composit_buts_dilateerode(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_dilateerode(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, NULL, 0, ptr, "distance", 0); } -static void node_composit_buts_diff_matte(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_diff_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1292,7 +853,7 @@ static void node_composit_buts_diff_matte(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "falloff", UI_ITEM_R_SLIDER); } -static void node_composit_buts_distance_matte(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_distance_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1301,7 +862,7 @@ static void node_composit_buts_distance_matte(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "falloff", UI_ITEM_R_SLIDER); } -static void node_composit_buts_color_spill(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_color_spill(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *row, *col; @@ -1311,7 +872,7 @@ static void node_composit_buts_color_spill(uiLayout *layout, PointerRNA *ptr) uiItemR(row, NULL, 0, ptr, "channel", UI_ITEM_R_EXPAND); } -static void node_composit_buts_chroma_matte(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1325,7 +886,7 @@ static void node_composit_buts_chroma_matte(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "shadow_adjust", UI_ITEM_R_SLIDER); } -static void node_composit_buts_color_matte(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_color_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1335,54 +896,22 @@ static void node_composit_buts_color_matte(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "v", UI_ITEM_R_SLIDER); } -static void node_composit_buts_channel_matte(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_channel_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col, *row; - - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; -// short sx= (butr->xmax-butr->xmin)/4; - short cx= (butr->xmax-butr->xmin)/3; -// NodeChroma *c=node->storage; - char *c1, *c2, *c3; - /*color space selector*/ row= uiLayoutRow(layout, 0); uiItemR(row, NULL, 0, ptr, "color_space", UI_ITEM_R_EXPAND); - if (node->custom1==1) { - c1="R"; c2="G"; c3="B"; - } - else if(node->custom1==2){ - c1="H"; c2="S"; c3="V"; - } - else if(node->custom1==3){ - c1="Y"; c2="U"; c3="V"; - } - else { // if(node->custom1==4){ - c1="Y"; c2="Cb"; c3="Cr"; - } - - /*channel selector */ row= uiLayoutRow(layout, 0); - uiBlockBeginAlign(block); - uiDefButS(block, ROW, B_NODE_EXEC, c1, - butr->xmin,butr->ymin+40,cx,20,&node->custom2,1, 1, 0, 0, "Channel 1"); - uiDefButS(block, ROW, B_NODE_EXEC, c2, - butr->xmin+cx,butr->ymin+40,cx,20,&node->custom2,1, 2, 0, 0, "Channel 2"); - uiDefButS(block, ROW, B_NODE_EXEC, c3, - butr->xmin+cx+cx,butr->ymin+40,cx,20,&node->custom2, 1, 3, 0, 0, "Channel 3"); - uiBlockEndAlign(block); + uiItemR(row, NULL, 0, ptr, "channel", UI_ITEM_R_EXPAND); - /*tolerance sliders */ col =uiLayoutColumn(layout, 1); uiItemR(col, NULL, 0, ptr, "high", UI_ITEM_R_SLIDER); uiItemR(col, NULL, 0, ptr, "low", UI_ITEM_R_SLIDER); - } -static void node_composit_buts_luma_matte(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_luma_matte(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1391,50 +920,17 @@ static void node_composit_buts_luma_matte(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "low", UI_ITEM_R_SLIDER); } -static void node_composit_buts_map_uv(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_map_uv(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, NULL, 0, ptr, "alpha", 0); } -static void node_composit_buts_id_mask(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_id_mask(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - - uiDefButS(block, NUM, B_NODE_EXEC, "ID:", - butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, - &node->custom1, 0, 10000, 0, 0, "Pass Index number to convert to Alpha"); + uiItemR(layout, NULL, 0, ptr, "index", 0); } -/* allocate sufficient! */ -/* -static void node_imagetype_string(char *str) -{ - str += sprintf(str, "Save Image as: %%t|"); - str += sprintf(str, "Targa %%x%d|", R_TARGA); - str += sprintf(str, "Targa Raw %%x%d|", R_RAWTGA); - str += sprintf(str, "PNG %%x%d|", R_PNG); - str += sprintf(str, "BMP %%x%d|", R_BMP); - str += sprintf(str, "Jpeg %%x%d|", R_JPEG90); - str += sprintf(str, "Iris %%x%d|", R_IRIS); - str += sprintf(str, "Radiance HDR %%x%d|", R_RADHDR); - str += sprintf(str, "Cineon %%x%d|", R_CINEON); - str += sprintf(str, "DPX %%x%d|", R_DPX); - str += sprintf(str, "OpenEXR %%x%d", R_OPENEXR); -} -*/ - -/*static void node_set_image_cb(bContext *C, void *ntree_v, void *node_v) -{ - bNodeTree *ntree= ntree_v; - bNode *node= node_v; - - nodeSetActive(ntree, node); -} -*/ - -static void node_composit_buts_file_output(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_file_output(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col, *row; @@ -1456,36 +952,12 @@ static void node_composit_buts_file_output(uiLayout *layout, PointerRNA *ptr) uiItemR(row, "End", 0, ptr, "end_frame", 0); } -static void node_scale_cb(bContext *C, void *node_v, void *unused_v) +static void node_composit_buts_scale(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node= node_v; - bNodeSocket *nsock; - - /* check the 2 inputs, and set them to reasonable values */ - for(nsock= node->inputs.first; nsock; nsock= nsock->next) { - if(ELEM(node->custom1, CMP_SCALE_RELATIVE, CMP_SCALE_SCENEPERCENT)) - nsock->ns.vec[0]= 1.0; - else { - if(nsock->next==NULL) - nsock->ns.vec[0]= (float)CTX_data_scene(C)->r.ysch; - else - nsock->ns.vec[0]= (float)CTX_data_scene(C)->r.xsch; - } - } -} - -static void node_composit_buts_scale(uiLayout *layout, PointerRNA *ptr) -{ - uiBlock *block= uiLayoutAbsoluteBlock(layout); - bNode *node= ptr->data; - rctf *butr= &node->butr; - uiBut *bt= uiDefButS(block, MENU, B_NODE_EXEC, "Relative %x0|Absolute %x1|Scene Size % %x2|", - butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20, - &node->custom1, 0, 0, 0, 0, "Scale new image to absolute pixel size, size relative to the incoming image, or using the 'percent' size of the scene"); - uiButSetFunc(bt, node_scale_cb, node, NULL); + uiItemR(layout, "", 0, ptr, "space", 0); } -static void node_composit_buts_invert(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_invert(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1494,14 +966,14 @@ static void node_composit_buts_invert(uiLayout *layout, PointerRNA *ptr) uiItemR(col, NULL, 0, ptr, "alpha", 0); } -static void node_composit_buts_premulkey(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_premulkey(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "mapping", 0); } -static void node_composit_buts_view_levels(uiLayout *layout, PointerRNA *ptr) +static void node_composit_buts_view_levels(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiItemR(layout, NULL, 0, ptr, "color_space", UI_ITEM_R_EXPAND); + uiItemR(layout, NULL, 0, ptr, "channel", UI_ITEM_R_EXPAND); } /* only once called */ @@ -1541,7 +1013,7 @@ static void node_composit_set_butfunc(bNodeType *ntype) ntype->uifunc= node_buts_mix_rgb; break; case CMP_NODE_VALTORGB: - ntype->uifunc= node_buts_valtorgb; + ntype->uifunc= node_buts_colorramp; break; case CMP_NODE_CROP: ntype->uifunc= node_composit_buts_crop; @@ -1555,19 +1027,15 @@ static void node_composit_set_butfunc(bNodeType *ntype) case CMP_NODE_BILATERALBLUR: ntype->uifunc= node_composit_buts_bilateralblur; break; - /* qdn: defocus node */ case CMP_NODE_DEFOCUS: ntype->uifunc = node_composit_buts_defocus; break; - /* qdn: glare node */ case CMP_NODE_GLARE: ntype->uifunc = node_composit_buts_glare; break; - /* qdn: tonemap node */ case CMP_NODE_TONEMAP: ntype->uifunc = node_composit_buts_tonemap; break; - /* qdn: lens distortion node */ case CMP_NODE_LENSDIST: ntype->uifunc = node_composit_buts_lensdist; break; @@ -1647,7 +1115,7 @@ static void node_composit_set_butfunc(bNodeType *ntype) /* ****************** BUTTON CALLBACKS FOR TEXTURE NODES ***************** */ -static void node_texture_buts_bricks(uiLayout *layout, PointerRNA *ptr) +static void node_texture_buts_bricks(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiLayout *col; @@ -1668,7 +1136,7 @@ static char* noisebasis_menu() return nbmenu; } -static void node_texture_buts_proc(uiLayout *layout, PointerRNA *ptr) +static void node_texture_buts_proc(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiBlock *block= uiLayoutAbsoluteBlock(layout); bNode *node= ptr->data; @@ -1747,7 +1215,7 @@ static void node_texture_buts_proc(uiLayout *layout, PointerRNA *ptr) } } -static void node_texture_buts_image(uiLayout *layout, PointerRNA *ptr) +static void node_texture_buts_image(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiBlock *block= uiLayoutAbsoluteBlock(layout); bNode *node= ptr->data; @@ -1786,7 +1254,7 @@ static void node_texture_buts_image(uiLayout *layout, PointerRNA *ptr) } } -static void node_texture_buts_output(uiLayout *layout, PointerRNA *ptr) +static void node_texture_buts_output(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, "", 0, ptr, "output_name", 0); } @@ -1808,7 +1276,7 @@ static void node_texture_set_butfunc(bNodeType *ntype) break; case TEX_NODE_VALTORGB: - ntype->uifunc = node_buts_valtorgb; + ntype->uifunc = node_buts_colorramp; break; case TEX_NODE_CURVE_RGB: diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c new file mode 100644 index 00000000000..20650812d52 --- /dev/null +++ b/source/blender/editors/space_node/node_buttons.c @@ -0,0 +1,180 @@ +/** + * $Id: + * + * ***** BEGIN GPL 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. + * + * 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) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <string.h> +#include <stdio.h> +#include <math.h> +#include <float.h> + +#include "DNA_ID.h" +#include "DNA_gpencil_types.h" +#include "DNA_node_types.h" +#include "DNA_space_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_userdef_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_blenlib.h" +#include "BLI_rand.h" + +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_idprop.h" +#include "BKE_object.h" +#include "BKE_node.h" +#include "BKE_global.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_utildefines.h" + +#include "BIF_gl.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "ED_gpencil.h" +#include "ED_screen.h" +#include "ED_types.h" +#include "ED_util.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "node_intern.h" // own include + + +/* ******************* node space & buttons ************** */ +#define B_NOP 1 +#define B_REDR 2 + +static void do_node_region_buttons(bContext *C, void *arg, int event) +{ + //SpaceNode *snode= CTX_wm_space_node(C); + + switch(event) { + case B_REDR: + ED_area_tag_redraw(CTX_wm_area(C)); + return; /* no notifier! */ + } +} + +/* poll callback for active node */ +static int active_node_poll(const bContext *C, PanelType *pt) +{ + SpaceNode *snode= CTX_wm_space_node(C); + + // TODO: include check for whether there is an active node... + return (snode && snode->nodetree); +} + +/* active node */ +static void active_node_panel(const bContext *C, Panel *pa) +{ + SpaceNode *snode= CTX_wm_space_node(C); + bNodeTree *ntree= (snode) ? snode->nodetree : NULL; // XXX what's up with edittree then? + bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; + uiLayout *layout= pa->layout; + uiBlock *block; + PointerRNA ptr; + + /* verify pointers, and create RNA pointer for the node */ + if ELEM(NULL, ntree, node) + return; + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + + /* set update callback */ + // xxx is this really needed + block= uiLayoutGetBlock(layout); + uiBlockSetHandleFunc(block, do_node_region_buttons, NULL); + + /* draw this node's name, etc. */ + uiItemR(layout, NULL, ICON_NODE, &ptr, "name", 0); + // TODO: a separator would be nice... + + /* draw this node's settings */ + if (node->typeinfo && node->typeinfo->uifunc) + node->typeinfo->uifunc(layout, (bContext *)C, &ptr); +} + +/* ******************* node buttons registration ************** */ + +void node_buttons_register(ARegionType *art) +{ + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype node panel active node"); + strcpy(pt->idname, "NODE_PT_item"); + strcpy(pt->label, "Active Node"); + pt->draw= active_node_panel; + pt->poll= active_node_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype node panel gpencil"); + strcpy(pt->idname, "NODE_PT_gpencil"); + strcpy(pt->label, "Grease Pencil"); + pt->draw= gpencil_panel_standard; + BLI_addtail(&art->paneltypes, pt); +} + +static int node_properties(bContext *C, wmOperator *op) +{ + ScrArea *sa= CTX_wm_area(C); + ARegion *ar= node_has_buttons_region(sa); + + if(ar) + ED_region_toggle_hidden(C, ar); + + return OPERATOR_FINISHED; +} + +/* non-standard poll operator which doesn't care if there are any nodes */ +static int node_properties_poll(bContext *C) +{ + ScrArea *sa= CTX_wm_area(C); + return (sa && (sa->spacetype == SPACE_NODE)); +} + +void NODE_OT_properties(wmOperatorType *ot) +{ + ot->name= "Properties"; + ot->description= "Toggles the properties panel display."; + ot->idname= "NODE_OT_properties"; + + ot->exec= node_properties; + ot->poll= node_properties_poll; + + /* flags */ + ot->flag= 0; +} diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 26601958c8a..1cdad0b746c 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -48,7 +48,7 @@ #include "DNA_text_types.h" #include "DNA_userdef_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_threads.h" #include "MEM_guardedalloc.h" @@ -66,14 +66,13 @@ #include "BKE_text.h" #include "BKE_utildefines.h" -/* #include "BDR_gpencil.h" XXX */ - #include "BIF_gl.h" #include "BIF_glutil.h" #include "WM_api.h" #include "WM_types.h" +#include "ED_gpencil.h" #include "ED_screen.h" #include "ED_util.h" #include "ED_types.h" @@ -259,7 +258,7 @@ static void node_update(const bContext *C, bNodeTree *ntree, bNode *node) layout= uiBlockLayout(node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, node->locx+NODE_DYS, dy, node->butr.xmax, 20, U.uistyles.first); - node->typeinfo->uifunc(layout, &ptr); + node->typeinfo->uifunc(layout, (bContext *)C, &ptr); uiBlockEndAlign(node->block); uiBlockLayoutResolve(node->block, NULL, &buty); @@ -548,53 +547,25 @@ static void node_sync_cb(bContext *C, void *snode_v, void *node_v) /* ************** Socket callbacks *********** */ -static void socket_vector_menu_cb(bContext *C, void *node_v, void *ntree_v) -{ - if(node_v && ntree_v) { - NodeTagChanged(ntree_v, node_v); - // addqueue(curarea->win, UI_BUT_EVENT, B_NODE_EXEC); XXX - } -} - /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */ static uiBlock *socket_vector_menu(bContext *C, ARegion *ar, void *socket_v) { - SpaceNode *snode= CTX_wm_space_node(C); - ScrArea *sa= CTX_wm_area(C); - bNode *node; bNodeSocket *sock= socket_v; - bNodeStack *ns= &sock->ns; uiBlock *block; - uiBut *bt; - /* a bit ugly... retrieve the node the socket comes from */ - for(node= snode->nodetree->nodes.first; node; node= node->next) { - bNodeSocket *sockt; - for(sockt= node->inputs.first; sockt; sockt= sockt->next) - if(sockt==sock) - break; - if(sockt) - break; - } + SpaceNode *snode= CTX_wm_space_node(C); + bNodeTree *ntree = snode->nodetree; + PointerRNA ptr; + uiLayout *layout; + + RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr); block= uiBeginBlock(C, ar, "socket menu", UI_EMBOSS); uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN); - - /* use this for a fake extra empy space around the buttons */ - uiDefBut(block, LABEL, 0, "", -4, -4, 188, 68, NULL, 0, 0, 0, 0, ""); - uiBlockBeginAlign(block); - bt= uiDefButF(block, NUMSLI, 0, "X ", 0,40,180,20, ns->vec, ns->min, ns->max, 10, 0, ""); - uiButSetFunc(bt, socket_vector_menu_cb, node, snode->nodetree); - bt= uiDefButF(block, NUMSLI, 0, "Y ", 0,20,180,20, ns->vec+1, ns->min, ns->max, 10, 0, ""); - uiButSetFunc(bt, socket_vector_menu_cb, node, snode->nodetree); - bt= uiDefButF(block, NUMSLI, 0, "Z ", 0,0,180,20, ns->vec+2, ns->min, ns->max, 10, 0, ""); - uiButSetFunc(bt, socket_vector_menu_cb, node, snode->nodetree); + layout= uiLayoutColumn(uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, sock->locx, sock->locy-8, 140, 20, U.uistyles.first), 0); - uiBlockSetDirection(block, UI_TOP); - uiEndBlock(C, block); - - ED_area_tag_redraw(sa); + uiItemR(layout, "", 0, &ptr, "default_value", UI_ITEM_R_EXPAND); return block; } @@ -671,6 +642,8 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN int /*ofs,*/ color_id= node_get_colorid(node); char showname[128]; /* 128 used below */ View2D *v2d = &ar->v2d; + bNodeTree *ntree = snode->nodetree; + PointerRNA ptr; uiSetRoundBox(15-4); ui_dropshadow(rct, BASIS_RAD, snode->aspect, node->flag & SELECT); @@ -694,41 +667,41 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN icon_id= ICON_MATERIAL; else icon_id= ICON_MATERIAL_DATA; - iconofs-= 18.0f; + iconofs-= 20.0f; glEnable(GL_BLEND); - UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, icon_id, snode->aspect, 0.5f); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY, icon_id, snode->aspect, 0.5f); glDisable(GL_BLEND); } if(node->type == NODE_GROUP) { - iconofs-= 18.0f; + iconofs-= 20.0f; glEnable(GL_BLEND); if(node->id->lib) { float rgb[3] = {1.0f, 0.7f, 0.3f}; - UI_icon_draw_aspect_color(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, rgb); + UI_icon_draw_aspect_color(iconofs, rct->ymax-NODE_DY, ICON_NODETREE, snode->aspect, rgb); } else { - UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, 0.5f); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY, ICON_NODETREE, snode->aspect, 0.5f); } glDisable(GL_BLEND); } if(node->typeinfo->flag & NODE_OPTIONS) { - iconofs-= 18.0f; + iconofs-= 20.0f; glEnable(GL_BLEND); - UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_BUTS, snode->aspect, 0.5f); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY, ICON_BUTS, snode->aspect, 0.5f); glDisable(GL_BLEND); } { /* always hide/reveal unused sockets */ int shade; - iconofs-= 18.0f; + iconofs-= 20.0f; // XXX re-enable /*if(node_has_hidden_sockets(node)) shade= -40; else*/ shade= -90; glEnable(GL_BLEND); - UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_PLUS, snode->aspect, 0.5f); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY, ICON_PLUS, snode->aspect, 0.5f); glDisable(GL_BLEND); } @@ -746,12 +719,14 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN else UI_ThemeColor(TH_TEXT); - if(node->flag & NODE_MUTED) - sprintf(showname, "[%s]", node->name); - else if(node->username[0]) - sprintf(showname, "(%s) %s", node->username, node->name); + if(node->flag & NODE_CUSTOM_NAME) + BLI_strncpy(showname, node->name, 32); else - BLI_strncpy(showname, node->name, 128); + /* todo: auto name display for node types */ + BLI_strncpy(showname, node->name, 32); + + //if(node->flag & NODE_MUTED) + // sprintf(showname, "[%s]", showname); uiDefBut(node->block, LABEL, 0, showname, (short)(rct->xmin+15), (short)(rct->ymax-NODE_DY), (int)(iconofs - rct->xmin-18.0f), NODE_DY, NULL, 0, 0, 0, 0, ""); @@ -789,13 +764,14 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) { socket_circle_draw(sock, NODE_SOCKSIZE); + RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr); + if(node->block && sock->link==NULL) { - float *butpoin= sock->ns.vec; - + if(sock->type==SOCK_VALUE) { - bt= uiDefButF(node->block, NUM, B_NODE_EXEC, sock->name, - (short)sock->locx+NODE_DYS, (short)(sock->locy)-9, (short)node->width-NODE_DY, 17, - butpoin, sock->ns.min, sock->ns.max, 10, 2, ""); + bt=uiDefButR(node->block, NUM, B_NODE_EXEC, sock->name, + (short)sock->locx+NODE_DYS, (short)(sock->locy)-9, (short)node->width-NODE_DY, 17, + &ptr, "default_value", 0, sock->ns.min, sock->ns.max, -1, -1, NULL); uiButSetFunc(bt, node_sync_cb, snode, node); } else if(sock->type==SOCK_VECTOR) { @@ -808,9 +784,9 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN if(labelw>0) width= 40; else width= (short)node->width-NODE_DY; - bt= uiDefButF(node->block, COL, B_NODE_EXEC, "", - (short)(sock->locx+NODE_DYS), (short)sock->locy-8, width, 15, - butpoin, 0, 0, 0, 0, ""); + bt=uiDefButR(node->block, COL, B_NODE_EXEC, "", + (short)sock->locx+NODE_DYS, (short)(sock->locy)-8, width, 15, + &ptr, "default_value", 0, sock->ns.min, sock->ns.max, -1, -1, NULL); uiButSetFunc(bt, node_sync_cb, snode, node); if(labelw>0) uiDefBut(node->block, LABEL, 0, sock->name, @@ -820,7 +796,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN } else { - uiDefBut(node->block, LABEL, 0, sock->name, (short)(sock->locx+3.0f), (short)(sock->locy-9.0f), + uiDefBut(node->block, LABEL, 0, sock->name, (short)(sock->locx+7), (short)(sock->locy-9.0f), (short)(node->width-NODE_DY), NODE_DY, NULL, 0, 0, 0, 0, ""); } } @@ -904,12 +880,15 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b if(node->miniwidth>0.0f) { - if(node->flag & NODE_MUTED) - sprintf(showname, "[%s]", node->name); - else if(node->username[0]) - sprintf(showname, "(%s)%s", node->username, node->name); + + if(node->flag & NODE_CUSTOM_NAME) + BLI_strncpy(showname, node->name, 128); else + /* todo: auto name display */ BLI_strncpy(showname, node->name, 128); + + //if(node->flag & NODE_MUTED) + // sprintf(showname, "[%s]", showname); uiDefBut(node->block, LABEL, 0, showname, (short)(rct->xmin+15), (short)(centy-10), (int)(rct->xmax - rct->xmin-18.0f -12.0f), NODE_DY, NULL, 0, 0, 0, 0, ""); @@ -1047,12 +1026,8 @@ static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bN /* backdrop title */ UI_ThemeColor(TH_TEXT_HI); - if(gnode->username[0]) { - strcpy(showname,"("); - strcat(showname, gnode->username); - strcat(showname,") "); - strcat(showname, ngroup->id.name+2); - } + if (gnode->flag & NODE_CUSTOM_NAME) + strcat(showname, gnode->name); else strcpy(showname, ngroup->id.name+2); @@ -1127,38 +1102,16 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d) } /* draw grease-pencil ('canvas' strokes) */ - /*if ((snode->flag & SNODE_DISPGP) && (snode->nodetree)) - draw_gpencil_2dview(sa, 1);*/ - - /* restore viewport (not needed yet) */ - /*mywinset(sa->win);*/ - - /* ortho at pixel level curarea */ - /*myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);*/ - - /* draw grease-pencil (screen strokes) */ - /*if ((snode->flag & SNODE_DISPGP) && (snode->nodetree)) - draw_gpencil_2dview(sa, 0);*/ - - //draw_area_emboss(sa); - - /* it is important to end a view in a transform compatible with buttons */ - /*bwin_scalematrix(sa->win, snode->blockscale, snode->blockscale, snode->blockscale); - nodes_blockhandlers(sa);*/ - - //curarea->win_swap= WIN_BACK_OK; - - /* in the end, this is a delayed previewrender test, to allow buttons to be first */ - /*if(snode->flag & SNODE_DO_PREVIEW) { - addafterqueue(sa->win, RENDERPREVIEW, 1); - snode->flag &= ~SNODE_DO_PREVIEW; - }*/ - - + if (/*(snode->flag & SNODE_DISPGP) &&*/ (snode->nodetree)) + draw_gpencil_2dview((bContext*)C, 1); /* reset view matrix */ UI_view2d_view_restore(C); + /* draw grease-pencil (screen strokes, and also paintbuffer) */ + if (/*(snode->flag & SNODE_DISPGP) && */(snode->nodetree)) + draw_gpencil_2dview((bContext*)C, 0); + /* scrollers */ scrollers= UI_view2d_scrollers_calc(C, v2d, 10, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); UI_view2d_scrollers_draw(C, v2d, scrollers); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 046ae8b1f5d..70c47a67761 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -64,7 +64,7 @@ #include "BIF_gl.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_storage_types.h" @@ -395,21 +395,6 @@ static void composit_node_event(SpaceNode *snode, short event) case B_REDR: // allqueue(REDRAWNODE, 1); break; - case B_NODE_LOADIMAGE: - { - bNode *node= nodeGetActive(snode->edittree); - char name[FILE_MAXDIR+FILE_MAXFILE]; - - if(node->id) - strcpy(name, ((Image *)node->id)->name); - else strcpy(name, U.textudir); - if (G.qual & LR_CTRLKEY) { - activate_imageselect(FILE_SPECIAL, "SELECT IMAGE", name, load_node_image); - } else { - activate_fileselect(FILE_SPECIAL, "SELECT IMAGE", name, load_node_image); - } - break; - } case B_NODE_SETIMAGE: { bNode *node= nodeGetActive(snode->edittree); @@ -1266,6 +1251,8 @@ void NODE_OT_resize(wmOperatorType *ot) /* ******************** rename ******************* */ + +/* should go through RNA */ void node_rename(SpaceNode *snode) { bNode *node, *rename_node; @@ -1281,7 +1268,7 @@ void node_rename(SpaceNode *snode) if(found_node) { rename_node= nodeGetActive(snode->edittree); - node_rename_but((char *)rename_node->username); + node_rename_but((char *)rename_node->name); // allqueue(REDRAWNODE, 1); } @@ -2169,7 +2156,7 @@ static int cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot) for(i=0; i<tot-1; i++) for(b=0; b<LINK_RESOL-1; b++) - if(IsectLL2Df(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0) + if(isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0) return 1; } return 0; diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index f55ecf1d0f4..2d4d7035568 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -44,6 +44,9 @@ struct wmWindowManager; #define NODE_EXTEND 1 #define NODE_EXCLUSIVE 3 +/* space_node.c */ +ARegion *node_has_buttons_region(ScrArea *sa); + /* node_header.c */ void node_header_buttons(const bContext *C, ARegion *ar); void node_menus_register(struct ARegionType *art); @@ -51,6 +54,10 @@ void node_menus_register(struct ARegionType *art); /* node_draw.c */ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d); +/* node_buttons.c */ +void node_buttons_register(struct ARegionType *art); +void NODE_OT_properties(struct wmOperatorType *ot); + /* node_ops.c */ void node_operatortypes(void); void node_keymap(wmKeyConfig *keyconf); @@ -121,6 +128,6 @@ enum { B_MATPRV, B_NODE_LOADIMAGE, B_NODE_SETIMAGE, -} eActHeader_ButEvents; +} eNodeSpace_ButEvents; #endif /* ED_NODE_INTERN_H */ diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index 443b83a91bc..b78fc864a11 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -49,6 +49,8 @@ void node_operatortypes(void) { + WM_operatortype_append(NODE_OT_properties); + WM_operatortype_append(NODE_OT_select); WM_operatortype_append(NODE_OT_select_extend); WM_operatortype_append(NODE_OT_select_all); @@ -69,9 +71,17 @@ void node_operatortypes(void) void node_keymap(struct wmKeyConfig *keyconf) { - wmKeyMap *keymap= WM_keymap_find(keyconf, "Node", SPACE_NODE, 0); + wmKeyMap *keymap; wmKeyMapItem *kmi; + /* Entire Editor only ----------------- */ + keymap= WM_keymap_find(keyconf, "Node Generic", SPACE_NODE, 0); + + WM_keymap_add_item(keymap, "NODE_OT_properties", NKEY, KM_PRESS, 0, 0); + + /* Main Area only ----------------- */ + keymap= WM_keymap_find(keyconf, "Node", SPACE_NODE, 0); + /* mouse select in nodes used to be both keys, it's UI elements... */ RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, 0, 0)->ptr, "select_type", NODE_SELECT_MOUSE); RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, 0, 0)->ptr, "select_type", NODE_SELECT_MOUSE); diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index e082f3797c1..67c7915694d 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -140,6 +140,9 @@ static int node_select_exec(bContext *C, wmOperator *op) } ED_region_tag_redraw(ar); + + /* send notifiers */ + WM_event_add_notifier(C, NC_NODE|ND_NODE_SELECT, NULL); /* allow tweak event to work too */ return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH; diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 46461eff76b..e5fb0b8dfcf 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" @@ -65,6 +65,35 @@ #include "node_intern.h" // own include +/* ******************** manage regions ********************* */ + +ARegion *node_has_buttons_region(ScrArea *sa) +{ + ARegion *ar, *arnew; + + for(ar= sa->regionbase.first; ar; ar= ar->next) + if(ar->regiontype==RGN_TYPE_UI) + return ar; + + /* add subdiv level; after header */ + for(ar= sa->regionbase.first; ar; ar= ar->next) + if(ar->regiontype==RGN_TYPE_HEADER) + break; + + /* is error! */ + if(ar==NULL) return NULL; + + arnew= MEM_callocN(sizeof(ARegion), "buttons for node"); + + BLI_insertlinkafter(&sa->regionbase, ar, arnew); + arnew->regiontype= RGN_TYPE_UI; + arnew->alignment= RGN_ALIGN_RIGHT; + + arnew->flag = RGN_FLAG_HIDDEN; + + return arnew; +} + /* ******************** default callbacks for node space ***************** */ static SpaceLink *node_new(const bContext *C) @@ -82,16 +111,13 @@ static SpaceLink *node_new(const bContext *C) ar->regiontype= RGN_TYPE_HEADER; ar->alignment= RGN_ALIGN_BOTTOM; -#if 0 - /* channels */ - ar= MEM_callocN(sizeof(ARegion), "nodetree area for node"); + /* buttons/list view */ + ar= MEM_callocN(sizeof(ARegion), "buttons for node"); BLI_addtail(&snode->regionbase, ar); - ar->regiontype= RGN_TYPE_CHANNELS; - ar->alignment= RGN_ALIGN_LEFT; - - //ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM); -#endif + ar->regiontype= RGN_TYPE_UI; + ar->alignment= RGN_ALIGN_RIGHT; + ar->flag = RGN_FLAG_HIDDEN; /* main area */ ar= MEM_callocN(sizeof(ARegion), "main area for node"); @@ -128,9 +154,7 @@ static SpaceLink *node_new(const bContext *C) /* not spacelink itself */ static void node_free(SpaceLink *sl) { -// SpaceNode *snode= (SpaceNode*) sl; -// XXX if(snode->gpd) free_gpencil_data(snode->gpd); } @@ -174,6 +198,9 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn) else if(wmn->data==ND_SPACE_NODE_VIEW) ED_area_tag_redraw(sa); break; + case NC_NODE: + ED_area_tag_refresh(sa); + break; } } @@ -210,41 +237,26 @@ static SpaceLink *node_duplicate(SpaceLink *sl) /* clear or remove stuff from old */ snoden->nodetree= NULL; -// XXX snoden->gpd= gpencil_data_duplicate(snode->gpd); return (SpaceLink *)snoden; } -#if 0 -static void node_channel_area_init(wmWindowManager *wm, ARegion *ar) + +/* add handlers, stuff you only do once or on area/region changes */ +static void node_buttons_area_init(wmWindowManager *wm, ARegion *ar) { - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); + wmKeyMap *keymap; + + ED_region_panels_init(wm, ar); + + keymap= WM_keymap_find(wm->defaultconf, "Node Generic", SPACE_NODE, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); } -static void node_channel_area_draw(const bContext *C, ARegion *ar) +static void node_buttons_area_draw(const bContext *C, ARegion *ar) { - View2D *v2d= &ar->v2d; - View2DScrollers *scrollers; - float col[3]; - - /* clear and setup matrix */ - UI_GetThemeColor3fv(TH_BACK, col); - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - UI_view2d_view_ortho(C, v2d); - - /* data... */ - - /* reset view matrix */ - UI_view2d_view_restore(C); - - /* scrollers */ - scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); - UI_view2d_scrollers_draw(C, v2d, scrollers); - UI_view2d_scrollers_free(scrollers); + ED_region_panels(C, ar, 1, NULL, -1); } -#endif /* Initialise main area, setting handlers. */ static void node_main_area_init(wmWindowManager *wm, ARegion *ar) @@ -253,7 +265,10 @@ static void node_main_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); - /* own keymap */ + /* own keymaps */ + keymap= WM_keymap_find(wm->defaultconf, "Node Generic", SPACE_NODE, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); + keymap= WM_keymap_find(wm->defaultconf, "Node", SPACE_NODE, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } @@ -287,6 +302,10 @@ static void node_region_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ switch(wmn->category) { + case NC_SPACE: + if(wmn->data==ND_SPACE_NODE) + ED_region_tag_redraw(ar); + break; case NC_SCENE: case NC_MATERIAL: case NC_TEXTURE: @@ -343,7 +362,7 @@ void ED_spacetype_node(void) art->init= node_main_area_init; art->draw= node_main_area_draw; art->listener= node_region_listener; - art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_GPENCIL; BLI_addhead(&st->regiontypes, art); @@ -360,19 +379,17 @@ void ED_spacetype_node(void) node_menus_register(art); -#if 0 - /* regions: channels */ + /* regions: listview/buttons */ art= MEM_callocN(sizeof(ARegionType), "spacetype node region"); - art->regionid = RGN_TYPE_CHANNELS; - art->minsizex= 100; - art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES; - - art->init= node_channel_area_init; - art->draw= node_channel_area_draw; - + art->regionid = RGN_TYPE_UI; + art->minsizex= 180; // XXX + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES; + art->listener= node_region_listener; + art->init= node_buttons_area_init; + art->draw= node_buttons_area_draw; BLI_addhead(&st->regiontypes, art); -#endif + node_buttons_register(art); BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_outliner/outliner.c b/source/blender/editors/space_outliner/outliner.c index bc203a9c80b..39eecd7d2de 100644 --- a/source/blender/editors/space_outliner/outliner.c +++ b/source/blender/editors/space_outliner/outliner.c @@ -2025,6 +2025,7 @@ static int tree_element_active_posegroup(bContext *C, Scene *scene, TreeElement static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set) { Object *ob= (Object *)tselem->id; + bArmature *arm= ob->data; bPoseChannel *pchan= te->directdata; if(set) { @@ -2033,10 +2034,14 @@ static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElemen if(set==2) ED_pose_deselectall(ob, 2, 0); // 2 = clear active tag else ED_pose_deselectall(ob, 0, 0); // 0 = deselect - if(set==2 && (pchan->bone->flag & BONE_SELECTED)) - pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); - else - pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE; + if(set==2 && (pchan->bone->flag & BONE_SELECTED)) { + pchan->bone->flag &= ~BONE_SELECTED; + if(arm->act_bone==pchan->bone) + arm->act_bone= NULL; + } else { + pchan->bone->flag |= BONE_SELECTED; + arm->act_bone= pchan->bone; + } WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, ob); @@ -2060,10 +2065,14 @@ static int tree_element_active_bone(bContext *C, Scene *scene, TreeElement *te, if(set==2) ED_pose_deselectall(OBACT, 2, 0); // 2 is clear active tag else ED_pose_deselectall(OBACT, 0, 0); - if(set==2 && (bone->flag & BONE_SELECTED)) - bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE); - else - bone->flag |= BONE_SELECTED|BONE_ACTIVE; + if(set==2 && (bone->flag & BONE_SELECTED)) { + bone->flag &= ~BONE_SELECTED; + if(arm->act_bone==bone) + arm->act_bone= NULL; + } else { + bone->flag |= BONE_SELECTED; + arm->act_bone= bone; + } WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, OBACT); } @@ -2086,11 +2095,13 @@ static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te, if(set) { if(!(ebone->flag & BONE_HIDDEN_A)) { - + bArmature *arm= scene->obedit->data; if(set==2) ED_armature_deselectall(scene->obedit, 2, 0); // only clear active tag else ED_armature_deselectall(scene->obedit, 0, 0); // deselect - ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE; + ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL; + arm->act_edbone= ebone; + // flush to parent? if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL; diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 93fdc96e9f7..5c6a8701f18 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -43,7 +43,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" diff --git a/source/blender/editors/space_script/script_ops.c b/source/blender/editors/space_script/script_ops.c index bf0a7e5769e..fd87705648f 100644 --- a/source/blender/editors/space_script/script_ops.c +++ b/source/blender/editors/space_script/script_ops.c @@ -37,7 +37,7 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_context.h" diff --git a/source/blender/editors/space_script/space_script.c b/source/blender/editors/space_script/space_script.c index eae0f77d0e1..fc2f10670df 100644 --- a/source/blender/editors/space_script/space_script.c +++ b/source/blender/editors/space_script/space_script.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index bd5259ddb52..824dbd1caa8 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -38,7 +38,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_storage_types.h" #include "IMB_imbuf_types.h" diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 76bed3772b1..ff9edeaeb4b 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -31,7 +31,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "IMB_imbuf_types.h" diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index a5e89b4023a..041ccd6641a 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_storage_types.h" #include "IMB_imbuf_types.h" @@ -2669,3 +2669,53 @@ void SEQUENCER_OT_swap_left(wmOperatorType *ot) /* properties */ } + +static int sequencer_rendersize_exec(bContext *C, wmOperator *op) +{ + int retval = OPERATOR_CANCELLED; + Scene *scene= CTX_data_scene(C); + Sequence *active_seq = get_last_seq(scene); + + if(active_seq==NULL) return OPERATOR_CANCELLED; + + printf("got active sequence\n"); + switch (active_seq->type) { + case SEQ_IMAGE: + case SEQ_MOVIE: + if (active_seq->strip) { + // prevent setting the render size if sequence values aren't initialized + if ( (active_seq->strip->orx>0) && (active_seq->strip->ory>0) ) { + scene->r.xsch= active_seq->strip->orx; + scene->r.ysch= active_seq->strip->ory; + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + retval = OPERATOR_FINISHED; + } + } + break; + case SEQ_SCENE: + case SEQ_META: + case SEQ_RAM_SOUND: + case SEQ_HD_SOUND: + default: + break; + } + return retval; +} + +void SEQUENCER_OT_rendersize(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Set Render Size"; + ot->idname= "SEQUENCER_OT_rendersize"; + ot->description="Set render size and aspect from active sequence."; + + /* api callbacks */ + ot->exec= sequencer_rendersize_exec; + ot->poll= ED_operator_sequencer_active; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ +} + diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index 0a8208fcc2e..82b24deae63 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -95,6 +95,7 @@ void SEQUENCER_OT_previous_edit(struct wmOperatorType *ot); void SEQUENCER_OT_next_edit(struct wmOperatorType *ot); void SEQUENCER_OT_swap_right(struct wmOperatorType *ot); void SEQUENCER_OT_swap_left(struct wmOperatorType *ot); +void SEQUENCER_OT_rendersize(struct wmOperatorType *ot); void SEQUENCER_OT_view_all(struct wmOperatorType *ot); void SEQUENCER_OT_view_selected(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c index 90342fc62b5..94b79fdf685 100644 --- a/source/blender/editors/space_sequencer/sequencer_ops.c +++ b/source/blender/editors/space_sequencer/sequencer_ops.c @@ -38,7 +38,7 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_context.h" @@ -81,6 +81,7 @@ void sequencer_operatortypes(void) WM_operatortype_append(SEQUENCER_OT_previous_edit); WM_operatortype_append(SEQUENCER_OT_swap_right); WM_operatortype_append(SEQUENCER_OT_swap_left); + WM_operatortype_append(SEQUENCER_OT_rendersize); WM_operatortype_append(SEQUENCER_OT_view_all); WM_operatortype_append(SEQUENCER_OT_view_selected); diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 381d9241094..2ead426c18a 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -38,7 +38,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_curve_types.h" #include "DNA_scene_types.h" diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 206070b7095..ed532edb0ec 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -37,7 +37,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" diff --git a/source/blender/editors/space_sound/space_sound.c b/source/blender/editors/space_sound/space_sound.c index 7cd9988eea0..314e711234a 100644 --- a/source/blender/editors/space_sound/space_sound.c +++ b/source/blender/editors/space_sound/space_sound.c @@ -38,7 +38,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index e9cd2644ba6..0b30587c521 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -39,7 +39,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_colortools.h" diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 656d7061d48..08629a9a2f7 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -51,7 +51,7 @@ #include "DNA_userdef_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_dlrbTree.h" #include "BKE_animsys.h" @@ -166,7 +166,7 @@ static short set_pchan_glColor (short colCode, int armflag, int boneflag, int co if (bcolor) { char cp[3]; - if (boneflag & BONE_ACTIVE) { + if (boneflag & BONE_DRAW_ACTIVE) { VECCOPY(cp, bcolor->active); } else if (boneflag & BONE_SELECTED) { @@ -181,7 +181,7 @@ static short set_pchan_glColor (short colCode, int armflag, int boneflag, int co glColor3ub(cp[0], cp[1], cp[2]); } else { - if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40); + if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40); else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE); else UI_ThemeColor(TH_WIRE); } @@ -225,7 +225,7 @@ static short set_pchan_glColor (short colCode, int armflag, int boneflag, int co if (bcolor) { char cp[3]; - if (boneflag & BONE_ACTIVE) { + if (boneflag & BONE_DRAW_ACTIVE) { VECCOPY(cp, bcolor->active); } else if (boneflag & BONE_SELECTED) { @@ -238,7 +238,7 @@ static short set_pchan_glColor (short colCode, int armflag, int boneflag, int co glColor3ub(cp[0], cp[1], cp[2]); } else { - if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40); + if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40); else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE); else UI_ThemeColor(TH_BONE_SOLID); } @@ -251,7 +251,7 @@ static short set_pchan_glColor (short colCode, int armflag, int boneflag, int co if (bcolor) { char cp[3]; - if (boneflag & BONE_ACTIVE) { + if (boneflag & BONE_DRAW_ACTIVE) { VECCOPY(cp, bcolor->active); cp_shade_color3ub(cp, 10); } @@ -267,7 +267,7 @@ static short set_pchan_glColor (short colCode, int armflag, int boneflag, int co glColor3ub(cp[0], cp[1], cp[2]); } else { - if (boneflag & BONE_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10); + if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10); else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30); else UI_ThemeColorShade(TH_BONE_SOLID, -30); } @@ -510,36 +510,36 @@ static void draw_bone_solid_octahedral(void) glBegin(GL_TRIANGLES); /* bottom */ - CalcNormFloat(vec[2], vec[1], vec[0], nor); + normal_tri_v3( nor,vec[2], vec[1], vec[0]); glNormal3fv(nor); glVertex3fv(vec[2]); glVertex3fv(vec[1]); glVertex3fv(vec[0]); - CalcNormFloat(vec[3], vec[2], vec[0], nor); + normal_tri_v3( nor,vec[3], vec[2], vec[0]); glNormal3fv(nor); glVertex3fv(vec[3]); glVertex3fv(vec[2]); glVertex3fv(vec[0]); - CalcNormFloat(vec[4], vec[3], vec[0], nor); + normal_tri_v3( nor,vec[4], vec[3], vec[0]); glNormal3fv(nor); glVertex3fv(vec[4]); glVertex3fv(vec[3]); glVertex3fv(vec[0]); - CalcNormFloat(vec[1], vec[4], vec[0], nor); + normal_tri_v3( nor,vec[1], vec[4], vec[0]); glNormal3fv(nor); glVertex3fv(vec[1]); glVertex3fv(vec[4]); glVertex3fv(vec[0]); /* top */ - CalcNormFloat(vec[5], vec[1], vec[2], nor); + normal_tri_v3( nor,vec[5], vec[1], vec[2]); glNormal3fv(nor); glVertex3fv(vec[5]); glVertex3fv(vec[1]); glVertex3fv(vec[2]); - CalcNormFloat(vec[5], vec[2], vec[3], nor); + normal_tri_v3( nor,vec[5], vec[2], vec[3]); glNormal3fv(nor); glVertex3fv(vec[5]); glVertex3fv(vec[2]); glVertex3fv(vec[3]); - CalcNormFloat(vec[5], vec[3], vec[4], nor); + normal_tri_v3( nor,vec[5], vec[3], vec[4]); glNormal3fv(nor); glVertex3fv(vec[5]); glVertex3fv(vec[3]); glVertex3fv(vec[4]); - CalcNormFloat(vec[5], vec[4], vec[1], nor); + normal_tri_v3( nor,vec[5], vec[4], vec[1]); glNormal3fv(nor); glVertex3fv(vec[5]); glVertex3fv(vec[4]); glVertex3fv(vec[1]); @@ -642,7 +642,7 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag /* figure out the sizes of spheres */ if (ebone) { /* this routine doesn't call get_matrix_editbone() that calculates it */ - ebone->length = VecLenf(ebone->head, ebone->tail); + ebone->length = len_v3v3(ebone->head, ebone->tail); length= ebone->length; tail= ebone->rad_tail; @@ -669,19 +669,19 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], int boneflag /* ***** draw it ***** */ /* move vector to viewspace */ - VecSubf(dirvec, tailvec, headvec); - Mat4Mul3Vecfl(smat, dirvec); + sub_v3_v3v3(dirvec, tailvec, headvec); + mul_mat3_m4_v3(smat, dirvec); /* clear zcomp */ dirvec[2]= 0.0f; /* move vector back */ - Mat4Mul3Vecfl(imat, dirvec); + mul_mat3_m4_v3(imat, dirvec); - if (0.0f != Normalize(dirvec)) { + if (0.0f != normalize_v3(dirvec)) { float norvec[3], vec1[3], vec2[3], vec[3]; int a; - //VecMulf(dirvec, head); - Crossf(norvec, dirvec, imat[2]); + //mul_v3_fl(dirvec, head); + cross_v3_v3v3(norvec, dirvec, imat[2]); glBegin(GL_QUAD_STRIP); @@ -752,7 +752,7 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag, /* figure out the sizes of spheres */ if (ebone) { /* this routine doesn't call get_matrix_editbone() that calculates it */ - ebone->length = VecLenf(ebone->head, ebone->tail); + ebone->length = len_v3v3(ebone->head, ebone->tail); length= ebone->length; tail= ebone->rad_tail; @@ -807,25 +807,25 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag, else UI_ThemeColor(TH_WIRE); } - VecSubf(dirvec, tailvec, headvec); + sub_v3_v3v3(dirvec, tailvec, headvec); /* move vector to viewspace */ - Mat4Mul3Vecfl(smat, dirvec); + mul_mat3_m4_v3(smat, dirvec); /* clear zcomp */ dirvec[2]= 0.0f; /* move vector back */ - Mat4Mul3Vecfl(imat, dirvec); + mul_mat3_m4_v3(imat, dirvec); - if (0.0f != Normalize(dirvec)) { + if (0.0f != normalize_v3(dirvec)) { float norvech[3], norvect[3], vec[3]; VECCOPY(vec, dirvec); - VecMulf(dirvec, head); - Crossf(norvech, dirvec, imat[2]); + mul_v3_fl(dirvec, head); + cross_v3_v3v3(norvech, dirvec, imat[2]); - VecMulf(vec, tail); - Crossf(norvect, vec, imat[2]); + mul_v3_fl(vec, tail); + cross_v3_v3v3(norvect, vec, imat[2]); if (id != -1) glLoadName(id | BONESEL_BONE); @@ -1151,7 +1151,7 @@ static void draw_b_bone(int dt, int armflag, int boneflag, int constflag, unsign } else if (armflag & ARM_EDITMODE) { if (dt==OB_WIRE) { - if (boneflag & BONE_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT); + if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT); else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20); else UI_ThemeColor(TH_WIRE); } @@ -1236,7 +1236,7 @@ static void draw_bone(int dt, int armflag, int boneflag, int constflag, unsigned if (dt <= OB_WIRE) { /* colors */ if (armflag & ARM_EDITMODE) { - if (boneflag & BONE_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT); + if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColor(TH_EDGE_SELECT); else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_EDGE_SELECT, -20); else UI_ThemeColor(TH_WIRE); } @@ -1463,12 +1463,12 @@ static void draw_pose_dofs(Object *ob) glTranslatef(posetrans[0], posetrans[1], posetrans[2]); if (pchan->parent) { - Mat4CpyMat4(mat, pchan->parent->pose_mat); + copy_m4_m4(mat, pchan->parent->pose_mat); mat[3][0]= mat[3][1]= mat[3][2]= 0.0f; glMultMatrixf(mat); } - Mat4CpyMat3(mat, pchan->bone->bone_mat); + copy_m4_m3(mat, pchan->bone->bone_mat); glMultMatrixf(mat); scale= bone->length*pchan->size[1]; @@ -1555,8 +1555,8 @@ static void bone_matrix_translate_y(float mat[][4], float y) float trans[3]; VECCOPY(trans, mat[1]); - VecMulf(trans, y); - VecAddf(mat[3], mat[3], trans); + mul_v3_fl(trans, y); + add_v3_v3v3(mat[3], mat[3], trans); } /* assumes object is Armature with pose */ @@ -1582,8 +1582,8 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, ARegion *ar, Base *bas if (arm->drawtype==ARM_ENVELOPE) { /* precalc inverse matrix for drawing screen aligned */ wmGetMatrix(smat); - Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0])); - Mat4Invert(imat, smat); + mul_mat3_m4_fl(smat, 1.0f/len_v3(ob->obmat[0])); + invert_m4_m4(imat, smat); /* and draw blended distances */ if (arm->flag & ARM_POSEMODE) { @@ -1629,7 +1629,11 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, ARegion *ar, Base *bas flag= bone->flag; if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) flag &= ~BONE_CONNECTED; - + + /* set temporary flag for drawing bone as active */ + if (bone == arm->act_bone) + flag |= BONE_DRAW_ACTIVE; + /* set color-set to use */ set_pchan_colorset(ob, pchan); @@ -1705,6 +1709,10 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, ARegion *ar, Base *bas flag= bone->flag; if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) flag &= ~BONE_CONNECTED; + + /* set temporary flag for drawing bone as active */ + if (bone == arm->act_bone) + flag |= BONE_DRAW_ACTIVE; draw_custom_bone(scene, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, bone->length); @@ -1797,6 +1805,10 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, ARegion *ar, Base *bas if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) flag &= ~BONE_CONNECTED; + /* set temporary flag for drawing bone as active */ + if (bone == arm->act_bone) + flag |= BONE_DRAW_ACTIVE; + /* extra draw service for pose mode */ constflag= pchan->constflag; if (pchan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE)) @@ -1862,22 +1874,22 @@ static void draw_pose_channels(Scene *scene, View3D *v3d, ARegion *ar, Base *bas /* Draw names of bone */ if (arm->flag & ARM_DRAWNAMES) { - VecMidf(vec, pchan->pose_head, pchan->pose_tail); + mid_v3_v3v3(vec, pchan->pose_head, pchan->pose_tail); view3d_cached_text_draw_add(vec[0], vec[1], vec[2], pchan->name, 10); } /* Draw additional axes on the bone tail */ if ( (arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE) ) { glPushMatrix(); - Mat4CpyMat4(bmat, pchan->pose_mat); + copy_m4_m4(bmat, pchan->pose_mat); bone_matrix_translate_y(bmat, pchan->bone->length); glMultMatrixf(bmat); - + /* do cached text draw immediate to include transform */ view3d_cached_text_draw_begin(); drawaxes(pchan->bone->length*0.25f, 0, OB_ARROWS); view3d_cached_text_draw_end(v3d, ar, 1, bmat); - + glPopMatrix(); } } @@ -1896,14 +1908,14 @@ static void get_matrix_editbone(EditBone *eBone, float bmat[][4]) float mat[3][3]; /* Compose the parent transforms (i.e. their translations) */ - VecSubf(delta, eBone->tail, eBone->head); + sub_v3_v3v3(delta, eBone->tail, eBone->head); eBone->length = (float)sqrt(delta[0]*delta[0] + delta[1]*delta[1] +delta[2]*delta[2]); vec_roll_to_mat3(delta, eBone->roll, mat); - Mat4CpyMat3(bmat, mat); + copy_m4_m3(bmat, mat); - VecAddf(bmat[3], bmat[3], eBone->head); + add_v3_v3v3(bmat[3], bmat[3], eBone->head); } static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt) @@ -1919,8 +1931,8 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt) if(arm->drawtype==ARM_ENVELOPE) { /* precalc inverse matrix for drawing screen aligned */ wmGetMatrix(smat); - Mat4MulFloat3(smat[0], 1.0f/VecLength(ob->obmat[0])); - Mat4Invert(imat, smat); + mul_mat3_m4_fl(smat, 1.0f/len_v3(ob->obmat[0])); + invert_m4_m4(imat, smat); /* and draw blended distances */ glEnable(GL_BLEND); @@ -1956,6 +1968,10 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt) flag= eBone->flag; if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) ) flag &= ~BONE_CONNECTED; + + /* set temporary flag for drawing bone as active */ + if (eBone == arm->act_edbone) + flag |= BONE_DRAW_ACTIVE; if (arm->drawtype==ARM_ENVELOPE) draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone); @@ -1991,6 +2007,10 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt) flag= eBone->flag; if ( (eBone->parent) && ((eBone->parent->flag & BONE_HIDDEN_A) || (eBone->parent->layer & arm->layer)==0) ) flag &= ~BONE_CONNECTED; + + /* set temporary flag for drawing bone as active */ + if (eBone == arm->act_edbone) + flag |= BONE_DRAW_ACTIVE; if (arm->drawtype == ARM_ENVELOPE) { if (dt < OB_SOLID) @@ -2050,7 +2070,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt) /* Draw name */ if (arm->flag & ARM_DRAWNAMES) { - VecMidf(vec, eBone->head, eBone->tail); + mid_v3_v3v3(vec, eBone->head, eBone->tail); glRasterPos3fv(vec); view3d_cached_text_draw_add(vec[0], vec[1], vec[2], eBone->name, 10); } @@ -2060,12 +2080,12 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt) get_matrix_editbone(eBone, bmat); bone_matrix_translate_y(bmat, eBone->length); glMultMatrixf(bmat); - + /* do cached text draw immediate to include transform */ view3d_cached_text_draw_begin(); drawaxes(eBone->length*0.25f, 0, OB_ARROWS); view3d_cached_text_draw_end(v3d, ar, 1, bmat); - + glPopMatrix(); } @@ -2223,7 +2243,7 @@ static void draw_pose_paths(Scene *scene, View3D *v3d, ARegion *ar, Object *ob) view3d_cached_text_draw_add(fp[0], fp[1], fp[2], str, 0); } else if ((a > stepsize) && (a < len-stepsize)) { - if ((VecEqual(fp, fp-(stepsize*3))==0) || (VecEqual(fp, fp+(stepsize*3))==0)) { + if ((equals_v3v3(fp, fp-(stepsize*3))==0) || (equals_v3v3(fp, fp+(stepsize*3))==0)) { sprintf(str, "%d", (a+sfra)); view3d_cached_text_draw_add(fp[0], fp[1], fp[2], str, 0); } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 365b9ff03f7..bf73e70367c 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -31,7 +31,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_edgehash.h" #include "BLI_editVert.h" @@ -614,7 +614,7 @@ void draw_mesh_text(Scene *scene, Object *ob, int glsl) if (!mf_smooth) { float nor[3]; - CalcNormFloat(v1, v2, v3, nor); + normal_tri_v3( nor,v1, v2, v3); glNormal3fv(nor); } diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 22fd77afd88..339dc830016 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -65,7 +65,7 @@ #include "DNA_world_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_edgehash.h" #include "BLI_rand.h" @@ -152,7 +152,7 @@ static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr) /* clipplanes in eye space */ if(rv3d->rflag & RV3D_CLIPPING) { VECCOPY(vec4, vec); - Mat4MulVecfl(rv3d->viewmatob, vec4); + mul_m4_v3(rv3d->viewmatob, vec4); if(view3d_test_clipping(rv3d, vec4)) return; } @@ -160,7 +160,7 @@ static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmatob, vec4); + mul_m4_v4(rv3d->persmatob, vec4); /* clipplanes in window space */ if( vec4[3]>BL_NEAR_CLIP ) { /* is the NEAR clipping cutoff for picking */ @@ -189,7 +189,7 @@ static void view3d_project_short_noclip(ARegion *ar, float *vec, short *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmatob, vec4); + mul_m4_v4(rv3d->persmatob, vec4); if( vec4[3]>BL_NEAR_CLIP ) { /* is the NEAR clipping cutoff for picking */ fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]); @@ -456,8 +456,8 @@ void drawcircball(int mode, float *cent, float rad, float tmat[][4]) VECCOPY(vx, tmat[0]); VECCOPY(vy, tmat[1]); - VecMulf(vx, rad); - VecMulf(vy, rad); + mul_v3_fl(vx, rad); + mul_v3_fl(vy, rad); glBegin(mode); for(a=0; a<tot; a++) { @@ -544,7 +544,7 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa /* project first and test */ for(vos= strings->first; vos; vos= vos->next) { if(mat) - Mat4MulVecfl(mat, vos->vec); + mul_m4_v3(mat, vos->vec); view3d_project_short_clip(ar, vos->vec, vos->mval); if(vos->mval[0]!=IS_CLIPPED) tot++; @@ -674,7 +674,7 @@ static void drawshadbuflimits(Lamp *la, float mat[][4]) lavec[0]= -mat[2][0]; lavec[1]= -mat[2][1]; lavec[2]= -mat[2][2]; - Normalize(lavec); + normalize_v3(lavec); sta[0]= mat[3][0]+ la->clipsta*lavec[0]; sta[1]= mat[3][1]+ la->clipsta*lavec[1]; @@ -705,13 +705,13 @@ static void spotvolume(float *lvec, float *vvec, float inp) /* camera is at 0,0,0 */ float temp[3],plane[3],mat1[3][3],mat2[3][3],mat3[3][3],mat4[3][3],q[4],co,si,angle; - Normalize(lvec); - Normalize(vvec); /* is this the correct vector ? */ + normalize_v3(lvec); + normalize_v3(vvec); /* is this the correct vector ? */ - Crossf(temp,vvec,lvec); /* equation for a plane through vvec en lvec */ - Crossf(plane,lvec,temp); /* a plane perpendicular to this, parrallel with lvec */ + cross_v3_v3v3(temp,vvec,lvec); /* equation for a plane through vvec en lvec */ + cross_v3_v3v3(plane,lvec,temp); /* a plane perpendicular to this, parrallel with lvec */ - Normalize(plane); + normalize_v3(plane); /* now we've got two equations: one of a cone and one of a plane, but we have three unknowns. We remove one unkown by rotating the plane to z=0 (the plane normal) */ @@ -724,7 +724,7 @@ static void spotvolume(float *lvec, float *vvec, float inp) q[1] = plane[1] ; q[2] = -plane[0] ; q[3] = 0 ; - Normalize(&q[1]); + normalize_v3(&q[1]); angle = saacos(plane[2])/2.0; co = cos(angle); @@ -735,7 +735,7 @@ static void spotvolume(float *lvec, float *vvec, float inp) q[2] *= si; q[3] = 0; - QuatToMat3(q,mat1); + quat_to_mat3(mat1,q); /* rotate lamp vector now over acos(inp) degrees */ @@ -743,7 +743,7 @@ static void spotvolume(float *lvec, float *vvec, float inp) vvec[1] = lvec[1] ; vvec[2] = lvec[2] ; - Mat3One(mat2); + unit_m3(mat2); co = inp; si = sqrt(1-inp*inp); @@ -751,17 +751,17 @@ static void spotvolume(float *lvec, float *vvec, float inp) mat2[1][0] = -si; mat2[0][1] = si; mat2[1][1] = co; - Mat3MulMat3(mat3,mat2,mat1); + mul_m3_m3m3(mat3,mat2,mat1); mat2[1][0] = si; mat2[0][1] = -si; - Mat3MulMat3(mat4,mat2,mat1); - Mat3Transp(mat1); + mul_m3_m3m3(mat4,mat2,mat1); + transpose_m3(mat1); - Mat3MulMat3(mat2,mat1,mat3); - Mat3MulVecfl(mat2,lvec); - Mat3MulMat3(mat2,mat1,mat4); - Mat3MulVecfl(mat2,vvec); + mul_m3_m3m3(mat2,mat1,mat3); + mul_m3_v3(mat2,lvec); + mul_m3_m3m3(mat2,mat1,mat4); + mul_m3_v3(mat2,vvec); return; } @@ -789,9 +789,9 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) lampsize= pixsize*((float)U.obcenter_dia*0.5f); /* and view aligned matrix: */ - Mat4CpyMat4(imat, rv3d->viewinv); - Normalize(imat[0]); - Normalize(imat[1]); + copy_m4_m4(imat, rv3d->viewinv); + normalize_v3(imat[0]); + normalize_v3(imat[1]); /* for AA effects */ glGetFloatv(GL_CURRENT_COLOR, curcol); @@ -835,13 +835,13 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) short axis; /* setup a 45 degree rotation matrix */ - VecRotToMat3(imat[2], M_PI/4.0f, mat); + vec_rot_to_mat3( mat,imat[2], M_PI/4.0f); /* vectors */ VECCOPY(v1, imat[0]); - VecMulf(v1, circrad*1.2f); + mul_v3_fl(v1, circrad*1.2f); VECCOPY(v2, imat[0]); - VecMulf(v2, circrad*2.5f); + mul_v3_fl(v2, circrad*2.5f); /* center */ glTranslatef(vec[0], vec[1], vec[2]); @@ -852,8 +852,8 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) for (axis=0; axis<8; axis++) { glVertex3fv(v1); glVertex3fv(v2); - Mat3MulVecfl(mat, v1); - Mat3MulVecfl(mat, v2); + mul_m3_v3(mat, v1); + mul_m3_v3(mat, v2); } glEnd(); @@ -1144,11 +1144,11 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob if(flag==0) { if(cam->flag & (CAM_SHOWLIMITS+CAM_SHOWMIST)) { wmLoadMatrix(rv3d->viewmat); - Mat4CpyMat4(vec, ob->obmat); - Mat4Ortho(vec); + copy_m4_m4(vec, ob->obmat); + normalize_m4(vec); wmMultMatrix(vec); - Mat4SwapMat4(rv3d->persmat, tmat); + swap_m4m4(rv3d->persmat, tmat); wmGetSingleMatrix(rv3d->persmat); if(cam->flag & CAM_SHOWLIMITS) { @@ -1161,7 +1161,7 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob if(cam->flag & CAM_SHOWMIST) if(wrld) draw_limit_line(wrld->miststa, wrld->miststa+wrld->mistdist, 0xFFFFFF); - Mat4SwapMat4(rv3d->persmat, tmat); + swap_m4m4(rv3d->persmat, tmat); } } } @@ -2271,13 +2271,13 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E z= 0.5f*(v1[2]+v2[2]); if(v3d->flag & V3D_GLOBAL_STATS) { - Mat4MulVecfl(ob->obmat, v1); - Mat4MulVecfl(ob->obmat, v2); + mul_m4_v3(ob->obmat, v1); + mul_m4_v3(ob->obmat, v2); } if(unit->system) - bUnit_AsString(val, sizeof(val), VecLenf(v1, v2)*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE); + bUnit_AsString(val, sizeof(val), len_v3v3(v1, v2)*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE); else - sprintf(val, conv_float, VecLenf(v1, v2)); + sprintf(val, conv_float, len_v3v3(v1, v2)); view3d_cached_text_draw_add(x, y, z, val, 0); } @@ -2302,16 +2302,16 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E VECCOPY(v4, efa->v4->co); } if(v3d->flag & V3D_GLOBAL_STATS) { - Mat4MulVecfl(ob->obmat, v1); - Mat4MulVecfl(ob->obmat, v2); - Mat4MulVecfl(ob->obmat, v3); - if (efa->v4) Mat4MulVecfl(ob->obmat, v4); + mul_m4_v3(ob->obmat, v1); + mul_m4_v3(ob->obmat, v2); + mul_m4_v3(ob->obmat, v3); + if (efa->v4) mul_m4_v3(ob->obmat, v4); } if (efa->v4) - area= AreaQ3Dfl(v1, v2, v3, v4); + area= area_quad_v3(v1, v2, v3, v4); else - area = AreaT3Dfl(v1, v2, v3); + area = area_tri_v3(v1, v2, v3); if(unit->system) bUnit_AsString(val, sizeof(val), area*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE); // XXX should be B_UNIT_AREA @@ -2343,10 +2343,10 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E VECCOPY(v4, v3); } if(v3d->flag & V3D_GLOBAL_STATS) { - Mat4MulVecfl(ob->obmat, v1); - Mat4MulVecfl(ob->obmat, v2); - Mat4MulVecfl(ob->obmat, v3); - Mat4MulVecfl(ob->obmat, v4); + mul_m4_v3(ob->obmat, v1); + mul_m4_v3(ob->obmat, v2); + mul_m4_v3(ob->obmat, v3); + mul_m4_v3(ob->obmat, v4); } e1= efa->e1; @@ -2358,30 +2358,30 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E if( (e4->f & e1->f & SELECT) || (G.moving && (efa->v1->f & SELECT)) ) { /* Vec 1 */ - sprintf(val,"%.3f", RAD2DEG(VecAngle3(v4, v1, v2))); - VecLerpf(fvec, efa->cent, efa->v1->co, 0.8f); + sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v4, v1, v2))); + interp_v3_v3v3(fvec, efa->cent, efa->v1->co, 0.8f); view3d_cached_text_draw_add(efa->cent[0], efa->cent[1], efa->cent[2], val, 0); } if( (e1->f & e2->f & SELECT) || (G.moving && (efa->v2->f & SELECT)) ) { /* Vec 2 */ - sprintf(val,"%.3f", RAD2DEG(VecAngle3(v1, v2, v3))); - VecLerpf(fvec, efa->cent, efa->v2->co, 0.8f); + sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v1, v2, v3))); + interp_v3_v3v3(fvec, efa->cent, efa->v2->co, 0.8f); view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0); } if( (e2->f & e3->f & SELECT) || (G.moving && (efa->v3->f & SELECT)) ) { /* Vec 3 */ if(efa->v4) - sprintf(val,"%.3f", RAD2DEG(VecAngle3(v2, v3, v4))); + sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v2, v3, v4))); else - sprintf(val,"%.3f", RAD2DEG(VecAngle3(v2, v3, v1))); - VecLerpf(fvec, efa->cent, efa->v3->co, 0.8f); + sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v2, v3, v1))); + interp_v3_v3v3(fvec, efa->cent, efa->v3->co, 0.8f); view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0); } /* Vec 4 */ if(efa->v4) { if( (e3->f & e4->f & SELECT) || (G.moving && (efa->v4->f & SELECT)) ) { - sprintf(val,"%.3f", RAD2DEG(VecAngle3(v3, v4, v1))); - VecLerpf(fvec, efa->cent, efa->v4->co, 0.8f); + sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v3, v4, v1))); + interp_v3_v3v3(fvec, efa->cent, efa->v4->co, 0.8f); view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0); } } @@ -3434,7 +3434,7 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix { vec[0]=2.0f*pixsize; vec[1]=vec[2]=0.0; - QuatMulVecf(state->rot,vec); + mul_qt_v3(state->rot,vec); if(draw_as==PART_DRAW_AXIS) { cd[1]=cd[2]=cd[4]=cd[5]=0.0; cd[0]=cd[3]=1.0; @@ -3462,7 +3462,7 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix vec[1]=2.0f*pixsize; vec[0]=vec[2]=0.0; - QuatMulVecf(state->rot,vec); + mul_qt_v3(state->rot,vec); if(draw_as==PART_DRAW_AXIS){ VECCOPY(vec2,state->co); } @@ -3474,7 +3474,7 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix vec[2]=2.0f*pixsize; vec[0]=vec[1]=0.0; - QuatMulVecf(state->rot,vec); + mul_qt_v3(state->rot,vec); if(draw_as==PART_DRAW_AXIS){ VECCOPY(vec2,state->co); } @@ -3489,9 +3489,9 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix case PART_DRAW_LINE: { VECCOPY(vec,state->vel); - Normalize(vec); + normalize_v3(vec); if(draw & PART_DRAW_VEL_LENGTH) - VecMulf(vec,VecLength(state->vel)); + mul_v3_fl(vec,len_v3(state->vel)); VECADDFAC(pdd->vd,state->co,vec,-draw_line[0]); pdd->vd+=3; VECADDFAC(pdd->vd,state->co,vec,draw_line[1]); pdd->vd+=3; if(cd) { @@ -3649,7 +3649,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv if( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) { float mat[4][4]; - Mat4MulMat4(mat, psys->imat, ob->obmat); + mul_m4_m4m4(mat, psys->imat, ob->obmat); wmMultMatrix(mat); } @@ -3671,9 +3671,9 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv break; case PART_DRAW_CIRC: /* calculate view aligned matrix: */ - Mat4CpyMat4(imat, rv3d->viewinv); - Normalize(imat[0]); - Normalize(imat[1]); + copy_m4_m4(imat, rv3d->viewinv); + normalize_v3(imat[0]); + normalize_v3(imat[1]); /* no break! */ case PART_DRAW_CROSS: case PART_DRAW_AXIS: @@ -3729,9 +3729,9 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv break; } if(part->draw & PART_DRAW_SIZE && part->draw_as!=PART_DRAW_CIRC){ - Mat4CpyMat4(imat, rv3d->viewinv); - Normalize(imat[0]); - Normalize(imat[1]); + copy_m4_m4(imat, rv3d->viewinv); + normalize_v3(imat[0]); + normalize_v3(imat[1]); } if(!create_cdata && pdd && pdd->cdata) { @@ -3903,7 +3903,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv psys_get_particle_on_path(&sim,a,&state,need_v); if(psys->parent) - Mat4MulVecfl(psys->parent->obmat, state.co); + mul_m4_v3(psys->parent->obmat, state.co); /* create actiual particle data */ if(draw_as == PART_DRAW_BB) { @@ -3923,7 +3923,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv state.time=cfra; if(psys_get_particle_state(&sim,a,&state,0)){ if(psys->parent) - Mat4MulVecfl(psys->parent->obmat, state.co); + mul_m4_v3(psys->parent->obmat, state.co); /* create actiual particle data */ if(draw_as == PART_DRAW_BB) { @@ -3946,7 +3946,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv VECCOPY(pdd->ved,state.co); pdd->ved+=3; VECCOPY(vel,state.vel); - VecMulf(vel,timestep); + mul_v3_fl(vel,timestep); VECADD(pdd->ved,state.co,vel); pdd->ved+=3; @@ -4566,10 +4566,10 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, float vec_a[3] = { fac,0, 0}; // Offset perpendicular to the curve float vec_b[3] = {-fac,0, 0}; // Delta along the curve - QuatMulVecf(bevp->quat, vec_a); - QuatMulVecf(bevp->quat, vec_b); - VecAddf(vec_a, vec_a, bevp->vec); - VecAddf(vec_b, vec_b, bevp->vec); + mul_qt_v3(bevp->quat, vec_a); + mul_qt_v3(bevp->quat, vec_b); + add_v3_v3v3(vec_a, vec_a, bevp->vec); + add_v3_v3v3(vec_b, vec_b, bevp->vec); VECSUBFAC(vec_a, vec_a, bevp->dir, fac); VECSUBFAC(vec_b, vec_b, bevp->dir, fac); @@ -4711,8 +4711,8 @@ static void drawspiral(float *cent, float rad, float tmat[][4], int start) VECCOPY(vx, tmat[0]); VECCOPY(vy, tmat[1]); - VecMulf(vx, rad); - VecMulf(vy, rad); + mul_v3_fl(vx, rad); + mul_v3_fl(vy, rad); VECCOPY(vec, cent); @@ -4776,7 +4776,7 @@ static void drawtube(float *vec, float radius, float height, float tmat[][4]) float cur[3]; drawcircball(GL_LINE_LOOP, vec, radius, tmat); - VecCopyf(cur,vec); + copy_v3_v3(cur,vec); cur[2]+=height; drawcircball(GL_LINE_LOOP, cur, radius, tmat); @@ -4797,7 +4797,7 @@ static void drawcone(float *vec, float radius, float height, float tmat[][4]) { float cur[3]; - VecCopyf(cur,vec); + copy_v3_v3(cur,vec); cur[2]+=height; drawcircball(GL_LINE_LOOP, cur, radius, tmat); @@ -4845,9 +4845,9 @@ static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, else UI_ThemeColor(TH_WIRE); wmGetMatrix(tmat); - Mat4Invert(imat, tmat); - Normalize(imat[0]); - Normalize(imat[1]); + invert_m4_m4(imat, tmat); + normalize_v3(imat[0]); + normalize_v3(imat[1]); while(ml) { @@ -4904,14 +4904,14 @@ static void draw_forcefield(Scene *scene, Object *ob) /* calculus here, is reused in PFIELD_FORCE */ wmGetMatrix(tmat); - Mat4Invert(imat, tmat); -// Normalize(imat[0]); // we don't do this because field doesnt scale either... apart from wind! -// Normalize(imat[1]); + invert_m4_m4(imat, tmat); +// normalize_v3(imat[0]); // we don't do this because field doesnt scale either... apart from wind! +// normalize_v3(imat[1]); if (pd->forcefield == PFIELD_WIND) { float force_val; - Mat4One(tmat); + unit_m4(tmat); UI_ThemeColorBlend(curcol, TH_BACK, 0.5); //if (has_ipo_code(ob->ipo, OB_PD_FSTR)) @@ -4947,7 +4947,7 @@ static void draw_forcefield(Scene *scene, Object *ob) else if (pd->forcefield == PFIELD_VORTEX) { float ffall_val, force_val; - Mat4One(tmat); + unit_m4(tmat); //if (has_ipo_code(ob->ipo, OB_PD_FFALL)) // ffall_val = IPO_GetFloatValue(ob->ipo, OB_PD_FFALL, scene->r.cfra); //else @@ -5008,7 +5008,7 @@ static void draw_forcefield(Scene *scene, Object *ob) else if(pd->falloff==PFIELD_FALL_TUBE){ float radius,distance; - Mat4One(tmat); + unit_m4(tmat); vec[0]=vec[1]=0.0f; radius=(pd->flag&PFIELD_USEMAXR)?pd->maxrad:1.0f; @@ -5030,7 +5030,7 @@ static void draw_forcefield(Scene *scene, Object *ob) else if(pd->falloff==PFIELD_FALL_CONE){ float radius,distance; - Mat4One(tmat); + unit_m4(tmat); radius=(pd->flag&PFIELD_USEMAXR)?pd->maxrad:1.0f; radius*=(float)M_PI/180.0f; @@ -5278,7 +5278,7 @@ static void draw_hooks(Object *ob) if (md->type==eModifierType_Hook) { HookModifierData *hmd = (HookModifierData*) md; - VecMat4MulVecfl(vec, ob->obmat, hmd->cent); + mul_v3_m4v3(vec, ob->obmat, hmd->cent); if(hmd->object) { setlinestyle(3); @@ -5310,7 +5310,7 @@ void drawRBpivot(bRigidBodyJointConstraint *data) if(G.f & G_RENDER_SHADOW) return; - EulToMat4(eu,mat); + eul_to_mat4(mat,eu); glLineWidth (4.0f); setlinestyle(2); for (axis=0; axis<3; axis++) { @@ -5319,7 +5319,7 @@ void drawRBpivot(bRigidBodyJointConstraint *data) dir[axis] = 1.f; glBegin(GL_LINES); - Mat4MulVecfl(mat,dir); + mul_m4_v3(mat,dir); v[0] += dir[0]; v[1] += dir[1]; v[2] += dir[2]; @@ -5895,7 +5895,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) vec[0]= vec[1]= vec[2]= 0.0; wmGetMatrix(tmat); - Mat4Invert(imat, tmat); + invert_m4_m4(imat, tmat); setlinestyle(2); drawcircball(GL_LINE_LOOP, vec, ob->inertia, imat); @@ -5982,7 +5982,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) if (cti->get_target_matrix) cti->get_target_matrix(curcon, cob, ct, bsystem_time(scene, ob, (float)(scene->r.cfra), give_timeoffset(ob))); else - Mat4One(ct->matrix); + unit_m4(ct->matrix); setlinestyle(3); glBegin(GL_LINES); diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 3c80441b9e6..168e1f8592d 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -66,7 +66,7 @@ #include "DNA_world_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_edgehash.h" #include "BLI_rand.h" @@ -191,7 +191,7 @@ static int convex(float *p0, float *up, float *a, float *b) float va[3], vb[3], tmp[3]; VECSUB(va, a, p0); VECSUB(vb, b, p0); - Crossf(tmp, va, vb); + cross_v3_v3v3(tmp, va, vb); return INPR(up, tmp) >= 0; } @@ -363,7 +363,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture // get view vector VECCOPY(viewnormal, rv3d->viewinv[2]); - Normalize(viewnormal); + normalize_v3(viewnormal); // find cube vertex that is closest to the viewer for (i=0; i<8; i++) { @@ -433,7 +433,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture break; VECCOPY(tmp_point, viewnormal); - VecMulf(tmp_point, -dd*((ds/dd)-(float)n)); + mul_v3_fl(tmp_point, -dd*((ds/dd)-(float)n)); VECADD(tmp_point2, cv[good_index], tmp_point); d = INPR(tmp_point2, viewnormal); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 4a9042aa31c..ebd1ab6dbff 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_action.h" @@ -148,7 +148,7 @@ RegionView3D *ED_view3d_context_rv3d(bContext *C) if(rv3d==NULL) { ScrArea *sa =CTX_wm_area(C); - if(sa->spacetype==SPACE_VIEW3D) { + if(sa && sa->spacetype==SPACE_VIEW3D) { ARegion *ar; for(ar= sa->regionbase.first; ar; ar= ar->next) if(ar->regiontype==RGN_TYPE_WINDOW) @@ -369,6 +369,9 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar) keymap= WM_keymap_find(wm->defaultconf, "Object Non-modal", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); + keymap= WM_keymap_find(wm->defaultconf, "Frames", 0, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); + /* own keymap, last so modes can override it */ keymap= WM_keymap_find(wm->defaultconf, "View3D Generic", SPACE_VIEW3D, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); @@ -676,7 +679,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes if(selected_objects) CTX_data_id_list_add(result, &base->object->id); else - CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base); + CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); } } } @@ -693,7 +696,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes if(selected_editable_objects) CTX_data_id_list_add(result, &base->object->id); else - CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base); + CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); } } } @@ -710,7 +713,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes if(visible_objects) CTX_data_id_list_add(result, &base->object->id); else - CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base); + CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); } } } @@ -726,7 +729,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes if(selectable_objects) CTX_data_id_list_add(result, &base->object->id); else - CTX_data_list_add(result, &scene->id, &RNA_UnknownType, base); + CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); } } } @@ -736,7 +739,7 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes else if(CTX_data_equals(member, "active_base")) { if(scene->basact && (scene->basact->lay & lay)) if((scene->basact->object->restrictflag & OB_RESTRICT_VIEW)==0) - CTX_data_pointer_set(result, &scene->id, &RNA_UnknownType, scene->basact); + CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, scene->basact); return 1; } @@ -747,7 +750,11 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes return 1; } - return 0; + else { + return 0; /* not found */ + } + + return -1; /* found but not available */ } /* only called once, from space/spacetypes.c */ @@ -769,7 +776,7 @@ void ED_spacetype_view3d(void) /* regions: main window */ art= MEM_callocN(sizeof(ARegionType), "spacetype view3d region"); art->regionid = RGN_TYPE_WINDOW; - art->keymapflag= ED_KEYMAP_FRAMES|ED_KEYMAP_GPENCIL; + art->keymapflag= ED_KEYMAP_GPENCIL; art->draw= view3d_main_area_draw; art->init= view3d_main_area_init; art->free= view3d_main_area_free; diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index 2edccacff7a..d3a922af67e 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -52,7 +52,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -176,7 +176,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d if(eve->f & SELECT) { evedef= eve; tot++; - VecAddf(median, median, eve->co); + add_v3_v3v3(median, median, eve->co); } eve= eve->next; } @@ -232,18 +232,18 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d a= nu->pntsu; while(a--) { if(bezt->f2 & SELECT) { - VecAddf(median, median, bezt->vec[1]); + add_v3_v3v3(median, median, bezt->vec[1]); tot++; median[4]+= bezt->weight; totweight++; } else { if(bezt->f1 & SELECT) { - VecAddf(median, median, bezt->vec[0]); + add_v3_v3v3(median, median, bezt->vec[0]); tot++; } if(bezt->f3 & SELECT) { - VecAddf(median, median, bezt->vec[2]); + add_v3_v3v3(median, median, bezt->vec[2]); tot++; } } @@ -255,7 +255,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d a= nu->pntsu*nu->pntsv; while(a--) { if(bp->f1 & SELECT) { - VecAddf(median, median, bp->vec); + add_v3_v3v3(median, median, bp->vec); median[3]+= bp->vec[3]; totw++; tot++; @@ -277,7 +277,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d bp= lt->editlatt->def; while(a--) { if(bp->f1 & SELECT) { - VecAddf(median, median, bp->vec); + add_v3_v3v3(median, median, bp->vec); tot++; median[4]+= bp->weight; totweight++; @@ -296,7 +296,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d if(totweight) median[4] /= (float)totweight; if(v3d->flag & V3D_GLOBAL_STATS) - Mat4MulVecfl(ob->obmat, median); + mul_m4_v3(ob->obmat, median); if(block) { // buttons int but_y; @@ -371,11 +371,11 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d memcpy(ve_median, tfp->ve_median, sizeof(tfp->ve_median)); if(v3d->flag & V3D_GLOBAL_STATS) { - Mat4Invert(ob->imat, ob->obmat); - Mat4MulVecfl(ob->imat, median); - Mat4MulVecfl(ob->imat, ve_median); + invert_m4_m4(ob->imat, ob->obmat); + mul_m4_v3(ob->imat, median); + mul_m4_v3(ob->imat, ve_median); } - VecSubf(median, ve_median, median); + sub_v3_v3v3(median, ve_median, median); median[3]= ve_median[3]-median[3]; median[4]= ve_median[4]-median[4]; @@ -388,7 +388,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d eve= em->verts.first; while(eve) { if(eve->f & SELECT) { - VecAddf(eve->co, eve->co, median); + add_v3_v3v3(eve->co, eve->co, median); } eve= eve->next; } @@ -423,17 +423,17 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d a= nu->pntsu; while(a--) { if(bezt->f2 & SELECT) { - VecAddf(bezt->vec[0], bezt->vec[0], median); - VecAddf(bezt->vec[1], bezt->vec[1], median); - VecAddf(bezt->vec[2], bezt->vec[2], median); + add_v3_v3v3(bezt->vec[0], bezt->vec[0], median); + add_v3_v3v3(bezt->vec[1], bezt->vec[1], median); + add_v3_v3v3(bezt->vec[2], bezt->vec[2], median); bezt->weight+= median[4]; } else { if(bezt->f1 & SELECT) { - VecAddf(bezt->vec[0], bezt->vec[0], median); + add_v3_v3v3(bezt->vec[0], bezt->vec[0], median); } if(bezt->f3 & SELECT) { - VecAddf(bezt->vec[2], bezt->vec[2], median); + add_v3_v3v3(bezt->vec[2], bezt->vec[2], median); } } bezt++; @@ -444,7 +444,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d a= nu->pntsu*nu->pntsv; while(a--) { if(bp->f1 & SELECT) { - VecAddf(bp->vec, bp->vec, median); + add_v3_v3v3(bp->vec, bp->vec, median); bp->vec[3]+= median[3]; bp->weight+= median[4]; } @@ -466,7 +466,7 @@ static void v3d_editvertex_buts(const bContext *C, uiLayout *layout, View3D *v3d bp= lt->editlatt->def; while(a--) { if(bp->f1 & SELECT) { - VecAddf(bp->vec, bp->vec, median); + add_v3_v3v3(bp->vec, bp->vec, median); bp->weight+= median[4]; } bp++; @@ -575,22 +575,15 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr) static void v3d_posearmature_buts(uiLayout *layout, View3D *v3d, Object *ob, float lim) { // uiBlock *block= uiLayoutGetBlock(layout); - bArmature *arm; +// bArmature *arm; bPoseChannel *pchan; - Bone *bone= NULL; // TransformProperties *tfp= v3d->properties_storage; PointerRNA pchanptr; uiLayout *col; // uiLayout *row; - arm = ob->data; - if (!arm || !ob->pose) return; + pchan= get_active_posechannel(ob); - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - bone = pchan->bone; - if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer)) - break; - } // row= uiLayoutRow(layout, 0); if (!pchan) { @@ -613,13 +606,13 @@ static void v3d_posearmature_buts(uiLayout *layout, View3D *v3d, Object *ob, flo if (pchan->rotmode == ROT_MODE_AXISANGLE) { float quat[4]; /* convert to euler, passing through quats... */ - AxisAngleToQuat(quat, pchan->rotAxis, pchan->rotAngle); - QuatToEul(quat, tfp->ob_eul); + axis_angle_to_quat(quat, pchan->rotAxis, pchan->rotAngle); + quat_to_eul( tfp->ob_eul,quat); } else if (pchan->rotmode == ROT_MODE_QUAT) - QuatToEul(pchan->quat, tfp->ob_eul); + quat_to_eul( tfp->ob_eul,pchan->quat); else - VecCopyf(tfp->ob_eul, pchan->eul); + copy_v3_v3(tfp->ob_eul, pchan->eul); tfp->ob_eul[0]*= 180.0/M_PI; tfp->ob_eul[1]*= 180.0/M_PI; tfp->ob_eul[2]*= 180.0/M_PI; @@ -691,14 +684,9 @@ static void v3d_editarmature_buts(uiLayout *layout, View3D *v3d, Object *ob, flo uiLayout *col; PointerRNA eboneptr; - ebone= arm->edbo->first; + ebone= arm->act_edbone; - for (ebone = arm->edbo->first; ebone; ebone=ebone->next){ - if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer)) - break; - } - - if (!ebone) + if (!ebone || (ebone->layer & arm->layer)==0) return; // row= uiLayoutRow(layout, 0); @@ -821,19 +809,10 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event) case B_ARMATUREPANEL3: // rotate button on channel { - bArmature *arm; bPoseChannel *pchan; - Bone *bone; float eul[3]; - arm = ob->data; - if (!arm || !ob->pose) return; - - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - bone = pchan->bone; - if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer)) - break; - } + pchan= get_active_posechannel(ob); if (!pchan) return; /* make a copy to eul[3], to allow TAB on buttons to work */ @@ -844,13 +823,13 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event) if (pchan->rotmode == ROT_MODE_AXISANGLE) { float quat[4]; /* convert to axis-angle, passing through quats */ - EulToQuat(eul, quat); - QuatToAxisAngle(quat, pchan->rotAxis, &pchan->rotAngle); + eul_to_quat( quat,eul); + quat_to_axis_angle( pchan->rotAxis, &pchan->rotAngle,quat); } else if (pchan->rotmode == ROT_MODE_QUAT) - EulToQuat(eul, pchan->quat); + eul_to_quat( pchan->quat,eul); else - VecCopyf(pchan->eul, eul); + copy_v3_v3(pchan->eul, eul); } /* no break, pass on */ case B_ARMATUREPANEL2: diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 64ea574b011..8aa63518e96 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -48,7 +48,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_anim.h" @@ -251,7 +251,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, char **grid_u vec4[0]=vec4[1]=vec4[2]=0.0; vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); fx= vec4[0]; fy= vec4[1]; fw= vec4[3]; @@ -266,7 +266,7 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, char **grid_u vec4[2]= 0.0; vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); fx= vec4[0]; fy= vec4[1]; fw= vec4[3]; @@ -596,7 +596,7 @@ static void draw_view_axis(RegionView3D *rv3d) /* X */ vec[0] = vec[3] = 1; vec[1] = vec[2] = 0; - QuatMulVecf(rv3d->viewquat, vec); + mul_qt_v3(rv3d->viewquat, vec); UI_make_axis_color((char *)gridcol, (char *)col, 'x'); rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v); @@ -616,7 +616,7 @@ static void draw_view_axis(RegionView3D *rv3d) /* Y */ vec[1] = vec[3] = 1; vec[0] = vec[2] = 0; - QuatMulVecf(rv3d->viewquat, vec); + mul_qt_v3(rv3d->viewquat, vec); UI_make_axis_color((char *)gridcol, (char *)col, 'y'); rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v); @@ -636,7 +636,7 @@ static void draw_view_axis(RegionView3D *rv3d) /* Z */ vec[2] = vec[3] = 1; vec[1] = vec[0] = 0; - QuatMulVecf(rv3d->viewquat, vec); + mul_qt_v3(rv3d->viewquat, vec); UI_make_axis_color((char *)gridcol, (char *)col, 'z'); rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v); @@ -791,21 +791,17 @@ static void draw_selected_name(Scene *scene, Object *ob, View3D *v3d) /* show name of active bone too (if possible) */ if(arm->edbo) { - EditBone *ebo; - for (ebo=arm->edbo->first; ebo; ebo=ebo->next){ - if ((ebo->flag & BONE_ACTIVE) && (ebo->layer & arm->layer)) { - name= ebo->name; - break; - } - } + + if(arm->act_edbone) + name= ((EditBone *)arm->act_edbone)->name; + } - else if(ob->pose && (ob->mode & OB_MODE_POSE)) { - bPoseChannel *pchan; - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if((pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) { - name= pchan->name; - break; - } + else if(ob->mode & OB_MODE_POSE) { + if(arm->act_bone) { + + if(arm->act_bone->layer & arm->layer) + name= arm->act_bone->name; + } } if(name && markern) @@ -1562,7 +1558,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas /* need this for next part of code */ bb= object_get_boundbox(dob->ob); - Mat4One(dob->ob->obmat); /* obmat gets restored */ + unit_m4(dob->ob->obmat); /* obmat gets restored */ displist= glGenLists(1); glNewList(displist, GL_COMPILE); @@ -1580,7 +1576,7 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas wmLoadMatrix(rv3d->viewmat); } else { - Mat4CpyMat4(dob->ob->obmat, dob->mat); + copy_m4_m4(dob->ob->obmat, dob->mat); draw_object(scene, ar, v3d, &tbase, DRAW_CONSTCOLOR); } @@ -1693,9 +1689,9 @@ void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *)) setwinmatrixview3d(ar, v3d, NULL); /* 0= no pick rect */ setviewmatrixview3d(scene, v3d, rv3d); /* note: calls where_is_object for camera... */ - Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); - Mat4Invert(rv3d->persinv, rv3d->persmat); - Mat4Invert(rv3d->viewinv, rv3d->viewmat); + mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); + invert_m4_m4(rv3d->persinv, rv3d->persmat); + invert_m4_m4(rv3d->viewinv, rv3d->viewmat); glClear(GL_DEPTH_BUFFER_BIT); @@ -1903,29 +1899,29 @@ static void view3d_main_area_setup_view(Scene *scene, View3D *v3d, ARegion *ar, /* setup window matrices */ if(winmat) - Mat4CpyMat4(rv3d->winmat, winmat); + copy_m4_m4(rv3d->winmat, winmat); else setwinmatrixview3d(ar, v3d, NULL); /* NULL= no pickrect */ /* setup view matrix */ if(viewmat) - Mat4CpyMat4(rv3d->viewmat, viewmat); + copy_m4_m4(rv3d->viewmat, viewmat); else setviewmatrixview3d(scene, v3d, rv3d); /* note: calls where_is_object for camera... */ /* update utilitity matrices */ - Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); - Mat4Invert(rv3d->persinv, rv3d->persmat); - Mat4Invert(rv3d->viewinv, rv3d->viewmat); + mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); + invert_m4_m4(rv3d->persinv, rv3d->persmat); + invert_m4_m4(rv3d->viewinv, rv3d->viewmat); /* calculate pixelsize factor once, is used for lamps and obcenters */ { float len1, len2, vec[3]; VECCOPY(vec, rv3d->persinv[0]); - len1= Normalize(vec); + len1= normalize_v3(vec); VECCOPY(vec, rv3d->persinv[1]); - len2= Normalize(vec); + len2= normalize_v3(vec); rv3d->pixsize= 2.0f*(len1>len2?len1:len2); @@ -2009,6 +2005,14 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, glDisable(GL_DEPTH_TEST); } + /* draw grease-pencil stuff */ + draw_gpencil_3dview_ext(scene, ar, 1); + + ED_region_pixelspace(ar); + + /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ + draw_gpencil_3dview_ext(scene, ar, 0); + GPU_free_images(); /* restore size */ @@ -2172,7 +2176,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) glDisable(GL_DEPTH_TEST); } - /* draw grease-pencil stuff */ + /* draw grease-pencil stuff (3d-space strokes) */ //if (v3d->flag2 & V3D_DISPGP) draw_gpencil_3dview((bContext *)C, 1); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 1cbb7d0ab56..6ef08a1c217 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -46,7 +46,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BKE_action.h" @@ -141,12 +141,12 @@ static void view3d_boxview_clip(ScrArea *sa) } /* normals for plane equations */ - CalcNormFloat(bb->vec[0], bb->vec[1], bb->vec[4], clip[0]); - CalcNormFloat(bb->vec[1], bb->vec[2], bb->vec[5], clip[1]); - CalcNormFloat(bb->vec[2], bb->vec[3], bb->vec[6], clip[2]); - CalcNormFloat(bb->vec[3], bb->vec[0], bb->vec[7], clip[3]); - CalcNormFloat(bb->vec[4], bb->vec[5], bb->vec[6], clip[4]); - CalcNormFloat(bb->vec[0], bb->vec[2], bb->vec[1], clip[5]); + normal_tri_v3( clip[0],bb->vec[0], bb->vec[1], bb->vec[4]); + normal_tri_v3( clip[1],bb->vec[1], bb->vec[2], bb->vec[5]); + normal_tri_v3( clip[2],bb->vec[2], bb->vec[3], bb->vec[6]); + normal_tri_v3( clip[3],bb->vec[3], bb->vec[0], bb->vec[7]); + normal_tri_v3( clip[4],bb->vec[4], bb->vec[5], bb->vec[6]); + normal_tri_v3( clip[5],bb->vec[0], bb->vec[2], bb->vec[1]); /* then plane equations */ for(val=0; val<5; val++) { @@ -299,7 +299,7 @@ static void viewops_data(bContext *C, wmOperator *op, wmEvent *event) /* If there's no selection, lastofs is unmodified and last value since static */ calculateTransformCenter(C, event, V3D_CENTROID, lastofs); VECCOPY(vod->obofs, lastofs); - VecMulf(vod->obofs, -1.0f); + mul_v3_fl(vod->obofs, -1.0f); } /* lookup, we dont pass on v3d to prevent confusement */ @@ -422,13 +422,13 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) calctrackballvec(&vod->ar->winrct, x, y, newvec); - VecSubf(dvec, newvec, vod->trackvec); + sub_v3_v3v3(dvec, newvec, vod->trackvec); si= sqrt(dvec[0]*dvec[0]+ dvec[1]*dvec[1]+ dvec[2]*dvec[2]); si/= (2.0*TRACKBALLSIZE); - Crossf(q1+1, vod->trackvec, newvec); - Normalize(q1+1); + cross_v3_v3v3(q1+1, vod->trackvec, newvec); + normalize_v3(q1+1); /* Allow for rotation beyond the interval * [-pi, pi] */ @@ -447,19 +447,19 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) q1[1]*= si; q1[2]*= si; q1[3]*= si; - QuatMul(rv3d->viewquat, q1, vod->oldquat); + mul_qt_qtqt(rv3d->viewquat, q1, vod->oldquat); if (use_sel) { /* compute the post multiplication quat, to rotate the offset correctly */ QUATCOPY(q1, vod->oldquat); - QuatConj(q1); - QuatMul(q1, q1, rv3d->viewquat); + conjugate_qt(q1); + mul_qt_qtqt(q1, q1, rv3d->viewquat); - QuatConj(q1); /* conj == inv for unit quat */ + conjugate_qt(q1); /* conj == inv for unit quat */ VECCOPY(rv3d->ofs, vod->ofs); - VecSubf(rv3d->ofs, rv3d->ofs, vod->obofs); - QuatMulVecf(q1, rv3d->ofs); - VecAddf(rv3d->ofs, rv3d->ofs, vod->obofs); + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, vod->obofs); + mul_qt_v3(q1, rv3d->ofs); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, vod->obofs); } } else { @@ -475,12 +475,12 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) const float sensitivity = 0.0035; /* Get the 3x3 matrix and its inverse from the quaternion */ - QuatToMat3(rv3d->viewquat, m); - Mat3Inv(m_inv,m); + quat_to_mat3( m,rv3d->viewquat); + invert_m3_m3(m_inv,m); /* Determine the direction of the x vector (for rotating up and down) */ /* This can likely be compuated directly from the quaternion. */ - Mat3MulVecfl(m_inv,xvec); + mul_m3_v3(m_inv,xvec); /* Perform the up/down rotation */ phi = sensitivity * -(y - vod->oldy); @@ -489,13 +489,13 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) q1[1] = si * xvec[0]; q1[2] = si * xvec[1]; q1[3] = si * xvec[2]; - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); if (use_sel) { - QuatConj(q1); /* conj == inv for unit quat */ - VecSubf(rv3d->ofs, rv3d->ofs, vod->obofs); - QuatMulVecf(q1, rv3d->ofs); - VecAddf(rv3d->ofs, rv3d->ofs, vod->obofs); + conjugate_qt(q1); /* conj == inv for unit quat */ + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, vod->obofs); + mul_qt_v3(q1, rv3d->ofs); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, vod->obofs); } /* Perform the orbital rotation */ @@ -503,13 +503,13 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) q1[0] = cos(phi); q1[1] = q1[2] = 0.0; q1[3] = sin(phi); - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); if (use_sel) { - QuatConj(q1); - VecSubf(rv3d->ofs, rv3d->ofs, vod->obofs); - QuatMulVecf(q1, rv3d->ofs); - VecAddf(rv3d->ofs, rv3d->ofs, vod->obofs); + conjugate_qt(q1); + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, vod->obofs); + mul_qt_v3(q1, rv3d->ofs); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, vod->obofs); } } @@ -519,17 +519,17 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) float viewmat[3][3]; - QuatToMat3(rv3d->viewquat, viewmat); + quat_to_mat3( viewmat,rv3d->viewquat); for (i = 0 ; i < 39; i++){ float snapmat[3][3]; float view = (int)snapquats[i][4]; - QuatToMat3(snapquats[i], snapmat); + quat_to_mat3( snapmat,snapquats[i]); - if ((Inpf(snapmat[0], viewmat[0]) > thres) && - (Inpf(snapmat[1], viewmat[1]) > thres) && - (Inpf(snapmat[2], viewmat[2]) > thres)){ + if ((dot_v3v3(snapmat[0], viewmat[0]) > thres) && + (dot_v3v3(snapmat[1], viewmat[1]) > thres) && + (dot_v3v3(snapmat[2], viewmat[2]) > thres)){ QUATCOPY(rv3d->viewquat, snapquats[i]); @@ -678,7 +678,7 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y) float dvec[3]; window_to_3d_delta(vod->ar, dvec, x-vod->oldx, y-vod->oldy); - VecAddf(vod->rv3d->ofs, vod->rv3d->ofs, dvec); + add_v3_v3v3(vod->rv3d->ofs, vod->rv3d->ofs, dvec); if(vod->rv3d->viewlock & RV3D_BOXVIEW) view3d_boxview_sync(vod->sa, vod->ar); @@ -868,9 +868,9 @@ static void viewzoom_apply(ViewOpsData *vod, int x, int y) upvec[0] = upvec[1] = 0.0f; upvec[2] = (vod->dist0 - vod->rv3d->dist) * vod->grid; vod->rv3d->dist = vod->dist0; - Mat3CpyMat4(mat, vod->rv3d->viewinv); - Mat3MulVecfl(mat, upvec); - VecAddf(vod->rv3d->ofs, vod->rv3d->ofs, upvec); + copy_m3_m4(mat, vod->rv3d->viewinv); + mul_m3_v3(mat, upvec); + add_v3_v3v3(vod->rv3d->ofs, vod->rv3d->ofs, upvec); } else { /* these limits were in old code too */ if(vod->rv3d->dist<0.001*vod->grid) vod->rv3d->dist= 0.001*vod->grid; @@ -1142,10 +1142,10 @@ static int viewcenter_exec(bContext *C, wmOperator *op) /* like a localview with if(pchan->bone->layer & arm->layer) { ok= 1; VECCOPY(vec, pchan->pose_head); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); DO_MINMAX(vec, min, max); VECCOPY(vec, pchan->pose_tail); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); DO_MINMAX(vec, min, max); } } @@ -1401,7 +1401,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) dvec[1] = p[1]-p_corner[1]; dvec[2] = p[2]-p_corner[2]; - new_dist = VecLength(dvec); + new_dist = len_v3(dvec); if(new_dist <= v3d->near*1.5) new_dist= v3d->near*1.5; new_ofs[0] = -p[0]; @@ -1430,7 +1430,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) window_to_3d_delta(ar, dvec, (rect.xmin+rect.xmax-vb[0])/2, (rect.ymin+rect.ymax-vb[1])/2); /* center the view to the center of the rectangle */ - VecSubf(new_ofs, new_ofs, dvec); + sub_v3_v3v3(new_ofs, new_ofs, dvec); } /* work out the ratios, so that everything selected fits when we zoom */ @@ -1524,9 +1524,9 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s /* same as transform manipulator when normal is set */ ED_getTransformOrientationMatrix(C, twmat, TRUE); - Mat3ToQuat(twmat, obact_quat); - QuatInv(obact_quat); - QuatMul(new_quat, new_quat, obact_quat); + mat3_to_quat( obact_quat,twmat); + invert_qt(obact_quat); + mul_qt_qtqt(new_quat, new_quat, obact_quat); rv3d->view= view= 0; } @@ -1704,14 +1704,14 @@ static int vieworbit_exec(bContext *C, wmOperator *op) q1[0]= (float)cos(phi); q1[1]= q1[2]= 0.0; q1[3]= si; - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); rv3d->view= 0; } if(orbitdir == V3D_VIEW_STEPDOWN || orbitdir == V3D_VIEW_STEPUP) { /* horizontal axis */ VECCOPY(q1+1, rv3d->viewinv[0]); - Normalize(q1+1); + normalize_v3(q1+1); phi= (float)(M_PI/360.0)*U.pad_rot_angle; if(orbitdir == V3D_VIEW_STEPDOWN) phi= -phi; si= (float)sin(phi); @@ -1719,7 +1719,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op) q1[1]*= si; q1[2]*= si; q1[3]*= si; - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); rv3d->view= 0; } ED_region_tag_redraw(ar); @@ -1881,8 +1881,7 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op) /* then plane equations */ for(val=0; val<4; val++) { - CalcNormFloat(rv3d->clipbb->vec[val], rv3d->clipbb->vec[val==3?0:val+1], rv3d->clipbb->vec[val+4], - rv3d->clip[val]); + normal_tri_v3( rv3d->clip[val],rv3d->clipbb->vec[val], rv3d->clipbb->vec[val==3?0:val+1], rv3d->clipbb->vec[val+4]); rv3d->clip[val][3]= - rv3d->clip[val][0]*rv3d->clipbb->vec[val][0] - rv3d->clip[val][1]*rv3d->clipbb->vec[val][1] @@ -1961,7 +1960,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *op, wmEvent *event) if(mval[0]!=IS_CLIPPED) { window_to_3d_delta(ar, dvec, mval[0]-mx, mval[1]-my); - VecSubf(fp, fp, dvec); + sub_v3_v3v3(fp, fp, dvec); } else { @@ -2248,9 +2247,9 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode) m_dist = rv3d->dist; upvec[0] = upvec[1] = 0; upvec[2] = rv3d->dist; - Mat3CpyMat4(mat, rv3d->viewinv); - Mat3MulVecfl(mat, upvec); - VecSubf(rv3d->ofs, rv3d->ofs, upvec); + copy_m3_m4(mat, rv3d->viewinv); + mul_m3_v3(mat, upvec); + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, upvec); rv3d->dist = 0.0; } @@ -2264,16 +2263,16 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode) // rotate device x and y by view z - Mat3CpyMat4(mat, rv3d->viewinv); + copy_m3_m4(mat, rv3d->viewinv); mat[2][2] = 0.0f; - Mat3MulVecfl(mat, rvec); + mul_m3_v3(mat, rvec); // rotate the view - phi = Normalize(rvec); + phi = normalize_v3(rvec); if(phi != 0) { - VecRotToQuat(rvec,phi,q1); - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + axis_angle_to_quat(q1,rvec,phi); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); } @@ -2286,13 +2285,13 @@ void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode) // the next three lines rotate the x and y translation coordinates // by the current z axis angle - Mat3CpyMat4(mat, rv3d->viewinv); + copy_m3_m4(mat, rv3d->viewinv); mat[2][2] = 0.0f; - Mat3MulVecfl(mat, tvec); + mul_m3_v3(mat, tvec); // translate the view - VecSubf(rv3d->ofs, rv3d->ofs, tvec); + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, tvec); /*---------------------------------------------------- @@ -2351,9 +2350,9 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) rv3d->dist = m_dist; upvec[0] = upvec[1] = 0; upvec[2] = rv3d->dist; - Mat3CpyMat4(mat, rv3d->viewinv); - Mat3MulVecfl(mat, upvec); - VecAddf(rv3d->ofs, rv3d->ofs, upvec); + copy_m3_m4(mat, rv3d->viewinv); + mul_m3_v3(mat, upvec); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, upvec); } /*---------------------------------------------------- @@ -2415,8 +2414,8 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) d = 1.0f; /* if (ob) { - VecSubf(diff, obofs, rv3d->ofs); - d = VecLength(diff); + sub_v3_v3v3(diff, obofs, rv3d->ofs); + d = len_v3(diff); } */ @@ -2431,7 +2430,7 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) dvec[0] = curareaX * rv3d->persinv[0][0] + curareaY * rv3d->persinv[1][0]; dvec[1] = curareaX * rv3d->persinv[0][1] + curareaY * rv3d->persinv[1][1]; dvec[2] = curareaX * rv3d->persinv[0][2] + curareaY * rv3d->persinv[1][2]; - VecAddf(rv3d->ofs, rv3d->ofs, dvec); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, dvec); /*---------------------------------------------------- * ndof device dolly @@ -2456,14 +2455,14 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) */ /* Get the 3x3 matrix and its inverse from the quaternion */ - QuatToMat3(rv3d->viewquat, m); - Mat3Inv(m_inv,m); + quat_to_mat3( m,rv3d->viewquat); + invert_m3_m3(m_inv,m); /* Determine the direction of the x vector (for rotating up and down) */ /* This can likely be compuated directly from the quaternion. */ - Mat3MulVecfl(m_inv,xvec); - Mat3MulVecfl(m_inv,yvec); - Mat3MulVecfl(m_inv,zvec); + mul_m3_v3(m_inv,xvec); + mul_m3_v3(m_inv,yvec); + mul_m3_v3(m_inv,zvec); /* Perform the up/down rotation */ phi = sbadjust * rsens * /*0.5f * */ fval[3]; /* spin vertically half as fast as horizontally */ @@ -2472,13 +2471,13 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) q1[1] = si * xvec[0]; q1[2] = si * xvec[1]; q1[3] = si * xvec[2]; - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); if (use_sel) { - QuatConj(q1); /* conj == inv for unit quat */ - VecSubf(rv3d->ofs, rv3d->ofs, obofs); - QuatMulVecf(q1, rv3d->ofs); - VecAddf(rv3d->ofs, rv3d->ofs, obofs); + conjugate_qt(q1); /* conj == inv for unit quat */ + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, obofs); + mul_qt_v3(q1, rv3d->ofs); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, obofs); } /* Perform the orbital rotation */ @@ -2497,13 +2496,13 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) q1[0] = cos(phi); q1[1] = q1[2] = 0.0; q1[3] = sin(phi); - QuatMul(rv3d->viewquat, rv3d->viewquat, q1); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); if (use_sel) { - QuatConj(q1); - VecSubf(rv3d->ofs, rv3d->ofs, obofs); - QuatMulVecf(q1, rv3d->ofs); - VecAddf(rv3d->ofs, rv3d->ofs, obofs); + conjugate_qt(q1); + sub_v3_v3v3(rv3d->ofs, rv3d->ofs, obofs); + mul_qt_v3(q1, rv3d->ofs); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, obofs); } /*---------------------------------------------------- diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index d37c81904cf..7e2f41b369b 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -85,7 +85,7 @@ #include "BIF_gl.h" #include "BIF_glutil.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" @@ -635,7 +635,7 @@ void do_view3d_transform_moveaxismenu(bContext *C, void *arg, int event) #if 0 float mat[3][3]; - Mat3One(mat); + unit_m3(mat); switch(event) { @@ -702,7 +702,7 @@ void do_view3d_transform_rotateaxismenu(bContext *C, void *arg, int event) #if 0 float mat[3][3]; - Mat3One(mat); + unit_m3(mat); switch(event) { @@ -769,7 +769,7 @@ void do_view3d_transform_scaleaxismenu(bContext *C, void *arg, int event) #if 0 float mat[3][3]; - Mat3One(mat); + unit_m3(mat); switch(event) { diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index adda08202c0..b8945c849ae 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -39,7 +39,7 @@ #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BKE_context.h" diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index f0425974f29..508bf56cc71 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -49,7 +49,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -120,7 +120,7 @@ void view3d_get_view_aligned_coordinate(ViewContext *vc, float *fp, short mval[2 if(mval[0]!=IS_CLIPPED) { window_to_3d_delta(vc->ar, dvec, mval[0]-mx, mval[1]-my); - VecSubf(fp, fp, dvec); + sub_v3_v3v3(fp, fp, dvec); } } @@ -129,7 +129,7 @@ void view3d_get_transformation(ViewContext *vc, Object *ob, bglMats *mats) float cpy[4][4]; int i, j; - Mat4MulMat4(cpy, ob->obmat, vc->rv3d->viewmat); + mul_m4_m4m4(cpy, ob->obmat, vc->rv3d->viewmat); for(i = 0; i < 4; ++i) { for(j = 0; j < 4; ++j) { @@ -326,9 +326,9 @@ int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, in /* no points in lasso, so we have to intersect with lasso edge */ - if( IsectLL2Ds(mcords[0], mcords[moves-1], v1, v2) > 0) return 1; + if( isect_line_line_v2_short(mcords[0], mcords[moves-1], v1, v2) > 0) return 1; for(a=0; a<moves-1; a++) { - if( IsectLL2Ds(mcords[a], mcords[a+1], v1, v2) > 0) return 1; + if( isect_line_line_v2_short(mcords[a], mcords[a+1], v1, v2) > 0) return 1; } return 0; @@ -349,15 +349,22 @@ static void do_lasso_select_pose(ViewContext *vc, short mcords[][2], short moves for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { VECCOPY(vec, pchan->pose_head); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); project_short(vc->ar, vec, sco1); VECCOPY(vec, pchan->pose_tail); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); project_short(vc->ar, vec, sco2); if(lasso_inside_edge(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1])) { if(select) pchan->bone->flag |= BONE_SELECTED; - else pchan->bone->flag &= ~(BONE_ACTIVE|BONE_SELECTED); + else pchan->bone->flag &= ~BONE_SELECTED; + } + } + + { + bArmature *arm= ob->data; + if(arm->act_bone && (arm->act_bone->flag & BONE_SELECTED)==0) { + arm->act_bone= NULL; } } } @@ -618,10 +625,10 @@ static void do_lasso_select_armature(ViewContext *vc, short mcords[][2], short m for (ebone= arm->edbo->first; ebone; ebone=ebone->next) { VECCOPY(vec, ebone->head); - Mat4MulVecfl(vc->obedit->obmat, vec); + mul_m4_v3(vc->obedit->obmat, vec); project_short(vc->ar, vec, sco1); VECCOPY(vec, ebone->tail); - Mat4MulVecfl(vc->obedit->obmat, vec); + mul_m4_v3(vc->obedit->obmat, vec); project_short(vc->ar, vec, sco2); didpoint= 0; @@ -638,9 +645,11 @@ static void do_lasso_select_armature(ViewContext *vc, short mcords[][2], short m /* if one of points selected, we skip the bone itself */ if(didpoint==0 && lasso_inside_edge(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1])) { if(select) ebone->flag |= BONE_TIPSEL|BONE_ROOTSEL|BONE_SELECTED; - else ebone->flag &= ~(BONE_ACTIVE|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + else ebone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); } } + + ED_armature_validate_active(arm); } static void do_lasso_select_facemode(ViewContext *vc, short mcords[][2], short moves, short select) @@ -1218,7 +1227,7 @@ int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, v2[0]= x2; v2[1]= y2; - if( PdistVL2Dfl(v3, v1, v2) < (float)rad ) return 1; + if( dist_to_line_segment_v2(v3, v1, v2) < (float)rad ) return 1; return 0; } @@ -1534,8 +1543,12 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) // XXX select_actionchannel_by_name(base->object->action, bone->name, 1); } else { - bone->flag &= ~(BONE_ACTIVE|BONE_SELECTED); + bArmature *arm= base->object->data; + bone->flag &= ~BONE_SELECTED; // XXX select_actionchannel_by_name(base->object->action, bone->name, 0); + if(arm->act_bone==bone) + arm->act_bone= NULL; + } } } @@ -1704,6 +1717,7 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa vc->em= ((Mesh *)vc->obedit->data)->edit_mesh; + data.vc = vc; data.select = selecting; data.mval[0] = mval[0]; data.mval[1] = mval[1]; @@ -1846,12 +1860,12 @@ static void armature_circle_select(ViewContext *vc, int selecting, short *mval, /* project head location to screenspace */ VECCOPY(vec, ebone->head); - Mat4MulVecfl(vc->obedit->obmat, vec); + mul_m4_v3(vc->obedit->obmat, vec); project_short(vc->ar, vec, sco1); /* project tail location to screenspace */ VECCOPY(vec, ebone->tail); - Mat4MulVecfl(vc->obedit->obmat, vec); + mul_m4_v3(vc->obedit->obmat, vec); project_short(vc->ar, vec, sco2); /* check if the head and/or tail is in the circle @@ -1868,9 +1882,11 @@ static void armature_circle_select(ViewContext *vc, int selecting, short *mval, if (selecting) ebone->flag |= BONE_TIPSEL|BONE_ROOTSEL|BONE_SELECTED; else - ebone->flag &= ~(BONE_ACTIVE|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + ebone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); } } + + ED_armature_validate_active(arm); } /** Callbacks for circle selection in Editmode */ diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 205d3e6df8c..933b12ae679 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -48,7 +48,7 @@ #include "DNA_view3d_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_linklist.h" @@ -135,8 +135,8 @@ static void special_transvert_update(Scene *scene, Object *obedit) if (tv) { float diffvec[3]; - VecSubf(diffvec, tv->loc, tv->oldloc); - VecAddf(ebo->tail, ebo->tail, diffvec); + sub_v3_v3v3(diffvec, tv->loc, tv->oldloc); + add_v3_v3v3(ebo->tail, ebo->tail, diffvec); a++; if (a<tottrans) tv++; @@ -454,21 +454,21 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op) make_trans_verts(obedit, bmat[0], bmat[1], 0); if(tottrans==0) return OPERATOR_CANCELLED; - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); tv= transvmain; for(a=0; a<tottrans; a++, tv++) { VECCOPY(vec, tv->loc); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, obedit->obmat[3]); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, obedit->obmat[3]); vec[0]= v3d->gridview*floor(.5+ vec[0]/gridf); vec[1]= v3d->gridview*floor(.5+ vec[1]/gridf); vec[2]= v3d->gridview*floor(.5+ vec[2]/gridf); - VecSubf(vec, vec, obedit->obmat[3]); + sub_v3_v3v3(vec, vec, obedit->obmat[3]); - Mat3MulVecfl(imat, vec); + mul_m3_v3(imat, vec); VECCOPY(tv->loc, vec); } @@ -525,8 +525,8 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op) if(ob->parent) { where_is_object(scene, ob); - Mat3Inv(imat, originmat); - Mat3MulVecfl(imat, vec); + invert_m3_m3(imat, originmat); + mul_m3_v3(imat, vec); ob->loc[0]+= vec[0]; ob->loc[1]+= vec[1]; ob->loc[2]+= vec[2]; @@ -586,8 +586,8 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) make_trans_verts(obedit, bmat[0], bmat[1], 0); if(tottrans==0) return OPERATOR_CANCELLED; - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); tv= transvmain; for(a=0; a<tottrans; a++, tv++) { @@ -595,7 +595,7 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) vec[1]= curs[1]-obedit->obmat[3][1]; vec[2]= curs[2]-obedit->obmat[3][2]; - Mat3MulVecfl(imat, vec); + mul_m3_v3(imat, vec); VECCOPY(tv->loc, vec); } @@ -612,9 +612,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) bArmature *arm= ob->data; float cursp[3]; - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); VECCOPY(cursp, curs); - Mat4MulVecfl(ob->imat, cursp); + mul_m4_v3(ob->imat, cursp); for (pchan = ob->pose->chanbase.first; pchan; pchan=pchan->next) { if(pchan->bone->flag & BONE_SELECTED) { @@ -650,8 +650,8 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op) if(ob->parent) { where_is_object(scene, ob); - Mat3Inv(imat, originmat); - Mat3MulVecfl(imat, vec); + invert_m3_m3(imat, originmat); + mul_m3_v3(imat, vec); ob->loc[0]+= vec[0]; ob->loc[1]+= vec[1]; ob->loc[2]+= vec[2]; @@ -749,19 +749,19 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op) make_trans_verts(obedit, bmat[0], bmat[1], 2); if(tottrans==0) return OPERATOR_CANCELLED; - Mat3CpyMat4(bmat, obedit->obmat); + copy_m3_m4(bmat, obedit->obmat); tv= transvmain; for(a=0; a<tottrans; a++, tv++) { VECCOPY(vec, tv->loc); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, obedit->obmat[3]); - VecAddf(centroid, centroid, vec); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, obedit->obmat[3]); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); } if(v3d->around==V3D_CENTROID) { - VecMulf(centroid, 1.0/(float)tottrans); + mul_v3_fl(centroid, 1.0/(float)tottrans); VECCOPY(curs, centroid); } else { @@ -782,8 +782,8 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op) if(arm->layer & pchan->bone->layer) { if(pchan->bone->flag & BONE_SELECTED) { VECCOPY(vec, pchan->pose_head); - Mat4MulVecfl(ob->obmat, vec); - VecAddf(centroid, centroid, vec); + mul_m4_v3(ob->obmat, vec); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); count++; } @@ -793,7 +793,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op) else { CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { VECCOPY(vec, ob->obmat[3]); - VecAddf(centroid, centroid, vec); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); count++; } @@ -801,7 +801,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op) } if(count) { if(v3d->around==V3D_CENTROID) { - VecMulf(centroid, 1.0/(float)count); + mul_v3_fl(centroid, 1.0/(float)count); VECCOPY(curs, centroid); } else { @@ -854,7 +854,7 @@ static int snap_curs_to_active(bContext *C, wmOperator *op) EM_editselection_center(curs, &ese); } - Mat4MulVecfl(obedit->obmat, curs); + mul_m4_v3(obedit->obmat, curs); } } else { @@ -908,20 +908,20 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) make_trans_verts(obedit, bmat[0], bmat[1], 0); if(tottrans==0) return OPERATOR_CANCELLED; - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); tv= transvmain; for(a=0; a<tottrans; a++, tv++) { VECCOPY(vec, tv->loc); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, obedit->obmat[3]); - VecAddf(centroid, centroid, vec); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, obedit->obmat[3]); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); } if(v3d->around==V3D_CENTROID) { - VecMulf(centroid, 1.0/(float)tottrans); + mul_v3_fl(centroid, 1.0/(float)tottrans); VECCOPY(snaploc, centroid); } else { @@ -944,7 +944,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) if(pchan->bone->flag & BONE_SELECTED) { if(pchan->bone->layer & arm->layer) { VECCOPY(vec, pchan->pose_mat[3]); - VecAddf(centroid, centroid, vec); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); count++; } @@ -954,7 +954,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) else { /* not armature bones (i.e. objects) */ VECCOPY(vec, ob->obmat[3]); - VecAddf(centroid, centroid, vec); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); count++; } @@ -963,7 +963,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) if(count) { if(v3d->around==V3D_CENTROID) { - VecMulf(centroid, 1.0/(float)count); + mul_v3_fl(centroid, 1.0/(float)count); VECCOPY(snaploc, centroid); } else { @@ -982,8 +982,8 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) make_trans_verts(obedit, bmat[0], bmat[1], 0); if(tottrans==0) return OPERATOR_CANCELLED; - Mat3CpyMat4(bmat, obedit->obmat); - Mat3Inv(imat, bmat); + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); tv= transvmain; for(a=0; a<tottrans; a++, tv++) { @@ -991,7 +991,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) vec[1]= snaploc[1]-obedit->obmat[3][1]; vec[2]= snaploc[2]-obedit->obmat[3][2]; - Mat3MulVecfl(imat, vec); + mul_m3_v3(imat, vec); VECCOPY(tv->loc, vec); } @@ -1040,8 +1040,8 @@ static int snap_selected_to_center(bContext *C, wmOperator *op) if(ob->parent) { where_is_object(scene, ob); - Mat3Inv(imat, originmat); - Mat3MulVecfl(imat, vec); + invert_m3_m3(imat, originmat); + mul_m3_v3(imat, vec); ob->loc[0]+= vec[0]; ob->loc[1]+= vec[1]; ob->loc[2]+= vec[2]; @@ -1093,14 +1093,14 @@ int minmax_verts(Object *obedit, float *min, float *max) if(tottrans==0) return 0; - Mat3CpyMat4(bmat, obedit->obmat); + copy_m3_m4(bmat, obedit->obmat); tv= transvmain; for(a=0; a<tottrans; a++, tv++) { VECCOPY(vec, tv->loc); - Mat3MulVecfl(bmat, vec); - VecAddf(vec, vec, obedit->obmat[3]); - VecAddf(centroid, centroid, vec); + mul_m3_v3(bmat, vec); + add_v3_v3v3(vec, vec, obedit->obmat[3]); + add_v3_v3v3(centroid, centroid, vec); DO_MINMAX(vec, min, max); } diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index e1c6f70bde0..3249f26aff6 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -51,7 +51,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 9fbc916c02d..96a16e733d0 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -45,7 +45,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -161,26 +161,26 @@ static void view_settings_from_ob(Object *ob, float *ofs, float *quat, float *di /* Offset */ if (ofs) { VECCOPY(ofs, ob->obmat[3]); - VecMulf(ofs, -1.0f); /*flip the vector*/ + mul_v3_fl(ofs, -1.0f); /*flip the vector*/ } /* Quat */ if (quat) { - Mat4CpyMat4(bmat, ob->obmat); - Mat4Ortho(bmat); - Mat4Invert(imat, bmat); - Mat3CpyMat4(tmat, imat); - Mat3ToQuat(tmat, quat); + copy_m4_m4(bmat, ob->obmat); + normalize_m4(bmat); + invert_m4_m4(imat, bmat); + copy_m3_m4(tmat, imat); + mat3_to_quat( quat,tmat); } if (dist) { float vec[3]; - Mat3CpyMat4(tmat, ob->obmat); + copy_m3_m4(tmat, ob->obmat); vec[0]= vec[1] = 0.0; vec[2]= -(*dist); - Mat3MulVecfl(tmat, vec); - VecSubf(ofs, ofs, vec); + mul_m3_v3(tmat, vec); + sub_v3_v3v3(ofs, ofs, vec); } /* Lens */ @@ -263,10 +263,10 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo VECCOPY(vec1, sms.new_quat); VECCOPY(vec2, sms.orig_quat); - Normalize(vec1); - Normalize(vec2); + normalize_v3(vec1); + normalize_v3(vec2); /* scale the time allowed by the rotation */ - sms.time_allowed *= NormalizedVecAngle2(vec1, vec2)/(M_PI/2); + sms.time_allowed *= angle_normalized_v3v3(vec1, vec2)/(M_PI/2); } /* original values */ @@ -361,7 +361,7 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *op, wmEvent *event) for (i=0; i<3; i++) rv3d->ofs[i] = sms->new_ofs[i]*step + sms->orig_ofs[i]*step_inv; - QuatInterpol(rv3d->viewquat, sms->orig_quat, sms->new_quat, step); + interp_qt_qtqt(rv3d->viewquat, sms->orig_quat, sms->new_quat, step); rv3d->dist = sms->new_dist*step + sms->orig_dist*step_inv; v3d->lens = sms->new_lens*step + sms->orig_lens*step_inv; @@ -395,10 +395,10 @@ static void setcameratoview3d(View3D *v3d, RegionView3D *rv3d, Object *ob) dvec[2]= rv3d->dist*rv3d->viewinv[2][2]; VECCOPY(ob->loc, dvec); - VecSubf(ob->loc, ob->loc, rv3d->ofs); + sub_v3_v3v3(ob->loc, ob->loc, rv3d->ofs); rv3d->viewquat[0]= -rv3d->viewquat[0]; - QuatToEul(rv3d->viewquat, ob->rot); + quat_to_eul( ob->rot,rv3d->viewquat); rv3d->viewquat[0]= -rv3d->viewquat[0]; ob->recalc= OB_RECALC_OB; @@ -493,12 +493,12 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float vec[2]= -1.0f; vec[3]= 1.0f; - Mat4MulVec4fl(rv3d->persinv, vec); - VecMulf(vec, 1.0f / vec[3]); + mul_m4_v4(rv3d->persinv, vec); + mul_v3_fl(vec, 1.0f / vec[3]); VECCOPY(ray_start, rv3d->viewinv[3]); VECSUB(vec, vec, ray_start); - Normalize(vec); + normalize_v3(vec); VECADDFAC(ray_start, rv3d->viewinv[3], vec, v3d->near); VECADDFAC(ray_end, rv3d->viewinv[3], vec, v3d->far); @@ -509,7 +509,7 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float vec[2] = 0.0f; vec[3] = 1.0f; - Mat4MulVec4fl(rv3d->persinv, vec); + mul_m4_v4(rv3d->persinv, vec); VECADDFAC(ray_start, vec, rv3d->viewinv[2], 1000.0f); VECADDFAC(ray_end, vec, rv3d->viewinv[2], -1000.0f); @@ -522,8 +522,8 @@ void viewray(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float float ray_end[3]; viewline(ar, v3d, mval, ray_start, ray_end); - VecSubf(ray_normal, ray_end, ray_start); - Normalize(ray_normal); + sub_v3_v3v3(ray_normal, ray_end, ray_start); + normalize_v3(ray_normal); } @@ -601,8 +601,8 @@ void view3d_get_object_project_mat(RegionView3D *rv3d, Object *ob, float pmat[4] { float vmat[4][4]; - Mat4MulMat4(vmat, ob->obmat, rv3d->viewmat); - Mat4MulMat4(pmat, vmat, rv3d->winmat); + mul_m4_m4m4(vmat, ob->obmat, rv3d->viewmat); + mul_m4_m4m4(pmat, vmat, rv3d->winmat); } /* Uses window coordinates (x,y) and depth component z to find a point in @@ -627,7 +627,7 @@ void view3d_project_float(ARegion *ar, float *vec, float *adr, float mat[4][4]) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(mat, vec4); + mul_m4_v4(mat, vec4); if( vec4[3]>FLT_EPSILON ) { adr[0] = (float)(ar->winx/2.0f)+(ar->winx/2.0f)*vec4[0]/vec4[3]; @@ -648,12 +648,12 @@ int boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb) if(bb==NULL) return 1; if(bb->flag & OB_BB_DISABLED) return 1; - Mat4MulMat4(mat, obmat, rv3d->persmat); + mul_m4_m4m4(mat, obmat, rv3d->persmat); for(a=0; a<8; a++) { VECCOPY(vec, bb->vec[a]); vec[3]= 1.0; - Mat4MulVec4fl(mat, vec); + mul_m4_v4(mat, vec); max= vec[3]; min= -vec[3]; @@ -686,7 +686,7 @@ void project_short(ARegion *ar, float *vec, short *adr) /* clips */ VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if( vec4[3]>BL_NEAR_CLIP ) { /* 0.001 is the NEAR clipping cutoff for picking */ fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]); @@ -712,7 +712,7 @@ void project_int(ARegion *ar, float *vec, int *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if( vec4[3]>BL_NEAR_CLIP ) { /* 0.001 is the NEAR clipping cutoff for picking */ fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]); @@ -736,7 +736,7 @@ void project_int_noclip(ARegion *ar, float *vec, int *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if( fabs(vec4[3]) > BL_NEAR_CLIP ) { fx = (ar->winx/2)*(1 + vec4[0]/vec4[3]); @@ -761,7 +761,7 @@ void project_short_noclip(ARegion *ar, float *vec, short *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if( vec4[3]>BL_NEAR_CLIP ) { /* 0.001 is the NEAR clipping cutoff for picking */ fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]); @@ -787,7 +787,7 @@ void project_float(ARegion *ar, float *vec, float *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if( vec4[3]>BL_NEAR_CLIP ) { adr[0] = (float)(ar->winx/2.0)+(ar->winx/2.0)*vec4[0]/vec4[3]; @@ -803,7 +803,7 @@ void project_float_noclip(ARegion *ar, float *vec, float *adr) VECCOPY(vec4, vec); vec4[3]= 1.0; - Mat4MulVec4fl(rv3d->persmat, vec4); + mul_m4_v4(rv3d->persmat, vec4); if( fabs(vec4[3]) > BL_NEAR_CLIP ) { adr[0] = (float)(ar->winx/2.0)+(ar->winx/2.0)*vec4[0]/vec4[3]; @@ -1001,12 +1001,12 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short rv3d->view= 0; /* dont show the grid */ - Mat4CpyMat4(bmat, ob->obmat); - Mat4Ortho(bmat); - Mat4Invert(rv3d->viewmat, bmat); + copy_m4_m4(bmat, ob->obmat); + normalize_m4(bmat); + invert_m4_m4(rv3d->viewmat, bmat); /* view quat calculation, needed for add object */ - Mat3CpyMat4(tmat, rv3d->viewmat); + copy_m3_m4(tmat, rv3d->viewmat); if (smooth) { float new_quat[4]; if (rv3d->persp==RV3D_CAMOB && v3d->camera) { @@ -1018,7 +1018,7 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short VECCOPY(orig_ofs, rv3d->ofs); /* Switch from camera view */ - Mat3ToQuat(tmat, new_quat); + mat3_to_quat( new_quat,tmat); rv3d->persp=RV3D_PERSP; rv3d->dist= 0.0; @@ -1029,11 +1029,11 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short rv3d->persp=RV3D_CAMOB; /* just to be polite, not needed */ } else { - Mat3ToQuat(tmat, new_quat); + mat3_to_quat( new_quat,tmat); smooth_view(NULL, NULL, NULL, NULL, new_quat, NULL, NULL); // XXX } } else { - Mat3ToQuat(tmat, rv3d->viewquat); + mat3_to_quat( rv3d->viewquat,tmat); } } @@ -1077,7 +1077,7 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) obmat_to_viewmat(v3d, rv3d, v3d->camera, 0); } else { - QuatToMat4(rv3d->viewquat, rv3d->viewmat); + quat_to_mat4( rv3d->viewmat,rv3d->viewquat); rv3d->viewmat[3][2]-= rv3d->dist; } } @@ -1086,7 +1086,7 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) if(rv3d->viewlock) view3d_viewlock(rv3d); - QuatToMat4(rv3d->viewquat, rv3d->viewmat); + quat_to_mat4( rv3d->viewmat,rv3d->viewquat); if(rv3d->persp==RV3D_PERSP) rv3d->viewmat[3][2]-= rv3d->dist; if(v3d->ob_centre) { Object *ob= v3d->ob_centre; @@ -1097,12 +1097,12 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) bPoseChannel *pchan= get_pose_channel(ob->pose, v3d->ob_centre_bone); if(pchan) { VECCOPY(vec, pchan->pose_mat[3]); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); } } - i_translate(-vec[0], -vec[1], -vec[2], rv3d->viewmat); + translate_m4( rv3d->viewmat,-vec[0], -vec[1], -vec[2]); } - else i_translate(rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2], rv3d->viewmat); + else translate_m4( rv3d->viewmat,rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]); } } @@ -1136,7 +1136,7 @@ short view3d_opengl_select(ViewContext *vc, unsigned int *buffer, unsigned int b } setwinmatrixview3d(ar, v3d, &rect); - Mat4MulMat4(vc->rv3d->persmat, vc->rv3d->viewmat, vc->rv3d->winmat); + mul_m4_m4m4(vc->rv3d->persmat, vc->rv3d->viewmat, vc->rv3d->winmat); if(v3d->drawtype > OB_WIRE) { v3d->zbuf= TRUE; @@ -1186,11 +1186,11 @@ short view3d_opengl_select(ViewContext *vc, unsigned int *buffer, unsigned int b for(dob= lb->first; dob; dob= dob->next) { tbase.object= dob->ob; - Mat4CpyMat4(dob->ob->obmat, dob->mat); + copy_m4_m4(dob->ob->obmat, dob->mat); draw_object(scene, ar, v3d, &tbase, DRAW_PICKING|DRAW_CONSTCOLOR); - Mat4CpyMat4(dob->ob->obmat, dob->omat); + copy_m4_m4(dob->ob->obmat, dob->omat); } free_object_duplilist(lb); } @@ -1206,7 +1206,7 @@ short view3d_opengl_select(ViewContext *vc, unsigned int *buffer, unsigned int b G.f &= ~G_PICKSEL; setwinmatrixview3d(ar, v3d, NULL); - Mat4MulMat4(vc->rv3d->persmat, vc->rv3d->viewmat, vc->rv3d->winmat); + mul_m4_m4m4(vc->rv3d->persmat, vc->rv3d->viewmat, vc->rv3d->winmat); if(v3d->drawtype > OB_WIRE) { v3d->zbuf= 0; @@ -1851,8 +1851,8 @@ int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event) /* detect weather to start with Z locking */ upvec[0]=1.0f; upvec[1]=0.0f; upvec[2]=0.0f; - Mat3CpyMat4(mat, fly->rv3d->viewinv); - Mat3MulVecfl(mat, upvec); + copy_m3_m4(mat, fly->rv3d->viewinv); + mul_m3_v3(mat, upvec); if (fabs(upvec[2]) < 0.1) fly->zlock = 1; upvec[0]=0; upvec[1]=0; upvec[2]=0; @@ -1866,7 +1866,7 @@ int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event) where_is_object(fly->scene, fly->v3d->camera); VECCOPY(fly->rv3d->ofs, fly->v3d->camera->obmat[3]); - VecMulf(fly->rv3d->ofs, -1.0f); /*flip the vector*/ + mul_v3_fl(fly->rv3d->ofs, -1.0f); /*flip the vector*/ fly->rv3d->dist=0.0; fly->rv3d->viewbut=0; @@ -1884,8 +1884,8 @@ int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event) fly->rv3d->dist= 0.0; upvec[2]= fly->dist_backup; /*x and y are 0*/ - Mat3MulVecfl(mat, upvec); - VecSubf(fly->rv3d->ofs, fly->rv3d->ofs, upvec); + mul_m3_v3(mat, upvec); + sub_v3_v3v3(fly->rv3d->ofs, fly->rv3d->ofs, upvec); /*Done with correcting for the dist*/ } @@ -1922,8 +1922,8 @@ static int flyEnd(bContext *C, FlyInfo *fly) } else if (fly->persp_backup==RV3D_CAMOB) { /* camera */ float mat3[3][3]; - Mat3CpyMat4(mat3, v3d->camera->obmat); - Mat3ToCompatibleEul(mat3, v3d->camera->rot, fly->rot_backup); + copy_m3_m4(mat3, v3d->camera->obmat); + mat3_to_compatible_eul( v3d->camera->rot, fly->rot_backup,mat3); DAG_id_flush_update(&v3d->camera->id, OB_RECALC_OB); #if 0 //XXX2.5 @@ -1941,9 +1941,9 @@ static int flyEnd(bContext *C, FlyInfo *fly) float mat[3][3]; upvec[0]= upvec[1]= 0; upvec[2]= fly->dist_backup; /*x and y are 0*/ - Mat3CpyMat4(mat, rv3d->viewinv); - Mat3MulVecfl(mat, upvec); - VecAddf(rv3d->ofs, rv3d->ofs, upvec); + copy_m3_m4(mat, rv3d->viewinv); + mul_m3_v3(mat, upvec); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, upvec); /*Done with correcting for the dist */ } @@ -2176,7 +2176,7 @@ int flyApply(FlyInfo *fly) if (fly->use_precision) fly->speed= fly->speed * (1.0f-time_redraw_clamped); - Mat3CpyMat4(mat, rv3d->viewinv); + copy_m3_m4(mat, rv3d->viewinv); if (fly->pan_view==TRUE) { /* pan only */ @@ -2189,8 +2189,8 @@ int flyApply(FlyInfo *fly) dvec_tmp[1] *= 0.1; } - Mat3MulVecfl(mat, dvec_tmp); - VecMulf(dvec_tmp, time_redraw*200.0 * fly->grid); + mul_m3_v3(mat, dvec_tmp); + mul_v3_fl(dvec_tmp, time_redraw*200.0 * fly->grid); } else { float roll; /* similar to the angle between the camera's up and the Z-up, but its very rough so just roll*/ @@ -2200,9 +2200,9 @@ int flyApply(FlyInfo *fly) upvec[0]=1; upvec[1]=0; upvec[2]=0; - Mat3MulVecfl(mat, upvec); - VecRotToQuat( upvec, (float)moffset[1]*-time_redraw*20, tmp_quat); /* Rotate about the relative up vec */ - QuatMul(rv3d->viewquat, rv3d->viewquat, tmp_quat); + mul_m3_v3(mat, upvec); + axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1]*-time_redraw*20); /* Rotate about the relative up vec */ + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock) fly->xlock = 2; /*check for rotation*/ if (fly->zlock) fly->zlock = 2; @@ -2216,7 +2216,7 @@ int flyApply(FlyInfo *fly) upvec[0]=0; upvec[1]=1; upvec[2]=0; - Mat3MulVecfl(mat, upvec); + mul_m3_v3(mat, upvec); if(upvec[2] < 0.0f) moffset[0]= -moffset[0]; @@ -2230,11 +2230,11 @@ int flyApply(FlyInfo *fly) upvec[0]=0; upvec[1]=1; upvec[2]=0; - Mat3MulVecfl(mat, upvec); + mul_m3_v3(mat, upvec); } - VecRotToQuat( upvec, (float)moffset[0]*time_redraw*20, tmp_quat); /* Rotate about the relative up vec */ - QuatMul(rv3d->viewquat, rv3d->viewquat, tmp_quat); + axis_angle_to_quat( tmp_quat, upvec, (float)moffset[0]*time_redraw*20); /* Rotate about the relative up vec */ + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock) fly->xlock = 2;/*check for rotation*/ if (fly->zlock) fly->zlock = 2; @@ -2244,7 +2244,7 @@ int flyApply(FlyInfo *fly) upvec[0]=1; upvec[1]=0; upvec[2]=0; - Mat3MulVecfl(mat, upvec); + mul_m3_v3(mat, upvec); /*make sure we have some z rolling*/ if (fabs(upvec[2]) > 0.00001f) { @@ -2253,9 +2253,9 @@ int flyApply(FlyInfo *fly) upvec[1]=0; upvec[2]=1; - Mat3MulVecfl(mat, upvec); - VecRotToQuat( upvec, roll*time_redraw_clamped*fly->zlock_momentum*0.1, tmp_quat); /* Rotate about the relative up vec */ - QuatMul(rv3d->viewquat, rv3d->viewquat, tmp_quat); + mul_m3_v3(mat, upvec); + axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->zlock_momentum*0.1); /* Rotate about the relative up vec */ + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); fly->zlock_momentum += 0.05f; } else { @@ -2268,7 +2268,7 @@ int flyApply(FlyInfo *fly) upvec[0]=0; upvec[1]=0; upvec[2]=1; - Mat3MulVecfl(mat, upvec); + mul_m3_v3(mat, upvec); /*make sure we have some z rolling*/ if (fabs(upvec[2]) > 0.00001) { roll= upvec[2] * -5; @@ -2277,10 +2277,10 @@ int flyApply(FlyInfo *fly) upvec[1]= 0.0f; upvec[2]= 0.0f; - Mat3MulVecfl(mat, upvec); + mul_m3_v3(mat, upvec); - VecRotToQuat( upvec, roll*time_redraw_clamped*fly->xlock_momentum*0.1f, tmp_quat); /* Rotate about the relative up vec */ - QuatMul(rv3d->viewquat, rv3d->viewquat, tmp_quat); + axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->xlock_momentum*0.1f); /* Rotate about the relative up vec */ + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); fly->xlock_momentum += 0.05f; } else { @@ -2297,14 +2297,14 @@ int flyApply(FlyInfo *fly) /* move along the current axis */ dvec_tmp[fly->axis]= 1.0f; - Mat3MulVecfl(mat, dvec_tmp); + mul_m3_v3(mat, dvec_tmp); - VecMulf(dvec_tmp, fly->speed * time_redraw * 0.25f); + mul_v3_fl(dvec_tmp, fly->speed * time_redraw * 0.25f); } } /* impose a directional lag */ - VecLerpf(dvec, dvec_tmp, fly->dvec_prev, (1.0f/(1.0f+(time_redraw*5.0f)))); + interp_v3_v3v3(dvec, dvec_tmp, fly->dvec_prev, (1.0f/(1.0f+(time_redraw*5.0f)))); if (rv3d->persp==RV3D_CAMOB) { if (v3d->camera->protectflag & OB_LOCK_LOCX) @@ -2315,7 +2315,7 @@ int flyApply(FlyInfo *fly) dvec[2] = 0.0; } - VecAddf(rv3d->ofs, rv3d->ofs, dvec); + add_v3_v3v3(rv3d->ofs, rv3d->ofs, dvec); #if 0 //XXX2.5 if (fly->zlock && fly->xlock) headerprint("FlyKeys Speed:(+/- | Wheel), Upright Axis:X on/Z on, Slow:Shift, Direction:WASDRF, Ok:LMB, Pan:MMB, Cancel:RMB"); @@ -2338,7 +2338,7 @@ int flyApply(FlyInfo *fly) { //XXX - some reason setcameratoview3d doesnt copy, shouldnt not be needed! VECCOPY(v3d->camera->loc, rv3d->ofs); - VecNegf(v3d->camera->loc); + negate_v3(v3d->camera->loc); } rv3d->persp= RV3D_CAMOB; @@ -2466,11 +2466,11 @@ void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, f else alignaxis[-axisidx-1]= -1.0; VECCOPY(norm, vec); - Normalize(norm); + normalize_v3(norm); - angle= (float)acos(Inpf(alignaxis, norm)); - Crossf(axis, alignaxis, norm); - VecRotToQuat(axis, -angle, new_quat); + angle= (float)acos(dot_v3v3(alignaxis, norm)); + cross_v3_v3v3(axis, alignaxis, norm); + axis_angle_to_quat( new_quat,axis, -angle); rv3d->view= 0; diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 7467f7880af..c8c2a000450 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -106,7 +106,7 @@ #include "WM_types.h" #include "WM_api.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_ghash.h" @@ -129,17 +129,17 @@ void setTransformViewMatrices(TransInfo *t) if(t->spacetype==SPACE_VIEW3D && t->ar->regiontype == RGN_TYPE_WINDOW) { RegionView3D *rv3d = t->ar->regiondata; - Mat4CpyMat4(t->viewmat, rv3d->viewmat); - Mat4CpyMat4(t->viewinv, rv3d->viewinv); - Mat4CpyMat4(t->persmat, rv3d->persmat); - Mat4CpyMat4(t->persinv, rv3d->persinv); + copy_m4_m4(t->viewmat, rv3d->viewmat); + copy_m4_m4(t->viewinv, rv3d->viewinv); + copy_m4_m4(t->persmat, rv3d->persmat); + copy_m4_m4(t->persinv, rv3d->persinv); t->persp = rv3d->persp; } else { - Mat4One(t->viewmat); - Mat4One(t->viewinv); - Mat4One(t->persmat); - Mat4One(t->persinv); + unit_m4(t->viewmat); + unit_m4(t->viewinv); + unit_m4(t->persmat); + unit_m4(t->persinv); t->persp = RV3D_ORTHO; } @@ -661,7 +661,7 @@ void transformEvent(TransInfo *t, wmEvent *event) getmouseco_sc(mval); BIF_selectOrientation(); calc_manipulator_stats(curarea); - Mat3CpyMat4(t->spacemtx, G.vd->twmat); + copy_m3_m4(t->spacemtx, G.vd->twmat); warp_pointer(mval[0], mval[1]); #endif } @@ -1112,11 +1112,11 @@ void drawHelpline(const struct bContext *C, TransInfo *t) VECCOPY(vecrot, t->center); if(t->flag & T_EDIT) { Object *ob= t->obedit; - if(ob) Mat4MulVecfl(ob->obmat, vecrot); + if(ob) mul_m4_v3(ob->obmat, vecrot); } else if(t->flag & T_POSE) { Object *ob=t->poseobj; - if(ob) Mat4MulVecfl(ob->obmat, vecrot); + if(ob) mul_m4_v3(ob->obmat, vecrot); } projectFloatView(t, vecrot, cent); // no overflow in extreme cases @@ -1368,12 +1368,12 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL); } else if(t->spacetype == SPACE_IMAGE) { - Mat3One(t->spacemtx); + unit_m3(t->spacemtx); t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW); t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL); } else - Mat3One(t->spacemtx); + unit_m3(t->spacemtx); createTransData(C, t); // make TransData structs from selection @@ -1652,8 +1652,8 @@ static void protectedAxisAngleBits(short protectflag, float axis[3], float *angl /* axis-angle get limited with euler... */ float eul[3], oldeul[3]; - AxisAngleToEulO(axis, *angle, eul, EULER_ORDER_DEFAULT); - AxisAngleToEulO(oldAxis, oldAngle, oldeul, EULER_ORDER_DEFAULT); + axis_angle_to_eulO( eul, EULER_ORDER_DEFAULT,axis, *angle); + axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,oldAxis, oldAngle); if (protectflag & OB_LOCK_ROTX) eul[0]= oldeul[0]; @@ -1662,7 +1662,7 @@ static void protectedAxisAngleBits(short protectflag, float axis[3], float *angl if (protectflag & OB_LOCK_ROTZ) eul[2]= oldeul[2]; - EulOToAxisAngle(eul, EULER_ORDER_DEFAULT, axis, angle); + eulO_to_axis_angle( axis, angle,eul, EULER_ORDER_DEFAULT); /* when converting to axis-angle, we need a special exception for the case when there is no axis */ if (IS_EQ(axis[0], axis[1]) && IS_EQ(axis[1], axis[2])) { @@ -1695,8 +1695,8 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu float eul[3], oldeul[3], quat1[4]; QUATCOPY(quat1, quat); - QuatToEul(quat, eul); - QuatToEul(oldquat, oldeul); + quat_to_eul( eul,quat); + quat_to_eul( oldeul,oldquat); if (protectflag & OB_LOCK_ROTX) eul[0]= oldeul[0]; @@ -1705,11 +1705,11 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu if (protectflag & OB_LOCK_ROTZ) eul[2]= oldeul[2]; - EulToQuat(eul, quat); + eul_to_quat( quat,eul); /* quaternions flip w sign to accumulate rotations correctly */ if ( (quat1[0]<0.0f && quat[0]>0.0f) || (quat1[0]>0.0f && quat[0]<0.0f) ) { - QuatMulf(quat, -1.0f); + mul_qt_fl(quat, -1.0f); } } } @@ -1728,7 +1728,7 @@ static void constraintTransLim(TransInfo *t, TransData *td) * - current space should be local */ memset(&cob, 0, sizeof(bConstraintOb)); - Mat4One(cob.matrix); + unit_m4(cob.matrix); VECCOPY(cob.matrix[3], td->loc); /* Evaluate valid constraints */ @@ -1749,8 +1749,8 @@ static void constraintTransLim(TransInfo *t, TransData *td) /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ - Mat4CpyMat4(tmat, cob.matrix); - Mat4MulMat34(cob.matrix, td->mtx, tmat); + copy_m4_m4(tmat, cob.matrix); + mul_m4_m3m4(cob.matrix, td->mtx, tmat); } else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) { /* skip... incompatable spacetype */ @@ -1763,8 +1763,8 @@ static void constraintTransLim(TransInfo *t, TransData *td) /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ - Mat4CpyMat4(tmat, cob.matrix); - Mat4MulMat34(cob.matrix, td->smtx, tmat); + copy_m4_m4(tmat, cob.matrix); + mul_m4_m3m4(cob.matrix, td->smtx, tmat); } } } @@ -1789,21 +1789,21 @@ static void constraintRotLim(TransInfo *t, TransData *td) if (td->rotOrder == ROT_MODE_QUAT) { /* quats */ if (td->ext) - QuatToMat4(td->ext->quat, cob.matrix); + quat_to_mat4( cob.matrix,td->ext->quat); else return; } else if (td->rotOrder == ROT_MODE_AXISANGLE) { /* axis angle */ if (td->ext) - AxisAngleToMat4(&td->ext->quat[1], td->ext->quat[0], cob.matrix); + axis_angle_to_mat4( cob.matrix,&td->ext->quat[1], td->ext->quat[0]); else return; } else { /* eulers */ if (td->ext) - EulOToMat4(td->ext->rot, td->rotOrder, cob.matrix); + eulO_to_mat4( cob.matrix,td->ext->rot, td->rotOrder); else return; } @@ -1826,8 +1826,8 @@ static void constraintRotLim(TransInfo *t, TransData *td) /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ - Mat4CpyMat4(tmat, cob.matrix); - Mat4MulMat34(cob.matrix, td->mtx, tmat); + copy_m4_m4(tmat, cob.matrix); + mul_m4_m3m4(cob.matrix, td->mtx, tmat); } else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) { /* skip... incompatable spacetype */ @@ -1840,8 +1840,8 @@ static void constraintRotLim(TransInfo *t, TransData *td) /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ - Mat4CpyMat4(tmat, cob.matrix); - Mat4MulMat34(cob.matrix, td->smtx, tmat); + copy_m4_m4(tmat, cob.matrix); + mul_m4_m3m4(cob.matrix, td->smtx, tmat); } } } @@ -1849,15 +1849,15 @@ static void constraintRotLim(TransInfo *t, TransData *td) /* copy results from cob->matrix */ if (td->rotOrder == ROT_MODE_QUAT) { /* quats */ - Mat4ToQuat(cob.matrix, td->ext->quat); + mat4_to_quat( td->ext->quat,cob.matrix); } else if (td->rotOrder == ROT_MODE_AXISANGLE) { /* axis angle */ - Mat4ToAxisAngle(cob.matrix, &td->ext->quat[1], &td->ext->quat[0]); + mat4_to_axis_angle( &td->ext->quat[1], &td->ext->quat[0],cob.matrix); } else { /* eulers */ - Mat4ToEulO(cob.matrix, td->ext->rot, td->rotOrder); + mat4_to_eulO( td->ext->rot, td->rotOrder,cob.matrix); } } } @@ -1883,7 +1883,7 @@ static void constraintSizeLim(TransInfo *t, TransData *td) if (td->flag & TD_SINGLESIZE) return; - SizeToMat4(td->ext->size, cob.matrix); + size_to_mat4( cob.matrix,td->ext->size); } /* Evaluate valid constraints */ @@ -1904,8 +1904,8 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ - Mat4CpyMat4(tmat, cob.matrix); - Mat4MulMat34(cob.matrix, td->mtx, tmat); + copy_m4_m4(tmat, cob.matrix); + mul_m4_m3m4(cob.matrix, td->mtx, tmat); } else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) { /* skip... incompatable spacetype */ @@ -1918,8 +1918,8 @@ static void constraintSizeLim(TransInfo *t, TransData *td) /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ - Mat4CpyMat4(tmat, cob.matrix); - Mat4MulMat34(cob.matrix, td->smtx, tmat); + copy_m4_m4(tmat, cob.matrix); + mul_m4_m3m4(cob.matrix, td->smtx, tmat); } } } @@ -1934,7 +1934,7 @@ static void constraintSizeLim(TransInfo *t, TransData *td) if (td->flag & TD_SINGLESIZE) return; - Mat4ToSize(cob.matrix, td->ext->size); + mat4_to_size( td->ext->size,cob.matrix); } } } @@ -1964,11 +1964,11 @@ void initWarp(TransInfo *t) for(i = 0; i < t->total; i++) { float center[3]; VECCOPY(center, t->data[i].center); - Mat3MulVecfl(t->data[i].mtx, center); - Mat4MulVecfl(t->viewmat, center); - VecSubf(center, center, t->viewmat[3]); + mul_m3_v3(t->data[i].mtx, center); + mul_m4_v3(t->viewmat, center); + sub_v3_v3v3(center, center, t->viewmat[3]); if (i) - MinMax3(min, max, center); + minmax_v3_v3v3(min, max, center); else { VECCOPY(max, center); VECCOPY(min, center); @@ -2022,12 +2022,12 @@ int Warp(TransInfo *t, short mval[2]) VECCOPY(cursor, curs); VECCOPY(gcursor, cursor); if (t->flag & T_EDIT) { - VecSubf(cursor, cursor, t->obedit->obmat[3]); - VecSubf(gcursor, gcursor, t->obedit->obmat[3]); - Mat3MulVecfl(t->data->smtx, gcursor); + sub_v3_v3v3(cursor, cursor, t->obedit->obmat[3]); + sub_v3_v3v3(gcursor, gcursor, t->obedit->obmat[3]); + mul_m3_v3(t->data->smtx, gcursor); } - Mat4MulVecfl(t->viewmat, cursor); - VecSubf(cursor, cursor, t->viewmat[3]); + mul_m4_v3(t->viewmat, cursor); + sub_v3_v3v3(cursor, cursor, t->viewmat[3]); /* amount of degrees for warp */ circumfac = 360.0f * t->values[0]; @@ -2065,9 +2065,9 @@ int Warp(TransInfo *t, short mval[2]) /* translate point to center, rotate in such a way that outline==distance */ VECCOPY(vec, td->iloc); - Mat3MulVecfl(td->mtx, vec); - Mat4MulVecfl(t->viewmat, vec); - VecSubf(vec, vec, t->viewmat[3]); + mul_m3_v3(td->mtx, vec); + mul_m4_v3(t->viewmat, vec); + sub_v3_v3v3(vec, vec, t->viewmat[3]); dist= vec[0]-cursor[0]; @@ -2082,13 +2082,13 @@ int Warp(TransInfo *t, short mval[2]) loc[1]= co*vec[1]+cursor[1]; loc[2]= vec[2]; - Mat4MulVecfl(t->viewinv, loc); - VecSubf(loc, loc, t->viewinv[3]); - Mat3MulVecfl(td->smtx, loc); + mul_m4_v3(t->viewinv, loc); + sub_v3_v3v3(loc, loc, t->viewinv[3]); + mul_m3_v3(td->smtx, loc); - VecSubf(loc, loc, td->iloc); - VecMulf(loc, td->factor); - VecAddf(td->loc, td->iloc, loc); + sub_v3_v3v3(loc, loc, td->iloc); + mul_v3_fl(loc, td->factor); + add_v3_v3v3(td->loc, td->iloc, loc); } recalcData(t); @@ -2151,8 +2151,8 @@ int Shear(TransInfo *t, short mval[2]) int i; char str[50]; - Mat3CpyMat4(persmat, t->viewmat); - Mat3Inv(persinv, persmat); + copy_m3_m4(persmat, t->viewmat); + invert_m3_m3(persinv, persmat); value = 0.05f * t->values[0]; @@ -2173,7 +2173,7 @@ int Shear(TransInfo *t, short mval[2]) sprintf(str, "Shear: %.3f %s", value, t->proptext); } - Mat3One(smat); + unit_m3(smat); // Custom data signals shear direction if (t->customData == 0) @@ -2181,8 +2181,8 @@ int Shear(TransInfo *t, short mval[2]) else smat[0][1] = value; - Mat3MulMat3(tmat, smat, persmat); - Mat3MulMat3(totmat, persinv, tmat); + mul_m3_m3m3(tmat, smat, persmat); + mul_m3_m3m3(totmat, persinv, tmat); for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) @@ -2193,22 +2193,22 @@ int Shear(TransInfo *t, short mval[2]) if (t->obedit) { float mat3[3][3]; - Mat3MulMat3(mat3, totmat, td->mtx); - Mat3MulMat3(tmat, td->smtx, mat3); + mul_m3_m3m3(mat3, totmat, td->mtx); + mul_m3_m3m3(tmat, td->smtx, mat3); } else { - Mat3CpyMat3(tmat, totmat); + copy_m3_m3(tmat, totmat); } - VecSubf(vec, td->center, t->center); + sub_v3_v3v3(vec, td->center, t->center); - Mat3MulVecfl(tmat, vec); + mul_m3_v3(tmat, vec); - VecAddf(vec, vec, t->center); - VecSubf(vec, vec, td->center); + add_v3_v3v3(vec, vec, t->center); + sub_v3_v3v3(vec, vec, td->center); - VecMulf(vec, td->factor); + mul_v3_fl(vec, td->factor); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); } recalcData(t); @@ -2281,12 +2281,12 @@ static void TransMat3ToSize( float mat[][3], float smat[][3], float *size) { float vec[3]; - VecCopyf(vec, mat[0]); - size[0]= Normalize(vec); - VecCopyf(vec, mat[1]); - size[1]= Normalize(vec); - VecCopyf(vec, mat[2]); - size[2]= Normalize(vec); + copy_v3_v3(vec, mat[0]); + size[0]= normalize_v3(vec); + copy_v3_v3(vec, mat[1]); + size[1]= normalize_v3(vec); + copy_v3_v3(vec, mat[2]); + size[2]= normalize_v3(vec); /* first tried with dotproduct... but the sign flip is crucial */ if( VECSIGNFLIP(mat[0], smat[0]) ) size[0]= -size[0]; @@ -2300,11 +2300,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { float vec[3]; if (t->flag & T_EDIT) { - Mat3MulMat3(smat, mat, td->mtx); - Mat3MulMat3(tmat, td->smtx, smat); + mul_m3_m3m3(smat, mat, td->mtx); + mul_m3_m3m3(tmat, td->smtx, smat); } else { - Mat3CpyMat3(tmat, mat); + copy_m3_m3(tmat, mat); } if (t->con.applySize) { @@ -2339,13 +2339,13 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { if (t->flag & (T_OBJECT|T_TEXTURE|T_POSE)) { float obsizemat[3][3]; // Reorient the size mat to fit the oriented object. - Mat3MulMat3(obsizemat, tmat, td->axismtx); - //printmatrix3("obsizemat", obsizemat); + mul_m3_m3m3(obsizemat, tmat, td->axismtx); + //print_m3("obsizemat", obsizemat); TransMat3ToSize(obsizemat, td->axismtx, fsize); - //printvecf("fsize", fsize); + //print_v3("fsize", fsize); } else { - Mat3ToSize(tmat, fsize); + mat3_to_size( fsize,tmat); } protectedSizeBits(td->protectflag, fsize); @@ -2375,26 +2375,26 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) { /* For individual element center, Editmode need to use iloc */ if (t->flag & T_POINTS) - VecSubf(vec, td->iloc, center); + sub_v3_v3v3(vec, td->iloc, center); else - VecSubf(vec, td->center, center); + sub_v3_v3v3(vec, td->center, center); - Mat3MulVecfl(tmat, vec); + mul_m3_v3(tmat, vec); - VecAddf(vec, vec, center); + add_v3_v3v3(vec, vec, center); if (t->flag & T_POINTS) - VecSubf(vec, vec, td->iloc); + sub_v3_v3v3(vec, vec, td->iloc); else - VecSubf(vec, vec, td->center); + sub_v3_v3v3(vec, vec, td->center); - VecMulf(vec, td->factor); + mul_v3_fl(vec, td->factor); if (t->flag & (T_OBJECT|T_POSE)) { - Mat3MulVecfl(td->smtx, vec); + mul_m3_v3(td->smtx, vec); } protectedTransBits(td->protectflag, vec); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); constraintTransLim(t, td); } @@ -2435,13 +2435,13 @@ int Resize(TransInfo *t, short mval[2]) VECCOPY(t->values, size); - SizeToMat3(size, mat); + size_to_mat3( mat,size); if (t->con.applySize) { t->con.applySize(t, NULL, mat); } - Mat3CpyMat3(t->mat, mat); // used in manipulator + copy_m3_m3(t->mat, mat); // used in manipulator headerResize(t, size, str); @@ -2457,7 +2457,7 @@ int Resize(TransInfo *t, short mval[2]) /* evil hack - redo resize if cliping needed */ if (t->flag & T_CLIP_UV && clipUVTransform(t, size, 1)) { - SizeToMat3(size, mat); + size_to_mat3( mat,size); if (t->con.applySize) t->con.applySize(t, NULL, mat); @@ -2496,7 +2496,7 @@ void initToSphere(TransInfo *t) // Calculate average radius for(i = 0 ; i < t->total; i++, td++) { - t->val += VecLenf(t->center, td->iloc); + t->val += len_v3v3(t->center, td->iloc); } t->val /= (float)t->total; @@ -2543,15 +2543,15 @@ int ToSphere(TransInfo *t, short mval[2]) if (td->flag & TD_SKIP) continue; - VecSubf(vec, td->iloc, t->center); + sub_v3_v3v3(vec, td->iloc, t->center); - radius = Normalize(vec); + radius = normalize_v3(vec); tratio = ratio * td->factor; - VecMulf(vec, radius * (1.0f - tratio) + t->val * tratio); + mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio); - VecAddf(td->loc, t->center, vec); + add_v3_v3v3(td->loc, t->center, vec); } @@ -2604,25 +2604,25 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short } if (t->flag & T_POINTS) { - Mat3MulMat3(totmat, mat, td->mtx); - Mat3MulMat3(smat, td->smtx, totmat); + mul_m3_m3m3(totmat, mat, td->mtx); + mul_m3_m3m3(smat, td->smtx, totmat); - VecSubf(vec, td->iloc, center); - Mat3MulVecfl(smat, vec); + sub_v3_v3v3(vec, td->iloc, center); + mul_m3_v3(smat, vec); - VecAddf(td->loc, vec, center); + add_v3_v3v3(td->loc, vec, center); - VecSubf(vec,td->loc,td->iloc); + sub_v3_v3v3(vec,td->loc,td->iloc); protectedTransBits(td->protectflag, vec); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); if(td->flag & TD_USEQUAT) { - Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); - Mat3ToQuat(fmat, quat); // Actual transform + mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); + mat3_to_quat( quat,fmat); // Actual transform if(td->ext->quat){ - QuatMul(td->ext->quat, quat, td->ext->iquat); + mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat); /* is there a reason not to have this here? -jahka */ protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat); @@ -2645,28 +2645,28 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short float pmtx[3][3], imtx[3][3]; // Extract and invert armature object matrix - Mat3CpyMat4(pmtx, t->poseobj->obmat); - Mat3Inv(imtx, pmtx); + copy_m3_m4(pmtx, t->poseobj->obmat); + invert_m3_m3(imtx, pmtx); if ((td->flag & TD_NO_LOC) == 0) { - VecSubf(vec, td->center, center); + sub_v3_v3v3(vec, td->center, center); - Mat3MulVecfl(pmtx, vec); // To Global space - Mat3MulVecfl(mat, vec); // Applying rotation - Mat3MulVecfl(imtx, vec); // To Local space + mul_m3_v3(pmtx, vec); // To Global space + mul_m3_v3(mat, vec); // Applying rotation + mul_m3_v3(imtx, vec); // To Local space - VecAddf(vec, vec, center); + add_v3_v3v3(vec, vec, center); /* vec now is the location where the object has to be */ - VecSubf(vec, vec, td->center); // Translation needed from the initial location + sub_v3_v3v3(vec, vec, td->center); // Translation needed from the initial location - Mat3MulVecfl(pmtx, vec); // To Global space - Mat3MulVecfl(td->smtx, vec);// To Pose space + mul_m3_v3(pmtx, vec); // To Global space + mul_m3_v3(td->smtx, vec);// To Pose space protectedTransBits(td->protectflag, vec); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); constraintTransLim(t, td); } @@ -2675,11 +2675,11 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself /* euler or quaternion/axis-angle? */ if (td->rotOrder == ROT_MODE_QUAT) { - Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); + mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); - Mat3ToQuat(fmat, quat); // Actual transform + mat3_to_quat( quat,fmat); // Actual transform - QuatMul(td->ext->quat, quat, td->ext->iquat); + mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat); /* this function works on end result */ protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat); @@ -2688,13 +2688,13 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short /* calculate effect based on quats */ float iquat[4], tquat[4]; - AxisAngleToQuat(iquat, td->ext->irotAxis, td->ext->irotAngle); + axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle); - Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); - Mat3ToQuat(fmat, quat); // Actual transform - QuatMul(tquat, quat, iquat); + mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); + mat3_to_quat( quat,fmat); // Actual transform + mul_qt_qtqt(tquat, quat, iquat); - QuatToAxisAngle(tquat, td->ext->rotAxis, td->ext->rotAngle); + quat_to_axis_angle( td->ext->rotAxis, td->ext->rotAngle,tquat); /* this function works on end result */ protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle); @@ -2702,17 +2702,17 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short else { float eulmat[3][3]; - Mat3MulMat3(totmat, mat, td->mtx); - Mat3MulMat3(smat, td->smtx, totmat); + mul_m3_m3m3(totmat, mat, td->mtx); + mul_m3_m3m3(smat, td->smtx, totmat); /* calculate the total rotatation in eulers */ VECCOPY(eul, td->ext->irot); - EulOToMat3(eul, td->rotOrder, eulmat); + eulO_to_mat3( eulmat,eul, td->rotOrder); /* mat = transform, obmat = bone rotation */ - Mat3MulMat3(fmat, smat, eulmat); + mul_m3_m3m3(fmat, smat, eulmat); - Mat3ToCompatibleEulO(fmat, eul, td->ext->rot, td->rotOrder); + mat3_to_compatible_eulO( eul, td->ext->rot, td->rotOrder,fmat); /* and apply (to end result only) */ protectedRotateBits(td->protectflag, eul, td->ext->irot); @@ -2726,16 +2726,16 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short if ((td->flag & TD_NO_LOC) == 0) { /* translation */ - VecSubf(vec, td->center, center); - Mat3MulVecfl(mat, vec); - VecAddf(vec, vec, center); + sub_v3_v3v3(vec, td->center, center); + mul_m3_v3(mat, vec); + add_v3_v3v3(vec, vec, center); /* vec now is the location where the object has to be */ - VecSubf(vec, vec, td->center); - Mat3MulVecfl(td->smtx, vec); + sub_v3_v3v3(vec, vec, td->center); + mul_m3_v3(td->smtx, vec); protectedTransBits(td->protectflag, vec); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); } @@ -2745,10 +2745,10 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short if ((t->flag & T_V3D_ALIGN)==0) { // align mode doesn't rotate objects itself /* euler or quaternion? */ if ((td->rotOrder == ROT_MODE_QUAT) || (td->flag & TD_USEQUAT)) { - Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); - Mat3ToQuat(fmat, quat); // Actual transform + mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); + mat3_to_quat( quat,fmat); // Actual transform - QuatMul(td->ext->quat, quat, td->ext->iquat); + mul_qt_qtqt(td->ext->quat, quat, td->ext->iquat); /* this function works on end result */ protectedQuaternionBits(td->protectflag, td->ext->quat, td->ext->iquat); } @@ -2756,13 +2756,13 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short /* calculate effect based on quats */ float iquat[4], tquat[4]; - AxisAngleToQuat(iquat, td->ext->irotAxis, td->ext->irotAngle); + axis_angle_to_quat(iquat, td->ext->irotAxis, td->ext->irotAngle); - Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); - Mat3ToQuat(fmat, quat); // Actual transform - QuatMul(tquat, quat, iquat); + mul_serie_m3(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0); + mat3_to_quat( quat,fmat); // Actual transform + mul_qt_qtqt(tquat, quat, iquat); - QuatToAxisAngle(quat, td->ext->rotAxis, td->ext->rotAngle); + quat_to_axis_angle( td->ext->rotAxis, td->ext->rotAngle,quat); /* this function works on end result */ protectedAxisAngleBits(td->protectflag, td->ext->rotAxis, td->ext->rotAngle, td->ext->irotAxis, td->ext->irotAngle); @@ -2770,19 +2770,19 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short else { float obmat[3][3]; - Mat3MulMat3(totmat, mat, td->mtx); - Mat3MulMat3(smat, td->smtx, totmat); + mul_m3_m3m3(totmat, mat, td->mtx); + mul_m3_m3m3(smat, td->smtx, totmat); /* calculate the total rotatation in eulers */ - VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */ - EulOToMat3(eul, td->rotOrder, obmat); + add_v3_v3v3(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */ + eulO_to_mat3( obmat,eul, td->rotOrder); /* mat = transform, obmat = object rotation */ - Mat3MulMat3(fmat, smat, obmat); + mul_m3_m3m3(fmat, smat, obmat); - Mat3ToCompatibleEulO(fmat, eul, td->ext->rot, td->rotOrder); + mat3_to_compatible_eulO( eul, td->ext->rot, td->rotOrder,fmat); /* correct back for delta rot */ - VecSubf(eul, eul, td->ext->drot); + sub_v3_v3v3(eul, eul, td->ext->drot); /* and apply */ protectedRotateBits(td->protectflag, eul, td->ext->irot); @@ -2800,7 +2800,7 @@ static void applyRotation(TransInfo *t, float angle, float axis[3]) float mat[3][3]; int i; - VecRotToMat3(axis, angle, mat); + vec_rot_to_mat3( mat,axis, angle); for(i = 0 ; i < t->total; i++, td++) { @@ -2812,10 +2812,10 @@ static void applyRotation(TransInfo *t, float angle, float axis[3]) if (t->con.applyRot) { t->con.applyRot(t, td, axis, NULL); - VecRotToMat3(axis, angle * td->factor, mat); + vec_rot_to_mat3( mat,axis, angle * td->factor); } else if (t->flag & T_PROP_EDIT) { - VecRotToMat3(axis, angle * td->factor, mat); + vec_rot_to_mat3( mat,axis, angle * td->factor); } ElementRotation(t, td, mat, t->around); @@ -2832,8 +2832,8 @@ int Rotation(TransInfo *t, short mval[2]) float mat[3][3]; VECCOPY(axis, t->viewinv[2]); - VecMulf(axis, -1.0f); - Normalize(axis); + mul_v3_fl(axis, -1.0f); + normalize_v3(axis); final = t->values[0]; @@ -2869,11 +2869,11 @@ int Rotation(TransInfo *t, short mval[2]) sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext); } - VecRotToMat3(axis, final, mat); + vec_rot_to_mat3( mat,axis, final); // TRANSFORM_FIX_ME // t->values[0] = final; // used in manipulator -// Mat3CpyMat3(t->mat, mat); // used in manipulator +// copy_m3_m3(t->mat, mat); // used in manipulator applyRotation(t, final, axis); @@ -2914,10 +2914,10 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a float mat[3][3], smat[3][3], totmat[3][3]; int i; - VecRotToMat3(axis1, angles[0], smat); - VecRotToMat3(axis2, angles[1], totmat); + vec_rot_to_mat3( smat,axis1, angles[0]); + vec_rot_to_mat3( totmat,axis2, angles[1]); - Mat3MulMat3(mat, smat, totmat); + mul_m3_m3m3(mat, smat, totmat); for(i = 0 ; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) @@ -2927,10 +2927,10 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a continue; if (t->flag & T_PROP_EDIT) { - VecRotToMat3(axis1, td->factor * angles[0], smat); - VecRotToMat3(axis2, td->factor * angles[1], totmat); + vec_rot_to_mat3( smat,axis1, td->factor * angles[0]); + vec_rot_to_mat3( totmat,axis2, td->factor * angles[1]); - Mat3MulMat3(mat, smat, totmat); + mul_m3_m3m3(mat, smat, totmat); } ElementRotation(t, td, mat, t->around); @@ -2946,8 +2946,8 @@ int Trackball(TransInfo *t, short mval[2]) VECCOPY(axis1, t->persinv[0]); VECCOPY(axis2, t->persinv[1]); - Normalize(axis1); - Normalize(axis2); + normalize_v3(axis1); + normalize_v3(axis2); phi[0] = t->values[0]; phi[1] = t->values[1]; @@ -2972,13 +2972,13 @@ int Trackball(TransInfo *t, short mval[2]) sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext); } - VecRotToMat3(axis1, phi[0], smat); - VecRotToMat3(axis2, phi[1], totmat); + vec_rot_to_mat3( smat,axis1, phi[0]); + vec_rot_to_mat3( totmat,axis2, phi[1]); - Mat3MulMat3(mat, smat, totmat); + mul_m3_m3m3(mat, smat, totmat); // TRANSFORM_FIX_ME - //Mat3CpyMat3(t->mat, mat); // used in manipulator + //copy_m3_m3(t->mat, mat); // used in manipulator applyTrackball(t, axis1, axis2, phi); @@ -3030,7 +3030,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) { if (hasNumInput(&t->num)) { outputNumInput(&(t->num), tvec); - dist = VecLength(t->num.val); + dist = len_v3(t->num.val); } else { float dvec[3]; @@ -3038,7 +3038,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) { VECCOPY(dvec, vec); applyAspectRatio(t, dvec); - dist = VecLength(vec); + dist = len_v3(vec); if(t->scene->unit.system) { int i, do_split= t->scene->unit.flag & USER_UNIT_OPT_SPLIT ? 1:0; @@ -3113,12 +3113,12 @@ static void applyTranslation(TransInfo *t, float vec[3]) { float mat[3][3]; float angle; - Crossf(axis, original_normal, t->tsnap.snapNormal); - angle = saacos(Inpf(original_normal, t->tsnap.snapNormal)); + cross_v3_v3v3(axis, original_normal, t->tsnap.snapNormal); + angle = saacos(dot_v3v3(original_normal, t->tsnap.snapNormal)); - AxisAngleToQuat(quat, axis, angle); + axis_angle_to_quat(quat, axis, angle); - QuatToMat3(quat, mat); + quat_to_mat3( mat,quat); ElementRotation(t, td, mat, V3D_LOCAL); } @@ -3126,7 +3126,7 @@ static void applyTranslation(TransInfo *t, float vec[3]) { { float mat[3][3]; - Mat3One(mat); + unit_m3(mat); ElementRotation(t, td, mat, V3D_LOCAL); } @@ -3140,12 +3140,12 @@ static void applyTranslation(TransInfo *t, float vec[3]) { VECCOPY(tvec, vec); } - Mat3MulVecfl(td->smtx, tvec); - VecMulf(tvec, td->factor); + mul_m3_v3(td->smtx, tvec); + mul_v3_fl(tvec, td->factor); protectedTransBits(td->protectflag, tvec); - VecAddf(td->loc, td->iloc, tvec); + add_v3_v3v3(td->loc, td->iloc, tvec); constraintTransLim(t, td); } @@ -3252,10 +3252,10 @@ int ShrinkFatten(TransInfo *t, short mval[2]) continue; VECCOPY(vec, td->axismtx[2]); - VecMulf(vec, distance); - VecMulf(vec, td->factor); + mul_v3_fl(vec, distance); + mul_v3_fl(vec, td->factor); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); } recalcData(t); @@ -3462,23 +3462,23 @@ int PushPull(TransInfo *t, short mval[2]) if (td->flag & TD_SKIP) continue; - VecSubf(vec, t->center, td->center); + sub_v3_v3v3(vec, t->center, td->center); if (t->con.applyRot && t->con.mode & CON_APPLY) { t->con.applyRot(t, td, axis, NULL); if (isLockConstraint(t)) { float dvec[3]; - Projf(dvec, vec, axis); - VecSubf(vec, vec, dvec); + project_v3_v3v3(dvec, vec, axis); + sub_v3_v3v3(vec, vec, dvec); } else { - Projf(vec, vec, axis); + project_v3_v3v3(vec, vec, axis); } } - Normalize(vec); - VecMulf(vec, distance); - VecMulf(vec, td->factor); + normalize_v3(vec); + mul_v3_fl(vec, distance); + mul_v3_fl(vec, td->factor); - VecAddf(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); } recalcData(t); @@ -3791,8 +3791,8 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) float tmat[3][3], smat[3][3], oldy; float sizemat[3][3]; - Mat3MulMat3(smat, mat, td->mtx); - Mat3MulMat3(tmat, td->smtx, smat); + mul_m3_m3m3(smat, mat, td->mtx); + mul_m3_m3m3(tmat, td->smtx, smat); if (t->con.applySize) { t->con.applySize(t, td, tmat); @@ -3800,9 +3800,9 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) /* we've tucked the scale in loc */ oldy= td->iloc[1]; - SizeToMat3(td->iloc, sizemat); - Mat3MulMat3(tmat, tmat, sizemat); - Mat3ToSize(tmat, td->loc); + size_to_mat3( sizemat,td->iloc); + mul_m3_m3m3(tmat, tmat, sizemat); + mat3_to_size( td->loc,tmat); td->loc[1]= oldy; } @@ -3834,13 +3834,13 @@ int BoneSize(TransInfo *t, short mval[2]) constraintNumInput(t, size); } - SizeToMat3(size, mat); + size_to_mat3( mat,size); if (t->con.applySize) { t->con.applySize(t, NULL, mat); } - Mat3CpyMat3(t->mat, mat); // used in manipulator + copy_m3_m3(t->mat, mat); // used in manipulator headerBoneSize(t, size, str); @@ -3955,7 +3955,7 @@ static int createSlideVerts(TransInfo *t) if (!v3d) { /*ok, let's try to survive this*/ - Mat4One(projectMat); + unit_m4(projectMat); } else { view3d_get_object_project_mat(v3d, t->obedit, projectMat); } @@ -4248,12 +4248,12 @@ static int createSlideVerts(TransInfo *t) } if (ev == tempsv->up->v1) { - VecSubf(vec, co, co2); + sub_v3_v3v3(vec, co, co2); } else { - VecSubf(vec, co2, co); + sub_v3_v3v3(vec, co2, co); } - VecAddf(start, start, vec); + add_v3_v3v3(start, start, vec); if (v3d) { view3d_project_float(t->ar, tempsv->down->v1->co, co, projectMat); @@ -4261,12 +4261,12 @@ static int createSlideVerts(TransInfo *t) } if (ev == tempsv->down->v1) { - VecSubf(vec, co2, co); + sub_v3_v3v3(vec, co2, co); } else { - VecSubf(vec, co, co2); + sub_v3_v3v3(vec, co, co2); } - VecAddf(end, end, vec); + add_v3_v3v3(end, end, vec); totvec += 1.0f; nearest = (EditVert*)look->link; @@ -4278,12 +4278,12 @@ static int createSlideVerts(TransInfo *t) look = look->next; } - VecAddf(start, start, end); - VecMulf(start, 0.5*(1.0/totvec)); + add_v3_v3v3(start, start, end); + mul_v3_fl(start, 0.5*(1.0/totvec)); VECCOPY(vec, start); start[0] = t->mval[0]; start[1] = t->mval[1]; - VecAddf(end, start, vec); + add_v3_v3v3(end, start, vec); sld->start[0] = (short) start[0]; sld->start[1] = (short) start[1]; @@ -4484,7 +4484,7 @@ int doEdgeSlide(TransInfo *t, float perc) upVert = editedge_getOtherVert(tempsv->up, centerVert); downVert = editedge_getOtherVert(tempsv->down, centerVert); - len = MIN2(perc, VecLenf(upVert->co,downVert->co)); + len = MIN2(perc, len_v3v3(upVert->co,downVert->co)); len = MAX2(len, 0); //Adjust Edgeloop @@ -4496,13 +4496,13 @@ int doEdgeSlide(TransInfo *t, float perc) tempsv = BLI_ghash_lookup(vertgh,ev); tempev = editedge_getOtherVert((perc>=0)?tempsv->up:tempsv->down, ev); - VecLerpf(ev->co, tempsv->origvert.co, tempev->co, fabs(perc)); + interp_v3_v3v3(ev->co, tempsv->origvert.co, tempev->co, fabs(perc)); if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { - Vec2Lerpf(uv_tmp, suv->origuv, (perc>=0)?suv->uv_up:suv->uv_down, fabs(perc)); + interp_v2_v2v2(uv_tmp, suv->origuv, (perc>=0)?suv->uv_up:suv->uv_down, fabs(perc)); fuv_link = suv->fuv_list; while (fuv_link) { VECCOPY2D(((float *)fuv_link->link), uv_tmp); @@ -4522,17 +4522,17 @@ int doEdgeSlide(TransInfo *t, float perc) float newlen; ev = look->link; tempsv = BLI_ghash_lookup(vertgh,ev); - newlen = (len / VecLenf(editedge_getOtherVert(tempsv->up,ev)->co,editedge_getOtherVert(tempsv->down,ev)->co)); + newlen = (len / len_v3v3(editedge_getOtherVert(tempsv->up,ev)->co,editedge_getOtherVert(tempsv->down,ev)->co)); if(newlen > 1.0) {newlen = 1.0;} if(newlen < 0.0) {newlen = 0.0;} if(flip == 0) { - VecLerpf(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen)); + interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen)); if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { - Vec2Lerpf(uv_tmp, suv->uv_down, suv->uv_up, fabs(newlen)); + interp_v2_v2v2(uv_tmp, suv->uv_down, suv->uv_up, fabs(newlen)); fuv_link = suv->fuv_list; while (fuv_link) { VECCOPY2D(((float *)fuv_link->link), uv_tmp); @@ -4542,14 +4542,14 @@ int doEdgeSlide(TransInfo *t, float perc) } } } else{ - VecLerpf(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen)); + interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen)); if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { - Vec2Lerpf(uv_tmp, suv->uv_up, suv->uv_down, fabs(newlen)); + interp_v2_v2v2(uv_tmp, suv->uv_up, suv->uv_down, fabs(newlen)); fuv_link = suv->fuv_list; while (fuv_link) { VECCOPY2D(((float *)fuv_link->link), uv_tmp); @@ -4775,7 +4775,7 @@ int Mirror(TransInfo *t, short mval[2]) if (t->con.mode & CON_APPLY) { size[0] = size[1] = size[2] = -1; - SizeToMat3(size, mat); + size_to_mat3( mat,size); if (t->con.applySize) { t->con.applySize(t, NULL, mat); @@ -4801,7 +4801,7 @@ int Mirror(TransInfo *t, short mval[2]) { size[0] = size[1] = size[2] = 1; - SizeToMat3(size, mat); + size_to_mat3( mat,size); for(i = 0, td=t->data; i < t->total; i++, td++) { if (td->flag & TD_NOACTION) @@ -4864,9 +4864,9 @@ int Align(TransInfo *t, short mval[2]) } } - Mat3Inv(invmat, td->axismtx); + invert_m3_m3(invmat, td->axismtx); - Mat3MulMat3(mat, t->spacemtx, invmat); + mul_m3_m3m3(mat, t->spacemtx, invmat); ElementRotation(t, td, mat, t->around); } diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 7a6244b72b8..da8f0c4d0e9 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -73,7 +73,7 @@ #include "ED_image.h" #include "ED_view3d.h" -#include "BLI_arithb.h" +#include "BLI_math.h" //#include "blendef.h" // @@ -157,7 +157,7 @@ void constraintNumInput(TransInfo *t, float vec[3]) static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) { int i = 0; - Mat3MulVecfl(t->con.imtx, vec); + mul_m3_v3(t->con.imtx, vec); snapGrid(t, vec); @@ -194,7 +194,7 @@ static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) { pvec[i++] = vec[2]; } - Mat3MulVecfl(t->con.mtx, vec); + mul_m3_v3(t->con.mtx, vec); } static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3]) { @@ -206,16 +206,16 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3 /* For when view is parallel to constraint... will cause NaNs otherwise So we take vertical motion in 3D space and apply it to the constraint axis. Nice for camera grab + MMB */ - if(1.0f - fabs(Inpf(axis, t->viewinv[2])) < 0.000001f) { - Projf(vec, in, t->viewinv[1]); - factor = Inpf(t->viewinv[1], vec) * 2.0f; + if(1.0f - fabs(dot_v3v3(axis, t->viewinv[2])) < 0.000001f) { + project_v3_v3v3(vec, in, t->viewinv[1]); + factor = dot_v3v3(t->viewinv[1], vec) * 2.0f; /* since camera distance is quite relative, use quadratic relationship. holding shift can compensate */ if(factor<0.0f) factor*= -factor; else factor*= factor; VECCOPY(out, axis); - Normalize(out); - VecMulf(out, -factor); /* -factor makes move down going backwards */ + normalize_v3(out); + mul_v3_fl(out, -factor); /* -factor makes move down going backwards */ } else { float v[3], i1[3], i2[3]; @@ -224,32 +224,32 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3 float plane[3]; getViewVector(t, t->con.center, norm_center); - Crossf(plane, norm_center, axis); + cross_v3_v3v3(plane, norm_center, axis); - Projf(vec, in, plane); - VecSubf(vec, in, vec); + project_v3_v3v3(vec, in, plane); + sub_v3_v3v3(vec, in, vec); - VecAddf(v, vec, t->con.center); + add_v3_v3v3(v, vec, t->con.center); getViewVector(t, v, norm); /* give arbitrary large value if projection is impossible */ - factor = Inpf(axis, norm); + factor = dot_v3v3(axis, norm); if (1 - fabs(factor) < 0.0002f) { VECCOPY(out, axis); if (factor > 0) { - VecMulf(out, 1000000000); + mul_v3_fl(out, 1000000000); } else { - VecMulf(out, -1000000000); + mul_v3_fl(out, -1000000000); } } else { - VecAddf(v2, t->con.center, axis); - VecAddf(v4, v, norm); + add_v3_v3v3(v2, t->con.center, axis); + add_v3_v3v3(v4, v, norm); - LineIntersectLine(t->con.center, v2, v, v4, i1, i2); + isect_line_line_v3(t->con.center, v2, v, v4, i1, i2); - VecSubf(v, i2, v); + sub_v3_v3v3(v, i2, v); - VecSubf(out, i1, t->con.center); + sub_v3_v3v3(out, i1, t->con.center); } } } @@ -257,21 +257,21 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3 static void planeProjection(TransInfo *t, float in[3], float out[3]) { float vec[3], factor, norm[3]; - VecAddf(vec, in, t->con.center); + add_v3_v3v3(vec, in, t->con.center); getViewVector(t, vec, norm); - VecSubf(vec, out, in); + sub_v3_v3v3(vec, out, in); - factor = Inpf(vec, norm); + factor = dot_v3v3(vec, norm); if (fabs(factor) <= 0.001) { return; /* prevent divide by zero */ } - factor = Inpf(vec, vec) / factor; + factor = dot_v3v3(vec, vec) / factor; VECCOPY(vec, norm); - VecMulf(vec, factor); + mul_v3_fl(vec, factor); - VecAddf(out, in, vec); + add_v3_v3v3(out, in, vec); } /* @@ -287,7 +287,7 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], flo { VECCOPY(out, in); if (!td && t->con.mode & CON_APPLY) { - Mat3MulVecfl(t->con.pmtx, out); + mul_m3_v3(t->con.pmtx, out); // With snap, a projection is alright, no need to correct for view alignment if ((t->tsnap.status & SNAP_ON) == 0) { @@ -331,7 +331,7 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, float in[3], f VECCOPY(out, in); if (t->con.mode & CON_APPLY) { if (!td) { - Mat3MulVecfl(t->con.pmtx, out); + mul_m3_v3(t->con.pmtx, out); if (getConstraintSpaceDimension(t) == 2) { if (out[0] != 0.0f || out[1] != 0.0f || out[2] != 0.0f) { planeProjection(t, in, out); @@ -367,7 +367,7 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, float in[3], f if (t->con.mode & CON_AXIS2) { out[2] = in[i++]; } - Mat3MulVecfl(td->axismtx, out); + mul_m3_v3(td->axismtx, out); } } } @@ -393,8 +393,8 @@ static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3 smat[2][2] = 1.0f; } - Mat3MulMat3(tmat, smat, t->con.imtx); - Mat3MulMat3(smat, t->con.mtx, tmat); + mul_m3_m3m3(tmat, smat, t->con.imtx); + mul_m3_m3m3(smat, t->con.mtx, tmat); } } @@ -410,7 +410,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3] float tmat[3][3]; float imat[3][3]; - Mat3Inv(imat, td->axismtx); + invert_m3_m3(imat, td->axismtx); if (!(t->con.mode & CON_AXIS0)) { smat[0][0] = 1.0f; @@ -422,8 +422,8 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3] smat[2][2] = 1.0f; } - Mat3MulMat3(tmat, smat, imat); - Mat3MulMat3(smat, td->axismtx, tmat); + mul_m3_m3m3(tmat, smat, imat); + mul_m3_m3m3(smat, td->axismtx, tmat); } } @@ -462,7 +462,7 @@ static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], fl } /* don't flip axis if asked to or if num input */ if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { - if (Inpf(vec, t->viewinv[2]) > 0.0f) { + if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { *angle = -(*angle); } } @@ -508,7 +508,7 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3], break; } if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) { - if (Inpf(vec, t->viewinv[2]) > 0.0f) { + if (dot_v3v3(vec, t->viewinv[2]) > 0.0f) { *angle = -(*angle); } } @@ -519,7 +519,7 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3], void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) { strncpy(t->con.text + 1, text, 48); - Mat3CpyMat3(t->con.mtx, space); + copy_m3_m3(t->con.mtx, space); t->con.mode = mode; getConstraintMatrix(t); @@ -535,7 +535,7 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) void setLocalConstraint(TransInfo *t, int mode, const char text[]) { if (t->flag & T_EDIT) { float obmat[3][3]; - Mat3CpyMat4(obmat, t->scene->obedit->obmat); + copy_m3_m4(obmat, t->scene->obedit->obmat); setConstraint(t, obmat, mode, text); } else { @@ -544,7 +544,7 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) { } else { strncpy(t->con.text + 1, text, 48); - Mat3CpyMat3(t->con.mtx, t->data->axismtx); + copy_m3_m3(t->con.mtx, t->data->axismtx); t->con.mode = mode; getConstraintMatrix(t); @@ -573,7 +573,7 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte { float mtx[3][3]; sprintf(text, ftext, "global"); - Mat3One(mtx); + unit_m3(mtx); setConstraint(t, mtx, mode, text); } break; @@ -630,7 +630,7 @@ void drawConstraint(const struct bContext *C, TransInfo *t) float vec[3]; char col2[3] = {255,255,255}; convertViewVec(t, vec, (short)(t->mval[0] - t->con.imval[0]), (short)(t->mval[1] - t->con.imval[1])); - VecAddf(vec, vec, tc->center); + add_v3_v3v3(vec, vec, tc->center); drawLine(t, tc->center, tc->mtx[0], 'x', 0); drawLine(t, tc->center, tc->mtx[1], 'y', 0); @@ -673,13 +673,13 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) if(t->spacetype == SPACE_VIEW3D && rv3d != NULL) { - Mat4CpyMat4(tmat, rv3d->viewmat); - Mat4Invert(imat, tmat); + copy_m4_m4(tmat, rv3d->viewmat); + invert_m4_m4(imat, tmat); } else { - Mat4One(tmat); - Mat4One(imat); + unit_m4(tmat); + unit_m4(imat); } glPushMatrix(); @@ -756,8 +756,8 @@ void stopConstraint(TransInfo *t) { void getConstraintMatrix(TransInfo *t) { float mat[3][3]; - Mat3Inv(t->con.imtx, t->con.mtx); - Mat3One(t->con.pmtx); + invert_m3_m3(t->con.imtx, t->con.mtx); + unit_m3(t->con.pmtx); if (!(t->con.mode & CON_AXIS0)) { t->con.pmtx[0][0] = @@ -777,15 +777,15 @@ void getConstraintMatrix(TransInfo *t) t->con.pmtx[2][2] = 0.0f; } - Mat3MulMat3(mat, t->con.pmtx, t->con.imtx); - Mat3MulMat3(t->con.pmtx, t->con.mtx, mat); + mul_m3_m3m3(mat, t->con.pmtx, t->con.imtx); + mul_m3_m3m3(t->con.pmtx, t->con.mtx, mat); } /*------------------------- MMB Select -------------------------------*/ void initSelectConstraint(TransInfo *t, float mtx[3][3]) { - Mat3CpyMat3(t->con.mtx, mtx); + copy_m3_m3(t->con.mtx, mtx); t->con.mode |= CON_APPLY; t->con.mode |= CON_SELECT; @@ -852,24 +852,24 @@ static void setNearestAxis3d(TransInfo *t) projecting them with window_to_3d_delta and then get the length of that vector. */ zfac= t->persmat[0][3]*t->center[0]+ t->persmat[1][3]*t->center[1]+ t->persmat[2][3]*t->center[2]+ t->persmat[3][3]; - zfac = VecLength(t->persinv[0]) * 2.0f/t->ar->winx * zfac * 30.0f; + zfac = len_v3(t->persinv[0]) * 2.0f/t->ar->winx * zfac * 30.0f; for (i = 0; i<3; i++) { VECCOPY(axis, t->con.mtx[i]); - VecMulf(axis, zfac); + mul_v3_fl(axis, zfac); /* now we can project to get window coordinate */ - VecAddf(axis, axis, t->con.center); + add_v3_v3v3(axis, axis, t->con.center); projectIntView(t, axis, icoord); axis[0] = (float)(icoord[0] - t->center2d[0]); axis[1] = (float)(icoord[1] - t->center2d[1]); axis[2] = 0.0f; - if (Normalize(axis) != 0.0f) { - Projf(proj, mvec, axis); - VecSubf(axis, mvec, proj); - len[i] = Normalize(axis); + if (normalize_v3(axis) != 0.0f) { + project_v3_v3v3(proj, mvec, axis); + sub_v3_v3v3(axis, mvec, proj); + len[i] = normalize_v3(axis); } else { len[i] = 10000000000.0f; diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 85ebf725467..618e71951c2 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -135,7 +135,7 @@ //#include "BDR_editobject.h" // reset_slowparents() //#include "BDR_gpencil.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" @@ -263,9 +263,9 @@ static void set_prop_dist(TransInfo *t, short with_dist) for (i = 0, td= t->data; i < t->total; i++, td++) { if(td->flag & TD_SELECTED) { - VecSubf(vec, tob->center, td->center); - Mat3MulVecfl(tob->mtx, vec); - dist = Normalize(vec); + sub_v3_v3v3(vec, tob->center, td->center); + mul_m3_v3(tob->mtx, vec); + dist = normalize_v3(vec); if (tob->rdist == -1.0f) { tob->rdist = dist; } @@ -315,10 +315,10 @@ static void createTransTexspace(bContext *C, TransInfo *t) VECCOPY(td->center, ob->obmat[3]); td->ob = ob; - Mat3CpyMat4(td->mtx, ob->obmat); - Mat3CpyMat4(td->axismtx, ob->obmat); - Mat3Ortho(td->axismtx); - Mat3Inv(td->smtx, td->mtx); + copy_m3_m4(td->mtx, ob->obmat); + copy_m3_m4(td->axismtx, ob->obmat); + normalize_m3(td->axismtx); + invert_m3_m3(td->smtx, td->mtx); if (give_obdata_texspace(ob, &texflag, &td->loc, &td->ext->size, &td->ext->rot)) { *texflag &= ~AUTOSPACE; @@ -358,14 +358,14 @@ static void createTransEdge(bContext *C, TransInfo *t) { td= t->data= MEM_callocN(t->total * sizeof(TransData), "TransCrease"); - Mat3CpyMat4(mtx, t->obedit->obmat); - Mat3Inv(smtx, mtx); + copy_m3_m4(mtx, t->obedit->obmat); + invert_m3_m3(smtx, mtx); for(eed= em->edges.first; eed; eed= eed->next) { if(eed->h==0 && (eed->f & SELECT || propmode)) { /* need to set center for center calculations */ - VecAddf(td->center, eed->v1->co, eed->v2->co); - VecMulf(td->center, 0.5f); + add_v3_v3v3(td->center, eed->v1->co, eed->v2->co); + mul_v3_fl(td->center, 0.5f); td->loc= NULL; if (eed->f & SELECT) @@ -374,8 +374,8 @@ static void createTransEdge(bContext *C, TransInfo *t) { td->flag= 0; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td->ext = NULL; if (t->mode == TFM_BWEIGHT) { @@ -460,7 +460,7 @@ static short apply_targetless_ik(Object *ob) float offs_bone[4][4]; /* offs_bone = yoffs(b-1) + root(b) + bonemat(b) */ - Mat4CpyMat3(offs_bone, bone->bone_mat); + copy_m4_m3(offs_bone, bone->bone_mat); /* The bone's root offset (is in the parent's coordinate system) */ VECCOPY(offs_bone[3], bone->head); @@ -471,60 +471,60 @@ static short apply_targetless_ik(Object *ob) /* pose_mat(b-1) * offs_bone */ if(parchan->bone->flag & BONE_HINGE) { /* the rotation of the parent restposition */ - Mat4CpyMat4(rmat, parbone->arm_mat); /* rmat used as temp */ + copy_m4_m4(rmat, parbone->arm_mat); /* rmat used as temp */ /* the location of actual parent transform */ VECCOPY(rmat[3], offs_bone[3]); offs_bone[3][0]= offs_bone[3][1]= offs_bone[3][2]= 0.0f; - Mat4MulVecfl(parchan->parent->pose_mat, rmat[3]); + mul_m4_v3(parchan->parent->pose_mat, rmat[3]); - Mat4MulMat4(tmat, offs_bone, rmat); + mul_m4_m4m4(tmat, offs_bone, rmat); } else if(parchan->bone->flag & BONE_NO_SCALE) { - Mat4MulMat4(tmat, offs_bone, parchan->parent->pose_mat); - Mat4Ortho(tmat); + mul_m4_m4m4(tmat, offs_bone, parchan->parent->pose_mat); + normalize_m4(tmat); } else - Mat4MulMat4(tmat, offs_bone, parchan->parent->pose_mat); + mul_m4_m4m4(tmat, offs_bone, parchan->parent->pose_mat); - Mat4Invert(imat, tmat); + invert_m4_m4(imat, tmat); } else { - Mat4CpyMat3(tmat, bone->bone_mat); + copy_m4_m3(tmat, bone->bone_mat); VECCOPY(tmat[3], bone->head); - Mat4Invert(imat, tmat); + invert_m4_m4(imat, tmat); } /* result matrix */ - Mat4MulMat4(rmat, parchan->pose_mat, imat); + mul_m4_m4m4(rmat, parchan->pose_mat, imat); /* apply and decompose, doesn't work for constraints or non-uniform scale well */ { float rmat3[3][3], qrmat[3][3], imat[3][3], smat[3][3]; - Mat3CpyMat4(rmat3, rmat); + copy_m3_m4(rmat3, rmat); /* rotation */ if (parchan->rotmode > 0) - Mat3ToEulO(rmat3, parchan->eul, parchan->rotmode); + mat3_to_eulO( parchan->eul, parchan->rotmode,rmat3); else if (parchan->rotmode == ROT_MODE_AXISANGLE) - Mat3ToAxisAngle(rmat3, parchan->rotAxis, &pchan->rotAngle); + mat3_to_axis_angle( parchan->rotAxis, &pchan->rotAngle,rmat3); else - Mat3ToQuat(rmat3, parchan->quat); + mat3_to_quat( parchan->quat,rmat3); /* for size, remove rotation */ /* causes problems with some constraints (so apply only if needed) */ if (data->flag & CONSTRAINT_IK_STRETCH) { if (parchan->rotmode > 0) - EulOToMat3(parchan->eul, parchan->rotmode, qrmat); + eulO_to_mat3( qrmat,parchan->eul, parchan->rotmode); else if (parchan->rotmode == ROT_MODE_AXISANGLE) - AxisAngleToMat3(parchan->rotAxis, parchan->rotAngle, qrmat); + axis_angle_to_mat3( qrmat,parchan->rotAxis, parchan->rotAngle); else - QuatToMat3(parchan->quat, qrmat); + quat_to_mat3( qrmat,parchan->quat); - Mat3Inv(imat, qrmat); - Mat3MulMat3(smat, rmat3, imat); - Mat3ToSize(smat, parchan->size); + invert_m3_m3(imat, qrmat); + mul_m3_m3m3(smat, rmat3, imat); + mat3_to_size( parchan->size,smat); } /* causes problems with some constraints (e.g. childof), so disable this */ @@ -602,38 +602,38 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr /* proper way to get parent transform + own transform + constraints transform */ - Mat3CpyMat4(omat, ob->obmat); + copy_m3_m4(omat, ob->obmat); if (pchan->parent) { if(pchan->bone->flag & BONE_HINGE) - Mat3CpyMat4(pmat, pchan->parent->bone->arm_mat); + copy_m3_m4(pmat, pchan->parent->bone->arm_mat); else - Mat3CpyMat4(pmat, pchan->parent->pose_mat); + copy_m3_m4(pmat, pchan->parent->pose_mat); if (constraints_list_needinv(t, &pchan->constraints)) { - Mat3CpyMat4(tmat, pchan->constinv); - Mat3Inv(cmat, tmat); - Mat3MulSerie(td->mtx, pchan->bone->bone_mat, pmat, omat, cmat, 0,0,0,0); // dang mulserie swaps args + copy_m3_m4(tmat, pchan->constinv); + invert_m3_m3(cmat, tmat); + mul_serie_m3(td->mtx, pchan->bone->bone_mat, pmat, omat, cmat, 0,0,0,0); // dang mulserie swaps args } else - Mat3MulSerie(td->mtx, pchan->bone->bone_mat, pmat, omat, 0,0,0,0,0); // dang mulserie swaps args + mul_serie_m3(td->mtx, pchan->bone->bone_mat, pmat, omat, 0,0,0,0,0); // dang mulserie swaps args } else { if (constraints_list_needinv(t, &pchan->constraints)) { - Mat3CpyMat4(tmat, pchan->constinv); - Mat3Inv(cmat, tmat); - Mat3MulSerie(td->mtx, pchan->bone->bone_mat, omat, cmat, 0,0,0,0,0); // dang mulserie swaps args + copy_m3_m4(tmat, pchan->constinv); + invert_m3_m3(cmat, tmat); + mul_serie_m3(td->mtx, pchan->bone->bone_mat, omat, cmat, 0,0,0,0,0); // dang mulserie swaps args } else - Mat3MulMat3(td->mtx, omat, pchan->bone->bone_mat); // Mat3MulMat3 has swapped args! + mul_m3_m3m3(td->mtx, omat, pchan->bone->bone_mat); // Mat3MulMat3 has swapped args! } - Mat3Inv(td->smtx, td->mtx); + invert_m3_m3(td->smtx, td->mtx); /* for axismat we use bone's own transform */ - Mat3CpyMat4(pmat, pchan->pose_mat); - Mat3MulMat3(td->axismtx, omat, pmat); - Mat3Ortho(td->axismtx); + copy_m3_m4(pmat, pchan->pose_mat); + mul_m3_m3m3(td->axismtx, omat, pmat); + normalize_m3(td->axismtx); if (t->mode==TFM_BONESIZE) { bArmature *arm= t->poseobj->data; @@ -666,8 +666,8 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr data->flag |= CONSTRAINT_IK_AUTO; /* only object matrix correction */ - Mat3CpyMat3 (td->mtx, omat); - Mat3Inv (td->smtx, td->mtx); + copy_m3_m3(td->mtx, omat); + invert_m3_m3(td->smtx, td->mtx); } } @@ -878,7 +878,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan) } } - con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC); + con = add_pose_constraint(NULL, pchan, "TempConstraint", CONSTRAINT_TYPE_KINEMATIC); BLI_addtail(&pchan->constraints, con); pchan->constflag |= (PCHAN_HAS_IK|PCHAN_HAS_TARGET); /* for draw, but also for detecting while pose solving */ data= con->data; @@ -1080,8 +1080,8 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t) if (!t->total) return; - Mat3CpyMat4(mtx, t->obedit->obmat); - Mat3Inv(smtx, mtx); + copy_m3_m4(mtx, t->obedit->obmat); + invert_m3_m3(smtx, mtx); td = t->data = MEM_callocN(t->total*sizeof(TransData), "TransEditBone"); @@ -1100,8 +1100,8 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t) VECCOPY (td->center, ebo->head); td->flag= TD_SELECTED; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td->loc = NULL; td->ext = NULL; @@ -1115,8 +1115,8 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t) VECCOPY (td->center, ebo->tail); td->flag= TD_SELECTED; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td->loc = NULL; td->ext = NULL; @@ -1145,13 +1145,13 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t) td->flag= TD_SELECTED; /* use local bone matrix */ - VecSubf(delta, ebo->tail, ebo->head); + sub_v3_v3v3(delta, ebo->tail, ebo->head); vec_roll_to_mat3(delta, ebo->roll, bonemat); - Mat3MulMat3(td->mtx, mtx, bonemat); - Mat3Inv(td->smtx, td->mtx); + mul_m3_m3m3(td->mtx, mtx, bonemat); + invert_m3_m3(td->smtx, td->mtx); - Mat3CpyMat3(td->axismtx, td->mtx); - Mat3Ortho(td->axismtx); + copy_m3_m3(td->axismtx, td->mtx); + normalize_m3(td->axismtx); td->ext = NULL; @@ -1185,10 +1185,10 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t) if (ebo->flag & BONE_EDITMODE_LOCKED) td->protectflag = OB_LOCK_LOC|OB_LOCK_ROT|OB_LOCK_SCALE; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - VecSubf(delta, ebo->tail, ebo->head); + sub_v3_v3v3(delta, ebo->tail, ebo->head); vec_roll_to_mat3(delta, ebo->roll, td->axismtx); if ((ebo->flag & BONE_ROOTSEL) == 0) @@ -1210,10 +1210,10 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t) if (ebo->flag & BONE_EDITMODE_LOCKED) td->protectflag = OB_LOCK_LOC|OB_LOCK_ROT|OB_LOCK_SCALE; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - VecSubf(delta, ebo->tail, ebo->head); + sub_v3_v3v3(delta, ebo->tail, ebo->head); vec_roll_to_mat3(delta, ebo->roll, td->axismtx); td->extra = ebo; /* to fix roll */ @@ -1255,8 +1255,8 @@ static void createTransMBallVerts(bContext *C, TransInfo *t) td = t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(MBall EditMode)"); tx = t->ext = MEM_callocN(t->total*sizeof(TransDataExtension), "MetaElement_TransExtension"); - Mat3CpyMat4(mtx, t->obedit->obmat); - Mat3Inv(smtx, mtx); + copy_m3_m4(mtx, t->obedit->obmat); + invert_m3_m3(smtx, mtx); for(ml= mb->editelems->first; ml; ml= ml->next) { if(propmode || (ml->flag & SELECT)) { @@ -1267,8 +1267,8 @@ static void createTransMBallVerts(bContext *C, TransInfo *t) if(ml->flag & SELECT) td->flag= TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE; else td->flag= TD_USEQUAT; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td->ext = tx; @@ -1311,7 +1311,7 @@ static void calc_distanceCurveVerts(TransData *head, TransData *tail) { } else if(td_near) { float dist; - dist = VecLenf(td_near->center, td->center); + dist = len_v3v3(td_near->center, td->center); if (dist < (td-1)->dist) { td->dist = (td-1)->dist; } @@ -1332,7 +1332,7 @@ static void calc_distanceCurveVerts(TransData *head, TransData *tail) { } else if(td_near) { float dist; - dist = VecLenf(td_near->center, td->center); + dist = len_v3v3(td_near->center, td->center); if (td->flag & TD_NOTCONNECTED || dist < td->dist || (td+1)->dist < td->dist) { td->flag &= ~TD_NOTCONNECTED; if (dist < (td+1)->dist) { @@ -1408,8 +1408,8 @@ static void createTransCurveVerts(bContext *C, TransInfo *t) else t->total = countsel; t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Curve EditMode)"); - Mat3CpyMat4(mtx, t->obedit->obmat); - Mat3Inv(smtx, mtx); + copy_m3_m4(mtx, t->obedit->obmat); + invert_m3_m3(smtx, mtx); td = t->data; for(nu= cu->editnurb->first; nu; nu= nu->next) { @@ -1439,8 +1439,8 @@ static void createTransCurveVerts(bContext *C, TransInfo *t) hdata = initTransDataCurveHandles(td, bezt); - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td++; count++; @@ -1466,8 +1466,8 @@ static void createTransCurveVerts(bContext *C, TransInfo *t) td->val = NULL; } - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); if ((bezt->f1&SELECT)==0 && (bezt->f3&SELECT)==0) /* If the middle is selected but the sides arnt, this is needed */ @@ -1500,8 +1500,8 @@ static void createTransCurveVerts(bContext *C, TransInfo *t) hdata = initTransDataCurveHandles(td, bezt); } - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td++; count++; @@ -1542,8 +1542,8 @@ static void createTransCurveVerts(bContext *C, TransInfo *t) td->ival = bp->alfa; } - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td++; count++; @@ -1590,8 +1590,8 @@ static void createTransLatticeVerts(bContext *C, TransInfo *t) else t->total = countsel; t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Lattice EditMode)"); - Mat3CpyMat4(mtx, t->obedit->obmat); - Mat3Inv(smtx, mtx); + copy_m3_m4(mtx, t->obedit->obmat); + invert_m3_m3(smtx, mtx); td = t->data; bp = latt->def; @@ -1604,8 +1604,8 @@ static void createTransLatticeVerts(bContext *C, TransInfo *t) VECCOPY(td->center, td->loc); if(bp->f1 & SELECT) td->flag= TD_SELECTED; else td->flag= 0; - Mat3CpyMat3(td->smtx, smtx); - Mat3CpyMat3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); td->ext = NULL; td->val = NULL; @@ -1679,9 +1679,9 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) else tx = t->ext = NULL; - Mat4One(mat); + unit_m4(mat); - Mat4Invert(ob->imat,ob->obmat); + invert_m4_m4(ob->imat,ob->obmat); for(i=0, point=edit->points; i<edit->totpoint; i++, point++) { TransData *head, *tail; @@ -1695,7 +1695,7 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) for(k=0, key=point->keys; k<point->totkey; k++, key++) { if(key->flag & PEK_USE_WCO) { VECCOPY(key->world_co, key->co); - Mat4MulVecfl(mat, key->world_co); + mul_m4_v3(mat, key->world_co); td->loc = key->world_co; } else @@ -1709,8 +1709,8 @@ static void createTransParticleVerts(bContext *C, TransInfo *t) else if(!propmode) td->flag |= TD_SKIP; - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); /* don't allow moving roots */ if(k==0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) @@ -1764,15 +1764,15 @@ void flushTransParticles(TransInfo *t) if(psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, psys->particles + i, mat); - Mat4Invert(imat,mat); + invert_m4_m4(imat,mat); for(k=0, key=point->keys; k<point->totkey; k++, key++) { VECCOPY(co, key->world_co); - Mat4MulVecfl(imat, co); + mul_m4_v3(imat, co); /* optimization for proportional edit */ - if(!propmode || !FloatCompare(key->co, co, 0.0001f)) { + if(!propmode || !compare_v3v3(key->co, co, 0.0001f)) { VECCOPY(key->co, co); point->flag |= PEP_EDIT_RECALC; } @@ -1838,13 +1838,13 @@ static void editmesh_set_connectivity_distance(EditMesh *em, int total, float *v if (v1->f2) { if (v2->f2) { float nvec[3]; - float len1 = VecLength(vec1); - float len2 = VecLength(vec2); + float len1 = len_v3(vec1); + float len2 = len_v3(vec2); float lenn; /* for v2 if not selected */ if (v2->f2 != 2) { - VecSubf(nvec, v2->co, E_NEAR(v1)->co); - lenn = VecLength(nvec); + sub_v3_v3v3(nvec, v2->co, E_NEAR(v1)->co); + lenn = len_v3(nvec); /* 1 < n < 2 */ if (lenn - len1 > THRESHOLD && len2 - lenn > THRESHOLD) { VECCOPY(vec2, nvec); @@ -1860,8 +1860,8 @@ static void editmesh_set_connectivity_distance(EditMesh *em, int total, float *v } /* for v1 if not selected */ if (v1->f2 != 2) { - VecSubf(nvec, v1->co, E_NEAR(v2)->co); - lenn = VecLength(nvec); + sub_v3_v3v3(nvec, v1->co, E_NEAR(v2)->co); + lenn = len_v3(nvec); /* 2 < n < 1 */ if (lenn - len2 > THRESHOLD && len1 - lenn > THRESHOLD) { VECCOPY(vec1, nvec); @@ -1878,9 +1878,9 @@ static void editmesh_set_connectivity_distance(EditMesh *em, int total, float *v } else { v2->f2 = 1; - VecSubf(vec2, v2->co, E_NEAR(v1)->co); + sub_v3_v3v3(vec2, v2->co, E_NEAR(v1)->co); /* 2 < 1 */ - if (VecLength(vec1) - VecLength(vec2) > THRESHOLD) { + if (len_v3(vec1) - len_v3(vec2) > THRESHOLD) { VECCOPY(vec2, vec1); } E_NEAR(v2) = E_NEAR(v1); @@ -1889,9 +1889,9 @@ static void editmesh_set_connectivity_distance(EditMesh *em, int total, float *v } else if (v2->f2) { v1->f2 = 1; - VecSubf(vec1, v1->co, E_NEAR(v2)->co); + sub_v3_v3v3(vec1, v1->co, E_NEAR(v2)->co); /* 2 < 1 */ - if (VecLength(vec2) - VecLength(vec1) > THRESHOLD) { + if (len_v3(vec2) - len_v3(vec1) > THRESHOLD) { VECCOPY(vec1, vec2); } E_NEAR(v1) = E_NEAR(v2); @@ -2009,13 +2009,13 @@ static void set_crazy_vertex_quat(float *quat, float *v1, float *v2, float *v3, TAN_MAKE_VEC(vecu, v1, v2); TAN_MAKE_VEC(vecv, v1, v3); - triatoquat(v1, vecu, vecv, q1); + tri_to_quat( q1,v1, vecu, vecv); TAN_MAKE_VEC(vecu, def1, def2); TAN_MAKE_VEC(vecv, def1, def3); - triatoquat(def1, vecu, vecv, q2); + tri_to_quat( q2,def1, vecu, vecv); - QuatSub(quat, q2, q1); + sub_qt_qtqt(quat, q2, q1); } #undef TAN_MAKE_VEC @@ -2192,8 +2192,8 @@ static void createTransEditVerts(bContext *C, TransInfo *t) else t->total = countsel; tob= t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)"); - Mat3CpyMat4(mtx, t->obedit->obmat); - Mat3Inv(smtx, mtx); + copy_m3_m4(mtx, t->obedit->obmat); + invert_m3_m3(smtx, mtx); if(propmode) editmesh_set_connectivity_distance(em, t->total, vectors, nears); @@ -2251,8 +2251,8 @@ static void createTransEditVerts(bContext *C, TransInfo *t) if (eve->f2) { float vec[3]; VECCOPY(vec, E_VEC(eve)); - Mat3MulVecfl(mtx, vec); - tob->dist= VecLength(vec); + mul_m3_v3(mtx, vec); + tob->dist= len_v3(vec); } else { tob->flag |= TD_NOTCONNECTED; @@ -2266,25 +2266,25 @@ static void createTransEditVerts(bContext *C, TransInfo *t) /* use both or either quat and defmat correction */ if(quats && eve->tmp.f) { - QuatToMat3(eve->tmp.p, qmat); + quat_to_mat3( qmat,eve->tmp.p); if(defmats) - Mat3MulSerie(mat, mtx, qmat, defmats[a], + mul_serie_m3(mat, mtx, qmat, defmats[a], NULL, NULL, NULL, NULL, NULL); else - Mat3MulMat3(mat, mtx, qmat); + mul_m3_m3m3(mat, mtx, qmat); } else - Mat3MulMat3(mat, mtx, defmats[a]); + mul_m3_m3m3(mat, mtx, defmats[a]); - Mat3Inv(imat, mat); + invert_m3_m3(imat, mat); - Mat3CpyMat3(tob->smtx, imat); - Mat3CpyMat3(tob->mtx, mat); + copy_m3_m3(tob->smtx, imat); + copy_m3_m3(tob->mtx, mat); } else { - Mat3CpyMat3(tob->smtx, smtx); - Mat3CpyMat3(tob->mtx, mtx); + copy_m3_m3(tob->smtx, smtx); + copy_m3_m3(tob->mtx, mtx); } /* Mirror? */ @@ -2459,8 +2459,8 @@ static void UVsToTransData(SpaceImage *sima, TransData *td, TransData2D *td2d, f else { td->dist= MAXFLOAT; } - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); } static void createTransUVs(bContext *C, TransInfo *t) @@ -2755,8 +2755,8 @@ static void createTransNlaData(bContext *C, TransInfo *t) td->flag |= TD_SELECTED; td->dist= 0.0f; - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); } else { td->val= &tdn->h1[0]; @@ -2786,8 +2786,8 @@ static void createTransNlaData(bContext *C, TransInfo *t) td->flag |= TD_SELECTED; td->dist= 0.0f; - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); } else { td->val= &tdn->h2[0]; @@ -3351,8 +3351,8 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, AnimData *adt, if (intvals) td->flag |= TD_INTVALUES; - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); } static void createTransGraphEditData(bContext *C, TransInfo *t) @@ -3986,8 +3986,8 @@ static TransData *SeqToTransData(TransInfo *t, TransData *td, TransData2D *td2d, td->flag |= TD_SELECTED; td->dist= 0.0; - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); /* Time Transform (extend) */ td->val= td2d->loc; @@ -4200,8 +4200,8 @@ static void ObjectToTransData(bContext *C, TransInfo *t, TransData *td, Object * short skip_invert = 0; /* axismtx has the real orientation */ - Mat3CpyMat4(td->axismtx, ob->obmat); - Mat3Ortho(td->axismtx); + copy_m3_m4(td->axismtx, ob->obmat); + normalize_m3(td->axismtx); td->con= ob->constraints.first; @@ -4280,7 +4280,7 @@ static void ObjectToTransData(bContext *C, TransInfo *t, TransData *td, Object * VECCOPY(td->center, ob->obmat[3]); - Mat4CpyMat4(td->ext->obmat, ob->obmat); + copy_m4_m4(td->ext->obmat, ob->obmat); /* is there a need to set the global<->data space conversion matrices? */ if (ob->parent || constinv) { @@ -4291,15 +4291,15 @@ static void ObjectToTransData(bContext *C, TransInfo *t, TransData *td, Object * * done, as it doesn't work well. */ object_to_mat3(ob, obmtx); - Mat3CpyMat4(totmat, ob->obmat); - Mat3Inv(obinv, totmat); - Mat3MulMat3(td->smtx, obmtx, obinv); - Mat3Inv(td->mtx, td->smtx); + copy_m3_m4(totmat, ob->obmat); + invert_m3_m3(obinv, totmat); + mul_m3_m3m3(td->smtx, obmtx, obinv); + invert_m3_m3(td->mtx, td->smtx); } else { /* no conversion to/from dataspace */ - Mat3One(td->smtx); - Mat3One(td->mtx); + unit_m3(td->smtx); + unit_m3(td->mtx); } /* set active flag */ @@ -5152,8 +5152,8 @@ static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node) td->flag |= TD_SELECTED; td->dist= 0.0; - Mat3One(td->mtx); - Mat3One(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); } void createTransNodeData(bContext *C, TransInfo *t) diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 2e7cfd63836..d3c0e91e57c 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -100,7 +100,7 @@ //#include "BDR_unwrapper.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_rand.h" @@ -131,20 +131,20 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3]) p1[3] = 1.0f; VECCOPY(p2, p1); p2[3] = 1.0f; - Mat4MulVec4fl(t->viewmat, p2); + mul_m4_v4(t->viewmat, p2); p2[0] = 2.0f * p2[0]; p2[1] = 2.0f * p2[1]; p2[2] = 2.0f * p2[2]; - Mat4MulVec4fl(t->viewinv, p2); + mul_m4_v4(t->viewinv, p2); - VecSubf(vec, p1, p2); + sub_v3_v3v3(vec, p1, p2); } else { VECCOPY(vec, t->viewinv[2]); } - Normalize(vec); + normalize_v3(vec); } /* ************************** GENERICS **************************** */ @@ -181,9 +181,9 @@ static void clipMirrorModifier(TransInfo *t, Object *ob) if (mmd->mirror_ob) { float obinv[4][4]; - Mat4Invert(obinv, mmd->mirror_ob->obmat); - Mat4MulMat4(mtx, ob->obmat, obinv); - Mat4Invert(imtx, mtx); + invert_m4_m4(obinv, mmd->mirror_ob->obmat); + mul_m4_m4m4(mtx, ob->obmat, obinv); + invert_m4_m4(imtx, mtx); } for(i = 0 ; i < t->total; i++, td++) { @@ -198,12 +198,12 @@ static void clipMirrorModifier(TransInfo *t, Object *ob) if (td->flag & TD_SKIP) continue; - VecCopyf(loc, td->loc); - VecCopyf(iloc, td->iloc); + copy_v3_v3(loc, td->loc); + copy_v3_v3(iloc, td->iloc); if (mmd->mirror_ob) { - VecMat4MulVecfl(loc, mtx, loc); - VecMat4MulVecfl(iloc, mtx, iloc); + mul_v3_m4v3(loc, mtx, loc); + mul_v3_m4v3(iloc, mtx, iloc); } clip = 0; @@ -231,9 +231,9 @@ static void clipMirrorModifier(TransInfo *t, Object *ob) } if (clip) { if (mmd->mirror_ob) { - VecMat4MulVecfl(loc, imtx, loc); + mul_v3_m4v3(loc, imtx, loc); } - VecCopyf(td->loc, loc); + copy_v3_v3(td->loc, loc); } } } @@ -692,7 +692,7 @@ void recalcData(TransInfo *t) } /* on extrude bones, oldlength==0.0f, so we scale radius of points */ - ebo->length= VecLenf(ebo->head, ebo->tail); + ebo->length= len_v3v3(ebo->head, ebo->tail); if(ebo->oldlength==0.0f) { ebo->rad_head= 0.25f*ebo->length; ebo->rad_tail= 0.10f*ebo->length; @@ -727,14 +727,14 @@ void recalcData(TransInfo *t) if (t->mode != TFM_ROTATION) { - VecSubf(vec, ebo->tail, ebo->head); - Normalize(vec); - RotationBetweenVectorsToQuat(qrot, td->axismtx[1], vec); - QuatMulVecf(qrot, up_axis); + sub_v3_v3v3(vec, ebo->tail, ebo->head); + normalize_v3(vec); + rotation_between_vecs_to_quat(qrot, td->axismtx[1], vec); + mul_qt_v3(qrot, up_axis); } else { - Mat3MulVecfl(t->mat, up_axis); + mul_m3_v3(t->mat, up_axis); } ebo->roll = ED_rollBoneToVector(ebo, up_axis); @@ -835,11 +835,11 @@ void drawLine(TransInfo *t, float *center, float *dir, char axis, short options) //if(t->obedit) glLoadMatrixf(t->obedit->obmat); // sets opengl viewing - VecCopyf(v3, dir); - VecMulf(v3, v3d->far); + copy_v3_v3(v3, dir); + mul_v3_fl(v3, v3d->far); - VecSubf(v2, center, v3); - VecAddf(v1, center, v3); + sub_v3_v3v3(v2, center, v3); + add_v3_v3v3(v1, center, v3); if (options & DRAWLIGHT) { col[0] = col[1] = col[2] = 220; @@ -928,7 +928,7 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) t->center[1] = t->center[2] = 0.0f; - Mat3One(t->mat); + unit_m3(t->mat); t->spacetype = sa->spacetype; if(t->spacetype == SPACE_VIEW3D) @@ -1155,7 +1155,7 @@ void restoreTransObjects(TransInfo *t) restoreElement(td); } - Mat3One(t->mat); + unit_m3(t->mat); recalcData(t); } @@ -1167,7 +1167,7 @@ void calculateCenter2D(TransInfo *t) float vec[3]; VECCOPY(vec, t->center); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); projectIntView(t, vec, t->center2d); } else { @@ -1187,10 +1187,10 @@ void calculateCenterCursor(TransInfo *t) Object *ob = t->obedit?t->obedit:t->poseobj; float mat[3][3], imat[3][3]; - VecSubf(t->center, t->center, ob->obmat[3]); - Mat3CpyMat4(mat, ob->obmat); - Mat3Inv(imat, mat); - Mat3MulVecfl(imat, t->center); + sub_v3_v3v3(t->center, t->center, ob->obmat[3]); + copy_m3_m4(mat, ob->obmat); + invert_m3_m3(imat, mat); + mul_m3_v3(imat, t->center); } calculateCenter2D(t); @@ -1234,7 +1234,7 @@ void calculateCenterMedian(TransInfo *t) if (t->data[i].flag & TD_SELECTED) { if (!(t->data[i].flag & TD_NOCENTER)) { - VecAddf(partial, partial, t->data[i].center); + add_v3_v3v3(partial, partial, t->data[i].center); total++; } } @@ -1247,7 +1247,7 @@ void calculateCenterMedian(TransInfo *t) } } if(i) - VecMulf(partial, 1.0f / total); + mul_v3_fl(partial, 1.0f / total); VECCOPY(t->center, partial); calculateCenter2D(t); @@ -1262,7 +1262,7 @@ void calculateCenterBound(TransInfo *t) if (i) { if (t->data[i].flag & TD_SELECTED) { if (!(t->data[i].flag & TD_NOCENTER)) - MinMax3(min, max, t->data[i].center); + minmax_v3_v3v3(min, max, t->data[i].center); } else { /* @@ -1277,8 +1277,8 @@ void calculateCenterBound(TransInfo *t) VECCOPY(min, t->data[i].center); } } - VecAddf(t->center, min, max); - VecMulf(t->center, 0.5); + add_v3_v3v3(t->center, min, max); + mul_v3_fl(t->center, 0.5); calculateCenter2D(t); } @@ -1341,7 +1341,7 @@ void calculateCenter(TransInfo *t) if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, t->con.center); + mul_m4_v3(ob->obmat, t->con.center); } /* for panning from cameraview */ @@ -1358,7 +1358,7 @@ void calculateCenter(TransInfo *t) float axis[3]; /* persinv is nasty, use viewinv instead, always right */ VECCOPY(axis, t->viewinv[2]); - Normalize(axis); + normalize_v3(axis); /* 6.0 = 6 grid units */ axis[0]= t->center[0]- 6.0f*axis[0]; @@ -1385,7 +1385,7 @@ void calculateCenter(TransInfo *t) float vec[3]; VECCOPY(vec, t->center); - Mat4MulVecfl(ob->obmat, vec); + mul_m4_v3(ob->obmat, vec); initgrabz(t->ar->regiondata, vec[0], vec[1], vec[2]); } else { @@ -1509,9 +1509,9 @@ float get_drawsize(ARegion *ar, float *co) size= rv3d->persmat[0][3]*co[0]+ rv3d->persmat[1][3]*co[1]+ rv3d->persmat[2][3]*co[2]+ rv3d->persmat[3][3]; VECCOPY(vec, rv3d->persinv[0]); - len1= Normalize(vec); + len1= normalize_v3(vec); VECCOPY(vec, rv3d->persinv[1]); - len2= Normalize(vec); + len2= normalize_v3(vec); size*= 0.01f*(len1>len2?len1:len2); diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c index 83d4a314057..bccbfbc65f7 100644 --- a/source/blender/editors/transform/transform_input.c +++ b/source/blender/editors/transform/transform_input.c @@ -28,7 +28,7 @@ #include "DNA_screen_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "WM_types.h" @@ -45,9 +45,9 @@ void InputVector(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) { /* calculate the main translation and the precise one separate */ convertViewVec(t, dvec, (short)(mval[0] - mi->precision_mval[0]), (short)(mval[1] - mi->precision_mval[1])); - VecMulf(dvec, 0.1f); + mul_v3_fl(dvec, 0.1f); convertViewVec(t, vec, (short)(mi->precision_mval[0] - t->imval[0]), (short)(mi->precision_mval[1] - t->imval[1])); - VecAddf(output, vec, dvec); + add_v3_v3v3(output, vec, dvec); } else { @@ -133,9 +133,9 @@ void InputHorizontalAbsolute(TransInfo *t, MouseInput *mi, short mval[2], float float vec[3]; InputVector(t, mi, mval, vec); - Projf(vec, vec, t->viewinv[0]); + project_v3_v3v3(vec, vec, t->viewinv[0]); - output[0] = Inpf(t->viewinv[0], vec) * 2.0f; + output[0] = dot_v3v3(t->viewinv[0], vec) * 2.0f; } void InputVerticalRatio(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) { @@ -158,9 +158,9 @@ void InputVerticalAbsolute(TransInfo *t, MouseInput *mi, short mval[2], float ou float vec[3]; InputVector(t, mi, mval, vec); - Projf(vec, vec, t->viewinv[1]); + project_v3_v3v3(vec, vec, t->viewinv[1]); - output[0] = Inpf(t->viewinv[1], vec) * 2.0f; + output[0] = dot_v3v3(t->viewinv[1], vec) * 2.0f; } void setCustomPoints(TransInfo *t, MouseInput *mi, short start[2], short end[2]) diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 0f4848d9120..fe79e9b4285 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -55,6 +55,7 @@ #include "RNA_access.h" +#include "BKE_action.h" #include "BKE_armature.h" #include "BKE_context.h" #include "BKE_global.h" @@ -65,7 +66,7 @@ #include "BKE_pointcache.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BIF_gl.h" @@ -115,8 +116,8 @@ static int is_mat4_flipped(float mat[][4]) { float vec[3]; - Crossf(vec, mat[0], mat[1]); - if( Inpf(vec, mat[2]) < 0.0 ) return 1; + cross_v3_v3v3(vec, mat[0], mat[1]); + if( dot_v3v3(vec, mat[2]) < 0.0 ) return 1; return 0; } @@ -128,7 +129,7 @@ static void calc_tw_center(Scene *scene, float *co) float *max= scene->twmax; DO_MINMAX(co, min, max); - VecAddf(twcent, twcent, co); + add_v3_v3v3(twcent, twcent, co); } static void protectflag_to_drawflags(short protectflag, short *drawflags) @@ -185,44 +186,35 @@ void gimbal_axis(Object *ob, float gmat[][3]) { if(ob->mode & OB_MODE_POSE) { - bPoseChannel *pchan= NULL; + bPoseChannel *pchan= get_active_posechannel(ob); - /* use channels to get stats */ - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if (pchan->bone && pchan->bone->flag & BONE_ACTIVE) { - if(test_rotmode_euler(pchan->rotmode)) { - break; - } - } - } - - if(pchan) { + if(pchan && test_rotmode_euler(pchan->rotmode)) { float mat[3][3], tmat[3][3], obmat[3][3]; - EulToGimbalAxis(mat, pchan->eul, pchan->rotmode); + eulO_to_gimbal_axis(mat, pchan->eul, pchan->rotmode); /* apply bone transformation */ - Mat3MulMat3(tmat, pchan->bone->bone_mat, mat); + mul_m3_m3m3(tmat, pchan->bone->bone_mat, mat); if (pchan->parent) { float parent_mat[3][3]; - Mat3CpyMat4(parent_mat, pchan->parent->pose_mat); - Mat3MulMat3(mat, parent_mat, tmat); + copy_m3_m4(parent_mat, pchan->parent->pose_mat); + mul_m3_m3m3(mat, parent_mat, tmat); /* needed if object transformation isn't identity */ - Mat3CpyMat4(obmat, ob->obmat); - Mat3MulMat3(gmat, obmat, mat); + copy_m3_m4(obmat, ob->obmat); + mul_m3_m3m3(gmat, obmat, mat); } else { /* needed if object transformation isn't identity */ - Mat3CpyMat4(obmat, ob->obmat); - Mat3MulMat3(gmat, obmat, tmat); + copy_m3_m4(obmat, ob->obmat); + mul_m3_m3m3(gmat, obmat, tmat); } - Mat3Ortho(gmat); + normalize_m3(gmat); } } else { @@ -233,14 +225,14 @@ void gimbal_axis(Object *ob, float gmat[][3]) { float parent_mat[3][3], amat[3][3]; - EulToGimbalAxis(amat, ob->rot, ob->rotmode); - Mat3CpyMat4(parent_mat, ob->parent->obmat); - Mat3Ortho(parent_mat); - Mat3MulMat3(gmat, parent_mat, amat); + eulO_to_gimbal_axis(amat, ob->rot, ob->rotmode); + copy_m3_m4(parent_mat, ob->parent->obmat); + normalize_m3(parent_mat); + mul_m3_m3m3(gmat, parent_mat, amat); } else { - EulToGimbalAxis(gmat, ob->rot, ob->rotmode); + eulO_to_gimbal_axis(gmat, ob->rot, ob->rotmode); } } } @@ -262,7 +254,7 @@ int calc_manipulator_stats(const bContext *C) int a, totsel= 0; /* transform widget matrix */ - Mat4One(rv3d->twmat); + unit_m4(rv3d->twmat); v3d->twdrawflag= 0xFFFF; @@ -403,10 +395,10 @@ int calc_manipulator_stats(const bContext *C) /* selection center */ if(totsel) { - VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! - Mat4MulVecfl(obedit->obmat, scene->twcent); - Mat4MulVecfl(obedit->obmat, scene->twmin); - Mat4MulVecfl(obedit->obmat, scene->twmax); + mul_v3_fl(scene->twcent, 1.0f/(float)totsel); // centroid! + mul_m4_v3(obedit->obmat, scene->twcent); + mul_m4_v3(obedit->obmat, scene->twmin); + mul_m4_v3(obedit->obmat, scene->twmax); } } else if(ob && (ob->mode & OB_MODE_POSE)) { @@ -423,10 +415,10 @@ int calc_manipulator_stats(const bContext *C) stats_pose(scene, v3d, pchan); } - VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! - Mat4MulVecfl(ob->obmat, scene->twcent); - Mat4MulVecfl(ob->obmat, scene->twmin); - Mat4MulVecfl(ob->obmat, scene->twmax); + mul_v3_fl(scene->twcent, 1.0f/(float)totsel); // centroid! + mul_m4_v3(ob->obmat, scene->twcent); + mul_m4_v3(ob->obmat, scene->twmin); + mul_m4_v3(ob->obmat, scene->twmax); } } else if(ob && (ob->mode & (OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))) { @@ -453,7 +445,7 @@ int calc_manipulator_stats(const bContext *C) /* selection center */ if(totsel) - VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! + mul_v3_fl(scene->twcent, 1.0f/(float)totsel); // centroid! } } else { @@ -474,7 +466,7 @@ int calc_manipulator_stats(const bContext *C) /* selection center */ if(totsel) { - VecMulf(scene->twcent, 1.0f/(float)totsel); // centroid! + mul_v3_fl(scene->twcent, 1.0f/(float)totsel); // centroid! } } @@ -489,37 +481,37 @@ int calc_manipulator_stats(const bContext *C) case V3D_MANIP_GIMBAL: { float mat[3][3]; - Mat3One(mat); + unit_m3(mat); gimbal_axis(ob, mat); - Mat4CpyMat3(rv3d->twmat, mat); + copy_m4_m3(rv3d->twmat, mat); break; } case V3D_MANIP_NORMAL: if(obedit || ob->mode & OB_MODE_POSE) { float mat[3][3]; ED_getTransformOrientationMatrix(C, mat, (v3d->around == V3D_ACTIVE)); - Mat4CpyMat3(rv3d->twmat, mat); + copy_m4_m3(rv3d->twmat, mat); break; } /* no break we define 'normal' as 'local' in Object mode */ case V3D_MANIP_LOCAL: - Mat4CpyMat4(rv3d->twmat, ob->obmat); - Mat4Ortho(rv3d->twmat); + copy_m4_m4(rv3d->twmat, ob->obmat); + normalize_m4(rv3d->twmat); break; case V3D_MANIP_VIEW: { float mat[3][3]; - Mat3CpyMat4(mat, rv3d->viewinv); - Mat3Ortho(mat); - Mat4CpyMat3(rv3d->twmat, mat); + copy_m3_m4(mat, rv3d->viewinv); + normalize_m3(mat); + copy_m4_m3(rv3d->twmat, mat); } break; default: /* V3D_MANIP_CUSTOM */ { float mat[3][3]; applyTransformOrientation(C, mat, NULL); - Mat4CpyMat3(rv3d->twmat, mat); + copy_m4_m3(rv3d->twmat, mat); break; } } @@ -536,7 +528,7 @@ static float screen_aligned(RegionView3D *rv3d, float mat[][4]) float vec[3], size; VECCOPY(vec, mat[0]); - size= Normalize(vec); + size= normalize_v3(vec); glTranslatef(mat[3][0], mat[3][1], mat[3][2]); @@ -717,8 +709,8 @@ static void preOrtho(int ortho, float twmat[][4], int axis) { if (ortho == 0) { float omat[4][4]; - Mat4CpyMat4(omat, twmat); - Mat4Orthogonal(omat, axis); + copy_m4_m4(omat, twmat); + orthogonalize_m4(omat, axis); glPushMatrix(); wmMultMatrix(omat); } @@ -728,8 +720,8 @@ static void preOrthoFront(int ortho, float twmat[][4], int axis) { if (ortho == 0) { float omat[4][4]; - Mat4CpyMat4(omat, twmat); - Mat4Orthogonal(omat, axis); + copy_m4_m4(omat, twmat); + orthogonalize_m4(omat, axis); glPushMatrix(); wmMultMatrix(omat); glFrontFace( is_mat4_flipped(omat)?GL_CW:GL_CCW); @@ -761,8 +753,8 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d glEnable(GL_BLEND); /* we need both [4][4] transforms, t->mat seems to be premul, not post for mat[][4] */ - Mat4CpyMat4(matt, rv3d->twmat); // to copy the parts outside of [3][3] -// XXX Mat4MulMat34(matt, t->mat, rv3d->twmat); + copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3] +// XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat); /* Screen aligned view rot circle */ if(drawflags & MAN_ROT_V) { @@ -774,7 +766,7 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d vec[0]= 0; // XXX (float)(t->con.imval[0] - t->center2d[0]); vec[1]= 0; // XXX (float)(t->con.imval[1] - t->center2d[1]); vec[2]= 0.0f; - Normalize(vec); + normalize_v3(vec); startphi= saacos( vec[1] ); if(vec[0]<0.0) startphi= -startphi; @@ -796,16 +788,16 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d svec[2]= 0.0f; /* screen aligned vec transform back to manipulator space */ - Mat3CpyMat4(ivmat, rv3d->viewinv); - Mat3CpyMat4(tmat, rv3d->twmat); - Mat3Inv(imat, tmat); - Mat3MulMat3(tmat, imat, ivmat); + copy_m3_m4(ivmat, rv3d->viewinv); + copy_m3_m4(tmat, rv3d->twmat); + invert_m3_m3(imat, tmat); + mul_m3_m3m3(tmat, imat, ivmat); - Mat3MulVecfl(tmat, svec); // tmat is used further on - Normalize(svec); + mul_m3_v3(tmat, svec); // tmat is used further on + normalize_v3(svec); } - ortho = IsMat4Orthogonal(rv3d->twmat); + ortho = is_orthogonal_m4(rv3d->twmat); if (ortho) { wmMultMatrix(rv3d->twmat); // aligns with original widget @@ -820,19 +812,19 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d /* correct for squeezed arc */ svec[0]+= tmat[2][0]; svec[1]+= tmat[2][1]; - Normalize(svec); + normalize_v3(svec); startphi= (float)atan2(svec[0], svec[1]); } else startphi= 0.5f*(float)M_PI; VECCOPY(vec, rv3d->twmat[0]); // use x axis to detect rotation - Normalize(vec); - Normalize(matt[0]); - phi= saacos( Inpf(vec, matt[0]) ); + normalize_v3(vec); + normalize_v3(matt[0]); + phi= saacos( dot_v3v3(vec, matt[0]) ); if(phi!=0.0) { - Crossf(cross, vec, matt[0]); // results in z vector - if(Inpf(cross, rv3d->twmat[2]) > 0.0) phi= -phi; + cross_v3_v3v3(cross, vec, matt[0]); // results in z vector + if(dot_v3v3(cross, rv3d->twmat[2]) > 0.0) phi= -phi; gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 180.0*startphi/M_PI, 180.0*(phi)/M_PI); } @@ -846,19 +838,19 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d /* correct for squeezed arc */ svec[1]+= tmat[2][1]; svec[2]+= tmat[2][2]; - Normalize(svec); + normalize_v3(svec); startphi= (float)(M_PI + atan2(svec[2], -svec[1])); } else startphi= 0.0f; VECCOPY(vec, rv3d->twmat[1]); // use y axis to detect rotation - Normalize(vec); - Normalize(matt[1]); - phi= saacos( Inpf(vec, matt[1]) ); + normalize_v3(vec); + normalize_v3(matt[1]); + phi= saacos( dot_v3v3(vec, matt[1]) ); if(phi!=0.0) { - Crossf(cross, vec, matt[1]); // results in x vector - if(Inpf(cross, rv3d->twmat[0]) > 0.0) phi= -phi; + cross_v3_v3v3(cross, vec, matt[1]); // results in x vector + if(dot_v3v3(cross, rv3d->twmat[0]) > 0.0) phi= -phi; glRotatef(90.0, 0.0, 1.0, 0.0); gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 180.0*startphi/M_PI, 180.0*phi/M_PI); glRotatef(-90.0, 0.0, 1.0, 0.0); @@ -874,19 +866,19 @@ static void draw_manipulator_rotate_ghost(View3D *v3d, RegionView3D *rv3d, int d /* correct for squeezed arc */ svec[0]+= tmat[2][0]; svec[2]+= tmat[2][2]; - Normalize(svec); + normalize_v3(svec); startphi= (float)(M_PI + atan2(-svec[0], svec[2])); } else startphi= (float)M_PI; VECCOPY(vec, rv3d->twmat[2]); // use z axis to detect rotation - Normalize(vec); - Normalize(matt[2]); - phi= saacos( Inpf(vec, matt[2]) ); + normalize_v3(vec); + normalize_v3(matt[2]); + phi= saacos( dot_v3v3(vec, matt[2]) ); if(phi!=0.0) { - Crossf(cross, vec, matt[2]); // results in y vector - if(Inpf(cross, rv3d->twmat[1]) > 0.0) phi= -phi; + cross_v3_v3v3(cross, vec, matt[2]); // results in y vector + if(dot_v3v3(cross, rv3d->twmat[1]) > 0.0) phi= -phi; glRotatef(-90.0, 1.0, 0.0, 0.0); gluPartialDisk(qobj, 0.0, 1.0, 32, 1, 180.0*startphi/M_PI, 180.0*phi/M_PI); glRotatef(90.0, 1.0, 0.0, 0.0); @@ -919,14 +911,14 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, /* Init stuff */ glDisable(GL_DEPTH_TEST); - Mat4One(unitmat); + unit_m4(unitmat); qobj= gluNewQuadric(); gluQuadricDrawStyle(qobj, GLU_FILL); /* prepare for screen aligned draw */ VECCOPY(vec, rv3d->twmat[0]); - size= Normalize(vec); + size= normalize_v3(vec); glPushMatrix(); glTranslatef(rv3d->twmat[3][0], rv3d->twmat[3][1], rv3d->twmat[3][2]); @@ -966,8 +958,8 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, vec[0]= 0; // XXX (float)(t->imval[0] - t->center2d[0]); vec[1]= 0; // XXX (float)(t->imval[1] - t->center2d[1]); vec[2]= 0.0f; - Normalize(vec); - VecMulf(vec, 1.2f*size); + normalize_v3(vec); + mul_v3_fl(vec, 1.2f*size); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3fv(vec); @@ -977,12 +969,12 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, glPopMatrix(); - ortho = IsMat4Orthogonal(rv3d->twmat); + ortho = is_orthogonal_m4(rv3d->twmat); /* apply the transform delta */ if(moving) { - Mat4CpyMat4(matt, rv3d->twmat); // to copy the parts outside of [3][3] - // XXX Mat4MulMat34(matt, t->mat, rv3d->twmat); + copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3] + // XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat); if (ortho) { wmMultMatrix(matt); glFrontFace( is_mat4_flipped(matt)?GL_CW:GL_CCW); @@ -1237,7 +1229,7 @@ static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, manipulator_setcolor(v3d, 'c', colcode); glPushMatrix(); size= screen_aligned(rv3d, rv3d->twmat); - Mat4One(unitmat); + unit_m4(unitmat); drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f*size, unitmat); glPopMatrix(); @@ -1248,8 +1240,8 @@ static void draw_manipulator_scale(View3D *v3d, RegionView3D *rv3d, int moving, if(moving) { float matt[4][4]; - Mat4CpyMat4(matt, rv3d->twmat); // to copy the parts outside of [3][3] - // XXX Mat4MulMat34(matt, t->mat, rv3d->twmat); + copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3] + // XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat); wmMultMatrix(matt); glFrontFace( is_mat4_flipped(matt)?GL_CW:GL_CCW); } @@ -1355,7 +1347,7 @@ static void draw_manipulator_translate(View3D *v3d, RegionView3D *rv3d, int movi manipulator_setcolor(v3d, 'c', colcode); glPushMatrix(); size= screen_aligned(rv3d, rv3d->twmat); - Mat4One(unitmat); + unit_m4(unitmat); drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f*size, unitmat); glPopMatrix(); @@ -1428,7 +1420,7 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov /* Screen aligned view rot circle */ if(drawflags & MAN_ROT_V) { float unitmat[4][4]; - Mat4One(unitmat); + unit_m4(unitmat); if(G.f & G_PICKSEL) glLoadName(MAN_ROT_V); UI_ThemeColor(TH_TRANSFORM); @@ -1439,8 +1431,8 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov vec[0]= 0; // XXX (float)(t->imval[0] - t->center2d[0]); vec[1]= 0; // XXX (float)(t->imval[1] - t->center2d[1]); vec[2]= 0.0f; - Normalize(vec); - VecMulf(vec, 1.2f*size); + normalize_v3(vec); + mul_v3_fl(vec, 1.2f*size); glBegin(GL_LINES); glVertex3f(0.0, 0.0, 0.0); glVertex3fv(vec); @@ -1452,9 +1444,9 @@ static void draw_manipulator_rotate_cyl(View3D *v3d, RegionView3D *rv3d, int mov /* apply the transform delta */ if(moving) { float matt[4][4]; - Mat4CpyMat4(matt, rv3d->twmat); // to copy the parts outside of [3][3] + copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3] // XXX if (t->flag & T_USES_MANIPULATOR) { - // XXX Mat4MulMat34(matt, t->mat, rv3d->twmat); + // XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat); // XXX } wmMultMatrix(matt); } @@ -1571,7 +1563,7 @@ void BIF_draw_manipulator(const bContext *C) break; } - Mat4MulFloat3((float *)rv3d->twmat, get_manipulator_drawsize(ar)); + mul_mat3_m4_fl(rv3d->twmat, get_manipulator_drawsize(ar)); } if(v3d->twflag & V3D_DRAW_MANIPULATOR) { @@ -1630,7 +1622,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, short *mval, float ho rect.ymax= mval[1]+hotspot; setwinmatrixview3d(ar, v3d, &rect); - Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); + mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); glSelectBuffer( 64, buffer); glRenderMode(GL_SELECT); @@ -1652,7 +1644,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, short *mval, float ho G.f &= ~G_PICKSEL; setwinmatrixview3d(ar, v3d, NULL); - Mat4MulMat4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); + mul_m4_m4m4(rv3d->persmat, rv3d->viewmat, rv3d->winmat); if(hits==1) return buffer[3]; else if(hits>1) { diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 207cf4b9aee..3cb6700d679 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -32,7 +32,7 @@ #include "RNA_define.h" #include "RNA_enum_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" #include "BKE_context.h" diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 0cb2515828d..463af961682 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -46,7 +46,7 @@ #include "BKE_context.h" #include "BKE_report.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" @@ -160,8 +160,8 @@ TransformOrientation *createObjectSpace(bContext *C, ReportList *reports, char * ob = base->object; - Mat3CpyMat4(mat, ob->obmat); - Mat3Ortho(mat); + copy_m3_m4(mat, ob->obmat); + normalize_m3(mat); /* use object name if no name is given */ if (name[0] == 0) @@ -246,20 +246,20 @@ int createSpaceNormal(float mat[3][3], float normal[3]) float tangent[3] = {0.0f, 0.0f, 1.0f}; VECCOPY(mat[2], normal); - if (Normalize(mat[2]) == 0.0f) { + if (normalize_v3(mat[2]) == 0.0f) { return 0; /* error return */ } - Crossf(mat[0], mat[2], tangent); - if (Inpf(mat[0], mat[0]) == 0.0f) { + cross_v3_v3v3(mat[0], mat[2], tangent); + if (dot_v3v3(mat[0], mat[0]) == 0.0f) { tangent[0] = 1.0f; tangent[1] = tangent[2] = 0.0f; - Crossf(mat[0], tangent, mat[2]); + cross_v3_v3v3(mat[0], tangent, mat[2]); } - Crossf(mat[1], mat[2], mat[0]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); - Mat3Ortho(mat); + normalize_m3(mat); return 1; } @@ -267,7 +267,7 @@ int createSpaceNormal(float mat[3][3], float normal[3]) int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]) { VECCOPY(mat[2], normal); - if (Normalize(mat[2]) == 0.0f) { + if (normalize_v3(mat[2]) == 0.0f) { return 0; /* error return */ } @@ -277,14 +277,14 @@ int createSpaceNormalTangent(float mat[3][3], float normal[3], float tangent[3]) tangent[2] = 1; } - Crossf(mat[0], mat[2], tangent); - if (Normalize(mat[0]) == 0.0f) { + cross_v3_v3v3(mat[0], mat[2], tangent); + if (normalize_v3(mat[0]) == 0.0f) { return 0; /* error return */ } - Crossf(mat[1], mat[2], mat[0]); + cross_v3_v3v3(mat[1], mat[2], mat[0]); - Mat3Ortho(mat); + normalize_m3(mat); return 1; } @@ -311,7 +311,7 @@ TransformOrientation* addMatrixSpace(bContext *C, float mat[3][3], char name[], } /* copy matrix into transform space */ - Mat3CpyMat3(ts->mat, mat); + copy_m3_m3(ts->mat, mat); return ts; } @@ -479,7 +479,7 @@ void applyTransformOrientation(const bContext *C, float mat[3][3], char *name) { if (name) strcpy(name, ts->name); - Mat3CpyMat3(mat, ts->mat); + copy_m3_m3(mat, ts->mat); break; } } @@ -522,7 +522,7 @@ void initTransformOrientation(bContext *C, TransInfo *t) break; case V3D_MANIP_GIMBAL: - Mat3One(t->spacemtx); + unit_m3(t->spacemtx); if(ob) gimbal_axis(ob, t->spacemtx); break; @@ -537,10 +537,10 @@ void initTransformOrientation(bContext *C, TransInfo *t) strcpy(t->spacename, "local"); if(ob) { - Mat3CpyMat4(t->spacemtx, ob->obmat); - Mat3Ortho(t->spacemtx); + copy_m3_m4(t->spacemtx, ob->obmat); + normalize_m3(t->spacemtx); } else { - Mat3One(t->spacemtx); + unit_m3(t->spacemtx); } break; @@ -552,13 +552,13 @@ void initTransformOrientation(bContext *C, TransInfo *t) float mat[3][3]; strcpy(t->spacename, "view"); - Mat3CpyMat4(mat, rv3d->viewinv); - Mat3Ortho(mat); - Mat3CpyMat3(t->spacemtx, mat); + copy_m3_m4(mat, rv3d->viewinv); + normalize_m3(mat); + copy_m3_m3(t->spacemtx, mat); } else { - Mat3One(t->spacemtx); + unit_m3(t->spacemtx); } break; default: /* V3D_MANIP_CUSTOM */ @@ -584,10 +584,10 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], float imat[3][3], mat[3][3]; /* we need the transpose of the inverse for a normal... */ - Mat3CpyMat4(imat, ob->obmat); + copy_m3_m4(imat, ob->obmat); - Mat3Inv(mat, imat); - Mat3Transp(mat); + invert_m3_m3(mat, imat); + transpose_m3(mat); ob= obedit; @@ -629,7 +629,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], if(efa->f & SELECT) { VECADD(normal, normal, efa->n); - VecSubf(vec, efa->v2->co, efa->v1->co); + sub_v3_v3v3(vec, efa->v2->co, efa->v1->co); VECADD(plane, plane, vec); } } @@ -653,9 +653,9 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], else { v3 = eve; - VecSubf(plane, v2->co, v1->co); - VecSubf(cotangent, v3->co, v2->co); - Crossf(normal, cotangent, plane); + sub_v3_v3v3(plane, v2->co, v1->co); + sub_v3_v3v3(cotangent, v3->co, v2->co); + cross_v3_v3v3(normal, cotangent, plane); break; } } @@ -668,7 +668,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], for(eed= em->edges.first; eed; eed= eed->next) { if(eed->f & SELECT) { - VecSubf(plane, eed->v2->co, eed->v1->co); + sub_v3_v3v3(plane, eed->v2->co, eed->v1->co); break; } } @@ -685,7 +685,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], /* use average vert normals as plane and edge vector as normal */ VECCOPY(plane, eed->v1->no); VECADD(plane, plane, eed->v2->no); - VecSubf(normal, eed->v2->co, eed->v1->co); + sub_v3_v3v3(normal, eed->v2->co, eed->v1->co); break; } } @@ -706,7 +706,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], VECCOPY(plane, v1->no); VECADD(plane, plane, v2->no); - VecSubf(normal, v2->co, v1->co); + sub_v3_v3v3(normal, v2->co, v1->co); break; } } @@ -731,10 +731,10 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], for (eve = em->verts.first; eve; eve = eve->next) { if ( eve->f & SELECT ) { - VecAddf(normal, normal, eve->no); + add_v3_v3v3(normal, normal, eve->no); } } - Normalize(normal); + normalize_v3(normal); result = ORIENTATION_VERT; } } @@ -758,21 +758,21 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], /* exception */ if ( (bezt->f1 & SELECT) + (bezt->f2 & SELECT) + (bezt->f3 & SELECT) > SELECT ) { - VecSubf(normal, bezt->vec[0], bezt->vec[2]); + sub_v3_v3v3(normal, bezt->vec[0], bezt->vec[2]); } else { if(bezt->f1) { - VecSubf(normal, bezt->vec[0], bezt->vec[1]); + sub_v3_v3v3(normal, bezt->vec[0], bezt->vec[1]); } if(bezt->f2) { - VecSubf(normal, bezt->vec[0], bezt->vec[2]); + sub_v3_v3v3(normal, bezt->vec[0], bezt->vec[2]); } if(bezt->f3) { - VecSubf(normal, bezt->vec[1], bezt->vec[2]); + sub_v3_v3v3(normal, bezt->vec[1], bezt->vec[2]); } } bezt++; @@ -813,12 +813,12 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], float mat[4][4]; /* Rotation of MetaElem is stored in quat */ - QuatToMat4(ml_sel->quat, mat); + quat_to_mat4( mat,ml_sel->quat); VECCOPY(normal, mat[2]); VECCOPY(plane, mat[1]); - VecMulf(plane, -1.0); + mul_v3_fl(plane, -1.0); result = ORIENTATION_NORMAL; } @@ -837,18 +837,18 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], { float mat[3][3]; float vec[3]; - VecSubf(vec, ebone->tail, ebone->head); - Normalize(vec); - VecAddf(normal, normal, vec); + sub_v3_v3v3(vec, ebone->tail, ebone->head); + normalize_v3(vec); + add_v3_v3v3(normal, normal, vec); vec_roll_to_mat3(vec, ebone->roll, mat); - VecAddf(plane, plane, mat[2]); + add_v3_v3v3(plane, plane, mat[2]); } } } - Normalize(normal); - Normalize(plane); + normalize_v3(normal); + normalize_v3(plane); if (plane[0] != 0 || plane[1] != 0 || plane[2] != 0) { @@ -860,13 +860,13 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], /* Vectors from edges don't need the special transpose inverse multiplication */ if (result == ORIENTATION_EDGE) { - Mat4Mul3Vecfl(ob->obmat, normal); - Mat4Mul3Vecfl(ob->obmat, plane); + mul_mat3_m4_v3(ob->obmat, normal); + mul_mat3_m4_v3(ob->obmat, plane); } else { - Mat3MulVecfl(mat, normal); - Mat3MulVecfl(mat, plane); + mul_m3_v3(mat, normal); + mul_m3_v3(mat, plane); } } else if(ob && (ob->mode & OB_MODE_POSE)) @@ -882,19 +882,19 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], /* use channels to get stats */ for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { if (pchan->bone && pchan->bone->flag & BONE_TRANSFORM) { - VecAddf(normal, normal, pchan->pose_mat[2]); - VecAddf(plane, plane, pchan->pose_mat[1]); + add_v3_v3v3(normal, normal, pchan->pose_mat[2]); + add_v3_v3v3(plane, plane, pchan->pose_mat[1]); } } - VecMulf(plane, -1.0); + mul_v3_fl(plane, -1.0); /* we need the transpose of the inverse for a normal... */ - Mat3CpyMat4(imat, ob->obmat); + copy_m3_m4(imat, ob->obmat); - Mat3Inv(mat, imat); - Mat3Transp(mat); - Mat3MulVecfl(mat, normal); - Mat3MulVecfl(mat, plane); + invert_m3_m3(mat, imat); + transpose_m3(mat); + mul_m3_v3(mat, normal); + mul_m3_v3(mat, plane); result = ORIENTATION_EDGE; } @@ -963,6 +963,6 @@ void ED_getTransformOrientationMatrix(const bContext *C, float orientation_mat[] if (type == ORIENTATION_NONE) { - Mat3One(orientation_mat); + unit_m3(orientation_mat); } } diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 1d26649fea2..062452d9e42 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -47,7 +47,7 @@ #include "RNA_access.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BLI_blenlib.h" @@ -145,8 +145,8 @@ void drawSnapping(const struct bContext *C, TransInfo *t) size *= 0.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); - Mat4CpyMat4(tmat, rv3d->viewmat); - Mat4Invert(imat, tmat); + copy_m4_m4(tmat, rv3d->viewmat); + invert_m4_m4(imat, tmat); drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, size, imat); @@ -229,7 +229,7 @@ void applyProject(TransInfo *t) if(t->flag & (T_EDIT|T_POSE)) { Object *ob = t->obedit?t->obedit:t->poseobj; - Mat4Invert(imat, ob->obmat); + invert_m4_m4(imat, ob->obmat); } for(i = 0 ; i < t->total; i++, td++) { @@ -247,7 +247,7 @@ void applyProject(TransInfo *t) if (t->flag & (T_EDIT|T_POSE)) { Object *ob = t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, iloc); + mul_m4_v3(ob->obmat, iloc); } else if (t->flag & T_OBJECT) { @@ -259,14 +259,14 @@ void applyProject(TransInfo *t) if (snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.mode)) { // if(t->flag & (T_EDIT|T_POSE)) { -// Mat4MulVecfl(imat, loc); +// mul_m4_v3(imat, loc); // } // - VecSubf(tvec, loc, iloc); + sub_v3_v3v3(tvec, loc, iloc); - Mat3MulVecfl(td->smtx, tvec); + mul_m3_v3(td->smtx, tvec); - VecAddf(td->loc, td->loc, tvec); + add_v3_v3v3(td->loc, td->loc, tvec); } //XXX constraintTransLim(t, td); @@ -331,7 +331,7 @@ int validSnappingNormal(TransInfo *t) { if ((t->tsnap.status & (POINT_INIT|TARGET_INIT)) == (POINT_INIT|TARGET_INIT)) { - if (Inpf(t->tsnap.snapNormal, t->tsnap.snapNormal) > 0) + if (dot_v3v3(t->tsnap.snapNormal, t->tsnap.snapNormal) > 0) { return 1; } @@ -365,7 +365,7 @@ void initSnapping(TransInfo *t, wmOperator *op) { t->tsnap.align = RNA_boolean_get(op->ptr, "snap_align"); RNA_float_get_array(op->ptr, "snap_normal", t->tsnap.snapNormal); - Normalize(t->tsnap.snapNormal); + normalize_v3(t->tsnap.snapNormal); } if (RNA_struct_find_property(op->ptr, "snap_project")) @@ -500,7 +500,7 @@ void setSnappingCallback(TransInfo *t, short snap_target) void ApplySnapTranslation(TransInfo *t, float vec[3]) { - VecSubf(vec, t->tsnap.snapPoint, t->tsnap.snapTarget); + sub_v3_v3v3(vec, t->tsnap.snapPoint, t->tsnap.snapTarget); } void ApplySnapRotation(TransInfo *t, float *vec) @@ -527,7 +527,7 @@ void ApplySnapResize(TransInfo *t, float vec[3]) float TranslationBetween(TransInfo *t, float p1[3], float p2[3]) { - return VecLenf(p1, p2); + return len_v3v3(p1, p2); } float RotationBetween(TransInfo *t, float p1[3], float p2[3]) @@ -537,11 +537,11 @@ float RotationBetween(TransInfo *t, float p1[3], float p2[3]) VECCOPY(center, t->center); if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, center); + mul_m4_v3(ob->obmat, center); } - VecSubf(start, p1, center); - VecSubf(end, p2, center); + sub_v3_v3v3(start, p1, center); + sub_v3_v3v3(end, p2, center); // Angle around a constraint axis (error prone, will need debug) if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) { @@ -549,29 +549,29 @@ float RotationBetween(TransInfo *t, float p1[3], float p2[3]) t->con.applyRot(t, NULL, axis, NULL); - Projf(tmp, end, axis); - VecSubf(end, end, tmp); + project_v3_v3v3(tmp, end, axis); + sub_v3_v3v3(end, end, tmp); - Projf(tmp, start, axis); - VecSubf(start, start, tmp); + project_v3_v3v3(tmp, start, axis); + sub_v3_v3v3(start, start, tmp); - Normalize(end); - Normalize(start); + normalize_v3(end); + normalize_v3(start); - Crossf(tmp, start, end); + cross_v3_v3v3(tmp, start, end); - if (Inpf(tmp, axis) < 0.0) - angle = -acos(Inpf(start, end)); + if (dot_v3v3(tmp, axis) < 0.0) + angle = -acos(dot_v3v3(start, end)); else - angle = acos(Inpf(start, end)); + angle = acos(dot_v3v3(start, end)); } else { float mtx[3][3]; - Mat3CpyMat4(mtx, t->viewmat); + copy_m3_m4(mtx, t->viewmat); - Mat3MulVecfl(mtx, end); - Mat3MulVecfl(mtx, start); + mul_m3_v3(mtx, end); + mul_m3_v3(mtx, start); angle = atan2(start[1],start[0]) - atan2(end[1],end[0]); } @@ -593,18 +593,18 @@ float ResizeBetween(TransInfo *t, float p1[3], float p2[3]) VECCOPY(center, t->center); if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, center); + mul_m4_v3(ob->obmat, center); } - VecSubf(d1, p1, center); - VecSubf(d2, p2, center); + sub_v3_v3v3(d1, p1, center); + sub_v3_v3v3(d2, p2, center); if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) { - Mat3MulVecfl(t->con.pmtx, d1); - Mat3MulVecfl(t->con.pmtx, d2); + mul_m3_v3(t->con.pmtx, d1); + mul_m3_v3(t->con.pmtx, d2); } - return VecLength(d2) / VecLength(d1); + return len_v3(d2) / len_v3(d1); } /********************** CALC **************************/ @@ -685,8 +685,8 @@ void CalcSnapGeometry(TransInfo *t, float *vec) { p2->flag = 1; - VecAddf(vec, p1->p, p2->p); - VecMulf(vec, 0.5f); + add_v3_v3v3(vec, p1->p, p2->p); + mul_v3_fl(vec, 0.5f); } else { @@ -700,7 +700,7 @@ void CalcSnapGeometry(TransInfo *t, float *vec) break; } - new_dist = VecLenf(last_p, vec); + new_dist = len_v3v3(last_p, vec); if (new_dist < dist) { @@ -727,10 +727,10 @@ void CalcSnapGeometry(TransInfo *t, float *vec) { float tangent[3]; - VecSubf(tangent, loc, t->tsnap.snapPoint); + sub_v3_v3v3(tangent, loc, t->tsnap.snapPoint); tangent[2] = 0; - if (Inpf(tangent, tangent) > 0) + if (dot_v3v3(tangent, tangent) > 0) { VECCOPY(t->tsnap.snapTangent, tangent); } @@ -759,7 +759,7 @@ void CalcSnapGeometry(TransInfo *t, float *vec) t->tsnap.snapPoint[0] *= aspx; t->tsnap.snapPoint[1] *= aspy; - Mat4MulVecfl(t->obedit->obmat, t->tsnap.snapPoint); + mul_m4_v3(t->obedit->obmat, t->tsnap.snapPoint); t->tsnap.status |= POINT_INIT; } @@ -780,7 +780,7 @@ void TargetSnapCenter(TransInfo *t) VECCOPY(t->tsnap.snapTarget, t->center); if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, t->tsnap.snapTarget); + mul_m4_v3(ob->obmat, t->tsnap.snapTarget); } t->tsnap.status |= TARGET_INIT; @@ -811,7 +811,7 @@ void TargetSnapActive(TransInfo *t) if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, t->tsnap.snapTarget); + mul_m4_v3(ob->obmat, t->tsnap.snapTarget); } t->tsnap.status |= TARGET_INIT; @@ -840,14 +840,14 @@ void TargetSnapMedian(TransInfo *t) for(td = t->data, i = 0 ; i < t->total && td->flag & TD_SELECTED ; i++, td++) { - VecAddf(t->tsnap.snapTarget, t->tsnap.snapTarget, td->center); + add_v3_v3v3(t->tsnap.snapTarget, t->tsnap.snapTarget, td->center); } - VecMulf(t->tsnap.snapTarget, 1.0 / i); + mul_v3_fl(t->tsnap.snapTarget, 1.0 / i); if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, t->tsnap.snapTarget); + mul_m4_v3(ob->obmat, t->tsnap.snapTarget); } t->tsnap.status |= TARGET_INIT; @@ -879,7 +879,7 @@ void TargetSnapClosest(TransInfo *t) float dist; VECCOPY(loc, bb->vec[j]); - Mat4MulVecfl(td->ext->obmat, loc); + mul_m4_v3(td->ext->obmat, loc); dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); @@ -922,7 +922,7 @@ void TargetSnapClosest(TransInfo *t) if(t->flag & (T_EDIT|T_POSE)) { Object *ob= t->obedit?t->obedit:t->poseobj; - Mat4MulVecfl(ob->obmat, loc); + mul_m4_v3(ob->obmat, loc); } dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); @@ -947,7 +947,7 @@ int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4 int result; int retval = 0; - result = RayIntersectsTriangleThreshold(ray_start_local, ray_normal_local, v1co, v2co, v3co, &lambda, NULL, 0.001); + result = isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, v1co, v2co, v3co, &lambda, NULL, 0.001); if (result) { float location[3], normal[3]; @@ -957,19 +957,19 @@ int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4 int new_dist; VECCOPY(intersect, ray_normal_local); - VecMulf(intersect, lambda); - VecAddf(intersect, intersect, ray_start_local); + mul_v3_fl(intersect, lambda); + add_v3_v3v3(intersect, intersect, ray_start_local); VECCOPY(location, intersect); if (v4co) - CalcNormFloat4(v1co, v2co, v3co, v4co, normal); + normal_quad_v3( normal,v1co, v2co, v3co, v4co); else - CalcNormFloat(v1co, v2co, v3co, normal); + normal_tri_v3( normal,v1co, v2co, v3co); - Mat4MulVecfl(obmat, location); + mul_m4_v3(obmat, location); - new_depth = VecLenf(location, ray_start); + new_depth = len_v3v3(location, ray_start); project_int(ar, location, screen_loc); new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]); @@ -982,8 +982,8 @@ int snapFace(ARegion *ar, float v1co[3], float v2co[3], float v3co[3], float *v4 VECCOPY(loc, location); VECCOPY(no, normal); - Mat3MulVecfl(timat, no); - Normalize(no); + mul_m3_v3(timat, no); + normalize_v3(no); *dist = new_dist; } @@ -999,10 +999,10 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n int retval = 0; VECCOPY(ray_end, ray_normal_local); - VecMulf(ray_end, 2000); - VecAddf(ray_end, ray_start_local, ray_end); + mul_v3_fl(ray_end, 2000); + add_v3_v3v3(ray_end, ray_start_local, ray_end); - result = LineIntersectLine(v1co, v2co, ray_start_local, ray_end, intersect, dvec); /* dvec used but we don't care about result */ + result = isect_line_line_v3(v1co, v2co, ray_start_local, ray_end, intersect, dvec); /* dvec used but we don't care about result */ if (result) { @@ -1010,12 +1010,12 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n float mul; /* check for behind ray_start */ - VecSubf(dvec, intersect, ray_start_local); + sub_v3_v3v3(dvec, intersect, ray_start_local); - VecSubf(edge_loc, v1co, v2co); - VecSubf(vec, intersect, v2co); + sub_v3_v3v3(edge_loc, v1co, v2co); + sub_v3_v3v3(vec, intersect, v2co); - mul = Inpf(vec, edge_loc) / Inpf(edge_loc, edge_loc); + mul = dot_v3v3(vec, edge_loc) / dot_v3v3(edge_loc, edge_loc); if (mul > 1) { mul = 1; @@ -1026,7 +1026,7 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n VECCOPY(intersect, v2co); } - if (Inpf(ray_normal_local, dvec) > 0) + if (dot_v3v3(ray_normal_local, dvec) > 0) { float location[3]; float new_depth; @@ -1035,9 +1035,9 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n VECCOPY(location, intersect); - Mat4MulVecfl(obmat, location); + mul_m4_v3(obmat, location); - new_depth = VecLenf(location, ray_start); + new_depth = len_v3v3(location, ray_start); project_int(ar, location, screen_loc); new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]); @@ -1053,18 +1053,18 @@ int snapEdge(ARegion *ar, float v1co[3], short v1no[3], float v2co[3], short v2n *depth = new_depth; retval = 1; - VecSubf(edge_loc, v1co, v2co); - VecSubf(vec, intersect, v2co); + sub_v3_v3v3(edge_loc, v1co, v2co); + sub_v3_v3v3(vec, intersect, v2co); - mul = Inpf(vec, edge_loc) / Inpf(edge_loc, edge_loc); + mul = dot_v3v3(vec, edge_loc) / dot_v3v3(edge_loc, edge_loc); if (no) { - NormalShortToFloat(n1, v1no); - NormalShortToFloat(n2, v2no); - VecLerpf(no, n2, n1, mul); - Mat3MulVecfl(timat, no); - Normalize(no); + normal_short_to_float_v3(n1, v1no); + normal_short_to_float_v3(n2, v2no); + interp_v3_v3v3(no, n2, n1, mul); + mul_m3_v3(timat, no); + normalize_v3(no); } VECCOPY(loc, location); @@ -1082,9 +1082,9 @@ int snapVertex(ARegion *ar, float vco[3], short vno[3], float mval[2], float ray int retval = 0; float dvec[3]; - VecSubf(dvec, vco, ray_start_local); + sub_v3_v3v3(dvec, vco, ray_start_local); - if (Inpf(ray_normal_local, dvec) > 0) + if (dot_v3v3(ray_normal_local, dvec) > 0) { float location[3]; float new_depth; @@ -1093,9 +1093,9 @@ int snapVertex(ARegion *ar, float vco[3], short vno[3], float mval[2], float ray VECCOPY(location, vco); - Mat4MulVecfl(obmat, location); + mul_m4_v3(obmat, location); - new_depth = VecLenf(location, ray_start); + new_depth = len_v3v3(location, ray_start); project_int(ar, location, screen_loc); new_dist = abs(screen_loc[0] - (int)mval[0]) + abs(screen_loc[1] - (int)mval[1]); @@ -1109,9 +1109,9 @@ int snapVertex(ARegion *ar, float vco[3], short vno[3], float mval[2], float ray if (no) { - NormalShortToFloat(no, vno); - Mat3MulVecfl(timat, no); - Normalize(no); + normal_short_to_float_v3(no, vno); + mul_m3_v3(timat, no); + normalize_v3(no); } *dist = new_dist; @@ -1127,13 +1127,13 @@ int snapArmature(short snap_mode, ARegion *ar, Object *ob, bArmature *arm, float float ray_start_local[3], ray_normal_local[3]; int retval = 0; - Mat4Invert(imat, obmat); + invert_m4_m4(imat, obmat); VECCOPY(ray_start_local, ray_start); VECCOPY(ray_normal_local, ray_normal); - Mat4MulVecfl(imat, ray_start_local); - Mat4Mul3Vecfl(imat, ray_normal_local); + mul_m4_v3(imat, ray_start_local); + mul_mat3_m4_v3(imat, ray_normal_local); if(arm->edbo) { @@ -1198,16 +1198,16 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E float ray_start_local[3], ray_normal_local[3]; int test = 1; - Mat4Invert(imat, obmat); + invert_m4_m4(imat, obmat); - Mat3CpyMat4(timat, imat); - Mat3Transp(timat); + copy_m3_m4(timat, imat); + transpose_m3(timat); VECCOPY(ray_start_local, ray_start); VECCOPY(ray_normal_local, ray_normal); - Mat4MulVecfl(imat, ray_start_local); - Mat4Mul3Vecfl(imat, ray_normal_local); + mul_m4_v3(imat, ray_start_local); + mul_mat3_m4_v3(imat, ray_normal_local); /* If number of vert is more than an arbitrary limit, @@ -1224,6 +1224,35 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E { case SCE_SNAP_MODE_FACE: { +#if 1 // Added for durian + BVHTreeRayHit hit; + BVHTreeFromMesh treeData; + + bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6); + + hit.index = -1; + hit.dist = *depth; + + if(treeData.tree && BLI_bvhtree_ray_cast(treeData.tree, ray_start_local, ray_normal_local, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) + { + if(hit.dist<=*depth) { + *depth= hit.dist; + copy_v3_v3(loc, hit.co); + copy_v3_v3(no, hit.no); + + /* back to worldspace */ + mul_m4_v3(obmat, loc); + copy_v3_v3(no, hit.no); + + mul_m3_v3(timat, no); + normalize_v3(no); + + retval |= 1; + } + } + break; + +#else MVert *verts = dm->getVertArray(dm); MFace *faces = dm->getFaceArray(dm); int *index_array = NULL; @@ -1293,6 +1322,7 @@ int snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMesh *dm, E { EM_free_index_arrays(); } +#endif break; } case SCE_SNAP_MODE_VERTEX: @@ -1587,16 +1617,16 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta float ray_start_local[3], ray_normal_local[3]; int test = 1; - Mat4Invert(imat, obmat); + invert_m4_m4(imat, obmat); - Mat3CpyMat4(timat, imat); - Mat3Transp(timat); + copy_m3_m4(timat, imat); + transpose_m3(timat); VECCOPY(ray_start_local, ray_start); VECCOPY(ray_normal_local, ray_normal); - Mat4MulVecfl(imat, ray_start_local); - Mat4Mul3Vecfl(imat, ray_normal_local); + mul_m4_v3(imat, ray_start_local); + mul_mat3_m4_v3(imat, ray_normal_local); /* If number of vert is more than an arbitrary limit, @@ -1618,7 +1648,7 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta int result; - result = RayIntersectsTriangleThreshold(ray_start_local, ray_normal_local, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, &lambda, NULL, 0.001); + result = isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, &lambda, NULL, 0.001); if (result) { float location[3], normal[3]; @@ -1626,29 +1656,29 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta float new_depth; VECCOPY(intersect, ray_normal_local); - VecMulf(intersect, lambda); - VecAddf(intersect, intersect, ray_start_local); + mul_v3_fl(intersect, lambda); + add_v3_v3v3(intersect, intersect, ray_start_local); VECCOPY(location, intersect); if (f->v4) - CalcNormFloat4(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co, normal); + normal_quad_v3( normal,verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co); else - CalcNormFloat(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, normal); + normal_tri_v3( normal,verts[f->v1].co, verts[f->v2].co, verts[f->v3].co); - Mat4MulVecfl(obmat, location); + mul_m4_v3(obmat, location); - new_depth = VecLenf(location, ray_start); + new_depth = len_v3v3(location, ray_start); - Mat3MulVecfl(timat, normal); - Normalize(normal); + mul_m3_v3(timat, normal); + normalize_v3(normal); addDepthPeel(depth_peels, new_depth, location, normal, ob); } if (f->v4 && result == 0) { - result = RayIntersectsTriangleThreshold(ray_start_local, ray_normal_local, verts[f->v3].co, verts[f->v4].co, verts[f->v1].co, &lambda, NULL, 0.001); + result = isect_ray_tri_threshold_v3(ray_start_local, ray_normal_local, verts[f->v3].co, verts[f->v4].co, verts[f->v1].co, &lambda, NULL, 0.001); if (result) { float location[3], normal[3]; @@ -1656,22 +1686,22 @@ int peelDerivedMesh(Object *ob, DerivedMesh *dm, float obmat[][4], float ray_sta float new_depth; VECCOPY(intersect, ray_normal_local); - VecMulf(intersect, lambda); - VecAddf(intersect, intersect, ray_start_local); + mul_v3_fl(intersect, lambda); + add_v3_v3v3(intersect, intersect, ray_start_local); VECCOPY(location, intersect); if (f->v4) - CalcNormFloat4(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co, normal); + normal_quad_v3( normal,verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, verts[f->v4].co); else - CalcNormFloat(verts[f->v1].co, verts[f->v2].co, verts[f->v3].co, normal); + normal_tri_v3( normal,verts[f->v1].co, verts[f->v2].co, verts[f->v3].co); - Mat4MulVecfl(obmat, location); + mul_m4_v3(obmat, location); - new_depth = VecLenf(location, ray_start); + new_depth = len_v3v3(location, ray_start); - Mat3MulVecfl(timat, normal); - Normalize(normal); + mul_m3_v3(timat, normal); + normalize_v3(normal); addDepthPeel(depth_peels, new_depth, location, normal, ob); } diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index fbd12007c16..c5dccc14b03 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -42,7 +42,7 @@ #include "BKE_object.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_editVert.h" #include "BIF_gl.h" @@ -251,44 +251,44 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFac if(efa->v4) { #if 0 /* Simple but slow, better reuse normalized vectors */ - uvang1 = RAD2DEG(Vec2Angle3(tf_uv[3], tf_uv[0], tf_uv[1])); - ang1 = RAD2DEG(VecAngle3(efa->v4->co, efa->v1->co, efa->v2->co)); + uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[3], tf_uv[0], tf_uv[1])); + ang1 = RAD2DEG(angle_v3v3v3(efa->v4->co, efa->v1->co, efa->v2->co)); - uvang2 = RAD2DEG(Vec2Angle3(tf_uv[0], tf_uv[1], tf_uv[2])); - ang2 = RAD2DEG(VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co)); + uvang2 = RAD2DEG(angle_v2v2v2(tf_uv[0], tf_uv[1], tf_uv[2])); + ang2 = RAD2DEG(angle_v3v3v3(efa->v1->co, efa->v2->co, efa->v3->co)); - uvang3 = RAD2DEG(Vec2Angle3(tf_uv[1], tf_uv[2], tf_uv[3])); - ang3 = RAD2DEG(VecAngle3(efa->v2->co, efa->v3->co, efa->v4->co)); + uvang3 = RAD2DEG(angle_v2v2v2(tf_uv[1], tf_uv[2], tf_uv[3])); + ang3 = RAD2DEG(angle_v3v3v3(efa->v2->co, efa->v3->co, efa->v4->co)); - uvang4 = RAD2DEG(Vec2Angle3(tf_uv[2], tf_uv[3], tf_uv[0])); - ang4 = RAD2DEG(VecAngle3(efa->v3->co, efa->v4->co, efa->v1->co)); + uvang4 = RAD2DEG(angle_v2v2v2(tf_uv[2], tf_uv[3], tf_uv[0])); + ang4 = RAD2DEG(angle_v3v3v3(efa->v3->co, efa->v4->co, efa->v1->co)); #endif /* uv angles */ - VECSUB2D(av1, tf_uv[3], tf_uv[0]); Normalize2(av1); - VECSUB2D(av2, tf_uv[0], tf_uv[1]); Normalize2(av2); - VECSUB2D(av3, tf_uv[1], tf_uv[2]); Normalize2(av3); - VECSUB2D(av4, tf_uv[2], tf_uv[3]); Normalize2(av4); + VECSUB2D(av1, tf_uv[3], tf_uv[0]); normalize_v2(av1); + VECSUB2D(av2, tf_uv[0], tf_uv[1]); normalize_v2(av2); + VECSUB2D(av3, tf_uv[1], tf_uv[2]); normalize_v2(av3); + VECSUB2D(av4, tf_uv[2], tf_uv[3]); normalize_v2(av4); /* This is the correct angle however we are only comparing angles - * uvang1 = 90-((NormalizedVecAngle2_2D(av1, av2) * 180.0/M_PI)-90);*/ - uvang1 = NormalizedVecAngle2_2D(av1, av2)*180.0/M_PI; - uvang2 = NormalizedVecAngle2_2D(av2, av3)*180.0/M_PI; - uvang3 = NormalizedVecAngle2_2D(av3, av4)*180.0/M_PI; - uvang4 = NormalizedVecAngle2_2D(av4, av1)*180.0/M_PI; + * uvang1 = 90-((angle_normalized_v2v2(av1, av2) * 180.0/M_PI)-90);*/ + uvang1 = angle_normalized_v2v2(av1, av2)*180.0/M_PI; + uvang2 = angle_normalized_v2v2(av2, av3)*180.0/M_PI; + uvang3 = angle_normalized_v2v2(av3, av4)*180.0/M_PI; + uvang4 = angle_normalized_v2v2(av4, av1)*180.0/M_PI; /* 3d angles */ - VECSUB(av1, efa->v4->co, efa->v1->co); Normalize(av1); - VECSUB(av2, efa->v1->co, efa->v2->co); Normalize(av2); - VECSUB(av3, efa->v2->co, efa->v3->co); Normalize(av3); - VECSUB(av4, efa->v3->co, efa->v4->co); Normalize(av4); + VECSUB(av1, efa->v4->co, efa->v1->co); normalize_v3(av1); + VECSUB(av2, efa->v1->co, efa->v2->co); normalize_v3(av2); + VECSUB(av3, efa->v2->co, efa->v3->co); normalize_v3(av3); + VECSUB(av4, efa->v3->co, efa->v4->co); normalize_v3(av4); /* This is the correct angle however we are only comparing angles - * ang1 = 90-((NormalizedVecAngle2(av1, av2) * 180.0/M_PI)-90);*/ - ang1 = NormalizedVecAngle2(av1, av2)*180.0/M_PI; - ang2 = NormalizedVecAngle2(av2, av3)*180.0/M_PI; - ang3 = NormalizedVecAngle2(av3, av4)*180.0/M_PI; - ang4 = NormalizedVecAngle2(av4, av1)*180.0/M_PI; + * ang1 = 90-((angle_normalized_v3v3(av1, av2) * 180.0/M_PI)-90);*/ + ang1 = angle_normalized_v3v3(av1, av2)*180.0/M_PI; + ang2 = angle_normalized_v3v3(av2, av3)*180.0/M_PI; + ang3 = angle_normalized_v3v3(av3, av4)*180.0/M_PI; + ang4 = angle_normalized_v3v3(av4, av1)*180.0/M_PI; glBegin(GL_QUADS); @@ -315,36 +315,36 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFac } else { #if 0 /* Simple but slow, better reuse normalized vectors */ - uvang1 = RAD2DEG(Vec2Angle3(tf_uv[2], tf_uv[0], tf_uv[1])); - ang1 = RAD2DEG(VecAngle3(efa->v3->co, efa->v1->co, efa->v2->co)); + uvang1 = RAD2DEG(angle_v2v2v2(tf_uv[2], tf_uv[0], tf_uv[1])); + ang1 = RAD2DEG(angle_v3v3v3(efa->v3->co, efa->v1->co, efa->v2->co)); - uvang2 = RAD2DEG(Vec2Angle3(tf_uv[0], tf_uv[1], tf_uv[2])); - ang2 = RAD2DEG(VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co)); + uvang2 = RAD2DEG(angle_v2v2v2(tf_uv[0], tf_uv[1], tf_uv[2])); + ang2 = RAD2DEG(angle_v3v3v3(efa->v1->co, efa->v2->co, efa->v3->co)); uvang3 = M_PI-(uvang1+uvang2); ang3 = M_PI-(ang1+ang2); #endif /* uv angles */ - VECSUB2D(av1, tf_uv[2], tf_uv[0]); Normalize2(av1); - VECSUB2D(av2, tf_uv[0], tf_uv[1]); Normalize2(av2); - VECSUB2D(av3, tf_uv[1], tf_uv[2]); Normalize2(av3); + VECSUB2D(av1, tf_uv[2], tf_uv[0]); normalize_v2(av1); + VECSUB2D(av2, tf_uv[0], tf_uv[1]); normalize_v2(av2); + VECSUB2D(av3, tf_uv[1], tf_uv[2]); normalize_v2(av3); /* This is the correct angle however we are only comparing angles - * uvang1 = 90-((NormalizedVecAngle2_2D(av1, av2) * 180.0/M_PI)-90); */ - uvang1 = NormalizedVecAngle2_2D(av1, av2)*180.0/M_PI; - uvang2 = NormalizedVecAngle2_2D(av2, av3)*180.0/M_PI; - uvang3 = NormalizedVecAngle2_2D(av3, av1)*180.0/M_PI; + * uvang1 = 90-((angle_normalized_v2v2(av1, av2) * 180.0/M_PI)-90); */ + uvang1 = angle_normalized_v2v2(av1, av2)*180.0/M_PI; + uvang2 = angle_normalized_v2v2(av2, av3)*180.0/M_PI; + uvang3 = angle_normalized_v2v2(av3, av1)*180.0/M_PI; /* 3d angles */ - VECSUB(av1, efa->v3->co, efa->v1->co); Normalize(av1); - VECSUB(av2, efa->v1->co, efa->v2->co); Normalize(av2); - VECSUB(av3, efa->v2->co, efa->v3->co); Normalize(av3); + VECSUB(av1, efa->v3->co, efa->v1->co); normalize_v3(av1); + VECSUB(av2, efa->v1->co, efa->v2->co); normalize_v3(av2); + VECSUB(av3, efa->v2->co, efa->v3->co); normalize_v3(av3); /* This is the correct angle however we are only comparing angles - * ang1 = 90-((NormalizedVecAngle2(av1, av2) * 180.0/M_PI)-90); */ - ang1 = NormalizedVecAngle2(av1, av2)*180.0/M_PI; - ang2 = NormalizedVecAngle2(av2, av3)*180.0/M_PI; - ang3 = NormalizedVecAngle2(av3, av1)*180.0/M_PI; + * ang1 = 90-((angle_normalized_v3v3(av1, av2) * 180.0/M_PI)-90); */ + ang1 = angle_normalized_v3v3(av1, av2)*180.0/M_PI; + ang2 = angle_normalized_v3v3(av2, av3)*180.0/M_PI; + ang3 = angle_normalized_v3v3(av3, av1)*180.0/M_PI; /* This simple makes the angles display worse then they really are ;) * 1.0-pow((1.0-a), 2) */ diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index f9a849798be..0e5e283d109 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -41,7 +41,7 @@ #include "DNA_screen_types.h" #include "DNA_windowmanager_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" @@ -359,9 +359,9 @@ void uv_center(float uv[][2], float cent[2], int quad) float uv_area(float uv[][2], int quad) { if(quad) - return AreaF2Dfl(uv[0], uv[1], uv[2]) + AreaF2Dfl(uv[0], uv[2], uv[3]); + return area_tri_v2(uv[0], uv[1], uv[2]) + area_tri_v2(uv[0], uv[2], uv[3]); else - return AreaF2Dfl(uv[0], uv[1], uv[2]); + return area_tri_v2(uv[0], uv[1], uv[2]); } void uv_copy_aspect(float uv_orig[][2], float uv[][2], float aspx, float aspy) @@ -473,7 +473,7 @@ static void find_nearest_uv_edge(Scene *scene, Image *ima, EditMesh *em, float c nverts= efa->v4? 4: 3; for(i=0; i<nverts; i++) { - dist= PdistVL2Dfl(co, tf->uv[i], tf->uv[(i+1)%nverts]); + dist= dist_to_line_segment_v2(co, tf->uv[i], tf->uv[(i+1)%nverts]); if(dist < mindist) { hit->tf= tf; @@ -534,8 +534,8 @@ static int nearest_uv_between(MTFace *tf, int nverts, int id, float co[2], float m[0]= co[0]-uv[0]; m[1]= co[1]-uv[1]; - Vec2Subf(v1, tf->uv[id1], tf->uv[id]); - Vec2Subf(v2, tf->uv[id2], tf->uv[id]); + sub_v2_v2v2(v1, tf->uv[id1], tf->uv[id]); + sub_v2_v2v2(v2, tf->uv[id2], tf->uv[id]); /* m and v2 on same side of v-v1? */ c1= v1[0]*m[1] - v1[1]*m[0]; diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 20f74085e52..85ccef5cd7d 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -2,7 +2,7 @@ #include "MEM_guardedalloc.h" #include "BLI_memarena.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BLI_heap.h" #include "BLI_boxpack2d.h" @@ -333,8 +333,8 @@ static float p_vec_angle_cos(float *v1, float *v2, float *v3) d2[1] = v3[1] - v2[1]; d2[2] = v3[2] - v2[2]; - Normalize(d1); - Normalize(d2); + normalize_v3(d1); + normalize_v3(d2); return d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2]; } @@ -382,7 +382,7 @@ static float p_face_area(PFace *f) PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; PVert *v1 = e1->vert, *v2 = e2->vert, *v3 = e3->vert; - return AreaT3Dfl(v1->co, v2->co, v3->co); + return area_tri_v3(v1->co, v2->co, v3->co); } static float p_area_signed(float *v1, float *v2, float *v3) @@ -1099,7 +1099,7 @@ static PFace *p_face_add_fill(PChart *chart, PVert *v1, PVert *v2, PVert *v3) static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys) { - float fac= VecLenf(co[0], co[2]) - VecLenf(co[1], co[3]); + float fac= len_v3v3(co[0], co[2]) - len_v3v3(co[1], co[3]); PBool dir = (fac <= 0.0f); /* the face exists check is there because of a special case: when @@ -1414,16 +1414,16 @@ static float p_vert_cotan(float *v1, float *v2, float *v3) { float a[3], b[3], c[3], clen; - VecSubf(a, v2, v1); - VecSubf(b, v3, v1); - Crossf(c, a, b); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v3, v1); + cross_v3_v3v3(c, a, b); - clen = VecLength(c); + clen = len_v3(c); if (clen == 0.0f) return 0.0f; - return Inpf(a, b)/clen; + return dot_v3v3(a, b)/clen; } static PBool p_vert_flipped_wheel_triangle(PVert *v) @@ -1752,15 +1752,15 @@ static PBool p_collapse_normal_flipped(float *v1, float *v2, float *vold, float { float nold[3], nnew[3], sub1[3], sub2[3]; - VecSubf(sub1, vold, v1); - VecSubf(sub2, vold, v2); - Crossf(nold, sub1, sub2); + sub_v3_v3v3(sub1, vold, v1); + sub_v3_v3v3(sub2, vold, v2); + cross_v3_v3v3(nold, sub1, sub2); - VecSubf(sub1, vnew, v1); - VecSubf(sub2, vnew, v2); - Crossf(nnew, sub1, sub2); + sub_v3_v3v3(sub1, vnew, v1); + sub_v3_v3v3(sub2, vnew, v2); + cross_v3_v3v3(nnew, sub1, sub2); - return (Inpf(nold, nnew) <= 0.0f); + return (dot_v3v3(nold, nnew) <= 0.0f); } static PBool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair) @@ -1866,7 +1866,7 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) oldf1 = (edge)? edge->face: NULL; oldf2 = (pair)? pair->face: NULL; - VecSubf(edgevec, keepv->co, oldv->co); + sub_v3_v3v3(edgevec, keepv->co, oldv->co); e = oldv->edge; do { @@ -1878,16 +1878,16 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) float tetrav2[3], tetrav3[3], c[3]; /* tetrahedron volume = (1/3!)*|a.(b x c)| */ - VecSubf(tetrav2, co1, oldv->co); - VecSubf(tetrav3, co2, oldv->co); - Crossf(c, tetrav2, tetrav3); + sub_v3_v3v3(tetrav2, co1, oldv->co); + sub_v3_v3v3(tetrav3, co2, oldv->co); + cross_v3_v3v3(c, tetrav2, tetrav3); - volumecost += fabs(Inpf(edgevec, c)/6.0f); + volumecost += fabs(dot_v3v3(edgevec, c)/6.0f); #if 0 - shapecost += Inpf(co1, keepv->co); + shapecost += dot_v3v3(co1, keepv->co); if (p_wheel_edge_next(e) == NULL) - shapecost += Inpf(co2, keepv->co); + shapecost += dot_v3v3(co2, keepv->co); #endif p_triangle_angles(oldv->co, co1, co2, &a1, &a2, &a3); @@ -1915,10 +1915,10 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) PVert *v1 = p_boundary_edge_prev(oldv->edge)->vert; PVert *v2 = p_boundary_edge_next(oldv->edge)->vert; - areacost = AreaT3Dfl(oldv->co, v1->co, v2->co); + areacost = area_tri_v3(oldv->co, v1->co, v2->co); } - elen = VecLength(edgevec); + elen = len_v3(edgevec); weight = 1.0f; /* 0.2f */ cost = weight*volumecost*volumecost + elen*elen*areacost*areacost; #if 0 @@ -2750,7 +2750,7 @@ static void p_chart_pin_positions(PChart *chart, PVert **pin1, PVert **pin2) int diru, dirv, dirx, diry; float sub[3]; - VecSubf(sub, (*pin1)->co, (*pin2)->co); + sub_v3_v3v3(sub, (*pin1)->co, (*pin2)->co); sub[0] = fabs(sub[0]); sub[1] = fabs(sub[1]); sub[2] = fabs(sub[2]); @@ -3185,35 +3185,35 @@ static float p_face_stretch(PFace *f) w= 1.0f/(2.0f*area); /* compute derivatives */ - VecCopyf(Ps, v1->co); - VecMulf(Ps, (v2->uv[1] - v3->uv[1])); + copy_v3_v3(Ps, v1->co); + mul_v3_fl(Ps, (v2->uv[1] - v3->uv[1])); - VecCopyf(tmp, v2->co); - VecMulf(tmp, (v3->uv[1] - v1->uv[1])); - VecAddf(Ps, Ps, tmp); + copy_v3_v3(tmp, v2->co); + mul_v3_fl(tmp, (v3->uv[1] - v1->uv[1])); + add_v3_v3v3(Ps, Ps, tmp); - VecCopyf(tmp, v3->co); - VecMulf(tmp, (v1->uv[1] - v2->uv[1])); - VecAddf(Ps, Ps, tmp); + copy_v3_v3(tmp, v3->co); + mul_v3_fl(tmp, (v1->uv[1] - v2->uv[1])); + add_v3_v3v3(Ps, Ps, tmp); - VecMulf(Ps, w); + mul_v3_fl(Ps, w); - VecCopyf(Pt, v1->co); - VecMulf(Pt, (v3->uv[0] - v2->uv[0])); + copy_v3_v3(Pt, v1->co); + mul_v3_fl(Pt, (v3->uv[0] - v2->uv[0])); - VecCopyf(tmp, v2->co); - VecMulf(tmp, (v1->uv[0] - v3->uv[0])); - VecAddf(Pt, Pt, tmp); + copy_v3_v3(tmp, v2->co); + mul_v3_fl(tmp, (v1->uv[0] - v3->uv[0])); + add_v3_v3v3(Pt, Pt, tmp); - VecCopyf(tmp, v3->co); - VecMulf(tmp, (v2->uv[0] - v1->uv[0])); - VecAddf(Pt, Pt, tmp); + copy_v3_v3(tmp, v3->co); + mul_v3_fl(tmp, (v2->uv[0] - v1->uv[0])); + add_v3_v3v3(Pt, Pt, tmp); - VecMulf(Pt, w); + mul_v3_fl(Pt, w); /* Sander Tensor */ - a= Inpf(Ps, Ps); - c= Inpf(Pt, Pt); + a= dot_v3v3(Ps, Ps); + c= dot_v3v3(Pt, Pt); T = sqrt(0.5f*(a + c)); if (f->flag & PFACE_FILLED) @@ -3273,7 +3273,7 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) low = 0; stretch_low = orig_stretch; - Vec2Addf(v->uv, orig_uv, dir); + add_v2_v2v2(v->uv, orig_uv, dir); high = 1; stretch = stretch_high = p_stretch_compute_vertex(v); @@ -3296,7 +3296,7 @@ static void p_chart_stretch_minimize(PChart *chart, RNG *rng) /* no luck, stretch has increased, reset to old values */ if(stretch >= orig_stretch) - Vec2Copyf(v->uv, orig_uv); + copy_v2_v2(v->uv, orig_uv); } } @@ -3404,7 +3404,7 @@ static float p_rectangle_area(float *p1, float *dir, float *p2, float *p3, float if (!p_intersect_line_2d_dir(p3, dir, p4, orthodir, corner3)) return 1e10; - return Vec2Lenf(corner1, corner2)*Vec2Lenf(corner2, corner3); + return len_v2v2(corner1, corner2)*len_v2v2(corner2, corner3); } static float p_chart_minimum_area_angle(PChart *chart) @@ -3499,7 +3499,7 @@ static float p_chart_minimum_area_angle(PChart *chart) p3 = points[idx[(mini+2)%4]]; p4 = points[idx[(mini+3)%4]]; - len = Vec2Lenf(p1->uv, p1n->uv); + len = len_v2v2(p1->uv, p1n->uv); if (len > 0.0f) { len = 1.0/len; diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 29d9bb4864e..e5881415100 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -48,7 +48,7 @@ #include "BKE_mesh.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_edgehash.h" #include "BLI_editVert.h" @@ -563,7 +563,7 @@ static void uv_map_transform_center(Scene *scene, View3D *v3d, float *result, Ob if(efa->v4) DO_MINMAX(efa->v4->co, min, max); } } - VecMidf(result, min, max); + mid_v3_v3v3(result, min, max); break; case V3D_CURSOR: /*cursor center*/ @@ -590,23 +590,23 @@ static void uv_map_rotation_matrix(float result[][4], RegionView3D *rv3d, Object /* get rotation of the current view matrix */ if(rv3d) - Mat4CpyMat4(viewmatrix, rv3d->viewmat); + copy_m4_m4(viewmatrix, rv3d->viewmat); else - Mat4One(viewmatrix); + unit_m4(viewmatrix); /* but shifting */ for(k=0; k<4; k++) viewmatrix[3][k] =0.0f; /* get rotation of the current object matrix */ - Mat4CpyMat4(rotobj,ob->obmat); + copy_m4_m4(rotobj,ob->obmat); /* but shifting */ for(k=0; k<4; k++) rotobj[3][k] =0.0f; - Mat4Clr(*rotup); - Mat4Clr(*rotside); + zero_m4(rotup); + zero_m4(rotside); /* compensate front/side.. against opengl x,y,z world definition */ /* this is "kanonen gegen spatzen", a few plus minus 1 will do here */ @@ -626,7 +626,7 @@ static void uv_map_rotation_matrix(float result[][4], RegionView3D *rv3d, Object rotup[0][0]= (float)1.0f/radius; /* calculate transforms*/ - Mat4MulSerie(result, rotup, rotside, viewmatrix, rotobj, NULL, NULL, NULL, NULL); + mul_serie_m4(result, rotup, rotside, viewmatrix, rotobj, NULL, NULL, NULL, NULL); } static void uv_map_transform(bContext *C, wmOperator *op, float center[3], float rotmat[4][4]) @@ -657,7 +657,7 @@ static void uv_map_transform(bContext *C, wmOperator *op, float center[3], float /* be compatible to the "old" sphere/cylinder mode */ if(direction == ALIGN_TO_OBJECT) - Mat4One(rotmat); + unit_m4(rotmat); else uv_map_rotation_matrix(rotmat, rv3d, obedit, upangledeg, sideangledeg, radius); @@ -873,7 +873,7 @@ static void uv_from_view_bounds(float target[2], float source[3], float rotmat[4 { float pv[3]; - Mat4MulVecfl(rotmat, pv); + mul_m4_v3(rotmat, pv); /* ortho projection */ target[0] = -pv[0]; @@ -885,19 +885,19 @@ static void uv_from_view(ARegion *ar, float target[2], float source[3], float ro RegionView3D *rv3d= ar->regiondata; float pv[3], pv4[4], dx, dy, x= 0.0, y= 0.0; - Mat4MulVecfl(rotmat, pv); + mul_m4_v3(rotmat, pv); dx= ar->winx; dy= ar->winy; - VecCopyf(pv4, source); + copy_v3_v3(pv4, source); pv4[3]= 1.0; /* rotmat is the object matrix in this case */ - Mat4MulVec4fl(rotmat, pv4); + mul_m4_v4(rotmat, pv4); /* almost project_short */ - Mat4MulVec4fl(rv3d->persmat, pv4); + mul_m4_v4(rv3d->persmat, pv4); if(fabs(pv4[3]) > 0.00001) { /* avoid division by zero */ target[0] = dx/2.0 + (dx/2.0)*pv4[0]/pv4[3]; target[1] = dy/2.0 + (dy/2.0)*pv4[1]/pv4[3]; @@ -954,7 +954,7 @@ static int from_view_exec(bContext *C, wmOperator *op) } } else { - Mat4CpyMat4(rotmat, obedit->obmat); + copy_m4_m4(rotmat, obedit->obmat); for(efa= em->faces.first; efa; efa= efa->next) { if(efa->f & SELECT) { @@ -1063,10 +1063,10 @@ static void uv_sphere_project(float target[2], float source[3], float center[3], { float pv[3]; - VecSubf(pv, source, center); - Mat4MulVecfl(rotmat, pv); + sub_v3_v3v3(pv, source, center); + mul_m4_v3(rotmat, pv); - spheremap(pv[0], pv[1], pv[2], &target[0], &target[1]); + map_to_sphere( &target[0], &target[1],pv[0], pv[1], pv[2]); /* split line is always zero */ if(target[0] >= 1.0f) @@ -1155,10 +1155,10 @@ static void uv_cylinder_project(float target[2], float source[3], float center[3 { float pv[3]; - VecSubf(pv, source, center); - Mat4MulVecfl(rotmat, pv); + sub_v3_v3v3(pv, source, center); + mul_m4_v3(rotmat, pv); - tubemap(pv[0], pv[1], pv[2], &target[0], &target[1]); + map_to_tube( &target[0], &target[1],pv[0], pv[1], pv[2]); /* split line is always zero */ if(target[0] >= 1.0f) @@ -1248,7 +1248,7 @@ static int cube_project_exec(bContext *C, wmOperator *op) for(efa= em->faces.first; efa; efa= efa->next) { if(efa->f & SELECT) { tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, no); + normal_tri_v3( no,efa->v1->co, efa->v2->co, efa->v3->co); no[0]= fabs(no[0]); no[1]= fabs(no[1]); diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 9e164f46e4c..a59c263055d 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_meshdata_types.h" @@ -545,9 +545,9 @@ void GPU_buffer_copy_normal( DerivedMesh *dm, float *varray, int *index, int *re VECCOPY(&varray[start+6],&nors[i*3]); } if( mface[i].v4 ) - CalcNormFloat4(mvert[mface[i].v1].co, mvert[mface[i].v2].co, mvert[mface[i].v3].co, mvert[mface[i].v4].co, norm); + normal_quad_v3( norm,mvert[mface[i].v1].co, mvert[mface[i].v2].co, mvert[mface[i].v3].co, mvert[mface[i].v4].co); else - CalcNormFloat(mvert[mface[i].v1].co, mvert[mface[i].v2].co, mvert[mface[i].v3].co, norm); + normal_tri_v3( norm,mvert[mface[i].v1].co, mvert[mface[i].v2].co, mvert[mface[i].v3].co); VECCOPY(&varray[start],norm); VECCOPY(&varray[start+3],norm); VECCOPY(&varray[start+6],norm); diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 0650a0bfa19..3da83d557a3 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -54,7 +54,7 @@ #include "BKE_texture.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "GPU_extensions.h" @@ -290,7 +290,7 @@ void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float v GPU_shader_uniform_vector(shader, material->obmatloc, 16, 1, (float*)obmat); } if(material->builtins & GPU_INVERSE_OBJECT_MATRIX) { - Mat4Invert(invmat, obmat); + invert_m4_m4(invmat, obmat); GPU_shader_uniform_vector(shader, material->invobmatloc, 16, 1, (float*)invmat); } if(material->builtins & GPU_OBCOLOR) { @@ -305,20 +305,20 @@ void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float v if(material->dynproperty & DYN_LAMP_VEC) { VECCOPY(lamp->dynvec, lamp->vec); - Normalize(lamp->dynvec); - VecNegf(lamp->dynvec); - Mat4Mul3Vecfl(viewmat, lamp->dynvec); + normalize_v3(lamp->dynvec); + negate_v3(lamp->dynvec); + mul_mat3_m4_v3(viewmat, lamp->dynvec); } if(material->dynproperty & DYN_LAMP_CO) { VECCOPY(lamp->dynco, lamp->co); - Mat4MulVecfl(viewmat, lamp->dynco); + mul_m4_v3(viewmat, lamp->dynco); } if(material->dynproperty & DYN_LAMP_IMAT) - Mat4MulMat4(lamp->dynimat, viewinv, lamp->imat); + mul_m4_m4m4(lamp->dynimat, viewinv, lamp->imat); if(material->dynproperty & DYN_LAMP_PERSMAT) - Mat4MulMat4(lamp->dynpersmat, viewinv, lamp->persmat); + mul_m4_m4m4(lamp->dynpersmat, viewinv, lamp->persmat); } GPU_pass_update_uniforms(material->pass); @@ -782,7 +782,7 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr) Object *ob = dob->ob; if(ob->type==OB_LAMP) { - Mat4CpyMat4(ob->obmat, dob->mat); + copy_m4_m4(ob->obmat, dob->mat); lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, base->object); if(lamp) @@ -1318,13 +1318,13 @@ void GPU_lamp_update(GPULamp *lamp, int lay, float obmat[][4]) lamp->lay = lay; - Mat4CpyMat4(mat, obmat); - Mat4Ortho(mat); + copy_m4_m4(mat, obmat); + normalize_m4(mat); VECCOPY(lamp->vec, mat[2]); VECCOPY(lamp->co, mat[3]); - Mat4CpyMat4(lamp->obmat, mat); - Mat4Invert(lamp->imat, mat); + copy_m4_m4(lamp->obmat, mat); + invert_m4_m4(lamp->imat, mat); } void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy) @@ -1388,7 +1388,7 @@ static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *l pixsize= (lamp->d)/temp; wsize= pixsize*0.5f*lamp->size; - i_window(-wsize, wsize, -wsize, wsize, lamp->d, lamp->clipend, lamp->winmat); + perspective_m4( lamp->winmat,-wsize, wsize, -wsize, wsize, lamp->d, lamp->clipend); } static void gpu_lamp_shadow_free(GPULamp *lamp) @@ -1489,16 +1489,16 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize float rangemat[4][4], persmat[4][4]; /* initshadowbuf */ - Mat4Invert(lamp->viewmat, lamp->obmat); - Normalize(lamp->viewmat[0]); - Normalize(lamp->viewmat[1]); - Normalize(lamp->viewmat[2]); + invert_m4_m4(lamp->viewmat, lamp->obmat); + normalize_v3(lamp->viewmat[0]); + normalize_v3(lamp->viewmat[1]); + normalize_v3(lamp->viewmat[2]); /* makeshadowbuf */ - Mat4MulMat4(persmat, lamp->viewmat, lamp->winmat); + mul_m4_m4m4(persmat, lamp->viewmat, lamp->winmat); /* opengl depth buffer is range 0.0..1.0 instead of -1.0..1.0 in blender */ - Mat4One(rangemat); + unit_m4(rangemat); rangemat[0][0] = 0.5f; rangemat[1][1] = 0.5f; rangemat[2][2] = 0.5f; @@ -1506,15 +1506,15 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize rangemat[3][1] = 0.5f; rangemat[3][2] = 0.5f; - Mat4MulMat4(lamp->persmat, persmat, rangemat); + mul_m4_m4m4(lamp->persmat, persmat, rangemat); /* opengl */ glDisable(GL_SCISSOR_TEST); GPU_framebuffer_texture_bind(lamp->fb, lamp->tex); /* set matrices */ - Mat4CpyMat4(viewmat, lamp->viewmat); - Mat4CpyMat4(winmat, lamp->winmat); + copy_m4_m4(viewmat, lamp->viewmat); + copy_m4_m4(winmat, lamp->winmat); *winsize = lamp->size; } diff --git a/source/blender/gpu/intern/gpu_shader_material.glsl b/source/blender/gpu/intern/gpu_shader_material.glsl index e59be0217b5..c824e755afc 100644 --- a/source/blender/gpu/intern/gpu_shader_material.glsl +++ b/source/blender/gpu/intern/gpu_shader_material.glsl @@ -276,18 +276,26 @@ void normal(vec3 dir, vec3 nor, out vec3 outnor, out float outdot) outdot = -dot(dir, nor); } -void curves_vec(vec3 vec, sampler1D curvemap, out vec3 outvec) +void curves_vec(float fac, vec3 vec, sampler1D curvemap, out vec3 outvec) { outvec.x = texture1D(curvemap, (vec.x + 1.0)*0.5).x; outvec.y = texture1D(curvemap, (vec.y + 1.0)*0.5).y; outvec.z = texture1D(curvemap, (vec.z + 1.0)*0.5).z; + + if (fac != 1.0) + outvec = (outvec*fac) + (vec*(1.0-fac)); + } -void curves_rgb(vec4 col, sampler1D curvemap, out vec4 outcol) +void curves_rgb(float fac, vec4 col, sampler1D curvemap, out vec4 outcol) { outcol.r = texture1D(curvemap, texture1D(curvemap, col.r).a).r; outcol.g = texture1D(curvemap, texture1D(curvemap, col.g).a).g; outcol.b = texture1D(curvemap, texture1D(curvemap, col.b).a).b; + + if (fac != 1.0) + outcol = (outcol*fac) + (col*(1.0-fac)); + outcol.a = col.a; } diff --git a/source/blender/gpu/intern/gpu_shader_material.glsl.c b/source/blender/gpu/intern/gpu_shader_material.glsl.c index d61491ad57a..920cd16c369 100644 --- a/source/blender/gpu/intern/gpu_shader_material.glsl.c +++ b/source/blender/gpu/intern/gpu_shader_material.glsl.c @@ -1,187 +1,192 @@ /* DataToC output of file <gpu_shader_material_glsl> */ -int datatoc_gpu_shader_material_glsl_size= 33385; +int datatoc_gpu_shader_material_glsl_size= 33537; char datatoc_gpu_shader_material_glsl[]= { - 10,102,108,111, 97,116, 32,101,120, -112, 95, 98,108,101,110,100,101,114, 40,102,108,111, 97,116, 32,102, 41, 10,123, 10, 9,114,101,116,117,114,110, 32,112,111,119, - 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 50, 56, 52, 54, 44, 32,102, 41, 59, 10,125, 10, 10,118,111,105,100, 32,114,103, 98, 95, -116,111, 95,104,115,118, 40,118,101, 99, 52, 32,114,103, 98, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, - 41, 10,123, 10, 9,102,108,111, 97,116, 32, 99,109, 97,120, 44, 32, 99,109,105,110, 44, 32,104, 44, 32,115, 44, 32,118, 44, 32, - 99,100,101,108,116, 97, 59, 10, 9,118,101, 99, 51, 32, 99, 59, 10, 10, 9, 99,109, 97,120, 32, 61, 32,109, 97,120, 40,114,103, - 98, 91, 48, 93, 44, 32,109, 97,120, 40,114,103, 98, 91, 49, 93, 44, 32,114,103, 98, 91, 50, 93, 41, 41, 59, 10, 9, 99,109,105, -110, 32, 61, 32,109,105,110, 40,114,103, 98, 91, 48, 93, 44, 32,109,105,110, 40,114,103, 98, 91, 49, 93, 44, 32,114,103, 98, 91, - 50, 93, 41, 41, 59, 10, 9, 99,100,101,108,116, 97, 32, 61, 32, 99,109, 97,120, 45, 99,109,105,110, 59, 10, 10, 9,118, 32, 61, - 32, 99,109, 97,120, 59, 10, 9,105,102, 32, 40, 99,109, 97,120, 33, 61, 48, 46, 48, 41, 10, 9, 9,115, 32, 61, 32, 99,100,101, -108,116, 97, 47, 99,109, 97,120, 59, 10, 9,101,108,115,101, 32,123, 10, 9, 9,115, 32, 61, 32, 48, 46, 48, 59, 10, 9, 9,104, - 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 10, 9,105,102, 32, 40,115, 32, 61, 61, 32, 48, 46, 48, 41, 32,123, 10, 9, 9,104, - 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 9,101,108,115,101, 32,123, 10, 9, 9, 99, 32, 61, 32, 40,118,101, 99, 51, 40, 99, -109, 97,120, 44, 32, 99,109, 97,120, 44, 32, 99,109, 97,120, 41, 32, 45, 32,114,103, 98, 46,120,121,122, 41, 47, 99,100,101,108, -116, 97, 59, 10, 10, 9, 9,105,102, 32, 40,114,103, 98, 46,120, 61, 61, 99,109, 97,120, 41, 32,104, 32, 61, 32, 99, 91, 50, 93, - 32, 45, 32, 99, 91, 49, 93, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,114,103, 98, 46,121, 61, 61, 99,109, 97,120, 41, - 32,104, 32, 61, 32, 50, 46, 48, 32, 43, 32, 99, 91, 48, 93, 32, 45, 32, 32, 99, 91, 50, 93, 59, 10, 9, 9,101,108,115,101, 32, -104, 32, 61, 32, 52, 46, 48, 32, 43, 32, 99, 91, 49, 93, 32, 45, 32, 99, 91, 48, 93, 59, 10, 10, 9, 9,104, 32, 47, 61, 32, 54, - 46, 48, 59, 10, 10, 9, 9,105,102, 32, 40,104, 60, 48, 46, 48, 41, 10, 9, 9, 9,104, 32, 43, 61, 32, 49, 46, 48, 59, 10, 9, -125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, 99, 52, 40,104, 44, 32,115, 44, 32,118, 44, 32,114,103, 98, 46,119, - 41, 59, 10,125, 10, 10,118,111,105,100, 32,104,115,118, 95,116,111, 95,114,103, 98, 40,118,101, 99, 52, 32,104,115,118, 44, 32, -111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, 41, 10,123, 10, 9,102,108,111, 97,116, 32,105, 44, 32,102, 44, 32, -112, 44, 32,113, 44, 32,116, 44, 32,104, 44, 32,115, 44, 32,118, 59, 10, 9,118,101, 99, 51, 32,114,103, 98, 59, 10, 10, 9,104, - 32, 61, 32,104,115,118, 91, 48, 93, 59, 10, 9,115, 32, 61, 32,104,115,118, 91, 49, 93, 59, 10, 9,118, 32, 61, 32,104,115,118, - 91, 50, 93, 59, 10, 10, 9,105,102, 40,115, 61, 61, 48, 46, 48, 41, 32,123, 10, 9, 9,114,103, 98, 32, 61, 32,118,101, 99, 51, - 40,118, 44, 32,118, 44, 32,118, 41, 59, 10, 9,125, 10, 9,101,108,115,101, 32,123, 10, 9, 9,105,102, 40,104, 61, 61, 49, 46, - 48, 41, 10, 9, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9, 9, 10, 9, 9,104, 32, 42, 61, 32, 54, 46, 48, 59, 10, 9, 9, -105, 32, 61, 32,102,108,111,111,114, 40,104, 41, 59, 10, 9, 9,102, 32, 61, 32,104, 32, 45, 32,105, 59, 10, 9, 9,114,103, 98, - 32, 61, 32,118,101, 99, 51, 40,102, 44, 32,102, 44, 32,102, 41, 59, 10, 9, 9,112, 32, 61, 32,118, 42, 40, 49, 46, 48, 45,115, - 41, 59, 10, 9, 9,113, 32, 61, 32,118, 42, 40, 49, 46, 48, 45, 40,115, 42,102, 41, 41, 59, 10, 9, 9,116, 32, 61, 32,118, 42, - 40, 49, 46, 48, 45, 40,115, 42, 40, 49, 46, 48, 45,102, 41, 41, 41, 59, 10, 9, 9, 10, 9, 9,105,102, 32, 40,105, 32, 61, 61, - 32, 48, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,118, 44, 32,116, 44, 32,112, 41, 59, 10, 9, 9,101,108,115, -101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 49, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,113, 44, 32,118, 44, - 32,112, 41, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 50, 46, 48, 41, 32,114,103, 98, 32, 61, 32, -118,101, 99, 51, 40,112, 44, 32,118, 44, 32,116, 41, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 51, - 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,112, 44, 32,113, 44, 32,118, 41, 59, 10, 9, 9,101,108,115,101, 32, -105,102, 32, 40,105, 32, 61, 61, 32, 52, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,116, 44, 32,112, 44, 32,118, - 41, 59, 10, 9, 9,101,108,115,101, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,118, 44, 32,112, 44, 32,113, 41, 59, 10, 9, -125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, 99, 52, 40,114,103, 98, 44, 32,104,115,118, 46,119, 41, 59, 10,125, - 10, 10, 35,100,101,102,105,110,101, 32, 77, 95, 80, 73, 32, 51, 46, 49, 52, 49, 53, 57, 50, 54, 53, 51, 53, 56, 57, 55, 57, 51, - 50, 51, 56, 52, 54, 10, 10, 47, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 32, 83, 72, 65, 68, 69, 82, 32, 78, 79, 68, 69, 83, - 32, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 47, 10, 10,118,111,105,100, 32,118, 99,111,108, 95, 97,116,116, -114,105, 98,117,116,101, 40,118,101, 99, 52, 32, 97,116,116,118, 99,111,108, 44, 32,111,117,116, 32,118,101, 99, 52, 32,118, 99, -111,108, 41, 10,123, 10, 9,118, 99,111,108, 32, 61, 32,118,101, 99, 52, 40, 97,116,116,118, 99,111,108, 46,120, 47, 50, 53, 53, - 46, 48, 44, 32, 97,116,116,118, 99,111,108, 46,121, 47, 50, 53, 53, 46, 48, 44, 32, 97,116,116,118, 99,111,108, 46,122, 47, 50, - 53, 53, 46, 48, 44, 32, 49, 46, 48, 41, 59, 10,125, 10, 10,118,111,105,100, 32,117,118, 95, 97,116,116,114,105, 98,117,116,101, - 40,118,101, 99, 50, 32, 97,116,116,117,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32,117,118, 41, 10,123, 10, 9,117,118, 32, - 61, 32,118,101, 99, 51, 40, 97,116,116,117,118, 42, 50, 46, 48, 32, 45, 32,118,101, 99, 50, 40, 49, 46, 48, 44, 32, 49, 46, 48, - 41, 44, 32, 48, 46, 48, 41, 59, 10,125, 10, 10,118,111,105,100, 32,103,101,111,109, 40,118,101, 99, 51, 32, 99,111, 44, 32,118, -101, 99, 51, 32,110,111,114, 44, 32,109, 97,116, 52, 32,118,105,101,119,105,110,118,109, 97,116, 44, 32,118,101, 99, 51, 32, 97, -116,116,111,114, 99,111, 44, 32,118,101, 99, 50, 32, 97,116,116,117,118, 44, 32,118,101, 99, 52, 32, 97,116,116,118, 99,111,108, - 44, 32,111,117,116, 32,118,101, 99, 51, 32,103,108,111, 98, 97,108, 44, 32,111,117,116, 32,118,101, 99, 51, 32,108,111, 99, 97, -108, 44, 32,111,117,116, 32,118,101, 99, 51, 32,118,105,101,119, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,114, 99,111, 44, - 32,111,117,116, 32,118,101, 99, 51, 32,117,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32,110,111,114,109, 97,108, 44, 32,111, -117,116, 32,118,101, 99, 52, 32,118, 99,111,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,102,114,111,110,116, 98, 97, 99, -107, 41, 10,123, 10, 9,108,111, 99, 97,108, 32, 61, 32, 99,111, 59, 10, 9,118,105,101,119, 32, 61, 32,110,111,114,109, 97,108, -105,122,101, 40,108,111, 99, 97,108, 41, 59, 10, 9,103,108,111, 98, 97,108, 32, 61, 32, 40,118,105,101,119,105,110,118,109, 97, -116, 42,118,101, 99, 52, 40,108,111, 99, 97,108, 44, 32, 49, 46, 48, 41, 41, 46,120,121,122, 59, 10, 9,111,114, 99,111, 32, 61, - 32, 97,116,116,111,114, 99,111, 59, 10, 9,117,118, 95, 97,116,116,114,105, 98,117,116,101, 40, 97,116,116,117,118, 44, 32,117, -118, 41, 59, 10, 9,110,111,114,109, 97,108, 32, 61, 32, 45,110,111,114,109, 97,108,105,122,101, 40,110,111,114, 41, 59, 9, 47, - 42, 32, 98,108,101,110,100,101,114, 32,114,101,110,100,101,114, 32,110,111,114,109, 97,108, 32,105,115, 32,110,101,103, 97,116, -101,100, 32, 42, 47, 10, 9,118, 99,111,108, 95, 97,116,116,114,105, 98,117,116,101, 40, 97,116,116,118, 99,111,108, 44, 32,118, - 99,111,108, 41, 59, 10, 9,102,114,111,110,116, 98, 97, 99,107, 32, 61, 32, 49, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32, -109, 97,112,112,105,110,103, 40,118,101, 99, 51, 32,118,101, 99, 44, 32,109, 97,116, 52, 32,109, 97,116, 44, 32,118,101, 99, 51, - 32,109,105,110,118,101, 99, 44, 32,118,101, 99, 51, 32,109, 97,120,118,101, 99, 44, 32,102,108,111, 97,116, 32,100,111,109,105, -110, 44, 32,102,108,111, 97,116, 32,100,111,109, 97,120, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 41, - 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32, 40,109, 97,116, 32, 42, 32,118,101, 99, 52, 40,118,101, 99, 44, 32, 49, 46, - 48, 41, 41, 46,120,121,122, 59, 10, 9,105,102, 40,100,111,109,105,110, 32, 61, 61, 32, 49, 46, 48, 41, 10, 9, 9,111,117,116, -118,101, 99, 32, 61, 32,109, 97,120, 40,111,117,116,118,101, 99, 44, 32,109,105,110,118,101, 99, 41, 59, 10, 9,105,102, 40,100, -111,109, 97,120, 32, 61, 61, 32, 49, 46, 48, 41, 10, 9, 9,111,117,116,118,101, 99, 32, 61, 32,109,105,110, 40,111,117,116,118, -101, 99, 44, 32,109, 97,120,118,101, 99, 41, 59, 10,125, 10, 10,118,111,105,100, 32, 99, 97,109,101,114, 97, 40,118,101, 99, 51, - 32, 99,111, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,105,101,119, 44, 32,111,117,116, 32,102,108,111, 97,116, - 32,111,117,116,100,101,112,116,104, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,100,105,115,116, 41, 10,123, 10, - 9,111,117,116,100,101,112,116,104, 32, 61, 32, 97, 98,115, 40, 99,111, 46,122, 41, 59, 10, 9,111,117,116,100,105,115,116, 32, - 61, 32,108,101,110,103,116,104, 40, 99,111, 41, 59, 10, 9,111,117,116,118,105,101,119, 32, 61, 32,110,111,114,109, 97,108,105, -122,101, 40, 99,111, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97,100,100, 40,102,108,111, 97,116, 32,118, - 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97, -108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,118, 97,108, 49, 32, 43, 32,118, 97,108, 50, 59, 10,125, 10, 10,118, -111,105,100, 32,109, 97,116,104, 95,115,117, 98,116,114, 97, 99,116, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108, -111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111, -117,116,118, 97,108, 32, 61, 32,118, 97,108, 49, 32, 45, 32,118, 97,108, 50, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116, -104, 95,109,117,108,116,105,112,108,121, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, - 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, - 32,118, 97,108, 49, 32, 42, 32,118, 97,108, 50, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,100,105,118,105,100, -101, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108, -111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40,118, 97,108, 50, 32, 61, 61, 32, 48, 46, 48, 41, 10, - 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, - 32,118, 97,108, 49, 32, 47, 32,118, 97,108, 50, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,115,105,110,101, 40, -102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9, -111,117,116,118, 97,108, 32, 61, 32,115,105,110, 40,118, 97,108, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, - 99,111,115,105,110,101, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, - 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 99,111,115, 40,118, 97,108, 41, 59, 10,125, 10, 10,118,111,105, -100, 32,109, 97,116,104, 95,116, 97,110,103,101,110,116, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108, -111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,116, 97,110, 40,118, 97,108, 41, - 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97,115,105,110, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111, -117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40,118, 97,108, 32, 60, 61, 32, 49, - 46, 48, 32, 38, 38, 32,118, 97,108, 32, 62, 61, 32, 45, 49, 46, 48, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 97,115, -105,110, 40,118, 97,108, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, - 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97, 99,111,115, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32, -102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40,118, 97,108, 32, 60, 61, 32, 49, 46, 48, 32, - 38, 38, 32,118, 97,108, 32, 62, 61, 32, 45, 49, 46, 48, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 97, 99,111,115, 40, -118, 97,108, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118, -111,105,100, 32,109, 97,116,104, 95, 97,116, 97,110, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, - 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 97,116, 97,110, 40,118, 97,108, 41, - 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,112,111,119, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102, + 10, +102,108,111, 97,116, 32,101,120,112, 95, 98,108,101,110,100,101,114, 40,102,108,111, 97,116, 32,102, 41, 10,123, 10, 9,114,101, +116,117,114,110, 32,112,111,119, 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 50, 56, 52, 54, 44, 32,102, 41, 59, 10,125, 10, 10,118, +111,105,100, 32,114,103, 98, 95,116,111, 95,104,115,118, 40,118,101, 99, 52, 32,114,103, 98, 44, 32,111,117,116, 32,118,101, 99, + 52, 32,111,117,116, 99,111,108, 41, 10,123, 10, 9,102,108,111, 97,116, 32, 99,109, 97,120, 44, 32, 99,109,105,110, 44, 32,104, + 44, 32,115, 44, 32,118, 44, 32, 99,100,101,108,116, 97, 59, 10, 9,118,101, 99, 51, 32, 99, 59, 10, 10, 9, 99,109, 97,120, 32, + 61, 32,109, 97,120, 40,114,103, 98, 91, 48, 93, 44, 32,109, 97,120, 40,114,103, 98, 91, 49, 93, 44, 32,114,103, 98, 91, 50, 93, + 41, 41, 59, 10, 9, 99,109,105,110, 32, 61, 32,109,105,110, 40,114,103, 98, 91, 48, 93, 44, 32,109,105,110, 40,114,103, 98, 91, + 49, 93, 44, 32,114,103, 98, 91, 50, 93, 41, 41, 59, 10, 9, 99,100,101,108,116, 97, 32, 61, 32, 99,109, 97,120, 45, 99,109,105, +110, 59, 10, 10, 9,118, 32, 61, 32, 99,109, 97,120, 59, 10, 9,105,102, 32, 40, 99,109, 97,120, 33, 61, 48, 46, 48, 41, 10, 9, + 9,115, 32, 61, 32, 99,100,101,108,116, 97, 47, 99,109, 97,120, 59, 10, 9,101,108,115,101, 32,123, 10, 9, 9,115, 32, 61, 32, + 48, 46, 48, 59, 10, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 10, 9,105,102, 32, 40,115, 32, 61, 61, 32, 48, 46, + 48, 41, 32,123, 10, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9,125, 10, 9,101,108,115,101, 32,123, 10, 9, 9, 99, 32, 61, + 32, 40,118,101, 99, 51, 40, 99,109, 97,120, 44, 32, 99,109, 97,120, 44, 32, 99,109, 97,120, 41, 32, 45, 32,114,103, 98, 46,120, +121,122, 41, 47, 99,100,101,108,116, 97, 59, 10, 10, 9, 9,105,102, 32, 40,114,103, 98, 46,120, 61, 61, 99,109, 97,120, 41, 32, +104, 32, 61, 32, 99, 91, 50, 93, 32, 45, 32, 99, 91, 49, 93, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,114,103, 98, 46, +121, 61, 61, 99,109, 97,120, 41, 32,104, 32, 61, 32, 50, 46, 48, 32, 43, 32, 99, 91, 48, 93, 32, 45, 32, 32, 99, 91, 50, 93, 59, + 10, 9, 9,101,108,115,101, 32,104, 32, 61, 32, 52, 46, 48, 32, 43, 32, 99, 91, 49, 93, 32, 45, 32, 99, 91, 48, 93, 59, 10, 10, + 9, 9,104, 32, 47, 61, 32, 54, 46, 48, 59, 10, 10, 9, 9,105,102, 32, 40,104, 60, 48, 46, 48, 41, 10, 9, 9, 9,104, 32, 43, + 61, 32, 49, 46, 48, 59, 10, 9,125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, 99, 52, 40,104, 44, 32,115, 44, 32, +118, 44, 32,114,103, 98, 46,119, 41, 59, 10,125, 10, 10,118,111,105,100, 32,104,115,118, 95,116,111, 95,114,103, 98, 40,118,101, + 99, 52, 32,104,115,118, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, 41, 10,123, 10, 9,102,108,111, 97, +116, 32,105, 44, 32,102, 44, 32,112, 44, 32,113, 44, 32,116, 44, 32,104, 44, 32,115, 44, 32,118, 59, 10, 9,118,101, 99, 51, 32, +114,103, 98, 59, 10, 10, 9,104, 32, 61, 32,104,115,118, 91, 48, 93, 59, 10, 9,115, 32, 61, 32,104,115,118, 91, 49, 93, 59, 10, + 9,118, 32, 61, 32,104,115,118, 91, 50, 93, 59, 10, 10, 9,105,102, 40,115, 61, 61, 48, 46, 48, 41, 32,123, 10, 9, 9,114,103, + 98, 32, 61, 32,118,101, 99, 51, 40,118, 44, 32,118, 44, 32,118, 41, 59, 10, 9,125, 10, 9,101,108,115,101, 32,123, 10, 9, 9, +105,102, 40,104, 61, 61, 49, 46, 48, 41, 10, 9, 9, 9,104, 32, 61, 32, 48, 46, 48, 59, 10, 9, 9, 10, 9, 9,104, 32, 42, 61, + 32, 54, 46, 48, 59, 10, 9, 9,105, 32, 61, 32,102,108,111,111,114, 40,104, 41, 59, 10, 9, 9,102, 32, 61, 32,104, 32, 45, 32, +105, 59, 10, 9, 9,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,102, 44, 32,102, 44, 32,102, 41, 59, 10, 9, 9,112, 32, 61, 32, +118, 42, 40, 49, 46, 48, 45,115, 41, 59, 10, 9, 9,113, 32, 61, 32,118, 42, 40, 49, 46, 48, 45, 40,115, 42,102, 41, 41, 59, 10, + 9, 9,116, 32, 61, 32,118, 42, 40, 49, 46, 48, 45, 40,115, 42, 40, 49, 46, 48, 45,102, 41, 41, 41, 59, 10, 9, 9, 10, 9, 9, +105,102, 32, 40,105, 32, 61, 61, 32, 48, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,118, 44, 32,116, 44, 32,112, + 41, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 49, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, + 99, 51, 40,113, 44, 32,118, 44, 32,112, 41, 59, 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 50, 46, 48, + 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,112, 44, 32,118, 44, 32,116, 41, 59, 10, 9, 9,101,108,115,101, 32,105,102, + 32, 40,105, 32, 61, 61, 32, 51, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,112, 44, 32,113, 44, 32,118, 41, 59, + 10, 9, 9,101,108,115,101, 32,105,102, 32, 40,105, 32, 61, 61, 32, 52, 46, 48, 41, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, + 40,116, 44, 32,112, 44, 32,118, 41, 59, 10, 9, 9,101,108,115,101, 32,114,103, 98, 32, 61, 32,118,101, 99, 51, 40,118, 44, 32, +112, 44, 32,113, 41, 59, 10, 9,125, 10, 10, 9,111,117,116, 99,111,108, 32, 61, 32,118,101, 99, 52, 40,114,103, 98, 44, 32,104, +115,118, 46,119, 41, 59, 10,125, 10, 10, 35,100,101,102,105,110,101, 32, 77, 95, 80, 73, 32, 51, 46, 49, 52, 49, 53, 57, 50, 54, + 53, 51, 53, 56, 57, 55, 57, 51, 50, 51, 56, 52, 54, 10, 10, 47, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 32, 83, 72, 65, 68, + 69, 82, 32, 78, 79, 68, 69, 83, 32, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 47, 10, 10,118,111,105,100, 32, +118, 99,111,108, 95, 97,116,116,114,105, 98,117,116,101, 40,118,101, 99, 52, 32, 97,116,116,118, 99,111,108, 44, 32,111,117,116, + 32,118,101, 99, 52, 32,118, 99,111,108, 41, 10,123, 10, 9,118, 99,111,108, 32, 61, 32,118,101, 99, 52, 40, 97,116,116,118, 99, +111,108, 46,120, 47, 50, 53, 53, 46, 48, 44, 32, 97,116,116,118, 99,111,108, 46,121, 47, 50, 53, 53, 46, 48, 44, 32, 97,116,116, +118, 99,111,108, 46,122, 47, 50, 53, 53, 46, 48, 44, 32, 49, 46, 48, 41, 59, 10,125, 10, 10,118,111,105,100, 32,117,118, 95, 97, +116,116,114,105, 98,117,116,101, 40,118,101, 99, 50, 32, 97,116,116,117,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32,117,118, + 41, 10,123, 10, 9,117,118, 32, 61, 32,118,101, 99, 51, 40, 97,116,116,117,118, 42, 50, 46, 48, 32, 45, 32,118,101, 99, 50, 40, + 49, 46, 48, 44, 32, 49, 46, 48, 41, 44, 32, 48, 46, 48, 41, 59, 10,125, 10, 10,118,111,105,100, 32,103,101,111,109, 40,118,101, + 99, 51, 32, 99,111, 44, 32,118,101, 99, 51, 32,110,111,114, 44, 32,109, 97,116, 52, 32,118,105,101,119,105,110,118,109, 97,116, + 44, 32,118,101, 99, 51, 32, 97,116,116,111,114, 99,111, 44, 32,118,101, 99, 50, 32, 97,116,116,117,118, 44, 32,118,101, 99, 52, + 32, 97,116,116,118, 99,111,108, 44, 32,111,117,116, 32,118,101, 99, 51, 32,103,108,111, 98, 97,108, 44, 32,111,117,116, 32,118, +101, 99, 51, 32,108,111, 99, 97,108, 44, 32,111,117,116, 32,118,101, 99, 51, 32,118,105,101,119, 44, 32,111,117,116, 32,118,101, + 99, 51, 32,111,114, 99,111, 44, 32,111,117,116, 32,118,101, 99, 51, 32,117,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32,110, +111,114,109, 97,108, 44, 32,111,117,116, 32,118,101, 99, 52, 32,118, 99,111,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32, +102,114,111,110,116, 98, 97, 99,107, 41, 10,123, 10, 9,108,111, 99, 97,108, 32, 61, 32, 99,111, 59, 10, 9,118,105,101,119, 32, + 61, 32,110,111,114,109, 97,108,105,122,101, 40,108,111, 99, 97,108, 41, 59, 10, 9,103,108,111, 98, 97,108, 32, 61, 32, 40,118, +105,101,119,105,110,118,109, 97,116, 42,118,101, 99, 52, 40,108,111, 99, 97,108, 44, 32, 49, 46, 48, 41, 41, 46,120,121,122, 59, + 10, 9,111,114, 99,111, 32, 61, 32, 97,116,116,111,114, 99,111, 59, 10, 9,117,118, 95, 97,116,116,114,105, 98,117,116,101, 40, + 97,116,116,117,118, 44, 32,117,118, 41, 59, 10, 9,110,111,114,109, 97,108, 32, 61, 32, 45,110,111,114,109, 97,108,105,122,101, + 40,110,111,114, 41, 59, 9, 47, 42, 32, 98,108,101,110,100,101,114, 32,114,101,110,100,101,114, 32,110,111,114,109, 97,108, 32, +105,115, 32,110,101,103, 97,116,101,100, 32, 42, 47, 10, 9,118, 99,111,108, 95, 97,116,116,114,105, 98,117,116,101, 40, 97,116, +116,118, 99,111,108, 44, 32,118, 99,111,108, 41, 59, 10, 9,102,114,111,110,116, 98, 97, 99,107, 32, 61, 32, 49, 46, 48, 59, 10, +125, 10, 10,118,111,105,100, 32,109, 97,112,112,105,110,103, 40,118,101, 99, 51, 32,118,101, 99, 44, 32,109, 97,116, 52, 32,109, + 97,116, 44, 32,118,101, 99, 51, 32,109,105,110,118,101, 99, 44, 32,118,101, 99, 51, 32,109, 97,120,118,101, 99, 44, 32,102,108, +111, 97,116, 32,100,111,109,105,110, 44, 32,102,108,111, 97,116, 32,100,111,109, 97,120, 44, 32,111,117,116, 32,118,101, 99, 51, + 32,111,117,116,118,101, 99, 41, 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32, 40,109, 97,116, 32, 42, 32,118,101, 99, 52, + 40,118,101, 99, 44, 32, 49, 46, 48, 41, 41, 46,120,121,122, 59, 10, 9,105,102, 40,100,111,109,105,110, 32, 61, 61, 32, 49, 46, + 48, 41, 10, 9, 9,111,117,116,118,101, 99, 32, 61, 32,109, 97,120, 40,111,117,116,118,101, 99, 44, 32,109,105,110,118,101, 99, + 41, 59, 10, 9,105,102, 40,100,111,109, 97,120, 32, 61, 61, 32, 49, 46, 48, 41, 10, 9, 9,111,117,116,118,101, 99, 32, 61, 32, +109,105,110, 40,111,117,116,118,101, 99, 44, 32,109, 97,120,118,101, 99, 41, 59, 10,125, 10, 10,118,111,105,100, 32, 99, 97,109, +101,114, 97, 40,118,101, 99, 51, 32, 99,111, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,105,101,119, 44, 32,111, +117,116, 32,102,108,111, 97,116, 32,111,117,116,100,101,112,116,104, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116, +100,105,115,116, 41, 10,123, 10, 9,111,117,116,100,101,112,116,104, 32, 61, 32, 97, 98,115, 40, 99,111, 46,122, 41, 59, 10, 9, +111,117,116,100,105,115,116, 32, 61, 32,108,101,110,103,116,104, 40, 99,111, 41, 59, 10, 9,111,117,116,118,105,101,119, 32, 61, + 32,110,111,114,109, 97,108,105,122,101, 40, 99,111, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97,100,100, + 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, + 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,118, 97,108, 49, 32, 43, 32,118, 97, +108, 50, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,115,117, 98,116,114, 97, 99,116, 40,102,108,111, 97,116, 32, +118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, + 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,118, 97,108, 49, 32, 45, 32,118, 97,108, 50, 59, 10,125, 10, 10, +118,111,105,100, 32,109, 97,116,104, 95,109,117,108,116,105,112,108,121, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102, 108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9, -105,102, 32, 40,118, 97,108, 49, 32, 62, 61, 32, 48, 46, 48, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32,112,111,119, 40, -118, 97,108, 49, 44, 32,118, 97,108, 50, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, - 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,108,111,103, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32, -102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, - 9,105,102, 40,118, 97,108, 49, 32, 62, 32, 48, 46, 48, 32, 32, 38, 38, 32,118, 97,108, 50, 32, 62, 32, 48, 46, 48, 41, 10, 9, - 9,111,117,116,118, 97,108, 61, 32,108,111,103, 50, 40,118, 97,108, 49, 41, 32, 47, 32,108,111,103, 50, 40,118, 97,108, 50, 41, - 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, - 97,116,104, 95,109, 97,120, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32, -111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,109, 97, -120, 40,118, 97,108, 49, 44, 32,118, 97,108, 50, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,109,105,110, 40, -102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97, -116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,109,105,110, 40,118, 97,108, 49, 44, 32, -118, 97,108, 50, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,114,111,117,110,100, 40,102,108,111, 97,116, 32, -118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, - 61, 32,102,108,111,111,114, 40,118, 97,108, 32, 43, 32, 48, 46, 53, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, - 95,108,101,115,115, 95,116,104, 97,110, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, - 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 40,118, 97,108, 49, 32, - 60, 32,118, 97,108, 50, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 49, 46, 48, 59, 10, 9,101,108,115,101, 10, 9, 9, -111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,103,114,101, 97,116, -101,114, 95,116,104, 97,110, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32, -111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 40,118, 97,108, 49, 32, 62, 32,118, - 97,108, 50, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 49, 46, 48, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116, -118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,115,113,117,101,101,122,101, 40,102,108,111, 97,116, - 32,118, 97,108, 44, 32,102,108,111, 97,116, 32,119,105,100,116,104, 44, 32,102,108,111, 97,116, 32, 99,101,110,116,101,114, 44, - 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 49, - 46, 48, 47, 40, 49, 46, 48, 32, 43, 32,112,111,119, 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 51, 44, 32, 45, 40, 40,118, 97,108, - 45, 99,101,110,116,101,114, 41, 42,119,105,100,116,104, 41, 41, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, - 97,116,104, 95, 97,100,100, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32,111,117,116, 32,118,101, - 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9, -111,117,116,118,101, 99, 32, 61, 32,118, 49, 32, 43, 32,118, 50, 59, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 40, 97, 98,115, - 40,111,117,116,118,101, 99, 91, 48, 93, 41, 32, 43, 32, 97, 98,115, 40,111,117,116,118,101, 99, 91, 49, 93, 41, 32, 43, 32, 97, - 98,115, 40,111,117,116,118,101, 99, 91, 50, 93, 41, 41, 47, 51, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95, -109, 97,116,104, 95,115,117, 98, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32,111,117,116, 32,118, -101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, - 9,111,117,116,118,101, 99, 32, 61, 32,118, 49, 32, 45, 32,118, 50, 59, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 40, 97, 98, -115, 40,111,117,116,118,101, 99, 91, 48, 93, 41, 32, 43, 32, 97, 98,115, 40,111,117,116,118,101, 99, 91, 49, 93, 41, 32, 43, 32, - 97, 98,115, 40,111,117,116,118,101, 99, 91, 50, 93, 41, 41, 47, 51, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, - 95,109, 97,116,104, 95, 97,118,101,114, 97,103,101, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32, -111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97, -108, 41, 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32,118, 49, 32, 43, 32,118, 50, 59, 10, 9,111,117,116,118, 97,108, 32, - 61, 32,108,101,110,103,116,104, 40,111,117,116,118,101, 99, 41, 59, 10, 9,111,117,116,118,101, 99, 32, 61, 32,110,111,114,109, - 97,108,105,122,101, 40,111,117,116,118,101, 99, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95, -100,111,116, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111, -117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, -101, 99, 32, 61, 32,118,101, 99, 51, 40, 48, 44, 32, 48, 44, 32, 48, 41, 59, 10, 9,111,117,116,118, 97,108, 32, 61, 32,100,111, -116, 40,118, 49, 44, 32,118, 50, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95, 99,114,111,115, -115, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116, -118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118,101, 99, - 32, 61, 32, 99,114,111,115,115, 40,118, 49, 44, 32,118, 50, 41, 59, 10, 9,111,117,116,118, 97,108, 32, 61, 32,108,101,110,103, -116,104, 40,111,117,116,118,101, 99, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95,110,111,114, -109, 97,108,105,122,101, 40,118,101, 99, 51, 32,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32, -111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,108,101, -110,103,116,104, 40,118, 41, 59, 10, 9,111,117,116,118,101, 99, 32, 61, 32,110,111,114,109, 97,108,105,122,101, 40,118, 41, 59, - 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95,110,101,103, 97,116,101, 40,118,101, 99, 51, 32,118, 44, - 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118, 41, 10,123, 10, 9,111,117,116,118, 32, 61, 32, 45,118, 59, 10,125, 10, - 10,118,111,105,100, 32,110,111,114,109, 97,108, 40,118,101, 99, 51, 32,100,105,114, 44, 32,118,101, 99, 51, 32,110,111,114, 44, - 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,110,111,114, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,100, -111,116, 41, 10,123, 10, 9,111,117,116,110,111,114, 32, 61, 32,100,105,114, 59, 10, 9,111,117,116,100,111,116, 32, 61, 32, 45, -100,111,116, 40,100,105,114, 44, 32,110,111,114, 41, 59, 10,125, 10, 10,118,111,105,100, 32, 99,117,114,118,101,115, 95,118,101, - 99, 40,118,101, 99, 51, 32,118,101, 99, 44, 32,115, 97,109,112,108,101,114, 49, 68, 32, 99,117,114,118,101,109, 97,112, 44, 32, -111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 41, 10,123, 10, 9,111,117,116,118,101, 99, 46,120, 32, 61, 32,116, -101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 40,118,101, 99, 46,120, 32, 43, 32, 49, 46, 48, 41, - 42, 48, 46, 53, 41, 46,120, 59, 10, 9,111,117,116,118,101, 99, 46,121, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99, -117,114,118,101,109, 97,112, 44, 32, 40,118,101, 99, 46,121, 32, 43, 32, 49, 46, 48, 41, 42, 48, 46, 53, 41, 46,121, 59, 10, 9, -111,117,116,118,101, 99, 46,122, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 40, -118,101, 99, 46,122, 32, 43, 32, 49, 46, 48, 41, 42, 48, 46, 53, 41, 46,122, 59, 10,125, 10, 10,118,111,105,100, 32, 99,117,114, -118,101,115, 95,114,103, 98, 40,118,101, 99, 52, 32, 99,111,108, 44, 32,115, 97,109,112,108,101,114, 49, 68, 32, 99,117,114,118, -101,109, 97,112, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, 41, 10,123, 10, 9,111,117,116, 99,111,108, - 46,114, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32,116,101,120,116,117,114,101, - 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 99,111,108, 46,114, 41, 46, 97, 41, 46,114, 59, 10, 9,111,117,116, 99,111, -108, 46,103, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32,116,101,120,116,117,114, -101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 99,111,108, 46,103, 41, 46, 97, 41, 46,103, 59, 10, 9,111,117,116, 99, -111,108, 46, 98, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32,116,101,120,116,117, -114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 99,111,108, 46, 98, 41, 46, 97, 41, 46, 98, 59, 10, 9,111,117,116, +111,117,116,118, 97,108, 32, 61, 32,118, 97,108, 49, 32, 42, 32,118, 97,108, 50, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97, +116,104, 95,100,105,118,105,100,101, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, + 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40,118, 97,108, 50, 32, + 61, 61, 32, 48, 46, 48, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10, 9,101,108,115,101, 10, 9, 9, +111,117,116,118, 97,108, 32, 61, 32,118, 97,108, 49, 32, 47, 32,118, 97,108, 50, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97, +116,104, 95,115,105,110,101, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116, +118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,115,105,110, 40,118, 97,108, 41, 59, 10,125, 10, 10,118,111, +105,100, 32,109, 97,116,104, 95, 99,111,115,105,110,101, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108, +111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 99,111,115, 40,118, 97,108, 41, + 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,116, 97,110,103,101,110,116, 40,102,108,111, 97,116, 32,118, 97,108, + 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32, +116, 97,110, 40,118, 97,108, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97,115,105,110, 40,102,108,111, 97, +116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40, +118, 97,108, 32, 60, 61, 32, 49, 46, 48, 32, 38, 38, 32,118, 97,108, 32, 62, 61, 32, 45, 49, 46, 48, 41, 10, 9, 9,111,117,116, +118, 97,108, 32, 61, 32, 97,115,105,110, 40,118, 97,108, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, + 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97, 99,111,115, 40,102,108,111, 97,116, 32,118, + 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40,118, 97,108, + 32, 60, 61, 32, 49, 46, 48, 32, 38, 38, 32,118, 97,108, 32, 62, 61, 32, 45, 49, 46, 48, 41, 10, 9, 9,111,117,116,118, 97,108, + 32, 61, 32, 97, 99,111,115, 40,118, 97,108, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, + 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95, 97,116, 97,110, 40,102,108,111, 97,116, 32,118, 97,108, 44, + 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32, 97, +116, 97,110, 40,118, 97,108, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,112,111,119, 40,102,108,111, 97,116, + 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116, +118, 97,108, 41, 10,123, 10, 9,105,102, 32, 40,118, 97,108, 49, 32, 62, 61, 32, 48, 46, 48, 41, 10, 9, 9,111,117,116,118, 97, +108, 32, 61, 32,112,111,119, 40,118, 97,108, 49, 44, 32,118, 97,108, 50, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116, +118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,108,111,103, 40,102,108,111, 97, +116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117, +116,118, 97,108, 41, 10,123, 10, 9,105,102, 40,118, 97,108, 49, 32, 62, 32, 48, 46, 48, 32, 32, 38, 38, 32,118, 97,108, 50, 32, + 62, 32, 48, 46, 48, 41, 10, 9, 9,111,117,116,118, 97,108, 61, 32,108,111,103, 50, 40,118, 97,108, 49, 41, 32, 47, 32,108,111, +103, 50, 40,118, 97,108, 50, 41, 59, 10, 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 61, 32, 48, 46, 48, 59, 10,125, + 10, 10,118,111,105,100, 32,109, 97,116,104, 95,109, 97,120, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97, +116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116, +118, 97,108, 32, 61, 32,109, 97,120, 40,118, 97,108, 49, 44, 32,118, 97,108, 50, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, + 97,116,104, 95,109,105,110, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97,116, 32,118, 97,108, 50, 44, 32, +111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,109,105, +110, 40,118, 97,108, 49, 44, 32,118, 97,108, 50, 41, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97,116,104, 95,114,111,117,110, +100, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, + 10, 9,111,117,116,118, 97,108, 61, 32,102,108,111,111,114, 40,118, 97,108, 32, 43, 32, 48, 46, 53, 41, 59, 10,125, 10, 10,118, +111,105,100, 32,109, 97,116,104, 95,108,101,115,115, 95,116,104, 97,110, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102, +108,111, 97,116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9, +105,102, 40,118, 97,108, 49, 32, 60, 32,118, 97,108, 50, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 49, 46, 48, 59, 10, + 9,101,108,115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,109, 97, +116,104, 95,103,114,101, 97,116,101,114, 95,116,104, 97,110, 40,102,108,111, 97,116, 32,118, 97,108, 49, 44, 32,102,108,111, 97, +116, 32,118, 97,108, 50, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,105,102, 40, +118, 97,108, 49, 32, 62, 32,118, 97,108, 50, 41, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 49, 46, 48, 59, 10, 9,101,108, +115,101, 10, 9, 9,111,117,116,118, 97,108, 32, 61, 32, 48, 46, 48, 59, 10,125, 10, 10,118,111,105,100, 32,115,113,117,101,101, +122,101, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,102,108,111, 97,116, 32,119,105,100,116,104, 44, 32,102,108,111, 97,116, + 32, 99,101,110,116,101,114, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117, +116,118, 97,108, 32, 61, 32, 49, 46, 48, 47, 40, 49, 46, 48, 32, 43, 32,112,111,119, 40, 50, 46, 55, 49, 56, 50, 56, 49, 56, 51, + 44, 32, 45, 40, 40,118, 97,108, 45, 99,101,110,116,101,114, 41, 42,119,105,100,116,104, 41, 41, 41, 59, 10,125, 10, 10,118,111, +105,100, 32,118,101, 99, 95,109, 97,116,104, 95, 97,100,100, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, + 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116, +118, 97,108, 41, 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32,118, 49, 32, 43, 32,118, 50, 59, 10, 9,111,117,116,118, 97, +108, 32, 61, 32, 40, 97, 98,115, 40,111,117,116,118,101, 99, 91, 48, 93, 41, 32, 43, 32, 97, 98,115, 40,111,117,116,118,101, 99, + 91, 49, 93, 41, 32, 43, 32, 97, 98,115, 40,111,117,116,118,101, 99, 91, 50, 93, 41, 41, 47, 51, 46, 48, 59, 10,125, 10, 10,118, +111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95,115,117, 98, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, + 50, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117, +116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32,118, 49, 32, 45, 32,118, 50, 59, 10, 9,111,117,116,118, + 97,108, 32, 61, 32, 40, 97, 98,115, 40,111,117,116,118,101, 99, 91, 48, 93, 41, 32, 43, 32, 97, 98,115, 40,111,117,116,118,101, + 99, 91, 49, 93, 41, 32, 43, 32, 97, 98,115, 40,111,117,116,118,101, 99, 91, 50, 93, 41, 41, 47, 51, 46, 48, 59, 10,125, 10, 10, +118,111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95, 97,118,101,114, 97,103,101, 40,118,101, 99, 51, 32,118, 49, 44, 32,118, +101, 99, 51, 32,118, 50, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, + 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32,118, 49, 32, 43, 32,118, 50, 59, 10, + 9,111,117,116,118, 97,108, 32, 61, 32,108,101,110,103,116,104, 40,111,117,116,118,101, 99, 41, 59, 10, 9,111,117,116,118,101, + 99, 32, 61, 32,110,111,114,109, 97,108,105,122,101, 40,111,117,116,118,101, 99, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118, +101, 99, 95,109, 97,116,104, 95,100,111,116, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32,111,117, +116, 32,118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, + 10,123, 10, 9,111,117,116,118,101, 99, 32, 61, 32,118,101, 99, 51, 40, 48, 44, 32, 48, 44, 32, 48, 41, 59, 10, 9,111,117,116, +118, 97,108, 32, 61, 32,100,111,116, 40,118, 49, 44, 32,118, 50, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, + 97,116,104, 95, 99,114,111,115,115, 40,118,101, 99, 51, 32,118, 49, 44, 32,118,101, 99, 51, 32,118, 50, 44, 32,111,117,116, 32, +118,101, 99, 51, 32,111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, + 10, 9,111,117,116,118,101, 99, 32, 61, 32, 99,114,111,115,115, 40,118, 49, 44, 32,118, 50, 41, 59, 10, 9,111,117,116,118, 97, +108, 32, 61, 32,108,101,110,103,116,104, 40,111,117,116,118,101, 99, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95, +109, 97,116,104, 95,110,111,114,109, 97,108,105,122,101, 40,118,101, 99, 51, 32,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32, +111,117,116,118,101, 99, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116, +118, 97,108, 32, 61, 32,108,101,110,103,116,104, 40,118, 41, 59, 10, 9,111,117,116,118,101, 99, 32, 61, 32,110,111,114,109, 97, +108,105,122,101, 40,118, 41, 59, 10,125, 10, 10,118,111,105,100, 32,118,101, 99, 95,109, 97,116,104, 95,110,101,103, 97,116,101, + 40,118,101, 99, 51, 32,118, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118, 41, 10,123, 10, 9,111,117,116,118, 32, + 61, 32, 45,118, 59, 10,125, 10, 10,118,111,105,100, 32,110,111,114,109, 97,108, 40,118,101, 99, 51, 32,100,105,114, 44, 32,118, +101, 99, 51, 32,110,111,114, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,110,111,114, 44, 32,111,117,116, 32,102,108, +111, 97,116, 32,111,117,116,100,111,116, 41, 10,123, 10, 9,111,117,116,110,111,114, 32, 61, 32,100,105,114, 59, 10, 9,111,117, +116,100,111,116, 32, 61, 32, 45,100,111,116, 40,100,105,114, 44, 32,110,111,114, 41, 59, 10,125, 10, 10,118,111,105,100, 32, 99, +117,114,118,101,115, 95,118,101, 99, 40,102,108,111, 97,116, 32,102, 97, 99, 44, 32,118,101, 99, 51, 32,118,101, 99, 44, 32,115, + 97,109,112,108,101,114, 49, 68, 32, 99,117,114,118,101,109, 97,112, 44, 32,111,117,116, 32,118,101, 99, 51, 32,111,117,116,118, +101, 99, 41, 10,123, 10, 9,111,117,116,118,101, 99, 46,120, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118, +101,109, 97,112, 44, 32, 40,118,101, 99, 46,120, 32, 43, 32, 49, 46, 48, 41, 42, 48, 46, 53, 41, 46,120, 59, 10, 9,111,117,116, +118,101, 99, 46,121, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 40,118,101, 99, + 46,121, 32, 43, 32, 49, 46, 48, 41, 42, 48, 46, 53, 41, 46,121, 59, 10, 9,111,117,116,118,101, 99, 46,122, 32, 61, 32,116,101, +120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 40,118,101, 99, 46,122, 32, 43, 32, 49, 46, 48, 41, 42, + 48, 46, 53, 41, 46,122, 59, 10, 9,105,102, 32, 40,102, 97, 99, 32, 33, 61, 32, 49, 46, 48, 41, 32,123, 10, 9, 9,111,117,116, +118,101, 99, 32, 61, 32, 40,111,117,116,118,101, 99, 42,102, 97, 99, 41, 32, 43, 32, 40,118,101, 99, 42, 40, 49, 46, 48, 45,102, + 97, 99, 41, 41, 59, 10, 9,125, 10,125, 10, 10,118,111,105,100, 32, 99,117,114,118,101,115, 95,114,103, 98, 40,102,108,111, 97, +116, 32,102, 97, 99, 44, 32,118,101, 99, 52, 32, 99,111,108, 44, 32,115, 97,109,112,108,101,114, 49, 68, 32, 99,117,114,118,101, +109, 97,112, 44, 32,111,117,116, 32,118,101, 99, 52, 32,111,117,116, 99,111,108, 41, 10,123, 10, 9,111,117,116, 99,111,108, 46, +114, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32,116,101,120,116,117,114,101, 49, + 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 99,111,108, 46,114, 41, 46, 97, 41, 46,114, 59, 10, 9,111,117,116, 99,111,108, + 46,103, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32,116,101,120,116,117,114,101, + 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 99,111,108, 46,103, 41, 46, 97, 41, 46,103, 59, 10, 9,111,117,116, 99,111, +108, 46, 98, 32, 61, 32,116,101,120,116,117,114,101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32,116,101,120,116,117,114, +101, 49, 68, 40, 99,117,114,118,101,109, 97,112, 44, 32, 99,111,108, 46, 98, 41, 46, 97, 41, 46, 98, 59, 10, 9,105,102, 32, 40, +102, 97, 99, 32, 33, 61, 32, 49, 46, 48, 41, 32,123, 10, 9, 9,111,117,116, 99,111,108, 32, 61, 32, 40,111,117,116, 99,111,108, + 42,102, 97, 99, 41, 32, 43, 32, 40, 99,111,108, 42, 40, 49, 46, 48, 45,102, 97, 99, 41, 41, 59, 10, 9,125, 10, 9,111,117,116, 99,111,108, 46, 97, 32, 61, 32, 99,111,108, 46, 97, 59, 10,125, 10, 10,118,111,105,100, 32,115,101,116, 95,118, 97,108,117,101, 40,102,108,111, 97,116, 32,118, 97,108, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,111,117,116,118, 97,108, 41, 10,123, 10, 9,111,117,116,118, 97,108, 32, 61, 32,118, 97,108, 59, 10,125, 10, 10,118,111,105,100, 32,115,101,116, 95,114,103, 98, 40,118, diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c index f106302dbaf..c6ff6377f00 100644 --- a/source/blender/ikplugin/intern/ikplugin_api.c +++ b/source/blender/ikplugin/intern/ikplugin_api.c @@ -31,7 +31,7 @@ #include "BIK_api.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_armature.h" #include "BKE_utildefines.h" diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index 6eb1ef56094..e9378a7e12b 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -31,7 +31,7 @@ #include "BIK_api.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_armature.h" #include "BKE_constraint.h" @@ -179,10 +179,10 @@ static void make_dmats(bPoseChannel *pchan) { if (pchan->parent) { float iR_parmat[4][4]; - Mat4Invert(iR_parmat, pchan->parent->pose_mat); - Mat4MulMat4(pchan->chan_mat, pchan->pose_mat, iR_parmat); // delta mat + invert_m4_m4(iR_parmat, pchan->parent->pose_mat); + mul_m4_m4m4(pchan->chan_mat, pchan->pose_mat, iR_parmat); // delta mat } - else Mat4CpyMat4(pchan->chan_mat, pchan->pose_mat); + else copy_m4_m4(pchan->chan_mat, pchan->pose_mat); } /* applies IK matrix to pchan, IK is done separated */ @@ -192,19 +192,19 @@ static void where_is_ik_bone(bPoseChannel *pchan, float ik_mat[][3]) // nr = t { float vec[3], ikmat[4][4]; - Mat4CpyMat3(ikmat, ik_mat); + copy_m4_m3(ikmat, ik_mat); if (pchan->parent) - Mat4MulSerie(pchan->pose_mat, pchan->parent->pose_mat, pchan->chan_mat, ikmat, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(pchan->pose_mat, pchan->parent->pose_mat, pchan->chan_mat, ikmat, NULL, NULL, NULL, NULL, NULL); else - Mat4MulMat4(pchan->pose_mat, ikmat, pchan->chan_mat); + mul_m4_m4m4(pchan->pose_mat, ikmat, pchan->chan_mat); /* calculate head */ VECCOPY(pchan->pose_head, pchan->pose_mat[3]); /* calculate tail */ VECCOPY(vec, pchan->pose_mat[1]); - VecMulf(vec, pchan->bone->length); - VecAddf(pchan->pose_tail, pchan->pose_head, vec); + mul_v3_fl(vec, pchan->bone->length); + add_v3_v3v3(pchan->pose_tail, pchan->pose_head, vec); pchan->flag |= POSE_DONE; } @@ -266,41 +266,41 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) IK_SetParent(seg, parent); /* get the matrix that transforms from prevbone into this bone */ - Mat3CpyMat4(R_bonemat, pchan->pose_mat); + copy_m3_m4(R_bonemat, pchan->pose_mat); /* gather transformations for this IK segment */ if (pchan->parent) - Mat3CpyMat4(R_parmat, pchan->parent->pose_mat); + copy_m3_m4(R_parmat, pchan->parent->pose_mat); else - Mat3One(R_parmat); + unit_m3(R_parmat); /* bone offset */ if (pchan->parent && (a > 0)) - VecSubf(start, pchan->pose_head, pchan->parent->pose_tail); + sub_v3_v3v3(start, pchan->pose_head, pchan->parent->pose_tail); else /* only root bone (a = 0) has no parent */ start[0]= start[1]= start[2]= 0.0f; /* change length based on bone size */ - length= bone->length*VecLength(R_bonemat[1]); + length= bone->length*len_v3(R_bonemat[1]); /* compute rest basis and its inverse */ - Mat3CpyMat3(rest_basis, bone->bone_mat); - Mat3CpyMat3(irest_basis, bone->bone_mat); - Mat3Transp(irest_basis); + copy_m3_m3(rest_basis, bone->bone_mat); + copy_m3_m3(irest_basis, bone->bone_mat); + transpose_m3(irest_basis); /* compute basis with rest_basis removed */ - Mat3Inv(iR_parmat, R_parmat); - Mat3MulMat3(full_basis, iR_parmat, R_bonemat); - Mat3MulMat3(basis, irest_basis, full_basis); + invert_m3_m3(iR_parmat, R_parmat); + mul_m3_m3m3(full_basis, iR_parmat, R_bonemat); + mul_m3_m3m3(basis, irest_basis, full_basis); /* basis must be pure rotation */ - Mat3Ortho(basis); + normalize_m3(basis); /* transform offset into local bone space */ - Mat3Ortho(iR_parmat); - Mat3MulVecfl(iR_parmat, start); + normalize_m3(iR_parmat); + mul_m3_v3(iR_parmat, start); IK_SetTransform(seg, start, rest_basis, basis, length); @@ -332,13 +332,13 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) /* transform goal by parent mat, so this rotation is not part of the segment's basis. otherwise rotation limits do not work on the local transform of the segment itself. */ - Mat4CpyMat4(rootmat, pchan->parent->pose_mat); + copy_m4_m4(rootmat, pchan->parent->pose_mat); else - Mat4One(rootmat); + unit_m4(rootmat); VECCOPY(rootmat[3], pchan->pose_head); - Mat4MulMat4 (imat, rootmat, ob->obmat); - Mat4Invert (goalinv, imat); + mul_m4_m4m4(imat, rootmat, ob->obmat); + invert_m4_m4(goalinv, imat); for (target=tree->targets.first; target; target=target->next) { float polepos[3]; @@ -352,10 +352,10 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) get_constraint_target_matrix(scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); /* and set and transform goal */ - Mat4MulMat4(goal, rootmat, goalinv); + mul_m4_m4m4(goal, rootmat, goalinv); VECCOPY(goalpos, goal[3]); - Mat3CpyMat4(goalrot, goal); + copy_m3_m4(goalrot, goal); /* same for pole vector target */ if(data->poletar) { @@ -366,7 +366,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) break; } else { - Mat4MulMat4(goal, rootmat, goalinv); + mul_m4_m4m4(goal, rootmat, goalinv); VECCOPY(polepos, goal[3]); poleconstrain= 1; @@ -392,9 +392,9 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) pchan= tree->pchan[target->tip]; /* end effector in world space */ - Mat4CpyMat4(end_pose, pchan->pose_mat); + copy_m4_m4(end_pose, pchan->pose_mat); VECCOPY(end_pose[3], pchan->pose_tail); - Mat4MulSerie(world_pose, goalinv, ob->obmat, end_pose, 0, 0, 0, 0, 0); + mul_serie_m4(world_pose, goalinv, ob->obmat, end_pose, 0, 0, 0, 0, 0); /* blend position */ goalpos[0]= fac*goalpos[0] + mfac*world_pose[3][0]; @@ -402,10 +402,10 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) goalpos[2]= fac*goalpos[2] + mfac*world_pose[3][2]; /* blend rotation */ - Mat3ToQuat(goalrot, q1); - Mat4ToQuat(world_pose, q2); - QuatInterpol(q, q1, q2, mfac); - QuatToMat3(q, goalrot); + mat3_to_quat( q1,goalrot); + mat4_to_quat( q2,world_pose); + interp_qt_qtqt(q, q1, q2, mfac); + quat_to_mat3( goalrot,q); } iktarget= iktree[target->tip]; @@ -449,7 +449,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) float trans[3], length; IK_GetTranslationChange(iktree[a], trans); - length= pchan->bone->length*VecLength(pchan->pose_mat[1]); + length= pchan->bone->length*len_v3(pchan->pose_mat[1]); ikstretch[a]= (length == 0.0)? 1.0: (trans[1]+length)/length; } @@ -458,14 +458,14 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) stretch= (parentstretch == 0.0)? 1.0: ikstretch[a]/parentstretch; - VecMulf(tree->basis_change[a][0], stretch); - VecMulf(tree->basis_change[a][1], stretch); - VecMulf(tree->basis_change[a][2], stretch); + mul_v3_fl(tree->basis_change[a][0], stretch); + mul_v3_fl(tree->basis_change[a][1], stretch); + mul_v3_fl(tree->basis_change[a][2], stretch); } if(resultblend && resultinf!=1.0f) { - Mat3One(identity); - Mat3BlendMat3(tree->basis_change[a], identity, + unit_m3(identity); + blend_m3_m3m3(tree->basis_change[a], identity, tree->basis_change[a], resultinf); } diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 3dcb9e462b9..05de0a0775b 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -46,7 +46,7 @@ extern "C" { #include "BIK_api.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_global.h" #include "BKE_armature.h" @@ -550,15 +550,15 @@ static bool target_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Fram if (pchan->parent) { pchan = pchan->parent; float chanmat[4][4]; - Mat4CpyMat4(chanmat, pchan->pose_mat); + copy_m4_m4(chanmat, pchan->pose_mat); VECCOPY(chanmat[3], pchan->pose_tail); - Mat4MulSerie(restmat, target->owner->obmat, chanmat, target->eeRest, NULL, NULL, NULL, NULL, NULL); + mul_serie_m4(restmat, target->owner->obmat, chanmat, target->eeRest, NULL, NULL, NULL, NULL, NULL); } else { - Mat4MulMat4(restmat, target->eeRest, target->owner->obmat); + mul_m4_m4m4(restmat, target->eeRest, target->owner->obmat); } // blend the target - Mat4BlendMat4(tarmat, restmat, tarmat, constraint->enforce); + blend_m4_m4m4(tarmat, restmat, tarmat, constraint->enforce); } next.setValue(&tarmat[0][0]); return true; @@ -577,15 +577,15 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& if (pchan->parent) { pchan = pchan->parent; float chanmat[4][4]; - Mat4CpyMat4(chanmat, pchan->pose_mat); + copy_m4_m4(chanmat, pchan->pose_mat); VECCOPY(chanmat[3], pchan->pose_tail); // save the base as a frame too so that we can compute deformation // after simulation ikscene->baseFrame.setValue(&chanmat[0][0]); - Mat4MulMat4(rootmat, chanmat, ikscene->blArmature->obmat); + mul_m4_m4m4(rootmat, chanmat, ikscene->blArmature->obmat); } else { - Mat4CpyMat4(rootmat, ikscene->blArmature->obmat); + copy_m4_m4(rootmat, ikscene->blArmature->obmat); ikscene->baseFrame = iTaSC::F_identity; } next.setValue(&rootmat[0][0]); @@ -598,7 +598,7 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& float mat[4][4]; // temp matrix bKinematicConstraint* poledata = (bKinematicConstraint*)ikscene->polarConstraint->data; - Mat4Invert(imat, rootmat); + invert_m4_m4(imat, rootmat); // polar constraint imply only one target IK_Target *iktarget = ikscene->targets[0]; // root channel from which we take the bone initial orientation @@ -607,11 +607,11 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& // get polar target matrix in world space get_constraint_target_matrix(ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0); // convert to armature space - Mat4MulMat4(polemat, mat, imat); + mul_m4_m4m4(polemat, mat, imat); // get the target in world space (was computed before as target object are defined before base object) iktarget->target->getPose().getValue(mat[0]); // convert to armature space - Mat4MulMat4(goalmat, mat, imat); + mul_m4_m4m4(goalmat, mat, imat); // take position of target, polar target, end effector, in armature space KDL::Vector goalpos(goalmat[3]); KDL::Vector polepos(polemat[3]); @@ -787,16 +787,16 @@ static bool joint_callback(const iTaSC::Timestamp& timestamp, iTaSC::ConstraintV if (chan->rotmode > 0) { /* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */ - EulOToMat3(chan->eul, chan->rotmode, rmat); + eulO_to_mat3( rmat,chan->eul, chan->rotmode); } else if (chan->rotmode == ROT_MODE_AXISANGLE) { /* axis-angle - stored in quaternion data, but not really that great for 3D-changing orientations */ - AxisAngleToMat3(&chan->quat[1], chan->quat[0], rmat); + axis_angle_to_mat3( rmat,&chan->quat[1], chan->quat[0]); } else { /* quats are normalised before use to eliminate scaling issues */ - NormalQuat(chan->quat); - QuatToMat3(chan->quat, rmat); + normalize_qt(chan->quat); + quat_to_mat3( rmat,chan->quat); } KDL::Rotation jointRot( rmat[0][0], rmat[1][0], rmat[2][0], @@ -977,26 +977,26 @@ static void convert_pose(IK_Scene *ikscene) int a, joint; // assume uniform scaling and take Y scale as general scale for the armature - scale = VecLength(ikscene->blArmature->obmat[1]); + scale = len_v3(ikscene->blArmature->obmat[1]); rot = &ikscene->jointArray(0); for(joint=a=0, ikchan = ikscene->channels; a<ikscene->numchan && joint<ikscene->numjoint; ++a, ++ikchan) { pchan= ikchan->pchan; bone= pchan->bone; if (pchan->parent) { - Mat4One(bmat); - Mat4MulMat43(bmat, pchan->parent->pose_mat, bone->bone_mat); + unit_m4(bmat); + mul_m4_m4m3(bmat, pchan->parent->pose_mat, bone->bone_mat); } else { - Mat4CpyMat4(bmat, bone->arm_mat); + copy_m4_m4(bmat, bone->arm_mat); } - Mat4Invert(rmat, bmat); - Mat4MulMat4(bmat, pchan->pose_mat, rmat); - Mat4Ortho(bmat); + invert_m4_m4(rmat, bmat); + mul_m4_m4m4(bmat, pchan->pose_mat, rmat); + normalize_m4(bmat); boneRot.setValue(bmat[0]); GetJointRotation(boneRot, ikchan->jointType, rot); if (ikchan->jointType & IK_TRANSY) { // compute actual length - rot[ikchan->ndof-1] = VecLenf(pchan->pose_tail, pchan->pose_head) * scale; + rot[ikchan->ndof-1] = len_v3v3(pchan->pose_tail, pchan->pose_head) * scale; } rot += ikchan->ndof; joint += ikchan->ndof; @@ -1014,7 +1014,7 @@ static void rest_pose(IK_Scene *ikscene) int a, joint; // assume uniform scaling and take Y scale as general scale for the armature - scale = VecLength(ikscene->blArmature->obmat[1]); + scale = len_v3(ikscene->blArmature->obmat[1]); // rest pose is 0 KDL::SetToZero(ikscene->jointArray); // except for transY joints @@ -1103,7 +1103,7 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) std::vector<double> weights; double weight[3]; // assume uniform scaling and take Y scale as general scale for the armature - float scale = VecLength(ob->obmat[1]); + float scale = len_v3(ob->obmat[1]); // build the array of joints corresponding to the IK chain convert_channels(ikscene, tree); if (ingame) { @@ -1379,12 +1379,12 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) // it has a parent, get the pose matrix from it float baseFrame[4][4]; pchan = pchan->parent; - Mat4CpyMat4(baseFrame, pchan->bone->arm_mat); + copy_m4_m4(baseFrame, pchan->bone->arm_mat); // move to the tail and scale to get rest pose of armature base - VecCopyf(baseFrame[3], pchan->bone->arm_tail); - Mat4Invert(invBaseFrame, baseFrame); + copy_v3_v3(baseFrame[3], pchan->bone->arm_tail); + invert_m4_m4(invBaseFrame, baseFrame); } else { - Mat4One(invBaseFrame); + unit_m4(invBaseFrame); } // finally add the constraint for (t=0; t<ikscene->targets.size(); t++) { @@ -1403,10 +1403,10 @@ static IK_Scene* convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) bonelen /= bonecnt; // store the rest pose of the end effector to compute enforce target - Mat4CpyMat4(mat, pchan->bone->arm_mat); - VecCopyf(mat[3], pchan->bone->arm_tail); + copy_m4_m4(mat, pchan->bone->arm_mat); + copy_v3_v3(mat[3], pchan->bone->arm_tail); // get the rest pose relative to the armature base - Mat4MulMat4(iktarget->eeRest, mat, invBaseFrame); + mul_m4_m4m4(iktarget->eeRest, mat, invBaseFrame); iktarget->eeBlend = (!ikscene->polarConstraint && condata->type==CONSTRAINT_IK_COPYPOSE) ? true : false; // use target_callback to make sure the initPose includes enforce coefficient target_callback(iTaSC::Timestamp(), iTaSC::F_identity, initPose, iktarget); @@ -1660,13 +1660,13 @@ static void execute_scene(Scene* blscene, IK_Scene* ikscene, bItasc* ikparam, fl VECCOPY(pchan->pose_tail, pchan->pose_mat[3]); // shift to head VECCOPY(yaxis, pchan->pose_mat[1]); - VecMulf(yaxis, length); - VecSubf(pchan->pose_mat[3], pchan->pose_mat[3], yaxis); + mul_v3_fl(yaxis, length); + sub_v3_v3v3(pchan->pose_mat[3], pchan->pose_mat[3], yaxis); VECCOPY(pchan->pose_head, pchan->pose_mat[3]); // add scale - VecMulf(pchan->pose_mat[0], scale); - VecMulf(pchan->pose_mat[1], scale); - VecMulf(pchan->pose_mat[2], scale); + mul_v3_fl(pchan->pose_mat[0], scale); + mul_v3_fl(pchan->pose_mat[1], scale); + mul_v3_fl(pchan->pose_mat[2], scale); } if (i<ikscene->numchan) { // big problem diff --git a/source/blender/imbuf/intern/Makefile b/source/blender/imbuf/intern/Makefile index 427052cbdc3..0f2020c799a 100644 --- a/source/blender/imbuf/intern/Makefile +++ b/source/blender/imbuf/intern/Makefile @@ -39,7 +39,7 @@ include nan_definitions.mk DIRS = cineon ifeq ($(WITH_OPENEXR), true) - DIRS += openexr + DIRS += openexr CFLAGS += -DWITH_OPENEXR endif @@ -49,7 +49,11 @@ ifeq ($(WITH_DDS), true) endif ifeq ($(WITH_OPENJPEG), true) - CFLAGS += -DWITH_OPENJPEG -I../../../../extern/libopenjpeg + ifndef BF_OPENJPEG_INC + CFLAGS += -DWITH_OPENJPEG -I../../../../extern/libopenjpeg + else + CFLAGS += -DWITH_OPENJPEG -I$(BF_OPENJPEG_INC) + endif endif CFLAGS += $(LEVEL_1_C_WARNINGS) diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h index 7067c967da3..5f6d8ef375a 100644 --- a/source/blender/makesdna/DNA_action_types.h +++ b/source/blender/makesdna/DNA_action_types.h @@ -220,7 +220,7 @@ typedef enum ePchan_IkFlag { typedef enum eRotationModes { /* quaternion rotations (default, and for older Blender versions) */ ROT_MODE_QUAT = 0, - /* euler rotations - keep in sync with enum in BLI_arithb.h */ + /* euler rotations - keep in sync with enum in BLI_math.h */ ROT_MODE_EUL = 1, /* Blender 'default' (classic) - must be as 1 to sync with arithb defines */ ROT_MODE_XYZ = 1, /* Blender 'default' (classic) - must be as 1 to sync with arithb defines */ ROT_MODE_XZY, @@ -446,6 +446,7 @@ typedef enum DOPESHEET_FILTERFLAG { ADS_FILTER_NOPART = (1<<16), ADS_FILTER_NOMBA = (1<<17), ADS_FILTER_NOARM = (1<<18), + ADS_FILTER_NONTREE = (1<<19), /* NLA-specific filters */ ADS_FILTER_NLA_NOACT = (1<<20), /* if the AnimData block has no NLA data, don't include to just show Action-line */ diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h index d3e611178fe..7dd90a3cf13 100644 --- a/source/blender/makesdna/DNA_armature_types.h +++ b/source/blender/makesdna/DNA_armature_types.h @@ -78,6 +78,9 @@ typedef struct bArmature { ListBase chainbase; ListBase *edbo; /* editbone listbase, we use pointer so we can check state */ + Bone *act_bone; + void *act_edbone; + void *sketch; /* sketch struct for etch-a-ton */ int flag; @@ -154,7 +157,7 @@ typedef enum eBone_Flag { /* 32 used to be quatrot, was always set in files, do not reuse unless you clear it always */ BONE_HIDDEN_P = (1<<6), /* hidden Bones when drawing PoseChannels */ BONE_DONE = (1<<7), /* For detecting cyclic dependancies */ - BONE_ACTIVE = (1<<8), /* active is on mouse clicks only */ + BONE_DRAW_ACTIVE = (1<<8), /* active is on mouse clicks only - deprecated, ONLY USE FOR DRAWING */ BONE_HINGE = (1<<9), /* No parent rotation or scale */ BONE_HIDDEN_A = (1<<10), /* hidden Bones when drawing Armature Editmode */ BONE_MULT_VG_ENV = (1<<11), /* multiplies vgroup with envelope */ diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 2b24b673185..8235d92d6f7 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -90,7 +90,7 @@ typedef struct bConstraintTarget { short space; /* space that target should be evaluated in (overrides bConstraint->tarspace) */ short flag; /* runtime settings (for editor, etc.) */ short type; /* type of target (B_CONSTRAINT_OB_TYPE) */ - short rotOrder; /* rotation order for target (as defined in BLI_arithb.h) */ + short rotOrder; /* rotation order for target (as defined in BLI_math.h) */ } bConstraintTarget; /* bConstraintTarget -> flag */ diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index ba1bb66c901..7ca8cea0763 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -40,6 +40,7 @@ struct bNodeLink; struct bNodeType; struct bNodeGroup; struct AnimData; +struct bGPdata; struct uiBlock; #define NODE_MAXSTR 32 @@ -109,7 +110,6 @@ typedef struct bNode { struct bNode *next, *prev, *new_node; char name[32]; - char username[32]; /* custom name defined by user */ short type, flag; short done, level; /* both for dependency and sorting */ short lasty, menunr; /* lasty: check preview render status, menunr: browse ID blocks */ @@ -151,6 +151,7 @@ typedef struct bNode { #define NODE_TEST 256 /* composite: don't do node but pass on buffer(s) */ #define NODE_MUTED 512 +#define NODE_CUSTOM_NAME 1024 typedef struct bNodeLink { struct bNodeLink *next, *prev; @@ -168,6 +169,8 @@ typedef struct bNodeTree { ID id; struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */ + struct bGPdata *gpd; /* grease pencil data */ + ListBase nodes, links; bNodeStack *stack; /* stack is only while executing, no read/write in file */ @@ -177,6 +180,8 @@ typedef struct bNodeTree { int stacksize; /* amount of elements in stack */ int cur_index; /* sockets in groups have unique identifiers, adding new sockets always will increase this counter */ + int flag, pad; + ListBase alltypes; /* type definitions */ struct bNodeType *owntype; /* for groups or dynamic trees, no read/write */ @@ -201,6 +206,9 @@ typedef struct bNodeTree { #define NTREE_TYPE_INIT 1 #define NTREE_EXEC_INIT 2 +/* ntree->flag */ +#define NTREE_DS_EXPAND 1 /* for animation editors */ + /* data structs, for node->storage */ /* this one has been replaced with ImageUser, keep it for do_versions() */ @@ -301,4 +309,11 @@ typedef struct TexNodeOutput { char name[32]; } TexNodeOutput; + +/* comp channel matte */ +#define CMP_NODE_CHANNEL_MATTE_CS_RGB 1 +#define CMP_NODE_CHANNEL_MATTE_CS_HSV 2 +#define CMP_NODE_CHANNEL_MATTE_CS_YUV 3 +#define CMP_NODE_CHANNEL_MATTE_CS_YCC 4 + #endif diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index bafe8cc3162..b041227110b 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -191,7 +191,8 @@ typedef struct RenderData { float edgeR, edgeG, edgeB; short fullscreen, xplay, yplay, freqplay; /* standalone player */ // XXX deprecated since 2.5 - short depth, attrib, rt1, rt2; /* standalone player */ // XXX deprecated since 2.5 + short depth, attrib, rt2; /* standalone player */ // XXX deprecated since 2.5 + short frame_step; /* frames to jump during render/playback */ short stereomode; /* standalone player stereo settings */ // XXX deprecated since 2.5 @@ -738,10 +739,8 @@ typedef struct Scene { short recalc; /* recalc = counterpart of ob->recalc */ short jumpframe; + int pad5; - /* frame step. */ - int frame_step; - /* User-Defined KeyingSets */ int active_keyingset; /* index of the active KeyingSet. first KeyingSet has index 1, 'none' active is 0, 'add new' is -1 */ ListBase keyingsets; /* KeyingSets for the given frame */ diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 70db6b7a1ff..d2beab5daba 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -505,7 +505,7 @@ typedef struct SpaceConsole { ListBase scrollback; /* ConsoleLine; output */ ListBase history; /* ConsoleLine; command history, current edited line is the first */ - char prompt[8]; + char prompt[256]; char language[32]; /* multiple consoles are possible, not just python */ } SpaceConsole; diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index dc730ee46f9..6a1ef195d1d 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -310,10 +310,12 @@ extern StructRNA RNA_NlaStrip; extern StructRNA RNA_NlaTrack; extern StructRNA RNA_Node; extern StructRNA RNA_NodeTree; +extern StructRNA RNA_NodeSocket; extern StructRNA RNA_NoiseTexture; extern StructRNA RNA_NorController; extern StructRNA RNA_Nurb; extern StructRNA RNA_Object; +extern StructRNA RNA_ObjectBase; extern StructRNA RNA_ObstacleFluidSettings; extern StructRNA RNA_Operator; extern StructRNA RNA_OperatorFileListElement; @@ -358,6 +360,7 @@ extern StructRNA RNA_RenderEngine; extern StructRNA RNA_RenderLayer; extern StructRNA RNA_RenderPass; extern StructRNA RNA_RenderResult; +extern StructRNA RNA_RGBANodeSocket; extern StructRNA RNA_RigidBodyJointConstraint; extern StructRNA RNA_Scene; extern StructRNA RNA_SceneGameData; @@ -515,7 +518,9 @@ extern StructRNA RNA_UserPreferencesFilePaths; extern StructRNA RNA_UserPreferencesSystem; extern StructRNA RNA_UserPreferencesView; extern StructRNA RNA_UserSolidLight; +extern StructRNA RNA_ValueNodeSocket; extern StructRNA RNA_VectorFont; +extern StructRNA RNA_VectorNodeSocket; extern StructRNA RNA_VertexGroup; extern StructRNA RNA_VertexGroupElement; extern StructRNA RNA_VertexPaint; @@ -678,7 +683,10 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop); int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *t_ptr); int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr); int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr); + PropertyRNA *RNA_property_collection_active(PropertyRNA *prop); +FunctionRNA *RNA_property_collection_add_func(PropertyRNA *prop); +FunctionRNA *RNA_property_collection_remove_func(PropertyRNA *prop); /* efficient functions to set properties for arrays */ int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 3de347cf80e..cb1a1211d24 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -53,7 +53,7 @@ EnumPropertyItem id_type_items[] = { {ID_MA, "MATERIAL", ICON_MATERIAL_DATA, "Material", ""}, {ID_MB, "META", ICON_META_DATA, "MetaBall", ""}, {ID_ME, "MESH", ICON_MESH_DATA, "Mesh", ""}, - {ID_NT, "NODETREE", ICON_NODE, "NodeTree", ""}, + {ID_NT, "NODETREE", ICON_NODETREE, "NodeTree", ""}, {ID_OB, "OBJECT", ICON_OBJECT_DATA, "Object", ""}, {ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""}, {ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""}, diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 93e83492efa..c8d488db6c3 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1248,8 +1248,12 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa int i; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) - IDP_Double(idprop)= values[0]; + if(prop->arraydimension == 0) { + if(idprop->type == IDP_FLOAT) + IDP_Float(idprop)= values[0]; + else + IDP_Double(idprop)= values[0]; + } else if(idprop->subtype == IDP_FLOAT) { memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len); } @@ -1567,7 +1571,7 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr) { IDProperty *idprop; - CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; +// CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if((idprop=rna_idproperty_check(&prop, ptr))) { IDPropertyTemplate val = {0}; @@ -1593,6 +1597,9 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA MEM_freeN(item); } } + + /* py api calls directly */ +#if 0 else if(cprop->add){ if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */ ParameterList params; @@ -1603,6 +1610,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA } /*else printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier);*/ +#endif if(r_ptr) { if(idprop) { @@ -1620,7 +1628,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) { IDProperty *idprop; - CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; +// CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if((idprop=rna_idproperty_check(&prop, ptr))) { IDProperty tmp, *array; @@ -1644,6 +1652,9 @@ int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) } else if(prop->flag & PROP_IDPROPERTY) return 1; + + /* py api calls directly */ +#if 0 else if(cprop->remove){ if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */ ParameterList params; @@ -1656,7 +1667,7 @@ int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) } /*else printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);*/ - +#endif return 0; } @@ -1767,6 +1778,18 @@ PropertyRNA *RNA_property_collection_active(PropertyRNA *prop) return cprop->active; } +FunctionRNA *RNA_property_collection_add_func(PropertyRNA *prop) +{ + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; + return cprop->add; +} + +FunctionRNA *RNA_property_collection_remove_func(PropertyRNA *prop) +{ + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; + return cprop->remove; +} + int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array) { CollectionPropertyIterator iter; diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 96dde186260..f73ac517213 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -38,7 +38,7 @@ #ifdef RNA_RUNTIME -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_depsgraph.h" @@ -56,6 +56,44 @@ static void rna_Armature_update_data(bContext *C, PointerRNA *ptr) //WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL); } + +static void rna_Armature_act_bone_set(PointerRNA *ptr, PointerRNA value) +{ + bArmature *arm= (bArmature*)ptr->data; + + if(value.id.data==NULL && value.data==NULL) { + arm->act_bone= NULL; + } + else { + if(value.id.data != arm) { + /* raise an error! */ + } + else { + arm->act_bone= value.data; + arm->act_bone->flag |= BONE_SELECTED; + } + } +} + +static void rna_Armature_act_edit_bone_set(PointerRNA *ptr, PointerRNA value) +{ + bArmature *arm= (bArmature*)ptr->data; + + if(value.id.data==NULL && value.data==NULL) { + arm->act_edbone= NULL; + } + else { + if(value.id.data != arm) { + /* raise an error! */ + } + else { + arm->act_edbone= value.data; + ((EditBone *)arm->act_edbone)->flag |= BONE_SELECTED; + } + } +} + + static void rna_Armature_redraw_data(bContext *C, PointerRNA *ptr) { ID *id= ptr->id.data; @@ -371,11 +409,6 @@ static void rna_def_bone_common(StructRNA *srna, int editbone) RNA_def_property_ui_text(prop, "Connected", "When bone has a parent, bone's head is struck to the parent's tail."); RNA_def_property_update(prop, 0, "rna_Armature_update_data"); - prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_ACTIVE); - RNA_def_property_ui_text(prop, "Active", "Bone was the last bone clicked on (most operations are applied to only this bone)"); - RNA_def_property_update(prop, 0, "rna_Armature_redraw_data"); - prop= RNA_def_property(srna, "hinge", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_HINGE); RNA_def_property_ui_text(prop, "Inherit Rotation", "Bone doesn't inherit rotation or scale from parent bone."); @@ -593,7 +626,7 @@ static void rna_def_edit_bone(BlenderRNA *brna) static void rna_def_armature(BlenderRNA *brna) { StructRNA *srna; - PropertyRNA *prop; + PropertyRNA *prop, *prop_act; static EnumPropertyItem prop_drawtype_items[] = { {ARM_OCTA, "OCTAHEDRAL", 0, "Octahedral", "Display bones as octahedral shape (default)."}, @@ -634,11 +667,34 @@ static void rna_def_armature(BlenderRNA *brna) RNA_def_property_struct_type(prop, "Bone"); RNA_def_property_ui_text(prop, "Bones", ""); + { /* Collection active property */ + prop_act= RNA_def_property(srna, "bones__active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop_act, "Bone"); + RNA_def_property_pointer_sdna(prop_act, NULL, "act_bone"); + RNA_def_property_flag(prop_act, PROP_EDITABLE); + RNA_def_property_ui_text(prop_act, "Active Bone", "Armatures active bone."); + RNA_def_property_pointer_funcs(prop_act, NULL, "rna_Armature_act_bone_set", NULL); + + /* todo, redraw */ + RNA_def_property_collection_active(prop, prop_act); + } + prop= RNA_def_property(srna, "edit_bones", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "edbo", NULL); RNA_def_property_struct_type(prop, "EditBone"); RNA_def_property_ui_text(prop, "Edit Bones", ""); + { /* Collection active property */ + prop_act= RNA_def_property(srna, "edit_bones__active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop_act, "EditBone"); + RNA_def_property_pointer_sdna(prop_act, NULL, "act_edbone"); + RNA_def_property_flag(prop_act, PROP_EDITABLE); + RNA_def_property_ui_text(prop_act, "Active EditBone", "Armatures active edit bone."); + //RNA_def_property_update(prop_act, 0, "rna_Armature_act_editbone_update"); + RNA_def_property_pointer_funcs(prop_act, NULL, "rna_Armature_act_edit_bone_set", NULL); + RNA_def_property_collection_active(prop, prop_act); + } + /* Enum values */ // prop= RNA_def_property(srna, "rest_position", PROP_BOOLEAN, PROP_NONE); // RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_RESTPOS); diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 7f7976c365f..24aff923ba8 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -1706,9 +1706,9 @@ static void rna_def_constraint_spline_ik(BlenderRNA *brna) // TODO: add access to the positions array to allow more flexible aligning? /* settings */ - prop= RNA_def_property(srna, "affect_root", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CONSTRAINT_SPLINEIK_NO_ROOT); - RNA_def_property_ui_text(prop, "Affect Root", "Include the root joint in the calculations."); + prop= RNA_def_property(srna, "chain_offset", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_SPLINEIK_NO_ROOT); + RNA_def_property_ui_text(prop, "Chain Offset", "Offset the entire chain relative to the root joint."); RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update"); prop= RNA_def_property(srna, "even_divisions", PROP_BOOLEAN, PROP_NONE); @@ -1716,9 +1716,9 @@ static void rna_def_constraint_spline_ik(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Even Divisions", "Ignore the relative lengths of the bones when fitting to the curve."); RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update"); - prop= RNA_def_property(srna, "keep_max_length", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_SPLINEIK_SCALE_LIMITED); - RNA_def_property_ui_text(prop, "Keep Max Length", "Maintain the maximum length of the chain when spline is stretched."); + prop= RNA_def_property(srna, "y_scaling", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CONSTRAINT_SPLINEIK_SCALE_LIMITED); + RNA_def_property_ui_text(prop, "Y Scaling", "Stretch the Y axis of the bones to fit the curve."); RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update"); prop= RNA_def_property(srna, "xz_scaling_mode", PROP_ENUM, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index a914deb37a6..294f38cf3f7 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -611,7 +611,7 @@ static void rna_def_channeldriver(BlenderRNA *brna) /* Collections */ prop= RNA_def_property(srna, "targets", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "targets", NULL); - RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "add_target", "remove_target"); + RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "targets__add", "targets__remove"); RNA_def_property_struct_type(prop, "DriverTarget"); RNA_def_property_ui_text(prop, "Target Variables", "Properties acting as targets for this driver."); @@ -652,8 +652,8 @@ static void rna_def_fcurve(BlenderRNA *brna) {FCURVE_EXTRAPOLATE_LINEAR, "LINEAR", 0, "Linear", ""}, {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem prop_mode_color_items[] = { - {FCURVE_COLOR_AUTO_RAINBOW, "AUTO_RAINBOW", 0, "Automatic Rainbow", ""}, - {FCURVE_COLOR_AUTO_RGB, "AUTO_RGB", 0, "Automatic XYZ to RGB", ""}, + {FCURVE_COLOR_AUTO_RAINBOW, "AUTO_RAINBOW", 0, "Auto Rainbow", ""}, + {FCURVE_COLOR_AUTO_RGB, "AUTO_RGB", 0, "Auto XYZ to RGB", ""}, {FCURVE_COLOR_CUSTOM, "CUSTOM", 0, "User Defined", ""}, {0, NULL, 0, NULL, NULL}}; diff --git a/source/blender/makesrna/intern/rna_fcurve_api.c b/source/blender/makesrna/intern/rna_fcurve_api.c index 12ffb3e26fb..0abb5e8e499 100644 --- a/source/blender/makesrna/intern/rna_fcurve_api.c +++ b/source/blender/makesrna/intern/rna_fcurve_api.c @@ -71,7 +71,7 @@ void RNA_api_drivers(StructRNA *srna) PropertyRNA *parm; /* add target */ - func= RNA_def_function(srna, "add_target", "rna_Driver_add_target"); + func= RNA_def_function(srna, "targets__add", "rna_Driver_add_target"); RNA_def_function_ui_description(func, "Add a new target for the driver."); /* return type */ parm= RNA_def_pointer(func, "target", "DriverTarget", "", "Newly created Driver Target."); @@ -80,7 +80,7 @@ void RNA_api_drivers(StructRNA *srna) parm= RNA_def_string(func, "name", "", 64, "Name", "Name to use in scripted expressions/functions. (No spaces or dots are allowed. Also, must not start with a symbol or digit)"); /* remove target */ - func= RNA_def_function(srna, "remove_target", "rna_Driver_remove_target"); + func= RNA_def_function(srna, "targets__remove", "rna_Driver_remove_target"); RNA_def_function_ui_description(func, "Remove an existing target from the driver."); /* target to remove*/ parm= RNA_def_pointer(func, "target", "DriverTarget", "", "Target to remove from the driver."); diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index dddc2062f07..8babb9593a0 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -33,6 +33,14 @@ #ifdef RNA_RUNTIME +#include "DNA_scene_types.h" +#include "DNA_object_types.h" + +#include "BKE_group.h" + +#include "WM_api.h" +#include "WM_types.h" + static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) { ListBaseIterator *internal= iter->internal; @@ -41,6 +49,18 @@ static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject*)internal->link)->ob); } +static int rna_Group_objects_add(Group *group, bContext *C, Object *object) +{ + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, &object->id); + return add_to_group(group, object, CTX_data_scene(C), NULL); +} + +static int rna_Group_objects_remove(Group *group, bContext *C, Object *object) +{ + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, &object->id); + return rem_from_group(group, object, CTX_data_scene(C), NULL); +} + #else void RNA_def_group(BlenderRNA *brna) @@ -48,6 +68,9 @@ void RNA_def_group(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; + FunctionRNA *func; + PropertyRNA *parm; + srna= RNA_def_struct(brna, "Group", "ID"); RNA_def_struct_ui_text(srna, "Group", "Group of Object datablocks."); RNA_def_struct_ui_icon(srna, ICON_GROUP); @@ -57,16 +80,39 @@ void RNA_def_group(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Dupli Offset", "Offset from the center to use when instancing as DupliGroup."); RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4); + prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER); + RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); + RNA_def_property_array(prop, 20); + RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli."); + + + /* add object */ + func= RNA_def_function(srna, "objects__add", "rna_Group_objects_add"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add this object to a group"); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Newly created Group Target."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_pointer(func, "object", "Object", "", "Object to add."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + /* remove object */ + func= RNA_def_function(srna, "objects__remove", "rna_Group_objects_remove"); + RNA_def_function_ui_description(func, "Remove this object to a group"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Newly created Group Target."); + RNA_def_function_return(func, parm); + /* object to remove */ + parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); + prop= RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL); RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects."); - RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, 0, 0); - - prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER); - RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); - RNA_def_property_array(prop, 20); - RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this groups is instanced as a dupli."); + RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, "objects__add", "objects__remove"); } #endif diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index d90b4f17c85..64af7e07fd5 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -213,6 +213,7 @@ void RNA_api_main(struct StructRNA *srna); void RNA_api_material(StructRNA *srna); void RNA_api_mesh(struct StructRNA *srna); void RNA_api_object(struct StructRNA *srna); +void RNA_api_pose_channel(struct StructRNA *srna); void RNA_api_scene(struct StructRNA *srna); void RNA_api_text(struct StructRNA *srna); void RNA_api_ui_layout(struct StructRNA *srna); diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 35eab7645f3..e311cad4568 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -1393,13 +1393,13 @@ static void rna_def_material_strand(BlenderRNA *brna) prop= RNA_def_property(srna, "root_size", PROP_FLOAT, PROP_UNSIGNED); RNA_def_property_float_sdna(prop, NULL, "strand_sta"); RNA_def_property_float_funcs(prop, NULL, NULL, "rna_MaterialStrand_start_size_range"); - RNA_def_property_ui_text(prop, "Root Size", "Start size of strands in pixels Blender units."); + RNA_def_property_ui_text(prop, "Root Size", "Start size of strands in pixels or Blender units."); RNA_def_property_update(prop, 0, "rna_Material_update"); prop= RNA_def_property(srna, "tip_size", PROP_FLOAT, PROP_UNSIGNED); RNA_def_property_float_sdna(prop, NULL, "strand_end"); RNA_def_property_float_funcs(prop, NULL, NULL, "rna_MaterialStrand_end_size_range"); - RNA_def_property_ui_text(prop, "Tip Size", "Start size of strands in pixels or Blender units."); + RNA_def_property_ui_text(prop, "Tip Size", "End size of strands in pixels or Blender units."); RNA_def_property_update(prop, 0, "rna_Material_update"); prop= RNA_def_property(srna, "min_size", PROP_FLOAT, PROP_UNSIGNED); diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index b02b6d8bba3..9217a7a7b98 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -39,7 +39,7 @@ #include "DNA_scene_types.h" #include "BLI_editVert.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_customdata.h" #include "BKE_depsgraph.h" @@ -123,9 +123,9 @@ static void rna_MeshFace_normal_get(PointerRNA *ptr, float *values) MFace *mface= (MFace*)ptr->data; if(mface->v4) - CalcNormFloat4(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co, values); + normal_quad_v3( values,me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co); else - CalcNormFloat(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, values); + normal_tri_v3( values,me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co); } static float rna_MeshFace_area_get(PointerRNA *ptr) @@ -134,9 +134,9 @@ static float rna_MeshFace_area_get(PointerRNA *ptr) MFace *mface= (MFace*)ptr->data; if(mface->v4) - return AreaQ3Dfl(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co); + return area_quad_v3(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co); else - return AreaT3Dfl(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co); + return area_tri_v3(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co); } /* notice red and blue are swapped */ diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 93972894ef1..7bc10c4f470 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -216,8 +216,17 @@ static void rna_Smoke_set_type(bContext *C, PointerRNA *ptr) smokeModifier_free(smd); // XXX TODO: completely free all 3 pointers smokeModifier_createType(smd); // create regarding of selected type - if(smd->type & MOD_SMOKE_TYPE_DOMAIN) - ob->dt = OB_WIRE; + switch (smd->type) { + case MOD_SMOKE_TYPE_DOMAIN: + ob->dt = OB_WIRE; + break; + case MOD_SMOKE_TYPE_FLOW: + case MOD_SMOKE_TYPE_COLL: + case 0: + default: + ob->dt = OB_SHADED; + break; + } // update dependancy since a domain - other type switch could have happened rna_Modifier_dependency_update(C, ptr); diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 2c8243a4f16..d8bf8cd4158 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -36,80 +36,20 @@ #include "DNA_scene_types.h" #include "DNA_texture_types.h" +#include "BKE_animsys.h" #include "BKE_main.h" #include "BKE_node.h" #include "BKE_image.h" +#include "BKE_texture.h" -static EnumPropertyItem node_blend_type_items[] = { - { 0, "MIX", 0, "Mix", ""}, - { 1, "ADD", 0, "Add", ""}, - { 3, "SUBTRACT", 0, "Subtract", ""}, - { 2, "MULTIPLY", 0, "Multiply", ""}, - { 4, "SCREEN", 0, "Screen", ""}, - { 9, "OVERLAY", 0, "Overlay", ""}, - { 5, "DIVIDE", 0, "Divide", ""}, - { 6, "DIFFERENCE", 0, "Difference", ""}, - { 7, "DARKEN", 0, "Darken", ""}, - { 8, "LIGHTEN", 0, "Lighten", ""}, - {10, "DODGE", 0, "Dodge", ""}, - {11, "BURN", 0, "Burn", ""}, - {15, "COLOR", 0, "Color", ""}, - {14, "VALUE", 0, "Value", ""}, - {13, "SATURATION", 0, "Saturation", ""}, - {12, "HUE", 0, "Hue", ""}, - {16, "SOFT_LIGHT", 0, "Soft Light", ""}, - {17, "LINEAR_LIGHT", 0, "Linear Light",""}, - {0, NULL, 0, NULL, NULL}}; - -static EnumPropertyItem node_flip_items[] = { - {0, "X", 0, "Flip X", ""}, - {1, "Y", 0, "Flip Y", ""}, - {2, "XY", 0, "Flip X & Y", ""}, - {0, NULL, 0, NULL, NULL}}; - -static EnumPropertyItem node_math_items[] = { - { 0, "ADD", 0, "Add", ""}, - { 1, "SUBTRACT", 0, "Subtract", ""}, - { 2, "MULTIPLY", 0, "Multiply", ""}, - { 3, "DIVIDE", 0, "Divide", ""}, - { 4, "SINE", 0, "Sine", ""}, - { 5, "COSINE", 0, "Cosine", ""}, - { 6, "TANGENT", 0, "Tangent", ""}, - { 7, "ARCSINE", 0, "Arcsine", ""}, - { 8, "ARCCOSINE", 0, "Arccosine", ""}, - { 9, "ARCTANGENT", 0, "Arctangent", ""}, - {10, "POWER", 0, "Power", ""}, - {11, "LOGARITHM", 0, "Logarithm", ""}, - {12, "MINIMUM", 0, "Minimum", ""}, - {13, "MAXIMUM", 0, "Maximum", ""}, - {14, "ROUND", 0, "Round", ""}, - {15, "LESS_THAN", 0, "Less Than", ""}, - {16, "GREATER_THAN", 0, "Greater Than", ""}, - {0, NULL, 0, NULL, NULL}}; - -static EnumPropertyItem node_vec_math_items[] = { - {0, "ADD", 0, "Add", ""}, - {1, "SUBTRACT", 0, "Subtract", ""}, - {2, "AVERAGE", 0, "Average", ""}, - {3, "DOT_PRODUCT", 0, "Dot Product", ""}, - {4, "CROSS_PRODUCT", 0, "Cross Product", ""}, - {5, "NORMALIZE", 0, "Normalize", ""}, - {0, NULL, 0, NULL, NULL}}; - -static EnumPropertyItem node_filter_items[] = { - {0, "SOFTEN", 0, "Soften", ""}, - {1, "SHARPEN", 0, "Sharpen", ""}, - {2, "LAPLACE", 0, "Laplace", ""}, - {3, "SOBEL", 0, "Sobel", ""}, - {4, "PREWITT", 0, "Prewitt", ""}, - {5, "KIRSCH", 0, "Kirsch", ""}, - {6, "SHADOW", 0, "Shadow", ""}, - {0, NULL, 0, NULL, NULL}}; +#include "WM_types.h" #ifdef RNA_RUNTIME #include "ED_node.h" +#include "RE_pipeline.h" + static StructRNA *rna_Node_refine(struct PointerRNA *ptr) { bNode *node = (bNode*)ptr->data; @@ -128,13 +68,47 @@ static StructRNA *rna_Node_refine(struct PointerRNA *ptr) } } +static StructRNA *rna_NodeSocketType_refine(struct PointerRNA *ptr) +{ + bNodeSocket *ns= (bNodeSocket*)ptr->data; + + switch(ns->type) { + case SOCK_VALUE: + return &RNA_ValueNodeSocket; + case SOCK_VECTOR: + return &RNA_VectorNodeSocket; + case SOCK_RGBA: + return &RNA_RGBANodeSocket; + default: + return &RNA_UnknownType; + } +} + static char *rna_Node_path(PointerRNA *ptr) { - bNodeTree *ntree= (bNodeTree*)ptr->id.data; bNode *node= (bNode*)ptr->data; - int index = BLI_findindex(&ntree->nodes, node); + + return BLI_sprintfN("nodes[\"%s\"]", node->name); +} + +static char *rna_NodeSocket_path(PointerRNA *ptr) +{ + bNodeTree *ntree= (bNodeTree*)ptr->id.data; + bNodeSocket *sock= (bNodeSocket*)ptr->data; + bNode *node; + int socketindex; - return BLI_sprintfN("nodes[%d]", index); + if (!nodeFindNode(ntree, sock, &node, NULL)) return NULL; + + socketindex = BLI_findindex(&node->inputs, sock); + if (socketindex != -1) + return BLI_sprintfN("nodes[\"%s\"].inputs[%d]", node->name, socketindex); + + socketindex = BLI_findindex(&node->outputs, sock); + if (socketindex != -1) + return BLI_sprintfN("nodes[\"%s\"].outputs[%d]", node->name, socketindex); + + return NULL; } static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup) @@ -175,71 +149,328 @@ static void rna_Matte_t2_set(PointerRNA *ptr, float value) chroma->t2 = value; } -static void rna_Node_update(bContext *C, PointerRNA *ptr) +static void node_update(bContext *C, bNodeTree *ntree, bNode *node) { Main *bmain= CTX_data_main(C); - bNodeTree *ntree= (bNodeTree*)ptr->id.data; - bNode *node= (bNode*)ptr->data; Material *ma; Tex *tex; Scene *sce; - + /* look through all datablocks, to support groups */ for(ma=bmain->mat.first; ma; ma=ma->id.next) if(ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree)) ED_node_changed_update(&ma->id, node); - + for(tex=bmain->tex.first; tex; tex=tex->id.next) if(tex->nodetree && tex->use_nodes && has_nodetree(tex->nodetree, ntree)) ED_node_changed_update(&tex->id, node); - + for(sce=bmain->scene.first; sce; sce=sce->id.next) if(sce->nodetree && sce->use_nodes && has_nodetree(sce->nodetree, ntree)) ED_node_changed_update(&sce->id, node); } +static void rna_Node_update(bContext *C, PointerRNA *ptr) +{ + bNodeTree *ntree= (bNodeTree*)ptr->id.data; + bNode *node= (bNode*)ptr->data; + + node_update(C, ntree, node); +} + static void rna_Node_update_name(bContext *C, PointerRNA *ptr) { + bNodeTree *ntree= (bNodeTree*)ptr->id.data; + bNode *node= (bNode*)ptr->data; + char oldname[32]; + + /* make a copy of the old name first */ + BLI_strncpy(oldname, node->name, sizeof(oldname)); + + nodeUniqueName(ntree, node); + node->flag |= NODE_CUSTOM_NAME; + + /* fix all the animation data which may link to this */ + BKE_all_animdata_fix_paths_rename("nodes", oldname, node->name); + + node_update(C, ntree, node); +} + +/* this should be done at display time! if no custom names are set */ +#if 0 +static void rna_Node_update_username(bContext *C, PointerRNA *ptr) +{ bNode *node= (bNode*)ptr->data; const char *name; - if(node->id) { - BLI_strncpy(node->name, node->id->name+2, NODE_MAXSTR); - } - else { - switch(node->typeinfo->type) { - case SH_NODE_MIX_RGB: - case CMP_NODE_MIX_RGB: - case TEX_NODE_MIX_RGB: - if(RNA_enum_name(node_blend_type_items, node->custom1, &name)) - BLI_strncpy(node->name, name, NODE_MAXSTR); - break; - case CMP_NODE_FILTER: - if(RNA_enum_name(node_filter_items, node->custom1, &name)) - BLI_strncpy(node->name, name, NODE_MAXSTR); - break; - case CMP_NODE_FLIP: - if(RNA_enum_name(node_flip_items, node->custom1, &name)) - BLI_strncpy(node->name, name, NODE_MAXSTR); - break; - case SH_NODE_MATH: - case CMP_NODE_MATH: - case TEX_NODE_MATH: - if(RNA_enum_name(node_math_items, node->custom1, &name)) - BLI_strncpy(node->name, name, NODE_MAXSTR); - break; - case SH_NODE_VECT_MATH: - if(RNA_enum_name(node_vec_math_items, node->custom1, &name)) - BLI_strncpy(node->name, name, NODE_MAXSTR); - break; + + /* + if (!node->username[0]) { + if(node->id) { + BLI_strncpy(node->username, node->id->name+2, NODE_MAXSTR); + } + else { + + switch(node->typeinfo->type) { + case SH_NODE_MIX_RGB: + case CMP_NODE_MIX_RGB: + case TEX_NODE_MIX_RGB: + if(RNA_enum_name(node_blend_type_items, node->custom1, &name)) + BLI_strncpy(node->username, name, NODE_MAXSTR); + break; + case CMP_NODE_FILTER: + if(RNA_enum_name(node_filter_items, node->custom1, &name)) + BLI_strncpy(node->username, name, NODE_MAXSTR); + break; + case CMP_NODE_FLIP: + if(RNA_enum_name(node_flip_items, node->custom1, &name)) + BLI_strncpy(node->username, name, NODE_MAXSTR); + break; + case SH_NODE_MATH: + case CMP_NODE_MATH: + case TEX_NODE_MATH: + if(RNA_enum_name(node_math_items, node->custom1, &name)) + BLI_strncpy(node->username, name, NODE_MAXSTR); + break; + case SH_NODE_VECT_MATH: + if(RNA_enum_name(node_vec_math_items, node->custom1, &name)) + BLI_strncpy(node->username, name, NODE_MAXSTR); + break; + } + */ } } rna_Node_update(C, ptr); } +#endif + +static void rna_NodeSocket_update(bContext *C, PointerRNA *ptr) +{ + bNodeTree *ntree= (bNodeTree*)ptr->id.data; + bNodeSocket *sock= (bNodeSocket*)ptr->data; + bNode *node; + + if (nodeFindNode(ntree, sock, &node, NULL)) + node_update(C, ntree, node); +} + +static void rna_NodeSocket_defvalue_range(PointerRNA *ptr, float *min, float *max) +{ + bNodeSocket *sock= (bNodeSocket*)ptr->data; + + *min = sock->ns.min; + *max = sock->ns.max; +} + +static void rna_Node_mapping_update(bContext *C, PointerRNA *ptr) +{ + bNode *node= (bNode*)ptr->data; + + init_mapping((TexMapping *)node->storage); + + rna_Node_update(C, ptr); +} + +static void rna_Node_image_layer_update(bContext *C, PointerRNA *ptr) +{ + bNode *node= (bNode*)ptr->data; + Image *ima = (Image *)node->id; + ImageUser *iuser= node->storage; + + BKE_image_multilayer_index(ima->rr, iuser); + BKE_image_signal(ima, iuser, IMA_SIGNAL_SRC_CHANGE); + + rna_Node_update(C, ptr); +} + +static EnumPropertyItem *renderresult_layers_add_enum(RenderLayer *rl) +{ + EnumPropertyItem *item= NULL; + EnumPropertyItem tmp = {0, "", 0, "", ""}; + int i=0, totitem=0; + + while (rl) { + tmp.identifier = rl->name; + tmp.name= rl->name; + tmp.value = i++; + RNA_enum_item_add(&item, &totitem, &tmp); + rl=rl->next; + } + + RNA_enum_item_end(&item, &totitem); + + return item; +} + +static EnumPropertyItem *rna_Node_image_layer_itemf(bContext *C, PointerRNA *ptr, int *free) +{ + bNode *node= (bNode*)ptr->data; + Image *ima = (Image *)node->id; + EnumPropertyItem *item= NULL; + RenderLayer *rl; + + if (!ima || !(ima->rr)) return NULL; + + rl = ima->rr->layers.first; + item = renderresult_layers_add_enum(rl); + + *free= 1; + + return item; +} + +static EnumPropertyItem *rna_Node_scene_layer_itemf(bContext *C, PointerRNA *ptr, int *free) +{ + bNode *node= (bNode*)ptr->data; + Scene *sce = (Scene *)node->id; + EnumPropertyItem *item= NULL; + RenderLayer *rl; + + if (!sce) return NULL; + + rl = sce->r.layers.first; + item = renderresult_layers_add_enum(rl); + + *free= 1; + + return item; +} + +static EnumPropertyItem *rna_Node_channel_itemf(bContext *C, PointerRNA *ptr, int *free) +{ + bNode *node= (bNode*)ptr->data; + EnumPropertyItem *item= NULL; + EnumPropertyItem tmp = {0, "", 0, "", ""}; + int totitem=0; + + switch(node->custom1) { + case CMP_NODE_CHANNEL_MATTE_CS_RGB: + tmp.identifier= "R"; tmp.name= "R"; tmp.value= 1; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "G"; tmp.name= "G"; tmp.value= 2; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "B"; tmp.name= "B"; tmp.value= 3; + RNA_enum_item_add(&item, &totitem, &tmp); + break; + case CMP_NODE_CHANNEL_MATTE_CS_HSV: + tmp.identifier= "H"; tmp.name= "H"; tmp.value= 1; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "S"; tmp.name= "S"; tmp.value= 2; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "V"; tmp.name= "V"; tmp.value= 3; + RNA_enum_item_add(&item, &totitem, &tmp); + break; + case CMP_NODE_CHANNEL_MATTE_CS_YUV: + tmp.identifier= "Y"; tmp.name= "Y"; tmp.value= 1; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "G"; tmp.name= "U"; tmp.value= 2; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "V"; tmp.name= "V"; tmp.value= 3; + RNA_enum_item_add(&item, &totitem, &tmp); + break; + case CMP_NODE_CHANNEL_MATTE_CS_YCC: + tmp.identifier= "Y"; tmp.name= "Y"; tmp.value= 1; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "CB"; tmp.name= "Cr"; tmp.value= 2; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.identifier= "CR"; tmp.name= "Cb"; tmp.value= 3; + RNA_enum_item_add(&item, &totitem, &tmp); + break; + default: + break; + } + + RNA_enum_item_end(&item, &totitem); + *free= 1; + + return item; +} + #else +static EnumPropertyItem prop_image_layer_items[] = { +{ 0, "PLACEHOLDER", 0, "Placeholder", ""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem prop_scene_layer_items[] = { +{ 0, "PLACEHOLDER", 0, "Placeholder", ""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem prop_tri_channel_items[] = { +{ 1, "R", 0, "R", ""}, +{ 2, "G", 0, "G", ""}, +{ 3, "B", 0, "B", ""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem node_blend_type_items[] = { +{ 0, "MIX", 0, "Mix", ""}, +{ 1, "ADD", 0, "Add", ""}, +{ 3, "SUBTRACT", 0, "Subtract", ""}, +{ 2, "MULTIPLY", 0, "Multiply", ""}, +{ 4, "SCREEN", 0, "Screen", ""}, +{ 9, "OVERLAY", 0, "Overlay", ""}, +{ 5, "DIVIDE", 0, "Divide", ""}, +{ 6, "DIFFERENCE", 0, "Difference", ""}, +{ 7, "DARKEN", 0, "Darken", ""}, +{ 8, "LIGHTEN", 0, "Lighten", ""}, +{10, "DODGE", 0, "Dodge", ""}, +{11, "BURN", 0, "Burn", ""}, +{15, "COLOR", 0, "Color", ""}, +{14, "VALUE", 0, "Value", ""}, +{13, "SATURATION", 0, "Saturation", ""}, +{12, "HUE", 0, "Hue", ""}, +{16, "SOFT_LIGHT", 0, "Soft Light", ""}, +{17, "LINEAR_LIGHT", 0, "Linear Light",""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem node_flip_items[] = { +{0, "X", 0, "Flip X", ""}, +{1, "Y", 0, "Flip Y", ""}, +{2, "XY", 0, "Flip X & Y", ""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem node_math_items[] = { +{ 0, "ADD", 0, "Add", ""}, +{ 1, "SUBTRACT", 0, "Subtract", ""}, +{ 2, "MULTIPLY", 0, "Multiply", ""}, +{ 3, "DIVIDE", 0, "Divide", ""}, +{ 4, "SINE", 0, "Sine", ""}, +{ 5, "COSINE", 0, "Cosine", ""}, +{ 6, "TANGENT", 0, "Tangent", ""}, +{ 7, "ARCSINE", 0, "Arcsine", ""}, +{ 8, "ARCCOSINE", 0, "Arccosine", ""}, +{ 9, "ARCTANGENT", 0, "Arctangent", ""}, +{10, "POWER", 0, "Power", ""}, +{11, "LOGARITHM", 0, "Logarithm", ""}, +{12, "MINIMUM", 0, "Minimum", ""}, +{13, "MAXIMUM", 0, "Maximum", ""}, +{14, "ROUND", 0, "Round", ""}, +{15, "LESS_THAN", 0, "Less Than", ""}, +{16, "GREATER_THAN", 0, "Greater Than", ""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem node_vec_math_items[] = { +{0, "ADD", 0, "Add", ""}, +{1, "SUBTRACT", 0, "Subtract", ""}, +{2, "AVERAGE", 0, "Average", ""}, +{3, "DOT_PRODUCT", 0, "Dot Product", ""}, +{4, "CROSS_PRODUCT", 0, "Cross Product", ""}, +{5, "NORMALIZE", 0, "Normalize", ""}, +{0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem node_filter_items[] = { +{0, "SOFTEN", 0, "Soften", ""}, +{1, "SHARPEN", 0, "Sharpen", ""}, +{2, "LAPLACE", 0, "Laplace", ""}, +{3, "SOBEL", 0, "Sobel", ""}, +{4, "PREWITT", 0, "Prewitt", ""}, +{5, "KIRSCH", 0, "Kirsch", ""}, +{6, "SHADOW", 0, "Shadow", ""}, +{0, NULL, 0, NULL, NULL}}; + + #define MaxNodes 1000 enum @@ -264,15 +495,9 @@ typedef struct NodeInfo static NodeInfo nodes[MaxNodes]; -static void reg_node( - int ID, - int category, - const char *enum_name, - const char *struct_name, - const char *base_name, - const char *ui_name, - const char *ui_desc -){ +static void reg_node(int ID, int category, const char *enum_name, const char *struct_name, + const char *base_name, const char *ui_name, const char *ui_desc) +{ NodeInfo *ni = nodes + ID; ni->defined = 1; @@ -359,7 +584,7 @@ static void def_math(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, node_math_items); RNA_def_property_ui_text(prop, "Operation", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_vector_math(StructRNA *srna) @@ -370,7 +595,7 @@ static void def_vector_math(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, node_vec_math_items); RNA_def_property_ui_text(prop, "Operation", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_rgb_curve(StructRNA *srna) @@ -381,7 +606,7 @@ static void def_rgb_curve(StructRNA *srna) RNA_def_property_pointer_sdna(prop, NULL, "storage"); RNA_def_property_struct_type(prop, "CurveMapping"); RNA_def_property_ui_text(prop, "Mapping", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_vector_curve(StructRNA *srna) @@ -392,7 +617,7 @@ static void def_vector_curve(StructRNA *srna) RNA_def_property_pointer_sdna(prop, NULL, "storage"); RNA_def_property_struct_type(prop, "CurveMapping"); RNA_def_property_ui_text(prop, "Mapping", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_time(StructRNA *srna) @@ -403,20 +628,20 @@ static void def_time(StructRNA *srna) RNA_def_property_pointer_sdna(prop, NULL, "storage"); RNA_def_property_struct_type(prop, "CurveMapping"); RNA_def_property_ui_text(prop, "Curve", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "start", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "custom1"); RNA_def_property_ui_text(prop, "Start Frame", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "end", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "custom2"); RNA_def_property_ui_text(prop, "End Frame", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } -static void def_val_to_rgb(StructRNA *srna) +static void def_colorramp(StructRNA *srna) { PropertyRNA *prop; @@ -424,7 +649,7 @@ static void def_val_to_rgb(StructRNA *srna) RNA_def_property_pointer_sdna(prop, NULL, "storage"); RNA_def_property_struct_type(prop, "ColorRamp"); RNA_def_property_ui_text(prop, "Color Ramp", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_mix_rgb(StructRNA *srna) @@ -435,12 +660,12 @@ static void def_mix_rgb(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, node_blend_type_items); RNA_def_property_ui_text(prop, "Blend Type", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "alpha", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1); RNA_def_property_ui_text(prop, "Alpha", "Include alpha of second input in this operation"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_texture(StructRNA *srna) @@ -452,12 +677,12 @@ static void def_texture(StructRNA *srna) RNA_def_property_struct_type(prop, "Texture"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Texture", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "node_output", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "custom1"); RNA_def_property_ui_text(prop, "Node Output", "For node-based textures, which output node to use"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } @@ -472,33 +697,69 @@ static void def_sh_material(StructRNA *srna) RNA_def_property_struct_type(prop, "Material"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Material", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "diffuse", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_DIFF); RNA_def_property_ui_text(prop, "Diffuse", "Material Node outputs Diffuse"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "specular", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_SPEC); RNA_def_property_ui_text(prop, "Specular", "Material Node outputs Specular"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "invert_normal", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_NEG); RNA_def_property_ui_text(prop, "Invert Normal", "Material Node uses inverted normal"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_sh_mapping(StructRNA *srna) { PropertyRNA *prop; - prop = RNA_def_property(srna, "mapping", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "storage"); - RNA_def_property_struct_type(prop, "TexMapping"); - RNA_def_property_ui_text(prop, "Mapping", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_struct_sdna_from(srna, "TexMapping", "storage"); + + prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION); + RNA_def_property_float_sdna(prop, NULL, "loc"); + RNA_def_property_ui_text(prop, "Location", "Location offset for the input coordinate"); + RNA_def_property_ui_range(prop, -10.f, 10.f, 0.1f, 2); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_mapping_update"); + + prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER); + RNA_def_property_float_sdna(prop, NULL, "rot"); + RNA_def_property_ui_text(prop, "Rotation", "Rotation offset for the input coordinate"); + RNA_def_property_ui_range(prop, -360.f, 360.f, 1.f, 2); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_mapping_update"); + + prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ); + RNA_def_property_float_sdna(prop, NULL, "size"); + RNA_def_property_ui_text(prop, "Scale", "Scale adjustment for the input coordinate"); + RNA_def_property_ui_range(prop, -10.f, 10.f, 0.1f, 2); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_mapping_update"); + + prop = RNA_def_property(srna, "clamp_minimum", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", TEXMAP_CLIP_MIN); + RNA_def_property_ui_text(prop, "Clamp Minimum", "Clamp the output coordinate to a minimum value"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop= RNA_def_property(srna, "minimum", PROP_FLOAT, PROP_XYZ); + RNA_def_property_float_sdna(prop, NULL, "min"); + RNA_def_property_ui_text(prop, "Minimum", "Minimum value to clamp coordinate to"); + RNA_def_property_ui_range(prop, -10.f, 10.f, 0.1f, 2); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "clamp_maximum", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", TEXMAP_CLIP_MAX); + RNA_def_property_ui_text(prop, "Clamp Maximum", "Clamp the output coordinate to a maximum value"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop= RNA_def_property(srna, "maximum", PROP_FLOAT, PROP_XYZ); + RNA_def_property_float_sdna(prop, NULL, "max"); + RNA_def_property_ui_text(prop, "Maximum", "Maximum value to clamp coordinate to"); + RNA_def_property_ui_range(prop, -10.f, 10.f, 0.1f, 2); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_sh_geometry(StructRNA *srna) @@ -510,12 +771,12 @@ static void def_sh_geometry(StructRNA *srna) prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "uvname"); RNA_def_property_ui_text(prop, "UV Layer", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "color_layer", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "colname"); RNA_def_property_ui_text(prop, "Vertex Color Layer", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } @@ -529,7 +790,7 @@ static void def_cmp_alpha_over(StructRNA *srna) prop = RNA_def_property(srna, "convert_premul", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1); RNA_def_property_ui_text(prop, "Convert Premul", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); RNA_def_struct_sdna_from(srna, "NodeTwoFloats", "storage"); @@ -537,7 +798,7 @@ static void def_cmp_alpha_over(StructRNA *srna) RNA_def_property_float_sdna(prop, NULL, "x"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Premul", "Mix Factor"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_hue_saturation(StructRNA *srna) @@ -550,19 +811,19 @@ static void def_cmp_hue_saturation(StructRNA *srna) RNA_def_property_float_sdna(prop, NULL, "hue"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Hue", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "sat", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "sat"); RNA_def_property_range(prop, 0.0f, 2.0f); RNA_def_property_ui_text(prop, "Saturation", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "val", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "val"); RNA_def_property_range(prop, 0.0f, 2.0f); RNA_def_property_ui_text(prop, "Value", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_blur(StructRNA *srna) @@ -586,79 +847,52 @@ static void def_cmp_blur(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "sizex"); RNA_def_property_range(prop, 0, 256); RNA_def_property_ui_text(prop, "Size X", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "sizey", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "sizey"); RNA_def_property_range(prop, 0, 256); RNA_def_property_ui_text(prop, "Size Y", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); - - prop = RNA_def_property(srna, "samples", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "samples"); - RNA_def_property_range(prop, 1, 256); - RNA_def_property_ui_text(prop, "Samples", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); - - prop = RNA_def_property(srna, "max_speed", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "maxspeed"); - RNA_def_property_range(prop, 1, 1024); - RNA_def_property_ui_text(prop, "Max Speed", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); - - prop = RNA_def_property(srna, "min_speed", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "minspeed"); - RNA_def_property_range(prop, 1, 1024); - RNA_def_property_ui_text(prop, "Min Speed", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "relative", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "relative", 1); RNA_def_property_ui_text(prop, "Relative", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fac"); RNA_def_property_range(prop, 0.0f, 2.0f); RNA_def_property_ui_text(prop, "Factor", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "factor_x", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "percentx"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Relative Size X", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "factor_y", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "percenty"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Relative Size Y", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "filter_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "filtertype"); RNA_def_property_enum_items(prop, filter_type_items); RNA_def_property_ui_text(prop, "Filter Type", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "bokeh", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "bokeh", 1); RNA_def_property_ui_text(prop, "Bokeh", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "gamma", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "gamma", 1); RNA_def_property_ui_text(prop, "Gamma", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); - - /* - TODO: - curved - image_in_width - image_in_height - - Don't know if these need wrapping, can't find them in interface - */ + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } @@ -670,7 +904,7 @@ static void def_cmp_filter(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, node_filter_items); RNA_def_property_ui_text(prop, "Filter Type", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_map_value(StructRNA *srna) @@ -684,38 +918,38 @@ static void def_cmp_map_value(StructRNA *srna) RNA_def_property_array(prop, 1); RNA_def_property_range(prop, -1000.0f, 1000.0f); RNA_def_property_ui_text(prop, "Offset", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "size"); RNA_def_property_array(prop, 1); RNA_def_property_range(prop, -1000.0f, 1000.0f); RNA_def_property_ui_text(prop, "Size", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "use_min", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", TEXMAP_CLIP_MIN); RNA_def_property_ui_text(prop, "Use Minimum", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "use_max", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", TEXMAP_CLIP_MAX); RNA_def_property_ui_text(prop, "Use Maximum", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "min", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "min"); RNA_def_property_array(prop, 1); RNA_def_property_range(prop, -1000.0f, 1000.0f); RNA_def_property_ui_text(prop, "Minimum", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "max", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "max"); RNA_def_property_array(prop, 1); RNA_def_property_range(prop, -1000.0f, 1000.0f); RNA_def_property_ui_text(prop, "Maximum", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_vector_blur(StructRNA *srna) @@ -727,112 +961,104 @@ static void def_cmp_vector_blur(StructRNA *srna) prop = RNA_def_property(srna, "samples", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "samples"); RNA_def_property_ui_text(prop, "Samples", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "min_speed", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "minspeed"); RNA_def_property_ui_text(prop, "Min Speed", "Minimum speed for a pixel to be blurred; used to separate background from foreground"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "max_speed", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "maxspeed"); RNA_def_property_ui_text(prop, "Max Speed", "Maximum speed, or zero for none"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fac"); RNA_def_property_ui_text(prop, "Blur Factor", "Scaling factor for motion vectors; actually 'shutter speed' in frames"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "curved", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "curved", 1); RNA_def_property_ui_text(prop, "Curved", "Interpolate between frames in a bezier curve, rather than linearly"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_levels(StructRNA *srna) { PropertyRNA *prop; - static EnumPropertyItem space_items[] = { - {1, "COMNINED_RGB", 0, "C", "Combined RGB"}, + static EnumPropertyItem channel_items[] = { + {1, "COMBINED_RGB", 0, "C", "Combined RGB"}, {2, "RED", 0, "R", "Red Channel"}, {3, "GREEN", 0, "G", "Green Channel"}, {4, "BLUE", 0, "B", "Blue Channel"}, {5, "LUMINANCE", 0, "L", "Luminance Channel"}, {0, NULL, 0, NULL, NULL}}; - prop = RNA_def_property(srna, "color_space", PROP_ENUM, PROP_NONE); + prop = RNA_def_property(srna, "channel", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "custom1"); - RNA_def_property_enum_items(prop, space_items); - RNA_def_property_ui_text(prop, "Color Space", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_enum_items(prop, channel_items); + RNA_def_property_ui_text(prop, "Channel", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_image(StructRNA *srna) { PropertyRNA *prop; - /*static EnumPropertyItem type_items[] = { + /* + static EnumPropertyItem type_items[] = { {IMA_SRC_FILE, "IMAGE", 0, "Image", ""}, {IMA_SRC_MOVIE, "MOVIE", "Movie", ""}, {IMA_SRC_SEQUENCE, "SEQUENCE", "Sequence", ""}, {IMA_SRC_GENERATED, "GENERATED", "Generated", ""}, - {0, NULL, 0, NULL, NULL}};*/ + {0, NULL, 0, NULL, NULL}}; + */ prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "id"); RNA_def_property_struct_type(prop, "Image"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Image", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); RNA_def_struct_sdna_from(srna, "ImageUser", "storage"); - - /* TODO: if movie or sequence { */ prop = RNA_def_property(srna, "frames", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "frames"); RNA_def_property_range(prop, 1, MAXFRAMEF); RNA_def_property_ui_text(prop, "Frames", "Number of images used in animation"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "start", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "sfra"); RNA_def_property_range(prop, 1, MAXFRAMEF); RNA_def_property_ui_text(prop, "Start Frame", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "offset", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "offset"); RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF); RNA_def_property_ui_text(prop, "Offset", "Offsets the number of the frame to use in the animation"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "cyclic", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "cycl", 1); RNA_def_property_ui_text(prop, "Cyclic", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "auto_refresh", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANIM_ALWAYS); RNA_def_property_ui_text(prop, "Auto-Refresh", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); - /* } */ - - /* if type == multilayer { */ - - prop = RNA_def_property(srna, "layer", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "layer"); - RNA_def_property_range(prop, 0, 10000); + prop= RNA_def_property(srna, "layer", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "layer"); + RNA_def_property_enum_items(prop, prop_image_layer_items); + RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_image_layer_itemf"); RNA_def_property_ui_text(prop, "Layer", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); - - /* } */ - - /* TODO: refresh on change */ - + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_image_layer_update"); } static void def_cmp_render_layers(StructRNA *srna) @@ -844,19 +1070,20 @@ static void def_cmp_render_layers(StructRNA *srna) RNA_def_property_struct_type(prop, "Scene"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Scene", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); - /* TODO: layers in menu */ - prop = RNA_def_property(srna, "layer", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "custom1"); + prop= RNA_def_property(srna, "layer", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom1"); + RNA_def_property_enum_items(prop, prop_scene_layer_items); + RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_scene_layer_itemf"); RNA_def_property_ui_text(prop, "Layer", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); /* TODO: comments indicate this might be a hack */ prop = RNA_def_property(srna, "re_render", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1); RNA_def_property_ui_text(prop, "Re-render", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_output_file(StructRNA *srna) @@ -889,37 +1116,42 @@ static void def_cmp_output_file(StructRNA *srna) prop = RNA_def_property(srna, "filename", PROP_STRING, PROP_DIRPATH); RNA_def_property_string_sdna(prop, NULL, "name"); RNA_def_property_ui_text(prop, "Filename", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "image_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "imtype"); RNA_def_property_enum_items(prop, type_items); RNA_def_property_ui_text(prop, "Image Type", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "exr_half", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "subimtype", R_OPENEXR_HALF); RNA_def_property_ui_text(prop, "Half", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "exr_codec", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "codec"); RNA_def_property_enum_items(prop, openexr_codec_items); RNA_def_property_ui_text(prop, "Codec", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "quality", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "quality"); RNA_def_property_range(prop, 1, 100); RNA_def_property_ui_text(prop, "Quality", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "start_frame", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "sfra"); RNA_def_property_range(prop, MINFRAMEF, MAXFRAMEF); RNA_def_property_ui_text(prop, "Start Frame", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "end_frame", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "efra"); RNA_def_property_range(prop, MINFRAMEF, MAXFRAMEF); RNA_def_property_ui_text(prop, "End Frame", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_dilate_erode(StructRNA *srna) @@ -930,7 +1162,7 @@ static void def_cmp_dilate_erode(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "custom2"); RNA_def_property_range(prop, -100, 100); RNA_def_property_ui_text(prop, "Distance", "Distance to grow/shrink (number of iterations)"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_scale(StructRNA *srna) @@ -947,7 +1179,7 @@ static void def_cmp_scale(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, space_items); RNA_def_property_ui_text(prop, "Space", "Coordinate space to scale relative to"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_diff_matte(StructRNA *srna) @@ -961,14 +1193,14 @@ static void def_cmp_diff_matte(StructRNA *srna) RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Tolerance", "Color distances below this threshold are keyed."); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Falloff", "Color distances below this additional threshold are partially keyed."); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_color_matte(StructRNA *srna) @@ -981,19 +1213,19 @@ static void def_cmp_color_matte(StructRNA *srna) RNA_def_property_float_sdna(prop, NULL, "t1"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "H", "Hue tolerance for colors to be considered a keying color"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "s", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "S", "Saturation Tolerance for the color"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "v", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t3"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "V", "Value Tolerance for the color"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_distance_matte(StructRNA *srna) @@ -1007,14 +1239,14 @@ static void def_cmp_distance_matte(StructRNA *srna) RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Tolerance", "Color distances below this threshold are keyed."); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Falloff", "Color distances below this additional threshold are partially keyed."); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_color_spill(StructRNA *srna) @@ -1031,7 +1263,7 @@ static void def_cmp_color_spill(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, channel_items); RNA_def_property_ui_text(prop, "Channel", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); RNA_def_struct_sdna_from(srna, "NodeChroma", "storage"); @@ -1039,7 +1271,7 @@ static void def_cmp_color_spill(StructRNA *srna) RNA_def_property_float_sdna(prop, NULL, "t1"); RNA_def_property_range(prop, 0.0f, 0.5f); RNA_def_property_ui_text(prop, "Amount", "How much the selected channel is affected by"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_luma_matte(StructRNA *srna) @@ -1053,14 +1285,14 @@ static void def_cmp_luma_matte(StructRNA *srna) RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "High", "Values higher than this setting are 100% opaque"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "low", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Low", "Values lower than this setting are 100% keyed"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_chroma_matte(StructRNA *srna) @@ -1074,32 +1306,32 @@ static void def_cmp_chroma_matte(StructRNA *srna) RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); RNA_def_property_range(prop, 1.0f, 80.0f); RNA_def_property_ui_text(prop, "Acceptance", "Tolerance for a color to be considered a keying color"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "cutoff", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 30.0f); RNA_def_property_ui_text(prop, "Cutoff", "Tolerance below which colors will be considered as exact matches"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "lift", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fsize"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Lift", "Alpha lift"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "gain", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fstrength"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Gain", "Alpha gain"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "shadow_adjust", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t3"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Shadow Adjust", "Adjusts the brightness of any shadows captured"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_channel_matte(StructRNA *srna) @@ -1107,23 +1339,25 @@ static void def_cmp_channel_matte(StructRNA *srna) PropertyRNA *prop; static EnumPropertyItem color_space_items[] = { - {1, "RGB", 0, "RGB", "RGB Color Space"}, - {2, "HSV", 0, "HSV", "HSV Color Space"}, - {3, "YUV", 0, "YUV", "YUV Color Space"}, - {4, "YCC", 0, "YCbCr", "YCbCr Color Space"}, + {CMP_NODE_CHANNEL_MATTE_CS_RGB, "RGB", 0, "RGB", "RGB Color Space"}, + {CMP_NODE_CHANNEL_MATTE_CS_HSV, "HSV", 0, "HSV", "HSV Color Space"}, + {CMP_NODE_CHANNEL_MATTE_CS_YUV, "YUV", 0, "YUV", "YUV Color Space"}, + {CMP_NODE_CHANNEL_MATTE_CS_YCC, "YCC", 0, "YCbCr", "YCbCr Color Space"}, {0, NULL, 0, NULL, NULL}}; prop = RNA_def_property(srna, "color_space", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, color_space_items); RNA_def_property_ui_text(prop, "Color Space", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); - /* TODO: channel must be 1, 2 or 3 */ - prop = RNA_def_property(srna, "channel", PROP_INT, PROP_NONE); - RNA_def_property_int_sdna(prop, NULL, "custom2"); - RNA_def_property_update(prop, 0, "rna_Node_update"); - RNA_def_property_ui_text(prop, "Channel", ""); + + prop= RNA_def_property(srna, "channel", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom2"); + RNA_def_property_enum_items(prop, prop_tri_channel_items); + RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_channel_itemf"); + RNA_def_property_ui_text(prop, "Channel", "Channel used to determine matte"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); RNA_def_struct_sdna_from(srna, "NodeChroma", "storage"); @@ -1132,14 +1366,14 @@ static void def_cmp_channel_matte(StructRNA *srna) RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "High", "Values higher than this setting are 100% opaque"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "low", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "t2"); RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Low", "Values lower than this setting are 100% keyed"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_flip(StructRNA *srna) @@ -1150,7 +1384,7 @@ static void def_cmp_flip(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, node_flip_items); RNA_def_property_ui_text(prop, "Axis", ""); - RNA_def_property_update(prop, 0, "rna_Node_update_name"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_splitviewer(StructRNA *srna) @@ -1166,13 +1400,13 @@ static void def_cmp_splitviewer(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom2"); RNA_def_property_enum_items(prop, axis_items); RNA_def_property_ui_text(prop, "Axis", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "factor", PROP_INT, PROP_FACTOR); RNA_def_property_int_sdna(prop, NULL, "custom1"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Factor", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_id_mask(StructRNA *srna) @@ -1183,7 +1417,7 @@ static void def_cmp_id_mask(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "custom1"); RNA_def_property_range(prop, 0, 10000); RNA_def_property_ui_text(prop, "Index", "Pass index number to convert to alpha"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_map_uv(StructRNA *srna) @@ -1194,7 +1428,7 @@ static void def_cmp_map_uv(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "custom1"); RNA_def_property_range(prop, 0, 100); RNA_def_property_ui_text(prop, "Alpha", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_defocus(StructRNA *srna) @@ -1217,60 +1451,60 @@ static void def_cmp_defocus(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "bktype"); RNA_def_property_enum_items(prop, bokeh_items); RNA_def_property_ui_text(prop, "Bokeh Type", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); /* TODO: angle in degrees */ prop = RNA_def_property(srna, "angle", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "rotation"); RNA_def_property_range(prop, 0, 90); RNA_def_property_ui_text(prop, "Angle", "Bokeh shape rotation offset in degrees"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "gamma_correction", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "gamco", 1); RNA_def_property_ui_text(prop, "Gamma Correction", "Enable gamma correction before and after main process"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); /* TODO */ prop = RNA_def_property(srna, "f_stop", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fstop"); RNA_def_property_range(prop, 0.0f, 128.0f); RNA_def_property_ui_text(prop, "fStop", "Amount of focal blur, 128=infinity=perfect focus, half the value doubles the blur radius"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "max_blur", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "maxblur"); RNA_def_property_range(prop, 0.0f, 10000.0f); RNA_def_property_ui_text(prop, "Max Blur", "blur limit, maximum CoC radius, 0=no limit"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "bthresh"); RNA_def_property_range(prop, 0.0f, 100.0f); RNA_def_property_ui_text(prop, "Threshold", "CoC radius threshold, prevents background bleed on in-focus midground, 0=off"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "preview", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "preview", 1); RNA_def_property_ui_text(prop, "Preview", "Enable sampling mode, useful for preview when using low samplecounts"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "samples", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "samples"); RNA_def_property_range(prop, 16, 256); RNA_def_property_ui_text(prop, "Samples", "Number of samples (16=grainy, higher=less noise)"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "use_zbuffer", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "no_zbuf", 1); RNA_def_property_ui_text(prop, "Use Z-Buffer", "Disable when using an image as input instead of actual zbuffer (auto enabled if node not image based, eg. time node)"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "z_scale", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "scale"); RNA_def_property_range(prop, 0.0f, 1000.0f); RNA_def_property_ui_text(prop, "Z-Scale", "Scales the Z input when not using a zbuffer, controls maximum blur designated by the color white or input value 1"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_invert(StructRNA *srna) @@ -1280,12 +1514,12 @@ static void def_cmp_invert(StructRNA *srna) prop = RNA_def_property(srna, "rgb", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", CMP_CHAN_RGB); RNA_def_property_ui_text(prop, "RGB", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "alpha", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", CMP_CHAN_A); RNA_def_property_ui_text(prop, "Alpha", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_crop(StructRNA *srna) @@ -1295,7 +1529,7 @@ static void def_cmp_crop(StructRNA *srna) prop = RNA_def_property(srna, "crop_size", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1); RNA_def_property_ui_text(prop, "Crop Image Size", "Whether to crop the size of the input image"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); RNA_def_struct_sdna_from(srna, "NodeTwoXYs", "storage"); @@ -1303,25 +1537,25 @@ static void def_cmp_crop(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "x1"); RNA_def_property_range(prop, 0, 10000); RNA_def_property_ui_text(prop, "X1", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "x2", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "x2"); RNA_def_property_range(prop, 0, 10000); RNA_def_property_ui_text(prop, "X2", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "y1", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "y1"); RNA_def_property_range(prop, 0, 10000); RNA_def_property_ui_text(prop, "Y1", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "y2", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "y2"); RNA_def_property_range(prop, 0, 10000); RNA_def_property_ui_text(prop, "Y2", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_dblur(StructRNA *srna) @@ -1334,48 +1568,48 @@ static void def_cmp_dblur(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "iter"); RNA_def_property_range(prop, 1, 32); RNA_def_property_ui_text(prop, "Iterations", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "wrap", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "wrap", 1); RNA_def_property_ui_text(prop, "Wrap", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "center_x", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "center_x"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Center X", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "center_y", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "center_y"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Center Y", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "distance"); RNA_def_property_range(prop, -1.0f, 1.0f); RNA_def_property_ui_text(prop, "Distance", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "angle"); RNA_def_property_range(prop, 0.0f, 360.0f); RNA_def_property_ui_text(prop, "Angle", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "spin", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spin"); RNA_def_property_range(prop, -360.0f, 360.0f); RNA_def_property_ui_text(prop, "Spin", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "zoom", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "zoom"); RNA_def_property_range(prop, 0.0f, 100.0f); RNA_def_property_ui_text(prop, "Zoom", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_bilateral_blur(StructRNA *srna) @@ -1388,19 +1622,19 @@ static void def_cmp_bilateral_blur(StructRNA *srna) RNA_def_property_int_sdna(prop, NULL, "iter"); RNA_def_property_range(prop, 1, 128); RNA_def_property_ui_text(prop, "Iterations", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "sigma_color", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "sigma_color"); RNA_def_property_range(prop, 0.01f, 3.0f); RNA_def_property_ui_text(prop, "Color Sigma", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "sigma_space", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "sigma_space"); RNA_def_property_range(prop, 0.01f, 30.0f); RNA_def_property_ui_text(prop, "Space Sigma", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_premul_key(StructRNA *srna) @@ -1416,7 +1650,7 @@ static void def_cmp_premul_key(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, type_items); RNA_def_property_ui_text(prop, "Mapping", "Conversion between premultiplied alpha and key alpha"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } @@ -1443,66 +1677,66 @@ static void def_cmp_glare(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "type"); RNA_def_property_enum_items(prop, type_items); RNA_def_property_ui_text(prop, "Glare Type", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "quality", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "quality"); RNA_def_property_enum_items(prop, quality_items); RNA_def_property_ui_text(prop, "Quality", "If not set to high quality, the effect will be applied to a low-res copy of the source image"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "iterations", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "iter"); RNA_def_property_range(prop, 2, 5); RNA_def_property_ui_text(prop, "Iterations", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "color_modulation", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "colmod"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Color Modulation", "Amount of Color Modulation, modulates colors of streaks and ghosts for a spectral dispersion effect"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "mix", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "mix"); RNA_def_property_range(prop, -1.0f, 1.0f); RNA_def_property_ui_text(prop, "Mix", "-1 is original image only, 0 is exact 50/50 mix, 1 is processed image only"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "threshold"); RNA_def_property_range(prop, 0.0f, 1000.0f); RNA_def_property_ui_text(prop, "Threshold", "The glare filter will only be applied to pixels brighter than this value"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "streaks", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "angle"); RNA_def_property_range(prop, 2, 16); RNA_def_property_ui_text(prop, "Streaks", "Total number of streaks"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "angle_offset", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "angle_ofs"); RNA_def_property_range(prop, 0.0f, 180.0f); RNA_def_property_ui_text(prop, "Angle Offset", "Streak angle offset in degrees"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "fade", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "fade"); RNA_def_property_range(prop, 0.75f, 1.0f); RNA_def_property_ui_text(prop, "Fade", "Streak fade-out factor"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "rotate_45", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "angle", 1); RNA_def_property_ui_text(prop, "Rotate 45", "Simple star filter: add 45 degree rotation offset"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "size", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "size"); RNA_def_property_range(prop, 6, 9); RNA_def_property_ui_text(prop, "Size", "Glow/glare size (not actual size; relative to initial size of bright area of pixels)"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); /* TODO */ } @@ -1522,49 +1756,49 @@ static void def_cmp_tonemap(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "type"); RNA_def_property_enum_items(prop, type_items); RNA_def_property_ui_text(prop, "Tonemap Type", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "key", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "key"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Key", "The value the average luminance is mapped to"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "offset"); RNA_def_property_range(prop, 0.001f, 10.0f); RNA_def_property_ui_text(prop, "Offset", "Normally always 1, but can be used as an extra control to alter the brightness curve"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "gamma"); RNA_def_property_range(prop, 0.001f, 3.0f); RNA_def_property_ui_text(prop, "Gamma", "If not used, set to 1"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "f"); RNA_def_property_range(prop, -8.0f, 8.0f); RNA_def_property_ui_text(prop, "Intensity", "If less than zero, darkens image; otherwise, makes it brighter"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "contrast", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "m"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Contrast", "Set to 0 to use estimate from input image"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "adaptation", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "a"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Adaptation", "If 0, global; if 1, based on pixel intensity"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "correction", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "c"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Color Correction", "If 0, same for all channels; if 1, each independent"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_lensdist(StructRNA *srna) @@ -1576,17 +1810,17 @@ static void def_cmp_lensdist(StructRNA *srna) prop = RNA_def_property(srna, "projector", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "proj", 1); RNA_def_property_ui_text(prop, "Projector", "Enable/disable projector mode. Effect is applied in horizontal direction only."); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "jitter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "jit", 1); RNA_def_property_ui_text(prop, "Jitter", "Enable/disable jittering; faster, but also noisier"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "fit", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "fit", 1); RNA_def_property_ui_text(prop, "Fit", "For positive distortion factor only: scale image such that black areas are not visible"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } @@ -1602,7 +1836,7 @@ static void def_tex_output(StructRNA *srna) prop = RNA_def_property(srna, "output_name", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "name"); RNA_def_property_ui_text(prop, "Output Name", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_tex_image(StructRNA *srna) @@ -1613,7 +1847,7 @@ static void def_tex_image(StructRNA *srna) RNA_def_property_pointer_sdna(prop, NULL, "storage"); RNA_def_property_struct_type(prop, "ImageUser"); RNA_def_property_ui_text(prop, "Settings", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_tex_bricks(StructRNA *srna) @@ -1624,25 +1858,25 @@ static void def_tex_bricks(StructRNA *srna) RNA_def_property_float_sdna(prop, NULL, "custom3"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Offset Amount", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "offset_frequency", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "custom1"); RNA_def_property_range(prop, 2, 99); RNA_def_property_ui_text(prop, "Offset Frequency", "Offset every N rows"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "squash", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "custom4"); RNA_def_property_range(prop, 0.0f, 99.0f); RNA_def_property_ui_text(prop, "Squash Amount", ""); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "squash_frequency", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "custom2"); RNA_def_property_range(prop, 2, 99); RNA_def_property_ui_text(prop, "Squash Frequency", "Squash every N rows"); - RNA_def_property_update(prop, 0, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } /* -------------------------------------------------------------------------- */ @@ -1703,6 +1937,91 @@ static void rna_def_texture_node(BlenderRNA *brna) /* -------------------------------------------------------------------------- */ +static void rna_def_node_socket(BlenderRNA *brna) +{ + StructRNA *srna; + + srna = RNA_def_struct(brna, "NodeSocket", NULL); + RNA_def_struct_ui_text(srna, "Node Socket", "Input or output socket of a node"); + RNA_def_struct_refine_func(srna, "rna_NodeSocketType_refine"); + RNA_def_struct_sdna(srna, "bNodeSocket"); + RNA_def_struct_ui_icon(srna, ICON_PLUG); + RNA_def_struct_path_func(srna, "rna_NodeSocket_path"); + +} + +static void rna_def_node_socket_value(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "ValueNodeSocket", NULL); + RNA_def_struct_ui_text(srna, "Value Node Socket", "Input or output socket of a node"); + RNA_def_struct_sdna(srna, "bNodeSocket"); + RNA_def_struct_ui_icon(srna, ICON_PLUG); + RNA_def_struct_path_func(srna, "rna_NodeSocket_path"); + + prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Name", "Socket name."); + RNA_def_struct_name_property(srna, prop); + + prop = RNA_def_property(srna, "default_value", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "ns.vec"); + RNA_def_property_array(prop, 1); + RNA_def_property_ui_text(prop, "Default Value", "Default value of the socket when no link is attached."); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update"); + RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocket_defvalue_range"); +} + +static void rna_def_node_socket_vector(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "VectorNodeSocket", NULL); + RNA_def_struct_ui_text(srna, "Vector Node Socket", "Input or output socket of a node"); + RNA_def_struct_sdna(srna, "bNodeSocket"); + RNA_def_struct_ui_icon(srna, ICON_PLUG); + RNA_def_struct_path_func(srna, "rna_NodeSocket_path"); + + prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Name", "Socket name."); + RNA_def_struct_name_property(srna, prop); + + prop = RNA_def_property(srna, "default_value", PROP_FLOAT, PROP_XYZ); + RNA_def_property_float_sdna(prop, NULL, "ns.vec"); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Default Value", "Default value of the socket when no link is attached."); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update"); + RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocket_defvalue_range"); +} + +static void rna_def_node_socket_rgba(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "RGBANodeSocket", NULL); + RNA_def_struct_ui_text(srna, "RGBA Node Socket", "Input or output socket of a node"); + RNA_def_struct_sdna(srna, "bNodeSocket"); + RNA_def_struct_ui_icon(srna, ICON_PLUG); + RNA_def_struct_path_func(srna, "rna_NodeSocket_path"); + + prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Name", "Socket name."); + RNA_def_struct_name_property(srna, prop); + + prop = RNA_def_property(srna, "default_value", PROP_FLOAT, PROP_COLOR); + RNA_def_property_float_sdna(prop, NULL, "ns.vec"); + RNA_def_property_array(prop, 4); + RNA_def_property_ui_text(prop, "Default Value", "Default value of the socket when no link is attached."); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_NodeSocket_update"); + RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocket_defvalue_range"); +} + static void rna_def_node(BlenderRNA *brna) { StructRNA *srna; @@ -1711,6 +2030,7 @@ static void rna_def_node(BlenderRNA *brna) srna = RNA_def_struct(brna, "Node", NULL); RNA_def_struct_ui_text(srna, "Node", "Node in a node tree."); RNA_def_struct_sdna(srna, "bNode"); + RNA_def_struct_ui_icon(srna, ICON_NODE); RNA_def_struct_refine_func(srna, "rna_Node_refine"); RNA_def_struct_path_func(srna, "rna_Node_path"); @@ -1719,10 +2039,22 @@ static void rna_def_node(BlenderRNA *brna) RNA_def_property_array(prop, 2); RNA_def_property_range(prop, -10000.0f, 10000.0f); RNA_def_property_ui_text(prop, "Location", ""); + RNA_def_property_update(prop, NC_NODE, "rna_Node_update"); prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_ui_text(prop, "Name", "Node name."); RNA_def_struct_name_property(srna, prop); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update_name"); + + prop = RNA_def_property(srna, "inputs", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "inputs", NULL); + RNA_def_property_struct_type(prop, "NodeSocket"); + RNA_def_property_ui_text(prop, "Inputs", ""); + + prop = RNA_def_property(srna, "outputs", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "outputs", NULL); + RNA_def_property_struct_type(prop, "NodeSocket"); + RNA_def_property_ui_text(prop, "Outputs", ""); } static void rna_def_nodetree(BlenderRNA *brna) @@ -1733,14 +2065,23 @@ static void rna_def_nodetree(BlenderRNA *brna) srna = RNA_def_struct(brna, "NodeTree", "ID"); RNA_def_struct_ui_text(srna, "Node Tree", "Node tree consisting of linked nodes used for materials, textures and compositing."); RNA_def_struct_sdna(srna, "bNodeTree"); - RNA_def_struct_ui_icon(srna, ICON_NODE); + RNA_def_struct_ui_icon(srna, ICON_NODETREE); + /* AnimData */ rna_def_animdata_common(srna); - + + /* Nodes Collection */ prop = RNA_def_property(srna, "nodes", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "nodes", NULL); RNA_def_property_struct_type(prop, "Node"); RNA_def_property_ui_text(prop, "Nodes", ""); + + /* Grease Pencil */ + prop= RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "gpd"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_struct_type(prop, "GreasePencil"); + RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil datablock"); } static void define_specific_node(BlenderRNA *brna, int id, void (*func)(StructRNA*)) @@ -1755,6 +2096,10 @@ void RNA_def_nodetree(BlenderRNA *brna) { init(); rna_def_nodetree(brna); + rna_def_node_socket(brna); + rna_def_node_socket_value(brna); + rna_def_node_socket_vector(brna); + rna_def_node_socket_rgba(brna); rna_def_node(brna); rna_def_shader_node(brna); rna_def_compositor_node(brna); diff --git a/source/blender/makesrna/intern/rna_nodetree_types.h b/source/blender/makesrna/intern/rna_nodetree_types.h index 69424649b3b..d9a1db996de 100644 --- a/source/blender/makesrna/intern/rna_nodetree_types.h +++ b/source/blender/makesrna/intern/rna_nodetree_types.h @@ -28,7 +28,7 @@ DefNode( ShaderNode, SH_NODE_MATERIAL, def_sh_material, "MATER DefNode( ShaderNode, SH_NODE_RGB, 0, "RGB", RGB, "RGB", "" ) DefNode( ShaderNode, SH_NODE_VALUE, 0, "VALUE", Value, "Value", "" ) DefNode( ShaderNode, SH_NODE_MIX_RGB, def_mix_rgb, "MIX_RGB", MixRGB, "MixRGB", "" ) -DefNode( ShaderNode, SH_NODE_VALTORGB, def_val_to_rgb, "VALTORGB", ValToRGB, "Value to RGB", "" ) +DefNode( ShaderNode, SH_NODE_VALTORGB, def_colorramp, "VALTORGB", ValToRGB, "Value to RGB", "" ) DefNode( ShaderNode, SH_NODE_RGBTOBW, 0, "RGBTOBW", RGBToBW, "RGB to BW", "" ) DefNode( ShaderNode, SH_NODE_TEXTURE, def_texture, "TEXTURE", Texture, "Texture", "" ) DefNode( ShaderNode, SH_NODE_NORMAL, 0, "NORMAL", Normal, "Normal", "" ) @@ -50,7 +50,7 @@ DefNode( CompositorNode, CMP_NODE_VIEWER, 0, "VIEWE DefNode( CompositorNode, CMP_NODE_RGB, 0, "RGB", RGB, "RGB", "" ) DefNode( CompositorNode, CMP_NODE_VALUE, 0, "VALUE", Value, "Value", "" ) DefNode( CompositorNode, CMP_NODE_MIX_RGB, def_mix_rgb, "MIX_RGB", MixRGB, "Mix RGB", "" ) -DefNode( CompositorNode, CMP_NODE_VALTORGB, def_val_to_rgb, "VALTORGB", ValToRGB, "Val to RGB", "" ) +DefNode( CompositorNode, CMP_NODE_VALTORGB, def_colorramp, "VALTORGB", ValToRGB, "Val to RGB", "" ) DefNode( CompositorNode, CMP_NODE_RGBTOBW, 0, "RGBTOBW", RGBToBW, "RGB to BW", "" ) DefNode( CompositorNode, CMP_NODE_NORMAL, 0, "NORMAL", Normal, "Normal", "" ) DefNode( CompositorNode, CMP_NODE_CURVE_VEC, def_vector_curve, "CURVE_VEC", CurveVec, "Vector Curve", "" ) @@ -115,7 +115,7 @@ DefNode( TextureNode, TEX_NODE_BRICKS, def_tex_bricks, "BRICK DefNode( TextureNode, TEX_NODE_MATH, def_math, "MATH", Math, "Math", "" ) DefNode( TextureNode, TEX_NODE_MIX_RGB, def_mix_rgb, "MIX_RGB", MixRGB, "Mix RGB", "" ) DefNode( TextureNode, TEX_NODE_RGBTOBW, 0, "RGBTOBW", RGBToBW, "RGB To BW", "" ) -DefNode( TextureNode, TEX_NODE_VALTORGB, def_val_to_rgb, "VALTORGB", ValToRGB, "Val To RGB", "" ) +DefNode( TextureNode, TEX_NODE_VALTORGB, def_colorramp, "VALTORGB", ValToRGB, "Val To RGB", "" ) DefNode( TextureNode, TEX_NODE_IMAGE, def_tex_image, "IMAGE", Image, "Image", "" ) DefNode( TextureNode, TEX_NODE_CURVE_RGB, def_rgb_curve, "CURVE_RGB", CurveRGB, "RGB Curve", "" ) DefNode( TextureNode, TEX_NODE_INVERT, 0, "INVERT", Invert, "Invert", "" ) diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index a5ec30bd624..652d018c345 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -83,9 +83,10 @@ EnumPropertyItem object_type_items[] = { #ifdef RNA_RUNTIME -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_key_types.h" +#include "DNA_constraint_types.h" #include "BKE_armature.h" #include "BKE_bullet.h" @@ -508,7 +509,7 @@ static void rna_Object_rotation_axis_angle_get(PointerRNA *ptr, float *value) /* for now, assume that rotation mode is axis-angle */ value[0]= ob->rotAngle; - VecCopyf(&value[1], ob->rotAxis); + copy_v3_v3(&value[1], ob->rotAxis); } /* rotation - axis-angle */ @@ -518,7 +519,7 @@ static void rna_Object_rotation_axis_angle_set(PointerRNA *ptr, const float *val /* for now, assume that rotation mode is axis-angle */ ob->rotAngle= value[0]; - VecCopyf(ob->rotAxis, (float *)&value[1]); + copy_v3_v3(ob->rotAxis, (float *)&value[1]); // TODO: validate axis? } @@ -543,7 +544,7 @@ static void rna_Object_dimensions_get(PointerRNA *ptr, float *value) if (bb) { float scale[3]; - Mat4ToSize(ob->obmat, scale); + mat4_to_size( scale,ob->obmat); value[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]); value[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]); @@ -562,7 +563,7 @@ static void rna_Object_dimensions_set(PointerRNA *ptr, const float *value) if (bb) { float scale[3], len[3]; - Mat4ToSize(ob->obmat, scale); + mat4_to_size( scale,ob->obmat); len[0] = bb->vec[4][0] - bb->vec[0][0]; len[1] = bb->vec[2][1] - bb->vec[0][1]; @@ -859,6 +860,30 @@ static PointerRNA rna_Object_collision_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_CollisionSettings, ob->pd); } +static PointerRNA rna_Object_active_constraint_get(PointerRNA *ptr) +{ + Object *ob= (Object*)ptr->id.data; + bConstraint *con; + for(con= ob->constraints.first; con; con= con->next) { + if(con->flag & CONSTRAINT_ACTIVE) + break; + } + + return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con); +} + +static void rna_Object_active_constraint_set(PointerRNA *ptr, PointerRNA value) +{ + Object *ob= (Object*)ptr->id.data; + bConstraint *con; + for(con= ob->constraints.first; con; con= con->next) { + if(value.data==con) + con->flag |= CONSTRAINT_ACTIVE; + else + con->flag &= ~CONSTRAINT_ACTIVE; + } +} + #else static void rna_def_vertex_group(BlenderRNA *brna) @@ -1428,6 +1453,16 @@ static void rna_def_object(BlenderRNA *brna) prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Constraint"); RNA_def_property_ui_text(prop, "Constraints", "Constraints of the object."); + RNA_def_property_collection_funcs(prop, 0, 0, 0, 0, 0, 0, 0, "constraints__add", "constraints__remove"); + + { /* Collection active property */ + PropertyRNA *prop_act= RNA_def_property(srna, "constraints__active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop_act, "Constraint"); + RNA_def_property_pointer_funcs(prop_act, "rna_Object_active_constraint_get", "rna_Object_active_constraint_set", NULL); + RNA_def_property_flag(prop_act, PROP_EDITABLE); + RNA_def_property_ui_text(prop_act, "Active Constraint", "Active Object constraint."); + RNA_def_property_collection_active(prop, prop_act); + } prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Modifier"); @@ -1763,7 +1798,7 @@ static void rna_def_base(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - srna= RNA_def_struct(brna, "Base", NULL); + srna= RNA_def_struct(brna, "ObjectBase", NULL); RNA_def_struct_sdna(srna, "Base"); RNA_def_struct_ui_text(srna, "Object Base", "An objects instance in a scene."); RNA_def_struct_ui_icon(srna, ICON_OBJECT_DATA); diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 098604c1eab..6435102d8e4 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -33,6 +33,7 @@ #include "RNA_define.h" #include "RNA_types.h" +#include "RNA_enum_types.h" #include "DNA_object_types.h" @@ -50,6 +51,7 @@ #include "BKE_mesh.h" #include "BKE_DerivedMesh.h" +#include "BKE_constraint.h" #include "BKE_customdata.h" #include "BKE_anim.h" #include "BKE_depsgraph.h" @@ -57,13 +59,14 @@ #include "BKE_font.h" #include "BKE_mball.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_mesh_types.h" #include "DNA_scene_types.h" #include "DNA_meshdata_types.h" #include "DNA_curve_types.h" #include "DNA_modifier_types.h" +#include "DNA_constraint_types.h" #include "MEM_guardedalloc.h" @@ -349,6 +352,30 @@ static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int } */ +static bConstraint *rna_Object_constraints_add(Object *object, bContext *C, int type) +{ + WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); + return add_ob_constraint(object, NULL, type); +} + +static int rna_Object_constraints_remove(Object *object, bContext *C, int index) +{ + bConstraint *con= BLI_findlink(&object->constraints, index); + + if(con) { + free_constraint_data(con); + BLI_freelinkN(&object->constraints, con); + + ED_object_constraint_set_active(object, NULL); + WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, object); + + return 1; + } + else { + return 0; + } +} + #else void RNA_api_object(StructRNA *srna) @@ -424,6 +451,27 @@ void RNA_api_object(StructRNA *srna) RNA_def_function_flag(func, FUNC_USE_CONTEXT); parm= RNA_def_boolean(func, "is_visible", 0, "", "Object visibility."); RNA_def_function_return(func, parm); + + /* Constraint collection */ + func= RNA_def_function(srna, "constraints__add", "rna_Object_constraints_add"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a constraint to this object"); + /* return type */ + parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "constraints__remove", "rna_Object_constraints_remove"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Remove a constraint from this object."); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); } #endif diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index ad73f279b45..f458ee86091 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -105,7 +105,7 @@ EnumPropertyItem part_hair_ren_as_items[] = { #include "BKE_particle.h" #include "BKE_pointcache.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_listbase.h" /* property update functions */ diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 584c971951a..7199bdaa2f6 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -43,7 +43,7 @@ #include "BIK_api.h" #include "BKE_action.h" #include "BKE_armature.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_userdef_types.h" @@ -163,7 +163,7 @@ static void rna_PoseChannel_rotation_axis_angle_get(PointerRNA *ptr, float *valu /* for now, assume that rotation mode is axis-angle */ value[0]= pchan->rotAngle; - VecCopyf(&value[1], pchan->rotAxis); + copy_v3_v3(&value[1], pchan->rotAxis); } /* rotation - axis-angle */ @@ -173,7 +173,7 @@ static void rna_PoseChannel_rotation_axis_angle_set(PointerRNA *ptr, const float /* for now, assume that rotation mode is axis-angle */ pchan->rotAngle= value[0]; - VecCopyf(pchan->rotAxis, (float *)&value[1]); + copy_v3_v3(pchan->rotAxis, (float *)&value[1]); // TODO: validate axis? } @@ -414,6 +414,32 @@ static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *r } #endif +static PointerRNA rna_PoseChannel_active_constraint_get(PointerRNA *ptr) +{ + bPoseChannel *pchan= (bPoseChannel*)ptr->data; + + bConstraint *con; + for(con= pchan->constraints.first; con; con= con->next) { + if(con->flag & CONSTRAINT_ACTIVE) + break; + } + + return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con); +} + +static void rna_PoseChannel_active_constraint_set(PointerRNA *ptr, PointerRNA value) +{ + bPoseChannel *pchan= (bPoseChannel*)ptr->data; + + bConstraint *con; + for(con= pchan->constraints.first; con; con= con->next) { + if(value.data==con) + con->flag |= CONSTRAINT_ACTIVE; + else + con->flag &= ~CONSTRAINT_ACTIVE; + } +} + #else static void rna_def_bone_group(BlenderRNA *brna) @@ -512,7 +538,17 @@ static void rna_def_pose_channel(BlenderRNA *brna) /* Bone Constraints */ prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Constraint"); - RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel."); + RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel."); + RNA_def_property_collection_funcs(prop, 0, 0, 0, 0, 0, 0, 0, "constraints__add", "constraints__remove"); + + { /* Collection active property */ + PropertyRNA *prop_act= RNA_def_property(srna, "constraints__active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop_act, "Constraint"); + RNA_def_property_pointer_funcs(prop_act, "rna_PoseChannel_active_constraint_get", "rna_PoseChannel_active_constraint_set", NULL); + RNA_def_property_flag(prop_act, PROP_EDITABLE); + RNA_def_property_ui_text(prop_act, "Active Constraint", "Active PoseChannel constraint."); + RNA_def_property_collection_active(prop, prop_act); + } /* Name + Selection Status */ prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); @@ -791,6 +827,8 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface."); RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + + RNA_api_pose_channel(srna); } static void rna_def_pose_itasc(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_pose_api.c b/source/blender/makesrna/intern/rna_pose_api.c index 40bb131b3f9..ae83b728dd6 100644 --- a/source/blender/makesrna/intern/rna_pose_api.c +++ b/source/blender/makesrna/intern/rna_pose_api.c @@ -33,6 +33,7 @@ #include "RNA_define.h" #include "RNA_types.h" +#include "RNA_enum_types.h" #include "DNA_object_types.h" @@ -43,14 +44,71 @@ /* #include "DNA_anim_types.h" */ #include "DNA_action_types.h" /* bPose */ +#include "BKE_constraint.h" /* bPose */ + +static bConstraint *rna_PoseChannel_constraints_add(bPoseChannel *pchan, bContext *C, int type) +{ + //WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); + // TODO, pass object also + // TODO, new pose bones don't have updated draw flags + return add_pose_constraint(NULL, pchan, NULL, type); +} + +static int rna_PoseChannel_constraints_remove(bPoseChannel *pchan, bContext *C, int index) +{ + bConstraint *con= BLI_findlink(&pchan->constraints, index); + + if(con) { + free_constraint_data(con); + BLI_freelinkN(&pchan->constraints, con); + + //ED_object_constraint_set_active(object, NULL); + //WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, object); + + return 1; + } + else { + return 0; + } +} + #else void RNA_api_pose(StructRNA *srna) { /* FunctionRNA *func; */ /* PropertyRNA *parm; */ +} + +void RNA_api_pose_channel(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + + /* Constraint collection */ + func= RNA_def_function(srna, "constraints__add", "rna_PoseChannel_constraints_add"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a constraint to this object"); + /* return type */ + parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "constraints__remove", "rna_PoseChannel_constraints_remove"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Remove a constraint from this object."); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); } + #endif diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 667f88a3a33..4805d6e8156 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -956,13 +956,13 @@ void rna_def_render_layer_common(StructRNA *srna, int scene) prop= RNA_def_property(srna, "pass_reflection", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_REFLECT); - RNA_def_property_ui_text(prop, "Reflection", "Deliver ratraced reflection pass."); + RNA_def_property_ui_text(prop, "Reflection", "Deliver raytraced reflection pass."); if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update"); else RNA_def_property_clear_flag(prop, PROP_EDITABLE); prop= RNA_def_property(srna, "pass_refraction", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_REFRACT); - RNA_def_property_ui_text(prop, "Refraction", "Deliver ratraced refraction pass."); + RNA_def_property_ui_text(prop, "Refraction", "Deliver raytraced refraction pass."); if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update"); else RNA_def_property_clear_flag(prop, PROP_EDITABLE); @@ -986,13 +986,13 @@ void rna_def_render_layer_common(StructRNA *srna, int scene) prop= RNA_def_property(srna, "pass_reflection_exclude", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_REFLECT); - RNA_def_property_ui_text(prop, "Reflection Exclude", "Exclude ratraced reflection pass from combined."); + RNA_def_property_ui_text(prop, "Reflection Exclude", "Exclude raytraced reflection pass from combined."); if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update"); else RNA_def_property_clear_flag(prop, PROP_EDITABLE); prop= RNA_def_property(srna, "pass_refraction_exclude", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_REFRACT); - RNA_def_property_ui_text(prop, "Refraction Exclude", "Exclude ratraced refraction pass from combined."); + RNA_def_property_ui_text(prop, "Refraction Exclude", "Exclude raytraced refraction pass from combined."); if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update"); else RNA_def_property_clear_flag(prop, PROP_EDITABLE); } @@ -2221,15 +2221,15 @@ void RNA_def_scene(BlenderRNA *brna) /* Bases/Objects */ prop= RNA_def_property(srna, "bases", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "base", NULL); - RNA_def_property_struct_type(prop, "Base"); + RNA_def_property_struct_type(prop, "ObjectBase"); RNA_def_property_ui_text(prop, "Bases", ""); { /* Collection active property */ - prop_act= RNA_def_property(srna, "base_active", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop_act, "Base"); + prop_act= RNA_def_property(srna, "bases__active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop_act, "ObjectBase"); RNA_def_property_pointer_sdna(prop_act, NULL, "basact"); RNA_def_property_flag(prop_act, PROP_EDITABLE); - RNA_def_property_ui_text(prop_act, "Active Base", "Active object in the scene."); + RNA_def_property_ui_text(prop_act, "Active Base", "Active object base in the scene."); RNA_def_property_update(prop_act, NC_SCENE|ND_OB_ACTIVE, NULL); RNA_def_property_collection_active(prop, prop_act); } @@ -2241,11 +2241,11 @@ void RNA_def_scene(BlenderRNA *brna) RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Scene_objects_get", 0, 0, 0, 0, 0); { /* Collection active property */ - prop_act= RNA_def_property(srna, "objects_active", PROP_POINTER, PROP_NONE); + prop_act= RNA_def_property(srna, "objects__active", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop_act, "Object"); RNA_def_property_pointer_funcs(prop_act, "rna_Scene_active_object_get", "rna_Scene_active_object_set", NULL); RNA_def_property_flag(prop_act, PROP_EDITABLE); - RNA_def_property_ui_text(prop_act, "Object", "Object to use as projector transform."); + RNA_def_property_ui_text(prop_act, "Active Object", "Active object for this scene."); /* Could call: ED_base_object_activate(C, scene->basact); * but would be a bad level call and it seems the notifier is enough */ RNA_def_property_update(prop_act, NC_SCENE|ND_OB_ACTIVE, NULL); @@ -2287,7 +2287,7 @@ void RNA_def_scene(BlenderRNA *brna) prop= RNA_def_property(srna, "frame_step", PROP_INT, PROP_TIME); RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE); - RNA_def_property_int_sdna(prop, NULL, "frame_step"); + RNA_def_property_int_sdna(prop, NULL, "r.frame_step"); RNA_def_property_range(prop, 0, MAXFRAME); RNA_def_property_ui_range(prop, 0, 100, 1, 0); RNA_def_property_ui_text(prop, "Frame Step", "Number of frames to skip forward while rendering/playing back each frame"); diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index 004c57eedfc..79a5d3d5cd1 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -148,6 +148,16 @@ static void rna_def_region(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "swinid"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Region ID", "Uniqute ID for this region."); + + prop= RNA_def_property(srna, "width", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "winx"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Width", "Region width."); + + prop= RNA_def_property(srna, "height", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "winy"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Height", "Region height."); } static void rna_def_screen(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index cb6671fbe56..c77dabe5e4d 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -265,8 +265,8 @@ static EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *C, P RNA_enum_items_add_value(&item, &totitem, draw_channels_items, 0); if(alpha) { - RNA_enum_items_add_value(&item, &totitem, draw_channels_items, SI_SHOW_ALPHA); RNA_enum_items_add_value(&item, &totitem, draw_channels_items, SI_USE_ALPHA); + RNA_enum_items_add_value(&item, &totitem, draw_channels_items, SI_SHOW_ALPHA); } else if(zbuf) { RNA_enum_items_add_value(&item, &totitem, draw_channels_items, SI_SHOW_ZBUF); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index a54e1b84709..c9056e386ac 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -491,22 +491,22 @@ static void rna_def_userdef_theme_spaces_main(StructRNA *srna, int spacetype) /* window */ prop= RNA_def_property(srna, "back", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Window Back", ""); + RNA_def_property_ui_text(prop, "Window Background", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "title", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Window Title", ""); + RNA_def_property_ui_text(prop, "Title", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "text", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Window Text", ""); + RNA_def_property_ui_text(prop, "Text", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "text_hi", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Window Text Highlight", ""); + RNA_def_property_ui_text(prop, "Text Highlight", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); /* header */ @@ -526,48 +526,48 @@ static void rna_def_userdef_theme_spaces_main(StructRNA *srna, int spacetype) RNA_def_property_update(prop, 0, "rna_userdef_update"); /* buttons */ - if(! ELEM(spacetype, SPACE_BUTS, SPACE_OUTLINER)) { - prop= RNA_def_property(srna, "button", PROP_FLOAT, PROP_COLOR); - RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Button Back", ""); - RNA_def_property_update(prop, 0, "rna_userdef_update"); - - prop= RNA_def_property(srna, "button_title", PROP_FLOAT, PROP_COLOR); - RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Button Title", ""); - RNA_def_property_update(prop, 0, "rna_userdef_update"); - - prop= RNA_def_property(srna, "button_text", PROP_FLOAT, PROP_COLOR); - RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Button Text", ""); - RNA_def_property_update(prop, 0, "rna_userdef_update"); - - prop= RNA_def_property(srna, "button_text_hi", PROP_FLOAT, PROP_COLOR); - RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Button Text Highlight", ""); - RNA_def_property_update(prop, 0, "rna_userdef_update"); - } +// if(! ELEM(spacetype, SPACE_BUTS, SPACE_OUTLINER)) { + prop= RNA_def_property(srna, "button", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Region Background", ""); + RNA_def_property_update(prop, 0, "rna_userdef_update"); + + prop= RNA_def_property(srna, "button_title", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Region Text Titles", ""); + RNA_def_property_update(prop, 0, "rna_userdef_update"); + + prop= RNA_def_property(srna, "button_text", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Region Text", ""); + RNA_def_property_update(prop, 0, "rna_userdef_update"); + + prop= RNA_def_property(srna, "button_text_hi", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Region Text Highlight", ""); + RNA_def_property_update(prop, 0, "rna_userdef_update"); +// } /* list/channels */ if(ELEM5(spacetype, SPACE_IPO, SPACE_ACTION, SPACE_NLA, SPACE_NODE, SPACE_FILE)) { prop= RNA_def_property(srna, "list", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "List Back", ""); + RNA_def_property_ui_text(prop, "Source List", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "list_title", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "List Title", ""); + RNA_def_property_ui_text(prop, "Source List Title", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "list_text", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "List Text", ""); + RNA_def_property_ui_text(prop, "Source List Text", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "list_text_hi", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "List Text Highlight", ""); + RNA_def_property_ui_text(prop, "Source List Text Highlight", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); } } @@ -1369,7 +1369,7 @@ static void rna_def_userdef_theme_space_nla(BlenderRNA *brna) prop= RNA_def_property(srna, "strips", PROP_FLOAT, PROP_COLOR); RNA_def_property_float_sdna(prop, NULL, "strip"); RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "strips", ""); + RNA_def_property_ui_text(prop, "Strips", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); prop= RNA_def_property(srna, "strips_selected", PROP_FLOAT, PROP_COLOR); @@ -1424,21 +1424,22 @@ static void rna_def_userdef_themes(BlenderRNA *brna) static EnumPropertyItem active_theme_group[] = { {0, "USER_INTERFACE", ICON_UI, "User Interface", ""}, - {1, "VIEW_3D", ICON_VIEW3D, "View 3D", ""}, - {2, "GRAPH_EDITOR", ICON_IPO, "Graph Editor", ""}, - {3, "FILE_BROWSER", ICON_FILESEL, "File Browser", ""}, - {4, "NLA_EDITOR", ICON_NLA, "NLA Editor", ""}, - {5, "DOPESHEET_EDITOR", ICON_ACTION, "Dopesheet Editor", ""}, - {6, "IMAGE_EDITOR", ICON_IMAGE_COL, "Image Editor", ""}, - {7, "SEQUENCE_EDITOR", ICON_SEQUENCE, "Sequence Editor", ""}, - {8, "PROPERTIES", ICON_BUTS, "Properties", ""}, - {9, "TEXT_EDITOR", ICON_TEXT, "Text Editor", ""}, - {10, "TIMELINE", ICON_TIME, "Timeline", ""}, - {11, "NODE_EDITOR", ICON_NODE, "Node Editor", ""}, - {12, "LOGIC_EDITOR", ICON_LOGIC, "Logic Editor", ""}, - {13, "OUTLINER", ICON_OOPS, "Outliner", ""}, - {14, "INFO", ICON_INFO, "Info", ""}, - {15, "USER_PREFERENCES", ICON_PREFERENCES, "User Preferences", ""}, + {1, "VIEW_3D", ICON_VIEW3D, "3D View", ""}, + {2, "TIMELINE", ICON_TIME, "Timeline", ""}, + {3, "GRAPH_EDITOR", ICON_IPO, "Graph Editor", ""}, + {4, "DOPESHEET_EDITOR", ICON_ACTION, "Dopesheet", ""}, + {5, "NLA_EDITOR", ICON_NLA, "NLA Editor", ""}, + {6, "IMAGE_EDITOR", ICON_IMAGE_COL, "UV/Image Editor", ""}, + {7, "SEQUENCE_EDITOR", ICON_SEQUENCE, "Video Sequence Editor", ""}, + {8, "TEXT_EDITOR", ICON_TEXT, "Text Editor", ""}, + {9, "NODE_EDITOR", ICON_NODETREE, "Node Editor", ""}, + {10, "LOGIC_EDITOR", ICON_LOGIC, "Logic Editor", ""}, + {11, "PROPERTIES", ICON_BUTS, "Properties", ""}, + {12, "OUTLINER", ICON_OOPS, "Outliner", ""}, + {14, "USER_PREFERENCES", ICON_PREFERENCES, "User Preferences", ""}, + {15, "INFO", ICON_INFO, "Info", ""}, + {16, "FILE_BROWSER", ICON_FILESEL, "File Browser", ""}, + {17, "CONSOLE", ICON_CONSOLE, "Console", ""}, {0, NULL, 0, NULL, NULL}}; srna= RNA_def_struct(brna, "Theme", NULL); diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c b/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c index ac940d76ed6..7b0476229fd 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_channelMatte.c @@ -131,15 +131,15 @@ static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack /*convert to colorspace*/ switch(node->custom1) { - case 1: /*RGB */ + case CMP_NODE_CHANNEL_MATTE_CS_RGB: break; - case 2: /*HSV*/ + case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/ composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_hsva, CB_RGBA); break; - case 3: /*YUV*/ + case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/ composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_rgba_to_yuva, CB_RGBA); break; - case 4: /*YCC*/ + case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/ composit1_pixel_processor(node, outbuf, cbuf, in[1]->vec, do_normalized_rgba_to_ycca2, CB_RGBA); break; default: @@ -151,15 +151,15 @@ static void node_composit_exec_channel_matte(void *data, bNode *node, bNodeStack /*convert back to RGB colorspace in place*/ switch(node->custom1) { - case 1: /*RGB*/ + case CMP_NODE_CHANNEL_MATTE_CS_RGB: /*RGB*/ break; - case 2: /*HSV*/ + case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_hsva_to_rgba, CB_RGBA); break; - case 3: /*YUV*/ + case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_yuva_to_rgba, CB_RGBA); break; - case 4: /*YCC*/ + case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/ composit1_pixel_processor(node, outbuf, outbuf, in[1]->vec, do_normalized_ycca_to_rgba2, CB_RGBA); break; default: diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_levels.c b/source/blender/nodes/intern/CMP_nodes/CMP_levels.c index f0e314793ed..9f845727ddd 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_levels.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_levels.c @@ -50,7 +50,7 @@ static void rgb_tobw(float r, float g, float b, float* out) static void fill_bins(bNode* node, CompBuf* in, int* bins) { float value[4]; - int ivalue; + int ivalue=0; int x,y; /*fill bins */ diff --git a/source/blender/nodes/intern/CMP_util.h b/source/blender/nodes/intern/CMP_util.h index bb08a448bf4..6f37a876169 100644 --- a/source/blender/nodes/intern/CMP_util.h +++ b/source/blender/nodes/intern/CMP_util.h @@ -60,7 +60,7 @@ #include "../CMP_node.h" #include "node_util.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" #include "BLI_threads.h" diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_camera.c b/source/blender/nodes/intern/SHD_nodes/SHD_camera.c index 20136d75540..91dc1c7ceb5 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_camera.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_camera.c @@ -45,7 +45,7 @@ static void node_shader_exec_camera(void *data, bNode *node, bNodeStack **in, bN VECCOPY(out[0]->vec, shi->co); /* get view vector */ out[1]->vec[0]= fabs(shi->co[2]); /* get view z-depth */ - out[2]->vec[0]= Normalize(out[0]->vec); /* get view distance */ + out[2]->vec[0]= normalize_v3(out[0]->vec); /* get view distance */ } } diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_curves.c b/source/blender/nodes/intern/SHD_nodes/SHD_curves.c index d277547b636..c4f1dba57d3 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_curves.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_curves.c @@ -32,6 +32,7 @@ /* **************** CURVE VEC ******************** */ static bNodeSocketType sh_node_curve_vec_in[]= { + { SOCK_VALUE, 0, "Fac", 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}, { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, { -1, 0, "" } }; @@ -47,7 +48,7 @@ static void node_shader_exec_curve_vec(void *data, bNode *node, bNodeStack **in, /* stack order input: vec */ /* stack order output: vec */ - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); + nodestack_get_vec(vec, SOCK_VECTOR, in[1]); curvemapping_evaluate3F(node->storage, out[0]->vec, vec); } @@ -86,6 +87,7 @@ bNodeType sh_node_curve_vec= { /* **************** CURVE RGB ******************** */ static bNodeSocketType sh_node_curve_rgb_in[]= { + { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, { -1, 0, "" } }; @@ -101,8 +103,11 @@ static void node_shader_exec_curve_rgb(void *data, bNode *node, bNodeStack **in, /* stack order input: vec */ /* stack order output: vec */ - nodestack_get_vec(vec, SOCK_VECTOR, in[0]); + nodestack_get_vec(vec, SOCK_VECTOR, in[1]); curvemapping_evaluateRGBF(node->storage, out[0]->vec, vec); + if(in[0]->vec[0] != 1.0f) { + interp_v3_v3v3(out[0]->vec, vec, out[0]->vec, *in[0]->vec); + } } static void node_shader_init_curve_rgb(bNode *node) @@ -114,7 +119,6 @@ static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, { float *array; int size; - curvemapping_table_RGBA(node->storage, &array, &size); return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array)); } diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c b/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c index c081929a2fc..987525f52b6 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c @@ -49,7 +49,7 @@ static void node_shader_exec_mapping(void *data, bNode *node, bNodeStack **in, b /* stack order input: vector */ /* stack order output: vector */ nodestack_get_vec(vec, SOCK_VECTOR, in[0]); - Mat4MulVecfl(texmap->mat, vec); + mul_m4_v3(texmap->mat, vec); if(texmap->flag & TEXMAP_CLIP_MIN) { if(vec[0]<texmap->min[0]) vec[0]= texmap->min[0]; diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_material.c b/source/blender/nodes/intern/SHD_nodes/SHD_material.c index 69c2c0a345c..551958d190d 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_material.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_material.c @@ -101,7 +101,7 @@ static void node_shader_exec_material(void *data, bNode *node, bNodeStack **in, /* retrieve normal */ if(in[MAT_IN_NORMAL]->hasinput) { nodestack_get_vec(shi->vn, SOCK_VECTOR, in[MAT_IN_NORMAL]); - Normalize(shi->vn); + normalize_v3(shi->vn); } else VECCOPY(shi->vn, shi->vno); @@ -138,7 +138,7 @@ static void node_shader_exec_material(void *data, bNode *node, bNodeStack **in, if(node->custom1 & SH_NODE_MAT_DIFF) { VECCOPY(col, shrnode.combined); if(!(node->custom1 & SH_NODE_MAT_SPEC)) { - VecSubf(col, col, shrnode.spec); + sub_v3_v3v3(col, col, shrnode.spec); } } else if(node->custom1 & SH_NODE_MAT_SPEC) { diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c b/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c index 8a73a318f70..b377dbd2e03 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c @@ -70,7 +70,7 @@ static void node_shader_exec_vect_math(void *data, bNode *node, bNodeStack **in, out[0]->vec[1]= vec1[1] + vec2[1]; out[0]->vec[2]= vec1[2] + vec2[2]; - out[1]->vec[0] = Normalize( out[0]->vec ); + out[1]->vec[0] = normalize_v3( out[0]->vec ); } else if(node->custom1 == 3) { /* Dot product */ out[1]->vec[0]= (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]); @@ -80,7 +80,7 @@ static void node_shader_exec_vect_math(void *data, bNode *node, bNodeStack **in, out[0]->vec[1]= (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]); out[0]->vec[2]= (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]); - out[1]->vec[0] = Normalize( out[0]->vec ); + out[1]->vec[0] = normalize_v3( out[0]->vec ); } else if(node->custom1 == 5) { /* Normalize */ if(in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ @@ -94,7 +94,7 @@ static void node_shader_exec_vect_math(void *data, bNode *node, bNodeStack **in, out[0]->vec[2]= vec2[2]; } - out[1]->vec[0] = Normalize( out[0]->vec ); + out[1]->vec[0] = normalize_v3( out[0]->vec ); } } diff --git a/source/blender/nodes/intern/SHD_util.h b/source/blender/nodes/intern/SHD_util.h index a6fe5f4e9cc..76d5eb79490 100644 --- a/source/blender/nodes/intern/SHD_util.h +++ b/source/blender/nodes/intern/SHD_util.h @@ -58,7 +58,7 @@ #include "../SHD_node.h" #include "node_util.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" #include "BLI_threads.h" diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c index 297fc02939d..5355b3f0fff 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_distance.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_distance.c @@ -27,7 +27,7 @@ */ #include <math.h> -#include "BLI_arithb.h" +#include "BLI_math.h" #include "../TEX_util.h" static bNodeSocketType inputs[]= { @@ -48,7 +48,7 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor tex_input_vec(coord1, in[0], p, thread); tex_input_vec(coord2, in[1], p, thread); - *out = VecLenf(coord2, coord1); + *out = len_v3v3(coord2, coord1); } static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) diff --git a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c index 2184d32fcf2..1f550e32135 100644 --- a/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c +++ b/source/blender/nodes/intern/TEX_nodes/TEX_rotate.c @@ -65,19 +65,19 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor if(magsq == 0) magsq = 1; - ndx = Inpf(coord, ax); + ndx = dot_v3v3(coord, ax); para[0] = ax[0] * ndx * (1 - cos_a); para[1] = ax[1] * ndx * (1 - cos_a); para[2] = ax[2] * ndx * (1 - cos_a); - VecSubf(perp, coord, para); + sub_v3_v3v3(perp, coord, para); perp[0] = coord[0] * cos_a; perp[1] = coord[1] * cos_a; perp[2] = coord[2] * cos_a; - Crossf(cp, ax, coord); + cross_v3_v3v3(cp, ax, coord); cp[0] = cp[0] * sin_a; cp[1] = cp[1] * sin_a; diff --git a/source/blender/nodes/intern/TEX_util.h b/source/blender/nodes/intern/TEX_util.h index 14e2773414a..e0bb907b0db 100644 --- a/source/blender/nodes/intern/TEX_util.h +++ b/source/blender/nodes/intern/TEX_util.h @@ -57,7 +57,7 @@ #include "../SHD_node.h" #include "node_util.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" #include "BLI_threads.h" diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index acb45790ed2..e73dec097a3 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -49,6 +49,7 @@ struct bConstraintTarget; /* DNA_constraint_types.h*/ struct Script; /* DNA_screen_types.h */ struct BPyMenu; struct bContext; +struct bContextDataResult; struct ReportList; #ifdef __cplusplus @@ -104,7 +105,7 @@ extern "C" { // int BPY_run_script_space_listener(struct bContext *C, struct SpaceScript * sc, struct ARegion *ar, struct wmNotifier *wmn); // 2.5 working void BPY_update_modules( void ); // XXX - annoying, need this for pointers that get out of date - + int BPY_context_get(struct bContext *C, const char *member, struct bContextDataResult *result); int BPY_run_script(struct Script *script); void BPY_free_compiled_text( struct Text *text ); diff --git a/source/blender/python/generic/Geometry.c b/source/blender/python/generic/Geometry.c index f7b7ee866f0..0d59df6ceca 100644 --- a/source/blender/python/generic/Geometry.c +++ b/source/blender/python/generic/Geometry.c @@ -30,7 +30,7 @@ #include "Geometry.h" /* - Not needed for now though other geometry functions will probably need them -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" */ @@ -42,10 +42,10 @@ #include "BKE_utildefines.h" #include "BKE_curve.h" #include "BLI_boxpack2d.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define SWAP_FLOAT(a,b,tmp) tmp=a; a=b; b=tmp -#define eul 0.000001 +#define eps 0.000001 /*-- forward declarations -- */ static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * polyLineSeq ); @@ -252,18 +252,18 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args ) Py_RETURN_NONE; } /* Make sure the hoz/vert line comes first. */ - if (fabs(b1x - b2x) < eul || fabs(b1y - b2y) < eul) { + if (fabs(b1x - b2x) < eps || fabs(b1y - b2y) < eps) { SWAP_FLOAT(a1x, b1x, xi); /*abuse xi*/ SWAP_FLOAT(a1y, b1y, xi); SWAP_FLOAT(a2x, b2x, xi); SWAP_FLOAT(a2y, b2y, xi); } - if (fabs(a1x-a2x) < eul) { /* verticle line */ - if (fabs(b1x-b2x) < eul){ /*verticle second line */ + if (fabs(a1x-a2x) < eps) { /* verticle line */ + if (fabs(b1x-b2x) < eps){ /*verticle second line */ Py_RETURN_NONE; /* 2 verticle lines dont intersect. */ } - else if (fabs(b1y-b2y) < eul) { + else if (fabs(b1y-b2y) < eps) { /*X of vert, Y of hoz. no calculation needed */ newvec[0]= a1x; newvec[1]= b1y; @@ -280,8 +280,8 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args ) newvec[0]= a1x; newvec[1]= yi; return newVectorObject(newvec, 2, Py_NEW, NULL); - } else if (fabs(a2y-a1y) < eul) { /* hoz line1 */ - if (fabs(b2y-b1y) < eul) { /*hoz line2*/ + } else if (fabs(a2y-a1y) < eps) { /* hoz line1 */ + if (fabs(b2y-b1y) < eps) { /*hoz line2*/ Py_RETURN_NONE; /*2 hoz lines dont intersect*/ } @@ -346,7 +346,7 @@ static PyObject *M_Geometry_ClosestPointOnLine( PyObject * self, PyObject * args else { l2[2]=0.0; VECCOPY2D(l2, line_2->vec) } /* do the calculation */ - lambda = lambda_cp_line_ex(pt_in, l1, l2, pt_out); + lambda = closest_to_line_v3( pt_out,pt_in, l1, l2); ret = PyTuple_New(2); PyTuple_SET_ITEM( ret, 0, newVectorObject(pt_out, 3, Py_NEW, NULL) ); @@ -371,7 +371,7 @@ static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args if(!BaseMath_ReadCallback(pt_vec) || !BaseMath_ReadCallback(tri_p1) || !BaseMath_ReadCallback(tri_p2) || !BaseMath_ReadCallback(tri_p3)) return NULL; - return PyLong_FromLong(IsectPT2Df(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec)); + return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec)); } static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args ) @@ -392,7 +392,7 @@ static PyObject *M_Geometry_PointInQuad2D( PyObject * self, PyObject * args ) if(!BaseMath_ReadCallback(pt_vec) || !BaseMath_ReadCallback(quad_p1) || !BaseMath_ReadCallback(quad_p2) || !BaseMath_ReadCallback(quad_p3) || !BaseMath_ReadCallback(quad_p4)) return NULL; - return PyLong_FromLong(IsectPQ2Df(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec)); + return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec)); } static int boxPack_FromPyObject(PyObject * value, boxPack **boxarray ) diff --git a/source/blender/python/generic/Mathutils.c b/source/blender/python/generic/Mathutils.c index 431f1987383..b44d6450145 100644 --- a/source/blender/python/generic/Mathutils.c +++ b/source/blender/python/generic/Mathutils.c @@ -29,7 +29,7 @@ #include "Mathutils.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "PIL_time.h" #include "BLI_rand.h" #include "BKE_utildefines.h" @@ -437,7 +437,7 @@ static PyObject *M_Mathutils_RotationMatrix(PyObject * self, PyObject * args) mat[8] = 1.0f; } else if((strcmp(axis, "r") == 0) || (strcmp(axis, "R") == 0)) { //arbitrary rotation - AxisAngleToMat3(vec->vec, angle, (float (*)[3])mat); + axis_angle_to_mat3( (float (*)[3])mat,vec->vec, angle); } else { PyErr_SetString(PyExc_AttributeError, "Mathutils.RotationMatrix(): unrecognizable axis of rotation type - expected x,y,z or r\n"); @@ -477,7 +477,7 @@ static PyObject *M_Mathutils_TranslationMatrix(PyObject * self, VectorObject * v return NULL; //create a identity matrix and add translation - Mat4One((float(*)[4]) mat); + unit_m4((float(*)[4]) mat); mat[12] = vec->vec[0]; mat[13] = vec->vec[1]; mat[14] = vec->vec[2]; @@ -762,7 +762,7 @@ static PyObject *M_Mathutils_DifferenceQuats(PyObject * self, PyObject * args) for(x = 0; x < 4; x++) { tempQuat[x] /= (float)(dot * dot); } - QuatMul(quat, tempQuat, quatV->quat); + mul_qt_qtqt(quat, tempQuat, quatV->quat); return newQuaternionObject(quat, Py_NEW, NULL); } //----------------------------------Mathutils.Slerp() ------------------ @@ -853,19 +853,19 @@ static PyObject *M_Mathutils_Intersect( PyObject * self, PyObject * args ) VECCOPY(v3, vec3->vec); VECCOPY(dir, ray->vec); - Normalize(dir); + normalize_v3(dir); VECCOPY(orig, ray_off->vec); /* find vectors for two edges sharing v1 */ - VecSubf(e1, v2, v1); - VecSubf(e2, v3, v1); + sub_v3_v3v3(e1, v2, v1); + sub_v3_v3v3(e2, v3, v1); /* begin calculating determinant - also used to calculated U parameter */ - Crossf(pvec, dir, e2); + cross_v3_v3v3(pvec, dir, e2); /* if determinant is near zero, ray lies in plane of triangle */ - det = Inpf(e1, pvec); + det = dot_v3v3(e1, pvec); if (det > -0.000001 && det < 0.000001) { Py_RETURN_NONE; @@ -874,29 +874,29 @@ static PyObject *M_Mathutils_Intersect( PyObject * self, PyObject * args ) inv_det = 1.0f / det; /* calculate distance from v1 to ray origin */ - VecSubf(tvec, orig, v1); + sub_v3_v3v3(tvec, orig, v1); /* calculate U parameter and test bounds */ - u = Inpf(tvec, pvec) * inv_det; + u = dot_v3v3(tvec, pvec) * inv_det; if (clip && (u < 0.0f || u > 1.0f)) { Py_RETURN_NONE; } /* prepare to test the V parameter */ - Crossf(qvec, tvec, e1); + cross_v3_v3v3(qvec, tvec, e1); /* calculate V parameter and test bounds */ - v = Inpf(dir, qvec) * inv_det; + v = dot_v3v3(dir, qvec) * inv_det; if (clip && (v < 0.0f || u + v > 1.0f)) { Py_RETURN_NONE; } /* calculate t, ray intersects triangle */ - t = Inpf(e2, qvec) * inv_det; + t = dot_v3v3(e2, qvec) * inv_det; - VecMulf(dir, t); - VecAddf(pvec, orig, dir); + mul_v3_fl(dir, t); + add_v3_v3v3(pvec, orig, dir); return newVectorObject(pvec, 3, Py_NEW, NULL); } @@ -947,7 +947,7 @@ static PyObject *M_Mathutils_LineIntersect( PyObject * self, PyObject * args ) v4[2] = 0.0f; } - result = LineIntersectLine(v1, v2, v3, v4, i1, i2); + result = isect_line_line_v3(v1, v2, v3, v4, i1, i2); if (result == 0) { /* colinear */ @@ -1000,22 +1000,22 @@ static PyObject *M_Mathutils_QuadNormal( PyObject * self, PyObject * args ) VECCOPY(v4, vec4->vec); /* find vectors for two edges sharing v2 */ - VecSubf(e1, v1, v2); - VecSubf(e2, v3, v2); + sub_v3_v3v3(e1, v1, v2); + sub_v3_v3v3(e2, v3, v2); - Crossf(n1, e2, e1); - Normalize(n1); + cross_v3_v3v3(n1, e2, e1); + normalize_v3(n1); /* find vectors for two edges sharing v4 */ - VecSubf(e1, v3, v4); - VecSubf(e2, v1, v4); + sub_v3_v3v3(e1, v3, v4); + sub_v3_v3v3(e2, v1, v4); - Crossf(n2, e2, e1); - Normalize(n2); + cross_v3_v3v3(n2, e2, e1); + normalize_v3(n2); /* adding and averaging the normals of both triangles */ - VecAddf(n1, n2, n1); - Normalize(n1); + add_v3_v3v3(n1, n2, n1); + normalize_v3(n1); return newVectorObject(n1, 3, Py_NEW, NULL); } @@ -1047,11 +1047,11 @@ static PyObject *M_Mathutils_TriangleNormal( PyObject * self, PyObject * args ) VECCOPY(v3, vec3->vec); /* find vectors for two edges sharing v2 */ - VecSubf(e1, v1, v2); - VecSubf(e2, v3, v2); + sub_v3_v3v3(e1, v1, v2); + sub_v3_v3v3(e2, v3, v2); - Crossf(n, e2, e1); - Normalize(n); + cross_v3_v3v3(n, e2, e1); + normalize_v3(n); return newVectorObject(n, 3, Py_NEW, NULL); } @@ -1082,7 +1082,7 @@ static PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args ) VECCOPY(v2, vec2->vec); VECCOPY(v3, vec3->vec); - return PyFloat_FromDouble( AreaT3Dfl(v1, v2, v3) ); + return PyFloat_FromDouble( area_tri_v3(v1, v2, v3) ); } else if (vec1->size == 2) { v1[0] = vec1->vec[0]; @@ -1094,7 +1094,7 @@ static PyObject *M_Mathutils_TriangleArea( PyObject * self, PyObject * args ) v3[0] = vec3->vec[0]; v3[1] = vec3->vec[1]; - return PyFloat_FromDouble( AreaF2Dfl(v1, v2, v3) ); + return PyFloat_FromDouble( area_tri_v2(v1, v2, v3) ); } else { PyErr_SetString( PyExc_TypeError, "only 2D,3D vectors are supported\n" ); diff --git a/source/blender/python/generic/euler.c b/source/blender/python/generic/euler.c index 73fcaeb457b..f6f2e337211 100644 --- a/source/blender/python/generic/euler.c +++ b/source/blender/python/generic/euler.c @@ -28,7 +28,7 @@ #include "Mathutils.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" #include "BLI_blenlib.h" @@ -123,9 +123,9 @@ static PyObject *Euler_ToQuat(EulerObject * self) for(x = 0; x < 3; x++) { eul[x] = self->eul[x] * ((float)Py_PI / 180); } - EulToQuat(eul, quat); + eul_to_quat( quat,eul); #else - EulToQuat(self->eul, quat); + eul_to_quat( quat,self->eul); #endif return newQuaternionObject(quat, Py_NEW, NULL); @@ -147,10 +147,10 @@ static PyObject *Euler_ToMatrix(EulerObject * self) for(x = 0; x < 3; x++) { eul[x] = self->eul[x] * ((float)Py_PI / 180); } - EulToMat3(eul, (float (*)[3]) mat); + eul_to_mat3( (float (*)[3]) mat,eul); } #else - EulToMat3(self->eul, (float (*)[3]) mat); + eul_to_mat3( (float (*)[3]) mat,self->eul); #endif return newMatrixObject(mat, 3, 3 , Py_NEW, NULL); } @@ -261,7 +261,7 @@ static PyObject *Euler_Rotate(EulerObject * self, PyObject *args) } } #endif - euler_rot(self->eul, angle, *axis); + rotate_eul(self->eul, *axis, angle); #ifdef USE_MATHUTILS_DEG { diff --git a/source/blender/python/generic/matrix.c b/source/blender/python/generic/matrix.c index 16ae3501b93..a1ef4b53615 100644 --- a/source/blender/python/generic/matrix.c +++ b/source/blender/python/generic/matrix.c @@ -28,7 +28,7 @@ #include "Mathutils.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec); /* utility func */ @@ -229,9 +229,9 @@ static PyObject *Matrix_toQuat(MatrixObject * self) return NULL; } if(self->colSize == 3){ - Mat3ToQuat((float (*)[3])*self->matrix, quat); + mat3_to_quat( quat,(float (*)[3])*self->matrix); }else{ - Mat4ToQuat((float (*)[4])*self->matrix, quat); + mat4_to_quat( quat,(float (*)[4])*self->matrix); } return newQuaternionObject(quat, Py_NEW, NULL); @@ -266,14 +266,14 @@ PyObject *Matrix_toEuler(MatrixObject * self, PyObject *args) /*must be 3-4 cols, 3-4 rows, square matrix*/ if(self->colSize ==3 && self->rowSize ==3) { - if(eul_compat) Mat3ToCompatibleEul((float (*)[3])*self->matrix, eul, eul_compatf); - else Mat3ToEul((float (*)[3])*self->matrix, eul); + if(eul_compat) mat3_to_compatible_eul( eul, eul_compatf,(float (*)[3])*self->matrix); + else mat3_to_eul( eul,(float (*)[3])*self->matrix); }else if (self->colSize ==4 && self->rowSize ==4) { float tempmat3[3][3]; - Mat3CpyMat4(tempmat3, (float (*)[4])*self->matrix); - Mat3ToEul(tempmat3, eul); - if(eul_compat) Mat3ToCompatibleEul(tempmat3, eul, eul_compatf); - else Mat3ToEul(tempmat3, eul); + copy_m3_m4(tempmat3, (float (*)[4])*self->matrix); + mat3_to_eul( eul,tempmat3); + if(eul_compat) mat3_to_compatible_eul( eul, eul_compatf,tempmat3); + else mat3_to_eul( eul,tempmat3); }else { PyErr_SetString(PyExc_AttributeError, "Matrix.toEuler(): inappropriate matrix size - expects 3x3 or 4x4 matrix\n"); @@ -400,18 +400,18 @@ PyObject *Matrix_scalePart(MatrixObject * self) /*must be 3-4 cols, 3-4 rows, square matrix*/ if(self->colSize == 4 && self->rowSize == 4) - Mat3CpyMat4(mat, (float (*)[4])*self->matrix); + copy_m3_m4(mat, (float (*)[4])*self->matrix); else if(self->colSize == 3 && self->rowSize == 3) - Mat3CpyMat3(mat, (float (*)[3])*self->matrix); + copy_m3_m3(mat, (float (*)[3])*self->matrix); else { PyErr_SetString(PyExc_AttributeError, "Matrix.scalePart(): inappropriate matrix size - expects 3x3 or 4x4 matrix\n"); return NULL; } /* functionality copied from editobject.c apply_obmat */ - Mat3ToEul(mat, rot); - EulToMat3(rot, tmat); - Mat3Inv(imat, tmat); - Mat3MulMat3(tmat, imat, mat); + mat3_to_eul( rot,mat); + eul_to_mat3( tmat,rot); + invert_m3_m3(imat, tmat); + mul_m3_m3m3(tmat, imat, mat); scale[0]= tmat[0][0]; scale[1]= tmat[1][1]; @@ -449,9 +449,9 @@ PyObject *Matrix_Invert(MatrixObject * self) mat[2] = -self->matrix[1][0]; mat[3] = self->matrix[0][0]; } else if(self->rowSize == 3) { - Mat3Adj((float (*)[3]) mat,(float (*)[3]) *self->matrix); + adjoint_m3_m3((float (*)[3]) mat,(float (*)[3]) *self->matrix); } else if(self->rowSize == 4) { - Mat4Adj((float (*)[4]) mat, (float (*)[4]) *self->matrix); + adjoint_m4_m4((float (*)[4]) mat, (float (*)[4]) *self->matrix); } /*divide by determinate*/ for(x = 0; x < (self->rowSize * self->colSize); x++) { @@ -491,16 +491,16 @@ PyObject *Matrix_Determinant(MatrixObject * self) } if(self->rowSize == 2) { - det = Det2x2(self->matrix[0][0], self->matrix[0][1], + det = determinant_m2(self->matrix[0][0], self->matrix[0][1], self->matrix[1][0], self->matrix[1][1]); } else if(self->rowSize == 3) { - det = Det3x3(self->matrix[0][0], self->matrix[0][1], + det = determinant_m3(self->matrix[0][0], self->matrix[0][1], self->matrix[0][2], self->matrix[1][0], self->matrix[1][1], self->matrix[1][2], self->matrix[2][0], self->matrix[2][1], self->matrix[2][2]); } else { - det = Det4x4((float (*)[4]) *self->matrix); + det = determinant_m4((float (*)[4]) *self->matrix); } return PyFloat_FromDouble( (double) det ); @@ -523,9 +523,9 @@ PyObject *Matrix_Transpose(MatrixObject * self) self->matrix[1][0] = self->matrix[0][1]; self->matrix[0][1] = t; } else if(self->rowSize == 3) { - Mat3Transp((float (*)[3])*self->matrix); + transpose_m3((float (*)[3])*self->matrix); } else { - Mat4Transp((float (*)[4])*self->matrix); + transpose_m4((float (*)[4])*self->matrix); } BaseMath_WriteCallback(self); @@ -568,9 +568,9 @@ PyObject *Matrix_Identity(MatrixObject * self) self->matrix[1][0] = 0.0f; self->matrix[1][1] = 1.0f; } else if(self->rowSize == 3) { - Mat3One((float (*)[3]) *self->matrix); + unit_m3((float (*)[3]) *self->matrix); } else { - Mat4One((float (*)[4]) *self->matrix); + unit_m4((float (*)[4]) *self->matrix); } if(!BaseMath_WriteCallback(self)) diff --git a/source/blender/python/generic/quat.c b/source/blender/python/generic/quat.c index 7e12fe7925a..2ee78235224 100644 --- a/source/blender/python/generic/quat.c +++ b/source/blender/python/generic/quat.c @@ -28,7 +28,7 @@ #include "Mathutils.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" #include "BLI_blenlib.h" @@ -152,9 +152,9 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw if(size == 3) //calculate the quat based on axis/angle #ifdef USE_MATHUTILS_DEG - AxisAngleToQuat(quat, quat, angle * (Py_PI / 180)); + axis_angle_to_quat(quat, quat, angle * (Py_PI / 180)); #else - AxisAngleToQuat(quat, quat, angle); + axis_angle_to_quat(quat, quat, angle); #endif return newQuaternionObject(quat, Py_NEW, NULL); @@ -180,7 +180,7 @@ static PyObject *Quaternion_ToEuler(QuaternionObject * self, PyObject *args) if(!BaseMath_ReadCallback(eul_compat)) return NULL; - QuatToMat3(self->quat, mat); + quat_to_mat3( mat,self->quat); #ifdef USE_MATHUTILS_DEG { @@ -190,14 +190,14 @@ static PyObject *Quaternion_ToEuler(QuaternionObject * self, PyObject *args) for(x = 0; x < 3; x++) { eul_compatf[x] = eul_compat->eul[x] * ((float)Py_PI / 180); } - Mat3ToCompatibleEul(mat, eul, eul_compatf); + mat3_to_compatible_eul( eul, eul_compatf,mat); } #else - Mat3ToCompatibleEul(mat, eul, eul_compat->eul); + mat3_to_compatible_eul( eul, eul_compat->eul,mat); #endif } else { - QuatToEul(self->quat, eul); + quat_to_eul( eul,self->quat); } #ifdef USE_MATHUTILS_DEG @@ -220,7 +220,7 @@ static PyObject *Quaternion_ToMatrix(QuaternionObject * self) if(!BaseMath_ReadCallback(self)) return NULL; - QuatToMat3(self->quat, (float (*)[3]) mat); + quat_to_mat3( (float (*)[3]) mat,self->quat); return newMatrixObject(mat, 3, 3, Py_NEW, NULL); } @@ -238,7 +238,7 @@ static PyObject *Quaternion_Cross(QuaternionObject * self, QuaternionObject * va if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value)) return NULL; - QuatMul(quat, self->quat, value->quat); + mul_qt_qtqt(quat, self->quat, value->quat); return newQuaternionObject(quat, Py_NEW, NULL); } @@ -254,7 +254,7 @@ static PyObject *Quaternion_Dot(QuaternionObject * self, QuaternionObject * valu if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value)) return NULL; - return PyFloat_FromDouble(QuatDot(self->quat, value->quat)); + return PyFloat_FromDouble(dot_qtqt(self->quat, value->quat)); } //----------------------------Quaternion.normalize()---------------- @@ -264,7 +264,7 @@ static PyObject *Quaternion_Normalize(QuaternionObject * self) if(!BaseMath_ReadCallback(self)) return NULL; - NormalQuat(self->quat); + normalize_qt(self->quat); BaseMath_WriteCallback(self); Py_INCREF(self); @@ -277,7 +277,7 @@ static PyObject *Quaternion_Inverse(QuaternionObject * self) if(!BaseMath_ReadCallback(self)) return NULL; - QuatInv(self->quat); + invert_qt(self->quat); BaseMath_WriteCallback(self); Py_INCREF(self); @@ -290,7 +290,7 @@ static PyObject *Quaternion_Identity(QuaternionObject * self) if(!BaseMath_ReadCallback(self)) return NULL; - QuatOne(self->quat); + unit_qt(self->quat); BaseMath_WriteCallback(self); Py_INCREF(self); @@ -303,7 +303,7 @@ static PyObject *Quaternion_Negate(QuaternionObject * self) if(!BaseMath_ReadCallback(self)) return NULL; - QuatMulf(self->quat, -1.0f); + mul_qt_fl(self->quat, -1.0f); BaseMath_WriteCallback(self); Py_INCREF(self); @@ -316,7 +316,7 @@ static PyObject *Quaternion_Conjugate(QuaternionObject * self) if(!BaseMath_ReadCallback(self)) return NULL; - QuatConj(self->quat); + conjugate_qt(self->quat); BaseMath_WriteCallback(self); Py_INCREF(self); @@ -525,7 +525,7 @@ static PyObject *Quaternion_add(PyObject * q1, PyObject * q2) if(!BaseMath_ReadCallback(quat1) || !BaseMath_ReadCallback(quat2)) return NULL; - QuatAdd(quat, quat1->quat, quat2->quat, 1.0f); + add_qt_qtqt(quat, quat1->quat, quat2->quat, 1.0f); return newQuaternionObject(quat, Py_NEW, NULL); } //------------------------obj - obj------------------------------ @@ -573,7 +573,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2) } if(quat1 && quat2) { /* QUAT*QUAT (dot product) */ - return PyFloat_FromDouble(QuatDot(quat1->quat, quat2->quat)); + return PyFloat_FromDouble(dot_qtqt(quat1->quat, quat2->quat)); } /* the only case this can happen (for a supported type is "FLOAT*QUAT" ) */ @@ -581,7 +581,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2) scalar= PyFloat_AsDouble(q1); if ((scalar == -1.0 && PyErr_Occurred())==0) { /* FLOAT*QUAT */ QUATCOPY(quat, quat2->quat); - QuatMulf(quat, scalar); + mul_qt_fl(quat, scalar); return newQuaternionObject(quat, Py_NEW, NULL); } PyErr_SetString(PyExc_TypeError, "Quaternion multiplication: val * quat, val is not an acceptable type"); @@ -600,7 +600,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2) scalar= PyFloat_AsDouble(q2); if ((scalar == -1.0 && PyErr_Occurred())==0) { /* QUAT*FLOAT */ QUATCOPY(quat, quat1->quat); - QuatMulf(quat, scalar); + mul_qt_fl(quat, scalar); return newQuaternionObject(quat, Py_NEW, NULL); } } @@ -669,7 +669,7 @@ static int Quaternion_setAxis( QuaternionObject * self, PyObject * value, void * static PyObject *Quaternion_getMagnitude( QuaternionObject * self, void *type ) { - return PyFloat_FromDouble(sqrt(QuatDot(self->quat, self->quat))); + return PyFloat_FromDouble(sqrt(dot_qtqt(self->quat, self->quat))); } static PyObject *Quaternion_getAngle( QuaternionObject * self, void *type ) @@ -692,7 +692,7 @@ static PyObject *Quaternion_getAxisVec( QuaternionObject * self, void *type ) for(i = 0; i < 3; i++) vec[i] = (float)(self->quat[i + 1] / mag); - Normalize(vec); + normalize_v3(vec); //If the axis of rotation is 0,0,0 set it to 1,0,0 - for zero-degree rotations if( EXPP_FloatsAreEqual(vec[0], 0.0f, 10) && EXPP_FloatsAreEqual(vec[1], 0.0f, 10) && @@ -820,7 +820,7 @@ PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type) }else if (type == Py_NEW){ self->quat = PyMem_Malloc(4 * sizeof(float)); if(!quat) { //new empty - QuatOne(self->quat); + unit_qt(self->quat); }else{ QUATCOPY(self->quat, quat); } diff --git a/source/blender/python/generic/vector.c b/source/blender/python/generic/vector.c index 0ce7b83e653..8d1356f62f4 100644 --- a/source/blender/python/generic/vector.c +++ b/source/blender/python/generic/vector.c @@ -29,7 +29,7 @@ #include "BLI_blenlib.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define MAX_DIMENSIONS 4 /* Swizzle axes get packed into a single value that is used as a closure. Each @@ -347,7 +347,7 @@ static PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args ) vec[1] = -self->vec[1]; vec[2] = -self->vec[2]; - vectoquat(vec, track, up, quat); + vec_to_quat( quat,vec, track, up); return newQuaternionObject(quat, Py_NEW, NULL); } @@ -379,7 +379,7 @@ static PyObject *Vector_Reflect( VectorObject * self, VectorObject * value ) if (self->size > 2) vec[2] = self->vec[2]; else vec[2] = 0.0; - VecReflect(reflect, vec, mirror); + reflect_v3_v3v3(reflect, vec, mirror); return newVectorObject(reflect, self->size, Py_NEW, NULL); } @@ -402,7 +402,7 @@ static PyObject *Vector_Cross( VectorObject * self, VectorObject * value ) return NULL; vecCross = (VectorObject *)newVectorObject(NULL, 3, Py_NEW, NULL); - Crossf(vecCross->vec, self->vec, value->vec); + cross_v3_v3v3(vecCross->vec, self->vec, value->vec); return (PyObject *)vecCross; } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index e67df5db096..47505f478af 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -64,6 +64,7 @@ #include "BKE_fcurve.h" #include "BKE_text.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BPY_extern.h" @@ -176,35 +177,35 @@ static void bpy_init_modules( void ) { PyObject *mod; - mod = PyModule_New("bpy"); + /* Needs to be first since this dir is needed for future modules */ + char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL); + if(modpath) { + PyObject *sys_path= PySys_GetObject("path"); /* borrow */ + PyObject *py_modpath= PyUnicode_FromString(modpath); + PyList_Insert(sys_path, 0, py_modpath); /* add first */ + Py_DECREF(py_modpath); + } - PyModule_AddObject( mod, "data", BPY_rna_module() ); + mod = PyModule_New("bpy"); + + /* add the module so we can import it */ + PyDict_SetItemString(PySys_GetObject("modules"), "bpy", mod); + Py_DECREF(mod); + + /* run first, initializes rna types */ + BPY_rna_init(); + + PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */ + bpy_import_test("bpy_types"); + PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */ + bpy_import_test("bpy_types"); /* PyModule_AddObject( mod, "doc", BPY_rna_doc() ); */ - PyModule_AddObject( mod, "types", BPY_rna_types() ); PyModule_AddObject( mod, "props", BPY_rna_props() ); PyModule_AddObject( mod, "__ops__", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */ PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experimental, consider this a test, especially PyCObject is not meant to be permanent - - /* add the module so we can import it */ - PyDict_SetItemString(PySys_GetObject("modules"), "bpy", mod); - Py_DECREF(mod); - /* add our own modules dir */ - { - char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL); - - if(modpath) { - PyObject *sys_path= PySys_GetObject("path"); /* borrow */ - PyObject *py_modpath= PyUnicode_FromString(modpath); - PyList_Insert(sys_path, 0, py_modpath); /* add first */ - Py_DECREF(py_modpath); - } - - bpy_import_test("bpy_ops"); /* adds its self to bpy.ops */ - bpy_import_test("bpy_utils"); /* adds its self to bpy.sys */ - bpy_import_test("bpy_ext"); /* extensions to our existing types */ - } - + + /* bpy context */ { bpy_context_module= ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type ); @@ -213,11 +214,16 @@ static void bpy_init_modules( void ) PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module); } - /* stand alone utility modules not related to blender directly */ Geometry_Init(); Mathutils_Init(); BGL_Init(); + + /* add our own modules dir */ + { + bpy_import_test("bpy_ops"); /* adds its self to bpy.ops */ + bpy_import_test("bpy_utils"); /* adds its self to bpy.sys */ + } } void BPY_update_modules( void ) @@ -411,24 +417,32 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict ); } else { -#if 0 - char *pystring; - pystring= malloc(strlen(fn) + 32); - pystring[0]= '\0'; - sprintf(pystring, "exec(open(r'%s').read())", fn); - py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict ); - free(pystring); -#else FILE *fp= fopen(fn, "r"); if(fp) { +#ifdef _WIN32 + /* Previously we used PyRun_File to run directly the code on a FILE + * object, but as written in the Python/C API Ref Manual, chapter 2, + * 'FILE structs for different C libraries can be different and + * incompatible'. + * So now we load the script file data to a buffer */ + char *pystring; + + fclose(fp); + + pystring= malloc(strlen(fn) + 32); + pystring[0]= '\0'; + sprintf(pystring, "exec(open(r'%s').read())", fn); + py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict ); + free(pystring); +#else py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict); fclose(fp); +#endif } else { PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno)); py_result= NULL; } -#endif } if (!py_result) { @@ -961,7 +975,7 @@ int BPY_button_eval(bContext *C, char *expr, double *value) -int bpy_context_get(bContext *C, const char *member, bContextDataResult *result) +int BPY_context_get(bContext *C, const char *member, bContextDataResult *result) { PyObject *pyctx= (PyObject *)CTX_py_dict_get(C); PyObject *item= PyDict_GetItemString(pyctx, member); @@ -1014,8 +1028,11 @@ int bpy_context_get(bContext *C, const char *member, bContextDataResult *result) } if(done==0) { - if (item) printf("Context '%s' not found\n", member); - else printf("Context '%s' not a valid type\n", member); + if (item) printf("Context '%s' not a valid type\n", member); + else printf("Context '%s' not found\n", member); + } + else if (G.f & G_DEBUG) { + printf("Context '%s' found\n", member); } return done; diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 1ae0a40ce16..b1577969a22 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -153,7 +153,7 @@ static PyObject *pyop_as_string( PyObject * self, PyObject * args) int all_args = 1; int error_val= 0; - char *buf; + char *buf = NULL; PyObject *pybuf; bContext *C = BPy_GetContext(); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index f96c2b49b92..3dcb47a0905 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -320,8 +320,11 @@ static void pyrna_struct_dealloc( BPy_StructRNA * self ) { if (self->freeptr && self->ptr.data) { IDP_FreeProperty(self->ptr.data); - MEM_freeN(self->ptr.data); - self->ptr.data= NULL; + if (self->ptr.type != &RNA_Context) + { + MEM_freeN(self->ptr.data); + self->ptr.data= NULL; + } } /* Note, for subclassed PyObjects we cant just call PyObject_DEL() directly or it will crash */ @@ -516,7 +519,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw); -PyObject *pyrna_func_to_py(BPy_StructRNA *pyrna, FunctionRNA *func) +PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func) { static PyMethodDef func_meth = {"<generic rna function>", (PyCFunction)pyrna_func_call, METH_VARARGS|METH_KEYWORDS, "python rna function"}; PyObject *self; @@ -592,7 +595,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v case PROP_INT: { int param = PyLong_AsSsize_t(value); - if (PyErr_Occurred()) { + if (param==-1 && PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "%.200s expected an int type", error_prefix); return -1; } else { @@ -813,7 +816,7 @@ static int pyrna_py_to_prop_index(BPy_PropertyRNA *self, int index, PyObject *va case PROP_INT: { int param = PyLong_AsSsize_t(value); - if (PyErr_Occurred()) { + if (param==-1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "expected an int type"); ret = -1; } else { @@ -1303,10 +1306,11 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self) nameptr= RNA_struct_name_get_alloc(&itemptr, name, sizeof(name)); if(nameptr) { - pystring = PyUnicode_FromString(nameptr); - PyList_Append(ret, pystring); - Py_DECREF(pystring); - + if(strstr(nameptr, "__")==NULL) { /* __ for hidden props, used for active object for eg. */ + pystring = PyUnicode_FromString(nameptr); + PyList_Append(ret, pystring); + Py_DECREF(pystring); + } if(name != nameptr) MEM_freeN(nameptr); } @@ -1320,14 +1324,19 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self) * Collect RNA function items */ PointerRNA tptr; + const char *idname; RNA_pointer_create(NULL, &RNA_Struct, self->ptr.type, &tptr); iterprop= RNA_struct_find_property(&tptr, "functions"); RNA_PROP_BEGIN(&tptr, itemptr, iterprop) { - pystring = PyUnicode_FromString(RNA_function_identifier(itemptr.data)); - PyList_Append(ret, pystring); - Py_DECREF(pystring); + idname= RNA_function_identifier(itemptr.data); + + if(strstr(idname, "__")==NULL) { /* __ for hidden function members, used for collection add/remove for eg. */ + pystring = PyUnicode_FromString(idname); + PyList_Append(ret, pystring); + Py_DECREF(pystring); + } } RNA_PROP_END; } @@ -1346,7 +1355,7 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self) } /* Hard coded names */ - { + if(self->ptr.id.data) { pystring = PyUnicode_FromString("id_data"); PyList_Append(ret, pystring); Py_DECREF(pystring); @@ -1364,46 +1373,47 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA * self, PyObject *pyname ) PropertyRNA *prop; FunctionRNA *func; - /* Include this incase this instance is a subtype of a python class - * In these instances we may want to return a function or variable provided by the subtype - * - * Also needed to return methods when its not a subtype - * */ - ret = PyObject_GenericGetAttr((PyObject *)self, pyname); - if (ret) return ret; - else PyErr_Clear(); - /* done with subtypes */ - if ((prop = RNA_struct_find_property(&self->ptr, name))) { ret = pyrna_prop_to_py(&self->ptr, prop); } else if ((func = RNA_struct_find_function(&self->ptr, name))) { - ret = pyrna_func_to_py(self, func); + ret = pyrna_func_to_py((BPy_DummyPointerRNA *)self, func); } else if (self->ptr.type == &RNA_Context) { PointerRNA newptr; ListBase newlb; + int done; - CTX_data_get(self->ptr.data, name, &newptr, &newlb); + done= CTX_data_get(self->ptr.data, name, &newptr, &newlb); - if (newptr.data) { - ret = pyrna_struct_CreatePyObject(&newptr); - } - else if (newlb.first) { - CollectionPointerLink *link; - PyObject *linkptr; + if(done==1) { /* found */ + if (newptr.data) { + ret = pyrna_struct_CreatePyObject(&newptr); + } + else if (newlb.first) { + CollectionPointerLink *link; + PyObject *linkptr; - ret = PyList_New(0); + ret = PyList_New(0); - for(link=newlb.first; link; link=link->next) { - linkptr= pyrna_struct_CreatePyObject(&link->ptr); - PyList_Append(ret, linkptr); - Py_DECREF(linkptr); + for(link=newlb.first; link; link=link->next) { + linkptr= pyrna_struct_CreatePyObject(&link->ptr); + PyList_Append(ret, linkptr); + Py_DECREF(linkptr); + } } + else { + ret = Py_None; + Py_INCREF(ret); + } + } + else if (done==-1) { /* found but not set */ + ret = Py_None; + Py_INCREF(ret); } - else { - ret = Py_None; - Py_INCREF(ret); + else { /* not found in the context */ + /* lookup the subclass. raise an error if its not found */ + ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } BLI_freelistN(&newlb); @@ -1412,15 +1422,26 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA * self, PyObject *pyname ) if(self->ptr.id.data) { PointerRNA id_ptr; RNA_id_pointer_create((ID *)self->ptr.id.data, &id_ptr); - return pyrna_struct_CreatePyObject(&id_ptr); + ret = pyrna_struct_CreatePyObject(&id_ptr); } else { - Py_RETURN_NONE; + ret = Py_None; + Py_INCREF(ret); } } else { +#if 0 PyErr_Format( PyExc_AttributeError, "StructRNA - Attribute \"%.200s\" not found", name); ret = NULL; +#endif + /* Include this incase this instance is a subtype of a python class + * In these instances we may want to return a function or variable provided by the subtype + * + * Also needed to return methods when its not a subtype + * */ + + /* The error raised here will be displayed */ + ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } return ret; @@ -1455,54 +1476,130 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "StructRNA - Attribute (setattr):"); } -static PyObject *pyrna_prop_getattro( BPy_PropertyRNA * self, PyObject *pyname ) +static PyObject *pyrna_prop_get_active( BPy_PropertyRNA * self ) { - char *name = _PyUnicode_AsString(pyname); + PropertyRNA *prop_act; - if(strcmp(name, "active")==0) { - PropertyRNA *prop_act; + if (RNA_property_type(self->prop) != PROP_COLLECTION) { + PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not a collection"); + return NULL; + } - if (RNA_property_type(self->prop) != PROP_COLLECTION) { - PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not a collection"); - return NULL; - } + prop_act= RNA_property_collection_active(self->prop); + if (prop_act==NULL) { + PyErr_SetString( PyExc_TypeError, "collection has no active"); + return NULL; + } - prop_act= RNA_property_collection_active(self->prop); - if (prop_act==NULL) { - PyErr_SetString( PyExc_TypeError, "collection has no active"); - return NULL; - } + return pyrna_prop_to_py(&self->ptr, prop_act); +} + +static int pyrna_prop_set_active( BPy_PropertyRNA * self, PyObject * value ) +{ + PropertyRNA *prop_act; - return pyrna_prop_to_py(&self->ptr, prop_act); + if (RNA_property_type(self->prop) != PROP_COLLECTION) { + PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not a collection"); + return -1; } - return PyObject_GenericGetAttr((PyObject *)self, pyname); + prop_act= RNA_property_collection_active(self->prop); + if (prop_act==NULL) { + PyErr_SetString( PyExc_TypeError, "collection has no active"); + return -1; + } + + return pyrna_py_to_prop(&self->ptr, prop_act, NULL, value, "StructRNA - Attribute (setattr):"); } -//--------------- setattr------------------------------------------- -static int pyrna_prop_setattro( BPy_PropertyRNA * self, PyObject *pyname, PyObject * value ) +/* odd case, we need to be able return a python method from a tp_getset */ +static PyObject *pyrna_prop_add(BPy_PropertyRNA *self); +static PyMethodDef pyrna_prop_add_meth[] = {{"add", (PyCFunction)pyrna_prop_add, METH_NOARGS, NULL}}; +static PyObject *pyrna_prop_add(BPy_PropertyRNA *self) { - char *name = _PyUnicode_AsString(pyname); - if(strcmp(name, "active")==0) { - PropertyRNA *prop_act; + PointerRNA r_ptr; - if (RNA_property_type(self->prop) != PROP_COLLECTION) { - PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA object is not a collection"); - return -1; - } + RNA_property_collection_add(&self->ptr, self->prop, &r_ptr); + if(!r_ptr.data) { + PyErr_SetString( PyExc_TypeError, "add() not supported for this collection"); + return NULL; + } + else { + return pyrna_struct_CreatePyObject(&r_ptr); + } +} - prop_act= RNA_property_collection_active(self->prop); - if (prop_act==NULL) { - PyErr_SetString( PyExc_TypeError, "collection has no active"); - return -1; + +static PyObject *pyrna_prop_remove(BPy_PropertyRNA *self, PyObject *value); +static PyMethodDef pyrna_prop_remove_meth[] = {{"remove", (PyCFunction)pyrna_prop_remove, METH_O, NULL}}; +static PyObject *pyrna_prop_remove(BPy_PropertyRNA *self, PyObject *value) +{ + PyObject *ret; + int key= PyLong_AsSsize_t(value); + + if (key==-1 && PyErr_Occurred()) { + PyErr_SetString( PyExc_TypeError, "remove() expected one int argument"); + return NULL; + } + + if(!RNA_property_collection_remove(&self->ptr, self->prop, key)) { + PyErr_SetString( PyExc_TypeError, "remove() not supported for this collection"); + return NULL; + } + + ret = Py_None; + Py_INCREF(ret); + + return ret; +} + +static PyObject *pyrna_prop_get_add_func( BPy_PropertyRNA * self ) +{ + FunctionRNA *func; + + if (RNA_property_type(self->prop) == PROP_COLLECTION) { + func = RNA_property_collection_add_func(self->prop); + if (func==NULL) { + PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA collection has no add() function"); + return NULL; } - return pyrna_py_to_prop(&self->ptr, prop_act, NULL, value, "StructRNA - Attribute (setattr):"); + return pyrna_func_to_py((BPy_DummyPointerRNA *)self, func); } + else { + return PyCFunction_New(pyrna_prop_add_meth, (PyObject *)self); + } +} - return PyObject_GenericSetAttr((PyObject *)self, pyname, value); +static PyObject *pyrna_prop_get_remove_func( BPy_PropertyRNA * self ) +{ + FunctionRNA *func; + + if (RNA_property_type(self->prop) == PROP_COLLECTION) { + func = RNA_property_collection_remove_func(self->prop); + if (func==NULL) { + PyErr_SetString( PyExc_TypeError, "this BPy_PropertyRNA collection has no add() function"); + return NULL; + } + + return pyrna_func_to_py((BPy_DummyPointerRNA *)self, func); + } + else { + return PyCFunction_New(pyrna_prop_remove_meth, (PyObject *)self); + } } +/*****************************************************************************/ +/* Python attributes get/set structure: */ +/*****************************************************************************/ +static PyGetSetDef pyrna_prop_getseters[] = { + {"active", (getter)pyrna_prop_get_active, (setter)pyrna_prop_set_active, "", NULL}, + /* rna functions */ + {"add", (getter)pyrna_prop_get_add_func, NULL, "", NULL}, + {"remove", (getter)pyrna_prop_get_remove_func, NULL, "", NULL}, + {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ +}; + static PyObject *pyrna_prop_keys(BPy_PropertyRNA *self) { PyObject *ret; @@ -1615,40 +1712,6 @@ static PyObject *pyrna_prop_get(BPy_PropertyRNA *self, PyObject *args) return def; } - -static PyObject *pyrna_prop_add(BPy_PropertyRNA *self, PyObject *args) -{ - PointerRNA newptr; - - RNA_property_collection_add(&self->ptr, self->prop, &newptr); - if(!newptr.data) { - PyErr_SetString( PyExc_TypeError, "add() not supported for this collection"); - return NULL; - } - else { - return pyrna_struct_CreatePyObject(&newptr); - } -} - -static PyObject *pyrna_prop_remove(BPy_PropertyRNA *self, PyObject *args) -{ - PyObject *ret; - int key= 0; - - if (!PyArg_ParseTuple(args, "i:remove", &key)) - return NULL; - - if(!RNA_property_collection_remove(&self->ptr, self->prop, key)) { - PyErr_SetString( PyExc_TypeError, "remove() not supported for this collection"); - return NULL; - } - - ret = Py_None; - Py_INCREF(ret); - - return ret; -} - static void foreach_attr_type( BPy_PropertyRNA *self, char *attr, /* values to assign */ RawPropertyType *raw_type, int *attr_tot, int *attr_signed ) @@ -1742,7 +1805,7 @@ static int foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, cons static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) { PyObject *item = NULL; - int i=0, ok, buffer_is_compat; + int i=0, ok=0, buffer_is_compat; void *array= NULL; /* get/set both take the same args currently */ @@ -1936,8 +1999,11 @@ static struct PyMethodDef pyrna_prop_methods[] = { {"get", (PyCFunction)pyrna_prop_get, METH_VARARGS, NULL}, - {"add", (PyCFunction)pyrna_prop_add, METH_VARARGS, NULL}, - {"remove", (PyCFunction)pyrna_prop_remove, METH_VARARGS, NULL}, + /* moved into a getset */ +#if 0 + {"add", (PyCFunction)pyrna_prop_add, METH_NOARGS, NULL}, + {"remove", (PyCFunction)pyrna_prop_remove, METH_O, NULL}, +#endif /* array accessor function */ {"foreach_get", (PyCFunction)pyrna_prop_foreach_get, METH_VARARGS, NULL}, @@ -2108,7 +2174,8 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw) { - PointerRNA *self_ptr= &(((BPy_StructRNA *)PyTuple_GET_ITEM(self, 0))->ptr); + /* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */ + PointerRNA *self_ptr= &(((BPy_DummyPointerRNA *)PyTuple_GET_ITEM(self, 0))->ptr); FunctionRNA *self_func= PyCObject_AsVoidPtr(PyTuple_GET_ITEM(self, 1)); PointerRNA funcptr; @@ -2414,8 +2481,8 @@ PyTypeObject pyrna_prop_Type = { NULL, /* reprfunc tp_str; */ /* will only use these if this is a subtype of a py class */ - ( getattrofunc ) pyrna_prop_getattro, /* getattrofunc tp_getattro; */ - ( setattrofunc ) pyrna_prop_setattro, /* setattrofunc tp_setattro; */ + ( getattrofunc ) NULL, /* getattrofunc tp_getattro; */ + ( setattrofunc ) NULL, /* setattrofunc tp_setattro; */ /* Functions to access object as input/output buffer */ NULL, /* PyBufferProcs *tp_as_buffer; */ @@ -2446,7 +2513,7 @@ PyTypeObject pyrna_prop_Type = { /*** Attribute descriptor and subclassing stuff ***/ pyrna_prop_methods, /* struct PyMethodDef *tp_methods; */ NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ + pyrna_prop_getseters, /* struct PyGetSetDef *tp_getset; */ NULL, /* struct _typeobject *tp_base; */ NULL, /* PyObject *tp_dict; */ NULL, /* descrgetfunc tp_descr_get; */ @@ -2539,7 +2606,83 @@ PyObject *BPy_GetStructRNA(PyObject *self) } */ -PyObject* pyrna_srna_Subtype(StructRNA *srna) +static PyObject* pyrna_srna_Subtype(StructRNA *srna); + +/* return a borrowed reference */ +static PyObject* pyrna_srna_PyBase(StructRNA *srna) //, PyObject *bpy_types_dict) +{ + /* Assume RNA_struct_py_type_get(srna) was already checked */ + StructRNA *base; + + PyObject *py_base= NULL; + + /* get the base type */ + base= RNA_struct_base(srna); + + if(base && base != srna) { + /*/printf("debug subtype %s %p\n", RNA_struct_identifier(srna), srna); */ + py_base= pyrna_srna_Subtype(base); //, bpy_types_dict); + Py_DECREF(py_base); /* srna owns, this is only to pass as an arg */ + } + + if(py_base==NULL) { + py_base= (PyObject *)&pyrna_struct_Type; + } + + return py_base; +} + +/* check if we have a native python subclass, use it when it exists + * return a borrowed reference */ +static PyObject* pyrna_srna_ExternalType(StructRNA *srna) +{ + PyObject *bpy_types_dict= NULL; + const char *idname= RNA_struct_identifier(srna); + PyObject *newclass; + + if(bpy_types_dict==NULL) { + PyObject *bpy_types= PyImport_ImportModuleLevel("bpy_types", NULL, NULL, NULL, 0); + + if(bpy_types==NULL) { + PyErr_Print(); + PyErr_Clear(); + fprintf(stderr, "pyrna_srna_ExternalType: failed to find 'bpy_types' module\n"); + return NULL; + } + + bpy_types_dict = PyModule_GetDict(bpy_types); // borrow + Py_DECREF(bpy_types); // fairly safe to assume the dict is kept + } + + newclass= PyDict_GetItemString(bpy_types_dict, idname); + + /* sanity check, could skip this unless in debug mode */ + if(newclass) { + PyObject *base_compare= pyrna_srna_PyBase(srna); + PyObject *bases= PyObject_GetAttrString(newclass, "__bases__"); + + if(PyTuple_GET_SIZE(bases)) { + PyObject *base= PyTuple_GET_ITEM(bases, 0); + + if(base_compare != base) { + PyLineSpit(); + fprintf(stderr, "pyrna_srna_ExternalType: incorrect subclassing of SRNA '%s'\n", idname); + PyObSpit("Expected! ", base_compare); + newclass= NULL; + } + else { + if(G.f & G_DEBUG) + fprintf(stderr, "SRNA Subclassed: '%s'\n", idname); + } + } + + Py_DECREF(bases); + } + + return newclass; +} + +static PyObject* pyrna_srna_Subtype(StructRNA *srna) { PyObject *newclass = NULL; @@ -2547,6 +2690,9 @@ PyObject* pyrna_srna_Subtype(StructRNA *srna) newclass= NULL; /* Nothing to do */ } else if ((newclass= RNA_struct_py_type_get(srna))) { Py_INCREF(newclass); + } else if ((newclass= pyrna_srna_ExternalType(srna))) { + pyrna_subtype_set_rna(newclass, srna); + Py_INCREF(newclass); } else { /* subclass equivelents - class myClass(myBase): @@ -2555,27 +2701,13 @@ PyObject* pyrna_srna_Subtype(StructRNA *srna) */ /* Assume RNA_struct_py_type_get(srna) was alredy checked */ - StructRNA *base; - - PyObject *py_base= NULL; + PyObject *py_base= pyrna_srna_PyBase(srna); const char *idname= RNA_struct_identifier(srna); const char *descr= RNA_struct_ui_description(srna); if(!descr) descr= "(no docs)"; - /* get the base type */ - base= RNA_struct_base(srna); - if(base && base != srna) { - /*/printf("debug subtype %s %p\n", RNA_struct_identifier(srna), srna); */ - py_base= pyrna_srna_Subtype(base); - Py_DECREF(py_base); /* srna owns, this is only to pass as an arg */ - } - - if(py_base==NULL) { - py_base= (PyObject *)&pyrna_struct_Type; - } - /* always use O not N when calling, N causes refcount errors */ newclass = PyObject_CallFunction( (PyObject*)&PyType_Type, "s(O){ssss}", idname, py_base, "__module__","bpy.types", "__doc__",descr); /* newclass will now have 2 ref's, ???, probably 1 is internal since decrefing here segfaults */ @@ -2611,7 +2743,7 @@ static StructRNA *srna_from_ptr(PointerRNA *ptr) } /* always returns a new ref, be sure to decref when done */ -PyObject* pyrna_struct_Subtype(PointerRNA *ptr) +static PyObject* pyrna_struct_Subtype(PointerRNA *ptr) { return pyrna_srna_Subtype(srna_from_ptr(ptr)); } @@ -2670,23 +2802,26 @@ PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop ) return ( PyObject * ) pyrna; } -/* bpy.data from python */ -static PointerRNA *rna_module_ptr= NULL; -PyObject *BPY_rna_module( void ) +void BPY_rna_init(void) { - BPy_StructRNA *pyrna; - PointerRNA ptr; - #ifdef USE_MATHUTILS // register mathutils callbacks, ok to run more then once. mathutils_rna_array_cb_index= Mathutils_RegisterCallback(&mathutils_rna_array_cb); mathutils_rna_matrix_cb_index= Mathutils_RegisterCallback(&mathutils_rna_matrix_cb); #endif - + if( PyType_Ready( &pyrna_struct_Type ) < 0 ) - return NULL; - + return; + if( PyType_Ready( &pyrna_prop_Type ) < 0 ) - return NULL; + return; +} + +/* bpy.data from python */ +static PointerRNA *rna_module_ptr= NULL; +PyObject *BPY_rna_module(void) +{ + BPy_StructRNA *pyrna; + PointerRNA ptr; /* for now, return the base RNA type rather then a real module */ RNA_main_pointer_create(G.main, &ptr); @@ -2724,21 +2859,22 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA * self, PyObject *pyna PointerRNA newptr; PyObject *ret; - ret = PyObject_GenericGetAttr((PyObject *)self, pyname); - if (ret) return ret; - else PyErr_Clear(); - if (RNA_property_collection_lookup_string(&self->ptr, self->prop, _PyUnicode_AsString(pyname), &newptr)) { ret= pyrna_struct_Subtype(&newptr); if (ret==NULL) { PyErr_Format(PyExc_SystemError, "bpy.types.%.200s subtype could not be generated, this is a bug!", _PyUnicode_AsString(pyname)); } - return ret; } - else { /* Override the error */ + else { +#if 0 PyErr_Format(PyExc_AttributeError, "bpy.types.%.200s RNA_Struct does not exist", _PyUnicode_AsString(pyname)); return NULL; +#endif + /* The error raised here will be displayed */ + ret= PyObject_GenericGetAttr((PyObject *)self, pyname); } + + return ret; } static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self); diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index d480fd3ec9b..0e40bf7258c 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -39,11 +39,9 @@ extern PyTypeObject pyrna_prop_Type; #define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type) typedef struct { - void * _a; - void * _b; - PyTypeObject *py_type; -} BPy_StructFakeType; - + PyObject_HEAD /* required python macro */ + PointerRNA ptr; +} BPy_DummyPointerRNA; typedef struct { PyObject_HEAD /* required python macro */ @@ -64,6 +62,7 @@ typedef struct { /* cheap trick */ #define BPy_BaseTypeRNA BPy_PropertyRNA +void BPY_rna_init( void ); PyObject *BPY_rna_module( void ); void BPY_update_rna_module( void ); /*PyObject *BPY_rna_doc( void );*/ diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 86407e0c818..174d1aa342f 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -162,12 +162,15 @@ void BPY_getFileAndNum(char **filename, int *lineno) getframe = PySys_GetObject("_getframe"); // borrowed if (getframe==NULL) { + PyErr_Clear(); return; } frame = PyObject_CallObject(getframe, NULL); - if (frame==NULL) + if (frame==NULL) { + PyErr_Clear(); return; + } if (filename) { co_filename= PyObject_GetAttrStringArgs(frame, 1, "f_code", "co_filename"); diff --git a/source/blender/quicktime/apple/quicktime_export.c b/source/blender/quicktime/apple/quicktime_export.c index de8c4179132..a2727963032 100644 --- a/source/blender/quicktime/apple/quicktime_export.c +++ b/source/blender/quicktime/apple/quicktime_export.c @@ -317,7 +317,7 @@ static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, i k32ARGBPixelFormat, trackFrame, NULL, NULL, 0, - (unsigned char *)qtexport->ibuf->rect, + (Ptr)qtexport->ibuf->rect, rectx * 4 ); CheckError (err, "NewGWorldFromPtr error"); @@ -438,7 +438,7 @@ void makeqtstring (RenderData *rd, char *string) { } -void start_qt(struct RenderData *rd, int rectx, int recty) { +void start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty) { OSErr err = noErr; char name[2048]; @@ -460,7 +460,7 @@ void start_qt(struct RenderData *rd, int rectx, int recty) { qtdata = MEM_callocN(sizeof(QuicktimeComponentData), "QuicktimeCodecDataExt"); - if(rd->qtcodecdata == NULL && rd->qtcodecdata->cdParms == NULL) { + if(rd->qtcodecdata == NULL || rd->qtcodecdata->cdParms == NULL) { get_qtcodec_settings(rd); } else { qtdata->theComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); @@ -484,7 +484,7 @@ void start_qt(struct RenderData *rd, int rectx, int recty) { /* do something? */ } close(myFile); - err = FSPathMakeRef(theFullPath, &myRef, 0); + err = FSPathMakeRef((const UInt8 *)theFullPath, &myRef, 0); CheckError(err, "FsPathMakeRef error"); err = FSGetCatalogInfo(&myRef, kFSCatInfoNone, NULL, NULL, &qtexport->theSpec, NULL); CheckError(err, "FsGetCatalogInfoRef error"); @@ -574,10 +574,13 @@ static void check_renderbutton_framerate(RenderData *rd) if( (rd->frs_sec == 24 || rd->frs_sec == 30 || rd->frs_sec == 60) && (qtdata->gTemporalSettings.frameRate == 1571553 || qtdata->gTemporalSettings.frameRate == 1964113 || - qtdata->gTemporalSettings.frameRate == 3928227)) {;} else - qtdata->gTemporalSettings.frameRate = - (rd->frs_sec << 16) / rd->frs_sec_base ; - + qtdata->gTemporalSettings.frameRate == 3928227)) {;} + else { + if (rd->frs_sec_base > 0) + qtdata->gTemporalSettings.frameRate = + (rd->frs_sec << 16) / rd->frs_sec_base ; + } + err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); CheckError( err, "SCSetInfo error" ); @@ -634,7 +637,7 @@ int get_qtcodec_settings(RenderData *rd) check_renderbutton_framerate(rd); - // put up the dialog box + // put up the dialog box - it needs to be called from the main thread err = SCRequestSequenceSettings(qtdata->theComponent); if (err == scUserCancelled) { diff --git a/source/blender/quicktime/quicktime_export.h b/source/blender/quicktime/quicktime_export.h index b5c0dcff232..4afcebab7bd 100644 --- a/source/blender/quicktime/quicktime_export.h +++ b/source/blender/quicktime/quicktime_export.h @@ -36,7 +36,7 @@ // quicktime movie output functions struct RenderData; -void start_qt(struct RenderData *rd, int rectx, int recty); //for movie handle (BKE writeavi.c now) +void start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty); //for movie handle (BKE writeavi.c now) void append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty); void end_qt(void); diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt index 279ba7698b7..40f697c7776 100644 --- a/source/blender/render/CMakeLists.txt +++ b/source/blender/render/CMakeLists.txt @@ -47,6 +47,13 @@ IF(WITH_QUICKTIME) ADD_DEFINITIONS(-DWITH_QUICKTIME) ENDIF(WITH_QUICKTIME) +IF(APPLE) + IF(CMAKE_OSX_ARCHITECTURES MATCHES "i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "x86_64") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfpmath=sse") + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfpmath=sse") + ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES "i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "x86_64") +ENDIF(APPLE) + #TODO #if env['OURPLATFORM']=='linux2': # cflags='-pthread' diff --git a/source/blender/render/SConscript b/source/blender/render/SConscript index f89e81708b4..795e7247597 100644 --- a/source/blender/render/SConscript +++ b/source/blender/render/SConscript @@ -5,9 +5,14 @@ if env['OURPLATFORM'] in ('win32-vc', 'win64-vc', 'win32-mingw'): # FIXME: need to set the appropriate flags for msvc, otherwise we get warnings cflags = [] cxxflags = [] -else: - cflags = ['-O2','-msse2','-mfpmath=sse'] - cxxflags = ['-O2','-msse2','-mfpmath=sse'] + +if env['OURPLATFORM'] == 'darwin': + if env['MACOSX_ARCHITECTURE'] in ('i386', 'x86_64'): + cflags = env['CFLAGS'] + ['-mfpmath=sse'] + cxxflags = env['CXXFLAGS'] + ['-mfpmath=sse'] + else: + cflags = env['CFLAGS'] + cxxflags = env['CXXFLAGS'] sources = env.Glob('intern/source/*.c') raysources = env.Glob('intern/raytrace/*.cpp') @@ -25,12 +30,9 @@ if env['WITH_BF_QUICKTIME']: if env['WITH_BF_OPENEXR']: defs.append('WITH_OPENEXR') -if env['OURPLATFORM']=='linux2': - cflags += ['-pthread'] - - if env['OURPLATFORM'] == 'linux2': - cflags='-pthread' + cflags = ['-O2','-msse2','-mfpmath=sse', '-pthread'] + cxxflags = ['-O2','-msse2','-mfpmath=sse', '-pthread'] incs += ' ../../../extern/binreloc/include' if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index 8aff7a38317..869405e0fbc 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -29,7 +29,7 @@ #include <assert.h> #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "DNA_material_types.h" #include "RE_raytrace.h" @@ -170,8 +170,8 @@ static inline int rayface_check_cullface(RayFace *face, Isect *is) float nor[3]; /* don't intersect if the ray faces along the face normal */ - if(face->quad) CalcNormFloat4(face->v1, face->v2, face->v3, face->v4, nor); - else CalcNormFloat(face->v1, face->v2, face->v3, nor); + if(face->quad) normal_quad_v3( nor,face->v1, face->v2, face->v3, face->v4); + else normal_tri_v3( nor,face->v1, face->v2, face->v3); return (INPR(nor, is->vec) < 0); } @@ -376,7 +376,7 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) RE_RC_COUNT(isec->raycounter->raycast.test); /* Setup vars used on raycast */ - isec->dist = VecLength(isec->vec); + isec->dist = len_v3(isec->vec); for(i=0; i<3; i++) { @@ -435,11 +435,11 @@ int RE_rayobject_intersect(RayObject *r, Isect *i) if(face->ob->transform_primitives) { - Mat4MulVecfl(face->ob->mat, nface.v1); - Mat4MulVecfl(face->ob->mat, nface.v2); - Mat4MulVecfl(face->ob->mat, nface.v3); + mul_m4_v3(face->ob->mat, nface.v1); + mul_m4_v3(face->ob->mat, nface.v2); + mul_m4_v3(face->ob->mat, nface.v3); if(RE_rayface_isQuad(&nface)) - Mat4MulVecfl(face->ob->mat, nface.v4); + mul_m4_v3(face->ob->mat, nface.v4); } return intersect_rayface(r, &nface, i); diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp index a16499d4f91..09026929829 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp @@ -33,7 +33,7 @@ #include "rayobject_rtbuild.h" #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_utildefines.h" static bool selected_node(RTBuilder::Object *node) diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index 11f04c04141..4a2a56fa8ef 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -38,7 +38,7 @@ int tot_hints = 0; #include "BLI_memarena.h" #include "MEM_guardedalloc.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "reorganize.h" #include "bvh.h" diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 072083e58a7..cbb15558a3d 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -35,7 +35,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" #include "BLI_memarena.h" @@ -191,8 +191,8 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), if (re) re->flag |= R_HALO; else stargrid *= 1.0; /* then it draws fewer */ - if(re) Mat4Invert(mat, re->viewmat); - else Mat4One(mat); + if(re) invert_m4_m4(mat, re->viewmat); + else unit_m4(mat); /* BOUNDING BOX CALCULATION * bbox goes from z = loc_near_var | loc_far_var, @@ -240,7 +240,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), done++; } else { - Mat4MulVecfl(re->viewmat, vec); + mul_m4_v3(re->viewmat, vec); /* in vec are global coordinates * calculate distance to camera @@ -372,7 +372,7 @@ static int check_vnormal(float *n, float *veno) static void calc_edge_stress_add(float *accum, VertRen *v1, VertRen *v2) { - float len= VecLenf(v1->co, v2->co)/VecLenf(v1->orco, v2->orco); + float len= len_v3v3(v1->co, v2->co)/len_v3v3(v1->orco, v2->orco); float *acc; acc= accum + 2*v1->index; @@ -459,11 +459,11 @@ static void calc_tangent_vector(ObjectRen *obr, VertexTangent **vtangents, MemAr } else if(v1->orco) { uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; - spheremap(v1->orco[0], v1->orco[1], v1->orco[2], &uv[0][0], &uv[0][1]); - spheremap(v2->orco[0], v2->orco[1], v2->orco[2], &uv[1][0], &uv[1][1]); - spheremap(v3->orco[0], v3->orco[1], v3->orco[2], &uv[2][0], &uv[2][1]); + map_to_sphere( &uv[0][0], &uv[0][1],v1->orco[0], v1->orco[1], v1->orco[2]); + map_to_sphere( &uv[1][0], &uv[1][1],v2->orco[0], v2->orco[1], v2->orco[2]); + map_to_sphere( &uv[2][0], &uv[2][1],v3->orco[0], v3->orco[1], v3->orco[2]); if(v4) - spheremap(v4->orco[0], v4->orco[1], v4->orco[2], &uv[3][0], &uv[3][1]); + map_to_sphere( &uv[3][0], &uv[3][1],v4->orco[0], v4->orco[1], v4->orco[2]); } else return; @@ -539,23 +539,23 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d if(re->flag & R_GLOB_NOPUNOFLIP) vlr->flag |= R_NOPUNOFLIP; - VecSubf(n1, v2->co, v1->co); - Normalize(n1); - VecSubf(n2, v3->co, v2->co); - Normalize(n2); + sub_v3_v3v3(n1, v2->co, v1->co); + normalize_v3(n1); + sub_v3_v3v3(n2, v3->co, v2->co); + normalize_v3(n2); if(v4==NULL) { - VecSubf(n3, v1->co, v3->co); - Normalize(n3); + sub_v3_v3v3(n3, v1->co, v3->co); + normalize_v3(n3); fac1= saacos(-n1[0]*n3[0]-n1[1]*n3[1]-n1[2]*n3[2]); fac2= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]); fac3= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]); } else { - VecSubf(n3, v4->co, v3->co); - Normalize(n3); - VecSubf(n4, v1->co, v4->co); - Normalize(n4); + sub_v3_v3v3(n3, v4->co, v3->co); + normalize_v3(n3); + sub_v3_v3v3(n4, v1->co, v4->co); + normalize_v3(n4); fac1= saacos(-n4[0]*n1[0]-n4[1]*n1[1]-n4[2]*n1[2]); fac2= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2]); @@ -622,17 +622,17 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d vtang= find_vertex_tangent(vtangents[v1->index], tface->uv[0]); VECCOPY(ftang, vtang); - Normalize(ftang); + normalize_v3(ftang); vtang= find_vertex_tangent(vtangents[v2->index], tface->uv[1]); VECCOPY(ftang+3, vtang); - Normalize(ftang+3); + normalize_v3(ftang+3); vtang= find_vertex_tangent(vtangents[v3->index], tface->uv[2]); VECCOPY(ftang+6, vtang); - Normalize(ftang+6); + normalize_v3(ftang+6); if(v4) { vtang= find_vertex_tangent(vtangents[v4->index], tface->uv[3]); VECCOPY(ftang+9, vtang); - Normalize(ftang+9); + normalize_v3(ftang+9); } } } @@ -641,7 +641,7 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d /* normalize vertex normals */ for(a=0; a<obr->totvert; a++) { VertRen *ver= RE_findOrAddVert(obr, a); - Normalize(ver->n); + normalize_v3(ver->n); if(do_tangent) { float *tav= RE_vertren_get_tangent(obr, ver, 0); if (tav) { @@ -650,7 +650,7 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d tav[0] -= ver->n[0]*tdn; tav[1] -= ver->n[1]*tdn; tav[2] -= ver->n[2]*tdn; - Normalize(tav); + normalize_v3(tav); } } } @@ -829,7 +829,7 @@ static void autosmooth(Render *re, ObjectRen *obr, float mat[][4], int degr) /* rotate vertices and calculate normal of faces */ for(a=0; a<obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); - Mat4MulVecfl(mat, ver->co); + mul_m4_v3(mat, ver->co); } for(a=0; a<obr->totvlak; a++) { vlr= RE_findOrAddVlak(obr, a); @@ -837,9 +837,9 @@ static void autosmooth(Render *re, ObjectRen *obr, float mat[][4], int degr) /* skip wire faces */ if(vlr->v2 != vlr->v3) { if(vlr->v4) - CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); else - CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); } } } @@ -982,9 +982,9 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par int flag, i; static int second=0; - VecSubf(nor, vec, vec1); - Normalize(nor); // nor needed as tangent - Crossf(cross, vec, nor); + sub_v3_v3v3(nor, vec, vec1); + normalize_v3(nor); // nor needed as tangent + cross_v3_v3v3(cross, vec, nor); /* turn cross in pixelsize */ w= vec[2]*re->winmat[2][3] + re->winmat[3][3]; @@ -1006,19 +1006,19 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par /* use actual Blender units for strand width and fall back to minimum width */ if(ma->mode & MA_STR_B_UNITS){ - crosslen= VecLength(cross); + crosslen= len_v3(cross); w= 2.0f*crosslen*ma->strand_min/w; if(width < w) width= w; /*cross is the radius of the strand so we want it to be half of full width */ - VecMulf(cross,0.5/crosslen); + mul_v3_fl(cross,0.5/crosslen); } else width/=w; - VecMulf(cross, width); + mul_v3_fl(cross, width); } else width= 1.0f; @@ -1041,30 +1041,30 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par vlr->v4= RE_findOrAddVert(obr, obr->totvert++); VECCOPY(vlr->v1->co, vec); - VecAddf(vlr->v1->co, vlr->v1->co, cross); + add_v3_v3v3(vlr->v1->co, vlr->v1->co, cross); VECCOPY(vlr->v1->n, nor); vlr->v1->orco= sd->orco; vlr->v1->accum= -1.0f; // accum abuse for strand texco VECCOPY(vlr->v2->co, vec); - VecSubf(vlr->v2->co, vlr->v2->co, cross); + sub_v3_v3v3(vlr->v2->co, vlr->v2->co, cross); VECCOPY(vlr->v2->n, nor); vlr->v2->orco= sd->orco; vlr->v2->accum= vlr->v1->accum; VECCOPY(vlr->v4->co, vec1); - VecAddf(vlr->v4->co, vlr->v4->co, cross); + add_v3_v3v3(vlr->v4->co, vlr->v4->co, cross); VECCOPY(vlr->v4->n, nor); vlr->v4->orco= sd->orco; vlr->v4->accum= 1.0f; // accum abuse for strand texco VECCOPY(vlr->v3->co, vec1); - VecSubf(vlr->v3->co, vlr->v3->co, cross); + sub_v3_v3v3(vlr->v3->co, vlr->v3->co, cross); VECCOPY(vlr->v3->n, nor); vlr->v3->orco= sd->orco; vlr->v3->accum= vlr->v4->accum; - CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); vlr->mat= ma; vlr->ec= ME_V2V3; @@ -1115,13 +1115,13 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par v2= RE_findOrAddVert(obr, obr->totvert++); VECCOPY(v1->co, vec); - VecAddf(v1->co, v1->co, cross); + add_v3_v3v3(v1->co, v1->co, cross); VECCOPY(v1->n, nor); v1->orco= sd->orco; v1->accum= -1.0f; // accum abuse for strand texco VECCOPY(v2->co, vec); - VecSubf(v2->co, v2->co, cross); + sub_v3_v3v3(v2->co, v2->co, cross); VECCOPY(v2->n, nor); v2->orco= sd->orco; v2->accum= v1->accum; @@ -1149,15 +1149,15 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par } else if(sd->adapt){ float dvec[3],pvec[3]; - VecSubf(dvec,avec,vec); - Projf(pvec,dvec,vec); - VecSubf(dvec,dvec,pvec); + sub_v3_v3v3(dvec,avec,vec); + project_v3_v3v3(pvec,dvec,vec); + sub_v3_v3v3(dvec,dvec,pvec); w= vec[2]*re->winmat[2][3] + re->winmat[3][3]; dx= re->winx*dvec[0]*re->winmat[0][0]/w; dy= re->winy*dvec[1]*re->winmat[1][1]/w; w= sqrt(dx*dx + dy*dy); - if(Inpf(anor,nor)<sd->adapt_angle && w>sd->adapt_pix){ + if(dot_v3v3(anor,nor)<sd->adapt_angle && w>sd->adapt_pix){ vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->flag= flag; vlr->v1= v1; @@ -1177,18 +1177,18 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par } VECCOPY(vlr->v4->co, vec); - VecAddf(vlr->v4->co, vlr->v4->co, cross); + add_v3_v3v3(vlr->v4->co, vlr->v4->co, cross); VECCOPY(vlr->v4->n, nor); vlr->v4->orco= sd->orco; vlr->v4->accum= -1.0f + 2.0f*sd->time; // accum abuse for strand texco VECCOPY(vlr->v3->co, vec); - VecSubf(vlr->v3->co, vlr->v3->co, cross); + sub_v3_v3v3(vlr->v3->co, vlr->v3->co, cross); VECCOPY(vlr->v3->n, nor); vlr->v3->orco= sd->orco; vlr->v3->accum= vlr->v4->accum; - CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); vlr->mat= ma; vlr->ec= ME_V2V3; @@ -1244,8 +1244,8 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, float *vec, float VECCOPY(vlr->v1->co, vec); VECCOPY(vlr->v2->co, vec1); - VecSubf(vlr->n, vec, vec1); - Normalize(vlr->n); + sub_v3_v3v3(vlr->n, vec, vec1); + normalize_v3(vlr->n); VECCOPY(vlr->v1->n, vlr->n); VECCOPY(vlr->v2->n, vlr->n); @@ -1267,8 +1267,8 @@ static void static_particle_wire(ObjectRen *obr, Material *ma, float *vec, float v1= vlr->v2; // cycle VECCOPY(v1->co, vec); - VecSubf(vlr->n, vec, vec1); - Normalize(vlr->n); + sub_v3_v3v3(vlr->n, vec, vec1); + normalize_v3(vlr->n); VECCOPY(v1->n, vlr->n); vlr->mat= ma; @@ -1307,21 +1307,21 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl VECADD(vlr->v1->co, bb_center, xvec); VECADD(vlr->v1->co, vlr->v1->co, yvec); - Mat4MulVecfl(re->viewmat, vlr->v1->co); + mul_m4_v3(re->viewmat, vlr->v1->co); VECSUB(vlr->v2->co, bb_center, xvec); VECADD(vlr->v2->co, vlr->v2->co, yvec); - Mat4MulVecfl(re->viewmat, vlr->v2->co); + mul_m4_v3(re->viewmat, vlr->v2->co); VECSUB(vlr->v3->co, bb_center, xvec); VECSUB(vlr->v3->co, vlr->v3->co, yvec); - Mat4MulVecfl(re->viewmat, vlr->v3->co); + mul_m4_v3(re->viewmat, vlr->v3->co); VECADD(vlr->v4->co, bb_center, xvec); VECSUB(vlr->v4->co, vlr->v4->co, yvec); - Mat4MulVecfl(re->viewmat, vlr->v4->co); + mul_m4_v3(re->viewmat, vlr->v4->co); - CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); VECCOPY(vlr->v1->n,vlr->n); VECCOPY(vlr->v2->n,vlr->n); VECCOPY(vlr->v3->n,vlr->n); @@ -1352,10 +1352,10 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl axis2[(bb->align + 2) % 3] = 1.0f; if(bb->lock == 0) { zvec[bb->align] = 0.0f; - Normalize(zvec); + normalize_v3(zvec); } - time = saacos(Inpf(zvec, axis1)) / (float)M_PI; - if(Inpf(zvec, axis2) < 0.0f) + time = saacos(dot_v3v3(zvec, axis1)) / (float)M_PI; + if(dot_v3v3(zvec, axis2) < 0.0f) time = 1.0f - time / 2.0f; else time = time / 2.0f; @@ -1419,7 +1419,7 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re VECCOPY(loc, state->co); if(ren_as != PART_DRAW_BB) - Mat4MulVecfl(re->viewmat, loc); + mul_m4_v3(re->viewmat, loc); switch(ren_as) { case PART_DRAW_LINE: @@ -1428,11 +1428,11 @@ static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re sd->size = hasize; VECCOPY(vel, state->vel); - Mat4Mul3Vecfl(re->viewmat, vel); - Normalize(vel); + mul_mat3_m4_v3(re->viewmat, vel); + normalize_v3(vel); if(part->draw & PART_DRAW_VEL_LENGTH) - VecMulf(vel, VecLength(state->vel)); + mul_v3_fl(vel, len_v3(state->vel)); VECADDFAC(loc0, loc, vel, -part->draw_line[0]); VECADDFAC(loc1, loc, vel, part->draw_line[1]); @@ -1651,10 +1651,10 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem // } /* 2.5 setup matrices */ - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); /* need to be that way, for imat texture */ - Mat3CpyMat4(nmat, ob->imat); - Mat3Transp(nmat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); /* need to be that way, for imat texture */ + copy_m3_m4(nmat, ob->imat); + transpose_m3(nmat); /* 2.6 setup strand rendering */ if(part->ren_as == PART_DRAW_PATH && psys->pathcache){ @@ -1677,7 +1677,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem strandbuf= RE_addStrandBuffer(obr, (totpart+totchild)*(path_nbr+1)); strandbuf->ma= ma; strandbuf->lay= ob->lay; - Mat4CpyMat4(strandbuf->winmat, re->winmat); + copy_m4_m4(strandbuf->winmat, re->winmat); strandbuf->winx= re->winx; strandbuf->winy= re->winy; strandbuf->maxdepth= 2; @@ -1861,7 +1861,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* surface normal shading setup */ if(ma->mode_l & MA_STR_SURFDIFF) { - Mat3MulVecfl(nmat, nor); + mul_m3_v3(nmat, nor); sd.surfnor= nor; } else @@ -1916,7 +1916,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem curlen= 0.0f; for(k=1; k<=path_nbr; k++) if(k<=max_k) - strandlen += VecLenf((cache+k-1)->co, (cache+k)->co); + strandlen += len_v3v3((cache+k-1)->co, (cache+k)->co); } if(path_nbr) { @@ -1930,11 +1930,11 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem continue; if(k > 0) - curlen += VecLenf((cache+k-1)->co, (cache+k)->co); + curlen += len_v3v3((cache+k-1)->co, (cache+k)->co); time= curlen/strandlen; VECCOPY(loc,state.co); - Mat4MulVecfl(re->viewmat,loc); + mul_m4_v3(re->viewmat,loc); if(strandbuf) { VECCOPY(svert->co, loc); @@ -1985,7 +1985,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem psys_get_particle_on_path(&sim,a,&state,1); if(psys->parent) - Mat4MulVecfl(psys->parent->obmat, state.co); + mul_m4_v3(psys->parent->obmat, state.co); if(part->ren_as == PART_DRAW_BB) { bb.random = random; @@ -2005,7 +2005,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem continue; if(psys->parent) - Mat4MulVecfl(psys->parent->obmat, state.co); + mul_m4_v3(psys->parent->obmat, state.co); if(part->ren_as == PART_DRAW_BB) { bb.random = random; @@ -2076,8 +2076,8 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *me, int totvert, float vec[3], hasize, mat[4][4], imat[3][3]; int a, ok, seed= ma->seed1; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat3CpyMat4(imat, ob->imat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + copy_m3_m4(imat, ob->imat); re->flag |= R_HALO; @@ -2088,7 +2088,7 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *me, int totvert, hasize= ma->hasize; VECCOPY(vec, mvert->co); - Mat4MulVecfl(mat, vec); + mul_m4_v3(mat, vec); if(ma->mode & MA_HALOPUNO) { xn= mvert->no[0]; @@ -2099,10 +2099,10 @@ static void make_render_halos(Render *re, ObjectRen *obr, Mesh *me, int totvert, nor[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn; nor[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn; nor[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn; - Normalize(nor); + normalize_v3(nor); VECCOPY(view, vec); - Normalize(view); + normalize_v3(view); zn= nor[0]*view[0]+nor[1]*view[1]+nor[2]*view[2]; if(zn>=0.0) hasize= 0.0; @@ -2183,7 +2183,7 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve VECCOPY(shi->vn, vr->n); if(mat) - Mat4MulVecfl(mat, shi->co); + mul_m4_v3(mat, shi->co); if(imat) { shi->vn[0]= imat[0][0]*vr->n[0]+imat[0][1]*vr->n[1]+imat[0][2]*vr->n[2]; @@ -2221,7 +2221,7 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve } if (texco & TEXCO_GLOB) { VECCOPY(shi->gl, shi->co); - Mat4MulVecfl(re->viewinv, shi->gl); + mul_m4_v3(re->viewinv, shi->gl); } if (texco & TEXCO_NORM) { VECCOPY(shi->orn, shi->vn); @@ -2242,7 +2242,7 @@ static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, Ve displace[2]= shi->displace[2] * scale[2]; if(mat) - Mat3MulVecfl(imat, displace); + mul_m3_v3(imat, displace); /* 0.5 could become button once? */ vr->co[0] += displace[0]; @@ -2306,10 +2306,10 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float /* Recalculate the face normal - if flipped before, flip now */ if(vlr->v4) { - CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); } else { - CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); } } @@ -2325,7 +2325,7 @@ static void do_displacement(Render *re, ObjectRen *obr, float mat[][4], float im /* Object Size with parenting */ obt=obr->ob; while(obt){ - VecAddf(temp, obt->size, obt->dsize); + add_v3_v3v3(temp, obt->size, obt->dsize); scale[0]*=temp[0]; scale[1]*=temp[1]; scale[2]*=temp[2]; obt=obt->parent; } @@ -2362,9 +2362,9 @@ static void init_render_mball(Render *re, ObjectRen *obr) if (ob!=find_basis_mball(re->scene, ob)) return; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); - Mat3CpyMat4(imat, ob->imat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); + copy_m3_m4(imat, ob->imat); ma= give_render_material(re, ob, 1); @@ -2385,7 +2385,7 @@ static void init_render_mball(Render *re, ObjectRen *obr) ver= RE_findOrAddVert(obr, obr->totvert++); VECCOPY(ver->co, data); - Mat4MulVecfl(mat, ver->co); + mul_m4_v3(mat, ver->co); /* render normals are inverted */ xn= -nors[0]; @@ -2396,8 +2396,8 @@ static void init_render_mball(Render *re, ObjectRen *obr) ver->n[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn; ver->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn; ver->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn; - Normalize(ver->n); - //if(ob->transflag & OB_NEG_SCALE) VecMulf(ver->n. -1.0); + normalize_v3(ver->n); + //if(ob->transflag & OB_NEG_SCALE) mul_v3_fl(ver->n. -1.0); if(need_orco) ver->orco= orco; } @@ -2412,9 +2412,9 @@ static void init_render_mball(Render *re, ObjectRen *obr) vlr->v4= 0; if(ob->transflag & OB_NEG_SCALE) - CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->n); + normal_tri_v3( vlr->n,vlr->v1->co, vlr->v2->co, vlr->v3->co); else - CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); vlr->mat= ma; vlr->flag= ME_SMOOTH+R_NOPUNOFLIP; @@ -2429,9 +2429,9 @@ static void init_render_mball(Render *re, ObjectRen *obr) vlr1->v2= vlr1->v3; vlr1->v3= RE_findOrAddVert(obr, index[3]); if(ob->transflag & OB_NEG_SCALE) - CalcNormFloat(vlr1->v1->co, vlr1->v2->co, vlr1->v3->co, vlr1->n); + normal_tri_v3( vlr1->n,vlr1->v1->co, vlr1->v2->co, vlr1->v3->co); else - CalcNormFloat(vlr1->v3->co, vlr1->v2->co, vlr1->v1->co, vlr1->n); + normal_tri_v3( vlr1->n,vlr1->v3->co, vlr1->v2->co, vlr1->v1->co); } } @@ -2469,7 +2469,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, if(orco) { v1->orco= orco; orco+= 3; orcoret++; } - Mat4MulVecfl(mat, v1->co); + mul_m4_v3(mat, v1->co); for (v = 1; v < sizev; v++) { ver= RE_findOrAddVert(obr, obr->totvert++); @@ -2477,7 +2477,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, if(orco) { ver->orco= orco; orco+= 3; orcoret++; } - Mat4MulVecfl(mat, ver->co); + mul_m4_v3(mat, ver->co); } /* if V-cyclic, add extra vertices at end of the row */ if (dl->flag & DL_CYCL_U) { @@ -2525,7 +2525,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, vlr= RE_findOrAddVlak(obr, obr->totvlak++); vlr->v1= v1; vlr->v2= v2; vlr->v3= v3; vlr->v4= v4; - CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, n1); + normal_quad_v3( n1,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); VECCOPY(vlr->n, n1); @@ -2536,10 +2536,10 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, vlr->flag |= R_NOPUNOFLIP; } - VecAddf(v1->n, v1->n, n1); - VecAddf(v2->n, v2->n, n1); - VecAddf(v3->n, v3->n, n1); - VecAddf(v4->n, v4->n, n1); + add_v3_v3v3(v1->n, v1->n, n1); + add_v3_v3v3(v2->n, v2->n, n1); + add_v3_v3v3(v3->n, v3->n, n1); + add_v3_v3v3(v4->n, v4->n, n1); p1++; p2++; p3++; p4++; } @@ -2553,10 +2553,10 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, /* optimize! :*/ vlr= RE_findOrAddVlak(obr, UVTOINDEX(sizeu - 1, v)); vlr1= RE_findOrAddVlak(obr, UVTOINDEX(0, v)); - VecAddf(vlr1->v1->n, vlr1->v1->n, vlr->n); - VecAddf(vlr1->v2->n, vlr1->v2->n, vlr->n); - VecAddf(vlr->v3->n, vlr->v3->n, vlr1->n); - VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n); + add_v3_v3v3(vlr1->v1->n, vlr1->v1->n, vlr->n); + add_v3_v3v3(vlr1->v2->n, vlr1->v2->n, vlr->n); + add_v3_v3v3(vlr->v3->n, vlr->v3->n, vlr1->n); + add_v3_v3v3(vlr->v4->n, vlr->v4->n, vlr1->n); } } if (dl->flag & DL_CYCL_U) { @@ -2566,10 +2566,10 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, /* optimize! :*/ vlr= RE_findOrAddVlak(obr, UVTOINDEX(u, 0)); vlr1= RE_findOrAddVlak(obr, UVTOINDEX(u, sizev-1)); - VecAddf(vlr1->v2->n, vlr1->v2->n, vlr->n); - VecAddf(vlr1->v3->n, vlr1->v3->n, vlr->n); - VecAddf(vlr->v1->n, vlr->v1->n, vlr1->n); - VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n); + add_v3_v3v3(vlr1->v2->n, vlr1->v2->n, vlr->n); + add_v3_v3v3(vlr1->v3->n, vlr1->v3->n, vlr->n); + add_v3_v3v3(vlr->v1->n, vlr->v1->n, vlr1->n); + add_v3_v3v3(vlr->v4->n, vlr->v4->n, vlr1->n); } } /* last vertex is an extra case: @@ -2593,11 +2593,11 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, { vlr= RE_findOrAddVlak(obr, UVTOINDEX(sizeu - 1, sizev - 1)); /* (m,n) */ vlr1= RE_findOrAddVlak(obr, UVTOINDEX(0,0)); /* (0,0) */ - VecAddf(n1, vlr->n, vlr1->n); + add_v3_v3v3(n1, vlr->n, vlr1->n); vlr2= RE_findOrAddVlak(obr, UVTOINDEX(0, sizev-1)); /* (0,n) */ - VecAddf(n1, n1, vlr2->n); + add_v3_v3v3(n1, n1, vlr2->n); vlr3= RE_findOrAddVlak(obr, UVTOINDEX(sizeu-1, 0)); /* (m,0) */ - VecAddf(n1, n1, vlr3->n); + add_v3_v3v3(n1, n1, vlr3->n); VECCOPY(vlr->v3->n, n1); VECCOPY(vlr1->v1->n, n1); VECCOPY(vlr2->v2->n, n1); @@ -2605,7 +2605,7 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, } for(a = startvert; a < obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); - Normalize(ver->n); + normalize_v3(ver->n); } @@ -2627,8 +2627,8 @@ static void init_render_surf(Render *re, ObjectRen *obr) nu= cu->nurb.first; if(nu==0) return; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); /* material array */ totmat= ob->totcol+1; @@ -2688,8 +2688,8 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) dl= cu->disp.first; if(cu->disp.first==NULL) return; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); /* material array */ totmat= ob->totcol+1; @@ -2715,7 +2715,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) n[0]= ob->imat[0][2]; n[1]= ob->imat[1][2]; n[2]= ob->imat[2][2]; - Normalize(n); + normalize_v3(n); for(a=0; a<dl->nr; a++, data+=3) { ver= RE_findOrAddVert(obr, obr->totvert++); @@ -2731,7 +2731,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) ver->flag = 0; } - Mat4MulVecfl(mat, ver->co); + mul_m4_v3(mat, ver->co); if (orco) { ver->orco = orco; @@ -2783,7 +2783,7 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) ver= RE_findOrAddVert(obr, obr->totvert++); VECCOPY(ver->co, fp); - Mat4MulVecfl(mat, ver->co); + mul_m4_v3(mat, ver->co); fp+= 3; if (orco) { @@ -2824,9 +2824,9 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) */ if(frontside) - CalcNormFloat(vlr->v2->co, vlr->v3->co, vlr->v4->co, vlr->n); + normal_tri_v3( vlr->n,vlr->v2->co, vlr->v3->co, vlr->v4->co); else - CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->n); + normal_tri_v3( vlr->n,vlr->v1->co, vlr->v2->co, vlr->v3->co); vlr->mat= matar[ dl->col ]; @@ -2847,14 +2847,14 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset) for(a= startvlak; a<obr->totvlak; a++) { vlr= RE_findOrAddVlak(obr, a); - VecAddf(vlr->v1->n, vlr->v1->n, vlr->n); - VecAddf(vlr->v3->n, vlr->v3->n, vlr->n); - VecAddf(vlr->v2->n, vlr->v2->n, vlr->n); - VecAddf(vlr->v4->n, vlr->v4->n, vlr->n); + add_v3_v3v3(vlr->v1->n, vlr->v1->n, vlr->n); + add_v3_v3v3(vlr->v3->n, vlr->v3->n, vlr->n); + add_v3_v3v3(vlr->v2->n, vlr->v2->n, vlr->n); + add_v3_v3v3(vlr->v4->n, vlr->v4->n, vlr->n); } for(a=startvert; a<obr->totvert; a++) { ver= RE_findOrAddVert(obr, a); - len= Normalize(ver->n); + len= normalize_v3(ver->n); if(len==0.0) ver->flag= 1; /* flag abuse, its only used in zbuf now */ else ver->flag= 0; } @@ -3080,9 +3080,9 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) me= ob->data; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); - Mat3CpyMat4(imat, ob->imat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); + copy_m3_m4(imat, ob->imat); if(me->totvert==0) return; @@ -3163,7 +3163,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) ver= RE_findOrAddVert(obr, obr->totvert++); VECCOPY(ver->co, mvert->co); if(do_autosmooth==0) /* autosmooth on original unrotated data to prevent differences between frames */ - Mat4MulVecfl(mat, ver->co); + mul_m4_v3(mat, ver->co); if(orco) { ver->orco= orco; @@ -3236,15 +3236,15 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) MVert *mv= me->mvert; if(vlr->v4) - len= CalcNormFloat4( mv[mf->v4].co, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co, vlr->n); + len= normal_quad_v3( vlr->n, mv[mf->v4].co, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co); else - len= CalcNormFloat(mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co, vlr->n); + len= normal_tri_v3( vlr->n,mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co); } else { if(vlr->v4) - len= CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + len= normal_quad_v3( vlr->n,vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co); else - len= CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); + len= normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); } vlr->mat= ma; @@ -3318,7 +3318,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset) vlr->n[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn; vlr->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn; vlr->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn; - Normalize(vlr->n); + normalize_v3(vlr->n); vlr->mat= ma; vlr->flag= 0; @@ -3384,13 +3384,13 @@ static void initshadowbuf(Render *re, LampRen *lar, float mat[][4]) shb->soft= lar->soft; shb->shadhalostep= lar->shadhalostep; - Mat4Ortho(mat); - Mat4Invert(shb->winmat, mat); /* winmat is temp */ + normalize_m4(mat); + invert_m4_m4(shb->winmat, mat); /* winmat is temp */ /* matrix: combination of inverse view and lampmat */ /* calculate again: the ortho-render has no correct viewinv */ - Mat4Invert(viewinv, re->viewmat); - Mat4MulMat4(shb->viewmat, viewinv, shb->winmat); + invert_m4_m4(viewinv, re->viewmat); + mul_m4_m4m4(shb->viewmat, viewinv, shb->winmat); /* projection */ shb->d= lar->clipsta; @@ -3469,11 +3469,11 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) BLI_addtail(&re->lampren, lar); go->lampren= lar; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); - Mat3CpyMat4(lar->mat, mat); - Mat3CpyMat4(lar->imat, ob->imat); + copy_m3_m4(lar->mat, mat); + copy_m3_m4(lar->imat, ob->imat); lar->bufsize = la->bufsize; lar->samp = la->samp; @@ -3498,7 +3498,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->vec[0]= -mat[2][0]; lar->vec[1]= -mat[2][1]; lar->vec[2]= -mat[2][2]; - Normalize(lar->vec); + normalize_v3(lar->vec); lar->co[0]= mat[3][0]; lar->co[1]= mat[3][1]; lar->co[2]= mat[3][2]; @@ -3577,7 +3577,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->sunsky->effect_type = la->sun_effect_type; VECCOPY(vec,ob->obmat[2]); - Normalize(vec); + normalize_v3(vec); InitSunSky(lar->sunsky, la->atm_turbidity, vec, la->horizon_brightness, la->spread, la->sun_brightness, la->sun_size, la->backscattered_light, @@ -3607,9 +3607,9 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) if(lar->type==LA_SPOT) { - Normalize(lar->imat[0]); - Normalize(lar->imat[1]); - Normalize(lar->imat[2]); + normalize_v3(lar->imat[0]); + normalize_v3(lar->imat[1]); + normalize_v3(lar->imat[2]); xn= saacos(lar->spotsi); xn= sin(xn)/cos(xn); @@ -3630,7 +3630,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) lar->sh_invcampos[0]= -lar->co[0]; lar->sh_invcampos[1]= -lar->co[1]; lar->sh_invcampos[2]= -lar->co[2]; - Mat3MulVecfl(lar->imat, lar->sh_invcampos); + mul_m3_v3(lar->imat, lar->sh_invcampos); /* z factor, for a normalized volume */ angle= saacos(lar->spotsi); @@ -3677,7 +3677,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) else if (la->type==LA_SPOT && (lar->mode & LA_SHAD_BUF) ) { /* Per lamp, one shadow buffer is made. */ lar->bufflag= la->bufflag; - Mat4CpyMat4(mat, ob->obmat); + copy_m4_m4(mat, ob->obmat); initshadowbuf(re, lar, mat); // mat is altered } @@ -3792,8 +3792,8 @@ void init_render_world(Render *re) cp[3]= 1; VECCOPY(re->grvec, re->viewmat[2]); - Normalize(re->grvec); - Mat3CpyMat4(re->imat, re->viewinv); + normalize_v3(re->grvec); + copy_m3_m4(re->imat, re->viewinv); for(a=0; a<MAX_MTEX; a++) if(re->wrld.mtex[a] && re->wrld.mtex[a]->tex) re->wrld.skytype |= WO_SKYTEX; @@ -3946,8 +3946,8 @@ static void split_quads(ObjectRen *obr, int dir) vlr->v4 = vlr1->v4 = NULL; /* new normals */ - CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); - CalcNormFloat(vlr1->v3->co, vlr1->v2->co, vlr1->v1->co, vlr1->n); + normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); + normal_tri_v3( vlr1->n,vlr1->v3->co, vlr1->v2->co, vlr1->v1->co); } /* clear the flag when not divided */ else vlr->flag &= ~R_DIVIDE_24; @@ -4011,8 +4011,8 @@ static void check_non_flat_quads(ObjectRen *obr) /* 1---2 1---2 0 = orig face, 1 = new face */ /* render normals are inverted in render! we calculate normal of single tria here */ - flen= CalcNormFloat(vlr->v4->co, vlr->v3->co, vlr->v1->co, nor); - if(flen==0.0) CalcNormFloat(vlr->v4->co, vlr->v2->co, vlr->v1->co, nor); + flen= normal_tri_v3( nor,vlr->v4->co, vlr->v3->co, vlr->v1->co); + if(flen==0.0) normal_tri_v3( nor,vlr->v4->co, vlr->v2->co, vlr->v1->co); xn= nor[0]*vlr->n[0] + nor[1]*vlr->n[1] + nor[2]*vlr->n[2]; @@ -4024,10 +4024,10 @@ static void check_non_flat_quads(ObjectRen *obr) vlr1->flag |= R_FACE_SPLIT; /* split direction based on vnorms */ - CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, nor); + normal_tri_v3( nor,vlr->v1->co, vlr->v2->co, vlr->v3->co); d1= nor[0]*vlr->v1->n[0] + nor[1]*vlr->v1->n[1] + nor[2]*vlr->v1->n[2]; - CalcNormFloat(vlr->v2->co, vlr->v3->co, vlr->v4->co, nor); + normal_tri_v3( nor,vlr->v2->co, vlr->v3->co, vlr->v4->co); d2= nor[0]*vlr->v2->n[0] + nor[1]*vlr->v2->n[1] + nor[2]*vlr->v2->n[2]; if( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; @@ -4053,8 +4053,8 @@ static void check_non_flat_quads(ObjectRen *obr) vlr->v4 = vlr1->v4 = NULL; /* new normals */ - CalcNormFloat(vlr->v3->co, vlr->v2->co, vlr->v1->co, vlr->n); - CalcNormFloat(vlr1->v3->co, vlr1->v2->co, vlr1->v1->co, vlr1->n); + normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co); + normal_tri_v3( vlr1->n,vlr1->v3->co, vlr1->v2->co, vlr1->v1->co); } /* clear the flag when not divided */ else vlr->flag &= ~R_DIVIDE_24; @@ -4143,8 +4143,8 @@ static void find_dupli_instances(Render *re, ObjectRen *obr) float imat[4][4], obmat[4][4], obimat[4][4], nmat[3][3]; int first = 1; - Mat4MulMat4(obmat, obr->obmat, re->viewmat); - Mat4Invert(imat, obmat); + mul_m4_m4m4(obmat, obr->obmat, re->viewmat); + invert_m4_m4(imat, obmat); /* for objects instanced by dupliverts/faces/particles, we go over the * list of instances to find ones that instance obr, and setup their @@ -4155,12 +4155,12 @@ static void find_dupli_instances(Render *re, ObjectRen *obr) /* compute difference between object matrix and * object matrix with dupli transform, in viewspace */ - Mat4CpyMat4(obimat, obi->mat); - Mat4MulMat4(obi->mat, imat, obimat); + copy_m4_m4(obimat, obi->mat); + mul_m4_m4m4(obi->mat, imat, obimat); - Mat3CpyMat4(nmat, obi->mat); - Mat3Inv(obi->nmat, nmat); - Mat3Transp(obi->nmat); + copy_m3_m4(nmat, obi->mat); + invert_m3_m3(obi->nmat, nmat); + transpose_m3(obi->nmat); if(!first) { re->totvert += obr->totvert; @@ -4178,19 +4178,19 @@ static void assign_dupligroup_dupli(Render *re, ObjectInstanceRen *obi, ObjectRe { float imat[4][4], obmat[4][4], obimat[4][4], nmat[3][3]; - Mat4MulMat4(obmat, obr->obmat, re->viewmat); - Mat4Invert(imat, obmat); + mul_m4_m4m4(obmat, obr->obmat, re->viewmat); + invert_m4_m4(imat, obmat); obi->obr= obr; /* compute difference between object matrix and * object matrix with dupli transform, in viewspace */ - Mat4CpyMat4(obimat, obi->mat); - Mat4MulMat4(obi->mat, imat, obimat); + copy_m4_m4(obimat, obi->mat); + mul_m4_m4m4(obi->mat, imat, obimat); - Mat3CpyMat4(nmat, obi->mat); - Mat3Inv(obi->nmat, nmat); - Mat3Transp(obi->nmat); + copy_m3_m4(nmat, obi->mat); + invert_m3_m3(obi->nmat, nmat); + transpose_m3(obi->nmat); re->totvert += obr->totvert; re->totvlak += obr->totvlak; @@ -4253,8 +4253,8 @@ static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *d float imat[4][4]; obi->duplitexmat= BLI_memarena_alloc(re->memArena, sizeof(float)*4*4); - Mat4Invert(imat, dob->mat); - Mat4MulSerie(obi->duplitexmat, re->viewmat, dob->omat, imat, re->viewinv, 0, 0, 0, 0); + invert_m4_m4(imat, dob->mat); + mul_serie_m4(obi->duplitexmat, re->viewmat, dob->omat, imat, re->viewinv, 0, 0, 0, 0); } } @@ -4325,7 +4325,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject * obr= RE_addRenderObject(re, ob, par, index, 0, ob->lay); if((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { obr->flag |= R_INSTANCEABLE; - Mat4CpyMat4(obr->obmat, ob->obmat); + copy_m4_m4(obr->obmat, ob->obmat); } if(obr->lay & vectorlay) obr->flag |= R_NEED_VECTORS; @@ -4353,7 +4353,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject * obr= RE_addRenderObject(re, ob, par, index, psysindex, ob->lay); if((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) { obr->flag |= R_INSTANCEABLE; - Mat4CpyMat4(obr->obmat, ob->obmat); + copy_m4_m4(obr->obmat, ob->obmat); } if(obr->lay & vectorlay) obr->flag |= R_NEED_VECTORS; @@ -4384,8 +4384,8 @@ static void init_render_object(Render *re, Object *ob, Object *par, DupliObject else if(render_object_type(ob->type)) add_render_object(re, ob, par, dob, timeoffset, vectorlay); else { - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); } time= PIL_check_seconds_timer(); @@ -4635,8 +4635,8 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp for(SETLOOPER(re->scene, base)) { ob= base->object; /* imat objects has to be done here, since displace can have texture using Object map-input */ - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); /* each object should only be rendered once */ ob->flag &= ~OB_DONE; ob->transflag &= ~OB_RENDER_DUPLI; @@ -4681,7 +4681,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp for(dob= lb->first; dob; dob= dob->next) { Object *obd= dob->ob; - Mat4CpyMat4(obd->obmat, dob->mat); + copy_m4_m4(obd->obmat, dob->mat); /* group duplis need to set ob matrices correct, for deform. so no_draw is part handled */ if(!(obd->transflag & OB_RENDER_DUPLI) && dob->no_draw) @@ -4706,7 +4706,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp * this is a duplivert/face/particle, or it is a non-animated object in * a dupligroup that has already been created before */ if(dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, 0))) { - Mat4MulMat4(mat, dob->mat, re->viewmat); + mul_m4_m4m4(mat, dob->mat, re->viewmat); obi= RE_addRenderInstance(re, NULL, obd, ob, dob->index, 0, mat, obd->lay); /* fill in instance variables for texturing */ @@ -4782,8 +4782,8 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp if(redoimat) { for(SETLOOPER(re->scene, base)) { ob= base->object; - Mat4MulMat4(mat, ob->obmat, re->viewmat); - Mat4Invert(ob->imat, mat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); + invert_m4_m4(ob->imat, mat); } } @@ -4827,8 +4827,8 @@ void RE_Database_FromScene(Render *re, Scene *scene, int use_camera_view) /* if no camera, viewmat should have been set! */ if(use_camera_view && re->scene->camera) { - Mat4Ortho(re->scene->camera->obmat); - Mat4Invert(mat, re->scene->camera->obmat); + normalize_m4(re->scene->camera->obmat); + invert_m4_m4(mat, re->scene->camera->obmat); RE_SetView(re, mat); re->scene->camera->recalc= OB_RECALC_OB; /* force correct matrix for scaled cameras */ } @@ -4948,7 +4948,7 @@ void RE_DataBase_ApplyWindow(Render *re) void RE_DataBase_GetView(Render *re, float mat[][4]) { - Mat4CpyMat4(mat, re->viewmat); + copy_m4_m4(mat, re->viewmat); } /* ------------------------------------------------------------------------- */ @@ -4982,8 +4982,8 @@ static void database_fromscene_vectors(Render *re, Scene *scene, int timeoffset) /* if no camera, viewmat should have been set! */ if(re->scene->camera) { - Mat4Ortho(re->scene->camera->obmat); - Mat4Invert(mat, re->scene->camera->obmat); + normalize_m4(re->scene->camera->obmat); + invert_m4_m4(mat, re->scene->camera->obmat); RE_SetView(re, mat); } @@ -5091,9 +5091,9 @@ static float *calculate_strandsurface_speedvectors(Render *re, ObjectInstanceRen if(mesh->co && mesh->prevco && mesh->nextco) { if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(winmat, obi->mat, re->winmat); + mul_m4_m4m4(winmat, obi->mat, re->winmat); else - Mat4CpyMat4(winmat, re->winmat); + copy_m4_m4(winmat, re->winmat); winspeed= MEM_callocN(sizeof(float)*4*mesh->totvert, "StrandSurfWin"); @@ -5128,9 +5128,9 @@ static void calculate_speedvectors(Render *re, ObjectInstanceRen *obi, float *ve int a, *face, *index; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(winmat, obi->mat, re->winmat); + mul_m4_m4m4(winmat, obi->mat, re->winmat); else - Mat4CpyMat4(winmat, re->winmat); + copy_m4_m4(winmat, re->winmat); if(obr->vertnodes) { for(a=0; a<obr->totvert; a++, vectors+=2) { @@ -5168,7 +5168,7 @@ static void calculate_speedvectors(Render *re, ObjectInstanceRen *obi, float *ve co3= mesh->co[face[2]]; co4= (face[3])? mesh->co[face[3]]: NULL; - InterpWeightsQ3Dfl(co1, co2, co3, co4, strand->vert->co, w); + interp_weights_face_v3( w,co1, co2, co3, co4, strand->vert->co); speed[0]= speed[1]= speed[2]= speed[3]= 0.0f; QUATADDFAC(speed, speed, winspeed[face[0]], w[0]); @@ -5208,8 +5208,8 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * else return 0; - Mat4CpyMat4(mat, re->viewmat); - Mat4Invert(imat, mat); + copy_m4_m4(mat, re->viewmat); + invert_m4_m4(imat, mat); /* set first vertex OK */ if(!fss->meshSurfNormals) return 0; @@ -5222,9 +5222,9 @@ static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float * velarray = (float *)fss->meshSurfNormals; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(winmat, obi->mat, re->winmat); + mul_m4_m4m4(winmat, obi->mat, re->winmat); else - Mat4CpyMat4(winmat, re->winmat); + copy_m4_m4(winmat, re->winmat); /* (bad) HACK calculate average velocity */ /* better solution would be fixing getVelocityAt() in intern/elbeem/intern/solver_util.cpp @@ -5312,9 +5312,9 @@ static void copy_dbase_object_vectors(Render *re, ListBase *lb) vec= obilb->vectors= MEM_mallocN(2*sizeof(float)*totvector, "vector array"); if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(winmat, obi->mat, re->winmat); + mul_m4_m4m4(winmat, obi->mat, re->winmat); else - Mat4CpyMat4(winmat, re->winmat); + copy_m4_m4(winmat, re->winmat); for(a=0; a<obr->totvert; a++, vec+=2) { if((a & 255)==0) ver= obr->vertnodes[a>>8].vert; @@ -5513,12 +5513,12 @@ void RE_Database_Baking(Render *re, Scene *scene, int type, Object *actob) /* if no camera, set unit */ if(re->scene->camera) { - Mat4Ortho(re->scene->camera->obmat); - Mat4Invert(mat, re->scene->camera->obmat); + normalize_m4(re->scene->camera->obmat); + invert_m4_m4(mat, re->scene->camera->obmat); RE_SetView(re, mat); } else { - Mat4One(mat); + unit_m4(mat); RE_SetView(re, mat); } @@ -5601,8 +5601,8 @@ void RE_make_sticky(Scene *scene, View3D *v3d) RE_SetCamera(re, scene->camera); /* and set view matrix */ - Mat4Ortho(scene->camera->obmat); - Mat4Invert(mat, scene->camera->obmat); + normalize_m4(scene->camera->obmat); + invert_m4_m4(mat, scene->camera->obmat); RE_SetView(re, mat); for(base= FIRSTBASE; base; base= base->next) { @@ -5618,12 +5618,12 @@ void RE_make_sticky(Scene *scene, View3D *v3d) CD_CALLOC, NULL, me->totvert); where_is_object(scene, ob); - Mat4MulMat4(mat, ob->obmat, re->viewmat); + mul_m4_m4m4(mat, ob->obmat, re->viewmat); ms= me->msticky; for(a=0; a<me->totvert; a++, ms++, mvert++) { VECCOPY(ho, mvert->co); - Mat4MulVecfl(mat, ho); + mul_m4_v3(mat, ho); projectverto(ho, re->winmat, ho); ms->co[0]= ho[0]/ho[3]; ms->co[1]= ho[1]/ho[3]; diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index b5774d11799..323eb6a9500 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -31,7 +31,7 @@ /* external modules: */ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_threads.h" @@ -211,9 +211,9 @@ static void envmap_transmatrix(float mat[][4], int part) eul[2]= -M_PI/2.0; } - Mat4CpyMat4(tmat, mat); - EulToMat4(eul, rotmat); - Mat4MulSerie(mat, tmat, rotmat, + copy_m4_m4(tmat, mat); + eul_to_mat4( rotmat,eul); + mul_serie_m4(mat, tmat, rotmat, 0, 0, 0, 0, 0, 0); } @@ -231,28 +231,28 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) int a; if(mode==0) { - Mat4Invert(tmat, mat); - Mat3CpyMat4(imat, tmat); + invert_m4_m4(tmat, mat); + copy_m3_m4(imat, tmat); } else { - Mat4CpyMat4(tmat, mat); - Mat3CpyMat4(imat, mat); + copy_m4_m4(tmat, mat); + copy_m3_m4(imat, mat); } for(obi=re->instancetable.first; obi; obi=obi->next) { /* append or set matrix depending on dupli */ if(obi->flag & R_DUPLI_TRANSFORMED) { - Mat4CpyMat4(tmpmat, obi->mat); - Mat4MulMat4(obi->mat, tmpmat, tmat); + copy_m4_m4(tmpmat, obi->mat); + mul_m4_m4m4(obi->mat, tmpmat, tmat); } else if(mode==1) - Mat4CpyMat4(obi->mat, tmat); + copy_m4_m4(obi->mat, tmat); else - Mat4One(obi->mat); + unit_m4(obi->mat); - Mat3CpyMat4(cmat, obi->mat); - Mat3Inv(obi->nmat, cmat); - Mat3Transp(obi->nmat); + copy_m3_m4(cmat, obi->mat); + invert_m3_m3(obi->nmat, cmat); + transpose_m3(obi->nmat); /* indicate the renderer has to use transform matrices */ if(mode==0) @@ -267,7 +267,7 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) if((a & 255)==0) har= obr->bloha[a>>8]; else har++; - Mat4MulVecfl(tmat, har->co); + mul_m4_v3(tmat, har->co); } } @@ -277,25 +277,25 @@ static void env_rotate_scene(Render *re, float mat[][4], int mode) /* removed here some horrible code of someone in NaN who tried to fix prototypes... just solved by introducing a correct cmat[3][3] instead of using smat. this works, check square spots in reflections (ton) */ - Mat3CpyMat3(cmat, lar->imat); - Mat3MulMat3(lar->imat, cmat, imat); + copy_m3_m3(cmat, lar->imat); + mul_m3_m3m3(lar->imat, cmat, imat); - Mat3MulVecfl(imat, lar->vec); - Mat4MulVecfl(tmat, lar->co); + mul_m3_v3(imat, lar->vec); + mul_m4_v3(tmat, lar->co); lar->sh_invcampos[0]= -lar->co[0]; lar->sh_invcampos[1]= -lar->co[1]; lar->sh_invcampos[2]= -lar->co[2]; - Mat3MulVecfl(lar->imat, lar->sh_invcampos); + mul_m3_v3(lar->imat, lar->sh_invcampos); lar->sh_invcampos[2]*= lar->sh_zfac; if(lar->shb) { if(mode==1) { - Mat4Invert(pmat, mat); - Mat4MulMat4(smat, pmat, lar->shb->viewmat); - Mat4MulMat4(lar->shb->persmat, smat, lar->shb->winmat); + invert_m4_m4(pmat, mat); + mul_m4_m4m4(smat, pmat, lar->shb->viewmat); + mul_m4_m4m4(lar->shb->persmat, smat, lar->shb->winmat); } - else Mat4MulMat4(lar->shb->persmat, lar->shb->viewmat, lar->shb->winmat); + else mul_m4_m4m4(lar->shb->persmat, lar->shb->viewmat, lar->shb->winmat); } } @@ -373,8 +373,8 @@ static void env_set_imats(Render *re) base= re->scene->base.first; while(base) { - Mat4MulMat4(mat, base->object->obmat, re->viewmat); - Mat4Invert(base->object->imat, mat); + mul_m4_m4m4(mat, base->object->obmat, re->viewmat); + invert_m4_m4(base->object->imat, mat); base= base->next; } @@ -393,18 +393,18 @@ static void render_envmap(Render *re, EnvMap *env) short part; /* need a recalc: ortho-render has no correct viewinv */ - Mat4Invert(oldviewinv, re->viewmat); + invert_m4_m4(oldviewinv, re->viewmat); envre= envmap_render_copy(re, env); /* precalc orthmat for object */ - Mat4CpyMat4(orthmat, env->object->obmat); - Mat4Ortho(orthmat); + copy_m4_m4(orthmat, env->object->obmat); + normalize_m4(orthmat); /* need imat later for texture imat */ - Mat4MulMat4(mat, orthmat, re->viewmat); - Mat4Invert(tmat, mat); - Mat3CpyMat4(env->obimat, tmat); + mul_m4_m4m4(mat, orthmat, re->viewmat); + invert_m4_m4(tmat, mat); + copy_m3_m4(env->obimat, tmat); for(part=0; part<6; part++) { if(env->type==ENV_PLANE && part!=1) @@ -412,17 +412,17 @@ static void render_envmap(Render *re, EnvMap *env) re->display_clear(re->dch, envre->result); - Mat4CpyMat4(tmat, orthmat); + copy_m4_m4(tmat, orthmat); envmap_transmatrix(tmat, part); - Mat4Invert(mat, tmat); + invert_m4_m4(mat, tmat); /* mat now is the camera 'viewmat' */ - Mat4CpyMat4(envre->viewmat, mat); - Mat4CpyMat4(envre->viewinv, tmat); + copy_m4_m4(envre->viewmat, mat); + copy_m4_m4(envre->viewinv, tmat); /* we have to correct for the already rotated vertexcoords */ - Mat4MulMat4(tmat, oldviewinv, envre->viewmat); - Mat4Invert(env->imat, tmat); + mul_m4_m4m4(tmat, oldviewinv, envre->viewmat); + invert_m4_m4(env->imat, tmat); env_rotate_scene(envre, tmat, 1); init_render_world(envre); @@ -503,13 +503,13 @@ void make_envmaps(Render *re) float orthmat[4][4], mat[4][4], tmat[4][4]; /* precalc orthmat for object */ - Mat4CpyMat4(orthmat, env->object->obmat); - Mat4Ortho(orthmat); + copy_m4_m4(orthmat, env->object->obmat); + normalize_m4(orthmat); /* need imat later for texture imat */ - Mat4MulMat4(mat, orthmat, re->viewmat); - Mat4Invert(tmat, mat); - Mat3CpyMat4(env->obimat, tmat); + mul_m4_m4m4(mat, orthmat, re->viewmat); + invert_m4_m4(tmat, mat); + copy_m3_m4(env->obimat, tmat); } else { @@ -678,20 +678,20 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe /* rotate to envmap space, if object is set */ VECCOPY(vec, texvec); - if(env->object) Mat3MulVecfl(env->obimat, vec); - else Mat4Mul3Vecfl(R.viewinv, vec); + if(env->object) mul_m3_v3(env->obimat, vec); + else mul_mat3_m4_v3(R.viewinv, vec); face= envcube_isect(env, vec, sco); ibuf= env->cube[face]; if(osatex) { if(env->object) { - Mat3MulVecfl(env->obimat, dxt); - Mat3MulVecfl(env->obimat, dyt); + mul_m3_v3(env->obimat, dxt); + mul_m3_v3(env->obimat, dyt); } else { - Mat4Mul3Vecfl(R.viewinv, dxt); - Mat4Mul3Vecfl(R.viewinv, dyt); + mul_mat3_m4_v3(R.viewinv, dxt); + mul_mat3_m4_v3(R.viewinv, dyt); } set_dxtdyt(dxts, dyts, dxt, dyt, face); imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, texres); @@ -703,9 +703,9 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe texr1.nor= texr2.nor= NULL; - VecAddf(vec, vec, dxt); + add_v3_v3v3(vec, vec, dxt); face1= envcube_isect(env, vec, sco); - VecSubf(vec, vec, dxt); + sub_v3_v3v3(vec, vec, dxt); if(face!=face1) { ibuf= env->cube[face1]; @@ -716,9 +716,9 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe /* here was the nasty bug! results were not zero-ed. FPE! */ - VecAddf(vec, vec, dyt); + add_v3_v3v3(vec, vec, dyt); face1= envcube_isect(env, vec, sco); - VecSubf(vec, vec, dyt); + sub_v3_v3v3(vec, vec, dyt); if(face!=face1) { ibuf= env->cube[face1]; diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 01131f09b96..3d46fdfaaee 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -48,7 +48,7 @@ #include "DNA_scene_types.h" #include "DNA_texture_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_threads.h" diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index d388e81a745..abff8bf2655 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -37,7 +37,7 @@ #include "PIL_time.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_jitter.h" @@ -562,7 +562,7 @@ void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, flo { re->r.cfra= frame; RE_SetCamera(re, camera); - Mat4CpyMat4(mat, re->winmat); + copy_m4_m4(mat, re->winmat); } /* ~~~~~~~~~~~~~~~~ part (tile) calculus ~~~~~~~~~~~~~~~~~~~~~~ */ diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index a15377a8c6d..f62668b84c0 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -36,7 +36,7 @@ #include "DNA_material_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_memarena.h" #include "BLI_threads.h" @@ -165,7 +165,7 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, /* set up view vector */ VECCOPY(shi->view, shi->co); - Normalize(shi->view); + normalize_v3(shi->view); /* cache for shadow */ shi->samplenr++; @@ -181,8 +181,8 @@ static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, /* not a pretty solution, but fixes common cases */ if(shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) { - VecNegf(shi->vn); - VecNegf(shi->vno); + negate_v3(shi->vn); + negate_v3(shi->vno); } /* init material vars */ @@ -311,12 +311,12 @@ static void occ_face(const OccFace *face, float *co, float *normal, float *area) if(co) { if(vlr->v4) - VecLerpf(co, vlr->v1->co, vlr->v3->co, 0.5f); + interp_v3_v3v3(co, vlr->v1->co, vlr->v3->co, 0.5f); else - CalcCent3f(co, vlr->v1->co, vlr->v2->co, vlr->v3->co); + cent_tri_v3(co, vlr->v1->co, vlr->v2->co, vlr->v3->co); if(obi->flag & R_TRANSFORMED) - Mat4MulVecfl(obi->mat, co); + mul_m4_v3(obi->mat, co); } if(normal) { @@ -325,7 +325,7 @@ static void occ_face(const OccFace *face, float *co, float *normal, float *area) normal[2]= -vlr->n[2]; if(obi->flag & R_TRANSFORMED) - Mat3MulVecfl(obi->nmat, normal); + mul_m3_v3(obi->nmat, normal); } if(area) { @@ -335,17 +335,17 @@ static void occ_face(const OccFace *face, float *co, float *normal, float *area) if(vlr->v4) VECCOPY(v4, vlr->v4->co); if(obi->flag & R_TRANSFORMED) { - Mat4MulVecfl(obi->mat, v1); - Mat4MulVecfl(obi->mat, v2); - Mat4MulVecfl(obi->mat, v3); - if(vlr->v4) Mat4MulVecfl(obi->mat, v4); + mul_m4_v3(obi->mat, v1); + mul_m4_v3(obi->mat, v2); + mul_m4_v3(obi->mat, v3); + if(vlr->v4) mul_m4_v3(obi->mat, v4); } /* todo: correct area for instances */ if(vlr->v4) - *area= AreaQ3Dfl(v1, v2, v3, v4); + *area= area_quad_v3(v1, v2, v3, v4); else - *area= AreaT3Dfl(v1, v2, v3); + *area= area_tri_v3(v1, v2, v3); } } @@ -591,7 +591,7 @@ static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, i } if(node->area != 0.0f) - VecMulf(node->co, 1.0f/node->area); + mul_v3_fl(node->co, 1.0f/node->area); /* compute maximum distance from center */ node->dco= 0.0f; @@ -1116,10 +1116,10 @@ static float occ_quad_form_factor(float *p, float *n, float *q0, float *q1, floa normalizef(r2); normalizef(r3); - Crossf(g0, r1, r0); normalizef(g0); - Crossf(g1, r2, r1); normalizef(g1); - Crossf(g2, r3, r2); normalizef(g2); - Crossf(g3, r0, r3); normalizef(g3); + cross_v3_v3v3(g0, r1, r0); normalizef(g0); + cross_v3_v3v3(g1, r2, r1); normalizef(g1); + cross_v3_v3v3(g2, r3, r2); normalizef(g2); + cross_v3_v3v3(g3, r0, r3); normalizef(g3); a1= saacosf(INPR(r0, r1)); a2= saacosf(INPR(r1, r2)); @@ -1151,9 +1151,9 @@ static float occ_form_factor(OccFace *face, float *p, float *n) VECCOPY(v3, vlr->v3->co); if(obi->flag & R_TRANSFORMED) { - Mat4MulVecfl(obi->mat, v1); - Mat4MulVecfl(obi->mat, v2); - Mat4MulVecfl(obi->mat, v3); + mul_m4_v3(obi->mat, v1); + mul_m4_v3(obi->mat, v2); + mul_m4_v3(obi->mat, v3); } if(occ_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) @@ -1162,7 +1162,7 @@ static float occ_form_factor(OccFace *face, float *p, float *n) if(vlr->v4) { VECCOPY(v4, vlr->v4->co); if(obi->flag & R_TRANSFORMED) - Mat4MulVecfl(obi->mat, v4); + mul_m4_v3(obi->mat, v4); if(occ_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) contrib += occ_quad_form_factor(p, n, q0, q1, q2, q3); @@ -1269,7 +1269,7 @@ static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude, float } if(occ) *occ= resultocc; - if(bentn) Normalize(bentn); + if(bentn) normalize_v3(bentn); } static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass) @@ -1282,7 +1282,7 @@ static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass) for(pass=0; pass<totpass; pass++) { for(i=0; i<tree->totface; i++) { occ_face(&tree->face[i], co, n, NULL); - VecNegf(n); + negate_v3(n); VECADDFAC(co, co, n, 1e-8f); occ_lookup(tree, 0, &tree->face[i], co, n, &occ[i], NULL); @@ -1315,7 +1315,7 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f aocolor= WO_AOPLAIN; VECCOPY(nn, n); - VecNegf(nn); + negate_v3(nn); occ_lookup(tree, thread, exclude, co, nn, &occ, (aocolor)? bn: NULL); @@ -1347,7 +1347,7 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f } #endif - VecMulf(skycol, occlusion); + mul_v3_fl(skycol, occlusion); } else { skycol[0]= occlusion; @@ -1477,7 +1477,7 @@ static void sample_occ_surface(ShadeInput *shi) co3= mesh->co[face[2]]; co4= (face[3])? mesh->co[face[3]]: NULL; - InterpWeightsQ3Dfl(co1, co2, co3, co4, strand->vert->co, w); + interp_weights_face_v3( w,co1, co2, co3, co4, strand->vert->co); shi->ao[0]= shi->ao[1]= shi->ao[2]= 0.0f; VECADDFAC(shi->ao, shi->ao, mesh->col[face[0]], w[0]); @@ -1512,14 +1512,14 @@ static void *exec_strandsurface_sample(void *data) if(face[3]) { co4= mesh->co[face[3]]; - VecLerpf(co, co1, co3, 0.5f); - CalcNormFloat4(co1, co2, co3, co4, n); + interp_v3_v3v3(co, co1, co3, 0.5f); + normal_quad_v3( n,co1, co2, co3, co4); } else { - CalcCent3f(co, co1, co2, co3); - CalcNormFloat(co1, co2, co3, n); + cent_tri_v3(co, co1, co2, co3); + normal_tri_v3( n,co1, co2, co3); } - VecNegf(n); + negate_v3(n); sample_occ_tree(re, re->occlusiontree, NULL, co, n, othread->thread, 0, col); VECCOPY(othread->facecol[a], col); @@ -1597,7 +1597,7 @@ void make_occ_tree(Render *re) for(a=0; a<mesh->totvert; a++) if(count[a]) - VecMulf(mesh->col[a], 1.0f/count[a]); + mul_v3_fl(mesh->col[a], 1.0f/count[a]); MEM_freeN(count); MEM_freeN(facecol); diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 5dcfb12a080..9c4c83a82f9 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -53,7 +53,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" #include "BLI_threads.h" @@ -95,7 +95,7 @@ - tiles, rect, baking - layers/tiles optionally to disk or directly in Render Result -4) Composit Render Result +4) Composite Render Result - also read external files etc 5) Image Files @@ -1264,7 +1264,7 @@ void RE_SetWindow(Render *re, rctf *viewplane, float clipsta, float clipend) re->clipend= clipend; re->r.mode &= ~R_ORTHO; - i_window(re->viewplane.xmin, re->viewplane.xmax, re->viewplane.ymin, re->viewplane.ymax, re->clipsta, re->clipend, re->winmat); + perspective_m4( re->winmat,re->viewplane.xmin, re->viewplane.xmax, re->viewplane.ymin, re->viewplane.ymax, re->clipsta, re->clipend); } @@ -1277,14 +1277,14 @@ void RE_SetOrtho(Render *re, rctf *viewplane, float clipsta, float clipend) re->clipend= clipend; re->r.mode |= R_ORTHO; - i_ortho(re->viewplane.xmin, re->viewplane.xmax, re->viewplane.ymin, re->viewplane.ymax, re->clipsta, re->clipend, re->winmat); + orthographic_m4( re->winmat,re->viewplane.xmin, re->viewplane.xmax, re->viewplane.ymin, re->viewplane.ymax, re->clipsta, re->clipend); } void RE_SetView(Render *re, float mat[][4]) { /* re->ok flag? */ - Mat4CpyMat4(re->viewmat, mat); - Mat4Invert(re->viewinv, re->viewmat); + copy_m4_m4(re->viewmat, mat); + invert_m4_m4(re->viewinv, re->viewmat); } /* image and movie output has to move to either imbuf or kernel */ @@ -1511,7 +1511,7 @@ static RenderPart *find_next_pano_slice(Render *re, int *minx, rctf *viewplane) R.viewplane.xmin = viewplane->xmin + R.panodxv; R.viewplane.xmax = viewplane->xmax + R.panodxv; RE_SetWindow(re, &R.viewplane, R.clipsta, R.clipend); - Mat4CpyMat4(R.winmat, re->winmat); + copy_m4_m4(R.winmat, re->winmat); /* rotate database according to part coordinates */ project_renderdata(re, projectverto, 1, -R.panodxp*phi, 1); diff --git a/source/blender/render/intern/source/pixelblending.c b/source/blender/render/intern/source/pixelblending.c index 0e453d461ab..da9a698291c 100644 --- a/source/blender/render/intern/source/pixelblending.c +++ b/source/blender/render/intern/source/pixelblending.c @@ -34,7 +34,7 @@ #include <string.h> /* global includes */ -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" /* own includes */ diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c index de3a50acddf..d4b7c403f50 100644 --- a/source/blender/render/intern/source/pixelshading.c +++ b/source/blender/render/intern/source/pixelshading.c @@ -27,7 +27,7 @@ #include <float.h> #include <math.h> #include <string.h> -#include "BLI_arithb.h" +#include "BLI_math.h" /* External modules: */ #include "IMB_imbuf_types.h" @@ -155,7 +155,7 @@ static void render_lighting_halo(HaloRen *har, float *colf) /* rotate view to lampspace */ VECCOPY(lvrot, lv); - Mat3MulVecfl(lar->imat, lvrot); + mul_m3_v3(lar->imat, lvrot); x= MAX2(fabs(lvrot[0]/lvrot[2]) , fabs(lvrot[1]/lvrot[2])); /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */ @@ -553,7 +553,7 @@ void shadeSkyView(float *colf, float *rco, float *view, float *dxyview, short th VECCOPY(lo, view); if(R.wrld.skytype & WO_SKYREAL) { - Mat3MulVecfl(R.imat, lo); + mul_m3_v3(R.imat, lo); SWAP(float, lo[1], lo[2]); @@ -594,11 +594,11 @@ void shadeSunView(float *colf, float *view) if(do_init) { VECCOPY(sview, view); - Normalize(sview); - Mat3MulVecfl(R.imat, sview); + normalize_v3(sview); + mul_m3_v3(R.imat, sview); if (sview[2] < 0.0) sview[2] = 0.0; - Normalize(sview); + normalize_v3(sview); do_init= 0; } @@ -654,7 +654,7 @@ void shadeSkyPixel(float *collector, float fx, float fy, short thread) } else { calc_view_vector(view, fx, fy); - fac= Normalize(view); + fac= normalize_v3(view); if(R.wrld.skytype & WO_SKYTEX) { dxyview[0]= -R.viewdx/fac; @@ -677,8 +677,8 @@ void shadeAtmPixel(struct SunSky *sunsky, float *collector, float fx, float fy, float view[3]; calc_view_vector(view, fx, fy); - Normalize(view); - /*Mat3MulVecfl(R.imat, view);*/ + normalize_v3(view); + /*mul_m3_v3(R.imat, view);*/ AtmospherePixleShader(sunsky, view, distance, collector); } diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index 2b3e6047af4..9ce77f751c0 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -29,7 +29,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_kdopbvh.h" @@ -106,7 +106,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa /* init everything */ if (!psys || !ob || !pd) return; - Mat4MulMat4(obview, re->viewinv, ob->obmat); + mul_m4_m4m4(obview, re->viewinv, ob->obmat); /* Just to create a valid rendering context for particles */ psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, 0); @@ -119,7 +119,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa } /* in case ob->imat isn't up-to-date */ - Mat4Invert(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); total_particles = psys->totpart+psys->totchild; psys->lattice=psys_get_lattice(&sim); @@ -140,11 +140,11 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa VECCOPY(partco, state.co); if (pd->psys_cache_space == TEX_PD_OBJECTSPACE) - Mat4MulVecfl(ob->imat, partco); + mul_m4_v3(ob->imat, partco); else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) { float obloc[3]; VECCOPY(obloc, ob->loc); - VecSubf(partco, partco, obloc); + sub_v3_v3v3(partco, partco, obloc); } else { /* TEX_PD_WORLDSPACE */ } @@ -190,7 +190,6 @@ static void pointdensity_cache_object(Render *re, PointDensity *pd, Object *ob) int i; DerivedMesh *dm; MVert *mvert = NULL; - float cam_mat[4][4]; dm = mesh_create_derived_render(re->scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); mvert= dm->getVertArray(dm); /* local object space */ @@ -209,12 +208,12 @@ static void pointdensity_cache_object(Render *re, PointDensity *pd, Object *ob) case TEX_PD_OBJECTSPACE: break; case TEX_PD_OBJECTLOC: - Mat4MulVecfl(ob->obmat, co); - VecSubf(co, co, ob->loc); + mul_m4_v3(ob->obmat, co); + sub_v3_v3v3(co, co, ob->loc); break; case TEX_PD_WORLDSPACE: default: - Mat4MulVecfl(ob->obmat, co); + mul_m4_v3(ob->obmat, co); break; } @@ -391,7 +390,7 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr); if (num > 0) { age /= num; - VecMulf(vec, 1.0f/num); + mul_v3_fl(vec, 1.0f/num); } /* reset */ @@ -424,7 +423,7 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) num = BLI_bvhtree_range_query(pd->point_tree, co, pd->radius, accum_density, &pdr); if (num > 0) { age /= num; - VecMulf(vec, 1.0f/num); + mul_v3_fl(vec, 1.0f/num); } texres->tin = density; @@ -448,7 +447,7 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) break; case TEX_PD_COLOR_PARTSPEED: { - float speed = VecLength(vec) * pd->speed_scale; + float speed = len_v3(vec) * pd->speed_scale; if (pd->coba) { if (do_colorband(pd->coba, speed, col)) { @@ -462,7 +461,7 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres) } case TEX_PD_COLOR_PARTVEL: texres->talpha= 1; - VecMulf(vec, pd->speed_scale); + mul_v3_fl(vec, pd->speed_scale); VECCOPY(&texres->tr, vec); texres->ta = texres->tin; break; diff --git a/source/blender/render/intern/source/rayobject_blibvh.c b/source/blender/render/intern/source/rayobject_blibvh.c index 3fd71862f54..3579eb9007f 100644 --- a/source/blender/render/intern/source/rayobject_blibvh.c +++ b/source/blender/render/intern/source/rayobject_blibvh.c @@ -31,7 +31,7 @@ #include "MEM_guardedalloc.h" #include "BKE_utildefines.h" #include "BLI_kdopbvh.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "RE_raytrace.h" #include "render_types.h" #include "rayobject.h" @@ -120,7 +120,7 @@ static int RE_rayobject_blibvh_intersect(RayObject *o, Isect *isec) data.leafs = obj->leafs; VECCOPY(dir, isec->vec); - Normalize(dir); + normalize_v3(dir); hit.index = 0; hit.dist = isec->labda*isec->dist; diff --git a/source/blender/render/intern/source/rayobject_instance.c b/source/blender/render/intern/source/rayobject_instance.c index e2f4dc5a9dd..9ed184e532c 100644 --- a/source/blender/render/intern/source/rayobject_instance.c +++ b/source/blender/render/intern/source/rayobject_instance.c @@ -30,7 +30,7 @@ #include "MEM_guardedalloc.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "RE_raytrace.h" #include "rayobject.h" @@ -79,8 +79,8 @@ RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4], obj->ob = ob; obj->target_ob = target_ob; - Mat4CpyMat4(obj->target2global, transform); - Mat4Invert(obj->global2target, obj->target2global); + copy_m4_m4(obj->target2global, transform); + invert_m4_m4(obj->global2target, obj->target2global); return RE_rayobject_unalignRayAPI((RayObject*) obj); } @@ -111,10 +111,10 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) //Transform to target coordinates system VECADD( isec->vec, isec->vec, isec->start ); - Mat4MulVecfl(obj->global2target, isec->start); - Mat4MulVecfl(obj->global2target, isec->vec ); + mul_m4_v3(obj->global2target, isec->start); + mul_m4_v3(obj->global2target, isec->vec ); - isec->dist = VecLenf( isec->start, isec->vec ); + isec->dist = len_v3v3( isec->start, isec->vec ); VECSUB( isec->vec, isec->vec, isec->start ); isec->labda *= isec->dist / dist; @@ -194,7 +194,7 @@ static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max) for(i=0; i<8; i++) { for(j=0; j<3; j++) t[j] = i&(1<<j) ? M[j] : m[j]; - Mat4MulVecfl(obj->target2global, t); + mul_m4_v3(obj->target2global, t); DO_MINMAX(t, min, max); } } diff --git a/source/blender/render/intern/source/rayobject_octree.c b/source/blender/render/intern/source/rayobject_octree.c index 2f0a1a3f53b..7c29db6a4bb 100644 --- a/source/blender/render/intern/source/rayobject_octree.c +++ b/source/blender/render/intern/source/rayobject_octree.c @@ -40,7 +40,7 @@ #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "rayobject.h" @@ -226,7 +226,7 @@ static int face_in_node(RayFace *face, short x, short y, short z, float rtf[][3] // init static vars if(face) { - CalcNormFloat(rtf[0], rtf[1], rtf[2], nor); + normal_tri_v3( nor,rtf[0], rtf[1], rtf[2]); d= -nor[0]*rtf[0][0] - nor[1]*rtf[0][1] - nor[2]*rtf[0][2]; return 0; } diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 7043837166a..85442480a9c 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -41,7 +41,7 @@ #include "BKE_node.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_jitter.h" #include "BLI_rand.h" @@ -397,11 +397,11 @@ static void makeraytree_single(Render *re) RE_rayface_from_vlak(face, obi, vlr); if((obi->flag & R_TRANSFORMED)) { - Mat4MulVecfl(obi->mat, face->v1); - Mat4MulVecfl(obi->mat, face->v2); - Mat4MulVecfl(obi->mat, face->v3); + mul_m4_v3(obi->mat, face->v1); + mul_m4_v3(obi->mat, face->v2); + mul_m4_v3(obi->mat, face->v3); if(RE_rayface_isQuad(face)) - Mat4MulVecfl(obi->mat, face->v4); + mul_m4_v3(obi->mat, face->v4); } RE_rayobject_add( raytree, RE_rayobject_unalignRayFace(face) ); @@ -481,7 +481,7 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr) shi->co[1]= is->start[1]+is->labda*(shi->view[1]); shi->co[2]= is->start[2]+is->labda*(shi->view[2]); - Normalize(shi->view); + normalize_v3(shi->view); shi->obi= obi; shi->obr= obi->obr; @@ -674,7 +674,7 @@ static void ray_fadeout_endcolor(float *col, ShadeInput *origshi, ShadeInput *sh VECCOPY(col, shr->combined); } else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) { VECCOPY(shi->view, vec); - Normalize(shi->view); + normalize_v3(shi->view); shadeSkyView(col, isec->start, shi->view, NULL, shi->thread); shadeSunView(col, shi->view); @@ -686,7 +686,7 @@ static void ray_fadeout(Isect *is, ShadeInput *shi, float *col, float *blendcol, /* if fading out, linear blend against fade color */ float blendfac; - blendfac = 1.0 - VecLenf(shi->co, is->start)/dist_mir; + blendfac = 1.0 - len_v3v3(shi->co, is->start)/dist_mir; col[0] = col[0]*blendfac + (1.0 - blendfac)*blendcol[0]; col[1] = col[1]*blendfac + (1.0 - blendfac)*blendcol[1]; @@ -1297,15 +1297,15 @@ static void trace_refract(float *col, ShadeInput *shi, ShadeResult *shr) /* get a quasi-random vector from a phong-weighted disc */ QMC_samplePhong(samp3d, qsa, shi->thread, samples, blur); - VecOrthoBasisf(v_refract, orthx, orthy); - VecMulf(orthx, samp3d[0]); - VecMulf(orthy, samp3d[1]); + ortho_basis_v3v3_v3( orthx, orthy,v_refract); + mul_v3_fl(orthx, samp3d[0]); + mul_v3_fl(orthy, samp3d[1]); /* and perturb the refraction vector in it */ - VecAddf(v_refract_new, v_refract, orthx); - VecAddf(v_refract_new, v_refract_new, orthy); + add_v3_v3v3(v_refract_new, v_refract, orthx); + add_v3_v3v3(v_refract_new, v_refract_new, orthy); - Normalize(v_refract_new); + normalize_v3(v_refract_new); } else { /* no blurriness, use the original normal */ VECCOPY(v_refract_new, v_refract); @@ -1384,20 +1384,20 @@ static void trace_reflect(float *col, ShadeInput *shi, ShadeResult *shr, float f /* find the normal's perpendicular plane, blurring along tangents * if tangent shading enabled */ if (shi->mat->mode & (MA_TANGENT_V)) { - Crossf(orthx, shi->vn, shi->tang); // bitangent + cross_v3_v3v3(orthx, shi->vn, shi->tang); // bitangent VECCOPY(orthy, shi->tang); - VecMulf(orthx, samp3d[0]); - VecMulf(orthy, samp3d[1]*aniso); + mul_v3_fl(orthx, samp3d[0]); + mul_v3_fl(orthy, samp3d[1]*aniso); } else { - VecOrthoBasisf(shi->vn, orthx, orthy); - VecMulf(orthx, samp3d[0]); - VecMulf(orthy, samp3d[1]); + ortho_basis_v3v3_v3( orthx, orthy,shi->vn); + mul_v3_fl(orthx, samp3d[0]); + mul_v3_fl(orthy, samp3d[1]); } /* and perturb the normal in it */ - VecAddf(v_nor_new, shi->vn, orthx); - VecAddf(v_nor_new, v_nor_new, orthy); - Normalize(v_nor_new); + add_v3_v3v3(v_nor_new, shi->vn, orthx); + add_v3_v3v3(v_nor_new, v_nor_new, orthy); + normalize_v3(v_nor_new); } else { /* no blurriness, use the original normal */ VECCOPY(v_nor_new, shi->vn); @@ -1706,7 +1706,7 @@ static void DS_energy(float *sphere, int tot, float *vec) res[0]= res[1]= res[2]= 0.0f; for(a=0, fp=sphere; a<tot; a++, fp+=3) { - VecSubf(force, vec, fp); + sub_v3_v3v3(force, vec, fp); fac= force[0]*force[0] + force[1]*force[1] + force[2]*force[2]; if(fac!=0.0f) { fac= 1.0f/fac; @@ -1716,9 +1716,9 @@ static void DS_energy(float *sphere, int tot, float *vec) } } - VecMulf(res, 0.5); - VecAddf(vec, vec, res); - Normalize(vec); + mul_v3_fl(res, 0.5); + add_v3_v3v3(vec, vec, res); + normalize_v3(vec); } @@ -1881,7 +1881,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *shadfac) VECCOPY(nrm, shi->facenor); } - VecOrthoBasisf(nrm, up, side); + ortho_basis_v3v3_v3( up, side,nrm); /* sampling init */ if (R.wrld.ao_samp_method==WO_AOSAMP_HALTON) { @@ -1908,7 +1908,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *shadfac) dir[1] = (samp3d[0]*up[1] + samp3d[1]*side[1] + samp3d[2]*nrm[1]); dir[2] = (samp3d[0]*up[2] + samp3d[1]*side[2] + samp3d[2]*nrm[2]); - Normalize(dir); + normalize_v3(dir); isec.vec[0] = -dir[0]; isec.vec[1] = -dir[1]; @@ -1928,7 +1928,7 @@ static void ray_ao_qmc(ShadeInput *shi, float *shadfac) view[0]= -dir[0]; view[1]= -dir[1]; view[2]= -dir[2]; - Normalize(view); + normalize_v3(view); if(aocolor==WO_AOSKYCOL) { skyfac= 0.5*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]); @@ -2064,7 +2064,7 @@ static void ray_ao_spheresamp(ShadeInput *shi, float *shadfac) view[0]= -vec[0]; view[1]= -vec[1]; view[2]= -vec[2]; - Normalize(view); + normalize_v3(view); if(aocolor==WO_AOSKYCOL) { fac= 0.5*(1.0f+view[0]*R.grvec[0]+ view[1]*R.grvec[1]+ view[2]*R.grvec[2]); @@ -2230,8 +2230,8 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float * v[0] = co[0] - lampco[0]; v[1] = co[1] - lampco[1]; v[2] = co[2] - lampco[2]; - Normalize(v); - VecOrthoBasisf(v, ru, rv); + normalize_v3(v); + ortho_basis_v3v3_v3( ru, rv,v); /* sampling, returns quasi-random vector in area_size disc */ QMC_sampleDisc(samp3d, qsa, shi->thread, samples,lar->area_size); @@ -2248,7 +2248,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float * QMC_sampleRect(samp3d, qsa, shi->thread, samples, lar->area_size, lar->area_sizey); /* align samples to lamp vector */ - Mat3MulVecfl(lar->mat, samp3d); + mul_m3_v3(lar->mat, samp3d); } end[0] = vec[0]+samp3d[0]; end[1] = vec[1]+samp3d[1]; @@ -2259,11 +2259,11 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float * if(shi->strand) { /* bias away somewhat to avoid self intersection */ - float jitbias= 0.5f*(VecLength(shi->dxco) + VecLength(shi->dyco)); + float jitbias= 0.5f*(len_v3(shi->dxco) + len_v3(shi->dyco)); float v[3]; VECSUB(v, co, end); - Normalize(v); + normalize_v3(v); co[0] -= jitbias*v[0]; co[1] -= jitbias*v[1]; @@ -2274,7 +2274,7 @@ static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, float *lampco, float * isec->vec[0] = end[0]-isec->start[0]; isec->vec[1] = end[1]-isec->start[1]; isec->vec[2] = end[2]-isec->start[2]; - isec->labda = 1.0f; // * Normalize(isec->vec); + isec->labda = 1.0f; // * normalize_v3(isec->vec); /* trace the ray */ if(isec->mode==RE_RAY_SHADOW_TRA) { @@ -2370,7 +2370,7 @@ static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, float *lampco, floa vec[0]= jitlamp[0]; vec[1]= jitlamp[1]; vec[2]= 0.0f; - Mat3MulVecfl(lar->mat, vec); + mul_m3_v3(lar->mat, vec); /* set start and vec */ isec->vec[0] = vec[0]+lampco[0]-isec->start[0]; @@ -2537,7 +2537,7 @@ static void ray_translucent(ShadeInput *shi, LampRen *lar, float *distfac, float co[1]= isec.start[1]+isec.labda*(isec.vec[1]); co[2]= isec.start[2]+isec.labda*(isec.vec[2]); - *distfac= VecLength(isec.vec); + *distfac= len_v3(isec.vec); } else *distfac= 0.0f; diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 6c18592b8d2..cae6c640f8b 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -36,7 +36,7 @@ /* External modules: */ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_jitter.h" #include "BLI_rand.h" @@ -1498,13 +1498,13 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe VECCOPY(nor, shi->facenor); calc_view_vector(shi->facenor, sx, sy); - Normalize(shi->facenor); + normalize_v3(shi->facenor); shade_input_set_viewco(shi, x, y, sx, sy, z); - orthoarea= VecLength(shi->dxco)*VecLength(shi->dyco); + orthoarea= len_v3(shi->dxco)*len_v3(shi->dyco); VECCOPY(shi->facenor, nor); shade_input_set_viewco(shi, x, y, sx, sy, z); - *area= VecLength(shi->dxco)*VecLength(shi->dyco); + *area= len_v3(shi->dxco)*len_v3(shi->dyco); *area= MIN2(*area, 2.0f*orthoarea); shade_input_set_uv(shi); @@ -1516,8 +1516,8 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe /* not a pretty solution, but fixes common cases */ if(shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) { - VecNegf(shi->vn); - VecNegf(shi->vno); + negate_v3(shi->vn); + negate_v3(shi->vno); } /* if nodetree, use the material that we are currently preprocessing @@ -2148,24 +2148,24 @@ static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int quad, int /* bitangent */ if(tvn && ttang) { VECCOPY(mat[0], ttang); - Crossf(mat[1], tvn, ttang); + cross_v3_v3v3(mat[1], tvn, ttang); VECCOPY(mat[2], tvn); } else { VECCOPY(mat[0], shi->nmaptang); - Crossf(mat[1], shi->vn, shi->nmaptang); + cross_v3_v3v3(mat[1], shi->vn, shi->nmaptang); VECCOPY(mat[2], shi->vn); } - Mat3Inv(imat, mat); - Mat3MulVecfl(imat, nor); + invert_m3_m3(imat, mat); + mul_m3_v3(imat, nor); } else if(R.r.bake_normal_space == R_BAKE_SPACE_OBJECT) - Mat4Mul3Vecfl(ob->imat, nor); /* ob->imat includes viewinv! */ + mul_mat3_m4_v3(ob->imat, nor); /* ob->imat includes viewinv! */ else if(R.r.bake_normal_space == R_BAKE_SPACE_WORLD) - Mat4Mul3Vecfl(R.viewinv, nor); + mul_mat3_m4_v3(R.viewinv, nor); - Normalize(nor); /* in case object has scaling */ + normalize_v3(nor); /* in case object has scaling */ shr.combined[0]= nor[0]/2.0f + 0.5f; shr.combined[1]= 0.5f - nor[1]/2.0f; @@ -2278,7 +2278,7 @@ static int bake_intersect_tree(RayObject* raytree, Isect* isect, float *start, f hitco[1] = isect->start[1] + isect->labda*isect->vec[1]; hitco[2] = isect->start[2] + isect->labda*isect->vec[2]; - *dist= VecLenf(start, hitco); + *dist= len_v3v3(start, hitco); } return hit; @@ -2330,8 +2330,8 @@ static void bake_set_vlr_dxyco(BakeShade *bs, float *uv1, float *uv2, float *uv3 } if(bs->obi->flag & R_TRANSFORMED) { - Mat3MulVecfl(bs->obi->nmat, bs->dxco); - Mat3MulVecfl(bs->obi->nmat, bs->dyco); + mul_m3_v3(bs->obi->nmat, bs->dxco); + mul_m3_v3(bs->obi->nmat, bs->dyco); } } @@ -2370,7 +2370,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) shi->co[2]= l*v3[2]+u*v1[2]+v*v2[2]; if(obi->flag & R_TRANSFORMED) - Mat4MulVecfl(obi->mat, shi->co); + mul_m4_v3(obi->mat, shi->co); VECCOPY(shi->dxco, bs->dxco); VECCOPY(shi->dyco, bs->dyco); @@ -2406,7 +2406,7 @@ static void do_bake_shade(void *handle, int x, int y, float u, float v) isec.userdata= bs; if(bake_intersect_tree(R.raytree, &isec, shi->co, shi->vn, sign, co, &dist)) { - if(!hit || VecLenf(shi->co, co) < VecLenf(shi->co, minco)) { + if(!hit || len_v3v3(shi->co, co) < len_v3v3(shi->co, minco)) { minisec= isec; mindist= dist; VECCOPY(minco, co); diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index 54863ef3295..75e58648cd5 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -60,7 +60,7 @@ #include "MEM_guardedalloc.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_memarena.h" @@ -448,8 +448,8 @@ int RE_vlakren_get_normal(Render *re, ObjectInstanceRen *obi, VlakRen *vlr, floa if(obi->flag & R_TRANSFORMED) { VECCOPY(nor, vlr->n); - Mat3MulVecfl(nmat, nor); - Normalize(nor); + mul_m3_v3(nmat, nor); + normalize_v3(nor); } else VECCOPY(nor, vlr->n); @@ -462,7 +462,7 @@ int RE_vlakren_get_normal(Render *re, ObjectInstanceRen *obi, VlakRen *vlr, floa else { VECCOPY(v1, vlr->v1->co); if(obi->flag & R_TRANSFORMED) - Mat4MulVecfl(obi->mat, v1); + mul_m4_v3(obi->mat, v1); if(INPR(v1, nor) < 0.0f) { flipped= 1; } @@ -995,12 +995,12 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f har->sin= sin(zn); har->cos= cos(zn); - zn= VecLenf(vec1, vec); + zn= len_v3v3(vec1, vec); har->hasize= vectsize*zn + (1.0-vectsize)*hasize; - VecSubf(har->no, vec, vec1); - Normalize(har->no); + sub_v3_v3v3(har->no, vec, vec1); + normalize_v3(har->no); } if(ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; @@ -1035,7 +1035,7 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, float *vec, f /* texvec[0]+= imatbase->ivec[0]; */ /* texvec[1]+= imatbase->ivec[1]; */ /* texvec[2]+= imatbase->ivec[2]; */ - /* Mat3MulVecfl(imatbase->imat, texvec); */ + /* mul_m3_v3(imatbase->imat, texvec); */ } else { if(orco) { @@ -1108,12 +1108,12 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater har->sin= sin(zn); har->cos= cos(zn); - zn= VecLenf(vec1, vec)*0.5; + zn= len_v3v3(vec1, vec)*0.5; har->hasize= vectsize*zn + (1.0-vectsize)*hasize; - VecSubf(har->no, vec, vec1); - Normalize(har->no); + sub_v3_v3v3(har->no, vec, vec1); + normalize_v3(har->no); } if(ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA; @@ -1149,13 +1149,13 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater if(mtex->object){ float imat[4][4]; /* imat should really be cached somewhere before this */ - Mat4Invert(imat,mtex->object->obmat); - Mat4MulVecfl(imat,texvec); + invert_m4_m4(imat,mtex->object->obmat); + mul_m4_v3(imat,texvec); } /* texvec[0]+= imatbase->ivec[0]; */ /* texvec[1]+= imatbase->ivec[1]; */ /* texvec[2]+= imatbase->ivec[2]; */ - /* Mat3MulVecfl(imatbase->imat, texvec); */ + /* mul_m3_v3(imatbase->imat, texvec); */ } else if(mtex->texco & TEXCO_GLOB){ VECCOPY(texvec,vec); @@ -1349,10 +1349,10 @@ ObjectInstanceRen *RE_addRenderInstance(Render *re, ObjectRen *obr, Object *ob, obi->lay= lay; if(mat) { - Mat4CpyMat4(obi->mat, mat); - Mat3CpyMat4(mat3, mat); - Mat3Inv(obi->nmat, mat3); - Mat3Transp(obi->nmat); + copy_m4_m4(obi->mat, mat); + copy_m3_m4(mat3, mat); + invert_m3_m3(obi->nmat, mat3); + transpose_m3(obi->nmat); obi->flag |= R_DUPLI_TRANSFORMED; } @@ -1395,14 +1395,14 @@ int clip_render_object(float boundbox[][3], float *bounds, float winmat[][4]) float mat[4][4], vec[4]; int a, fl, flag= -1; - Mat4CpyMat4(mat, winmat); + copy_m4_m4(mat, winmat); for(a=0; a<8; a++) { vec[0]= (a & 1)? boundbox[0][0]: boundbox[1][0]; vec[1]= (a & 2)? boundbox[0][1]: boundbox[1][1]; vec[2]= (a & 4)? boundbox[0][2]: boundbox[1][2]; vec[3]= 1.0; - Mat4MulVec4fl(mat, vec); + mul_m4_v4(mat, vec); fl= 0; if(bounds) { diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 50e0321a6eb..f8428680135 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -37,7 +37,7 @@ #include "BKE_scene.h" #include "BKE_utildefines.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_jitter.h" #include "BLI_memarena.h" @@ -613,7 +613,7 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) char *clipflag; minz= 1.0e30f; maxz= -1.0e30f; - Mat4CpyMat4(viewmat, lar->shb->viewmat); + copy_m4_m4(viewmat, lar->shb->viewmat); if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay; @@ -628,9 +628,9 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) obr= obi->obr; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obviewmat, obi->mat, viewmat); + mul_m4_m4m4(obviewmat, obi->mat, viewmat); else - Mat4CpyMat4(obviewmat, viewmat); + copy_m4_m4(obviewmat, viewmat); memset(clipflag, 0, sizeof(char)*obr->totvert); @@ -661,7 +661,7 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) if(clipflag[a]) { VECCOPY(vec, ver->co); - Mat4MulVecfl(obviewmat, vec); + mul_m4_v3(obviewmat, vec); /* Z on visible side of lamp space */ if(vec[2] < 0.0f) { float inpr, z= -vec[2]; @@ -669,7 +669,7 @@ static void shadowbuf_autoclip(Render *re, LampRen *lar) /* since vec is rotated in lampspace, this is how to get the cosine of angle */ /* precision is set 20% larger */ vec[2]*= 1.2f; - Normalize(vec); + normalize_v3(vec); inpr= - vec[2]; if(inpr>=lar->spotsi) { @@ -764,8 +764,8 @@ void makeshadowbuf(Render *re, LampRen *lar) shb->pixsize= (shb->d)/temp; wsize= shb->pixsize*(shb->size/2.0); - i_window(-wsize, wsize, -wsize, wsize, shb->d, shb->clipend, shb->winmat); - Mat4MulMat4(shb->persmat, shb->viewmat, shb->winmat); + perspective_m4( shb->winmat,-wsize, wsize, -wsize, wsize, shb->d, shb->clipend); + mul_m4_m4m4(shb->persmat, shb->viewmat, shb->winmat); if(ELEM3(lar->buftype, LA_SHADBUF_REGULAR, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) { shb->totbuf= lar->buffers; @@ -1107,7 +1107,7 @@ float testshadowbuf(Render *re, ShadBuf *shb, float *rco, float *dxco, float *dy VECCOPY(co, rco); co[3]= 1.0f; - Mat4MulVec4fl(shb->persmat, co); /* rational hom co */ + mul_m4_v4(shb->persmat, co); /* rational hom co */ xs1= siz*(1.0f+co[0]/co[3]); ys1= siz*(1.0f+co[1]/co[3]); @@ -1148,7 +1148,7 @@ float testshadowbuf(Render *re, ShadBuf *shb, float *rco, float *dxco, float *dy co[1]= rco[1]+dxco[1]; co[2]= rco[2]+dxco[2]; co[3]= 1.0; - Mat4MulVec4fl(shb->persmat,co); /* rational hom co */ + mul_m4_v4(shb->persmat,co); /* rational hom co */ dx[0]= xs1- siz*(1.0+co[0]/co[3]); dx[1]= ys1- siz*(1.0+co[1]/co[3]); @@ -1156,7 +1156,7 @@ float testshadowbuf(Render *re, ShadBuf *shb, float *rco, float *dxco, float *dy co[1]= rco[1]+dyco[1]; co[2]= rco[2]+dyco[2]; co[3]= 1.0; - Mat4MulVec4fl(shb->persmat,co); /* rational hom co */ + mul_m4_v4(shb->persmat,co); /* rational hom co */ dy[0]= xs1- siz*(1.0+co[0]/co[3]); dy[1]= ys1- siz*(1.0+co[1]/co[3]); @@ -1292,7 +1292,7 @@ float shadow_halo(LampRen *lar, float *p1, float *p2) co[1]= p1[1]; co[2]= p1[2]/lar->sh_zfac; co[3]= 1.0; - Mat4MulVec4fl(shb->winmat, co); /* rational hom co */ + mul_m4_v4(shb->winmat, co); /* rational hom co */ xf1= siz*(1.0+co[0]/co[3]); yf1= siz*(1.0+co[1]/co[3]); zf1= (co[2]/co[3]); @@ -1302,7 +1302,7 @@ float shadow_halo(LampRen *lar, float *p1, float *p2) co[1]= p2[1]; co[2]= p2[2]/lar->sh_zfac; co[3]= 1.0; - Mat4MulVec4fl(shb->winmat, co); /* rational hom co */ + mul_m4_v4(shb->winmat, co); /* rational hom co */ xf2= siz*(1.0+co[0]/co[3]); yf2= siz*(1.0+co[1]/co[3]); zf2= (co[2]/co[3]); @@ -1635,9 +1635,9 @@ static void bspface_init_strand(BSPFace *face) face->radline= 0.5f*VecLen2f(face->v1, face->v2); - VecMidf(face->vec1, face->v1, face->v2); + mid_v3_v3v3(face->vec1, face->v1, face->v2); if(face->v4) - VecMidf(face->vec2, face->v3, face->v4); + mid_v3_v3v3(face->vec2, face->v3, face->v4); else VECCOPY(face->vec2, face->v3); @@ -1659,7 +1659,7 @@ static int point_behind_strand(float *p, BSPFace *face) /* v1 - v2 is radius, v1 - v3 length */ float dist, rc[2], pt[2]; - /* using code from PdistVL2Dfl(), distance vec to line-piece */ + /* using code from dist_to_line_segment_v2(), distance vec to line-piece */ if(face->len==0.0f) { rc[0]= p[0]-face->vec1[0]; @@ -1977,9 +1977,9 @@ static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root) obr= obi->obr; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(winmat, obi->mat, shb->persmat); + mul_m4_m4m4(winmat, obi->mat, shb->persmat); else - Mat4CpyMat4(winmat, shb->persmat); + copy_m4_m4(winmat, shb->persmat); for(a=0; a<obr->totvlak; a++) { @@ -2055,7 +2055,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v RE_vlakren_get_normal(&R, obi, vlr, nor); VECCOPY(v1, vlr->v1->co); if(obi->flag & R_TRANSFORMED) - Mat4MulVecfl(obi->mat, v1); + mul_m4_v3(obi->mat, v1); /* from shadepixel() */ dface= v1[0]*nor[0] + v1[1]*nor[1] + v1[2]*nor[2]; @@ -2093,7 +2093,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v } /* move 3d vector to lampbuf */ - Mat4MulVec4fl(shb->persmat, hoco); /* rational hom co */ + mul_m4_v4(shb->persmat, hoco); /* rational hom co */ /* clip We can test for -1.0/1.0 because of the properties of the * coordinate transformations. */ diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index 79ee6c89460..396c713cfb7 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -30,7 +30,7 @@ #include <string.h> -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "DNA_curve_types.h" @@ -212,7 +212,7 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) if(R.r.mode & R_ORTHO) shr->mist= mistfactor(-shi->co[2], shi->co); else - shr->mist= mistfactor(VecLength(shi->co), shi->co); + shr->mist= mistfactor(len_v3(shi->co), shi->co); } else shr->mist= 0.0f; @@ -227,7 +227,7 @@ void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr) shr->combined[3]= fac; if (shi->mat->material_type!= MA_TYPE_VOLUME) - VecMulf(shr->combined, fac); + mul_v3_fl(shr->combined, fac); } else shr->combined[3]= 1.0f; @@ -314,9 +314,9 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen VECCOPY(shi->n3, shi->v3->n); if(obi->flag & R_TRANSFORMED) { - Mat3MulVecfl(obi->nmat, shi->n1); - Mat3MulVecfl(obi->nmat, shi->n2); - Mat3MulVecfl(obi->nmat, shi->n3); + mul_m3_v3(obi->nmat, shi->n1); + mul_m3_v3(obi->nmat, shi->n2); + mul_m3_v3(obi->nmat, shi->n3); } if(!(vlr->flag & (R_NOPUNOFLIP|R_TANGENT))) { @@ -384,7 +384,7 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo /* shade_input_set_viewco equivalent */ VECCOPY(shi->co, spoint->co); VECCOPY(shi->view, shi->co); - Normalize(shi->view); + normalize_v3(shi->view); shi->xs= (int)spoint->x; shi->ys= (int)spoint->y; @@ -407,12 +407,12 @@ void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spo else { float cross[3]; - Crossf(cross, spoint->co, spoint->tan); - Crossf(shi->vn, cross, spoint->tan); - Normalize(shi->vn); + cross_v3_v3v3(cross, spoint->co, spoint->tan); + cross_v3_v3v3(shi->vn, cross, spoint->tan); + normalize_v3(shi->vn); if(INPR(shi->vn, shi->view) < 0.0f) - VecNegf(shi->vn); + negate_v3(shi->vn); } VECCOPY(shi->vno, shi->vn); @@ -450,8 +450,8 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert if(shi->mat->strand_surfnor > 0.0f) { shi->surfdist= 0.0f; for(sv=strand->vert; sv!=svert; sv++) - shi->surfdist+=VecLenf(sv->co, (sv+1)->co); - shi->surfdist += spoint->t*VecLenf(sv->co, (sv+1)->co); + shi->surfdist+=len_v3v3(sv->co, (sv+1)->co); + shi->surfdist += spoint->t*len_v3v3(sv->co, (sv+1)->co); } } @@ -474,13 +474,13 @@ void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert if(texco & TEXCO_GLOB) { VECCOPY(shi->gl, shi->co); - Mat4MulVecfl(R.viewinv, shi->gl); + mul_m4_v3(R.viewinv, shi->gl); if(shi->osatex) { VECCOPY(shi->dxgl, shi->dxco); - Mat3MulVecfl(R.imat, shi->dxco); + mul_m3_v3(R.imat, shi->dxco); VECCOPY(shi->dygl, shi->dyco); - Mat3MulVecfl(R.imat, shi->dyco); + mul_m3_v3(R.imat, shi->dyco); } } @@ -652,7 +652,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float * VECCOPY(v1, shi->v1->co); if(shi->obi->flag & R_TRANSFORMED) - Mat4MulVecfl(shi->obi->mat, v1); + mul_m4_v3(shi->obi->mat, v1); dface= v1[0]*shi->facenor[0]+v1[1]*shi->facenor[1]+v1[2]*shi->facenor[2]; @@ -731,7 +731,7 @@ void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float * shi->camera_co[0] = shi->camera_co[1] = shi->camera_co[2] = 0.0f; /* cannot normalize earlier, code above needs it at viewplane level */ - Normalize(view); + normalize_v3(view); } /* from scanline pixel coordinates to 3d coordinates, requires set_triangle */ @@ -773,17 +773,17 @@ void shade_input_set_uv(ShadeInput *shi) VECCOPY(v3, shi->v3->co); if(shi->obi->flag & R_TRANSFORMED) { - Mat4MulVecfl(shi->obi->mat, v1); - Mat4MulVecfl(shi->obi->mat, v2); - Mat4MulVecfl(shi->obi->mat, v3); + mul_m4_v3(shi->obi->mat, v1); + mul_m4_v3(shi->obi->mat, v2); + mul_m4_v3(shi->obi->mat, v3); } /* exception case for wire render of edge */ if(vlr->v2==vlr->v3) { float lend, lenc; - lend= VecLenf(v2, v1); - lenc= VecLenf(shi->co, v1); + lend= len_v3v3(v2, v1); + lenc= len_v3v3(shi->co, v1); if(lend==0.0f) { shi->u=shi->v= 0.0f; @@ -851,7 +851,7 @@ void shade_input_set_normals(ShadeInput *shi) shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1]; shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2]; - Normalize(shi->vn); + normalize_v3(shi->vn); } else VECCOPY(shi->vn, shi->facenor); @@ -939,9 +939,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->tang[2]= (tl*s3[2] - tu*s1[2] - tv*s2[2]); if(obi->flag & R_TRANSFORMED) - Mat3MulVecfl(obi->nmat, shi->tang); + mul_m3_v3(obi->nmat, shi->tang); - Normalize(shi->tang); + normalize_v3(shi->tang); VECCOPY(shi->nmaptang, shi->tang); } } @@ -963,9 +963,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) shi->nmaptang[2]= (tl*s3[2] - tu*s1[2] - tv*s2[2]); if(obi->flag & R_TRANSFORMED) - Mat3MulVecfl(obi->nmat, shi->nmaptang); + mul_m3_v3(obi->nmat, shi->nmaptang); - Normalize(shi->nmaptang); + normalize_v3(shi->nmaptang); } } } @@ -976,7 +976,7 @@ void shade_input_set_shade_texco(ShadeInput *shi) if(surfnor) { VECCOPY(shi->surfnor, surfnor) if(obi->flag & R_TRANSFORMED) - Mat3MulVecfl(obi->nmat, shi->surfnor); + mul_m3_v3(obi->nmat, shi->surfnor); } else VECCOPY(shi->surfnor, shi->vn) @@ -1037,15 +1037,15 @@ void shade_input_set_shade_texco(ShadeInput *shi) if(texco & TEXCO_GLOB) { VECCOPY(shi->gl, shi->co); - Mat4MulVecfl(R.viewinv, shi->gl); + mul_m4_v3(R.viewinv, shi->gl); if(shi->osatex) { VECCOPY(shi->dxgl, shi->dxco); // TXF: bug was here, but probably should be in convertblender.c, R.imat only valid if there is a world - //Mat3MulVecfl(R.imat, shi->dxco); - Mat4Mul3Vecfl(R.viewinv, shi->dxco); + //mul_m3_v3(R.imat, shi->dxco); + mul_mat3_m4_v3(R.viewinv, shi->dxco); VECCOPY(shi->dygl, shi->dyco); - //Mat3MulVecfl(R.imat, shi->dyco); - Mat4Mul3Vecfl(R.viewinv, shi->dyco); + //mul_m3_v3(R.imat, shi->dyco); + mul_mat3_m4_v3(R.viewinv, shi->dyco); } } @@ -1242,9 +1242,9 @@ void shade_input_set_shade_texco(ShadeInput *shi) zbuf_make_winmat(&R, winmat); if(shi->obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); zbuf_render_project(obwinmat, v1->co, ho1); zbuf_render_project(obwinmat, v2->co, ho2); diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index aa0bbd575a7..f167122f497 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -31,7 +31,7 @@ #include <string.h> -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_colortools.h" #include "BKE_material.h" @@ -168,7 +168,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) p1[0]= shi->co[0]-lar->co[0]; p1[1]= shi->co[1]-lar->co[1]; p1[2]= -lar->co[2]; - Mat3MulVecfl(lar->imat, p1); + mul_m3_v3(lar->imat, p1); VECCOPY(npos, p1); // npos is double! /* pre-scale */ @@ -180,7 +180,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) /* rotate view */ VECCOPY(nray, shi->view); - Mat3MulVecd(lar->imat, nray); + mul_m3_v3_double(lar->imat, nray); if(R.wrld.mode & WO_MIST) { /* patchy... */ @@ -311,7 +311,7 @@ static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens) a= sqrt(p1[0]*p1[0]+p1[1]*p1[1]+p1[2]*p1[2]); b= sqrt(p2[0]*p2[0]+p2[1]*p2[1]+p2[2]*p2[2]); - c= VecLenf(p1, p2); + c= len_v3v3(p1, p2); a/= ladist; a= sqrt(a); @@ -489,7 +489,7 @@ static float area_lamp_energy_multisample(LampRen *lar, float *co, float *vn) vec[0]= jitlamp[0]; vec[1]= jitlamp[1]; vec[2]= 0.0f; - Mat3MulVecfl(lar->mat, vec); + mul_m3_v3(lar->mat, vec); VECADD(area[0], lar->area[0], vec); VECADD(area[1], lar->area[1], vec); @@ -553,7 +553,7 @@ static float Phong_Spec( float *n, float *l, float *v, int hard, int tangent ) h[0] = l[0] + v[0]; h[1] = l[1] + v[1]; h[2] = l[2] + v[2]; - Normalize(h); + normalize_v3(h); rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; if(tangent) rslt= sasqrt(1.0f - rslt*rslt); @@ -573,7 +573,7 @@ static float CookTorr_Spec(float *n, float *l, float *v, int hard, int tangent) h[0]= v[0]+l[0]; h[1]= v[1]+l[1]; h[2]= v[2]+l[2]; - Normalize(h); + normalize_v3(h); nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; if(tangent) nh= sasqrt(1.0f - nh*nh); @@ -606,7 +606,7 @@ static float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_p h[0]= v[0]+l[0]; h[1]= v[1]+l[1]; h[2]= v[2]+l[2]; - Normalize(h); + normalize_v3(h); nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ if(tangent) nh= sasqrt(1.0f - nh*nh); @@ -653,7 +653,7 @@ static float Toon_Spec( float *n, float *l, float *v, float size, float smooth, h[0] = l[0] + v[0]; h[1] = l[1] + v[1]; h[2] = l[2] + v[2]; - Normalize(h); + normalize_v3(h); rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2]; if(tangent) rslt = sasqrt(1.0f - rslt*rslt); @@ -677,7 +677,7 @@ static float WardIso_Spec( float *n, float *l, float *v, float rms, int tangent) h[0] = l[0] + v[0]; h[1] = l[1] + v[1]; h[2] = l[2] + v[2]; - Normalize(h); + normalize_v3(h); nh = n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ if(tangent) nh = sasqrt(1.0f - nh*nh); @@ -728,7 +728,7 @@ static float OrenNayar_Diff(float nl, float *n, float *l, float *v, float rough h[0]= v[0]+l[0]; h[1]= v[1]+l[1]; h[2]= v[2]+l[2]; - Normalize(h); + normalize_v3(h); nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */ if(nh<0.0f) nh = 0.0f; @@ -749,12 +749,12 @@ static float OrenNayar_Diff(float nl, float *n, float *l, float *v, float rough Lit_B[0] = l[0] - (realnl * n[0]); Lit_B[1] = l[1] - (realnl * n[1]); Lit_B[2] = l[2] - (realnl * n[2]); - Normalize( Lit_B ); + normalize_v3( Lit_B ); View_B[0] = v[0] - (nv * n[0]); View_B[1] = v[1] - (nv * n[1]); View_B[2] = v[2] - (nv * n[2]); - Normalize( View_B ); + normalize_v3( View_B ); t = Lit_B[0]*View_B[0] + Lit_B[1]*View_B[1] + Lit_B[2]*View_B[2]; if( t < 0 ) t = 0; @@ -1143,7 +1143,7 @@ float lamp_get_visibility(LampRen *lar, float *co, float *lv, float *dist) /* rotate view to lampspace */ VECCOPY(lvrot, lv); - Mat3MulVecfl(lar->imat, lvrot); + mul_m3_v3(lar->imat, lvrot); x= MAX2(fabs(lvrot[0]/lvrot[2]) , fabs(lvrot[1]/lvrot[2])); /* 1.0f/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */ @@ -1235,27 +1235,27 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int float cross[3], nstrand[3], blend; if(ma->mode & MA_STR_SURFDIFF) { - Crossf(cross, shi->surfnor, vn); - Crossf(nstrand, vn, cross); + cross_v3_v3v3(cross, shi->surfnor, vn); + cross_v3_v3v3(nstrand, vn, cross); blend= INPR(nstrand, shi->surfnor); blend= 1.0f - blend; CLAMP(blend, 0.0f, 1.0f); - VecLerpf(vnor, nstrand, shi->surfnor, blend); - Normalize(vnor); + interp_v3_v3v3(vnor, nstrand, shi->surfnor, blend); + normalize_v3(vnor); } else { - Crossf(cross, lv, vn); - Crossf(vnor, cross, vn); - Normalize(vnor); + cross_v3_v3v3(cross, lv, vn); + cross_v3_v3v3(vnor, cross, vn); + normalize_v3(vnor); } if(ma->strand_surfnor > 0.0f) { if(ma->strand_surfnor > shi->surfdist) { blend= (ma->strand_surfnor - shi->surfdist)/ma->strand_surfnor; - VecLerpf(vnor, vnor, shi->surfnor, blend); - Normalize(vnor); + interp_v3_v3v3(vnor, vnor, shi->surfnor, blend); + normalize_v3(vnor); } } @@ -1264,9 +1264,9 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } else if (ma->mode & MA_TANGENT_V) { float cross[3]; - Crossf(cross, lv, shi->tang); - Crossf(vnor, cross, shi->tang); - Normalize(vnor); + cross_v3_v3v3(cross, lv, shi->tang); + cross_v3_v3v3(vnor, cross, shi->tang); + normalize_v3(vnor); vnor[0]= -vnor[0];vnor[1]= -vnor[1];vnor[2]= -vnor[2]; vn= vnor; } @@ -1404,7 +1404,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int lv[1]+= view[1]; lv[2]+= view[2]; - Normalize(lv); + normalize_v3(lv); t= vn[0]*lv[0]+vn[1]*lv[1]+vn[2]*lv[2]; @@ -1662,15 +1662,15 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr) if(texfac==0.0f) { VECCOPY(col, shr->col); - VecMulf(col, invalpha); + mul_v3_fl(col, invalpha); } else if(texfac==1.0f) { col[0]= col[1]= col[2]= 1.0f; - VecMulf(col, invalpha); + mul_v3_fl(col, invalpha); } else { VECCOPY(col, shr->col); - VecMulf(col, invalpha); + mul_v3_fl(col, invalpha); col[0]= pow(col[0], 1.0f-texfac); col[1]= pow(col[1], 1.0f-texfac); col[2]= pow(col[2], 1.0f-texfac); diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c index a416c2d2764..25cfc0f1253 100644 --- a/source/blender/render/intern/source/sss.c +++ b/source/blender/render/intern/source/sss.c @@ -47,7 +47,7 @@ /* external modules: */ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_memarena.h" @@ -443,8 +443,8 @@ static void compute_radiance(ScatterTree *tree, float *co, float *rad) of the mesh not visible from the camera. this can not only make it darker, but also lead to ugly color shifts */ - VecMulf(result.rad, tree->ss[0]->frontweight); - VecMulf(result.backrad, tree->ss[0]->backweight); + mul_v3_fl(result.rad, tree->ss[0]->frontweight); + mul_v3_fl(result.backrad, tree->ss[0]->backweight); VECCOPY(rad, result.rad); VECADD(backrad, result.rad, result.backrad); @@ -760,7 +760,7 @@ ScatterTree *scatter_tree_new(ScatterSettings *ss[3], float scale, float error, points[i].area= fabs(area[i])/(tree->scale*tree->scale); points[i].back= (area[i] < 0.0f); - VecMulf(points[i].co, 1.0f/tree->scale); + mul_v3_fl(points[i].co, 1.0f/tree->scale); DO_MINMAX(points[i].co, tree->min, tree->max); refpoints[i]= points + i; @@ -813,7 +813,7 @@ void scatter_tree_sample(ScatterTree *tree, float *co, float *color) float sco[3]; VECCOPY(sco, co); - VecMulf(sco, 1.0f/tree->scale); + mul_v3_fl(sco, 1.0f/tree->scale); compute_radiance(tree, sco, color); } diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index 61080c7d807..47a7c052b18 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -37,7 +37,7 @@ #include "DNA_material_types.h" #include "DNA_meshdata_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_memarena.h" @@ -99,10 +99,10 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) VECCOPY(p[3], sseg->v[3]->co); if(sseg->obi->flag & R_TRANSFORMED) { - Mat4MulVecfl(sseg->obi->mat, p[0]); - Mat4MulVecfl(sseg->obi->mat, p[1]); - Mat4MulVecfl(sseg->obi->mat, p[2]); - Mat4MulVecfl(sseg->obi->mat, p[3]); + mul_m4_v3(sseg->obi->mat, p[0]); + mul_m4_v3(sseg->obi->mat, p[1]); + mul_m4_v3(sseg->obi->mat, p[2]); + mul_m4_v3(sseg->obi->mat, p[3]); } if(t == 0.0f) { @@ -135,11 +135,11 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) spoint->dtco[2]= data[0]*p[0][2] + data[1]*p[1][2] + data[2]*p[2][2] + data[3]*p[3][2]; VECCOPY(spoint->tan, spoint->dtco); - Normalize(spoint->tan); + normalize_v3(spoint->tan); VECCOPY(spoint->nor, spoint->co); VECMUL(spoint->nor, -1.0f); - Normalize(spoint->nor); + normalize_v3(spoint->nor); spoint->width= strand_eval_width(ma, spoint->strandco); @@ -148,7 +148,7 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) spoint->alpha= (simplify)? simplify[1]: 1.0f; /* outer points */ - Crossf(cross, spoint->co, spoint->tan); + cross_v3_v3v3(cross, spoint->co, spoint->tan); w= spoint->co[2]*strandbuf->winmat[2][3] + strandbuf->winmat[3][3]; dx= strandbuf->winx*cross[0]*strandbuf->winmat[0][0]/w; @@ -157,7 +157,7 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) if(w > 0.0f) { if(strandbuf->flag & R_STRAND_B_UNITS) { - crosslen= VecLength(cross); + crosslen= len_v3(cross); w= 2.0f*crosslen*strandbuf->minwidth/w; if(spoint->width < w) { @@ -169,14 +169,14 @@ void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint) /* squared because we only change width, not length */ spoint->width *= simplify[0]*simplify[0]; - VecMulf(cross, spoint->width*0.5f/crosslen); + mul_v3_fl(cross, spoint->width*0.5f/crosslen); } else - VecMulf(cross, spoint->width/w); + mul_v3_fl(cross, spoint->width/w); } - VecSubf(spoint->co1, spoint->co, cross); - VecAddf(spoint->co2, spoint->co, cross); + sub_v3_v3v3(spoint->co1, spoint->co, cross); + add_v3_v3v3(spoint->co2, spoint->co, cross); VECCOPY(spoint->dsco, cross); } @@ -220,7 +220,7 @@ void interpolate_shade_result(ShadeResult *shr1, ShadeResult *shr2, float t, Sha interpolate_vec4(shr1->col, shr2->col, t, negt, shr->col); if(addpassflag & SCE_PASS_NORMAL) { interpolate_vec3(shr1->nor, shr2->nor, t, negt, shr->nor); - Normalize(shr->nor); + normalize_v3(shr->nor); } if(addpassflag & SCE_PASS_DIFFUSE) interpolate_vec3(shr1->diff, shr2->diff, t, negt, shr->diff); @@ -825,9 +825,9 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa /* compute matrix and try clipping whole object */ if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); if(clip_render_object(obi->obr->boundbox, bounds, winmat)) continue; @@ -903,9 +903,9 @@ int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBa obr= obi->obr; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); sseg.obi= obi; sseg.strand= RE_findOrAddStrand(obr, sortseg->strand); @@ -975,7 +975,7 @@ StrandSurface *cache_strand_surface(Render *re, ObjectRen *obr, DerivedMesh *dm, mvert= dm->getVertArray(dm); for(a=0; a<mesh->totvert; a++, mvert++) { VECCOPY(co[a], mvert->co); - Mat4MulVecfl(mat, co[a]); + mul_m4_v3(mat, co[a]); } mface= dm->getFaceArray(dm); diff --git a/source/blender/render/intern/source/sunsky.c b/source/blender/render/intern/source/sunsky.c index 2b490e71142..54032833196 100644 --- a/source/blender/render/intern/source/sunsky.c +++ b/source/blender/render/intern/source/sunsky.c @@ -21,7 +21,7 @@ #include "sunsky.h" #include "math.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_global.h" /** @@ -289,12 +289,12 @@ void GetSkyXYZRadiancef(struct SunSky* sunsky, const float varg[3], float color_ float theta, phi; float v[3]; - VecCopyf(v, (float*)varg); - Normalize(v); + copy_v3_v3(v, (float*)varg); + normalize_v3(v); if (v[2] < 0.001){ v[2] = 0.001; - Normalize(v); + normalize_v3(v); } DirectionToThetaPhi(v, &theta, &phi); @@ -448,7 +448,7 @@ void AtmospherePixleShader( struct SunSky* sunSky, float view[3], float s, float sunDirection[1] = sunSky->toSun[1]; sunDirection[2] = sunSky->toSun[2]; - costheta = Inpf(view, sunDirection); // cos(theta) + costheta = dot_v3v3(view, sunDirection); // cos(theta) Phase_1 = 1 + (costheta * costheta); // Phase_1 vec3opf(sunSky->atm_BetaRay, sunSky->atm_BetaRay, *, sunSky->atm_BetaRayMultiplier); @@ -461,7 +461,7 @@ void AtmospherePixleShader( struct SunSky* sunSky, float view[3], float s, float E1[1] = exp(E1[1]); E1[2] = exp(E1[2]); - VecCopyf(E, E1); + copy_v3_v3(E, E1); //Phase2(theta) = (1-g^2)/(1+g-2g*cos(theta))^(3/2) fTemp = 1 + sunSky->atm_HGg - 2 * sunSky->atm_HGg * costheta; diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c index 9510dc15e5a..d2e36a7a286 100644 --- a/source/blender/render/intern/source/texture.c +++ b/source/blender/render/intern/source/texture.c @@ -33,7 +33,7 @@ #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "DNA_texture_types.h" @@ -832,7 +832,7 @@ static int cubemap_glob(float *n, float x, float y, float z, float *adr1, float else { VECCOPY(nor, n); } - Mat4Mul3Vecfl(R.viewinv, nor); + mul_mat3_m4_v3(R.viewinv, nor); x1= fabs(nor[0]); y1= fabs(nor[1]); @@ -871,7 +871,7 @@ static int cubemap(MTex *mtex, VlakRen *vlr, float *n, float x, float y, float z /* test for v1, vlr can be faked for baking */ if(vlr->v1 && vlr->v1->orco) { float nor[3]; - CalcNormFloat(vlr->v1->orco, vlr->v2->orco, vlr->v3->orco, nor); + normal_tri_v3( nor,vlr->v1->orco, vlr->v2->orco, vlr->v3->orco); if( fabs(nor[0])<fabs(nor[2]) && fabs(nor[1])<fabs(nor[2]) ) vlr->puno |= ME_PROJXY; else if( fabs(nor[0])<fabs(nor[1]) && fabs(nor[2])<fabs(nor[1]) ) vlr->puno |= ME_PROJXZ; @@ -925,7 +925,7 @@ static int cubemap_ob(Object *ob, float *n, float x, float y, float z, float *ad if(n==NULL) return 0; VECCOPY(nor, n); - if(ob) Mat4Mul3Vecfl(ob->imat, nor); + if(ob) mul_mat3_m4_v3(ob->imat, nor); x1= fabs(nor[0]); y1= fabs(nor[1]); @@ -970,8 +970,8 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d fx = (t[0] + 1.0) / 2.0; fy = (t[1] + 1.0) / 2.0; } - else if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy); - else if(wrap==MTEX_SPHERE) spheremap(t[0], t[1], t[2], &fx, &fy); + else if(wrap==MTEX_TUBE) map_to_tube( &fx, &fy,t[0], t[1], t[2]); + else if(wrap==MTEX_SPHERE) map_to_sphere( &fx, &fy,t[0], t[1], t[2]); else { if(texco==TEXCO_OBJECT) cubemap_ob(ob, n, t[0], t[1], t[2], &fx, &fy); else if(texco==TEXCO_GLOB) cubemap_glob(n, t[0], t[1], t[2], &fx, &fy); @@ -1042,20 +1042,20 @@ static void do_2d_mapping(MTex *mtex, float *t, VlakRen *vlr, float *n, float *d } if(ok) { if(wrap==MTEX_TUBE) { - tubemap(t[0], t[1], t[2], area, area+1); - tubemap(t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2], area+2, area+3); - tubemap(t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2], area+4, area+5); + map_to_tube( area, area+1,t[0], t[1], t[2]); + map_to_tube( area+2, area+3,t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2]); + map_to_tube( area+4, area+5,t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2]); } else { - spheremap(t[0], t[1], t[2],area,area+1); - spheremap(t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2], area+2, area+3); - spheremap(t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2], area+4, area+5); + map_to_sphere(area,area+1,t[0], t[1], t[2]); + map_to_sphere( area+2, area+3,t[0]+dxt[0], t[1]+dxt[1], t[2]+dxt[2]); + map_to_sphere( area+4, area+5,t[0]+dyt[0], t[1]+dyt[1], t[2]+dyt[2]); } areaflag= 1; } else { - if(wrap==MTEX_TUBE) tubemap(t[0], t[1], t[2], &fx, &fy); - else spheremap(t[0], t[1], t[2], &fx, &fy); + if(wrap==MTEX_TUBE) map_to_tube( &fx, &fy,t[0], t[1], t[2]); + else map_to_sphere( &fx, &fy,t[0], t[1], t[2]); dxt[0]/= 2.0; dxt[1]/= 2.0; dyt[0]/= 2.0; @@ -1230,7 +1230,7 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, * artificer: added the use of tmpvec to avoid scaling texvec */ VECCOPY(tmpvec, texvec); - VecMulf(tmpvec, 1.0/tex->noisesize); + mul_v3_fl(tmpvec, 1.0/tex->noisesize); switch(tex->stype) { case TEX_MFRACTAL: @@ -1252,7 +1252,7 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, * artificer: added the use of tmpvec to avoid scaling texvec */ VECCOPY(tmpvec, texvec); - VecMulf(tmpvec, 1.0/tex->noisesize); + mul_v3_fl(tmpvec, 1.0/tex->noisesize); retval= voronoiTex(tex, tmpvec, texres); break; @@ -1261,7 +1261,7 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, * artificer: added the use of tmpvec to avoid scaling texvec */ VECCOPY(tmpvec, texvec); - VecMulf(tmpvec, 1.0/tex->noisesize); + mul_v3_fl(tmpvec, 1.0/tex->noisesize); retval= mg_distNoiseTex(tex, tmpvec, texres); break; @@ -1416,11 +1416,11 @@ void texture_rgb_blend(float *in, float *tex, float *out, float fact, float facg fact*= facg; facm= 1.0-fact; - col= fact*tex[0]; + col= tex[0]+((1-tex[0])*facm); if(col < out[0]) in[0]= col; else in[0]= out[0]; - col= fact*tex[1]; + col= tex[1]+((1-tex[1])*facm); if(col < out[1]) in[1]= col; else in[1]= out[1]; - col= fact*tex[2]; + col= tex[2]+((1-tex[2])*facm); if(col < out[2]) in[2]= col; else in[2]= out[2]; break; @@ -1675,13 +1675,13 @@ void do_material_tex(ShadeInput *shi) VECCOPY(tempvec, shi->co); if(mtex->texflag & MTEX_OB_DUPLI_ORIG) if(shi->obi && shi->obi->duplitexmat) - Mat4MulVecfl(shi->obi->duplitexmat, tempvec); - Mat4MulVecfl(ob->imat, tempvec); + mul_m4_v3(shi->obi->duplitexmat, tempvec); + mul_m4_v3(ob->imat, tempvec); if(shi->osatex) { VECCOPY(dxt, shi->dxco); VECCOPY(dyt, shi->dyco); - Mat4Mul3Vecfl(ob->imat, dxt); - Mat4Mul3Vecfl(ob->imat, dyt); + mul_mat3_m4_v3(ob->imat, dxt); + mul_mat3_m4_v3(ob->imat, dyt); } } else { @@ -1742,7 +1742,7 @@ void do_material_tex(ShadeInput *shi) nn[0] = -shi->vn[0]; nn[1] = -shi->vn[1]; nn[2] = -shi->vn[2]; - VecOrthoBasisf(nn, nu, nv); + ortho_basis_v3v3_v3( nu, nv,nn); nunvdone= 1; } @@ -1819,7 +1819,7 @@ void do_material_tex(ShadeInput *shi) nn[0] = -shi->vn[0]; nn[1] = -shi->vn[1]; nn[2] = -shi->vn[2]; - VecOrthoBasisf(nn, nu, nv); + ortho_basis_v3v3_v3( nu, nv,nn); nunvdone= 1; } @@ -1897,20 +1897,20 @@ void do_material_tex(ShadeInput *shi) idv = (dv < 1e-6f) ? bf : (bf/dv); if ((mtex->texco == TEXCO_ORCO) && shi->obr && shi->obr->ob) { - Mat4Mul3Vecfl(shi->obr->ob->imat, tu); - Mat4Mul3Vecfl(shi->obr->ob->imat, tv); - Normalize(tu); - Normalize(tv); + mul_mat3_m4_v3(shi->obr->ob->imat, tu); + mul_mat3_m4_v3(shi->obr->ob->imat, tv); + normalize_v3(tu); + normalize_v3(tv); } else if (mtex->texco == TEXCO_GLOB) { - Mat4Mul3Vecfl(R.viewinv, tu); - Mat4Mul3Vecfl(R.viewinv, tv); + mul_mat3_m4_v3(R.viewinv, tu); + mul_mat3_m4_v3(R.viewinv, tv); } else if (mtex->texco == TEXCO_OBJECT && mtex->object) { - Mat4Mul3Vecfl(mtex->object->imat, tu); - Mat4Mul3Vecfl(mtex->object->imat, tv); - Normalize(tu); - Normalize(tv); + mul_mat3_m4_v3(mtex->object->imat, tu); + mul_mat3_m4_v3(mtex->object->imat, tv); + normalize_v3(tu); + normalize_v3(tv); } // +u val @@ -1937,7 +1937,7 @@ void do_material_tex(ShadeInput *shi) nv[0] += vd*nn[0]; nv[1] += vd*nn[1]; nv[2] += vd*nn[2]; - Crossf(nvec, nu, nv); + cross_v3_v3v3(nvec, nu, nv); nvec[0] = -nvec[0]; nvec[1] = -nvec[1]; @@ -2020,12 +2020,12 @@ void do_material_tex(ShadeInput *shi) // rotate to global coords if(mtex->texco==TEXCO_ORCO || mtex->texco==TEXCO_UV) { if(shi->vlr && shi->obr && shi->obr->ob) { - float len= Normalize(texres.nor); + float len= normalize_v3(texres.nor); // can be optimized... (ton) - Mat4Mul3Vecfl(shi->obr->ob->obmat, texres.nor); - Mat4Mul3Vecfl(R.viewmat, texres.nor); - Normalize(texres.nor); - VecMulf(texres.nor, len); + mul_mat3_m4_v3(shi->obr->ob->obmat, texres.nor); + mul_mat3_m4_v3(R.viewmat, texres.nor); + normalize_v3(texres.nor); + mul_v3_fl(texres.nor, len); } } } @@ -2100,7 +2100,7 @@ void do_material_tex(ShadeInput *shi) if(mtex->normapspace == MTEX_NSPACE_TANGENT) { /* qdn: tangent space */ float B[3], tv[3]; - Crossf(B, shi->vn, shi->nmaptang); /* bitangent */ + cross_v3_v3v3(B, shi->vn, shi->nmaptang); /* bitangent */ /* transform norvec from tangent space to object surface in camera space */ tv[0] = texres.nor[0]*shi->nmaptang[0] + texres.nor[1]*B[0] + texres.nor[2]*shi->vn[0]; tv[1] = texres.nor[0]*shi->nmaptang[1] + texres.nor[1]*B[1] + texres.nor[2]*shi->vn[1]; @@ -2116,15 +2116,15 @@ void do_material_tex(ShadeInput *shi) if(mtex->normapspace == MTEX_NSPACE_CAMERA); else if(mtex->normapspace == MTEX_NSPACE_WORLD) { - Mat4Mul3Vecfl(R.viewmat, nor); + mul_mat3_m4_v3(R.viewmat, nor); } else if(mtex->normapspace == MTEX_NSPACE_OBJECT) { if(shi->obr && shi->obr->ob) - Mat4Mul3Vecfl(shi->obr->ob->obmat, nor); - Mat4Mul3Vecfl(R.viewmat, nor); + mul_mat3_m4_v3(shi->obr->ob->obmat, nor); + mul_mat3_m4_v3(R.viewmat, nor); } - Normalize(nor); + normalize_v3(nor); /* qdn: worldspace */ shi->vn[0]= facm*shi->vn[0] + fact*nor[0]; @@ -2159,7 +2159,7 @@ void do_material_tex(ShadeInput *shi) shi->vn[2]+= dot*nor[2]; } } - Normalize(shi->vn); + normalize_v3(shi->vn); /* this makes sure the bump is passed on to the next texture */ shi->orn[0]= -shi->vn[0]; @@ -2316,9 +2316,9 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa VECCOPY(co, xyz); if(mtex->texflag & MTEX_OB_DUPLI_ORIG) { if(shi->obi && shi->obi->duplitexmat) - Mat4MulVecfl(shi->obi->duplitexmat, co); + mul_m4_v3(shi->obi->duplitexmat, co); } - Mat4MulVecfl(ob->imat, co); + mul_m4_v3(ob->imat, co); } } /* not really orco, but 'local' */ @@ -2330,12 +2330,12 @@ void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, floa else { Object *ob= shi->obi->ob; VECCOPY(co, xyz); - Mat4MulVecfl(ob->imat, co); + mul_m4_v3(ob->imat, co); } } else if(mtex->texco==TEXCO_GLOB) { VECCOPY(co, xyz); - Mat4MulVecfl(R.viewinv, co); + mul_m4_v3(R.viewinv, co); } else continue; // can happen when texco defines disappear and it renders old files @@ -2648,8 +2648,8 @@ void do_sky_tex(float *rco, float *lo, float *dxyview, float *hor, float *zen, f case TEXCO_H_SPHEREMAP: case TEXCO_H_TUBEMAP: if(skyflag & WO_ZENUP) { - if(mtex->texco==TEXCO_H_TUBEMAP) tubemap(lo[0], lo[2], lo[1], tempvec, tempvec+1); - else spheremap(lo[0], lo[2], lo[1], tempvec, tempvec+1); + if(mtex->texco==TEXCO_H_TUBEMAP) map_to_tube( tempvec, tempvec+1,lo[0], lo[2], lo[1]); + else map_to_sphere( tempvec, tempvec+1,lo[0], lo[2], lo[1]); /* tube/spheremap maps for outside view, not inside */ tempvec[0]= 1.0-tempvec[0]; /* only top half */ @@ -2668,7 +2668,7 @@ void do_sky_tex(float *rco, float *lo, float *dxyview, float *hor, float *zen, f case TEXCO_OBJECT: if(mtex->object) { VECCOPY(tempvec, lo); - Mat4MulVecfl(mtex->object->imat, tempvec); + mul_m4_v3(mtex->object->imat, tempvec); co= tempvec; } break; @@ -2676,16 +2676,16 @@ void do_sky_tex(float *rco, float *lo, float *dxyview, float *hor, float *zen, f case TEXCO_GLOB: if(rco) { VECCOPY(tempvec, rco); - Mat4MulVecfl(R.viewinv, tempvec); + mul_m4_v3(R.viewinv, tempvec); co= tempvec; } else co= lo; // VECCOPY(shi->dxgl, shi->dxco); -// Mat3MulVecfl(R.imat, shi->dxco); +// mul_m3_v3(R.imat, shi->dxco); // VECCOPY(shi->dygl, shi->dyco); -// Mat3MulVecfl(R.imat, shi->dyco); +// mul_m3_v3(R.imat, shi->dyco); break; } @@ -2812,12 +2812,12 @@ void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi, float *colf, int ef dx= dxt; dy= dyt; VECCOPY(tempvec, shi->co); - Mat4MulVecfl(ob->imat, tempvec); + mul_m4_v3(ob->imat, tempvec); if(shi->osatex) { VECCOPY(dxt, shi->dxco); VECCOPY(dyt, shi->dyco); - Mat4Mul3Vecfl(ob->imat, dxt); - Mat4Mul3Vecfl(ob->imat, dyt); + mul_mat3_m4_v3(ob->imat, dxt); + mul_mat3_m4_v3(ob->imat, dyt); } } else { @@ -2828,12 +2828,12 @@ void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi, float *colf, int ef else if(mtex->texco==TEXCO_GLOB) { co= shi->gl; dx= shi->dxco; dy= shi->dyco; VECCOPY(shi->gl, shi->co); - Mat4MulVecfl(R.viewinv, shi->gl); + mul_m4_v3(R.viewinv, shi->gl); } else if(mtex->texco==TEXCO_VIEW) { VECCOPY(tempvec, lavec); - Mat3MulVecfl(la->imat, tempvec); + mul_m3_v3(la->imat, tempvec); if(la->type==LA_SPOT) { tempvec[0]*= la->spottexfac; @@ -2846,11 +2846,11 @@ void do_lamp_tex(LampRen *la, float *lavec, ShadeInput *shi, float *colf, int ef VECCOPY(dxt, shi->dxlv); VECCOPY(dyt, shi->dylv); /* need some matrix conversion here? la->imat is a [3][3] matrix!!! **/ - Mat3MulVecfl(la->imat, dxt); - Mat3MulVecfl(la->imat, dyt); + mul_m3_v3(la->imat, dxt); + mul_m3_v3(la->imat, dyt); - VecMulf(dxt, la->spottexfac); - VecMulf(dyt, la->spottexfac); + mul_v3_fl(dxt, la->spottexfac); + mul_v3_fl(dyt, la->spottexfac); } } diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c index cfaf333d656..e9162b7367f 100644 --- a/source/blender/render/intern/source/volume_precache.c +++ b/source/blender/render/intern/source/volume_precache.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_threads.h" #include "BLI_voxel.h" @@ -175,6 +175,7 @@ static void lightcache_filter(VolumePrecache *vp) } } +#if 0 static void lightcache_filter2(VolumePrecache *vp) { int x, y, z; @@ -211,6 +212,7 @@ static void lightcache_filter2(VolumePrecache *vp) if (new_g) { MEM_freeN(new_g); new_g=NULL; } if (new_b) { MEM_freeN(new_b); new_b=NULL; } } +#endif static inline int ms_I(int x, int y, int z, int *n) //has a pad of 1 voxel surrounding the core for boundary simulation { @@ -444,8 +446,8 @@ static void *vol_precache_part(void *data) continue; } - VecCopyf(shi->view, co); - Normalize(shi->view); + copy_v3_v3(shi->view, co); + normalize_v3(shi->view); vol_get_scattering(shi, scatter_col, co); obi->volume_precache->data_r[ V_I(x, y, z, res) ] = scatter_col[0]; @@ -495,7 +497,7 @@ static void precache_init_parts(Render *re, RayObject *tree, ShadeInput *shi, Ob parts[0] = parts[1] = parts[2] = totthread; res = vp->res; - VecSubf(voxel, bbmax, bbmin); + sub_v3_v3v3(voxel, bbmax, bbmin); voxel[0] /= res[0]; voxel[1] /= res[1]; @@ -564,7 +566,7 @@ static int precache_resolution(VolumePrecache *vp, float *bbmin, float *bbmax, i { float dim[3], div; - VecSubf(dim, bbmax, bbmin); + sub_v3_v3v3(dim, bbmax, bbmin); div = MAX3(dim[0], dim[1], dim[2]); dim[0] /= div; diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c index cf4b6b4002f..32ab2980316 100644 --- a/source/blender/render/intern/source/volumetric.c +++ b/source/blender/render/intern/source/volumetric.c @@ -34,7 +34,7 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "BLI_voxel.h" @@ -85,7 +85,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, float *co) /* trace shadow manually, no good lamp api atm */ Isect is; - VecCopyf(is.start, co); + copy_v3_v3(is.start, co); if(lar->type==LA_SUN || lar->type==LA_HEMI) { is.vec[0] = -lar->vec[0]; is.vec[1] = -lar->vec[1]; @@ -93,7 +93,7 @@ static float vol_get_shadow(ShadeInput *shi, LampRen *lar, float *co) is.labda = R.maxdist; } else { VECSUB( is.vec, lar->co, is.start ); - is.labda = VecLength( is.vec ); + is.labda = len_v3( is.vec ); } is.mode = RE_RAY_MIRROR; @@ -122,9 +122,9 @@ static int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco, /* XXX TODO - get raytrace max distance from object instance's bounding box */ /* need to account for scaling only, but keep coords in camera space... * below code is WIP and doesn't work! - VecSubf(bb_dim, shi->obi->obr->boundbox[1], shi->obi->obr->boundbox[2]); - Mat3MulVecfl(shi->obi->nmat, bb_dim); - maxsize = VecLength(bb_dim); + sub_v3_v3v3(bb_dim, shi->obi->obr->boundbox[1], shi->obi->obr->boundbox[2]); + mul_m3_v3(shi->obi->nmat, bb_dim); + maxsize = len_v3(bb_dim); */ VECCOPY(isect->start, co); @@ -184,7 +184,7 @@ static void shade_intersection(ShadeInput *shi, float *col, Isect *is) shade_ray(is, &shi_new, &shr_new); } - VecCopyf(col, shr_new.combined); + copy_v3_v3(col, shr_new.combined); col[3] = shr_new.alpha; } @@ -225,7 +225,7 @@ static void vol_get_precached_scattering(ShadeInput *shi, float *scatter_col, fl /* convert input coords to 0.0, 1.0 */ VECCOPY(bbmin, shi->obi->obr->boundbox[0]); VECCOPY(bbmax, shi->obi->obr->boundbox[1]); - VecSubf(dim, bbmax, bbmin); + sub_v3_v3v3(dim, bbmax, bbmin); sample_co[0] = ((co[0] - bbmin[0]) / dim[0]); sample_co[1] = ((co[1] - bbmin[1]) / dim[1]); @@ -246,18 +246,18 @@ static float metadensity(Object* ob, float* co) /* transform co to meta-element */ float tco[3] = {co[0], co[1], co[2]}; - Mat4MulMat4(mat, ob->obmat, R.viewmat); - Mat4Invert(imat, mat); - Mat4MulVecfl(imat, tco); + mul_m4_m4m4(mat, ob->obmat, R.viewmat); + invert_m4_m4(imat, mat); + mul_m4_v3(imat, tco); for (ml = mb->elems.first; ml; ml=ml->next) { float bmat[3][3], dist2; /* element rotation transform */ float tp[3] = {ml->x - tco[0], ml->y - tco[1], ml->z - tco[2]}; - QuatToMat3(ml->quat, bmat); - Mat3Transp(bmat); // rot.only, so inverse == transpose - Mat3MulVecfl(bmat, tp); + quat_to_mat3( bmat,ml->quat); + transpose_m3(bmat); // rot.only, so inverse == transpose + mul_m3_v3(bmat, tp); /* MB_BALL default */ switch (ml->type) { @@ -379,7 +379,7 @@ float vol_get_phasefunc(ShadeInput *shi, float g, float *w, float *wp) return normalize * 1.f; } else { /* schlick */ const float k = 1.55f * g - .55f * g * g * g; - const float kcostheta = k * Inpf(w, wp); + const float kcostheta = k * dot_v3v3(w, wp); return normalize * (1.f - k*k) / ((1.f - kcostheta) * (1.f - kcostheta)); } @@ -435,14 +435,14 @@ static void vol_get_transmittance(ShadeInput *shi, float *tr, float *co, float * float tau[3] = {0.f, 0.f, 0.f}; float t0 = 0.f; - float t1 = Normalize(step_vec); + float t1 = normalize_v3(step_vec); float pt0 = t0; t0 += shi->mat->vol.stepsize * ((shi->mat->vol.stepsize_type == MA_VOL_STEP_CONSTANT) ? 0.5f : BLI_thread_frand(shi->thread)); p[0] += t0 * step_vec[0]; p[1] += t0 * step_vec[1]; p[2] += t0 * step_vec[2]; - VecMulf(step_vec, shi->mat->vol.stepsize); + mul_v3_fl(step_vec, shi->mat->vol.stepsize); for (; t0 < t1; pt0 = t0, t0 += shi->mat->vol.stepsize) { const float d = vol_get_density(shi, p); @@ -455,7 +455,7 @@ static void vol_get_transmittance(ShadeInput *shi, float *tr, float *co, float * tau[1] += stepd * sigma_t[1]; tau[2] += stepd * sigma_t[2]; - VecAddf(p, p, step_vec); + add_v3_v3v3(p, p, step_vec); } /* return transmittance */ @@ -477,34 +477,34 @@ void vol_shade_one_lamp(struct ShadeInput *shi, float *co, LampRen *lar, float * if ((visifac= lamp_get_visibility(lar, co, lv, &lampdist)) == 0.f) return; - VecCopyf(lacol, &lar->r); + copy_v3_v3(lacol, &lar->r); if(lar->mode & LA_TEXTURE) { shi->osatex= 0; do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE); } - VecMulf(lacol, visifac); + mul_v3_fl(lacol, visifac); if (ELEM(lar->type, LA_SUN, LA_HEMI)) VECCOPY(lv, lar->vec); - VecMulf(lv, -1.0f); + mul_v3_fl(lv, -1.0f); if (shi->mat->vol.shade_type == MA_VOL_SHADE_SHADOWED) { - VecMulf(lacol, vol_get_shadow(shi, lar, co)); + mul_v3_fl(lacol, vol_get_shadow(shi, lar, co)); } else if (shi->mat->vol.shade_type == MA_VOL_SHADE_SHADED) { Isect is; if (shi->mat->vol.shadeflag & MA_VOL_RECV_EXT_SHADOW) { - VecMulf(lacol, vol_get_shadow(shi, lar, co)); + mul_v3_fl(lacol, vol_get_shadow(shi, lar, co)); if (luminance(lacol) < 0.001f) return; } /* find minimum of volume bounds, or lamp coord */ if (vol_get_bounds(shi, co, lv, hitco, &is, VOL_BOUNDS_SS)) { - float dist = VecLenf(co, hitco); + float dist = len_v3v3(co, hitco); VlakRen *vlr = (VlakRen *)is.hit.face; /* simple internal shadowing */ @@ -523,7 +523,7 @@ void vol_shade_one_lamp(struct ShadeInput *shi, float *co, LampRen *lar, float * vol_get_transmittance(shi, tr, co, atten_co); - VecMulVecf(lacol, lacol, tr); + mul_v3_v3v3(lacol, lacol, tr); } else { /* Point is on the outside edge of the volume, @@ -561,7 +561,7 @@ void vol_get_scattering(ShadeInput *shi, float *scatter_col, float *co) if (lar) { vol_shade_one_lamp(shi, co, lar, lacol); - VecAddf(scatter_col, scatter_col, lacol); + add_v3_v3v3(scatter_col, scatter_col, lacol); } } } @@ -594,13 +594,13 @@ static void volumeintegrate(struct ShadeInput *shi, float *col, float *co, float float t0 = 0.f; float pt0 = t0; - float t1 = Normalize(step_vec); /* returns vector length */ + float t1 = normalize_v3(step_vec); /* returns vector length */ t0 += stepsize * ((shi->mat->vol.stepsize_type == MA_VOL_STEP_CONSTANT) ? 0.5f : BLI_thread_frand(shi->thread)); p[0] += t0 * step_vec[0]; p[1] += t0 * step_vec[1]; p[2] += t0 * step_vec[2]; - VecMulf(step_vec, stepsize); + mul_v3_fl(step_vec, stepsize); for (; t0 < t1; pt0 = t0, t0 += stepsize) { const float density = vol_get_density(shi, p); @@ -631,12 +631,12 @@ static void volumeintegrate(struct ShadeInput *shi, float *col, float *co, float radiance[1] += stepd * tr[1] * (emit_col[1] + scatter_col[1]); radiance[2] += stepd * tr[2] * (emit_col[2] + scatter_col[2]); } - VecAddf(p, p, step_vec); + add_v3_v3v3(p, p, step_vec); } /* multiply original color (from behind volume) with transmittance over entire distance */ - VecMulVecf(col, tr, col); - VecAddf(col, col, radiance); + mul_v3_v3v3(col, tr, col); + add_v3_v3v3(col, col, radiance); /* alpha <-- transmission luminance */ col[3] = 1.0f - luminance(tr); @@ -729,7 +729,7 @@ static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int in else col[3] = 1.f; - VecCopyf(shr->combined, col); + copy_v3_v3(shr->combined, col); shr->alpha = col[3]; VECCOPY(shr->diff, shr->combined); @@ -768,7 +768,7 @@ void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct density = vol_get_density(shi, startco); vol_get_transmittance(shi, tr, startco, endco); - VecCopyf(shr->combined, tr); + copy_v3_v3(shr->combined, tr); shr->combined[3] = 1.0f - luminance(tr); } diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c index 479f33c9ff2..8e71fec4db9 100644 --- a/source/blender/render/intern/source/voxeldata.c +++ b/source/blender/render/intern/source/voxeldata.c @@ -32,7 +32,7 @@ #include "MEM_guardedalloc.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_voxel.h" @@ -277,9 +277,9 @@ int voxeldatatex(struct Tex *tex, float *texvec, struct TexResult *texres) /* scale lookup from 0.0-1.0 (original location) to -1.0, 1.0, consistent with image texture tex coords */ /* in implementation this works backwards, bringing sample locations from -1.0, 1.0 * to the range 0.0, 1.0, before looking up in the voxel structure. */ - VecCopyf(co, texvec); - VecMulf(co, 0.5f); - VecAddf(co, co, offset); + copy_v3_v3(co, texvec); + mul_v3_fl(co, 0.5f); + add_v3_v3v3(co, co, offset); /* co is now in the range 0.0, 1.0 */ switch (tex->extend) { diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 6c1055ec9e0..a3a714553d2 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -37,7 +37,7 @@ #include <limits.h> #include <string.h> -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_jitter.h" #include "BLI_threads.h" @@ -1808,16 +1808,16 @@ void zbuf_make_winmat(Render *re, float winmat[][4]) float panomat[4][4]; if(re->r.mode & R_PANORAMA) { - Mat4One(panomat); + unit_m4(panomat); panomat[0][0]= re->panoco; panomat[0][2]= re->panosi; panomat[2][0]= -re->panosi; panomat[2][2]= re->panoco; - Mat4MulMat4(winmat, panomat, re->winmat); + mul_m4_m4m4(winmat, panomat, re->winmat); } else - Mat4CpyMat4(winmat, re->winmat); + copy_m4_m4(winmat, re->winmat); } /* do zbuffering and clip, f1 f2 f3 are hocos, c1 c2 c3 are clipping flags */ @@ -2133,9 +2133,9 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*, continue; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; @@ -2312,9 +2312,9 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int continue; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); if(clip_render_object(obi->obr->boundbox, NULL, obwinmat)) continue; @@ -2551,9 +2551,9 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo continue; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; @@ -3297,9 +3297,9 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase * continue; if(obi->flag & R_TRANSFORMED) - Mat4MulMat4(obwinmat, obi->mat, winmat); + mul_m4_m4m4(obwinmat, obi->mat, winmat); else - Mat4CpyMat4(obwinmat, winmat); + copy_m4_m4(obwinmat, winmat); if(clip_render_object(obi->obr->boundbox, bounds, obwinmat)) continue; diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index f9732b9c929..554418e6483 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -52,6 +52,9 @@ void WM_init (struct bContext *C); void WM_exit (struct bContext *C); void WM_main (struct bContext *C); + +void WM_check (struct bContext *C); + struct wmWindow *WM_window_open (struct bContext *C, struct rcti *rect); /* defines for 'type' WM_window_open_temp */ @@ -83,6 +86,8 @@ void WM_timecursor (struct wmWindow *win, int nr); void *WM_paint_cursor_activate(struct wmWindowManager *wm, int (*poll)(struct bContext *C), void (*draw)(struct bContext *C, int, int, void *customdata), void *customdata); void WM_paint_cursor_end(struct wmWindowManager *wm, void *handle); +void WM_cursor_warp (struct wmWindow *win, int x, int y); + /* keyconfig and keymap */ wmKeyConfig *WM_keyconfig_add (struct wmWindowManager *wm, char *idname); void WM_keyconfig_free (struct wmKeyConfig *keyconf); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 3d31341c66a..891ed8358fb 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -133,8 +133,8 @@ typedef struct wmNotifier { #define NC_WORLD (13<<24) #define NC_ANIMATION (14<<24) #define NC_SPACE (15<<24) -#define NC_NODE (15<<24) #define NC_GEOM (16<<24) +#define NC_NODE (17<<24) /* data type, 256 entries is enough, it can overlap */ #define NOTE_DATA 0x00FF0000 @@ -211,6 +211,10 @@ typedef struct wmNotifier { #define ND_SELECT (80<<16) #define ND_DATA (81<<16) + /* NC_NODE Nodes */ +#define ND_NODE_SELECT (1<<16) + + /* NC_SPACE */ #define ND_SPACE_CONSOLE (1<<16) /* general redraw */ #define ND_SPACE_CONSOLE_REPORT (2<<16) /* update for reports, could specify type */ diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 1d173005d85..d455c8b2bc1 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -43,6 +43,7 @@ #include "BKE_main.h" #include "BKE_screen.h" #include "BKE_report.h" +#include "BKE_global.h" #include "WM_api.h" #include "WM_types.h" @@ -196,7 +197,7 @@ void WM_keymap_init(bContext *C) WM_keyconfig_userdef(wm); } -void wm_check(bContext *C) +void WM_check(bContext *C) { wmWindowManager *wm= CTX_wm_manager(C); @@ -208,19 +209,21 @@ void wm_check(bContext *C) if(wm==NULL) return; if(wm->windows.first==NULL) return; - /* case: fileread */ - if((wm->initialized & WM_INIT_WINDOW) == 0) { - WM_keymap_init(C); - WM_autosave_init(C); - } - - /* case: no open windows at all, for old file reads */ - wm_window_add_ghostwindows(wm); - - /* case: fileread */ - if((wm->initialized & WM_INIT_WINDOW) == 0) { - ED_screens_initialize(wm); - wm->initialized |= WM_INIT_WINDOW; + if (!G.background) { + /* case: fileread */ + if((wm->initialized & WM_INIT_WINDOW) == 0) { + WM_keymap_init(C); + WM_autosave_init(C); + } + + /* case: no open windows at all, for old file reads */ + wm_window_add_ghostwindows(wm); + + /* case: fileread */ + if((wm->initialized & WM_INIT_WINDOW) == 0) { + ED_screens_initialize(wm); + wm->initialized |= WM_INIT_WINDOW; + } } } diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index f301a20a7c1..fc453756ffa 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -498,12 +498,25 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex int retval; /* dummie test */ - if(ot && C && window) { - event= window->eventstate; + if(ot && C) { + switch(context) { + case WM_OP_INVOKE_DEFAULT: + case WM_OP_INVOKE_REGION_WIN: + case WM_OP_INVOKE_AREA: + case WM_OP_INVOKE_SCREEN: + /* window is needed for invoke, cancel operator */ + if (window == NULL) + return 0; + else + event= window->eventstate; + break; + default: + event = NULL; + } + switch(context) { case WM_OP_EXEC_REGION_WIN: - event= NULL; /* pass on without break */ case WM_OP_INVOKE_REGION_WIN: { /* forces operator to go to the region window, for header menus */ @@ -527,7 +540,6 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex return retval; } case WM_OP_EXEC_AREA: - event= NULL; /* pass on without break */ case WM_OP_INVOKE_AREA: { /* remove region from context */ @@ -540,7 +552,6 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex return retval; } case WM_OP_EXEC_SCREEN: - event= NULL; /* pass on without break */ case WM_OP_INVOKE_SCREEN: { /* remove region + area from context */ @@ -556,7 +567,6 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex return retval; } case WM_OP_EXEC_DEFAULT: - event= NULL; /* pass on without break */ case WM_OP_INVOKE_DEFAULT: return wm_operator_invoke(C, ot, event, properties, reports); } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index b2e55c8532e..6348e1a2717 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -256,8 +256,8 @@ void WM_read_file(bContext *C, char *name, ReportList *reports) G.save_over = 1; /* match the read WM with current WM */ - wm_window_match_do(C, &wmbase); - wm_check(C); /* opens window(s), checks keymaps */ + wm_window_match_do(C, &wmbase); + WM_check(C); /* opens window(s), checks keymaps */ // XXX mainwindow_set_filename_to_title(G.main->name); @@ -322,14 +322,14 @@ int WM_read_homefile(bContext *C, wmOperator *op) /* match the read WM with current WM */ wm_window_match_do(C, &wmbase); - wm_check(C); /* opens window(s), checks keymaps */ + WM_check(C); /* opens window(s), checks keymaps */ strcpy(G.sce, scestr); /* restore */ wm_init_userdef(); /* When loading factory settings, the reset solid OpenGL lights need to be applied. */ - GPU_default_lights(); + if (!G.background) GPU_default_lights(); /* XXX */ G.save_over = 0; // start with save preference untitled.blend diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 8097822acbc..06227086006 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -108,8 +108,10 @@ static void wm_free_reports(bContext *C) void WM_init(bContext *C) { - wm_ghost_init(C); /* note: it assigns C to ghost! */ - wm_init_cursor_data(); + if (!G.background) { + wm_ghost_init(C); /* note: it assigns C to ghost! */ + wm_init_cursor_data(); + } wm_operatortype_init(); set_free_windowmanager_cb(wm_close_and_free); /* library.c */ @@ -130,10 +132,12 @@ void WM_init(bContext *C) WM_read_homefile(C, NULL); wm_init_reports(C); /* reports cant be initialized before the wm */ - - GPU_extensions_init(); - UI_init(); + if (!G.background) { + GPU_extensions_init(); + + UI_init(); + } // clear_matcopybuf(); /* XXX */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 674f7233690..1f8e2e28024 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -1811,8 +1811,11 @@ static void tweak_gesture_modal(bContext *C, wmEvent *event) } break; default: - WM_gesture_end(C, gesture); - window->tweak= NULL; + if(!ISTIMER(event->type)) { + WM_gesture_end(C, gesture); + window->tweak= NULL; + } + break; } } diff --git a/source/blender/windowmanager/intern/wm_subwindow.c b/source/blender/windowmanager/intern/wm_subwindow.c index 081125bf7f6..00af9eb0bb9 100644 --- a/source/blender/windowmanager/intern/wm_subwindow.c +++ b/source/blender/windowmanager/intern/wm_subwindow.c @@ -38,7 +38,7 @@ #include "DNA_screen_types.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_global.h" @@ -133,7 +133,7 @@ void wm_subwindow_getmatrix(wmWindow *win, int swinid, float mat[][4]) wmSubWindow *swin= swin_from_swinid(win, swinid); if(swin) - Mat4MulMat4(mat, swin->viewmat, swin->winmat); + mul_m4_m4m4(mat, swin->viewmat, swin->winmat); } /* always sets pixel-precise 2D window/view matrices */ @@ -155,8 +155,8 @@ int wm_subwindow_open(wmWindow *win, rcti *winrct) swin->swinid= freewinid; swin->winrct= *winrct; - Mat4One(swin->viewmat); - Mat4One(swin->winmat); + unit_m4(swin->viewmat); + unit_m4(swin->winmat); /* and we appy it all right away */ wmSubWindowSet(win, swin->swinid); @@ -279,9 +279,9 @@ void wmLoadMatrix(float mat[][4]) glLoadMatrixf(mat); if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW) - Mat4CpyMat4(_curswin->viewmat, mat); + copy_m4_m4(_curswin->viewmat, mat); else - Mat4CpyMat4(_curswin->winmat, mat); + copy_m4_m4(_curswin->winmat, mat); } void wmGetMatrix(float mat[][4]) @@ -289,9 +289,9 @@ void wmGetMatrix(float mat[][4]) if(_curswin==NULL) return; if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW) { - Mat4CpyMat4(mat, _curswin->viewmat); + copy_m4_m4(mat, _curswin->viewmat); } else { - Mat4CpyMat4(mat, _curswin->winmat); + copy_m4_m4(mat, _curswin->winmat); } } @@ -317,8 +317,8 @@ void wmPushMatrix(void) printf("wmPushMatrix error already pushed\n"); debugpush= 1; - Mat4CpyMat4(_curswin->viewmat1, _curswin->viewmat); - Mat4CpyMat4(_curswin->winmat1, _curswin->winmat); + copy_m4_m4(_curswin->viewmat1, _curswin->viewmat); + copy_m4_m4(_curswin->winmat1, _curswin->winmat); } void wmPopMatrix(void) @@ -329,8 +329,8 @@ void wmPopMatrix(void) printf("wmPopMatrix error nothing popped\n"); debugpush= 0; - Mat4CpyMat4(_curswin->viewmat, _curswin->viewmat1); - Mat4CpyMat4(_curswin->winmat, _curswin->winmat1); + copy_m4_m4(_curswin->viewmat, _curswin->viewmat1); + copy_m4_m4(_curswin->winmat, _curswin->winmat1); glMatrixMode(GL_PROJECTION); glLoadMatrixf(&_curswin->winmat[0][0]); @@ -342,7 +342,7 @@ void wmPopMatrix(void) void wmGetSingleMatrix(float mat[][4]) { if(_curswin) - Mat4MulMat4(mat, _curswin->viewmat, _curswin->winmat); + mul_m4_m4m4(mat, _curswin->viewmat, _curswin->winmat); } void wmScale(float x, float y, float z) @@ -363,9 +363,9 @@ void wmLoadIdentity(void) if(_curswin==NULL) return; if (glaGetOneInteger(GL_MATRIX_MODE)==GL_MODELVIEW) - Mat4One(_curswin->viewmat); + unit_m4(_curswin->viewmat); else - Mat4One(_curswin->winmat); + unit_m4(_curswin->winmat); glLoadIdentity(); } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 70d40df4532..dbc3d27be6a 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -335,7 +335,7 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow /* for wmWindows without ghostwin, open these and clear */ /* window size is read from window, if 0 it uses prefsize */ -/* called in wm_check, also inits stuff after file read */ +/* called in WM_check, also inits stuff after file read */ void wm_window_add_ghostwindows(wmWindowManager *wm) { wmKeyMap *keymap; @@ -403,7 +403,7 @@ wmWindow *WM_window_open(bContext *C, rcti *rect) win->drawmethod= -1; win->drawdata= NULL; - wm_check(C); + WM_check(C); return win; } @@ -448,7 +448,7 @@ void WM_window_open_temp(bContext *C, rcti *position, int type) /* make window active, and validate/resize */ CTX_wm_window_set(C, win); - wm_check(C); + WM_check(C); /* ensure it shows the right spacetype editor */ sa= win->screen->areabase.first; @@ -480,7 +480,7 @@ void WM_window_open_temp(bContext *C, rcti *position, int type) int wm_window_duplicate_op(bContext *C, wmOperator *op) { wm_window_copy(C, CTX_wm_window(C)); - wm_check(C); + WM_check(C); return OPERATOR_FINISHED; } @@ -972,3 +972,18 @@ void WM_setprefsize(int stax, int stay, int sizx, int sizy) prefsizy= sizy; } +/* This function requires access to the GHOST_SystemHandle (g_system) */ +void WM_cursor_warp(wmWindow *win, int x, int y) +{ + if (win && win->ghostwin) { + int oldx=x, oldy=y; + + y= win->sizey -y - 1; + GHOST_ClientToScreen(win->ghostwin, x, y, &x, &y); + GHOST_SetCursorPosition(g_system, x, y); + + win->eventstate->prevx= oldx; + win->eventstate->prevy= oldy; + } +} + diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index c476b7efa1e..9b888a0e347 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -44,7 +44,6 @@ extern void wm_close_and_free(bContext *C, wmWindowManager *); extern void wm_close_and_free_all(bContext *C, ListBase *); extern void wm_add_default(bContext *C); -extern void wm_check(bContext *C); extern void wm_clear_default_size(bContext *C); /* register to windowmanager for redo or macro */ diff --git a/source/creator/creator.c b/source/creator/creator.c index 6f90c2ffe84..b4c962cbfc8 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -508,6 +508,27 @@ int main(int argc, char **argv) #endif } else { + for(a=1; a<argc; a++) { + if(argv[a][0] == '-') { + switch(argv[a][1]) { + case 'd': + G.f |= G_DEBUG; /* std output printf's */ + printf ("Blender %d.%02d (sub %d) Build\n", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION); + MEM_set_memory_debug(); +#ifdef NAN_BUILDINFO + printf("Build: %s %s %s %s\n", build_date, build_time, build_platform, build_type); + +#endif // NAN_BUILDINFO + for (i = 0; i < argc; i++) { + printf("argv[%d] = %s\n", i, argv[i]); + } + break; + } + } + } + + WM_init(C); + #ifndef DISABLE_PYTHON BPY_start_python(argc, argv); #endif @@ -524,13 +545,11 @@ int main(int argc, char **argv) */ BPY_post_start_python(); - if(!G.background) - BPY_run_ui_scripts(C, 0); /* dont need to reload the first time */ + BPY_run_ui_scripts(C, 0); /* dont need to reload the first time */ #endif CTX_py_init_set(C, 1); - if(!G.background) - WM_keymap_init(C); /* after BPY_run_ui_scripts() */ + WM_keymap_init(C); /* after BPY_run_ui_scripts() */ #ifdef WITH_QUICKTIME @@ -621,7 +640,7 @@ int main(int argc, char **argv) frame = MIN2(MAXFRAME, MAX2(MINAFRAME, frame)); - RE_BlenderAnim(re, scene, frame, frame, scene->frame_step); + RE_BlenderAnim(re, scene, frame, frame, scene->r.frame_step); } } else { printf("\nError: no blend loaded. cannot use '-f'.\n"); @@ -631,7 +650,7 @@ int main(int argc, char **argv) if (CTX_data_scene(C)) { Scene *scene= CTX_data_scene(C); Render *re= RE_NewRender(scene->id.name); - RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->frame_step); + RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->r.frame_step); } else { printf("\nError: no blend loaded. cannot use '-a'.\n"); } @@ -671,7 +690,7 @@ int main(int argc, char **argv) Scene *scene= CTX_data_scene(C); if (a < argc) { int frame = atoi(argv[a]); - (scene->frame_step) = MIN2(MAXFRAME, MAX2(1, frame)); + (scene->r.frame_step) = MIN2(MAXFRAME, MAX2(1, frame)); } } else { printf("\nError: no blend loaded. cannot use '-j'.\n"); @@ -843,7 +862,11 @@ int main(int argc, char **argv) /*we successfully loaded a blend file, get sure that pointcache works */ - if (retval!=0) G.relbase_valid = 1; + if (retval!=0) { + CTX_wm_manager_set(C, NULL); /* remove wm to force check */ + WM_check(C); + G.relbase_valid = 1; + } /* happens for the UI on file reading too (huh? (ton))*/ // XXX BKE_reset_undo(); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index 73803846d70..e53a96ad9f6 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -138,17 +138,17 @@ void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate) { case MOUSE_INVISIBLE: { - BL_HideMouse(); + BL_HideMouse(m_win); break; } case MOUSE_WAIT: { - BL_WaitMouse(); + BL_WaitMouse(m_win); break; } case MOUSE_NORMAL: { - BL_NormalMouse(); + BL_NormalMouse(m_win); break; } default: @@ -166,7 +166,7 @@ void KX_BlenderCanvas::SetMousePosition(int x,int y) int winY = m_frame_rect.GetBottom(); int winH = m_frame_rect.GetHeight(); - BL_warp_pointer(winX + x, winY + (winH-y-1)); + BL_warp_pointer(m_win, winX + x, winY + (winH-y-1)); } diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h index 5967ce78b46..2c6962b5863 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h @@ -64,7 +64,7 @@ public: * * @param area The Blender ARegion to run the game within. */ - KX_BlenderCanvas(struct wmWindow* win, struct RAS_Rect &rect); + KX_BlenderCanvas(struct wmWindow* win, class RAS_Rect &rect); ~KX_BlenderCanvas(); void diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index bb02f3b372e..b718dfc1acd 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -73,11 +73,11 @@ extern "C" { #include "BKE_image.h" extern "C" { -//XXX #include "BDR_drawmesh.h" -//XXX #include "BIF_mywindow.h" -//XXX #include "BIF_toolbox.h" -//XXX #include "BIF_graphics.h" /* For CURSOR_NONE CURSOR_WAIT CURSOR_STD */ -void wm_window_swap_buffers(wmWindow *win); // wm_window.h +#include "WM_api.h" +#include "WM_types.h" +#include "wm_event_system.h" +#include "wm_cursors.h" +#include "wm_window.h" } /* end of blender block */ @@ -90,16 +90,14 @@ void spack(unsigned int ucol) glColor3ub(cp[3], cp[2], cp[1]); } -void BL_warp_pointer(int x,int y) +void BL_warp_pointer(wmWindow *win, int x,int y) { - //XXX warp_pointer(x,y); + WM_cursor_warp(win, x, y); } void BL_SwapBuffers(wmWindow *win) { - //wmWindow *window= CTX_wm_window(C); wm_window_swap_buffers(win); - //XXX myswapbuffers(); } void DisableForText() @@ -194,21 +192,21 @@ void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int widt glEnable(GL_DEPTH_TEST); } -void BL_HideMouse() +void BL_HideMouse(wmWindow *win) { - //XXX set_cursor(CURSOR_NONE); + WM_cursor_set(win, CURSOR_NONE); } -void BL_WaitMouse() +void BL_WaitMouse(wmWindow *win) { - //XXX set_cursor(CURSOR_WAIT); + WM_cursor_set(win, CURSOR_WAIT); } -void BL_NormalMouse() +void BL_NormalMouse(wmWindow *win) { - //XXX set_cursor(CURSOR_STD); + WM_cursor_set(win, CURSOR_STD); } #define MAX_FILE_LENGTH 512 diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h index 5c947ff630e..d93b5eeabc5 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h @@ -39,13 +39,13 @@ struct ARegion; // special swapbuffers, that takes care of which area (viewport) needs to be swapped void BL_SwapBuffers(struct wmWindow *win); -void BL_warp_pointer(int x,int y); +void BL_warp_pointer(struct wmWindow *win,int x,int y); void BL_MakeScreenShot(struct ARegion *ar, const char* filename); -void BL_HideMouse(); -void BL_NormalMouse(); -void BL_WaitMouse(); +void BL_HideMouse(struct wmWindow *win); +void BL_NormalMouse(struct wmWindow *win); +void BL_WaitMouse(struct wmWindow *win); void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height); void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int width, int height); diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 6f3036d8e09..1325c80a6d4 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -46,7 +46,7 @@ #include "DNA_scene_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "MT_Matrix4x4.h" #include "BKE_utildefines.h" #include "FloatValue.h" @@ -539,8 +539,8 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel, if(pchan) { VECCOPY (pchan->loc, matrix[3]); - Mat4ToSize(matrix, pchan->size); - Mat4ToQuat(matrix, pchan->quat); + mat4_to_size( pchan->size,matrix); + mat4_to_quat( pchan->quat,matrix); } } else { diff --git a/source/gameengine/Converter/BL_ArmatureActuator.cpp b/source/gameengine/Converter/BL_ArmatureActuator.cpp index b70a0aa79e7..603dfc370b4 100644 --- a/source/gameengine/Converter/BL_ArmatureActuator.cpp +++ b/source/gameengine/Converter/BL_ArmatureActuator.cpp @@ -33,7 +33,7 @@ #include "BKE_constraint.h" #include "BL_ArmatureActuator.h" #include "BL_ArmatureObject.h" -#include "BLI_arithb.h" +#include "BLI_math.h" /** * This class is the conversion of the Pose channel constraint. diff --git a/source/gameengine/Converter/BL_ArmatureChannel.cpp b/source/gameengine/Converter/BL_ArmatureChannel.cpp index 9a9161b080f..2444390c9f3 100644 --- a/source/gameengine/Converter/BL_ArmatureChannel.cpp +++ b/source/gameengine/Converter/BL_ArmatureChannel.cpp @@ -34,7 +34,7 @@ #include "BL_ArmatureChannel.h" #include "BL_ArmatureObject.h" #include "BL_ArmatureConstraint.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_string.h" #ifndef DISABLE_PYTHON @@ -180,10 +180,10 @@ int BL_ArmatureChannel::py_attr_setattr(void *self_v, const struct KX_PYATTRIBUT bPoseChannel* channel = self->m_posechannel; int attr_order = attrdef-Attributes; - int ival; - double dval; - char* sval; - KX_GameObject *oval; +// int ival; +// double dval; +// char* sval; +// KX_GameObject *oval; if (!channel) { PyErr_SetString(PyExc_AttributeError, "channel is NULL"); @@ -211,19 +211,19 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str float norm; double sa, ca; // get rotation in armature space - Mat3CpyMat4(pose_mat, pchan->pose_mat); - Mat3Ortho(pose_mat); + copy_m3_m4(pose_mat, pchan->pose_mat); + normalize_m3(pose_mat); if (pchan->parent) { // bone has a parent, compute the rest pose of the bone taking actual pose of parent - Mat3IsMat3MulMat4(rest_mat, pchan->bone->bone_mat, pchan->parent->pose_mat); - Mat3Ortho(rest_mat); + mul_m3_m3m4(rest_mat, pchan->bone->bone_mat, pchan->parent->pose_mat); + normalize_m3(rest_mat); } else { // otherwise, the bone matrix in armature space is the rest pose - Mat3CpyMat4(rest_mat, pchan->bone->arm_mat); + copy_m3_m4(rest_mat, pchan->bone->arm_mat); } // remove the rest pose to get the joint movement - Mat3Transp(rest_mat); - Mat3MulMat3(joint_mat, rest_mat, pose_mat); + transpose_m3(rest_mat); + mul_m3_m3m3(joint_mat, rest_mat, pose_mat); joints[0] = joints[1] = joints[2] = 0.f; // returns a 3 element list that gives corresponding joint int flag = 0; @@ -237,35 +237,35 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str case 0: // fixed joint break; case 1: // X only - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[1] = joints[2] = 0.f; break; case 2: // Y only - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[0] = joints[2] = 0.f; break; case 3: // X+Y - Mat3ToEulO(joint_mat, joints, EULER_ORDER_ZYX); + mat3_to_eulO( joints, EULER_ORDER_ZYX,joint_mat); joints[2] = 0.f; break; case 4: // Z only - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[0] = joints[1] = 0.f; break; case 5: // X+Z // decompose this as an equivalent rotation vector in X/Z plane joints[0] = joint_mat[1][2]; joints[2] = -joint_mat[1][0]; - norm = Normalize(joints); + norm = normalize_v3(joints); if (norm < FLT_EPSILON) { norm = (joint_mat[1][1] < 0.f) ? M_PI : 0.f; } else { norm = acos(joint_mat[1][1]); } - VecMulf(joints, norm); + mul_v3_fl(joints, norm); break; case 6: // Y+Z - Mat3ToEulO(joint_mat, joints, EULER_ORDER_XYZ); + mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat); joints[0] = 0.f; break; case 7: // X+Y+Z @@ -273,14 +273,14 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str joints[0] = (joint_mat[1][2]-joint_mat[2][1])*0.5f; joints[1] = (joint_mat[2][0]-joint_mat[0][2])*0.5f; joints[2] = (joint_mat[0][1]-joint_mat[1][0])*0.5f; - sa = VecLength(joints); + sa = len_v3(joints); ca = (joint_mat[0][0]+joint_mat[1][1]+joint_mat[1][1]-1.0f)*0.5f; if (sa > FLT_EPSILON) { norm = atan2(sa,ca)/sa; } else { if (ca < 0.0) { norm = M_PI; - VecMulf(joints,0.f); + mul_v3_fl(joints,0.f); if (joint_mat[0][0] > 0.f) { joints[0] = 1.0f; } else if (joint_mat[1][1] > 0.f) { @@ -292,7 +292,7 @@ PyObject* BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const str norm = 0.0; } } - VecMulf(joints,norm); + mul_v3_fl(joints,norm); break; } return newVectorObject(joints, 3, Py_NEW, NULL); @@ -327,45 +327,45 @@ int BL_ArmatureChannel::py_attr_set_joint_rotation(void *self_v, const struct KX flag |= 2; if (!(pchan->ikflag & BONE_IK_NO_ZDOF)) flag |= 4; - QuatOne(quat); + unit_qt(quat); switch (flag) { case 0: // fixed joint break; case 1: // X only joints[1] = joints[2] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 2: // Y only joints[0] = joints[2] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 3: // X+Y joints[2] = 0.f; - EulOToQuat(joints, EULER_ORDER_ZYX, quat); + eulO_to_quat( quat,joints, EULER_ORDER_ZYX); break; case 4: // Z only joints[0] = joints[1] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 5: // X+Z // X and Z are components of an equivalent rotation axis joints[1] = 0; - VecRotToQuat(joints, VecLength(joints), quat); + axis_angle_to_quat( quat,joints, len_v3(joints)); break; case 6: // Y+Z joints[0] = 0.f; - EulOToQuat(joints, EULER_ORDER_XYZ, quat); + eulO_to_quat( quat,joints, EULER_ORDER_XYZ); break; case 7: // X+Y+Z // equivalent axis - VecRotToQuat(joints, VecLength(joints), quat); + axis_angle_to_quat( quat,joints, len_v3(joints)); break; } if (pchan->rotmode > 0) { - QuatToEulO(quat, joints, pchan->rotmode); - VecCopyf(pchan->eul, joints); + quat_to_eulO( joints, pchan->rotmode,quat); + copy_v3_v3(pchan->eul, joints); } else - QuatCopy(pchan->quat, quat); + copy_qt_qt(pchan->quat, quat); return PY_SET_ATTR_SUCCESS; } diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.cpp b/source/gameengine/Converter/BL_ArmatureConstraint.cpp index 42581b63ec4..c37f963b82f 100644 --- a/source/gameengine/Converter/BL_ArmatureConstraint.cpp +++ b/source/gameengine/Converter/BL_ArmatureConstraint.cpp @@ -34,7 +34,7 @@ #include "DNA_action_types.h" #include "BL_ArmatureConstraint.h" #include "BL_ArmatureObject.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BLI_string.h" #ifndef DISABLE_PYTHON @@ -82,12 +82,12 @@ BL_ArmatureConstraint::BL_ArmatureConstraint( m_blendsubtarget = (subtarget) ? subtarget->GetBlenderObject() : NULL; m_pose = m_subpose = NULL; if (m_blendtarget) { - Mat4CpyMat4(m_blendmat, m_blendtarget->obmat); + copy_m4_m4(m_blendmat, m_blendtarget->obmat); if (m_blendtarget->type == OB_ARMATURE) m_pose = m_blendtarget->pose; } if (m_blendsubtarget) { - Mat4CpyMat4(m_blendsubmat, m_blendsubtarget->obmat); + copy_m4_m4(m_blendsubmat, m_blendsubtarget->obmat); if (m_blendsubtarget->type == OB_ARMATURE) m_subpose = m_blendsubtarget->pose; } @@ -198,12 +198,12 @@ void BL_ArmatureConstraint::RestoreTarget() { if (m_constraint && !(m_constraint->flag&CONSTRAINT_OFF) && (!m_blendtarget || m_target)) { if (m_blendtarget) { - Mat4CpyMat4(m_blendtarget->obmat, m_blendmat); + copy_m4_m4(m_blendtarget->obmat, m_blendmat); if (m_pose) m_blendtarget->pose = m_pose; } if (m_blendsubtarget && m_subtarget) { - Mat4CpyMat4(m_blendsubtarget->obmat, m_blendsubmat); + copy_m4_m4(m_blendsubtarget->obmat, m_blendsubmat); if (m_subpose) m_blendsubtarget->pose = m_subpose; } diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp index a6066adc03e..f62a6b84fca 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.cpp +++ b/source/gameengine/Converter/BL_ArmatureObject.cpp @@ -32,7 +32,7 @@ #include "KX_BlenderSceneConverter.h" #include "BLI_blenlib.h" #include "BLI_ghash.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "BIK_api.h" #include "BKE_action.h" #include "BKE_armature.h" @@ -158,13 +158,13 @@ void game_blend_poses(bPose *dst, bPose *src, float srcweight/*, short mode*/) QUATCOPY(dquat, dchan->quat); QUATCOPY(squat, schan->quat); if (mode==ACTSTRIPMODE_BLEND) - QuatInterpol(dchan->quat, dquat, squat, srcweight); + interp_qt_qtqt(dchan->quat, dquat, squat, srcweight); else { - QuatMulFac(squat, srcweight); - QuatMul(dchan->quat, dquat, squat); + mul_fac_qt_fl(squat, srcweight); + mul_qt_qtqt(dchan->quat, dquat, squat); } - NormalQuat(dchan->quat); + normalize_qt(dchan->quat); } for (i=0; i<3; i++) { diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index db32f18f63b..6e26182a23f 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -135,7 +135,7 @@ #include "BKE_mesh.h" #include "MT_Point3.h" -#include "BLI_arithb.h" +#include "BLI_math.h" extern "C" { #include "BKE_customdata.h" @@ -805,15 +805,15 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, if(mface->flag & ME_SMOOTH) { float n0[3], n1[3], n2[3], n3[3]; - NormalShortToFloat(n0, mvert[mface->v1].no); - NormalShortToFloat(n1, mvert[mface->v2].no); - NormalShortToFloat(n2, mvert[mface->v3].no); + normal_short_to_float_v3(n0, mvert[mface->v1].no); + normal_short_to_float_v3(n1, mvert[mface->v2].no); + normal_short_to_float_v3(n2, mvert[mface->v3].no); no0 = n0; no1 = n1; no2 = n2; if(mface->v4) { - NormalShortToFloat(n3, mvert[mface->v4].no); + normal_short_to_float_v3(n3, mvert[mface->v4].no); no3 = n3; } } @@ -821,11 +821,9 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, float fno[3]; if(mface->v4) - CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co, - mvert[mface->v3].co, mvert[mface->v4].co, fno); + normal_quad_v3( fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co); else - CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co, - mvert[mface->v3].co, fno); + normal_tri_v3( fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co); no0 = no1 = no2 = no3 = MT_Vector3(fno); } @@ -1818,7 +1816,7 @@ bPoseChannel *get_active_posechannel2 (Object *ob) /* find active */ for(pchan= (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if(pchan->bone && (pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) + if(pchan->bone && (pchan->bone == arm->act_bone) && (pchan->bone->layer & arm->layer)) return pchan; } diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp index d7012abe316..0abc344a844 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.cpp +++ b/source/gameengine/Converter/BL_MeshDeformer.cpp @@ -47,7 +47,7 @@ #include "GEN_Map.h" #include "STR_HashedString.h" -#include "BLI_arithb.h" +#include "BLI_math.h" bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*) { @@ -176,7 +176,7 @@ void BL_MeshDeformer::RecalcNormals() fnor[0]= n1[1]*n2[2] - n1[2]*n2[1]; fnor[1]= n1[2]*n2[0] - n1[0]*n2[2]; fnor[2]= n1[0]*n2[1] - n1[1]*n2[0]; - Normalize(fnor); + normalize_v3(fnor); /* add to vertices for smooth normals */ float *vn1 = m_transnors[v1.getOrigIndex()]; diff --git a/source/gameengine/Converter/BL_ModifierDeformer.cpp b/source/gameengine/Converter/BL_ModifierDeformer.cpp index 80165548ff2..0cdca74fea5 100644 --- a/source/gameengine/Converter/BL_ModifierDeformer.cpp +++ b/source/gameengine/Converter/BL_ModifierDeformer.cpp @@ -64,7 +64,7 @@ extern "C"{ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 0af6556f285..4171bfcc58e 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -46,7 +46,7 @@ #include "DNA_armature_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "MT_Matrix4x4.h" #include "BKE_utildefines.h" #include "FloatValue.h" diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index 125e91e0e0a..9b6d3f61705 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -58,7 +58,7 @@ extern "C"{ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index f166a7252ad..ecc45b2da1a 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -52,7 +52,7 @@ extern "C"{ #include "BKE_utildefines.h" #include "BLI_blenlib.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #define __NLA_DEFNORMALS //#undef __NLA_DEFNORMALS @@ -70,7 +70,7 @@ BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj, m_poseApplied(false), m_recalcNormal(true) { - Mat4CpyMat4(m_obmat, bmeshobj->obmat); + copy_m4_m4(m_obmat, bmeshobj->obmat); }; BL_SkinDeformer::BL_SkinDeformer( @@ -93,7 +93,7 @@ BL_SkinDeformer::BL_SkinDeformer( // that takes an object as parameter and not a mesh. The object matrice is used // in the calculation, so we must use the matrix of the original object to // simulate a pure replacement of the mesh. - Mat4CpyMat4(m_obmat, bmeshobj_new->obmat); + copy_m4_m4(m_obmat, bmeshobj_new->obmat); } BL_SkinDeformer::~BL_SkinDeformer() @@ -194,14 +194,14 @@ bool BL_SkinDeformer::UpdateInternal(bool shape_applied) m_armobj->ApplyPose(); // save matrix first - Mat4CpyMat4(obmat, m_objMesh->obmat); + copy_m4_m4(obmat, m_objMesh->obmat); // set reference matrix - Mat4CpyMat4(m_objMesh->obmat, m_obmat); + copy_m4_m4(m_objMesh->obmat, m_obmat); armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, NULL, m_bmesh->totvert, ARM_DEF_VGROUP, NULL, NULL ); // restore matrix - Mat4CpyMat4(m_objMesh->obmat, obmat); + copy_m4_m4(m_objMesh->obmat, obmat); #ifdef __NLA_DEFNORMALS if (m_recalcNormal) diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 26b4514061c..8e7560cdcbd 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -66,7 +66,7 @@ #include "DNA_world_types.h" #include "BKE_main.h" -#include "BLI_arithb.h" +#include "BLI_math.h" extern "C" { @@ -617,8 +617,8 @@ extern "C" //XXX void testhandles_ipocurve(struct IpoCurve *icu); void insert_vert_icu(struct IpoCurve *, float, float, short); float eval_icu(struct IpoCurve *icu, float ipotime); - //void Mat3ToEul(float tmat[][3], float *eul); - void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot); + //void mat3_to_eul( float *eul,float tmat[][3]); + void mat3_to_compatible_eul( float *eul, float *oldrot,float mat[][3]); } IpoCurve* findIpoCurve(IpoCurve* first, const char* searchName) @@ -742,7 +742,7 @@ void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo(){ if (blenderobject->type==OB_ARMATURE) continue; float eu[3]; - Mat4ToEul(blenderobject->obmat,eu); + mat4_to_eul(eu,blenderobject->obmat); MT_Point3 pos = MT_Point3( blenderobject->obmat[3][0], blenderobject->obmat[3][1], @@ -847,8 +847,8 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) for (int c=0;c<3;c++) tmat[r][c] = orn[c][r]; - // Mat3ToEul(tmat, eulerAngles); // better to use Mat3ToCompatibleEul - Mat3ToCompatibleEul(tmat, eulerAngles, eulerAnglesOld); + // mat3_to_eul( eulerAngles,tmat); // better to use Mat3ToCompatibleEul + mat3_to_compatible_eul( eulerAngles, eulerAnglesOld,tmat); //eval_icu for(int x = 0; x < 3; x++) diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp index 91135079fe6..2771b6c45b5 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp +++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp @@ -107,7 +107,7 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr) { if (value->IsError()) { - printf(value->GetText()); + printf("%s\n", value->GetText().ReadPtr()); } else { float num = (float)value->GetNumber(); diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index c0d7b639077..b62593b7911 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -33,7 +33,7 @@ Developed as part of a Research and Development project for SAT - La Soci�t� #include "DNA_scene_types.h" #include "RAS_CameraData.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "GL/glew.h" diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index d516d3e03ff..d18e11d3ca5 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -79,7 +79,7 @@ typedef unsigned long uint_ptr; #include "KX_SG_NodeRelationships.h" -#include "BLI_arithb.h" +#include "BLI_math.h" static MT_Point3 dummy_point= MT_Point3(0.0, 0.0, 0.0); static MT_Vector3 dummy_scaling = MT_Vector3(1.0, 1.0, 1.0); @@ -474,9 +474,9 @@ void KX_GameObject::UpdateBlenderObjectMatrix(Object* blendobj) const MT_Vector3& pos = NodeGetWorldPosition(); rot.getValue(blendobj->obmat[0]); pos.getValue(blendobj->obmat[3]); - VecMulf(blendobj->obmat[0], scale[0]); - VecMulf(blendobj->obmat[1], scale[1]); - VecMulf(blendobj->obmat[2], scale[2]); + mul_v3_fl(blendobj->obmat[0], scale[0]); + mul_v3_fl(blendobj->obmat[1], scale[1]); + mul_v3_fl(blendobj->obmat[2], scale[2]); } } diff --git a/source/gameengine/Ketsji/KX_IPO_SGController.cpp b/source/gameengine/Ketsji/KX_IPO_SGController.cpp index bd7e09d1dda..edd3a82b6b0 100644 --- a/source/gameengine/Ketsji/KX_IPO_SGController.cpp +++ b/source/gameengine/Ketsji/KX_IPO_SGController.cpp @@ -49,7 +49,7 @@ typedef unsigned long uint_ptr; #include "KX_GameObject.h" #include "KX_IPhysicsController.h" #include "DNA_ipo_types.h" -#include "BLI_arithb.h" +#include "BLI_math.h" // All objects should start on frame 1! Will we ever need an object to // start on another frame, the 1.0 should change. diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 6e70bfb14a0..62594f9552c 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -34,7 +34,7 @@ http://www.gnu.org/copyleft/lesser.txt. #include "DNA_scene_types.h" #include "RAS_CameraData.h" #include "RAS_MeshObject.h" -#include "BLI_arithb.h" +#include "BLI_math.h" #include "ImageRender.h" #include "ImageBase.h" @@ -589,15 +589,15 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj { v4 = polygon->GetVertex(3); mirrorVerts.push_back(v4); - area = CalcNormFloat4((float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ(), (float*)v4->getXYZ(), normal); + area = normal_quad_v3( normal,(float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ(), (float*)v4->getXYZ()); } else { - area = CalcNormFloat((float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ(), normal); + area = normal_tri_v3( normal,(float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ()); } area = fabs(area); mirrorArea += area; - VecMulf(normal, area); - VecAddf(mirrorNormal, mirrorNormal, normal); + mul_v3_fl(normal, area); + add_v3_v3v3(mirrorNormal, mirrorNormal, normal); } } } @@ -607,8 +607,8 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj THRWEXCP(MirrorSizeInvalid, S_OK); } // compute average normal of mirror faces - VecMulf(mirrorNormal, 1.0f/mirrorArea); - if (Normalize(mirrorNormal) == 0.f) + mul_v3_fl(mirrorNormal, 1.0f/mirrorArea); + if (normalize_v3(mirrorNormal) == 0.f) { // no normal THRWEXCP(MirrorNormalInvalid, S_OK); @@ -622,26 +622,26 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj fabs(mirrorNormal[2]) > fabs(mirrorNormal[0])) { // the mirror is more horizontal than vertical - VecCopyf(axis, yaxis); + copy_v3_v3(axis, yaxis); } else { // the mirror is more vertical than horizontal - VecCopyf(axis, zaxis); + copy_v3_v3(axis, zaxis); } - dist = Inpf(mirrorNormal, axis); + dist = dot_v3v3(mirrorNormal, axis); if (fabs(dist) < FLT_EPSILON) { // the mirror is already fully aligned with up axis - VecCopyf(mirrorUp, axis); + copy_v3_v3(mirrorUp, axis); } else { // projection of axis to mirror plane through normal - VecCopyf(vec, mirrorNormal); - VecMulf(vec, dist); - VecSubf(mirrorUp, axis, vec); - if (Normalize(mirrorUp) == 0.f) + copy_v3_v3(vec, mirrorNormal); + mul_v3_fl(vec, dist); + sub_v3_v3v3(mirrorUp, axis, vec); + if (normalize_v3(mirrorUp) == 0.f) { // should not happen THRWEXCP(MirrorHorizontal, S_OK); @@ -650,12 +650,12 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj } // compute rotation matrix between local coord and mirror coord // to match camera orientation, we select mirror z = -normal, y = up, x = y x z - VecCopyf(mirrorMat[2], mirrorNormal); - VecMulf(mirrorMat[2], -1.0f); - VecCopyf(mirrorMat[1], mirrorUp); - Crossf(mirrorMat[0], mirrorMat[1], mirrorMat[2]); + copy_v3_v3(mirrorMat[2], mirrorNormal); + mul_v3_fl(mirrorMat[2], -1.0f); + copy_v3_v3(mirrorMat[1], mirrorUp); + cross_v3_v3v3(mirrorMat[0], mirrorMat[1], mirrorMat[2]); // transpose to make it a orientation matrix from local space to mirror space - Mat3Transp(mirrorMat); + transpose_m3(mirrorMat); // transform all vertex to plane coordinates and determine mirror position left = FLT_MAX; right = -FLT_MAX; @@ -664,8 +664,8 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj back = -FLT_MAX; // most backward vertex (=highest Z coord in mirror space) for (it = mirrorVerts.begin(); it != mirrorVerts.end(); it++) { - VecCopyf(vec, (float*)(*it)->getXYZ()); - Mat3MulVecfl(mirrorMat, vec); + copy_v3_v3(vec, (float*)(*it)->getXYZ()); + mul_m3_v3(mirrorMat, vec); if (vec[0] < left) left = vec[0]; if (vec[0] > right) @@ -690,8 +690,8 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj vec[1] = (top+bottom)*0.5f; vec[2] = back; // convert it in local space: transpose again the matrix to get back to mirror to local transform - Mat3Transp(mirrorMat); - Mat3MulVecfl(mirrorMat, vec); + transpose_m3(mirrorMat); + mul_m3_v3(mirrorMat, vec); // mirror position in local space m_mirrorPos.setValue(vec[0], vec[1], vec[2]); // mirror normal vector (pointed towards the back of the mirror) in local space diff --git a/source/nan_definitions.mk b/source/nan_definitions.mk index 1aff7e1dea7..50df0e777cc 100644 --- a/source/nan_definitions.mk +++ b/source/nan_definitions.mk @@ -81,8 +81,8 @@ ifndef CONFIG_GUESS endif export NAN_MOTO ?= $(LCGDIR)/moto - export NAN_ITASC ?= $(LCGDIR)/itasc - + export NAN_ITASC ?= $(LCGDIR)/itasc + export BF_PROFILE ?= false export NAN_USE_BULLET ?= true export NAN_BULLET2 ?= $(LCGDIR)/bullet2 @@ -122,6 +122,7 @@ ifndef CONFIG_GUESS export WITH_OPENAL ?= false export WITH_JACK ?= false export WITH_SNDFILE ?= false + export WITH_FFTW3 ?= false ifeq ($(WITH_OPENAL), true) export NAN_OPENAL ?= /usr @@ -195,7 +196,7 @@ ifndef CONFIG_GUESS export NAN_OPENEXR ?= $(LCGDIR)/openexr export NAN_OPENEXR_INC ?= -I$(NAN_OPENEXR)/include -I$(NAN_OPENEXR)/include/OpenEXR export NAN_OPENEXR_LIBS ?= $(NAN_OPENEXR)/lib/libIlmImf.a $(NAN_OPENEXR)/lib/libHalf.a $(NAN_OPENEXR)/lib/libIex.a $(NAN_OPENEXR)/lib/libIlmThread.a - + export NAN_NO_KETSJI=false ifeq ($(CPU), i386) @@ -350,6 +351,18 @@ ifndef CONFIG_GUESS export NAN_OPENEXR_LIBS ?= $(addprefix ${NAN_OPENEXR}/lib/lib,$(addsuffix .a,$(shell pkg-config --libs-only-l OpenEXR | sed -s "s/-l//g" ))) endif + ifeq ($(WITH_FFTW3), true) + export BF_FFTW3 ?= $(shell pkg-config --variable=prefix fftw3 ) + export BF_FFTW3_INC ?= $(shell pkg-config --variable=includedir fftw3 ) + export BF_FFTW3_LIBS ?= $(shell pkg-config --libs fftw3 ) + endif + + ifeq ($(WITH_OPENJPEG), true) + export BF_OPENJPEG ?= /usr + export BF_OPENJPEG_INC ?= /usr/include + export BF_OPENJPEG_LIBS ?= -lopenjpeg + endif + # Uncomment the following line to use Mozilla inplace of netscape # Location of MOZILLA/Netscape header files... diff --git a/source/nan_link.mk b/source/nan_link.mk index 52e5c5de9ed..8f33c917526 100644 --- a/source/nan_link.mk +++ b/source/nan_link.mk @@ -170,4 +170,8 @@ ifeq ($(WITH_BF_OPENMP),true) LLIBS += -lgomp endif +ifeq ($(WITH_FFTW3),true) + LLIBS += $(BF_FFTW3_LIBS) +endif + LLIBS += $(NAN_PYTHON_LIB) |