SRL Archive - Reflection Development

World3DToScreen/TileToMSEx


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;

Naike

2010-11-30 15:02:56

If my memory serves me correct, I'm sure we didn't do that to break scripts.

Narcle

2010-11-30 15:37:23

From: Naike
If my memory serves me correct, I'm sure we didn't do that to break scripts.


EH? It wouldn't break anything…

mormonman you should mention that this way its possible (if we manage it) to then use World3DToScreen for models.

mormonman

2010-11-30 17:22:25

From: Narcle
EH? It wouldn't break anything…

mormonman you should mention that this way its possible (if we manage it) to then use World3DToScreen for models.


Ya, but this function isn't quite working for me with models at the moment.
@Naike - it doesn't break anything.

Bad Boy JH

2010-11-30 17:27:30

wait, we are getting models soon? Sweet!

Shuttleu

2010-11-30 18:47:51

From: Bad Boy JH
wait, we are getting models soon? Sweet!


if so then that means we can get precise positions for things like doors and part-tile items, right?

~shut

Sir R. M8gic1an

2010-11-30 21:32:30

I'm completely lost in whatever use this might have…

~RM

mormonman

2010-11-30 22:43:04

From: Sir R. Magician
I'm completely lost in whatever use this might have…

~RM


The Runetek5 engine uses 3D points to describe a certain point on the screen. This allows for the proper use of those points, instead of using the pixel offsets that are in the current TileToMSEx. The model class in the runescape client uses 3D points to describe where the vertices of the many model triangles are located.

Cstrike

2010-11-30 22:52:04

Would TileToMSEx change? Or would all the stuff remain the same (based on the above post)

pyroryan

2010-11-30 23:05:36

From: Bad Boy JH
wait, we are getting models soon? Sweet!


Not that I'm aware of.

Cstrike

2010-11-30 23:10:54

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)

mormonman

2010-12-01 00:14:13

From: cstrike
Would TileToMSEx change? Or would all the stuff remain the same (based on the above post)


TileToMSEx is the same.

Cstrike

2010-12-01 00:19:36

From: mormonman
TileToMSEx is the same.


From: cstrike
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)


Would it fix this? Ideally one line, though it's not a big deal if it isnt.

mormonman

2010-12-01 00:52:12

From: cstrike
Would it fix this? Ideally one line, though it's not a big deal if it isnt.


Post the function for finding the boundaries.