get good get legendware
-
Автор темы
- #1
C++:
void Movement::FixMove(CUserCmd* cmd, ang_t& wanted_move, bool a7)
{
// Declare and initialize variables
float move_magnitude = 0.0f;
float forwardY = 0.0f, forwardZ = 0.0f, forwardX = 0.0f;
float rightY = 0.0f, rightZ = 0.0f, rightX = 0.0f;
float upZ = 1.0f;
// Copy the input wanted_move and view angles
ang_t inputAngles = wanted_move;
ang_t viewAngles = cmd->m_view_angles;
// Check if wanted_move is the same as the view angles
if (wanted_move == viewAngles)
return;
// Calculate the magnitude of movement
move_magnitude = std::sqrt((cmd->m_forward_move * cmd->m_forward_move) + (cmd->m_side_move * cmd->m_side_move));
// If there's no movement, return
if (move_magnitude == 0.0f)
return;
// Check if the local player's move type is 8 (LADDER) or 9 (NOCLIP)
if (g_cl.m_local->m_MoveType() == 8 || g_cl.m_local->m_MoveType() == 9)
return;
// Calculate forward, right, and up vectors based on input angles
vec3_t forwardVector, rightVector, upVector;
math::AngleVectors(inputAngles, &forwardVector, &rightVector, &upVector);
// Extract components of the forward vector
forwardY = forwardVector.y;
forwardZ = forwardVector.z;
// Set upZ to 1.0 if forwardVector.z is zero, otherwise calculate forwardX, forwardY, and forwardXNormalized
if (forwardVector.z != 0.0f) {
forwardZ = 0.0f;
float forwardVectorLength2D = forwardVector.length_2d();
if (forwardVectorLength2D >= 0.00000011920929f) {
forwardY = forwardVector.y * (1.0f / forwardVectorLength2D);
forwardX = forwardVector.x * (1.0f / forwardVectorLength2D);
} else {
forwardY = 0.0f;
forwardX = 0.0f;
}
}
// Extract components of the right vector
rightY = rightVector.y;
rightZ = rightVector.z;
// Set rightX and rightZ to components of the right vector
if (rightVector.z != 0.0) {
rightZ = 0.0f;
float rightVectorLength2D = rightVector.length_2d();
if (rightVectorLength2D < 0.00000011920929f) {
rightY = 0.0f;
rightX = 0.0f;
} else {
rightY = rightVector.y * (1.0f / rightVectorLength2D);
rightX = rightVector.x * (1.0f / rightVectorLength2D);
}
}
// Set upZ to 0.0 if upVector.z is small
if (upVector.z < 0.00000011920929f)
upZ = 0.0f;
// Handle special case for cmd->m_forward_move if viewAngles.z is 180.0 and a7 is false
if (viewAngles.z == 180.0 && !a7)
cmd->m_forward_move = std::abs(cmd->m_forward_move);
// Calculate vectors based on view angles
math::AngleVectors(viewAngles, &rightVector, &forwardVector, &upVector);
// Extract components of the right and forward vectors
rightZ = rightVector.z;
if (rightVector.z == 0.0f) {
rightY = rightVector.y;
rightX = rightVector.x;
} else {
rightZ = 0.0f;
float rightVectorLength2D = rightVector.length_2d();
if (rightVectorLength2D < 0.00000011920929f) {
rightY = 0.0f;
rightX = 0.0f;
} else {
rightX = rightVector.x * (1.0f / rightVectorLength2D);
rightY = rightVector.y * (1.0f / rightVectorLength2D);
}
}
float forwardZView = forwardVector.z;
if (forwardVector.z == 0.0f) {
float forwardYView = forwardVector.y;
float forwardXView = forwardVector.x;
} else {
forwardZView = 0.0f;
float forwardVectorLength2D = forwardVector.length_2d();
if (forwardVectorLength2D < 0.00000011920929f) {
float forwardYView = 0.0f;
float forwardXView = 0.0f;
} else {
float forwardXView = forwardVector.x * (1.0f / forwardVectorLength2D);
float forwardYView = forwardVector.y * (1.0f / forwardVectorLength2D);
}
}
// Set upZ to 0.0 if upVector.z is small
if (upVector.z < 0.00000011920929f)
upZ = 0.0f;
// Calculate new movement values for cmd
float rightMove = rightY * cmd->m_side_move;
float forwardMove = forwardX * cmd->m_forward_move;
float upMove = upZ * cmd->m_up_move;
cmd->m_forward_move = ((((rightMove * rightY) + (rightX * rightX)) + (rightZ * forwardYView)) + (((upMove * rightY) + (forwardMove * rightX)) + (rightMove * forwardZView))) + (((upMove * rightY) + (upMove * rightX)) + (upZ * forwardZView));
cmd->m_side_move = ((((rightMove * forwardY) + (rightX * forwardXView)) + (rightZ * forwardZView)) + (((upMove * forwardY) + (forwardMove * forwardXView)) + (rightMove * forwardZView))) + (((upMove * forwardY) + (upMove * forwardXView)) + (upZ * forwardZView));
cmd->m_up_move = ((((rightMove * 0.0f) + (rightX * 0.0f)) + (rightZ * upZ)) + (((upMove * 0.0f) + (forwardMove * 0.0f)) + (rightMove * upZ))) + (((upMove * 0.0f) + (upMove * 0.0f)) + (upZ * upZ));
}