From 5d14a63c372e5d9fd0700fde0b7dae7c1d75ac96 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 22 Sep 2013 08:37:58 -0700 Subject: [PATCH] Add cross product operation to Vector3 --- src/basics.cc | 13 +++++++++++++ src/basics.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/basics.cc b/src/basics.cc index 63ffd5c..8dd91d4 100644 --- a/src/basics.cc +++ b/src/basics.cc @@ -205,6 +205,19 @@ Vector3::dot(const Vector3 &v) } +/* + * Vector3::cross -- + * + * Compute and return the cross product of this and the given vectors. + */ +Vector3 +Vector3::cross(const Vector3 &v) + const +{ + return Vector3(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); +} + + /* * Vector3::normalize -- * diff --git a/src/basics.h b/src/basics.h index 2ec9a27..ab6b16a 100644 --- a/src/basics.h +++ b/src/basics.h @@ -34,6 +34,7 @@ struct Vector3 float length2() const; float length() const; float dot(const Vector3 &v) const; + Vector3 cross(const Vector3 &v) const; Vector3 &normalize();