rotated Particle nodes

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Nessie

rotated Particle nodes

Post by Nessie »

I had hooked a particle node up to a character (animated mesh node) in my game, and as the player moved around, the particle cloud followed him around...which was what I wanted. Cool!

However, when the player rotated, the shape of the particles in the cloud distorted. Admittedly, a somewhat minor bug.[/end of bug report]

After looking into a bit, I spotted some code that seemed unnecessarily complicated, which I'll point out just for the heck of it.

CParticleSystemSceneNode.cpp

Code: Select all

// Hmm, this code seems a bit wordy? (not being critical, just thinking out loud)
core::vector3df campos = camera->getAbsolutePosition();
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 = horizontal.crossProduct(view);
vertical.normalize();
I think it could actually be replaced with this, which basically involves no potentially expensive math

Code: Select all

core::matrix4 matrix = camera->getViewMatrix();
core::vector3df horizontal = matrix.getColumn(0);
core::vector3df vertical	= matrix.getColumn(1);
core::vector3df view = matrix.getColumn(2);
....assuming that this is added to matrix4.h

Code: Select all

//! Gets the specified column of the matrix, which is the camera axis in the case of a camera rotation matrix
vector3df getColumn(const s32 column) const;

inline vector3df matrix4::getColumn(const s32 column) const
{
	return vector3df(M[column], M[column+4], M[column+8]);
}
Anyway, I'll admit this doesn't fix the rotated particle node bug.. :)
Nessie
Posts: 14
Joined: Thu Apr 08, 2004 4:27 pm
Location: Madison, WI, USA

Post by Nessie »

Of course, I was looking into why the billboards don't exhibit this bug and I noticed the same thing in CBillboardSceneNode::render(). So, just by changing the 'facing camera' code with the simplified equivalent version, I noticed about a 2 fps increase in a scene that uses a lot of billboards just by making that change.

Obviously nothing drastic, but hey.

Anyway, billboards don't have the same problem because it calls:

Code: Select all

core::matrix4 mat;
driver->setTransform(video::ETS_WORLD, mat);
instead of (in CParticleSceneNode):

Code: Select all

driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
Of course, this wasn't a big surprise, however, it did mean that getting an easy fix is less easy. I suspect this is why Quake3 just does the transformations in code instead of setting up the required transformation and then letting OpenGL do the work.
"Build a man a fire and he'll be warm for the evening. Set a man on fire and he'll be warm for the rest of his life." -unknown
Post Reply