-
Postów
56 -
Dołączył
-
Ostatnia wizyta
Typ zawartości
Profile
Forum
Wydarzenia
Odpowiedzi opublikowane przez Marcin1147
-
-
Nadal kupa.
Gdy direction=0 wtedy grafika porusza się w prawo, gdy dam np. 45 to wtedy staje w miejscu :(
-
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.
-
Yyy, to jest mój kod tylko skrócony?
Nic się nie zmieniło.
-
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!
-
No, dzięki :P
EDIT:
Siedziba PM-Games:
-
Siedziba YYG (wiem, nie mam talentu):
-
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!
-
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);
}
-
Sory, pomyłka:
obj2.x=x+lengthdir_x(32,obj1.direction);
obj2.y=y+lengthdir_y(32,obj1.direction);
-
obj2.x=lengthdir_x(32,obj1.direction);
obj2.y=lengthdir_y(32,obj1.direction);
??
-
-
Super, teraz już wszystko wiem! Rozwiązałeś wszystkie moje problemy + problem głodu na ziemi oraz problem bezrobocia! Super! Znakomicie... :(
-
// //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!
-
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);
}
-
Brakuje mi jeszcze lengthdirów do C++, kiedyś widziałem to na GMClanie ale teraz nie mogę znaleźć!
-
We wszystkich funkcjach operatorów wywala takie coś:
Attempting to return a reference to local variable 'temp'
-
Jezu, dzięki PsichiX że wytrzymałeś tyle czasu z takim noobem jak ja ^_^
Dam znać czy działa, i jeszcze raz dzięki.
-
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 :(
-
Czekaj, a co mam w takim razie wstawić w miejsce i_co_teraz(); aby przerobić ten hmm "wektor" spowrotem na ball->direction ?
-
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(); }
-
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?
-
A w jakiej bibliotece jest ten typ vec2, vec3 - bo chyba nie w standardowych :P
-
Przepraszam, ale ten kod to chyba do 3d, bo skąd ja mam w 2d wziąć coś takiego jak Z? :P
-
A odbijanie się od powierzchni płaskiej tzn. leci na ścianę pod kątem 45, odbija się i odlatuje od ściany pod kątem 135? :P
E: Jeżeli to jednak niemożliwe poprosiłbym cię o podanie tego wektora odbicia bo w googlach jakoś nic nie mogę znaleźć: http://www.google.pl/search?q=wektor+odbicia
GM'owe direction i speed
w C, C++
Opublikowano
Dobra, już działa.