FALSE
I added few hundred billboards and the fps dropped a lot.
Fix code:
Code: Select all
//! constructor
CBillboardSceneNode::CBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::dimension2d<f32>& size)
: IBillboardSceneNode(parent, mgr, id, position)
{
#ifdef _DEBUG
setDebugName("CBillboardSceneNode");
#endif
setSize(size);
//AutomaticCullingEnabled = false;
//lsize,position.Z-lsize,position.X+lsize,position.Y+lsize,position.Z+lsize);
f32 lsize = size.Height>size.Width ? size.Height/2:size.Width/2;
BBox = core::aabbox3d<f32>(-lsize,-lsize,-lsize,lsize,+lsize,+lsize);
............
Code: Select all
//! sets the size of the billboard
void CBillboardSceneNode::setSize(const core::dimension2d<f32>& size)
{
Size = size;
f32 lsize = size.Height>size.Width ? size.Height/2:size.Width/2;
BBox = core::aabbox3d<f32>(-lsize,-lsize,-lsize,lsize,+lsize,+lsize);
}
Code: Select all
//! Sets the color of the billboard. useful for color animator
//! Sets the color of the billboard.
void CBillboardSceneNode::setColor(const video::SColor& color)
{
vertices[0].Color = color;
vertices[1].Color = color;
vertices[2].Color = color;
vertices[3].Color = color;
}
//! Sets the color of the billboard.
virtual void setColor(const video::SColor& color);
Ibillboardscenenode.h
//! Sets the color of the billboard.
virtual void setColor(const video::SColor& color) =0;
From here on I'm using ISceneNode.h ::::
Now i cand add thousand of nodes.
The only bad think is that now:
Code: Select all
virtual void OnPostRender(u32 timeMs)
{....
// update absolute position
updateAbsolutePosition();
....
i get thousand of useless updateAbsolutePosition();
more exactly:
Code: Select all
virtual core::matrix4 getRelativeTransformation() const
{
core::matrix4 mat;
mat.setRotationDegrees(RelativeRotation);
mat.setTranslation(RelativeTranslation);
if (RelativeScale != core::vector3df(1,1,1))
{
core::matrix4 smat;
smat.setScale(RelativeScale);
mat *= smat;
}
return mat;
}
Code: Select all
virtual core::matrix4 getRelativeTransformation() const
{
core::matrix4 mat;
if (RelativeRotation != core::vector3df(0,0,0))
mat.setRotationDegrees(RelativeRotation);
mat.setTranslation(RelativeTranslation);
if (RelativeScale != core::vector3df(1,1,1))
{
core::matrix4 smat;
smat.setScale(RelativeScale);
mat *= smat;
}
return mat;
}
sin,cos,transformations and lot's of operations if the node isn't rotated.
Normaly the update for relativetransformation sould be made only in:
setPosition
setRotation
setScale functions.
Fix code
in ISceneNode.h add and modify:
Code: Select all
protected:
//! relative transformation of the node.
core::matrix4 RelativeTransformation;
Code: Select all
//! Returns the relative transformation of the scene node.
//! The relative transformation is stored internally as 3 vectors:
//! translation, rotation and scale. To get the relative transformation
//! matrix, it is calculated from these values.
//! \return Returns the relative transformation matrix.
virtual core::matrix4 getRelativeTransformation() const
{
return RelativeTransformation;
}
Code: Select all
//! Sets the rotation of the node. This only modifies
//! the relative rotation of the node.
//! \param roation: New rotation of the node in degrees.
virtual void setRotation(const core::vector3df& rotation)
{
RelativeRotation = rotation;
RelativeTransformation.setRotationDegrees(RelativeRotation);
//not sure if need it
if (RelativeScale != core::vector3df(1,1,1))
{
core::matrix4 smat;
smat.setScale(RelativeScale);
RelativeTransformation*= smat;
}
}
Code: Select all
virtual void setPosition(const core::vector3df& newpos)
{
RelativeTranslation = newpos;
RelativeTransformation.setTranslation(RelativeTranslation);
//not sure if need it
if (RelativeScale != core::vector3df(1,1,1))
{
core::matrix4 smat;
smat.setScale(RelativeScale);
RelativeTransformation *= smat;
}
}
Code: Select all
//! Sets the scale of the scene node.
//! \param scale: New scale of the node
virtual void setScale(const core::vector3df& scale)
{
RelativeScale = scale;
core::matrix4 smat;
smat.setScale(RelativeScale);
RelativeTransformation*= smat;
}
Code: Select all
//! Constructor
ISceneNode( ISceneNode* parent, ISceneManager* mgr, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f,
1.0f, 1.0f))
: IsVisible(true), ID(id), Parent(parent), SceneManager(mgr),
AutomaticCullingEnabled(true), DebugDataVisible(false),
TriangleSelector(0), RelativeTranslation(position),
RelativeRotation(rotation), RelativeScale(scale)
{
if (Parent)
Parent->addChild(this);
//new update relative pozition
RelativeTransformation.setRotationDegrees(RelativeRotation);
RelativeTransformation.setTranslation(RelativeTranslation);
core::matrix4 smat;
smat.setScale(RelativeScale);
RelativeTransformation*= smat;
updateAbsolutePosition();
}
Code: Select all
//! updates the absolute position based on the relative and the parents position
virtual void updateAbsolutePosition()
{
if (Parent) AbsoluteTransformation =
Parent->getAbsoluteTransformation() * RelativeTransformation;
else
AbsoluteTransformation = RelativeTransformation;
}
setVissble(true) ... node first apears on old pozition an then jump to new pozition no more).