From c65538b0e1ac6630c41f4784c327ba18d1ac447b Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 16 Sep 2002 18:07:10 +0000 Subject: [PATCH] LOD::set_stress_factor --- panda/src/gobj/LOD.cxx | 40 +++++++++++++++++++++++++--------- panda/src/gobj/LOD.h | 40 ++++++++++++---------------------- panda/src/gobj/config_gobj.cxx | 4 ++-- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/panda/src/gobj/LOD.cxx b/panda/src/gobj/LOD.cxx index c8dfb127c6..0c0e563857 100644 --- a/panda/src/gobj/LOD.cxx +++ b/panda/src/gobj/LOD.cxx @@ -17,22 +17,19 @@ //////////////////////////////////////////////////////////////////// #include "LOD.h" -#include -#include -#include +#include "datagram.h" +#include "datagramIterator.h" +#include "indent.h" +#include "config_gobj.h" #define EXPCL EXPCL_PANDA #define EXPTP EXPTP_PANDA #define TYPE LODSwitch #define NAME LODSwitchVector -#include -#include "config_gobj.h" +#include "vector_src.cxx" -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle LOD::_type_handle; +float LOD::_stress_factor = lod_stress_factor; //////////////////////////////////////////////////////////////////// // Function: LOD::constructor @@ -97,7 +94,7 @@ int LOD:: compute_child(const LPoint3f &cam_pos, const LPoint3f ¢er) const { LVector3f v = cam_pos - center; - float dist = dot(v, v); + float dist = dot(v, v) * _stress_factor; LODSwitchVector::const_iterator i; int child = 0; for (i = _switch_vector.begin(), child = 0; @@ -206,3 +203,26 @@ write(ostream &out, int indent_level) const { } } +//////////////////////////////////////////////////////////////////// +// Function: LOD::set_stress_factor +// Access: Published, Static +// Description: Sets the factor that globally scales all LOD's. This +// factor is applied to the square of the LOD distance, +// so the larger the number, the lower the detail that +// is presented. The normal value is 1.0. +//////////////////////////////////////////////////////////////////// +void LOD:: +set_stress_factor(float stress_factor) { + _stress_factor = stress_factor; +} + +//////////////////////////////////////////////////////////////////// +// Function: LOD::get_stress_factor +// Access: Published, Static +// Description: Returns the factor that globally scales all LOD's. +// See get_stress_factor(). +//////////////////////////////////////////////////////////////////// +float LOD:: +get_stress_factor() { + return _stress_factor; +} diff --git a/panda/src/gobj/LOD.h b/panda/src/gobj/LOD.h index a6546624ed..7b92c1a4e6 100644 --- a/panda/src/gobj/LOD.h +++ b/panda/src/gobj/LOD.h @@ -15,16 +15,14 @@ // panda3d@yahoogroups.com . // //////////////////////////////////////////////////////////////////// + #ifndef LOD_H #define LOD_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include -#include -#include +#include "pandabase.h" + +#include "luse.h" +#include "typedReferenceCount.h" class Datagram; class DatagramIterator; @@ -82,11 +80,11 @@ protected: // Description : Computes whether a level-of-detail should be rendered // or not based on distance from the rendering camera. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA LOD : public TypedReferenceCount { +class EXPCL_PANDA LOD { public: - LOD(void); + LOD(); LOD(const LOD ©); - ~LOD(void); + ~LOD(); void xform(const LMatrix4f &mat); @@ -99,26 +97,16 @@ public: void output(ostream &out) const; void write(ostream &out, int indent_level = 0) const; -public: - LPoint3f _center; - LODSwitchVector _switch_vector; +PUBLISHED: + static void set_stress_factor(float stress_factor); + static float get_stress_factor(); public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "LOD", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + LPoint3f _center; + LODSwitchVector _switch_vector; private: - static TypeHandle _type_handle; + static float _stress_factor; }; INLINE ostream &operator << (ostream &out, const LOD &lod) { diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index 0a2222fbb7..e9e194caf5 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -17,7 +17,6 @@ //////////////////////////////////////////////////////////////////// #include -#include "LOD.h" #include "boundedObject.h" #include "config_gobj.h" #include "drawable.h" @@ -118,6 +117,8 @@ const int select_LOD_number = config_gobj.GetInt("select-LOD-number", -1); // will screen out successively higher levels const int minimum_LOD_number = config_gobj.GetInt("minimum-LOD-number", 0); +const float lod_stress_factor = config_gobj.GetFloat("lod-stress-factor", 1.0f); + // The default near and far plane distances. const float default_near = config_gobj.GetFloat("default-near", 1.0f); const float default_far = config_gobj.GetFloat("default-far", 1000.0f); @@ -181,7 +182,6 @@ ConfigureFn(config_gobj) { GeomTrifan::init_type(); GeomTristrip::init_type(); ImageBuffer::init_type(); - LOD::init_type(); Material::init_type(); OrthographicLens::init_type(); MatrixLens::init_type();