Skip to content
Snippets Groups Projects
Commit cc33bc33 authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

added radius multiplier to gfx.CPK rendering

parent c1f4931b
Branches
Tags
No related merge requests found
...@@ -91,6 +91,7 @@ void export_RenderOptions() ...@@ -91,6 +91,7 @@ void export_RenderOptions()
.def("GetCPKMode", &CPKRenderOptions::GetSphereMode) .def("GetCPKMode", &CPKRenderOptions::GetSphereMode)
.add_property("cpk_mode", &CPKRenderOptions::GetSphereMode, .add_property("cpk_mode", &CPKRenderOptions::GetSphereMode,
&CPKRenderOptions::SetSphereMode) &CPKRenderOptions::SetSphereMode)
.add_property("radius_mult",&CPKRenderOptions::GetRadiusMult,&CPKRenderOptions::SetRadiusMult)
; ;
class_<CustomRenderOptions, boost::shared_ptr<CustomRenderOptions>, bases<RenderOptions>, boost::noncopyable>("CustomRenderOptions") class_<CustomRenderOptions, boost::shared_ptr<CustomRenderOptions>, bases<RenderOptions>, boost::noncopyable>("CustomRenderOptions")
... ...
......
...@@ -49,21 +49,26 @@ void CPKRenderer::PrepareRendering() ...@@ -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(); const Color& sel_clr=this->GetSelectionColor();
float factor=is_sel ? 1.2 : 1.0; float factor=is_sel ? 1.2 : 1.0;
if(options_!=NULL){ if(options_!=NULL){
factor *= options_->GetRadiusMult();
if(factor>0.0) {
va.SetLighting(true); va.SetLighting(true);
va.SetCullFace(true); va.SetCullFace(true);
va.SetColorMaterial(true); va.SetColorMaterial(true);
va.SetMode(0x4); va.SetMode(0x4);
// draw all spheres // draw all spheres
uint det=options_->GetSphereDetail();
for(AtomEntryMap::const_iterator it=view.atom_map.begin();it!=view.atom_map.end();++it) { for(AtomEntryMap::const_iterator it=view.atom_map.begin();it!=view.atom_map.end();++it) {
va.AddSphere(SpherePrim(it->second.atom.GetPos(), va.AddSphere(SpherePrim(it->second.atom.GetPos(),
it->second.vdwr*factor, it->second.vdwr*factor,
is_sel? sel_clr : it->second.color), is_sel? sel_clr : it->second.color),
options_->GetSphereDetail()); det);
}
} }
} }
sel_state_=0; sel_state_=0;
...@@ -115,10 +120,11 @@ namespace { ...@@ -115,10 +120,11 @@ namespace {
void Render3DSpritesInnerLoop(const AtomEntry* ae, const geom::Vec3& cx, void Render3DSpritesInnerLoop(const AtomEntry* ae, const geom::Vec3& cx,
const geom::Vec3& cy, const geom::Vec3& cz, const geom::Vec3& cy, const geom::Vec3& cz,
GLdouble* gl_mmat, GLdouble* gl_pmat, GLint* gl_vp) GLdouble* gl_mmat, GLdouble* gl_pmat, GLint* gl_vp,
float rmul)
{ {
geom::Vec3 pos = ae->atom.GetPos(); geom::Vec3 pos = ae->atom.GetPos();
float rad = ae->vdwr; float rad = rmul*ae->vdwr;
GLdouble r1[3],r2[3]; GLdouble r1[3],r2[3];
gluProject(pos[0],pos[1],pos[2], gluProject(pos[0],pos[1],pos[2],
gl_mmat,gl_pmat,gl_vp, gl_mmat,gl_pmat,gl_vp,
...@@ -144,6 +150,9 @@ void CPKRenderer::Render3DSprites() ...@@ -144,6 +150,9 @@ void CPKRenderer::Render3DSprites()
{ {
#if OST_SHADER_SUPPORT_ENABLED #if OST_SHADER_SUPPORT_ENABLED
if(options_!=NULL){ if(options_!=NULL){
float rmul= options_->GetRadiusMult();
if(rmul==0.0) return;
geom::Mat3 irot=geom::Transpose(Scene::Instance().GetTransform().GetRot()); geom::Mat3 irot=geom::Transpose(Scene::Instance().GetTransform().GetRot());
geom::Vec3 cx=irot*geom::Vec3(1.0,0.0,0.0); geom::Vec3 cx=irot*geom::Vec3(1.0,0.0,0.0);
geom::Vec3 cy=irot*geom::Vec3(0.0,1.0,0.0); geom::Vec3 cy=irot*geom::Vec3(0.0,1.0,0.0);
...@@ -170,10 +179,10 @@ void CPKRenderer::Render3DSprites() ...@@ -170,10 +179,10 @@ void CPKRenderer::Render3DSprites()
glBegin(GL_QUADS); glBegin(GL_QUADS);
for(AtomEntryMap::const_iterator it=view_.atom_map.begin();it!=view_.atom_map.end();++it) { 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(); glEnd();
glPopAttrib(); glPopAttrib();
Shader::Instance().PopProgram(); Shader::Instance().PopProgram();
... ...
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
namespace ost { namespace gfx { 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 #if OST_SHADER_SUPPORT_ENABLED
cpk_mode_=1; cpk_mode_=1;
#else #else
...@@ -70,4 +70,15 @@ uint CPKRenderOptions::GetSphereMode(){ ...@@ -70,4 +70,15 @@ uint CPKRenderOptions::GetSphereMode(){
return cpk_mode_; 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 }} // ns
...@@ -42,14 +42,21 @@ public: ...@@ -42,14 +42,21 @@ public:
virtual void ApplyRenderOptions(RenderOptionsPtr render_options); virtual void ApplyRenderOptions(RenderOptionsPtr render_options);
// own interface // own interface
/// number of arc subdivisions per pi/2
void SetSphereDetail(uint detail); void SetSphereDetail(uint detail);
uint GetSphereDetail(); uint GetSphereDetail();
/// 0 = triangulated spheres, 1 = fast 3D sprites (default)
void SetSphereMode(uint mode); void SetSphereMode(uint mode);
uint GetSphereMode(); uint GetSphereMode();
/// Radius multiplier, default=1.0
void SetRadiusMult(float m);
float GetRadiusMult() const;
private: private:
uint sphere_detail_; uint sphere_detail_;
uint cpk_mode_; uint cpk_mode_;
float rad_mult_;
}; };
typedef boost::shared_ptr<CPKRenderOptions> CPKRenderOptionsPtr; typedef boost::shared_ptr<CPKRenderOptions> CPKRenderOptionsPtr;
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment