blob: 9f56aa38055dae2c352023c1573f7ac73e0c699f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#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];
entity->collisionModel = entityCreateCollisionModel(*entity->model);
entity->transformedCollisionModel = entityCreateCollisionModel(*entity->model);
setEntityRadius(entity);
// Allocate data.
entity->data = KF_MALLOC(sizeof(Mussolini));
if (entity->data == NULL) {
ALLOCATION_ERROR;
return;
}
Mussolini * data = (Mussolini*)entity->data;
}
void closeMussolini(Entity * entity) {
if (entity->data != NULL)
KF_FREE(entity->data);
}
void updateMussolini(Game * game, Entity * entity) {
entityUpdateLastValues(entity);
float t = GetFrameTime();
Entity * player = getEntityFromWorld(game->world, 0);
Mussolini * data = (Mussolini*)entity->data;
// Look at player.
Matrix matrix = MatrixLookAt(player->position, entity->position, (Vector3){0.0, 1.0, 0.0});
Quaternion rotation = QuaternionInvert(QuaternionFromMatrix(matrix));
entity->rotation = QuaternionSlerp(entity->rotation, rotation, t * MUSSOLINI_TURN_SPEED);
entityCheckTransformedCollisionModel(entity);
}
void drawMussolini(Game * game, Entity * entity) {
entityDraw(entity);
}
|