/
Zamar_Terrier
/
TigorEngine
Обзор
Документация
Войти
/
Zamar_Terrier
/
TigorEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Core/e_camera.c
450 строк
10 KB
Zamar_Terrier
Доработка + нововведения
06 июл 2026, 16:26
Верифицирован
06 июл 2026, 16:26
0d4ab95
Код
Авторство
О чём код?
#include "TigorEngine.h" #include "Core/e_camera.h" #include "Objects/render_texture.h" #include "Tools/e_math.h" #include "Data/e_resource_data.h" #include "wManager/manager_includes.h" extern TEngine engine; void Camera2DInit(Camera2D *cam) { memset(cam, 0, sizeof(Camera2D)); cam->scale.x = 1; cam->scale.y = 1; } void Camera3DInit(Camera3D *cam) { memset(cam, 0, sizeof(Camera3D)); cam->scale.x = 1; cam->scale.y = 1; cam->scale.z = 1; cam->view_distance = 1000; cam->view_angle = 75.0f; cam->view_near = 0.01f; cam->yaw = 90; cam->pitch = 0; cam->sensitivity = 100.0f; cam->moveSpeed = 50.0f; cam->cameraSpeed = 1.5f; cam->firstMouse = true; cam->walk = false; vec3 next_rotation; next_rotation.x = cos(90 * (M_PI / 180)) * cos(0 * (M_PI / 180)); next_rotation.y = -sin(0 * (M_PI / 180)); next_rotation.z = sin(90 * (M_PI / 180)) * cos(0 * (M_PI / 180)); next_rotation = v3_norm(next_rotation); Camera3DSetRotation(cam, next_rotation.x, next_rotation.y, next_rotation.z); } void Camera3DSetViewDistanceMain(double distance) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DSetViewDistance(&render->cam3D, distance); } void Camera3DSetViewDistance(Camera3D *cam, double distance) { cam->view_distance = distance; } void Camera3DSetViewAngleMain(double angle) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DSetViewAngle(&render->cam3D, angle); } void Camera3DSetViewAngle(Camera3D *cam, double angle) { cam->view_angle = angle; } void Camera3DSetViewNearMain(double v_near) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DSetViewNear(&render->cam3D, v_near); } void Camera3DSetViewNear(Camera3D *cam, double v_near) { cam->view_near = v_near; } void Camera2DSetRotationMain(float angle) { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera2DSetRotation(&render->cam2D, angle); } void Camera2DSetRotation(Camera2D *cam, float angle) { cam->angle = angle; } void Camera3DSetRotationMain(float x, float y, float z) { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera3DSetRotation(&render->cam3D, x, y, z); } void Camera3DSetRotation(Camera3D *cam, float x, float y, float z) { cam->rotation.x = x; cam->rotation.y = y; cam->rotation.z = z; } float Camera2DGetRotationMain() { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera2DGetRotation(&render->cam2D); } float Camera2DGetRotation(Camera2D *cam) { return cam->angle; } vec3 Camera3DGetRotationMain() { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera3DGetRotation(&render->cam3D); } vec3 Camera3DGetRotation(Camera3D *cam) { return cam->rotation; } void Camera2DSetPositionMain(float x, float y) { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera2DSetPosition(&render->cam2D, x, y); } void Camera2DSetPosition(Camera2D *cam, float x, float y) { cam->position.x = x; cam->position.y = y; } void Camera3DSetPositionMain(float x, float y, float z) { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera3DSetPosition(&render->cam3D, x, y, z); } void Camera3DSetPosition(Camera3D *cam, float x, float y, float z) { cam->position.x = x; cam->position.y = y; cam->position.z = z; } vec2 Camera2DGetPositionMain() { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera2DGetPosition(&render->cam2D); } vec2 Camera2DGetPosition(Camera2D *cam) { return cam->position; } vec3 Camera3DGetPositionMain() { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera3DGetPosition(&render->cam3D); } vec3 Camera3DGetPosition(Camera3D *cam) { return cam->position; } void Camera2DSetScaleMain(float x, float y) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera2DSetScale(&render->cam2D, x, y); } void Camera2DSetScale(Camera2D *cam, float x, float y) { cam->scale.x = x; cam->scale.y = y; } void Camera3DSetScaleMain(float x, float y, float z) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DSetScale(&render->cam3D, x, y, z); } void Camera3DSetScale(Camera3D *cam, float x, float y, float z) { cam->scale.x = x; cam->scale.y = y; cam->scale.z = z; } void Camera3DSetSensitivityMain(float senso) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DSetSensitivity(&render->cam3D, senso); } void Camera3DSetSensitivity(Camera3D *cam, float senso) { cam->sensitivity = senso; } float Camera3DGetSensitivityMain() { RenderTexture *render = (RenderTexture *)engine.main_render; return Camera3DGetSensitivity(&render->cam3D); } float Camera3DGetSensitivity(Camera3D *cam) { return cam->sensitivity; } void Camera3DMovementUpdateMain(float deltaTime) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DMovementUpdate(&render->cam3D, deltaTime); } void Camera3DMovementUpdate(Camera3D *cam, float deltaTime) { vec3 up = {0.0f, 1.0f, 0.0f}; vec3 pos = Camera3DGetPosition(cam); vec3 viewRot = Camera3DGetRotation(cam); vec3 some_pos; if (TEngineGetKeyPress(TIGOR_KEY_W)) { if (cam->walk) viewRot.y = 0; some_pos = v3_sub(pos, v3_muls(viewRot, cam->cameraSpeed * deltaTime)); Camera3DSetPosition(cam, some_pos.x, some_pos.y, some_pos.z); } else if (TEngineGetKeyPress(TIGOR_KEY_S)) { if (cam->walk) viewRot.y = 0; some_pos = v3_add(pos, v3_muls(viewRot, cam->cameraSpeed * deltaTime)); Camera3DSetPosition(cam, some_pos.x, some_pos.y, some_pos.z); } if (TEngineGetKeyPress(TIGOR_KEY_A)) { some_pos = v3_sub(pos, v3_muls(v3_norm(v3_cross(viewRot, up)), cam->cameraSpeed * deltaTime)); Camera3DSetPosition(cam, some_pos.x, some_pos.y, some_pos.z); } else if (TEngineGetKeyPress(TIGOR_KEY_D)) { some_pos = v3_add(pos, v3_muls(v3_norm(v3_cross(viewRot, up)), cam->cameraSpeed * deltaTime)); Camera3DSetPosition(cam, some_pos.x, some_pos.y, some_pos.z); } if (TEngineGetKeyPress(TIGOR_KEY_LEFT_SHIFT)) { cam->cameraSpeed = cam->moveSpeed * 10; } else { cam->cameraSpeed = cam->moveSpeed * 3; } /*if (TEngineGetKeyPress(TIGOR_KEY_1)){ walk = true; }else if (TEngineGetKeyPress(TIGOR_KEY_2)){ walk = false; }*/ /*if (TEngineGetKeyPress(TIGOR_KEY_SPACE) && force <= 0 && grounded){ jump = true; force = 5; }*/ } void Camera3DRotationUpdateMain(float deltaTime) { RenderTexture *render = (RenderTexture *)engine.main_render; Camera3DRotationUpdate(&render->cam3D, deltaTime); } void Camera3DTrueRotation(Camera3D *cam, float xpos, float ypos, float deltaTime) { if (cam->firstMouse) { cam->lastX = xpos; cam->lastY = ypos; cam->firstMouse = false; } double xoffset, yoffset; if (cam->lockMouse) { xoffset = engine.width / 2 - xpos; yoffset = engine.height / 2 - ypos; } else { xoffset = xpos - cam->lastX; yoffset = cam->lastY - ypos; } cam->lastX = xpos; cam->lastY = ypos; xoffset *= cam->sensitivity * deltaTime; yoffset *= cam->sensitivity * deltaTime; cam->yaw += xoffset; cam->pitch += yoffset; if (cam->pitch > 89.0f) cam->pitch = 89.0f; if (cam->pitch < -89.0f) cam->pitch = -89.0f; vec3 direction = Camera3DGetRotation(cam); vec3 next_rotation, result; next_rotation.x = cos(cam->yaw * (M_PI / 180)) * cos(cam->pitch * (M_PI / 180)); next_rotation.y = -sin(cam->pitch * (M_PI / 180)); next_rotation.z = -sin(cam->yaw * (M_PI / 180)) * cos(cam->pitch * (M_PI / 180)); if (cam->lockMouse) next_rotation.z *= -1; next_rotation = v3_norm(next_rotation); Camera3DSetRotation(cam, next_rotation.x, next_rotation.y, next_rotation.z); } void Camera3DRotationUpdate(Camera3D *cam, float deltaTime) { double xpos, ypos; TEngineGetCursorPos(&xpos, &ypos); if (cam->firstMouse) { cam->lastX = xpos; cam->lastY = ypos; cam->firstMouse = false; } double xoffset, yoffset; if (cam->lockMouse) { xoffset = engine.width / 2 - xpos; yoffset = engine.height / 2 - ypos; } else { xoffset = xpos - cam->lastX; yoffset = cam->lastY - ypos; } cam->lastX = xpos; cam->lastY = ypos; xoffset *= cam->sensitivity * deltaTime; yoffset *= cam->sensitivity * deltaTime; cam->yaw += xoffset; cam->pitch += yoffset; if (cam->pitch > 89.0f) cam->pitch = 89.0f; if (cam->pitch < -89.0f) cam->pitch = -89.0f; vec3 direction = Camera3DGetRotation(cam); vec3 next_rotation, result; next_rotation.x = cos(cam->yaw * (M_PI / 180)) * cos(cam->pitch * (M_PI / 180)); next_rotation.y = -sin(cam->pitch * (M_PI / 180)); next_rotation.z = -sin(cam->yaw * (M_PI / 180)) * cos(cam->pitch * (M_PI / 180)); if (cam->lockMouse) next_rotation.z *= -1; next_rotation = v3_norm(next_rotation); Camera3DSetRotation(cam, next_rotation.x, next_rotation.y, next_rotation.z); if (cam->lockMouse) TEngineFixedCursorCenter(cam); } void CameraSetLockCursorMain() { RenderTexture *render = (RenderTexture *)engine.main_render; CameraSetLockCursor(&render->cam3D); } void CameraSetLockCursor(Camera3D *cam) { cam->lockMouse = !cam->lockMouse; if (cam->lockMouse) TEngineHideCursor(1); else TEngineHideCursor(2); } bool CameraGetLockCursorMain() { RenderTexture *render = (RenderTexture *)engine.main_render; return CameraGetLockCursor(&render->cam3D); } bool CameraGetLockCursor(Camera3D *cam) { return cam->lockMouse; }