1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/scummsys.h"
24 
25 #include "zvision/scripting/effects/distort_effect.h"
26 
27 #include "zvision/zvision.h"
28 #include "zvision/scripting/script_manager.h"
29 #include "zvision/graphics/render_manager.h"
30 #include "zvision/graphics/render_table.h"
31 
32 #include "common/stream.h"
33 
34 namespace ZVision {
35 
DistortNode(ZVision * engine,uint32 key,int16 speed,float startAngle,float endAngle,float startLineScale,float endLineScale)36 DistortNode::DistortNode(ZVision *engine, uint32 key, int16 speed, float startAngle, float endAngle, float startLineScale, float endLineScale)
37 	: ScriptingEffect(engine, key, SCRIPTING_EFFECT_DISTORT) {
38 
39 	_angle = _engine->getRenderManager()->getRenderTable()->getAngle();
40 	_linScale = _engine->getRenderManager()->getRenderTable()->getLinscale();
41 
42 	_speed = speed;
43 	_incr = true;
44 	_startAngle = startAngle;
45 	_endAngle = endAngle;
46 	_startLineScale = startLineScale;
47 	_endLineScale = endLineScale;
48 
49 	_curFrame = 1.0;
50 
51 	_diffAngle = endAngle - startAngle;
52 	_diffLinScale = endLineScale - startLineScale;
53 
54 	_frmSpeed = (float)speed / 15.0;
55 	_frames = (int)ceil((5.0 - _frmSpeed * 2.0) / _frmSpeed);
56 	if (_frames <= 0)
57 		_frames = 1;
58 
59 	if (_key != StateKey_NotSet)
60 		_engine->getScriptManager()->setStateValue(_key, 1);
61 }
62 
~DistortNode()63 DistortNode::~DistortNode() {
64 	setParams(_angle, _linScale);
65 }
66 
process(uint32 deltaTimeInMillis)67 bool DistortNode::process(uint32 deltaTimeInMillis) {
68 	float updTime = deltaTimeInMillis / (1000.0 / 60.0);
69 
70 	if (_incr)
71 		_curFrame += updTime;
72 	else
73 		_curFrame -= updTime;
74 
75 	if (_curFrame < 1.0) {
76 		_curFrame = 1.0;
77 		_incr = true;
78 	} else if (_curFrame > _frames) {
79 		_curFrame = _frames;
80 		_incr = false;
81 	}
82 
83 	float diff = (1.0 / (5.0 - (_curFrame * _frmSpeed))) / (5.0 - _frmSpeed);
84 	setParams(_startAngle + diff * _diffAngle, _startLineScale + diff * _diffLinScale);
85 
86 	return false;
87 }
88 
setParams(float angl,float linScale)89 void DistortNode::setParams(float angl, float linScale) {
90 	RenderTable *table = _engine->getRenderManager()->getRenderTable();
91 	if (table->getRenderState() == RenderTable::PANORAMA) {
92 		table->setPanoramaFoV(angl);
93 		table->setPanoramaScale(linScale);
94 		table->generateRenderTable();
95 		_engine->getRenderManager()->markDirty();
96 	} else if (table->getRenderState() == RenderTable::TILT) {
97 		table->setTiltFoV(angl);
98 		table->setTiltScale(linScale);
99 		table->generateRenderTable();
100 		_engine->getRenderManager()->markDirty();
101 	}
102 }
103 
104 } // End of namespace ZVision
105