PDA

View Full Version : image wrap-round

peterbone
03-11-2003, 11:16 AM
I have a TBitmap containing an image of starts (generated randomly). I'm using it for the background in my 3d engine. When the camera rotates the background image will move to give an impression of rotation relative to the background. The bitmap is the same size as the screen, so it will have to wrap-round in x and y as it moves. I've worked out that the amount it has to move will be equal to the angle of rotation multiplied by the focal length - for x and y.
My problem is how do I do the image wrap-round. Basically I need to be able to define a point in the bitmap and create another bitmap that has that point at the center with wrap-round. I could do it with scanline (by putting the stars image in a 2D array first) but I could also do it with copyrect - there will be 9 segments of the original image to move into the correct position in the new image.
So what's the best way to do it and has anyone already got delphi code for it?

Thanks

Peter

peterbone
04-11-2003, 01:48 PM
I worked out how to do it using copyrect.

// copy a canvas to a given location on another canvas with wrap-round
// canvas' must have equal dimensions
procedure DrawWrap&#40;ACanvas1, ACanvas2 &#58; TCanvas ; W, H, x, y &#58; integer&#41;;
Var
V, U &#58; integer;
SRect, DRect &#58; TRect;
begin
V &#58;= W - x;
U &#58;= H - y;

// Copy rect A into position
SRect &#58;= Rect&#40;0, 0, V, U&#41;;
DRect &#58;= Rect&#40;x, y, W, H&#41;;
ACanvas2.CopyRect&#40;DRect, ACanvas1, SRect&#41;;

// Copy rect B into position
SRect.Left &#58;= V; SRect.Right &#58;= W;
DRect.Left &#58;= 0; DRect.Right &#58;= x;
ACanvas2.CopyRect&#40;DRect, ACanvas1, SRect&#41;;

// Copy rect C into position
SRect.Top &#58;= U; SRect.Bottom &#58;= H;
DRect.Top &#58;= 0; DRect.Bottom &#58;= y;
ACanvas2.CopyRect&#40;DRect, ACanvas1, SRect&#41;;

// Copy rect D into position
SRect.Left &#58;= 0; SRect.Right &#58;= V;
DRect.Left &#58;= x; DRect.Right &#58;= W;
ACanvas2.CopyRect&#40;DRect, ACanvas1, SRect&#41;;
end;

You can see how it turned out here
http://www.geocities.com/peter_bone_uk/engine3d
and look at the 'world' project

Alimonster
04-11-2003, 04:07 PM
That's starting to look really snazzy, mate! Maybe a few different objects are required, though -- I think the juggler may get suspicious that you're stealing all his clubs. ;)

peterbone
04-11-2003, 04:19 PM
It's just a test for my 3D rendering engine.

I forgot to say that to exit the program press esc and pressing w will toggle between wireframe and fully rendered. Pressing the arrow keys will make the camera go up,down,left,right relative to the viewing direction and left and right mouse buttons will zoom in/out.

When you downloaded it did you get the one with stars in the background? Because I uploaded the new one, with stars, but when I downloaded it to see if it had uploaded properly I got the old one - no stars.

Alimonster
04-11-2003, 04:41 PM