Exemplo n.º 1
0
/*!
	@brief		トレース
	@param[o]	out: 出力輝度
	@param[i]	ray: 光線
	@param[i]	depth: 深度
 */
void Renderer::Trace(Color& out, const Ray& ray, std::size_t depth)
{
	Primitive* prim = NULL;
	Primitive::Param param;

	if((depth >= max_depth) || !FindNearest(&prim, param, ray))
	{
		out = scene->GetBGColor();
		return;
	}

	Vertex v;
	prim->CalcVertex(v, param, ray);
	Material* mtrl = prim->GetMaterial();

	// emittance
	out = mtrl->e;
 #ifdef USE_LOCAL_ILLUMINATION
	// direct lighting
	Color direct;
	DirectLighting(direct, ray, v, *mtrl);
	ColorAdd3(&out, &out, &direct);
 #endif // USE_LOCAL_ILLUMINATION
 #ifdef USE_GLOBAL_ILLUMINATION
	// indirect lighting
	Color indirect;
	IndirectLighting(indirect, ray, v, *mtrl, depth);
	ColorAdd3(&out, &out, &indirect);
 #endif // USE_GLOBAL_ILLUMINATION
}
Exemplo n.º 2
0
CV_uoff32_t
WINAPI
PHGetNearestHsym(
    LPADDR  lpaddr,
    HEXE    hexe,
    PHSYM   phsym
    )
{
    CV_uoff32_t dCur = CV_MAXOFFSET;
    LPEXE  lpexe;
    LPEXG  lpexg;

    *phsym = NULL;

    if (!VerifyHexe (hexe)) {
        return dCur;
    }

    SHWantSymbols(hexe);

    lpexe = (LPEXE) LLLock (hexe);

    if (lpexe->hexg != hexgNull) {
        lpexg = (LPEXG) LLLock (lpexe->hexg);
        *phsym = FindNearest (lpexg, lpaddr, (LPL) &dCur);
        LLUnlock(lpexe->hexg);
    }

    LLUnlock(hexe);

    return dCur;
}
Exemplo n.º 3
0
/************************************************************************************
 IterativePrint
 
 *************************************************************************************/
void NearestNeighborDirectory::IterativeSolve( )
{	
	std::vector<Node* > stackOfTreeNodes;
	
	stackOfTreeNodes.push_back( m_tree->root );
	
	Node* currentNodePtr;
	
	while( stackOfTreeNodes.empty( ) == false )
	{
		currentNodePtr = stackOfTreeNodes.back( );
		stackOfTreeNodes.pop_back( );
	
		if( currentNodePtr->m_right != NULL )
		{
			stackOfTreeNodes.push_back( currentNodePtr->m_right );
		}

		if( currentNodePtr->m_left != NULL )
		{
			stackOfTreeNodes.push_back( currentNodePtr->m_left );
		}
		
		FindNearest( m_tree->root, currentNodePtr );
	}
}
Exemplo n.º 4
0
double VspCurve::FindNearest01( double &u, const vec3d &pt, const double &u0 ) const
{
    double dist;

    dist = FindNearest( u, pt, u0 * m_Curve.get_tmax() );

    u = u / m_Curve.get_tmax();

    return dist;
}
void Application::Shoot(Projectile::PROJECTILE_TYPE type)
{
	Projectile* p = FetchProjectile();
	if (p)
	{
		float posX = ships_.at(0)->GetX();
		float posY = ships_.at(0)->GetY();
		switch (type)
		{
		case Projectile::PROJ_BULLET:
			{
				// TODO: Find pos
				p->Init(ships_.at(0), type, posX, posY, ships_.at(0)->GetW());
				p->SetDamage(1);
				p->SetSpeed(400.f);
				bulletShootTimer = 0.f;
			}
			break;
		case Projectile::PROJ_SEEKING_MISSLE:
			{
				// TODO: Find pos
				p->Init(ships_.at(0), type, posX, posY, ships_.at(0)->GetW());
				p->SetDamage(5);
				p->SetSpeed(250.f);
				p->SetTarget(FindNearest());
				missileShootTimer = 0.f;
			}
			break;
		}

		RakNet::BitStream bs;
		bs.Write((unsigned char)ID_SHOOT);
		bs.Write(p->GetID());
		bs.Write(p->GetType());
		bs.Write(p->GetX());
		bs.Write(p->GetY());
		bs.Write(p->GetW());
		bs.Write(p->GetVelocityX());
		bs.Write(p->GetVelocityY());
		bs.Write(p->GetSpeed());
		bs.Write(p->GetDamage());
		bs.Write(p->GetOwner()->GetID());
		// Send target if available
		if (p->GetTarget())
		{
			bs.Write(p->GetTarget()->GetID());
		}
		else
		{
			bs.Write(-1);
		}
		rakpeer_->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_SYSTEM_ADDRESS, true);
	}
}
Exemplo n.º 6
0
/*!
	@brief		光源方向への遮蔽物チェック
	@param[o]	t: 最近傍
	@param[i]	ray: 光線
 */
bool Renderer::FindOccluder(float& t, const Ray& ray)
{
	Primitive* prim = NULL;
	Primitive::Param param;

 #ifdef USE_KDTREE
	const KdTree* kdtree = scene->GetKdTree();
	bool ret = kdtree->Traverse(&prim, param, ray);
	t = param.t;
	return ret;
 #else
	if(FindNearest(&prim, param, ray))
	{
		t = param.t;
		return true;
	}
	return false;
 #endif // USE_KDTREE
}
Exemplo n.º 7
0
/************************************************************************************
 FindNearest
 
 *************************************************************************************/
void NearestNeighborDirectory::FindNearest( Node* currentNodePtr, Node* toComputeNNDFor )
{
	if( currentNodePtr == NULL )
	{
		return;
	}
	
	int currentSplittingPlane = currentNodePtr->GetCurrentSplitPlane( );

	if( toComputeNNDFor->GetLocation( currentSplittingPlane ) < currentNodePtr->GetLocation( currentSplittingPlane ) )
	{
		if( currentNodePtr->m_left != NULL )
		{
			FindNearest( currentNodePtr->m_left, toComputeNNDFor );
		}
		else if( currentNodePtr->m_right != NULL )
		{
			FindNearest( currentNodePtr->m_right, toComputeNNDFor );
		}
	}
	else 
	{
		if( currentNodePtr->m_right != NULL )
		{
			FindNearest( currentNodePtr->m_right, toComputeNNDFor );
		}
		else if( currentNodePtr->m_left != NULL )
		{
			FindNearest( currentNodePtr->m_left, toComputeNNDFor );
		}
	}
	
	bool shouldCheckOtherBranch;
	
	double* currentWorstLocPtr = toComputeNNDFor->GetCurrentWorstLoc( );
	
	if( currentWorstLocPtr == NULL || toComputeNNDFor->m_NearNeighborList.size( ) < 3 )
	{
		shouldCheckOtherBranch = true;
	}
	else 
	{
		int sp = toComputeNNDFor->GetCurrentSplitPlane( );
		
		double x1 = toComputeNNDFor->GetLocation(sp);
		double x2 = currentNodePtr->GetLocation(sp);
		double xworst = toComputeNNDFor->GetCurrentWorstLoc( )[ sp ];
		
		int sp_other = ( sp + 1 ) % 2;
		
		double y1 = toComputeNNDFor->GetLocation(sp_other);
		double yworst = toComputeNNDFor->GetCurrentWorstLoc( )[ sp_other ];
	
		shouldCheckOtherBranch = fabs(x1 - x2) < ( fabs(x1 - xworst) + fabs(y1 -yworst) );
		
		if( currentNodePtr == m_tree->root )
		{
			shouldCheckOtherBranch = true;
		}
	}
						
	
	if( shouldCheckOtherBranch )
	{
		int otherSide;
		int persplit = currentNodePtr->GetCurrentSplitPlane( );

		int previousDir = toComputeNNDFor->GetLocation( persplit ) < currentNodePtr->GetLocation( persplit );
		
		
		if( previousDir /* LEFT*/ )
		{
			if( currentNodePtr->m_left != NULL )
			{
				otherSide = RIGHT;
			}
			else if( currentNodePtr->m_right != NULL )
			{
				otherSide = LEFT;
			}
		}
		else
		{
			if( currentNodePtr->m_right != NULL )
			{
				otherSide = LEFT;
			}
			else if( currentNodePtr->m_left != NULL )
			{
				otherSide = RIGHT;
			}
		}
		
		if( otherSide == LEFT  )
		{
			if( currentNodePtr->m_left != NULL )
			{
				FindNearest( currentNodePtr->m_left, toComputeNNDFor );
			}
		}
		else if( otherSide == RIGHT )
		{
			if( currentNodePtr->m_right != NULL )
			{
				FindNearest( currentNodePtr->m_right, toComputeNNDFor );
			}
		}

	}
	double thisSquaredDist = CalculateSquaredDist( toComputeNNDFor->GetLocationPtr(), currentNodePtr->GetLocationPtr() );
	
	if( thisSquaredDist != 0)
	{
		toComputeNNDFor->SortedInsert(currentNodePtr, thisSquaredDist );		
	}
	
}