コード例 #1
0
ファイル: IObjectDrw.cpp プロジェクト: hallLong/bb_alembic
//-*****************************************************************************
void IObjectDrw::draw( const DrawContext &iCtx )
{
    if ( !m_object ) { return; }

    // Skip objects with "visible" property set to 0
    if ( iCtx.getVisibleOnly() ) {
        Abc::ICompoundProperty props = m_object.getProperties();
        const Abc::PropertyHeader* header = props.getPropertyHeader( "visible" );
        if ( header != NULL ) {
            Abc::IScalarProperty visible( props, "visible" );
            Abc::ISampleSelector iss( m_currentTime );
            int8_t val = 1;
            visible.get( reinterpret_cast<void*>( &val ), iss );
            if ( val == 0 ) 
                return;
        }
    }

    for ( DrawablePtrVec::iterator iter = m_children.begin();
          iter != m_children.end(); ++iter )
    {
        DrawablePtr dptr = (*iter);
        if ( dptr )
        {
            dptr->draw( iCtx );
        }
    }
}
コード例 #2
0
void AccelerateAction::apply(const DrawablePtr& target, const DateTime& thisFrameStartTime, const TimeDuration& deltaTime)
{
	// basic physics
	// v = a t
	// d = v t
	// d = 1/2 a t^2
	// delta_d = 1/2 a t^2 - 1/2 a (t-delta_t)^2    : 6 *, 2 -
	// alternate forms (thanks to wolfram alpha)
	// delta_d = -1/2 a delta_t (delta_t - 2 t)     : 4 *, 1 - (using this one)
	// delta_d = a delta_t t - (a delta_t^2)/2      : 4 *, 1 /, 1 -
	// delta_d = 1/2 a delta_t (2 t - delta_t)      : 4 *, 1 -

	elapsedTime += deltaTime;
	double delta_t = deltaTime.realSeconds();
	double t = elapsedTime.realSeconds();
	Point position = target->position();
	currentSpeed = t * yPixelsPerSecondSquared;
	if( (useMaxSpeed && (currentSpeed <= maxSpd)) || (!useMaxSpeed))
	{
		position.y() += -.5 * yPixelsPerSecondSquared * delta_t * (delta_t - 2 * t);
	}
	else
	{
		position.y() += maxSpd *delta_t;
	}

	position.x() += -.5 * xPixelsPerSecondSquared * delta_t * (delta_t - 2 * t);

	target->setPosition(position);
}
コード例 #3
0
//-*****************************************************************************
void IObjectDrw::draw( const DrawContext &iCtx )
{
    if ( !m_object ) { return; }

    // Skip objects with "visible" property set to 0
    if ( iCtx.visibleOnly() ) {
        Abc::ICompoundProperty props = m_object.getProperties();
        const Abc::PropertyHeader* header = props.getPropertyHeader( "visible" );
        if ( header != NULL ) {
            Abc::IScalarProperty visible( props, "visible" );
            Abc::ISampleSelector iss( m_currentTime );
            int8_t val = 1;
            visible.get( reinterpret_cast<void*>( &val ), iss );
            if ( val == 0 ) 
                return;
        }
    }

    // GL picking, add to global selection index
    int i = 0;
    for ( DrawablePtrVec::iterator iter = m_children.begin();
          iter != m_children.end(); ++iter, i++ )
    {
        Abc::IObject iChild = m_object.getChild( i );
        int index = pushName( iChild );
        DrawablePtr dptr = (*iter);
        if ( dptr )
        {
            dptr->draw( iCtx );
        }
        if ( index >= 0 )
            popName( m_object );
    }
    
}
コード例 #4
0
// Called when the gem should setup.
void ExpandingDropsGem::OnSetup(IDrawablePtr mainLayer)
{
    // Create a layer so we can dim this a little
    DrawablePtr dimmedLayer = std::make_shared<Drawable>();
    dimmedLayer->SetIntensity(0.3);
    m_mainLayer = dimmedLayer;

    // Add the layer
    mainLayer->AddDrawable(dimmedLayer, 50);
}
コード例 #5
0
//-*****************************************************************************
void IObjectDrw::draw( const DrawContext &iCtx )
{
    if ( !m_object ) { return; }

    for ( DrawablePtrVec::iterator iter = m_children.begin();
          iter != m_children.end(); ++iter )
    {
        DrawablePtr dptr = (*iter);
        if ( dptr )
        {
            dptr->draw( iCtx );
        }
    }
}
コード例 #6
0
//-*****************************************************************************
void IObjectDrw::setTime( chrono_t iTime )
{
    if ( !m_object ) { return; }

    // Object itself has no properties to worry about.
    m_bounds.makeEmpty();
    for ( DrawablePtrVec::iterator iter = m_children.begin();
          iter != m_children.end(); ++iter )
    {
        DrawablePtr dptr = (*iter);
        if ( dptr )
        {
            dptr->setTime( iTime );
            m_bounds.extendBy( dptr->getBounds() );
        }
    }
}
コード例 #7
0
ファイル: main.cpp プロジェクト: metiscus/creepy-octo-waddle
void add_yoshi( std::vector<std::shared_ptr<Object> > &objects, int x, int y)
{
    DrawablePtr yoshi (new Drawable());
    yoshi->SetTexture(1);
    yoshi->SetWidth(64.0);
    yoshi->SetHeight(64.0);
    yoshi->SetMaxFrame(8);
    yoshi->SetFrameRate(4);
    yoshi->SetLayer(Render::LayerBg);

    std::shared_ptr<RenderComponent> render_comp (new RenderComponent());
    render_comp->AddDrawable(yoshi);
    render->AddComponent(render_comp);

    std::shared_ptr<AIComponent> ai_comp(new AIComponent());
    ai_comp->SetMaxSpeed(3.5);
    ai_world->AddComponent(ai_comp);

    std::shared_ptr<PhysicsComponent> phy_comp(new PhysicsComponent());

    std::shared_ptr<Object> yoshi_obj(new Object());
    yoshi_obj->SetPosition(Vector(x, y));
    yoshi_obj->SetComponent(AIComponentId, ai_comp);
    yoshi_obj->SetComponent(RenderComponentId, render_comp);
    yoshi_obj->SetComponent(PhysicsComponentId, phy_comp);

    objects.emplace_back(yoshi_obj);
}
コード例 #8
0
ファイル: drawable.cpp プロジェクト: bssrdf/toptop
void drawScene(ScnNodePtr sceneRoot)
{
    glPushMatrix();
    glMultMatrixf(transpose(sceneRoot->transform.mat()).data);
    
    // post-order traversal
    const auto &children = sceneRoot->getChildren();
    for(const ScnNodePtr &node : children)
    {
        drawScene(node);
    }
    
    DrawablePtr drawable =
        std::dynamic_pointer_cast<Drawable>(sceneRoot);
    if(drawable)
        drawable->draw();
    
    glPopMatrix();
}
コード例 #9
0
//-*****************************************************************************
IObjectDrw::IObjectDrw( IObject &iObj, bool iResetIfNoChildren )
  : m_object( iObj )
  , m_minTime( ( chrono_t )FLT_MAX )
  , m_maxTime( ( chrono_t )-FLT_MAX )
{
    // If not valid, just bail.
    if ( !m_object ) { return; }

    // IObject has no explicit time sampling, but its children may.
    size_t numChildren = m_object.getNumChildren();
    for ( size_t i = 0; i < numChildren; ++i )
    {
        const ObjectHeader &ohead = m_object.getChildHeader( i );

        // Decide what to make.
        DrawablePtr dptr;
        if ( IPolyMesh::matches( ohead ) )
        {
            IPolyMesh pmesh( m_object, ohead.getName() );
            if ( pmesh )
            {
                dptr.reset( new IPolyMeshDrw( pmesh ) );
            }
        }
        else if ( IPoints::matches( ohead ) )
        {
            IPoints points( m_object, ohead.getName() );
            if ( points )
            {
                dptr.reset( new IPointsDrw( points ) );
            }
        }
        else if ( ICurves::matches( ohead ) )
        {
            ICurves curves( m_object, ohead.getName() );
            if ( curves )
            {
                dptr.reset( new ICurvesDrw( curves ) );
            }
        }
        else if ( INuPatch::matches( ohead ) )
        {
            INuPatch nuPatch( m_object, ohead.getName() );
            if ( nuPatch )
            {
                dptr.reset( new INuPatchDrw( nuPatch ) );
            }
        }
        else if ( IXform::matches( ohead ) )
        {
            IXform xform( m_object, ohead.getName() );
            if ( xform )
            {
                dptr.reset( new IXformDrw( xform ) );
            }
        }
        else if ( ISubD::matches( ohead ) )
        {
            ISubD subd( m_object, ohead.getName() );
            if ( subd )
            {
                dptr.reset( new ISubDDrw( subd ) );
            }
        }
        else
        {
            IObject object( m_object, ohead.getName() );
            if ( object )
            {
                dptr.reset( new IObjectDrw( object, true ) );
            }
        }

        if ( dptr && dptr->valid() )
        {
            m_children.push_back( dptr );
            m_minTime = std::min( m_minTime, dptr->getMinTime() );
            m_maxTime = std::max( m_maxTime, dptr->getMaxTime() );
        }
    }

    // Make the bounds empty to start
    m_bounds.makeEmpty();

    // If we have no children, just leave.
    if ( m_children.size() == 0 && iResetIfNoChildren )
    {
        m_object.reset();
    }
}
コード例 #10
0
//-*****************************************************************************
IObjectDrw::IObjectDrw( IObject &iObj, bool iResetIfNoChildren, std::vector<std::string> path )
  : m_object( iObj )
  , m_minTime( ( chrono_t )FLT_MAX )
  , m_maxTime( ( chrono_t )-FLT_MAX )
  , m_currentTime( ( chrono_t )-FLT_MAX )
{
    // If not valid, just bail.
    if ( !m_object ) { return; }

    if (path.size()) {
        // std::cout << "IObjectDraw path: " << path[0] << std::endl;
        const ObjectHeader *ohead = m_object.getChildHeader( path[0] );
        if ( ohead!=NULL ) {
            path.erase(path.begin());
            DrawablePtr dptr;
            if ( IXform::matches( *ohead ) ) {
                IXform xform( m_object, ohead->getName() );
                if ( xform ) {
                    dptr.reset( new IXformDrw( xform, path ) );
                }
            }
            if ( dptr && dptr->valid() ) {
                m_children.push_back( dptr );
                m_minTime = std::min( m_minTime, dptr->getMinTime() );
                m_maxTime = std::max( m_maxTime, dptr->getMaxTime() );
            }
        }
    }       
    else
    {   
        // IObject has no explicit time sampling, but its children may.
        size_t numChildren = m_object.getNumChildren();
        for ( size_t i = 0; i < numChildren; ++i )
        {
            const ObjectHeader &ohead = m_object.getChildHeader( i );
            std::cout << "IObjectDraw path: " << ohead.getName() << std::endl;

            // Decide what to make.
            DrawablePtr dptr;
            if ( IPolyMesh::matches( ohead ) )
            {

                // std::cout << "IPolyMesh path: " << ohead.getName() << std::endl;
                IPolyMesh pmesh( m_object, ohead.getName() );
                if ( pmesh )
                {
                    dptr.reset( new IPolyMeshDrw( pmesh, path ) );
                }
            }
    /*        else if ( IPoints::matches( ohead ) )
            {
                IPoints points( m_object, ohead.getName() );
                if ( points )
                {
                    dptr.reset( new IPointsDrw( points ) );
                }
            }
            else if ( IXform::matches( ohead ) )
            {
                IXform xform( m_object, ohead.getName() );
                if ( xform )
                {
                    dptr.reset( new ISimpleXformDrw( xform ) );
                }
            }
    */        else if ( IXform::matches( ohead ) )
            {
                // std::cout << "IXform path: " << ohead.getName() << std::endl;

                IXform xform( m_object, ohead.getName() );
                if ( xform )
                {
                    dptr.reset( new IXformDrw( xform, path ) );
                }
            }
            // else if ( ISubD::matches( ohead ) )
            // {
            //     // std::cout << "ISubD path: " << ohead.getName() << std::endl;
                
            //     ISubD subd( m_object, ohead.getName() );
            //     if ( subd )
            //     {
            //         dptr.reset( new ISubDDrw( subd, path  ) );
            //     }
            // }
            else
            {
                // std::cout << "IObject path: " << ohead.getName() << std::endl;
                IObject object( m_object, ohead.getName() );
                if ( object )
                {
                    dptr.reset( new IObjectDrw( object, true, path ) );
                }
            }

            if ( dptr && dptr->valid() )
            {
                m_children.push_back( dptr );
                m_minTime = std::min( m_minTime, dptr->getMinTime() );
                m_maxTime = std::max( m_maxTime, dptr->getMaxTime() );
            }
        }
    }
    
    // Make the bounds empty to start
    m_bounds.makeEmpty();

    // If we have no children, just leave.
    if ( m_children.size() == 0 && iResetIfNoChildren )
    {
        m_object.reset();
    }
}
コード例 #11
0
ファイル: Node.cpp プロジェクト: uudens/ouzel
 void Node::addDrawable(DrawablePtr drawable)
 {
     drawables.push_back(drawable);
     drawable->setParentNode(std::static_pointer_cast<Node>(shared_from_this()));
 }