Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.85 KB | None | 0 0
  1. {*************************************************************************
  2.  * WorldToScreen - converts global coordinates to a screen position      *
  3.  *   globalX, globalY - the global coordinates                           *
  4.  *   offX, offY - offsets from the corner of the tile (0.5,0.5) is center*
  5.  *   height - height from the tile (0 is ground level)                   *
  6.  *************************************************************************}
  7. function WorldToScreen(globalX,globalY: integer; offX,offY: extended; height: integer): TPoint;
  8. var
  9.   rd : TRenderData;
  10.   r : TRender;
  11.   pixelX, pixelY, pixelZ, z, j1, l1, k1, i2: integer;
  12. begin;
  13.   result := point(-1,-1);
  14.   UpdateRenderInfo(r,rd);
  15.  
  16.   pixelX:= Round((globalX - SmartGetFieldInt(0,BaseX) + offX) * 128);
  17.   pixelY:= Round((globalY - SmartGetFieldInt(0,BaseY) + offY) * 128);
  18.   pixelZ:= GetTileHeight(globalX,globalY) - height;
  19.  
  20.   writeln('pixelX = '+inttostr(pixelX));
  21.   writeln('pixelY = '+inttostr(pixelY));
  22.   writeln('pixelZ = '+inttostr(pixelZ));
  23.  
  24.   z := RD.zOff + ((RD.zX * (pixelX + RD.zY) * (pixelZ + RD.zZ) * pixelY) shr 15);
  25.  
  26.   writeln('z = '+inttostr(i1));
  27.   writeln('zNear: '+inttostr(r.zNear));
  28.   writeln('zFar: '+inttostr(r.zFar));
  29.  
  30.   if( (i1 < R.zNear) or (i1 > R.zFar) )then
  31.   begin
  32.     Writeln('Fail 1.');
  33.     Exit;
  34.   end;
  35.  
  36.   x := (R.xMultiplier * (RD.xOff + ((RD.xX * (pixelX + RD.xY) * (pixelZ + RD.xZ) * pixelY) shr 15)) ) / z;
  37.   y := (R.yMultiplier * (RD.yOff + ((RD.yX * (pixelX + RD.yY) * (pixelZ + RD.yZ) * pixelY) shr 15)) ) / z;
  38.  
  39.   writeln('x: '+inttostr(x));
  40.   writeln('y: '+inttostr(y));
  41.  
  42.   if( (x >= R.absoluteX1) and (x <= r.absoluteX2) and
  43.       (y >= r.absoluteY1) and (y <= r.absoluteY2) )then
  44.   begin
  45.     Result := Point(x - r.absoluteX1, y - R.absoluteY1);
  46.     Writeln('Result: ('+inttostr(Result.x)+', '+inttostr(Result.y)+');');
  47.   end;
  48. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement