demos/vector.py
author Radek Brich <radek.brich@devl.cz>
Fri, 02 May 2008 13:27:47 +0200
branchpyrit
changeset 91 9d66d323c354
parent 72 7c3f38dff082
permissions -rw-r--r--
packetize Phong shader new scons config options: simd=(yes|no) - allow/suppress explicit SSE force_flags=(yes|no) - force use of specified flags instead of autodetected profile=(yes|no) - enable gcc's profiling (-pg option) check for pthread.h header, don't try to build without it add fourth Vector3 component for better memory aligning rename Vector3 to Vector partialy SSE-ize Vector class (only fully vertical operations) build static lib and python module in distinctive directories to avoid collision of library file names on some platforms

from math import *

def dot(a,b):
	sum = 0
	for i in range(min(len(a),len(b))):
		sum += a[i]*b[i]
	return sum

def cross(a,b):
	return (
		a[1]*b[2] - a[2]*b[1],
		a[2]*b[0] - a[0]*b[2],
		a[0]*b[1] - a[1]*b[0]
	)

def unit(a):
	m = mag(a)
	return (a[0]/m, a[1]/m, a[2]/m)

def mag(a):
	return sqrt(mag2(a))

def mag2(a):
	return a[0]*a[0] + a[1]*a[1] + a[2]*a[2]