SoftPixel Forum

Official community of the SoftPixel Engine and the SoftPixel Sandbox (REGISTRATION only with consultation with the Admin)
It is currently Wed Dec 13, 2017 10:28 pm

All times are UTC




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Rotate billboards
PostPosted: Sat Mar 01, 2014 11:06 am 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
How do I rotate billboards from class scene::Billboard()?
Because when I call "turn", it rotates around the global axis.


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sat Mar 01, 2014 1:47 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
As far as I remember, you have to rotate around the Z axis only.
When the billboard is about to be rendered, it will be rotated by the Z rotation factor.

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sat Mar 01, 2014 4:28 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Thank you :)
And btw., i didnt got the blending.
So, is there a way, i can set the "brightness", because i make smoke out of billboards and when there are too much overlapping, its almost or completly white?
And how to set alpha of billboards?

Edit: Hmm..this doesnt work (rotating around Z-Axis).
They do rotate, but only like every second they make a rotate-step instantly and in the other time they rotate smooth BACK. Idk how that could happen.


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sun Mar 02, 2014 12:07 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
There are several ways for configuring the blending. You do this via the video::MaterialStates object from your Billboard (MaterialNode::getMaterial).
See setBlendingMode and setBlending.

@your rotation problem: could you post a little code snippet?
Sounds like your Billboard has become self-employed ^^

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sun Mar 02, 2014 1:18 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
@Blending:
I dont understand blending(that is one of the cause, i quit pure opengl :D).
Do u have a sample?

@Billboard

I will post now the WHOLE code:

Code:

//Particlesystem

class particle
{
public:

    particle(vector3f position, vector3f _velocity, float _life, float _lifeMax, video::Texture* tex, float scale);
    ~particle();

    vector3f velocity;
    scene::Billboard* obj;

    float life;
    float lifeMax;
};

particle::particle(vector3f position, vector3f _velocity, float _life, float _lifeMax, video::Texture* tex, float scale)
{
    velocity = _velocity;
    life = _life;
    lifeMax = _lifeMax;

    obj = spScene->createBillboard(tex);
    obj->setPosition(dim::vector3df(position.x, position.y, position.z));
    obj->setScale(dim::vector3df(scale, scale, scale));
}

particle::~particle()
{
}

class emitter
{
public:

    emitter(char* image, float _scale, float _emitterLifetime, vector3f _velocity, vector3f _position, int _maxParticles, int _maxLifetime, int _particles_Second);
    ~emitter();

    vector3f velocity;
    vector3f rand_velocity;
    vector3f position;
    vector3f rand_position;
    vector3f gravity;

    float newParticle;
    float emitterLife;
    float emitterLifetime;
    int maxParticles;
    int maxLifetime;
    int particles_Second;

    //Draw
    video::Texture* tex;
    float scale;
    float alpha_start;
    float alpha_end;

    vector<particle> particles;

    void update(float fps);
};

emitter::emitter(char* image, float _scale, float _emitterLifetime, vector3f _velocity, vector3f _position, int _maxParticles, int _maxLifetime, int _particles_Second)
{
    tex = spRenderer->loadTexture(image); //Load the texture
    scale = _scale;

    emitterLife = 0;
    emitterLifetime = _emitterLifetime;

    velocity = _velocity;
    position = _position;

    rand_position = vector3f(0, 0, 0);
    rand_velocity = vector3f(0, 0, 0);
    gravity = vector3f(0, 0, 0);

    maxParticles = _maxParticles;
    maxLifetime = _maxLifetime;
    particles_Second = _particles_Second;

    alpha_start = 1;
    alpha_end = 1;

    newParticle = 0;
}

emitter::~emitter()
{
    while (particles.size() > 0)
    {
        spScene->removeSceneNode(particles[0].obj);
        particles.erase(particles.begin());
    }
}

void emitter::update(float fps)
{
    //Create new particles
    newParticle += particles_Second / fps;
    for (float i = 0; i < floor(newParticle); i++)
    {
        if (particles.size() >= maxParticles)
            break;
        particles.push_back(
            particle(
                vector3f(
                    rand_position.x != 0? position.x + ((rand() % 1000 * rand_position.x) / 1000) - int(rand_position.x / 2) : position.x,
                    rand_position.y != 0? position.y + ((rand() % 1000 * rand_position.y) / 1000) - int(rand_position.y / 2) : position.y,
                    rand_position.z != 0? position.z + ((rand() % 1000 * rand_position.z) / 1000) - int(rand_position.z / 2) : position.z
                ),
                vector3f(
                    rand_velocity.x != 0? velocity.x + ((rand() % 1000 * rand_velocity.x) / 1000) - int(rand_velocity.x / 2) : velocity.x,
                    rand_velocity.y != 0? velocity.y + ((rand() % 1000 * rand_velocity.y) / 1000) - int(rand_velocity.y / 2) : velocity.y,
                    rand_velocity.z != 0? velocity.z + ((rand() % 1000 * rand_velocity.z) / 1000) - int(rand_velocity.z / 2) : velocity.z
                ),
                maxLifetime,
                maxLifetime,
                tex,
                scale
            )
        );
    }
    if (newParticle > 1)
        newParticle = (int(newParticle * 1000) % 1000) / 1000;

    //Handle particles
    for (int i = 0; i < particles.size(); i++)
    {
        particles[i].life -= 1 / fps;
        if (particles[i].life <= 0)
        {
            spScene->removeSceneNode(particles[i].obj);
            particles.erase(particles.begin() + i);
            i--;
        }
        else
        {
            particles[i].velocity.x += gravity.x / fps;
            particles[i].velocity.y += gravity.y / fps;
            particles[i].velocity.z += gravity.z / fps;
            particles[i].obj->translate(dim::vector3df(particles[i].velocity.x / fps, particles[i].velocity.y / fps, particles[i].velocity.z / fps));

            //particles[i].obj->turn(dim::vector3df(0, 0, 3));

            /*float alpha = (alpha_start - alpha_end) * (particles[i].life / particles[i].lifeMax);
            particles[i].obj->getMaterial()->setAlphaReference(alpha);*/
        }
    }
}

class particlesystem
{
public:

    particlesystem();
    ~particlesystem();

    //Emitter
    vector<emitter> _emitter;
    void createEmitter(char* image, float scale, float _emitterLifetime, vector3f _velocity, vector3f _position, int _maxParticles, int _maxLifetime, int _particles_Second);

    void update(float fps);
    void clean();
};

particlesystem::particlesystem()
{
}

particlesystem::~particlesystem()
{
}

void particlesystem::update(float fps)
{
    for (int i = 0; i < _emitter.size(); i++)
    {
        _emitter[i].update(fps);
        if (_emitter[i].emitterLifetime  > 0)
        {
            _emitter[i].emitterLife += 1 / fps;
            if (_emitter[i].emitterLife >= _emitter[i].emitterLifetime)
                _emitter.erase(_emitter.begin() + i);
        }
    }
}

void particlesystem::createEmitter(char* image, float scale, float _emitterLifetime, vector3f _velocity, vector3f _position, int _maxParticles, int _maxLifetime, int _particles_Second)
{
    _emitter.push_back(graphics::emitter(image, scale, _emitterLifetime, _velocity, _position, _maxParticles, _maxLifetime, _particles_Second));
}

void particlesystem::clean()
{
    while (_emitter.size() > 0)
    {
        _emitter.erase(_emitter.begin());
    }
}



Also I dont understand, how to set the alpha of billboards, as you can see on line 146.
In line 144 is the real problem(rotating).
Hope it helps.


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sun Mar 02, 2014 3:50 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
I see you are using "setAlphaReference" in the code. Take a look at this tutorial at the section Problems with Alpha-Blending and the Depth-Buffer.

You can also download the "BlendingChart" from the SPE's download page to have an overview of all possible blending combinations.

To use the standard blending mode (as for 3D meshes) use this:
Code:
video::MaterialsStates* material = billboard->getMaterial();
material->setBlendingMode(video::BLEND_NORMAL);
material->setDiffuseAlpha(transparency); // transparency is a float in the range [0.0 .. 1.0].

Which SPE version do you have and are you able to compile the engine?

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sun Mar 02, 2014 5:24 pm 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Thanks.
I have 3.2 and never tried to compile the engine (too lazy).

And how about the rotation? Do u have any idea about the problem?


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Sun Mar 02, 2014 9:24 pm 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
That's why I wanted to know if you every compiled the engine. In that case you could make a little change if the rotation does not work correctly.
But actually using "turn(vector3df(0, 0, Z))" or "setRotation(vector3df(0, 0, Z))" should work for billboards.
I don't know what do you mean with "it rotates smooth BACK"?!

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Mon Mar 03, 2014 5:03 am 
Offline

Joined: Tue Jan 07, 2014 6:38 pm
Posts: 90
Location: Germany
Ah, sorry. I got it wrong.
They are first normally turning, like i want. But about every second, they turn in one frame back to the start-position.
Hope you could understand.
Im not the best in english :D


Top
 Profile  
 
 Post subject: Re: Rotate billboards
PostPosted: Mon Mar 03, 2014 11:29 am 
Offline
Site Admin
User avatar

Joined: Sat Jul 07, 2012 5:58 pm
Posts: 540
Location: Germany
It's not your English ;-)

But I fear you have to compile the engine to solve this problem.
You either use the new SPE 3.3 (from SVN Repository) or you compile the SPE 3.2 which you already have and fix that.

How you fix that:
In the SPE 3.3 I changed the possibility to rotate a billboard around itself by adding an extra rotation field in the "Billboard" class,
called "float BaseRotation_;".
Then you can set it with "setBaseRotation(float rotation)".

Take a look in the latest version of the spSceneBillboard.cpp file at the "updateTransformation" function.
There is a line like this:
Code:
FinalWorldMatrix_.rotateZ(BaseRotation_);

This will add the rotation around the billboard itself.

The problem you have is probably, that this rotation is currently read from the standard 3D-Vector rotation,
which is an euler rotation. Euler rotations may cause a problem which is called Gimbal Lock.

Hope I could help.
Sorry but I think the only way to fix it is, to compile the engine ;-)
But in that way, you are also able to add some other features right into the engine.

Greetings,
Lukas

_________________
My latest project:
- The XièXiè Programming Language

My hardware:
- GIGABYTE GeForce GTX 670
- Intel Core i7 (Ivy-Bridge)
- 16 GB DDR3


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group