示例#1
0
void GUI2015_Event(enGUI2015Event evt) {

	int bestfit = -1;

	switch(evt)
	{
		case eGUI2015Event_LEFT:		bestfit = FindClosest(4); break;
		case eGUI2015Event_RIGHT:	bestfit = FindClosest(6); break;
		case eGUI2015Event_UP:		bestfit = FindClosest(2); break;
		case eGUI2015Event_DOWN:	bestfit = FindClosest(8); break;

		case eGUI2015Event_B1ON: {
			if(selected != -1) {
				int objn = selectable[selected];
				enGUI2015Obj objtype = GUI2015_ObjType(objn);

				if(objtype == eGUI2015_OBJ_CHBOX) {
					void *objptr = GUI2015_ObjPtr(objn);
					stGUI2015Checkbox *chk = (stGUI2015Checkbox *)objptr;
					// chk->val ^= 1;
                                        if(! chk->val) chk->val = 1; else chk->val = 0;
					GUI2015_DrawObject( objptr,  eGUI2015State_Selected );
				} else if(objtype == eGUI2015_OBJ_BUT) {
					void *objptr = GUI2015_ObjPtr(objn);
					stGUI2015Button *p = (stGUI2015Button *)objptr;
					if(p->attr & eGUI2015Button_Locked) {  p->attr &= ~ eGUI2015Button_Locked; } else { p->attr |= eGUI2015Button_Locked; }
					GUI2015_DrawObject( objptr,  eGUI2015State_Selected );
				}
			}
		}
		break;

		case eGUI2015Event_B1OFF:	{ } break;
		case eGUI2015Event_B2ON: { } break;
		case eGUI2015Event_B2OFF: { } break;

		default: { }
	}

	if(bestfit != -1) {
		// Draw Previous
		GUI2015_DrawObject( GUI2015_ObjPtr( selectable[selected] ) ,  eGUI2015State_Normal );

		// Draw next
		selected = bestfit;
		GUI2015_DrawObject( GUI2015_ObjPtr( selectable[selected] ) , eGUI2015State_Selected );
	}

}
示例#2
0
void R3MeshSearchTree::
FindClosest(const R3Point& query_position, R3MeshIntersection& closest,
  RNScalar min_distance, RNScalar max_distance,
  int (*IsCompatible)(const R3Point&, const R3Vector&, R3Mesh *, R3MeshFace *, void *), void *compatible_data)
{
  // Find closest point, ignoring normal
  FindClosest(query_position, R3zero_vector, closest, min_distance, max_distance, IsCompatible, compatible_data);
}
示例#3
0
void R3MeshSearchTree::
FindClosest(const R3Point& query_position, const R3Vector& query_normal, R3MeshIntersection& closest,
  RNScalar min_distance, RNScalar max_distance,
  int (*IsCompatible)(const R3Point&, const R3Vector&, R3Mesh *, R3MeshFace *, void *), void *compatible_data)
{
  // Initialize result
  closest.type = R3_MESH_NULL_TYPE;
  closest.vertex = NULL;
  closest.edge = NULL;
  closest.face = NULL;
  closest.point = R3zero_point;
  closest.t = 0;

  // Check root
  if (!root) return;

  // Update mark (used to avoid checking same face twice)
  mark++;

  // Use squared distances for efficiency
  RNScalar min_distance_squared = min_distance * min_distance;
  RNScalar closest_distance_squared = max_distance * max_distance;

  // Search nodes recursively
  FindClosest(query_position, query_normal, closest,
    min_distance_squared, closest_distance_squared,
    IsCompatible, compatible_data,
    root, BBox());

  // Update result
  closest.t = sqrt(closest_distance_squared);
  if (closest.type == R3_MESH_VERTEX_TYPE) {
    closest.edge = mesh->EdgeOnVertex(closest.vertex);
    closest.face = mesh->FaceOnEdge(closest.edge);
  }
  else if (closest.type == R3_MESH_EDGE_TYPE) {
    closest.vertex = NULL;
    closest.face = mesh->FaceOnEdge(closest.edge);
  }
  else if (closest.type == R3_MESH_FACE_TYPE) {
    closest.vertex = NULL;
    closest.edge = NULL;
  }
}
示例#4
0
void Boid::PreUpdate()
{
	// find nearest boids
	BoidFriend boids[5];
	int count = 0;
	FindClosest(boids, count, 5);

	// avoid walls
	AvoidWalls();

	// update anger
	if (count != 0)
	{
		float anger = 0.f;
		for (int i = 0; i != count; ++i)
			anger += boids[i].boid->m_Anger;
		anger /= count;

		// slowly adjust towards group anger
		if (anger > m_Anger)
			m_Anger += g_FrameTime * count;
		else
			m_Anger -= g_FrameTime * 0.5f;
	}

	m_Anger += Rand(0.f, 0.05f) * g_FrameTime;
	m_Anger = Clamp(m_Anger, 0.f, 1.f);

	// calculate flocking steering
	AddForce(Flock(boids, count));

	// attack if angry, otherwise flock and wander
	if (m_Anger > 0.5f)
	{
		float t = (m_Anger - 0.5f) * 2.f;
		AddForce(Attack() * t);
	}
	else
		AddForce(Wander());
}
示例#5
0
/* this will insert all free extents that are holes,
 * created by existed allocated extents in the tree
 * from lowerBound to upperBound
 */
status_t
CachedExtentTree::FillFreeExtents(uint64 lowerBound, uint64 upperBound)
{
	CachedExtent* node = FindClosest(lowerBound, false);
	CachedExtent* hole = NULL;
	status_t status = B_OK;
	uint64 flags = node->flags & (~BTRFS_EXTENT_FLAG_ALLOCATED);
	if (lowerBound < node->offset) {
		hole = CachedExtent::Create(lowerBound, node->offset - lowerBound,
			flags);
		status = _AddFreeExtent(hole);
		if (status != B_OK)
			return status;
	}

	CachedExtent* next = NULL;
	while ((next = Next(node)) != NULL && next->End() < upperBound) {
		if (node->End() == next->offset) {
			node = next;
			continue;
		}

		hole = CachedExtent::Create(node->End(), next->offset - node->End(),
			flags);
		status = _AddFreeExtent(hole);
		if (status != B_OK)
			return status;
		node = next;
	}

	// final node should be a right most node
	if (upperBound > node->End()) {
		hole = CachedExtent::Create(node->End(), upperBound - node->End(),
			flags);
		status = _AddFreeExtent(hole);
	}

	return status;
}
示例#6
0
void RadarDopplerClass::NextTarget (void)
{
	//Step target starting with the closest one to us
	SimObjectType* rdrObj = platform->targetList;
	SimObjectType* NextFurther = NULL;
	
	
	if (mode != TWS)
	{
		float RangeToBeat; //next target needs to be further then this
		float MinRange = tdisplayRange;	//make sure we check the whole radar range
		
		if(lockedTarget)
		{
			//store our dist
			RangeToBeat = lockedTarget->localData->range;
			while(rdrObj)
			{
				//only what we've detected
				if(ObjectDetected(rdrObj))
				{
					//can't lock onto these
					if(!rdrObj->BaseData()->OnGround() && !rdrObj->BaseData()->IsMissile() && 
						!rdrObj->BaseData()->IsBomb() && !rdrObj->BaseData()->IsEject() &&
						rdrObj->localData->rdrDetect)
					{
						if(MinRange > rdrObj->localData->range)
						{ 
							if(rdrObj->localData->range > RangeToBeat)
							{
								NextFurther = rdrObj;
								MinRange = rdrObj->localData->range;
							}
						}
					}
				}
				if(!rdrObj->next)
					break;
				rdrObj = rdrObj->next;
			}
			if(NextFurther)
				SetDesiredTarget(NextFurther);
			else
				FindClosest(MinRange);
		}
		else
			FindClosest(MinRange);
	}
	else  // revised TWS mode TWS directory based targeting
	{
		if (IsSet(STTingTarget))
			return;  // no cycling if we are in STT

		if (lockedTarget && TWSTrackDirectory)
		{
			if (!IsSet(STTingTarget)) 
			{
				TWSTrackList* tmp = TWSTrackDirectory->OnList(lockedTarget);
				AddToHistory(lockedTarget, Track);  // demote current from bug to a track
				if (tmp)
					do
					{
						if (!tmp->Next())
							tmp = TWSTrackDirectory;
						else
							tmp = tmp->Next();
					} while ((tmp->TrackFile()->localData->extrapolateStart != 0)
						&& (tmp->TrackFile() != lockedTarget));

				ClearSensorTarget();  // ...and release it.
				// ...and if there's a suitable candidate bug it instead
				if (tmp && (tmp->TrackFile()->localData->extrapolateStart == 0))
				{
					SetDesiredTarget(tmp->TrackFile());
				}
			}
		}
		else if (TWSTrackDirectory)
			SetDesiredTarget(TWSTrackDirectory->TrackFile());
		else
			FindClosest(tdisplayRange);

		if (lockedTarget)
			AddToHistory(lockedTarget, Bug);  // promote new one to a bug
	}
}
示例#7
0
void R3MeshSearchTree::
FindClosest(const R3Point& query_position, const R3Vector& query_normal, R3MeshIntersection& closest,
  RNScalar min_distance_squared, RNScalar& max_distance_squared,
  int (*IsCompatible)(const R3Point&, const R3Vector&, R3Mesh *, R3MeshFace *, void *), void *compatible_data,
  R3MeshSearchTreeNode *node, const R3Box& node_box) const
{
  // Compute distance (squared) from query point to node bbox
  RNScalar distance_squared = DistanceSquared(query_position, node_box, max_distance_squared);
  if (distance_squared >= max_distance_squared) return;

  // Update based on distance to each big face
  for (int i = 0; i < node->big_faces.NEntries(); i++) {
    // Get face container and check mark
    R3MeshSearchTreeFace *face_container = node->big_faces[i];
    if (face_container->mark == mark) continue;
    face_container->mark = mark;

    // Find closest point in mesh face
    FindClosest(query_position, query_normal, closest,
      min_distance_squared, max_distance_squared,
      IsCompatible, compatible_data, face_container->face);
  }

  // Check if node is interior
  if (node->children[0]) {
    assert(node->children[1]);
    assert(node->small_faces.IsEmpty());

    // Compute distance from query point to split plane
    RNScalar side = query_position[node->split_dimension] - node->split_coordinate;

    // Search children nodes
    if (side <= 0) {
      // Search negative side first
      R3Box child_box(node_box);
      child_box[RN_HI][node->split_dimension] = node->split_coordinate;
      FindClosest(query_position, query_normal, closest,
        min_distance_squared, max_distance_squared, IsCompatible, compatible_data,
        node->children[0], child_box);
      if (side*side < max_distance_squared) {
        R3Box child_box(node_box);
        child_box[RN_LO][node->split_dimension] = node->split_coordinate;
        FindClosest(query_position, query_normal, closest,
          min_distance_squared, max_distance_squared, IsCompatible, compatible_data,
          node->children[1], child_box);
      }
    }
    else {
      // Search positive side first
      R3Box child_box(node_box);
      child_box[RN_LO][node->split_dimension] = node->split_coordinate;
      FindClosest(query_position, query_normal, closest,
        min_distance_squared, max_distance_squared, IsCompatible, compatible_data,
        node->children[1], child_box);
      if (side*side < max_distance_squared) {
        R3Box child_box(node_box);
        child_box[RN_HI][node->split_dimension] = node->split_coordinate;
        FindClosest(query_position, query_normal, closest,
          min_distance_squared, max_distance_squared, IsCompatible, compatible_data,
          node->children[0], child_box);
      }
    }
  }
  else {
    // Update based on distance to each small face
    for (int i = 0; i < node->small_faces.NEntries(); i++) {
      // Get face container and check mark
      R3MeshSearchTreeFace *face_container = node->small_faces[i];
      if (face_container->mark == mark) continue;
      face_container->mark = mark;

      // Find closest point in mesh face
      FindClosest(query_position, query_normal, closest,
        min_distance_squared, max_distance_squared,
        IsCompatible, compatible_data, face_container->face);
    }
  }
}