SRL Archive - OSR Help

TPA rotation


riwu

2012-10-17 00:43:18

EDIT: i managed to figure out most stuffs, thanks everyone that helped :)


Also there appears to have small empty spaces after rotation, probably because the rotate function isn't perfect? Is there anyway i can prevent/fill up these?

The last problem i have is with debugging:

Even if i change to a lighter color, the drawing will still cover up the spots completely. Is there anyway to make it 'transparent'? Drawing box will not work because you can't draw a diagonal box!

Olly

2012-10-17 08:50:21

I've always wanted to know this aswell, if its possible to draw something % transparent.

Also there is a findgaps tpa function but I have no clue what it does haha.

riwu

2012-10-17 08:58:48

From: Ollybest
I've always wanted to know this aswell, if its possible to draw something % transparent.

Also there is a findgaps tpa function but I have no clue what it does haha.

Yeah i've explored that too, the comment says it's only horizontal, not really sure what that means. On second thought might as well read the source and try it, could potentially work.

RotatePoints seems to be very accurate though not sure why it isn't filled up after rotating, could be just SMART not able to display it correctly.

J J

2012-10-17 09:10:12

Zyt3x has something where he drawed semi-transparant: http://villavu.com/vb/showthread.php?t=57502 last post.
Just tried it and it gives some errors after a short while but you can see the idea. There are some gaps in there because of the rounding after rotating.

I'm not sure why you need to take the negative angle but I believe it has something to do with the way radians work. Not sure what the best way is to fill the gaps, FindGapsTPA might work as Olly mentioned or FloodFillTPA. Possibly splitting it and doing some stuff then might work.

Another way of drawing the boxes is by using SMART_DrawLine and calculate all the points that need to connect.

Nebula

2012-10-17 09:43:49

Lets say the compass is facing east, and you want it to be as if the compass was north. RotatePoint(s) rotates clockwise, so rotating by east(90), will put you at 180, which is south not north. You must rotate by the negative to "cancel out" the original offset, otherwise you are just doubling the angle.

litoris

2012-10-17 09:51:03

Don't get bothered about the negative sign, just use it that way.
You get holes in the TPA because your box consisted of points that form vertical and horizontal lines, when you rotate, you rotate the lines and the areas between the line intersections become visible.(that's how I explain it, and it seems to be correct if you look at the images closely)
To eliminate it, use FindGapsTPA with minpixels set as 1. Then, use MergeATPAWrap on that result so that all the gaps are in one TPA(the original result is an array of gaps, ie an ATPA because each gap would consist of multiple points if minpixels wasn't 1). Finally, use CombineTPA to get full boxes as the result.
As for transparency, I have no idea. :(

riwu

2012-10-17 09:56:17

From: Nebula
Lets say the compass is facing east, and you want it to be as if the compass was north. RotatePoint(s) rotates clockwise, so rotating by east(90), will put you at 180, which is south not north. You must rotate by the negative to "cancel out" the original offset, otherwise you are just doubling the angle.

Nope RotatePoints rotate anticlockwise, rs_GetCompassAngleRadians retrieve the angle anticlockwise too. I've been experimenting with them for the past few days, was working as expected for my other rotate functions but this is strangely the reverse of what i thought it would be.


From: J J
Zyt3x has something where he drawed semi-transparant: http://villavu.com/vb/showthread.php?t=57502 last post.
Just tried it and it gives some errors after a short while but you can see the idea. There are some gaps in there because of the rounding after rotating.

I'm not sure why you need to take the negative angle but I believe it has something to do with the way radians work. Not sure what the best way is to fill the gaps, FindGapsTPA might work as Olly mentioned or FloodFillTPA. Possibly splitting it and doing some stuff then might work.

Another way of drawing the boxes is by using SMART_DrawLine and calculate all the points that need to connect.

Zyt3x's function looks hopeful, will have to read it slowly. SetTransparentColor doesn't work though as all it does is to remove the color completely rather than making it partially transparent.
Draw line could be a possibility by retrieving the edge of TPA then rotating them, will test it now. Thanks for the suggestion.

From: litoris
Don't get bothered about the negative sign, just use it that way.
You get holes in the TPA because your box consisted of points that form vertical and horizontal lines, when you rotate, you rotate the lines and the areas between the line intersections become visible.(that's how I explain it, and it seems to be correct if you look at the images closely)
To eliminate it, use FindGapsTPA with minpixels set as 1. Then, use MergeATPAWrap on that result so that all the gaps are in one TPA(the original result is an array of gaps, ie an ATPA because each gap would consist of multiple points if minpixels wasn't 1). Finally, use CombineTPA to get full boxes as the result.
As for transparency, I have no idea. :(

I'm pretty into trigonometry and i want to understand why things work the way they are so that i wont make conceptual mistakes with them.

Are you saying that duplicate points appear as invisible instead? I've intentionally ClearDoubleTPA to avoid duplicated ones. I'll try out the FindGapsTPA function, thanks.

Nebula

2012-10-17 10:13:14

From: riwu
Nope RotatePoints rotate anticlockwise, rs_GetCompassAngleRadians retrieve the angle anticlockwise too. I've been experimenting with them for the past few days, was working as expected for my other rotate functions but this is strangely the reverse of what i thought it would be.


If both are anticlockwise, then it still works the same way I described it. Your compass is at -90, and since rotatepoints is anticlockwise, rotating by -90 (the positive value) will rotate the point to -180. So you have to rotate by the negative value (90) to return things to how they would be if the compass was north.

tristen8878

2012-10-17 11:04:44

Hey I've been working on something similar to this but it's a rs tile grind and I am trying to get it to rotate with my compass so far got North and south working will work on each individual ones lol going to take a long time.

riwu

2012-10-19 10:10:56

From: Nebula
If both are anticlockwise, then it still works the same way I described it. Your compass is at -90, and since rotatepoints is anticlockwise, rotating by -90 (the positive value) will rotate the point to -180. So you have to rotate by the negative value (90) to return things to how they would be if the compass was north.

When compass is at west, the angle retrieved is 90 (or p/2 in rad), and RotatePoint will rotate the point by 90 anticlockwise, so the point go from north to west. Rotating it by -90 cause it to go east.
Eg.
writeln(RotatePoint(Point(0, 2), 3.142/2, 0,0));
returns (-2, 0), the negative x axis (west) which is correct.
Rotating it by -3.142/2 results in (2,0) (east), so i don't understand why i get the right box only when i rotate it by negative rs_GetCompassAngleRadians.

Anyway i tried out drawing lines today:

At good angles it draws out nicely, but it gets worse at diagonal compass. Apparently ReadySteadyGo managed to debug them nicely (http://villavu.com/forum/showthread.php?t=72985), and he create his own point rotation functions, so i'd assume that Simba's RotatePoint is flawed? Box rotation also seems to behave differently during run time despite constant compass dir.
Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint;
Begin
Result.X := Trunc(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
Result.Y := Trunc(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my));
End;

ReadySteadyGo's: (i'm not sure how a rotation requires so much addition and subtraction)
 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)];

Also just checked out FindGapsTPA, it seems to be somewhat like SplitTPA?
FindGapsTPAWrap([Point(1,1),Point(2,2),Point(12,12),Point(3,3),Point(50,50),Point(5,5)],1,ATPA);
writeln(ATPA);
debug: [[(1, 1), (2, 2), (3, 3), (5, 5)], [(12, 12)], [(50, 50)]]
I'd retrieve the exact same result with SplitTPAWrap.

Kasi

2012-10-19 10:25:57

rotate along 0, 0? and transparency works can work in a different way, give me a couple mins. ill post examples.
Edit:when i get my smart to work -.-

riwu

2012-10-19 10:29:13

From: Kasi
rotate along 0, 0? and transparency works can work in a different way, give me a couple mins. ill post examples.

Just a theoretical example. When you draw graphs in math the origin is usually (0,0), so i find it more familiar when testing angle rotation. (rather than using MSCX, MSCY etc)

Runaway

2012-10-19 10:43:50

You could always use static coords for each unrotated box's corners, store them in separate boxes/TPAs, and rotate each one around their centerpoint.

Although now that I think about it, I believe your biggest problem is going to be the z (camera height) value…

Kasi

2012-10-19 11:17:07



program new;
{$DEFINE SMART}
{$I SRL/SRL.SIMBA}
{$IFDEF SMART}
{$I SRL/SRL/MISC/SMARTGRAPHICS.SIMBA}
{$ENDIF}

function GetColorTPoint(T : TPoint) : Integer;
begin
Result := GetColor(T.x, T.y);
end;

function example() : boolean;
var
TransBox : TBox;
TPABox : TPointArray;
I, R, G, B : Integer;
begin
TransBox := IntToBox(218, 136, 307, 229);
TPAFromBoxWrap(TransBox, TPABox);

for I := 0 to High(TPABox) do
begin
ColorToRGB(GetColorTPoint(TPABox[I]), R, G, B);
SMART_DrawDot(false, TPABox[I], RGBtoColor(255, G, B));
end;
Result := True;
end;

begin
SRL_SixHourFix := True;
Smart_FixSpeed := True;
SetupSRL;
SMART_ClearCanvas();
example();
end.

Dunno how it could be made more efficient.
does smart work with java 7? :S
Edit: you can mess around with the function to get your required transparency i guess.

Olly

2012-10-19 14:29:54

From: Kasi

Dunno how it could be made more efficient.
does smart work with java 7? :S
Edit: you can mess around with the function to get your required transparency i guess.


Been looking for something like that for ages, shame its kinda slow though :/

Kasi

2012-10-19 14:34:04

From: Ollybest
Been looking for something like that for ages, shame its kinda slow though :/


it can be a lot faster i guess, one sec. or appear to be faster.

Olly

2012-10-19 14:36:49

From: Kasi
it can be a lot faster i guess, one sec. or appear to be faster.


Another problem is that because it does it pixel by pixel (ie doesnt save the whole area first) if something is animating it such as running though it will show like the whole player running down at once if you get me. Could do something like grab a bitmap of the area… then again I have no idea what im doing :P But getting all the pixels at once then "converting" them would be better.

Kasi

2012-10-19 14:37:54

From: Ollybest
Another problem is that because it does it pixel by pixel (ie doesnt save the whole area first) if something is animating it such as running though it will show like the whole player running down at once if you get me.


yer, i can place it all on a bitmap first. need to delete java again. does anyone know if smart actually works with Java 7?

Olly

2012-10-19 14:38:46

From: Kasi
yer, i can place it all on a bitmap first. need to delete java again. does anyone know if smart actually works with Java 7?


Not currently(atleast it doesnt for me), although I think you can get it running in j7 put you need to compile it yourself or something :P

Kasi

2012-10-19 15:40:39

From: Ollybest
Not currently(atleast it doesnt for me), although I think you can get it running in j7 put you need to compile it yourself or something :P


:P, just installed j7 first and then j6 after.


program new;
{$DEFINE SMART}
{$I SRL/SRL.SIMBA}
{$IFDEF SMART}
{$I SRL/SRL/MISC/SMARTGRAPHICS.SIMBA}
{$ENDIF}

function example2(X1, Y1, X2, Y2 : Integer) : boolean;
var
R, G, B, W, H, bmp : Integer;
begin
bmp := CreateBitmap(X2 - X1, Y2 - Y1);

for W := 0 to (X2 - X1) - 1 do
for H := 0 to (Y2 - Y1) - 1 do
begin
ColorToRGB(GetColor(X1 + W, Y1 + H), R, G, B);
FastSetPixel(bmp, W, H, RGBToColor(255, G, B));
end;

SMART_DrawBitmap(false, bmp, Point(X1, Y1));
freebitmap(bmp);

Result := True;
end;

begin
SRL_SixHourFix := True;
Smart_FixSpeed := True;
SetupSRL;
SMART_ClearCanvas();

example2(218, 136, 307, 229);
end.

works now, its faster too.

Olly

2012-10-19 16:20:37

Big improvement, still takes a good 300ms but that's nothing to what it was :P

riwu

2012-10-19 21:59:46

From: Runaway
You could always use static coords for each unrotated box's corners, store them in separate boxes/TPAs, and rotate each one around their centerpoint.

Although now that I think about it, I believe your biggest problem is going to be the z (camera height) value…

I'm currently storing them as TPAs, can't store them as boxes since box rotation is not possible (getting TPA bound of the rotated box will result in a much larger box as it just take the edge x and y value and fill everything)

From: Kasi
:P, just installed j7 first and then j6 after.

works now, its faster too.

Thanks for the procedure. Although as stated above i can't use boxes. I'll probably look into RSG's line drawing and try to figure out how he came up with all that math! Nevertheless good job, never knew you can make use of RGB conversion to modify color elements. Some reps for you :)

Btw Smart does work with both java 7 and 6, although java 7 has some issue that makes Smart steals focus (can be fixed by properly minimizing it though). If you have both 6&7 it will by default use 7 iirc.


Any idea what's the difference between FindGapsTPA and SplitTPA? Also i still can't figure out why i should rotate the reverse angle.

Kasi

2012-10-20 19:41:08

From: riwu
I'm currently storing them as TPAs, can't store them as boxes since box rotation is not possible (getting TPA bound of the rotated box will result in a much larger box as it just take the edge x and y value and fill everything)


erm when drawing bitmaps im sure it ignore's the black pixels. (0)

ReadySteadyGo

2012-11-18 10:26:28

From: riwu
I'm currently storing them as TPAs, can't store them as boxes since box rotation is not possible (getting TPA bound of the rotated box will result in a much larger box as it just take the edge x and y value and fill everything)


Thanks for the procedure. Although as stated above i can't use boxes. I'll probably look into RSG's line drawing and try to figure out how he came up with all that math! Nevertheless good job, never knew you can make use of RGB conversion to modify color elements. Some reps for you :)

Btw Smart does work with both java 7 and 6, although java 7 has some issue that makes Smart steals focus (can be fixed by properly minimizing it though). If you have both 6&7 it will by default use 7 iirc.


Any idea what's the difference between FindGapsTPA and SplitTPA? Also i still can't figure out why i should rotate the reverse angle.


My rotate function is for 3D, it uses matrix multiplication for the transformation.

Enslaved

2012-11-27 18:43:15

Define TPBox with the max and mins making each corner value, then apply a rotation matrix?