Exemplo n.º 1
0
void CGView::mouseMoveEvent(QMouseEvent *event) {
    QPoint current = event->pos();


    int x = current.x();
    int y = current.y();
    int xClick = clickedPoint.x();
    int yClick = clickedPoint.y();

    double diffX, diffY;
    double dx, dy, dxClick, dyClick;
    worldCoord(x, y, dx, dy);
    worldCoord(xClick, yClick, dxClick, dyClick);
    diffX = dx - dxClick;
    diffY = dy - dyClick;

    // add code here to move the picked lizard

    trans[i_picked][0] = clickedPolyTrans[0] + diffX;
    trans[i_picked][1] = clickedPolyTrans[1] + diffY;

    //if (event->button() == Qt::LeftButton)

    std::cout << "clickedPoint (" << diffX << "," << diffY << "," << dxClick << "," << dyClick << ")" << std::endl;

    if (clicked)
        updateGL();
}
Exemplo n.º 2
0
void CGView::mousePressEvent(QMouseEvent *event) {
    double dx, dy, px, py;
    worldCoord(event->x(), event->y(), dx, dy);
    std::cout << "Mouse pressed at (" << dx << "," << dy << ")" << std::endl;
    px = dx;
    py = dy;
    bool inI;

    if (event->button() == Qt::LeftButton)
        clicked = true;

    clickedPoint = event->pos();

    // add your intersect code here
    // also set the new i_picked
    for (int i = 0; i < poly.size(); i++) {
        inI = insidePolygonI(i, px, py);

        if (inI) {
            i_picked = i;
            std::cout << "Polygon " << i << " selected" << std::endl;
            clickedPolyTrans.clear();
            clickedPolyTrans.push_back(trans[i_picked][0]);
            clickedPolyTrans.push_back(trans[i_picked][1]);
        }
    }

    update();

}
Exemplo n.º 3
0
void csMeshGeneratorGeometry::GetDensityMapFactor (float x, float z,
                                                   float &data)
{
  float factorMapScale = 1.0f;
  if (density_map)
  {
    density_map->SampleFloat (density_map_type, x, z, factorMapScale); 
    factorMapScale *= density_map_factor;  
  }
  data = factorMapScale;

  // Sum up all density factor maps
  if (densityFactorMaps.GetSize() > 0)
  {
    csVector3 worldCoord (x, 0, z);
    float factorMapSum = 0;
    for (size_t i = 0; i < densityFactorMaps.GetSize(); i++)
    {
      factorMapSum += densityFactorMaps[i].first->GetDensity (worldCoord)
	* densityFactorMaps[i].second;
    }    
    
    data *= factorMapSum;
  }
}
Exemplo n.º 4
0
/* Mouse clicks. */
void mouse(int button, int state, int x, int y)
{
	if (state == GLUT_DOWN)
	{
		/* Save mouse positions for everything but zooming. */
		if (button == GLUT_LEFT_BUTTON || button == GLUT_RIGHT_BUTTON
		    || button == GLUT_MIDDLE_BUTTON)
		{
			interaction.lastMouseDownBS[0] = x;
			interaction.lastMouseDownBS[1] = y;
			worldCoord(interaction.lastMouseDownBS,
			           interaction.lastMouseDownBW);
			interaction.lastMouseDownEW[0] = interaction.lastMouseDownBW[0];
			interaction.lastMouseDownEW[1] = interaction.lastMouseDownBW[1];
		}

		if (button == GLUT_LEFT_BUTTON)
		{
			interaction.showOvertones = 1;
		}
		else if (button == GLUT_RIGHT_BUTTON && !interaction.forceOverview)
		{
			interaction.doPanning = 1;
			interaction.lastOffsetX = interaction.offsetX;
		}
		else if (button == INTERACTION_ZOOM_IN)
		{
			interaction.scaleX *= INTERACTION_ZOOM_SPEED;
		}
		else if (button == INTERACTION_ZOOM_OUT)
		{
			interaction.scaleX /= INTERACTION_ZOOM_SPEED;
			if (interaction.scaleX < 1)
				interaction.scaleX = 1;
		}
		else if (button == GLUT_MIDDLE_BUTTON)
		{
			interaction.showFrequency = 1;
		}
	}
	else
	{
		/* Copy new offset if we were panning. */
		if (interaction.doPanning)
		{
			double dx = interaction.lastMouseDownEW[0]
			            - interaction.lastMouseDownBW[0];
			interaction.offsetX = interaction.lastOffsetX + dx;
			interaction.lastOffsetX = interaction.offsetX;
		}

		interaction.showOvertones = 0;
		interaction.doPanning = 0;
		interaction.showFrequency = 0;
	}
}
Exemplo n.º 5
0
void renderFrame(void) {
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 162, 232), 1.0f, 0);	// use 0, 162, 232 for nice blue color

	d3ddev->BeginScene();    // begins the 3D scene

	// SET UP THE PIPELINE
	D3DXMATRIX matTranslate;

	Vector2 mousePos = worldCoord(mouseX, mouseY);

	D3DXMatrixTranslation(&matTranslate, mousePos.x, mousePos.y, 0);

	D3DXMATRIX matView;    // the view transform matrix

	D3DXMatrixLookAtRH(&matView,
		&D3DXVECTOR3(0.0f, 0.0f, 5.0f),    // the camera position
		&D3DXVECTOR3(0.0f, 0.0f, 0.0f),    // the look-at position
		&D3DXVECTOR3(0.0f, 1.0f, 0.0f));    // the up direction

	d3ddev->SetTransform(D3DTS_VIEW, &(matView));    // set the view transform to matView

	D3DXMATRIX matProjection;     // the projection transform matrix

	D3DXMatrixOrthoRH(&matProjection,
		viewWidth,	// the horizontal view volume
		viewWidth * currentRatio,	// the vertical view volume
		0.25f,    // the near view-plane
		15.0f);    // the far view-plane

	d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection

	d3ddev->SetTexture(0, tx);

	// select the vertex buffer to display
	d3ddev->SetStreamSource(0, vb, 0, sizeof(CUSTOMVERTEX));

	// copy the vertex buffer to the back buffer
	d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

	RECT rect;

	SetRect(&rect, 0, 0, wndWidth, wndHeight);

	font->DrawTextA(NULL, "Everward", 8, &rect, DT_CENTER | DT_VCENTER, 0xffffff00);

	d3ddev->EndScene();    // ends the 3D scene

	d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}
Exemplo n.º 6
0
/* Mouse movements/drags. */
void motion(int x, int y)
{
	if (!interaction.showOvertones && !interaction.doPanning
	    && !interaction.showFrequency)
		return;

	interaction.lastMouseDownES[0] = x;
	interaction.lastMouseDownES[1] = y;
	worldCoord(interaction.lastMouseDownES, interaction.lastMouseDownEW);

	if (interaction.doPanning)
	{
		double dx = interaction.lastMouseDownEW[0]
		            - interaction.lastMouseDownBW[0];
		interaction.offsetX = interaction.lastOffsetX + dx;
	}
}