Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actual___

Posted 10 October 2012 - 07:46 AM

the func void T3DPlanet::GetOGLPos(int x, int y, t3dpoint & np, t3dpoint & fp)
void gluPerspectiveA(GLfloat fovy, GLfloat aspect, GLfloat zmin, GLfloat zmax)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zmin * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
}


provides the correct X and Y values for mouse cursor,

The idea of my soulition is: (i will explain the code now)
the idea is as follows:
set z near and z far closely
gluPerspectiveA(90.0f, DISPLAY_WIDTH/DISPLAY_HEIGHT,1000.0f, 2000.0f);
set the camera

then check nearest depth val and the farthest, then make from them a line and test whatever you want

gluUnProject(winX, winY, 0, modelview, projection, viewport, &nx, &ny, &nz); //the point on your screeen! (depth value 0,0f)
gluUnProject(winX, winY, 1, modelview, projection, viewport, &fx, &fy, &fz); //pushed far away point (depth value 1.0f)

Maybye you are not familiar with the dpeth values they are from 0 to 1 (depending on znear/zfar value 0.75 from depth vcan be farther than 0.75 from diffferent znear/zfar perspective ble ble ble ble )

void T3DPlanet::GetOGLPos(int x, int y[..])
{
[...]
glGetIntegerv( GL_VIEWPORT, viewport );
  float winX = float(x);
   float winY = float(viewport[3]) - float(y);

//optional readpixels

//optional one gluunproject(winx,winy, readpixeldepth, modelview, projection, viewport, outputx,outputy,outputz);







if you do not want to make rays and then test some shit you use)
if you use glReadPixels() with the same x,y values (winX, winY) range 1 GL_DEPTH_COMPONENT (or GL_DEPTH_COMPONENT24)

after reading the depth value from the pixel you
call glunproject
heres is a pixel reading
void __fastcall READ_RGBA_FROM_OGL_WINDOW(int x,int height, int y, int & r, int & g, int & b, int & a)
{


unsigned char* pdata = new unsigned char[4];
glReadBuffer(GL_COLOR_BUFFER_BIT);

glReadPixels(x,height-y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pdata);

r = pdata[0];
g = pdata[1];
b = pdata[2];
a = pdata[3];
// delete B2;
delete [] pdata;
}

//so for depth is should be but i dont know if that is correct

float __fastcall READ_DEPTH_FROM_OGL_WINDOW(int x,int height, int y)
{

unsigned char* pdata = new unsigned char[1];
glReadBuffer(GL_DEPTH_BUFFER_BIT);
glReadPixels(x,height-y,1,1,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,pdata);

return float(pdata[0]) / 255.0f;

}


I have tried everything but not getting the exact X and Y values. - no you didin't
I am applying glPerspective() in real-time (display function) thats why
- I don;t understand, you display the scene and you store for it a modelview matrix, projection matrix , and viewport
so you can call fcking gluUnProject

and do not use so big ratio between z_near/z_far


I think I have to apply it with a specific matrix but i dont know which matrix. - ah HELL NO !!!

I do not want to select vertex or something like that I just need 3D coordinates at the click position.


So WHA THE HELL ARE YOU WAITING FOR?
CLEAN YOUR CODE


and do as follows


draw the scene

store modelview matrix and stroe viewport also
(when want to click)
change perspective to 'nicest z_near/z_far aspect ratio)
store projection matrix
call gluUnProject and get the values

be happy ;(


I still have no idea what are you doing wrong dude

#4___

Posted 10 October 2012 - 07:44 AM

the func void T3DPlanet::GetOGLPos(int x, int y, t3dpoint & np, t3dpoint & fp)
void gluPerspectiveA(GLfloat fovy, GLfloat aspect, GLfloat zmin, GLfloat zmax)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zmin * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
}


provides the correct X and Y values for mouse cursor,

The idea of my soulition is: (i will explain the code now)
the idea is as follows:
set z near and z far closely
gluPerspectiveA(90.0f, DISPLAY_WIDTH/DISPLAY_HEIGHT,1000.0f, 2000.0f);
set the camera

then check nearest depth val and the farthest, then make from them a line and test whatever you want

gluUnProject(winX, winY, 0, modelview, projection, viewport, &nx, &ny, &nz); //the point on your screeen! (depth value 0,0f)
gluUnProject(winX, winY, 1, modelview, projection, viewport, &fx, &fy, &fz); //pushed far away point (depth value 1.0f)

Maybye you are not familiar with the dpeth values they are from 0 to 1 (depending on znear/zfar value 0.75 from depth vcan be farther than 0.75 from diffferent znear/zfar perspective ble ble ble ble )

void T3DPlanet::GetOGLPos(int x, int y[..])
{
[...]
glGetIntegerv( GL_VIEWPORT, viewport );
  float winX = float(x);
   float winY = float(viewport[3]) - float(y);

//optional readpixels

//optional one gluunproject(winx,winy, readpixeldepth, modelview, projection, viewport, outputx,outputy,outputz);







if you do not want to make rays and then test some shit you use)
if you use glReadPixels() with the same x,y values (winX, winY) range 1 GL_DEPTH_COMPONENT (or GL_DEPTH_COMPONENT24)

after reading the depth value from the pixel you
call glunproject
heres is a pixel reading
void __fastcall READ_RGBA_FROM_OGL_WINDOW(int x,int height, int y, int & r, int & g, int & b, int & a)
{


unsigned char* pdata = new unsigned char[4];
glReadBuffer(GL_COLOR_BUFFER_BIT);

glReadPixels(x,height-y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pdata);

r = pdata[0];
g = pdata[1];
b = pdata[2];
a = pdata[3];
// delete B2;
delete [] pdata;
}

//so for depth is should be but i dont know if that is correct

float __fastcall READ_DEPTH_FROM_OGL_WINDOW(int x,int height, int y)
{

unsigned char* pdata = new unsigned char[1];
glReadBuffer(GL_DEPTH_BUFFER_BIT);
glReadPixels(x,height-y,1,1,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,pdata);

return float(pdata[0]) / 255.0f;

}


I have tried everything but not getting the exact X and Y values. - no you didin't
I am applying glPerspective() in real-time (display function) thats why
- I don;t understand, you display the scene and you store for it a modelview matrix, projection matrix , and viewport
so you can call fcking gluUnProject

and do not use so big ratio between z_near/z_far


I think I have to apply it with a specific matrix but i dont know which matrix. - ah HELL NO !!!

I do not want to select vertex or something like that I just need 3D coordinates at the click position.


So WHA THE HELL ARE YOU WAITING FOR?
CLEAN YOUR CODE


and so as follows


draw the scene

store projection and modelview matrix and stroe viewport also
change perspective to 'nicest z_near/z_far aspect ratio)
call gluUnProject and get the values


I still have no idea what are you doing wrong dude

#3___

Posted 10 October 2012 - 07:43 AM

the func void T3DPlanet::GetOGLPos(int x, int y, t3dpoint & np, t3dpoint & fp)
void gluPerspectiveA(GLfloat fovy, GLfloat aspect, GLfloat zmin, GLfloat zmax)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zmin * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
}


provides the correct X and Y values for mouse cursor,

The idea of my soulition is: (i will explain the code now)
the idea is as follows:
set z near and z far closely
gluPerspectiveA(90.0f, DISPLAY_WIDTH/DISPLAY_HEIGHT,1000.0f, 2000.0f);
set the camera

then check nearest depth val and the farthest, then make from them a line and test whatever you want

gluUnProject(winX, winY, 0, modelview, projection, viewport, &nx, &ny, &nz); //the point on your screeen! (depth value 0,0f)
gluUnProject(winX, winY, 1, modelview, projection, viewport, &fx, &fy, &fz); //pushed far away point (depth value 1.0f)

Maybye you are not familiar with the dpeth values they are from 0 to 1 (depending on znear/zfar value 0.75 from depth vcan be farther than 0.75 from diffferent znear/zfar perspective ble ble ble ble )

void T3DPlanet::GetOGLPos(int x, int y[..])
{
[...]
glGetIntegerv( GL_VIEWPORT, viewport );
  float winX = float(x);
   float winY = float(viewport[3]) - float(y);

//optional readpixels

//optional one gluunproject(winx,winy, readpixeldepth, modelview, projection, viewport, outputx,outputy,outputz);







if you do not want to make rays and then test some shit you use)
if you use glReadPixels() with the same x,y values (winX, winY) range 1 GL_DEPTH_COMPONENT (or GL_DEPTH_COMPONENT24)

after reading the depth value from the pixel you
call glunproject
heres is a pixel reading
void __fastcall READ_RGBA_FROM_OGL_WINDOW(int x,int height, int y, int & r, int & g, int & b, int & a)
{


unsigned char* pdata = new unsigned char[4];
glReadBuffer(GL_COLOR_BUFFER_BIT);

glReadPixels(x,height-y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pdata);

r = pdata[0];
g = pdata[1];
b = pdata[2];
a = pdata[3];
// delete B2;
delete [] pdata;
}

//so for depth is should be but i dont know if that is correct

float __fastcall READ_DEPTH_FROM_OGL_WINDOW(int x,int height, int y)
{

unsigned char* pdata = new unsigned char[1];
glReadBuffer(GL_DEPTH_BUFFER_BIT);
glReadPixels(x,height-y,1,1,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,pdata);

return float(pdata[0]) / 255.0f;

}


I have tried everything but not getting the exact X and Y values. - no you didin't
I am applying glPerspective() in real-time (display function) thats why
- I don;t understand, you display the scene and you store for it a modelview matrix, projection matrix , and viewport
so you can call fcking gluUnProject

and do not use so big ratio between z_near/z_far


I think I have to apply it with a specific matrix but i dont know which matrix. - ah HELL NO !!!

I do not want to select vertex or something like that I just need 3D coordinates at the click position.


So WHA THE HELL ARE YOU WAITING FOR?
CLEAN YOUR CODE


and so as follows


draw the scene

store projection and modelview matrix and stroe viewport also
change perspective to 'nicest z_near/z_far aspect ratio)
call gluUnProject and get the values

#2___

Posted 10 October 2012 - 07:38 AM

the func void T3DPlanet::GetOGLPos(int x, int y, t3dpoint & np, t3dpoint & fp)
void gluPerspectiveA(GLfloat fovy, GLfloat aspect, GLfloat zmin, GLfloat zmax)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zmin * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zmin, zmax);
}


provides the correct X and Y values for mouse cursor,

The idea of my soulition is: (i will explain the code now)
the idea is as follows:
set z near and z far closely
gluPerspectiveA(90.0f, DISPLAY_WIDTH/DISPLAY_HEIGHT,1000.0f, 2000.0f);
set the camera

then check nearest depth val and the farthest, then make from them a line and test whatever you want

gluUnProject(winX, winY, 0, modelview, projection, viewport, &nx, &ny, &nz);
gluUnProject(winX, winY, 1, modelview, projection, viewport, &fx, &fy, &fz);

void T3DPlanet::GetOGLPos(int x, int y[..])
{
[...]
glGetIntegerv( GL_VIEWPORT, viewport );
  float winX = float(x);
   float winY = float(viewport[3]) - float(y);

//optional readpixels

//optional one gluunproject(winx,winy, readpixeldepth, modelview, projection, viewport, outputx,outputy,outputz);







if you do not want to make rays and then test some shit you use)
if you use glReadPixels() with the same x,y values (winX, winY) range 1 GL_DEPTH_COMPONENT (or GL_DEPTH_COMPONENT24)

after reading the depth value from the pixel you
call glunproject
heres is a pixel reading
void __fastcall READ_RGBA_FROM_OGL_WINDOW(int x,int height, int y, int & r, int & g, int & b, int & a)
{


unsigned char* pdata = new unsigned char[4];
glReadBuffer(GL_COLOR_BUFFER_BIT);

glReadPixels(x,height-y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pdata);

r = pdata[0];
g = pdata[1];
b = pdata[2];
a = pdata[3];
// delete B2;
delete [] pdata;
}

//so for depth is should be but i dont know if that is correct

float __fastcall READ_DEPTH_FROM_OGL_WINDOW(int x,int height, int y)
{

unsigned char* pdata = new unsigned char[1];
glReadBuffer(GL_DEPTH_BUFFER_BIT);
glReadPixels(x,height-y,1,1,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,pdata);

return float(pdata[0]) / 255.0f;

}


I have tried everything but not getting the exact X and Y values. - no you didin't
I am applying glPerspective() in real-time (display function) thats why
- I don;t understand, you display the scene and you store for it a modelview matrix, projection matrix , and viewport
so you can call fcking gluUnProject

and do not use so big ratio between z_near/z_far


I think I have to apply it with a specific matrix but i dont know which matrix. - ah HELL NO !!!

I do not want to select vertex or something like that I just need 3D coordinates at the click position.

#1___

Posted 10 October 2012 - 07:37 AM

the func void T3DPlanet::GetOGLPos(int x, int y, t3dpoint & np, t3dpoint & fp)

provides the correct X and Y values for mouse cursor,

The idea of my soulition is: (i will explain the code now)
the idea is as follows:
set z near and z far closely
gluPerspectiveA(90.0f, DISPLAY_WIDTH/DISPLAY_HEIGHT,1000.0f, 2000.0f);
set the camera

then check nearest depth val and the farthest, then make from them a line and test whatever you want

gluUnProject(winX, winY, 0, modelview, projection, viewport, &nx, &ny, &nz);
gluUnProject(winX, winY, 1, modelview, projection, viewport, &fx, &fy, &fz);

void T3DPlanet::GetOGLPos(int x, int y[..])
{
[...]
glGetIntegerv( GL_VIEWPORT, viewport );
  float winX = float(x);
   float winY = float(viewport[3]) - float(y);

//optional readpixels

//optional one gluunproject(winx,winy, readpixeldepth, modelview, projection, viewport, outputx,outputy,outputz);



but yes you want to click on the point first of all points have in default 1 pixel width so better change the thickness.
if you do not want to make rays and then test some shit you use)
if you use glReadPixels() with the same x,y values (winX, winY) range 1 GL_DEPTH_COMPONENT (or GL_DEPTH_COMPONENT24)

after reading the depth value from the pixel you
call glunproject
heres is a pixel reading
void __fastcall READ_RGBA_FROM_OGL_WINDOW(int x,int height, int y, int & r, int & g, int & b, int & a)
{


unsigned char* pdata = new unsigned char[4];
glReadBuffer(GL_COLOR_BUFFER_BIT);

glReadPixels(x,height-y,1,1,GL_RGBA,GL_UNSIGNED_BYTE,pdata);

r = pdata[0];
g = pdata[1];
b = pdata[2];
a = pdata[3];
// delete B2;
delete [] pdata;
}

//so for depth is should be but i dont know if that is correct

float __fastcall READ_DEPTH_FROM_OGL_WINDOW(int x,int height, int y)
{

unsigned char* pdata = new unsigned char[1];
glReadBuffer(GL_DEPTH_BUFFER_BIT);
glReadPixels(x,height-y,1,1,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,pdata);

return float(pdata[0]) / 255.0f;
 
}


I have tried everything but not getting the exact X and Y values. - no you didin't
I am applying glPerspective() in real-time (display function) thats why
- I don;t understand, you display the scene and you store for it a modelview matrix, projection matrix , and viewport
so you can call fcking gluUnProject

and do not use so big ratio between z_near/z_far


I think I have to apply it with a specific matrix but i dont know which matrix. - ah HELL NO !!!

I do not want to select vertex or something like that I just need 3D coordinates at the click position.

PARTNERS