indicator.cpp 3.17 KB
Newer Older
1
/* Quatter
魔大农's avatar
魔大农 committed
2
// Copyright (C) 2017 LucKey Productions (luckeyproductions.nl)
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
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "indicator.h"

void Indicator::RegisterObject(Context *context)
{
    context->RegisterFactory<Indicator>();
}

Indicator::Indicator(Context* context) : LogicComponent(context)
{

}

void Indicator::OnNodeSet(Node *node)
魔大农's avatar
魔大农 committed
32
{ if (!node) return;
33

魔大农's avatar
魔大农 committed
34 35
    node_->AddTag("Indicator");

36 37
    glow_ = MC->GetMaterial("Glow")->Clone();
    //Create nodes and models
魔大农's avatar
魔大农 committed
38
    arrowNode1_ = node_->CreateChild("Arrow", LOCAL);
39 40 41
    arrowNode1_->Rotate(Quaternion(-90.0f, Vector3::UP));
    model1_ = arrowNode1_->CreateComponent<AnimatedModel>();

魔大农's avatar
魔大农 committed
42
    arrowNode2_ = node_->CreateChild("Arrow", LOCAL);
43 44 45
    arrowNode2_->Rotate(Quaternion(90.0f, Vector3::UP));
    model2_ = arrowNode2_->CreateComponent<AnimatedModel>();

魔大农's avatar
魔大农 committed
46
    //Create lights
魔大农's avatar
魔大农 committed
47
    Node* lightNode1{ arrowNode1_->CreateChild("Light", LOCAL) };
48 49 50 51 52 53
    lightNode1->SetPosition(Vector3::UP * 0.23f);
    light1_ = lightNode1->CreateComponent<Light>();
    light1_->SetColor(COLOR_GLOW);
    light1_->SetBrightness(0.023f);
    light1_->SetRange(2.0f);
    light1_->SetCastShadows(false);
魔大农's avatar
魔大农 committed
54

魔大农's avatar
魔大农 committed
55
    Node* lightNode2{ arrowNode2_->CreateChild("Light", LOCAL) };
56 57 58 59 60 61 62 63 64 65
    lightNode2->SetPosition(Vector3::UP * 0.23f);
    light2_ = lightNode2->CreateComponent<Light>();
    light2_->SetColor(COLOR_GLOW);
    light2_->SetBrightness(0.023f);
    light2_->SetRange(2.0f);
    light2_->SetCastShadows(false);
}

void Indicator::Init(int nth)
{
魔大农's avatar
魔大农 committed
66
    arrowNode1_->SetPosition(Vector3::LEFT  * (2.3f + 0.95f * (nth == 2 || nth == 3)) + Vector3::FORWARD * (nth >= 4));
67 68
    arrowNode2_->SetPosition(Vector3::RIGHT * (2.3f + 0.95f * (nth == 2 || nth == 3)));

魔大农's avatar
魔大农 committed
69 70
    switch (nth) {
    case 1: case 5:
71
        node_->Rotate(Quaternion(90.0f, Vector3::UP));
魔大农's avatar
魔大农 committed
72 73
        break;
    case 2:
74
        node_->Rotate(Quaternion(45.0f, Vector3::UP));
魔大农's avatar
魔大农 committed
75 76
        break;
    case 3:
77
        node_->Rotate(Quaternion(-45.0f, Vector3::UP));
魔大农's avatar
魔大农 committed
78 79 80 81 82 83
        break;
    default:
        break;
    }

    if (nth < 4) {
84 85 86 87 88 89

        model1_->SetModel(MC->GetModel("Arrow"));
        model1_->SetMorphWeight(0, static_cast<float>(nth < 2));

        model2_->SetModel(MC->GetModel("Arrow"));
        model2_->SetMorphWeight(0, static_cast<float>(nth < 2));
魔大农's avatar
魔大农 committed
90

91
    } else {
魔大农's avatar
魔大农 committed
92

93 94 95
        model1_->SetModel(MC->GetModel("BlockIndicator"));
        model2_->SetModel(MC->GetModel("BlockIndicator"));
    }
魔大农's avatar
魔大农 committed
96

97 98 99 100 101 102
    model1_->SetMaterial(glow_);
    model2_->SetMaterial(glow_);
    model2_->GetMaterial()->SetShaderParameter("MatDiffColor", Color(0.0f, 0.0f, 0.0f, 0.0f));
}