Esempio n. 1
0
void GLWidget::Update(/*DWORD milliseconds*/)									// Perform Motion Updates Here
{

 /*   if (isRClicked)													// If Right Mouse Clicked, Reset All Rotations
    {
        Matrix3fSetIdentity(&LastRot);								// Reset Rotation
        Matrix3fSetIdentity(&ThisRot);								// Reset Rotation
        Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);		// Reset Rotation
    }
*/
    if (!mouseIsDragging)												// Not Dragging
    {
        if (mouseIsPressed)												// First Click
        {
            this->mouseIsDragging = true;							// Prepare For Dragging
            LastRot = ThisRot;										// Set Last Static Rotation To Last Dynamic One
            ObjectRotation.click(&MousePt);								// Update Start Vector And Prepare For Dragging
        }
    }
    else
    {
        if (mouseIsPressed)												// Still Clicked, So Still Dragging
        {
            Quat4fT     ThisQuat;

            ObjectRotation.drag(&MousePt, &ThisQuat);						// Update End Vector And Get Rotation As Quaternion
            Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);		// Convert Quaternion Into Matrix3fT
            Matrix3fMulMatrix3f(&ThisRot, &LastRot);				// Accumulate Last Rotation Into This One
            Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);	// Set Our Final Transform's Rotation From This One
        }
        else														// No Longer Dragging
            mouseIsDragging = false;
    }
}
Esempio n. 2
0
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{	
	if (isRClicked)													// If Right Mouse Clicked, Reset All Rotations
			{
				Matrix3fSetIdentity(&LastRot);								// Reset Rotation
				Matrix3fSetIdentity(&ThisRot);								// Reset Rotation
				Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);		// Reset Rotation
			}

			if (!isDragging)												// Not Dragging
			{
				if (isClicked)												// First Click
				{
					isDragging = true;										// Prepare For Dragging
					LastRot = ThisRot;										// Set Last Static Rotation To Last Dynamic One
					ArcBall.click(&MousePt);								// Update Start Vector And Prepare For Dragging
				}
			}
			else
			{
				if (isClicked)												// Still Clicked, So Still Dragging
				{
					Quat4fT     ThisQuat;

					ArcBall.drag(&MousePt, &ThisQuat);						// Update End Vector And Get Rotation As Quaternion
					Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);		// Convert Quaternion Into Matrix3fT
					Matrix3fMulMatrix3f(&ThisRot, &LastRot);				// Accumulate Last Rotation Into This One
					Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);	// Set Our Final Transform's Rotation From This One
				}
				else														// No Longer Dragging
					isDragging = false;
			}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	glTranslatef(0, 0, -1.0f);
	glPushMatrix();													// NEW: Prepare Dynamic Transform
	glMultMatrixf(Transform.M);	
	glCallList(dl);
	glPopMatrix();
	glLoadIdentity();									// Reset The Current Modelview Matrix
	return TRUE;										// Everything Went OK
}
Esempio n. 3
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
	MousePt.s.X = event->x();
	MousePt.s.Y = event->y();

	Quat4fT ThisQuat;
	arc_ball->drag(&MousePt, &ThisQuat);
	Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);
	Matrix3fMulMatrix3f(&ThisRot, &LastRot);
	Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);

    updateGL();
}
Esempio n. 4
0
float* ArcBall_update(int x,int y,int down) {
    Quat4fT q;
    MousePt.s.X = x;
    MousePt.s.Y = y;
    if (!down) {
        isDragging = 0;
    }
    else if(!isDragging) {
        isDragging = 1;
        LastRot = ThisRot;
        ArcBall_click(&MousePt);
    }
    else {
        ArcBall_drag(&MousePt,&q);
        Matrix3fSetRotationFromQuat4f(&ThisRot, &q);
        Matrix3fMulMatrix3f(&ThisRot, &LastRot);
        Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);
    }
    return (float*)&Transform;
}
afx_msg void CLineComputeView::OnMouseMove(UINT nFlags, CPoint point)
{
    if (isDragging)
    {
        if((nFlags & MK_RBUTTON) == MK_RBUTTON)//右键旋转
        {
            Quat4fT     ThisQuat;
            Point2fT    MousePt;
            MousePt.s.X = point.x;
            MousePt.s.Y = point.y;
            arcBall->drag(&MousePt, &ThisQuat);
            Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);
            Matrix3fMulMatrix3f(&ThisRot, &LastRot);
            Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);
        }
        else if((nFlags & MK_LBUTTON) == MK_LBUTTON)//左键移动
        {
            nextPoint.SetPoint(point.x, point.y);
            if((prePoint.x != -1) && (prePoint.y != -1) && (nextPoint.x != -1) && (nextPoint.y != -1))
            {
                float deltaX = -(nextPoint.x-prePoint.x)/500.0f;
                float deltaY = (nextPoint.y-prePoint.y)/500.0f;
                zoomLeft += deltaX;
                zoomRight += deltaX;
                zoomTop += deltaY;
                zoomBottom += deltaY;
                glViewport(0, 0, screenWidth, screenHeight);
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();
                glOrtho(zoomLeft, zoomRight, zoomBottom, zoomTop, zNear, zFar);
                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();
            }
            prePoint.SetPoint(nextPoint.x, nextPoint.y);
        }
        RenderScene();
    }
    return ;
}
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    //go and get the contents
    ImportREFile();

    //start the windows loop

    MSG msg;                // Windows message structure
	bool done = false;      // bool variable to exit loop
    fullscreen = false;       // Windowed mode


	// Create our OpenGL window
	if (!CreateGLWindow("Roadworks Estimator OpenGL Renderer",1024,768,16,fullscreen))
	{
		return 0;               // Quit if window was not created
	}

	while(!done)                    // Loop that runs while done = false
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is there a message waiting?
		{
			if (msg.message == WM_QUIT)             // Have we received a quit message?
			{
				done = true;                    // If so done = true
			}
			else                                    // If not, deal with window messages
			{
				TranslateMessage(&msg);         // Translate the message
				DispatchMessage(&msg);          // Dispatch the message
			}
		}
		else            // If there are no messages
		{
			// Draw the scene.  Watch for ESC key and quit messages from DrawGLScene()
			if (active)                             // Program active?
			{
                if (keys['W'] )
                {
                    translatez+=0.01f;
                }

                 if (keys['S'] )
                {
                    translatez-=0.01f;
                }

                 if (keys['A'] )
                {
                    rotatey+=0.01f;
                }

                 if (keys['D'] )
                {
                    rotatey-=0.01f;
                }

                if (keys[VK_UP] )
                {
                    rotatex+=0.025f;
                }

                if (keys[VK_DOWN] )
                {
                    rotatex-=0.025f;
                }

                if (keys[VK_LEFT] )
                {
                    rotatez+=0.1f;
                }

                if (keys[VK_RIGHT] )
                {
                    rotatez-=0.1f;
                }

                if (keys[VK_F1] )
                {
                    wireframemode=!wireframemode;
                    if(wireframemode)
                    {
                       WireframeMode();
                       Sleep(100);
                    }
                    else
                    {
                        TextureMode();
                        Sleep(100);


                    }
                }

				if (keys[VK_ESCAPE])            // Was ESC pressed?
				{
					done = true;            // ESC signalled a quit
				}
				                           // Not time to quit, Update screen


                if (isRClicked)													// If Right Mouse Clicked, Reset All Rotations
                {
		            Matrix3fSetIdentity(&LastRot);								// Reset Rotation
                    Matrix3fSetIdentity(&ThisRot);								// Reset Rotation
                    Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);		// Reset Rotation
                }

                if (!isDragging)												// Not Dragging
                {
                    if (isClicked)												// First Click
                    {
			            isDragging = true;										// Prepare For Dragging
			            LastRot = ThisRot;										// Set Last Static Rotation To Last Dynamic One
			            ArcBall.click(&MousePt);								// Update Start Vector And Prepare For Dragging
                    }
                }


                if (isClicked)												// Still Clicked, So Still Dragging
                {
                    Quat4fT     ThisQuat;

                    ArcBall.drag(&MousePt, &ThisQuat);						// Update End Vector And Get Rotation As Quaternion
                    Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);		// Convert Quaternion Into Matrix3fT
                    Matrix3fMulMatrix3f(&ThisRot, &LastRot);				// Accumulate Last Rotation Into This One
                    Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);	// Set Our Final Transform's Rotation From This One
                }
                else														// No Longer Dragging
                    isDragging = false;


                DrawGLScene();          // Draw the scene
                SwapBuffers(hDC);       // Swap buffers (Double buffering)
            }
        }

    }

	// Shutdown
	KillGLWindow();         // Kill the window
	return (msg.wParam);    // Exit the program
}
int ModelViewController::handle(int event)
{
	Vector2f    Clickpoint;												// NEW: Current Mouse Point
	static float Click_y;
	static float old_zoom;

	Clickpoint.x =  (GLfloat)Fl::event_x();;
	Clickpoint.y =  (GLfloat)Fl::event_y();;

	switch(event) {
		case FL_PUSH:	//mouse down event position in Fl::event_x() and Fl::event_y()
			{
				switch(Fl::event_button())	{
				case FL_LEFT_MOUSE:
					MousePt.T[0] = (GLfloat)Clickpoint.x;
					MousePt.T[1] = (GLfloat)Clickpoint.y;
					ArcBall->click(&MousePt);								// Update Start Vector And Prepare For Dragging
					break;
				case FL_MIDDLE_MOUSE:
					downPoint = Clickpoint;
					/*
					Matrix3fSetIdentity(&LastRot);								// Reset Rotation
					Matrix3fSetIdentity(&ThisRot);								// Reset Rotation
					Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);		// Reset Rotation
					*/
					break;
				case FL_RIGHT_MOUSE:
					Click_y = Clickpoint.y;
					old_zoom = zoom;
					break;
				}
				LastRot = ThisRot;										// Set Last Static Rotation To Last Dynamic One
				redraw();
				return 1;
			}
		case FL_DRAG:	//mouse moved while down event ...
			switch(Fl::event_button())
				{
				case FL_LEFT_MOUSE:
					Quat4fT     ThisQuat;

					MousePt.T[0] = Clickpoint.x;
					MousePt.T[1] = Clickpoint.y;

					ArcBall->drag(&MousePt, &ThisQuat);						// Update End Vector And Get Rotation As Quaternion
					Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);		// Convert Quaternion Into Matrix3fT
					Matrix3fMulMatrix3f(&ThisRot, &LastRot);				// Accumulate Last Rotation Into This One
					Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);	// Set Our Final Transform's Rotation From This One
					redraw();
					break;
				case FL_MIDDLE_MOUSE:
					{
					Vector2f    dragp = Clickpoint;
					Vector2f delta = downPoint-dragp;
					Matrix4f matrix;
					memcpy(&matrix.m00, &Transform.M[0], sizeof(Matrix4f));
					Vector3f X(delta.x,0,0);
					X = matrix * X;
					Vector3f Y(0,-delta.y,0);
					Y = matrix * Y;
					ProcessControl.Center += X*delta.length()*0.01f;
					ProcessControl.Center += Y*delta.length()*0.01f;
					redraw();
					downPoint=Clickpoint;
					}

					break;
				case FL_RIGHT_MOUSE:
					float y = 	Click_y - Clickpoint.y;
					zoom = old_zoom + y*0.1;
					redraw();
					break;
				}
			return 1;
		case FL_RELEASE: //mouse up event ...
			MousePt.T[0] = (GLfloat)Fl::event_x();
			MousePt.T[1] = (GLfloat)Fl::event_y();
			redraw();
			return 1;
		case FL_MOUSEWHEEL: { //mouse scroll event
			int mwscrolled = Fl::event_dy();
			zoom += mwscrolled*1;
			redraw();
			return 1;
			}
		case FL_FOCUS :
		case FL_UNFOCUS : // Return 1 if you want keyboard events, 0 otherwise
			return 0;
		case FL_KEYBOARD: //keypress, key is in Fl::event_key(), ascii in Fl::event_text() .. Return 1 if you understand/use the keyboard event, 0 otherwise...
			return 1;
		case FL_SHORTCUT: // shortcut, key is in Fl::event_key(), ascii in Fl::event_text() ... Return 1 if you understand/use the shortcut event, 0 otherwise...
			return 1;
		case FL_CLOSE:
			if (fl_choice("Save settings ?", "Exit", "Save then exit", NULL))
			{
//				int a=0;
//				ProcessControl.SaveXML();
			}
			break;
		default:
			break;
	}
	// pass other events to the base class...
	return Fl_Gl_Window::handle(event);
}
Esempio n. 8
0
void Update (long milliseconds) {									// Perform Motion Updates Here
	if(isClicked) {
		if(newClick) {
			if(!state) {
				mySelect(MousePt.s.X, MousePt.s.Y,(int)wwidth, (int)wheight);
				if(recycleClicked) {
					recycleState=true;
					recyclingMode=recyclingMode?false:true;
					newClick = false;
				} else if(recyclingMode) {
	//				mySelect(MousePt.s.X, MousePt.s.Y,(int)wwidth, (int)wheight);
					newClick = false;
				}
				else if(newClick && gotNewPosition) {
					bridge->click3(mpx,mpy,((float)thickness)/100.0f);
					newClick = false;
				}
			} else {
					Matrix3fSetIdentity(&LastRot);								// Reset Rotation
					Matrix3fSetIdentity(&ThisRot);								// Reset Rotation
					Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);		// Reset Rotation
					ArcBall.clickL(&MousePt);
					newClick = false;
			
			//		mySelect(MousePt.s.X, MousePt.s.Y, (int)wwidth, (int)wheight);
						state = 0;
					//	printf("was here asdf\n");
						for(int i=bridge->nnodes; i--;) {
							bridge->nodes[i].reset();
						}
			}
		}
	} else {
		newClick = true;
		gotNewPosition = false;
		recycleClicked = false;
		recycleState = false;
	}

	if(bridge->tfrom) {
		mySelect(MousePt.s.X, MousePt.s.Y, (int) wwidth, (int)wheight);
		if((bridge->tfrom->p.x != (mpx-24.0f) || bridge->tfrom->p.y != (mpy-13.0f))) {
			if(5>(sqrt(pow(bridge->tfrom->p.x-(mpx-24.0f),2)+pow(bridge->tfrom->p.y-(mpy-13.0f),2)))) {		// restricting to nodes which aren't itself ( edgelenth=0 ) and limiting the maximal size of edges
				if(bridge->tto == 0)	// tto = temporary to
					bridge->tto = new Node();
				bridge->tto->set((float)mpx-24.0f, (float)mpy-13.0f);
				if(bridge->tEdge == 0) {
					bridge->tEdge = new Edge();	// tEdge = temporary Edge
					bridge->tEdge->set(((float)thickness)/100.0f,bridge->tfrom,bridge->tto);
				}
			} else {
				if(bridge->tto == 0)	// tto = temporary to
					bridge->tto = new Node();
//				std::cout<<"tfrom x="<<bridge->tfrom->p.x<<"  tfrom y="<<bridge->tfrom->p.y<<"  mpx-24.0f="<<(float)mpx-24.0f<<"   mpy-13.0f="<<mpy-13.0f<<std::endl;
				float vlength = 5/sqrt(pow(((float)mpx-24.0f)-bridge->tfrom->p.x,2.0)+pow(((float)mpy-13.0f)-bridge->tfrom->p.y,2.0));
				bridge->tto->set(bridge->tfrom->p.x+round((((float)mpx-24.0f)-bridge->tfrom->p.x)*vlength), bridge->tfrom->p.y+round((((float)mpy-13.0f)-bridge->tfrom->p.y)*vlength));
				if(bridge->tEdge == 0) {
					bridge->tEdge = new Edge();	// tEdge = temporary Edge
					bridge->tEdge->set(((float)thickness)/100.0f,bridge->tfrom,bridge->tto);
				}
			}
		}
//		else
//			std::cout<<"\n was here"<<std::endl;
	}

    if (!isDragging) {												// Not Dragging
        if (isRClicked) {												// First Click
			recyclingMode = false;
			bridge->stopClicking();
			state=1;
			isDragging = true;										// Prepare For Dragging
			LastRot = ThisRot;										// Set Last Static Rotation To Last Dynamic One
			ArcBall.click(&MousePt);								// Update Start Vector And Prepare For Dragging
        }
    }
    else {
        if (isRClicked) {												// Still Clicked, So Still Dragging
            Quat4fT     ThisQuat;

            ArcBall.drag(&MousePt, &ThisQuat);						// Update End Vector And Get Rotation As Quaternion
            Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);		// Convert Quaternion Into Matrix3fT
            Matrix3fMulMatrix3f(&ThisRot, &LastRot);				// Accumulate Last Rotation Into This One
            Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);	// Set Our Final Transform's Rotation From This One
        }
        else														// No Longer Dragging
            isDragging = false;
    }
}