summaryrefslogtreecommitdiff
path: root/src/rotatingcube.cpp
blob: 4b04c2bef4f20d9afaa24003d73d20495e4fc52c (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "rotatingcube.h"

bool ScreenRotatingCube::loadCubePlugin()
{
	if (!CompPlugin::checkPluginABI ("cube", COMPIZ_CUBE_ABI))
	    return false;

	return true;
}

bool ScreenRotatingCube::enable()
{
	if( !loadCubePlugin() )
		return false;
		
	CubeScreen *cs = ss->cubeScreen;

	ss->mZCamera = 0.0;
	ss->mCubeRotX = 0.0;
	ss->mCubeRotV = 0.0;
	cs->rotationState (CubeScreen::RotationManual);

	ss->cubeScreen->cubeGetRotationSetEnabled (ss, true);
	
	return ScreenEffect::enable();
}

void ScreenRotatingCube::disable()
{
	ss->mZCameraFadeOut = ss->mZCamera;
	ss->mCubeRotXFadeOut = ss->mCubeRotX;
	ss->mCubeRotVFadeOut = ss->mCubeRotV;

	ss->cubeScreen->cubeGetRotationSetEnabled (ss, false);
	
	ScreenEffect::disable();
}

void ScreenRotatingCube::clean()
{
	ss->cubeScreen->rotationState (CubeScreen::RotationNone);
}

void ScreenRotatingCube::cubeGetRotation( float& x, float& v, float &progress )
{
	ScreenEffect::cubeGetRotation( x, v, progress );

	x += ss->mCubeRotX;
	v += ss->mCubeRotV;
	progress = MAX (progress, ss->mCubeProgress);
}

void ScreenRotatingCube::preparePaint (int msSinceLastPaint )
{	
	ScreenEffect::preparePaint ( msSinceLastPaint );
	
	float rotX = ss->optionGetCubeRotationSpeed ()/100.0;
	float rotV = 0.0;
	
	if( ss->mState.fadingIn )
	{
		rotX *= getProgress();
		ss->mZCamera = -ss->optionGetCubeZoom() * getProgress();
		ss->mCubeProgress = getProgress();
	}
	else if( ss->mState.fadingOut )
	{
		ss->mZCamera = ss->mZCameraFadeOut * (1-getProgress());
		ss->mCubeRotX = ss->mCubeRotXFadeOut * (1-getProgress());
		ss->mCubeRotV = ss->mCubeRotVFadeOut * (1-getProgress());
		ss->mCubeProgress = 1 - getProgress();
	}
	
	if( !ss->mState.fadingOut )
	{
		ss->mCubeRotX += rotX * msSinceLastPaint;
		ss->mCubeRotV += rotV * msSinceLastPaint;
	}
	if( ss->mCubeRotX > 180.0 ) ss->mCubeRotX -= 360.0;
	if( ss->mCubeRotX < -180.0 ) ss->mCubeRotX += 360.0;
}

void ScreenRotatingCube::donePaint()
{
	ss->cScreen->damageScreen();
	ScreenEffect::donePaint();
}

bool ScreenRotatingCube::glPaintOutput (const GLScreenPaintAttrib &attrib,
			          	const GLMatrix		 &transform,
				  	const CompRegion		 &region,
				  	CompOutput		 *output,
				  	unsigned int		mask)
{
	GLScreenPaintAttrib sA (attrib);
	sA.zCamera += ss->mZCamera;
	
	mask &= ~PAINT_SCREEN_REGION_MASK;
	mask |= PAINT_SCREEN_TRANSFORMED_MASK;
	return ScreenEffect::glPaintOutput( sA, transform, region, output, mask );
}