mormonman
2010-11-29 16:23:23
I don't know why we didn't do it like this…but here you go.
{*******************************************************************************
function World3DToScreen(xx, yy, zz: Extended): TPoint;
By: Benland100/mormonman
Description: Converts a RS 3D point to a coordinate on the screen.
*******************************************************************************}
function World3DToScreen(xx, yy, zz: Extended): TPoint;//modified TileToMSEx
var
rd : TRenderData;
r : TRender;
x, y, z: extended;
tries: integer;
label
ProcStart;
begin;
ProcStart:
EmptyRenderInfo(r, rd);
x := 0;
y := 0;
z := 0;
Inc(tries);
result:= point(-1,-1);
UpdateRenderInfo(r,rd);
z:= rd.zOff + (rd.zX * xx + rd.zY * yy + rd.zZ * zz);
if ((z < r.zMin) or (z > r.zMax)) then
exit;
x:= r.xScale * (rd.xOff + (rd.xX * xx + rd.xY * yy + rd.xZ * zz)) / z;
y:= r.yScale * (rd.yOff + (rd.yX * xx + rd.yY * yy + rd.yZ * zz)) / z;
if ((x >= r.xMin) and (x <= r.xMax) and (y >= r.yMin) and (y <= r.yMax)) then
begin
result.x:= Round(x - r.xMin);
result.y:= Round(y - r.yMin);
end else
begin
if (tries > 30)then Exit;
goto ProcStart;
end;
end;
{*******************************************************************************
function TileToMSEx(tile: TTile; offx, offy : extended; height : integer): TPoint;
By: BenLand100/mormonman
Description: Converts the global tile position, a position on that tile in the
range [(0,0), (1,1)] with (0.5, 0.5) being center and a height above
ground level to a screen location on the main screen, taking camera
position and rotation into account.
*******************************************************************************}
function TileToMSEx(tile: TTile; offx, offy : extended; height : integer) : TPoint;
var
pixelX, pixelY, pixelZ: extended;
begin
pixelX:= (tile.x - SmartGetFieldInt(0,hook_static_BaseX) + offX) * 512.0;
pixelY:= GetTileHeight(tile) - height;
pixelZ:= (tile.y - SmartGetFieldInt(0,hook_static_BaseY) + offY) * 512.0;
Result := World3DToScreen(pixelX, pixelY, pixelZ);
if not PointInBox(Result, IntToBox(MSX1, MSY1, MSX2, MSY2))then
begin
Result.x := -1;
Result.y := -1;
end;
end;
This is PaintSmart telling me what the tiles are. I told it to make a perfect box with TileToMsEx and that is what I got back (was not from this thread, this is the current Reflection)