#include <math.h>
#include <stdio.h>

// 假设的API函数，获取玩家和敌人的位置和旋转
void getPlayerPosition(float *x, float *y, float *z);
void getEnemyPosition(float *x, float *y, float *z);
void setPlayerRotation(float yaw, float pitch);

// 计算两个点之间的方向向量
void calculateDirection(float x1, float y1, float z1, float x2, float y2, float z2, float *dx, float *dy, float *dz) {
    *dx = x2 - x1;
    *dy = y2 - y1;
    *dz = z2 - z1;
}

// 将方向向量转换为旋转角度
void directionToRotation(float dx, float dy, float dz, float *yaw, float *pitch) {
    *yaw = atan2(dx, dz) * (180.0 / M_PI); // Yaw (左右旋转)
    *pitch = atan2(dy, sqrt(dx * dx + dz * dz)) * (180.0 / M_PI); // Pitch (上下旋转)
}

// 主函数，实现强锁自瞄
void lockOnEnemy() {
    float playerX, playerY, playerZ;
    float enemyX, enemyY, enemyZ;
    float dx, dy, dz;
    float yaw, pitch;

    // 获取玩家和敌人的位置
    getPlayerPosition(&playerX, &playerY, &playerZ);
    getEnemyPosition(&enemyX, &enemyY, &enemyZ);

    // 计算方向向量
    calculateDirection(playerX, playerY, playerZ, enemyX, enemyY, enemyZ, &dx, &dy, &dz);

    // 将方向向量转换为旋转角度
    directionToRotation(dx, dy, dz, &yaw, &pitch);

    // 设置玩家的旋转角度
    setPlayerRotation(yaw, pitch);

    // 打印调试信息
    printf("Player Position: (%f, %f, %f)\n", playerX, playerY, playerZ);
    printf("Enemy Position: (%f, %f, %f)\n", enemyX, enemyY, enemyZ);
    printf("Yaw: %f, Pitch: %f\n", yaw, pitch);
}

int main() {
    // 模拟游戏循环
    while (1) {
        lockOnEnemy();
        // 模拟游戏循环的延迟
        sleep(1);
    }
    return 0;
}