I am trying to create move a circle that was created in 2d coordinate plane and move it with my cursor while viewing from a camera angle. I know this question has been asked a few times but I have still not been able to get anything to work.
The code I am trying to use is this:
myvectortest = camera.worldToScreen(myVecBlack);
test = myvectortest.distance(myvectortest2);`
From what I have found this should work but I’m sure I am missing something because none of the other people seem to take a similar approach.
Currently, I am just trying to measure the distance to the vector defined in the myVecBlack array for verification that things are working.
Although I am still unsure why my original code does not work I have started taking another approach but it also is not working right.
ofVec3f GetOGLPos(int x, int y)
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
winX = (float)x;
winY = (float)viewport - (float)y;
glReadPixels( x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return ofVec3f(posX, posY, posZ);
and then in the update to test it out
otherVector = GetOGLPos(myNodeBlack.getX(),myNodeBlack.getY());
test = ofDist(mouseX,mouseY,otherVector.x,otherVector.y);
I think my issue is that it is not referencing my camera viewing angle but I don’t really know it seems like it should be.