Recently, i've finished my studies, and since i am a bit unenployed now, decided to get back to my hobby. I am having a trouble with my 3D project, at first, everything seemed fine, but after i started implementing "projectiles", buggs started popping up.
First of, heres the code bit that determines angle i am facing. Note that in code it should be angleZ not Y.
public static float angleX;
private float rotationSpeed;
xRel = Mouse.getDX(); // relativnes from last cursor position
if (xRel > 0)
{
angleY += rotationSpeed * xRel/2;
if (angleY >= 360)
angleY = 0;
}
if (xRel < 0)
{
if (angleY <= 0)
angleY = 360;
angleY -= rotationSpeed * (xRel * -1)/2;
}
Then theres this class
public final class Utils {
public static float angleConst = 100/90;
public static float angleMod = 0;
private static int quarter;
private static int procValue;
private static float placeHolder;
public static float normalizeAngle()
{
placeHolder = angleY + angleMod;
if (placeHolder > 360)
placeHolder -= 360;
else if (placeHolder < 0)
placeHolder += 360;
return placeHolder;
}
public static void setMows()
{
quarter = (int) (normalizeAngle() / 90.0f);
procValue = (int) (normalizeAngle() - 90 * quarter);
switch(quarter)
{
case 0:
mowX = 1 * ((procValue*angleConst)/100);
mowY = 1 - mowX;
mowX *= -1;
break;
case 1:
mowY = 1 * ((procValue*angleConst)/100);
mowX = 1 * (1 - mowY);
mowY *= -1;
mowX *= -1;
break;
case 2:
mowX = 1 * ((procValue*angleConst)/100);
mowY = 1 * (1 - mowX);
mowY *= -1;
break;
case 3:
mowY = 1 * ((procValue*angleConst)/100);
mowX = 1 - mowY;
break;
default:
break;
}
}
And when i press for example S this is what happens
case 's': angleMod = 180; setMows(); x += mowX; y += mowY; break;
Long story short, whenever i rotate myself, and press walking button, setMows is called, which sets mowX and mowY, sort of "vector" that is latter used when i make a step, to calculate my new x and y. Problem is, that this logic is bad and i need some sort of other algorithm. Here is a picture that illustrates "bad" things. It was done by standing in the midle rotating 360 and placing a "stick" on the ground. Start point is x and y, end point is x + mowX * staticNumber and y + mowY * staticNumber.
Problem is that its not
a) Circle
b) It has blind spots
Maybe someone could redirect me towards some sort of better algorythms? I am not entirely sure i am posting in propper section, tho it seems like a begginer problem.
Thanks in advance.






