Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members   Related Pages  

Composition::EffectI Class Reference

The effect interface. More...

#include <EffectI.h>

Inheritance diagram for Composition::EffectI:

Edit::EditableI Edit::DataBlockI List of all members.

Public Methods

Protected Methods


Detailed Description

The effect interface.

The effect interface is one of the most import interfaces in Demopaja for the coder. Every effect to be shown on screen have to be derived from this class.

In normal play mode there are two metods which are called every frame: eval_state() and do_frame(). The first evaluates the state of the specified frame, calculates all data that can be calculated before hand. The latter renders the effect to the screen.

The reason to cut the rendering in tow parts is that sometimes the Demopaja editor needs some information about the effect but there is no need to render the object. Also a frame can be rendered multiple time while editing and there's no reason to update the data, only to draw it.

To create a new instace of the effect class a static member should be created, which takes care of the instantiating. The member could look like this:

        TestEffectC*
        TestEffectC::create_new()
        {
            return new TestEffectC;
        }


Constructor & Destructor Documentation

EffectI ( ) [protected]
 

Default constructor.

EffectI ( Edit::EditableI * pOriginal ) [protected]
 

Default constructor with reference to the original.

~EffectI ( ) [protected, virtual]
 

Default destructor.


Member Function Documentation

void add_flags ( PajaTypes::int32 i32Flags ) [virtual]
 

Sets only specified flags.

Implemented by the EffectI class.

void copy ( Edit::DataBlockI * pBlock ) [virtual]
 

Deep copy from a data block, see Edit::DataBlockI::copy().

When overriding this method the base class member should be called first.

Example:

            void
            TestEffectC::copy( DataBlockI* pBlock )
            {
                EffectI::copy( pBlock );
                TestEffectC*    pEffect = (TestEffectC*)pBlock;
                m_pGizmo->copy( pEffect->m_pGizmo );
            }

Reimplemented from Edit::EditableI.

void del_flags ( PajaTypes::int32 i32Flags ) [virtual]
 

Removes only specified flags.

Implemented by the EffectI class.

void do_frame ( PajaSystem::DeviceContextC * pContext ) [pure virtual]
 

Execute (draws, plays, etc.) the current state of the effect.

All the rendering code goes in this method.

Example:

            void
            PlasmaEffectC::do_frame( DeviceContextC* pContext )
            {
                // Query the interface to use.
                OpenGLInterfaceC*   pInterface = (OpenGLInterfaceC*)pContext->query_interface( INTERFACE_OPENGL );
                if( !pInterface )
                    return;

                // Use the interface to set the rendering area.
                pInterface->set_ortho( m_rBBox, m_rBBox.width(), m_rBBox.height() );

                // Render the effect
                ...
            }

void eval_state ( PajaTypes::int32 i32Time,
PajaSystem::TimeContextC * pTimeContext ) [pure virtual]
 

Evaluate the state of this effect at specified time.

All the calculation should be done in this method. The eval_state() and do_frame() have been separated to allow the user interface to update the state of the effect only once and draw the effect many times.

The eval_state() method may also be called to update the data (such as the transformation matrix), but not to draw it.

Example:

            void
            TestEffectC::eval_state( int32 i32Time, TimeContextC* pTimeContext )
            {
                Matrix2C    rPosMat, rRotMat, rScaleMat, rPivotMat;
                Vector2C    rPivot = m_pGizmo->get_pivot( i32Time );

                // Calc matrix.
                rPivotMat.set_trans( -rPivot );
                rPosMat.set_trans( m_pGizmo->get_pos( i32Time ) + rPivot );
                rRotMat.set_rot( m_pGizmo->get_rot( i32Time ) / 180.0f * M_PI );
                rScaleMat.set_scale( m_pGizmo->get_scale( i32Time ) ) ;

                // Store matrix.
                m_rTM = rPivotMat * rRotMat * rScaleMat * rPosMat;

                // Calc bounding box
                float32     f32Width = 25, f32Height = 25;
                Vector2C    rMin, rMax, rVec;

                m_rVertices[0][0] = -f32Width;      // top-left
                m_rVertices[0][1] = -f32Height;
                m_rVertices[1][0] =  f32Width;      // top-right
                m_rVertices[1][1] = -f32Height;
                m_rVertices[2][0] =  f32Width;      // bottom-right
                m_rVertices[2][1] =  f32Height;
                m_rVertices[3][0] = -f32Width;      // bottom-left
                m_rVertices[3][1] =  f32Height;

                for( uint32 i = 0; i < 4; i++ ) {
                    rVec = m_rTM * m_rVertices[i];
                    m_rVertices[i] = rVec;
                    if( !i )
                        rMin = rMax = rVec;
                    else {
                        if( rVec[0] < rMin[0] ) rMin[0] = rVec[0];
                        if( rVec[1] < rMin[1] ) rMin[1] = rVec[1];
                        if( rVec[0] > rMax[0] ) rMax[0] = rVec[0];
                        if( rVec[1] > rMax[1] ) rMax[1] = rVec[1];
                    }
                }
                // Store bounding box.
                m_rBBox[0] = rMin;
                m_rBBox[1] = rMax;
            }

PajaTypes::BBox2C get_bbox ( ) [pure virtual]
 

Returns axis-aligned bounding box of the effect.

PluginClass::ClassIdC get_class_id ( ) [pure virtual]
 

Returns unique class ID of the effect.

const char * get_class_name ( ) [pure virtual]
 

Returns effect's class name as NULL terminated string.

ParamI * get_default_param ( PajaTypes::int32 i32Param ) [pure virtual]
 

Returns default parameter.

Default parameters are commonly used parameters such as position and scale.

Example:

            ParamI*
            TestEffectC::get_default_param( PajaTypes::int32 i32Param )
            {
                if( i32Param == DEFAULT_PARAM_POSITION )
                    return m_pGizmo->get_parameter( TEST_PARAM_POS );
                else if( i32Param == DEFAULT_PARAM_ROTATION )
                    return m_pGizmo->get_parameter( TEST_PARAM_ROT );
                return 0;
            }
See also:
DefaultParamE

PajaTypes::int32 get_flags ( ) [virtual]
 

Returns effect flags.

Implemented by the EffectI class.

GizmoI * get_gizmo ( PajaTypes::int32 i32Index ) [pure virtual]
 

Returns gizmo at specified index.

PajaTypes::int32 get_gizmo_count ( ) [pure virtual]
 

Returns number of gizmos in the effect.

const char * get_name ( ) const [virtual]
 

Returns the name of the effect.

Implemented by the EffectI class.

PluginClass::SuperClassIdC get_super_class_id ( ) [virtual]
 

Returns super class ID of the effect (should be SUPERCLASS_EFFECT for effects).

TimeSegmentC * get_timesegment ( ) [virtual]
 

Returns the timesegment of this effect.

Implemented by the EffectI class.

const PajaTypes::Matrix2C & get_transform_matrix ( ) const [pure virtual]
 

Returns transformaion matrix of the effect.

bool hit_test ( const PajaTypes::Vector2C & rPoint ) [pure virtual]
 

Returns true if the given point is inside the region of the effect.

Example:

            bool
            TestEffectC::hit_test( const PajaTypes::Vector2C& rPoint )
            {
                // Point in polygon test (from comp.graphics.algorithms FAQ).
                int32   i, j;
                bool    bInside = false;
                for( i = 0, j = 4 - 1; i < 4; j = i++ ) {
                    if( ( ((m_rVertices[i][1] <= rPoint[1]) && (rPoint[1] < m_rVertices[j][1])) ||
                        ((m_rVertices[j][1] <= rPoint[1]) && (rPoint[1] < m_rVertices[i][1])) ) &&
                        (rPoint[0] < (m_rVertices[j][0] - m_rVertices[i][0]) * (rPoint[1] - m_rVertices[i][1]) / (m_rVertices[j][1] - m_rVertices[i][1]) + m_rVertices[i][0]) )
                        bInside = !bInside;
                }
                return bInside;
            }

void initialize ( PajaSystem::DeviceContextC * pContext,
PajaSystem::TimeContextC * pTimeContext ) [pure virtual]
 

Initialize effect.

This method is called after all data is passed to the effect. That is, after the effect has been loaded from file or after the effect is created, and all the possible data is set. Usually there is no need to do anything in this method.

PajaTypes::uint32 load ( FileIO::LoadC * pLoad ) [virtual]
 

Serialize effect from a Demopaja input stream.

The base class implementation of this method has to be called in the overridden method.

Example:

            uint32
            TestEffectC::load( LoadC* pLoad )
            {
                uint32  ui32Error = IO_OK;
                while( (ui32Error = pLoad->open_chunk()) == IO_OK ) {
                    switch( pLoad->get_chunk_id() ) {
                    case CHUNK_TESTEFFECT_EFFECTI:
                        if( pLoad->get_chunk_version() == TESTEFFECT_VERSION )
                            ui32Error = EffectI::load( pLoad );
                        break;
                    default:
                        assert( 0 );
                    }
                    pLoad->close_chunk();
                    if( ui32Error != IO_OK && ui32Error != IO_END )
                        return ui32Error;
                }
                return ui32Error;
            }

Reimplemented from Edit::EditableI.

void restore ( Edit::EditableI * pEditable ) [virtual]
 

Shallow copy from a editable, see Edit::EditableI::restore().

When overriding this method the base class member should be called first.

Example:

            void
            TestEffectC::restore( EditableI* pEditable )
            {
                EffectI::restore( pEditable );
                TestEffectC*    pEffect = (TestEffectC*)pEditable;
                m_pGizmo = pEffect->m_pGizmo;
            }

Reimplemented from Edit::EditableI.

PajaTypes::uint32 save ( FileIO::SaveC * pSave ) [virtual]
 

Serialize effect to a Demopaja output stream.

The base class implementation of this method has to be called in the overridden method.

Example:

            uint32
            TestEffectC::save( SaveC* pSave )
            {
                uint32  ui32Error = IO_OK;
                // EffectI stuff
                pSave->begin_chunk( CHUNK_TESTEFFECT_EFFECTI, TESTEFFECT_VERSION );
                    ui32Error = EffectI::save( pSave );
                pSave->end_chunk();
                return ui32Error;
            }

Reimplemented from Edit::EditableI.

void set_default_file ( Import::FileHandleC * pHandle ) [pure virtual]
 

Sets the default file if effect has a default file.

If the effect uses file parameters one of the file parameters has to be set as default file parameter. This is used for example is a file is dragged from File Inspector window to the Timeline Window. That causes new effect to be created and the dragged file to be set as default file. This method does not have to accept the file.

void set_flags ( PajaTypes::int32 i32Flags ) [virtual]
 

Sets the effect flags.

Be careful to use this method. There are some flags, which have to be in place to make the effect work correctly. Use add, del or toggle flags methods instead.

void set_name ( const char * szName ) [virtual]
 

Sets the name of the effect.

Implemented by the EffectI class.

void toggle_flags ( PajaTypes::int32 i32Flags ) [virtual]
 

Toggles only specified flags.

Implemented by the EffectI class.

void update_notify ( PajaTypes::uint32 ui32GizmoId,
PajaTypes::uint32 ui32ParamId,
PajaTypes::int32 i32Time ) [virtual]
 

This method is called when a parameter is changed.

Do not call the rendering methods from this method. The system will automatically update the state effect if a parameter is changed.


The documentation for this class was generated from the following file:
Moppi Demopaja SDK Documentation -- Copyright © 2000 Moppi Productions