  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Project 3D point to 2D screen coordinate  » python » Project 3D point to 2D screen coordinate

By : user2953787
Date : November 21 2020, 01:01 AM
I hope this helps . I'm trying to project a few 3d points to screen coordinates to determine whether a touch occurs in roughly the same area. It should be noted that I'm doing this in Kivy, which is Python and OpenGL. I've seen questions like this, but I still don't have a solution. I've tried the following, but the numbers are not close to screen co-ordinates. , The first problem is here: code :
``````p = modelview*[pos, pos, pos, 0])
``````
``````c = p
a /= c
b /= c
``````
``````v4.x = v3.x
v4.y = v3.y
v4.z = v3.z
v4.w = 1.0
``````
``````v4.x /= v4.w
v4.y /= v4.w
v4.z /= v4.w
`````` ## Projecting a 3D point to a 2D screen coordinate

By : user670003
Date : March 29 2020, 07:55 AM
Does that help Since Windows coordinates are z into the screen (x cross y), I would use something like
code :
``````screenY = viewPort.ActualHeight * (1 - screenY);
``````
``````screenY = screenY * viewPort.ActualHeight;
``````
``````screenX = viewPort.ActualWidth * (screenX + 1.0) / 2.0
screenY = viewPort.ActualHeight * (1.0 - ((screenY + 1.0) / 2.0))
`````` ## Convert a given point from the window’s base coordinate system to the screen coordinate system

By : RiAsta
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The window maintains its own position in global screen space and the compositor knows how to put that window's image at the correct location in screen space. The context itself, however doesn't have a location.
Quartz Compositor knows where the window is positioned on the screen, but Quartz 2D doesn't know anything more than how big the area it is supposed to draw in is. It has no idea where Quartz Compositor is going to put the drawing once it is done. ## How can i draw a black point on the 0,0,-1 opengl coordinate of the screen?

By : user3750693
Date : March 29 2020, 07:55 AM
To fix this issue If you want to be able to draw directly in window space then the easiest thing would be to load modelview and projection temporarily with the identity matrix and draw a GL_POINT with the location that you need. So that'd be something like:
code :
``````glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glMatrixMode(GL_PROJECTION);
glPushMatrix();

// draw the point here; specifics depending on whether you
// favour VBOs, VBAs, etc

// e.g. (assuming you don't have any client state enabled
// on entry and don't care about leaving the vertex array
// enabled on exit)
GLfloat vertexLocation[] = {0.0f, 0.0f, -1.0f};

glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexLocation);

glDrawArrays(GL_POINTS, 0, 1);

// end of example to plot a GL_POINT

glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

// and possibly restore yourself to some other matrix mode
// if, atypically, the rest of your code doesn't assume modelview
`````` ## Convert screen coordinate to UIView local point

By : Reks Stek
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Try this if you want to get screen position from position of subContent.
[subContent convertPoint:subContentLocalPoint fromView:[UIApplication sharedApplication].keyWindow]; ## How to calculate 3D point (World Coordinate) from 2D mouse clicked screen coordinate point in Openscenegraph?

By : ditayb
Date : March 29 2020, 07:55 AM
should help you out Under the assumption that the mouse position is normalized in the range [-1, 1] for x and y, the following code will give you 2 points in world coordinates projected from your mouse coords: nearPoint is the point in 3D lying on the camera frustum near plane, farPointon the frustum far plane.
Than you can compute a line passing by these points and intersecting that with your plane.
code :
``````  // compute the matrix to unproject the mouse coords (in homogeneous space)
osg::Matrix VP = _camera->getViewMatrix() * _camera->getProjectionMatrix();

osg::Matrix inverseVP;
inverseVP.invert(VP);

// compute world near far
osg::Vec3 nearPoint(mousePosition.x, mousePosition.x, -1.0f);
osg::Vec3 farPoint(mousePosition.x, mousePosition.x, 1.0f);
osg::Vec3 nearPointWorld = nearPoint * inverseVP;
osg::Vec3 farPointWorld = farPoint * inverseVP;
`````` 