custom scene nodes

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
empirepro
Posts: 71
Joined: Thu Dec 27, 2007 5:41 am

custom scene nodes

Post by empirepro »

In order to add custom scene nodes you have to recompile Irrlicht right?
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

No, just have a look at the Custom Scene Node tutorial.
empirepro
Posts: 71
Joined: Thu Dec 27, 2007 5:41 am

Post by empirepro »

Ok I am trying to add a sun flare scene node that I found on this forum. It came with 2 header files and 1 cpp file. I added all 3 files to my project and included the one header file that it said to include in your project. How ever when I try to compile it I get the error:

Code: Select all

------ Rebuild All started: Project: Final Conflict, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'Final Conflict', configuration 'Debug|Win32'
Compiling...
CLensFlareSceneNode.cpp
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(83) : error C2039: 'Textures' : is not a member of 'irr::video::SMaterial'
        c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\include\smaterial.h(66) : see declaration of 'irr::video::SMaterial'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(91) : warning C4244: 'argument' : conversion from 'irr::s32' to 'irr::f32', possible loss of data
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(91) : warning C4244: 'argument' : conversion from 'irr::s32' to 'irr::f32', possible loss of data
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(97) : warning C4244: 'argument' : conversion from 'irr::s32' to 'irr::f32', possible loss of data
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(97) : warning C4244: 'argument' : conversion from 'irr::s32' to 'irr::f32', possible loss of data
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(101) : error C2039: 'Textures' : is not a member of 'irr::video::SMaterial'
        c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\include\smaterial.h(66) : see declaration of 'irr::video::SMaterial'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(101) : error C2227: left of '->getOriginalSize' must point to class/struct/union/generic type
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(101) : error C2228: left of '.Width' must have class/struct/union
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(101) : error C2039: 'Textures' : is not a member of 'irr::video::SMaterial'
        c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\include\smaterial.h(66) : see declaration of 'irr::video::SMaterial'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(101) : error C2227: left of '->getOriginalSize' must point to class/struct/union/generic type
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(101) : error C2228: left of '.Height' must have class/struct/union
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(103) : error C2039: 'Textures' : is not a member of 'irr::video::SMaterial'
        c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\include\smaterial.h(66) : see declaration of 'irr::video::SMaterial'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(103) : error C2227: left of '->getSize' must point to class/struct/union/generic type
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\clensflarescenenode.cpp(103) : error C2228: left of '.Height' must have class/struct/union
main.cpp
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\laser.h(56) : warning C4305: '*=' : truncation from 'double' to 'irr::f32'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\laser.h(66) : warning C4305: '*=' : truncation from 'double' to 'irr::f32'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\main.cpp(243) : warning C4305: 'argument' : truncation from 'double' to 'irr::f32'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\main.cpp(247) : warning C4305: 'argument' : truncation from 'double' to 'irr::f32'
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\main.cpp(260) : warning C4244: 'argument' : conversion from 'double' to 'irr::f32', possible loss of data
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\main.cpp(283) : warning C4244: 'argument' : conversion from 'double' to 'irr::f32', possible loss of data
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\main.cpp(65) : warning C4101: 'metaSelector' : unreferenced local variable
c:\documents and settings\empire productions\desktop\game development\game engine\game core\renderer\examples\04.movement\main.cpp(66) : warning C4101: 'anim' : unreferenced local variable
Generating Code...
Build log was saved at "file://c:\Documents and Settings\Empire Productions\Desktop\game development\Game Engine\Game Core\Renderer\examples\04.Movement\Debug\BuildLog.htm"
Final Conflict - 10 error(s), 12 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Now I am sure its because this node was made using a older version of Irrlicht but what do I need to change to get it to work with the current version?

Code: Select all

#include "irrlicht.h"
#include "CLensFlareSceneNode.h"
#include <string>
#include <iostream>

using namespace std;

namespace irr
{
namespace scene
{

CLensFlareSceneNode::CLensFlareSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, const core::vector3df& position )
: ILensFlareSceneNode(parent, mgr, id, position)
{
    AutomaticCullingState = EAC_BOX;

    indices[0] = 0;
    indices[1] = 2;
    indices[2] = 1;
    indices[3] = 0;
    indices[4] = 3;
    indices[5] = 2;

    (this)->setID(id);
    (this)->setParent(parent);

    vertices[0].TCoords.set(0.0f, 1.0f);
    vertices[0].Color = 0xffffffff;
    vertices[1].TCoords.set(0.0f, 0.0f);
    vertices[1].Color = 0xffffffff;
    vertices[2].TCoords.set(1.0f, 0.0f);
    vertices[2].Color = 0xffffffff;
    vertices[3].TCoords.set(1.0f, 1.0f);
    vertices[3].Color = 0xffffffff;
    
    screensize = SceneManager->getVideoDriver()->getScreenSize();
    
    material.Lighting = false;

    material.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;

    material.ZBuffer = false;

    material.ZWriteEnable = false;

    BBox.MinEdge = core::vector3df(-2, -2, -2 );

    BBox.MaxEdge = core::vector3df( 2,  2,  2 );
}

video::SMaterial& CLensFlareSceneNode::getMaterial(s32 i)
{
    return material;
}

u32 CLensFlareSceneNode::getMaterialCount()
{ 
    return 1;
}

void CLensFlareSceneNode::OnRegisterSceneNode()
{
    if(IsVisible)
    {
        core::position2d<s32> pm = SceneManager->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(getAbsolutePosition(), SceneManager->getActiveCamera() );
        
        if(core::rect<s32>(core::position2d<s32>(0,0), screensize).isPointInside(pm))
        {
            SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);

            ISceneNode::OnRegisterSceneNode();
        }
    }
}

void CLensFlareSceneNode::render()
{
    video::IVideoDriver* driver = SceneManager->getVideoDriver();

    ICameraSceneNode* camera = SceneManager->getActiveCamera();

    if (!camera || !driver || !material.Textures[0]) return;

    driver->setTransform(video::ETS_WORLD, core::matrix4());

    core::vector3df campos = camera->getAbsolutePosition();

    core::dimension2d<s32> sz = SceneManager->getVideoDriver()->getScreenSize();

    core::vector2df mid = core::vector2df(sz.Width, sz.Height );

    mid /= 2;

    core::position2d< s32 > lp = SceneManager->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(getAbsolutePosition(), camera );

    core::vector2df lightpos = core::vector2df(lp.X, lp.Y );

    core::vector2df ipos;

    int nframes = material.Textures[0]->getOriginalSize().Width / material.Textures[0]->getOriginalSize().Height;

    int imageheight = material.Textures[0]->getSize().Height;

    int texw = 8;

    float texp = 1.0f / nframes;

    core::vector3df target = camera->getTarget();

    core::vector3df up = camera->getUpVector();

    core::vector3df view = target - campos;

    view.normalize();
    
    core::vector3df horizontal = up.crossProduct(view);

    horizontal.normalize();

    core::vector3df vertical;

    vertical = horizontal.crossProduct(view);

    vertical.normalize();

    view *= -1.0f;

    for (s32 i=0; i<4; ++i) vertices[i].Normal = view;

    core::vector3df hor;

    core::vector3df ver;

    driver->setMaterial(material);

    core::vector3df pos;

    for (int ax = 0; ax < nframes; ax++ )
    {
        if (ax == 0 )
        { 
            pos = getAbsolutePosition();
            texw = imageheight;
        }
        else
        {
            ipos = mid.getInterpolated(lightpos, (2.0f / nframes ) * ax );

            pos = SceneManager->getSceneCollisionManager()->getRayFromScreenCoordinates(
            core::position2d<s32>(int(ipos.X ), int(ipos.Y ) ), camera ).end;
            core::vector3df dir = core::vector3df(campos - pos ).normalize();
            pos = campos + (dir * -10.0f );
            texw = 4;
        }

        vertices[0].TCoords.set(   ax * texp,  1.0f);
        vertices[1].TCoords.set(   ax * texp,  0.0f);
        vertices[2].TCoords.set((ax+1) * texp, 0.0f);
        vertices[3].TCoords.set((ax+1) * texp, 1.0f);

        hor = horizontal * (0.5f * texw );
        ver = vertical   * (0.5f * texw );

        vertices[0].Pos = pos + hor + ver;
        vertices[1].Pos = pos + hor - ver;
        vertices[2].Pos = pos - hor - ver;
        vertices[3].Pos = pos - hor + ver;

        driver->drawIndexedTriangleList(vertices, 4, indices, 2);
    }
}

const core::aabbox3d<f32>& CLensFlareSceneNode::getBoundingBox() const { return BBox; }
}
}
Theres the content of the cpp file[/quote]
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It looks like it needs updated to be compatible with 1.4/1.4.1. I'll try and have a look later, but given your track record of abandoning solutions or figuring things out yourself without updating your posts, you'll understand if I don't put this at the top of my ToDo list.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

This should be pretty simple to solve and you can find what you need to change things to from the API, learn to use the API, it will answer a lot of your questions quicker than asking on the forum.

There's a link to the API on the irrlicht website or you can use the handy .chm in the docs folder of the SDK which allows you to search for keywords which would obviously be faster than sifting through the API online.

I'll give you a helping hand to show you what to do. The first error says Textures is not a member of SMaterial, this suggests that it's been changed to something different in the current version of Irrlicht so you look up SMaterial in the API/docs and try and find out what it's been changed to. So from the API you can see a function called getTexture(int) so it looks like the Textures field of SMaterial was made private and a get function has been added instead, so change Textures to getTexture and that should solve that error.

Now repeat the same process for the other errors that have been reported by your compiler.
Image Image Image
Post Reply