summaryrefslogtreecommitdiff
path: root/src/engine/actors/Ship.cpp
blob: 148b883eb7b899fee82bced81e183c6ea9cc816c (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Ship.h"

#include <libultra/gbi.h>

extern "C" {
#include "common_structs.h"
#include "math_util.h"
#include "main.h"
#include "courses/harbour/ghostship_model.h"
#include "courses/harbour/ship2_model.h"
#include "courses/harbour/ship3_model.h"
}

AShip::AShip(FVector pos, AShip::Skin skin) {
    Spawn = pos;
    Spawn.y += 10;

    switch(skin) {
        case GHOSTSHIP:
            _skin = ghostship_Plane_mesh;
            break;
        case SHIP2:
            _skin = ship2_SoH_mesh;
            break;
        case SHIP3:
            _skin = ship3_2Ship_mesh;
            break;
    }
}

void AShip::Tick() {
    static float angle = 0.0f; // Keeps track of the ship's rotation around the circle
    float radius = 150.0f;      // The radius of the circular path
    float speed = 0.01f;       // Speed of rotation

    angle += speed; // Increment the angle to move in a circle

    // Update the position based on a circular path
    Pos.x = Spawn.x + radius * cosf(angle);
    Pos.z = Spawn.z + radius * sinf(angle);

    // Rotate to face forward along the circle
    Rot.yaw = -static_cast<int16_t>(angle * (32768.0f / M_PI / 2.0f));
}

void AShip::Draw(Camera *camera) {
    Mat4 shipMtx;
    Vec3f hullPos = {Pos.x, Pos.y, Pos.z};
    Vec3s hullRot = {Rot.pitch, Rot.yaw, Rot.roll};

    gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH);
    gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);

    mtxf_pos_rotation_xyz(shipMtx, hullPos, hullRot);
    mtxf_scale(shipMtx, 0.4);
    if (render_set_position(shipMtx, 0) != 0) {
        gSPDisplayList(gDisplayListHead++, _skin);
    }
}

bool AShip::IsMod() { return true; }