'* perspectiverotate.bas
'* a flippin' special by codeguy
'* this version does not use a temporary drawing surface, so it saves memory and perhaps time.
SumRotxyz
AS CurrentRotations
AddRotxyz
AS CurrentRotations
AddDstXYZ
AS AccumInteger
IRec.Filename = "donut with code sprinkles.png" '"c:\gaia.jpg" '* "e:\qb64\test.jpg" '*"c:\qb64\v091\qb64\test.jpg" '*
IRec.handle
= _LOADIMAGE(Clean$
(IRec.Filename
), 32)IRec.Ends.x
= _WIDTH(IRec.handle
)IRec.starts.x = 1
IRec.starts.y = 1
IRec.starts.z = 1
IRec.scale = 1
IRec.intensity = 1
IRec.transparentcolor
= _RGB(0, 128, 129)IRec.CurrentFrame = 0
IRec.NumFramesX = 1
IRec.NumFramesY = 1
IRec.NumFramesZ = 1
Scrn.Filename = ":video_output"
Scrn.Ends.x
= _WIDTH(Scrn.handle
)Scrn.starts.x = 1
Scrn.starts.y = 1
Scrn.starts.z = 1
Scrn.transparentcolor = -1
Scrn.CurrentFrame = 0
Scrn.NumFramesX = 1
Scrn.NumFramesY = 1
Scrn.NumFramesZ = 1
Rxyz.AddRotxyz.rx = 3.1415926535 / 17
Rxyz.SumRotxyz.rx = 0
Rxyz.AddRotxyz.ry = 3.1415926535 / 37
Rxyz.SumRotxyz.ry = 0
Rxyz.AddRotxyz.rz = 3.1415926535 / 47
Rxyz.SumRotxyz.rz = 0
Rxyz.Origins.x
= _WIDTH(Scrn.handle
) / 2Rxyz.AddDstXYZ.x = 7
Rxyz.Origins.y
= _HEIGHT(Scrn.handle
) / 2Rxyz.AddDstXYZ.y = 7
Rxyz.Origins.z = IRec.Ends.z
Rxyz.AddDstXYZ.z = 7
CONST holybejeezusthisisgonnabecomplex%
= -1 imageclearmethod% = darthwho%
FrameCount = 0
DIM LastRotateRec
AS RotateRec
DIM LastPicRec
AS ImageRec
FrameCount = FrameCount + 1
_TITLE Clean$
(IRec.Filename
) + STR$(FrameCount \
(etime#
- stime#
)) + STR$(FrameCount
* IRec.Ends.y
* IRec.Ends.x \
(etime#
- stime#
)) FrameCount = 0
stime# = etime#
LINE (Scrn.starts.x
, Scrn.starts.y
)-(Scrn.Ends.x
, Scrn.Ends.y
), _RGBA(127, 129, 131, 127), BF
'*effect courtesy of darthwho CASE holybejeezusthisisgonnabecomplex%
LastRotateRec = Rxyz
LastPicRec = IRec
LastScrn = Scrn
LastPicRec.intensity
= NOT (IRec.intensity
) AND 1 PerspectiveRotate LastPicRec, LastScrn, LastRotateRec.Origins, LastRotateRec.SumRotxyz
PerspectiveRotate IRec, Scrn, Rxyz.Origins, Rxyz.SumRotxyz
'IRec.intensity = (IRec.intensity + 1) MOD 2
Rxyz.SumRotxyz.rx = Rxyz.SumRotxyz.rx + Rxyz.AddRotxyz.rx
IF Rxyz.Origins.x
< Scrn.starts.x
THEN Rxyz.AddDstXYZ.x = -Rxyz.AddDstXYZ.x
Rxyz.AddDstXYZ.x = -Rxyz.AddDstXYZ.x
Rxyz.Origins.x = Rxyz.Origins.x + Rxyz.AddDstXYZ.x
Rxyz.SumRotxyz.ry = Rxyz.SumRotxyz.ry + Rxyz.AddRotxyz.ry
IF Rxyz.Origins.y
< Scrn.starts.y
THEN Rxyz.AddDstXYZ.y = -Rxyz.AddDstXYZ.y
Rxyz.AddDstXYZ.y = -Rxyz.AddDstXYZ.y
Rxyz.Origins.y = Rxyz.Origins.y + Rxyz.AddDstXYZ.y
Rxyz.SumRotxyz.rz = Rxyz.SumRotxyz.rz + Rxyz.AddRotxyz.rz
IF Rxyz.Origins.z
< Scrn.starts.z
THEN Rxyz.AddDstXYZ.z = -Rxyz.AddDstXYZ.z
Rxyz.AddDstXYZ.z = -Rxyz.AddDstXYZ.z
Rxyz.Origins.z = Rxyz.Origins.z + Rxyz.AddDstXYZ.z
SUB PerspectiveRotate
(irec
AS ImageRec
, scrn
AS ImageRec
, Oxyz
AS Point3d
, rxyz
AS CurrentRotations
) zscale! = Oxyz.z / (scrn.Ends.z - scrn.starts.z + 1)
FOR i%
= irec.starts.y
TO irec.Ends.y
newx# = (i% * srz#)
FOR j%
= irec.starts.x
TO irec.Ends.x
IF p&
<> irec.transparentcolor
THEN PSET (COS(rxyz.rx
) * (newx#
) * zscale!
+ Oxyz.x
, SIN(rxyz.rx
) * (j%
* srz#
+ i%
) * zscale!
+ Oxyz.y
), p&
PSET (COS(rxyz.rx
) * (newx#
) * zscale!
+ Oxyz.x
, SIN(rxyz.rx
) * (j%
* srz#
+ i%
) * zscale!
+ Oxyz.y
), 0 IF p&
<> irec.transparentcolor
THEN PSET (COS(rxyz.rx
) * (newx#
* irec.scale
) * zscale!
+ Oxyz.x
, SIN(rxyz.rx
) * ((j%
* srz#
+ i%
) * irec.scale
) * zscale!
+ Oxyz.y
), p&
PSET (COS(rxyz.rx
) * (newx#
* irec.scale
) * zscale!
+ Oxyz.x
, SIN(rxyz.rx
) * ((j%
* srz#
+ i%
) * irec.scale
) * zscale!
+ Oxyz.y
), 0
FUNCTION Clean$
(x$
) 'sorta like ltrim$(rtrim$(x$)) b% = b% - 1
a% = a% + 1
Clean$
= MID$(x$
, a%
, b%
- a%
+ 1)