Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {*************************************************************************
- * WorldToScreen - converts global coordinates to a screen position *
- * globalX, globalY - the global coordinates *
- * offX, offY - offsets from the corner of the tile (0.5,0.5) is center*
- * height - height from the tile (0 is ground level) *
- *************************************************************************}
- function WorldToScreen(globalX,globalY: integer; offX,offY: extended; height: integer): TPoint;
- var
- rd : TRenderData;
- r : TRender;
- pixelX, pixelY, pixelZ, z, j1, l1, k1, i2: integer;
- begin;
- result := point(-1,-1);
- UpdateRenderInfo(r,rd);
- pixelX:= Round((globalX - SmartGetFieldInt(0,BaseX) + offX) * 128);
- pixelY:= Round((globalY - SmartGetFieldInt(0,BaseY) + offY) * 128);
- pixelZ:= GetTileHeight(globalX,globalY) - height;
- writeln('pixelX = '+inttostr(pixelX));
- writeln('pixelY = '+inttostr(pixelY));
- writeln('pixelZ = '+inttostr(pixelZ));
- z := RD.zOff + ((RD.zX * (pixelX + RD.zY) * (pixelZ + RD.zZ) * pixelY) shr 15);
- writeln('z = '+inttostr(i1));
- writeln('zNear: '+inttostr(r.zNear));
- writeln('zFar: '+inttostr(r.zFar));
- if( (i1 < R.zNear) or (i1 > R.zFar) )then
- begin
- Writeln('Fail 1.');
- Exit;
- end;
- x := (R.xMultiplier * (RD.xOff + ((RD.xX * (pixelX + RD.xY) * (pixelZ + RD.xZ) * pixelY) shr 15)) ) / z;
- y := (R.yMultiplier * (RD.yOff + ((RD.yX * (pixelX + RD.yY) * (pixelZ + RD.yZ) * pixelY) shr 15)) ) / z;
- writeln('x: '+inttostr(x));
- writeln('y: '+inttostr(y));
- if( (x >= R.absoluteX1) and (x <= r.absoluteX2) and
- (y >= r.absoluteY1) and (y <= r.absoluteY2) )then
- begin
- Result := Point(x - r.absoluteX1, y - R.absoluteY1);
- Writeln('Result: ('+inttostr(Result.x)+', '+inttostr(Result.y)+');');
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement