void CLineComputeView::InitViewParams(int type=0)
{
    arcBall = new ArcBallT(1000.0f, 600.0f);
    scale = 1.0;
    zoomLeft = -0.5f;
    zoomRight = 4.0f;
    zoomTop = 1.0f;
    zoomBottom = -1.0f;
    zNear = -10.0f;
    zFar = 10.0f;
    switch (type)
    {
    case 0:
    default://初始视图
        xRot = 26.0f;
        yRot = 36.0f;
        zRot = 15.0f;
        break;
    case 1: //侧向视图
        xRot = 0.0f;
        yRot = 0.0f;
        zRot = 0.0f;
        break;
    }
    //鼠标旋转初始化参数
    Matrix3fSetIdentity(&LastRot);
    Matrix3fSetIdentity(&ThisRot);
    Matrix4fSetIdentity(&Transform);
    return ;
}
Example #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
}
Example #3
0
Render::Render (View *view, Glib::RefPtr<Gtk::TreeSelection> selection) :
  m_arcBall(new ArcBall()), m_view (view), m_selection(selection)
{
  set_events (Gdk::POINTER_MOTION_MASK |
	      Gdk::BUTTON_MOTION_MASK |
	      Gdk::BUTTON_PRESS_MASK |
	      Gdk::BUTTON_RELEASE_MASK |
	      Gdk::BUTTON1_MOTION_MASK |
	      Gdk::BUTTON2_MOTION_MASK |
	      Gdk::BUTTON3_MOTION_MASK);

  GdkGLConfig *glconfig;

  // glconfig is leaked at program exit
  glconfig = gdk_gl_config_new_by_mode
		    ((GdkGLConfigMode) (GDK_GL_MODE_RGBA |
					GDK_GL_MODE_ALPHA |
					GDK_GL_MODE_STENCIL |
					GDK_GL_MODE_DEPTH |
					GDK_GL_MODE_DOUBLE));
  if (!glconfig) // try single buffered
    glconfig = gdk_gl_config_new_by_mode
		      ((GdkGLConfigMode) (GDK_GL_MODE_RGBA |
					  GDK_GL_MODE_ALPHA |
					  GDK_GL_MODE_STENCIL |
					  GDK_GL_MODE_DEPTH));
  if (!gtk_widget_set_gl_capability (get_widget(), glconfig,
				     NULL, TRUE, GDK_GL_RGBA_TYPE))
    g_error (_("failed to init gl area\n"));

  memset (&m_transform.M, 0, sizeof (m_transform.M));

  Matrix3fT identity;
  Matrix3fSetIdentity(&identity);

  // set initial rotation 30 degrees around Y axis
  identity.s.M11 = identity.s.M22 = 0.5253; // cos -45
  identity.s.M12 = 0.851; // -sin -45
  identity.s.M21 = -0.851; // sin -45

  Matrix4fSetRotationScaleFromMatrix3f(&m_transform, &identity);
  m_transform.s.SW = 1.0;

  m_zoom = 120.0;
  for (uint i = 0; i < N_LIGHTS; i++)
    m_lights[i] = NULL;

  m_selection->signal_changed().connect (sigc::mem_fun(*this, &Render::selection_changed));
}
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
}
Example #5
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;
    }
}