-
how to get the 4 corners object coordinates of my screen
#include <stdio.h>
#ifdef __cplusplus
extern "C"
#endif
FILE _iob[3] = {__iob_func()[0], __iob_func()[1], __iob_func()[2]};
#include "shared/gltools.h" // OpenGL toolkit
#include <math.h>
#include "shared\math3d.h"
#include "GL\GL.H"
#include <fstream>
#include <sstream>
GLdouble aspect ;
GLdouble d_yfov_tan ;
GLdouble d_viewDistance ;
GLdouble midx ;
GLdouble midy ;
std::fstream fs;
void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
gluLookAt(1600.f/2.f, 900.f/2, -d_viewDistance, 1600.f/2.f, 900.f/2.f,1, 0, -1, 0);
glTranslated(755.067810058594,247.161117553711,665 .0654296875);
GLdouble d_matrix[16],d_proj[16];
glGetDoublev(GL_MODELVIEW_MATRIX, d_matrix);
glGetDoublev(GL_PROJECTION_MATRIX,d_proj);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
GLdouble obj1[3] = {0.f,0.f,0.f};
GLdouble winY = (GLdouble)viewport[3] - 0.f;
if(gluUnProject(0, winY, 0,
d_matrix,
d_proj,
viewport,
obj1, obj1+1, obj1+2) == GL_FALSE) {}
winY = (GLdouble)viewport[3] - 900.f;
GLdouble obj2[3] = {0.f,0.f,0.f};
if(gluUnProject(0, winY, 0,
d_matrix,
d_proj,
viewport,
obj2, obj2+1, obj2+2) == GL_FALSE) {}
winY = (GLdouble)viewport[3] - 900.f;
GLdouble obj3[3] = {0.f,0.f,0.f};
if(gluUnProject(1600, winY, 0,
d_matrix,
d_proj,
viewport,
obj3, obj3+1, obj3+2) == GL_FALSE) {}
GLdouble v1[3] = {399.01f,397.958f,10.f};
GLdouble v2[3] = {-1067.64f,819.34f,10.f};
GLdouble v3[3] = {-225.503f,360.178,10.f};
GLdouble winObj[3];
gluProject(v2[0],v2[1],v2[2],d_matrix,d_proj,viewport,winObj,winObj+1,winObj+2 );
std::stringstream ss;
ss<<winObj[0]<<","<<winObj[1]<<","<<winObj[1]<<std::endl;
fs.write(ss.str().data(),ss.str().size());
glPointSize(5.f);
glColor3d(0.f,1.f,0.f);
glBegin(GL_POINTS);
//glVertex3dv(v1);
glVertex3dv(v2);
//glVertex3dv(v3);
glEnd();
glColor3d(0.f,0.f,1.f);
glBegin(GL_POINTS);
glVertex3dv(obj1);
glVertex3dv(obj2);
glVertex3dv(obj3);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void Keyboard (unsigned char key, int x, int y)
{
if (key==27)
{
glutLeaveGameMode(); //set the resolution how it was
fs.close();
exit(0); //quit the program
}
}
void ChangeSize(int w, int h)
{
GLfloat fAspect;
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
glViewport(0, 0, w, h);
fAspect = (GLfloat)w / (GLfloat)h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the clipping volume
gluPerspective(30.0, aspect, d_viewDistance * 0.5, d_viewDistance * 2.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void SetupRC()
{
glDisable (GL_DEPTH_TEST); //enable the depth testing
glDisable (GL_LIGHTING); //enable the lighting
glShadeModel (GL_SMOOTH); //set the shader to smooth shader
glClearColor(0,0,0,0);
aspect = 1600.f/900.f;
d_yfov_tan = 0.267949192431123;
d_viewDistance = 1600/2.0f/ (aspect * d_yfov_tan);
midx = 1600.f * 0.5;
midy = 900.f * 0.5;
fs.open("f:/test.txt",
std::fstream:
ut | std::fstream::binary);
}
int main(int argc, char **argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE); //set the display to Double buffer, with depth
glutGameModeString("1600x900:32@60"); //the settinswerrgsfor fullscreen mode
glutEnterGameMode(); //set glut to fullscreen using the settings in the line above
SetupRC (); //call the init function
glutDisplayFunc (RenderScene); //use the display function to draw everything
//glutIdleFunc (RenderScene); //update any variables in display,display can be changed to anyhing, as long as you move the variables to be updated, in this case, angle++;
glutReshapeFunc (ChangeSize); //reshape the window accordingly
glutKeyboardFunc (Keyboard); //check the keyboard
glutMainLoop (); //call the main loop
return 0;
}
Above is my code,but i can't get these object coordinates,thank u
-
Advanced Member
Frequent Contributor
Will you please, please, obey forum rules and start putting your code into '['code']' '['/code']' tags?
Do you even read your other threads before starting new ones? Reading code like this is very tedious and if you want people's help you'll have to play by the rules.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules