Esempio n. 1
0
/*!
SLMesh::preShade calculates the rest of the intersection information 
after the final hit point is determined. Should be called just before the 
shading when the final intersection point of the closest triangle was found.
*/
void SLMesh::preShade(SLRay* ray)
{
   SLFace* hit = ray->hitTriangle;
   
   // calculate the hit point in world space
   ray->hitPoint.set(ray->origin + ray->length * ray->dir);
      
   // calculate the interpolated normal with vertex normals in object space
   ray->hitNormal.set(N[hit->iA] * (1-(ray->hitU+ray->hitV)) + 
                      N[hit->iB] * ray->hitU + 
                      N[hit->iC] * ray->hitV);
                      
   // transform normal back to world space
   ray->hitNormal.set(ray->hitShape->wmN() * ray->hitNormal);
                 
   // invert normal if the ray is inside a shape
   if (!ray->isOutside) ray->hitNormal *= -1;
   
   // for shading the normal is expected to be unit length
   ray->hitNormal.normalize();
   
   // calculate interpolated texture coordinates
   SLVGLTexture& textures = ray->hitMat->textures();
   if (textures.size() > 0)
   {  SLVec2f Tu(Tc[hit->iB] - Tc[hit->iA]);
      SLVec2f Tv(Tc[hit->iC] - Tc[hit->iA]);
      SLVec2f tc(Tc[hit->iA] + ray->hitU*Tu + ray->hitV*Tv);
      ray->hitTexCol.set(textures[0]->getTexelf(tc.x,tc.y));
      
      // bumpmapping
      if (textures.size() > 1)
      {  if (T)
         {  
            // calculate the interpolated tangent with vertex tangent in object space
            SLVec4f hitT(T[hit->iA] * (1-(ray->hitU+ray->hitV)) + 
                         T[hit->iB] * ray->hitU + 
                         T[hit->iC] * ray->hitV);
                         
            SLVec3f T3(hitT.x,hitT.y,hitT.z);         // tangent with 3 components
            T3.set(ray->hitShape->wmN() * T3);        // transform tangent back to world space
            SLVec2f d = textures[1]->dsdt(tc.x,tc.y);  // slope of bumpmap at tc
            SLVec3f N = ray->hitNormal;               // unperturbated normal
            SLVec3f B(N^T3);                          // binormal tangent B
            B *= T[hit->iA].w;                        // correct handedness
            SLVec3f D(d.x*T3 + d.y*B);                // perturbation vector D
            N+=D;
            N.normalize();
            ray->hitNormal.set(N);
         }
      }
   }
}
Esempio n. 2
0
void enum_mobile_devices(pfc::list_t<device_instance_info_t> & p_out)
{
	HDEVINFO di = SetupDiGetClassDevs(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);

	if (di != INVALID_HANDLE_VALUE)
	{
		SP_DEVINFO_DATA did;
		memset(&did, 0, sizeof(did));
		did.cbSize = sizeof(did);

		DWORD i;
		for (i=0; SetupDiEnumDeviceInfo(di, i, &did); i++)
		{
			//if (did.ClassGuid == GUID_DEVCLASS_USB)
			{
				ULONG DevDiskLen=0;
				pfc::array_t<WCHAR> DevDisk;
				if (CR_SUCCESS == CM_Get_Device_ID_Size(&DevDiskLen, did.DevInst, NULL))
				{
					DevDisk.set_size(DevDiskLen+1);
					DevDisk.fill_null();
					if (CR_SUCCESS == CM_Get_Device_ID(did.DevInst, DevDisk.get_ptr(), DevDisk.get_size(), NULL))
					{
						if (g_check_devid_is_mobile_device(DevDisk.get_ptr()))
						{
							device_instance_info_t temp;
							temp.m_handle = did.DevInst;
							temp.m_path = DevDisk.get_ptr();
							p_out.add_item(temp);

							console::formatter() << "iPod manager: USB AMD enumerator: Found " << Tu(DevDisk.get_ptr());
						}
					}
				}
			}
		}

		SetupDiDestroyDeviceInfoList(di);
	}
	if (!p_out.get_count())
		console::formatter() << "iPod manager: USB AMD enumerator: No devices found!";
}