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(ACanvas1, ACanvas2 : TCanvas ; W, H, x, y : integer);
Var
V, U : integer;
SRect, DRect : TRect;
begin
V := W - x;
U := H - y;

// Copy rect A into position
SRect := Rect(0, 0, V, U);
DRect := Rect(x, y, W, H);
ACanvas2.CopyRect(DRect, ACanvas1, SRect);

// Copy rect B into position
SRect.Left := V; SRect.Right := W;
DRect.Left := 0; DRect.Right := x;
ACanvas2.CopyRect(DRect, ACanvas1, SRect);

// Copy rect C into position
SRect.Top := U; SRect.Bottom := H;
DRect.Top := 0; DRect.Bottom := y;
ACanvas2.CopyRect(DRect, ACanvas1, SRect);

// Copy rect D into position
SRect.Left := 0; SRect.Right := V;
DRect.Left := x; DRect.Right := W;
ACanvas2.CopyRect(DRect, ACanvas1, SRect);
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
Yep, it had stars when I downloaded it.