I'm trying to get Doom-style 8 direction sprite rotation that changes its sprite depending on the camera and the forward vector of the entity just like this video here: https://www.youtube.com/watch?v=DBRR_ZVWtMk&t=13s.
I've searched around the internet for a solution and I have found some people that have been having the same issue but no one that really got it working like it should. I managed to figure out how to get the entity to change it's sprite depending on the camera view angle but I can't figure out how to account for the entity's own forward vector. I would assume you'll use the CrossProduct but I'm not sure...
Here is my code:
// Get the angles
angles = entity->parms.axis.ToAngles();
// Compute the forward and normalize
forward = angles.ToForward();
// Compute the direction and normalize
direction = rg.renderView.origin - entity->parms.origin;
direction.Normalize();
odVec3 point = forward.Cross(direction); (NOT USED)
// Compute the yaw angle
yaw = RAD2DEG(odMath::ATan(direction.y, direction.x));
yaw = odMath::AngleNormalize360(yaw);
if (yaw >= 22.5f && yaw < 67.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_1");
else if (yaw >= 67.5f && yaw < 112.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_2");
else if (yaw >= 112.5f && yaw < 157.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_3");
else if (yaw >= 157.0f && yaw < 202.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_4");
else if (yaw >= 202.5f && yaw < 247.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_5");
else if (yaw >= 247.5f && yaw < 292.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_6");
else if (yaw >= 292.5f && yaw < 337.5f)
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_7");
else
entity->parms.skin = R_FindSkin("skins/sdk/rotation/angle_0");
157.0f
should be157.5f
. \$\endgroup\$