ReadySteadyGo
01-22-2012, 06:46 AM
http://i.imgur.com/PanUV.png
program new;
{$DEFINE SMART}
{$i SRL/SRL.simba}
{$i SRL/SRL/misc/paintsmart.simba}
const
TILE = 12;
type
TPoint3D = record
x, y, z: Extended;
end;
TRotation = TPoint3D;
ATPoint3D = Array of TPoint3D;
TMatrix = record
Data: Array of Extended;
end;
TScene = record
TilePosition, PlayerTile, CameraPosition: TPoint3D;
TileRotation, CameraRotation: TRotation;
end;
function Point3D(x, y, z: Extended): TPoint3D;
begin
Result.x := x;
Result.y := y;
Result.z := z;
end;
function Rotation(xpheta, ypheta, zpheta: Extended): TRotation;
begin
Result.x := xpheta;
Result.y := ypheta;
Result.z := zpheta;
end;
function Multiply_Point3D_Matrix3x3(p: TPoint3D; m: TMatrix): TPoint3D;
begin
Result.x := (m.Data[0] * p.x) + (m.Data[1] * p.y) + (m.Data[2] * p.z);
Result.y := (m.Data[3] * p.x) + (m.Data[4] * p.y) + (m.Data[5] * p.z);
Result.z := (m.Data[6] * p.x) + (m.Data[7] * p.y) + (m.Data[8] * p.z);
end;
procedure TranslatePoints3D(var p: ATPoint3D; v: TPoint3D);
var
Len, i: Integer;
begin
Len := Length(p);
for i := 0 to Len-1 do
p[i] := Point3D(p[i].x + v.x, p[i].y + v.y, p[i].z + v.z);
end;
function RotatePoints3D(Points: ATPoint3D; rp: TPoint3D; r: TRotation): Array of TPoint3D;
var
m: TMatrix;
Len, i: Integer;
begin
R.x := radians(R.x);
R.Y := radians(R.Y);
r.z := radians(R.z);
SetLength(m.Data, 9);
m.Data := [Cos(r.y)*Cos(r.z), -Cos(r.x)*Sin(r.z) + Sin(r.x)*Sin(r.y)*Cos(r.z), Sin(r.x)*Sin(r.z)+Cos(r.x)*Sin(r.y)*Cos(r.z),
Cos(r.y)*Sin(r.z), Cos(r.x)*Cos(r.z) + Sin(r.x)*Sin(r.y)*Sin(r.z), -Sin(r.x)*Cos(r.z)+Cos(r.x)*Sin(r.y)*Sin(r.z),
-Sin(r.y), Sin(r.x)*Cos(r.y), Cos(r.x)*Cos(r.y)];
Len := Length(Points);
SetLength(Result, Len);
TranslatePoints3D(Points, Point3D(-rp.x, -rp.y, -rp.z));
for i := 0 to Len-1 do
Result[i] := Multiply_Point3D_Matrix3x3(Points[i], m);
TranslatePoints3D(Result, rp);
end;
function PerspectiveProject(p: ATPoint3D; cPos:TPoint3D): TPointArray;
var
Len, i: Integer;
begin
Len := Length(p);
SetLength(Result, Len);
for i := 0 to Len-1 do
begin
if (p[i].z - cPos.z) < 1 then
begin
Result[i].x:= 0;
Result[i].y:= 0;
Exit;
end;
Result[i].x:= Round((p[i].x - cPos.x) * {((512/2) / Tan(33/2))}864 / (p[i].z - cPos.z));
Result[i].y:= Round((p[i].y - cPos.y) * {(512/2) / Tan(33/2)}864 / (p[i].z - cPos.z));
end;
end;
function ProjectTile(var x, y: Integer; s: TScene; DrawColor{-1 to not Draw}: Integer): Boolean;
var
_3DPoints: ATPoint3D;
_2DPoints: TPointArray;
Len, i: Integer;
MSBox: TBox;
tp: TPoint3D;
begin
if DrawColor = -1 then
Len := 2
else
Len := 6;
SetLength(_3DPoints, Len);
SetLength(_2DPoints, Len);
tp := s.TilePosition;
_3DPoints[0] := s.PlayerTile;
_3DPoints[1] := Point3D(tp.x + TILE/2, tp.y + TILE, tp.z + TILE/2); // Center of input Tile
if DrawColor <> -1 then
begin
_3DPoints[2] := Point3D(tp.x + TILE, tp.y + TILE, tp.z);
_3DPoints[3] := Point3D(tp.x, tp.y + TILE, tp.z);
_3DPoints[4] := Point3D(tp.x + TILE, tp.y + TILE, tp.z + TILE);
_3DPoints[5] := Point3D(tp.x, tp.y + TILE, tp.z + TILE);
end;
TranslatePoints3D(_3DPoints, Point3D(-TILE/2, -TILE/2, 0));
_3DPoints := RotatePoints3D(_3DPoints, _3DPoints[0], s.TileRotation);
_3DPoints := RotatePoints3D(_3DPoints, s.CameraPosition, s.CameraRotation);
_2DPoints := PerspectiveProject(_3DPoints, s.CameraPosition);
MSBox.X1 := MSX1;
MSBox.Y1 := MSY1;
MSBox.X2 := MSX2;
MSBox.Y2 := MSY2;
for i := 0 to Len-1 do
begin
_2DPoints[i].x := _2DPoints[i].x + {(511/2) + 4}260;
_2DPoints[i].y := _2DPoints[i].y + {(334/2) - 4}163;
if not PointInBox(_2DPoints[i], MSBox) then
begin
Result := False;
Exit;
end;
end;
if DrawColor <> -1 then
begin
SMART_DrawLine(False, _2DPoints[2], _2DPoints[3], DrawColor);
SMART_DrawLine(False, _2DPoints[4], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[3], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[2], _2DPoints[4], DrawColor);
end;
x := _2DPoints[1].x;
y := _2DPoints[1].y;
Result := True;
end;
function GetTile(var x, y: Integer; tx, tz: Integer; Draw: Boolean; Color: Integer): Boolean;
var
s: TScene;
begin
with s do
begin
PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);
end;
if (not Draw) then
Color := -1;
Result := ProjectTile(x, y, s, Color);
end;
function MMToMSTileEx(var x, y: Integer; MMx, MMy:Integer; Draw: Boolean; Color: Integer): Boolean;
var
p: TPoint;
begin
p := RotatePoint(Point(MMx, MMy), rs_GetCompassAngleRadians, MMCX, MMCY);
p.x := Floor((p.x - (MMCX - 33)) / 4.0);
p.y := 17- Floor((p.y - (MMCY - 37)) / 4.0);
Result := GetTile(x, y, p.x, p.y, Draw, Color);
end;
function MMToMSTile(var x, y: Integer; MMx, MMy: Integer): Boolean;
begin
Result := MMToMSTileEx(x, y, MMx, MMy, False, 0);
end;
procedure ProjectTiles;
var i, j, x, y: Integer;
begin
for i := 0 to 16 do
for j := 0 to 16 do
GetTile(x, y, i, j, True, clGray);
end;
function GetMMDotsOnMS2(WhatDot: String; ShowGrid:Boolean): TPointArray;
var
x, y, Len, i, c, Col: Integer;
p: TPointArray;
begin
if ShowGrid then
ProjectTiles;
p := GetMiniMapDots(WhatDot);
case LowerCase(WhatDot) of
'npc', 'n', 'yellow', 'y': Col := clYellow;
'item', 'i', 'red', 'r': Col := clRed;
'player', 'p', 'white', 'w': Col := clWhite;
'friend', 'f', 'green', 'g': Col := clFriend;
'team', 't', 'blue', 'b', 'cape': Col := clBlue;
end;
Len := Length(p);
SetLength(Result, Len);
c := 0;
for i := 0 to Len-1 do
if MMToMSTileEx(x, y, p[i].x, p[i].y, True, Col) then
begin
Result[i] := Point(x, y);
Inc(c);
end;
SetLength(Result, c);
end;
var x, y: Integer;
begin
ClearDebug();
Smart_Server := 1;
SetupSRL();
SMART_SetupDebug;
SMART_ClearCanvas;
GetMMDotsOnMS2('Red', True);
GetMMDotsOnMS2('White', False);
GetMMDotsOnMS2('Yellow', False);
end.
program new;
{$DEFINE SMART}
{$i SRL/SRL.simba}
{$i SRL/SRL/misc/paintsmart.simba}
const
TILE = 12;
type
TPoint3D = record
x, y, z: Extended;
end;
TRotation = TPoint3D;
ATPoint3D = Array of TPoint3D;
TMatrix = record
Data: Array of Extended;
end;
TScene = record
TilePosition, PlayerTile, CameraPosition: TPoint3D;
TileRotation, CameraRotation: TRotation;
end;
function Point3D(x, y, z: Extended): TPoint3D;
begin
Result.x := x;
Result.y := y;
Result.z := z;
end;
function Rotation(xpheta, ypheta, zpheta: Extended): TRotation;
begin
Result.x := xpheta;
Result.y := ypheta;
Result.z := zpheta;
end;
function Multiply_Point3D_Matrix3x3(p: TPoint3D; m: TMatrix): TPoint3D;
begin
Result.x := (m.Data[0] * p.x) + (m.Data[1] * p.y) + (m.Data[2] * p.z);
Result.y := (m.Data[3] * p.x) + (m.Data[4] * p.y) + (m.Data[5] * p.z);
Result.z := (m.Data[6] * p.x) + (m.Data[7] * p.y) + (m.Data[8] * p.z);
end;
procedure TranslatePoints3D(var p: ATPoint3D; v: TPoint3D);
var
Len, i: Integer;
begin
Len := Length(p);
for i := 0 to Len-1 do
p[i] := Point3D(p[i].x + v.x, p[i].y + v.y, p[i].z + v.z);
end;
function RotatePoints3D(Points: ATPoint3D; rp: TPoint3D; r: TRotation): Array of TPoint3D;
var
m: TMatrix;
Len, i: Integer;
begin
R.x := radians(R.x);
R.Y := radians(R.Y);
r.z := radians(R.z);
SetLength(m.Data, 9);
m.Data := [Cos(r.y)*Cos(r.z), -Cos(r.x)*Sin(r.z) + Sin(r.x)*Sin(r.y)*Cos(r.z), Sin(r.x)*Sin(r.z)+Cos(r.x)*Sin(r.y)*Cos(r.z),
Cos(r.y)*Sin(r.z), Cos(r.x)*Cos(r.z) + Sin(r.x)*Sin(r.y)*Sin(r.z), -Sin(r.x)*Cos(r.z)+Cos(r.x)*Sin(r.y)*Sin(r.z),
-Sin(r.y), Sin(r.x)*Cos(r.y), Cos(r.x)*Cos(r.y)];
Len := Length(Points);
SetLength(Result, Len);
TranslatePoints3D(Points, Point3D(-rp.x, -rp.y, -rp.z));
for i := 0 to Len-1 do
Result[i] := Multiply_Point3D_Matrix3x3(Points[i], m);
TranslatePoints3D(Result, rp);
end;
function PerspectiveProject(p: ATPoint3D; cPos:TPoint3D): TPointArray;
var
Len, i: Integer;
begin
Len := Length(p);
SetLength(Result, Len);
for i := 0 to Len-1 do
begin
if (p[i].z - cPos.z) < 1 then
begin
Result[i].x:= 0;
Result[i].y:= 0;
Exit;
end;
Result[i].x:= Round((p[i].x - cPos.x) * {((512/2) / Tan(33/2))}864 / (p[i].z - cPos.z));
Result[i].y:= Round((p[i].y - cPos.y) * {(512/2) / Tan(33/2)}864 / (p[i].z - cPos.z));
end;
end;
function ProjectTile(var x, y: Integer; s: TScene; DrawColor{-1 to not Draw}: Integer): Boolean;
var
_3DPoints: ATPoint3D;
_2DPoints: TPointArray;
Len, i: Integer;
MSBox: TBox;
tp: TPoint3D;
begin
if DrawColor = -1 then
Len := 2
else
Len := 6;
SetLength(_3DPoints, Len);
SetLength(_2DPoints, Len);
tp := s.TilePosition;
_3DPoints[0] := s.PlayerTile;
_3DPoints[1] := Point3D(tp.x + TILE/2, tp.y + TILE, tp.z + TILE/2); // Center of input Tile
if DrawColor <> -1 then
begin
_3DPoints[2] := Point3D(tp.x + TILE, tp.y + TILE, tp.z);
_3DPoints[3] := Point3D(tp.x, tp.y + TILE, tp.z);
_3DPoints[4] := Point3D(tp.x + TILE, tp.y + TILE, tp.z + TILE);
_3DPoints[5] := Point3D(tp.x, tp.y + TILE, tp.z + TILE);
end;
TranslatePoints3D(_3DPoints, Point3D(-TILE/2, -TILE/2, 0));
_3DPoints := RotatePoints3D(_3DPoints, _3DPoints[0], s.TileRotation);
_3DPoints := RotatePoints3D(_3DPoints, s.CameraPosition, s.CameraRotation);
_2DPoints := PerspectiveProject(_3DPoints, s.CameraPosition);
MSBox.X1 := MSX1;
MSBox.Y1 := MSY1;
MSBox.X2 := MSX2;
MSBox.Y2 := MSY2;
for i := 0 to Len-1 do
begin
_2DPoints[i].x := _2DPoints[i].x + {(511/2) + 4}260;
_2DPoints[i].y := _2DPoints[i].y + {(334/2) - 4}163;
if not PointInBox(_2DPoints[i], MSBox) then
begin
Result := False;
Exit;
end;
end;
if DrawColor <> -1 then
begin
SMART_DrawLine(False, _2DPoints[2], _2DPoints[3], DrawColor);
SMART_DrawLine(False, _2DPoints[4], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[3], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[2], _2DPoints[4], DrawColor);
end;
x := _2DPoints[1].x;
y := _2DPoints[1].y;
Result := True;
end;
function GetTile(var x, y: Integer; tx, tz: Integer; Draw: Boolean; Color: Integer): Boolean;
var
s: TScene;
begin
with s do
begin
PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);
end;
if (not Draw) then
Color := -1;
Result := ProjectTile(x, y, s, Color);
end;
function MMToMSTileEx(var x, y: Integer; MMx, MMy:Integer; Draw: Boolean; Color: Integer): Boolean;
var
p: TPoint;
begin
p := RotatePoint(Point(MMx, MMy), rs_GetCompassAngleRadians, MMCX, MMCY);
p.x := Floor((p.x - (MMCX - 33)) / 4.0);
p.y := 17- Floor((p.y - (MMCY - 37)) / 4.0);
Result := GetTile(x, y, p.x, p.y, Draw, Color);
end;
function MMToMSTile(var x, y: Integer; MMx, MMy: Integer): Boolean;
begin
Result := MMToMSTileEx(x, y, MMx, MMy, False, 0);
end;
procedure ProjectTiles;
var i, j, x, y: Integer;
begin
for i := 0 to 16 do
for j := 0 to 16 do
GetTile(x, y, i, j, True, clGray);
end;
function GetMMDotsOnMS2(WhatDot: String; ShowGrid:Boolean): TPointArray;
var
x, y, Len, i, c, Col: Integer;
p: TPointArray;
begin
if ShowGrid then
ProjectTiles;
p := GetMiniMapDots(WhatDot);
case LowerCase(WhatDot) of
'npc', 'n', 'yellow', 'y': Col := clYellow;
'item', 'i', 'red', 'r': Col := clRed;
'player', 'p', 'white', 'w': Col := clWhite;
'friend', 'f', 'green', 'g': Col := clFriend;
'team', 't', 'blue', 'b', 'cape': Col := clBlue;
end;
Len := Length(p);
SetLength(Result, Len);
c := 0;
for i := 0 to Len-1 do
if MMToMSTileEx(x, y, p[i].x, p[i].y, True, Col) then
begin
Result[i] := Point(x, y);
Inc(c);
end;
SetLength(Result, c);
end;
var x, y: Integer;
begin
ClearDebug();
Smart_Server := 1;
SetupSRL();
SMART_SetupDebug;
SMART_ClearCanvas;
GetMMDotsOnMS2('Red', True);
GetMMDotsOnMS2('White', False);
GetMMDotsOnMS2('Yellow', False);
end.