Ejemplo n.º 1
0
/***********************************************************************

  HandleButton() - this function determines if the end effector of the 
		structure has been grabbed or not.

***********************************************************************/
int 
HandleButton(MyProgram *data)
{
   pointType curr_p;

   curr_p.x = data->curr_mousx;
   curr_p.y = InvertY(data->curr_mousy);

   if (data->button_state == BUTTON_DOWN)  /* check if actually grabbed */

      if (PointInBox(curr_p, data->end_effect.extent) == TRUE) {
         data->endgrabbed = TRUE;
         printf("end effector was grabbed\n");
      }
      else
         data->endgrabbed = FALSE;

   else
      return(1);			/* error, unknown button state */
   
   return(0);
} /* end of HandleButton() */
Ejemplo n.º 2
0
//---------------------------------------------------------------------------
std::vector<int> BDOctTree::SphereInNode(BDOctNode* node, float x, float y, float z, float sz) {
  std::vector<int> nodelist, dummy;

  for (short index = 0; index < 8; index++) {
    if (PointInBox(Nodes[node->children[index]].x1 - sz, Nodes[node->children[index]].x2 + sz,
                   Nodes[node->children[index]].y1 - sz, Nodes[node->children[index]].y2 + sz,
                   Nodes[node->children[index]].z1 - sz, Nodes[node->children[index]].z2 + sz,
                   x, y, z)) {
      // If this child is the smallest
      if (Nodes[node->children[index]].children[0] == 0) {
        nodelist.push_back(node->children[index]);
      } else {
        dummy = SphereInNode(&Nodes[node->children[index]], x, y, z, sz);
        while(dummy.size() > 0) {
          nodelist.push_back(dummy.back());
          dummy.pop_back();
        }
      }
    }
  }

  return nodelist;
}
Ejemplo n.º 3
0
void GUIControl::Process()
{
	__super::Process();

	if(IsVisible() && IsEnabled())
	{
		if(PointInBox(mouseX, mouseY, GetX(), GetY(), GetWidth(), GetHeight()))
		{

			int cursor = GetLastCursorPos();
			SetLastCursorPos(1); // mouse is in

			// here
			// 0 - init
			// 1 - mouse was IN control
			// 2 - mouse was OUT control

			if(cursor == 0 || cursor == 2)
			{
				OnMouseEnter();
			}
			else
			{
				OnMouseMove();
			}

			if(mouse[0] || mouse[1])
			{
				if(GetLastPressState() == 0)
				{
					OnMouseDown();

					if(mouse[0])
						SetLastPressState(1);
					else if(mouse[1])
						SetLastPressState(2);
				}
			}
			else
			{
				int press_state = GetLastPressState();
				SetLastPressState(0);

				// here
				// 0 - init
				// 1 - left mouse down
				// 2 - right mouse down
				// 3 - all up

				if(press_state == 1)
				{
					OnLeftClick();
					OnMouseUp();
				}
				else if(press_state == 2)
				{
					OnRightClick();
					OnMouseUp();
				}
			}
		}
		else
		{
			int cursor = GetLastCursorPos();
			SetLastCursorPos(2); // mouse is out

			if(cursor == 1)
			{
				OnMouseLeave();
				SetLastPressState(0);
			}
		}


		// TODO:
		// fix it somehow :(
		if(IsFocused())
		{
			static UCHAR count = 0;
			int delay = 0;
			for(UCHAR i = 0; i < 255; i++)
			{			
				if(GetAsyncKeyState(i) & 0x8000)
				{
					count++;
					static int prev;
					count == 1 ? delay = KEY_FIRST_DELAY : delay = KEY_DELAY;

					if(current_time - prev >= delay)
					{
						if(i != VK_SHIFT)
						{
							OnKeyDown(i);
							prev = current_time;
						}
					}
				}
			}
		}
	}
}
Ejemplo n.º 4
0
//
// Is the given point in the boundingbox ??
//
bool wxBoundingBox::PointInBox(const wxPoint2DDouble& a, double Marge) const
{
    assert (m_validbbox == TRUE);

    return PointInBox(a.m_x, a.m_y, Marge);
}
Ejemplo n.º 5
0
void GUIcontrol::Process()
{
	if(visible)
	{
		if(GetChildCount() == 0)
		{
			if(PointInBox(mouseX, mouseY, GetPosX(), GetPosY(), GetPatternWidth(), GetPatternHeight()))
			{
				GUIMessage temp_message;
							
				if(GetPatternCount() > 1)
					SetCurrentPattern(1);

				//temp_message.from = GetGID();
				//temp_message.a1 = MOUSE_OVER;
				//temp_message.a2 = 0;

				if(mouse[0])
				{
					_pressed = true;
					//mouse[0] = false;

					
					if(GetPatternCount() > 1)
					{
						SetCurrentPattern(2);
						_pos_dx = 1;
						_pos_dy = 1;
						if(_caption)
						{
							_caption_dx = 1;
							_caption_dy = 1;
						}
					}
				}
				else
				{
					_pos_dx = 0;
					_pos_dy = 0;
					if(_caption)
					{
						_caption_dx = 0;
						_caption_dy = 0;
					}

					if(_pressed)
					{
						_pressed = false;

						temp_message.from = GetGID();
						temp_message.a1 = MOUSE_LEFT_CLICKED;
						temp_message.a2 = 0;
						temp_message.solved = false;

						SendMessage(temp_message);

					}

				}

			}

			else
			{
				if(GetCurrentPattern() != 0) SetCurrentPattern(0);
			}
		}
	}

}
Ejemplo n.º 6
0
void FizzyWindow::OnDisplay()
{
	//double DT = gameTime.Update();

	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	scn.Draw();

	glColor3f(1,1,1);

	float2 BL = MouseToSpace2(0, 0, windowResolution.y, scn.zoom, scn.camPos);
	float2 TR = MouseToSpace2(windowResolution.x, windowResolution.y, windowResolution.y, scn.zoom, scn.camPos);

	glDisable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glRasterPos2f(0.4f, 0.9f);

	float yPos = 0.9;
	float yDiff = -0.05;

	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	//int objectCount = scn.netController->mode&NetworkController::Simulating ? scn.objects.size()/2-4 : scn.objects.size()-4;

	int objectCount=0;
	for(int i=4;i<scn.objects.size();++i)
		if(scn.objects[i]->owner == SimBody::whoami)
			++objectCount;

	Printf("Owned Objects: %d", objectCount);

	scn.mypvr.bl = BL;
	scn.mypvr.tr = TR;

	float L = BL.x;
	float R = TR.x;
	float B = BL.y;
	float T = TR.y;

	int myObjects=0, othersObjects=0;
	for(int i=4;i<scn.objects.size();++i)
	{
		if(PointInBox(scn.objects[i]->position, L,R,B,T))
		{
			if(scn.objects[i]->owner == SimBody::whoami)
			{
				++myObjects;
			}
			else
			{
				++othersObjects;
			}
		}
	}

	glRasterPos2f(0.3, 0.9);
	Printf("Press 'c' to connect");
	glRasterPos2f(0.3, 0.85);
	Printf("Press 'o' to enable/disable ownership");
	glRasterPos2f(0.3,0.8);
	Printf("Ownership Migration: %s", scn.doOwnershipUpdates?"Enabled":"Disabled");

	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	Printf("# Owned Objects displayed: %d", myObjects);

	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	Printf("# Not owned objects displayed: %d", othersObjects);
	
	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	Printf("Spring Magnitude: %f", scn.springForce.magnitude());

	float avgTime = 1.0f/(float)CalcAverageTick((float)scn.frameTime); // physics fps
	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	Printf("Avg. physics iterations/s: %d", (int)avgTime);


	int avgSent = CalcAverageSent(scn.numberOfObjectsSent);
	scn.numberOfObjectsSent = 0;
	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	Printf("Avg. objects sent/s: %d", avgSent);

	int avgRecv = CalcAverageRecv(scn.numberOfObjectsRecv);
	scn.numberOfObjectsRecv = 0;
	glRasterPos2f(-0.9f,yPos); yPos += yDiff;
	Printf("Avg. objects received/s: %d", avgRecv);

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();   
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glEnable(GL_DEPTH_TEST);

	SwapBuffers();
};