The Vish Visualization Shell 0.3
Vish
Public Member Functions | Static Public Member Functions | List of all members
Wizt::FloatOrigin Struct Referenceabstract

By default, the Camera in Vish is NOT translated to the location of the specified observer, but it resides at location (0,0,0). More...

#include <ocean/Anemonia/FloatOrigin.hpp>

Inheritance diagram for Wizt::FloatOrigin:
Wizt::VStateCreatorBase Wizt::BaseCursor3D

Public Member Functions

RefPtr< Chunk< Eagle::point3 > > computeShiftedCoordinates (const RefPtr< Chunk< Eagle::point3 > > &RawCoordinates, const Eagle::tvector3 &TranslationVector) const
 Given raw coordinates that are shifted far from the origin, compute shifted coordinated according to the given TranslationVector that has been provided by getCoordinateTranslation().
 
VRenderContext::ModelViewState getCoordinateTranslation (const VRenderContext &Context, Eagle::tvector3 &TranslationVector) const
 
VRenderContext::ModelViewState getCoordinateTranslation (const VRenderContext &Context, Intercube &IC, Eagle::tvector3 &TranslationVector) const
 Get the coordinate translaton as cached at a given Intercube.
 
- Public Member Functions inherited from Wizt::VStateCreatorBase
RefPtr< State > & getState (const WeakPtr< ValuePool > &VP) const
 Retrieve a pointer to a state object for the given context.
 
RefPtr< InterfaceBasehasLocalInterface (const type_info &InterfaceType) const
 Check whether any of the local object states has an interface of the given type.
 
RefPtr< StatemyState (const WeakPtr< ValuePool > &Context) const
 Retrieve a state for the current context, possibly creating one.
 
virtual RefPtr< StatenewState () const
 create a new state object. Child classes might deliver child states.
 
void setState (const WeakPtr< ValuePool > &, const RefPtr< State > &st) const
 Set a state object for a given context.
 

Static Public Member Functions

static VRenderContext::ModelViewState getTranslationVector (const VRenderContext &Context, Intercube &IC, Eagle::tvector3 &TranslationVector, double CameraShiftThreshold)
 The core function.
 
static Eagle::tvector3 getTranslationVector (Intercube &IC)
 Get the current translation vector that needs to be subtracted from coordinates when rendering.
 

Detailed Description

By default, the Camera in Vish is NOT translated to the location of the specified observer, but it resides at location (0,0,0).

This is to allow FloatOrigin objects to shift and move their data to the observer's location to enhance the numerical precision of OpenGL rendering.

So, if we render an object that does NOT provide this data shifting functionality, i.e. it is NOT a FloatOrigin object, then we have to translate the camera to the origin of the observer.

Basically implements the ideas from http://www.floatingorigin.com/ i.e. shift the coordinates, not the camera.

Render code using FloatOrigin works like this:

  1. Derive the VRenderObject also from class FloatOrigin;
  2. In the overriden render() function, call FloatOrigin::getCoordinateTranslation() and subtract the translation vector from physical world coordinates to get them into the local coordinate system;
  3. Advanced usage for lots of data coordinates to be translated will require caching such that a re-computation is only done at significant changes of the translation, but not always. This behavior is controllable by a threshold value, the CameraShiftThreshold . By default, it is 1E4.
  4. In practice, the translation vector is \not exactly the camera position, but comes with a tiny offset from that one, depending on said threshold. Thus, recomputing data values at each render() call is not needed, but only if this threshold has been exceeded, otherwise caching of shifted coordinates is the way to go, but only worth the effort for a significant amount of data values.

    Basic code (without caching) is as follows:

    // for glVertex() on Eagle::PhysicalSpace::point support
    #include <eagle/GL/EagleGL.hpp>
    struct MyRenderObject : VRenderObject, FloatOrigin
    {
    ... constructor etc. ...
    bool render(VRenderContext&Context, const View&Eye) const override
    {
    Eagle::point3 WorldCoordinates{ 1E10, 1E12, 1E25 };
    {
    Eagle::tvector3 TranslationVector;
    VRenderContext::ModelViewState FloatOriginRenderSection =
    getCoordinateTranslation(Context, TranslationVector);
    Eagle::point3 LocalCoordinates = WorldCoordinates - TranslationVector;
    glVertex( LocalCoordinates );
    }
    }
    };
    A set of variable names, with indices associated to each type.
    Definition Context.hpp:18
    Definition Camera.hpp:199
    A point in physical 3D space.
    Definition elementary/eagle/PhysicalSpace.hpp:106
    3-dimensional vector.
    Definition elementary/eagle/PhysicalSpace.hpp:170
    A reference counting pointer class which keeps objects alive as long as strong pointers to these obje...
    Definition RefPtr.hpp:405
    Base class for objects that may display something.
    Definition VRenderContext.hpp:77
    Base class for objects that implement a drawing routine.
    Definition VRenderObject.hpp:71
    By default, the Camera in Vish is NOT translated to the location of the specified observer,...
    Definition FloatOrigin.hpp:86
    Defining the view in a rendering scene via the projection parameters and the rotation / translation d...
    Definition View.hpp:155

    Here, the VRenderContext::ModelViewState performs the - little - translation within the camera threshold. I.e., the translation part of the modelview matrix is not entirely zero, but managed within this object. Its constructor sets the offset translation, its destructor removes it. The offset translation is always specific to each render object. In the above code, both WorldCoordinates and TranslationVector a large numbers, each of them would not fit into the floating point precision of GPU rendering. However, the difference, LocalCoordinates, is tiny enough to be sent, and handled, by the GPU in single-precision.

To enable threshold caching, the previous observer origin needs to be remembered somewhere. This is done by the caller providing an MemCore::Intercube object, for instance the VObject::State, but it can also be an Intercube attached to each of multiple data fragments. Then, provide this Intercube object to the getTranslationVector() function with an explicit argument.

Examples
AnemoneBoundingVolume.cpp.

Member Function Documentation

◆ getCoordinateTranslation()

VRenderContext::ModelViewState Wizt::FloatOrigin::getCoordinateTranslation ( const VRenderContext Context,
Eagle::tvector3 TranslationVector 
) const
       Get the coordinate translaton as cached at the object's local
       state.
       This might be problematic, it is better to cache the float
       origin at a better suitable object.

       @param  TranslationVector output only - the translation vector by which
                                 coordinates need to be shifted
point RenderCoords(const point&DataCoords)
{
return DataCoords - TranslationVector;
}
Returns
nullptr if the translation vector has been changed since last call, which would require re-computation of cached coordinates, otherwise it contains a MatrixState preserving the current matrix status just before it was shifted using a matrix operation
A FixedArray is a simple copy-by-value array providing random access to its elements.
Definition FixedArray.hpp:217
virtual ModelViewState ModelShift(const Eagle::FixedArray< double, 3 > &Translation) const =0

Referenced by Wizt::BaseCursor3D::environment_render().

◆ getTranslationVector()

VRenderContext::ModelViewState Wizt::FloatOrigin::getTranslationVector ( const VRenderContext Context,
Intercube IC,
Eagle::tvector3 TranslationVector,
double  CameraShiftThreshold 
)
static

The core function.

This function computes a translation vector as required for shifting coordinates. It also shifts the model view matrix if required, so this function must be called in advance of any rendering that uses the same translation vector shift.

References MemCore::Intercube::addInterface().