diff --git a/modules/gfx/pymod/export_scene.cc b/modules/gfx/pymod/export_scene.cc index adaa52e479b97355f5d4adb0c2a6aa269302ff54..b9313b2d6d997ed0f64e40718e41f243862953b3 100644 --- a/modules/gfx/pymod/export_scene.cc +++ b/modules/gfx/pymod/export_scene.cc @@ -126,6 +126,10 @@ void export_Scene() .add_property("bg", &Scene::GetBackground, &Scene::SetBackground) + .def("GetProjection",&Scene::GetProjection) + .add_property("projection",&Scene::GetProjection) + .def("GetInvertedProjection",&Scene::GetInvertedProjection) + .add_property("inverted_projection",&Scene::GetInvertedProjection) .def("SetNear",&Scene::SetNear) .def("GetNear",&Scene::GetNear) .add_property("near", &Scene::GetNear, &Scene::SetNear) diff --git a/modules/gfx/src/scene.cc b/modules/gfx/src/scene.cc index 708d8688cbf43435ed995ce0d1963c9a31d07768..71aba002cb8ac81e7ba9a419be3042d779000c7a 100644 --- a/modules/gfx/src/scene.cc +++ b/modules/gfx/src/scene.cc @@ -2016,6 +2016,12 @@ void Scene::stereo_projection(int view) // standard viewing frustum glFrustum(left,right,bot,top,zn,zf); } + + // TODO: generate both directly from near/far/fov + float pm[16]; + glGetFloatv(GL_PROJECTION_MATRIX,pm); + pmat_=geom::Transpose(geom::Mat4(pm)); + ipmat_=geom::Invert(pmat_); } void Scene::render_stereo() diff --git a/modules/gfx/src/scene.hh b/modules/gfx/src/scene.hh index 6912bfbfffb4d26ac9c8974ddee8a63b8756a6d8..f127ee28fddcf37df4759542c67fea038ae2386e 100644 --- a/modules/gfx/src/scene.hh +++ b/modules/gfx/src/scene.hh @@ -142,6 +142,9 @@ class DLLEXPORT_OST_GFX Scene { /// one of fallback, basic, default, hf, toon1, toon2 void SetShadingMode(const std::string& smode); + geom::Mat4 GetProjection() const {return pmat_;} + geom::Mat4 GetInvertedProjection() const {return ipmat_;} + /// \name clipping planes, fog and field-of-view //@{ /// \brief get near clipping plane @@ -514,6 +517,7 @@ private: float znear_,zfar_; // near and far clipping plane float fnear_,ffar_; // fog near and far offsets + geom::Mat4 pmat_,ipmat_; // projection and inverted projection matrix unsigned int vp_width_,vp_height_; // viewport SceneViewStack scene_view_stack_; diff --git a/modules/mol/base/pymod/CMakeLists.txt b/modules/mol/base/pymod/CMakeLists.txt index 3f514b2b8afba9e8f95473898b9649da2b3afcb7..6e158771aa0c9e3b2608203469f9b3afc65e5708 100644 --- a/modules/mol/base/pymod/CMakeLists.txt +++ b/modules/mol/base/pymod/CMakeLists.txt @@ -18,6 +18,7 @@ export_bounding_box.cc export_query_view_wrapper.cc export_torsion.cc export_visitor.cc +export_transform.cc wrap_mol.cc export_entity_property_mapper.cc ) diff --git a/modules/mol/base/pymod/export_transform.cc b/modules/mol/base/pymod/export_transform.cc new file mode 100644 index 0000000000000000000000000000000000000000..1dc8bdc16bb6df0ba9f55693ebd0866da449400e --- /dev/null +++ b/modules/mol/base/pymod/export_transform.cc @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#include <boost/python.hpp> + +#include <ost/mol/transform.hh> +#if(OST_INFO_ENABLED) +#include <ost/info/info.hh> +#endif + +using namespace boost::python; +using namespace ost; +using namespace ost::mol; + +void export_Transform() +{ + class_<Transform>("Transform", init<>()) + .def(init<const Transform&>()) // shouldn't this be there automatically ? + .def("GetMatrix",&Transform::GetMatrix) + .def("SetMatrix",&Transform::SetMatrix) + .add_property("matrix",&Transform::GetMatrix,&Transform::SetMatrix) + .def("GetTransposedMatrix",&Transform::GetTransposedMatrix) + .add_property("tmatrix",&Transform::GetTransposedMatrix) + .add_property("transposed_matrix",&Transform::GetTransposedMatrix) + .def("GetInvertedMatrix",&Transform::GetInvertedMatrix) + .add_property("inverted_matrix",&Transform::GetInvertedMatrix) + .def("SetTrans",&Transform::SetTrans) + .def("GetTrans",&Transform::GetTrans) + .add_property("trans",&Transform::GetTrans,&Transform::SetTrans) + .def("SetCenter",&Transform::SetCenter) + .def("GetCenter",&Transform::GetCenter) + .add_property("center",&Transform::GetCenter,&Transform::SetCenter) + .def("SetRot",&Transform::SetRot) + .def("GetRot",&Transform::GetRot) + .add_property("rot",&Transform::GetRot,&Transform::SetRot) + .def("ApplyXAxisRotation",&Transform::ApplyXAxisRotation) + .def("ApplyYAxisRotation",&Transform::ApplyYAxisRotation) + .def("ApplyZAxisRotation",&Transform::ApplyZAxisRotation) + .def("ApplyXAxisTranslation",&Transform::ApplyXAxisTranslation) + .def("ApplyYAxisTranslation",&Transform::ApplyYAxisTranslation) + .def("ApplyZAxisTranslation",&Transform::ApplyZAxisTranslation) + .def("ApplyAxisRotation",&Transform::ApplyAxisRotation) + ; +#if(OST_INFO_ENABLED) + def("TransformToInfo", &TransformToInfo); + def("TransformFromInfo", &TransformFromInfo); +#endif +} diff --git a/modules/mol/base/pymod/wrap_mol.cc b/modules/mol/base/pymod/wrap_mol.cc index 33b09e2f20b4c1126f05cf501c04a599663048f9..31cf8165b463460f346fc6d1ec820ceb317edb65 100644 --- a/modules/mol/base/pymod/wrap_mol.cc +++ b/modules/mol/base/pymod/wrap_mol.cc @@ -17,11 +17,7 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ #include <boost/python.hpp> -#include <ost/mol/transform.hh> #include <ost/mol/editor_base.hh> -#if(OST_INFO_ENABLED) -#include <ost/info/info.hh> -#endif using namespace boost::python; using namespace ost::mol; @@ -46,6 +42,8 @@ void export_PropertyID(); void export_BoundingBox(); void export_QueryViewWrapper(); void export_EntityPropertyMapper(); +void export_Transform(); + BOOST_PYTHON_MODULE(_ost_mol) { enum_<EditMode>("EditMode") @@ -73,33 +71,5 @@ BOOST_PYTHON_MODULE(_ost_mol) export_BoundingBox(); export_QueryViewWrapper(); export_EntityPropertyMapper(); - class_<Transform>("Transform", init<>()) - .def(init<const Transform&>()) // shouldn't this be there automatically ? - .def("GetMatrix",&Transform::GetMatrix) - .def("SetMatrix",&Transform::SetMatrix) - .add_property("matrix",&Transform::GetMatrix,&Transform::SetMatrix) - .def("GetTransposedMatrix",&Transform::GetTransposedMatrix) - .add_property("tmatrix",&Transform::GetTransposedMatrix) - .def("SetTrans",&Transform::SetTrans) - .def("GetTrans",&Transform::GetTrans) - .add_property("trans",&Transform::GetTrans,&Transform::SetTrans) - .def("SetCenter",&Transform::SetCenter) - .def("GetCenter",&Transform::GetCenter) - .add_property("center",&Transform::GetCenter,&Transform::SetCenter) - .def("SetRot",&Transform::SetRot) - .def("GetRot",&Transform::GetRot) - .add_property("rot",&Transform::GetRot,&Transform::SetRot) - .def("ApplyXAxisRotation",&Transform::ApplyXAxisRotation) - .def("ApplyYAxisRotation",&Transform::ApplyYAxisRotation) - .def("ApplyZAxisRotation",&Transform::ApplyZAxisRotation) - .def("ApplyXAxisTranslation",&Transform::ApplyXAxisTranslation) - .def("ApplyYAxisTranslation",&Transform::ApplyYAxisTranslation) - .def("ApplyZAxisTranslation",&Transform::ApplyZAxisTranslation) - .def("ApplyAxisRotation",&Transform::ApplyAxisRotation) - ; -#if(OST_INFO_ENABLED) - def("TransformToInfo", &TransformToInfo); - def("TransformFromInfo", &TransformFromInfo); -#endif - + export_Transform(); } diff --git a/modules/mol/base/src/transform.cc b/modules/mol/base/src/transform.cc index 9202ed0b3971110a1f6298f70a9c1f30f46ea6f6..560216cc2045f4917431f46ca3d9377a344b666d 100644 --- a/modules/mol/base/src/transform.cc +++ b/modules/mol/base/src/transform.cc @@ -40,11 +40,6 @@ Transform::Transform(): update_tm(); } -Mat4 Transform::GetMatrix() const -{ - return tm_; -} - void Transform::SetMatrix(const Mat4& m) { tm_=m; @@ -52,11 +47,6 @@ void Transform::SetMatrix(const Mat4& m) update_components(); } -Mat4 Transform::GetTransposedMatrix() const -{ - return ttm_; -} - void Transform::SetTrans(const Vec3& t) { trans_=t; @@ -212,6 +202,8 @@ void Transform::update_tm() 0.0,0.0,1.0,-cen_[2], 0.0,0.0,0.0,1.0); ttm_ = Transpose(tm_); + // TODO: calculate from rot, cen and trans + itm_ = Invert(tm_); } void Transform::update_components() diff --git a/modules/mol/base/src/transform.hh b/modules/mol/base/src/transform.hh index 20ef4820efca693a968d29ce420f46823b8454fe..f9c59f6f5095256795b90e105d8067f20f1e6772 100644 --- a/modules/mol/base/src/transform.hh +++ b/modules/mol/base/src/transform.hh @@ -38,8 +38,9 @@ class DLLEXPORT_OST_MOL Transform { public: Transform(); - geom::Mat4 GetMatrix() const; - geom::Mat4 GetTransposedMatrix() const; + geom::Mat4 GetMatrix() const {return tm_;} + geom::Mat4 GetTransposedMatrix() const {return ttm_;} + geom::Mat4 GetInvertedMatrix() const {return itm_;} void SetCenter(const geom::Vec3& c); geom::Vec3 GetCenter() const; @@ -81,6 +82,7 @@ private: geom::Vec3 cen_; geom::Mat4 tm_; geom::Mat4 ttm_; + geom::Mat4 itm_; void update_tm(); void update_components();