Et oui! il est que 6h30 du matin je sais...
Bon comme le titre l'indique, cette fonction permet de modifier la position d'un point selon un angle et une origine... cette fonction me sert pour un logiciel d'animation par squelette par exemple, elle pourrait aussi servir à faire de la physique
Code :
set display mode desktop width(),desktop height(),32,0
sync on
Type Tsquare
x1 as float
y1 as float
x2 as float
y2 as float
x3 as float
y3 as float
x4 as float
y4 as float
EndType
square as Tsquare
square.x1=screen width()/2-50
square.y1=screen height()/2-50
square.x2=screen width()/2+50
square.y2=screen height()/2-50
square.x3=screen width()/2+50
square.y3=screen height()/2+50
square.x4=screen width()/2-50
square.y4=screen height()/2+50
Global newx as float : Global newy as float : angle as integer
ox as integer
oy as integer
do
cls
rem l'origine de la rotation est le curseur de la souris
ox=mousex()
oy=mousey()
rem control de la rotation avec les clic de souris
angle=0
if mouseclick()=1 : angle=1 : endif
if mouseclick()=2 : angle=-1 : endif
rem on récupere la nouvelle position modifiée par l'angle(angle) et l'origine(ox,oy)
rem pour chaque sommets du carré
rotation_par_origine(ox,oy,square.x1,square.y1,angle) : square.x1=newx : square.y1=newy
rotation_par_origine(ox,oy,square.x2,square.y2,angle) : square.x2=newx : square.y2=newy
rotation_par_origine(ox,oy,square.x3,square.y3,angle) : square.x3=newx : square.y3=newy
rotation_par_origine(ox,oy,square.x4,square.y4,angle) : square.x4=newx : square.y4=newy
rem affichage du carré
line square.x1,square.y1,square.x2,square.y2
line square.x2,square.y2,square.x3,square.y3
line square.x3,square.y3,square.x4,square.y4
line square.x4,square.y4,square.x1,square.y1
sync
loop
rem rotation à partir d'une origine
function rotation_par_origine(ox as float,oy as float,x as float,y as float,angle as integer)
x=x-ox : y=y-oy
newx=ox+x*cos(angle)-y*sin(angle)
newy=oy+x*sin(angle)+y*cos(angle)
endfunction
Syltech
Dernière édition le 15 Jan 2009 à 06:33
|