コード例 #1
0
ファイル: Bullet.cpp プロジェクト: RuWhyNot/stealthgame
void Bullet::update(float deltatime)
{
	Vector2D newLocation = this->getLocation() + deltatime * this->speed * Vector2D(this->getRotation());
	
	WARN_IF(!this->getOwnerWorld(), "Not assigned OwnerWorld for bullet");

	Vector2D traceLocation(ZERO_VECTOR);
	IActor *trasedActor = RayTrace::trace(this->getOwnerWorld(), this->getLocation(), newLocation, &traceLocation);

	// if there nothing to hit
	if (trasedActor == nullptr)
	{
		this->setLocation(newLocation);
	}
	else // bullet is hiting some actor
	{
		trasedActor->hit(this, 10.f, Vector2D(this->getRotation()) * this->speed * 0.01f);
		this->speed = 0.0f;
		this->destroy();
	}

	// bullet will be destroyed after 10 second
	if (this->getLifetime() > 10.f)
	{
		this->destroy();
	}

	Actor::update(deltatime);
}
コード例 #2
0
ファイル: Tracer.cpp プロジェクト: asplendidday/ptchan
void Tracer::trace()
{
	if( !scene_ || is_tracing_ )
	{
		return;
	}

	startTracing();

	const int width		= film_->getWidth();
	const int height	= film_->getHeight();
	const double aspect = static_cast< double >( width ) /
						  static_cast< double >( height );

	Logging::log( LogLevel::Info,
				"[Tracer] Tracing image with " + std::to_string( width ) + 
				" x " + std::to_string( height ) + " pixels (w x h) and " +
				std::to_string( rays_per_pixel_ ) + " samples per pixel." );

	std::thread t( [=]{
#pragma omp parallel for schedule( dynamic, 1 )	
	for( int samp = 0; samp < rays_per_pixel_; ++samp )
	{
		for( int y = 0; y < height && is_tracing_; ++y )
		{
			for( int x = 0; x < width && is_tracing_; ++x )
			{
				const double x_d = static_cast< double >( x );
				const double y_d = static_cast< double >( y );
				const double width_d = static_cast< double >( width );
				const double height_d = static_cast< double >( height );

				const double dx = aspect * ( x_d / width_d - .5 );
				const double dy = ( y_d / height_d - .5 );

				Color sample = traceLocation( dx, dy );
				film_->addSample( x, y, sample );
				curr_num_samples_.fetch_add( 1 );
			}			
		}
	}

	stopTracing();
	
	auto perf_string = std::to_string( getSpeedAsMsamplesPerSec() );
	// @TODO cutting away unwanted digits entails wrong rounding
	perf_string = perf_string.substr( 0, perf_string.length() - 4 );

	Logging::log( LogLevel::Info,
				  "[Tracer] Generated samples at a rate of " + perf_string +
					  " Msamples/sec." );
	} );
	t.detach();
}