Is it possible to quickly rotate images in B3D?
Real Time 2D Rotating
Blitz3D Forums/Blitz3D Beginners Area/Real Time 2D Rotating This was taken from game programming for teens
Graphics 800,600 ;Set up AutoMidHandle and BackBuffer() AutoMidHadle True Setbuffer backbuffer() ;Images ;Load yourimage that will be rotated yourimage=loadimage("yourimage.bmp") ;CONSTANTS ;How many rotations do you want total Const rotations = 16 ;Create the rotation array Dim imagearray(rotations) ;For all of the rotations you want, copy the spaceship image and routate it the correct amount of degrees For frame=0 to rotations-1 imagearray(frame) = copyimage(yourimage) rotateimage imagearray(frame), frame*360/rotations Next Print "Press Left to rotate conter-clockwise and right to rotate clockwise," print "Press Esc to exit." ;Begin at frame 0 (facing upward) frame=0 ;MAIN LOOP while not keydown(1) ;Clear the screen cls ;Rotate the ship left if use presses left If Keydown(203) ;Decrement frame by 1 (thus rotating it left frame=frame-1 ;If the frame count is less the 0,put it back at the max value of the array if frame<0 frame=rotations - 1 endif ;Rotate the ship right if user presses right elseif keydown(205) ;Increment frame by 1 (thus rotating it right) frame=frame+1 ;If the frame gets to big, set it to the first frame (0) If frame >= rotations frame=0 endif endif drawimage imagearray(frame),400,300 flip ;Wait for a while Delay 50 Wend
-
Since your using b3d, maybe you could use a texture instead:
Graphics3D 800, 600, 0, 2 SetBuffer BackBuffer() tex = CreateTexture(256, 256, 1, 8) Rect 0, 0, 256, 256 For i = 0 To 20 x1 = Rand(256) y1 = Rand(256) x2 = Rand(256) y2 = Rand(256) Color 0, 0, Rand($FFFFFF) Line x1, y1, x2, y2 Next CopyRect 0, 0, 256, 256, 0, 0, BackBuffer(), TextureBuffer(tex) camera = CreateCamera() MoveEntity camera, 0, 0, -2 cube = CreateCube() ScaleEntity cube, 1, 1, 0.01 EntityTexture cube, tex Repeat RotateEntity cube, 0, 0, MilliSecs() / 10.0 RenderWorld() Flip 0 Until KeyHit(1) End
Thanks guys, I'll try your ideas...
@Cyberspy
I've been testing your method and I got it to work without functions in my code.
@Everyone
How can I define arrays and constants as global so I can use them in functions?
I've been testing your method and I got it to work without functions in my code.
@Everyone
How can I define arrays and constants as global so I can use them in functions?
I think you can use Constants in functions just like globals, not sure about arrays though.
Okay, thanks for the tip. I'm almost positive that arrays don't work in functions (unless they're somehow defined as global).
In my program, the compiler ignores rotating the image--but still draws it in the default position.
In my program, the compiler ignores rotating the image--but still draws it in the default position.
B3D does actually support local arrays. Just use square brackets, a la array[10]. However, this type of array can only be one dimensional.
B3D does actually support local arrays...
Man, I'm glad you posted - I'd gotten it into my head that 'blitz arrays' could only be used in types. RTFM, Sledge!
Okay, I'll report back if I have more problems.
Man, I'm glad you posted - I'd gotten it into my head that 'blitz arrays' could only be used in types. RTFM, Sledge!
Heh - to be fair, I dont think blitz arrays are even in the manual. :) I also forgot to mention you need to use the Local keyword when defining blitz arrays, so it should actually be 'Local array[10]'. :)