dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Arktangenss

 
dev.gamez.lv Forum Index -> Matemātika un fizika
View previous topic :: View next topic  
Author Message
Himself
Indago dalībnieks
Indago dalībnieks


Joined: 13 Apr 2004
Posts: 87
Location: Rīga

PostPosted: Mon Aug 22, 2005 9:46 pm    Post subject: Arktangenss

Lieta šāda - jāuzzin lenkjis starp peles kursoru un punktu plaknē.
Ideja šāda - atrod starpību starp punktu x un y koordinātēm, x starpība ir horizontālā katete, y starpība ir vertikālā katete, hipotenūza ir attālums starp punktu un kursoru, kas nav nepieciešams, jānosaka, lenkjis starp horizontālo kateti(piekateti) un hipotenūzu, izmantoju arktangensa funckiju - tam pieskjiru y/x (starpības) pretkatetes attiecību pret piekateti. Problēma šāda - uz papīra un kalkulatora viss strādā.
Code:

void Speletajs::Parvietot(){
int x,y,xs,ys;
SDL_PumpEvents();
Uint8 pele = SDL_GetMouseState(&x,&y);

//pozx un pozy ir punkta koordinaates     
xs=x-pozx-10;  //starpiiba pa x asi 1.katete
ys=y-pozy-10;  //2.katete   

if (xs==0) return; //ar nulli nedaliit
int lenkis = atan(fabs(ys/xs)) * 180/PI; // ieguustu arkatengensa veertiibu graados, no malu attieciibu absolūtās vērtības - nepareizu veertiibu

//Sheit zimee uz ekraana
char txlen[20];   
SDL_Surface *t;
SDL_Rect klucis;
klucis.x=klucis.y=0;
SDL_Color krasa;
krasa.r=180;
krasa.g=18;
krasa.b=10;
sprintf(txlen," x:%d,y:%d,l:%d",xs,ys,lenkis);

t = TTF_RenderText_Blended(font,txlen,krasa);
SDL_BlitSurface(t, NULL, screen, &klucis); 
 
}


Ir kādam idejas, ko daru nepareizi ?
_________________
Paldies
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Mon Aug 22, 2005 10:38 pm    Post subject:

int lenkis = atan(fabs(ys/xs)) * 180/PI;
vietā iesaku lietot:
int lenkis = atan2(ys,xs) * 180/PI;
Jo atan atgriež vērtības tikai no -pi/2..+pi/2 (nāksies analizēt ys un xs zīmes), taču atan2 no -pi līdz +pi.

Kautkur te jau nedaudz senāk tika runāts par šito atan2.
Back to top
View user's profile Send e-mail
Guest






PostPosted: Tue Aug 23, 2005 9:24 am    Post subject:

Paldies!
Tagad viss strādā.
Back to top
Himself
Indago dalībnieks
Indago dalībnieks


Joined: 13 Apr 2004
Posts: 87
Location: Rīga

PostPosted: Tue Aug 23, 2005 9:25 am    Post subject:

Briesmīgi atvainojos, tas bi' es ! Wink
_________________
Paldies
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> Matemātika un fizika All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group