From cc33bc333859c85ffa2c8f53cd93b974ff4af9de Mon Sep 17 00:00:00 2001 From: Ansgar Philippsen <ansgar.philippsen@gmail.com> Date: Wed, 20 Jul 2011 20:40:01 -0400 Subject: [PATCH] added radius multiplier to gfx.CPK rendering --- modules/gfx/pymod/export_render_options.cc | 1 + modules/gfx/src/impl/cpk_renderer.cc | 45 +++++++++++-------- .../src/render_options/cpk_render_options.cc | 13 +++++- .../src/render_options/cpk_render_options.hh | 7 +++ 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/modules/gfx/pymod/export_render_options.cc b/modules/gfx/pymod/export_render_options.cc index 2d5d21e23..4f1de36c4 100644 --- a/modules/gfx/pymod/export_render_options.cc +++ b/modules/gfx/pymod/export_render_options.cc @@ -91,6 +91,7 @@ void export_RenderOptions() .def("GetCPKMode", &CPKRenderOptions::GetSphereMode) .add_property("cpk_mode", &CPKRenderOptions::GetSphereMode, &CPKRenderOptions::SetSphereMode) + .add_property("radius_mult",&CPKRenderOptions::GetRadiusMult,&CPKRenderOptions::SetRadiusMult) ; class_<CustomRenderOptions, boost::shared_ptr<CustomRenderOptions>, bases<RenderOptions>, boost::noncopyable>("CustomRenderOptions") diff --git a/modules/gfx/src/impl/cpk_renderer.cc b/modules/gfx/src/impl/cpk_renderer.cc index f7b0df84c..a0d286047 100644 --- a/modules/gfx/src/impl/cpk_renderer.cc +++ b/modules/gfx/src/impl/cpk_renderer.cc @@ -49,21 +49,26 @@ void CPKRenderer::PrepareRendering() } } -void CPKRenderer::PrepareRendering(GfxView& view, IndexedVertexArray& va, bool is_sel){ +void CPKRenderer::PrepareRendering(GfxView& view, IndexedVertexArray& va, bool is_sel) +{ const Color& sel_clr=this->GetSelectionColor(); float factor=is_sel ? 1.2 : 1.0; if(options_!=NULL){ - va.SetLighting(true); - va.SetCullFace(true); - va.SetColorMaterial(true); - va.SetMode(0x4); - - // draw all spheres - for(AtomEntryMap::const_iterator it=view.atom_map.begin();it!=view.atom_map.end();++it) { - va.AddSphere(SpherePrim(it->second.atom.GetPos(), - it->second.vdwr*factor, - is_sel? sel_clr : it->second.color), - options_->GetSphereDetail()); + factor *= options_->GetRadiusMult(); + if(factor>0.0) { + va.SetLighting(true); + va.SetCullFace(true); + va.SetColorMaterial(true); + va.SetMode(0x4); + + // draw all spheres + uint det=options_->GetSphereDetail(); + for(AtomEntryMap::const_iterator it=view.atom_map.begin();it!=view.atom_map.end();++it) { + va.AddSphere(SpherePrim(it->second.atom.GetPos(), + it->second.vdwr*factor, + is_sel? sel_clr : it->second.color), + det); + } } } sel_state_=0; @@ -114,11 +119,12 @@ RenderOptionsPtr CPKRenderer::GetOptions(){ namespace { void Render3DSpritesInnerLoop(const AtomEntry* ae, const geom::Vec3& cx, - const geom::Vec3& cy, const geom::Vec3& cz, - GLdouble* gl_mmat, GLdouble* gl_pmat, GLint* gl_vp) + const geom::Vec3& cy, const geom::Vec3& cz, + GLdouble* gl_mmat, GLdouble* gl_pmat, GLint* gl_vp, + float rmul) { geom::Vec3 pos = ae->atom.GetPos(); - float rad = ae->vdwr; + float rad = rmul*ae->vdwr; GLdouble r1[3],r2[3]; gluProject(pos[0],pos[1],pos[2], gl_mmat,gl_pmat,gl_vp, @@ -144,6 +150,9 @@ void CPKRenderer::Render3DSprites() { #if OST_SHADER_SUPPORT_ENABLED if(options_!=NULL){ + float rmul= options_->GetRadiusMult(); + if(rmul==0.0) return; + geom::Mat3 irot=geom::Transpose(Scene::Instance().GetTransform().GetRot()); geom::Vec3 cx=irot*geom::Vec3(1.0,0.0,0.0); geom::Vec3 cy=irot*geom::Vec3(0.0,1.0,0.0); @@ -168,12 +177,12 @@ void CPKRenderer::Render3DSprites() GLint gl_vp[]={0,0,1,1}; glBegin(GL_QUADS); - + for(AtomEntryMap::const_iterator it=view_.atom_map.begin();it!=view_.atom_map.end();++it) { - Render3DSpritesInnerLoop(&it->second,cx,cy,cz,gl_mmat,gl_pmat,gl_vp); + Render3DSpritesInnerLoop(&it->second,cx,cy,cz,gl_mmat,gl_pmat,gl_vp,rmul); } - glEnd(); + glPopAttrib(); Shader::Instance().PopProgram(); diff --git a/modules/gfx/src/render_options/cpk_render_options.cc b/modules/gfx/src/render_options/cpk_render_options.cc index add931551..93f0206e5 100644 --- a/modules/gfx/src/render_options/cpk_render_options.cc +++ b/modules/gfx/src/render_options/cpk_render_options.cc @@ -24,7 +24,7 @@ namespace ost { namespace gfx { -CPKRenderOptions::CPKRenderOptions(): sphere_detail_(4) { + CPKRenderOptions::CPKRenderOptions(): sphere_detail_(4),cpk_mode_(0),rad_mult_(1.0) { #if OST_SHADER_SUPPORT_ENABLED cpk_mode_=1; #else @@ -70,4 +70,15 @@ uint CPKRenderOptions::GetSphereMode(){ return cpk_mode_; } +void CPKRenderOptions::SetRadiusMult(float m) +{ + rad_mult_=std::max(0.0f,m); + this->NotifyStateChange(); +} + +float CPKRenderOptions::GetRadiusMult() const +{ + return rad_mult_; +} + }} // ns diff --git a/modules/gfx/src/render_options/cpk_render_options.hh b/modules/gfx/src/render_options/cpk_render_options.hh index 98845a536..abc469cc1 100644 --- a/modules/gfx/src/render_options/cpk_render_options.hh +++ b/modules/gfx/src/render_options/cpk_render_options.hh @@ -42,14 +42,21 @@ public: virtual void ApplyRenderOptions(RenderOptionsPtr render_options); // own interface + /// number of arc subdivisions per pi/2 void SetSphereDetail(uint detail); uint GetSphereDetail(); + /// 0 = triangulated spheres, 1 = fast 3D sprites (default) void SetSphereMode(uint mode); uint GetSphereMode(); + /// Radius multiplier, default=1.0 + void SetRadiusMult(float m); + float GetRadiusMult() const; + private: uint sphere_detail_; uint cpk_mode_; + float rad_mult_; }; typedef boost::shared_ptr<CPKRenderOptions> CPKRenderOptionsPtr; -- GitLab