Skocz do zawartości

Marcin1147

Użytkownicy
  • Postów

    56
  • Dołączył

  • Ostatnia wizyta

Odpowiedzi opublikowane przez Marcin1147

  1. Chodzi mi o to, że ten kod nie działa jak powinien, zwyczajnie "świruje".

    Chciałem aby ktoś znający się trochę na matmie napisał algorytm działający jak GM'owe speed i direction bo mój kod (z pierwszego postu) zwyczajnie nie działa.

  2. Potrzebuje poruszania się po danym kącie z daną szybkością. Kiedyś miałem taki fajny kod, ok. 4 linie ale działał perfekcyjnie. Z pamięci napisałem takie coś, ale nie działa tak jakbym chciał. Kod jest do C#, ale mi chodzi o sam algorytm.

     angle = direction * (180/Math.PI);
    dx = Math.Cos(angle) * speed;
    dy = Math.Sin(angle) * speed;
    x += (int)dx;
    y += (int)dy;

     

    Pomóżcie!

  3. Ok, działa - a jak zwolnić pamięć po tworzonej co sekundę strukturze?

    O, tej:

    void co_sekunde()

    {

    MotionBlur tmp;

    tmp.x=krolik->x;

    tmp.y=krolik->y;

    tmp.alpha=150;

    motion.push_front(tmp);

    }

    Chodzi mi o coś w stylu:

    void co_sekunde()

    {

    MotionBlur tmp;

    tmp.x=krolik->x;

    tmp.y=krolik->y;

    tmp.alpha=150;

    motion.push_front(tmp);

    memory_free(tmp);

    }

     

    EDIT: BTW. Dzięki, wygląda nawet nieźle!

    motionb.png

  4. Hej, pisze sobie w C++ taki, hmmm... Motion-blur, i mam problem z usuwaniem iteratorów z listy STL w pętli "for".

    Gdy zakomentuję pogrubioną linijkę kodu to blur działa, gdy nie to dostaje errora: list iterator is not incrementable... Pomóżcie.

     

    struct MotionBlur

    {

    float x,y;

    int alpha;

    };

     

    list<MotionBlur> motion;

    list<MotionBlur>::iterator motion_iter;

    HTEXTURE syf;

    hgeSprite *objmotion;

    void co_sekunde()

    {

    MotionBlur tmp;

    tmp.x=krolik->x;

    tmp.y=krolik->y;

    tmp.alpha=150;

    motion.push_front(tmp);

    }

    for(motion_iter=motion.begin();motion_iter!=motion.end();motion_iter++)

    {

    if((*motion_iter).alpha>0)

    {

    (*motion_iter).alpha-=10;

    objmotion->SetColor(ARGB( (*motion_iter).alpha ,255,255,255),-1);

    objmotion->Render( (*motion_iter).x , (*motion_iter).y);

    }

    else motion.erase(motion_iter);

    }

  5. //
    //Początek GMCLAN'owego syfa
    //
    struct vec2
    {
    float x;
    float y;
    };
    
    //Operatory wektor<->float
    vec2 operator* (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x*v2;
    temp.y=v1.y*v2;
    return(temp);
    };
    
    vec2 operator/ (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x/v2;
    temp.y=v1.y/v2;
    return(temp);
    };
    
    vec2 operator+ (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x+v2;
    temp.y=v1.y+v2;
    return(temp);
    };
    
    vec2 operator- (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x-v2;
    temp.y=v1.y-v2;
    return(temp);
    };
    //Operatory wektor<->float
    
    //Operatory wektor<->wektor
    vec2 operator* (vec2& v1,vec2& v2)
    {
    vec2 temp;
    temp.x=v1.x*v2.x;
    temp.y=v1.y*v2.y;
    return(temp);
    };
    
    vec2 operator/ (vec2& v1,vec2& v2)
    {
    vec2 temp;
    temp.x=v1.x/v2.x;
    temp.y=v1.y/v2.y;
    return(temp);
    };
    
    vec2 operator+ (vec2& v1,vec2& v2)
    {
    vec2 temp;
    temp.x=v1.x+v2.x;
    temp.y=v1.y+v2.y;
    return(temp);
    };
    
    vec2 operator- (vec2& v1,vec2& v2)
    {
    vec2 temp;
    temp.x=v1.x-v2.x;
    temp.y=v1.y-v2.y;
    return(temp);
    };
    //Operatory wektor<->wektor
    
    float dot(vec2 v1,vec2 v2)
    {
    return v1.x*v2.x+v1.y*v2.y;
    }
    
    vec2 reflect(vec2 I,vec2 N)
    {
    return I-2.0f*N*dot(N,I);
    }
    
    int point_direction(int x1, int x2, int y1, int y2)
    {
    return(atan2(y2-y1,x2-x1) * 180 / M_PI);
    }
    
    double degtorad( double alfa) { return alfa * M_PI / 180; }
    
    float lengthdir_x(float len,float dir)
    {
    return(cos(degtorad(dir))*len);
    }
    
    float lengthdir_y(float len,float dir)
    {
    return(sin(degtorad(dir))*len);
    }
    
    void Odbij()
    {
    
    vec2 srodek;
    srodek.x=12;
    srodek.y=12;
    
    vec2 kierunek,nowy;
    kierunek.x=lengthdir_x(ball->direction,1);
    kierunek.y=lengthdir_y(ball->direction,1);
    nowy=reflect(srodek,kierunek);
    ball->direction=point_direction(0,0,nowy.x,nowy.y);
    }
    //
    //Koniec GMCLAN'owego syfa
    //

    Ten sam error!

  6. Ok, mam takie coś:

    //
    //Początek GMCLAN'owego syfa
    //
    struct vec2
    {
    float x;
    float y;
    };
    
    vec2 operator* (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x*v2;
    temp.y=v1.y*v2;
    return(temp);
    };
    
    vec2 operator/ (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x/v2;
    temp.y=v1.y/v2;
    return(temp);
    };
    
    vec2 operator+ (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x+v2;
    temp.y=v1.y+v2;
    return(temp);
    };
    
    vec2 operator- (vec2& v1,float& v2)
    {
    vec2 temp;
    temp.x=v1.x-v2;
    temp.y=v1.y-v2;
    return(temp);
    };
    
    float dot(vec2 v1,vec2 v2)
    {
    return v1.x*v2.x+v1.y*v2.y;
    }
    
    vec2 reflect(vec2 I,vec2 N)
    {
    return I-2.0f*N*dot(N,I);
    }
    
    int point_direction(int x1, int x2, int y1, int y2)
    {
    return(atan2(y2-y1,x2-x1) * 180 / M_PI);
    }
    
    double degtorad( double alfa) { return alfa * M_PI / 180; }
    
    float lengthdir_x(float len,float dir)
    {
    return(cos(degtorad(dir))*len);
    }
    
    float lengthdir_y(float len,float dir)
    {
    return(sin(degtorad(dir))*len);
    }
    
    void Odbij()
    {
    
    vec2 srodek;
    srodek.x=12;
    srodek.y=12;
    
    vec2 kierunek,nowy;
    kierunek.x=lengthdir_x(ball->direction,1);
    kierunek.y=lengthdir_y(ball->direction,1);
    nowy=reflect(srodek,kierunek);
    ball->direction=point_direction(0,0,nowy.x,nowy.y);
    }
    //
    //Koniec GMCLAN'owego syfa
    //

     

    I wywala: Illegal structure operation tutaj:

    vec2 reflect(vec2 I,vec2 N)

    {

    return I-2.0f*N*dot(N,I);

    }

  7. struct vec2
    {
    float x;
    float y;
    };
    
    //pomijam operatory
    
    vec2 reflect(vec2 I,vec2 N)
    {
    return I-2.0f*N*dot(N,I);
    {
    
    float dot(vec2 v1,vec2 v2)
    {
    return v1.x*v2.x+v1.y*v2.y;
    }
    
    int point_direction(int x1, int x2, int y1, int y2)
    {
    atan2(y2-y1,x2-x1) * 180 / M_PI; //korzystam z math.h
    }
    
    void Odbij()  
    {
    vec2 kierunek,nowy;
    kierunek.x=lengthdir_x(ball->direction,1);
    kierunek.y=lengthdir_y(ball->direction,1);
    nowy=reflect(12,kierunek);
    ball->direction=point_direction(nowy.x,nowy.y, -co tutaj-, -co tutaj-);
    }

    A co z x2, y2 :(

  8. Czekaj, uaktualnie mój cudowny kod:

    struct vec2
    {
    float x;
    float y;
    };
    
    vec2 reflect(vec2 I,vec2 N)
    {
    return I-2.0f*N*dot(N,I);
    {
    
    float dot(vec2 v1,vec2 v2)
    {
    return v1.x*v2.x+v1.y*v2.y;
    }
    
    void Odbij()  
    {
    vec2 kierunek,nowy;
    kierunek.x=lengthdir_x(ball->direction,1);
    kierunek.y=lengthdir_y(ball->direction,1);
    nowy=reflect(12,kierunek);
    i_co_teraz();
    }

  9. OMG dobra, to łatwiejsze niż myślałem :P

    Wiesz Vec kojarzy mi się z wektorem, takim co ma pkt. zaczepienia kierunek, wartość i inne syfy :P

     

    Ale skoro I to promień padania, to jak mam go wyrazić w X i Y?

×
×
  • Dodaj nową pozycję...