Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: So Jul 20, 2025 21:19

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 11 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: gluUnProject and FreePascal
BeitragVerfasst: Fr Aug 13, 2004 17:51 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
Hi,

I'm using the FreePascal compiler (http://www.freepascal.org/). I have a tile based landscape with objects and now I want to know at wich tile/object the user clicks. First I use gluUnProject to get the 3D coordinates and then, I use a tree to know on wich tile/object the user clicks. But the gluUnProject function has strange output.
This is the code:

Code:
  1.  
  2. //************************************************************************************************
  3. //Get the tile wich is selected
  4. //************************************************************************************************
  5. function GetOGLPos(X, Y: Integer): T3D_Point;
  6. var
  7.   viewport: TViewPortArray;
  8.   modelview:  T16dArray;
  9.   projection: T16dArray;
  10.   winZ: Single;
  11.   resPoint: T3D_Point;
  12. begin
  13.   glGetDoublev(GL_MODELVIEW_MATRIX, @modelview );
  14.   glGetDoublev(GL_PROJECTION_MATRIX, @projection );
  15.   glGetIntegerv(GL_VIEWPORT, @viewport );
  16.  
  17.   // In Delphi A Y Value Of 0 Returns An Unknown Value
  18.   // I Discovered This While I Was Testing A Crosshair
  19.   if(Y = 0) then Y := 1;
  20.   glReadPixels(X,-Y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@winZ);
  21.   gluUnProject(X,viewport[4]-Y,winZ,modelview,projection,viewport,@resPoint[0],@resPoint[1],@resPoint[2]);
  22.   writeLn(floatToStr(resPoint[0]) + ' , ' + floatToStr(resPoint[1]) + ' , ' + floatToStr(resPoint[2]));
  23.   Result := resPoint;
  24. end;
  25.  


I got results like 0.01268 for x, 1085,36 for y and -0,099 for z. All my tiles are 1x1 and the result doesn't change to much. The y-value (1085,36) is much too high.
Does somebody knows what the problem is?


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 13, 2004 18:00 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
How does T3D_Point look? You must declare the return values for gluUnproject as doubles, or else you will get bogus results. I guess there lies your problem, as your T3D_Point most likely consists of singles. So change that to doubles and try again.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 13, 2004 18:08 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
No, T3D_Point is an array of gldouble. I get the same result if I change gldouble by double.


Zitat:
T3D_Point = Array[0..2] of gldouble;


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 13, 2004 18:17 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
I just saw this (didn't look close before my last post) :

Code:
  1. glReadPixels(X,-Y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@winZ);


The -Y is wrong in there, and should just be Y.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 13, 2004 18:26 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
Now I get other output but now, most of the times the y value is 2170779,42944. I based my code on Delphi code from http://nehe.gamedev.net/data/articles/article.asp?article=13 wich was based on C++ code on the same page.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 13, 2004 18:59 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
I changed the code a bit so the code is more similar to the C++ code.

Code:
  1.  
  2. function GetOGLPos(X, Y: integer): T3D_Point;
  3. var
  4.   viewport: TViewPortArray;
  5.   modelview:  T16dArray;
  6.   projection: T16dArray;
  7.   winZ: single;
  8.   resPoint: T3D_Point;
  9. begin
  10.   glGetDoublev(GL_MODELVIEW_MATRIX, @modelview );
  11.   glGetDoublev(GL_PROJECTION_MATRIX, @projection );
  12.   glGetIntegerv(GL_VIEWPORT, @viewport );
  13.  
  14.   // In Delphi A Y Value Of 0 Returns An Unknown Value
  15.   // I Discovered This While I Was Testing A Crosshair
  16.   if(Y = 0) then Y := 1;
  17.   glReadPixels(X,round(viewport[3]-Y),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@winZ);
  18.   gluUnProject(X,viewport[3]-Y,winZ,modelview,projection,viewport,@resPoint[0],@resPoint[1],@resPoint[2]);
  19.   writeLn(floatToStr(resPoint[0]) + ' , ' + floatToStr(resPoint[1]) + ' , ' + floatToStr(resPoint[2]));
  20.   Result := resPoint;
  21. end;
  22.  


I don't get values that are too high anymore but I don't think the values are correct. I've attached a screenshot to show the problem.


Dateianhänge:
Dateikommentar: You can see tree cursors with the value of the getOGLPos function. In the center, you see the size of one tile (1x1).
screenshot.jpg
screenshot.jpg [ 82.99 KiB | 6184-mal betrachtet ]
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Aug 13, 2004 20:11 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
Code:
  1. glReadPixels(X,round(viewport[3]-Y),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@winZ)


Why that? glReadPixels(X, Y, ...) should be correct. In opposition to gluUnproject, die Origin for glReadPixels lies in the upper/left corner, so you don't need to subtract Y from the bottom of the viewport.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Aug 14, 2004 07:29 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
The reference page from msdn.microsoft.com says this:
Zitat:
x, y
The window coordinates of the first pixel that is read from the framebuffer. This location is the lower-left corner of a rectangular block of pixels.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Aug 14, 2004 08:57 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
It seems to work now. Thanks for your help.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Aug 14, 2004 13:54 
Offline
Fels i.d. Brandung
Benutzeravatar

Registriert: Sa Mai 04, 2002 19:48
Beiträge: 3830
Wohnort: Tespe (nahe Hamburg)
btw: Interesting to see that someone is using freepascal for a project. Please feel free to keep us informed about the progress. I will be interested in ;)

_________________
"Light travels faster than sound. This is why some people appear bright, before you can hear them speak..."


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Aug 14, 2004 15:40 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
I will do that.


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 11 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.029s | 19 Queries | GZIP : On ]