コード例 #1
0
//===========================================================================
// A coordinate system is layed out on the plane and the texture is
// scaled into the first quadrant of that system.  UV coordintes
// will go outside of the range [0,1]x[0,1] if the given surface point
// is not in the square of this first quadrant.
/*virtual*/ bool Plane::CalculateTextureCoordinates( const c3ga::vectorE3GA& point, c3ga::vectorE3GA& textureCoordinates ) const
{
	c3ga::bivectorE3GA plane = c3ga::gp( normal, c3ga::I3 );

	c3ga::vectorE3GA uAxis, vAxis;

	uAxis.set( c3ga::vectorE3GA::coord_e1_e2_e3, 1.0, 0.0, 0.0 );
	uAxis = c3ga::lc( c3ga::lc( uAxis, plane ), c3ga::reverse( plane ) );
	if( c3ga::norm( uAxis ) == 0.0 )
	{
		uAxis.set( c3ga::vectorE3GA::coord_e1_e2_e3, 0.0, 1.0, 0.0 );
		uAxis = c3ga::lc( c3ga::lc( uAxis, plane ), c3ga::reverse( plane ) );
		if( c3ga::norm( uAxis ) == 0.0 )
		{
			uAxis.set( c3ga::vectorE3GA::coord_e1_e2_e3, 0.0, 0.0, 1.0 );
			uAxis = c3ga::lc( c3ga::lc( uAxis, plane ), c3ga::reverse( plane ) );
			if( c3ga::norm( uAxis ) == 0.0 )
				return false;
		}
	}

	uAxis = c3ga::unit( uAxis );
	vAxis = c3ga::gp( c3ga::op( normal, uAxis ), c3ga::I3 );

	c3ga::vectorE3GA vector = point - center;

	// This works, because the UV axes are orthonormal.
	double u = c3ga::lc( vector, uAxis ) / textureScale;
	double v = c3ga::lc( vector, vAxis ) / textureScale;

	textureCoordinates.set( c3ga::vectorE3GA::coord_e1_e2_e3, u, v, 0.0 );
	return true;
}
コード例 #2
0
ファイル: Node.cpp プロジェクト: spencerparkin/Junk
//=================================================================================
/*static*/ bool Node::ReadVectorE3GA( lua_State* L, Context& context, const std::string& name, c3ga::vectorE3GA& vector, const c3ga::vectorE3GA* defaultValue /*= 0*/ )
{
	bool success = false;
	int top = lua_gettop( L );

	try
	{
		if( defaultValue )
			vector = *defaultValue;
		else
			vector.set( c3ga::vectorE3GA::coord_e1_e2_e3, 0.0, 0.0, 0.0 );

		lua_getfield( L, -1, name.c_str() );
		if( lua_isnil( L, -1 ) || !lua_istable( L, -1 ) )
		{
			if( context.GetNodeReadingDisposition() == Context::NONEXISTENCE_OF_FIELD_IS_FATAL_ERROR )
				throw new Error( "ReadVectorE3GA failed to read \"%s\" as a table.", name.c_str() );
		}
		else
		{
			if( !ReadNumber( L, context, "x", vector.m_e1, 0.0 ) )
				throw new Error( "ReadVectorE3GA failed to read \"x\" from \"%s\".", name.c_str() );

			if( !ReadNumber( L, context, "y", vector.m_e2, 0.0 ) )
				throw new Error( "ReadVectorE3GA failed to read \"y\" from \"%s\".", name.c_str() );

			if( !ReadNumber( L, context, "z", vector.m_e3, 0.0 ) )
				throw new Error( "ReadVectorE3GA failed to read \"z\" from \"%s\".", name.c_str() );
		}

		// Pop the vector table.
		lua_pop( L, 1 );

		success = true;
	}
	catch( Error* error )
	{
		context.IssueError( error );
	}

	lua_settop( L, top );

	return success;
}