// 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 #include #include #include #include #include #include #include #include #include "Transform.hpp" #include "held_ptr.hpp" using namespace boost::python; namespace { DEFINE_TRANSFORM_CAST(PositionAttitudeTransform) } typedef osg::PositionAttitudeTransform PATransform; class PyTransform : public PATransform { public: PyTransform() : PATransform(), _self(NULL) {} PyTransform(PyObject * p) : PATransform(), _self(p) { Py_XINCREF(_self); } ~PyTransform() { Py_XDECREF(_self); } virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const { bool ret = false; try { ret = call_method(_self, "computeLocalToWorldMatrix", ptr(&matrix), ptr(nv)); } catch(...) { handle_exception(); PyErr_Print(); return false; } return ret; } virtual bool computeLocalToWorldMatrix_imp(osg::Matrix& matrix, osg::NodeVisitor* nv) const { return PATransform::computeLocalToWorldMatrix(matrix, nv); } virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const { bool ret = false; try { ret = call_method(_self, "computeWorldToLocalMatrix", ptr(&matrix), ptr(nv)); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); } return ret; } virtual bool computeWorldToLocalMatrix_imp(osg::Matrix& matrix, osg::NodeVisitor* nv) const { return PATransform::computeWorldToLocalMatrix(matrix, nv); } inline void setPositionVec3f(const osg::Vec3f& pos) { _position = pos; dirtyBound(); } void setCustom(float x,float y, float zscale, float ang) { _position = osg::Vec3f(x,y,-zscale); _scale = osg::Vec3f(zscale,zscale,zscale); _attitude = osg::Quat(ang,osg::Vec3f(0.0f,0.0f,1.0f)); dirtyBound(); } private: PyObject * _self; }; namespace PyOSG { void init_PositionAttitudeTransform() { REGISTER_TRANSFORM_CAST(PositionAttitudeTransform) class_, bases, boost::noncopyable> transform("PositionAttitudeTransform", no_init); transform.def(init<>()); transform.def("setPosition", &PyTransform::setPosition); transform.def("setPosition", &PyTransform::setPositionVec3f); transform.def("getPosition", &PyTransform::getPosition, return_value_policy()); transform.def("setAttitude", &PyTransform::setAttitude); transform.def("setCustom",&PyTransform::setCustom); transform.def("getAttitude", &PyTransform::getAttitude, return_value_policy()); transform.def("setScale", &PyTransform::setScale); transform.def("getScale", &PyTransform::getScale, return_value_policy()); transform.def("setPivotPoint", &osg::PositionAttitudeTransform::setPivotPoint); transform.def("getPivotPoint", &osg::PositionAttitudeTransform::getPivotPoint, return_value_policy()); transform.def("computeLocalToWorldMatrix", &PyTransform::computeLocalToWorldMatrix_imp); transform.def("computeWorldToLocalMatrix", &PyTransform::computeWorldToLocalMatrix_imp); } }