Game Objects 3D math
I've just uploaded a new version of Game Objects. The 3D maths classes (Vector2, Vector3 and Matrix44) are reasonably stable now. I'd like to invite Python coders to play around with them, and suggest any improvements. My intention was to make something that was very easy to use, but well optimized. Game Objects is public domain. Do what you want with the code - go crazy!
There is no documentation at the moment I'm afraid, but here are a few edited highlights.
Vector3 class
>>> from gameobjects.vector3 import * >>> A = (-5, 2, -6 ) >>> B = (10, 2, 8) >>> AB = Vector3.from_points(A, B) >>> print AB (15, 0, 14) >>> AB.length 20.518284528683193 >>> AB.length = 1 >>> print AB (0.731055, 0, 0.682318) >>> AB *= 2 >>> print AB (1.462111, 0, 1.364637) >>> AB += (1, 2, 3) >>> print AB (2.462111, 2, 4.364637)
Matrix44 Class
>>> from gameobjects.matrix44 import * >>> identity = Matrix44() >>> print identity [ 1 0 0 0 ] [ 0 1 0 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ] >>> scale = Matrix44.scale(2.) >>> print scale [ 2 0 0 0 ] [ 0 2 0 0 ] [ 0 0 2 0 ] [ 0 0 0 1 ] >>> scale.transform( (1, 2, 3) ) (2.0, 4.0, 6.0) >>> from math import radians >>> rotate = Matrix44.x_rotation(radians(45)) >>> print rotate [ 1 0 0 0 ] [ 0 0.707107 0.707107 0 ] [ 0 -0.707107 0.707107 0 ] [ 0 0 0 1 ] >>> p = (5, 10, 0) >>> rotated_p = rotate.transform(p) >>> print rotated_p (5.0, 7.0710678118654755, 7.0710678118654746) >>> inverse_rotate = rotate.get_inverse() >>> inverse_rotate.transform(rotated_p) (5.0, 10.0, 0.0) >>> rotation.right Traceback (most recent call last): File "<interactive>", line 1, in ? NameError: name 'rotation' is not defined >>> rotate.right (1.0, 0.0, 0.0, 0.0) >>> rotate.translate (0.0, 0.0, 0.0, 1.0) >>> rotate.translate = (10, 2, 5) >>> print rotate [ 1 0 0 0 ] [ 0 0.707107 0.707107 0 ] [ 0 -0.707107 0.707107 0 ] [ 10 2 5 1 ] </interactive>
I am a noob so forgive my ignorance - I need to install the vector2 module for python for a project I am doing (I currently get the ‘No module named gameobjects.vector2’ message when running a script.)
Could you tell me how I download and install this? I am running Python IDLE 2.7
cheers
Ollie
your suggestion will be very helpful for me.
thanks