Commit cafc775e authored by 魔大农's avatar 魔大农

Switched to custom component based approach

parent 1815c575
......@@ -26,7 +26,10 @@ SOURCES += \
board.cpp \
piece.cpp \
master.cpp \
effectmaster.cpp
effectmaster.cpp \
square.cpp \
yad.cpp \
indicator.cpp
HEADERS += \
luckey.h \
......@@ -36,7 +39,10 @@ HEADERS += \
board.h \
piece.h \
master.h \
effectmaster.h
effectmaster.h \
square.h \
yad.h \
indicator.h
unix {
isEmpty(PREFIX) {
......
This diff is collapsed.
......@@ -22,7 +22,7 @@
#include <Urho3D/Urho3D.h>
#include "mastercontrol.h"
#include "piece.h"
#include "square.h"
#include "quattercam.h"
namespace Urho3D {
......@@ -34,37 +34,17 @@ using namespace Urho3D;
#define BOARD_WIDTH 4
#define BOARD_HEIGHT 4
typedef class Square : public Object{
URHO3D_OBJECT(Square, Object);
public:
Square() : Object(MC->GetContext()) {}
IntVector2 coords_;
SharedPtr<Node> node_;
SharedPtr<AnimatedModel> slot_;
SharedPtr<Light> light_;
Piece* piece_;
bool free_;
bool selected_;
}Square;
typedef class Indicator : public Object{
URHO3D_OBJECT(Indicator, Object);
public:
Indicator() : Object(MC->GetContext()) {}
SharedPtr<Node> rootNode_;
SharedPtr<Material> glow_;
SharedPtr<AnimatedModel> model1_;
SharedPtr<AnimatedModel> model2_;
SharedPtr<Light> light1_;
SharedPtr<Light> light2_;
}Indicator;
class Piece;
class Indicator;
class Board : public Object
class Board : public LogicComponent
{
URHO3D_OBJECT(Board, Object);
URHO3D_OBJECT(Board, LogicComponent);
public:
Board();
Node* GetRootNode() const { return rootNode_; }
Board(Context* context);
static void RegisterObject(Context* context);
virtual void OnNodeSet(Node* node);
float GetThickness() const { return model_->GetBoundingBox().Size().y_; }
bool PutPiece(Piece* piece, Square* square);
......@@ -92,7 +72,6 @@ public:
void HideIndicators();
private:
bool indicateSingle_;
SharedPtr<Node> rootNode_;
StaticModel* model_;
HashMap<IntVector2, SharedPtr<Square>> squares_;
......
......@@ -20,7 +20,7 @@
using namespace Urho3D;
EffectMaster::EffectMaster() : Master()
EffectMaster::EffectMaster(Context* context) : Master(context)
{
}
......
......@@ -28,7 +28,7 @@ class EffectMaster : public Master
{
URHO3D_OBJECT(EffectMaster, Master);
public:
EffectMaster();
EffectMaster(Context* context);
void FadeTo(Material* material, Color color, float duration = 0.23f, float delay = 0.0f);
void FadeTo(Light* light, float brightness, float duration = 0.23f);
......
/* Quatter
// Copyright (C) 2016 LucKey Productions (luckeyproductions.nl)
//
// 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)
{ (void)node;
glow_ = MC->GetMaterial("Glow")->Clone();
//Create nodes and models
arrowNode1_ = node_->CreateChild("Arrow");
arrowNode1_->Rotate(Quaternion(-90.0f, Vector3::UP));
model1_ = arrowNode1_->CreateComponent<AnimatedModel>();
arrowNode2_ = node_->CreateChild("Arrow");
arrowNode2_->Rotate(Quaternion(90.0f, Vector3::UP));
model2_ = arrowNode2_->CreateComponent<AnimatedModel>();
//Create light
Node* lightNode1{arrowNode1_->CreateChild("Light")};
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);
Node* lightNode2{arrowNode2_->CreateChild("Light")};
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)
{
arrowNode1_->SetPosition(Vector3::LEFT * (2.3f + 0.95f * (nth == 2 || nth == 3)) + Vector3::FORWARD * (nth >= 4));
arrowNode2_->SetPosition(Vector3::RIGHT * (2.3f + 0.95f * (nth == 2 || nth == 3)));
if (nth == 1)
node_->Rotate(Quaternion(90.0f, Vector3::UP));
else if (nth == 2)
node_->Rotate(Quaternion(45.0f, Vector3::UP));
else if (nth == 3)
node_->Rotate(Quaternion(-45.0f, Vector3::UP));
else if (nth == 5)
node_->Rotate(Quaternion(90.0f, Vector3::UP));
if (nth < 4){
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));
} else {
model1_->SetModel(MC->GetModel("BlockIndicator"));
model2_->SetModel(MC->GetModel("BlockIndicator"));
}
model1_->SetMaterial(glow_);
model2_->SetMaterial(glow_);
model2_->GetMaterial()->SetShaderParameter("MatDiffColor", Color(0.0f, 0.0f, 0.0f, 0.0f));
}
/* Quatter
// Copyright (C) 2016 LucKey Productions (luckeyproductions.nl)
//
// 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.
*/
#ifndef INDICATOR_H
#define INDICATOR_H
#include <Urho3D/Urho3D.h>
#include "mastercontrol.h"
#include "luckey.h"
class Indicator : public LogicComponent
{
friend class Board;
URHO3D_OBJECT(Indicator, LogicComponent);
public:
Indicator(Context* context);
static void RegisterObject(Context* context);
virtual void OnNodeSet(Node* node);
private:
Node* arrowNode1_;
Node* arrowNode2_;
SharedPtr<Material> glow_;
SharedPtr<AnimatedModel> model1_;
SharedPtr<AnimatedModel> model2_;
SharedPtr<Light> light1_;
SharedPtr<Light> light2_;
void Init(int nth);
};
#endif // INDICATOR_H
......@@ -21,8 +21,10 @@
#include "quattercam.h"
#include "board.h"
#include "piece.h"
#include "square.h"
#include "yad.h"
InputMaster::InputMaster() : Master(),
InputMaster::InputMaster(Context* context) : Master(context),
pressedKeys_{},
pressedMouseButtons_{},
pressedJoystickButtons_{},
......@@ -38,7 +40,7 @@ InputMaster::InputMaster() : Master(),
mouseMoveSinceClick_{},
smoothCamRotate_{},
smoothCamZoom_{},
yad_{new Yad()},
yad_{},
rayPiece_{},
raySquare_{}
{
......@@ -57,21 +59,9 @@ InputMaster::InputMaster() : Master(),
void InputMaster::ConstructYad()
{
yad_->node_ = MC->world_.scene_->CreateChild("Yad");
StringVector tag{}; tag.Push(String("Yad"));
yad_->node_->SetTags(tag);
Node* lightNode{yad_->node_->CreateChild("Light")};
lightNode->SetPosition(Vector3::UP * 0.23f);
yad_->model_ = yad_->node_->CreateComponent<AnimatedModel>();
yad_->model_->SetModel(MC->GetModel("Yad"));
yad_->material_ = MC->GetMaterial("Glow")->Clone();
yad_->model_->SetMaterial(yad_->material_);
yad_->light_ = lightNode->CreateComponent<Light>();
yad_->light_->SetLightType(LIGHT_POINT);
yad_->light_->SetCastShadows(true);
yad_->light_->SetColor(COLOR_GLOW);
yad_->light_->SetRange(1.0f);
yad_->light_->SetBrightness(YAD_FULLBRIGHT);
Node* yadNode{ MC->world_.scene_->CreateChild("Yad") };
yad_ = yadNode->CreateComponent<Yad>();
HideYad();
}
......@@ -205,7 +195,7 @@ void InputMaster::Step(Vector3 step)
Square* selectedSquare{BOARD->GetSelectedSquare()};
if (selectedSquare) {
Vector3 resultingStep{Quaternion(quadrant, Vector3::UP) * step};
BOARD->SelectNearestSquare(selectedSquare->node_->GetPosition() + resultingStep);
BOARD->SelectNearestSquare(selectedSquare->GetNode()->GetPosition() + resultingStep);
} else {
BOARD->SelectLast();
}
......@@ -710,7 +700,7 @@ Square* InputMaster::RaycastToSquare()
for (RayQueryResult r : results){
for (Square* s : BOARD->GetSquares())
if (r.node_ == s->node_){
if (r.node_ == s->GetNode()){
raySquare_ = s;
return s;
}
......
......@@ -32,24 +32,13 @@
#define DRAG_THRESHOLD 0.023f
class Square;
typedef class Yad : public Object{
URHO3D_OBJECT(Yad, Object);
public:
Yad() : Object(MC->GetContext()) {}
SharedPtr<Node> node_{};
SharedPtr<AnimatedModel> model_{};
SharedPtr<Material> material_{};
SharedPtr<Light> light_{};
bool hidden_{true};
bool dimmed_{false};
}Yad;
class Yad;
class InputMaster : public Master
{
URHO3D_OBJECT(InputMaster, Master);
public:
InputMaster();
InputMaster(Context* context);
bool IsIdle() const noexcept { return idle_; }
void ConstructYad();
......
......@@ -49,6 +49,7 @@
#include <Urho3D/Graphics/RenderPath.h>
#include <Urho3D/Graphics/Skybox.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Texture2D.h>
#include <Urho3D/Graphics/Viewport.h>
#include <Urho3D/Graphics/Zone.h>
#include <Urho3D/Input/InputEvents.h>
......
......@@ -18,7 +18,7 @@
#include "master.h"
Master::Master(): Object(MC->GetContext())
Master::Master(Context* context): Object(context)
{
}
......@@ -36,8 +36,7 @@ class Master : public Object
friend class MasterControl;
URHO3D_OBJECT(Master, Object);
public:
Master();
protected:
Master(Context* context);
};
#endif // MASTER_H
......@@ -20,9 +20,11 @@
#include "inputmaster.h"
#include "effectmaster.h"
#include "quattercam.h"
#include "piece.h"
#include "board.h"
#include <Urho3D/Graphics/Texture2D.h>
#include <Urho3D/Graphics/Terrain.h>
#include "square.h"
#include "indicator.h"
#include "yad.h"
URHO3D_DEFINE_APPLICATION_MAIN(MasterControl);
......@@ -48,6 +50,13 @@ MasterControl::MasterControl(Context *context):
lastReset_{0.0f}
{
instance_ = this;
QuatterCam::RegisterObject(context_);
Piece::RegisterObject(context_);
Board::RegisterObject(context_);
Square::RegisterObject(context_);
Indicator::RegisterObject(context_);
Yad::RegisterObject(context_);
}
void MasterControl::Setup()
......@@ -59,9 +68,11 @@ void MasterControl::Setup()
engineParameters_["WindowIcon"] = "icon.png";
//Add resource path
Vector<String> resourcePaths{FILES->GetAppPreferencesDir("luckey", "quatter"),
"Resources",
"../Quatter/Resources"};
Vector<String> resourcePaths{};
resourcePaths.Push(FILES->GetAppPreferencesDir("luckey", "quatter"));
resourcePaths.Push("Resources");
resourcePaths.Push("../Quatter/Resources");
for (String path : resourcePaths)
if (FILES->DirExists(path)){
engineParameters_["ResourcePaths"] = path;
......@@ -75,8 +86,9 @@ void MasterControl::Setup()
}
void MasterControl::Start()
{
inputMaster_ = new InputMaster();
effectMaster_ = new EffectMaster();
context_->RegisterSubsystem(new InputMaster(context_));
context_->RegisterSubsystem(new EffectMaster(context_));
CreateScene();
......@@ -98,7 +110,9 @@ void MasterControl::CreateScene()
{
world_.scene_ = new Scene(context_);
world_.scene_->CreateComponent<Octree>();
world_.camera_ = new QuatterCam();
Node* cameraNode{ world_.scene_->CreateChild("Camera") };
world_.camera_ = cameraNode->CreateComponent<QuatterCam>();
CreateLights();
CreateSkybox();
......@@ -106,7 +120,7 @@ void MasterControl::CreateScene()
CreateTable();
CreateBoardAndPieces();
inputMaster_->ConstructYad();
GetSubsystem<InputMaster>()->ConstructYad();
}
void MasterControl::CreateLights()
{
......@@ -189,11 +203,15 @@ void MasterControl::CreateTable()
}
void MasterControl::CreateBoardAndPieces()
{
world_.board_ = new Board();
Node* boardNode{ world_.scene_->CreateChild("Board") };
world_.board_ = boardNode->CreateComponent<Board>();
world_.pieces_.Reserve(NUM_PIECES);
for (int p{0}; p < NUM_PIECES; ++p){
Piece* newPiece = new Piece(Piece::Attributes(p));
Node* pieceNode{ world_.scene_->CreateChild("Piece") };
Piece* newPiece = pieceNode->CreateComponent<Piece>();
newPiece->Init(Piece::PieceAttributes(p));
world_.pieces_.Push(SharedPtr<Piece>(newPiece));
newPiece->SetPosition(AttributesToPosition(newPiece->ToInt())
+ Vector3(Random(0.05f),
......@@ -203,12 +221,12 @@ void MasterControl::CreateBoardAndPieces()
}
Sound* MasterControl::GetMusic(String name) const {
Sound* song{CACHE->GetResource<Sound>("Music/"+name+".ogg")};
Sound* song{ CACHE->GetResource<Sound>("Music/"+name+".ogg") };
song->SetLooped(true);
return song;
}
Sound* MasterControl::GetSample(String name) const {
Sound* sample{CACHE->GetResource<Sound>("Samples/"+name+".ogg")};
Sound* sample{ CACHE->GetResource<Sound>("Samples/"+name+".ogg") };
sample->SetLooped(false);
return sample;
}
......@@ -216,7 +234,7 @@ Sound* MasterControl::GetSample(String name) const {
void MasterControl::HandleUpdate(StringHash eventType, VariantMap& eventData)
{ (void)eventType; (void)eventData;
if (selectionMode_ == SM_CAMERA && !inputMaster_->IsIdle())
if (selectionMode_ == SM_CAMERA && !GetSubsystem<InputMaster>()->IsIdle())
CameraSelectPiece();
//Wave leafy light
......
......@@ -53,7 +53,7 @@ typedef struct GameWorld
} GameWorld;
#define MC MasterControl::GetInstance()
#define FX MC->GetEffectMaster()
#define FX GetSubsystem<EffectMaster>()
#define CAMERA MC->world_.camera_
#define BOARD MC->world_.board_
#define NUM_PIECES 16
......@@ -69,7 +69,6 @@ class MasterControl : public Application
public:
MasterControl(Context* context);
static MasterControl* GetInstance();
EffectMaster* GetEffectMaster() const { return effectMaster_; }
GameWorld world_;
......@@ -115,8 +114,6 @@ public:
float Cosine(const float freq, const float min = -1.0f, const float max = 1.0f, const float shift = 0.0f);
private:
static MasterControl* instance_;
InputMaster* inputMaster_;
EffectMaster* effectMaster_;
SharedPtr<Node> leafyLightNode_;
SharedPtr<Light> leafyLight_;
......
......@@ -21,40 +21,57 @@
#include "board.h"
#include "piece.h"
Piece::Piece(Attributes attributes): Object(MC->GetContext()),
attributes_{attributes},
void Piece::RegisterObject(Context *context)
{
context->RegisterFactory<Piece>();
}
Piece::Piece(Context* context): LogicComponent(context),
attributes_{},
state_{PieceState::FREE }
{
rootNode_ = MC->world_.scene_->CreateChild("Piece_"+GetCodon(4));
rootNode_->SetRotation(Quaternion(Random(360.0f), Vector3::UP));
}
void Piece::OnNodeSet(Node* node)
{ (void)node;
node_->SetRotation(Quaternion(Random(360.0f), Vector3::UP));
StringVector tag{}; tag.Push(String("Piece"));
rootNode_->SetTags(tag);
node_->SetTags(tag);
StaticModel* pieceModel{rootNode_->CreateComponent<StaticModel>()};
pieceModel->SetCastShadows(true);
pieceModel->SetModel(MC->GetModel("Piece_"+GetCodon(3)));
if (attributes[3]){
pieceModel->SetMaterial(MC->GetMaterial("Wood_light"));
}
else pieceModel->SetMaterial(MC->GetMaterial("Wood_dark"));
pieceModel_ = node_->CreateComponent<StaticModel>();
pieceModel_->SetCastShadows(true);
outlineModel_ = rootNode_->CreateComponent<StaticModel>();
outlineModel_ = node_->CreateComponent<StaticModel>();
outlineModel_->SetCastShadows(false);
outlineModel_->SetModel(MC->GetModel("Piece_"+GetCodon(2)+"_outline"));
outlineModel_->SetMaterial(MC->GetMaterial("Glow")->Clone());
outlineModel_->GetMaterial()->SetShaderParameter("MatDiffColor", Color(0.0f, 0.0f, 0.0f));
outlineModel_->SetEnabled(false);
Node* lightNode{rootNode_->CreateChild("Light")};
Node* lightNode{node_->CreateChild("Light")};
lightNode->SetPosition(Vector3::UP * 0.5f);
light_ = lightNode->CreateComponent<Light>();
light_->SetColor(Color(0.0f, 0.8f, 0.5f));
light_->SetBrightness(0.0f);
light_->SetRange(3.0f);
}
void Piece::Init(PieceAttributes attributes)
{
attributes_ = attributes;
pieceModel_->SetModel(MC->GetModel("Piece_" + GetCodon(3)));
if (attributes[3]){
pieceModel_->SetMaterial(MC->GetMaterial("Wood_light"));
}
else pieceModel_->SetMaterial(MC->GetMaterial("Wood_dark"));
outlineModel_->SetModel(MC->GetModel("Piece_"+GetCodon(2)+"_outline"));
outlineModel_->SetMaterial(MC->GetMaterial("Glow")->Clone());
outlineModel_->GetMaterial()->SetShaderParameter("MatDiffColor", Color(0.0f, 0.0f, 0.0f));
outlineModel_->SetEnabled(false);
}
void Piece::Reset()
{
rootNode_->SetParent(MC->world_.scene_);
node_->SetParent(MC->world_.scene_);
if (MC->GetSelectedPiece() == this)
MC->DeselectPiece();
......@@ -63,7 +80,7 @@ void Piece::Reset()
if (state_ != PieceState::FREE){
state_ = PieceState::FREE;
FX->ArchTo(rootNode_,
FX->ArchTo(node_,
MC->AttributesToPosition(ToInt()),
Quaternion(Random(360.0f), Vector3::UP),
attributes_[0] ? 2.0f : 1.3f + attributes_[1] ? 0.5f : 1.0f + Random(0.23f),
......@@ -120,11 +137,11 @@ void Piece::Pick()
state_ = PieceState::PICKED;
MC->SetPickedPiece(this);
if (MC->GetGameState() == GameState::PLAYER1PICKS)
rootNode_->SetParent(CAMERA->GetPocket(false));
node_->SetParent(CAMERA->GetPocket(false));
if (MC->GetGameState() == GameState::PLAYER2PICKS)
rootNode_->SetParent(CAMERA->GetPocket(true));
node_->SetParent(CAMERA->GetPocket(true));
FX->ArchTo(rootNode_, Vector3::DOWN, Quaternion(10.0f, Vector3(1.0f, 0.0f, 0.5f)), 1.0f, 0.8f);
FX->ArchTo(node_, Vector3::DOWN, Quaternion(10.0f, Vector3(1.0f, 0.0f, 0.5f)), 1.0f, 0.8f);
FX->FadeOut(outlineModel_->GetMaterial());
FX->FadeOut(light_);
......@@ -138,7 +155,7 @@ void Piece::Put(Vector3 position)
state_ = PieceState::PUT;
MC->SetPickedPiece(nullptr);
rootNode_->SetParent(MC->world_.scene_);
FX->ArchTo(rootNode_, position, Quaternion(Random(-13.0f, 13.0f), Vector3::UP), 2.3f, 0.5f);
node_->SetParent(MC->world_.scene_);
FX->ArchTo(node_, position, Quaternion(Random(-13.0f, 13.0f), Vector3::UP), 2.3f, 0.5f);
}
}
......@@ -35,18 +35,21 @@ enum class PieceState {FREE, SELECTED, PICKED, PUT};
class Square;
class Piece : public Object
class Piece : public LogicComponent
{
URHO3D_OBJECT(Piece, Object);
public:
typedef std::bitset<NUM_ATTRIBUTES> Attributes;
Piece(Attributes);
typedef std::bitset<NUM_ATTRIBUTES> PieceAttributes;
Piece(Context* context);
static void RegisterObject(Context* context);
virtual void OnNodeSet(Node* node);
void Init(PieceAttributes attributes);
Node* GetNode() const { return rootNode_; }
void SetPosition(Vector3 pos) { rootNode_->SetPosition(pos); }
Vector3 GetPosition() const { return rootNode_->GetPosition(); }
bool GetAttribute(int index) const { return attributes_[index]; }
Attributes GetAttributes() const { return attributes_; }
Node* GetNode() const { return node_; }
void SetPosition(Vector3 pos) { node_->SetPosition(pos); }
Vector3 GetPosition() const { return node_->GetPosition(); }
bool GetPieceAttribute(int index) const { return attributes_[index]; }
PieceAttributes GetPieceAttributes() const { return attributes_; }
String GetCodon(int length = NUM_ATTRIBUTES) const;
float GetAngle() const { return MC->AttributesToAngle(ToInt()); }
void Select();
......@@ -58,12 +61,13 @@ public:
int ToInt() const { return static_cast<int>(attributes_.to_ulong()); }
private:
SharedPtr<Node> rootNode_;
SharedPtr<StaticModel> pieceModel_;
SharedPtr<StaticModel> outlineModel_;
SharedPtr<Light> light_;
Attributes attributes_;
PieceAttributes attributes_;
PieceState state_;
};
#endif // PIECE_H
......@@ -19,19 +19,26 @@
#include "quattercam.h"
#include <initializer_list>
QuatterCam::QuatterCam():
Object(MC->GetContext()),
void QuatterCam::RegisterObject(Context *context)
{
context->RegisterFactory<QuatterCam>();
}
QuatterCam::QuatterCam(Context* context) : LogicComponent(context),
distance_{12.0f},
aimDistance_{distance_},
targetPosition_{Vector3::UP * 0.42f}
{
rootNode_ = MC->world_.scene_->CreateChild("Camera");
rootNode_->SetPosition(Vector3(3.0f, 10.0f, -8.0f));
rootNode_->LookAt(Vector3::ZERO);
camera_ = rootNode_->CreateComponent<Camera>();
}
void QuatterCam::OnNodeSet(Node *node)
{ (void)node;
node_->SetPosition(Vector3(3.0f, 10.0f, -8.0f));
node_->LookAt(Vector3::ZERO);
camera_ = node_->CreateComponent<Camera>();
camera_->SetFarClip(1024.0f);
Zone* zone{rootNode_->CreateComponent<Zone>()};
Zone* zone{node_->CreateComponent<Zone>()};
zone->SetFogColor(Color(0.20f, 0.17f, 0.13f));
zone->SetFogStart(50.0f);
zone->SetFogEnd(64.0f);
......@@ -39,13 +46,13 @@ QuatterCam::QuatterCam():
CreatePockets();
SetupViewport();
SubscribeToEvent(E_SCENEUPDATE, URHO3D_HANDLER(QuatterCam, HandleSceneUpdate));
}
void QuatterCam::CreatePockets()
{
for (bool p : {true, false}){
Node* pocketNode{rootNode_->CreateChild("Pocket")};
Node* pocketNode{node_->CreateChild("Pocket")};
pocketNode->SetPosition(Vector3(p?2.0f:-2.0f, 1.5f, 3.2f));
pocketNode->SetRotation(Quaternion(-70.0f, Vector3::RIGHT));
if (p)
......@@ -72,24 +79,22 @@ void QuatterCam::SetupViewport()
renderer->SetViewport(0, viewport_);
}
void QuatterCam::HandleSceneUpdate(StringHash eventType, VariantMap& eventData)
void QuatterCam::Update(float timeStep)
{
(void)eventType;
float t{eventData[SceneUpdate::P_TIMESTEP].GetFloat()};
//Update distance
if (aimDistance_ != distance_)
distance_ = 0.1f * (9.0f * distance_ + aimDistance_);
Vector3 relativeToTarget{(rootNode_->GetPosition() - targetPosition_).Normalized()};
Vector3 relativeToTarget{(node_->GetPosition() - targetPosition_).Normalized()};
if (relativeToTarget.Length() != distance_){
rootNode_->SetPosition(distance_ * relativeToTarget + targetPosition_);
node_->SetPosition(distance_ * relativeToTarget + targetPosition_);
camera_->SetFov(Clamp(60.0f + distance_, 23.0f, 110.0f));