Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:59 17 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMX(+): Three-shear Rotation using BLIT

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8604
Posted: 10:48pm 24 Jan 2017
Copy link to clipboard 
Print this post



Probably not much use but an interesting academic exercise

This code snippet uses the "three-shear" method to rotate an image. The method works for angles between -45 and 45 degrees and is explained nicely here

It could be used to rotate text to specific angles, for example to draw a compass rose, and then position the images on the screen as part of drawing a fixed background.

Option explicit
option default NONE
cls
'
' draw the image to be rotated
'
const image_width=100, image_height=100, image_left=80, image_top=80
box image_left,image_top,image_width,image_height,5,rgb(red),rgb(green)
text image_left+image_width/2,image_top+image_height/2,"A",CM,4,2,rgb(red),-1
'
'set up variables and constants
'
const xo=image_left+image_width/2,yo=image_top+image_height/2, xn=xo+400, yn=yo+200
dim float maxf=sqr(2.0)*image_width
if sqr(2.0)*image_height > maxf then maxf = sqr(2.0)*image_height
dim integer max= cint(maxf+1)/2
const rot=45.0
dim integer i,shear
dim float alpha= -tan(rad(rot/2))
dim float beta=sin(rad(rot))
print alpha,beta
'
' first shear
'
pause 4000
for i=-max to max
shear = cint(i*alpha)
blit xo-max,yo+i,xn-max+shear,yo+i,max*2,1
next i
pause 2000
'
' second shear
'
for i=-max to max
shear = cint(i*beta)
blit xn+i,yo-max,xn+i,yn-max+shear,1,max*2
next i
pause 2000
'
' third shear
'
for i=-max to max
shear = cint(i*alpha)
blit xn-max,yn+i,xo-max+shear,yn+i,max*2,1
next i
pause 2000
Edited by matherp 2017-01-26
 
Cremo
Newbie

Joined: 21/07/2015
Location: Italy
Posts: 34
Posted: 07:50am 25 Jan 2017
Copy link to clipboard 
Print this post

Very interesting.

Pietro
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 05:10pm 25 Jan 2017
Copy link to clipboard 
Print this post

Thanks Peter for giving good examples on how to use the new features we have been given..! I had no idea that the BLIT function could be used in this way... Never herd of "tree shear" or some of the other methods you have used in the passed... I love your knowledge base of maths and how you share code and much of your time..!

Big "tip of the hat" to you fine Sir..!!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024