// 获取曲面数据
BOOL CSDMdlMachLongAxisCheck::SetSurfaceData(ProSurface pSurf, ProSurface pSameSurf, SDC_SurfaceData &surfData)
{
    if (NULL == pSurf)
        return FALSE;

    surfData.pSurface = pSurf;
    surfData.pSameSurf = pSameSurf;
    ProGeomitemdata *pGeomData = NULL;
    ProSurfaceDataGet(pSurf, &pGeomData);
    BOOL bRet = FALSE;
    if (pGeomData->data.p_surface_data->type == PRO_SRF_CYL)
    {
        VectorCopy(pGeomData->data.p_surface_data->srf_shape.cylinder.origin, surfData.origin);
        VectorCopy(pGeomData->data.p_surface_data->srf_shape.cylinder.e3, surfData.axisVector);
        VectorCopy(pGeomData->data.p_surface_data->xyz_min, surfData.minPt);
        VectorCopy(pGeomData->data.p_surface_data->xyz_max, surfData.maxPt);
        SVDOUBLE3 minProj, maxProj;
        ProjectPtToLine(SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.origin),
                        SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.e3), SVDOUBLE3(surfData.minPt), minProj);
        ProjectPtToLine(SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.origin),
                        SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.e3), SVDOUBLE3(surfData.maxPt), maxProj);
        surfData.dDiameter = pGeomData->data.p_surface_data->srf_shape.cylinder.radius * 2.0;
        SVDOUBLE3ToPoint3D(minProj, surfData.minPt);
        SVDOUBLE3ToPoint3D(maxProj, surfData.maxPt);
        bRet = TRUE;
    }
    else if (pGeomData->data.p_surface_data->type == PRO_SRF_CONE)
    {
        VectorCopy(pGeomData->data.p_surface_data->srf_shape.cone.origin, surfData.origin);
        VectorCopy(pGeomData->data.p_surface_data->srf_shape.cone.e3, surfData.axisVector);
        VectorCopy(pGeomData->data.p_surface_data->xyz_min, surfData.minPt);
        VectorCopy(pGeomData->data.p_surface_data->xyz_max, surfData.maxPt);
        SVDOUBLE3 minProj, maxProj;
        ProjectPtToLine(SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.origin),
                        SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.e3), SVDOUBLE3(surfData.minPt), minProj);
        ProjectPtToLine(SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.origin),
                        SVDOUBLE3(pGeomData->data.p_surface_data->srf_shape.cone.e3), SVDOUBLE3(surfData.maxPt), maxProj);
        double dR1 = CalculateDistance(SVDOUBLE3(surfData.minPt), SVDOUBLE3(minProj));
        double dR2 = CalculateDistance(SVDOUBLE3(surfData.maxPt), SVDOUBLE3(maxProj));
        surfData.dDiameter = dR1 < dR2 ? (dR1 * 2.0) : (dR2 * 2.0);
        VectorCopy(minProj, surfData.minPt);
        VectorCopy(maxProj, surfData.maxPt);
        bRet = TRUE;
    }
    ProGeomitemdataFree(&pGeomData);

    return TRUE;
}
Exemplo n.º 2
0
State_t Striker::DoStateDribble()
{
	m_vision->SetHeadTrackingStatus(BALL_TRACKING);
	// Assumption: The robot is close to the ball face to the opponent goal.
	bool isAlreadyDribbling = false;
	cm prevBallDistanceFromMe;
	BallLocation ballLocation = m_localization->GetBallLocation();
	while (IsBallDataRelevant(&ballLocation) && (ballLocation.angleFromMe
			< VALID_ANGLE_FOR_DRIBBLE && ballLocation.angleFromMe
			> -VALID_ANGLE_FOR_DRIBBLE) && !IsIBlocked()
			&& CalculateDistance(m_localization->GetMyLocation().x,
					m_localization->GetMyLocation().y, OPPONENT_GOAL_X,
					OPPONENT_GOAL_Y) > KICKABLE_DISTANCE_FROM_OPPONENT_GOAL)
	{
		if (!IsStatePlaying())
		{
			return STATE_HANDLE_GAME_CONTROLLER_STATES;
		}
		if (!isAlreadyDribbling)
		{
			AdjustYourselfTowardTheBallForDribble();
			m_motion->StartWalkingAsync(DRIBBLE_X_SPEED, 0, 0);
			isAlreadyDribbling = true;
		}
		prevBallDistanceFromMe = ballLocation.distanceFromMe;
		usleep(500 * 1000);
		ballLocation = m_localization->GetBallLocation();
		if (ballLocation.distanceFromMe > prevBallDistanceFromMe + DISTANCE_FROM_BALL_THRESHOLD)
		{
			return STATE_SHOULD_I_GO_TO_THE_BALL;
		}
	}
	return STATE_LOOK_FOR_THE_BALL;
}
Exemplo n.º 3
0
BOOL CTeleportPath::MakeDistanceTable()
{	
	if (m_ppTable == NULL)
		return FALSE;

	// convert the graph into a distance table
	for (int x = 0; x < m_nCX; x++)	
	{
		for (int y = 0; y < m_nCY; y++)
		{
			if ((m_ppTable[x][y] % 2) == 0)
				m_ppTable[x][y] = (short)CalculateDistance(x, y, m_ptEnd.x, m_ptEnd.y);
			else
				m_ppTable[x][y] = RANGE_INVALID;
		}
	}
	if(m_ptEnd.y >= m_nCY)
		m_ptEnd.y = m_nCY - 1;

	if(!IsValidIndex(m_ptEnd.x, m_ptEnd.y))
		return false;

	m_ppTable[m_ptEnd.x][m_ptEnd.y] = 1;	
	return TRUE;
}
Exemplo n.º 4
0
void StrandOfTheAncient::OnPlatformTeleport(Player *plr)
{
	LocationVector dest;
	uint32 closest_platform = 0;

	for (uint32 i = 0; i < GATE_COUNT; i++)
	{
		float distance = CalculateDistance(plr->GetPositionX(),
			plr->GetPositionY(), plr->GetPositionZ(),
			sotaTransporterDestination[i][0],
			sotaTransporterDestination[i][1],
			sotaTransporterDestination[i][2]);
		if (distance < 75)
		{
			closest_platform = i;
			break;
		}
	}
	dest.ChangeCoords(sotaTransporterDestination[closest_platform][0],
		sotaTransporterDestination[closest_platform][1],
		sotaTransporterDestination[closest_platform][2],
		sotaTransporterDestination[closest_platform][3]);

	plr->SafeTeleport(plr->GetMapId(), plr->GetInstanceID(), dest);
}
Exemplo n.º 5
0
    pcl::CorrespondencesPtr CloudMapper::LandmarksToCorresponencies(Cloud::Ptr &cloud1, CloudMapper::Landmarks &landmarks1, Cloud::Ptr &cloud2, CloudMapper::Landmarks &landmarks2)
    {
        pcl::CorrespondencesPtr result(new pcl::Correspondences);

        int resultSize = std::min(landmarks1.size(), landmarks2.size());

        for (int i = 0; i < resultSize; i++)
        {
            auto sourcePoint1 = landmarks1.at(i).point;
            auto sourcePoint2 = landmarks2.at(i).point;

            auto p1IsNotNan = IsNotNAN(sourcePoint1);
            auto p2IsNotNan = IsNotNAN(sourcePoint2);
            if (p1IsNotNan && p2IsNotNan)
            {
                CloudMapper::Landmarks::value_type pt1 = FindClosestPoint(cloud1, sourcePoint1);
                CloudMapper::Landmarks::value_type pt2 = FindClosestPoint(cloud2, sourcePoint2);

                float distance = CalculateDistance(pt1.point, pt2.point);
                pcl::Correspondence correspondence(pt1.index, pt2.index, distance);

                result->push_back(correspondence);
            }
        }

        return result;
    }
Exemplo n.º 6
0
double cRenderWorker::AuxShadow(const sShaderInputData &input, double distance,
		CVector3 lightVector)
{
	double step = input.delta;
	double dist = step;
	double light = 1.0;

	double opacity = 0.0;
	double shadowTemp = 1.0;

	double DE_factor = params->DEFactor;
	if (params->iterFogEnabled || params->volumetricLightAnyEnabled) DE_factor = 1.0;

	for (double i = input.delta; i < distance; i += dist * DE_factor)
	{
		CVector3 point2 = input.point + lightVector * i;

		sDistanceOut distanceOut;
		sDistanceIn distanceIn(point2, input.distThresh, false);
		dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;

		if (params->iterFogEnabled)
		{
			opacity = IterOpacity(dist * DE_factor,
														distanceOut.iters,
														params->N,
														params->iterFogOpacityTrim,
														params->iterFogOpacity);
		}
		else
		{
			opacity = 0.0;
		}
		shadowTemp -= opacity * (distance - i) / distance;

		float dist_thresh;
		if (params->iterFogEnabled || params->volumetricLightAnyEnabled)
		{
			dist_thresh = CalcDistThresh(point2);
		}
		else dist_thresh = input.distThresh;

		if (dist < dist_thresh || shadowTemp < 0.0)
		{
			if (params->penetratingLights)
			{
				shadowTemp -= (distance - i) / distance;
				if (shadowTemp < 0.0) shadowTemp = 0.0;
			}
			else
			{
				shadowTemp = 0.0;
			}
			break;
		}
	}
	light = shadowTemp;
	return light;
}
Exemplo n.º 7
0
sRGBAfloat cRenderWorker::FastAmbientOcclusion(const sShaderInputData &input)
{
	// reference Iñigo Quilez –iq/rgba:
	// http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf
	double delta = input.distThresh;
	double aoTemp = 0;
	double quality = params->ambientOcclusionQuality;
	double lastDist = 1e20;
	for (int i = 1; i < quality * quality; i++)
	{
		double scan = i * i * delta;
		CVector3 pointTemp = input.point + input.normal * scan;

		sDistanceOut distanceOut;
		sDistanceIn distanceIn(pointTemp, input.distThresh, false);
		double dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data);
		if (dist > lastDist * 2) dist = lastDist * 2.0;
		lastDist = dist;
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;
		aoTemp +=
			1.0 / pow(2.0, i) * (scan - params->ambientOcclusionFastTune * dist) / input.distThresh;
	}
	double ao = 1.0 - 0.2 * aoTemp;
	if (ao < 0) ao = 0;
	sRGBAfloat output(ao, ao, ao, 1.0);
	return output;
}
Exemplo n.º 8
0
cm Striker::CalculateDistanceFromOtherStriker(cm xLocation, cm yLocation)
{
	return CalculateDistance(
			m_communication->GetFriendData(m_otherStrikerId)->ballLocation.x,
			m_communication->GetFriendData(m_otherStrikerId)->ballLocation.y,
			m_localization->GetMyLocation().y, yLocation);
}
Exemplo n.º 9
0
float PrlxPhysics::CalculateDistance(PrlxPhysics::Motion::Position A, PrlxPhysics::Motion::Position B)
{
    return CalculateDistance
        (
            PRLX_Point(Point(A.x, A.y)),
            PRLX_Point(Point(B.x, B.y))
        );
}
Exemplo n.º 10
0
/////////////////////////////////////////////////////////////////////
// The "Get Best Move" Algorithm
//
// Originally developed by Niren7, Modified by Abin
/////////////////////////////////////////////////////////////////////
BOOL CTeleportPath::GetBestMove(POINT& pos, int nAdjust)
{	
	if(CalculateDistance(m_ptEnd, pos) <= TP_RANGE)
	{
		pos = m_ptEnd;
		return PATH_REACHED; // we reached the destination
	}

	if (!IsValidIndex(pos.x, pos.y))
		return PATH_FAIL; // fail

	Block(pos, nAdjust);

	POINT p, best;
	int value = RANGE_INVALID;

	DWORD LeftX = pos.x, LeftY = pos.y;

	if( pos.x < TP_RANGE )
		LeftX += ( TP_RANGE - pos.x);
	
	if( pos.y < TP_RANGE)
		LeftY += ( TP_RANGE - pos.y);

	for (p.x = LeftX - TP_RANGE; p.x <= LeftX + TP_RANGE; p.x++)
	{
		for (p.y = LeftY - TP_RANGE; p.y <= LeftY + TP_RANGE; p.y++)
		{			
			if (!IsValidIndex(p.x, p.y))
				continue;
		
			if (m_ppTable[p.x][p.y] < value && CalculateDistance(p, pos) <= TP_RANGE)
			{				
				value = m_ppTable[p.x][p.y];
				best = p;					
			}			
		}
	}

	if (value >= RANGE_INVALID)
		return PATH_FAIL; // no path at all	
	
	pos = best;
	Block(pos, nAdjust);	
	return PATH_CONTINUE; // ok but not reached yet
}
Exemplo n.º 11
0
void FileList::addChild(ngl::Vec3 _childlocalposition)
{


  std::cout<<std::endl<<"*********CHILD "<<_childlocalposition.m_x<<" "<<_childlocalposition.m_y<<std::endl;
  m_node.m_localposition.m_x = _childlocalposition.m_x;
  m_node.m_localposition.m_y = _childlocalposition.m_y;
  m_node.m_localposition.m_z = 0;


  if(m_numberofjoints > MAX_CHCOUNT)
     exit(0);
  else
  {

    if (m_numberofjoints == 0) //Creating a null root
    {
        m_node.m_worldposition = m_node.m_localposition;
        m_node.m_zAngle =0;
        m_node.m_jointnumber= 1;

//        std::cout<<"INSIDE 0 ROOT"<<std::endl;
    }
    else
    {
      auto id = m_jointData.rbegin();



      ngl::Vec3 localposition = (*id).m_localposition;
      ngl::Vec3 worldposition = (*id).m_worldposition;

      float length;
     // float angle ;


      length = CalculateDistance(worldposition, worldposition+_childlocalposition);

     // angle = CalculateAngle(worldposition, worldposition+_childlocalposition);

      (*id).m_length = length;
     // (*id).m_zAngle = angle;

      m_node.m_worldposition = worldposition + _childlocalposition ;


      m_node.m_jointnumber = (*id).m_jointnumber +1;
      //m_node.m_zAngle = (*id).m_zAngle ;
    }


  }
  m_jointData.push_back( m_node);
  m_numberofjoints++;



}
Exemplo n.º 12
0
int CTeleportPath::GetRedundancy(const LPPOINT lpPath, DWORD dwMaxCount, const POINT &pos)
{
	// step redundancy check
	if (lpPath == NULL || dwMaxCount == 0)
		return -1;

	for (DWORD i = 1; i < dwMaxCount; i++)
	{
		if (CalculateDistance(lpPath[i].x, lpPath[i].y, pos.x, pos.y) <= TP_RANGE / 2)
			return i;
	}

	return -1;
}
Exemplo n.º 13
0
bool CollisionSystem::ReproduceEntities(std::shared_ptr<Entity> entity1,
    std::shared_ptr<Entity> entity2)
{
    auto reproductionComponent1 = std::static_pointer_cast<ReproductionComponent>(
        Engine::GetInstance().GetSingleComponentOfClass(entity1,
            "ReproductionComponent"));

    auto reproductionComponent2 = std::static_pointer_cast<ReproductionComponent>(
        Engine::GetInstance().GetSingleComponentOfClass(entity2,
            "ReproductionComponent"));

    auto particleComponent1 = std::static_pointer_cast<ParticleComponent>(
        Engine::GetInstance().GetSingleComponentOfClass(entity1,
            "ParticleComponent"));
    auto particleComponent2 = std::static_pointer_cast<ParticleComponent>(
        Engine::GetInstance().GetSingleComponentOfClass(entity2,
            "ParticleComponent"));

    auto position1 = particleComponent1->GetPosition();
    auto position2 = particleComponent2->GetPosition();

    if (position1.CalculateDistance(position2) >= CFG_GETF("REPRODUCTION_DISTANCE_MAX"))
        return true;

    auto enabled1 = reproductionComponent1->GetEnabled();
    auto enabled2 = reproductionComponent2->GetEnabled();

    auto reproduced1 = reproductionComponent1->GetReproduced();
    auto reproduced2 = reproductionComponent2->GetReproduced();

    auto type1 = reproductionComponent1->GetType();
    auto type2 = reproductionComponent2->GetType();

    if (enabled1 && enabled2 && !reproduced1 && !reproduced2 && type1 == type2)
    {
        LOG_D("[CollisionSystem] Reproducing entities " << entity1->GetId()
            << " and " << entity2->GetId());
        EntityFactory::CreateCell(particleComponent1->GetPosition() + Vector(50, 50));
        reproductionComponent1->SetReproduced(true);
        reproductionComponent2->SetReproduced(true);
        return true;
    }

    return false;
}
Exemplo n.º 14
0
bool ChatHandler::HandleSimpleDistanceCommand(const char* args, WorldSession* m_session)
{
    float toX, toY, toZ;
    if (sscanf(args, "%f %f %f", &toX, &toY, &toZ) != 3)
        return false;

    if (toX >= _maxX || toX <= _minX || toY <= _minY || toY >= _maxY)
        return false;

    float posX = m_session->GetPlayer()->GetPositionX();
    float posY = m_session->GetPlayer()->GetPositionY();
    float posZ = m_session->GetPlayer()->GetPositionZ();

    float distance = CalculateDistance(posX, posY, posZ, toX, toY, toZ);

    m_session->SystemMessage("Your distance to location (%f, %f, %f) is %f.", toX, toY, toZ, distance);
    return true;
}
Exemplo n.º 15
0
int main()
{
   int x1, x2, y1, y2;
   double totalInches = 0;
   int distanceInFeet = 0;
   double distanceInInches = 0;
   
   
   /*************************************
    *               Step 2              *
    * Add two calls to ScanCoordinates, *
    * one for each pair of coordinates. *
    * Also, uncomment the two lines of  *
    * code below before compiling again *
    *************************************/
   ScanCoordinates( &x1, &y1);
   ScanCoordinates( &x2, &y2);
   
   totalInches = CalculateDistance(x1, y1, x2, y2);
   printf("The distance is: %lf\n", totalInches);
   
   
   
   /************************************
    *          Step 4                  *
    * Call the ConvertInchesToFeet     *
    * function, making sure to pay     *
    * attention to what is passed in   *
    * by reference, and what is passed *
    * in by value. Also uncomment the  *
    * call to printf below.            *
    ************************************/
   ConvertInchesToFeet(&distanceInFeet, &distanceInInches, totalInches);
  
   
   printf("Feet: %d, Inches: %lf\n", distanceInFeet, 
	  distanceInInches);
   
   
   return 0;
}
Exemplo n.º 16
0
DWORD GetUnitDist(UnitAny* pUnit1, UnitAny* pUnit2)
{
	DWORD dwDist[4] = {0};

	switch(pUnit1->dwType)
	{
	case UNIT_TYPE_PLAYER:
	case UNIT_TYPE_MISSILE:
	case UNIT_TYPE_ITEM:
		dwDist[0] = pUnit1->pPath->xPos;
		dwDist[1] = pUnit1->pPath->yPos;
		break;

	case UNIT_TYPE_OBJECT:
		dwDist[0] = pUnit1->pObjectPath->dwPosX;
		dwDist[1] = pUnit1->pObjectPath->dwPosY;
		break;
	}

	switch(pUnit2->dwType)
	{
	case UNIT_TYPE_PLAYER:
	case UNIT_TYPE_MISSILE:
	case UNIT_TYPE_ITEM:
		dwDist[2] = pUnit2->pPath->xPos;
		dwDist[3] = pUnit2->pPath->yPos;
		break;

	case UNIT_TYPE_OBJECT:
		dwDist[2] = pUnit2->pObjectPath->dwPosX;
		dwDist[3] = pUnit2->pObjectPath->dwPosY;
		break;
	}

	for(int x = 0; x < 4; x++)
		if(!dwDist[x])
			return INFINITE;

	return (DWORD)CalculateDistance(dwDist[0], dwDist[1], dwDist[2], dwDist[3]);
}
Exemplo n.º 17
0
CVector3 cRenderWorker::CalculateNormals(const sShaderInputData &input)
{
	CVector3 normal(0.0, 0.0, 0.0);
	// calculating normal vector based on distance estimation (gradient of distance function)
	if (!params->slowShading)
	{
		double delta = input.delta * params->smoothness;
		if (params->interiorMode) delta = input.distThresh * 0.2 * params->smoothness;

		double sx1, sx2, sy1, sy2, sz1, sz2;
		sDistanceOut distanceOut;

		CVector3 deltax(delta, 0.0, 0.0);
		sDistanceIn distanceIn1(input.point + deltax, input.distThresh, true);
		sx1 = CalculateDistance(*params, *fractal, distanceIn1, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;
		sDistanceIn distanceIn2(input.point - deltax, input.distThresh, true);
		sx2 = CalculateDistance(*params, *fractal, distanceIn2, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;

		CVector3 deltay(0.0, delta, 0.0);
		sDistanceIn distanceIn3(input.point + deltay, input.distThresh, true);
		sy1 = CalculateDistance(*params, *fractal, distanceIn3, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;
		sDistanceIn distanceIn4(input.point - deltay, input.distThresh, true);
		sy2 = CalculateDistance(*params, *fractal, distanceIn4, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;

		CVector3 deltaz(0.0, 0.0, delta);
		sDistanceIn distanceIn5(input.point + deltaz, input.distThresh, true);
		sz1 = CalculateDistance(*params, *fractal, distanceIn5, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;
		sDistanceIn distanceIn6(input.point - deltaz, input.distThresh, true);
		sz2 = CalculateDistance(*params, *fractal, distanceIn6, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;

		normal.x = sx1 - sx2;
		normal.y = sy1 - sy2;
		normal.z = sz1 - sz2;
	}

	// calculating normal vector based on average value of binary central difference
	else
	{
		CVector3 point2;
		CVector3 point3;
		double delta = input.delta * params->smoothness * 0.5;
		if (params->interiorMode) delta = input.distThresh * 0.2 * params->smoothness;

		sDistanceOut distanceOut;
		for (point2.x = -1.0; point2.x <= 1.0; point2.x += 0.2) //+0.2
		{
			for (point2.y = -1.0; point2.y <= 1.0; point2.y += 0.2)
			{
				for (point2.z = -1.0; point2.z <= 1.0; point2.z += 0.2)
				{
					point3 = input.point + point2 * delta;

					sDistanceIn distanceIn(point3, input.distThresh, true);
					double dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data);
					data->statistics.totalNumberOfIterations += distanceOut.totalIters;
					normal += (point2 * dist);
				}
			}
		}
	}

	if ((normal.x == 0 && normal.y == 0 && normal.z == 0))
	{
		normal = CVector3(1.0, 0.0, 0.0);
	}
	else
	{
		normal.Normalize();
	}

	if (normal.IsNotANumber())
	{
		normal = CVector3(1.0, 0.0, 0.0);
	}

	if (input.invertMode) normal *= (-1.0);

	// qDebug() << input.point.Debug() << normal.Debug();

	return normal;
}
Exemplo n.º 18
0
sRGBAfloat cRenderWorker::AmbientOcclusion(const sShaderInputData &input)
{
	sRGBAfloat AO(0, 0, 0, 1.0);

	double start_dist = input.delta;
	double end_dist = input.delta / params->resolution;
	double intense = 0;

	for (int i = 0; i < AOvectorsCount; i++)
	{
		sVectorsAround v = AOvectorsAround[i];

		double dist = input.lastDist;

		double opacity = 0.0;
		double shadowTemp = 1.0;

		for (double r = start_dist; r < end_dist; r += dist * 2.0)
		{
			CVector3 point2 = input.point + v.v * r;

			sDistanceOut distanceOut;
			sDistanceIn distanceIn(point2, input.distThresh, false);
			dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data);
			data->statistics.totalNumberOfIterations += distanceOut.totalIters;

			if (params->iterFogEnabled)
			{
				opacity = IterOpacity(dist * 2.0, distanceOut.iters, params->N, params->iterFogOpacityTrim,
					params->iterFogOpacity);
			}
			else
			{
				opacity = 0.0;
			}
			shadowTemp -= opacity * (end_dist - r) / end_dist;

			float dist_thresh;
			if (params->iterFogEnabled || params->volumetricLightEnabled[0])
			{
				dist_thresh = CalcDistThresh(point2);
			}
			else
				dist_thresh = input.distThresh;

			if (dist < dist_thresh || distanceOut.maxiter || shadowTemp < 0.0)
			{
				shadowTemp -= (end_dist - r) / end_dist;
				if (shadowTemp < 0.0) shadowTemp = 0.0;
				break;
			}
		}

		intense = shadowTemp;

		AO.R += intense * v.R;
		AO.G += intense * v.G;
		AO.B += intense * v.B;
	}
	AO.R /= (AOvectorsCount * 256.0);
	AO.G /= (AOvectorsCount * 256.0);
	AO.B /= (AOvectorsCount * 256.0);

	return AO;
}
Exemplo n.º 19
0
static uint8 gps_data_change(void *arg)
{
	GPSDATA_TYPE *data = (GPSDATA_TYPE *)arg;
	uint32 average = 0;

	if(data->glatitude == regionDat.last_lat && data->glongitude == regionDat.last_lon)
	{
		return 0;
	}

	regionDat.trip_distance += CalculateDistance(data->glatitude, data->glongitude, regionDat.last_lat, regionDat.last_lon, NULL);
	regionDat.speed_sum += data->gspeed;
	regionDat.point_cnt += 1;
	regionDat.last_lat = data->glatitude;
	regionDat.last_lon = data->glongitude;

	if(regionDat.trip_distance >= regionDat.distance)
	{
		//should unregister this listener
		LOGD("region end by distance");
		regionDat.listener.listener = NULL;
		RemoveDisplayByNode(&regionDat.display);
		return 1;
	}

	average = regionDat.speed_sum / regionDat.point_cnt;
	if(average > (regionDat.speed - 2))
	{
		uint32 diff = average - regionDat.speed + 2;
		uint8 cnt = 0;

		if(diff > 30)
		{
			cnt = 2;
		}
		else if(diff > 20)
		{
			cnt = 3;
		}
		else if(diff > 10)
		{
			cnt = 4;
		}
		else
		{
			cnt = 5;
		}

		if(regionDat.point_cnt % (15 * cnt) == 0)
		{
			VoicePlayCommon(speed_over_alarm_voice, TTS_PLAY_LEVEL_HIGH, VOICE_DATA_FLAG_NULL);
		}
		else
		{
			if(regionDat.point_cnt % cnt == 0)
			{
				VoicePlayCommon(ding_voice, TTS_PLAY_LEVEL_IGNORE, VOICE_DATA_FLAG_NULL);
			}
		}
	}

	return 0;
}
Exemplo n.º 20
0
sRGBAfloat cRenderWorker::MainShadow(const sShaderInputData &input)
{
	sRGBAfloat shadow(1.0, 1.0, 1.0, 1.0);

	// starting point
	CVector3 point2;

	double factor = input.delta / params->resolution;
	if (!params->penetratingLights) factor = params->viewDistanceMax;
	double dist = input.distThresh;

	double DEFactor = params->DEFactor;
	if (params->iterFogEnabled || params->volumetricLightEnabled[0]) DEFactor = 1.0;

	// double start = input.delta;
	double start = input.distThresh;
	if (params->interiorMode) start = input.distThresh * DEFactor;

	double opacity = 0.0;
	double shadowTemp = 1.0;

	double softRange = tan(params->shadowConeAngle / 180.0 * M_PI);
	double maxSoft = 0.0;

	const bool bSoft = (!params->iterFogEnabled && !params->limitsEnabled && !params->iterThreshMode)
										 && softRange > 0.0;

	for (double i = start; i < factor; i += dist * DEFactor)
	{
		point2 = input.point + input.lightVect * i;

		float dist_thresh;
		if (params->iterFogEnabled || params->volumetricLightEnabled[0])
		{
			dist_thresh = CalcDistThresh(point2);
		}
		else
			dist_thresh = input.distThresh;

		sDistanceOut distanceOut;
		sDistanceIn distanceIn(point2, dist_thresh, false);
		dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;

		if (bSoft)
		{
			double angle = (dist - dist_thresh) / i;
			if (angle < 0) angle = 0;
			if (dist < dist_thresh) angle = 0;
			double softShadow = (1.0 - angle / softRange);
			if (params->penetratingLights) softShadow *= (factor - i) / factor;
			if (softShadow < 0) softShadow = 0;
			if (softShadow > maxSoft) maxSoft = softShadow;
		}

		if (params->iterFogEnabled)
		{
			opacity = IterOpacity(dist * DEFactor, distanceOut.iters, params->N,
				params->iterFogOpacityTrim, params->iterFogOpacity);
		}
		else
		{
			opacity = 0.0;
		}
		shadowTemp -= opacity * (factor - i) / factor;

		if (dist < dist_thresh || shadowTemp < 0.0)
		{
			shadowTemp -= (factor - i) / factor;
			if (!params->penetratingLights) shadowTemp = 0.0;
			if (shadowTemp < 0.0) shadowTemp = 0.0;
			break;
		}
	}
	if (!bSoft)
	{
		shadow.R = shadowTemp;
		shadow.G = shadowTemp;
		shadow.B = shadowTemp;
	}
	else
	{
		shadow.R = (1.0 - maxSoft);
		shadow.G = (1.0 - maxSoft);
		shadow.B = (1.0 - maxSoft);
	}
	return shadow;
}
Exemplo n.º 21
0
bool CircleCircleIntersect(const Circle * circle1, const Circle * circle2)
{
	return (CalculateDistance(circle1->GetCenter(), circle2->GetCenter()) < (circle1->GetRadius() + circle2->GetRadius()));
}
Exemplo n.º 22
0
void CollisionSystem::CheckCollisions()
{
    float maxDistance = CFG_GETF("COLLISION_MAX_DISTANCE");
    Quadtree<std::shared_ptr<Entity>> quadtree(Rectangle(CFG_GETF("LEVEL_MIN_X"), CFG_GETF("LEVEL_MIN_Y"), CFG_GETF("LEVEL_MAX_X") - CFG_GETF("LEVEL_MIN_X"), CFG_GETF("LEVEL_MAX_Y") - CFG_GETF("LEVEL_MIN_Y")));
    auto cameraEntities = Engine::GetInstance().GetAllEntitiesWithComponentOfClass("CameraComponent");
    collidableEntities = Engine::GetInstance().GetAllEntitiesWithComponentOfClass("ColliderComponent");

    // Clear deleted entities from last iteration.
    deletedEntities.clear();

    std::shared_ptr<Entity> cameraEntity;
    if (cameraEntities.size() > 0)
        cameraEntity = cameraEntities[0];

    // Build quadtree for close enough entities.
    for (auto entity : collidableEntities)
    {
        auto particleComponent = std::static_pointer_cast<ParticleComponent>(Engine::GetInstance().GetSingleComponentOfClass(entity, "ParticleComponent"));
        auto position = particleComponent->GetPosition();

        // Ignore collision from things that aren't visible.
        if (cameraEntity)
        {
            auto cameraComponent = std::static_pointer_cast<CameraComponent>(Engine::GetInstance().GetSingleComponentOfClass(cameraEntity, "CameraComponent"));
            auto cameraPosition = cameraComponent->GetPosition();

            if (cameraPosition.CalculateDistance(position) > maxDistance)
                continue;
            else
                quadtree.Add(entity, position);
        }
        else
        {
            quadtree.Add(entity, position);
        }
    }

    // Detect and solve collisions.
    for (unsigned int i = 0; i < collidableEntities.size(); ++i)
    {
        auto entity = collidableEntities[i];

        auto particleComponent = std::static_pointer_cast<ParticleComponent>(Engine::GetInstance().GetSingleComponentOfClass(entity, "ParticleComponent"));
        auto position = particleComponent->GetPosition();
        auto quadtreeEntities = quadtree.Get(position);

        for (unsigned int j = 0; j < quadtreeEntities.size(); ++j)
        {
            auto otherEntity = quadtreeEntities[j];

            if (std::find(deletedEntities.begin(), deletedEntities.end(),  entity->GetId()) != deletedEntities.end())
                continue;

            if (std::find(deletedEntities.begin(), deletedEntities.end(),  otherEntity->GetId()) != deletedEntities.end())
                continue;

            if (entity->GetId() != otherEntity->GetId()
                && IsColliding(entity, otherEntity))
                SolveCollision(entity, otherEntity);
        }
    }
}
Exemplo n.º 23
0
Float RotateGameObject(Script * script)
{
	if (script->VerifyArguments(3) == true)
	{
		Word * rotatePosWord = script->GetNextWord();
		Point2D rotatePosition(0, 0);
		Point2D * rotatePos = (Point2D *)(uint32)rotatePosWord->value;
		if (rotatePos != NULL)
		{
			rotatePosition.SetValues(rotatePos->GetX(), rotatePos->GetY());
		}

		Word * angleWord = script->GetNextWord();

		Word * directionWord = script->GetNextWord();
		Vector3D direction(0, 0, 0);
		Point2D * dirVector = (Point2D *)(uint32)directionWord->value;
		if (dirVector != NULL)
		{
			direction.SetValues(dirVector->GetX(), dirVector->GetY(), 0);
		}

		GameObject * source = (GameObject *)script->GetSource();
		Shape * shape = source->GetShape();
		
		if ((rotatePos != NULL) && (source != NULL) && (source->CheckType(OBJ_TYPE_GAME_OBJECT) == true) && (shape != NULL))
		{
			Float distance = CalculateDistance(rotatePosition, source->GetPosition());
			if (angleWord->value != NULL)
			{
				Vector3D sourceDirection(rotatePosition, source->GetPosition());
				Float angle = sourceDirection.GetZeroAngleD() + angleWord->value;
				
				source->SetPosition(rotatePosition.GetX() + (distance * CosD(angle)),
									rotatePosition.GetY() + (distance * SinD(angle)));

				direction.SetValues(rotatePosition, source->GetPosition());
				direction.SetUnitVector();
			}
			else if (dirVector != NULL)
			{
				direction -= rotatePosition;
				direction.SetUnitVector();

				source->SetPosition(rotatePosition.GetX() + (direction.GetX() * distance),
									rotatePosition.GetY() + (direction.GetY() * distance));
			}
			else
			{
				return false;
			}

			if ((shape->GetType() == SHAPE_TYPE_LINE) || (shape->GetType() == SHAPE_TYPE_LINE_SEGMENT))
			{
				Line * line = (Line *)shape;
				Line * newLine = (Line *)line->CreateInstance();
				newLine->Translate(source->GetPosition());	

				Vector3D v1(rotatePosition, newLine->GetPoint1());
				Vector3D v2(rotatePosition, newLine->GetPoint2());

				Float baseAngle = direction.GetZeroAngleD();

				Float v1Length = v1.GetLength();
				Float v2Length = v2.GetLength();
				Float angle1 = v1.GetZeroAngleD() - baseAngle;
				Float angle2 = v2.GetZeroAngleD() - baseAngle;

				Point2D p1((v1Length * CosD(angle1)),
						   (v1Length * SinD(angle1)));
				Point2D p2((v2Length * CosD(angle2)),
						   (v2Length * SinD(angle2)));

				line->SetValues(p1 + rotatePosition, p2 + rotatePosition);

				line->Translate(!source->GetPosition());

				delete newLine;
			}
			else if (shape->GetType() == SHAPE_TYPE_CONE)
			{
				Cone * cone = (Cone *)shape;
				cone->SetValues(cone->GetVertex(), Vector3D(dirVector->GetX(), dirVector->GetY(), 0), cone->GetHeight(), cone->GetAngle());
			}
			return true;
		}
	}
	return false;
}
Exemplo n.º 24
0
bool PrlxPhysics::HitTest(PRLX_Circle A, PRLX_Circle B)
{
    return (CalculateDistance(Point(A.pos.x, A.pos.y), Point(B.pos.x, B.pos.y)) <= A.radius + B.radius);
}
Exemplo n.º 25
0
bool PrlxPhysics::HitTest(PRLX_Circle circle, PRLX_Point point)
{
    return (CalculateDistance(Point(circle.pos.x, circle.pos.y), point) <= circle.radius);
}
Exemplo n.º 26
0
void Point2PhantomNode::CalculateWeight(OsrmMappingTypes::FtSeg const & seg,
                                        m2::PointD const & segPt, NodeID const & nodeId,
                                        bool calcFromRight, int & weight, int & offset) const
{
  // nodeId can be INVALID_NODE_ID when reverse node is absent. This node has no weight.
  if (nodeId == INVALID_NODE_ID)
  {
    offset = 0;
    weight = 0;
    return;
  }

  Index::FeaturesLoaderGuard loader(m_index, m_routingMapping.GetMwmId());

  // Offset is measured in milliseconds. We don't know about speed restrictions on the road.
  // So we find it by a whole edge weight.
  // Distance from the node border to the projection point is in meters.
  double distanceM = 0.;
  // Whole node distance in meters.
  double fullDistanceM = 0.;
  // Minimal OSRM edge weight in milliseconds.
  EdgeWeight minWeight = 0;

  auto const range = m_routingMapping.m_segMapping.GetSegmentsRange(nodeId);
  OsrmMappingTypes::FtSeg segment;

  size_t const startIndex = calcFromRight ? range.second - 1 : range.first;
  size_t const endIndex = calcFromRight ? range.first - 1 : range.second;
  int const indexIncrement = calcFromRight ? -1 : 1;

  bool foundSeg = false;
  m2::PointD lastPoint;
  for (size_t segmentIndex = startIndex; segmentIndex != endIndex; segmentIndex += indexIncrement)
  {
    m_routingMapping.m_segMapping.GetSegmentByIndex(segmentIndex, segment);
    if (!segment.IsValid())
      continue;

    FeatureType ft;
    loader.GetFeatureByIndex(segment.m_fid, ft);
    ft.ParseGeometry(FeatureType::BEST_GEOMETRY);

    // Find whole edge weight by node outgoing point.
    if (segmentIndex == range.second - 1)
      minWeight = GetMinNodeWeight(nodeId, ft.GetPoint(segment.m_pointEnd));

    // Calculate distances.
    double distance = CalculateDistance(ft, segment.m_pointStart, segment.m_pointEnd);
    fullDistanceM += distance;
    if (foundSeg)
      continue;

    if (segment.m_fid == seg.m_fid && OsrmMappingTypes::IsInside(segment, seg))
    {
      auto const splittedSegment = OsrmMappingTypes::SplitSegment(segment, seg, !calcFromRight);
      distanceM += CalculateDistance(ft, splittedSegment.m_pointStart, splittedSegment.m_pointEnd);
      // node.m_seg always forward ordered (m_pointStart < m_pointEnd)
      distanceM -= MercatorBounds::DistanceOnEarth(
          ft.GetPoint(calcFromRight ? seg.m_pointStart : seg.m_pointEnd), segPt);

      foundSeg = true;
    }
    else
    {
      distanceM += distance;
    }
  }

  ASSERT_GREATER(fullDistanceM, 0, ("No valid segments on the edge."));
  double const ratio = (fullDistanceM == 0) ? 0 : distanceM / fullDistanceM;
  ASSERT_LESS_OR_EQUAL(ratio, 1., ());

  // OSRM calculates edge weight form start to user point how offset + weight.
  // But it doesn't place info about start and end edge result weight into result structure.
  // So we store whole edge weight into offset and calculates this weights at a postprocessing step.
  offset = minWeight;
  weight = max(static_cast<int>(minWeight * ratio), 0) - minWeight;
}
Exemplo n.º 27
0
cm Striker::CalculateDistanceFromMe(cm xLocation, cm yLocation)
{
	return CalculateDistance(m_localization->GetMyLocation().x, xLocation,
			m_localization->GetMyLocation().y, yLocation);
}
Exemplo n.º 28
0
//Ray-Marching
CVector3 cRenderWorker::RayMarching(sRayMarchingIn &in, sRayMarchingInOut *inOut,
		sRayMarchingOut *out)
{
	CVector3 point;
	bool found = false;
	double scan = in.minScan;
	double dist = 0;
	double search_accuracy = 0.01 * params->detailLevel;
	double search_limit = 1.0 - search_accuracy;
	int counter = 0;
	double step = 0.0;
	(*inOut->buffCount) = 0;
	double distThresh;
	out->objectId = 0;

	//qDebug() << "Start ************************";

	CVector3 lastPoint, lastGoodPoint;
	bool deadComputationFound = false;

	for (int i = 0; i < 10000; i++)
	{
		lastGoodPoint = lastPoint;
		lastPoint = point;

		counter++;

		point = in.start + in.direction * scan;

		if (point == lastPoint || point == point/0.0) //detection of dead calculation
		{
			//qWarning() << "Dead computation\n"
			//		<< "Point:" << point.Debug()
			//		<< "\nPrevious point:" << lastPoint.Debug();
			point = lastPoint;
			found = true;
			deadComputationFound = true;
			break;
		}

		distThresh = CalcDistThresh(point);

		sDistanceIn distanceIn(point, distThresh, false);
		sDistanceOut distanceOut;
		dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data);
		//qDebug() <<"thresh" <<  distThresh << "dist" << dist << "scan" << scan;
		if (in.invertMode)
		{
			dist = distThresh * 1.99 - dist;
			if (dist < 0.0) dist = 0.0;
		}
		out->objectId = distanceOut.objectId;

		//-------------------- 4.18us for Calculate distance --------------

		//printf("Distance = %g\n", dist/distThresh);
		inOut->stepBuff[i].distance = dist;
		inOut->stepBuff[i].iters = distanceOut.iters;
		inOut->stepBuff[i].distThresh = distThresh;

		data->statistics.histogramIterations.Add(distanceOut.iters);
		data->statistics.totalNumberOfIterations += distanceOut.totalIters;

		if (dist > 3.0) dist = 3.0;
		if (dist < distThresh)
		{
			if (dist < 0.1 * distThresh) data->statistics.missedDE++;
			found = true;
			break;
		}

		inOut->stepBuff[i].step = step;
		if (params->interiorMode)
		{
			step = (dist - 0.8 * distThresh) * params->DEFactor * (1.0 - Random(1000) / 10000.0);
			;
		}
		else
		{
			step = (dist - 0.5 * distThresh) * params->DEFactor * (1.0 - Random(1000) / 10000.0);
			;
		}
		inOut->stepBuff[i].point = point;
		//qDebug() << "i" << i << "dist" << inOut->stepBuff[i].distance << "iters" << inOut->stepBuff[i].iters << "distThresh" << inOut->stepBuff[i].distThresh << "step" << inOut->stepBuff[i].step << "point" << inOut->stepBuff[i].point.Debug();
		(*inOut->buffCount) = i + 1;
		scan += step / in.direction.Length(); //divided by length of view Vector to eliminate overstepping when fov is big
		if (scan > in.maxScan)
		{
			break;
		}

	}
	//------------- 83.2473 us for RayMarching loop -------------------------

	//qDebug() << "------------ binary search";
	if (found && in.binaryEnable && !deadComputationFound)
	{
		step *= 0.5;
		for (int i = 0; i < 30; i++)
		{
			counter++;
			if (dist < distThresh && dist > distThresh * search_limit)
			{
				break;
			}
			else
			{
				if (dist > distThresh)
				{
					scan += step;
					point = in.start + in.direction * scan;
				}
				else if (dist < distThresh * search_limit)
				{
					scan -= step;
					point = in.start + in.direction * scan;
				}
			}

			distThresh = CalcDistThresh(point);

			sDistanceIn distanceIn(point, distThresh, false);
			sDistanceOut distanceOut;
			dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data);

			//qDebug() << "i" << i <<"thresh" <<  distThresh << "dist" << dist << "scan" << scan << "step" << step;

			if (in.invertMode)
			{
				dist = distThresh * 1.99 - dist;
				if (dist < 0.0) dist = 0.0;
			}

			out->objectId = distanceOut.objectId;

			data->statistics.histogramIterations.Add(distanceOut.iters);
			data->statistics.totalNumberOfIterations += distanceOut.totalIters;

			step *= 0.5;
		}
	}
	if (params->iterThreshMode)
	{
		//this fixes problem with noise when there is used "stop at maxIter" mode
		scan -= distThresh;
		point = in.start + in.direction * scan;
	}

	//---------- 7.19605us for binary searching ---------------

	data->statistics.histogramStepCount.Add(counter);

	out->found = found;
	out->lastDist = dist;
	out->depth = scan;
	out->distThresh = distThresh;
	data->statistics.numberOfRaymarchings++;
	return point;
}
Exemplo n.º 29
0
long CalculateDistance(const POINT& pt1, const POINT& pt2)
{
	return CalculateDistance(pt1.x, pt1.y, pt2.x, pt2.y);
}
Exemplo n.º 30
0
BOOL PtInCircle(const POINT& pt, const POINT& ptOrigin, int nRadius)
{
	return CalculateDistance(pt, ptOrigin) < ::abs(nRadius);
}