1 (edited by kianoosh 2017-05-08 18:20:14)

Hi guise. Today I decided to post this topic just because get the rotation package bugs fixed and we all go fine with this awesome include.
As most of you might know, Rotation package for bgt which is created by sam tupy has a tun of nice calculations. Like calculating angles, moving based on a speceffic direction and other stuff like these. But unfortunately this package has got weird bugs that needs your experience to be fixed. Before I mention bugs, I wanna talk about a function (An integer or double which is not included in that project) and that is calculating z angle. And here is a integer that I've wrote to get this feature going:
int calculate_z_angle(double z1, double z2)
{
double z=z2-z1;
double hdeg;
if(z>0)
{
hdeg=90;
}
else if(z<0)
{
hdeg=235;
}
else if(z==0) hdeg=0;
hdeg=round(hdeg, 0);
return hdeg;
}
If you want to include this integer in your own rotation package, simpley copy this code and paste it into your rotation.bgt file. This integer needs to be used but how? As you know, we also got a string which is called calculate_x_y_string which turns the angle to string based on the direction your player is facing. But how you wanna handle z angle in that string too?
string calculate_x_y_string(double deg, double zdeg)
{
string mdeg="", hdeg="";
if(deg==0)
{
mdeg="streight in front";
}
else if(deg>0 and deg<10)
{
mdeg="very slightly to the right";
}
else if(deg>9 and deg<20)
{
mdeg="slightly off to the right";
}
else if(deg>19 and deg<40)
{
mdeg="a little ways off to the right";
}
else if(deg>39 and deg<90)
{
mdeg="a fair distance off to the right";
}
else if(deg==90)
{
mdeg="streight off to the right";
}
else if(deg>90 and deg<120)
{
mdeg="slightly behind and far off to the right";
}
else if(deg>119 and deg<150)
{
mdeg="behind and a little ways off to the right";
}
else if(deg>149 and deg<170)
{
mdeg="behind and slightly to the right";
}
else if(deg>169 and deg<180)
{
mdeg="behind and very slightly to the right";
}
else if(deg==180)
{
mdeg="streight behind";
}
else if(deg>180 and deg<190)
{
mdeg="behind and very slightly to the left";
}
else if(deg>189 and deg<200)
{
mdeg="behind and slightly to the left";
}
else if(deg>199 and deg<220)
{
mdeg="behind and a little ways off to the left";
}
else if(deg>219 and deg<240)
{
mdeg="behind and a fair distance off to the left";
}
else if(deg>239 and deg<270)
{
mdeg="slightly behind and far off to the left";
}
else if(deg==270)
{
mdeg="streight off to the left";
}
else if(deg>270 and deg<300)
{
mdeg="far off to the left";
}
else if(deg>299 and deg<320)
{
mdeg="a ways off to the left";
}
else if(deg>319 and deg<340)
{
mdeg="A little ways off to the left";
}
else if(deg>339 and deg<350)
{
mdeg="slightly off to the left";
}
else if(deg>349 and deg<=360)
{
mdeg="very slightly off to the left";
}
if(zdeg==0) hdeg="";
else if(zdeg==90) hdeg="above";
else if(zdeg==235) hdeg="below";
if(hdeg!="") return hdeg+", "+mdeg;
else if(hdeg=="") return mdeg;
return "";
}
Wanna use this string too, simply replace it with your old calculate_x_y_string.
so now here's what you're gonna do to get 3d angle of a thing.
double angle1=calculate_x_y_angle(player.x,player.y,thing.x,thing.y,player_facing); //this calculates the 2d angle between player and that object, but it is not 3d. It just supports x and y.
double angle2=calculate_z_angle(player.z,thing.z);
//We assoom we have a tts_voice veriable asigned to v. So,
v.speak("Something is "+calculate_x_y_string(angle1, angle2)+", "+get_3d_distance(player.x,player.y,player.z,thing.x,thing.y,thing.z)+" feet away"); //This will speak where the object is. Something like that:  something is infront and slightly of to the right, 115 feet(s) away. You can fix this grammer eshu but that is not going to be around here.

Now let's talk about bugs. First of all the movement have a bug or maybe a 3 forgotten lines of code. Make sure you round that vector r not to get problems with your facing and player coords.
And another bug is in the turnright function. This is the fixed code. Just a "=" is forgotten or is not placed:
double turnright(double deg, double inc)
{
deg+=inc;
if(deg>=360)
deg-=360;
if(deg==360) deg=0;
return deg;
}
And I found another bug which i still could not manage to fix it and that is, when you stay at e.g. 5, 0, 0, if you face at north east, You should not be able to walk but unfortunately you can do that. It might also doesn't play the tile sound even but you walk to your left and that is too annoying. If any of you had find a fix for this, Please comment it here as it is really needed.
Last but not least, I want the developer to pack this all codes again or if he has already fixed this bugs, post the new update into his website so noone will run to such problems.
You can also ask your questions about this package here, Me or anyone else who knows bgt will try to answer you.
Thanks for reading this long, Best regards for you all!

Thumbs up

Good evening,
well, an other nice bug is in move_3d method, which's algorithm is little bit unreal, when you are for example facing 90 degrees of z_angle and call this method, it will get you also forward. I wrote fix for this some time ago, someones probably remember that thread, I am apologizing btw for my reactions in it, they weren't my best days.
Anyway my function is here, it helped me a lot, hope it will help also someone other.

vector move_3d(double x, double y, double z, double angle, double zangle, double distance=1.0) {
double tempa=0, tempb=0;
vector r;
tempa=tempa+(distance*sine(((zangle)*pi)/180));
tempb = tempb+(distance*cosine(((zangle)*pi)/180));
r.z=z+tempa;
r.x=x+(tempb*sine(((angle)*pi)/180));
r.y=y+(tempb*cosine(((angle)*pi)/180));
return r;
}

Best regards

Rastislav

Thumbs up