on4now4
December 10, 2015, 4:04am
#1
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:
ofVec3f myvectortest;
ofVec3f myvectortest2;
myvectortest = camera.worldToScreen(myVecBlack[0]);
myvectortest2.set(mouseX,mouseY,0);
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.
on4now4
December 10, 2015, 4:43pm
#2
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 );
glDepthMask(1);
glDepthFunc( GL_LEQUAL );
*/
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
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[3] - (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
`camera.begin();
Mouse.set(mouseX,mouseY);
ofVec3f testvec;
otherVector = GetOGLPos(myNodeBlack[0].getX(),myNodeBlack[0].getY());
camera.end();
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.