summaryrefslogtreecommitdiff
path: root/src/engine/editor/Light.cpp
blob: 4777935405948a600ad92ecbf03f18de59e37e58 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <libultraship/libultraship.h>
#include <libultra/gbi.h>
#include "../CoreMath.h"
#include <libultra/types.h>
#include "../World.h"
#include "engine/Matrix.h"

#include "Light.h"
#include "port/Engine.h"
#include <ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h>
#include <ship/window/Window.h>

#include "engine/actors/Ship.h"
#include "port/Game.h"
#include "Gizmo.h"

#include "EditorMath.h"

extern "C" {
#include "common_structs.h"
#include "main.h"
#include "defines.h"
#include "actors.h"
#include "camera.h"
#include "math_util.h"
#include "math_util_2.h"
}

namespace TrackEditor {

size_t LightObject::NumLights = 0;

    LightObject::LightObject(const char* name, FVector* pos, s8* direction) {
        Name = name;
        ResourceName = "editor:light";

        Pos = FVector(0, 100, 0);
        Rot = IRotator(0, 0, 0);
        Scale = FVector(0.1, 0.1, 0.1);

        SpawnPos = Pos;
        SpawnRot = Rot;

        Direction = direction;

        Collision = CollisionType::BOUNDING_BOX;
        BoundingBoxSize = 4.0f;

        NumLights += 1;
    }

    void LightObject::Load() {
    }

    void LightObject::Tick() {
        SetDirectionFromRotator(Rot, Direction);
    }
    void LightObject::Draw() {
        Camera* camera = gScreenOneCtx->camera;
        Mat4 mtx_sun;
        Editor_MatrixIdentity(mtx_sun);
        gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH);
        gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);


        // Calculate camera-to-object distance
        FVector cameraDir = FVector(Pos.x - camera->pos[0], Pos.y - camera->pos[1], Pos.z - camera->pos[2]);
        cameraDir = cameraDir.Normalize();

        IRotator centerRot;
        SetRotatorFromDirection(cameraDir, &centerRot);

        // The sun was exported facing the wrong direction.
        // Thus, force the sun texture to face the camera.
        centerRot.yaw += 0x4000;
        ApplyMatrixTransformations(mtx_sun, Pos, centerRot, Scale);
        Editor_AddMatrix(mtx_sun, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
        gSPDisplayList(gDisplayListHead++, sun_LightModel_mesh);

        // Draw Arrow
        Mat4 mtx_arrow;
        ApplyMatrixTransformations(mtx_arrow, Pos, Rot, Scale);
        Editor_AddMatrix(mtx_arrow, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
        gSPDisplayList(gDisplayListHead++, (Gfx*)"__OTR__editor/light/sun_arrow");
    }
}