Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SkillsXP

Pages: [1]
1
General / Re: Better way to create particle as Vertex Array?
« on: February 05, 2015, 04:54:13 pm »
.h


#ifndef PIXELCREATOR_HPP
#define PIXELCREATOR_HPP

#include <SFML\Graphics.hpp>
#include <iostream>




class Pixelcreator
{
public:
        Pixelcreator(int posx, int posy);

        ~Pixelcreator();

        void update(float frametime);
        void handle();
        void render(sf::RenderWindow *rnd);

        const bool getIsAlive() {return mIsAlive;};
        void setIsAlive(bool alive) {mIsAlive = alive;};

        void set_alpha(float alph) {iAlpha = alph;};

        const float get_ran_0() {return ran[0];};
        void set_ran_0(float ran_0) {ran[0] = ran_0;};

        const float get_ran_1() {return ran[1];};
        void set_ran_1(float ran_1) {ran[1] = ran_1;};

        const bool get_bX() {return bX;};
        const bool get_bY() {return bY;};

        void set_bX(bool bx) {bX = bx;};
        void set_bY(bool by) {bY = by;};

        const float get_grav() {return fgrav;};
        void set_grav(float gra) {fgrav = gra;};

        void set_default() {ran[0] = defran_0; ran[1] = defran_1;};

        const float get_horiz() {return horiz;};
        void set_horiz(float hor) {horiz = hor;};

        const float get_vert() {return vert;};
        void set_vert(float ver) {vert = ver;};

private:
       
        sf::VertexArray pointmap;
        sf::Clock *pClock;

        float defran_0, defran_1;


       
       
        bool mIsAlive;
        int iAlpha;
        int irand;
        float horiz;
        float vert;
        float fgrav;
        bool bX;
        bool bFirst;
        bool bY;
        float ran[];

         

        float rand_dom(float a, float b)
        {
        return ((b-a)*((float)rand()/RAND_MAX))+a;
        }
};


#endif

 



.cpp


#include "pixelcreator.h"

using namespace std;

template<class T>
        T roundd(T a){
                if(a < 0.05) {a = 0;
                }
                else
                if(a > 0.05 && a < 0.01)        {a = 0.01;
                }
                else
                if(a > 0.01 && a < 0.02)        {a = 0.02;
                }
                else
                if(a > 0.02 && a < 0.03)        {a = 0.03;
                }
                else
                if(a > 0.03 && a < 0.04)        {a = 0.04;
                }
                else
                if(a > 0.04 && a < 0.05)        {a = 0.05;
                }
                else
                if(a > 0.05 && a < 0.06)        {a = 0.06;
                }
                else
                if(a > 0.06 && a < 0.07)        {a = 0.07;
                }
                else
                if(a > 0.07 && a < 0.08)        {a = 0.08;
                }
                else
                if(a > 0.08 && a < 0.09)        {a = 0.09;
                }

                T fin = a;
                return fin;
        }

Pixelcreator::Pixelcreator(int posx, int posy){
       
       
        pClock = new sf::Clock();
        pClock->restart();


        setIsAlive(true);

        horiz = posx;
        vert = posy;

        for( int a = 0; a < 16; a++) {

                pointmap.append(sf::Vertex(sf::Vector2f((a % 4) + horiz, (a / 4) + vert), sf::Color::Green));
                pointmap[a].color.a = static_cast<sf::Uint8>(iAlpha);
        }

        fgrav = 0.04;

        ran[0] = roundd(ran[0]);
        ran[1] = roundd(ran[1]);

        ran[0] = rand_dom(0.0,0.09);
        ran[1] = rand_dom(0.0,0.09);

        defran_0 = ran[0];
        defran_1 = ran[1];

                switch(rand() % 4)
                {
                case 0: iAlpha = 255; break;
                case 1: iAlpha = 220; break;
                case 2: iAlpha = 160; break;
                case 3: iAlpha = 150; break;
                case 4: iAlpha = 90; break;
               
                }

                irand = rand() % 4;

                switch(irand)
                {
                case 0: bX = true; bY = false; break;
                case 1: bX = false; bY = true; break;
                case 2: bX = false; bY = false; break;
                case 3: bX = true; bY = true; break;
                }


                bFirst = true;
               


}

Pixelcreator::~Pixelcreator(){
        delete pClock;
        pClock = nullptr;

}

void Pixelcreator::update(float frametime){


        if(ran[1] <= 0 && bY == false) {bY == true;};

        if(horiz >= 634 ) {bX = false;}
        if(vert >= 634  ) {bY = false;}
       
        if(horiz <= 0 ) {bX = true;}
        if(vert <= 0  ) {bY = true;}

        if(bX == true)  horiz += ran[0];
        if(bX == false) horiz -= ran[0];
       
        if(bY == false) { vert -= (ran[1] = ran[1]-((ran[1]*1.5)+fgrav)*frametime);}
        if(bY == true)  vert += ran[1];

        if(pClock->getElapsedTime().asMilliseconds() > 50.f) {iAlpha -= 5; pClock->restart();}
        if(iAlpha < 0) iAlpha = 0;
       

        for(int u = 0; u != 16; u++){
                //pointmap.append(sf::Vertex(sf::Vector2f((u % 4) + horiz, (u / 4) + vert), sf::Color::Green));
                pointmap[u].position.x = (u % 4) + horiz;
                pointmap[u].position.y = (u / 4) + vert;
                pointmap[u].color.a = static_cast<sf::Uint8>(iAlpha);

        }

        if(iAlpha <= 20) setIsAlive(false);
        if(getIsAlive() == false) pointmap.clear();

}

void Pixelcreator::handle(){

}

void Pixelcreator::render(sf::RenderWindow *rnd){
        rnd->draw(pointmap);

}


 

2
General / Better way to create particle as Vertex Array?
« on: February 04, 2015, 05:03:52 pm »
does someone know any solution to create pixel as vertex array?
I used them but if I create more than 1024 pixel, it will get slower.

I made 4x4 Pixel, so I have 64 Particle and I becomes slower

3
General / Re: Vertex Array crash at the release executable
« on: February 04, 2015, 04:06:19 pm »
SOLVED! I can't explain concrete how I did that.

I switcht this code in the class definition up to the first of the code, after I have define the horizontal and the vertical integer.

4
General / Re: Vertex Array crash at the release executable
« on: February 04, 2015, 03:57:09 pm »
This is confusing. If I break the code at 2 it can start in the executable. Then everything works fine.

My debugger doesn't work too good at the moment, but he is telling me this:


1> pixelcreator.obj: error LNK2001: unresolved external symbol "" public: static class sf :: Color const sf :: Color :: Green "" (Green Color @ @ @ sf@@2V12 B?).
1> pixelcreator.obj: error LNK2001: unresolved external symbol "" public: static class sf :: Render States const sf :: Render States :: Default "" (Default Render States @ @ @ sf@@2V12 B?).

 

5
General / Vertex Array crash at the release executable
« on: February 04, 2015, 03:26:37 pm »

for( int a = 0; a < 16; a++) {

pointmap.append(sf::Vertex(sf::Vector2f((a % 4) + horiz, (a / 4) + vert), sf::Color::Green));

}

 

If I start this code in c++, it works fine.
If I start the executable in the release folder, the loop works up to 2, so if a is equal to 2, the program crashs

Does someone know why this is happening?

Pages: [1]