Beispiel #1
0
bool Triangle::intersect_test(const Ray& r, real_t& t, Intersection& info){

	Ray local_r = to_local(r);
    t = -1;
	if (solve_raytri(local_r, vertices[0].position, vertices[1].position, vertices[2].position, t)){
		Vector3 local_pos = local_r.atTime(t);

		real_t a, b, c;

		barycentric_coor(local_pos, vertices[0].position, vertices[1].position, vertices[2].position, a, b, c);
		// compute intersection material info based on barycentric coordinate
		info.ambient = vertices[0].material->ambient * a + vertices[1].material->ambient * b + vertices[1].material->ambient * c;
		info.diffuse = vertices[0].material->diffuse * a + vertices[1].material->diffuse * b + vertices[1].material->diffuse * c;
		info.specular = vertices[0].material->specular * a + vertices[1].material->specular * b + vertices[1].material->specular * c;
		info.shininess = vertices[0].material->shininess * a + vertices[1].material->shininess * b + vertices[1].material->shininess * c;
		info.position = mat.transform_point(local_pos);
		info.normal = vertices[0].normal * a + vertices[1].normal * b + vertices[2].normal * c;
		info.normal = normalize(normMat * info.normal);
		info.refractive_index = vertices[0].material->refractive_index * a
			+ vertices[1].material->refractive_index * b
			+ vertices[2].material->refractive_index * c;
		//get the texture coordinate
		Vector2 tex_coord = vertices[0].tex_coord * a + vertices[1].tex_coord * b + vertices[2].tex_coord * c;
		//interpolate texture color
		Color3 c0 = vertices[0].material->texture.sample(tex_coord);
		Color3 c1 = vertices[1].material->texture.sample(tex_coord);
		Color3 c2 = vertices[2].material->texture.sample(tex_coord);
		info.tex_Color = c0 * a + c1 * b + c2 * c;
		return true;
	}
	return false;
}
Beispiel #2
0
context::~context()
{
	// remove all class singletons before modules unload
	cleanup(isolate_);

	for (auto& kv : modules_)
	{
		dynamic_module& module = kv.second;
		module.exports.Reset();
		if (module.handle)
		{
#if defined(WIN32)
			::FreeLibrary((HMODULE)module.handle);
#else
			dlclose(module.handle);
#endif
		}
	}
	modules_.clear();

	v8::Local<v8::Context> impl = to_local(isolate_, impl_);
	impl->Exit();

	impl_.Reset();
	if (own_isolate_)
	{
		isolate_->Exit();
		isolate_->Dispose();
	}
}
Beispiel #3
0
bool Triangle::shadow_test(const Ray& r,real_t dis){
	if (!box.intersects(r)){
		return false;
	}

	Ray local_r = to_local(r);
	real_t t = -1;
	return solve_raytri(local_r, vertices[0].position, vertices[1].position, vertices[2].position, t) && t < dis;
}
int bsearch_day_cmp( const void* key, const void* element )		// REQ5
{
	const time_t* k = (const time_t*)key;
	const reservation* res = (const reservation*)element;
	time_t res_t_start = to_local( res->starttime );
	time_t res_t_end = to_local( res->endtime );
	struct tm restm_start;
	struct tm restm_end;
	localtime_r( &res_t_start, &restm_start );
	localtime_r( &res_t_end, &restm_end );
	struct tm ktm;
	localtime_r( k, &ktm );

	if( ktm.tm_wday < restm_start.tm_wday )
		return -1;
	else if( ktm.tm_wday > restm_end.tm_wday )
		return 1;
	return 0;
}
Beispiel #5
0
context& context::set(char const* name, v8::Handle<v8::Value> value)
{
	v8::HandleScope scope(isolate_);
	to_local(isolate_, impl_)->Global()->Set(to_v8(isolate_, name), value);
	return *this;
}