void TestReflection()
{
    {
        void *obj = Create("Hoge");
        CallMemberFunction(obj, "Hoge", "ExecHoge");
        Delete(obj, "Hoge");
    }
    {
        void *obj = Create("Hage");
        CallMemberFunction(obj, "Hage", "ExecHage");
        Delete(obj, "Hage");
    }
}
int main(int argc, char* argv[])
{
  MyClass myDoubler(2.);

  std::cout << CallMemberFunction(&myDoubler, &MyClass::Multiply, 2., 3.)
            << std::endl;
}
示例#3
0
void CRibbonComponent::Update()
{
	float frame_length = Tmr::FrameLength();
	
	// update link positions based on velocity
	for (int n = m_num_links; n--; )
	{
		Mth::Vector vel = mp_links[n].p - mp_links[n].last_p;
		vel *= 1.0f / m_last_frame_length;
		
		// damp
		vel -= 10.0f * frame_length * vel;
		
		// momentum
		mp_links[n].next_p = mp_links[n].p + frame_length * vel;
		
		// gravity
		mp_links[n].next_p[Y] -= 800.0f * frame_length * frame_length;
	}
	
	// fetch bone position
	Mth::Vector bone_p;
	mp_skeleton_component->GetBonePosition(m_bone_name, &bone_p);
	bone_p = GetObject()->GetMatrix().Rotate(bone_p);
	bone_p += GetObject()->GetPos();
	
	// update link constraints
	for (int c = 20; c--; )
	{
		// first link special case
		float length = (mp_links[0].next_p - bone_p).Length();
		Mth::Vector axis = (mp_links[0].next_p - bone_p) * (1.0f / length);
		float adjustment = m_link_length - length;
		mp_links[0].next_p += adjustment * axis;
		
		// second and subsequent links
		for (int n = 1; n < m_num_links; n++)
		{
			float length = (mp_links[n].next_p - mp_links[n - 1].next_p).Length();
			Mth::Vector axis = (mp_links[n].next_p - mp_links[n - 1].next_p) * (1.0f / length);
			
			float adjustment = 0.5f * (m_link_length - length);
			
			// hack
			if (length > 20.0f * m_link_length)
			{
				CallMemberFunction(CRCD(0x796084f4, "Ribbon_Reset"), NULL, NULL);
				return;
			}
			
			mp_links[n].next_p += adjustment * axis;
			mp_links[n - 1].next_p -= adjustment * axis;
		}
	}
	
	#if 0
	
	// cheap collision detection
	float min_y = GetObject()->GetPos()[Y] + 0.1f;
	for (int n = m_num_links; n--; )
	{
		mp_links[n].next_p[Y] = Mth::ClampMin(mp_links[n].next_p[Y], min_y);
	}
	
	#else
	
	Mth::CBBox bbox;
	Nx::CCollCache* p_coll_cache = Nx::CCollCacheManager::sCreateCollCache();
	for (int n = m_num_links; n--; )
	{
		bbox.AddPoint(mp_links[n].p);
		bbox.AddPoint(mp_links[n].next_p);
	}
	p_coll_cache->Update(bbox);
	
	CFeeler feeler;
	feeler.SetCache(p_coll_cache);
	// real collision detection
	for (int n = m_num_links; n--; )
	{
		feeler.m_start = mp_links[n].p;
		feeler.m_end = mp_links[n].next_p;
		if (!feeler.GetCollision()) continue;
		
		Mth::Vector movement = mp_links[n].next_p - mp_links[n].p;
		
		mp_links[n].next_p = feeler.GetPoint() + 0.1f * feeler.GetNormal();
		
		// assume no additional collision
		movement *= 1.0f - feeler.GetDist();
		movement.ProjectToPlane(feeler.GetNormal());
		
		mp_links[n].next_p += movement;
	}
	
	Nx::CCollCacheManager::sDestroyCollCache(p_coll_cache);
	
	#endif
	
	// update state
	for (int n = m_num_links; n--; )
	{
		mp_links[n].last_p = mp_links[n].p;
		mp_links[n].p = mp_links[n].next_p;
	}
	m_last_frame_length = frame_length;
	
	// debug draw
	Gfx::AddDebugLine(bone_p, mp_links[0].p, m_color, 0, 1);
	for (int n = 1; n < m_num_links; n++)
	{
		Gfx::AddDebugLine(mp_links[n].p, mp_links[n - 1].p, m_color, 0, 1);
	}
}