diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-08-04 01:26:17 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-08-04 01:26:17 -0600 |
commit | 2849ccc2afcf89c46a9471b787b1ab14959637ae (patch) | |
tree | 6f77772da8e7004d6918b513ac3b82e5aae78b83 /src | |
parent | 6d7842484434d1d3f4265194ba87db6afff3186b (diff) |
After lots of time got the circle thingy working
Diffstat (limited to 'src')
-rw-r--r-- | src/entities/maresciallo.c | 58 | ||||
-rw-r--r-- | src/entities/maresciallo.h | 7 | ||||
-rw-r--r-- | src/settings.c | 2 |
3 files changed, 44 insertions, 23 deletions
diff --git a/src/entities/maresciallo.c b/src/entities/maresciallo.c index 288b27e..a302b89 100644 --- a/src/entities/maresciallo.c +++ b/src/entities/maresciallo.c @@ -19,8 +19,8 @@ void initMaresciallo(Entity * entity, Game * game) { Maresciallo * data = (Maresciallo*)entity->data; - PIDConfig flyAwayPID = (PIDConfig){ - .kP = 100, // 1.1 + PIDConfig flyToPointPID = (PIDConfig){ + .kP = 1.1, // 1.1 .kI = 0.0, .kD = 0.0, .angleMode = false, @@ -29,13 +29,12 @@ void initMaresciallo(Entity * entity, Game * game) { .max = 210.0 }; - data->flyAway = (EntityFlyToPointInfo){ - .controller.speedPID = createPID(flyAwayPID), + data->flyToPoint = (EntityFlyToPointInfo){ + .controller.speedPID = createPID(flyToPointPID), .controlType = ENTITY_FLY_TO_POINT_PID, - .rotationSpeed = 0.0, + .rotationSpeed = MARESCIALLO_ROTATION_SPEED, .applyRotation = true }; - } void closeMaresciallo(Entity * entity) { @@ -46,7 +45,7 @@ void closeMaresciallo(Entity * entity) { entityFreeCollisionModel(entity->transformedCollisionModel); } -void getAwayMaresciallo(Game * game, Entity * entity) { +void flyToPointMaresciallo(Game * game, Entity * entity) { Maresciallo * data = (Maresciallo*)entity->data; Entity * player = getEntityFromWorld(game->world, 0); @@ -56,23 +55,37 @@ void getAwayMaresciallo(Game * game, Entity * entity) { target = Vector3Scale(target, MARESCIALLO_CIRCLE_AT_DIS); target = Vector3Add(player->position, target); - // Fucking get away from the smelly player. - entityFlyToPoint(entity, target, &data->flyAway); + // Fucking fly. + entityFlyToPoint(entity, target, &data->flyToPoint); } void circlePlayerMaresciallo(Game * game, Entity * entity) { float t = GetFrameTime(); Maresciallo * data = (Maresciallo*)entity->data; Entity * player = getEntityFromWorld(game->world, 0); - - Quaternion toEntity = QuaternionFromVector3ToVector3(player->position, entity->position); - Quaternion next = toEntity; - next = QuaternionIdentity(); - - Vector3 target = Vector3Subtract(entity->position, player->position); - target = Vector3RotateByQuaternion(target, next); - - entity->position = Vector3Add(player->position, target); + + Vector3 axis = (Vector3){1.0, 1.0, 1.0}; + float angle = t * MARESCIALLO_CIRCLE_PLAYER_SPEED; + + Vector3 oldPos = entity->position; + + // Get position. + entity->position = Vector3Add( + Vector3RotateByAxisAngle( + Vector3Subtract(entity->position, player->position), + axis, + angle + ), + player->position + ); + + Vector3 direction = Vector3Subtract(oldPos, entity->position); + direction = Vector3Normalize(direction); + + // Get rotation. + Matrix matrix = MatrixLookAt(Vector3Zero(), direction, (Vector3){0.0, 1.0, 0.0}); + Quaternion rotation = QuaternionInvert(QuaternionFromMatrix(matrix)); + entity->rotation = QuaternionSlerp(entity->rotation, rotation, t * MARESCIALLO_ROTATION_SPEED); } void updateMaresciallo(Game * game, Entity * entity) { @@ -81,9 +94,11 @@ void updateMaresciallo(Game * game, Entity * entity) { Maresciallo * data = (Maresciallo*)entity->data; Entity * player = getEntityFromWorld(game->world, 0); + float dis = Vector3Distance(entity->position, player->position); + // Fly away if to close to player. - if (Vector3Distance(entity->position, player->position) < MARESCIALLO_CIRCLE_AT_DIS - 1) { - getAwayMaresciallo(game, entity); + if (dis < MARESCIALLO_CIRCLE_AT_DIS - 1 || dis >= MARESCIALLO_COME_BACK_AT_DIS) { + flyToPointMaresciallo(game, entity); } else { circlePlayerMaresciallo(game, entity); } @@ -93,4 +108,7 @@ void updateMaresciallo(Game * game, Entity * entity) { void drawMaresciallo(Game * game, Entity * entity) { entityDraw(entity); + + Entity * player = getEntityFromWorld(game->world, 0); + DrawLine3D(entity->position, player->position, BLUE); } diff --git a/src/entities/maresciallo.h b/src/entities/maresciallo.h index e607ab3..2e50ffe 100644 --- a/src/entities/maresciallo.h +++ b/src/entities/maresciallo.h @@ -4,10 +4,13 @@ #ifndef MARESCIALLO_H #define MARESCIALLO_H -#define MARESCIALLO_CIRCLE_AT_DIS 50.0 // 200.0 +#define MARESCIALLO_CIRCLE_AT_DIS 200.0 // 200.0 +#define MARESCIALLO_COME_BACK_AT_DIS 250.0 +#define MARESCIALLO_ROTATION_SPEED 20.0 +#define MARESCIALLO_CIRCLE_PLAYER_SPEED 1.0 typedef struct Maresciallo { - EntityFlyToPointInfo flyAway; + EntityFlyToPointInfo flyToPoint; } Maresciallo; void initMaresciallo(Entity * entity, Game * game); diff --git a/src/settings.c b/src/settings.c index 16c1ec3..5b91f65 100644 --- a/src/settings.c +++ b/src/settings.c @@ -2,7 +2,7 @@ void initSettings(Settings * settings) { *settings = (Settings){ - .controlMode = KEYBOARD_AND_MOUSE_CONTROL, + .controlMode = JOYSTICK_CONTROL, .mouseSensitivity = 0.05, .scrollBarSpeed = 10.0, .gamePadNum = 0, |