custom scene nodes
Posted: Fri Jul 18, 2008 4:33 am
In order to add custom scene nodes you have to recompile Irrlicht right?
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
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 ==========
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; }
}
}