//----------------------------------------------------------------------------
bool MapTextureToQuad::OnMouseClick (int button, int state, int x, int y,
    unsigned int)
{
    if (button != MOUSE_LEFT_BUTTON)
    {
        return false;
    }

    if (state == MOUSE_DOWN)
    {
        mMouseDown = true;
        SelectVertex(Vector2f((float)x, (float)y));
        return true;
    }

    if (state == MOUSE_UP)
    {
        mMouseDown = false;
        if (mSelected >= 0
        &&  0 <= x && x < GetWidth()
        &&  0 <= y && y < GetHeight())
        {
            UpdateQuadrilateral(Vector2f((float)x, (float)y));
        }
        return true;
    }

    return false;
}
//----------------------------------------------------------------------------
bool QuadraticFreeForm2D::OnMouseClick (int button, int state, int x, int y,
    unsigned int)
{
    if (button != MOUSE_LEFT_BUTTON)
    {
        return false;
    }

    // Handle the flip in y that is used for drawing.
    y = mSize - 1 - y;

    if (state == MOUSE_DOWN)
    {
        mMouseDown = true;
        SelectVertex(x, y);
        return true;
    }

    if (state == MOUSE_UP)
    {
        mMouseDown = false;
        if (mRow >= 0 && mCol >= 0
        &&  0 <= x && x < GetWidth() && 0 <= y && y < GetHeight())
        {
            mCtrlX[mRow][mCol] = x;
            mCtrlY[mRow][mCol] = y;
            mCtrl[mRow][mCol].X() = ScreenToControl(x);
            mCtrl[mRow][mCol].Y() = ScreenToControl(y);
            OnDisplay();
        }
        return true;
    }

    return false;
}
void SelectVertexByRay (vec3_t org, vec3_t dir)
{
	int		i, besti;
	float	d, bestd;
	vec3_t	temp;

	// find the point closest to the ray
	besti = -1;
	bestd = 8;

	for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
	{
		VectorSubtract (g_qeglobals.d_points[i], org, temp);
		d = DotProduct (temp, dir);
		VectorMA (org, d, dir, temp);
		VectorSubtract (g_qeglobals.d_points[i], temp, temp);
		d = VectorLength (temp);
		if (d < bestd)
		{
			bestd = d;
			besti = i;
		}
	}

	if (besti == -1)
	{
		Sys_Printf ("Click didn't hit a vertex\n");
		return;
	}
	Sys_Printf ("hit vertex\n");
	SelectVertex (besti);
}
Beispiel #4
0
//
//   This file contains the C++ code from Program 16.9 of
//   "Data Structures and Algorithms
//    with Object-Oriented Design Patterns in C++"
//   by Bruno R. Preiss.
//
//   Copyright (c) 1998 by Bruno R. Preiss, P.Eng.  All rights reserved.
//
//   http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/programs/pgm16_09.cpp
//
void Digraph::TopologicalOrderTraversal (Visitor& visitor) const
{
    Array<unsigned int> inDegree (numberOfVertices);
    for (Vertex::Number v = 0; v < numberOfVertices; ++v)
	inDegree [v] = 0;
    Iterator& p = Edges ();
    while (!p.IsDone ()) {
	Edge& edge = dynamic_cast<Edge&> (*p);
	++inDegree [edge.V1 ()];
	++p;
    }
    delete &p;

    Queue& queue = *new QueueAsLinkedList ();
    queue.RescindOwnership ();
    for (Vertex::Number v = 0; v < numberOfVertices; ++v)
	if (inDegree [v] == 0)
	    queue.Enqueue (SelectVertex (v));
    while (!queue.IsEmpty () && !visitor.IsDone ())
    {
	Vertex& vertex =
	    dynamic_cast<Vertex&> (queue.Dequeue ());
	visitor.Visit (vertex);
	Iterator& q = EmanatingEdges (vertex);
	while (!q.IsDone ()) {
	    Edge& edge = dynamic_cast<Edge&> (*q);
	    Vertex& to = edge.V1 ();
	    if (--inDegree [to] == 0)
		queue.Enqueue (to);
	    ++q;
	}
	delete &q;
    }
    delete &queue;
}
//----------------------------------------------------------------------------
void MapTextureToQuad::OnMouseClick (int iButton, int iState, int iX,
    int iY, unsigned int)
{
    if ( iButton != MOUSE_LEFT_BUTTON )
        return;

    if ( iState == MOUSE_DOWN )
    {
        m_bMouseDown = true;
        SelectVertex(Vector2f((float)iX,(float)iY));
    }
    else if ( iState == MOUSE_UP )
    {
        m_bMouseDown = false;
        if ( m_iSelected >= 0
        &&   0 <= iX && iX < GetWidth()
        &&   0 <= iY && iY < GetHeight() )
        {
            UpdateQuadrilateral(Vector2f((float)iX,(float)iY));
        }
    }
}