Commit Graph

35 Commits

Author SHA1 Message Date
403b62fbcf matrix .inverted() and .transposed() didnt work because the matrix was wrongly copied.
2 more memory leaks in matrix multiplication fixed.
2006-07-27 02:33:54 +00:00
b227c98c44 Addition to Mathutils
vec.normalized()
 mat.inverted()
 mat.transposed()
 made vec/float possible

 normalize/invert/transpose now return None because they modify the data in place.
 use the ...(ed) versions to return a modified copy.


Fixed Memory leaks from not decreffing PyFloat_AS_DOUBLE from these python functions...
(found when testing above functions)
  ob.rbMass
  ob.rbRadius
  matrix.determinant()
  quat*float
  vec*float
  matrix.transpose()
  EXPP_setModuleConstant

Checked all instances of PyFloat_AS_DOUBLE so I dont think there are any mroe leaks there.
2006-07-27 01:18:21 +00:00
176a4c8507 Added scalePart to mathutils matrix type object.
and made it so toEuler converts a 4x4 matrix to a 3x3 rather then raising an error.

Its not straight fwd to get an objects worldspace loc/size/rot from its 4x4 matrix.
Example from updated docs.
      import Blender
      scn = Blender.Scene.GetCurrent()
      ob = scn.getActiveObject()
      if ob:
        mat= ob.mat # Same as martixWorld
        print 'Location", mat.translationPart() # 3D Vector
        print 'Size", mat.scalePart() # 3D Vector
        print 'Rotation", mat.toEuler() # Euler object
2006-04-27 12:32:44 +00:00
Ken Hughes
5fa5ea352e ===Bugfix===
matrix.resize4x4() was incorrectly allocating a array of pointers using
the wrong cast -- sizeof(float) instead of sizeof(float *).  Worked fine
on 32-bit systems but caused a crash on AMD64.  Discovered by a student
in one of my classes (kudos, Joe).
2006-04-24 23:00:03 +00:00
9fedbd6c51 ==Python==
Small bug reported on irc, matrix.translationPart didn't check bounds
properly (needed to use || instead of &&). Also fixed similar bugs in
rotationPart and rich compare.
2006-02-15 22:31:43 +00:00
5f0232f68f *pose code for python
- adds object.getPose
- ability to manipulate poses /posebones
- fixes a overflow bug in matrix sequence accessor
- adds code to get vec/roll from mat3
- few internal fixes to NLA
- ability to set bone matrices
2006-01-11 19:40:06 +00:00
9e36d4bc8e [ #3661 ] resize4x4 in Matrix class doesn't set ones on the diagonal
* resizing a matrix now puts 1's back on the diagonals.
2006-01-04 16:02:02 +00:00
Ken Hughes
1a2ac4e64d -- Bugfix #3072: As discussed on IRC, matrix.invert() should throw a
ValueError exception if matrix is singular.
2005-12-05 19:57:23 +00:00
Ken Hughes
e209676d3d -- Bugfix 3453: coercion operations were doing an extra incref on coerced
objects.  Also found extra increfs on some newly-created quat and matrix
   objects, from calls to Matrix_Identity() and Quaternion_Identity().
2005-12-05 19:02:30 +00:00
b63e26e109 Added some equvalency tests for the other math objects
* ==, != are defined for matrix, quat, euler.
2005-11-22 17:59:49 +00:00
3f8f0f7aac Silly error string correction 2005-11-03 20:22:29 +00:00
39a243f8d2 Refcount fixes
* fixes posible reference count issues with mathutils
* mathutils classes should no longer memory leak
2005-09-27 17:03:28 +00:00
Stephen Swaney
a4ca8267cf bugfix: [ #3009 ] possible memory leak in Mathutils
fixed by patch [ #3013 ] patch for memleak in vector
Submitted By: Ken Hughes (khughes)
2005-09-12 06:18:45 +00:00
6a9e7ab3f2 _new point class and update_
- adds a new point class
  * point/ vector math (p + v = p, p - p = v, etc.)
  * points can be transformed by matrices/quats
  * wraps 'place vector' type vectors that have no magnitude
- wrapped toXXX() methods work correctly
  * toXXX() will NOT wrap data (this is due to the fact that wrapped data cannot be converted)
  * added a 'wrapped' attribute to mathutils classes to determine wether the object is accessing python or blender data
- added the ability to negate vectors/points with "-vec"
  * deprecated vector.negate()
- added the ability to shorhand inverse matrices with "~mat" (tilde)
- conversion between vector/point with toXXX() methods
2005-07-23 13:46:40 +00:00
2801c8b20a __ bug fix__
- internal methods for mathutils class need to incref before returning a pointer to self
  * memory allocation errors (freeing bad pointers) were appearing after repeatedly calling internal methods on the same object due to ref counts.
2005-07-19 18:47:25 +00:00
8d2d045079 -Patch submitted by Campbell Barton
-Fixed matrix.invert() to return the correct inverse matrix
2005-07-19 14:17:07 +00:00
e60291d39c Header file clean up and warning fixes
- Mostly this cleans up the #includes and header files in the python project.
- Warning fixes are mostly casting issues and misc fixes. General warning clean up.
- #include Python.h MUST come as the first include to avoid the POSIX redefine warning in the unix makefiles
- fno-strict-aliasing flag added to makefile to fix a unavoidable type punning warning in types.c
2005-07-18 03:50:37 +00:00
b89035906d Mathutils update
- also included is some fixes for preprocessor inclues and some clean up of the previous commit

-rewrite and bugfixes
  ----------------------------------
  Here's my changelog:
  -fixed Rand() so that it doesn't seed everytime and should generate better random numbers
  - changed a few error return types to something more appropriate
  - clean up of uninitialized variables & removal of unneccessary objects
  - NMesh returns wrapped vectors now
  - World returns wrapped matrices now
  - Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
  - Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
  - Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
  - Removed memory allocation (unneeded) from all methods
  - Vector's resize methods are only applicable to new vectors not wrapped data.
  - Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
  - Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
  - Euler.rotate does internal rotation now
  - Slice assignment now works better for all types
  - Vector * Vector and Quat * Quat are defined and return the DOT product
  - Mat * Vec and Vec * Mat are defined now
  - Moved #includes to .c file from headers. Also fixed prototypes in mathutils
  - Added new helper functions for incref'ing to genutils
  - Major cleanup of header files includes - include Mathutils.h for access to math types
  - matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
  - Matrix() with no parameters now returns an identity matrix by default not a zero matrix
  - printf() now prints with 6 digits instead of 4
  - printf() now prints output with object descriptor
  - Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
  - Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence.  index cannot go above the row size of the matrix.
  - slice operations on matrices work with sequences now (rows of the matrix) example:  mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
  - slice assignment will no longer modify the data if the assignment operation fails
  - fixed error in matrix * scalar multiplication
  - euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
  - Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
  - Quats can be created with angle/axis, axis/angle
  - 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
  - vec *quat / quat * vec is now defined
  - vec.magnitude alias for vec.length
  - all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
  - these methods have been deprecated (still functioning but suggested to use the corrected functionality):
    * CopyVec() - replaced by Vector() functionality
    * CopyMat() - replaced by Matrix() functionality
    * CopyQuat() - replace by Quaternion() functionality
    * CopyEuler() - replaced by Euler() functionality
    * RotateEuler() - replaced by Euler.rotate() funtionality
    * MatMultVec() - replaced by matrix * vector
    * VecMultMat() - replaced by vector * matrix
  -  New struct containers references to python object data or internally allocated blender data for wrapping
  * Explaination here:  math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
  *    otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-07-14 03:34:56 +00:00
Stephen Swaney
ece00ff04a Roll back changes from Big Mathutils Commit on 2005/05/20. 2005-05-22 17:40:00 +00:00
Stephen Swaney
21d07f7ea3 Matrix_Determinant() was returning its input arg rather than
the determinant.  bugfix via LetterRip.
2005-05-21 20:05:28 +00:00
7586eb28a1 -rewrite and bugfixes
----------------------------------
Here's my changelog:
-fixed Rand() so that it doesn't seed everytime and should generate better random numbers
- changed a few error return types to something more appropriate
- clean up of uninitialized variables & removal of unneccessary objects
- NMesh returns wrapped vectors now
- World returns wrapped matrices now
- Object.getEuler() and Object.getBoundingBox() return Wrapped data when data is present
- Object.getMatrix() returns wrapped data if it's worldspace, 'localspace' returns a new matrix
- Vector, Euler, Mat, Quat, call all now internally wrap object without destroying internal datablocks
- Removed memory allocation (unneeded) from all methods
- Vector's resize methods are only applicable to new vectors not wrapped data.
- Matrix(), Quat(), Euler(), Vector() now accepts ANY sequence list, including tuples, list, or a self object to copy - matrices accept multiple sequences
- Fixed Slerp() so that it now works correctly values are clamped between 0 and 1
- Euler.rotate does internal rotation now
- Slice assignment now works better for all types
- Vector * Vector and Quat * Quat are defined and return the DOT product
- Mat * Vec and Vec * Mat are defined now
- Moved #includes to .c file from headers. Also fixed prototypes in mathutils
- Added new helper functions for incref'ing to genutils
- Major cleanup of header files includes - include Mathutils.h for access to math types
- matrix.toQuat() and .toEuler() now fixed take appropriate matrix sizes
- Matrix() with no parameters now returns an identity matrix by default not a zero matrix
- printf() now prints with 6 digits instead of 4
- printf() now prints output with object descriptor
- Matrices now support [x][y] assignment (e.g. matrix[x][y] = 5.4)
- Matrix[index] = value now expectes a sequence not an integer. This will now set a ROW of the matrix through a sequence.  index cannot go above the row size of the matrix.
- slice operations on matrices work with sequences now (rows of the matrix) example:  mymatrix[0:2] returns a list of 2 wrapped vectors with access to the matrix data.
- slice assignment will no longer modify the data if the assignment operation fails
- fixed error in matrix * scalar multiplication
- euler.toMatrix(), toQuat() no longer causes "creep" from repeated use
- Wrapped data will generate wrapped objects when toEuler(), toQuat(), toMatrix() is used
- Quats can be created with angle/axis, axis/angle
- 4x4 matrices can be multiplied by 3D vectors (by popular demand :))
- vec *quat / quat * vec is now defined
- vec.magnitude alias for vec.length
- all self, internal methods return a pointer to self now so you can do print vector.internalmethod() or vector.internalmethod().nextmethod() (no more print matrix.inverse() returning 'none')
- these methods have been deprecated (still functioning but suggested to use the corrected functionality):
  * CopyVec() - replaced by Vector() functionality
  * CopyMat() - replaced by Matrix() functionality
  * CopyQuat() - replace by Quaternion() functionality
  * CopyEuler() - replaced by Euler() functionality
  * RotateEuler() - replaced by Euler.rotate() funtionality
  * MatMultVec() - replaced by matrix * vector
  * VecMultMat() - replaced by vector * matrix
-  New struct containers references to python object data or internally allocated blender data for wrapping
* Explaination here:  math structs now function as a 'simple wrapper' or a 'py_object' - data that is created on the fly will now be a 'py_object' with its memory managed by python
*    otherwise if the data is returned by blender's G.main then the math object is a 'simple wrapper' and data can be accessed directly from the struct just like other python objects.
2005-05-20 19:28:04 +00:00
c78e44cdc5 big warning hunt commit
lot of casts, added prototypes, missing includes and some true errors
2005-03-09 19:45:59 +00:00
Nathan Letwory
9d579591a3 Make msvc happy by 'improving' order of declaration and removing superfluous layout issues. 2004-10-14 23:34:19 +00:00
Stephen Swaney
8edf8ff5fa bugfix: #1642 Matrix multiplication memory leak
another memory leak plugged.
2004-10-14 23:11:09 +00:00
Stephen Swaney
78a810d9af fix bad return types for errors in Matrix_coerce().
EXPP_ReturnPyObjError() should have been EXPP_ReturnIntError().
2004-10-14 19:06:44 +00:00
Stephen Swaney
7dda27fcd7 followup to vector memory leak fixes:
fix for problems with NMesh vertices.
  plug some more leaks in matrix module.
  new vector method newVectorProxy().

In BPy-Land, we have overloaded the meaning of our Vector
type.  One use is for vectors in the traditional mathmatical
sense.  The other legacy use is as a proxy for Blender data.
The recent memory leak fixed have lead to the Vector type
behaving as mathematical vectors.

However, the NMesh module is still using Vector types as a
proxy to manipulate NMVert data.  To support this usage, in
the vector module there is a new factory method
newVectorProxy().  This creates a Vector that references
memory outside the Vector.  Vectors created by
newVectorProxy() do NOT free their referenced memory.  The
newVectorProxy() is used only in bpy code and is not exposed
thru the scripting interface.

Anyone using newVectorProxy() must be aware of object
lifetime and scoping issues because the returned Vector
holds a pointer to memory it does not own.  This works in
the NMVert case since we are referencing memory belonging to
the NMVert object via an NMVert method.
2004-10-14 17:35:16 +00:00
Stephen Swaney
afbf2c25ce fix memory leak in Object.GetSelected().
bugfix: #1631 Memory Leak in newMatrixObject
  PyMem_Malloc()s not followed with PyMem_Free().
  allocation error checking contributed by Tom Musgrove.
2004-10-11 17:05:14 +00:00
Stephen Swaney
a509b8adc9 Another round in the Great BPy Cleanup:
Run everything thru indent to cleanup spaces vs tabs.
Clean up some of the comments by hand.
BGL.c was not touched due to all that macro wackyness.

There are no functional changes to the code.
Pre-indent versions of source are tagged with
tag bpy-cleanup-20040925 , just in case.
2004-09-25 20:30:40 +00:00
Stephen Swaney
a2ea84903e One small part of the Great Bpy Code Cleanup.
Add cvs $Id tag to files
2004-09-18 18:47:03 +00:00
abe8191d70 BPython:
- fixed two warnings, unused var in Object.c and undeclared function in script.c
- updated Blender.Draw doc, it was missing info about Button object
- refactored pytype initialization to try to fix for once platform (and distro!) specific crashes on startup.  This asked for tiny updates in Effect.[ch] (removed static from declaration, moved definitions to the .c file) and modules.h
- fixed error I made trying to fix scripts w/ no [eol] char in menus.  Thanks Michael Velikanje for reporting the problem!
2004-04-23 13:11:48 +00:00
127e57d983 -bug fix: matrix_item callback now returns rows from a matrix as in previous API implementation (exmple: ob.getMatrix()[0]) 2004-03-15 00:43:38 +00:00
8f3a9815ba Mathutils library for the python API
- support for quaternions, euler, vector, matrix operations.
- euler supports unique rotation calculation
- new matrix memory construction and internal functions
- quaternion slerp and diff calculation
- 2d, 3d, 4d vector construction and handling
- full conversion support between types
- update to object/window to reflect to matrix type
- update to types/blender/module to reflect new module
2004-02-29 13:20:34 +00:00
f999426daa * Object_getInverseMatrix now returns a correct matrix.
The problem was that the memory was allocated at the stack, but after the
  Python object was created, the pointer to the memory goes invalid.

  Thanks to Kester Maddoc for providing a patch - almost 2 weeks ago. Ouch,
  I should read my mail a little bit better.
2003-07-10 20:00:51 +00:00
62ffb7a5f6 * Fixed:
- Object_getMatrix()    - prints correct values now
    - Object_getName()      - removes the two identifying chars from the front
    - Object_setName()      - calls the internal function to correctly set the
                              name of the object.
* Removed the Object_print function. It causes a crash on Windows.
* Updated the Object_repr function to display the Object nicely.
* Object.Get() now returns a list of Objects when no argument has passed to
  it.
* Changed the function declaration for newMatrixObject function
  Easier to read now.
2003-07-06 19:58:27 +00:00
61e41f6817 * Added matrix module
* Moved the function EXPP_tuple_repr from vector.c to gen_utils.[ch]
* Matrix functionality should work now in Object module.
* Fixed compilation warning about implicit declaration of M_World_Init.
  Added the declaration to modules.h
2003-06-22 20:14:11 +00:00