Ribbon Trails: Tracers

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Tang of the mountain
Kobold
Posts: 35
Joined: Mon Oct 30, 2006 11:03 pm

Ribbon Trails: Tracers

Post by Tang of the mountain »

Im attempting to use ribbon trails as tracers on projectiles. Which are dynamically created and destroyed, naturally.

I create on ribbon trail object and add a scene node created from each projectiles scene node.

I notice, however, that when one of the nodes is deleted. All the nodes shift down and adopt the previous nodes chains until the last one is deleted. This creates the effect of the last projectile adopting each previous projectiles trail for a bit until another one is deleted. Which filters down throughout all nodes until it itself is deleted. At which time it currently owns the very first chain and the rest are left dangling.

Is there a way to not get this effect? I dont want to have to use a ribbon trail object for each projectile. I have found nothing in the docs about removing a chain, simply clearing it(leaving it intact), clearing them all(leaving them intact), or removing individual elements from specific chains.

Any help is appreciated. Thanks.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Insteaad of removing the node, you can move the node to where it needs to be next and call ribbonTrail->clearChain(index) to reset the trail for it.
Tang of the mountain
Kobold
Posts: 35
Joined: Mon Oct 30, 2006 11:03 pm

Post by Tang of the mountain »

if i were to move the node to where it needs to be, wouldnt that create the same problem with the chains not actually moving thus every node would still adopt the previous chain, as they dont seem to be directly attached to a node, just an index. I want the chain and the node to be removed completely when the item is deleted.


I also changed the demo to use only one chain, create it, then increase the number using setNumberOfChains() and create a new node and add it. This, however, created a line stretching into infinity.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

No, clearChain will basically remove the effect of the node without actually removing it. The chain should be invisible until you move that Node again (because it needs more than one reference point to be a valid chain). That's why I said move it then clear it.

RibbonTrail doesn't currently support dynamically removing a node in the middle, only at the end. It also assumes the number of chains is set to the same number of nodes being monitored. For the moment I suggest the workaround above or tinkering with the implementation yourself if you want to provide a more flexible mappping between monitored nodes and chains (basically you could do this through an indirection from Node to chain).
Tang of the mountain
Kobold
Posts: 35
Joined: Mon Oct 30, 2006 11:03 pm

Post by Tang of the mountain »

Thanks a ton for the help! Im working on the aformentioned implementatino now. ;)
Tang of the mountain
Kobold
Posts: 35
Joined: Mon Oct 30, 2006 11:03 pm

Post by Tang of the mountain »

ok, so the individual ribbon trail objects per projectile work to a point.

I create the ribbon trail effect and attach to a child of the root scene node offset to the entities position(if i use any other noed besides root it wont render)

I then make the tracked node a child of the entity im following. (i like to keep effects and entities separated)

When i move around the world and shoot, the tracer works most of the time. However, sometimes it doesnt attach to the entity and seems to fire from a location offset from the entity it was attached to. I also sometimes see a distant line flicker when this happens like the ribbon is stretched out across the scene for a brief moment.

I rechecked the positions and orientations im using to ensure they match the entity, which they do. But the entity and ribbon trail still do not match up sometimes. Am I not updating something properly?

Ive checked the forums but havent found anything related to my problem.

this is some of my attach code

Code: Select all


//...i create and set up the ribbon trail here...

m_pTrailSceneNode = m_pParentEntity->GetOgreSceneNode()->createChildSceneNode(m_strSceneNodeName);

//...I set width and colour values here...

//offset the ribbon trail to be at the entities position
m_pSceneMgr->getRootSceneNode()->createChildSceneNode(pos, qOrient)->attachObject(ribbonTrail);

ribbonTrail->addNode(m_pTrailSceneNode);
pos and qOrient are the exact data from the entity(which is correct)

its not a constant problem, only happens at random times(at least seems random thus far)
Tang of the mountain
Kobold
Posts: 35
Joined: Mon Oct 30, 2006 11:03 pm

Post by Tang of the mountain »

i found a post that talked about attaching nodes and double transforms. So i removed the tracer node and just attached my entity and it seemed to work fine. Although a little explanation on why would be superb. Thanks.
User avatar
leonardoaraujo.santos
Greenskin
Posts: 141
Joined: Fri Apr 27, 2007 6:00 pm
Location: Brazil

Post by leonardoaraujo.santos »

Hi Tang of the mountain could you send a snippet or the code that you used to do this ribbon trail effect for missiles. I'm also looking for this.

Thanks
Tang of the mountain
Kobold
Posts: 35
Joined: Mon Oct 30, 2006 11:03 pm

Post by Tang of the mountain »

I have a central area that loads all of the ribbon trail properties from a file(or uses a cached version if file was loaded already) which gives me a pointer to a class containing all of the data.

When i activate my entity in the scene i create the ribbon trail much as they do in the lighting demo only i set a few more properties.

Code: Select all

    Ogre::NameValuePairList pairList;
    std::string numChains = stringbuilder() << m_pDescription->m_iChainCount;
    std::string maxElements = stringbuilder() << m_pDescription->m_iMaxElementsPerChain;
    pairList["numberOfChains"] = numChains;
    pairList["maxElements"] = maxElements;

  try
    {
        //build object name
        std::string name = stringbuilder() <<  "_$_" << m_pDescription->m_strName << "_" << g_iTracerIndex << "_$_";
        ribbonTrail = static_cast<Ogre::RibbonTrail*>(
            m_pSceneMgr->createMovableObject(name, "RibbonTrail", &pairList));
    }
    catch (Ogre::Exception &e)
    {
        LOGE("Could not create ribbon trail object: " + e.getDescription());
        return false;
    }

    if (!ribbonTrail)
    {
        return false;
    }

    //set ribbon trail attributes from loaded file
    ribbonTrail->setMaterialName(m_pDescription->m_strMaterialName);
    ribbonTrail->setTrailLength(m_pDescription->m_fTrailLength);
    ribbonTrail->setRenderingDistance(m_pDescription->m_fRenderingDistance);
    ribbonTrail->setUseVertexColours(m_pDescription->m_bUseVertexColors);
    ribbonTrail->setUseTextureCoords(m_pDescription->m_bUseTextureCoords);
    ribbonTrail->setDynamic(m_pDescription->m_bDynamicUse);
    ribbonTrail->setVisible(m_pDescription->m_bVisible);
    ribbonTrail->setPolygonModeOverrideable(m_pDescription->m_bPolygonModeOverrideable);
then i get the position and orientation of the entiyt and attach as such

Code: Select all

    m_strSceneNodeName = stringbuilder() << "_$_tracer_" << g_iTracerIndex << "_$_";
    g_iTracerIndex++;
    Vector3 pos = m_pParentEntity->GetPosition();
    Matrix33 orient = m_pParentEntity->GetOrientation();
    Quat qOrient;
    orient.toQuat(qOrient);

    OnChangeInitialColor();
    OnChangeDeltaColor();
    OnChangeInitialWidth();
    OnChangeDeltaWidth();

    //offset the ribbon trail to be at the entities position
    m_pSceneMgr->getRootSceneNode()->createChildSceneNode(m_strSceneNodeName, pos, qOrient)->attachObject(ribbonTrail);
    ribbonTrail->addNode(m_pParentEntity->GetOgreSceneNode());
The on change func you see here just ser the data on a per entity bases that could be changed per projectile. The rest I use template ribbon trails which are those that store the other properties above in a file. I assume these wont change and if they do I ask the user to define a new template file. (all props done in XML)

All of the above is done per entity that requires a ribbon trail tracer. So each entity(for now) uses a full 524(or so) byte ribbon trail. Which is oppose to having all liek tracers under one ribbon trail which cant be done for my purposes but would only use the 36+ bytes per chain. If you can work with one ribbon trail object, i suggest doing it.

The only problem I forsee, is I have yet to be able to get the trail length to be fully customizable. Im not sure if im using the trail length, and max elements wrong, but I either get a trail nub, a small trail, or somethign the size of an airline strip which goes for far too long. I can get nothing in between. That and the small trail nly has two elements so it look horrible when moving slow.
User avatar
leonardoaraujo.santos
Greenskin
Posts: 141
Joined: Fri Apr 27, 2007 6:00 pm
Location: Brazil

Post by leonardoaraujo.santos »

Thanks Tang of the mountain I also made a simple example based on the SDK Lightning Demo on http://www.ogre3d.org/phpBB2/viewtopic.php?t=34020

Thanks
Post Reply