demos/vector.py
author Radek Brich <radek.brich@devl.cz>
Sat, 10 May 2008 14:29:37 +0200
branchpyrit
changeset 95 ca7d4c665531
parent 72 7c3f38dff082
permissions -rw-r--r--
build script fixes, add ldflags build option update and enhance demos fix bug in 4x grid oversampling warn if writePNG called while compiled without libpng make shapes in ShapeList const and add many other const needed due to snowball effect slightly optimize Camera::makeRayPacket using _mm_shuffle_ps make Vector SIMD vectorization disabled by default (causes problems) fix bug in implicit reflection of transmissive surfaces, when surface's reflection parameter is set to zero

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]