67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
#include "component_camera_focus.h"
|
|
|
|
void
|
|
component_camera_focus_tick(ComponentCameraFocus* self, ECS* ecs)
|
|
{
|
|
ComponentPhysics* physics;
|
|
vec3 position;
|
|
//f32 velocityPercent;
|
|
//vec2 positionPercent;
|
|
|
|
physics = ecs_component_get(ecs, COMPONENT_PHYSICS, self->entityID);
|
|
|
|
if (!physics)
|
|
return;
|
|
|
|
glm_vec3_copy(physics->position, position);
|
|
|
|
/*
|
|
positionPercent[0] = (physics->position[0] + (physics->velocity[0] * COMPONENT_CAMERA_FOCUS_VELOCITY_MULTIPLIER)) / self->camera->orthographic.size[0];
|
|
positionPercent[1] = (physics->position[1] + (physics->velocity[1] * COMPONENT_CAMERA_FOCUS_VELOCITY_MULTIPLIER)) / self->camera->orthographic.size[1];
|
|
*/
|
|
|
|
/*
|
|
position[0] += physics->velocity[0] * COMPONENT_CAMERA_FOCUS_VELOCITY_MULTIPLIER;
|
|
position[1] += physics->velocity[1] * COMPONENT_CAMERA_FOCUS_VELOCITY_MULTIPLIER;
|
|
*/
|
|
|
|
position[0] -= self->camera->orthographic.size[0] / 2;
|
|
position[1] -= self->camera->orthographic.size[1] / 2;
|
|
|
|
/*
|
|
position[0] += (physics->position[0]) - ((self->camera->orthographic.size[0] / 4) * (1 - self->camera->zoom));
|
|
position[1] += (physics->position[1]) - ((self->camera->orthographic.size[1] / 4) * (1 - self->camera->zoom));
|
|
*/
|
|
|
|
position[2] = 0.0f;
|
|
|
|
//velocityPercent = 0.0f;
|
|
|
|
/*
|
|
if (fabs(physics->velocity[0]) >= fabs(physics->velocity[1]))
|
|
velocityPercent = fabs(physics->velocity[0]) / physics->velocityMax[0];
|
|
else if (fabs(physics->velocity[1]) > fabs(physics->velocity[0]))
|
|
velocityPercent = fabs(physics->velocity[1]) / physics->velocityMax[1];
|
|
|
|
self->camera->zoom = COMPONENT_CAMERA_FOCUS_ZOOM_MIN;
|
|
self->camera->zoom += (velocityPercent * (COMPONENT_CAMERA_FOCUS_ZOOM_MAX - COMPONENT_CAMERA_FOCUS_ZOOM_MIN));
|
|
*/
|
|
|
|
//glm_vec3_print(position, stderr);
|
|
|
|
camera_position_set(self->camera, position);
|
|
}
|
|
|
|
void
|
|
component_camera_focus_init
|
|
(
|
|
ComponentCameraFocus* self,
|
|
ECS* ecs,
|
|
Camera* camera,
|
|
u32 entityID
|
|
)
|
|
{
|
|
self->camera = camera;
|
|
self->entityID = entityID;
|
|
}
|