Example #1
0
NitsEndTest

NitsTestWithSetup(TestResizeToShrink, TestArraySetup)
{
    Array<TestCreateDestroyClass> v;

    v.Resize(100);

    v.Resize(10);

    UT_ASSERT(v.GetSize() == 10);
    TestAllItemsAreValid(v);
}
Example #2
0
//==================================
// VRMenuMgrLocal::CondenseList
// keeps the free list from growing too large when items are removed
void VRMenuMgrLocal::CondenseList()
{
	// we can only condense the array if we have a significant number of items at the end of the array buffer
	// that are empty (because we cannot move an existing object around without changing its handle, too, which
	// would invalidate any existing references to it).  
	// This is the difference between the current size and the array capacity.
	int const MIN_FREE = 64;	// very arbitray number
	if ( ObjectList.GetCapacityI() - ObjectList.GetSizeI() < MIN_FREE )
	{
		return;
	}

	// shrink to current size
	ObjectList.Resize( ObjectList.GetSizeI() );	

	// create a new free list of just indices < the new size
	Array< int > newFreeList;
	for ( int i = 0; i < FreeList.GetSizeI(); ++i ) 
	{
		if ( FreeList[i] <= ObjectList.GetSizeI() )
		{
			newFreeList.PushBack( FreeList[i] );
		}
	}
	FreeList = newFreeList;
}
Example #3
0
// Get fake Poisson taps in one-third sections of
// the unit hemisphere for doing directional AO.
void MeshCompiler::GetAmbientOcclusionTaps( Array< Vector >& Taps, const Matrix& TangentSpace )
{
	Taps.Clear();
	Taps.Resize( 51 );
	Taps[0] = Vector( 0.0f, 0.81649700000000003f, 0.57735000000000003f );
	Taps[1] = Vector( -0.74401973459062531f, 0.57783472685691717f, 0.33547229837631554f );
	Taps[2] = Vector( 0.25901018724643815f, 0.68792466879887804f, 0.67799216290494024f );
	Taps[3] = Vector( -0.58988856970793446f, 0.80685558587873407f, 0.031867520521874151f );
	Taps[4] = Vector( 0.26882545565790789f, 0.93007621426021569f, 0.25038192837683715f );
	Taps[5] = Vector( 0.0041285378312679675f, 0.52339192756451713f, 0.85208206490670535f );
	Taps[6] = Vector( 0.52300845383744843f, 0.83589430002845266f, 0.16656192960729299f );
	Taps[7] = Vector( 0.67164601369536103f, 0.61759181590387924f, 0.40923340676889991f );
	Taps[8] = Vector( -0.38725619624135338f, 0.76349261896781795f, 0.51682846211711353f );
	Taps[9] = Vector( 0.55273004695713479f, 0.56155706754364609f, 0.61574601507646354f );
	Taps[10] = Vector( 0.72493806462362065f, 0.68525434936331431f, 0.069937680390617263f );
	Taps[11] = Vector( -0.57003909323433155f, 0.74767366048824102f, 0.34064575382161405f );
	Taps[12] = Vector( -0.4883240745402157f, 0.56430943593345706f, 0.66565340736820811f );
	Taps[13] = Vector( 0.24691230716222037f, 0.50036658190736905f, 0.82985998595074195f );
	Taps[14] = Vector( -0.26737561786638481f, 0.53293155768514677f, 0.80280398217363869f );
	Taps[15] = Vector( -0.33103794538084164f, 0.93594428249487172f, 0.12009237604107406f );
	Taps[16] = Vector( 0.076679712920537185f, 0.99461859155774424f, 0.069671220414983512f );

	Matrix FirstSection = Matrix::CreateRotationAboutZ( -TWOPI / 3.0f );
	Matrix ThirdSection = Matrix::CreateRotationAboutZ( TWOPI / 3.0f );

	for( uint i = 0; i < 17; ++i )
	{
		Vector Tap = Taps[ i ];
		Taps[ i ] = ( Tap * FirstSection ) * TangentSpace;
		Taps[ i + 17 ] = Tap * TangentSpace;
		Taps[ i + 34 ] = ( Tap * ThirdSection ) * TangentSpace;
	}
}
Example #4
0
void SimpleString::FillArray( Array<char>& OutArray, bool WithNull /*= false*/ ) const
{
	const uint Length = WithNull ? m_Length + 1 : m_Length;
	OutArray.Clear();
	OutArray.Resize( Length );
	memcpy_s( OutArray.GetData(), Length, m_String, Length );
}
Example #5
0
GlGeometry BuildSpherePatch( const float fov )
{
	const int horizontal = 64;
	const int vertical = 64;
	const float radius = 100.0f;

	const int vertexCount = (horizontal + 1) * (vertical + 1);

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y <= vertical; y++ )
	{
		const float yf = (float) y / (float) vertical;
		const float lat = (yf - 0.5) * fov;
		const float cosLat = cosf(lat);
		for ( int x = 0; x <= horizontal; x++ )
		{
			const float xf = (float) x / (float) horizontal;
			const float lon = ( xf - 0.5f ) * fov;
			const int index = y * ( horizontal + 1 ) + x;

			attribs.position[index].x = radius * cosf( lon ) * cosLat;
			attribs.position[index].z = radius * sinf( lon ) * cosLat;
			attribs.position[index].y = radius * sinf( lat );

			// center in the middle of the screen for roll rotation
			attribs.uv0[index].x = xf - 0.5f;
			attribs.uv0[index].y = ( 1.0f - yf ) - 0.5f;

			for ( int i = 0 ; i < 4 ; i++ )
			{
				attribs.color[index][i] = 1.0f;
			}
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( horizontal * vertical * 6 );

	int index = 0;
	for ( int x = 0; x < horizontal; x++ )
	{
		for ( int y = 0; y < vertical; y++ )
		{
			indices[index + 0] = y * (horizontal + 1) + x;
			indices[index + 1] = y * (horizontal + 1) + x + 1;
			indices[index + 2] = (y + 1) * (horizontal + 1) + x;
			indices[index + 3] = (y + 1) * (horizontal + 1) + x;
			indices[index + 4] = y * (horizontal + 1) + x + 1;
			indices[index + 5] = (y + 1) * (horizontal + 1) + x + 1;
			index += 6;
		}
	}

	return GlGeometry( attribs, indices );
}
Example #6
0
GlGeometry BuildTesselatedQuad( const int horizontal, const int vertical )
{
	const int vertexCount = ( horizontal + 1 ) * ( vertical + 1 );

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y <= vertical; y++ )
	{
		const float yf = (float) y / (float) vertical;
		for ( int x = 0; x <= horizontal; x++ )
		{
			const float xf = (float) x / (float) horizontal;
			const int index = y * ( horizontal + 1 ) + x;
			attribs.position[index].x = -1 + xf * 2;
			attribs.position[index].z = 0;
			attribs.position[index].y = -1 + yf * 2;
			attribs.uv0[index].x = xf;
			attribs.uv0[index].y = 1.0 - yf;
			for ( int i = 0; i < 4; i++ )
			{
				attribs.color[index][i] = 1.0f;
			}
			// fade to transparent on the outside
			if ( x == 0 || x == horizontal || y == 0 || y == vertical )
			{
				attribs.color[index][3] = 0.0f;
			}
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( horizontal * vertical * 6 );

	// If this is to be used to draw a linear format texture, like
	// a surface texture, it is better for cache performance that
	// the triangles be drawn to follow the side to side linear order.
	int index = 0;
	for ( int y = 0; y < vertical; y++ )
	{
		for ( int x = 0; x < horizontal; x++ )
		{
			indices[index + 0] = y * (horizontal + 1) + x;
			indices[index + 1] = y * (horizontal + 1) + x + 1;
			indices[index + 2] = (y + 1) * (horizontal + 1) + x;
			indices[index + 3] = (y + 1) * (horizontal + 1) + x;
			indices[index + 4] = y * (horizontal + 1) + x + 1;
			indices[index + 5] = (y + 1) * (horizontal + 1) + x + 1;
			index += 6;
		}
	}

	return GlGeometry( attribs, indices );
}
Example #7
0
GlGeometry BuildTesselatedCylinder( const float radius, const float height, const int horizontal, const int vertical, const float uScale, const float vScale )
{
	const int vertexCount = ( horizontal + 1 ) * ( vertical + 1 );

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y <= vertical; ++y )
	{
		const float yf = (float) y / (float) vertical;
		for ( int x = 0; x <= horizontal; ++x )
		{
			const float xf = (float) x / (float) horizontal;
			const int index = y * ( horizontal + 1 ) + x;
			attribs.position[index].x = cosf( M_PI * 2 * xf ) * radius;
			attribs.position[index].y = sinf( M_PI * 2 * xf ) * radius;
			attribs.position[index].z = -height + yf * 2 * height;
			attribs.uv0[index].x = xf * uScale;
			attribs.uv0[index].y = ( 1.0f - yf ) * vScale;
			for ( int i = 0; i < 4; ++i )
			{
				attribs.color[index][i] = 1.0f;
			}
			// fade to transparent on the outside
			if ( y == 0 || y == vertical )
			{
				attribs.color[index][3] = 0.0f;
			}
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( horizontal * vertical * 6 );

	// If this is to be used to draw a linear format texture, like
	// a surface texture, it is better for cache performance that
	// the triangles be drawn to follow the side to side linear order.
	int index = 0;
	for ( int y = 0; y < vertical; y++ )
	{
		for ( int x = 0; x < horizontal; x++ )
		{
			indices[index + 0] = y * (horizontal + 1) + x;
			indices[index + 1] = y * (horizontal + 1) + x + 1;
			indices[index + 2] = (y + 1) * (horizontal + 1) + x;
			indices[index + 3] = (y + 1) * (horizontal + 1) + x;
			indices[index + 4] = y * (horizontal + 1) + x + 1;
			indices[index + 5] = (y + 1) * (horizontal + 1) + x + 1;
			index += 6;
		}
	}

	return GlGeometry( attribs, indices );
}
Example #8
0
NitsEndTest

NitsTestWithSetup(TestDeleteTheOnlyOne, TestArraySetup)
{
    Array<TestCreateDestroyClass> v;

    v.Resize(1);

    v.Delete(0);

    UT_ASSERT(v.GetSize() == 0);
}
Example #9
0
/**
*  @brief
*    This function loads a '.ogg' file into a memory buffer and returns
*    the format and frequency
*/
bool LoadOGG(File *pFile, Array<uint8> &lstBuffer, ALenum &nFormat, ALsizei &nFrequency)
{
	bool bResult = false; // Error by default
	if (pFile) {
		// Try opening the given file
		OggVorbis_File oggFile;
		ov_callbacks ovc;
		ovc.read_func  = &SoundManager::read_func;
		ovc.seek_func  = &SoundManager::seek_func;
		ovc.close_func = &SoundManager::close_func;
		ovc.tell_func  = &SoundManager::tell_func;
		if (ov_open_callbacks(pFile, &oggFile, nullptr, 0, ovc) == 0) {
			// Get some information about the OGG file
			vorbis_info *pInfo = ov_info(&oggFile, -1);

			// Check the number of channels... always use 16-bit samples
			nFormat = (pInfo->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;

			// The frequency of the sampling rate
			nFrequency = pInfo->rate;

			// Set to no error
			bResult = true;

			// Keep reading until all is read
			lstBuffer.Resize(pFile->GetSize()*100, false);
			static const uint32 BufferSize = 8192;	// 8 KB buffers
			uint8 nArray[BufferSize];				// Local fixed size array
			int nEndian = 0;						// 0 for Little-Endian, 1 for Big-Endian
			int nBitStream;
			long nBytes;
			do {
				// Read up to a buffer's worth of decoded sound data
				nBytes = ov_read(&oggFile, reinterpret_cast<char*>(nArray), BufferSize, nEndian, 2, 1, &nBitStream);
				if (nBytes < 0) {
					// Error!
					bResult = false;
				} else {
					// Append to end of buffer
					lstBuffer.Add(nArray, nBytes);
				}
			} while (nBytes>0);

			// Cleanup (OpenAL takes over the file reference)
			ov_clear(&oggFile);
		}
	}

	// Done
	return bResult;
}
void ScanLineComputer::SetSize(wxSize size)
{
	Array<double> tmp;
	tmp.Resize(3);

	height = size.GetHeight();
	width = size.GetWidth();
	left.Resize(height);
	right.Resize(height);
	leftweight.Resize(height);
	rightweight.Resize(height);
	leftweight.Fill(tmp);
	rightweight.Fill(tmp);
}
Example #11
0
NitsEndTest

NitsTestWithSetup(TestGetWritableData, TestArraySetup)
{
    Array< int > v;

    v.Resize(3);

    v.GetWritableData() [0] = 0;
    v.GetWritableData() [1] = 1;
    v.GetWritableData() [2] = 2;

    UT_ASSERT(0 == v[0]);
    UT_ASSERT(1 == v[1]);
    UT_ASSERT(2 == v[2]);
}
/*virtual*/ void GL2ShaderProgram::Initialize( IVertexShader* const pVertexShader, IPixelShader* const pPixelShader, IVertexDeclaration* const pVertexDeclaration )
{
	XTRACE_FUNCTION;

	m_VertexShader	= pVertexShader;
	m_PixelShader	= pPixelShader;

	ASSERT( m_VertexShader );
	ASSERT( m_PixelShader );

	m_ShaderProgram = glCreateProgram();
	ASSERT( m_ShaderProgram != 0 );

	GLuint VertexShader = *static_cast<GLuint*>( m_VertexShader->GetHandle() );
	ASSERT( VertexShader != 0 );
	glAttachShader( m_ShaderProgram, VertexShader );

	GLuint PixelShader = *static_cast<GLuint*>( m_PixelShader->GetHandle() );
	ASSERT( PixelShader != 0 );
	glAttachShader( m_ShaderProgram, PixelShader );

	BindAttributes( pVertexDeclaration );

	glLinkProgram( m_ShaderProgram );
	GLERRORCHECK;

	GLint LinkStatus;
	glGetProgramiv( m_ShaderProgram, GL_LINK_STATUS, &LinkStatus );

	if( LinkStatus != GL_TRUE )
	{
		GLint LogLength;
		glGetProgramiv( m_ShaderProgram, GL_INFO_LOG_LENGTH, &LogLength );
		Array<GLchar>	Log;
		Log.Resize( LogLength );
		glGetProgramInfoLog( m_ShaderProgram, LogLength, NULL, Log.GetData() );
		if( LogLength > 0 )
		{
			PRINTF( "GLSL shader program link failed:\n" );
			PRINTF( Log.GetData() );
		}
		WARNDESC( "GLSL shader program link failed" );
	}

	BuildUniformTable();
	SetSamplerUniforms();
}
Example #13
0
void Crypto::Decrypt( const Array< char >& Ciphertext, const Array< char >& Key, Array< char >& OutPlaintext )
{
	ARC4Initialize( Key );

	uint8 Nonce = Ciphertext[ Ciphertext.Size() - 1 ];
	for( uint Step = 0; Step < Nonce + FixedStep; ++Step )
	{
		ARC4Step();
	}

	OutPlaintext.Clear();
	OutPlaintext.Resize( Ciphertext.Size() - Overhead );

	for( uint Index = 0; Index < Ciphertext.Size() - Overhead; ++Index )
	{
		OutPlaintext[ Index ] = Ciphertext[ Index ] ^ ARC4Step();
	}
}
Example #14
0
void PackVertexAttribute( Array< uint8_t > & packed, const Array< _attrib_type_ > & attrib,
				const int glLocation, const int glType, const int glComponents )
{
	if ( attrib.GetSize() > 0 )
	{
		const size_t offset = packed.GetSize();
		const size_t size = attrib.GetSize() * sizeof( attrib[0] );

		packed.Resize( offset + size );
		memcpy( &packed[offset], attrib.GetDataPtr(), size );

		glEnableVertexAttribArray( glLocation );
		glVertexAttribPointer( glLocation, glComponents, glType, false, sizeof( attrib[0] ), (void *)( offset ) );
	}
	else
	{
		glDisableVertexAttribArray( glLocation );
	}
}
Example #15
0
GlGeometry BuildUnitCubeLines()
{
	VertexAttribs attribs;
	attribs.position.Resize( 8 );

	for ( int i = 0; i < 8; i++) {
		attribs.position[i][0] = i & 1;
		attribs.position[i][1] = ( i & 2 ) >> 1;
		attribs.position[i][2] = ( i & 4 ) >> 2;
	}

	const TriangleIndex staticIndices[24] = { 0,1, 1,3, 3,2, 2,0, 4,5, 5,7, 7,6, 6,4, 0,4, 1,5, 3,7, 2,6 };

	Array< TriangleIndex > indices;
	indices.Resize( 24 );
	memcpy( &indices[0], staticIndices, 24 * sizeof( indices[0] ) );

	return GlGeometry( attribs, indices );
}
void GL2PixelShader::Initialize( const IDataStream& Stream )
{
	XTRACE_FUNCTION;

	const int Length	= Stream.Size();
	byte* pBuffer		= new byte[ Length ];
	Stream.Read( Length, pBuffer );

	m_PixelShader = glCreateShader( GL_FRAGMENT_SHADER );
	ASSERT( m_PixelShader != 0 );

	// Copy the GLSL source
	const GLsizei	NumStrings		= 1;
	const GLchar*	Strings[]		= { reinterpret_cast<GLchar*>( pBuffer ) };
	const GLint		StringLengths[]	= { Length };	// I don't trust this file to be null-terminated, so explicitly declare the length.
	glShaderSource( m_PixelShader, NumStrings, Strings, StringLengths );

	// Compile the shader
	glCompileShader( m_PixelShader );
	GLERRORCHECK;

	GLint CompileStatus;
	glGetShaderiv( m_PixelShader, GL_COMPILE_STATUS, &CompileStatus );

	if( CompileStatus != GL_TRUE )
	{
		GLint LogLength;
		glGetShaderiv( m_PixelShader, GL_INFO_LOG_LENGTH, &LogLength );
		Array<GLchar>	Log;
		Log.Resize( LogLength );
		glGetShaderInfoLog( m_PixelShader, LogLength, NULL, Log.GetData() );
		if( LogLength > 0 )
		{
			PRINTF( "GLSL fragment shader compile failed:\n" );
			PRINTF( Log.GetData() );
		}
		WARNDESC( "GLSL fragment shader compile failed" );
	}

	SafeDeleteArray( pBuffer );
}
Example #17
0
void Crypto::Encrypt( const Array< char >& Plaintext, const Array< char >& Key, Array< char >& OutCiphertext )
{
	ARC4Initialize( Key );

	uint8 Nonce = (char)Math::Random( 256 );
	for( uint Step = 0; Step < Nonce + FixedStep; ++Step )
	{
		ARC4Step();
	}

	OutCiphertext.Clear();
	OutCiphertext.Resize( Plaintext.Size() + Overhead );

	for( uint Index = 0; Index < Plaintext.Size(); ++Index )
	{
		OutCiphertext[ Index ] = Plaintext[ Index ] ^ ARC4Step();
	}

	// Sign the array with the nonce we chose
	OutCiphertext[ OutCiphertext.Size() - 1 ] = Nonce;
}
Example #18
0
			bool GuiColorDialog::ShowDialog()
			{
				Array<Color> colors;
				CopyFrom(colors, customColors);
				colors.Resize(16);

				INativeDialogService::ColorDialogCustomColorOptions options =
					!enabledCustomColor ? INativeDialogService::CustomColorDisabled :
					!openedCustomColor ? INativeDialogService::CustomColorEnabled :
					INativeDialogService::CustomColorOpened;

				auto service = GetCurrentController()->DialogService();
				if (!service->ShowColorDialog(GetHostWindow()->GetNativeWindow(), selectedColor, showSelection, options, &colors[0]))
				{
					return false;
				}

				CopyFrom(customColors, colors);
				SelectedColorChanged.Execute(GuiEventArgs());
				return true;
			}
Example #19
0
SimpleString SimpleString::Replace( const char* const Find, const char* const Replace ) const
{
	DEVASSERT( Find );
	DEVASSERT( Replace );

	Array<char> NewStringBuffer;
	NewStringBuffer.Resize( m_Length + 1 );
	memcpy( NewStringBuffer.GetData(), m_String, m_Length + 1	);

	const size_t FindLength		= strlen( Find );
	const size_t ReplaceLength	= strlen( Replace );
	const size_t Difference		= ReplaceLength - FindLength;

	for( size_t Iterator = 0; Iterator < NewStringBuffer.Size(); )
	{
		const char* const		SubStr	= strstr( NewStringBuffer.GetData() + Iterator, Find );
		if( SubStr )
		{
			const char* const	Base	= NewStringBuffer.GetData();
			const size_t		Offset	= SubStr - Base;

			for( size_t DifferenceIndex = 0; DifferenceIndex < Difference; ++DifferenceIndex )
			{
				NewStringBuffer.Insert( 0, static_cast<uint>( Offset ) );
			}

			memcpy( NewStringBuffer.GetData() + Offset, Replace, ReplaceLength );

			Iterator += ReplaceLength;
		}
		else
		{
			break;
		}
	}

	return SimpleString( NewStringBuffer );
}
Example #20
0
//==============================
// VRMenuMgrLocal::Finish
void VRMenuMgrLocal::Finish( Matrix4f const & viewMatrix )
{
	if ( NumSubmitted == 0 )
	{
		return;
	}

	Matrix4f invViewMatrix = viewMatrix.Inverted(); // if the view is never scaled or sheared we could use Transposed() here instead
	Vector3f viewPos = invViewMatrix.GetTranslation();

	// sort surfaces
	SortKeys.Resize( NumSubmitted );
	for ( int i = 0; i < NumSubmitted; ++i )
	{
		// the sort key is a combination of the distance squared, reinterpreted as an integer, and the submission index
		// this sorts on distance while still allowing submission order to contribute in the equal case.
		float distSq = ( Submitted[i].Pose.Position - viewPos ).LengthSq();
		int64_t sortKey = *reinterpret_cast< unsigned* >( &distSq );
		SortKeys[i].Key = ( sortKey << 32ULL ) | i;
	}
	
	Alg::QuickSort( SortKeys );
}
Example #21
0
MIDIEvent* MIDI::EventFactory( const uint8 EventCode, const IDataStream& Stream ) const
{
	const uint8 MIDIEventType = ( EventCode & 0xF0 ) >> 4;

	if( MIDIEventType == 0x08 )
	{
		// Note off
		return new MIDINoteOffEvent();
	}
	else if( MIDIEventType == 0x09 )
	{
		// Note on
		return new MIDINoteOnEvent();
	}
	else if( MIDIEventType == 0x0A )
	{
		// Note aftertouch
	}
	else if( MIDIEventType == 0x0B )
	{
		// Controller
		return new MIDIControllerEvent();
	}
	else if( MIDIEventType == 0x0C )
	{
		// Program change
		return new MIDIProgramChangeEvent();
	}
	else if( MIDIEventType == 0x0D )
	{
		// Channel aftertouch
	}
	else if( MIDIEventType == 0x0E )
	{
		// Pitch bend
		return new MIDIPitchBendEvent();
	}
	else if( EventCode == 0xF0 || EventCode == 0xF7 )
	{
		// SysEx event

		// For now, skip SysEx events because I don't care (TODO: I'll need to load them to resave them, though)
		const uint SysExLength = LoadVariableLengthValue( Stream );
		Stream.Skip( SysExLength );

		//PRINTF( "Skipped SysEx of length %d\n", SysExLength );

		return NULL;
	}
	else if( EventCode == 0xFF )
	{
		// Meta event
		const uint8 MetaType = Stream.ReadUInt8();
		Unused( MetaType );

		// For now, skip meta events because I don't care (TODO: I'll need to load them to resave them, though)
		const uint MetaLength = LoadVariableLengthValue( Stream );
		//Stream.Skip( MetaLength );
		Array<uint8> MetaString;
		MetaString.Resize( MetaLength );
		Stream.Read( MetaLength, MetaString.GetData() );
		MetaString.PushBack( '\0' );

		//PRINTF( "Skipped meta (0x%02X) of length %d\n", MetaType, MetaLength );
		//PRINTF( "%s\n", MetaString.GetData() );

		return NULL;
	}
	else
	{
		// Unknown event
		WARN;
		return NULL;
	}

	// Not yet handled
	WARN;
	return NULL;
}
Example #22
0
Bool_T Postsolver::GetRowData( Real_T &val, Int_T &len, // )
	Array<Real_T> &a, Array<Int_T> &ind )
{
	//--------------------------------------------------------------------------
	//	Read the removed variable's coefficient in the row in question.
	//
	if( !Lexer::GetSpace() )
	{
		Error( "Premature end of section." );
		return False;
	}

	if( !Lexer::GetKeyword( "VALUE" ) || !Lexer::GetSpace() ||
		!Lexer::GetNumeric() )
	{
		Error( "Variable's coefficient expected." );
		return False;
	}

	val = Lexer::Number;

	Lexer::GetNewline( True );

	//--------------------------------------------------------------------------
	//	Read the row's coefficients.
	//
	{
		Int_T max_len = 10;
		a.Resize( max_len);		a.Fill( 0.0, max_len );
		ind.Resize( max_len );	ind.Fill( -1, max_len );

		for( len = 0; Lexer::GetSpace(); len++ )
		{
			if( !Lexer::GetKeyword( "COEFF" ) || !Lexer::GetSpace() )
			{
				Error( "Matrix coefficient expected." );
				return False;
			}

			if( len >= max_len )
			{
				Int_T new_max_len = Int_T( Max( max_len + 10, 3*max_len/2 ) );

				a.Resize( new_max_len );
				ind.Resize( new_max_len );

				a.Fill( 0.0, new_max_len, max_len );
				ind.Fill( -1, new_max_len, max_len );

				max_len = new_max_len;
			}

			if( !Lexer::GetNumeric() || !Lexer::GetSpace() )
			{
				Error( "Variable index expected." );
				return False;
			}
			ind[len]	= (Int_T) Lexer::Number;

			if( !Lexer::GetNumeric() )
			{
				Error( "Matrix coefficient expected." );
				return False;
			}

			a[len]		= Lexer::Number;

			if( ind[len] < 0 || ind[len] >= n )
			{
				Error( "Variable index out of range: %d", ind[len] );
				return False;
			}
			Lexer::GetNewline( True );
		}
	}
	
	return True;
}
Example #23
0
GlGeometry BuildGlobe( const float uScale, const float vScale )
{
	// Make four rows at the polar caps in the place of one
	// to diminish the degenerate triangle issue.
	const int poleVertical = 3;
	const int uniformVertical = 64;
	const int horizontal = 128;
	const int vertical = uniformVertical + poleVertical*2;
	const float radius = 100.0f;

	const int vertexCount = ( horizontal + 1 ) * ( vertical + 1 );

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y <= vertical; y++ )
	{
		float yf;
		if ( y <= poleVertical )
		{
			yf = (float)y / (poleVertical+1) / uniformVertical;
		}
		else if ( y >= vertical - poleVertical )
		{
			yf = (float) (uniformVertical - 1 + ( (float)( y - (vertical - poleVertical - 1) ) / ( poleVertical+1) ) ) / uniformVertical;
		}
		else
		{
			yf = (float) ( y - poleVertical ) / uniformVertical;
		}
		const float lat = ( yf - 0.5f ) * M_PI;
		const float cosLat = cosf( lat );
		for ( int x = 0; x <= horizontal; x++ )
		{
			const float xf = (float) x / (float) horizontal;
			const float lon = ( 0.5f + xf ) * M_PI * 2;
			const int index = y * ( horizontal + 1 ) + x;

			if ( x == horizontal )
			{
				// Make sure that the wrap seam is EXACTLY the same
				// xyz so there is no chance of pixel cracks.
				attribs.position[index] = attribs.position[y * ( horizontal + 1 ) + 0];
			}
			else
			{
				attribs.position[index].x = radius * cosf( lon ) * cosLat;
				attribs.position[index].z = radius * sinf( lon ) * cosLat;
				attribs.position[index].y = radius * sinf( lat );
			}

			// With a normal mapping, half the triangles degenerate at the poles,
			// which causes seams between every triangle.  It is better to make them
			// a fan, and only get one seam.
			if ( y == 0 || y == vertical )
			{
				attribs.uv0[index].x = 0.5f;
			}
			else
			{
				attribs.uv0[index].x = xf * uScale;
			}
			attribs.uv0[index].y = ( 1.0 - yf ) * vScale;
			for ( int i = 0; i < 4; i++ )
			{
				attribs.color[index][i] = 1.0f;
			}
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( horizontal * vertical * 6 );

	int index = 0;
	for ( int x = 0; x < horizontal; x++ )
	{
		for ( int y = 0; y < vertical; y++ )
		{
			indices[index + 0] = y * (horizontal + 1) + x;
			indices[index + 1] = y * (horizontal + 1) + x + 1;
			indices[index + 2] = (y + 1) * (horizontal + 1) + x;
			indices[index + 3] = (y + 1) * (horizontal + 1) + x;
			indices[index + 4] = y * (horizontal + 1) + x + 1;
			indices[index + 5] = (y + 1) * (horizontal + 1) + x + 1;
			index += 6;
		}
	}

	return GlGeometry( attribs, indices );
}
Example #24
0
// To guarantee that the edge pixels are completely black, we need to
// have a band of solid 0.  Just interpolating to 0 at the edges will
// leave some pixels with low color values.  This stuck out as surprisingly
// visible smears from the distorted edges of the eye renderings in
// some cases.
GlGeometry BuildVignette( const float xFraction, const float yFraction )
{
	// Leave 25% of the vignette as solid black
	const float posx[] = { -1.001f, -1.0f + xFraction * 0.25f, -1.0f + xFraction, 1.0f - xFraction, 1.0f - xFraction * 0.25f, 1.001f };
	const float posy[] = { -1.001f, -1.0f + yFraction * 0.25f, -1.0f + yFraction, 1.0f - yFraction, 1.0f - yFraction * 0.25f, 1.001f };

	const int vertexCount = 6 * 6;

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y < 6; y++ )
	{
		for ( int x = 0; x < 6; x++ )
		{
			const int index = y * 6 + x;
			attribs.position[index].x = posx[x];
			attribs.position[index].y = posy[y];
			attribs.position[index].z = 0.0f;
			attribs.uv0[index].x = 0.0f;
			attribs.uv0[index].y = 0.0f;
			// the outer edges will have 0 color
			const float c = ( y <= 1 || y >= 4 || x <= 1 || x >= 4 ) ? 0.0f : 1.0f;
			for ( int i = 0; i < 3; i++ )
			{
				attribs.color[index][i] = c;
			}
			attribs.color[index][3] = 1.0f;	// solid alpha
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( 24 * 6 );

	int index = 0;
	for ( int x = 0; x < 5; x++ )
	{
		for ( int y = 0; y < 5; y++ )
		{
			if ( x == 2 && y == 2 )
			{
				continue;	// the middle is open
			}
			// flip triangulation at corners
			if ( x == y )
			{
				indices[index + 0] = y * 6 + x;
				indices[index + 1] = (y + 1) * 6 + x + 1;
				indices[index + 2] = (y + 1) * 6 + x;
				indices[index + 3] = y * 6 + x;
				indices[index + 4] = y * 6 + x + 1;
				indices[index + 5] = (y + 1) * 6 + x + 1;
			}
			else
			{
				indices[index + 0] = y * 6 + x;
				indices[index + 1] = y * 6 + x + 1;
				indices[index + 2] = (y + 1) * 6 + x;
				indices[index + 3] = (y + 1) * 6 + x;
				indices[index + 4] = y * 6 + x + 1;
				indices[index + 5] = (y + 1) * 6 + x + 1;
			}
			index += 6;
		}
	}

	return GlGeometry( attribs, indices );
}
Example #25
0
GlGeometry BuildCalibrationLines( const int extraLines, const bool fullGrid )
{
	// lines per axis
	const int lineCount = 1 + extraLines * 2;
	const int vertexCount = lineCount * 2 * 2;

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y < lineCount; y++ )
	{
		const float yf = ( lineCount == 1 ) ? 0.5f : (float) y / (float) ( lineCount - 1 );
		for ( int x = 0; x <= 1; x++ )
		{
			// along x
			const int v1 = 2 * ( y * 2 + x ) + 0;
			attribs.position[v1].x = -1 + x * 2;
			attribs.position[v1].z = -1.001f;	// keep the -1 and 1 just off the projection edges
			attribs.position[v1].y = -1 + yf * 2;
			attribs.uv0[v1].x = x;
			attribs.uv0[v1].y = 1.0f - yf;
			for ( int i = 0; i < 4; i++ )
			{
				attribs.color[v1][i] = 1.0f;
			}

			// swap y and x to go along y
			const int v2 = 2 * ( y * 2 + x ) + 1;
			attribs.position[v2].y = -1 + x * 2;
			attribs.position[v2].z = -1.001f;	// keep the -1 and 1 just off the projection edges
			attribs.position[v2].x = -1 + yf * 2;
			attribs.uv0[v2].x = x;
			attribs.uv0[v2].y = 1.0f - yf;
			for ( int i = 0; i < 4; i++ )
			{
				attribs.color[v2][i] = 1.0f;
			}

			if ( !fullGrid && y != extraLines )
			{	// make a short hash instead of a full line
				attribs.position[v1].x *= 0.02f;
				attribs.position[v2].y *= 0.02f;
			}
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( lineCount * 4 );

	int index = 0;
	for ( int x = 0; x < lineCount; x++ )
	{
		const int start = x * 4;

		indices[index + 0] = start;
		indices[index + 1] = start + 2;

		indices[index + 2] = start + 1;
		indices[index + 3] = start + 3;

		index += 4;
	}
	return GlGeometry( attribs, indices );
}
Example #26
0
GlGeometry BuildDome( const float latRads, const float uScale, const float vScale )
{
	const int horizontal = 64;
	const int vertical = 32;
	const float radius = 100.0f;

	const int vertexCount = ( horizontal + 1 ) * ( vertical + 1 );

	VertexAttribs attribs;
	attribs.position.Resize( vertexCount );
	attribs.uv0.Resize( vertexCount );
	attribs.color.Resize( vertexCount );

	for ( int y = 0; y <= vertical; y++ )
	{
		const float yf = (float) y / (float) vertical;
		const float lat = M_PI - yf * latRads - 0.5f * M_PI;
		const float cosLat = cosf( lat );
		for ( int x = 0; x <= horizontal; x++ )
		{
			const float xf = (float) x / (float) horizontal;
			const float lon = ( 0.5f + xf ) * M_PI * 2;
			const int index = y * ( horizontal + 1 ) + x;

			if ( x == horizontal )
			{
				// Make sure that the wrap seam is EXACTLY the same
				// xyz so there is no chance of pixel cracks.
				attribs.position[index] = attribs.position[y * ( horizontal + 1 ) + 0];
			}
			else
			{
				attribs.position[index].x = radius * cosf( lon ) * cosLat;
				attribs.position[index].z = radius * sinf( lon ) * cosLat;
				attribs.position[index].y = radius * sinf( lat );
			}

			attribs.uv0[index].x = xf * uScale;
			attribs.uv0[index].y = ( 1.0f - yf ) * vScale;
			for ( int i = 0; i < 4; i++ )
			{
				attribs.color[index][i] = 1.0f;
			}
		}
	}

	Array< TriangleIndex > indices;
	indices.Resize( horizontal * vertical * 6 );

	int index = 0;
	for ( int x = 0; x < horizontal; x++ )
	{
		for ( int y = 0; y < vertical; y++ )
		{
			indices[index + 0] = y * (horizontal + 1) + x;
			indices[index + 1] = y * (horizontal + 1) + x + 1;
			indices[index + 2] = (y + 1) * (horizontal + 1) + x;
			indices[index + 3] = (y + 1) * (horizontal + 1) + x;
			indices[index + 4] = y * (horizontal + 1) + x + 1;
			indices[index + 5] = (y + 1) * (horizontal + 1) + x + 1;
			index += 6;
		}
	}

	return GlGeometry( attribs, indices );
}