예제 #1
0
	//------------------------------------------------------------------------------------------------------
	void RotatingRing::CreateRing( const float& r )
	{
		float bs = 1.5 * r;
		m_BindBox = aabbox3df( vector3f( -bs, -bs, -bs ), vector3f( bs, bs, bs ) );
		m_isMaked = true;
		m_fRadius = r;
		ASSERT( 3 == RC_AXIS );
		VertexColor LineVertex[ RC_AXIS * RC_POINT ];
		for ( int i = 0; i < RC_POINT; i ++ )
		{
			Matrix22f m;
			m.FromRadian( (PI / 180) * i );
			vector2f v( r, 0 );
			v *= m;
			LineVertex[i].SetVertex( vector4f( v.m_x, 0, v.m_y, 1 ) );//ΧÈÆyÖá
			LineVertex[i].SetColor( Color( 1, 0, 0, 1) );

			LineVertex[i+RC_POINT].SetVertex( vector4f( 0, v.m_x, v.m_y, 1 ) );//ΧÈÆxÖá
			LineVertex[i+RC_POINT].SetColor( Color( 0, 1, 0, 1) );

			LineVertex[i+2*RC_POINT].SetVertex( vector4f( v.m_x, v.m_y, 0, 1 ) );//ΧÈÆxÖá
			LineVertex[i+2*RC_POINT].SetColor( Color( 0, 0, 1, 1) );
		}
		m_pVertexBuffer->FlushVertexBuffer( RC_AXIS * RC_POINT, LineVertex );
	}
예제 #2
0
	//-------------------------------------------------------------------------------------
	void Billboard::SetBillCoordnate( const vector2f& lt, const vector2f& rb )
	{
		m_VertexArray[0].Coordinates() = vector4f( lt.m_x, lt.m_y, 0, 0 );
		m_VertexArray[1].Coordinates() = vector4f( lt.m_x, rb.m_y, 0, 1 );
		m_VertexArray[2].Coordinates() = vector4f( rb.m_x, lt.m_y, 1, 0 );
		m_VertexArray[3].Coordinates() = vector4f( rb.m_x, rb.m_y, 1, 1 );
	}
예제 #3
0
	Billboard::	Billboard( )
	{
		m_VertexArray[0].Coordinates() = vector4f( 0, 0, 0, 0 );
		m_VertexArray[1].Coordinates() = vector4f( 0, 1, 0, 1 );
		m_VertexArray[2].Coordinates() = vector4f( 1, 0, 1, 0 );
		m_VertexArray[3].Coordinates() = vector4f( 1, 1, 1, 1 );
	}
예제 #4
0
	//------------------------------------------------------------------------------------------------------
	void Rect2D::SetRect(const vector2f& leftTop, const vector2f& rightBottom)
	{
		m_pVertexArray[0].SetVertex( vector4f( leftTop.m_x ,		leftTop.m_y ,		0.0 ) );
		m_pVertexArray[1].SetVertex( vector4f( leftTop.m_x ,		rightBottom.m_y ,	0.0 ) );
		m_pVertexArray[2].SetVertex( vector4f( rightBottom.m_x ,	rightBottom.m_y ,	0.0 ) );
		m_pVertexArray[3].SetVertex( vector4f( rightBottom.m_x ,	leftTop.m_y ,		0.0 ) );
		m_pVertexArray[0].SetColor( Color::BloodRed );
		m_pVertexArray[1].SetColor( Color::BloodRed );
		m_pVertexArray[2].SetColor( Color::BloodRed );
		m_pVertexArray[3].SetColor( Color::BloodRed );
		m_pVertexBuffer->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertexArray );
	}
예제 #5
0
void gearScenePreview::reinitPreviewWorld()
{
	if(m_pPreviewWorldPtr)
		m_pPreviewWorldPtr->resetWorld();
	m_pPreviewWorldPtr=monoWrapper::mono_engine_getWorld(1);
	m_pPreviewWorldPtr->getActiveCamera()->setNear(1.0f);
	object3d* light=engine_createLight(m_pPreviewWorldPtr, "Light", gxLight::LIGHT_DIRECTIONAL);
	((gxLight*)light)->setDiffuseColor(vector4f(0.75f, 0.75f, 0.75f, 1.0f));
	((gxLight*)light)->setAmbientColor(vector4f(0.2f, 0.2f, 0.2f, 1.0f));
	((gxLight*)light)->setSpecularColor(vector4f(0.5f, 0.5f, 0.5f, 1.0f));
	((gxLight*)light)->setConstantAttenuation(0.5f);
	light->updatePositionf(-1, -10, 1);
	m_pLightPtr=light;
}
예제 #6
0
	//------------------------------------------------------------------------------------------------------
	Rect2D::Rect2D(const vector2f& leftTop, const vector2f& rightBottom, const Color& color)
	{
		NewRect2D();
		m_pVertexArray[0].SetVertex( vector4f( leftTop.m_x ,		leftTop.m_y ,		0.0 ) );
		m_pVertexArray[1].SetVertex( vector4f( leftTop.m_x ,		rightBottom.m_y ,	0.0 ) );
		m_pVertexArray[2].SetVertex( vector4f( rightBottom.m_x ,	rightBottom.m_y ,	0.0 ) );
		m_pVertexArray[3].SetVertex( vector4f( rightBottom.m_x ,	leftTop.m_y ,		0.0 ) );
		m_pVertexArray[0].SetColor( color );
		m_pVertexArray[1].SetColor( color );
		m_pVertexArray[2].SetColor( color );
		m_pVertexArray[3].SetColor( color );

		m_pVertexBuffer->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertexArray );
	}
예제 #7
0
	//-------------------------------------------------------------------------------------
	void Billboard::SetBillBorad( const vector3f& pos, const vector2f& rectsize )
	{
		//m_VertexArray[0].SetVertex( vector4f( pos.m_x - rectsize.m_x, pos.m_y + rectsize.m_y, pos.m_z, 1.0 ) );
		//m_VertexArray[1].SetVertex( vector4f( pos.m_x - rectsize.m_x, pos.m_y - rectsize.m_y, pos.m_z, 1.0 ) );
		//m_VertexArray[2].SetVertex( vector4f( pos.m_x + rectsize.m_x, pos.m_y + rectsize.m_y, pos.m_z, 1.0 ) );
		//m_VertexArray[3].SetVertex( vector4f( pos.m_x + rectsize.m_x, pos.m_y - rectsize.m_y, pos.m_z, 1.0 ) );
		m_VertexArray[0].SetVertex( vector4f( pos.m_x - rectsize.m_x, pos.m_y + 2*rectsize.m_y, pos.m_z, 1.0 ) );
		m_VertexArray[1].SetVertex( vector4f( pos.m_x - rectsize.m_x, pos.m_y, pos.m_z, 1.0 ) );
		m_VertexArray[2].SetVertex( vector4f( pos.m_x + rectsize.m_x, pos.m_y + 2*rectsize.m_y, pos.m_z, 1.0 ) );
		m_VertexArray[3].SetVertex( vector4f( pos.m_x + rectsize.m_x, pos.m_y, pos.m_z, 1.0 ) );
		for ( int i = 0 ; i < COUNT_OF_VERTEX; i ++ )
		{
			m_VertexArray[i].Normal() = pos;
		}
	}
예제 #8
0
void cloud_object::init_state_sets(batch* b)
{
    static cg_program_file vp("cloud_object.cg");

    state_set_ = b->create_state_set();
    state_set_->set_vertices(this);
    state_set_->set_vertex_program(&vp);
	state_set_->set_texture(0, this);

	float sqrt075 = sqrt(0.75f);
	state_set_->set_vertex_program_parameter(1, vector4f(-0.5f, -sqrt075/2, 0, 0));
	state_set_->set_vertex_program_parameter(2, vector4f(0.5f, -sqrt075/2, 0, 0));
	state_set_->set_vertex_program_parameter(3, vector4f(0, sqrt075/2, 0, 0));

	state_set_->set_blending_mode(state_set::BLEND_ADD);
}
	//--------------------------------------------------------------------------------------
	void PrePixelLightTransform::_SetParameters ()
	{
		Engine& engine = Engine::Instance();
		Device* device = engine.GetDevice();
		Environment* env = engine.GetEnvironment();
		ICamera* camera = engine.GetCamera();

		Matrix44f wvp = *m_pTransform * camera->GetViewProj();

		device->SetShaderParameter(m_hTransform, *m_pTransform);
		if( NULL == m_pColor )
		{
			device->SetShaderParameter(m_hColor, vector4f(1,1,1,1) );
		}
		else
		{
			device->SetShaderParameter(m_hColor, *m_pColor);
		}
		device->SetShaderParameter(m_hNormalTransform, Matrix33f( *m_pTransform ) );
		device->SetShaderParameter(m_hWorldViewProjMatrixLoc, wvp);
		device->SetShaderParameter(m_hLightDirectionLoc, -env->GetCurrentLight().GetWorldDirection());//phong光是像素到光源的方向,所以这里反向
		device->SetShaderParameter(m_hCameraPositionLoc, camera->GetPosition() );
		device->SetShaderParameter(m_hAmbientLoc, env->GetAmbient());
		device->SetShaderParameter(m_hLightLoc, env->GetCurrentLight().GetColor());
		//clean up
		m_pTransform = NULL;
		m_pColor = NULL;
	}
예제 #10
0
//-------------------------------------------------------------------------------------------------------
vector4f BString::GetStringCoordnate( const wstring& wstr )
{
    if ( -1 != m_String.find( wstr ) )
    {
        int beginpos = m_String.find( wstr );
        vector2d begin;
        vector2d tgsize = m_Father->GetStringSize( m_ScreenFontSize, wstr );
        if ( 0 != beginpos )
        {
            int hangCount = 0;
            wstring forwardstr = m_String.substr( 0, beginpos );//得到整个前半段文本
            for ( int i = 0 ; i < forwardstr.size(); i ++ )
            {
                if ( L'\n' == forwardstr[i] )
                {
                    hangCount ++;//记录有多少行
                }
            }
            int lastenter = forwardstr.find_last_of('\n');
            wstring substr = forwardstr.substr( lastenter+1, forwardstr.size()-lastenter );
            vector2d offset = m_Father->GetStringSize( m_ScreenFontSize, substr );//取得前半段文本的尺寸
            begin.m_y = m_MaxHeight * hangCount;
            begin.m_x = offset.m_x;
        }
        vector2d TextureSize = m_pTex->GetSize();
        vector4f coord;
        coord.m_x = static_cast<float>(begin.m_x) / TextureSize.m_x;
        coord.m_y = static_cast<float>(begin.m_y) / TextureSize.m_y;
        coord.m_z = static_cast<float>(begin.m_x+tgsize.m_x) / TextureSize.m_x;
        coord.m_w = static_cast<float>(begin.m_y+tgsize.m_y) / TextureSize.m_y;
        return coord;
    }
    return vector4f();
}
예제 #11
0
	//------------------------------------------------------------------------------------------------------
	void Rect3D::ResetRect3D( const vector3f& ulb, const vector3f& drf )
	{
		m_pVertexArray[0].Position() = vector4f(ulb.m_x, ulb.m_y, drf.m_z);
		m_pVertexArray[1].Position() = vector4f(drf.m_x, ulb.m_y, drf.m_z);
		m_pVertexArray[2].Position() = vector4f(drf.m_x, drf.m_y, drf.m_z);
		m_pVertexArray[3].Position() = vector4f(ulb.m_x, drf.m_y, drf.m_z);
		m_pVertexArray[4].Position() = vector4f(ulb.m_x, ulb.m_y, ulb.m_z);
		m_pVertexArray[5].Position() = vector4f(drf.m_x, ulb.m_y, ulb.m_z);
		m_pVertexArray[6].Position() = vector4f(drf.m_x, drf.m_y, ulb.m_z);
		m_pVertexArray[7].Position() = vector4f(ulb.m_x, drf.m_y, ulb.m_z);
		m_pVertexBuffer->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertexArray );
	}
예제 #12
0
/*---------------------------------------------------------------------------
   Clears the structure.
  ---------------------------------------------------------------------------*/
void FilterSolids::Clear(void)
   {
   Filter::Clear();

   Mat.SetAmbient(vector4f(0.4f, 0.3f, 0.3f, 1.0f));
   Mat.SetDiffuse(vector4f(0.9f, 0.9f, 0.9f, 1.0f));
   Mat.SetSpecular(vector4f(0.6f, 0.6f, 0.5f, 0.0f));
   Mat.SetShininess(45.0f);

   Grid = 1;
   GridNorm = 1.0f;
   Offset = 0.0f;
   UID = 0;

   Near = -1.0f;
   Far = -7.0f;
   Range = Math::Abs(Far - Near);

   Select = Filter::SelectDepth;
   EnableVideo = false;
   EnableDepth = true;
   EnableColour = true;
   }
예제 #13
0
//-------------------------------------------------------------------------------------------------------
BString::BString(StringManager* father, const wstring& wstr, int height, const vector2f& screensize, const vector2d& orgiSize, const Color& clr, RendBuffer* buffer, const vector2d& texSize, const byte* pBuffer )
    :m_String(wstr),
     m_Father( father ),
     m_MaxHeight(height),
     m_isManaged(true),
     m_isShow(true),
     m_fScale(1,1),
     m_StringTextureSize(orgiSize),
     m_ScreenFontSize( screensize ),
     m_eAlign(Center)
{
    m_pTex = NEW Texture2D();
    m_pTex->MakeTexture( Device::PF_A8, 1, texSize, pBuffer );

    const vector2d& resolution = Engine::Instance().GetDevice()->GetResolutionSize();
    m_Size = vector2f(
                 static_cast<float>(orgiSize.m_x) / static_cast<float>(resolution.m_x),
                 static_cast<float>(orgiSize.m_y) / static_cast<float>(resolution.m_y)
             );
    m_Size *= 2.0f;//转换到屏幕级别
    vector2f scrrenPos = m_Size;// * 2.0f;


    vector2f coord;
    coord.m_x = static_cast<float>(orgiSize.m_x) / texSize.m_x;
    coord.m_y = static_cast<float>(orgiSize.m_y) / texSize.m_y;

    m_pVertex = NEW VertexTextureColor[COUNT_OF_VERTEX];
    m_pVertex[0] = VertexTextureColor(vector4f(0,0,0), vector2f(0,0), clr);
    m_pVertex[1] = VertexTextureColor(vector4f(0,-scrrenPos.m_y,0), vector2f(0,coord.m_y), clr);
    m_pVertex[2] = VertexTextureColor(vector4f(scrrenPos.m_x,0,0), vector2f(coord.m_x,0), clr);
    m_pVertex[3] = VertexTextureColor(vector4f(scrrenPos.m_x,-scrrenPos.m_y,0), vector2f(coord.m_x,coord.m_y), clr);

    ASSERT( NULL != buffer );
    m_pRendBuffer = buffer;
    m_pRendBuffer->GetVertexBuffer()->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertex );
}
예제 #14
0
void star_scroller::update(float t)
{
	float f = t * 0.1f;
	float x = fmod(3*(sin(1.5f*f+3) + 1.0f), 2.0f);
	float y = fmod(3*(sin(1.7f*f+1) + 1.0f), 2.0f);
	float z = fmod(5*(sin(2.3f*f) + 1.0f), 1.0f);
	state_set_->set_vertex_program_parameter(0, vector4f(x, y, z, 1.0));

	size_t frame_i = 0;
	while(star_count_frames[frame_i].time < t)
		++frame_i;
	f = (t - star_count_frames[frame_i-1].time)
		/ (star_count_frames[frame_i].time - star_count_frames[frame_i-1].time);
	set_visible_stars(star_count_frames[frame_i-1].count +
		f*(star_count_frames[frame_i].count - star_count_frames[frame_i-1].count));
	//set_visible_stars(1);

	//std::cout << "visible_stars = " << visible_stars_ << std::endl;
	state_set_->set_vertex_range(0, visible_stars_*3);
}
예제 #15
0
	//------------------------------------------------------------------------------------------------------
	Rect3D::Rect3D(const vector3f& ulb, const vector3f& drf, const Color& color)
	{
		m_pVertexArray = NEW VertexColor[COUNT_OF_VERTEX];
		m_pVertexArray[0] = VertexColor( vector4f(ulb.m_x, ulb.m_y, drf.m_z), color ) ;
		m_pVertexArray[1] = VertexColor( vector4f(drf.m_x, ulb.m_y, drf.m_z), color ) ;
		m_pVertexArray[2] = VertexColor( vector4f(drf.m_x, drf.m_y, drf.m_z), color ) ;
		m_pVertexArray[3] = VertexColor( vector4f(ulb.m_x, drf.m_y, drf.m_z), color ) ;
		m_pVertexArray[4] = VertexColor( vector4f(ulb.m_x, ulb.m_y, ulb.m_z), color ) ;
		m_pVertexArray[5] = VertexColor( vector4f(drf.m_x, ulb.m_y, ulb.m_z), color ) ;
		m_pVertexArray[6] = VertexColor( vector4f(drf.m_x, drf.m_y, ulb.m_z), color ) ;
		m_pVertexArray[7] = VertexColor( vector4f(ulb.m_x, drf.m_y, ulb.m_z), color ) ;

		static ushort Indies[COUNT_OF_INDIES]={	0,1, 1,2, 2,3, 3,0,
			0,4, 1,5, 2,6, 3,7,
			4,5, 5,6, 6,7, 7,4};

		m_pRendBuffer = NEW RendBuffer( Device::RM_LINES );
		m_pVertexBuffer = NEW VertexBuffer( Device::MU_DYNAMIC );
		m_pIndicesBuffer = NEW IndicesBuffer( Device::MU_STATIC );
		m_pRendBuffer->SetVertexBuffer( m_pVertexBuffer );
		m_pRendBuffer->SetIndicesBuffer( m_pIndicesBuffer );
		m_pVertexBuffer->FlushVertexBuffer( COUNT_OF_VERTEX, m_pVertexArray );
		m_pIndicesBuffer->FlushIndiesBuffer( COUNT_OF_INDIES, &Indies[0] );
	}
예제 #16
0
	state_set_->set_blending_mode(state_set::BLEND_ADD);
}

void cloud_object::remove_state_sets(batch* b)
{
	b->remove_state_set(state_set_);
}

// At time t:
// Change number of stars
// Change object
// Change color
// Change scale
cloud_object::key_frame cloud_object::key_frames[7] = {
	{ 0, NONE, vector4f(1.0f, 0.0f, 1.0f), 0.25f, 0},
	{ 68.0f, SPHERE, vector4f(0.1f, 0.0f, 1.0f), 0.25f, 50000},
	{ 90.0f, CUBE, vector4f(0.15f, 1.0f, 0.0f), 0.15f, 50000},
	{ 120.0f, TORUS, vector4f(0.1f, 0.1f, 1.0f), 0.35f, 50000},
	{ 140.0f, BROKEN_TORUS, vector4f(0.8f, 0.1f, 0.0f), 0.23f, 50000},
	{ 178.0f, NONE, vector4f(0.8f, 0.1f, 0.0f), 0.23f, 0},
	{ 1000.0f, NONE, vector4f(1.0f, 0.0f, 1.0f), 0.25f, 0}
};

void cloud_object::update(float t)
{
	float pitch = 1.0f;
	float roll = 1.3f;
	float yaw = 0.7f;

	float dt = t - last_time_;
예제 #17
0
	//------------------------------------------------------------------------------------------------------
	void GridNode::MakeGrid( const vector3f& center, float size, int grids )
	{
		int Lines = (grids+1)*2;
		float addtion = size / grids;
		float begin = - size / 2;
		m_BindBox.Reset();
		m_BindBox.Contains( vector3f( center.m_x + begin, center.m_y, center.m_z + begin ) );
		m_BindBox.Contains( vector3f( center.m_x - begin, center.m_y, center.m_z - begin ) );
		VertexColor* linever = NEW VertexColor[Lines*2];
		for ( int i = 0 ; i < Lines / 2; i ++ )//×ÝÏß
		{
			if ( i == Lines / 4 )
			{
				linever[i*2].SetColor( Color(0,0,1,1) );
				linever[i*2+1].SetColor( Color(0,0,1,1) );
			}
			else
			{
				linever[i*2].SetColor( Color::White );
				linever[i*2+1].SetColor( Color::White );
			}
			linever[i*2].SetVertex( vector4f( 
				center.m_x+begin+addtion*i,
				center.m_y,
				center.m_z+begin
				) );
			linever[i*2+1].SetVertex( vector4f( 
				center.m_x+begin+addtion*i,
				center.m_y,
				center.m_z+begin+size
				) );
		}
		for ( int i = Lines / 2, j = 0 ; i < Lines ; i ++, j ++ )//×ÝÏß
		{
			if ( i == 3* Lines / 4 )
			{
				linever[i*2].SetColor( Color(1,0,0,1) );
				linever[i*2+1].SetColor( Color(1,0,0,1) );
			}
			else
			{
				linever[i*2].SetColor( Color::White );
				linever[i*2+1].SetColor( Color::White );
			}
			linever[i*2].SetVertex( vector4f( 
				center.m_x+begin,
				center.m_y,
				center.m_z+begin+addtion*j
				) );
			linever[i*2+1].SetVertex( vector4f( 
				center.m_x+begin+size,
				center.m_y,
				center.m_z+begin+addtion*j
				) );
		}
		vector<ushort> Indies;
		for ( int i = 0; i < Lines * 2; i ++ )
		{
			Indies.push_back(i);
		}
		m_pVertexBuffer->FlushVertexBuffer( Lines*2, linever );
		m_pIndicesBuffer->FlushIndiesBuffer( Indies.size(), &Indies[0] );
		SAFE_DELETE_ARRAY(linever);
	}
예제 #18
0
			LinkElement::LinkElement(const ref_ptr<Element>& parent) :
				Element(parent),
				state(LinkState::INACTIVE)
			{
				setRect(vector4f());
			}
예제 #19
0
			HeadElement::HeadElement(const ref_ptr<Element>& parent) :
				Element(parent)
			{
				setRect(vector4f());
			}
예제 #20
0
/*---------------------------------------------------------------------------
   Class specific setup function for the effects assets.
  ---------------------------------------------------------------------------*/
void FilterSolids::Assets(Buffers &Buffer)
   {
   if (!Ready()) {return;}

   vector2u Res = Buffer.GetDepthResolution();
   Depth.Create(Res, Buffer.GetDepthDataType());
   Depth.ClearData();
   Depth.Buffer(false);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glPushMatrix();
   Light.SetPosition(vector4f(0.5f, -0.5f, Near + 1.0f, 0.0f));
   Light.Buffer(0);
   glPopMatrix();

   Grid = Res / GridDiv;
   Grid = Grid.Clamp(GridMin, GridMax);
   GridNorm = cast_vector2(float, Grid);
   GridNorm = GridNorm.Rcp();
   uint GridSmallest = Math::Min(Grid.U, Grid.V);

   Offset = cast_vector2(float, Grid);
   Offset = (Offset - 1.0f) * 0.5f;

   //Geometry subdivisions for curved solids
   uint PolyDiv = (Math::Min(Res.U, Res.V) / GridSmallest) / PolyDivPixels;
   PolyDiv = Math::Clamp(PolyDiv, PolyDivMin, PolyDivMax);

   File::Text Text;
   std::string CodeVert, CodeFrag;

   switch (Type)
      {
      case FilterSolids::Cubes :
         Model.Cube(1, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         Mat.SetShininess(0.0f);
         break;

      case FilterSolids::Spheres :
         Model.Sphere(PolyDiv, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         break;

      case FilterSolids::CubesTinted :
         Model.Cube(1, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsVideoVert));
         Video.Create(Buffer.GetVideoResolution(), Buffer.GetVideoDataType());
         Video.ClearData();
         Video.Buffer(false);
         EnableVideo = true;
         EnableDepth = true;
         EnableCal = true;
         Mat.SetShininess(0.0f);
         break;

      case FilterSolids::SpheresTinted :
         Model.Sphere(PolyDiv, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsVideoVert));
         Video.Create(Buffer.GetVideoResolution(), Buffer.GetVideoDataType());
         Video.ClearData();
         Video.Buffer(false);
         EnableVideo = true;
         EnableDepth = true;
         EnableCal = true;
         break;

      case FilterSolids::CubesFar :
         Model.Cube(1, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         Mat.SetShininess(0.0f);
         Far = -1000.0f;
         break;

      case FilterSolids::SpheresFar :
         Model.Sphere(PolyDiv, Mesh::ModeSolid);
         Text.Load(CodeVert, File::Path::Shader(File::FilterSolidsDepthVert));
         EnableVideo = false;
         EnableDepth = true;
         EnableCal = false;
         Far = -1000.0f;
         break;

      default : dexception("Unknown filter enumeration type.");
      }

   Range = Math::Abs(Far - Near);

   Model.Buffer(false);

   Text.Load(CodeFrag, File::Path::Shader(File::FilterSolidsFrag));
   Program.Attach(CodeVert, Shader::ShaderVert);
   Program.Attach(CodeFrag, Shader::ShaderFrag);
   Program.Buffer(false);

   Program.Bind();
   glUniform1f(glGetUniformLocation(Program.ID(), "Range"), Math::Abs(Range));
   glUniform1i(glGetUniformLocation(Program.ID(), "Depth"), 0);   //Texture unit 0
   glUniform1i(glGetUniformLocation(Program.ID(), "Video"), 1);   //Texture unit 1
   UID = glGetUniformLocation(Program.ID(), "TexCoord");
   glUniform2f(UID, 0.0f, 0.0f);
   Program.Unbind();

   //Projection matrix
   MP = MP.Identity();
   MP = MP.Frustum(-Ratio.X, Ratio.X, -Ratio.Y, Ratio.Y, Math::Abs(Near), Math::Abs(Far));

   //Modelview matrix
   float Scale = 1.0f / (float)GridSmallest;
   MV = MV.Identity();
   MV = MV.Scale(Scale, Scale, Scale);
   MV = MV.Translate(0.0f, 0.0f, (Near - Scale - 0.01f) / Scale);

   GLenum Error = glGetError();
   if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   }
예제 #21
0
 inline Vector4 toVector4f(const Vector3 &v)
 {
     return vector4f(v(0,0),v(1,0),v(2,0),1);
 }
예제 #22
0
NE_API void set_color(float red, float green, float blue, float alpha) {
	set_color_uniform(vector4f(red, green, blue, alpha));
}
예제 #23
0
void Space::CreateTestScene(Entity player, double time)
{
	auto renderer = p3::game->GetRenderer();
	m_renderer = renderer;

	StarSystemCache::ShrinkCache(SystemPath(), true);
	Sector::cache.ClearCache();
	SystemPath path(10,0,0,0);
	m_starSystem = StarSystemCache::GetCached(path);

	GenBody(time, m_starSystem->m_rootBody.Get(), m_rootFrame.get());
	m_rootFrame->UpdateOrbitRails(time, 1.0);

	//init "player"
	{
		auto model = p3::game->GetModelCache()->FindModel("kanara");
		SDL_assert(model);
		player.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		player.assign<PosOrientComponent>(vector3d(0,0,1e6), matrix3x3d(1.0));
		player.assign<MassComponent>(10.0);
		player.assign<DynamicsComponent>();
		player.assign<ThrusterComponent>();
		player.assign<WeaponComponent>();
		player.assign<PlayerInputComponent>();
		player.assign<CollisionMeshComponent>(player, model->GetCollisionMesh());
		player.assign<FrameComponent>(GetRootFrame());
		//player.assign<ColorComponent>(Color(0,255,255,255));
		player.assign<ShipAIComponent>();
		player.assign<NameComponent>("Player");

		GetRootFrame()->GetCollisionSpace()->AddGeom(player.component<CollisionMeshComponent>()->geom.get());
	}

	//init "AI"
	{
		auto model = p3::game->GetModelCache()->FindModel("natrix");
		SDL_assert(model);
		Entity ship = m_entities->create();
		ship.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		ship.assign<PosOrientComponent>(vector3d(0,0,1e6 - 200), matrix3x3d(1.0));
		ship.assign<MassComponent>(10.0);
		ship.assign<DynamicsComponent>();
		ship.assign<ThrusterComponent>();
		ship.assign<WeaponComponent>();
		ship.assign<CollisionMeshComponent>(ship, model->GetCollisionMesh());
		ship.assign<FrameComponent>(GetRootFrame());
		ship.assign<ColorComponent>(Color(255,0,0,255));
		ship.assign<ShipAIComponent>();
		ship.assign<NameComponent>("Drone");
		ship.assign<AICommandComponent>(); //kamikaze
		auto aicmd = ship.component<AICommandComponent>();
		aicmd->SetKamikaze(player);

		GetRootFrame()->GetCollisionSpace()->AddGeom(ship.component<CollisionMeshComponent>()->geom.get());
	}

	//some scenery
	//Entity obstacle = m_entities->create();
	if (0)
	{
		Entity obstacle = m_entities->create();
		auto model = p3::game->GetModelCache()->FindModel("kbuilding02");
		obstacle.assign<PosOrientComponent>(vector3d(0, 0, -200), matrix3x3d(1.0));
		obstacle.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		obstacle.assign<MassComponent>(100.0);
		obstacle.assign<DynamicsComponent>();
		obstacle.assign<CollisionMeshComponent>(obstacle, model->GetCollisionMesh());
		obstacle.assign<FrameComponent>(GetRootFrame());

		GetRootFrame()->GetCollisionSpace()->AddGeom(obstacle.component<CollisionMeshComponent>()->geom.get());

		Entity hangAroundMember = m_entities->create();
		hangAroundMember.assign<PosOrientComponent>(vector3d(0.0), matrix3x3d(1.0));
		hangAroundMember.assign<AttachToEntityComponent>(obstacle, vector3d(0, 50, 0));
		hangAroundMember.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		hangAroundMember.assign<FrameComponent>(GetRootFrame());
	}

	//init camera
	//left camera
	if (0)
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		camc->camera->viewport = vector4f(0.f, 0.f, 0.5f, 1.f);
		camc->camera->clearColor = Color(0, 40, 0, 0);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(0, 50, 100), matrix3x3d(1.0));
		camera.assign<CameraLookAtComponent>(player);
		camera.assign<FrameComponent>(GetRootFrame());
		//camera.assign<AttachToEntityComponent>(player, vector3d(0, 5, 50));
	}

	//right top camera
	if (0)
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		camc->camera->viewport = vector4f(0.5f, 0.5f, 0.5f, 0.5f);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(100, -10, -10), matrix3x3d(1.0));
		//camera.assign<CameraLookAtComponent>(obstacle);
		camera.assign<FrameComponent>(GetRootFrame());
	}
	//right bottom camera
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		//camc->camera->clearColor = Color(10, 10, 10, 0);
		camc->camera->viewport = vector4f(0.0f, 0.f, 1.0f, 1.0f);
		//camc->camera->viewport = vector4f(0.5f, 0.f, 0.5f, 1.0f);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(0, 0, 0), matrix3x3d(1.0));
		camera.assign<AttachToEntityComponent>(player, vector3d(0, 5, 10));
		camera.assign<FrameComponent>(GetRootFrame());
	}
}