Ejemplo n.º 1
0
void Update (DWORD milliseconds)									// Perform Motion Updates Here
{
	if (g_keys->keyDown ['W'])	
		trans.z += 1.0f;
	
	if (g_keys->keyDown ['S'])	
		trans.z -= 1.0f;

	if (g_keys->keyDown ['A'])	
		trans.x += 1.0f;
	if (g_keys->keyDown ['D'])	
		trans.x -= 1.0f;

	if (g_keys->keyDown ['B'])	{
		splineFunction = &bezier;
		BuildPath();
	}
	if (g_keys->keyDown ['C'])	{
		splineFunction = &catmullrom;
		BuildPath();
	}
	if (g_keys->keyDown [VK_ESCAPE] == TRUE)						// Is ESC Being Pressed?
		TerminateApplication (g_window);							// Terminate The Program

	if (g_keys->keyDown [VK_F1] == TRUE)							// Is F1 Being Pressed?
		ToggleFullscreen (g_window);								// Toggle Fullscreen Mode

    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;
    }
	//rotY+=1.0f;
}
void motion(int x, int y)
{
	MousePt.s.X = x;
	MousePt.s.Y = y;

	if(!isDragging && isClicked){
		isDragging = true;
		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;
	}

	if(buttonState == 4){
		Matrix3fSetIdentity(&LastRot);								// Reset Rotation
		Matrix3fSetIdentity(&ThisRot);								// Reset Rotation
        Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);		// Reset Rotation
	}

	////////////////////////////////////////////
    float dx, dy;
    dx = (float)(x - ox);
    dy = (float)(y - oy);

	if (buttonState == 1) {
		//Copy Transform Rotation to Model Matrix
		for(int i=0; i<4; ++i)
			for(int j=0; j<4; ++j){
				Model[i][j] = Transform.M[i*4+j];
			}
	}
	if (buttonState == 2) {
		// middle = translate
		View = glm::translate(View, glm::vec3(dx * translateSpeed, -dy*translateSpeed, 0.f));
	}
	if (buttonState == 3) {
		// left+middle = zoom
		View = glm::translate(View, glm::vec3(0.f, 0.f, dy*translateSpeed));
	} 

	MVP = Projection * View * Model;
	ox = x; oy = y;
	glutPostRedisplay();
}
Ejemplo n.º 3
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
}
Ejemplo n.º 4
0
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
}