Results 1 to 5 of 5

Thread: image wrap-round

  1. #1

    image wrap-round

    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

  2. #2

    I've done it now

    I worked out how to do it using copyrect.

    Code:
    // 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

  3. #3

    image wrap-round

    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.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  4. #4

    thanks

    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.

  5. #5

    image wrap-round

    Yep, it had stars when I downloaded it.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •