Hi Ilan,
Could you elaborate a little more on this..
* Do the 3 squares represent 3 images?
** which image is the center or the original?
*** are the 45o and the 135o just examples or the rotation step?
**** does an image rotate around itself or around another image (center or original image axis)... etc..
Formula of degree between two coordinates:
Degree=Arctan[ (y2-y1) / (x2-x1) ]
Degree may be radian for some language so you may have to convert degree it.
thanx strat could you tell me please if y2/x2 is the image that should rotate and y1/x1 is the moving image??
can I use arctan in b4a??
x2,y2 is moving image's coordinates. B4a has most of trigonometry functions so you can use Arctan. Look here:
http://www.b4x.com/android/help/core.html#keywords_atan
You can use both degree or radian. It depends on which library you will use to rotate an image.
sorry i dont understand how can i link the camera head with the line head.
dont i need for that to know the degrees?
Formula of degree between two coordinates:
Degree=Arctan[ (y2-y1) / (x2-x1) ]
Degree may be radian for some language so you may have to convert degree it.
Dim deg As Int
For i = 0 To enemiesize -1
deg = ATanD((ball.Top-enemies(i).top) / (ball.Left-enemies(i).Left))
enemiescnv(i).DrawBitmapRotated(enemybmp(enemies(i).enemybmpstr),Null,enemiesrect,deg)'newdeg)
Next
#Region Project Attributes
#ApplicationLabel: JHSImageFlip
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim timer1 As Timer
End Sub
Sub Globals
Dim x,y As Float
Dim radius,angle,degree As Float
Private Button1 As Button
Private ImageView1 As ImageView
Dim c As Canvas
Dim rect1 As Rect
Private ImageView2 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
timer1.Initialize("timer1",50)
timer1.Enabled=True
angle=0
radius=40%x
rect1.Initialize(0,0,ImageView1.Width,ImageView1.Height)
ImageView1.Left=50%x-(ImageView1.Width/2)
ImageView1.Top=50%y-(ImageView1.Height/2)
ImageView2.Left=101%x
End Sub
Sub Activity_Resume
End Sub
Sub timer1_Tick
Dim c As Canvas
c.Initialize(ImageView1)
angle=angle+1
'If angle>359 Then
' angle=0
'End If
x=CosD(angle)*radius+50%x
y=SinD(angle)*radius+50%y
Button1.Left=x
Button1.Top=y
degree = ATan2D((Button1.Top-ImageView1.top), (Button1.Left-ImageView1.Left))
c.DrawBitmapRotated(ImageView2.Bitmap,Null,rect1,degree)
Log(degree)
End Sub
Try this:
B4X:deg = ATan2D(ball.Top - enemies(i).to), ball.Left - enemies(i).Left)
Klaus's code works better. Thank you Klaus.
Here example I tried. It works now.
B4X:#Region Project Attributes #ApplicationLabel: JHSImageFlip #VersionCode: 1 #VersionName: 'SupportedOrientations possible values: unspecified, landscape or portrait. #SupportedOrientations: portrait #CanInstallToExternalStorage: False #End Region #Region Activity Attributes #FullScreen: False #IncludeTitle: True #End Region Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. Dim timer1 As Timer End Sub Sub Globals Dim x,y As Float Dim radius,angle,degree As Float Private Button1 As Button Private ImageView1 As ImageView Dim c As Canvas Dim rect1 As Rect Private ImageView2 As ImageView End Sub Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("main") timer1.Initialize("timer1",50) timer1.Enabled=True angle=0 radius=40%x rect1.Initialize(0,0,ImageView1.Width,ImageView1.Height) ImageView1.Left=50%x-(ImageView1.Width/2) ImageView1.Top=50%y-(ImageView1.Height/2) ImageView2.Left=101%x End Sub Sub Activity_Resume End Sub Sub timer1_Tick Dim c As Canvas c.Initialize(ImageView1) angle=angle+1 'If angle>359 Then ' angle=0 'End If x=CosD(angle)*radius+50%x y=SinD(angle)*radius+50%y Button1.Left=x Button1.Top=y degree = ATan2D((Button1.Top-ImageView1.top), (Button1.Left-ImageView1.Left)) c.DrawBitmapRotated(ImageView2.Bitmap,Null,rect1,degree) Log(degree) End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?