-
Notifications
You must be signed in to change notification settings - Fork 2
/
TTscene.cpp
127 lines (106 loc) · 3.74 KB
/
TTscene.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright © 2013 Tom Tondeur
//
// This file is part of tt::Engine.
//
// tt::Engine 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 3 of the License, or
// (at your option) any later version.
//
// tt::Engine 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 tt::Engine. If not, see <http://www.gnu.org/licenses/>.
// __ __ ______ _
// / /_/ /__ _ / ____/___ ____ _(_)___ ___
// / __/ __(_|_) __/ / __ \/ __ `/ / __ \/ _ \
// / /_/ /__ _ / /___/ / / / /_/ / / / / / __/
// \__/\__(_|_)_____/_/ /_/\__, /_/_/ /_/\___/
// /____/
//
// TTscene.cpp
//
#include "TTscene.h"
#include "SceneObjects/FreeCamera.h"
#include "SceneObjects/Object3D.h"
#include "SceneObjects/Object3DStatic.h"
#include "SceneObjects/ParticleSystem.h"
#include "SceneObjects/Skybox.h"
#include "SceneObjects/Terrain.h"
#include "Services/ServiceLocator.h"
#include "Graphics/SpriteFont.h"
#include "Graphics/PostProcessingEffect.h"
#include "Graphics/Materials/PostProcessing/BlurMaterial.h"
#include "Graphics/GraphicsDevice.h"
#include "Services/InputEnums.h"
static ScriptComponent* g_pScript = nullptr;
bool g_bAutoCam = false;
void SetDemoScene(int iScene)
{
tt::g_SceneIndex = iScene;
}
void SetAutoCamera(bool bAutoCamera)
{
g_bAutoCam = bAutoCamera;
}
static void InitializeLuaScript()
{
LuaLink::LuaFunction::Register(SetDemoScene, "SetDemoScene");
LuaLink::LuaFunction::Register(SetAutoCamera, "SetAutoCamera");
}
TTscene::TTscene(void)
{
try{
g_pScript = new ScriptComponent(_T("Resources/Scripts/TestScript.lua"));
g_pScript->Load(InitializeLuaScript);
}
catch(LuaLoadException& e)
{
OutputDebugStringA(e.what());
}
}
TTscene::~TTscene(void)
{
delete g_pScript;
}
//Methods
void TTscene::Initialize(void)
{
m_pCam = new FreeCamera();
AddSceneObject(m_pCam);
SetActiveCamera(m_pCam->GetComponent<CameraComponent>());
AddSceneObject(new Object3D(_T("Resources/goblin.ttmesh")));
AddSceneObject(new Object3DStatic(_T("Resources/Models/environment.ttmesh")));
AddSceneObject(new Skybox());
auto pBlurMat = new BlurMaterial();
pBlurMat->LoadEffect();
AddPostProcessingEffect(new PostProcessingEffect(pBlurMat), 0);
//AddSceneObject(new ParticleSystem() );
AddSceneObject( new Terrain( tt::Vector3(100,30,100), 6, _T("Resources/Textures/HeightMap_128x128x16.raw") ) );
MyServiceLocator::GetInstance()->GetService<IInputService>()->AddInputAction(InputActionId::ToggleVSync, 'V', KeyState::Pressed);
g_pScript->Initialize();
}
void TTscene::Update(const tt::GameContext& context)
{
if(MyServiceLocator::GetInstance()->GetService<IInputService>()->IsActionTriggered(InputActionId::ToggleVSync)){
tcout << _T("Toggle") << endl;
MyServiceLocator::GetInstance()->GetService<IGraphicsService>()->GetGraphicsDevice()->ToggleVSync();
}
D3DXMATRIX tempView, tempProj;
D3DXMatrixLookAtLH(&tempView, &D3DXVECTOR3(100,200,100), &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,0,1));
D3DXMatrixOrthoLH(&tempProj, 500, 500, 10, 1000);
auto lightView = tt::Matrix4x4(tempView);
auto lightProj = tt::Matrix4x4(tempProj);
Material::SetDominantDirectionalLightViewProjection(lightView * lightProj);
delete g_pScript;
g_pScript = new ScriptComponent(_T("Resources/Scripts/TestScript.lua"));
g_pScript->Load(InitializeLuaScript);
g_pScript->Initialize();
g_pScript->Update(context);
}
void TTscene::Draw(const tt::GameContext& context)
{
}