2 * Copyright © 2010-2013 Team XBMC
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "angelscript.h"
24 struct TunnelParameters
39 float Min( float x, float y )
44 float Max( float x, float y )
49 float ApplySinX(int i, float time)
51 const float radian = (i/40.0f*(2.0f*3.14159f));
52 float returnvalue = sinf(radian/2.0f+time)+6.0f*cosf(radian/4.0f+time);//+6*cosf((radian+time)/10.0f);
53 return returnvalue*1.0f;
56 float ApplySinY(int i, float time)
58 const float radian = (i/40.0f*(2.0f*3.14159f));
59 float returnvalue = 3.0f*sinf(radian/8.0f+time)+3.0f*cosf(radian/2.0f+time)*sinf(radian/4.0f+time);
60 return returnvalue*0.2f;
63 void RenderTunnel( TunnelParameters& tp )
65 int TunnelLength = max( min( tp.TunnelLength, 100 ), 2 );
66 int CircleSegments = max( min( tp.CircleSegments, 30 ), 3 );
68 // Renderer::RotateAxis(atanf((ApplySinX(3, tp.XCounter)-ApplySinX(0,tp.XCounter))/3.0f)*(180.0f/3.14159f), 0.0f, 1.0f, 0.0f);
69 // Renderer::RotateAxis(atanf((ApplySinY(0,tp.YCounter)-ApplySinY(7, tp.YCounter))/7.0f)*(180.0f/3.14159f), 1.0f, 0.0f, 0.0f);
71 Renderer::RotateAxis( (tp.RotateZ) * 45, 0, 0, 1 );
73 Renderer::Translate( -ApplySinX( 0, tp.XCounter ), -ApplySinY( 0, tp.YCounter ), 0.0f );
75 for ( int z = 0; z < CircleSegments; z++ )
77 Renderer::Begin( D3DPT_TRIANGLESTRIP );
78 for ( int i = 0; i < TunnelLength; i++ )
80 float col = 1-(((1.0f * i / TunnelLength))*1);
81 Renderer::Colour( col, col, col, col );
82 Renderer::TexCoord( 1-((float)z/CircleSegments*4.0f),
83 1 - ( (float)i / TunnelLength * 8 + tp.TunnelZ ) );
84 Renderer::Vertex( tp.XRadius * sinf( (float)z / CircleSegments * ( 2.0f * 3.14159f ) ) + ApplySinX( i, tp.XCounter ),
85 tp.YRadius * cosf( (float)z / CircleSegments * ( 2.0f * 3.14159f ) ) + ApplySinY( i, tp.YCounter ),
87 Renderer::TexCoord( 1 - ( ( (float)z + 1 ) / CircleSegments * 4.0f ),
88 1 - ( (float)i / TunnelLength * 8 + tp.TunnelZ ) );
89 Renderer::Vertex( tp.XRadius * sinf( ( (float)z + 1 ) / CircleSegments * ( 2.0f * 3.14159f ) ) + ApplySinX( i, tp.XCounter ),
90 tp.YRadius * cosf( ( (float)z + 1 ) / CircleSegments * ( 2.0f * 3.14159f ) ) + ApplySinY( i, tp.YCounter ),
101 void Tunnel::RegisterScriptInterface( asIScriptEngine* pScriptEngine )
105 //----------------------------------------------------------------------------
106 // Register Tunnel Parameter structure
107 r = pScriptEngine->RegisterObjectType("TunnelParameters", sizeof(TunnelParameters), asOBJ_VALUE | asOBJ_POD); assert( r >= 0 );
109 // Register the object properties
110 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float Time", offsetof(TunnelParameters, Time)); assert( r >= 0 );
111 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float XRadius", offsetof(TunnelParameters, XRadius)); assert( r >= 0 );
112 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float YRadius", offsetof(TunnelParameters, YRadius)); assert( r >= 0 );
113 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float XCounter", offsetof(TunnelParameters, XCounter)); assert( r >= 0 );
114 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float YCounter", offsetof(TunnelParameters, YCounter)); assert( r >= 0 );
115 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "int CircleSegments", offsetof(TunnelParameters, CircleSegments)); assert( r >= 0 );
116 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "int TunnelLength", offsetof(TunnelParameters, TunnelLength)); assert( r >= 0 );
117 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float TunnelZ", offsetof(TunnelParameters, TunnelZ)); assert( r >= 0 );
118 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float RotateX", offsetof(TunnelParameters, RotateX)); assert( r >= 0 );
119 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float RotateY", offsetof(TunnelParameters, RotateY)); assert( r >= 0 );
120 r = pScriptEngine->RegisterObjectProperty("TunnelParameters", "float RotateZ", offsetof(TunnelParameters, RotateZ)); assert( r >= 0 );
122 r = pScriptEngine->RegisterGlobalFunction("void RenderTunnel(TunnelParameters& in)", asFUNCTION(RenderTunnel), asCALL_CDECL); assert(r >= 0);