// Copyright (C) 2002-2003 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #include #include #include #include #include #ifdef __USE_OSX_IMPLEMENTATION__ #include "missing.hpp" #undef check #endif #include using namespace boost::python; using namespace Producer; namespace { void __setitem__(Vec3 * self, int idx, float val) { (*self)[idx] = val; } const Vec3 crossProduct(Vec3 * self, Vec3 * other) { return (*self) ^ (*other); } } // namespace namespace PyProd { void init_Math() { class_ vec3("Vec3"); vec3 .def(init()) .def("set", &Vec3::set) .def("x", (float (Vec3::*)() const) &Vec3::x) .def("y", (float (Vec3::*)() const) &Vec3::y) .def("z", (float (Vec3::*)() const) &Vec3::z) // operator[] get and set methods .def("__getitem__", (float (Vec3::*)(int) const) &Vec3::operator[]) .def("__setitem__", &__setitem__) .def("crossProduct", &crossProduct) .def(self - self) .def(-self) .def("length", &Vec3::length) .def("normalize", &Vec3::normalize) .def(self * float()) .def(self *= float()) ; class_ matrix("Matrix"); matrix .def("makeIdentity", &Matrix::makeIdentity) .def("makeLookAt", &Matrix::makeLookAt) .def("makeTranslate", &Matrix::makeTranslate) .def("makeRotate", &Matrix::makeRotate) .def("makeScale", &Matrix::makeScale) .def("invert", &Matrix::invert) .def(self * self) .def(self *= self) .def("translate", (Matrix (*)(const Vec3&)) &Matrix::translate) .def("translate", (Matrix (*)(Matrix::value_type, Matrix::value_type, Matrix::value_type)) &Matrix::translate) .def("rotate", (Matrix (*)(Matrix::value_type, Matrix::value_type, Matrix::value_type, Matrix::value_type)) &Matrix::rotate) .def("rotate", (Matrix (*)(Matrix::value_type, const Vec3&)) &Matrix::rotate) .def("scale", &Matrix::scale) .staticmethod("translate") .staticmethod("rotate") .staticmethod("scale") ; } }