diff options
author | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-07-16 18:57:08 -0600 |
---|---|---|
committer | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-07-16 18:57:08 -0600 |
commit | ed1704f9a110c9fa909dccb3169bf388f48279e4 (patch) | |
tree | b153bddd10a82dbcb7c5c3253e3466b61d5326ba /src/entities | |
parent | 9eeb5293fc0d022298fb772338241aa7e8672dac (diff) |
Chatgpt saved my ass again
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/mussolini.c | 46 | ||||
-rw-r--r-- | src/entities/mussolini.h | 7 | ||||
-rw-r--r-- | src/entities/soldato.c | 17 |
3 files changed, 51 insertions, 19 deletions
diff --git a/src/entities/mussolini.c b/src/entities/mussolini.c index 2770d2f..9ea54c7 100644 --- a/src/entities/mussolini.c +++ b/src/entities/mussolini.c @@ -1,32 +1,44 @@ #include "mussolini.h" #include "assets.h" #include "game.h" +#include "util.h" void initMussolini(Entity * entity, Game * game) { entity->model = &game->assets.models[MUSSOLINI_ASSET]; + + // PID configs. + PIDConfig stickPIDConfig = { + .kP = 0.5, + .kI = 0.0, + .kD = 0.0, + .angleMode = false, + .doClamp = false, + .min = 0.0, + .max = 0.0 + }; + + // Allocate data. + entity->data = KF_MALLOC(sizeof(Mussolini)); + + if (entity->data == NULL) { + ALLOCATION_ERROR; + return; + } + + Mussolini * data = (Mussolini*)entity->data; + data->xStickPID = createPID(stickPIDConfig); + data->yStickPID = createPID(stickPIDConfig); + data->zStickPID = createPID(stickPIDConfig); } void closeMussolini(Entity * entity) { + if (entity->data != NULL) + KF_FREE(entity->data); } void updateMussolini(Game * game, Entity * entity) { - Entity * player = getEntityFromWorld(game->world, 0); - - float pitch = Vector2Angle( - (Vector2){entity->position.y, entity->position.x}, - (Vector2){player->position.y, player->position.x} - ); - - float yaw = Vector2Angle( - (Vector2){entity->position.x, entity->position.z}, - (Vector2){player->position.x, player->position.z} - ); - - entity->rotation = QuaternionFromEuler( - pitch - (PI/2), - -(yaw - (PI/2)), - 0.0 - ); + Entity * ship = getEntityFromWorld(game->world, 0); + Mussolini * data = (Mussolini*)entity->data; } void drawMussolini(Game * game, Entity * entity) { diff --git a/src/entities/mussolini.h b/src/entities/mussolini.h index ee595f5..46520a7 100644 --- a/src/entities/mussolini.h +++ b/src/entities/mussolini.h @@ -1,9 +1,16 @@ #include "gameCommon.h" #include "entity.h" +#include "PID.h" #ifndef MUSSOLINI_H #define MUSSOLINI_H +typedef struct Mussolini { + PID xStickPID; + PID yStickPID; + PID zStickPID; +} Mussolini; + void initMussolini(Entity * entity, Game * game); void closeMussolini(Entity * entity); void updateMussolini(Game * game, Entity * entity); diff --git a/src/entities/soldato.c b/src/entities/soldato.c index da8df84..f19faa7 100644 --- a/src/entities/soldato.c +++ b/src/entities/soldato.c @@ -3,14 +3,27 @@ void initSoldato(Entity * entity, Game * game) { entity->model = &game->assets.models[SOLDATO_ASSET]; - entity->velocity.angularVelocity = (AxisAngle){(Vector3){1.0, 1.0, 1.0}, 1.0}; } void closeSoldato(Entity * entity) { } void updateSoldato(Game * game, Entity * entity) { - entityUpdateRotation(entity); + Entity * player = getEntityFromWorld(game->world, 0); + + // Get direction. + Vector3 direction = Vector3Subtract(entity->position, player->position); + direction = Vector3Normalize(direction); + + // Get look at and rotation. + Matrix matrix = MatrixLookAt(Vector3Zero(), direction, (Vector3){0, 1, 0}); + Quaternion rotation = QuaternionFromMatrix(matrix); + rotation = QuaternionInvert(rotation); + + entity->rotation = rotation; + + entity->velocity.velocity = Vector3Scale(direction, -10.0); + entityUpdatePosition(entity); } void drawSoldato(Game * game, Entity * entity) { |