![]() ![]() If( distanceSqrd < maxAcceptableDistanceSqr ) const double maxAcceptableDistanceSqr = 1e-5 // You need to change this to your likingĭouble distanceSqrd = (pontos.vX - x)^2 + (pontos.vY - y)^2 This has the advantage of using distances, which is more intuitive because you can determine which distance doesn't make the user frustrated with selecting the point, if you need him to exactly match the point, he will be frustrated. If( fabs(pontos.vX - x) < err & fabs(pontos.vY - y) < err )īetter yet, you can calculate the distance squared to the point instead, and check if it's within an acceptable distance. You need to introduce an error margin like this const double err = 1e-15 Well, I can see few problems in your approach, but I will assume both points are in the same coordinate system (world space).Ĭomparing doubles and floats using "=" is a bad idea. I have this function to calculate the coordinates from the mouse input to world coordinates: void converterCoords(GLfloat winX, GLfloat winY) Right now, let's say I defined a GL_POINT with the glVertex2f(20.0f, 0.0f). ![]() Probably because of the mouse coordinates being off.I'm programming a simple graph game and so far I'm still doing a few tests in OpenGL. The line just stays in the same The problem is that when i move my mouse it does not act as an end point, it just fly's off the screen. each coordinate in opengl actually has four components, x, y, z, and w by default, the following are enabled: dragging the map and zooming the map by multitouch or double-click on touch screen devices dragging the map with the mouse, double-click zooming and right-click area selection on all other devices find the gps coordinates of any address. ReleaseDC( hWnd, hDC I assume screen_width and screen_height are 1280/1040? Also I attempted to put in your code, and it doesn't work for me. Disable OpenGL void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) create and enable the render context (RC) The dimension of the canvas is found using the getBoundingClientRect () function. A function is created which takes in the canvas element and event as parameters. Pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER įormat = ChoosePixelFormat( *hDC, &pfd ) The coordinates of the mouse whenever a click takes place can be found by detecting the click event with an event listener and finding the event’s x and y position. Enable OpenGL void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC) Return DefWindowProc( hWnd, message, wParam, lParam ) This is where coords should change to openGL coords LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) handle or dispatch messages if ( msg.message = WM_QUIT ) The motion callback for a window is called. ![]() check for messages if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) The x and y callback parameters indicate the window relative coordinates when the mouse button state changed. WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ) //wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1) Wc.hCursor = LoadCursor( NULL, IDC_ARROW ) Wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ) WinMain int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, global variables int xPos,yPos,xPosg,yPosg Void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) Void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC) #include #include #include // Function Declarations ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |